aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/writing-an-alsa-driver.tmpl72
-rw-r--r--Documentation/devicetree/bindings/i2c/trivial-devices.txt1
-rw-r--r--Documentation/devicetree/bindings/misc/atmel-ssc.txt8
-rw-r--r--Documentation/devicetree/bindings/sound/armada-370db-audio.txt27
-rw-r--r--Documentation/devicetree/bindings/sound/cs42xx8.txt28
-rw-r--r--Documentation/devicetree/bindings/sound/da9055.txt22
-rw-r--r--Documentation/devicetree/bindings/sound/davinci-evm-audio.txt9
-rw-r--r--Documentation/devicetree/bindings/sound/eukrea-tlv320.txt21
-rw-r--r--Documentation/devicetree/bindings/sound/fsl,esai.txt5
-rw-r--r--Documentation/devicetree/bindings/sound/fsl,spdif.txt5
-rw-r--r--Documentation/devicetree/bindings/sound/mvebu-audio.txt1
-rw-r--r--Documentation/devicetree/bindings/sound/pcm512x.txt30
-rw-r--r--Documentation/devicetree/bindings/sound/renesas,rsnd.txt96
-rw-r--r--Documentation/devicetree/bindings/sound/simple-card.txt23
-rw-r--r--Documentation/devicetree/bindings/sound/sirf-audio-codec.txt17
-rw-r--r--Documentation/devicetree/bindings/sound/sirf-audio-port.txt20
-rw-r--r--Documentation/devicetree/bindings/sound/sirf-audio.txt41
-rw-r--r--Documentation/devicetree/bindings/sound/tdm-slot.txt20
-rw-r--r--Documentation/devicetree/bindings/sound/tlv320aic31xx.txt61
-rw-r--r--Documentation/devicetree/bindings/sound/tlv320aic32x4.txt30
-rw-r--r--Documentation/devicetree/bindings/sound/tlv320aic3x.txt1
-rw-r--r--Documentation/devicetree/bindings/sound/widgets.txt20
-rw-r--r--Documentation/networking/packet_mmap.txt2
-rw-r--r--Documentation/networking/timestamping.txt52
-rw-r--r--MAINTAINERS10
-rw-r--r--Makefile2
-rw-r--r--arch/arm/mach-shmobile/board-armadillo800eva.c4
-rw-r--r--arch/arm/mach-shmobile/board-kzm9g.c4
-rw-r--r--arch/arm/mach-shmobile/board-mackerel.c6
-rw-r--r--arch/cris/include/asm/bitops.h2
-rw-r--r--arch/ia64/kernel/uncached.c2
-rw-r--r--arch/powerpc/platforms/cell/ras.c3
-rw-r--r--arch/sh/boards/mach-ecovec24/setup.c4
-rw-r--r--arch/sh/boards/mach-se/7724/setup.c4
-rw-r--r--arch/x86/Kconfig.cpu4
-rw-r--r--arch/x86/include/asm/barrier.h8
-rw-r--r--arch/x86/include/asm/io.h2
-rw-r--r--arch/x86/include/asm/spinlock.h5
-rw-r--r--arch/x86/kernel/cpu/centaur.c272
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_uncore.c3
-rw-r--r--arch/x86/kernel/i387.c15
-rw-r--r--arch/x86/kernel/quirks.c2
-rw-r--r--arch/x86/kvm/svm.c6
-rw-r--r--arch/x86/net/bpf_jit.S2
-rw-r--r--arch/x86/um/asm/barrier.h4
-rw-r--r--drivers/acpi/sleep.c32
-rw-r--r--drivers/ata/libata-core.c3
-rw-r--r--drivers/base/regmap/regmap.c12
-rw-r--r--drivers/cpufreq/cpufreq.c4
-rw-r--r--drivers/gpu/drm/radeon/cik.c5
-rw-r--r--drivers/gpu/drm/radeon/cik_sdma.c14
-rw-r--r--drivers/gpu/drm/radeon/radeon_kms.c10
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c8
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_vm.c12
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_surface.c18
-rw-r--r--drivers/hid/hid-prodikeys.c5
-rw-r--r--drivers/i2c/busses/Kconfig2
-rw-r--r--drivers/md/dm-cache-target.c11
-rw-r--r--drivers/media/pci/cx18/cx18-alsa-main.c9
-rw-r--r--drivers/media/pci/cx23885/cx23885-alsa.c5
-rw-r--r--drivers/media/pci/cx25821/cx25821-alsa.c7
-rw-r--r--drivers/media/pci/cx88/cx88-alsa.c6
-rw-r--r--drivers/media/pci/ivtv/ivtv-alsa-main.c9
-rw-r--r--drivers/media/pci/saa7134/saa7134-alsa.c6
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-audio.c5
-rw-r--r--drivers/media/usb/em28xx/em28xx-audio.c5
-rw-r--r--drivers/media/usb/stk1160/stk1160-ac97.c6
-rw-r--r--drivers/media/usb/tlg2300/pd-alsa.c3
-rw-r--r--drivers/media/usb/tm6000/tm6000-alsa.c4
-rw-r--r--drivers/misc/atmel-ssc.c6
-rw-r--r--drivers/misc/sgi-xp/xpc_uv.c2
-rw-r--r--drivers/net/bonding/bond_alb.c2
-rw-r--r--drivers/net/bonding/bond_options.c1
-rw-r--r--drivers/net/ethernet/broadcom/bnx2.c37
-rw-r--r--drivers/net/ethernet/broadcom/bnx2.h5
-rw-r--r--drivers/net/ethernet/brocade/bna/bfa_ioc.c2
-rw-r--r--drivers/net/ethernet/cadence/macb.c16
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c14
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.c25
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.h1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_netdev.c10
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/fw.c11
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/main.c14
-rw-r--r--drivers/net/ethernet/realtek/r8169.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/chain_mode.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/common.h20
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/ring_mode.c9
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c91
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c2
-rw-r--r--drivers/net/hyperv/netvsc_drv.c4
-rw-r--r--drivers/net/hyperv/rndis_filter.c21
-rw-r--r--drivers/net/ieee802154/at86rf230.c11
-rw-r--r--drivers/net/phy/phy.c11
-rw-r--r--drivers/net/usb/Makefile2
-rw-r--r--drivers/net/usb/cdc_ether.c7
-rw-r--r--drivers/net/usb/r8152.c15
-rw-r--r--drivers/net/usb/r815x.c248
-rw-r--r--drivers/net/vmxnet3/vmxnet3_drv.c19
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/bt-coex.c7
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/drv.c5
-rw-r--r--drivers/net/wireless/mwifiex/11ac.c3
-rw-r--r--drivers/net/wireless/mwifiex/11n.c3
-rw-r--r--drivers/net/wireless/mwifiex/scan.c8
-rw-r--r--drivers/net/wireless/ti/wl1251/rx.c2
-rw-r--r--drivers/net/xen-netback/interface.c3
-rw-r--r--drivers/net/xen-netback/netback.c39
-rw-r--r--drivers/pci/bus.c2
-rw-r--r--drivers/pci/pci.c3
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c6
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c15
-rw-r--r--drivers/scsi/be2iscsi/be_main.c2
-rw-r--r--drivers/scsi/isci/host.h5
-rw-r--r--drivers/scsi/isci/port_config.c7
-rw-r--r--drivers/scsi/isci/task.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h3
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c46
-rw-r--r--drivers/scsi/storvsc_drv.c3
-rw-r--r--drivers/staging/line6/audio.c5
-rw-r--r--drivers/staging/line6/midi.c2
-rw-r--r--drivers/staging/line6/pcm.c2
-rw-r--r--drivers/staging/media/go7007/snd-go7007.c5
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-g723.c6
-rw-r--r--drivers/usb/gadget/f_midi.c7
-rw-r--r--drivers/usb/gadget/f_uac2.c4
-rw-r--r--fs/cifs/cifsglob.h2
-rw-r--r--fs/cifs/file.c24
-rw-r--r--fs/cifs/transport.c29
-rw-r--r--fs/file.c56
-rw-r--r--fs/file_table.c1
-rw-r--r--fs/hfsplus/catalog.c41
-rw-r--r--fs/hfsplus/hfsplus_fs.h1
-rw-r--r--fs/hfsplus/hfsplus_raw.h6
-rw-r--r--fs/hfsplus/inode.c9
-rw-r--r--fs/namei.c2
-rw-r--r--fs/ocfs2/file.c8
-rw-r--r--fs/open.c4
-rw-r--r--fs/proc/base.c1
-rw-r--r--fs/read_write.c40
-rw-r--r--include/dt-bindings/sound/tlv320aic31xx-micbias.h8
-rw-r--r--include/kvm/arm_vgic.h5
-rw-r--r--include/linux/atmel-ssc.h1
-rw-r--r--include/linux/audit.h3
-rw-r--r--include/linux/file.h27
-rw-r--r--include/linux/fs.h8
-rw-r--r--include/linux/gfp.h4
-rw-r--r--include/linux/mfd/arizona/registers.h6
-rw-r--r--include/linux/mmzone.h4
-rw-r--r--include/linux/platform_data/adau1977.h45
-rw-r--r--include/linux/platform_data/asoc-s3c.h3
-rw-r--r--include/linux/platform_data/asoc-s3c24xx_simtec.h3
-rw-r--r--include/linux/platform_data/davinci_asp.h4
-rw-r--r--include/linux/regmap.h9
-rw-r--r--include/linux/slab.h2
-rw-r--r--include/net/sock.h6
-rw-r--r--include/sound/core.h113
-rw-r--r--include/sound/emu10k1.h2
-rw-r--r--include/sound/hwdep.h3
-rw-r--r--include/sound/pcm.h8
-rw-r--r--include/sound/rawmidi.h2
-rw-r--r--include/sound/rcar_snd.h36
-rw-r--r--include/sound/simple_card.h6
-rw-r--r--include/sound/soc-dai.h3
-rw-r--r--include/sound/soc-dapm.h40
-rw-r--r--include/sound/soc.h152
-rw-r--r--include/trace/events/hswadsp.h384
-rw-r--r--include/trace/events/intel-sst.h148
-rw-r--r--init/main.c2
-rw-r--r--ipc/msg.c2
-rw-r--r--kernel/audit.c31
-rw-r--r--kernel/audit.h2
-rw-r--r--kernel/auditfilter.c10
-rw-r--r--kernel/profile.c4
-rw-r--r--kernel/sched/clock.c4
-rw-r--r--kernel/sched/core.c9
-rw-r--r--kernel/stop_machine.c2
-rw-r--r--mm/Kconfig4
-rw-r--r--mm/compaction.c20
-rw-r--r--mm/migrate.c11
-rw-r--r--net/8021q/vlan_dev.c3
-rw-r--r--net/bridge/br_multicast.c33
-rw-r--r--net/core/skbuff.c100
-rw-r--r--net/core/sock.c5
-rw-r--r--net/ipv4/inet_fragment.c5
-rw-r--r--net/ipv4/tcp_output.c11
-rw-r--r--net/ipv6/addrconf.c5
-rw-r--r--net/ipv6/exthdrs_offload.c4
-rw-r--r--net/ipv6/route.c2
-rw-r--r--net/l2tp/l2tp_core.c4
-rw-r--r--net/l2tp/l2tp_core.h1
-rw-r--r--net/l2tp/l2tp_netlink.c4
-rw-r--r--net/l2tp/l2tp_ppp.c13
-rw-r--r--net/mac80211/chan.c6
-rw-r--r--net/mac80211/mesh_ps.c1
-rw-r--r--net/mac80211/sta_info.c1
-rw-r--r--net/sched/sch_api.c7
-rw-r--r--net/sched/sch_fq.c21
-rw-r--r--net/sctp/sm_make_chunk.c4
-rw-r--r--net/sctp/sm_statefuns.c5
-rw-r--r--net/socket.c17
-rw-r--r--net/tipc/config.c9
-rw-r--r--net/tipc/handler.c1
-rw-r--r--net/tipc/name_table.c37
-rw-r--r--net/tipc/server.c14
-rw-r--r--net/tipc/socket.c4
-rw-r--r--net/tipc/subscr.c19
-rw-r--r--net/unix/af_unix.c3
-rw-r--r--net/wireless/core.c2
-rw-r--r--scripts/kallsyms.c3
-rw-r--r--sound/aoa/aoa.h2
-rw-r--r--sound/aoa/codecs/onyx.c2
-rw-r--r--sound/aoa/codecs/tas.c2
-rw-r--r--sound/aoa/codecs/toonie.c2
-rw-r--r--sound/aoa/core/alsa.c7
-rw-r--r--sound/arm/aaci.c6
-rw-r--r--sound/arm/pxa2xx-ac97.c6
-rw-r--r--sound/atmel/abdac.c13
-rw-r--r--sound/atmel/ac97c.c10
-rw-r--r--sound/core/control.c17
-rw-r--r--sound/core/control_compat.c2
-rw-r--r--sound/core/device.c175
-rw-r--r--sound/core/hrtimer.c3
-rw-r--r--sound/core/hwdep.c53
-rw-r--r--sound/core/info.c15
-rw-r--r--sound/core/init.c186
-rw-r--r--sound/core/isadma.c2
-rw-r--r--sound/core/memalloc.c4
-rw-r--r--sound/core/oss/mixer_oss.c20
-rw-r--r--sound/core/oss/pcm_oss.c103
-rw-r--r--sound/core/pcm.c52
-rw-r--r--sound/core/pcm_lib.c28
-rw-r--r--sound/core/pcm_native.c51
-rw-r--r--sound/core/pcm_timer.c4
-rw-r--r--sound/core/rawmidi.c90
-rw-r--r--sound/core/rtctimer.c7
-rw-r--r--sound/core/seq/oss/seq_oss.c22
-rw-r--r--sound/core/seq/oss/seq_oss_device.h13
-rw-r--r--sound/core/seq/oss/seq_oss_init.c29
-rw-r--r--sound/core/seq/oss/seq_oss_ioctl.c18
-rw-r--r--sound/core/seq/oss/seq_oss_midi.c7
-rw-r--r--sound/core/seq/oss/seq_oss_readq.c4
-rw-r--r--sound/core/seq/oss/seq_oss_synth.c11
-rw-r--r--sound/core/seq/oss/seq_oss_timer.c7
-rw-r--r--sound/core/seq/seq_clientmgr.c16
-rw-r--r--sound/core/seq/seq_device.c18
-rw-r--r--sound/core/seq/seq_dummy.c2
-rw-r--r--sound/core/seq/seq_fifo.c2
-rw-r--r--sound/core/seq/seq_lock.c4
-rw-r--r--sound/core/seq/seq_memory.c8
-rw-r--r--sound/core/seq/seq_midi.c8
-rw-r--r--sound/core/seq/seq_midi_emul.c6
-rw-r--r--sound/core/seq/seq_ports.c4
-rw-r--r--sound/core/seq/seq_prioq.c14
-rw-r--r--sound/core/seq/seq_queue.c2
-rw-r--r--sound/core/seq/seq_timer.c10
-rw-r--r--sound/core/seq/seq_virmidi.c2
-rw-r--r--sound/core/sound.c29
-rw-r--r--sound/core/sound_oss.c7
-rw-r--r--sound/core/timer.c17
-rw-r--r--sound/core/vmaster.c2
-rw-r--r--sound/drivers/aloop.c4
-rw-r--r--sound/drivers/dummy.c6
-rw-r--r--sound/drivers/ml403-ac97cr.c5
-rw-r--r--sound/drivers/mpu401/mpu401.c12
-rw-r--r--sound/drivers/mtpav.c4
-rw-r--r--sound/drivers/mts64.c5
-rw-r--r--sound/drivers/opl3/opl3_lib.c4
-rw-r--r--sound/drivers/opl3/opl3_synth.c2
-rw-r--r--sound/drivers/pcsp/pcsp.c4
-rw-r--r--sound/drivers/pcsp/pcsp_input.c1
-rw-r--r--sound/drivers/portman2x4.c5
-rw-r--r--sound/drivers/serial-u16550.c5
-rw-r--r--sound/drivers/virmidi.c6
-rw-r--r--sound/firewire/dice.c4
-rw-r--r--sound/firewire/isight.c4
-rw-r--r--sound/firewire/scs1x.c4
-rw-r--r--sound/firewire/speakers.c4
-rw-r--r--sound/i2c/other/ak4113.c2
-rw-r--r--sound/i2c/other/ak4114.c2
-rw-r--r--sound/i2c/other/ak4117.c2
-rw-r--r--sound/isa/ad1816a/ad1816a.c6
-rw-r--r--sound/isa/ad1848/ad1848.c4
-rw-r--r--sound/isa/adlib.c4
-rw-r--r--sound/isa/als100.c6
-rw-r--r--sound/isa/azt2320.c6
-rw-r--r--sound/isa/cmi8328.c5
-rw-r--r--sound/isa/cmi8330.c13
-rw-r--r--sound/isa/cs423x/cs4231.c4
-rw-r--r--sound/isa/cs423x/cs4236.c16
-rw-r--r--sound/isa/es1688/es1688.c12
-rw-r--r--sound/isa/es18xx.c16
-rw-r--r--sound/isa/galaxy/galaxy.c6
-rw-r--r--sound/isa/gus/gusclassic.c4
-rw-r--r--sound/isa/gus/gusextreme.c6
-rw-r--r--sound/isa/gus/gusmax.c6
-rw-r--r--sound/isa/gus/interwave.c13
-rw-r--r--sound/isa/msnd/msnd_pinnacle.c11
-rw-r--r--sound/isa/opl3sa2.c16
-rw-r--r--sound/isa/opti9xx/miro.c11
-rw-r--r--sound/isa/opti9xx/opti92x-ad1848.c12
-rw-r--r--sound/isa/sb/jazz16.c6
-rw-r--r--sound/isa/sb/sb16.c13
-rw-r--r--sound/isa/sb/sb8.c6
-rw-r--r--sound/isa/sc6000.c6
-rw-r--r--sound/isa/sscape.c11
-rw-r--r--sound/isa/wavefront/wavefront.c13
-rw-r--r--sound/mips/au1x00.c241
-rw-r--r--sound/mips/hal2.c3
-rw-r--r--sound/mips/sgio2audio.c3
-rw-r--r--sound/oss/pas2.h3
-rw-r--r--sound/oss/pas2_card.c2
-rw-r--r--sound/parisc/harmony.c4
-rw-r--r--sound/pci/Kconfig9
-rw-r--r--sound/pci/ac97/ac97_codec.c45
-rw-r--r--sound/pci/ac97/ac97_patch.c3
-rw-r--r--sound/pci/ac97/ac97_pcm.c15
-rw-r--r--sound/pci/ad1889.c37
-rw-r--r--sound/pci/ali5451/ali5451.c152
-rw-r--r--sound/pci/als300.c57
-rw-r--r--sound/pci/als4000.c22
-rw-r--r--sound/pci/asihpi/asihpi.c25
-rw-r--r--sound/pci/atiixp.c33
-rw-r--r--sound/pci/atiixp_modem.c28
-rw-r--r--sound/pci/au88x0/au88x0.c5
-rw-r--r--sound/pci/aw2/aw2-alsa.c46
-rw-r--r--sound/pci/aw2/aw2-saa7146.c6
-rw-r--r--sound/pci/azt3328.c351
-rw-r--r--sound/pci/bt87x.c41
-rw-r--r--sound/pci/ca0106/ca0106_main.c89
-rw-r--r--sound/pci/ca0106/ca_midi.c4
-rw-r--r--sound/pci/cmipci.c41
-rw-r--r--sound/pci/cs4281.c49
-rw-r--r--sound/pci/cs46xx/cs46xx.c3
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.c145
-rw-r--r--sound/pci/cs46xx/dsp_spos.c126
-rw-r--r--sound/pci/cs46xx/dsp_spos_scb_lib.c57
-rw-r--r--sound/pci/cs5530.c27
-rw-r--r--sound/pci/cs5535audio/cs5535audio.c31
-rw-r--r--sound/pci/cs5535audio/cs5535audio_olpc.c7
-rw-r--r--sound/pci/cs5535audio/cs5535audio_pcm.c6
-rw-r--r--sound/pci/cs5535audio/cs5535audio_pm.c7
-rw-r--r--sound/pci/ctxfi/ctatc.c2
-rw-r--r--sound/pci/ctxfi/xfi.c3
-rw-r--r--sound/pci/echoaudio/echoaudio.c26
-rw-r--r--sound/pci/echoaudio/echoaudio_dsp.c9
-rw-r--r--sound/pci/echoaudio/midi.c3
-rw-r--r--sound/pci/emu10k1/emu10k1.c9
-rw-r--r--sound/pci/emu10k1/emu10k1_callback.c4
-rw-r--r--sound/pci/emu10k1/emu10k1_main.c74
-rw-r--r--sound/pci/emu10k1/emu10k1_patch.c6
-rw-r--r--sound/pci/emu10k1/emu10k1x.c32
-rw-r--r--sound/pci/emu10k1/emufx.c12
-rw-r--r--sound/pci/emu10k1/emumixer.c6
-rw-r--r--sound/pci/emu10k1/emumpu401.c7
-rw-r--r--sound/pci/emu10k1/emupcm.c22
-rw-r--r--sound/pci/emu10k1/io.c13
-rw-r--r--sound/pci/emu10k1/irq.c21
-rw-r--r--sound/pci/emu10k1/memory.c12
-rw-r--r--sound/pci/emu10k1/p16v.c45
-rw-r--r--sound/pci/emu10k1/voice.c6
-rw-r--r--sound/pci/ens1370.c44
-rw-r--r--sound/pci/es1938.c79
-rw-r--r--sound/pci/es1968.c54
-rw-r--r--sound/pci/fm801.c31
-rw-r--r--sound/pci/hda/Kconfig45
-rw-r--r--sound/pci/hda/Makefile8
-rw-r--r--sound/pci/hda/hda_auto_parser.c65
-rw-r--r--sound/pci/hda/hda_beep.c36
-rw-r--r--sound/pci/hda/hda_beep.h6
-rw-r--r--sound/pci/hda/hda_codec.c238
-rw-r--r--sound/pci/hda/hda_codec.h8
-rw-r--r--sound/pci/hda/hda_controller.c2031
-rw-r--r--sound/pci/hda/hda_controller.h53
-rw-r--r--sound/pci/hda/hda_eld.c17
-rw-r--r--sound/pci/hda/hda_generic.c49
-rw-r--r--sound/pci/hda/hda_generic.h1
-rw-r--r--sound/pci/hda/hda_hwdep.c769
-rw-r--r--sound/pci/hda/hda_i915.c6
-rw-r--r--sound/pci/hda/hda_intel.c2710
-rw-r--r--sound/pci/hda/hda_local.h26
-rw-r--r--sound/pci/hda/hda_priv.h463
-rw-r--r--sound/pci/hda/hda_sysfs.c780
-rw-r--r--sound/pci/hda/patch_analog.c1
-rw-r--r--sound/pci/hda/patch_ca0110.c1
-rw-r--r--sound/pci/hda/patch_ca0132.c209
-rw-r--r--sound/pci/hda/patch_cirrus.c1
-rw-r--r--sound/pci/hda/patch_cmedia.c34
-rw-r--r--sound/pci/hda/patch_conexant.c847
-rw-r--r--sound/pci/hda/patch_hdmi.c109
-rw-r--r--sound/pci/hda/patch_realtek.c442
-rw-r--r--sound/pci/hda/patch_si3054.c5
-rw-r--r--sound/pci/hda/patch_sigmatel.c15
-rw-r--r--sound/pci/hda/patch_via.c8
-rw-r--r--sound/pci/hda/thinkpad_helper.c6
-rw-r--r--sound/pci/ice1712/aureon.c7
-rw-r--r--sound/pci/ice1712/delta.c5
-rw-r--r--sound/pci/ice1712/ews.c12
-rw-r--r--sound/pci/ice1712/ice1712.c38
-rw-r--r--sound/pci/ice1712/ice1724.c50
-rw-r--r--sound/pci/ice1712/juli.c14
-rw-r--r--sound/pci/ice1712/prodigy192.c13
-rw-r--r--sound/pci/ice1712/quartet.c6
-rw-r--r--sound/pci/intel8x0.c90
-rw-r--r--sound/pci/intel8x0m.c50
-rw-r--r--sound/pci/korg1212/korg1212.c5
-rw-r--r--sound/pci/lola/lola.c46
-rw-r--r--sound/pci/lola/lola_clock.c14
-rw-r--r--sound/pci/lola/lola_mixer.c22
-rw-r--r--sound/pci/lola/lola_pcm.c26
-rw-r--r--sound/pci/lx6464es/lx6464es.c162
-rw-r--r--sound/pci/lx6464es/lx_core.c173
-rw-r--r--sound/pci/maestro3.c42
-rw-r--r--sound/pci/mixart/mixart.c123
-rw-r--r--sound/pci/mixart/mixart_core.c49
-rw-r--r--sound/pci/mixart/mixart_hwdep.c65
-rw-r--r--sound/pci/mixart/mixart_mixer.c16
-rw-r--r--sound/pci/nm256/nm256.c79
-rw-r--r--sound/pci/oxygen/oxygen_io.c8
-rw-r--r--sound/pci/oxygen/oxygen_lib.c14
-rw-r--r--sound/pci/oxygen/xonar_hdmi.c2
-rw-r--r--sound/pci/oxygen/xonar_lib.c4
-rw-r--r--sound/pci/pcxhr/pcxhr.c58
-rw-r--r--sound/pci/pcxhr/pcxhr_core.c108
-rw-r--r--sound/pci/pcxhr/pcxhr_hwdep.c31
-rw-r--r--sound/pci/pcxhr/pcxhr_mix22.c23
-rw-r--r--sound/pci/pcxhr/pcxhr_mixer.c13
-rw-r--r--sound/pci/riptide/riptide.c5
-rw-r--r--sound/pci/rme32.c10
-rw-r--r--sound/pci/rme96.c51
-rw-r--r--sound/pci/rme9652/hdsp.c133
-rw-r--r--sound/pci/rme9652/hdspm.c131
-rw-r--r--sound/pci/rme9652/rme9652.c24
-rw-r--r--sound/pci/sis7019.c5
-rw-r--r--sound/pci/sonicvibes.c240
-rw-r--r--sound/pci/trident/trident.c3
-rw-r--r--sound/pci/trident/trident_main.c90
-rw-r--r--sound/pci/via82xx.c73
-rw-r--r--sound/pci/via82xx_modem.c49
-rw-r--r--sound/pci/vx222/vx222.c12
-rw-r--r--sound/pci/vx222/vx222_ops.c19
-rw-r--r--sound/pci/ymfpci/ymfpci.c25
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c28
-rw-r--r--sound/pcmcia/pdaudiocf/pdaudiocf.c5
-rw-r--r--sound/pcmcia/vx/vxpocket.c4
-rw-r--r--sound/ppc/powermac.c4
-rw-r--r--sound/ppc/snd_ps3.c4
-rw-r--r--sound/sh/aica.c5
-rw-r--r--sound/sh/sh_dac_audio.c2
-rw-r--r--sound/soc/Kconfig1
-rw-r--r--sound/soc/Makefile1
-rw-r--r--sound/soc/atmel/Kconfig2
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.c13
-rw-r--r--sound/soc/atmel/sam9g20_wm8731.c20
-rw-r--r--sound/soc/blackfin/Kconfig9
-rw-r--r--sound/soc/cirrus/Kconfig4
-rw-r--r--sound/soc/cirrus/snappercl15.c18
-rw-r--r--sound/soc/codecs/88pm860x-codec.c119
-rw-r--r--sound/soc/codecs/Kconfig195
-rw-r--r--sound/soc/codecs/Makefile39
-rw-r--r--sound/soc/codecs/ad1836.c4
-rw-r--r--sound/soc/codecs/ad193x-i2c.c54
-rw-r--r--sound/soc/codecs/ad193x-spi.c48
-rw-r--r--sound/soc/codecs/ad193x.c154
-rw-r--r--sound/soc/codecs/ad193x.h7
-rw-r--r--sound/soc/codecs/adau1373.c39
-rw-r--r--sound/soc/codecs/adau1977-i2c.c59
-rw-r--r--sound/soc/codecs/adau1977-spi.c76
-rw-r--r--sound/soc/codecs/adau1977.c1018
-rw-r--r--sound/soc/codecs/adau1977.h37
-rw-r--r--sound/soc/codecs/adav801.c53
-rw-r--r--sound/soc/codecs/adav803.c50
-rw-r--r--sound/soc/codecs/adav80x.c159
-rw-r--r--sound/soc/codecs/adav80x.h7
-rw-r--r--sound/soc/codecs/ak4104.c2
-rw-r--r--sound/soc/codecs/ak4535.c9
-rw-r--r--sound/soc/codecs/ak4641.c24
-rw-r--r--sound/soc/codecs/ak4642.c8
-rw-r--r--sound/soc/codecs/ak4671.c250
-rw-r--r--sound/soc/codecs/ak4671.h2
-rw-r--r--sound/soc/codecs/alc5623.c120
-rw-r--r--sound/soc/codecs/alc5632.c48
-rw-r--r--sound/soc/codecs/arizona.c325
-rw-r--r--sound/soc/codecs/cq93vc.c3
-rw-r--r--sound/soc/codecs/cs4270.c9
-rw-r--r--sound/soc/codecs/cs4271.c63
-rw-r--r--sound/soc/codecs/cs42l51.c99
-rw-r--r--sound/soc/codecs/cs42l52.c109
-rw-r--r--sound/soc/codecs/cs42l73.c72
-rw-r--r--sound/soc/codecs/cs42xx8-i2c.c64
-rw-r--r--sound/soc/codecs/cs42xx8.c602
-rw-r--r--sound/soc/codecs/cs42xx8.h238
-rw-r--r--sound/soc/codecs/da7210.c28
-rw-r--r--sound/soc/codecs/da7213.c159
-rw-r--r--sound/soc/codecs/da732x.c196
-rw-r--r--sound/soc/codecs/da732x.h3
-rw-r--r--sound/soc/codecs/da9055.c100
-rw-r--r--sound/soc/codecs/isabelle.c19
-rw-r--r--sound/soc/codecs/lm4857.c3
-rw-r--r--sound/soc/codecs/lm49453.c47
-rw-r--r--sound/soc/codecs/max9768.c5
-rw-r--r--sound/soc/codecs/max98088.c47
-rw-r--r--sound/soc/codecs/max98090.c181
-rw-r--r--sound/soc/codecs/max98090.h1
-rw-r--r--sound/soc/codecs/max98095.c60
-rw-r--r--sound/soc/codecs/max9850.c8
-rw-r--r--sound/soc/codecs/mc13783.c30
-rw-r--r--sound/soc/codecs/ml26124.c22
-rw-r--r--sound/soc/codecs/pcm1681.c15
-rw-r--r--sound/soc/codecs/pcm1792a.c33
-rw-r--r--sound/soc/codecs/pcm512x-i2c.c71
-rw-r--r--sound/soc/codecs/pcm512x-spi.c69
-rw-r--r--sound/soc/codecs/pcm512x.c589
-rw-r--r--sound/soc/codecs/pcm512x.h171
-rw-r--r--sound/soc/codecs/rt5631.c84
-rw-r--r--sound/soc/codecs/rt5640.c86
-rw-r--r--sound/soc/codecs/sgtl5000.c18
-rw-r--r--sound/soc/codecs/si476x.c6
-rw-r--r--sound/soc/codecs/sirf-audio-codec.c524
-rw-r--r--sound/soc/codecs/sirf-audio-codec.h75
-rw-r--r--sound/soc/codecs/sn95031.c46
-rw-r--r--sound/soc/codecs/ssm2518.c24
-rw-r--r--sound/soc/codecs/ssm2602-i2c.c57
-rw-r--r--sound/soc/codecs/ssm2602-spi.c41
-rw-r--r--sound/soc/codecs/ssm2602.c180
-rw-r--r--sound/soc/codecs/ssm2602.h14
-rw-r--r--sound/soc/codecs/sta32x.c14
-rw-r--r--sound/soc/codecs/sta529.c15
-rw-r--r--sound/soc/codecs/stac9766.c38
-rw-r--r--sound/soc/codecs/tlv320aic23-i2c.c59
-rw-r--r--sound/soc/codecs/tlv320aic23-spi.c56
-rw-r--r--sound/soc/codecs/tlv320aic23.c79
-rw-r--r--sound/soc/codecs/tlv320aic23.h6
-rw-r--r--sound/soc/codecs/tlv320aic26.c7
-rw-r--r--sound/soc/codecs/tlv320aic31xx.c1280
-rw-r--r--sound/soc/codecs/tlv320aic31xx.h258
-rw-r--r--sound/soc/codecs/tlv320aic32x4.c234
-rw-r--r--sound/soc/codecs/tlv320aic3x.c6
-rw-r--r--sound/soc/codecs/tlv320dac33.c35
-rw-r--r--sound/soc/codecs/twl4030.c101
-rw-r--r--sound/soc/codecs/twl6040.c17
-rw-r--r--sound/soc/codecs/uda134x.c3
-rw-r--r--sound/soc/codecs/uda1380.c43
-rw-r--r--sound/soc/codecs/wl1273.c9
-rw-r--r--sound/soc/codecs/wm2000.c2
-rw-r--r--sound/soc/codecs/wm2200.c25
-rw-r--r--sound/soc/codecs/wm5100.c43
-rw-r--r--sound/soc/codecs/wm5102.c32
-rw-r--r--sound/soc/codecs/wm5110.c22
-rw-r--r--sound/soc/codecs/wm8350.c4
-rw-r--r--sound/soc/codecs/wm8400.c3
-rw-r--r--sound/soc/codecs/wm8510.c10
-rw-r--r--sound/soc/codecs/wm8523.c11
-rw-r--r--sound/soc/codecs/wm8580.c9
-rw-r--r--sound/soc/codecs/wm8711.c8
-rw-r--r--sound/soc/codecs/wm8728.c11
-rw-r--r--sound/soc/codecs/wm8731.c11
-rw-r--r--sound/soc/codecs/wm8737.c56
-rw-r--r--sound/soc/codecs/wm8741.c40
-rw-r--r--sound/soc/codecs/wm8750.c6
-rw-r--r--sound/soc/codecs/wm8753.c12
-rw-r--r--sound/soc/codecs/wm8770.c6
-rw-r--r--sound/soc/codecs/wm8776.c6
-rw-r--r--sound/soc/codecs/wm8804.c10
-rw-r--r--sound/soc/codecs/wm8900.c8
-rw-r--r--sound/soc/codecs/wm8903.c118
-rw-r--r--sound/soc/codecs/wm8904.c86
-rw-r--r--sound/soc/codecs/wm8940.c26
-rw-r--r--sound/soc/codecs/wm8955.c19
-rw-r--r--sound/soc/codecs/wm8958-dsp2.c8
-rw-r--r--sound/soc/codecs/wm8960.c6
-rw-r--r--sound/soc/codecs/wm8961.c23
-rw-r--r--sound/soc/codecs/wm8962.c87
-rw-r--r--sound/soc/codecs/wm8971.c6
-rw-r--r--sound/soc/codecs/wm8974.c10
-rw-r--r--sound/soc/codecs/wm8978.c38
-rw-r--r--sound/soc/codecs/wm8983.c51
-rw-r--r--sound/soc/codecs/wm8985.c46
-rw-r--r--sound/soc/codecs/wm8988.c70
-rw-r--r--sound/soc/codecs/wm8990.c49
-rw-r--r--sound/soc/codecs/wm8991.c52
-rw-r--r--sound/soc/codecs/wm8993.c73
-rw-r--r--sound/soc/codecs/wm8994.c55
-rw-r--r--sound/soc/codecs/wm8995.c50
-rw-r--r--sound/soc/codecs/wm8996.c87
-rw-r--r--sound/soc/codecs/wm8997.c29
-rw-r--r--sound/soc/codecs/wm9081.c34
-rw-r--r--sound/soc/codecs/wm9090.c10
-rw-r--r--sound/soc/codecs/wm9705.c12
-rw-r--r--sound/soc/codecs/wm_adsp.c50
-rw-r--r--sound/soc/codecs/wm_hubs.c16
-rw-r--r--sound/soc/davinci/davinci-evm.c80
-rw-r--r--sound/soc/davinci/davinci-mcasp.c213
-rw-r--r--sound/soc/davinci/edma-pcm.c57
-rw-r--r--sound/soc/davinci/edma-pcm.h25
-rw-r--r--sound/soc/fsl/Kconfig12
-rw-r--r--sound/soc/fsl/eukrea-tlv320.c108
-rw-r--r--sound/soc/fsl/fsl_esai.c32
-rw-r--r--sound/soc/fsl/fsl_sai.c332
-rw-r--r--sound/soc/fsl/fsl_sai.h48
-rw-r--r--sound/soc/fsl/fsl_spdif.c9
-rw-r--r--sound/soc/fsl/imx-pcm-fiq.c7
-rw-r--r--sound/soc/fsl/wm1133-ev1.c11
-rw-r--r--sound/soc/generic/simple-card.c295
-rw-r--r--sound/soc/intel/Kconfig42
-rw-r--r--sound/soc/intel/Makefile27
-rw-r--r--sound/soc/intel/byt-rt5640.c187
-rw-r--r--sound/soc/intel/haswell.c235
-rw-r--r--sound/soc/intel/mfld_machine.c108
-rw-r--r--sound/soc/intel/sst-acpi.c284
-rw-r--r--sound/soc/intel/sst-baytrail-dsp.c372
-rw-r--r--sound/soc/intel/sst-baytrail-ipc.c867
-rw-r--r--sound/soc/intel/sst-baytrail-ipc.h69
-rw-r--r--sound/soc/intel/sst-baytrail-pcm.c422
-rw-r--r--sound/soc/intel/sst-dsp-priv.h309
-rw-r--r--sound/soc/intel/sst-dsp.c385
-rw-r--r--sound/soc/intel/sst-dsp.h233
-rw-r--r--sound/soc/intel/sst-firmware.c587
-rw-r--r--sound/soc/intel/sst-haswell-dsp.c517
-rw-r--r--sound/soc/intel/sst-haswell-ipc.c1785
-rw-r--r--sound/soc/intel/sst-haswell-ipc.h488
-rw-r--r--sound/soc/intel/sst-haswell-pcm.c872
-rw-r--r--sound/soc/intel/sst-mfld-dsp.h (renamed from sound/soc/intel/sst_dsp.h)8
-rw-r--r--sound/soc/intel/sst-mfld-platform.c (renamed from sound/soc/intel/sst_platform.c)8
-rw-r--r--sound/soc/intel/sst-mfld-platform.h (renamed from sound/soc/intel/sst_platform.h)4
-rw-r--r--sound/soc/kirkwood/Kconfig11
-rw-r--r--sound/soc/kirkwood/Makefile2
-rw-r--r--sound/soc/kirkwood/armada-370-db.c148
-rw-r--r--sound/soc/kirkwood/kirkwood-i2s.c1
-rw-r--r--sound/soc/omap/Kconfig4
-rw-r--r--sound/soc/omap/ams-delta.c55
-rw-r--r--sound/soc/omap/n810.c22
-rw-r--r--sound/soc/omap/omap-abe-twl6040.c3
-rw-r--r--sound/soc/omap/rx51.c22
-rw-r--r--sound/soc/pxa/corgi.c49
-rw-r--r--sound/soc/pxa/e740_wm9705.c10
-rw-r--r--sound/soc/pxa/e750_wm9705.c10
-rw-r--r--sound/soc/pxa/e800_wm9712.c19
-rw-r--r--sound/soc/pxa/magician.c60
-rw-r--r--sound/soc/pxa/mioa701_wm9713.c19
-rw-r--r--sound/soc/pxa/poodle.c7
-rw-r--r--sound/soc/pxa/spitz.c58
-rw-r--r--sound/soc/pxa/tosa.c67
-rw-r--r--sound/soc/pxa/zylonite.c17
-rw-r--r--sound/soc/s6000/s6105-ipcam.c28
-rw-r--r--sound/soc/samsung/Kconfig2
-rw-r--r--sound/soc/samsung/h1940_uda1380.c7
-rw-r--r--sound/soc/samsung/neo1973_wm8753.c168
-rw-r--r--sound/soc/samsung/rx1950_uda1380.c5
-rw-r--r--sound/soc/samsung/smdk_wm8994.c2
-rw-r--r--sound/soc/samsung/tobermory.c2
-rw-r--r--sound/soc/sh/fsi.c2
-rw-r--r--sound/soc/sh/migor.c19
-rw-r--r--sound/soc/sh/rcar/Makefile2
-rw-r--r--sound/soc/sh/rcar/adg.c229
-rw-r--r--sound/soc/sh/rcar/core.c426
-rw-r--r--sound/soc/sh/rcar/gen.c113
-rw-r--r--sound/soc/sh/rcar/rsnd.h206
-rw-r--r--sound/soc/sh/rcar/scu.c384
-rw-r--r--sound/soc/sh/rcar/src.c723
-rw-r--r--sound/soc/sh/rcar/ssi.c388
-rw-r--r--sound/soc/sirf/Kconfig14
-rw-r--r--sound/soc/sirf/Makefile5
-rw-r--r--sound/soc/sirf/sirf-audio-port.c194
-rw-r--r--sound/soc/sirf/sirf-audio-port.h62
-rw-r--r--sound/soc/sirf/sirf-audio.c156
-rw-r--r--sound/soc/soc-cache.c13
-rw-r--r--sound/soc/soc-compress.c65
-rw-r--r--sound/soc/soc-core.c599
-rw-r--r--sound/soc/soc-dapm.c465
-rw-r--r--sound/soc/soc-io.c99
-rw-r--r--sound/soc/soc-jack.c5
-rw-r--r--sound/soc/soc-pcm.c112
-rw-r--r--sound/soc/spear/spdif_out.c10
-rw-r--r--sound/soc/tegra/Kconfig2
-rw-r--r--sound/soc/tegra/tegra20_ac97.c2
-rw-r--r--sound/soc/tegra/tegra20_das.c2
-rw-r--r--sound/soc/tegra/tegra20_i2s.c2
-rw-r--r--sound/soc/tegra/tegra20_spdif.c2
-rw-r--r--sound/soc/tegra/tegra30_ahub.c4
-rw-r--r--sound/soc/tegra/tegra30_i2s.c2
-rw-r--r--sound/sparc/amd7930.c4
-rw-r--r--sound/sparc/cs4231.c11
-rw-r--r--sound/sparc/dbri.c4
-rw-r--r--sound/spi/at73c213.c6
-rw-r--r--sound/usb/6fire/chip.c13
-rw-r--r--sound/usb/6fire/comm.c4
-rw-r--r--sound/usb/6fire/control.c18
-rw-r--r--sound/usb/6fire/firmware.c70
-rw-r--r--sound/usb/6fire/midi.c12
-rw-r--r--sound/usb/6fire/pcm.c46
-rw-r--r--sound/usb/caiaq/device.c6
-rw-r--r--sound/usb/card.c69
-rw-r--r--sound/usb/clock.c65
-rw-r--r--sound/usb/endpoint.c32
-rw-r--r--sound/usb/format.c68
-rw-r--r--sound/usb/hiface/chip.c10
-rw-r--r--sound/usb/midi.c45
-rw-r--r--sound/usb/misc/ua101.c7
-rw-r--r--sound/usb/mixer.c225
-rw-r--r--sound/usb/mixer.h7
-rw-r--r--sound/usb/mixer_quirks.c10
-rw-r--r--sound/usb/pcm.c83
-rw-r--r--sound/usb/quirks.c52
-rw-r--r--sound/usb/stream.c50
-rw-r--r--sound/usb/usbaudio.h9
-rw-r--r--sound/usb/usx2y/us122l.c11
-rw-r--r--sound/usb/usx2y/usbusx2y.c13
-rw-r--r--sound/usb/usx2y/usbusx2y.h2
-rw-r--r--sound/usb/usx2y/usbusx2yaudio.c60
-rw-r--r--sound/usb/usx2y/usx2yhwdeppcm.c76
-rw-r--r--tools/net/Makefile2
-rw-r--r--tools/perf/builtin-trace.c10
-rw-r--r--tools/perf/util/machine.c2
-rw-r--r--tools/perf/util/symbol-elf.c6
-rw-r--r--tools/testing/selftests/ipc/msgque.c1
714 files changed, 30599 insertions, 14253 deletions
diff --git a/Documentation/DocBook/writing-an-alsa-driver.tmpl b/Documentation/DocBook/writing-an-alsa-driver.tmpl
index 06741e925985..d0056a4e9c53 100644
--- a/Documentation/DocBook/writing-an-alsa-driver.tmpl
+++ b/Documentation/DocBook/writing-an-alsa-driver.tmpl
@@ -468,8 +468,6 @@
468 return err; 468 return err;
469 } 469 }
470 470
471 snd_card_set_dev(card, &pci->dev);
472
473 *rchip = chip; 471 *rchip = chip;
474 return 0; 472 return 0;
475 } 473 }
@@ -492,7 +490,8 @@
492 } 490 }
493 491
494 /* (2) */ 492 /* (2) */
495 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 493 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
494 0, &card);
496 if (err < 0) 495 if (err < 0)
497 return err; 496 return err;
498 497
@@ -591,7 +590,8 @@
591 struct snd_card *card; 590 struct snd_card *card;
592 int err; 591 int err;
593 .... 592 ....
594 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 593 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
594 0, &card);
595]]> 595]]>
596 </programlisting> 596 </programlisting>
597 </informalexample> 597 </informalexample>
@@ -809,28 +809,34 @@
809 809
810 <para> 810 <para>
811 As mentioned above, to create a card instance, call 811 As mentioned above, to create a card instance, call
812 <function>snd_card_create()</function>. 812 <function>snd_card_new()</function>.
813 813
814 <informalexample> 814 <informalexample>
815 <programlisting> 815 <programlisting>
816<![CDATA[ 816<![CDATA[
817 struct snd_card *card; 817 struct snd_card *card;
818 int err; 818 int err;
819 err = snd_card_create(index, id, module, extra_size, &card); 819 err = snd_card_new(&pci->dev, index, id, module, extra_size, &card);
820]]> 820]]>
821 </programlisting> 821 </programlisting>
822 </informalexample> 822 </informalexample>
823 </para> 823 </para>
824 824
825 <para> 825 <para>
826 The function takes five arguments, the card-index number, the 826 The function takes six arguments: the parent device pointer,
827 id string, the module pointer (usually 827 the card-index number, the id string, the module pointer (usually
828 <constant>THIS_MODULE</constant>), 828 <constant>THIS_MODULE</constant>),
829 the size of extra-data space, and the pointer to return the 829 the size of extra-data space, and the pointer to return the
830 card instance. The extra_size argument is used to 830 card instance. The extra_size argument is used to
831 allocate card-&gt;private_data for the 831 allocate card-&gt;private_data for the
832 chip-specific data. Note that these data 832 chip-specific data. Note that these data
833 are allocated by <function>snd_card_create()</function>. 833 are allocated by <function>snd_card_new()</function>.
834 </para>
835
836 <para>
837 The first argument, the pointer of struct
838 <structname>device</structname>, specifies the parent device.
839 For PCI devices, typically &amp;pci-&gt; is passed there.
834 </para> 840 </para>
835 </section> 841 </section>
836 842
@@ -916,16 +922,16 @@
916 </para> 922 </para>
917 923
918 <section id="card-management-chip-specific-snd-card-new"> 924 <section id="card-management-chip-specific-snd-card-new">
919 <title>1. Allocating via <function>snd_card_create()</function>.</title> 925 <title>1. Allocating via <function>snd_card_new()</function>.</title>
920 <para> 926 <para>
921 As mentioned above, you can pass the extra-data-length 927 As mentioned above, you can pass the extra-data-length
922 to the 4th argument of <function>snd_card_create()</function>, i.e. 928 to the 5th argument of <function>snd_card_new()</function>, i.e.
923 929
924 <informalexample> 930 <informalexample>
925 <programlisting> 931 <programlisting>
926<![CDATA[ 932<![CDATA[
927 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 933 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
928 sizeof(struct mychip), &card); 934 sizeof(struct mychip), &card);
929]]> 935]]>
930 </programlisting> 936 </programlisting>
931 </informalexample> 937 </informalexample>
@@ -954,7 +960,7 @@
954 960
955 <para> 961 <para>
956 After allocating a card instance via 962 After allocating a card instance via
957 <function>snd_card_create()</function> (with 963 <function>snd_card_new()</function> (with
958 <constant>0</constant> on the 4th arg), call 964 <constant>0</constant> on the 4th arg), call
959 <function>kzalloc()</function>. 965 <function>kzalloc()</function>.
960 966
@@ -963,7 +969,8 @@
963<![CDATA[ 969<![CDATA[
964 struct snd_card *card; 970 struct snd_card *card;
965 struct mychip *chip; 971 struct mychip *chip;
966 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 972 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
973 0, &card);
967 ..... 974 .....
968 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 975 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
969]]> 976]]>
@@ -1170,8 +1177,6 @@
1170 return err; 1177 return err;
1171 } 1178 }
1172 1179
1173 snd_card_set_dev(card, &pci->dev);
1174
1175 *rchip = chip; 1180 *rchip = chip;
1176 return 0; 1181 return 0;
1177 } 1182 }
@@ -1526,30 +1531,6 @@
1526 1531
1527 </section> 1532 </section>
1528 1533
1529 <section id="pci-resource-device-struct">
1530 <title>Registration of Device Struct</title>
1531 <para>
1532 At some point, typically after calling <function>snd_device_new()</function>,
1533 you need to register the struct <structname>device</structname> of the chip
1534 you're handling for udev and co. ALSA provides a macro for compatibility with
1535 older kernels. Simply call like the following:
1536 <informalexample>
1537 <programlisting>
1538<![CDATA[
1539 snd_card_set_dev(card, &pci->dev);
1540]]>
1541 </programlisting>
1542 </informalexample>
1543 so that it stores the PCI's device pointer to the card. This will be
1544 referred by ALSA core functions later when the devices are registered.
1545 </para>
1546 <para>
1547 In the case of non-PCI, pass the proper device struct pointer of the BUS
1548 instead. (In the case of legacy ISA without PnP, you don't have to do
1549 anything.)
1550 </para>
1551 </section>
1552
1553 <section id="pci-resource-entries"> 1534 <section id="pci-resource-entries">
1554 <title>PCI Entries</title> 1535 <title>PCI Entries</title>
1555 <para> 1536 <para>
@@ -5740,7 +5721,8 @@ struct _snd_pcm_runtime {
5740 struct mychip *chip; 5721 struct mychip *chip;
5741 int err; 5722 int err;
5742 .... 5723 ....
5743 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 5724 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
5725 0, &card);
5744 .... 5726 ....
5745 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 5727 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
5746 .... 5728 ....
@@ -5752,7 +5734,7 @@ struct _snd_pcm_runtime {
5752 </informalexample> 5734 </informalexample>
5753 5735
5754 When you created the chip data with 5736 When you created the chip data with
5755 <function>snd_card_create()</function>, it's anyway accessible 5737 <function>snd_card_new()</function>, it's anyway accessible
5756 via <structfield>private_data</structfield> field. 5738 via <structfield>private_data</structfield> field.
5757 5739
5758 <informalexample> 5740 <informalexample>
@@ -5766,8 +5748,8 @@ struct _snd_pcm_runtime {
5766 struct mychip *chip; 5748 struct mychip *chip;
5767 int err; 5749 int err;
5768 .... 5750 ....
5769 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 5751 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
5770 sizeof(struct mychip), &card); 5752 sizeof(struct mychip), &card);
5771 .... 5753 ....
5772 chip = card->private_data; 5754 chip = card->private_data;
5773 .... 5755 ....
diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
index 1a1ac2e560e9..f47e56bcf78d 100644
--- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt
+++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
@@ -18,6 +18,7 @@ atmel,24c02 i2c serial eeprom (24cxx)
18atmel,at97sc3204t i2c trusted platform module (TPM) 18atmel,at97sc3204t i2c trusted platform module (TPM)
19capella,cm32181 CM32181: Ambient Light Sensor 19capella,cm32181 CM32181: Ambient Light Sensor
20catalyst,24c32 i2c serial eeprom 20catalyst,24c32 i2c serial eeprom
21cirrus,cs42l51 Cirrus Logic CS42L51 audio codec
21dallas,ds1307 64 x 8, Serial, I2C Real-Time Clock 22dallas,ds1307 64 x 8, Serial, I2C Real-Time Clock
22dallas,ds1338 I2C RTC with 56-Byte NV RAM 23dallas,ds1338 I2C RTC with 56-Byte NV RAM
23dallas,ds1339 I2C Serial Real-Time Clock 24dallas,ds1339 I2C Serial Real-Time Clock
diff --git a/Documentation/devicetree/bindings/misc/atmel-ssc.txt b/Documentation/devicetree/bindings/misc/atmel-ssc.txt
index 60960b2755f4..efc98ea1f23d 100644
--- a/Documentation/devicetree/bindings/misc/atmel-ssc.txt
+++ b/Documentation/devicetree/bindings/misc/atmel-ssc.txt
@@ -17,6 +17,14 @@ Required properties for devices compatible with "atmel,at91sam9g45-ssc":
17 See Documentation/devicetree/bindings/dma/atmel-dma.txt for details. 17 See Documentation/devicetree/bindings/dma/atmel-dma.txt for details.
18- dma-names: Must be "tx", "rx". 18- dma-names: Must be "tx", "rx".
19 19
20Optional properties:
21 - atmel,clk-from-rk-pin: bool property.
22 - When SSC works in slave mode, according to the hardware design, the
23 clock can get from TK pin, and also can get from RK pin. So, add
24 this parameter to choose where the clock from.
25 - By default the clock is from TK pin, if the clock from RK pin, this
26 property is needed.
27
20Examples: 28Examples:
21- PDC transfer: 29- PDC transfer:
22ssc0: ssc@fffbc000 { 30ssc0: ssc@fffbc000 {
diff --git a/Documentation/devicetree/bindings/sound/armada-370db-audio.txt b/Documentation/devicetree/bindings/sound/armada-370db-audio.txt
new file mode 100644
index 000000000000..bf984d238620
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/armada-370db-audio.txt
@@ -0,0 +1,27 @@
1Device Tree bindings for the Armada 370 DB audio
2================================================
3
4These Device Tree bindings are used to describe the audio complex
5found on the Armada 370 DB platform.
6
7Mandatory properties:
8
9 * compatible: must be "marvell,a370db-audio"
10
11 * marvell,audio-controller: a phandle that points to the audio
12 controller of the Armada 370 SoC.
13
14 * marvell,audio-codec: a set of three phandles that points to:
15
16 1/ the analog audio codec connected to the Armada 370 SoC
17 2/ the S/PDIF transceiver
18 3/ the S/PDIF receiver
19
20Example:
21
22 sound {
23 compatible = "marvell,a370db-audio";
24 marvell,audio-controller = <&audio_controller>;
25 marvell,audio-codec = <&audio_codec &spdif_out &spdif_in>;
26 status = "okay";
27 };
diff --git a/Documentation/devicetree/bindings/sound/cs42xx8.txt b/Documentation/devicetree/bindings/sound/cs42xx8.txt
new file mode 100644
index 000000000000..f631fbca6284
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/cs42xx8.txt
@@ -0,0 +1,28 @@
1CS42448/CS42888 audio CODEC
2
3Required properties:
4
5 - compatible : must contain one of "cirrus,cs42448" and "cirrus,cs42888"
6
7 - reg : the I2C address of the device for I2C
8
9 - clocks : a list of phandles + clock-specifiers, one for each entry in
10 clock-names
11
12 - clock-names : must contain "mclk"
13
14 - VA-supply, VD-supply, VLS-supply, VLC-supply: power supplies for the device,
15 as covered in Documentation/devicetree/bindings/regulator/regulator.txt
16
17Example:
18
19codec: cs42888@48 {
20 compatible = "cirrus,cs42888";
21 reg = <0x48>;
22 clocks = <&codec_mclk 0>;
23 clock-names = "mclk";
24 VA-supply = <&reg_audio>;
25 VD-supply = <&reg_audio>;
26 VLS-supply = <&reg_audio>;
27 VLC-supply = <&reg_audio>;
28};
diff --git a/Documentation/devicetree/bindings/sound/da9055.txt b/Documentation/devicetree/bindings/sound/da9055.txt
new file mode 100644
index 000000000000..ed1b7cc6f249
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/da9055.txt
@@ -0,0 +1,22 @@
1* Dialog DA9055 Audio CODEC
2
3DA9055 provides Audio CODEC support (I2C only).
4
5The Audio CODEC device in DA9055 has it's own I2C address which is configurable,
6so the device is instantiated separately from the PMIC (MFD) device.
7
8For details on accompanying PMIC I2C device, see the following:
9Documentation/devicetree/bindings/mfd/da9055.txt
10
11Required properties:
12
13 - compatible: "dlg,da9055-codec"
14 - reg: Specifies the I2C slave address
15
16
17Example:
18
19 codec: da9055-codec@1a {
20 compatible = "dlg,da9055-codec";
21 reg = <0x1a>;
22 };
diff --git a/Documentation/devicetree/bindings/sound/davinci-evm-audio.txt b/Documentation/devicetree/bindings/sound/davinci-evm-audio.txt
index 865178d5cdf3..963e100514c2 100644
--- a/Documentation/devicetree/bindings/sound/davinci-evm-audio.txt
+++ b/Documentation/devicetree/bindings/sound/davinci-evm-audio.txt
@@ -5,12 +5,19 @@ Required properties:
5- ti,model : The user-visible name of this sound complex. 5- ti,model : The user-visible name of this sound complex.
6- ti,audio-codec : The phandle of the TLV320AIC3x audio codec 6- ti,audio-codec : The phandle of the TLV320AIC3x audio codec
7- ti,mcasp-controller : The phandle of the McASP controller 7- ti,mcasp-controller : The phandle of the McASP controller
8- ti,codec-clock-rate : The Codec Clock rate (in Hz) applied to the Codec
9- ti,audio-routing : A list of the connections between audio components. 8- ti,audio-routing : A list of the connections between audio components.
10 Each entry is a pair of strings, the first being the connection's sink, 9 Each entry is a pair of strings, the first being the connection's sink,
11 the second being the connection's source. Valid names for sources and 10 the second being the connection's source. Valid names for sources and
12 sinks are the codec's pins, and the jacks on the board: 11 sinks are the codec's pins, and the jacks on the board:
13 12
13Optional properties:
14- ti,codec-clock-rate : The Codec Clock rate (in Hz) applied to the Codec.
15- clocks : Reference to the master clock
16- clock-names : The clock should be named "mclk"
17- Either codec-clock-rate or the codec-clock reference has to be defined. If
18 the both are defined the driver attempts to set referenced clock to the
19 defined rate and takes the rate from the clock reference.
20
14 Board connectors: 21 Board connectors:
15 22
16 * Headphone Jack 23 * Headphone Jack
diff --git a/Documentation/devicetree/bindings/sound/eukrea-tlv320.txt b/Documentation/devicetree/bindings/sound/eukrea-tlv320.txt
new file mode 100644
index 000000000000..0d7985c864af
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/eukrea-tlv320.txt
@@ -0,0 +1,21 @@
1Audio complex for Eukrea boards with tlv320aic23 codec.
2
3Required properties:
4- compatible : "eukrea,asoc-tlv320"
5- eukrea,model : The user-visible name of this sound complex.
6- ssi-controller : The phandle of the SSI controller.
7- fsl,mux-int-port : The internal port of the i.MX audio muxer (AUDMUX).
8- fsl,mux-ext-port : The external port of the i.MX audio muxer.
9
10Note: The AUDMUX port numbering should start at 1, which is consistent with
11hardware manual.
12
13Example:
14
15 sound {
16 compatible = "eukrea,asoc-tlv320";
17 eukrea,model = "imx51-eukrea-tlv320aic23";
18 ssi-controller = <&ssi2>;
19 fsl,mux-int-port = <2>;
20 fsl,mux-ext-port = <3>;
21 };
diff --git a/Documentation/devicetree/bindings/sound/fsl,esai.txt b/Documentation/devicetree/bindings/sound/fsl,esai.txt
index d7b99fa637b5..aeb8c4a0b88d 100644
--- a/Documentation/devicetree/bindings/sound/fsl,esai.txt
+++ b/Documentation/devicetree/bindings/sound/fsl,esai.txt
@@ -34,6 +34,10 @@ Required properties:
34 that ESAI would work in the synchronous mode, which means all the settings 34 that ESAI would work in the synchronous mode, which means all the settings
35 for Receiving would be duplicated from Transmition related registers. 35 for Receiving would be duplicated from Transmition related registers.
36 36
37 - big-endian : If this property is absent, the native endian mode will
38 be in use as default, or the big endian mode will be in use for all the
39 device registers.
40
37Example: 41Example:
38 42
39esai: esai@02024000 { 43esai: esai@02024000 {
@@ -46,5 +50,6 @@ esai: esai@02024000 {
46 dma-names = "rx", "tx"; 50 dma-names = "rx", "tx";
47 fsl,fifo-depth = <128>; 51 fsl,fifo-depth = <128>;
48 fsl,esai-synchronous; 52 fsl,esai-synchronous;
53 big-endian;
49 status = "disabled"; 54 status = "disabled";
50}; 55};
diff --git a/Documentation/devicetree/bindings/sound/fsl,spdif.txt b/Documentation/devicetree/bindings/sound/fsl,spdif.txt
index f2ae335670f5..3e9e82c8eab3 100644
--- a/Documentation/devicetree/bindings/sound/fsl,spdif.txt
+++ b/Documentation/devicetree/bindings/sound/fsl,spdif.txt
@@ -29,6 +29,10 @@ Required properties:
29 can also be referred to TxClk_Source 29 can also be referred to TxClk_Source
30 bit of register SPDIF_STC. 30 bit of register SPDIF_STC.
31 31
32 - big-endian : If this property is absent, the native endian mode will
33 be in use as default, or the big endian mode will be in use for all the
34 device registers.
35
32Example: 36Example:
33 37
34spdif: spdif@02004000 { 38spdif: spdif@02004000 {
@@ -50,5 +54,6 @@ spdif: spdif@02004000 {
50 "rxtx5", "rxtx6", 54 "rxtx5", "rxtx6",
51 "rxtx7"; 55 "rxtx7";
52 56
57 big-endian;
53 status = "okay"; 58 status = "okay";
54}; 59};
diff --git a/Documentation/devicetree/bindings/sound/mvebu-audio.txt b/Documentation/devicetree/bindings/sound/mvebu-audio.txt
index f0062c5871b4..cb8c07c81ce4 100644
--- a/Documentation/devicetree/bindings/sound/mvebu-audio.txt
+++ b/Documentation/devicetree/bindings/sound/mvebu-audio.txt
@@ -5,6 +5,7 @@ Required properties:
5- compatible: 5- compatible:
6 "marvell,kirkwood-audio" for Kirkwood platforms 6 "marvell,kirkwood-audio" for Kirkwood platforms
7 "marvell,dove-audio" for Dove platforms 7 "marvell,dove-audio" for Dove platforms
8 "marvell,armada370-audio" for Armada 370 platforms
8 9
9- reg: physical base address of the controller and length of memory mapped 10- reg: physical base address of the controller and length of memory mapped
10 region. 11 region.
diff --git a/Documentation/devicetree/bindings/sound/pcm512x.txt b/Documentation/devicetree/bindings/sound/pcm512x.txt
new file mode 100644
index 000000000000..faff75e64573
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/pcm512x.txt
@@ -0,0 +1,30 @@
1PCM512x audio CODECs
2
3These devices support both I2C and SPI (configured with pin strapping
4on the board).
5
6Required properties:
7
8 - compatible : One of "ti,pcm5121" or "ti,pcm5122"
9
10 - reg : the I2C address of the device for I2C, the chip select
11 number for SPI.
12
13 - AVDD-supply, DVDD-supply, and CPVDD-supply : power supplies for the
14 device, as covered in bindings/regulator/regulator.txt
15
16Optional properties:
17
18 - clocks : A clock specifier for the clock connected as SCLK. If this
19 is absent the device will be configured to clock from BCLK.
20
21Example:
22
23 pcm5122: pcm5122@4c {
24 compatible = "ti,pcm5122";
25 reg = <0x4c>;
26
27 AVDD-supply = <&reg_3v3_analog>;
28 DVDD-supply = <&reg_1v8>;
29 CPVDD-supply = <&reg_3v3>;
30 };
diff --git a/Documentation/devicetree/bindings/sound/renesas,rsnd.txt b/Documentation/devicetree/bindings/sound/renesas,rsnd.txt
new file mode 100644
index 000000000000..7c6d33f29796
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/renesas,rsnd.txt
@@ -0,0 +1,96 @@
1Renesas R-Car sound
2
3Required properties:
4- compatible : "renesas,rcar_sound-gen1" if generation1
5 "renesas,rcar_sound-gen2" if generation2
6- reg : Should contain the register physical address.
7 required register is
8 SRU/ADG/SSI if generation1
9 SRU/ADG/SSIU/SSI if generation2
10- rcar_sound,ssi : SSI subnode
11- rcar_sound,scu : SCU subnode
12- rcar_sound,dai : DAI subnode
13
14SSI subnode properties:
15- interrupts : Should contain SSI interrupt for PIO transfer
16- shared-pin : if shared clock pin
17
18DAI subnode properties:
19- playback : list of playback modules
20- capture : list of capture modules
21
22Example:
23
24rcar_sound: rcar_sound@0xffd90000 {
25 #sound-dai-cells = <1>;
26 compatible = "renesas,rcar_sound-gen2";
27 reg = <0 0xec500000 0 0x1000>, /* SCU */
28 <0 0xec5a0000 0 0x100>, /* ADG */
29 <0 0xec540000 0 0x1000>, /* SSIU */
30 <0 0xec541000 0 0x1280>; /* SSI */
31
32 rcar_sound,src {
33 src0: src@0 { };
34 src1: src@1 { };
35 src2: src@2 { };
36 src3: src@3 { };
37 src4: src@4 { };
38 src5: src@5 { };
39 src6: src@6 { };
40 src7: src@7 { };
41 src8: src@8 { };
42 src9: src@9 { };
43 };
44
45 rcar_sound,ssi {
46 ssi0: ssi@0 {
47 interrupts = <0 370 IRQ_TYPE_LEVEL_HIGH>;
48 };
49 ssi1: ssi@1 {
50 interrupts = <0 371 IRQ_TYPE_LEVEL_HIGH>;
51 };
52 ssi2: ssi@2 {
53 interrupts = <0 372 IRQ_TYPE_LEVEL_HIGH>;
54 };
55 ssi3: ssi@3 {
56 interrupts = <0 373 IRQ_TYPE_LEVEL_HIGH>;
57 };
58 ssi4: ssi@4 {
59 interrupts = <0 374 IRQ_TYPE_LEVEL_HIGH>;
60 };
61 ssi5: ssi@5 {
62 interrupts = <0 375 IRQ_TYPE_LEVEL_HIGH>;
63 };
64 ssi6: ssi@6 {
65 interrupts = <0 376 IRQ_TYPE_LEVEL_HIGH>;
66 };
67 ssi7: ssi@7 {
68 interrupts = <0 377 IRQ_TYPE_LEVEL_HIGH>;
69 };
70 ssi8: ssi@8 {
71 interrupts = <0 378 IRQ_TYPE_LEVEL_HIGH>;
72 };
73 ssi9: ssi@9 {
74 interrupts = <0 379 IRQ_TYPE_LEVEL_HIGH>;
75 };
76 };
77
78 rcar_sound,dai {
79 dai0 {
80 playback = <&ssi5 &src5>;
81 capture = <&ssi6>;
82 };
83 dai1 {
84 playback = <&ssi3>;
85 };
86 dai2 {
87 capture = <&ssi4>;
88 };
89 dai3 {
90 playback = <&ssi7>;
91 };
92 dai4 {
93 capture = <&ssi8>;
94 };
95 };
96};
diff --git a/Documentation/devicetree/bindings/sound/simple-card.txt b/Documentation/devicetree/bindings/sound/simple-card.txt
index 19c84df5fffa..881914b139ca 100644
--- a/Documentation/devicetree/bindings/sound/simple-card.txt
+++ b/Documentation/devicetree/bindings/sound/simple-card.txt
@@ -8,13 +8,18 @@ Required properties:
8 8
9Optional properties: 9Optional properties:
10 10
11- simple-audio-card,name : User specified audio sound card name, one string
12 property.
11- simple-audio-card,format : CPU/CODEC common audio format. 13- simple-audio-card,format : CPU/CODEC common audio format.
12 "i2s", "right_j", "left_j" , "dsp_a" 14 "i2s", "right_j", "left_j" , "dsp_a"
13 "dsp_b", "ac97", "pdm", "msb", "lsb" 15 "dsp_b", "ac97", "pdm", "msb", "lsb"
16- simple-audio-card,widgets : Please refer to widgets.txt.
14- simple-audio-card,routing : A list of the connections between audio components. 17- simple-audio-card,routing : A list of the connections between audio components.
15 Each entry is a pair of strings, the first being the 18 Each entry is a pair of strings, the first being the
16 connection's sink, the second being the connection's 19 connection's sink, the second being the connection's
17 source. 20 source.
21- dai-tdm-slot-num : Please refer to tdm-slot.txt.
22- dai-tdm-slot-width : Please refer to tdm-slot.txt.
18 23
19Required subnodes: 24Required subnodes:
20 25
@@ -38,15 +43,29 @@ Optional CPU/CODEC subnodes properties:
38 clock node (= common clock), or "system-clock-frequency" 43 clock node (= common clock), or "system-clock-frequency"
39 (if system doens't support common clock) 44 (if system doens't support common clock)
40 45
46Note:
47 * For 'format', 'frame-master', 'bitclock-master', 'bitclock-inversion' and
48 'frame-inversion', the simple card will use the settings of CODEC for both
49 CPU and CODEC sides as we need to keep the settings identical for both ends
50 of the link.
51
41Example: 52Example:
42 53
43sound { 54sound {
44 compatible = "simple-audio-card"; 55 compatible = "simple-audio-card";
56 simple-audio-card,name = "VF610-Tower-Sound-Card";
45 simple-audio-card,format = "left_j"; 57 simple-audio-card,format = "left_j";
58 simple-audio-card,widgets =
59 "Microphone", "Microphone Jack",
60 "Headphone", "Headphone Jack",
61 "Speaker", "External Speaker";
46 simple-audio-card,routing = 62 simple-audio-card,routing =
47 "MIC_IN", "Mic Jack", 63 "MIC_IN", "Microphone Jack",
48 "Headphone Jack", "HP_OUT", 64 "Headphone Jack", "HP_OUT",
49 "Ext Spk", "LINE_OUT"; 65 "External Speaker", "LINE_OUT";
66
67 dai-tdm-slot-num = <2>;
68 dai-tdm-slot-width = <8>;
50 69
51 simple-audio-card,cpu { 70 simple-audio-card,cpu {
52 sound-dai = <&sh_fsi2 0>; 71 sound-dai = <&sh_fsi2 0>;
diff --git a/Documentation/devicetree/bindings/sound/sirf-audio-codec.txt b/Documentation/devicetree/bindings/sound/sirf-audio-codec.txt
new file mode 100644
index 000000000000..062f5ec36f9b
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/sirf-audio-codec.txt
@@ -0,0 +1,17 @@
1SiRF internal audio CODEC
2
3Required properties:
4
5 - compatible : "sirf,atlas6-audio-codec" or "sirf,prima2-audio-codec"
6
7 - reg : the register address of the device.
8
9 - clocks: the clock of SiRF internal audio codec
10
11Example:
12
13audiocodec: audiocodec@b0040000 {
14 compatible = "sirf,atlas6-audio-codec";
15 reg = <0xb0040000 0x10000>;
16 clocks = <&clks 27>;
17};
diff --git a/Documentation/devicetree/bindings/sound/sirf-audio-port.txt b/Documentation/devicetree/bindings/sound/sirf-audio-port.txt
new file mode 100644
index 000000000000..1f66de3c8f00
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/sirf-audio-port.txt
@@ -0,0 +1,20 @@
1* SiRF SoC audio port
2
3Required properties:
4- compatible: "sirf,audio-port"
5- reg: Base address and size entries:
6- dmas: List of DMA controller phandle and DMA request line ordered pairs.
7- dma-names: Identifier string for each DMA request line in the dmas property.
8 These strings correspond 1:1 with the ordered pairs in dmas.
9
10 One of the DMA channels will be responsible for transmission (should be
11 named "tx") and one for reception (should be named "rx").
12
13Example:
14
15audioport: audioport@b0040000 {
16 compatible = "sirf,audio-port";
17 reg = <0xb0040000 0x10000>;
18 dmas = <&dmac1 3>, <&dmac1 8>;
19 dma-names = "rx", "tx";
20};
diff --git a/Documentation/devicetree/bindings/sound/sirf-audio.txt b/Documentation/devicetree/bindings/sound/sirf-audio.txt
new file mode 100644
index 000000000000..c88882ca3704
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/sirf-audio.txt
@@ -0,0 +1,41 @@
1* SiRF atlas6 and prima2 internal audio codec and port based audio setups
2
3Required properties:
4- compatible: "sirf,sirf-audio-card"
5- sirf,audio-platform: phandle for the platform node
6- sirf,audio-codec: phandle for the SiRF internal codec node
7
8Optional properties:
9- hp-pa-gpios: Need to be present if the board need control external
10 headphone amplifier.
11- spk-pa-gpios: Need to be present if the board need control external
12 speaker amplifier.
13- hp-switch-gpios: Need to be present if the board capable to detect jack
14 insertion, removal.
15
16Available audio endpoints for the audio-routing table:
17
18Board connectors:
19 * Headset Stereophone
20 * Ext Spk
21 * Line In
22 * Mic
23
24SiRF internal audio codec pins:
25 * HPOUTL
26 * HPOUTR
27 * SPKOUT
28 * Ext Mic
29 * Mic Bias
30
31Example:
32
33sound {
34 compatible = "sirf,sirf-audio-card";
35 sirf,audio-codec = <&audiocodec>;
36 sirf,audio-platform = <&audioport>;
37 hp-pa-gpios = <&gpio 44 0>;
38 spk-pa-gpios = <&gpio 46 0>;
39 hp-switch-gpios = <&gpio 45 0>;
40};
41
diff --git a/Documentation/devicetree/bindings/sound/tdm-slot.txt b/Documentation/devicetree/bindings/sound/tdm-slot.txt
new file mode 100644
index 000000000000..6a2c84247f91
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/tdm-slot.txt
@@ -0,0 +1,20 @@
1TDM slot:
2
3This specifies audio DAI's TDM slot.
4
5TDM slot properties:
6dai-tdm-slot-num : Number of slots in use.
7dai-tdm-slot-width : Width in bits for each slot.
8
9For instance:
10 dai-tdm-slot-num = <2>;
11 dai-tdm-slot-width = <8>;
12
13And for each spcified driver, there could be one .of_xlate_tdm_slot_mask()
14to specify a explicit mapping of the channels and the slots. If it's absent
15the default snd_soc_of_xlate_tdm_slot_mask() will be used to generating the
16tx and rx masks.
17
18For snd_soc_of_xlate_tdm_slot_mask(), the tx and rx masks will use a 1 bit
19for an active slot as default, and the default active bits are at the LSB of
20the masks.
diff --git a/Documentation/devicetree/bindings/sound/tlv320aic31xx.txt b/Documentation/devicetree/bindings/sound/tlv320aic31xx.txt
new file mode 100644
index 000000000000..74c66dee3e14
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/tlv320aic31xx.txt
@@ -0,0 +1,61 @@
1Texas Instruments - tlv320aic31xx Codec module
2
3The tlv320aic31xx serial control bus communicates through I2C protocols
4
5Required properties:
6
7- compatible - "string" - One of:
8 "ti,tlv320aic310x" - Generic TLV320AIC31xx with mono speaker amp
9 "ti,tlv320aic311x" - Generic TLV320AIC31xx with stereo speaker amp
10 "ti,tlv320aic3100" - TLV320AIC3100 (mono speaker amp, no MiniDSP)
11 "ti,tlv320aic3110" - TLV320AIC3110 (stereo speaker amp, no MiniDSP)
12 "ti,tlv320aic3120" - TLV320AIC3120 (mono speaker amp, MiniDSP)
13 "ti,tlv320aic3111" - TLV320AIC3111 (stereo speaker amp, MiniDSP)
14
15- reg - <int> - I2C slave address
16
17
18Optional properties:
19
20- gpio-reset - gpio pin number used for codec reset
21- ai31xx-micbias-vg - MicBias Voltage setting
22 1 or MICBIAS_2_0V - MICBIAS output is powered to 2.0V
23 2 or MICBIAS_2_5V - MICBIAS output is powered to 2.5V
24 3 or MICBIAS_AVDD - MICBIAS output is connected to AVDD
25 If this node is not mentioned or if the value is unknown, then
26 micbias is set to 2.0V.
27- HPVDD-supply, SPRVDD-supply, SPLVDD-supply, AVDD-supply, IOVDD-supply,
28 DVDD-supply : power supplies for the device as covered in
29 Documentation/devicetree/bindings/regulator/regulator.txt
30
31CODEC output pins:
32 * HPL
33 * HPR
34 * SPL, devices with stereo speaker amp
35 * SPR, devices with stereo speaker amp
36 * SPK, devices with mono speaker amp
37 * MICBIAS
38
39CODEC input pins:
40 * MIC1LP
41 * MIC1RP
42 * MIC1LM
43
44The pins can be used in referring sound node's audio-routing property.
45
46Example:
47#include <dt-bindings/sound/tlv320aic31xx-micbias.h>
48
49tlv320aic31xx: tlv320aic31xx@18 {
50 compatible = "ti,tlv320aic311x";
51 reg = <0x18>;
52
53 ai31xx-micbias-vg = <MICBIAS_OFF>;
54
55 HPVDD-supply = <&regulator>;
56 SPRVDD-supply = <&regulator>;
57 SPLVDD-supply = <&regulator>;
58 AVDD-supply = <&regulator>;
59 IOVDD-supply = <&regulator>;
60 DVDD-supply = <&regulator>;
61};
diff --git a/Documentation/devicetree/bindings/sound/tlv320aic32x4.txt b/Documentation/devicetree/bindings/sound/tlv320aic32x4.txt
new file mode 100644
index 000000000000..5e2741af27be
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/tlv320aic32x4.txt
@@ -0,0 +1,30 @@
1Texas Instruments - tlv320aic32x4 Codec module
2
3The tlv320aic32x4 serial control bus communicates through I2C protocols
4
5Required properties:
6 - compatible: Should be "ti,tlv320aic32x4"
7 - reg: I2C slave address
8 - supply-*: Required supply regulators are:
9 "iov" - digital IO power supply
10 "ldoin" - LDO power supply
11 "dv" - Digital core power supply
12 "av" - Analog core power supply
13 If you supply ldoin, dv and av are optional. Otherwise they are required
14 See regulator/regulator.txt for more information about the detailed binding
15 format.
16
17Optional properties:
18 - reset-gpios: Reset-GPIO phandle with args as described in gpio/gpio.txt
19 - clocks/clock-names: Clock named 'mclk' for the master clock of the codec.
20 See clock/clock-bindings.txt for information about the detailed format.
21
22
23Example:
24
25codec: tlv320aic32x4@18 {
26 compatible = "ti,tlv320aic32x4";
27 reg = <0x18>;
28 clocks = <&clks 201>;
29 clock-names = "mclk";
30};
diff --git a/Documentation/devicetree/bindings/sound/tlv320aic3x.txt b/Documentation/devicetree/bindings/sound/tlv320aic3x.txt
index 9d8ea14db490..5e6040c2c2e9 100644
--- a/Documentation/devicetree/bindings/sound/tlv320aic3x.txt
+++ b/Documentation/devicetree/bindings/sound/tlv320aic3x.txt
@@ -6,7 +6,6 @@ Required properties:
6 6
7- compatible - "string" - One of: 7- compatible - "string" - One of:
8 "ti,tlv320aic3x" - Generic TLV320AIC3x device 8 "ti,tlv320aic3x" - Generic TLV320AIC3x device
9 "ti,tlv320aic32x4" - TLV320AIC32x4
10 "ti,tlv320aic33" - TLV320AIC33 9 "ti,tlv320aic33" - TLV320AIC33
11 "ti,tlv320aic3007" - TLV320AIC3007 10 "ti,tlv320aic3007" - TLV320AIC3007
12 "ti,tlv320aic3106" - TLV320AIC3106 11 "ti,tlv320aic3106" - TLV320AIC3106
diff --git a/Documentation/devicetree/bindings/sound/widgets.txt b/Documentation/devicetree/bindings/sound/widgets.txt
new file mode 100644
index 000000000000..b6de5ba3b2de
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/widgets.txt
@@ -0,0 +1,20 @@
1Widgets:
2
3This mainly specifies audio off-codec DAPM widgets.
4
5Each entry is a pair of strings in DT:
6
7 "template-wname", "user-supplied-wname"
8
9The "template-wname" being the template widget name and currently includes:
10"Microphone", "Line", "Headphone" and "Speaker".
11
12The "user-supplied-wname" being the user specified widget name.
13
14For instance:
15 simple-audio-widgets =
16 "Microphone", "Microphone Jack",
17 "Line", "Line In Jack",
18 "Line", "Line Out Jack",
19 "Headphone", "Headphone Jack",
20 "Speaker", "Speaker External";
diff --git a/Documentation/networking/packet_mmap.txt b/Documentation/networking/packet_mmap.txt
index 1404674c0a02..6fea79efb4cb 100644
--- a/Documentation/networking/packet_mmap.txt
+++ b/Documentation/networking/packet_mmap.txt
@@ -453,7 +453,7 @@ TP_STATUS_COPY : This flag indicates that the frame (and associated
453 enabled previously with setsockopt() and 453 enabled previously with setsockopt() and
454 the PACKET_COPY_THRESH option. 454 the PACKET_COPY_THRESH option.
455 455
456 The number of frames than can be buffered to 456 The number of frames that can be buffered to
457 be read with recvfrom is limited like a normal socket. 457 be read with recvfrom is limited like a normal socket.
458 See the SO_RCVBUF option in the socket (7) man page. 458 See the SO_RCVBUF option in the socket (7) man page.
459 459
diff --git a/Documentation/networking/timestamping.txt b/Documentation/networking/timestamping.txt
index 661d3c316a17..048c92b487f6 100644
--- a/Documentation/networking/timestamping.txt
+++ b/Documentation/networking/timestamping.txt
@@ -21,26 +21,38 @@ has such a feature).
21 21
22SO_TIMESTAMPING: 22SO_TIMESTAMPING:
23 23
24Instructs the socket layer which kind of information is wanted. The 24Instructs the socket layer which kind of information should be collected
25parameter is an integer with some of the following bits set. Setting 25and/or reported. The parameter is an integer with some of the following
26other bits is an error and doesn't change the current state. 26bits set. Setting other bits is an error and doesn't change the current
27 27state.
28SOF_TIMESTAMPING_TX_HARDWARE: try to obtain send time stamp in hardware 28
29SOF_TIMESTAMPING_TX_SOFTWARE: if SOF_TIMESTAMPING_TX_HARDWARE is off or 29Four of the bits are requests to the stack to try to generate
30 fails, then do it in software 30timestamps. Any combination of them is valid.
31SOF_TIMESTAMPING_RX_HARDWARE: return the original, unmodified time stamp 31
32 as generated by the hardware 32SOF_TIMESTAMPING_TX_HARDWARE: try to obtain send time stamps in hardware
33SOF_TIMESTAMPING_RX_SOFTWARE: if SOF_TIMESTAMPING_RX_HARDWARE is off or 33SOF_TIMESTAMPING_TX_SOFTWARE: try to obtain send time stamps in software
34 fails, then do it in software 34SOF_TIMESTAMPING_RX_HARDWARE: try to obtain receive time stamps in hardware
35SOF_TIMESTAMPING_RAW_HARDWARE: return original raw hardware time stamp 35SOF_TIMESTAMPING_RX_SOFTWARE: try to obtain receive time stamps in software
36SOF_TIMESTAMPING_SYS_HARDWARE: return hardware time stamp transformed to 36
37 the system time base 37The other three bits control which timestamps will be reported in a
38SOF_TIMESTAMPING_SOFTWARE: return system time stamp generated in 38generated control message. If none of these bits are set or if none of
39 software 39the set bits correspond to data that is available, then the control
40 40message will not be generated:
41SOF_TIMESTAMPING_TX/RX determine how time stamps are generated. 41
42SOF_TIMESTAMPING_RAW/SYS determine how they are reported in the 42SOF_TIMESTAMPING_SOFTWARE: report systime if available
43following control message: 43SOF_TIMESTAMPING_SYS_HARDWARE: report hwtimetrans if available
44SOF_TIMESTAMPING_RAW_HARDWARE: report hwtimeraw if available
45
46It is worth noting that timestamps may be collected for reasons other
47than being requested by a particular socket with
48SOF_TIMESTAMPING_[TR]X_(HARD|SOFT)WARE. For example, most drivers that
49can generate hardware receive timestamps ignore
50SOF_TIMESTAMPING_RX_HARDWARE. It is still a good idea to set that flag
51in case future drivers pay attention.
52
53If timestamps are reported, they will appear in a control message with
54cmsg_level==SOL_SOCKET, cmsg_type==SO_TIMESTAMPING, and a payload like
55this:
44 56
45struct scm_timestamping { 57struct scm_timestamping {
46 struct timespec systime; 58 struct timespec systime;
diff --git a/MAINTAINERS b/MAINTAINERS
index b7befe758429..7c42d59effab 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1738,6 +1738,7 @@ F: include/uapi/linux/bfs_fs.h
1738BLACKFIN ARCHITECTURE 1738BLACKFIN ARCHITECTURE
1739M: Steven Miao <realmz6@gmail.com> 1739M: Steven Miao <realmz6@gmail.com>
1740L: adi-buildroot-devel@lists.sourceforge.net 1740L: adi-buildroot-devel@lists.sourceforge.net
1741T: git git://git.code.sf.net/p/adi-linux/code
1741W: http://blackfin.uclinux.org 1742W: http://blackfin.uclinux.org
1742S: Supported 1743S: Supported
1743F: arch/blackfin/ 1744F: arch/blackfin/
@@ -2202,6 +2203,13 @@ L: alsa-devel@alsa-project.org (moderated for non-subscribers)
2202S: Odd Fixes 2203S: Odd Fixes
2203F: sound/soc/codecs/cs4270* 2204F: sound/soc/codecs/cs4270*
2204 2205
2206CIRRUS LOGIC AUDIO CODEC DRIVERS
2207M: Brian Austin <brian.austin@cirrus.com>
2208M: Paul Handrigan <Paul.Handrigan@cirrus.com>
2209L: alsa-devel@alsa-project.org (moderated for non-subscribers)
2210S: Maintained
2211F: sound/soc/codecs/cs*
2212
2205CLEANCACHE API 2213CLEANCACHE API
2206M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> 2214M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
2207L: linux-kernel@vger.kernel.org 2215L: linux-kernel@vger.kernel.org
@@ -6002,6 +6010,8 @@ F: include/linux/netdevice.h
6002F: include/uapi/linux/in.h 6010F: include/uapi/linux/in.h
6003F: include/uapi/linux/net.h 6011F: include/uapi/linux/net.h
6004F: include/uapi/linux/netdevice.h 6012F: include/uapi/linux/netdevice.h
6013F: tools/net/
6014F: tools/testing/selftests/net/
6005 6015
6006NETWORKING [IPv4/IPv6] 6016NETWORKING [IPv4/IPv6]
6007M: "David S. Miller" <davem@davemloft.net> 6017M: "David S. Miller" <davem@davemloft.net>
diff --git a/Makefile b/Makefile
index 1a2628ee5d91..ef779ec26f62 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 3 1VERSION = 3
2PATCHLEVEL = 14 2PATCHLEVEL = 14
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc6 4EXTRAVERSION = -rc7
5NAME = Shuffling Zombie Juror 5NAME = Shuffling Zombie Juror
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/arm/mach-shmobile/board-armadillo800eva.c b/arch/arm/mach-shmobile/board-armadillo800eva.c
index 93533e2710a8..9323854242ca 100644
--- a/arch/arm/mach-shmobile/board-armadillo800eva.c
+++ b/arch/arm/mach-shmobile/board-armadillo800eva.c
@@ -988,14 +988,12 @@ static struct asoc_simple_card_info fsi_wm8978_info = {
988 .card = "FSI2A-WM8978", 988 .card = "FSI2A-WM8978",
989 .codec = "wm8978.0-001a", 989 .codec = "wm8978.0-001a",
990 .platform = "sh_fsi2", 990 .platform = "sh_fsi2",
991 .daifmt = SND_SOC_DAIFMT_I2S, 991 .daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM,
992 .cpu_dai = { 992 .cpu_dai = {
993 .name = "fsia-dai", 993 .name = "fsia-dai",
994 .fmt = SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_IB_NF,
995 }, 994 },
996 .codec_dai = { 995 .codec_dai = {
997 .name = "wm8978-hifi", 996 .name = "wm8978-hifi",
998 .fmt = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_NB_NF,
999 .sysclk = 12288000, 997 .sysclk = 12288000,
1000 }, 998 },
1001}; 999};
diff --git a/arch/arm/mach-shmobile/board-kzm9g.c b/arch/arm/mach-shmobile/board-kzm9g.c
index bc40b853ffd3..03dc3ac84502 100644
--- a/arch/arm/mach-shmobile/board-kzm9g.c
+++ b/arch/arm/mach-shmobile/board-kzm9g.c
@@ -589,14 +589,12 @@ static struct asoc_simple_card_info fsi2_ak4648_info = {
589 .card = "FSI2A-AK4648", 589 .card = "FSI2A-AK4648",
590 .codec = "ak4642-codec.0-0012", 590 .codec = "ak4642-codec.0-0012",
591 .platform = "sh_fsi2", 591 .platform = "sh_fsi2",
592 .daifmt = SND_SOC_DAIFMT_LEFT_J, 592 .daifmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM,
593 .cpu_dai = { 593 .cpu_dai = {
594 .name = "fsia-dai", 594 .name = "fsia-dai",
595 .fmt = SND_SOC_DAIFMT_CBS_CFS,
596 }, 595 },
597 .codec_dai = { 596 .codec_dai = {
598 .name = "ak4642-hifi", 597 .name = "ak4642-hifi",
599 .fmt = SND_SOC_DAIFMT_CBM_CFM,
600 .sysclk = 11289600, 598 .sysclk = 11289600,
601 }, 599 },
602}; 600};
diff --git a/arch/arm/mach-shmobile/board-mackerel.c b/arch/arm/mach-shmobile/board-mackerel.c
index 3aba0372f630..0ff4d8e45cf7 100644
--- a/arch/arm/mach-shmobile/board-mackerel.c
+++ b/arch/arm/mach-shmobile/board-mackerel.c
@@ -509,9 +509,9 @@ static struct asoc_simple_card_info fsi2_hdmi_info = {
509 .card = "FSI2B-HDMI", 509 .card = "FSI2B-HDMI",
510 .codec = "sh-mobile-hdmi", 510 .codec = "sh-mobile-hdmi",
511 .platform = "sh_fsi2", 511 .platform = "sh_fsi2",
512 .daifmt = SND_SOC_DAIFMT_CBS_CFS,
512 .cpu_dai = { 513 .cpu_dai = {
513 .name = "fsib-dai", 514 .name = "fsib-dai",
514 .fmt = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF,
515 }, 515 },
516 .codec_dai = { 516 .codec_dai = {
517 .name = "sh_mobile_hdmi-hifi", 517 .name = "sh_mobile_hdmi-hifi",
@@ -905,14 +905,12 @@ static struct asoc_simple_card_info fsi2_ak4643_info = {
905 .card = "FSI2A-AK4643", 905 .card = "FSI2A-AK4643",
906 .codec = "ak4642-codec.0-0013", 906 .codec = "ak4642-codec.0-0013",
907 .platform = "sh_fsi2", 907 .platform = "sh_fsi2",
908 .daifmt = SND_SOC_DAIFMT_LEFT_J, 908 .daifmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM,
909 .cpu_dai = { 909 .cpu_dai = {
910 .name = "fsia-dai", 910 .name = "fsia-dai",
911 .fmt = SND_SOC_DAIFMT_CBS_CFS,
912 }, 911 },
913 .codec_dai = { 912 .codec_dai = {
914 .name = "ak4642-hifi", 913 .name = "ak4642-hifi",
915 .fmt = SND_SOC_DAIFMT_CBM_CFM,
916 .sysclk = 11289600, 914 .sysclk = 11289600,
917 }, 915 },
918}; 916};
diff --git a/arch/cris/include/asm/bitops.h b/arch/cris/include/asm/bitops.h
index 184066ceb1f6..053c17b36559 100644
--- a/arch/cris/include/asm/bitops.h
+++ b/arch/cris/include/asm/bitops.h
@@ -144,7 +144,7 @@ static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
144 * definition, which doesn't have the same semantics. We don't want to 144 * definition, which doesn't have the same semantics. We don't want to
145 * use -fno-builtin, so just hide the name ffs. 145 * use -fno-builtin, so just hide the name ffs.
146 */ 146 */
147#define ffs kernel_ffs 147#define ffs(x) kernel_ffs(x)
148 148
149#include <asm-generic/bitops/fls.h> 149#include <asm-generic/bitops/fls.h>
150#include <asm-generic/bitops/__fls.h> 150#include <asm-generic/bitops/__fls.h>
diff --git a/arch/ia64/kernel/uncached.c b/arch/ia64/kernel/uncached.c
index a96bcf83a735..20e8a9b21d75 100644
--- a/arch/ia64/kernel/uncached.c
+++ b/arch/ia64/kernel/uncached.c
@@ -98,7 +98,7 @@ static int uncached_add_chunk(struct uncached_pool *uc_pool, int nid)
98 /* attempt to allocate a granule's worth of cached memory pages */ 98 /* attempt to allocate a granule's worth of cached memory pages */
99 99
100 page = alloc_pages_exact_node(nid, 100 page = alloc_pages_exact_node(nid,
101 GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, 101 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
102 IA64_GRANULE_SHIFT-PAGE_SHIFT); 102 IA64_GRANULE_SHIFT-PAGE_SHIFT);
103 if (!page) { 103 if (!page) {
104 mutex_unlock(&uc_pool->add_chunk_mutex); 104 mutex_unlock(&uc_pool->add_chunk_mutex);
diff --git a/arch/powerpc/platforms/cell/ras.c b/arch/powerpc/platforms/cell/ras.c
index 5ec1e47a0d77..e865d748179b 100644
--- a/arch/powerpc/platforms/cell/ras.c
+++ b/arch/powerpc/platforms/cell/ras.c
@@ -123,7 +123,8 @@ static int __init cbe_ptcal_enable_on_node(int nid, int order)
123 123
124 area->nid = nid; 124 area->nid = nid;
125 area->order = order; 125 area->order = order;
126 area->pages = alloc_pages_exact_node(area->nid, GFP_KERNEL|GFP_THISNODE, 126 area->pages = alloc_pages_exact_node(area->nid,
127 GFP_KERNEL|__GFP_THISNODE,
127 area->order); 128 area->order);
128 129
129 if (!area->pages) { 130 if (!area->pages) {
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index 5bc3a15465c7..85d5255d259f 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -861,14 +861,12 @@ static struct asoc_simple_card_info fsi_da7210_info = {
861 .card = "FSIB-DA7210", 861 .card = "FSIB-DA7210",
862 .codec = "da7210.0-001a", 862 .codec = "da7210.0-001a",
863 .platform = "sh_fsi.0", 863 .platform = "sh_fsi.0",
864 .daifmt = SND_SOC_DAIFMT_I2S, 864 .daifmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM,
865 .cpu_dai = { 865 .cpu_dai = {
866 .name = "fsib-dai", 866 .name = "fsib-dai",
867 .fmt = SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_IB_NF,
868 }, 867 },
869 .codec_dai = { 868 .codec_dai = {
870 .name = "da7210-hifi", 869 .name = "da7210-hifi",
871 .fmt = SND_SOC_DAIFMT_CBM_CFM,
872 }, 870 },
873}; 871};
874 872
diff --git a/arch/sh/boards/mach-se/7724/setup.c b/arch/sh/boards/mach-se/7724/setup.c
index 21e4230659a5..1162bc6945a3 100644
--- a/arch/sh/boards/mach-se/7724/setup.c
+++ b/arch/sh/boards/mach-se/7724/setup.c
@@ -304,14 +304,12 @@ static struct asoc_simple_card_info fsi_ak4642_info = {
304 .card = "FSIA-AK4642", 304 .card = "FSIA-AK4642",
305 .codec = "ak4642-codec.0-0012", 305 .codec = "ak4642-codec.0-0012",
306 .platform = "sh_fsi.0", 306 .platform = "sh_fsi.0",
307 .daifmt = SND_SOC_DAIFMT_LEFT_J, 307 .daifmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBM_CFM,
308 .cpu_dai = { 308 .cpu_dai = {
309 .name = "fsia-dai", 309 .name = "fsia-dai",
310 .fmt = SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_IB_NF,
311 }, 310 },
312 .codec_dai = { 311 .codec_dai = {
313 .name = "ak4642-hifi", 312 .name = "ak4642-hifi",
314 .fmt = SND_SOC_DAIFMT_CBM_CFM,
315 .sysclk = 11289600, 313 .sysclk = 11289600,
316 }, 314 },
317}; 315};
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index c026cca5602c..f3aaf231b4e5 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -341,10 +341,6 @@ config X86_USE_3DNOW
341 def_bool y 341 def_bool y
342 depends on (MCYRIXIII || MK7 || MGEODE_LX) && !UML 342 depends on (MCYRIXIII || MK7 || MGEODE_LX) && !UML
343 343
344config X86_OOSTORE
345 def_bool y
346 depends on (MWINCHIP3D || MWINCHIPC6) && MTRR
347
348# 344#
349# P6_NOPs are a relatively minor optimization that require a family >= 345# P6_NOPs are a relatively minor optimization that require a family >=
350# 6 processor, except that it is broken on certain VIA chips. 346# 6 processor, except that it is broken on certain VIA chips.
diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
index 04a48903b2eb..69bbb4845020 100644
--- a/arch/x86/include/asm/barrier.h
+++ b/arch/x86/include/asm/barrier.h
@@ -85,11 +85,7 @@
85#else 85#else
86# define smp_rmb() barrier() 86# define smp_rmb() barrier()
87#endif 87#endif
88#ifdef CONFIG_X86_OOSTORE 88#define smp_wmb() barrier()
89# define smp_wmb() wmb()
90#else
91# define smp_wmb() barrier()
92#endif
93#define smp_read_barrier_depends() read_barrier_depends() 89#define smp_read_barrier_depends() read_barrier_depends()
94#define set_mb(var, value) do { (void)xchg(&var, value); } while (0) 90#define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
95#else /* !SMP */ 91#else /* !SMP */
@@ -100,7 +96,7 @@
100#define set_mb(var, value) do { var = value; barrier(); } while (0) 96#define set_mb(var, value) do { var = value; barrier(); } while (0)
101#endif /* SMP */ 97#endif /* SMP */
102 98
103#if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE) 99#if defined(CONFIG_X86_PPRO_FENCE)
104 100
105/* 101/*
106 * For either of these options x86 doesn't have a strong TSO memory 102 * For either of these options x86 doesn't have a strong TSO memory
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index 34f69cb9350a..91d9c69a629e 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -237,7 +237,7 @@ memcpy_toio(volatile void __iomem *dst, const void *src, size_t count)
237 237
238static inline void flush_write_buffers(void) 238static inline void flush_write_buffers(void)
239{ 239{
240#if defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE) 240#if defined(CONFIG_X86_PPRO_FENCE)
241 asm volatile("lock; addl $0,0(%%esp)": : :"memory"); 241 asm volatile("lock; addl $0,0(%%esp)": : :"memory");
242#endif 242#endif
243} 243}
diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
index bf156ded74b5..0f62f5482d91 100644
--- a/arch/x86/include/asm/spinlock.h
+++ b/arch/x86/include/asm/spinlock.h
@@ -26,10 +26,9 @@
26# define LOCK_PTR_REG "D" 26# define LOCK_PTR_REG "D"
27#endif 27#endif
28 28
29#if defined(CONFIG_X86_32) && \ 29#if defined(CONFIG_X86_32) && (defined(CONFIG_X86_PPRO_FENCE))
30 (defined(CONFIG_X86_OOSTORE) || defined(CONFIG_X86_PPRO_FENCE))
31/* 30/*
32 * On PPro SMP or if we are using OOSTORE, we use a locked operation to unlock 31 * On PPro SMP, we use a locked operation to unlock
33 * (PPro errata 66, 92) 32 * (PPro errata 66, 92)
34 */ 33 */
35# define UNLOCK_LOCK_PREFIX LOCK_PREFIX 34# define UNLOCK_LOCK_PREFIX LOCK_PREFIX
diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index 8779edab684e..d8fba5c15fbd 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -8,236 +8,6 @@
8 8
9#include "cpu.h" 9#include "cpu.h"
10 10
11#ifdef CONFIG_X86_OOSTORE
12
13static u32 power2(u32 x)
14{
15 u32 s = 1;
16
17 while (s <= x)
18 s <<= 1;
19
20 return s >>= 1;
21}
22
23
24/*
25 * Set up an actual MCR
26 */
27static void centaur_mcr_insert(int reg, u32 base, u32 size, int key)
28{
29 u32 lo, hi;
30
31 hi = base & ~0xFFF;
32 lo = ~(size-1); /* Size is a power of 2 so this makes a mask */
33 lo &= ~0xFFF; /* Remove the ctrl value bits */
34 lo |= key; /* Attribute we wish to set */
35 wrmsr(reg+MSR_IDT_MCR0, lo, hi);
36 mtrr_centaur_report_mcr(reg, lo, hi); /* Tell the mtrr driver */
37}
38
39/*
40 * Figure what we can cover with MCR's
41 *
42 * Shortcut: We know you can't put 4Gig of RAM on a winchip
43 */
44static u32 ramtop(void)
45{
46 u32 clip = 0xFFFFFFFFUL;
47 u32 top = 0;
48 int i;
49
50 for (i = 0; i < e820.nr_map; i++) {
51 unsigned long start, end;
52
53 if (e820.map[i].addr > 0xFFFFFFFFUL)
54 continue;
55 /*
56 * Don't MCR over reserved space. Ignore the ISA hole
57 * we frob around that catastrophe already
58 */
59 if (e820.map[i].type == E820_RESERVED) {
60 if (e820.map[i].addr >= 0x100000UL &&
61 e820.map[i].addr < clip)
62 clip = e820.map[i].addr;
63 continue;
64 }
65 start = e820.map[i].addr;
66 end = e820.map[i].addr + e820.map[i].size;
67 if (start >= end)
68 continue;
69 if (end > top)
70 top = end;
71 }
72 /*
73 * Everything below 'top' should be RAM except for the ISA hole.
74 * Because of the limited MCR's we want to map NV/ACPI into our
75 * MCR range for gunk in RAM
76 *
77 * Clip might cause us to MCR insufficient RAM but that is an
78 * acceptable failure mode and should only bite obscure boxes with
79 * a VESA hole at 15Mb
80 *
81 * The second case Clip sometimes kicks in is when the EBDA is marked
82 * as reserved. Again we fail safe with reasonable results
83 */
84 if (top > clip)
85 top = clip;
86
87 return top;
88}
89
90/*
91 * Compute a set of MCR's to give maximum coverage
92 */
93static int centaur_mcr_compute(int nr, int key)
94{
95 u32 mem = ramtop();
96 u32 root = power2(mem);
97 u32 base = root;
98 u32 top = root;
99 u32 floor = 0;
100 int ct = 0;
101
102 while (ct < nr) {
103 u32 fspace = 0;
104 u32 high;
105 u32 low;
106
107 /*
108 * Find the largest block we will fill going upwards
109 */
110 high = power2(mem-top);
111
112 /*
113 * Find the largest block we will fill going downwards
114 */
115 low = base/2;
116
117 /*
118 * Don't fill below 1Mb going downwards as there
119 * is an ISA hole in the way.
120 */
121 if (base <= 1024*1024)
122 low = 0;
123
124 /*
125 * See how much space we could cover by filling below
126 * the ISA hole
127 */
128
129 if (floor == 0)
130 fspace = 512*1024;
131 else if (floor == 512*1024)
132 fspace = 128*1024;
133
134 /* And forget ROM space */
135
136 /*
137 * Now install the largest coverage we get
138 */
139 if (fspace > high && fspace > low) {
140 centaur_mcr_insert(ct, floor, fspace, key);
141 floor += fspace;
142 } else if (high > low) {
143 centaur_mcr_insert(ct, top, high, key);
144 top += high;
145 } else if (low > 0) {
146 base -= low;
147 centaur_mcr_insert(ct, base, low, key);
148 } else
149 break;
150 ct++;
151 }
152 /*
153 * We loaded ct values. We now need to set the mask. The caller
154 * must do this bit.
155 */
156 return ct;
157}
158
159static void centaur_create_optimal_mcr(void)
160{
161 int used;
162 int i;
163
164 /*
165 * Allocate up to 6 mcrs to mark as much of ram as possible
166 * as write combining and weak write ordered.
167 *
168 * To experiment with: Linux never uses stack operations for
169 * mmio spaces so we could globally enable stack operation wc
170 *
171 * Load the registers with type 31 - full write combining, all
172 * writes weakly ordered.
173 */
174 used = centaur_mcr_compute(6, 31);
175
176 /*
177 * Wipe unused MCRs
178 */
179 for (i = used; i < 8; i++)
180 wrmsr(MSR_IDT_MCR0+i, 0, 0);
181}
182
183static void winchip2_create_optimal_mcr(void)
184{
185 u32 lo, hi;
186 int used;
187 int i;
188
189 /*
190 * Allocate up to 6 mcrs to mark as much of ram as possible
191 * as write combining, weak store ordered.
192 *
193 * Load the registers with type 25
194 * 8 - weak write ordering
195 * 16 - weak read ordering
196 * 1 - write combining
197 */
198 used = centaur_mcr_compute(6, 25);
199
200 /*
201 * Mark the registers we are using.
202 */
203 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
204 for (i = 0; i < used; i++)
205 lo |= 1<<(9+i);
206 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
207
208 /*
209 * Wipe unused MCRs
210 */
211
212 for (i = used; i < 8; i++)
213 wrmsr(MSR_IDT_MCR0+i, 0, 0);
214}
215
216/*
217 * Handle the MCR key on the Winchip 2.
218 */
219static void winchip2_unprotect_mcr(void)
220{
221 u32 lo, hi;
222 u32 key;
223
224 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
225 lo &= ~0x1C0; /* blank bits 8-6 */
226 key = (lo>>17) & 7;
227 lo |= key<<6; /* replace with unlock key */
228 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
229}
230
231static void winchip2_protect_mcr(void)
232{
233 u32 lo, hi;
234
235 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
236 lo &= ~0x1C0; /* blank bits 8-6 */
237 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
238}
239#endif /* CONFIG_X86_OOSTORE */
240
241#define ACE_PRESENT (1 << 6) 11#define ACE_PRESENT (1 << 6)
242#define ACE_ENABLED (1 << 7) 12#define ACE_ENABLED (1 << 7)
243#define ACE_FCR (1 << 28) /* MSR_VIA_FCR */ 13#define ACE_FCR (1 << 28) /* MSR_VIA_FCR */
@@ -362,20 +132,6 @@ static void init_centaur(struct cpuinfo_x86 *c)
362 fcr_clr = DPDC; 132 fcr_clr = DPDC;
363 printk(KERN_NOTICE "Disabling bugged TSC.\n"); 133 printk(KERN_NOTICE "Disabling bugged TSC.\n");
364 clear_cpu_cap(c, X86_FEATURE_TSC); 134 clear_cpu_cap(c, X86_FEATURE_TSC);
365#ifdef CONFIG_X86_OOSTORE
366 centaur_create_optimal_mcr();
367 /*
368 * Enable:
369 * write combining on non-stack, non-string
370 * write combining on string, all types
371 * weak write ordering
372 *
373 * The C6 original lacks weak read order
374 *
375 * Note 0x120 is write only on Winchip 1
376 */
377 wrmsr(MSR_IDT_MCR_CTRL, 0x01F0001F, 0);
378#endif
379 break; 135 break;
380 case 8: 136 case 8:
381 switch (c->x86_mask) { 137 switch (c->x86_mask) {
@@ -392,40 +148,12 @@ static void init_centaur(struct cpuinfo_x86 *c)
392 fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK| 148 fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|
393 E2MMX|EAMD3D; 149 E2MMX|EAMD3D;
394 fcr_clr = DPDC; 150 fcr_clr = DPDC;
395#ifdef CONFIG_X86_OOSTORE
396 winchip2_unprotect_mcr();
397 winchip2_create_optimal_mcr();
398 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
399 /*
400 * Enable:
401 * write combining on non-stack, non-string
402 * write combining on string, all types
403 * weak write ordering
404 */
405 lo |= 31;
406 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
407 winchip2_protect_mcr();
408#endif
409 break; 151 break;
410 case 9: 152 case 9:
411 name = "3"; 153 name = "3";
412 fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK| 154 fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|
413 E2MMX|EAMD3D; 155 E2MMX|EAMD3D;
414 fcr_clr = DPDC; 156 fcr_clr = DPDC;
415#ifdef CONFIG_X86_OOSTORE
416 winchip2_unprotect_mcr();
417 winchip2_create_optimal_mcr();
418 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
419 /*
420 * Enable:
421 * write combining on non-stack, non-string
422 * write combining on string, all types
423 * weak write ordering
424 */
425 lo |= 31;
426 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
427 winchip2_protect_mcr();
428#endif
429 break; 157 break;
430 default: 158 default:
431 name = "??"; 159 name = "??";
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
index c88f7f4b03ee..047f540cf3f7 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
@@ -3334,6 +3334,8 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
3334 if (!pmus) 3334 if (!pmus)
3335 return -ENOMEM; 3335 return -ENOMEM;
3336 3336
3337 type->pmus = pmus;
3338
3337 type->unconstrainted = (struct event_constraint) 3339 type->unconstrainted = (struct event_constraint)
3338 __EVENT_CONSTRAINT(0, (1ULL << type->num_counters) - 1, 3340 __EVENT_CONSTRAINT(0, (1ULL << type->num_counters) - 1,
3339 0, type->num_counters, 0, 0); 3341 0, type->num_counters, 0, 0);
@@ -3369,7 +3371,6 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
3369 } 3371 }
3370 3372
3371 type->pmu_group = &uncore_pmu_attr_group; 3373 type->pmu_group = &uncore_pmu_attr_group;
3372 type->pmus = pmus;
3373 return 0; 3374 return 0;
3374fail: 3375fail:
3375 uncore_type_exit(type); 3376 uncore_type_exit(type);
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
index e8368c6dd2a2..d5dd80814419 100644
--- a/arch/x86/kernel/i387.c
+++ b/arch/x86/kernel/i387.c
@@ -86,10 +86,19 @@ EXPORT_SYMBOL(__kernel_fpu_begin);
86 86
87void __kernel_fpu_end(void) 87void __kernel_fpu_end(void)
88{ 88{
89 if (use_eager_fpu()) 89 if (use_eager_fpu()) {
90 math_state_restore(); 90 /*
91 else 91 * For eager fpu, most the time, tsk_used_math() is true.
92 * Restore the user math as we are done with the kernel usage.
93 * At few instances during thread exit, signal handling etc,
94 * tsk_used_math() is false. Those few places will take proper
95 * actions, so we don't need to restore the math here.
96 */
97 if (likely(tsk_used_math(current)))
98 math_state_restore();
99 } else {
92 stts(); 100 stts();
101 }
93} 102}
94EXPORT_SYMBOL(__kernel_fpu_end); 103EXPORT_SYMBOL(__kernel_fpu_end);
95 104
diff --git a/arch/x86/kernel/quirks.c b/arch/x86/kernel/quirks.c
index 7c6acd4b8995..ff898bbf579d 100644
--- a/arch/x86/kernel/quirks.c
+++ b/arch/x86/kernel/quirks.c
@@ -529,7 +529,7 @@ static void quirk_amd_nb_node(struct pci_dev *dev)
529 return; 529 return;
530 530
531 pci_read_config_dword(nb_ht, 0x60, &val); 531 pci_read_config_dword(nb_ht, 0x60, &val);
532 node = val & 7; 532 node = pcibus_to_node(dev->bus) | (val & 7);
533 /* 533 /*
534 * Some hardware may return an invalid node ID, 534 * Some hardware may return an invalid node ID,
535 * so check it first: 535 * so check it first:
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index e81df8fce027..2de1bc09a8d4 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -3002,10 +3002,8 @@ static int cr8_write_interception(struct vcpu_svm *svm)
3002 u8 cr8_prev = kvm_get_cr8(&svm->vcpu); 3002 u8 cr8_prev = kvm_get_cr8(&svm->vcpu);
3003 /* instruction emulation calls kvm_set_cr8() */ 3003 /* instruction emulation calls kvm_set_cr8() */
3004 r = cr_interception(svm); 3004 r = cr_interception(svm);
3005 if (irqchip_in_kernel(svm->vcpu.kvm)) { 3005 if (irqchip_in_kernel(svm->vcpu.kvm))
3006 clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
3007 return r; 3006 return r;
3008 }
3009 if (cr8_prev <= kvm_get_cr8(&svm->vcpu)) 3007 if (cr8_prev <= kvm_get_cr8(&svm->vcpu))
3010 return r; 3008 return r;
3011 kvm_run->exit_reason = KVM_EXIT_SET_TPR; 3009 kvm_run->exit_reason = KVM_EXIT_SET_TPR;
@@ -3567,6 +3565,8 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu, int tpr, int irr)
3567 if (is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK)) 3565 if (is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK))
3568 return; 3566 return;
3569 3567
3568 clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
3569
3570 if (irr == -1) 3570 if (irr == -1)
3571 return; 3571 return;
3572 3572
diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
index 877b9a1b2152..01495755701b 100644
--- a/arch/x86/net/bpf_jit.S
+++ b/arch/x86/net/bpf_jit.S
@@ -140,7 +140,7 @@ bpf_slow_path_byte_msh:
140 push %r9; \ 140 push %r9; \
141 push SKBDATA; \ 141 push SKBDATA; \
142/* rsi already has offset */ \ 142/* rsi already has offset */ \
143 mov $SIZE,%ecx; /* size */ \ 143 mov $SIZE,%edx; /* size */ \
144 call bpf_internal_load_pointer_neg_helper; \ 144 call bpf_internal_load_pointer_neg_helper; \
145 test %rax,%rax; \ 145 test %rax,%rax; \
146 pop SKBDATA; \ 146 pop SKBDATA; \
diff --git a/arch/x86/um/asm/barrier.h b/arch/x86/um/asm/barrier.h
index 7d01b8c56c00..cc04e67bfd05 100644
--- a/arch/x86/um/asm/barrier.h
+++ b/arch/x86/um/asm/barrier.h
@@ -40,11 +40,7 @@
40#define smp_rmb() barrier() 40#define smp_rmb() barrier()
41#endif /* CONFIG_X86_PPRO_FENCE */ 41#endif /* CONFIG_X86_PPRO_FENCE */
42 42
43#ifdef CONFIG_X86_OOSTORE
44#define smp_wmb() wmb()
45#else /* CONFIG_X86_OOSTORE */
46#define smp_wmb() barrier() 43#define smp_wmb() barrier()
47#endif /* CONFIG_X86_OOSTORE */
48 44
49#define smp_read_barrier_depends() read_barrier_depends() 45#define smp_read_barrier_depends() read_barrier_depends()
50#define set_mb(var, value) do { (void)xchg(&var, value); } while (0) 46#define set_mb(var, value) do { (void)xchg(&var, value); } while (0)
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index b718806657cd..c40fb2e81bbc 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -71,6 +71,17 @@ static int acpi_sleep_prepare(u32 acpi_state)
71 return 0; 71 return 0;
72} 72}
73 73
74static bool acpi_sleep_state_supported(u8 sleep_state)
75{
76 acpi_status status;
77 u8 type_a, type_b;
78
79 status = acpi_get_sleep_type_data(sleep_state, &type_a, &type_b);
80 return ACPI_SUCCESS(status) && (!acpi_gbl_reduced_hardware
81 || (acpi_gbl_FADT.sleep_control.address
82 && acpi_gbl_FADT.sleep_status.address));
83}
84
74#ifdef CONFIG_ACPI_SLEEP 85#ifdef CONFIG_ACPI_SLEEP
75static u32 acpi_target_sleep_state = ACPI_STATE_S0; 86static u32 acpi_target_sleep_state = ACPI_STATE_S0;
76 87
@@ -604,15 +615,9 @@ static void acpi_sleep_suspend_setup(void)
604{ 615{
605 int i; 616 int i;
606 617
607 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) { 618 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++)
608 acpi_status status; 619 if (acpi_sleep_state_supported(i))
609 u8 type_a, type_b;
610
611 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
612 if (ACPI_SUCCESS(status)) {
613 sleep_states[i] = 1; 620 sleep_states[i] = 1;
614 }
615 }
616 621
617 suspend_set_ops(old_suspend_ordering ? 622 suspend_set_ops(old_suspend_ordering ?
618 &acpi_suspend_ops_old : &acpi_suspend_ops); 623 &acpi_suspend_ops_old : &acpi_suspend_ops);
@@ -740,11 +745,7 @@ static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
740 745
741static void acpi_sleep_hibernate_setup(void) 746static void acpi_sleep_hibernate_setup(void)
742{ 747{
743 acpi_status status; 748 if (!acpi_sleep_state_supported(ACPI_STATE_S4))
744 u8 type_a, type_b;
745
746 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
747 if (ACPI_FAILURE(status))
748 return; 749 return;
749 750
750 hibernation_set_ops(old_suspend_ordering ? 751 hibernation_set_ops(old_suspend_ordering ?
@@ -793,8 +794,6 @@ static void acpi_power_off(void)
793 794
794int __init acpi_sleep_init(void) 795int __init acpi_sleep_init(void)
795{ 796{
796 acpi_status status;
797 u8 type_a, type_b;
798 char supported[ACPI_S_STATE_COUNT * 3 + 1]; 797 char supported[ACPI_S_STATE_COUNT * 3 + 1];
799 char *pos = supported; 798 char *pos = supported;
800 int i; 799 int i;
@@ -806,8 +805,7 @@ int __init acpi_sleep_init(void)
806 acpi_sleep_suspend_setup(); 805 acpi_sleep_suspend_setup();
807 acpi_sleep_hibernate_setup(); 806 acpi_sleep_hibernate_setup();
808 807
809 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); 808 if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
810 if (ACPI_SUCCESS(status)) {
811 sleep_states[ACPI_STATE_S5] = 1; 809 sleep_states[ACPI_STATE_S5] = 1;
812 pm_power_off_prepare = acpi_power_off_prepare; 810 pm_power_off_prepare = acpi_power_off_prepare;
813 pm_power_off = acpi_power_off; 811 pm_power_off = acpi_power_off;
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 65d3f1b5966c..8cb2522d592a 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4225,8 +4225,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4225 4225
4226 /* devices that don't properly handle queued TRIM commands */ 4226 /* devices that don't properly handle queued TRIM commands */
4227 { "Micron_M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, }, 4227 { "Micron_M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
4228 { "Crucial_CT???M500SSD1", NULL, ATA_HORKAGE_NO_NCQ_TRIM, }, 4228 { "Crucial_CT???M500SSD*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
4229 { "Crucial_CT???M500SSD3", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
4230 4229
4231 /* 4230 /*
4232 * Some WD SATA-I drives spin up and down erratically when the link 4231 * Some WD SATA-I drives spin up and down erratically when the link
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 6a19515f8a45..4b2ed0c9e80d 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2240,6 +2240,18 @@ int regmap_get_val_bytes(struct regmap *map)
2240} 2240}
2241EXPORT_SYMBOL_GPL(regmap_get_val_bytes); 2241EXPORT_SYMBOL_GPL(regmap_get_val_bytes);
2242 2242
2243int regmap_parse_val(struct regmap *map, const void *buf,
2244 unsigned int *val)
2245{
2246 if (!map->format.parse_val)
2247 return -EINVAL;
2248
2249 *val = map->format.parse_val(buf);
2250
2251 return 0;
2252}
2253EXPORT_SYMBOL_GPL(regmap_parse_val);
2254
2243static int __init regmap_initcall(void) 2255static int __init regmap_initcall(void)
2244{ 2256{
2245 regmap_debugfs_initcall(); 2257 regmap_debugfs_initcall();
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index cf485d928903..199b52b7c3e1 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1129,7 +1129,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1129 per_cpu(cpufreq_cpu_data, j) = policy; 1129 per_cpu(cpufreq_cpu_data, j) = policy;
1130 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1130 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1131 1131
1132 if (cpufreq_driver->get) { 1132 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
1133 policy->cur = cpufreq_driver->get(policy->cpu); 1133 policy->cur = cpufreq_driver->get(policy->cpu);
1134 if (!policy->cur) { 1134 if (!policy->cur) {
1135 pr_err("%s: ->get() failed\n", __func__); 1135 pr_err("%s: ->get() failed\n", __func__);
@@ -2143,7 +2143,7 @@ int cpufreq_update_policy(unsigned int cpu)
2143 * BIOS might change freq behind our back 2143 * BIOS might change freq behind our back
2144 * -> ask driver for current freq and notify governors about a change 2144 * -> ask driver for current freq and notify governors about a change
2145 */ 2145 */
2146 if (cpufreq_driver->get) { 2146 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
2147 new_policy.cur = cpufreq_driver->get(cpu); 2147 new_policy.cur = cpufreq_driver->get(cpu);
2148 if (!policy->cur) { 2148 if (!policy->cur) {
2149 pr_debug("Driver did not initialize current freq"); 2149 pr_debug("Driver did not initialize current freq");
diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
index e22be8458d92..bbb17841a9e5 100644
--- a/drivers/gpu/drm/radeon/cik.c
+++ b/drivers/gpu/drm/radeon/cik.c
@@ -4134,8 +4134,11 @@ static void cik_cp_compute_enable(struct radeon_device *rdev, bool enable)
4134{ 4134{
4135 if (enable) 4135 if (enable)
4136 WREG32(CP_MEC_CNTL, 0); 4136 WREG32(CP_MEC_CNTL, 0);
4137 else 4137 else {
4138 WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT)); 4138 WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT));
4139 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
4140 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
4141 }
4139 udelay(50); 4142 udelay(50);
4140} 4143}
4141 4144
diff --git a/drivers/gpu/drm/radeon/cik_sdma.c b/drivers/gpu/drm/radeon/cik_sdma.c
index 1ecb3f1070e3..94626ea90fa5 100644
--- a/drivers/gpu/drm/radeon/cik_sdma.c
+++ b/drivers/gpu/drm/radeon/cik_sdma.c
@@ -264,6 +264,8 @@ static void cik_sdma_gfx_stop(struct radeon_device *rdev)
264 WREG32(SDMA0_GFX_RB_CNTL + reg_offset, rb_cntl); 264 WREG32(SDMA0_GFX_RB_CNTL + reg_offset, rb_cntl);
265 WREG32(SDMA0_GFX_IB_CNTL + reg_offset, 0); 265 WREG32(SDMA0_GFX_IB_CNTL + reg_offset, 0);
266 } 266 }
267 rdev->ring[R600_RING_TYPE_DMA_INDEX].ready = false;
268 rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX].ready = false;
267} 269}
268 270
269/** 271/**
@@ -291,6 +293,11 @@ void cik_sdma_enable(struct radeon_device *rdev, bool enable)
291 u32 me_cntl, reg_offset; 293 u32 me_cntl, reg_offset;
292 int i; 294 int i;
293 295
296 if (enable == false) {
297 cik_sdma_gfx_stop(rdev);
298 cik_sdma_rlc_stop(rdev);
299 }
300
294 for (i = 0; i < 2; i++) { 301 for (i = 0; i < 2; i++) {
295 if (i == 0) 302 if (i == 0)
296 reg_offset = SDMA0_REGISTER_OFFSET; 303 reg_offset = SDMA0_REGISTER_OFFSET;
@@ -420,10 +427,6 @@ static int cik_sdma_load_microcode(struct radeon_device *rdev)
420 if (!rdev->sdma_fw) 427 if (!rdev->sdma_fw)
421 return -EINVAL; 428 return -EINVAL;
422 429
423 /* stop the gfx rings and rlc compute queues */
424 cik_sdma_gfx_stop(rdev);
425 cik_sdma_rlc_stop(rdev);
426
427 /* halt the MEs */ 430 /* halt the MEs */
428 cik_sdma_enable(rdev, false); 431 cik_sdma_enable(rdev, false);
429 432
@@ -492,9 +495,6 @@ int cik_sdma_resume(struct radeon_device *rdev)
492 */ 495 */
493void cik_sdma_fini(struct radeon_device *rdev) 496void cik_sdma_fini(struct radeon_device *rdev)
494{ 497{
495 /* stop the gfx rings and rlc compute queues */
496 cik_sdma_gfx_stop(rdev);
497 cik_sdma_rlc_stop(rdev);
498 /* halt the MEs */ 498 /* halt the MEs */
499 cik_sdma_enable(rdev, false); 499 cik_sdma_enable(rdev, false);
500 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]); 500 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]);
diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
index 2aecd6dc2610..66ed3ea71440 100644
--- a/drivers/gpu/drm/radeon/radeon_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_kms.c
@@ -33,6 +33,13 @@
33#include <linux/vga_switcheroo.h> 33#include <linux/vga_switcheroo.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/pm_runtime.h> 35#include <linux/pm_runtime.h>
36
37#if defined(CONFIG_VGA_SWITCHEROO)
38bool radeon_is_px(void);
39#else
40static inline bool radeon_is_px(void) { return false; }
41#endif
42
36/** 43/**
37 * radeon_driver_unload_kms - Main unload function for KMS. 44 * radeon_driver_unload_kms - Main unload function for KMS.
38 * 45 *
@@ -130,7 +137,8 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
130 "Error during ACPI methods call\n"); 137 "Error during ACPI methods call\n");
131 } 138 }
132 139
133 if (radeon_runtime_pm != 0) { 140 if ((radeon_runtime_pm == 1) ||
141 ((radeon_runtime_pm == -1) && radeon_is_px())) {
134 pm_runtime_use_autosuspend(dev->dev); 142 pm_runtime_use_autosuspend(dev->dev);
135 pm_runtime_set_autosuspend_delay(dev->dev, 5000); 143 pm_runtime_set_autosuspend_delay(dev->dev, 5000);
136 pm_runtime_set_active(dev->dev); 144 pm_runtime_set_active(dev->dev);
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index a06651309388..214b7992a3aa 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -351,9 +351,11 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
351 351
352moved: 352moved:
353 if (bo->evicted) { 353 if (bo->evicted) {
354 ret = bdev->driver->invalidate_caches(bdev, bo->mem.placement); 354 if (bdev->driver->invalidate_caches) {
355 if (ret) 355 ret = bdev->driver->invalidate_caches(bdev, bo->mem.placement);
356 pr_err("Can not flush read caches\n"); 356 if (ret)
357 pr_err("Can not flush read caches\n");
358 }
357 bo->evicted = false; 359 bo->evicted = false;
358 } 360 }
359 361
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 801231c9ae48..0ce48e5a9cb4 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -339,11 +339,13 @@ int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
339 vma->vm_private_data = bo; 339 vma->vm_private_data = bo;
340 340
341 /* 341 /*
342 * PFNMAP is faster than MIXEDMAP due to reduced page 342 * We'd like to use VM_PFNMAP on shared mappings, where
343 * administration. So use MIXEDMAP only if private VMA, where 343 * (vma->vm_flags & VM_SHARED) != 0, for performance reasons,
344 * we need to support COW. 344 * but for some reason VM_PFNMAP + x86 PAT + write-combine is very
345 * bad for performance. Until that has been sorted out, use
346 * VM_MIXEDMAP on all mappings. See freedesktop.org bug #75719
345 */ 347 */
346 vma->vm_flags |= (vma->vm_flags & VM_SHARED) ? VM_PFNMAP : VM_MIXEDMAP; 348 vma->vm_flags |= VM_MIXEDMAP;
347 vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP; 349 vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
348 return 0; 350 return 0;
349out_unref: 351out_unref:
@@ -359,7 +361,7 @@ int ttm_fbdev_mmap(struct vm_area_struct *vma, struct ttm_buffer_object *bo)
359 361
360 vma->vm_ops = &ttm_bo_vm_ops; 362 vma->vm_ops = &ttm_bo_vm_ops;
361 vma->vm_private_data = ttm_bo_reference(bo); 363 vma->vm_private_data = ttm_bo_reference(bo);
362 vma->vm_flags |= (vma->vm_flags & VM_SHARED) ? VM_PFNMAP : VM_MIXEDMAP; 364 vma->vm_flags |= VM_MIXEDMAP;
363 vma->vm_flags |= VM_IO | VM_DONTEXPAND; 365 vma->vm_flags |= VM_IO | VM_DONTEXPAND;
364 return 0; 366 return 0;
365} 367}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index 82468d902915..e7af580ab977 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -830,6 +830,24 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
830 if (unlikely(ret != 0)) 830 if (unlikely(ret != 0))
831 goto out_unlock; 831 goto out_unlock;
832 832
833 /*
834 * A gb-aware client referencing a shared surface will
835 * expect a backup buffer to be present.
836 */
837 if (dev_priv->has_mob && req->shareable) {
838 uint32_t backup_handle;
839
840 ret = vmw_user_dmabuf_alloc(dev_priv, tfile,
841 res->backup_size,
842 true,
843 &backup_handle,
844 &res->backup);
845 if (unlikely(ret != 0)) {
846 vmw_resource_unreference(&res);
847 goto out_unlock;
848 }
849 }
850
833 tmp = vmw_resource_reference(&srf->res); 851 tmp = vmw_resource_reference(&srf->res);
834 ret = ttm_prime_object_init(tfile, res->backup_size, &user_srf->prime, 852 ret = ttm_prime_object_init(tfile, res->backup_size, &user_srf->prime,
835 req->shareable, VMW_RES_SURFACE, 853 req->shareable, VMW_RES_SURFACE,
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index 7ed828056414..91fab975063c 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -624,7 +624,8 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm)
624 624
625 /* Setup sound card */ 625 /* Setup sound card */
626 626
627 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 627 err = snd_card_new(&pm->pk->hdev->dev, index[dev], id[dev],
628 THIS_MODULE, 0, &card);
628 if (err < 0) { 629 if (err < 0) {
629 pk_error("failed to create pc-midi sound card\n"); 630 pk_error("failed to create pc-midi sound card\n");
630 err = -ENOMEM; 631 err = -ENOMEM;
@@ -660,8 +661,6 @@ static int pcmidi_snd_initialise(struct pcmidi_snd *pm)
660 snd_rawmidi_set_ops(rwmidi, SNDRV_RAWMIDI_STREAM_INPUT, 661 snd_rawmidi_set_ops(rwmidi, SNDRV_RAWMIDI_STREAM_INPUT,
661 &pcmidi_in_ops); 662 &pcmidi_in_ops);
662 663
663 snd_card_set_dev(card, &pm->pk->hdev->dev);
664
665 /* create sysfs variables */ 664 /* create sysfs variables */
666 err = device_create_file(&pm->pk->hdev->dev, 665 err = device_create_file(&pm->pk->hdev->dev,
667 sysfs_device_attr_channel); 666 sysfs_device_attr_channel);
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index f5ed03164d86..de17c5593d97 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -387,7 +387,7 @@ config I2C_CBUS_GPIO
387 387
388config I2C_CPM 388config I2C_CPM
389 tristate "Freescale CPM1 or CPM2 (MPC8xx/826x)" 389 tristate "Freescale CPM1 or CPM2 (MPC8xx/826x)"
390 depends on (CPM1 || CPM2) && OF_I2C 390 depends on CPM1 || CPM2
391 help 391 help
392 This supports the use of the I2C interface on Freescale 392 This supports the use of the I2C interface on Freescale
393 processors with CPM1 or CPM2. 393 processors with CPM1 or CPM2.
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 1af70145fab9..074b9c8e4cf0 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -979,12 +979,13 @@ static void issue_copy_real(struct dm_cache_migration *mg)
979 int r; 979 int r;
980 struct dm_io_region o_region, c_region; 980 struct dm_io_region o_region, c_region;
981 struct cache *cache = mg->cache; 981 struct cache *cache = mg->cache;
982 sector_t cblock = from_cblock(mg->cblock);
982 983
983 o_region.bdev = cache->origin_dev->bdev; 984 o_region.bdev = cache->origin_dev->bdev;
984 o_region.count = cache->sectors_per_block; 985 o_region.count = cache->sectors_per_block;
985 986
986 c_region.bdev = cache->cache_dev->bdev; 987 c_region.bdev = cache->cache_dev->bdev;
987 c_region.sector = from_cblock(mg->cblock) * cache->sectors_per_block; 988 c_region.sector = cblock * cache->sectors_per_block;
988 c_region.count = cache->sectors_per_block; 989 c_region.count = cache->sectors_per_block;
989 990
990 if (mg->writeback || mg->demote) { 991 if (mg->writeback || mg->demote) {
@@ -2464,20 +2465,18 @@ static int cache_map(struct dm_target *ti, struct bio *bio)
2464 bool discarded_block; 2465 bool discarded_block;
2465 struct dm_bio_prison_cell *cell; 2466 struct dm_bio_prison_cell *cell;
2466 struct policy_result lookup_result; 2467 struct policy_result lookup_result;
2467 struct per_bio_data *pb; 2468 struct per_bio_data *pb = init_per_bio_data(bio, pb_data_size);
2468 2469
2469 if (from_oblock(block) > from_oblock(cache->origin_blocks)) { 2470 if (unlikely(from_oblock(block) >= from_oblock(cache->origin_blocks))) {
2470 /* 2471 /*
2471 * This can only occur if the io goes to a partial block at 2472 * This can only occur if the io goes to a partial block at
2472 * the end of the origin device. We don't cache these. 2473 * the end of the origin device. We don't cache these.
2473 * Just remap to the origin and carry on. 2474 * Just remap to the origin and carry on.
2474 */ 2475 */
2475 remap_to_origin_clear_discard(cache, bio, block); 2476 remap_to_origin(cache, bio);
2476 return DM_MAPIO_REMAPPED; 2477 return DM_MAPIO_REMAPPED;
2477 } 2478 }
2478 2479
2479 pb = init_per_bio_data(bio, pb_data_size);
2480
2481 if (bio->bi_rw & (REQ_FLUSH | REQ_FUA | REQ_DISCARD)) { 2480 if (bio->bi_rw & (REQ_FLUSH | REQ_FUA | REQ_DISCARD)) {
2482 defer_bio(cache, bio); 2481 defer_bio(cache, bio);
2483 return DM_MAPIO_SUBMITTED; 2482 return DM_MAPIO_SUBMITTED;
diff --git a/drivers/media/pci/cx18/cx18-alsa-main.c b/drivers/media/pci/cx18/cx18-alsa-main.c
index b2c8c3439fea..ea272bcb38df 100644
--- a/drivers/media/pci/cx18/cx18-alsa-main.c
+++ b/drivers/media/pci/cx18/cx18-alsa-main.c
@@ -145,11 +145,12 @@ static int snd_cx18_init(struct v4l2_device *v4l2_dev)
145 /* This is a no-op for us. We'll use the cx->instance */ 145 /* This is a no-op for us. We'll use the cx->instance */
146 146
147 /* (2) Create a card instance */ 147 /* (2) Create a card instance */
148 ret = snd_card_create(SNDRV_DEFAULT_IDX1, /* use first available id */ 148 ret = snd_card_new(&cx->pci_dev->dev,
149 SNDRV_DEFAULT_STR1, /* xid from end of shortname*/ 149 SNDRV_DEFAULT_IDX1, /* use first available id */
150 THIS_MODULE, 0, &sc); 150 SNDRV_DEFAULT_STR1, /* xid from end of shortname*/
151 THIS_MODULE, 0, &sc);
151 if (ret) { 152 if (ret) {
152 CX18_ALSA_ERR("%s: snd_card_create() failed with err %d\n", 153 CX18_ALSA_ERR("%s: snd_card_new() failed with err %d\n",
153 __func__, ret); 154 __func__, ret);
154 goto err_exit; 155 goto err_exit;
155 } 156 }
diff --git a/drivers/media/pci/cx23885/cx23885-alsa.c b/drivers/media/pci/cx23885/cx23885-alsa.c
index c6c9bd58f8be..554798dcedd0 100644
--- a/drivers/media/pci/cx23885/cx23885-alsa.c
+++ b/drivers/media/pci/cx23885/cx23885-alsa.c
@@ -489,7 +489,8 @@ struct cx23885_audio_dev *cx23885_audio_register(struct cx23885_dev *dev)
489 return NULL; 489 return NULL;
490 } 490 }
491 491
492 err = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 492 err = snd_card_new(&dev->pci->dev,
493 SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
493 THIS_MODULE, sizeof(struct cx23885_audio_dev), &card); 494 THIS_MODULE, sizeof(struct cx23885_audio_dev), &card);
494 if (err < 0) 495 if (err < 0)
495 goto error; 496 goto error;
@@ -500,8 +501,6 @@ struct cx23885_audio_dev *cx23885_audio_register(struct cx23885_dev *dev)
500 chip->card = card; 501 chip->card = card;
501 spin_lock_init(&chip->lock); 502 spin_lock_init(&chip->lock);
502 503
503 snd_card_set_dev(card, &dev->pci->dev);
504
505 err = snd_cx23885_pcm(chip, 0, "CX23885 Digital"); 504 err = snd_cx23885_pcm(chip, 0, "CX23885 Digital");
506 if (err < 0) 505 if (err < 0)
507 goto error; 506 goto error;
diff --git a/drivers/media/pci/cx25821/cx25821-alsa.c b/drivers/media/pci/cx25821/cx25821-alsa.c
index b1e08c3e55cd..2dd5bcaa7e53 100644
--- a/drivers/media/pci/cx25821/cx25821-alsa.c
+++ b/drivers/media/pci/cx25821/cx25821-alsa.c
@@ -645,8 +645,9 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
645 return -ENOENT; 645 return -ENOENT;
646 } 646 }
647 647
648 err = snd_card_create(index[devno], id[devno], THIS_MODULE, 648 err = snd_card_new(&dev->pci->dev, index[devno], id[devno],
649 sizeof(struct cx25821_audio_dev), &card); 649 THIS_MODULE,
650 sizeof(struct cx25821_audio_dev), &card);
650 if (err < 0) { 651 if (err < 0) {
651 pr_info("DEBUG ERROR: cannot create snd_card_new in %s\n", 652 pr_info("DEBUG ERROR: cannot create snd_card_new in %s\n",
652 __func__); 653 __func__);
@@ -682,8 +683,6 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
682 goto error; 683 goto error;
683 } 684 }
684 685
685 snd_card_set_dev(card, &chip->pci->dev);
686
687 strcpy(card->shortname, "cx25821"); 686 strcpy(card->shortname, "cx25821");
688 sprintf(card->longname, "%s at 0x%lx irq %d", chip->dev->name, 687 sprintf(card->longname, "%s at 0x%lx irq %d", chip->dev->name,
689 chip->iobase, chip->irq); 688 chip->iobase, chip->irq);
diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
index d014206e7176..a72579a9f67f 100644
--- a/drivers/media/pci/cx88/cx88-alsa.c
+++ b/drivers/media/pci/cx88/cx88-alsa.c
@@ -852,8 +852,6 @@ static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
852 chip->irq = pci->irq; 852 chip->irq = pci->irq;
853 synchronize_irq(chip->irq); 853 synchronize_irq(chip->irq);
854 854
855 snd_card_set_dev(card, &pci->dev);
856
857 *rchip = chip; 855 *rchip = chip;
858 *core_ptr = core; 856 *core_ptr = core;
859 857
@@ -876,8 +874,8 @@ static int cx88_audio_initdev(struct pci_dev *pci,
876 return (-ENOENT); 874 return (-ENOENT);
877 } 875 }
878 876
879 err = snd_card_create(index[devno], id[devno], THIS_MODULE, 877 err = snd_card_new(&pci->dev, index[devno], id[devno], THIS_MODULE,
880 sizeof(snd_cx88_card_t), &card); 878 sizeof(snd_cx88_card_t), &card);
881 if (err < 0) 879 if (err < 0)
882 return err; 880 return err;
883 881
diff --git a/drivers/media/pci/ivtv/ivtv-alsa-main.c b/drivers/media/pci/ivtv/ivtv-alsa-main.c
index e970cface70e..39b52929755a 100644
--- a/drivers/media/pci/ivtv/ivtv-alsa-main.c
+++ b/drivers/media/pci/ivtv/ivtv-alsa-main.c
@@ -145,11 +145,12 @@ static int snd_ivtv_init(struct v4l2_device *v4l2_dev)
145 /* This is a no-op for us. We'll use the itv->instance */ 145 /* This is a no-op for us. We'll use the itv->instance */
146 146
147 /* (2) Create a card instance */ 147 /* (2) Create a card instance */
148 ret = snd_card_create(SNDRV_DEFAULT_IDX1, /* use first available id */ 148 ret = snd_card_new(&itv->pdev->dev,
149 SNDRV_DEFAULT_STR1, /* xid from end of shortname*/ 149 SNDRV_DEFAULT_IDX1, /* use first available id */
150 THIS_MODULE, 0, &sc); 150 SNDRV_DEFAULT_STR1, /* xid from end of shortname*/
151 THIS_MODULE, 0, &sc);
151 if (ret) { 152 if (ret) {
152 IVTV_ALSA_ERR("%s: snd_card_create() failed with err %d\n", 153 IVTV_ALSA_ERR("%s: snd_card_new() failed with err %d\n",
153 __func__, ret); 154 __func__, ret);
154 goto err_exit; 155 goto err_exit;
155 } 156 }
diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c
index dd67c8a400cc..e04a4d5d6672 100644
--- a/drivers/media/pci/saa7134/saa7134-alsa.c
+++ b/drivers/media/pci/saa7134/saa7134-alsa.c
@@ -1072,8 +1072,8 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
1072 if (!enable[devnum]) 1072 if (!enable[devnum])
1073 return -ENODEV; 1073 return -ENODEV;
1074 1074
1075 err = snd_card_create(index[devnum], id[devnum], THIS_MODULE, 1075 err = snd_card_new(&dev->pci->dev, index[devnum], id[devnum],
1076 sizeof(snd_card_saa7134_t), &card); 1076 THIS_MODULE, sizeof(snd_card_saa7134_t), &card);
1077 if (err < 0) 1077 if (err < 0)
1078 return err; 1078 return err;
1079 1079
@@ -1115,8 +1115,6 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
1115 if ((err = snd_card_saa7134_pcm(chip, 0)) < 0) 1115 if ((err = snd_card_saa7134_pcm(chip, 0)) < 0)
1116 goto __nodev; 1116 goto __nodev;
1117 1117
1118 snd_card_set_dev(card, &chip->pci->dev);
1119
1120 /* End of "creation" */ 1118 /* End of "creation" */
1121 1119
1122 strcpy(card->shortname, "SAA7134"); 1120 strcpy(card->shortname, "SAA7134");
diff --git a/drivers/media/usb/cx231xx/cx231xx-audio.c b/drivers/media/usb/cx231xx/cx231xx-audio.c
index 81a1d971d797..9b925874d392 100644
--- a/drivers/media/usb/cx231xx/cx231xx-audio.c
+++ b/drivers/media/usb/cx231xx/cx231xx-audio.c
@@ -665,8 +665,8 @@ static int cx231xx_audio_init(struct cx231xx *dev)
665 cx231xx_info("cx231xx-audio.c: probing for cx231xx " 665 cx231xx_info("cx231xx-audio.c: probing for cx231xx "
666 "non standard usbaudio\n"); 666 "non standard usbaudio\n");
667 667
668 err = snd_card_create(index[devnr], "Cx231xx Audio", THIS_MODULE, 668 err = snd_card_new(&dev->udev->dev, index[devnr], "Cx231xx Audio",
669 0, &card); 669 THIS_MODULE, 0, &card);
670 if (err < 0) 670 if (err < 0)
671 return err; 671 return err;
672 672
@@ -682,7 +682,6 @@ static int cx231xx_audio_init(struct cx231xx *dev)
682 pcm->info_flags = 0; 682 pcm->info_flags = 0;
683 pcm->private_data = dev; 683 pcm->private_data = dev;
684 strcpy(pcm->name, "Conexant cx231xx Capture"); 684 strcpy(pcm->name, "Conexant cx231xx Capture");
685 snd_card_set_dev(card, &dev->udev->dev);
686 strcpy(card->driver, "Cx231xx-Audio"); 685 strcpy(card->driver, "Cx231xx-Audio");
687 strcpy(card->shortname, "Cx231xx Audio"); 686 strcpy(card->shortname, "Cx231xx Audio");
688 strcpy(card->longname, "Conexant cx231xx Audio"); 687 strcpy(card->longname, "Conexant cx231xx Audio");
diff --git a/drivers/media/usb/em28xx/em28xx-audio.c b/drivers/media/usb/em28xx/em28xx-audio.c
index 05e9bd11a3ff..1a28897af183 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -900,8 +900,8 @@ static int em28xx_audio_init(struct em28xx *dev)
900 printk(KERN_INFO 900 printk(KERN_INFO
901 "em28xx-audio.c: Copyright (C) 2007-2014 Mauro Carvalho Chehab\n"); 901 "em28xx-audio.c: Copyright (C) 2007-2014 Mauro Carvalho Chehab\n");
902 902
903 err = snd_card_create(index[devnr], "Em28xx Audio", THIS_MODULE, 0, 903 err = snd_card_new(&dev->udev->dev, index[devnr], "Em28xx Audio",
904 &card); 904 THIS_MODULE, 0, &card);
905 if (err < 0) 905 if (err < 0)
906 return err; 906 return err;
907 907
@@ -918,7 +918,6 @@ static int em28xx_audio_init(struct em28xx *dev)
918 pcm->private_data = dev; 918 pcm->private_data = dev;
919 strcpy(pcm->name, "Empia 28xx Capture"); 919 strcpy(pcm->name, "Empia 28xx Capture");
920 920
921 snd_card_set_dev(card, &dev->udev->dev);
922 strcpy(card->driver, "Em28xx-Audio"); 921 strcpy(card->driver, "Em28xx-Audio");
923 strcpy(card->shortname, "Em28xx Audio"); 922 strcpy(card->shortname, "Em28xx Audio");
924 strcpy(card->longname, "Empia Em28xx Audio"); 923 strcpy(card->longname, "Empia Em28xx Audio");
diff --git a/drivers/media/usb/stk1160/stk1160-ac97.c b/drivers/media/usb/stk1160/stk1160-ac97.c
index c8583c262c3d..c46c8be89602 100644
--- a/drivers/media/usb/stk1160/stk1160-ac97.c
+++ b/drivers/media/usb/stk1160/stk1160-ac97.c
@@ -98,13 +98,11 @@ int stk1160_ac97_register(struct stk1160 *dev)
98 * Just want a card to access ac96 controls, 98 * Just want a card to access ac96 controls,
99 * the actual capture interface will be handled by snd-usb-audio 99 * the actual capture interface will be handled by snd-usb-audio
100 */ 100 */
101 rc = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 101 rc = snd_card_new(dev->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
102 THIS_MODULE, 0, &card); 102 THIS_MODULE, 0, &card);
103 if (rc < 0) 103 if (rc < 0)
104 return rc; 104 return rc;
105 105
106 snd_card_set_dev(card, dev->dev);
107
108 /* TODO: I'm not sure where should I get these names :-( */ 106 /* TODO: I'm not sure where should I get these names :-( */
109 snprintf(card->shortname, sizeof(card->shortname), 107 snprintf(card->shortname, sizeof(card->shortname),
110 "stk1160-mixer"); 108 "stk1160-mixer");
diff --git a/drivers/media/usb/tlg2300/pd-alsa.c b/drivers/media/usb/tlg2300/pd-alsa.c
index 3f3e141f70fb..dd8fe100590f 100644
--- a/drivers/media/usb/tlg2300/pd-alsa.c
+++ b/drivers/media/usb/tlg2300/pd-alsa.c
@@ -300,7 +300,8 @@ int poseidon_audio_init(struct poseidon *p)
300 struct snd_pcm *pcm; 300 struct snd_pcm *pcm;
301 int ret; 301 int ret;
302 302
303 ret = snd_card_create(-1, "Telegent", THIS_MODULE, 0, &card); 303 ret = snd_card_new(&p->interface->dev, -1, "Telegent",
304 THIS_MODULE, 0, &card);
304 if (ret != 0) 305 if (ret != 0)
305 return ret; 306 return ret;
306 307
diff --git a/drivers/media/usb/tm6000/tm6000-alsa.c b/drivers/media/usb/tm6000/tm6000-alsa.c
index 813c1ec53608..3239cd62e452 100644
--- a/drivers/media/usb/tm6000/tm6000-alsa.c
+++ b/drivers/media/usb/tm6000/tm6000-alsa.c
@@ -431,7 +431,8 @@ static int tm6000_audio_init(struct tm6000_core *dev)
431 if (!enable[devnr]) 431 if (!enable[devnr])
432 return -ENOENT; 432 return -ENOENT;
433 433
434 rc = snd_card_create(index[devnr], "tm6000", THIS_MODULE, 0, &card); 434 rc = snd_card_new(&dev->udev->dev, index[devnr], "tm6000",
435 THIS_MODULE, 0, &card);
435 if (rc < 0) { 436 if (rc < 0) {
436 snd_printk(KERN_ERR "cannot create card instance %d\n", devnr); 437 snd_printk(KERN_ERR "cannot create card instance %d\n", devnr);
437 return rc; 438 return rc;
@@ -445,7 +446,6 @@ static int tm6000_audio_init(struct tm6000_core *dev)
445 le16_to_cpu(dev->udev->descriptor.idVendor), 446 le16_to_cpu(dev->udev->descriptor.idVendor),
446 le16_to_cpu(dev->udev->descriptor.idProduct)); 447 le16_to_cpu(dev->udev->descriptor.idProduct));
447 snd_component_add(card, component); 448 snd_component_add(card, component);
448 snd_card_set_dev(card, &dev->udev->dev);
449 449
450 chip = kzalloc(sizeof(struct snd_tm6000_card), GFP_KERNEL); 450 chip = kzalloc(sizeof(struct snd_tm6000_card), GFP_KERNEL);
451 if (!chip) { 451 if (!chip) {
diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c
index 5be808406edc..22de13727641 100644
--- a/drivers/misc/atmel-ssc.c
+++ b/drivers/misc/atmel-ssc.c
@@ -150,6 +150,12 @@ static int ssc_probe(struct platform_device *pdev)
150 return -ENODEV; 150 return -ENODEV;
151 ssc->pdata = (struct atmel_ssc_platform_data *)plat_dat; 151 ssc->pdata = (struct atmel_ssc_platform_data *)plat_dat;
152 152
153 if (pdev->dev.of_node) {
154 struct device_node *np = pdev->dev.of_node;
155 ssc->clk_from_rk_pin =
156 of_property_read_bool(np, "atmel,clk-from-rk-pin");
157 }
158
153 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 159 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
154 ssc->regs = devm_ioremap_resource(&pdev->dev, regs); 160 ssc->regs = devm_ioremap_resource(&pdev->dev, regs);
155 if (IS_ERR(ssc->regs)) 161 if (IS_ERR(ssc->regs))
diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
index b9e2000969f0..95c894482fdd 100644
--- a/drivers/misc/sgi-xp/xpc_uv.c
+++ b/drivers/misc/sgi-xp/xpc_uv.c
@@ -240,7 +240,7 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name,
240 240
241 nid = cpu_to_node(cpu); 241 nid = cpu_to_node(cpu);
242 page = alloc_pages_exact_node(nid, 242 page = alloc_pages_exact_node(nid,
243 GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, 243 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
244 pg_order); 244 pg_order);
245 if (page == NULL) { 245 if (page == NULL) {
246 dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d " 246 dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d "
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index a2c47476804d..e8f133e926aa 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -730,7 +730,7 @@ static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bon
730 client_info->ntt = 0; 730 client_info->ntt = 0;
731 } 731 }
732 732
733 if (!vlan_get_tag(skb, &client_info->vlan_id)) 733 if (vlan_get_tag(skb, &client_info->vlan_id))
734 client_info->vlan_id = 0; 734 client_info->vlan_id = 0;
735 735
736 if (!client_info->assigned) { 736 if (!client_info->assigned) {
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index c37878432717..298c26509095 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -121,6 +121,7 @@ static struct bond_opt_value bond_resend_igmp_tbl[] = {
121static struct bond_opt_value bond_lp_interval_tbl[] = { 121static struct bond_opt_value bond_lp_interval_tbl[] = {
122 { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT}, 122 { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT},
123 { "maxval", INT_MAX, BOND_VALFLAG_MAX}, 123 { "maxval", INT_MAX, BOND_VALFLAG_MAX},
124 { NULL, -1, 0},
124}; 125};
125 126
126static struct bond_option bond_opts[] = { 127static struct bond_option bond_opts[] = {
diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c
index cda25ac45b47..6c9e1c9bdeb8 100644
--- a/drivers/net/ethernet/broadcom/bnx2.c
+++ b/drivers/net/ethernet/broadcom/bnx2.c
@@ -2507,6 +2507,7 @@ bnx2_fw_sync(struct bnx2 *bp, u32 msg_data, int ack, int silent)
2507 2507
2508 bp->fw_wr_seq++; 2508 bp->fw_wr_seq++;
2509 msg_data |= bp->fw_wr_seq; 2509 msg_data |= bp->fw_wr_seq;
2510 bp->fw_last_msg = msg_data;
2510 2511
2511 bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data); 2512 bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data);
2512 2513
@@ -4000,8 +4001,23 @@ bnx2_setup_wol(struct bnx2 *bp)
4000 wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL; 4001 wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
4001 } 4002 }
4002 4003
4003 if (!(bp->flags & BNX2_FLAG_NO_WOL)) 4004 if (!(bp->flags & BNX2_FLAG_NO_WOL)) {
4004 bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg, 1, 0); 4005 u32 val;
4006
4007 wol_msg |= BNX2_DRV_MSG_DATA_WAIT3;
4008 if (bp->fw_last_msg || BNX2_CHIP(bp) != BNX2_CHIP_5709) {
4009 bnx2_fw_sync(bp, wol_msg, 1, 0);
4010 return;
4011 }
4012 /* Tell firmware not to power down the PHY yet, otherwise
4013 * the chip will take a long time to respond to MMIO reads.
4014 */
4015 val = bnx2_shmem_rd(bp, BNX2_PORT_FEATURE);
4016 bnx2_shmem_wr(bp, BNX2_PORT_FEATURE,
4017 val | BNX2_PORT_FEATURE_ASF_ENABLED);
4018 bnx2_fw_sync(bp, wol_msg, 1, 0);
4019 bnx2_shmem_wr(bp, BNX2_PORT_FEATURE, val);
4020 }
4005 4021
4006} 4022}
4007 4023
@@ -4033,9 +4049,22 @@ bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
4033 4049
4034 if (bp->wol) 4050 if (bp->wol)
4035 pci_set_power_state(bp->pdev, PCI_D3hot); 4051 pci_set_power_state(bp->pdev, PCI_D3hot);
4036 } else { 4052 break;
4037 pci_set_power_state(bp->pdev, PCI_D3hot); 4053
4054 }
4055 if (!bp->fw_last_msg && BNX2_CHIP(bp) == BNX2_CHIP_5709) {
4056 u32 val;
4057
4058 /* Tell firmware not to power down the PHY yet,
4059 * otherwise the other port may not respond to
4060 * MMIO reads.
4061 */
4062 val = bnx2_shmem_rd(bp, BNX2_BC_STATE_CONDITION);
4063 val &= ~BNX2_CONDITION_PM_STATE_MASK;
4064 val |= BNX2_CONDITION_PM_STATE_UNPREP;
4065 bnx2_shmem_wr(bp, BNX2_BC_STATE_CONDITION, val);
4038 } 4066 }
4067 pci_set_power_state(bp->pdev, PCI_D3hot);
4039 4068
4040 /* No more memory access after this point until 4069 /* No more memory access after this point until
4041 * device is brought back to D0. 4070 * device is brought back to D0.
diff --git a/drivers/net/ethernet/broadcom/bnx2.h b/drivers/net/ethernet/broadcom/bnx2.h
index f1cf2c44e7ed..e341bc366fa5 100644
--- a/drivers/net/ethernet/broadcom/bnx2.h
+++ b/drivers/net/ethernet/broadcom/bnx2.h
@@ -6900,6 +6900,7 @@ struct bnx2 {
6900 6900
6901 u16 fw_wr_seq; 6901 u16 fw_wr_seq;
6902 u16 fw_drv_pulse_wr_seq; 6902 u16 fw_drv_pulse_wr_seq;
6903 u32 fw_last_msg;
6903 6904
6904 int rx_max_ring; 6905 int rx_max_ring;
6905 int rx_ring_size; 6906 int rx_ring_size;
@@ -7406,6 +7407,10 @@ struct bnx2_rv2p_fw_file {
7406#define BNX2_CONDITION_MFW_RUN_NCSI 0x00006000 7407#define BNX2_CONDITION_MFW_RUN_NCSI 0x00006000
7407#define BNX2_CONDITION_MFW_RUN_NONE 0x0000e000 7408#define BNX2_CONDITION_MFW_RUN_NONE 0x0000e000
7408#define BNX2_CONDITION_MFW_RUN_MASK 0x0000e000 7409#define BNX2_CONDITION_MFW_RUN_MASK 0x0000e000
7410#define BNX2_CONDITION_PM_STATE_MASK 0x00030000
7411#define BNX2_CONDITION_PM_STATE_FULL 0x00030000
7412#define BNX2_CONDITION_PM_STATE_PREP 0x00020000
7413#define BNX2_CONDITION_PM_STATE_UNPREP 0x00010000
7409 7414
7410#define BNX2_BC_STATE_DEBUG_CMD 0x1dc 7415#define BNX2_BC_STATE_DEBUG_CMD 0x1dc
7411#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000 7416#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000
diff --git a/drivers/net/ethernet/brocade/bna/bfa_ioc.c b/drivers/net/ethernet/brocade/bna/bfa_ioc.c
index 1803c3959044..354ae9792bad 100644
--- a/drivers/net/ethernet/brocade/bna/bfa_ioc.c
+++ b/drivers/net/ethernet/brocade/bna/bfa_ioc.c
@@ -1704,7 +1704,7 @@ bfa_flash_sem_get(void __iomem *bar)
1704 while (!bfa_raw_sem_get(bar)) { 1704 while (!bfa_raw_sem_get(bar)) {
1705 if (--n <= 0) 1705 if (--n <= 0)
1706 return BFA_STATUS_BADFLASH; 1706 return BFA_STATUS_BADFLASH;
1707 udelay(10000); 1707 mdelay(10);
1708 } 1708 }
1709 return BFA_STATUS_OK; 1709 return BFA_STATUS_OK;
1710} 1710}
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 3190d38e16fb..d0c38e01e99f 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -632,11 +632,16 @@ static void gem_rx_refill(struct macb *bp)
632 "Unable to allocate sk_buff\n"); 632 "Unable to allocate sk_buff\n");
633 break; 633 break;
634 } 634 }
635 bp->rx_skbuff[entry] = skb;
636 635
637 /* now fill corresponding descriptor entry */ 636 /* now fill corresponding descriptor entry */
638 paddr = dma_map_single(&bp->pdev->dev, skb->data, 637 paddr = dma_map_single(&bp->pdev->dev, skb->data,
639 bp->rx_buffer_size, DMA_FROM_DEVICE); 638 bp->rx_buffer_size, DMA_FROM_DEVICE);
639 if (dma_mapping_error(&bp->pdev->dev, paddr)) {
640 dev_kfree_skb(skb);
641 break;
642 }
643
644 bp->rx_skbuff[entry] = skb;
640 645
641 if (entry == RX_RING_SIZE - 1) 646 if (entry == RX_RING_SIZE - 1)
642 paddr |= MACB_BIT(RX_WRAP); 647 paddr |= MACB_BIT(RX_WRAP);
@@ -725,7 +730,7 @@ static int gem_rx(struct macb *bp, int budget)
725 skb_put(skb, len); 730 skb_put(skb, len);
726 addr = MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, addr)); 731 addr = MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, addr));
727 dma_unmap_single(&bp->pdev->dev, addr, 732 dma_unmap_single(&bp->pdev->dev, addr,
728 len, DMA_FROM_DEVICE); 733 bp->rx_buffer_size, DMA_FROM_DEVICE);
729 734
730 skb->protocol = eth_type_trans(skb, bp->dev); 735 skb->protocol = eth_type_trans(skb, bp->dev);
731 skb_checksum_none_assert(skb); 736 skb_checksum_none_assert(skb);
@@ -1036,11 +1041,15 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
1036 } 1041 }
1037 1042
1038 entry = macb_tx_ring_wrap(bp->tx_head); 1043 entry = macb_tx_ring_wrap(bp->tx_head);
1039 bp->tx_head++;
1040 netdev_vdbg(bp->dev, "Allocated ring entry %u\n", entry); 1044 netdev_vdbg(bp->dev, "Allocated ring entry %u\n", entry);
1041 mapping = dma_map_single(&bp->pdev->dev, skb->data, 1045 mapping = dma_map_single(&bp->pdev->dev, skb->data,
1042 len, DMA_TO_DEVICE); 1046 len, DMA_TO_DEVICE);
1047 if (dma_mapping_error(&bp->pdev->dev, mapping)) {
1048 kfree_skb(skb);
1049 goto unlock;
1050 }
1043 1051
1052 bp->tx_head++;
1044 tx_skb = &bp->tx_skb[entry]; 1053 tx_skb = &bp->tx_skb[entry];
1045 tx_skb->skb = skb; 1054 tx_skb->skb = skb;
1046 tx_skb->mapping = mapping; 1055 tx_skb->mapping = mapping;
@@ -1066,6 +1075,7 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
1066 if (CIRC_SPACE(bp->tx_head, bp->tx_tail, TX_RING_SIZE) < 1) 1075 if (CIRC_SPACE(bp->tx_head, bp->tx_tail, TX_RING_SIZE) < 1)
1067 netif_stop_queue(dev); 1076 netif_stop_queue(dev);
1068 1077
1078unlock:
1069 spin_unlock_irqrestore(&bp->lock, flags); 1079 spin_unlock_irqrestore(&bp->lock, flags);
1070 1080
1071 return NETDEV_TX_OK; 1081 return NETDEV_TX_OK;
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 479a7cba45c0..03a351300013 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -528,13 +528,6 @@ fec_restart(struct net_device *ndev, int duplex)
528 /* Clear any outstanding interrupt. */ 528 /* Clear any outstanding interrupt. */
529 writel(0xffc00000, fep->hwp + FEC_IEVENT); 529 writel(0xffc00000, fep->hwp + FEC_IEVENT);
530 530
531 /* Setup multicast filter. */
532 set_multicast_list(ndev);
533#ifndef CONFIG_M5272
534 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
535 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
536#endif
537
538 /* Set maximum receive buffer size. */ 531 /* Set maximum receive buffer size. */
539 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE); 532 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
540 533
@@ -655,6 +648,13 @@ fec_restart(struct net_device *ndev, int duplex)
655 648
656 writel(rcntl, fep->hwp + FEC_R_CNTRL); 649 writel(rcntl, fep->hwp + FEC_R_CNTRL);
657 650
651 /* Setup multicast filter. */
652 set_multicast_list(ndev);
653#ifndef CONFIG_M5272
654 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
655 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
656#endif
657
658 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) { 658 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
659 /* enable ENET endian swap */ 659 /* enable ENET endian swap */
660 ecntl |= (1 << 8); 660 ecntl |= (1 << 8);
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index 4be971590461..1fc8334fc181 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -522,10 +522,21 @@ retry:
522 return rc; 522 return rc;
523} 523}
524 524
525static u64 ibmveth_encode_mac_addr(u8 *mac)
526{
527 int i;
528 u64 encoded = 0;
529
530 for (i = 0; i < ETH_ALEN; i++)
531 encoded = (encoded << 8) | mac[i];
532
533 return encoded;
534}
535
525static int ibmveth_open(struct net_device *netdev) 536static int ibmveth_open(struct net_device *netdev)
526{ 537{
527 struct ibmveth_adapter *adapter = netdev_priv(netdev); 538 struct ibmveth_adapter *adapter = netdev_priv(netdev);
528 u64 mac_address = 0; 539 u64 mac_address;
529 int rxq_entries = 1; 540 int rxq_entries = 1;
530 unsigned long lpar_rc; 541 unsigned long lpar_rc;
531 int rc; 542 int rc;
@@ -579,8 +590,7 @@ static int ibmveth_open(struct net_device *netdev)
579 adapter->rx_queue.num_slots = rxq_entries; 590 adapter->rx_queue.num_slots = rxq_entries;
580 adapter->rx_queue.toggle = 1; 591 adapter->rx_queue.toggle = 1;
581 592
582 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len); 593 mac_address = ibmveth_encode_mac_addr(netdev->dev_addr);
583 mac_address = mac_address >> 16;
584 594
585 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | 595 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID |
586 adapter->rx_queue.queue_len; 596 adapter->rx_queue.queue_len;
@@ -1183,8 +1193,8 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
1183 /* add the addresses to the filter table */ 1193 /* add the addresses to the filter table */
1184 netdev_for_each_mc_addr(ha, netdev) { 1194 netdev_for_each_mc_addr(ha, netdev) {
1185 /* add the multicast address to the filter table */ 1195 /* add the multicast address to the filter table */
1186 unsigned long mcast_addr = 0; 1196 u64 mcast_addr;
1187 memcpy(((char *)&mcast_addr)+2, ha->addr, ETH_ALEN); 1197 mcast_addr = ibmveth_encode_mac_addr(ha->addr);
1188 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, 1198 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1189 IbmVethMcastAddFilter, 1199 IbmVethMcastAddFilter,
1190 mcast_addr); 1200 mcast_addr);
@@ -1372,9 +1382,6 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1372 1382
1373 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16); 1383 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16);
1374 1384
1375 adapter->mac_addr = 0;
1376 memcpy(&adapter->mac_addr, mac_addr_p, ETH_ALEN);
1377
1378 netdev->irq = dev->irq; 1385 netdev->irq = dev->irq;
1379 netdev->netdev_ops = &ibmveth_netdev_ops; 1386 netdev->netdev_ops = &ibmveth_netdev_ops;
1380 netdev->ethtool_ops = &netdev_ethtool_ops; 1387 netdev->ethtool_ops = &netdev_ethtool_ops;
@@ -1383,7 +1390,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1383 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; 1390 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
1384 netdev->features |= netdev->hw_features; 1391 netdev->features |= netdev->hw_features;
1385 1392
1386 memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len); 1393 memcpy(netdev->dev_addr, mac_addr_p, ETH_ALEN);
1387 1394
1388 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { 1395 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
1389 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj; 1396 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h
index 451ba7949e15..1f37499d4398 100644
--- a/drivers/net/ethernet/ibm/ibmveth.h
+++ b/drivers/net/ethernet/ibm/ibmveth.h
@@ -138,7 +138,6 @@ struct ibmveth_adapter {
138 struct napi_struct napi; 138 struct napi_struct napi;
139 struct net_device_stats stats; 139 struct net_device_stats stats;
140 unsigned int mcastFilterSize; 140 unsigned int mcastFilterSize;
141 unsigned long mac_addr;
142 void * buffer_list_addr; 141 void * buffer_list_addr;
143 void * filter_list_addr; 142 void * filter_list_addr;
144 dma_addr_t buffer_list_dma; 143 dma_addr_t buffer_list_dma;
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index fad45316200a..84a96f70dfb5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -742,6 +742,14 @@ static int mlx4_en_replace_mac(struct mlx4_en_priv *priv, int qpn,
742 err = mlx4_en_uc_steer_add(priv, new_mac, 742 err = mlx4_en_uc_steer_add(priv, new_mac,
743 &qpn, 743 &qpn,
744 &entry->reg_id); 744 &entry->reg_id);
745 if (err)
746 return err;
747 if (priv->tunnel_reg_id) {
748 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
749 priv->tunnel_reg_id = 0;
750 }
751 err = mlx4_en_tunnel_steer_add(priv, new_mac, qpn,
752 &priv->tunnel_reg_id);
745 return err; 753 return err;
746 } 754 }
747 } 755 }
@@ -1792,6 +1800,8 @@ void mlx4_en_stop_port(struct net_device *dev, int detach)
1792 mc_list[5] = priv->port; 1800 mc_list[5] = priv->port;
1793 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, 1801 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
1794 mc_list, MLX4_PROT_ETH, mclist->reg_id); 1802 mc_list, MLX4_PROT_ETH, mclist->reg_id);
1803 if (mclist->tunnel_reg_id)
1804 mlx4_flow_detach(mdev->dev, mclist->tunnel_reg_id);
1795 } 1805 }
1796 mlx4_en_clear_list(dev); 1806 mlx4_en_clear_list(dev);
1797 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { 1807 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
diff --git a/drivers/net/ethernet/mellanox/mlx4/fw.c b/drivers/net/ethernet/mellanox/mlx4/fw.c
index 91b69ff4b4a2..7e2995ecea6f 100644
--- a/drivers/net/ethernet/mellanox/mlx4/fw.c
+++ b/drivers/net/ethernet/mellanox/mlx4/fw.c
@@ -129,13 +129,14 @@ static void dump_dev_cap_flags2(struct mlx4_dev *dev, u64 flags)
129 [0] = "RSS support", 129 [0] = "RSS support",
130 [1] = "RSS Toeplitz Hash Function support", 130 [1] = "RSS Toeplitz Hash Function support",
131 [2] = "RSS XOR Hash Function support", 131 [2] = "RSS XOR Hash Function support",
132 [3] = "Device manage flow steering support", 132 [3] = "Device managed flow steering support",
133 [4] = "Automatic MAC reassignment support", 133 [4] = "Automatic MAC reassignment support",
134 [5] = "Time stamping support", 134 [5] = "Time stamping support",
135 [6] = "VST (control vlan insertion/stripping) support", 135 [6] = "VST (control vlan insertion/stripping) support",
136 [7] = "FSM (MAC anti-spoofing) support", 136 [7] = "FSM (MAC anti-spoofing) support",
137 [8] = "Dynamic QP updates support", 137 [8] = "Dynamic QP updates support",
138 [9] = "TCP/IP offloads/flow-steering for VXLAN support" 138 [9] = "Device managed flow steering IPoIB support",
139 [10] = "TCP/IP offloads/flow-steering for VXLAN support"
139 }; 140 };
140 int i; 141 int i;
141 142
@@ -859,7 +860,7 @@ int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
859 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET); 860 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET);
860 861
861 /* For guests, disable vxlan tunneling */ 862 /* For guests, disable vxlan tunneling */
862 MLX4_GET(field, outbox, QUERY_DEV_CAP_VXLAN); 863 MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_VXLAN);
863 field &= 0xf7; 864 field &= 0xf7;
864 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VXLAN); 865 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VXLAN);
865 866
@@ -869,7 +870,7 @@ int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
869 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_BF_OFFSET); 870 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_BF_OFFSET);
870 871
871 /* For guests, disable mw type 2 */ 872 /* For guests, disable mw type 2 */
872 MLX4_GET(bmme_flags, outbox, QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 873 MLX4_GET(bmme_flags, outbox->buf, QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
873 bmme_flags &= ~MLX4_BMME_FLAG_TYPE_2_WIN; 874 bmme_flags &= ~MLX4_BMME_FLAG_TYPE_2_WIN;
874 MLX4_PUT(outbox->buf, bmme_flags, QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 875 MLX4_PUT(outbox->buf, bmme_flags, QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
875 876
@@ -883,7 +884,7 @@ int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
883 } 884 }
884 885
885 /* turn off ipoib managed steering for guests */ 886 /* turn off ipoib managed steering for guests */
886 MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET); 887 MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
887 field &= ~0x80; 888 field &= ~0x80;
888 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET); 889 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
889 890
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index d711158b0d4b..936c15364739 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -150,6 +150,8 @@ struct mlx4_port_config {
150 struct pci_dev *pdev; 150 struct pci_dev *pdev;
151}; 151};
152 152
153static atomic_t pf_loading = ATOMIC_INIT(0);
154
153int mlx4_check_port_params(struct mlx4_dev *dev, 155int mlx4_check_port_params(struct mlx4_dev *dev,
154 enum mlx4_port_type *port_type) 156 enum mlx4_port_type *port_type)
155{ 157{
@@ -749,7 +751,7 @@ static void mlx4_request_modules(struct mlx4_dev *dev)
749 has_eth_port = true; 751 has_eth_port = true;
750 } 752 }
751 753
752 if (has_ib_port) 754 if (has_ib_port || (dev->caps.flags & MLX4_DEV_CAP_FLAG_IBOE))
753 request_module_nowait(IB_DRV_NAME); 755 request_module_nowait(IB_DRV_NAME);
754 if (has_eth_port) 756 if (has_eth_port)
755 request_module_nowait(EN_DRV_NAME); 757 request_module_nowait(EN_DRV_NAME);
@@ -1407,6 +1409,11 @@ static int mlx4_init_slave(struct mlx4_dev *dev)
1407 u32 slave_read; 1409 u32 slave_read;
1408 u32 cmd_channel_ver; 1410 u32 cmd_channel_ver;
1409 1411
1412 if (atomic_read(&pf_loading)) {
1413 mlx4_warn(dev, "PF is not ready. Deferring probe\n");
1414 return -EPROBE_DEFER;
1415 }
1416
1410 mutex_lock(&priv->cmd.slave_cmd_mutex); 1417 mutex_lock(&priv->cmd.slave_cmd_mutex);
1411 priv->cmd.max_cmds = 1; 1418 priv->cmd.max_cmds = 1;
1412 mlx4_warn(dev, "Sending reset\n"); 1419 mlx4_warn(dev, "Sending reset\n");
@@ -2319,7 +2326,11 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data)
2319 2326
2320 if (num_vfs) { 2327 if (num_vfs) {
2321 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", num_vfs); 2328 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", num_vfs);
2329
2330 atomic_inc(&pf_loading);
2322 err = pci_enable_sriov(pdev, num_vfs); 2331 err = pci_enable_sriov(pdev, num_vfs);
2332 atomic_dec(&pf_loading);
2333
2323 if (err) { 2334 if (err) {
2324 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d).\n", 2335 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d).\n",
2325 err); 2336 err);
@@ -2684,6 +2695,7 @@ static struct pci_driver mlx4_driver = {
2684 .name = DRV_NAME, 2695 .name = DRV_NAME,
2685 .id_table = mlx4_pci_table, 2696 .id_table = mlx4_pci_table,
2686 .probe = mlx4_init_one, 2697 .probe = mlx4_init_one,
2698 .shutdown = mlx4_remove_one,
2687 .remove = mlx4_remove_one, 2699 .remove = mlx4_remove_one,
2688 .err_handler = &mlx4_err_handler, 2700 .err_handler = &mlx4_err_handler,
2689}; 2701};
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index e9779653cd4c..3ff7bc3e7a23 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -209,7 +209,7 @@ static const struct {
209 [RTL_GIGA_MAC_VER_16] = 209 [RTL_GIGA_MAC_VER_16] =
210 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), 210 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true),
211 [RTL_GIGA_MAC_VER_17] = 211 [RTL_GIGA_MAC_VER_17] =
212 _R("RTL8168b/8111b", RTL_TD_1, NULL, JUMBO_4K, false), 212 _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false),
213 [RTL_GIGA_MAC_VER_18] = 213 [RTL_GIGA_MAC_VER_18] =
214 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), 214 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false),
215 [RTL_GIGA_MAC_VER_19] = 215 [RTL_GIGA_MAC_VER_19] =
diff --git a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
index 72d282bf33a5..c553f6b5a913 100644
--- a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
@@ -151,7 +151,7 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
151 sizeof(struct dma_desc))); 151 sizeof(struct dma_desc)));
152} 152}
153 153
154const struct stmmac_chain_mode_ops chain_mode_ops = { 154const struct stmmac_mode_ops chain_mode_ops = {
155 .init = stmmac_init_dma_chain, 155 .init = stmmac_init_dma_chain,
156 .is_jumbo_frm = stmmac_is_jumbo_frm, 156 .is_jumbo_frm = stmmac_is_jumbo_frm,
157 .jumbo_frm = stmmac_jumbo_frm, 157 .jumbo_frm = stmmac_jumbo_frm,
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index 7834a3993946..74610f3aca9e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -419,20 +419,13 @@ struct mii_regs {
419 unsigned int data; /* MII Data */ 419 unsigned int data; /* MII Data */
420}; 420};
421 421
422struct stmmac_ring_mode_ops { 422struct stmmac_mode_ops {
423 unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
424 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum);
425 void (*refill_desc3) (void *priv, struct dma_desc *p);
426 void (*init_desc3) (struct dma_desc *p);
427 void (*clean_desc3) (void *priv, struct dma_desc *p);
428 int (*set_16kib_bfsize) (int mtu);
429};
430
431struct stmmac_chain_mode_ops {
432 void (*init) (void *des, dma_addr_t phy_addr, unsigned int size, 423 void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
433 unsigned int extend_desc); 424 unsigned int extend_desc);
434 unsigned int (*is_jumbo_frm) (int len, int ehn_desc); 425 unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
435 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum); 426 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum);
427 int (*set_16kib_bfsize)(int mtu);
428 void (*init_desc3)(struct dma_desc *p);
436 void (*refill_desc3) (void *priv, struct dma_desc *p); 429 void (*refill_desc3) (void *priv, struct dma_desc *p);
437 void (*clean_desc3) (void *priv, struct dma_desc *p); 430 void (*clean_desc3) (void *priv, struct dma_desc *p);
438}; 431};
@@ -441,8 +434,7 @@ struct mac_device_info {
441 const struct stmmac_ops *mac; 434 const struct stmmac_ops *mac;
442 const struct stmmac_desc_ops *desc; 435 const struct stmmac_desc_ops *desc;
443 const struct stmmac_dma_ops *dma; 436 const struct stmmac_dma_ops *dma;
444 const struct stmmac_ring_mode_ops *ring; 437 const struct stmmac_mode_ops *mode;
445 const struct stmmac_chain_mode_ops *chain;
446 const struct stmmac_hwtimestamp *ptp; 438 const struct stmmac_hwtimestamp *ptp;
447 struct mii_regs mii; /* MII register Addresses */ 439 struct mii_regs mii; /* MII register Addresses */
448 struct mac_link link; 440 struct mac_link link;
@@ -460,7 +452,7 @@ void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
460void stmmac_set_mac(void __iomem *ioaddr, bool enable); 452void stmmac_set_mac(void __iomem *ioaddr, bool enable);
461 453
462void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr); 454void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr);
463extern const struct stmmac_ring_mode_ops ring_mode_ops; 455extern const struct stmmac_mode_ops ring_mode_ops;
464extern const struct stmmac_chain_mode_ops chain_mode_ops; 456extern const struct stmmac_mode_ops chain_mode_ops;
465 457
466#endif /* __COMMON_H__ */ 458#endif /* __COMMON_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
index a96c7c2f5f3f..650a4be6bce5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
@@ -100,10 +100,9 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
100{ 100{
101 struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr; 101 struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
102 102
103 if (unlikely(priv->plat->has_gmac)) 103 /* Fill DES3 in case of RING mode */
104 /* Fill DES3 in case of RING mode */ 104 if (priv->dma_buf_sz >= BUF_SIZE_8KiB)
105 if (priv->dma_buf_sz >= BUF_SIZE_8KiB) 105 p->des3 = p->des2 + BUF_SIZE_8KiB;
106 p->des3 = p->des2 + BUF_SIZE_8KiB;
107} 106}
108 107
109/* In ring mode we need to fill the desc3 because it is used as buffer */ 108/* In ring mode we need to fill the desc3 because it is used as buffer */
@@ -126,7 +125,7 @@ static int stmmac_set_16kib_bfsize(int mtu)
126 return ret; 125 return ret;
127} 126}
128 127
129const struct stmmac_ring_mode_ops ring_mode_ops = { 128const struct stmmac_mode_ops ring_mode_ops = {
130 .is_jumbo_frm = stmmac_is_jumbo_frm, 129 .is_jumbo_frm = stmmac_is_jumbo_frm,
131 .jumbo_frm = stmmac_jumbo_frm, 130 .jumbo_frm = stmmac_jumbo_frm,
132 .refill_desc3 = stmmac_refill_desc3, 131 .refill_desc3 = stmmac_refill_desc3,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 078ad0ec8593..8543e1cfd55e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -92,8 +92,8 @@ static int tc = TC_DEFAULT;
92module_param(tc, int, S_IRUGO | S_IWUSR); 92module_param(tc, int, S_IRUGO | S_IWUSR);
93MODULE_PARM_DESC(tc, "DMA threshold control value"); 93MODULE_PARM_DESC(tc, "DMA threshold control value");
94 94
95#define DMA_BUFFER_SIZE BUF_SIZE_4KiB 95#define DEFAULT_BUFSIZE 1536
96static int buf_sz = DMA_BUFFER_SIZE; 96static int buf_sz = DEFAULT_BUFSIZE;
97module_param(buf_sz, int, S_IRUGO | S_IWUSR); 97module_param(buf_sz, int, S_IRUGO | S_IWUSR);
98MODULE_PARM_DESC(buf_sz, "DMA buffer size"); 98MODULE_PARM_DESC(buf_sz, "DMA buffer size");
99 99
@@ -136,8 +136,8 @@ static void stmmac_verify_args(void)
136 dma_rxsize = DMA_RX_SIZE; 136 dma_rxsize = DMA_RX_SIZE;
137 if (unlikely(dma_txsize < 0)) 137 if (unlikely(dma_txsize < 0))
138 dma_txsize = DMA_TX_SIZE; 138 dma_txsize = DMA_TX_SIZE;
139 if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB))) 139 if (unlikely((buf_sz < DEFAULT_BUFSIZE) || (buf_sz > BUF_SIZE_16KiB)))
140 buf_sz = DMA_BUFFER_SIZE; 140 buf_sz = DEFAULT_BUFSIZE;
141 if (unlikely(flow_ctrl > 1)) 141 if (unlikely(flow_ctrl > 1))
142 flow_ctrl = FLOW_AUTO; 142 flow_ctrl = FLOW_AUTO;
143 else if (likely(flow_ctrl < 0)) 143 else if (likely(flow_ctrl < 0))
@@ -286,10 +286,25 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
286 286
287 /* MAC core supports the EEE feature. */ 287 /* MAC core supports the EEE feature. */
288 if (priv->dma_cap.eee) { 288 if (priv->dma_cap.eee) {
289 int tx_lpi_timer = priv->tx_lpi_timer;
290
289 /* Check if the PHY supports EEE */ 291 /* Check if the PHY supports EEE */
290 if (phy_init_eee(priv->phydev, 1)) 292 if (phy_init_eee(priv->phydev, 1)) {
293 /* To manage at run-time if the EEE cannot be supported
294 * anymore (for example because the lp caps have been
295 * changed).
296 * In that case the driver disable own timers.
297 */
298 if (priv->eee_active) {
299 pr_debug("stmmac: disable EEE\n");
300 del_timer_sync(&priv->eee_ctrl_timer);
301 priv->hw->mac->set_eee_timer(priv->ioaddr, 0,
302 tx_lpi_timer);
303 }
304 priv->eee_active = 0;
291 goto out; 305 goto out;
292 306 }
307 /* Activate the EEE and start timers */
293 if (!priv->eee_active) { 308 if (!priv->eee_active) {
294 priv->eee_active = 1; 309 priv->eee_active = 1;
295 init_timer(&priv->eee_ctrl_timer); 310 init_timer(&priv->eee_ctrl_timer);
@@ -300,13 +315,13 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
300 315
301 priv->hw->mac->set_eee_timer(priv->ioaddr, 316 priv->hw->mac->set_eee_timer(priv->ioaddr,
302 STMMAC_DEFAULT_LIT_LS, 317 STMMAC_DEFAULT_LIT_LS,
303 priv->tx_lpi_timer); 318 tx_lpi_timer);
304 } else 319 } else
305 /* Set HW EEE according to the speed */ 320 /* Set HW EEE according to the speed */
306 priv->hw->mac->set_eee_pls(priv->ioaddr, 321 priv->hw->mac->set_eee_pls(priv->ioaddr,
307 priv->phydev->link); 322 priv->phydev->link);
308 323
309 pr_info("stmmac: Energy-Efficient Ethernet initialized\n"); 324 pr_debug("stmmac: Energy-Efficient Ethernet initialized\n");
310 325
311 ret = true; 326 ret = true;
312 } 327 }
@@ -886,10 +901,10 @@ static int stmmac_set_bfsize(int mtu, int bufsize)
886 ret = BUF_SIZE_8KiB; 901 ret = BUF_SIZE_8KiB;
887 else if (mtu >= BUF_SIZE_2KiB) 902 else if (mtu >= BUF_SIZE_2KiB)
888 ret = BUF_SIZE_4KiB; 903 ret = BUF_SIZE_4KiB;
889 else if (mtu >= DMA_BUFFER_SIZE) 904 else if (mtu > DEFAULT_BUFSIZE)
890 ret = BUF_SIZE_2KiB; 905 ret = BUF_SIZE_2KiB;
891 else 906 else
892 ret = DMA_BUFFER_SIZE; 907 ret = DEFAULT_BUFSIZE;
893 908
894 return ret; 909 return ret;
895} 910}
@@ -951,9 +966,9 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
951 966
952 p->des2 = priv->rx_skbuff_dma[i]; 967 p->des2 = priv->rx_skbuff_dma[i];
953 968
954 if ((priv->mode == STMMAC_RING_MODE) && 969 if ((priv->hw->mode->init_desc3) &&
955 (priv->dma_buf_sz == BUF_SIZE_16KiB)) 970 (priv->dma_buf_sz == BUF_SIZE_16KiB))
956 priv->hw->ring->init_desc3(p); 971 priv->hw->mode->init_desc3(p);
957 972
958 return 0; 973 return 0;
959} 974}
@@ -984,11 +999,8 @@ static int init_dma_desc_rings(struct net_device *dev)
984 unsigned int bfsize = 0; 999 unsigned int bfsize = 0;
985 int ret = -ENOMEM; 1000 int ret = -ENOMEM;
986 1001
987 /* Set the max buffer size according to the DESC mode 1002 if (priv->hw->mode->set_16kib_bfsize)
988 * and the MTU. Note that RING mode allows 16KiB bsize. 1003 bfsize = priv->hw->mode->set_16kib_bfsize(dev->mtu);
989 */
990 if (priv->mode == STMMAC_RING_MODE)
991 bfsize = priv->hw->ring->set_16kib_bfsize(dev->mtu);
992 1004
993 if (bfsize < BUF_SIZE_16KiB) 1005 if (bfsize < BUF_SIZE_16KiB)
994 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz); 1006 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
@@ -1029,15 +1041,15 @@ static int init_dma_desc_rings(struct net_device *dev)
1029 /* Setup the chained descriptor addresses */ 1041 /* Setup the chained descriptor addresses */
1030 if (priv->mode == STMMAC_CHAIN_MODE) { 1042 if (priv->mode == STMMAC_CHAIN_MODE) {
1031 if (priv->extend_desc) { 1043 if (priv->extend_desc) {
1032 priv->hw->chain->init(priv->dma_erx, priv->dma_rx_phy, 1044 priv->hw->mode->init(priv->dma_erx, priv->dma_rx_phy,
1033 rxsize, 1); 1045 rxsize, 1);
1034 priv->hw->chain->init(priv->dma_etx, priv->dma_tx_phy, 1046 priv->hw->mode->init(priv->dma_etx, priv->dma_tx_phy,
1035 txsize, 1); 1047 txsize, 1);
1036 } else { 1048 } else {
1037 priv->hw->chain->init(priv->dma_rx, priv->dma_rx_phy, 1049 priv->hw->mode->init(priv->dma_rx, priv->dma_rx_phy,
1038 rxsize, 0); 1050 rxsize, 0);
1039 priv->hw->chain->init(priv->dma_tx, priv->dma_tx_phy, 1051 priv->hw->mode->init(priv->dma_tx, priv->dma_tx_phy,
1040 txsize, 0); 1052 txsize, 0);
1041 } 1053 }
1042 } 1054 }
1043 1055
@@ -1288,7 +1300,7 @@ static void stmmac_tx_clean(struct stmmac_priv *priv)
1288 DMA_TO_DEVICE); 1300 DMA_TO_DEVICE);
1289 priv->tx_skbuff_dma[entry] = 0; 1301 priv->tx_skbuff_dma[entry] = 0;
1290 } 1302 }
1291 priv->hw->ring->clean_desc3(priv, p); 1303 priv->hw->mode->clean_desc3(priv, p);
1292 1304
1293 if (likely(skb != NULL)) { 1305 if (likely(skb != NULL)) {
1294 dev_kfree_skb(skb); 1306 dev_kfree_skb(skb);
@@ -1844,6 +1856,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1844 int nfrags = skb_shinfo(skb)->nr_frags; 1856 int nfrags = skb_shinfo(skb)->nr_frags;
1845 struct dma_desc *desc, *first; 1857 struct dma_desc *desc, *first;
1846 unsigned int nopaged_len = skb_headlen(skb); 1858 unsigned int nopaged_len = skb_headlen(skb);
1859 unsigned int enh_desc = priv->plat->enh_desc;
1847 1860
1848 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) { 1861 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1849 if (!netif_queue_stopped(dev)) { 1862 if (!netif_queue_stopped(dev)) {
@@ -1871,27 +1884,19 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1871 first = desc; 1884 first = desc;
1872 1885
1873 /* To program the descriptors according to the size of the frame */ 1886 /* To program the descriptors according to the size of the frame */
1874 if (priv->mode == STMMAC_RING_MODE) { 1887 if (enh_desc)
1875 is_jumbo = priv->hw->ring->is_jumbo_frm(skb->len, 1888 is_jumbo = priv->hw->mode->is_jumbo_frm(skb->len, enh_desc);
1876 priv->plat->enh_desc); 1889
1877 if (unlikely(is_jumbo))
1878 entry = priv->hw->ring->jumbo_frm(priv, skb,
1879 csum_insertion);
1880 } else {
1881 is_jumbo = priv->hw->chain->is_jumbo_frm(skb->len,
1882 priv->plat->enh_desc);
1883 if (unlikely(is_jumbo))
1884 entry = priv->hw->chain->jumbo_frm(priv, skb,
1885 csum_insertion);
1886 }
1887 if (likely(!is_jumbo)) { 1890 if (likely(!is_jumbo)) {
1888 desc->des2 = dma_map_single(priv->device, skb->data, 1891 desc->des2 = dma_map_single(priv->device, skb->data,
1889 nopaged_len, DMA_TO_DEVICE); 1892 nopaged_len, DMA_TO_DEVICE);
1890 priv->tx_skbuff_dma[entry] = desc->des2; 1893 priv->tx_skbuff_dma[entry] = desc->des2;
1891 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, 1894 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
1892 csum_insertion, priv->mode); 1895 csum_insertion, priv->mode);
1893 } else 1896 } else {
1894 desc = first; 1897 desc = first;
1898 entry = priv->hw->mode->jumbo_frm(priv, skb, csum_insertion);
1899 }
1895 1900
1896 for (i = 0; i < nfrags; i++) { 1901 for (i = 0; i < nfrags; i++) {
1897 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 1902 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
@@ -2029,7 +2034,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv)
2029 2034
2030 p->des2 = priv->rx_skbuff_dma[entry]; 2035 p->des2 = priv->rx_skbuff_dma[entry];
2031 2036
2032 priv->hw->ring->refill_desc3(priv, p); 2037 priv->hw->mode->refill_desc3(priv, p);
2033 2038
2034 if (netif_msg_rx_status(priv)) 2039 if (netif_msg_rx_status(priv))
2035 pr_debug("\trefill entry #%d\n", entry); 2040 pr_debug("\trefill entry #%d\n", entry);
@@ -2633,11 +2638,11 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
2633 2638
2634 /* To use the chained or ring mode */ 2639 /* To use the chained or ring mode */
2635 if (chain_mode) { 2640 if (chain_mode) {
2636 priv->hw->chain = &chain_mode_ops; 2641 priv->hw->mode = &chain_mode_ops;
2637 pr_info(" Chain mode enabled\n"); 2642 pr_info(" Chain mode enabled\n");
2638 priv->mode = STMMAC_CHAIN_MODE; 2643 priv->mode = STMMAC_CHAIN_MODE;
2639 } else { 2644 } else {
2640 priv->hw->ring = &ring_mode_ops; 2645 priv->hw->mode = &ring_mode_ops;
2641 pr_info(" Ring mode enabled\n"); 2646 pr_info(" Ring mode enabled\n");
2642 priv->mode = STMMAC_RING_MODE; 2647 priv->mode = STMMAC_RING_MODE;
2643 } 2648 }
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index c61bc72b8e90..8fb32a80f1c1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -36,7 +36,7 @@ static const struct of_device_id stmmac_dt_ids[] = {
36#ifdef CONFIG_DWMAC_STI 36#ifdef CONFIG_DWMAC_STI
37 { .compatible = "st,stih415-dwmac", .data = &sti_gmac_data}, 37 { .compatible = "st,stih415-dwmac", .data = &sti_gmac_data},
38 { .compatible = "st,stih416-dwmac", .data = &sti_gmac_data}, 38 { .compatible = "st,stih416-dwmac", .data = &sti_gmac_data},
39 { .compatible = "st,stih127-dwmac", .data = &sti_gmac_data}, 39 { .compatible = "st,stid127-dwmac", .data = &sti_gmac_data},
40#endif 40#endif
41 /* SoC specific glue layers should come before generic bindings */ 41 /* SoC specific glue layers should come before generic bindings */
42 { .compatible = "st,spear600-gmac"}, 42 { .compatible = "st,spear600-gmac"},
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 7141a1937360..d6fce9750b95 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -442,6 +442,8 @@ static int netvsc_probe(struct hv_device *dev,
442 if (!net) 442 if (!net)
443 return -ENOMEM; 443 return -ENOMEM;
444 444
445 netif_carrier_off(net);
446
445 net_device_ctx = netdev_priv(net); 447 net_device_ctx = netdev_priv(net);
446 net_device_ctx->device_ctx = dev; 448 net_device_ctx->device_ctx = dev;
447 hv_set_drvdata(dev, net); 449 hv_set_drvdata(dev, net);
@@ -473,6 +475,8 @@ static int netvsc_probe(struct hv_device *dev,
473 pr_err("Unable to register netdev.\n"); 475 pr_err("Unable to register netdev.\n");
474 rndis_filter_device_remove(dev); 476 rndis_filter_device_remove(dev);
475 free_netdev(net); 477 free_netdev(net);
478 } else {
479 schedule_delayed_work(&net_device_ctx->dwork, 0);
476 } 480 }
477 481
478 return ret; 482 return ret;
diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index 1084e5de3ceb..b54fd257652b 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -243,6 +243,22 @@ static int rndis_filter_send_request(struct rndis_device *dev,
243 return ret; 243 return ret;
244} 244}
245 245
246static void rndis_set_link_state(struct rndis_device *rdev,
247 struct rndis_request *request)
248{
249 u32 link_status;
250 struct rndis_query_complete *query_complete;
251
252 query_complete = &request->response_msg.msg.query_complete;
253
254 if (query_complete->status == RNDIS_STATUS_SUCCESS &&
255 query_complete->info_buflen == sizeof(u32)) {
256 memcpy(&link_status, (void *)((unsigned long)query_complete +
257 query_complete->info_buf_offset), sizeof(u32));
258 rdev->link_state = link_status != 0;
259 }
260}
261
246static void rndis_filter_receive_response(struct rndis_device *dev, 262static void rndis_filter_receive_response(struct rndis_device *dev,
247 struct rndis_message *resp) 263 struct rndis_message *resp)
248{ 264{
@@ -272,6 +288,10 @@ static void rndis_filter_receive_response(struct rndis_device *dev,
272 sizeof(struct rndis_message) + RNDIS_EXT_LEN) { 288 sizeof(struct rndis_message) + RNDIS_EXT_LEN) {
273 memcpy(&request->response_msg, resp, 289 memcpy(&request->response_msg, resp,
274 resp->msg_len); 290 resp->msg_len);
291 if (request->request_msg.ndis_msg_type ==
292 RNDIS_MSG_QUERY && request->request_msg.msg.
293 query_req.oid == RNDIS_OID_GEN_MEDIA_CONNECT_STATUS)
294 rndis_set_link_state(dev, request);
275 } else { 295 } else {
276 netdev_err(ndev, 296 netdev_err(ndev,
277 "rndis response buffer overflow " 297 "rndis response buffer overflow "
@@ -620,7 +640,6 @@ static int rndis_filter_query_device_link_status(struct rndis_device *dev)
620 ret = rndis_filter_query_device(dev, 640 ret = rndis_filter_query_device(dev,
621 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, 641 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
622 &link_status, &size); 642 &link_status, &size);
623 dev->link_state = (link_status != 0) ? true : false;
624 643
625 return ret; 644 return ret;
626} 645}
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index ab31544bc254..a30258aad139 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -546,12 +546,12 @@ at86rf230_xmit(struct ieee802154_dev *dev, struct sk_buff *skb)
546 int rc; 546 int rc;
547 unsigned long flags; 547 unsigned long flags;
548 548
549 spin_lock(&lp->lock); 549 spin_lock_irqsave(&lp->lock, flags);
550 if (lp->irq_busy) { 550 if (lp->irq_busy) {
551 spin_unlock(&lp->lock); 551 spin_unlock_irqrestore(&lp->lock, flags);
552 return -EBUSY; 552 return -EBUSY;
553 } 553 }
554 spin_unlock(&lp->lock); 554 spin_unlock_irqrestore(&lp->lock, flags);
555 555
556 might_sleep(); 556 might_sleep();
557 557
@@ -725,10 +725,11 @@ static void at86rf230_irqwork_level(struct work_struct *work)
725static irqreturn_t at86rf230_isr(int irq, void *data) 725static irqreturn_t at86rf230_isr(int irq, void *data)
726{ 726{
727 struct at86rf230_local *lp = data; 727 struct at86rf230_local *lp = data;
728 unsigned long flags;
728 729
729 spin_lock(&lp->lock); 730 spin_lock_irqsave(&lp->lock, flags);
730 lp->irq_busy = 1; 731 lp->irq_busy = 1;
731 spin_unlock(&lp->lock); 732 spin_unlock_irqrestore(&lp->lock, flags);
732 733
733 schedule_work(&lp->irqwork); 734 schedule_work(&lp->irqwork);
734 735
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 19c9eca0ef26..76d96b9ebcdb 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -164,9 +164,9 @@ static const struct phy_setting settings[] = {
164 * of that setting. Returns the index of the last setting if 164 * of that setting. Returns the index of the last setting if
165 * none of the others match. 165 * none of the others match.
166 */ 166 */
167static inline int phy_find_setting(int speed, int duplex) 167static inline unsigned int phy_find_setting(int speed, int duplex)
168{ 168{
169 int idx = 0; 169 unsigned int idx = 0;
170 170
171 while (idx < ARRAY_SIZE(settings) && 171 while (idx < ARRAY_SIZE(settings) &&
172 (settings[idx].speed != speed || settings[idx].duplex != duplex)) 172 (settings[idx].speed != speed || settings[idx].duplex != duplex))
@@ -185,7 +185,7 @@ static inline int phy_find_setting(int speed, int duplex)
185 * the mask in features. Returns the index of the last setting 185 * the mask in features. Returns the index of the last setting
186 * if nothing else matches. 186 * if nothing else matches.
187 */ 187 */
188static inline int phy_find_valid(int idx, u32 features) 188static inline unsigned int phy_find_valid(unsigned int idx, u32 features)
189{ 189{
190 while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features)) 190 while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features))
191 idx++; 191 idx++;
@@ -204,7 +204,7 @@ static inline int phy_find_valid(int idx, u32 features)
204static void phy_sanitize_settings(struct phy_device *phydev) 204static void phy_sanitize_settings(struct phy_device *phydev)
205{ 205{
206 u32 features = phydev->supported; 206 u32 features = phydev->supported;
207 int idx; 207 unsigned int idx;
208 208
209 /* Sanitize settings based on PHY capabilities */ 209 /* Sanitize settings based on PHY capabilities */
210 if ((features & SUPPORTED_Autoneg) == 0) 210 if ((features & SUPPORTED_Autoneg) == 0)
@@ -954,7 +954,8 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)
954 (phydev->interface == PHY_INTERFACE_MODE_RGMII))) { 954 (phydev->interface == PHY_INTERFACE_MODE_RGMII))) {
955 int eee_lp, eee_cap, eee_adv; 955 int eee_lp, eee_cap, eee_adv;
956 u32 lp, cap, adv; 956 u32 lp, cap, adv;
957 int idx, status; 957 int status;
958 unsigned int idx;
958 959
959 /* Read phy status to properly get the right settings */ 960 /* Read phy status to properly get the right settings */
960 status = phy_read_status(phydev); 961 status = phy_read_status(phydev);
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index 433f0a00c683..e2797f1e1b31 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -11,7 +11,7 @@ obj-$(CONFIG_USB_HSO) += hso.o
11obj-$(CONFIG_USB_NET_AX8817X) += asix.o 11obj-$(CONFIG_USB_NET_AX8817X) += asix.o
12asix-y := asix_devices.o asix_common.o ax88172a.o 12asix-y := asix_devices.o asix_common.o ax88172a.o
13obj-$(CONFIG_USB_NET_AX88179_178A) += ax88179_178a.o 13obj-$(CONFIG_USB_NET_AX88179_178A) += ax88179_178a.o
14obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o r815x.o 14obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o
15obj-$(CONFIG_USB_NET_CDC_EEM) += cdc_eem.o 15obj-$(CONFIG_USB_NET_CDC_EEM) += cdc_eem.o
16obj-$(CONFIG_USB_NET_DM9601) += dm9601.o 16obj-$(CONFIG_USB_NET_DM9601) += dm9601.o
17obj-$(CONFIG_USB_NET_SR9700) += sr9700.o 17obj-$(CONFIG_USB_NET_SR9700) += sr9700.o
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index 42e176912c8e..bd363b27e854 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -652,6 +652,13 @@ static const struct usb_device_id products[] = {
652 .driver_info = 0, 652 .driver_info = 0,
653}, 653},
654 654
655/* Samsung USB Ethernet Adapters */
656{
657 USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, 0xa101, USB_CLASS_COMM,
658 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
659 .driver_info = 0,
660},
661
655/* WHITELIST!!! 662/* WHITELIST!!!
656 * 663 *
657 * CDC Ether uses two interfaces, not necessarily consecutive. 664 * CDC Ether uses two interfaces, not necessarily consecutive.
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index d89dbe395ad2..adb12f349a61 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -449,9 +449,6 @@ enum rtl8152_flags {
449#define MCU_TYPE_PLA 0x0100 449#define MCU_TYPE_PLA 0x0100
450#define MCU_TYPE_USB 0x0000 450#define MCU_TYPE_USB 0x0000
451 451
452#define REALTEK_USB_DEVICE(vend, prod) \
453 USB_DEVICE_INTERFACE_CLASS(vend, prod, USB_CLASS_VENDOR_SPEC)
454
455struct rx_desc { 452struct rx_desc {
456 __le32 opts1; 453 __le32 opts1;
457#define RX_LEN_MASK 0x7fff 454#define RX_LEN_MASK 0x7fff
@@ -2739,6 +2736,12 @@ static int rtl8152_probe(struct usb_interface *intf,
2739 struct net_device *netdev; 2736 struct net_device *netdev;
2740 int ret; 2737 int ret;
2741 2738
2739 if (udev->actconfig->desc.bConfigurationValue != 1) {
2740 usb_driver_set_configuration(udev, 1);
2741 return -ENODEV;
2742 }
2743
2744 usb_reset_device(udev);
2742 netdev = alloc_etherdev(sizeof(struct r8152)); 2745 netdev = alloc_etherdev(sizeof(struct r8152));
2743 if (!netdev) { 2746 if (!netdev) {
2744 dev_err(&intf->dev, "Out of memory\n"); 2747 dev_err(&intf->dev, "Out of memory\n");
@@ -2819,9 +2822,9 @@ static void rtl8152_disconnect(struct usb_interface *intf)
2819 2822
2820/* table of devices that work with this driver */ 2823/* table of devices that work with this driver */
2821static struct usb_device_id rtl8152_table[] = { 2824static struct usb_device_id rtl8152_table[] = {
2822 {REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8152)}, 2825 {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8152)},
2823 {REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8153)}, 2826 {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8153)},
2824 {REALTEK_USB_DEVICE(VENDOR_ID_SAMSUNG, PRODUCT_ID_SAMSUNG)}, 2827 {USB_DEVICE(VENDOR_ID_SAMSUNG, PRODUCT_ID_SAMSUNG)},
2825 {} 2828 {}
2826}; 2829};
2827 2830
diff --git a/drivers/net/usb/r815x.c b/drivers/net/usb/r815x.c
deleted file mode 100644
index f0a8791b7636..000000000000
--- a/drivers/net/usb/r815x.c
+++ /dev/null
@@ -1,248 +0,0 @@
1#include <linux/module.h>
2#include <linux/netdevice.h>
3#include <linux/mii.h>
4#include <linux/usb.h>
5#include <linux/usb/cdc.h>
6#include <linux/usb/usbnet.h>
7
8#define RTL815x_REQT_READ 0xc0
9#define RTL815x_REQT_WRITE 0x40
10#define RTL815x_REQ_GET_REGS 0x05
11#define RTL815x_REQ_SET_REGS 0x05
12
13#define MCU_TYPE_PLA 0x0100
14#define OCP_BASE 0xe86c
15#define BASE_MII 0xa400
16
17#define BYTE_EN_DWORD 0xff
18#define BYTE_EN_WORD 0x33
19#define BYTE_EN_BYTE 0x11
20
21#define R815x_PHY_ID 32
22#define REALTEK_VENDOR_ID 0x0bda
23
24
25static int pla_read_word(struct usb_device *udev, u16 index)
26{
27 int ret;
28 u8 shift = index & 2;
29 __le32 *tmp;
30
31 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
32 if (!tmp)
33 return -ENOMEM;
34
35 index &= ~3;
36
37 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
38 RTL815x_REQ_GET_REGS, RTL815x_REQT_READ,
39 index, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500);
40 if (ret < 0)
41 goto out2;
42
43 ret = __le32_to_cpu(*tmp);
44 ret >>= (shift * 8);
45 ret &= 0xffff;
46
47out2:
48 kfree(tmp);
49 return ret;
50}
51
52static int pla_write_word(struct usb_device *udev, u16 index, u32 data)
53{
54 __le32 *tmp;
55 u32 mask = 0xffff;
56 u16 byen = BYTE_EN_WORD;
57 u8 shift = index & 2;
58 int ret;
59
60 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
61 if (!tmp)
62 return -ENOMEM;
63
64 data &= mask;
65
66 if (shift) {
67 byen <<= shift;
68 mask <<= (shift * 8);
69 data <<= (shift * 8);
70 index &= ~3;
71 }
72
73 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
74 RTL815x_REQ_GET_REGS, RTL815x_REQT_READ,
75 index, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500);
76 if (ret < 0)
77 goto out3;
78
79 data |= __le32_to_cpu(*tmp) & ~mask;
80 *tmp = __cpu_to_le32(data);
81
82 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
83 RTL815x_REQ_SET_REGS, RTL815x_REQT_WRITE,
84 index, MCU_TYPE_PLA | byen, tmp, sizeof(*tmp),
85 500);
86
87out3:
88 kfree(tmp);
89 return ret;
90}
91
92static int ocp_reg_read(struct usbnet *dev, u16 addr)
93{
94 u16 ocp_base, ocp_index;
95 int ret;
96
97 ocp_base = addr & 0xf000;
98 ret = pla_write_word(dev->udev, OCP_BASE, ocp_base);
99 if (ret < 0)
100 goto out;
101
102 ocp_index = (addr & 0x0fff) | 0xb000;
103 ret = pla_read_word(dev->udev, ocp_index);
104
105out:
106 return ret;
107}
108
109static int ocp_reg_write(struct usbnet *dev, u16 addr, u16 data)
110{
111 u16 ocp_base, ocp_index;
112 int ret;
113
114 ocp_base = addr & 0xf000;
115 ret = pla_write_word(dev->udev, OCP_BASE, ocp_base);
116 if (ret < 0)
117 goto out1;
118
119 ocp_index = (addr & 0x0fff) | 0xb000;
120 ret = pla_write_word(dev->udev, ocp_index, data);
121
122out1:
123 return ret;
124}
125
126static int r815x_mdio_read(struct net_device *netdev, int phy_id, int reg)
127{
128 struct usbnet *dev = netdev_priv(netdev);
129 int ret;
130
131 if (phy_id != R815x_PHY_ID)
132 return -EINVAL;
133
134 if (usb_autopm_get_interface(dev->intf) < 0)
135 return -ENODEV;
136
137 ret = ocp_reg_read(dev, BASE_MII + reg * 2);
138
139 usb_autopm_put_interface(dev->intf);
140 return ret;
141}
142
143static
144void r815x_mdio_write(struct net_device *netdev, int phy_id, int reg, int val)
145{
146 struct usbnet *dev = netdev_priv(netdev);
147
148 if (phy_id != R815x_PHY_ID)
149 return;
150
151 if (usb_autopm_get_interface(dev->intf) < 0)
152 return;
153
154 ocp_reg_write(dev, BASE_MII + reg * 2, val);
155
156 usb_autopm_put_interface(dev->intf);
157}
158
159static int r8153_bind(struct usbnet *dev, struct usb_interface *intf)
160{
161 int status;
162
163 status = usbnet_cdc_bind(dev, intf);
164 if (status < 0)
165 return status;
166
167 dev->mii.dev = dev->net;
168 dev->mii.mdio_read = r815x_mdio_read;
169 dev->mii.mdio_write = r815x_mdio_write;
170 dev->mii.phy_id_mask = 0x3f;
171 dev->mii.reg_num_mask = 0x1f;
172 dev->mii.phy_id = R815x_PHY_ID;
173 dev->mii.supports_gmii = 1;
174
175 return status;
176}
177
178static int r8152_bind(struct usbnet *dev, struct usb_interface *intf)
179{
180 int status;
181
182 status = usbnet_cdc_bind(dev, intf);
183 if (status < 0)
184 return status;
185
186 dev->mii.dev = dev->net;
187 dev->mii.mdio_read = r815x_mdio_read;
188 dev->mii.mdio_write = r815x_mdio_write;
189 dev->mii.phy_id_mask = 0x3f;
190 dev->mii.reg_num_mask = 0x1f;
191 dev->mii.phy_id = R815x_PHY_ID;
192 dev->mii.supports_gmii = 0;
193
194 return status;
195}
196
197static const struct driver_info r8152_info = {
198 .description = "RTL8152 ECM Device",
199 .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
200 .bind = r8152_bind,
201 .unbind = usbnet_cdc_unbind,
202 .status = usbnet_cdc_status,
203 .manage_power = usbnet_manage_power,
204};
205
206static const struct driver_info r8153_info = {
207 .description = "RTL8153 ECM Device",
208 .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
209 .bind = r8153_bind,
210 .unbind = usbnet_cdc_unbind,
211 .status = usbnet_cdc_status,
212 .manage_power = usbnet_manage_power,
213};
214
215static const struct usb_device_id products[] = {
216{
217 USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8152, USB_CLASS_COMM,
218 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
219 .driver_info = (unsigned long) &r8152_info,
220},
221
222{
223 USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8153, USB_CLASS_COMM,
224 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
225 .driver_info = (unsigned long) &r8153_info,
226},
227
228 { }, /* END */
229};
230MODULE_DEVICE_TABLE(usb, products);
231
232static struct usb_driver r815x_driver = {
233 .name = "r815x",
234 .id_table = products,
235 .probe = usbnet_probe,
236 .disconnect = usbnet_disconnect,
237 .suspend = usbnet_suspend,
238 .resume = usbnet_resume,
239 .reset_resume = usbnet_resume,
240 .supports_autosuspend = 1,
241 .disable_hub_initiated_lpm = 1,
242};
243
244module_usb_driver(r815x_driver);
245
246MODULE_AUTHOR("Hayes Wang");
247MODULE_DESCRIPTION("Realtek USB ECM device");
248MODULE_LICENSE("GPL");
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
index 3be786faaaec..0fa3b44f7342 100644
--- a/drivers/net/vmxnet3/vmxnet3_drv.c
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -1762,11 +1762,20 @@ vmxnet3_netpoll(struct net_device *netdev)
1762{ 1762{
1763 struct vmxnet3_adapter *adapter = netdev_priv(netdev); 1763 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1764 1764
1765 if (adapter->intr.mask_mode == VMXNET3_IMM_ACTIVE) 1765 switch (adapter->intr.type) {
1766 vmxnet3_disable_all_intrs(adapter); 1766#ifdef CONFIG_PCI_MSI
1767 1767 case VMXNET3_IT_MSIX: {
1768 vmxnet3_do_poll(adapter, adapter->rx_queue[0].rx_ring[0].size); 1768 int i;
1769 vmxnet3_enable_all_intrs(adapter); 1769 for (i = 0; i < adapter->num_rx_queues; i++)
1770 vmxnet3_msix_rx(0, &adapter->rx_queue[i]);
1771 break;
1772 }
1773#endif
1774 case VMXNET3_IT_MSI:
1775 default:
1776 vmxnet3_intr(0, adapter->netdev);
1777 break;
1778 }
1770 1779
1771} 1780}
1772#endif /* CONFIG_NET_POLL_CONTROLLER */ 1781#endif /* CONFIG_NET_POLL_CONTROLLER */
diff --git a/drivers/net/wireless/iwlwifi/mvm/bt-coex.c b/drivers/net/wireless/iwlwifi/mvm/bt-coex.c
index 76cde6ce6551..18a895a949d4 100644
--- a/drivers/net/wireless/iwlwifi/mvm/bt-coex.c
+++ b/drivers/net/wireless/iwlwifi/mvm/bt-coex.c
@@ -872,8 +872,11 @@ void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
872 872
873 lockdep_assert_held(&mvm->mutex); 873 lockdep_assert_held(&mvm->mutex);
874 874
875 /* Rssi update while not associated ?! */ 875 /*
876 if (WARN_ON_ONCE(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)) 876 * Rssi update while not associated - can happen since the statistics
877 * are handled asynchronously
878 */
879 if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
877 return; 880 return;
878 881
879 /* No BT - reports should be disabled */ 882 /* No BT - reports should be disabled */
diff --git a/drivers/net/wireless/iwlwifi/pcie/drv.c b/drivers/net/wireless/iwlwifi/pcie/drv.c
index f47bcbe2945a..3872ead75488 100644
--- a/drivers/net/wireless/iwlwifi/pcie/drv.c
+++ b/drivers/net/wireless/iwlwifi/pcie/drv.c
@@ -359,13 +359,12 @@ static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
359/* 7265 Series */ 359/* 7265 Series */
360 {IWL_PCI_DEVICE(0x095A, 0x5010, iwl7265_2ac_cfg)}, 360 {IWL_PCI_DEVICE(0x095A, 0x5010, iwl7265_2ac_cfg)},
361 {IWL_PCI_DEVICE(0x095A, 0x5110, iwl7265_2ac_cfg)}, 361 {IWL_PCI_DEVICE(0x095A, 0x5110, iwl7265_2ac_cfg)},
362 {IWL_PCI_DEVICE(0x095A, 0x5112, iwl7265_2ac_cfg)},
363 {IWL_PCI_DEVICE(0x095A, 0x5100, iwl7265_2ac_cfg)}, 362 {IWL_PCI_DEVICE(0x095A, 0x5100, iwl7265_2ac_cfg)},
364 {IWL_PCI_DEVICE(0x095A, 0x510A, iwl7265_2ac_cfg)},
365 {IWL_PCI_DEVICE(0x095B, 0x5310, iwl7265_2ac_cfg)}, 363 {IWL_PCI_DEVICE(0x095B, 0x5310, iwl7265_2ac_cfg)},
366 {IWL_PCI_DEVICE(0x095B, 0x5302, iwl7265_2ac_cfg)}, 364 {IWL_PCI_DEVICE(0x095B, 0x5302, iwl7265_n_cfg)},
367 {IWL_PCI_DEVICE(0x095B, 0x5210, iwl7265_2ac_cfg)}, 365 {IWL_PCI_DEVICE(0x095B, 0x5210, iwl7265_2ac_cfg)},
368 {IWL_PCI_DEVICE(0x095A, 0x5012, iwl7265_2ac_cfg)}, 366 {IWL_PCI_DEVICE(0x095A, 0x5012, iwl7265_2ac_cfg)},
367 {IWL_PCI_DEVICE(0x095A, 0x5412, iwl7265_2ac_cfg)},
369 {IWL_PCI_DEVICE(0x095A, 0x5410, iwl7265_2ac_cfg)}, 368 {IWL_PCI_DEVICE(0x095A, 0x5410, iwl7265_2ac_cfg)},
370 {IWL_PCI_DEVICE(0x095A, 0x5400, iwl7265_2ac_cfg)}, 369 {IWL_PCI_DEVICE(0x095A, 0x5400, iwl7265_2ac_cfg)},
371 {IWL_PCI_DEVICE(0x095A, 0x1010, iwl7265_2ac_cfg)}, 370 {IWL_PCI_DEVICE(0x095A, 0x1010, iwl7265_2ac_cfg)},
diff --git a/drivers/net/wireless/mwifiex/11ac.c b/drivers/net/wireless/mwifiex/11ac.c
index 5e0eec4d71c7..5d9a8084665d 100644
--- a/drivers/net/wireless/mwifiex/11ac.c
+++ b/drivers/net/wireless/mwifiex/11ac.c
@@ -189,8 +189,7 @@ int mwifiex_cmd_append_11ac_tlv(struct mwifiex_private *priv,
189 vht_cap->header.len = 189 vht_cap->header.len =
190 cpu_to_le16(sizeof(struct ieee80211_vht_cap)); 190 cpu_to_le16(sizeof(struct ieee80211_vht_cap));
191 memcpy((u8 *)vht_cap + sizeof(struct mwifiex_ie_types_header), 191 memcpy((u8 *)vht_cap + sizeof(struct mwifiex_ie_types_header),
192 (u8 *)bss_desc->bcn_vht_cap + 192 (u8 *)bss_desc->bcn_vht_cap,
193 sizeof(struct ieee_types_header),
194 le16_to_cpu(vht_cap->header.len)); 193 le16_to_cpu(vht_cap->header.len));
195 194
196 mwifiex_fill_vht_cap_tlv(priv, vht_cap, bss_desc->bss_band); 195 mwifiex_fill_vht_cap_tlv(priv, vht_cap, bss_desc->bss_band);
diff --git a/drivers/net/wireless/mwifiex/11n.c b/drivers/net/wireless/mwifiex/11n.c
index 6261f8c53d44..7db1a89fdd95 100644
--- a/drivers/net/wireless/mwifiex/11n.c
+++ b/drivers/net/wireless/mwifiex/11n.c
@@ -308,8 +308,7 @@ mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
308 ht_cap->header.len = 308 ht_cap->header.len =
309 cpu_to_le16(sizeof(struct ieee80211_ht_cap)); 309 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
310 memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header), 310 memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
311 (u8 *) bss_desc->bcn_ht_cap + 311 (u8 *)bss_desc->bcn_ht_cap,
312 sizeof(struct ieee_types_header),
313 le16_to_cpu(ht_cap->header.len)); 312 le16_to_cpu(ht_cap->header.len));
314 313
315 mwifiex_fill_cap_info(priv, radio_type, ht_cap); 314 mwifiex_fill_cap_info(priv, radio_type, ht_cap);
diff --git a/drivers/net/wireless/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
index 0a8a26e10f01..668547c2de84 100644
--- a/drivers/net/wireless/mwifiex/scan.c
+++ b/drivers/net/wireless/mwifiex/scan.c
@@ -2101,12 +2101,12 @@ mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2101 curr_bss->ht_info_offset); 2101 curr_bss->ht_info_offset);
2102 2102
2103 if (curr_bss->bcn_vht_cap) 2103 if (curr_bss->bcn_vht_cap)
2104 curr_bss->bcn_ht_cap = (void *)(curr_bss->beacon_buf + 2104 curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf +
2105 curr_bss->vht_cap_offset); 2105 curr_bss->vht_cap_offset);
2106 2106
2107 if (curr_bss->bcn_vht_oper) 2107 if (curr_bss->bcn_vht_oper)
2108 curr_bss->bcn_ht_oper = (void *)(curr_bss->beacon_buf + 2108 curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf +
2109 curr_bss->vht_info_offset); 2109 curr_bss->vht_info_offset);
2110 2110
2111 if (curr_bss->bcn_bss_co_2040) 2111 if (curr_bss->bcn_bss_co_2040)
2112 curr_bss->bcn_bss_co_2040 = 2112 curr_bss->bcn_bss_co_2040 =
diff --git a/drivers/net/wireless/ti/wl1251/rx.c b/drivers/net/wireless/ti/wl1251/rx.c
index 123c4bb50e0a..cde0eaf99714 100644
--- a/drivers/net/wireless/ti/wl1251/rx.c
+++ b/drivers/net/wireless/ti/wl1251/rx.c
@@ -180,7 +180,7 @@ static void wl1251_rx_body(struct wl1251 *wl,
180 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length); 180 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
181 181
182 /* The actual length doesn't include the target's alignment */ 182 /* The actual length doesn't include the target's alignment */
183 skb->len = desc->length - PLCP_HEADER_LENGTH; 183 skb_trim(skb, desc->length - PLCP_HEADER_LENGTH);
184 184
185 fc = (u16 *)skb->data; 185 fc = (u16 *)skb->data;
186 186
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index 7669d49a67e2..301cc037fda8 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -132,8 +132,7 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
132 /* If the skb is GSO then we'll also need an extra slot for the 132 /* If the skb is GSO then we'll also need an extra slot for the
133 * metadata. 133 * metadata.
134 */ 134 */
135 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 || 135 if (skb_is_gso(skb))
136 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
137 min_slots_needed++; 136 min_slots_needed++;
138 137
139 /* If the skb can't possibly fit in the remaining slots 138 /* If the skb can't possibly fit in the remaining slots
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index e5284bca2d90..438d0c09b7e6 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -240,7 +240,7 @@ static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
240 struct gnttab_copy *copy_gop; 240 struct gnttab_copy *copy_gop;
241 struct xenvif_rx_meta *meta; 241 struct xenvif_rx_meta *meta;
242 unsigned long bytes; 242 unsigned long bytes;
243 int gso_type; 243 int gso_type = XEN_NETIF_GSO_TYPE_NONE;
244 244
245 /* Data must not cross a page boundary. */ 245 /* Data must not cross a page boundary. */
246 BUG_ON(size + offset > PAGE_SIZE<<compound_order(page)); 246 BUG_ON(size + offset > PAGE_SIZE<<compound_order(page));
@@ -299,12 +299,12 @@ static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
299 } 299 }
300 300
301 /* Leave a gap for the GSO descriptor. */ 301 /* Leave a gap for the GSO descriptor. */
302 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) 302 if (skb_is_gso(skb)) {
303 gso_type = XEN_NETIF_GSO_TYPE_TCPV4; 303 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
304 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) 304 gso_type = XEN_NETIF_GSO_TYPE_TCPV4;
305 gso_type = XEN_NETIF_GSO_TYPE_TCPV6; 305 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
306 else 306 gso_type = XEN_NETIF_GSO_TYPE_TCPV6;
307 gso_type = XEN_NETIF_GSO_TYPE_NONE; 307 }
308 308
309 if (*head && ((1 << gso_type) & vif->gso_mask)) 309 if (*head && ((1 << gso_type) & vif->gso_mask))
310 vif->rx.req_cons++; 310 vif->rx.req_cons++;
@@ -338,19 +338,15 @@ static int xenvif_gop_skb(struct sk_buff *skb,
338 int head = 1; 338 int head = 1;
339 int old_meta_prod; 339 int old_meta_prod;
340 int gso_type; 340 int gso_type;
341 int gso_size;
342 341
343 old_meta_prod = npo->meta_prod; 342 old_meta_prod = npo->meta_prod;
344 343
345 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) { 344 gso_type = XEN_NETIF_GSO_TYPE_NONE;
346 gso_type = XEN_NETIF_GSO_TYPE_TCPV4; 345 if (skb_is_gso(skb)) {
347 gso_size = skb_shinfo(skb)->gso_size; 346 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
348 } else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) { 347 gso_type = XEN_NETIF_GSO_TYPE_TCPV4;
349 gso_type = XEN_NETIF_GSO_TYPE_TCPV6; 348 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
350 gso_size = skb_shinfo(skb)->gso_size; 349 gso_type = XEN_NETIF_GSO_TYPE_TCPV6;
351 } else {
352 gso_type = XEN_NETIF_GSO_TYPE_NONE;
353 gso_size = 0;
354 } 350 }
355 351
356 /* Set up a GSO prefix descriptor, if necessary */ 352 /* Set up a GSO prefix descriptor, if necessary */
@@ -358,7 +354,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
358 req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++); 354 req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
359 meta = npo->meta + npo->meta_prod++; 355 meta = npo->meta + npo->meta_prod++;
360 meta->gso_type = gso_type; 356 meta->gso_type = gso_type;
361 meta->gso_size = gso_size; 357 meta->gso_size = skb_shinfo(skb)->gso_size;
362 meta->size = 0; 358 meta->size = 0;
363 meta->id = req->id; 359 meta->id = req->id;
364 } 360 }
@@ -368,7 +364,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
368 364
369 if ((1 << gso_type) & vif->gso_mask) { 365 if ((1 << gso_type) & vif->gso_mask) {
370 meta->gso_type = gso_type; 366 meta->gso_type = gso_type;
371 meta->gso_size = gso_size; 367 meta->gso_size = skb_shinfo(skb)->gso_size;
372 } else { 368 } else {
373 meta->gso_type = XEN_NETIF_GSO_TYPE_NONE; 369 meta->gso_type = XEN_NETIF_GSO_TYPE_NONE;
374 meta->gso_size = 0; 370 meta->gso_size = 0;
@@ -500,8 +496,9 @@ static void xenvif_rx_action(struct xenvif *vif)
500 size = skb_frag_size(&skb_shinfo(skb)->frags[i]); 496 size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
501 max_slots_needed += DIV_ROUND_UP(size, PAGE_SIZE); 497 max_slots_needed += DIV_ROUND_UP(size, PAGE_SIZE);
502 } 498 }
503 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 || 499 if (skb_is_gso(skb) &&
504 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) 500 (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 ||
501 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6))
505 max_slots_needed++; 502 max_slots_needed++;
506 503
507 /* If the skb may not fit then bail out now */ 504 /* If the skb may not fit then bail out now */
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 00660cc502c5..38901665c770 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -162,8 +162,6 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
162 162
163 avail = *r; 163 avail = *r;
164 pci_clip_resource_to_region(bus, &avail, region); 164 pci_clip_resource_to_region(bus, &avail, region);
165 if (!resource_size(&avail))
166 continue;
167 165
168 /* 166 /*
169 * "min" is typically PCIBIOS_MIN_IO or PCIBIOS_MIN_MEM to 167 * "min" is typically PCIBIOS_MIN_IO or PCIBIOS_MIN_MEM to
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 6b05f6134b68..fdbc294821e6 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1192,6 +1192,9 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars)
1192 return err; 1192 return err;
1193 pci_fixup_device(pci_fixup_enable, dev); 1193 pci_fixup_device(pci_fixup_enable, dev);
1194 1194
1195 if (dev->msi_enabled || dev->msix_enabled)
1196 return 0;
1197
1195 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); 1198 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
1196 if (pin) { 1199 if (pin) {
1197 pci_read_config_word(dev, PCI_COMMAND, &cmd); 1200 pci_read_config_word(dev, PCI_COMMAND, &cmd);
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index defb6afc1409..94bb6157c957 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -6776,8 +6776,9 @@ static int __init volume_create_alsa_mixer(void)
6776 struct snd_kcontrol *ctl_mute; 6776 struct snd_kcontrol *ctl_mute;
6777 int rc; 6777 int rc;
6778 6778
6779 rc = snd_card_create(alsa_index, alsa_id, THIS_MODULE, 6779 rc = snd_card_new(&tpacpi_pdev->dev,
6780 sizeof(struct tpacpi_alsa_data), &card); 6780 alsa_index, alsa_id, THIS_MODULE,
6781 sizeof(struct tpacpi_alsa_data), &card);
6781 if (rc < 0 || !card) { 6782 if (rc < 0 || !card) {
6782 pr_err("Failed to create ALSA card structures: %d\n", rc); 6783 pr_err("Failed to create ALSA card structures: %d\n", rc);
6783 return 1; 6784 return 1;
@@ -6828,7 +6829,6 @@ static int __init volume_create_alsa_mixer(void)
6828 } 6829 }
6829 data->ctl_mute_id = &ctl_mute->id; 6830 data->ctl_mute_id = &ctl_mute->id;
6830 6831
6831 snd_card_set_dev(card, &tpacpi_pdev->dev);
6832 rc = snd_card_register(card); 6832 rc = snd_card_register(card);
6833 if (rc < 0) { 6833 if (rc < 0) {
6834 pr_err("Failed to register ALSA card: %d\n", rc); 6834 pr_err("Failed to register ALSA card: %d\n", rc);
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index 167f3d00c916..66977ebf13b3 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -183,9 +183,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
183 struct resource r = {0}; 183 struct resource r = {0};
184 int i, flags; 184 int i, flags;
185 185
186 if (acpi_dev_resource_memory(res, &r) 186 if (acpi_dev_resource_address_space(res, &r)
187 || acpi_dev_resource_io(res, &r)
188 || acpi_dev_resource_address_space(res, &r)
189 || acpi_dev_resource_ext_address_space(res, &r)) { 187 || acpi_dev_resource_ext_address_space(res, &r)) {
190 pnp_add_resource(dev, &r); 188 pnp_add_resource(dev, &r);
191 return AE_OK; 189 return AE_OK;
@@ -217,6 +215,17 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
217 } 215 }
218 216
219 switch (res->type) { 217 switch (res->type) {
218 case ACPI_RESOURCE_TYPE_MEMORY24:
219 case ACPI_RESOURCE_TYPE_MEMORY32:
220 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
221 if (acpi_dev_resource_memory(res, &r))
222 pnp_add_resource(dev, &r);
223 break;
224 case ACPI_RESOURCE_TYPE_IO:
225 case ACPI_RESOURCE_TYPE_FIXED_IO:
226 if (acpi_dev_resource_io(res, &r))
227 pnp_add_resource(dev, &r);
228 break;
220 case ACPI_RESOURCE_TYPE_DMA: 229 case ACPI_RESOURCE_TYPE_DMA:
221 dma = &res->data.dma; 230 dma = &res->data.dma;
222 if (dma->channel_count > 0 && dma->channels[0] != (u8) -1) 231 if (dma->channel_count > 0 && dma->channels[0] != (u8) -1)
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 1f375051483a..5642a9b250c2 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -325,7 +325,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
325 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE) 325 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
326 continue; 326 continue;
327 327
328 if (abrt_task->sc->device->lun != abrt_task->sc->device->lun) 328 if (sc->device->lun != abrt_task->sc->device->lun)
329 continue; 329 continue;
330 330
331 /* Invalidate WRB Posted for this Task */ 331 /* Invalidate WRB Posted for this Task */
diff --git a/drivers/scsi/isci/host.h b/drivers/scsi/isci/host.h
index 4911310a38f5..22a9bb1abae1 100644
--- a/drivers/scsi/isci/host.h
+++ b/drivers/scsi/isci/host.h
@@ -311,9 +311,8 @@ static inline struct Scsi_Host *to_shost(struct isci_host *ihost)
311} 311}
312 312
313#define for_each_isci_host(id, ihost, pdev) \ 313#define for_each_isci_host(id, ihost, pdev) \
314 for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \ 314 for (id = 0; id < SCI_MAX_CONTROLLERS && \
315 id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \ 315 (ihost = to_pci_info(pdev)->hosts[id]); id++)
316 ihost = to_pci_info(pdev)->hosts[++id])
317 316
318static inline void wait_for_start(struct isci_host *ihost) 317static inline void wait_for_start(struct isci_host *ihost)
319{ 318{
diff --git a/drivers/scsi/isci/port_config.c b/drivers/scsi/isci/port_config.c
index 85c77f6b802b..ac879745ef80 100644
--- a/drivers/scsi/isci/port_config.c
+++ b/drivers/scsi/isci/port_config.c
@@ -615,13 +615,6 @@ static void sci_apc_agent_link_up(struct isci_host *ihost,
615 SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION); 615 SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION);
616 } else { 616 } else {
617 /* the phy is already the part of the port */ 617 /* the phy is already the part of the port */
618 u32 port_state = iport->sm.current_state_id;
619
620 /* if the PORT'S state is resetting then the link up is from
621 * port hard reset in this case, we need to tell the port
622 * that link up is recieved
623 */
624 BUG_ON(port_state != SCI_PORT_RESETTING);
625 port_agent->phy_ready_mask |= 1 << phy_index; 618 port_agent->phy_ready_mask |= 1 << phy_index;
626 sci_port_link_up(iport, iphy); 619 sci_port_link_up(iport, iphy);
627 } 620 }
diff --git a/drivers/scsi/isci/task.c b/drivers/scsi/isci/task.c
index 0d30ca849e8f..5d6fda72d659 100644
--- a/drivers/scsi/isci/task.c
+++ b/drivers/scsi/isci/task.c
@@ -801,7 +801,7 @@ int isci_task_I_T_nexus_reset(struct domain_device *dev)
801 /* XXX: need to cleanup any ireqs targeting this 801 /* XXX: need to cleanup any ireqs targeting this
802 * domain_device 802 * domain_device
803 */ 803 */
804 ret = TMF_RESP_FUNC_COMPLETE; 804 ret = -ENODEV;
805 goto out; 805 goto out;
806 } 806 }
807 807
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index e1fe95ef23e1..266724b6b899 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2996,8 +2996,7 @@ struct qla_hw_data {
2996 IS_QLA82XX(ha) || IS_QLA83XX(ha) || \ 2996 IS_QLA82XX(ha) || IS_QLA83XX(ha) || \
2997 IS_QLA8044(ha)) 2997 IS_QLA8044(ha))
2998#define IS_MSIX_NACK_CAPABLE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha)) 2998#define IS_MSIX_NACK_CAPABLE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha))
2999#define IS_NOPOLLING_TYPE(ha) ((IS_QLA25XX(ha) || IS_QLA81XX(ha) || \ 2999#define IS_NOPOLLING_TYPE(ha) (IS_QLA81XX(ha) && (ha)->flags.msix_enabled)
3000 IS_QLA83XX(ha)) && (ha)->flags.msix_enabled)
3001#define IS_FAC_REQUIRED(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha)) 3000#define IS_FAC_REQUIRED(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha))
3002#define IS_NOCACHE_VPD_TYPE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha)) 3001#define IS_NOCACHE_VPD_TYPE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha))
3003#define IS_ALOGIO_CAPABLE(ha) (IS_QLA23XX(ha) || IS_FWI2_CAPABLE(ha)) 3002#define IS_ALOGIO_CAPABLE(ha) (IS_QLA23XX(ha) || IS_FWI2_CAPABLE(ha))
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 9bc86b9e86b1..0a1dcb43d18b 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -2880,6 +2880,7 @@ static int
2880qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp) 2880qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
2881{ 2881{
2882#define MIN_MSIX_COUNT 2 2882#define MIN_MSIX_COUNT 2
2883#define ATIO_VECTOR 2
2883 int i, ret; 2884 int i, ret;
2884 struct msix_entry *entries; 2885 struct msix_entry *entries;
2885 struct qla_msix_entry *qentry; 2886 struct qla_msix_entry *qentry;
@@ -2936,34 +2937,47 @@ msix_failed:
2936 } 2937 }
2937 2938
2938 /* Enable MSI-X vectors for the base queue */ 2939 /* Enable MSI-X vectors for the base queue */
2939 for (i = 0; i < ha->msix_count; i++) { 2940 for (i = 0; i < 2; i++) {
2940 qentry = &ha->msix_entries[i]; 2941 qentry = &ha->msix_entries[i];
2941 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) { 2942 if (IS_P3P_TYPE(ha))
2942 ret = request_irq(qentry->vector,
2943 qla83xx_msix_entries[i].handler,
2944 0, qla83xx_msix_entries[i].name, rsp);
2945 } else if (IS_P3P_TYPE(ha)) {
2946 ret = request_irq(qentry->vector, 2943 ret = request_irq(qentry->vector,
2947 qla82xx_msix_entries[i].handler, 2944 qla82xx_msix_entries[i].handler,
2948 0, qla82xx_msix_entries[i].name, rsp); 2945 0, qla82xx_msix_entries[i].name, rsp);
2949 } else { 2946 else
2950 ret = request_irq(qentry->vector, 2947 ret = request_irq(qentry->vector,
2951 msix_entries[i].handler, 2948 msix_entries[i].handler,
2952 0, msix_entries[i].name, rsp); 2949 0, msix_entries[i].name, rsp);
2953 } 2950 if (ret)
2954 if (ret) { 2951 goto msix_register_fail;
2955 ql_log(ql_log_fatal, vha, 0x00cb,
2956 "MSI-X: unable to register handler -- %x/%d.\n",
2957 qentry->vector, ret);
2958 qla24xx_disable_msix(ha);
2959 ha->mqenable = 0;
2960 goto msix_out;
2961 }
2962 qentry->have_irq = 1; 2952 qentry->have_irq = 1;
2963 qentry->rsp = rsp; 2953 qentry->rsp = rsp;
2964 rsp->msix = qentry; 2954 rsp->msix = qentry;
2965 } 2955 }
2966 2956
2957 /*
2958 * If target mode is enable, also request the vector for the ATIO
2959 * queue.
2960 */
2961 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
2962 qentry = &ha->msix_entries[ATIO_VECTOR];
2963 ret = request_irq(qentry->vector,
2964 qla83xx_msix_entries[ATIO_VECTOR].handler,
2965 0, qla83xx_msix_entries[ATIO_VECTOR].name, rsp);
2966 qentry->have_irq = 1;
2967 qentry->rsp = rsp;
2968 rsp->msix = qentry;
2969 }
2970
2971msix_register_fail:
2972 if (ret) {
2973 ql_log(ql_log_fatal, vha, 0x00cb,
2974 "MSI-X: unable to register handler -- %x/%d.\n",
2975 qentry->vector, ret);
2976 qla24xx_disable_msix(ha);
2977 ha->mqenable = 0;
2978 goto msix_out;
2979 }
2980
2967 /* Enable MSI-X vector for response queue update for queue 0 */ 2981 /* Enable MSI-X vector for response queue update for queue 0 */
2968 if (IS_QLA83XX(ha)) { 2982 if (IS_QLA83XX(ha)) {
2969 if (ha->msixbase && ha->mqiobase && 2983 if (ha->msixbase && ha->mqiobase &&
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 17d740427240..9969fa1ef7c4 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1419,6 +1419,9 @@ static void storvsc_device_destroy(struct scsi_device *sdevice)
1419{ 1419{
1420 struct stor_mem_pools *memp = sdevice->hostdata; 1420 struct stor_mem_pools *memp = sdevice->hostdata;
1421 1421
1422 if (!memp)
1423 return;
1424
1422 mempool_destroy(memp->request_mempool); 1425 mempool_destroy(memp->request_mempool);
1423 kmem_cache_destroy(memp->request_pool); 1426 kmem_cache_destroy(memp->request_pool);
1424 kfree(memp); 1427 kfree(memp);
diff --git a/drivers/staging/line6/audio.c b/drivers/staging/line6/audio.c
index a92e21f7d55b..171d80c1b020 100644
--- a/drivers/staging/line6/audio.c
+++ b/drivers/staging/line6/audio.c
@@ -24,8 +24,9 @@ int line6_init_audio(struct usb_line6 *line6)
24 struct snd_card *card; 24 struct snd_card *card;
25 int err; 25 int err;
26 26
27 err = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 27 err = snd_card_new(line6->ifcdev,
28 THIS_MODULE, 0, &card); 28 SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
29 THIS_MODULE, 0, &card);
29 if (err < 0) 30 if (err < 0)
30 return err; 31 return err;
31 32
diff --git a/drivers/staging/line6/midi.c b/drivers/staging/line6/midi.c
index 3f6d78c585fb..c61cd0515baf 100644
--- a/drivers/staging/line6/midi.c
+++ b/drivers/staging/line6/midi.c
@@ -307,8 +307,6 @@ int line6_init_midi(struct usb_line6 *line6)
307 if (err < 0) 307 if (err < 0)
308 return err; 308 return err;
309 309
310 snd_card_set_dev(line6->card, line6->ifcdev);
311
312 err = snd_line6_new_midi(line6midi); 310 err = snd_line6_new_midi(line6midi);
313 if (err < 0) 311 if (err < 0)
314 return err; 312 return err;
diff --git a/drivers/staging/line6/pcm.c b/drivers/staging/line6/pcm.c
index df8331bce175..661080b3c39d 100644
--- a/drivers/staging/line6/pcm.c
+++ b/drivers/staging/line6/pcm.c
@@ -501,8 +501,6 @@ int line6_init_pcm(struct usb_line6 *line6,
501 if (err < 0) 501 if (err < 0)
502 return err; 502 return err;
503 503
504 snd_card_set_dev(line6->card, line6->ifcdev);
505
506 err = snd_line6_new_pcm(line6pcm); 504 err = snd_line6_new_pcm(line6pcm);
507 if (err < 0) 505 if (err < 0)
508 return err; 506 return err;
diff --git a/drivers/staging/media/go7007/snd-go7007.c b/drivers/staging/media/go7007/snd-go7007.c
index 16dd64920767..9eb2a20ae40a 100644
--- a/drivers/staging/media/go7007/snd-go7007.c
+++ b/drivers/staging/media/go7007/snd-go7007.c
@@ -245,8 +245,8 @@ int go7007_snd_init(struct go7007 *go)
245 spin_lock_init(&gosnd->lock); 245 spin_lock_init(&gosnd->lock);
246 gosnd->hw_ptr = gosnd->w_idx = gosnd->avail = 0; 246 gosnd->hw_ptr = gosnd->w_idx = gosnd->avail = 0;
247 gosnd->capturing = 0; 247 gosnd->capturing = 0;
248 ret = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, 248 ret = snd_card_new(go->dev, index[dev], id[dev], THIS_MODULE, 0,
249 &gosnd->card); 249 &gosnd->card);
250 if (ret < 0) { 250 if (ret < 0) {
251 kfree(gosnd); 251 kfree(gosnd);
252 return ret; 252 return ret;
@@ -257,7 +257,6 @@ int go7007_snd_init(struct go7007 *go)
257 kfree(gosnd); 257 kfree(gosnd);
258 return ret; 258 return ret;
259 } 259 }
260 snd_card_set_dev(gosnd->card, go->dev);
261 ret = snd_pcm_new(gosnd->card, "go7007", 0, 0, 1, &gosnd->pcm); 260 ret = snd_pcm_new(gosnd->card, "go7007", 0, 0, 1, &gosnd->pcm);
262 if (ret < 0) { 261 if (ret < 0) {
263 snd_card_free(gosnd->card); 262 snd_card_free(gosnd->card);
diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
index 1db18c7972a0..74f037b6166c 100644
--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
@@ -366,8 +366,9 @@ int solo_g723_init(struct solo_dev *solo_dev)
366 /* Allows for easier mapping between video and audio */ 366 /* Allows for easier mapping between video and audio */
367 sprintf(name, "Softlogic%d", solo_dev->vfd->num); 367 sprintf(name, "Softlogic%d", solo_dev->vfd->num);
368 368
369 ret = snd_card_create(SNDRV_DEFAULT_IDX1, name, THIS_MODULE, 0, 369 ret = snd_card_new(&solo_dev->pdev->dev,
370 &solo_dev->snd_card); 370 SNDRV_DEFAULT_IDX1, name, THIS_MODULE, 0,
371 &solo_dev->snd_card);
371 if (ret < 0) 372 if (ret < 0)
372 return ret; 373 return ret;
373 374
@@ -377,7 +378,6 @@ int solo_g723_init(struct solo_dev *solo_dev)
377 strcpy(card->shortname, "SOLO-6x10 Audio"); 378 strcpy(card->shortname, "SOLO-6x10 Audio");
378 sprintf(card->longname, "%s on %s IRQ %d", card->shortname, 379 sprintf(card->longname, "%s on %s IRQ %d", card->shortname,
379 pci_name(solo_dev->pdev), solo_dev->pdev->irq); 380 pci_name(solo_dev->pdev), solo_dev->pdev->irq);
380 snd_card_set_dev(card, &solo_dev->pdev->dev);
381 381
382 ret = snd_device_new(card, SNDRV_DEV_LOWLEVEL, solo_dev, &ops); 382 ret = snd_device_new(card, SNDRV_DEV_LOWLEVEL, solo_dev, &ops);
383 if (ret < 0) 383 if (ret < 0)
diff --git a/drivers/usb/gadget/f_midi.c b/drivers/usb/gadget/f_midi.c
index 36d4bb23087f..807b31c0edc3 100644
--- a/drivers/usb/gadget/f_midi.c
+++ b/drivers/usb/gadget/f_midi.c
@@ -664,9 +664,10 @@ static int f_midi_register_card(struct f_midi *midi)
664 .dev_free = f_midi_snd_free, 664 .dev_free = f_midi_snd_free,
665 }; 665 };
666 666
667 err = snd_card_create(midi->index, midi->id, THIS_MODULE, 0, &card); 667 err = snd_card_new(&midi->gadget->dev, midi->index, midi->id,
668 THIS_MODULE, 0, &card);
668 if (err < 0) { 669 if (err < 0) {
669 ERROR(midi, "snd_card_create() failed\n"); 670 ERROR(midi, "snd_card_new() failed\n");
670 goto fail; 671 goto fail;
671 } 672 }
672 midi->card = card; 673 midi->card = card;
@@ -703,8 +704,6 @@ static int f_midi_register_card(struct f_midi *midi)
703 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &gmidi_in_ops); 704 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &gmidi_in_ops);
704 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &gmidi_out_ops); 705 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &gmidi_out_ops);
705 706
706 snd_card_set_dev(card, &midi->gadget->dev);
707
708 /* register it - we're ready to go */ 707 /* register it - we're ready to go */
709 err = snd_card_register(card); 708 err = snd_card_register(card);
710 if (err < 0) { 709 if (err < 0) {
diff --git a/drivers/usb/gadget/f_uac2.c b/drivers/usb/gadget/f_uac2.c
index 2f23566e53d8..bc23040c7790 100644
--- a/drivers/usb/gadget/f_uac2.c
+++ b/drivers/usb/gadget/f_uac2.c
@@ -394,7 +394,7 @@ static int snd_uac2_probe(struct platform_device *pdev)
394 int err; 394 int err;
395 395
396 /* Choose any slot, with no id */ 396 /* Choose any slot, with no id */
397 err = snd_card_create(-1, NULL, THIS_MODULE, 0, &card); 397 err = snd_card_new(&pdev->dev, -1, NULL, THIS_MODULE, 0, &card);
398 if (err < 0) 398 if (err < 0)
399 return err; 399 return err;
400 400
@@ -421,8 +421,6 @@ static int snd_uac2_probe(struct platform_device *pdev)
421 strcpy(card->shortname, "UAC2_Gadget"); 421 strcpy(card->shortname, "UAC2_Gadget");
422 sprintf(card->longname, "UAC2_Gadget %i", pdev->id); 422 sprintf(card->longname, "UAC2_Gadget %i", pdev->id);
423 423
424 snd_card_set_dev(card, &pdev->dev);
425
426 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, 424 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
427 snd_dma_continuous_data(GFP_KERNEL), 0, BUFF_SIZE_MAX); 425 snd_dma_continuous_data(GFP_KERNEL), 0, BUFF_SIZE_MAX);
428 426
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index cf32f0393369..c0f3718b77a8 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -513,7 +513,7 @@ struct cifs_mnt_data {
513static inline unsigned int 513static inline unsigned int
514get_rfc1002_length(void *buf) 514get_rfc1002_length(void *buf)
515{ 515{
516 return be32_to_cpu(*((__be32 *)buf)); 516 return be32_to_cpu(*((__be32 *)buf)) & 0xffffff;
517} 517}
518 518
519static inline void 519static inline void
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 53c15074bb36..834fce759d80 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2579,31 +2579,19 @@ cifs_writev(struct kiocb *iocb, const struct iovec *iov,
2579 struct cifsInodeInfo *cinode = CIFS_I(inode); 2579 struct cifsInodeInfo *cinode = CIFS_I(inode);
2580 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; 2580 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
2581 ssize_t rc = -EACCES; 2581 ssize_t rc = -EACCES;
2582 loff_t lock_pos = pos;
2582 2583
2583 BUG_ON(iocb->ki_pos != pos); 2584 if (file->f_flags & O_APPEND)
2584 2585 lock_pos = i_size_read(inode);
2585 /* 2586 /*
2586 * We need to hold the sem to be sure nobody modifies lock list 2587 * We need to hold the sem to be sure nobody modifies lock list
2587 * with a brlock that prevents writing. 2588 * with a brlock that prevents writing.
2588 */ 2589 */
2589 down_read(&cinode->lock_sem); 2590 down_read(&cinode->lock_sem);
2590 if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs), 2591 if (!cifs_find_lock_conflict(cfile, lock_pos, iov_length(iov, nr_segs),
2591 server->vals->exclusive_lock_type, NULL, 2592 server->vals->exclusive_lock_type, NULL,
2592 CIFS_WRITE_OP)) { 2593 CIFS_WRITE_OP))
2593 mutex_lock(&inode->i_mutex); 2594 rc = generic_file_aio_write(iocb, iov, nr_segs, pos);
2594 rc = __generic_file_aio_write(iocb, iov, nr_segs,
2595 &iocb->ki_pos);
2596 mutex_unlock(&inode->i_mutex);
2597 }
2598
2599 if (rc > 0) {
2600 ssize_t err;
2601
2602 err = generic_write_sync(file, iocb->ki_pos - rc, rc);
2603 if (err < 0)
2604 rc = err;
2605 }
2606
2607 up_read(&cinode->lock_sem); 2595 up_read(&cinode->lock_sem);
2608 return rc; 2596 return rc;
2609} 2597}
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index b37570952846..18cd5650a5fc 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -270,6 +270,26 @@ cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx,
270 iov->iov_len = rqst->rq_pagesz; 270 iov->iov_len = rqst->rq_pagesz;
271} 271}
272 272
273static unsigned long
274rqst_len(struct smb_rqst *rqst)
275{
276 unsigned int i;
277 struct kvec *iov = rqst->rq_iov;
278 unsigned long buflen = 0;
279
280 /* total up iov array first */
281 for (i = 0; i < rqst->rq_nvec; i++)
282 buflen += iov[i].iov_len;
283
284 /* add in the page array if there is one */
285 if (rqst->rq_npages) {
286 buflen += rqst->rq_pagesz * (rqst->rq_npages - 1);
287 buflen += rqst->rq_tailsz;
288 }
289
290 return buflen;
291}
292
273static int 293static int
274smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) 294smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
275{ 295{
@@ -277,6 +297,7 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
277 struct kvec *iov = rqst->rq_iov; 297 struct kvec *iov = rqst->rq_iov;
278 int n_vec = rqst->rq_nvec; 298 int n_vec = rqst->rq_nvec;
279 unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base); 299 unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base);
300 unsigned long send_length;
280 unsigned int i; 301 unsigned int i;
281 size_t total_len = 0, sent; 302 size_t total_len = 0, sent;
282 struct socket *ssocket = server->ssocket; 303 struct socket *ssocket = server->ssocket;
@@ -285,6 +306,14 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
285 if (ssocket == NULL) 306 if (ssocket == NULL)
286 return -ENOTSOCK; 307 return -ENOTSOCK;
287 308
309 /* sanity check send length */
310 send_length = rqst_len(rqst);
311 if (send_length != smb_buf_length + 4) {
312 WARN(1, "Send length mismatch(send_length=%lu smb_buf_length=%u)\n",
313 send_length, smb_buf_length);
314 return -EIO;
315 }
316
288 cifs_dbg(FYI, "Sending smb: smb_len=%u\n", smb_buf_length); 317 cifs_dbg(FYI, "Sending smb: smb_len=%u\n", smb_buf_length);
289 dump_smb(iov[0].iov_base, iov[0].iov_len); 318 dump_smb(iov[0].iov_base, iov[0].iov_len);
290 319
diff --git a/fs/file.c b/fs/file.c
index db25c2bdfe46..60a45e9f5323 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -683,35 +683,65 @@ EXPORT_SYMBOL(fget_raw);
683 * The fput_needed flag returned by fget_light should be passed to the 683 * The fput_needed flag returned by fget_light should be passed to the
684 * corresponding fput_light. 684 * corresponding fput_light.
685 */ 685 */
686struct file *__fget_light(unsigned int fd, fmode_t mask, int *fput_needed) 686static unsigned long __fget_light(unsigned int fd, fmode_t mask)
687{ 687{
688 struct files_struct *files = current->files; 688 struct files_struct *files = current->files;
689 struct file *file; 689 struct file *file;
690 690
691 *fput_needed = 0;
692 if (atomic_read(&files->count) == 1) { 691 if (atomic_read(&files->count) == 1) {
693 file = __fcheck_files(files, fd); 692 file = __fcheck_files(files, fd);
694 if (file && (file->f_mode & mask)) 693 if (!file || unlikely(file->f_mode & mask))
695 file = NULL; 694 return 0;
695 return (unsigned long)file;
696 } else { 696 } else {
697 file = __fget(fd, mask); 697 file = __fget(fd, mask);
698 if (file) 698 if (!file)
699 *fput_needed = 1; 699 return 0;
700 return FDPUT_FPUT | (unsigned long)file;
700 } 701 }
701
702 return file;
703} 702}
704struct file *fget_light(unsigned int fd, int *fput_needed) 703unsigned long __fdget(unsigned int fd)
705{ 704{
706 return __fget_light(fd, FMODE_PATH, fput_needed); 705 return __fget_light(fd, FMODE_PATH);
707} 706}
708EXPORT_SYMBOL(fget_light); 707EXPORT_SYMBOL(__fdget);
709 708
710struct file *fget_raw_light(unsigned int fd, int *fput_needed) 709unsigned long __fdget_raw(unsigned int fd)
711{ 710{
712 return __fget_light(fd, 0, fput_needed); 711 return __fget_light(fd, 0);
712}
713
714unsigned long __fdget_pos(unsigned int fd)
715{
716 struct files_struct *files = current->files;
717 struct file *file;
718 unsigned long v;
719
720 if (atomic_read(&files->count) == 1) {
721 file = __fcheck_files(files, fd);
722 v = 0;
723 } else {
724 file = __fget(fd, 0);
725 v = FDPUT_FPUT;
726 }
727 if (!file)
728 return 0;
729
730 if (file->f_mode & FMODE_ATOMIC_POS) {
731 if (file_count(file) > 1) {
732 v |= FDPUT_POS_UNLOCK;
733 mutex_lock(&file->f_pos_lock);
734 }
735 }
736 return v | (unsigned long)file;
713} 737}
714 738
739/*
740 * We only lock f_pos if we have threads or if the file might be
741 * shared with another process. In both cases we'll have an elevated
742 * file count (done either by fdget() or by fork()).
743 */
744
715void set_close_on_exec(unsigned int fd, int flag) 745void set_close_on_exec(unsigned int fd, int flag)
716{ 746{
717 struct files_struct *files = current->files; 747 struct files_struct *files = current->files;
diff --git a/fs/file_table.c b/fs/file_table.c
index 5fff9030be34..5b24008ea4f6 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -135,6 +135,7 @@ struct file *get_empty_filp(void)
135 atomic_long_set(&f->f_count, 1); 135 atomic_long_set(&f->f_count, 1);
136 rwlock_init(&f->f_owner.lock); 136 rwlock_init(&f->f_owner.lock);
137 spin_lock_init(&f->f_lock); 137 spin_lock_init(&f->f_lock);
138 mutex_init(&f->f_pos_lock);
138 eventpoll_init_file(f); 139 eventpoll_init_file(f);
139 /* f->f_version: 0 */ 140 /* f->f_version: 0 */
140 return f; 141 return f;
diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
index 968ce411db53..32602c667b4a 100644
--- a/fs/hfsplus/catalog.c
+++ b/fs/hfsplus/catalog.c
@@ -103,6 +103,8 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
103 folder = &entry->folder; 103 folder = &entry->folder;
104 memset(folder, 0, sizeof(*folder)); 104 memset(folder, 0, sizeof(*folder));
105 folder->type = cpu_to_be16(HFSPLUS_FOLDER); 105 folder->type = cpu_to_be16(HFSPLUS_FOLDER);
106 if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags))
107 folder->flags |= cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT);
106 folder->id = cpu_to_be32(inode->i_ino); 108 folder->id = cpu_to_be32(inode->i_ino);
107 HFSPLUS_I(inode)->create_date = 109 HFSPLUS_I(inode)->create_date =
108 folder->create_date = 110 folder->create_date =
@@ -203,6 +205,36 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
203 return hfs_brec_find(fd, hfs_find_rec_by_key); 205 return hfs_brec_find(fd, hfs_find_rec_by_key);
204} 206}
205 207
208static void hfsplus_subfolders_inc(struct inode *dir)
209{
210 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb);
211
212 if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags)) {
213 /*
214 * Increment subfolder count. Note, the value is only meaningful
215 * for folders with HFSPLUS_HAS_FOLDER_COUNT flag set.
216 */
217 HFSPLUS_I(dir)->subfolders++;
218 }
219}
220
221static void hfsplus_subfolders_dec(struct inode *dir)
222{
223 struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb);
224
225 if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags)) {
226 /*
227 * Decrement subfolder count. Note, the value is only meaningful
228 * for folders with HFSPLUS_HAS_FOLDER_COUNT flag set.
229 *
230 * Check for zero. Some subfolders may have been created
231 * by an implementation ignorant of this counter.
232 */
233 if (HFSPLUS_I(dir)->subfolders)
234 HFSPLUS_I(dir)->subfolders--;
235 }
236}
237
206int hfsplus_create_cat(u32 cnid, struct inode *dir, 238int hfsplus_create_cat(u32 cnid, struct inode *dir,
207 struct qstr *str, struct inode *inode) 239 struct qstr *str, struct inode *inode)
208{ 240{
@@ -247,6 +279,8 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
247 goto err1; 279 goto err1;
248 280
249 dir->i_size++; 281 dir->i_size++;
282 if (S_ISDIR(inode->i_mode))
283 hfsplus_subfolders_inc(dir);
250 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; 284 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
251 hfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY); 285 hfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY);
252 286
@@ -336,6 +370,8 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str)
336 goto out; 370 goto out;
337 371
338 dir->i_size--; 372 dir->i_size--;
373 if (type == HFSPLUS_FOLDER)
374 hfsplus_subfolders_dec(dir);
339 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; 375 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
340 hfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY); 376 hfsplus_mark_inode_dirty(dir, HFSPLUS_I_CAT_DIRTY);
341 377
@@ -380,6 +416,7 @@ int hfsplus_rename_cat(u32 cnid,
380 416
381 hfs_bnode_read(src_fd.bnode, &entry, src_fd.entryoffset, 417 hfs_bnode_read(src_fd.bnode, &entry, src_fd.entryoffset,
382 src_fd.entrylength); 418 src_fd.entrylength);
419 type = be16_to_cpu(entry.type);
383 420
384 /* create new dir entry with the data from the old entry */ 421 /* create new dir entry with the data from the old entry */
385 hfsplus_cat_build_key(sb, dst_fd.search_key, dst_dir->i_ino, dst_name); 422 hfsplus_cat_build_key(sb, dst_fd.search_key, dst_dir->i_ino, dst_name);
@@ -394,6 +431,8 @@ int hfsplus_rename_cat(u32 cnid,
394 if (err) 431 if (err)
395 goto out; 432 goto out;
396 dst_dir->i_size++; 433 dst_dir->i_size++;
434 if (type == HFSPLUS_FOLDER)
435 hfsplus_subfolders_inc(dst_dir);
397 dst_dir->i_mtime = dst_dir->i_ctime = CURRENT_TIME_SEC; 436 dst_dir->i_mtime = dst_dir->i_ctime = CURRENT_TIME_SEC;
398 437
399 /* finally remove the old entry */ 438 /* finally remove the old entry */
@@ -405,6 +444,8 @@ int hfsplus_rename_cat(u32 cnid,
405 if (err) 444 if (err)
406 goto out; 445 goto out;
407 src_dir->i_size--; 446 src_dir->i_size--;
447 if (type == HFSPLUS_FOLDER)
448 hfsplus_subfolders_dec(src_dir);
408 src_dir->i_mtime = src_dir->i_ctime = CURRENT_TIME_SEC; 449 src_dir->i_mtime = src_dir->i_ctime = CURRENT_TIME_SEC;
409 450
410 /* remove old thread entry */ 451 /* remove old thread entry */
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 08846425b67f..62d571eb69ba 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -242,6 +242,7 @@ struct hfsplus_inode_info {
242 */ 242 */
243 sector_t fs_blocks; 243 sector_t fs_blocks;
244 u8 userflags; /* BSD user file flags */ 244 u8 userflags; /* BSD user file flags */
245 u32 subfolders; /* Subfolder count (HFSX only) */
245 struct list_head open_dir_list; 246 struct list_head open_dir_list;
246 loff_t phys_size; 247 loff_t phys_size;
247 248
diff --git a/fs/hfsplus/hfsplus_raw.h b/fs/hfsplus/hfsplus_raw.h
index 8ffb3a8ffe75..5a126828d85e 100644
--- a/fs/hfsplus/hfsplus_raw.h
+++ b/fs/hfsplus/hfsplus_raw.h
@@ -261,7 +261,7 @@ struct hfsplus_cat_folder {
261 struct DInfo user_info; 261 struct DInfo user_info;
262 struct DXInfo finder_info; 262 struct DXInfo finder_info;
263 __be32 text_encoding; 263 __be32 text_encoding;
264 u32 reserved; 264 __be32 subfolders; /* Subfolder count in HFSX. Reserved in HFS+. */
265} __packed; 265} __packed;
266 266
267/* HFS file info (stolen from hfs.h) */ 267/* HFS file info (stolen from hfs.h) */
@@ -301,11 +301,13 @@ struct hfsplus_cat_file {
301 struct hfsplus_fork_raw rsrc_fork; 301 struct hfsplus_fork_raw rsrc_fork;
302} __packed; 302} __packed;
303 303
304/* File attribute bits */ 304/* File and folder flag bits */
305#define HFSPLUS_FILE_LOCKED 0x0001 305#define HFSPLUS_FILE_LOCKED 0x0001
306#define HFSPLUS_FILE_THREAD_EXISTS 0x0002 306#define HFSPLUS_FILE_THREAD_EXISTS 0x0002
307#define HFSPLUS_XATTR_EXISTS 0x0004 307#define HFSPLUS_XATTR_EXISTS 0x0004
308#define HFSPLUS_ACL_EXISTS 0x0008 308#define HFSPLUS_ACL_EXISTS 0x0008
309#define HFSPLUS_HAS_FOLDER_COUNT 0x0010 /* Folder has subfolder count
310 * (HFSX only) */
309 311
310/* HFS+ catalog thread (part of a cat_entry) */ 312/* HFS+ catalog thread (part of a cat_entry) */
311struct hfsplus_cat_thread { 313struct hfsplus_cat_thread {
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index fa929f325f87..a4f45bd88a63 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -375,6 +375,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, umode_t mode)
375 hip->extent_state = 0; 375 hip->extent_state = 0;
376 hip->flags = 0; 376 hip->flags = 0;
377 hip->userflags = 0; 377 hip->userflags = 0;
378 hip->subfolders = 0;
378 memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec)); 379 memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec));
379 memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec)); 380 memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
380 hip->alloc_blocks = 0; 381 hip->alloc_blocks = 0;
@@ -494,6 +495,10 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
494 inode->i_ctime = hfsp_mt2ut(folder->attribute_mod_date); 495 inode->i_ctime = hfsp_mt2ut(folder->attribute_mod_date);
495 HFSPLUS_I(inode)->create_date = folder->create_date; 496 HFSPLUS_I(inode)->create_date = folder->create_date;
496 HFSPLUS_I(inode)->fs_blocks = 0; 497 HFSPLUS_I(inode)->fs_blocks = 0;
498 if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
499 HFSPLUS_I(inode)->subfolders =
500 be32_to_cpu(folder->subfolders);
501 }
497 inode->i_op = &hfsplus_dir_inode_operations; 502 inode->i_op = &hfsplus_dir_inode_operations;
498 inode->i_fop = &hfsplus_dir_operations; 503 inode->i_fop = &hfsplus_dir_operations;
499 } else if (type == HFSPLUS_FILE) { 504 } else if (type == HFSPLUS_FILE) {
@@ -566,6 +571,10 @@ int hfsplus_cat_write_inode(struct inode *inode)
566 folder->content_mod_date = hfsp_ut2mt(inode->i_mtime); 571 folder->content_mod_date = hfsp_ut2mt(inode->i_mtime);
567 folder->attribute_mod_date = hfsp_ut2mt(inode->i_ctime); 572 folder->attribute_mod_date = hfsp_ut2mt(inode->i_ctime);
568 folder->valence = cpu_to_be32(inode->i_size - 2); 573 folder->valence = cpu_to_be32(inode->i_size - 2);
574 if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
575 folder->subfolders =
576 cpu_to_be32(HFSPLUS_I(inode)->subfolders);
577 }
569 hfs_bnode_write(fd.bnode, &entry, fd.entryoffset, 578 hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
570 sizeof(struct hfsplus_cat_folder)); 579 sizeof(struct hfsplus_cat_folder));
571 } else if (HFSPLUS_IS_RSRC(inode)) { 580 } else if (HFSPLUS_IS_RSRC(inode)) {
diff --git a/fs/namei.c b/fs/namei.c
index 385f7817bfcc..2f730ef9b4b3 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1884,7 +1884,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
1884 1884
1885 nd->path = f.file->f_path; 1885 nd->path = f.file->f_path;
1886 if (flags & LOOKUP_RCU) { 1886 if (flags & LOOKUP_RCU) {
1887 if (f.need_put) 1887 if (f.flags & FDPUT_FPUT)
1888 *fp = f.file; 1888 *fp = f.file;
1889 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); 1889 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);
1890 rcu_read_lock(); 1890 rcu_read_lock();
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 8450262bcf2a..51632c40e896 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2393,8 +2393,8 @@ out_dio:
2393 2393
2394 if (((file->f_flags & O_DSYNC) && !direct_io) || IS_SYNC(inode) || 2394 if (((file->f_flags & O_DSYNC) && !direct_io) || IS_SYNC(inode) ||
2395 ((file->f_flags & O_DIRECT) && !direct_io)) { 2395 ((file->f_flags & O_DIRECT) && !direct_io)) {
2396 ret = filemap_fdatawrite_range(file->f_mapping, pos, 2396 ret = filemap_fdatawrite_range(file->f_mapping, *ppos,
2397 pos + count - 1); 2397 *ppos + count - 1);
2398 if (ret < 0) 2398 if (ret < 0)
2399 written = ret; 2399 written = ret;
2400 2400
@@ -2407,8 +2407,8 @@ out_dio:
2407 } 2407 }
2408 2408
2409 if (!ret) 2409 if (!ret)
2410 ret = filemap_fdatawait_range(file->f_mapping, pos, 2410 ret = filemap_fdatawait_range(file->f_mapping, *ppos,
2411 pos + count - 1); 2411 *ppos + count - 1);
2412 } 2412 }
2413 2413
2414 /* 2414 /*
diff --git a/fs/open.c b/fs/open.c
index 4b3e1edf2fe4..b9ed8b25c108 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -705,6 +705,10 @@ static int do_dentry_open(struct file *f,
705 return 0; 705 return 0;
706 } 706 }
707 707
708 /* POSIX.1-2008/SUSv4 Section XSI 2.9.7 */
709 if (S_ISREG(inode->i_mode))
710 f->f_mode |= FMODE_ATOMIC_POS;
711
708 f->f_op = fops_get(inode->i_fop); 712 f->f_op = fops_get(inode->i_fop);
709 if (unlikely(WARN_ON(!f->f_op))) { 713 if (unlikely(WARN_ON(!f->f_op))) {
710 error = -ENODEV; 714 error = -ENODEV;
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 51507065263b..b9760628e1fd 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1824,6 +1824,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
1824 if (rc) 1824 if (rc)
1825 goto out_mmput; 1825 goto out_mmput;
1826 1826
1827 rc = -ENOENT;
1827 down_read(&mm->mmap_sem); 1828 down_read(&mm->mmap_sem);
1828 vma = find_exact_vma(mm, vm_start, vm_end); 1829 vma = find_exact_vma(mm, vm_start, vm_end);
1829 if (vma && vma->vm_file) { 1830 if (vma && vma->vm_file) {
diff --git a/fs/read_write.c b/fs/read_write.c
index edc5746a902a..54e19b9392dc 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -264,10 +264,22 @@ loff_t vfs_llseek(struct file *file, loff_t offset, int whence)
264} 264}
265EXPORT_SYMBOL(vfs_llseek); 265EXPORT_SYMBOL(vfs_llseek);
266 266
267static inline struct fd fdget_pos(int fd)
268{
269 return __to_fd(__fdget_pos(fd));
270}
271
272static inline void fdput_pos(struct fd f)
273{
274 if (f.flags & FDPUT_POS_UNLOCK)
275 mutex_unlock(&f.file->f_pos_lock);
276 fdput(f);
277}
278
267SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence) 279SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence)
268{ 280{
269 off_t retval; 281 off_t retval;
270 struct fd f = fdget(fd); 282 struct fd f = fdget_pos(fd);
271 if (!f.file) 283 if (!f.file)
272 return -EBADF; 284 return -EBADF;
273 285
@@ -278,7 +290,7 @@ SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence)
278 if (res != (loff_t)retval) 290 if (res != (loff_t)retval)
279 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */ 291 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
280 } 292 }
281 fdput(f); 293 fdput_pos(f);
282 return retval; 294 return retval;
283} 295}
284 296
@@ -498,7 +510,7 @@ static inline void file_pos_write(struct file *file, loff_t pos)
498 510
499SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count) 511SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
500{ 512{
501 struct fd f = fdget(fd); 513 struct fd f = fdget_pos(fd);
502 ssize_t ret = -EBADF; 514 ssize_t ret = -EBADF;
503 515
504 if (f.file) { 516 if (f.file) {
@@ -506,7 +518,7 @@ SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
506 ret = vfs_read(f.file, buf, count, &pos); 518 ret = vfs_read(f.file, buf, count, &pos);
507 if (ret >= 0) 519 if (ret >= 0)
508 file_pos_write(f.file, pos); 520 file_pos_write(f.file, pos);
509 fdput(f); 521 fdput_pos(f);
510 } 522 }
511 return ret; 523 return ret;
512} 524}
@@ -514,7 +526,7 @@ SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
514SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf, 526SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
515 size_t, count) 527 size_t, count)
516{ 528{
517 struct fd f = fdget(fd); 529 struct fd f = fdget_pos(fd);
518 ssize_t ret = -EBADF; 530 ssize_t ret = -EBADF;
519 531
520 if (f.file) { 532 if (f.file) {
@@ -522,7 +534,7 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
522 ret = vfs_write(f.file, buf, count, &pos); 534 ret = vfs_write(f.file, buf, count, &pos);
523 if (ret >= 0) 535 if (ret >= 0)
524 file_pos_write(f.file, pos); 536 file_pos_write(f.file, pos);
525 fdput(f); 537 fdput_pos(f);
526 } 538 }
527 539
528 return ret; 540 return ret;
@@ -797,7 +809,7 @@ EXPORT_SYMBOL(vfs_writev);
797SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec, 809SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,
798 unsigned long, vlen) 810 unsigned long, vlen)
799{ 811{
800 struct fd f = fdget(fd); 812 struct fd f = fdget_pos(fd);
801 ssize_t ret = -EBADF; 813 ssize_t ret = -EBADF;
802 814
803 if (f.file) { 815 if (f.file) {
@@ -805,7 +817,7 @@ SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,
805 ret = vfs_readv(f.file, vec, vlen, &pos); 817 ret = vfs_readv(f.file, vec, vlen, &pos);
806 if (ret >= 0) 818 if (ret >= 0)
807 file_pos_write(f.file, pos); 819 file_pos_write(f.file, pos);
808 fdput(f); 820 fdput_pos(f);
809 } 821 }
810 822
811 if (ret > 0) 823 if (ret > 0)
@@ -817,7 +829,7 @@ SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,
817SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec, 829SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
818 unsigned long, vlen) 830 unsigned long, vlen)
819{ 831{
820 struct fd f = fdget(fd); 832 struct fd f = fdget_pos(fd);
821 ssize_t ret = -EBADF; 833 ssize_t ret = -EBADF;
822 834
823 if (f.file) { 835 if (f.file) {
@@ -825,7 +837,7 @@ SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
825 ret = vfs_writev(f.file, vec, vlen, &pos); 837 ret = vfs_writev(f.file, vec, vlen, &pos);
826 if (ret >= 0) 838 if (ret >= 0)
827 file_pos_write(f.file, pos); 839 file_pos_write(f.file, pos);
828 fdput(f); 840 fdput_pos(f);
829 } 841 }
830 842
831 if (ret > 0) 843 if (ret > 0)
@@ -968,7 +980,7 @@ COMPAT_SYSCALL_DEFINE3(readv, compat_ulong_t, fd,
968 const struct compat_iovec __user *,vec, 980 const struct compat_iovec __user *,vec,
969 compat_ulong_t, vlen) 981 compat_ulong_t, vlen)
970{ 982{
971 struct fd f = fdget(fd); 983 struct fd f = fdget_pos(fd);
972 ssize_t ret; 984 ssize_t ret;
973 loff_t pos; 985 loff_t pos;
974 986
@@ -978,7 +990,7 @@ COMPAT_SYSCALL_DEFINE3(readv, compat_ulong_t, fd,
978 ret = compat_readv(f.file, vec, vlen, &pos); 990 ret = compat_readv(f.file, vec, vlen, &pos);
979 if (ret >= 0) 991 if (ret >= 0)
980 f.file->f_pos = pos; 992 f.file->f_pos = pos;
981 fdput(f); 993 fdput_pos(f);
982 return ret; 994 return ret;
983} 995}
984 996
@@ -1035,7 +1047,7 @@ COMPAT_SYSCALL_DEFINE3(writev, compat_ulong_t, fd,
1035 const struct compat_iovec __user *, vec, 1047 const struct compat_iovec __user *, vec,
1036 compat_ulong_t, vlen) 1048 compat_ulong_t, vlen)
1037{ 1049{
1038 struct fd f = fdget(fd); 1050 struct fd f = fdget_pos(fd);
1039 ssize_t ret; 1051 ssize_t ret;
1040 loff_t pos; 1052 loff_t pos;
1041 1053
@@ -1045,7 +1057,7 @@ COMPAT_SYSCALL_DEFINE3(writev, compat_ulong_t, fd,
1045 ret = compat_writev(f.file, vec, vlen, &pos); 1057 ret = compat_writev(f.file, vec, vlen, &pos);
1046 if (ret >= 0) 1058 if (ret >= 0)
1047 f.file->f_pos = pos; 1059 f.file->f_pos = pos;
1048 fdput(f); 1060 fdput_pos(f);
1049 return ret; 1061 return ret;
1050} 1062}
1051 1063
diff --git a/include/dt-bindings/sound/tlv320aic31xx-micbias.h b/include/dt-bindings/sound/tlv320aic31xx-micbias.h
new file mode 100644
index 000000000000..f5cb772ab9c8
--- /dev/null
+++ b/include/dt-bindings/sound/tlv320aic31xx-micbias.h
@@ -0,0 +1,8 @@
1#ifndef __DT_TLV320AIC31XX_MICBIAS_H
2#define __DT_TLV320AIC31XX_MICBIAS_H
3
4#define MICBIAS_2_0V 1
5#define MICBIAS_2_5V 2
6#define MICBIAS_AVDDV 3
7
8#endif /* __DT_TLV320AIC31XX_MICBIAS_H */
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
index be85127bfed3..f27000f55a83 100644
--- a/include/kvm/arm_vgic.h
+++ b/include/kvm/arm_vgic.h
@@ -171,6 +171,11 @@ static inline int kvm_vgic_set_addr(struct kvm *kvm, unsigned long type, u64 add
171 return 0; 171 return 0;
172} 172}
173 173
174static inline int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write)
175{
176 return -ENXIO;
177}
178
174static inline int kvm_vgic_init(struct kvm *kvm) 179static inline int kvm_vgic_init(struct kvm *kvm)
175{ 180{
176 return 0; 181 return 0;
diff --git a/include/linux/atmel-ssc.h b/include/linux/atmel-ssc.h
index 66a0e5384edd..571a12ebb018 100644
--- a/include/linux/atmel-ssc.h
+++ b/include/linux/atmel-ssc.h
@@ -18,6 +18,7 @@ struct ssc_device {
18 struct clk *clk; 18 struct clk *clk;
19 int user; 19 int user;
20 int irq; 20 int irq;
21 bool clk_from_rk_pin;
21}; 22};
22 23
23struct ssc_device * __must_check ssc_request(unsigned int ssc_num); 24struct ssc_device * __must_check ssc_request(unsigned int ssc_num);
diff --git a/include/linux/audit.h b/include/linux/audit.h
index aa865a9a4c4f..ec1464df4c60 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -43,6 +43,7 @@ struct mq_attr;
43struct mqstat; 43struct mqstat;
44struct audit_watch; 44struct audit_watch;
45struct audit_tree; 45struct audit_tree;
46struct sk_buff;
46 47
47struct audit_krule { 48struct audit_krule {
48 int vers_ops; 49 int vers_ops;
@@ -463,7 +464,7 @@ extern int audit_filter_user(int type);
463extern int audit_filter_type(int type); 464extern int audit_filter_type(int type);
464extern int audit_rule_change(int type, __u32 portid, int seq, 465extern int audit_rule_change(int type, __u32 portid, int seq,
465 void *data, size_t datasz); 466 void *data, size_t datasz);
466extern int audit_list_rules_send(__u32 portid, int seq); 467extern int audit_list_rules_send(struct sk_buff *request_skb, int seq);
467 468
468extern u32 audit_enabled; 469extern u32 audit_enabled;
469#else /* CONFIG_AUDIT */ 470#else /* CONFIG_AUDIT */
diff --git a/include/linux/file.h b/include/linux/file.h
index cbacf4faf447..4d69123377a2 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -28,33 +28,36 @@ static inline void fput_light(struct file *file, int fput_needed)
28 28
29struct fd { 29struct fd {
30 struct file *file; 30 struct file *file;
31 int need_put; 31 unsigned int flags;
32}; 32};
33#define FDPUT_FPUT 1
34#define FDPUT_POS_UNLOCK 2
33 35
34static inline void fdput(struct fd fd) 36static inline void fdput(struct fd fd)
35{ 37{
36 if (fd.need_put) 38 if (fd.flags & FDPUT_FPUT)
37 fput(fd.file); 39 fput(fd.file);
38} 40}
39 41
40extern struct file *fget(unsigned int fd); 42extern struct file *fget(unsigned int fd);
41extern struct file *fget_light(unsigned int fd, int *fput_needed); 43extern struct file *fget_raw(unsigned int fd);
44extern unsigned long __fdget(unsigned int fd);
45extern unsigned long __fdget_raw(unsigned int fd);
46extern unsigned long __fdget_pos(unsigned int fd);
42 47
43static inline struct fd fdget(unsigned int fd) 48static inline struct fd __to_fd(unsigned long v)
44{ 49{
45 int b; 50 return (struct fd){(struct file *)(v & ~3),v & 3};
46 struct file *f = fget_light(fd, &b);
47 return (struct fd){f,b};
48} 51}
49 52
50extern struct file *fget_raw(unsigned int fd); 53static inline struct fd fdget(unsigned int fd)
51extern struct file *fget_raw_light(unsigned int fd, int *fput_needed); 54{
55 return __to_fd(__fdget(fd));
56}
52 57
53static inline struct fd fdget_raw(unsigned int fd) 58static inline struct fd fdget_raw(unsigned int fd)
54{ 59{
55 int b; 60 return __to_fd(__fdget_raw(fd));
56 struct file *f = fget_raw_light(fd, &b);
57 return (struct fd){f,b};
58} 61}
59 62
60extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); 63extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 60829565e552..23b2a35d712e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -123,6 +123,9 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
123/* File is opened with O_PATH; almost nothing can be done with it */ 123/* File is opened with O_PATH; almost nothing can be done with it */
124#define FMODE_PATH ((__force fmode_t)0x4000) 124#define FMODE_PATH ((__force fmode_t)0x4000)
125 125
126/* File needs atomic accesses to f_pos */
127#define FMODE_ATOMIC_POS ((__force fmode_t)0x8000)
128
126/* File was opened by fanotify and shouldn't generate fanotify events */ 129/* File was opened by fanotify and shouldn't generate fanotify events */
127#define FMODE_NONOTIFY ((__force fmode_t)0x1000000) 130#define FMODE_NONOTIFY ((__force fmode_t)0x1000000)
128 131
@@ -780,13 +783,14 @@ struct file {
780 const struct file_operations *f_op; 783 const struct file_operations *f_op;
781 784
782 /* 785 /*
783 * Protects f_ep_links, f_flags, f_pos vs i_size in lseek SEEK_CUR. 786 * Protects f_ep_links, f_flags.
784 * Must not be taken from IRQ context. 787 * Must not be taken from IRQ context.
785 */ 788 */
786 spinlock_t f_lock; 789 spinlock_t f_lock;
787 atomic_long_t f_count; 790 atomic_long_t f_count;
788 unsigned int f_flags; 791 unsigned int f_flags;
789 fmode_t f_mode; 792 fmode_t f_mode;
793 struct mutex f_pos_lock;
790 loff_t f_pos; 794 loff_t f_pos;
791 struct fown_struct f_owner; 795 struct fown_struct f_owner;
792 const struct cred *f_cred; 796 const struct cred *f_cred;
@@ -808,7 +812,7 @@ struct file {
808#ifdef CONFIG_DEBUG_WRITECOUNT 812#ifdef CONFIG_DEBUG_WRITECOUNT
809 unsigned long f_mnt_write_state; 813 unsigned long f_mnt_write_state;
810#endif 814#endif
811}; 815} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
812 816
813struct file_handle { 817struct file_handle {
814 __u32 handle_bytes; 818 __u32 handle_bytes;
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 0437439bc047..39b81dc7d01a 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -123,6 +123,10 @@ struct vm_area_struct;
123 __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN | \ 123 __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN | \
124 __GFP_NO_KSWAPD) 124 __GFP_NO_KSWAPD)
125 125
126/*
127 * GFP_THISNODE does not perform any reclaim, you most likely want to
128 * use __GFP_THISNODE to allocate from a given node without fallback!
129 */
126#ifdef CONFIG_NUMA 130#ifdef CONFIG_NUMA
127#define GFP_THISNODE (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY) 131#define GFP_THISNODE (__GFP_THISNODE | __GFP_NOWARN | __GFP_NORETRY)
128#else 132#else
diff --git a/include/linux/mfd/arizona/registers.h b/include/linux/mfd/arizona/registers.h
index fdf3aa376eb2..3ddaa634b19d 100644
--- a/include/linux/mfd/arizona/registers.h
+++ b/include/linux/mfd/arizona/registers.h
@@ -1702,9 +1702,9 @@
1702/* 1702/*
1703 * R373 (0x175) - FLL1 Control 5 1703 * R373 (0x175) - FLL1 Control 5
1704 */ 1704 */
1705#define ARIZONA_FLL1_FRATIO_MASK 0x0700 /* FLL1_FRATIO - [10:8] */ 1705#define ARIZONA_FLL1_FRATIO_MASK 0x0F00 /* FLL1_FRATIO - [11:8] */
1706#define ARIZONA_FLL1_FRATIO_SHIFT 8 /* FLL1_FRATIO - [10:8] */ 1706#define ARIZONA_FLL1_FRATIO_SHIFT 8 /* FLL1_FRATIO - [11:8] */
1707#define ARIZONA_FLL1_FRATIO_WIDTH 3 /* FLL1_FRATIO - [10:8] */ 1707#define ARIZONA_FLL1_FRATIO_WIDTH 4 /* FLL1_FRATIO - [11:8] */
1708#define ARIZONA_FLL1_OUTDIV_MASK 0x000E /* FLL1_OUTDIV - [3:1] */ 1708#define ARIZONA_FLL1_OUTDIV_MASK 0x000E /* FLL1_OUTDIV - [3:1] */
1709#define ARIZONA_FLL1_OUTDIV_SHIFT 1 /* FLL1_OUTDIV - [3:1] */ 1709#define ARIZONA_FLL1_OUTDIV_SHIFT 1 /* FLL1_OUTDIV - [3:1] */
1710#define ARIZONA_FLL1_OUTDIV_WIDTH 3 /* FLL1_OUTDIV - [3:1] */ 1710#define ARIZONA_FLL1_OUTDIV_WIDTH 3 /* FLL1_OUTDIV - [3:1] */
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 5f2052c83154..9b61b9bf81ac 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -590,10 +590,10 @@ static inline bool zone_is_empty(struct zone *zone)
590 590
591/* 591/*
592 * The NUMA zonelists are doubled because we need zonelists that restrict the 592 * The NUMA zonelists are doubled because we need zonelists that restrict the
593 * allocations to a single node for GFP_THISNODE. 593 * allocations to a single node for __GFP_THISNODE.
594 * 594 *
595 * [0] : Zonelist with fallback 595 * [0] : Zonelist with fallback
596 * [1] : No fallback (GFP_THISNODE) 596 * [1] : No fallback (__GFP_THISNODE)
597 */ 597 */
598#define MAX_ZONELISTS 2 598#define MAX_ZONELISTS 2
599 599
diff --git a/include/linux/platform_data/adau1977.h b/include/linux/platform_data/adau1977.h
new file mode 100644
index 000000000000..bed11d908f92
--- /dev/null
+++ b/include/linux/platform_data/adau1977.h
@@ -0,0 +1,45 @@
1/*
2 * ADAU1977/ADAU1978/ADAU1979 driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
6 *
7 * Licensed under the GPL-2.
8 */
9
10#ifndef __LINUX_PLATFORM_DATA_ADAU1977_H__
11#define __LINUX_PLATFORM_DATA_ADAU1977_H__
12
13/**
14 * enum adau1977_micbias - ADAU1977 MICBIAS pin voltage setting
15 * @ADAU1977_MICBIAS_5V0: MICBIAS is set to 5.0 V
16 * @ADAU1977_MICBIAS_5V5: MICBIAS is set to 5.5 V
17 * @ADAU1977_MICBIAS_6V0: MICBIAS is set to 6.0 V
18 * @ADAU1977_MICBIAS_6V5: MICBIAS is set to 6.5 V
19 * @ADAU1977_MICBIAS_7V0: MICBIAS is set to 7.0 V
20 * @ADAU1977_MICBIAS_7V5: MICBIAS is set to 7.5 V
21 * @ADAU1977_MICBIAS_8V0: MICBIAS is set to 8.0 V
22 * @ADAU1977_MICBIAS_8V5: MICBIAS is set to 8.5 V
23 * @ADAU1977_MICBIAS_9V0: MICBIAS is set to 9.0 V
24 */
25enum adau1977_micbias {
26 ADAU1977_MICBIAS_5V0 = 0x0,
27 ADAU1977_MICBIAS_5V5 = 0x1,
28 ADAU1977_MICBIAS_6V0 = 0x2,
29 ADAU1977_MICBIAS_6V5 = 0x3,
30 ADAU1977_MICBIAS_7V0 = 0x4,
31 ADAU1977_MICBIAS_7V5 = 0x5,
32 ADAU1977_MICBIAS_8V0 = 0x6,
33 ADAU1977_MICBIAS_8V5 = 0x7,
34 ADAU1977_MICBIAS_9V0 = 0x8,
35};
36
37/**
38 * struct adau1977_platform_data - Platform configuration data for the ADAU1977
39 * @micbias: Specifies the voltage for the MICBIAS pin
40 */
41struct adau1977_platform_data {
42 enum adau1977_micbias micbias;
43};
44
45#endif
diff --git a/include/linux/platform_data/asoc-s3c.h b/include/linux/platform_data/asoc-s3c.h
index 9efc04dd255a..709c6f7e2f8c 100644
--- a/include/linux/platform_data/asoc-s3c.h
+++ b/include/linux/platform_data/asoc-s3c.h
@@ -1,5 +1,4 @@
1/* arch/arm/plat-samsung/include/plat/audio.h 1/*
2 *
3 * Copyright (c) 2009 Samsung Electronics Co. Ltd 2 * Copyright (c) 2009 Samsung Electronics Co. Ltd
4 * Author: Jaswinder Singh <jassi.brar@samsung.com> 3 * Author: Jaswinder Singh <jassi.brar@samsung.com>
5 * 4 *
diff --git a/include/linux/platform_data/asoc-s3c24xx_simtec.h b/include/linux/platform_data/asoc-s3c24xx_simtec.h
index 376af5286a3e..d220e54123aa 100644
--- a/include/linux/platform_data/asoc-s3c24xx_simtec.h
+++ b/include/linux/platform_data/asoc-s3c24xx_simtec.h
@@ -1,5 +1,4 @@
1/* arch/arm/plat-samsung/include/plat/audio-simtec.h 1/*
2 *
3 * Copyright 2008 Simtec Electronics 2 * Copyright 2008 Simtec Electronics
4 * http://armlinux.simtec.co.uk/ 3 * http://armlinux.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk> 4 * Ben Dooks <ben@simtec.co.uk>
diff --git a/include/linux/platform_data/davinci_asp.h b/include/linux/platform_data/davinci_asp.h
index 5245992b0367..85ad68f9206a 100644
--- a/include/linux/platform_data/davinci_asp.h
+++ b/include/linux/platform_data/davinci_asp.h
@@ -18,7 +18,7 @@
18 18
19#include <linux/genalloc.h> 19#include <linux/genalloc.h>
20 20
21struct snd_platform_data { 21struct davinci_mcasp_pdata {
22 u32 tx_dma_offset; 22 u32 tx_dma_offset;
23 u32 rx_dma_offset; 23 u32 rx_dma_offset;
24 int asp_chan_q; /* event queue number for ASP channel */ 24 int asp_chan_q; /* event queue number for ASP channel */
@@ -87,6 +87,8 @@ struct snd_platform_data {
87 int tx_dma_channel; 87 int tx_dma_channel;
88 int rx_dma_channel; 88 int rx_dma_channel;
89}; 89};
90/* TODO: Fix arch/arm/mach-davinci/ users and remove this define */
91#define snd_platform_data davinci_mcasp_pdata
90 92
91enum { 93enum {
92 MCASP_VERSION_1 = 0, /* DM646x */ 94 MCASP_VERSION_1 = 0, /* DM646x */
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 4149f1a9b003..3e1a2e4a92ad 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -423,6 +423,8 @@ bool regmap_check_range_table(struct regmap *map, unsigned int reg,
423 423
424int regmap_register_patch(struct regmap *map, const struct reg_default *regs, 424int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
425 int num_regs); 425 int num_regs);
426int regmap_parse_val(struct regmap *map, const void *buf,
427 unsigned int *val);
426 428
427static inline bool regmap_reg_in_range(unsigned int reg, 429static inline bool regmap_reg_in_range(unsigned int reg,
428 const struct regmap_range *range) 430 const struct regmap_range *range)
@@ -695,6 +697,13 @@ static inline int regmap_register_patch(struct regmap *map,
695 return -EINVAL; 697 return -EINVAL;
696} 698}
697 699
700static inline int regmap_parse_val(struct regmap *map, const void *buf,
701 unsigned int *val)
702{
703 WARN_ONCE(1, "regmap API is disabled");
704 return -EINVAL;
705}
706
698static inline struct regmap *dev_get_regmap(struct device *dev, 707static inline struct regmap *dev_get_regmap(struct device *dev,
699 const char *name) 708 const char *name)
700{ 709{
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 9260abdd67df..b5b2df60299e 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -410,7 +410,7 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
410 * 410 *
411 * %GFP_NOWAIT - Allocation will not sleep. 411 * %GFP_NOWAIT - Allocation will not sleep.
412 * 412 *
413 * %GFP_THISNODE - Allocate node-local memory only. 413 * %__GFP_THISNODE - Allocate node-local memory only.
414 * 414 *
415 * %GFP_DMA - Allocation suitable for DMA. 415 * %GFP_DMA - Allocation suitable for DMA.
416 * Should only be used for kmalloc() caches. Otherwise, use a 416 * Should only be used for kmalloc() caches. Otherwise, use a
diff --git a/include/net/sock.h b/include/net/sock.h
index 5c3f7c3624aa..b9586a137cad 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1488,6 +1488,11 @@ static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb)
1488 */ 1488 */
1489#define sock_owned_by_user(sk) ((sk)->sk_lock.owned) 1489#define sock_owned_by_user(sk) ((sk)->sk_lock.owned)
1490 1490
1491static inline void sock_release_ownership(struct sock *sk)
1492{
1493 sk->sk_lock.owned = 0;
1494}
1495
1491/* 1496/*
1492 * Macro so as to not evaluate some arguments when 1497 * Macro so as to not evaluate some arguments when
1493 * lockdep is not enabled. 1498 * lockdep is not enabled.
@@ -2186,7 +2191,6 @@ static inline void sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk,
2186{ 2191{
2187#define FLAGS_TS_OR_DROPS ((1UL << SOCK_RXQ_OVFL) | \ 2192#define FLAGS_TS_OR_DROPS ((1UL << SOCK_RXQ_OVFL) | \
2188 (1UL << SOCK_RCVTSTAMP) | \ 2193 (1UL << SOCK_RCVTSTAMP) | \
2189 (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE) | \
2190 (1UL << SOCK_TIMESTAMPING_SOFTWARE) | \ 2194 (1UL << SOCK_TIMESTAMPING_SOFTWARE) | \
2191 (1UL << SOCK_TIMESTAMPING_RAW_HARDWARE) | \ 2195 (1UL << SOCK_TIMESTAMPING_RAW_HARDWARE) | \
2192 (1UL << SOCK_TIMESTAMPING_SYS_HARDWARE)) 2196 (1UL << SOCK_TIMESTAMPING_SYS_HARDWARE))
diff --git a/include/sound/core.h b/include/sound/core.h
index 2a14f1f02d4f..d3f5f818e0b9 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -22,6 +22,7 @@
22 * 22 *
23 */ 23 */
24 24
25#include <linux/device.h>
25#include <linux/sched.h> /* wake_up() */ 26#include <linux/sched.h> /* wake_up() */
26#include <linux/mutex.h> /* struct mutex */ 27#include <linux/mutex.h> /* struct mutex */
27#include <linux/rwsem.h> /* struct rw_semaphore */ 28#include <linux/rwsem.h> /* struct rw_semaphore */
@@ -41,39 +42,33 @@
41/* forward declarations */ 42/* forward declarations */
42struct pci_dev; 43struct pci_dev;
43struct module; 44struct module;
44struct device; 45struct completion;
45struct device_attribute;
46 46
47/* device allocation stuff */ 47/* device allocation stuff */
48 48
49#define SNDRV_DEV_TYPE_RANGE_SIZE 0x1000 49/* type of the object used in snd_device_*()
50 50 * this also defines the calling order
51typedef int __bitwise snd_device_type_t; 51 */
52#define SNDRV_DEV_TOPLEVEL ((__force snd_device_type_t) 0) 52enum snd_device_type {
53#define SNDRV_DEV_CONTROL ((__force snd_device_type_t) 1) 53 SNDRV_DEV_LOWLEVEL,
54#define SNDRV_DEV_LOWLEVEL_PRE ((__force snd_device_type_t) 2) 54 SNDRV_DEV_CONTROL,
55#define SNDRV_DEV_LOWLEVEL_NORMAL ((__force snd_device_type_t) 0x1000) 55 SNDRV_DEV_INFO,
56#define SNDRV_DEV_PCM ((__force snd_device_type_t) 0x1001) 56 SNDRV_DEV_BUS,
57#define SNDRV_DEV_RAWMIDI ((__force snd_device_type_t) 0x1002) 57 SNDRV_DEV_CODEC,
58#define SNDRV_DEV_TIMER ((__force snd_device_type_t) 0x1003) 58 SNDRV_DEV_PCM,
59#define SNDRV_DEV_SEQUENCER ((__force snd_device_type_t) 0x1004) 59 SNDRV_DEV_COMPRESS,
60#define SNDRV_DEV_HWDEP ((__force snd_device_type_t) 0x1005) 60 SNDRV_DEV_RAWMIDI,
61#define SNDRV_DEV_INFO ((__force snd_device_type_t) 0x1006) 61 SNDRV_DEV_TIMER,
62#define SNDRV_DEV_BUS ((__force snd_device_type_t) 0x1007) 62 SNDRV_DEV_SEQUENCER,
63#define SNDRV_DEV_CODEC ((__force snd_device_type_t) 0x1008) 63 SNDRV_DEV_HWDEP,
64#define SNDRV_DEV_JACK ((__force snd_device_type_t) 0x1009) 64 SNDRV_DEV_JACK,
65#define SNDRV_DEV_COMPRESS ((__force snd_device_type_t) 0x100A) 65};
66#define SNDRV_DEV_LOWLEVEL ((__force snd_device_type_t) 0x2000) 66
67 67enum snd_device_state {
68typedef int __bitwise snd_device_state_t; 68 SNDRV_DEV_BUILD,
69#define SNDRV_DEV_BUILD ((__force snd_device_state_t) 0) 69 SNDRV_DEV_REGISTERED,
70#define SNDRV_DEV_REGISTERED ((__force snd_device_state_t) 1) 70 SNDRV_DEV_DISCONNECTED,
71#define SNDRV_DEV_DISCONNECTED ((__force snd_device_state_t) 2) 71};
72
73typedef int __bitwise snd_device_cmd_t;
74#define SNDRV_DEV_CMD_PRE ((__force snd_device_cmd_t) 0)
75#define SNDRV_DEV_CMD_NORMAL ((__force snd_device_cmd_t) 1)
76#define SNDRV_DEV_CMD_POST ((__force snd_device_cmd_t) 2)
77 72
78struct snd_device; 73struct snd_device;
79 74
@@ -86,8 +81,8 @@ struct snd_device_ops {
86struct snd_device { 81struct snd_device {
87 struct list_head list; /* list of registered devices */ 82 struct list_head list; /* list of registered devices */
88 struct snd_card *card; /* card which holds this device */ 83 struct snd_card *card; /* card which holds this device */
89 snd_device_state_t state; /* state of the device */ 84 enum snd_device_state state; /* state of the device */
90 snd_device_type_t type; /* device type */ 85 enum snd_device_type type; /* device type */
91 void *device_data; /* device structure */ 86 void *device_data; /* device structure */
92 struct snd_device_ops *ops; /* operations */ 87 struct snd_device_ops *ops; /* operations */
93}; 88};
@@ -131,11 +126,10 @@ struct snd_card {
131 state */ 126 state */
132 spinlock_t files_lock; /* lock the files for this card */ 127 spinlock_t files_lock; /* lock the files for this card */
133 int shutdown; /* this card is going down */ 128 int shutdown; /* this card is going down */
134 int free_on_last_close; /* free in context of file_release */ 129 struct completion *release_completion;
135 wait_queue_head_t shutdown_sleep;
136 atomic_t refcount; /* refcount for disconnection */
137 struct device *dev; /* device assigned to this card */ 130 struct device *dev; /* device assigned to this card */
138 struct device *card_dev; /* cardX object for sysfs */ 131 struct device card_dev; /* cardX object for sysfs */
132 bool registered; /* card_dev is registered? */
139 133
140#ifdef CONFIG_PM 134#ifdef CONFIG_PM
141 unsigned int power_state; /* power state */ 135 unsigned int power_state; /* power state */
@@ -149,6 +143,8 @@ struct snd_card {
149#endif 143#endif
150}; 144};
151 145
146#define dev_to_snd_card(p) container_of(p, struct snd_card, card_dev)
147
152#ifdef CONFIG_PM 148#ifdef CONFIG_PM
153static inline void snd_power_lock(struct snd_card *card) 149static inline void snd_power_lock(struct snd_card *card)
154{ 150{
@@ -197,7 +193,7 @@ struct snd_minor {
197/* return a device pointer linked to each sound device as a parent */ 193/* return a device pointer linked to each sound device as a parent */
198static inline struct device *snd_card_get_device_link(struct snd_card *card) 194static inline struct device *snd_card_get_device_link(struct snd_card *card)
199{ 195{
200 return card ? card->card_dev : NULL; 196 return card ? &card->card_dev : NULL;
201} 197}
202 198
203/* sound.c */ 199/* sound.c */
@@ -244,13 +240,11 @@ static inline int snd_register_device(int type, struct snd_card *card, int dev,
244 240
245int snd_unregister_device(int type, struct snd_card *card, int dev); 241int snd_unregister_device(int type, struct snd_card *card, int dev);
246void *snd_lookup_minor_data(unsigned int minor, int type); 242void *snd_lookup_minor_data(unsigned int minor, int type);
247int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev, 243struct device *snd_get_device(int type, struct snd_card *card, int dev);
248 struct device_attribute *attr);
249 244
250#ifdef CONFIG_SND_OSSEMUL 245#ifdef CONFIG_SND_OSSEMUL
251int snd_register_oss_device(int type, struct snd_card *card, int dev, 246int snd_register_oss_device(int type, struct snd_card *card, int dev,
252 const struct file_operations *f_ops, void *private_data, 247 const struct file_operations *f_ops, void *private_data);
253 const char *name);
254int snd_unregister_oss_device(int type, struct snd_card *card, int dev); 248int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
255void *snd_lookup_oss_minor_data(unsigned int minor, int type); 249void *snd_lookup_oss_minor_data(unsigned int minor, int type);
256#endif 250#endif
@@ -284,9 +278,16 @@ int snd_card_locked(int card);
284extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd); 278extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
285#endif 279#endif
286 280
287int snd_card_create(int idx, const char *id, 281int snd_card_new(struct device *parent, int idx, const char *xid,
288 struct module *module, int extra_size, 282 struct module *module, int extra_size,
289 struct snd_card **card_ret); 283 struct snd_card **card_ret);
284
285static inline int __deprecated
286snd_card_create(int idx, const char *id, struct module *module, int extra_size,
287 struct snd_card **ret)
288{
289 return snd_card_new(NULL, idx, id, module, extra_size, ret);
290}
290 291
291int snd_card_disconnect(struct snd_card *card); 292int snd_card_disconnect(struct snd_card *card);
292int snd_card_free(struct snd_card *card); 293int snd_card_free(struct snd_card *card);
@@ -298,20 +299,19 @@ int snd_card_info_done(void);
298int snd_component_add(struct snd_card *card, const char *component); 299int snd_component_add(struct snd_card *card, const char *component);
299int snd_card_file_add(struct snd_card *card, struct file *file); 300int snd_card_file_add(struct snd_card *card, struct file *file);
300int snd_card_file_remove(struct snd_card *card, struct file *file); 301int snd_card_file_remove(struct snd_card *card, struct file *file);
301void snd_card_unref(struct snd_card *card); 302#define snd_card_unref(card) put_device(&(card)->card_dev)
302 303
303#define snd_card_set_dev(card, devptr) ((card)->dev = (devptr)) 304#define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
304 305
305/* device.c */ 306/* device.c */
306 307
307int snd_device_new(struct snd_card *card, snd_device_type_t type, 308int snd_device_new(struct snd_card *card, enum snd_device_type type,
308 void *device_data, struct snd_device_ops *ops); 309 void *device_data, struct snd_device_ops *ops);
309int snd_device_register(struct snd_card *card, void *device_data); 310int snd_device_register(struct snd_card *card, void *device_data);
310int snd_device_register_all(struct snd_card *card); 311int snd_device_register_all(struct snd_card *card);
311int snd_device_disconnect(struct snd_card *card, void *device_data);
312int snd_device_disconnect_all(struct snd_card *card); 312int snd_device_disconnect_all(struct snd_card *card);
313int snd_device_free(struct snd_card *card, void *device_data); 313void snd_device_free(struct snd_card *card, void *device_data);
314int snd_device_free_all(struct snd_card *card, snd_device_cmd_t cmd); 314void snd_device_free_all(struct snd_card *card);
315 315
316/* isadma.c */ 316/* isadma.c */
317 317
@@ -433,7 +433,6 @@ static inline void snd_printdd(const char *format, ...) {}
433#define gameport_get_port_data(gp) (gp)->port_data 433#define gameport_get_port_data(gp) (gp)->port_data
434#endif 434#endif
435 435
436#ifdef CONFIG_PCI
437/* PCI quirk list helper */ 436/* PCI quirk list helper */
438struct snd_pci_quirk { 437struct snd_pci_quirk {
439 unsigned short subvendor; /* PCI subvendor ID */ 438 unsigned short subvendor; /* PCI subvendor ID */
@@ -469,12 +468,26 @@ struct snd_pci_quirk {
469#define snd_pci_quirk_name(q) "" 468#define snd_pci_quirk_name(q) ""
470#endif 469#endif
471 470
471#ifdef CONFIG_PCI
472const struct snd_pci_quirk * 472const struct snd_pci_quirk *
473snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list); 473snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
474 474
475const struct snd_pci_quirk * 475const struct snd_pci_quirk *
476snd_pci_quirk_lookup_id(u16 vendor, u16 device, 476snd_pci_quirk_lookup_id(u16 vendor, u16 device,
477 const struct snd_pci_quirk *list); 477 const struct snd_pci_quirk *list);
478#else
479static inline const struct snd_pci_quirk *
480snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
481{
482 return NULL;
483}
484
485static inline const struct snd_pci_quirk *
486snd_pci_quirk_lookup_id(u16 vendor, u16 device,
487 const struct snd_pci_quirk *list)
488{
489 return NULL;
490}
478#endif 491#endif
479 492
480#endif /* __SOUND_CORE_H */ 493#endif /* __SOUND_CORE_H */
diff --git a/include/sound/emu10k1.h b/include/sound/emu10k1.h
index dfb42ca6d043..c46908c1bb3f 100644
--- a/include/sound/emu10k1.h
+++ b/include/sound/emu10k1.h
@@ -436,8 +436,6 @@
436#define CCCA_CURRADDR_MASK 0x00ffffff /* Current address of the selected channel */ 436#define CCCA_CURRADDR_MASK 0x00ffffff /* Current address of the selected channel */
437#define CCCA_CURRADDR 0x18000008 437#define CCCA_CURRADDR 0x18000008
438 438
439/* undefine CCR to avoid conflict with the definition for SH */
440#undef CCR
441#define CCR 0x09 /* Cache control register */ 439#define CCR 0x09 /* Cache control register */
442#define CCR_CACHEINVALIDSIZE 0x07190009 440#define CCR_CACHEINVALIDSIZE 0x07190009
443#define CCR_CACHEINVALIDSIZE_MASK 0xfe000000 /* Number of invalid samples cache for this channel */ 441#define CCR_CACHEINVALIDSIZE_MASK 0xfe000000 /* Number of invalid samples cache for this channel */
diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
index 8c05e47a4090..ae04a3ec9c77 100644
--- a/include/sound/hwdep.h
+++ b/include/sound/hwdep.h
@@ -60,7 +60,6 @@ struct snd_hwdep {
60 int iface; 60 int iface;
61 61
62#ifdef CONFIG_SND_OSSEMUL 62#ifdef CONFIG_SND_OSSEMUL
63 char oss_dev[32];
64 int oss_type; 63 int oss_type;
65 int ossreg; 64 int ossreg;
66#endif 65#endif
@@ -69,6 +68,8 @@ struct snd_hwdep {
69 wait_queue_head_t open_wait; 68 wait_queue_head_t open_wait;
70 void *private_data; 69 void *private_data;
71 void (*private_free) (struct snd_hwdep *hwdep); 70 void (*private_free) (struct snd_hwdep *hwdep);
71 struct device *dev;
72 const struct attribute_group **groups;
72 73
73 struct mutex open_mutex; 74 struct mutex open_mutex;
74 int used; /* reference counter */ 75 int used; /* reference counter */
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 4883499ab38b..b4d6697085fe 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -1141,4 +1141,12 @@ static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
1141 return 1ULL << (__force int) pcm_format; 1141 return 1ULL << (__force int) pcm_format;
1142} 1142}
1143 1143
1144/* printk helpers */
1145#define pcm_err(pcm, fmt, args...) \
1146 dev_err((pcm)->card->dev, fmt, ##args)
1147#define pcm_warn(pcm, fmt, args...) \
1148 dev_warn((pcm)->card->dev, fmt, ##args)
1149#define pcm_dbg(pcm, fmt, args...) \
1150 dev_dbg((pcm)->card->dev, fmt, ##args)
1151
1144#endif /* __SOUND_PCM_H */ 1152#endif /* __SOUND_PCM_H */
diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h
index adf0885153f3..311dafe6cc4b 100644
--- a/include/sound/rawmidi.h
+++ b/include/sound/rawmidi.h
@@ -157,10 +157,8 @@ void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
157 157
158/* callbacks */ 158/* callbacks */
159 159
160void snd_rawmidi_receive_reset(struct snd_rawmidi_substream *substream);
161int snd_rawmidi_receive(struct snd_rawmidi_substream *substream, 160int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
162 const unsigned char *buffer, int count); 161 const unsigned char *buffer, int count);
163void snd_rawmidi_transmit_reset(struct snd_rawmidi_substream *substream);
164int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream); 162int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream);
165int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream, 163int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
166 unsigned char *buffer, int count); 164 unsigned char *buffer, int count);
diff --git a/include/sound/rcar_snd.h b/include/sound/rcar_snd.h
index 6add6ccc811e..34a3c02a4576 100644
--- a/include/sound/rcar_snd.h
+++ b/include/sound/rcar_snd.h
@@ -34,17 +34,17 @@
34 * B : SSI direction 34 * B : SSI direction
35 */ 35 */
36#define RSND_SSI_CLK_PIN_SHARE (1 << 31) 36#define RSND_SSI_CLK_PIN_SHARE (1 << 31)
37#define RSND_SSI_SYNC (1 << 29) /* SSI34_sync etc */
38
39#define RSND_SSI_PLAY (1 << 24) 37#define RSND_SSI_PLAY (1 << 24)
40 38
39#define RSND_SSI(_dma_id, _pio_irq, _flags) \
40{ .dma_id = _dma_id, .pio_irq = _pio_irq, .flags = _flags }
41#define RSND_SSI_SET(_dai_id, _dma_id, _pio_irq, _flags) \ 41#define RSND_SSI_SET(_dai_id, _dma_id, _pio_irq, _flags) \
42{ .dai_id = _dai_id, .dma_id = _dma_id, .pio_irq = _pio_irq, .flags = _flags } 42{ .dai_id = _dai_id, .dma_id = _dma_id, .pio_irq = _pio_irq, .flags = _flags }
43#define RSND_SSI_UNUSED \ 43#define RSND_SSI_UNUSED \
44{ .dai_id = -1, .dma_id = -1, .pio_irq = -1, .flags = 0 } 44{ .dai_id = -1, .dma_id = -1, .pio_irq = -1, .flags = 0 }
45 45
46struct rsnd_ssi_platform_info { 46struct rsnd_ssi_platform_info {
47 int dai_id; 47 int dai_id; /* will be removed */
48 int dma_id; 48 int dma_id;
49 int pio_irq; 49 int pio_irq;
50 u32 flags; 50 u32 flags;
@@ -55,9 +55,31 @@ struct rsnd_ssi_platform_info {
55 */ 55 */
56#define RSND_SCU_USE_HPBIF (1 << 31) /* it needs RSND_SSI_DEPENDENT */ 56#define RSND_SCU_USE_HPBIF (1 << 31) /* it needs RSND_SSI_DEPENDENT */
57 57
58struct rsnd_scu_platform_info { 58#define RSND_SRC(rate, _dma_id) \
59{ .flags = RSND_SCU_USE_HPBIF, .convert_rate = rate, .dma_id = _dma_id, }
60#define RSND_SRC_SET(rate, _dma_id) \
61 { .flags = RSND_SCU_USE_HPBIF, .convert_rate = rate, .dma_id = _dma_id, }
62#define RSND_SRC_UNUSED \
63 { .flags = 0, .convert_rate = 0, .dma_id = 0, }
64
65#define rsnd_scu_platform_info rsnd_src_platform_info
66#define src_info scu_info
67#define src_info_nr scu_info_nr
68
69struct rsnd_src_platform_info {
59 u32 flags; 70 u32 flags;
60 u32 convert_rate; /* sampling rate convert */ 71 u32 convert_rate; /* sampling rate convert */
72 int dma_id; /* for Gen2 SCU */
73};
74
75struct rsnd_dai_path_info {
76 struct rsnd_ssi_platform_info *ssi;
77 struct rsnd_src_platform_info *src;
78};
79
80struct rsnd_dai_platform_info {
81 struct rsnd_dai_path_info playback;
82 struct rsnd_dai_path_info capture;
61}; 83};
62 84
63/* 85/*
@@ -75,8 +97,10 @@ struct rcar_snd_info {
75 u32 flags; 97 u32 flags;
76 struct rsnd_ssi_platform_info *ssi_info; 98 struct rsnd_ssi_platform_info *ssi_info;
77 int ssi_info_nr; 99 int ssi_info_nr;
78 struct rsnd_scu_platform_info *scu_info; 100 struct rsnd_src_platform_info *src_info;
79 int scu_info_nr; 101 int src_info_nr;
102 struct rsnd_dai_platform_info *dai_info;
103 int dai_info_nr;
80 int (*start)(int id); 104 int (*start)(int id);
81 int (*stop)(int id); 105 int (*stop)(int id);
82}; 106};
diff --git a/include/sound/simple_card.h b/include/sound/simple_card.h
index 6c74527d4926..9b0ac77177b6 100644
--- a/include/sound/simple_card.h
+++ b/include/sound/simple_card.h
@@ -18,6 +18,8 @@ struct asoc_simple_dai {
18 const char *name; 18 const char *name;
19 unsigned int fmt; 19 unsigned int fmt;
20 unsigned int sysclk; 20 unsigned int sysclk;
21 int slots;
22 int slot_width;
21}; 23};
22 24
23struct asoc_simple_card_info { 25struct asoc_simple_card_info {
@@ -29,10 +31,6 @@ struct asoc_simple_card_info {
29 unsigned int daifmt; 31 unsigned int daifmt;
30 struct asoc_simple_dai cpu_dai; 32 struct asoc_simple_dai cpu_dai;
31 struct asoc_simple_dai codec_dai; 33 struct asoc_simple_dai codec_dai;
32
33 /* used in simple-card.c */
34 struct snd_soc_dai_link snd_link;
35 struct snd_soc_card snd_card;
36}; 34};
37 35
38#endif /* __SIMPLE_CARD_H */ 36#endif /* __SIMPLE_CARD_H */
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index 71f27c403194..2f66d5e8cd15 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -142,6 +142,8 @@ struct snd_soc_dai_ops {
142 * Called by soc_card drivers, normally in their hw_params. 142 * Called by soc_card drivers, normally in their hw_params.
143 */ 143 */
144 int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt); 144 int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
145 int (*of_xlate_tdm_slot_mask)(unsigned int slots,
146 unsigned int *tx_mask, unsigned int *rx_mask);
145 int (*set_tdm_slot)(struct snd_soc_dai *dai, 147 int (*set_tdm_slot)(struct snd_soc_dai *dai,
146 unsigned int tx_mask, unsigned int rx_mask, 148 unsigned int tx_mask, unsigned int rx_mask,
147 int slots, int slot_width); 149 int slots, int slot_width);
@@ -270,6 +272,7 @@ struct snd_soc_dai {
270 /* parent platform/codec */ 272 /* parent platform/codec */
271 struct snd_soc_platform *platform; 273 struct snd_soc_platform *platform;
272 struct snd_soc_codec *codec; 274 struct snd_soc_codec *codec;
275 struct snd_soc_component *component;
273 276
274 struct snd_soc_card *card; 277 struct snd_soc_card *card;
275 278
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 6e89ef6c11c1..ef78f562f4a8 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -108,13 +108,9 @@ struct device;
108 SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ 108 SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
109 .kcontrol_news = wcontrols, .num_kcontrols = 1} 109 .kcontrol_news = wcontrols, .num_kcontrols = 1}
110#define SND_SOC_DAPM_VIRT_MUX(wname, wreg, wshift, winvert, wcontrols) \ 110#define SND_SOC_DAPM_VIRT_MUX(wname, wreg, wshift, winvert, wcontrols) \
111{ .id = snd_soc_dapm_virt_mux, .name = wname, \ 111 SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols)
112 SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
113 .kcontrol_news = wcontrols, .num_kcontrols = 1}
114#define SND_SOC_DAPM_VALUE_MUX(wname, wreg, wshift, winvert, wcontrols) \ 112#define SND_SOC_DAPM_VALUE_MUX(wname, wreg, wshift, winvert, wcontrols) \
115{ .id = snd_soc_dapm_value_mux, .name = wname, \ 113 SND_SOC_DAPM_MUX(wname, wreg, wshift, winvert, wcontrols)
116 SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
117 .kcontrol_news = wcontrols, .num_kcontrols = 1}
118 114
119/* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */ 115/* Simplified versions of above macros, assuming wncontrols = ARRAY_SIZE(wcontrols) */
120#define SOC_PGA_ARRAY(wname, wreg, wshift, winvert,\ 116#define SOC_PGA_ARRAY(wname, wreg, wshift, winvert,\
@@ -172,10 +168,8 @@ struct device;
172 .event = wevent, .event_flags = wflags} 168 .event = wevent, .event_flags = wflags}
173#define SND_SOC_DAPM_VIRT_MUX_E(wname, wreg, wshift, winvert, wcontrols, \ 169#define SND_SOC_DAPM_VIRT_MUX_E(wname, wreg, wshift, winvert, wcontrols, \
174 wevent, wflags) \ 170 wevent, wflags) \
175{ .id = snd_soc_dapm_virt_mux, .name = wname, \ 171 SND_SOC_DAPM_MUX_E(wname, wreg, wshift, winvert, wcontrols, wevent, \
176 SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \ 172 wflags)
177 .kcontrol_news = wcontrols, .num_kcontrols = 1, \
178 .event = wevent, .event_flags = wflags}
179 173
180/* additional sequencing control within an event type */ 174/* additional sequencing control within an event type */
181#define SND_SOC_DAPM_PGA_S(wname, wsubseq, wreg, wshift, winvert, \ 175#define SND_SOC_DAPM_PGA_S(wname, wsubseq, wreg, wshift, winvert, \
@@ -311,12 +305,8 @@ struct device;
311 .get = snd_soc_dapm_get_enum_double, \ 305 .get = snd_soc_dapm_get_enum_double, \
312 .put = snd_soc_dapm_put_enum_double, \ 306 .put = snd_soc_dapm_put_enum_double, \
313 .private_value = (unsigned long)&xenum } 307 .private_value = (unsigned long)&xenum }
314#define SOC_DAPM_ENUM_VIRT(xname, xenum) \ 308#define SOC_DAPM_ENUM_VIRT(xname, xenum) \
315{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 309 SOC_DAPM_ENUM(xname, xenum)
316 .info = snd_soc_info_enum_double, \
317 .get = snd_soc_dapm_get_enum_virt, \
318 .put = snd_soc_dapm_put_enum_virt, \
319 .private_value = (unsigned long)&xenum }
320#define SOC_DAPM_ENUM_EXT(xname, xenum, xget, xput) \ 310#define SOC_DAPM_ENUM_EXT(xname, xenum, xget, xput) \
321{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 311{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
322 .info = snd_soc_info_enum_double, \ 312 .info = snd_soc_info_enum_double, \
@@ -324,11 +314,7 @@ struct device;
324 .put = xput, \ 314 .put = xput, \
325 .private_value = (unsigned long)&xenum } 315 .private_value = (unsigned long)&xenum }
326#define SOC_DAPM_VALUE_ENUM(xname, xenum) \ 316#define SOC_DAPM_VALUE_ENUM(xname, xenum) \
327{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 317 SOC_DAPM_ENUM(xname, xenum)
328 .info = snd_soc_info_enum_double, \
329 .get = snd_soc_dapm_get_value_enum_double, \
330 .put = snd_soc_dapm_put_value_enum_double, \
331 .private_value = (unsigned long)&xenum }
332#define SOC_DAPM_PIN_SWITCH(xname) \ 318#define SOC_DAPM_PIN_SWITCH(xname) \
333{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname " Switch", \ 319{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname " Switch", \
334 .info = snd_soc_dapm_info_pin_switch, \ 320 .info = snd_soc_dapm_info_pin_switch, \
@@ -392,14 +378,6 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
392 struct snd_ctl_elem_value *ucontrol); 378 struct snd_ctl_elem_value *ucontrol);
393int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, 379int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
394 struct snd_ctl_elem_value *ucontrol); 380 struct snd_ctl_elem_value *ucontrol);
395int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
396 struct snd_ctl_elem_value *ucontrol);
397int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
398 struct snd_ctl_elem_value *ucontrol);
399int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
400 struct snd_ctl_elem_value *ucontrol);
401int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
402 struct snd_ctl_elem_value *ucontrol);
403int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, 381int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
404 struct snd_ctl_elem_info *uinfo); 382 struct snd_ctl_elem_info *uinfo);
405int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, 383int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
@@ -461,6 +439,7 @@ int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context *dapm,
461int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, 439int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
462 const char *pin); 440 const char *pin);
463int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm); 441int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm);
442int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context *dapm);
464int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, 443int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
465 const char *pin); 444 const char *pin);
466int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm, 445int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
@@ -470,7 +449,6 @@ int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
470void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec); 449void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec);
471 450
472/* Mostly internal - should not normally be used */ 451/* Mostly internal - should not normally be used */
473void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason);
474void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm); 452void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm);
475 453
476/* dapm path query */ 454/* dapm path query */
@@ -484,8 +462,6 @@ enum snd_soc_dapm_type {
484 snd_soc_dapm_input = 0, /* input pin */ 462 snd_soc_dapm_input = 0, /* input pin */
485 snd_soc_dapm_output, /* output pin */ 463 snd_soc_dapm_output, /* output pin */
486 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */ 464 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */
487 snd_soc_dapm_virt_mux, /* virtual version of snd_soc_dapm_mux */
488 snd_soc_dapm_value_mux, /* selects 1 analog signal from many inputs */
489 snd_soc_dapm_mixer, /* mixes several analog signals together */ 465 snd_soc_dapm_mixer, /* mixes several analog signals together */
490 snd_soc_dapm_mixer_named_ctl, /* mixer with named controls */ 466 snd_soc_dapm_mixer_named_ctl, /* mixer with named controls */
491 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */ 467 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 9a001472b96a..0b83168d8ff4 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -45,6 +45,11 @@
45 ((unsigned long)&(struct soc_mixer_control) \ 45 ((unsigned long)&(struct soc_mixer_control) \
46 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \ 46 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
47 .max = xmax, .platform_max = xmax, .invert = xinvert}) 47 .max = xmax, .platform_max = xmax, .invert = xinvert})
48#define SOC_DOUBLE_R_S_VALUE(xlreg, xrreg, xshift, xmin, xmax, xsign_bit, xinvert) \
49 ((unsigned long)&(struct soc_mixer_control) \
50 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
51 .max = xmax, .min = xmin, .platform_max = xmax, .sign_bit = xsign_bit, \
52 .invert = xinvert})
48#define SOC_DOUBLE_R_RANGE_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \ 53#define SOC_DOUBLE_R_RANGE_VALUE(xlreg, xrreg, xshift, xmin, xmax, xinvert) \
49 ((unsigned long)&(struct soc_mixer_control) \ 54 ((unsigned long)&(struct soc_mixer_control) \
50 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \ 55 {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
@@ -152,6 +157,15 @@
152 {.reg = xreg, .rreg = xrreg, \ 157 {.reg = xreg, .rreg = xrreg, \
153 .shift = xshift, .rshift = xshift, \ 158 .shift = xshift, .rshift = xshift, \
154 .max = xmax, .min = xmin} } 159 .max = xmax, .min = xmin} }
160#define SOC_DOUBLE_R_S_TLV(xname, reg_left, reg_right, xshift, xmin, xmax, xsign_bit, xinvert, tlv_array) \
161{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
162 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
163 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
164 .tlv.p = (tlv_array), \
165 .info = snd_soc_info_volsw, \
166 .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
167 .private_value = SOC_DOUBLE_R_S_VALUE(reg_left, reg_right, xshift, \
168 xmin, xmax, xsign_bit, xinvert) }
155#define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \ 169#define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
156{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 170{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
157 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ 171 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
@@ -162,30 +176,28 @@
162 .private_value = (unsigned long)&(struct soc_mixer_control) \ 176 .private_value = (unsigned long)&(struct soc_mixer_control) \
163 {.reg = xreg, .min = xmin, .max = xmax, \ 177 {.reg = xreg, .min = xmin, .max = xmax, \
164 .platform_max = xmax} } 178 .platform_max = xmax} }
165#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \ 179#define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xitems, xtexts) \
166{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ 180{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
167 .max = xmax, .texts = xtexts, \ 181 .items = xitems, .texts = xtexts, \
168 .mask = xmax ? roundup_pow_of_two(xmax) - 1 : 0} 182 .mask = xitems ? roundup_pow_of_two(xitems) - 1 : 0}
169#define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \ 183#define SOC_ENUM_SINGLE(xreg, xshift, xitems, xtexts) \
170 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts) 184 SOC_ENUM_DOUBLE(xreg, xshift, xshift, xitems, xtexts)
171#define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \ 185#define SOC_ENUM_SINGLE_EXT(xitems, xtexts) \
172{ .max = xmax, .texts = xtexts } 186{ .items = xitems, .texts = xtexts }
173#define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xmax, xtexts, xvalues) \ 187#define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
174{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ 188{ .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
175 .mask = xmask, .max = xmax, .texts = xtexts, .values = xvalues} 189 .mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
176#define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xmax, xtexts, xvalues) \ 190#define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xnitmes, xtexts, xvalues) \
177 SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xmax, xtexts, xvalues) 191 SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xnitmes, xtexts, xvalues)
192#define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
193 SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
178#define SOC_ENUM(xname, xenum) \ 194#define SOC_ENUM(xname, xenum) \
179{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\ 195{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
180 .info = snd_soc_info_enum_double, \ 196 .info = snd_soc_info_enum_double, \
181 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \ 197 .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
182 .private_value = (unsigned long)&xenum } 198 .private_value = (unsigned long)&xenum }
183#define SOC_VALUE_ENUM(xname, xenum) \ 199#define SOC_VALUE_ENUM(xname, xenum) \
184{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\ 200 SOC_ENUM(xname, xenum)
185 .info = snd_soc_info_enum_double, \
186 .get = snd_soc_get_value_enum_double, \
187 .put = snd_soc_put_value_enum_double, \
188 .private_value = (unsigned long)&xenum }
189#define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\ 201#define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
190 xhandler_get, xhandler_put) \ 202 xhandler_get, xhandler_put) \
191{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 203{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
@@ -272,17 +284,19 @@
272 * ARRAY_SIZE internally 284 * ARRAY_SIZE internally
273 */ 285 */
274#define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \ 286#define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
275 struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \ 287 const struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
276 ARRAY_SIZE(xtexts), xtexts) 288 ARRAY_SIZE(xtexts), xtexts)
277#define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \ 289#define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
278 SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts) 290 SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
279#define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \ 291#define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
280 struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts) 292 const struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
281#define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \ 293#define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
282 struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \ 294 const struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
283 ARRAY_SIZE(xtexts), xtexts, xvalues) 295 ARRAY_SIZE(xtexts), xtexts, xvalues)
284#define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \ 296#define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
285 SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues) 297 SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
298#define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
299 const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
286 300
287/* 301/*
288 * Component probe and remove ordering levels for components with runtime 302 * Component probe and remove ordering levels for components with runtime
@@ -340,12 +354,6 @@ typedef int (*hw_write_t)(void *,const char* ,int);
340 354
341extern struct snd_ac97_bus_ops *soc_ac97_ops; 355extern struct snd_ac97_bus_ops *soc_ac97_ops;
342 356
343enum snd_soc_control_type {
344 SND_SOC_I2C = 1,
345 SND_SOC_SPI,
346 SND_SOC_REGMAP,
347};
348
349enum snd_soc_pcm_subclass { 357enum snd_soc_pcm_subclass {
350 SND_SOC_PCM_CLASS_PCM = 0, 358 SND_SOC_PCM_CLASS_PCM = 0,
351 SND_SOC_PCM_CLASS_BE = 1, 359 SND_SOC_PCM_CLASS_BE = 1,
@@ -392,8 +400,7 @@ int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
392int snd_soc_codec_writable_register(struct snd_soc_codec *codec, 400int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
393 unsigned int reg); 401 unsigned int reg);
394int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, 402int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
395 int addr_bits, int data_bits, 403 struct regmap *regmap);
396 enum snd_soc_control_type control);
397int snd_soc_cache_sync(struct snd_soc_codec *codec); 404int snd_soc_cache_sync(struct snd_soc_codec *codec);
398int snd_soc_cache_init(struct snd_soc_codec *codec); 405int snd_soc_cache_init(struct snd_soc_codec *codec);
399int snd_soc_cache_exit(struct snd_soc_codec *codec); 406int snd_soc_cache_exit(struct snd_soc_codec *codec);
@@ -413,6 +420,10 @@ struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
413struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, 420struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
414 const char *dai_link); 421 const char *dai_link);
415 422
423bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
424void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream);
425void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
426
416/* Utility functions to get clock rates from various things */ 427/* Utility functions to get clock rates from various things */
417int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots); 428int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
418int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params); 429int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
@@ -496,10 +507,6 @@ int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
496 struct snd_ctl_elem_value *ucontrol); 507 struct snd_ctl_elem_value *ucontrol);
497int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, 508int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
498 struct snd_ctl_elem_value *ucontrol); 509 struct snd_ctl_elem_value *ucontrol);
499int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
500 struct snd_ctl_elem_value *ucontrol);
501int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
502 struct snd_ctl_elem_value *ucontrol);
503int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, 510int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
504 struct snd_ctl_elem_info *uinfo); 511 struct snd_ctl_elem_info *uinfo);
505#define snd_soc_info_bool_ext snd_ctl_boolean_mono_info 512#define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
@@ -600,7 +607,8 @@ struct snd_soc_jack_gpio {
600 struct snd_soc_jack *jack; 607 struct snd_soc_jack *jack;
601 struct delayed_work work; 608 struct delayed_work work;
602 609
603 int (*jack_status_check)(void); 610 void *data;
611 int (*jack_status_check)(void *data);
604}; 612};
605 613
606struct snd_soc_jack { 614struct snd_soc_jack {
@@ -656,12 +664,19 @@ struct snd_soc_component {
656 const char *name; 664 const char *name;
657 int id; 665 int id;
658 struct device *dev; 666 struct device *dev;
667
668 unsigned int active;
669
670 unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
671
659 struct list_head list; 672 struct list_head list;
660 673
661 struct snd_soc_dai_driver *dai_drv; 674 struct snd_soc_dai_driver *dai_drv;
662 int num_dai; 675 int num_dai;
663 676
664 const struct snd_soc_component_driver *driver; 677 const struct snd_soc_component_driver *driver;
678
679 struct list_head dai_list;
665}; 680};
666 681
667/* SoC Audio Codec device */ 682/* SoC Audio Codec device */
@@ -683,7 +698,6 @@ struct snd_soc_codec {
683 698
684 /* runtime */ 699 /* runtime */
685 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */ 700 struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
686 unsigned int active;
687 unsigned int cache_bypass:1; /* Suppress access to the cache */ 701 unsigned int cache_bypass:1; /* Suppress access to the cache */
688 unsigned int suspended:1; /* Codec is in suspend PM state */ 702 unsigned int suspended:1; /* Codec is in suspend PM state */
689 unsigned int probed:1; /* Codec has been probed */ 703 unsigned int probed:1; /* Codec has been probed */
@@ -697,7 +711,6 @@ struct snd_soc_codec {
697 /* codec IO */ 711 /* codec IO */
698 void *control_data; /* codec control (i2c/3wire) data */ 712 void *control_data; /* codec control (i2c/3wire) data */
699 hw_write_t hw_write; 713 hw_write_t hw_write;
700 unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int);
701 unsigned int (*read)(struct snd_soc_codec *, unsigned int); 714 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
702 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int); 715 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
703 void *reg_cache; 716 void *reg_cache;
@@ -709,7 +722,6 @@ struct snd_soc_codec {
709 722
710 /* dapm */ 723 /* dapm */
711 struct snd_soc_dapm_context dapm; 724 struct snd_soc_dapm_context dapm;
712 unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
713 725
714#ifdef CONFIG_DEBUG_FS 726#ifdef CONFIG_DEBUG_FS
715 struct dentry *debugfs_codec_root; 727 struct dentry *debugfs_codec_root;
@@ -1067,6 +1079,7 @@ struct soc_mixer_control {
1067 int min, max, platform_max; 1079 int min, max, platform_max;
1068 int reg, rreg; 1080 int reg, rreg;
1069 unsigned int shift, rshift; 1081 unsigned int shift, rshift;
1082 unsigned int sign_bit;
1070 unsigned int invert:1; 1083 unsigned int invert:1;
1071 unsigned int autodisable:1; 1084 unsigned int autodisable:1;
1072}; 1085};
@@ -1085,16 +1098,28 @@ struct soc_mreg_control {
1085 1098
1086/* enumerated kcontrol */ 1099/* enumerated kcontrol */
1087struct soc_enum { 1100struct soc_enum {
1088 unsigned short reg; 1101 int reg;
1089 unsigned short reg2;
1090 unsigned char shift_l; 1102 unsigned char shift_l;
1091 unsigned char shift_r; 1103 unsigned char shift_r;
1092 unsigned int max; 1104 unsigned int items;
1093 unsigned int mask; 1105 unsigned int mask;
1094 const char * const *texts; 1106 const char * const *texts;
1095 const unsigned int *values; 1107 const unsigned int *values;
1096}; 1108};
1097 1109
1110/**
1111 * snd_soc_component_to_codec() - Casts a component to the CODEC it is embedded in
1112 * @component: The component to cast to a CODEC
1113 *
1114 * This function must only be used on components that are known to be CODECs.
1115 * Otherwise the behavior is undefined.
1116 */
1117static inline struct snd_soc_codec *snd_soc_component_to_codec(
1118 struct snd_soc_component *component)
1119{
1120 return container_of(component, struct snd_soc_codec, component);
1121}
1122
1098/* codec IO */ 1123/* codec IO */
1099unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg); 1124unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
1100unsigned int snd_soc_write(struct snd_soc_codec *codec, 1125unsigned int snd_soc_write(struct snd_soc_codec *codec,
@@ -1168,11 +1193,51 @@ static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
1168 return 1; 1193 return 1;
1169} 1194}
1170 1195
1196static inline unsigned int snd_soc_enum_val_to_item(struct soc_enum *e,
1197 unsigned int val)
1198{
1199 unsigned int i;
1200
1201 if (!e->values)
1202 return val;
1203
1204 for (i = 0; i < e->items; i++)
1205 if (val == e->values[i])
1206 return i;
1207
1208 return 0;
1209}
1210
1211static inline unsigned int snd_soc_enum_item_to_val(struct soc_enum *e,
1212 unsigned int item)
1213{
1214 if (!e->values)
1215 return item;
1216
1217 return e->values[item];
1218}
1219
1220static inline bool snd_soc_component_is_active(
1221 struct snd_soc_component *component)
1222{
1223 return component->active != 0;
1224}
1225
1226static inline bool snd_soc_codec_is_active(struct snd_soc_codec *codec)
1227{
1228 return snd_soc_component_is_active(&codec->component);
1229}
1230
1171int snd_soc_util_init(void); 1231int snd_soc_util_init(void);
1172void snd_soc_util_exit(void); 1232void snd_soc_util_exit(void);
1173 1233
1174int snd_soc_of_parse_card_name(struct snd_soc_card *card, 1234int snd_soc_of_parse_card_name(struct snd_soc_card *card,
1175 const char *propname); 1235 const char *propname);
1236int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
1237 const char *propname);
1238int snd_soc_of_parse_tdm_slot(struct device_node *np,
1239 unsigned int *slots,
1240 unsigned int *slot_width);
1176int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, 1241int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
1177 const char *propname); 1242 const char *propname);
1178unsigned int snd_soc_of_parse_daifmt(struct device_node *np, 1243unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
@@ -1188,4 +1253,15 @@ extern struct dentry *snd_soc_debugfs_root;
1188 1253
1189extern const struct dev_pm_ops snd_soc_pm_ops; 1254extern const struct dev_pm_ops snd_soc_pm_ops;
1190 1255
1256/* Helper functions */
1257static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm)
1258{
1259 mutex_lock(&dapm->card->dapm_mutex);
1260}
1261
1262static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
1263{
1264 mutex_unlock(&dapm->card->dapm_mutex);
1265}
1266
1191#endif 1267#endif
diff --git a/include/trace/events/hswadsp.h b/include/trace/events/hswadsp.h
new file mode 100644
index 000000000000..0f78bbb02002
--- /dev/null
+++ b/include/trace/events/hswadsp.h
@@ -0,0 +1,384 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM hswadsp
3
4#if !defined(_TRACE_HSWADSP_H) || defined(TRACE_HEADER_MULTI_READ)
5#define _TRACE_HSWADSP_H
6
7#include <linux/types.h>
8#include <linux/ktime.h>
9#include <linux/tracepoint.h>
10
11struct sst_hsw;
12struct sst_hsw_stream;
13struct sst_hsw_ipc_stream_free_req;
14struct sst_hsw_ipc_volume_req;
15struct sst_hsw_ipc_stream_alloc_req;
16struct sst_hsw_audio_data_format_ipc;
17struct sst_hsw_ipc_stream_info_reply;
18struct sst_hsw_ipc_device_config_req;
19
20DECLARE_EVENT_CLASS(sst_irq,
21
22 TP_PROTO(uint32_t status, uint32_t mask),
23
24 TP_ARGS(status, mask),
25
26 TP_STRUCT__entry(
27 __field( unsigned int, status )
28 __field( unsigned int, mask )
29 ),
30
31 TP_fast_assign(
32 __entry->status = status;
33 __entry->mask = mask;
34 ),
35
36 TP_printk("status 0x%8.8x mask 0x%8.8x",
37 (unsigned int)__entry->status, (unsigned int)__entry->mask)
38);
39
40DEFINE_EVENT(sst_irq, sst_irq_busy,
41
42 TP_PROTO(unsigned int status, unsigned int mask),
43
44 TP_ARGS(status, mask)
45
46);
47
48DEFINE_EVENT(sst_irq, sst_irq_done,
49
50 TP_PROTO(unsigned int status, unsigned int mask),
51
52 TP_ARGS(status, mask)
53
54);
55
56DECLARE_EVENT_CLASS(ipc,
57
58 TP_PROTO(const char *name, int val),
59
60 TP_ARGS(name, val),
61
62 TP_STRUCT__entry(
63 __string( name, name )
64 __field( unsigned int, val )
65 ),
66
67 TP_fast_assign(
68 __assign_str(name, name);
69 __entry->val = val;
70 ),
71
72 TP_printk("%s 0x%8.8x", __get_str(name), (unsigned int)__entry->val)
73
74);
75
76DEFINE_EVENT(ipc, ipc_request,
77
78 TP_PROTO(const char *name, int val),
79
80 TP_ARGS(name, val)
81
82);
83
84DEFINE_EVENT(ipc, ipc_reply,
85
86 TP_PROTO(const char *name, int val),
87
88 TP_ARGS(name, val)
89
90);
91
92DEFINE_EVENT(ipc, ipc_pending_reply,
93
94 TP_PROTO(const char *name, int val),
95
96 TP_ARGS(name, val)
97
98);
99
100DEFINE_EVENT(ipc, ipc_notification,
101
102 TP_PROTO(const char *name, int val),
103
104 TP_ARGS(name, val)
105
106);
107
108DEFINE_EVENT(ipc, ipc_error,
109
110 TP_PROTO(const char *name, int val),
111
112 TP_ARGS(name, val)
113
114);
115
116DECLARE_EVENT_CLASS(stream_position,
117
118 TP_PROTO(unsigned int id, unsigned int pos),
119
120 TP_ARGS(id, pos),
121
122 TP_STRUCT__entry(
123 __field( unsigned int, id )
124 __field( unsigned int, pos )
125 ),
126
127 TP_fast_assign(
128 __entry->id = id;
129 __entry->pos = pos;
130 ),
131
132 TP_printk("id %d position 0x%x",
133 (unsigned int)__entry->id, (unsigned int)__entry->pos)
134);
135
136DEFINE_EVENT(stream_position, stream_read_position,
137
138 TP_PROTO(unsigned int id, unsigned int pos),
139
140 TP_ARGS(id, pos)
141
142);
143
144DEFINE_EVENT(stream_position, stream_write_position,
145
146 TP_PROTO(unsigned int id, unsigned int pos),
147
148 TP_ARGS(id, pos)
149
150);
151
152TRACE_EVENT(hsw_stream_buffer,
153
154 TP_PROTO(struct sst_hsw_stream *stream),
155
156 TP_ARGS(stream),
157
158 TP_STRUCT__entry(
159 __field( int, id )
160 __field( int, pt_addr )
161 __field( int, num_pages )
162 __field( int, ring_size )
163 __field( int, ring_offset )
164 __field( int, first_pfn )
165 ),
166
167 TP_fast_assign(
168 __entry->id = stream->host_id;
169 __entry->pt_addr = stream->request.ringinfo.ring_pt_address;
170 __entry->num_pages = stream->request.ringinfo.num_pages;
171 __entry->ring_size = stream->request.ringinfo.ring_size;
172 __entry->ring_offset = stream->request.ringinfo.ring_offset;
173 __entry->first_pfn = stream->request.ringinfo.ring_first_pfn;
174 ),
175
176 TP_printk("stream %d ring addr 0x%x pages %d size 0x%x offset 0x%x PFN 0x%x",
177 (int) __entry->id, (int)__entry->pt_addr,
178 (int)__entry->num_pages, (int)__entry->ring_size,
179 (int)__entry->ring_offset, (int)__entry->first_pfn)
180);
181
182TRACE_EVENT(hsw_stream_alloc_reply,
183
184 TP_PROTO(struct sst_hsw_stream *stream),
185
186 TP_ARGS(stream),
187
188 TP_STRUCT__entry(
189 __field( int, id )
190 __field( int, stream_id )
191 __field( int, mixer_id )
192 __field( int, peak0 )
193 __field( int, peak1 )
194 __field( int, vol0 )
195 __field( int, vol1 )
196 ),
197
198 TP_fast_assign(
199 __entry->id = stream->host_id;
200 __entry->stream_id = stream->reply.stream_hw_id;
201 __entry->mixer_id = stream->reply.mixer_hw_id;
202 __entry->peak0 = stream->reply.peak_meter_register_address[0];
203 __entry->peak1 = stream->reply.peak_meter_register_address[1];
204 __entry->vol0 = stream->reply.volume_register_address[0];
205 __entry->vol1 = stream->reply.volume_register_address[1];
206 ),
207
208 TP_printk("stream %d hw id %d mixer %d peak 0x%x:0x%x vol 0x%x,0x%x",
209 (int) __entry->id, (int) __entry->stream_id, (int)__entry->mixer_id,
210 (int)__entry->peak0, (int)__entry->peak1,
211 (int)__entry->vol0, (int)__entry->vol1)
212);
213
214TRACE_EVENT(hsw_mixer_info_reply,
215
216 TP_PROTO(struct sst_hsw_ipc_stream_info_reply *reply),
217
218 TP_ARGS(reply),
219
220 TP_STRUCT__entry(
221 __field( int, mixer_id )
222 __field( int, peak0 )
223 __field( int, peak1 )
224 __field( int, vol0 )
225 __field( int, vol1 )
226 ),
227
228 TP_fast_assign(
229 __entry->mixer_id = reply->mixer_hw_id;
230 __entry->peak0 = reply->peak_meter_register_address[0];
231 __entry->peak1 = reply->peak_meter_register_address[1];
232 __entry->vol0 = reply->volume_register_address[0];
233 __entry->vol1 = reply->volume_register_address[1];
234 ),
235
236 TP_printk("mixer id %d peak 0x%x:0x%x vol 0x%x,0x%x",
237 (int)__entry->mixer_id,
238 (int)__entry->peak0, (int)__entry->peak1,
239 (int)__entry->vol0, (int)__entry->vol1)
240);
241
242TRACE_EVENT(hsw_stream_data_format,
243
244 TP_PROTO(struct sst_hsw_stream *stream,
245 struct sst_hsw_audio_data_format_ipc *req),
246
247 TP_ARGS(stream, req),
248
249 TP_STRUCT__entry(
250 __field( uint32_t, id )
251 __field( uint32_t, frequency )
252 __field( uint32_t, bitdepth )
253 __field( uint32_t, map )
254 __field( uint32_t, config )
255 __field( uint32_t, style )
256 __field( uint8_t, ch_num )
257 __field( uint8_t, valid_bit )
258 ),
259
260 TP_fast_assign(
261 __entry->id = stream->host_id;
262 __entry->frequency = req->frequency;
263 __entry->bitdepth = req->bitdepth;
264 __entry->map = req->map;
265 __entry->config = req->config;
266 __entry->style = req->style;
267 __entry->ch_num = req->ch_num;
268 __entry->valid_bit = req->valid_bit;
269 ),
270
271 TP_printk("stream %d freq %d depth %d map 0x%x config 0x%x style 0x%x ch %d bits %d",
272 (int) __entry->id, (uint32_t)__entry->frequency,
273 (uint32_t)__entry->bitdepth, (uint32_t)__entry->map,
274 (uint32_t)__entry->config, (uint32_t)__entry->style,
275 (uint8_t)__entry->ch_num, (uint8_t)__entry->valid_bit)
276);
277
278TRACE_EVENT(hsw_stream_alloc_request,
279
280 TP_PROTO(struct sst_hsw_stream *stream,
281 struct sst_hsw_ipc_stream_alloc_req *req),
282
283 TP_ARGS(stream, req),
284
285 TP_STRUCT__entry(
286 __field( uint32_t, id )
287 __field( uint8_t, path_id )
288 __field( uint8_t, stream_type )
289 __field( uint8_t, format_id )
290 ),
291
292 TP_fast_assign(
293 __entry->id = stream->host_id;
294 __entry->path_id = req->path_id;
295 __entry->stream_type = req->stream_type;
296 __entry->format_id = req->format_id;
297 ),
298
299 TP_printk("stream %d path %d type %d format %d",
300 (int) __entry->id, (uint8_t)__entry->path_id,
301 (uint8_t)__entry->stream_type, (uint8_t)__entry->format_id)
302);
303
304TRACE_EVENT(hsw_stream_free_req,
305
306 TP_PROTO(struct sst_hsw_stream *stream,
307 struct sst_hsw_ipc_stream_free_req *req),
308
309 TP_ARGS(stream, req),
310
311 TP_STRUCT__entry(
312 __field( int, id )
313 __field( int, stream_id )
314 ),
315
316 TP_fast_assign(
317 __entry->id = stream->host_id;
318 __entry->stream_id = req->stream_id;
319 ),
320
321 TP_printk("stream %d hw id %d",
322 (int) __entry->id, (int) __entry->stream_id)
323);
324
325TRACE_EVENT(hsw_volume_req,
326
327 TP_PROTO(struct sst_hsw_stream *stream,
328 struct sst_hsw_ipc_volume_req *req),
329
330 TP_ARGS(stream, req),
331
332 TP_STRUCT__entry(
333 __field( int, id )
334 __field( uint32_t, channel )
335 __field( uint32_t, target_volume )
336 __field( uint64_t, curve_duration )
337 __field( uint32_t, curve_type )
338 ),
339
340 TP_fast_assign(
341 __entry->id = stream->host_id;
342 __entry->channel = req->channel;
343 __entry->target_volume = req->target_volume;
344 __entry->curve_duration = req->curve_duration;
345 __entry->curve_type = req->curve_type;
346 ),
347
348 TP_printk("stream %d chan 0x%x vol %d duration %llu type %d",
349 (int) __entry->id, (uint32_t) __entry->channel,
350 (uint32_t)__entry->target_volume,
351 (uint64_t)__entry->curve_duration,
352 (uint32_t)__entry->curve_type)
353);
354
355TRACE_EVENT(hsw_device_config_req,
356
357 TP_PROTO(struct sst_hsw_ipc_device_config_req *req),
358
359 TP_ARGS(req),
360
361 TP_STRUCT__entry(
362 __field( uint32_t, ssp )
363 __field( uint32_t, clock_freq )
364 __field( uint32_t, mode )
365 __field( uint16_t, clock_divider )
366 ),
367
368 TP_fast_assign(
369 __entry->ssp = req->ssp_interface;
370 __entry->clock_freq = req->clock_frequency;
371 __entry->mode = req->mode;
372 __entry->clock_divider = req->clock_divider;
373 ),
374
375 TP_printk("SSP %d Freq %d mode %d div %d",
376 (uint32_t)__entry->ssp,
377 (uint32_t)__entry->clock_freq, (uint32_t)__entry->mode,
378 (uint32_t)__entry->clock_divider)
379);
380
381#endif /* _TRACE_HSWADSP_H */
382
383/* This part must be outside protection */
384#include <trace/define_trace.h>
diff --git a/include/trace/events/intel-sst.h b/include/trace/events/intel-sst.h
new file mode 100644
index 000000000000..76c72d3f1902
--- /dev/null
+++ b/include/trace/events/intel-sst.h
@@ -0,0 +1,148 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM intel-sst
3
4#if !defined(_TRACE_INTEL_SST_H) || defined(TRACE_HEADER_MULTI_READ)
5#define _TRACE_INTEL_SST_H
6
7#include <linux/types.h>
8#include <linux/ktime.h>
9#include <linux/tracepoint.h>
10
11DECLARE_EVENT_CLASS(sst_ipc_msg,
12
13 TP_PROTO(unsigned int val),
14
15 TP_ARGS(val),
16
17 TP_STRUCT__entry(
18 __field( unsigned int, val )
19 ),
20
21 TP_fast_assign(
22 __entry->val = val;
23 ),
24
25 TP_printk("0x%8.8x", (unsigned int)__entry->val)
26);
27
28DEFINE_EVENT(sst_ipc_msg, sst_ipc_msg_tx,
29
30 TP_PROTO(unsigned int val),
31
32 TP_ARGS(val)
33
34);
35
36DEFINE_EVENT(sst_ipc_msg, sst_ipc_msg_rx,
37
38 TP_PROTO(unsigned int val),
39
40 TP_ARGS(val)
41
42);
43
44DECLARE_EVENT_CLASS(sst_ipc_mailbox,
45
46 TP_PROTO(unsigned int offset, unsigned int val),
47
48 TP_ARGS(offset, val),
49
50 TP_STRUCT__entry(
51 __field( unsigned int, offset )
52 __field( unsigned int, val )
53 ),
54
55 TP_fast_assign(
56 __entry->offset = offset;
57 __entry->val = val;
58 ),
59
60 TP_printk(" 0x%4.4x = 0x%8.8x",
61 (unsigned int)__entry->offset, (unsigned int)__entry->val)
62);
63
64DEFINE_EVENT(sst_ipc_mailbox, sst_ipc_inbox_rdata,
65
66 TP_PROTO(unsigned int offset, unsigned int val),
67
68 TP_ARGS(offset, val)
69
70);
71
72DEFINE_EVENT(sst_ipc_mailbox, sst_ipc_inbox_wdata,
73
74 TP_PROTO(unsigned int offset, unsigned int val),
75
76 TP_ARGS(offset, val)
77
78);
79
80DEFINE_EVENT(sst_ipc_mailbox, sst_ipc_outbox_rdata,
81
82 TP_PROTO(unsigned int offset, unsigned int val),
83
84 TP_ARGS(offset, val)
85
86);
87
88DEFINE_EVENT(sst_ipc_mailbox, sst_ipc_outbox_wdata,
89
90 TP_PROTO(unsigned int offset, unsigned int val),
91
92 TP_ARGS(offset, val)
93
94);
95
96DECLARE_EVENT_CLASS(sst_ipc_mailbox_info,
97
98 TP_PROTO(unsigned int size),
99
100 TP_ARGS(size),
101
102 TP_STRUCT__entry(
103 __field( unsigned int, size )
104 ),
105
106 TP_fast_assign(
107 __entry->size = size;
108 ),
109
110 TP_printk("Mailbox bytes 0x%8.8x", (unsigned int)__entry->size)
111);
112
113DEFINE_EVENT(sst_ipc_mailbox_info, sst_ipc_inbox_read,
114
115 TP_PROTO(unsigned int size),
116
117 TP_ARGS(size)
118
119);
120
121DEFINE_EVENT(sst_ipc_mailbox_info, sst_ipc_inbox_write,
122
123 TP_PROTO(unsigned int size),
124
125 TP_ARGS(size)
126
127);
128
129DEFINE_EVENT(sst_ipc_mailbox_info, sst_ipc_outbox_read,
130
131 TP_PROTO(unsigned int size),
132
133 TP_ARGS(size)
134
135);
136
137DEFINE_EVENT(sst_ipc_mailbox_info, sst_ipc_outbox_write,
138
139 TP_PROTO(unsigned int size),
140
141 TP_ARGS(size)
142
143);
144
145#endif /* _TRACE_SST_H */
146
147/* This part must be outside protection */
148#include <trace/define_trace.h>
diff --git a/init/main.c b/init/main.c
index eb03090cdced..9c7fd4c9249f 100644
--- a/init/main.c
+++ b/init/main.c
@@ -561,7 +561,6 @@ asmlinkage void __init start_kernel(void)
561 init_timers(); 561 init_timers();
562 hrtimers_init(); 562 hrtimers_init();
563 softirq_init(); 563 softirq_init();
564 acpi_early_init();
565 timekeeping_init(); 564 timekeeping_init();
566 time_init(); 565 time_init();
567 sched_clock_postinit(); 566 sched_clock_postinit();
@@ -613,6 +612,7 @@ asmlinkage void __init start_kernel(void)
613 calibrate_delay(); 612 calibrate_delay();
614 pidmap_init(); 613 pidmap_init();
615 anon_vma_init(); 614 anon_vma_init();
615 acpi_early_init();
616#ifdef CONFIG_X86 616#ifdef CONFIG_X86
617 if (efi_enabled(EFI_RUNTIME_SERVICES)) 617 if (efi_enabled(EFI_RUNTIME_SERVICES))
618 efi_enter_virtual_mode(); 618 efi_enter_virtual_mode();
diff --git a/ipc/msg.c b/ipc/msg.c
index 245db1140ad6..649853105a5d 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -901,6 +901,8 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp, int msgfl
901 return -EINVAL; 901 return -EINVAL;
902 902
903 if (msgflg & MSG_COPY) { 903 if (msgflg & MSG_COPY) {
904 if ((msgflg & MSG_EXCEPT) || !(msgflg & IPC_NOWAIT))
905 return -EINVAL;
904 copy = prepare_copy(buf, min_t(size_t, bufsz, ns->msg_ctlmax)); 906 copy = prepare_copy(buf, min_t(size_t, bufsz, ns->msg_ctlmax));
905 if (IS_ERR(copy)) 907 if (IS_ERR(copy))
906 return PTR_ERR(copy); 908 return PTR_ERR(copy);
diff --git a/kernel/audit.c b/kernel/audit.c
index 34c5a2310fbf..3392d3e0254a 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -182,7 +182,7 @@ struct audit_buffer {
182 182
183struct audit_reply { 183struct audit_reply {
184 __u32 portid; 184 __u32 portid;
185 pid_t pid; 185 struct net *net;
186 struct sk_buff *skb; 186 struct sk_buff *skb;
187}; 187};
188 188
@@ -500,7 +500,7 @@ int audit_send_list(void *_dest)
500{ 500{
501 struct audit_netlink_list *dest = _dest; 501 struct audit_netlink_list *dest = _dest;
502 struct sk_buff *skb; 502 struct sk_buff *skb;
503 struct net *net = get_net_ns_by_pid(dest->pid); 503 struct net *net = dest->net;
504 struct audit_net *aunet = net_generic(net, audit_net_id); 504 struct audit_net *aunet = net_generic(net, audit_net_id);
505 505
506 /* wait for parent to finish and send an ACK */ 506 /* wait for parent to finish and send an ACK */
@@ -510,6 +510,7 @@ int audit_send_list(void *_dest)
510 while ((skb = __skb_dequeue(&dest->q)) != NULL) 510 while ((skb = __skb_dequeue(&dest->q)) != NULL)
511 netlink_unicast(aunet->nlsk, skb, dest->portid, 0); 511 netlink_unicast(aunet->nlsk, skb, dest->portid, 0);
512 512
513 put_net(net);
513 kfree(dest); 514 kfree(dest);
514 515
515 return 0; 516 return 0;
@@ -543,7 +544,7 @@ out_kfree_skb:
543static int audit_send_reply_thread(void *arg) 544static int audit_send_reply_thread(void *arg)
544{ 545{
545 struct audit_reply *reply = (struct audit_reply *)arg; 546 struct audit_reply *reply = (struct audit_reply *)arg;
546 struct net *net = get_net_ns_by_pid(reply->pid); 547 struct net *net = reply->net;
547 struct audit_net *aunet = net_generic(net, audit_net_id); 548 struct audit_net *aunet = net_generic(net, audit_net_id);
548 549
549 mutex_lock(&audit_cmd_mutex); 550 mutex_lock(&audit_cmd_mutex);
@@ -552,12 +553,13 @@ static int audit_send_reply_thread(void *arg)
552 /* Ignore failure. It'll only happen if the sender goes away, 553 /* Ignore failure. It'll only happen if the sender goes away,
553 because our timeout is set to infinite. */ 554 because our timeout is set to infinite. */
554 netlink_unicast(aunet->nlsk , reply->skb, reply->portid, 0); 555 netlink_unicast(aunet->nlsk , reply->skb, reply->portid, 0);
556 put_net(net);
555 kfree(reply); 557 kfree(reply);
556 return 0; 558 return 0;
557} 559}
558/** 560/**
559 * audit_send_reply - send an audit reply message via netlink 561 * audit_send_reply - send an audit reply message via netlink
560 * @portid: netlink port to which to send reply 562 * @request_skb: skb of request we are replying to (used to target the reply)
561 * @seq: sequence number 563 * @seq: sequence number
562 * @type: audit message type 564 * @type: audit message type
563 * @done: done (last) flag 565 * @done: done (last) flag
@@ -568,9 +570,11 @@ static int audit_send_reply_thread(void *arg)
568 * Allocates an skb, builds the netlink message, and sends it to the port id. 570 * Allocates an skb, builds the netlink message, and sends it to the port id.
569 * No failure notifications. 571 * No failure notifications.
570 */ 572 */
571static void audit_send_reply(__u32 portid, int seq, int type, int done, 573static void audit_send_reply(struct sk_buff *request_skb, int seq, int type, int done,
572 int multi, const void *payload, int size) 574 int multi, const void *payload, int size)
573{ 575{
576 u32 portid = NETLINK_CB(request_skb).portid;
577 struct net *net = sock_net(NETLINK_CB(request_skb).sk);
574 struct sk_buff *skb; 578 struct sk_buff *skb;
575 struct task_struct *tsk; 579 struct task_struct *tsk;
576 struct audit_reply *reply = kmalloc(sizeof(struct audit_reply), 580 struct audit_reply *reply = kmalloc(sizeof(struct audit_reply),
@@ -583,8 +587,8 @@ static void audit_send_reply(__u32 portid, int seq, int type, int done,
583 if (!skb) 587 if (!skb)
584 goto out; 588 goto out;
585 589
590 reply->net = get_net(net);
586 reply->portid = portid; 591 reply->portid = portid;
587 reply->pid = task_pid_vnr(current);
588 reply->skb = skb; 592 reply->skb = skb;
589 593
590 tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply"); 594 tsk = kthread_run(audit_send_reply_thread, reply, "audit_send_reply");
@@ -673,8 +677,7 @@ static int audit_get_feature(struct sk_buff *skb)
673 677
674 seq = nlmsg_hdr(skb)->nlmsg_seq; 678 seq = nlmsg_hdr(skb)->nlmsg_seq;
675 679
676 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0, 680 audit_send_reply(skb, seq, AUDIT_GET, 0, 0, &af, sizeof(af));
677 &af, sizeof(af));
678 681
679 return 0; 682 return 0;
680} 683}
@@ -794,8 +797,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
794 s.backlog = skb_queue_len(&audit_skb_queue); 797 s.backlog = skb_queue_len(&audit_skb_queue);
795 s.version = AUDIT_VERSION_LATEST; 798 s.version = AUDIT_VERSION_LATEST;
796 s.backlog_wait_time = audit_backlog_wait_time; 799 s.backlog_wait_time = audit_backlog_wait_time;
797 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0, 800 audit_send_reply(skb, seq, AUDIT_GET, 0, 0, &s, sizeof(s));
798 &s, sizeof(s));
799 break; 801 break;
800 } 802 }
801 case AUDIT_SET: { 803 case AUDIT_SET: {
@@ -905,7 +907,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
905 seq, data, nlmsg_len(nlh)); 907 seq, data, nlmsg_len(nlh));
906 break; 908 break;
907 case AUDIT_LIST_RULES: 909 case AUDIT_LIST_RULES:
908 err = audit_list_rules_send(NETLINK_CB(skb).portid, seq); 910 err = audit_list_rules_send(skb, seq);
909 break; 911 break;
910 case AUDIT_TRIM: 912 case AUDIT_TRIM:
911 audit_trim_trees(); 913 audit_trim_trees();
@@ -970,8 +972,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
970 memcpy(sig_data->ctx, ctx, len); 972 memcpy(sig_data->ctx, ctx, len);
971 security_release_secctx(ctx, len); 973 security_release_secctx(ctx, len);
972 } 974 }
973 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_SIGNAL_INFO, 975 audit_send_reply(skb, seq, AUDIT_SIGNAL_INFO, 0, 0,
974 0, 0, sig_data, sizeof(*sig_data) + len); 976 sig_data, sizeof(*sig_data) + len);
975 kfree(sig_data); 977 kfree(sig_data);
976 break; 978 break;
977 case AUDIT_TTY_GET: { 979 case AUDIT_TTY_GET: {
@@ -983,8 +985,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
983 s.log_passwd = tsk->signal->audit_tty_log_passwd; 985 s.log_passwd = tsk->signal->audit_tty_log_passwd;
984 spin_unlock(&tsk->sighand->siglock); 986 spin_unlock(&tsk->sighand->siglock);
985 987
986 audit_send_reply(NETLINK_CB(skb).portid, seq, 988 audit_send_reply(skb, seq, AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
987 AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
988 break; 989 break;
989 } 990 }
990 case AUDIT_TTY_SET: { 991 case AUDIT_TTY_SET: {
diff --git a/kernel/audit.h b/kernel/audit.h
index 57cc64d67718..8df132214606 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -247,7 +247,7 @@ extern void audit_panic(const char *message);
247 247
248struct audit_netlink_list { 248struct audit_netlink_list {
249 __u32 portid; 249 __u32 portid;
250 pid_t pid; 250 struct net *net;
251 struct sk_buff_head q; 251 struct sk_buff_head q;
252}; 252};
253 253
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index 14a78cca384e..92062fd6cc8c 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -29,6 +29,8 @@
29#include <linux/sched.h> 29#include <linux/sched.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/security.h> 31#include <linux/security.h>
32#include <net/net_namespace.h>
33#include <net/sock.h>
32#include "audit.h" 34#include "audit.h"
33 35
34/* 36/*
@@ -1065,11 +1067,13 @@ int audit_rule_change(int type, __u32 portid, int seq, void *data,
1065 1067
1066/** 1068/**
1067 * audit_list_rules_send - list the audit rules 1069 * audit_list_rules_send - list the audit rules
1068 * @portid: target portid for netlink audit messages 1070 * @request_skb: skb of request we are replying to (used to target the reply)
1069 * @seq: netlink audit message sequence (serial) number 1071 * @seq: netlink audit message sequence (serial) number
1070 */ 1072 */
1071int audit_list_rules_send(__u32 portid, int seq) 1073int audit_list_rules_send(struct sk_buff *request_skb, int seq)
1072{ 1074{
1075 u32 portid = NETLINK_CB(request_skb).portid;
1076 struct net *net = sock_net(NETLINK_CB(request_skb).sk);
1073 struct task_struct *tsk; 1077 struct task_struct *tsk;
1074 struct audit_netlink_list *dest; 1078 struct audit_netlink_list *dest;
1075 int err = 0; 1079 int err = 0;
@@ -1083,8 +1087,8 @@ int audit_list_rules_send(__u32 portid, int seq)
1083 dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL); 1087 dest = kmalloc(sizeof(struct audit_netlink_list), GFP_KERNEL);
1084 if (!dest) 1088 if (!dest)
1085 return -ENOMEM; 1089 return -ENOMEM;
1090 dest->net = get_net(net);
1086 dest->portid = portid; 1091 dest->portid = portid;
1087 dest->pid = task_pid_vnr(current);
1088 skb_queue_head_init(&dest->q); 1092 skb_queue_head_init(&dest->q);
1089 1093
1090 mutex_lock(&audit_filter_mutex); 1094 mutex_lock(&audit_filter_mutex);
diff --git a/kernel/profile.c b/kernel/profile.c
index 6631e1ef55ab..ebdd9c1a86b4 100644
--- a/kernel/profile.c
+++ b/kernel/profile.c
@@ -549,14 +549,14 @@ static int create_hash_tables(void)
549 struct page *page; 549 struct page *page;
550 550
551 page = alloc_pages_exact_node(node, 551 page = alloc_pages_exact_node(node,
552 GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, 552 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
553 0); 553 0);
554 if (!page) 554 if (!page)
555 goto out_cleanup; 555 goto out_cleanup;
556 per_cpu(cpu_profile_hits, cpu)[1] 556 per_cpu(cpu_profile_hits, cpu)[1]
557 = (struct profile_hit *)page_address(page); 557 = (struct profile_hit *)page_address(page);
558 page = alloc_pages_exact_node(node, 558 page = alloc_pages_exact_node(node,
559 GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, 559 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
560 0); 560 0);
561 if (!page) 561 if (!page)
562 goto out_cleanup; 562 goto out_cleanup;
diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c
index 43c2bcc35761..b30a2924ef14 100644
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -301,14 +301,14 @@ u64 sched_clock_cpu(int cpu)
301 if (unlikely(!sched_clock_running)) 301 if (unlikely(!sched_clock_running))
302 return 0ull; 302 return 0ull;
303 303
304 preempt_disable(); 304 preempt_disable_notrace();
305 scd = cpu_sdc(cpu); 305 scd = cpu_sdc(cpu);
306 306
307 if (cpu != smp_processor_id()) 307 if (cpu != smp_processor_id())
308 clock = sched_clock_remote(scd); 308 clock = sched_clock_remote(scd);
309 else 309 else
310 clock = sched_clock_local(scd); 310 clock = sched_clock_local(scd);
311 preempt_enable(); 311 preempt_enable_notrace();
312 312
313 return clock; 313 return clock;
314} 314}
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 6edbef296ece..f5c6635b806c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3338,6 +3338,15 @@ recheck:
3338 return -EPERM; 3338 return -EPERM;
3339 } 3339 }
3340 3340
3341 /*
3342 * Can't set/change SCHED_DEADLINE policy at all for now
3343 * (safest behavior); in the future we would like to allow
3344 * unprivileged DL tasks to increase their relative deadline
3345 * or reduce their runtime (both ways reducing utilization)
3346 */
3347 if (dl_policy(policy))
3348 return -EPERM;
3349
3341 /* 3350 /*
3342 * Treat SCHED_IDLE as nice 20. Only allow a switch to 3351 * Treat SCHED_IDLE as nice 20. Only allow a switch to
3343 * SCHED_NORMAL if the RLIMIT_NICE would normally permit it. 3352 * SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index 84571e09c907..01fbae5b97b7 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -293,7 +293,7 @@ int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void *
293 */ 293 */
294 smp_call_function_single(min(cpu1, cpu2), 294 smp_call_function_single(min(cpu1, cpu2),
295 &irq_cpu_stop_queue_work, 295 &irq_cpu_stop_queue_work,
296 &call_args, 0); 296 &call_args, 1);
297 lg_local_unlock(&stop_cpus_lock); 297 lg_local_unlock(&stop_cpus_lock);
298 preempt_enable(); 298 preempt_enable();
299 299
diff --git a/mm/Kconfig b/mm/Kconfig
index 2d9f1504d75e..2888024e0b0a 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -575,5 +575,5 @@ config PGTABLE_MAPPING
575 then you should select this. This causes zsmalloc to use page table 575 then you should select this. This causes zsmalloc to use page table
576 mapping rather than copying for object mapping. 576 mapping rather than copying for object mapping.
577 577
578 You can check speed with zsmalloc benchmark[1]. 578 You can check speed with zsmalloc benchmark:
579 [1] https://github.com/spartacus06/zsmalloc 579 https://github.com/spartacus06/zsmapbench
diff --git a/mm/compaction.c b/mm/compaction.c
index b48c5259ea33..918577595ea8 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -251,7 +251,6 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
251{ 251{
252 int nr_scanned = 0, total_isolated = 0; 252 int nr_scanned = 0, total_isolated = 0;
253 struct page *cursor, *valid_page = NULL; 253 struct page *cursor, *valid_page = NULL;
254 unsigned long nr_strict_required = end_pfn - blockpfn;
255 unsigned long flags; 254 unsigned long flags;
256 bool locked = false; 255 bool locked = false;
257 256
@@ -264,11 +263,12 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
264 263
265 nr_scanned++; 264 nr_scanned++;
266 if (!pfn_valid_within(blockpfn)) 265 if (!pfn_valid_within(blockpfn))
267 continue; 266 goto isolate_fail;
267
268 if (!valid_page) 268 if (!valid_page)
269 valid_page = page; 269 valid_page = page;
270 if (!PageBuddy(page)) 270 if (!PageBuddy(page))
271 continue; 271 goto isolate_fail;
272 272
273 /* 273 /*
274 * The zone lock must be held to isolate freepages. 274 * The zone lock must be held to isolate freepages.
@@ -289,12 +289,10 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
289 289
290 /* Recheck this is a buddy page under lock */ 290 /* Recheck this is a buddy page under lock */
291 if (!PageBuddy(page)) 291 if (!PageBuddy(page))
292 continue; 292 goto isolate_fail;
293 293
294 /* Found a free page, break it into order-0 pages */ 294 /* Found a free page, break it into order-0 pages */
295 isolated = split_free_page(page); 295 isolated = split_free_page(page);
296 if (!isolated && strict)
297 break;
298 total_isolated += isolated; 296 total_isolated += isolated;
299 for (i = 0; i < isolated; i++) { 297 for (i = 0; i < isolated; i++) {
300 list_add(&page->lru, freelist); 298 list_add(&page->lru, freelist);
@@ -305,7 +303,15 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
305 if (isolated) { 303 if (isolated) {
306 blockpfn += isolated - 1; 304 blockpfn += isolated - 1;
307 cursor += isolated - 1; 305 cursor += isolated - 1;
306 continue;
308 } 307 }
308
309isolate_fail:
310 if (strict)
311 break;
312 else
313 continue;
314
309 } 315 }
310 316
311 trace_mm_compaction_isolate_freepages(nr_scanned, total_isolated); 317 trace_mm_compaction_isolate_freepages(nr_scanned, total_isolated);
@@ -315,7 +321,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
315 * pages requested were isolated. If there were any failures, 0 is 321 * pages requested were isolated. If there were any failures, 0 is
316 * returned and CMA will fail. 322 * returned and CMA will fail.
317 */ 323 */
318 if (strict && nr_strict_required > total_isolated) 324 if (strict && blockpfn < end_pfn)
319 total_isolated = 0; 325 total_isolated = 0;
320 326
321 if (locked) 327 if (locked)
diff --git a/mm/migrate.c b/mm/migrate.c
index 482a33d89134..b494fdb9a636 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1158,7 +1158,7 @@ static struct page *new_page_node(struct page *p, unsigned long private,
1158 pm->node); 1158 pm->node);
1159 else 1159 else
1160 return alloc_pages_exact_node(pm->node, 1160 return alloc_pages_exact_node(pm->node,
1161 GFP_HIGHUSER_MOVABLE | GFP_THISNODE, 0); 1161 GFP_HIGHUSER_MOVABLE | __GFP_THISNODE, 0);
1162} 1162}
1163 1163
1164/* 1164/*
@@ -1544,9 +1544,9 @@ static struct page *alloc_misplaced_dst_page(struct page *page,
1544 struct page *newpage; 1544 struct page *newpage;
1545 1545
1546 newpage = alloc_pages_exact_node(nid, 1546 newpage = alloc_pages_exact_node(nid,
1547 (GFP_HIGHUSER_MOVABLE | GFP_THISNODE | 1547 (GFP_HIGHUSER_MOVABLE |
1548 __GFP_NOMEMALLOC | __GFP_NORETRY | 1548 __GFP_THISNODE | __GFP_NOMEMALLOC |
1549 __GFP_NOWARN) & 1549 __GFP_NORETRY | __GFP_NOWARN) &
1550 ~GFP_IOFS, 0); 1550 ~GFP_IOFS, 0);
1551 1551
1552 return newpage; 1552 return newpage;
@@ -1747,7 +1747,8 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
1747 goto out_dropref; 1747 goto out_dropref;
1748 1748
1749 new_page = alloc_pages_node(node, 1749 new_page = alloc_pages_node(node,
1750 (GFP_TRANSHUGE | GFP_THISNODE) & ~__GFP_WAIT, HPAGE_PMD_ORDER); 1750 (GFP_TRANSHUGE | __GFP_THISNODE) & ~__GFP_WAIT,
1751 HPAGE_PMD_ORDER);
1751 if (!new_page) 1752 if (!new_page)
1752 goto out_fail; 1753 goto out_fail;
1753 1754
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index de51c48c4393..4b65aa492fb6 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -538,6 +538,9 @@ static int vlan_passthru_hard_header(struct sk_buff *skb, struct net_device *dev
538 struct vlan_dev_priv *vlan = vlan_dev_priv(dev); 538 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
539 struct net_device *real_dev = vlan->real_dev; 539 struct net_device *real_dev = vlan->real_dev;
540 540
541 if (saddr == NULL)
542 saddr = dev->dev_addr;
543
541 return dev_hard_header(skb, real_dev, type, daddr, saddr, len); 544 return dev_hard_header(skb, real_dev, type, daddr, saddr, len);
542} 545}
543 546
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index ef66365b7354..93067ecdb9a2 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -1127,9 +1127,10 @@ static void br_multicast_query_received(struct net_bridge *br,
1127 struct net_bridge_port *port, 1127 struct net_bridge_port *port,
1128 struct bridge_mcast_querier *querier, 1128 struct bridge_mcast_querier *querier,
1129 int saddr, 1129 int saddr,
1130 bool is_general_query,
1130 unsigned long max_delay) 1131 unsigned long max_delay)
1131{ 1132{
1132 if (saddr) 1133 if (saddr && is_general_query)
1133 br_multicast_update_querier_timer(br, querier, max_delay); 1134 br_multicast_update_querier_timer(br, querier, max_delay);
1134 else if (timer_pending(&querier->timer)) 1135 else if (timer_pending(&querier->timer))
1135 return; 1136 return;
@@ -1181,8 +1182,16 @@ static int br_ip4_multicast_query(struct net_bridge *br,
1181 IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1; 1182 IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1;
1182 } 1183 }
1183 1184
1185 /* RFC2236+RFC3376 (IGMPv2+IGMPv3) require the multicast link layer
1186 * all-systems destination addresses (224.0.0.1) for general queries
1187 */
1188 if (!group && iph->daddr != htonl(INADDR_ALLHOSTS_GROUP)) {
1189 err = -EINVAL;
1190 goto out;
1191 }
1192
1184 br_multicast_query_received(br, port, &br->ip4_querier, !!iph->saddr, 1193 br_multicast_query_received(br, port, &br->ip4_querier, !!iph->saddr,
1185 max_delay); 1194 !group, max_delay);
1186 1195
1187 if (!group) 1196 if (!group)
1188 goto out; 1197 goto out;
@@ -1228,6 +1237,7 @@ static int br_ip6_multicast_query(struct net_bridge *br,
1228 unsigned long max_delay; 1237 unsigned long max_delay;
1229 unsigned long now = jiffies; 1238 unsigned long now = jiffies;
1230 const struct in6_addr *group = NULL; 1239 const struct in6_addr *group = NULL;
1240 bool is_general_query;
1231 int err = 0; 1241 int err = 0;
1232 1242
1233 spin_lock(&br->multicast_lock); 1243 spin_lock(&br->multicast_lock);
@@ -1235,6 +1245,12 @@ static int br_ip6_multicast_query(struct net_bridge *br,
1235 (port && port->state == BR_STATE_DISABLED)) 1245 (port && port->state == BR_STATE_DISABLED))
1236 goto out; 1246 goto out;
1237 1247
1248 /* RFC2710+RFC3810 (MLDv1+MLDv2) require link-local source addresses */
1249 if (!(ipv6_addr_type(&ip6h->saddr) & IPV6_ADDR_LINKLOCAL)) {
1250 err = -EINVAL;
1251 goto out;
1252 }
1253
1238 if (skb->len == sizeof(*mld)) { 1254 if (skb->len == sizeof(*mld)) {
1239 if (!pskb_may_pull(skb, sizeof(*mld))) { 1255 if (!pskb_may_pull(skb, sizeof(*mld))) {
1240 err = -EINVAL; 1256 err = -EINVAL;
@@ -1256,8 +1272,19 @@ static int br_ip6_multicast_query(struct net_bridge *br,
1256 max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL); 1272 max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL);
1257 } 1273 }
1258 1274
1275 is_general_query = group && ipv6_addr_any(group);
1276
1277 /* RFC2710+RFC3810 (MLDv1+MLDv2) require the multicast link layer
1278 * all-nodes destination address (ff02::1) for general queries
1279 */
1280 if (is_general_query && !ipv6_addr_is_ll_all_nodes(&ip6h->daddr)) {
1281 err = -EINVAL;
1282 goto out;
1283 }
1284
1259 br_multicast_query_received(br, port, &br->ip6_querier, 1285 br_multicast_query_received(br, port, &br->ip6_querier,
1260 !ipv6_addr_any(&ip6h->saddr), max_delay); 1286 !ipv6_addr_any(&ip6h->saddr),
1287 is_general_query, max_delay);
1261 1288
1262 if (!group) 1289 if (!group)
1263 goto out; 1290 goto out;
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 5d6236d9fdce..869c7afe3b07 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -2838,81 +2838,84 @@ EXPORT_SYMBOL_GPL(skb_pull_rcsum);
2838 2838
2839/** 2839/**
2840 * skb_segment - Perform protocol segmentation on skb. 2840 * skb_segment - Perform protocol segmentation on skb.
2841 * @skb: buffer to segment 2841 * @head_skb: buffer to segment
2842 * @features: features for the output path (see dev->features) 2842 * @features: features for the output path (see dev->features)
2843 * 2843 *
2844 * This function performs segmentation on the given skb. It returns 2844 * This function performs segmentation on the given skb. It returns
2845 * a pointer to the first in a list of new skbs for the segments. 2845 * a pointer to the first in a list of new skbs for the segments.
2846 * In case of error it returns ERR_PTR(err). 2846 * In case of error it returns ERR_PTR(err).
2847 */ 2847 */
2848struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features) 2848struct sk_buff *skb_segment(struct sk_buff *head_skb,
2849 netdev_features_t features)
2849{ 2850{
2850 struct sk_buff *segs = NULL; 2851 struct sk_buff *segs = NULL;
2851 struct sk_buff *tail = NULL; 2852 struct sk_buff *tail = NULL;
2852 struct sk_buff *fskb = skb_shinfo(skb)->frag_list; 2853 struct sk_buff *list_skb = skb_shinfo(head_skb)->frag_list;
2853 skb_frag_t *skb_frag = skb_shinfo(skb)->frags; 2854 skb_frag_t *frag = skb_shinfo(head_skb)->frags;
2854 unsigned int mss = skb_shinfo(skb)->gso_size; 2855 unsigned int mss = skb_shinfo(head_skb)->gso_size;
2855 unsigned int doffset = skb->data - skb_mac_header(skb); 2856 unsigned int doffset = head_skb->data - skb_mac_header(head_skb);
2857 struct sk_buff *frag_skb = head_skb;
2856 unsigned int offset = doffset; 2858 unsigned int offset = doffset;
2857 unsigned int tnl_hlen = skb_tnl_header_len(skb); 2859 unsigned int tnl_hlen = skb_tnl_header_len(head_skb);
2858 unsigned int headroom; 2860 unsigned int headroom;
2859 unsigned int len; 2861 unsigned int len;
2860 __be16 proto; 2862 __be16 proto;
2861 bool csum; 2863 bool csum;
2862 int sg = !!(features & NETIF_F_SG); 2864 int sg = !!(features & NETIF_F_SG);
2863 int nfrags = skb_shinfo(skb)->nr_frags; 2865 int nfrags = skb_shinfo(head_skb)->nr_frags;
2864 int err = -ENOMEM; 2866 int err = -ENOMEM;
2865 int i = 0; 2867 int i = 0;
2866 int pos; 2868 int pos;
2867 2869
2868 proto = skb_network_protocol(skb); 2870 proto = skb_network_protocol(head_skb);
2869 if (unlikely(!proto)) 2871 if (unlikely(!proto))
2870 return ERR_PTR(-EINVAL); 2872 return ERR_PTR(-EINVAL);
2871 2873
2872 csum = !!can_checksum_protocol(features, proto); 2874 csum = !!can_checksum_protocol(features, proto);
2873 __skb_push(skb, doffset); 2875 __skb_push(head_skb, doffset);
2874 headroom = skb_headroom(skb); 2876 headroom = skb_headroom(head_skb);
2875 pos = skb_headlen(skb); 2877 pos = skb_headlen(head_skb);
2876 2878
2877 do { 2879 do {
2878 struct sk_buff *nskb; 2880 struct sk_buff *nskb;
2879 skb_frag_t *frag; 2881 skb_frag_t *nskb_frag;
2880 int hsize; 2882 int hsize;
2881 int size; 2883 int size;
2882 2884
2883 len = skb->len - offset; 2885 len = head_skb->len - offset;
2884 if (len > mss) 2886 if (len > mss)
2885 len = mss; 2887 len = mss;
2886 2888
2887 hsize = skb_headlen(skb) - offset; 2889 hsize = skb_headlen(head_skb) - offset;
2888 if (hsize < 0) 2890 if (hsize < 0)
2889 hsize = 0; 2891 hsize = 0;
2890 if (hsize > len || !sg) 2892 if (hsize > len || !sg)
2891 hsize = len; 2893 hsize = len;
2892 2894
2893 if (!hsize && i >= nfrags && skb_headlen(fskb) && 2895 if (!hsize && i >= nfrags && skb_headlen(list_skb) &&
2894 (skb_headlen(fskb) == len || sg)) { 2896 (skb_headlen(list_skb) == len || sg)) {
2895 BUG_ON(skb_headlen(fskb) > len); 2897 BUG_ON(skb_headlen(list_skb) > len);
2896 2898
2897 i = 0; 2899 i = 0;
2898 nfrags = skb_shinfo(fskb)->nr_frags; 2900 nfrags = skb_shinfo(list_skb)->nr_frags;
2899 skb_frag = skb_shinfo(fskb)->frags; 2901 frag = skb_shinfo(list_skb)->frags;
2900 pos += skb_headlen(fskb); 2902 frag_skb = list_skb;
2903 pos += skb_headlen(list_skb);
2901 2904
2902 while (pos < offset + len) { 2905 while (pos < offset + len) {
2903 BUG_ON(i >= nfrags); 2906 BUG_ON(i >= nfrags);
2904 2907
2905 size = skb_frag_size(skb_frag); 2908 size = skb_frag_size(frag);
2906 if (pos + size > offset + len) 2909 if (pos + size > offset + len)
2907 break; 2910 break;
2908 2911
2909 i++; 2912 i++;
2910 pos += size; 2913 pos += size;
2911 skb_frag++; 2914 frag++;
2912 } 2915 }
2913 2916
2914 nskb = skb_clone(fskb, GFP_ATOMIC); 2917 nskb = skb_clone(list_skb, GFP_ATOMIC);
2915 fskb = fskb->next; 2918 list_skb = list_skb->next;
2916 2919
2917 if (unlikely(!nskb)) 2920 if (unlikely(!nskb))
2918 goto err; 2921 goto err;
@@ -2933,7 +2936,7 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
2933 __skb_push(nskb, doffset); 2936 __skb_push(nskb, doffset);
2934 } else { 2937 } else {
2935 nskb = __alloc_skb(hsize + doffset + headroom, 2938 nskb = __alloc_skb(hsize + doffset + headroom,
2936 GFP_ATOMIC, skb_alloc_rx_flag(skb), 2939 GFP_ATOMIC, skb_alloc_rx_flag(head_skb),
2937 NUMA_NO_NODE); 2940 NUMA_NO_NODE);
2938 2941
2939 if (unlikely(!nskb)) 2942 if (unlikely(!nskb))
@@ -2949,12 +2952,12 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
2949 segs = nskb; 2952 segs = nskb;
2950 tail = nskb; 2953 tail = nskb;
2951 2954
2952 __copy_skb_header(nskb, skb); 2955 __copy_skb_header(nskb, head_skb);
2953 nskb->mac_len = skb->mac_len; 2956 nskb->mac_len = head_skb->mac_len;
2954 2957
2955 skb_headers_offset_update(nskb, skb_headroom(nskb) - headroom); 2958 skb_headers_offset_update(nskb, skb_headroom(nskb) - headroom);
2956 2959
2957 skb_copy_from_linear_data_offset(skb, -tnl_hlen, 2960 skb_copy_from_linear_data_offset(head_skb, -tnl_hlen,
2958 nskb->data - tnl_hlen, 2961 nskb->data - tnl_hlen,
2959 doffset + tnl_hlen); 2962 doffset + tnl_hlen);
2960 2963
@@ -2963,30 +2966,32 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
2963 2966
2964 if (!sg) { 2967 if (!sg) {
2965 nskb->ip_summed = CHECKSUM_NONE; 2968 nskb->ip_summed = CHECKSUM_NONE;
2966 nskb->csum = skb_copy_and_csum_bits(skb, offset, 2969 nskb->csum = skb_copy_and_csum_bits(head_skb, offset,
2967 skb_put(nskb, len), 2970 skb_put(nskb, len),
2968 len, 0); 2971 len, 0);
2969 continue; 2972 continue;
2970 } 2973 }
2971 2974
2972 frag = skb_shinfo(nskb)->frags; 2975 nskb_frag = skb_shinfo(nskb)->frags;
2973 2976
2974 skb_copy_from_linear_data_offset(skb, offset, 2977 skb_copy_from_linear_data_offset(head_skb, offset,
2975 skb_put(nskb, hsize), hsize); 2978 skb_put(nskb, hsize), hsize);
2976 2979
2977 skb_shinfo(nskb)->tx_flags = skb_shinfo(skb)->tx_flags & SKBTX_SHARED_FRAG; 2980 skb_shinfo(nskb)->tx_flags = skb_shinfo(head_skb)->tx_flags &
2981 SKBTX_SHARED_FRAG;
2978 2982
2979 while (pos < offset + len) { 2983 while (pos < offset + len) {
2980 if (i >= nfrags) { 2984 if (i >= nfrags) {
2981 BUG_ON(skb_headlen(fskb)); 2985 BUG_ON(skb_headlen(list_skb));
2982 2986
2983 i = 0; 2987 i = 0;
2984 nfrags = skb_shinfo(fskb)->nr_frags; 2988 nfrags = skb_shinfo(list_skb)->nr_frags;
2985 skb_frag = skb_shinfo(fskb)->frags; 2989 frag = skb_shinfo(list_skb)->frags;
2990 frag_skb = list_skb;
2986 2991
2987 BUG_ON(!nfrags); 2992 BUG_ON(!nfrags);
2988 2993
2989 fskb = fskb->next; 2994 list_skb = list_skb->next;
2990 } 2995 }
2991 2996
2992 if (unlikely(skb_shinfo(nskb)->nr_frags >= 2997 if (unlikely(skb_shinfo(nskb)->nr_frags >=
@@ -2997,27 +3002,30 @@ struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features)
2997 goto err; 3002 goto err;
2998 } 3003 }
2999 3004
3000 *frag = *skb_frag; 3005 if (unlikely(skb_orphan_frags(frag_skb, GFP_ATOMIC)))
3001 __skb_frag_ref(frag); 3006 goto err;
3002 size = skb_frag_size(frag); 3007
3008 *nskb_frag = *frag;
3009 __skb_frag_ref(nskb_frag);
3010 size = skb_frag_size(nskb_frag);
3003 3011
3004 if (pos < offset) { 3012 if (pos < offset) {
3005 frag->page_offset += offset - pos; 3013 nskb_frag->page_offset += offset - pos;
3006 skb_frag_size_sub(frag, offset - pos); 3014 skb_frag_size_sub(nskb_frag, offset - pos);
3007 } 3015 }
3008 3016
3009 skb_shinfo(nskb)->nr_frags++; 3017 skb_shinfo(nskb)->nr_frags++;
3010 3018
3011 if (pos + size <= offset + len) { 3019 if (pos + size <= offset + len) {
3012 i++; 3020 i++;
3013 skb_frag++; 3021 frag++;
3014 pos += size; 3022 pos += size;
3015 } else { 3023 } else {
3016 skb_frag_size_sub(frag, pos + size - (offset + len)); 3024 skb_frag_size_sub(nskb_frag, pos + size - (offset + len));
3017 goto skip_fraglist; 3025 goto skip_fraglist;
3018 } 3026 }
3019 3027
3020 frag++; 3028 nskb_frag++;
3021 } 3029 }
3022 3030
3023skip_fraglist: 3031skip_fraglist:
@@ -3031,7 +3039,7 @@ perform_csum_check:
3031 nskb->len - doffset, 0); 3039 nskb->len - doffset, 0);
3032 nskb->ip_summed = CHECKSUM_NONE; 3040 nskb->ip_summed = CHECKSUM_NONE;
3033 } 3041 }
3034 } while ((offset += len) < skb->len); 3042 } while ((offset += len) < head_skb->len);
3035 3043
3036 return segs; 3044 return segs;
3037 3045
diff --git a/net/core/sock.c b/net/core/sock.c
index 5b6a9431b017..c0fc6bdad1e3 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2357,10 +2357,13 @@ void release_sock(struct sock *sk)
2357 if (sk->sk_backlog.tail) 2357 if (sk->sk_backlog.tail)
2358 __release_sock(sk); 2358 __release_sock(sk);
2359 2359
2360 /* Warning : release_cb() might need to release sk ownership,
2361 * ie call sock_release_ownership(sk) before us.
2362 */
2360 if (sk->sk_prot->release_cb) 2363 if (sk->sk_prot->release_cb)
2361 sk->sk_prot->release_cb(sk); 2364 sk->sk_prot->release_cb(sk);
2362 2365
2363 sk->sk_lock.owned = 0; 2366 sock_release_ownership(sk);
2364 if (waitqueue_active(&sk->sk_lock.wq)) 2367 if (waitqueue_active(&sk->sk_lock.wq))
2365 wake_up(&sk->sk_lock.wq); 2368 wake_up(&sk->sk_lock.wq);
2366 spin_unlock_bh(&sk->sk_lock.slock); 2369 spin_unlock_bh(&sk->sk_lock.slock);
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index bb075fc9a14f..3b01959bf4bb 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -208,7 +208,7 @@ int inet_frag_evictor(struct netns_frags *nf, struct inet_frags *f, bool force)
208 } 208 }
209 209
210 work = frag_mem_limit(nf) - nf->low_thresh; 210 work = frag_mem_limit(nf) - nf->low_thresh;
211 while (work > 0) { 211 while (work > 0 || force) {
212 spin_lock(&nf->lru_lock); 212 spin_lock(&nf->lru_lock);
213 213
214 if (list_empty(&nf->lru_list)) { 214 if (list_empty(&nf->lru_list)) {
@@ -278,9 +278,10 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
278 278
279 atomic_inc(&qp->refcnt); 279 atomic_inc(&qp->refcnt);
280 hlist_add_head(&qp->list, &hb->chain); 280 hlist_add_head(&qp->list, &hb->chain);
281 inet_frag_lru_add(nf, qp);
281 spin_unlock(&hb->chain_lock); 282 spin_unlock(&hb->chain_lock);
282 read_unlock(&f->lock); 283 read_unlock(&f->lock);
283 inet_frag_lru_add(nf, qp); 284
284 return qp; 285 return qp;
285} 286}
286 287
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index f0eb4e337ec8..17a11e65e57f 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -767,6 +767,17 @@ void tcp_release_cb(struct sock *sk)
767 if (flags & (1UL << TCP_TSQ_DEFERRED)) 767 if (flags & (1UL << TCP_TSQ_DEFERRED))
768 tcp_tsq_handler(sk); 768 tcp_tsq_handler(sk);
769 769
770 /* Here begins the tricky part :
771 * We are called from release_sock() with :
772 * 1) BH disabled
773 * 2) sk_lock.slock spinlock held
774 * 3) socket owned by us (sk->sk_lock.owned == 1)
775 *
776 * But following code is meant to be called from BH handlers,
777 * so we should keep BH disabled, but early release socket ownership
778 */
779 sock_release_ownership(sk);
780
770 if (flags & (1UL << TCP_WRITE_TIMER_DEFERRED)) { 781 if (flags & (1UL << TCP_WRITE_TIMER_DEFERRED)) {
771 tcp_write_timer_handler(sk); 782 tcp_write_timer_handler(sk);
772 __sock_put(sk); 783 __sock_put(sk);
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index fdbfeca36d63..344e972426df 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1103,8 +1103,11 @@ retry:
1103 * Lifetime is greater than REGEN_ADVANCE time units. In particular, 1103 * Lifetime is greater than REGEN_ADVANCE time units. In particular,
1104 * an implementation must not create a temporary address with a zero 1104 * an implementation must not create a temporary address with a zero
1105 * Preferred Lifetime. 1105 * Preferred Lifetime.
1106 * Use age calculation as in addrconf_verify to avoid unnecessary
1107 * temporary addresses being generated.
1106 */ 1108 */
1107 if (tmp_prefered_lft <= regen_advance) { 1109 age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ;
1110 if (tmp_prefered_lft <= regen_advance + age) {
1108 in6_ifa_put(ifp); 1111 in6_ifa_put(ifp);
1109 in6_dev_put(idev); 1112 in6_dev_put(idev);
1110 ret = -1; 1113 ret = -1;
diff --git a/net/ipv6/exthdrs_offload.c b/net/ipv6/exthdrs_offload.c
index cf77f3abfd06..447a7fbd1bb6 100644
--- a/net/ipv6/exthdrs_offload.c
+++ b/net/ipv6/exthdrs_offload.c
@@ -25,11 +25,11 @@ int __init ipv6_exthdrs_offload_init(void)
25 int ret; 25 int ret;
26 26
27 ret = inet6_add_offload(&rthdr_offload, IPPROTO_ROUTING); 27 ret = inet6_add_offload(&rthdr_offload, IPPROTO_ROUTING);
28 if (!ret) 28 if (ret)
29 goto out; 29 goto out;
30 30
31 ret = inet6_add_offload(&dstopt_offload, IPPROTO_DSTOPTS); 31 ret = inet6_add_offload(&dstopt_offload, IPPROTO_DSTOPTS);
32 if (!ret) 32 if (ret)
33 goto out_rt; 33 goto out_rt;
34 34
35out: 35out:
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 11dac21e6586..fba54a407bb2 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1513,7 +1513,7 @@ int ip6_route_add(struct fib6_config *cfg)
1513 if (!table) 1513 if (!table)
1514 goto out; 1514 goto out;
1515 1515
1516 rt = ip6_dst_alloc(net, NULL, DST_NOCOUNT, table); 1516 rt = ip6_dst_alloc(net, NULL, (cfg->fc_flags & RTF_ADDRCONF) ? 0 : DST_NOCOUNT, table);
1517 1517
1518 if (!rt) { 1518 if (!rt) {
1519 err = -ENOMEM; 1519 err = -ENOMEM;
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index 735d0f60c83a..85d9d94c0a3c 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -112,7 +112,6 @@ struct l2tp_net {
112 spinlock_t l2tp_session_hlist_lock; 112 spinlock_t l2tp_session_hlist_lock;
113}; 113};
114 114
115static void l2tp_session_set_header_len(struct l2tp_session *session, int version);
116static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel); 115static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel);
117 116
118static inline struct l2tp_tunnel *l2tp_tunnel(struct sock *sk) 117static inline struct l2tp_tunnel *l2tp_tunnel(struct sock *sk)
@@ -1863,7 +1862,7 @@ EXPORT_SYMBOL_GPL(l2tp_session_delete);
1863/* We come here whenever a session's send_seq, cookie_len or 1862/* We come here whenever a session's send_seq, cookie_len or
1864 * l2specific_len parameters are set. 1863 * l2specific_len parameters are set.
1865 */ 1864 */
1866static void l2tp_session_set_header_len(struct l2tp_session *session, int version) 1865void l2tp_session_set_header_len(struct l2tp_session *session, int version)
1867{ 1866{
1868 if (version == L2TP_HDR_VER_2) { 1867 if (version == L2TP_HDR_VER_2) {
1869 session->hdr_len = 6; 1868 session->hdr_len = 6;
@@ -1876,6 +1875,7 @@ static void l2tp_session_set_header_len(struct l2tp_session *session, int versio
1876 } 1875 }
1877 1876
1878} 1877}
1878EXPORT_SYMBOL_GPL(l2tp_session_set_header_len);
1879 1879
1880struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg) 1880struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg)
1881{ 1881{
diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
index 1f01ba3435bc..3f93ccd6ba97 100644
--- a/net/l2tp/l2tp_core.h
+++ b/net/l2tp/l2tp_core.h
@@ -263,6 +263,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
263 int length, int (*payload_hook)(struct sk_buff *skb)); 263 int length, int (*payload_hook)(struct sk_buff *skb));
264int l2tp_session_queue_purge(struct l2tp_session *session); 264int l2tp_session_queue_purge(struct l2tp_session *session);
265int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb); 265int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb);
266void l2tp_session_set_header_len(struct l2tp_session *session, int version);
266 267
267int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, 268int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb,
268 int hdr_len); 269 int hdr_len);
diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c
index 4cfd722e9153..bd7387adea9e 100644
--- a/net/l2tp/l2tp_netlink.c
+++ b/net/l2tp/l2tp_netlink.c
@@ -578,8 +578,10 @@ static int l2tp_nl_cmd_session_modify(struct sk_buff *skb, struct genl_info *inf
578 if (info->attrs[L2TP_ATTR_RECV_SEQ]) 578 if (info->attrs[L2TP_ATTR_RECV_SEQ])
579 session->recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]); 579 session->recv_seq = nla_get_u8(info->attrs[L2TP_ATTR_RECV_SEQ]);
580 580
581 if (info->attrs[L2TP_ATTR_SEND_SEQ]) 581 if (info->attrs[L2TP_ATTR_SEND_SEQ]) {
582 session->send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]); 582 session->send_seq = nla_get_u8(info->attrs[L2TP_ATTR_SEND_SEQ]);
583 l2tp_session_set_header_len(session, session->tunnel->version);
584 }
583 585
584 if (info->attrs[L2TP_ATTR_LNS_MODE]) 586 if (info->attrs[L2TP_ATTR_LNS_MODE])
585 session->lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]); 587 session->lns_mode = nla_get_u8(info->attrs[L2TP_ATTR_LNS_MODE]);
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index be5fadf34739..5990919356a5 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -254,12 +254,14 @@ static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int
254 po = pppox_sk(sk); 254 po = pppox_sk(sk);
255 ppp_input(&po->chan, skb); 255 ppp_input(&po->chan, skb);
256 } else { 256 } else {
257 l2tp_info(session, PPPOL2TP_MSG_DATA, "%s: socket not bound\n", 257 l2tp_dbg(session, PPPOL2TP_MSG_DATA,
258 session->name); 258 "%s: recv %d byte data frame, passing to L2TP socket\n",
259 session->name, data_len);
259 260
260 /* Not bound. Nothing we can do, so discard. */ 261 if (sock_queue_rcv_skb(sk, skb) < 0) {
261 atomic_long_inc(&session->stats.rx_errors); 262 atomic_long_inc(&session->stats.rx_errors);
262 kfree_skb(skb); 263 kfree_skb(skb);
264 }
263 } 265 }
264 266
265 return; 267 return;
@@ -1312,6 +1314,7 @@ static int pppol2tp_session_setsockopt(struct sock *sk,
1312 po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ : 1314 po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ :
1313 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ; 1315 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
1314 } 1316 }
1317 l2tp_session_set_header_len(session, session->tunnel->version);
1315 l2tp_info(session, PPPOL2TP_MSG_CONTROL, 1318 l2tp_info(session, PPPOL2TP_MSG_CONTROL,
1316 "%s: set send_seq=%d\n", 1319 "%s: set send_seq=%d\n",
1317 session->name, session->send_seq); 1320 session->name, session->send_seq);
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index f43613a97dd6..0c1ecfdf9a12 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -100,6 +100,12 @@ ieee80211_get_chanctx_max_required_bw(struct ieee80211_local *local,
100 } 100 }
101 max_bw = max(max_bw, width); 101 max_bw = max(max_bw, width);
102 } 102 }
103
104 /* use the configured bandwidth in case of monitor interface */
105 sdata = rcu_dereference(local->monitor_sdata);
106 if (sdata && rcu_access_pointer(sdata->vif.chanctx_conf) == conf)
107 max_bw = max(max_bw, conf->def.width);
108
103 rcu_read_unlock(); 109 rcu_read_unlock();
104 110
105 return max_bw; 111 return max_bw;
diff --git a/net/mac80211/mesh_ps.c b/net/mac80211/mesh_ps.c
index 2802f9d9279d..ad8b377b4b9f 100644
--- a/net/mac80211/mesh_ps.c
+++ b/net/mac80211/mesh_ps.c
@@ -36,6 +36,7 @@ static struct sk_buff *mps_qos_null_get(struct sta_info *sta)
36 sdata->vif.addr); 36 sdata->vif.addr);
37 nullfunc->frame_control = fc; 37 nullfunc->frame_control = fc;
38 nullfunc->duration_id = 0; 38 nullfunc->duration_id = 0;
39 nullfunc->seq_ctrl = 0;
39 /* no address resolution for this frame -> set addr 1 immediately */ 40 /* no address resolution for this frame -> set addr 1 immediately */
40 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); 41 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
41 memset(skb_put(skb, 2), 0, 2); /* append QoS control field */ 42 memset(skb_put(skb, 2), 0, 2); /* append QoS control field */
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index a023b432143b..137a192e64bc 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -1206,6 +1206,7 @@ static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata,
1206 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); 1206 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1207 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); 1207 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1208 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); 1208 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
1209 nullfunc->seq_ctrl = 0;
1209 1210
1210 skb->priority = tid; 1211 skb->priority = tid;
1211 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]); 1212 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 1313145e3b86..a07d55e75698 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -273,11 +273,12 @@ static struct Qdisc *qdisc_match_from_root(struct Qdisc *root, u32 handle)
273 273
274void qdisc_list_add(struct Qdisc *q) 274void qdisc_list_add(struct Qdisc *q)
275{ 275{
276 struct Qdisc *root = qdisc_dev(q)->qdisc; 276 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS)) {
277 struct Qdisc *root = qdisc_dev(q)->qdisc;
277 278
278 WARN_ON_ONCE(root == &noop_qdisc); 279 WARN_ON_ONCE(root == &noop_qdisc);
279 if ((q->parent != TC_H_ROOT) && !(q->flags & TCQ_F_INGRESS))
280 list_add_tail(&q->list, &root->list); 280 list_add_tail(&q->list, &root->list);
281 }
281} 282}
282EXPORT_SYMBOL(qdisc_list_add); 283EXPORT_SYMBOL(qdisc_list_add);
283 284
diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c
index 08ef7a42c0e4..21e251766eb1 100644
--- a/net/sched/sch_fq.c
+++ b/net/sched/sch_fq.c
@@ -601,6 +601,7 @@ static int fq_resize(struct Qdisc *sch, u32 log)
601{ 601{
602 struct fq_sched_data *q = qdisc_priv(sch); 602 struct fq_sched_data *q = qdisc_priv(sch);
603 struct rb_root *array; 603 struct rb_root *array;
604 void *old_fq_root;
604 u32 idx; 605 u32 idx;
605 606
606 if (q->fq_root && log == q->fq_trees_log) 607 if (q->fq_root && log == q->fq_trees_log)
@@ -615,13 +616,19 @@ static int fq_resize(struct Qdisc *sch, u32 log)
615 for (idx = 0; idx < (1U << log); idx++) 616 for (idx = 0; idx < (1U << log); idx++)
616 array[idx] = RB_ROOT; 617 array[idx] = RB_ROOT;
617 618
618 if (q->fq_root) { 619 sch_tree_lock(sch);
619 fq_rehash(q, q->fq_root, q->fq_trees_log, array, log); 620
620 fq_free(q->fq_root); 621 old_fq_root = q->fq_root;
621 } 622 if (old_fq_root)
623 fq_rehash(q, old_fq_root, q->fq_trees_log, array, log);
624
622 q->fq_root = array; 625 q->fq_root = array;
623 q->fq_trees_log = log; 626 q->fq_trees_log = log;
624 627
628 sch_tree_unlock(sch);
629
630 fq_free(old_fq_root);
631
625 return 0; 632 return 0;
626} 633}
627 634
@@ -697,9 +704,11 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt)
697 q->flow_refill_delay = usecs_to_jiffies(usecs_delay); 704 q->flow_refill_delay = usecs_to_jiffies(usecs_delay);
698 } 705 }
699 706
700 if (!err) 707 if (!err) {
708 sch_tree_unlock(sch);
701 err = fq_resize(sch, fq_log); 709 err = fq_resize(sch, fq_log);
702 710 sch_tree_lock(sch);
711 }
703 while (sch->q.qlen > sch->limit) { 712 while (sch->q.qlen > sch->limit) {
704 struct sk_buff *skb = fq_dequeue(sch); 713 struct sk_buff *skb = fq_dequeue(sch);
705 714
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 632090b961c3..3a1767ef3201 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1421,8 +1421,8 @@ static void sctp_chunk_destroy(struct sctp_chunk *chunk)
1421 BUG_ON(!list_empty(&chunk->list)); 1421 BUG_ON(!list_empty(&chunk->list));
1422 list_del_init(&chunk->transmitted_list); 1422 list_del_init(&chunk->transmitted_list);
1423 1423
1424 /* Free the chunk skb data and the SCTP_chunk stub itself. */ 1424 consume_skb(chunk->skb);
1425 dev_kfree_skb(chunk->skb); 1425 consume_skb(chunk->auth_chunk);
1426 1426
1427 SCTP_DBG_OBJCNT_DEC(chunk); 1427 SCTP_DBG_OBJCNT_DEC(chunk);
1428 kmem_cache_free(sctp_chunk_cachep, chunk); 1428 kmem_cache_free(sctp_chunk_cachep, chunk);
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index ae65b6b5973a..01e002430c85 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -760,7 +760,6 @@ sctp_disposition_t sctp_sf_do_5_1D_ce(struct net *net,
760 760
761 /* Make sure that we and the peer are AUTH capable */ 761 /* Make sure that we and the peer are AUTH capable */
762 if (!net->sctp.auth_enable || !new_asoc->peer.auth_capable) { 762 if (!net->sctp.auth_enable || !new_asoc->peer.auth_capable) {
763 kfree_skb(chunk->auth_chunk);
764 sctp_association_free(new_asoc); 763 sctp_association_free(new_asoc);
765 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); 764 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
766 } 765 }
@@ -775,10 +774,6 @@ sctp_disposition_t sctp_sf_do_5_1D_ce(struct net *net,
775 auth.transport = chunk->transport; 774 auth.transport = chunk->transport;
776 775
777 ret = sctp_sf_authenticate(net, ep, new_asoc, type, &auth); 776 ret = sctp_sf_authenticate(net, ep, new_asoc, type, &auth);
778
779 /* We can now safely free the auth_chunk clone */
780 kfree_skb(chunk->auth_chunk);
781
782 if (ret != SCTP_IERROR_NO_ERROR) { 777 if (ret != SCTP_IERROR_NO_ERROR) {
783 sctp_association_free(new_asoc); 778 sctp_association_free(new_asoc);
784 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); 779 return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
diff --git a/net/socket.c b/net/socket.c
index 879933aaed4c..a19ae1968d37 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -450,16 +450,17 @@ EXPORT_SYMBOL(sockfd_lookup);
450 450
451static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed) 451static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
452{ 452{
453 struct file *file; 453 struct fd f = fdget(fd);
454 struct socket *sock; 454 struct socket *sock;
455 455
456 *err = -EBADF; 456 *err = -EBADF;
457 file = fget_light(fd, fput_needed); 457 if (f.file) {
458 if (file) { 458 sock = sock_from_file(f.file, err);
459 sock = sock_from_file(file, err); 459 if (likely(sock)) {
460 if (sock) 460 *fput_needed = f.flags;
461 return sock; 461 return sock;
462 fput_light(file, *fput_needed); 462 }
463 fdput(f);
463 } 464 }
464 return NULL; 465 return NULL;
465} 466}
@@ -1985,6 +1986,10 @@ static int copy_msghdr_from_user(struct msghdr *kmsg,
1985{ 1986{
1986 if (copy_from_user(kmsg, umsg, sizeof(struct msghdr))) 1987 if (copy_from_user(kmsg, umsg, sizeof(struct msghdr)))
1987 return -EFAULT; 1988 return -EFAULT;
1989
1990 if (kmsg->msg_namelen < 0)
1991 return -EINVAL;
1992
1988 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage)) 1993 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
1989 kmsg->msg_namelen = sizeof(struct sockaddr_storage); 1994 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
1990 return 0; 1995 return 0;
diff --git a/net/tipc/config.c b/net/tipc/config.c
index e74eef2e7490..e6d721692ae0 100644
--- a/net/tipc/config.c
+++ b/net/tipc/config.c
@@ -376,7 +376,6 @@ static void cfg_conn_msg_event(int conid, struct sockaddr_tipc *addr,
376 struct tipc_cfg_msg_hdr *req_hdr; 376 struct tipc_cfg_msg_hdr *req_hdr;
377 struct tipc_cfg_msg_hdr *rep_hdr; 377 struct tipc_cfg_msg_hdr *rep_hdr;
378 struct sk_buff *rep_buf; 378 struct sk_buff *rep_buf;
379 int ret;
380 379
381 /* Validate configuration message header (ignore invalid message) */ 380 /* Validate configuration message header (ignore invalid message) */
382 req_hdr = (struct tipc_cfg_msg_hdr *)buf; 381 req_hdr = (struct tipc_cfg_msg_hdr *)buf;
@@ -398,12 +397,8 @@ static void cfg_conn_msg_event(int conid, struct sockaddr_tipc *addr,
398 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr)); 397 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
399 rep_hdr->tcm_len = htonl(rep_buf->len); 398 rep_hdr->tcm_len = htonl(rep_buf->len);
400 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST); 399 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
401 400 tipc_conn_sendmsg(&cfgsrv, conid, addr, rep_buf->data,
402 ret = tipc_conn_sendmsg(&cfgsrv, conid, addr, rep_buf->data, 401 rep_buf->len);
403 rep_buf->len);
404 if (ret < 0)
405 pr_err("Sending cfg reply message failed, no memory\n");
406
407 kfree_skb(rep_buf); 402 kfree_skb(rep_buf);
408 } 403 }
409} 404}
diff --git a/net/tipc/handler.c b/net/tipc/handler.c
index e4bc8a296744..1fabf160501f 100644
--- a/net/tipc/handler.c
+++ b/net/tipc/handler.c
@@ -58,7 +58,6 @@ unsigned int tipc_k_signal(Handler routine, unsigned long argument)
58 58
59 spin_lock_bh(&qitem_lock); 59 spin_lock_bh(&qitem_lock);
60 if (!handler_enabled) { 60 if (!handler_enabled) {
61 pr_err("Signal request ignored by handler\n");
62 spin_unlock_bh(&qitem_lock); 61 spin_unlock_bh(&qitem_lock);
63 return -ENOPROTOOPT; 62 return -ENOPROTOOPT;
64 } 63 }
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index 48302be175ce..042e8e3cabc0 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -941,17 +941,48 @@ int tipc_nametbl_init(void)
941 return 0; 941 return 0;
942} 942}
943 943
944/**
945 * tipc_purge_publications - remove all publications for a given type
946 *
947 * tipc_nametbl_lock must be held when calling this function
948 */
949static void tipc_purge_publications(struct name_seq *seq)
950{
951 struct publication *publ, *safe;
952 struct sub_seq *sseq;
953 struct name_info *info;
954
955 if (!seq->sseqs) {
956 nameseq_delete_empty(seq);
957 return;
958 }
959 sseq = seq->sseqs;
960 info = sseq->info;
961 list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) {
962 tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node,
963 publ->ref, publ->key);
964 }
965}
966
944void tipc_nametbl_stop(void) 967void tipc_nametbl_stop(void)
945{ 968{
946 u32 i; 969 u32 i;
970 struct name_seq *seq;
971 struct hlist_head *seq_head;
972 struct hlist_node *safe;
947 973
948 /* Verify name table is empty, then release it */ 974 /* Verify name table is empty and purge any lingering
975 * publications, then release the name table
976 */
949 write_lock_bh(&tipc_nametbl_lock); 977 write_lock_bh(&tipc_nametbl_lock);
950 for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { 978 for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {
951 if (hlist_empty(&table.types[i])) 979 if (hlist_empty(&table.types[i]))
952 continue; 980 continue;
953 pr_err("nametbl_stop(): orphaned hash chain detected\n"); 981 seq_head = &table.types[i];
954 break; 982 hlist_for_each_entry_safe(seq, safe, seq_head, ns_list) {
983 tipc_purge_publications(seq);
984 }
985 continue;
955 } 986 }
956 kfree(table.types); 987 kfree(table.types);
957 table.types = NULL; 988 table.types = NULL;
diff --git a/net/tipc/server.c b/net/tipc/server.c
index 373979789a73..646a930eefbf 100644
--- a/net/tipc/server.c
+++ b/net/tipc/server.c
@@ -87,7 +87,6 @@ static void tipc_clean_outqueues(struct tipc_conn *con);
87static void tipc_conn_kref_release(struct kref *kref) 87static void tipc_conn_kref_release(struct kref *kref)
88{ 88{
89 struct tipc_conn *con = container_of(kref, struct tipc_conn, kref); 89 struct tipc_conn *con = container_of(kref, struct tipc_conn, kref);
90 struct tipc_server *s = con->server;
91 90
92 if (con->sock) { 91 if (con->sock) {
93 tipc_sock_release_local(con->sock); 92 tipc_sock_release_local(con->sock);
@@ -95,10 +94,6 @@ static void tipc_conn_kref_release(struct kref *kref)
95 } 94 }
96 95
97 tipc_clean_outqueues(con); 96 tipc_clean_outqueues(con);
98
99 if (con->conid)
100 s->tipc_conn_shutdown(con->conid, con->usr_data);
101
102 kfree(con); 97 kfree(con);
103} 98}
104 99
@@ -181,6 +176,9 @@ static void tipc_close_conn(struct tipc_conn *con)
181 struct tipc_server *s = con->server; 176 struct tipc_server *s = con->server;
182 177
183 if (test_and_clear_bit(CF_CONNECTED, &con->flags)) { 178 if (test_and_clear_bit(CF_CONNECTED, &con->flags)) {
179 if (con->conid)
180 s->tipc_conn_shutdown(con->conid, con->usr_data);
181
184 spin_lock_bh(&s->idr_lock); 182 spin_lock_bh(&s->idr_lock);
185 idr_remove(&s->conn_idr, con->conid); 183 idr_remove(&s->conn_idr, con->conid);
186 s->idr_in_use--; 184 s->idr_in_use--;
@@ -429,10 +427,12 @@ int tipc_conn_sendmsg(struct tipc_server *s, int conid,
429 list_add_tail(&e->list, &con->outqueue); 427 list_add_tail(&e->list, &con->outqueue);
430 spin_unlock_bh(&con->outqueue_lock); 428 spin_unlock_bh(&con->outqueue_lock);
431 429
432 if (test_bit(CF_CONNECTED, &con->flags)) 430 if (test_bit(CF_CONNECTED, &con->flags)) {
433 if (!queue_work(s->send_wq, &con->swork)) 431 if (!queue_work(s->send_wq, &con->swork))
434 conn_put(con); 432 conn_put(con);
435 433 } else {
434 conn_put(con);
435 }
436 return 0; 436 return 0;
437} 437}
438 438
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index a4cf274455aa..0ed0eaa62f29 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -997,7 +997,7 @@ static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo)
997 997
998 for (;;) { 998 for (;;) {
999 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); 999 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
1000 if (skb_queue_empty(&sk->sk_receive_queue)) { 1000 if (timeo && skb_queue_empty(&sk->sk_receive_queue)) {
1001 if (sock->state == SS_DISCONNECTING) { 1001 if (sock->state == SS_DISCONNECTING) {
1002 err = -ENOTCONN; 1002 err = -ENOTCONN;
1003 break; 1003 break;
@@ -1623,7 +1623,7 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo)
1623 for (;;) { 1623 for (;;) {
1624 prepare_to_wait_exclusive(sk_sleep(sk), &wait, 1624 prepare_to_wait_exclusive(sk_sleep(sk), &wait,
1625 TASK_INTERRUPTIBLE); 1625 TASK_INTERRUPTIBLE);
1626 if (skb_queue_empty(&sk->sk_receive_queue)) { 1626 if (timeo && skb_queue_empty(&sk->sk_receive_queue)) {
1627 release_sock(sk); 1627 release_sock(sk);
1628 timeo = schedule_timeout(timeo); 1628 timeo = schedule_timeout(timeo);
1629 lock_sock(sk); 1629 lock_sock(sk);
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
index 7cb0bd5b1176..11c9ae00837d 100644
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -96,20 +96,16 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
96{ 96{
97 struct tipc_subscriber *subscriber = sub->subscriber; 97 struct tipc_subscriber *subscriber = sub->subscriber;
98 struct kvec msg_sect; 98 struct kvec msg_sect;
99 int ret;
100 99
101 msg_sect.iov_base = (void *)&sub->evt; 100 msg_sect.iov_base = (void *)&sub->evt;
102 msg_sect.iov_len = sizeof(struct tipc_event); 101 msg_sect.iov_len = sizeof(struct tipc_event);
103
104 sub->evt.event = htohl(event, sub->swap); 102 sub->evt.event = htohl(event, sub->swap);
105 sub->evt.found_lower = htohl(found_lower, sub->swap); 103 sub->evt.found_lower = htohl(found_lower, sub->swap);
106 sub->evt.found_upper = htohl(found_upper, sub->swap); 104 sub->evt.found_upper = htohl(found_upper, sub->swap);
107 sub->evt.port.ref = htohl(port_ref, sub->swap); 105 sub->evt.port.ref = htohl(port_ref, sub->swap);
108 sub->evt.port.node = htohl(node, sub->swap); 106 sub->evt.port.node = htohl(node, sub->swap);
109 ret = tipc_conn_sendmsg(&topsrv, subscriber->conid, NULL, 107 tipc_conn_sendmsg(&topsrv, subscriber->conid, NULL, msg_sect.iov_base,
110 msg_sect.iov_base, msg_sect.iov_len); 108 msg_sect.iov_len);
111 if (ret < 0)
112 pr_err("Sending subscription event failed, no memory\n");
113} 109}
114 110
115/** 111/**
@@ -153,14 +149,6 @@ static void subscr_timeout(struct tipc_subscription *sub)
153 /* The spin lock per subscriber is used to protect its members */ 149 /* The spin lock per subscriber is used to protect its members */
154 spin_lock_bh(&subscriber->lock); 150 spin_lock_bh(&subscriber->lock);
155 151
156 /* Validate if the connection related to the subscriber is
157 * closed (in case subscriber is terminating)
158 */
159 if (subscriber->conid == 0) {
160 spin_unlock_bh(&subscriber->lock);
161 return;
162 }
163
164 /* Validate timeout (in case subscription is being cancelled) */ 152 /* Validate timeout (in case subscription is being cancelled) */
165 if (sub->timeout == TIPC_WAIT_FOREVER) { 153 if (sub->timeout == TIPC_WAIT_FOREVER) {
166 spin_unlock_bh(&subscriber->lock); 154 spin_unlock_bh(&subscriber->lock);
@@ -215,9 +203,6 @@ static void subscr_release(struct tipc_subscriber *subscriber)
215 203
216 spin_lock_bh(&subscriber->lock); 204 spin_lock_bh(&subscriber->lock);
217 205
218 /* Invalidate subscriber reference */
219 subscriber->conid = 0;
220
221 /* Destroy any existing subscriptions for subscriber */ 206 /* Destroy any existing subscriptions for subscriber */
222 list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list, 207 list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
223 subscription_list) { 208 subscription_list) {
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 29fc8bee9702..ce6ec6c2f4de 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -163,9 +163,8 @@ static inline void unix_set_secdata(struct scm_cookie *scm, struct sk_buff *skb)
163 163
164static inline unsigned int unix_hash_fold(__wsum n) 164static inline unsigned int unix_hash_fold(__wsum n)
165{ 165{
166 unsigned int hash = (__force unsigned int)n; 166 unsigned int hash = (__force unsigned int)csum_fold(n);
167 167
168 hash ^= hash>>16;
169 hash ^= hash>>8; 168 hash ^= hash>>8;
170 return hash&(UNIX_HASH_SIZE-1); 169 return hash&(UNIX_HASH_SIZE-1);
171} 170}
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 010892b81a06..a3bf18d11609 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -788,8 +788,6 @@ void cfg80211_leave(struct cfg80211_registered_device *rdev,
788 default: 788 default:
789 break; 789 break;
790 } 790 }
791
792 wdev->beacon_interval = 0;
793} 791}
794 792
795static int cfg80211_netdev_notifier_call(struct notifier_block *nb, 793static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 276e84b8a8e5..10085de886fe 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -330,7 +330,8 @@ static void write_src(void)
330 printf("\tPTR\t_text + %#llx\n", 330 printf("\tPTR\t_text + %#llx\n",
331 table[i].addr - _text); 331 table[i].addr - _text);
332 else 332 else
333 printf("\tPTR\t%#llx\n", table[i].addr); 333 printf("\tPTR\t_text - %#llx\n",
334 _text - table[i].addr);
334 } else { 335 } else {
335 printf("\tPTR\t%#llx\n", table[i].addr); 336 printf("\tPTR\t%#llx\n", table[i].addr);
336 } 337 }
diff --git a/sound/aoa/aoa.h b/sound/aoa/aoa.h
index e08789484e30..34c668f27798 100644
--- a/sound/aoa/aoa.h
+++ b/sound/aoa/aoa.h
@@ -116,7 +116,7 @@ struct aoa_card {
116 struct snd_card *alsa_card; 116 struct snd_card *alsa_card;
117}; 117};
118 118
119extern int aoa_snd_device_new(snd_device_type_t type, 119extern int aoa_snd_device_new(enum snd_device_type type,
120 void * device_data, struct snd_device_ops * ops); 120 void * device_data, struct snd_device_ops * ops);
121extern struct snd_card *aoa_get_card(void); 121extern struct snd_card *aoa_get_card(void);
122extern int aoa_snd_ctl_add(struct snd_kcontrol* control); 122extern int aoa_snd_ctl_add(struct snd_kcontrol* control);
diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
index 4cedc6950d72..f01bffb702bc 100644
--- a/sound/aoa/codecs/onyx.c
+++ b/sound/aoa/codecs/onyx.c
@@ -889,7 +889,7 @@ static int onyx_init_codec(struct aoa_codec *codec)
889 return -ENODEV; 889 return -ENODEV;
890 } 890 }
891 891
892 if (aoa_snd_device_new(SNDRV_DEV_LOWLEVEL, onyx, &ops)) { 892 if (aoa_snd_device_new(SNDRV_DEV_CODEC, onyx, &ops)) {
893 printk(KERN_ERR PFX "failed to create onyx snd device!\n"); 893 printk(KERN_ERR PFX "failed to create onyx snd device!\n");
894 return -ENODEV; 894 return -ENODEV;
895 } 895 }
diff --git a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c
index c491ae0f749c..cf3c6303b7e3 100644
--- a/sound/aoa/codecs/tas.c
+++ b/sound/aoa/codecs/tas.c
@@ -826,7 +826,7 @@ static int tas_init_codec(struct aoa_codec *codec)
826 return -ENODEV; 826 return -ENODEV;
827 } 827 }
828 828
829 if (aoa_snd_device_new(SNDRV_DEV_LOWLEVEL, tas, &ops)) { 829 if (aoa_snd_device_new(SNDRV_DEV_CODEC, tas, &ops)) {
830 printk(KERN_ERR PFX "failed to create tas snd device!\n"); 830 printk(KERN_ERR PFX "failed to create tas snd device!\n");
831 return -ENODEV; 831 return -ENODEV;
832 } 832 }
diff --git a/sound/aoa/codecs/toonie.c b/sound/aoa/codecs/toonie.c
index 69d2cb601f2a..7e8c3417cd85 100644
--- a/sound/aoa/codecs/toonie.c
+++ b/sound/aoa/codecs/toonie.c
@@ -92,7 +92,7 @@ static int toonie_init_codec(struct aoa_codec *codec)
92 if (toonie->codec.connected != 1) 92 if (toonie->codec.connected != 1)
93 return -ENOTCONN; 93 return -ENOTCONN;
94 94
95 if (aoa_snd_device_new(SNDRV_DEV_LOWLEVEL, toonie, &ops)) { 95 if (aoa_snd_device_new(SNDRV_DEV_CODEC, toonie, &ops)) {
96 printk(KERN_ERR PFX "failed to create toonie snd device!\n"); 96 printk(KERN_ERR PFX "failed to create toonie snd device!\n");
97 return -ENODEV; 97 return -ENODEV;
98 } 98 }
diff --git a/sound/aoa/core/alsa.c b/sound/aoa/core/alsa.c
index 0fa3855b4790..4a7e4e6b746f 100644
--- a/sound/aoa/core/alsa.c
+++ b/sound/aoa/core/alsa.c
@@ -23,13 +23,12 @@ 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 err = snd_card_create(index, name, mod, sizeof(struct aoa_card), 26 err = snd_card_new(dev, index, name, mod, sizeof(struct aoa_card),
27 &alsa_card); 27 &alsa_card);
28 if (err < 0) 28 if (err < 0)
29 return err; 29 return err;
30 aoa_card = alsa_card->private_data; 30 aoa_card = alsa_card->private_data;
31 aoa_card->alsa_card = alsa_card; 31 aoa_card->alsa_card = alsa_card;
32 alsa_card->dev = dev;
33 strlcpy(alsa_card->driver, "AppleOnbdAudio", sizeof(alsa_card->driver)); 32 strlcpy(alsa_card->driver, "AppleOnbdAudio", sizeof(alsa_card->driver));
34 strlcpy(alsa_card->shortname, name, sizeof(alsa_card->shortname)); 33 strlcpy(alsa_card->shortname, name, sizeof(alsa_card->shortname));
35 strlcpy(alsa_card->longname, name, sizeof(alsa_card->longname)); 34 strlcpy(alsa_card->longname, name, sizeof(alsa_card->longname));
@@ -60,7 +59,7 @@ void aoa_alsa_cleanup(void)
60 } 59 }
61} 60}
62 61
63int aoa_snd_device_new(snd_device_type_t type, 62int aoa_snd_device_new(enum snd_device_type type,
64 void * device_data, struct snd_device_ops * ops) 63 void * device_data, struct snd_device_ops * ops)
65{ 64{
66 struct snd_card *card = aoa_get_card(); 65 struct snd_card *card = aoa_get_card();
diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c
index c421fdb3c7a1..0e83a73efb16 100644
--- a/sound/arm/aaci.c
+++ b/sound/arm/aaci.c
@@ -899,8 +899,8 @@ static struct aaci *aaci_init_card(struct amba_device *dev)
899 struct snd_card *card; 899 struct snd_card *card;
900 int err; 900 int err;
901 901
902 err = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 902 err = snd_card_new(&dev->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
903 THIS_MODULE, sizeof(struct aaci), &card); 903 THIS_MODULE, sizeof(struct aaci), &card);
904 if (err < 0) 904 if (err < 0)
905 return NULL; 905 return NULL;
906 906
@@ -1055,8 +1055,6 @@ static int aaci_probe(struct amba_device *dev,
1055 if (ret) 1055 if (ret)
1056 goto out; 1056 goto out;
1057 1057
1058 snd_card_set_dev(aaci->card, &dev->dev);
1059
1060 ret = snd_card_register(aaci->card); 1058 ret = snd_card_register(aaci->card);
1061 if (ret == 0) { 1059 if (ret == 0) {
1062 dev_info(&dev->dev, "%s\n", aaci->card->longname); 1060 dev_info(&dev->dev, "%s\n", aaci->card->longname);
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index 9a2ac1e0f77a..3a10df6688ee 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -179,12 +179,11 @@ static int pxa2xx_ac97_probe(struct platform_device *dev)
179 goto err_dev; 179 goto err_dev;
180 } 180 }
181 181
182 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 182 ret = snd_card_new(&dev->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
183 THIS_MODULE, 0, &card); 183 THIS_MODULE, 0, &card);
184 if (ret < 0) 184 if (ret < 0)
185 goto err; 185 goto err;
186 186
187 card->dev = &dev->dev;
188 strlcpy(card->driver, dev->dev.driver->name, sizeof(card->driver)); 187 strlcpy(card->driver, dev->dev.driver->name, sizeof(card->driver));
189 188
190 ret = pxa2xx_pcm_new(card, &pxa2xx_ac97_pcm_client, &pxa2xx_ac97_pcm); 189 ret = pxa2xx_pcm_new(card, &pxa2xx_ac97_pcm_client, &pxa2xx_ac97_pcm);
@@ -210,7 +209,6 @@ static int pxa2xx_ac97_probe(struct platform_device *dev)
210 209
211 if (pdata && pdata->codec_pdata[0]) 210 if (pdata && pdata->codec_pdata[0])
212 snd_ac97_dev_add_pdata(ac97_bus->codec[0], pdata->codec_pdata[0]); 211 snd_ac97_dev_add_pdata(ac97_bus->codec[0], pdata->codec_pdata[0]);
213 snd_card_set_dev(card, &dev->dev);
214 ret = snd_card_register(card); 212 ret = snd_card_register(card);
215 if (ret == 0) { 213 if (ret == 0) {
216 platform_set_drvdata(dev, card); 214 platform_set_drvdata(dev, card);
diff --git a/sound/atmel/abdac.c b/sound/atmel/abdac.c
index 3519518e25a0..edf2ca72d518 100644
--- a/sound/atmel/abdac.c
+++ b/sound/atmel/abdac.c
@@ -429,8 +429,9 @@ static int atmel_abdac_probe(struct platform_device *pdev)
429 } 429 }
430 clk_enable(pclk); 430 clk_enable(pclk);
431 431
432 retval = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 432 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1,
433 THIS_MODULE, sizeof(struct atmel_abdac), &card); 433 SNDRV_DEFAULT_STR1, THIS_MODULE,
434 sizeof(struct atmel_abdac), &card);
434 if (retval) { 435 if (retval) {
435 dev_dbg(&pdev->dev, "could not create sound card device\n"); 436 dev_dbg(&pdev->dev, "could not create sound card device\n");
436 goto out_put_sample_clk; 437 goto out_put_sample_clk;
@@ -467,8 +468,6 @@ static int atmel_abdac_probe(struct platform_device *pdev)
467 goto out_unmap_regs; 468 goto out_unmap_regs;
468 } 469 }
469 470
470 snd_card_set_dev(card, &pdev->dev);
471
472 if (pdata->dws.dma_dev) { 471 if (pdata->dws.dma_dev) {
473 dma_cap_mask_t mask; 472 dma_cap_mask_t mask;
474 473
@@ -492,7 +491,7 @@ static int atmel_abdac_probe(struct platform_device *pdev)
492 if (!pdata->dws.dma_dev || !dac->dma.chan) { 491 if (!pdata->dws.dma_dev || !dac->dma.chan) {
493 dev_dbg(&pdev->dev, "DMA not available\n"); 492 dev_dbg(&pdev->dev, "DMA not available\n");
494 retval = -ENODEV; 493 retval = -ENODEV;
495 goto out_unset_card_dev; 494 goto out_unmap_regs;
496 } 495 }
497 496
498 strcpy(card->driver, "Atmel ABDAC"); 497 strcpy(card->driver, "Atmel ABDAC");
@@ -521,9 +520,6 @@ static int atmel_abdac_probe(struct platform_device *pdev)
521out_release_dma: 520out_release_dma:
522 dma_release_channel(dac->dma.chan); 521 dma_release_channel(dac->dma.chan);
523 dac->dma.chan = NULL; 522 dac->dma.chan = NULL;
524out_unset_card_dev:
525 snd_card_set_dev(card, NULL);
526 free_irq(irq, dac);
527out_unmap_regs: 523out_unmap_regs:
528 iounmap(dac->regs); 524 iounmap(dac->regs);
529out_free_card: 525out_free_card:
@@ -579,7 +575,6 @@ static int atmel_abdac_remove(struct platform_device *pdev)
579 575
580 dma_release_channel(dac->dma.chan); 576 dma_release_channel(dac->dma.chan);
581 dac->dma.chan = NULL; 577 dac->dma.chan = NULL;
582 snd_card_set_dev(card, NULL);
583 iounmap(dac->regs); 578 iounmap(dac->regs);
584 free_irq(dac->irq, dac); 579 free_irq(dac->irq, dac);
585 snd_card_free(card); 580 snd_card_free(card);
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c
index c5f0ddd729b3..05ec049c9faf 100644
--- a/sound/atmel/ac97c.c
+++ b/sound/atmel/ac97c.c
@@ -945,8 +945,9 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
945 } 945 }
946 clk_enable(pclk); 946 clk_enable(pclk);
947 947
948 retval = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 948 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1,
949 THIS_MODULE, sizeof(struct atmel_ac97c), &card); 949 SNDRV_DEFAULT_STR1, THIS_MODULE,
950 sizeof(struct atmel_ac97c), &card);
950 if (retval) { 951 if (retval) {
951 dev_dbg(&pdev->dev, "could not create sound card device\n"); 952 dev_dbg(&pdev->dev, "could not create sound card device\n");
952 goto err_snd_card_new; 953 goto err_snd_card_new;
@@ -990,8 +991,6 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
990 chip->reset_pin = -EINVAL; 991 chip->reset_pin = -EINVAL;
991 } 992 }
992 993
993 snd_card_set_dev(card, &pdev->dev);
994
995 atmel_ac97c_reset(chip); 994 atmel_ac97c_reset(chip);
996 995
997 /* Enable overrun interrupt from codec channel */ 996 /* Enable overrun interrupt from codec channel */
@@ -1113,8 +1112,6 @@ err_dma:
1113 chip->dma.tx_chan = NULL; 1112 chip->dma.tx_chan = NULL;
1114 } 1113 }
1115err_ac97_bus: 1114err_ac97_bus:
1116 snd_card_set_dev(card, NULL);
1117
1118 if (gpio_is_valid(chip->reset_pin)) 1115 if (gpio_is_valid(chip->reset_pin))
1119 gpio_free(chip->reset_pin); 1116 gpio_free(chip->reset_pin);
1120 1117
@@ -1195,7 +1192,6 @@ static int atmel_ac97c_remove(struct platform_device *pdev)
1195 chip->dma.tx_chan = NULL; 1192 chip->dma.tx_chan = NULL;
1196 } 1193 }
1197 1194
1198 snd_card_set_dev(card, NULL);
1199 snd_card_free(card); 1195 snd_card_free(card);
1200 1196
1201 return 0; 1197 return 0;
diff --git a/sound/core/control.c b/sound/core/control.c
index d8aa206e8bde..f038f5afafe2 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -151,7 +151,7 @@ void snd_ctl_notify(struct snd_card *card, unsigned int mask,
151 if (snd_BUG_ON(!card || !id)) 151 if (snd_BUG_ON(!card || !id))
152 return; 152 return;
153 read_lock(&card->ctl_files_rwlock); 153 read_lock(&card->ctl_files_rwlock);
154#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 154#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
155 card->mixer_oss_change_count++; 155 card->mixer_oss_change_count++;
156#endif 156#endif
157 list_for_each_entry(ctl, &card->ctl_files, list) { 157 list_for_each_entry(ctl, &card->ctl_files, list) {
@@ -170,7 +170,7 @@ void snd_ctl_notify(struct snd_card *card, unsigned int mask,
170 ev->mask = mask; 170 ev->mask = mask;
171 list_add_tail(&ev->list, &ctl->events); 171 list_add_tail(&ev->list, &ctl->events);
172 } else { 172 } else {
173 snd_printk(KERN_ERR "No memory available to allocate event\n"); 173 dev_err(card->dev, "No memory available to allocate event\n");
174 } 174 }
175 _found: 175 _found:
176 wake_up(&ctl->change_sleep); 176 wake_up(&ctl->change_sleep);
@@ -206,7 +206,7 @@ static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control,
206 206
207 kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL); 207 kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL);
208 if (kctl == NULL) { 208 if (kctl == NULL) {
209 snd_printk(KERN_ERR "Cannot allocate control instance\n"); 209 pr_err("ALSA: Cannot allocate control instance\n");
210 return NULL; 210 return NULL;
211 } 211 }
212 *kctl = *control; 212 *kctl = *control;
@@ -241,9 +241,8 @@ struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol,
241 if (ncontrol->name) { 241 if (ncontrol->name) {
242 strlcpy(kctl.id.name, ncontrol->name, sizeof(kctl.id.name)); 242 strlcpy(kctl.id.name, ncontrol->name, sizeof(kctl.id.name));
243 if (strcmp(ncontrol->name, kctl.id.name) != 0) 243 if (strcmp(ncontrol->name, kctl.id.name) != 0)
244 snd_printk(KERN_WARNING 244 pr_warn("ALSA: Control name '%s' truncated to '%s'\n",
245 "Control name '%s' truncated to '%s'\n", 245 ncontrol->name, kctl.id.name);
246 ncontrol->name, kctl.id.name);
247 } 246 }
248 kctl.id.index = ncontrol->index; 247 kctl.id.index = ncontrol->index;
249 kctl.count = ncontrol->count ? ncontrol->count : 1; 248 kctl.count = ncontrol->count ? ncontrol->count : 1;
@@ -306,7 +305,7 @@ static int snd_ctl_find_hole(struct snd_card *card, unsigned int count)
306 while (snd_ctl_remove_numid_conflict(card, count)) { 305 while (snd_ctl_remove_numid_conflict(card, count)) {
307 if (--iter == 0) { 306 if (--iter == 0) {
308 /* this situation is very unlikely */ 307 /* this situation is very unlikely */
309 snd_printk(KERN_ERR "unable to allocate new control numid\n"); 308 dev_err(card->dev, "unable to allocate new control numid\n");
310 return -ENOMEM; 309 return -ENOMEM;
311 } 310 }
312 } 311 }
@@ -341,7 +340,7 @@ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol)
341 down_write(&card->controls_rwsem); 340 down_write(&card->controls_rwsem);
342 if (snd_ctl_find_id(card, &id)) { 341 if (snd_ctl_find_id(card, &id)) {
343 up_write(&card->controls_rwsem); 342 up_write(&card->controls_rwsem);
344 snd_printd(KERN_ERR "control %i:%i:%i:%s:%i is already present\n", 343 dev_err(card->dev, "control %i:%i:%i:%s:%i is already present\n",
345 id.iface, 344 id.iface,
346 id.device, 345 id.device,
347 id.subdevice, 346 id.subdevice,
@@ -1406,7 +1405,7 @@ static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg
1406 } 1405 }
1407 } 1406 }
1408 up_read(&snd_ioctl_rwsem); 1407 up_read(&snd_ioctl_rwsem);
1409 snd_printdd("unknown ioctl = 0x%x\n", cmd); 1408 dev_dbg(card->dev, "unknown ioctl = 0x%x\n", cmd);
1410 return -ENOTTY; 1409 return -ENOTTY;
1411} 1410}
1412 1411
diff --git a/sound/core/control_compat.c b/sound/core/control_compat.c
index 2bb95a7a8809..b9c0910fb8c4 100644
--- a/sound/core/control_compat.c
+++ b/sound/core/control_compat.c
@@ -247,7 +247,7 @@ static int copy_ctl_value_from_user(struct snd_card *card,
247 } else { 247 } else {
248 size = get_elem_size(type, count); 248 size = get_elem_size(type, count);
249 if (size < 0) { 249 if (size < 0) {
250 printk(KERN_ERR "snd_ioctl32_ctl_elem_value: unknown type %d\n", type); 250 dev_err(card->dev, "snd_ioctl32_ctl_elem_value: unknown type %d\n", type);
251 return -EINVAL; 251 return -EINVAL;
252 } 252 }
253 if (copy_from_user(data->value.bytes.data, 253 if (copy_from_user(data->value.bytes.data,
diff --git a/sound/core/device.c b/sound/core/device.c
index df88defed176..41bec3075ae5 100644
--- a/sound/core/device.c
+++ b/sound/core/device.c
@@ -41,29 +41,73 @@
41 * 41 *
42 * Return: Zero if successful, or a negative error code on failure. 42 * Return: Zero if successful, or a negative error code on failure.
43 */ 43 */
44int snd_device_new(struct snd_card *card, snd_device_type_t type, 44int snd_device_new(struct snd_card *card, enum snd_device_type type,
45 void *device_data, struct snd_device_ops *ops) 45 void *device_data, struct snd_device_ops *ops)
46{ 46{
47 struct snd_device *dev; 47 struct snd_device *dev;
48 struct list_head *p;
48 49
49 if (snd_BUG_ON(!card || !device_data || !ops)) 50 if (snd_BUG_ON(!card || !device_data || !ops))
50 return -ENXIO; 51 return -ENXIO;
51 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 52 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
52 if (dev == NULL) { 53 if (dev == NULL) {
53 snd_printk(KERN_ERR "Cannot allocate device\n"); 54 dev_err(card->dev, "Cannot allocate device, type=%d\n", type);
54 return -ENOMEM; 55 return -ENOMEM;
55 } 56 }
57 INIT_LIST_HEAD(&dev->list);
56 dev->card = card; 58 dev->card = card;
57 dev->type = type; 59 dev->type = type;
58 dev->state = SNDRV_DEV_BUILD; 60 dev->state = SNDRV_DEV_BUILD;
59 dev->device_data = device_data; 61 dev->device_data = device_data;
60 dev->ops = ops; 62 dev->ops = ops;
61 list_add(&dev->list, &card->devices); /* add to the head of list */ 63
64 /* insert the entry in an incrementally sorted list */
65 list_for_each_prev(p, &card->devices) {
66 struct snd_device *pdev = list_entry(p, struct snd_device, list);
67 if ((unsigned int)pdev->type <= (unsigned int)type)
68 break;
69 }
70
71 list_add(&dev->list, p);
62 return 0; 72 return 0;
63} 73}
64
65EXPORT_SYMBOL(snd_device_new); 74EXPORT_SYMBOL(snd_device_new);
66 75
76static int __snd_device_disconnect(struct snd_device *dev)
77{
78 if (dev->state == SNDRV_DEV_REGISTERED) {
79 if (dev->ops->dev_disconnect &&
80 dev->ops->dev_disconnect(dev))
81 dev_err(dev->card->dev, "device disconnect failure\n");
82 dev->state = SNDRV_DEV_DISCONNECTED;
83 }
84 return 0;
85}
86
87static void __snd_device_free(struct snd_device *dev)
88{
89 /* unlink */
90 list_del(&dev->list);
91
92 __snd_device_disconnect(dev);
93 if (dev->ops->dev_free) {
94 if (dev->ops->dev_free(dev))
95 dev_err(dev->card->dev, "device free failure\n");
96 }
97 kfree(dev);
98}
99
100static struct snd_device *look_for_dev(struct snd_card *card, void *device_data)
101{
102 struct snd_device *dev;
103
104 list_for_each_entry(dev, &card->devices, list)
105 if (dev->device_data == device_data)
106 return dev;
107
108 return NULL;
109}
110
67/** 111/**
68 * snd_device_free - release the device from the card 112 * snd_device_free - release the device from the card
69 * @card: the card instance 113 * @card: the card instance
@@ -72,73 +116,33 @@ EXPORT_SYMBOL(snd_device_new);
72 * Removes the device from the list on the card and invokes the 116 * Removes the device from the list on the card and invokes the
73 * callbacks, dev_disconnect and dev_free, corresponding to the state. 117 * callbacks, dev_disconnect and dev_free, corresponding to the state.
74 * Then release the device. 118 * Then release the device.
75 *
76 * Return: Zero if successful, or a negative error code on failure or if the
77 * device not found.
78 */ 119 */
79int snd_device_free(struct snd_card *card, void *device_data) 120void snd_device_free(struct snd_card *card, void *device_data)
80{ 121{
81 struct snd_device *dev; 122 struct snd_device *dev;
82 123
83 if (snd_BUG_ON(!card || !device_data)) 124 if (snd_BUG_ON(!card || !device_data))
84 return -ENXIO; 125 return;
85 list_for_each_entry(dev, &card->devices, list) { 126 dev = look_for_dev(card, device_data);
86 if (dev->device_data != device_data) 127 if (dev)
87 continue; 128 __snd_device_free(dev);
88 /* unlink */ 129 else
89 list_del(&dev->list); 130 dev_dbg(card->dev, "device free %p (from %pF), not found\n",
90 if (dev->state == SNDRV_DEV_REGISTERED && 131 device_data, __builtin_return_address(0));
91 dev->ops->dev_disconnect)
92 if (dev->ops->dev_disconnect(dev))
93 snd_printk(KERN_ERR
94 "device disconnect failure\n");
95 if (dev->ops->dev_free) {
96 if (dev->ops->dev_free(dev))
97 snd_printk(KERN_ERR "device free failure\n");
98 }
99 kfree(dev);
100 return 0;
101 }
102 snd_printd("device free %p (from %pF), not found\n", device_data,
103 __builtin_return_address(0));
104 return -ENXIO;
105} 132}
106
107EXPORT_SYMBOL(snd_device_free); 133EXPORT_SYMBOL(snd_device_free);
108 134
109/** 135static int __snd_device_register(struct snd_device *dev)
110 * snd_device_disconnect - disconnect the device
111 * @card: the card instance
112 * @device_data: the data pointer to disconnect
113 *
114 * Turns the device into the disconnection state, invoking
115 * dev_disconnect callback, if the device was already registered.
116 *
117 * Usually called from snd_card_disconnect().
118 *
119 * Return: Zero if successful, or a negative error code on failure or if the
120 * device not found.
121 */
122int snd_device_disconnect(struct snd_card *card, void *device_data)
123{ 136{
124 struct snd_device *dev; 137 if (dev->state == SNDRV_DEV_BUILD) {
125 138 if (dev->ops->dev_register) {
126 if (snd_BUG_ON(!card || !device_data)) 139 int err = dev->ops->dev_register(dev);
127 return -ENXIO; 140 if (err < 0)
128 list_for_each_entry(dev, &card->devices, list) { 141 return err;
129 if (dev->device_data != device_data)
130 continue;
131 if (dev->state == SNDRV_DEV_REGISTERED &&
132 dev->ops->dev_disconnect) {
133 if (dev->ops->dev_disconnect(dev))
134 snd_printk(KERN_ERR "device disconnect failure\n");
135 dev->state = SNDRV_DEV_DISCONNECTED;
136 } 142 }
137 return 0; 143 dev->state = SNDRV_DEV_REGISTERED;
138 } 144 }
139 snd_printd("device disconnect %p (from %pF), not found\n", device_data, 145 return 0;
140 __builtin_return_address(0));
141 return -ENXIO;
142} 146}
143 147
144/** 148/**
@@ -157,26 +161,15 @@ int snd_device_disconnect(struct snd_card *card, void *device_data)
157int snd_device_register(struct snd_card *card, void *device_data) 161int snd_device_register(struct snd_card *card, void *device_data)
158{ 162{
159 struct snd_device *dev; 163 struct snd_device *dev;
160 int err;
161 164
162 if (snd_BUG_ON(!card || !device_data)) 165 if (snd_BUG_ON(!card || !device_data))
163 return -ENXIO; 166 return -ENXIO;
164 list_for_each_entry(dev, &card->devices, list) { 167 dev = look_for_dev(card, device_data);
165 if (dev->device_data != device_data) 168 if (dev)
166 continue; 169 return __snd_device_register(dev);
167 if (dev->state == SNDRV_DEV_BUILD && dev->ops->dev_register) {
168 if ((err = dev->ops->dev_register(dev)) < 0)
169 return err;
170 dev->state = SNDRV_DEV_REGISTERED;
171 return 0;
172 }
173 snd_printd("snd_device_register busy\n");
174 return -EBUSY;
175 }
176 snd_BUG(); 170 snd_BUG();
177 return -ENXIO; 171 return -ENXIO;
178} 172}
179
180EXPORT_SYMBOL(snd_device_register); 173EXPORT_SYMBOL(snd_device_register);
181 174
182/* 175/*
@@ -191,11 +184,9 @@ int snd_device_register_all(struct snd_card *card)
191 if (snd_BUG_ON(!card)) 184 if (snd_BUG_ON(!card))
192 return -ENXIO; 185 return -ENXIO;
193 list_for_each_entry(dev, &card->devices, list) { 186 list_for_each_entry(dev, &card->devices, list) {
194 if (dev->state == SNDRV_DEV_BUILD && dev->ops->dev_register) { 187 err = __snd_device_register(dev);
195 if ((err = dev->ops->dev_register(dev)) < 0) 188 if (err < 0)
196 return err; 189 return err;
197 dev->state = SNDRV_DEV_REGISTERED;
198 }
199 } 190 }
200 return 0; 191 return 0;
201} 192}
@@ -211,8 +202,8 @@ int snd_device_disconnect_all(struct snd_card *card)
211 202
212 if (snd_BUG_ON(!card)) 203 if (snd_BUG_ON(!card))
213 return -ENXIO; 204 return -ENXIO;
214 list_for_each_entry(dev, &card->devices, list) { 205 list_for_each_entry_reverse(dev, &card->devices, list) {
215 if (snd_device_disconnect(card, dev->device_data) < 0) 206 if (__snd_device_disconnect(dev) < 0)
216 err = -ENXIO; 207 err = -ENXIO;
217 } 208 }
218 return err; 209 return err;
@@ -222,24 +213,12 @@ int snd_device_disconnect_all(struct snd_card *card)
222 * release all the devices on the card. 213 * release all the devices on the card.
223 * called from init.c 214 * called from init.c
224 */ 215 */
225int snd_device_free_all(struct snd_card *card, snd_device_cmd_t cmd) 216void snd_device_free_all(struct snd_card *card)
226{ 217{
227 struct snd_device *dev; 218 struct snd_device *dev, *next;
228 int err;
229 unsigned int range_low, range_high, type;
230 219
231 if (snd_BUG_ON(!card)) 220 if (snd_BUG_ON(!card))
232 return -ENXIO; 221 return;
233 range_low = (__force unsigned int)cmd * SNDRV_DEV_TYPE_RANGE_SIZE; 222 list_for_each_entry_safe_reverse(dev, next, &card->devices, list)
234 range_high = range_low + SNDRV_DEV_TYPE_RANGE_SIZE - 1; 223 __snd_device_free(dev);
235 __again:
236 list_for_each_entry(dev, &card->devices, list) {
237 type = (__force unsigned int)dev->type;
238 if (type >= range_low && type <= range_high) {
239 if ((err = snd_device_free(card, dev->device_data)) < 0)
240 return err;
241 goto __again;
242 }
243 }
244 return 0;
245} 224}
diff --git a/sound/core/hrtimer.c b/sound/core/hrtimer.c
index b8b31c433d64..886be7da989d 100644
--- a/sound/core/hrtimer.c
+++ b/sound/core/hrtimer.c
@@ -126,8 +126,7 @@ static int __init snd_hrtimer_init(void)
126 126
127 hrtimer_get_res(CLOCK_MONOTONIC, &tp); 127 hrtimer_get_res(CLOCK_MONOTONIC, &tp);
128 if (tp.tv_sec > 0 || !tp.tv_nsec) { 128 if (tp.tv_sec > 0 || !tp.tv_nsec) {
129 snd_printk(KERN_ERR 129 pr_err("snd-hrtimer: Invalid resolution %u.%09u",
130 "snd-hrtimer: Invalid resolution %u.%09u",
131 (unsigned)tp.tv_sec, (unsigned)tp.tv_nsec); 130 (unsigned)tp.tv_sec, (unsigned)tp.tv_nsec);
132 return -EINVAL; 131 return -EINVAL;
133 } 132 }
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index d105073298cb..69459e5f712e 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -375,7 +375,7 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
375 *rhwdep = NULL; 375 *rhwdep = NULL;
376 hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL); 376 hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL);
377 if (hwdep == NULL) { 377 if (hwdep == NULL) {
378 snd_printk(KERN_ERR "hwdep: cannot allocate\n"); 378 dev_err(card->dev, "hwdep: cannot allocate\n");
379 return -ENOMEM; 379 return -ENOMEM;
380 } 380 }
381 hwdep->card = card; 381 hwdep->card = card;
@@ -395,6 +395,7 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
395 *rhwdep = hwdep; 395 *rhwdep = hwdep;
396 return 0; 396 return 0;
397} 397}
398EXPORT_SYMBOL(snd_hwdep_new);
398 399
399static int snd_hwdep_free(struct snd_hwdep *hwdep) 400static int snd_hwdep_free(struct snd_hwdep *hwdep)
400{ 401{
@@ -415,37 +416,61 @@ static int snd_hwdep_dev_free(struct snd_device *device)
415static int snd_hwdep_dev_register(struct snd_device *device) 416static int snd_hwdep_dev_register(struct snd_device *device)
416{ 417{
417 struct snd_hwdep *hwdep = device->device_data; 418 struct snd_hwdep *hwdep = device->device_data;
419 struct snd_card *card = hwdep->card;
420 struct device *dev;
418 int err; 421 int err;
419 char name[32]; 422 char name[32];
420 423
421 mutex_lock(&register_mutex); 424 mutex_lock(&register_mutex);
422 if (snd_hwdep_search(hwdep->card, hwdep->device)) { 425 if (snd_hwdep_search(card, hwdep->device)) {
423 mutex_unlock(&register_mutex); 426 mutex_unlock(&register_mutex);
424 return -EBUSY; 427 return -EBUSY;
425 } 428 }
426 list_add_tail(&hwdep->list, &snd_hwdep_devices); 429 list_add_tail(&hwdep->list, &snd_hwdep_devices);
427 sprintf(name, "hwC%iD%i", hwdep->card->number, hwdep->device); 430 sprintf(name, "hwC%iD%i", hwdep->card->number, hwdep->device);
428 if ((err = snd_register_device(SNDRV_DEVICE_TYPE_HWDEP, 431 dev = hwdep->dev;
429 hwdep->card, hwdep->device, 432 if (!dev)
430 &snd_hwdep_f_ops, hwdep, name)) < 0) { 433 dev = snd_card_get_device_link(hwdep->card);
431 snd_printk(KERN_ERR "unable to register hardware dependent device %i:%i\n", 434 err = snd_register_device_for_dev(SNDRV_DEVICE_TYPE_HWDEP,
432 hwdep->card->number, hwdep->device); 435 hwdep->card, hwdep->device,
436 &snd_hwdep_f_ops, hwdep, name, dev);
437 if (err < 0) {
438 dev_err(dev,
439 "unable to register hardware dependent device %i:%i\n",
440 card->number, hwdep->device);
433 list_del(&hwdep->list); 441 list_del(&hwdep->list);
434 mutex_unlock(&register_mutex); 442 mutex_unlock(&register_mutex);
435 return err; 443 return err;
436 } 444 }
445
446 if (hwdep->groups) {
447 struct device *d = snd_get_device(SNDRV_DEVICE_TYPE_HWDEP,
448 hwdep->card, hwdep->device);
449 if (d) {
450 if (hwdep->private_data)
451 dev_set_drvdata(d, hwdep->private_data);
452 err = sysfs_create_groups(&d->kobj, hwdep->groups);
453 if (err < 0)
454 dev_warn(dev,
455 "hwdep %d:%d: cannot create sysfs groups\n",
456 card->number, hwdep->device);
457 put_device(d);
458 }
459 }
460
437#ifdef CONFIG_SND_OSSEMUL 461#ifdef CONFIG_SND_OSSEMUL
438 hwdep->ossreg = 0; 462 hwdep->ossreg = 0;
439 if (hwdep->oss_type >= 0) { 463 if (hwdep->oss_type >= 0) {
440 if ((hwdep->oss_type == SNDRV_OSS_DEVICE_TYPE_DMFM) && (hwdep->device != 0)) { 464 if ((hwdep->oss_type == SNDRV_OSS_DEVICE_TYPE_DMFM) && (hwdep->device != 0)) {
441 snd_printk (KERN_WARNING "only hwdep device 0 can be registered as OSS direct FM device!\n"); 465 dev_warn(dev,
466 "only hwdep device 0 can be registered as OSS direct FM device!\n");
442 } else { 467 } else {
443 if (snd_register_oss_device(hwdep->oss_type, 468 if (snd_register_oss_device(hwdep->oss_type,
444 hwdep->card, hwdep->device, 469 card, hwdep->device,
445 &snd_hwdep_f_ops, hwdep, 470 &snd_hwdep_f_ops, hwdep) < 0) {
446 hwdep->oss_dev) < 0) { 471 dev_err(dev,
447 snd_printk(KERN_ERR "unable to register OSS compatibility device %i:%i\n", 472 "unable to register OSS compatibility device %i:%i\n",
448 hwdep->card->number, hwdep->device); 473 card->number, hwdep->device);
449 } else 474 } else
450 hwdep->ossreg = 1; 475 hwdep->ossreg = 1;
451 } 476 }
@@ -543,5 +568,3 @@ static void __exit alsa_hwdep_exit(void)
543 568
544module_init(alsa_hwdep_init) 569module_init(alsa_hwdep_init)
545module_exit(alsa_hwdep_exit) 570module_exit(alsa_hwdep_exit)
546
547EXPORT_SYMBOL(snd_hwdep_new);
diff --git a/sound/core/info.c b/sound/core/info.c
index e79baa11b60e..051d55b05521 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -418,9 +418,14 @@ static int snd_info_entry_release(struct inode *inode, struct file *file)
418 if (entry->c.text.write) { 418 if (entry->c.text.write) {
419 entry->c.text.write(entry, data->wbuffer); 419 entry->c.text.write(entry, data->wbuffer);
420 if (data->wbuffer->error) { 420 if (data->wbuffer->error) {
421 snd_printk(KERN_WARNING "data write error to %s (%i)\n", 421 if (entry->card)
422 entry->name, 422 dev_warn(entry->card->dev, "info: data write error to %s (%i)\n",
423 data->wbuffer->error); 423 entry->name,
424 data->wbuffer->error);
425 else
426 pr_warn("ALSA: info: data write error to %s (%i)\n",
427 entry->name,
428 data->wbuffer->error);
424 } 429 }
425 } 430 }
426 kfree(data->wbuffer->buffer); 431 kfree(data->wbuffer->buffer);
@@ -540,7 +545,7 @@ int __init snd_info_init(void)
540 snd_oss_root = entry; 545 snd_oss_root = entry;
541 } 546 }
542#endif 547#endif
543#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE) 548#if IS_ENABLED(CONFIG_SND_SEQUENCER)
544 { 549 {
545 struct snd_info_entry *entry; 550 struct snd_info_entry *entry;
546 if ((entry = snd_info_create_module_entry(THIS_MODULE, "seq", NULL)) == NULL) 551 if ((entry = snd_info_create_module_entry(THIS_MODULE, "seq", NULL)) == NULL)
@@ -567,7 +572,7 @@ int __exit snd_info_done(void)
567 snd_minor_info_done(); 572 snd_minor_info_done();
568 snd_info_version_done(); 573 snd_info_version_done();
569 if (snd_proc_root) { 574 if (snd_proc_root) {
570#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE) 575#if IS_ENABLED(CONFIG_SND_SEQUENCER)
571 snd_info_free_entry(snd_seq_root); 576 snd_info_free_entry(snd_seq_root);
572#endif 577#endif
573#ifdef CONFIG_SND_OSSEMUL 578#ifdef CONFIG_SND_OSSEMUL
diff --git a/sound/core/init.c b/sound/core/init.c
index 0d42fcda0de2..5ee83845c5de 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -28,6 +28,7 @@
28#include <linux/time.h> 28#include <linux/time.h>
29#include <linux/ctype.h> 29#include <linux/ctype.h>
30#include <linux/pm.h> 30#include <linux/pm.h>
31#include <linux/completion.h>
31 32
32#include <sound/core.h> 33#include <sound/core.h>
33#include <sound/control.h> 34#include <sound/control.h>
@@ -94,7 +95,7 @@ static int module_slot_match(struct module *module, int idx)
94 return match; 95 return match;
95} 96}
96 97
97#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 98#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
98int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag); 99int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag);
99EXPORT_SYMBOL(snd_mixer_oss_notify_callback); 100EXPORT_SYMBOL(snd_mixer_oss_notify_callback);
100#endif 101#endif
@@ -112,11 +113,11 @@ static inline int init_info_for_card(struct snd_card *card)
112 struct snd_info_entry *entry; 113 struct snd_info_entry *entry;
113 114
114 if ((err = snd_info_card_register(card)) < 0) { 115 if ((err = snd_info_card_register(card)) < 0) {
115 snd_printd("unable to create card info\n"); 116 dev_dbg(card->dev, "unable to create card info\n");
116 return err; 117 return err;
117 } 118 }
118 if ((entry = snd_info_create_card_entry(card, "id", card->proc_root)) == NULL) { 119 if ((entry = snd_info_create_card_entry(card, "id", card->proc_root)) == NULL) {
119 snd_printd("unable to create card entry\n"); 120 dev_dbg(card->dev, "unable to create card entry\n");
120 return err; 121 return err;
121 } 122 }
122 entry->c.text.read = snd_card_id_read; 123 entry->c.text.read = snd_card_id_read;
@@ -156,8 +157,17 @@ static int get_slot_from_bitmask(int mask, int (*check)(struct module *, int),
156 return mask; /* unchanged */ 157 return mask; /* unchanged */
157} 158}
158 159
160static int snd_card_do_free(struct snd_card *card);
161static const struct attribute_group *card_dev_attr_groups[];
162
163static void release_card_device(struct device *dev)
164{
165 snd_card_do_free(dev_to_snd_card(dev));
166}
167
159/** 168/**
160 * snd_card_create - create and initialize a soundcard structure 169 * snd_card_new - create and initialize a soundcard structure
170 * @parent: the parent device object
161 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)] 171 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
162 * @xid: card identification (ASCII string) 172 * @xid: card identification (ASCII string)
163 * @module: top level module for locking 173 * @module: top level module for locking
@@ -172,7 +182,7 @@ static int get_slot_from_bitmask(int mask, int (*check)(struct module *, int),
172 * 182 *
173 * Return: Zero if successful or a negative error code. 183 * Return: Zero if successful or a negative error code.
174 */ 184 */
175int snd_card_create(int idx, const char *xid, 185int snd_card_new(struct device *parent, int idx, const char *xid,
176 struct module *module, int extra_size, 186 struct module *module, int extra_size,
177 struct snd_card **card_ret) 187 struct snd_card **card_ret)
178{ 188{
@@ -188,6 +198,8 @@ int snd_card_create(int idx, const char *xid,
188 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); 198 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL);
189 if (!card) 199 if (!card)
190 return -ENOMEM; 200 return -ENOMEM;
201 if (extra_size > 0)
202 card->private_data = (char *)card + sizeof(struct snd_card);
191 if (xid) 203 if (xid)
192 strlcpy(card->id, xid, sizeof(card->id)); 204 strlcpy(card->id, xid, sizeof(card->id));
193 err = 0; 205 err = 0;
@@ -205,14 +217,16 @@ int snd_card_create(int idx, const char *xid,
205 err = -ENODEV; 217 err = -ENODEV;
206 if (err < 0) { 218 if (err < 0) {
207 mutex_unlock(&snd_card_mutex); 219 mutex_unlock(&snd_card_mutex);
208 snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i), error: %d\n", 220 dev_err(parent, "cannot find the slot for index %d (range 0-%i), error: %d\n",
209 idx, snd_ecards_limit - 1, err); 221 idx, snd_ecards_limit - 1, err);
210 goto __error; 222 kfree(card);
223 return err;
211 } 224 }
212 set_bit(idx, snd_cards_lock); /* lock it */ 225 set_bit(idx, snd_cards_lock); /* lock it */
213 if (idx >= snd_ecards_limit) 226 if (idx >= snd_ecards_limit)
214 snd_ecards_limit = idx + 1; /* increase the limit */ 227 snd_ecards_limit = idx + 1; /* increase the limit */
215 mutex_unlock(&snd_card_mutex); 228 mutex_unlock(&snd_card_mutex);
229 card->dev = parent;
216 card->number = idx; 230 card->number = idx;
217 card->module = module; 231 card->module = module;
218 INIT_LIST_HEAD(&card->devices); 232 INIT_LIST_HEAD(&card->devices);
@@ -222,36 +236,42 @@ int snd_card_create(int idx, const char *xid,
222 INIT_LIST_HEAD(&card->ctl_files); 236 INIT_LIST_HEAD(&card->ctl_files);
223 spin_lock_init(&card->files_lock); 237 spin_lock_init(&card->files_lock);
224 INIT_LIST_HEAD(&card->files_list); 238 INIT_LIST_HEAD(&card->files_list);
225 init_waitqueue_head(&card->shutdown_sleep);
226 atomic_set(&card->refcount, 0);
227#ifdef CONFIG_PM 239#ifdef CONFIG_PM
228 mutex_init(&card->power_lock); 240 mutex_init(&card->power_lock);
229 init_waitqueue_head(&card->power_sleep); 241 init_waitqueue_head(&card->power_sleep);
230#endif 242#endif
243
244 device_initialize(&card->card_dev);
245 card->card_dev.parent = parent;
246 card->card_dev.class = sound_class;
247 card->card_dev.release = release_card_device;
248 card->card_dev.groups = card_dev_attr_groups;
249 err = kobject_set_name(&card->card_dev.kobj, "card%d", idx);
250 if (err < 0)
251 goto __error;
252
231 /* the control interface cannot be accessed from the user space until */ 253 /* the control interface cannot be accessed from the user space until */
232 /* snd_cards_bitmask and snd_cards are set with snd_card_register */ 254 /* snd_cards_bitmask and snd_cards are set with snd_card_register */
233 err = snd_ctl_create(card); 255 err = snd_ctl_create(card);
234 if (err < 0) { 256 if (err < 0) {
235 snd_printk(KERN_ERR "unable to register control minors\n"); 257 dev_err(parent, "unable to register control minors\n");
236 goto __error; 258 goto __error;
237 } 259 }
238 err = snd_info_card_create(card); 260 err = snd_info_card_create(card);
239 if (err < 0) { 261 if (err < 0) {
240 snd_printk(KERN_ERR "unable to create card info\n"); 262 dev_err(parent, "unable to create card info\n");
241 goto __error_ctl; 263 goto __error_ctl;
242 } 264 }
243 if (extra_size > 0)
244 card->private_data = (char *)card + sizeof(struct snd_card);
245 *card_ret = card; 265 *card_ret = card;
246 return 0; 266 return 0;
247 267
248 __error_ctl: 268 __error_ctl:
249 snd_device_free_all(card, SNDRV_DEV_CMD_PRE); 269 snd_device_free_all(card);
250 __error: 270 __error:
251 kfree(card); 271 put_device(&card->card_dev);
252 return err; 272 return err;
253} 273}
254EXPORT_SYMBOL(snd_card_create); 274EXPORT_SYMBOL(snd_card_new);
255 275
256/* return non-zero if a card is already locked */ 276/* return non-zero if a card is already locked */
257int snd_card_locked(int card) 277int snd_card_locked(int card)
@@ -394,7 +414,7 @@ int snd_card_disconnect(struct snd_card *card)
394 /* phase 3: notify all connected devices about disconnection */ 414 /* phase 3: notify all connected devices about disconnection */
395 /* at this point, they cannot respond to any calls except release() */ 415 /* at this point, they cannot respond to any calls except release() */
396 416
397#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 417#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
398 if (snd_mixer_oss_notify_callback) 418 if (snd_mixer_oss_notify_callback)
399 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_DISCONNECT); 419 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_DISCONNECT);
400#endif 420#endif
@@ -402,12 +422,12 @@ int snd_card_disconnect(struct snd_card *card)
402 /* notify all devices that we are disconnected */ 422 /* notify all devices that we are disconnected */
403 err = snd_device_disconnect_all(card); 423 err = snd_device_disconnect_all(card);
404 if (err < 0) 424 if (err < 0)
405 snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number); 425 dev_err(card->dev, "not all devices for card %i can be disconnected\n", card->number);
406 426
407 snd_info_card_disconnect(card); 427 snd_info_card_disconnect(card);
408 if (card->card_dev) { 428 if (card->registered) {
409 device_unregister(card->card_dev); 429 device_del(&card->card_dev);
410 card->card_dev = NULL; 430 card->registered = false;
411 } 431 }
412#ifdef CONFIG_PM 432#ifdef CONFIG_PM
413 wake_up(&card->power_sleep); 433 wake_up(&card->power_sleep);
@@ -430,81 +450,48 @@ EXPORT_SYMBOL(snd_card_disconnect);
430 */ 450 */
431static int snd_card_do_free(struct snd_card *card) 451static int snd_card_do_free(struct snd_card *card)
432{ 452{
433#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 453#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
434 if (snd_mixer_oss_notify_callback) 454 if (snd_mixer_oss_notify_callback)
435 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE); 455 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE);
436#endif 456#endif
437 if (snd_device_free_all(card, SNDRV_DEV_CMD_PRE) < 0) { 457 snd_device_free_all(card);
438 snd_printk(KERN_ERR "unable to free all devices (pre)\n");
439 /* Fatal, but this situation should never occur */
440 }
441 if (snd_device_free_all(card, SNDRV_DEV_CMD_NORMAL) < 0) {
442 snd_printk(KERN_ERR "unable to free all devices (normal)\n");
443 /* Fatal, but this situation should never occur */
444 }
445 if (snd_device_free_all(card, SNDRV_DEV_CMD_POST) < 0) {
446 snd_printk(KERN_ERR "unable to free all devices (post)\n");
447 /* Fatal, but this situation should never occur */
448 }
449 if (card->private_free) 458 if (card->private_free)
450 card->private_free(card); 459 card->private_free(card);
451 snd_info_free_entry(card->proc_id); 460 snd_info_free_entry(card->proc_id);
452 if (snd_info_card_free(card) < 0) { 461 if (snd_info_card_free(card) < 0) {
453 snd_printk(KERN_WARNING "unable to free card info\n"); 462 dev_warn(card->dev, "unable to free card info\n");
454 /* Not fatal error */ 463 /* Not fatal error */
455 } 464 }
465 if (card->release_completion)
466 complete(card->release_completion);
456 kfree(card); 467 kfree(card);
457 return 0; 468 return 0;
458} 469}
459 470
460/**
461 * snd_card_unref - release the reference counter
462 * @card: the card instance
463 *
464 * Decrements the reference counter. When it reaches to zero, wake up
465 * the sleeper and call the destructor if needed.
466 */
467void snd_card_unref(struct snd_card *card)
468{
469 if (atomic_dec_and_test(&card->refcount)) {
470 wake_up(&card->shutdown_sleep);
471 if (card->free_on_last_close)
472 snd_card_do_free(card);
473 }
474}
475EXPORT_SYMBOL(snd_card_unref);
476
477int snd_card_free_when_closed(struct snd_card *card) 471int snd_card_free_when_closed(struct snd_card *card)
478{ 472{
479 int ret; 473 int ret = snd_card_disconnect(card);
480 474 if (ret)
481 atomic_inc(&card->refcount);
482 ret = snd_card_disconnect(card);
483 if (ret) {
484 atomic_dec(&card->refcount);
485 return ret; 475 return ret;
486 } 476 put_device(&card->card_dev);
487
488 card->free_on_last_close = 1;
489 if (atomic_dec_and_test(&card->refcount))
490 snd_card_do_free(card);
491 return 0; 477 return 0;
492} 478}
493
494EXPORT_SYMBOL(snd_card_free_when_closed); 479EXPORT_SYMBOL(snd_card_free_when_closed);
495 480
496int snd_card_free(struct snd_card *card) 481int snd_card_free(struct snd_card *card)
497{ 482{
498 int ret = snd_card_disconnect(card); 483 struct completion released;
484 int ret;
485
486 init_completion(&released);
487 card->release_completion = &released;
488 ret = snd_card_free_when_closed(card);
499 if (ret) 489 if (ret)
500 return ret; 490 return ret;
501
502 /* wait, until all devices are ready for the free operation */ 491 /* wait, until all devices are ready for the free operation */
503 wait_event(card->shutdown_sleep, !atomic_read(&card->refcount)); 492 wait_for_completion(&released);
504 snd_card_do_free(card);
505 return 0; 493 return 0;
506} 494}
507
508EXPORT_SYMBOL(snd_card_free); 495EXPORT_SYMBOL(snd_card_free);
509 496
510/* retrieve the last word of shortname or longname */ 497/* retrieve the last word of shortname or longname */
@@ -598,7 +585,7 @@ static void snd_card_set_id_no_lock(struct snd_card *card, const char *src,
598 goto again; 585 goto again;
599 } 586 }
600 /* last resort... */ 587 /* last resort... */
601 snd_printk(KERN_ERR "unable to set card id (%s)\n", id); 588 dev_err(card->dev, "unable to set card id (%s)\n", id);
602 if (card->proc_root->name) 589 if (card->proc_root->name)
603 strlcpy(card->id, card->proc_root->name, sizeof(card->id)); 590 strlcpy(card->id, card->proc_root->name, sizeof(card->id));
604} 591}
@@ -626,15 +613,15 @@ static ssize_t
626card_id_show_attr(struct device *dev, 613card_id_show_attr(struct device *dev,
627 struct device_attribute *attr, char *buf) 614 struct device_attribute *attr, char *buf)
628{ 615{
629 struct snd_card *card = dev_get_drvdata(dev); 616 struct snd_card *card = container_of(dev, struct snd_card, card_dev);
630 return snprintf(buf, PAGE_SIZE, "%s\n", card ? card->id : "(null)"); 617 return snprintf(buf, PAGE_SIZE, "%s\n", card->id);
631} 618}
632 619
633static ssize_t 620static ssize_t
634card_id_store_attr(struct device *dev, struct device_attribute *attr, 621card_id_store_attr(struct device *dev, struct device_attribute *attr,
635 const char *buf, size_t count) 622 const char *buf, size_t count)
636{ 623{
637 struct snd_card *card = dev_get_drvdata(dev); 624 struct snd_card *card = container_of(dev, struct snd_card, card_dev);
638 char buf1[sizeof(card->id)]; 625 char buf1[sizeof(card->id)];
639 size_t copy = count > sizeof(card->id) - 1 ? 626 size_t copy = count > sizeof(card->id) - 1 ?
640 sizeof(card->id) - 1 : count; 627 sizeof(card->id) - 1 : count;
@@ -660,19 +647,32 @@ card_id_store_attr(struct device *dev, struct device_attribute *attr,
660 return count; 647 return count;
661} 648}
662 649
663static struct device_attribute card_id_attrs = 650static DEVICE_ATTR(id, S_IRUGO | S_IWUSR, card_id_show_attr, card_id_store_attr);
664 __ATTR(id, S_IRUGO | S_IWUSR, card_id_show_attr, card_id_store_attr);
665 651
666static ssize_t 652static ssize_t
667card_number_show_attr(struct device *dev, 653card_number_show_attr(struct device *dev,
668 struct device_attribute *attr, char *buf) 654 struct device_attribute *attr, char *buf)
669{ 655{
670 struct snd_card *card = dev_get_drvdata(dev); 656 struct snd_card *card = container_of(dev, struct snd_card, card_dev);
671 return snprintf(buf, PAGE_SIZE, "%i\n", card ? card->number : -1); 657 return snprintf(buf, PAGE_SIZE, "%i\n", card->number);
672} 658}
673 659
674static struct device_attribute card_number_attrs = 660static DEVICE_ATTR(number, S_IRUGO, card_number_show_attr, NULL);
675 __ATTR(number, S_IRUGO, card_number_show_attr, NULL); 661
662static struct attribute *card_dev_attrs[] = {
663 &dev_attr_id.attr,
664 &dev_attr_number.attr,
665 NULL
666};
667
668static struct attribute_group card_dev_attr_group = {
669 .attrs = card_dev_attrs,
670};
671
672static const struct attribute_group *card_dev_attr_groups[] = {
673 &card_dev_attr_group,
674 NULL
675};
676 676
677/** 677/**
678 * snd_card_register - register the soundcard 678 * snd_card_register - register the soundcard
@@ -692,12 +692,11 @@ int snd_card_register(struct snd_card *card)
692 if (snd_BUG_ON(!card)) 692 if (snd_BUG_ON(!card))
693 return -EINVAL; 693 return -EINVAL;
694 694
695 if (!card->card_dev) { 695 if (!card->registered) {
696 card->card_dev = device_create(sound_class, card->dev, 696 err = device_add(&card->card_dev);
697 MKDEV(0, 0), card, 697 if (err < 0)
698 "card%i", card->number); 698 return err;
699 if (IS_ERR(card->card_dev)) 699 card->registered = true;
700 card->card_dev = NULL;
701 } 700 }
702 701
703 if ((err = snd_device_register_all(card)) < 0) 702 if ((err = snd_device_register_all(card)) < 0)
@@ -723,19 +722,10 @@ int snd_card_register(struct snd_card *card)
723 snd_cards[card->number] = card; 722 snd_cards[card->number] = card;
724 mutex_unlock(&snd_card_mutex); 723 mutex_unlock(&snd_card_mutex);
725 init_info_for_card(card); 724 init_info_for_card(card);
726#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 725#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
727 if (snd_mixer_oss_notify_callback) 726 if (snd_mixer_oss_notify_callback)
728 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER); 727 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER);
729#endif 728#endif
730 if (card->card_dev) {
731 err = device_create_file(card->card_dev, &card_id_attrs);
732 if (err < 0)
733 return err;
734 err = device_create_file(card->card_dev, &card_number_attrs);
735 if (err < 0)
736 return err;
737 }
738
739 return 0; 729 return 0;
740} 730}
741 731
@@ -908,7 +898,7 @@ int snd_card_file_add(struct snd_card *card, struct file *file)
908 return -ENODEV; 898 return -ENODEV;
909 } 899 }
910 list_add(&mfile->list, &card->files_list); 900 list_add(&mfile->list, &card->files_list);
911 atomic_inc(&card->refcount); 901 get_device(&card->card_dev);
912 spin_unlock(&card->files_lock); 902 spin_unlock(&card->files_lock);
913 return 0; 903 return 0;
914} 904}
@@ -947,11 +937,11 @@ int snd_card_file_remove(struct snd_card *card, struct file *file)
947 } 937 }
948 spin_unlock(&card->files_lock); 938 spin_unlock(&card->files_lock);
949 if (!found) { 939 if (!found) {
950 snd_printk(KERN_ERR "ALSA card file remove problem (%p)\n", file); 940 dev_err(card->dev, "card file remove problem (%p)\n", file);
951 return -ENOENT; 941 return -ENOENT;
952 } 942 }
953 kfree(found); 943 kfree(found);
954 snd_card_unref(card); 944 put_device(&card->card_dev);
955 return 0; 945 return 0;
956} 946}
957 947
diff --git a/sound/core/isadma.c b/sound/core/isadma.c
index e2b386156a4c..31e8544d7f2d 100644
--- a/sound/core/isadma.c
+++ b/sound/core/isadma.c
@@ -106,7 +106,7 @@ unsigned int snd_dma_pointer(unsigned long dma, unsigned int size)
106 result = result1; 106 result = result1;
107#ifdef CONFIG_SND_DEBUG 107#ifdef CONFIG_SND_DEBUG
108 if (result > size) 108 if (result > size)
109 snd_printk(KERN_ERR "pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size); 109 pr_err("ALSA: pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size);
110#endif 110#endif
111 if (result >= size || result == 0) 111 if (result >= size || result == 0)
112 return 0; 112 return 0;
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 4595f93d151e..082509eb805d 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -207,7 +207,7 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
207 break; 207 break;
208#endif 208#endif
209 default: 209 default:
210 printk(KERN_ERR "snd-malloc: invalid device type %d\n", type); 210 pr_err("snd-malloc: invalid device type %d\n", type);
211 dmab->area = NULL; 211 dmab->area = NULL;
212 dmab->addr = 0; 212 dmab->addr = 0;
213 return -ENXIO; 213 return -ENXIO;
@@ -284,7 +284,7 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
284 break; 284 break;
285#endif 285#endif
286 default: 286 default:
287 printk(KERN_ERR "snd-malloc: invalid device type %d\n", dmab->dev.type); 287 pr_err("snd-malloc: invalid device type %d\n", dmab->dev.type);
288 } 288 }
289} 289}
290 290
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index e8a1d18774b2..5e6349f00ecd 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1187,7 +1187,8 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
1187 if (oss_mixer_names[ch] && strcmp(oss_mixer_names[ch], str) == 0) 1187 if (oss_mixer_names[ch] && strcmp(oss_mixer_names[ch], str) == 0)
1188 break; 1188 break;
1189 if (ch >= SNDRV_OSS_MAX_MIXERS) { 1189 if (ch >= SNDRV_OSS_MAX_MIXERS) {
1190 snd_printk(KERN_ERR "mixer_oss: invalid OSS volume '%s'\n", str); 1190 pr_err("ALSA: mixer_oss: invalid OSS volume '%s'\n",
1191 str);
1191 continue; 1192 continue;
1192 } 1193 }
1193 cptr = snd_info_get_str(str, cptr, sizeof(str)); 1194 cptr = snd_info_get_str(str, cptr, sizeof(str));
@@ -1201,7 +1202,7 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
1201 snd_info_get_str(idxstr, cptr, sizeof(idxstr)); 1202 snd_info_get_str(idxstr, cptr, sizeof(idxstr));
1202 idx = simple_strtoul(idxstr, NULL, 10); 1203 idx = simple_strtoul(idxstr, NULL, 10);
1203 if (idx >= 0x4000) { /* too big */ 1204 if (idx >= 0x4000) { /* too big */
1204 snd_printk(KERN_ERR "mixer_oss: invalid index %d\n", idx); 1205 pr_err("ALSA: mixer_oss: invalid index %d\n", idx);
1205 continue; 1206 continue;
1206 } 1207 }
1207 mutex_lock(&mixer->reg_mutex); 1208 mutex_lock(&mixer->reg_mutex);
@@ -1212,7 +1213,7 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
1212 goto __unlock; 1213 goto __unlock;
1213 tbl = kmalloc(sizeof(*tbl), GFP_KERNEL); 1214 tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
1214 if (! tbl) { 1215 if (! tbl) {
1215 snd_printk(KERN_ERR "mixer_oss: no memory\n"); 1216 pr_err("ALSA: mixer_oss: no memory\n");
1216 goto __unlock; 1217 goto __unlock;
1217 } 1218 }
1218 tbl->oss_id = ch; 1219 tbl->oss_id = ch;
@@ -1343,20 +1344,18 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)
1343 struct snd_mixer_oss *mixer; 1344 struct snd_mixer_oss *mixer;
1344 1345
1345 if (cmd == SND_MIXER_OSS_NOTIFY_REGISTER) { 1346 if (cmd == SND_MIXER_OSS_NOTIFY_REGISTER) {
1346 char name[128];
1347 int idx, err; 1347 int idx, err;
1348 1348
1349 mixer = kcalloc(2, sizeof(*mixer), GFP_KERNEL); 1349 mixer = kcalloc(2, sizeof(*mixer), GFP_KERNEL);
1350 if (mixer == NULL) 1350 if (mixer == NULL)
1351 return -ENOMEM; 1351 return -ENOMEM;
1352 mutex_init(&mixer->reg_mutex); 1352 mutex_init(&mixer->reg_mutex);
1353 sprintf(name, "mixer%i%i", card->number, 0);
1354 if ((err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, 1353 if ((err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER,
1355 card, 0, 1354 card, 0,
1356 &snd_mixer_oss_f_ops, card, 1355 &snd_mixer_oss_f_ops, card)) < 0) {
1357 name)) < 0) { 1356 dev_err(card->dev,
1358 snd_printk(KERN_ERR "unable to register OSS mixer device %i:%i\n", 1357 "unable to register OSS mixer device %i:%i\n",
1359 card->number, 0); 1358 card->number, 0);
1360 kfree(mixer); 1359 kfree(mixer);
1361 return err; 1360 return err;
1362 } 1361 }
@@ -1365,7 +1364,8 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)
1365 if (*card->mixername) 1364 if (*card->mixername)
1366 strlcpy(mixer->name, card->mixername, sizeof(mixer->name)); 1365 strlcpy(mixer->name, card->mixername, sizeof(mixer->name));
1367 else 1366 else
1368 strlcpy(mixer->name, name, sizeof(mixer->name)); 1367 snprintf(mixer->name, sizeof(mixer->name),
1368 "mixer%i", card->number);
1369#ifdef SNDRV_OSS_INFO_DEV_MIXERS 1369#ifdef SNDRV_OSS_INFO_DEV_MIXERS
1370 snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIXERS, 1370 snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIXERS,
1371 card->number, 1371 card->number,
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 4c1cc51772e6..ada69d7a8d70 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -854,7 +854,7 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
854 params = kmalloc(sizeof(*params), GFP_KERNEL); 854 params = kmalloc(sizeof(*params), GFP_KERNEL);
855 sparams = kmalloc(sizeof(*sparams), GFP_KERNEL); 855 sparams = kmalloc(sizeof(*sparams), GFP_KERNEL);
856 if (!sw_params || !params || !sparams) { 856 if (!sw_params || !params || !sparams) {
857 snd_printd("No memory\n"); 857 pcm_dbg(substream->pcm, "No memory\n");
858 err = -ENOMEM; 858 err = -ENOMEM;
859 goto failure; 859 goto failure;
860 } 860 }
@@ -877,7 +877,7 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
877 } 877 }
878 err = snd_pcm_hw_param_mask(substream, sparams, SNDRV_PCM_HW_PARAM_ACCESS, &mask); 878 err = snd_pcm_hw_param_mask(substream, sparams, SNDRV_PCM_HW_PARAM_ACCESS, &mask);
879 if (err < 0) { 879 if (err < 0) {
880 snd_printd("No usable accesses\n"); 880 pcm_dbg(substream->pcm, "No usable accesses\n");
881 err = -EINVAL; 881 err = -EINVAL;
882 goto failure; 882 goto failure;
883 } 883 }
@@ -902,7 +902,7 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
902 break; 902 break;
903 } 903 }
904 if ((__force int)sformat > (__force int)SNDRV_PCM_FORMAT_LAST) { 904 if ((__force int)sformat > (__force int)SNDRV_PCM_FORMAT_LAST) {
905 snd_printd("Cannot find a format!!!\n"); 905 pcm_dbg(substream->pcm, "Cannot find a format!!!\n");
906 err = -EINVAL; 906 err = -EINVAL;
907 goto failure; 907 goto failure;
908 } 908 }
@@ -942,14 +942,16 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
942 if ((err = snd_pcm_plug_format_plugins(substream, 942 if ((err = snd_pcm_plug_format_plugins(substream,
943 params, 943 params,
944 sparams)) < 0) { 944 sparams)) < 0) {
945 snd_printd("snd_pcm_plug_format_plugins failed: %i\n", err); 945 pcm_dbg(substream->pcm,
946 "snd_pcm_plug_format_plugins failed: %i\n", err);
946 snd_pcm_oss_plugin_clear(substream); 947 snd_pcm_oss_plugin_clear(substream);
947 goto failure; 948 goto failure;
948 } 949 }
949 if (runtime->oss.plugin_first) { 950 if (runtime->oss.plugin_first) {
950 struct snd_pcm_plugin *plugin; 951 struct snd_pcm_plugin *plugin;
951 if ((err = snd_pcm_plugin_build_io(substream, sparams, &plugin)) < 0) { 952 if ((err = snd_pcm_plugin_build_io(substream, sparams, &plugin)) < 0) {
952 snd_printd("snd_pcm_plugin_build_io failed: %i\n", err); 953 pcm_dbg(substream->pcm,
954 "snd_pcm_plugin_build_io failed: %i\n", err);
953 snd_pcm_oss_plugin_clear(substream); 955 snd_pcm_oss_plugin_clear(substream);
954 goto failure; 956 goto failure;
955 } 957 }
@@ -983,7 +985,7 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
983 snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); 985 snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
984 986
985 if ((err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_HW_PARAMS, sparams)) < 0) { 987 if ((err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_HW_PARAMS, sparams)) < 0) {
986 snd_printd("HW_PARAMS failed: %i\n", err); 988 pcm_dbg(substream->pcm, "HW_PARAMS failed: %i\n", err);
987 goto failure; 989 goto failure;
988 } 990 }
989 991
@@ -1016,7 +1018,7 @@ static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream)
1016 } 1018 }
1017 1019
1018 if ((err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_SW_PARAMS, sw_params)) < 0) { 1020 if ((err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_SW_PARAMS, sw_params)) < 0) {
1019 snd_printd("SW_PARAMS failed: %i\n", err); 1021 pcm_dbg(substream->pcm, "SW_PARAMS failed: %i\n", err);
1020 goto failure; 1022 goto failure;
1021 } 1023 }
1022 1024
@@ -1110,7 +1112,8 @@ static int snd_pcm_oss_prepare(struct snd_pcm_substream *substream)
1110 1112
1111 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_PREPARE, NULL); 1113 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_PREPARE, NULL);
1112 if (err < 0) { 1114 if (err < 0) {
1113 snd_printd("snd_pcm_oss_prepare: SNDRV_PCM_IOCTL_PREPARE failed\n"); 1115 pcm_dbg(substream->pcm,
1116 "snd_pcm_oss_prepare: SNDRV_PCM_IOCTL_PREPARE failed\n");
1114 return err; 1117 return err;
1115 } 1118 }
1116 runtime->oss.prepare = 0; 1119 runtime->oss.prepare = 0;
@@ -1175,12 +1178,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
1175 if (runtime->status->state == SNDRV_PCM_STATE_XRUN || 1178 if (runtime->status->state == SNDRV_PCM_STATE_XRUN ||
1176 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1179 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1177#ifdef OSS_DEBUG 1180#ifdef OSS_DEBUG
1178 if (runtime->status->state == SNDRV_PCM_STATE_XRUN) 1181 pcm_dbg(substream->pcm,
1179 printk(KERN_DEBUG "pcm_oss: write: " 1182 "pcm_oss: write: recovering from %s\n",
1180 "recovering from XRUN\n"); 1183 runtime->status->state == SNDRV_PCM_STATE_XRUN ?
1181 else 1184 "XRUN" : "SUSPEND");
1182 printk(KERN_DEBUG "pcm_oss: write: "
1183 "recovering from SUSPEND\n");
1184#endif 1185#endif
1185 ret = snd_pcm_oss_prepare(substream); 1186 ret = snd_pcm_oss_prepare(substream);
1186 if (ret < 0) 1187 if (ret < 0)
@@ -1213,12 +1214,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
1213 if (runtime->status->state == SNDRV_PCM_STATE_XRUN || 1214 if (runtime->status->state == SNDRV_PCM_STATE_XRUN ||
1214 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1215 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1215#ifdef OSS_DEBUG 1216#ifdef OSS_DEBUG
1216 if (runtime->status->state == SNDRV_PCM_STATE_XRUN) 1217 pcm_dbg(substream->pcm,
1217 printk(KERN_DEBUG "pcm_oss: read: " 1218 "pcm_oss: read: recovering from %s\n",
1218 "recovering from XRUN\n"); 1219 runtime->status->state == SNDRV_PCM_STATE_XRUN ?
1219 else 1220 "XRUN" : "SUSPEND");
1220 printk(KERN_DEBUG "pcm_oss: read: "
1221 "recovering from SUSPEND\n");
1222#endif 1221#endif
1223 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL); 1222 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL);
1224 if (ret < 0) 1223 if (ret < 0)
@@ -1261,12 +1260,10 @@ snd_pcm_sframes_t snd_pcm_oss_writev3(struct snd_pcm_substream *substream, void
1261 if (runtime->status->state == SNDRV_PCM_STATE_XRUN || 1260 if (runtime->status->state == SNDRV_PCM_STATE_XRUN ||
1262 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1261 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1263#ifdef OSS_DEBUG 1262#ifdef OSS_DEBUG
1264 if (runtime->status->state == SNDRV_PCM_STATE_XRUN) 1263 pcm_dbg(substream->pcm,
1265 printk(KERN_DEBUG "pcm_oss: writev: " 1264 "pcm_oss: writev: recovering from %s\n",
1266 "recovering from XRUN\n"); 1265 runtime->status->state == SNDRV_PCM_STATE_XRUN ?
1267 else 1266 "XRUN" : "SUSPEND");
1268 printk(KERN_DEBUG "pcm_oss: writev: "
1269 "recovering from SUSPEND\n");
1270#endif 1267#endif
1271 ret = snd_pcm_oss_prepare(substream); 1268 ret = snd_pcm_oss_prepare(substream);
1272 if (ret < 0) 1269 if (ret < 0)
@@ -1299,12 +1296,10 @@ snd_pcm_sframes_t snd_pcm_oss_readv3(struct snd_pcm_substream *substream, void *
1299 if (runtime->status->state == SNDRV_PCM_STATE_XRUN || 1296 if (runtime->status->state == SNDRV_PCM_STATE_XRUN ||
1300 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1297 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1301#ifdef OSS_DEBUG 1298#ifdef OSS_DEBUG
1302 if (runtime->status->state == SNDRV_PCM_STATE_XRUN) 1299 pcm_dbg(substream->pcm,
1303 printk(KERN_DEBUG "pcm_oss: readv: " 1300 "pcm_oss: readv: recovering from %s\n",
1304 "recovering from XRUN\n"); 1301 runtime->status->state == SNDRV_PCM_STATE_XRUN ?
1305 else 1302 "XRUN" : "SUSPEND");
1306 printk(KERN_DEBUG "pcm_oss: readv: "
1307 "recovering from SUSPEND\n");
1308#endif 1303#endif
1309 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL); 1304 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL);
1310 if (ret < 0) 1305 if (ret < 0)
@@ -1561,7 +1556,7 @@ static int snd_pcm_oss_sync1(struct snd_pcm_substream *substream, size_t size)
1561 init_waitqueue_entry(&wait, current); 1556 init_waitqueue_entry(&wait, current);
1562 add_wait_queue(&runtime->sleep, &wait); 1557 add_wait_queue(&runtime->sleep, &wait);
1563#ifdef OSS_DEBUG 1558#ifdef OSS_DEBUG
1564 printk(KERN_DEBUG "sync1: size = %li\n", size); 1559 pcm_dbg(substream->pcm, "sync1: size = %li\n", size);
1565#endif 1560#endif
1566 while (1) { 1561 while (1) {
1567 result = snd_pcm_oss_write2(substream, runtime->oss.buffer, size, 1); 1562 result = snd_pcm_oss_write2(substream, runtime->oss.buffer, size, 1);
@@ -1587,7 +1582,8 @@ static int snd_pcm_oss_sync1(struct snd_pcm_substream *substream, size_t size)
1587 break; 1582 break;
1588 } 1583 }
1589 if (res == 0) { 1584 if (res == 0) {
1590 snd_printk(KERN_ERR "OSS sync error - DMA timeout\n"); 1585 pcm_err(substream->pcm,
1586 "OSS sync error - DMA timeout\n");
1591 result = -EIO; 1587 result = -EIO;
1592 break; 1588 break;
1593 } 1589 }
@@ -1618,7 +1614,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
1618 mutex_lock(&runtime->oss.params_lock); 1614 mutex_lock(&runtime->oss.params_lock);
1619 if (runtime->oss.buffer_used > 0) { 1615 if (runtime->oss.buffer_used > 0) {
1620#ifdef OSS_DEBUG 1616#ifdef OSS_DEBUG
1621 printk(KERN_DEBUG "sync: buffer_used\n"); 1617 pcm_dbg(substream->pcm, "sync: buffer_used\n");
1622#endif 1618#endif
1623 size = (8 * (runtime->oss.period_bytes - runtime->oss.buffer_used) + 7) / width; 1619 size = (8 * (runtime->oss.period_bytes - runtime->oss.buffer_used) + 7) / width;
1624 snd_pcm_format_set_silence(format, 1620 snd_pcm_format_set_silence(format,
@@ -1631,7 +1627,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
1631 } 1627 }
1632 } else if (runtime->oss.period_ptr > 0) { 1628 } else if (runtime->oss.period_ptr > 0) {
1633#ifdef OSS_DEBUG 1629#ifdef OSS_DEBUG
1634 printk(KERN_DEBUG "sync: period_ptr\n"); 1630 pcm_dbg(substream->pcm, "sync: period_ptr\n");
1635#endif 1631#endif
1636 size = runtime->oss.period_bytes - runtime->oss.period_ptr; 1632 size = runtime->oss.period_bytes - runtime->oss.period_ptr;
1637 snd_pcm_format_set_silence(format, 1633 snd_pcm_format_set_silence(format,
@@ -1983,7 +1979,7 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr
1983 int err, cmd; 1979 int err, cmd;
1984 1980
1985#ifdef OSS_DEBUG 1981#ifdef OSS_DEBUG
1986 printk(KERN_DEBUG "pcm_oss: trigger = 0x%x\n", trigger); 1982 pcm_dbg(substream->pcm, "pcm_oss: trigger = 0x%x\n", trigger);
1987#endif 1983#endif
1988 1984
1989 psubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK]; 1985 psubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
@@ -2203,9 +2199,9 @@ static int snd_pcm_oss_get_space(struct snd_pcm_oss_file *pcm_oss_file, int stre
2203 } 2199 }
2204 2200
2205#ifdef OSS_DEBUG 2201#ifdef OSS_DEBUG
2206 printk(KERN_DEBUG "pcm_oss: space: bytes = %i, fragments = %i, " 2202 pcm_dbg(substream->pcm,
2207 "fragstotal = %i, fragsize = %i\n", 2203 "pcm_oss: space: bytes = %i, fragments = %i, fragstotal = %i, fragsize = %i\n",
2208 info.bytes, info.fragments, info.fragstotal, info.fragsize); 2204 info.bytes, info.fragments, info.fragstotal, info.fragsize);
2209#endif 2205#endif
2210 if (copy_to_user(_info, &info, sizeof(info))) 2206 if (copy_to_user(_info, &info, sizeof(info)))
2211 return -EFAULT; 2207 return -EFAULT;
@@ -2215,7 +2211,7 @@ static int snd_pcm_oss_get_space(struct snd_pcm_oss_file *pcm_oss_file, int stre
2215static int snd_pcm_oss_get_mapbuf(struct snd_pcm_oss_file *pcm_oss_file, int stream, struct buffmem_desc __user * _info) 2211static int snd_pcm_oss_get_mapbuf(struct snd_pcm_oss_file *pcm_oss_file, int stream, struct buffmem_desc __user * _info)
2216{ 2212{
2217 // it won't be probably implemented 2213 // it won't be probably implemented
2218 // snd_printd("TODO: snd_pcm_oss_get_mapbuf\n"); 2214 // pr_debug("TODO: snd_pcm_oss_get_mapbuf\n");
2219 return -EINVAL; 2215 return -EINVAL;
2220} 2216}
2221 2217
@@ -2519,7 +2515,7 @@ static long snd_pcm_oss_ioctl(struct file *file, unsigned int cmd, unsigned long
2519 if (((cmd >> 8) & 0xff) != 'P') 2515 if (((cmd >> 8) & 0xff) != 'P')
2520 return -EINVAL; 2516 return -EINVAL;
2521#ifdef OSS_DEBUG 2517#ifdef OSS_DEBUG
2522 printk(KERN_DEBUG "pcm_oss: ioctl = 0x%x\n", cmd); 2518 pr_debug("pcm_oss: ioctl = 0x%x\n", cmd);
2523#endif 2519#endif
2524 switch (cmd) { 2520 switch (cmd) {
2525 case SNDCTL_DSP_RESET: 2521 case SNDCTL_DSP_RESET:
@@ -2646,7 +2642,7 @@ static long snd_pcm_oss_ioctl(struct file *file, unsigned int cmd, unsigned long
2646 case SNDCTL_DSP_PROFILE: 2642 case SNDCTL_DSP_PROFILE:
2647 return 0; /* silently ignore */ 2643 return 0; /* silently ignore */
2648 default: 2644 default:
2649 snd_printd("pcm_oss: unknown command = 0x%x\n", cmd); 2645 pr_debug("pcm_oss: unknown command = 0x%x\n", cmd);
2650 } 2646 }
2651 return -EINVAL; 2647 return -EINVAL;
2652} 2648}
@@ -2673,8 +2669,9 @@ static ssize_t snd_pcm_oss_read(struct file *file, char __user *buf, size_t coun
2673#else 2669#else
2674 { 2670 {
2675 ssize_t res = snd_pcm_oss_read1(substream, buf, count); 2671 ssize_t res = snd_pcm_oss_read1(substream, buf, count);
2676 printk(KERN_DEBUG "pcm_oss: read %li bytes " 2672 pcm_dbg(substream->pcm,
2677 "(returned %li bytes)\n", (long)count, (long)res); 2673 "pcm_oss: read %li bytes (returned %li bytes)\n",
2674 (long)count, (long)res);
2678 return res; 2675 return res;
2679 } 2676 }
2680#endif 2677#endif
@@ -2693,7 +2690,7 @@ static ssize_t snd_pcm_oss_write(struct file *file, const char __user *buf, size
2693 substream->f_flags = file->f_flags & O_NONBLOCK; 2690 substream->f_flags = file->f_flags & O_NONBLOCK;
2694 result = snd_pcm_oss_write1(substream, buf, count); 2691 result = snd_pcm_oss_write1(substream, buf, count);
2695#ifdef OSS_DEBUG 2692#ifdef OSS_DEBUG
2696 printk(KERN_DEBUG "pcm_oss: write %li bytes (wrote %li bytes)\n", 2693 pcm_dbg(substream->pcm, "pcm_oss: write %li bytes (wrote %li bytes)\n",
2697 (long)count, (long)result); 2694 (long)count, (long)result);
2698#endif 2695#endif
2699 return result; 2696 return result;
@@ -2772,7 +2769,7 @@ static int snd_pcm_oss_mmap(struct file *file, struct vm_area_struct *area)
2772 int err; 2769 int err;
2773 2770
2774#ifdef OSS_DEBUG 2771#ifdef OSS_DEBUG
2775 printk(KERN_DEBUG "pcm_oss: mmap begin\n"); 2772 pr_debug("pcm_oss: mmap begin\n");
2776#endif 2773#endif
2777 pcm_oss_file = file->private_data; 2774 pcm_oss_file = file->private_data;
2778 switch ((area->vm_flags & (VM_READ | VM_WRITE))) { 2775 switch ((area->vm_flags & (VM_READ | VM_WRITE))) {
@@ -2822,7 +2819,7 @@ static int snd_pcm_oss_mmap(struct file *file, struct vm_area_struct *area)
2822 runtime->silence_threshold = 0; 2819 runtime->silence_threshold = 0;
2823 runtime->silence_size = 0; 2820 runtime->silence_size = 0;
2824#ifdef OSS_DEBUG 2821#ifdef OSS_DEBUG
2825 printk(KERN_DEBUG "pcm_oss: mmap ok, bytes = 0x%x\n", 2822 pr_debug("pcm_oss: mmap ok, bytes = 0x%x\n",
2826 runtime->oss.mmap_bytes); 2823 runtime->oss.mmap_bytes);
2827#endif 2824#endif
2828 /* In mmap mode we never stop */ 2825 /* In mmap mode we never stop */
@@ -3007,12 +3004,10 @@ static const struct file_operations snd_pcm_oss_f_reg =
3007 3004
3008static void register_oss_dsp(struct snd_pcm *pcm, int index) 3005static void register_oss_dsp(struct snd_pcm *pcm, int index)
3009{ 3006{
3010 char name[128];
3011 sprintf(name, "dsp%i%i", pcm->card->number, pcm->device);
3012 if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM, 3007 if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
3013 pcm->card, index, &snd_pcm_oss_f_reg, 3008 pcm->card, index, &snd_pcm_oss_f_reg,
3014 pcm, name) < 0) { 3009 pcm) < 0) {
3015 snd_printk(KERN_ERR "unable to register OSS PCM device %i:%i\n", 3010 pcm_err(pcm, "unable to register OSS PCM device %i:%i\n",
3016 pcm->card->number, pcm->device); 3011 pcm->card->number, pcm->device);
3017 } 3012 }
3018} 3013}
@@ -3093,12 +3088,12 @@ static int __init alsa_pcm_oss_init(void)
3093 /* check device map table */ 3088 /* check device map table */
3094 for (i = 0; i < SNDRV_CARDS; i++) { 3089 for (i = 0; i < SNDRV_CARDS; i++) {
3095 if (dsp_map[i] < 0 || dsp_map[i] >= SNDRV_PCM_DEVICES) { 3090 if (dsp_map[i] < 0 || dsp_map[i] >= SNDRV_PCM_DEVICES) {
3096 snd_printk(KERN_ERR "invalid dsp_map[%d] = %d\n", 3091 pr_err("ALSA: pcm_oss: invalid dsp_map[%d] = %d\n",
3097 i, dsp_map[i]); 3092 i, dsp_map[i]);
3098 dsp_map[i] = 0; 3093 dsp_map[i] = 0;
3099 } 3094 }
3100 if (adsp_map[i] < 0 || adsp_map[i] >= SNDRV_PCM_DEVICES) { 3095 if (adsp_map[i] < 0 || adsp_map[i] >= SNDRV_PCM_DEVICES) {
3101 snd_printk(KERN_ERR "invalid adsp_map[%d] = %d\n", 3096 pr_err("ALSA: pcm_oss: invalid adsp_map[%d] = %d\n",
3102 i, adsp_map[i]); 3097 i, adsp_map[i]);
3103 adsp_map[i] = 1; 3098 adsp_map[i] = 1;
3104 } 3099 }
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index e1e9e0c999fe..43932e8dce66 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -295,7 +295,7 @@ static const char *snd_pcm_state_name(snd_pcm_state_t state)
295 return snd_pcm_state_names[(__force int)state]; 295 return snd_pcm_state_names[(__force int)state];
296} 296}
297 297
298#if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 298#if IS_ENABLED(CONFIG_SND_PCM_OSS)
299#include <linux/soundcard.h> 299#include <linux/soundcard.h>
300 300
301static const char *snd_pcm_oss_format_name(int format) 301static const char *snd_pcm_oss_format_name(int format)
@@ -338,7 +338,8 @@ static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream,
338 338
339 info = kmalloc(sizeof(*info), GFP_KERNEL); 339 info = kmalloc(sizeof(*info), GFP_KERNEL);
340 if (! info) { 340 if (! info) {
341 printk(KERN_DEBUG "snd_pcm_proc_info_read: cannot malloc\n"); 341 pcm_dbg(substream->pcm,
342 "snd_pcm_proc_info_read: cannot malloc\n");
342 return; 343 return;
343 } 344 }
344 345
@@ -398,7 +399,7 @@ static void snd_pcm_substream_proc_hw_params_read(struct snd_info_entry *entry,
398 snd_iprintf(buffer, "rate: %u (%u/%u)\n", runtime->rate, runtime->rate_num, runtime->rate_den); 399 snd_iprintf(buffer, "rate: %u (%u/%u)\n", runtime->rate, runtime->rate_num, runtime->rate_den);
399 snd_iprintf(buffer, "period_size: %lu\n", runtime->period_size); 400 snd_iprintf(buffer, "period_size: %lu\n", runtime->period_size);
400 snd_iprintf(buffer, "buffer_size: %lu\n", runtime->buffer_size); 401 snd_iprintf(buffer, "buffer_size: %lu\n", runtime->buffer_size);
401#if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 402#if IS_ENABLED(CONFIG_SND_PCM_OSS)
402 if (substream->oss.oss) { 403 if (substream->oss.oss) {
403 snd_iprintf(buffer, "OSS format: %s\n", snd_pcm_oss_format_name(runtime->oss.format)); 404 snd_iprintf(buffer, "OSS format: %s\n", snd_pcm_oss_format_name(runtime->oss.format));
404 snd_iprintf(buffer, "OSS channels: %u\n", runtime->oss.channels); 405 snd_iprintf(buffer, "OSS channels: %u\n", runtime->oss.channels);
@@ -651,7 +652,7 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
651 struct snd_pcm_str *pstr = &pcm->streams[stream]; 652 struct snd_pcm_str *pstr = &pcm->streams[stream];
652 struct snd_pcm_substream *substream, *prev; 653 struct snd_pcm_substream *substream, *prev;
653 654
654#if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 655#if IS_ENABLED(CONFIG_SND_PCM_OSS)
655 mutex_init(&pstr->oss.setup_mutex); 656 mutex_init(&pstr->oss.setup_mutex);
656#endif 657#endif
657 pstr->stream = stream; 658 pstr->stream = stream;
@@ -660,7 +661,7 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
660 if (substream_count > 0 && !pcm->internal) { 661 if (substream_count > 0 && !pcm->internal) {
661 err = snd_pcm_stream_proc_init(pstr); 662 err = snd_pcm_stream_proc_init(pstr);
662 if (err < 0) { 663 if (err < 0) {
663 snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n"); 664 pcm_err(pcm, "Error in snd_pcm_stream_proc_init\n");
664 return err; 665 return err;
665 } 666 }
666 } 667 }
@@ -668,7 +669,7 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
668 for (idx = 0, prev = NULL; idx < substream_count; idx++) { 669 for (idx = 0, prev = NULL; idx < substream_count; idx++) {
669 substream = kzalloc(sizeof(*substream), GFP_KERNEL); 670 substream = kzalloc(sizeof(*substream), GFP_KERNEL);
670 if (substream == NULL) { 671 if (substream == NULL) {
671 snd_printk(KERN_ERR "Cannot allocate PCM substream\n"); 672 pcm_err(pcm, "Cannot allocate PCM substream\n");
672 return -ENOMEM; 673 return -ENOMEM;
673 } 674 }
674 substream->pcm = pcm; 675 substream->pcm = pcm;
@@ -685,7 +686,8 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
685 if (!pcm->internal) { 686 if (!pcm->internal) {
686 err = snd_pcm_substream_proc_init(substream); 687 err = snd_pcm_substream_proc_init(substream);
687 if (err < 0) { 688 if (err < 0) {
688 snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n"); 689 pcm_err(pcm,
690 "Error in snd_pcm_stream_proc_init\n");
689 if (prev == NULL) 691 if (prev == NULL)
690 pstr->substream = NULL; 692 pstr->substream = NULL;
691 else 693 else
@@ -724,7 +726,7 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
724 *rpcm = NULL; 726 *rpcm = NULL;
725 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); 727 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
726 if (pcm == NULL) { 728 if (pcm == NULL) {
727 snd_printk(KERN_ERR "Cannot allocate PCM\n"); 729 dev_err(card->dev, "Cannot allocate PCM\n");
728 return -ENOMEM; 730 return -ENOMEM;
729 } 731 }
730 pcm->card = card; 732 pcm->card = card;
@@ -807,7 +809,7 @@ EXPORT_SYMBOL(snd_pcm_new_internal);
807static void snd_pcm_free_stream(struct snd_pcm_str * pstr) 809static void snd_pcm_free_stream(struct snd_pcm_str * pstr)
808{ 810{
809 struct snd_pcm_substream *substream, *substream_next; 811 struct snd_pcm_substream *substream, *substream_next;
810#if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 812#if IS_ENABLED(CONFIG_SND_PCM_OSS)
811 struct snd_pcm_oss_setup *setup, *setupn; 813 struct snd_pcm_oss_setup *setup, *setupn;
812#endif 814#endif
813 substream = pstr->substream; 815 substream = pstr->substream;
@@ -819,7 +821,7 @@ static void snd_pcm_free_stream(struct snd_pcm_str * pstr)
819 substream = substream_next; 821 substream = substream_next;
820 } 822 }
821 snd_pcm_stream_proc_done(pstr); 823 snd_pcm_stream_proc_done(pstr);
822#if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 824#if IS_ENABLED(CONFIG_SND_PCM_OSS)
823 for (setup = pstr->oss.setup_list; setup; setup = setupn) { 825 for (setup = pstr->oss.setup_list; setup; setup = setupn) {
824 setupn = setup->next; 826 setupn = setup->next;
825 kfree(setup->task_name); 827 kfree(setup->task_name);
@@ -1016,8 +1018,20 @@ static ssize_t show_pcm_class(struct device *dev,
1016 return snprintf(buf, PAGE_SIZE, "%s\n", str); 1018 return snprintf(buf, PAGE_SIZE, "%s\n", str);
1017} 1019}
1018 1020
1019static struct device_attribute pcm_attrs = 1021static DEVICE_ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL);
1020 __ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL); 1022static struct attribute *pcm_dev_attrs[] = {
1023 &dev_attr_pcm_class.attr,
1024 NULL
1025};
1026
1027static struct attribute_group pcm_dev_attr_group = {
1028 .attrs = pcm_dev_attrs,
1029};
1030
1031static const struct attribute_group *pcm_dev_attr_groups[] = {
1032 &pcm_dev_attr_group,
1033 NULL
1034};
1021 1035
1022static int snd_pcm_dev_register(struct snd_device *device) 1036static int snd_pcm_dev_register(struct snd_device *device)
1023{ 1037{
@@ -1067,8 +1081,18 @@ static int snd_pcm_dev_register(struct snd_device *device)
1067 mutex_unlock(&register_mutex); 1081 mutex_unlock(&register_mutex);
1068 return err; 1082 return err;
1069 } 1083 }
1070 snd_add_device_sysfs_file(devtype, pcm->card, pcm->device, 1084
1071 &pcm_attrs); 1085 dev = snd_get_device(devtype, pcm->card, pcm->device);
1086 if (dev) {
1087 err = sysfs_create_groups(&dev->kobj,
1088 pcm_dev_attr_groups);
1089 if (err < 0)
1090 dev_warn(dev,
1091 "pcm %d:%d: cannot create sysfs groups\n",
1092 pcm->card->number, pcm->device);
1093 put_device(dev);
1094 }
1095
1072 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) 1096 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
1073 snd_pcm_timer_init(substream); 1097 snd_pcm_timer_init(substream);
1074 } 1098 }
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index a2104671f51d..ce83def9f43b 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -174,7 +174,7 @@ static void xrun(struct snd_pcm_substream *substream)
174 if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { 174 if (xrun_debug(substream, XRUN_DEBUG_BASIC)) {
175 char name[16]; 175 char name[16];
176 snd_pcm_debug_name(substream, name, sizeof(name)); 176 snd_pcm_debug_name(substream, name, sizeof(name));
177 snd_printd(KERN_DEBUG "XRUN: %s\n", name); 177 pcm_warn(substream->pcm, "XRUN: %s\n", name);
178 dump_stack_on_xrun(substream); 178 dump_stack_on_xrun(substream);
179 } 179 }
180} 180}
@@ -184,9 +184,7 @@ static void xrun(struct snd_pcm_substream *substream)
184 do { \ 184 do { \
185 if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { \ 185 if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { \
186 xrun_log_show(substream); \ 186 xrun_log_show(substream); \
187 if (snd_printd_ratelimit()) { \ 187 pr_err_ratelimited("ALSA: PCM: " fmt, ##args); \
188 snd_printd("PCM: " fmt, ##args); \
189 } \
190 dump_stack_on_xrun(substream); \ 188 dump_stack_on_xrun(substream); \
191 } \ 189 } \
192 } while (0) 190 } while (0)
@@ -253,7 +251,7 @@ static void xrun_log_show(struct snd_pcm_substream *substream)
253 entry = &log->entries[idx]; 251 entry = &log->entries[idx];
254 if (entry->period_size == 0) 252 if (entry->period_size == 0)
255 break; 253 break;
256 snd_printd("hwptr log: %s: %sj=%lu, pos=%ld/%ld/%ld, " 254 pr_info("hwptr log: %s: %sj=%lu, pos=%ld/%ld/%ld, "
257 "hwptr=%ld/%ld\n", 255 "hwptr=%ld/%ld\n",
258 name, entry->in_interrupt ? "[Q] " : "", 256 name, entry->in_interrupt ? "[Q] " : "",
259 entry->jiffies, 257 entry->jiffies,
@@ -342,14 +340,14 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
342 return -EPIPE; 340 return -EPIPE;
343 } 341 }
344 if (pos >= runtime->buffer_size) { 342 if (pos >= runtime->buffer_size) {
345 if (snd_printd_ratelimit()) { 343 if (printk_ratelimit()) {
346 char name[16]; 344 char name[16];
347 snd_pcm_debug_name(substream, name, sizeof(name)); 345 snd_pcm_debug_name(substream, name, sizeof(name));
348 xrun_log_show(substream); 346 xrun_log_show(substream);
349 snd_printd(KERN_ERR "BUG: %s, pos = %ld, " 347 pcm_err(substream->pcm,
350 "buffer size = %ld, period size = %ld\n", 348 "BUG: %s, pos = %ld, buffer size = %ld, period size = %ld\n",
351 name, pos, runtime->buffer_size, 349 name, pos, runtime->buffer_size,
352 runtime->period_size); 350 runtime->period_size);
353 } 351 }
354 pos = 0; 352 pos = 0;
355 } 353 }
@@ -394,8 +392,8 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
394 XRUN_DEBUG_PERIODUPDATE : XRUN_DEBUG_HWPTRUPDATE)) { 392 XRUN_DEBUG_PERIODUPDATE : XRUN_DEBUG_HWPTRUPDATE)) {
395 char name[16]; 393 char name[16];
396 snd_pcm_debug_name(substream, name, sizeof(name)); 394 snd_pcm_debug_name(substream, name, sizeof(name));
397 snd_printd("%s_update: %s: pos=%u/%u/%u, " 395 pcm_dbg(substream->pcm,
398 "hwptr=%ld/%ld/%ld/%ld\n", 396 "%s_update: %s: pos=%u/%u/%u, hwptr=%ld/%ld/%ld/%ld\n",
399 in_interrupt ? "period" : "hwptr", 397 in_interrupt ? "period" : "hwptr",
400 name, 398 name,
401 (unsigned int)pos, 399 (unsigned int)pos,
@@ -1242,6 +1240,7 @@ int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_par
1242 return -EINVAL; 1240 return -EINVAL;
1243 return 0; 1241 return 0;
1244} 1242}
1243EXPORT_SYMBOL(snd_pcm_hw_constraint_mask64);
1245 1244
1246/** 1245/**
1247 * snd_pcm_hw_constraint_integer - apply an integer constraint to an interval 1246 * snd_pcm_hw_constraint_integer - apply an integer constraint to an interval
@@ -1941,8 +1940,9 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
1941 continue; 1940 continue;
1942 } 1941 }
1943 if (!tout) { 1942 if (!tout) {
1944 snd_printd("%s write error (DMA or IRQ trouble?)\n", 1943 pcm_dbg(substream->pcm,
1945 is_playback ? "playback" : "capture"); 1944 "%s write error (DMA or IRQ trouble?)\n",
1945 is_playback ? "playback" : "capture");
1946 err = -EIO; 1946 err = -EIO;
1947 break; 1947 break;
1948 } 1948 }
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 01a5e05ede95..b653ab001fba 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -190,12 +190,12 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
190 if (!(params->rmask & (1 << k))) 190 if (!(params->rmask & (1 << k)))
191 continue; 191 continue;
192#ifdef RULES_DEBUG 192#ifdef RULES_DEBUG
193 printk(KERN_DEBUG "%s = ", snd_pcm_hw_param_names[k]); 193 pr_debug("%s = ", snd_pcm_hw_param_names[k]);
194 printk("%04x%04x%04x%04x -> ", m->bits[3], m->bits[2], m->bits[1], m->bits[0]); 194 pr_cont("%04x%04x%04x%04x -> ", m->bits[3], m->bits[2], m->bits[1], m->bits[0]);
195#endif 195#endif
196 changed = snd_mask_refine(m, constrs_mask(constrs, k)); 196 changed = snd_mask_refine(m, constrs_mask(constrs, k));
197#ifdef RULES_DEBUG 197#ifdef RULES_DEBUG
198 printk("%04x%04x%04x%04x\n", m->bits[3], m->bits[2], m->bits[1], m->bits[0]); 198 pr_cont("%04x%04x%04x%04x\n", m->bits[3], m->bits[2], m->bits[1], m->bits[0]);
199#endif 199#endif
200 if (changed) 200 if (changed)
201 params->cmask |= 1 << k; 201 params->cmask |= 1 << k;
@@ -210,21 +210,21 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
210 if (!(params->rmask & (1 << k))) 210 if (!(params->rmask & (1 << k)))
211 continue; 211 continue;
212#ifdef RULES_DEBUG 212#ifdef RULES_DEBUG
213 printk(KERN_DEBUG "%s = ", snd_pcm_hw_param_names[k]); 213 pr_debug("%s = ", snd_pcm_hw_param_names[k]);
214 if (i->empty) 214 if (i->empty)
215 printk("empty"); 215 pr_cont("empty");
216 else 216 else
217 printk("%c%u %u%c", 217 pr_cont("%c%u %u%c",
218 i->openmin ? '(' : '[', i->min, 218 i->openmin ? '(' : '[', i->min,
219 i->max, i->openmax ? ')' : ']'); 219 i->max, i->openmax ? ')' : ']');
220 printk(" -> "); 220 pr_cont(" -> ");
221#endif 221#endif
222 changed = snd_interval_refine(i, constrs_interval(constrs, k)); 222 changed = snd_interval_refine(i, constrs_interval(constrs, k));
223#ifdef RULES_DEBUG 223#ifdef RULES_DEBUG
224 if (i->empty) 224 if (i->empty)
225 printk("empty\n"); 225 pr_cont("empty\n");
226 else 226 else
227 printk("%c%u %u%c\n", 227 pr_cont("%c%u %u%c\n",
228 i->openmin ? '(' : '[', i->min, 228 i->openmin ? '(' : '[', i->min,
229 i->max, i->openmax ? ')' : ']'); 229 i->max, i->openmax ? ')' : ']');
230#endif 230#endif
@@ -255,18 +255,18 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
255 if (!doit) 255 if (!doit)
256 continue; 256 continue;
257#ifdef RULES_DEBUG 257#ifdef RULES_DEBUG
258 printk(KERN_DEBUG "Rule %d [%p]: ", k, r->func); 258 pr_debug("Rule %d [%p]: ", k, r->func);
259 if (r->var >= 0) { 259 if (r->var >= 0) {
260 printk("%s = ", snd_pcm_hw_param_names[r->var]); 260 pr_cont("%s = ", snd_pcm_hw_param_names[r->var]);
261 if (hw_is_mask(r->var)) { 261 if (hw_is_mask(r->var)) {
262 m = hw_param_mask(params, r->var); 262 m = hw_param_mask(params, r->var);
263 printk("%x", *m->bits); 263 pr_cont("%x", *m->bits);
264 } else { 264 } else {
265 i = hw_param_interval(params, r->var); 265 i = hw_param_interval(params, r->var);
266 if (i->empty) 266 if (i->empty)
267 printk("empty"); 267 pr_cont("empty");
268 else 268 else
269 printk("%c%u %u%c", 269 pr_cont("%c%u %u%c",
270 i->openmin ? '(' : '[', i->min, 270 i->openmin ? '(' : '[', i->min,
271 i->max, i->openmax ? ')' : ']'); 271 i->max, i->openmax ? ')' : ']');
272 } 272 }
@@ -275,19 +275,19 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
275 changed = r->func(params, r); 275 changed = r->func(params, r);
276#ifdef RULES_DEBUG 276#ifdef RULES_DEBUG
277 if (r->var >= 0) { 277 if (r->var >= 0) {
278 printk(" -> "); 278 pr_cont(" -> ");
279 if (hw_is_mask(r->var)) 279 if (hw_is_mask(r->var))
280 printk("%x", *m->bits); 280 pr_cont("%x", *m->bits);
281 else { 281 else {
282 if (i->empty) 282 if (i->empty)
283 printk("empty"); 283 pr_cont("empty");
284 else 284 else
285 printk("%c%u %u%c", 285 pr_cont("%c%u %u%c",
286 i->openmin ? '(' : '[', i->min, 286 i->openmin ? '(' : '[', i->min,
287 i->max, i->openmax ? ')' : ']'); 287 i->max, i->openmax ? ')' : ']');
288 } 288 }
289 } 289 }
290 printk("\n"); 290 pr_cont("\n");
291#endif 291#endif
292 rstamps[k] = stamp; 292 rstamps[k] = stamp;
293 if (changed && r->var >= 0) { 293 if (changed && r->var >= 0) {
@@ -399,7 +399,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
399 return -EBADFD; 399 return -EBADFD;
400 } 400 }
401 snd_pcm_stream_unlock_irq(substream); 401 snd_pcm_stream_unlock_irq(substream);
402#if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 402#if IS_ENABLED(CONFIG_SND_PCM_OSS)
403 if (!substream->oss.oss) 403 if (!substream->oss.oss)
404#endif 404#endif
405 if (atomic_read(&substream->mmap_count)) 405 if (atomic_read(&substream->mmap_count))
@@ -954,7 +954,7 @@ static struct action_ops snd_pcm_action_stop = {
954 * 954 *
955 * The state of each stream is then changed to the given state unconditionally. 955 * The state of each stream is then changed to the given state unconditionally.
956 * 956 *
957 * Return: Zero if succesful, or a negative error code. 957 * Return: Zero if successful, or a negative error code.
958 */ 958 */
959int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) 959int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state)
960{ 960{
@@ -1541,7 +1541,8 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
1541 if (substream->runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) 1541 if (substream->runtime->status->state == SNDRV_PCM_STATE_SUSPENDED)
1542 result = -ESTRPIPE; 1542 result = -ESTRPIPE;
1543 else { 1543 else {
1544 snd_printd("playback drain error (DMA or IRQ trouble?)\n"); 1544 dev_dbg(substream->pcm->card->dev,
1545 "playback drain error (DMA or IRQ trouble?)\n");
1545 snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); 1546 snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP);
1546 result = -EIO; 1547 result = -EIO;
1547 } 1548 }
@@ -2066,7 +2067,7 @@ int snd_pcm_open_substream(struct snd_pcm *pcm, int stream,
2066 2067
2067 err = snd_pcm_hw_constraints_init(substream); 2068 err = snd_pcm_hw_constraints_init(substream);
2068 if (err < 0) { 2069 if (err < 0) {
2069 snd_printd("snd_pcm_hw_constraints_init failed\n"); 2070 pcm_dbg(pcm, "snd_pcm_hw_constraints_init failed\n");
2070 goto error; 2071 goto error;
2071 } 2072 }
2072 2073
@@ -2077,7 +2078,7 @@ int snd_pcm_open_substream(struct snd_pcm *pcm, int stream,
2077 2078
2078 err = snd_pcm_hw_constraints_complete(substream); 2079 err = snd_pcm_hw_constraints_complete(substream);
2079 if (err < 0) { 2080 if (err < 0) {
2080 snd_printd("snd_pcm_hw_constraints_complete failed\n"); 2081 pcm_dbg(pcm, "snd_pcm_hw_constraints_complete failed\n");
2081 goto error; 2082 goto error;
2082 } 2083 }
2083 2084
@@ -2609,7 +2610,7 @@ static int snd_pcm_common_ioctl1(struct file *file,
2609 return res; 2610 return res;
2610 } 2611 }
2611 } 2612 }
2612 snd_printd("unknown ioctl = 0x%x\n", cmd); 2613 pcm_dbg(substream->pcm, "unknown ioctl = 0x%x\n", cmd);
2613 return -ENOTTY; 2614 return -ENOTTY;
2614} 2615}
2615 2616
diff --git a/sound/core/pcm_timer.c b/sound/core/pcm_timer.c
index b01d9481d632..20ecd8f18080 100644
--- a/sound/core/pcm_timer.c
+++ b/sound/core/pcm_timer.c
@@ -53,7 +53,9 @@ void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream)
53 post *= 2; 53 post *= 2;
54 } 54 }
55 if (rate == 0) { 55 if (rate == 0) {
56 snd_printk(KERN_ERR "pcm timer resolution out of range (rate = %u, period_size = %lu)\n", runtime->rate, runtime->period_size); 56 pcm_err(substream->pcm,
57 "pcm timer resolution out of range (rate = %u, period_size = %lu)\n",
58 runtime->rate, runtime->period_size);
57 runtime->timer_resolution = -1; 59 runtime->timer_resolution = -1;
58 return; 60 return;
59 } 61 }
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 7b596b5751db..6fc71a4c8a51 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -56,6 +56,13 @@ static int snd_rawmidi_dev_disconnect(struct snd_device *device);
56static LIST_HEAD(snd_rawmidi_devices); 56static LIST_HEAD(snd_rawmidi_devices);
57static DEFINE_MUTEX(register_mutex); 57static DEFINE_MUTEX(register_mutex);
58 58
59#define rmidi_err(rmidi, fmt, args...) \
60 dev_err((rmidi)->card->dev, fmt, ##args)
61#define rmidi_warn(rmidi, fmt, args...) \
62 dev_warn((rmidi)->card->dev, fmt, ##args)
63#define rmidi_dbg(rmidi, fmt, args...) \
64 dev_dbg((rmidi)->card->dev, fmt, ##args)
65
59static struct snd_rawmidi *snd_rawmidi_search(struct snd_card *card, int device) 66static struct snd_rawmidi *snd_rawmidi_search(struct snd_card *card, int device)
60{ 67{
61 struct snd_rawmidi *rawmidi; 68 struct snd_rawmidi *rawmidi;
@@ -165,6 +172,7 @@ int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream)
165 spin_unlock_irqrestore(&runtime->lock, flags); 172 spin_unlock_irqrestore(&runtime->lock, flags);
166 return 0; 173 return 0;
167} 174}
175EXPORT_SYMBOL(snd_rawmidi_drop_output);
168 176
169int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream) 177int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream)
170{ 178{
@@ -180,7 +188,9 @@ int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream)
180 if (signal_pending(current)) 188 if (signal_pending(current))
181 err = -ERESTARTSYS; 189 err = -ERESTARTSYS;
182 if (runtime->avail < runtime->buffer_size && !timeout) { 190 if (runtime->avail < runtime->buffer_size && !timeout) {
183 snd_printk(KERN_WARNING "rawmidi drain error (avail = %li, buffer_size = %li)\n", (long)runtime->avail, (long)runtime->buffer_size); 191 rmidi_warn(substream->rmidi,
192 "rawmidi drain error (avail = %li, buffer_size = %li)\n",
193 (long)runtime->avail, (long)runtime->buffer_size);
184 err = -EIO; 194 err = -EIO;
185 } 195 }
186 runtime->drain = 0; 196 runtime->drain = 0;
@@ -194,6 +204,7 @@ int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream)
194 } 204 }
195 return err; 205 return err;
196} 206}
207EXPORT_SYMBOL(snd_rawmidi_drain_output);
197 208
198int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream) 209int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream)
199{ 210{
@@ -208,6 +219,7 @@ int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream)
208 spin_unlock_irqrestore(&runtime->lock, flags); 219 spin_unlock_irqrestore(&runtime->lock, flags);
209 return 0; 220 return 0;
210} 221}
222EXPORT_SYMBOL(snd_rawmidi_drain_input);
211 223
212/* look for an available substream for the given stream direction; 224/* look for an available substream for the given stream direction;
213 * if a specific subdevice is given, try to assign it 225 * if a specific subdevice is given, try to assign it
@@ -345,6 +357,7 @@ int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
345 module_put(rmidi->card->module); 357 module_put(rmidi->card->module);
346 return err; 358 return err;
347} 359}
360EXPORT_SYMBOL(snd_rawmidi_kernel_open);
348 361
349static int snd_rawmidi_open(struct inode *inode, struct file *file) 362static int snd_rawmidi_open(struct inode *inode, struct file *file)
350{ 363{
@@ -523,6 +536,7 @@ int snd_rawmidi_kernel_release(struct snd_rawmidi_file *rfile)
523 module_put(rmidi->card->module); 536 module_put(rmidi->card->module);
524 return 0; 537 return 0;
525} 538}
539EXPORT_SYMBOL(snd_rawmidi_kernel_release);
526 540
527static int snd_rawmidi_release(struct inode *inode, struct file *file) 541static int snd_rawmidi_release(struct inode *inode, struct file *file)
528{ 542{
@@ -599,6 +613,7 @@ int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info
599 } 613 }
600 return -ENXIO; 614 return -ENXIO;
601} 615}
616EXPORT_SYMBOL(snd_rawmidi_info_select);
602 617
603static int snd_rawmidi_info_select_user(struct snd_card *card, 618static int snd_rawmidi_info_select_user(struct snd_card *card,
604 struct snd_rawmidi_info __user *_info) 619 struct snd_rawmidi_info __user *_info)
@@ -646,6 +661,7 @@ int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
646 substream->active_sensing = !params->no_active_sensing; 661 substream->active_sensing = !params->no_active_sensing;
647 return 0; 662 return 0;
648} 663}
664EXPORT_SYMBOL(snd_rawmidi_output_params);
649 665
650int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream, 666int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
651 struct snd_rawmidi_params * params) 667 struct snd_rawmidi_params * params)
@@ -671,6 +687,7 @@ int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
671 runtime->avail_min = params->avail_min; 687 runtime->avail_min = params->avail_min;
672 return 0; 688 return 0;
673} 689}
690EXPORT_SYMBOL(snd_rawmidi_input_params);
674 691
675static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream, 692static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream,
676 struct snd_rawmidi_status * status) 693 struct snd_rawmidi_status * status)
@@ -802,10 +819,9 @@ static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long
802 return -EINVAL; 819 return -EINVAL;
803 } 820 }
804 } 821 }
805#ifdef CONFIG_SND_DEBUG
806 default: 822 default:
807 snd_printk(KERN_WARNING "rawmidi: unknown command = 0x%x\n", cmd); 823 rmidi_dbg(rfile->rmidi,
808#endif 824 "rawmidi: unknown command = 0x%x\n", cmd);
809 } 825 }
810 return -ENOTTY; 826 return -ENOTTY;
811} 827}
@@ -875,7 +891,8 @@ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
875 if (!substream->opened) 891 if (!substream->opened)
876 return -EBADFD; 892 return -EBADFD;
877 if (runtime->buffer == NULL) { 893 if (runtime->buffer == NULL) {
878 snd_printd("snd_rawmidi_receive: input is not active!!!\n"); 894 rmidi_dbg(substream->rmidi,
895 "snd_rawmidi_receive: input is not active!!!\n");
879 return -EINVAL; 896 return -EINVAL;
880 } 897 }
881 spin_lock_irqsave(&runtime->lock, flags); 898 spin_lock_irqsave(&runtime->lock, flags);
@@ -926,6 +943,7 @@ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
926 spin_unlock_irqrestore(&runtime->lock, flags); 943 spin_unlock_irqrestore(&runtime->lock, flags);
927 return result; 944 return result;
928} 945}
946EXPORT_SYMBOL(snd_rawmidi_receive);
929 947
930static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream, 948static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
931 unsigned char __user *userbuf, 949 unsigned char __user *userbuf,
@@ -968,6 +986,7 @@ long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
968 snd_rawmidi_input_trigger(substream, 1); 986 snd_rawmidi_input_trigger(substream, 1);
969 return snd_rawmidi_kernel_read1(substream, NULL/*userbuf*/, buf, count); 987 return snd_rawmidi_kernel_read1(substream, NULL/*userbuf*/, buf, count);
970} 988}
989EXPORT_SYMBOL(snd_rawmidi_kernel_read);
971 990
972static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t count, 991static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t count,
973 loff_t *offset) 992 loff_t *offset)
@@ -1034,7 +1053,8 @@ int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
1034 unsigned long flags; 1053 unsigned long flags;
1035 1054
1036 if (runtime->buffer == NULL) { 1055 if (runtime->buffer == NULL) {
1037 snd_printd("snd_rawmidi_transmit_empty: output is not active!!!\n"); 1056 rmidi_dbg(substream->rmidi,
1057 "snd_rawmidi_transmit_empty: output is not active!!!\n");
1038 return 1; 1058 return 1;
1039 } 1059 }
1040 spin_lock_irqsave(&runtime->lock, flags); 1060 spin_lock_irqsave(&runtime->lock, flags);
@@ -1042,6 +1062,7 @@ int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
1042 spin_unlock_irqrestore(&runtime->lock, flags); 1062 spin_unlock_irqrestore(&runtime->lock, flags);
1043 return result; 1063 return result;
1044} 1064}
1065EXPORT_SYMBOL(snd_rawmidi_transmit_empty);
1045 1066
1046/** 1067/**
1047 * snd_rawmidi_transmit_peek - copy data from the internal buffer 1068 * snd_rawmidi_transmit_peek - copy data from the internal buffer
@@ -1065,7 +1086,8 @@ int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
1065 struct snd_rawmidi_runtime *runtime = substream->runtime; 1086 struct snd_rawmidi_runtime *runtime = substream->runtime;
1066 1087
1067 if (runtime->buffer == NULL) { 1088 if (runtime->buffer == NULL) {
1068 snd_printd("snd_rawmidi_transmit_peek: output is not active!!!\n"); 1089 rmidi_dbg(substream->rmidi,
1090 "snd_rawmidi_transmit_peek: output is not active!!!\n");
1069 return -EINVAL; 1091 return -EINVAL;
1070 } 1092 }
1071 result = 0; 1093 result = 0;
@@ -1097,11 +1119,12 @@ int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
1097 spin_unlock_irqrestore(&runtime->lock, flags); 1119 spin_unlock_irqrestore(&runtime->lock, flags);
1098 return result; 1120 return result;
1099} 1121}
1122EXPORT_SYMBOL(snd_rawmidi_transmit_peek);
1100 1123
1101/** 1124/**
1102 * snd_rawmidi_transmit_ack - acknowledge the transmission 1125 * snd_rawmidi_transmit_ack - acknowledge the transmission
1103 * @substream: the rawmidi substream 1126 * @substream: the rawmidi substream
1104 * @count: the tranferred count 1127 * @count: the transferred count
1105 * 1128 *
1106 * Advances the hardware pointer for the internal output buffer with 1129 * Advances the hardware pointer for the internal output buffer with
1107 * the given size and updates the condition. 1130 * the given size and updates the condition.
@@ -1115,7 +1138,8 @@ int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
1115 struct snd_rawmidi_runtime *runtime = substream->runtime; 1138 struct snd_rawmidi_runtime *runtime = substream->runtime;
1116 1139
1117 if (runtime->buffer == NULL) { 1140 if (runtime->buffer == NULL) {
1118 snd_printd("snd_rawmidi_transmit_ack: output is not active!!!\n"); 1141 rmidi_dbg(substream->rmidi,
1142 "snd_rawmidi_transmit_ack: output is not active!!!\n");
1119 return -EINVAL; 1143 return -EINVAL;
1120 } 1144 }
1121 spin_lock_irqsave(&runtime->lock, flags); 1145 spin_lock_irqsave(&runtime->lock, flags);
@@ -1131,6 +1155,7 @@ int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
1131 spin_unlock_irqrestore(&runtime->lock, flags); 1155 spin_unlock_irqrestore(&runtime->lock, flags);
1132 return count; 1156 return count;
1133} 1157}
1158EXPORT_SYMBOL(snd_rawmidi_transmit_ack);
1134 1159
1135/** 1160/**
1136 * snd_rawmidi_transmit - copy from the buffer to the device 1161 * snd_rawmidi_transmit - copy from the buffer to the device
@@ -1152,6 +1177,7 @@ int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
1152 return count; 1177 return count;
1153 return snd_rawmidi_transmit_ack(substream, count); 1178 return snd_rawmidi_transmit_ack(substream, count);
1154} 1179}
1180EXPORT_SYMBOL(snd_rawmidi_transmit);
1155 1181
1156static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream, 1182static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
1157 const unsigned char __user *userbuf, 1183 const unsigned char __user *userbuf,
@@ -1213,6 +1239,7 @@ long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
1213{ 1239{
1214 return snd_rawmidi_kernel_write1(substream, NULL, buf, count); 1240 return snd_rawmidi_kernel_write1(substream, NULL, buf, count);
1215} 1241}
1242EXPORT_SYMBOL(snd_rawmidi_kernel_write);
1216 1243
1217static ssize_t snd_rawmidi_write(struct file *file, const char __user *buf, 1244static ssize_t snd_rawmidi_write(struct file *file, const char __user *buf,
1218 size_t count, loff_t *offset) 1245 size_t count, loff_t *offset)
@@ -1413,7 +1440,7 @@ static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
1413 for (idx = 0; idx < count; idx++) { 1440 for (idx = 0; idx < count; idx++) {
1414 substream = kzalloc(sizeof(*substream), GFP_KERNEL); 1441 substream = kzalloc(sizeof(*substream), GFP_KERNEL);
1415 if (substream == NULL) { 1442 if (substream == NULL) {
1416 snd_printk(KERN_ERR "rawmidi: cannot allocate substream\n"); 1443 rmidi_err(rmidi, "rawmidi: cannot allocate substream\n");
1417 return -ENOMEM; 1444 return -ENOMEM;
1418 } 1445 }
1419 substream->stream = direction; 1446 substream->stream = direction;
@@ -1458,7 +1485,7 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
1458 *rrawmidi = NULL; 1485 *rrawmidi = NULL;
1459 rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL); 1486 rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL);
1460 if (rmidi == NULL) { 1487 if (rmidi == NULL) {
1461 snd_printk(KERN_ERR "rawmidi: cannot allocate\n"); 1488 dev_err(card->dev, "rawmidi: cannot allocate\n");
1462 return -ENOMEM; 1489 return -ENOMEM;
1463 } 1490 }
1464 rmidi->card = card; 1491 rmidi->card = card;
@@ -1492,6 +1519,7 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
1492 *rrawmidi = rmidi; 1519 *rrawmidi = rmidi;
1493 return 0; 1520 return 0;
1494} 1521}
1522EXPORT_SYMBOL(snd_rawmidi_new);
1495 1523
1496static void snd_rawmidi_free_substreams(struct snd_rawmidi_str *stream) 1524static void snd_rawmidi_free_substreams(struct snd_rawmidi_str *stream)
1497{ 1525{
@@ -1557,7 +1585,8 @@ static int snd_rawmidi_dev_register(struct snd_device *device)
1557 if ((err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI, 1585 if ((err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI,
1558 rmidi->card, rmidi->device, 1586 rmidi->card, rmidi->device,
1559 &snd_rawmidi_f_ops, rmidi, name)) < 0) { 1587 &snd_rawmidi_f_ops, rmidi, name)) < 0) {
1560 snd_printk(KERN_ERR "unable to register rawmidi device %i:%i\n", rmidi->card->number, rmidi->device); 1588 rmidi_err(rmidi, "unable to register rawmidi device %i:%i\n",
1589 rmidi->card->number, rmidi->device);
1561 list_del(&rmidi->list); 1590 list_del(&rmidi->list);
1562 mutex_unlock(&register_mutex); 1591 mutex_unlock(&register_mutex);
1563 return err; 1592 return err;
@@ -1574,8 +1603,10 @@ static int snd_rawmidi_dev_register(struct snd_device *device)
1574 if ((int)rmidi->device == midi_map[rmidi->card->number]) { 1603 if ((int)rmidi->device == midi_map[rmidi->card->number]) {
1575 if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI, 1604 if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI,
1576 rmidi->card, 0, &snd_rawmidi_f_ops, 1605 rmidi->card, 0, &snd_rawmidi_f_ops,
1577 rmidi, name) < 0) { 1606 rmidi) < 0) {
1578 snd_printk(KERN_ERR "unable to register OSS rawmidi device %i:%i\n", rmidi->card->number, 0); 1607 rmidi_err(rmidi,
1608 "unable to register OSS rawmidi device %i:%i\n",
1609 rmidi->card->number, 0);
1579 } else { 1610 } else {
1580 rmidi->ossreg++; 1611 rmidi->ossreg++;
1581#ifdef SNDRV_OSS_INFO_DEV_MIDI 1612#ifdef SNDRV_OSS_INFO_DEV_MIDI
@@ -1586,8 +1617,10 @@ static int snd_rawmidi_dev_register(struct snd_device *device)
1586 if ((int)rmidi->device == amidi_map[rmidi->card->number]) { 1617 if ((int)rmidi->device == amidi_map[rmidi->card->number]) {
1587 if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI, 1618 if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI,
1588 rmidi->card, 1, &snd_rawmidi_f_ops, 1619 rmidi->card, 1, &snd_rawmidi_f_ops,
1589 rmidi, name) < 0) { 1620 rmidi) < 0) {
1590 snd_printk(KERN_ERR "unable to register OSS rawmidi device %i:%i\n", rmidi->card->number, 1); 1621 rmidi_err(rmidi,
1622 "unable to register OSS rawmidi device %i:%i\n",
1623 rmidi->card->number, 1);
1591 } else { 1624 } else {
1592 rmidi->ossreg++; 1625 rmidi->ossreg++;
1593 } 1626 }
@@ -1670,6 +1703,7 @@ void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
1670 list_for_each_entry(substream, &rmidi->streams[stream].substreams, list) 1703 list_for_each_entry(substream, &rmidi->streams[stream].substreams, list)
1671 substream->ops = ops; 1704 substream->ops = ops;
1672} 1705}
1706EXPORT_SYMBOL(snd_rawmidi_set_ops);
1673 1707
1674/* 1708/*
1675 * ENTRY functions 1709 * ENTRY functions
@@ -1685,11 +1719,13 @@ static int __init alsa_rawmidi_init(void)
1685 /* check device map table */ 1719 /* check device map table */
1686 for (i = 0; i < SNDRV_CARDS; i++) { 1720 for (i = 0; i < SNDRV_CARDS; i++) {
1687 if (midi_map[i] < 0 || midi_map[i] >= SNDRV_RAWMIDI_DEVICES) { 1721 if (midi_map[i] < 0 || midi_map[i] >= SNDRV_RAWMIDI_DEVICES) {
1688 snd_printk(KERN_ERR "invalid midi_map[%d] = %d\n", i, midi_map[i]); 1722 pr_err("ALSA: rawmidi: invalid midi_map[%d] = %d\n",
1723 i, midi_map[i]);
1689 midi_map[i] = 0; 1724 midi_map[i] = 0;
1690 } 1725 }
1691 if (amidi_map[i] < 0 || amidi_map[i] >= SNDRV_RAWMIDI_DEVICES) { 1726 if (amidi_map[i] < 0 || amidi_map[i] >= SNDRV_RAWMIDI_DEVICES) {
1692 snd_printk(KERN_ERR "invalid amidi_map[%d] = %d\n", i, amidi_map[i]); 1727 pr_err("ALSA: rawmidi: invalid amidi_map[%d] = %d\n",
1728 i, amidi_map[i]);
1693 amidi_map[i] = 1; 1729 amidi_map[i] = 1;
1694 } 1730 }
1695 } 1731 }
@@ -1706,21 +1742,3 @@ static void __exit alsa_rawmidi_exit(void)
1706 1742
1707module_init(alsa_rawmidi_init) 1743module_init(alsa_rawmidi_init)
1708module_exit(alsa_rawmidi_exit) 1744module_exit(alsa_rawmidi_exit)
1709
1710EXPORT_SYMBOL(snd_rawmidi_output_params);
1711EXPORT_SYMBOL(snd_rawmidi_input_params);
1712EXPORT_SYMBOL(snd_rawmidi_drop_output);
1713EXPORT_SYMBOL(snd_rawmidi_drain_output);
1714EXPORT_SYMBOL(snd_rawmidi_drain_input);
1715EXPORT_SYMBOL(snd_rawmidi_receive);
1716EXPORT_SYMBOL(snd_rawmidi_transmit_empty);
1717EXPORT_SYMBOL(snd_rawmidi_transmit_peek);
1718EXPORT_SYMBOL(snd_rawmidi_transmit_ack);
1719EXPORT_SYMBOL(snd_rawmidi_transmit);
1720EXPORT_SYMBOL(snd_rawmidi_new);
1721EXPORT_SYMBOL(snd_rawmidi_set_ops);
1722EXPORT_SYMBOL(snd_rawmidi_info_select);
1723EXPORT_SYMBOL(snd_rawmidi_kernel_open);
1724EXPORT_SYMBOL(snd_rawmidi_kernel_release);
1725EXPORT_SYMBOL(snd_rawmidi_kernel_read);
1726EXPORT_SYMBOL(snd_rawmidi_kernel_write);
diff --git a/sound/core/rtctimer.c b/sound/core/rtctimer.c
index e85e72baff9e..f3420d11a12f 100644
--- a/sound/core/rtctimer.c
+++ b/sound/core/rtctimer.c
@@ -27,7 +27,7 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include <sound/timer.h> 28#include <sound/timer.h>
29 29
30#if defined(CONFIG_RTC) || defined(CONFIG_RTC_MODULE) 30#if IS_ENABLED(CONFIG_RTC)
31 31
32#include <linux/mc146818rtc.h> 32#include <linux/mc146818rtc.h>
33 33
@@ -132,8 +132,7 @@ static int __init rtctimer_init(void)
132 132
133 if (rtctimer_freq < 2 || rtctimer_freq > 8192 || 133 if (rtctimer_freq < 2 || rtctimer_freq > 8192 ||
134 !is_power_of_2(rtctimer_freq)) { 134 !is_power_of_2(rtctimer_freq)) {
135 snd_printk(KERN_ERR "rtctimer: invalid frequency %d\n", 135 pr_err("ALSA: rtctimer: invalid frequency %d\n", rtctimer_freq);
136 rtctimer_freq);
137 return -EINVAL; 136 return -EINVAL;
138 } 137 }
139 138
@@ -185,4 +184,4 @@ MODULE_LICENSE("GPL");
185 184
186MODULE_ALIAS("snd-timer-" __stringify(SNDRV_TIMER_GLOBAL_RTC)); 185MODULE_ALIAS("snd-timer-" __stringify(SNDRV_TIMER_GLOBAL_RTC));
187 186
188#endif /* CONFIG_RTC || CONFIG_RTC_MODULE */ 187#endif /* IS_ENABLED(CONFIG_RTC) */
diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
index 8d4d5e853efe..16d42679e43f 100644
--- a/sound/core/seq/oss/seq_oss.c
+++ b/sound/core/seq/oss/seq_oss.c
@@ -39,12 +39,6 @@ MODULE_LICENSE("GPL");
39MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_SEQUENCER); 39MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_SEQUENCER);
40MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MUSIC); 40MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MUSIC);
41 41
42#ifdef SNDRV_SEQ_OSS_DEBUG
43module_param(seq_oss_debug, int, 0644);
44MODULE_PARM_DESC(seq_oss_debug, "debug option");
45int seq_oss_debug = 0;
46#endif
47
48 42
49/* 43/*
50 * prototypes 44 * prototypes
@@ -231,22 +225,19 @@ register_device(void)
231 mutex_lock(&register_mutex); 225 mutex_lock(&register_mutex);
232 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, 226 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
233 NULL, 0, 227 NULL, 0,
234 &seq_oss_f_ops, NULL, 228 &seq_oss_f_ops, NULL)) < 0) {
235 SNDRV_SEQ_OSS_DEVNAME)) < 0) { 229 pr_err("ALSA: seq_oss: can't register device seq\n");
236 snd_printk(KERN_ERR "can't register device seq\n");
237 mutex_unlock(&register_mutex); 230 mutex_unlock(&register_mutex);
238 return rc; 231 return rc;
239 } 232 }
240 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, 233 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
241 NULL, 0, 234 NULL, 0,
242 &seq_oss_f_ops, NULL, 235 &seq_oss_f_ops, NULL)) < 0) {
243 SNDRV_SEQ_OSS_DEVNAME)) < 0) { 236 pr_err("ALSA: seq_oss: can't register device music\n");
244 snd_printk(KERN_ERR "can't register device music\n");
245 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0); 237 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
246 mutex_unlock(&register_mutex); 238 mutex_unlock(&register_mutex);
247 return rc; 239 return rc;
248 } 240 }
249 debug_printk(("device registered\n"));
250 mutex_unlock(&register_mutex); 241 mutex_unlock(&register_mutex);
251 return 0; 242 return 0;
252} 243}
@@ -255,11 +246,10 @@ static void
255unregister_device(void) 246unregister_device(void)
256{ 247{
257 mutex_lock(&register_mutex); 248 mutex_lock(&register_mutex);
258 debug_printk(("device unregistered\n"));
259 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0) 249 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
260 snd_printk(KERN_ERR "error unregister device music\n"); 250 pr_err("ALSA: seq_oss: error unregister device music\n");
261 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0) 251 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
262 snd_printk(KERN_ERR "error unregister device seq\n"); 252 pr_err("ALSA: seq_oss: error unregister device seq\n");
263 mutex_unlock(&register_mutex); 253 mutex_unlock(&register_mutex);
264} 254}
265 255
diff --git a/sound/core/seq/oss/seq_oss_device.h b/sound/core/seq/oss/seq_oss_device.h
index c0154a959d55..b43924325249 100644
--- a/sound/core/seq/oss/seq_oss_device.h
+++ b/sound/core/seq/oss/seq_oss_device.h
@@ -31,9 +31,6 @@
31#include <sound/seq_kernel.h> 31#include <sound/seq_kernel.h>
32#include <sound/info.h> 32#include <sound/info.h>
33 33
34/* enable debug print */
35#define SNDRV_SEQ_OSS_DEBUG
36
37/* max. applications */ 34/* max. applications */
38#define SNDRV_SEQ_OSS_MAX_CLIENTS 16 35#define SNDRV_SEQ_OSS_MAX_CLIENTS 16
39#define SNDRV_SEQ_OSS_MAX_SYNTH_DEVS 16 36#define SNDRV_SEQ_OSS_MAX_SYNTH_DEVS 16
@@ -46,7 +43,6 @@
46#define SNDRV_SEQ_OSS_VERSION_STR "0.1.8" 43#define SNDRV_SEQ_OSS_VERSION_STR "0.1.8"
47 44
48/* device and proc interface name */ 45/* device and proc interface name */
49#define SNDRV_SEQ_OSS_DEVNAME "seq_oss"
50#define SNDRV_SEQ_OSS_PROCNAME "oss" 46#define SNDRV_SEQ_OSS_PROCNAME "oss"
51 47
52 48
@@ -177,13 +173,4 @@ snd_seq_oss_fill_addr(struct seq_oss_devinfo *dp, struct snd_seq_event *ev,
177/* misc. functions for proc interface */ 173/* misc. functions for proc interface */
178char *enabled_str(int bool); 174char *enabled_str(int bool);
179 175
180
181/* for debug */
182#ifdef SNDRV_SEQ_OSS_DEBUG
183extern int seq_oss_debug;
184#define debug_printk(x) do { if (seq_oss_debug > 0) snd_printd x; } while (0)
185#else
186#define debug_printk(x) /**/
187#endif
188
189#endif /* __SEQ_OSS_DEVICE_H */ 176#endif /* __SEQ_OSS_DEVICE_H */
diff --git a/sound/core/seq/oss/seq_oss_init.c b/sound/core/seq/oss/seq_oss_init.c
index b3f39b5ed742..b9184d20c39f 100644
--- a/sound/core/seq/oss/seq_oss_init.c
+++ b/sound/core/seq/oss/seq_oss_init.c
@@ -92,7 +92,6 @@ snd_seq_oss_create_client(void)
92 goto __error; 92 goto __error;
93 93
94 system_client = rc; 94 system_client = rc;
95 debug_printk(("new client = %d\n", rc));
96 95
97 /* create annoucement receiver port */ 96 /* create annoucement receiver port */
98 memset(port, 0, sizeof(*port)); 97 memset(port, 0, sizeof(*port));
@@ -190,10 +189,9 @@ snd_seq_oss_open(struct file *file, int level)
190 189
191 dp = kzalloc(sizeof(*dp), GFP_KERNEL); 190 dp = kzalloc(sizeof(*dp), GFP_KERNEL);
192 if (!dp) { 191 if (!dp) {
193 snd_printk(KERN_ERR "can't malloc device info\n"); 192 pr_err("ALSA: seq_oss: can't malloc device info\n");
194 return -ENOMEM; 193 return -ENOMEM;
195 } 194 }
196 debug_printk(("oss_open: dp = %p\n", dp));
197 195
198 dp->cseq = system_client; 196 dp->cseq = system_client;
199 dp->port = -1; 197 dp->port = -1;
@@ -206,7 +204,7 @@ snd_seq_oss_open(struct file *file, int level)
206 204
207 dp->index = i; 205 dp->index = i;
208 if (i >= SNDRV_SEQ_OSS_MAX_CLIENTS) { 206 if (i >= SNDRV_SEQ_OSS_MAX_CLIENTS) {
209 snd_printk(KERN_ERR "too many applications\n"); 207 pr_err("ALSA: seq_oss: too many applications\n");
210 rc = -ENOMEM; 208 rc = -ENOMEM;
211 goto _error; 209 goto _error;
212 } 210 }
@@ -216,21 +214,19 @@ snd_seq_oss_open(struct file *file, int level)
216 snd_seq_oss_midi_setup(dp); 214 snd_seq_oss_midi_setup(dp);
217 215
218 if (dp->synth_opened == 0 && dp->max_mididev == 0) { 216 if (dp->synth_opened == 0 && dp->max_mididev == 0) {
219 /* snd_printk(KERN_ERR "no device found\n"); */ 217 /* pr_err("ALSA: seq_oss: no device found\n"); */
220 rc = -ENODEV; 218 rc = -ENODEV;
221 goto _error; 219 goto _error;
222 } 220 }
223 221
224 /* create port */ 222 /* create port */
225 debug_printk(("create new port\n"));
226 rc = create_port(dp); 223 rc = create_port(dp);
227 if (rc < 0) { 224 if (rc < 0) {
228 snd_printk(KERN_ERR "can't create port\n"); 225 pr_err("ALSA: seq_oss: can't create port\n");
229 goto _error; 226 goto _error;
230 } 227 }
231 228
232 /* allocate queue */ 229 /* allocate queue */
233 debug_printk(("allocate queue\n"));
234 rc = alloc_seq_queue(dp); 230 rc = alloc_seq_queue(dp);
235 if (rc < 0) 231 if (rc < 0)
236 goto _error; 232 goto _error;
@@ -247,7 +243,6 @@ snd_seq_oss_open(struct file *file, int level)
247 dp->file_mode = translate_mode(file); 243 dp->file_mode = translate_mode(file);
248 244
249 /* initialize read queue */ 245 /* initialize read queue */
250 debug_printk(("initialize read queue\n"));
251 if (is_read_mode(dp->file_mode)) { 246 if (is_read_mode(dp->file_mode)) {
252 dp->readq = snd_seq_oss_readq_new(dp, maxqlen); 247 dp->readq = snd_seq_oss_readq_new(dp, maxqlen);
253 if (!dp->readq) { 248 if (!dp->readq) {
@@ -257,7 +252,6 @@ snd_seq_oss_open(struct file *file, int level)
257 } 252 }
258 253
259 /* initialize write queue */ 254 /* initialize write queue */
260 debug_printk(("initialize write queue\n"));
261 if (is_write_mode(dp->file_mode)) { 255 if (is_write_mode(dp->file_mode)) {
262 dp->writeq = snd_seq_oss_writeq_new(dp, maxqlen); 256 dp->writeq = snd_seq_oss_writeq_new(dp, maxqlen);
263 if (!dp->writeq) { 257 if (!dp->writeq) {
@@ -267,14 +261,12 @@ snd_seq_oss_open(struct file *file, int level)
267 } 261 }
268 262
269 /* initialize timer */ 263 /* initialize timer */
270 debug_printk(("initialize timer\n"));
271 dp->timer = snd_seq_oss_timer_new(dp); 264 dp->timer = snd_seq_oss_timer_new(dp);
272 if (!dp->timer) { 265 if (!dp->timer) {
273 snd_printk(KERN_ERR "can't alloc timer\n"); 266 pr_err("ALSA: seq_oss: can't alloc timer\n");
274 rc = -ENOMEM; 267 rc = -ENOMEM;
275 goto _error; 268 goto _error;
276 } 269 }
277 debug_printk(("timer initialized\n"));
278 270
279 /* set private data pointer */ 271 /* set private data pointer */
280 file->private_data = dp; 272 file->private_data = dp;
@@ -288,7 +280,6 @@ snd_seq_oss_open(struct file *file, int level)
288 client_table[dp->index] = dp; 280 client_table[dp->index] = dp;
289 num_clients++; 281 num_clients++;
290 282
291 debug_printk(("open done\n"));
292 return 0; 283 return 0;
293 284
294 _error: 285 _error:
@@ -347,7 +338,6 @@ create_port(struct seq_oss_devinfo *dp)
347 return rc; 338 return rc;
348 339
349 dp->port = port.addr.port; 340 dp->port = port.addr.port;
350 debug_printk(("new port = %d\n", port.addr.port));
351 341
352 return 0; 342 return 0;
353} 343}
@@ -363,7 +353,6 @@ delete_port(struct seq_oss_devinfo *dp)
363 return 0; 353 return 0;
364 } 354 }
365 355
366 debug_printk(("delete_port %i\n", dp->port));
367 return snd_seq_event_port_detach(dp->cseq, dp->port); 356 return snd_seq_event_port_detach(dp->cseq, dp->port);
368} 357}
369 358
@@ -401,7 +390,7 @@ delete_seq_queue(int queue)
401 qinfo.queue = queue; 390 qinfo.queue = queue;
402 rc = call_ctl(SNDRV_SEQ_IOCTL_DELETE_QUEUE, &qinfo); 391 rc = call_ctl(SNDRV_SEQ_IOCTL_DELETE_QUEUE, &qinfo);
403 if (rc < 0) 392 if (rc < 0)
404 printk(KERN_ERR "seq-oss: unable to delete queue %d (%d)\n", queue, rc); 393 pr_err("ALSA: seq_oss: unable to delete queue %d (%d)\n", queue, rc);
405 return rc; 394 return rc;
406} 395}
407 396
@@ -438,21 +427,16 @@ snd_seq_oss_release(struct seq_oss_devinfo *dp)
438 client_table[dp->index] = NULL; 427 client_table[dp->index] = NULL;
439 num_clients--; 428 num_clients--;
440 429
441 debug_printk(("resetting..\n"));
442 snd_seq_oss_reset(dp); 430 snd_seq_oss_reset(dp);
443 431
444 debug_printk(("cleaning up..\n"));
445 snd_seq_oss_synth_cleanup(dp); 432 snd_seq_oss_synth_cleanup(dp);
446 snd_seq_oss_midi_cleanup(dp); 433 snd_seq_oss_midi_cleanup(dp);
447 434
448 /* clear slot */ 435 /* clear slot */
449 debug_printk(("releasing resource..\n"));
450 queue = dp->queue; 436 queue = dp->queue;
451 if (dp->port >= 0) 437 if (dp->port >= 0)
452 delete_port(dp); 438 delete_port(dp);
453 delete_seq_queue(queue); 439 delete_seq_queue(queue);
454
455 debug_printk(("release done\n"));
456} 440}
457 441
458 442
@@ -466,7 +450,6 @@ snd_seq_oss_drain_write(struct seq_oss_devinfo *dp)
466 return; 450 return;
467 if (is_write_mode(dp->file_mode) && !is_nonblock_mode(dp->file_mode) && 451 if (is_write_mode(dp->file_mode) && !is_nonblock_mode(dp->file_mode) &&
468 dp->writeq) { 452 dp->writeq) {
469 debug_printk(("syncing..\n"));
470 while (snd_seq_oss_writeq_sync(dp->writeq)) 453 while (snd_seq_oss_writeq_sync(dp->writeq))
471 ; 454 ;
472 } 455 }
diff --git a/sound/core/seq/oss/seq_oss_ioctl.c b/sound/core/seq/oss/seq_oss_ioctl.c
index 5ac701c903c1..5b8520177b0e 100644
--- a/sound/core/seq/oss/seq_oss_ioctl.c
+++ b/sound/core/seq/oss/seq_oss_ioctl.c
@@ -90,12 +90,10 @@ snd_seq_oss_ioctl(struct seq_oss_devinfo *dp, unsigned int cmd, unsigned long ca
90 return snd_seq_oss_timer_ioctl(dp->timer, cmd, arg); 90 return snd_seq_oss_timer_ioctl(dp->timer, cmd, arg);
91 91
92 case SNDCTL_SEQ_PANIC: 92 case SNDCTL_SEQ_PANIC:
93 debug_printk(("panic\n"));
94 snd_seq_oss_reset(dp); 93 snd_seq_oss_reset(dp);
95 return -EINVAL; 94 return -EINVAL;
96 95
97 case SNDCTL_SEQ_SYNC: 96 case SNDCTL_SEQ_SYNC:
98 debug_printk(("sync\n"));
99 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL) 97 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
100 return 0; 98 return 0;
101 while (snd_seq_oss_writeq_sync(dp->writeq)) 99 while (snd_seq_oss_writeq_sync(dp->writeq))
@@ -105,55 +103,45 @@ snd_seq_oss_ioctl(struct seq_oss_devinfo *dp, unsigned int cmd, unsigned long ca
105 return 0; 103 return 0;
106 104
107 case SNDCTL_SEQ_RESET: 105 case SNDCTL_SEQ_RESET:
108 debug_printk(("reset\n"));
109 snd_seq_oss_reset(dp); 106 snd_seq_oss_reset(dp);
110 return 0; 107 return 0;
111 108
112 case SNDCTL_SEQ_TESTMIDI: 109 case SNDCTL_SEQ_TESTMIDI:
113 debug_printk(("test midi\n"));
114 if (get_user(dev, p)) 110 if (get_user(dev, p))
115 return -EFAULT; 111 return -EFAULT;
116 return snd_seq_oss_midi_open(dp, dev, dp->file_mode); 112 return snd_seq_oss_midi_open(dp, dev, dp->file_mode);
117 113
118 case SNDCTL_SEQ_GETINCOUNT: 114 case SNDCTL_SEQ_GETINCOUNT:
119 debug_printk(("get in count\n"));
120 if (dp->readq == NULL || ! is_read_mode(dp->file_mode)) 115 if (dp->readq == NULL || ! is_read_mode(dp->file_mode))
121 return 0; 116 return 0;
122 return put_user(dp->readq->qlen, p) ? -EFAULT : 0; 117 return put_user(dp->readq->qlen, p) ? -EFAULT : 0;
123 118
124 case SNDCTL_SEQ_GETOUTCOUNT: 119 case SNDCTL_SEQ_GETOUTCOUNT:
125 debug_printk(("get out count\n"));
126 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL) 120 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
127 return 0; 121 return 0;
128 return put_user(snd_seq_oss_writeq_get_free_size(dp->writeq), p) ? -EFAULT : 0; 122 return put_user(snd_seq_oss_writeq_get_free_size(dp->writeq), p) ? -EFAULT : 0;
129 123
130 case SNDCTL_SEQ_GETTIME: 124 case SNDCTL_SEQ_GETTIME:
131 debug_printk(("get time\n"));
132 return put_user(snd_seq_oss_timer_cur_tick(dp->timer), p) ? -EFAULT : 0; 125 return put_user(snd_seq_oss_timer_cur_tick(dp->timer), p) ? -EFAULT : 0;
133 126
134 case SNDCTL_SEQ_RESETSAMPLES: 127 case SNDCTL_SEQ_RESETSAMPLES:
135 debug_printk(("reset samples\n"));
136 if (get_user(dev, p)) 128 if (get_user(dev, p))
137 return -EFAULT; 129 return -EFAULT;
138 return snd_seq_oss_synth_ioctl(dp, dev, cmd, carg); 130 return snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
139 131
140 case SNDCTL_SEQ_NRSYNTHS: 132 case SNDCTL_SEQ_NRSYNTHS:
141 debug_printk(("nr synths\n"));
142 return put_user(dp->max_synthdev, p) ? -EFAULT : 0; 133 return put_user(dp->max_synthdev, p) ? -EFAULT : 0;
143 134
144 case SNDCTL_SEQ_NRMIDIS: 135 case SNDCTL_SEQ_NRMIDIS:
145 debug_printk(("nr midis\n"));
146 return put_user(dp->max_mididev, p) ? -EFAULT : 0; 136 return put_user(dp->max_mididev, p) ? -EFAULT : 0;
147 137
148 case SNDCTL_SYNTH_MEMAVL: 138 case SNDCTL_SYNTH_MEMAVL:
149 debug_printk(("mem avail\n"));
150 if (get_user(dev, p)) 139 if (get_user(dev, p))
151 return -EFAULT; 140 return -EFAULT;
152 val = snd_seq_oss_synth_ioctl(dp, dev, cmd, carg); 141 val = snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
153 return put_user(val, p) ? -EFAULT : 0; 142 return put_user(val, p) ? -EFAULT : 0;
154 143
155 case SNDCTL_FM_4OP_ENABLE: 144 case SNDCTL_FM_4OP_ENABLE:
156 debug_printk(("4op\n"));
157 if (get_user(dev, p)) 145 if (get_user(dev, p))
158 return -EFAULT; 146 return -EFAULT;
159 snd_seq_oss_synth_ioctl(dp, dev, cmd, carg); 147 snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
@@ -161,19 +149,15 @@ snd_seq_oss_ioctl(struct seq_oss_devinfo *dp, unsigned int cmd, unsigned long ca
161 149
162 case SNDCTL_SYNTH_INFO: 150 case SNDCTL_SYNTH_INFO:
163 case SNDCTL_SYNTH_ID: 151 case SNDCTL_SYNTH_ID:
164 debug_printk(("synth info\n"));
165 return snd_seq_oss_synth_info_user(dp, arg); 152 return snd_seq_oss_synth_info_user(dp, arg);
166 153
167 case SNDCTL_SEQ_OUTOFBAND: 154 case SNDCTL_SEQ_OUTOFBAND:
168 debug_printk(("out of band\n"));
169 return snd_seq_oss_oob_user(dp, arg); 155 return snd_seq_oss_oob_user(dp, arg);
170 156
171 case SNDCTL_MIDI_INFO: 157 case SNDCTL_MIDI_INFO:
172 debug_printk(("midi info\n"));
173 return snd_seq_oss_midi_info_user(dp, arg); 158 return snd_seq_oss_midi_info_user(dp, arg);
174 159
175 case SNDCTL_SEQ_THRESHOLD: 160 case SNDCTL_SEQ_THRESHOLD:
176 debug_printk(("threshold\n"));
177 if (! is_write_mode(dp->file_mode)) 161 if (! is_write_mode(dp->file_mode))
178 return 0; 162 return 0;
179 if (get_user(val, p)) 163 if (get_user(val, p))
@@ -186,7 +170,6 @@ snd_seq_oss_ioctl(struct seq_oss_devinfo *dp, unsigned int cmd, unsigned long ca
186 return 0; 170 return 0;
187 171
188 case SNDCTL_MIDI_PRETIME: 172 case SNDCTL_MIDI_PRETIME:
189 debug_printk(("pretime\n"));
190 if (dp->readq == NULL || !is_read_mode(dp->file_mode)) 173 if (dp->readq == NULL || !is_read_mode(dp->file_mode))
191 return 0; 174 return 0;
192 if (get_user(val, p)) 175 if (get_user(val, p))
@@ -199,7 +182,6 @@ snd_seq_oss_ioctl(struct seq_oss_devinfo *dp, unsigned int cmd, unsigned long ca
199 return put_user(val, p) ? -EFAULT : 0; 182 return put_user(val, p) ? -EFAULT : 0;
200 183
201 default: 184 default:
202 debug_printk(("others\n"));
203 if (! is_write_mode(dp->file_mode)) 185 if (! is_write_mode(dp->file_mode))
204 return -EIO; 186 return -EIO;
205 return snd_seq_oss_synth_ioctl(dp, 0, cmd, carg); 187 return snd_seq_oss_synth_ioctl(dp, 0, cmd, carg);
diff --git a/sound/core/seq/oss/seq_oss_midi.c b/sound/core/seq/oss/seq_oss_midi.c
index 862d84893ee8..3a4569669efa 100644
--- a/sound/core/seq/oss/seq_oss_midi.c
+++ b/sound/core/seq/oss/seq_oss_midi.c
@@ -153,7 +153,6 @@ snd_seq_oss_midi_check_new_port(struct snd_seq_port_info *pinfo)
153 struct seq_oss_midi *mdev; 153 struct seq_oss_midi *mdev;
154 unsigned long flags; 154 unsigned long flags;
155 155
156 debug_printk(("check for MIDI client %d port %d\n", pinfo->addr.client, pinfo->addr.port));
157 /* the port must include generic midi */ 156 /* the port must include generic midi */
158 if (! (pinfo->type & SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC)) 157 if (! (pinfo->type & SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC))
159 return 0; 158 return 0;
@@ -175,7 +174,7 @@ snd_seq_oss_midi_check_new_port(struct snd_seq_port_info *pinfo)
175 * allocate midi info record 174 * allocate midi info record
176 */ 175 */
177 if ((mdev = kzalloc(sizeof(*mdev), GFP_KERNEL)) == NULL) { 176 if ((mdev = kzalloc(sizeof(*mdev), GFP_KERNEL)) == NULL) {
178 snd_printk(KERN_ERR "can't malloc midi info\n"); 177 pr_err("ALSA: seq_oss: can't malloc midi info\n");
179 return -ENOMEM; 178 return -ENOMEM;
180 } 179 }
181 180
@@ -191,7 +190,7 @@ snd_seq_oss_midi_check_new_port(struct snd_seq_port_info *pinfo)
191 190
192 /* create MIDI coder */ 191 /* create MIDI coder */
193 if (snd_midi_event_new(MAX_MIDI_EVENT_BUF, &mdev->coder) < 0) { 192 if (snd_midi_event_new(MAX_MIDI_EVENT_BUF, &mdev->coder) < 0) {
194 snd_printk(KERN_ERR "can't malloc midi coder\n"); 193 pr_err("ALSA: seq_oss: can't malloc midi coder\n");
195 kfree(mdev); 194 kfree(mdev);
196 return -ENOMEM; 195 return -ENOMEM;
197 } 196 }
@@ -406,7 +405,6 @@ snd_seq_oss_midi_close(struct seq_oss_devinfo *dp, int dev)
406 return 0; 405 return 0;
407 } 406 }
408 407
409 debug_printk(("closing client %d port %d mode %d\n", mdev->client, mdev->port, mdev->opened));
410 memset(&subs, 0, sizeof(subs)); 408 memset(&subs, 0, sizeof(subs));
411 if (mdev->opened & PERM_WRITE) { 409 if (mdev->opened & PERM_WRITE) {
412 subs.sender = dp->addr; 410 subs.sender = dp->addr;
@@ -470,7 +468,6 @@ snd_seq_oss_midi_reset(struct seq_oss_devinfo *dp, int dev)
470 struct snd_seq_event ev; 468 struct snd_seq_event ev;
471 int c; 469 int c;
472 470
473 debug_printk(("resetting client %d port %d\n", mdev->client, mdev->port));
474 memset(&ev, 0, sizeof(ev)); 471 memset(&ev, 0, sizeof(ev));
475 ev.dest.client = mdev->client; 472 ev.dest.client = mdev->client;
476 ev.dest.port = mdev->port; 473 ev.dest.port = mdev->port;
diff --git a/sound/core/seq/oss/seq_oss_readq.c b/sound/core/seq/oss/seq_oss_readq.c
index 73661c4ab82a..654d17a5023c 100644
--- a/sound/core/seq/oss/seq_oss_readq.c
+++ b/sound/core/seq/oss/seq_oss_readq.c
@@ -48,12 +48,12 @@ snd_seq_oss_readq_new(struct seq_oss_devinfo *dp, int maxlen)
48 struct seq_oss_readq *q; 48 struct seq_oss_readq *q;
49 49
50 if ((q = kzalloc(sizeof(*q), GFP_KERNEL)) == NULL) { 50 if ((q = kzalloc(sizeof(*q), GFP_KERNEL)) == NULL) {
51 snd_printk(KERN_ERR "can't malloc read queue\n"); 51 pr_err("ALSA: seq_oss: can't malloc read queue\n");
52 return NULL; 52 return NULL;
53 } 53 }
54 54
55 if ((q->q = kcalloc(maxlen, sizeof(union evrec), GFP_KERNEL)) == NULL) { 55 if ((q->q = kcalloc(maxlen, sizeof(union evrec), GFP_KERNEL)) == NULL) {
56 snd_printk(KERN_ERR "can't malloc read queue buffer\n"); 56 pr_err("ALSA: seq_oss: can't malloc read queue buffer\n");
57 kfree(q); 57 kfree(q);
58 return NULL; 58 return NULL;
59 } 59 }
diff --git a/sound/core/seq/oss/seq_oss_synth.c b/sound/core/seq/oss/seq_oss_synth.c
index c5b773a1eea9..701feb71b700 100644
--- a/sound/core/seq/oss/seq_oss_synth.c
+++ b/sound/core/seq/oss/seq_oss_synth.c
@@ -106,7 +106,7 @@ snd_seq_oss_synth_register(struct snd_seq_device *dev)
106 unsigned long flags; 106 unsigned long flags;
107 107
108 if ((rec = kzalloc(sizeof(*rec), GFP_KERNEL)) == NULL) { 108 if ((rec = kzalloc(sizeof(*rec), GFP_KERNEL)) == NULL) {
109 snd_printk(KERN_ERR "can't malloc synth info\n"); 109 pr_err("ALSA: seq_oss: can't malloc synth info\n");
110 return -ENOMEM; 110 return -ENOMEM;
111 } 111 }
112 rec->seq_device = -1; 112 rec->seq_device = -1;
@@ -130,7 +130,7 @@ snd_seq_oss_synth_register(struct snd_seq_device *dev)
130 if (i >= max_synth_devs) { 130 if (i >= max_synth_devs) {
131 if (max_synth_devs >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS) { 131 if (max_synth_devs >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS) {
132 spin_unlock_irqrestore(&register_lock, flags); 132 spin_unlock_irqrestore(&register_lock, flags);
133 snd_printk(KERN_ERR "no more synth slot\n"); 133 pr_err("ALSA: seq_oss: no more synth slot\n");
134 kfree(rec); 134 kfree(rec);
135 return -ENOMEM; 135 return -ENOMEM;
136 } 136 }
@@ -138,7 +138,6 @@ snd_seq_oss_synth_register(struct snd_seq_device *dev)
138 } 138 }
139 rec->seq_device = i; 139 rec->seq_device = i;
140 synth_devs[i] = rec; 140 synth_devs[i] = rec;
141 debug_printk(("synth %s registered %d\n", rec->name, i));
142 spin_unlock_irqrestore(&register_lock, flags); 141 spin_unlock_irqrestore(&register_lock, flags);
143 dev->driver_data = rec; 142 dev->driver_data = rec;
144#ifdef SNDRV_OSS_INFO_DEV_SYNTH 143#ifdef SNDRV_OSS_INFO_DEV_SYNTH
@@ -163,7 +162,7 @@ snd_seq_oss_synth_unregister(struct snd_seq_device *dev)
163 } 162 }
164 if (index >= max_synth_devs) { 163 if (index >= max_synth_devs) {
165 spin_unlock_irqrestore(&register_lock, flags); 164 spin_unlock_irqrestore(&register_lock, flags);
166 snd_printk(KERN_ERR "can't unregister synth\n"); 165 pr_err("ALSA: seq_oss: can't unregister synth\n");
167 return -EINVAL; 166 return -EINVAL;
168 } 167 }
169 synth_devs[index] = NULL; 168 synth_devs[index] = NULL;
@@ -248,7 +247,7 @@ snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp)
248 if (info->nr_voices > 0) { 247 if (info->nr_voices > 0) {
249 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL); 248 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL);
250 if (!info->ch) { 249 if (!info->ch) {
251 snd_printk(KERN_ERR "Cannot malloc\n"); 250 pr_err("ALSA: seq_oss: Cannot malloc voices\n");
252 rec->oper.close(&info->arg); 251 rec->oper.close(&info->arg);
253 module_put(rec->oper.owner); 252 module_put(rec->oper.owner);
254 snd_use_lock_free(&rec->use_lock); 253 snd_use_lock_free(&rec->use_lock);
@@ -256,7 +255,6 @@ snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp)
256 } 255 }
257 reset_channels(info); 256 reset_channels(info);
258 } 257 }
259 debug_printk(("synth %d assigned\n", i));
260 info->opened++; 258 info->opened++;
261 rec->opened++; 259 rec->opened++;
262 dp->synth_opened++; 260 dp->synth_opened++;
@@ -326,7 +324,6 @@ snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp)
326 if (rec == NULL) 324 if (rec == NULL)
327 continue; 325 continue;
328 if (rec->opened > 0) { 326 if (rec->opened > 0) {
329 debug_printk(("synth %d closed\n", i));
330 rec->oper.close(&info->arg); 327 rec->oper.close(&info->arg);
331 module_put(rec->oper.owner); 328 module_put(rec->oper.owner);
332 rec->opened = 0; 329 rec->opened = 0;
diff --git a/sound/core/seq/oss/seq_oss_timer.c b/sound/core/seq/oss/seq_oss_timer.c
index ab59cbfbcaf2..4f24ea9fad93 100644
--- a/sound/core/seq/oss/seq_oss_timer.c
+++ b/sound/core/seq/oss/seq_oss_timer.c
@@ -233,7 +233,6 @@ snd_seq_oss_timer_ioctl(struct seq_oss_timer *timer, unsigned int cmd, int __use
233 int value; 233 int value;
234 234
235 if (cmd == SNDCTL_SEQ_CTRLRATE) { 235 if (cmd == SNDCTL_SEQ_CTRLRATE) {
236 debug_printk(("ctrl rate\n"));
237 /* if *arg == 0, just return the current rate */ 236 /* if *arg == 0, just return the current rate */
238 if (get_user(value, arg)) 237 if (get_user(value, arg))
239 return -EFAULT; 238 return -EFAULT;
@@ -248,21 +247,16 @@ snd_seq_oss_timer_ioctl(struct seq_oss_timer *timer, unsigned int cmd, int __use
248 247
249 switch (cmd) { 248 switch (cmd) {
250 case SNDCTL_TMR_START: 249 case SNDCTL_TMR_START:
251 debug_printk(("timer start\n"));
252 return snd_seq_oss_timer_start(timer); 250 return snd_seq_oss_timer_start(timer);
253 case SNDCTL_TMR_STOP: 251 case SNDCTL_TMR_STOP:
254 debug_printk(("timer stop\n"));
255 return snd_seq_oss_timer_stop(timer); 252 return snd_seq_oss_timer_stop(timer);
256 case SNDCTL_TMR_CONTINUE: 253 case SNDCTL_TMR_CONTINUE:
257 debug_printk(("timer continue\n"));
258 return snd_seq_oss_timer_continue(timer); 254 return snd_seq_oss_timer_continue(timer);
259 case SNDCTL_TMR_TEMPO: 255 case SNDCTL_TMR_TEMPO:
260 debug_printk(("timer tempo\n"));
261 if (get_user(value, arg)) 256 if (get_user(value, arg))
262 return -EFAULT; 257 return -EFAULT;
263 return snd_seq_oss_timer_tempo(timer, value); 258 return snd_seq_oss_timer_tempo(timer, value);
264 case SNDCTL_TMR_TIMEBASE: 259 case SNDCTL_TMR_TIMEBASE:
265 debug_printk(("timer timebase\n"));
266 if (get_user(value, arg)) 260 if (get_user(value, arg))
267 return -EFAULT; 261 return -EFAULT;
268 if (value < MIN_OSS_TIMEBASE) 262 if (value < MIN_OSS_TIMEBASE)
@@ -276,7 +270,6 @@ snd_seq_oss_timer_ioctl(struct seq_oss_timer *timer, unsigned int cmd, int __use
276 case SNDCTL_TMR_METRONOME: 270 case SNDCTL_TMR_METRONOME:
277 case SNDCTL_TMR_SELECT: 271 case SNDCTL_TMR_SELECT:
278 case SNDCTL_TMR_SOURCE: 272 case SNDCTL_TMR_SOURCE:
279 debug_printk(("timer XXX\n"));
280 /* not supported */ 273 /* not supported */
281 return 0; 274 return 0;
282 } 275 }
diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c
index 4dc6bae80e15..9ca5e647e54b 100644
--- a/sound/core/seq/seq_clientmgr.c
+++ b/sound/core/seq/seq_clientmgr.c
@@ -123,7 +123,7 @@ static inline int snd_seq_write_pool_allocated(struct snd_seq_client *client)
123static struct snd_seq_client *clientptr(int clientid) 123static struct snd_seq_client *clientptr(int clientid)
124{ 124{
125 if (clientid < 0 || clientid >= SNDRV_SEQ_MAX_CLIENTS) { 125 if (clientid < 0 || clientid >= SNDRV_SEQ_MAX_CLIENTS) {
126 snd_printd("Seq: oops. Trying to get pointer to client %d\n", 126 pr_debug("ALSA: seq: oops. Trying to get pointer to client %d\n",
127 clientid); 127 clientid);
128 return NULL; 128 return NULL;
129 } 129 }
@@ -136,7 +136,7 @@ struct snd_seq_client *snd_seq_client_use_ptr(int clientid)
136 struct snd_seq_client *client; 136 struct snd_seq_client *client;
137 137
138 if (clientid < 0 || clientid >= SNDRV_SEQ_MAX_CLIENTS) { 138 if (clientid < 0 || clientid >= SNDRV_SEQ_MAX_CLIENTS) {
139 snd_printd("Seq: oops. Trying to get pointer to client %d\n", 139 pr_debug("ALSA: seq: oops. Trying to get pointer to client %d\n",
140 clientid); 140 clientid);
141 return NULL; 141 return NULL;
142 } 142 }
@@ -291,8 +291,8 @@ static void seq_free_client(struct snd_seq_client * client)
291 mutex_lock(&register_mutex); 291 mutex_lock(&register_mutex);
292 switch (client->type) { 292 switch (client->type) {
293 case NO_CLIENT: 293 case NO_CLIENT:
294 snd_printk(KERN_WARNING "Seq: Trying to free unused client %d\n", 294 pr_warn("ALSA: seq: Trying to free unused client %d\n",
295 client->number); 295 client->number);
296 break; 296 break;
297 case USER_CLIENT: 297 case USER_CLIENT:
298 case KERNEL_CLIENT: 298 case KERNEL_CLIENT:
@@ -301,7 +301,7 @@ static void seq_free_client(struct snd_seq_client * client)
301 break; 301 break;
302 302
303 default: 303 default:
304 snd_printk(KERN_ERR "Seq: Trying to free client %d with undefined type = %d\n", 304 pr_err("ALSA: seq: Trying to free client %d with undefined type = %d\n",
305 client->number, client->type); 305 client->number, client->type);
306 } 306 }
307 mutex_unlock(&register_mutex); 307 mutex_unlock(&register_mutex);
@@ -773,7 +773,7 @@ static int broadcast_event(struct snd_seq_client *client,
773static int multicast_event(struct snd_seq_client *client, struct snd_seq_event *event, 773static int multicast_event(struct snd_seq_client *client, struct snd_seq_event *event,
774 int atomic, int hop) 774 int atomic, int hop)
775{ 775{
776 snd_printd("seq: multicast not supported yet.\n"); 776 pr_debug("ALSA: seq: multicast not supported yet.\n");
777 return 0; /* ignored */ 777 return 0; /* ignored */
778} 778}
779#endif /* SUPPORT_BROADCAST */ 779#endif /* SUPPORT_BROADCAST */
@@ -794,7 +794,7 @@ static int snd_seq_deliver_event(struct snd_seq_client *client, struct snd_seq_e
794 794
795 hop++; 795 hop++;
796 if (hop >= SNDRV_SEQ_MAX_HOPS) { 796 if (hop >= SNDRV_SEQ_MAX_HOPS) {
797 snd_printd("too long delivery path (%d:%d->%d:%d)\n", 797 pr_debug("ALSA: seq: too long delivery path (%d:%d->%d:%d)\n",
798 event->source.client, event->source.port, 798 event->source.client, event->source.port,
799 event->dest.client, event->dest.port); 799 event->dest.client, event->dest.port);
800 return -EMLINK; 800 return -EMLINK;
@@ -2196,7 +2196,7 @@ static int snd_seq_do_ioctl(struct snd_seq_client *client, unsigned int cmd,
2196 if (p->cmd == cmd) 2196 if (p->cmd == cmd)
2197 return p->func(client, arg); 2197 return p->func(client, arg);
2198 } 2198 }
2199 snd_printd("seq unknown ioctl() 0x%x (type='%c', number=0x%02x)\n", 2199 pr_debug("ALSA: seq unknown ioctl() 0x%x (type='%c', number=0x%02x)\n",
2200 cmd, _IOC_TYPE(cmd), _IOC_NR(cmd)); 2200 cmd, _IOC_TYPE(cmd), _IOC_NR(cmd));
2201 return -ENOTTY; 2201 return -ENOTTY;
2202} 2202}
diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
index 040c60e1da28..91a786a783e1 100644
--- a/sound/core/seq/seq_device.c
+++ b/sound/core/seq/seq_device.c
@@ -168,7 +168,7 @@ void snd_seq_device_load_drivers(void)
168 168
169/* 169/*
170 * register a sequencer device 170 * register a sequencer device
171 * card = card info (NULL allowed) 171 * card = card info
172 * device = device number (if any) 172 * device = device number (if any)
173 * id = id of driver 173 * id = id of driver
174 * result = return pointer (NULL allowed if unnecessary) 174 * result = return pointer (NULL allowed if unnecessary)
@@ -325,7 +325,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
325 return -ENOMEM; 325 return -ENOMEM;
326 } 326 }
327 if (ops->driver & DRIVER_LOADED) { 327 if (ops->driver & DRIVER_LOADED) {
328 snd_printk(KERN_WARNING "driver_register: driver '%s' already exists\n", id); 328 pr_warn("ALSA: seq: driver_register: driver '%s' already exists\n", id);
329 unlock_driver(ops); 329 unlock_driver(ops);
330 snd_seq_autoload_unlock(); 330 snd_seq_autoload_unlock();
331 return -EBUSY; 331 return -EBUSY;
@@ -398,7 +398,7 @@ int snd_seq_device_unregister_driver(char *id)
398 return -ENXIO; 398 return -ENXIO;
399 if (! (ops->driver & DRIVER_LOADED) || 399 if (! (ops->driver & DRIVER_LOADED) ||
400 (ops->driver & DRIVER_LOCKED)) { 400 (ops->driver & DRIVER_LOCKED)) {
401 snd_printk(KERN_ERR "driver_unregister: cannot unload driver '%s': status=%x\n", 401 pr_err("ALSA: seq: driver_unregister: cannot unload driver '%s': status=%x\n",
402 id, ops->driver); 402 id, ops->driver);
403 unlock_driver(ops); 403 unlock_driver(ops);
404 return -EBUSY; 404 return -EBUSY;
@@ -413,7 +413,7 @@ int snd_seq_device_unregister_driver(char *id)
413 413
414 ops->driver = 0; 414 ops->driver = 0;
415 if (ops->num_init_devices > 0) 415 if (ops->num_init_devices > 0)
416 snd_printk(KERN_ERR "free_driver: init_devices > 0!! (%d)\n", 416 pr_err("ALSA: seq: free_driver: init_devices > 0!! (%d)\n",
417 ops->num_init_devices); 417 ops->num_init_devices);
418 mutex_unlock(&ops->reg_mutex); 418 mutex_unlock(&ops->reg_mutex);
419 419
@@ -459,7 +459,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
459 if (dev->status != SNDRV_SEQ_DEVICE_FREE) 459 if (dev->status != SNDRV_SEQ_DEVICE_FREE)
460 return 0; /* already initialized */ 460 return 0; /* already initialized */
461 if (ops->argsize != dev->argsize) { 461 if (ops->argsize != dev->argsize) {
462 snd_printk(KERN_ERR "incompatible device '%s' for plug-in '%s' (%d %d)\n", 462 pr_err("ALSA: seq: incompatible device '%s' for plug-in '%s' (%d %d)\n",
463 dev->name, ops->id, ops->argsize, dev->argsize); 463 dev->name, ops->id, ops->argsize, dev->argsize);
464 return -EINVAL; 464 return -EINVAL;
465 } 465 }
@@ -467,7 +467,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
467 dev->status = SNDRV_SEQ_DEVICE_REGISTERED; 467 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
468 ops->num_init_devices++; 468 ops->num_init_devices++;
469 } else { 469 } else {
470 snd_printk(KERN_ERR "init_device failed: %s: %s\n", 470 pr_err("ALSA: seq: init_device failed: %s: %s\n",
471 dev->name, dev->id); 471 dev->name, dev->id);
472 } 472 }
473 473
@@ -486,7 +486,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
486 if (dev->status != SNDRV_SEQ_DEVICE_REGISTERED) 486 if (dev->status != SNDRV_SEQ_DEVICE_REGISTERED)
487 return 0; /* not registered */ 487 return 0; /* not registered */
488 if (ops->argsize != dev->argsize) { 488 if (ops->argsize != dev->argsize) {
489 snd_printk(KERN_ERR "incompatible device '%s' for plug-in '%s' (%d %d)\n", 489 pr_err("ALSA: seq: incompatible device '%s' for plug-in '%s' (%d %d)\n",
490 dev->name, ops->id, ops->argsize, dev->argsize); 490 dev->name, ops->id, ops->argsize, dev->argsize);
491 return -EINVAL; 491 return -EINVAL;
492 } 492 }
@@ -495,7 +495,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
495 dev->driver_data = NULL; 495 dev->driver_data = NULL;
496 ops->num_init_devices--; 496 ops->num_init_devices--;
497 } else { 497 } else {
498 snd_printk(KERN_ERR "free_device failed: %s: %s\n", 498 pr_err("ALSA: seq: free_device failed: %s: %s\n",
499 dev->name, dev->id); 499 dev->name, dev->id);
500 } 500 }
501 501
@@ -559,7 +559,7 @@ static void __exit alsa_seq_device_exit(void)
559 snd_info_free_entry(info_entry); 559 snd_info_free_entry(info_entry);
560#endif 560#endif
561 if (num_ops) 561 if (num_ops)
562 snd_printk(KERN_ERR "drivers not released (%d)\n", num_ops); 562 pr_err("ALSA: seq: drivers not released (%d)\n", num_ops);
563} 563}
564 564
565module_init(alsa_seq_device_init) 565module_init(alsa_seq_device_init)
diff --git a/sound/core/seq/seq_dummy.c b/sound/core/seq/seq_dummy.c
index dbc550716790..ec667f158f19 100644
--- a/sound/core/seq/seq_dummy.c
+++ b/sound/core/seq/seq_dummy.c
@@ -198,7 +198,7 @@ register_client(void)
198 int i; 198 int i;
199 199
200 if (ports < 1) { 200 if (ports < 1) {
201 snd_printk(KERN_ERR "invalid number of ports %d\n", ports); 201 pr_err("ALSA: seq_dummy: invalid number of ports %d\n", ports);
202 return -EINVAL; 202 return -EINVAL;
203 } 203 }
204 204
diff --git a/sound/core/seq/seq_fifo.c b/sound/core/seq/seq_fifo.c
index 0d75afa786bc..559989992bef 100644
--- a/sound/core/seq/seq_fifo.c
+++ b/sound/core/seq/seq_fifo.c
@@ -34,7 +34,7 @@ struct snd_seq_fifo *snd_seq_fifo_new(int poolsize)
34 34
35 f = kzalloc(sizeof(*f), GFP_KERNEL); 35 f = kzalloc(sizeof(*f), GFP_KERNEL);
36 if (f == NULL) { 36 if (f == NULL) {
37 snd_printd("malloc failed for snd_seq_fifo_new() \n"); 37 pr_debug("ALSA: seq: malloc failed for snd_seq_fifo_new() \n");
38 return NULL; 38 return NULL;
39 } 39 }
40 40
diff --git a/sound/core/seq/seq_lock.c b/sound/core/seq/seq_lock.c
index 2cfe50c71a9d..3b693e924db7 100644
--- a/sound/core/seq/seq_lock.c
+++ b/sound/core/seq/seq_lock.c
@@ -31,12 +31,12 @@ void snd_use_lock_sync_helper(snd_use_lock_t *lockp, const char *file, int line)
31 int max_count = 5 * HZ; 31 int max_count = 5 * HZ;
32 32
33 if (atomic_read(lockp) < 0) { 33 if (atomic_read(lockp) < 0) {
34 printk(KERN_WARNING "seq_lock: lock trouble [counter = %d] in %s:%d\n", atomic_read(lockp), file, line); 34 pr_warn("ALSA: seq_lock: lock trouble [counter = %d] in %s:%d\n", atomic_read(lockp), file, line);
35 return; 35 return;
36 } 36 }
37 while (atomic_read(lockp) > 0) { 37 while (atomic_read(lockp) > 0) {
38 if (max_count == 0) { 38 if (max_count == 0) {
39 snd_printk(KERN_WARNING "seq_lock: timeout [%d left] in %s:%d\n", atomic_read(lockp), file, line); 39 pr_warn("ALSA: seq_lock: timeout [%d left] in %s:%d\n", atomic_read(lockp), file, line);
40 break; 40 break;
41 } 41 }
42 schedule_timeout_uninterruptible(1); 42 schedule_timeout_uninterruptible(1);
diff --git a/sound/core/seq/seq_memory.c b/sound/core/seq/seq_memory.c
index f478f770bf52..1e206de0c2dd 100644
--- a/sound/core/seq/seq_memory.c
+++ b/sound/core/seq/seq_memory.c
@@ -236,7 +236,7 @@ static int snd_seq_cell_alloc(struct snd_seq_pool *pool,
236 init_waitqueue_entry(&wait, current); 236 init_waitqueue_entry(&wait, current);
237 spin_lock_irqsave(&pool->lock, flags); 237 spin_lock_irqsave(&pool->lock, flags);
238 if (pool->ptr == NULL) { /* not initialized */ 238 if (pool->ptr == NULL) { /* not initialized */
239 snd_printd("seq: pool is not initialized\n"); 239 pr_debug("ALSA: seq: pool is not initialized\n");
240 err = -EINVAL; 240 err = -EINVAL;
241 goto __error; 241 goto __error;
242 } 242 }
@@ -388,7 +388,7 @@ int snd_seq_pool_init(struct snd_seq_pool *pool)
388 388
389 pool->ptr = vmalloc(sizeof(struct snd_seq_event_cell) * pool->size); 389 pool->ptr = vmalloc(sizeof(struct snd_seq_event_cell) * pool->size);
390 if (pool->ptr == NULL) { 390 if (pool->ptr == NULL) {
391 snd_printd("seq: malloc for sequencer events failed\n"); 391 pr_debug("ALSA: seq: malloc for sequencer events failed\n");
392 return -ENOMEM; 392 return -ENOMEM;
393 } 393 }
394 394
@@ -431,7 +431,7 @@ int snd_seq_pool_done(struct snd_seq_pool *pool)
431 431
432 while (atomic_read(&pool->counter) > 0) { 432 while (atomic_read(&pool->counter) > 0) {
433 if (max_count == 0) { 433 if (max_count == 0) {
434 snd_printk(KERN_WARNING "snd_seq_pool_done timeout: %d cells remain\n", atomic_read(&pool->counter)); 434 pr_warn("ALSA: snd_seq_pool_done timeout: %d cells remain\n", atomic_read(&pool->counter));
435 break; 435 break;
436 } 436 }
437 schedule_timeout_uninterruptible(1); 437 schedule_timeout_uninterruptible(1);
@@ -464,7 +464,7 @@ struct snd_seq_pool *snd_seq_pool_new(int poolsize)
464 /* create pool block */ 464 /* create pool block */
465 pool = kzalloc(sizeof(*pool), GFP_KERNEL); 465 pool = kzalloc(sizeof(*pool), GFP_KERNEL);
466 if (pool == NULL) { 466 if (pool == NULL) {
467 snd_printd("seq: malloc failed for pool\n"); 467 pr_debug("ALSA: seq: malloc failed for pool\n");
468 return NULL; 468 return NULL;
469 } 469 }
470 spin_lock_init(&pool->lock); 470 spin_lock_init(&pool->lock);
diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
index 64069dbf89ca..3e05c55a2880 100644
--- a/sound/core/seq/seq_midi.c
+++ b/sound/core/seq/seq_midi.c
@@ -121,7 +121,7 @@ static int dump_midi(struct snd_rawmidi_substream *substream, const char *buf, i
121 runtime = substream->runtime; 121 runtime = substream->runtime;
122 if ((tmp = runtime->avail) < count) { 122 if ((tmp = runtime->avail) < count) {
123 if (printk_ratelimit()) 123 if (printk_ratelimit())
124 snd_printk(KERN_ERR "MIDI output buffer overrun\n"); 124 pr_err("ALSA: seq_midi: MIDI output buffer overrun\n");
125 return -ENOMEM; 125 return -ENOMEM;
126 } 126 }
127 if (snd_rawmidi_kernel_write(substream, buf, count) < count) 127 if (snd_rawmidi_kernel_write(substream, buf, count) < count)
@@ -145,7 +145,7 @@ static int event_process_midi(struct snd_seq_event *ev, int direct,
145 if (ev->type == SNDRV_SEQ_EVENT_SYSEX) { /* special case, to save space */ 145 if (ev->type == SNDRV_SEQ_EVENT_SYSEX) { /* special case, to save space */
146 if ((ev->flags & SNDRV_SEQ_EVENT_LENGTH_MASK) != SNDRV_SEQ_EVENT_LENGTH_VARIABLE) { 146 if ((ev->flags & SNDRV_SEQ_EVENT_LENGTH_MASK) != SNDRV_SEQ_EVENT_LENGTH_VARIABLE) {
147 /* invalid event */ 147 /* invalid event */
148 snd_printd("seq_midi: invalid sysex event flags = 0x%x\n", ev->flags); 148 pr_debug("ALSA: seq_midi: invalid sysex event flags = 0x%x\n", ev->flags);
149 return 0; 149 return 0;
150 } 150 }
151 snd_seq_dump_var_event(ev, (snd_seq_dump_func_t)dump_midi, substream); 151 snd_seq_dump_var_event(ev, (snd_seq_dump_func_t)dump_midi, substream);
@@ -189,7 +189,7 @@ static int midisynth_subscribe(void *private_data, struct snd_seq_port_subscribe
189 msynth->subdevice, 189 msynth->subdevice,
190 SNDRV_RAWMIDI_LFLG_INPUT, 190 SNDRV_RAWMIDI_LFLG_INPUT,
191 &msynth->input_rfile)) < 0) { 191 &msynth->input_rfile)) < 0) {
192 snd_printd("midi input open failed!!!\n"); 192 pr_debug("ALSA: seq_midi: midi input open failed!!!\n");
193 return err; 193 return err;
194 } 194 }
195 runtime = msynth->input_rfile.input->runtime; 195 runtime = msynth->input_rfile.input->runtime;
@@ -231,7 +231,7 @@ static int midisynth_use(void *private_data, struct snd_seq_port_subscribe *info
231 msynth->subdevice, 231 msynth->subdevice,
232 SNDRV_RAWMIDI_LFLG_OUTPUT, 232 SNDRV_RAWMIDI_LFLG_OUTPUT,
233 &msynth->output_rfile)) < 0) { 233 &msynth->output_rfile)) < 0) {
234 snd_printd("midi output open failed!!!\n"); 234 pr_debug("ALSA: seq_midi: midi output open failed!!!\n");
235 return err; 235 return err;
236 } 236 }
237 memset(&params, 0, sizeof(params)); 237 memset(&params, 0, sizeof(params));
diff --git a/sound/core/seq/seq_midi_emul.c b/sound/core/seq/seq_midi_emul.c
index 6f64471ddde3..9b6470cdcf24 100644
--- a/sound/core/seq/seq_midi_emul.c
+++ b/sound/core/seq/seq_midi_emul.c
@@ -89,7 +89,7 @@ snd_midi_process_event(struct snd_midi_op *ops,
89 int dest_channel = 0; 89 int dest_channel = 0;
90 90
91 if (ev == NULL || chanset == NULL) { 91 if (ev == NULL || chanset == NULL) {
92 snd_printd("ev or chanbase NULL (snd_midi_process_event)\n"); 92 pr_debug("ALSA: seq_midi_emul: ev or chanbase NULL (snd_midi_process_event)\n");
93 return; 93 return;
94 } 94 }
95 if (chanset->channels == NULL) 95 if (chanset->channels == NULL)
@@ -98,7 +98,7 @@ snd_midi_process_event(struct snd_midi_op *ops,
98 if (snd_seq_ev_is_channel_type(ev)) { 98 if (snd_seq_ev_is_channel_type(ev)) {
99 dest_channel = ev->data.note.channel; 99 dest_channel = ev->data.note.channel;
100 if (dest_channel >= chanset->max_channels) { 100 if (dest_channel >= chanset->max_channels) {
101 snd_printd("dest channel is %d, max is %d\n", 101 pr_debug("ALSA: seq_midi_emul: dest channel is %d, max is %d\n",
102 dest_channel, chanset->max_channels); 102 dest_channel, chanset->max_channels);
103 return; 103 return;
104 } 104 }
@@ -232,7 +232,7 @@ snd_midi_process_event(struct snd_midi_op *ops,
232 case SNDRV_SEQ_EVENT_ECHO: 232 case SNDRV_SEQ_EVENT_ECHO:
233 not_yet: 233 not_yet:
234 default: 234 default:
235 /*snd_printd("Unimplemented event %d\n", ev->type);*/ 235 /*pr_debug("ALSA: seq_midi_emul: Unimplemented event %d\n", ev->type);*/
236 break; 236 break;
237 } 237 }
238} 238}
diff --git a/sound/core/seq/seq_ports.c b/sound/core/seq/seq_ports.c
index 9516e5ce3aad..794a341bf0e5 100644
--- a/sound/core/seq/seq_ports.c
+++ b/sound/core/seq/seq_ports.c
@@ -135,14 +135,14 @@ struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client,
135 return NULL; 135 return NULL;
136 136
137 if (client->num_ports >= SNDRV_SEQ_MAX_PORTS - 1) { 137 if (client->num_ports >= SNDRV_SEQ_MAX_PORTS - 1) {
138 snd_printk(KERN_WARNING "too many ports for client %d\n", client->number); 138 pr_warn("ALSA: seq: too many ports for client %d\n", client->number);
139 return NULL; 139 return NULL;
140 } 140 }
141 141
142 /* create a new port */ 142 /* create a new port */
143 new_port = kzalloc(sizeof(*new_port), GFP_KERNEL); 143 new_port = kzalloc(sizeof(*new_port), GFP_KERNEL);
144 if (! new_port) { 144 if (! new_port) {
145 snd_printd("malloc failed for registering client port\n"); 145 pr_debug("ALSA: seq: malloc failed for registering client port\n");
146 return NULL; /* failure, out of memory */ 146 return NULL; /* failure, out of memory */
147 } 147 }
148 /* init port data */ 148 /* init port data */
diff --git a/sound/core/seq/seq_prioq.c b/sound/core/seq/seq_prioq.c
index 29896ab23403..021b02bc9330 100644
--- a/sound/core/seq/seq_prioq.c
+++ b/sound/core/seq/seq_prioq.c
@@ -60,7 +60,7 @@ struct snd_seq_prioq *snd_seq_prioq_new(void)
60 60
61 f = kzalloc(sizeof(*f), GFP_KERNEL); 61 f = kzalloc(sizeof(*f), GFP_KERNEL);
62 if (f == NULL) { 62 if (f == NULL) {
63 snd_printd("oops: malloc failed for snd_seq_prioq_new()\n"); 63 pr_debug("ALSA: seq: malloc failed for snd_seq_prioq_new()\n");
64 return NULL; 64 return NULL;
65 } 65 }
66 66
@@ -79,7 +79,7 @@ void snd_seq_prioq_delete(struct snd_seq_prioq **fifo)
79 *fifo = NULL; 79 *fifo = NULL;
80 80
81 if (f == NULL) { 81 if (f == NULL) {
82 snd_printd("oops: snd_seq_prioq_delete() called with NULL prioq\n"); 82 pr_debug("ALSA: seq: snd_seq_prioq_delete() called with NULL prioq\n");
83 return; 83 return;
84 } 84 }
85 85
@@ -197,7 +197,7 @@ int snd_seq_prioq_cell_in(struct snd_seq_prioq * f,
197 cur = cur->next; 197 cur = cur->next;
198 if (! --count) { 198 if (! --count) {
199 spin_unlock_irqrestore(&f->lock, flags); 199 spin_unlock_irqrestore(&f->lock, flags);
200 snd_printk(KERN_ERR "cannot find a pointer.. infinite loop?\n"); 200 pr_err("ALSA: seq: cannot find a pointer.. infinite loop?\n");
201 return -EINVAL; 201 return -EINVAL;
202 } 202 }
203 } 203 }
@@ -223,7 +223,7 @@ struct snd_seq_event_cell *snd_seq_prioq_cell_out(struct snd_seq_prioq *f)
223 unsigned long flags; 223 unsigned long flags;
224 224
225 if (f == NULL) { 225 if (f == NULL) {
226 snd_printd("oops: snd_seq_prioq_cell_in() called with NULL prioq\n"); 226 pr_debug("ALSA: seq: snd_seq_prioq_cell_in() called with NULL prioq\n");
227 return NULL; 227 return NULL;
228 } 228 }
229 spin_lock_irqsave(&f->lock, flags); 229 spin_lock_irqsave(&f->lock, flags);
@@ -248,7 +248,7 @@ struct snd_seq_event_cell *snd_seq_prioq_cell_out(struct snd_seq_prioq *f)
248int snd_seq_prioq_avail(struct snd_seq_prioq * f) 248int snd_seq_prioq_avail(struct snd_seq_prioq * f)
249{ 249{
250 if (f == NULL) { 250 if (f == NULL) {
251 snd_printd("oops: snd_seq_prioq_cell_in() called with NULL prioq\n"); 251 pr_debug("ALSA: seq: snd_seq_prioq_cell_in() called with NULL prioq\n");
252 return 0; 252 return 0;
253 } 253 }
254 return f->cells; 254 return f->cells;
@@ -259,7 +259,7 @@ int snd_seq_prioq_avail(struct snd_seq_prioq * f)
259struct snd_seq_event_cell *snd_seq_prioq_cell_peek(struct snd_seq_prioq * f) 259struct snd_seq_event_cell *snd_seq_prioq_cell_peek(struct snd_seq_prioq * f)
260{ 260{
261 if (f == NULL) { 261 if (f == NULL) {
262 snd_printd("oops: snd_seq_prioq_cell_in() called with NULL prioq\n"); 262 pr_debug("ALSA: seq: snd_seq_prioq_cell_in() called with NULL prioq\n");
263 return NULL; 263 return NULL;
264 } 264 }
265 return f->head; 265 return f->head;
@@ -321,7 +321,7 @@ 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(KERN_DEBUG "type = %i, source = %i, dest = %i, " 324 pr_debug("ALSA: seq: type = %i, source = %i, dest = %i, "
325 "client = %i\n", 325 "client = %i\n",
326 cell->event.type, 326 cell->event.type,
327 cell->event.source.client, 327 cell->event.source.client,
diff --git a/sound/core/seq/seq_queue.c b/sound/core/seq/seq_queue.c
index f9077361c119..aad4878cee55 100644
--- a/sound/core/seq/seq_queue.c
+++ b/sound/core/seq/seq_queue.c
@@ -112,7 +112,7 @@ static struct snd_seq_queue *queue_new(int owner, int locked)
112 112
113 q = kzalloc(sizeof(*q), GFP_KERNEL); 113 q = kzalloc(sizeof(*q), GFP_KERNEL);
114 if (q == NULL) { 114 if (q == NULL) {
115 snd_printd("malloc failed for snd_seq_queue_new()\n"); 115 pr_debug("ALSA: seq: malloc failed for snd_seq_queue_new()\n");
116 return NULL; 116 return NULL;
117 } 117 }
118 118
diff --git a/sound/core/seq/seq_timer.c b/sound/core/seq/seq_timer.c
index 24d44b2f61ac..e73605393eee 100644
--- a/sound/core/seq/seq_timer.c
+++ b/sound/core/seq/seq_timer.c
@@ -57,7 +57,7 @@ struct snd_seq_timer *snd_seq_timer_new(void)
57 57
58 tmr = kzalloc(sizeof(*tmr), GFP_KERNEL); 58 tmr = kzalloc(sizeof(*tmr), GFP_KERNEL);
59 if (tmr == NULL) { 59 if (tmr == NULL) {
60 snd_printd("malloc failed for snd_seq_timer_new() \n"); 60 pr_debug("ALSA: seq: malloc failed for snd_seq_timer_new() \n");
61 return NULL; 61 return NULL;
62 } 62 }
63 spin_lock_init(&tmr->lock); 63 spin_lock_init(&tmr->lock);
@@ -78,7 +78,7 @@ void snd_seq_timer_delete(struct snd_seq_timer **tmr)
78 *tmr = NULL; 78 *tmr = NULL;
79 79
80 if (t == NULL) { 80 if (t == NULL) {
81 snd_printd("oops: snd_seq_timer_delete() called with NULL timer\n"); 81 pr_debug("ALSA: seq: snd_seq_timer_delete() called with NULL timer\n");
82 return; 82 return;
83 } 83 }
84 t->running = 0; 84 t->running = 0;
@@ -199,7 +199,7 @@ int snd_seq_timer_set_ppq(struct snd_seq_timer * tmr, int ppq)
199 /* refuse to change ppq on running timers */ 199 /* refuse to change ppq on running timers */
200 /* because it will upset the song position (ticks) */ 200 /* because it will upset the song position (ticks) */
201 spin_unlock_irqrestore(&tmr->lock, flags); 201 spin_unlock_irqrestore(&tmr->lock, flags);
202 snd_printd("seq: cannot change ppq of a running timer\n"); 202 pr_debug("ALSA: seq: cannot change ppq of a running timer\n");
203 return -EBUSY; 203 return -EBUSY;
204 } 204 }
205 205
@@ -252,7 +252,7 @@ int snd_seq_timer_set_skew(struct snd_seq_timer *tmr, unsigned int skew,
252 252
253 /* FIXME */ 253 /* FIXME */
254 if (base != SKEW_BASE) { 254 if (base != SKEW_BASE) {
255 snd_printd("invalid skew base 0x%x\n", base); 255 pr_debug("ALSA: seq: invalid skew base 0x%x\n", base);
256 return -EINVAL; 256 return -EINVAL;
257 } 257 }
258 spin_lock_irqsave(&tmr->lock, flags); 258 spin_lock_irqsave(&tmr->lock, flags);
@@ -292,7 +292,7 @@ int snd_seq_timer_open(struct snd_seq_queue *q)
292 } 292 }
293 } 293 }
294 if (err < 0) { 294 if (err < 0) {
295 snd_printk(KERN_ERR "seq fatal error: cannot create timer (%i)\n", err); 295 pr_err("ALSA: seq fatal error: cannot create timer (%i)\n", err);
296 return err; 296 return err;
297 } 297 }
298 t->callback = snd_seq_timer_interrupt; 298 t->callback = snd_seq_timer_interrupt;
diff --git a/sound/core/seq/seq_virmidi.c b/sound/core/seq/seq_virmidi.c
index 4b50e604276d..56e0f4cd3f82 100644
--- a/sound/core/seq/seq_virmidi.c
+++ b/sound/core/seq/seq_virmidi.c
@@ -446,7 +446,7 @@ static int snd_virmidi_dev_register(struct snd_rawmidi *rmidi)
446 /* should check presence of port more strictly.. */ 446 /* should check presence of port more strictly.. */
447 break; 447 break;
448 default: 448 default:
449 snd_printk(KERN_ERR "seq_mode is not set: %d\n", rdev->seq_mode); 449 pr_err("ALSA: seq_virmidi: seq_mode is not set: %d\n", rdev->seq_mode);
450 return -EINVAL; 450 return -EINVAL;
451 } 451 }
452 return 0; 452 return 0;
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 437c25ea6403..38ad1a0dd3f7 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -118,7 +118,7 @@ void *snd_lookup_minor_data(unsigned int minor, int type)
118 if (mreg && mreg->type == type) { 118 if (mreg && mreg->type == type) {
119 private_data = mreg->private_data; 119 private_data = mreg->private_data;
120 if (private_data && mreg->card_ptr) 120 if (private_data && mreg->card_ptr)
121 atomic_inc(&mreg->card_ptr->refcount); 121 get_device(&mreg->card_ptr->card_dev);
122 } else 122 } else
123 private_data = NULL; 123 private_data = NULL;
124 mutex_unlock(&sound_mutex); 124 mutex_unlock(&sound_mutex);
@@ -355,22 +355,25 @@ int snd_unregister_device(int type, struct snd_card *card, int dev)
355 355
356EXPORT_SYMBOL(snd_unregister_device); 356EXPORT_SYMBOL(snd_unregister_device);
357 357
358int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev, 358/* get the assigned device to the given type and device number;
359 struct device_attribute *attr) 359 * the caller needs to release it via put_device() after using it
360 */
361struct device *snd_get_device(int type, struct snd_card *card, int dev)
360{ 362{
361 int minor, ret = -EINVAL; 363 int minor;
362 struct device *d; 364 struct device *d = NULL;
363 365
364 mutex_lock(&sound_mutex); 366 mutex_lock(&sound_mutex);
365 minor = find_snd_minor(type, card, dev); 367 minor = find_snd_minor(type, card, dev);
366 if (minor >= 0 && (d = snd_minors[minor]->dev) != NULL) 368 if (minor >= 0) {
367 ret = device_create_file(d, attr); 369 d = snd_minors[minor]->dev;
370 if (d)
371 get_device(d);
372 }
368 mutex_unlock(&sound_mutex); 373 mutex_unlock(&sound_mutex);
369 return ret; 374 return d;
370
371} 375}
372 376EXPORT_SYMBOL(snd_get_device);
373EXPORT_SYMBOL(snd_add_device_sysfs_file);
374 377
375#ifdef CONFIG_PROC_FS 378#ifdef CONFIG_PROC_FS
376/* 379/*
@@ -458,7 +461,7 @@ static int __init alsa_sound_init(void)
458 snd_major = major; 461 snd_major = major;
459 snd_ecards_limit = cards_limit; 462 snd_ecards_limit = cards_limit;
460 if (register_chrdev(major, "alsa", &snd_fops)) { 463 if (register_chrdev(major, "alsa", &snd_fops)) {
461 snd_printk(KERN_ERR "unable to register native major device number %d\n", major); 464 pr_err("ALSA core: unable to register native major device number %d\n", major);
462 return -EIO; 465 return -EIO;
463 } 466 }
464 if (snd_info_init() < 0) { 467 if (snd_info_init() < 0) {
@@ -467,7 +470,7 @@ static int __init alsa_sound_init(void)
467 } 470 }
468 snd_info_minor_register(); 471 snd_info_minor_register();
469#ifndef MODULE 472#ifndef MODULE
470 printk(KERN_INFO "Advanced Linux Sound Architecture Driver Initialized.\n"); 473 pr_info("Advanced Linux Sound Architecture Driver Initialized.\n");
471#endif 474#endif
472 return 0; 475 return 0;
473} 476}
diff --git a/sound/core/sound_oss.c b/sound/core/sound_oss.c
index 726a49ac9725..573a65eb2b79 100644
--- a/sound/core/sound_oss.c
+++ b/sound/core/sound_oss.c
@@ -21,7 +21,7 @@
21 21
22#ifdef CONFIG_SND_OSSEMUL 22#ifdef CONFIG_SND_OSSEMUL
23 23
24#if !defined(CONFIG_SOUND) && !(defined(MODULE) && defined(CONFIG_SOUND_MODULE)) 24#if !IS_ENABLED(CONFIG_SOUND)
25#error "Enable the OSS soundcore multiplexer (CONFIG_SOUND) in the kernel." 25#error "Enable the OSS soundcore multiplexer (CONFIG_SOUND) in the kernel."
26#endif 26#endif
27 27
@@ -55,7 +55,7 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type)
55 if (mreg && mreg->type == type) { 55 if (mreg && mreg->type == type) {
56 private_data = mreg->private_data; 56 private_data = mreg->private_data;
57 if (private_data && mreg->card_ptr) 57 if (private_data && mreg->card_ptr)
58 atomic_inc(&mreg->card_ptr->refcount); 58 get_device(&mreg->card_ptr->card_dev);
59 } else 59 } else
60 private_data = NULL; 60 private_data = NULL;
61 mutex_unlock(&sound_oss_mutex); 61 mutex_unlock(&sound_oss_mutex);
@@ -105,8 +105,7 @@ static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev)
105} 105}
106 106
107int snd_register_oss_device(int type, struct snd_card *card, int dev, 107int snd_register_oss_device(int type, struct snd_card *card, int dev,
108 const struct file_operations *f_ops, void *private_data, 108 const struct file_operations *f_ops, void *private_data)
109 const char *name)
110{ 109{
111 int minor = snd_oss_kernel_minor(type, card, dev); 110 int minor = snd_oss_kernel_minor(type, card, dev);
112 int minor_unit; 111 int minor_unit;
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 6ddcf06f52f9..cfd455a8ac1a 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -35,9 +35,9 @@
35#include <sound/initval.h> 35#include <sound/initval.h>
36#include <linux/kmod.h> 36#include <linux/kmod.h>
37 37
38#if defined(CONFIG_SND_HRTIMER) || defined(CONFIG_SND_HRTIMER_MODULE) 38#if IS_ENABLED(CONFIG_SND_HRTIMER)
39#define DEFAULT_TIMER_LIMIT 4 39#define DEFAULT_TIMER_LIMIT 4
40#elif defined(CONFIG_SND_RTCTIMER) || defined(CONFIG_SND_RTCTIMER_MODULE) 40#elif IS_ENABLED(CONFIG_SND_RTCTIMER)
41#define DEFAULT_TIMER_LIMIT 2 41#define DEFAULT_TIMER_LIMIT 2
42#else 42#else
43#define DEFAULT_TIMER_LIMIT 1 43#define DEFAULT_TIMER_LIMIT 1
@@ -240,7 +240,8 @@ int snd_timer_open(struct snd_timer_instance **ti,
240 /* open a slave instance */ 240 /* open a slave instance */
241 if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE || 241 if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE ||
242 tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) { 242 tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) {
243 snd_printd("invalid slave class %i\n", tid->dev_sclass); 243 pr_debug("ALSA: timer: invalid slave class %i\n",
244 tid->dev_sclass);
244 return -EINVAL; 245 return -EINVAL;
245 } 246 }
246 mutex_lock(&register_mutex); 247 mutex_lock(&register_mutex);
@@ -774,7 +775,7 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
774 *rtimer = NULL; 775 *rtimer = NULL;
775 timer = kzalloc(sizeof(*timer), GFP_KERNEL); 776 timer = kzalloc(sizeof(*timer), GFP_KERNEL);
776 if (timer == NULL) { 777 if (timer == NULL) {
777 snd_printk(KERN_ERR "timer: cannot allocate\n"); 778 pr_err("ALSA: timer: cannot allocate\n");
778 return -ENOMEM; 779 return -ENOMEM;
779 } 780 }
780 timer->tmr_class = tid->dev_class; 781 timer->tmr_class = tid->dev_class;
@@ -813,7 +814,7 @@ static int snd_timer_free(struct snd_timer *timer)
813 if (! list_empty(&timer->open_list_head)) { 814 if (! list_empty(&timer->open_list_head)) {
814 struct list_head *p, *n; 815 struct list_head *p, *n;
815 struct snd_timer_instance *ti; 816 struct snd_timer_instance *ti;
816 snd_printk(KERN_WARNING "timer %p is busy?\n", timer); 817 pr_warn("ALSA: timer %p is busy?\n", timer);
817 list_for_each_safe(p, n, &timer->open_list_head) { 818 list_for_each_safe(p, n, &timer->open_list_head) {
818 list_del_init(p); 819 list_del_init(p);
819 ti = list_entry(p, struct snd_timer_instance, open_list); 820 ti = list_entry(p, struct snd_timer_instance, open_list);
@@ -1955,12 +1956,10 @@ static int __init alsa_timer_init(void)
1955#endif 1956#endif
1956 1957
1957 if ((err = snd_timer_register_system()) < 0) 1958 if ((err = snd_timer_register_system()) < 0)
1958 snd_printk(KERN_ERR "unable to register system timer (%i)\n", 1959 pr_err("ALSA: unable to register system timer (%i)\n", err);
1959 err);
1960 if ((err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0, 1960 if ((err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0,
1961 &snd_timer_f_ops, NULL, "timer")) < 0) 1961 &snd_timer_f_ops, NULL, "timer")) < 0)
1962 snd_printk(KERN_ERR "unable to register timer device (%i)\n", 1962 pr_err("ALSA: unable to register timer device (%i)\n", err);
1963 err);
1964 snd_timer_proc_init(); 1963 snd_timer_proc_init();
1965 return 0; 1964 return 0;
1966} 1965}
diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c
index 842a97d5fc3a..6c58e6f73a01 100644
--- a/sound/core/vmaster.c
+++ b/sound/core/vmaster.c
@@ -101,7 +101,7 @@ static int slave_init(struct link_slave *slave)
101 if (slave->info.count > 2 || 101 if (slave->info.count > 2 ||
102 (slave->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER && 102 (slave->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER &&
103 slave->info.type != SNDRV_CTL_ELEM_TYPE_BOOLEAN)) { 103 slave->info.type != SNDRV_CTL_ELEM_TYPE_BOOLEAN)) {
104 snd_printk(KERN_ERR "invalid slave element\n"); 104 pr_err("ALSA: vmaster: invalid slave element\n");
105 kfree(uinfo); 105 kfree(uinfo);
106 return -EINVAL; 106 return -EINVAL;
107 } 107 }
diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c
index f7589923effa..2a16c86a60b3 100644
--- a/sound/drivers/aloop.c
+++ b/sound/drivers/aloop.c
@@ -1142,8 +1142,8 @@ static int loopback_probe(struct platform_device *devptr)
1142 int dev = devptr->id; 1142 int dev = devptr->id;
1143 int err; 1143 int err;
1144 1144
1145 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 1145 err = snd_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE,
1146 sizeof(struct loopback), &card); 1146 sizeof(struct loopback), &card);
1147 if (err < 0) 1147 if (err < 0)
1148 return err; 1148 return err;
1149 loopback = card->private_data; 1149 loopback = card->private_data;
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index 915b4d7fbb23..fab90bd2bd51 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -1054,8 +1054,8 @@ static int snd_dummy_probe(struct platform_device *devptr)
1054 int idx, err; 1054 int idx, err;
1055 int dev = devptr->id; 1055 int dev = devptr->id;
1056 1056
1057 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 1057 err = snd_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE,
1058 sizeof(struct snd_dummy), &card); 1058 sizeof(struct snd_dummy), &card);
1059 if (err < 0) 1059 if (err < 0)
1060 return err; 1060 return err;
1061 dummy = card->private_data; 1061 dummy = card->private_data;
@@ -1114,8 +1114,6 @@ static int snd_dummy_probe(struct platform_device *devptr)
1114 1114
1115 dummy_proc_init(dummy); 1115 dummy_proc_init(dummy);
1116 1116
1117 snd_card_set_dev(card, &devptr->dev);
1118
1119 err = snd_card_register(card); 1117 err = snd_card_register(card);
1120 if (err == 0) { 1118 if (err == 0) {
1121 platform_set_drvdata(devptr, card); 1119 platform_set_drvdata(devptr, card);
diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c
index 95ea4a153ea4..33ed76530d0b 100644
--- a/sound/drivers/ml403-ac97cr.c
+++ b/sound/drivers/ml403-ac97cr.c
@@ -1280,7 +1280,8 @@ static int snd_ml403_ac97cr_probe(struct platform_device *pfdev)
1280 if (!enable[dev]) 1280 if (!enable[dev])
1281 return -ENOENT; 1281 return -ENOENT;
1282 1282
1283 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1283 err = snd_card_new(&pfdev->dev, index[dev], id[dev], THIS_MODULE,
1284 0, &card);
1284 if (err < 0) 1285 if (err < 0)
1285 return err; 1286 return err;
1286 err = snd_ml403_ac97cr_create(card, pfdev, &ml403_ac97cr); 1287 err = snd_ml403_ac97cr_create(card, pfdev, &ml403_ac97cr);
@@ -1310,8 +1311,6 @@ static int snd_ml403_ac97cr_probe(struct platform_device *pfdev)
1310 (unsigned long)ml403_ac97cr->port, ml403_ac97cr->irq, 1311 (unsigned long)ml403_ac97cr->port, ml403_ac97cr->irq,
1311 ml403_ac97cr->capture_irq, dev + 1); 1312 ml403_ac97cr->capture_irq, dev + 1);
1312 1313
1313 snd_card_set_dev(card, &pfdev->dev);
1314
1315 err = snd_card_register(card); 1314 err = snd_card_register(card);
1316 if (err < 0) { 1315 if (err < 0) {
1317 snd_card_free(card); 1316 snd_card_free(card);
diff --git a/sound/drivers/mpu401/mpu401.c b/sound/drivers/mpu401/mpu401.c
index 90a3a7b38a2a..83014b83a44e 100644
--- a/sound/drivers/mpu401/mpu401.c
+++ b/sound/drivers/mpu401/mpu401.c
@@ -64,7 +64,8 @@ static struct platform_device *platform_devices[SNDRV_CARDS];
64static int pnp_registered; 64static int pnp_registered;
65static unsigned int snd_mpu401_devices; 65static unsigned int snd_mpu401_devices;
66 66
67static int snd_mpu401_create(int dev, struct snd_card **rcard) 67static int snd_mpu401_create(struct device *devptr, int dev,
68 struct snd_card **rcard)
68{ 69{
69 struct snd_card *card; 70 struct snd_card *card;
70 int err; 71 int err;
@@ -73,7 +74,8 @@ 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"); 74 snd_printk(KERN_ERR "the uart_enter option is obsolete; remove it\n");
74 75
75 *rcard = NULL; 76 *rcard = NULL;
76 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 77 err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
78 0, &card);
77 if (err < 0) 79 if (err < 0)
78 return err; 80 return err;
79 strcpy(card->driver, "MPU-401 UART"); 81 strcpy(card->driver, "MPU-401 UART");
@@ -114,10 +116,9 @@ static int snd_mpu401_probe(struct platform_device *devptr)
114 snd_printk(KERN_ERR "specify or disable IRQ\n"); 116 snd_printk(KERN_ERR "specify or disable IRQ\n");
115 return -EINVAL; 117 return -EINVAL;
116 } 118 }
117 err = snd_mpu401_create(dev, &card); 119 err = snd_mpu401_create(&devptr->dev, dev, &card);
118 if (err < 0) 120 if (err < 0)
119 return err; 121 return err;
120 snd_card_set_dev(card, &devptr->dev);
121 if ((err = snd_card_register(card)) < 0) { 122 if ((err = snd_card_register(card)) < 0) {
122 snd_card_free(card); 123 snd_card_free(card);
123 return err; 124 return err;
@@ -194,14 +195,13 @@ static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
194 err = snd_mpu401_pnp(dev, pnp_dev, id); 195 err = snd_mpu401_pnp(dev, pnp_dev, id);
195 if (err < 0) 196 if (err < 0)
196 return err; 197 return err;
197 err = snd_mpu401_create(dev, &card); 198 err = snd_mpu401_create(&pnp_dev->dev, dev, &card);
198 if (err < 0) 199 if (err < 0)
199 return err; 200 return err;
200 if ((err = snd_card_register(card)) < 0) { 201 if ((err = snd_card_register(card)) < 0) {
201 snd_card_free(card); 202 snd_card_free(card);
202 return err; 203 return err;
203 } 204 }
204 snd_card_set_dev(card, &pnp_dev->dev);
205 pnp_set_drvdata(pnp_dev, card); 205 pnp_set_drvdata(pnp_dev, card);
206 snd_mpu401_devices++; 206 snd_mpu401_devices++;
207 ++dev; 207 ++dev;
diff --git a/sound/drivers/mtpav.c b/sound/drivers/mtpav.c
index e5ec7eb27dec..4b66c7f22af7 100644
--- a/sound/drivers/mtpav.c
+++ b/sound/drivers/mtpav.c
@@ -697,7 +697,8 @@ static int snd_mtpav_probe(struct platform_device *dev)
697 int err; 697 int err;
698 struct mtpav *mtp_card; 698 struct mtpav *mtp_card;
699 699
700 err = snd_card_create(index, id, THIS_MODULE, sizeof(*mtp_card), &card); 700 err = snd_card_new(&dev->dev, index, id, THIS_MODULE,
701 sizeof(*mtp_card), &card);
701 if (err < 0) 702 if (err < 0)
702 return err; 703 return err;
703 704
@@ -732,7 +733,6 @@ static int snd_mtpav_probe(struct platform_device *dev)
732 733
733 snd_mtpav_portscan(mtp_card); 734 snd_mtpav_portscan(mtp_card);
734 735
735 snd_card_set_dev(card, &dev->dev);
736 err = snd_card_register(mtp_card->card); 736 err = snd_card_register(mtp_card->card);
737 if (err < 0) 737 if (err < 0)
738 goto __error; 738 goto __error;
diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
index 4e0dd22ba08e..f5fd448dbc57 100644
--- a/sound/drivers/mts64.c
+++ b/sound/drivers/mts64.c
@@ -959,7 +959,8 @@ static int snd_mts64_probe(struct platform_device *pdev)
959 if ((err = snd_mts64_probe_port(p)) < 0) 959 if ((err = snd_mts64_probe_port(p)) < 0)
960 return err; 960 return err;
961 961
962 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 962 err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE,
963 0, &card);
963 if (err < 0) { 964 if (err < 0) {
964 snd_printd("Cannot create card\n"); 965 snd_printd("Cannot create card\n");
965 return err; 966 return err;
@@ -1009,8 +1010,6 @@ static int snd_mts64_probe(struct platform_device *pdev)
1009 1010
1010 platform_set_drvdata(pdev, card); 1011 platform_set_drvdata(pdev, card);
1011 1012
1012 snd_card_set_dev(card, &pdev->dev);
1013
1014 /* At this point card will be usable */ 1013 /* At this point card will be usable */
1015 if ((err = snd_card_register(card)) < 0) { 1014 if ((err = snd_card_register(card)) < 0) {
1016 snd_printd("Cannot register card\n"); 1015 snd_printd("Cannot register card\n");
diff --git a/sound/drivers/opl3/opl3_lib.c b/sound/drivers/opl3/opl3_lib.c
index 33d9a857a262..f66af5884c40 100644
--- a/sound/drivers/opl3/opl3_lib.c
+++ b/sound/drivers/opl3/opl3_lib.c
@@ -501,10 +501,8 @@ int snd_opl3_hwdep_new(struct snd_opl3 * opl3,
501 hw->private_data = opl3; 501 hw->private_data = opl3;
502 hw->exclusive = 1; 502 hw->exclusive = 1;
503#ifdef CONFIG_SND_OSSEMUL 503#ifdef CONFIG_SND_OSSEMUL
504 if (device == 0) { 504 if (device == 0)
505 hw->oss_type = SNDRV_OSS_DEVICE_TYPE_DMFM; 505 hw->oss_type = SNDRV_OSS_DEVICE_TYPE_DMFM;
506 sprintf(hw->oss_dev, "dmfm%i", card->number);
507 }
508#endif 506#endif
509 strcpy(hw->name, hw->id); 507 strcpy(hw->name, hw->id);
510 switch (opl3->hardware & OPL3_HW_MASK) { 508 switch (opl3->hardware & OPL3_HW_MASK) {
diff --git a/sound/drivers/opl3/opl3_synth.c b/sound/drivers/opl3/opl3_synth.c
index 742a4b642fd9..ddcc1a325a61 100644
--- a/sound/drivers/opl3/opl3_synth.c
+++ b/sound/drivers/opl3/opl3_synth.c
@@ -24,7 +24,7 @@
24#include <sound/opl3.h> 24#include <sound/opl3.h>
25#include <sound/asound_fm.h> 25#include <sound/asound_fm.h>
26 26
27#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE) 27#if IS_ENABLED(CONFIG_SND_SEQUENCER)
28#define OPL3_SUPPORT_SYNTH 28#define OPL3_SUPPORT_SYNTH
29#endif 29#endif
30 30
diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
index 328bd29264ce..36808cdab06f 100644
--- a/sound/drivers/pcsp/pcsp.c
+++ b/sound/drivers/pcsp/pcsp.c
@@ -105,7 +105,7 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev)
105 hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 105 hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
106 pcsp_chip.timer.function = pcsp_do_timer; 106 pcsp_chip.timer.function = pcsp_do_timer;
107 107
108 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 108 err = snd_card_new(dev, index, id, THIS_MODULE, 0, &card);
109 if (err < 0) 109 if (err < 0)
110 return err; 110 return err;
111 111
@@ -127,8 +127,6 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev)
127 return err; 127 return err;
128 } 128 }
129 129
130 snd_card_set_dev(pcsp_chip.card, dev);
131
132 strcpy(card->driver, "PC-Speaker"); 130 strcpy(card->driver, "PC-Speaker");
133 strcpy(card->shortname, "pcsp"); 131 strcpy(card->shortname, "pcsp");
134 sprintf(card->longname, "Internal PC-Speaker at port 0x%x", 132 sprintf(card->longname, "Internal PC-Speaker at port 0x%x",
diff --git a/sound/drivers/pcsp/pcsp_input.c b/sound/drivers/pcsp/pcsp_input.c
index b874b0ad99cd..0ecf8a453e01 100644
--- a/sound/drivers/pcsp/pcsp_input.c
+++ b/sound/drivers/pcsp/pcsp_input.c
@@ -16,6 +16,7 @@
16#include <linux/input.h> 16#include <linux/input.h>
17#include <asm/io.h> 17#include <asm/io.h>
18#include "pcsp.h" 18#include "pcsp.h"
19#include "pcsp_input.h"
19 20
20static void pcspkr_do_sound(unsigned int count) 21static void pcspkr_do_sound(unsigned int count)
21{ 22{
diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
index 991018df7131..78ccfa455527 100644
--- a/sound/drivers/portman2x4.c
+++ b/sound/drivers/portman2x4.c
@@ -748,7 +748,8 @@ static int snd_portman_probe(struct platform_device *pdev)
748 if ((err = snd_portman_probe_port(p)) < 0) 748 if ((err = snd_portman_probe_port(p)) < 0)
749 return err; 749 return err;
750 750
751 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 751 err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE,
752 0, &card);
752 if (err < 0) { 753 if (err < 0) {
753 snd_printd("Cannot create card\n"); 754 snd_printd("Cannot create card\n");
754 return err; 755 return err;
@@ -798,8 +799,6 @@ static int snd_portman_probe(struct platform_device *pdev)
798 799
799 platform_set_drvdata(pdev, card); 800 platform_set_drvdata(pdev, card);
800 801
801 snd_card_set_dev(card, &pdev->dev);
802
803 /* At this point card will be usable */ 802 /* At this point card will be usable */
804 if ((err = snd_card_register(card)) < 0) { 803 if ((err = snd_card_register(card)) < 0) {
805 snd_printd("Cannot register card\n"); 804 snd_printd("Cannot register card\n");
diff --git a/sound/drivers/serial-u16550.c b/sound/drivers/serial-u16550.c
index e0bf5e77b43a..9ad4414fa25c 100644
--- a/sound/drivers/serial-u16550.c
+++ b/sound/drivers/serial-u16550.c
@@ -942,7 +942,8 @@ static int snd_serial_probe(struct platform_device *devptr)
942 return -ENODEV; 942 return -ENODEV;
943 } 943 }
944 944
945 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 945 err = snd_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE,
946 0, &card);
946 if (err < 0) 947 if (err < 0)
947 return err; 948 return err;
948 949
@@ -969,8 +970,6 @@ static int snd_serial_probe(struct platform_device *devptr)
969 uart->base, 970 uart->base,
970 uart->irq); 971 uart->irq);
971 972
972 snd_card_set_dev(card, &devptr->dev);
973
974 if ((err = snd_card_register(card)) < 0) 973 if ((err = snd_card_register(card)) < 0)
975 goto _err; 974 goto _err;
976 975
diff --git a/sound/drivers/virmidi.c b/sound/drivers/virmidi.c
index ace3879e8d96..b178724295f3 100644
--- a/sound/drivers/virmidi.c
+++ b/sound/drivers/virmidi.c
@@ -90,8 +90,8 @@ static int 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 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 93 err = snd_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE,
94 sizeof(struct snd_card_virmidi), &card); 94 sizeof(struct snd_card_virmidi), &card);
95 if (err < 0) 95 if (err < 0)
96 return err; 96 return err;
97 vmidi = card->private_data; 97 vmidi = card->private_data;
@@ -118,8 +118,6 @@ static int snd_virmidi_probe(struct platform_device *devptr)
118 strcpy(card->shortname, "VirMIDI"); 118 strcpy(card->shortname, "VirMIDI");
119 sprintf(card->longname, "Virtual MIDI Card %i", dev + 1); 119 sprintf(card->longname, "Virtual MIDI Card %i", dev + 1);
120 120
121 snd_card_set_dev(card, &devptr->dev);
122
123 if ((err = snd_card_register(card)) == 0) { 121 if ((err = snd_card_register(card)) == 0) {
124 platform_set_drvdata(devptr, card); 122 platform_set_drvdata(devptr, card);
125 return 0; 123 return 0;
diff --git a/sound/firewire/dice.c b/sound/firewire/dice.c
index c0aa64941cee..0c3948630cf7 100644
--- a/sound/firewire/dice.c
+++ b/sound/firewire/dice.c
@@ -1326,10 +1326,10 @@ static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
1326 if (err < 0) 1326 if (err < 0)
1327 return err; 1327 return err;
1328 1328
1329 err = snd_card_create(-1, NULL, THIS_MODULE, sizeof(*dice), &card); 1329 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
1330 sizeof(*dice), &card);
1330 if (err < 0) 1331 if (err < 0)
1331 return err; 1332 return err;
1332 snd_card_set_dev(card, &unit->device);
1333 1333
1334 dice = card->private_data; 1334 dice = card->private_data;
1335 dice->card = card; 1335 dice->card = card;
diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
index fd42e6b315e6..7ac94439e758 100644
--- a/sound/firewire/isight.c
+++ b/sound/firewire/isight.c
@@ -631,10 +631,10 @@ static int isight_probe(struct fw_unit *unit,
631 struct isight *isight; 631 struct isight *isight;
632 int err; 632 int err;
633 633
634 err = snd_card_create(-1, NULL, THIS_MODULE, sizeof(*isight), &card); 634 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
635 sizeof(*isight), &card);
635 if (err < 0) 636 if (err < 0)
636 return err; 637 return err;
637 snd_card_set_dev(card, &unit->device);
638 638
639 isight = card->private_data; 639 isight = card->private_data;
640 isight->card = card; 640 isight->card = card;
diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
index 858023cf4298..2dba848a781f 100644
--- a/sound/firewire/scs1x.c
+++ b/sound/firewire/scs1x.c
@@ -391,10 +391,10 @@ static int scs_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
391 struct scs *scs; 391 struct scs *scs;
392 int err; 392 int err;
393 393
394 err = snd_card_create(-16, NULL, THIS_MODULE, sizeof(*scs), &card); 394 err = snd_card_new(&unit->device, -16, NULL, THIS_MODULE,
395 sizeof(*scs), &card);
395 if (err < 0) 396 if (err < 0)
396 return err; 397 return err;
397 snd_card_set_dev(card, &unit->device);
398 398
399 scs = card->private_data; 399 scs = card->private_data;
400 scs->card = card; 400 scs->card = card;
diff --git a/sound/firewire/speakers.c b/sound/firewire/speakers.c
index cc8bc3a51bc1..9f7ef219b109 100644
--- a/sound/firewire/speakers.c
+++ b/sound/firewire/speakers.c
@@ -668,10 +668,10 @@ static int fwspk_probe(struct fw_unit *unit,
668 u32 firmware; 668 u32 firmware;
669 int err; 669 int err;
670 670
671 err = snd_card_create(-1, NULL, THIS_MODULE, sizeof(*fwspk), &card); 671 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
672 sizeof(*fwspk), &card);
672 if (err < 0) 673 if (err < 0)
673 return err; 674 return err;
674 snd_card_set_dev(card, &unit->device);
675 675
676 fwspk = card->private_data; 676 fwspk = card->private_data;
677 fwspk->card = card; 677 fwspk->card = card;
diff --git a/sound/i2c/other/ak4113.c b/sound/i2c/other/ak4113.c
index e04e750a77ed..1a3a6fa27158 100644
--- a/sound/i2c/other/ak4113.c
+++ b/sound/i2c/other/ak4113.c
@@ -98,7 +98,7 @@ int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read,
98 AK4113_CINT | AK4113_STC); 98 AK4113_CINT | AK4113_STC);
99 chip->rcs1 = reg_read(chip, AK4113_REG_RCS1); 99 chip->rcs1 = reg_read(chip, AK4113_REG_RCS1);
100 chip->rcs2 = reg_read(chip, AK4113_REG_RCS2); 100 chip->rcs2 = reg_read(chip, AK4113_REG_RCS2);
101 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 101 err = snd_device_new(card, SNDRV_DEV_CODEC, chip, &ops);
102 if (err < 0) 102 if (err < 0)
103 goto __fail; 103 goto __fail;
104 104
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c
index 15ae0250eace..c7f56339415d 100644
--- a/sound/i2c/other/ak4114.c
+++ b/sound/i2c/other/ak4114.c
@@ -111,7 +111,7 @@ int snd_ak4114_create(struct snd_card *card,
111 chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT); 111 chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT);
112 chip->rcs1 = reg_read(chip, AK4114_REG_RCS1); 112 chip->rcs1 = reg_read(chip, AK4114_REG_RCS1);
113 113
114 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) 114 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, chip, &ops)) < 0)
115 goto __fail; 115 goto __fail;
116 116
117 if (r_ak4114) 117 if (r_ak4114)
diff --git a/sound/i2c/other/ak4117.c b/sound/i2c/other/ak4117.c
index 40e33c9f2b09..88452e899bd9 100644
--- a/sound/i2c/other/ak4117.c
+++ b/sound/i2c/other/ak4117.c
@@ -62,7 +62,7 @@ static void reg_dump(struct ak4117 *ak4117)
62 62
63static void snd_ak4117_free(struct ak4117 *chip) 63static void snd_ak4117_free(struct ak4117 *chip)
64{ 64{
65 del_timer(&chip->timer); 65 del_timer_sync(&chip->timer);
66 kfree(chip); 66 kfree(chip);
67} 67}
68 68
diff --git a/sound/isa/ad1816a/ad1816a.c b/sound/isa/ad1816a/ad1816a.c
index 26ce26a5884d..f481a41e027e 100644
--- a/sound/isa/ad1816a/ad1816a.c
+++ b/sound/isa/ad1816a/ad1816a.c
@@ -144,8 +144,9 @@ static int snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
144 struct snd_opl3 *opl3; 144 struct snd_opl3 *opl3;
145 struct snd_timer *timer; 145 struct snd_timer *timer;
146 146
147 error = snd_card_create(index[dev], id[dev], THIS_MODULE, 147 error = snd_card_new(&pcard->card->dev,
148 sizeof(struct snd_ad1816a), &card); 148 index[dev], id[dev], THIS_MODULE,
149 sizeof(struct snd_ad1816a), &card);
149 if (error < 0) 150 if (error < 0)
150 return error; 151 return error;
151 chip = card->private_data; 152 chip = card->private_data;
@@ -154,7 +155,6 @@ static int snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
154 snd_card_free(card); 155 snd_card_free(card);
155 return error; 156 return error;
156 } 157 }
157 snd_card_set_dev(card, &pcard->card->dev);
158 158
159 if ((error = snd_ad1816a_create(card, port[dev], 159 if ((error = snd_ad1816a_create(card, port[dev],
160 irq[dev], 160 irq[dev],
diff --git a/sound/isa/ad1848/ad1848.c b/sound/isa/ad1848/ad1848.c
index e3f455bd85cd..093f22a464d7 100644
--- a/sound/isa/ad1848/ad1848.c
+++ b/sound/isa/ad1848/ad1848.c
@@ -91,7 +91,7 @@ static int 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 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card); 94 error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
95 if (error < 0) 95 if (error < 0)
96 return error; 96 return error;
97 97
@@ -119,8 +119,6 @@ static int snd_ad1848_probe(struct device *dev, unsigned int n)
119 if (thinkpad[n]) 119 if (thinkpad[n])
120 strcat(card->longname, " [Thinkpad]"); 120 strcat(card->longname, " [Thinkpad]");
121 121
122 snd_card_set_dev(card, dev);
123
124 error = snd_card_register(card); 122 error = snd_card_register(card);
125 if (error < 0) 123 if (error < 0)
126 goto out; 124 goto out;
diff --git a/sound/isa/adlib.c b/sound/isa/adlib.c
index 35659218710f..120c524bb2a0 100644
--- a/sound/isa/adlib.c
+++ b/sound/isa/adlib.c
@@ -53,7 +53,7 @@ static int 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 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card); 56 error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
57 if (error < 0) { 57 if (error < 0) {
58 dev_err(dev, "could not create card\n"); 58 dev_err(dev, "could not create card\n");
59 return error; 59 return error;
@@ -83,8 +83,6 @@ static int snd_adlib_probe(struct device *dev, unsigned int n)
83 goto out; 83 goto out;
84 } 84 }
85 85
86 snd_card_set_dev(card, dev);
87
88 error = snd_card_register(card); 86 error = snd_card_register(card);
89 if (error < 0) { 87 if (error < 0) {
90 dev_err(dev, "could not register card\n"); 88 dev_err(dev, "could not register card\n");
diff --git a/sound/isa/als100.c b/sound/isa/als100.c
index 10f08a18fe3b..32d01525211d 100644
--- a/sound/isa/als100.c
+++ b/sound/isa/als100.c
@@ -193,8 +193,9 @@ static int snd_card_als100_probe(int dev,
193 struct snd_card_als100 *acard; 193 struct snd_card_als100 *acard;
194 struct snd_opl3 *opl3; 194 struct snd_opl3 *opl3;
195 195
196 error = snd_card_create(index[dev], id[dev], THIS_MODULE, 196 error = snd_card_new(&pcard->card->dev,
197 sizeof(struct snd_card_als100), &card); 197 index[dev], id[dev], THIS_MODULE,
198 sizeof(struct snd_card_als100), &card);
198 if (error < 0) 199 if (error < 0)
199 return error; 200 return error;
200 acard = card->private_data; 201 acard = card->private_data;
@@ -203,7 +204,6 @@ static int snd_card_als100_probe(int dev,
203 snd_card_free(card); 204 snd_card_free(card);
204 return error; 205 return error;
205 } 206 }
206 snd_card_set_dev(card, &pcard->card->dev);
207 207
208 if (pid->driver_data == SB_HW_DT019X) 208 if (pid->driver_data == SB_HW_DT019X)
209 dma16[dev] = -1; 209 dma16[dev] = -1;
diff --git a/sound/isa/azt2320.c b/sound/isa/azt2320.c
index db301ff94ec2..0ea75fc62072 100644
--- a/sound/isa/azt2320.c
+++ b/sound/isa/azt2320.c
@@ -184,8 +184,9 @@ static int 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 error = snd_card_create(index[dev], id[dev], THIS_MODULE, 187 error = snd_card_new(&pcard->card->dev,
188 sizeof(struct snd_card_azt2320), &card); 188 index[dev], id[dev], THIS_MODULE,
189 sizeof(struct snd_card_azt2320), &card);
189 if (error < 0) 190 if (error < 0)
190 return error; 191 return error;
191 acard = card->private_data; 192 acard = card->private_data;
@@ -194,7 +195,6 @@ static int snd_card_azt2320_probe(int dev,
194 snd_card_free(card); 195 snd_card_free(card);
195 return error; 196 return error;
196 } 197 }
197 snd_card_set_dev(card, &pcard->card->dev);
198 198
199 if ((error = snd_card_azt2320_enable_wss(port[dev]))) { 199 if ((error = snd_card_azt2320_enable_wss(port[dev]))) {
200 snd_card_free(card); 200 snd_card_free(card);
diff --git a/sound/isa/cmi8328.c b/sound/isa/cmi8328.c
index ab6b2dc043f1..4778852a1201 100644
--- a/sound/isa/cmi8328.c
+++ b/sound/isa/cmi8328.c
@@ -293,15 +293,14 @@ static int snd_cmi8328_probe(struct device *pdev, unsigned int ndev)
293 } 293 }
294 outb(val, port); 294 outb(val, port);
295 295
296 err = snd_card_create(index[ndev], id[ndev], THIS_MODULE, 296 err = snd_card_new(pdev, index[ndev], id[ndev], THIS_MODULE,
297 sizeof(struct snd_cmi8328), &card); 297 sizeof(struct snd_cmi8328), &card);
298 if (err < 0) 298 if (err < 0)
299 return err; 299 return err;
300 cmi = card->private_data; 300 cmi = card->private_data;
301 cmi->card = card; 301 cmi->card = card;
302 cmi->port = port; 302 cmi->port = port;
303 cmi->wss_cfg = val; 303 cmi->wss_cfg = val;
304 snd_card_set_dev(card, pdev);
305 304
306 err = snd_wss_create(card, port + 4, -1, irq[ndev], dma1[ndev], 305 err = snd_wss_create(card, port + 4, -1, irq[ndev], dma1[ndev],
307 dma2[ndev], WSS_HW_DETECT, 0, &cmi->wss); 306 dma2[ndev], WSS_HW_DETECT, 0, &cmi->wss);
diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
index 270b9659ef7f..dfedfd85f205 100644
--- a/sound/isa/cmi8330.c
+++ b/sound/isa/cmi8330.c
@@ -514,14 +514,15 @@ static int snd_cmi8330_resume(struct snd_card *card)
514 514
515#define PFX "cmi8330: " 515#define PFX "cmi8330: "
516 516
517static int snd_cmi8330_card_new(int dev, struct snd_card **cardp) 517static int snd_cmi8330_card_new(struct device *pdev, int dev,
518 struct snd_card **cardp)
518{ 519{
519 struct snd_card *card; 520 struct snd_card *card;
520 struct snd_cmi8330 *acard; 521 struct snd_cmi8330 *acard;
521 int err; 522 int err;
522 523
523 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 524 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
524 sizeof(struct snd_cmi8330), &card); 525 sizeof(struct snd_cmi8330), &card);
525 if (err < 0) { 526 if (err < 0) {
526 snd_printk(KERN_ERR PFX "could not get a new card\n"); 527 snd_printk(KERN_ERR PFX "could not get a new card\n");
527 return err; 528 return err;
@@ -635,10 +636,9 @@ static int snd_cmi8330_isa_probe(struct device *pdev,
635 struct snd_card *card; 636 struct snd_card *card;
636 int err; 637 int err;
637 638
638 err = snd_cmi8330_card_new(dev, &card); 639 err = snd_cmi8330_card_new(pdev, dev, &card);
639 if (err < 0) 640 if (err < 0)
640 return err; 641 return err;
641 snd_card_set_dev(card, pdev);
642 if ((err = snd_cmi8330_probe(card, dev)) < 0) { 642 if ((err = snd_cmi8330_probe(card, dev)) < 0) {
643 snd_card_free(card); 643 snd_card_free(card);
644 return err; 644 return err;
@@ -698,7 +698,7 @@ static int snd_cmi8330_pnp_detect(struct pnp_card_link *pcard,
698 if (dev >= SNDRV_CARDS) 698 if (dev >= SNDRV_CARDS)
699 return -ENODEV; 699 return -ENODEV;
700 700
701 res = snd_cmi8330_card_new(dev, &card); 701 res = snd_cmi8330_card_new(&pcard->card->dev, dev, &card);
702 if (res < 0) 702 if (res < 0)
703 return res; 703 return res;
704 if ((res = snd_cmi8330_pnp(dev, card->private_data, pcard, pid)) < 0) { 704 if ((res = snd_cmi8330_pnp(dev, card->private_data, pcard, pid)) < 0) {
@@ -706,7 +706,6 @@ static int snd_cmi8330_pnp_detect(struct pnp_card_link *pcard,
706 snd_card_free(card); 706 snd_card_free(card);
707 return res; 707 return res;
708 } 708 }
709 snd_card_set_dev(card, &pcard->card->dev);
710 if ((res = snd_cmi8330_probe(card, dev)) < 0) { 709 if ((res = snd_cmi8330_probe(card, dev)) < 0) {
711 snd_card_free(card); 710 snd_card_free(card);
712 return res; 711 return res;
diff --git a/sound/isa/cs423x/cs4231.c b/sound/isa/cs423x/cs4231.c
index ba9a74eff3e0..7dba07a4343a 100644
--- a/sound/isa/cs423x/cs4231.c
+++ b/sound/isa/cs423x/cs4231.c
@@ -95,7 +95,7 @@ static int 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 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card); 98 error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
99 if (error < 0) 99 if (error < 0)
100 return error; 100 return error;
101 101
@@ -135,8 +135,6 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n)
135 dev_warn(dev, "MPU401 not detected\n"); 135 dev_warn(dev, "MPU401 not detected\n");
136 } 136 }
137 137
138 snd_card_set_dev(card, dev);
139
140 error = snd_card_register(card); 138 error = snd_card_register(card);
141 if (error < 0) 139 if (error < 0)
142 goto out; 140 goto out;
diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c
index 69614acb2052..750f51c904fc 100644
--- a/sound/isa/cs423x/cs4236.c
+++ b/sound/isa/cs423x/cs4236.c
@@ -364,13 +364,14 @@ static void snd_card_cs4236_free(struct snd_card *card)
364 release_and_free_resource(acard->res_sb_port); 364 release_and_free_resource(acard->res_sb_port);
365} 365}
366 366
367static int snd_cs423x_card_new(int dev, struct snd_card **cardp) 367static int snd_cs423x_card_new(struct device *pdev, int dev,
368 struct snd_card **cardp)
368{ 369{
369 struct snd_card *card; 370 struct snd_card *card;
370 int err; 371 int err;
371 372
372 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 373 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
373 sizeof(struct snd_card_cs4236), &card); 374 sizeof(struct snd_card_cs4236), &card);
374 if (err < 0) 375 if (err < 0)
375 return err; 376 return err;
376 card->private_free = snd_card_cs4236_free; 377 card->private_free = snd_card_cs4236_free;
@@ -487,10 +488,9 @@ static int snd_cs423x_isa_probe(struct device *pdev,
487 struct snd_card *card; 488 struct snd_card *card;
488 int err; 489 int err;
489 490
490 err = snd_cs423x_card_new(dev, &card); 491 err = snd_cs423x_card_new(pdev, dev, &card);
491 if (err < 0) 492 if (err < 0)
492 return err; 493 return err;
493 snd_card_set_dev(card, pdev);
494 if ((err = snd_cs423x_probe(card, dev)) < 0) { 494 if ((err = snd_cs423x_probe(card, dev)) < 0) {
495 snd_card_free(card); 495 snd_card_free(card);
496 return err; 496 return err;
@@ -577,7 +577,7 @@ static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
577 if (!strcmp(cdev->id[0].id, cid)) 577 if (!strcmp(cdev->id[0].id, cid))
578 break; 578 break;
579 } 579 }
580 err = snd_cs423x_card_new(dev, &card); 580 err = snd_cs423x_card_new(&pdev->dev, dev, &card);
581 if (err < 0) 581 if (err < 0)
582 return err; 582 return err;
583 err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev); 583 err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
@@ -586,7 +586,6 @@ static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
586 snd_card_free(card); 586 snd_card_free(card);
587 return err; 587 return err;
588 } 588 }
589 snd_card_set_dev(card, &pdev->dev);
590 if ((err = snd_cs423x_probe(card, dev)) < 0) { 589 if ((err = snd_cs423x_probe(card, dev)) < 0) {
591 snd_card_free(card); 590 snd_card_free(card);
592 return err; 591 return err;
@@ -638,7 +637,7 @@ static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
638 if (dev >= SNDRV_CARDS) 637 if (dev >= SNDRV_CARDS)
639 return -ENODEV; 638 return -ENODEV;
640 639
641 res = snd_cs423x_card_new(dev, &card); 640 res = snd_cs423x_card_new(&pcard->card->dev, dev, &card);
642 if (res < 0) 641 if (res < 0)
643 return res; 642 return res;
644 if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) { 643 if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
@@ -647,7 +646,6 @@ static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
647 snd_card_free(card); 646 snd_card_free(card);
648 return res; 647 return res;
649 } 648 }
650 snd_card_set_dev(card, &pcard->card->dev);
651 if ((res = snd_cs423x_probe(card, dev)) < 0) { 649 if ((res = snd_cs423x_probe(card, dev)) < 0) {
652 snd_card_free(card); 650 snd_card_free(card);
653 return res; 651 return res;
diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c
index cdcfb57f1f0a..76001fe0579d 100644
--- a/sound/isa/es1688/es1688.c
+++ b/sound/isa/es1688/es1688.c
@@ -187,8 +187,8 @@ static int snd_es1688_isa_probe(struct device *dev, unsigned int n)
187 struct snd_card *card; 187 struct snd_card *card;
188 int error; 188 int error;
189 189
190 error = snd_card_create(index[n], id[n], THIS_MODULE, 190 error = snd_card_new(dev, index[n], id[n], THIS_MODULE,
191 sizeof(struct snd_es1688), &card); 191 sizeof(struct snd_es1688), &card);
192 if (error < 0) 192 if (error < 0)
193 return error; 193 return error;
194 194
@@ -196,8 +196,6 @@ static int snd_es1688_isa_probe(struct device *dev, unsigned int n)
196 if (error < 0) 196 if (error < 0)
197 goto out; 197 goto out;
198 198
199 snd_card_set_dev(card, dev);
200
201 error = snd_es1688_probe(card, n); 199 error = snd_es1688_probe(card, n);
202 if (error < 0) 200 if (error < 0)
203 goto out; 201 goto out;
@@ -274,8 +272,9 @@ static int snd_es968_pnp_detect(struct pnp_card_link *pcard,
274 if (dev == SNDRV_CARDS) 272 if (dev == SNDRV_CARDS)
275 return -ENODEV; 273 return -ENODEV;
276 274
277 error = snd_card_create(index[dev], id[dev], THIS_MODULE, 275 error = snd_card_new(&pcard->card->dev,
278 sizeof(struct snd_es1688), &card); 276 index[dev], id[dev], THIS_MODULE,
277 sizeof(struct snd_es1688), &card);
279 if (error < 0) 278 if (error < 0)
280 return error; 279 return error;
281 chip = card->private_data; 280 chip = card->private_data;
@@ -285,7 +284,6 @@ static int snd_es968_pnp_detect(struct pnp_card_link *pcard,
285 snd_card_free(card); 284 snd_card_free(card);
286 return error; 285 return error;
287 } 286 }
288 snd_card_set_dev(card, &pcard->card->dev);
289 error = snd_es1688_probe(card, dev); 287 error = snd_es1688_probe(card, dev);
290 if (error < 0) 288 if (error < 0)
291 return error; 289 return error;
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
index 12978b864c3a..1c16830af3d8 100644
--- a/sound/isa/es18xx.c
+++ b/sound/isa/es18xx.c
@@ -2105,10 +2105,11 @@ static int snd_audiodrive_pnpc(int dev, struct snd_es18xx *chip,
2105#define is_isapnp_selected(dev) 0 2105#define is_isapnp_selected(dev) 0
2106#endif 2106#endif
2107 2107
2108static int snd_es18xx_card_new(int dev, struct snd_card **cardp) 2108static int snd_es18xx_card_new(struct device *pdev, int dev,
2109 struct snd_card **cardp)
2109{ 2110{
2110 return snd_card_create(index[dev], id[dev], THIS_MODULE, 2111 return snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
2111 sizeof(struct snd_es18xx), cardp); 2112 sizeof(struct snd_es18xx), cardp);
2112} 2113}
2113 2114
2114static int snd_audiodrive_probe(struct snd_card *card, int dev) 2115static int snd_audiodrive_probe(struct snd_card *card, int dev)
@@ -2179,10 +2180,9 @@ static int snd_es18xx_isa_probe1(int dev, struct device *devptr)
2179 struct snd_card *card; 2180 struct snd_card *card;
2180 int err; 2181 int err;
2181 2182
2182 err = snd_es18xx_card_new(dev, &card); 2183 err = snd_es18xx_card_new(devptr, dev, &card);
2183 if (err < 0) 2184 if (err < 0)
2184 return err; 2185 return err;
2185 snd_card_set_dev(card, devptr);
2186 if ((err = snd_audiodrive_probe(card, dev)) < 0) { 2186 if ((err = snd_audiodrive_probe(card, dev)) < 0) {
2187 snd_card_free(card); 2187 snd_card_free(card);
2188 return err; 2188 return err;
@@ -2284,14 +2284,13 @@ static int snd_audiodrive_pnp_detect(struct pnp_dev *pdev,
2284 if (dev >= SNDRV_CARDS) 2284 if (dev >= SNDRV_CARDS)
2285 return -ENODEV; 2285 return -ENODEV;
2286 2286
2287 err = snd_es18xx_card_new(dev, &card); 2287 err = snd_es18xx_card_new(&pdev->dev, dev, &card);
2288 if (err < 0) 2288 if (err < 0)
2289 return err; 2289 return err;
2290 if ((err = snd_audiodrive_pnp(dev, card->private_data, pdev)) < 0) { 2290 if ((err = snd_audiodrive_pnp(dev, card->private_data, pdev)) < 0) {
2291 snd_card_free(card); 2291 snd_card_free(card);
2292 return err; 2292 return err;
2293 } 2293 }
2294 snd_card_set_dev(card, &pdev->dev);
2295 if ((err = snd_audiodrive_probe(card, dev)) < 0) { 2294 if ((err = snd_audiodrive_probe(card, dev)) < 0) {
2296 snd_card_free(card); 2295 snd_card_free(card);
2297 return err; 2296 return err;
@@ -2342,7 +2341,7 @@ static int snd_audiodrive_pnpc_detect(struct pnp_card_link *pcard,
2342 if (dev >= SNDRV_CARDS) 2341 if (dev >= SNDRV_CARDS)
2343 return -ENODEV; 2342 return -ENODEV;
2344 2343
2345 res = snd_es18xx_card_new(dev, &card); 2344 res = snd_es18xx_card_new(&pcard->card->dev, dev, &card);
2346 if (res < 0) 2345 if (res < 0)
2347 return res; 2346 return res;
2348 2347
@@ -2350,7 +2349,6 @@ static int snd_audiodrive_pnpc_detect(struct pnp_card_link *pcard,
2350 snd_card_free(card); 2349 snd_card_free(card);
2351 return res; 2350 return res;
2352 } 2351 }
2353 snd_card_set_dev(card, &pcard->card->dev);
2354 if ((res = snd_audiodrive_probe(card, dev)) < 0) { 2352 if ((res = snd_audiodrive_probe(card, dev)) < 0) {
2355 snd_card_free(card); 2353 snd_card_free(card);
2356 return res; 2354 return res;
diff --git a/sound/isa/galaxy/galaxy.c b/sound/isa/galaxy/galaxy.c
index 81244e7cea5b..1eb2b1ec0fd9 100644
--- a/sound/isa/galaxy/galaxy.c
+++ b/sound/isa/galaxy/galaxy.c
@@ -506,13 +506,11 @@ static int snd_galaxy_probe(struct device *dev, unsigned int n)
506 u8 type; 506 u8 type;
507 int err; 507 int err;
508 508
509 err = snd_card_create(index[n], id[n], THIS_MODULE, sizeof *galaxy, 509 err = snd_card_new(dev, index[n], id[n], THIS_MODULE,
510 &card); 510 sizeof(*galaxy), &card);
511 if (err < 0) 511 if (err < 0)
512 return err; 512 return err;
513 513
514 snd_card_set_dev(card, dev);
515
516 card->private_free = snd_galaxy_free; 514 card->private_free = snd_galaxy_free;
517 galaxy = card->private_data; 515 galaxy = card->private_data;
518 516
diff --git a/sound/isa/gus/gusclassic.c b/sound/isa/gus/gusclassic.c
index 1adc1b924f39..7ce29ffa1af9 100644
--- a/sound/isa/gus/gusclassic.c
+++ b/sound/isa/gus/gusclassic.c
@@ -149,7 +149,7 @@ static int snd_gusclassic_probe(struct device *dev, unsigned int n)
149 struct snd_gus_card *gus; 149 struct snd_gus_card *gus;
150 int error; 150 int error;
151 151
152 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card); 152 error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
153 if (error < 0) 153 if (error < 0)
154 return error; 154 return error;
155 155
@@ -199,8 +199,6 @@ static int snd_gusclassic_probe(struct device *dev, unsigned int n)
199 sprintf(card->longname + strlen(card->longname), 199 sprintf(card->longname + strlen(card->longname),
200 "&%d", gus->gf1.dma2); 200 "&%d", gus->gf1.dma2);
201 201
202 snd_card_set_dev(card, dev);
203
204 error = snd_card_register(card); 202 error = snd_card_register(card);
205 if (error < 0) 203 if (error < 0)
206 goto out; 204 goto out;
diff --git a/sound/isa/gus/gusextreme.c b/sound/isa/gus/gusextreme.c
index 38e1e3260c24..28a16936a397 100644
--- a/sound/isa/gus/gusextreme.c
+++ b/sound/isa/gus/gusextreme.c
@@ -242,8 +242,8 @@ static int snd_gusextreme_probe(struct device *dev, unsigned int n)
242 struct snd_opl3 *opl3; 242 struct snd_opl3 *opl3;
243 int error; 243 int error;
244 244
245 error = snd_card_create(index[n], id[n], THIS_MODULE, 245 error = snd_card_new(dev, index[n], id[n], THIS_MODULE,
246 sizeof(struct snd_es1688), &card); 246 sizeof(struct snd_es1688), &card);
247 if (error < 0) 247 if (error < 0)
248 return error; 248 return error;
249 249
@@ -328,8 +328,6 @@ static int snd_gusextreme_probe(struct device *dev, unsigned int n)
328 "irq %i&%i, dma %i&%i", es1688->port, 328 "irq %i&%i, dma %i&%i", es1688->port,
329 gus->gf1.irq, es1688->irq, gus->gf1.dma1, es1688->dma8); 329 gus->gf1.irq, es1688->irq, gus->gf1.dma1, es1688->dma8);
330 330
331 snd_card_set_dev(card, dev);
332
333 error = snd_card_register(card); 331 error = snd_card_register(card);
334 if (error < 0) 332 if (error < 0)
335 goto out; 333 goto out;
diff --git a/sound/isa/gus/gusmax.c b/sound/isa/gus/gusmax.c
index 652d5d834620..39df36ca3acb 100644
--- a/sound/isa/gus/gusmax.c
+++ b/sound/isa/gus/gusmax.c
@@ -214,8 +214,8 @@ static int 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 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 217 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
218 sizeof(struct snd_gusmax), &card); 218 sizeof(struct snd_gusmax), &card);
219 if (err < 0) 219 if (err < 0)
220 return err; 220 return err;
221 card->private_free = snd_gusmax_free; 221 card->private_free = snd_gusmax_free;
@@ -337,8 +337,6 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev)
337 if (xdma2 >= 0) 337 if (xdma2 >= 0)
338 sprintf(card->longname + strlen(card->longname), "&%i", xdma2); 338 sprintf(card->longname + strlen(card->longname), "&%i", xdma2);
339 339
340 snd_card_set_dev(card, pdev);
341
342 err = snd_card_register(card); 340 err = snd_card_register(card);
343 if (err < 0) 341 if (err < 0)
344 goto _err; 342 goto _err;
diff --git a/sound/isa/gus/interwave.c b/sound/isa/gus/interwave.c
index afef0d738078..5abbbe477d16 100644
--- a/sound/isa/gus/interwave.c
+++ b/sound/isa/gus/interwave.c
@@ -625,14 +625,15 @@ static void snd_interwave_free(struct snd_card *card)
625 free_irq(iwcard->irq, (void *)iwcard); 625 free_irq(iwcard->irq, (void *)iwcard);
626} 626}
627 627
628static int snd_interwave_card_new(int dev, struct snd_card **cardp) 628static int snd_interwave_card_new(struct device *pdev, int dev,
629 struct snd_card **cardp)
629{ 630{
630 struct snd_card *card; 631 struct snd_card *card;
631 struct snd_interwave *iwcard; 632 struct snd_interwave *iwcard;
632 int err; 633 int err;
633 634
634 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 635 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
635 sizeof(struct snd_interwave), &card); 636 sizeof(struct snd_interwave), &card);
636 if (err < 0) 637 if (err < 0)
637 return err; 638 return err;
638 iwcard = card->private_data; 639 iwcard = card->private_data;
@@ -779,11 +780,10 @@ static int snd_interwave_isa_probe1(int dev, struct device *devptr)
779 struct snd_card *card; 780 struct snd_card *card;
780 int err; 781 int err;
781 782
782 err = snd_interwave_card_new(dev, &card); 783 err = snd_interwave_card_new(devptr, dev, &card);
783 if (err < 0) 784 if (err < 0)
784 return err; 785 return err;
785 786
786 snd_card_set_dev(card, devptr);
787 if ((err = snd_interwave_probe(card, dev)) < 0) { 787 if ((err = snd_interwave_probe(card, dev)) < 0) {
788 snd_card_free(card); 788 snd_card_free(card);
789 return err; 789 return err;
@@ -876,7 +876,7 @@ static int snd_interwave_pnp_detect(struct pnp_card_link *pcard,
876 if (dev >= SNDRV_CARDS) 876 if (dev >= SNDRV_CARDS)
877 return -ENODEV; 877 return -ENODEV;
878 878
879 res = snd_interwave_card_new(dev, &card); 879 res = snd_interwave_card_new(&pcard->card->dev, dev, &card);
880 if (res < 0) 880 if (res < 0)
881 return res; 881 return res;
882 882
@@ -884,7 +884,6 @@ static int snd_interwave_pnp_detect(struct pnp_card_link *pcard,
884 snd_card_free(card); 884 snd_card_free(card);
885 return res; 885 return res;
886 } 886 }
887 snd_card_set_dev(card, &pcard->card->dev);
888 if ((res = snd_interwave_probe(card, dev)) < 0) { 887 if ((res = snd_interwave_probe(card, dev)) < 0) {
889 snd_card_free(card); 888 snd_card_free(card);
890 return res; 889 return res;
diff --git a/sound/isa/msnd/msnd_pinnacle.c b/sound/isa/msnd/msnd_pinnacle.c
index 0a90bd6ae232..5016bf957f51 100644
--- a/sound/isa/msnd/msnd_pinnacle.c
+++ b/sound/isa/msnd/msnd_pinnacle.c
@@ -905,12 +905,11 @@ static int snd_msnd_isa_probe(struct device *pdev, unsigned int idx)
905 return -ENODEV; 905 return -ENODEV;
906 } 906 }
907 907
908 err = snd_card_create(index[idx], id[idx], THIS_MODULE, 908 err = snd_card_new(pdev, index[idx], id[idx], THIS_MODULE,
909 sizeof(struct snd_msnd), &card); 909 sizeof(struct snd_msnd), &card);
910 if (err < 0) 910 if (err < 0)
911 return err; 911 return err;
912 912
913 snd_card_set_dev(card, pdev);
914 chip = card->private_data; 913 chip = card->private_data;
915 chip->card = card; 914 chip->card = card;
916 915
@@ -1122,14 +1121,14 @@ static int snd_msnd_pnp_detect(struct pnp_card_link *pcard,
1122 * Create a new ALSA sound card entry, in anticipation 1121 * Create a new ALSA sound card entry, in anticipation
1123 * of detecting our hardware ... 1122 * of detecting our hardware ...
1124 */ 1123 */
1125 ret = snd_card_create(index[idx], id[idx], THIS_MODULE, 1124 ret = snd_card_new(&pcard->card->dev,
1126 sizeof(struct snd_msnd), &card); 1125 index[idx], id[idx], THIS_MODULE,
1126 sizeof(struct snd_msnd), &card);
1127 if (ret < 0) 1127 if (ret < 0)
1128 return ret; 1128 return ret;
1129 1129
1130 chip = card->private_data; 1130 chip = card->private_data;
1131 chip->card = card; 1131 chip->card = card;
1132 snd_card_set_dev(card, &pcard->card->dev);
1133 1132
1134 /* 1133 /*
1135 * Read the correct parameters off the ISA PnP bus ... 1134 * Read the correct parameters off the ISA PnP bus ...
diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c
index cc01c419b7e9..a219bc37816b 100644
--- a/sound/isa/opl3sa2.c
+++ b/sound/isa/opl3sa2.c
@@ -627,14 +627,15 @@ static void snd_opl3sa2_free(struct snd_card *card)
627 release_and_free_resource(chip->res_port); 627 release_and_free_resource(chip->res_port);
628} 628}
629 629
630static int snd_opl3sa2_card_new(int dev, struct snd_card **cardp) 630static int snd_opl3sa2_card_new(struct device *pdev, int dev,
631 struct snd_card **cardp)
631{ 632{
632 struct snd_card *card; 633 struct snd_card *card;
633 struct snd_opl3sa2 *chip; 634 struct snd_opl3sa2 *chip;
634 int err; 635 int err;
635 636
636 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 637 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
637 sizeof(struct snd_opl3sa2), &card); 638 sizeof(struct snd_opl3sa2), &card);
638 if (err < 0) 639 if (err < 0)
639 return err; 640 return err;
640 strcpy(card->driver, "OPL3SA2"); 641 strcpy(card->driver, "OPL3SA2");
@@ -737,14 +738,13 @@ static int snd_opl3sa2_pnp_detect(struct pnp_dev *pdev,
737 if (dev >= SNDRV_CARDS) 738 if (dev >= SNDRV_CARDS)
738 return -ENODEV; 739 return -ENODEV;
739 740
740 err = snd_opl3sa2_card_new(dev, &card); 741 err = snd_opl3sa2_card_new(&pdev->dev, dev, &card);
741 if (err < 0) 742 if (err < 0)
742 return err; 743 return err;
743 if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) { 744 if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) {
744 snd_card_free(card); 745 snd_card_free(card);
745 return err; 746 return err;
746 } 747 }
747 snd_card_set_dev(card, &pdev->dev);
748 if ((err = snd_opl3sa2_probe(card, dev)) < 0) { 748 if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
749 snd_card_free(card); 749 snd_card_free(card);
750 return err; 750 return err;
@@ -802,14 +802,13 @@ static int snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard,
802 if (dev >= SNDRV_CARDS) 802 if (dev >= SNDRV_CARDS)
803 return -ENODEV; 803 return -ENODEV;
804 804
805 err = snd_opl3sa2_card_new(dev, &card); 805 err = snd_opl3sa2_card_new(&pdev->dev, dev, &card);
806 if (err < 0) 806 if (err < 0)
807 return err; 807 return err;
808 if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) { 808 if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) {
809 snd_card_free(card); 809 snd_card_free(card);
810 return err; 810 return err;
811 } 811 }
812 snd_card_set_dev(card, &pdev->dev);
813 if ((err = snd_opl3sa2_probe(card, dev)) < 0) { 812 if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
814 snd_card_free(card); 813 snd_card_free(card);
815 return err; 814 return err;
@@ -883,10 +882,9 @@ static int snd_opl3sa2_isa_probe(struct device *pdev,
883 struct snd_card *card; 882 struct snd_card *card;
884 int err; 883 int err;
885 884
886 err = snd_opl3sa2_card_new(dev, &card); 885 err = snd_opl3sa2_card_new(pdev, dev, &card);
887 if (err < 0) 886 if (err < 0)
888 return err; 887 return err;
889 snd_card_set_dev(card, pdev);
890 if ((err = snd_opl3sa2_probe(card, dev)) < 0) { 888 if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
891 snd_card_free(card); 889 snd_card_free(card);
892 return err; 890 return err;
diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c
index 619753d96ca5..c2ca681ac51b 100644
--- a/sound/isa/opti9xx/miro.c
+++ b/sound/isa/opti9xx/miro.c
@@ -1411,8 +1411,8 @@ static int snd_miro_isa_probe(struct device *devptr, unsigned int n)
1411 struct snd_miro *miro; 1411 struct snd_miro *miro;
1412 struct snd_card *card; 1412 struct snd_card *card;
1413 1413
1414 error = snd_card_create(index, id, THIS_MODULE, 1414 error = snd_card_new(devptr, index, id, THIS_MODULE,
1415 sizeof(struct snd_miro), &card); 1415 sizeof(struct snd_miro), &card);
1416 if (error < 0) 1416 if (error < 0)
1417 return error; 1417 return error;
1418 1418
@@ -1479,8 +1479,6 @@ static int snd_miro_isa_probe(struct device *devptr, unsigned int n)
1479 } 1479 }
1480 } 1480 }
1481 1481
1482 snd_card_set_dev(card, devptr);
1483
1484 error = snd_miro_probe(card); 1482 error = snd_miro_probe(card);
1485 if (error < 0) { 1483 if (error < 0) {
1486 snd_card_free(card); 1484 snd_card_free(card);
@@ -1584,8 +1582,8 @@ static int snd_miro_pnp_probe(struct pnp_card_link *pcard,
1584 return -EBUSY; 1582 return -EBUSY;
1585 if (!isapnp) 1583 if (!isapnp)
1586 return -ENODEV; 1584 return -ENODEV;
1587 err = snd_card_create(index, id, THIS_MODULE, 1585 err = snd_card_new(&pcard->card->dev, index, id, THIS_MODULE,
1588 sizeof(struct snd_miro), &card); 1586 sizeof(struct snd_miro), &card);
1589 if (err < 0) 1587 if (err < 0)
1590 return err; 1588 return err;
1591 1589
@@ -1612,7 +1610,6 @@ static int snd_miro_pnp_probe(struct pnp_card_link *pcard,
1612 return err; 1610 return err;
1613 } 1611 }
1614 1612
1615 snd_card_set_dev(card, &pcard->card->dev);
1616 err = snd_miro_probe(card); 1613 err = snd_miro_probe(card);
1617 if (err < 0) { 1614 if (err < 0) {
1618 snd_card_free(card); 1615 snd_card_free(card);
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c
index 6effe99bbb9c..c9b582848603 100644
--- a/sound/isa/opti9xx/opti92x-ad1848.c
+++ b/sound/isa/opti9xx/opti92x-ad1848.c
@@ -934,13 +934,13 @@ static int snd_opti9xx_probe(struct snd_card *card)
934 return snd_card_register(card); 934 return snd_card_register(card);
935} 935}
936 936
937static int snd_opti9xx_card_new(struct snd_card **cardp) 937static int snd_opti9xx_card_new(struct device *pdev, struct snd_card **cardp)
938{ 938{
939 struct snd_card *card; 939 struct snd_card *card;
940 int err; 940 int err;
941 941
942 err = snd_card_create(index, id, THIS_MODULE, 942 err = snd_card_new(pdev, index, id, THIS_MODULE,
943 sizeof(struct snd_opti9xx), &card); 943 sizeof(struct snd_opti9xx), &card);
944 if (err < 0) 944 if (err < 0)
945 return err; 945 return err;
946 card->private_free = snd_card_opti9xx_free; 946 card->private_free = snd_card_opti9xx_free;
@@ -1010,7 +1010,7 @@ static int snd_opti9xx_isa_probe(struct device *devptr,
1010 } 1010 }
1011#endif 1011#endif
1012 1012
1013 error = snd_opti9xx_card_new(&card); 1013 error = snd_opti9xx_card_new(devptr, &card);
1014 if (error < 0) 1014 if (error < 0)
1015 return error; 1015 return error;
1016 1016
@@ -1018,7 +1018,6 @@ static int snd_opti9xx_isa_probe(struct device *devptr,
1018 snd_card_free(card); 1018 snd_card_free(card);
1019 return error; 1019 return error;
1020 } 1020 }
1021 snd_card_set_dev(card, devptr);
1022 if ((error = snd_opti9xx_probe(card)) < 0) { 1021 if ((error = snd_opti9xx_probe(card)) < 0) {
1023 snd_card_free(card); 1022 snd_card_free(card);
1024 return error; 1023 return error;
@@ -1100,7 +1099,7 @@ static int snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
1100 return -EBUSY; 1099 return -EBUSY;
1101 if (! isapnp) 1100 if (! isapnp)
1102 return -ENODEV; 1101 return -ENODEV;
1103 error = snd_opti9xx_card_new(&card); 1102 error = snd_opti9xx_card_new(&pcard->card->dev, &card);
1104 if (error < 0) 1103 if (error < 0)
1105 return error; 1104 return error;
1106 chip = card->private_data; 1105 chip = card->private_data;
@@ -1131,7 +1130,6 @@ static int snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
1131 snd_card_free(card); 1130 snd_card_free(card);
1132 return error; 1131 return error;
1133 } 1132 }
1134 snd_card_set_dev(card, &pcard->card->dev);
1135 if ((error = snd_opti9xx_probe(card)) < 0) { 1133 if ((error = snd_opti9xx_probe(card)) < 0) {
1136 snd_card_free(card); 1134 snd_card_free(card);
1137 return error; 1135 return error;
diff --git a/sound/isa/sb/jazz16.c b/sound/isa/sb/jazz16.c
index 356a6308392f..90d2eba549e9 100644
--- a/sound/isa/sb/jazz16.c
+++ b/sound/isa/sb/jazz16.c
@@ -229,8 +229,8 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
229 static int possible_dmas16[] = {5, 7, -1}; 229 static int possible_dmas16[] = {5, 7, -1};
230 int err, xirq, xdma8, xdma16, xmpu_port, xmpu_irq; 230 int err, xirq, xdma8, xdma16, xmpu_port, xmpu_irq;
231 231
232 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 232 err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
233 sizeof(struct snd_card_jazz16), &card); 233 sizeof(struct snd_card_jazz16), &card);
234 if (err < 0) 234 if (err < 0)
235 return err; 235 return err;
236 236
@@ -327,8 +327,6 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
327 mpu_port[dev]); 327 mpu_port[dev]);
328 } 328 }
329 329
330 snd_card_set_dev(card, devptr);
331
332 err = snd_card_register(card); 330 err = snd_card_register(card);
333 if (err < 0) 331 if (err < 0)
334 goto err_free; 332 goto err_free;
diff --git a/sound/isa/sb/sb16.c b/sound/isa/sb/sb16.c
index a4130993955f..3f694543a7ea 100644
--- a/sound/isa/sb/sb16.c
+++ b/sound/isa/sb/sb16.c
@@ -323,13 +323,14 @@ static void snd_sb16_free(struct snd_card *card)
323#define is_isapnp_selected(dev) 0 323#define is_isapnp_selected(dev) 0
324#endif 324#endif
325 325
326static int snd_sb16_card_new(int dev, struct snd_card **cardp) 326static int snd_sb16_card_new(struct device *devptr, int dev,
327 struct snd_card **cardp)
327{ 328{
328 struct snd_card *card; 329 struct snd_card *card;
329 int err; 330 int err;
330 331
331 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 332 err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
332 sizeof(struct snd_card_sb16), &card); 333 sizeof(struct snd_card_sb16), &card);
333 if (err < 0) 334 if (err < 0)
334 return err; 335 return err;
335 card->private_free = snd_sb16_free; 336 card->private_free = snd_sb16_free;
@@ -493,7 +494,7 @@ static int snd_sb16_isa_probe1(int dev, struct device *pdev)
493 struct snd_card *card; 494 struct snd_card *card;
494 int err; 495 int err;
495 496
496 err = snd_sb16_card_new(dev, &card); 497 err = snd_sb16_card_new(pdev, dev, &card);
497 if (err < 0) 498 if (err < 0)
498 return err; 499 return err;
499 500
@@ -507,7 +508,6 @@ static int snd_sb16_isa_probe1(int dev, struct device *pdev)
507 awe_port[dev] = port[dev] + 0x400; 508 awe_port[dev] = port[dev] + 0x400;
508#endif 509#endif
509 510
510 snd_card_set_dev(card, pdev);
511 if ((err = snd_sb16_probe(card, dev)) < 0) { 511 if ((err = snd_sb16_probe(card, dev)) < 0) {
512 snd_card_free(card); 512 snd_card_free(card);
513 return err; 513 return err;
@@ -613,10 +613,9 @@ static int snd_sb16_pnp_detect(struct pnp_card_link *pcard,
613 for ( ; dev < SNDRV_CARDS; dev++) { 613 for ( ; dev < SNDRV_CARDS; dev++) {
614 if (!enable[dev] || !isapnp[dev]) 614 if (!enable[dev] || !isapnp[dev])
615 continue; 615 continue;
616 res = snd_sb16_card_new(dev, &card); 616 res = snd_sb16_card_new(&pcard->card->dev, dev, &card);
617 if (res < 0) 617 if (res < 0)
618 return res; 618 return res;
619 snd_card_set_dev(card, &pcard->card->dev);
620 if ((res = snd_card_sb16_pnp(dev, card->private_data, pcard, pid)) < 0 || 619 if ((res = snd_card_sb16_pnp(dev, card->private_data, pcard, pid)) < 0 ||
621 (res = snd_sb16_probe(card, dev)) < 0) { 620 (res = snd_sb16_probe(card, dev)) < 0) {
622 snd_card_free(card); 621 snd_card_free(card);
diff --git a/sound/isa/sb/sb8.c b/sound/isa/sb/sb8.c
index a806ae90a944..6c32b3aa34af 100644
--- a/sound/isa/sb/sb8.c
+++ b/sound/isa/sb/sb8.c
@@ -102,8 +102,8 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
102 struct snd_opl3 *opl3; 102 struct snd_opl3 *opl3;
103 int err; 103 int err;
104 104
105 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 105 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
106 sizeof(struct snd_sb8), &card); 106 sizeof(struct snd_sb8), &card);
107 if (err < 0) 107 if (err < 0)
108 return err; 108 return err;
109 acard = card->private_data; 109 acard = card->private_data;
@@ -192,8 +192,6 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
192 chip->port, 192 chip->port,
193 irq[dev], dma8[dev]); 193 irq[dev], dma8[dev]);
194 194
195 snd_card_set_dev(card, pdev);
196
197 if ((err = snd_card_register(card)) < 0) 195 if ((err = snd_card_register(card)) < 0)
198 goto _err; 196 goto _err;
199 197
diff --git a/sound/isa/sc6000.c b/sound/isa/sc6000.c
index 09d481b3ba7f..15a152eaa2e8 100644
--- a/sound/isa/sc6000.c
+++ b/sound/isa/sc6000.c
@@ -559,8 +559,8 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev)
559 char __iomem *vmss_port; 559 char __iomem *vmss_port;
560 560
561 561
562 err = snd_card_create(index[dev], id[dev], THIS_MODULE, sizeof(vport), 562 err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
563 &card); 563 sizeof(vport), &card);
564 if (err < 0) 564 if (err < 0)
565 return err; 565 return err;
566 566
@@ -668,8 +668,6 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev)
668 sprintf(card->longname, "Gallant SC-6000 at 0x%lx, irq %d, dma %d", 668 sprintf(card->longname, "Gallant SC-6000 at 0x%lx, irq %d, dma %d",
669 mss_port[dev], xirq, xdma); 669 mss_port[dev], xirq, xdma);
670 670
671 snd_card_set_dev(card, devptr);
672
673 err = snd_card_register(card); 671 err = snd_card_register(card);
674 if (err < 0) 672 if (err < 0)
675 goto err_unmap2; 673 goto err_unmap2;
diff --git a/sound/isa/sscape.c b/sound/isa/sscape.c
index 57b338973ede..44405df7d4be 100644
--- a/sound/isa/sscape.c
+++ b/sound/isa/sscape.c
@@ -1169,8 +1169,8 @@ static int snd_sscape_probe(struct device *pdev, unsigned int dev)
1169 struct soundscape *sscape; 1169 struct soundscape *sscape;
1170 int ret; 1170 int ret;
1171 1171
1172 ret = snd_card_create(index[dev], id[dev], THIS_MODULE, 1172 ret = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
1173 sizeof(struct soundscape), &card); 1173 sizeof(struct soundscape), &card);
1174 if (ret < 0) 1174 if (ret < 0)
1175 return ret; 1175 return ret;
1176 1176
@@ -1178,7 +1178,6 @@ static int snd_sscape_probe(struct device *pdev, unsigned int dev)
1178 sscape->type = SSCAPE; 1178 sscape->type = SSCAPE;
1179 1179
1180 dma[dev] &= 0x03; 1180 dma[dev] &= 0x03;
1181 snd_card_set_dev(card, pdev);
1182 1181
1183 ret = create_sscape(dev, card); 1182 ret = create_sscape(dev, card);
1184 if (ret < 0) 1183 if (ret < 0)
@@ -1259,8 +1258,9 @@ static int sscape_pnp_detect(struct pnp_card_link *pcard,
1259 * Create a new ALSA sound card entry, in anticipation 1258 * Create a new ALSA sound card entry, in anticipation
1260 * of detecting our hardware ... 1259 * of detecting our hardware ...
1261 */ 1260 */
1262 ret = snd_card_create(index[idx], id[idx], THIS_MODULE, 1261 ret = snd_card_new(&pcard->card->dev,
1263 sizeof(struct soundscape), &card); 1262 index[idx], id[idx], THIS_MODULE,
1263 sizeof(struct soundscape), &card);
1264 if (ret < 0) 1264 if (ret < 0)
1265 return ret; 1265 return ret;
1266 1266
@@ -1288,7 +1288,6 @@ static int sscape_pnp_detect(struct pnp_card_link *pcard,
1288 wss_port[idx] = pnp_port_start(dev, 1); 1288 wss_port[idx] = pnp_port_start(dev, 1);
1289 dma2[idx] = pnp_dma(dev, 1); 1289 dma2[idx] = pnp_dma(dev, 1);
1290 } 1290 }
1291 snd_card_set_dev(card, &pcard->card->dev);
1292 1291
1293 ret = create_sscape(idx, card); 1292 ret = create_sscape(idx, card);
1294 if (ret < 0) 1293 if (ret < 0)
diff --git a/sound/isa/wavefront/wavefront.c b/sound/isa/wavefront/wavefront.c
index 82dd76939fa0..bfbf38cf9841 100644
--- a/sound/isa/wavefront/wavefront.c
+++ b/sound/isa/wavefront/wavefront.c
@@ -334,14 +334,15 @@ snd_wavefront_free(struct snd_card *card)
334 } 334 }
335} 335}
336 336
337static int snd_wavefront_card_new(int dev, struct snd_card **cardp) 337static int snd_wavefront_card_new(struct device *pdev, int dev,
338 struct snd_card **cardp)
338{ 339{
339 struct snd_card *card; 340 struct snd_card *card;
340 snd_wavefront_card_t *acard; 341 snd_wavefront_card_t *acard;
341 int err; 342 int err;
342 343
343 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 344 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
344 sizeof(snd_wavefront_card_t), &card); 345 sizeof(snd_wavefront_card_t), &card);
345 if (err < 0) 346 if (err < 0)
346 return err; 347 return err;
347 348
@@ -564,10 +565,9 @@ static int snd_wavefront_isa_probe(struct device *pdev,
564 struct snd_card *card; 565 struct snd_card *card;
565 int err; 566 int err;
566 567
567 err = snd_wavefront_card_new(dev, &card); 568 err = snd_wavefront_card_new(pdev, dev, &card);
568 if (err < 0) 569 if (err < 0)
569 return err; 570 return err;
570 snd_card_set_dev(card, pdev);
571 if ((err = snd_wavefront_probe(card, dev)) < 0) { 571 if ((err = snd_wavefront_probe(card, dev)) < 0) {
572 snd_card_free(card); 572 snd_card_free(card);
573 return err; 573 return err;
@@ -612,7 +612,7 @@ static int snd_wavefront_pnp_detect(struct pnp_card_link *pcard,
612 if (dev >= SNDRV_CARDS) 612 if (dev >= SNDRV_CARDS)
613 return -ENODEV; 613 return -ENODEV;
614 614
615 res = snd_wavefront_card_new(dev, &card); 615 res = snd_wavefront_card_new(&pcard->card->dev, dev, &card);
616 if (res < 0) 616 if (res < 0)
617 return res; 617 return res;
618 618
@@ -623,7 +623,6 @@ static int snd_wavefront_pnp_detect(struct pnp_card_link *pcard,
623 return -ENODEV; 623 return -ENODEV;
624 } 624 }
625 } 625 }
626 snd_card_set_dev(card, &pcard->card->dev);
627 626
628 if ((res = snd_wavefront_probe(card, dev)) < 0) 627 if ((res = snd_wavefront_probe(card, dev)) < 0)
629 return res; 628 return res;
diff --git a/sound/mips/au1x00.c b/sound/mips/au1x00.c
index 224f54be15a6..a7cc49e96068 100644
--- a/sound/mips/au1x00.c
+++ b/sound/mips/au1x00.c
@@ -37,6 +37,7 @@
37#include <linux/ioport.h> 37#include <linux/ioport.h>
38#include <linux/interrupt.h> 38#include <linux/interrupt.h>
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/platform_device.h>
40#include <linux/slab.h> 41#include <linux/slab.h>
41#include <linux/module.h> 42#include <linux/module.h>
42#include <sound/core.h> 43#include <sound/core.h>
@@ -98,6 +99,7 @@ struct snd_au1000 {
98 99
99 struct snd_pcm *pcm; 100 struct snd_pcm *pcm;
100 struct audio_stream *stream[2]; /* playback & capture */ 101 struct audio_stream *stream[2]; /* playback & capture */
102 int dmaid[2]; /* tx(0)/rx(1) DMA ids */
101}; 103};
102 104
103/*--------------------------- Local Functions --------------------------------*/ 105/*--------------------------- Local Functions --------------------------------*/
@@ -465,15 +467,17 @@ snd_au1000_pcm_new(struct snd_au1000 *au1000)
465 spin_lock_init(&au1000->stream[CAPTURE]->dma_lock); 467 spin_lock_init(&au1000->stream[CAPTURE]->dma_lock);
466 468
467 flags = claim_dma_lock(); 469 flags = claim_dma_lock();
468 if ((au1000->stream[PLAYBACK]->dma = request_au1000_dma(DMA_ID_AC97C_TX, 470 au1000->stream[PLAYBACK]->dma = request_au1000_dma(au1000->dmaid[0],
469 "AC97 TX", au1000_dma_interrupt, 0, 471 "AC97 TX", au1000_dma_interrupt, 0,
470 au1000->stream[PLAYBACK])) < 0) { 472 au1000->stream[PLAYBACK]);
473 if (au1000->stream[PLAYBACK]->dma < 0) {
471 release_dma_lock(flags); 474 release_dma_lock(flags);
472 return -EBUSY; 475 return -EBUSY;
473 } 476 }
474 if ((au1000->stream[CAPTURE]->dma = request_au1000_dma(DMA_ID_AC97C_RX, 477 au1000->stream[CAPTURE]->dma = request_au1000_dma(au1000->dmaid[1],
475 "AC97 RX", au1000_dma_interrupt, 0, 478 "AC97 RX", au1000_dma_interrupt, 0,
476 au1000->stream[CAPTURE])) < 0){ 479 au1000->stream[CAPTURE]);
480 if (au1000->stream[CAPTURE]->dma < 0){
477 release_dma_lock(flags); 481 release_dma_lock(flags);
478 return -EBUSY; 482 return -EBUSY;
479 } 483 }
@@ -552,69 +556,12 @@ get the interrupt driven case to work efficiently */
552 spin_unlock(&au1000->ac97_lock); 556 spin_unlock(&au1000->ac97_lock);
553} 557}
554 558
555static int
556snd_au1000_ac97_new(struct snd_au1000 *au1000)
557{
558 int err;
559 struct snd_ac97_bus *pbus;
560 struct snd_ac97_template ac97;
561 static struct snd_ac97_bus_ops ops = {
562 .write = snd_au1000_ac97_write,
563 .read = snd_au1000_ac97_read,
564 };
565
566 if ((au1000->ac97_res_port = request_mem_region(CPHYSADDR(AC97C_CONFIG),
567 0x100000, "Au1x00 AC97")) == NULL) {
568 snd_printk(KERN_ERR "ALSA AC97: can't grap AC97 port\n");
569 return -EBUSY;
570 }
571 au1000->ac97_ioport = (struct au1000_ac97_reg *)
572 KSEG1ADDR(au1000->ac97_res_port->start);
573
574 spin_lock_init(&au1000->ac97_lock);
575
576 /* configure pins for AC'97
577 TODO: move to board_setup.c */
578 au_writel(au_readl(SYS_PINFUNC) & ~0x02, SYS_PINFUNC);
579
580 /* Initialise Au1000's AC'97 Control Block */
581 au1000->ac97_ioport->cntrl = AC97C_RS | AC97C_CE;
582 udelay(10);
583 au1000->ac97_ioport->cntrl = AC97C_CE;
584 udelay(10);
585
586 /* Initialise External CODEC -- cold reset */
587 au1000->ac97_ioport->config = AC97C_RESET;
588 udelay(10);
589 au1000->ac97_ioport->config = 0x0;
590 mdelay(5);
591
592 /* Initialise AC97 middle-layer */
593 if ((err = snd_ac97_bus(au1000->card, 0, &ops, au1000, &pbus)) < 0)
594 return err;
595
596 memset(&ac97, 0, sizeof(ac97));
597 ac97.private_data = au1000;
598 if ((err = snd_ac97_mixer(pbus, &ac97, &au1000->ac97)) < 0)
599 return err;
600
601 return 0;
602}
603
604/*------------------------------ Setup / Destroy ----------------------------*/ 559/*------------------------------ Setup / Destroy ----------------------------*/
605 560
606void 561static void snd_au1000_free(struct snd_card *card)
607snd_au1000_free(struct snd_card *card)
608{ 562{
609 struct snd_au1000 *au1000 = card->private_data; 563 struct snd_au1000 *au1000 = card->private_data;
610 564
611 if (au1000->ac97_res_port) {
612 /* put internal AC97 block into reset */
613 au1000->ac97_ioport->cntrl = AC97C_RS;
614 au1000->ac97_ioport = NULL;
615 release_and_free_resource(au1000->ac97_res_port);
616 }
617
618 if (au1000->stream[PLAYBACK]) { 565 if (au1000->stream[PLAYBACK]) {
619 if (au1000->stream[PLAYBACK]->dma >= 0) 566 if (au1000->stream[PLAYBACK]->dma >= 0)
620 free_au1000_dma(au1000->stream[PLAYBACK]->dma); 567 free_au1000_dma(au1000->stream[PLAYBACK]->dma);
@@ -626,71 +573,167 @@ snd_au1000_free(struct snd_card *card)
626 free_au1000_dma(au1000->stream[CAPTURE]->dma); 573 free_au1000_dma(au1000->stream[CAPTURE]->dma);
627 kfree(au1000->stream[CAPTURE]); 574 kfree(au1000->stream[CAPTURE]);
628 } 575 }
629}
630 576
577 if (au1000->ac97_res_port) {
578 /* put internal AC97 block into reset */
579 if (au1000->ac97_ioport) {
580 au1000->ac97_ioport->cntrl = AC97C_RS;
581 iounmap(au1000->ac97_ioport);
582 au1000->ac97_ioport = NULL;
583 }
584 release_and_free_resource(au1000->ac97_res_port);
585 au1000->ac97_res_port = NULL;
586 }
587}
631 588
632static struct snd_card *au1000_card; 589static struct snd_ac97_bus_ops ops = {
590 .write = snd_au1000_ac97_write,
591 .read = snd_au1000_ac97_read,
592};
633 593
634static int __init 594static int au1000_ac97_probe(struct platform_device *pdev)
635au1000_init(void)
636{ 595{
637 int err; 596 int err;
597 void __iomem *io;
598 struct resource *r;
638 struct snd_card *card; 599 struct snd_card *card;
639 struct snd_au1000 *au1000; 600 struct snd_au1000 *au1000;
601 struct snd_ac97_bus *pbus;
602 struct snd_ac97_template ac97;
640 603
641 err = snd_card_create(-1, "AC97", THIS_MODULE, 604 err = snd_card_new(&pdev->dev, -1, "AC97", THIS_MODULE,
642 sizeof(struct snd_au1000), &card); 605 sizeof(struct snd_au1000), &card);
643 if (err < 0) 606 if (err < 0)
644 return err; 607 return err;
645 608
646 card->private_free = snd_au1000_free;
647 au1000 = card->private_data; 609 au1000 = card->private_data;
648 au1000->card = card; 610 au1000->card = card;
611 spin_lock_init(&au1000->ac97_lock);
649 612
650 au1000->stream[PLAYBACK] = kmalloc(sizeof(struct audio_stream), GFP_KERNEL); 613 /* from here on let ALSA call the special freeing function */
651 au1000->stream[CAPTURE ] = kmalloc(sizeof(struct audio_stream), GFP_KERNEL); 614 card->private_free = snd_au1000_free;
652 /* so that snd_au1000_free will work as intended */
653 au1000->ac97_res_port = NULL;
654 if (au1000->stream[PLAYBACK])
655 au1000->stream[PLAYBACK]->dma = -1;
656 if (au1000->stream[CAPTURE ])
657 au1000->stream[CAPTURE ]->dma = -1;
658
659 if (au1000->stream[PLAYBACK] == NULL ||
660 au1000->stream[CAPTURE ] == NULL) {
661 snd_card_free(card);
662 return -ENOMEM;
663 }
664 615
665 if ((err = snd_au1000_ac97_new(au1000)) < 0 ) { 616 /* TX DMA ID */
666 snd_card_free(card); 617 r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
667 return err; 618 if (!r) {
619 err = -ENODEV;
620 snd_printk(KERN_INFO "no TX DMA platform resource!\n");
621 goto out;
668 } 622 }
669 623 au1000->dmaid[0] = r->start;
670 if ((err = snd_au1000_pcm_new(au1000)) < 0) { 624
671 snd_card_free(card); 625 /* RX DMA ID */
672 return err; 626 r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
627 if (!r) {
628 err = -ENODEV;
629 snd_printk(KERN_INFO "no RX DMA platform resource!\n");
630 goto out;
631 }
632 au1000->dmaid[1] = r->start;
633
634 au1000->stream[PLAYBACK] = kmalloc(sizeof(struct audio_stream),
635 GFP_KERNEL);
636 if (!au1000->stream[PLAYBACK])
637 goto out;
638 au1000->stream[PLAYBACK]->dma = -1;
639
640 au1000->stream[CAPTURE] = kmalloc(sizeof(struct audio_stream),
641 GFP_KERNEL);
642 if (!au1000->stream[CAPTURE])
643 goto out;
644 au1000->stream[CAPTURE]->dma = -1;
645
646 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
647 if (!r)
648 goto out;
649
650 err = -EBUSY;
651 au1000->ac97_res_port = request_mem_region(r->start,
652 r->end - r->start + 1, pdev->name);
653 if (!au1000->ac97_res_port) {
654 snd_printk(KERN_ERR "ALSA AC97: can't grab AC97 port\n");
655 goto out;
673 } 656 }
674 657
658 io = ioremap(r->start, r->end - r->start + 1);
659 if (!io)
660 goto out;
661
662 au1000->ac97_ioport = (struct au1000_ac97_reg *)io;
663
664 /* configure pins for AC'97
665 TODO: move to board_setup.c */
666 au_writel(au_readl(SYS_PINFUNC) & ~0x02, SYS_PINFUNC);
667
668 /* Initialise Au1000's AC'97 Control Block */
669 au1000->ac97_ioport->cntrl = AC97C_RS | AC97C_CE;
670 udelay(10);
671 au1000->ac97_ioport->cntrl = AC97C_CE;
672 udelay(10);
673
674 /* Initialise External CODEC -- cold reset */
675 au1000->ac97_ioport->config = AC97C_RESET;
676 udelay(10);
677 au1000->ac97_ioport->config = 0x0;
678 mdelay(5);
679
680 /* Initialise AC97 middle-layer */
681 err = snd_ac97_bus(au1000->card, 0, &ops, au1000, &pbus);
682 if (err < 0)
683 goto out;
684
685 memset(&ac97, 0, sizeof(ac97));
686 ac97.private_data = au1000;
687 err = snd_ac97_mixer(pbus, &ac97, &au1000->ac97);
688 if (err < 0)
689 goto out;
690
691 err = snd_au1000_pcm_new(au1000);
692 if (err < 0)
693 goto out;
694
675 strcpy(card->driver, "Au1000-AC97"); 695 strcpy(card->driver, "Au1000-AC97");
676 strcpy(card->shortname, "AMD Au1000-AC97"); 696 strcpy(card->shortname, "AMD Au1000-AC97");
677 sprintf(card->longname, "AMD Au1000--AC97 ALSA Driver"); 697 sprintf(card->longname, "AMD Au1000--AC97 ALSA Driver");
678 698
679 if ((err = snd_card_register(card)) < 0) { 699 err = snd_card_register(card);
680 snd_card_free(card); 700 if (err < 0)
681 return err; 701 goto out;
682 }
683 702
684 printk(KERN_INFO "ALSA AC97: Driver Initialized\n"); 703 printk(KERN_INFO "ALSA AC97: Driver Initialized\n");
685 au1000_card = card; 704
705 platform_set_drvdata(pdev, card);
706
686 return 0; 707 return 0;
708
709 out:
710 snd_card_free(card);
711 return err;
712}
713
714static int au1000_ac97_remove(struct platform_device *pdev)
715{
716 return snd_card_free(platform_get_drvdata(pdev));
687} 717}
688 718
689static void __exit au1000_exit(void) 719struct platform_driver au1000_ac97c_driver = {
720 .driver = {
721 .name = "au1000-ac97c",
722 .owner = THIS_MODULE,
723 },
724 .probe = au1000_ac97_probe,
725 .remove = au1000_ac97_remove,
726};
727
728static int __init au1000_ac97_load(void)
690{ 729{
691 snd_card_free(au1000_card); 730 return platform_driver_register(&au1000_ac97c_driver);
692} 731}
693 732
694module_init(au1000_init); 733static void __exit au1000_ac97_unload(void)
695module_exit(au1000_exit); 734{
735 platform_driver_unregister(&au1000_ac97c_driver);
736}
696 737
738module_init(au1000_ac97_load);
739module_exit(au1000_ac97_unload);
diff --git a/sound/mips/hal2.c b/sound/mips/hal2.c
index 2b7f6e8bdd24..23441b9e6148 100644
--- a/sound/mips/hal2.c
+++ b/sound/mips/hal2.c
@@ -880,7 +880,7 @@ static int hal2_probe(struct platform_device *pdev)
880 struct snd_hal2 *chip; 880 struct snd_hal2 *chip;
881 int err; 881 int err;
882 882
883 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 883 err = snd_card_new(&pdev->dev, index, id, THIS_MODULE, 0, &card);
884 if (err < 0) 884 if (err < 0)
885 return err; 885 return err;
886 886
@@ -889,7 +889,6 @@ static int hal2_probe(struct platform_device *pdev)
889 snd_card_free(card); 889 snd_card_free(card);
890 return err; 890 return err;
891 } 891 }
892 snd_card_set_dev(card, &pdev->dev);
893 892
894 err = hal2_pcm_create(chip); 893 err = hal2_pcm_create(chip);
895 if (err < 0) { 894 if (err < 0) {
diff --git a/sound/mips/sgio2audio.c b/sound/mips/sgio2audio.c
index cfe99ae149fe..04bb06c03ec8 100644
--- a/sound/mips/sgio2audio.c
+++ b/sound/mips/sgio2audio.c
@@ -920,7 +920,7 @@ static int snd_sgio2audio_probe(struct platform_device *pdev)
920 struct snd_sgio2audio *chip; 920 struct snd_sgio2audio *chip;
921 int err; 921 int err;
922 922
923 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 923 err = snd_card_new(&pdev->dev, index, id, THIS_MODULE, 0, &card);
924 if (err < 0) 924 if (err < 0)
925 return err; 925 return err;
926 926
@@ -929,7 +929,6 @@ static int snd_sgio2audio_probe(struct platform_device *pdev)
929 snd_card_free(card); 929 snd_card_free(card);
930 return err; 930 return err;
931 } 931 }
932 snd_card_set_dev(card, &pdev->dev);
933 932
934 err = snd_sgio2audio_new_pcm(chip); 933 err = snd_sgio2audio_new_pcm(chip);
935 if (err < 0) { 934 if (err < 0) {
diff --git a/sound/oss/pas2.h b/sound/oss/pas2.h
index fa12c55f560e..d19f757dbd79 100644
--- a/sound/oss/pas2.h
+++ b/sound/oss/pas2.h
@@ -15,3 +15,6 @@ int pas_init_mixer(void);
15/* From pas_midi.c */ 15/* From pas_midi.c */
16void pas_midi_init(void); 16void pas_midi_init(void);
17void pas_midi_interrupt(void); 17void pas_midi_interrupt(void);
18
19/* From pas2_mixer.c*/
20void mix_write(unsigned char data, int ioaddr);
diff --git a/sound/oss/pas2_card.c b/sound/oss/pas2_card.c
index 7004e24d209f..b07954a79536 100644
--- a/sound/oss/pas2_card.c
+++ b/sound/oss/pas2_card.c
@@ -74,8 +74,6 @@ static char *pas_model_names[] = {
74 * to support other than the default base address 74 * to support other than the default base address
75 */ 75 */
76 76
77extern void mix_write(unsigned char data, int ioaddr);
78
79unsigned char pas_read(int ioaddr) 77unsigned char pas_read(int ioaddr)
80{ 78{
81 return inb(ioaddr + pas_translate_code); 79 return inb(ioaddr + pas_translate_code);
diff --git a/sound/parisc/harmony.c b/sound/parisc/harmony.c
index 67f56a2cee6a..4b20be79c1dd 100644
--- a/sound/parisc/harmony.c
+++ b/sound/parisc/harmony.c
@@ -959,8 +959,6 @@ snd_harmony_create(struct snd_card *card,
959 goto free_and_ret; 959 goto free_and_ret;
960 } 960 }
961 961
962 snd_card_set_dev(card, &padev->dev);
963
964 *rchip = h; 962 *rchip = h;
965 963
966 return 0; 964 return 0;
@@ -977,7 +975,7 @@ snd_harmony_probe(struct parisc_device *padev)
977 struct snd_card *card; 975 struct snd_card *card;
978 struct snd_harmony *h; 976 struct snd_harmony *h;
979 977
980 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 978 err = snd_card_new(&padev->dev, index, id, THIS_MODULE, 0, &card);
981 if (err < 0) 979 if (err < 0)
982 return err; 980 return err;
983 981
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 8756c8e32922..0b0c0cf13f74 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -276,7 +276,7 @@ config SND_CS46XX_NEW_DSP
276 276
277config SND_CS5530 277config SND_CS5530
278 tristate "CS5530 Audio" 278 tristate "CS5530 Audio"
279 depends on ISA_DMA_API 279 depends on ISA_DMA_API && (X86_32 || COMPILE_TEST)
280 select SND_SB16_DSP 280 select SND_SB16_DSP
281 help 281 help
282 Say Y here to include support for audio on Cyrix/NatSemi CS5530 chips. 282 Say Y here to include support for audio on Cyrix/NatSemi CS5530 chips.
@@ -286,6 +286,7 @@ config SND_CS5530
286 286
287config SND_CS5535AUDIO 287config SND_CS5535AUDIO
288 tristate "CS5535/CS5536 Audio" 288 tristate "CS5535/CS5536 Audio"
289 depends on X86_32 || MIPS || COMPILE_TEST
289 select SND_PCM 290 select SND_PCM
290 select SND_AC97_CODEC 291 select SND_AC97_CODEC
291 help 292 help
@@ -578,8 +579,6 @@ config SND_FM801_TEA575X_BOOL
578 FM801 chip with a TEA5757 tuner (MediaForte SF256-PCS, SF256-PCP and 579 FM801 chip with a TEA5757 tuner (MediaForte SF256-PCS, SF256-PCP and
579 SF64-PCR) into the snd-fm801 driver. 580 SF64-PCR) into the snd-fm801 driver.
580 581
581source "sound/pci/hda/Kconfig"
582
583config SND_HDSP 582config SND_HDSP
584 tristate "RME Hammerfall DSP Audio" 583 tristate "RME Hammerfall DSP Audio"
585 select FW_LOADER 584 select FW_LOADER
@@ -796,7 +795,7 @@ config SND_RME9652
796 795
797config SND_SIS7019 796config SND_SIS7019
798 tristate "SiS 7019 Audio Accelerator" 797 tristate "SiS 7019 Audio Accelerator"
799 depends on X86 && !X86_64 798 depends on X86_32
800 select SND_AC97_CODEC 799 select SND_AC97_CODEC
801 select ZONE_DMA 800 select ZONE_DMA
802 help 801 help
@@ -889,3 +888,5 @@ config SND_YMFPCI
889 will be called snd-ymfpci. 888 will be called snd-ymfpci.
890 889
891endif # SND_PCI 890endif # SND_PCI
891
892source "sound/pci/hda/Kconfig"
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index bf578ba2677e..14ad54b7928c 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -214,6 +214,12 @@ static void update_power_regs(struct snd_ac97 *ac97);
214#define ac97_is_power_save_mode(ac97) 0 214#define ac97_is_power_save_mode(ac97) 0
215#endif 215#endif
216 216
217#define ac97_err(ac97, fmt, args...) \
218 dev_err((ac97)->bus->card->dev, fmt, ##args)
219#define ac97_warn(ac97, fmt, args...) \
220 dev_warn((ac97)->bus->card->dev, fmt, ##args)
221#define ac97_dbg(ac97, fmt, args...) \
222 dev_dbg((ac97)->bus->card->dev, fmt, ##args)
217 223
218/* 224/*
219 * I/O routines 225 * I/O routines
@@ -1673,7 +1679,7 @@ static int snd_ac97_modem_build(struct snd_card *card, struct snd_ac97 * ac97)
1673 int err, idx; 1679 int err, idx;
1674 1680
1675 /* 1681 /*
1676 printk(KERN_DEBUG "AC97_GPIO_CFG = %x\n", 1682 ac97_dbg(ac97, "AC97_GPIO_CFG = %x\n",
1677 snd_ac97_read(ac97,AC97_GPIO_CFG)); 1683 snd_ac97_read(ac97,AC97_GPIO_CFG));
1678 */ 1684 */
1679 snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH)); 1685 snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH));
@@ -1963,7 +1969,7 @@ static int snd_ac97_dev_register(struct snd_device *device)
1963 ac97->bus->card->number, ac97->num, 1969 ac97->bus->card->number, ac97->num,
1964 snd_ac97_get_short_name(ac97)); 1970 snd_ac97_get_short_name(ac97));
1965 if ((err = device_register(&ac97->dev)) < 0) { 1971 if ((err = device_register(&ac97->dev)) < 0) {
1966 snd_printk(KERN_ERR "Can't register ac97 bus\n"); 1972 ac97_err(ac97, "Can't register ac97 bus\n");
1967 ac97->dev.bus = NULL; 1973 ac97->dev.bus = NULL;
1968 return err; 1974 return err;
1969 } 1975 }
@@ -2089,7 +2095,8 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
2089 msecs_to_jiffies(500), 1); 2095 msecs_to_jiffies(500), 1);
2090 } 2096 }
2091 if (err < 0) { 2097 if (err < 0) {
2092 snd_printk(KERN_WARNING "AC'97 %d does not respond - RESET\n", ac97->num); 2098 ac97_warn(ac97, "AC'97 %d does not respond - RESET\n",
2099 ac97->num);
2093 /* proceed anyway - it's often non-critical */ 2100 /* proceed anyway - it's often non-critical */
2094 } 2101 }
2095 } 2102 }
@@ -2098,7 +2105,9 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
2098 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2); 2105 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
2099 if (! (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) && 2106 if (! (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) &&
2100 (ac97->id == 0x00000000 || ac97->id == 0xffffffff)) { 2107 (ac97->id == 0x00000000 || ac97->id == 0xffffffff)) {
2101 snd_printk(KERN_ERR "AC'97 %d access is not valid [0x%x], removing mixer.\n", ac97->num, ac97->id); 2108 ac97_err(ac97,
2109 "AC'97 %d access is not valid [0x%x], removing mixer.\n",
2110 ac97->num, ac97->id);
2102 snd_ac97_free(ac97); 2111 snd_ac97_free(ac97);
2103 return -EIO; 2112 return -EIO;
2104 } 2113 }
@@ -2131,7 +2140,9 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
2131 2140
2132 if (!ac97_is_audio(ac97) && !ac97_is_modem(ac97)) { 2141 if (!ac97_is_audio(ac97) && !ac97_is_modem(ac97)) {
2133 if (!(ac97->scaps & (AC97_SCAP_SKIP_AUDIO|AC97_SCAP_SKIP_MODEM))) 2142 if (!(ac97->scaps & (AC97_SCAP_SKIP_AUDIO|AC97_SCAP_SKIP_MODEM)))
2134 snd_printk(KERN_ERR "AC'97 %d access error (not audio or modem codec)\n", ac97->num); 2143 ac97_err(ac97,
2144 "AC'97 %d access error (not audio or modem codec)\n",
2145 ac97->num);
2135 snd_ac97_free(ac97); 2146 snd_ac97_free(ac97);
2136 return -EACCES; 2147 return -EACCES;
2137 } 2148 }
@@ -2156,7 +2167,8 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
2156 goto __ready_ok; 2167 goto __ready_ok;
2157 schedule_timeout_uninterruptible(1); 2168 schedule_timeout_uninterruptible(1);
2158 } while (time_after_eq(end_time, jiffies)); 2169 } while (time_after_eq(end_time, jiffies));
2159 snd_printk(KERN_WARNING "AC'97 %d analog subsections not ready\n", ac97->num); 2170 ac97_warn(ac97,
2171 "AC'97 %d analog subsections not ready\n", ac97->num);
2160 } 2172 }
2161 2173
2162 /* FIXME: add powerdown control */ 2174 /* FIXME: add powerdown control */
@@ -2188,7 +2200,10 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
2188 goto __ready_ok; 2200 goto __ready_ok;
2189 schedule_timeout_uninterruptible(1); 2201 schedule_timeout_uninterruptible(1);
2190 } while (time_after_eq(end_time, jiffies)); 2202 } while (time_after_eq(end_time, jiffies));
2191 snd_printk(KERN_WARNING "MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS)); 2203 ac97_warn(ac97,
2204 "MC'97 %d converters and GPIO not ready (0x%x)\n",
2205 ac97->num,
2206 snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));
2192 } 2207 }
2193 2208
2194 __ready_ok: 2209 __ready_ok:
@@ -2723,7 +2738,7 @@ static int tune_ad_sharing(struct snd_ac97 *ac97)
2723{ 2738{
2724 unsigned short scfg; 2739 unsigned short scfg;
2725 if ((ac97->id & 0xffffff00) != 0x41445300) { 2740 if ((ac97->id & 0xffffff00) != 0x41445300) {
2726 snd_printk(KERN_ERR "ac97_quirk AD_SHARING is only for AD codecs\n"); 2741 ac97_err(ac97, "ac97_quirk AD_SHARING is only for AD codecs\n");
2727 return -EINVAL; 2742 return -EINVAL;
2728 } 2743 }
2729 /* Turn on OMS bit to route microphone to back panel */ 2744 /* Turn on OMS bit to route microphone to back panel */
@@ -2739,7 +2754,8 @@ AC97_SINGLE("Jack Detect", AC97_ALC650_CLOCK, 5, 1, 0);
2739static int tune_alc_jack(struct snd_ac97 *ac97) 2754static int tune_alc_jack(struct snd_ac97 *ac97)
2740{ 2755{
2741 if ((ac97->id & 0xffffff00) != 0x414c4700) { 2756 if ((ac97->id & 0xffffff00) != 0x414c4700) {
2742 snd_printk(KERN_ERR "ac97_quirk ALC_JACK is only for Realtek codecs\n"); 2757 ac97_err(ac97,
2758 "ac97_quirk ALC_JACK is only for Realtek codecs\n");
2743 return -EINVAL; 2759 return -EINVAL;
2744 } 2760 }
2745 snd_ac97_update_bits(ac97, 0x7a, 0x20, 0x20); /* select jack detect function */ 2761 snd_ac97_update_bits(ac97, 0x7a, 0x20, 0x20); /* select jack detect function */
@@ -2899,7 +2915,8 @@ int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, cons
2899 if (override && strcmp(override, "-1") && strcmp(override, "default")) { 2915 if (override && strcmp(override, "-1") && strcmp(override, "default")) {
2900 result = apply_quirk_str(ac97, override); 2916 result = apply_quirk_str(ac97, override);
2901 if (result < 0) 2917 if (result < 0)
2902 snd_printk(KERN_ERR "applying quirk type %s failed (%d)\n", override, result); 2918 ac97_err(ac97, "applying quirk type %s failed (%d)\n",
2919 override, result);
2903 return result; 2920 return result;
2904 } 2921 }
2905 2922
@@ -2913,10 +2930,14 @@ int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, cons
2913 quirk->subdevice == (quirk->mask & ac97->subsystem_device)) { 2930 quirk->subdevice == (quirk->mask & ac97->subsystem_device)) {
2914 if (quirk->codec_id && quirk->codec_id != ac97->id) 2931 if (quirk->codec_id && quirk->codec_id != ac97->id)
2915 continue; 2932 continue;
2916 snd_printdd("ac97 quirk for %s (%04x:%04x)\n", quirk->name, ac97->subsystem_vendor, ac97->subsystem_device); 2933 ac97_dbg(ac97, "ac97 quirk for %s (%04x:%04x)\n",
2934 quirk->name, ac97->subsystem_vendor,
2935 ac97->subsystem_device);
2917 result = apply_quirk(ac97, quirk->type); 2936 result = apply_quirk(ac97, quirk->type);
2918 if (result < 0) 2937 if (result < 0)
2919 snd_printk(KERN_ERR "applying quirk type %d for %s failed (%d)\n", quirk->type, quirk->name, result); 2938 ac97_err(ac97,
2939 "applying quirk type %d for %s failed (%d)\n",
2940 quirk->type, quirk->name, result);
2920 return result; 2941 return result;
2921 } 2942 }
2922 } 2943 }
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 66a3bc95fb84..991762215417 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -3477,7 +3477,8 @@ static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
3477 3477
3478 sctl = snd_ac97_find_mixer_ctl(ac97, *s); 3478 sctl = snd_ac97_find_mixer_ctl(ac97, *s);
3479 if (!sctl) { 3479 if (!sctl) {
3480 snd_printdd("Cannot find slave %s, skipped\n", *s); 3480 dev_dbg(ac97->bus->card->dev,
3481 "Cannot find slave %s, skipped\n", *s);
3481 continue; 3482 continue;
3482 } 3483 }
3483 err = snd_ctl_add_slave(kctl, sctl); 3484 err = snd_ctl_add_slave(kctl, sctl);
diff --git a/sound/pci/ac97/ac97_pcm.c b/sound/pci/ac97/ac97_pcm.c
index eab0fc9ff2e0..d15297a68801 100644
--- a/sound/pci/ac97/ac97_pcm.c
+++ b/sound/pci/ac97/ac97_pcm.c
@@ -604,7 +604,9 @@ int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,
604 } 604 }
605 if (!ok_flag) { 605 if (!ok_flag) {
606 spin_unlock_irq(&pcm->bus->bus_lock); 606 spin_unlock_irq(&pcm->bus->bus_lock);
607 snd_printk(KERN_ERR "cannot find configuration for AC97 slot %i\n", i); 607 dev_err(bus->card->dev,
608 "cannot find configuration for AC97 slot %i\n",
609 i);
608 err = -EAGAIN; 610 err = -EAGAIN;
609 goto error; 611 goto error;
610 } 612 }
@@ -618,15 +620,20 @@ int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,
618 if (pcm->r[r].rslots[cidx] & (1 << i)) { 620 if (pcm->r[r].rslots[cidx] & (1 << i)) {
619 reg = get_slot_reg(pcm, cidx, i, r); 621 reg = get_slot_reg(pcm, cidx, i, r);
620 if (reg == 0xff) { 622 if (reg == 0xff) {
621 snd_printk(KERN_ERR "invalid AC97 slot %i?\n", i); 623 dev_err(bus->card->dev,
624 "invalid AC97 slot %i?\n", i);
622 continue; 625 continue;
623 } 626 }
624 if (reg_ok[cidx] & (1 << (reg - AC97_PCM_FRONT_DAC_RATE))) 627 if (reg_ok[cidx] & (1 << (reg - AC97_PCM_FRONT_DAC_RATE)))
625 continue; 628 continue;
626 //printk(KERN_DEBUG "setting ac97 reg 0x%x to rate %d\n", reg, rate); 629 dev_dbg(bus->card->dev,
630 "setting ac97 reg 0x%x to rate %d\n",
631 reg, rate);
627 err = snd_ac97_set_rate(pcm->r[r].codec[cidx], reg, rate); 632 err = snd_ac97_set_rate(pcm->r[r].codec[cidx], reg, rate);
628 if (err < 0) 633 if (err < 0)
629 snd_printk(KERN_ERR "error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n", cidx, reg, rate, err); 634 dev_err(bus->card->dev,
635 "error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n",
636 cidx, reg, rate, err);
630 else 637 else
631 reg_ok[cidx] |= (1 << (reg - AC97_PCM_FRONT_DAC_RATE)); 638 reg_ok[cidx] |= (1 << (reg - AC97_PCM_FRONT_DAC_RATE));
632 } 639 }
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index b680d03e2419..488f966adde3 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -77,9 +77,6 @@ MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
77#define DEVNAME "ad1889" 77#define DEVNAME "ad1889"
78#define PFX DEVNAME ": " 78#define PFX DEVNAME ": "
79 79
80/* let's use the global sound debug interfaces */
81#define ad1889_debug(fmt, arg...) snd_printd(KERN_DEBUG fmt, ## arg)
82
83/* keep track of some hw registers */ 80/* keep track of some hw registers */
84struct ad1889_register_state { 81struct ad1889_register_state {
85 u16 reg; /* reg setup */ 82 u16 reg; /* reg setup */
@@ -264,11 +261,11 @@ snd_ad1889_ac97_ready(struct snd_ad1889 *chip)
264 && --retry) 261 && --retry)
265 mdelay(1); 262 mdelay(1);
266 if (!retry) { 263 if (!retry) {
267 snd_printk(KERN_ERR PFX "[%s] Link is not ready.\n", 264 dev_err(chip->card->dev, "[%s] Link is not ready.\n",
268 __func__); 265 __func__);
269 return -EIO; 266 return -EIO;
270 } 267 }
271 ad1889_debug("[%s] ready after %d ms\n", __func__, 400 - retry); 268 dev_dbg(chip->card->dev, "[%s] ready after %d ms\n", __func__, 400 - retry);
272 269
273 return 0; 270 return 0;
274} 271}
@@ -405,9 +402,9 @@ snd_ad1889_playback_prepare(struct snd_pcm_substream *ss)
405 402
406 spin_unlock_irq(&chip->lock); 403 spin_unlock_irq(&chip->lock);
407 404
408 ad1889_debug("prepare playback: addr = 0x%x, count = %u, " 405 dev_dbg(chip->card->dev,
409 "size = %u, reg = 0x%x, rate = %u\n", chip->wave.addr, 406 "prepare playback: addr = 0x%x, count = %u, size = %u, reg = 0x%x, rate = %u\n",
410 count, size, reg, rt->rate); 407 chip->wave.addr, count, size, reg, rt->rate);
411 return 0; 408 return 0;
412} 409}
413 410
@@ -452,9 +449,9 @@ snd_ad1889_capture_prepare(struct snd_pcm_substream *ss)
452 449
453 spin_unlock_irq(&chip->lock); 450 spin_unlock_irq(&chip->lock);
454 451
455 ad1889_debug("prepare capture: addr = 0x%x, count = %u, " 452 dev_dbg(chip->card->dev,
456 "size = %u, reg = 0x%x, rate = %u\n", chip->ramc.addr, 453 "prepare capture: addr = 0x%x, count = %u, size = %u, reg = 0x%x, rate = %u\n",
457 count, size, reg, rt->rate); 454 chip->ramc.addr, count, size, reg, rt->rate);
458 return 0; 455 return 0;
459} 456}
460 457
@@ -614,7 +611,8 @@ snd_ad1889_interrupt(int irq, void *dev_id)
614 return IRQ_NONE; 611 return IRQ_NONE;
615 612
616 if (st & (AD_DMA_DISR_PMAI|AD_DMA_DISR_PTAI)) 613 if (st & (AD_DMA_DISR_PMAI|AD_DMA_DISR_PTAI))
617 ad1889_debug("Unexpected master or target abort interrupt!\n"); 614 dev_dbg(chip->card->dev,
615 "Unexpected master or target abort interrupt!\n");
618 616
619 if ((st & AD_DMA_DISR_WAVI) && chip->psubs) 617 if ((st & AD_DMA_DISR_WAVI) && chip->psubs)
620 snd_pcm_period_elapsed(chip->psubs); 618 snd_pcm_period_elapsed(chip->psubs);
@@ -656,7 +654,7 @@ snd_ad1889_pcm_init(struct snd_ad1889 *chip, int device, struct snd_pcm **rpcm)
656 BUFFER_BYTES_MAX); 654 BUFFER_BYTES_MAX);
657 655
658 if (err < 0) { 656 if (err < 0) {
659 snd_printk(KERN_ERR PFX "buffer allocation error: %d\n", err); 657 dev_err(chip->card->dev, "buffer allocation error: %d\n", err);
660 return err; 658 return err;
661 } 659 }
662 660
@@ -912,7 +910,7 @@ snd_ad1889_create(struct snd_card *card,
912 /* check PCI availability (32bit DMA) */ 910 /* check PCI availability (32bit DMA) */
913 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 || 911 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 ||
914 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { 912 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) {
915 printk(KERN_ERR PFX "error setting 32-bit DMA mask.\n"); 913 dev_err(card->dev, "error setting 32-bit DMA mask.\n");
916 pci_disable_device(pci); 914 pci_disable_device(pci);
917 return -ENXIO; 915 return -ENXIO;
918 } 916 }
@@ -935,7 +933,7 @@ snd_ad1889_create(struct snd_card *card,
935 chip->bar = pci_resource_start(pci, 0); 933 chip->bar = pci_resource_start(pci, 0);
936 chip->iobase = pci_ioremap_bar(pci, 0); 934 chip->iobase = pci_ioremap_bar(pci, 0);
937 if (chip->iobase == NULL) { 935 if (chip->iobase == NULL) {
938 printk(KERN_ERR PFX "unable to reserve region.\n"); 936 dev_err(card->dev, "unable to reserve region.\n");
939 err = -EBUSY; 937 err = -EBUSY;
940 goto free_and_ret; 938 goto free_and_ret;
941 } 939 }
@@ -946,7 +944,7 @@ snd_ad1889_create(struct snd_card *card,
946 944
947 if (request_irq(pci->irq, snd_ad1889_interrupt, 945 if (request_irq(pci->irq, snd_ad1889_interrupt,
948 IRQF_SHARED, KBUILD_MODNAME, chip)) { 946 IRQF_SHARED, KBUILD_MODNAME, chip)) {
949 printk(KERN_ERR PFX "cannot obtain IRQ %d\n", pci->irq); 947 dev_err(card->dev, "cannot obtain IRQ %d\n", pci->irq);
950 snd_ad1889_free(chip); 948 snd_ad1889_free(chip);
951 return -EBUSY; 949 return -EBUSY;
952 } 950 }
@@ -965,8 +963,6 @@ snd_ad1889_create(struct snd_card *card,
965 return err; 963 return err;
966 } 964 }
967 965
968 snd_card_set_dev(card, &pci->dev);
969
970 *rchip = chip; 966 *rchip = chip;
971 967
972 return 0; 968 return 0;
@@ -996,7 +992,8 @@ snd_ad1889_probe(struct pci_dev *pci,
996 } 992 }
997 993
998 /* (2) */ 994 /* (2) */
999 err = snd_card_create(index[devno], id[devno], THIS_MODULE, 0, &card); 995 err = snd_card_new(&pci->dev, index[devno], id[devno], THIS_MODULE,
996 0, &card);
1000 /* XXX REVISIT: we can probably allocate chip in this call */ 997 /* XXX REVISIT: we can probably allocate chip in this call */
1001 if (err < 0) 998 if (err < 0)
1002 return err; 999 return err;
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index c6835a3d64fb..feb29c24cab1 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -65,18 +65,6 @@ module_param(enable, bool, 0444);
65 65
66 66
67/* 67/*
68 * Debug part definitions
69 */
70
71/* #define ALI_DEBUG */
72
73#ifdef ALI_DEBUG
74#define snd_ali_printk(format, args...) printk(KERN_DEBUG format, ##args);
75#else
76#define snd_ali_printk(format, args...)
77#endif
78
79/*
80 * Constants definition 68 * Constants definition
81 */ 69 */
82 70
@@ -321,7 +309,7 @@ static int snd_ali_codec_ready(struct snd_ali *codec,
321 } 309 }
322 310
323 snd_ali_5451_poke(codec, port, res & ~0x8000); 311 snd_ali_5451_poke(codec, port, res & ~0x8000);
324 snd_printdd("ali_codec_ready: codec is not ready.\n "); 312 dev_dbg(codec->card->dev, "ali_codec_ready: codec is not ready.\n ");
325 return -EIO; 313 return -EIO;
326} 314}
327 315
@@ -342,7 +330,7 @@ static int snd_ali_stimer_ready(struct snd_ali *codec)
342 schedule_timeout_uninterruptible(1); 330 schedule_timeout_uninterruptible(1);
343 } 331 }
344 332
345 snd_printk(KERN_ERR "ali_stimer_read: stimer is not ready.\n"); 333 dev_err(codec->card->dev, "ali_stimer_read: stimer is not ready.\n");
346 return -EIO; 334 return -EIO;
347} 335}
348 336
@@ -354,7 +342,8 @@ static void snd_ali_codec_poke(struct snd_ali *codec,int secondary,
354 unsigned int port; 342 unsigned int port;
355 343
356 if (reg >= 0x80) { 344 if (reg >= 0x80) {
357 snd_printk(KERN_ERR "ali_codec_poke: reg(%xh) invalid.\n", reg); 345 dev_err(codec->card->dev,
346 "ali_codec_poke: reg(%xh) invalid.\n", reg);
358 return; 347 return;
359 } 348 }
360 349
@@ -385,7 +374,8 @@ static unsigned short snd_ali_codec_peek(struct snd_ali *codec,
385 unsigned int port; 374 unsigned int port;
386 375
387 if (reg >= 0x80) { 376 if (reg >= 0x80) {
388 snd_printk(KERN_ERR "ali_codec_peek: reg(%xh) invalid.\n", reg); 377 dev_err(codec->card->dev,
378 "ali_codec_peek: reg(%xh) invalid.\n", reg);
389 return ~0; 379 return ~0;
390 } 380 }
391 381
@@ -417,7 +407,7 @@ static void snd_ali_codec_write(struct snd_ac97 *ac97,
417{ 407{
418 struct snd_ali *codec = ac97->private_data; 408 struct snd_ali *codec = ac97->private_data;
419 409
420 snd_ali_printk("codec_write: reg=%xh data=%xh.\n", reg, val); 410 dev_dbg(codec->card->dev, "codec_write: reg=%xh data=%xh.\n", reg, val);
421 if (reg == AC97_GPIO_STATUS) { 411 if (reg == AC97_GPIO_STATUS) {
422 outl((val << ALI_AC97_GPIO_DATA_SHIFT) | ALI_AC97_GPIO_ENABLE, 412 outl((val << ALI_AC97_GPIO_DATA_SHIFT) | ALI_AC97_GPIO_ENABLE,
423 ALI_REG(codec, ALI_AC97_GPIO)); 413 ALI_REG(codec, ALI_AC97_GPIO));
@@ -433,7 +423,7 @@ static unsigned short snd_ali_codec_read(struct snd_ac97 *ac97,
433{ 423{
434 struct snd_ali *codec = ac97->private_data; 424 struct snd_ali *codec = ac97->private_data;
435 425
436 snd_ali_printk("codec_read reg=%xh.\n", reg); 426 dev_dbg(codec->card->dev, "codec_read reg=%xh.\n", reg);
437 return snd_ali_codec_peek(codec, ac97->num, reg); 427 return snd_ali_codec_peek(codec, ac97->num, reg);
438} 428}
439 429
@@ -474,7 +464,7 @@ static int snd_ali_reset_5451(struct snd_ali *codec)
474 } 464 }
475 465
476 /* non-fatal if you have a non PM capable codec */ 466 /* non-fatal if you have a non PM capable codec */
477 /* snd_printk(KERN_WARNING "ali5451: reset time out\n"); */ 467 /* dev_warn(codec->card->dev, "ali5451: reset time out\n"); */
478 return 0; 468 return 0;
479} 469}
480 470
@@ -528,7 +518,7 @@ static void snd_ali_disable_voice_irq(struct snd_ali *codec,
528 unsigned int mask; 518 unsigned int mask;
529 struct snd_ali_channel_control *pchregs = &(codec->chregs); 519 struct snd_ali_channel_control *pchregs = &(codec->chregs);
530 520
531 snd_ali_printk("disable_voice_irq channel=%d\n",channel); 521 dev_dbg(codec->card->dev, "disable_voice_irq channel=%d\n", channel);
532 522
533 mask = 1 << (channel & 0x1f); 523 mask = 1 << (channel & 0x1f);
534 pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten)); 524 pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten));
@@ -541,7 +531,7 @@ static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel)
541 unsigned int idx = channel & 0x1f; 531 unsigned int idx = channel & 0x1f;
542 532
543 if (codec->synth.chcnt >= ALI_CHANNELS){ 533 if (codec->synth.chcnt >= ALI_CHANNELS){
544 snd_printk(KERN_ERR 534 dev_err(codec->card->dev,
545 "ali_alloc_pcm_channel: no free channels.\n"); 535 "ali_alloc_pcm_channel: no free channels.\n");
546 return -1; 536 return -1;
547 } 537 }
@@ -549,7 +539,7 @@ static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel)
549 if (!(codec->synth.chmap & (1 << idx))) { 539 if (!(codec->synth.chmap & (1 << idx))) {
550 codec->synth.chmap |= 1 << idx; 540 codec->synth.chmap |= 1 << idx;
551 codec->synth.chcnt++; 541 codec->synth.chcnt++;
552 snd_ali_printk("alloc_pcm_channel no. %d.\n",idx); 542 dev_dbg(codec->card->dev, "alloc_pcm_channel no. %d.\n", idx);
553 return idx; 543 return idx;
554 } 544 }
555 return -1; 545 return -1;
@@ -560,7 +550,8 @@ static int snd_ali_find_free_channel(struct snd_ali * codec, int rec)
560 int idx; 550 int idx;
561 int result = -1; 551 int result = -1;
562 552
563 snd_ali_printk("find_free_channel: for %s\n",rec ? "rec" : "pcm"); 553 dev_dbg(codec->card->dev,
554 "find_free_channel: for %s\n", rec ? "rec" : "pcm");
564 555
565 /* recording */ 556 /* recording */
566 if (rec) { 557 if (rec) {
@@ -575,8 +566,8 @@ static int snd_ali_find_free_channel(struct snd_ali * codec, int rec)
575 if (result >= 0) 566 if (result >= 0)
576 return result; 567 return result;
577 else { 568 else {
578 snd_printk(KERN_ERR "ali_find_free_channel: " 569 dev_err(codec->card->dev,
579 "record channel is busy now.\n"); 570 "ali_find_free_channel: record channel is busy now.\n");
580 return -1; 571 return -1;
581 } 572 }
582 } 573 }
@@ -590,8 +581,8 @@ static int snd_ali_find_free_channel(struct snd_ali * codec, int rec)
590 if (result >= 0) 581 if (result >= 0)
591 return result; 582 return result;
592 else 583 else
593 snd_printk(KERN_ERR "ali_find_free_channel: " 584 dev_err(codec->card->dev,
594 "S/PDIF out channel is in busy now.\n"); 585 "ali_find_free_channel: S/PDIF out channel is in busy now.\n");
595 } 586 }
596 587
597 for (idx = 0; idx < ALI_CHANNELS; idx++) { 588 for (idx = 0; idx < ALI_CHANNELS; idx++) {
@@ -599,7 +590,7 @@ static int snd_ali_find_free_channel(struct snd_ali * codec, int rec)
599 if (result >= 0) 590 if (result >= 0)
600 return result; 591 return result;
601 } 592 }
602 snd_printk(KERN_ERR "ali_find_free_channel: no free channels.\n"); 593 dev_err(codec->card->dev, "ali_find_free_channel: no free channels.\n");
603 return -1; 594 return -1;
604} 595}
605 596
@@ -607,14 +598,15 @@ static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel)
607{ 598{
608 unsigned int idx = channel & 0x0000001f; 599 unsigned int idx = channel & 0x0000001f;
609 600
610 snd_ali_printk("free_channel_pcm channel=%d\n",channel); 601 dev_dbg(codec->card->dev, "free_channel_pcm channel=%d\n", channel);
611 602
612 if (channel < 0 || channel >= ALI_CHANNELS) 603 if (channel < 0 || channel >= ALI_CHANNELS)
613 return; 604 return;
614 605
615 if (!(codec->synth.chmap & (1 << idx))) { 606 if (!(codec->synth.chmap & (1 << idx))) {
616 snd_printk(KERN_ERR "ali_free_channel_pcm: " 607 dev_err(codec->card->dev,
617 "channel %d is not in use.\n", channel); 608 "ali_free_channel_pcm: channel %d is not in use.\n",
609 channel);
618 return; 610 return;
619 } else { 611 } else {
620 codec->synth.chmap &= ~(1 << idx); 612 codec->synth.chmap &= ~(1 << idx);
@@ -626,7 +618,7 @@ static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel)
626{ 618{
627 unsigned int mask = 1 << (channel & 0x1f); 619 unsigned int mask = 1 << (channel & 0x1f);
628 620
629 snd_ali_printk("stop_voice: channel=%d\n",channel); 621 dev_dbg(codec->card->dev, "stop_voice: channel=%d\n", channel);
630 outl(mask, ALI_REG(codec, codec->chregs.regs.stop)); 622 outl(mask, ALI_REG(codec, codec->chregs.regs.stop));
631} 623}
632 624
@@ -667,7 +659,7 @@ static void snd_ali_detect_spdif_rate(struct snd_ali *codec)
667 } 659 }
668 660
669 if (count > 50000) { 661 if (count > 50000) {
670 snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n"); 662 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n");
671 return; 663 return;
672 } 664 }
673 665
@@ -682,7 +674,7 @@ static void snd_ali_detect_spdif_rate(struct snd_ali *codec)
682 } 674 }
683 675
684 if (count > 50000) { 676 if (count > 50000) {
685 snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n"); 677 dev_err(codec->card->dev, "ali_detect_spdif_rate: timeout!\n");
686 return; 678 return;
687 } 679 }
688 680
@@ -857,9 +849,6 @@ static void snd_ali_update_ptr(struct snd_ali *codec, int channel)
857 struct snd_ali_voice *pvoice; 849 struct snd_ali_voice *pvoice;
858 struct snd_ali_channel_control *pchregs; 850 struct snd_ali_channel_control *pchregs;
859 unsigned int old, mask; 851 unsigned int old, mask;
860#ifdef ALI_DEBUG
861 unsigned int temp, cspf;
862#endif
863 852
864 pchregs = &(codec->chregs); 853 pchregs = &(codec->chregs);
865 854
@@ -877,14 +866,11 @@ static void snd_ali_update_ptr(struct snd_ali *codec, int channel)
877 866
878 if (pvoice->pcm && pvoice->substream) { 867 if (pvoice->pcm && pvoice->substream) {
879 /* pcm interrupt */ 868 /* pcm interrupt */
880#ifdef ALI_DEBUG
881 outb((u8)(pvoice->number), ALI_REG(codec, ALI_GC_CIR));
882 temp = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2));
883 cspf = (inl(ALI_REG(codec, ALI_CSPF)) & mask) == mask;
884#endif
885 if (pvoice->running) { 869 if (pvoice->running) {
886 snd_ali_printk("update_ptr: cso=%4.4x cspf=%d.\n", 870 dev_dbg(codec->card->dev,
887 (u16)temp, cspf); 871 "update_ptr: cso=%4.4x cspf=%d.\n",
872 inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)),
873 (inl(ALI_REG(codec, ALI_CSPF)) & mask) == mask);
888 spin_unlock(&codec->reg_lock); 874 spin_unlock(&codec->reg_lock);
889 snd_pcm_period_elapsed(pvoice->substream); 875 snd_pcm_period_elapsed(pvoice->substream);
890 spin_lock(&codec->reg_lock); 876 spin_lock(&codec->reg_lock);
@@ -940,14 +926,14 @@ static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec,
940 struct snd_ali_voice *pvoice; 926 struct snd_ali_voice *pvoice;
941 int idx; 927 int idx;
942 928
943 snd_ali_printk("alloc_voice: type=%d rec=%d\n", type, rec); 929 dev_dbg(codec->card->dev, "alloc_voice: type=%d rec=%d\n", type, rec);
944 930
945 spin_lock_irq(&codec->voice_alloc); 931 spin_lock_irq(&codec->voice_alloc);
946 if (type == SNDRV_ALI_VOICE_TYPE_PCM) { 932 if (type == SNDRV_ALI_VOICE_TYPE_PCM) {
947 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) : 933 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) :
948 snd_ali_find_free_channel(codec,rec); 934 snd_ali_find_free_channel(codec,rec);
949 if (idx < 0) { 935 if (idx < 0) {
950 snd_printk(KERN_ERR "ali_alloc_voice: err.\n"); 936 dev_err(codec->card->dev, "ali_alloc_voice: err.\n");
951 spin_unlock_irq(&codec->voice_alloc); 937 spin_unlock_irq(&codec->voice_alloc);
952 return NULL; 938 return NULL;
953 } 939 }
@@ -970,7 +956,7 @@ static void snd_ali_free_voice(struct snd_ali * codec,
970 void (*private_free)(void *); 956 void (*private_free)(void *);
971 void *private_data; 957 void *private_data;
972 958
973 snd_ali_printk("free_voice: channel=%d\n",pvoice->number); 959 dev_dbg(codec->card->dev, "free_voice: channel=%d\n", pvoice->number);
974 if (!pvoice->use) 960 if (!pvoice->use)
975 return; 961 return;
976 snd_ali_clear_voices(codec, pvoice->number, pvoice->number); 962 snd_ali_clear_voices(codec, pvoice->number, pvoice->number);
@@ -1153,7 +1139,7 @@ static int snd_ali_trigger(struct snd_pcm_substream *substream,
1153 outl(val, ALI_REG(codec, ALI_AINTEN)); 1139 outl(val, ALI_REG(codec, ALI_AINTEN));
1154 if (do_start) 1140 if (do_start)
1155 outl(what, ALI_REG(codec, ALI_START)); 1141 outl(what, ALI_REG(codec, ALI_START));
1156 snd_ali_printk("trigger: what=%xh whati=%xh\n", what, whati); 1142 dev_dbg(codec->card->dev, "trigger: what=%xh whati=%xh\n", what, whati);
1157 spin_unlock(&codec->reg_lock); 1143 spin_unlock(&codec->reg_lock);
1158 1144
1159 return 0; 1145 return 0;
@@ -1239,7 +1225,7 @@ static int snd_ali_playback_prepare(struct snd_pcm_substream *substream)
1239 unsigned int VOL; 1225 unsigned int VOL;
1240 unsigned int EC; 1226 unsigned int EC;
1241 1227
1242 snd_ali_printk("playback_prepare ...\n"); 1228 dev_dbg(codec->card->dev, "playback_prepare ...\n");
1243 1229
1244 spin_lock_irq(&codec->reg_lock); 1230 spin_lock_irq(&codec->reg_lock);
1245 1231
@@ -1266,7 +1252,7 @@ static int snd_ali_playback_prepare(struct snd_pcm_substream *substream)
1266 /* set target ESO for channel */ 1252 /* set target ESO for channel */
1267 pvoice->eso = runtime->buffer_size; 1253 pvoice->eso = runtime->buffer_size;
1268 1254
1269 snd_ali_printk("playback_prepare: eso=%xh count=%xh\n", 1255 dev_dbg(codec->card->dev, "playback_prepare: eso=%xh count=%xh\n",
1270 pvoice->eso, pvoice->count); 1256 pvoice->eso, pvoice->count);
1271 1257
1272 /* set ESO to capture first MIDLP interrupt */ 1258 /* set ESO to capture first MIDLP interrupt */
@@ -1278,8 +1264,9 @@ static int snd_ali_playback_prepare(struct snd_pcm_substream *substream)
1278 PAN = 0; 1264 PAN = 0;
1279 VOL = 0; 1265 VOL = 0;
1280 EC = 0; 1266 EC = 0;
1281 snd_ali_printk("playback_prepare:\n"); 1267 dev_dbg(codec->card->dev, "playback_prepare:\n");
1282 snd_ali_printk("ch=%d, Rate=%d Delta=%xh,GVSEL=%xh,PAN=%xh,CTRL=%xh\n", 1268 dev_dbg(codec->card->dev,
1269 "ch=%d, Rate=%d Delta=%xh,GVSEL=%xh,PAN=%xh,CTRL=%xh\n",
1283 pvoice->number,runtime->rate,Delta,GVSEL,PAN,CTRL); 1270 pvoice->number,runtime->rate,Delta,GVSEL,PAN,CTRL);
1284 snd_ali_write_voice_regs(codec, 1271 snd_ali_write_voice_regs(codec,
1285 pvoice->number, 1272 pvoice->number,
@@ -1332,7 +1319,7 @@ static int snd_ali_prepare(struct snd_pcm_substream *substream)
1332 1319
1333 spin_lock_irq(&codec->reg_lock); 1320 spin_lock_irq(&codec->reg_lock);
1334 1321
1335 snd_ali_printk("ali_prepare...\n"); 1322 dev_dbg(codec->card->dev, "ali_prepare...\n");
1336 1323
1337 snd_ali_enable_special_channel(codec,pvoice->number); 1324 snd_ali_enable_special_channel(codec,pvoice->number);
1338 1325
@@ -1351,15 +1338,16 @@ static int snd_ali_prepare(struct snd_pcm_substream *substream)
1351 1338
1352 rate = snd_ali_get_spdif_in_rate(codec); 1339 rate = snd_ali_get_spdif_in_rate(codec);
1353 if (rate == 0) { 1340 if (rate == 0) {
1354 snd_printk(KERN_WARNING "ali_capture_preapre: " 1341 dev_warn(codec->card->dev,
1355 "spdif rate detect err!\n"); 1342 "ali_capture_preapre: spdif rate detect err!\n");
1356 rate = 48000; 1343 rate = 48000;
1357 } 1344 }
1358 spin_lock_irq(&codec->reg_lock); 1345 spin_lock_irq(&codec->reg_lock);
1359 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL)); 1346 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL));
1360 if (bValue & 0x10) { 1347 if (bValue & 0x10) {
1361 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL)); 1348 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL));
1362 printk(KERN_WARNING "clear SPDIF parity error flag.\n"); 1349 dev_warn(codec->card->dev,
1350 "clear SPDIF parity error flag.\n");
1363 } 1351 }
1364 1352
1365 if (rate != 48000) 1353 if (rate != 48000)
@@ -1418,7 +1406,7 @@ snd_ali_playback_pointer(struct snd_pcm_substream *substream)
1418 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); 1406 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR));
1419 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); 1407 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2));
1420 spin_unlock(&codec->reg_lock); 1408 spin_unlock(&codec->reg_lock);
1421 snd_ali_printk("playback pointer returned cso=%xh.\n", cso); 1409 dev_dbg(codec->card->dev, "playback pointer returned cso=%xh.\n", cso);
1422 1410
1423 return cso; 1411 return cso;
1424} 1412}
@@ -1685,7 +1673,8 @@ static int snd_ali_pcm(struct snd_ali *codec, int device,
1685 err = snd_pcm_new(codec->card, desc->name, device, 1673 err = snd_pcm_new(codec->card, desc->name, device,
1686 desc->playback_num, desc->capture_num, &pcm); 1674 desc->playback_num, desc->capture_num, &pcm);
1687 if (err < 0) { 1675 if (err < 0) {
1688 snd_printk(KERN_ERR "snd_ali_pcm: err called snd_pcm_new.\n"); 1676 dev_err(codec->card->dev,
1677 "snd_ali_pcm: err called snd_pcm_new.\n");
1689 return err; 1678 return err;
1690 } 1679 }
1691 pcm->private_data = codec; 1680 pcm->private_data = codec;
@@ -1861,7 +1850,7 @@ static int snd_ali_mixer(struct snd_ali *codec)
1861 ac97.num = i; 1850 ac97.num = i;
1862 err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i]); 1851 err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i]);
1863 if (err < 0) { 1852 if (err < 0) {
1864 snd_printk(KERN_ERR 1853 dev_err(codec->card->dev,
1865 "ali mixer %d creating error.\n", i); 1854 "ali mixer %d creating error.\n", i);
1866 if (i == 0) 1855 if (i == 0)
1867 return err; 1856 return err;
@@ -1947,8 +1936,7 @@ static int ali_resume(struct device *dev)
1947 pci_set_power_state(pci, PCI_D0); 1936 pci_set_power_state(pci, PCI_D0);
1948 pci_restore_state(pci); 1937 pci_restore_state(pci);
1949 if (pci_enable_device(pci) < 0) { 1938 if (pci_enable_device(pci) < 0) {
1950 printk(KERN_ERR "ali5451: pci_enable_device failed, " 1939 dev_err(dev, "pci_enable_device failed, disabling device\n");
1951 "disabling device\n");
1952 snd_card_disconnect(card); 1940 snd_card_disconnect(card);
1953 return -EIO; 1941 return -EIO;
1954 } 1942 }
@@ -2013,10 +2001,10 @@ static int snd_ali_chip_init(struct snd_ali *codec)
2013 unsigned char temp; 2001 unsigned char temp;
2014 struct pci_dev *pci_dev; 2002 struct pci_dev *pci_dev;
2015 2003
2016 snd_ali_printk("chip initializing ... \n"); 2004 dev_dbg(codec->card->dev, "chip initializing ...\n");
2017 2005
2018 if (snd_ali_reset_5451(codec)) { 2006 if (snd_ali_reset_5451(codec)) {
2019 snd_printk(KERN_ERR "ali_chip_init: reset 5451 error.\n"); 2007 dev_err(codec->card->dev, "ali_chip_init: reset 5451 error.\n");
2020 return -1; 2008 return -1;
2021 } 2009 }
2022 2010
@@ -2062,7 +2050,7 @@ static int snd_ali_chip_init(struct snd_ali *codec)
2062 ALI_REG(codec, ALI_SCTRL)); 2050 ALI_REG(codec, ALI_SCTRL));
2063 } 2051 }
2064 2052
2065 snd_ali_printk("chip initialize succeed.\n"); 2053 dev_dbg(codec->card->dev, "chip initialize succeed.\n");
2066 return 0; 2054 return 0;
2067 2055
2068} 2056}
@@ -2088,7 +2076,7 @@ static int snd_ali_resources(struct snd_ali *codec)
2088{ 2076{
2089 int err; 2077 int err;
2090 2078
2091 snd_ali_printk("resources allocation ...\n"); 2079 dev_dbg(codec->card->dev, "resources allocation ...\n");
2092 err = pci_request_regions(codec->pci, "ALI 5451"); 2080 err = pci_request_regions(codec->pci, "ALI 5451");
2093 if (err < 0) 2081 if (err < 0)
2094 return err; 2082 return err;
@@ -2096,11 +2084,11 @@ static int snd_ali_resources(struct snd_ali *codec)
2096 2084
2097 if (request_irq(codec->pci->irq, snd_ali_card_interrupt, 2085 if (request_irq(codec->pci->irq, snd_ali_card_interrupt,
2098 IRQF_SHARED, KBUILD_MODNAME, codec)) { 2086 IRQF_SHARED, KBUILD_MODNAME, codec)) {
2099 snd_printk(KERN_ERR "Unable to request irq.\n"); 2087 dev_err(codec->card->dev, "Unable to request irq.\n");
2100 return -EBUSY; 2088 return -EBUSY;
2101 } 2089 }
2102 codec->irq = codec->pci->irq; 2090 codec->irq = codec->pci->irq;
2103 snd_ali_printk("resources allocated.\n"); 2091 dev_dbg(codec->card->dev, "resources allocated.\n");
2104 return 0; 2092 return 0;
2105} 2093}
2106static int snd_ali_dev_free(struct snd_device *device) 2094static int snd_ali_dev_free(struct snd_device *device)
@@ -2125,7 +2113,7 @@ static int snd_ali_create(struct snd_card *card,
2125 2113
2126 *r_ali = NULL; 2114 *r_ali = NULL;
2127 2115
2128 snd_ali_printk("creating ...\n"); 2116 dev_dbg(card->dev, "creating ...\n");
2129 2117
2130 /* enable PCI device */ 2118 /* enable PCI device */
2131 err = pci_enable_device(pci); 2119 err = pci_enable_device(pci);
@@ -2134,8 +2122,8 @@ static int snd_ali_create(struct snd_card *card,
2134 /* check, if we can restrict PCI DMA transfers to 31 bits */ 2122 /* check, if we can restrict PCI DMA transfers to 31 bits */
2135 if (pci_set_dma_mask(pci, DMA_BIT_MASK(31)) < 0 || 2123 if (pci_set_dma_mask(pci, DMA_BIT_MASK(31)) < 0 ||
2136 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(31)) < 0) { 2124 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(31)) < 0) {
2137 snd_printk(KERN_ERR "architecture does not support " 2125 dev_err(card->dev,
2138 "31bit PCI busmaster DMA\n"); 2126 "architecture does not support 31bit PCI busmaster DMA\n");
2139 pci_disable_device(pci); 2127 pci_disable_device(pci);
2140 return -ENXIO; 2128 return -ENXIO;
2141 } 2129 }
@@ -2199,48 +2187,46 @@ static int snd_ali_create(struct snd_card *card,
2199 /* M1533: southbridge */ 2187 /* M1533: southbridge */
2200 codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL); 2188 codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL);
2201 if (!codec->pci_m1533) { 2189 if (!codec->pci_m1533) {
2202 snd_printk(KERN_ERR "ali5451: cannot find ALi 1533 chip.\n"); 2190 dev_err(card->dev, "cannot find ALi 1533 chip.\n");
2203 snd_ali_free(codec); 2191 snd_ali_free(codec);
2204 return -ENODEV; 2192 return -ENODEV;
2205 } 2193 }
2206 /* M7101: power management */ 2194 /* M7101: power management */
2207 codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL); 2195 codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL);
2208 if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) { 2196 if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) {
2209 snd_printk(KERN_ERR "ali5451: cannot find ALi 7101 chip.\n"); 2197 dev_err(card->dev, "cannot find ALi 7101 chip.\n");
2210 snd_ali_free(codec); 2198 snd_ali_free(codec);
2211 return -ENODEV; 2199 return -ENODEV;
2212 } 2200 }
2213 2201
2214 snd_ali_printk("snd_device_new is called.\n"); 2202 dev_dbg(card->dev, "snd_device_new is called.\n");
2215 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops); 2203 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops);
2216 if (err < 0) { 2204 if (err < 0) {
2217 snd_ali_free(codec); 2205 snd_ali_free(codec);
2218 return err; 2206 return err;
2219 } 2207 }
2220 2208
2221 snd_card_set_dev(card, &pci->dev);
2222
2223 /* initialise synth voices*/ 2209 /* initialise synth voices*/
2224 for (i = 0; i < ALI_CHANNELS; i++) 2210 for (i = 0; i < ALI_CHANNELS; i++)
2225 codec->synth.voices[i].number = i; 2211 codec->synth.voices[i].number = i;
2226 2212
2227 err = snd_ali_chip_init(codec); 2213 err = snd_ali_chip_init(codec);
2228 if (err < 0) { 2214 if (err < 0) {
2229 snd_printk(KERN_ERR "ali create: chip init error.\n"); 2215 dev_err(card->dev, "ali create: chip init error.\n");
2230 return err; 2216 return err;
2231 } 2217 }
2232 2218
2233#ifdef CONFIG_PM_SLEEP 2219#ifdef CONFIG_PM_SLEEP
2234 codec->image = kmalloc(sizeof(*codec->image), GFP_KERNEL); 2220 codec->image = kmalloc(sizeof(*codec->image), GFP_KERNEL);
2235 if (!codec->image) 2221 if (!codec->image)
2236 snd_printk(KERN_WARNING "can't allocate apm buffer\n"); 2222 dev_warn(card->dev, "can't allocate apm buffer\n");
2237#endif 2223#endif
2238 2224
2239 snd_ali_enable_address_interrupt(codec); 2225 snd_ali_enable_address_interrupt(codec);
2240 codec->hw_initialized = 1; 2226 codec->hw_initialized = 1;
2241 2227
2242 *r_ali = codec; 2228 *r_ali = codec;
2243 snd_ali_printk("created.\n"); 2229 dev_dbg(card->dev, "created.\n");
2244 return 0; 2230 return 0;
2245} 2231}
2246 2232
@@ -2251,9 +2237,9 @@ static int snd_ali_probe(struct pci_dev *pci,
2251 struct snd_ali *codec; 2237 struct snd_ali *codec;
2252 int err; 2238 int err;
2253 2239
2254 snd_ali_printk("probe ...\n"); 2240 dev_dbg(&pci->dev, "probe ...\n");
2255 2241
2256 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 2242 err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
2257 if (err < 0) 2243 if (err < 0)
2258 return err; 2244 return err;
2259 2245
@@ -2262,12 +2248,12 @@ static int snd_ali_probe(struct pci_dev *pci,
2262 goto error; 2248 goto error;
2263 card->private_data = codec; 2249 card->private_data = codec;
2264 2250
2265 snd_ali_printk("mixer building ...\n"); 2251 dev_dbg(&pci->dev, "mixer building ...\n");
2266 err = snd_ali_mixer(codec); 2252 err = snd_ali_mixer(codec);
2267 if (err < 0) 2253 if (err < 0)
2268 goto error; 2254 goto error;
2269 2255
2270 snd_ali_printk("pcm building ...\n"); 2256 dev_dbg(&pci->dev, "pcm building ...\n");
2271 err = snd_ali_build_pcms(codec); 2257 err = snd_ali_build_pcms(codec);
2272 if (err < 0) 2258 if (err < 0)
2273 goto error; 2259 goto error;
@@ -2280,7 +2266,7 @@ static int snd_ali_probe(struct pci_dev *pci,
2280 sprintf(card->longname, "%s at 0x%lx, irq %i", 2266 sprintf(card->longname, "%s at 0x%lx, irq %i",
2281 card->shortname, codec->port, codec->irq); 2267 card->shortname, codec->port, codec->irq);
2282 2268
2283 snd_ali_printk("register card.\n"); 2269 dev_dbg(&pci->dev, "register card.\n");
2284 err = snd_card_register(card); 2270 err = snd_card_register(card);
2285 if (err < 0) 2271 if (err < 0)
2286 goto error; 2272 goto error;
diff --git a/sound/pci/als300.c b/sound/pci/als300.c
index 591efb6eef05..cc9a15a1304b 100644
--- a/sound/pci/als300.c
+++ b/sound/pci/als300.c
@@ -87,19 +87,8 @@
87#define PLAYBACK_BLOCK_COUNTER 0x9A 87#define PLAYBACK_BLOCK_COUNTER 0x9A
88#define RECORD_BLOCK_COUNTER 0x9B 88#define RECORD_BLOCK_COUNTER 0x9B
89 89
90#define DEBUG_CALLS 0
91#define DEBUG_PLAY_REC 0 90#define DEBUG_PLAY_REC 0
92 91
93#if DEBUG_CALLS
94#define snd_als300_dbgcalls(format, args...) printk(KERN_DEBUG format, ##args)
95#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__)
96#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__)
97#else
98#define snd_als300_dbgcalls(format, args...)
99#define snd_als300_dbgcallenter()
100#define snd_als300_dbgcallleave()
101#endif
102
103#if DEBUG_PLAY_REC 92#if DEBUG_PLAY_REC
104#define snd_als300_dbgplay(format, args...) printk(KERN_ERR format, ##args) 93#define snd_als300_dbgplay(format, args...) printk(KERN_ERR format, ##args)
105#else 94#else
@@ -177,7 +166,6 @@ static inline void snd_als300_gcr_write(unsigned long port,
177static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd) 166static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd)
178{ 167{
179 u32 tmp = snd_als300_gcr_read(chip->port, MISC_CONTROL); 168 u32 tmp = snd_als300_gcr_read(chip->port, MISC_CONTROL);
180 snd_als300_dbgcallenter();
181 169
182 /* boolean XOR check, since old vs. new hardware have 170 /* boolean XOR check, since old vs. new hardware have
183 directly reversed bit setting for ENABLE and DISABLE. 171 directly reversed bit setting for ENABLE and DISABLE.
@@ -188,19 +176,16 @@ static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd)
188 else 176 else
189 tmp &= ~IRQ_SET_BIT; 177 tmp &= ~IRQ_SET_BIT;
190 snd_als300_gcr_write(chip->port, MISC_CONTROL, tmp); 178 snd_als300_gcr_write(chip->port, MISC_CONTROL, tmp);
191 snd_als300_dbgcallleave();
192} 179}
193 180
194static int snd_als300_free(struct snd_als300 *chip) 181static int snd_als300_free(struct snd_als300 *chip)
195{ 182{
196 snd_als300_dbgcallenter();
197 snd_als300_set_irq_flag(chip, IRQ_DISABLE); 183 snd_als300_set_irq_flag(chip, IRQ_DISABLE);
198 if (chip->irq >= 0) 184 if (chip->irq >= 0)
199 free_irq(chip->irq, chip); 185 free_irq(chip->irq, chip);
200 pci_release_regions(chip->pci); 186 pci_release_regions(chip->pci);
201 pci_disable_device(chip->pci); 187 pci_disable_device(chip->pci);
202 kfree(chip); 188 kfree(chip);
203 snd_als300_dbgcallleave();
204 return 0; 189 return 0;
205} 190}
206 191
@@ -280,9 +265,7 @@ static irqreturn_t snd_als300plus_interrupt(int irq, void *dev_id)
280 265
281static void snd_als300_remove(struct pci_dev *pci) 266static void snd_als300_remove(struct pci_dev *pci)
282{ 267{
283 snd_als300_dbgcallenter();
284 snd_card_free(pci_get_drvdata(pci)); 268 snd_card_free(pci_get_drvdata(pci));
285 snd_als300_dbgcallleave();
286} 269}
287 270
288static unsigned short snd_als300_ac97_read(struct snd_ac97 *ac97, 271static unsigned short snd_als300_ac97_read(struct snd_ac97 *ac97,
@@ -330,14 +313,12 @@ static int snd_als300_ac97(struct snd_als300 *chip)
330 .read = snd_als300_ac97_read, 313 .read = snd_als300_ac97_read,
331 }; 314 };
332 315
333 snd_als300_dbgcallenter();
334 if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &bus)) < 0) 316 if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &bus)) < 0)
335 return err; 317 return err;
336 318
337 memset(&ac97, 0, sizeof(ac97)); 319 memset(&ac97, 0, sizeof(ac97));
338 ac97.private_data = chip; 320 ac97.private_data = chip;
339 321
340 snd_als300_dbgcallleave();
341 return snd_ac97_mixer(bus, &ac97, &chip->ac97); 322 return snd_ac97_mixer(bus, &ac97, &chip->ac97);
342} 323}
343 324
@@ -395,13 +376,11 @@ static int snd_als300_playback_open(struct snd_pcm_substream *substream)
395 376
396 if (!data) 377 if (!data)
397 return -ENOMEM; 378 return -ENOMEM;
398 snd_als300_dbgcallenter();
399 chip->playback_substream = substream; 379 chip->playback_substream = substream;
400 runtime->hw = snd_als300_playback_hw; 380 runtime->hw = snd_als300_playback_hw;
401 runtime->private_data = data; 381 runtime->private_data = data;
402 data->control_register = PLAYBACK_CONTROL; 382 data->control_register = PLAYBACK_CONTROL;
403 data->block_counter_register = PLAYBACK_BLOCK_COUNTER; 383 data->block_counter_register = PLAYBACK_BLOCK_COUNTER;
404 snd_als300_dbgcallleave();
405 return 0; 384 return 0;
406} 385}
407 386
@@ -411,11 +390,9 @@ static int snd_als300_playback_close(struct snd_pcm_substream *substream)
411 struct snd_als300_substream_data *data; 390 struct snd_als300_substream_data *data;
412 391
413 data = substream->runtime->private_data; 392 data = substream->runtime->private_data;
414 snd_als300_dbgcallenter();
415 kfree(data); 393 kfree(data);
416 chip->playback_substream = NULL; 394 chip->playback_substream = NULL;
417 snd_pcm_lib_free_pages(substream); 395 snd_pcm_lib_free_pages(substream);
418 snd_als300_dbgcallleave();
419 return 0; 396 return 0;
420} 397}
421 398
@@ -428,13 +405,11 @@ static int snd_als300_capture_open(struct snd_pcm_substream *substream)
428 405
429 if (!data) 406 if (!data)
430 return -ENOMEM; 407 return -ENOMEM;
431 snd_als300_dbgcallenter();
432 chip->capture_substream = substream; 408 chip->capture_substream = substream;
433 runtime->hw = snd_als300_capture_hw; 409 runtime->hw = snd_als300_capture_hw;
434 runtime->private_data = data; 410 runtime->private_data = data;
435 data->control_register = RECORD_CONTROL; 411 data->control_register = RECORD_CONTROL;
436 data->block_counter_register = RECORD_BLOCK_COUNTER; 412 data->block_counter_register = RECORD_BLOCK_COUNTER;
437 snd_als300_dbgcallleave();
438 return 0; 413 return 0;
439} 414}
440 415
@@ -444,11 +419,9 @@ static int snd_als300_capture_close(struct snd_pcm_substream *substream)
444 struct snd_als300_substream_data *data; 419 struct snd_als300_substream_data *data;
445 420
446 data = substream->runtime->private_data; 421 data = substream->runtime->private_data;
447 snd_als300_dbgcallenter();
448 kfree(data); 422 kfree(data);
449 chip->capture_substream = NULL; 423 chip->capture_substream = NULL;
450 snd_pcm_lib_free_pages(substream); 424 snd_pcm_lib_free_pages(substream);
451 snd_als300_dbgcallleave();
452 return 0; 425 return 0;
453} 426}
454 427
@@ -472,7 +445,6 @@ static int snd_als300_playback_prepare(struct snd_pcm_substream *substream)
472 unsigned short period_bytes = snd_pcm_lib_period_bytes(substream); 445 unsigned short period_bytes = snd_pcm_lib_period_bytes(substream);
473 unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream); 446 unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
474 447
475 snd_als300_dbgcallenter();
476 spin_lock_irq(&chip->reg_lock); 448 spin_lock_irq(&chip->reg_lock);
477 tmp = snd_als300_gcr_read(chip->port, PLAYBACK_CONTROL); 449 tmp = snd_als300_gcr_read(chip->port, PLAYBACK_CONTROL);
478 tmp &= ~TRANSFER_START; 450 tmp &= ~TRANSFER_START;
@@ -491,7 +463,6 @@ static int snd_als300_playback_prepare(struct snd_pcm_substream *substream)
491 snd_als300_gcr_write(chip->port, PLAYBACK_END, 463 snd_als300_gcr_write(chip->port, PLAYBACK_END,
492 runtime->dma_addr + buffer_bytes - 1); 464 runtime->dma_addr + buffer_bytes - 1);
493 spin_unlock_irq(&chip->reg_lock); 465 spin_unlock_irq(&chip->reg_lock);
494 snd_als300_dbgcallleave();
495 return 0; 466 return 0;
496} 467}
497 468
@@ -503,7 +474,6 @@ static int snd_als300_capture_prepare(struct snd_pcm_substream *substream)
503 unsigned short period_bytes = snd_pcm_lib_period_bytes(substream); 474 unsigned short period_bytes = snd_pcm_lib_period_bytes(substream);
504 unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream); 475 unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
505 476
506 snd_als300_dbgcallenter();
507 spin_lock_irq(&chip->reg_lock); 477 spin_lock_irq(&chip->reg_lock);
508 tmp = snd_als300_gcr_read(chip->port, RECORD_CONTROL); 478 tmp = snd_als300_gcr_read(chip->port, RECORD_CONTROL);
509 tmp &= ~TRANSFER_START; 479 tmp &= ~TRANSFER_START;
@@ -522,7 +492,6 @@ static int snd_als300_capture_prepare(struct snd_pcm_substream *substream)
522 snd_als300_gcr_write(chip->port, RECORD_END, 492 snd_als300_gcr_write(chip->port, RECORD_END,
523 runtime->dma_addr + buffer_bytes - 1); 493 runtime->dma_addr + buffer_bytes - 1);
524 spin_unlock_irq(&chip->reg_lock); 494 spin_unlock_irq(&chip->reg_lock);
525 snd_als300_dbgcallleave();
526 return 0; 495 return 0;
527} 496}
528 497
@@ -537,7 +506,6 @@ static int snd_als300_trigger(struct snd_pcm_substream *substream, int cmd)
537 data = substream->runtime->private_data; 506 data = substream->runtime->private_data;
538 reg = data->control_register; 507 reg = data->control_register;
539 508
540 snd_als300_dbgcallenter();
541 spin_lock(&chip->reg_lock); 509 spin_lock(&chip->reg_lock);
542 switch (cmd) { 510 switch (cmd) {
543 case SNDRV_PCM_TRIGGER_START: 511 case SNDRV_PCM_TRIGGER_START:
@@ -568,7 +536,6 @@ static int snd_als300_trigger(struct snd_pcm_substream *substream, int cmd)
568 ret = -EINVAL; 536 ret = -EINVAL;
569 } 537 }
570 spin_unlock(&chip->reg_lock); 538 spin_unlock(&chip->reg_lock);
571 snd_als300_dbgcallleave();
572 return ret; 539 return ret;
573} 540}
574 541
@@ -582,7 +549,6 @@ static snd_pcm_uframes_t snd_als300_pointer(struct snd_pcm_substream *substream)
582 data = substream->runtime->private_data; 549 data = substream->runtime->private_data;
583 period_bytes = snd_pcm_lib_period_bytes(substream); 550 period_bytes = snd_pcm_lib_period_bytes(substream);
584 551
585 snd_als300_dbgcallenter();
586 spin_lock(&chip->reg_lock); 552 spin_lock(&chip->reg_lock);
587 current_ptr = (u16) snd_als300_gcr_read(chip->port, 553 current_ptr = (u16) snd_als300_gcr_read(chip->port,
588 data->block_counter_register) + 4; 554 data->block_counter_register) + 4;
@@ -595,7 +561,6 @@ static snd_pcm_uframes_t snd_als300_pointer(struct snd_pcm_substream *substream)
595 if (data->period_flipflop == 0) 561 if (data->period_flipflop == 0)
596 current_ptr += period_bytes; 562 current_ptr += period_bytes;
597 snd_als300_dbgplay("Pointer (bytes): %d\n", current_ptr); 563 snd_als300_dbgplay("Pointer (bytes): %d\n", current_ptr);
598 snd_als300_dbgcallleave();
599 return bytes_to_frames(substream->runtime, current_ptr); 564 return bytes_to_frames(substream->runtime, current_ptr);
600} 565}
601 566
@@ -626,7 +591,6 @@ static int snd_als300_new_pcm(struct snd_als300 *chip)
626 struct snd_pcm *pcm; 591 struct snd_pcm *pcm;
627 int err; 592 int err;
628 593
629 snd_als300_dbgcallenter();
630 err = snd_pcm_new(chip->card, "ALS300", 0, 1, 1, &pcm); 594 err = snd_pcm_new(chip->card, "ALS300", 0, 1, 1, &pcm);
631 if (err < 0) 595 if (err < 0)
632 return err; 596 return err;
@@ -643,7 +607,6 @@ static int snd_als300_new_pcm(struct snd_als300 *chip)
643 /* pre-allocation of buffers */ 607 /* pre-allocation of buffers */
644 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 608 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
645 snd_dma_pci_data(chip->pci), 64*1024, 64*1024); 609 snd_dma_pci_data(chip->pci), 64*1024, 64*1024);
646 snd_als300_dbgcallleave();
647 return 0; 610 return 0;
648} 611}
649 612
@@ -652,7 +615,6 @@ static void snd_als300_init(struct snd_als300 *chip)
652 unsigned long flags; 615 unsigned long flags;
653 u32 tmp; 616 u32 tmp;
654 617
655 snd_als300_dbgcallenter();
656 spin_lock_irqsave(&chip->reg_lock, flags); 618 spin_lock_irqsave(&chip->reg_lock, flags);
657 chip->revision = (snd_als300_gcr_read(chip->port, MISC_CONTROL) >> 16) 619 chip->revision = (snd_als300_gcr_read(chip->port, MISC_CONTROL) >> 16)
658 & 0x0000000F; 620 & 0x0000000F;
@@ -679,7 +641,6 @@ static void snd_als300_init(struct snd_als300 *chip)
679 snd_als300_gcr_write(chip->port, PLAYBACK_CONTROL, 641 snd_als300_gcr_write(chip->port, PLAYBACK_CONTROL,
680 tmp & ~TRANSFER_START); 642 tmp & ~TRANSFER_START);
681 spin_unlock_irqrestore(&chip->reg_lock, flags); 643 spin_unlock_irqrestore(&chip->reg_lock, flags);
682 snd_als300_dbgcallleave();
683} 644}
684 645
685static int snd_als300_create(struct snd_card *card, 646static int snd_als300_create(struct snd_card *card,
@@ -695,13 +656,12 @@ static int snd_als300_create(struct snd_card *card,
695 }; 656 };
696 *rchip = NULL; 657 *rchip = NULL;
697 658
698 snd_als300_dbgcallenter();
699 if ((err = pci_enable_device(pci)) < 0) 659 if ((err = pci_enable_device(pci)) < 0)
700 return err; 660 return err;
701 661
702 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || 662 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
703 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { 663 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) {
704 printk(KERN_ERR "error setting 28bit DMA mask\n"); 664 dev_err(card->dev, "error setting 28bit DMA mask\n");
705 pci_disable_device(pci); 665 pci_disable_device(pci);
706 return -ENXIO; 666 return -ENXIO;
707 } 667 }
@@ -733,7 +693,7 @@ static int snd_als300_create(struct snd_card *card,
733 693
734 if (request_irq(pci->irq, irq_handler, IRQF_SHARED, 694 if (request_irq(pci->irq, irq_handler, IRQF_SHARED,
735 KBUILD_MODNAME, chip)) { 695 KBUILD_MODNAME, chip)) {
736 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 696 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
737 snd_als300_free(chip); 697 snd_als300_free(chip);
738 return -EBUSY; 698 return -EBUSY;
739 } 699 }
@@ -744,13 +704,13 @@ static int snd_als300_create(struct snd_card *card,
744 704
745 err = snd_als300_ac97(chip); 705 err = snd_als300_ac97(chip);
746 if (err < 0) { 706 if (err < 0) {
747 snd_printk(KERN_WARNING "Could not create ac97\n"); 707 dev_err(card->dev, "Could not create ac97\n");
748 snd_als300_free(chip); 708 snd_als300_free(chip);
749 return err; 709 return err;
750 } 710 }
751 711
752 if ((err = snd_als300_new_pcm(chip)) < 0) { 712 if ((err = snd_als300_new_pcm(chip)) < 0) {
753 snd_printk(KERN_WARNING "Could not create PCM\n"); 713 dev_err(card->dev, "Could not create PCM\n");
754 snd_als300_free(chip); 714 snd_als300_free(chip);
755 return err; 715 return err;
756 } 716 }
@@ -761,10 +721,7 @@ static int snd_als300_create(struct snd_card *card,
761 return err; 721 return err;
762 } 722 }
763 723
764 snd_card_set_dev(card, &pci->dev);
765
766 *rchip = chip; 724 *rchip = chip;
767 snd_als300_dbgcallleave();
768 return 0; 725 return 0;
769} 726}
770 727
@@ -794,8 +751,7 @@ static int snd_als300_resume(struct device *dev)
794 pci_set_power_state(pci, PCI_D0); 751 pci_set_power_state(pci, PCI_D0);
795 pci_restore_state(pci); 752 pci_restore_state(pci);
796 if (pci_enable_device(pci) < 0) { 753 if (pci_enable_device(pci) < 0) {
797 printk(KERN_ERR "als300: pci_enable_device failed, " 754 dev_err(dev, "pci_enable_device failed, disabling device\n");
798 "disabling device\n");
799 snd_card_disconnect(card); 755 snd_card_disconnect(card);
800 return -EIO; 756 return -EIO;
801 } 757 }
@@ -829,7 +785,8 @@ static int snd_als300_probe(struct pci_dev *pci,
829 return -ENOENT; 785 return -ENOENT;
830 } 786 }
831 787
832 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 788 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
789 0, &card);
833 790
834 if (err < 0) 791 if (err < 0)
835 return err; 792 return err;
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c
index ffc821b0139e..b751c381d25e 100644
--- a/sound/pci/als4000.c
+++ b/sound/pci/als4000.c
@@ -578,7 +578,7 @@ static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id)
578 snd_als4k_iobase_readb(chip->alt_port, 578 snd_als4k_iobase_readb(chip->alt_port,
579 ALS4K_IOB_16_ACK_FOR_CR1E); 579 ALS4K_IOB_16_ACK_FOR_CR1E);
580 580
581 /* printk(KERN_INFO "als4000: irq 0x%04x 0x%04x\n", 581 /* dev_dbg(chip->card->dev, "als4000: irq 0x%04x 0x%04x\n",
582 pci_irqstatus, sb_irqstatus); */ 582 pci_irqstatus, sb_irqstatus); */
583 583
584 /* only ack the things we actually handled above */ 584 /* only ack the things we actually handled above */
@@ -791,13 +791,13 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev)
791 } 791 }
792 792
793 if (!r) { 793 if (!r) {
794 printk(KERN_WARNING "als4000: cannot reserve joystick ports\n"); 794 dev_warn(&acard->pci->dev, "cannot reserve joystick ports\n");
795 return -EBUSY; 795 return -EBUSY;
796 } 796 }
797 797
798 acard->gameport = gp = gameport_allocate_port(); 798 acard->gameport = gp = gameport_allocate_port();
799 if (!gp) { 799 if (!gp) {
800 printk(KERN_ERR "als4000: cannot allocate memory for gameport\n"); 800 dev_err(&acard->pci->dev, "cannot allocate memory for gameport\n");
801 release_and_free_resource(r); 801 release_and_free_resource(r);
802 return -ENOMEM; 802 return -ENOMEM;
803 } 803 }
@@ -873,7 +873,7 @@ static int snd_card_als4000_probe(struct pci_dev *pci,
873 /* check, if we can restrict PCI DMA transfers to 24 bits */ 873 /* check, if we can restrict PCI DMA transfers to 24 bits */
874 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 || 874 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 ||
875 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) { 875 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) {
876 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n"); 876 dev_err(&pci->dev, "architecture does not support 24bit PCI busmaster DMA\n");
877 pci_disable_device(pci); 877 pci_disable_device(pci);
878 return -ENXIO; 878 return -ENXIO;
879 } 879 }
@@ -888,9 +888,9 @@ static int snd_card_als4000_probe(struct pci_dev *pci,
888 pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO); 888 pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO);
889 pci_set_master(pci); 889 pci_set_master(pci);
890 890
891 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 891 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
892 sizeof(*acard) /* private_data: acard */, 892 sizeof(*acard) /* private_data: acard */,
893 &card); 893 &card);
894 if (err < 0) { 894 if (err < 0) {
895 pci_release_regions(pci); 895 pci_release_regions(pci);
896 pci_disable_device(pci); 896 pci_disable_device(pci);
@@ -920,7 +920,6 @@ static int snd_card_als4000_probe(struct pci_dev *pci,
920 920
921 chip->pci = pci; 921 chip->pci = pci;
922 chip->alt_port = iobase; 922 chip->alt_port = iobase;
923 snd_card_set_dev(card, &pci->dev);
924 923
925 snd_als4000_configure(chip); 924 snd_als4000_configure(chip);
926 925
@@ -934,7 +933,7 @@ static int snd_card_als4000_probe(struct pci_dev *pci,
934 MPU401_INFO_INTEGRATED | 933 MPU401_INFO_INTEGRATED |
935 MPU401_INFO_IRQ_HOOK, 934 MPU401_INFO_IRQ_HOOK,
936 -1, &chip->rmidi)) < 0) { 935 -1, &chip->rmidi)) < 0) {
937 printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n", 936 dev_err(&pci->dev, "no MPU-401 device at 0x%lx?\n",
938 iobase + ALS4K_IOB_30_MIDI_DATA); 937 iobase + ALS4K_IOB_30_MIDI_DATA);
939 goto out_err; 938 goto out_err;
940 } 939 }
@@ -955,7 +954,7 @@ static int snd_card_als4000_probe(struct pci_dev *pci,
955 iobase + ALS4K_IOB_10_ADLIB_ADDR0, 954 iobase + ALS4K_IOB_10_ADLIB_ADDR0,
956 iobase + ALS4K_IOB_12_ADLIB_ADDR2, 955 iobase + ALS4K_IOB_12_ADLIB_ADDR2,
957 OPL3_HW_AUTO, 1, &opl3) < 0) { 956 OPL3_HW_AUTO, 1, &opl3) < 0) {
958 printk(KERN_ERR "als4000: no OPL device at 0x%lx-0x%lx?\n", 957 dev_err(&pci->dev, "no OPL device at 0x%lx-0x%lx?\n",
959 iobase + ALS4K_IOB_10_ADLIB_ADDR0, 958 iobase + ALS4K_IOB_10_ADLIB_ADDR0,
960 iobase + ALS4K_IOB_12_ADLIB_ADDR2); 959 iobase + ALS4K_IOB_12_ADLIB_ADDR2);
961 } else { 960 } else {
@@ -1015,8 +1014,7 @@ static int snd_als4000_resume(struct device *dev)
1015 pci_set_power_state(pci, PCI_D0); 1014 pci_set_power_state(pci, PCI_D0);
1016 pci_restore_state(pci); 1015 pci_restore_state(pci);
1017 if (pci_enable_device(pci) < 0) { 1016 if (pci_enable_device(pci) < 0) {
1018 printk(KERN_ERR "als4000: pci_enable_device failed, " 1017 dev_err(dev, "pci_enable_device failed, disabling device\n");
1019 "disabling device\n");
1020 snd_card_disconnect(card); 1018 snd_card_disconnect(card);
1021 return -EIO; 1019 return -EIO;
1022 } 1020 }
diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c
index 5f2acd35dcb9..901c9490398a 100644
--- a/sound/pci/asihpi/asihpi.c
+++ b/sound/pci/asihpi/asihpi.c
@@ -1253,11 +1253,12 @@ static int snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, int device)
1253 num_outstreams, num_instreams, &pcm); 1253 num_outstreams, num_instreams, &pcm);
1254 if (err < 0) 1254 if (err < 0)
1255 return err; 1255 return err;
1256
1256 /* pointer to ops struct is stored, dont change ops afterwards! */ 1257 /* pointer to ops struct is stored, dont change ops afterwards! */
1257 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, 1258 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1258 &snd_card_asihpi_playback_mmap_ops); 1259 &snd_card_asihpi_playback_mmap_ops);
1259 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 1260 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1260 &snd_card_asihpi_capture_mmap_ops); 1261 &snd_card_asihpi_capture_mmap_ops);
1261 1262
1262 pcm->private_data = asihpi; 1263 pcm->private_data = asihpi;
1263 pcm->info_flags = 0; 1264 pcm->info_flags = 0;
@@ -2827,17 +2828,13 @@ static int snd_asihpi_probe(struct pci_dev *pci_dev,
2827 hpi = pci_get_drvdata(pci_dev); 2828 hpi = pci_get_drvdata(pci_dev);
2828 adapter_index = hpi->adapter->index; 2829 adapter_index = hpi->adapter->index;
2829 /* first try to give the card the same index as its hardware index */ 2830 /* first try to give the card the same index as its hardware index */
2830 err = snd_card_create(adapter_index, 2831 err = snd_card_new(&pci_dev->dev, adapter_index, id[adapter_index],
2831 id[adapter_index], THIS_MODULE, 2832 THIS_MODULE, sizeof(struct snd_card_asihpi), &card);
2832 sizeof(struct snd_card_asihpi),
2833 &card);
2834 if (err < 0) { 2833 if (err < 0) {
2835 /* if that fails, try the default index==next available */ 2834 /* if that fails, try the default index==next available */
2836 err = 2835 err = snd_card_new(&pci_dev->dev, index[dev], id[dev],
2837 snd_card_create(index[dev], id[dev], 2836 THIS_MODULE, sizeof(struct snd_card_asihpi),
2838 THIS_MODULE, 2837 &card);
2839 sizeof(struct snd_card_asihpi),
2840 &card);
2841 if (err < 0) 2838 if (err < 0)
2842 return err; 2839 return err;
2843 snd_printk(KERN_WARNING 2840 snd_printk(KERN_WARNING
@@ -2845,8 +2842,6 @@ static int snd_asihpi_probe(struct pci_dev *pci_dev,
2845 adapter_index, card->number); 2842 adapter_index, card->number);
2846 } 2843 }
2847 2844
2848 snd_card_set_dev(card, &pci_dev->dev);
2849
2850 asihpi = card->private_data; 2845 asihpi = card->private_data;
2851 asihpi->card = card; 2846 asihpi->card = card;
2852 asihpi->pci = pci_dev; 2847 asihpi->pci = pci_dev;
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index f6dec3ea371f..ae07b4926dc2 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -432,7 +432,7 @@ static int snd_atiixp_acquire_codec(struct atiixp *chip)
432 432
433 while (atiixp_read(chip, PHYS_OUT_ADDR) & ATI_REG_PHYS_OUT_ADDR_EN) { 433 while (atiixp_read(chip, PHYS_OUT_ADDR) & ATI_REG_PHYS_OUT_ADDR_EN) {
434 if (! timeout--) { 434 if (! timeout--) {
435 snd_printk(KERN_WARNING "atiixp: codec acquire timeout\n"); 435 dev_warn(chip->card->dev, "codec acquire timeout\n");
436 return -EBUSY; 436 return -EBUSY;
437 } 437 }
438 udelay(1); 438 udelay(1);
@@ -463,7 +463,7 @@ static unsigned short snd_atiixp_codec_read(struct atiixp *chip, unsigned short
463 } while (--timeout); 463 } while (--timeout);
464 /* time out may happen during reset */ 464 /* time out may happen during reset */
465 if (reg < 0x7c) 465 if (reg < 0x7c)
466 snd_printk(KERN_WARNING "atiixp: codec read timeout (reg %x)\n", reg); 466 dev_warn(chip->card->dev, "codec read timeout (reg %x)\n", reg);
467 return 0xffff; 467 return 0xffff;
468} 468}
469 469
@@ -523,7 +523,7 @@ static int snd_atiixp_aclink_reset(struct atiixp *chip)
523 mdelay(1); 523 mdelay(1);
524 atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET); 524 atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET);
525 if (!--timeout) { 525 if (!--timeout) {
526 snd_printk(KERN_ERR "atiixp: codec reset timeout\n"); 526 dev_err(chip->card->dev, "codec reset timeout\n");
527 break; 527 break;
528 } 528 }
529 } 529 }
@@ -567,9 +567,8 @@ static int ac97_probing_bugs(struct pci_dev *pci)
567 567
568 q = snd_pci_quirk_lookup(pci, atiixp_quirks); 568 q = snd_pci_quirk_lookup(pci, atiixp_quirks);
569 if (q) { 569 if (q) {
570 snd_printdd(KERN_INFO 570 dev_dbg(&pci->dev, "atiixp quirk for %s. Forcing codec %d\n",
571 "Atiixp quirk for %s. Forcing codec %d\n", 571 snd_pci_quirk_name(q), q->value);
572 snd_pci_quirk_name(q), q->value);
573 return q->value; 572 return q->value;
574 } 573 }
575 /* this hardware doesn't need workarounds. Probe for codec */ 574 /* this hardware doesn't need workarounds. Probe for codec */
@@ -600,7 +599,7 @@ static int snd_atiixp_codec_detect(struct atiixp *chip)
600 atiixp_write(chip, IER, 0); /* disable irqs */ 599 atiixp_write(chip, IER, 0); /* disable irqs */
601 600
602 if ((chip->codec_not_ready_bits & ALL_CODEC_NOT_READY) == ALL_CODEC_NOT_READY) { 601 if ((chip->codec_not_ready_bits & ALL_CODEC_NOT_READY) == ALL_CODEC_NOT_READY) {
603 snd_printk(KERN_ERR "atiixp: no codec detected!\n"); 602 dev_err(chip->card->dev, "no codec detected!\n");
604 return -ENXIO; 603 return -ENXIO;
605 } 604 }
606 return 0; 605 return 0;
@@ -676,7 +675,7 @@ static snd_pcm_uframes_t snd_atiixp_pcm_pointer(struct snd_pcm_substream *substr
676 continue; 675 continue;
677 return bytes_to_frames(runtime, curptr); 676 return bytes_to_frames(runtime, curptr);
678 } 677 }
679 snd_printd("atiixp: invalid DMA pointer read 0x%x (buf=%x)\n", 678 dev_dbg(chip->card->dev, "invalid DMA pointer read 0x%x (buf=%x)\n",
680 readl(chip->remap_addr + dma->ops->dt_cur), dma->buf_addr); 679 readl(chip->remap_addr + dma->ops->dt_cur), dma->buf_addr);
681 return 0; 680 return 0;
682} 681}
@@ -688,7 +687,7 @@ static void snd_atiixp_xrun_dma(struct atiixp *chip, struct atiixp_dma *dma)
688{ 687{
689 if (! dma->substream || ! dma->running) 688 if (! dma->substream || ! dma->running)
690 return; 689 return;
691 snd_printdd("atiixp: XRUN detected (DMA %d)\n", dma->ops->type); 690 dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type);
692 snd_pcm_stream_lock(dma->substream); 691 snd_pcm_stream_lock(dma->substream);
693 snd_pcm_stop(dma->substream, SNDRV_PCM_STATE_XRUN); 692 snd_pcm_stop(dma->substream, SNDRV_PCM_STATE_XRUN);
694 snd_pcm_stream_unlock(dma->substream); 693 snd_pcm_stream_unlock(dma->substream);
@@ -1453,14 +1452,15 @@ static int snd_atiixp_mixer_new(struct atiixp *chip, int clock,
1453 ac97.scaps |= AC97_SCAP_NO_SPDIF; 1452 ac97.scaps |= AC97_SCAP_NO_SPDIF;
1454 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) { 1453 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
1455 chip->ac97[i] = NULL; /* to be sure */ 1454 chip->ac97[i] = NULL; /* to be sure */
1456 snd_printdd("atiixp: codec %d not available for audio\n", i); 1455 dev_dbg(chip->card->dev,
1456 "codec %d not available for audio\n", i);
1457 continue; 1457 continue;
1458 } 1458 }
1459 codec_count++; 1459 codec_count++;
1460 } 1460 }
1461 1461
1462 if (! codec_count) { 1462 if (! codec_count) {
1463 snd_printk(KERN_ERR "atiixp: no codec available\n"); 1463 dev_err(chip->card->dev, "no codec available\n");
1464 return -ENODEV; 1464 return -ENODEV;
1465 } 1465 }
1466 1466
@@ -1511,8 +1511,7 @@ static int snd_atiixp_resume(struct device *dev)
1511 pci_set_power_state(pci, PCI_D0); 1511 pci_set_power_state(pci, PCI_D0);
1512 pci_restore_state(pci); 1512 pci_restore_state(pci);
1513 if (pci_enable_device(pci) < 0) { 1513 if (pci_enable_device(pci) < 0) {
1514 printk(KERN_ERR "atiixp: pci_enable_device failed, " 1514 dev_err(dev, "pci_enable_device failed, disabling device\n");
1515 "disabling device\n");
1516 snd_card_disconnect(card); 1515 snd_card_disconnect(card);
1517 return -EIO; 1516 return -EIO;
1518 } 1517 }
@@ -1637,14 +1636,14 @@ static int snd_atiixp_create(struct snd_card *card,
1637 chip->addr = pci_resource_start(pci, 0); 1636 chip->addr = pci_resource_start(pci, 0);
1638 chip->remap_addr = pci_ioremap_bar(pci, 0); 1637 chip->remap_addr = pci_ioremap_bar(pci, 0);
1639 if (chip->remap_addr == NULL) { 1638 if (chip->remap_addr == NULL) {
1640 snd_printk(KERN_ERR "AC'97 space ioremap problem\n"); 1639 dev_err(card->dev, "AC'97 space ioremap problem\n");
1641 snd_atiixp_free(chip); 1640 snd_atiixp_free(chip);
1642 return -EIO; 1641 return -EIO;
1643 } 1642 }
1644 1643
1645 if (request_irq(pci->irq, snd_atiixp_interrupt, IRQF_SHARED, 1644 if (request_irq(pci->irq, snd_atiixp_interrupt, IRQF_SHARED,
1646 KBUILD_MODNAME, chip)) { 1645 KBUILD_MODNAME, chip)) {
1647 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1646 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1648 snd_atiixp_free(chip); 1647 snd_atiixp_free(chip);
1649 return -EBUSY; 1648 return -EBUSY;
1650 } 1649 }
@@ -1657,8 +1656,6 @@ static int snd_atiixp_create(struct snd_card *card,
1657 return err; 1656 return err;
1658 } 1657 }
1659 1658
1660 snd_card_set_dev(card, &pci->dev);
1661
1662 *r_chip = chip; 1659 *r_chip = chip;
1663 return 0; 1660 return 0;
1664} 1661}
@@ -1671,7 +1668,7 @@ static int snd_atiixp_probe(struct pci_dev *pci,
1671 struct atiixp *chip; 1668 struct atiixp *chip;
1672 int err; 1669 int err;
1673 1670
1674 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 1671 err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
1675 if (err < 0) 1672 if (err < 0)
1676 return err; 1673 return err;
1677 1674
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index 289563ecb6dd..b9dc96c5d21e 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -400,7 +400,7 @@ static int snd_atiixp_acquire_codec(struct atiixp_modem *chip)
400 400
401 while (atiixp_read(chip, PHYS_OUT_ADDR) & ATI_REG_PHYS_OUT_ADDR_EN) { 401 while (atiixp_read(chip, PHYS_OUT_ADDR) & ATI_REG_PHYS_OUT_ADDR_EN) {
402 if (! timeout--) { 402 if (! timeout--) {
403 snd_printk(KERN_WARNING "atiixp-modem: codec acquire timeout\n"); 403 dev_warn(chip->card->dev, "codec acquire timeout\n");
404 return -EBUSY; 404 return -EBUSY;
405 } 405 }
406 udelay(1); 406 udelay(1);
@@ -433,7 +433,7 @@ static unsigned short snd_atiixp_codec_read(struct atiixp_modem *chip,
433 } while (--timeout); 433 } while (--timeout);
434 /* time out may happen during reset */ 434 /* time out may happen during reset */
435 if (reg < 0x7c) 435 if (reg < 0x7c)
436 snd_printk(KERN_WARNING "atiixp-modem: codec read timeout (reg %x)\n", reg); 436 dev_warn(chip->card->dev, "codec read timeout (reg %x)\n", reg);
437 return 0xffff; 437 return 0xffff;
438} 438}
439 439
@@ -499,7 +499,7 @@ static int snd_atiixp_aclink_reset(struct atiixp_modem *chip)
499 msleep(1); 499 msleep(1);
500 atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET); 500 atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET);
501 if (!--timeout) { 501 if (!--timeout) {
502 snd_printk(KERN_ERR "atiixp-modem: codec reset timeout\n"); 502 dev_err(chip->card->dev, "codec reset timeout\n");
503 break; 503 break;
504 } 504 }
505 } 505 }
@@ -553,7 +553,7 @@ static int snd_atiixp_codec_detect(struct atiixp_modem *chip)
553 atiixp_write(chip, IER, 0); /* disable irqs */ 553 atiixp_write(chip, IER, 0); /* disable irqs */
554 554
555 if ((chip->codec_not_ready_bits & ALL_CODEC_NOT_READY) == ALL_CODEC_NOT_READY) { 555 if ((chip->codec_not_ready_bits & ALL_CODEC_NOT_READY) == ALL_CODEC_NOT_READY) {
556 snd_printk(KERN_ERR "atiixp-modem: no codec detected!\n"); 556 dev_err(chip->card->dev, "no codec detected!\n");
557 return -ENXIO; 557 return -ENXIO;
558 } 558 }
559 return 0; 559 return 0;
@@ -624,7 +624,7 @@ static snd_pcm_uframes_t snd_atiixp_pcm_pointer(struct snd_pcm_substream *substr
624 continue; 624 continue;
625 return bytes_to_frames(runtime, curptr); 625 return bytes_to_frames(runtime, curptr);
626 } 626 }
627 snd_printd("atiixp-modem: invalid DMA pointer read 0x%x (buf=%x)\n", 627 dev_dbg(chip->card->dev, "invalid DMA pointer read 0x%x (buf=%x)\n",
628 readl(chip->remap_addr + dma->ops->dt_cur), dma->buf_addr); 628 readl(chip->remap_addr + dma->ops->dt_cur), dma->buf_addr);
629 return 0; 629 return 0;
630} 630}
@@ -637,7 +637,7 @@ static void snd_atiixp_xrun_dma(struct atiixp_modem *chip,
637{ 637{
638 if (! dma->substream || ! dma->running) 638 if (! dma->substream || ! dma->running)
639 return; 639 return;
640 snd_printdd("atiixp-modem: XRUN detected (DMA %d)\n", dma->ops->type); 640 dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type);
641 snd_pcm_stream_lock(dma->substream); 641 snd_pcm_stream_lock(dma->substream);
642 snd_pcm_stop(dma->substream, SNDRV_PCM_STATE_XRUN); 642 snd_pcm_stop(dma->substream, SNDRV_PCM_STATE_XRUN);
643 snd_pcm_stream_unlock(dma->substream); 643 snd_pcm_stream_unlock(dma->substream);
@@ -1098,14 +1098,15 @@ static int snd_atiixp_mixer_new(struct atiixp_modem *chip, int clock)
1098 ac97.scaps = AC97_SCAP_SKIP_AUDIO | AC97_SCAP_POWER_SAVE; 1098 ac97.scaps = AC97_SCAP_SKIP_AUDIO | AC97_SCAP_POWER_SAVE;
1099 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) { 1099 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
1100 chip->ac97[i] = NULL; /* to be sure */ 1100 chip->ac97[i] = NULL; /* to be sure */
1101 snd_printdd("atiixp-modem: codec %d not available for modem\n", i); 1101 dev_dbg(chip->card->dev,
1102 "codec %d not available for modem\n", i);
1102 continue; 1103 continue;
1103 } 1104 }
1104 codec_count++; 1105 codec_count++;
1105 } 1106 }
1106 1107
1107 if (! codec_count) { 1108 if (! codec_count) {
1108 snd_printk(KERN_ERR "atiixp-modem: no codec available\n"); 1109 dev_err(chip->card->dev, "no codec available\n");
1109 return -ENODEV; 1110 return -ENODEV;
1110 } 1111 }
1111 1112
@@ -1150,8 +1151,7 @@ static int snd_atiixp_resume(struct device *dev)
1150 pci_set_power_state(pci, PCI_D0); 1151 pci_set_power_state(pci, PCI_D0);
1151 pci_restore_state(pci); 1152 pci_restore_state(pci);
1152 if (pci_enable_device(pci) < 0) { 1153 if (pci_enable_device(pci) < 0) {
1153 printk(KERN_ERR "atiixp-modem: pci_enable_device failed, " 1154 dev_err(dev, "pci_enable_device failed, disabling device\n");
1154 "disabling device\n");
1155 snd_card_disconnect(card); 1155 snd_card_disconnect(card);
1156 return -EIO; 1156 return -EIO;
1157 } 1157 }
@@ -1262,14 +1262,14 @@ static int snd_atiixp_create(struct snd_card *card,
1262 chip->addr = pci_resource_start(pci, 0); 1262 chip->addr = pci_resource_start(pci, 0);
1263 chip->remap_addr = pci_ioremap_bar(pci, 0); 1263 chip->remap_addr = pci_ioremap_bar(pci, 0);
1264 if (chip->remap_addr == NULL) { 1264 if (chip->remap_addr == NULL) {
1265 snd_printk(KERN_ERR "AC'97 space ioremap problem\n"); 1265 dev_err(card->dev, "AC'97 space ioremap problem\n");
1266 snd_atiixp_free(chip); 1266 snd_atiixp_free(chip);
1267 return -EIO; 1267 return -EIO;
1268 } 1268 }
1269 1269
1270 if (request_irq(pci->irq, snd_atiixp_interrupt, IRQF_SHARED, 1270 if (request_irq(pci->irq, snd_atiixp_interrupt, IRQF_SHARED,
1271 KBUILD_MODNAME, chip)) { 1271 KBUILD_MODNAME, chip)) {
1272 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1272 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1273 snd_atiixp_free(chip); 1273 snd_atiixp_free(chip);
1274 return -EBUSY; 1274 return -EBUSY;
1275 } 1275 }
@@ -1282,8 +1282,6 @@ static int snd_atiixp_create(struct snd_card *card,
1282 return err; 1282 return err;
1283 } 1283 }
1284 1284
1285 snd_card_set_dev(card, &pci->dev);
1286
1287 *r_chip = chip; 1285 *r_chip = chip;
1288 return 0; 1286 return 0;
1289} 1287}
@@ -1296,7 +1294,7 @@ static int snd_atiixp_probe(struct pci_dev *pci,
1296 struct atiixp_modem *chip; 1294 struct atiixp_modem *chip;
1297 int err; 1295 int err;
1298 1296
1299 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 1297 err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
1300 if (err < 0) 1298 if (err < 0)
1301 return err; 1299 return err;
1302 1300
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c
index 7059dd69e5e6..afb1b44b741e 100644
--- a/sound/pci/au88x0/au88x0.c
+++ b/sound/pci/au88x0/au88x0.c
@@ -211,8 +211,6 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
211 goto alloc_out; 211 goto alloc_out;
212 } 212 }
213 213
214 snd_card_set_dev(card, &pci->dev);
215
216 *rchip = chip; 214 *rchip = chip;
217 215
218 return 0; 216 return 0;
@@ -250,7 +248,8 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
250 return -ENOENT; 248 return -ENOENT;
251 } 249 }
252 // (2) 250 // (2)
253 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 251 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
252 0, &card);
254 if (err < 0) 253 if (err < 0)
255 return err; 254 return err;
256 255
diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c
index 2925220d3fcf..120d0d320a60 100644
--- a/sound/pci/aw2/aw2-alsa.c
+++ b/sound/pci/aw2/aw2-alsa.c
@@ -262,7 +262,7 @@ static int snd_aw2_create(struct snd_card *card,
262 /* check PCI availability (32bit DMA) */ 262 /* check PCI availability (32bit DMA) */
263 if ((pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0) || 263 if ((pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0) ||
264 (pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0)) { 264 (pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0)) {
265 printk(KERN_ERR "aw2: Impossible to set 32bit mask DMA\n"); 265 dev_err(card->dev, "Impossible to set 32bit mask DMA\n");
266 pci_disable_device(pci); 266 pci_disable_device(pci);
267 return -ENXIO; 267 return -ENXIO;
268 } 268 }
@@ -290,7 +290,7 @@ static int snd_aw2_create(struct snd_card *card,
290 pci_resource_len(pci, 0)); 290 pci_resource_len(pci, 0));
291 291
292 if (chip->iobase_virt == NULL) { 292 if (chip->iobase_virt == NULL) {
293 printk(KERN_ERR "aw2: unable to remap memory region"); 293 dev_err(card->dev, "unable to remap memory region");
294 pci_release_regions(pci); 294 pci_release_regions(pci);
295 pci_disable_device(pci); 295 pci_disable_device(pci);
296 kfree(chip); 296 kfree(chip);
@@ -302,7 +302,7 @@ static int snd_aw2_create(struct snd_card *card,
302 302
303 if (request_irq(pci->irq, snd_aw2_saa7146_interrupt, 303 if (request_irq(pci->irq, snd_aw2_saa7146_interrupt,
304 IRQF_SHARED, KBUILD_MODNAME, chip)) { 304 IRQF_SHARED, KBUILD_MODNAME, chip)) {
305 printk(KERN_ERR "aw2: Cannot grab irq %d\n", pci->irq); 305 dev_err(card->dev, "Cannot grab irq %d\n", pci->irq);
306 306
307 iounmap(chip->iobase_virt); 307 iounmap(chip->iobase_virt);
308 pci_release_regions(chip->pci); 308 pci_release_regions(chip->pci);
@@ -322,12 +322,10 @@ static int snd_aw2_create(struct snd_card *card,
322 return err; 322 return err;
323 } 323 }
324 324
325 snd_card_set_dev(card, &pci->dev);
326 *rchip = chip; 325 *rchip = chip;
327 326
328 printk(KERN_INFO 327 dev_info(card->dev,
329 "Audiowerk 2 sound card (saa7146 chipset) detected and " 328 "Audiowerk 2 sound card (saa7146 chipset) detected and managed\n");
330 "managed\n");
331 return 0; 329 return 0;
332} 330}
333 331
@@ -349,7 +347,8 @@ static int snd_aw2_probe(struct pci_dev *pci,
349 } 347 }
350 348
351 /* (2) Create card instance */ 349 /* (2) Create card instance */
352 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 350 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
351 0, &card);
353 if (err < 0) 352 if (err < 0)
354 return err; 353 return err;
355 354
@@ -399,7 +398,7 @@ static int snd_aw2_pcm_playback_open(struct snd_pcm_substream *substream)
399{ 398{
400 struct snd_pcm_runtime *runtime = substream->runtime; 399 struct snd_pcm_runtime *runtime = substream->runtime;
401 400
402 snd_printdd(KERN_DEBUG "aw2: Playback_open\n"); 401 dev_dbg(substream->pcm->card->dev, "Playback_open\n");
403 runtime->hw = snd_aw2_playback_hw; 402 runtime->hw = snd_aw2_playback_hw;
404 return 0; 403 return 0;
405} 404}
@@ -415,7 +414,7 @@ static int snd_aw2_pcm_capture_open(struct snd_pcm_substream *substream)
415{ 414{
416 struct snd_pcm_runtime *runtime = substream->runtime; 415 struct snd_pcm_runtime *runtime = substream->runtime;
417 416
418 snd_printdd(KERN_DEBUG "aw2: Capture_open\n"); 417 dev_dbg(substream->pcm->card->dev, "Capture_open\n");
419 runtime->hw = snd_aw2_capture_hw; 418 runtime->hw = snd_aw2_capture_hw;
420 return 0; 419 return 0;
421} 420}
@@ -603,7 +602,7 @@ static int snd_aw2_new_pcm(struct aw2 *chip)
603 err = snd_pcm_new(chip->card, "Audiowerk2 analog playback", 0, 1, 0, 602 err = snd_pcm_new(chip->card, "Audiowerk2 analog playback", 0, 1, 0,
604 &pcm_playback_ana); 603 &pcm_playback_ana);
605 if (err < 0) { 604 if (err < 0) {
606 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err); 605 dev_err(chip->card->dev, "snd_pcm_new error (0x%X)\n", err);
607 return err; 606 return err;
608 } 607 }
609 608
@@ -633,14 +632,15 @@ static int snd_aw2_new_pcm(struct aw2 *chip)
633 (chip->pci), 632 (chip->pci),
634 64 * 1024, 64 * 1024); 633 64 * 1024, 64 * 1024);
635 if (err) 634 if (err)
636 printk(KERN_ERR "aw2: snd_pcm_lib_preallocate_pages_for_all " 635 dev_err(chip->card->dev,
637 "error (0x%X)\n", err); 636 "snd_pcm_lib_preallocate_pages_for_all error (0x%X)\n",
637 err);
638 638
639 err = snd_pcm_new(chip->card, "Audiowerk2 digital playback", 1, 1, 0, 639 err = snd_pcm_new(chip->card, "Audiowerk2 digital playback", 1, 1, 0,
640 &pcm_playback_num); 640 &pcm_playback_num);
641 641
642 if (err < 0) { 642 if (err < 0) {
643 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err); 643 dev_err(chip->card->dev, "snd_pcm_new error (0x%X)\n", err);
644 return err; 644 return err;
645 } 645 }
646 /* Creation ok */ 646 /* Creation ok */
@@ -669,17 +669,15 @@ static int snd_aw2_new_pcm(struct aw2 *chip)
669 (chip->pci), 669 (chip->pci),
670 64 * 1024, 64 * 1024); 670 64 * 1024, 64 * 1024);
671 if (err) 671 if (err)
672 printk(KERN_ERR 672 dev_err(chip->card->dev,
673 "aw2: snd_pcm_lib_preallocate_pages_for_all error " 673 "snd_pcm_lib_preallocate_pages_for_all error (0x%X)\n",
674 "(0x%X)\n", err); 674 err);
675
676
677 675
678 err = snd_pcm_new(chip->card, "Audiowerk2 capture", 2, 0, 1, 676 err = snd_pcm_new(chip->card, "Audiowerk2 capture", 2, 0, 1,
679 &pcm_capture); 677 &pcm_capture);
680 678
681 if (err < 0) { 679 if (err < 0) {
682 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err); 680 dev_err(chip->card->dev, "snd_pcm_new error (0x%X)\n", err);
683 return err; 681 return err;
684 } 682 }
685 683
@@ -709,15 +707,15 @@ static int snd_aw2_new_pcm(struct aw2 *chip)
709 (chip->pci), 707 (chip->pci),
710 64 * 1024, 64 * 1024); 708 64 * 1024, 64 * 1024);
711 if (err) 709 if (err)
712 printk(KERN_ERR 710 dev_err(chip->card->dev,
713 "aw2: snd_pcm_lib_preallocate_pages_for_all error " 711 "snd_pcm_lib_preallocate_pages_for_all error (0x%X)\n",
714 "(0x%X)\n", err); 712 err);
715 713
716 714
717 /* Create control */ 715 /* Create control */
718 err = snd_ctl_add(chip->card, snd_ctl_new1(&aw2_control, chip)); 716 err = snd_ctl_add(chip->card, snd_ctl_new1(&aw2_control, chip));
719 if (err < 0) { 717 if (err < 0) {
720 printk(KERN_ERR "aw2: snd_ctl_add error (0x%X)\n", err); 718 dev_err(chip->card->dev, "snd_ctl_add error (0x%X)\n", err);
721 return err; 719 return err;
722 } 720 }
723 721
diff --git a/sound/pci/aw2/aw2-saa7146.c b/sound/pci/aw2/aw2-saa7146.c
index 4439636971eb..6d24e9536777 100644
--- a/sound/pci/aw2/aw2-saa7146.c
+++ b/sound/pci/aw2/aw2-saa7146.c
@@ -204,8 +204,7 @@ void snd_aw2_saa7146_pcm_init_playback(struct snd_aw2_saa7146 *chip,
204 /* Define upper limit for DMA access */ 204 /* Define upper limit for DMA access */
205 WRITEREG(dma_addr + buffer_size, ProtA1_out); 205 WRITEREG(dma_addr + buffer_size, ProtA1_out);
206 } else { 206 } else {
207 printk(KERN_ERR 207 pr_err("aw2: snd_aw2_saa7146_pcm_init_playback: "
208 "aw2: snd_aw2_saa7146_pcm_init_playback: "
209 "Substream number is not 0 or 1 -> not managed\n"); 208 "Substream number is not 0 or 1 -> not managed\n");
210 } 209 }
211} 210}
@@ -251,8 +250,7 @@ void snd_aw2_saa7146_pcm_init_capture(struct snd_aw2_saa7146 *chip,
251 /* Define upper limit for DMA access */ 250 /* Define upper limit for DMA access */
252 WRITEREG(dma_addr + buffer_size, ProtA1_in); 251 WRITEREG(dma_addr + buffer_size, ProtA1_in);
253 } else { 252 } else {
254 printk(KERN_ERR 253 pr_err("aw2: snd_aw2_saa7146_pcm_init_capture: "
255 "aw2: snd_aw2_saa7146_pcm_init_capture: "
256 "Substream number is not 0 -> not managed\n"); 254 "Substream number is not 0 -> not managed\n");
257 } 255 }
258} 256}
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 1aef7128f7ca..c9216c0a9c8b 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -238,61 +238,6 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
238 2>/dev/null 238 2>/dev/null
239*/ 239*/
240 240
241#define DEBUG_MISC 0
242#define DEBUG_CALLS 0
243#define DEBUG_MIXER 0
244#define DEBUG_CODEC 0
245#define DEBUG_TIMER 0
246#define DEBUG_GAME 0
247#define DEBUG_PM 0
248#define MIXER_TESTING 0
249
250#if DEBUG_MISC
251#define snd_azf3328_dbgmisc(format, args...) printk(KERN_DEBUG format, ##args)
252#else
253#define snd_azf3328_dbgmisc(format, args...)
254#endif
255
256#if DEBUG_CALLS
257#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
258#define snd_azf3328_dbgcallenter() printk(KERN_DEBUG "--> %s\n", __func__)
259#define snd_azf3328_dbgcallleave() printk(KERN_DEBUG "<-- %s\n", __func__)
260#else
261#define snd_azf3328_dbgcalls(format, args...)
262#define snd_azf3328_dbgcallenter()
263#define snd_azf3328_dbgcallleave()
264#endif
265
266#if DEBUG_MIXER
267#define snd_azf3328_dbgmixer(format, args...) printk(KERN_DEBUG format, ##args)
268#else
269#define snd_azf3328_dbgmixer(format, args...)
270#endif
271
272#if DEBUG_CODEC
273#define snd_azf3328_dbgcodec(format, args...) printk(KERN_DEBUG format, ##args)
274#else
275#define snd_azf3328_dbgcodec(format, args...)
276#endif
277
278#if DEBUG_MISC
279#define snd_azf3328_dbgtimer(format, args...) printk(KERN_DEBUG format, ##args)
280#else
281#define snd_azf3328_dbgtimer(format, args...)
282#endif
283
284#if DEBUG_GAME
285#define snd_azf3328_dbggame(format, args...) printk(KERN_DEBUG format, ##args)
286#else
287#define snd_azf3328_dbggame(format, args...)
288#endif
289
290#if DEBUG_PM
291#define snd_azf3328_dbgpm(format, args...) printk(KERN_DEBUG format, ##args)
292#else
293#define snd_azf3328_dbgpm(format, args...)
294#endif
295
296static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 241static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
297module_param_array(index, int, NULL, 0444); 242module_param_array(index, int, NULL, 0444);
298MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard."); 243MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard.");
@@ -475,6 +420,12 @@ snd_azf3328_ctrl_inb(const struct snd_azf3328 *chip, unsigned reg)
475 return inb(chip->ctrl_io + reg); 420 return inb(chip->ctrl_io + reg);
476} 421}
477 422
423static inline u16
424snd_azf3328_ctrl_inw(const struct snd_azf3328 *chip, unsigned reg)
425{
426 return inw(chip->ctrl_io + reg);
427}
428
478static inline void 429static inline void
479snd_azf3328_ctrl_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value) 430snd_azf3328_ctrl_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
480{ 431{
@@ -578,11 +529,12 @@ snd_azf3328_mixer_reset(const struct snd_azf3328 *chip)
578#ifdef AZF_USE_AC97_LAYER 529#ifdef AZF_USE_AC97_LAYER
579 530
580static inline void 531static inline void
581snd_azf3328_mixer_ac97_map_unsupported(unsigned short reg, const char *mode) 532snd_azf3328_mixer_ac97_map_unsupported(const struct snd_azf3328 *chip,
533 unsigned short reg, const char *mode)
582{ 534{
583 /* need to add some more or less clever emulation? */ 535 /* need to add some more or less clever emulation? */
584 printk(KERN_WARNING 536 dev_warn(chip->card->dev,
585 "azt3328: missing %s emulation for AC97 register 0x%02x!\n", 537 "missing %s emulation for AC97 register 0x%02x!\n",
586 mode, reg); 538 mode, reg);
587} 539}
588 540
@@ -717,10 +669,8 @@ snd_azf3328_mixer_ac97_read(struct snd_ac97 *ac97, unsigned short reg_ac97)
717 unsigned short reg_val = 0; 669 unsigned short reg_val = 0;
718 bool unsupported = false; 670 bool unsupported = false;
719 671
720 snd_azf3328_dbgmixer( 672 dev_dbg(chip->card->dev, "snd_azf3328_mixer_ac97_read reg_ac97 %u\n",
721 "snd_azf3328_mixer_ac97_read reg_ac97 %u\n", 673 reg_ac97);
722 reg_ac97
723 );
724 if (reg_azf & AZF_AC97_REG_UNSUPPORTED) 674 if (reg_azf & AZF_AC97_REG_UNSUPPORTED)
725 unsupported = true; 675 unsupported = true;
726 else { 676 else {
@@ -765,7 +715,7 @@ snd_azf3328_mixer_ac97_read(struct snd_ac97 *ac97, unsigned short reg_ac97)
765 } 715 }
766 } 716 }
767 if (unsupported) 717 if (unsupported)
768 snd_azf3328_mixer_ac97_map_unsupported(reg_ac97, "read"); 718 snd_azf3328_mixer_ac97_map_unsupported(chip, reg_ac97, "read");
769 719
770 return reg_val; 720 return reg_val;
771} 721}
@@ -778,10 +728,9 @@ snd_azf3328_mixer_ac97_write(struct snd_ac97 *ac97,
778 unsigned short reg_azf = snd_azf3328_mixer_ac97_map_reg_idx(reg_ac97); 728 unsigned short reg_azf = snd_azf3328_mixer_ac97_map_reg_idx(reg_ac97);
779 bool unsupported = false; 729 bool unsupported = false;
780 730
781 snd_azf3328_dbgmixer( 731 dev_dbg(chip->card->dev,
782 "snd_azf3328_mixer_ac97_write reg_ac97 %u val %u\n", 732 "snd_azf3328_mixer_ac97_write reg_ac97 %u val %u\n",
783 reg_ac97, val 733 reg_ac97, val);
784 );
785 if (reg_azf & AZF_AC97_REG_UNSUPPORTED) 734 if (reg_azf & AZF_AC97_REG_UNSUPPORTED)
786 unsupported = true; 735 unsupported = true;
787 else { 736 else {
@@ -814,7 +763,7 @@ snd_azf3328_mixer_ac97_write(struct snd_ac97 *ac97,
814 } 763 }
815 } 764 }
816 if (unsupported) 765 if (unsupported)
817 snd_azf3328_mixer_ac97_map_unsupported(reg_ac97, "write"); 766 snd_azf3328_mixer_ac97_map_unsupported(chip, reg_ac97, "write");
818} 767}
819 768
820static int 769static int
@@ -850,7 +799,7 @@ snd_azf3328_mixer_new(struct snd_azf3328 *chip)
850 * due to this card being a very quirky AC97 "lookalike". 799 * due to this card being a very quirky AC97 "lookalike".
851 */ 800 */
852 if (rc) 801 if (rc)
853 printk(KERN_ERR "azt3328: AC97 init failed, err %d!\n", rc); 802 dev_err(chip->card->dev, "AC97 init failed, err %d!\n", rc);
854 803
855 /* If we return an error here, then snd_card_free() should 804 /* If we return an error here, then snd_card_free() should
856 * free up any ac97 codecs that got created, as well as the bus. 805 * free up any ac97 codecs that got created, as well as the bus.
@@ -870,8 +819,6 @@ snd_azf3328_mixer_write_volume_gradually(const struct snd_azf3328 *chip,
870 unsigned char curr_vol_left = 0, curr_vol_right = 0; 819 unsigned char curr_vol_left = 0, curr_vol_right = 0;
871 int left_change = 0, right_change = 0; 820 int left_change = 0, right_change = 0;
872 821
873 snd_azf3328_dbgcallenter();
874
875 if (chan_sel & SET_CHAN_LEFT) { 822 if (chan_sel & SET_CHAN_LEFT) {
876 curr_vol_left = inb(portbase + 1); 823 curr_vol_left = inb(portbase + 1);
877 824
@@ -912,7 +859,6 @@ snd_azf3328_mixer_write_volume_gradually(const struct snd_azf3328 *chip,
912 if (delay) 859 if (delay)
913 mdelay(delay); 860 mdelay(delay);
914 } while ((left_change) || (right_change)); 861 } while ((left_change) || (right_change));
915 snd_azf3328_dbgcallleave();
916} 862}
917 863
918/* 864/*
@@ -990,14 +936,12 @@ snd_azf3328_info_mixer(struct snd_kcontrol *kcontrol,
990{ 936{
991 struct azf3328_mixer_reg reg; 937 struct azf3328_mixer_reg reg;
992 938
993 snd_azf3328_dbgcallenter();
994 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 939 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
995 uinfo->type = reg.mask == 1 ? 940 uinfo->type = reg.mask == 1 ?
996 SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; 941 SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
997 uinfo->count = reg.stereo + 1; 942 uinfo->count = reg.stereo + 1;
998 uinfo->value.integer.min = 0; 943 uinfo->value.integer.min = 0;
999 uinfo->value.integer.max = reg.mask; 944 uinfo->value.integer.max = reg.mask;
1000 snd_azf3328_dbgcallleave();
1001 return 0; 945 return 0;
1002} 946}
1003 947
@@ -1009,7 +953,6 @@ snd_azf3328_get_mixer(struct snd_kcontrol *kcontrol,
1009 struct azf3328_mixer_reg reg; 953 struct azf3328_mixer_reg reg;
1010 u16 oreg, val; 954 u16 oreg, val;
1011 955
1012 snd_azf3328_dbgcallenter();
1013 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 956 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
1014 957
1015 oreg = snd_azf3328_mixer_inw(chip, reg.reg); 958 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
@@ -1023,12 +966,11 @@ snd_azf3328_get_mixer(struct snd_kcontrol *kcontrol,
1023 val = reg.mask - val; 966 val = reg.mask - val;
1024 ucontrol->value.integer.value[1] = val; 967 ucontrol->value.integer.value[1] = val;
1025 } 968 }
1026 snd_azf3328_dbgmixer("get: %02x is %04x -> vol %02lx|%02lx " 969 dev_dbg(chip->card->dev,
1027 "(shift %02d|%02d, mask %02x, inv. %d, stereo %d)\n", 970 "get: %02x is %04x -> vol %02lx|%02lx (shift %02d|%02d, mask %02x, inv. %d, stereo %d)\n",
1028 reg.reg, oreg, 971 reg.reg, oreg,
1029 ucontrol->value.integer.value[0], ucontrol->value.integer.value[1], 972 ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
1030 reg.lchan_shift, reg.rchan_shift, reg.mask, reg.invert, reg.stereo); 973 reg.lchan_shift, reg.rchan_shift, reg.mask, reg.invert, reg.stereo);
1031 snd_azf3328_dbgcallleave();
1032 return 0; 974 return 0;
1033} 975}
1034 976
@@ -1040,7 +982,6 @@ snd_azf3328_put_mixer(struct snd_kcontrol *kcontrol,
1040 struct azf3328_mixer_reg reg; 982 struct azf3328_mixer_reg reg;
1041 u16 oreg, nreg, val; 983 u16 oreg, nreg, val;
1042 984
1043 snd_azf3328_dbgcallenter();
1044 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 985 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
1045 oreg = snd_azf3328_mixer_inw(chip, reg.reg); 986 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
1046 val = ucontrol->value.integer.value[0] & reg.mask; 987 val = ucontrol->value.integer.value[0] & reg.mask;
@@ -1064,12 +1005,11 @@ snd_azf3328_put_mixer(struct snd_kcontrol *kcontrol,
1064 else 1005 else
1065 snd_azf3328_mixer_outw(chip, reg.reg, nreg); 1006 snd_azf3328_mixer_outw(chip, reg.reg, nreg);
1066 1007
1067 snd_azf3328_dbgmixer("put: %02x to %02lx|%02lx, " 1008 dev_dbg(chip->card->dev,
1068 "oreg %04x; shift %02d|%02d -> nreg %04x; after: %04x\n", 1009 "put: %02x to %02lx|%02lx, oreg %04x; shift %02d|%02d -> nreg %04x; after: %04x\n",
1069 reg.reg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1], 1010 reg.reg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
1070 oreg, reg.lchan_shift, reg.rchan_shift, 1011 oreg, reg.lchan_shift, reg.rchan_shift,
1071 nreg, snd_azf3328_mixer_inw(chip, reg.reg)); 1012 nreg, snd_azf3328_mixer_inw(chip, reg.reg));
1072 snd_azf3328_dbgcallleave();
1073 return (nreg != oreg); 1013 return (nreg != oreg);
1074} 1014}
1075 1015
@@ -1135,7 +1075,8 @@ snd_azf3328_get_mixer_enum(struct snd_kcontrol *kcontrol,
1135 } else 1075 } else
1136 ucontrol->value.enumerated.item[0] = (val >> reg.lchan_shift) & (reg.enum_c - 1); 1076 ucontrol->value.enumerated.item[0] = (val >> reg.lchan_shift) & (reg.enum_c - 1);
1137 1077
1138 snd_azf3328_dbgmixer("get_enum: %02x is %04x -> %d|%d (shift %02d, enum_c %d)\n", 1078 dev_dbg(chip->card->dev,
1079 "get_enum: %02x is %04x -> %d|%d (shift %02d, enum_c %d)\n",
1139 reg.reg, val, ucontrol->value.enumerated.item[0], ucontrol->value.enumerated.item[1], 1080 reg.reg, val, ucontrol->value.enumerated.item[0], ucontrol->value.enumerated.item[1],
1140 reg.lchan_shift, reg.enum_c); 1081 reg.lchan_shift, reg.enum_c);
1141 return 0; 1082 return 0;
@@ -1167,7 +1108,8 @@ snd_azf3328_put_mixer_enum(struct snd_kcontrol *kcontrol,
1167 snd_azf3328_mixer_outw(chip, reg.reg, val); 1108 snd_azf3328_mixer_outw(chip, reg.reg, val);
1168 nreg = val; 1109 nreg = val;
1169 1110
1170 snd_azf3328_dbgmixer("put_enum: %02x to %04x, oreg %04x\n", reg.reg, val, oreg); 1111 dev_dbg(chip->card->dev,
1112 "put_enum: %02x to %04x, oreg %04x\n", reg.reg, val, oreg);
1171 return (nreg != oreg); 1113 return (nreg != oreg);
1172} 1114}
1173 1115
@@ -1253,7 +1195,6 @@ snd_azf3328_mixer_new(struct snd_azf3328 *chip)
1253 unsigned int idx; 1195 unsigned int idx;
1254 int err; 1196 int err;
1255 1197
1256 snd_azf3328_dbgcallenter();
1257 if (snd_BUG_ON(!chip || !chip->card)) 1198 if (snd_BUG_ON(!chip || !chip->card))
1258 return -EINVAL; 1199 return -EINVAL;
1259 1200
@@ -1279,7 +1220,6 @@ snd_azf3328_mixer_new(struct snd_azf3328 *chip)
1279 snd_component_add(card, "AZF3328 mixer"); 1220 snd_component_add(card, "AZF3328 mixer");
1280 strcpy(card->mixername, "AZF3328 mixer"); 1221 strcpy(card->mixername, "AZF3328 mixer");
1281 1222
1282 snd_azf3328_dbgcallleave();
1283 return 0; 1223 return 0;
1284} 1224}
1285#endif /* AZF_USE_AC97_LAYER */ 1225#endif /* AZF_USE_AC97_LAYER */
@@ -1288,19 +1228,13 @@ static int
1288snd_azf3328_hw_params(struct snd_pcm_substream *substream, 1228snd_azf3328_hw_params(struct snd_pcm_substream *substream,
1289 struct snd_pcm_hw_params *hw_params) 1229 struct snd_pcm_hw_params *hw_params)
1290{ 1230{
1291 int res; 1231 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1292 snd_azf3328_dbgcallenter();
1293 res = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
1294 snd_azf3328_dbgcallleave();
1295 return res;
1296} 1232}
1297 1233
1298static int 1234static int
1299snd_azf3328_hw_free(struct snd_pcm_substream *substream) 1235snd_azf3328_hw_free(struct snd_pcm_substream *substream)
1300{ 1236{
1301 snd_azf3328_dbgcallenter();
1302 snd_pcm_lib_free_pages(substream); 1237 snd_pcm_lib_free_pages(substream);
1303 snd_azf3328_dbgcallleave();
1304 return 0; 1238 return 0;
1305} 1239}
1306 1240
@@ -1315,7 +1249,6 @@ snd_azf3328_codec_setfmt(struct snd_azf3328_codec_data *codec,
1315 u16 val = 0xff00; 1249 u16 val = 0xff00;
1316 u8 freq = 0; 1250 u8 freq = 0;
1317 1251
1318 snd_azf3328_dbgcallenter();
1319 switch (bitrate) { 1252 switch (bitrate) {
1320 case AZF_FREQ_4000: freq = SOUNDFORMAT_FREQ_SUSPECTED_4000; break; 1253 case AZF_FREQ_4000: freq = SOUNDFORMAT_FREQ_SUSPECTED_4000; break;
1321 case AZF_FREQ_4800: freq = SOUNDFORMAT_FREQ_SUSPECTED_4800; break; 1254 case AZF_FREQ_4800: freq = SOUNDFORMAT_FREQ_SUSPECTED_4800; break;
@@ -1379,7 +1312,6 @@ snd_azf3328_codec_setfmt(struct snd_azf3328_codec_data *codec,
1379 ); 1312 );
1380 1313
1381 spin_unlock_irqrestore(codec->lock, flags); 1314 spin_unlock_irqrestore(codec->lock, flags);
1382 snd_azf3328_dbgcallleave();
1383} 1315}
1384 1316
1385static inline void 1317static inline void
@@ -1404,15 +1336,16 @@ snd_azf3328_ctrl_reg_6AH_update(struct snd_azf3328 *chip,
1404 chip->shadow_reg_ctrl_6AH |= bitmask; 1336 chip->shadow_reg_ctrl_6AH |= bitmask;
1405 else 1337 else
1406 chip->shadow_reg_ctrl_6AH &= ~bitmask; 1338 chip->shadow_reg_ctrl_6AH &= ~bitmask;
1407 snd_azf3328_dbgcodec("6AH_update mask 0x%04x do_mask %d: val 0x%04x\n", 1339 dev_dbg(chip->card->dev,
1408 bitmask, do_mask, chip->shadow_reg_ctrl_6AH); 1340 "6AH_update mask 0x%04x do_mask %d: val 0x%04x\n",
1341 bitmask, do_mask, chip->shadow_reg_ctrl_6AH);
1409 snd_azf3328_ctrl_outw(chip, IDX_IO_6AH, chip->shadow_reg_ctrl_6AH); 1342 snd_azf3328_ctrl_outw(chip, IDX_IO_6AH, chip->shadow_reg_ctrl_6AH);
1410} 1343}
1411 1344
1412static inline void 1345static inline void
1413snd_azf3328_ctrl_enable_codecs(struct snd_azf3328 *chip, bool enable) 1346snd_azf3328_ctrl_enable_codecs(struct snd_azf3328 *chip, bool enable)
1414{ 1347{
1415 snd_azf3328_dbgcodec("codec_enable %d\n", enable); 1348 dev_dbg(chip->card->dev, "codec_enable %d\n", enable);
1416 /* no idea what exactly is being done here, but I strongly assume it's 1349 /* no idea what exactly is being done here, but I strongly assume it's
1417 * PM related */ 1350 * PM related */
1418 snd_azf3328_ctrl_reg_6AH_update( 1351 snd_azf3328_ctrl_reg_6AH_update(
@@ -1429,7 +1362,7 @@ snd_azf3328_ctrl_codec_activity(struct snd_azf3328 *chip,
1429 struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type]; 1362 struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
1430 bool need_change = (codec->running != enable); 1363 bool need_change = (codec->running != enable);
1431 1364
1432 snd_azf3328_dbgcodec( 1365 dev_dbg(chip->card->dev,
1433 "codec_activity: %s codec, enable %d, need_change %d\n", 1366 "codec_activity: %s codec, enable %d, need_change %d\n",
1434 codec->name, enable, need_change 1367 codec->name, enable, need_change
1435 ); 1368 );
@@ -1470,13 +1403,13 @@ snd_azf3328_ctrl_codec_activity(struct snd_azf3328 *chip,
1470} 1403}
1471 1404
1472static void 1405static void
1473snd_azf3328_codec_setdmaa(struct snd_azf3328_codec_data *codec, 1406snd_azf3328_codec_setdmaa(struct snd_azf3328 *chip,
1474 unsigned long addr, 1407 struct snd_azf3328_codec_data *codec,
1475 unsigned int period_bytes, 1408 unsigned long addr,
1476 unsigned int buffer_bytes 1409 unsigned int period_bytes,
1410 unsigned int buffer_bytes
1477) 1411)
1478{ 1412{
1479 snd_azf3328_dbgcallenter();
1480 WARN_ONCE(period_bytes & 1, "odd period length!?\n"); 1413 WARN_ONCE(period_bytes & 1, "odd period length!?\n");
1481 WARN_ONCE(buffer_bytes != 2 * period_bytes, 1414 WARN_ONCE(buffer_bytes != 2 * period_bytes,
1482 "missed our input expectations! %u vs. %u\n", 1415 "missed our input expectations! %u vs. %u\n",
@@ -1499,7 +1432,7 @@ snd_azf3328_codec_setdmaa(struct snd_azf3328_codec_data *codec,
1499 setup_io.dma_start_1 = addr; 1432 setup_io.dma_start_1 = addr;
1500 setup_io.dma_start_2 = addr+area_length; 1433 setup_io.dma_start_2 = addr+area_length;
1501 1434
1502 snd_azf3328_dbgcodec( 1435 dev_dbg(chip->card->dev,
1503 "setdma: buffers %08x[%u] / %08x[%u], %u, %u\n", 1436 "setdma: buffers %08x[%u] / %08x[%u], %u, %u\n",
1504 setup_io.dma_start_1, area_length, 1437 setup_io.dma_start_1, area_length,
1505 setup_io.dma_start_2, area_length, 1438 setup_io.dma_start_2, area_length,
@@ -1522,7 +1455,6 @@ snd_azf3328_codec_setdmaa(struct snd_azf3328_codec_data *codec,
1522 ); 1455 );
1523 spin_unlock_irqrestore(codec->lock, flags); 1456 spin_unlock_irqrestore(codec->lock, flags);
1524 } 1457 }
1525 snd_azf3328_dbgcallleave();
1526} 1458}
1527 1459
1528static int 1460static int
@@ -1535,8 +1467,6 @@ snd_azf3328_pcm_prepare(struct snd_pcm_substream *substream)
1535 unsigned int count = snd_pcm_lib_period_bytes(substream); 1467 unsigned int count = snd_pcm_lib_period_bytes(substream);
1536#endif 1468#endif
1537 1469
1538 snd_azf3328_dbgcallenter();
1539
1540 codec->dma_base = runtime->dma_addr; 1470 codec->dma_base = runtime->dma_addr;
1541 1471
1542#if 0 1472#if 0
@@ -1544,10 +1474,9 @@ snd_azf3328_pcm_prepare(struct snd_pcm_substream *substream)
1544 runtime->rate, 1474 runtime->rate,
1545 snd_pcm_format_width(runtime->format), 1475 snd_pcm_format_width(runtime->format),
1546 runtime->channels); 1476 runtime->channels);
1547 snd_azf3328_codec_setdmaa(codec, 1477 snd_azf3328_codec_setdmaa(chip, codec,
1548 runtime->dma_addr, count, size); 1478 runtime->dma_addr, count, size);
1549#endif 1479#endif
1550 snd_azf3328_dbgcallleave();
1551 return 0; 1480 return 0;
1552} 1481}
1553 1482
@@ -1562,11 +1491,9 @@ snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1562 bool previously_muted = false; 1491 bool previously_muted = false;
1563 bool is_main_mixer_playback_codec = (AZF_CODEC_PLAYBACK == codec->type); 1492 bool is_main_mixer_playback_codec = (AZF_CODEC_PLAYBACK == codec->type);
1564 1493
1565 snd_azf3328_dbgcalls("snd_azf3328_pcm_trigger cmd %d\n", cmd);
1566
1567 switch (cmd) { 1494 switch (cmd) {
1568 case SNDRV_PCM_TRIGGER_START: 1495 case SNDRV_PCM_TRIGGER_START:
1569 snd_azf3328_dbgcodec("START %s\n", codec->name); 1496 dev_dbg(chip->card->dev, "START PCM %s\n", codec->name);
1570 1497
1571 if (is_main_mixer_playback_codec) { 1498 if (is_main_mixer_playback_codec) {
1572 /* mute WaveOut (avoid clicking during setup) */ 1499 /* mute WaveOut (avoid clicking during setup) */
@@ -1593,7 +1520,7 @@ snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1593 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_IRQTYPE, 0xffff); 1520 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_IRQTYPE, 0xffff);
1594 spin_unlock(codec->lock); 1521 spin_unlock(codec->lock);
1595 1522
1596 snd_azf3328_codec_setdmaa(codec, runtime->dma_addr, 1523 snd_azf3328_codec_setdmaa(chip, codec, runtime->dma_addr,
1597 snd_pcm_lib_period_bytes(substream), 1524 snd_pcm_lib_period_bytes(substream),
1598 snd_pcm_lib_buffer_bytes(substream) 1525 snd_pcm_lib_buffer_bytes(substream)
1599 ); 1526 );
@@ -1633,10 +1560,10 @@ snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1633 ); 1560 );
1634 } 1561 }
1635 1562
1636 snd_azf3328_dbgcodec("STARTED %s\n", codec->name); 1563 dev_dbg(chip->card->dev, "PCM STARTED %s\n", codec->name);
1637 break; 1564 break;
1638 case SNDRV_PCM_TRIGGER_RESUME: 1565 case SNDRV_PCM_TRIGGER_RESUME:
1639 snd_azf3328_dbgcodec("RESUME %s\n", codec->name); 1566 dev_dbg(chip->card->dev, "PCM RESUME %s\n", codec->name);
1640 /* resume codec if we were active */ 1567 /* resume codec if we were active */
1641 spin_lock(codec->lock); 1568 spin_lock(codec->lock);
1642 if (codec->running) 1569 if (codec->running)
@@ -1648,7 +1575,7 @@ snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1648 spin_unlock(codec->lock); 1575 spin_unlock(codec->lock);
1649 break; 1576 break;
1650 case SNDRV_PCM_TRIGGER_STOP: 1577 case SNDRV_PCM_TRIGGER_STOP:
1651 snd_azf3328_dbgcodec("STOP %s\n", codec->name); 1578 dev_dbg(chip->card->dev, "PCM STOP %s\n", codec->name);
1652 1579
1653 if (is_main_mixer_playback_codec) { 1580 if (is_main_mixer_playback_codec) {
1654 /* mute WaveOut (avoid clicking during setup) */ 1581 /* mute WaveOut (avoid clicking during setup) */
@@ -1684,10 +1611,10 @@ snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1684 ); 1611 );
1685 } 1612 }
1686 1613
1687 snd_azf3328_dbgcodec("STOPPED %s\n", codec->name); 1614 dev_dbg(chip->card->dev, "PCM STOPPED %s\n", codec->name);
1688 break; 1615 break;
1689 case SNDRV_PCM_TRIGGER_SUSPEND: 1616 case SNDRV_PCM_TRIGGER_SUSPEND:
1690 snd_azf3328_dbgcodec("SUSPEND %s\n", codec->name); 1617 dev_dbg(chip->card->dev, "PCM SUSPEND %s\n", codec->name);
1691 /* make sure codec is stopped */ 1618 /* make sure codec is stopped */
1692 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS, 1619 snd_azf3328_codec_outw(codec, IDX_IO_CODEC_DMA_FLAGS,
1693 snd_azf3328_codec_inw( 1620 snd_azf3328_codec_inw(
@@ -1696,17 +1623,16 @@ snd_azf3328_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1696 ); 1623 );
1697 break; 1624 break;
1698 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1625 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1699 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n"); 1626 WARN(1, "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
1700 break; 1627 break;
1701 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1628 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1702 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n"); 1629 WARN(1, "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
1703 break; 1630 break;
1704 default: 1631 default:
1705 snd_printk(KERN_ERR "FIXME: unknown trigger mode!\n"); 1632 WARN(1, "FIXME: unknown trigger mode!\n");
1706 return -EINVAL; 1633 return -EINVAL;
1707 } 1634 }
1708 1635
1709 snd_azf3328_dbgcallleave();
1710 return result; 1636 return result;
1711} 1637}
1712 1638
@@ -1728,8 +1654,8 @@ snd_azf3328_pcm_pointer(struct snd_pcm_substream *substream
1728 result -= codec->dma_base; 1654 result -= codec->dma_base;
1729#endif 1655#endif
1730 frmres = bytes_to_frames( substream->runtime, result); 1656 frmres = bytes_to_frames( substream->runtime, result);
1731 snd_azf3328_dbgcodec("%08li %s @ 0x%8lx, frames %8ld\n", 1657 dev_dbg(substream->pcm->card->dev, "%08li %s @ 0x%8lx, frames %8ld\n",
1732 jiffies, codec->name, result, frmres); 1658 jiffies, codec->name, result, frmres);
1733 return frmres; 1659 return frmres;
1734} 1660}
1735 1661
@@ -1792,7 +1718,7 @@ snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
1792 * skeleton handler only 1718 * skeleton handler only
1793 * (we do not want axis reading in interrupt handler - too much load!) 1719 * (we do not want axis reading in interrupt handler - too much load!)
1794 */ 1720 */
1795 snd_azf3328_dbggame("gameport irq\n"); 1721 dev_dbg(chip->card->dev, "gameport irq\n");
1796 1722
1797 /* this should ACK the gameport IRQ properly, hopefully. */ 1723 /* this should ACK the gameport IRQ properly, hopefully. */
1798 snd_azf3328_game_inw(chip, IDX_GAME_AXIS_VALUE); 1724 snd_azf3328_game_inw(chip, IDX_GAME_AXIS_VALUE);
@@ -1804,7 +1730,7 @@ snd_azf3328_gameport_open(struct gameport *gameport, int mode)
1804 struct snd_azf3328 *chip = gameport_get_port_data(gameport); 1730 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1805 int res; 1731 int res;
1806 1732
1807 snd_azf3328_dbggame("gameport_open, mode %d\n", mode); 1733 dev_dbg(chip->card->dev, "gameport_open, mode %d\n", mode);
1808 switch (mode) { 1734 switch (mode) {
1809 case GAMEPORT_MODE_COOKED: 1735 case GAMEPORT_MODE_COOKED:
1810 case GAMEPORT_MODE_RAW: 1736 case GAMEPORT_MODE_RAW:
@@ -1827,7 +1753,7 @@ snd_azf3328_gameport_close(struct gameport *gameport)
1827{ 1753{
1828 struct snd_azf3328 *chip = gameport_get_port_data(gameport); 1754 struct snd_azf3328 *chip = gameport_get_port_data(gameport);
1829 1755
1830 snd_azf3328_dbggame("gameport_close\n"); 1756 dev_dbg(chip->card->dev, "gameport_close\n");
1831 snd_azf3328_gameport_set_counter_frequency(chip, 1757 snd_azf3328_gameport_set_counter_frequency(chip,
1832 GAME_HWCFG_ADC_COUNTER_FREQ_1_200); 1758 GAME_HWCFG_ADC_COUNTER_FREQ_1_200);
1833 snd_azf3328_gameport_axis_circuit_enable(chip, 0); 1759 snd_azf3328_gameport_axis_circuit_enable(chip, 0);
@@ -1892,9 +1818,8 @@ snd_azf3328_gameport_cooked_read(struct gameport *gameport,
1892 axes[i] = -1; 1818 axes[i] = -1;
1893 } 1819 }
1894 1820
1895 snd_azf3328_dbggame("cooked_read: axes %d %d %d %d buttons %d\n", 1821 dev_dbg(chip->card->dev, "cooked_read: axes %d %d %d %d buttons %d\n",
1896 axes[0], axes[1], axes[2], axes[3], *buttons 1822 axes[0], axes[1], axes[2], axes[3], *buttons);
1897 );
1898 1823
1899 return 0; 1824 return 0;
1900} 1825}
@@ -1906,7 +1831,7 @@ snd_azf3328_gameport(struct snd_azf3328 *chip, int dev)
1906 1831
1907 chip->gameport = gp = gameport_allocate_port(); 1832 chip->gameport = gp = gameport_allocate_port();
1908 if (!gp) { 1833 if (!gp) {
1909 printk(KERN_ERR "azt3328: cannot alloc memory for gameport\n"); 1834 dev_err(chip->card->dev, "cannot alloc memory for gameport\n");
1910 return -ENOMEM; 1835 return -ENOMEM;
1911 } 1836 }
1912 1837
@@ -1950,23 +1875,23 @@ snd_azf3328_gameport_free(struct snd_azf3328 *chip) { }
1950static inline void 1875static inline void
1951snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip) 1876snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
1952{ 1877{
1953 printk(KERN_WARNING "huh, game port IRQ occurred!?\n"); 1878 dev_warn(chip->card->dev, "huh, game port IRQ occurred!?\n");
1954} 1879}
1955#endif /* SUPPORT_GAMEPORT */ 1880#endif /* SUPPORT_GAMEPORT */
1956 1881
1957/******************************************************************/ 1882/******************************************************************/
1958 1883
1959static inline void 1884static inline void
1960snd_azf3328_irq_log_unknown_type(u8 which) 1885snd_azf3328_irq_log_unknown_type(struct snd_azf3328 *chip, u8 which)
1961{ 1886{
1962 snd_azf3328_dbgcodec( 1887 dev_dbg(chip->card->dev,
1963 "azt3328: unknown IRQ type (%x) occurred, please report!\n", 1888 "unknown IRQ type (%x) occurred, please report!\n",
1964 which 1889 which);
1965 );
1966} 1890}
1967 1891
1968static inline void 1892static inline void
1969snd_azf3328_pcm_interrupt(const struct snd_azf3328_codec_data *first_codec, 1893snd_azf3328_pcm_interrupt(struct snd_azf3328 *chip,
1894 const struct snd_azf3328_codec_data *first_codec,
1970 u8 status 1895 u8 status
1971) 1896)
1972{ 1897{
@@ -1990,17 +1915,15 @@ snd_azf3328_pcm_interrupt(const struct snd_azf3328_codec_data *first_codec,
1990 1915
1991 if (codec->substream) { 1916 if (codec->substream) {
1992 snd_pcm_period_elapsed(codec->substream); 1917 snd_pcm_period_elapsed(codec->substream);
1993 snd_azf3328_dbgcodec("%s period done (#%x), @ %x\n", 1918 dev_dbg(chip->card->dev, "%s period done (#%x), @ %x\n",
1994 codec->name, 1919 codec->name,
1995 which, 1920 which,
1996 snd_azf3328_codec_inl( 1921 snd_azf3328_codec_inl(
1997 codec, IDX_IO_CODEC_DMA_CURRPOS 1922 codec, IDX_IO_CODEC_DMA_CURRPOS));
1998 )
1999 );
2000 } else 1923 } else
2001 printk(KERN_WARNING "azt3328: irq handler problem!\n"); 1924 dev_warn(chip->card->dev, "irq handler problem!\n");
2002 if (which & IRQ_SOMETHING) 1925 if (which & IRQ_SOMETHING)
2003 snd_azf3328_irq_log_unknown_type(which); 1926 snd_azf3328_irq_log_unknown_type(chip, which);
2004 } 1927 }
2005} 1928}
2006 1929
@@ -2009,9 +1932,7 @@ snd_azf3328_interrupt(int irq, void *dev_id)
2009{ 1932{
2010 struct snd_azf3328 *chip = dev_id; 1933 struct snd_azf3328 *chip = dev_id;
2011 u8 status; 1934 u8 status;
2012#if DEBUG_CODEC
2013 static unsigned long irq_count; 1935 static unsigned long irq_count;
2014#endif
2015 1936
2016 status = snd_azf3328_ctrl_inb(chip, IDX_IO_IRQSTATUS); 1937 status = snd_azf3328_ctrl_inb(chip, IDX_IO_IRQSTATUS);
2017 1938
@@ -2022,14 +1943,13 @@ snd_azf3328_interrupt(int irq, void *dev_id)
2022 )) 1943 ))
2023 return IRQ_NONE; /* must be interrupt for another device */ 1944 return IRQ_NONE; /* must be interrupt for another device */
2024 1945
2025 snd_azf3328_dbgcodec( 1946 dev_dbg(chip->card->dev,
2026 "irq_count %ld! IDX_IO_IRQSTATUS %04x\n", 1947 "irq_count %ld! IDX_IO_IRQSTATUS %04x\n",
2027 irq_count++ /* debug-only */, 1948 irq_count++ /* debug-only */,
2028 status 1949 status);
2029 );
2030 1950
2031 if (status & IRQ_TIMER) { 1951 if (status & IRQ_TIMER) {
2032 /* snd_azf3328_dbgcodec("timer %ld\n", 1952 /* dev_dbg(chip->card->dev, "timer %ld\n",
2033 snd_azf3328_codec_inl(chip, IDX_IO_TIMER_VALUE) 1953 snd_azf3328_codec_inl(chip, IDX_IO_TIMER_VALUE)
2034 & TIMER_VALUE_MASK 1954 & TIMER_VALUE_MASK
2035 ); */ 1955 ); */
@@ -2039,11 +1959,11 @@ snd_azf3328_interrupt(int irq, void *dev_id)
2039 spin_lock(&chip->reg_lock); 1959 spin_lock(&chip->reg_lock);
2040 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x07); 1960 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x07);
2041 spin_unlock(&chip->reg_lock); 1961 spin_unlock(&chip->reg_lock);
2042 snd_azf3328_dbgcodec("azt3328: timer IRQ\n"); 1962 dev_dbg(chip->card->dev, "timer IRQ\n");
2043 } 1963 }
2044 1964
2045 if (status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT)) 1965 if (status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_I2S_OUT))
2046 snd_azf3328_pcm_interrupt(chip->codecs, status); 1966 snd_azf3328_pcm_interrupt(chip, chip->codecs, status);
2047 1967
2048 if (status & IRQ_GAMEPORT) 1968 if (status & IRQ_GAMEPORT)
2049 snd_azf3328_gameport_interrupt(chip); 1969 snd_azf3328_gameport_interrupt(chip);
@@ -2055,7 +1975,7 @@ snd_azf3328_interrupt(int irq, void *dev_id)
2055 1975
2056 /* hmm, do we have to ack the IRQ here somehow? 1976 /* hmm, do we have to ack the IRQ here somehow?
2057 * If so, then I don't know how yet... */ 1977 * If so, then I don't know how yet... */
2058 snd_azf3328_dbgcodec("azt3328: MPU401 IRQ\n"); 1978 dev_dbg(chip->card->dev, "MPU401 IRQ\n");
2059 } 1979 }
2060 return IRQ_HANDLED; 1980 return IRQ_HANDLED;
2061} 1981}
@@ -2133,7 +2053,6 @@ snd_azf3328_pcm_open(struct snd_pcm_substream *substream,
2133 struct snd_pcm_runtime *runtime = substream->runtime; 2053 struct snd_pcm_runtime *runtime = substream->runtime;
2134 struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type]; 2054 struct snd_azf3328_codec_data *codec = &chip->codecs[codec_type];
2135 2055
2136 snd_azf3328_dbgcallenter();
2137 codec->substream = substream; 2056 codec->substream = substream;
2138 2057
2139 /* same parameters for all our codecs - at least we think so... */ 2058 /* same parameters for all our codecs - at least we think so... */
@@ -2142,7 +2061,6 @@ snd_azf3328_pcm_open(struct snd_pcm_substream *substream,
2142 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 2061 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
2143 &snd_azf3328_hw_constraints_rates); 2062 &snd_azf3328_hw_constraints_rates);
2144 runtime->private_data = codec; 2063 runtime->private_data = codec;
2145 snd_azf3328_dbgcallleave();
2146 return 0; 2064 return 0;
2147} 2065}
2148 2066
@@ -2171,9 +2089,7 @@ snd_azf3328_pcm_close(struct snd_pcm_substream *substream
2171 struct snd_azf3328_codec_data *codec = 2089 struct snd_azf3328_codec_data *codec =
2172 substream->runtime->private_data; 2090 substream->runtime->private_data;
2173 2091
2174 snd_azf3328_dbgcallenter();
2175 codec->substream = NULL; 2092 codec->substream = NULL;
2176 snd_azf3328_dbgcallleave();
2177 return 0; 2093 return 0;
2178} 2094}
2179 2095
@@ -2220,8 +2136,6 @@ enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS }; /* pcm devices */
2220 struct snd_pcm *pcm; 2136 struct snd_pcm *pcm;
2221 int err; 2137 int err;
2222 2138
2223 snd_azf3328_dbgcallenter();
2224
2225 err = snd_pcm_new(chip->card, "AZF3328 DSP", AZF_PCMDEV_STD, 2139 err = snd_pcm_new(chip->card, "AZF3328 DSP", AZF_PCMDEV_STD,
2226 1, 1, &pcm); 2140 1, 1, &pcm);
2227 if (err < 0) 2141 if (err < 0)
@@ -2258,7 +2172,6 @@ enum { AZF_PCMDEV_STD, AZF_PCMDEV_I2S_OUT, NUM_AZF_PCMDEVS }; /* pcm devices */
2258 snd_dma_pci_data(chip->pci), 2172 snd_dma_pci_data(chip->pci),
2259 64*1024, 64*1024); 2173 64*1024, 64*1024);
2260 2174
2261 snd_azf3328_dbgcallleave();
2262 return 0; 2175 return 0;
2263} 2176}
2264 2177
@@ -2281,7 +2194,6 @@ snd_azf3328_timer_start(struct snd_timer *timer)
2281 unsigned long flags; 2194 unsigned long flags;
2282 unsigned int delay; 2195 unsigned int delay;
2283 2196
2284 snd_azf3328_dbgcallenter();
2285 chip = snd_timer_chip(timer); 2197 chip = snd_timer_chip(timer);
2286 delay = ((timer->sticks * seqtimer_scaling) - 1) & TIMER_VALUE_MASK; 2198 delay = ((timer->sticks * seqtimer_scaling) - 1) & TIMER_VALUE_MASK;
2287 if (delay < 49) { 2199 if (delay < 49) {
@@ -2289,15 +2201,14 @@ snd_azf3328_timer_start(struct snd_timer *timer)
2289 * this timing tweak 2201 * this timing tweak
2290 * (we need to do it to avoid a lockup, though) */ 2202 * (we need to do it to avoid a lockup, though) */
2291 2203
2292 snd_azf3328_dbgtimer("delay was too low (%d)!\n", delay); 2204 dev_dbg(chip->card->dev, "delay was too low (%d)!\n", delay);
2293 delay = 49; /* minimum time is 49 ticks */ 2205 delay = 49; /* minimum time is 49 ticks */
2294 } 2206 }
2295 snd_azf3328_dbgtimer("setting timer countdown value %d\n", delay); 2207 dev_dbg(chip->card->dev, "setting timer countdown value %d\n", delay);
2296 delay |= TIMER_COUNTDOWN_ENABLE | TIMER_IRQ_ENABLE; 2208 delay |= TIMER_COUNTDOWN_ENABLE | TIMER_IRQ_ENABLE;
2297 spin_lock_irqsave(&chip->reg_lock, flags); 2209 spin_lock_irqsave(&chip->reg_lock, flags);
2298 snd_azf3328_ctrl_outl(chip, IDX_IO_TIMER_VALUE, delay); 2210 snd_azf3328_ctrl_outl(chip, IDX_IO_TIMER_VALUE, delay);
2299 spin_unlock_irqrestore(&chip->reg_lock, flags); 2211 spin_unlock_irqrestore(&chip->reg_lock, flags);
2300 snd_azf3328_dbgcallleave();
2301 return 0; 2212 return 0;
2302} 2213}
2303 2214
@@ -2307,7 +2218,6 @@ snd_azf3328_timer_stop(struct snd_timer *timer)
2307 struct snd_azf3328 *chip; 2218 struct snd_azf3328 *chip;
2308 unsigned long flags; 2219 unsigned long flags;
2309 2220
2310 snd_azf3328_dbgcallenter();
2311 chip = snd_timer_chip(timer); 2221 chip = snd_timer_chip(timer);
2312 spin_lock_irqsave(&chip->reg_lock, flags); 2222 spin_lock_irqsave(&chip->reg_lock, flags);
2313 /* disable timer countdown and interrupt */ 2223 /* disable timer countdown and interrupt */
@@ -2319,7 +2229,6 @@ snd_azf3328_timer_stop(struct snd_timer *timer)
2319 the hardware/ALSA interrupt activity. */ 2229 the hardware/ALSA interrupt activity. */
2320 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x04); 2230 snd_azf3328_ctrl_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x04);
2321 spin_unlock_irqrestore(&chip->reg_lock, flags); 2231 spin_unlock_irqrestore(&chip->reg_lock, flags);
2322 snd_azf3328_dbgcallleave();
2323 return 0; 2232 return 0;
2324} 2233}
2325 2234
@@ -2328,10 +2237,8 @@ static int
2328snd_azf3328_timer_precise_resolution(struct snd_timer *timer, 2237snd_azf3328_timer_precise_resolution(struct snd_timer *timer,
2329 unsigned long *num, unsigned long *den) 2238 unsigned long *num, unsigned long *den)
2330{ 2239{
2331 snd_azf3328_dbgcallenter();
2332 *num = 1; 2240 *num = 1;
2333 *den = 1024000 / seqtimer_scaling; 2241 *den = 1024000 / seqtimer_scaling;
2334 snd_azf3328_dbgcallleave();
2335 return 0; 2242 return 0;
2336} 2243}
2337 2244
@@ -2351,7 +2258,6 @@ snd_azf3328_timer(struct snd_azf3328 *chip, int device)
2351 struct snd_timer_id tid; 2258 struct snd_timer_id tid;
2352 int err; 2259 int err;
2353 2260
2354 snd_azf3328_dbgcallenter();
2355 tid.dev_class = SNDRV_TIMER_CLASS_CARD; 2261 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
2356 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; 2262 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
2357 tid.card = chip->card->number; 2263 tid.card = chip->card->number;
@@ -2376,7 +2282,6 @@ snd_azf3328_timer(struct snd_azf3328 *chip, int device)
2376 err = 0; 2282 err = 0;
2377 2283
2378out: 2284out:
2379 snd_azf3328_dbgcallleave();
2380 return err; 2285 return err;
2381} 2286}
2382 2287
@@ -2438,34 +2343,34 @@ snd_azf3328_test_bit(unsigned unsigned reg, int bit)
2438static inline void 2343static inline void
2439snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip) 2344snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip)
2440{ 2345{
2441#if DEBUG_MISC
2442 u16 tmp; 2346 u16 tmp;
2443 2347
2444 snd_azf3328_dbgmisc( 2348 dev_dbg(chip->card->dev,
2445 "ctrl_io 0x%lx, game_io 0x%lx, mpu_io 0x%lx, " 2349 "ctrl_io 0x%lx, game_io 0x%lx, mpu_io 0x%lx, "
2446 "opl3_io 0x%lx, mixer_io 0x%lx, irq %d\n", 2350 "opl3_io 0x%lx, mixer_io 0x%lx, irq %d\n",
2447 chip->ctrl_io, chip->game_io, chip->mpu_io, 2351 chip->ctrl_io, chip->game_io, chip->mpu_io,
2448 chip->opl3_io, chip->mixer_io, chip->irq 2352 chip->opl3_io, chip->mixer_io, chip->irq);
2449 );
2450 2353
2451 snd_azf3328_dbgmisc("game %02x %02x %02x %02x %02x %02x\n", 2354 dev_dbg(chip->card->dev,
2355 "game %02x %02x %02x %02x %02x %02x\n",
2452 snd_azf3328_game_inb(chip, 0), 2356 snd_azf3328_game_inb(chip, 0),
2453 snd_azf3328_game_inb(chip, 1), 2357 snd_azf3328_game_inb(chip, 1),
2454 snd_azf3328_game_inb(chip, 2), 2358 snd_azf3328_game_inb(chip, 2),
2455 snd_azf3328_game_inb(chip, 3), 2359 snd_azf3328_game_inb(chip, 3),
2456 snd_azf3328_game_inb(chip, 4), 2360 snd_azf3328_game_inb(chip, 4),
2457 snd_azf3328_game_inb(chip, 5) 2361 snd_azf3328_game_inb(chip, 5));
2458 );
2459 2362
2460 for (tmp = 0; tmp < 0x07; tmp += 1) 2363 for (tmp = 0; tmp < 0x07; tmp += 1)
2461 snd_azf3328_dbgmisc("mpu_io 0x%04x\n", inb(chip->mpu_io + tmp)); 2364 dev_dbg(chip->card->dev,
2365 "mpu_io 0x%04x\n", inb(chip->mpu_io + tmp));
2462 2366
2463 for (tmp = 0; tmp <= 0x07; tmp += 1) 2367 for (tmp = 0; tmp <= 0x07; tmp += 1)
2464 snd_azf3328_dbgmisc("0x%02x: game200 0x%04x, game208 0x%04x\n", 2368 dev_dbg(chip->card->dev,
2369 "0x%02x: game200 0x%04x, game208 0x%04x\n",
2465 tmp, inb(0x200 + tmp), inb(0x208 + tmp)); 2370 tmp, inb(0x200 + tmp), inb(0x208 + tmp));
2466 2371
2467 for (tmp = 0; tmp <= 0x01; tmp += 1) 2372 for (tmp = 0; tmp <= 0x01; tmp += 1)
2468 snd_azf3328_dbgmisc( 2373 dev_dbg(chip->card->dev,
2469 "0x%02x: mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, " 2374 "0x%02x: mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, "
2470 "mpu330 0x%04x opl388 0x%04x opl38c 0x%04x\n", 2375 "mpu330 0x%04x opl388 0x%04x opl38c 0x%04x\n",
2471 tmp, 2376 tmp,
@@ -2474,19 +2379,17 @@ snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip)
2474 inb(0x320 + tmp), 2379 inb(0x320 + tmp),
2475 inb(0x330 + tmp), 2380 inb(0x330 + tmp),
2476 inb(0x388 + tmp), 2381 inb(0x388 + tmp),
2477 inb(0x38c + tmp) 2382 inb(0x38c + tmp));
2478 );
2479 2383
2480 for (tmp = 0; tmp < AZF_IO_SIZE_CTRL; tmp += 2) 2384 for (tmp = 0; tmp < AZF_IO_SIZE_CTRL; tmp += 2)
2481 snd_azf3328_dbgmisc("ctrl 0x%02x: 0x%04x\n", 2385 dev_dbg(chip->card->dev,
2482 tmp, snd_azf3328_ctrl_inw(chip, tmp) 2386 "ctrl 0x%02x: 0x%04x\n",
2483 ); 2387 tmp, snd_azf3328_ctrl_inw(chip, tmp));
2484 2388
2485 for (tmp = 0; tmp < AZF_IO_SIZE_MIXER; tmp += 2) 2389 for (tmp = 0; tmp < AZF_IO_SIZE_MIXER; tmp += 2)
2486 snd_azf3328_dbgmisc("mixer 0x%02x: 0x%04x\n", 2390 dev_dbg(chip->card->dev,
2487 tmp, snd_azf3328_mixer_inw(chip, tmp) 2391 "mixer 0x%02x: 0x%04x\n",
2488 ); 2392 tmp, snd_azf3328_mixer_inw(chip, tmp));
2489#endif /* DEBUG_MISC */
2490} 2393}
2491 2394
2492static int 2395static int
@@ -2523,8 +2426,8 @@ snd_azf3328_create(struct snd_card *card,
2523 /* check if we can restrict PCI DMA transfers to 24 bits */ 2426 /* check if we can restrict PCI DMA transfers to 24 bits */
2524 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 || 2427 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 ||
2525 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) { 2428 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) {
2526 snd_printk(KERN_ERR "architecture does not support " 2429 dev_err(card->dev,
2527 "24bit PCI busmaster DMA\n" 2430 "architecture does not support 24bit PCI busmaster DMA\n"
2528 ); 2431 );
2529 err = -ENXIO; 2432 err = -ENXIO;
2530 goto out_err; 2433 goto out_err;
@@ -2560,7 +2463,7 @@ snd_azf3328_create(struct snd_card *card,
2560 2463
2561 if (request_irq(pci->irq, snd_azf3328_interrupt, 2464 if (request_irq(pci->irq, snd_azf3328_interrupt,
2562 IRQF_SHARED, KBUILD_MODNAME, chip)) { 2465 IRQF_SHARED, KBUILD_MODNAME, chip)) {
2563 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 2466 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
2564 err = -EBUSY; 2467 err = -EBUSY;
2565 goto out_err; 2468 goto out_err;
2566 } 2469 }
@@ -2599,8 +2502,6 @@ snd_azf3328_create(struct snd_card *card,
2599 spin_unlock_irq(codec->lock); 2502 spin_unlock_irq(codec->lock);
2600 } 2503 }
2601 2504
2602 snd_card_set_dev(card, &pci->dev);
2603
2604 *rchip = chip; 2505 *rchip = chip;
2605 2506
2606 err = 0; 2507 err = 0;
@@ -2624,7 +2525,6 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2624 struct snd_opl3 *opl3; 2525 struct snd_opl3 *opl3;
2625 int err; 2526 int err;
2626 2527
2627 snd_azf3328_dbgcallenter();
2628 if (dev >= SNDRV_CARDS) { 2528 if (dev >= SNDRV_CARDS) {
2629 err = -ENODEV; 2529 err = -ENODEV;
2630 goto out; 2530 goto out;
@@ -2635,7 +2535,8 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2635 goto out; 2535 goto out;
2636 } 2536 }
2637 2537
2638 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2538 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2539 0, &card);
2639 if (err < 0) 2540 if (err < 0)
2640 goto out; 2541 goto out;
2641 2542
@@ -2657,7 +2558,7 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2657 -1, &chip->rmidi 2558 -1, &chip->rmidi
2658 ); 2559 );
2659 if (err < 0) { 2560 if (err < 0) {
2660 snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n", 2561 dev_err(card->dev, "no MPU-401 device at 0x%lx?\n",
2661 chip->mpu_io 2562 chip->mpu_io
2662 ); 2563 );
2663 goto out_err; 2564 goto out_err;
@@ -2673,7 +2574,7 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2673 2574
2674 if (snd_opl3_create(card, chip->opl3_io, chip->opl3_io+2, 2575 if (snd_opl3_create(card, chip->opl3_io, chip->opl3_io+2,
2675 OPL3_HW_AUTO, 1, &opl3) < 0) { 2576 OPL3_HW_AUTO, 1, &opl3) < 0) {
2676 snd_printk(KERN_ERR "azf3328: no OPL3 device at 0x%lx-0x%lx?\n", 2577 dev_err(card->dev, "no OPL3 device at 0x%lx-0x%lx?\n",
2677 chip->opl3_io, chip->opl3_io+2 2578 chip->opl3_io, chip->opl3_io+2
2678 ); 2579 );
2679 } else { 2580 } else {
@@ -2695,12 +2596,15 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2695 goto out_err; 2596 goto out_err;
2696 2597
2697#ifdef MODULE 2598#ifdef MODULE
2698 printk(KERN_INFO 2599 dev_info(card->dev,
2699"azt3328: Sound driver for Aztech AZF3328-based soundcards such as PCI168.\n" 2600 "Sound driver for Aztech AZF3328-based soundcards such as PCI168.\n");
2700"azt3328: Hardware was completely undocumented, unfortunately.\n" 2601 dev_info(card->dev,
2701"azt3328: Feel free to contact andi AT lisas.de for bug reports etc.!\n" 2602 "Hardware was completely undocumented, unfortunately.\n");
2702"azt3328: User-scalable sequencer timer set to %dHz (1024000Hz / %d).\n", 2603 dev_info(card->dev,
2703 1024000 / seqtimer_scaling, seqtimer_scaling); 2604 "Feel free to contact andi AT lisas.de for bug reports etc.!\n");
2605 dev_info(card->dev,
2606 "User-scalable sequencer timer set to %dHz (1024000Hz / %d).\n",
2607 1024000 / seqtimer_scaling, seqtimer_scaling);
2704#endif 2608#endif
2705 2609
2706 snd_azf3328_gameport(chip, dev); 2610 snd_azf3328_gameport(chip, dev);
@@ -2712,31 +2616,29 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2712 goto out; 2616 goto out;
2713 2617
2714out_err: 2618out_err:
2715 snd_printk(KERN_ERR "azf3328: something failed, exiting\n"); 2619 dev_err(card->dev, "something failed, exiting\n");
2716 snd_card_free(card); 2620 snd_card_free(card);
2717 2621
2718out: 2622out:
2719 snd_azf3328_dbgcallleave();
2720 return err; 2623 return err;
2721} 2624}
2722 2625
2723static void 2626static void
2724snd_azf3328_remove(struct pci_dev *pci) 2627snd_azf3328_remove(struct pci_dev *pci)
2725{ 2628{
2726 snd_azf3328_dbgcallenter();
2727 snd_card_free(pci_get_drvdata(pci)); 2629 snd_card_free(pci_get_drvdata(pci));
2728 snd_azf3328_dbgcallleave();
2729} 2630}
2730 2631
2731#ifdef CONFIG_PM_SLEEP 2632#ifdef CONFIG_PM_SLEEP
2732static inline void 2633static inline void
2733snd_azf3328_suspend_regs(unsigned long io_addr, unsigned count, u32 *saved_regs) 2634snd_azf3328_suspend_regs(const struct snd_azf3328 *chip,
2635 unsigned long io_addr, unsigned count, u32 *saved_regs)
2734{ 2636{
2735 unsigned reg; 2637 unsigned reg;
2736 2638
2737 for (reg = 0; reg < count; ++reg) { 2639 for (reg = 0; reg < count; ++reg) {
2738 *saved_regs = inl(io_addr); 2640 *saved_regs = inl(io_addr);
2739 snd_azf3328_dbgpm("suspend: io 0x%04lx: 0x%08x\n", 2641 dev_dbg(chip->card->dev, "suspend: io 0x%04lx: 0x%08x\n",
2740 io_addr, *saved_regs); 2642 io_addr, *saved_regs);
2741 ++saved_regs; 2643 ++saved_regs;
2742 io_addr += sizeof(*saved_regs); 2644 io_addr += sizeof(*saved_regs);
@@ -2744,7 +2646,8 @@ snd_azf3328_suspend_regs(unsigned long io_addr, unsigned count, u32 *saved_regs)
2744} 2646}
2745 2647
2746static inline void 2648static inline void
2747snd_azf3328_resume_regs(const u32 *saved_regs, 2649snd_azf3328_resume_regs(const struct snd_azf3328 *chip,
2650 const u32 *saved_regs,
2748 unsigned long io_addr, 2651 unsigned long io_addr,
2749 unsigned count 2652 unsigned count
2750) 2653)
@@ -2753,7 +2656,8 @@ snd_azf3328_resume_regs(const u32 *saved_regs,
2753 2656
2754 for (reg = 0; reg < count; ++reg) { 2657 for (reg = 0; reg < count; ++reg) {
2755 outl(*saved_regs, io_addr); 2658 outl(*saved_regs, io_addr);
2756 snd_azf3328_dbgpm("resume: io 0x%04lx: 0x%08x --> 0x%08x\n", 2659 dev_dbg(chip->card->dev,
2660 "resume: io 0x%04lx: 0x%08x --> 0x%08x\n",
2757 io_addr, *saved_regs, inl(io_addr)); 2661 io_addr, *saved_regs, inl(io_addr));
2758 ++saved_regs; 2662 ++saved_regs;
2759 io_addr += sizeof(*saved_regs); 2663 io_addr += sizeof(*saved_regs);
@@ -2766,7 +2670,7 @@ snd_azf3328_suspend_ac97(struct snd_azf3328 *chip)
2766#ifdef AZF_USE_AC97_LAYER 2670#ifdef AZF_USE_AC97_LAYER
2767 snd_ac97_suspend(chip->ac97); 2671 snd_ac97_suspend(chip->ac97);
2768#else 2672#else
2769 snd_azf3328_suspend_regs(chip->mixer_io, 2673 snd_azf3328_suspend_regs(chip, chip->mixer_io,
2770 ARRAY_SIZE(chip->saved_regs_mixer), chip->saved_regs_mixer); 2674 ARRAY_SIZE(chip->saved_regs_mixer), chip->saved_regs_mixer);
2771 2675
2772 /* make sure to disable master volume etc. to prevent looping sound */ 2676 /* make sure to disable master volume etc. to prevent looping sound */
@@ -2781,7 +2685,7 @@ snd_azf3328_resume_ac97(const struct snd_azf3328 *chip)
2781#ifdef AZF_USE_AC97_LAYER 2685#ifdef AZF_USE_AC97_LAYER
2782 snd_ac97_resume(chip->ac97); 2686 snd_ac97_resume(chip->ac97);
2783#else 2687#else
2784 snd_azf3328_resume_regs(chip->saved_regs_mixer, chip->mixer_io, 2688 snd_azf3328_resume_regs(chip, chip->saved_regs_mixer, chip->mixer_io,
2785 ARRAY_SIZE(chip->saved_regs_mixer)); 2689 ARRAY_SIZE(chip->saved_regs_mixer));
2786 2690
2787 /* unfortunately with 32bit transfers, IDX_MIXER_PLAY_MASTER (0x02) 2691 /* unfortunately with 32bit transfers, IDX_MIXER_PLAY_MASTER (0x02)
@@ -2808,18 +2712,18 @@ snd_azf3328_suspend(struct device *dev)
2808 2712
2809 snd_azf3328_suspend_ac97(chip); 2713 snd_azf3328_suspend_ac97(chip);
2810 2714
2811 snd_azf3328_suspend_regs(chip->ctrl_io, 2715 snd_azf3328_suspend_regs(chip, chip->ctrl_io,
2812 ARRAY_SIZE(chip->saved_regs_ctrl), chip->saved_regs_ctrl); 2716 ARRAY_SIZE(chip->saved_regs_ctrl), chip->saved_regs_ctrl);
2813 2717
2814 /* manually store the one currently relevant write-only reg, too */ 2718 /* manually store the one currently relevant write-only reg, too */
2815 saved_regs_ctrl_u16 = (u16 *)chip->saved_regs_ctrl; 2719 saved_regs_ctrl_u16 = (u16 *)chip->saved_regs_ctrl;
2816 saved_regs_ctrl_u16[IDX_IO_6AH / 2] = chip->shadow_reg_ctrl_6AH; 2720 saved_regs_ctrl_u16[IDX_IO_6AH / 2] = chip->shadow_reg_ctrl_6AH;
2817 2721
2818 snd_azf3328_suspend_regs(chip->game_io, 2722 snd_azf3328_suspend_regs(chip, chip->game_io,
2819 ARRAY_SIZE(chip->saved_regs_game), chip->saved_regs_game); 2723 ARRAY_SIZE(chip->saved_regs_game), chip->saved_regs_game);
2820 snd_azf3328_suspend_regs(chip->mpu_io, 2724 snd_azf3328_suspend_regs(chip, chip->mpu_io,
2821 ARRAY_SIZE(chip->saved_regs_mpu), chip->saved_regs_mpu); 2725 ARRAY_SIZE(chip->saved_regs_mpu), chip->saved_regs_mpu);
2822 snd_azf3328_suspend_regs(chip->opl3_io, 2726 snd_azf3328_suspend_regs(chip, chip->opl3_io,
2823 ARRAY_SIZE(chip->saved_regs_opl3), chip->saved_regs_opl3); 2727 ARRAY_SIZE(chip->saved_regs_opl3), chip->saved_regs_opl3);
2824 2728
2825 pci_disable_device(pci); 2729 pci_disable_device(pci);
@@ -2838,23 +2742,22 @@ snd_azf3328_resume(struct device *dev)
2838 pci_set_power_state(pci, PCI_D0); 2742 pci_set_power_state(pci, PCI_D0);
2839 pci_restore_state(pci); 2743 pci_restore_state(pci);
2840 if (pci_enable_device(pci) < 0) { 2744 if (pci_enable_device(pci) < 0) {
2841 printk(KERN_ERR "azt3328: pci_enable_device failed, " 2745 dev_err(dev, "pci_enable_device failed, disabling device\n");
2842 "disabling device\n");
2843 snd_card_disconnect(card); 2746 snd_card_disconnect(card);
2844 return -EIO; 2747 return -EIO;
2845 } 2748 }
2846 pci_set_master(pci); 2749 pci_set_master(pci);
2847 2750
2848 snd_azf3328_resume_regs(chip->saved_regs_game, chip->game_io, 2751 snd_azf3328_resume_regs(chip, chip->saved_regs_game, chip->game_io,
2849 ARRAY_SIZE(chip->saved_regs_game)); 2752 ARRAY_SIZE(chip->saved_regs_game));
2850 snd_azf3328_resume_regs(chip->saved_regs_mpu, chip->mpu_io, 2753 snd_azf3328_resume_regs(chip, chip->saved_regs_mpu, chip->mpu_io,
2851 ARRAY_SIZE(chip->saved_regs_mpu)); 2754 ARRAY_SIZE(chip->saved_regs_mpu));
2852 snd_azf3328_resume_regs(chip->saved_regs_opl3, chip->opl3_io, 2755 snd_azf3328_resume_regs(chip, chip->saved_regs_opl3, chip->opl3_io,
2853 ARRAY_SIZE(chip->saved_regs_opl3)); 2756 ARRAY_SIZE(chip->saved_regs_opl3));
2854 2757
2855 snd_azf3328_resume_ac97(chip); 2758 snd_azf3328_resume_ac97(chip);
2856 2759
2857 snd_azf3328_resume_regs(chip->saved_regs_ctrl, chip->ctrl_io, 2760 snd_azf3328_resume_regs(chip, chip->saved_regs_ctrl, chip->ctrl_io,
2858 ARRAY_SIZE(chip->saved_regs_ctrl)); 2761 ARRAY_SIZE(chip->saved_regs_ctrl));
2859 2762
2860 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 2763 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c
index 18802039497a..8546711d12f9 100644
--- a/sound/pci/bt87x.c
+++ b/sound/pci/bt87x.c
@@ -293,17 +293,23 @@ static void snd_bt87x_pci_error(struct snd_bt87x *chip, unsigned int status)
293 PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_DETECTED_PARITY; 293 PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_DETECTED_PARITY;
294 pci_write_config_word(chip->pci, PCI_STATUS, pci_status); 294 pci_write_config_word(chip->pci, PCI_STATUS, pci_status);
295 if (pci_status != PCI_STATUS_DETECTED_PARITY) 295 if (pci_status != PCI_STATUS_DETECTED_PARITY)
296 snd_printk(KERN_ERR "Aieee - PCI error! status %#08x, PCI status %#04x\n", 296 dev_err(chip->card->dev,
297 "Aieee - PCI error! status %#08x, PCI status %#04x\n",
297 status & ERROR_INTERRUPTS, pci_status); 298 status & ERROR_INTERRUPTS, pci_status);
298 else { 299 else {
299 snd_printk(KERN_ERR "Aieee - PCI parity error detected!\n"); 300 dev_err(chip->card->dev,
301 "Aieee - PCI parity error detected!\n");
300 /* error 'handling' similar to aic7xxx_pci.c: */ 302 /* error 'handling' similar to aic7xxx_pci.c: */
301 chip->pci_parity_errors++; 303 chip->pci_parity_errors++;
302 if (chip->pci_parity_errors > 20) { 304 if (chip->pci_parity_errors > 20) {
303 snd_printk(KERN_ERR "Too many PCI parity errors observed.\n"); 305 dev_err(chip->card->dev,
304 snd_printk(KERN_ERR "Some device on this bus is generating bad parity.\n"); 306 "Too many PCI parity errors observed.\n");
305 snd_printk(KERN_ERR "This is an error *observed by*, not *generated by*, this card.\n"); 307 dev_err(chip->card->dev,
306 snd_printk(KERN_ERR "PCI parity error checking has been disabled.\n"); 308 "Some device on this bus is generating bad parity.\n");
309 dev_err(chip->card->dev,
310 "This is an error *observed by*, not *generated by*, this card.\n");
311 dev_err(chip->card->dev,
312 "PCI parity error checking has been disabled.\n");
307 chip->interrupt_mask &= ~(INT_PPERR | INT_RIPERR); 313 chip->interrupt_mask &= ~(INT_PPERR | INT_RIPERR);
308 snd_bt87x_writel(chip, REG_INT_MASK, chip->interrupt_mask); 314 snd_bt87x_writel(chip, REG_INT_MASK, chip->interrupt_mask);
309 } 315 }
@@ -323,9 +329,11 @@ static irqreturn_t snd_bt87x_interrupt(int irq, void *dev_id)
323 329
324 if (irq_status & ERROR_INTERRUPTS) { 330 if (irq_status & ERROR_INTERRUPTS) {
325 if (irq_status & (INT_FBUS | INT_FTRGT)) 331 if (irq_status & (INT_FBUS | INT_FTRGT))
326 snd_printk(KERN_WARNING "FIFO overrun, status %#08x\n", status); 332 dev_warn(chip->card->dev,
333 "FIFO overrun, status %#08x\n", status);
327 if (irq_status & INT_OCERR) 334 if (irq_status & INT_OCERR)
328 snd_printk(KERN_ERR "internal RISC error, status %#08x\n", status); 335 dev_err(chip->card->dev,
336 "internal RISC error, status %#08x\n", status);
329 if (irq_status & (INT_PPERR | INT_RIPERR | INT_PABORT)) 337 if (irq_status & (INT_PPERR | INT_RIPERR | INT_PABORT))
330 snd_bt87x_pci_error(chip, irq_status); 338 snd_bt87x_pci_error(chip, irq_status);
331 } 339 }
@@ -747,7 +755,7 @@ static int snd_bt87x_create(struct snd_card *card,
747 } 755 }
748 chip->mmio = pci_ioremap_bar(pci, 0); 756 chip->mmio = pci_ioremap_bar(pci, 0);
749 if (!chip->mmio) { 757 if (!chip->mmio) {
750 snd_printk(KERN_ERR "cannot remap io memory\n"); 758 dev_err(card->dev, "cannot remap io memory\n");
751 err = -ENOMEM; 759 err = -ENOMEM;
752 goto fail; 760 goto fail;
753 } 761 }
@@ -762,7 +770,7 @@ static int snd_bt87x_create(struct snd_card *card,
762 err = request_irq(pci->irq, snd_bt87x_interrupt, IRQF_SHARED, 770 err = request_irq(pci->irq, snd_bt87x_interrupt, IRQF_SHARED,
763 KBUILD_MODNAME, chip); 771 KBUILD_MODNAME, chip);
764 if (err < 0) { 772 if (err < 0) {
765 snd_printk(KERN_ERR "cannot grab irq %d\n", pci->irq); 773 dev_err(card->dev, "cannot grab irq %d\n", pci->irq);
766 goto fail; 774 goto fail;
767 } 775 }
768 chip->irq = pci->irq; 776 chip->irq = pci->irq;
@@ -773,7 +781,6 @@ static int snd_bt87x_create(struct snd_card *card,
773 if (err < 0) 781 if (err < 0)
774 goto fail; 782 goto fail;
775 783
776 snd_card_set_dev(card, &pci->dev);
777 *rchip = chip; 784 *rchip = chip;
778 return 0; 785 return 0;
779 786
@@ -851,14 +858,15 @@ static int snd_bt87x_detect_card(struct pci_dev *pci)
851 for (i = 0; i < ARRAY_SIZE(blacklist); ++i) 858 for (i = 0; i < ARRAY_SIZE(blacklist); ++i)
852 if (blacklist[i].subvendor == pci->subsystem_vendor && 859 if (blacklist[i].subvendor == pci->subsystem_vendor &&
853 blacklist[i].subdevice == pci->subsystem_device) { 860 blacklist[i].subdevice == pci->subsystem_device) {
854 snd_printdd(KERN_INFO "card %#04x-%#04x:%#04x has no audio\n", 861 dev_dbg(&pci->dev,
862 "card %#04x-%#04x:%#04x has no audio\n",
855 pci->device, pci->subsystem_vendor, pci->subsystem_device); 863 pci->device, pci->subsystem_vendor, pci->subsystem_device);
856 return -EBUSY; 864 return -EBUSY;
857 } 865 }
858 866
859 snd_printk(KERN_INFO "unknown card %#04x-%#04x:%#04x\n", 867 dev_info(&pci->dev, "unknown card %#04x-%#04x:%#04x\n",
860 pci->device, pci->subsystem_vendor, pci->subsystem_device); 868 pci->device, pci->subsystem_vendor, pci->subsystem_device);
861 snd_printk(KERN_DEBUG "please mail id, board name, and, " 869 dev_info(&pci->dev, "please mail id, board name, and, "
862 "if it works, the correct digital_rate option to " 870 "if it works, the correct digital_rate option to "
863 "<alsa-devel@alsa-project.org>\n"); 871 "<alsa-devel@alsa-project.org>\n");
864 return SND_BT87X_BOARD_UNKNOWN; 872 return SND_BT87X_BOARD_UNKNOWN;
@@ -888,7 +896,8 @@ static int snd_bt87x_probe(struct pci_dev *pci,
888 return -ENOENT; 896 return -ENOENT;
889 } 897 }
890 898
891 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 899 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
900 0, &card);
892 if (err < 0) 901 if (err < 0)
893 return err; 902 return err;
894 903
@@ -925,7 +934,7 @@ static int snd_bt87x_probe(struct pci_dev *pci,
925 if (err < 0) 934 if (err < 0)
926 goto _error; 935 goto _error;
927 } 936 }
928 snd_printk(KERN_INFO "bt87x%d: Using board %d, %sanalog, %sdigital " 937 dev_info(card->dev, "bt87x%d: Using board %d, %sanalog, %sdigital "
929 "(rate %d Hz)\n", dev, boardid, 938 "(rate %d Hz)\n", dev, boardid,
930 chip->board.no_analog ? "no " : "", 939 chip->board.no_analog ? "no " : "",
931 chip->board.no_digital ? "no " : "", chip->board.dig_rate); 940 chip->board.no_digital ? "no " : "", chip->board.dig_rate);
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index f4db5587e86e..f94cc6e97d4a 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -417,13 +417,13 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
417 int status; 417 int status;
418 int retry; 418 int retry;
419 if ((reg > 0x7f) || (value > 0x1ff)) { 419 if ((reg > 0x7f) || (value > 0x1ff)) {
420 snd_printk(KERN_ERR "i2c_write: invalid values.\n"); 420 dev_err(emu->card->dev, "i2c_write: invalid values.\n");
421 return -EINVAL; 421 return -EINVAL;
422 } 422 }
423 423
424 tmp = reg << 25 | value << 16; 424 tmp = reg << 25 | value << 16;
425 /* 425 /*
426 snd_printk(KERN_DEBUG "I2C-write:reg=0x%x, value=0x%x\n", reg, value); 426 dev_dbg(emu->card->dev, "I2C-write:reg=0x%x, value=0x%x\n", reg, value);
427 */ 427 */
428 /* Not sure what this I2C channel controls. */ 428 /* Not sure what this I2C channel controls. */
429 /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */ 429 /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */
@@ -442,7 +442,7 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
442 /* Wait till the transaction ends */ 442 /* Wait till the transaction ends */
443 while (1) { 443 while (1) {
444 status = snd_ca0106_ptr_read(emu, I2C_A, 0); 444 status = snd_ca0106_ptr_read(emu, I2C_A, 0);
445 /*snd_printk(KERN_DEBUG "I2C:status=0x%x\n", status);*/ 445 /*dev_dbg(emu->card->dev, "I2C:status=0x%x\n", status);*/
446 timeout++; 446 timeout++;
447 if ((status & I2C_A_ADC_START) == 0) 447 if ((status & I2C_A_ADC_START) == 0)
448 break; 448 break;
@@ -456,7 +456,7 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
456 } 456 }
457 457
458 if (retry == 10) { 458 if (retry == 10) {
459 snd_printk(KERN_ERR "Writing to ADC failed!\n"); 459 dev_err(emu->card->dev, "Writing to ADC failed!\n");
460 return -EINVAL; 460 return -EINVAL;
461 } 461 }
462 462
@@ -516,7 +516,8 @@ static void restore_spdif_bits(struct snd_ca0106 *chip, int idx)
516 } 516 }
517} 517}
518 518
519static int snd_ca0106_channel_dac(struct snd_ca0106_details *details, 519static int snd_ca0106_channel_dac(struct snd_ca0106 *chip,
520 struct snd_ca0106_details *details,
520 int channel_id) 521 int channel_id)
521{ 522{
522 switch (channel_id) { 523 switch (channel_id) {
@@ -529,7 +530,7 @@ static int snd_ca0106_channel_dac(struct snd_ca0106_details *details,
529 case PCM_UNKNOWN_CHANNEL: 530 case PCM_UNKNOWN_CHANNEL:
530 return (details->spi_dac & 0x000f) >> (4 * 0); 531 return (details->spi_dac & 0x000f) >> (4 * 0);
531 default: 532 default:
532 snd_printk(KERN_DEBUG "ca0106: unknown channel_id %d\n", 533 dev_dbg(chip->card->dev, "ca0106: unknown channel_id %d\n",
533 channel_id); 534 channel_id);
534 } 535 }
535 return 0; 536 return 0;
@@ -539,7 +540,7 @@ static int snd_ca0106_pcm_power_dac(struct snd_ca0106 *chip, int channel_id,
539 int power) 540 int power)
540{ 541{
541 if (chip->details->spi_dac) { 542 if (chip->details->spi_dac) {
542 const int dac = snd_ca0106_channel_dac(chip->details, 543 const int dac = snd_ca0106_channel_dac(chip, chip->details,
543 channel_id); 544 channel_id);
544 const int reg = spi_dacd_reg[dac]; 545 const int reg = spi_dacd_reg[dac];
545 const int bit = spi_dacd_bit[dac]; 546 const int bit = spi_dacd_bit[dac];
@@ -583,7 +584,7 @@ static int snd_ca0106_pcm_open_playback_channel(struct snd_pcm_substream *substr
583 584
584 channel->use = 1; 585 channel->use = 1;
585 /* 586 /*
586 printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n", 587 dev_dbg(chip->card->dev, "open:channel_id=%d, chip=%p, channel=%p\n",
587 channel_id, chip, channel); 588 channel_id, chip, channel);
588 */ 589 */
589 //channel->interrupt = snd_ca0106_pcm_channel_interrupt; 590 //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
@@ -660,7 +661,8 @@ static int snd_ca0106_pcm_open_capture_channel(struct snd_pcm_substream *substre
660 661
661 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 662 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
662 if (epcm == NULL) { 663 if (epcm == NULL) {
663 snd_printk(KERN_ERR "open_capture_channel: failed epcm alloc\n"); 664 dev_err(chip->card->dev,
665 "open_capture_channel: failed epcm alloc\n");
664 return -ENOMEM; 666 return -ENOMEM;
665 } 667 }
666 epcm->emu = chip; 668 epcm->emu = chip;
@@ -677,7 +679,7 @@ static int snd_ca0106_pcm_open_capture_channel(struct snd_pcm_substream *substre
677 679
678 channel->use = 1; 680 channel->use = 1;
679 /* 681 /*
680 printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n", 682 dev_dbg(chip->card->dev, "open:channel_id=%d, chip=%p, channel=%p\n",
681 channel_id, chip, channel); 683 channel_id, chip, channel);
682 */ 684 */
683 //channel->interrupt = snd_ca0106_pcm_channel_interrupt; 685 //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
@@ -771,7 +773,7 @@ static int snd_ca0106_pcm_prepare_playback(struct snd_pcm_substream *substream)
771 int i; 773 int i;
772 774
773#if 0 /* debug */ 775#if 0 /* debug */
774 snd_printk(KERN_DEBUG 776 dev_dbg(emu->card->dev,
775 "prepare:channel_number=%d, rate=%d, format=0x%x, " 777 "prepare:channel_number=%d, rate=%d, format=0x%x, "
776 "channels=%d, buffer_size=%ld, period_size=%ld, " 778 "channels=%d, buffer_size=%ld, period_size=%ld, "
777 "periods=%u, frames_to_bytes=%d\n", 779 "periods=%u, frames_to_bytes=%d\n",
@@ -779,9 +781,11 @@ static int snd_ca0106_pcm_prepare_playback(struct snd_pcm_substream *substream)
779 runtime->channels, runtime->buffer_size, 781 runtime->channels, runtime->buffer_size,
780 runtime->period_size, runtime->periods, 782 runtime->period_size, runtime->periods,
781 frames_to_bytes(runtime, 1)); 783 frames_to_bytes(runtime, 1));
782 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, table_base=%p\n", 784 dev_dbg(emu->card->dev,
785 "dma_addr=%x, dma_area=%p, table_base=%p\n",
783 runtime->dma_addr, runtime->dma_area, table_base); 786 runtime->dma_addr, runtime->dma_area, table_base);
784 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n", 787 dev_dbg(emu->card->dev,
788 "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",
785 emu->buffer.addr, emu->buffer.area, emu->buffer.bytes); 789 emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
786#endif /* debug */ 790#endif /* debug */
787 /* Rate can be set per channel. */ 791 /* Rate can be set per channel. */
@@ -876,7 +880,7 @@ static int snd_ca0106_pcm_prepare_capture(struct snd_pcm_substream *substream)
876 u32 reg71; 880 u32 reg71;
877 881
878#if 0 /* debug */ 882#if 0 /* debug */
879 snd_printk(KERN_DEBUG 883 dev_dbg(emu->card->dev,
880 "prepare:channel_number=%d, rate=%d, format=0x%x, " 884 "prepare:channel_number=%d, rate=%d, format=0x%x, "
881 "channels=%d, buffer_size=%ld, period_size=%ld, " 885 "channels=%d, buffer_size=%ld, period_size=%ld, "
882 "periods=%u, frames_to_bytes=%d\n", 886 "periods=%u, frames_to_bytes=%d\n",
@@ -884,9 +888,11 @@ static int snd_ca0106_pcm_prepare_capture(struct snd_pcm_substream *substream)
884 runtime->channels, runtime->buffer_size, 888 runtime->channels, runtime->buffer_size,
885 runtime->period_size, runtime->periods, 889 runtime->period_size, runtime->periods,
886 frames_to_bytes(runtime, 1)); 890 frames_to_bytes(runtime, 1));
887 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, table_base=%p\n", 891 dev_dbg(emu->card->dev,
892 "dma_addr=%x, dma_area=%p, table_base=%p\n",
888 runtime->dma_addr, runtime->dma_area, table_base); 893 runtime->dma_addr, runtime->dma_area, table_base);
889 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n", 894 dev_dbg(emu->card->dev,
895 "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",
890 emu->buffer.addr, emu->buffer.area, emu->buffer.bytes); 896 emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
891#endif /* debug */ 897#endif /* debug */
892 /* reg71 controls ADC rate. */ 898 /* reg71 controls ADC rate. */
@@ -934,7 +940,7 @@ static int snd_ca0106_pcm_prepare_capture(struct snd_pcm_substream *substream)
934 940
935 941
936 /* 942 /*
937 printk(KERN_DEBUG 943 dev_dbg(emu->card->dev,
938 "prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, " 944 "prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, "
939 "buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n", 945 "buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n",
940 channel, runtime->rate, runtime->format, runtime->channels, 946 channel, runtime->rate, runtime->format, runtime->channels,
@@ -982,13 +988,13 @@ static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream,
982 runtime = s->runtime; 988 runtime = s->runtime;
983 epcm = runtime->private_data; 989 epcm = runtime->private_data;
984 channel = epcm->channel_id; 990 channel = epcm->channel_id;
985 /* snd_printk(KERN_DEBUG "channel=%d\n", channel); */ 991 /* dev_dbg(emu->card->dev, "channel=%d\n", channel); */
986 epcm->running = running; 992 epcm->running = running;
987 basic |= (0x1 << channel); 993 basic |= (0x1 << channel);
988 extended |= (0x10 << channel); 994 extended |= (0x10 << channel);
989 snd_pcm_trigger_done(s, substream); 995 snd_pcm_trigger_done(s, substream);
990 } 996 }
991 /* snd_printk(KERN_DEBUG "basic=0x%x, extended=0x%x\n",basic, extended); */ 997 /* dev_dbg(emu->card->dev, "basic=0x%x, extended=0x%x\n",basic, extended); */
992 998
993 switch (cmd) { 999 switch (cmd) {
994 case SNDRV_PCM_TRIGGER_START: 1000 case SNDRV_PCM_TRIGGER_START:
@@ -1070,7 +1076,7 @@ snd_ca0106_pcm_pointer_playback(struct snd_pcm_substream *substream)
1070 return ptr; 1076 return ptr;
1071 prev_ptr = ptr; 1077 prev_ptr = ptr;
1072 } while (--timeout); 1078 } while (--timeout);
1073 snd_printk(KERN_WARNING "ca0106: unstable DMA pointer!\n"); 1079 dev_warn(emu->card->dev, "ca0106: unstable DMA pointer!\n");
1074 return 0; 1080 return 0;
1075} 1081}
1076 1082
@@ -1093,7 +1099,7 @@ snd_ca0106_pcm_pointer_capture(struct snd_pcm_substream *substream)
1093 if (ptr >= runtime->buffer_size) 1099 if (ptr >= runtime->buffer_size)
1094 ptr -= runtime->buffer_size; 1100 ptr -= runtime->buffer_size;
1095 /* 1101 /*
1096 printk(KERN_DEBUG "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, " 1102 dev_dbg(emu->card->dev, "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, "
1097 "buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", 1103 "buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n",
1098 ptr1, ptr2, ptr, (int)runtime->buffer_size, 1104 ptr1, ptr2, ptr, (int)runtime->buffer_size,
1099 (int)runtime->period_size, (int)runtime->frame_bits, 1105 (int)runtime->period_size, (int)runtime->frame_bits,
@@ -1284,9 +1290,9 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id)
1284 1290
1285 stat76 = snd_ca0106_ptr_read(chip, EXTENDED_INT, 0); 1291 stat76 = snd_ca0106_ptr_read(chip, EXTENDED_INT, 0);
1286 /* 1292 /*
1287 snd_printk(KERN_DEBUG "interrupt status = 0x%08x, stat76=0x%08x\n", 1293 dev_dbg(emu->card->dev, "interrupt status = 0x%08x, stat76=0x%08x\n",
1288 status, stat76); 1294 status, stat76);
1289 snd_printk(KERN_DEBUG "ptr=0x%08x\n", 1295 dev_dbg(emu->card->dev, "ptr=0x%08x\n",
1290 snd_ca0106_ptr_read(chip, PLAYBACK_POINTER, 0)); 1296 snd_ca0106_ptr_read(chip, PLAYBACK_POINTER, 0));
1291 */ 1297 */
1292 mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */ 1298 mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */
@@ -1296,11 +1302,13 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id)
1296/* FIXME: Select the correct substream for period elapsed */ 1302/* FIXME: Select the correct substream for period elapsed */
1297 if(pchannel->use) { 1303 if(pchannel->use) {
1298 snd_pcm_period_elapsed(pchannel->epcm->substream); 1304 snd_pcm_period_elapsed(pchannel->epcm->substream);
1299 //printk(KERN_INFO "interrupt [%d] used\n", i); 1305 /* dev_dbg(emu->card->dev, "interrupt [%d] used\n", i); */
1300 } 1306 }
1301 } 1307 }
1302 //printk(KERN_INFO "channel=%p\n",pchannel); 1308 /*
1303 //printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number); 1309 dev_dbg(emu->card->dev, "channel=%p\n", pchannel);
1310 dev_dbg(emu->card->dev, "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number);
1311 */
1304 mask <<= 1; 1312 mask <<= 1;
1305 } 1313 }
1306 mask = 0x110000; /* 0x1 for one half, 0x10 for the other half period. */ 1314 mask = 0x110000; /* 0x1 for one half, 0x10 for the other half period. */
@@ -1310,11 +1318,13 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id)
1310/* FIXME: Select the correct substream for period elapsed */ 1318/* FIXME: Select the correct substream for period elapsed */
1311 if(pchannel->use) { 1319 if(pchannel->use) {
1312 snd_pcm_period_elapsed(pchannel->epcm->substream); 1320 snd_pcm_period_elapsed(pchannel->epcm->substream);
1313 //printk(KERN_INFO "interrupt [%d] used\n", i); 1321 /* dev_dbg(emu->card->dev, "interrupt [%d] used\n", i); */
1314 } 1322 }
1315 } 1323 }
1316 //printk(KERN_INFO "channel=%p\n",pchannel); 1324 /*
1317 //printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number); 1325 dev_dbg(emu->card->dev, "channel=%p\n", pchannel);
1326 dev_dbg(emu->card->dev, "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number);
1327 */
1318 mask <<= 1; 1328 mask <<= 1;
1319 } 1329 }
1320 1330
@@ -1603,7 +1613,7 @@ static void ca0106_init_chip(struct snd_ca0106 *chip, int resume)
1603 int size, n; 1613 int size, n;
1604 1614
1605 size = ARRAY_SIZE(i2c_adc_init); 1615 size = ARRAY_SIZE(i2c_adc_init);
1606 /* snd_printk(KERN_DEBUG "I2C:array size=0x%x\n", size); */ 1616 /* dev_dbg(emu->card->dev, "I2C:array size=0x%x\n", size); */
1607 for (n = 0; n < size; n++) 1617 for (n = 0; n < size; n++)
1608 snd_ca0106_i2c_write(chip, i2c_adc_init[n][0], 1618 snd_ca0106_i2c_write(chip, i2c_adc_init[n][0],
1609 i2c_adc_init[n][1]); 1619 i2c_adc_init[n][1]);
@@ -1668,7 +1678,7 @@ static int snd_ca0106_create(int dev, struct snd_card *card,
1668 return err; 1678 return err;
1669 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 || 1679 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 ||
1670 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { 1680 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) {
1671 printk(KERN_ERR "error to set 32bit mask DMA\n"); 1681 dev_err(card->dev, "error to set 32bit mask DMA\n");
1672 pci_disable_device(pci); 1682 pci_disable_device(pci);
1673 return -ENXIO; 1683 return -ENXIO;
1674 } 1684 }
@@ -1689,14 +1699,14 @@ static int snd_ca0106_create(int dev, struct snd_card *card,
1689 chip->res_port = request_region(chip->port, 0x20, "snd_ca0106"); 1699 chip->res_port = request_region(chip->port, 0x20, "snd_ca0106");
1690 if (!chip->res_port) { 1700 if (!chip->res_port) {
1691 snd_ca0106_free(chip); 1701 snd_ca0106_free(chip);
1692 printk(KERN_ERR "cannot allocate the port\n"); 1702 dev_err(card->dev, "cannot allocate the port\n");
1693 return -EBUSY; 1703 return -EBUSY;
1694 } 1704 }
1695 1705
1696 if (request_irq(pci->irq, snd_ca0106_interrupt, 1706 if (request_irq(pci->irq, snd_ca0106_interrupt,
1697 IRQF_SHARED, KBUILD_MODNAME, chip)) { 1707 IRQF_SHARED, KBUILD_MODNAME, chip)) {
1698 snd_ca0106_free(chip); 1708 snd_ca0106_free(chip);
1699 printk(KERN_ERR "cannot grab irq\n"); 1709 dev_err(card->dev, "cannot grab irq\n");
1700 return -EBUSY; 1710 return -EBUSY;
1701 } 1711 }
1702 chip->irq = pci->irq; 1712 chip->irq = pci->irq;
@@ -1712,7 +1722,7 @@ static int snd_ca0106_create(int dev, struct snd_card *card,
1712 /* read serial */ 1722 /* read serial */
1713 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial); 1723 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
1714 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model); 1724 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
1715 printk(KERN_INFO "snd-ca0106: Model %04x Rev %08x Serial %08x\n", 1725 dev_info(card->dev, "Model %04x Rev %08x Serial %08x\n",
1716 chip->model, pci->revision, chip->serial); 1726 chip->model, pci->revision, chip->serial);
1717 strcpy(card->driver, "CA0106"); 1727 strcpy(card->driver, "CA0106");
1718 strcpy(card->shortname, "CA0106"); 1728 strcpy(card->shortname, "CA0106");
@@ -1726,7 +1736,7 @@ static int snd_ca0106_create(int dev, struct snd_card *card,
1726 } 1736 }
1727 chip->details = c; 1737 chip->details = c;
1728 if (subsystem[dev]) { 1738 if (subsystem[dev]) {
1729 printk(KERN_INFO "snd-ca0106: Sound card name=%s, " 1739 dev_info(card->dev, "Sound card name=%s, "
1730 "subsystem=0x%x. Forced to subsystem=0x%x\n", 1740 "subsystem=0x%x. Forced to subsystem=0x%x\n",
1731 c->name, chip->serial, subsystem[dev]); 1741 c->name, chip->serial, subsystem[dev]);
1732 } 1742 }
@@ -1843,7 +1853,8 @@ static int snd_ca0106_probe(struct pci_dev *pci,
1843 return -ENOENT; 1853 return -ENOENT;
1844 } 1854 }
1845 1855
1846 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1856 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1857 0, &card);
1847 if (err < 0) 1858 if (err < 0)
1848 return err; 1859 return err;
1849 1860
@@ -1868,18 +1879,16 @@ static int snd_ca0106_probe(struct pci_dev *pci,
1868 if (err < 0) 1879 if (err < 0)
1869 goto error; 1880 goto error;
1870 1881
1871 snd_printdd("ca0106: probe for MIDI channel A ..."); 1882 dev_dbg(card->dev, "probe for MIDI channel A ...");
1872 err = snd_ca0106_midi(chip, CA0106_MIDI_CHAN_A); 1883 err = snd_ca0106_midi(chip, CA0106_MIDI_CHAN_A);
1873 if (err < 0) 1884 if (err < 0)
1874 goto error; 1885 goto error;
1875 snd_printdd(" done.\n"); 1886 dev_dbg(card->dev, " done.\n");
1876 1887
1877#ifdef CONFIG_PROC_FS 1888#ifdef CONFIG_PROC_FS
1878 snd_ca0106_proc_init(chip); 1889 snd_ca0106_proc_init(chip);
1879#endif 1890#endif
1880 1891
1881 snd_card_set_dev(card, &pci->dev);
1882
1883 err = snd_card_register(card); 1892 err = snd_card_register(card);
1884 if (err < 0) 1893 if (err < 0)
1885 goto error; 1894 goto error;
diff --git a/sound/pci/ca0106/ca_midi.c b/sound/pci/ca0106/ca_midi.c
index 8bbdf265d11d..b91c7f6d19f9 100644
--- a/sound/pci/ca0106/ca_midi.c
+++ b/sound/pci/ca0106/ca_midi.c
@@ -46,7 +46,7 @@ static void ca_midi_clear_rx(struct snd_ca_midi *midi)
46 ca_midi_read_data(midi); 46 ca_midi_read_data(midi);
47#ifdef CONFIG_SND_DEBUG 47#ifdef CONFIG_SND_DEBUG
48 if (timeout <= 0) 48 if (timeout <= 0)
49 snd_printk(KERN_ERR "ca_midi_clear_rx: timeout (status = 0x%x)\n", 49 pr_err("ca_midi_clear_rx: timeout (status = 0x%x)\n",
50 ca_midi_read_stat(midi)); 50 ca_midi_read_stat(midi));
51#endif 51#endif
52} 52}
@@ -113,7 +113,7 @@ static void ca_midi_cmd(struct snd_ca_midi *midi, unsigned char cmd, int ack)
113 } 113 }
114 spin_unlock_irqrestore(&midi->input_lock, flags); 114 spin_unlock_irqrestore(&midi->input_lock, flags);
115 if (!ok) 115 if (!ok)
116 snd_printk(KERN_ERR "ca_midi_cmd: 0x%x failed at 0x%x (status = 0x%x, data = 0x%x)!!!\n", 116 pr_err("ca_midi_cmd: 0x%x failed at 0x%x (status = 0x%x, data = 0x%x)!!!\n",
117 cmd, 117 cmd,
118 midi->get_dev_id_port(midi->dev_id), 118 midi->get_dev_id_port(midi->dev_id),
119 ca_midi_read_stat(midi), 119 ca_midi_read_stat(midi),
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 2755ec5bcc25..12c318e175f4 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -796,7 +796,7 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
796 if (runtime->channels > 1) 796 if (runtime->channels > 1)
797 rec->fmt |= 0x01; 797 rec->fmt |= 0x01;
798 if (rec->is_dac && set_dac_channels(cm, rec, runtime->channels) < 0) { 798 if (rec->is_dac && set_dac_channels(cm, rec, runtime->channels) < 0) {
799 snd_printd("cannot set dac channels\n"); 799 dev_dbg(cm->card->dev, "cannot set dac channels\n");
800 return -EINVAL; 800 return -EINVAL;
801 } 801 }
802 802
@@ -827,7 +827,7 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
827 else 827 else
828 cm->ctrl |= val; 828 cm->ctrl |= val;
829 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); 829 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl);
830 //snd_printd("cmipci: functrl0 = %08x\n", cm->ctrl); 830 /* dev_dbg(cm->card->dev, "functrl0 = %08x\n", cm->ctrl); */
831 831
832 /* set sample rate */ 832 /* set sample rate */
833 freq = 0; 833 freq = 0;
@@ -850,7 +850,7 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
850 val |= (freq << CM_ASFC_SHIFT) & CM_ASFC_MASK; 850 val |= (freq << CM_ASFC_SHIFT) & CM_ASFC_MASK;
851 } 851 }
852 snd_cmipci_write(cm, CM_REG_FUNCTRL1, val); 852 snd_cmipci_write(cm, CM_REG_FUNCTRL1, val);
853 //snd_printd("cmipci: functrl1 = %08x\n", val); 853 dev_dbg(cm->card->dev, "functrl1 = %08x\n", val);
854 854
855 /* set format */ 855 /* set format */
856 val = snd_cmipci_read(cm, CM_REG_CHFORMAT); 856 val = snd_cmipci_read(cm, CM_REG_CHFORMAT);
@@ -866,7 +866,7 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
866 val |= freq_ext << (rec->ch * 2); 866 val |= freq_ext << (rec->ch * 2);
867 } 867 }
868 snd_cmipci_write(cm, CM_REG_CHFORMAT, val); 868 snd_cmipci_write(cm, CM_REG_CHFORMAT, val);
869 //snd_printd("cmipci: chformat = %08x\n", val); 869 dev_dbg(cm->card->dev, "chformat = %08x\n", val);
870 870
871 if (!rec->is_dac && cm->chip_version) { 871 if (!rec->is_dac && cm->chip_version) {
872 if (runtime->rate > 44100) 872 if (runtime->rate > 44100)
@@ -904,7 +904,7 @@ static int snd_cmipci_pcm_trigger(struct cmipci *cm, struct cmipci_pcm *rec,
904 cm->ctrl |= chen; 904 cm->ctrl |= chen;
905 /* enable channel */ 905 /* enable channel */
906 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); 906 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl);
907 //snd_printd("cmipci: functrl0 = %08x\n", cm->ctrl); 907 dev_dbg(cm->card->dev, "functrl0 = %08x\n", cm->ctrl);
908 break; 908 break;
909 case SNDRV_PCM_TRIGGER_STOP: 909 case SNDRV_PCM_TRIGGER_STOP:
910 rec->running = 0; 910 rec->running = 0;
@@ -952,7 +952,7 @@ static snd_pcm_uframes_t snd_cmipci_pcm_pointer(struct cmipci *cm, struct cmipci
952 if (rem < rec->dma_size) 952 if (rem < rec->dma_size)
953 goto ok; 953 goto ok;
954 } 954 }
955 printk(KERN_ERR "cmipci: invalid PCM pointer: %#x\n", rem); 955 dev_err(cm->card->dev, "invalid PCM pointer: %#x\n", rem);
956 return SNDRV_PCM_POS_XRUN; 956 return SNDRV_PCM_POS_XRUN;
957ok: 957ok:
958 ptr = (rec->dma_size - (rem + 1)) >> rec->shift; 958 ptr = (rec->dma_size - (rem + 1)) >> rec->shift;
@@ -2889,13 +2889,13 @@ static int snd_cmipci_create_gameport(struct cmipci *cm, int dev)
2889 } 2889 }
2890 2890
2891 if (!r) { 2891 if (!r) {
2892 printk(KERN_WARNING "cmipci: cannot reserve joystick ports\n"); 2892 dev_warn(cm->card->dev, "cannot reserve joystick ports\n");
2893 return -EBUSY; 2893 return -EBUSY;
2894 } 2894 }
2895 2895
2896 cm->gameport = gp = gameport_allocate_port(); 2896 cm->gameport = gp = gameport_allocate_port();
2897 if (!gp) { 2897 if (!gp) {
2898 printk(KERN_ERR "cmipci: cannot allocate memory for gameport\n"); 2898 dev_err(cm->card->dev, "cannot allocate memory for gameport\n");
2899 release_and_free_resource(r); 2899 release_and_free_resource(r);
2900 return -ENOMEM; 2900 return -ENOMEM;
2901 } 2901 }
@@ -2995,13 +2995,14 @@ static int snd_cmipci_create_fm(struct cmipci *cm, long fm_port)
2995 2995
2996 if (snd_opl3_create(cm->card, iosynth, iosynth + 2, 2996 if (snd_opl3_create(cm->card, iosynth, iosynth + 2,
2997 OPL3_HW_OPL3, 0, &opl3) < 0) { 2997 OPL3_HW_OPL3, 0, &opl3) < 0) {
2998 printk(KERN_ERR "cmipci: no OPL device at %#lx, " 2998 dev_err(cm->card->dev,
2999 "skipping...\n", iosynth); 2999 "no OPL device at %#lx, skipping...\n",
3000 iosynth);
3000 goto disable_fm; 3001 goto disable_fm;
3001 } 3002 }
3002 } 3003 }
3003 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { 3004 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
3004 printk(KERN_ERR "cmipci: cannot create OPL3 hwdep\n"); 3005 dev_err(cm->card->dev, "cannot create OPL3 hwdep\n");
3005 return err; 3006 return err;
3006 } 3007 }
3007 return 0; 3008 return 0;
@@ -3060,7 +3061,7 @@ static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
3060 3061
3061 if (request_irq(pci->irq, snd_cmipci_interrupt, 3062 if (request_irq(pci->irq, snd_cmipci_interrupt,
3062 IRQF_SHARED, KBUILD_MODNAME, cm)) { 3063 IRQF_SHARED, KBUILD_MODNAME, cm)) {
3063 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 3064 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
3064 snd_cmipci_free(cm); 3065 snd_cmipci_free(cm);
3065 return -EBUSY; 3066 return -EBUSY;
3066 } 3067 }
@@ -3192,8 +3193,9 @@ static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
3192 /* enable UART */ 3193 /* enable UART */
3193 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN); 3194 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN);
3194 if (inb(iomidi + 1) == 0xff) { 3195 if (inb(iomidi + 1) == 0xff) {
3195 snd_printk(KERN_ERR "cannot enable MPU-401 port" 3196 dev_err(cm->card->dev,
3196 " at %#lx\n", iomidi); 3197 "cannot enable MPU-401 port at %#lx\n",
3198 iomidi);
3197 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, 3199 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1,
3198 CM_UART_EN); 3200 CM_UART_EN);
3199 iomidi = 0; 3201 iomidi = 0;
@@ -3237,7 +3239,8 @@ static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
3237 MPU401_INFO_INTEGRATED : 0) | 3239 MPU401_INFO_INTEGRATED : 0) |
3238 MPU401_INFO_IRQ_HOOK, 3240 MPU401_INFO_IRQ_HOOK,
3239 -1, &cm->rmidi)) < 0) { 3241 -1, &cm->rmidi)) < 0) {
3240 printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi); 3242 dev_err(cm->card->dev,
3243 "no UART401 device at 0x%lx\n", iomidi);
3241 } 3244 }
3242 } 3245 }
3243 3246
@@ -3254,8 +3257,6 @@ static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
3254 if (snd_cmipci_create_gameport(cm, dev) < 0) 3257 if (snd_cmipci_create_gameport(cm, dev) < 0)
3255 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN); 3258 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
3256 3259
3257 snd_card_set_dev(card, &pci->dev);
3258
3259 *rcmipci = cm; 3260 *rcmipci = cm;
3260 return 0; 3261 return 0;
3261} 3262}
@@ -3280,7 +3281,8 @@ static int snd_cmipci_probe(struct pci_dev *pci,
3280 return -ENOENT; 3281 return -ENOENT;
3281 } 3282 }
3282 3283
3283 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 3284 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
3285 0, &card);
3284 if (err < 0) 3286 if (err < 0)
3285 return err; 3287 return err;
3286 3288
@@ -3381,8 +3383,7 @@ static int snd_cmipci_resume(struct device *dev)
3381 pci_set_power_state(pci, PCI_D0); 3383 pci_set_power_state(pci, PCI_D0);
3382 pci_restore_state(pci); 3384 pci_restore_state(pci);
3383 if (pci_enable_device(pci) < 0) { 3385 if (pci_enable_device(pci) < 0) {
3384 printk(KERN_ERR "cmipci: pci_enable_device failed, " 3386 dev_err(dev, "pci_enable_device failed, disabling device\n");
3385 "disabling device\n");
3386 snd_card_disconnect(card); 3387 snd_card_disconnect(card);
3387 return -EIO; 3388 return -EIO;
3388 } 3389 }
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index 1dc793e742d7..43d1f912c641 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -564,7 +564,8 @@ static void snd_cs4281_ac97_write(struct snd_ac97 *ac97,
564 return; 564 return;
565 } 565 }
566 } 566 }
567 snd_printk(KERN_ERR "AC'97 write problem, reg = 0x%x, val = 0x%x\n", reg, val); 567 dev_err(chip->card->dev,
568 "AC'97 write problem, reg = 0x%x, val = 0x%x\n", reg, val);
568} 569}
569 570
570static unsigned short snd_cs4281_ac97_read(struct snd_ac97 *ac97, 571static unsigned short snd_cs4281_ac97_read(struct snd_ac97 *ac97,
@@ -624,7 +625,8 @@ static unsigned short snd_cs4281_ac97_read(struct snd_ac97 *ac97,
624 goto __ok1; 625 goto __ok1;
625 } 626 }
626 627
627 snd_printk(KERN_ERR "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg); 628 dev_err(chip->card->dev,
629 "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg);
628 result = 0xffff; 630 result = 0xffff;
629 goto __end; 631 goto __end;
630 632
@@ -643,7 +645,8 @@ static unsigned short snd_cs4281_ac97_read(struct snd_ac97 *ac97,
643 udelay(10); 645 udelay(10);
644 } 646 }
645 647
646 snd_printk(KERN_ERR "AC'97 read problem (ACSTS_VSTS), reg = 0x%x\n", reg); 648 dev_err(chip->card->dev,
649 "AC'97 read problem (ACSTS_VSTS), reg = 0x%x\n", reg);
647 result = 0xffff; 650 result = 0xffff;
648 goto __end; 651 goto __end;
649 652
@@ -835,8 +838,9 @@ static snd_pcm_uframes_t snd_cs4281_pointer(struct snd_pcm_substream *substream)
835 struct cs4281 *chip = snd_pcm_substream_chip(substream); 838 struct cs4281 *chip = snd_pcm_substream_chip(substream);
836 839
837 /* 840 /*
838 printk(KERN_DEBUG "DCC = 0x%x, buffer_size = 0x%x, jiffies = %li\n", 841 dev_dbg(chip->card->dev,
839 snd_cs4281_peekBA0(chip, dma->regDCC), runtime->buffer_size, 842 "DCC = 0x%x, buffer_size = 0x%x, jiffies = %li\n",
843 snd_cs4281_peekBA0(chip, dma->regDCC), runtime->buffer_size,
840 jiffies); 844 jiffies);
841 */ 845 */
842 return runtime->buffer_size - 846 return runtime->buffer_size -
@@ -1265,7 +1269,8 @@ static int snd_cs4281_create_gameport(struct cs4281 *chip)
1265 1269
1266 chip->gameport = gp = gameport_allocate_port(); 1270 chip->gameport = gp = gameport_allocate_port();
1267 if (!gp) { 1271 if (!gp) {
1268 printk(KERN_ERR "cs4281: cannot allocate memory for gameport\n"); 1272 dev_err(chip->card->dev,
1273 "cannot allocate memory for gameport\n");
1269 return -ENOMEM; 1274 return -ENOMEM;
1270 } 1275 }
1271 1276
@@ -1361,7 +1366,7 @@ static int snd_cs4281_create(struct snd_card *card,
1361 chip->irq = -1; 1366 chip->irq = -1;
1362 pci_set_master(pci); 1367 pci_set_master(pci);
1363 if (dual_codec < 0 || dual_codec > 3) { 1368 if (dual_codec < 0 || dual_codec > 3) {
1364 snd_printk(KERN_ERR "invalid dual_codec option %d\n", dual_codec); 1369 dev_err(card->dev, "invalid dual_codec option %d\n", dual_codec);
1365 dual_codec = 0; 1370 dual_codec = 0;
1366 } 1371 }
1367 chip->dual_codec = dual_codec; 1372 chip->dual_codec = dual_codec;
@@ -1383,7 +1388,7 @@ static int snd_cs4281_create(struct snd_card *card,
1383 1388
1384 if (request_irq(pci->irq, snd_cs4281_interrupt, IRQF_SHARED, 1389 if (request_irq(pci->irq, snd_cs4281_interrupt, IRQF_SHARED,
1385 KBUILD_MODNAME, chip)) { 1390 KBUILD_MODNAME, chip)) {
1386 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1391 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1387 snd_cs4281_free(chip); 1392 snd_cs4281_free(chip);
1388 return -ENOMEM; 1393 return -ENOMEM;
1389 } 1394 }
@@ -1402,8 +1407,6 @@ static int snd_cs4281_create(struct snd_card *card,
1402 1407
1403 snd_cs4281_proc_init(chip); 1408 snd_cs4281_proc_init(chip);
1404 1409
1405 snd_card_set_dev(card, &pci->dev);
1406
1407 *rchip = chip; 1410 *rchip = chip;
1408 return 0; 1411 return 0;
1409} 1412}
@@ -1425,7 +1428,8 @@ static int snd_cs4281_chip_init(struct cs4281 *chip)
1425 snd_cs4281_pokeBA0(chip, BA0_CFLR, BA0_CFLR_DEFAULT); 1428 snd_cs4281_pokeBA0(chip, BA0_CFLR, BA0_CFLR_DEFAULT);
1426 tmp = snd_cs4281_peekBA0(chip, BA0_CFLR); 1429 tmp = snd_cs4281_peekBA0(chip, BA0_CFLR);
1427 if (tmp != BA0_CFLR_DEFAULT) { 1430 if (tmp != BA0_CFLR_DEFAULT) {
1428 snd_printk(KERN_ERR "CFLR setup failed (0x%x)\n", tmp); 1431 dev_err(chip->card->dev,
1432 "CFLR setup failed (0x%x)\n", tmp);
1429 return -EIO; 1433 return -EIO;
1430 } 1434 }
1431 } 1435 }
@@ -1436,11 +1440,13 @@ static int snd_cs4281_chip_init(struct cs4281 *chip)
1436 snd_cs4281_pokeBA0(chip, BA0_CWPR, 0x4281); 1440 snd_cs4281_pokeBA0(chip, BA0_CWPR, 0x4281);
1437 1441
1438 if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC1)) != (BA0_SERC1_SO1EN | BA0_SERC1_AC97)) { 1442 if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC1)) != (BA0_SERC1_SO1EN | BA0_SERC1_AC97)) {
1439 snd_printk(KERN_ERR "SERC1 AC'97 check failed (0x%x)\n", tmp); 1443 dev_err(chip->card->dev,
1444 "SERC1 AC'97 check failed (0x%x)\n", tmp);
1440 return -EIO; 1445 return -EIO;
1441 } 1446 }
1442 if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC2)) != (BA0_SERC2_SI1EN | BA0_SERC2_AC97)) { 1447 if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC2)) != (BA0_SERC2_SI1EN | BA0_SERC2_AC97)) {
1443 snd_printk(KERN_ERR "SERC2 AC'97 check failed (0x%x)\n", tmp); 1448 dev_err(chip->card->dev,
1449 "SERC2 AC'97 check failed (0x%x)\n", tmp);
1444 return -EIO; 1450 return -EIO;
1445 } 1451 }
1446 1452
@@ -1502,7 +1508,7 @@ static int snd_cs4281_chip_init(struct cs4281 *chip)
1502 schedule_timeout_uninterruptible(1); 1508 schedule_timeout_uninterruptible(1);
1503 } while (time_after_eq(end_time, jiffies)); 1509 } while (time_after_eq(end_time, jiffies));
1504 1510
1505 snd_printk(KERN_ERR "DLLRDY not seen\n"); 1511 dev_err(chip->card->dev, "DLLRDY not seen\n");
1506 return -EIO; 1512 return -EIO;
1507 1513
1508 __ok0: 1514 __ok0:
@@ -1528,7 +1534,9 @@ static int snd_cs4281_chip_init(struct cs4281 *chip)
1528 schedule_timeout_uninterruptible(1); 1534 schedule_timeout_uninterruptible(1);
1529 } while (time_after_eq(end_time, jiffies)); 1535 } while (time_after_eq(end_time, jiffies));
1530 1536
1531 snd_printk(KERN_ERR "never read codec ready from AC'97 (0x%x)\n", snd_cs4281_peekBA0(chip, BA0_ACSTS)); 1537 dev_err(chip->card->dev,
1538 "never read codec ready from AC'97 (0x%x)\n",
1539 snd_cs4281_peekBA0(chip, BA0_ACSTS));
1532 return -EIO; 1540 return -EIO;
1533 1541
1534 __ok1: 1542 __ok1:
@@ -1539,7 +1547,8 @@ static int snd_cs4281_chip_init(struct cs4281 *chip)
1539 goto __codec2_ok; 1547 goto __codec2_ok;
1540 schedule_timeout_uninterruptible(1); 1548 schedule_timeout_uninterruptible(1);
1541 } while (time_after_eq(end_time, jiffies)); 1549 } while (time_after_eq(end_time, jiffies));
1542 snd_printk(KERN_INFO "secondary codec doesn't respond. disable it...\n"); 1550 dev_info(chip->card->dev,
1551 "secondary codec doesn't respond. disable it...\n");
1543 chip->dual_codec = 0; 1552 chip->dual_codec = 0;
1544 __codec2_ok: ; 1553 __codec2_ok: ;
1545 } 1554 }
@@ -1569,7 +1578,7 @@ static int snd_cs4281_chip_init(struct cs4281 *chip)
1569 1578
1570 if (--retry_count > 0) 1579 if (--retry_count > 0)
1571 goto __retry; 1580 goto __retry;
1572 snd_printk(KERN_ERR "never read ISV3 and ISV4 from AC'97\n"); 1581 dev_err(chip->card->dev, "never read ISV3 and ISV4 from AC'97\n");
1573 return -EIO; 1582 return -EIO;
1574 1583
1575 __ok2: 1584 __ok2:
@@ -1917,7 +1926,8 @@ static int snd_cs4281_probe(struct pci_dev *pci,
1917 return -ENOENT; 1926 return -ENOENT;
1918 } 1927 }
1919 1928
1920 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1929 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1930 0, &card);
1921 if (err < 0) 1931 if (err < 0)
1922 return err; 1932 return err;
1923 1933
@@ -2055,8 +2065,7 @@ static int cs4281_resume(struct device *dev)
2055 pci_set_power_state(pci, PCI_D0); 2065 pci_set_power_state(pci, PCI_D0);
2056 pci_restore_state(pci); 2066 pci_restore_state(pci);
2057 if (pci_enable_device(pci) < 0) { 2067 if (pci_enable_device(pci) < 0) {
2058 printk(KERN_ERR "cs4281: pci_enable_device failed, " 2068 dev_err(dev, "pci_enable_device failed, disabling device\n");
2059 "disabling device\n");
2060 snd_card_disconnect(card); 2069 snd_card_disconnect(card);
2061 return -EIO; 2070 return -EIO;
2062 } 2071 }
diff --git a/sound/pci/cs46xx/cs46xx.c b/sound/pci/cs46xx/cs46xx.c
index b03498325d66..af0eacbc8bd2 100644
--- a/sound/pci/cs46xx/cs46xx.c
+++ b/sound/pci/cs46xx/cs46xx.c
@@ -88,7 +88,8 @@ static int snd_card_cs46xx_probe(struct pci_dev *pci,
88 return -ENOENT; 88 return -ENOENT;
89 } 89 }
90 90
91 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 91 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
92 0, &card);
92 if (err < 0) 93 if (err < 0)
93 return err; 94 return err;
94 if ((err = snd_cs46xx_create(card, pci, 95 if ((err = snd_cs46xx_create(card, pci,
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index 062398ec5335..32b44f25b5c8 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -116,7 +116,7 @@ static unsigned short snd_cs46xx_codec_read(struct snd_cs46xx *chip,
116 116
117 tmp = snd_cs46xx_peekBA0(chip, BA0_ACCTL); 117 tmp = snd_cs46xx_peekBA0(chip, BA0_ACCTL);
118 if ((tmp & ACCTL_VFRM) == 0) { 118 if ((tmp & ACCTL_VFRM) == 0) {
119 snd_printk(KERN_WARNING "cs46xx: ACCTL_VFRM not set 0x%x\n",tmp); 119 dev_warn(chip->card->dev, "ACCTL_VFRM not set 0x%x\n", tmp);
120 snd_cs46xx_pokeBA0(chip, BA0_ACCTL, (tmp & (~ACCTL_ESYN)) | ACCTL_VFRM ); 120 snd_cs46xx_pokeBA0(chip, BA0_ACCTL, (tmp & (~ACCTL_ESYN)) | ACCTL_VFRM );
121 msleep(50); 121 msleep(50);
122 tmp = snd_cs46xx_peekBA0(chip, BA0_ACCTL + offset); 122 tmp = snd_cs46xx_peekBA0(chip, BA0_ACCTL + offset);
@@ -168,7 +168,8 @@ static unsigned short snd_cs46xx_codec_read(struct snd_cs46xx *chip,
168 goto ok1; 168 goto ok1;
169 } 169 }
170 170
171 snd_printk(KERN_ERR "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg); 171 dev_err(chip->card->dev,
172 "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg);
172 result = 0xffff; 173 result = 0xffff;
173 goto end; 174 goto end;
174 175
@@ -187,7 +188,9 @@ static unsigned short snd_cs46xx_codec_read(struct snd_cs46xx *chip,
187 udelay(10); 188 udelay(10);
188 } 189 }
189 190
190 snd_printk(KERN_ERR "AC'97 read problem (ACSTS_VSTS), codec_index %d, reg = 0x%x\n", codec_index, reg); 191 dev_err(chip->card->dev,
192 "AC'97 read problem (ACSTS_VSTS), codec_index %d, reg = 0x%x\n",
193 codec_index, reg);
191 result = 0xffff; 194 result = 0xffff;
192 goto end; 195 goto end;
193 196
@@ -197,7 +200,8 @@ static unsigned short snd_cs46xx_codec_read(struct snd_cs46xx *chip,
197 * ACSDA = Status Data Register = 474h 200 * ACSDA = Status Data Register = 474h
198 */ 201 */
199#if 0 202#if 0
200 printk(KERN_DEBUG "e) reg = 0x%x, val = 0x%x, BA0_ACCAD = 0x%x\n", reg, 203 dev_dbg(chip->card->dev,
204 "e) reg = 0x%x, val = 0x%x, BA0_ACCAD = 0x%x\n", reg,
201 snd_cs46xx_peekBA0(chip, BA0_ACSDA), 205 snd_cs46xx_peekBA0(chip, BA0_ACSDA),
202 snd_cs46xx_peekBA0(chip, BA0_ACCAD)); 206 snd_cs46xx_peekBA0(chip, BA0_ACCAD));
203#endif 207#endif
@@ -286,7 +290,9 @@ static void snd_cs46xx_codec_write(struct snd_cs46xx *chip,
286 goto end; 290 goto end;
287 } 291 }
288 } 292 }
289 snd_printk(KERN_ERR "AC'97 write problem, codec_index = %d, reg = 0x%x, val = 0x%x\n", codec_index, reg, val); 293 dev_err(chip->card->dev,
294 "AC'97 write problem, codec_index = %d, reg = 0x%x, val = 0x%x\n",
295 codec_index, reg, val);
290 end: 296 end:
291 chip->active_ctrl(chip, -1); 297 chip->active_ctrl(chip, -1);
292} 298}
@@ -608,8 +614,8 @@ static int cs46xx_wait_for_fifo(struct snd_cs46xx * chip,int retry_timeout)
608 } 614 }
609 615
610 if(status & SERBST_WBSY) { 616 if(status & SERBST_WBSY) {
611 snd_printk(KERN_ERR "cs46xx: failure waiting for " 617 dev_err(chip->card->dev,
612 "FIFO command to complete\n"); 618 "failure waiting for FIFO command to complete\n");
613 return -EINVAL; 619 return -EINVAL;
614 } 620 }
615 621
@@ -646,7 +652,9 @@ static void snd_cs46xx_clear_serial_FIFOs(struct snd_cs46xx *chip)
646 * Make sure the previous FIFO write operation has completed. 652 * Make sure the previous FIFO write operation has completed.
647 */ 653 */
648 if (cs46xx_wait_for_fifo(chip,1)) { 654 if (cs46xx_wait_for_fifo(chip,1)) {
649 snd_printdd ("failed waiting for FIFO at addr (%02X)\n",idx); 655 dev_dbg(chip->card->dev,
656 "failed waiting for FIFO at addr (%02X)\n",
657 idx);
650 658
651 if (powerdown) 659 if (powerdown)
652 snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); 660 snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp);
@@ -694,7 +702,7 @@ static void snd_cs46xx_proc_start(struct snd_cs46xx *chip)
694 } 702 }
695 703
696 if (snd_cs46xx_peek(chip, BA1_SPCR) & SPCR_RUNFR) 704 if (snd_cs46xx_peek(chip, BA1_SPCR) & SPCR_RUNFR)
697 snd_printk(KERN_ERR "SPCR_RUNFR never reset\n"); 705 dev_err(chip->card->dev, "SPCR_RUNFR never reset\n");
698} 706}
699 707
700static void snd_cs46xx_proc_stop(struct snd_cs46xx *chip) 708static void snd_cs46xx_proc_stop(struct snd_cs46xx *chip)
@@ -1054,7 +1062,8 @@ static int _cs46xx_adjust_sample_rate (struct snd_cs46xx *chip, struct snd_cs46x
1054 cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, sample_rate, 1062 cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, sample_rate,
1055 cpcm, cpcm->hw_buf.addr,cpcm->pcm_channel_id); 1063 cpcm, cpcm->hw_buf.addr,cpcm->pcm_channel_id);
1056 if (cpcm->pcm_channel == NULL) { 1064 if (cpcm->pcm_channel == NULL) {
1057 snd_printk(KERN_ERR "cs46xx: failed to create virtual PCM channel\n"); 1065 dev_err(chip->card->dev,
1066 "failed to create virtual PCM channel\n");
1058 return -ENOMEM; 1067 return -ENOMEM;
1059 } 1068 }
1060 cpcm->pcm_channel->sample_rate = sample_rate; 1069 cpcm->pcm_channel->sample_rate = sample_rate;
@@ -1067,7 +1076,8 @@ static int _cs46xx_adjust_sample_rate (struct snd_cs46xx *chip, struct snd_cs46x
1067 if ( (cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, sample_rate, cpcm, 1076 if ( (cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, sample_rate, cpcm,
1068 cpcm->hw_buf.addr, 1077 cpcm->hw_buf.addr,
1069 cpcm->pcm_channel_id)) == NULL) { 1078 cpcm->pcm_channel_id)) == NULL) {
1070 snd_printk(KERN_ERR "cs46xx: failed to re-create virtual PCM channel\n"); 1079 dev_err(chip->card->dev,
1080 "failed to re-create virtual PCM channel\n");
1071 return -ENOMEM; 1081 return -ENOMEM;
1072 } 1082 }
1073 1083
@@ -1116,7 +1126,8 @@ static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream,
1116 return -EINVAL; 1126 return -EINVAL;
1117 } 1127 }
1118 1128
1119 snd_printdd ("period_size (%d), periods (%d) buffer_size(%d)\n", 1129 dev_dbg(chip->card->dev,
1130 "period_size (%d), periods (%d) buffer_size(%d)\n",
1120 period_size, params_periods(hw_params), 1131 period_size, params_periods(hw_params),
1121 params_buffer_bytes(hw_params)); 1132 params_buffer_bytes(hw_params));
1122#endif 1133#endif
@@ -1531,22 +1542,20 @@ static int _cs46xx_playback_open_channel (struct snd_pcm_substream *substream,in
1531 1542
1532static int snd_cs46xx_playback_open(struct snd_pcm_substream *substream) 1543static int snd_cs46xx_playback_open(struct snd_pcm_substream *substream)
1533{ 1544{
1534 snd_printdd("open front channel\n"); 1545 dev_dbg(substream->pcm->card->dev, "open front channel\n");
1535 return _cs46xx_playback_open_channel(substream,DSP_PCM_MAIN_CHANNEL); 1546 return _cs46xx_playback_open_channel(substream,DSP_PCM_MAIN_CHANNEL);
1536} 1547}
1537 1548
1538#ifdef CONFIG_SND_CS46XX_NEW_DSP 1549#ifdef CONFIG_SND_CS46XX_NEW_DSP
1539static int snd_cs46xx_playback_open_rear(struct snd_pcm_substream *substream) 1550static int snd_cs46xx_playback_open_rear(struct snd_pcm_substream *substream)
1540{ 1551{
1541 snd_printdd("open rear channel\n"); 1552 dev_dbg(substream->pcm->card->dev, "open rear channel\n");
1542
1543 return _cs46xx_playback_open_channel(substream,DSP_PCM_REAR_CHANNEL); 1553 return _cs46xx_playback_open_channel(substream,DSP_PCM_REAR_CHANNEL);
1544} 1554}
1545 1555
1546static int snd_cs46xx_playback_open_clfe(struct snd_pcm_substream *substream) 1556static int snd_cs46xx_playback_open_clfe(struct snd_pcm_substream *substream)
1547{ 1557{
1548 snd_printdd("open center - LFE channel\n"); 1558 dev_dbg(substream->pcm->card->dev, "open center - LFE channel\n");
1549
1550 return _cs46xx_playback_open_channel(substream,DSP_PCM_CENTER_LFE_CHANNEL); 1559 return _cs46xx_playback_open_channel(substream,DSP_PCM_CENTER_LFE_CHANNEL);
1551} 1560}
1552 1561
@@ -1554,7 +1563,7 @@ static int snd_cs46xx_playback_open_iec958(struct snd_pcm_substream *substream)
1554{ 1563{
1555 struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 1564 struct snd_cs46xx *chip = snd_pcm_substream_chip(substream);
1556 1565
1557 snd_printdd("open raw iec958 channel\n"); 1566 dev_dbg(chip->card->dev, "open raw iec958 channel\n");
1558 1567
1559 mutex_lock(&chip->spos_mutex); 1568 mutex_lock(&chip->spos_mutex);
1560 cs46xx_iec958_pre_open (chip); 1569 cs46xx_iec958_pre_open (chip);
@@ -1570,7 +1579,7 @@ static int snd_cs46xx_playback_close_iec958(struct snd_pcm_substream *substream)
1570 int err; 1579 int err;
1571 struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); 1580 struct snd_cs46xx *chip = snd_pcm_substream_chip(substream);
1572 1581
1573 snd_printdd("close raw iec958 channel\n"); 1582 dev_dbg(chip->card->dev, "close raw iec958 channel\n");
1574 1583
1575 err = snd_cs46xx_playback_close(substream); 1584 err = snd_cs46xx_playback_close(substream);
1576 1585
@@ -2421,10 +2430,10 @@ static void snd_cs46xx_codec_reset (struct snd_ac97 * ac97)
2421 2430
2422 /* set the desired CODEC mode */ 2431 /* set the desired CODEC mode */
2423 if (ac97->num == CS46XX_PRIMARY_CODEC_INDEX) { 2432 if (ac97->num == CS46XX_PRIMARY_CODEC_INDEX) {
2424 snd_printdd("cs46xx: CODEC1 mode %04x\n", 0x0); 2433 dev_dbg(ac97->bus->card->dev, "CODEC1 mode %04x\n", 0x0);
2425 snd_cs46xx_ac97_write(ac97, AC97_CSR_ACMODE, 0x0); 2434 snd_cs46xx_ac97_write(ac97, AC97_CSR_ACMODE, 0x0);
2426 } else if (ac97->num == CS46XX_SECONDARY_CODEC_INDEX) { 2435 } else if (ac97->num == CS46XX_SECONDARY_CODEC_INDEX) {
2427 snd_printdd("cs46xx: CODEC2 mode %04x\n", 0x3); 2436 dev_dbg(ac97->bus->card->dev, "CODEC2 mode %04x\n", 0x3);
2428 snd_cs46xx_ac97_write(ac97, AC97_CSR_ACMODE, 0x3); 2437 snd_cs46xx_ac97_write(ac97, AC97_CSR_ACMODE, 0x3);
2429 } else { 2438 } else {
2430 snd_BUG(); /* should never happen ... */ 2439 snd_BUG(); /* should never happen ... */
@@ -2456,7 +2465,8 @@ static void snd_cs46xx_codec_reset (struct snd_ac97 * ac97)
2456 msleep(10); 2465 msleep(10);
2457 } while (time_after_eq(end_time, jiffies)); 2466 } while (time_after_eq(end_time, jiffies));
2458 2467
2459 snd_printk(KERN_ERR "CS46xx secondary codec doesn't respond!\n"); 2468 dev_err(ac97->bus->card->dev,
2469 "CS46xx secondary codec doesn't respond!\n");
2460} 2470}
2461#endif 2471#endif
2462 2472
@@ -2476,7 +2486,8 @@ static int cs46xx_detect_codec(struct snd_cs46xx *chip, int codec)
2476 snd_cs46xx_codec_write(chip, AC97_RESET, 0, codec); 2486 snd_cs46xx_codec_write(chip, AC97_RESET, 0, codec);
2477 udelay(10); 2487 udelay(10);
2478 if (snd_cs46xx_codec_read(chip, AC97_RESET, codec) & 0x8000) { 2488 if (snd_cs46xx_codec_read(chip, AC97_RESET, codec) & 0x8000) {
2479 snd_printdd("snd_cs46xx: seconadry codec not present\n"); 2489 dev_dbg(chip->card->dev,
2490 "seconadry codec not present\n");
2480 return -ENXIO; 2491 return -ENXIO;
2481 } 2492 }
2482 } 2493 }
@@ -2489,7 +2500,7 @@ static int cs46xx_detect_codec(struct snd_cs46xx *chip, int codec)
2489 } 2500 }
2490 msleep(10); 2501 msleep(10);
2491 } 2502 }
2492 snd_printdd("snd_cs46xx: codec %d detection timeout\n", codec); 2503 dev_dbg(chip->card->dev, "codec %d detection timeout\n", codec);
2493 return -ENXIO; 2504 return -ENXIO;
2494} 2505}
2495 2506
@@ -2509,7 +2520,7 @@ int snd_cs46xx_mixer(struct snd_cs46xx *chip, int spdif_device)
2509 2520
2510 /* detect primary codec */ 2521 /* detect primary codec */
2511 chip->nr_ac97_codecs = 0; 2522 chip->nr_ac97_codecs = 0;
2512 snd_printdd("snd_cs46xx: detecting primary codec\n"); 2523 dev_dbg(chip->card->dev, "detecting primary codec\n");
2513 if ((err = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus)) < 0) 2524 if ((err = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus)) < 0)
2514 return err; 2525 return err;
2515 chip->ac97_bus->private_free = snd_cs46xx_mixer_free_ac97_bus; 2526 chip->ac97_bus->private_free = snd_cs46xx_mixer_free_ac97_bus;
@@ -2519,7 +2530,7 @@ int snd_cs46xx_mixer(struct snd_cs46xx *chip, int spdif_device)
2519 chip->nr_ac97_codecs = 1; 2530 chip->nr_ac97_codecs = 1;
2520 2531
2521#ifdef CONFIG_SND_CS46XX_NEW_DSP 2532#ifdef CONFIG_SND_CS46XX_NEW_DSP
2522 snd_printdd("snd_cs46xx: detecting seconadry codec\n"); 2533 dev_dbg(chip->card->dev, "detecting seconadry codec\n");
2523 /* try detect a secondary codec */ 2534 /* try detect a secondary codec */
2524 if (! cs46xx_detect_codec(chip, CS46XX_SECONDARY_CODEC_INDEX)) 2535 if (! cs46xx_detect_codec(chip, CS46XX_SECONDARY_CODEC_INDEX))
2525 chip->nr_ac97_codecs = 2; 2536 chip->nr_ac97_codecs = 2;
@@ -2554,7 +2565,7 @@ int snd_cs46xx_mixer(struct snd_cs46xx *chip, int spdif_device)
2554 } 2565 }
2555 /* do soundcard specific mixer setup */ 2566 /* do soundcard specific mixer setup */
2556 if (chip->mixer_init) { 2567 if (chip->mixer_init) {
2557 snd_printdd ("calling chip->mixer_init(chip);\n"); 2568 dev_dbg(chip->card->dev, "calling chip->mixer_init(chip);\n");
2558 chip->mixer_init(chip); 2569 chip->mixer_init(chip);
2559 } 2570 }
2560#endif 2571#endif
@@ -2801,7 +2812,8 @@ int snd_cs46xx_gameport(struct snd_cs46xx *chip)
2801 2812
2802 chip->gameport = gp = gameport_allocate_port(); 2813 chip->gameport = gp = gameport_allocate_port();
2803 if (!gp) { 2814 if (!gp) {
2804 printk(KERN_ERR "cs46xx: cannot allocate memory for gameport\n"); 2815 dev_err(chip->card->dev,
2816 "cannot allocate memory for gameport\n");
2805 return -ENOMEM; 2817 return -ENOMEM;
2806 } 2818 }
2807 2819
@@ -3138,8 +3150,10 @@ static int snd_cs46xx_chip_init(struct snd_cs46xx *chip)
3138 } 3150 }
3139 3151
3140 3152
3141 snd_printk(KERN_ERR "create - never read codec ready from AC'97\n"); 3153 dev_err(chip->card->dev,
3142 snd_printk(KERN_ERR "it is not probably bug, try to use CS4236 driver\n"); 3154 "create - never read codec ready from AC'97\n");
3155 dev_err(chip->card->dev,
3156 "it is not probably bug, try to use CS4236 driver\n");
3143 return -EIO; 3157 return -EIO;
3144 ok1: 3158 ok1:
3145#ifdef CONFIG_SND_CS46XX_NEW_DSP 3159#ifdef CONFIG_SND_CS46XX_NEW_DSP
@@ -3157,7 +3171,8 @@ static int snd_cs46xx_chip_init(struct snd_cs46xx *chip)
3157 * Make sure CODEC is READY. 3171 * Make sure CODEC is READY.
3158 */ 3172 */
3159 if (!(snd_cs46xx_peekBA0(chip, BA0_ACSTS2) & ACSTS_CRDY)) 3173 if (!(snd_cs46xx_peekBA0(chip, BA0_ACSTS2) & ACSTS_CRDY))
3160 snd_printdd("cs46xx: never read card ready from secondary AC'97\n"); 3174 dev_dbg(chip->card->dev,
3175 "never read card ready from secondary AC'97\n");
3161 } 3176 }
3162#endif 3177#endif
3163 3178
@@ -3187,17 +3202,21 @@ static int snd_cs46xx_chip_init(struct snd_cs46xx *chip)
3187 } 3202 }
3188 3203
3189#ifndef CONFIG_SND_CS46XX_NEW_DSP 3204#ifndef CONFIG_SND_CS46XX_NEW_DSP
3190 snd_printk(KERN_ERR "create - never read ISV3 & ISV4 from AC'97\n"); 3205 dev_err(chip->card->dev,
3206 "create - never read ISV3 & ISV4 from AC'97\n");
3191 return -EIO; 3207 return -EIO;
3192#else 3208#else
3193 /* This may happen on a cold boot with a Terratec SiXPack 5.1. 3209 /* This may happen on a cold boot with a Terratec SiXPack 5.1.
3194 Reloading the driver may help, if there's other soundcards 3210 Reloading the driver may help, if there's other soundcards
3195 with the same problem I would like to know. (Benny) */ 3211 with the same problem I would like to know. (Benny) */
3196 3212
3197 snd_printk(KERN_ERR "ERROR: snd-cs46xx: never read ISV3 & ISV4 from AC'97\n"); 3213 dev_err(chip->card->dev, "never read ISV3 & ISV4 from AC'97\n");
3198 snd_printk(KERN_ERR " Try reloading the ALSA driver, if you find something\n"); 3214 dev_err(chip->card->dev,
3199 snd_printk(KERN_ERR " broken or not working on your soundcard upon\n"); 3215 "Try reloading the ALSA driver, if you find something\n");
3200 snd_printk(KERN_ERR " this message please report to alsa-devel@alsa-project.org\n"); 3216 dev_err(chip->card->dev,
3217 "broken or not working on your soundcard upon\n");
3218 dev_err(chip->card->dev,
3219 "this message please report to alsa-devel@alsa-project.org\n");
3201 3220
3202 return -EIO; 3221 return -EIO;
3203#endif 3222#endif
@@ -3266,13 +3285,13 @@ int snd_cs46xx_start_dsp(struct snd_cs46xx *chip)
3266 for (i = 0; i < CS46XX_DSP_MODULES; i++) { 3285 for (i = 0; i < CS46XX_DSP_MODULES; i++) {
3267 err = load_firmware(chip, &chip->modules[i], module_names[i]); 3286 err = load_firmware(chip, &chip->modules[i], module_names[i]);
3268 if (err < 0) { 3287 if (err < 0) {
3269 snd_printk(KERN_ERR "firmware load error [%s]\n", 3288 dev_err(chip->card->dev, "firmware load error [%s]\n",
3270 module_names[i]); 3289 module_names[i]);
3271 return err; 3290 return err;
3272 } 3291 }
3273 err = cs46xx_dsp_load_module(chip, chip->modules[i]); 3292 err = cs46xx_dsp_load_module(chip, chip->modules[i]);
3274 if (err < 0) { 3293 if (err < 0) {
3275 snd_printk(KERN_ERR "image download error [%s]\n", 3294 dev_err(chip->card->dev, "image download error [%s]\n",
3276 module_names[i]); 3295 module_names[i]);
3277 return err; 3296 return err;
3278 } 3297 }
@@ -3288,7 +3307,7 @@ int snd_cs46xx_start_dsp(struct snd_cs46xx *chip)
3288 /* old image */ 3307 /* old image */
3289 err = snd_cs46xx_download_image(chip); 3308 err = snd_cs46xx_download_image(chip);
3290 if (err < 0) { 3309 if (err < 0) {
3291 snd_printk(KERN_ERR "image download error\n"); 3310 dev_err(chip->card->dev, "image download error\n");
3292 return err; 3311 return err;
3293 } 3312 }
3294 3313
@@ -3341,7 +3360,7 @@ static int voyetra_setup_eapd_slot(struct snd_cs46xx *chip)
3341 u32 idx, valid_slots,tmp,powerdown = 0; 3360 u32 idx, valid_slots,tmp,powerdown = 0;
3342 u16 modem_power,pin_config,logic_type; 3361 u16 modem_power,pin_config,logic_type;
3343 3362
3344 snd_printdd ("cs46xx: cs46xx_setup_eapd_slot()+\n"); 3363 dev_dbg(chip->card->dev, "cs46xx_setup_eapd_slot()+\n");
3345 3364
3346 /* 3365 /*
3347 * See if the devices are powered down. If so, we must power them up first 3366 * See if the devices are powered down. If so, we must power them up first
@@ -3359,7 +3378,8 @@ static int voyetra_setup_eapd_slot(struct snd_cs46xx *chip)
3359 * stuff. 3378 * stuff.
3360 */ 3379 */
3361 if(chip->nr_ac97_codecs != 2) { 3380 if(chip->nr_ac97_codecs != 2) {
3362 snd_printk (KERN_ERR "cs46xx: cs46xx_setup_eapd_slot() - no secondary codec configured\n"); 3381 dev_err(chip->card->dev,
3382 "cs46xx_setup_eapd_slot() - no secondary codec configured\n");
3363 return -EINVAL; 3383 return -EINVAL;
3364 } 3384 }
3365 3385
@@ -3400,7 +3420,7 @@ static int voyetra_setup_eapd_slot(struct snd_cs46xx *chip)
3400 snd_cs46xx_pokeBA0(chip, BA0_ACOSV, valid_slots); 3420 snd_cs46xx_pokeBA0(chip, BA0_ACOSV, valid_slots);
3401 3421
3402 if ( cs46xx_wait_for_fifo(chip,1) ) { 3422 if ( cs46xx_wait_for_fifo(chip,1) ) {
3403 snd_printdd("FIFO is busy\n"); 3423 dev_dbg(chip->card->dev, "FIFO is busy\n");
3404 3424
3405 return -EINVAL; 3425 return -EINVAL;
3406 } 3426 }
@@ -3421,7 +3441,9 @@ static int voyetra_setup_eapd_slot(struct snd_cs46xx *chip)
3421 * Wait for command to complete 3441 * Wait for command to complete
3422 */ 3442 */
3423 if ( cs46xx_wait_for_fifo(chip,200) ) { 3443 if ( cs46xx_wait_for_fifo(chip,200) ) {
3424 snd_printdd("failed waiting for FIFO at addr (%02X)\n",idx); 3444 dev_dbg(chip->card->dev,
3445 "failed waiting for FIFO at addr (%02X)\n",
3446 idx);
3425 3447
3426 return -EINVAL; 3448 return -EINVAL;
3427 } 3449 }
@@ -3510,14 +3532,14 @@ static void amp_hercules(struct snd_cs46xx *chip, int change)
3510 3532
3511 chip->amplifier += change; 3533 chip->amplifier += change;
3512 if (chip->amplifier && !old) { 3534 if (chip->amplifier && !old) {
3513 snd_printdd ("Hercules amplifier ON\n"); 3535 dev_dbg(chip->card->dev, "Hercules amplifier ON\n");
3514 3536
3515 snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, 3537 snd_cs46xx_pokeBA0(chip, BA0_EGPIODR,
3516 EGPIODR_GPOE2 | val1); /* enable EGPIO2 output */ 3538 EGPIODR_GPOE2 | val1); /* enable EGPIO2 output */
3517 snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, 3539 snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR,
3518 EGPIOPTR_GPPT2 | val2); /* open-drain on output */ 3540 EGPIOPTR_GPPT2 | val2); /* open-drain on output */
3519 } else if (old && !chip->amplifier) { 3541 } else if (old && !chip->amplifier) {
3520 snd_printdd ("Hercules amplifier OFF\n"); 3542 dev_dbg(chip->card->dev, "Hercules amplifier OFF\n");
3521 snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, val1 & ~EGPIODR_GPOE2); /* disable */ 3543 snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, val1 & ~EGPIODR_GPOE2); /* disable */
3522 snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, val2 & ~EGPIOPTR_GPPT2); /* disable */ 3544 snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, val2 & ~EGPIOPTR_GPPT2); /* disable */
3523 } 3545 }
@@ -3525,7 +3547,7 @@ static void amp_hercules(struct snd_cs46xx *chip, int change)
3525 3547
3526static void voyetra_mixer_init (struct snd_cs46xx *chip) 3548static void voyetra_mixer_init (struct snd_cs46xx *chip)
3527{ 3549{
3528 snd_printdd ("initializing Voyetra mixer\n"); 3550 dev_dbg(chip->card->dev, "initializing Voyetra mixer\n");
3529 3551
3530 /* Enable SPDIF out */ 3552 /* Enable SPDIF out */
3531 snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, EGPIODR_GPOE0); 3553 snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, EGPIODR_GPOE0);
@@ -3543,7 +3565,7 @@ static void hercules_mixer_init (struct snd_cs46xx *chip)
3543 /* set EGPIO to default */ 3565 /* set EGPIO to default */
3544 hercules_init(chip); 3566 hercules_init(chip);
3545 3567
3546 snd_printdd ("initializing Hercules mixer\n"); 3568 dev_dbg(chip->card->dev, "initializing Hercules mixer\n");
3547 3569
3548#ifdef CONFIG_SND_CS46XX_NEW_DSP 3570#ifdef CONFIG_SND_CS46XX_NEW_DSP
3549 if (chip->in_suspend) 3571 if (chip->in_suspend)
@@ -3554,7 +3576,9 @@ static void hercules_mixer_init (struct snd_cs46xx *chip)
3554 3576
3555 kctl = snd_ctl_new1(&snd_hercules_controls[idx], chip); 3577 kctl = snd_ctl_new1(&snd_hercules_controls[idx], chip);
3556 if ((err = snd_ctl_add(card, kctl)) < 0) { 3578 if ((err = snd_ctl_add(card, kctl)) < 0) {
3557 printk (KERN_ERR "cs46xx: failed to initialize Hercules mixer (%d)\n",err); 3579 dev_err(card->dev,
3580 "failed to initialize Hercules mixer (%d)\n",
3581 err);
3558 break; 3582 break;
3559 } 3583 }
3560 } 3584 }
@@ -3826,8 +3850,7 @@ static int snd_cs46xx_resume(struct device *dev)
3826 pci_set_power_state(pci, PCI_D0); 3850 pci_set_power_state(pci, PCI_D0);
3827 pci_restore_state(pci); 3851 pci_restore_state(pci);
3828 if (pci_enable_device(pci) < 0) { 3852 if (pci_enable_device(pci) < 0) {
3829 printk(KERN_ERR "cs46xx: pci_enable_device failed, " 3853 dev_err(dev, "pci_enable_device failed, disabling device\n");
3830 "disabling device\n");
3831 snd_card_disconnect(card); 3854 snd_card_disconnect(card);
3832 return -EIO; 3855 return -EIO;
3833 } 3856 }
@@ -3932,7 +3955,8 @@ int snd_cs46xx_create(struct snd_card *card,
3932 chip->ba1_addr = pci_resource_start(pci, 1); 3955 chip->ba1_addr = pci_resource_start(pci, 1);
3933 if (chip->ba0_addr == 0 || chip->ba0_addr == (unsigned long)~0 || 3956 if (chip->ba0_addr == 0 || chip->ba0_addr == (unsigned long)~0 ||
3934 chip->ba1_addr == 0 || chip->ba1_addr == (unsigned long)~0) { 3957 chip->ba1_addr == 0 || chip->ba1_addr == (unsigned long)~0) {
3935 snd_printk(KERN_ERR "wrong address(es) - ba0 = 0x%lx, ba1 = 0x%lx\n", 3958 dev_err(chip->card->dev,
3959 "wrong address(es) - ba0 = 0x%lx, ba1 = 0x%lx\n",
3936 chip->ba0_addr, chip->ba1_addr); 3960 chip->ba0_addr, chip->ba1_addr);
3937 snd_cs46xx_free(chip); 3961 snd_cs46xx_free(chip);
3938 return -ENOMEM; 3962 return -ENOMEM;
@@ -3969,7 +3993,8 @@ int snd_cs46xx_create(struct snd_card *card,
3969 3993
3970 for (cp = &cards[0]; cp->name; cp++) { 3994 for (cp = &cards[0]; cp->name; cp++) {
3971 if (cp->vendor == ss_vendor && cp->id == ss_card) { 3995 if (cp->vendor == ss_vendor && cp->id == ss_card) {
3972 snd_printdd ("hack for %s enabled\n", cp->name); 3996 dev_dbg(chip->card->dev, "hack for %s enabled\n",
3997 cp->name);
3973 3998
3974 chip->amplifier_ctrl = cp->amp; 3999 chip->amplifier_ctrl = cp->amp;
3975 chip->active_ctrl = cp->active; 4000 chip->active_ctrl = cp->active;
@@ -3982,12 +4007,14 @@ int snd_cs46xx_create(struct snd_card *card,
3982 } 4007 }
3983 4008
3984 if (external_amp) { 4009 if (external_amp) {
3985 snd_printk(KERN_INFO "Crystal EAPD support forced on.\n"); 4010 dev_info(chip->card->dev,
4011 "Crystal EAPD support forced on.\n");
3986 chip->amplifier_ctrl = amp_voyetra; 4012 chip->amplifier_ctrl = amp_voyetra;
3987 } 4013 }
3988 4014
3989 if (thinkpad) { 4015 if (thinkpad) {
3990 snd_printk(KERN_INFO "Activating CLKRUN hack for Thinkpad.\n"); 4016 dev_info(chip->card->dev,
4017 "Activating CLKRUN hack for Thinkpad.\n");
3991 chip->active_ctrl = clkrun_hack; 4018 chip->active_ctrl = clkrun_hack;
3992 clkrun_init(chip); 4019 clkrun_init(chip);
3993 } 4020 }
@@ -4005,14 +4032,16 @@ int snd_cs46xx_create(struct snd_card *card,
4005 region = &chip->region.idx[idx]; 4032 region = &chip->region.idx[idx];
4006 if ((region->resource = request_mem_region(region->base, region->size, 4033 if ((region->resource = request_mem_region(region->base, region->size,
4007 region->name)) == NULL) { 4034 region->name)) == NULL) {
4008 snd_printk(KERN_ERR "unable to request memory region 0x%lx-0x%lx\n", 4035 dev_err(chip->card->dev,
4036 "unable to request memory region 0x%lx-0x%lx\n",
4009 region->base, region->base + region->size - 1); 4037 region->base, region->base + region->size - 1);
4010 snd_cs46xx_free(chip); 4038 snd_cs46xx_free(chip);
4011 return -EBUSY; 4039 return -EBUSY;
4012 } 4040 }
4013 region->remap_addr = ioremap_nocache(region->base, region->size); 4041 region->remap_addr = ioremap_nocache(region->base, region->size);
4014 if (region->remap_addr == NULL) { 4042 if (region->remap_addr == NULL) {
4015 snd_printk(KERN_ERR "%s ioremap problem\n", region->name); 4043 dev_err(chip->card->dev,
4044 "%s ioremap problem\n", region->name);
4016 snd_cs46xx_free(chip); 4045 snd_cs46xx_free(chip);
4017 return -ENOMEM; 4046 return -ENOMEM;
4018 } 4047 }
@@ -4020,7 +4049,7 @@ int snd_cs46xx_create(struct snd_card *card,
4020 4049
4021 if (request_irq(pci->irq, snd_cs46xx_interrupt, IRQF_SHARED, 4050 if (request_irq(pci->irq, snd_cs46xx_interrupt, IRQF_SHARED,
4022 KBUILD_MODNAME, chip)) { 4051 KBUILD_MODNAME, chip)) {
4023 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 4052 dev_err(chip->card->dev, "unable to grab IRQ %d\n", pci->irq);
4024 snd_cs46xx_free(chip); 4053 snd_cs46xx_free(chip);
4025 return -EBUSY; 4054 return -EBUSY;
4026 } 4055 }
@@ -4058,8 +4087,6 @@ int snd_cs46xx_create(struct snd_card *card,
4058 4087
4059 chip->active_ctrl(chip, -1); /* disable CLKRUN */ 4088 chip->active_ctrl(chip, -1); /* disable CLKRUN */
4060 4089
4061 snd_card_set_dev(card, &pci->dev);
4062
4063 *rchip = chip; 4090 *rchip = chip;
4064 return 0; 4091 return 0;
4065} 4092}
diff --git a/sound/pci/cs46xx/dsp_spos.c b/sound/pci/cs46xx/dsp_spos.c
index 1686b4f4c44f..1c4a0fb3ffef 100644
--- a/sound/pci/cs46xx/dsp_spos.c
+++ b/sound/pci/cs46xx/dsp_spos.c
@@ -85,12 +85,15 @@ static int shadow_and_reallocate_code (struct snd_cs46xx * chip, u32 * data, u32
85 address = (hival & 0x00FFF) << 5; 85 address = (hival & 0x00FFF) << 5;
86 address |= loval >> 15; 86 address |= loval >> 15;
87 87
88 snd_printdd("handle_wideop[1]: %05x:%05x addr %04x\n",hival,loval,address); 88 dev_dbg(chip->card->dev,
89 "handle_wideop[1]: %05x:%05x addr %04x\n",
90 hival, loval, address);
89 91
90 if ( !(address & 0x8000) ) { 92 if ( !(address & 0x8000) ) {
91 address += (ins->code.offset / 2) - overlay_begin_address; 93 address += (ins->code.offset / 2) - overlay_begin_address;
92 } else { 94 } else {
93 snd_printdd("handle_wideop[1]: ROM symbol not reallocated\n"); 95 dev_dbg(chip->card->dev,
96 "handle_wideop[1]: ROM symbol not reallocated\n");
94 } 97 }
95 98
96 hival &= 0xFF000; 99 hival &= 0xFF000;
@@ -102,8 +105,9 @@ static int shadow_and_reallocate_code (struct snd_cs46xx * chip, u32 * data, u32
102 address = (hival & 0x00FFF) << 5; 105 address = (hival & 0x00FFF) << 5;
103 address |= loval >> 15; 106 address |= loval >> 15;
104 107
105 snd_printdd("handle_wideop:[2] %05x:%05x addr %04x\n",hival,loval,address); 108 dev_dbg(chip->card->dev,
106 nreallocated ++; 109 "handle_wideop:[2] %05x:%05x addr %04x\n",
110 hival, loval, address); nreallocated++;
107 } /* wide_opcodes[j] == wide_op */ 111 } /* wide_opcodes[j] == wide_op */
108 } /* for */ 112 } /* for */
109 } /* mod_type == 0 ... */ 113 } /* mod_type == 0 ... */
@@ -113,7 +117,8 @@ static int shadow_and_reallocate_code (struct snd_cs46xx * chip, u32 * data, u32
113 ins->code.data[ins->code.size++] = hival; 117 ins->code.data[ins->code.size++] = hival;
114 } 118 }
115 119
116 snd_printdd("dsp_spos: %d instructions reallocated\n",nreallocated); 120 dev_dbg(chip->card->dev,
121 "dsp_spos: %d instructions reallocated\n", nreallocated);
117 return nreallocated; 122 return nreallocated;
118} 123}
119 124
@@ -157,7 +162,8 @@ static int add_symbols (struct snd_cs46xx * chip, struct dsp_module_desc * modul
157 162
158 for (i = 0;i < module->symbol_table.nsymbols; ++i) { 163 for (i = 0;i < module->symbol_table.nsymbols; ++i) {
159 if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) { 164 if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) {
160 snd_printk(KERN_ERR "dsp_spos: symbol table is full\n"); 165 dev_err(chip->card->dev,
166 "dsp_spos: symbol table is full\n");
161 return -ENOMEM; 167 return -ENOMEM;
162 } 168 }
163 169
@@ -176,8 +182,11 @@ static int add_symbols (struct snd_cs46xx * chip, struct dsp_module_desc * modul
176 182
177 ins->symbol_table.nsymbols++; 183 ins->symbol_table.nsymbols++;
178 } else { 184 } else {
179 /* if (0) printk ("dsp_spos: symbol <%s> duplicated, probably nothing wrong with that (Cirrus?)\n", 185#if 0
180 module->symbol_table.symbols[i].symbol_name); */ 186 dev_dbg(chip->card->dev,
187 "dsp_spos: symbol <%s> duplicated, probably nothing wrong with that (Cirrus?)\n",
188 module->symbol_table.symbols[i].symbol_name); */
189#endif
181 } 190 }
182 } 191 }
183 192
@@ -192,14 +201,15 @@ add_symbol (struct snd_cs46xx * chip, char * symbol_name, u32 address, int type)
192 int index; 201 int index;
193 202
194 if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) { 203 if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) {
195 snd_printk(KERN_ERR "dsp_spos: symbol table is full\n"); 204 dev_err(chip->card->dev, "dsp_spos: symbol table is full\n");
196 return NULL; 205 return NULL;
197 } 206 }
198 207
199 if (cs46xx_dsp_lookup_symbol(chip, 208 if (cs46xx_dsp_lookup_symbol(chip,
200 symbol_name, 209 symbol_name,
201 type) != NULL) { 210 type) != NULL) {
202 snd_printk(KERN_ERR "dsp_spos: symbol <%s> duplicated\n", symbol_name); 211 dev_err(chip->card->dev,
212 "dsp_spos: symbol <%s> duplicated\n", symbol_name);
203 return NULL; 213 return NULL;
204 } 214 }
205 215
@@ -305,19 +315,20 @@ static int dsp_load_parameter(struct snd_cs46xx *chip,
305 u32 doffset, dsize; 315 u32 doffset, dsize;
306 316
307 if (!parameter) { 317 if (!parameter) {
308 snd_printdd("dsp_spos: module got no parameter segment\n"); 318 dev_dbg(chip->card->dev,
319 "dsp_spos: module got no parameter segment\n");
309 return 0; 320 return 0;
310 } 321 }
311 322
312 doffset = (parameter->offset * 4 + DSP_PARAMETER_BYTE_OFFSET); 323 doffset = (parameter->offset * 4 + DSP_PARAMETER_BYTE_OFFSET);
313 dsize = parameter->size * 4; 324 dsize = parameter->size * 4;
314 325
315 snd_printdd("dsp_spos: " 326 dev_dbg(chip->card->dev,
316 "downloading parameter data to chip (%08x-%08x)\n", 327 "dsp_spos: downloading parameter data to chip (%08x-%08x)\n",
317 doffset,doffset + dsize); 328 doffset,doffset + dsize);
318 if (snd_cs46xx_download (chip, parameter->data, doffset, dsize)) { 329 if (snd_cs46xx_download (chip, parameter->data, doffset, dsize)) {
319 snd_printk(KERN_ERR "dsp_spos: " 330 dev_err(chip->card->dev,
320 "failed to download parameter data to DSP\n"); 331 "dsp_spos: failed to download parameter data to DSP\n");
321 return -EINVAL; 332 return -EINVAL;
322 } 333 }
323 return 0; 334 return 0;
@@ -329,18 +340,21 @@ static int dsp_load_sample(struct snd_cs46xx *chip,
329 u32 doffset, dsize; 340 u32 doffset, dsize;
330 341
331 if (!sample) { 342 if (!sample) {
332 snd_printdd("dsp_spos: module got no sample segment\n"); 343 dev_dbg(chip->card->dev,
344 "dsp_spos: module got no sample segment\n");
333 return 0; 345 return 0;
334 } 346 }
335 347
336 doffset = (sample->offset * 4 + DSP_SAMPLE_BYTE_OFFSET); 348 doffset = (sample->offset * 4 + DSP_SAMPLE_BYTE_OFFSET);
337 dsize = sample->size * 4; 349 dsize = sample->size * 4;
338 350
339 snd_printdd("dsp_spos: downloading sample data to chip (%08x-%08x)\n", 351 dev_dbg(chip->card->dev,
352 "dsp_spos: downloading sample data to chip (%08x-%08x)\n",
340 doffset,doffset + dsize); 353 doffset,doffset + dsize);
341 354
342 if (snd_cs46xx_download (chip,sample->data,doffset,dsize)) { 355 if (snd_cs46xx_download (chip,sample->data,doffset,dsize)) {
343 snd_printk(KERN_ERR "dsp_spos: failed to sample data to DSP\n"); 356 dev_err(chip->card->dev,
357 "dsp_spos: failed to sample data to DSP\n");
344 return -EINVAL; 358 return -EINVAL;
345 } 359 }
346 return 0; 360 return 0;
@@ -354,14 +368,16 @@ int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * m
354 int err; 368 int err;
355 369
356 if (ins->nmodules == DSP_MAX_MODULES - 1) { 370 if (ins->nmodules == DSP_MAX_MODULES - 1) {
357 snd_printk(KERN_ERR "dsp_spos: to many modules loaded into DSP\n"); 371 dev_err(chip->card->dev,
372 "dsp_spos: to many modules loaded into DSP\n");
358 return -ENOMEM; 373 return -ENOMEM;
359 } 374 }
360 375
361 snd_printdd("dsp_spos: loading module %s into DSP\n", module->module_name); 376 dev_dbg(chip->card->dev,
377 "dsp_spos: loading module %s into DSP\n", module->module_name);
362 378
363 if (ins->nmodules == 0) { 379 if (ins->nmodules == 0) {
364 snd_printdd("dsp_spos: clearing parameter area\n"); 380 dev_dbg(chip->card->dev, "dsp_spos: clearing parameter area\n");
365 snd_cs46xx_clear_BA1(chip, DSP_PARAMETER_BYTE_OFFSET, DSP_PARAMETER_BYTE_SIZE); 381 snd_cs46xx_clear_BA1(chip, DSP_PARAMETER_BYTE_OFFSET, DSP_PARAMETER_BYTE_SIZE);
366 } 382 }
367 383
@@ -371,7 +387,7 @@ int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * m
371 return err; 387 return err;
372 388
373 if (ins->nmodules == 0) { 389 if (ins->nmodules == 0) {
374 snd_printdd("dsp_spos: clearing sample area\n"); 390 dev_dbg(chip->card->dev, "dsp_spos: clearing sample area\n");
375 snd_cs46xx_clear_BA1(chip, DSP_SAMPLE_BYTE_OFFSET, DSP_SAMPLE_BYTE_SIZE); 391 snd_cs46xx_clear_BA1(chip, DSP_SAMPLE_BYTE_OFFSET, DSP_SAMPLE_BYTE_SIZE);
376 } 392 }
377 393
@@ -381,15 +397,17 @@ int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * m
381 return err; 397 return err;
382 398
383 if (ins->nmodules == 0) { 399 if (ins->nmodules == 0) {
384 snd_printdd("dsp_spos: clearing code area\n"); 400 dev_dbg(chip->card->dev, "dsp_spos: clearing code area\n");
385 snd_cs46xx_clear_BA1(chip, DSP_CODE_BYTE_OFFSET, DSP_CODE_BYTE_SIZE); 401 snd_cs46xx_clear_BA1(chip, DSP_CODE_BYTE_OFFSET, DSP_CODE_BYTE_SIZE);
386 } 402 }
387 403
388 if (code == NULL) { 404 if (code == NULL) {
389 snd_printdd("dsp_spos: module got no code segment\n"); 405 dev_dbg(chip->card->dev,
406 "dsp_spos: module got no code segment\n");
390 } else { 407 } else {
391 if (ins->code.offset + code->size > DSP_CODE_BYTE_SIZE) { 408 if (ins->code.offset + code->size > DSP_CODE_BYTE_SIZE) {
392 snd_printk(KERN_ERR "dsp_spos: no space available in DSP\n"); 409 dev_err(chip->card->dev,
410 "dsp_spos: no space available in DSP\n");
393 return -ENOMEM; 411 return -ENOMEM;
394 } 412 }
395 413
@@ -401,19 +419,22 @@ int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * m
401 if (snd_BUG_ON(!module->symbol_table.symbols)) 419 if (snd_BUG_ON(!module->symbol_table.symbols))
402 return -ENOMEM; 420 return -ENOMEM;
403 if (add_symbols(chip,module)) { 421 if (add_symbols(chip,module)) {
404 snd_printk(KERN_ERR "dsp_spos: failed to load symbol table\n"); 422 dev_err(chip->card->dev,
423 "dsp_spos: failed to load symbol table\n");
405 return -ENOMEM; 424 return -ENOMEM;
406 } 425 }
407 426
408 doffset = (code->offset * 4 + ins->code.offset * 4 + DSP_CODE_BYTE_OFFSET); 427 doffset = (code->offset * 4 + ins->code.offset * 4 + DSP_CODE_BYTE_OFFSET);
409 dsize = code->size * 4; 428 dsize = code->size * 4;
410 snd_printdd("dsp_spos: downloading code to chip (%08x-%08x)\n", 429 dev_dbg(chip->card->dev,
430 "dsp_spos: downloading code to chip (%08x-%08x)\n",
411 doffset,doffset + dsize); 431 doffset,doffset + dsize);
412 432
413 module->nfixups = shadow_and_reallocate_code(chip,code->data,code->size,module->overlay_begin_address); 433 module->nfixups = shadow_and_reallocate_code(chip,code->data,code->size,module->overlay_begin_address);
414 434
415 if (snd_cs46xx_download (chip,(ins->code.data + ins->code.offset),doffset,dsize)) { 435 if (snd_cs46xx_download (chip,(ins->code.data + ins->code.offset),doffset,dsize)) {
416 snd_printk(KERN_ERR "dsp_spos: failed to download code to DSP\n"); 436 dev_err(chip->card->dev,
437 "dsp_spos: failed to download code to DSP\n");
417 return -EINVAL; 438 return -EINVAL;
418 } 439 }
419 440
@@ -447,7 +468,7 @@ cs46xx_dsp_lookup_symbol (struct snd_cs46xx * chip, char * symbol_name, int symb
447 } 468 }
448 469
449#if 0 470#if 0
450 printk ("dsp_spos: symbol <%s> type %02x not found\n", 471 dev_err(chip->card->dev, "dsp_spos: symbol <%s> type %02x not found\n",
451 symbol_name,symbol_type); 472 symbol_name,symbol_type);
452#endif 473#endif
453 474
@@ -910,7 +931,6 @@ int cs46xx_dsp_proc_done (struct snd_cs46xx *chip)
910} 931}
911#endif /* CONFIG_PROC_FS */ 932#endif /* CONFIG_PROC_FS */
912 933
913static int debug_tree;
914static void _dsp_create_task_tree (struct snd_cs46xx *chip, u32 * task_data, 934static void _dsp_create_task_tree (struct snd_cs46xx *chip, u32 * task_data,
915 u32 dest, int size) 935 u32 dest, int size)
916{ 936{
@@ -919,13 +939,13 @@ static void _dsp_create_task_tree (struct snd_cs46xx *chip, u32 * task_data,
919 int i; 939 int i;
920 940
921 for (i = 0; i < size; ++i) { 941 for (i = 0; i < size; ++i) {
922 if (debug_tree) printk ("addr %p, val %08x\n",spdst,task_data[i]); 942 dev_dbg(chip->card->dev, "addr %p, val %08x\n",
943 spdst, task_data[i]);
923 writel(task_data[i],spdst); 944 writel(task_data[i],spdst);
924 spdst += sizeof(u32); 945 spdst += sizeof(u32);
925 } 946 }
926} 947}
927 948
928static int debug_scb;
929static void _dsp_create_scb (struct snd_cs46xx *chip, u32 * scb_data, u32 dest) 949static void _dsp_create_scb (struct snd_cs46xx *chip, u32 * scb_data, u32 dest)
930{ 950{
931 void __iomem *spdst = chip->region.idx[1].remap_addr + 951 void __iomem *spdst = chip->region.idx[1].remap_addr +
@@ -933,7 +953,8 @@ static void _dsp_create_scb (struct snd_cs46xx *chip, u32 * scb_data, u32 dest)
933 int i; 953 int i;
934 954
935 for (i = 0; i < 0x10; ++i) { 955 for (i = 0; i < 0x10; ++i) {
936 if (debug_scb) printk ("addr %p, val %08x\n",spdst,scb_data[i]); 956 dev_dbg(chip->card->dev, "addr %p, val %08x\n",
957 spdst, scb_data[i]);
937 writel(scb_data[i],spdst); 958 writel(scb_data[i],spdst);
938 spdst += sizeof(u32); 959 spdst += sizeof(u32);
939 } 960 }
@@ -960,7 +981,8 @@ static struct dsp_scb_descriptor * _map_scb (struct snd_cs46xx *chip, char * nam
960 int index; 981 int index;
961 982
962 if (ins->nscb == DSP_MAX_SCB_DESC - 1) { 983 if (ins->nscb == DSP_MAX_SCB_DESC - 1) {
963 snd_printk(KERN_ERR "dsp_spos: got no place for other SCB\n"); 984 dev_err(chip->card->dev,
985 "dsp_spos: got no place for other SCB\n");
964 return NULL; 986 return NULL;
965 } 987 }
966 988
@@ -991,7 +1013,8 @@ _map_task_tree (struct snd_cs46xx *chip, char * name, u32 dest, u32 size)
991 struct dsp_task_descriptor * desc = NULL; 1013 struct dsp_task_descriptor * desc = NULL;
992 1014
993 if (ins->ntask == DSP_MAX_TASK_DESC - 1) { 1015 if (ins->ntask == DSP_MAX_TASK_DESC - 1) {
994 snd_printk(KERN_ERR "dsp_spos: got no place for other TASK\n"); 1016 dev_err(chip->card->dev,
1017 "dsp_spos: got no place for other TASK\n");
995 return NULL; 1018 return NULL;
996 } 1019 }
997 1020
@@ -1031,7 +1054,7 @@ cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32
1031 desc->data = scb_data; 1054 desc->data = scb_data;
1032 _dsp_create_scb(chip,scb_data,dest); 1055 _dsp_create_scb(chip,scb_data,dest);
1033 } else { 1056 } else {
1034 snd_printk(KERN_ERR "dsp_spos: failed to map SCB\n"); 1057 dev_err(chip->card->dev, "dsp_spos: failed to map SCB\n");
1035#ifdef CONFIG_PM_SLEEP 1058#ifdef CONFIG_PM_SLEEP
1036 kfree(scb_data); 1059 kfree(scb_data);
1037#endif 1060#endif
@@ -1052,7 +1075,7 @@ cs46xx_dsp_create_task_tree (struct snd_cs46xx *chip, char * name, u32 * task_da
1052 desc->data = task_data; 1075 desc->data = task_data;
1053 _dsp_create_task_tree(chip,task_data,dest,size); 1076 _dsp_create_task_tree(chip,task_data,dest,size);
1054 } else { 1077 } else {
1055 snd_printk(KERN_ERR "dsp_spos: failed to map TASK\n"); 1078 dev_err(chip->card->dev, "dsp_spos: failed to map TASK\n");
1056 } 1079 }
1057 1080
1058 return desc; 1081 return desc;
@@ -1105,31 +1128,36 @@ int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip)
1105 1128
1106 null_algorithm = cs46xx_dsp_lookup_symbol(chip, "NULLALGORITHM", SYMBOL_CODE); 1129 null_algorithm = cs46xx_dsp_lookup_symbol(chip, "NULLALGORITHM", SYMBOL_CODE);
1107 if (null_algorithm == NULL) { 1130 if (null_algorithm == NULL) {
1108 snd_printk(KERN_ERR "dsp_spos: symbol NULLALGORITHM not found\n"); 1131 dev_err(chip->card->dev,
1132 "dsp_spos: symbol NULLALGORITHM not found\n");
1109 return -EIO; 1133 return -EIO;
1110 } 1134 }
1111 1135
1112 fg_task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "FGTASKTREEHEADERCODE", SYMBOL_CODE); 1136 fg_task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "FGTASKTREEHEADERCODE", SYMBOL_CODE);
1113 if (fg_task_tree_header_code == NULL) { 1137 if (fg_task_tree_header_code == NULL) {
1114 snd_printk(KERN_ERR "dsp_spos: symbol FGTASKTREEHEADERCODE not found\n"); 1138 dev_err(chip->card->dev,
1139 "dsp_spos: symbol FGTASKTREEHEADERCODE not found\n");
1115 return -EIO; 1140 return -EIO;
1116 } 1141 }
1117 1142
1118 task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "TASKTREEHEADERCODE", SYMBOL_CODE); 1143 task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "TASKTREEHEADERCODE", SYMBOL_CODE);
1119 if (task_tree_header_code == NULL) { 1144 if (task_tree_header_code == NULL) {
1120 snd_printk(KERN_ERR "dsp_spos: symbol TASKTREEHEADERCODE not found\n"); 1145 dev_err(chip->card->dev,
1146 "dsp_spos: symbol TASKTREEHEADERCODE not found\n");
1121 return -EIO; 1147 return -EIO;
1122 } 1148 }
1123 1149
1124 task_tree_thread = cs46xx_dsp_lookup_symbol(chip, "TASKTREETHREAD", SYMBOL_CODE); 1150 task_tree_thread = cs46xx_dsp_lookup_symbol(chip, "TASKTREETHREAD", SYMBOL_CODE);
1125 if (task_tree_thread == NULL) { 1151 if (task_tree_thread == NULL) {
1126 snd_printk(KERN_ERR "dsp_spos: symbol TASKTREETHREAD not found\n"); 1152 dev_err(chip->card->dev,
1153 "dsp_spos: symbol TASKTREETHREAD not found\n");
1127 return -EIO; 1154 return -EIO;
1128 } 1155 }
1129 1156
1130 magic_snoop_task = cs46xx_dsp_lookup_symbol(chip, "MAGICSNOOPTASK", SYMBOL_CODE); 1157 magic_snoop_task = cs46xx_dsp_lookup_symbol(chip, "MAGICSNOOPTASK", SYMBOL_CODE);
1131 if (magic_snoop_task == NULL) { 1158 if (magic_snoop_task == NULL) {
1132 snd_printk(KERN_ERR "dsp_spos: symbol MAGICSNOOPTASK not found\n"); 1159 dev_err(chip->card->dev,
1160 "dsp_spos: symbol MAGICSNOOPTASK not found\n");
1133 return -EIO; 1161 return -EIO;
1134 } 1162 }
1135 1163
@@ -1476,7 +1504,7 @@ int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip)
1476 return 0; 1504 return 0;
1477 1505
1478 _fail_end: 1506 _fail_end:
1479 snd_printk(KERN_ERR "dsp_spos: failed to setup SCB's in DSP\n"); 1507 dev_err(chip->card->dev, "dsp_spos: failed to setup SCB's in DSP\n");
1480 return -EINVAL; 1508 return -EINVAL;
1481} 1509}
1482 1510
@@ -1491,18 +1519,21 @@ static int cs46xx_dsp_async_init (struct snd_cs46xx *chip,
1491 1519
1492 s16_async_codec_input_task = cs46xx_dsp_lookup_symbol(chip, "S16_ASYNCCODECINPUTTASK", SYMBOL_CODE); 1520 s16_async_codec_input_task = cs46xx_dsp_lookup_symbol(chip, "S16_ASYNCCODECINPUTTASK", SYMBOL_CODE);
1493 if (s16_async_codec_input_task == NULL) { 1521 if (s16_async_codec_input_task == NULL) {
1494 snd_printk(KERN_ERR "dsp_spos: symbol S16_ASYNCCODECINPUTTASK not found\n"); 1522 dev_err(chip->card->dev,
1523 "dsp_spos: symbol S16_ASYNCCODECINPUTTASK not found\n");
1495 return -EIO; 1524 return -EIO;
1496 } 1525 }
1497 spdifo_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFOTASK", SYMBOL_CODE); 1526 spdifo_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFOTASK", SYMBOL_CODE);
1498 if (spdifo_task == NULL) { 1527 if (spdifo_task == NULL) {
1499 snd_printk(KERN_ERR "dsp_spos: symbol SPDIFOTASK not found\n"); 1528 dev_err(chip->card->dev,
1529 "dsp_spos: symbol SPDIFOTASK not found\n");
1500 return -EIO; 1530 return -EIO;
1501 } 1531 }
1502 1532
1503 spdifi_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFITASK", SYMBOL_CODE); 1533 spdifi_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFITASK", SYMBOL_CODE);
1504 if (spdifi_task == NULL) { 1534 if (spdifi_task == NULL) {
1505 snd_printk(KERN_ERR "dsp_spos: symbol SPDIFITASK not found\n"); 1535 dev_err(chip->card->dev,
1536 "dsp_spos: symbol SPDIFITASK not found\n");
1506 return -EIO; 1537 return -EIO;
1507 } 1538 }
1508 1539
@@ -1883,7 +1914,8 @@ int cs46xx_poke_via_dsp (struct snd_cs46xx *chip, u32 address, u32 data)
1883 } 1914 }
1884 1915
1885 if (i == 25) { 1916 if (i == 25) {
1886 snd_printk(KERN_ERR "dsp_spos: SPIOWriteTask not responding\n"); 1917 dev_err(chip->card->dev,
1918 "dsp_spos: SPIOWriteTask not responding\n");
1887 return -EBUSY; 1919 return -EBUSY;
1888 } 1920 }
1889 1921
diff --git a/sound/pci/cs46xx/dsp_spos_scb_lib.c b/sound/pci/cs46xx/dsp_spos_scb_lib.c
index 409e8764fbeb..8284bc9b5858 100644
--- a/sound/pci/cs46xx/dsp_spos_scb_lib.c
+++ b/sound/pci/cs46xx/dsp_spos_scb_lib.c
@@ -233,8 +233,11 @@ void cs46xx_dsp_proc_free_scb_desc (struct dsp_scb_descriptor * scb)
233{ 233{
234 if (scb->proc_info) { 234 if (scb->proc_info) {
235 struct proc_scb_info * scb_info = scb->proc_info->private_data; 235 struct proc_scb_info * scb_info = scb->proc_info->private_data;
236 struct snd_cs46xx *chip = scb_info->chip;
236 237
237 snd_printdd("cs46xx_dsp_proc_free_scb_desc: freeing %s\n",scb->scb_name); 238 dev_dbg(chip->card->dev,
239 "cs46xx_dsp_proc_free_scb_desc: freeing %s\n",
240 scb->scb_name);
238 241
239 snd_info_free_entry(scb->proc_info); 242 snd_info_free_entry(scb->proc_info);
240 scb->proc_info = NULL; 243 scb->proc_info = NULL;
@@ -305,7 +308,7 @@ _dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u
305 scb_data[SCBfuncEntryPtr] &= 0xFFFF0000; 308 scb_data[SCBfuncEntryPtr] &= 0xFFFF0000;
306 scb_data[SCBfuncEntryPtr] |= task_entry->address; 309 scb_data[SCBfuncEntryPtr] |= task_entry->address;
307 310
308 snd_printdd("dsp_spos: creating SCB <%s>\n",name); 311 dev_dbg(chip->card->dev, "dsp_spos: creating SCB <%s>\n", name);
309 312
310 scb = cs46xx_dsp_create_scb(chip,name,scb_data,dest); 313 scb = cs46xx_dsp_create_scb(chip,name,scb_data,dest);
311 314
@@ -320,9 +323,15 @@ _dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u
320 /* update parent SCB */ 323 /* update parent SCB */
321 if (scb->parent_scb_ptr) { 324 if (scb->parent_scb_ptr) {
322#if 0 325#if 0
323 printk ("scb->parent_scb_ptr = %s\n",scb->parent_scb_ptr->scb_name); 326 dev_dbg(chip->card->dev,
324 printk ("scb->parent_scb_ptr->next_scb_ptr = %s\n",scb->parent_scb_ptr->next_scb_ptr->scb_name); 327 "scb->parent_scb_ptr = %s\n",
325 printk ("scb->parent_scb_ptr->sub_list_ptr = %s\n",scb->parent_scb_ptr->sub_list_ptr->scb_name); 328 scb->parent_scb_ptr->scb_name);
329 dev_dbg(chip->card->dev,
330 "scb->parent_scb_ptr->next_scb_ptr = %s\n",
331 scb->parent_scb_ptr->next_scb_ptr->scb_name);
332 dev_dbg(chip->card->dev,
333 "scb->parent_scb_ptr->sub_list_ptr = %s\n",
334 scb->parent_scb_ptr->sub_list_ptr->scb_name);
326#endif 335#endif
327 /* link to parent SCB */ 336 /* link to parent SCB */
328 if (scb_child_type == SCB_ON_PARENT_NEXT_SCB) { 337 if (scb_child_type == SCB_ON_PARENT_NEXT_SCB) {
@@ -368,7 +377,8 @@ cs46xx_dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_d
368 SYMBOL_CODE); 377 SYMBOL_CODE);
369 378
370 if (task_entry == NULL) { 379 if (task_entry == NULL) {
371 snd_printk (KERN_ERR "dsp_spos: symbol %s not found\n",task_entry_name); 380 dev_err(chip->card->dev,
381 "dsp_spos: symbol %s not found\n", task_entry_name);
372 return NULL; 382 return NULL;
373 } 383 }
374 384
@@ -582,7 +592,8 @@ cs46xx_dsp_create_pcm_reader_scb(struct snd_cs46xx * chip, char * scb_name,
582 SYMBOL_CODE); 592 SYMBOL_CODE);
583 593
584 if (ins->null_algorithm == NULL) { 594 if (ins->null_algorithm == NULL) {
585 snd_printk (KERN_ERR "dsp_spos: symbol NULLALGORITHM not found\n"); 595 dev_err(chip->card->dev,
596 "dsp_spos: symbol NULLALGORITHM not found\n");
586 return NULL; 597 return NULL;
587 } 598 }
588 } 599 }
@@ -612,7 +623,8 @@ cs46xx_dsp_create_src_task_scb(struct snd_cs46xx * chip, char * scb_name,
612 unsigned int phiIncr; 623 unsigned int phiIncr;
613 unsigned int correctionPerGOF, correctionPerSec; 624 unsigned int correctionPerGOF, correctionPerSec;
614 625
615 snd_printdd( "dsp_spos: setting %s rate to %u\n",scb_name,rate); 626 dev_dbg(chip->card->dev, "dsp_spos: setting %s rate to %u\n",
627 scb_name, rate);
616 628
617 /* 629 /*
618 * Compute the values used to drive the actual sample rate conversion. 630 * Compute the values used to drive the actual sample rate conversion.
@@ -670,7 +682,8 @@ cs46xx_dsp_create_src_task_scb(struct snd_cs46xx * chip, char * scb_name,
670 SYMBOL_CODE); 682 SYMBOL_CODE);
671 683
672 if (ins->s16_up == NULL) { 684 if (ins->s16_up == NULL) {
673 snd_printk (KERN_ERR "dsp_spos: symbol S16_UPSRC not found\n"); 685 dev_err(chip->card->dev,
686 "dsp_spos: symbol S16_UPSRC not found\n");
674 return NULL; 687 return NULL;
675 } 688 }
676 } 689 }
@@ -1265,7 +1278,7 @@ cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
1265 the Sample Rate Converted (which could 1278 the Sample Rate Converted (which could
1266 alter the raw data stream ...) */ 1279 alter the raw data stream ...) */
1267 if (sample_rate == 48000) { 1280 if (sample_rate == 48000) {
1268 snd_printdd ("IEC958 pass through\n"); 1281 dev_dbg(chip->card->dev, "IEC958 pass through\n");
1269 /* Hack to bypass creating a new SRC */ 1282 /* Hack to bypass creating a new SRC */
1270 pass_through = 1; 1283 pass_through = 1;
1271 } 1284 }
@@ -1299,13 +1312,14 @@ cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
1299 } 1312 }
1300 1313
1301 if (pcm_index == -1) { 1314 if (pcm_index == -1) {
1302 snd_printk (KERN_ERR "dsp_spos: no free PCM channel\n"); 1315 dev_err(chip->card->dev, "dsp_spos: no free PCM channel\n");
1303 return NULL; 1316 return NULL;
1304 } 1317 }
1305 1318
1306 if (src_scb == NULL) { 1319 if (src_scb == NULL) {
1307 if (ins->nsrc_scb >= DSP_MAX_SRC_NR) { 1320 if (ins->nsrc_scb >= DSP_MAX_SRC_NR) {
1308 snd_printk(KERN_ERR "dsp_spos: to many SRC instances\n!"); 1321 dev_err(chip->card->dev,
1322 "dsp_spos: to many SRC instances\n!");
1309 return NULL; 1323 return NULL;
1310 } 1324 }
1311 1325
@@ -1331,7 +1345,8 @@ cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
1331 1345
1332 snprintf (scb_name,DSP_MAX_SCB_NAME,"SrcTask_SCB%d",src_index); 1346 snprintf (scb_name,DSP_MAX_SCB_NAME,"SrcTask_SCB%d",src_index);
1333 1347
1334 snd_printdd( "dsp_spos: creating SRC \"%s\"\n",scb_name); 1348 dev_dbg(chip->card->dev,
1349 "dsp_spos: creating SRC \"%s\"\n", scb_name);
1335 src_scb = cs46xx_dsp_create_src_task_scb(chip,scb_name, 1350 src_scb = cs46xx_dsp_create_src_task_scb(chip,scb_name,
1336 sample_rate, 1351 sample_rate,
1337 src_output_buffer_addr[src_index], 1352 src_output_buffer_addr[src_index],
@@ -1343,7 +1358,8 @@ cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
1343 pass_through); 1358 pass_through);
1344 1359
1345 if (!src_scb) { 1360 if (!src_scb) {
1346 snd_printk (KERN_ERR "dsp_spos: failed to create SRCtaskSCB\n"); 1361 dev_err(chip->card->dev,
1362 "dsp_spos: failed to create SRCtaskSCB\n");
1347 return NULL; 1363 return NULL;
1348 } 1364 }
1349 1365
@@ -1355,8 +1371,8 @@ cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
1355 1371
1356 snprintf (scb_name,DSP_MAX_SCB_NAME,"PCMReader_SCB%d",pcm_index); 1372 snprintf (scb_name,DSP_MAX_SCB_NAME,"PCMReader_SCB%d",pcm_index);
1357 1373
1358 snd_printdd( "dsp_spos: creating PCM \"%s\" (%d)\n",scb_name, 1374 dev_dbg(chip->card->dev, "dsp_spos: creating PCM \"%s\" (%d)\n",
1359 pcm_channel_id); 1375 scb_name, pcm_channel_id);
1360 1376
1361 pcm_scb = cs46xx_dsp_create_pcm_reader_scb(chip,scb_name, 1377 pcm_scb = cs46xx_dsp_create_pcm_reader_scb(chip,scb_name,
1362 pcm_reader_buffer_addr[pcm_index], 1378 pcm_reader_buffer_addr[pcm_index],
@@ -1369,7 +1385,8 @@ cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
1369 ); 1385 );
1370 1386
1371 if (!pcm_scb) { 1387 if (!pcm_scb) {
1372 snd_printk (KERN_ERR "dsp_spos: failed to create PCMreaderSCB\n"); 1388 dev_err(chip->card->dev,
1389 "dsp_spos: failed to create PCMreaderSCB\n");
1373 return NULL; 1390 return NULL;
1374 } 1391 }
1375 1392
@@ -1419,7 +1436,8 @@ int cs46xx_dsp_pcm_channel_set_period (struct snd_cs46xx * chip,
1419 temp |= DMA_RQ_C1_SOURCE_MOD16; 1436 temp |= DMA_RQ_C1_SOURCE_MOD16;
1420 break; 1437 break;
1421 default: 1438 default:
1422 snd_printdd ("period size (%d) not supported by HW\n", period_size); 1439 dev_dbg(chip->card->dev,
1440 "period size (%d) not supported by HW\n", period_size);
1423 return -EINVAL; 1441 return -EINVAL;
1424 } 1442 }
1425 1443
@@ -1457,7 +1475,8 @@ int cs46xx_dsp_pcm_ostream_set_period (struct snd_cs46xx * chip,
1457 temp |= DMA_RQ_C1_DEST_MOD16; 1475 temp |= DMA_RQ_C1_DEST_MOD16;
1458 break; 1476 break;
1459 default: 1477 default:
1460 snd_printdd ("period size (%d) not supported by HW\n", period_size); 1478 dev_dbg(chip->card->dev,
1479 "period size (%d) not supported by HW\n", period_size);
1461 return -EINVAL; 1480 return -EINVAL;
1462 } 1481 }
1463 1482
diff --git a/sound/pci/cs5530.c b/sound/pci/cs5530.c
index c6b82c85e044..b4e0ff6a99a3 100644
--- a/sound/pci/cs5530.c
+++ b/sound/pci/cs5530.c
@@ -160,17 +160,17 @@ static int snd_cs5530_create(struct snd_card *card,
160 sb_base = 0x220 + 0x20 * (map & 3); 160 sb_base = 0x220 + 0x20 * (map & 3);
161 161
162 if (map & (1<<2)) 162 if (map & (1<<2))
163 printk(KERN_INFO "CS5530: XpressAudio at 0x%lx\n", sb_base); 163 dev_info(card->dev, "XpressAudio at 0x%lx\n", sb_base);
164 else { 164 else {
165 printk(KERN_ERR "Could not find XpressAudio!\n"); 165 dev_err(card->dev, "Could not find XpressAudio!\n");
166 snd_cs5530_free(chip); 166 snd_cs5530_free(chip);
167 return -ENODEV; 167 return -ENODEV;
168 } 168 }
169 169
170 if (map & (1<<5)) 170 if (map & (1<<5))
171 printk(KERN_INFO "CS5530: MPU at 0x300\n"); 171 dev_info(card->dev, "MPU at 0x300\n");
172 else if (map & (1<<6)) 172 else if (map & (1<<6))
173 printk(KERN_INFO "CS5530: MPU at 0x330\n"); 173 dev_info(card->dev, "MPU at 0x330\n");
174 174
175 irq = snd_cs5530_mixer_read(sb_base, 0x80) & 0x0F; 175 irq = snd_cs5530_mixer_read(sb_base, 0x80) & 0x0F;
176 dma8 = snd_cs5530_mixer_read(sb_base, 0x81); 176 dma8 = snd_cs5530_mixer_read(sb_base, 0x81);
@@ -182,7 +182,7 @@ static int snd_cs5530_create(struct snd_card *card,
182 else if (dma8 & 0x80) 182 else if (dma8 & 0x80)
183 dma16 = 7; 183 dma16 = 7;
184 else { 184 else {
185 printk(KERN_ERR "CS5530: No 16bit DMA enabled\n"); 185 dev_err(card->dev, "No 16bit DMA enabled\n");
186 snd_cs5530_free(chip); 186 snd_cs5530_free(chip);
187 return -ENODEV; 187 return -ENODEV;
188 } 188 }
@@ -194,7 +194,7 @@ static int snd_cs5530_create(struct snd_card *card,
194 else if (dma8 & 0x08) 194 else if (dma8 & 0x08)
195 dma8 = 3; 195 dma8 = 3;
196 else { 196 else {
197 printk(KERN_ERR "CS5530: No 8bit DMA enabled\n"); 197 dev_err(card->dev, "No 8bit DMA enabled\n");
198 snd_cs5530_free(chip); 198 snd_cs5530_free(chip);
199 return -ENODEV; 199 return -ENODEV;
200 } 200 }
@@ -208,32 +208,31 @@ static int snd_cs5530_create(struct snd_card *card,
208 else if (irq & 8) 208 else if (irq & 8)
209 irq = 10; 209 irq = 10;
210 else { 210 else {
211 printk(KERN_ERR "CS5530: SoundBlaster IRQ not set\n"); 211 dev_err(card->dev, "SoundBlaster IRQ not set\n");
212 snd_cs5530_free(chip); 212 snd_cs5530_free(chip);
213 return -ENODEV; 213 return -ENODEV;
214 } 214 }
215 215
216 printk(KERN_INFO "CS5530: IRQ: %d DMA8: %d DMA16: %d\n", irq, dma8, 216 dev_info(card->dev, "IRQ: %d DMA8: %d DMA16: %d\n", irq, dma8, dma16);
217 dma16);
218 217
219 err = snd_sbdsp_create(card, sb_base, irq, snd_sb16dsp_interrupt, dma8, 218 err = snd_sbdsp_create(card, sb_base, irq, snd_sb16dsp_interrupt, dma8,
220 dma16, SB_HW_CS5530, &chip->sb); 219 dma16, SB_HW_CS5530, &chip->sb);
221 if (err < 0) { 220 if (err < 0) {
222 printk(KERN_ERR "CS5530: Could not create SoundBlaster\n"); 221 dev_err(card->dev, "Could not create SoundBlaster\n");
223 snd_cs5530_free(chip); 222 snd_cs5530_free(chip);
224 return err; 223 return err;
225 } 224 }
226 225
227 err = snd_sb16dsp_pcm(chip->sb, 0, &chip->sb->pcm); 226 err = snd_sb16dsp_pcm(chip->sb, 0, &chip->sb->pcm);
228 if (err < 0) { 227 if (err < 0) {
229 printk(KERN_ERR "CS5530: Could not create PCM\n"); 228 dev_err(card->dev, "Could not create PCM\n");
230 snd_cs5530_free(chip); 229 snd_cs5530_free(chip);
231 return err; 230 return err;
232 } 231 }
233 232
234 err = snd_sbmixer_new(chip->sb); 233 err = snd_sbmixer_new(chip->sb);
235 if (err < 0) { 234 if (err < 0) {
236 printk(KERN_ERR "CS5530: Could not create Mixer\n"); 235 dev_err(card->dev, "Could not create Mixer\n");
237 snd_cs5530_free(chip); 236 snd_cs5530_free(chip);
238 return err; 237 return err;
239 } 238 }
@@ -244,7 +243,6 @@ static int snd_cs5530_create(struct snd_card *card,
244 return err; 243 return err;
245 } 244 }
246 245
247 snd_card_set_dev(card, &pci->dev);
248 *rchip = chip; 246 *rchip = chip;
249 return 0; 247 return 0;
250} 248}
@@ -264,7 +262,8 @@ static int snd_cs5530_probe(struct pci_dev *pci,
264 return -ENOENT; 262 return -ENOENT;
265 } 263 }
266 264
267 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 265 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
266 0, &card);
268 267
269 if (err < 0) 268 if (err < 0)
270 return err; 269 return err;
diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c
index c0d2835344da..edcbbda5c488 100644
--- a/sound/pci/cs5535audio/cs5535audio.c
+++ b/sound/pci/cs5535audio/cs5535audio.c
@@ -84,7 +84,8 @@ static void wait_till_cmd_acked(struct cs5535audio *cs5535au, unsigned long time
84 udelay(1); 84 udelay(1);
85 } while (--timeout); 85 } while (--timeout);
86 if (!timeout) 86 if (!timeout)
87 snd_printk(KERN_ERR "Failure writing to cs5535 codec\n"); 87 dev_err(cs5535au->card->dev,
88 "Failure writing to cs5535 codec\n");
88} 89}
89 90
90static unsigned short snd_cs5535audio_codec_read(struct cs5535audio *cs5535au, 91static unsigned short snd_cs5535audio_codec_read(struct cs5535audio *cs5535au,
@@ -109,8 +110,9 @@ static unsigned short snd_cs5535audio_codec_read(struct cs5535audio *cs5535au,
109 udelay(1); 110 udelay(1);
110 } while (--timeout); 111 } while (--timeout);
111 if (!timeout) 112 if (!timeout)
112 snd_printk(KERN_ERR "Failure reading codec reg 0x%x," 113 dev_err(cs5535au->card->dev,
113 "Last value=0x%x\n", reg, val); 114 "Failure reading codec reg 0x%x, Last value=0x%x\n",
115 reg, val);
114 116
115 return (unsigned short) val; 117 return (unsigned short) val;
116} 118}
@@ -168,7 +170,7 @@ static int snd_cs5535audio_mixer(struct cs5535audio *cs5535au)
168 olpc_prequirks(card, &ac97); 170 olpc_prequirks(card, &ac97);
169 171
170 if ((err = snd_ac97_mixer(pbus, &ac97, &cs5535au->ac97)) < 0) { 172 if ((err = snd_ac97_mixer(pbus, &ac97, &cs5535au->ac97)) < 0) {
171 snd_printk(KERN_ERR "mixer failed\n"); 173 dev_err(card->dev, "mixer failed\n");
172 return err; 174 return err;
173 } 175 }
174 176
@@ -176,7 +178,7 @@ static int snd_cs5535audio_mixer(struct cs5535audio *cs5535au)
176 178
177 err = olpc_quirks(card, cs5535au->ac97); 179 err = olpc_quirks(card, cs5535au->ac97);
178 if (err < 0) { 180 if (err < 0) {
179 snd_printk(KERN_ERR "olpc quirks failed\n"); 181 dev_err(card->dev, "olpc quirks failed\n");
180 return err; 182 return err;
181 } 183 }
182 184
@@ -194,8 +196,9 @@ static void process_bm0_irq(struct cs5535audio *cs5535au)
194 dma = cs5535au->playback_substream->runtime->private_data; 196 dma = cs5535au->playback_substream->runtime->private_data;
195 snd_pcm_period_elapsed(cs5535au->playback_substream); 197 snd_pcm_period_elapsed(cs5535au->playback_substream);
196 } else { 198 } else {
197 snd_printk(KERN_ERR "unexpected bm0 irq src, bm_stat=%x\n", 199 dev_err(cs5535au->card->dev,
198 bm_stat); 200 "unexpected bm0 irq src, bm_stat=%x\n",
201 bm_stat);
199 } 202 }
200} 203}
201 204
@@ -241,8 +244,9 @@ static irqreturn_t snd_cs5535audio_interrupt(int irq, void *dev_id)
241 process_bm1_irq(cs5535au); 244 process_bm1_irq(cs5535au);
242 break; 245 break;
243 default: 246 default:
244 snd_printk(KERN_ERR "Unexpected irq src: " 247 dev_err(cs5535au->card->dev,
245 "0x%x\n", acc_irq_stat); 248 "Unexpected irq src: 0x%x\n",
249 acc_irq_stat);
246 break; 250 break;
247 } 251 }
248 } 252 }
@@ -287,7 +291,7 @@ static int snd_cs5535audio_create(struct snd_card *card,
287 291
288 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 || 292 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 ||
289 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { 293 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) {
290 printk(KERN_WARNING "unable to get 32bit dma\n"); 294 dev_warn(card->dev, "unable to get 32bit dma\n");
291 err = -ENXIO; 295 err = -ENXIO;
292 goto pcifail; 296 goto pcifail;
293 } 297 }
@@ -312,7 +316,7 @@ static int snd_cs5535audio_create(struct snd_card *card,
312 316
313 if (request_irq(pci->irq, snd_cs5535audio_interrupt, 317 if (request_irq(pci->irq, snd_cs5535audio_interrupt,
314 IRQF_SHARED, KBUILD_MODNAME, cs5535au)) { 318 IRQF_SHARED, KBUILD_MODNAME, cs5535au)) {
315 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 319 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
316 err = -EBUSY; 320 err = -EBUSY;
317 goto sndfail; 321 goto sndfail;
318 } 322 }
@@ -324,8 +328,6 @@ static int snd_cs5535audio_create(struct snd_card *card,
324 cs5535au, &ops)) < 0) 328 cs5535au, &ops)) < 0)
325 goto sndfail; 329 goto sndfail;
326 330
327 snd_card_set_dev(card, &pci->dev);
328
329 *rcs5535au = cs5535au; 331 *rcs5535au = cs5535au;
330 return 0; 332 return 0;
331 333
@@ -353,7 +355,8 @@ static int snd_cs5535audio_probe(struct pci_dev *pci,
353 return -ENOENT; 355 return -ENOENT;
354 } 356 }
355 357
356 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 358 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
359 0, &card);
357 if (err < 0) 360 if (err < 0)
358 return err; 361 return err;
359 362
diff --git a/sound/pci/cs5535audio/cs5535audio_olpc.c b/sound/pci/cs5535audio/cs5535audio_olpc.c
index e6a44507d557..3b0fdaca8dc7 100644
--- a/sound/pci/cs5535audio/cs5535audio_olpc.c
+++ b/sound/pci/cs5535audio/cs5535audio_olpc.c
@@ -36,7 +36,8 @@ void olpc_analog_input(struct snd_ac97 *ac97, int on)
36 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2, 36 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
37 1 << AC97_AD_HPFD_SHIFT, on << AC97_AD_HPFD_SHIFT); 37 1 << AC97_AD_HPFD_SHIFT, on << AC97_AD_HPFD_SHIFT);
38 if (err < 0) { 38 if (err < 0) {
39 snd_printk(KERN_ERR "setting High Pass Filter - %d\n", err); 39 dev_err(ac97->bus->card->dev,
40 "setting High Pass Filter - %d\n", err);
40 return; 41 return;
41 } 42 }
42 43
@@ -58,7 +59,7 @@ void olpc_mic_bias(struct snd_ac97 *ac97, int on)
58 err = snd_ac97_update_bits(ac97, AC97_AD_MISC, 59 err = snd_ac97_update_bits(ac97, AC97_AD_MISC,
59 1 << AC97_AD_VREFD_SHIFT, on << AC97_AD_VREFD_SHIFT); 60 1 << AC97_AD_VREFD_SHIFT, on << AC97_AD_VREFD_SHIFT);
60 if (err < 0) 61 if (err < 0)
61 snd_printk(KERN_ERR "setting MIC Bias - %d\n", err); 62 dev_err(ac97->bus->card->dev, "setting MIC Bias - %d\n", err);
62} 63}
63 64
64static int olpc_dc_info(struct snd_kcontrol *kctl, 65static int olpc_dc_info(struct snd_kcontrol *kctl,
@@ -153,7 +154,7 @@ int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
153 return 0; 154 return 0;
154 155
155 if (gpio_request(OLPC_GPIO_MIC_AC, DRV_NAME)) { 156 if (gpio_request(OLPC_GPIO_MIC_AC, DRV_NAME)) {
156 printk(KERN_ERR DRV_NAME ": unable to allocate MIC GPIO\n"); 157 dev_err(card->dev, "unable to allocate MIC GPIO\n");
157 return -EIO; 158 return -EIO;
158 } 159 }
159 gpio_direction_output(OLPC_GPIO_MIC_AC, 0); 160 gpio_direction_output(OLPC_GPIO_MIC_AC, 0);
diff --git a/sound/pci/cs5535audio/cs5535audio_pcm.c b/sound/pci/cs5535audio/cs5535audio_pcm.c
index 9ab01a7047cf..9c2dc911d8d7 100644
--- a/sound/pci/cs5535audio/cs5535audio_pcm.c
+++ b/sound/pci/cs5535audio/cs5535audio_pcm.c
@@ -317,7 +317,7 @@ static int snd_cs5535audio_trigger(struct snd_pcm_substream *substream, int cmd)
317 dma->ops->disable_dma(cs5535au); 317 dma->ops->disable_dma(cs5535au);
318 break; 318 break;
319 default: 319 default:
320 snd_printk(KERN_ERR "unhandled trigger\n"); 320 dev_err(cs5535au->card->dev, "unhandled trigger\n");
321 err = -EINVAL; 321 err = -EINVAL;
322 break; 322 break;
323 } 323 }
@@ -335,13 +335,13 @@ static snd_pcm_uframes_t snd_cs5535audio_pcm_pointer(struct snd_pcm_substream
335 dma = substream->runtime->private_data; 335 dma = substream->runtime->private_data;
336 curdma = dma->ops->read_dma_pntr(cs5535au); 336 curdma = dma->ops->read_dma_pntr(cs5535au);
337 if (curdma < dma->buf_addr) { 337 if (curdma < dma->buf_addr) {
338 snd_printk(KERN_ERR "curdma=%x < %x bufaddr.\n", 338 dev_err(cs5535au->card->dev, "curdma=%x < %x bufaddr.\n",
339 curdma, dma->buf_addr); 339 curdma, dma->buf_addr);
340 return 0; 340 return 0;
341 } 341 }
342 curdma -= dma->buf_addr; 342 curdma -= dma->buf_addr;
343 if (curdma >= dma->buf_bytes) { 343 if (curdma >= dma->buf_bytes) {
344 snd_printk(KERN_ERR "diff=%x >= %x buf_bytes.\n", 344 dev_err(cs5535au->card->dev, "diff=%x >= %x buf_bytes.\n",
345 curdma, dma->buf_bytes); 345 curdma, dma->buf_bytes);
346 return 0; 346 return 0;
347 } 347 }
diff --git a/sound/pci/cs5535audio/cs5535audio_pm.c b/sound/pci/cs5535audio/cs5535audio_pm.c
index 6c34def5986d..34cc60057d0c 100644
--- a/sound/pci/cs5535audio/cs5535audio_pm.c
+++ b/sound/pci/cs5535audio/cs5535audio_pm.c
@@ -74,7 +74,7 @@ static int snd_cs5535audio_suspend(struct device *dev)
74 snd_cs5535audio_stop_hardware(cs5535au); 74 snd_cs5535audio_stop_hardware(cs5535au);
75 75
76 if (pci_save_state(pci)) { 76 if (pci_save_state(pci)) {
77 printk(KERN_ERR "cs5535audio: pci_save_state failed!\n"); 77 dev_err(dev, "pci_save_state failed!\n");
78 return -EIO; 78 return -EIO;
79 } 79 }
80 pci_disable_device(pci); 80 pci_disable_device(pci);
@@ -94,8 +94,7 @@ static int snd_cs5535audio_resume(struct device *dev)
94 pci_set_power_state(pci, PCI_D0); 94 pci_set_power_state(pci, PCI_D0);
95 pci_restore_state(pci); 95 pci_restore_state(pci);
96 if (pci_enable_device(pci) < 0) { 96 if (pci_enable_device(pci) < 0) {
97 printk(KERN_ERR "cs5535audio: pci_enable_device failed, " 97 dev_err(dev, "pci_enable_device failed, disabling device\n");
98 "disabling device\n");
99 snd_card_disconnect(card); 98 snd_card_disconnect(card);
100 return -EIO; 99 return -EIO;
101 } 100 }
@@ -113,7 +112,7 @@ static int snd_cs5535audio_resume(struct device *dev)
113 } while (--timeout); 112 } while (--timeout);
114 113
115 if (!timeout) 114 if (!timeout)
116 snd_printk(KERN_ERR "Failure getting AC Link ready\n"); 115 dev_err(cs5535au->card->dev, "Failure getting AC Link ready\n");
117 116
118 /* set up rate regs, dma. actual initiation is done in trig */ 117 /* set up rate regs, dma. actual initiation is done in trig */
119 for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) { 118 for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) {
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index eb86829529eb..af632bd08323 100644
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -1739,8 +1739,6 @@ int ct_atc_create(struct snd_card *card, struct pci_dev *pci,
1739 if (err < 0) 1739 if (err < 0)
1740 goto error1; 1740 goto error1;
1741 1741
1742 snd_card_set_dev(card, &pci->dev);
1743
1744 *ratc = atc; 1742 *ratc = atc;
1745 return 0; 1743 return 0;
1746 1744
diff --git a/sound/pci/ctxfi/xfi.c b/sound/pci/ctxfi/xfi.c
index d464ad2fc7b7..98426d09c8bd 100644
--- a/sound/pci/ctxfi/xfi.c
+++ b/sound/pci/ctxfi/xfi.c
@@ -71,7 +71,8 @@ ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
71 dev++; 71 dev++;
72 return -ENOENT; 72 return -ENOENT;
73 } 73 }
74 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 74 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
75 0, &card);
75 if (err) 76 if (err)
76 return err; 77 return err;
77 if ((reference_rate != 48000) && (reference_rate != 44100)) { 78 if ((reference_rate != 48000) && (reference_rate != 44100)) {
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 05cfe551ce42..9f10c9e0df5e 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -58,7 +58,8 @@ static int get_firmware(const struct firmware **fw_entry,
58 snprintf(name, sizeof(name), "ea/%s", card_fw[fw_index].data); 58 snprintf(name, sizeof(name), "ea/%s", card_fw[fw_index].data);
59 err = request_firmware(fw_entry, name, pci_device(chip)); 59 err = request_firmware(fw_entry, name, pci_device(chip));
60 if (err < 0) 60 if (err < 0)
61 snd_printk(KERN_ERR "get_firmware(): Firmware not available (%d)\n", err); 61 dev_err(chip->card->dev,
62 "get_firmware(): Firmware not available (%d)\n", err);
62#ifdef CONFIG_PM_SLEEP 63#ifdef CONFIG_PM_SLEEP
63 else 64 else
64 chip->fw_cache[fw_index] = *fw_entry; 65 chip->fw_cache[fw_index] = *fw_entry;
@@ -563,7 +564,7 @@ static int init_engine(struct snd_pcm_substream *substream,
563 err = snd_pcm_lib_malloc_pages(substream, 564 err = snd_pcm_lib_malloc_pages(substream,
564 params_buffer_bytes(hw_params)); 565 params_buffer_bytes(hw_params));
565 if (err < 0) { 566 if (err < 0) {
566 snd_printk(KERN_ERR "malloc_pages err=%d\n", err); 567 dev_err(chip->card->dev, "malloc_pages err=%d\n", err);
567 spin_lock_irq(&chip->lock); 568 spin_lock_irq(&chip->lock);
568 free_pipes(chip, pipe); 569 free_pipes(chip, pipe);
569 spin_unlock_irq(&chip->lock); 570 spin_unlock_irq(&chip->lock);
@@ -1989,8 +1990,8 @@ static int snd_echo_create(struct snd_card *card,
1989 1990
1990 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz, 1991 if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz,
1991 ECHOCARD_NAME)) == NULL) { 1992 ECHOCARD_NAME)) == NULL) {
1993 dev_err(chip->card->dev, "cannot get memory region\n");
1992 snd_echo_free(chip); 1994 snd_echo_free(chip);
1993 snd_printk(KERN_ERR "cannot get memory region\n");
1994 return -EBUSY; 1995 return -EBUSY;
1995 } 1996 }
1996 chip->dsp_registers = (volatile u32 __iomem *) 1997 chip->dsp_registers = (volatile u32 __iomem *)
@@ -1998,8 +1999,8 @@ static int snd_echo_create(struct snd_card *card,
1998 1999
1999 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED, 2000 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
2000 KBUILD_MODNAME, chip)) { 2001 KBUILD_MODNAME, chip)) {
2002 dev_err(chip->card->dev, "cannot grab irq\n");
2001 snd_echo_free(chip); 2003 snd_echo_free(chip);
2002 snd_printk(KERN_ERR "cannot grab irq\n");
2003 return -EBUSY; 2004 return -EBUSY;
2004 } 2005 }
2005 chip->irq = pci->irq; 2006 chip->irq = pci->irq;
@@ -2011,8 +2012,8 @@ static int snd_echo_create(struct snd_card *card,
2011 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), 2012 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
2012 sizeof(struct comm_page), 2013 sizeof(struct comm_page),
2013 &chip->commpage_dma_buf) < 0) { 2014 &chip->commpage_dma_buf) < 0) {
2015 dev_err(chip->card->dev, "cannot allocate the comm page\n");
2014 snd_echo_free(chip); 2016 snd_echo_free(chip);
2015 snd_printk(KERN_ERR "cannot allocate the comm page\n");
2016 return -ENOMEM; 2017 return -ENOMEM;
2017 } 2018 }
2018 chip->comm_page_phys = chip->commpage_dma_buf.addr; 2019 chip->comm_page_phys = chip->commpage_dma_buf.addr;
@@ -2058,12 +2059,11 @@ static int snd_echo_probe(struct pci_dev *pci,
2058 2059
2059 DE_INIT(("Echoaudio driver starting...\n")); 2060 DE_INIT(("Echoaudio driver starting...\n"));
2060 i = 0; 2061 i = 0;
2061 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2062 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2063 0, &card);
2062 if (err < 0) 2064 if (err < 0)
2063 return err; 2065 return err;
2064 2066
2065 snd_card_set_dev(card, &pci->dev);
2066
2067 chip = NULL; /* Tells snd_echo_create to allocate chip */ 2067 chip = NULL; /* Tells snd_echo_create to allocate chip */
2068 if ((err = snd_echo_create(card, pci, &chip)) < 0) { 2068 if ((err = snd_echo_create(card, pci, &chip)) < 0) {
2069 snd_card_free(card); 2069 snd_card_free(card);
@@ -2082,7 +2082,7 @@ static int snd_echo_probe(struct pci_dev *pci,
2082 chip->dsp_registers_phys, chip->irq); 2082 chip->dsp_registers_phys, chip->irq);
2083 2083
2084 if ((err = snd_echo_new_pcm(chip)) < 0) { 2084 if ((err = snd_echo_new_pcm(chip)) < 0) {
2085 snd_printk(KERN_ERR "new pcm error %d\n", err); 2085 dev_err(chip->card->dev, "new pcm error %d\n", err);
2086 snd_card_free(card); 2086 snd_card_free(card);
2087 return err; 2087 return err;
2088 } 2088 }
@@ -2090,7 +2090,7 @@ static int snd_echo_probe(struct pci_dev *pci,
2090#ifdef ECHOCARD_HAS_MIDI 2090#ifdef ECHOCARD_HAS_MIDI
2091 if (chip->has_midi) { /* Some Mia's do not have midi */ 2091 if (chip->has_midi) { /* Some Mia's do not have midi */
2092 if ((err = snd_echo_midi_create(card, chip)) < 0) { 2092 if ((err = snd_echo_midi_create(card, chip)) < 0) {
2093 snd_printk(KERN_ERR "new midi error %d\n", err); 2093 dev_err(chip->card->dev, "new midi error %d\n", err);
2094 snd_card_free(card); 2094 snd_card_free(card);
2095 return err; 2095 return err;
2096 } 2096 }
@@ -2189,14 +2189,14 @@ static int snd_echo_probe(struct pci_dev *pci,
2189 err = snd_card_register(card); 2189 err = snd_card_register(card);
2190 if (err < 0) 2190 if (err < 0)
2191 goto ctl_error; 2191 goto ctl_error;
2192 snd_printk(KERN_INFO "Card registered: %s\n", card->longname); 2192 dev_info(card->dev, "Card registered: %s\n", card->longname);
2193 2193
2194 pci_set_drvdata(pci, chip); 2194 pci_set_drvdata(pci, chip);
2195 dev++; 2195 dev++;
2196 return 0; 2196 return 0;
2197 2197
2198ctl_error: 2198ctl_error:
2199 snd_printk(KERN_ERR "new control error %d\n", err); 2199 dev_err(card->dev, "new control error %d\n", err);
2200 snd_card_free(card); 2200 snd_card_free(card);
2201 return err; 2201 return err;
2202} 2202}
@@ -2291,8 +2291,8 @@ static int snd_echo_resume(struct device *dev)
2291 2291
2292 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED, 2292 if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED,
2293 KBUILD_MODNAME, chip)) { 2293 KBUILD_MODNAME, chip)) {
2294 dev_err(chip->card->dev, "cannot grab irq\n");
2294 snd_echo_free(chip); 2295 snd_echo_free(chip);
2295 snd_printk(KERN_ERR "cannot grab irq\n");
2296 return -EBUSY; 2296 return -EBUSY;
2297 } 2297 }
2298 chip->irq = pci->irq; 2298 chip->irq = pci->irq;
diff --git a/sound/pci/echoaudio/echoaudio_dsp.c b/sound/pci/echoaudio/echoaudio_dsp.c
index d8c670c9d62c..5a6a217b82e0 100644
--- a/sound/pci/echoaudio/echoaudio_dsp.c
+++ b/sound/pci/echoaudio/echoaudio_dsp.c
@@ -53,7 +53,7 @@ static int wait_handshake(struct echoaudio *chip)
53 udelay(1); 53 udelay(1);
54 } 54 }
55 55
56 snd_printk(KERN_ERR "wait_handshake(): Timeout waiting for DSP\n"); 56 dev_err(chip->card->dev, "wait_handshake(): Timeout waiting for DSP\n");
57 return -EBUSY; 57 return -EBUSY;
58} 58}
59 59
@@ -149,7 +149,8 @@ static int read_sn(struct echoaudio *chip)
149 149
150 for (i = 0; i < 5; i++) { 150 for (i = 0; i < 5; i++) {
151 if (read_dsp(chip, &sn[i])) { 151 if (read_dsp(chip, &sn[i])) {
152 snd_printk(KERN_ERR "Failed to read serial number\n"); 152 dev_err(chip->card->dev,
153 "Failed to read serial number\n");
153 return -EIO; 154 return -EIO;
154 } 155 }
155 } 156 }
@@ -184,7 +185,7 @@ static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic)
184 185
185 err = get_firmware(&fw, chip, asic); 186 err = get_firmware(&fw, chip, asic);
186 if (err < 0) { 187 if (err < 0) {
187 snd_printk(KERN_WARNING "Firmware not found !\n"); 188 dev_warn(chip->card->dev, "Firmware not found !\n");
188 return err; 189 return err;
189 } 190 }
190 191
@@ -247,7 +248,7 @@ static int install_resident_loader(struct echoaudio *chip)
247 248
248 i = get_firmware(&fw, chip, FW_361_LOADER); 249 i = get_firmware(&fw, chip, FW_361_LOADER);
249 if (i < 0) { 250 if (i < 0) {
250 snd_printk(KERN_WARNING "Firmware not found !\n"); 251 dev_warn(chip->card->dev, "Firmware not found !\n");
251 return i; 252 return i;
252 } 253 }
253 254
diff --git a/sound/pci/echoaudio/midi.c b/sound/pci/echoaudio/midi.c
index abfd51c2530e..7f4dfae0323a 100644
--- a/sound/pci/echoaudio/midi.c
+++ b/sound/pci/echoaudio/midi.c
@@ -221,7 +221,8 @@ static void snd_echo_midi_output_write(unsigned long data)
221 DE_MID(("Try to send %d bytes...\n", bytes)); 221 DE_MID(("Try to send %d bytes...\n", bytes));
222 sent = write_midi(chip, buf, bytes); 222 sent = write_midi(chip, buf, bytes);
223 if (sent < 0) { 223 if (sent < 0) {
224 snd_printk(KERN_ERR "write_midi() error %d\n", sent); 224 dev_err(chip->card->dev,
225 "write_midi() error %d\n", sent);
225 /* retry later */ 226 /* retry later */
226 sent = 9000; 227 sent = 9000;
227 chip->midi_full = 1; 228 chip->midi_full = 1;
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c
index 9e1bd0c39a8c..ad9d9f8b48ed 100644
--- a/sound/pci/emu10k1/emu10k1.c
+++ b/sound/pci/emu10k1/emu10k1.c
@@ -117,7 +117,8 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci,
117 return -ENOENT; 117 return -ENOENT;
118 } 118 }
119 119
120 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 120 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
121 0, &card);
121 if (err < 0) 122 if (err < 0)
122 return err; 123 return err;
123 if (max_buffer_size[dev] < 32) 124 if (max_buffer_size[dev] < 32)
@@ -169,7 +170,8 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci,
169 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, 170 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
170 sizeof(struct snd_emu10k1_synth_arg), &wave) < 0 || 171 sizeof(struct snd_emu10k1_synth_arg), &wave) < 0 ||
171 wave == NULL) { 172 wave == NULL) {
172 snd_printk(KERN_WARNING "can't initialize Emu10k1 wavetable synth\n"); 173 dev_warn(emu->card->dev,
174 "can't initialize Emu10k1 wavetable synth\n");
173 } else { 175 } else {
174 struct snd_emu10k1_synth_arg *arg; 176 struct snd_emu10k1_synth_arg *arg;
175 arg = SNDRV_SEQ_DEVICE_ARGPTR(wave); 177 arg = SNDRV_SEQ_DEVICE_ARGPTR(wave);
@@ -246,8 +248,7 @@ static int snd_emu10k1_resume(struct device *dev)
246 pci_set_power_state(pci, PCI_D0); 248 pci_set_power_state(pci, PCI_D0);
247 pci_restore_state(pci); 249 pci_restore_state(pci);
248 if (pci_enable_device(pci) < 0) { 250 if (pci_enable_device(pci) < 0) {
249 printk(KERN_ERR "emu10k1: pci_enable_device failed, " 251 dev_err(dev, "pci_enable_device failed, disabling device\n");
250 "disabling device\n");
251 snd_card_disconnect(card); 252 snd_card_disconnect(card);
252 return -EIO; 253 return -EIO;
253 } 254 }
diff --git a/sound/pci/emu10k1/emu10k1_callback.c b/sound/pci/emu10k1/emu10k1_callback.c
index cae36597aa71..3f3ef38d9b6e 100644
--- a/sound/pci/emu10k1/emu10k1_callback.c
+++ b/sound/pci/emu10k1/emu10k1_callback.c
@@ -105,7 +105,7 @@ snd_emu10k1_synth_get_voice(struct snd_emu10k1 *hw)
105 vp = &emu->voices[best[i].voice]; 105 vp = &emu->voices[best[i].voice];
106 if ((ch = vp->ch) < 0) { 106 if ((ch = vp->ch) < 0) {
107 /* 107 /*
108 printk(KERN_WARNING 108 dev_warn(emu->card->dev,
109 "synth_get_voice: ch < 0 (%d) ??", i); 109 "synth_get_voice: ch < 0 (%d) ??", i);
110 */ 110 */
111 continue; 111 continue;
@@ -339,7 +339,7 @@ start_voice(struct snd_emux_voice *vp)
339 return -EINVAL; 339 return -EINVAL;
340 emem->map_locked++; 340 emem->map_locked++;
341 if (snd_emu10k1_memblk_map(hw, emem) < 0) { 341 if (snd_emu10k1_memblk_map(hw, emem) < 0) {
342 /* printk(KERN_ERR "emu: cannot map!\n"); */ 342 /* dev_err(hw->card->devK, "emu: cannot map!\n"); */
343 return -ENOMEM; 343 return -ENOMEM;
344 } 344 }
345 mapped_offset = snd_emu10k1_memblk_offset(emem) >> 1; 345 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 bdd888ec9a84..229269788023 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -217,7 +217,7 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
217 } 217 }
218 if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */ 218 if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */
219 /* Hacks for Alice3 to work independent of haP16V driver */ 219 /* Hacks for Alice3 to work independent of haP16V driver */
220 snd_printk(KERN_INFO "Audigy2 value: Special config.\n"); 220 dev_info(emu->card->dev, "Audigy2 value: Special config.\n");
221 /* Setup SRCMulti_I2S SamplingRate */ 221 /* Setup SRCMulti_I2S SamplingRate */
222 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0); 222 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
223 tmp &= 0xfffff1ff; 223 tmp &= 0xfffff1ff;
@@ -723,7 +723,8 @@ static int emu1010_firmware_thread(void *data)
723 if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) { 723 if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) {
724 /* Audio Dock attached */ 724 /* Audio Dock attached */
725 /* Return to Audio Dock programming mode */ 725 /* Return to Audio Dock programming mode */
726 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware\n"); 726 dev_info(emu->card->dev,
727 "emu1010: Loading Audio Dock Firmware\n");
727 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, EMU_HANA_FPGA_CONFIG_AUDIODOCK); 728 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, EMU_HANA_FPGA_CONFIG_AUDIODOCK);
728 729
729 if (!emu->dock_fw) { 730 if (!emu->dock_fw) {
@@ -756,19 +757,25 @@ static int emu1010_firmware_thread(void *data)
756 757
757 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0); 758 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0);
758 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &reg); 759 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &reg);
759 snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_IRQ_STATUS = 0x%x\n", reg); 760 dev_info(emu->card->dev,
761 "emu1010: EMU_HANA+DOCK_IRQ_STATUS = 0x%x\n",
762 reg);
760 /* ID, should read & 0x7f = 0x55 when FPGA programmed. */ 763 /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
761 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg); 764 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
762 snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_ID = 0x%x\n", reg); 765 dev_info(emu->card->dev,
766 "emu1010: EMU_HANA+DOCK_ID = 0x%x\n", reg);
763 if ((reg & 0x1f) != 0x15) { 767 if ((reg & 0x1f) != 0x15) {
764 /* FPGA failed to be programmed */ 768 /* FPGA failed to be programmed */
765 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware file failed, reg = 0x%x\n", reg); 769 dev_info(emu->card->dev,
770 "emu1010: Loading Audio Dock Firmware file failed, reg = 0x%x\n",
771 reg);
766 continue; 772 continue;
767 } 773 }
768 snd_printk(KERN_INFO "emu1010: Audio Dock Firmware loaded\n"); 774 dev_info(emu->card->dev,
775 "emu1010: Audio Dock Firmware loaded\n");
769 snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp); 776 snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp);
770 snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2); 777 snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2);
771 snd_printk(KERN_INFO "Audio Dock ver: %u.%u\n", 778 dev_info(emu->card->dev, "Audio Dock ver: %u.%u\n",
772 tmp, tmp2); 779 tmp, tmp2);
773 /* Sync clocking between 1010 and Dock */ 780 /* Sync clocking between 1010 and Dock */
774 /* Allow DLL to settle */ 781 /* Allow DLL to settle */
@@ -777,7 +784,7 @@ static int emu1010_firmware_thread(void *data)
777 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE); 784 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
778 } 785 }
779 } 786 }
780 snd_printk(KERN_INFO "emu1010: firmware thread stopping\n"); 787 dev_info(emu->card->dev, "emu1010: firmware thread stopping\n");
781 return 0; 788 return 0;
782} 789}
783 790
@@ -818,7 +825,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
818 u32 tmp, tmp2, reg; 825 u32 tmp, tmp2, reg;
819 int err; 826 int err;
820 827
821 snd_printk(KERN_INFO "emu1010: Special config.\n"); 828 dev_info(emu->card->dev, "emu1010: Special config.\n");
822 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave, 829 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
823 * Lock Sound Memory Cache, Lock Tank Memory Cache, 830 * Lock Sound Memory Cache, Lock Tank Memory Cache,
824 * Mute all codecs. 831 * Mute all codecs.
@@ -843,7 +850,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
843 850
844 /* ID, should read & 0x7f = 0x55. (Bit 7 is the IRQ bit) */ 851 /* ID, should read & 0x7f = 0x55. (Bit 7 is the IRQ bit) */
845 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg); 852 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
846 snd_printdd("reg1 = 0x%x\n", reg); 853 dev_dbg(emu->card->dev, "reg1 = 0x%x\n", reg);
847 if ((reg & 0x3f) == 0x15) { 854 if ((reg & 0x3f) == 0x15) {
848 /* FPGA netlist already present so clear it */ 855 /* FPGA netlist already present so clear it */
849 /* Return to programming mode */ 856 /* Return to programming mode */
@@ -851,13 +858,14 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
851 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0x02); 858 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0x02);
852 } 859 }
853 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg); 860 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
854 snd_printdd("reg2 = 0x%x\n", reg); 861 dev_dbg(emu->card->dev, "reg2 = 0x%x\n", reg);
855 if ((reg & 0x3f) == 0x15) { 862 if ((reg & 0x3f) == 0x15) {
856 /* FPGA failed to return to programming mode */ 863 /* FPGA failed to return to programming mode */
857 snd_printk(KERN_INFO "emu1010: FPGA failed to return to programming mode\n"); 864 dev_info(emu->card->dev,
865 "emu1010: FPGA failed to return to programming mode\n");
858 return -ENODEV; 866 return -ENODEV;
859 } 867 }
860 snd_printk(KERN_INFO "emu1010: EMU_HANA_ID = 0x%x\n", reg); 868 dev_info(emu->card->dev, "emu1010: EMU_HANA_ID = 0x%x\n", reg);
861 869
862 if (!emu->firmware) { 870 if (!emu->firmware) {
863 const char *filename; 871 const char *filename;
@@ -880,16 +888,19 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
880 888
881 err = request_firmware(&emu->firmware, filename, &emu->pci->dev); 889 err = request_firmware(&emu->firmware, filename, &emu->pci->dev);
882 if (err != 0) { 890 if (err != 0) {
883 snd_printk(KERN_ERR "emu1010: firmware: %s not found. Err = %d\n", filename, err); 891 dev_info(emu->card->dev,
892 "emu1010: firmware: %s not found. Err = %d\n",
893 filename, err);
884 return err; 894 return err;
885 } 895 }
886 snd_printk(KERN_INFO "emu1010: firmware file = %s, size = 0x%zx\n", 896 dev_info(emu->card->dev,
897 "emu1010: firmware file = %s, size = 0x%zx\n",
887 filename, emu->firmware->size); 898 filename, emu->firmware->size);
888 } 899 }
889 900
890 err = snd_emu1010_load_firmware(emu, emu->firmware); 901 err = snd_emu1010_load_firmware(emu, emu->firmware);
891 if (err != 0) { 902 if (err != 0) {
892 snd_printk(KERN_INFO "emu1010: Loading Firmware failed\n"); 903 dev_info(emu->card->dev, "emu1010: Loading Firmware failed\n");
893 return err; 904 return err;
894 } 905 }
895 906
@@ -897,21 +908,23 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
897 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg); 908 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
898 if ((reg & 0x3f) != 0x15) { 909 if ((reg & 0x3f) != 0x15) {
899 /* FPGA failed to be programmed */ 910 /* FPGA failed to be programmed */
900 snd_printk(KERN_INFO "emu1010: Loading Hana Firmware file failed, reg = 0x%x\n", reg); 911 dev_info(emu->card->dev,
912 "emu1010: Loading Hana Firmware file failed, reg = 0x%x\n",
913 reg);
901 return -ENODEV; 914 return -ENODEV;
902 } 915 }
903 916
904 snd_printk(KERN_INFO "emu1010: Hana Firmware loaded\n"); 917 dev_info(emu->card->dev, "emu1010: Hana Firmware loaded\n");
905 snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp); 918 snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp);
906 snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2); 919 snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2);
907 snd_printk(KERN_INFO "emu1010: Hana version: %u.%u\n", tmp, tmp2); 920 dev_info(emu->card->dev, "emu1010: Hana version: %u.%u\n", tmp, tmp2);
908 /* Enable 48Volt power to Audio Dock */ 921 /* Enable 48Volt power to Audio Dock */
909 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, EMU_HANA_DOCK_PWR_ON); 922 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, EMU_HANA_DOCK_PWR_ON);
910 923
911 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg); 924 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
912 snd_printk(KERN_INFO "emu1010: Card options = 0x%x\n", reg); 925 dev_info(emu->card->dev, "emu1010: Card options = 0x%x\n", reg);
913 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg); 926 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
914 snd_printk(KERN_INFO "emu1010: Card options = 0x%x\n", reg); 927 dev_info(emu->card->dev, "emu1010: Card options = 0x%x\n", reg);
915 snd_emu1010_fpga_read(emu, EMU_HANA_OPTICAL_TYPE, &tmp); 928 snd_emu1010_fpga_read(emu, EMU_HANA_OPTICAL_TYPE, &tmp);
916 /* Optical -> ADAT I/O */ 929 /* Optical -> ADAT I/O */
917 /* 0 : SPDIF 930 /* 0 : SPDIF
@@ -950,7 +963,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
950 snd_emu1010_fpga_write(emu, EMU_HANA_IRQ_ENABLE, 0x00); 963 snd_emu1010_fpga_write(emu, EMU_HANA_IRQ_ENABLE, 0x00);
951 964
952 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg); 965 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
953 snd_printk(KERN_INFO "emu1010: Card options3 = 0x%x\n", reg); 966 dev_info(emu->card->dev, "emu1010: Card options3 = 0x%x\n", reg);
954 /* Default WCLK set to 48kHz. */ 967 /* Default WCLK set to 48kHz. */
955 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x00); 968 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x00);
956 /* Word Clock source, Internal 48kHz x1 */ 969 /* Word Clock source, Internal 48kHz x1 */
@@ -1808,7 +1821,9 @@ int snd_emu10k1_create(struct snd_card *card,
1808 emu->revision = pci->revision; 1821 emu->revision = pci->revision;
1809 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial); 1822 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
1810 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model); 1823 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
1811 snd_printdd("vendor = 0x%x, device = 0x%x, subsystem_vendor_id = 0x%x, subsystem_id = 0x%x\n", pci->vendor, pci->device, emu->serial, emu->model); 1824 dev_dbg(card->dev,
1825 "vendor = 0x%x, device = 0x%x, subsystem_vendor_id = 0x%x, subsystem_id = 0x%x\n",
1826 pci->vendor, pci->device, emu->serial, emu->model);
1812 1827
1813 for (c = emu_chip_details; c->vendor; c++) { 1828 for (c = emu_chip_details; c->vendor; c++) {
1814 if (c->vendor == pci->vendor && c->device == pci->device) { 1829 if (c->vendor == pci->vendor && c->device == pci->device) {
@@ -1827,21 +1842,21 @@ int snd_emu10k1_create(struct snd_card *card,
1827 } 1842 }
1828 } 1843 }
1829 if (c->vendor == 0) { 1844 if (c->vendor == 0) {
1830 snd_printk(KERN_ERR "emu10k1: Card not recognised\n"); 1845 dev_err(card->dev, "emu10k1: Card not recognised\n");
1831 kfree(emu); 1846 kfree(emu);
1832 pci_disable_device(pci); 1847 pci_disable_device(pci);
1833 return -ENOENT; 1848 return -ENOENT;
1834 } 1849 }
1835 emu->card_capabilities = c; 1850 emu->card_capabilities = c;
1836 if (c->subsystem && !subsystem) 1851 if (c->subsystem && !subsystem)
1837 snd_printdd("Sound card name = %s\n", c->name); 1852 dev_dbg(card->dev, "Sound card name = %s\n", c->name);
1838 else if (subsystem) 1853 else if (subsystem)
1839 snd_printdd("Sound card name = %s, " 1854 dev_dbg(card->dev, "Sound card name = %s, "
1840 "vendor = 0x%x, device = 0x%x, subsystem = 0x%x. " 1855 "vendor = 0x%x, device = 0x%x, subsystem = 0x%x. "
1841 "Forced to subsystem = 0x%x\n", c->name, 1856 "Forced to subsystem = 0x%x\n", c->name,
1842 pci->vendor, pci->device, emu->serial, c->subsystem); 1857 pci->vendor, pci->device, emu->serial, c->subsystem);
1843 else 1858 else
1844 snd_printdd("Sound card name = %s, " 1859 dev_dbg(card->dev, "Sound card name = %s, "
1845 "vendor = 0x%x, device = 0x%x, subsystem = 0x%x.\n", 1860 "vendor = 0x%x, device = 0x%x, subsystem = 0x%x.\n",
1846 c->name, pci->vendor, pci->device, 1861 c->name, pci->vendor, pci->device,
1847 emu->serial); 1862 emu->serial);
@@ -1869,7 +1884,9 @@ int snd_emu10k1_create(struct snd_card *card,
1869 emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK; 1884 emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
1870 if (pci_set_dma_mask(pci, emu->dma_mask) < 0 || 1885 if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
1871 pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) { 1886 pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
1872 snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask); 1887 dev_err(card->dev,
1888 "architecture does not support PCI busmaster DMA with mask 0x%lx\n",
1889 emu->dma_mask);
1873 kfree(emu); 1890 kfree(emu);
1874 pci_disable_device(pci); 1891 pci_disable_device(pci);
1875 return -ENXIO; 1892 return -ENXIO;
@@ -2021,7 +2038,6 @@ int snd_emu10k1_create(struct snd_card *card,
2021 snd_emu10k1_proc_init(emu); 2038 snd_emu10k1_proc_init(emu);
2022#endif 2039#endif
2023 2040
2024 snd_card_set_dev(card, &pci->dev);
2025 *remu = emu; 2041 *remu = emu;
2026 return 0; 2042 return 0;
2027 2043
diff --git a/sound/pci/emu10k1/emu10k1_patch.c b/sound/pci/emu10k1/emu10k1_patch.c
index 662a45876a8b..0e069aeab86d 100644
--- a/sound/pci/emu10k1/emu10k1_patch.c
+++ b/sound/pci/emu10k1/emu10k1_patch.c
@@ -50,7 +50,8 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
50 return -EINVAL; 50 return -EINVAL;
51 51
52 if (sp->v.size == 0) { 52 if (sp->v.size == 0) {
53 snd_printd("emu: rom font for sample %d\n", sp->v.sample); 53 dev_dbg(emu->card->dev,
54 "emu: rom font for sample %d\n", sp->v.sample);
54 return 0; 55 return 0;
55 } 56 }
56 57
@@ -92,7 +93,8 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
92 blocksize *= 2; 93 blocksize *= 2;
93 sp->block = snd_emu10k1_synth_alloc(emu, blocksize); 94 sp->block = snd_emu10k1_synth_alloc(emu, blocksize);
94 if (sp->block == NULL) { 95 if (sp->block == NULL) {
95 snd_printd("emu10k1: synth malloc failed (size=%d)\n", blocksize); 96 dev_dbg(emu->card->dev,
97 "synth malloc failed (size=%d)\n", blocksize);
96 /* not ENOMEM (for compatibility with OSS) */ 98 /* not ENOMEM (for compatibility with OSS) */
97 return -ENOSPC; 99 return -ENOSPC;
98 } 100 }
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 56ad9d6f200d..efe017526977 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -369,7 +369,8 @@ static void snd_emu10k1x_pcm_interrupt(struct emu10k1x *emu, struct emu10k1x_voi
369 if (epcm->substream == NULL) 369 if (epcm->substream == NULL)
370 return; 370 return;
371#if 0 371#if 0
372 snd_printk(KERN_INFO "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n", 372 dev_info(emu->card->dev,
373 "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
373 epcm->substream->ops->pointer(epcm->substream), 374 epcm->substream->ops->pointer(epcm->substream),
374 snd_pcm_lib_period_bytes(epcm->substream), 375 snd_pcm_lib_period_bytes(epcm->substream),
375 snd_pcm_lib_buffer_bytes(epcm->substream)); 376 snd_pcm_lib_buffer_bytes(epcm->substream));
@@ -487,7 +488,11 @@ static int snd_emu10k1x_pcm_trigger(struct snd_pcm_substream *substream,
487 int channel = epcm->voice->number; 488 int channel = epcm->voice->number;
488 int result = 0; 489 int result = 0;
489 490
490// snd_printk(KERN_INFO "trigger - emu10k1x = 0x%x, cmd = %i, pointer = %d\n", (int)emu, cmd, (int)substream->ops->pointer(substream)); 491 /*
492 dev_dbg(emu->card->dev,
493 "trigger - emu10k1x = 0x%x, cmd = %i, pointer = %d\n",
494 (int)emu, cmd, (int)substream->ops->pointer(substream));
495 */
491 496
492 switch (cmd) { 497 switch (cmd) {
493 case SNDRV_PCM_TRIGGER_START: 498 case SNDRV_PCM_TRIGGER_START:
@@ -826,7 +831,7 @@ static irqreturn_t snd_emu10k1x_interrupt(int irq, void *dev_id)
826 // acknowledge the interrupt if necessary 831 // acknowledge the interrupt if necessary
827 outl(status, chip->port + IPR); 832 outl(status, chip->port + IPR);
828 833
829 // snd_printk(KERN_INFO "interrupt %08x\n", status); 834 /* dev_dbg(chip->card->dev, "interrupt %08x\n", status); */
830 return IRQ_HANDLED; 835 return IRQ_HANDLED;
831} 836}
832 837
@@ -919,7 +924,7 @@ static int snd_emu10k1x_create(struct snd_card *card,
919 return err; 924 return err;
920 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || 925 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
921 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { 926 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) {
922 snd_printk(KERN_ERR "error to set 28bit mask DMA\n"); 927 dev_err(card->dev, "error to set 28bit mask DMA\n");
923 pci_disable_device(pci); 928 pci_disable_device(pci);
924 return -ENXIO; 929 return -ENXIO;
925 } 930 }
@@ -940,14 +945,15 @@ static int snd_emu10k1x_create(struct snd_card *card,
940 chip->port = pci_resource_start(pci, 0); 945 chip->port = pci_resource_start(pci, 0);
941 if ((chip->res_port = request_region(chip->port, 8, 946 if ((chip->res_port = request_region(chip->port, 8,
942 "EMU10K1X")) == NULL) { 947 "EMU10K1X")) == NULL) {
943 snd_printk(KERN_ERR "emu10k1x: cannot allocate the port 0x%lx\n", chip->port); 948 dev_err(card->dev, "cannot allocate the port 0x%lx\n",
949 chip->port);
944 snd_emu10k1x_free(chip); 950 snd_emu10k1x_free(chip);
945 return -EBUSY; 951 return -EBUSY;
946 } 952 }
947 953
948 if (request_irq(pci->irq, snd_emu10k1x_interrupt, 954 if (request_irq(pci->irq, snd_emu10k1x_interrupt,
949 IRQF_SHARED, KBUILD_MODNAME, chip)) { 955 IRQF_SHARED, KBUILD_MODNAME, chip)) {
950 snd_printk(KERN_ERR "emu10k1x: cannot grab irq %d\n", pci->irq); 956 dev_err(card->dev, "cannot grab irq %d\n", pci->irq);
951 snd_emu10k1x_free(chip); 957 snd_emu10k1x_free(chip);
952 return -EBUSY; 958 return -EBUSY;
953 } 959 }
@@ -964,7 +970,7 @@ static int snd_emu10k1x_create(struct snd_card *card,
964 chip->revision = pci->revision; 970 chip->revision = pci->revision;
965 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial); 971 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
966 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model); 972 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
967 snd_printk(KERN_INFO "Model %04x Rev %08x Serial %08x\n", chip->model, 973 dev_info(card->dev, "Model %04x Rev %08x Serial %08x\n", chip->model,
968 chip->revision, chip->serial); 974 chip->revision, chip->serial);
969 975
970 outl(0, chip->port + INTE); 976 outl(0, chip->port + INTE);
@@ -1248,7 +1254,9 @@ static void mpu401_clear_rx(struct emu10k1x *emu, struct emu10k1x_midi *mpu)
1248 mpu401_read_data(emu, mpu); 1254 mpu401_read_data(emu, mpu);
1249#ifdef CONFIG_SND_DEBUG 1255#ifdef CONFIG_SND_DEBUG
1250 if (timeout <= 0) 1256 if (timeout <= 0)
1251 snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n", mpu401_read_stat(emu, mpu)); 1257 dev_err(emu->card->dev,
1258 "cmd: clear rx timeout (status = 0x%x)\n",
1259 mpu401_read_stat(emu, mpu));
1252#endif 1260#endif
1253} 1261}
1254 1262
@@ -1322,7 +1330,8 @@ static int snd_emu10k1x_midi_cmd(struct emu10k1x * emu,
1322 } 1330 }
1323 spin_unlock_irqrestore(&midi->input_lock, flags); 1331 spin_unlock_irqrestore(&midi->input_lock, flags);
1324 if (!ok) { 1332 if (!ok) {
1325 snd_printk(KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n", 1333 dev_err(emu->card->dev,
1334 "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
1326 cmd, emu->port, 1335 cmd, emu->port,
1327 mpu401_read_stat(emu, midi), 1336 mpu401_read_stat(emu, midi),
1328 mpu401_read_data(emu, midi)); 1337 mpu401_read_data(emu, midi));
@@ -1564,7 +1573,8 @@ static int snd_emu10k1x_probe(struct pci_dev *pci,
1564 return -ENOENT; 1573 return -ENOENT;
1565 } 1574 }
1566 1575
1567 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1576 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1577 0, &card);
1568 if (err < 0) 1578 if (err < 0)
1569 return err; 1579 return err;
1570 1580
@@ -1608,8 +1618,6 @@ static int snd_emu10k1x_probe(struct pci_dev *pci,
1608 sprintf(card->longname, "%s at 0x%lx irq %i", 1618 sprintf(card->longname, "%s at 0x%lx irq %i",
1609 card->shortname, chip->port, chip->irq); 1619 card->shortname, chip->port, chip->irq);
1610 1620
1611 snd_card_set_dev(card, &pci->dev);
1612
1613 if ((err = snd_card_register(card)) < 0) { 1621 if ((err = snd_card_register(card)) < 0) {
1614 snd_card_free(card); 1622 snd_card_free(card);
1615 return err; 1623 return err;
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 1f9c7c4bbcd8..745f0627c634 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -1547,7 +1547,7 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
1547 /* A_PUT_STEREO_OUTPUT(A_EXTOUT_FRONT_L, A_EXTOUT_FRONT_R, playback + SND_EMU10K1_PLAYBACK_CHANNELS); */ 1547 /* A_PUT_STEREO_OUTPUT(A_EXTOUT_FRONT_L, A_EXTOUT_FRONT_R, playback + SND_EMU10K1_PLAYBACK_CHANNELS); */
1548 if (emu->card_capabilities->emu_model) { 1548 if (emu->card_capabilities->emu_model) {
1549 /* EMU1010 Outputs from PCM Front, Rear, Center, LFE, Side */ 1549 /* EMU1010 Outputs from PCM Front, Rear, Center, LFE, Side */
1550 snd_printk(KERN_INFO "EMU outputs on\n"); 1550 dev_info(emu->card->dev, "EMU outputs on\n");
1551 for (z = 0; z < 8; z++) { 1551 for (z = 0; z < 8; z++) {
1552 if (emu->card_capabilities->ca0108_chip) { 1552 if (emu->card_capabilities->ca0108_chip) {
1553 A_OP(icode, &ptr, iACC3, A3_EMU32OUT(z), A_GPR(playback + SND_EMU10K1_PLAYBACK_CHANNELS + z), A_C_00000000, A_C_00000000); 1553 A_OP(icode, &ptr, iACC3, A3_EMU32OUT(z), A_GPR(playback + SND_EMU10K1_PLAYBACK_CHANNELS + z), A_C_00000000, A_C_00000000);
@@ -1571,7 +1571,9 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
1571 A_SWITCH(icode, &ptr, tmp + 1, playback + SND_EMU10K1_PLAYBACK_CHANNELS + z, tmp + 1); 1571 A_SWITCH(icode, &ptr, tmp + 1, playback + SND_EMU10K1_PLAYBACK_CHANNELS + z, tmp + 1);
1572 if ((z==1) && (emu->card_capabilities->spdif_bug)) { 1572 if ((z==1) && (emu->card_capabilities->spdif_bug)) {
1573 /* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */ 1573 /* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */
1574 snd_printk(KERN_INFO "Installing spdif_bug patch: %s\n", emu->card_capabilities->name); 1574 dev_info(emu->card->dev,
1575 "Installing spdif_bug patch: %s\n",
1576 emu->card_capabilities->name);
1575 A_OP(icode, &ptr, iACC3, A_EXTOUT(A_EXTOUT_FRONT_L + z), A_GPR(gpr - 3), A_C_00000000, A_C_00000000); 1577 A_OP(icode, &ptr, iACC3, A_EXTOUT(A_EXTOUT_FRONT_L + z), A_GPR(gpr - 3), A_C_00000000, A_C_00000000);
1576 A_OP(icode, &ptr, iACC3, A_GPR(gpr - 3), A_GPR(tmp + 0), A_GPR(tmp + 1), A_C_00000000); 1578 A_OP(icode, &ptr, iACC3, A_GPR(gpr - 3), A_GPR(tmp + 0), A_GPR(tmp + 1), A_C_00000000);
1577 } else { 1579 } else {
@@ -1595,7 +1597,7 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
1595 1597
1596 if (emu->card_capabilities->emu_model) { 1598 if (emu->card_capabilities->emu_model) {
1597 if (emu->card_capabilities->ca0108_chip) { 1599 if (emu->card_capabilities->ca0108_chip) {
1598 snd_printk(KERN_INFO "EMU2 inputs on\n"); 1600 dev_info(emu->card->dev, "EMU2 inputs on\n");
1599 for (z = 0; z < 0x10; z++) { 1601 for (z = 0; z < 0x10; z++) {
1600 snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, 1602 snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp,
1601 bit_shifter16, 1603 bit_shifter16,
@@ -1603,11 +1605,11 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
1603 A_FXBUS2(z*2) ); 1605 A_FXBUS2(z*2) );
1604 } 1606 }
1605 } else { 1607 } else {
1606 snd_printk(KERN_INFO "EMU inputs on\n"); 1608 dev_info(emu->card->dev, "EMU inputs on\n");
1607 /* Capture 16 (originally 8) channels of S32_LE sound */ 1609 /* Capture 16 (originally 8) channels of S32_LE sound */
1608 1610
1609 /* 1611 /*
1610 printk(KERN_DEBUG "emufx.c: gpr=0x%x, tmp=0x%x\n", 1612 dev_dbg(emu->card->dev, "emufx.c: gpr=0x%x, tmp=0x%x\n",
1611 gpr, tmp); 1613 gpr, tmp);
1612 */ 1614 */
1613 /* For the EMU1010: How to get 32bit values from the DSP. High 16bits into L, low 16bits into R. */ 1615 /* For the EMU1010: How to get 32bit values from the DSP. High 16bits into L, low 16bits into R. */
diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c
index f6c3da0d377d..c5ae2a24d8a5 100644
--- a/sound/pci/emu10k1/emumixer.c
+++ b/sound/pci/emu10k1/emumixer.c
@@ -1853,8 +1853,10 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu,
1853 if ((err = snd_ac97_mixer(pbus, &ac97, &emu->ac97)) < 0) { 1853 if ((err = snd_ac97_mixer(pbus, &ac97, &emu->ac97)) < 0) {
1854 if (emu->card_capabilities->ac97_chip == 1) 1854 if (emu->card_capabilities->ac97_chip == 1)
1855 return err; 1855 return err;
1856 snd_printd(KERN_INFO "emu10k1: AC97 is optional on this board\n"); 1856 dev_info(emu->card->dev,
1857 snd_printd(KERN_INFO" Proceeding without ac97 mixers...\n"); 1857 "AC97 is optional on this board\n");
1858 dev_info(emu->card->dev,
1859 "Proceeding without ac97 mixers...\n");
1858 snd_device_free(emu->card, pbus); 1860 snd_device_free(emu->card, pbus);
1859 goto no_ac97; /* FIXME: get rid of ugly gotos.. */ 1861 goto no_ac97; /* FIXME: get rid of ugly gotos.. */
1860 } 1862 }
diff --git a/sound/pci/emu10k1/emumpu401.c b/sound/pci/emu10k1/emumpu401.c
index 1ec91246dfee..fdf2b0ada489 100644
--- a/sound/pci/emu10k1/emumpu401.c
+++ b/sound/pci/emu10k1/emumpu401.c
@@ -64,7 +64,9 @@ static void mpu401_clear_rx(struct snd_emu10k1 *emu, struct snd_emu10k1_midi *mp
64 mpu401_read_data(emu, mpu); 64 mpu401_read_data(emu, mpu);
65#ifdef CONFIG_SND_DEBUG 65#ifdef CONFIG_SND_DEBUG
66 if (timeout <= 0) 66 if (timeout <= 0)
67 snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n", mpu401_read_stat(emu, mpu)); 67 dev_err(emu->card->dev,
68 "cmd: clear rx timeout (status = 0x%x)\n",
69 mpu401_read_stat(emu, mpu));
68#endif 70#endif
69} 71}
70 72
@@ -141,7 +143,8 @@ static int snd_emu10k1_midi_cmd(struct snd_emu10k1 * emu, struct snd_emu10k1_mid
141 } 143 }
142 spin_unlock_irqrestore(&midi->input_lock, flags); 144 spin_unlock_irqrestore(&midi->input_lock, flags);
143 if (!ok) { 145 if (!ok) {
144 snd_printk(KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n", 146 dev_err(emu->card->dev,
147 "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
145 cmd, emu->port, 148 cmd, emu->port,
146 mpu401_read_stat(emu, midi), 149 mpu401_read_stat(emu, midi),
147 mpu401_read_data(emu, midi)); 150 mpu401_read_data(emu, midi));
diff --git a/sound/pci/emu10k1/emupcm.c b/sound/pci/emu10k1/emupcm.c
index 5ae1d045bdcb..f82481bd2542 100644
--- a/sound/pci/emu10k1/emupcm.c
+++ b/sound/pci/emu10k1/emupcm.c
@@ -44,7 +44,8 @@ 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(KERN_DEBUG "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n", 47 dev_dbg(emu->card->dev,
48 "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
48 epcm->substream->runtime->hw->pointer(emu, epcm->substream), 49 epcm->substream->runtime->hw->pointer(emu, epcm->substream),
49 snd_pcm_lib_period_bytes(epcm->substream), 50 snd_pcm_lib_period_bytes(epcm->substream),
50 snd_pcm_lib_buffer_bytes(epcm->substream)); 51 snd_pcm_lib_buffer_bytes(epcm->substream));
@@ -147,7 +148,7 @@ static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voic
147 &epcm->extra); 148 &epcm->extra);
148 if (err < 0) { 149 if (err < 0) {
149 /* 150 /*
150 printk(KERN_DEBUG "pcm_channel_alloc: " 151 dev_dbg(emu->card->dev, "pcm_channel_alloc: "
151 "failed extra: voices=%d, frame=%d\n", 152 "failed extra: voices=%d, frame=%d\n",
152 voices, frame); 153 voices, frame);
153 */ 154 */
@@ -761,7 +762,8 @@ static int snd_emu10k1_playback_trigger(struct snd_pcm_substream *substream,
761 int result = 0; 762 int result = 0;
762 763
763 /* 764 /*
764 printk(KERN_DEBUG "trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n", 765 dev_dbg(emu->card->dev,
766 "trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n",
765 (int)emu, cmd, substream->ops->pointer(substream)) 767 (int)emu, cmd, substream->ops->pointer(substream))
766 */ 768 */
767 spin_lock(&emu->reg_lock); 769 spin_lock(&emu->reg_lock);
@@ -815,7 +817,7 @@ static int snd_emu10k1_capture_trigger(struct snd_pcm_substream *substream,
815 outl(epcm->capture_ipr, emu->port + IPR); 817 outl(epcm->capture_ipr, emu->port + IPR);
816 snd_emu10k1_intr_enable(emu, epcm->capture_inte); 818 snd_emu10k1_intr_enable(emu, epcm->capture_inte);
817 /* 819 /*
818 printk(KERN_DEBUG "adccr = 0x%x, adcbs = 0x%x\n", 820 dev_dbg(emu->card->dev, "adccr = 0x%x, adcbs = 0x%x\n",
819 epcm->adccr, epcm->adcbs); 821 epcm->adccr, epcm->adcbs);
820 */ 822 */
821 switch (epcm->type) { 823 switch (epcm->type) {
@@ -826,7 +828,10 @@ static int snd_emu10k1_capture_trigger(struct snd_pcm_substream *substream,
826 if (emu->audigy) { 828 if (emu->audigy) {
827 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, epcm->capture_cr_val); 829 snd_emu10k1_ptr_write(emu, A_FXWC1, 0, epcm->capture_cr_val);
828 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, epcm->capture_cr_val2); 830 snd_emu10k1_ptr_write(emu, A_FXWC2, 0, epcm->capture_cr_val2);
829 snd_printdd("cr_val=0x%x, cr_val2=0x%x\n", epcm->capture_cr_val, epcm->capture_cr_val2); 831 dev_dbg(emu->card->dev,
832 "cr_val=0x%x, cr_val2=0x%x\n",
833 epcm->capture_cr_val,
834 epcm->capture_cr_val2);
830 } else 835 } else
831 snd_emu10k1_ptr_write(emu, FXWC, 0, epcm->capture_cr_val); 836 snd_emu10k1_ptr_write(emu, FXWC, 0, epcm->capture_cr_val);
832 break; 837 break;
@@ -889,7 +894,7 @@ static snd_pcm_uframes_t snd_emu10k1_playback_pointer(struct snd_pcm_substream *
889 } 894 }
890#endif 895#endif
891 /* 896 /*
892 printk(KERN_DEBUG 897 dev_dbg(emu->card->dev,
893 "ptr = 0x%lx, buffer_size = 0x%lx, period_size = 0x%lx\n", 898 "ptr = 0x%lx, buffer_size = 0x%lx, period_size = 0x%lx\n",
894 (long)ptr, (long)runtime->buffer_size, 899 (long)ptr, (long)runtime->buffer_size,
895 (long)runtime->period_size); 900 (long)runtime->period_size);
@@ -1594,7 +1599,8 @@ static void snd_emu10k1_fx8010_playback_tram_poke1(unsigned short *dst_left,
1594 unsigned int tram_shift) 1599 unsigned int tram_shift)
1595{ 1600{
1596 /* 1601 /*
1597 printk(KERN_DEBUG "tram_poke1: dst_left = 0x%p, dst_right = 0x%p, " 1602 dev_dbg(emu->card->dev,
1603 "tram_poke1: dst_left = 0x%p, dst_right = 0x%p, "
1598 "src = 0x%p, count = 0x%x\n", 1604 "src = 0x%p, count = 0x%x\n",
1599 dst_left, dst_right, src, count); 1605 dst_left, dst_right, src, count);
1600 */ 1606 */
@@ -1675,7 +1681,7 @@ static int snd_emu10k1_fx8010_playback_prepare(struct snd_pcm_substream *substre
1675 unsigned int i; 1681 unsigned int i;
1676 1682
1677 /* 1683 /*
1678 printk(KERN_DEBUG "prepare: etram_pages = 0x%p, dma_area = 0x%x, " 1684 dev_dbg(emu->card->dev, "prepare: etram_pages = 0x%p, dma_area = 0x%x, "
1679 "buffer_size = 0x%x (0x%x)\n", 1685 "buffer_size = 0x%x (0x%x)\n",
1680 emu->fx8010.etram_pages, runtime->dma_area, 1686 emu->fx8010.etram_pages, runtime->dma_area,
1681 runtime->buffer_size, runtime->buffer_size << 2); 1687 runtime->buffer_size, runtime->buffer_size << 2);
diff --git a/sound/pci/emu10k1/io.c b/sound/pci/emu10k1/io.c
index e4fba49fee4a..706b4f0c6806 100644
--- a/sound/pci/emu10k1/io.c
+++ b/sound/pci/emu10k1/io.c
@@ -71,11 +71,8 @@ void snd_emu10k1_ptr_write(struct snd_emu10k1 *emu, unsigned int reg, unsigned i
71 unsigned long flags; 71 unsigned long flags;
72 unsigned int mask; 72 unsigned int mask;
73 73
74 if (!emu) { 74 if (snd_BUG_ON(!emu))
75 snd_printk(KERN_ERR "ptr_write: emu is null!\n");
76 dump_stack();
77 return; 75 return;
78 }
79 mask = emu->audigy ? A_PTR_ADDRESS_MASK : PTR_ADDRESS_MASK; 76 mask = emu->audigy ? A_PTR_ADDRESS_MASK : PTR_ADDRESS_MASK;
80 regptr = ((reg << 16) & mask) | (chn & PTR_CHANNELNUM_MASK); 77 regptr = ((reg << 16) & mask) | (chn & PTR_CHANNELNUM_MASK);
81 78
@@ -199,7 +196,7 @@ int snd_emu10k1_i2c_write(struct snd_emu10k1 *emu,
199 int err = 0; 196 int err = 0;
200 197
201 if ((reg > 0x7f) || (value > 0x1ff)) { 198 if ((reg > 0x7f) || (value > 0x1ff)) {
202 snd_printk(KERN_ERR "i2c_write: invalid values.\n"); 199 dev_err(emu->card->dev, "i2c_write: invalid values.\n");
203 return -EINVAL; 200 return -EINVAL;
204 } 201 }
205 202
@@ -227,7 +224,7 @@ int snd_emu10k1_i2c_write(struct snd_emu10k1 *emu,
227 break; 224 break;
228 225
229 if (timeout > 1000) { 226 if (timeout > 1000) {
230 snd_printk(KERN_WARNING 227 dev_warn(emu->card->dev,
231 "emu10k1:I2C:timeout status=0x%x\n", 228 "emu10k1:I2C:timeout status=0x%x\n",
232 status); 229 status);
233 break; 230 break;
@@ -239,8 +236,8 @@ int snd_emu10k1_i2c_write(struct snd_emu10k1 *emu,
239 } 236 }
240 237
241 if (retry == 10) { 238 if (retry == 10) {
242 snd_printk(KERN_ERR "Writing to ADC failed!\n"); 239 dev_err(emu->card->dev, "Writing to ADC failed!\n");
243 snd_printk(KERN_ERR "status=0x%x, reg=%d, value=%d\n", 240 dev_err(emu->card->dev, "status=0x%x, reg=%d, value=%d\n",
244 status, reg, value); 241 status, reg, value);
245 /* dump_stack(); */ 242 /* dump_stack(); */
246 err = -EINVAL; 243 err = -EINVAL;
diff --git a/sound/pci/emu10k1/irq.c b/sound/pci/emu10k1/irq.c
index 30bfed6f8339..3c5c5e3dc2d9 100644
--- a/sound/pci/emu10k1/irq.c
+++ b/sound/pci/emu10k1/irq.c
@@ -41,11 +41,12 @@ irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id)
41 orig_status = status; 41 orig_status = status;
42 handled = 1; 42 handled = 1;
43 if ((status & 0xffffffff) == 0xffffffff) { 43 if ((status & 0xffffffff) == 0xffffffff) {
44 snd_printk(KERN_INFO "snd-emu10k1: Suspected sound card removal\n"); 44 dev_info(emu->card->dev,
45 "Suspected sound card removal\n");
45 break; 46 break;
46 } 47 }
47 if (status & IPR_PCIERROR) { 48 if (status & IPR_PCIERROR) {
48 snd_printk(KERN_ERR "interrupt: PCI error\n"); 49 dev_err(emu->card->dev, "interrupt: PCI error\n");
49 snd_emu10k1_intr_disable(emu, INTE_PCIERRORENABLE); 50 snd_emu10k1_intr_disable(emu, INTE_PCIERRORENABLE);
50 status &= ~IPR_PCIERROR; 51 status &= ~IPR_PCIERROR;
51 } 52 }
@@ -157,19 +158,22 @@ irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id)
157 struct snd_emu10k1_voice *pvoice = &(emu->p16v_voices[0]); 158 struct snd_emu10k1_voice *pvoice = &(emu->p16v_voices[0]);
158 struct snd_emu10k1_voice *cvoice = &(emu->p16v_capture_voice); 159 struct snd_emu10k1_voice *cvoice = &(emu->p16v_capture_voice);
159 160
160 //printk(KERN_INFO "status2=0x%x\n", status2); 161 /* dev_dbg(emu->card->dev, "status2=0x%x\n", status2); */
161 orig_status2 = status2; 162 orig_status2 = status2;
162 if(status2 & mask) { 163 if(status2 & mask) {
163 if(pvoice->use) { 164 if(pvoice->use) {
164 snd_pcm_period_elapsed(pvoice->epcm->substream); 165 snd_pcm_period_elapsed(pvoice->epcm->substream);
165 } else { 166 } else {
166 snd_printk(KERN_ERR "p16v: status: 0x%08x, mask=0x%08x, pvoice=%p, use=%d\n", status2, mask, pvoice, pvoice->use); 167 dev_err(emu->card->dev,
168 "p16v: status: 0x%08x, mask=0x%08x, pvoice=%p, use=%d\n",
169 status2, mask, pvoice,
170 pvoice->use);
167 } 171 }
168 } 172 }
169 if(status2 & 0x110000) { 173 if(status2 & 0x110000) {
170 //printk(KERN_INFO "capture int found\n"); 174 /* dev_info(emu->card->dev, "capture int found\n"); */
171 if(cvoice->use) { 175 if(cvoice->use) {
172 //printk(KERN_INFO "capture period_elapsed\n"); 176 /* dev_info(emu->card->dev, "capture period_elapsed\n"); */
173 snd_pcm_period_elapsed(cvoice->epcm->substream); 177 snd_pcm_period_elapsed(cvoice->epcm->substream);
174 } 178 }
175 } 179 }
@@ -180,7 +184,8 @@ irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id)
180 184
181 if (status) { 185 if (status) {
182 unsigned int bits; 186 unsigned int bits;
183 snd_printk(KERN_ERR "emu10k1: unhandled interrupt: 0x%08x\n", status); 187 dev_err(emu->card->dev,
188 "unhandled interrupt: 0x%08x\n", status);
184 //make sure any interrupts we don't handle are disabled: 189 //make sure any interrupts we don't handle are disabled:
185 bits = INTE_FXDSPENABLE | 190 bits = INTE_FXDSPENABLE |
186 INTE_PCIERRORENABLE | 191 INTE_PCIERRORENABLE |
@@ -202,7 +207,7 @@ irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id)
202 outl(orig_status, emu->port + IPR); /* ack all */ 207 outl(orig_status, emu->port + IPR); /* ack all */
203 } 208 }
204 if (timeout == 1000) 209 if (timeout == 1000)
205 snd_printk(KERN_INFO "emu10k1 irq routine failure\n"); 210 dev_info(emu->card->dev, "emu10k1 irq routine failure\n");
206 211
207 return IRQ_RETVAL(handled); 212 return IRQ_RETVAL(handled);
208} 213}
diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c
index ae709c1ab3a8..c68e6dd2fa67 100644
--- a/sound/pci/emu10k1/memory.c
+++ b/sound/pci/emu10k1/memory.c
@@ -236,11 +236,13 @@ __found_pages:
236static int is_valid_page(struct snd_emu10k1 *emu, dma_addr_t addr) 236static int is_valid_page(struct snd_emu10k1 *emu, dma_addr_t addr)
237{ 237{
238 if (addr & ~emu->dma_mask) { 238 if (addr & ~emu->dma_mask) {
239 snd_printk(KERN_ERR "max memory size is 0x%lx (addr = 0x%lx)!!\n", emu->dma_mask, (unsigned long)addr); 239 dev_err(emu->card->dev,
240 "max memory size is 0x%lx (addr = 0x%lx)!!\n",
241 emu->dma_mask, (unsigned long)addr);
240 return 0; 242 return 0;
241 } 243 }
242 if (addr & (EMUPAGESIZE-1)) { 244 if (addr & (EMUPAGESIZE-1)) {
243 snd_printk(KERN_ERR "page is not aligned\n"); 245 dev_err(emu->card->dev, "page is not aligned\n");
244 return 0; 246 return 0;
245 } 247 }
246 return 1; 248 return 1;
@@ -331,7 +333,8 @@ snd_emu10k1_alloc_pages(struct snd_emu10k1 *emu, struct snd_pcm_substream *subst
331 else 333 else
332 addr = snd_pcm_sgbuf_get_addr(substream, ofs); 334 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
333 if (! is_valid_page(emu, addr)) { 335 if (! is_valid_page(emu, addr)) {
334 printk(KERN_ERR "emu: failure page = %d\n", idx); 336 dev_err(emu->card->dev,
337 "emu: failure page = %d\n", idx);
335 mutex_unlock(&hdr->block_mutex); 338 mutex_unlock(&hdr->block_mutex);
336 return NULL; 339 return NULL;
337 } 340 }
@@ -507,7 +510,8 @@ static inline void *offset_ptr(struct snd_emu10k1 *emu, int page, int offset)
507 return NULL; 510 return NULL;
508 ptr = emu->page_ptr_table[page]; 511 ptr = emu->page_ptr_table[page];
509 if (! ptr) { 512 if (! ptr) {
510 printk(KERN_ERR "emu10k1: access to NULL ptr: page = %d\n", page); 513 dev_err(emu->card->dev,
514 "access to NULL ptr: page = %d\n", page);
511 return NULL; 515 return NULL;
512 } 516 }
513 ptr += offset & (PAGE_SIZE - 1); 517 ptr += offset & (PAGE_SIZE - 1);
diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c
index 7e2025cd6d9c..a4fe7f0c9458 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(KERN_DEBUG "epcm free: %p\n", epcm); */ 171 /* dev_dbg(emu->card->dev, "epcm free: %p\n", epcm); */
172 kfree(epcm); 172 kfree(epcm);
173 } 173 }
174} 174}
@@ -183,14 +183,14 @@ 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(KERN_DEBUG "epcm kcalloc: %p\n", epcm); */ 186 /* dev_dbg(emu->card->dev, "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 /* 192 /*
193 snd_printk(KERN_DEBUG "epcm device=%d, channel_id=%d\n", 193 dev_dbg(emu->card->dev, "epcm device=%d, channel_id=%d\n",
194 substream->pcm->device, channel_id); 194 substream->pcm->device, channel_id);
195 */ 195 */
196 runtime->private_data = epcm; 196 runtime->private_data = epcm;
@@ -203,10 +203,10 @@ static int snd_p16v_pcm_open_playback_channel(struct snd_pcm_substream *substrea
203 203
204 channel->use=1; 204 channel->use=1;
205#if 0 /* debug */ 205#if 0 /* debug */
206 snd_printk(KERN_DEBUG 206 dev_dbg(emu->card->dev,
207 "p16v: open channel_id=%d, channel=%p, use=0x%x\n", 207 "p16v: open channel_id=%d, channel=%p, use=0x%x\n",
208 channel_id, channel, channel->use); 208 channel_id, channel, channel->use);
209 printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n", 209 dev_dbg(emu->card->dev, "open:channel_id=%d, chip=%p, channel=%p\n",
210 channel_id, chip, channel); 210 channel_id, chip, channel);
211#endif /* debug */ 211#endif /* debug */
212 /* channel->interrupt = snd_p16v_pcm_channel_interrupt; */ 212 /* channel->interrupt = snd_p16v_pcm_channel_interrupt; */
@@ -231,14 +231,14 @@ static int snd_p16v_pcm_open_capture_channel(struct snd_pcm_substream *substream
231 int err; 231 int err;
232 232
233 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 233 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
234 /* snd_printk(KERN_DEBUG "epcm kcalloc: %p\n", epcm); */ 234 /* dev_dbg(emu->card->dev, "epcm kcalloc: %p\n", epcm); */
235 235
236 if (epcm == NULL) 236 if (epcm == NULL)
237 return -ENOMEM; 237 return -ENOMEM;
238 epcm->emu = emu; 238 epcm->emu = emu;
239 epcm->substream = substream; 239 epcm->substream = substream;
240 /* 240 /*
241 snd_printk(KERN_DEBUG "epcm device=%d, channel_id=%d\n", 241 dev_dbg(emu->card->dev, "epcm device=%d, channel_id=%d\n",
242 substream->pcm->device, channel_id); 242 substream->pcm->device, channel_id);
243 */ 243 */
244 runtime->private_data = epcm; 244 runtime->private_data = epcm;
@@ -251,10 +251,10 @@ static int snd_p16v_pcm_open_capture_channel(struct snd_pcm_substream *substream
251 251
252 channel->use=1; 252 channel->use=1;
253#if 0 /* debug */ 253#if 0 /* debug */
254 snd_printk(KERN_DEBUG 254 dev_dbg(emu->card->dev,
255 "p16v: open channel_id=%d, channel=%p, use=0x%x\n", 255 "p16v: open channel_id=%d, channel=%p, use=0x%x\n",
256 channel_id, channel, channel->use); 256 channel_id, channel, channel->use);
257 printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n", 257 dev_dbg(emu->card->dev, "open:channel_id=%d, chip=%p, channel=%p\n",
258 channel_id, chip, channel); 258 channel_id, chip, channel);
259#endif /* debug */ 259#endif /* debug */
260 /* channel->interrupt = snd_p16v_pcm_channel_interrupt; */ 260 /* channel->interrupt = snd_p16v_pcm_channel_interrupt; */
@@ -349,15 +349,18 @@ static int snd_p16v_pcm_prepare_playback(struct snd_pcm_substream *substream)
349 u32 tmp; 349 u32 tmp;
350 350
351#if 0 /* debug */ 351#if 0 /* debug */
352 snd_printk(KERN_DEBUG "prepare:channel_number=%d, rate=%d, " 352 dev_dbg(emu->card->dev,
353 "prepare:channel_number=%d, rate=%d, "
353 "format=0x%x, channels=%d, buffer_size=%ld, " 354 "format=0x%x, channels=%d, buffer_size=%ld, "
354 "period_size=%ld, periods=%u, frames_to_bytes=%d\n", 355 "period_size=%ld, periods=%u, frames_to_bytes=%d\n",
355 channel, runtime->rate, runtime->format, runtime->channels, 356 channel, runtime->rate, runtime->format, runtime->channels,
356 runtime->buffer_size, runtime->period_size, 357 runtime->buffer_size, runtime->period_size,
357 runtime->periods, frames_to_bytes(runtime, 1)); 358 runtime->periods, frames_to_bytes(runtime, 1));
358 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, table_base=%p\n", 359 dev_dbg(emu->card->dev,
360 "dma_addr=%x, dma_area=%p, table_base=%p\n",
359 runtime->dma_addr, runtime->dma_area, table_base); 361 runtime->dma_addr, runtime->dma_area, table_base);
360 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n", 362 dev_dbg(emu->card->dev,
363 "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",
361 emu->p16v_buffer.addr, emu->p16v_buffer.area, 364 emu->p16v_buffer.addr, emu->p16v_buffer.area,
362 emu->p16v_buffer.bytes); 365 emu->p16v_buffer.bytes);
363#endif /* debug */ 366#endif /* debug */
@@ -405,7 +408,7 @@ static int snd_p16v_pcm_prepare_capture(struct snd_pcm_substream *substream)
405 u32 tmp; 408 u32 tmp;
406 409
407 /* 410 /*
408 printk(KERN_DEBUG "prepare capture:channel_number=%d, rate=%d, " 411 dev_dbg(emu->card->dev, "prepare capture:channel_number=%d, rate=%d, "
409 "format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, " 412 "format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, "
410 "frames_to_bytes=%d\n", 413 "frames_to_bytes=%d\n",
411 channel, runtime->rate, runtime->format, runtime->channels, 414 channel, runtime->rate, runtime->format, runtime->channels,
@@ -491,13 +494,13 @@ static int snd_p16v_pcm_trigger_playback(struct snd_pcm_substream *substream,
491 runtime = s->runtime; 494 runtime = s->runtime;
492 epcm = runtime->private_data; 495 epcm = runtime->private_data;
493 channel = substream->pcm->device-emu->p16v_device_offset; 496 channel = substream->pcm->device-emu->p16v_device_offset;
494 /* snd_printk(KERN_DEBUG "p16v channel=%d\n", channel); */ 497 /* dev_dbg(emu->card->dev, "p16v channel=%d\n", channel); */
495 epcm->running = running; 498 epcm->running = running;
496 basic |= (0x1<<channel); 499 basic |= (0x1<<channel);
497 inte |= (INTE2_PLAYBACK_CH_0_LOOP<<channel); 500 inte |= (INTE2_PLAYBACK_CH_0_LOOP<<channel);
498 snd_pcm_trigger_done(s, substream); 501 snd_pcm_trigger_done(s, substream);
499 } 502 }
500 /* snd_printk(KERN_DEBUG "basic=0x%x, inte=0x%x\n", basic, inte); */ 503 /* dev_dbg(emu->card->dev, "basic=0x%x, inte=0x%x\n", basic, inte); */
501 504
502 switch (cmd) { 505 switch (cmd) {
503 case SNDRV_PCM_TRIGGER_START: 506 case SNDRV_PCM_TRIGGER_START:
@@ -588,10 +591,10 @@ snd_p16v_pcm_pointer_capture(struct snd_pcm_substream *substream)
588 ptr=ptr2; 591 ptr=ptr2;
589 if (ptr >= runtime->buffer_size) { 592 if (ptr >= runtime->buffer_size) {
590 ptr -= runtime->buffer_size; 593 ptr -= runtime->buffer_size;
591 printk(KERN_WARNING "buffer capture limited!\n"); 594 dev_warn(emu->card->dev, "buffer capture limited!\n");
592 } 595 }
593 /* 596 /*
594 printk(KERN_DEBUG "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, " 597 dev_dbg(emu->card->dev, "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, "
595 "buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", 598 "buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n",
596 ptr1, ptr2, ptr, (int)runtime->buffer_size, 599 ptr1, ptr2, ptr, (int)runtime->buffer_size,
597 (int)runtime->period_size, (int)runtime->frame_bits, 600 (int)runtime->period_size, (int)runtime->frame_bits,
@@ -630,7 +633,7 @@ int snd_p16v_free(struct snd_emu10k1 *chip)
630 if (chip->p16v_buffer.area) { 633 if (chip->p16v_buffer.area) {
631 snd_dma_free_pages(&chip->p16v_buffer); 634 snd_dma_free_pages(&chip->p16v_buffer);
632 /* 635 /*
633 snd_printk(KERN_DEBUG "period lables free: %p\n", 636 dev_dbg(chip->card->dev, "period lables free: %p\n",
634 &chip->p16v_buffer); 637 &chip->p16v_buffer);
635 */ 638 */
636 } 639 }
@@ -644,7 +647,7 @@ int snd_p16v_pcm(struct snd_emu10k1 *emu, int device, struct snd_pcm **rpcm)
644 int err; 647 int err;
645 int capture=1; 648 int capture=1;
646 649
647 /* snd_printk(KERN_DEBUG "snd_p16v_pcm called. device=%d\n", device); */ 650 /* dev_dbg(emu->card->dev, "snd_p16v_pcm called. device=%d\n", device); */
648 emu->p16v_device_offset = device; 651 emu->p16v_device_offset = device;
649 if (rpcm) 652 if (rpcm)
650 *rpcm = NULL; 653 *rpcm = NULL;
@@ -672,7 +675,7 @@ int snd_p16v_pcm(struct snd_emu10k1 *emu, int device, struct snd_pcm **rpcm)
672 ((65536 - 64) * 8), ((65536 - 64) * 8))) < 0) 675 ((65536 - 64) * 8), ((65536 - 64) * 8))) < 0)
673 return err; 676 return err;
674 /* 677 /*
675 snd_printk(KERN_DEBUG 678 dev_dbg(emu->card->dev,
676 "preallocate playback substream: err=%d\n", err); 679 "preallocate playback substream: err=%d\n", err);
677 */ 680 */
678 } 681 }
@@ -686,7 +689,7 @@ int snd_p16v_pcm(struct snd_emu10k1 *emu, int device, struct snd_pcm **rpcm)
686 65536 - 64, 65536 - 64)) < 0) 689 65536 - 64, 65536 - 64)) < 0)
687 return err; 690 return err;
688 /* 691 /*
689 snd_printk(KERN_DEBUG 692 dev_dbg(emu->card->dev,
690 "preallocate capture substream: err=%d\n", err); 693 "preallocate capture substream: err=%d\n", err);
691 */ 694 */
692 } 695 }
diff --git a/sound/pci/emu10k1/voice.c b/sound/pci/emu10k1/voice.c
index 101e7cb79cb2..f16fd5cfb7cd 100644
--- a/sound/pci/emu10k1/voice.c
+++ b/sound/pci/emu10k1/voice.c
@@ -55,7 +55,7 @@ static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
55 first_voice = last_voice = 0; 55 first_voice = last_voice = 0;
56 for (i = emu->next_free_voice, j = 0; j < NUM_G ; i += number, j += number) { 56 for (i = emu->next_free_voice, j = 0; j < NUM_G ; i += number, j += number) {
57 /* 57 /*
58 printk(KERN_DEBUG "i %d j %d next free %d!\n", 58 dev_dbg(emu->card->dev, "i %d j %d next free %d!\n",
59 i, j, emu->next_free_voice); 59 i, j, emu->next_free_voice);
60 */ 60 */
61 i %= NUM_G; 61 i %= NUM_G;
@@ -75,7 +75,7 @@ static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
75 } 75 }
76 } 76 }
77 if (!skip) { 77 if (!skip) {
78 /* printk(KERN_DEBUG "allocated voice %d\n", i); */ 78 /* dev_dbg(emu->card->dev, "allocated voice %d\n", i); */
79 first_voice = i; 79 first_voice = i;
80 last_voice = (i + number) % NUM_G; 80 last_voice = (i + number) % NUM_G;
81 emu->next_free_voice = last_voice; 81 emu->next_free_voice = last_voice;
@@ -89,7 +89,7 @@ static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
89 for (i = 0; i < number; i++) { 89 for (i = 0; i < number; i++) {
90 voice = &emu->voices[(first_voice + i) % NUM_G]; 90 voice = &emu->voices[(first_voice + i) % NUM_G];
91 /* 91 /*
92 printk(kERN_DEBUG "voice alloc - %i, %i of %i\n", 92 dev_dbg(emu->card->dev, "voice alloc - %i, %i of %i\n",
93 voice->number, idx-first_voice+1, number); 93 voice->number, idx-first_voice+1, number);
94 */ 94 */
95 voice->use = 1; 95 voice->use = 1;
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index 61262f396004..29cd339ffc37 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -525,7 +525,7 @@ static unsigned int snd_es1371_wait_src_ready(struct ensoniq * ensoniq)
525 return r; 525 return r;
526 cond_resched(); 526 cond_resched();
527 } 527 }
528 snd_printk(KERN_ERR "wait src ready timeout 0x%lx [0x%x]\n", 528 dev_err(ensoniq->card->dev, "wait src ready timeout 0x%lx [0x%x]\n",
529 ES_REG(ensoniq, 1371_SMPRATE), r); 529 ES_REG(ensoniq, 1371_SMPRATE), r);
530 return 0; 530 return 0;
531} 531}
@@ -587,7 +587,7 @@ static void snd_es1370_codec_write(struct snd_ak4531 *ak4531,
587 unsigned long end_time = jiffies + HZ / 10; 587 unsigned long end_time = jiffies + HZ / 10;
588 588
589#if 0 589#if 0
590 printk(KERN_DEBUG 590 dev_dbg(ensoniq->card->dev,
591 "CODEC WRITE: reg = 0x%x, val = 0x%x (0x%x), creg = 0x%x\n", 591 "CODEC WRITE: reg = 0x%x, val = 0x%x (0x%x), creg = 0x%x\n",
592 reg, val, ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC)); 592 reg, val, ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC));
593#endif 593#endif
@@ -598,7 +598,7 @@ static void snd_es1370_codec_write(struct snd_ak4531 *ak4531,
598 } 598 }
599 schedule_timeout_uninterruptible(1); 599 schedule_timeout_uninterruptible(1);
600 } while (time_after(end_time, jiffies)); 600 } while (time_after(end_time, jiffies));
601 snd_printk(KERN_ERR "codec write timeout, status = 0x%x\n", 601 dev_err(ensoniq->card->dev, "codec write timeout, status = 0x%x\n",
602 inl(ES_REG(ensoniq, STATUS))); 602 inl(ES_REG(ensoniq, STATUS)));
603} 603}
604 604
@@ -649,7 +649,7 @@ static void snd_es1371_codec_write(struct snd_ac97 *ac97,
649 } 649 }
650 } 650 }
651 mutex_unlock(&ensoniq->src_mutex); 651 mutex_unlock(&ensoniq->src_mutex);
652 snd_printk(KERN_ERR "codec write timeout at 0x%lx [0x%x]\n", 652 dev_err(ensoniq->card->dev, "codec write timeout at 0x%lx [0x%x]\n",
653 ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC))); 653 ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
654} 654}
655 655
@@ -706,8 +706,8 @@ static unsigned short snd_es1371_codec_read(struct snd_ac97 *ac97,
706 } 706 }
707 mutex_unlock(&ensoniq->src_mutex); 707 mutex_unlock(&ensoniq->src_mutex);
708 if (++fail > 10) { 708 if (++fail > 10) {
709 snd_printk(KERN_ERR "codec read timeout (final) " 709 dev_err(ensoniq->card->dev,
710 "at 0x%lx, reg = 0x%x [0x%x]\n", 710 "codec read timeout (final) at 0x%lx, reg = 0x%x [0x%x]\n",
711 ES_REG(ensoniq, 1371_CODEC), reg, 711 ES_REG(ensoniq, 1371_CODEC), reg,
712 inl(ES_REG(ensoniq, 1371_CODEC))); 712 inl(ES_REG(ensoniq, 1371_CODEC)));
713 return 0; 713 return 0;
@@ -716,7 +716,7 @@ static unsigned short snd_es1371_codec_read(struct snd_ac97 *ac97,
716 } 716 }
717 } 717 }
718 mutex_unlock(&ensoniq->src_mutex); 718 mutex_unlock(&ensoniq->src_mutex);
719 snd_printk(KERN_ERR "es1371: codec read timeout at 0x%lx [0x%x]\n", 719 dev_err(ensoniq->card->dev, "codec read timeout at 0x%lx [0x%x]\n",
720 ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC))); 720 ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
721 return 0; 721 return 0;
722} 722}
@@ -1796,7 +1796,7 @@ static int snd_ensoniq_1370_mixer(struct ensoniq *ensoniq)
1796#ifdef SUPPORT_JOYSTICK 1796#ifdef SUPPORT_JOYSTICK
1797 1797
1798#ifdef CHIP1371 1798#ifdef CHIP1371
1799static int snd_ensoniq_get_joystick_port(int dev) 1799static int snd_ensoniq_get_joystick_port(struct ensoniq *ensoniq, int dev)
1800{ 1800{
1801 switch (joystick_port[dev]) { 1801 switch (joystick_port[dev]) {
1802 case 0: /* disabled */ 1802 case 0: /* disabled */
@@ -1808,12 +1808,13 @@ static int snd_ensoniq_get_joystick_port(int dev)
1808 return joystick_port[dev]; 1808 return joystick_port[dev];
1809 1809
1810 default: 1810 default:
1811 printk(KERN_ERR "ens1371: invalid joystick port %#x", joystick_port[dev]); 1811 dev_err(ensoniq->card->dev,
1812 "invalid joystick port %#x", joystick_port[dev]);
1812 return 0; 1813 return 0;
1813 } 1814 }
1814} 1815}
1815#else 1816#else
1816static inline int snd_ensoniq_get_joystick_port(int dev) 1817static int snd_ensoniq_get_joystick_port(struct ensoniq *ensoniq, int dev)
1817{ 1818{
1818 return joystick[dev] ? 0x200 : 0; 1819 return joystick[dev] ? 0x200 : 0;
1819} 1820}
@@ -1824,7 +1825,7 @@ static int snd_ensoniq_create_gameport(struct ensoniq *ensoniq, int dev)
1824 struct gameport *gp; 1825 struct gameport *gp;
1825 int io_port; 1826 int io_port;
1826 1827
1827 io_port = snd_ensoniq_get_joystick_port(dev); 1828 io_port = snd_ensoniq_get_joystick_port(ensoniq, dev);
1828 1829
1829 switch (io_port) { 1830 switch (io_port) {
1830 case 0: 1831 case 0:
@@ -1835,14 +1836,16 @@ static int snd_ensoniq_create_gameport(struct ensoniq *ensoniq, int dev)
1835 if (request_region(io_port, 8, "ens137x: gameport")) 1836 if (request_region(io_port, 8, "ens137x: gameport"))
1836 break; 1837 break;
1837 if (io_port > 0x218) { 1838 if (io_port > 0x218) {
1838 printk(KERN_WARNING "ens137x: no gameport ports available\n"); 1839 dev_warn(ensoniq->card->dev,
1840 "no gameport ports available\n");
1839 return -EBUSY; 1841 return -EBUSY;
1840 } 1842 }
1841 break; 1843 break;
1842 1844
1843 default: 1845 default:
1844 if (!request_region(io_port, 8, "ens137x: gameport")) { 1846 if (!request_region(io_port, 8, "ens137x: gameport")) {
1845 printk(KERN_WARNING "ens137x: gameport io port %#x in use\n", 1847 dev_warn(ensoniq->card->dev,
1848 "gameport io port %#x in use\n",
1846 io_port); 1849 io_port);
1847 return -EBUSY; 1850 return -EBUSY;
1848 } 1851 }
@@ -1851,7 +1854,8 @@ static int snd_ensoniq_create_gameport(struct ensoniq *ensoniq, int dev)
1851 1854
1852 ensoniq->gameport = gp = gameport_allocate_port(); 1855 ensoniq->gameport = gp = gameport_allocate_port();
1853 if (!gp) { 1856 if (!gp) {
1854 printk(KERN_ERR "ens137x: cannot allocate memory for gameport\n"); 1857 dev_err(ensoniq->card->dev,
1858 "cannot allocate memory for gameport\n");
1855 release_region(io_port, 8); 1859 release_region(io_port, 8);
1856 return -ENOMEM; 1860 return -ENOMEM;
1857 } 1861 }
@@ -2082,8 +2086,7 @@ static int snd_ensoniq_resume(struct device *dev)
2082 pci_set_power_state(pci, PCI_D0); 2086 pci_set_power_state(pci, PCI_D0);
2083 pci_restore_state(pci); 2087 pci_restore_state(pci);
2084 if (pci_enable_device(pci) < 0) { 2088 if (pci_enable_device(pci) < 0) {
2085 printk(KERN_ERR DRIVER_NAME ": pci_enable_device failed, " 2089 dev_err(dev, "pci_enable_device failed, disabling device\n");
2086 "disabling device\n");
2087 snd_card_disconnect(card); 2090 snd_card_disconnect(card);
2088 return -EIO; 2091 return -EIO;
2089 } 2092 }
@@ -2137,7 +2140,7 @@ static int snd_ensoniq_create(struct snd_card *card,
2137 ensoniq->port = pci_resource_start(pci, 0); 2140 ensoniq->port = pci_resource_start(pci, 0);
2138 if (request_irq(pci->irq, snd_audiopci_interrupt, IRQF_SHARED, 2141 if (request_irq(pci->irq, snd_audiopci_interrupt, IRQF_SHARED,
2139 KBUILD_MODNAME, ensoniq)) { 2142 KBUILD_MODNAME, ensoniq)) {
2140 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 2143 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
2141 snd_ensoniq_free(ensoniq); 2144 snd_ensoniq_free(ensoniq);
2142 return -EBUSY; 2145 return -EBUSY;
2143 } 2146 }
@@ -2145,7 +2148,7 @@ static int snd_ensoniq_create(struct snd_card *card,
2145#ifdef CHIP1370 2148#ifdef CHIP1370
2146 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 2149 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
2147 16, &ensoniq->dma_bug) < 0) { 2150 16, &ensoniq->dma_bug) < 0) {
2148 snd_printk(KERN_ERR "unable to allocate space for phantom area - dma_bug\n"); 2151 dev_err(card->dev, "unable to allocate space for phantom area - dma_bug\n");
2149 snd_ensoniq_free(ensoniq); 2152 snd_ensoniq_free(ensoniq);
2150 return -EBUSY; 2153 return -EBUSY;
2151 } 2154 }
@@ -2180,8 +2183,6 @@ static int snd_ensoniq_create(struct snd_card *card,
2180 2183
2181 snd_ensoniq_proc_init(ensoniq); 2184 snd_ensoniq_proc_init(ensoniq);
2182 2185
2183 snd_card_set_dev(card, &pci->dev);
2184
2185 *rensoniq = ensoniq; 2186 *rensoniq = ensoniq;
2186 return 0; 2187 return 0;
2187} 2188}
@@ -2437,7 +2438,8 @@ static int snd_audiopci_probe(struct pci_dev *pci,
2437 return -ENOENT; 2438 return -ENOENT;
2438 } 2439 }
2439 2440
2440 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2441 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2442 0, &card);
2441 if (err < 0) 2443 if (err < 0)
2442 return err; 2444 return err;
2443 2445
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 9213fb38921c..34d95bf916b5 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -254,7 +254,6 @@ MODULE_DEVICE_TABLE(pci, snd_es1938_ids);
254#define WRITE_LOOP_TIMEOUT 0x10000 254#define WRITE_LOOP_TIMEOUT 0x10000
255#define GET_LOOP_TIMEOUT 0x01000 255#define GET_LOOP_TIMEOUT 0x01000
256 256
257#undef REG_DEBUG
258/* ----------------------------------------------------------------- 257/* -----------------------------------------------------------------
259 * Write to a mixer register 258 * Write to a mixer register
260 * -----------------------------------------------------------------*/ 259 * -----------------------------------------------------------------*/
@@ -265,9 +264,7 @@ static void snd_es1938_mixer_write(struct es1938 *chip, unsigned char reg, unsig
265 outb(reg, SLSB_REG(chip, MIXERADDR)); 264 outb(reg, SLSB_REG(chip, MIXERADDR));
266 outb(val, SLSB_REG(chip, MIXERDATA)); 265 outb(val, SLSB_REG(chip, MIXERDATA));
267 spin_unlock_irqrestore(&chip->mixer_lock, flags); 266 spin_unlock_irqrestore(&chip->mixer_lock, flags);
268#ifdef REG_DEBUG 267 dev_dbg(chip->card->dev, "Mixer reg %02x set to %02x\n", reg, val);
269 snd_printk(KERN_DEBUG "Mixer reg %02x set to %02x\n", reg, val);
270#endif
271} 268}
272 269
273/* ----------------------------------------------------------------- 270/* -----------------------------------------------------------------
@@ -281,9 +278,7 @@ static int snd_es1938_mixer_read(struct es1938 *chip, unsigned char reg)
281 outb(reg, SLSB_REG(chip, MIXERADDR)); 278 outb(reg, SLSB_REG(chip, MIXERADDR));
282 data = inb(SLSB_REG(chip, MIXERDATA)); 279 data = inb(SLSB_REG(chip, MIXERDATA));
283 spin_unlock_irqrestore(&chip->mixer_lock, flags); 280 spin_unlock_irqrestore(&chip->mixer_lock, flags);
284#ifdef REG_DEBUG 281 dev_dbg(chip->card->dev, "Mixer reg %02x now is %02x\n", reg, data);
285 snd_printk(KERN_DEBUG "Mixer reg %02x now is %02x\n", reg, data);
286#endif
287 return data; 282 return data;
288} 283}
289 284
@@ -302,10 +297,9 @@ static int snd_es1938_mixer_bits(struct es1938 *chip, unsigned char reg,
302 if (val != oval) { 297 if (val != oval) {
303 new = (old & ~mask) | (val & mask); 298 new = (old & ~mask) | (val & mask);
304 outb(new, SLSB_REG(chip, MIXERDATA)); 299 outb(new, SLSB_REG(chip, MIXERDATA));
305#ifdef REG_DEBUG 300 dev_dbg(chip->card->dev,
306 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x\n", 301 "Mixer reg %02x was %02x, set to %02x\n",
307 reg, old, new); 302 reg, old, new);
308#endif
309 } 303 }
310 spin_unlock_irqrestore(&chip->mixer_lock, flags); 304 spin_unlock_irqrestore(&chip->mixer_lock, flags);
311 return oval; 305 return oval;
@@ -324,7 +318,8 @@ static void snd_es1938_write_cmd(struct es1938 *chip, unsigned char cmd)
324 return; 318 return;
325 } 319 }
326 } 320 }
327 printk(KERN_ERR "snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v); 321 dev_err(chip->card->dev,
322 "snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v);
328} 323}
329 324
330/* ----------------------------------------------------------------- 325/* -----------------------------------------------------------------
@@ -337,7 +332,7 @@ static int snd_es1938_get_byte(struct es1938 *chip)
337 for (i = GET_LOOP_TIMEOUT; i; i--) 332 for (i = GET_LOOP_TIMEOUT; i; i--)
338 if ((v = inb(SLSB_REG(chip, STATUS))) & 0x80) 333 if ((v = inb(SLSB_REG(chip, STATUS))) & 0x80)
339 return inb(SLSB_REG(chip, READDATA)); 334 return inb(SLSB_REG(chip, READDATA));
340 snd_printk(KERN_ERR "get_byte timeout: status 0x02%x\n", v); 335 dev_err(chip->card->dev, "get_byte timeout: status 0x02%x\n", v);
341 return -ENODEV; 336 return -ENODEV;
342} 337}
343 338
@@ -351,9 +346,7 @@ static void snd_es1938_write(struct es1938 *chip, unsigned char reg, unsigned ch
351 snd_es1938_write_cmd(chip, reg); 346 snd_es1938_write_cmd(chip, reg);
352 snd_es1938_write_cmd(chip, val); 347 snd_es1938_write_cmd(chip, val);
353 spin_unlock_irqrestore(&chip->reg_lock, flags); 348 spin_unlock_irqrestore(&chip->reg_lock, flags);
354#ifdef REG_DEBUG 349 dev_dbg(chip->card->dev, "Reg %02x set to %02x\n", reg, val);
355 snd_printk(KERN_DEBUG "Reg %02x set to %02x\n", reg, val);
356#endif
357} 350}
358 351
359/* ----------------------------------------------------------------- 352/* -----------------------------------------------------------------
@@ -368,9 +361,7 @@ static unsigned char snd_es1938_read(struct es1938 *chip, unsigned char reg)
368 snd_es1938_write_cmd(chip, reg); 361 snd_es1938_write_cmd(chip, reg);
369 val = snd_es1938_get_byte(chip); 362 val = snd_es1938_get_byte(chip);
370 spin_unlock_irqrestore(&chip->reg_lock, flags); 363 spin_unlock_irqrestore(&chip->reg_lock, flags);
371#ifdef REG_DEBUG 364 dev_dbg(chip->card->dev, "Reg %02x now is %02x\n", reg, val);
372 snd_printk(KERN_DEBUG "Reg %02x now is %02x\n", reg, val);
373#endif
374 return val; 365 return val;
375} 366}
376 367
@@ -391,10 +382,8 @@ static int snd_es1938_bits(struct es1938 *chip, unsigned char reg, unsigned char
391 snd_es1938_write_cmd(chip, reg); 382 snd_es1938_write_cmd(chip, reg);
392 new = (old & ~mask) | (val & mask); 383 new = (old & ~mask) | (val & mask);
393 snd_es1938_write_cmd(chip, new); 384 snd_es1938_write_cmd(chip, new);
394#ifdef REG_DEBUG 385 dev_dbg(chip->card->dev, "Reg %02x was %02x, set to %02x\n",
395 snd_printk(KERN_DEBUG "Reg %02x was %02x, set to %02x\n",
396 reg, old, new); 386 reg, old, new);
397#endif
398 } 387 }
399 spin_unlock_irqrestore(&chip->reg_lock, flags); 388 spin_unlock_irqrestore(&chip->reg_lock, flags);
400 return oval; 389 return oval;
@@ -416,7 +405,7 @@ static void snd_es1938_reset(struct es1938 *chip)
416 goto __next; 405 goto __next;
417 } 406 }
418 } 407 }
419 snd_printk(KERN_ERR "ESS Solo-1 reset failed\n"); 408 dev_err(chip->card->dev, "ESS Solo-1 reset failed\n");
420 409
421 __next: 410 __next:
422 snd_es1938_write_cmd(chip, ESS_CMD_ENABLEEXT); 411 snd_es1938_write_cmd(chip, ESS_CMD_ENABLEEXT);
@@ -1504,16 +1493,15 @@ static int es1938_resume(struct device *dev)
1504 pci_set_power_state(pci, PCI_D0); 1493 pci_set_power_state(pci, PCI_D0);
1505 pci_restore_state(pci); 1494 pci_restore_state(pci);
1506 if (pci_enable_device(pci) < 0) { 1495 if (pci_enable_device(pci) < 0) {
1507 printk(KERN_ERR "es1938: pci_enable_device failed, " 1496 dev_err(dev, "pci_enable_device failed, disabling device\n");
1508 "disabling device\n");
1509 snd_card_disconnect(card); 1497 snd_card_disconnect(card);
1510 return -EIO; 1498 return -EIO;
1511 } 1499 }
1512 1500
1513 if (request_irq(pci->irq, snd_es1938_interrupt, 1501 if (request_irq(pci->irq, snd_es1938_interrupt,
1514 IRQF_SHARED, KBUILD_MODNAME, chip)) { 1502 IRQF_SHARED, KBUILD_MODNAME, chip)) {
1515 printk(KERN_ERR "es1938: unable to grab IRQ %d, " 1503 dev_err(dev, "unable to grab IRQ %d, disabling device\n",
1516 "disabling device\n", pci->irq); 1504 pci->irq);
1517 snd_card_disconnect(card); 1505 snd_card_disconnect(card);
1518 return -EIO; 1506 return -EIO;
1519 } 1507 }
@@ -1545,7 +1533,8 @@ static int snd_es1938_create_gameport(struct es1938 *chip)
1545 1533
1546 chip->gameport = gp = gameport_allocate_port(); 1534 chip->gameport = gp = gameport_allocate_port();
1547 if (!gp) { 1535 if (!gp) {
1548 printk(KERN_ERR "es1938: cannot allocate memory for gameport\n"); 1536 dev_err(chip->card->dev,
1537 "cannot allocate memory for gameport\n");
1549 return -ENOMEM; 1538 return -ENOMEM;
1550 } 1539 }
1551 1540
@@ -1612,7 +1601,8 @@ static int snd_es1938_create(struct snd_card *card,
1612 /* check, if we can restrict PCI DMA transfers to 24 bits */ 1601 /* check, if we can restrict PCI DMA transfers to 24 bits */
1613 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 || 1602 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 ||
1614 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) { 1603 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) {
1615 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n"); 1604 dev_err(card->dev,
1605 "architecture does not support 24bit PCI busmaster DMA\n");
1616 pci_disable_device(pci); 1606 pci_disable_device(pci);
1617 return -ENXIO; 1607 return -ENXIO;
1618 } 1608 }
@@ -1639,15 +1629,14 @@ static int snd_es1938_create(struct snd_card *card,
1639 chip->game_port = pci_resource_start(pci, 4); 1629 chip->game_port = pci_resource_start(pci, 4);
1640 if (request_irq(pci->irq, snd_es1938_interrupt, IRQF_SHARED, 1630 if (request_irq(pci->irq, snd_es1938_interrupt, IRQF_SHARED,
1641 KBUILD_MODNAME, chip)) { 1631 KBUILD_MODNAME, chip)) {
1642 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1632 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1643 snd_es1938_free(chip); 1633 snd_es1938_free(chip);
1644 return -EBUSY; 1634 return -EBUSY;
1645 } 1635 }
1646 chip->irq = pci->irq; 1636 chip->irq = pci->irq;
1647#ifdef ES1938_DDEBUG 1637 dev_dbg(card->dev,
1648 snd_printk(KERN_DEBUG "create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n", 1638 "create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n",
1649 chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port); 1639 chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port);
1650#endif
1651 1640
1652 chip->ddma_port = chip->vc_port + 0x00; /* fix from Thomas Sailer */ 1641 chip->ddma_port = chip->vc_port + 0x00; /* fix from Thomas Sailer */
1653 1642
@@ -1658,8 +1647,6 @@ static int snd_es1938_create(struct snd_card *card,
1658 return err; 1647 return err;
1659 } 1648 }
1660 1649
1661 snd_card_set_dev(card, &pci->dev);
1662
1663 *rchip = chip; 1650 *rchip = chip;
1664 return 0; 1651 return 0;
1665} 1652}
@@ -1675,21 +1662,22 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id)
1675 1662
1676 status = inb(SLIO_REG(chip, IRQCONTROL)); 1663 status = inb(SLIO_REG(chip, IRQCONTROL));
1677#if 0 1664#if 0
1678 printk(KERN_DEBUG "Es1938debug - interrupt status: =0x%x\n", status); 1665 dev_dbg(chip->card->dev,
1666 "Es1938debug - interrupt status: =0x%x\n", status);
1679#endif 1667#endif
1680 1668
1681 /* AUDIO 1 */ 1669 /* AUDIO 1 */
1682 if (status & 0x10) { 1670 if (status & 0x10) {
1683#if 0 1671#if 0
1684 printk(KERN_DEBUG 1672 dev_dbg(chip->card->dev,
1685 "Es1938debug - AUDIO channel 1 interrupt\n"); 1673 "Es1938debug - AUDIO channel 1 interrupt\n");
1686 printk(KERN_DEBUG 1674 dev_dbg(chip->card->dev,
1687 "Es1938debug - AUDIO channel 1 DMAC DMA count: %u\n", 1675 "Es1938debug - AUDIO channel 1 DMAC DMA count: %u\n",
1688 inw(SLDM_REG(chip, DMACOUNT))); 1676 inw(SLDM_REG(chip, DMACOUNT)));
1689 printk(KERN_DEBUG 1677 dev_dbg(chip->card->dev,
1690 "Es1938debug - AUDIO channel 1 DMAC DMA base: %u\n", 1678 "Es1938debug - AUDIO channel 1 DMAC DMA base: %u\n",
1691 inl(SLDM_REG(chip, DMAADDR))); 1679 inl(SLDM_REG(chip, DMAADDR)));
1692 printk(KERN_DEBUG 1680 dev_dbg(chip->card->dev,
1693 "Es1938debug - AUDIO channel 1 DMAC DMA status: 0x%x\n", 1681 "Es1938debug - AUDIO channel 1 DMAC DMA status: 0x%x\n",
1694 inl(SLDM_REG(chip, DMASTATUS))); 1682 inl(SLDM_REG(chip, DMASTATUS)));
1695#endif 1683#endif
@@ -1705,12 +1693,12 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id)
1705 /* AUDIO 2 */ 1693 /* AUDIO 2 */
1706 if (status & 0x20) { 1694 if (status & 0x20) {
1707#if 0 1695#if 0
1708 printk(KERN_DEBUG 1696 dev_dbg(chip->card->dev,
1709 "Es1938debug - AUDIO channel 2 interrupt\n"); 1697 "Es1938debug - AUDIO channel 2 interrupt\n");
1710 printk(KERN_DEBUG 1698 dev_dbg(chip->card->dev,
1711 "Es1938debug - AUDIO channel 2 DMAC DMA count: %u\n", 1699 "Es1938debug - AUDIO channel 2 DMAC DMA count: %u\n",
1712 inw(SLIO_REG(chip, AUDIO2DMACOUNT))); 1700 inw(SLIO_REG(chip, AUDIO2DMACOUNT)));
1713 printk(KERN_DEBUG 1701 dev_dbg(chip->card->dev,
1714 "Es1938debug - AUDIO channel 2 DMAC DMA base: %u\n", 1702 "Es1938debug - AUDIO channel 2 DMAC DMA base: %u\n",
1715 inl(SLIO_REG(chip, AUDIO2DMAADDR))); 1703 inl(SLIO_REG(chip, AUDIO2DMAADDR)));
1716 1704
@@ -1808,7 +1796,8 @@ static int snd_es1938_probe(struct pci_dev *pci,
1808 return -ENOENT; 1796 return -ENOENT;
1809 } 1797 }
1810 1798
1811 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1799 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1800 0, &card);
1812 if (err < 0) 1801 if (err < 0)
1813 return err; 1802 return err;
1814 for (idx = 0; idx < 5; idx++) { 1803 for (idx = 0; idx < 5; idx++) {
@@ -1843,7 +1832,7 @@ static int snd_es1938_probe(struct pci_dev *pci,
1843 SLSB_REG(chip, FMLOWADDR), 1832 SLSB_REG(chip, FMLOWADDR),
1844 SLSB_REG(chip, FMHIGHADDR), 1833 SLSB_REG(chip, FMHIGHADDR),
1845 OPL3_HW_OPL3, 1, &opl3) < 0) { 1834 OPL3_HW_OPL3, 1, &opl3) < 0) {
1846 printk(KERN_ERR "es1938: OPL3 not detected at 0x%lx\n", 1835 dev_err(card->dev, "OPL3 not detected at 0x%lx\n",
1847 SLSB_REG(chip, FMLOWADDR)); 1836 SLSB_REG(chip, FMLOWADDR));
1848 } else { 1837 } else {
1849 if ((err = snd_opl3_timer_new(opl3, 0, 1)) < 0) { 1838 if ((err = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
@@ -1859,7 +1848,7 @@ static int snd_es1938_probe(struct pci_dev *pci,
1859 chip->mpu_port, 1848 chip->mpu_port,
1860 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, 1849 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
1861 -1, &chip->rmidi) < 0) { 1850 -1, &chip->rmidi) < 0) {
1862 printk(KERN_ERR "es1938: unable to initialize MPU-401\n"); 1851 dev_err(card->dev, "unable to initialize MPU-401\n");
1863 } else { 1852 } else {
1864 // this line is vital for MIDI interrupt handling on ess-solo1 1853 // this line is vital for MIDI interrupt handling on ess-solo1
1865 // andreas@flying-snail.de 1854 // andreas@flying-snail.de
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 772cc36f951d..5bb1cf603301 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -632,7 +632,7 @@ static int snd_es1968_ac97_wait(struct es1968 *chip)
632 return 0; 632 return 0;
633 cond_resched(); 633 cond_resched();
634 } 634 }
635 snd_printd("es1968: ac97 timeout\n"); 635 dev_dbg(chip->card->dev, "ac97 timeout\n");
636 return 1; /* timeout */ 636 return 1; /* timeout */
637} 637}
638 638
@@ -644,7 +644,7 @@ static int snd_es1968_ac97_wait_poll(struct es1968 *chip)
644 if (!(inb(chip->io_port + ESM_AC97_INDEX) & 1)) 644 if (!(inb(chip->io_port + ESM_AC97_INDEX) & 1))
645 return 0; 645 return 0;
646 } 646 }
647 snd_printd("es1968: ac97 timeout\n"); 647 dev_dbg(chip->card->dev, "ac97 timeout\n");
648 return 1; /* timeout */ 648 return 1; /* timeout */
649} 649}
650 650
@@ -687,7 +687,7 @@ static void apu_index_set(struct es1968 *chip, u16 index)
687 for (i = 0; i < 1000; i++) 687 for (i = 0; i < 1000; i++)
688 if (__maestro_read(chip, IDR1_CRAM_POINTER) == index) 688 if (__maestro_read(chip, IDR1_CRAM_POINTER) == index)
689 return; 689 return;
690 snd_printd("es1968: APU register select failed. (Timeout)\n"); 690 dev_dbg(chip->card->dev, "APU register select failed. (Timeout)\n");
691} 691}
692 692
693/* no spinlock */ 693/* no spinlock */
@@ -699,7 +699,7 @@ static void apu_data_set(struct es1968 *chip, u16 data)
699 return; 699 return;
700 __maestro_write(chip, IDR0_DATA_PORT, data); 700 __maestro_write(chip, IDR0_DATA_PORT, data);
701 } 701 }
702 snd_printd("es1968: APU register set probably failed (Timeout)!\n"); 702 dev_dbg(chip->card->dev, "APU register set probably failed (Timeout)!\n");
703} 703}
704 704
705/* no spinlock */ 705/* no spinlock */
@@ -1442,13 +1442,14 @@ snd_es1968_init_dmabuf(struct es1968 *chip)
1442 snd_dma_pci_data(chip->pci), 1442 snd_dma_pci_data(chip->pci),
1443 chip->total_bufsize, &chip->dma); 1443 chip->total_bufsize, &chip->dma);
1444 if (err < 0 || ! chip->dma.area) { 1444 if (err < 0 || ! chip->dma.area) {
1445 snd_printk(KERN_ERR "es1968: can't allocate dma pages for size %d\n", 1445 dev_err(chip->card->dev,
1446 "can't allocate dma pages for size %d\n",
1446 chip->total_bufsize); 1447 chip->total_bufsize);
1447 return -ENOMEM; 1448 return -ENOMEM;
1448 } 1449 }
1449 if ((chip->dma.addr + chip->dma.bytes - 1) & ~((1 << 28) - 1)) { 1450 if ((chip->dma.addr + chip->dma.bytes - 1) & ~((1 << 28) - 1)) {
1450 snd_dma_free_pages(&chip->dma); 1451 snd_dma_free_pages(&chip->dma);
1451 snd_printk(KERN_ERR "es1968: DMA buffer beyond 256MB.\n"); 1452 dev_err(chip->card->dev, "DMA buffer beyond 256MB.\n");
1452 return -ENOMEM; 1453 return -ENOMEM;
1453 } 1454 }
1454 1455
@@ -1489,7 +1490,8 @@ static int snd_es1968_hw_params(struct snd_pcm_substream *substream,
1489 } 1490 }
1490 chan->memory = snd_es1968_new_memory(chip, size); 1491 chan->memory = snd_es1968_new_memory(chip, size);
1491 if (chan->memory == NULL) { 1492 if (chan->memory == NULL) {
1492 // snd_printd("cannot allocate dma buffer: size = %d\n", size); 1493 dev_dbg(chip->card->dev,
1494 "cannot allocate dma buffer: size = %d\n", size);
1493 return -ENOMEM; 1495 return -ENOMEM;
1494 } 1496 }
1495 snd_pcm_set_runtime_buffer(substream, &chan->memory->buf); 1497 snd_pcm_set_runtime_buffer(substream, &chan->memory->buf);
@@ -1715,11 +1717,13 @@ static void es1968_measure_clock(struct es1968 *chip)
1715 1717
1716 /* search 2 APUs (although one apu is enough) */ 1718 /* search 2 APUs (although one apu is enough) */
1717 if ((apu = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_PLAY)) < 0) { 1719 if ((apu = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_PLAY)) < 0) {
1718 snd_printk(KERN_ERR "Hmm, cannot find empty APU pair!?\n"); 1720 dev_err(chip->card->dev, "Hmm, cannot find empty APU pair!?\n");
1719 return; 1721 return;
1720 } 1722 }
1721 if ((memory = snd_es1968_new_memory(chip, CLOCK_MEASURE_BUFSIZE)) == NULL) { 1723 if ((memory = snd_es1968_new_memory(chip, CLOCK_MEASURE_BUFSIZE)) == NULL) {
1722 snd_printk(KERN_ERR "cannot allocate dma buffer - using default clock %d\n", chip->clock); 1724 dev_warn(chip->card->dev,
1725 "cannot allocate dma buffer - using default clock %d\n",
1726 chip->clock);
1723 snd_es1968_free_apu_pair(chip, apu); 1727 snd_es1968_free_apu_pair(chip, apu);
1724 return; 1728 return;
1725 } 1729 }
@@ -1780,7 +1784,7 @@ static void es1968_measure_clock(struct es1968 *chip)
1780 else 1784 else
1781 t += stop_time.tv_usec - start_time.tv_usec; 1785 t += stop_time.tv_usec - start_time.tv_usec;
1782 if (t == 0) { 1786 if (t == 0) {
1783 snd_printk(KERN_ERR "?? calculation error..\n"); 1787 dev_err(chip->card->dev, "?? calculation error..\n");
1784 } else { 1788 } else {
1785 offset *= 1000; 1789 offset *= 1000;
1786 offset = (offset / t) * 1000 + ((offset % t) * 1000) / t; 1790 offset = (offset / t) * 1000 + ((offset % t) * 1000) / t;
@@ -1788,7 +1792,7 @@ static void es1968_measure_clock(struct es1968 *chip)
1788 if (offset >= 40000 && offset <= 50000) 1792 if (offset >= 40000 && offset <= 50000)
1789 chip->clock = (chip->clock * offset) / 48000; 1793 chip->clock = (chip->clock * offset) / 48000;
1790 } 1794 }
1791 printk(KERN_INFO "es1968: clocking to %d\n", chip->clock); 1795 dev_info(chip->card->dev, "clocking to %d\n", chip->clock);
1792 } 1796 }
1793 snd_es1968_free_memory(chip, memory); 1797 snd_es1968_free_memory(chip, memory);
1794 snd_es1968_free_apu_pair(chip, apu); 1798 snd_es1968_free_apu_pair(chip, apu);
@@ -2108,7 +2112,7 @@ static void snd_es1968_ac97_reset(struct es1968 *chip)
2108 outw(inw(ioaddr + 0x3c) & 0xfffc, ioaddr + 0x3c); 2112 outw(inw(ioaddr + 0x3c) & 0xfffc, ioaddr + 0x3c);
2109 2113
2110#if 0 /* the loop here needs to be much better if we want it.. */ 2114#if 0 /* the loop here needs to be much better if we want it.. */
2111 snd_printk(KERN_INFO "trying software reset\n"); 2115 dev_info(chip->card->dev, "trying software reset\n");
2112 /* try and do a software reset */ 2116 /* try and do a software reset */
2113 outb(0x80 | 0x7c, ioaddr + 0x30); 2117 outb(0x80 | 0x7c, ioaddr + 0x30);
2114 for (w = 0;; w++) { 2118 for (w = 0;; w++) {
@@ -2416,8 +2420,7 @@ static int es1968_resume(struct device *dev)
2416 pci_set_power_state(pci, PCI_D0); 2420 pci_set_power_state(pci, PCI_D0);
2417 pci_restore_state(pci); 2421 pci_restore_state(pci);
2418 if (pci_enable_device(pci) < 0) { 2422 if (pci_enable_device(pci) < 0) {
2419 printk(KERN_ERR "es1968: pci_enable_device failed, " 2423 dev_err(dev, "pci_enable_device failed, disabling device\n");
2420 "disabling device\n");
2421 snd_card_disconnect(card); 2424 snd_card_disconnect(card);
2422 return -EIO; 2425 return -EIO;
2423 } 2426 }
@@ -2479,7 +2482,8 @@ static int snd_es1968_create_gameport(struct es1968 *chip, int dev)
2479 2482
2480 chip->gameport = gp = gameport_allocate_port(); 2483 chip->gameport = gp = gameport_allocate_port();
2481 if (!gp) { 2484 if (!gp) {
2482 printk(KERN_ERR "es1968: cannot allocate memory for gameport\n"); 2485 dev_err(chip->card->dev,
2486 "cannot allocate memory for gameport\n");
2483 release_and_free_resource(r); 2487 release_and_free_resource(r);
2484 return -ENOMEM; 2488 return -ENOMEM;
2485 } 2489 }
@@ -2706,7 +2710,8 @@ static int snd_es1968_create(struct snd_card *card,
2706 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2710 /* check, if we can restrict PCI DMA transfers to 28 bits */
2707 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || 2711 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
2708 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { 2712 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) {
2709 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n"); 2713 dev_err(card->dev,
2714 "architecture does not support 28bit PCI busmaster DMA\n");
2710 pci_disable_device(pci); 2715 pci_disable_device(pci);
2711 return -ENXIO; 2716 return -ENXIO;
2712 } 2717 }
@@ -2740,7 +2745,7 @@ static int snd_es1968_create(struct snd_card *card,
2740 chip->io_port = pci_resource_start(pci, 0); 2745 chip->io_port = pci_resource_start(pci, 0);
2741 if (request_irq(pci->irq, snd_es1968_interrupt, IRQF_SHARED, 2746 if (request_irq(pci->irq, snd_es1968_interrupt, IRQF_SHARED,
2742 KBUILD_MODNAME, chip)) { 2747 KBUILD_MODNAME, chip)) {
2743 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 2748 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
2744 snd_es1968_free(chip); 2749 snd_es1968_free(chip);
2745 return -EBUSY; 2750 return -EBUSY;
2746 } 2751 }
@@ -2770,7 +2775,7 @@ static int snd_es1968_create(struct snd_card *card,
2770 } 2775 }
2771 if (do_pm > 1) { 2776 if (do_pm > 1) {
2772 /* not matched; disabling pm */ 2777 /* not matched; disabling pm */
2773 printk(KERN_INFO "es1968: not attempting power management.\n"); 2778 dev_info(card->dev, "not attempting power management.\n");
2774 do_pm = 0; 2779 do_pm = 0;
2775 } 2780 }
2776 } 2781 }
@@ -2783,8 +2788,6 @@ static int snd_es1968_create(struct snd_card *card,
2783 return err; 2788 return err;
2784 } 2789 }
2785 2790
2786 snd_card_set_dev(card, &pci->dev);
2787
2788#ifdef CONFIG_SND_ES1968_RADIO 2791#ifdef CONFIG_SND_ES1968_RADIO
2789 /* don't play with GPIOs on laptops */ 2792 /* don't play with GPIOs on laptops */
2790 if (chip->pci->subsystem_vendor != 0x125d) 2793 if (chip->pci->subsystem_vendor != 0x125d)
@@ -2802,7 +2805,7 @@ static int snd_es1968_create(struct snd_card *card,
2802 for (i = 0; i < ARRAY_SIZE(snd_es1968_tea575x_gpios); i++) { 2805 for (i = 0; i < ARRAY_SIZE(snd_es1968_tea575x_gpios); i++) {
2803 chip->tea575x_tuner = i; 2806 chip->tea575x_tuner = i;
2804 if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) { 2807 if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) {
2805 snd_printk(KERN_INFO "es1968: detected TEA575x radio type %s\n", 2808 dev_info(card->dev, "detected TEA575x radio type %s\n",
2806 get_tea575x_gpio(chip)->name); 2809 get_tea575x_gpio(chip)->name);
2807 strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name, 2810 strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name,
2808 sizeof(chip->tea.card)); 2811 sizeof(chip->tea.card));
@@ -2836,7 +2839,8 @@ static int snd_es1968_probe(struct pci_dev *pci,
2836 return -ENOENT; 2839 return -ENOENT;
2837 } 2840 }
2838 2841
2839 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2842 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2843 0, &card);
2840 if (err < 0) 2844 if (err < 0)
2841 return err; 2845 return err;
2842 2846
@@ -2900,7 +2904,7 @@ static int snd_es1968_probe(struct pci_dev *pci,
2900 MPU401_INFO_INTEGRATED | 2904 MPU401_INFO_INTEGRATED |
2901 MPU401_INFO_IRQ_HOOK, 2905 MPU401_INFO_IRQ_HOOK,
2902 -1, &chip->rmidi)) < 0) { 2906 -1, &chip->rmidi)) < 0) {
2903 printk(KERN_WARNING "es1968: skipping MPU-401 MIDI support..\n"); 2907 dev_warn(card->dev, "skipping MPU-401 MIDI support..\n");
2904 } 2908 }
2905 } 2909 }
2906 2910
@@ -2909,8 +2913,8 @@ static int snd_es1968_probe(struct pci_dev *pci,
2909#ifdef CONFIG_SND_ES1968_INPUT 2913#ifdef CONFIG_SND_ES1968_INPUT
2910 err = snd_es1968_input_register(chip); 2914 err = snd_es1968_input_register(chip);
2911 if (err) 2915 if (err)
2912 snd_printk(KERN_WARNING "Input device registration " 2916 dev_warn(card->dev,
2913 "failed with error %i", err); 2917 "Input device registration failed with error %i", err);
2914#endif 2918#endif
2915 2919
2916 snd_es1968_start_irq(chip); 2920 snd_es1968_start_irq(chip);
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index 45bc8a95b7c4..db18ccabadd6 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -254,7 +254,7 @@ static void snd_fm801_codec_write(struct snd_ac97 *ac97,
254 goto ok1; 254 goto ok1;
255 udelay(10); 255 udelay(10);
256 } 256 }
257 snd_printk(KERN_ERR "AC'97 interface is busy (1)\n"); 257 dev_err(chip->card->dev, "AC'97 interface is busy (1)\n");
258 return; 258 return;
259 259
260 ok1: 260 ok1:
@@ -269,7 +269,7 @@ static void snd_fm801_codec_write(struct snd_ac97 *ac97,
269 return; 269 return;
270 udelay(10); 270 udelay(10);
271 } 271 }
272 snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num); 272 dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n", ac97->num);
273} 273}
274 274
275static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short reg) 275static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short reg)
@@ -285,7 +285,7 @@ static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short
285 goto ok1; 285 goto ok1;
286 udelay(10); 286 udelay(10);
287 } 287 }
288 snd_printk(KERN_ERR "AC'97 interface is busy (1)\n"); 288 dev_err(chip->card->dev, "AC'97 interface is busy (1)\n");
289 return 0; 289 return 0;
290 290
291 ok1: 291 ok1:
@@ -297,7 +297,7 @@ static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short
297 goto ok2; 297 goto ok2;
298 udelay(10); 298 udelay(10);
299 } 299 }
300 snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num); 300 dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n", ac97->num);
301 return 0; 301 return 0;
302 302
303 ok2: 303 ok2:
@@ -306,7 +306,7 @@ static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short
306 goto ok3; 306 goto ok3;
307 udelay(10); 307 udelay(10);
308 } 308 }
309 snd_printk(KERN_ERR "AC'97 interface #%d is not valid (2)\n", ac97->num); 309 dev_err(chip->card->dev, "AC'97 interface #%d is not valid (2)\n", ac97->num);
310 return 0; 310 return 0;
311 311
312 ok3: 312 ok3:
@@ -1100,8 +1100,8 @@ static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1100 1100
1101 if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0) 1101 if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0)
1102 if (!resume) { 1102 if (!resume) {
1103 snd_printk(KERN_INFO "Primary AC'97 codec not found, " 1103 dev_info(chip->card->dev,
1104 "assume SF64-PCR (tuner-only)\n"); 1104 "Primary AC'97 codec not found, assume SF64-PCR (tuner-only)\n");
1105 chip->tea575x_tuner = 3 | TUNER_ONLY; 1105 chip->tea575x_tuner = 3 | TUNER_ONLY;
1106 goto __ac97_ok; 1106 goto __ac97_ok;
1107 } 1107 }
@@ -1225,7 +1225,7 @@ static int snd_fm801_create(struct snd_card *card,
1225 if ((tea575x_tuner & TUNER_ONLY) == 0) { 1225 if ((tea575x_tuner & TUNER_ONLY) == 0) {
1226 if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED, 1226 if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED,
1227 KBUILD_MODNAME, chip)) { 1227 KBUILD_MODNAME, chip)) {
1228 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq); 1228 dev_err(card->dev, "unable to grab IRQ %d\n", chip->irq);
1229 snd_fm801_free(chip); 1229 snd_fm801_free(chip);
1230 return -EBUSY; 1230 return -EBUSY;
1231 } 1231 }
@@ -1251,8 +1251,6 @@ static int snd_fm801_create(struct snd_card *card,
1251 return err; 1251 return err;
1252 } 1252 }
1253 1253
1254 snd_card_set_dev(card, &pci->dev);
1255
1256#ifdef CONFIG_SND_FM801_TEA575X_BOOL 1254#ifdef CONFIG_SND_FM801_TEA575X_BOOL
1257 err = v4l2_device_register(&pci->dev, &chip->v4l2_dev); 1255 err = v4l2_device_register(&pci->dev, &chip->v4l2_dev);
1258 if (err < 0) { 1256 if (err < 0) {
@@ -1267,7 +1265,7 @@ static int snd_fm801_create(struct snd_card *card,
1267 if ((tea575x_tuner & TUNER_TYPE_MASK) > 0 && 1265 if ((tea575x_tuner & TUNER_TYPE_MASK) > 0 &&
1268 (tea575x_tuner & TUNER_TYPE_MASK) < 4) { 1266 (tea575x_tuner & TUNER_TYPE_MASK) < 4) {
1269 if (snd_tea575x_init(&chip->tea, THIS_MODULE)) { 1267 if (snd_tea575x_init(&chip->tea, THIS_MODULE)) {
1270 snd_printk(KERN_ERR "TEA575x radio not found\n"); 1268 dev_err(card->dev, "TEA575x radio not found\n");
1271 snd_fm801_free(chip); 1269 snd_fm801_free(chip);
1272 return -ENODEV; 1270 return -ENODEV;
1273 } 1271 }
@@ -1276,13 +1274,14 @@ static int snd_fm801_create(struct snd_card *card,
1276 for (tea575x_tuner = 1; tea575x_tuner <= 3; tea575x_tuner++) { 1274 for (tea575x_tuner = 1; tea575x_tuner <= 3; tea575x_tuner++) {
1277 chip->tea575x_tuner = tea575x_tuner; 1275 chip->tea575x_tuner = tea575x_tuner;
1278 if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) { 1276 if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) {
1279 snd_printk(KERN_INFO "detected TEA575x radio type %s\n", 1277 dev_info(card->dev,
1278 "detected TEA575x radio type %s\n",
1280 get_tea575x_gpio(chip)->name); 1279 get_tea575x_gpio(chip)->name);
1281 break; 1280 break;
1282 } 1281 }
1283 } 1282 }
1284 if (tea575x_tuner == 4) { 1283 if (tea575x_tuner == 4) {
1285 snd_printk(KERN_ERR "TEA575x radio not found\n"); 1284 dev_err(card->dev, "TEA575x radio not found\n");
1286 chip->tea575x_tuner = TUNER_DISABLED; 1285 chip->tea575x_tuner = TUNER_DISABLED;
1287 } 1286 }
1288 } 1287 }
@@ -1312,7 +1311,8 @@ static int snd_card_fm801_probe(struct pci_dev *pci,
1312 return -ENOENT; 1311 return -ENOENT;
1313 } 1312 }
1314 1313
1315 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1314 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1315 0, &card);
1316 if (err < 0) 1316 if (err < 0)
1317 return err; 1317 return err;
1318 if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev], &chip)) < 0) { 1318 if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev], &chip)) < 0) {
@@ -1411,8 +1411,7 @@ static int snd_fm801_resume(struct device *dev)
1411 pci_set_power_state(pci, PCI_D0); 1411 pci_set_power_state(pci, PCI_D0);
1412 pci_restore_state(pci); 1412 pci_restore_state(pci);
1413 if (pci_enable_device(pci) < 0) { 1413 if (pci_enable_device(pci) < 0) {
1414 printk(KERN_ERR "fm801: pci_enable_device failed, " 1414 dev_err(dev, "pci_enable_device failed, disabling device\n");
1415 "disabling device\n");
1416 snd_card_disconnect(card); 1415 snd_card_disconnect(card);
1417 return -EIO; 1416 return -EIO;
1418 } 1417 }
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 0e53634dbbd8..ac17c3fc9388 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -1,8 +1,15 @@
1menuconfig SND_HDA_INTEL 1menu "HD-Audio"
2 tristate "Intel HD Audio" 2
3config SND_HDA
4 tristate
3 select SND_PCM 5 select SND_PCM
4 select SND_VMASTER 6 select SND_VMASTER
5 select SND_KCTL_JACK 7 select SND_KCTL_JACK
8
9config SND_HDA_INTEL
10 tristate "HD Audio PCI"
11 depends on SND_PCI
12 select SND_HDA
6 help 13 help
7 Say Y here to include support for Intel "High Definition 14 Say Y here to include support for Intel "High Definition
8 Audio" (Azalia) and its compatible devices. 15 Audio" (Azalia) and its compatible devices.
@@ -13,7 +20,7 @@ menuconfig SND_HDA_INTEL
13 To compile this driver as a module, choose M here: the module 20 To compile this driver as a module, choose M here: the module
14 will be called snd-hda-intel. 21 will be called snd-hda-intel.
15 22
16if SND_HDA_INTEL 23if SND_HDA
17 24
18config SND_HDA_DSP_LOADER 25config SND_HDA_DSP_LOADER
19 bool 26 bool
@@ -41,7 +48,6 @@ config SND_HDA_HWDEP
41 48
42config SND_HDA_RECONFIG 49config SND_HDA_RECONFIG
43 bool "Allow dynamic codec reconfiguration" 50 bool "Allow dynamic codec reconfiguration"
44 depends on SND_HDA_HWDEP
45 help 51 help
46 Say Y here to enable the HD-audio codec re-configuration feature. 52 Say Y here to enable the HD-audio codec re-configuration feature.
47 This adds the sysfs interfaces to allow user to clear the whole 53 This adds the sysfs interfaces to allow user to clear the whole
@@ -50,7 +56,7 @@ config SND_HDA_RECONFIG
50 56
51config SND_HDA_INPUT_BEEP 57config SND_HDA_INPUT_BEEP
52 bool "Support digital beep via input layer" 58 bool "Support digital beep via input layer"
53 depends on INPUT=y || INPUT=SND_HDA_INTEL 59 depends on INPUT=y || INPUT=SND_HDA
54 help 60 help
55 Say Y here to build a digital beep interface for HD-audio 61 Say Y here to build a digital beep interface for HD-audio
56 driver. This interface is used to generate digital beeps. 62 driver. This interface is used to generate digital beeps.
@@ -76,7 +82,6 @@ config SND_HDA_INPUT_JACK
76config SND_HDA_PATCH_LOADER 82config SND_HDA_PATCH_LOADER
77 bool "Support initialization patch loading for HD-audio" 83 bool "Support initialization patch loading for HD-audio"
78 select FW_LOADER 84 select FW_LOADER
79 select SND_HDA_HWDEP
80 select SND_HDA_RECONFIG 85 select SND_HDA_RECONFIG
81 help 86 help
82 Say Y here to allow the HD-audio driver to load a pseudo 87 Say Y here to allow the HD-audio driver to load a pseudo
@@ -84,8 +89,6 @@ config SND_HDA_PATCH_LOADER
84 start up. The "patch" file can be specified via patch module 89 start up. The "patch" file can be specified via patch module
85 option, such as patch=hda-init. 90 option, such as patch=hda-init.
86 91
87 This option turns on hwdep and reconfig features automatically.
88
89config SND_HDA_CODEC_REALTEK 92config SND_HDA_CODEC_REALTEK
90 tristate "Build Realtek HD-audio codec support" 93 tristate "Build Realtek HD-audio codec support"
91 select SND_HDA_GENERIC 94 select SND_HDA_GENERIC
@@ -94,7 +97,7 @@ config SND_HDA_CODEC_REALTEK
94 snd-hda-intel driver, such as ALC880. 97 snd-hda-intel driver, such as ALC880.
95 98
96comment "Set to Y if you want auto-loading the codec driver" 99comment "Set to Y if you want auto-loading the codec driver"
97 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_REALTEK=m 100 depends on SND_HDA=y && SND_HDA_CODEC_REALTEK=m
98 101
99config SND_HDA_CODEC_ANALOG 102config SND_HDA_CODEC_ANALOG
100 tristate "Build Analog Device HD-audio codec support" 103 tristate "Build Analog Device HD-audio codec support"
@@ -104,7 +107,7 @@ config SND_HDA_CODEC_ANALOG
104 snd-hda-intel driver, such as AD1986A. 107 snd-hda-intel driver, such as AD1986A.
105 108
106comment "Set to Y if you want auto-loading the codec driver" 109comment "Set to Y if you want auto-loading the codec driver"
107 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_ANALOG=m 110 depends on SND_HDA=y && SND_HDA_CODEC_ANALOG=m
108 111
109config SND_HDA_CODEC_SIGMATEL 112config SND_HDA_CODEC_SIGMATEL
110 tristate "Build IDT/Sigmatel HD-audio codec support" 113 tristate "Build IDT/Sigmatel HD-audio codec support"
@@ -114,7 +117,7 @@ config SND_HDA_CODEC_SIGMATEL
114 snd-hda-intel driver, such as STAC9200. 117 snd-hda-intel driver, such as STAC9200.
115 118
116comment "Set to Y if you want auto-loading the codec driver" 119comment "Set to Y if you want auto-loading the codec driver"
117 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_SIGMATEL=m 120 depends on SND_HDA=y && SND_HDA_CODEC_SIGMATEL=m
118 121
119config SND_HDA_CODEC_VIA 122config SND_HDA_CODEC_VIA
120 tristate "Build VIA HD-audio codec support" 123 tristate "Build VIA HD-audio codec support"
@@ -124,7 +127,7 @@ config SND_HDA_CODEC_VIA
124 snd-hda-intel driver, such as VT1708. 127 snd-hda-intel driver, such as VT1708.
125 128
126comment "Set to Y if you want auto-loading the codec driver" 129comment "Set to Y if you want auto-loading the codec driver"
127 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_VIA=m 130 depends on SND_HDA=y && SND_HDA_CODEC_VIA=m
128 131
129config SND_HDA_CODEC_HDMI 132config SND_HDA_CODEC_HDMI
130 tristate "Build HDMI/DisplayPort HD-audio codec support" 133 tristate "Build HDMI/DisplayPort HD-audio codec support"
@@ -134,7 +137,7 @@ config SND_HDA_CODEC_HDMI
134 Intel and Nvidia HDMI/DisplayPort codecs. 137 Intel and Nvidia HDMI/DisplayPort codecs.
135 138
136comment "Set to Y if you want auto-loading the codec driver" 139comment "Set to Y if you want auto-loading the codec driver"
137 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_HDMI=m 140 depends on SND_HDA=y && SND_HDA_CODEC_HDMI=m
138 141
139config SND_HDA_I915 142config SND_HDA_I915
140 bool 143 bool
@@ -149,7 +152,7 @@ config SND_HDA_CODEC_CIRRUS
149 snd-hda-intel driver, such as CS4206. 152 snd-hda-intel driver, such as CS4206.
150 153
151comment "Set to Y if you want auto-loading the codec driver" 154comment "Set to Y if you want auto-loading the codec driver"
152 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_CIRRUS=m 155 depends on SND_HDA=y && SND_HDA_CODEC_CIRRUS=m
153 156
154config SND_HDA_CODEC_CONEXANT 157config SND_HDA_CODEC_CONEXANT
155 tristate "Build Conexant HD-audio codec support" 158 tristate "Build Conexant HD-audio codec support"
@@ -159,7 +162,7 @@ config SND_HDA_CODEC_CONEXANT
159 snd-hda-intel driver, such as CX20549. 162 snd-hda-intel driver, such as CX20549.
160 163
161comment "Set to Y if you want auto-loading the codec driver" 164comment "Set to Y if you want auto-loading the codec driver"
162 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_CONEXANT=m 165 depends on SND_HDA=y && SND_HDA_CODEC_CONEXANT=m
163 166
164config SND_HDA_CODEC_CA0110 167config SND_HDA_CODEC_CA0110
165 tristate "Build Creative CA0110-IBG codec support" 168 tristate "Build Creative CA0110-IBG codec support"
@@ -169,7 +172,7 @@ config SND_HDA_CODEC_CA0110
169 snd-hda-intel driver, found on some Creative X-Fi cards. 172 snd-hda-intel driver, found on some Creative X-Fi cards.
170 173
171comment "Set to Y if you want auto-loading the codec driver" 174comment "Set to Y if you want auto-loading the codec driver"
172 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_CA0110=m 175 depends on SND_HDA=y && SND_HDA_CODEC_CA0110=m
173 176
174config SND_HDA_CODEC_CA0132 177config SND_HDA_CODEC_CA0132
175 tristate "Build Creative CA0132 codec support" 178 tristate "Build Creative CA0132 codec support"
@@ -178,7 +181,7 @@ config SND_HDA_CODEC_CA0132
178 snd-hda-intel driver. 181 snd-hda-intel driver.
179 182
180comment "Set to Y if you want auto-loading the codec driver" 183comment "Set to Y if you want auto-loading the codec driver"
181 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_CA0132=m 184 depends on SND_HDA=y && SND_HDA_CODEC_CA0132=m
182 185
183config SND_HDA_CODEC_CA0132_DSP 186config SND_HDA_CODEC_CA0132_DSP
184 bool "Support new DSP code for CA0132 codec" 187 bool "Support new DSP code for CA0132 codec"
@@ -200,7 +203,7 @@ config SND_HDA_CODEC_CMEDIA
200 snd-hda-intel driver, such as CMI9880. 203 snd-hda-intel driver, such as CMI9880.
201 204
202comment "Set to Y if you want auto-loading the codec driver" 205comment "Set to Y if you want auto-loading the codec driver"
203 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_CMEDIA=m 206 depends on SND_HDA=y && SND_HDA_CODEC_CMEDIA=m
204 207
205config SND_HDA_CODEC_SI3054 208config SND_HDA_CODEC_SI3054
206 tristate "Build Silicon Labs 3054 HD-modem codec support" 209 tristate "Build Silicon Labs 3054 HD-modem codec support"
@@ -209,7 +212,7 @@ config SND_HDA_CODEC_SI3054
209 (and compatibles) support in snd-hda-intel driver. 212 (and compatibles) support in snd-hda-intel driver.
210 213
211comment "Set to Y if you want auto-loading the codec driver" 214comment "Set to Y if you want auto-loading the codec driver"
212 depends on SND_HDA_INTEL=y && SND_HDA_CODEC_SI3054=m 215 depends on SND_HDA=y && SND_HDA_CODEC_SI3054=m
213 216
214config SND_HDA_GENERIC 217config SND_HDA_GENERIC
215 tristate "Enable generic HD-audio codec parser" 218 tristate "Enable generic HD-audio codec parser"
@@ -218,7 +221,7 @@ config SND_HDA_GENERIC
218 in snd-hda-intel driver. 221 in snd-hda-intel driver.
219 222
220comment "Set to Y if you want auto-loading the codec driver" 223comment "Set to Y if you want auto-loading the codec driver"
221 depends on SND_HDA_INTEL=y && SND_HDA_GENERIC=m 224 depends on SND_HDA=y && SND_HDA_GENERIC=m
222 225
223config SND_HDA_POWER_SAVE_DEFAULT 226config SND_HDA_POWER_SAVE_DEFAULT
224 int "Default time-out for HD-audio power-save mode" 227 int "Default time-out for HD-audio power-save mode"
@@ -229,3 +232,5 @@ config SND_HDA_POWER_SAVE_DEFAULT
229 power-save mode. 0 means to disable the power-save mode. 232 power-save mode. 0 means to disable the power-save mode.
230 233
231endif 234endif
235
236endmenu
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 1fcb118e480a..d0d0c19ddfc2 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -1,15 +1,16 @@
1snd-hda-intel-objs := hda_intel.o 1snd-hda-intel-objs := hda_intel.o
2snd-hda-controller-objs := hda_controller.o
2# for haswell power well 3# for haswell power well
3snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o 4snd-hda-intel-$(CONFIG_SND_HDA_I915) += hda_i915.o
4 5
5snd-hda-codec-y := hda_codec.o hda_jack.o hda_auto_parser.o 6snd-hda-codec-y := hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o
6snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o 7snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
7snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 8snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
8snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o 9snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
9 10
10# for trace-points 11# for trace-points
11CFLAGS_hda_codec.o := -I$(src) 12CFLAGS_hda_codec.o := -I$(src)
12CFLAGS_hda_intel.o := -I$(src) 13CFLAGS_hda_controller.o := -I$(src)
13 14
14snd-hda-codec-generic-objs := hda_generic.o 15snd-hda-codec-generic-objs := hda_generic.o
15snd-hda-codec-realtek-objs := patch_realtek.o 16snd-hda-codec-realtek-objs := patch_realtek.o
@@ -25,7 +26,8 @@ snd-hda-codec-via-objs := patch_via.o
25snd-hda-codec-hdmi-objs := patch_hdmi.o hda_eld.o 26snd-hda-codec-hdmi-objs := patch_hdmi.o hda_eld.o
26 27
27# common driver 28# common driver
28obj-$(CONFIG_SND_HDA_INTEL) := snd-hda-codec.o 29obj-$(CONFIG_SND_HDA) := snd-hda-codec.o
30obj-$(CONFIG_SND_HDA) += snd-hda-controller.o
29 31
30# codec drivers 32# codec drivers
31obj-$(CONFIG_SND_HDA_GENERIC) += snd-hda-codec-generic.o 33obj-$(CONFIG_SND_HDA_GENERIC) += snd-hda-codec-generic.o
diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c
index 47ad31c6aa70..90d2fda6c8f9 100644
--- a/sound/pci/hda/hda_auto_parser.c
+++ b/sound/pci/hda/hda_auto_parser.c
@@ -227,10 +227,18 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
227 continue; 227 continue;
228 if (!assoc_line_out) 228 if (!assoc_line_out)
229 assoc_line_out = assoc; 229 assoc_line_out = assoc;
230 else if (assoc_line_out != assoc) 230 else if (assoc_line_out != assoc) {
231 codec_info(codec,
232 "ignore pin 0x%x with mismatching assoc# 0x%x vs 0x%x\n",
233 nid, assoc, assoc_line_out);
231 continue; 234 continue;
232 if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins)) 235 }
236 if (cfg->line_outs >= ARRAY_SIZE(cfg->line_out_pins)) {
237 codec_info(codec,
238 "ignore pin 0x%x, too many assigned pins\n",
239 nid);
233 continue; 240 continue;
241 }
234 line_out[cfg->line_outs].pin = nid; 242 line_out[cfg->line_outs].pin = nid;
235 line_out[cfg->line_outs].seq = seq; 243 line_out[cfg->line_outs].seq = seq;
236 cfg->line_outs++; 244 cfg->line_outs++;
@@ -238,8 +246,12 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
238 case AC_JACK_SPEAKER: 246 case AC_JACK_SPEAKER:
239 seq = get_defcfg_sequence(def_conf); 247 seq = get_defcfg_sequence(def_conf);
240 assoc = get_defcfg_association(def_conf); 248 assoc = get_defcfg_association(def_conf);
241 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins)) 249 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins)) {
250 codec_info(codec,
251 "ignore pin 0x%x, too many assigned pins\n",
252 nid);
242 continue; 253 continue;
254 }
243 speaker_out[cfg->speaker_outs].pin = nid; 255 speaker_out[cfg->speaker_outs].pin = nid;
244 speaker_out[cfg->speaker_outs].seq = (assoc << 4) | seq; 256 speaker_out[cfg->speaker_outs].seq = (assoc << 4) | seq;
245 cfg->speaker_outs++; 257 cfg->speaker_outs++;
@@ -247,8 +259,12 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
247 case AC_JACK_HP_OUT: 259 case AC_JACK_HP_OUT:
248 seq = get_defcfg_sequence(def_conf); 260 seq = get_defcfg_sequence(def_conf);
249 assoc = get_defcfg_association(def_conf); 261 assoc = get_defcfg_association(def_conf);
250 if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins)) 262 if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins)) {
263 codec_info(codec,
264 "ignore pin 0x%x, too many assigned pins\n",
265 nid);
251 continue; 266 continue;
267 }
252 hp_out[cfg->hp_outs].pin = nid; 268 hp_out[cfg->hp_outs].pin = nid;
253 hp_out[cfg->hp_outs].seq = (assoc << 4) | seq; 269 hp_out[cfg->hp_outs].seq = (assoc << 4) | seq;
254 cfg->hp_outs++; 270 cfg->hp_outs++;
@@ -267,8 +283,12 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
267 break; 283 break;
268 case AC_JACK_SPDIF_OUT: 284 case AC_JACK_SPDIF_OUT:
269 case AC_JACK_DIG_OTHER_OUT: 285 case AC_JACK_DIG_OTHER_OUT:
270 if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins)) 286 if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins)) {
287 codec_info(codec,
288 "ignore pin 0x%x, too many assigned pins\n",
289 nid);
271 continue; 290 continue;
291 }
272 cfg->dig_out_pins[cfg->dig_outs] = nid; 292 cfg->dig_out_pins[cfg->dig_outs] = nid;
273 cfg->dig_out_type[cfg->dig_outs] = 293 cfg->dig_out_type[cfg->dig_outs] =
274 (loc == AC_JACK_LOC_HDMI) ? 294 (loc == AC_JACK_LOC_HDMI) ?
@@ -313,9 +333,9 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
313 } 333 }
314 334
315 if (hsmic) 335 if (hsmic)
316 snd_printdd("Told to look for a headset mic, but didn't find any.\n"); 336 codec_dbg(codec, "Told to look for a headset mic, but didn't find any.\n");
317 if (hpmic) 337 if (hpmic)
318 snd_printdd("Told to look for a headphone mic, but didn't find any.\n"); 338 codec_dbg(codec, "Told to look for a headphone mic, but didn't find any.\n");
319 } 339 }
320 340
321 /* FIX-UP: 341 /* FIX-UP:
@@ -384,33 +404,33 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
384 /* 404 /*
385 * debug prints of the parsed results 405 * debug prints of the parsed results
386 */ 406 */
387 snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n", 407 codec_info(codec, "autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n",
388 cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1], 408 cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
389 cfg->line_out_pins[2], cfg->line_out_pins[3], 409 cfg->line_out_pins[2], cfg->line_out_pins[3],
390 cfg->line_out_pins[4], 410 cfg->line_out_pins[4],
391 cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" : 411 cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" :
392 (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ? 412 (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ?
393 "speaker" : "line")); 413 "speaker" : "line"));
394 snd_printd(" speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", 414 codec_info(codec, " speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
395 cfg->speaker_outs, cfg->speaker_pins[0], 415 cfg->speaker_outs, cfg->speaker_pins[0],
396 cfg->speaker_pins[1], cfg->speaker_pins[2], 416 cfg->speaker_pins[1], cfg->speaker_pins[2],
397 cfg->speaker_pins[3], cfg->speaker_pins[4]); 417 cfg->speaker_pins[3], cfg->speaker_pins[4]);
398 snd_printd(" hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", 418 codec_info(codec, " hp_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
399 cfg->hp_outs, cfg->hp_pins[0], 419 cfg->hp_outs, cfg->hp_pins[0],
400 cfg->hp_pins[1], cfg->hp_pins[2], 420 cfg->hp_pins[1], cfg->hp_pins[2],
401 cfg->hp_pins[3], cfg->hp_pins[4]); 421 cfg->hp_pins[3], cfg->hp_pins[4]);
402 snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin); 422 codec_info(codec, " mono: mono_out=0x%x\n", cfg->mono_out_pin);
403 if (cfg->dig_outs) 423 if (cfg->dig_outs)
404 snd_printd(" dig-out=0x%x/0x%x\n", 424 codec_info(codec, " dig-out=0x%x/0x%x\n",
405 cfg->dig_out_pins[0], cfg->dig_out_pins[1]); 425 cfg->dig_out_pins[0], cfg->dig_out_pins[1]);
406 snd_printd(" inputs:\n"); 426 codec_info(codec, " inputs:\n");
407 for (i = 0; i < cfg->num_inputs; i++) { 427 for (i = 0; i < cfg->num_inputs; i++) {
408 snd_printd(" %s=0x%x\n", 428 codec_info(codec, " %s=0x%x\n",
409 hda_get_autocfg_input_label(codec, cfg, i), 429 hda_get_autocfg_input_label(codec, cfg, i),
410 cfg->inputs[i].pin); 430 cfg->inputs[i].pin);
411 } 431 }
412 if (cfg->dig_in_pin) 432 if (cfg->dig_in_pin)
413 snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin); 433 codec_info(codec, " dig-in=0x%x\n", cfg->dig_in_pin);
414 434
415 return 0; 435 return 0;
416} 436}
@@ -774,38 +794,33 @@ static void apply_fixup(struct hda_codec *codec, int id, int action, int depth)
774 case HDA_FIXUP_PINS: 794 case HDA_FIXUP_PINS:
775 if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins) 795 if (action != HDA_FIXUP_ACT_PRE_PROBE || !fix->v.pins)
776 break; 796 break;
777 snd_printdd(KERN_INFO SFX 797 codec_dbg(codec, "%s: Apply pincfg for %s\n",
778 "%s: Apply pincfg for %s\n",
779 codec->chip_name, modelname); 798 codec->chip_name, modelname);
780 snd_hda_apply_pincfgs(codec, fix->v.pins); 799 snd_hda_apply_pincfgs(codec, fix->v.pins);
781 break; 800 break;
782 case HDA_FIXUP_VERBS: 801 case HDA_FIXUP_VERBS:
783 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs) 802 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.verbs)
784 break; 803 break;
785 snd_printdd(KERN_INFO SFX 804 codec_dbg(codec, "%s: Apply fix-verbs for %s\n",
786 "%s: Apply fix-verbs for %s\n",
787 codec->chip_name, modelname); 805 codec->chip_name, modelname);
788 snd_hda_add_verbs(codec, fix->v.verbs); 806 snd_hda_add_verbs(codec, fix->v.verbs);
789 break; 807 break;
790 case HDA_FIXUP_FUNC: 808 case HDA_FIXUP_FUNC:
791 if (!fix->v.func) 809 if (!fix->v.func)
792 break; 810 break;
793 snd_printdd(KERN_INFO SFX 811 codec_dbg(codec, "%s: Apply fix-func for %s\n",
794 "%s: Apply fix-func for %s\n",
795 codec->chip_name, modelname); 812 codec->chip_name, modelname);
796 fix->v.func(codec, fix, action); 813 fix->v.func(codec, fix, action);
797 break; 814 break;
798 case HDA_FIXUP_PINCTLS: 815 case HDA_FIXUP_PINCTLS:
799 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.pins) 816 if (action != HDA_FIXUP_ACT_PROBE || !fix->v.pins)
800 break; 817 break;
801 snd_printdd(KERN_INFO SFX 818 codec_dbg(codec, "%s: Apply pinctl for %s\n",
802 "%s: Apply pinctl for %s\n",
803 codec->chip_name, modelname); 819 codec->chip_name, modelname);
804 set_pin_targets(codec, fix->v.pins); 820 set_pin_targets(codec, fix->v.pins);
805 break; 821 break;
806 default: 822 default:
807 snd_printk(KERN_ERR SFX 823 codec_err(codec, "%s: Invalid fixup type %d\n",
808 "%s: Invalid fixup type %d\n",
809 codec->chip_name, fix->type); 824 codec->chip_name, fix->type);
810 break; 825 break;
811 } 826 }
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 0589b39cda6e..8c6c50afc0b7 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -20,7 +20,6 @@
20 */ 20 */
21 21
22#include <linux/input.h> 22#include <linux/input.h>
23#include <linux/pci.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
25#include <linux/workqueue.h> 24#include <linux/workqueue.h>
26#include <linux/export.h> 25#include <linux/export.h>
@@ -140,7 +139,10 @@ static void turn_off_beep(struct hda_beep *beep)
140 139
141static void snd_hda_do_detach(struct hda_beep *beep) 140static void snd_hda_do_detach(struct hda_beep *beep)
142{ 141{
143 input_unregister_device(beep->dev); 142 if (beep->registered)
143 input_unregister_device(beep->dev);
144 else
145 input_free_device(beep->dev);
144 beep->dev = NULL; 146 beep->dev = NULL;
145 turn_off_beep(beep); 147 turn_off_beep(beep);
146} 148}
@@ -149,7 +151,6 @@ static int snd_hda_do_attach(struct hda_beep *beep)
149{ 151{
150 struct input_dev *input_dev; 152 struct input_dev *input_dev;
151 struct hda_codec *codec = beep->codec; 153 struct hda_codec *codec = beep->codec;
152 int err;
153 154
154 input_dev = input_allocate_device(); 155 input_dev = input_allocate_device();
155 if (!input_dev) 156 if (!input_dev)
@@ -167,15 +168,9 @@ static int snd_hda_do_attach(struct hda_beep *beep)
167 input_dev->evbit[0] = BIT_MASK(EV_SND); 168 input_dev->evbit[0] = BIT_MASK(EV_SND);
168 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); 169 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
169 input_dev->event = snd_hda_beep_event; 170 input_dev->event = snd_hda_beep_event;
170 input_dev->dev.parent = &codec->bus->pci->dev; 171 input_dev->dev.parent = &codec->dev;
171 input_set_drvdata(input_dev, beep); 172 input_set_drvdata(input_dev, beep);
172 173
173 err = input_register_device(input_dev);
174 if (err < 0) {
175 input_free_device(input_dev);
176 printk(KERN_INFO "hda_beep: unable to register input device\n");
177 return err;
178 }
179 beep->dev = input_dev; 174 beep->dev = input_dev;
180 return 0; 175 return 0;
181} 176}
@@ -245,6 +240,27 @@ void snd_hda_detach_beep_device(struct hda_codec *codec)
245} 240}
246EXPORT_SYMBOL_GPL(snd_hda_detach_beep_device); 241EXPORT_SYMBOL_GPL(snd_hda_detach_beep_device);
247 242
243int snd_hda_register_beep_device(struct hda_codec *codec)
244{
245 struct hda_beep *beep = codec->beep;
246 int err;
247
248 if (!beep || !beep->dev)
249 return 0;
250
251 err = input_register_device(beep->dev);
252 if (err < 0) {
253 codec_err(codec, "hda_beep: unable to register input device\n");
254 input_free_device(beep->dev);
255 codec->beep = NULL;
256 kfree(beep);
257 return err;
258 }
259 beep->registered = true;
260 return 0;
261}
262EXPORT_SYMBOL_GPL(snd_hda_register_beep_device);
263
248static bool ctl_has_mute(struct snd_kcontrol *kcontrol) 264static bool ctl_has_mute(struct snd_kcontrol *kcontrol)
249{ 265{
250 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 266 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h
index cb88464676b6..a63b5e077332 100644
--- a/sound/pci/hda/hda_beep.h
+++ b/sound/pci/hda/hda_beep.h
@@ -34,6 +34,7 @@ struct hda_beep {
34 char phys[32]; 34 char phys[32];
35 int tone; 35 int tone;
36 hda_nid_t nid; 36 hda_nid_t nid;
37 unsigned int registered:1;
37 unsigned int enabled:1; 38 unsigned int enabled:1;
38 unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */ 39 unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */
39 unsigned int playing:1; 40 unsigned int playing:1;
@@ -45,6 +46,7 @@ struct hda_beep {
45int snd_hda_enable_beep_device(struct hda_codec *codec, int enable); 46int snd_hda_enable_beep_device(struct hda_codec *codec, int enable);
46int snd_hda_attach_beep_device(struct hda_codec *codec, int nid); 47int snd_hda_attach_beep_device(struct hda_codec *codec, int nid);
47void snd_hda_detach_beep_device(struct hda_codec *codec); 48void snd_hda_detach_beep_device(struct hda_codec *codec);
49int snd_hda_register_beep_device(struct hda_codec *codec);
48#else 50#else
49static inline int snd_hda_attach_beep_device(struct hda_codec *codec, int nid) 51static inline int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
50{ 52{
@@ -53,5 +55,9 @@ static inline int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
53static inline void snd_hda_detach_beep_device(struct hda_codec *codec) 55static inline void snd_hda_detach_beep_device(struct hda_codec *codec)
54{ 56{
55} 57}
58static inline int snd_hda_register_beep_device(struct hda_codec *codec)
59{
60 return 0;
61}
56#endif 62#endif
57#endif 63#endif
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index dafcf82139e2..4c20277a6835 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <linux/mutex.h> 26#include <linux/mutex.h>
28#include <linux/module.h> 27#include <linux/module.h>
29#include <linux/async.h> 28#include <linux/async.h>
@@ -68,6 +67,7 @@ static struct hda_vendor_id hda_vendor_ids[] = {
68 { 0x17e8, "Chrontel" }, 67 { 0x17e8, "Chrontel" },
69 { 0x1854, "LG" }, 68 { 0x1854, "LG" },
70 { 0x1aec, "Wolfson Microelectronics" }, 69 { 0x1aec, "Wolfson Microelectronics" },
70 { 0x1af4, "QEMU" },
71 { 0x434d, "C-Media" }, 71 { 0x434d, "C-Media" },
72 { 0x8086, "Intel" }, 72 { 0x8086, "Intel" },
73 { 0x8384, "SigmaTel" }, 73 { 0x8384, "SigmaTel" },
@@ -201,7 +201,7 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int flags,
201 201
202 if ((codec->addr & ~0xf) || (nid & ~0x7f) || 202 if ((codec->addr & ~0xf) || (nid & ~0x7f) ||
203 (verb & ~0xfff) || (parm & ~0xffff)) { 203 (verb & ~0xfff) || (parm & ~0xffff)) {
204 printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x\n", 204 codec_err(codec, "hda-codec: out of range cmd %x:%x:%x:%x\n",
205 codec->addr, nid, verb, parm); 205 codec->addr, nid, verb, parm);
206 return ~0; 206 return ~0;
207 } 207 }
@@ -249,8 +249,8 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
249 snd_hda_power_down(codec); 249 snd_hda_power_down(codec);
250 if (!codec_in_pm(codec) && res && *res == -1 && bus->rirb_error) { 250 if (!codec_in_pm(codec) && res && *res == -1 && bus->rirb_error) {
251 if (bus->response_reset) { 251 if (bus->response_reset) {
252 snd_printd("hda_codec: resetting BUS due to " 252 codec_dbg(codec,
253 "fatal communication error\n"); 253 "resetting BUS due to fatal communication error\n");
254 trace_hda_bus_reset(bus); 254 trace_hda_bus_reset(bus);
255 bus->ops.bus_reset(bus); 255 bus->ops.bus_reset(bus);
256 } 256 }
@@ -475,8 +475,7 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
475 475
476 if (len > 0 && conn_list) { 476 if (len > 0 && conn_list) {
477 if (len > max_conns) { 477 if (len > max_conns) {
478 snd_printk(KERN_ERR "hda_codec: " 478 codec_err(codec, "Too many connections %d for NID 0x%x\n",
479 "Too many connections %d for NID 0x%x\n",
480 len, nid); 479 len, nid);
481 return -EINVAL; 480 return -EINVAL;
482 } 481 }
@@ -574,8 +573,8 @@ int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
574 range_val = !!(parm & (1 << (shift-1))); /* ranges */ 573 range_val = !!(parm & (1 << (shift-1))); /* ranges */
575 val = parm & mask; 574 val = parm & mask;
576 if (val == 0 && null_count++) { /* no second chance */ 575 if (val == 0 && null_count++) { /* no second chance */
577 snd_printdd("hda_codec: " 576 codec_dbg(codec,
578 "invalid CONNECT_LIST verb %x[%i]:%x\n", 577 "invalid CONNECT_LIST verb %x[%i]:%x\n",
579 nid, i, parm); 578 nid, i, parm);
580 return 0; 579 return 0;
581 } 580 }
@@ -583,7 +582,7 @@ int snd_hda_get_raw_connections(struct hda_codec *codec, hda_nid_t nid,
583 if (range_val) { 582 if (range_val) {
584 /* ranges between the previous and this one */ 583 /* ranges between the previous and this one */
585 if (!prev_nid || prev_nid >= val) { 584 if (!prev_nid || prev_nid >= val) {
586 snd_printk(KERN_WARNING "hda_codec: " 585 codec_warn(codec,
587 "invalid dep_range_val %x:%x\n", 586 "invalid dep_range_val %x:%x\n",
588 prev_nid, val); 587 prev_nid, val);
589 continue; 588 continue;
@@ -660,7 +659,7 @@ int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
660 if (!recursive) 659 if (!recursive)
661 return -1; 660 return -1;
662 if (recursive > 10) { 661 if (recursive > 10) {
663 snd_printd("hda_codec: too deep connection for 0x%x\n", nid); 662 codec_dbg(codec, "too deep connection for 0x%x\n", nid);
664 return -1; 663 return -1;
665 } 664 }
666 recursive++; 665 recursive++;
@@ -808,8 +807,7 @@ static int init_unsol_queue(struct hda_bus *bus)
808 807
809 unsol = kzalloc(sizeof(*unsol), GFP_KERNEL); 808 unsol = kzalloc(sizeof(*unsol), GFP_KERNEL);
810 if (!unsol) { 809 if (!unsol) {
811 snd_printk(KERN_ERR "hda_codec: " 810 dev_err(bus->card->dev, "can't allocate unsolicited queue\n");
812 "can't allocate unsolicited queue\n");
813 return -ENOMEM; 811 return -ENOMEM;
814 } 812 }
815 INIT_WORK(&unsol->work, process_unsol_events); 813 INIT_WORK(&unsol->work, process_unsol_events);
@@ -821,51 +819,36 @@ static int init_unsol_queue(struct hda_bus *bus)
821/* 819/*
822 * destructor 820 * destructor
823 */ 821 */
824static void snd_hda_codec_free(struct hda_codec *codec); 822static void snd_hda_bus_free(struct hda_bus *bus)
825
826static int snd_hda_bus_free(struct hda_bus *bus)
827{ 823{
828 struct hda_codec *codec, *n;
829
830 if (!bus) 824 if (!bus)
831 return 0; 825 return;
826
827 WARN_ON(!list_empty(&bus->codec_list));
832 if (bus->workq) 828 if (bus->workq)
833 flush_workqueue(bus->workq); 829 flush_workqueue(bus->workq);
834 if (bus->unsol) 830 if (bus->unsol)
835 kfree(bus->unsol); 831 kfree(bus->unsol);
836 list_for_each_entry_safe(codec, n, &bus->codec_list, list) {
837 snd_hda_codec_free(codec);
838 }
839 if (bus->ops.private_free) 832 if (bus->ops.private_free)
840 bus->ops.private_free(bus); 833 bus->ops.private_free(bus);
841 if (bus->workq) 834 if (bus->workq)
842 destroy_workqueue(bus->workq); 835 destroy_workqueue(bus->workq);
843 836
844 kfree(bus); 837 kfree(bus);
845 return 0;
846} 838}
847 839
848static int snd_hda_bus_dev_free(struct snd_device *device) 840static int snd_hda_bus_dev_free(struct snd_device *device)
849{ 841{
850 struct hda_bus *bus = device->device_data; 842 snd_hda_bus_free(device->device_data);
851 bus->shutdown = 1; 843 return 0;
852 return snd_hda_bus_free(bus);
853} 844}
854 845
855#ifdef CONFIG_SND_HDA_HWDEP 846static int snd_hda_bus_dev_disconnect(struct snd_device *device)
856static int snd_hda_bus_dev_register(struct snd_device *device)
857{ 847{
858 struct hda_bus *bus = device->device_data; 848 struct hda_bus *bus = device->device_data;
859 struct hda_codec *codec; 849 bus->shutdown = 1;
860 list_for_each_entry(codec, &bus->codec_list, list) {
861 snd_hda_hwdep_add_sysfs(codec);
862 snd_hda_hwdep_add_power_sysfs(codec);
863 }
864 return 0; 850 return 0;
865} 851}
866#else
867#define snd_hda_bus_dev_register NULL
868#endif
869 852
870/** 853/**
871 * snd_hda_bus_new - create a HDA bus 854 * snd_hda_bus_new - create a HDA bus
@@ -882,7 +865,7 @@ int snd_hda_bus_new(struct snd_card *card,
882 struct hda_bus *bus; 865 struct hda_bus *bus;
883 int err; 866 int err;
884 static struct snd_device_ops dev_ops = { 867 static struct snd_device_ops dev_ops = {
885 .dev_register = snd_hda_bus_dev_register, 868 .dev_disconnect = snd_hda_bus_dev_disconnect,
886 .dev_free = snd_hda_bus_dev_free, 869 .dev_free = snd_hda_bus_dev_free,
887 }; 870 };
888 871
@@ -896,7 +879,7 @@ int snd_hda_bus_new(struct snd_card *card,
896 879
897 bus = kzalloc(sizeof(*bus), GFP_KERNEL); 880 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
898 if (bus == NULL) { 881 if (bus == NULL) {
899 snd_printk(KERN_ERR "can't allocate struct hda_bus\n"); 882 dev_err(card->dev, "can't allocate struct hda_bus\n");
900 return -ENOMEM; 883 return -ENOMEM;
901 } 884 }
902 885
@@ -915,7 +898,7 @@ int snd_hda_bus_new(struct snd_card *card,
915 "hd-audio%d", card->number); 898 "hd-audio%d", card->number);
916 bus->workq = create_singlethread_workqueue(bus->workq_name); 899 bus->workq = create_singlethread_workqueue(bus->workq_name);
917 if (!bus->workq) { 900 if (!bus->workq) {
918 snd_printk(KERN_ERR "cannot create workqueue %s\n", 901 dev_err(card->dev, "cannot create workqueue %s\n",
919 bus->workq_name); 902 bus->workq_name);
920 kfree(bus); 903 kfree(bus);
921 return -ENOMEM; 904 return -ENOMEM;
@@ -959,7 +942,7 @@ find_codec_preset(struct hda_codec *codec)
959 mutex_lock(&preset_mutex); 942 mutex_lock(&preset_mutex);
960 list_for_each_entry(tbl, &hda_preset_tables, list) { 943 list_for_each_entry(tbl, &hda_preset_tables, list) {
961 if (!try_module_get(tbl->owner)) { 944 if (!try_module_get(tbl->owner)) {
962 snd_printk(KERN_ERR "hda_codec: cannot module_get\n"); 945 codec_err(codec, "cannot module_get\n");
963 continue; 946 continue;
964 } 947 }
965 for (preset = tbl->preset; preset->id; preset++) { 948 for (preset = tbl->preset; preset->id; preset++) {
@@ -1185,7 +1168,7 @@ unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
1185{ 1168{
1186 struct hda_pincfg *pin; 1169 struct hda_pincfg *pin;
1187 1170
1188#ifdef CONFIG_SND_HDA_HWDEP 1171#ifdef CONFIG_SND_HDA_RECONFIG
1189 { 1172 {
1190 unsigned int cfg = 0; 1173 unsigned int cfg = 0;
1191 mutex_lock(&codec->user_mutex); 1174 mutex_lock(&codec->user_mutex);
@@ -1300,7 +1283,7 @@ static void free_hda_cache(struct hda_cache_rec *cache);
1300static void free_init_pincfgs(struct hda_codec *codec) 1283static void free_init_pincfgs(struct hda_codec *codec)
1301{ 1284{
1302 snd_array_free(&codec->driver_pins); 1285 snd_array_free(&codec->driver_pins);
1303#ifdef CONFIG_SND_HDA_HWDEP 1286#ifdef CONFIG_SND_HDA_RECONFIG
1304 snd_array_free(&codec->user_pins); 1287 snd_array_free(&codec->user_pins);
1305#endif 1288#endif
1306 snd_array_free(&codec->init_pins); 1289 snd_array_free(&codec->init_pins);
@@ -1374,6 +1357,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
1374 if (codec->patch_ops.free) 1357 if (codec->patch_ops.free)
1375 codec->patch_ops.free(codec); 1358 codec->patch_ops.free(codec);
1376 hda_call_pm_notify(codec, false); /* cancel leftover refcounts */ 1359 hda_call_pm_notify(codec, false); /* cancel leftover refcounts */
1360 snd_hda_sysfs_clear(codec);
1377 unload_parser(codec); 1361 unload_parser(codec);
1378 module_put(codec->owner); 1362 module_put(codec->owner);
1379 free_hda_cache(&codec->amp_cache); 1363 free_hda_cache(&codec->amp_cache);
@@ -1383,7 +1367,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
1383 kfree(codec->modelname); 1367 kfree(codec->modelname);
1384 kfree(codec->wcaps); 1368 kfree(codec->wcaps);
1385 codec->bus->num_codecs--; 1369 codec->bus->num_codecs--;
1386 kfree(codec); 1370 put_device(&codec->dev);
1387} 1371}
1388 1372
1389static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, 1373static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec,
@@ -1392,6 +1376,38 @@ static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec,
1392static unsigned int hda_set_power_state(struct hda_codec *codec, 1376static unsigned int hda_set_power_state(struct hda_codec *codec,
1393 unsigned int power_state); 1377 unsigned int power_state);
1394 1378
1379static int snd_hda_codec_dev_register(struct snd_device *device)
1380{
1381 struct hda_codec *codec = device->device_data;
1382 int err = device_add(&codec->dev);
1383
1384 if (err < 0)
1385 return err;
1386 snd_hda_register_beep_device(codec);
1387 return 0;
1388}
1389
1390static int snd_hda_codec_dev_disconnect(struct snd_device *device)
1391{
1392 struct hda_codec *codec = device->device_data;
1393
1394 snd_hda_detach_beep_device(codec);
1395 device_del(&codec->dev);
1396 return 0;
1397}
1398
1399static int snd_hda_codec_dev_free(struct snd_device *device)
1400{
1401 snd_hda_codec_free(device->device_data);
1402 return 0;
1403}
1404
1405/* just free the container */
1406static void snd_hda_codec_dev_release(struct device *dev)
1407{
1408 kfree(container_of(dev, struct hda_codec, dev));
1409}
1410
1395/** 1411/**
1396 * snd_hda_codec_new - create a HDA codec 1412 * snd_hda_codec_new - create a HDA codec
1397 * @bus: the bus to assign 1413 * @bus: the bus to assign
@@ -1408,6 +1424,11 @@ int snd_hda_codec_new(struct hda_bus *bus,
1408 char component[31]; 1424 char component[31];
1409 hda_nid_t fg; 1425 hda_nid_t fg;
1410 int err; 1426 int err;
1427 static struct snd_device_ops dev_ops = {
1428 .dev_register = snd_hda_codec_dev_register,
1429 .dev_disconnect = snd_hda_codec_dev_disconnect,
1430 .dev_free = snd_hda_codec_dev_free,
1431 };
1411 1432
1412 if (snd_BUG_ON(!bus)) 1433 if (snd_BUG_ON(!bus))
1413 return -EINVAL; 1434 return -EINVAL;
@@ -1415,17 +1436,27 @@ int snd_hda_codec_new(struct hda_bus *bus,
1415 return -EINVAL; 1436 return -EINVAL;
1416 1437
1417 if (bus->caddr_tbl[codec_addr]) { 1438 if (bus->caddr_tbl[codec_addr]) {
1418 snd_printk(KERN_ERR "hda_codec: " 1439 dev_err(bus->card->dev,
1419 "address 0x%x is already occupied\n", codec_addr); 1440 "address 0x%x is already occupied\n",
1441 codec_addr);
1420 return -EBUSY; 1442 return -EBUSY;
1421 } 1443 }
1422 1444
1423 codec = kzalloc(sizeof(*codec), GFP_KERNEL); 1445 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
1424 if (codec == NULL) { 1446 if (codec == NULL) {
1425 snd_printk(KERN_ERR "can't allocate struct hda_codec\n"); 1447 dev_err(bus->card->dev, "can't allocate struct hda_codec\n");
1426 return -ENOMEM; 1448 return -ENOMEM;
1427 } 1449 }
1428 1450
1451 device_initialize(&codec->dev);
1452 codec->dev.parent = &bus->card->card_dev;
1453 codec->dev.class = sound_class;
1454 codec->dev.release = snd_hda_codec_dev_release;
1455 codec->dev.groups = snd_hda_dev_attr_groups;
1456 dev_set_name(&codec->dev, "hdaudioC%dD%d", bus->card->number,
1457 codec_addr);
1458 dev_set_drvdata(&codec->dev, codec); /* for sysfs */
1459
1429 codec->bus = bus; 1460 codec->bus = bus;
1430 codec->addr = codec_addr; 1461 codec->addr = codec_addr;
1431 mutex_init(&codec->spdif_mutex); 1462 mutex_init(&codec->spdif_mutex);
@@ -1456,11 +1487,13 @@ int snd_hda_codec_new(struct hda_bus *bus,
1456 hda_keep_power_on(codec); 1487 hda_keep_power_on(codec);
1457#endif 1488#endif
1458 1489
1490 snd_hda_sysfs_init(codec);
1491
1459 if (codec->bus->modelname) { 1492 if (codec->bus->modelname) {
1460 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); 1493 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
1461 if (!codec->modelname) { 1494 if (!codec->modelname) {
1462 snd_hda_codec_free(codec); 1495 err = -ENODEV;
1463 return -ENODEV; 1496 goto error;
1464 } 1497 }
1465 } 1498 }
1466 1499
@@ -1484,7 +1517,7 @@ int snd_hda_codec_new(struct hda_bus *bus,
1484 1517
1485 setup_fg_nodes(codec); 1518 setup_fg_nodes(codec);
1486 if (!codec->afg && !codec->mfg) { 1519 if (!codec->afg && !codec->mfg) {
1487 snd_printdd("hda_codec: no AFG or MFG node found\n"); 1520 dev_err(bus->card->dev, "no AFG or MFG node found\n");
1488 err = -ENODEV; 1521 err = -ENODEV;
1489 goto error; 1522 goto error;
1490 } 1523 }
@@ -1492,7 +1525,7 @@ int snd_hda_codec_new(struct hda_bus *bus,
1492 fg = codec->afg ? codec->afg : codec->mfg; 1525 fg = codec->afg ? codec->afg : codec->mfg;
1493 err = read_widget_caps(codec, fg); 1526 err = read_widget_caps(codec, fg);
1494 if (err < 0) { 1527 if (err < 0) {
1495 snd_printk(KERN_ERR "hda_codec: cannot malloc\n"); 1528 dev_err(bus->card->dev, "cannot malloc\n");
1496 goto error; 1529 goto error;
1497 } 1530 }
1498 err = read_pin_defaults(codec); 1531 err = read_pin_defaults(codec);
@@ -1528,6 +1561,10 @@ int snd_hda_codec_new(struct hda_bus *bus,
1528 codec->subsystem_id, codec->revision_id); 1561 codec->subsystem_id, codec->revision_id);
1529 snd_component_add(codec->bus->card, component); 1562 snd_component_add(codec->bus->card, component);
1530 1563
1564 err = snd_device_new(bus->card, SNDRV_DEV_CODEC, codec, &dev_ops);
1565 if (err < 0)
1566 goto error;
1567
1531 if (codecp) 1568 if (codecp)
1532 *codecp = codec; 1569 *codecp = codec;
1533 return 0; 1570 return 0;
@@ -1550,7 +1587,7 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec)
1550 fg = codec->afg ? codec->afg : codec->mfg; 1587 fg = codec->afg ? codec->afg : codec->mfg;
1551 err = read_widget_caps(codec, fg); 1588 err = read_widget_caps(codec, fg);
1552 if (err < 0) { 1589 if (err < 0) {
1553 snd_printk(KERN_ERR "hda_codec: cannot malloc\n"); 1590 codec_err(codec, "cannot malloc\n");
1554 return err; 1591 return err;
1555 } 1592 }
1556 1593
@@ -1627,7 +1664,7 @@ int snd_hda_codec_configure(struct hda_codec *codec)
1627#endif 1664#endif
1628 } 1665 }
1629 if (!patch) { 1666 if (!patch) {
1630 printk(KERN_ERR "hda-codec: No codec parser is available\n"); 1667 codec_err(codec, "No codec parser is available\n");
1631 return -ENODEV; 1668 return -ENODEV;
1632 } 1669 }
1633 } 1670 }
@@ -1711,9 +1748,9 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1711 if (!nid) 1748 if (!nid)
1712 return; 1749 return;
1713 1750
1714 snd_printdd("hda_codec_setup_stream: " 1751 codec_dbg(codec,
1715 "NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n", 1752 "hda_codec_setup_stream: NID=0x%x, stream=0x%x, channel=%d, format=0x%x\n",
1716 nid, stream_tag, channel_id, format); 1753 nid, stream_tag, channel_id, format);
1717 p = get_hda_cvt_setup(codec, nid); 1754 p = get_hda_cvt_setup(codec, nid);
1718 if (!p) 1755 if (!p)
1719 return; 1756 return;
@@ -1760,7 +1797,7 @@ void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid,
1760 if (codec->no_sticky_stream) 1797 if (codec->no_sticky_stream)
1761 do_now = 1; 1798 do_now = 1;
1762 1799
1763 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid); 1800 codec_dbg(codec, "hda_codec_cleanup_stream: NID=0x%x\n", nid);
1764 p = get_hda_cvt_setup(codec, nid); 1801 p = get_hda_cvt_setup(codec, nid);
1765 if (p) { 1802 if (p) {
1766 /* here we just clear the active flag when do_now isn't set; 1803 /* here we just clear the active flag when do_now isn't set;
@@ -2282,9 +2319,9 @@ int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
2282 uinfo->value.integer.min = 0; 2319 uinfo->value.integer.min = 0;
2283 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs); 2320 uinfo->value.integer.max = get_amp_max_value(codec, nid, dir, ofs);
2284 if (!uinfo->value.integer.max) { 2321 if (!uinfo->value.integer.max) {
2285 printk(KERN_WARNING "hda_codec: " 2322 codec_warn(codec,
2286 "num_steps = 0 for NID=0x%x (ctl = %s)\n", nid, 2323 "num_steps = 0 for NID=0x%x (ctl = %s)\n",
2287 kcontrol->id.name); 2324 nid, kcontrol->id.name);
2288 return -EINVAL; 2325 return -EINVAL;
2289 } 2326 }
2290 return 0; 2327 return 0;
@@ -2558,8 +2595,8 @@ int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
2558 item->nid = nid; 2595 item->nid = nid;
2559 return 0; 2596 return 0;
2560 } 2597 }
2561 printk(KERN_ERR "hda-codec: no NID for mapping control %s:%d:%d\n", 2598 codec_err(codec, "no NID for mapping control %s:%d:%d\n",
2562 kctl->id.name, kctl->id.index, index); 2599 kctl->id.name, kctl->id.index, index);
2563 return -EINVAL; 2600 return -EINVAL;
2564} 2601}
2565EXPORT_SYMBOL_GPL(snd_hda_add_nid); 2602EXPORT_SYMBOL_GPL(snd_hda_add_nid);
@@ -2660,6 +2697,7 @@ int snd_hda_codec_reset(struct hda_codec *codec)
2660 bus->pcm_dev_bits); 2697 bus->pcm_dev_bits);
2661 } 2698 }
2662 } 2699 }
2700 snd_hda_detach_beep_device(codec);
2663 if (codec->patch_ops.free) 2701 if (codec->patch_ops.free)
2664 codec->patch_ops.free(codec); 2702 codec->patch_ops.free(codec);
2665 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops)); 2703 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
@@ -2751,7 +2789,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
2751 return -1; 2789 return -1;
2752 if (*step_to_check && *step_to_check != step) { 2790 if (*step_to_check && *step_to_check != step) {
2753 snd_printk(KERN_ERR "hda_codec: Mismatching dB step for vmaster slave (%d!=%d)\n", 2791 snd_printk(KERN_ERR "hda_codec: Mismatching dB step for vmaster slave (%d!=%d)\n",
2754 *step_to_check, step); 2792- *step_to_check, step);
2755 return -1; 2793 return -1;
2756 } 2794 }
2757 *step_to_check = step; 2795 *step_to_check = step;
@@ -2821,7 +2859,7 @@ int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
2821 2859
2822 err = map_slaves(codec, slaves, suffix, check_slave_present, NULL); 2860 err = map_slaves(codec, slaves, suffix, check_slave_present, NULL);
2823 if (err != 1) { 2861 if (err != 1) {
2824 snd_printdd("No slave found for %s\n", name); 2862 codec_dbg(codec, "No slave found for %s\n", name);
2825 return 0; 2863 return 0;
2826 } 2864 }
2827 kctl = snd_ctl_make_virtual_master(name, tlv); 2865 kctl = snd_ctl_make_virtual_master(name, tlv);
@@ -3487,7 +3525,7 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
3487 3525
3488 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx); 3526 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Playback Switch", idx);
3489 if (idx < 0) { 3527 if (idx < 0) {
3490 printk(KERN_ERR "hda_codec: too many IEC958 outputs\n"); 3528 codec_err(codec, "too many IEC958 outputs\n");
3491 return -EBUSY; 3529 return -EBUSY;
3492 } 3530 }
3493 spdif = snd_array_new(&codec->spdif_out); 3531 spdif = snd_array_new(&codec->spdif_out);
@@ -3691,7 +3729,7 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
3691 3729
3692 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0); 3730 idx = find_empty_mixer_ctl_idx(codec, "IEC958 Capture Switch", 0);
3693 if (idx < 0) { 3731 if (idx < 0) {
3694 printk(KERN_ERR "hda_codec: too many IEC958 inputs\n"); 3732 codec_err(codec, "too many IEC958 inputs\n");
3695 return -EBUSY; 3733 return -EBUSY;
3696 } 3734 }
3697 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { 3735 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
@@ -4010,7 +4048,7 @@ static void sync_power_up_states(struct hda_codec *codec)
4010 } 4048 }
4011} 4049}
4012 4050
4013#ifdef CONFIG_SND_HDA_HWDEP 4051#ifdef CONFIG_SND_HDA_RECONFIG
4014/* execute additional init verbs */ 4052/* execute additional init verbs */
4015static void hda_exec_init_verbs(struct hda_codec *codec) 4053static void hda_exec_init_verbs(struct hda_codec *codec)
4016{ 4054{
@@ -4118,12 +4156,13 @@ int snd_hda_build_controls(struct hda_bus *bus)
4118 list_for_each_entry(codec, &bus->codec_list, list) { 4156 list_for_each_entry(codec, &bus->codec_list, list) {
4119 int err = snd_hda_codec_build_controls(codec); 4157 int err = snd_hda_codec_build_controls(codec);
4120 if (err < 0) { 4158 if (err < 0) {
4121 printk(KERN_ERR "hda_codec: cannot build controls " 4159 codec_err(codec,
4122 "for #%d (error %d)\n", codec->addr, err); 4160 "cannot build controls for #%d (error %d)\n",
4161 codec->addr, err);
4123 err = snd_hda_codec_reset(codec); 4162 err = snd_hda_codec_reset(codec);
4124 if (err < 0) { 4163 if (err < 0) {
4125 printk(KERN_ERR 4164 codec_err(codec,
4126 "hda_codec: cannot revert codec\n"); 4165 "cannot revert codec\n");
4127 return err; 4166 return err;
4128 } 4167 }
4129 } 4168 }
@@ -4294,7 +4333,7 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
4294 break; 4333 break;
4295 default: 4334 default:
4296 snd_printdd("invalid format width %d\n", 4335 snd_printdd("invalid format width %d\n",
4297 snd_pcm_format_width(format)); 4336 snd_pcm_format_width(format));
4298 return 0; 4337 return 0;
4299 } 4338 }
4300 4339
@@ -4370,10 +4409,10 @@ int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
4370 rates |= rate_bits[i].alsa_bits; 4409 rates |= rate_bits[i].alsa_bits;
4371 } 4410 }
4372 if (rates == 0) { 4411 if (rates == 0) {
4373 snd_printk(KERN_ERR "hda_codec: rates == 0 " 4412 codec_err(codec,
4374 "(nid=0x%x, val=0x%x, ovrd=%i)\n", 4413 "rates == 0 (nid=0x%x, val=0x%x, ovrd=%i)\n",
4375 nid, val, 4414 nid, val,
4376 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0); 4415 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0);
4377 return -EIO; 4416 return -EIO;
4378 } 4417 }
4379 *ratesp = rates; 4418 *ratesp = rates;
@@ -4433,12 +4472,11 @@ int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
4433 bps = 8; 4472 bps = 8;
4434 } 4473 }
4435 if (formats == 0) { 4474 if (formats == 0) {
4436 snd_printk(KERN_ERR "hda_codec: formats == 0 " 4475 codec_err(codec,
4437 "(nid=0x%x, val=0x%x, ovrd=%i, " 4476 "formats == 0 (nid=0x%x, val=0x%x, ovrd=%i, streams=0x%x)\n",
4438 "streams=0x%x)\n", 4477 nid, val,
4439 nid, val, 4478 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0,
4440 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0, 4479 streams);
4441 streams);
4442 return -EIO; 4480 return -EIO;
4443 } 4481 }
4444 if (formatsp) 4482 if (formatsp)
@@ -4629,7 +4667,7 @@ static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type)
4629 int i; 4667 int i;
4630 4668
4631 if (type >= HDA_PCM_NTYPES) { 4669 if (type >= HDA_PCM_NTYPES) {
4632 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type); 4670 dev_err(bus->card->dev, "Invalid PCM type %d\n", type);
4633 return -EINVAL; 4671 return -EINVAL;
4634 } 4672 }
4635 4673
@@ -4650,10 +4688,11 @@ static int get_empty_pcm_device(struct hda_bus *bus, unsigned int type)
4650 } 4688 }
4651#endif 4689#endif
4652 4690
4653 snd_printk(KERN_WARNING "Too many %s devices\n", 4691 dev_warn(bus->card->dev, "Too many %s devices\n",
4654 snd_hda_pcm_type_name[type]); 4692 snd_hda_pcm_type_name[type]);
4655#ifndef CONFIG_SND_DYNAMIC_MINORS 4693#ifndef CONFIG_SND_DYNAMIC_MINORS
4656 snd_printk(KERN_WARNING "Consider building the kernel with CONFIG_SND_DYNAMIC_MINORS=y\n"); 4694 dev_warn(bus->card->dev,
4695 "Consider building the kernel with CONFIG_SND_DYNAMIC_MINORS=y\n");
4657#endif 4696#endif
4658 return -EAGAIN; 4697 return -EAGAIN;
4659} 4698}
@@ -4691,12 +4730,13 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec)
4691 return 0; 4730 return 0;
4692 err = codec->patch_ops.build_pcms(codec); 4731 err = codec->patch_ops.build_pcms(codec);
4693 if (err < 0) { 4732 if (err < 0) {
4694 printk(KERN_ERR "hda_codec: cannot build PCMs" 4733 codec_err(codec,
4695 "for #%d (error %d)\n", codec->addr, err); 4734 "cannot build PCMs for #%d (error %d)\n",
4735 codec->addr, err);
4696 err = snd_hda_codec_reset(codec); 4736 err = snd_hda_codec_reset(codec);
4697 if (err < 0) { 4737 if (err < 0) {
4698 printk(KERN_ERR 4738 codec_err(codec,
4699 "hda_codec: cannot revert codec\n"); 4739 "cannot revert codec\n");
4700 return err; 4740 return err;
4701 } 4741 }
4702 } 4742 }
@@ -4715,9 +4755,9 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec)
4715 cpcm->device = dev; 4755 cpcm->device = dev;
4716 err = snd_hda_attach_pcm(codec, cpcm); 4756 err = snd_hda_attach_pcm(codec, cpcm);
4717 if (err < 0) { 4757 if (err < 0) {
4718 printk(KERN_ERR "hda_codec: cannot attach " 4758 codec_err(codec,
4719 "PCM stream %d for codec #%d\n", 4759 "cannot attach PCM stream %d for codec #%d\n",
4720 dev, codec->addr); 4760 dev, codec->addr);
4721 continue; /* no fatal error */ 4761 continue; /* no fatal error */
4722 } 4762 }
4723 } 4763 }
@@ -4786,8 +4826,8 @@ int snd_hda_check_board_config(struct hda_codec *codec,
4786 for (i = 0; i < num_configs; i++) { 4826 for (i = 0; i < num_configs; i++) {
4787 if (models[i] && 4827 if (models[i] &&
4788 !strcmp(codec->modelname, models[i])) { 4828 !strcmp(codec->modelname, models[i])) {
4789 snd_printd(KERN_INFO "hda_codec: model '%s' is " 4829 codec_info(codec, "model '%s' is selected\n",
4790 "selected\n", models[i]); 4830 models[i]);
4791 return i; 4831 return i;
4792 } 4832 }
4793 } 4833 }
@@ -4809,10 +4849,9 @@ int snd_hda_check_board_config(struct hda_codec *codec,
4809 sprintf(tmp, "#%d", tbl->value); 4849 sprintf(tmp, "#%d", tbl->value);
4810 model = tmp; 4850 model = tmp;
4811 } 4851 }
4812 snd_printdd(KERN_INFO "hda_codec: model '%s' is selected " 4852 codec_info(codec, "model '%s' is selected for config %x:%x (%s)\n",
4813 "for config %x:%x (%s)\n", 4853 model, tbl->subvendor, tbl->subdevice,
4814 model, tbl->subvendor, tbl->subdevice, 4854 (tbl->name ? tbl->name : "Unknown device"));
4815 (tbl->name ? tbl->name : "Unknown device"));
4816#endif 4855#endif
4817 return tbl->value; 4856 return tbl->value;
4818 } 4857 }
@@ -4870,10 +4909,9 @@ int snd_hda_check_board_codec_sid_config(struct hda_codec *codec,
4870 sprintf(tmp, "#%d", tbl->value); 4909 sprintf(tmp, "#%d", tbl->value);
4871 model = tmp; 4910 model = tmp;
4872 } 4911 }
4873 snd_printdd(KERN_INFO "hda_codec: model '%s' is selected " 4912 codec_info(codec, "model '%s' is selected for config %x:%x (%s)\n",
4874 "for config %x:%x (%s)\n", 4913 model, tbl->subvendor, tbl->subdevice,
4875 model, tbl->subvendor, tbl->subdevice, 4914 (tbl->name ? tbl->name : "Unknown device"));
4876 (tbl->name ? tbl->name : "Unknown device"));
4877#endif 4915#endif
4878 return tbl->value; 4916 return tbl->value;
4879 } 4917 }
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index ab2a444ba501..a4233136cb93 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -271,6 +271,7 @@ struct hda_pcm {
271 271
272/* codec information */ 272/* codec information */
273struct hda_codec { 273struct hda_codec {
274 struct device dev;
274 struct hda_bus *bus; 275 struct hda_bus *bus;
275 unsigned int addr; /* codec addr*/ 276 unsigned int addr; /* codec addr*/
276 struct list_head list; /* list point */ 277 struct list_head list; /* list point */
@@ -332,14 +333,17 @@ struct hda_codec {
332 struct snd_array driver_pins; /* pin configs set by codec parser */ 333 struct snd_array driver_pins; /* pin configs set by codec parser */
333 struct snd_array cvt_setups; /* audio convert setups */ 334 struct snd_array cvt_setups; /* audio convert setups */
334 335
335#ifdef CONFIG_SND_HDA_HWDEP
336 struct mutex user_mutex; 336 struct mutex user_mutex;
337 struct snd_hwdep *hwdep; /* assigned hwdep device */ 337#ifdef CONFIG_SND_HDA_RECONFIG
338 struct snd_array init_verbs; /* additional init verbs */ 338 struct snd_array init_verbs; /* additional init verbs */
339 struct snd_array hints; /* additional hints */ 339 struct snd_array hints; /* additional hints */
340 struct snd_array user_pins; /* default pin configs to override */ 340 struct snd_array user_pins; /* default pin configs to override */
341#endif 341#endif
342 342
343#ifdef CONFIG_SND_HDA_HWDEP
344 struct snd_hwdep *hwdep; /* assigned hwdep device */
345#endif
346
343 /* misc flags */ 347 /* misc flags */
344 unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each 348 unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each
345 * status change 349 * status change
diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c
new file mode 100644
index 000000000000..97993e17f46a
--- /dev/null
+++ b/sound/pci/hda/hda_controller.c
@@ -0,0 +1,2031 @@
1/*
2 *
3 * Implementation of primary alsa driver code base for Intel HD Audio.
4 *
5 * Copyright(c) 2004 Intel Corporation. All rights reserved.
6 *
7 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
8 * PeiSen Hou <pshou@realtek.com.tw>
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 Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 *
21 */
22
23#include <linux/clocksource.h>
24#include <linux/delay.h>
25#include <linux/interrupt.h>
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/pm_runtime.h>
29#include <linux/slab.h>
30#include <sound/core.h>
31#include <sound/initval.h>
32#include "hda_priv.h"
33#include "hda_controller.h"
34
35#define CREATE_TRACE_POINTS
36#include "hda_intel_trace.h"
37
38/* DSP lock helpers */
39#ifdef CONFIG_SND_HDA_DSP_LOADER
40#define dsp_lock_init(dev) mutex_init(&(dev)->dsp_mutex)
41#define dsp_lock(dev) mutex_lock(&(dev)->dsp_mutex)
42#define dsp_unlock(dev) mutex_unlock(&(dev)->dsp_mutex)
43#define dsp_is_locked(dev) ((dev)->locked)
44#else
45#define dsp_lock_init(dev) do {} while (0)
46#define dsp_lock(dev) do {} while (0)
47#define dsp_unlock(dev) do {} while (0)
48#define dsp_is_locked(dev) 0
49#endif
50
51/*
52 * AZX stream operations.
53 */
54
55/* start a stream */
56static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev)
57{
58 /*
59 * Before stream start, initialize parameter
60 */
61 azx_dev->insufficient = 1;
62
63 /* enable SIE */
64 azx_writel(chip, INTCTL,
65 azx_readl(chip, INTCTL) | (1 << azx_dev->index));
66 /* set DMA start and interrupt mask */
67 azx_sd_writeb(chip, azx_dev, SD_CTL,
68 azx_sd_readb(chip, azx_dev, SD_CTL) |
69 SD_CTL_DMA_START | SD_INT_MASK);
70}
71
72/* stop DMA */
73static void azx_stream_clear(struct azx *chip, struct azx_dev *azx_dev)
74{
75 azx_sd_writeb(chip, azx_dev, SD_CTL,
76 azx_sd_readb(chip, azx_dev, SD_CTL) &
77 ~(SD_CTL_DMA_START | SD_INT_MASK));
78 azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK); /* to be sure */
79}
80
81/* stop a stream */
82void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev)
83{
84 azx_stream_clear(chip, azx_dev);
85 /* disable SIE */
86 azx_writel(chip, INTCTL,
87 azx_readl(chip, INTCTL) & ~(1 << azx_dev->index));
88}
89EXPORT_SYMBOL_GPL(azx_stream_stop);
90
91/* reset stream */
92static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
93{
94 unsigned char val;
95 int timeout;
96
97 azx_stream_clear(chip, azx_dev);
98
99 azx_sd_writeb(chip, azx_dev, SD_CTL,
100 azx_sd_readb(chip, azx_dev, SD_CTL) |
101 SD_CTL_STREAM_RESET);
102 udelay(3);
103 timeout = 300;
104 while (!((val = azx_sd_readb(chip, azx_dev, SD_CTL)) &
105 SD_CTL_STREAM_RESET) && --timeout)
106 ;
107 val &= ~SD_CTL_STREAM_RESET;
108 azx_sd_writeb(chip, azx_dev, SD_CTL, val);
109 udelay(3);
110
111 timeout = 300;
112 /* waiting for hardware to report that the stream is out of reset */
113 while (((val = azx_sd_readb(chip, azx_dev, SD_CTL)) &
114 SD_CTL_STREAM_RESET) && --timeout)
115 ;
116
117 /* reset first position - may not be synced with hw at this time */
118 *azx_dev->posbuf = 0;
119}
120
121/*
122 * set up the SD for streaming
123 */
124static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
125{
126 unsigned int val;
127 /* make sure the run bit is zero for SD */
128 azx_stream_clear(chip, azx_dev);
129 /* program the stream_tag */
130 val = azx_sd_readl(chip, azx_dev, SD_CTL);
131 val = (val & ~SD_CTL_STREAM_TAG_MASK) |
132 (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT);
133 if (!azx_snoop(chip))
134 val |= SD_CTL_TRAFFIC_PRIO;
135 azx_sd_writel(chip, azx_dev, SD_CTL, val);
136
137 /* program the length of samples in cyclic buffer */
138 azx_sd_writel(chip, azx_dev, SD_CBL, azx_dev->bufsize);
139
140 /* program the stream format */
141 /* this value needs to be the same as the one programmed */
142 azx_sd_writew(chip, azx_dev, SD_FORMAT, azx_dev->format_val);
143
144 /* program the stream LVI (last valid index) of the BDL */
145 azx_sd_writew(chip, azx_dev, SD_LVI, azx_dev->frags - 1);
146
147 /* program the BDL address */
148 /* lower BDL address */
149 azx_sd_writel(chip, azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
150 /* upper BDL address */
151 azx_sd_writel(chip, azx_dev, SD_BDLPU,
152 upper_32_bits(azx_dev->bdl.addr));
153
154 /* enable the position buffer */
155 if (chip->position_fix[0] != POS_FIX_LPIB ||
156 chip->position_fix[1] != POS_FIX_LPIB) {
157 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
158 azx_writel(chip, DPLBASE,
159 (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
160 }
161
162 /* set the interrupt enable bits in the descriptor control register */
163 azx_sd_writel(chip, azx_dev, SD_CTL,
164 azx_sd_readl(chip, azx_dev, SD_CTL) | SD_INT_MASK);
165
166 return 0;
167}
168
169/* assign a stream for the PCM */
170static inline struct azx_dev *
171azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
172{
173 int dev, i, nums;
174 struct azx_dev *res = NULL;
175 /* make a non-zero unique key for the substream */
176 int key = (substream->pcm->device << 16) | (substream->number << 2) |
177 (substream->stream + 1);
178
179 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
180 dev = chip->playback_index_offset;
181 nums = chip->playback_streams;
182 } else {
183 dev = chip->capture_index_offset;
184 nums = chip->capture_streams;
185 }
186 for (i = 0; i < nums; i++, dev++) {
187 struct azx_dev *azx_dev = &chip->azx_dev[dev];
188 dsp_lock(azx_dev);
189 if (!azx_dev->opened && !dsp_is_locked(azx_dev)) {
190 res = azx_dev;
191 if (res->assigned_key == key) {
192 res->opened = 1;
193 res->assigned_key = key;
194 dsp_unlock(azx_dev);
195 return azx_dev;
196 }
197 }
198 dsp_unlock(azx_dev);
199 }
200 if (res) {
201 dsp_lock(res);
202 res->opened = 1;
203 res->assigned_key = key;
204 dsp_unlock(res);
205 }
206 return res;
207}
208
209/* release the assigned stream */
210static inline void azx_release_device(struct azx_dev *azx_dev)
211{
212 azx_dev->opened = 0;
213}
214
215static cycle_t azx_cc_read(const struct cyclecounter *cc)
216{
217 struct azx_dev *azx_dev = container_of(cc, struct azx_dev, azx_cc);
218 struct snd_pcm_substream *substream = azx_dev->substream;
219 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
220 struct azx *chip = apcm->chip;
221
222 return azx_readl(chip, WALLCLK);
223}
224
225static void azx_timecounter_init(struct snd_pcm_substream *substream,
226 bool force, cycle_t last)
227{
228 struct azx_dev *azx_dev = get_azx_dev(substream);
229 struct timecounter *tc = &azx_dev->azx_tc;
230 struct cyclecounter *cc = &azx_dev->azx_cc;
231 u64 nsec;
232
233 cc->read = azx_cc_read;
234 cc->mask = CLOCKSOURCE_MASK(32);
235
236 /*
237 * Converting from 24 MHz to ns means applying a 125/3 factor.
238 * To avoid any saturation issues in intermediate operations,
239 * the 125 factor is applied first. The division is applied
240 * last after reading the timecounter value.
241 * Applying the 1/3 factor as part of the multiplication
242 * requires at least 20 bits for a decent precision, however
243 * overflows occur after about 4 hours or less, not a option.
244 */
245
246 cc->mult = 125; /* saturation after 195 years */
247 cc->shift = 0;
248
249 nsec = 0; /* audio time is elapsed time since trigger */
250 timecounter_init(tc, cc, nsec);
251 if (force)
252 /*
253 * force timecounter to use predefined value,
254 * used for synchronized starts
255 */
256 tc->cycle_last = last;
257}
258
259static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream,
260 u64 nsec)
261{
262 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
263 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
264 u64 codec_frames, codec_nsecs;
265
266 if (!hinfo->ops.get_delay)
267 return nsec;
268
269 codec_frames = hinfo->ops.get_delay(hinfo, apcm->codec, substream);
270 codec_nsecs = div_u64(codec_frames * 1000000000LL,
271 substream->runtime->rate);
272
273 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
274 return nsec + codec_nsecs;
275
276 return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0;
277}
278
279/*
280 * set up a BDL entry
281 */
282static int setup_bdle(struct azx *chip,
283 struct snd_dma_buffer *dmab,
284 struct azx_dev *azx_dev, u32 **bdlp,
285 int ofs, int size, int with_ioc)
286{
287 u32 *bdl = *bdlp;
288
289 while (size > 0) {
290 dma_addr_t addr;
291 int chunk;
292
293 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
294 return -EINVAL;
295
296 addr = snd_sgbuf_get_addr(dmab, ofs);
297 /* program the address field of the BDL entry */
298 bdl[0] = cpu_to_le32((u32)addr);
299 bdl[1] = cpu_to_le32(upper_32_bits(addr));
300 /* program the size field of the BDL entry */
301 chunk = snd_sgbuf_get_chunk_size(dmab, ofs, size);
302 /* one BDLE cannot cross 4K boundary on CTHDA chips */
303 if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) {
304 u32 remain = 0x1000 - (ofs & 0xfff);
305 if (chunk > remain)
306 chunk = remain;
307 }
308 bdl[2] = cpu_to_le32(chunk);
309 /* program the IOC to enable interrupt
310 * only when the whole fragment is processed
311 */
312 size -= chunk;
313 bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
314 bdl += 4;
315 azx_dev->frags++;
316 ofs += chunk;
317 }
318 *bdlp = bdl;
319 return ofs;
320}
321
322/*
323 * set up BDL entries
324 */
325static int azx_setup_periods(struct azx *chip,
326 struct snd_pcm_substream *substream,
327 struct azx_dev *azx_dev)
328{
329 u32 *bdl;
330 int i, ofs, periods, period_bytes;
331 int pos_adj = 0;
332
333 /* reset BDL address */
334 azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
335 azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
336
337 period_bytes = azx_dev->period_bytes;
338 periods = azx_dev->bufsize / period_bytes;
339
340 /* program the initial BDL entries */
341 bdl = (u32 *)azx_dev->bdl.area;
342 ofs = 0;
343 azx_dev->frags = 0;
344
345 if (chip->bdl_pos_adj)
346 pos_adj = chip->bdl_pos_adj[chip->dev_index];
347 if (!azx_dev->no_period_wakeup && pos_adj > 0) {
348 struct snd_pcm_runtime *runtime = substream->runtime;
349 int pos_align = pos_adj;
350 pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
351 if (!pos_adj)
352 pos_adj = pos_align;
353 else
354 pos_adj = ((pos_adj + pos_align - 1) / pos_align) *
355 pos_align;
356 pos_adj = frames_to_bytes(runtime, pos_adj);
357 if (pos_adj >= period_bytes) {
358 dev_warn(chip->card->dev,"Too big adjustment %d\n",
359 pos_adj);
360 pos_adj = 0;
361 } else {
362 ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
363 azx_dev,
364 &bdl, ofs, pos_adj, true);
365 if (ofs < 0)
366 goto error;
367 }
368 } else
369 pos_adj = 0;
370
371 for (i = 0; i < periods; i++) {
372 if (i == periods - 1 && pos_adj)
373 ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
374 azx_dev, &bdl, ofs,
375 period_bytes - pos_adj, 0);
376 else
377 ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
378 azx_dev, &bdl, ofs,
379 period_bytes,
380 !azx_dev->no_period_wakeup);
381 if (ofs < 0)
382 goto error;
383 }
384 return 0;
385
386 error:
387 dev_err(chip->card->dev, "Too many BDL entries: buffer=%d, period=%d\n",
388 azx_dev->bufsize, period_bytes);
389 return -EINVAL;
390}
391
392/*
393 * PCM ops
394 */
395
396static int azx_pcm_close(struct snd_pcm_substream *substream)
397{
398 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
399 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
400 struct azx *chip = apcm->chip;
401 struct azx_dev *azx_dev = get_azx_dev(substream);
402 unsigned long flags;
403
404 mutex_lock(&chip->open_mutex);
405 spin_lock_irqsave(&chip->reg_lock, flags);
406 azx_dev->substream = NULL;
407 azx_dev->running = 0;
408 spin_unlock_irqrestore(&chip->reg_lock, flags);
409 azx_release_device(azx_dev);
410 hinfo->ops.close(hinfo, apcm->codec, substream);
411 snd_hda_power_down(apcm->codec);
412 mutex_unlock(&chip->open_mutex);
413 return 0;
414}
415
416static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
417 struct snd_pcm_hw_params *hw_params)
418{
419 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
420 struct azx *chip = apcm->chip;
421 int ret;
422
423 dsp_lock(get_azx_dev(substream));
424 if (dsp_is_locked(get_azx_dev(substream))) {
425 ret = -EBUSY;
426 goto unlock;
427 }
428
429 ret = chip->ops->substream_alloc_pages(chip, substream,
430 params_buffer_bytes(hw_params));
431unlock:
432 dsp_unlock(get_azx_dev(substream));
433 return ret;
434}
435
436static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
437{
438 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
439 struct azx_dev *azx_dev = get_azx_dev(substream);
440 struct azx *chip = apcm->chip;
441 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
442 int err;
443
444 /* reset BDL address */
445 dsp_lock(azx_dev);
446 if (!dsp_is_locked(azx_dev)) {
447 azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
448 azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
449 azx_sd_writel(chip, azx_dev, SD_CTL, 0);
450 azx_dev->bufsize = 0;
451 azx_dev->period_bytes = 0;
452 azx_dev->format_val = 0;
453 }
454
455 snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
456
457 err = chip->ops->substream_free_pages(chip, substream);
458 azx_dev->prepared = 0;
459 dsp_unlock(azx_dev);
460 return err;
461}
462
463static int azx_pcm_prepare(struct snd_pcm_substream *substream)
464{
465 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
466 struct azx *chip = apcm->chip;
467 struct azx_dev *azx_dev = get_azx_dev(substream);
468 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
469 struct snd_pcm_runtime *runtime = substream->runtime;
470 unsigned int bufsize, period_bytes, format_val, stream_tag;
471 int err;
472 struct hda_spdif_out *spdif =
473 snd_hda_spdif_out_of_nid(apcm->codec, hinfo->nid);
474 unsigned short ctls = spdif ? spdif->ctls : 0;
475
476 dsp_lock(azx_dev);
477 if (dsp_is_locked(azx_dev)) {
478 err = -EBUSY;
479 goto unlock;
480 }
481
482 azx_stream_reset(chip, azx_dev);
483 format_val = snd_hda_calc_stream_format(runtime->rate,
484 runtime->channels,
485 runtime->format,
486 hinfo->maxbps,
487 ctls);
488 if (!format_val) {
489 dev_err(chip->card->dev,
490 "invalid format_val, rate=%d, ch=%d, format=%d\n",
491 runtime->rate, runtime->channels, runtime->format);
492 err = -EINVAL;
493 goto unlock;
494 }
495
496 bufsize = snd_pcm_lib_buffer_bytes(substream);
497 period_bytes = snd_pcm_lib_period_bytes(substream);
498
499 dev_dbg(chip->card->dev, "azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
500 bufsize, format_val);
501
502 if (bufsize != azx_dev->bufsize ||
503 period_bytes != azx_dev->period_bytes ||
504 format_val != azx_dev->format_val ||
505 runtime->no_period_wakeup != azx_dev->no_period_wakeup) {
506 azx_dev->bufsize = bufsize;
507 azx_dev->period_bytes = period_bytes;
508 azx_dev->format_val = format_val;
509 azx_dev->no_period_wakeup = runtime->no_period_wakeup;
510 err = azx_setup_periods(chip, substream, azx_dev);
511 if (err < 0)
512 goto unlock;
513 }
514
515 /* when LPIB delay correction gives a small negative value,
516 * we ignore it; currently set the threshold statically to
517 * 64 frames
518 */
519 if (runtime->period_size > 64)
520 azx_dev->delay_negative_threshold = -frames_to_bytes(runtime, 64);
521 else
522 azx_dev->delay_negative_threshold = 0;
523
524 /* wallclk has 24Mhz clock source */
525 azx_dev->period_wallclk = (((runtime->period_size * 24000) /
526 runtime->rate) * 1000);
527 azx_setup_controller(chip, azx_dev);
528 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
529 azx_dev->fifo_size =
530 azx_sd_readw(chip, azx_dev, SD_FIFOSIZE) + 1;
531 else
532 azx_dev->fifo_size = 0;
533
534 stream_tag = azx_dev->stream_tag;
535 /* CA-IBG chips need the playback stream starting from 1 */
536 if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) &&
537 stream_tag > chip->capture_streams)
538 stream_tag -= chip->capture_streams;
539 err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,
540 azx_dev->format_val, substream);
541
542 unlock:
543 if (!err)
544 azx_dev->prepared = 1;
545 dsp_unlock(azx_dev);
546 return err;
547}
548
549static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
550{
551 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
552 struct azx *chip = apcm->chip;
553 struct azx_dev *azx_dev;
554 struct snd_pcm_substream *s;
555 int rstart = 0, start, nsync = 0, sbits = 0;
556 int nwait, timeout;
557
558 azx_dev = get_azx_dev(substream);
559 trace_azx_pcm_trigger(chip, azx_dev, cmd);
560
561 if (dsp_is_locked(azx_dev) || !azx_dev->prepared)
562 return -EPIPE;
563
564 switch (cmd) {
565 case SNDRV_PCM_TRIGGER_START:
566 rstart = 1;
567 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
568 case SNDRV_PCM_TRIGGER_RESUME:
569 start = 1;
570 break;
571 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
572 case SNDRV_PCM_TRIGGER_SUSPEND:
573 case SNDRV_PCM_TRIGGER_STOP:
574 start = 0;
575 break;
576 default:
577 return -EINVAL;
578 }
579
580 snd_pcm_group_for_each_entry(s, substream) {
581 if (s->pcm->card != substream->pcm->card)
582 continue;
583 azx_dev = get_azx_dev(s);
584 sbits |= 1 << azx_dev->index;
585 nsync++;
586 snd_pcm_trigger_done(s, substream);
587 }
588
589 spin_lock(&chip->reg_lock);
590
591 /* first, set SYNC bits of corresponding streams */
592 if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC)
593 azx_writel(chip, OLD_SSYNC,
594 azx_readl(chip, OLD_SSYNC) | sbits);
595 else
596 azx_writel(chip, SSYNC, azx_readl(chip, SSYNC) | sbits);
597
598 snd_pcm_group_for_each_entry(s, substream) {
599 if (s->pcm->card != substream->pcm->card)
600 continue;
601 azx_dev = get_azx_dev(s);
602 if (start) {
603 azx_dev->start_wallclk = azx_readl(chip, WALLCLK);
604 if (!rstart)
605 azx_dev->start_wallclk -=
606 azx_dev->period_wallclk;
607 azx_stream_start(chip, azx_dev);
608 } else {
609 azx_stream_stop(chip, azx_dev);
610 }
611 azx_dev->running = start;
612 }
613 spin_unlock(&chip->reg_lock);
614 if (start) {
615 /* wait until all FIFOs get ready */
616 for (timeout = 5000; timeout; timeout--) {
617 nwait = 0;
618 snd_pcm_group_for_each_entry(s, substream) {
619 if (s->pcm->card != substream->pcm->card)
620 continue;
621 azx_dev = get_azx_dev(s);
622 if (!(azx_sd_readb(chip, azx_dev, SD_STS) &
623 SD_STS_FIFO_READY))
624 nwait++;
625 }
626 if (!nwait)
627 break;
628 cpu_relax();
629 }
630 } else {
631 /* wait until all RUN bits are cleared */
632 for (timeout = 5000; timeout; timeout--) {
633 nwait = 0;
634 snd_pcm_group_for_each_entry(s, substream) {
635 if (s->pcm->card != substream->pcm->card)
636 continue;
637 azx_dev = get_azx_dev(s);
638 if (azx_sd_readb(chip, azx_dev, SD_CTL) &
639 SD_CTL_DMA_START)
640 nwait++;
641 }
642 if (!nwait)
643 break;
644 cpu_relax();
645 }
646 }
647 spin_lock(&chip->reg_lock);
648 /* reset SYNC bits */
649 if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC)
650 azx_writel(chip, OLD_SSYNC,
651 azx_readl(chip, OLD_SSYNC) & ~sbits);
652 else
653 azx_writel(chip, SSYNC, azx_readl(chip, SSYNC) & ~sbits);
654 if (start) {
655 azx_timecounter_init(substream, 0, 0);
656 if (nsync > 1) {
657 cycle_t cycle_last;
658
659 /* same start cycle for master and group */
660 azx_dev = get_azx_dev(substream);
661 cycle_last = azx_dev->azx_tc.cycle_last;
662
663 snd_pcm_group_for_each_entry(s, substream) {
664 if (s->pcm->card != substream->pcm->card)
665 continue;
666 azx_timecounter_init(s, 1, cycle_last);
667 }
668 }
669 }
670 spin_unlock(&chip->reg_lock);
671 return 0;
672}
673
674/* get the current DMA position with correction on VIA chips */
675static unsigned int azx_via_get_position(struct azx *chip,
676 struct azx_dev *azx_dev)
677{
678 unsigned int link_pos, mini_pos, bound_pos;
679 unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
680 unsigned int fifo_size;
681
682 link_pos = azx_sd_readl(chip, azx_dev, SD_LPIB);
683 if (azx_dev->substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
684 /* Playback, no problem using link position */
685 return link_pos;
686 }
687
688 /* Capture */
689 /* For new chipset,
690 * use mod to get the DMA position just like old chipset
691 */
692 mod_dma_pos = le32_to_cpu(*azx_dev->posbuf);
693 mod_dma_pos %= azx_dev->period_bytes;
694
695 /* azx_dev->fifo_size can't get FIFO size of in stream.
696 * Get from base address + offset.
697 */
698 fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET);
699
700 if (azx_dev->insufficient) {
701 /* Link position never gather than FIFO size */
702 if (link_pos <= fifo_size)
703 return 0;
704
705 azx_dev->insufficient = 0;
706 }
707
708 if (link_pos <= fifo_size)
709 mini_pos = azx_dev->bufsize + link_pos - fifo_size;
710 else
711 mini_pos = link_pos - fifo_size;
712
713 /* Find nearest previous boudary */
714 mod_mini_pos = mini_pos % azx_dev->period_bytes;
715 mod_link_pos = link_pos % azx_dev->period_bytes;
716 if (mod_link_pos >= fifo_size)
717 bound_pos = link_pos - mod_link_pos;
718 else if (mod_dma_pos >= mod_mini_pos)
719 bound_pos = mini_pos - mod_mini_pos;
720 else {
721 bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes;
722 if (bound_pos >= azx_dev->bufsize)
723 bound_pos = 0;
724 }
725
726 /* Calculate real DMA position we want */
727 return bound_pos + mod_dma_pos;
728}
729
730unsigned int azx_get_position(struct azx *chip,
731 struct azx_dev *azx_dev,
732 bool with_check)
733{
734 struct snd_pcm_substream *substream = azx_dev->substream;
735 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
736 unsigned int pos;
737 int stream = substream->stream;
738 struct hda_pcm_stream *hinfo = apcm->hinfo[stream];
739 int delay = 0;
740
741 switch (chip->position_fix[stream]) {
742 case POS_FIX_LPIB:
743 /* read LPIB */
744 pos = azx_sd_readl(chip, azx_dev, SD_LPIB);
745 break;
746 case POS_FIX_VIACOMBO:
747 pos = azx_via_get_position(chip, azx_dev);
748 break;
749 default:
750 /* use the position buffer */
751 pos = le32_to_cpu(*azx_dev->posbuf);
752 if (with_check && chip->position_fix[stream] == POS_FIX_AUTO) {
753 if (!pos || pos == (u32)-1) {
754 dev_info(chip->card->dev,
755 "Invalid position buffer, using LPIB read method instead.\n");
756 chip->position_fix[stream] = POS_FIX_LPIB;
757 pos = azx_sd_readl(chip, azx_dev, SD_LPIB);
758 } else
759 chip->position_fix[stream] = POS_FIX_POSBUF;
760 }
761 break;
762 }
763
764 if (pos >= azx_dev->bufsize)
765 pos = 0;
766
767 /* calculate runtime delay from LPIB */
768 if (substream->runtime &&
769 chip->position_fix[stream] == POS_FIX_POSBUF &&
770 (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) {
771 unsigned int lpib_pos = azx_sd_readl(chip, azx_dev, SD_LPIB);
772 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
773 delay = pos - lpib_pos;
774 else
775 delay = lpib_pos - pos;
776 if (delay < 0) {
777 if (delay >= azx_dev->delay_negative_threshold)
778 delay = 0;
779 else
780 delay += azx_dev->bufsize;
781 }
782 if (delay >= azx_dev->period_bytes) {
783 dev_info(chip->card->dev,
784 "Unstable LPIB (%d >= %d); disabling LPIB delay counting\n",
785 delay, azx_dev->period_bytes);
786 delay = 0;
787 chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY;
788 }
789 delay = bytes_to_frames(substream->runtime, delay);
790 }
791
792 if (substream->runtime) {
793 if (hinfo->ops.get_delay)
794 delay += hinfo->ops.get_delay(hinfo, apcm->codec,
795 substream);
796 substream->runtime->delay = delay;
797 }
798
799 trace_azx_get_position(chip, azx_dev, pos, delay);
800 return pos;
801}
802EXPORT_SYMBOL_GPL(azx_get_position);
803
804static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
805{
806 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
807 struct azx *chip = apcm->chip;
808 struct azx_dev *azx_dev = get_azx_dev(substream);
809 return bytes_to_frames(substream->runtime,
810 azx_get_position(chip, azx_dev, false));
811}
812
813static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream,
814 struct timespec *ts)
815{
816 struct azx_dev *azx_dev = get_azx_dev(substream);
817 u64 nsec;
818
819 nsec = timecounter_read(&azx_dev->azx_tc);
820 nsec = div_u64(nsec, 3); /* can be optimized */
821 nsec = azx_adjust_codec_delay(substream, nsec);
822
823 *ts = ns_to_timespec(nsec);
824
825 return 0;
826}
827
828static struct snd_pcm_hardware azx_pcm_hw = {
829 .info = (SNDRV_PCM_INFO_MMAP |
830 SNDRV_PCM_INFO_INTERLEAVED |
831 SNDRV_PCM_INFO_BLOCK_TRANSFER |
832 SNDRV_PCM_INFO_MMAP_VALID |
833 /* No full-resume yet implemented */
834 /* SNDRV_PCM_INFO_RESUME |*/
835 SNDRV_PCM_INFO_PAUSE |
836 SNDRV_PCM_INFO_SYNC_START |
837 SNDRV_PCM_INFO_HAS_WALL_CLOCK |
838 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
839 .formats = SNDRV_PCM_FMTBIT_S16_LE,
840 .rates = SNDRV_PCM_RATE_48000,
841 .rate_min = 48000,
842 .rate_max = 48000,
843 .channels_min = 2,
844 .channels_max = 2,
845 .buffer_bytes_max = AZX_MAX_BUF_SIZE,
846 .period_bytes_min = 128,
847 .period_bytes_max = AZX_MAX_BUF_SIZE / 2,
848 .periods_min = 2,
849 .periods_max = AZX_MAX_FRAG,
850 .fifo_size = 0,
851};
852
853static int azx_pcm_open(struct snd_pcm_substream *substream)
854{
855 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
856 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
857 struct azx *chip = apcm->chip;
858 struct azx_dev *azx_dev;
859 struct snd_pcm_runtime *runtime = substream->runtime;
860 unsigned long flags;
861 int err;
862 int buff_step;
863
864 mutex_lock(&chip->open_mutex);
865 azx_dev = azx_assign_device(chip, substream);
866 if (azx_dev == NULL) {
867 mutex_unlock(&chip->open_mutex);
868 return -EBUSY;
869 }
870 runtime->hw = azx_pcm_hw;
871 runtime->hw.channels_min = hinfo->channels_min;
872 runtime->hw.channels_max = hinfo->channels_max;
873 runtime->hw.formats = hinfo->formats;
874 runtime->hw.rates = hinfo->rates;
875 snd_pcm_limit_hw_rates(runtime);
876 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
877
878 /* avoid wrap-around with wall-clock */
879 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME,
880 20,
881 178000000);
882
883 if (chip->align_buffer_size)
884 /* constrain buffer sizes to be multiple of 128
885 bytes. This is more efficient in terms of memory
886 access but isn't required by the HDA spec and
887 prevents users from specifying exact period/buffer
888 sizes. For example for 44.1kHz, a period size set
889 to 20ms will be rounded to 19.59ms. */
890 buff_step = 128;
891 else
892 /* Don't enforce steps on buffer sizes, still need to
893 be multiple of 4 bytes (HDA spec). Tested on Intel
894 HDA controllers, may not work on all devices where
895 option needs to be disabled */
896 buff_step = 4;
897
898 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
899 buff_step);
900 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
901 buff_step);
902 snd_hda_power_up_d3wait(apcm->codec);
903 err = hinfo->ops.open(hinfo, apcm->codec, substream);
904 if (err < 0) {
905 azx_release_device(azx_dev);
906 snd_hda_power_down(apcm->codec);
907 mutex_unlock(&chip->open_mutex);
908 return err;
909 }
910 snd_pcm_limit_hw_rates(runtime);
911 /* sanity check */
912 if (snd_BUG_ON(!runtime->hw.channels_min) ||
913 snd_BUG_ON(!runtime->hw.channels_max) ||
914 snd_BUG_ON(!runtime->hw.formats) ||
915 snd_BUG_ON(!runtime->hw.rates)) {
916 azx_release_device(azx_dev);
917 hinfo->ops.close(hinfo, apcm->codec, substream);
918 snd_hda_power_down(apcm->codec);
919 mutex_unlock(&chip->open_mutex);
920 return -EINVAL;
921 }
922
923 /* disable WALLCLOCK timestamps for capture streams
924 until we figure out how to handle digital inputs */
925 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
926 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK;
927
928 spin_lock_irqsave(&chip->reg_lock, flags);
929 azx_dev->substream = substream;
930 azx_dev->running = 0;
931 spin_unlock_irqrestore(&chip->reg_lock, flags);
932
933 runtime->private_data = azx_dev;
934 snd_pcm_set_sync(substream);
935 mutex_unlock(&chip->open_mutex);
936 return 0;
937}
938
939static int azx_pcm_mmap(struct snd_pcm_substream *substream,
940 struct vm_area_struct *area)
941{
942 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
943 struct azx *chip = apcm->chip;
944 if (chip->ops->pcm_mmap_prepare)
945 chip->ops->pcm_mmap_prepare(substream, area);
946 return snd_pcm_lib_default_mmap(substream, area);
947}
948
949static struct snd_pcm_ops azx_pcm_ops = {
950 .open = azx_pcm_open,
951 .close = azx_pcm_close,
952 .ioctl = snd_pcm_lib_ioctl,
953 .hw_params = azx_pcm_hw_params,
954 .hw_free = azx_pcm_hw_free,
955 .prepare = azx_pcm_prepare,
956 .trigger = azx_pcm_trigger,
957 .pointer = azx_pcm_pointer,
958 .wall_clock = azx_get_wallclock_tstamp,
959 .mmap = azx_pcm_mmap,
960 .page = snd_pcm_sgbuf_ops_page,
961};
962
963static void azx_pcm_free(struct snd_pcm *pcm)
964{
965 struct azx_pcm *apcm = pcm->private_data;
966 if (apcm) {
967 list_del(&apcm->list);
968 kfree(apcm);
969 }
970}
971
972#define MAX_PREALLOC_SIZE (32 * 1024 * 1024)
973
974static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
975 struct hda_pcm *cpcm)
976{
977 struct azx *chip = bus->private_data;
978 struct snd_pcm *pcm;
979 struct azx_pcm *apcm;
980 int pcm_dev = cpcm->device;
981 unsigned int size;
982 int s, err;
983
984 list_for_each_entry(apcm, &chip->pcm_list, list) {
985 if (apcm->pcm->device == pcm_dev) {
986 dev_err(chip->card->dev, "PCM %d already exists\n",
987 pcm_dev);
988 return -EBUSY;
989 }
990 }
991 err = snd_pcm_new(chip->card, cpcm->name, pcm_dev,
992 cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams,
993 cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams,
994 &pcm);
995 if (err < 0)
996 return err;
997 strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
998 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
999 if (apcm == NULL)
1000 return -ENOMEM;
1001 apcm->chip = chip;
1002 apcm->pcm = pcm;
1003 apcm->codec = codec;
1004 pcm->private_data = apcm;
1005 pcm->private_free = azx_pcm_free;
1006 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)
1007 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
1008 list_add_tail(&apcm->list, &chip->pcm_list);
1009 cpcm->pcm = pcm;
1010 for (s = 0; s < 2; s++) {
1011 apcm->hinfo[s] = &cpcm->stream[s];
1012 if (cpcm->stream[s].substreams)
1013 snd_pcm_set_ops(pcm, s, &azx_pcm_ops);
1014 }
1015 /* buffer pre-allocation */
1016 size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024;
1017 if (size > MAX_PREALLOC_SIZE)
1018 size = MAX_PREALLOC_SIZE;
1019 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1020 chip->card->dev,
1021 size, MAX_PREALLOC_SIZE);
1022 /* link to codec */
1023 pcm->dev = &codec->dev;
1024 return 0;
1025}
1026
1027/*
1028 * CORB / RIRB interface
1029 */
1030static int azx_alloc_cmd_io(struct azx *chip)
1031{
1032 int err;
1033
1034 /* single page (at least 4096 bytes) must suffice for both ringbuffes */
1035 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
1036 PAGE_SIZE, &chip->rb);
1037 if (err < 0)
1038 dev_err(chip->card->dev, "cannot allocate CORB/RIRB\n");
1039 return err;
1040}
1041EXPORT_SYMBOL_GPL(azx_alloc_cmd_io);
1042
1043static void azx_init_cmd_io(struct azx *chip)
1044{
1045 int timeout;
1046
1047 spin_lock_irq(&chip->reg_lock);
1048 /* CORB set up */
1049 chip->corb.addr = chip->rb.addr;
1050 chip->corb.buf = (u32 *)chip->rb.area;
1051 azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);
1052 azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));
1053
1054 /* set the corb size to 256 entries (ULI requires explicitly) */
1055 azx_writeb(chip, CORBSIZE, 0x02);
1056 /* set the corb write pointer to 0 */
1057 azx_writew(chip, CORBWP, 0);
1058
1059 /* reset the corb hw read pointer */
1060 azx_writew(chip, CORBRP, ICH6_CORBRP_RST);
1061 for (timeout = 1000; timeout > 0; timeout--) {
1062 if ((azx_readw(chip, CORBRP) & ICH6_CORBRP_RST) == ICH6_CORBRP_RST)
1063 break;
1064 udelay(1);
1065 }
1066 if (timeout <= 0)
1067 dev_err(chip->card->dev, "CORB reset timeout#1, CORBRP = %d\n",
1068 azx_readw(chip, CORBRP));
1069
1070 azx_writew(chip, CORBRP, 0);
1071 for (timeout = 1000; timeout > 0; timeout--) {
1072 if (azx_readw(chip, CORBRP) == 0)
1073 break;
1074 udelay(1);
1075 }
1076 if (timeout <= 0)
1077 dev_err(chip->card->dev, "CORB reset timeout#2, CORBRP = %d\n",
1078 azx_readw(chip, CORBRP));
1079
1080 /* enable corb dma */
1081 azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN);
1082
1083 /* RIRB set up */
1084 chip->rirb.addr = chip->rb.addr + 2048;
1085 chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
1086 chip->rirb.wp = chip->rirb.rp = 0;
1087 memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds));
1088 azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
1089 azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
1090
1091 /* set the rirb size to 256 entries (ULI requires explicitly) */
1092 azx_writeb(chip, RIRBSIZE, 0x02);
1093 /* reset the rirb hw write pointer */
1094 azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST);
1095 /* set N=1, get RIRB response interrupt for new entry */
1096 if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND)
1097 azx_writew(chip, RINTCNT, 0xc0);
1098 else
1099 azx_writew(chip, RINTCNT, 1);
1100 /* enable rirb dma and response irq */
1101 azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN);
1102 spin_unlock_irq(&chip->reg_lock);
1103}
1104EXPORT_SYMBOL_GPL(azx_init_cmd_io);
1105
1106static void azx_free_cmd_io(struct azx *chip)
1107{
1108 spin_lock_irq(&chip->reg_lock);
1109 /* disable ringbuffer DMAs */
1110 azx_writeb(chip, RIRBCTL, 0);
1111 azx_writeb(chip, CORBCTL, 0);
1112 spin_unlock_irq(&chip->reg_lock);
1113}
1114EXPORT_SYMBOL_GPL(azx_free_cmd_io);
1115
1116static unsigned int azx_command_addr(u32 cmd)
1117{
1118 unsigned int addr = cmd >> 28;
1119
1120 if (addr >= AZX_MAX_CODECS) {
1121 snd_BUG();
1122 addr = 0;
1123 }
1124
1125 return addr;
1126}
1127
1128/* send a command */
1129static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
1130{
1131 struct azx *chip = bus->private_data;
1132 unsigned int addr = azx_command_addr(val);
1133 unsigned int wp, rp;
1134
1135 spin_lock_irq(&chip->reg_lock);
1136
1137 /* add command to corb */
1138 wp = azx_readw(chip, CORBWP);
1139 if (wp == 0xffff) {
1140 /* something wrong, controller likely turned to D3 */
1141 spin_unlock_irq(&chip->reg_lock);
1142 return -EIO;
1143 }
1144 wp++;
1145 wp %= ICH6_MAX_CORB_ENTRIES;
1146
1147 rp = azx_readw(chip, CORBRP);
1148 if (wp == rp) {
1149 /* oops, it's full */
1150 spin_unlock_irq(&chip->reg_lock);
1151 return -EAGAIN;
1152 }
1153
1154 chip->rirb.cmds[addr]++;
1155 chip->corb.buf[wp] = cpu_to_le32(val);
1156 azx_writew(chip, CORBWP, wp);
1157
1158 spin_unlock_irq(&chip->reg_lock);
1159
1160 return 0;
1161}
1162
1163#define ICH6_RIRB_EX_UNSOL_EV (1<<4)
1164
1165/* retrieve RIRB entry - called from interrupt handler */
1166static void azx_update_rirb(struct azx *chip)
1167{
1168 unsigned int rp, wp;
1169 unsigned int addr;
1170 u32 res, res_ex;
1171
1172 wp = azx_readw(chip, RIRBWP);
1173 if (wp == 0xffff) {
1174 /* something wrong, controller likely turned to D3 */
1175 return;
1176 }
1177
1178 if (wp == chip->rirb.wp)
1179 return;
1180 chip->rirb.wp = wp;
1181
1182 while (chip->rirb.rp != wp) {
1183 chip->rirb.rp++;
1184 chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES;
1185
1186 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
1187 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
1188 res = le32_to_cpu(chip->rirb.buf[rp]);
1189 addr = res_ex & 0xf;
1190 if ((addr >= AZX_MAX_CODECS) || !(chip->codec_mask & (1 << addr))) {
1191 dev_err(chip->card->dev, "spurious response %#x:%#x, rp = %d, wp = %d",
1192 res, res_ex,
1193 chip->rirb.rp, wp);
1194 snd_BUG();
1195 }
1196 else if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
1197 snd_hda_queue_unsol_event(chip->bus, res, res_ex);
1198 else if (chip->rirb.cmds[addr]) {
1199 chip->rirb.res[addr] = res;
1200 smp_wmb();
1201 chip->rirb.cmds[addr]--;
1202 } else if (printk_ratelimit()) {
1203 dev_err(chip->card->dev, "spurious response %#x:%#x, last cmd=%#08x\n",
1204 res, res_ex,
1205 chip->last_cmd[addr]);
1206 }
1207 }
1208}
1209
1210/* receive a response */
1211static unsigned int azx_rirb_get_response(struct hda_bus *bus,
1212 unsigned int addr)
1213{
1214 struct azx *chip = bus->private_data;
1215 unsigned long timeout;
1216 unsigned long loopcounter;
1217 int do_poll = 0;
1218
1219 again:
1220 timeout = jiffies + msecs_to_jiffies(1000);
1221
1222 for (loopcounter = 0;; loopcounter++) {
1223 if (chip->polling_mode || do_poll) {
1224 spin_lock_irq(&chip->reg_lock);
1225 azx_update_rirb(chip);
1226 spin_unlock_irq(&chip->reg_lock);
1227 }
1228 if (!chip->rirb.cmds[addr]) {
1229 smp_rmb();
1230 bus->rirb_error = 0;
1231
1232 if (!do_poll)
1233 chip->poll_count = 0;
1234 return chip->rirb.res[addr]; /* the last value */
1235 }
1236 if (time_after(jiffies, timeout))
1237 break;
1238 if (bus->needs_damn_long_delay || loopcounter > 3000)
1239 msleep(2); /* temporary workaround */
1240 else {
1241 udelay(10);
1242 cond_resched();
1243 }
1244 }
1245
1246 if (!bus->no_response_fallback)
1247 return -1;
1248
1249 if (!chip->polling_mode && chip->poll_count < 2) {
1250 dev_dbg(chip->card->dev,
1251 "azx_get_response timeout, polling the codec once: last cmd=0x%08x\n",
1252 chip->last_cmd[addr]);
1253 do_poll = 1;
1254 chip->poll_count++;
1255 goto again;
1256 }
1257
1258
1259 if (!chip->polling_mode) {
1260 dev_warn(chip->card->dev,
1261 "azx_get_response timeout, switching to polling mode: last cmd=0x%08x\n",
1262 chip->last_cmd[addr]);
1263 chip->polling_mode = 1;
1264 goto again;
1265 }
1266
1267 if (chip->msi) {
1268 dev_warn(chip->card->dev,
1269 "No response from codec, disabling MSI: last cmd=0x%08x\n",
1270 chip->last_cmd[addr]);
1271 if (chip->ops->disable_msi_reset_irq(chip) &&
1272 chip->ops->disable_msi_reset_irq(chip) < 0) {
1273 bus->rirb_error = 1;
1274 return -1;
1275 }
1276 goto again;
1277 }
1278
1279 if (chip->probing) {
1280 /* If this critical timeout happens during the codec probing
1281 * phase, this is likely an access to a non-existing codec
1282 * slot. Better to return an error and reset the system.
1283 */
1284 return -1;
1285 }
1286
1287 /* a fatal communication error; need either to reset or to fallback
1288 * to the single_cmd mode
1289 */
1290 bus->rirb_error = 1;
1291 if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) {
1292 bus->response_reset = 1;
1293 return -1; /* give a chance to retry */
1294 }
1295
1296 dev_err(chip->card->dev,
1297 "azx_get_response timeout, switching to single_cmd mode: last cmd=0x%08x\n",
1298 chip->last_cmd[addr]);
1299 chip->single_cmd = 1;
1300 bus->response_reset = 0;
1301 /* release CORB/RIRB */
1302 azx_free_cmd_io(chip);
1303 /* disable unsolicited responses */
1304 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL);
1305 return -1;
1306}
1307
1308/*
1309 * Use the single immediate command instead of CORB/RIRB for simplicity
1310 *
1311 * Note: according to Intel, this is not preferred use. The command was
1312 * intended for the BIOS only, and may get confused with unsolicited
1313 * responses. So, we shouldn't use it for normal operation from the
1314 * driver.
1315 * I left the codes, however, for debugging/testing purposes.
1316 */
1317
1318/* receive a response */
1319static int azx_single_wait_for_response(struct azx *chip, unsigned int addr)
1320{
1321 int timeout = 50;
1322
1323 while (timeout--) {
1324 /* check IRV busy bit */
1325 if (azx_readw(chip, IRS) & ICH6_IRS_VALID) {
1326 /* reuse rirb.res as the response return value */
1327 chip->rirb.res[addr] = azx_readl(chip, IR);
1328 return 0;
1329 }
1330 udelay(1);
1331 }
1332 if (printk_ratelimit())
1333 dev_dbg(chip->card->dev, "get_response timeout: IRS=0x%x\n",
1334 azx_readw(chip, IRS));
1335 chip->rirb.res[addr] = -1;
1336 return -EIO;
1337}
1338
1339/* send a command */
1340static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
1341{
1342 struct azx *chip = bus->private_data;
1343 unsigned int addr = azx_command_addr(val);
1344 int timeout = 50;
1345
1346 bus->rirb_error = 0;
1347 while (timeout--) {
1348 /* check ICB busy bit */
1349 if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) {
1350 /* Clear IRV valid bit */
1351 azx_writew(chip, IRS, azx_readw(chip, IRS) |
1352 ICH6_IRS_VALID);
1353 azx_writel(chip, IC, val);
1354 azx_writew(chip, IRS, azx_readw(chip, IRS) |
1355 ICH6_IRS_BUSY);
1356 return azx_single_wait_for_response(chip, addr);
1357 }
1358 udelay(1);
1359 }
1360 if (printk_ratelimit())
1361 dev_dbg(chip->card->dev,
1362 "send_cmd timeout: IRS=0x%x, val=0x%x\n",
1363 azx_readw(chip, IRS), val);
1364 return -EIO;
1365}
1366
1367/* receive a response */
1368static unsigned int azx_single_get_response(struct hda_bus *bus,
1369 unsigned int addr)
1370{
1371 struct azx *chip = bus->private_data;
1372 return chip->rirb.res[addr];
1373}
1374
1375/*
1376 * The below are the main callbacks from hda_codec.
1377 *
1378 * They are just the skeleton to call sub-callbacks according to the
1379 * current setting of chip->single_cmd.
1380 */
1381
1382/* send a command */
1383static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
1384{
1385 struct azx *chip = bus->private_data;
1386
1387 if (chip->disabled)
1388 return 0;
1389 chip->last_cmd[azx_command_addr(val)] = val;
1390 if (chip->single_cmd)
1391 return azx_single_send_cmd(bus, val);
1392 else
1393 return azx_corb_send_cmd(bus, val);
1394}
1395EXPORT_SYMBOL_GPL(azx_send_cmd);
1396
1397/* get a response */
1398static unsigned int azx_get_response(struct hda_bus *bus,
1399 unsigned int addr)
1400{
1401 struct azx *chip = bus->private_data;
1402 if (chip->disabled)
1403 return 0;
1404 if (chip->single_cmd)
1405 return azx_single_get_response(bus, addr);
1406 else
1407 return azx_rirb_get_response(bus, addr);
1408}
1409EXPORT_SYMBOL_GPL(azx_get_response);
1410
1411#ifdef CONFIG_SND_HDA_DSP_LOADER
1412/*
1413 * DSP loading code (e.g. for CA0132)
1414 */
1415
1416/* use the first stream for loading DSP */
1417static struct azx_dev *
1418azx_get_dsp_loader_dev(struct azx *chip)
1419{
1420 return &chip->azx_dev[chip->playback_index_offset];
1421}
1422
1423static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
1424 unsigned int byte_size,
1425 struct snd_dma_buffer *bufp)
1426{
1427 u32 *bdl;
1428 struct azx *chip = bus->private_data;
1429 struct azx_dev *azx_dev;
1430 int err;
1431
1432 azx_dev = azx_get_dsp_loader_dev(chip);
1433
1434 dsp_lock(azx_dev);
1435 spin_lock_irq(&chip->reg_lock);
1436 if (azx_dev->running || azx_dev->locked) {
1437 spin_unlock_irq(&chip->reg_lock);
1438 err = -EBUSY;
1439 goto unlock;
1440 }
1441 azx_dev->prepared = 0;
1442 chip->saved_azx_dev = *azx_dev;
1443 azx_dev->locked = 1;
1444 spin_unlock_irq(&chip->reg_lock);
1445
1446 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV_SG,
1447 byte_size, bufp);
1448 if (err < 0)
1449 goto err_alloc;
1450
1451 azx_dev->bufsize = byte_size;
1452 azx_dev->period_bytes = byte_size;
1453 azx_dev->format_val = format;
1454
1455 azx_stream_reset(chip, azx_dev);
1456
1457 /* reset BDL address */
1458 azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
1459 azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
1460
1461 azx_dev->frags = 0;
1462 bdl = (u32 *)azx_dev->bdl.area;
1463 err = setup_bdle(chip, bufp, azx_dev, &bdl, 0, byte_size, 0);
1464 if (err < 0)
1465 goto error;
1466
1467 azx_setup_controller(chip, azx_dev);
1468 dsp_unlock(azx_dev);
1469 return azx_dev->stream_tag;
1470
1471 error:
1472 chip->ops->dma_free_pages(chip, bufp);
1473 err_alloc:
1474 spin_lock_irq(&chip->reg_lock);
1475 if (azx_dev->opened)
1476 *azx_dev = chip->saved_azx_dev;
1477 azx_dev->locked = 0;
1478 spin_unlock_irq(&chip->reg_lock);
1479 unlock:
1480 dsp_unlock(azx_dev);
1481 return err;
1482}
1483
1484static void azx_load_dsp_trigger(struct hda_bus *bus, bool start)
1485{
1486 struct azx *chip = bus->private_data;
1487 struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
1488
1489 if (start)
1490 azx_stream_start(chip, azx_dev);
1491 else
1492 azx_stream_stop(chip, azx_dev);
1493 azx_dev->running = start;
1494}
1495
1496static void azx_load_dsp_cleanup(struct hda_bus *bus,
1497 struct snd_dma_buffer *dmab)
1498{
1499 struct azx *chip = bus->private_data;
1500 struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
1501
1502 if (!dmab->area || !azx_dev->locked)
1503 return;
1504
1505 dsp_lock(azx_dev);
1506 /* reset BDL address */
1507 azx_sd_writel(chip, azx_dev, SD_BDLPL, 0);
1508 azx_sd_writel(chip, azx_dev, SD_BDLPU, 0);
1509 azx_sd_writel(chip, azx_dev, SD_CTL, 0);
1510 azx_dev->bufsize = 0;
1511 azx_dev->period_bytes = 0;
1512 azx_dev->format_val = 0;
1513
1514 chip->ops->dma_free_pages(chip, dmab);
1515 dmab->area = NULL;
1516
1517 spin_lock_irq(&chip->reg_lock);
1518 if (azx_dev->opened)
1519 *azx_dev = chip->saved_azx_dev;
1520 azx_dev->locked = 0;
1521 spin_unlock_irq(&chip->reg_lock);
1522 dsp_unlock(azx_dev);
1523}
1524#endif /* CONFIG_SND_HDA_DSP_LOADER */
1525
1526int azx_alloc_stream_pages(struct azx *chip)
1527{
1528 int i, err;
1529 struct snd_card *card = chip->card;
1530
1531 for (i = 0; i < chip->num_streams; i++) {
1532 dsp_lock_init(&chip->azx_dev[i]);
1533 /* allocate memory for the BDL for each stream */
1534 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
1535 BDL_SIZE,
1536 &chip->azx_dev[i].bdl);
1537 if (err < 0) {
1538 dev_err(card->dev, "cannot allocate BDL\n");
1539 return -ENOMEM;
1540 }
1541 }
1542 /* allocate memory for the position buffer */
1543 err = chip->ops->dma_alloc_pages(chip, SNDRV_DMA_TYPE_DEV,
1544 chip->num_streams * 8, &chip->posbuf);
1545 if (err < 0) {
1546 dev_err(card->dev, "cannot allocate posbuf\n");
1547 return -ENOMEM;
1548 }
1549
1550 /* allocate CORB/RIRB */
1551 err = azx_alloc_cmd_io(chip);
1552 if (err < 0)
1553 return err;
1554 return 0;
1555}
1556EXPORT_SYMBOL_GPL(azx_alloc_stream_pages);
1557
1558void azx_free_stream_pages(struct azx *chip)
1559{
1560 int i;
1561 if (chip->azx_dev) {
1562 for (i = 0; i < chip->num_streams; i++)
1563 if (chip->azx_dev[i].bdl.area)
1564 chip->ops->dma_free_pages(
1565 chip, &chip->azx_dev[i].bdl);
1566 }
1567 if (chip->rb.area)
1568 chip->ops->dma_free_pages(chip, &chip->rb);
1569 if (chip->posbuf.area)
1570 chip->ops->dma_free_pages(chip, &chip->posbuf);
1571}
1572EXPORT_SYMBOL_GPL(azx_free_stream_pages);
1573
1574/*
1575 * Lowlevel interface
1576 */
1577
1578/* enter link reset */
1579void azx_enter_link_reset(struct azx *chip)
1580{
1581 unsigned long timeout;
1582
1583 /* reset controller */
1584 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);
1585
1586 timeout = jiffies + msecs_to_jiffies(100);
1587 while ((azx_readb(chip, GCTL) & ICH6_GCTL_RESET) &&
1588 time_before(jiffies, timeout))
1589 usleep_range(500, 1000);
1590}
1591EXPORT_SYMBOL_GPL(azx_enter_link_reset);
1592
1593/* exit link reset */
1594static void azx_exit_link_reset(struct azx *chip)
1595{
1596 unsigned long timeout;
1597
1598 azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
1599
1600 timeout = jiffies + msecs_to_jiffies(100);
1601 while (!azx_readb(chip, GCTL) &&
1602 time_before(jiffies, timeout))
1603 usleep_range(500, 1000);
1604}
1605
1606/* reset codec link */
1607static int azx_reset(struct azx *chip, int full_reset)
1608{
1609 if (!full_reset)
1610 goto __skip;
1611
1612 /* clear STATESTS */
1613 azx_writew(chip, STATESTS, STATESTS_INT_MASK);
1614
1615 /* reset controller */
1616 azx_enter_link_reset(chip);
1617
1618 /* delay for >= 100us for codec PLL to settle per spec
1619 * Rev 0.9 section 5.5.1
1620 */
1621 usleep_range(500, 1000);
1622
1623 /* Bring controller out of reset */
1624 azx_exit_link_reset(chip);
1625
1626 /* Brent Chartrand said to wait >= 540us for codecs to initialize */
1627 usleep_range(1000, 1200);
1628
1629 __skip:
1630 /* check to see if controller is ready */
1631 if (!azx_readb(chip, GCTL)) {
1632 dev_dbg(chip->card->dev, "azx_reset: controller not ready!\n");
1633 return -EBUSY;
1634 }
1635
1636 /* Accept unsolicited responses */
1637 if (!chip->single_cmd)
1638 azx_writel(chip, GCTL, azx_readl(chip, GCTL) |
1639 ICH6_GCTL_UNSOL);
1640
1641 /* detect codecs */
1642 if (!chip->codec_mask) {
1643 chip->codec_mask = azx_readw(chip, STATESTS);
1644 dev_dbg(chip->card->dev, "codec_mask = 0x%x\n",
1645 chip->codec_mask);
1646 }
1647
1648 return 0;
1649}
1650
1651/* enable interrupts */
1652static void azx_int_enable(struct azx *chip)
1653{
1654 /* enable controller CIE and GIE */
1655 azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) |
1656 ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN);
1657}
1658
1659/* disable interrupts */
1660static void azx_int_disable(struct azx *chip)
1661{
1662 int i;
1663
1664 /* disable interrupts in stream descriptor */
1665 for (i = 0; i < chip->num_streams; i++) {
1666 struct azx_dev *azx_dev = &chip->azx_dev[i];
1667 azx_sd_writeb(chip, azx_dev, SD_CTL,
1668 azx_sd_readb(chip, azx_dev, SD_CTL) &
1669 ~SD_INT_MASK);
1670 }
1671
1672 /* disable SIE for all streams */
1673 azx_writeb(chip, INTCTL, 0);
1674
1675 /* disable controller CIE and GIE */
1676 azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) &
1677 ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN));
1678}
1679
1680/* clear interrupts */
1681static void azx_int_clear(struct azx *chip)
1682{
1683 int i;
1684
1685 /* clear stream status */
1686 for (i = 0; i < chip->num_streams; i++) {
1687 struct azx_dev *azx_dev = &chip->azx_dev[i];
1688 azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK);
1689 }
1690
1691 /* clear STATESTS */
1692 azx_writew(chip, STATESTS, STATESTS_INT_MASK);
1693
1694 /* clear rirb status */
1695 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
1696
1697 /* clear int status */
1698 azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM);
1699}
1700
1701/*
1702 * reset and start the controller registers
1703 */
1704void azx_init_chip(struct azx *chip, int full_reset)
1705{
1706 if (chip->initialized)
1707 return;
1708
1709 /* reset controller */
1710 azx_reset(chip, full_reset);
1711
1712 /* initialize interrupts */
1713 azx_int_clear(chip);
1714 azx_int_enable(chip);
1715
1716 /* initialize the codec command I/O */
1717 if (!chip->single_cmd)
1718 azx_init_cmd_io(chip);
1719
1720 /* program the position buffer */
1721 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
1722 azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));
1723
1724 chip->initialized = 1;
1725}
1726EXPORT_SYMBOL_GPL(azx_init_chip);
1727
1728void azx_stop_chip(struct azx *chip)
1729{
1730 if (!chip->initialized)
1731 return;
1732
1733 /* disable interrupts */
1734 azx_int_disable(chip);
1735 azx_int_clear(chip);
1736
1737 /* disable CORB/RIRB */
1738 azx_free_cmd_io(chip);
1739
1740 /* disable position buffer */
1741 azx_writel(chip, DPLBASE, 0);
1742 azx_writel(chip, DPUBASE, 0);
1743
1744 chip->initialized = 0;
1745}
1746EXPORT_SYMBOL_GPL(azx_stop_chip);
1747
1748/*
1749 * interrupt handler
1750 */
1751irqreturn_t azx_interrupt(int irq, void *dev_id)
1752{
1753 struct azx *chip = dev_id;
1754 struct azx_dev *azx_dev;
1755 u32 status;
1756 u8 sd_status;
1757 int i;
1758
1759#ifdef CONFIG_PM_RUNTIME
1760 if (chip->driver_caps & AZX_DCAPS_PM_RUNTIME)
1761 if (chip->card->dev->power.runtime_status != RPM_ACTIVE)
1762 return IRQ_NONE;
1763#endif
1764
1765 spin_lock(&chip->reg_lock);
1766
1767 if (chip->disabled) {
1768 spin_unlock(&chip->reg_lock);
1769 return IRQ_NONE;
1770 }
1771
1772 status = azx_readl(chip, INTSTS);
1773 if (status == 0 || status == 0xffffffff) {
1774 spin_unlock(&chip->reg_lock);
1775 return IRQ_NONE;
1776 }
1777
1778 for (i = 0; i < chip->num_streams; i++) {
1779 azx_dev = &chip->azx_dev[i];
1780 if (status & azx_dev->sd_int_sta_mask) {
1781 sd_status = azx_sd_readb(chip, azx_dev, SD_STS);
1782 azx_sd_writeb(chip, azx_dev, SD_STS, SD_INT_MASK);
1783 if (!azx_dev->substream || !azx_dev->running ||
1784 !(sd_status & SD_INT_COMPLETE))
1785 continue;
1786 /* check whether this IRQ is really acceptable */
1787 if (!chip->ops->position_check ||
1788 chip->ops->position_check(chip, azx_dev)) {
1789 spin_unlock(&chip->reg_lock);
1790 snd_pcm_period_elapsed(azx_dev->substream);
1791 spin_lock(&chip->reg_lock);
1792 }
1793 }
1794 }
1795
1796 /* clear rirb int */
1797 status = azx_readb(chip, RIRBSTS);
1798 if (status & RIRB_INT_MASK) {
1799 if (status & RIRB_INT_RESPONSE) {
1800 if (chip->driver_caps & AZX_DCAPS_RIRB_PRE_DELAY)
1801 udelay(80);
1802 azx_update_rirb(chip);
1803 }
1804 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
1805 }
1806
1807 spin_unlock(&chip->reg_lock);
1808
1809 return IRQ_HANDLED;
1810}
1811EXPORT_SYMBOL_GPL(azx_interrupt);
1812
1813/*
1814 * Codec initerface
1815 */
1816
1817/*
1818 * Probe the given codec address
1819 */
1820static int probe_codec(struct azx *chip, int addr)
1821{
1822 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
1823 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
1824 unsigned int res;
1825
1826 mutex_lock(&chip->bus->cmd_mutex);
1827 chip->probing = 1;
1828 azx_send_cmd(chip->bus, cmd);
1829 res = azx_get_response(chip->bus, addr);
1830 chip->probing = 0;
1831 mutex_unlock(&chip->bus->cmd_mutex);
1832 if (res == -1)
1833 return -EIO;
1834 dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr);
1835 return 0;
1836}
1837
1838static void azx_bus_reset(struct hda_bus *bus)
1839{
1840 struct azx *chip = bus->private_data;
1841
1842 bus->in_reset = 1;
1843 azx_stop_chip(chip);
1844 azx_init_chip(chip, 1);
1845#ifdef CONFIG_PM
1846 if (chip->initialized) {
1847 struct azx_pcm *p;
1848 list_for_each_entry(p, &chip->pcm_list, list)
1849 snd_pcm_suspend_all(p->pcm);
1850 snd_hda_suspend(chip->bus);
1851 snd_hda_resume(chip->bus);
1852 }
1853#endif
1854 bus->in_reset = 0;
1855}
1856
1857#ifdef CONFIG_PM
1858/* power-up/down the controller */
1859static void azx_power_notify(struct hda_bus *bus, bool power_up)
1860{
1861 struct azx *chip = bus->private_data;
1862
1863 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
1864 return;
1865
1866 if (power_up)
1867 pm_runtime_get_sync(chip->card->dev);
1868 else
1869 pm_runtime_put_sync(chip->card->dev);
1870}
1871#endif
1872
1873static int get_jackpoll_interval(struct azx *chip)
1874{
1875 int i;
1876 unsigned int j;
1877
1878 if (!chip->jackpoll_ms)
1879 return 0;
1880
1881 i = chip->jackpoll_ms[chip->dev_index];
1882 if (i == 0)
1883 return 0;
1884 if (i < 50 || i > 60000)
1885 j = 0;
1886 else
1887 j = msecs_to_jiffies(i);
1888 if (j == 0)
1889 dev_warn(chip->card->dev,
1890 "jackpoll_ms value out of range: %d\n", i);
1891 return j;
1892}
1893
1894/* Codec initialization */
1895int azx_codec_create(struct azx *chip, const char *model,
1896 unsigned int max_slots,
1897 int *power_save_to)
1898{
1899 struct hda_bus_template bus_temp;
1900 int c, codecs, err;
1901
1902 memset(&bus_temp, 0, sizeof(bus_temp));
1903 bus_temp.private_data = chip;
1904 bus_temp.modelname = model;
1905 bus_temp.pci = chip->pci;
1906 bus_temp.ops.command = azx_send_cmd;
1907 bus_temp.ops.get_response = azx_get_response;
1908 bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
1909 bus_temp.ops.bus_reset = azx_bus_reset;
1910#ifdef CONFIG_PM
1911 bus_temp.power_save = power_save_to;
1912 bus_temp.ops.pm_notify = azx_power_notify;
1913#endif
1914#ifdef CONFIG_SND_HDA_DSP_LOADER
1915 bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare;
1916 bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger;
1917 bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup;
1918#endif
1919
1920 err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
1921 if (err < 0)
1922 return err;
1923
1924 if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) {
1925 dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
1926 chip->bus->needs_damn_long_delay = 1;
1927 }
1928
1929 codecs = 0;
1930 if (!max_slots)
1931 max_slots = AZX_DEFAULT_CODECS;
1932
1933 /* First try to probe all given codec slots */
1934 for (c = 0; c < max_slots; c++) {
1935 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1936 if (probe_codec(chip, c) < 0) {
1937 /* Some BIOSen give you wrong codec addresses
1938 * that don't exist
1939 */
1940 dev_warn(chip->card->dev,
1941 "Codec #%d probe error; disabling it...\n", c);
1942 chip->codec_mask &= ~(1 << c);
1943 /* More badly, accessing to a non-existing
1944 * codec often screws up the controller chip,
1945 * and disturbs the further communications.
1946 * Thus if an error occurs during probing,
1947 * better to reset the controller chip to
1948 * get back to the sanity state.
1949 */
1950 azx_stop_chip(chip);
1951 azx_init_chip(chip, 1);
1952 }
1953 }
1954 }
1955
1956 /* AMD chipsets often cause the communication stalls upon certain
1957 * sequence like the pin-detection. It seems that forcing the synced
1958 * access works around the stall. Grrr...
1959 */
1960 if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) {
1961 dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n");
1962 chip->bus->sync_write = 1;
1963 chip->bus->allow_bus_reset = 1;
1964 }
1965
1966 /* Then create codec instances */
1967 for (c = 0; c < max_slots; c++) {
1968 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1969 struct hda_codec *codec;
1970 err = snd_hda_codec_new(chip->bus, c, &codec);
1971 if (err < 0)
1972 continue;
1973 codec->jackpoll_interval = get_jackpoll_interval(chip);
1974 codec->beep_mode = chip->beep_mode;
1975 codecs++;
1976 }
1977 }
1978 if (!codecs) {
1979 dev_err(chip->card->dev, "no codecs initialized\n");
1980 return -ENXIO;
1981 }
1982 return 0;
1983}
1984EXPORT_SYMBOL_GPL(azx_codec_create);
1985
1986/* configure each codec instance */
1987int azx_codec_configure(struct azx *chip)
1988{
1989 struct hda_codec *codec;
1990 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1991 snd_hda_codec_configure(codec);
1992 }
1993 return 0;
1994}
1995EXPORT_SYMBOL_GPL(azx_codec_configure);
1996
1997/* mixer creation - all stuff is implemented in hda module */
1998int azx_mixer_create(struct azx *chip)
1999{
2000 return snd_hda_build_controls(chip->bus);
2001}
2002EXPORT_SYMBOL_GPL(azx_mixer_create);
2003
2004
2005/* initialize SD streams */
2006int azx_init_stream(struct azx *chip)
2007{
2008 int i;
2009
2010 /* initialize each stream (aka device)
2011 * assign the starting bdl address to each stream (device)
2012 * and initialize
2013 */
2014 for (i = 0; i < chip->num_streams; i++) {
2015 struct azx_dev *azx_dev = &chip->azx_dev[i];
2016 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
2017 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
2018 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
2019 /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
2020 azx_dev->sd_int_sta_mask = 1 << i;
2021 /* stream tag: must be non-zero and unique */
2022 azx_dev->index = i;
2023 azx_dev->stream_tag = i + 1;
2024 }
2025
2026 return 0;
2027}
2028EXPORT_SYMBOL_GPL(azx_init_stream);
2029
2030MODULE_LICENSE("GPL");
2031MODULE_DESCRIPTION("Common HDA driver funcitons");
diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h
new file mode 100644
index 000000000000..1d2e3be2bae6
--- /dev/null
+++ b/sound/pci/hda/hda_controller.h
@@ -0,0 +1,53 @@
1/*
2 * Common functionality for the alsa driver code base for HD Audio.
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 Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef __SOUND_HDA_CONTROLLER_H
16#define __SOUND_HDA_CONTROLLER_H
17
18#include <sound/core.h>
19#include <sound/initval.h>
20#include "hda_codec.h"
21#include "hda_priv.h"
22
23/* PCM setup */
24static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream)
25{
26 return substream->runtime->private_data;
27}
28unsigned int azx_get_position(struct azx *chip,
29 struct azx_dev *azx_dev,
30 bool with_check);
31
32/* Stream control. */
33void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev);
34
35/* Allocation functions. */
36int azx_alloc_stream_pages(struct azx *chip);
37void azx_free_stream_pages(struct azx *chip);
38
39/* Low level azx interface */
40void azx_init_chip(struct azx *chip, int full_reset);
41void azx_stop_chip(struct azx *chip);
42void azx_enter_link_reset(struct azx *chip);
43irqreturn_t azx_interrupt(int irq, void *dev_id);
44
45/* Codec interface */
46int azx_codec_create(struct azx *chip, const char *model,
47 unsigned int max_slots,
48 int *power_save_to);
49int azx_codec_configure(struct azx *chip);
50int azx_mixer_create(struct azx *chip);
51int azx_init_stream(struct azx *chip);
52
53#endif /* __SOUND_HDA_CONTROLLER_H */
diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c
index 79ca80f6c77a..46690a7f48f6 100644
--- a/sound/pci/hda/hda_eld.c
+++ b/sound/pci/hda/hda_eld.c
@@ -153,7 +153,7 @@ static unsigned int hdmi_get_eld_data(struct hda_codec *codec, hda_nid_t nid,
153 val = snd_hda_codec_read(codec, nid, 0, 153 val = snd_hda_codec_read(codec, nid, 0,
154 AC_VERB_GET_HDMI_ELDD, byte_index); 154 AC_VERB_GET_HDMI_ELDD, byte_index);
155#ifdef BE_PARANOID 155#ifdef BE_PARANOID
156 printk(KERN_INFO "HDMI: ELD data byte %d: 0x%x\n", byte_index, val); 156 codec_info(codec, "HDMI: ELD data byte %d: 0x%x\n", byte_index, val);
157#endif 157#endif
158 return val; 158 return val;
159} 159}
@@ -332,11 +332,11 @@ int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
332 size = snd_hdmi_get_eld_size(codec, nid); 332 size = snd_hdmi_get_eld_size(codec, nid);
333 if (size == 0) { 333 if (size == 0) {
334 /* wfg: workaround for ASUS P5E-VM HDMI board */ 334 /* wfg: workaround for ASUS P5E-VM HDMI board */
335 snd_printd(KERN_INFO "HDMI: ELD buf size is 0, force 128\n"); 335 codec_info(codec, "HDMI: ELD buf size is 0, force 128\n");
336 size = 128; 336 size = 128;
337 } 337 }
338 if (size < ELD_FIXED_BYTES || size > ELD_MAX_SIZE) { 338 if (size < ELD_FIXED_BYTES || size > ELD_MAX_SIZE) {
339 snd_printd(KERN_INFO "HDMI: invalid ELD buf size %d\n", size); 339 codec_info(codec, "HDMI: invalid ELD buf size %d\n", size);
340 return -ERANGE; 340 return -ERANGE;
341 } 341 }
342 342
@@ -348,8 +348,7 @@ int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
348 * Just abort. The caller will repoll after a while. 348 * Just abort. The caller will repoll after a while.
349 */ 349 */
350 if (!(val & AC_ELDD_ELD_VALID)) { 350 if (!(val & AC_ELDD_ELD_VALID)) {
351 snd_printd(KERN_INFO 351 codec_info(codec, "HDMI: invalid ELD data byte %d\n", i);
352 "HDMI: invalid ELD data byte %d\n", i);
353 ret = -EINVAL; 352 ret = -EINVAL;
354 goto error; 353 goto error;
355 } 354 }
@@ -361,7 +360,7 @@ int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
361 * correctly writes ELD content before setting ELD_valid bit. 360 * correctly writes ELD content before setting ELD_valid bit.
362 */ 361 */
363 if (!val && !i) { 362 if (!val && !i) {
364 snd_printdd(KERN_INFO "HDMI: 0 ELD data\n"); 363 codec_dbg(codec, "HDMI: 0 ELD data\n");
365 ret = -EINVAL; 364 ret = -EINVAL;
366 goto error; 365 goto error;
367 } 366 }
@@ -681,7 +680,7 @@ int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
681 spkalloc = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SPEAKER_ALLOCATION, 0); 680 spkalloc = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SPEAKER_ALLOCATION, 0);
682 681
683 if (spkalloc <= 0) { 682 if (spkalloc <= 0) {
684 snd_printd(KERN_INFO "HDMI ATI/AMD: no speaker allocation for ELD\n"); 683 codec_info(codec, "HDMI ATI/AMD: no speaker allocation for ELD\n");
685 return -EINVAL; 684 return -EINVAL;
686 } 685 }
687 686
@@ -722,7 +721,7 @@ int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
722 sink_desc_len = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0); 721 sink_desc_len = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
723 722
724 if (sink_desc_len > ELD_MAX_MNL) { 723 if (sink_desc_len > ELD_MAX_MNL) {
725 snd_printd(KERN_INFO "HDMI ATI/AMD: Truncating HDMI sink description with length %d\n", 724 codec_info(codec, "HDMI ATI/AMD: Truncating HDMI sink description with length %d\n",
726 sink_desc_len); 725 sink_desc_len);
727 sink_desc_len = ELD_MAX_MNL; 726 sink_desc_len = ELD_MAX_MNL;
728 } 727 }
@@ -764,7 +763,7 @@ int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
764 } 763 }
765 764
766 if (pos == ELD_FIXED_BYTES + sink_desc_len) { 765 if (pos == ELD_FIXED_BYTES + sink_desc_len) {
767 snd_printd(KERN_INFO "HDMI ATI/AMD: no audio descriptors for ELD\n"); 766 codec_info(codec, "HDMI ATI/AMD: no audio descriptors for ELD\n");
768 return -EINVAL; 767 return -EINVAL;
769 } 768 }
770 769
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index d9a09bdd09db..16133881e967 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -79,7 +79,7 @@ static void free_kctls(struct hda_gen_spec *spec)
79 snd_array_free(&spec->kctls); 79 snd_array_free(&spec->kctls);
80} 80}
81 81
82void snd_hda_gen_spec_free(struct hda_gen_spec *spec) 82static void snd_hda_gen_spec_free(struct hda_gen_spec *spec)
83{ 83{
84 if (!spec) 84 if (!spec)
85 return; 85 return;
@@ -87,7 +87,6 @@ void snd_hda_gen_spec_free(struct hda_gen_spec *spec)
87 snd_array_free(&spec->paths); 87 snd_array_free(&spec->paths);
88 snd_array_free(&spec->loopback_list); 88 snd_array_free(&spec->loopback_list);
89} 89}
90EXPORT_SYMBOL_GPL(snd_hda_gen_spec_free);
91 90
92/* 91/*
93 * store user hints 92 * store user hints
@@ -347,7 +346,8 @@ static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
347 return is_ctl_used(codec, val, type); 346 return is_ctl_used(codec, val, type);
348} 347}
349 348
350static void print_nid_path(const char *pfx, struct nid_path *path) 349static void print_nid_path(struct hda_codec *codec,
350 const char *pfx, struct nid_path *path)
351{ 351{
352 char buf[40]; 352 char buf[40];
353 int i; 353 int i;
@@ -359,7 +359,7 @@ static void print_nid_path(const char *pfx, struct nid_path *path)
359 sprintf(tmp, ":%02x", path->path[i]); 359 sprintf(tmp, ":%02x", path->path[i]);
360 strlcat(buf, tmp, sizeof(buf)); 360 strlcat(buf, tmp, sizeof(buf));
361 } 361 }
362 snd_printdd("%s path: depth=%d %s\n", pfx, path->depth, buf); 362 codec_dbg(codec, "%s path: depth=%d %s\n", pfx, path->depth, buf);
363} 363}
364 364
365/* called recursively */ 365/* called recursively */
@@ -762,7 +762,7 @@ void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
762 AC_PWRST_D0); 762 AC_PWRST_D0);
763 } 763 }
764 if (enable && path->multi[i]) 764 if (enable && path->multi[i])
765 snd_hda_codec_write_cache(codec, nid, 0, 765 snd_hda_codec_update_cache(codec, nid, 0,
766 AC_VERB_SET_CONNECT_SEL, 766 AC_VERB_SET_CONNECT_SEL,
767 path->idx[i]); 767 path->idx[i]);
768 if (has_amp_in(codec, path, i)) 768 if (has_amp_in(codec, path, i))
@@ -1261,7 +1261,7 @@ static int try_assign_dacs(struct hda_codec *codec, int num_outs,
1261 dac = dacs[i] = 0; 1261 dac = dacs[i] = 0;
1262 badness += bad->no_dac; 1262 badness += bad->no_dac;
1263 } else { 1263 } else {
1264 /* print_nid_path("output", path); */ 1264 /* print_nid_path(codec, "output", path); */
1265 path->active = true; 1265 path->active = true;
1266 path_idx[i] = snd_hda_get_path_idx(codec, path); 1266 path_idx[i] = snd_hda_get_path_idx(codec, path);
1267 badness += assign_out_path_ctls(codec, path); 1267 badness += assign_out_path_ctls(codec, path);
@@ -1388,7 +1388,7 @@ static int fill_multi_ios(struct hda_codec *codec,
1388 badness++; 1388 badness++;
1389 continue; 1389 continue;
1390 } 1390 }
1391 /* print_nid_path("multiio", path); */ 1391 /* print_nid_path(codec, "multiio", path); */
1392 spec->multi_io[spec->multi_ios].pin = nid; 1392 spec->multi_io[spec->multi_ios].pin = nid;
1393 spec->multi_io[spec->multi_ios].dac = dac; 1393 spec->multi_io[spec->multi_ios].dac = dac;
1394 spec->out_paths[cfg->line_outs + spec->multi_ios] = 1394 spec->out_paths[cfg->line_outs + spec->multi_ios] =
@@ -1445,7 +1445,7 @@ static bool map_singles(struct hda_codec *codec, int outs,
1445 if (path) { 1445 if (path) {
1446 dacs[i] = dac; 1446 dacs[i] = dac;
1447 found = true; 1447 found = true;
1448 /* print_nid_path("output", path); */ 1448 /* print_nid_path(codec, "output", path); */
1449 path->active = true; 1449 path->active = true;
1450 path_idx[i] = snd_hda_get_path_idx(codec, path); 1450 path_idx[i] = snd_hda_get_path_idx(codec, path);
1451 } 1451 }
@@ -1483,7 +1483,7 @@ static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1483 } 1483 }
1484 if (!path) 1484 if (!path)
1485 return 0; 1485 return 0;
1486 /* print_nid_path("output-aamix", path); */ 1486 /* print_nid_path(codec, "output-aamix", path); */
1487 path->active = false; /* unused as default */ 1487 path->active = false; /* unused as default */
1488 return snd_hda_get_path_idx(codec, path); 1488 return snd_hda_get_path_idx(codec, path);
1489} 1489}
@@ -1700,7 +1700,7 @@ static int fill_and_eval_dacs(struct hda_codec *codec,
1700#define DEBUG_BADNESS 1700#define DEBUG_BADNESS
1701 1701
1702#ifdef DEBUG_BADNESS 1702#ifdef DEBUG_BADNESS
1703#define debug_badness snd_printdd 1703#define debug_badness(fmt, args...) codec_dbg(codec, fmt, ##args)
1704#else 1704#else
1705#define debug_badness(...) 1705#define debug_badness(...)
1706#endif 1706#endif
@@ -1713,7 +1713,7 @@ static inline void print_nid_path_idx(struct hda_codec *codec,
1713 1713
1714 path = snd_hda_get_path_from_idx(codec, idx); 1714 path = snd_hda_get_path_from_idx(codec, idx);
1715 if (path) 1715 if (path)
1716 print_nid_path(pfx, path); 1716 print_nid_path(codec, pfx, path);
1717} 1717}
1718 1718
1719static void debug_show_configs(struct hda_codec *codec, 1719static void debug_show_configs(struct hda_codec *codec,
@@ -1781,7 +1781,7 @@ static void fill_all_dac_nids(struct hda_codec *codec)
1781 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT) 1781 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
1782 continue; 1782 continue;
1783 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) { 1783 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
1784 snd_printk(KERN_ERR "hda: Too many DACs!\n"); 1784 codec_err(codec, "Too many DACs!\n");
1785 break; 1785 break;
1786 } 1786 }
1787 spec->all_dacs[spec->num_all_dacs++] = nid; 1787 spec->all_dacs[spec->num_all_dacs++] = nid;
@@ -2430,7 +2430,7 @@ static int create_hp_mic(struct hda_codec *codec)
2430 spec->hp_mic_pin = nid; 2430 spec->hp_mic_pin = nid;
2431 /* we can't handle auto-mic together with HP-mic */ 2431 /* we can't handle auto-mic together with HP-mic */
2432 spec->suppress_auto_mic = 1; 2432 spec->suppress_auto_mic = 1;
2433 snd_printdd("hda-codec: Enable shared I/O jack on NID 0x%x\n", nid); 2433 codec_dbg(codec, "Enable shared I/O jack on NID 0x%x\n", nid);
2434 return 0; 2434 return 0;
2435} 2435}
2436 2436
@@ -2884,7 +2884,7 @@ static int new_analog_input(struct hda_codec *codec, int input_idx,
2884 path = snd_hda_add_new_path(codec, pin, mix_nid, 0); 2884 path = snd_hda_add_new_path(codec, pin, mix_nid, 0);
2885 if (!path) 2885 if (!path)
2886 return -EINVAL; 2886 return -EINVAL;
2887 print_nid_path("loopback", path); 2887 print_nid_path(codec, "loopback", path);
2888 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path); 2888 spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path);
2889 2889
2890 idx = path->idx[path->depth - 1]; 2890 idx = path->idx[path->depth - 1];
@@ -2912,7 +2912,7 @@ static int new_analog_input(struct hda_codec *codec, int input_idx,
2912 path = snd_hda_add_new_path(codec, spec->mixer_nid, 2912 path = snd_hda_add_new_path(codec, spec->mixer_nid,
2913 spec->mixer_merge_nid, 0); 2913 spec->mixer_merge_nid, 0);
2914 if (path) { 2914 if (path) {
2915 print_nid_path("loopback-merge", path); 2915 print_nid_path(codec, "loopback-merge", path);
2916 path->active = true; 2916 path->active = true;
2917 spec->loopback_merge_path = 2917 spec->loopback_merge_path =
2918 snd_hda_get_path_idx(codec, path); 2918 snd_hda_get_path_idx(codec, path);
@@ -2991,7 +2991,7 @@ static int check_dyn_adc_switch(struct hda_codec *codec)
2991 } 2991 }
2992 } 2992 }
2993 2993
2994 snd_printdd("hda-codec: enabling ADC switching\n"); 2994 codec_dbg(codec, "enabling ADC switching\n");
2995 spec->dyn_adc_switch = 1; 2995 spec->dyn_adc_switch = 1;
2996 } else if (nums != spec->num_adc_nids) { 2996 } else if (nums != spec->num_adc_nids) {
2997 /* shrink the invalid adcs and input paths */ 2997 /* shrink the invalid adcs and input paths */
@@ -3015,7 +3015,7 @@ static int check_dyn_adc_switch(struct hda_codec *codec)
3015 3015
3016 if (imux->num_items == 1 || 3016 if (imux->num_items == 1 ||
3017 (imux->num_items == 2 && spec->hp_mic)) { 3017 (imux->num_items == 2 && spec->hp_mic)) {
3018 snd_printdd("hda-codec: reducing to a single ADC\n"); 3018 codec_dbg(codec, "reducing to a single ADC\n");
3019 spec->num_adc_nids = 1; /* reduce to a single ADC */ 3019 spec->num_adc_nids = 1; /* reduce to a single ADC */
3020 } 3020 }
3021 3021
@@ -3046,7 +3046,7 @@ static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin,
3046 path = snd_hda_add_new_path(codec, pin, adc, anchor); 3046 path = snd_hda_add_new_path(codec, pin, adc, anchor);
3047 if (!path) 3047 if (!path)
3048 continue; 3048 continue;
3049 print_nid_path("input", path); 3049 print_nid_path(codec, "input", path);
3050 spec->input_paths[imux_idx][c] = 3050 spec->input_paths[imux_idx][c] =
3051 snd_hda_get_path_idx(codec, path); 3051 snd_hda_get_path_idx(codec, path);
3052 3052
@@ -3712,7 +3712,7 @@ static void parse_digital(struct hda_codec *codec)
3712 path = snd_hda_add_new_path(codec, dig_nid, pin, 0); 3712 path = snd_hda_add_new_path(codec, dig_nid, pin, 0);
3713 if (!path) 3713 if (!path)
3714 continue; 3714 continue;
3715 print_nid_path("digout", path); 3715 print_nid_path(codec, "digout", path);
3716 path->active = true; 3716 path->active = true;
3717 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path); 3717 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
3718 set_pin_target(codec, pin, PIN_OUT, false); 3718 set_pin_target(codec, pin, PIN_OUT, false);
@@ -3739,7 +3739,7 @@ static void parse_digital(struct hda_codec *codec)
3739 continue; 3739 continue;
3740 path = snd_hda_add_new_path(codec, pin, dig_nid, 0); 3740 path = snd_hda_add_new_path(codec, pin, dig_nid, 0);
3741 if (path) { 3741 if (path) {
3742 print_nid_path("digin", path); 3742 print_nid_path(codec, "digin", path);
3743 path->active = true; 3743 path->active = true;
3744 spec->dig_in_nid = dig_nid; 3744 spec->dig_in_nid = dig_nid;
3745 spec->digin_path = snd_hda_get_path_idx(codec, path); 3745 spec->digin_path = snd_hda_get_path_idx(codec, path);
@@ -4170,8 +4170,7 @@ static int check_auto_mute_availability(struct hda_codec *codec)
4170 hda_nid_t nid = cfg->hp_pins[i]; 4170 hda_nid_t nid = cfg->hp_pins[i];
4171 if (!is_jack_detectable(codec, nid)) 4171 if (!is_jack_detectable(codec, nid))
4172 continue; 4172 continue;
4173 snd_printdd("hda-codec: Enable HP auto-muting on NID 0x%x\n", 4173 codec_dbg(codec, "Enable HP auto-muting on NID 0x%x\n", nid);
4174 nid);
4175 snd_hda_jack_detect_enable_callback(codec, nid, HDA_GEN_HP_EVENT, 4174 snd_hda_jack_detect_enable_callback(codec, nid, HDA_GEN_HP_EVENT,
4176 call_hp_automute); 4175 call_hp_automute);
4177 spec->detect_hp = 1; 4176 spec->detect_hp = 1;
@@ -4183,7 +4182,7 @@ static int check_auto_mute_availability(struct hda_codec *codec)
4183 hda_nid_t nid = cfg->line_out_pins[i]; 4182 hda_nid_t nid = cfg->line_out_pins[i];
4184 if (!is_jack_detectable(codec, nid)) 4183 if (!is_jack_detectable(codec, nid))
4185 continue; 4184 continue;
4186 snd_printdd("hda-codec: Enable Line-Out auto-muting on NID 0x%x\n", nid); 4185 codec_dbg(codec, "Enable Line-Out auto-muting on NID 0x%x\n", nid);
4187 snd_hda_jack_detect_enable_callback(codec, nid, 4186 snd_hda_jack_detect_enable_callback(codec, nid,
4188 HDA_GEN_FRONT_EVENT, 4187 HDA_GEN_FRONT_EVENT,
4189 call_line_automute); 4188 call_line_automute);
@@ -4303,7 +4302,7 @@ static int check_auto_mic_availability(struct hda_codec *codec)
4303 spec->auto_mic = 1; 4302 spec->auto_mic = 1;
4304 spec->num_adc_nids = 1; 4303 spec->num_adc_nids = 1;
4305 spec->cur_mux[0] = spec->am_entry[0].idx; 4304 spec->cur_mux[0] = spec->am_entry[0].idx;
4306 snd_printdd("hda-codec: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", 4305 codec_dbg(codec, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
4307 spec->am_entry[0].pin, 4306 spec->am_entry[0].pin,
4308 spec->am_entry[1].pin, 4307 spec->am_entry[1].pin,
4309 spec->am_entry[2].pin); 4308 spec->am_entry[2].pin);
@@ -5350,7 +5349,7 @@ EXPORT_SYMBOL_GPL(snd_hda_gen_init);
5350 */ 5349 */
5351void snd_hda_gen_free(struct hda_codec *codec) 5350void snd_hda_gen_free(struct hda_codec *codec)
5352{ 5351{
5353 snd_hda_detach_beep_device(codec); 5352 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
5354 snd_hda_gen_spec_free(codec->spec); 5353 snd_hda_gen_spec_free(codec->spec);
5355 kfree(codec->spec); 5354 kfree(codec->spec);
5356 codec->spec = NULL; 5355 codec->spec = NULL;
diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h
index c908afbe4d94..bb2dea743986 100644
--- a/sound/pci/hda/hda_generic.h
+++ b/sound/pci/hda/hda_generic.h
@@ -297,7 +297,6 @@ struct hda_gen_spec {
297}; 297};
298 298
299int snd_hda_gen_spec_init(struct hda_gen_spec *spec); 299int snd_hda_gen_spec_init(struct hda_gen_spec *spec);
300void snd_hda_gen_spec_free(struct hda_gen_spec *spec);
301 300
302int snd_hda_gen_init(struct hda_codec *codec); 301int snd_hda_gen_init(struct hda_codec *codec);
303void snd_hda_gen_free(struct hda_codec *codec); 302void snd_hda_gen_free(struct hda_codec *codec);
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index 72d8389fb399..014a7849e8fd 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -20,24 +20,13 @@
20 20
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/pci.h>
24#include <linux/compat.h> 23#include <linux/compat.h>
25#include <linux/mutex.h>
26#include <linux/ctype.h>
27#include <linux/string.h>
28#include <linux/export.h>
29#include <sound/core.h> 24#include <sound/core.h>
30#include "hda_codec.h" 25#include "hda_codec.h"
31#include "hda_local.h" 26#include "hda_local.h"
32#include <sound/hda_hwdep.h> 27#include <sound/hda_hwdep.h>
33#include <sound/minors.h> 28#include <sound/minors.h>
34 29
35/* hint string pair */
36struct hda_hint {
37 const char *key;
38 const char *val; /* contained in the same alloc as key */
39};
40
41/* 30/*
42 * write/read an out-of-bound verb 31 * write/read an out-of-bound verb
43 */ 32 */
@@ -105,26 +94,6 @@ static int hda_hwdep_open(struct snd_hwdep *hw, struct file *file)
105 return 0; 94 return 0;
106} 95}
107 96
108static void clear_hwdep_elements(struct hda_codec *codec)
109{
110 int i;
111
112 /* clear init verbs */
113 snd_array_free(&codec->init_verbs);
114 /* clear hints */
115 for (i = 0; i < codec->hints.used; i++) {
116 struct hda_hint *hint = snd_array_elem(&codec->hints, i);
117 kfree(hint->key); /* we don't need to free hint->val */
118 }
119 snd_array_free(&codec->hints);
120 snd_array_free(&codec->user_pins);
121}
122
123static void hwdep_free(struct snd_hwdep *hwdep)
124{
125 clear_hwdep_elements(hwdep->private_data);
126}
127
128int snd_hda_create_hwdep(struct hda_codec *codec) 97int snd_hda_create_hwdep(struct hda_codec *codec)
129{ 98{
130 char hwname[16]; 99 char hwname[16];
@@ -139,8 +108,8 @@ int snd_hda_create_hwdep(struct hda_codec *codec)
139 sprintf(hwdep->name, "HDA Codec %d", codec->addr); 108 sprintf(hwdep->name, "HDA Codec %d", codec->addr);
140 hwdep->iface = SNDRV_HWDEP_IFACE_HDA; 109 hwdep->iface = SNDRV_HWDEP_IFACE_HDA;
141 hwdep->private_data = codec; 110 hwdep->private_data = codec;
142 hwdep->private_free = hwdep_free;
143 hwdep->exclusive = 1; 111 hwdep->exclusive = 1;
112 hwdep->groups = snd_hda_dev_attr_groups;
144 113
145 hwdep->ops.open = hda_hwdep_open; 114 hwdep->ops.open = hda_hwdep_open;
146 hwdep->ops.ioctl = hda_hwdep_ioctl; 115 hwdep->ops.ioctl = hda_hwdep_ioctl;
@@ -148,740 +117,8 @@ int snd_hda_create_hwdep(struct hda_codec *codec)
148 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat; 117 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat;
149#endif 118#endif
150 119
151 mutex_init(&codec->user_mutex); 120 /* link to codec */
152 snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32); 121 hwdep->dev = &codec->dev;
153 snd_array_init(&codec->hints, sizeof(struct hda_hint), 32);
154 snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16);
155
156 return 0;
157}
158
159#ifdef CONFIG_PM
160static ssize_t power_on_acct_show(struct device *dev,
161 struct device_attribute *attr,
162 char *buf)
163{
164 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
165 struct hda_codec *codec = hwdep->private_data;
166 snd_hda_update_power_acct(codec);
167 return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
168}
169
170static ssize_t power_off_acct_show(struct device *dev,
171 struct device_attribute *attr,
172 char *buf)
173{
174 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
175 struct hda_codec *codec = hwdep->private_data;
176 snd_hda_update_power_acct(codec);
177 return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct));
178}
179
180static struct device_attribute power_attrs[] = {
181 __ATTR_RO(power_on_acct),
182 __ATTR_RO(power_off_acct),
183};
184
185int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
186{
187 struct snd_hwdep *hwdep = codec->hwdep;
188 int i;
189
190 for (i = 0; i < ARRAY_SIZE(power_attrs); i++)
191 snd_add_device_sysfs_file(SNDRV_DEVICE_TYPE_HWDEP, hwdep->card,
192 hwdep->device, &power_attrs[i]);
193 return 0;
194}
195#endif /* CONFIG_PM */
196
197#ifdef CONFIG_SND_HDA_RECONFIG
198
199/*
200 * sysfs interface
201 */
202
203static int clear_codec(struct hda_codec *codec)
204{
205 int err;
206
207 err = snd_hda_codec_reset(codec);
208 if (err < 0) {
209 snd_printk(KERN_ERR "The codec is being used, can't free.\n");
210 return err;
211 }
212 clear_hwdep_elements(codec);
213 return 0;
214}
215
216static int reconfig_codec(struct hda_codec *codec)
217{
218 int err;
219
220 snd_hda_power_up(codec);
221 snd_printk(KERN_INFO "hda-codec: reconfiguring\n");
222 err = snd_hda_codec_reset(codec);
223 if (err < 0) {
224 snd_printk(KERN_ERR
225 "The codec is being used, can't reconfigure.\n");
226 goto error;
227 }
228 err = snd_hda_codec_configure(codec);
229 if (err < 0)
230 goto error;
231 /* rebuild PCMs */
232 err = snd_hda_codec_build_pcms(codec);
233 if (err < 0)
234 goto error;
235 /* rebuild mixers */
236 err = snd_hda_codec_build_controls(codec);
237 if (err < 0)
238 goto error;
239 err = snd_card_register(codec->bus->card);
240 error:
241 snd_hda_power_down(codec);
242 return err;
243}
244
245/*
246 * allocate a string at most len chars, and remove the trailing EOL
247 */
248static char *kstrndup_noeol(const char *src, size_t len)
249{
250 char *s = kstrndup(src, len, GFP_KERNEL);
251 char *p;
252 if (!s)
253 return NULL;
254 p = strchr(s, '\n');
255 if (p)
256 *p = 0;
257 return s;
258}
259
260#define CODEC_INFO_SHOW(type) \
261static ssize_t type##_show(struct device *dev, \
262 struct device_attribute *attr, \
263 char *buf) \
264{ \
265 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
266 struct hda_codec *codec = hwdep->private_data; \
267 return sprintf(buf, "0x%x\n", codec->type); \
268}
269
270#define CODEC_INFO_STR_SHOW(type) \
271static ssize_t type##_show(struct device *dev, \
272 struct device_attribute *attr, \
273 char *buf) \
274{ \
275 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
276 struct hda_codec *codec = hwdep->private_data; \
277 return sprintf(buf, "%s\n", \
278 codec->type ? codec->type : ""); \
279}
280
281CODEC_INFO_SHOW(vendor_id);
282CODEC_INFO_SHOW(subsystem_id);
283CODEC_INFO_SHOW(revision_id);
284CODEC_INFO_SHOW(afg);
285CODEC_INFO_SHOW(mfg);
286CODEC_INFO_STR_SHOW(vendor_name);
287CODEC_INFO_STR_SHOW(chip_name);
288CODEC_INFO_STR_SHOW(modelname);
289
290#define CODEC_INFO_STORE(type) \
291static ssize_t type##_store(struct device *dev, \
292 struct device_attribute *attr, \
293 const char *buf, size_t count) \
294{ \
295 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
296 struct hda_codec *codec = hwdep->private_data; \
297 unsigned long val; \
298 int err = kstrtoul(buf, 0, &val); \
299 if (err < 0) \
300 return err; \
301 codec->type = val; \
302 return count; \
303}
304
305#define CODEC_INFO_STR_STORE(type) \
306static ssize_t type##_store(struct device *dev, \
307 struct device_attribute *attr, \
308 const char *buf, size_t count) \
309{ \
310 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
311 struct hda_codec *codec = hwdep->private_data; \
312 char *s = kstrndup_noeol(buf, 64); \
313 if (!s) \
314 return -ENOMEM; \
315 kfree(codec->type); \
316 codec->type = s; \
317 return count; \
318}
319
320CODEC_INFO_STORE(vendor_id);
321CODEC_INFO_STORE(subsystem_id);
322CODEC_INFO_STORE(revision_id);
323CODEC_INFO_STR_STORE(vendor_name);
324CODEC_INFO_STR_STORE(chip_name);
325CODEC_INFO_STR_STORE(modelname);
326
327#define CODEC_ACTION_STORE(type) \
328static ssize_t type##_store(struct device *dev, \
329 struct device_attribute *attr, \
330 const char *buf, size_t count) \
331{ \
332 struct snd_hwdep *hwdep = dev_get_drvdata(dev); \
333 struct hda_codec *codec = hwdep->private_data; \
334 int err = 0; \
335 if (*buf) \
336 err = type##_codec(codec); \
337 return err < 0 ? err : count; \
338}
339
340CODEC_ACTION_STORE(reconfig);
341CODEC_ACTION_STORE(clear);
342
343static ssize_t init_verbs_show(struct device *dev,
344 struct device_attribute *attr,
345 char *buf)
346{
347 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
348 struct hda_codec *codec = hwdep->private_data;
349 int i, len = 0;
350 mutex_lock(&codec->user_mutex);
351 for (i = 0; i < codec->init_verbs.used; i++) {
352 struct hda_verb *v = snd_array_elem(&codec->init_verbs, i);
353 len += snprintf(buf + len, PAGE_SIZE - len,
354 "0x%02x 0x%03x 0x%04x\n",
355 v->nid, v->verb, v->param);
356 }
357 mutex_unlock(&codec->user_mutex);
358 return len;
359}
360
361static int parse_init_verbs(struct hda_codec *codec, const char *buf)
362{
363 struct hda_verb *v;
364 int nid, verb, param;
365
366 if (sscanf(buf, "%i %i %i", &nid, &verb, &param) != 3)
367 return -EINVAL;
368 if (!nid || !verb)
369 return -EINVAL;
370 mutex_lock(&codec->user_mutex);
371 v = snd_array_new(&codec->init_verbs);
372 if (!v) {
373 mutex_unlock(&codec->user_mutex);
374 return -ENOMEM;
375 }
376 v->nid = nid;
377 v->verb = verb;
378 v->param = param;
379 mutex_unlock(&codec->user_mutex);
380 return 0;
381}
382
383static ssize_t init_verbs_store(struct device *dev,
384 struct device_attribute *attr,
385 const char *buf, size_t count)
386{
387 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
388 struct hda_codec *codec = hwdep->private_data;
389 int err = parse_init_verbs(codec, buf);
390 if (err < 0)
391 return err;
392 return count;
393}
394
395static ssize_t hints_show(struct device *dev,
396 struct device_attribute *attr,
397 char *buf)
398{
399 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
400 struct hda_codec *codec = hwdep->private_data;
401 int i, len = 0;
402 mutex_lock(&codec->user_mutex);
403 for (i = 0; i < codec->hints.used; i++) {
404 struct hda_hint *hint = snd_array_elem(&codec->hints, i);
405 len += snprintf(buf + len, PAGE_SIZE - len,
406 "%s = %s\n", hint->key, hint->val);
407 }
408 mutex_unlock(&codec->user_mutex);
409 return len;
410}
411
412static struct hda_hint *get_hint(struct hda_codec *codec, const char *key)
413{
414 int i;
415
416 for (i = 0; i < codec->hints.used; i++) {
417 struct hda_hint *hint = snd_array_elem(&codec->hints, i);
418 if (!strcmp(hint->key, key))
419 return hint;
420 }
421 return NULL;
422}
423
424static void remove_trail_spaces(char *str)
425{
426 char *p;
427 if (!*str)
428 return;
429 p = str + strlen(str) - 1;
430 for (; isspace(*p); p--) {
431 *p = 0;
432 if (p == str)
433 return;
434 }
435}
436
437#define MAX_HINTS 1024
438
439static int parse_hints(struct hda_codec *codec, const char *buf)
440{
441 char *key, *val;
442 struct hda_hint *hint;
443 int err = 0;
444
445 buf = skip_spaces(buf);
446 if (!*buf || *buf == '#' || *buf == '\n')
447 return 0;
448 if (*buf == '=')
449 return -EINVAL;
450 key = kstrndup_noeol(buf, 1024);
451 if (!key)
452 return -ENOMEM;
453 /* extract key and val */
454 val = strchr(key, '=');
455 if (!val) {
456 kfree(key);
457 return -EINVAL;
458 }
459 *val++ = 0;
460 val = skip_spaces(val);
461 remove_trail_spaces(key);
462 remove_trail_spaces(val);
463 mutex_lock(&codec->user_mutex);
464 hint = get_hint(codec, key);
465 if (hint) {
466 /* replace */
467 kfree(hint->key);
468 hint->key = key;
469 hint->val = val;
470 goto unlock;
471 }
472 /* allocate a new hint entry */
473 if (codec->hints.used >= MAX_HINTS)
474 hint = NULL;
475 else
476 hint = snd_array_new(&codec->hints);
477 if (hint) {
478 hint->key = key;
479 hint->val = val;
480 } else {
481 err = -ENOMEM;
482 }
483 unlock:
484 mutex_unlock(&codec->user_mutex);
485 if (err)
486 kfree(key);
487 return err;
488}
489
490static ssize_t hints_store(struct device *dev,
491 struct device_attribute *attr,
492 const char *buf, size_t count)
493{
494 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
495 struct hda_codec *codec = hwdep->private_data;
496 int err = parse_hints(codec, buf);
497 if (err < 0)
498 return err;
499 return count;
500}
501
502static ssize_t pin_configs_show(struct hda_codec *codec,
503 struct snd_array *list,
504 char *buf)
505{
506 int i, len = 0;
507 mutex_lock(&codec->user_mutex);
508 for (i = 0; i < list->used; i++) {
509 struct hda_pincfg *pin = snd_array_elem(list, i);
510 len += sprintf(buf + len, "0x%02x 0x%08x\n",
511 pin->nid, pin->cfg);
512 }
513 mutex_unlock(&codec->user_mutex);
514 return len;
515}
516
517static ssize_t init_pin_configs_show(struct device *dev,
518 struct device_attribute *attr,
519 char *buf)
520{
521 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
522 struct hda_codec *codec = hwdep->private_data;
523 return pin_configs_show(codec, &codec->init_pins, buf);
524}
525
526static ssize_t user_pin_configs_show(struct device *dev,
527 struct device_attribute *attr,
528 char *buf)
529{
530 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
531 struct hda_codec *codec = hwdep->private_data;
532 return pin_configs_show(codec, &codec->user_pins, buf);
533}
534
535static ssize_t driver_pin_configs_show(struct device *dev,
536 struct device_attribute *attr,
537 char *buf)
538{
539 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
540 struct hda_codec *codec = hwdep->private_data;
541 return pin_configs_show(codec, &codec->driver_pins, buf);
542}
543
544#define MAX_PIN_CONFIGS 32
545
546static int parse_user_pin_configs(struct hda_codec *codec, const char *buf)
547{
548 int nid, cfg, err;
549
550 if (sscanf(buf, "%i %i", &nid, &cfg) != 2)
551 return -EINVAL;
552 if (!nid)
553 return -EINVAL;
554 mutex_lock(&codec->user_mutex);
555 err = snd_hda_add_pincfg(codec, &codec->user_pins, nid, cfg);
556 mutex_unlock(&codec->user_mutex);
557 return err;
558}
559
560static ssize_t user_pin_configs_store(struct device *dev,
561 struct device_attribute *attr,
562 const char *buf, size_t count)
563{
564 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
565 struct hda_codec *codec = hwdep->private_data;
566 int err = parse_user_pin_configs(codec, buf);
567 if (err < 0)
568 return err;
569 return count;
570}
571
572#define CODEC_ATTR_RW(type) \
573 __ATTR(type, 0644, type##_show, type##_store)
574#define CODEC_ATTR_RO(type) \
575 __ATTR_RO(type)
576#define CODEC_ATTR_WO(type) \
577 __ATTR(type, 0200, NULL, type##_store)
578
579static struct device_attribute codec_attrs[] = {
580 CODEC_ATTR_RW(vendor_id),
581 CODEC_ATTR_RW(subsystem_id),
582 CODEC_ATTR_RW(revision_id),
583 CODEC_ATTR_RO(afg),
584 CODEC_ATTR_RO(mfg),
585 CODEC_ATTR_RW(vendor_name),
586 CODEC_ATTR_RW(chip_name),
587 CODEC_ATTR_RW(modelname),
588 CODEC_ATTR_RW(init_verbs),
589 CODEC_ATTR_RW(hints),
590 CODEC_ATTR_RO(init_pin_configs),
591 CODEC_ATTR_RW(user_pin_configs),
592 CODEC_ATTR_RO(driver_pin_configs),
593 CODEC_ATTR_WO(reconfig),
594 CODEC_ATTR_WO(clear),
595};
596
597/*
598 * create sysfs files on hwdep directory
599 */
600int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
601{
602 struct snd_hwdep *hwdep = codec->hwdep;
603 int i;
604
605 for (i = 0; i < ARRAY_SIZE(codec_attrs); i++)
606 snd_add_device_sysfs_file(SNDRV_DEVICE_TYPE_HWDEP, hwdep->card,
607 hwdep->device, &codec_attrs[i]);
608 return 0;
609}
610
611/*
612 * Look for hint string
613 */
614const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
615{
616 struct hda_hint *hint = get_hint(codec, key);
617 return hint ? hint->val : NULL;
618}
619EXPORT_SYMBOL_GPL(snd_hda_get_hint);
620
621int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
622{
623 const char *p;
624 int ret;
625
626 mutex_lock(&codec->user_mutex);
627 p = snd_hda_get_hint(codec, key);
628 if (!p || !*p)
629 ret = -ENOENT;
630 else {
631 switch (toupper(*p)) {
632 case 'T': /* true */
633 case 'Y': /* yes */
634 case '1':
635 ret = 1;
636 break;
637 default:
638 ret = 0;
639 break;
640 }
641 }
642 mutex_unlock(&codec->user_mutex);
643 return ret;
644}
645EXPORT_SYMBOL_GPL(snd_hda_get_bool_hint);
646
647int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
648{
649 const char *p;
650 unsigned long val;
651 int ret;
652
653 mutex_lock(&codec->user_mutex);
654 p = snd_hda_get_hint(codec, key);
655 if (!p)
656 ret = -ENOENT;
657 else if (kstrtoul(p, 0, &val))
658 ret = -EINVAL;
659 else {
660 *valp = val;
661 ret = 0;
662 }
663 mutex_unlock(&codec->user_mutex);
664 return ret;
665}
666EXPORT_SYMBOL_GPL(snd_hda_get_int_hint);
667#endif /* CONFIG_SND_HDA_RECONFIG */
668
669#ifdef CONFIG_SND_HDA_PATCH_LOADER
670 122
671/* parser mode */
672enum {
673 LINE_MODE_NONE,
674 LINE_MODE_CODEC,
675 LINE_MODE_MODEL,
676 LINE_MODE_PINCFG,
677 LINE_MODE_VERB,
678 LINE_MODE_HINT,
679 LINE_MODE_VENDOR_ID,
680 LINE_MODE_SUBSYSTEM_ID,
681 LINE_MODE_REVISION_ID,
682 LINE_MODE_CHIP_NAME,
683 NUM_LINE_MODES,
684};
685
686static inline int strmatch(const char *a, const char *b)
687{
688 return strnicmp(a, b, strlen(b)) == 0;
689}
690
691/* parse the contents after the line "[codec]"
692 * accept only the line with three numbers, and assign the current codec
693 */
694static void parse_codec_mode(char *buf, struct hda_bus *bus,
695 struct hda_codec **codecp)
696{
697 int vendorid, subid, caddr;
698 struct hda_codec *codec;
699
700 *codecp = NULL;
701 if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) {
702 list_for_each_entry(codec, &bus->codec_list, list) {
703 if ((vendorid <= 0 || codec->vendor_id == vendorid) &&
704 (subid <= 0 || codec->subsystem_id == subid) &&
705 codec->addr == caddr) {
706 *codecp = codec;
707 break;
708 }
709 }
710 }
711}
712
713/* parse the contents after the other command tags, [pincfg], [verb],
714 * [vendor_id], [subsystem_id], [revision_id], [chip_name], [hint] and [model]
715 * just pass to the sysfs helper (only when any codec was specified)
716 */
717static void parse_pincfg_mode(char *buf, struct hda_bus *bus,
718 struct hda_codec **codecp)
719{
720 parse_user_pin_configs(*codecp, buf);
721}
722
723static void parse_verb_mode(char *buf, struct hda_bus *bus,
724 struct hda_codec **codecp)
725{
726 parse_init_verbs(*codecp, buf);
727}
728
729static void parse_hint_mode(char *buf, struct hda_bus *bus,
730 struct hda_codec **codecp)
731{
732 parse_hints(*codecp, buf);
733}
734
735static void parse_model_mode(char *buf, struct hda_bus *bus,
736 struct hda_codec **codecp)
737{
738 kfree((*codecp)->modelname);
739 (*codecp)->modelname = kstrdup(buf, GFP_KERNEL);
740}
741
742static void parse_chip_name_mode(char *buf, struct hda_bus *bus,
743 struct hda_codec **codecp)
744{
745 kfree((*codecp)->chip_name);
746 (*codecp)->chip_name = kstrdup(buf, GFP_KERNEL);
747}
748
749#define DEFINE_PARSE_ID_MODE(name) \
750static void parse_##name##_mode(char *buf, struct hda_bus *bus, \
751 struct hda_codec **codecp) \
752{ \
753 unsigned long val; \
754 if (!kstrtoul(buf, 0, &val)) \
755 (*codecp)->name = val; \
756}
757
758DEFINE_PARSE_ID_MODE(vendor_id);
759DEFINE_PARSE_ID_MODE(subsystem_id);
760DEFINE_PARSE_ID_MODE(revision_id);
761
762
763struct hda_patch_item {
764 const char *tag;
765 const char *alias;
766 void (*parser)(char *buf, struct hda_bus *bus, struct hda_codec **retc);
767};
768
769static struct hda_patch_item patch_items[NUM_LINE_MODES] = {
770 [LINE_MODE_CODEC] = {
771 .tag = "[codec]",
772 .parser = parse_codec_mode,
773 },
774 [LINE_MODE_MODEL] = {
775 .tag = "[model]",
776 .parser = parse_model_mode,
777 },
778 [LINE_MODE_VERB] = {
779 .tag = "[verb]",
780 .alias = "[init_verbs]",
781 .parser = parse_verb_mode,
782 },
783 [LINE_MODE_PINCFG] = {
784 .tag = "[pincfg]",
785 .alias = "[user_pin_configs]",
786 .parser = parse_pincfg_mode,
787 },
788 [LINE_MODE_HINT] = {
789 .tag = "[hint]",
790 .alias = "[hints]",
791 .parser = parse_hint_mode
792 },
793 [LINE_MODE_VENDOR_ID] = {
794 .tag = "[vendor_id]",
795 .parser = parse_vendor_id_mode,
796 },
797 [LINE_MODE_SUBSYSTEM_ID] = {
798 .tag = "[subsystem_id]",
799 .parser = parse_subsystem_id_mode,
800 },
801 [LINE_MODE_REVISION_ID] = {
802 .tag = "[revision_id]",
803 .parser = parse_revision_id_mode,
804 },
805 [LINE_MODE_CHIP_NAME] = {
806 .tag = "[chip_name]",
807 .parser = parse_chip_name_mode,
808 },
809};
810
811/* check the line starting with '[' -- change the parser mode accodingly */
812static int parse_line_mode(char *buf, struct hda_bus *bus)
813{
814 int i;
815 for (i = 0; i < ARRAY_SIZE(patch_items); i++) {
816 if (!patch_items[i].tag)
817 continue;
818 if (strmatch(buf, patch_items[i].tag))
819 return i;
820 if (patch_items[i].alias && strmatch(buf, patch_items[i].alias))
821 return i;
822 }
823 return LINE_MODE_NONE;
824}
825
826/* copy one line from the buffer in fw, and update the fields in fw
827 * return zero if it reaches to the end of the buffer, or non-zero
828 * if successfully copied a line
829 *
830 * the spaces at the beginning and the end of the line are stripped
831 */
832static int get_line_from_fw(char *buf, int size, size_t *fw_size_p,
833 const void **fw_data_p)
834{
835 int len;
836 size_t fw_size = *fw_size_p;
837 const char *p = *fw_data_p;
838
839 while (isspace(*p) && fw_size) {
840 p++;
841 fw_size--;
842 }
843 if (!fw_size)
844 return 0;
845
846 for (len = 0; len < fw_size; len++) {
847 if (!*p)
848 break;
849 if (*p == '\n') {
850 p++;
851 len++;
852 break;
853 }
854 if (len < size)
855 *buf++ = *p++;
856 }
857 *buf = 0;
858 *fw_size_p = fw_size - len;
859 *fw_data_p = p;
860 remove_trail_spaces(buf);
861 return 1;
862}
863
864/*
865 * load a "patch" firmware file and parse it
866 */
867int snd_hda_load_patch(struct hda_bus *bus, size_t fw_size, const void *fw_buf)
868{
869 char buf[128];
870 struct hda_codec *codec;
871 int line_mode;
872
873 line_mode = LINE_MODE_NONE;
874 codec = NULL;
875 while (get_line_from_fw(buf, sizeof(buf) - 1, &fw_size, &fw_buf)) {
876 if (!*buf || *buf == '#' || *buf == '\n')
877 continue;
878 if (*buf == '[')
879 line_mode = parse_line_mode(buf, bus);
880 else if (patch_items[line_mode].parser &&
881 (codec || line_mode <= LINE_MODE_CODEC))
882 patch_items[line_mode].parser(buf, bus, &codec);
883 }
884 return 0; 123 return 0;
885} 124}
886EXPORT_SYMBOL_GPL(snd_hda_load_patch);
887#endif /* CONFIG_SND_HDA_PATCH_LOADER */
diff --git a/sound/pci/hda/hda_i915.c b/sound/pci/hda/hda_i915.c
index 76c13d5b3ca0..9d07e4edacdb 100644
--- a/sound/pci/hda/hda_i915.c
+++ b/sound/pci/hda/hda_i915.c
@@ -30,7 +30,7 @@ void hda_display_power(bool enable)
30 if (!get_power || !put_power) 30 if (!get_power || !put_power)
31 return; 31 return;
32 32
33 snd_printdd("HDA display power %s \n", 33 pr_debug("HDA display power %s \n",
34 enable ? "Enable" : "Disable"); 34 enable ? "Enable" : "Disable");
35 if (enable) 35 if (enable)
36 get_power(); 36 get_power();
@@ -44,7 +44,7 @@ int hda_i915_init(void)
44 44
45 get_power = symbol_request(i915_request_power_well); 45 get_power = symbol_request(i915_request_power_well);
46 if (!get_power) { 46 if (!get_power) {
47 snd_printk(KERN_WARNING "hda-i915: get_power symbol get fail\n"); 47 pr_warn("hda-i915: get_power symbol get fail\n");
48 return -ENODEV; 48 return -ENODEV;
49 } 49 }
50 50
@@ -55,7 +55,7 @@ int hda_i915_init(void)
55 return -ENODEV; 55 return -ENODEV;
56 } 56 }
57 57
58 snd_printd("HDA driver get symbol successfully from i915 module\n"); 58 pr_debug("HDA driver get symbol successfully from i915 module\n");
59 59
60 return err; 60 return err;
61} 61}
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index e354ab1ec20f..77ca894f8284 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -63,6 +63,8 @@
63#include <linux/firmware.h> 63#include <linux/firmware.h>
64#include "hda_codec.h" 64#include "hda_codec.h"
65#include "hda_i915.h" 65#include "hda_i915.h"
66#include "hda_controller.h"
67#include "hda_priv.h"
66 68
67 69
68static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 70static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
@@ -127,6 +129,7 @@ static struct kernel_param_ops param_ops_xint = {
127#define param_check_xint param_check_int 129#define param_check_xint param_check_int
128 130
129static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT; 131static int power_save = CONFIG_SND_HDA_POWER_SAVE_DEFAULT;
132static int *power_save_addr = &power_save;
130module_param(power_save, xint, 0644); 133module_param(power_save, xint, 0644);
131MODULE_PARM_DESC(power_save, "Automatic power-saving timeout " 134MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
132 "(in second, 0 = disable)."); 135 "(in second, 0 = disable).");
@@ -138,6 +141,8 @@ MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
138static bool power_save_controller = 1; 141static bool power_save_controller = 1;
139module_param(power_save_controller, bool, 0644); 142module_param(power_save_controller, bool, 0644);
140MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode."); 143MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
144#else
145static int *power_save_addr;
141#endif /* CONFIG_PM */ 146#endif /* CONFIG_PM */
142 147
143static int align_buffer_size = -1; 148static int align_buffer_size = -1;
@@ -149,10 +154,8 @@ MODULE_PARM_DESC(align_buffer_size,
149static bool hda_snoop = true; 154static bool hda_snoop = true;
150module_param_named(snoop, hda_snoop, bool, 0444); 155module_param_named(snoop, hda_snoop, bool, 0444);
151MODULE_PARM_DESC(snoop, "Enable/disable snooping"); 156MODULE_PARM_DESC(snoop, "Enable/disable snooping");
152#define azx_snoop(chip) (chip)->snoop
153#else 157#else
154#define hda_snoop true 158#define hda_snoop true
155#define azx_snoop(chip) true
156#endif 159#endif
157 160
158 161
@@ -191,12 +194,6 @@ MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
191 "{ULI, M5461}}"); 194 "{ULI, M5461}}");
192MODULE_DESCRIPTION("Intel HDA driver"); 195MODULE_DESCRIPTION("Intel HDA driver");
193 196
194#ifdef CONFIG_SND_VERBOSE_PRINTK
195#define SFX /* nop */
196#else
197#define SFX "hda-intel "
198#endif
199
200#if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO) 197#if defined(CONFIG_PM) && defined(CONFIG_VGA_SWITCHEROO)
201#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI) 198#if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI)
202#define SUPPORT_VGA_SWITCHEROO 199#define SUPPORT_VGA_SWITCHEROO
@@ -205,365 +202,8 @@ MODULE_DESCRIPTION("Intel HDA driver");
205 202
206 203
207/* 204/*
208 * registers
209 */
210#define ICH6_REG_GCAP 0x00
211#define ICH6_GCAP_64OK (1 << 0) /* 64bit address support */
212#define ICH6_GCAP_NSDO (3 << 1) /* # of serial data out signals */
213#define ICH6_GCAP_BSS (31 << 3) /* # of bidirectional streams */
214#define ICH6_GCAP_ISS (15 << 8) /* # of input streams */
215#define ICH6_GCAP_OSS (15 << 12) /* # of output streams */
216#define ICH6_REG_VMIN 0x02
217#define ICH6_REG_VMAJ 0x03
218#define ICH6_REG_OUTPAY 0x04
219#define ICH6_REG_INPAY 0x06
220#define ICH6_REG_GCTL 0x08
221#define ICH6_GCTL_RESET (1 << 0) /* controller reset */
222#define ICH6_GCTL_FCNTRL (1 << 1) /* flush control */
223#define ICH6_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
224#define ICH6_REG_WAKEEN 0x0c
225#define ICH6_REG_STATESTS 0x0e
226#define ICH6_REG_GSTS 0x10
227#define ICH6_GSTS_FSTS (1 << 1) /* flush status */
228#define ICH6_REG_INTCTL 0x20
229#define ICH6_REG_INTSTS 0x24
230#define ICH6_REG_WALLCLK 0x30 /* 24Mhz source */
231#define ICH6_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */
232#define ICH6_REG_SSYNC 0x38
233#define ICH6_REG_CORBLBASE 0x40
234#define ICH6_REG_CORBUBASE 0x44
235#define ICH6_REG_CORBWP 0x48
236#define ICH6_REG_CORBRP 0x4a
237#define ICH6_CORBRP_RST (1 << 15) /* read pointer reset */
238#define ICH6_REG_CORBCTL 0x4c
239#define ICH6_CORBCTL_RUN (1 << 1) /* enable DMA */
240#define ICH6_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
241#define ICH6_REG_CORBSTS 0x4d
242#define ICH6_CORBSTS_CMEI (1 << 0) /* memory error indication */
243#define ICH6_REG_CORBSIZE 0x4e
244
245#define ICH6_REG_RIRBLBASE 0x50
246#define ICH6_REG_RIRBUBASE 0x54
247#define ICH6_REG_RIRBWP 0x58
248#define ICH6_RIRBWP_RST (1 << 15) /* write pointer reset */
249#define ICH6_REG_RINTCNT 0x5a
250#define ICH6_REG_RIRBCTL 0x5c
251#define ICH6_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
252#define ICH6_RBCTL_DMA_EN (1 << 1) /* enable DMA */
253#define ICH6_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
254#define ICH6_REG_RIRBSTS 0x5d
255#define ICH6_RBSTS_IRQ (1 << 0) /* response irq */
256#define ICH6_RBSTS_OVERRUN (1 << 2) /* overrun irq */
257#define ICH6_REG_RIRBSIZE 0x5e
258
259#define ICH6_REG_IC 0x60
260#define ICH6_REG_IR 0x64
261#define ICH6_REG_IRS 0x68
262#define ICH6_IRS_VALID (1<<1)
263#define ICH6_IRS_BUSY (1<<0)
264
265#define ICH6_REG_DPLBASE 0x70
266#define ICH6_REG_DPUBASE 0x74
267#define ICH6_DPLBASE_ENABLE 0x1 /* Enable position buffer */
268
269/* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
270enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
271
272/* stream register offsets from stream base */
273#define ICH6_REG_SD_CTL 0x00
274#define ICH6_REG_SD_STS 0x03
275#define ICH6_REG_SD_LPIB 0x04
276#define ICH6_REG_SD_CBL 0x08
277#define ICH6_REG_SD_LVI 0x0c
278#define ICH6_REG_SD_FIFOW 0x0e
279#define ICH6_REG_SD_FIFOSIZE 0x10
280#define ICH6_REG_SD_FORMAT 0x12
281#define ICH6_REG_SD_BDLPL 0x18
282#define ICH6_REG_SD_BDLPU 0x1c
283
284/* PCI space */
285#define ICH6_PCIREG_TCSEL 0x44
286
287/*
288 * other constants
289 */ 205 */
290 206
291/* max number of SDs */
292/* ICH, ATI and VIA have 4 playback and 4 capture */
293#define ICH6_NUM_CAPTURE 4
294#define ICH6_NUM_PLAYBACK 4
295
296/* ULI has 6 playback and 5 capture */
297#define ULI_NUM_CAPTURE 5
298#define ULI_NUM_PLAYBACK 6
299
300/* ATI HDMI may have up to 8 playbacks and 0 capture */
301#define ATIHDMI_NUM_CAPTURE 0
302#define ATIHDMI_NUM_PLAYBACK 8
303
304/* TERA has 4 playback and 3 capture */
305#define TERA_NUM_CAPTURE 3
306#define TERA_NUM_PLAYBACK 4
307
308/* this number is statically defined for simplicity */
309#define MAX_AZX_DEV 16
310
311/* max number of fragments - we may use more if allocating more pages for BDL */
312#define BDL_SIZE 4096
313#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
314#define AZX_MAX_FRAG 32
315/* max buffer size - no h/w limit, you can increase as you like */
316#define AZX_MAX_BUF_SIZE (1024*1024*1024)
317
318/* RIRB int mask: overrun[2], response[0] */
319#define RIRB_INT_RESPONSE 0x01
320#define RIRB_INT_OVERRUN 0x04
321#define RIRB_INT_MASK 0x05
322
323/* STATESTS int mask: S3,SD2,SD1,SD0 */
324#define AZX_MAX_CODECS 8
325#define AZX_DEFAULT_CODECS 4
326#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
327
328/* SD_CTL bits */
329#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
330#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
331#define SD_CTL_STRIPE (3 << 16) /* stripe control */
332#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
333#define SD_CTL_DIR (1 << 19) /* bi-directional stream */
334#define SD_CTL_STREAM_TAG_MASK (0xf << 20)
335#define SD_CTL_STREAM_TAG_SHIFT 20
336
337/* SD_CTL and SD_STS */
338#define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
339#define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
340#define SD_INT_COMPLETE 0x04 /* completion interrupt */
341#define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
342 SD_INT_COMPLETE)
343
344/* SD_STS */
345#define SD_STS_FIFO_READY 0x20 /* FIFO ready */
346
347/* INTCTL and INTSTS */
348#define ICH6_INT_ALL_STREAM 0xff /* all stream interrupts */
349#define ICH6_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
350#define ICH6_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
351
352/* below are so far hardcoded - should read registers in future */
353#define ICH6_MAX_CORB_ENTRIES 256
354#define ICH6_MAX_RIRB_ENTRIES 256
355
356/* position fix mode */
357enum {
358 POS_FIX_AUTO,
359 POS_FIX_LPIB,
360 POS_FIX_POSBUF,
361 POS_FIX_VIACOMBO,
362 POS_FIX_COMBO,
363};
364
365/* Defines for ATI HD Audio support in SB450 south bridge */
366#define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
367#define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
368
369/* Defines for Nvidia HDA support */
370#define NVIDIA_HDA_TRANSREG_ADDR 0x4e
371#define NVIDIA_HDA_ENABLE_COHBITS 0x0f
372#define NVIDIA_HDA_ISTRM_COH 0x4d
373#define NVIDIA_HDA_OSTRM_COH 0x4c
374#define NVIDIA_HDA_ENABLE_COHBIT 0x01
375
376/* Defines for Intel SCH HDA snoop control */
377#define INTEL_SCH_HDA_DEVC 0x78
378#define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
379
380/* Define IN stream 0 FIFO size offset in VIA controller */
381#define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
382/* Define VIA HD Audio Device ID*/
383#define VIA_HDAC_DEVICE_ID 0x3288
384
385/* HD Audio class code */
386#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
387
388/*
389 */
390
391struct azx_dev {
392 struct snd_dma_buffer bdl; /* BDL buffer */
393 u32 *posbuf; /* position buffer pointer */
394
395 unsigned int bufsize; /* size of the play buffer in bytes */
396 unsigned int period_bytes; /* size of the period in bytes */
397 unsigned int frags; /* number for period in the play buffer */
398 unsigned int fifo_size; /* FIFO size */
399 unsigned long start_wallclk; /* start + minimum wallclk */
400 unsigned long period_wallclk; /* wallclk for period */
401
402 void __iomem *sd_addr; /* stream descriptor pointer */
403
404 u32 sd_int_sta_mask; /* stream int status mask */
405
406 /* pcm support */
407 struct snd_pcm_substream *substream; /* assigned substream,
408 * set in PCM open
409 */
410 unsigned int format_val; /* format value to be set in the
411 * controller and the codec
412 */
413 unsigned char stream_tag; /* assigned stream */
414 unsigned char index; /* stream index */
415 int assigned_key; /* last device# key assigned to */
416
417 unsigned int opened :1;
418 unsigned int running :1;
419 unsigned int irq_pending :1;
420 unsigned int prepared:1;
421 unsigned int locked:1;
422 /*
423 * For VIA:
424 * A flag to ensure DMA position is 0
425 * when link position is not greater than FIFO size
426 */
427 unsigned int insufficient :1;
428 unsigned int wc_marked:1;
429 unsigned int no_period_wakeup:1;
430
431 struct timecounter azx_tc;
432 struct cyclecounter azx_cc;
433
434 int delay_negative_threshold;
435
436#ifdef CONFIG_SND_HDA_DSP_LOADER
437 struct mutex dsp_mutex;
438#endif
439};
440
441/* DSP lock helpers */
442#ifdef CONFIG_SND_HDA_DSP_LOADER
443#define dsp_lock_init(dev) mutex_init(&(dev)->dsp_mutex)
444#define dsp_lock(dev) mutex_lock(&(dev)->dsp_mutex)
445#define dsp_unlock(dev) mutex_unlock(&(dev)->dsp_mutex)
446#define dsp_is_locked(dev) ((dev)->locked)
447#else
448#define dsp_lock_init(dev) do {} while (0)
449#define dsp_lock(dev) do {} while (0)
450#define dsp_unlock(dev) do {} while (0)
451#define dsp_is_locked(dev) 0
452#endif
453
454/* CORB/RIRB */
455struct azx_rb {
456 u32 *buf; /* CORB/RIRB buffer
457 * Each CORB entry is 4byte, RIRB is 8byte
458 */
459 dma_addr_t addr; /* physical address of CORB/RIRB buffer */
460 /* for RIRB */
461 unsigned short rp, wp; /* read/write pointers */
462 int cmds[AZX_MAX_CODECS]; /* number of pending requests */
463 u32 res[AZX_MAX_CODECS]; /* last read value */
464};
465
466struct azx_pcm {
467 struct azx *chip;
468 struct snd_pcm *pcm;
469 struct hda_codec *codec;
470 struct hda_pcm_stream *hinfo[2];
471 struct list_head list;
472};
473
474struct azx {
475 struct snd_card *card;
476 struct pci_dev *pci;
477 int dev_index;
478
479 /* chip type specific */
480 int driver_type;
481 unsigned int driver_caps;
482 int playback_streams;
483 int playback_index_offset;
484 int capture_streams;
485 int capture_index_offset;
486 int num_streams;
487
488 /* pci resources */
489 unsigned long addr;
490 void __iomem *remap_addr;
491 int irq;
492
493 /* locks */
494 spinlock_t reg_lock;
495 struct mutex open_mutex;
496 struct completion probe_wait;
497
498 /* streams (x num_streams) */
499 struct azx_dev *azx_dev;
500
501 /* PCM */
502 struct list_head pcm_list; /* azx_pcm list */
503
504 /* HD codec */
505 unsigned short codec_mask;
506 int codec_probe_mask; /* copied from probe_mask option */
507 struct hda_bus *bus;
508 unsigned int beep_mode;
509
510 /* CORB/RIRB */
511 struct azx_rb corb;
512 struct azx_rb rirb;
513
514 /* CORB/RIRB and position buffers */
515 struct snd_dma_buffer rb;
516 struct snd_dma_buffer posbuf;
517
518#ifdef CONFIG_SND_HDA_PATCH_LOADER
519 const struct firmware *fw;
520#endif
521
522 /* flags */
523 int position_fix[2]; /* for both playback/capture streams */
524 int poll_count;
525 unsigned int running :1;
526 unsigned int initialized :1;
527 unsigned int single_cmd :1;
528 unsigned int polling_mode :1;
529 unsigned int msi :1;
530 unsigned int irq_pending_warned :1;
531 unsigned int probing :1; /* codec probing phase */
532 unsigned int snoop:1;
533 unsigned int align_buffer_size:1;
534 unsigned int region_requested:1;
535
536 /* VGA-switcheroo setup */
537 unsigned int use_vga_switcheroo:1;
538 unsigned int vga_switcheroo_registered:1;
539 unsigned int init_failed:1; /* delayed init failed */
540 unsigned int disabled:1; /* disabled by VGA-switcher */
541
542 /* for debugging */
543 unsigned int last_cmd[AZX_MAX_CODECS];
544
545 /* for pending irqs */
546 struct work_struct irq_pending_work;
547
548 struct work_struct probe_work;
549
550 /* reboot notifier (for mysterious hangup problem at power-down) */
551 struct notifier_block reboot_notifier;
552
553 /* card list (for power_save trigger) */
554 struct list_head list;
555
556#ifdef CONFIG_SND_HDA_DSP_LOADER
557 struct azx_dev saved_azx_dev;
558#endif
559
560 /* secondary power domain for hdmi audio under vga device */
561 struct dev_pm_domain hdmi_pm_domain;
562};
563
564#define CREATE_TRACE_POINTS
565#include "hda_intel_trace.h"
566
567/* driver types */ 207/* driver types */
568enum { 208enum {
569 AZX_DRIVER_ICH, 209 AZX_DRIVER_ICH,
@@ -584,28 +224,6 @@ enum {
584 AZX_NUM_DRIVERS, /* keep this as last entry */ 224 AZX_NUM_DRIVERS, /* keep this as last entry */
585}; 225};
586 226
587/* driver quirks (capabilities) */
588/* bits 0-7 are used for indicating driver type */
589#define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */
590#define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */
591#define AZX_DCAPS_ATI_SNOOP (1 << 10) /* ATI snoop enable */
592#define AZX_DCAPS_NVIDIA_SNOOP (1 << 11) /* Nvidia snoop enable */
593#define AZX_DCAPS_SCH_SNOOP (1 << 12) /* SCH/PCH snoop enable */
594#define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */
595#define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */
596#define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */
597#define AZX_DCAPS_POSFIX_LPIB (1 << 16) /* Use LPIB as default */
598#define AZX_DCAPS_POSFIX_VIA (1 << 17) /* Use VIACOMBO as default */
599#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */
600#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */
601#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
602#define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */
603#define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22) /* buffer size alignment */
604#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */
605#define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */
606#define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */
607#define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 power well support */
608
609/* quirks for Intel PCH */ 227/* quirks for Intel PCH */
610#define AZX_DCAPS_INTEL_PCH_NOPM \ 228#define AZX_DCAPS_INTEL_PCH_NOPM \
611 (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_BUFSIZE | \ 229 (AZX_DCAPS_SCH_SNOOP | AZX_DCAPS_BUFSIZE | \
@@ -663,38 +281,6 @@ static char *driver_short_names[] = {
663 [AZX_DRIVER_GENERIC] = "HD-Audio Generic", 281 [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
664}; 282};
665 283
666/*
667 * macros for easy use
668 */
669#define azx_writel(chip,reg,value) \
670 writel(value, (chip)->remap_addr + ICH6_REG_##reg)
671#define azx_readl(chip,reg) \
672 readl((chip)->remap_addr + ICH6_REG_##reg)
673#define azx_writew(chip,reg,value) \
674 writew(value, (chip)->remap_addr + ICH6_REG_##reg)
675#define azx_readw(chip,reg) \
676 readw((chip)->remap_addr + ICH6_REG_##reg)
677#define azx_writeb(chip,reg,value) \
678 writeb(value, (chip)->remap_addr + ICH6_REG_##reg)
679#define azx_readb(chip,reg) \
680 readb((chip)->remap_addr + ICH6_REG_##reg)
681
682#define azx_sd_writel(dev,reg,value) \
683 writel(value, (dev)->sd_addr + ICH6_REG_##reg)
684#define azx_sd_readl(dev,reg) \
685 readl((dev)->sd_addr + ICH6_REG_##reg)
686#define azx_sd_writew(dev,reg,value) \
687 writew(value, (dev)->sd_addr + ICH6_REG_##reg)
688#define azx_sd_readw(dev,reg) \
689 readw((dev)->sd_addr + ICH6_REG_##reg)
690#define azx_sd_writeb(dev,reg,value) \
691 writeb(value, (dev)->sd_addr + ICH6_REG_##reg)
692#define azx_sd_readb(dev,reg) \
693 readb((dev)->sd_addr + ICH6_REG_##reg)
694
695/* for pcm support */
696#define get_azx_dev(substream) (substream->runtime->private_data)
697
698#ifdef CONFIG_X86 284#ifdef CONFIG_X86
699static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool on) 285static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool on)
700{ 286{
@@ -749,578 +335,6 @@ static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
749#endif 335#endif
750 336
751static int azx_acquire_irq(struct azx *chip, int do_disconnect); 337static int azx_acquire_irq(struct azx *chip, int do_disconnect);
752static int azx_send_cmd(struct hda_bus *bus, unsigned int val);
753/*
754 * Interface for HD codec
755 */
756
757/*
758 * CORB / RIRB interface
759 */
760static int azx_alloc_cmd_io(struct azx *chip)
761{
762 int err;
763
764 /* single page (at least 4096 bytes) must suffice for both ringbuffes */
765 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
766 snd_dma_pci_data(chip->pci),
767 PAGE_SIZE, &chip->rb);
768 if (err < 0) {
769 snd_printk(KERN_ERR SFX "%s: cannot allocate CORB/RIRB\n", pci_name(chip->pci));
770 return err;
771 }
772 mark_pages_wc(chip, &chip->rb, true);
773 return 0;
774}
775
776static void azx_init_cmd_io(struct azx *chip)
777{
778 spin_lock_irq(&chip->reg_lock);
779 /* CORB set up */
780 chip->corb.addr = chip->rb.addr;
781 chip->corb.buf = (u32 *)chip->rb.area;
782 azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);
783 azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));
784
785 /* set the corb size to 256 entries (ULI requires explicitly) */
786 azx_writeb(chip, CORBSIZE, 0x02);
787 /* set the corb write pointer to 0 */
788 azx_writew(chip, CORBWP, 0);
789 /* reset the corb hw read pointer */
790 azx_writew(chip, CORBRP, ICH6_CORBRP_RST);
791 /* enable corb dma */
792 azx_writeb(chip, CORBCTL, ICH6_CORBCTL_RUN);
793
794 /* RIRB set up */
795 chip->rirb.addr = chip->rb.addr + 2048;
796 chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
797 chip->rirb.wp = chip->rirb.rp = 0;
798 memset(chip->rirb.cmds, 0, sizeof(chip->rirb.cmds));
799 azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
800 azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
801
802 /* set the rirb size to 256 entries (ULI requires explicitly) */
803 azx_writeb(chip, RIRBSIZE, 0x02);
804 /* reset the rirb hw write pointer */
805 azx_writew(chip, RIRBWP, ICH6_RIRBWP_RST);
806 /* set N=1, get RIRB response interrupt for new entry */
807 if (chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND)
808 azx_writew(chip, RINTCNT, 0xc0);
809 else
810 azx_writew(chip, RINTCNT, 1);
811 /* enable rirb dma and response irq */
812 azx_writeb(chip, RIRBCTL, ICH6_RBCTL_DMA_EN | ICH6_RBCTL_IRQ_EN);
813 spin_unlock_irq(&chip->reg_lock);
814}
815
816static void azx_free_cmd_io(struct azx *chip)
817{
818 spin_lock_irq(&chip->reg_lock);
819 /* disable ringbuffer DMAs */
820 azx_writeb(chip, RIRBCTL, 0);
821 azx_writeb(chip, CORBCTL, 0);
822 spin_unlock_irq(&chip->reg_lock);
823}
824
825static unsigned int azx_command_addr(u32 cmd)
826{
827 unsigned int addr = cmd >> 28;
828
829 if (addr >= AZX_MAX_CODECS) {
830 snd_BUG();
831 addr = 0;
832 }
833
834 return addr;
835}
836
837static unsigned int azx_response_addr(u32 res)
838{
839 unsigned int addr = res & 0xf;
840
841 if (addr >= AZX_MAX_CODECS) {
842 snd_BUG();
843 addr = 0;
844 }
845
846 return addr;
847}
848
849/* send a command */
850static int azx_corb_send_cmd(struct hda_bus *bus, u32 val)
851{
852 struct azx *chip = bus->private_data;
853 unsigned int addr = azx_command_addr(val);
854 unsigned int wp, rp;
855
856 spin_lock_irq(&chip->reg_lock);
857
858 /* add command to corb */
859 wp = azx_readw(chip, CORBWP);
860 if (wp == 0xffff) {
861 /* something wrong, controller likely turned to D3 */
862 spin_unlock_irq(&chip->reg_lock);
863 return -EIO;
864 }
865 wp++;
866 wp %= ICH6_MAX_CORB_ENTRIES;
867
868 rp = azx_readw(chip, CORBRP);
869 if (wp == rp) {
870 /* oops, it's full */
871 spin_unlock_irq(&chip->reg_lock);
872 return -EAGAIN;
873 }
874
875 chip->rirb.cmds[addr]++;
876 chip->corb.buf[wp] = cpu_to_le32(val);
877 azx_writel(chip, CORBWP, wp);
878
879 spin_unlock_irq(&chip->reg_lock);
880
881 return 0;
882}
883
884#define ICH6_RIRB_EX_UNSOL_EV (1<<4)
885
886/* retrieve RIRB entry - called from interrupt handler */
887static void azx_update_rirb(struct azx *chip)
888{
889 unsigned int rp, wp;
890 unsigned int addr;
891 u32 res, res_ex;
892
893 wp = azx_readw(chip, RIRBWP);
894 if (wp == 0xffff) {
895 /* something wrong, controller likely turned to D3 */
896 return;
897 }
898
899 if (wp == chip->rirb.wp)
900 return;
901 chip->rirb.wp = wp;
902
903 while (chip->rirb.rp != wp) {
904 chip->rirb.rp++;
905 chip->rirb.rp %= ICH6_MAX_RIRB_ENTRIES;
906
907 rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */
908 res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]);
909 res = le32_to_cpu(chip->rirb.buf[rp]);
910 addr = azx_response_addr(res_ex);
911 if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
912 snd_hda_queue_unsol_event(chip->bus, res, res_ex);
913 else if (chip->rirb.cmds[addr]) {
914 chip->rirb.res[addr] = res;
915 smp_wmb();
916 chip->rirb.cmds[addr]--;
917 } else if (printk_ratelimit()) {
918 snd_printk(KERN_ERR SFX "%s: spurious response %#x:%#x, last cmd=%#08x\n",
919 pci_name(chip->pci),
920 res, res_ex,
921 chip->last_cmd[addr]);
922 }
923 }
924}
925
926/* receive a response */
927static unsigned int azx_rirb_get_response(struct hda_bus *bus,
928 unsigned int addr)
929{
930 struct azx *chip = bus->private_data;
931 unsigned long timeout;
932 unsigned long loopcounter;
933 int do_poll = 0;
934
935 again:
936 timeout = jiffies + msecs_to_jiffies(1000);
937
938 for (loopcounter = 0;; loopcounter++) {
939 if (chip->polling_mode || do_poll) {
940 spin_lock_irq(&chip->reg_lock);
941 azx_update_rirb(chip);
942 spin_unlock_irq(&chip->reg_lock);
943 }
944 if (!chip->rirb.cmds[addr]) {
945 smp_rmb();
946 bus->rirb_error = 0;
947
948 if (!do_poll)
949 chip->poll_count = 0;
950 return chip->rirb.res[addr]; /* the last value */
951 }
952 if (time_after(jiffies, timeout))
953 break;
954 if (bus->needs_damn_long_delay || loopcounter > 3000)
955 msleep(2); /* temporary workaround */
956 else {
957 udelay(10);
958 cond_resched();
959 }
960 }
961
962 if (!bus->no_response_fallback)
963 return -1;
964
965 if (!chip->polling_mode && chip->poll_count < 2) {
966 snd_printdd(SFX "%s: azx_get_response timeout, "
967 "polling the codec once: last cmd=0x%08x\n",
968 pci_name(chip->pci), chip->last_cmd[addr]);
969 do_poll = 1;
970 chip->poll_count++;
971 goto again;
972 }
973
974
975 if (!chip->polling_mode) {
976 snd_printk(KERN_WARNING SFX "%s: azx_get_response timeout, "
977 "switching to polling mode: last cmd=0x%08x\n",
978 pci_name(chip->pci), chip->last_cmd[addr]);
979 chip->polling_mode = 1;
980 goto again;
981 }
982
983 if (chip->msi) {
984 snd_printk(KERN_WARNING SFX "%s: No response from codec, "
985 "disabling MSI: last cmd=0x%08x\n",
986 pci_name(chip->pci), chip->last_cmd[addr]);
987 free_irq(chip->irq, chip);
988 chip->irq = -1;
989 pci_disable_msi(chip->pci);
990 chip->msi = 0;
991 if (azx_acquire_irq(chip, 1) < 0) {
992 bus->rirb_error = 1;
993 return -1;
994 }
995 goto again;
996 }
997
998 if (chip->probing) {
999 /* If this critical timeout happens during the codec probing
1000 * phase, this is likely an access to a non-existing codec
1001 * slot. Better to return an error and reset the system.
1002 */
1003 return -1;
1004 }
1005
1006 /* a fatal communication error; need either to reset or to fallback
1007 * to the single_cmd mode
1008 */
1009 bus->rirb_error = 1;
1010 if (bus->allow_bus_reset && !bus->response_reset && !bus->in_reset) {
1011 bus->response_reset = 1;
1012 return -1; /* give a chance to retry */
1013 }
1014
1015 snd_printk(KERN_ERR "hda_intel: azx_get_response timeout, "
1016 "switching to single_cmd mode: last cmd=0x%08x\n",
1017 chip->last_cmd[addr]);
1018 chip->single_cmd = 1;
1019 bus->response_reset = 0;
1020 /* release CORB/RIRB */
1021 azx_free_cmd_io(chip);
1022 /* disable unsolicited responses */
1023 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_UNSOL);
1024 return -1;
1025}
1026
1027/*
1028 * Use the single immediate command instead of CORB/RIRB for simplicity
1029 *
1030 * Note: according to Intel, this is not preferred use. The command was
1031 * intended for the BIOS only, and may get confused with unsolicited
1032 * responses. So, we shouldn't use it for normal operation from the
1033 * driver.
1034 * I left the codes, however, for debugging/testing purposes.
1035 */
1036
1037/* receive a response */
1038static int azx_single_wait_for_response(struct azx *chip, unsigned int addr)
1039{
1040 int timeout = 50;
1041
1042 while (timeout--) {
1043 /* check IRV busy bit */
1044 if (azx_readw(chip, IRS) & ICH6_IRS_VALID) {
1045 /* reuse rirb.res as the response return value */
1046 chip->rirb.res[addr] = azx_readl(chip, IR);
1047 return 0;
1048 }
1049 udelay(1);
1050 }
1051 if (printk_ratelimit())
1052 snd_printd(SFX "%s: get_response timeout: IRS=0x%x\n",
1053 pci_name(chip->pci), azx_readw(chip, IRS));
1054 chip->rirb.res[addr] = -1;
1055 return -EIO;
1056}
1057
1058/* send a command */
1059static int azx_single_send_cmd(struct hda_bus *bus, u32 val)
1060{
1061 struct azx *chip = bus->private_data;
1062 unsigned int addr = azx_command_addr(val);
1063 int timeout = 50;
1064
1065 bus->rirb_error = 0;
1066 while (timeout--) {
1067 /* check ICB busy bit */
1068 if (!((azx_readw(chip, IRS) & ICH6_IRS_BUSY))) {
1069 /* Clear IRV valid bit */
1070 azx_writew(chip, IRS, azx_readw(chip, IRS) |
1071 ICH6_IRS_VALID);
1072 azx_writel(chip, IC, val);
1073 azx_writew(chip, IRS, azx_readw(chip, IRS) |
1074 ICH6_IRS_BUSY);
1075 return azx_single_wait_for_response(chip, addr);
1076 }
1077 udelay(1);
1078 }
1079 if (printk_ratelimit())
1080 snd_printd(SFX "%s: send_cmd timeout: IRS=0x%x, val=0x%x\n",
1081 pci_name(chip->pci), azx_readw(chip, IRS), val);
1082 return -EIO;
1083}
1084
1085/* receive a response */
1086static unsigned int azx_single_get_response(struct hda_bus *bus,
1087 unsigned int addr)
1088{
1089 struct azx *chip = bus->private_data;
1090 return chip->rirb.res[addr];
1091}
1092
1093/*
1094 * The below are the main callbacks from hda_codec.
1095 *
1096 * They are just the skeleton to call sub-callbacks according to the
1097 * current setting of chip->single_cmd.
1098 */
1099
1100/* send a command */
1101static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
1102{
1103 struct azx *chip = bus->private_data;
1104
1105 if (chip->disabled)
1106 return 0;
1107 chip->last_cmd[azx_command_addr(val)] = val;
1108 if (chip->single_cmd)
1109 return azx_single_send_cmd(bus, val);
1110 else
1111 return azx_corb_send_cmd(bus, val);
1112}
1113
1114/* get a response */
1115static unsigned int azx_get_response(struct hda_bus *bus,
1116 unsigned int addr)
1117{
1118 struct azx *chip = bus->private_data;
1119 if (chip->disabled)
1120 return 0;
1121 if (chip->single_cmd)
1122 return azx_single_get_response(bus, addr);
1123 else
1124 return azx_rirb_get_response(bus, addr);
1125}
1126
1127#ifdef CONFIG_PM
1128static void azx_power_notify(struct hda_bus *bus, bool power_up);
1129#endif
1130
1131#ifdef CONFIG_SND_HDA_DSP_LOADER
1132static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
1133 unsigned int byte_size,
1134 struct snd_dma_buffer *bufp);
1135static void azx_load_dsp_trigger(struct hda_bus *bus, bool start);
1136static void azx_load_dsp_cleanup(struct hda_bus *bus,
1137 struct snd_dma_buffer *dmab);
1138#endif
1139
1140/* enter link reset */
1141static void azx_enter_link_reset(struct azx *chip)
1142{
1143 unsigned long timeout;
1144
1145 /* reset controller */
1146 azx_writel(chip, GCTL, azx_readl(chip, GCTL) & ~ICH6_GCTL_RESET);
1147
1148 timeout = jiffies + msecs_to_jiffies(100);
1149 while ((azx_readb(chip, GCTL) & ICH6_GCTL_RESET) &&
1150 time_before(jiffies, timeout))
1151 usleep_range(500, 1000);
1152}
1153
1154/* exit link reset */
1155static void azx_exit_link_reset(struct azx *chip)
1156{
1157 unsigned long timeout;
1158
1159 azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
1160
1161 timeout = jiffies + msecs_to_jiffies(100);
1162 while (!azx_readb(chip, GCTL) &&
1163 time_before(jiffies, timeout))
1164 usleep_range(500, 1000);
1165}
1166
1167/* reset codec link */
1168static int azx_reset(struct azx *chip, int full_reset)
1169{
1170 if (!full_reset)
1171 goto __skip;
1172
1173 /* clear STATESTS */
1174 azx_writew(chip, STATESTS, STATESTS_INT_MASK);
1175
1176 /* reset controller */
1177 azx_enter_link_reset(chip);
1178
1179 /* delay for >= 100us for codec PLL to settle per spec
1180 * Rev 0.9 section 5.5.1
1181 */
1182 usleep_range(500, 1000);
1183
1184 /* Bring controller out of reset */
1185 azx_exit_link_reset(chip);
1186
1187 /* Brent Chartrand said to wait >= 540us for codecs to initialize */
1188 usleep_range(1000, 1200);
1189
1190 __skip:
1191 /* check to see if controller is ready */
1192 if (!azx_readb(chip, GCTL)) {
1193 snd_printd(SFX "%s: azx_reset: controller not ready!\n", pci_name(chip->pci));
1194 return -EBUSY;
1195 }
1196
1197 /* Accept unsolicited responses */
1198 if (!chip->single_cmd)
1199 azx_writel(chip, GCTL, azx_readl(chip, GCTL) |
1200 ICH6_GCTL_UNSOL);
1201
1202 /* detect codecs */
1203 if (!chip->codec_mask) {
1204 chip->codec_mask = azx_readw(chip, STATESTS);
1205 snd_printdd(SFX "%s: codec_mask = 0x%x\n", pci_name(chip->pci), chip->codec_mask);
1206 }
1207
1208 return 0;
1209}
1210
1211
1212/*
1213 * Lowlevel interface
1214 */
1215
1216/* enable interrupts */
1217static void azx_int_enable(struct azx *chip)
1218{
1219 /* enable controller CIE and GIE */
1220 azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) |
1221 ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN);
1222}
1223
1224/* disable interrupts */
1225static void azx_int_disable(struct azx *chip)
1226{
1227 int i;
1228
1229 /* disable interrupts in stream descriptor */
1230 for (i = 0; i < chip->num_streams; i++) {
1231 struct azx_dev *azx_dev = &chip->azx_dev[i];
1232 azx_sd_writeb(azx_dev, SD_CTL,
1233 azx_sd_readb(azx_dev, SD_CTL) & ~SD_INT_MASK);
1234 }
1235
1236 /* disable SIE for all streams */
1237 azx_writeb(chip, INTCTL, 0);
1238
1239 /* disable controller CIE and GIE */
1240 azx_writel(chip, INTCTL, azx_readl(chip, INTCTL) &
1241 ~(ICH6_INT_CTRL_EN | ICH6_INT_GLOBAL_EN));
1242}
1243
1244/* clear interrupts */
1245static void azx_int_clear(struct azx *chip)
1246{
1247 int i;
1248
1249 /* clear stream status */
1250 for (i = 0; i < chip->num_streams; i++) {
1251 struct azx_dev *azx_dev = &chip->azx_dev[i];
1252 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
1253 }
1254
1255 /* clear STATESTS */
1256 azx_writew(chip, STATESTS, STATESTS_INT_MASK);
1257
1258 /* clear rirb status */
1259 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
1260
1261 /* clear int status */
1262 azx_writel(chip, INTSTS, ICH6_INT_CTRL_EN | ICH6_INT_ALL_STREAM);
1263}
1264
1265/* start a stream */
1266static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev)
1267{
1268 /*
1269 * Before stream start, initialize parameter
1270 */
1271 azx_dev->insufficient = 1;
1272
1273 /* enable SIE */
1274 azx_writel(chip, INTCTL,
1275 azx_readl(chip, INTCTL) | (1 << azx_dev->index));
1276 /* set DMA start and interrupt mask */
1277 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
1278 SD_CTL_DMA_START | SD_INT_MASK);
1279}
1280
1281/* stop DMA */
1282static void azx_stream_clear(struct azx *chip, struct azx_dev *azx_dev)
1283{
1284 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) &
1285 ~(SD_CTL_DMA_START | SD_INT_MASK));
1286 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */
1287}
1288
1289/* stop a stream */
1290static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev)
1291{
1292 azx_stream_clear(chip, azx_dev);
1293 /* disable SIE */
1294 azx_writel(chip, INTCTL,
1295 azx_readl(chip, INTCTL) & ~(1 << azx_dev->index));
1296}
1297
1298
1299/*
1300 * reset and start the controller registers
1301 */
1302static void azx_init_chip(struct azx *chip, int full_reset)
1303{
1304 if (chip->initialized)
1305 return;
1306
1307 /* reset controller */
1308 azx_reset(chip, full_reset);
1309
1310 /* initialize interrupts */
1311 azx_int_clear(chip);
1312 azx_int_enable(chip);
1313
1314 /* initialize the codec command I/O */
1315 if (!chip->single_cmd)
1316 azx_init_cmd_io(chip);
1317
1318 /* program the position buffer */
1319 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
1320 azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));
1321
1322 chip->initialized = 1;
1323}
1324 338
1325/* 339/*
1326 * initialize the PCI registers 340 * initialize the PCI registers
@@ -1346,7 +360,7 @@ static void azx_init_pci(struct azx *chip)
1346 * The PCI register TCSEL is defined in the Intel manuals. 360 * The PCI register TCSEL is defined in the Intel manuals.
1347 */ 361 */
1348 if (!(chip->driver_caps & AZX_DCAPS_NO_TCSEL)) { 362 if (!(chip->driver_caps & AZX_DCAPS_NO_TCSEL)) {
1349 snd_printdd(SFX "%s: Clearing TCSEL\n", pci_name(chip->pci)); 363 dev_dbg(chip->card->dev, "Clearing TCSEL\n");
1350 update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0); 364 update_pci_byte(chip->pci, ICH6_PCIREG_TCSEL, 0x07, 0);
1351 } 365 }
1352 366
@@ -1354,7 +368,8 @@ static void azx_init_pci(struct azx *chip)
1354 * we need to enable snoop. 368 * we need to enable snoop.
1355 */ 369 */
1356 if (chip->driver_caps & AZX_DCAPS_ATI_SNOOP) { 370 if (chip->driver_caps & AZX_DCAPS_ATI_SNOOP) {
1357 snd_printdd(SFX "%s: Setting ATI snoop: %d\n", pci_name(chip->pci), azx_snoop(chip)); 371 dev_dbg(chip->card->dev, "Setting ATI snoop: %d\n",
372 azx_snoop(chip));
1358 update_pci_byte(chip->pci, 373 update_pci_byte(chip->pci,
1359 ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07, 374 ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07,
1360 azx_snoop(chip) ? ATI_SB450_HDAUDIO_ENABLE_SNOOP : 0); 375 azx_snoop(chip) ? ATI_SB450_HDAUDIO_ENABLE_SNOOP : 0);
@@ -1362,7 +377,8 @@ static void azx_init_pci(struct azx *chip)
1362 377
1363 /* For NVIDIA HDA, enable snoop */ 378 /* For NVIDIA HDA, enable snoop */
1364 if (chip->driver_caps & AZX_DCAPS_NVIDIA_SNOOP) { 379 if (chip->driver_caps & AZX_DCAPS_NVIDIA_SNOOP) {
1365 snd_printdd(SFX "%s: Setting Nvidia snoop: %d\n", pci_name(chip->pci), azx_snoop(chip)); 380 dev_dbg(chip->card->dev, "Setting Nvidia snoop: %d\n",
381 azx_snoop(chip));
1366 update_pci_byte(chip->pci, 382 update_pci_byte(chip->pci,
1367 NVIDIA_HDA_TRANSREG_ADDR, 383 NVIDIA_HDA_TRANSREG_ADDR,
1368 0x0f, NVIDIA_HDA_ENABLE_COHBITS); 384 0x0f, NVIDIA_HDA_ENABLE_COHBITS);
@@ -1387,1114 +403,31 @@ static void azx_init_pci(struct azx *chip)
1387 pci_read_config_word(chip->pci, 403 pci_read_config_word(chip->pci,
1388 INTEL_SCH_HDA_DEVC, &snoop); 404 INTEL_SCH_HDA_DEVC, &snoop);
1389 } 405 }
1390 snd_printdd(SFX "%s: SCH snoop: %s\n", 406 dev_dbg(chip->card->dev, "SCH snoop: %s\n",
1391 pci_name(chip->pci), (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) 407 (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) ?
1392 ? "Disabled" : "Enabled"); 408 "Disabled" : "Enabled");
1393 } 409 }
1394} 410}
1395 411
1396
1397static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev); 412static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
1398 413
1399/* 414/* called from IRQ */
1400 * interrupt handler 415static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev)
1401 */
1402static irqreturn_t azx_interrupt(int irq, void *dev_id)
1403{
1404 struct azx *chip = dev_id;
1405 struct azx_dev *azx_dev;
1406 u32 status;
1407 u8 sd_status;
1408 int i, ok;
1409
1410#ifdef CONFIG_PM_RUNTIME
1411 if (chip->driver_caps & AZX_DCAPS_PM_RUNTIME)
1412 if (chip->pci->dev.power.runtime_status != RPM_ACTIVE)
1413 return IRQ_NONE;
1414#endif
1415
1416 spin_lock(&chip->reg_lock);
1417
1418 if (chip->disabled) {
1419 spin_unlock(&chip->reg_lock);
1420 return IRQ_NONE;
1421 }
1422
1423 status = azx_readl(chip, INTSTS);
1424 if (status == 0 || status == 0xffffffff) {
1425 spin_unlock(&chip->reg_lock);
1426 return IRQ_NONE;
1427 }
1428
1429 for (i = 0; i < chip->num_streams; i++) {
1430 azx_dev = &chip->azx_dev[i];
1431 if (status & azx_dev->sd_int_sta_mask) {
1432 sd_status = azx_sd_readb(azx_dev, SD_STS);
1433 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
1434 if (!azx_dev->substream || !azx_dev->running ||
1435 !(sd_status & SD_INT_COMPLETE))
1436 continue;
1437 /* check whether this IRQ is really acceptable */
1438 ok = azx_position_ok(chip, azx_dev);
1439 if (ok == 1) {
1440 azx_dev->irq_pending = 0;
1441 spin_unlock(&chip->reg_lock);
1442 snd_pcm_period_elapsed(azx_dev->substream);
1443 spin_lock(&chip->reg_lock);
1444 } else if (ok == 0 && chip->bus && chip->bus->workq) {
1445 /* bogus IRQ, process it later */
1446 azx_dev->irq_pending = 1;
1447 queue_work(chip->bus->workq,
1448 &chip->irq_pending_work);
1449 }
1450 }
1451 }
1452
1453 /* clear rirb int */
1454 status = azx_readb(chip, RIRBSTS);
1455 if (status & RIRB_INT_MASK) {
1456 if (status & RIRB_INT_RESPONSE) {
1457 if (chip->driver_caps & AZX_DCAPS_RIRB_PRE_DELAY)
1458 udelay(80);
1459 azx_update_rirb(chip);
1460 }
1461 azx_writeb(chip, RIRBSTS, RIRB_INT_MASK);
1462 }
1463
1464#if 0
1465 /* clear state status int */
1466 if (azx_readw(chip, STATESTS) & 0x04)
1467 azx_writew(chip, STATESTS, 0x04);
1468#endif
1469 spin_unlock(&chip->reg_lock);
1470
1471 return IRQ_HANDLED;
1472}
1473
1474
1475/*
1476 * set up a BDL entry
1477 */
1478static int setup_bdle(struct azx *chip,
1479 struct snd_dma_buffer *dmab,
1480 struct azx_dev *azx_dev, u32 **bdlp,
1481 int ofs, int size, int with_ioc)
1482{
1483 u32 *bdl = *bdlp;
1484
1485 while (size > 0) {
1486 dma_addr_t addr;
1487 int chunk;
1488
1489 if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
1490 return -EINVAL;
1491
1492 addr = snd_sgbuf_get_addr(dmab, ofs);
1493 /* program the address field of the BDL entry */
1494 bdl[0] = cpu_to_le32((u32)addr);
1495 bdl[1] = cpu_to_le32(upper_32_bits(addr));
1496 /* program the size field of the BDL entry */
1497 chunk = snd_sgbuf_get_chunk_size(dmab, ofs, size);
1498 /* one BDLE cannot cross 4K boundary on CTHDA chips */
1499 if (chip->driver_caps & AZX_DCAPS_4K_BDLE_BOUNDARY) {
1500 u32 remain = 0x1000 - (ofs & 0xfff);
1501 if (chunk > remain)
1502 chunk = remain;
1503 }
1504 bdl[2] = cpu_to_le32(chunk);
1505 /* program the IOC to enable interrupt
1506 * only when the whole fragment is processed
1507 */
1508 size -= chunk;
1509 bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
1510 bdl += 4;
1511 azx_dev->frags++;
1512 ofs += chunk;
1513 }
1514 *bdlp = bdl;
1515 return ofs;
1516}
1517
1518/*
1519 * set up BDL entries
1520 */
1521static int azx_setup_periods(struct azx *chip,
1522 struct snd_pcm_substream *substream,
1523 struct azx_dev *azx_dev)
1524{
1525 u32 *bdl;
1526 int i, ofs, periods, period_bytes;
1527 int pos_adj;
1528
1529 /* reset BDL address */
1530 azx_sd_writel(azx_dev, SD_BDLPL, 0);
1531 azx_sd_writel(azx_dev, SD_BDLPU, 0);
1532
1533 period_bytes = azx_dev->period_bytes;
1534 periods = azx_dev->bufsize / period_bytes;
1535
1536 /* program the initial BDL entries */
1537 bdl = (u32 *)azx_dev->bdl.area;
1538 ofs = 0;
1539 azx_dev->frags = 0;
1540 pos_adj = bdl_pos_adj[chip->dev_index];
1541 if (!azx_dev->no_period_wakeup && pos_adj > 0) {
1542 struct snd_pcm_runtime *runtime = substream->runtime;
1543 int pos_align = pos_adj;
1544 pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
1545 if (!pos_adj)
1546 pos_adj = pos_align;
1547 else
1548 pos_adj = ((pos_adj + pos_align - 1) / pos_align) *
1549 pos_align;
1550 pos_adj = frames_to_bytes(runtime, pos_adj);
1551 if (pos_adj >= period_bytes) {
1552 snd_printk(KERN_WARNING SFX "%s: Too big adjustment %d\n",
1553 pci_name(chip->pci), bdl_pos_adj[chip->dev_index]);
1554 pos_adj = 0;
1555 } else {
1556 ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
1557 azx_dev,
1558 &bdl, ofs, pos_adj, true);
1559 if (ofs < 0)
1560 goto error;
1561 }
1562 } else
1563 pos_adj = 0;
1564 for (i = 0; i < periods; i++) {
1565 if (i == periods - 1 && pos_adj)
1566 ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
1567 azx_dev, &bdl, ofs,
1568 period_bytes - pos_adj, 0);
1569 else
1570 ofs = setup_bdle(chip, snd_pcm_get_dma_buf(substream),
1571 azx_dev, &bdl, ofs,
1572 period_bytes,
1573 !azx_dev->no_period_wakeup);
1574 if (ofs < 0)
1575 goto error;
1576 }
1577 return 0;
1578
1579 error:
1580 snd_printk(KERN_ERR SFX "%s: Too many BDL entries: buffer=%d, period=%d\n",
1581 pci_name(chip->pci), azx_dev->bufsize, period_bytes);
1582 return -EINVAL;
1583}
1584
1585/* reset stream */
1586static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
1587{
1588 unsigned char val;
1589 int timeout;
1590
1591 azx_stream_clear(chip, azx_dev);
1592
1593 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
1594 SD_CTL_STREAM_RESET);
1595 udelay(3);
1596 timeout = 300;
1597 while (!((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
1598 --timeout)
1599 ;
1600 val &= ~SD_CTL_STREAM_RESET;
1601 azx_sd_writeb(azx_dev, SD_CTL, val);
1602 udelay(3);
1603
1604 timeout = 300;
1605 /* waiting for hardware to report that the stream is out of reset */
1606 while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
1607 --timeout)
1608 ;
1609
1610 /* reset first position - may not be synced with hw at this time */
1611 *azx_dev->posbuf = 0;
1612}
1613
1614/*
1615 * set up the SD for streaming
1616 */
1617static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1618{
1619 unsigned int val;
1620 /* make sure the run bit is zero for SD */
1621 azx_stream_clear(chip, azx_dev);
1622 /* program the stream_tag */
1623 val = azx_sd_readl(azx_dev, SD_CTL);
1624 val = (val & ~SD_CTL_STREAM_TAG_MASK) |
1625 (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT);
1626 if (!azx_snoop(chip))
1627 val |= SD_CTL_TRAFFIC_PRIO;
1628 azx_sd_writel(azx_dev, SD_CTL, val);
1629
1630 /* program the length of samples in cyclic buffer */
1631 azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize);
1632
1633 /* program the stream format */
1634 /* this value needs to be the same as the one programmed */
1635 azx_sd_writew(azx_dev, SD_FORMAT, azx_dev->format_val);
1636
1637 /* program the stream LVI (last valid index) of the BDL */
1638 azx_sd_writew(azx_dev, SD_LVI, azx_dev->frags - 1);
1639
1640 /* program the BDL address */
1641 /* lower BDL address */
1642 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
1643 /* upper BDL address */
1644 azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));
1645
1646 /* enable the position buffer */
1647 if (chip->position_fix[0] != POS_FIX_LPIB ||
1648 chip->position_fix[1] != POS_FIX_LPIB) {
1649 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
1650 azx_writel(chip, DPLBASE,
1651 (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
1652 }
1653
1654 /* set the interrupt enable bits in the descriptor control register */
1655 azx_sd_writel(azx_dev, SD_CTL,
1656 azx_sd_readl(azx_dev, SD_CTL) | SD_INT_MASK);
1657
1658 return 0;
1659}
1660
1661/*
1662 * Probe the given codec address
1663 */
1664static int probe_codec(struct azx *chip, int addr)
1665{
1666 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
1667 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
1668 unsigned int res;
1669
1670 mutex_lock(&chip->bus->cmd_mutex);
1671 chip->probing = 1;
1672 azx_send_cmd(chip->bus, cmd);
1673 res = azx_get_response(chip->bus, addr);
1674 chip->probing = 0;
1675 mutex_unlock(&chip->bus->cmd_mutex);
1676 if (res == -1)
1677 return -EIO;
1678 snd_printdd(SFX "%s: codec #%d probed OK\n", pci_name(chip->pci), addr);
1679 return 0;
1680}
1681
1682static int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
1683 struct hda_pcm *cpcm);
1684static void azx_stop_chip(struct azx *chip);
1685
1686static void azx_bus_reset(struct hda_bus *bus)
1687{
1688 struct azx *chip = bus->private_data;
1689
1690 bus->in_reset = 1;
1691 azx_stop_chip(chip);
1692 azx_init_chip(chip, 1);
1693#ifdef CONFIG_PM
1694 if (chip->initialized) {
1695 struct azx_pcm *p;
1696 list_for_each_entry(p, &chip->pcm_list, list)
1697 snd_pcm_suspend_all(p->pcm);
1698 snd_hda_suspend(chip->bus);
1699 snd_hda_resume(chip->bus);
1700 }
1701#endif
1702 bus->in_reset = 0;
1703}
1704
1705static int get_jackpoll_interval(struct azx *chip)
1706{
1707 int i = jackpoll_ms[chip->dev_index];
1708 unsigned int j;
1709 if (i == 0)
1710 return 0;
1711 if (i < 50 || i > 60000)
1712 j = 0;
1713 else
1714 j = msecs_to_jiffies(i);
1715 if (j == 0)
1716 snd_printk(KERN_WARNING SFX
1717 "jackpoll_ms value out of range: %d\n", i);
1718 return j;
1719}
1720
1721/*
1722 * Codec initialization
1723 */
1724
1725/* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
1726static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = {
1727 [AZX_DRIVER_NVIDIA] = 8,
1728 [AZX_DRIVER_TERA] = 1,
1729};
1730
1731static int azx_codec_create(struct azx *chip, const char *model)
1732{
1733 struct hda_bus_template bus_temp;
1734 int c, codecs, err;
1735 int max_slots;
1736
1737 memset(&bus_temp, 0, sizeof(bus_temp));
1738 bus_temp.private_data = chip;
1739 bus_temp.modelname = model;
1740 bus_temp.pci = chip->pci;
1741 bus_temp.ops.command = azx_send_cmd;
1742 bus_temp.ops.get_response = azx_get_response;
1743 bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
1744 bus_temp.ops.bus_reset = azx_bus_reset;
1745#ifdef CONFIG_PM
1746 bus_temp.power_save = &power_save;
1747 bus_temp.ops.pm_notify = azx_power_notify;
1748#endif
1749#ifdef CONFIG_SND_HDA_DSP_LOADER
1750 bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare;
1751 bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger;
1752 bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup;
1753#endif
1754
1755 err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
1756 if (err < 0)
1757 return err;
1758
1759 if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) {
1760 snd_printd(SFX "%s: Enable delay in RIRB handling\n", pci_name(chip->pci));
1761 chip->bus->needs_damn_long_delay = 1;
1762 }
1763
1764 codecs = 0;
1765 max_slots = azx_max_codecs[chip->driver_type];
1766 if (!max_slots)
1767 max_slots = AZX_DEFAULT_CODECS;
1768
1769 /* First try to probe all given codec slots */
1770 for (c = 0; c < max_slots; c++) {
1771 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1772 if (probe_codec(chip, c) < 0) {
1773 /* Some BIOSen give you wrong codec addresses
1774 * that don't exist
1775 */
1776 snd_printk(KERN_WARNING SFX
1777 "%s: Codec #%d probe error; "
1778 "disabling it...\n", pci_name(chip->pci), c);
1779 chip->codec_mask &= ~(1 << c);
1780 /* More badly, accessing to a non-existing
1781 * codec often screws up the controller chip,
1782 * and disturbs the further communications.
1783 * Thus if an error occurs during probing,
1784 * better to reset the controller chip to
1785 * get back to the sanity state.
1786 */
1787 azx_stop_chip(chip);
1788 azx_init_chip(chip, 1);
1789 }
1790 }
1791 }
1792
1793 /* AMD chipsets often cause the communication stalls upon certain
1794 * sequence like the pin-detection. It seems that forcing the synced
1795 * access works around the stall. Grrr...
1796 */
1797 if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) {
1798 snd_printd(SFX "%s: Enable sync_write for stable communication\n",
1799 pci_name(chip->pci));
1800 chip->bus->sync_write = 1;
1801 chip->bus->allow_bus_reset = 1;
1802 }
1803
1804 /* Then create codec instances */
1805 for (c = 0; c < max_slots; c++) {
1806 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1807 struct hda_codec *codec;
1808 err = snd_hda_codec_new(chip->bus, c, &codec);
1809 if (err < 0)
1810 continue;
1811 codec->jackpoll_interval = get_jackpoll_interval(chip);
1812 codec->beep_mode = chip->beep_mode;
1813 codecs++;
1814 }
1815 }
1816 if (!codecs) {
1817 snd_printk(KERN_ERR SFX "%s: no codecs initialized\n", pci_name(chip->pci));
1818 return -ENXIO;
1819 }
1820 return 0;
1821}
1822
1823/* configure each codec instance */
1824static int azx_codec_configure(struct azx *chip)
1825{
1826 struct hda_codec *codec;
1827 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1828 snd_hda_codec_configure(codec);
1829 }
1830 return 0;
1831}
1832
1833
1834/*
1835 * PCM support
1836 */
1837
1838/* assign a stream for the PCM */
1839static inline struct azx_dev *
1840azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
1841{
1842 int dev, i, nums;
1843 struct azx_dev *res = NULL;
1844 /* make a non-zero unique key for the substream */
1845 int key = (substream->pcm->device << 16) | (substream->number << 2) |
1846 (substream->stream + 1);
1847
1848 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1849 dev = chip->playback_index_offset;
1850 nums = chip->playback_streams;
1851 } else {
1852 dev = chip->capture_index_offset;
1853 nums = chip->capture_streams;
1854 }
1855 for (i = 0; i < nums; i++, dev++) {
1856 struct azx_dev *azx_dev = &chip->azx_dev[dev];
1857 dsp_lock(azx_dev);
1858 if (!azx_dev->opened && !dsp_is_locked(azx_dev)) {
1859 res = azx_dev;
1860 if (res->assigned_key == key) {
1861 res->opened = 1;
1862 res->assigned_key = key;
1863 dsp_unlock(azx_dev);
1864 return azx_dev;
1865 }
1866 }
1867 dsp_unlock(azx_dev);
1868 }
1869 if (res) {
1870 dsp_lock(res);
1871 res->opened = 1;
1872 res->assigned_key = key;
1873 dsp_unlock(res);
1874 }
1875 return res;
1876}
1877
1878/* release the assigned stream */
1879static inline void azx_release_device(struct azx_dev *azx_dev)
1880{ 416{
1881 azx_dev->opened = 0; 417 int ok;
1882}
1883
1884static cycle_t azx_cc_read(const struct cyclecounter *cc)
1885{
1886 struct azx_dev *azx_dev = container_of(cc, struct azx_dev, azx_cc);
1887 struct snd_pcm_substream *substream = azx_dev->substream;
1888 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1889 struct azx *chip = apcm->chip;
1890
1891 return azx_readl(chip, WALLCLK);
1892}
1893
1894static void azx_timecounter_init(struct snd_pcm_substream *substream,
1895 bool force, cycle_t last)
1896{
1897 struct azx_dev *azx_dev = get_azx_dev(substream);
1898 struct timecounter *tc = &azx_dev->azx_tc;
1899 struct cyclecounter *cc = &azx_dev->azx_cc;
1900 u64 nsec;
1901
1902 cc->read = azx_cc_read;
1903 cc->mask = CLOCKSOURCE_MASK(32);
1904
1905 /*
1906 * Converting from 24 MHz to ns means applying a 125/3 factor.
1907 * To avoid any saturation issues in intermediate operations,
1908 * the 125 factor is applied first. The division is applied
1909 * last after reading the timecounter value.
1910 * Applying the 1/3 factor as part of the multiplication
1911 * requires at least 20 bits for a decent precision, however
1912 * overflows occur after about 4 hours or less, not a option.
1913 */
1914
1915 cc->mult = 125; /* saturation after 195 years */
1916 cc->shift = 0;
1917
1918 nsec = 0; /* audio time is elapsed time since trigger */
1919 timecounter_init(tc, cc, nsec);
1920 if (force)
1921 /*
1922 * force timecounter to use predefined value,
1923 * used for synchronized starts
1924 */
1925 tc->cycle_last = last;
1926}
1927
1928static u64 azx_adjust_codec_delay(struct snd_pcm_substream *substream,
1929 u64 nsec)
1930{
1931 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1932 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
1933 u64 codec_frames, codec_nsecs;
1934
1935 if (!hinfo->ops.get_delay)
1936 return nsec;
1937
1938 codec_frames = hinfo->ops.get_delay(hinfo, apcm->codec, substream);
1939 codec_nsecs = div_u64(codec_frames * 1000000000LL,
1940 substream->runtime->rate);
1941
1942 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
1943 return nsec + codec_nsecs;
1944
1945 return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0;
1946}
1947
1948static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream,
1949 struct timespec *ts)
1950{
1951 struct azx_dev *azx_dev = get_azx_dev(substream);
1952 u64 nsec;
1953
1954 nsec = timecounter_read(&azx_dev->azx_tc);
1955 nsec = div_u64(nsec, 3); /* can be optimized */
1956 nsec = azx_adjust_codec_delay(substream, nsec);
1957
1958 *ts = ns_to_timespec(nsec);
1959
1960 return 0;
1961}
1962
1963static struct snd_pcm_hardware azx_pcm_hw = {
1964 .info = (SNDRV_PCM_INFO_MMAP |
1965 SNDRV_PCM_INFO_INTERLEAVED |
1966 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1967 SNDRV_PCM_INFO_MMAP_VALID |
1968 /* No full-resume yet implemented */
1969 /* SNDRV_PCM_INFO_RESUME |*/
1970 SNDRV_PCM_INFO_PAUSE |
1971 SNDRV_PCM_INFO_SYNC_START |
1972 SNDRV_PCM_INFO_HAS_WALL_CLOCK |
1973 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
1974 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1975 .rates = SNDRV_PCM_RATE_48000,
1976 .rate_min = 48000,
1977 .rate_max = 48000,
1978 .channels_min = 2,
1979 .channels_max = 2,
1980 .buffer_bytes_max = AZX_MAX_BUF_SIZE,
1981 .period_bytes_min = 128,
1982 .period_bytes_max = AZX_MAX_BUF_SIZE / 2,
1983 .periods_min = 2,
1984 .periods_max = AZX_MAX_FRAG,
1985 .fifo_size = 0,
1986};
1987
1988static int azx_pcm_open(struct snd_pcm_substream *substream)
1989{
1990 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1991 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
1992 struct azx *chip = apcm->chip;
1993 struct azx_dev *azx_dev;
1994 struct snd_pcm_runtime *runtime = substream->runtime;
1995 unsigned long flags;
1996 int err;
1997 int buff_step;
1998 418
1999 mutex_lock(&chip->open_mutex); 419 ok = azx_position_ok(chip, azx_dev);
2000 azx_dev = azx_assign_device(chip, substream); 420 if (ok == 1) {
2001 if (azx_dev == NULL) { 421 azx_dev->irq_pending = 0;
2002 mutex_unlock(&chip->open_mutex); 422 return ok;
2003 return -EBUSY; 423 } else if (ok == 0 && chip->bus && chip->bus->workq) {
2004 } 424 /* bogus IRQ, process it later */
2005 runtime->hw = azx_pcm_hw; 425 azx_dev->irq_pending = 1;
2006 runtime->hw.channels_min = hinfo->channels_min; 426 queue_work(chip->bus->workq, &chip->irq_pending_work);
2007 runtime->hw.channels_max = hinfo->channels_max;
2008 runtime->hw.formats = hinfo->formats;
2009 runtime->hw.rates = hinfo->rates;
2010 snd_pcm_limit_hw_rates(runtime);
2011 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
2012
2013 /* avoid wrap-around with wall-clock */
2014 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME,
2015 20,
2016 178000000);
2017
2018 if (chip->align_buffer_size)
2019 /* constrain buffer sizes to be multiple of 128
2020 bytes. This is more efficient in terms of memory
2021 access but isn't required by the HDA spec and
2022 prevents users from specifying exact period/buffer
2023 sizes. For example for 44.1kHz, a period size set
2024 to 20ms will be rounded to 19.59ms. */
2025 buff_step = 128;
2026 else
2027 /* Don't enforce steps on buffer sizes, still need to
2028 be multiple of 4 bytes (HDA spec). Tested on Intel
2029 HDA controllers, may not work on all devices where
2030 option needs to be disabled */
2031 buff_step = 4;
2032
2033 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
2034 buff_step);
2035 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
2036 buff_step);
2037 snd_hda_power_up_d3wait(apcm->codec);
2038 err = hinfo->ops.open(hinfo, apcm->codec, substream);
2039 if (err < 0) {
2040 azx_release_device(azx_dev);
2041 snd_hda_power_down(apcm->codec);
2042 mutex_unlock(&chip->open_mutex);
2043 return err;
2044 } 427 }
2045 snd_pcm_limit_hw_rates(runtime);
2046 /* sanity check */
2047 if (snd_BUG_ON(!runtime->hw.channels_min) ||
2048 snd_BUG_ON(!runtime->hw.channels_max) ||
2049 snd_BUG_ON(!runtime->hw.formats) ||
2050 snd_BUG_ON(!runtime->hw.rates)) {
2051 azx_release_device(azx_dev);
2052 hinfo->ops.close(hinfo, apcm->codec, substream);
2053 snd_hda_power_down(apcm->codec);
2054 mutex_unlock(&chip->open_mutex);
2055 return -EINVAL;
2056 }
2057
2058 /* disable WALLCLOCK timestamps for capture streams
2059 until we figure out how to handle digital inputs */
2060 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
2061 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK;
2062
2063 spin_lock_irqsave(&chip->reg_lock, flags);
2064 azx_dev->substream = substream;
2065 azx_dev->running = 0;
2066 spin_unlock_irqrestore(&chip->reg_lock, flags);
2067
2068 runtime->private_data = azx_dev;
2069 snd_pcm_set_sync(substream);
2070 mutex_unlock(&chip->open_mutex);
2071 return 0; 428 return 0;
2072} 429}
2073 430
2074static int azx_pcm_close(struct snd_pcm_substream *substream)
2075{
2076 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2077 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
2078 struct azx *chip = apcm->chip;
2079 struct azx_dev *azx_dev = get_azx_dev(substream);
2080 unsigned long flags;
2081
2082 mutex_lock(&chip->open_mutex);
2083 spin_lock_irqsave(&chip->reg_lock, flags);
2084 azx_dev->substream = NULL;
2085 azx_dev->running = 0;
2086 spin_unlock_irqrestore(&chip->reg_lock, flags);
2087 azx_release_device(azx_dev);
2088 hinfo->ops.close(hinfo, apcm->codec, substream);
2089 snd_hda_power_down(apcm->codec);
2090 mutex_unlock(&chip->open_mutex);
2091 return 0;
2092}
2093
2094static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
2095 struct snd_pcm_hw_params *hw_params)
2096{
2097 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2098 struct azx *chip = apcm->chip;
2099 struct azx_dev *azx_dev = get_azx_dev(substream);
2100 int ret;
2101
2102 dsp_lock(azx_dev);
2103 if (dsp_is_locked(azx_dev)) {
2104 ret = -EBUSY;
2105 goto unlock;
2106 }
2107
2108 mark_runtime_wc(chip, azx_dev, substream, false);
2109 azx_dev->bufsize = 0;
2110 azx_dev->period_bytes = 0;
2111 azx_dev->format_val = 0;
2112 ret = snd_pcm_lib_malloc_pages(substream,
2113 params_buffer_bytes(hw_params));
2114 if (ret < 0)
2115 goto unlock;
2116 mark_runtime_wc(chip, azx_dev, substream, true);
2117 unlock:
2118 dsp_unlock(azx_dev);
2119 return ret;
2120}
2121
2122static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
2123{
2124 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2125 struct azx_dev *azx_dev = get_azx_dev(substream);
2126 struct azx *chip = apcm->chip;
2127 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
2128
2129 /* reset BDL address */
2130 dsp_lock(azx_dev);
2131 if (!dsp_is_locked(azx_dev)) {
2132 azx_sd_writel(azx_dev, SD_BDLPL, 0);
2133 azx_sd_writel(azx_dev, SD_BDLPU, 0);
2134 azx_sd_writel(azx_dev, SD_CTL, 0);
2135 azx_dev->bufsize = 0;
2136 azx_dev->period_bytes = 0;
2137 azx_dev->format_val = 0;
2138 }
2139
2140 snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
2141
2142 mark_runtime_wc(chip, azx_dev, substream, false);
2143 azx_dev->prepared = 0;
2144 dsp_unlock(azx_dev);
2145 return snd_pcm_lib_free_pages(substream);
2146}
2147
2148static int azx_pcm_prepare(struct snd_pcm_substream *substream)
2149{
2150 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2151 struct azx *chip = apcm->chip;
2152 struct azx_dev *azx_dev = get_azx_dev(substream);
2153 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
2154 struct snd_pcm_runtime *runtime = substream->runtime;
2155 unsigned int bufsize, period_bytes, format_val, stream_tag;
2156 int err;
2157 struct hda_spdif_out *spdif =
2158 snd_hda_spdif_out_of_nid(apcm->codec, hinfo->nid);
2159 unsigned short ctls = spdif ? spdif->ctls : 0;
2160
2161 dsp_lock(azx_dev);
2162 if (dsp_is_locked(azx_dev)) {
2163 err = -EBUSY;
2164 goto unlock;
2165 }
2166
2167 azx_stream_reset(chip, azx_dev);
2168 format_val = snd_hda_calc_stream_format(runtime->rate,
2169 runtime->channels,
2170 runtime->format,
2171 hinfo->maxbps,
2172 ctls);
2173 if (!format_val) {
2174 snd_printk(KERN_ERR SFX
2175 "%s: invalid format_val, rate=%d, ch=%d, format=%d\n",
2176 pci_name(chip->pci), runtime->rate, runtime->channels, runtime->format);
2177 err = -EINVAL;
2178 goto unlock;
2179 }
2180
2181 bufsize = snd_pcm_lib_buffer_bytes(substream);
2182 period_bytes = snd_pcm_lib_period_bytes(substream);
2183
2184 snd_printdd(SFX "%s: azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
2185 pci_name(chip->pci), bufsize, format_val);
2186
2187 if (bufsize != azx_dev->bufsize ||
2188 period_bytes != azx_dev->period_bytes ||
2189 format_val != azx_dev->format_val ||
2190 runtime->no_period_wakeup != azx_dev->no_period_wakeup) {
2191 azx_dev->bufsize = bufsize;
2192 azx_dev->period_bytes = period_bytes;
2193 azx_dev->format_val = format_val;
2194 azx_dev->no_period_wakeup = runtime->no_period_wakeup;
2195 err = azx_setup_periods(chip, substream, azx_dev);
2196 if (err < 0)
2197 goto unlock;
2198 }
2199
2200 /* when LPIB delay correction gives a small negative value,
2201 * we ignore it; currently set the threshold statically to
2202 * 64 frames
2203 */
2204 if (runtime->period_size > 64)
2205 azx_dev->delay_negative_threshold = -frames_to_bytes(runtime, 64);
2206 else
2207 azx_dev->delay_negative_threshold = 0;
2208
2209 /* wallclk has 24Mhz clock source */
2210 azx_dev->period_wallclk = (((runtime->period_size * 24000) /
2211 runtime->rate) * 1000);
2212 azx_setup_controller(chip, azx_dev);
2213 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
2214 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
2215 else
2216 azx_dev->fifo_size = 0;
2217
2218 stream_tag = azx_dev->stream_tag;
2219 /* CA-IBG chips need the playback stream starting from 1 */
2220 if ((chip->driver_caps & AZX_DCAPS_CTX_WORKAROUND) &&
2221 stream_tag > chip->capture_streams)
2222 stream_tag -= chip->capture_streams;
2223 err = snd_hda_codec_prepare(apcm->codec, hinfo, stream_tag,
2224 azx_dev->format_val, substream);
2225
2226 unlock:
2227 if (!err)
2228 azx_dev->prepared = 1;
2229 dsp_unlock(azx_dev);
2230 return err;
2231}
2232
2233static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
2234{
2235 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2236 struct azx *chip = apcm->chip;
2237 struct azx_dev *azx_dev;
2238 struct snd_pcm_substream *s;
2239 int rstart = 0, start, nsync = 0, sbits = 0;
2240 int nwait, timeout;
2241
2242 azx_dev = get_azx_dev(substream);
2243 trace_azx_pcm_trigger(chip, azx_dev, cmd);
2244
2245 if (dsp_is_locked(azx_dev) || !azx_dev->prepared)
2246 return -EPIPE;
2247
2248 switch (cmd) {
2249 case SNDRV_PCM_TRIGGER_START:
2250 rstart = 1;
2251 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2252 case SNDRV_PCM_TRIGGER_RESUME:
2253 start = 1;
2254 break;
2255 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2256 case SNDRV_PCM_TRIGGER_SUSPEND:
2257 case SNDRV_PCM_TRIGGER_STOP:
2258 start = 0;
2259 break;
2260 default:
2261 return -EINVAL;
2262 }
2263
2264 snd_pcm_group_for_each_entry(s, substream) {
2265 if (s->pcm->card != substream->pcm->card)
2266 continue;
2267 azx_dev = get_azx_dev(s);
2268 sbits |= 1 << azx_dev->index;
2269 nsync++;
2270 snd_pcm_trigger_done(s, substream);
2271 }
2272
2273 spin_lock(&chip->reg_lock);
2274
2275 /* first, set SYNC bits of corresponding streams */
2276 if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC)
2277 azx_writel(chip, OLD_SSYNC,
2278 azx_readl(chip, OLD_SSYNC) | sbits);
2279 else
2280 azx_writel(chip, SSYNC, azx_readl(chip, SSYNC) | sbits);
2281
2282 snd_pcm_group_for_each_entry(s, substream) {
2283 if (s->pcm->card != substream->pcm->card)
2284 continue;
2285 azx_dev = get_azx_dev(s);
2286 if (start) {
2287 azx_dev->start_wallclk = azx_readl(chip, WALLCLK);
2288 if (!rstart)
2289 azx_dev->start_wallclk -=
2290 azx_dev->period_wallclk;
2291 azx_stream_start(chip, azx_dev);
2292 } else {
2293 azx_stream_stop(chip, azx_dev);
2294 }
2295 azx_dev->running = start;
2296 }
2297 spin_unlock(&chip->reg_lock);
2298 if (start) {
2299 /* wait until all FIFOs get ready */
2300 for (timeout = 5000; timeout; timeout--) {
2301 nwait = 0;
2302 snd_pcm_group_for_each_entry(s, substream) {
2303 if (s->pcm->card != substream->pcm->card)
2304 continue;
2305 azx_dev = get_azx_dev(s);
2306 if (!(azx_sd_readb(azx_dev, SD_STS) &
2307 SD_STS_FIFO_READY))
2308 nwait++;
2309 }
2310 if (!nwait)
2311 break;
2312 cpu_relax();
2313 }
2314 } else {
2315 /* wait until all RUN bits are cleared */
2316 for (timeout = 5000; timeout; timeout--) {
2317 nwait = 0;
2318 snd_pcm_group_for_each_entry(s, substream) {
2319 if (s->pcm->card != substream->pcm->card)
2320 continue;
2321 azx_dev = get_azx_dev(s);
2322 if (azx_sd_readb(azx_dev, SD_CTL) &
2323 SD_CTL_DMA_START)
2324 nwait++;
2325 }
2326 if (!nwait)
2327 break;
2328 cpu_relax();
2329 }
2330 }
2331 spin_lock(&chip->reg_lock);
2332 /* reset SYNC bits */
2333 if (chip->driver_caps & AZX_DCAPS_OLD_SSYNC)
2334 azx_writel(chip, OLD_SSYNC,
2335 azx_readl(chip, OLD_SSYNC) & ~sbits);
2336 else
2337 azx_writel(chip, SSYNC, azx_readl(chip, SSYNC) & ~sbits);
2338 if (start) {
2339 azx_timecounter_init(substream, 0, 0);
2340 if (nsync > 1) {
2341 cycle_t cycle_last;
2342
2343 /* same start cycle for master and group */
2344 azx_dev = get_azx_dev(substream);
2345 cycle_last = azx_dev->azx_tc.cycle_last;
2346
2347 snd_pcm_group_for_each_entry(s, substream) {
2348 if (s->pcm->card != substream->pcm->card)
2349 continue;
2350 azx_timecounter_init(s, 1, cycle_last);
2351 }
2352 }
2353 }
2354 spin_unlock(&chip->reg_lock);
2355 return 0;
2356}
2357
2358/* get the current DMA position with correction on VIA chips */
2359static unsigned int azx_via_get_position(struct azx *chip,
2360 struct azx_dev *azx_dev)
2361{
2362 unsigned int link_pos, mini_pos, bound_pos;
2363 unsigned int mod_link_pos, mod_dma_pos, mod_mini_pos;
2364 unsigned int fifo_size;
2365
2366 link_pos = azx_sd_readl(azx_dev, SD_LPIB);
2367 if (azx_dev->substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2368 /* Playback, no problem using link position */
2369 return link_pos;
2370 }
2371
2372 /* Capture */
2373 /* For new chipset,
2374 * use mod to get the DMA position just like old chipset
2375 */
2376 mod_dma_pos = le32_to_cpu(*azx_dev->posbuf);
2377 mod_dma_pos %= azx_dev->period_bytes;
2378
2379 /* azx_dev->fifo_size can't get FIFO size of in stream.
2380 * Get from base address + offset.
2381 */
2382 fifo_size = readw(chip->remap_addr + VIA_IN_STREAM0_FIFO_SIZE_OFFSET);
2383
2384 if (azx_dev->insufficient) {
2385 /* Link position never gather than FIFO size */
2386 if (link_pos <= fifo_size)
2387 return 0;
2388
2389 azx_dev->insufficient = 0;
2390 }
2391
2392 if (link_pos <= fifo_size)
2393 mini_pos = azx_dev->bufsize + link_pos - fifo_size;
2394 else
2395 mini_pos = link_pos - fifo_size;
2396
2397 /* Find nearest previous boudary */
2398 mod_mini_pos = mini_pos % azx_dev->period_bytes;
2399 mod_link_pos = link_pos % azx_dev->period_bytes;
2400 if (mod_link_pos >= fifo_size)
2401 bound_pos = link_pos - mod_link_pos;
2402 else if (mod_dma_pos >= mod_mini_pos)
2403 bound_pos = mini_pos - mod_mini_pos;
2404 else {
2405 bound_pos = mini_pos - mod_mini_pos + azx_dev->period_bytes;
2406 if (bound_pos >= azx_dev->bufsize)
2407 bound_pos = 0;
2408 }
2409
2410 /* Calculate real DMA position we want */
2411 return bound_pos + mod_dma_pos;
2412}
2413
2414static unsigned int azx_get_position(struct azx *chip,
2415 struct azx_dev *azx_dev,
2416 bool with_check)
2417{
2418 struct snd_pcm_substream *substream = azx_dev->substream;
2419 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2420 unsigned int pos;
2421 int stream = substream->stream;
2422 struct hda_pcm_stream *hinfo = apcm->hinfo[stream];
2423 int delay = 0;
2424
2425 switch (chip->position_fix[stream]) {
2426 case POS_FIX_LPIB:
2427 /* read LPIB */
2428 pos = azx_sd_readl(azx_dev, SD_LPIB);
2429 break;
2430 case POS_FIX_VIACOMBO:
2431 pos = azx_via_get_position(chip, azx_dev);
2432 break;
2433 default:
2434 /* use the position buffer */
2435 pos = le32_to_cpu(*azx_dev->posbuf);
2436 if (with_check && chip->position_fix[stream] == POS_FIX_AUTO) {
2437 if (!pos || pos == (u32)-1) {
2438 printk(KERN_WARNING
2439 "hda-intel: Invalid position buffer, "
2440 "using LPIB read method instead.\n");
2441 chip->position_fix[stream] = POS_FIX_LPIB;
2442 pos = azx_sd_readl(azx_dev, SD_LPIB);
2443 } else
2444 chip->position_fix[stream] = POS_FIX_POSBUF;
2445 }
2446 break;
2447 }
2448
2449 if (pos >= azx_dev->bufsize)
2450 pos = 0;
2451
2452 /* calculate runtime delay from LPIB */
2453 if (substream->runtime &&
2454 chip->position_fix[stream] == POS_FIX_POSBUF &&
2455 (chip->driver_caps & AZX_DCAPS_COUNT_LPIB_DELAY)) {
2456 unsigned int lpib_pos = azx_sd_readl(azx_dev, SD_LPIB);
2457 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
2458 delay = pos - lpib_pos;
2459 else
2460 delay = lpib_pos - pos;
2461 if (delay < 0) {
2462 if (delay >= azx_dev->delay_negative_threshold)
2463 delay = 0;
2464 else
2465 delay += azx_dev->bufsize;
2466 }
2467 if (delay >= azx_dev->period_bytes) {
2468 snd_printk(KERN_WARNING SFX
2469 "%s: Unstable LPIB (%d >= %d); "
2470 "disabling LPIB delay counting\n",
2471 pci_name(chip->pci), delay, azx_dev->period_bytes);
2472 delay = 0;
2473 chip->driver_caps &= ~AZX_DCAPS_COUNT_LPIB_DELAY;
2474 }
2475 delay = bytes_to_frames(substream->runtime, delay);
2476 }
2477
2478 if (substream->runtime) {
2479 if (hinfo->ops.get_delay)
2480 delay += hinfo->ops.get_delay(hinfo, apcm->codec,
2481 substream);
2482 substream->runtime->delay = delay;
2483 }
2484
2485 trace_azx_get_position(chip, azx_dev, pos, delay);
2486 return pos;
2487}
2488
2489static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
2490{
2491 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2492 struct azx *chip = apcm->chip;
2493 struct azx_dev *azx_dev = get_azx_dev(substream);
2494 return bytes_to_frames(substream->runtime,
2495 azx_get_position(chip, azx_dev, false));
2496}
2497
2498/* 431/*
2499 * Check whether the current DMA position is acceptable for updating 432 * Check whether the current DMA position is acceptable for updating
2500 * periods. Returns non-zero if it's OK. 433 * periods. Returns non-zero if it's OK.
@@ -2521,7 +454,7 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
2521 if (wallclk < (azx_dev->period_wallclk * 5) / 4 && 454 if (wallclk < (azx_dev->period_wallclk * 5) / 4 &&
2522 pos % azx_dev->period_bytes > azx_dev->period_bytes / 2) 455 pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
2523 /* NG - it's below the first next period boundary */ 456 /* NG - it's below the first next period boundary */
2524 return bdl_pos_adj[chip->dev_index] ? 0 : -1; 457 return chip->bdl_pos_adj[chip->dev_index] ? 0 : -1;
2525 azx_dev->start_wallclk += wallclk; 458 azx_dev->start_wallclk += wallclk;
2526 return 1; /* OK, it's fine */ 459 return 1; /* OK, it's fine */
2527} 460}
@@ -2535,10 +468,9 @@ static void azx_irq_pending_work(struct work_struct *work)
2535 int i, pending, ok; 468 int i, pending, ok;
2536 469
2537 if (!chip->irq_pending_warned) { 470 if (!chip->irq_pending_warned) {
2538 printk(KERN_WARNING 471 dev_info(chip->card->dev,
2539 "hda-intel: IRQ timing workaround is activated " 472 "IRQ timing workaround is activated for card #%d. Suggest a bigger bdl_pos_adj.\n",
2540 "for card #%d. Suggest a bigger bdl_pos_adj.\n", 473 chip->card->number);
2541 chip->card->number);
2542 chip->irq_pending_warned = 1; 474 chip->irq_pending_warned = 1;
2543 } 475 }
2544 476
@@ -2580,139 +512,14 @@ static void azx_clear_irq_pending(struct azx *chip)
2580 spin_unlock_irq(&chip->reg_lock); 512 spin_unlock_irq(&chip->reg_lock);
2581} 513}
2582 514
2583#ifdef CONFIG_X86
2584static int azx_pcm_mmap(struct snd_pcm_substream *substream,
2585 struct vm_area_struct *area)
2586{
2587 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2588 struct azx *chip = apcm->chip;
2589 if (!azx_snoop(chip))
2590 area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
2591 return snd_pcm_lib_default_mmap(substream, area);
2592}
2593#else
2594#define azx_pcm_mmap NULL
2595#endif
2596
2597static struct snd_pcm_ops azx_pcm_ops = {
2598 .open = azx_pcm_open,
2599 .close = azx_pcm_close,
2600 .ioctl = snd_pcm_lib_ioctl,
2601 .hw_params = azx_pcm_hw_params,
2602 .hw_free = azx_pcm_hw_free,
2603 .prepare = azx_pcm_prepare,
2604 .trigger = azx_pcm_trigger,
2605 .pointer = azx_pcm_pointer,
2606 .wall_clock = azx_get_wallclock_tstamp,
2607 .mmap = azx_pcm_mmap,
2608 .page = snd_pcm_sgbuf_ops_page,
2609};
2610
2611static void azx_pcm_free(struct snd_pcm *pcm)
2612{
2613 struct azx_pcm *apcm = pcm->private_data;
2614 if (apcm) {
2615 list_del(&apcm->list);
2616 kfree(apcm);
2617 }
2618}
2619
2620#define MAX_PREALLOC_SIZE (32 * 1024 * 1024)
2621
2622static int
2623azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
2624 struct hda_pcm *cpcm)
2625{
2626 struct azx *chip = bus->private_data;
2627 struct snd_pcm *pcm;
2628 struct azx_pcm *apcm;
2629 int pcm_dev = cpcm->device;
2630 unsigned int size;
2631 int s, err;
2632
2633 list_for_each_entry(apcm, &chip->pcm_list, list) {
2634 if (apcm->pcm->device == pcm_dev) {
2635 snd_printk(KERN_ERR SFX "%s: PCM %d already exists\n",
2636 pci_name(chip->pci), pcm_dev);
2637 return -EBUSY;
2638 }
2639 }
2640 err = snd_pcm_new(chip->card, cpcm->name, pcm_dev,
2641 cpcm->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams,
2642 cpcm->stream[SNDRV_PCM_STREAM_CAPTURE].substreams,
2643 &pcm);
2644 if (err < 0)
2645 return err;
2646 strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
2647 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
2648 if (apcm == NULL)
2649 return -ENOMEM;
2650 apcm->chip = chip;
2651 apcm->pcm = pcm;
2652 apcm->codec = codec;
2653 pcm->private_data = apcm;
2654 pcm->private_free = azx_pcm_free;
2655 if (cpcm->pcm_type == HDA_PCM_TYPE_MODEM)
2656 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
2657 list_add_tail(&apcm->list, &chip->pcm_list);
2658 cpcm->pcm = pcm;
2659 for (s = 0; s < 2; s++) {
2660 apcm->hinfo[s] = &cpcm->stream[s];
2661 if (cpcm->stream[s].substreams)
2662 snd_pcm_set_ops(pcm, s, &azx_pcm_ops);
2663 }
2664 /* buffer pre-allocation */
2665 size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024;
2666 if (size > MAX_PREALLOC_SIZE)
2667 size = MAX_PREALLOC_SIZE;
2668 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
2669 snd_dma_pci_data(chip->pci),
2670 size, MAX_PREALLOC_SIZE);
2671 return 0;
2672}
2673
2674/*
2675 * mixer creation - all stuff is implemented in hda module
2676 */
2677static int azx_mixer_create(struct azx *chip)
2678{
2679 return snd_hda_build_controls(chip->bus);
2680}
2681
2682
2683/*
2684 * initialize SD streams
2685 */
2686static int azx_init_stream(struct azx *chip)
2687{
2688 int i;
2689
2690 /* initialize each stream (aka device)
2691 * assign the starting bdl address to each stream (device)
2692 * and initialize
2693 */
2694 for (i = 0; i < chip->num_streams; i++) {
2695 struct azx_dev *azx_dev = &chip->azx_dev[i];
2696 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
2697 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
2698 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
2699 /* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
2700 azx_dev->sd_int_sta_mask = 1 << i;
2701 /* stream tag: must be non-zero and unique */
2702 azx_dev->index = i;
2703 azx_dev->stream_tag = i + 1;
2704 }
2705
2706 return 0;
2707}
2708
2709static int azx_acquire_irq(struct azx *chip, int do_disconnect) 515static int azx_acquire_irq(struct azx *chip, int do_disconnect)
2710{ 516{
2711 if (request_irq(chip->pci->irq, azx_interrupt, 517 if (request_irq(chip->pci->irq, azx_interrupt,
2712 chip->msi ? 0 : IRQF_SHARED, 518 chip->msi ? 0 : IRQF_SHARED,
2713 KBUILD_MODNAME, chip)) { 519 KBUILD_MODNAME, chip)) {
2714 printk(KERN_ERR "hda-intel: unable to grab IRQ %d, " 520 dev_err(chip->card->dev,
2715 "disabling device\n", chip->pci->irq); 521 "unable to grab IRQ %d, disabling device\n",
522 chip->pci->irq);
2716 if (do_disconnect) 523 if (do_disconnect)
2717 snd_card_disconnect(chip->card); 524 snd_card_disconnect(chip->card);
2718 return -1; 525 return -1;
@@ -2722,160 +529,7 @@ static int azx_acquire_irq(struct azx *chip, int do_disconnect)
2722 return 0; 529 return 0;
2723} 530}
2724 531
2725
2726static void azx_stop_chip(struct azx *chip)
2727{
2728 if (!chip->initialized)
2729 return;
2730
2731 /* disable interrupts */
2732 azx_int_disable(chip);
2733 azx_int_clear(chip);
2734
2735 /* disable CORB/RIRB */
2736 azx_free_cmd_io(chip);
2737
2738 /* disable position buffer */
2739 azx_writel(chip, DPLBASE, 0);
2740 azx_writel(chip, DPUBASE, 0);
2741
2742 chip->initialized = 0;
2743}
2744
2745#ifdef CONFIG_SND_HDA_DSP_LOADER
2746/*
2747 * DSP loading code (e.g. for CA0132)
2748 */
2749
2750/* use the first stream for loading DSP */
2751static struct azx_dev *
2752azx_get_dsp_loader_dev(struct azx *chip)
2753{
2754 return &chip->azx_dev[chip->playback_index_offset];
2755}
2756
2757static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
2758 unsigned int byte_size,
2759 struct snd_dma_buffer *bufp)
2760{
2761 u32 *bdl;
2762 struct azx *chip = bus->private_data;
2763 struct azx_dev *azx_dev;
2764 int err;
2765
2766 azx_dev = azx_get_dsp_loader_dev(chip);
2767
2768 dsp_lock(azx_dev);
2769 spin_lock_irq(&chip->reg_lock);
2770 if (azx_dev->running || azx_dev->locked) {
2771 spin_unlock_irq(&chip->reg_lock);
2772 err = -EBUSY;
2773 goto unlock;
2774 }
2775 azx_dev->prepared = 0;
2776 chip->saved_azx_dev = *azx_dev;
2777 azx_dev->locked = 1;
2778 spin_unlock_irq(&chip->reg_lock);
2779
2780 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG,
2781 snd_dma_pci_data(chip->pci),
2782 byte_size, bufp);
2783 if (err < 0)
2784 goto err_alloc;
2785
2786 mark_pages_wc(chip, bufp, true);
2787 azx_dev->bufsize = byte_size;
2788 azx_dev->period_bytes = byte_size;
2789 azx_dev->format_val = format;
2790
2791 azx_stream_reset(chip, azx_dev);
2792
2793 /* reset BDL address */
2794 azx_sd_writel(azx_dev, SD_BDLPL, 0);
2795 azx_sd_writel(azx_dev, SD_BDLPU, 0);
2796
2797 azx_dev->frags = 0;
2798 bdl = (u32 *)azx_dev->bdl.area;
2799 err = setup_bdle(chip, bufp, azx_dev, &bdl, 0, byte_size, 0);
2800 if (err < 0)
2801 goto error;
2802
2803 azx_setup_controller(chip, azx_dev);
2804 dsp_unlock(azx_dev);
2805 return azx_dev->stream_tag;
2806
2807 error:
2808 mark_pages_wc(chip, bufp, false);
2809 snd_dma_free_pages(bufp);
2810 err_alloc:
2811 spin_lock_irq(&chip->reg_lock);
2812 if (azx_dev->opened)
2813 *azx_dev = chip->saved_azx_dev;
2814 azx_dev->locked = 0;
2815 spin_unlock_irq(&chip->reg_lock);
2816 unlock:
2817 dsp_unlock(azx_dev);
2818 return err;
2819}
2820
2821static void azx_load_dsp_trigger(struct hda_bus *bus, bool start)
2822{
2823 struct azx *chip = bus->private_data;
2824 struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
2825
2826 if (start)
2827 azx_stream_start(chip, azx_dev);
2828 else
2829 azx_stream_stop(chip, azx_dev);
2830 azx_dev->running = start;
2831}
2832
2833static void azx_load_dsp_cleanup(struct hda_bus *bus,
2834 struct snd_dma_buffer *dmab)
2835{
2836 struct azx *chip = bus->private_data;
2837 struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
2838
2839 if (!dmab->area || !azx_dev->locked)
2840 return;
2841
2842 dsp_lock(azx_dev);
2843 /* reset BDL address */
2844 azx_sd_writel(azx_dev, SD_BDLPL, 0);
2845 azx_sd_writel(azx_dev, SD_BDLPU, 0);
2846 azx_sd_writel(azx_dev, SD_CTL, 0);
2847 azx_dev->bufsize = 0;
2848 azx_dev->period_bytes = 0;
2849 azx_dev->format_val = 0;
2850
2851 mark_pages_wc(chip, dmab, false);
2852 snd_dma_free_pages(dmab);
2853 dmab->area = NULL;
2854
2855 spin_lock_irq(&chip->reg_lock);
2856 if (azx_dev->opened)
2857 *azx_dev = chip->saved_azx_dev;
2858 azx_dev->locked = 0;
2859 spin_unlock_irq(&chip->reg_lock);
2860 dsp_unlock(azx_dev);
2861}
2862#endif /* CONFIG_SND_HDA_DSP_LOADER */
2863
2864#ifdef CONFIG_PM 532#ifdef CONFIG_PM
2865/* power-up/down the controller */
2866static void azx_power_notify(struct hda_bus *bus, bool power_up)
2867{
2868 struct azx *chip = bus->private_data;
2869
2870 if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
2871 return;
2872
2873 if (power_up)
2874 pm_runtime_get_sync(&chip->pci->dev);
2875 else
2876 pm_runtime_put_sync(&chip->pci->dev);
2877}
2878
2879static DEFINE_MUTEX(card_list_lock); 533static DEFINE_MUTEX(card_list_lock);
2880static LIST_HEAD(card_list); 534static LIST_HEAD(card_list);
2881 535
@@ -2969,8 +623,8 @@ static int azx_resume(struct device *dev)
2969 pci_set_power_state(pci, PCI_D0); 623 pci_set_power_state(pci, PCI_D0);
2970 pci_restore_state(pci); 624 pci_restore_state(pci);
2971 if (pci_enable_device(pci) < 0) { 625 if (pci_enable_device(pci) < 0) {
2972 printk(KERN_ERR "hda-intel: pci_enable_device failed, " 626 dev_err(chip->card->dev,
2973 "disabling device\n"); 627 "pci_enable_device failed, disabling device\n");
2974 snd_card_disconnect(card); 628 snd_card_disconnect(card);
2975 return -EIO; 629 return -EIO;
2976 } 630 }
@@ -3127,36 +781,32 @@ static void azx_vs_set_state(struct pci_dev *pci,
3127 if (!chip->bus) { 781 if (!chip->bus) {
3128 chip->disabled = disabled; 782 chip->disabled = disabled;
3129 if (!disabled) { 783 if (!disabled) {
3130 snd_printk(KERN_INFO SFX 784 dev_info(chip->card->dev,
3131 "%s: Start delayed initialization\n", 785 "Start delayed initialization\n");
3132 pci_name(chip->pci));
3133 if (azx_probe_continue(chip) < 0) { 786 if (azx_probe_continue(chip) < 0) {
3134 snd_printk(KERN_ERR SFX 787 dev_err(chip->card->dev, "initialization error\n");
3135 "%s: initialization error\n",
3136 pci_name(chip->pci));
3137 chip->init_failed = true; 788 chip->init_failed = true;
3138 } 789 }
3139 } 790 }
3140 } else { 791 } else {
3141 snd_printk(KERN_INFO SFX 792 dev_info(chip->card->dev, "%s via VGA-switcheroo\n",
3142 "%s: %s via VGA-switcheroo\n", pci_name(chip->pci), 793 disabled ? "Disabling" : "Enabling");
3143 disabled ? "Disabling" : "Enabling");
3144 if (disabled) { 794 if (disabled) {
3145 pm_runtime_put_sync_suspend(&pci->dev); 795 pm_runtime_put_sync_suspend(card->dev);
3146 azx_suspend(&pci->dev); 796 azx_suspend(card->dev);
3147 /* when we get suspended by vga switcheroo we end up in D3cold, 797 /* when we get suspended by vga switcheroo we end up in D3cold,
3148 * however we have no ACPI handle, so pci/acpi can't put us there, 798 * however we have no ACPI handle, so pci/acpi can't put us there,
3149 * put ourselves there */ 799 * put ourselves there */
3150 pci->current_state = PCI_D3cold; 800 pci->current_state = PCI_D3cold;
3151 chip->disabled = true; 801 chip->disabled = true;
3152 if (snd_hda_lock_devices(chip->bus)) 802 if (snd_hda_lock_devices(chip->bus))
3153 snd_printk(KERN_WARNING SFX "%s: Cannot lock devices!\n", 803 dev_warn(chip->card->dev,
3154 pci_name(chip->pci)); 804 "Cannot lock devices!\n");
3155 } else { 805 } else {
3156 snd_hda_unlock_devices(chip->bus); 806 snd_hda_unlock_devices(chip->bus);
3157 pm_runtime_get_noresume(&pci->dev); 807 pm_runtime_get_noresume(card->dev);
3158 chip->disabled = false; 808 chip->disabled = false;
3159 azx_resume(&pci->dev); 809 azx_resume(card->dev);
3160 } 810 }
3161 } 811 }
3162} 812}
@@ -3181,9 +831,8 @@ static void init_vga_switcheroo(struct azx *chip)
3181{ 831{
3182 struct pci_dev *p = get_bound_vga(chip->pci); 832 struct pci_dev *p = get_bound_vga(chip->pci);
3183 if (p) { 833 if (p) {
3184 snd_printk(KERN_INFO SFX 834 dev_info(chip->card->dev,
3185 "%s: Handle VGA-switcheroo audio client\n", 835 "Handle VGA-switcheroo audio client\n");
3186 pci_name(chip->pci));
3187 chip->use_vga_switcheroo = 1; 836 chip->use_vga_switcheroo = 1;
3188 pci_dev_put(p); 837 pci_dev_put(p);
3189 } 838 }
@@ -3211,7 +860,8 @@ static int register_vga_switcheroo(struct azx *chip)
3211 chip->vga_switcheroo_registered = 1; 860 chip->vga_switcheroo_registered = 1;
3212 861
3213 /* register as an optimus hdmi audio power domain */ 862 /* register as an optimus hdmi audio power domain */
3214 vga_switcheroo_init_domain_pm_optimus_hdmi_audio(&chip->pci->dev, &chip->hdmi_pm_domain); 863 vga_switcheroo_init_domain_pm_optimus_hdmi_audio(chip->card->dev,
864 &chip->hdmi_pm_domain);
3215 return 0; 865 return 0;
3216} 866}
3217#else 867#else
@@ -3260,21 +910,7 @@ static int azx_free(struct azx *chip)
3260 if (chip->remap_addr) 910 if (chip->remap_addr)
3261 iounmap(chip->remap_addr); 911 iounmap(chip->remap_addr);
3262 912
3263 if (chip->azx_dev) { 913 azx_free_stream_pages(chip);
3264 for (i = 0; i < chip->num_streams; i++)
3265 if (chip->azx_dev[i].bdl.area) {
3266 mark_pages_wc(chip, &chip->azx_dev[i].bdl, false);
3267 snd_dma_free_pages(&chip->azx_dev[i].bdl);
3268 }
3269 }
3270 if (chip->rb.area) {
3271 mark_pages_wc(chip, &chip->rb, false);
3272 snd_dma_free_pages(&chip->rb);
3273 }
3274 if (chip->posbuf.area) {
3275 mark_pages_wc(chip, &chip->posbuf, false);
3276 snd_dma_free_pages(&chip->posbuf);
3277 }
3278 if (chip->region_requested) 914 if (chip->region_requested)
3279 pci_release_regions(chip->pci); 915 pci_release_regions(chip->pci);
3280 pci_disable_device(chip->pci); 916 pci_disable_device(chip->pci);
@@ -3374,20 +1010,19 @@ static int check_position_fix(struct azx *chip, int fix)
3374 1010
3375 q = snd_pci_quirk_lookup(chip->pci, position_fix_list); 1011 q = snd_pci_quirk_lookup(chip->pci, position_fix_list);
3376 if (q) { 1012 if (q) {
3377 printk(KERN_INFO 1013 dev_info(chip->card->dev,
3378 "hda_intel: position_fix set to %d " 1014 "position_fix set to %d for device %04x:%04x\n",
3379 "for device %04x:%04x\n", 1015 q->value, q->subvendor, q->subdevice);
3380 q->value, q->subvendor, q->subdevice);
3381 return q->value; 1016 return q->value;
3382 } 1017 }
3383 1018
3384 /* Check VIA/ATI HD Audio Controller exist */ 1019 /* Check VIA/ATI HD Audio Controller exist */
3385 if (chip->driver_caps & AZX_DCAPS_POSFIX_VIA) { 1020 if (chip->driver_caps & AZX_DCAPS_POSFIX_VIA) {
3386 snd_printd(SFX "%s: Using VIACOMBO position fix\n", pci_name(chip->pci)); 1021 dev_dbg(chip->card->dev, "Using VIACOMBO position fix\n");
3387 return POS_FIX_VIACOMBO; 1022 return POS_FIX_VIACOMBO;
3388 } 1023 }
3389 if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) { 1024 if (chip->driver_caps & AZX_DCAPS_POSFIX_LPIB) {
3390 snd_printd(SFX "%s: Using LPIB position fix\n", pci_name(chip->pci)); 1025 dev_dbg(chip->card->dev, "Using LPIB position fix\n");
3391 return POS_FIX_LPIB; 1026 return POS_FIX_LPIB;
3392 } 1027 }
3393 return POS_FIX_AUTO; 1028 return POS_FIX_AUTO;
@@ -3425,10 +1060,9 @@ static void check_probe_mask(struct azx *chip, int dev)
3425 if (chip->codec_probe_mask == -1) { 1060 if (chip->codec_probe_mask == -1) {
3426 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list); 1061 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
3427 if (q) { 1062 if (q) {
3428 printk(KERN_INFO 1063 dev_info(chip->card->dev,
3429 "hda_intel: probe_mask set to 0x%x " 1064 "probe_mask set to 0x%x for device %04x:%04x\n",
3430 "for device %04x:%04x\n", 1065 q->value, q->subvendor, q->subdevice);
3431 q->value, q->subvendor, q->subdevice);
3432 chip->codec_probe_mask = q->value; 1066 chip->codec_probe_mask = q->value;
3433 } 1067 }
3434 } 1068 }
@@ -3437,8 +1071,8 @@ static void check_probe_mask(struct azx *chip, int dev)
3437 if (chip->codec_probe_mask != -1 && 1071 if (chip->codec_probe_mask != -1 &&
3438 (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) { 1072 (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
3439 chip->codec_mask = chip->codec_probe_mask & 0xff; 1073 chip->codec_mask = chip->codec_probe_mask & 0xff;
3440 printk(KERN_INFO "hda_intel: codec_mask forced to 0x%x\n", 1074 dev_info(chip->card->dev, "codec_mask forced to 0x%x\n",
3441 chip->codec_mask); 1075 chip->codec_mask);
3442 } 1076 }
3443} 1077}
3444 1078
@@ -3470,16 +1104,16 @@ static void check_msi(struct azx *chip)
3470 chip->msi = 1; /* enable MSI as default */ 1104 chip->msi = 1; /* enable MSI as default */
3471 q = snd_pci_quirk_lookup(chip->pci, msi_black_list); 1105 q = snd_pci_quirk_lookup(chip->pci, msi_black_list);
3472 if (q) { 1106 if (q) {
3473 printk(KERN_INFO 1107 dev_info(chip->card->dev,
3474 "hda_intel: msi for device %04x:%04x set to %d\n", 1108 "msi for device %04x:%04x set to %d\n",
3475 q->subvendor, q->subdevice, q->value); 1109 q->subvendor, q->subdevice, q->value);
3476 chip->msi = q->value; 1110 chip->msi = q->value;
3477 return; 1111 return;
3478 } 1112 }
3479 1113
3480 /* NVidia chipsets seem to cause troubles with MSI */ 1114 /* NVidia chipsets seem to cause troubles with MSI */
3481 if (chip->driver_caps & AZX_DCAPS_NO_MSI) { 1115 if (chip->driver_caps & AZX_DCAPS_NO_MSI) {
3482 printk(KERN_INFO "hda_intel: Disabling MSI\n"); 1116 dev_info(chip->card->dev, "Disabling MSI\n");
3483 chip->msi = 0; 1117 chip->msi = 0;
3484 } 1118 }
3485} 1119}
@@ -3511,8 +1145,8 @@ static void azx_check_snoop_available(struct azx *chip)
3511 } 1145 }
3512 1146
3513 if (snoop != chip->snoop) { 1147 if (snoop != chip->snoop) {
3514 snd_printk(KERN_INFO SFX "%s: Force to %s mode\n", 1148 dev_info(chip->card->dev, "Force to %s mode\n",
3515 pci_name(chip->pci), snoop ? "snoop" : "non-snoop"); 1149 snoop ? "snoop" : "non-snoop");
3516 chip->snoop = snoop; 1150 chip->snoop = snoop;
3517 } 1151 }
3518} 1152}
@@ -3527,6 +1161,7 @@ static void azx_probe_work(struct work_struct *work)
3527 */ 1161 */
3528static int azx_create(struct snd_card *card, struct pci_dev *pci, 1162static int azx_create(struct snd_card *card, struct pci_dev *pci,
3529 int dev, unsigned int driver_caps, 1163 int dev, unsigned int driver_caps,
1164 const struct hda_controller_ops *hda_ops,
3530 struct azx **rchip) 1165 struct azx **rchip)
3531{ 1166{
3532 static struct snd_device_ops ops = { 1167 static struct snd_device_ops ops = {
@@ -3543,7 +1178,7 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
3543 1178
3544 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1179 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
3545 if (!chip) { 1180 if (!chip) {
3546 snd_printk(KERN_ERR SFX "%s: Cannot allocate chip\n", pci_name(pci)); 1181 dev_err(card->dev, "Cannot allocate chip\n");
3547 pci_disable_device(pci); 1182 pci_disable_device(pci);
3548 return -ENOMEM; 1183 return -ENOMEM;
3549 } 1184 }
@@ -3552,11 +1187,13 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
3552 mutex_init(&chip->open_mutex); 1187 mutex_init(&chip->open_mutex);
3553 chip->card = card; 1188 chip->card = card;
3554 chip->pci = pci; 1189 chip->pci = pci;
1190 chip->ops = hda_ops;
3555 chip->irq = -1; 1191 chip->irq = -1;
3556 chip->driver_caps = driver_caps; 1192 chip->driver_caps = driver_caps;
3557 chip->driver_type = driver_caps & 0xff; 1193 chip->driver_type = driver_caps & 0xff;
3558 check_msi(chip); 1194 check_msi(chip);
3559 chip->dev_index = dev; 1195 chip->dev_index = dev;
1196 chip->jackpoll_ms = jackpoll_ms;
3560 INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work); 1197 INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
3561 INIT_LIST_HEAD(&chip->pcm_list); 1198 INIT_LIST_HEAD(&chip->pcm_list);
3562 INIT_LIST_HEAD(&chip->list); 1199 INIT_LIST_HEAD(&chip->list);
@@ -3588,11 +1225,11 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
3588 break; 1225 break;
3589 } 1226 }
3590 } 1227 }
1228 chip->bdl_pos_adj = bdl_pos_adj;
3591 1229
3592 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 1230 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
3593 if (err < 0) { 1231 if (err < 0) {
3594 snd_printk(KERN_ERR SFX "%s: Error creating device [card]!\n", 1232 dev_err(card->dev, "Error creating device [card]!\n");
3595 pci_name(chip->pci));
3596 azx_free(chip); 1233 azx_free(chip);
3597 return err; 1234 return err;
3598 } 1235 }
@@ -3610,7 +1247,7 @@ static int azx_first_init(struct azx *chip)
3610 int dev = chip->dev_index; 1247 int dev = chip->dev_index;
3611 struct pci_dev *pci = chip->pci; 1248 struct pci_dev *pci = chip->pci;
3612 struct snd_card *card = chip->card; 1249 struct snd_card *card = chip->card;
3613 int i, err; 1250 int err;
3614 unsigned short gcap; 1251 unsigned short gcap;
3615 1252
3616#if BITS_PER_LONG != 64 1253#if BITS_PER_LONG != 64
@@ -3631,7 +1268,7 @@ static int azx_first_init(struct azx *chip)
3631 chip->addr = pci_resource_start(pci, 0); 1268 chip->addr = pci_resource_start(pci, 0);
3632 chip->remap_addr = pci_ioremap_bar(pci, 0); 1269 chip->remap_addr = pci_ioremap_bar(pci, 0);
3633 if (chip->remap_addr == NULL) { 1270 if (chip->remap_addr == NULL) {
3634 snd_printk(KERN_ERR SFX "%s: ioremap error\n", pci_name(chip->pci)); 1271 dev_err(card->dev, "ioremap error\n");
3635 return -ENXIO; 1272 return -ENXIO;
3636 } 1273 }
3637 1274
@@ -3646,7 +1283,7 @@ static int azx_first_init(struct azx *chip)
3646 synchronize_irq(chip->irq); 1283 synchronize_irq(chip->irq);
3647 1284
3648 gcap = azx_readw(chip, GCAP); 1285 gcap = azx_readw(chip, GCAP);
3649 snd_printdd(SFX "%s: chipset global capabilities = 0x%x\n", pci_name(chip->pci), gcap); 1286 dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);
3650 1287
3651 /* disable SB600 64bit support for safety */ 1288 /* disable SB600 64bit support for safety */
3652 if (chip->pci->vendor == PCI_VENDOR_ID_ATI) { 1289 if (chip->pci->vendor == PCI_VENDOR_ID_ATI) {
@@ -3663,7 +1300,7 @@ static int azx_first_init(struct azx *chip)
3663 1300
3664 /* disable 64bit DMA address on some devices */ 1301 /* disable 64bit DMA address on some devices */
3665 if (chip->driver_caps & AZX_DCAPS_NO_64BIT) { 1302 if (chip->driver_caps & AZX_DCAPS_NO_64BIT) {
3666 snd_printd(SFX "%s: Disabling 64bit DMA\n", pci_name(chip->pci)); 1303 dev_dbg(card->dev, "Disabling 64bit DMA\n");
3667 gcap &= ~ICH6_GCAP_64OK; 1304 gcap &= ~ICH6_GCAP_64OK;
3668 } 1305 }
3669 1306
@@ -3718,33 +1355,11 @@ static int azx_first_init(struct azx *chip)
3718 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), 1355 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
3719 GFP_KERNEL); 1356 GFP_KERNEL);
3720 if (!chip->azx_dev) { 1357 if (!chip->azx_dev) {
3721 snd_printk(KERN_ERR SFX "%s: cannot malloc azx_dev\n", pci_name(chip->pci)); 1358 dev_err(card->dev, "cannot malloc azx_dev\n");
3722 return -ENOMEM; 1359 return -ENOMEM;
3723 } 1360 }
3724 1361
3725 for (i = 0; i < chip->num_streams; i++) { 1362 err = azx_alloc_stream_pages(chip);
3726 dsp_lock_init(&chip->azx_dev[i]);
3727 /* allocate memory for the BDL for each stream */
3728 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
3729 snd_dma_pci_data(chip->pci),
3730 BDL_SIZE, &chip->azx_dev[i].bdl);
3731 if (err < 0) {
3732 snd_printk(KERN_ERR SFX "%s: cannot allocate BDL\n", pci_name(chip->pci));
3733 return -ENOMEM;
3734 }
3735 mark_pages_wc(chip, &chip->azx_dev[i].bdl, true);
3736 }
3737 /* allocate memory for the position buffer */
3738 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
3739 snd_dma_pci_data(chip->pci),
3740 chip->num_streams * 8, &chip->posbuf);
3741 if (err < 0) {
3742 snd_printk(KERN_ERR SFX "%s: cannot allocate posbuf\n", pci_name(chip->pci));
3743 return -ENOMEM;
3744 }
3745 mark_pages_wc(chip, &chip->posbuf, true);
3746 /* allocate CORB/RIRB */
3747 err = azx_alloc_cmd_io(chip);
3748 if (err < 0) 1363 if (err < 0)
3749 return err; 1364 return err;
3750 1365
@@ -3757,7 +1372,7 @@ static int azx_first_init(struct azx *chip)
3757 1372
3758 /* codec detection */ 1373 /* codec detection */
3759 if (!chip->codec_mask) { 1374 if (!chip->codec_mask) {
3760 snd_printk(KERN_ERR SFX "%s: no codecs found!\n", pci_name(chip->pci)); 1375 dev_err(card->dev, "no codecs found!\n");
3761 return -ENODEV; 1376 return -ENODEV;
3762 } 1377 }
3763 1378
@@ -3793,8 +1408,7 @@ static void azx_firmware_cb(const struct firmware *fw, void *context)
3793 struct pci_dev *pci = chip->pci; 1408 struct pci_dev *pci = chip->pci;
3794 1409
3795 if (!fw) { 1410 if (!fw) {
3796 snd_printk(KERN_ERR SFX "%s: Cannot load firmware, aborting\n", 1411 dev_err(card->dev, "Cannot load firmware, aborting\n");
3797 pci_name(chip->pci));
3798 goto error; 1412 goto error;
3799 } 1413 }
3800 1414
@@ -3812,6 +1426,132 @@ static void azx_firmware_cb(const struct firmware *fw, void *context)
3812} 1426}
3813#endif 1427#endif
3814 1428
1429/*
1430 * HDA controller ops.
1431 */
1432
1433/* PCI register access. */
1434static void pci_azx_writel(u32 value, u32 __iomem *addr)
1435{
1436 writel(value, addr);
1437}
1438
1439static u32 pci_azx_readl(u32 __iomem *addr)
1440{
1441 return readl(addr);
1442}
1443
1444static void pci_azx_writew(u16 value, u16 __iomem *addr)
1445{
1446 writew(value, addr);
1447}
1448
1449static u16 pci_azx_readw(u16 __iomem *addr)
1450{
1451 return readw(addr);
1452}
1453
1454static void pci_azx_writeb(u8 value, u8 __iomem *addr)
1455{
1456 writeb(value, addr);
1457}
1458
1459static u8 pci_azx_readb(u8 __iomem *addr)
1460{
1461 return readb(addr);
1462}
1463
1464static int disable_msi_reset_irq(struct azx *chip)
1465{
1466 int err;
1467
1468 free_irq(chip->irq, chip);
1469 chip->irq = -1;
1470 pci_disable_msi(chip->pci);
1471 chip->msi = 0;
1472 err = azx_acquire_irq(chip, 1);
1473 if (err < 0)
1474 return err;
1475
1476 return 0;
1477}
1478
1479/* DMA page allocation helpers. */
1480static int dma_alloc_pages(struct azx *chip,
1481 int type,
1482 size_t size,
1483 struct snd_dma_buffer *buf)
1484{
1485 int err;
1486
1487 err = snd_dma_alloc_pages(type,
1488 chip->card->dev,
1489 size, buf);
1490 if (err < 0)
1491 return err;
1492 mark_pages_wc(chip, buf, true);
1493 return 0;
1494}
1495
1496static void dma_free_pages(struct azx *chip, struct snd_dma_buffer *buf)
1497{
1498 mark_pages_wc(chip, buf, false);
1499 snd_dma_free_pages(buf);
1500}
1501
1502static int substream_alloc_pages(struct azx *chip,
1503 struct snd_pcm_substream *substream,
1504 size_t size)
1505{
1506 struct azx_dev *azx_dev = get_azx_dev(substream);
1507 int ret;
1508
1509 mark_runtime_wc(chip, azx_dev, substream, false);
1510 azx_dev->bufsize = 0;
1511 azx_dev->period_bytes = 0;
1512 azx_dev->format_val = 0;
1513 ret = snd_pcm_lib_malloc_pages(substream, size);
1514 if (ret < 0)
1515 return ret;
1516 mark_runtime_wc(chip, azx_dev, substream, true);
1517 return 0;
1518}
1519
1520static int substream_free_pages(struct azx *chip,
1521 struct snd_pcm_substream *substream)
1522{
1523 struct azx_dev *azx_dev = get_azx_dev(substream);
1524 mark_runtime_wc(chip, azx_dev, substream, false);
1525 return snd_pcm_lib_free_pages(substream);
1526}
1527
1528static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
1529 struct vm_area_struct *area)
1530{
1531#ifdef CONFIG_X86
1532 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1533 struct azx *chip = apcm->chip;
1534 if (!azx_snoop(chip))
1535 area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
1536#endif
1537}
1538
1539static const struct hda_controller_ops pci_hda_ops = {
1540 .reg_writel = pci_azx_writel,
1541 .reg_readl = pci_azx_readl,
1542 .reg_writew = pci_azx_writew,
1543 .reg_readw = pci_azx_readw,
1544 .reg_writeb = pci_azx_writeb,
1545 .reg_readb = pci_azx_readb,
1546 .disable_msi_reset_irq = disable_msi_reset_irq,
1547 .dma_alloc_pages = dma_alloc_pages,
1548 .dma_free_pages = dma_free_pages,
1549 .substream_alloc_pages = substream_alloc_pages,
1550 .substream_free_pages = substream_free_pages,
1551 .pcm_mmap_prepare = pcm_mmap_prepare,
1552 .position_check = azx_position_check,
1553};
1554
3815static int azx_probe(struct pci_dev *pci, 1555static int azx_probe(struct pci_dev *pci,
3816 const struct pci_device_id *pci_id) 1556 const struct pci_device_id *pci_id)
3817{ 1557{
@@ -3828,15 +1568,15 @@ static int azx_probe(struct pci_dev *pci,
3828 return -ENOENT; 1568 return -ENOENT;
3829 } 1569 }
3830 1570
3831 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1571 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1572 0, &card);
3832 if (err < 0) { 1573 if (err < 0) {
3833 snd_printk(KERN_ERR "hda-intel: Error creating card!\n"); 1574 dev_err(&pci->dev, "Error creating card!\n");
3834 return err; 1575 return err;
3835 } 1576 }
3836 1577
3837 snd_card_set_dev(card, &pci->dev); 1578 err = azx_create(card, pci, dev, pci_id->driver_data,
3838 1579 &pci_hda_ops, &chip);
3839 err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
3840 if (err < 0) 1580 if (err < 0)
3841 goto out_free; 1581 goto out_free;
3842 card->private_data = chip; 1582 card->private_data = chip;
@@ -3845,15 +1585,13 @@ static int azx_probe(struct pci_dev *pci,
3845 1585
3846 err = register_vga_switcheroo(chip); 1586 err = register_vga_switcheroo(chip);
3847 if (err < 0) { 1587 if (err < 0) {
3848 snd_printk(KERN_ERR SFX 1588 dev_err(card->dev, "Error registering VGA-switcheroo client\n");
3849 "%s: Error registering VGA-switcheroo client\n", pci_name(pci));
3850 goto out_free; 1589 goto out_free;
3851 } 1590 }
3852 1591
3853 if (check_hdmi_disabled(pci)) { 1592 if (check_hdmi_disabled(pci)) {
3854 snd_printk(KERN_INFO SFX "%s: VGA controller is disabled\n", 1593 dev_info(card->dev, "VGA controller is disabled\n");
3855 pci_name(pci)); 1594 dev_info(card->dev, "Delaying initialization\n");
3856 snd_printk(KERN_INFO SFX "%s: Delaying initialization\n", pci_name(pci));
3857 chip->disabled = true; 1595 chip->disabled = true;
3858 } 1596 }
3859 1597
@@ -3861,8 +1599,8 @@ static int azx_probe(struct pci_dev *pci,
3861 1599
3862#ifdef CONFIG_SND_HDA_PATCH_LOADER 1600#ifdef CONFIG_SND_HDA_PATCH_LOADER
3863 if (patch[dev] && *patch[dev]) { 1601 if (patch[dev] && *patch[dev]) {
3864 snd_printk(KERN_ERR SFX "%s: Applying patch firmware '%s'\n", 1602 dev_info(card->dev, "Applying patch firmware '%s'\n",
3865 pci_name(pci), patch[dev]); 1603 patch[dev]);
3866 err = request_firmware_nowait(THIS_MODULE, true, patch[dev], 1604 err = request_firmware_nowait(THIS_MODULE, true, patch[dev],
3867 &pci->dev, GFP_KERNEL, card, 1605 &pci->dev, GFP_KERNEL, card,
3868 azx_firmware_cb); 1606 azx_firmware_cb);
@@ -3874,7 +1612,7 @@ static int azx_probe(struct pci_dev *pci,
3874 1612
3875#ifndef CONFIG_SND_HDA_I915 1613#ifndef CONFIG_SND_HDA_I915
3876 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) 1614 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
3877 snd_printk(KERN_ERR SFX "Haswell must build in CONFIG_SND_HDA_I915\n"); 1615 dev_err(card->dev, "Haswell must build in CONFIG_SND_HDA_I915\n");
3878#endif 1616#endif
3879 1617
3880 if (schedule_probe) 1618 if (schedule_probe)
@@ -3890,6 +1628,12 @@ out_free:
3890 return err; 1628 return err;
3891} 1629}
3892 1630
1631/* number of codec slots for each chipset: 0 = default slots (i.e. 4) */
1632static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] = {
1633 [AZX_DRIVER_NVIDIA] = 8,
1634 [AZX_DRIVER_TERA] = 1,
1635};
1636
3893static int azx_probe_continue(struct azx *chip) 1637static int azx_probe_continue(struct azx *chip)
3894{ 1638{
3895 struct pci_dev *pci = chip->pci; 1639 struct pci_dev *pci = chip->pci;
@@ -3901,7 +1645,8 @@ static int azx_probe_continue(struct azx *chip)
3901#ifdef CONFIG_SND_HDA_I915 1645#ifdef CONFIG_SND_HDA_I915
3902 err = hda_i915_init(); 1646 err = hda_i915_init();
3903 if (err < 0) { 1647 if (err < 0) {
3904 snd_printk(KERN_ERR SFX "Error request power-well from i915\n"); 1648 dev_err(chip->card->dev,
1649 "Error request power-well from i915\n");
3905 goto out_free; 1650 goto out_free;
3906 } 1651 }
3907#endif 1652#endif
@@ -3917,7 +1662,10 @@ static int azx_probe_continue(struct azx *chip)
3917#endif 1662#endif
3918 1663
3919 /* create codec instances */ 1664 /* create codec instances */
3920 err = azx_codec_create(chip, model[dev]); 1665 err = azx_codec_create(chip, model[dev],
1666 azx_max_codecs[chip->driver_type],
1667 power_save_addr);
1668
3921 if (err < 0) 1669 if (err < 0)
3922 goto out_free; 1670 goto out_free;
3923#ifdef CONFIG_SND_HDA_PATCH_LOADER 1671#ifdef CONFIG_SND_HDA_PATCH_LOADER
@@ -4142,7 +1890,7 @@ static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
4142 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA }, 1890 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
4143 { PCI_DEVICE(0x1102, 0x0012), 1891 { PCI_DEVICE(0x1102, 0x0012),
4144 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA }, 1892 .driver_data = AZX_DRIVER_CTHDA | AZX_DCAPS_PRESET_CTHDA },
4145#if !defined(CONFIG_SND_CTXFI) && !defined(CONFIG_SND_CTXFI_MODULE) 1893#if !IS_ENABLED(CONFIG_SND_CTXFI)
4146 /* the following entry conflicts with snd-ctxfi driver, 1894 /* the following entry conflicts with snd-ctxfi driver,
4147 * as ctxfi driver mutates from HD-audio to native mode with 1895 * as ctxfi driver mutates from HD-audio to native mode with
4148 * a special command sequence. 1896 * a special command sequence.
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index da80c5bd7fd4..e51d15529215 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -597,23 +597,10 @@ int snd_hda_create_hwdep(struct hda_codec *codec);
597static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; } 597static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
598#endif 598#endif
599 599
600#if defined(CONFIG_PM) && defined(CONFIG_SND_HDA_HWDEP) 600void snd_hda_sysfs_init(struct hda_codec *codec);
601int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec); 601void snd_hda_sysfs_clear(struct hda_codec *codec);
602#else
603static inline int snd_hda_hwdep_add_power_sysfs(struct hda_codec *codec)
604{
605 return 0;
606}
607#endif
608 602
609#ifdef CONFIG_SND_HDA_RECONFIG 603extern const struct attribute_group *snd_hda_dev_attr_groups[];
610int snd_hda_hwdep_add_sysfs(struct hda_codec *codec);
611#else
612static inline int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
613{
614 return 0;
615}
616#endif
617 604
618#ifdef CONFIG_SND_HDA_RECONFIG 605#ifdef CONFIG_SND_HDA_RECONFIG
619const char *snd_hda_get_hint(struct hda_codec *codec, const char *key); 606const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
@@ -771,4 +758,11 @@ void snd_hdmi_write_eld_info(struct hdmi_eld *eld,
771#define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80 758#define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
772void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen); 759void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
773 760
761/*
762 */
763#define codec_err(codec, fmt, args...) dev_err(&(codec)->dev, fmt, ##args)
764#define codec_warn(codec, fmt, args...) dev_warn(&(codec)->dev, fmt, ##args)
765#define codec_info(codec, fmt, args...) dev_info(&(codec)->dev, fmt, ##args)
766#define codec_dbg(codec, fmt, args...) dev_dbg(&(codec)->dev, fmt, ##args)
767
774#endif /* __SOUND_HDA_LOCAL_H */ 768#endif /* __SOUND_HDA_LOCAL_H */
diff --git a/sound/pci/hda/hda_priv.h b/sound/pci/hda/hda_priv.h
new file mode 100644
index 000000000000..ba38b819f984
--- /dev/null
+++ b/sound/pci/hda/hda_priv.h
@@ -0,0 +1,463 @@
1/*
2 * Common defines for the alsa driver code base for HD Audio.
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 Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef __SOUND_HDA_PRIV_H
16#define __SOUND_HDA_PRIV_H
17
18#include <linux/clocksource.h>
19#include <sound/core.h>
20#include <sound/pcm.h>
21
22/*
23 * registers
24 */
25#define ICH6_REG_GCAP 0x00
26#define ICH6_GCAP_64OK (1 << 0) /* 64bit address support */
27#define ICH6_GCAP_NSDO (3 << 1) /* # of serial data out signals */
28#define ICH6_GCAP_BSS (31 << 3) /* # of bidirectional streams */
29#define ICH6_GCAP_ISS (15 << 8) /* # of input streams */
30#define ICH6_GCAP_OSS (15 << 12) /* # of output streams */
31#define ICH6_REG_VMIN 0x02
32#define ICH6_REG_VMAJ 0x03
33#define ICH6_REG_OUTPAY 0x04
34#define ICH6_REG_INPAY 0x06
35#define ICH6_REG_GCTL 0x08
36#define ICH6_GCTL_RESET (1 << 0) /* controller reset */
37#define ICH6_GCTL_FCNTRL (1 << 1) /* flush control */
38#define ICH6_GCTL_UNSOL (1 << 8) /* accept unsol. response enable */
39#define ICH6_REG_WAKEEN 0x0c
40#define ICH6_REG_STATESTS 0x0e
41#define ICH6_REG_GSTS 0x10
42#define ICH6_GSTS_FSTS (1 << 1) /* flush status */
43#define ICH6_REG_INTCTL 0x20
44#define ICH6_REG_INTSTS 0x24
45#define ICH6_REG_WALLCLK 0x30 /* 24Mhz source */
46#define ICH6_REG_OLD_SSYNC 0x34 /* SSYNC for old ICH */
47#define ICH6_REG_SSYNC 0x38
48#define ICH6_REG_CORBLBASE 0x40
49#define ICH6_REG_CORBUBASE 0x44
50#define ICH6_REG_CORBWP 0x48
51#define ICH6_REG_CORBRP 0x4a
52#define ICH6_CORBRP_RST (1 << 15) /* read pointer reset */
53#define ICH6_REG_CORBCTL 0x4c
54#define ICH6_CORBCTL_RUN (1 << 1) /* enable DMA */
55#define ICH6_CORBCTL_CMEIE (1 << 0) /* enable memory error irq */
56#define ICH6_REG_CORBSTS 0x4d
57#define ICH6_CORBSTS_CMEI (1 << 0) /* memory error indication */
58#define ICH6_REG_CORBSIZE 0x4e
59
60#define ICH6_REG_RIRBLBASE 0x50
61#define ICH6_REG_RIRBUBASE 0x54
62#define ICH6_REG_RIRBWP 0x58
63#define ICH6_RIRBWP_RST (1 << 15) /* write pointer reset */
64#define ICH6_REG_RINTCNT 0x5a
65#define ICH6_REG_RIRBCTL 0x5c
66#define ICH6_RBCTL_IRQ_EN (1 << 0) /* enable IRQ */
67#define ICH6_RBCTL_DMA_EN (1 << 1) /* enable DMA */
68#define ICH6_RBCTL_OVERRUN_EN (1 << 2) /* enable overrun irq */
69#define ICH6_REG_RIRBSTS 0x5d
70#define ICH6_RBSTS_IRQ (1 << 0) /* response irq */
71#define ICH6_RBSTS_OVERRUN (1 << 2) /* overrun irq */
72#define ICH6_REG_RIRBSIZE 0x5e
73
74#define ICH6_REG_IC 0x60
75#define ICH6_REG_IR 0x64
76#define ICH6_REG_IRS 0x68
77#define ICH6_IRS_VALID (1<<1)
78#define ICH6_IRS_BUSY (1<<0)
79
80#define ICH6_REG_DPLBASE 0x70
81#define ICH6_REG_DPUBASE 0x74
82#define ICH6_DPLBASE_ENABLE 0x1 /* Enable position buffer */
83
84/* SD offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
85enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
86
87/* stream register offsets from stream base */
88#define ICH6_REG_SD_CTL 0x00
89#define ICH6_REG_SD_STS 0x03
90#define ICH6_REG_SD_LPIB 0x04
91#define ICH6_REG_SD_CBL 0x08
92#define ICH6_REG_SD_LVI 0x0c
93#define ICH6_REG_SD_FIFOW 0x0e
94#define ICH6_REG_SD_FIFOSIZE 0x10
95#define ICH6_REG_SD_FORMAT 0x12
96#define ICH6_REG_SD_BDLPL 0x18
97#define ICH6_REG_SD_BDLPU 0x1c
98
99/* PCI space */
100#define ICH6_PCIREG_TCSEL 0x44
101
102/*
103 * other constants
104 */
105
106/* max number of SDs */
107/* ICH, ATI and VIA have 4 playback and 4 capture */
108#define ICH6_NUM_CAPTURE 4
109#define ICH6_NUM_PLAYBACK 4
110
111/* ULI has 6 playback and 5 capture */
112#define ULI_NUM_CAPTURE 5
113#define ULI_NUM_PLAYBACK 6
114
115/* ATI HDMI may have up to 8 playbacks and 0 capture */
116#define ATIHDMI_NUM_CAPTURE 0
117#define ATIHDMI_NUM_PLAYBACK 8
118
119/* TERA has 4 playback and 3 capture */
120#define TERA_NUM_CAPTURE 3
121#define TERA_NUM_PLAYBACK 4
122
123/* this number is statically defined for simplicity */
124#define MAX_AZX_DEV 16
125
126/* max number of fragments - we may use more if allocating more pages for BDL */
127#define BDL_SIZE 4096
128#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
129#define AZX_MAX_FRAG 32
130/* max buffer size - no h/w limit, you can increase as you like */
131#define AZX_MAX_BUF_SIZE (1024*1024*1024)
132
133/* RIRB int mask: overrun[2], response[0] */
134#define RIRB_INT_RESPONSE 0x01
135#define RIRB_INT_OVERRUN 0x04
136#define RIRB_INT_MASK 0x05
137
138/* STATESTS int mask: S3,SD2,SD1,SD0 */
139#define AZX_MAX_CODECS 8
140#define AZX_DEFAULT_CODECS 4
141#define STATESTS_INT_MASK ((1 << AZX_MAX_CODECS) - 1)
142
143/* SD_CTL bits */
144#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
145#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
146#define SD_CTL_STRIPE (3 << 16) /* stripe control */
147#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
148#define SD_CTL_DIR (1 << 19) /* bi-directional stream */
149#define SD_CTL_STREAM_TAG_MASK (0xf << 20)
150#define SD_CTL_STREAM_TAG_SHIFT 20
151
152/* SD_CTL and SD_STS */
153#define SD_INT_DESC_ERR 0x10 /* descriptor error interrupt */
154#define SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
155#define SD_INT_COMPLETE 0x04 /* completion interrupt */
156#define SD_INT_MASK (SD_INT_DESC_ERR|SD_INT_FIFO_ERR|\
157 SD_INT_COMPLETE)
158
159/* SD_STS */
160#define SD_STS_FIFO_READY 0x20 /* FIFO ready */
161
162/* INTCTL and INTSTS */
163#define ICH6_INT_ALL_STREAM 0xff /* all stream interrupts */
164#define ICH6_INT_CTRL_EN 0x40000000 /* controller interrupt enable bit */
165#define ICH6_INT_GLOBAL_EN 0x80000000 /* global interrupt enable bit */
166
167/* below are so far hardcoded - should read registers in future */
168#define ICH6_MAX_CORB_ENTRIES 256
169#define ICH6_MAX_RIRB_ENTRIES 256
170
171/* driver quirks (capabilities) */
172/* bits 0-7 are used for indicating driver type */
173#define AZX_DCAPS_NO_TCSEL (1 << 8) /* No Intel TCSEL bit */
174#define AZX_DCAPS_NO_MSI (1 << 9) /* No MSI support */
175#define AZX_DCAPS_ATI_SNOOP (1 << 10) /* ATI snoop enable */
176#define AZX_DCAPS_NVIDIA_SNOOP (1 << 11) /* Nvidia snoop enable */
177#define AZX_DCAPS_SCH_SNOOP (1 << 12) /* SCH/PCH snoop enable */
178#define AZX_DCAPS_RIRB_DELAY (1 << 13) /* Long delay in read loop */
179#define AZX_DCAPS_RIRB_PRE_DELAY (1 << 14) /* Put a delay before read */
180#define AZX_DCAPS_CTX_WORKAROUND (1 << 15) /* X-Fi workaround */
181#define AZX_DCAPS_POSFIX_LPIB (1 << 16) /* Use LPIB as default */
182#define AZX_DCAPS_POSFIX_VIA (1 << 17) /* Use VIACOMBO as default */
183#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */
184#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */
185#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
186#define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */
187#define AZX_DCAPS_ALIGN_BUFSIZE (1 << 22) /* buffer size alignment */
188#define AZX_DCAPS_4K_BDLE_BOUNDARY (1 << 23) /* BDLE in 4k boundary */
189#define AZX_DCAPS_COUNT_LPIB_DELAY (1 << 25) /* Take LPIB as delay */
190#define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */
191#define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */
192
193/* position fix mode */
194enum {
195 POS_FIX_AUTO,
196 POS_FIX_LPIB,
197 POS_FIX_POSBUF,
198 POS_FIX_VIACOMBO,
199 POS_FIX_COMBO,
200};
201
202/* Defines for ATI HD Audio support in SB450 south bridge */
203#define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
204#define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
205
206/* Defines for Nvidia HDA support */
207#define NVIDIA_HDA_TRANSREG_ADDR 0x4e
208#define NVIDIA_HDA_ENABLE_COHBITS 0x0f
209#define NVIDIA_HDA_ISTRM_COH 0x4d
210#define NVIDIA_HDA_OSTRM_COH 0x4c
211#define NVIDIA_HDA_ENABLE_COHBIT 0x01
212
213/* Defines for Intel SCH HDA snoop control */
214#define INTEL_SCH_HDA_DEVC 0x78
215#define INTEL_SCH_HDA_DEVC_NOSNOOP (0x1<<11)
216
217/* Define IN stream 0 FIFO size offset in VIA controller */
218#define VIA_IN_STREAM0_FIFO_SIZE_OFFSET 0x90
219/* Define VIA HD Audio Device ID*/
220#define VIA_HDAC_DEVICE_ID 0x3288
221
222/* HD Audio class code */
223#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
224
225struct azx_dev {
226 struct snd_dma_buffer bdl; /* BDL buffer */
227 u32 *posbuf; /* position buffer pointer */
228
229 unsigned int bufsize; /* size of the play buffer in bytes */
230 unsigned int period_bytes; /* size of the period in bytes */
231 unsigned int frags; /* number for period in the play buffer */
232 unsigned int fifo_size; /* FIFO size */
233 unsigned long start_wallclk; /* start + minimum wallclk */
234 unsigned long period_wallclk; /* wallclk for period */
235
236 void __iomem *sd_addr; /* stream descriptor pointer */
237
238 u32 sd_int_sta_mask; /* stream int status mask */
239
240 /* pcm support */
241 struct snd_pcm_substream *substream; /* assigned substream,
242 * set in PCM open
243 */
244 unsigned int format_val; /* format value to be set in the
245 * controller and the codec
246 */
247 unsigned char stream_tag; /* assigned stream */
248 unsigned char index; /* stream index */
249 int assigned_key; /* last device# key assigned to */
250
251 unsigned int opened:1;
252 unsigned int running:1;
253 unsigned int irq_pending:1;
254 unsigned int prepared:1;
255 unsigned int locked:1;
256 /*
257 * For VIA:
258 * A flag to ensure DMA position is 0
259 * when link position is not greater than FIFO size
260 */
261 unsigned int insufficient:1;
262 unsigned int wc_marked:1;
263 unsigned int no_period_wakeup:1;
264
265 struct timecounter azx_tc;
266 struct cyclecounter azx_cc;
267
268 int delay_negative_threshold;
269
270#ifdef CONFIG_SND_HDA_DSP_LOADER
271 /* Allows dsp load to have sole access to the playback stream. */
272 struct mutex dsp_mutex;
273#endif
274};
275
276/* CORB/RIRB */
277struct azx_rb {
278 u32 *buf; /* CORB/RIRB buffer
279 * Each CORB entry is 4byte, RIRB is 8byte
280 */
281 dma_addr_t addr; /* physical address of CORB/RIRB buffer */
282 /* for RIRB */
283 unsigned short rp, wp; /* read/write pointers */
284 int cmds[AZX_MAX_CODECS]; /* number of pending requests */
285 u32 res[AZX_MAX_CODECS]; /* last read value */
286};
287
288struct azx;
289
290/* Functions to read/write to hda registers. */
291struct hda_controller_ops {
292 /* Register Access */
293 void (*reg_writel)(u32 value, u32 __iomem *addr);
294 u32 (*reg_readl)(u32 __iomem *addr);
295 void (*reg_writew)(u16 value, u16 __iomem *addr);
296 u16 (*reg_readw)(u16 __iomem *addr);
297 void (*reg_writeb)(u8 value, u8 __iomem *addr);
298 u8 (*reg_readb)(u8 __iomem *addr);
299 /* Disable msi if supported, PCI only */
300 int (*disable_msi_reset_irq)(struct azx *);
301 /* Allocation ops */
302 int (*dma_alloc_pages)(struct azx *chip,
303 int type,
304 size_t size,
305 struct snd_dma_buffer *buf);
306 void (*dma_free_pages)(struct azx *chip, struct snd_dma_buffer *buf);
307 int (*substream_alloc_pages)(struct azx *chip,
308 struct snd_pcm_substream *substream,
309 size_t size);
310 int (*substream_free_pages)(struct azx *chip,
311 struct snd_pcm_substream *substream);
312 void (*pcm_mmap_prepare)(struct snd_pcm_substream *substream,
313 struct vm_area_struct *area);
314 /* Check if current position is acceptable */
315 int (*position_check)(struct azx *chip, struct azx_dev *azx_dev);
316};
317
318struct azx_pcm {
319 struct azx *chip;
320 struct snd_pcm *pcm;
321 struct hda_codec *codec;
322 struct hda_pcm_stream *hinfo[2];
323 struct list_head list;
324};
325
326struct azx {
327 struct snd_card *card;
328 struct pci_dev *pci;
329 int dev_index;
330
331 /* chip type specific */
332 int driver_type;
333 unsigned int driver_caps;
334 int playback_streams;
335 int playback_index_offset;
336 int capture_streams;
337 int capture_index_offset;
338 int num_streams;
339 const int *jackpoll_ms; /* per-card jack poll interval */
340
341 /* Register interaction. */
342 const struct hda_controller_ops *ops;
343
344 /* pci resources */
345 unsigned long addr;
346 void __iomem *remap_addr;
347 int irq;
348
349 /* locks */
350 spinlock_t reg_lock;
351 struct mutex open_mutex; /* Prevents concurrent open/close operations */
352 struct completion probe_wait;
353
354 /* streams (x num_streams) */
355 struct azx_dev *azx_dev;
356
357 /* PCM */
358 struct list_head pcm_list; /* azx_pcm list */
359
360 /* HD codec */
361 unsigned short codec_mask;
362 int codec_probe_mask; /* copied from probe_mask option */
363 struct hda_bus *bus;
364 unsigned int beep_mode;
365
366 /* CORB/RIRB */
367 struct azx_rb corb;
368 struct azx_rb rirb;
369
370 /* CORB/RIRB and position buffers */
371 struct snd_dma_buffer rb;
372 struct snd_dma_buffer posbuf;
373
374#ifdef CONFIG_SND_HDA_PATCH_LOADER
375 const struct firmware *fw;
376#endif
377
378 /* flags */
379 int position_fix[2]; /* for both playback/capture streams */
380 const int *bdl_pos_adj;
381 int poll_count;
382 unsigned int running:1;
383 unsigned int initialized:1;
384 unsigned int single_cmd:1;
385 unsigned int polling_mode:1;
386 unsigned int msi:1;
387 unsigned int irq_pending_warned:1;
388 unsigned int probing:1; /* codec probing phase */
389 unsigned int snoop:1;
390 unsigned int align_buffer_size:1;
391 unsigned int region_requested:1;
392
393 /* VGA-switcheroo setup */
394 unsigned int use_vga_switcheroo:1;
395 unsigned int vga_switcheroo_registered:1;
396 unsigned int init_failed:1; /* delayed init failed */
397 unsigned int disabled:1; /* disabled by VGA-switcher */
398
399 /* for debugging */
400 unsigned int last_cmd[AZX_MAX_CODECS];
401
402 /* for pending irqs */
403 struct work_struct irq_pending_work;
404
405 struct work_struct probe_work;
406
407 /* reboot notifier (for mysterious hangup problem at power-down) */
408 struct notifier_block reboot_notifier;
409
410 /* card list (for power_save trigger) */
411 struct list_head list;
412
413#ifdef CONFIG_SND_HDA_DSP_LOADER
414 struct azx_dev saved_azx_dev;
415#endif
416
417 /* secondary power domain for hdmi audio under vga device */
418 struct dev_pm_domain hdmi_pm_domain;
419};
420
421#ifdef CONFIG_SND_VERBOSE_PRINTK
422#define SFX /* nop */
423#else
424#define SFX "hda-intel "
425#endif
426
427#ifdef CONFIG_X86
428#define azx_snoop(chip) ((chip)->snoop)
429#else
430#define azx_snoop(chip) true
431#endif
432
433/*
434 * macros for easy use
435 */
436
437#define azx_writel(chip, reg, value) \
438 ((chip)->ops->reg_writel(value, (chip)->remap_addr + ICH6_REG_##reg))
439#define azx_readl(chip, reg) \
440 ((chip)->ops->reg_readl((chip)->remap_addr + ICH6_REG_##reg))
441#define azx_writew(chip, reg, value) \
442 ((chip)->ops->reg_writew(value, (chip)->remap_addr + ICH6_REG_##reg))
443#define azx_readw(chip, reg) \
444 ((chip)->ops->reg_readw((chip)->remap_addr + ICH6_REG_##reg))
445#define azx_writeb(chip, reg, value) \
446 ((chip)->ops->reg_writeb(value, (chip)->remap_addr + ICH6_REG_##reg))
447#define azx_readb(chip, reg) \
448 ((chip)->ops->reg_readb((chip)->remap_addr + ICH6_REG_##reg))
449
450#define azx_sd_writel(chip, dev, reg, value) \
451 ((chip)->ops->reg_writel(value, (dev)->sd_addr + ICH6_REG_##reg))
452#define azx_sd_readl(chip, dev, reg) \
453 ((chip)->ops->reg_readl((dev)->sd_addr + ICH6_REG_##reg))
454#define azx_sd_writew(chip, dev, reg, value) \
455 ((chip)->ops->reg_writew(value, (dev)->sd_addr + ICH6_REG_##reg))
456#define azx_sd_readw(chip, dev, reg) \
457 ((chip)->ops->reg_readw((dev)->sd_addr + ICH6_REG_##reg))
458#define azx_sd_writeb(chip, dev, reg, value) \
459 ((chip)->ops->reg_writeb(value, (dev)->sd_addr + ICH6_REG_##reg))
460#define azx_sd_readb(chip, dev, reg) \
461 ((chip)->ops->reg_readb((dev)->sd_addr + ICH6_REG_##reg))
462
463#endif /* __SOUND_HDA_PRIV_H */
diff --git a/sound/pci/hda/hda_sysfs.c b/sound/pci/hda/hda_sysfs.c
new file mode 100644
index 000000000000..e2079090ca6f
--- /dev/null
+++ b/sound/pci/hda/hda_sysfs.c
@@ -0,0 +1,780 @@
1/*
2 * sysfs interface for HD-audio codec
3 *
4 * Copyright (c) 2014 Takashi Iwai <tiwai@suse.de>
5 *
6 * split from hda_hwdep.c
7 */
8
9#include <linux/init.h>
10#include <linux/slab.h>
11#include <linux/compat.h>
12#include <linux/mutex.h>
13#include <linux/ctype.h>
14#include <linux/string.h>
15#include <linux/export.h>
16#include <sound/core.h>
17#include "hda_codec.h"
18#include "hda_local.h"
19#include <sound/hda_hwdep.h>
20#include <sound/minors.h>
21
22/* hint string pair */
23struct hda_hint {
24 const char *key;
25 const char *val; /* contained in the same alloc as key */
26};
27
28#ifdef CONFIG_PM
29static ssize_t power_on_acct_show(struct device *dev,
30 struct device_attribute *attr,
31 char *buf)
32{
33 struct hda_codec *codec = dev_get_drvdata(dev);
34 snd_hda_update_power_acct(codec);
35 return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
36}
37
38static ssize_t power_off_acct_show(struct device *dev,
39 struct device_attribute *attr,
40 char *buf)
41{
42 struct hda_codec *codec = dev_get_drvdata(dev);
43 snd_hda_update_power_acct(codec);
44 return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct));
45}
46
47static DEVICE_ATTR_RO(power_on_acct);
48static DEVICE_ATTR_RO(power_off_acct);
49#endif /* CONFIG_PM */
50
51#define CODEC_INFO_SHOW(type) \
52static ssize_t type##_show(struct device *dev, \
53 struct device_attribute *attr, \
54 char *buf) \
55{ \
56 struct hda_codec *codec = dev_get_drvdata(dev); \
57 return sprintf(buf, "0x%x\n", codec->type); \
58}
59
60#define CODEC_INFO_STR_SHOW(type) \
61static ssize_t type##_show(struct device *dev, \
62 struct device_attribute *attr, \
63 char *buf) \
64{ \
65 struct hda_codec *codec = dev_get_drvdata(dev); \
66 return sprintf(buf, "%s\n", \
67 codec->type ? codec->type : ""); \
68}
69
70CODEC_INFO_SHOW(vendor_id);
71CODEC_INFO_SHOW(subsystem_id);
72CODEC_INFO_SHOW(revision_id);
73CODEC_INFO_SHOW(afg);
74CODEC_INFO_SHOW(mfg);
75CODEC_INFO_STR_SHOW(vendor_name);
76CODEC_INFO_STR_SHOW(chip_name);
77CODEC_INFO_STR_SHOW(modelname);
78
79static ssize_t pin_configs_show(struct hda_codec *codec,
80 struct snd_array *list,
81 char *buf)
82{
83 int i, len = 0;
84 mutex_lock(&codec->user_mutex);
85 for (i = 0; i < list->used; i++) {
86 struct hda_pincfg *pin = snd_array_elem(list, i);
87 len += sprintf(buf + len, "0x%02x 0x%08x\n",
88 pin->nid, pin->cfg);
89 }
90 mutex_unlock(&codec->user_mutex);
91 return len;
92}
93
94static ssize_t init_pin_configs_show(struct device *dev,
95 struct device_attribute *attr,
96 char *buf)
97{
98 struct hda_codec *codec = dev_get_drvdata(dev);
99 return pin_configs_show(codec, &codec->init_pins, buf);
100}
101
102static ssize_t driver_pin_configs_show(struct device *dev,
103 struct device_attribute *attr,
104 char *buf)
105{
106 struct hda_codec *codec = dev_get_drvdata(dev);
107 return pin_configs_show(codec, &codec->driver_pins, buf);
108}
109
110#ifdef CONFIG_SND_HDA_RECONFIG
111
112/*
113 * sysfs interface
114 */
115
116static int clear_codec(struct hda_codec *codec)
117{
118 int err;
119
120 err = snd_hda_codec_reset(codec);
121 if (err < 0) {
122 codec_err(codec, "The codec is being used, can't free.\n");
123 return err;
124 }
125 snd_hda_sysfs_clear(codec);
126 return 0;
127}
128
129static int reconfig_codec(struct hda_codec *codec)
130{
131 int err;
132
133 snd_hda_power_up(codec);
134 codec_info(codec, "hda-codec: reconfiguring\n");
135 err = snd_hda_codec_reset(codec);
136 if (err < 0) {
137 codec_err(codec,
138 "The codec is being used, can't reconfigure.\n");
139 goto error;
140 }
141 err = snd_hda_codec_configure(codec);
142 if (err < 0)
143 goto error;
144 /* rebuild PCMs */
145 err = snd_hda_codec_build_pcms(codec);
146 if (err < 0)
147 goto error;
148 /* rebuild mixers */
149 err = snd_hda_codec_build_controls(codec);
150 if (err < 0)
151 goto error;
152 err = snd_card_register(codec->bus->card);
153 error:
154 snd_hda_power_down(codec);
155 return err;
156}
157
158/*
159 * allocate a string at most len chars, and remove the trailing EOL
160 */
161static char *kstrndup_noeol(const char *src, size_t len)
162{
163 char *s = kstrndup(src, len, GFP_KERNEL);
164 char *p;
165 if (!s)
166 return NULL;
167 p = strchr(s, '\n');
168 if (p)
169 *p = 0;
170 return s;
171}
172
173#define CODEC_INFO_STORE(type) \
174static ssize_t type##_store(struct device *dev, \
175 struct device_attribute *attr, \
176 const char *buf, size_t count) \
177{ \
178 struct hda_codec *codec = dev_get_drvdata(dev); \
179 unsigned long val; \
180 int err = kstrtoul(buf, 0, &val); \
181 if (err < 0) \
182 return err; \
183 codec->type = val; \
184 return count; \
185}
186
187#define CODEC_INFO_STR_STORE(type) \
188static ssize_t type##_store(struct device *dev, \
189 struct device_attribute *attr, \
190 const char *buf, size_t count) \
191{ \
192 struct hda_codec *codec = dev_get_drvdata(dev); \
193 char *s = kstrndup_noeol(buf, 64); \
194 if (!s) \
195 return -ENOMEM; \
196 kfree(codec->type); \
197 codec->type = s; \
198 return count; \
199}
200
201CODEC_INFO_STORE(vendor_id);
202CODEC_INFO_STORE(subsystem_id);
203CODEC_INFO_STORE(revision_id);
204CODEC_INFO_STR_STORE(vendor_name);
205CODEC_INFO_STR_STORE(chip_name);
206CODEC_INFO_STR_STORE(modelname);
207
208#define CODEC_ACTION_STORE(type) \
209static ssize_t type##_store(struct device *dev, \
210 struct device_attribute *attr, \
211 const char *buf, size_t count) \
212{ \
213 struct hda_codec *codec = dev_get_drvdata(dev); \
214 int err = 0; \
215 if (*buf) \
216 err = type##_codec(codec); \
217 return err < 0 ? err : count; \
218}
219
220CODEC_ACTION_STORE(reconfig);
221CODEC_ACTION_STORE(clear);
222
223static ssize_t init_verbs_show(struct device *dev,
224 struct device_attribute *attr,
225 char *buf)
226{
227 struct hda_codec *codec = dev_get_drvdata(dev);
228 int i, len = 0;
229 mutex_lock(&codec->user_mutex);
230 for (i = 0; i < codec->init_verbs.used; i++) {
231 struct hda_verb *v = snd_array_elem(&codec->init_verbs, i);
232 len += snprintf(buf + len, PAGE_SIZE - len,
233 "0x%02x 0x%03x 0x%04x\n",
234 v->nid, v->verb, v->param);
235 }
236 mutex_unlock(&codec->user_mutex);
237 return len;
238}
239
240static int parse_init_verbs(struct hda_codec *codec, const char *buf)
241{
242 struct hda_verb *v;
243 int nid, verb, param;
244
245 if (sscanf(buf, "%i %i %i", &nid, &verb, &param) != 3)
246 return -EINVAL;
247 if (!nid || !verb)
248 return -EINVAL;
249 mutex_lock(&codec->user_mutex);
250 v = snd_array_new(&codec->init_verbs);
251 if (!v) {
252 mutex_unlock(&codec->user_mutex);
253 return -ENOMEM;
254 }
255 v->nid = nid;
256 v->verb = verb;
257 v->param = param;
258 mutex_unlock(&codec->user_mutex);
259 return 0;
260}
261
262static ssize_t init_verbs_store(struct device *dev,
263 struct device_attribute *attr,
264 const char *buf, size_t count)
265{
266 struct hda_codec *codec = dev_get_drvdata(dev);
267 int err = parse_init_verbs(codec, buf);
268 if (err < 0)
269 return err;
270 return count;
271}
272
273static ssize_t hints_show(struct device *dev,
274 struct device_attribute *attr,
275 char *buf)
276{
277 struct hda_codec *codec = dev_get_drvdata(dev);
278 int i, len = 0;
279 mutex_lock(&codec->user_mutex);
280 for (i = 0; i < codec->hints.used; i++) {
281 struct hda_hint *hint = snd_array_elem(&codec->hints, i);
282 len += snprintf(buf + len, PAGE_SIZE - len,
283 "%s = %s\n", hint->key, hint->val);
284 }
285 mutex_unlock(&codec->user_mutex);
286 return len;
287}
288
289static struct hda_hint *get_hint(struct hda_codec *codec, const char *key)
290{
291 int i;
292
293 for (i = 0; i < codec->hints.used; i++) {
294 struct hda_hint *hint = snd_array_elem(&codec->hints, i);
295 if (!strcmp(hint->key, key))
296 return hint;
297 }
298 return NULL;
299}
300
301static void remove_trail_spaces(char *str)
302{
303 char *p;
304 if (!*str)
305 return;
306 p = str + strlen(str) - 1;
307 for (; isspace(*p); p--) {
308 *p = 0;
309 if (p == str)
310 return;
311 }
312}
313
314#define MAX_HINTS 1024
315
316static int parse_hints(struct hda_codec *codec, const char *buf)
317{
318 char *key, *val;
319 struct hda_hint *hint;
320 int err = 0;
321
322 buf = skip_spaces(buf);
323 if (!*buf || *buf == '#' || *buf == '\n')
324 return 0;
325 if (*buf == '=')
326 return -EINVAL;
327 key = kstrndup_noeol(buf, 1024);
328 if (!key)
329 return -ENOMEM;
330 /* extract key and val */
331 val = strchr(key, '=');
332 if (!val) {
333 kfree(key);
334 return -EINVAL;
335 }
336 *val++ = 0;
337 val = skip_spaces(val);
338 remove_trail_spaces(key);
339 remove_trail_spaces(val);
340 mutex_lock(&codec->user_mutex);
341 hint = get_hint(codec, key);
342 if (hint) {
343 /* replace */
344 kfree(hint->key);
345 hint->key = key;
346 hint->val = val;
347 goto unlock;
348 }
349 /* allocate a new hint entry */
350 if (codec->hints.used >= MAX_HINTS)
351 hint = NULL;
352 else
353 hint = snd_array_new(&codec->hints);
354 if (hint) {
355 hint->key = key;
356 hint->val = val;
357 } else {
358 err = -ENOMEM;
359 }
360 unlock:
361 mutex_unlock(&codec->user_mutex);
362 if (err)
363 kfree(key);
364 return err;
365}
366
367static ssize_t hints_store(struct device *dev,
368 struct device_attribute *attr,
369 const char *buf, size_t count)
370{
371 struct hda_codec *codec = dev_get_drvdata(dev);
372 int err = parse_hints(codec, buf);
373 if (err < 0)
374 return err;
375 return count;
376}
377
378static ssize_t user_pin_configs_show(struct device *dev,
379 struct device_attribute *attr,
380 char *buf)
381{
382 struct hda_codec *codec = dev_get_drvdata(dev);
383 return pin_configs_show(codec, &codec->user_pins, buf);
384}
385
386#define MAX_PIN_CONFIGS 32
387
388static int parse_user_pin_configs(struct hda_codec *codec, const char *buf)
389{
390 int nid, cfg, err;
391
392 if (sscanf(buf, "%i %i", &nid, &cfg) != 2)
393 return -EINVAL;
394 if (!nid)
395 return -EINVAL;
396 mutex_lock(&codec->user_mutex);
397 err = snd_hda_add_pincfg(codec, &codec->user_pins, nid, cfg);
398 mutex_unlock(&codec->user_mutex);
399 return err;
400}
401
402static ssize_t user_pin_configs_store(struct device *dev,
403 struct device_attribute *attr,
404 const char *buf, size_t count)
405{
406 struct hda_codec *codec = dev_get_drvdata(dev);
407 int err = parse_user_pin_configs(codec, buf);
408 if (err < 0)
409 return err;
410 return count;
411}
412
413/* sysfs attributes exposed only when CONFIG_SND_HDA_RECONFIG=y */
414static DEVICE_ATTR_RW(init_verbs);
415static DEVICE_ATTR_RW(hints);
416static DEVICE_ATTR_RW(user_pin_configs);
417static DEVICE_ATTR_WO(reconfig);
418static DEVICE_ATTR_WO(clear);
419
420/*
421 * Look for hint string
422 */
423const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
424{
425 struct hda_hint *hint = get_hint(codec, key);
426 return hint ? hint->val : NULL;
427}
428EXPORT_SYMBOL_GPL(snd_hda_get_hint);
429
430int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
431{
432 const char *p;
433 int ret;
434
435 mutex_lock(&codec->user_mutex);
436 p = snd_hda_get_hint(codec, key);
437 if (!p || !*p)
438 ret = -ENOENT;
439 else {
440 switch (toupper(*p)) {
441 case 'T': /* true */
442 case 'Y': /* yes */
443 case '1':
444 ret = 1;
445 break;
446 default:
447 ret = 0;
448 break;
449 }
450 }
451 mutex_unlock(&codec->user_mutex);
452 return ret;
453}
454EXPORT_SYMBOL_GPL(snd_hda_get_bool_hint);
455
456int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
457{
458 const char *p;
459 unsigned long val;
460 int ret;
461
462 mutex_lock(&codec->user_mutex);
463 p = snd_hda_get_hint(codec, key);
464 if (!p)
465 ret = -ENOENT;
466 else if (kstrtoul(p, 0, &val))
467 ret = -EINVAL;
468 else {
469 *valp = val;
470 ret = 0;
471 }
472 mutex_unlock(&codec->user_mutex);
473 return ret;
474}
475EXPORT_SYMBOL_GPL(snd_hda_get_int_hint);
476#endif /* CONFIG_SND_HDA_RECONFIG */
477
478/*
479 * common sysfs attributes
480 */
481#ifdef CONFIG_SND_HDA_RECONFIG
482#define RECONFIG_DEVICE_ATTR(name) DEVICE_ATTR_RW(name)
483#else
484#define RECONFIG_DEVICE_ATTR(name) DEVICE_ATTR_RO(name)
485#endif
486static RECONFIG_DEVICE_ATTR(vendor_id);
487static RECONFIG_DEVICE_ATTR(subsystem_id);
488static RECONFIG_DEVICE_ATTR(revision_id);
489static DEVICE_ATTR_RO(afg);
490static DEVICE_ATTR_RO(mfg);
491static RECONFIG_DEVICE_ATTR(vendor_name);
492static RECONFIG_DEVICE_ATTR(chip_name);
493static RECONFIG_DEVICE_ATTR(modelname);
494static DEVICE_ATTR_RO(init_pin_configs);
495static DEVICE_ATTR_RO(driver_pin_configs);
496
497
498#ifdef CONFIG_SND_HDA_PATCH_LOADER
499
500/* parser mode */
501enum {
502 LINE_MODE_NONE,
503 LINE_MODE_CODEC,
504 LINE_MODE_MODEL,
505 LINE_MODE_PINCFG,
506 LINE_MODE_VERB,
507 LINE_MODE_HINT,
508 LINE_MODE_VENDOR_ID,
509 LINE_MODE_SUBSYSTEM_ID,
510 LINE_MODE_REVISION_ID,
511 LINE_MODE_CHIP_NAME,
512 NUM_LINE_MODES,
513};
514
515static inline int strmatch(const char *a, const char *b)
516{
517 return strnicmp(a, b, strlen(b)) == 0;
518}
519
520/* parse the contents after the line "[codec]"
521 * accept only the line with three numbers, and assign the current codec
522 */
523static void parse_codec_mode(char *buf, struct hda_bus *bus,
524 struct hda_codec **codecp)
525{
526 int vendorid, subid, caddr;
527 struct hda_codec *codec;
528
529 *codecp = NULL;
530 if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) {
531 list_for_each_entry(codec, &bus->codec_list, list) {
532 if ((vendorid <= 0 || codec->vendor_id == vendorid) &&
533 (subid <= 0 || codec->subsystem_id == subid) &&
534 codec->addr == caddr) {
535 *codecp = codec;
536 break;
537 }
538 }
539 }
540}
541
542/* parse the contents after the other command tags, [pincfg], [verb],
543 * [vendor_id], [subsystem_id], [revision_id], [chip_name], [hint] and [model]
544 * just pass to the sysfs helper (only when any codec was specified)
545 */
546static void parse_pincfg_mode(char *buf, struct hda_bus *bus,
547 struct hda_codec **codecp)
548{
549 parse_user_pin_configs(*codecp, buf);
550}
551
552static void parse_verb_mode(char *buf, struct hda_bus *bus,
553 struct hda_codec **codecp)
554{
555 parse_init_verbs(*codecp, buf);
556}
557
558static void parse_hint_mode(char *buf, struct hda_bus *bus,
559 struct hda_codec **codecp)
560{
561 parse_hints(*codecp, buf);
562}
563
564static void parse_model_mode(char *buf, struct hda_bus *bus,
565 struct hda_codec **codecp)
566{
567 kfree((*codecp)->modelname);
568 (*codecp)->modelname = kstrdup(buf, GFP_KERNEL);
569}
570
571static void parse_chip_name_mode(char *buf, struct hda_bus *bus,
572 struct hda_codec **codecp)
573{
574 kfree((*codecp)->chip_name);
575 (*codecp)->chip_name = kstrdup(buf, GFP_KERNEL);
576}
577
578#define DEFINE_PARSE_ID_MODE(name) \
579static void parse_##name##_mode(char *buf, struct hda_bus *bus, \
580 struct hda_codec **codecp) \
581{ \
582 unsigned long val; \
583 if (!kstrtoul(buf, 0, &val)) \
584 (*codecp)->name = val; \
585}
586
587DEFINE_PARSE_ID_MODE(vendor_id);
588DEFINE_PARSE_ID_MODE(subsystem_id);
589DEFINE_PARSE_ID_MODE(revision_id);
590
591
592struct hda_patch_item {
593 const char *tag;
594 const char *alias;
595 void (*parser)(char *buf, struct hda_bus *bus, struct hda_codec **retc);
596};
597
598static struct hda_patch_item patch_items[NUM_LINE_MODES] = {
599 [LINE_MODE_CODEC] = {
600 .tag = "[codec]",
601 .parser = parse_codec_mode,
602 },
603 [LINE_MODE_MODEL] = {
604 .tag = "[model]",
605 .parser = parse_model_mode,
606 },
607 [LINE_MODE_VERB] = {
608 .tag = "[verb]",
609 .alias = "[init_verbs]",
610 .parser = parse_verb_mode,
611 },
612 [LINE_MODE_PINCFG] = {
613 .tag = "[pincfg]",
614 .alias = "[user_pin_configs]",
615 .parser = parse_pincfg_mode,
616 },
617 [LINE_MODE_HINT] = {
618 .tag = "[hint]",
619 .alias = "[hints]",
620 .parser = parse_hint_mode
621 },
622 [LINE_MODE_VENDOR_ID] = {
623 .tag = "[vendor_id]",
624 .parser = parse_vendor_id_mode,
625 },
626 [LINE_MODE_SUBSYSTEM_ID] = {
627 .tag = "[subsystem_id]",
628 .parser = parse_subsystem_id_mode,
629 },
630 [LINE_MODE_REVISION_ID] = {
631 .tag = "[revision_id]",
632 .parser = parse_revision_id_mode,
633 },
634 [LINE_MODE_CHIP_NAME] = {
635 .tag = "[chip_name]",
636 .parser = parse_chip_name_mode,
637 },
638};
639
640/* check the line starting with '[' -- change the parser mode accodingly */
641static int parse_line_mode(char *buf, struct hda_bus *bus)
642{
643 int i;
644 for (i = 0; i < ARRAY_SIZE(patch_items); i++) {
645 if (!patch_items[i].tag)
646 continue;
647 if (strmatch(buf, patch_items[i].tag))
648 return i;
649 if (patch_items[i].alias && strmatch(buf, patch_items[i].alias))
650 return i;
651 }
652 return LINE_MODE_NONE;
653}
654
655/* copy one line from the buffer in fw, and update the fields in fw
656 * return zero if it reaches to the end of the buffer, or non-zero
657 * if successfully copied a line
658 *
659 * the spaces at the beginning and the end of the line are stripped
660 */
661static int get_line_from_fw(char *buf, int size, size_t *fw_size_p,
662 const void **fw_data_p)
663{
664 int len;
665 size_t fw_size = *fw_size_p;
666 const char *p = *fw_data_p;
667
668 while (isspace(*p) && fw_size) {
669 p++;
670 fw_size--;
671 }
672 if (!fw_size)
673 return 0;
674
675 for (len = 0; len < fw_size; len++) {
676 if (!*p)
677 break;
678 if (*p == '\n') {
679 p++;
680 len++;
681 break;
682 }
683 if (len < size)
684 *buf++ = *p++;
685 }
686 *buf = 0;
687 *fw_size_p = fw_size - len;
688 *fw_data_p = p;
689 remove_trail_spaces(buf);
690 return 1;
691}
692
693/*
694 * load a "patch" firmware file and parse it
695 */
696int snd_hda_load_patch(struct hda_bus *bus, size_t fw_size, const void *fw_buf)
697{
698 char buf[128];
699 struct hda_codec *codec;
700 int line_mode;
701
702 line_mode = LINE_MODE_NONE;
703 codec = NULL;
704 while (get_line_from_fw(buf, sizeof(buf) - 1, &fw_size, &fw_buf)) {
705 if (!*buf || *buf == '#' || *buf == '\n')
706 continue;
707 if (*buf == '[')
708 line_mode = parse_line_mode(buf, bus);
709 else if (patch_items[line_mode].parser &&
710 (codec || line_mode <= LINE_MODE_CODEC))
711 patch_items[line_mode].parser(buf, bus, &codec);
712 }
713 return 0;
714}
715EXPORT_SYMBOL_GPL(snd_hda_load_patch);
716#endif /* CONFIG_SND_HDA_PATCH_LOADER */
717
718/*
719 * sysfs entries
720 */
721static struct attribute *hda_dev_attrs[] = {
722 &dev_attr_vendor_id.attr,
723 &dev_attr_subsystem_id.attr,
724 &dev_attr_revision_id.attr,
725 &dev_attr_afg.attr,
726 &dev_attr_mfg.attr,
727 &dev_attr_vendor_name.attr,
728 &dev_attr_chip_name.attr,
729 &dev_attr_modelname.attr,
730 &dev_attr_init_pin_configs.attr,
731 &dev_attr_driver_pin_configs.attr,
732#ifdef CONFIG_PM
733 &dev_attr_power_on_acct.attr,
734 &dev_attr_power_off_acct.attr,
735#endif
736#ifdef CONFIG_SND_HDA_RECONFIG
737 &dev_attr_init_verbs.attr,
738 &dev_attr_hints.attr,
739 &dev_attr_user_pin_configs.attr,
740 &dev_attr_reconfig.attr,
741 &dev_attr_clear.attr,
742#endif
743 NULL
744};
745
746static struct attribute_group hda_dev_attr_group = {
747 .attrs = hda_dev_attrs,
748};
749
750const struct attribute_group *snd_hda_dev_attr_groups[] = {
751 &hda_dev_attr_group,
752 NULL
753};
754
755void snd_hda_sysfs_init(struct hda_codec *codec)
756{
757 mutex_init(&codec->user_mutex);
758#ifdef CONFIG_SND_HDA_RECONFIG
759 snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32);
760 snd_array_init(&codec->hints, sizeof(struct hda_hint), 32);
761 snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16);
762#endif
763}
764
765void snd_hda_sysfs_clear(struct hda_codec *codec)
766{
767#ifdef CONFIG_SND_HDA_RECONFIG
768 int i;
769
770 /* clear init verbs */
771 snd_array_free(&codec->init_verbs);
772 /* clear hints */
773 for (i = 0; i < codec->hints.used; i++) {
774 struct hda_hint *hint = snd_array_elem(&codec->hints, i);
775 kfree(hint->key); /* we don't need to free hint->val */
776 }
777 snd_array_free(&codec->hints);
778 snd_array_free(&codec->user_pins);
779#endif
780}
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 8ed0bcc01386..40ba06eb44af 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -21,7 +21,6 @@
21 21
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/pci.h>
25#include <linux/module.h> 24#include <linux/module.h>
26 25
27#include <sound/core.h> 26#include <sound/core.h>
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c
index 30b3a4bc06ee..5e65999e0d8e 100644
--- a/sound/pci/hda/patch_ca0110.c
+++ b/sound/pci/hda/patch_ca0110.c
@@ -20,7 +20,6 @@
20 20
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/pci.h>
24#include <linux/module.h> 23#include <linux/module.h>
25#include <sound/core.h> 24#include <sound/core.h>
26#include "hda_codec.h" 25#include "hda_codec.h"
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 46ecdbb9053f..092f2bd030bd 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -24,7 +24,6 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/pci.h>
28#include <linux/mutex.h> 27#include <linux/mutex.h>
29#include <linux/module.h> 28#include <linux/module.h>
30#include <linux/firmware.h> 29#include <linux/firmware.h>
@@ -868,7 +867,7 @@ static int chipio_write_data_multiple(struct hda_codec *codec,
868 int status = 0; 867 int status = 0;
869 868
870 if (data == NULL) { 869 if (data == NULL) {
871 snd_printdd(KERN_ERR "chipio_write_data null ptr\n"); 870 codec_dbg(codec, "chipio_write_data null ptr\n");
872 return -EINVAL; 871 return -EINVAL;
873 } 872 }
874 873
@@ -1407,12 +1406,12 @@ static int dspio_scp(struct hda_codec *codec,
1407 return -EINVAL; 1406 return -EINVAL;
1408 1407
1409 if (dir == SCP_GET && reply == NULL) { 1408 if (dir == SCP_GET && reply == NULL) {
1410 snd_printdd(KERN_ERR "dspio_scp get but has no buffer\n"); 1409 codec_dbg(codec, "dspio_scp get but has no buffer\n");
1411 return -EINVAL; 1410 return -EINVAL;
1412 } 1411 }
1413 1412
1414 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) { 1413 if (reply != NULL && (reply_len == NULL || (*reply_len == 0))) {
1415 snd_printdd(KERN_ERR "dspio_scp bad resp buf len parms\n"); 1414 codec_dbg(codec, "dspio_scp bad resp buf len parms\n");
1416 return -EINVAL; 1415 return -EINVAL;
1417 } 1416 }
1418 1417
@@ -1430,7 +1429,7 @@ static int dspio_scp(struct hda_codec *codec,
1430 sizeof(scp_reply), &ret_bytes); 1429 sizeof(scp_reply), &ret_bytes);
1431 1430
1432 if (status < 0) { 1431 if (status < 0) {
1433 snd_printdd(KERN_ERR "dspio_scp: send scp msg failed\n"); 1432 codec_dbg(codec, "dspio_scp: send scp msg failed\n");
1434 return status; 1433 return status;
1435 } 1434 }
1436 1435
@@ -1449,17 +1448,17 @@ static int dspio_scp(struct hda_codec *codec,
1449 / sizeof(unsigned int); 1448 / sizeof(unsigned int);
1450 1449
1451 if (*reply_len < ret_size*sizeof(unsigned int)) { 1450 if (*reply_len < ret_size*sizeof(unsigned int)) {
1452 snd_printdd(KERN_ERR "reply too long for buf\n"); 1451 codec_dbg(codec, "reply too long for buf\n");
1453 return -EINVAL; 1452 return -EINVAL;
1454 } else if (ret_size != reply_data_size) { 1453 } else if (ret_size != reply_data_size) {
1455 snd_printdd(KERN_ERR "RetLen and HdrLen .NE.\n"); 1454 codec_dbg(codec, "RetLen and HdrLen .NE.\n");
1456 return -EINVAL; 1455 return -EINVAL;
1457 } else { 1456 } else {
1458 *reply_len = ret_size*sizeof(unsigned int); 1457 *reply_len = ret_size*sizeof(unsigned int);
1459 memcpy(reply, scp_reply.data, *reply_len); 1458 memcpy(reply, scp_reply.data, *reply_len);
1460 } 1459 }
1461 } else { 1460 } else {
1462 snd_printdd(KERN_ERR "reply ill-formed or errflag set\n"); 1461 codec_dbg(codec, "reply ill-formed or errflag set\n");
1463 return -EIO; 1462 return -EIO;
1464 } 1463 }
1465 1464
@@ -1489,22 +1488,22 @@ static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
1489 int status = 0; 1488 int status = 0;
1490 unsigned int size = sizeof(dma_chan); 1489 unsigned int size = sizeof(dma_chan);
1491 1490
1492 snd_printdd(KERN_INFO " dspio_alloc_dma_chan() -- begin\n"); 1491 codec_dbg(codec, " dspio_alloc_dma_chan() -- begin\n");
1493 status = dspio_scp(codec, MASTERCONTROL, MASTERCONTROL_ALLOC_DMA_CHAN, 1492 status = dspio_scp(codec, MASTERCONTROL, MASTERCONTROL_ALLOC_DMA_CHAN,
1494 SCP_GET, NULL, 0, dma_chan, &size); 1493 SCP_GET, NULL, 0, dma_chan, &size);
1495 1494
1496 if (status < 0) { 1495 if (status < 0) {
1497 snd_printdd(KERN_INFO "dspio_alloc_dma_chan: SCP Failed\n"); 1496 codec_dbg(codec, "dspio_alloc_dma_chan: SCP Failed\n");
1498 return status; 1497 return status;
1499 } 1498 }
1500 1499
1501 if ((*dma_chan + 1) == 0) { 1500 if ((*dma_chan + 1) == 0) {
1502 snd_printdd(KERN_INFO "no free dma channels to allocate\n"); 1501 codec_dbg(codec, "no free dma channels to allocate\n");
1503 return -EBUSY; 1502 return -EBUSY;
1504 } 1503 }
1505 1504
1506 snd_printdd("dspio_alloc_dma_chan: chan=%d\n", *dma_chan); 1505 codec_dbg(codec, "dspio_alloc_dma_chan: chan=%d\n", *dma_chan);
1507 snd_printdd(KERN_INFO " dspio_alloc_dma_chan() -- complete\n"); 1506 codec_dbg(codec, " dspio_alloc_dma_chan() -- complete\n");
1508 1507
1509 return status; 1508 return status;
1510} 1509}
@@ -1517,18 +1516,18 @@ static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
1517 int status = 0; 1516 int status = 0;
1518 unsigned int dummy = 0; 1517 unsigned int dummy = 0;
1519 1518
1520 snd_printdd(KERN_INFO " dspio_free_dma_chan() -- begin\n"); 1519 codec_dbg(codec, " dspio_free_dma_chan() -- begin\n");
1521 snd_printdd("dspio_free_dma_chan: chan=%d\n", dma_chan); 1520 codec_dbg(codec, "dspio_free_dma_chan: chan=%d\n", dma_chan);
1522 1521
1523 status = dspio_scp(codec, MASTERCONTROL, MASTERCONTROL_ALLOC_DMA_CHAN, 1522 status = dspio_scp(codec, MASTERCONTROL, MASTERCONTROL_ALLOC_DMA_CHAN,
1524 SCP_SET, &dma_chan, sizeof(dma_chan), NULL, &dummy); 1523 SCP_SET, &dma_chan, sizeof(dma_chan), NULL, &dummy);
1525 1524
1526 if (status < 0) { 1525 if (status < 0) {
1527 snd_printdd(KERN_INFO "dspio_free_dma_chan: SCP Failed\n"); 1526 codec_dbg(codec, "dspio_free_dma_chan: SCP Failed\n");
1528 return status; 1527 return status;
1529 } 1528 }
1530 1529
1531 snd_printdd(KERN_INFO " dspio_free_dma_chan() -- complete\n"); 1530 codec_dbg(codec, " dspio_free_dma_chan() -- complete\n");
1532 1531
1533 return status; 1532 return status;
1534} 1533}
@@ -1576,14 +1575,14 @@ static int dsp_reset(struct hda_codec *codec)
1576 unsigned int res; 1575 unsigned int res;
1577 int retry = 20; 1576 int retry = 20;
1578 1577
1579 snd_printdd("dsp_reset\n"); 1578 codec_dbg(codec, "dsp_reset\n");
1580 do { 1579 do {
1581 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0); 1580 res = dspio_send(codec, VENDOR_DSPIO_DSP_INIT, 0);
1582 retry--; 1581 retry--;
1583 } while (res == -EIO && retry); 1582 } while (res == -EIO && retry);
1584 1583
1585 if (!retry) { 1584 if (!retry) {
1586 snd_printdd("dsp_reset timeout\n"); 1585 codec_dbg(codec, "dsp_reset timeout\n");
1587 return -EIO; 1586 return -EIO;
1588 } 1587 }
1589 1588
@@ -1636,39 +1635,39 @@ static int dsp_dma_setup_common(struct hda_codec *codec,
1636 unsigned int active; 1635 unsigned int active;
1637 bool code, yram; 1636 bool code, yram;
1638 1637
1639 snd_printdd(KERN_INFO "-- dsp_dma_setup_common() -- Begin ---------\n"); 1638 codec_dbg(codec, "-- dsp_dma_setup_common() -- Begin ---------\n");
1640 1639
1641 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) { 1640 if (dma_chan >= DSPDMAC_DMA_CFG_CHANNEL_COUNT) {
1642 snd_printdd(KERN_ERR "dma chan num invalid\n"); 1641 codec_dbg(codec, "dma chan num invalid\n");
1643 return -EINVAL; 1642 return -EINVAL;
1644 } 1643 }
1645 1644
1646 if (dsp_is_dma_active(codec, dma_chan)) { 1645 if (dsp_is_dma_active(codec, dma_chan)) {
1647 snd_printdd(KERN_ERR "dma already active\n"); 1646 codec_dbg(codec, "dma already active\n");
1648 return -EBUSY; 1647 return -EBUSY;
1649 } 1648 }
1650 1649
1651 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram); 1650 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
1652 1651
1653 if (dsp_addx == INVALID_CHIP_ADDRESS) { 1652 if (dsp_addx == INVALID_CHIP_ADDRESS) {
1654 snd_printdd(KERN_ERR "invalid chip addr\n"); 1653 codec_dbg(codec, "invalid chip addr\n");
1655 return -ENXIO; 1654 return -ENXIO;
1656 } 1655 }
1657 1656
1658 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK; 1657 chnl_prop = DSPDMAC_CHNLPROP_AC_MASK;
1659 active = 0; 1658 active = 0;
1660 1659
1661 snd_printdd(KERN_INFO " dsp_dma_setup_common() start reg pgm\n"); 1660 codec_dbg(codec, " dsp_dma_setup_common() start reg pgm\n");
1662 1661
1663 if (ovly) { 1662 if (ovly) {
1664 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET, 1663 status = chipio_read(codec, DSPDMAC_CHNLPROP_INST_OFFSET,
1665 &chnl_prop); 1664 &chnl_prop);
1666 1665
1667 if (status < 0) { 1666 if (status < 0) {
1668 snd_printdd(KERN_ERR "read CHNLPROP Reg fail\n"); 1667 codec_dbg(codec, "read CHNLPROP Reg fail\n");
1669 return status; 1668 return status;
1670 } 1669 }
1671 snd_printdd(KERN_INFO "dsp_dma_setup_common() Read CHNLPROP\n"); 1670 codec_dbg(codec, "dsp_dma_setup_common() Read CHNLPROP\n");
1672 } 1671 }
1673 1672
1674 if (!code) 1673 if (!code)
@@ -1680,20 +1679,20 @@ static int dsp_dma_setup_common(struct hda_codec *codec,
1680 1679
1681 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop); 1680 status = chipio_write(codec, DSPDMAC_CHNLPROP_INST_OFFSET, chnl_prop);
1682 if (status < 0) { 1681 if (status < 0) {
1683 snd_printdd(KERN_ERR "write CHNLPROP Reg fail\n"); 1682 codec_dbg(codec, "write CHNLPROP Reg fail\n");
1684 return status; 1683 return status;
1685 } 1684 }
1686 snd_printdd(KERN_INFO " dsp_dma_setup_common() Write CHNLPROP\n"); 1685 codec_dbg(codec, " dsp_dma_setup_common() Write CHNLPROP\n");
1687 1686
1688 if (ovly) { 1687 if (ovly) {
1689 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET, 1688 status = chipio_read(codec, DSPDMAC_ACTIVE_INST_OFFSET,
1690 &active); 1689 &active);
1691 1690
1692 if (status < 0) { 1691 if (status < 0) {
1693 snd_printdd(KERN_ERR "read ACTIVE Reg fail\n"); 1692 codec_dbg(codec, "read ACTIVE Reg fail\n");
1694 return status; 1693 return status;
1695 } 1694 }
1696 snd_printdd(KERN_INFO "dsp_dma_setup_common() Read ACTIVE\n"); 1695 codec_dbg(codec, "dsp_dma_setup_common() Read ACTIVE\n");
1697 } 1696 }
1698 1697
1699 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) & 1698 active &= (~(1 << (DSPDMAC_ACTIVE_AAR_LOBIT + dma_chan))) &
@@ -1701,35 +1700,35 @@ static int dsp_dma_setup_common(struct hda_codec *codec,
1701 1700
1702 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active); 1701 status = chipio_write(codec, DSPDMAC_ACTIVE_INST_OFFSET, active);
1703 if (status < 0) { 1702 if (status < 0) {
1704 snd_printdd(KERN_ERR "write ACTIVE Reg fail\n"); 1703 codec_dbg(codec, "write ACTIVE Reg fail\n");
1705 return status; 1704 return status;
1706 } 1705 }
1707 1706
1708 snd_printdd(KERN_INFO " dsp_dma_setup_common() Write ACTIVE\n"); 1707 codec_dbg(codec, " dsp_dma_setup_common() Write ACTIVE\n");
1709 1708
1710 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan), 1709 status = chipio_write(codec, DSPDMAC_AUDCHSEL_INST_OFFSET(dma_chan),
1711 port_map_mask); 1710 port_map_mask);
1712 if (status < 0) { 1711 if (status < 0) {
1713 snd_printdd(KERN_ERR "write AUDCHSEL Reg fail\n"); 1712 codec_dbg(codec, "write AUDCHSEL Reg fail\n");
1714 return status; 1713 return status;
1715 } 1714 }
1716 snd_printdd(KERN_INFO " dsp_dma_setup_common() Write AUDCHSEL\n"); 1715 codec_dbg(codec, " dsp_dma_setup_common() Write AUDCHSEL\n");
1717 1716
1718 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan), 1717 status = chipio_write(codec, DSPDMAC_IRQCNT_INST_OFFSET(dma_chan),
1719 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK); 1718 DSPDMAC_IRQCNT_BICNT_MASK | DSPDMAC_IRQCNT_CICNT_MASK);
1720 if (status < 0) { 1719 if (status < 0) {
1721 snd_printdd(KERN_ERR "write IRQCNT Reg fail\n"); 1720 codec_dbg(codec, "write IRQCNT Reg fail\n");
1722 return status; 1721 return status;
1723 } 1722 }
1724 snd_printdd(KERN_INFO " dsp_dma_setup_common() Write IRQCNT\n"); 1723 codec_dbg(codec, " dsp_dma_setup_common() Write IRQCNT\n");
1725 1724
1726 snd_printdd( 1725 codec_dbg(codec,
1727 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, " 1726 "ChipA=0x%x,DspA=0x%x,dmaCh=%u, "
1728 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n", 1727 "CHSEL=0x%x,CHPROP=0x%x,Active=0x%x\n",
1729 chip_addx, dsp_addx, dma_chan, 1728 chip_addx, dsp_addx, dma_chan,
1730 port_map_mask, chnl_prop, active); 1729 port_map_mask, chnl_prop, active);
1731 1730
1732 snd_printdd(KERN_INFO "-- dsp_dma_setup_common() -- Complete ------\n"); 1731 codec_dbg(codec, "-- dsp_dma_setup_common() -- Complete ------\n");
1733 1732
1734 return 0; 1733 return 0;
1735} 1734}
@@ -1755,20 +1754,20 @@ static int dsp_dma_setup(struct hda_codec *codec,
1755 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT - 1754 const unsigned int max_dma_count = 1 << (DSPDMAC_XFRCNT_BCNT_HIBIT -
1756 DSPDMAC_XFRCNT_BCNT_LOBIT + 1); 1755 DSPDMAC_XFRCNT_BCNT_LOBIT + 1);
1757 1756
1758 snd_printdd(KERN_INFO "-- dsp_dma_setup() -- Begin ---------\n"); 1757 codec_dbg(codec, "-- dsp_dma_setup() -- Begin ---------\n");
1759 1758
1760 if (count > max_dma_count) { 1759 if (count > max_dma_count) {
1761 snd_printdd(KERN_ERR "count too big\n"); 1760 codec_dbg(codec, "count too big\n");
1762 return -EINVAL; 1761 return -EINVAL;
1763 } 1762 }
1764 1763
1765 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram); 1764 dsp_addx = dsp_chip_to_dsp_addx(chip_addx, &code, &yram);
1766 if (dsp_addx == INVALID_CHIP_ADDRESS) { 1765 if (dsp_addx == INVALID_CHIP_ADDRESS) {
1767 snd_printdd(KERN_ERR "invalid chip addr\n"); 1766 codec_dbg(codec, "invalid chip addr\n");
1768 return -ENXIO; 1767 return -ENXIO;
1769 } 1768 }
1770 1769
1771 snd_printdd(KERN_INFO " dsp_dma_setup() start reg pgm\n"); 1770 codec_dbg(codec, " dsp_dma_setup() start reg pgm\n");
1772 1771
1773 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT; 1772 addr_field = dsp_addx << DSPDMAC_DMACFG_DBADR_LOBIT;
1774 incr_field = 0; 1773 incr_field = 0;
@@ -1785,10 +1784,10 @@ static int dsp_dma_setup(struct hda_codec *codec,
1785 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan), 1784 status = chipio_write(codec, DSPDMAC_DMACFG_INST_OFFSET(dma_chan),
1786 dma_cfg); 1785 dma_cfg);
1787 if (status < 0) { 1786 if (status < 0) {
1788 snd_printdd(KERN_ERR "write DMACFG Reg fail\n"); 1787 codec_dbg(codec, "write DMACFG Reg fail\n");
1789 return status; 1788 return status;
1790 } 1789 }
1791 snd_printdd(KERN_INFO " dsp_dma_setup() Write DMACFG\n"); 1790 codec_dbg(codec, " dsp_dma_setup() Write DMACFG\n");
1792 1791
1793 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT + 1792 adr_ofs = (count - 1) << (DSPDMAC_DSPADROFS_BOFS_LOBIT +
1794 (code ? 0 : 1)); 1793 (code ? 0 : 1));
@@ -1796,10 +1795,10 @@ static int dsp_dma_setup(struct hda_codec *codec,
1796 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan), 1795 status = chipio_write(codec, DSPDMAC_DSPADROFS_INST_OFFSET(dma_chan),
1797 adr_ofs); 1796 adr_ofs);
1798 if (status < 0) { 1797 if (status < 0) {
1799 snd_printdd(KERN_ERR "write DSPADROFS Reg fail\n"); 1798 codec_dbg(codec, "write DSPADROFS Reg fail\n");
1800 return status; 1799 return status;
1801 } 1800 }
1802 snd_printdd(KERN_INFO " dsp_dma_setup() Write DSPADROFS\n"); 1801 codec_dbg(codec, " dsp_dma_setup() Write DSPADROFS\n");
1803 1802
1804 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT; 1803 base_cnt = (count - 1) << DSPDMAC_XFRCNT_BCNT_LOBIT;
1805 1804
@@ -1810,17 +1809,17 @@ static int dsp_dma_setup(struct hda_codec *codec,
1810 status = chipio_write(codec, 1809 status = chipio_write(codec,
1811 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt); 1810 DSPDMAC_XFRCNT_INST_OFFSET(dma_chan), xfr_cnt);
1812 if (status < 0) { 1811 if (status < 0) {
1813 snd_printdd(KERN_ERR "write XFRCNT Reg fail\n"); 1812 codec_dbg(codec, "write XFRCNT Reg fail\n");
1814 return status; 1813 return status;
1815 } 1814 }
1816 snd_printdd(KERN_INFO " dsp_dma_setup() Write XFRCNT\n"); 1815 codec_dbg(codec, " dsp_dma_setup() Write XFRCNT\n");
1817 1816
1818 snd_printdd( 1817 codec_dbg(codec,
1819 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, " 1818 "ChipA=0x%x, cnt=0x%x, DMACFG=0x%x, "
1820 "ADROFS=0x%x, XFRCNT=0x%x\n", 1819 "ADROFS=0x%x, XFRCNT=0x%x\n",
1821 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt); 1820 chip_addx, count, dma_cfg, adr_ofs, xfr_cnt);
1822 1821
1823 snd_printdd(KERN_INFO "-- dsp_dma_setup() -- Complete ---------\n"); 1822 codec_dbg(codec, "-- dsp_dma_setup() -- Complete ---------\n");
1824 1823
1825 return 0; 1824 return 0;
1826} 1825}
@@ -1834,17 +1833,17 @@ static int dsp_dma_start(struct hda_codec *codec,
1834 unsigned int reg = 0; 1833 unsigned int reg = 0;
1835 int status = 0; 1834 int status = 0;
1836 1835
1837 snd_printdd(KERN_INFO "-- dsp_dma_start() -- Begin ---------\n"); 1836 codec_dbg(codec, "-- dsp_dma_start() -- Begin ---------\n");
1838 1837
1839 if (ovly) { 1838 if (ovly) {
1840 status = chipio_read(codec, 1839 status = chipio_read(codec,
1841 DSPDMAC_CHNLSTART_INST_OFFSET, &reg); 1840 DSPDMAC_CHNLSTART_INST_OFFSET, &reg);
1842 1841
1843 if (status < 0) { 1842 if (status < 0) {
1844 snd_printdd(KERN_ERR "read CHNLSTART reg fail\n"); 1843 codec_dbg(codec, "read CHNLSTART reg fail\n");
1845 return status; 1844 return status;
1846 } 1845 }
1847 snd_printdd(KERN_INFO "-- dsp_dma_start() Read CHNLSTART\n"); 1846 codec_dbg(codec, "-- dsp_dma_start() Read CHNLSTART\n");
1848 1847
1849 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK | 1848 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
1850 DSPDMAC_CHNLSTART_DIS_MASK); 1849 DSPDMAC_CHNLSTART_DIS_MASK);
@@ -1853,10 +1852,10 @@ static int dsp_dma_start(struct hda_codec *codec,
1853 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET, 1852 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
1854 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT))); 1853 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_EN_LOBIT)));
1855 if (status < 0) { 1854 if (status < 0) {
1856 snd_printdd(KERN_ERR "write CHNLSTART reg fail\n"); 1855 codec_dbg(codec, "write CHNLSTART reg fail\n");
1857 return status; 1856 return status;
1858 } 1857 }
1859 snd_printdd(KERN_INFO "-- dsp_dma_start() -- Complete ---------\n"); 1858 codec_dbg(codec, "-- dsp_dma_start() -- Complete ---------\n");
1860 1859
1861 return status; 1860 return status;
1862} 1861}
@@ -1870,17 +1869,17 @@ static int dsp_dma_stop(struct hda_codec *codec,
1870 unsigned int reg = 0; 1869 unsigned int reg = 0;
1871 int status = 0; 1870 int status = 0;
1872 1871
1873 snd_printdd(KERN_INFO "-- dsp_dma_stop() -- Begin ---------\n"); 1872 codec_dbg(codec, "-- dsp_dma_stop() -- Begin ---------\n");
1874 1873
1875 if (ovly) { 1874 if (ovly) {
1876 status = chipio_read(codec, 1875 status = chipio_read(codec,
1877 DSPDMAC_CHNLSTART_INST_OFFSET, &reg); 1876 DSPDMAC_CHNLSTART_INST_OFFSET, &reg);
1878 1877
1879 if (status < 0) { 1878 if (status < 0) {
1880 snd_printdd(KERN_ERR "read CHNLSTART reg fail\n"); 1879 codec_dbg(codec, "read CHNLSTART reg fail\n");
1881 return status; 1880 return status;
1882 } 1881 }
1883 snd_printdd(KERN_INFO "-- dsp_dma_stop() Read CHNLSTART\n"); 1882 codec_dbg(codec, "-- dsp_dma_stop() Read CHNLSTART\n");
1884 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK | 1883 reg &= ~(DSPDMAC_CHNLSTART_EN_MASK |
1885 DSPDMAC_CHNLSTART_DIS_MASK); 1884 DSPDMAC_CHNLSTART_DIS_MASK);
1886 } 1885 }
@@ -1888,10 +1887,10 @@ static int dsp_dma_stop(struct hda_codec *codec,
1888 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET, 1887 status = chipio_write(codec, DSPDMAC_CHNLSTART_INST_OFFSET,
1889 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT))); 1888 reg | (1 << (dma_chan + DSPDMAC_CHNLSTART_DIS_LOBIT)));
1890 if (status < 0) { 1889 if (status < 0) {
1891 snd_printdd(KERN_ERR "write CHNLSTART reg fail\n"); 1890 codec_dbg(codec, "write CHNLSTART reg fail\n");
1892 return status; 1891 return status;
1893 } 1892 }
1894 snd_printdd(KERN_INFO "-- dsp_dma_stop() -- Complete ---------\n"); 1893 codec_dbg(codec, "-- dsp_dma_stop() -- Complete ---------\n");
1895 1894
1896 return status; 1895 return status;
1897} 1896}
@@ -1974,17 +1973,17 @@ static int dsp_allocate_ports(struct hda_codec *codec,
1974{ 1973{
1975 int status; 1974 int status;
1976 1975
1977 snd_printdd(KERN_INFO " dsp_allocate_ports() -- begin\n"); 1976 codec_dbg(codec, " dsp_allocate_ports() -- begin\n");
1978 1977
1979 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) { 1978 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
1980 snd_printdd(KERN_ERR "bad rate multiple\n"); 1979 codec_dbg(codec, "bad rate multiple\n");
1981 return -EINVAL; 1980 return -EINVAL;
1982 } 1981 }
1983 1982
1984 status = dsp_allocate_router_ports(codec, num_chans, 1983 status = dsp_allocate_router_ports(codec, num_chans,
1985 rate_multi, 0, port_map); 1984 rate_multi, 0, port_map);
1986 1985
1987 snd_printdd(KERN_INFO " dsp_allocate_ports() -- complete\n"); 1986 codec_dbg(codec, " dsp_allocate_ports() -- complete\n");
1988 1987
1989 return status; 1988 return status;
1990} 1989}
@@ -2001,7 +2000,7 @@ static int dsp_allocate_ports_format(struct hda_codec *codec,
2001 unsigned int rate_multi = sample_rate_mul / sample_rate_div; 2000 unsigned int rate_multi = sample_rate_mul / sample_rate_div;
2002 2001
2003 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) { 2002 if ((rate_multi != 1) && (rate_multi != 2) && (rate_multi != 4)) {
2004 snd_printdd(KERN_ERR "bad rate multiple\n"); 2003 codec_dbg(codec, "bad rate multiple\n");
2005 return -EINVAL; 2004 return -EINVAL;
2006 } 2005 }
2007 2006
@@ -2019,14 +2018,14 @@ static int dsp_free_ports(struct hda_codec *codec)
2019{ 2018{
2020 int status; 2019 int status;
2021 2020
2022 snd_printdd(KERN_INFO " dsp_free_ports() -- begin\n"); 2021 codec_dbg(codec, " dsp_free_ports() -- begin\n");
2023 2022
2024 status = dsp_free_router_ports(codec); 2023 status = dsp_free_router_ports(codec);
2025 if (status < 0) { 2024 if (status < 0) {
2026 snd_printdd(KERN_ERR "free router ports fail\n"); 2025 codec_dbg(codec, "free router ports fail\n");
2027 return status; 2026 return status;
2028 } 2027 }
2029 snd_printdd(KERN_INFO " dsp_free_ports() -- complete\n"); 2028 codec_dbg(codec, " dsp_free_ports() -- complete\n");
2030 2029
2031 return status; 2030 return status;
2032} 2031}
@@ -2092,8 +2091,6 @@ static int dma_set_state(struct dma_engine *dma, enum dma_state state)
2092{ 2091{
2093 bool cmd; 2092 bool cmd;
2094 2093
2095 snd_printdd("dma_set_state state=%d\n", state);
2096
2097 switch (state) { 2094 switch (state) {
2098 case DMA_STATE_STOP: 2095 case DMA_STATE_STOP:
2099 cmd = false; 2096 cmd = false;
@@ -2196,7 +2193,7 @@ static int dspxfr_hci_write(struct hda_codec *codec,
2196 unsigned int count; 2193 unsigned int count;
2197 2194
2198 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) { 2195 if (fls == NULL || fls->chip_addr != g_chip_addr_magic_value) {
2199 snd_printdd(KERN_ERR "hci_write invalid params\n"); 2196 codec_dbg(codec, "hci_write invalid params\n");
2200 return -EINVAL; 2197 return -EINVAL;
2201 } 2198 }
2202 2199
@@ -2205,7 +2202,7 @@ static int dspxfr_hci_write(struct hda_codec *codec,
2205 while (count >= 2) { 2202 while (count >= 2) {
2206 status = chipio_write(codec, data[0], data[1]); 2203 status = chipio_write(codec, data[0], data[1]);
2207 if (status < 0) { 2204 if (status < 0) {
2208 snd_printdd(KERN_ERR "hci_write chipio failed\n"); 2205 codec_dbg(codec, "hci_write chipio failed\n");
2209 return status; 2206 return status;
2210 } 2207 }
2211 count -= 2; 2208 count -= 2;
@@ -2265,12 +2262,12 @@ static int dspxfr_one_seg(struct hda_codec *codec,
2265 } 2262 }
2266 2263
2267 if (hci_write && (!fls || is_last(fls))) { 2264 if (hci_write && (!fls || is_last(fls))) {
2268 snd_printdd("hci_write\n"); 2265 codec_dbg(codec, "hci_write\n");
2269 return dspxfr_hci_write(codec, hci_write); 2266 return dspxfr_hci_write(codec, hci_write);
2270 } 2267 }
2271 2268
2272 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) { 2269 if (fls == NULL || dma_engine == NULL || port_map_mask == 0) {
2273 snd_printdd("Invalid Params\n"); 2270 codec_dbg(codec, "Invalid Params\n");
2274 return -EINVAL; 2271 return -EINVAL;
2275 } 2272 }
2276 2273
@@ -2286,7 +2283,7 @@ static int dspxfr_one_seg(struct hda_codec *codec,
2286 if (!UC_RANGE(chip_addx, words_to_write) && 2283 if (!UC_RANGE(chip_addx, words_to_write) &&
2287 !X_RANGE_ALL(chip_addx, words_to_write) && 2284 !X_RANGE_ALL(chip_addx, words_to_write) &&
2288 !Y_RANGE_ALL(chip_addx, words_to_write)) { 2285 !Y_RANGE_ALL(chip_addx, words_to_write)) {
2289 snd_printdd("Invalid chip_addx Params\n"); 2286 codec_dbg(codec, "Invalid chip_addx Params\n");
2290 return -EINVAL; 2287 return -EINVAL;
2291 } 2288 }
2292 2289
@@ -2296,7 +2293,7 @@ static int dspxfr_one_seg(struct hda_codec *codec,
2296 buffer_addx = dma_get_buffer_addr(dma_engine); 2293 buffer_addx = dma_get_buffer_addr(dma_engine);
2297 2294
2298 if (buffer_addx == NULL) { 2295 if (buffer_addx == NULL) {
2299 snd_printdd(KERN_ERR "dma_engine buffer NULL\n"); 2296 codec_dbg(codec, "dma_engine buffer NULL\n");
2300 return -EINVAL; 2297 return -EINVAL;
2301 } 2298 }
2302 2299
@@ -2309,7 +2306,7 @@ static int dspxfr_one_seg(struct hda_codec *codec,
2309 (num_chans * sample_rate_mul / sample_rate_div)); 2306 (num_chans * sample_rate_mul / sample_rate_div));
2310 2307
2311 if (hda_frame_size_words == 0) { 2308 if (hda_frame_size_words == 0) {
2312 snd_printdd(KERN_ERR "frmsz zero\n"); 2309 codec_dbg(codec, "frmsz zero\n");
2313 return -EINVAL; 2310 return -EINVAL;
2314 } 2311 }
2315 2312
@@ -2317,14 +2314,14 @@ static int dspxfr_one_seg(struct hda_codec *codec,
2317 (unsigned int)(UC_RANGE(chip_addx, 1) ? 2314 (unsigned int)(UC_RANGE(chip_addx, 1) ?
2318 65536 : 32768)); 2315 65536 : 32768));
2319 buffer_size_words -= buffer_size_words % hda_frame_size_words; 2316 buffer_size_words -= buffer_size_words % hda_frame_size_words;
2320 snd_printdd( 2317 codec_dbg(codec,
2321 "chpadr=0x%08x frmsz=%u nchan=%u " 2318 "chpadr=0x%08x frmsz=%u nchan=%u "
2322 "rate_mul=%u div=%u bufsz=%u\n", 2319 "rate_mul=%u div=%u bufsz=%u\n",
2323 chip_addx, hda_frame_size_words, num_chans, 2320 chip_addx, hda_frame_size_words, num_chans,
2324 sample_rate_mul, sample_rate_div, buffer_size_words); 2321 sample_rate_mul, sample_rate_div, buffer_size_words);
2325 2322
2326 if (buffer_size_words < hda_frame_size_words) { 2323 if (buffer_size_words < hda_frame_size_words) {
2327 snd_printdd(KERN_ERR "dspxfr_one_seg:failed\n"); 2324 codec_dbg(codec, "dspxfr_one_seg:failed\n");
2328 return -EINVAL; 2325 return -EINVAL;
2329 } 2326 }
2330 2327
@@ -2338,7 +2335,7 @@ static int dspxfr_one_seg(struct hda_codec *codec,
2338 2335
2339 while (words_to_write != 0) { 2336 while (words_to_write != 0) {
2340 run_size_words = min(buffer_size_words, words_to_write); 2337 run_size_words = min(buffer_size_words, words_to_write);
2341 snd_printdd("dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n", 2338 codec_dbg(codec, "dspxfr (seg loop)cnt=%u rs=%u remainder=%u\n",
2342 words_to_write, run_size_words, remainder_words); 2339 words_to_write, run_size_words, remainder_words);
2343 dma_xfer(dma_engine, data, run_size_words*sizeof(u32)); 2340 dma_xfer(dma_engine, data, run_size_words*sizeof(u32));
2344 if (!comm_dma_setup_done) { 2341 if (!comm_dma_setup_done) {
@@ -2360,7 +2357,7 @@ static int dspxfr_one_seg(struct hda_codec *codec,
2360 if (status < 0) 2357 if (status < 0)
2361 return status; 2358 return status;
2362 if (!dsp_is_dma_active(codec, dma_chan)) { 2359 if (!dsp_is_dma_active(codec, dma_chan)) {
2363 snd_printdd(KERN_ERR "dspxfr:DMA did not start\n"); 2360 codec_dbg(codec, "dspxfr:DMA did not start\n");
2364 return -EIO; 2361 return -EIO;
2365 } 2362 }
2366 status = dma_set_state(dma_engine, DMA_STATE_RUN); 2363 status = dma_set_state(dma_engine, DMA_STATE_RUN);
@@ -2392,7 +2389,7 @@ static int dspxfr_one_seg(struct hda_codec *codec,
2392 if (dma_active) 2389 if (dma_active)
2393 break; 2390 break;
2394 2391
2395 snd_printdd(KERN_INFO "+++++ DMA complete\n"); 2392 codec_dbg(codec, "+++++ DMA complete\n");
2396 dma_set_state(dma_engine, DMA_STATE_STOP); 2393 dma_set_state(dma_engine, DMA_STATE_STOP);
2397 status = dma_reset(dma_engine); 2394 status = dma_reset(dma_engine);
2398 2395
@@ -2466,7 +2463,7 @@ static int dspxfr_image(struct hda_codec *codec,
2466 hda_format, &response); 2463 hda_format, &response);
2467 2464
2468 if (status < 0) { 2465 if (status < 0) {
2469 snd_printdd(KERN_ERR "set converter format fail\n"); 2466 codec_dbg(codec, "set converter format fail\n");
2470 goto exit; 2467 goto exit;
2471 } 2468 }
2472 2469
@@ -2481,7 +2478,7 @@ static int dspxfr_image(struct hda_codec *codec,
2481 if (ovly) { 2478 if (ovly) {
2482 status = dspio_alloc_dma_chan(codec, &dma_chan); 2479 status = dspio_alloc_dma_chan(codec, &dma_chan);
2483 if (status < 0) { 2480 if (status < 0) {
2484 snd_printdd(KERN_ERR "alloc dmachan fail\n"); 2481 codec_dbg(codec, "alloc dmachan fail\n");
2485 dma_chan = INVALID_DMA_CHANNEL; 2482 dma_chan = INVALID_DMA_CHANNEL;
2486 goto exit; 2483 goto exit;
2487 } 2484 }
@@ -2491,7 +2488,7 @@ static int dspxfr_image(struct hda_codec *codec,
2491 status = dsp_allocate_ports_format(codec, hda_format, 2488 status = dsp_allocate_ports_format(codec, hda_format,
2492 &port_map_mask); 2489 &port_map_mask);
2493 if (status < 0) { 2490 if (status < 0) {
2494 snd_printdd(KERN_ERR "alloc ports fail\n"); 2491 codec_dbg(codec, "alloc ports fail\n");
2495 goto exit; 2492 goto exit;
2496 } 2493 }
2497 2494
@@ -2499,13 +2496,13 @@ static int dspxfr_image(struct hda_codec *codec,
2499 status = codec_set_converter_stream_channel(codec, 2496 status = codec_set_converter_stream_channel(codec,
2500 WIDGET_CHIP_CTRL, stream_id, 0, &response); 2497 WIDGET_CHIP_CTRL, stream_id, 0, &response);
2501 if (status < 0) { 2498 if (status < 0) {
2502 snd_printdd(KERN_ERR "set stream chan fail\n"); 2499 codec_dbg(codec, "set stream chan fail\n");
2503 goto exit; 2500 goto exit;
2504 } 2501 }
2505 2502
2506 while ((fls_data != NULL) && !is_last(fls_data)) { 2503 while ((fls_data != NULL) && !is_last(fls_data)) {
2507 if (!is_valid(fls_data)) { 2504 if (!is_valid(fls_data)) {
2508 snd_printdd(KERN_ERR "FLS check fail\n"); 2505 codec_dbg(codec, "FLS check fail\n");
2509 status = -EINVAL; 2506 status = -EINVAL;
2510 goto exit; 2507 goto exit;
2511 } 2508 }
@@ -2548,7 +2545,7 @@ exit:
2548 */ 2545 */
2549static void dspload_post_setup(struct hda_codec *codec) 2546static void dspload_post_setup(struct hda_codec *codec)
2550{ 2547{
2551 snd_printdd(KERN_INFO "---- dspload_post_setup ------\n"); 2548 codec_dbg(codec, "---- dspload_post_setup ------\n");
2552 2549
2553 /*set DSP speaker to 2.0 configuration*/ 2550 /*set DSP speaker to 2.0 configuration*/
2554 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080); 2551 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x18), 0x08080080);
@@ -2586,7 +2583,7 @@ static int dspload_image(struct hda_codec *codec,
2586 unsigned int sample_rate; 2583 unsigned int sample_rate;
2587 unsigned short channels; 2584 unsigned short channels;
2588 2585
2589 snd_printdd(KERN_INFO "---- dspload_image begin ------\n"); 2586 codec_dbg(codec, "---- dspload_image begin ------\n");
2590 if (router_chans == 0) { 2587 if (router_chans == 0) {
2591 if (!ovly) 2588 if (!ovly)
2592 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS; 2589 router_chans = DMA_TRANSFER_FRAME_SIZE_NWORDS;
@@ -2603,27 +2600,27 @@ static int dspload_image(struct hda_codec *codec,
2603 } 2600 }
2604 2601
2605 do { 2602 do {
2606 snd_printdd(KERN_INFO "Ready to program DMA\n"); 2603 codec_dbg(codec, "Ready to program DMA\n");
2607 if (!ovly) 2604 if (!ovly)
2608 status = dsp_reset(codec); 2605 status = dsp_reset(codec);
2609 2606
2610 if (status < 0) 2607 if (status < 0)
2611 break; 2608 break;
2612 2609
2613 snd_printdd(KERN_INFO "dsp_reset() complete\n"); 2610 codec_dbg(codec, "dsp_reset() complete\n");
2614 status = dspxfr_image(codec, fls, reloc, sample_rate, channels, 2611 status = dspxfr_image(codec, fls, reloc, sample_rate, channels,
2615 ovly); 2612 ovly);
2616 2613
2617 if (status < 0) 2614 if (status < 0)
2618 break; 2615 break;
2619 2616
2620 snd_printdd(KERN_INFO "dspxfr_image() complete\n"); 2617 codec_dbg(codec, "dspxfr_image() complete\n");
2621 if (autostart && !ovly) { 2618 if (autostart && !ovly) {
2622 dspload_post_setup(codec); 2619 dspload_post_setup(codec);
2623 status = dsp_set_run_state(codec); 2620 status = dsp_set_run_state(codec);
2624 } 2621 }
2625 2622
2626 snd_printdd(KERN_INFO "LOAD FINISHED\n"); 2623 codec_dbg(codec, "LOAD FINISHED\n");
2627 } while (0); 2624 } while (0);
2628 2625
2629 return status; 2626 return status;
@@ -3132,7 +3129,7 @@ static int ca0132_select_out(struct hda_codec *codec)
3132 unsigned int tmp; 3129 unsigned int tmp;
3133 int err; 3130 int err;
3134 3131
3135 snd_printdd(KERN_INFO "ca0132_select_out\n"); 3132 codec_dbg(codec, "ca0132_select_out\n");
3136 3133
3137 snd_hda_power_up(codec); 3134 snd_hda_power_up(codec);
3138 3135
@@ -3150,7 +3147,7 @@ static int ca0132_select_out(struct hda_codec *codec)
3150 spec->cur_out_type = SPEAKER_OUT; 3147 spec->cur_out_type = SPEAKER_OUT;
3151 3148
3152 if (spec->cur_out_type == SPEAKER_OUT) { 3149 if (spec->cur_out_type == SPEAKER_OUT) {
3153 snd_printdd(KERN_INFO "ca0132_select_out speaker\n"); 3150 codec_dbg(codec, "ca0132_select_out speaker\n");
3154 /*speaker out config*/ 3151 /*speaker out config*/
3155 tmp = FLOAT_ONE; 3152 tmp = FLOAT_ONE;
3156 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp); 3153 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
@@ -3183,7 +3180,7 @@ static int ca0132_select_out(struct hda_codec *codec)
3183 snd_hda_set_pin_ctl(codec, spec->out_pins[0], 3180 snd_hda_set_pin_ctl(codec, spec->out_pins[0],
3184 pin_ctl | PIN_OUT); 3181 pin_ctl | PIN_OUT);
3185 } else { 3182 } else {
3186 snd_printdd(KERN_INFO "ca0132_select_out hp\n"); 3183 codec_dbg(codec, "ca0132_select_out hp\n");
3187 /*headphone out config*/ 3184 /*headphone out config*/
3188 tmp = FLOAT_ZERO; 3185 tmp = FLOAT_ZERO;
3189 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp); 3186 err = dspio_set_uint_param(codec, 0x80, 0x04, tmp);
@@ -3288,7 +3285,7 @@ static int ca0132_select_mic(struct hda_codec *codec)
3288 int jack_present; 3285 int jack_present;
3289 int auto_jack; 3286 int auto_jack;
3290 3287
3291 snd_printdd(KERN_INFO "ca0132_select_mic\n"); 3288 codec_dbg(codec, "ca0132_select_mic\n");
3292 3289
3293 snd_hda_power_up(codec); 3290 snd_hda_power_up(codec);
3294 3291
@@ -3410,7 +3407,7 @@ static int ca0132_effects_set(struct hda_codec *codec, hda_nid_t nid, long val)
3410 val = 0; 3407 val = 0;
3411 } 3408 }
3412 3409
3413 snd_printdd(KERN_INFO "ca0132_effect_set: nid=0x%x, val=%ld\n", 3410 codec_dbg(codec, "ca0132_effect_set: nid=0x%x, val=%ld\n",
3414 nid, val); 3411 nid, val);
3415 3412
3416 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE; 3413 on = (val == 0) ? FLOAT_ZERO : FLOAT_ONE;
@@ -3432,7 +3429,7 @@ static int ca0132_pe_switch_set(struct hda_codec *codec)
3432 hda_nid_t nid; 3429 hda_nid_t nid;
3433 int i, ret = 0; 3430 int i, ret = 0;
3434 3431
3435 snd_printdd(KERN_INFO "ca0132_pe_switch_set: val=%ld\n", 3432 codec_dbg(codec, "ca0132_pe_switch_set: val=%ld\n",
3436 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]); 3433 spec->effects_switch[PLAY_ENHANCEMENT - EFFECT_START_NID]);
3437 3434
3438 i = OUT_EFFECT_START_NID - EFFECT_START_NID; 3435 i = OUT_EFFECT_START_NID - EFFECT_START_NID;
@@ -3478,7 +3475,7 @@ static int ca0132_cvoice_switch_set(struct hda_codec *codec)
3478 int i, ret = 0; 3475 int i, ret = 0;
3479 unsigned int oldval; 3476 unsigned int oldval;
3480 3477
3481 snd_printdd(KERN_INFO "ca0132_cvoice_switch_set: val=%ld\n", 3478 codec_dbg(codec, "ca0132_cvoice_switch_set: val=%ld\n",
3482 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]); 3479 spec->effects_switch[CRYSTAL_VOICE - EFFECT_START_NID]);
3483 3480
3484 i = IN_EFFECT_START_NID - EFFECT_START_NID; 3481 i = IN_EFFECT_START_NID - EFFECT_START_NID;
@@ -3608,7 +3605,7 @@ static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
3608 if (sel >= items) 3605 if (sel >= items)
3609 return 0; 3606 return 0;
3610 3607
3611 snd_printdd(KERN_INFO "ca0132_voicefx_put: sel=%d, preset=%s\n", 3608 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
3612 sel, ca0132_voicefx_presets[sel].name); 3609 sel, ca0132_voicefx_presets[sel].name);
3613 3610
3614 /* 3611 /*
@@ -3679,7 +3676,7 @@ static int ca0132_switch_put(struct snd_kcontrol *kcontrol,
3679 long *valp = ucontrol->value.integer.value; 3676 long *valp = ucontrol->value.integer.value;
3680 int changed = 1; 3677 int changed = 1;
3681 3678
3682 snd_printdd(KERN_INFO "ca0132_switch_put: nid=0x%x, val=%ld\n", 3679 codec_dbg(codec, "ca0132_switch_put: nid=0x%x, val=%ld\n",
3683 nid, *valp); 3680 nid, *valp);
3684 3681
3685 snd_hda_power_up(codec); 3682 snd_hda_power_up(codec);
@@ -4142,7 +4139,7 @@ static void ca0132_set_dmic(struct hda_codec *codec, int enable)
4142 u8 val; 4139 u8 val;
4143 unsigned int oldval; 4140 unsigned int oldval;
4144 4141
4145 snd_printdd(KERN_INFO "ca0132_set_dmic: enable=%d\n", enable); 4142 codec_dbg(codec, "ca0132_set_dmic: enable=%d\n", enable);
4146 4143
4147 oldval = stop_mic1(codec); 4144 oldval = stop_mic1(codec);
4148 ca0132_set_vipsource(codec, 0); 4145 ca0132_set_vipsource(codec, 0);
@@ -4250,7 +4247,7 @@ static void ca0132_refresh_widget_caps(struct hda_codec *codec)
4250 int i; 4247 int i;
4251 hda_nid_t nid; 4248 hda_nid_t nid;
4252 4249
4253 snd_printdd(KERN_INFO "ca0132_refresh_widget_caps.\n"); 4250 codec_dbg(codec, "ca0132_refresh_widget_caps.\n");
4254 nid = codec->start_nid; 4251 nid = codec->start_nid;
4255 for (i = 0; i < codec->num_nodes; i++, nid++) 4252 for (i = 0; i < codec->num_nodes; i++, nid++)
4256 codec->wcaps[i] = snd_hda_param_read(codec, nid, 4253 codec->wcaps[i] = snd_hda_param_read(codec, nid,
@@ -4394,7 +4391,7 @@ static void ca0132_process_dsp_response(struct hda_codec *codec)
4394{ 4391{
4395 struct ca0132_spec *spec = codec->spec; 4392 struct ca0132_spec *spec = codec->spec;
4396 4393
4397 snd_printdd(KERN_INFO "ca0132_process_dsp_response\n"); 4394 codec_dbg(codec, "ca0132_process_dsp_response\n");
4398 if (spec->wait_scp) { 4395 if (spec->wait_scp) {
4399 if (dspio_get_response_data(codec) >= 0) 4396 if (dspio_get_response_data(codec) >= 0)
4400 spec->wait_scp = 0; 4397 spec->wait_scp = 0;
@@ -4413,7 +4410,7 @@ static void ca0132_unsol_event(struct hda_codec *codec, unsigned int res)
4413 res = snd_hda_jack_get_action(codec, 4410 res = snd_hda_jack_get_action(codec,
4414 (res >> AC_UNSOL_RES_TAG_SHIFT) & 0x3f); 4411 (res >> AC_UNSOL_RES_TAG_SHIFT) & 0x3f);
4415 4412
4416 snd_printdd(KERN_INFO "snd_hda_jack_get_action: 0x%x\n", res); 4413 codec_dbg(codec, "snd_hda_jack_get_action: 0x%x\n", res);
4417 4414
4418 switch (res) { 4415 switch (res) {
4419 case UNSOL_TAG_HP: 4416 case UNSOL_TAG_HP:
@@ -4658,7 +4655,7 @@ static int patch_ca0132(struct hda_codec *codec)
4658 struct ca0132_spec *spec; 4655 struct ca0132_spec *spec;
4659 int err; 4656 int err;
4660 4657
4661 snd_printdd("patch_ca0132\n"); 4658 codec_dbg(codec, "patch_ca0132\n");
4662 4659
4663 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4660 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4664 if (!spec) 4661 if (!spec)
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index fc492ac24caa..387f0b551889 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -20,7 +20,6 @@
20 20
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/pci.h>
24#include <linux/module.h> 23#include <linux/module.h>
25#include <sound/core.h> 24#include <sound/core.h>
26#include <sound/tlv.h> 25#include <sound/tlv.h>
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index 9c6ce73b03c5..061ea5965dd5 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -23,7 +23,6 @@
23 23
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <linux/module.h> 26#include <linux/module.h>
28#include <sound/core.h> 27#include <sound/core.h>
29#include "hda_codec.h" 28#include "hda_codec.h"
@@ -32,6 +31,9 @@
32#include "hda_jack.h" 31#include "hda_jack.h"
33#include "hda_generic.h" 32#include "hda_generic.h"
34 33
34#undef ENABLE_CMI_STATIC_QUIRKS
35
36#ifdef ENABLE_CMI_STATIC_QUIRKS
35#define NUM_PINS 11 37#define NUM_PINS 11
36 38
37 39
@@ -45,10 +47,12 @@ enum {
45 CMI_AUTO, /* let driver guess it */ 47 CMI_AUTO, /* let driver guess it */
46 CMI_MODELS 48 CMI_MODELS
47}; 49};
50#endif /* ENABLE_CMI_STATIC_QUIRKS */
48 51
49struct cmi_spec { 52struct cmi_spec {
50 struct hda_gen_spec gen; 53 struct hda_gen_spec gen;
51 54
55#ifdef ENABLE_CMI_STATIC_QUIRKS
52 /* below are only for static models */ 56 /* below are only for static models */
53 57
54 int board_config; 58 int board_config;
@@ -81,8 +85,10 @@ struct cmi_spec {
81 85
82 /* multichannel pins */ 86 /* multichannel pins */
83 struct hda_verb multi_init[9]; /* 2 verbs for each pin + terminator */ 87 struct hda_verb multi_init[9]; /* 2 verbs for each pin + terminator */
88#endif /* ENABLE_CMI_STATIC_QUIRKS */
84}; 89};
85 90
91#ifdef ENABLE_CMI_STATIC_QUIRKS
86/* 92/*
87 * input MUX 93 * input MUX
88 */ 94 */
@@ -566,6 +572,7 @@ static const struct hda_codec_ops cmi9880_patch_ops = {
566 .init = cmi9880_init, 572 .init = cmi9880_init,
567 .free = cmi9880_free, 573 .free = cmi9880_free,
568}; 574};
575#endif /* ENABLE_CMI_STATIC_QUIRKS */
569 576
570/* 577/*
571 * stuff for auto-parser 578 * stuff for auto-parser
@@ -588,15 +595,20 @@ static int cmi_parse_auto_config(struct hda_codec *codec)
588 595
589 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0); 596 err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
590 if (err < 0) 597 if (err < 0)
591 return err; 598 goto error;
592 err = snd_hda_gen_parse_auto_config(codec, cfg); 599 err = snd_hda_gen_parse_auto_config(codec, cfg);
593 if (err < 0) 600 if (err < 0)
594 return err; 601 goto error;
595 602
596 codec->patch_ops = cmi_auto_patch_ops; 603 codec->patch_ops = cmi_auto_patch_ops;
597 return 0; 604 return 0;
605
606 error:
607 snd_hda_gen_free(codec);
608 return err;
598} 609}
599 610
611
600static int patch_cmi9880(struct hda_codec *codec) 612static int patch_cmi9880(struct hda_codec *codec)
601{ 613{
602 struct cmi_spec *spec; 614 struct cmi_spec *spec;
@@ -606,23 +618,18 @@ static int patch_cmi9880(struct hda_codec *codec)
606 return -ENOMEM; 618 return -ENOMEM;
607 619
608 codec->spec = spec; 620 codec->spec = spec;
621#ifdef ENABLE_CMI_STATIC_QUIRKS
609 spec->board_config = snd_hda_check_board_config(codec, CMI_MODELS, 622 spec->board_config = snd_hda_check_board_config(codec, CMI_MODELS,
610 cmi9880_models, 623 cmi9880_models,
611 cmi9880_cfg_tbl); 624 cmi9880_cfg_tbl);
612 if (spec->board_config < 0) { 625 if (spec->board_config < 0) {
613 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 626 codec_dbg(codec, "%s: BIOS auto-probing.\n",
614 codec->chip_name); 627 codec->chip_name);
615 spec->board_config = CMI_AUTO; /* try everything */ 628 spec->board_config = CMI_AUTO; /* try everything */
616 } 629 }
617 630
618 if (spec->board_config == CMI_AUTO) { 631 if (spec->board_config == CMI_AUTO)
619 int err = cmi_parse_auto_config(codec); 632 return cmi_parse_auto_config(codec);
620 if (err < 0) {
621 snd_hda_gen_free(codec);
622 return err;
623 }
624 return 0;
625 }
626 633
627 /* copy default DAC NIDs */ 634 /* copy default DAC NIDs */
628 memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids)); 635 memcpy(spec->dac_nids, cmi9880_dac_nids, sizeof(spec->dac_nids));
@@ -669,6 +676,9 @@ static int patch_cmi9880(struct hda_codec *codec)
669 codec->patch_ops = cmi9880_patch_ops; 676 codec->patch_ops = cmi9880_patch_ops;
670 677
671 return 0; 678 return 0;
679#else
680 return cmi_parse_auto_config(codec);
681#endif
672} 682}
673 683
674/* 684/*
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index bcf91bea3317..1dc7e974f3b1 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/pci.h>
27#include <linux/module.h> 26#include <linux/module.h>
28#include <sound/core.h> 27#include <sound/core.h>
29#include <sound/jack.h> 28#include <sound/jack.h>
@@ -35,7 +34,7 @@
35#include "hda_jack.h" 34#include "hda_jack.h"
36#include "hda_generic.h" 35#include "hda_generic.h"
37 36
38#define ENABLE_CXT_STATIC_QUIRKS 37#undef ENABLE_CXT_STATIC_QUIRKS
39 38
40#define CXT_PIN_DIR_IN 0x00 39#define CXT_PIN_DIR_IN 0x00
41#define CXT_PIN_DIR_OUT 0x01 40#define CXT_PIN_DIR_OUT 0x01
@@ -68,6 +67,12 @@ struct conexant_spec {
68 67
69 unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */ 68 unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
70 69
70 /* OPLC XO specific */
71 bool recording;
72 bool dc_enable;
73 unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */
74 struct nid_path *dc_mode_path;
75
71#ifdef ENABLE_CXT_STATIC_QUIRKS 76#ifdef ENABLE_CXT_STATIC_QUIRKS
72 const struct snd_kcontrol_new *mixers[5]; 77 const struct snd_kcontrol_new *mixers[5];
73 int num_mixers; 78 int num_mixers;
@@ -123,19 +128,6 @@ struct conexant_spec {
123 unsigned int hp_laptop:1; 128 unsigned int hp_laptop:1;
124 unsigned int asus:1; 129 unsigned int asus:1;
125 130
126 unsigned int ext_mic_present;
127 unsigned int recording;
128 void (*capture_prepare)(struct hda_codec *codec);
129 void (*capture_cleanup)(struct hda_codec *codec);
130
131 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
132 * through the microphone jack.
133 * When the user enables this through a mixer switch, both internal and
134 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
135 * we also allow the bias to be configured through a separate mixer
136 * control. */
137 unsigned int dc_enable;
138 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
139 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 131 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
140#endif /* ENABLE_CXT_STATIC_QUIRKS */ 132#endif /* ENABLE_CXT_STATIC_QUIRKS */
141}; 133};
@@ -253,8 +245,6 @@ static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
253 struct snd_pcm_substream *substream) 245 struct snd_pcm_substream *substream)
254{ 246{
255 struct conexant_spec *spec = codec->spec; 247 struct conexant_spec *spec = codec->spec;
256 if (spec->capture_prepare)
257 spec->capture_prepare(codec);
258 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 248 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
259 stream_tag, 0, format); 249 stream_tag, 0, format);
260 return 0; 250 return 0;
@@ -266,8 +256,6 @@ static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
266{ 256{
267 struct conexant_spec *spec = codec->spec; 257 struct conexant_spec *spec = codec->spec;
268 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 258 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
269 if (spec->capture_cleanup)
270 spec->capture_cleanup(codec);
271 return 0; 259 return 0;
272} 260}
273 261
@@ -457,9 +445,7 @@ static int conexant_init(struct hda_codec *codec)
457 445
458static void conexant_free(struct hda_codec *codec) 446static void conexant_free(struct hda_codec *codec)
459{ 447{
460 struct conexant_spec *spec = codec->spec; 448 kfree(codec->spec);
461 snd_hda_detach_beep_device(codec);
462 kfree(spec);
463} 449}
464 450
465static const struct snd_kcontrol_new cxt_capture_mixers[] = { 451static const struct snd_kcontrol_new cxt_capture_mixers[] = {
@@ -673,14 +659,6 @@ static const struct hda_input_mux cxt5045_capture_source_benq = {
673 } 659 }
674}; 660};
675 661
676static const struct hda_input_mux cxt5045_capture_source_hp530 = {
677 .num_items = 2,
678 .items = {
679 { "Mic", 0x1 },
680 { "Internal Mic", 0x2 },
681 }
682};
683
684/* turn on/off EAPD (+ mute HP) as a master switch */ 662/* turn on/off EAPD (+ mute HP) as a master switch */
685static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 663static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_value *ucontrol) 664 struct snd_ctl_elem_value *ucontrol)
@@ -796,28 +774,6 @@ static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
796 {} 774 {}
797}; 775};
798 776
799static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
800 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
801 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
802 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
803 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
804 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
805 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
806 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
807 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
808 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
809 {
810 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
811 .name = "Master Playback Switch",
812 .info = cxt_eapd_info,
813 .get = cxt_eapd_get,
814 .put = cxt5045_hp_master_sw_put,
815 .private_value = 0x10,
816 },
817
818 {}
819};
820
821static const struct hda_verb cxt5045_init_verbs[] = { 777static const struct hda_verb cxt5045_init_verbs[] = {
822 /* Line in, Mic */ 778 /* Line in, Mic */
823 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 779 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
@@ -1000,7 +956,6 @@ enum {
1000 CXT5045_LAPTOP_MICSENSE, 956 CXT5045_LAPTOP_MICSENSE,
1001 CXT5045_LAPTOP_HPMICSENSE, 957 CXT5045_LAPTOP_HPMICSENSE,
1002 CXT5045_BENQ, 958 CXT5045_BENQ,
1003 CXT5045_LAPTOP_HP530,
1004#ifdef CONFIG_SND_DEBUG 959#ifdef CONFIG_SND_DEBUG
1005 CXT5045_TEST, 960 CXT5045_TEST,
1006#endif 961#endif
@@ -1013,7 +968,6 @@ static const char * const cxt5045_models[CXT5045_MODELS] = {
1013 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 968 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
1014 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 969 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
1015 [CXT5045_BENQ] = "benq", 970 [CXT5045_BENQ] = "benq",
1016 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
1017#ifdef CONFIG_SND_DEBUG 971#ifdef CONFIG_SND_DEBUG
1018 [CXT5045_TEST] = "test", 972 [CXT5045_TEST] = "test",
1019#endif 973#endif
@@ -1021,8 +975,6 @@ static const char * const cxt5045_models[CXT5045_MODELS] = {
1021}; 975};
1022 976
1023static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { 977static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1024 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1025 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1026 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 978 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1027 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 979 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
1028 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 980 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
@@ -1113,14 +1065,6 @@ static int patch_cxt5045(struct hda_codec *codec)
1113 spec->num_mixers = 2; 1065 spec->num_mixers = 2;
1114 codec->patch_ops.init = cxt5045_init; 1066 codec->patch_ops.init = cxt5045_init;
1115 break; 1067 break;
1116 case CXT5045_LAPTOP_HP530:
1117 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1118 spec->input_mux = &cxt5045_capture_source_hp530;
1119 spec->num_init_verbs = 2;
1120 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
1121 spec->mixers[0] = cxt5045_mixers_hp530;
1122 codec->patch_ops.init = cxt5045_init;
1123 break;
1124#ifdef CONFIG_SND_DEBUG 1068#ifdef CONFIG_SND_DEBUG
1125 case CXT5045_TEST: 1069 case CXT5045_TEST:
1126 spec->input_mux = &cxt5045_test_capture_source; 1070 spec->input_mux = &cxt5045_test_capture_source;
@@ -1940,11 +1884,6 @@ static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
1940static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 1884static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
1941static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 1885static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
1942 1886
1943/* OLPC's microphone port is DC coupled for use with external sensors,
1944 * therefore we use a 50% mic bias in order to center the input signal with
1945 * the DC input range of the codec. */
1946#define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1947
1948static const struct hda_channel_mode cxt5066_modes[1] = { 1887static const struct hda_channel_mode cxt5066_modes[1] = {
1949 { 2, NULL }, 1888 { 2, NULL },
1950}; 1889};
@@ -1959,7 +1898,8 @@ static void cxt5066_update_speaker(struct hda_codec *codec)
1959 struct conexant_spec *spec = codec->spec; 1898 struct conexant_spec *spec = codec->spec;
1960 unsigned int pinctl; 1899 unsigned int pinctl;
1961 1900
1962 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 1901 codec_dbg(codec,
1902 "CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
1963 spec->hp_present, spec->cur_eapd); 1903 spec->hp_present, spec->cur_eapd);
1964 1904
1965 /* Port A (HP) */ 1905 /* Port A (HP) */
@@ -1997,88 +1937,6 @@ static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1997 return 1; 1937 return 1;
1998} 1938}
1999 1939
2000static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2001 .num_items = 3,
2002 .items = {
2003 { "Off", PIN_IN },
2004 { "50%", PIN_VREF50 },
2005 { "80%", PIN_VREF80 },
2006 },
2007};
2008
2009static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2010{
2011 struct conexant_spec *spec = codec->spec;
2012 /* Even though port F is the DC input, the bias is controlled on port B.
2013 * we also leave that port as an active input (but unselected) in DC mode
2014 * just in case that is necessary to make the bias setting take effect. */
2015 return snd_hda_set_pin_ctl_cache(codec, 0x1a,
2016 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2017}
2018
2019/* OLPC defers mic widget control until when capture is started because the
2020 * microphone LED comes on as soon as these settings are put in place. if we
2021 * did this before recording, it would give the false indication that recording
2022 * is happening when it is not. */
2023static void cxt5066_olpc_select_mic(struct hda_codec *codec)
2024{
2025 struct conexant_spec *spec = codec->spec;
2026 if (!spec->recording)
2027 return;
2028
2029 if (spec->dc_enable) {
2030 /* in DC mode we ignore presence detection and just use the jack
2031 * through our special DC port */
2032 const struct hda_verb enable_dc_mode[] = {
2033 /* disble internal mic, port C */
2034 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2035
2036 /* enable DC capture, port F */
2037 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2038 {},
2039 };
2040
2041 snd_hda_sequence_write(codec, enable_dc_mode);
2042 /* port B input disabled (and bias set) through the following call */
2043 cxt5066_set_olpc_dc_bias(codec);
2044 return;
2045 }
2046
2047 /* disable DC (port F) */
2048 snd_hda_set_pin_ctl(codec, 0x1e, 0);
2049
2050 /* external mic, port B */
2051 snd_hda_set_pin_ctl(codec, 0x1a,
2052 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
2053
2054 /* internal mic, port C */
2055 snd_hda_set_pin_ctl(codec, 0x1b,
2056 spec->ext_mic_present ? 0 : PIN_VREF80);
2057}
2058
2059/* toggle input of built-in and mic jack appropriately */
2060static void cxt5066_olpc_automic(struct hda_codec *codec)
2061{
2062 struct conexant_spec *spec = codec->spec;
2063 unsigned int present;
2064
2065 if (spec->dc_enable) /* don't do presence detection in DC mode */
2066 return;
2067
2068 present = snd_hda_codec_read(codec, 0x1a, 0,
2069 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2070 if (present)
2071 snd_printdd("CXT5066: external microphone detected\n");
2072 else
2073 snd_printdd("CXT5066: external microphone absent\n");
2074
2075 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2076 present ? 0 : 1);
2077 spec->ext_mic_present = !!present;
2078
2079 cxt5066_olpc_select_mic(codec);
2080}
2081
2082/* toggle input of built-in digital mic and mic jack appropriately */ 1940/* toggle input of built-in digital mic and mic jack appropriately */
2083static void cxt5066_vostro_automic(struct hda_codec *codec) 1941static void cxt5066_vostro_automic(struct hda_codec *codec)
2084{ 1942{
@@ -2110,10 +1968,10 @@ static void cxt5066_vostro_automic(struct hda_codec *codec)
2110 1968
2111 present = snd_hda_jack_detect(codec, 0x1a); 1969 present = snd_hda_jack_detect(codec, 0x1a);
2112 if (present) { 1970 if (present) {
2113 snd_printdd("CXT5066: external microphone detected\n"); 1971 codec_dbg(codec, "CXT5066: external microphone detected\n");
2114 snd_hda_sequence_write(codec, ext_mic_present); 1972 snd_hda_sequence_write(codec, ext_mic_present);
2115 } else { 1973 } else {
2116 snd_printdd("CXT5066: external microphone absent\n"); 1974 codec_dbg(codec, "CXT5066: external microphone absent\n");
2117 snd_hda_sequence_write(codec, ext_mic_absent); 1975 snd_hda_sequence_write(codec, ext_mic_absent);
2118 } 1976 }
2119} 1977}
@@ -2138,10 +1996,10 @@ static void cxt5066_ideapad_automic(struct hda_codec *codec)
2138 1996
2139 present = snd_hda_jack_detect(codec, 0x1b); 1997 present = snd_hda_jack_detect(codec, 0x1b);
2140 if (present) { 1998 if (present) {
2141 snd_printdd("CXT5066: external microphone detected\n"); 1999 codec_dbg(codec, "CXT5066: external microphone detected\n");
2142 snd_hda_sequence_write(codec, ext_mic_present); 2000 snd_hda_sequence_write(codec, ext_mic_present);
2143 } else { 2001 } else {
2144 snd_printdd("CXT5066: external microphone absent\n"); 2002 codec_dbg(codec, "CXT5066: external microphone absent\n");
2145 snd_hda_sequence_write(codec, ext_mic_absent); 2003 snd_hda_sequence_write(codec, ext_mic_absent);
2146 } 2004 }
2147} 2005}
@@ -2153,7 +2011,7 @@ static void cxt5066_asus_automic(struct hda_codec *codec)
2153 unsigned int present; 2011 unsigned int present;
2154 2012
2155 present = snd_hda_jack_detect(codec, 0x1b); 2013 present = snd_hda_jack_detect(codec, 0x1b);
2156 snd_printdd("CXT5066: external microphone present=%d\n", present); 2014 codec_dbg(codec, "CXT5066: external microphone present=%d\n", present);
2157 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2015 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2158 present ? 1 : 0); 2016 present ? 1 : 0);
2159} 2017}
@@ -2165,7 +2023,7 @@ static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2165 unsigned int present; 2023 unsigned int present;
2166 2024
2167 present = snd_hda_jack_detect(codec, 0x1b); 2025 present = snd_hda_jack_detect(codec, 0x1b);
2168 snd_printdd("CXT5066: external microphone present=%d\n", present); 2026 codec_dbg(codec, "CXT5066: external microphone present=%d\n", present);
2169 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2027 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2170 present ? 1 : 3); 2028 present ? 1 : 3);
2171} 2029}
@@ -2204,13 +2062,13 @@ static void cxt5066_thinkpad_automic(struct hda_codec *codec)
2204 ext_present = snd_hda_jack_detect(codec, 0x1b); 2062 ext_present = snd_hda_jack_detect(codec, 0x1b);
2205 dock_present = snd_hda_jack_detect(codec, 0x1a); 2063 dock_present = snd_hda_jack_detect(codec, 0x1a);
2206 if (ext_present) { 2064 if (ext_present) {
2207 snd_printdd("CXT5066: external microphone detected\n"); 2065 codec_dbg(codec, "CXT5066: external microphone detected\n");
2208 snd_hda_sequence_write(codec, ext_mic_present); 2066 snd_hda_sequence_write(codec, ext_mic_present);
2209 } else if (dock_present) { 2067 } else if (dock_present) {
2210 snd_printdd("CXT5066: dock microphone detected\n"); 2068 codec_dbg(codec, "CXT5066: dock microphone detected\n");
2211 snd_hda_sequence_write(codec, dock_mic_present); 2069 snd_hda_sequence_write(codec, dock_mic_present);
2212 } else { 2070 } else {
2213 snd_printdd("CXT5066: external microphone absent\n"); 2071 codec_dbg(codec, "CXT5066: external microphone absent\n");
2214 snd_hda_sequence_write(codec, ext_mic_absent); 2072 snd_hda_sequence_write(codec, ext_mic_absent);
2215 } 2073 }
2216} 2074}
@@ -2229,7 +2087,7 @@ static void cxt5066_hp_automute(struct hda_codec *codec)
2229 2087
2230 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2088 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2231 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 2089 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
2232 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 2090 codec_dbg(codec, "CXT5066: hp automute portA=%x portD=%x present=%d\n",
2233 portA, portD, spec->hp_present); 2091 portA, portD, spec->hp_present);
2234 cxt5066_update_speaker(codec); 2092 cxt5066_update_speaker(codec);
2235} 2093}
@@ -2252,26 +2110,9 @@ static void cxt5066_automic(struct hda_codec *codec)
2252} 2110}
2253 2111
2254/* unsolicited event for jack sensing */ 2112/* unsolicited event for jack sensing */
2255static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
2256{
2257 struct conexant_spec *spec = codec->spec;
2258 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
2259 switch (res >> 26) {
2260 case CONEXANT_HP_EVENT:
2261 cxt5066_hp_automute(codec);
2262 break;
2263 case CONEXANT_MIC_EVENT:
2264 /* ignore mic events in DC mode; we're always using the jack */
2265 if (!spec->dc_enable)
2266 cxt5066_olpc_automic(codec);
2267 break;
2268 }
2269}
2270
2271/* unsolicited event for jack sensing */
2272static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 2113static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
2273{ 2114{
2274 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 2115 codec_dbg(codec, "CXT5066: unsol event %x (%x)\n", res, res >> 26);
2275 switch (res >> 26) { 2116 switch (res >> 26) {
2276 case CONEXANT_HP_EVENT: 2117 case CONEXANT_HP_EVENT:
2277 cxt5066_hp_automute(codec); 2118 cxt5066_hp_automute(codec);
@@ -2338,124 +2179,10 @@ static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
2338 idx = imux->num_items - 1; 2179 idx = imux->num_items - 1;
2339 2180
2340 spec->mic_boost = idx; 2181 spec->mic_boost = idx;
2341 if (!spec->dc_enable)
2342 cxt5066_set_mic_boost(codec);
2343 return 1;
2344}
2345
2346static void cxt5066_enable_dc(struct hda_codec *codec)
2347{
2348 const struct hda_verb enable_dc_mode[] = {
2349 /* disable gain */
2350 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2351
2352 /* switch to DC input */
2353 {0x17, AC_VERB_SET_CONNECT_SEL, 3},
2354 {}
2355 };
2356
2357 /* configure as input source */
2358 snd_hda_sequence_write(codec, enable_dc_mode);
2359 cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2360}
2361
2362static void cxt5066_disable_dc(struct hda_codec *codec)
2363{
2364 /* reconfigure input source */
2365 cxt5066_set_mic_boost(codec); 2182 cxt5066_set_mic_boost(codec);
2366 /* automic also selects the right mic if we're recording */
2367 cxt5066_olpc_automic(codec);
2368}
2369
2370static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2371 struct snd_ctl_elem_value *ucontrol)
2372{
2373 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2374 struct conexant_spec *spec = codec->spec;
2375 ucontrol->value.integer.value[0] = spec->dc_enable;
2376 return 0;
2377}
2378
2379static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2380 struct snd_ctl_elem_value *ucontrol)
2381{
2382 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2383 struct conexant_spec *spec = codec->spec;
2384 int dc_enable = !!ucontrol->value.integer.value[0];
2385
2386 if (dc_enable == spec->dc_enable)
2387 return 0;
2388
2389 spec->dc_enable = dc_enable;
2390 if (dc_enable)
2391 cxt5066_enable_dc(codec);
2392 else
2393 cxt5066_disable_dc(codec);
2394
2395 return 1;
2396}
2397
2398static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2399 struct snd_ctl_elem_info *uinfo)
2400{
2401 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2402}
2403
2404static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2405 struct snd_ctl_elem_value *ucontrol)
2406{
2407 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2408 struct conexant_spec *spec = codec->spec;
2409 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2410 return 0;
2411}
2412
2413static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2414 struct snd_ctl_elem_value *ucontrol)
2415{
2416 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2417 struct conexant_spec *spec = codec->spec;
2418 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2419 unsigned int idx;
2420
2421 idx = ucontrol->value.enumerated.item[0];
2422 if (idx >= imux->num_items)
2423 idx = imux->num_items - 1;
2424
2425 spec->dc_input_bias = idx;
2426 if (spec->dc_enable)
2427 cxt5066_set_olpc_dc_bias(codec);
2428 return 1; 2183 return 1;
2429} 2184}
2430 2185
2431static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
2432{
2433 struct conexant_spec *spec = codec->spec;
2434 /* mark as recording and configure the microphone widget so that the
2435 * recording LED comes on. */
2436 spec->recording = 1;
2437 cxt5066_olpc_select_mic(codec);
2438}
2439
2440static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
2441{
2442 struct conexant_spec *spec = codec->spec;
2443 const struct hda_verb disable_mics[] = {
2444 /* disable external mic, port B */
2445 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2446
2447 /* disble internal mic, port C */
2448 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2449
2450 /* disable DC capture, port F */
2451 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2452 {},
2453 };
2454
2455 snd_hda_sequence_write(codec, disable_mics);
2456 spec->recording = 0;
2457}
2458
2459static void conexant_check_dig_outs(struct hda_codec *codec, 2186static void conexant_check_dig_outs(struct hda_codec *codec,
2460 const hda_nid_t *dig_pins, 2187 const hda_nid_t *dig_pins,
2461 int num_pins) 2188 int num_pins)
@@ -2506,43 +2233,6 @@ static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
2506 {} 2233 {}
2507}; 2234};
2508 2235
2509static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
2510 {
2511 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2512 .name = "Master Playback Volume",
2513 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2514 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
2515 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
2516 .subdevice = HDA_SUBDEV_AMP_FLAG,
2517 .info = snd_hda_mixer_amp_volume_info,
2518 .get = snd_hda_mixer_amp_volume_get,
2519 .put = snd_hda_mixer_amp_volume_put,
2520 .tlv = { .c = snd_hda_mixer_amp_tlv },
2521 /* offset by 28 volume steps to limit minimum gain to -46dB */
2522 .private_value =
2523 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
2524 },
2525 {}
2526};
2527
2528static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2529 {
2530 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2531 .name = "DC Mode Enable Switch",
2532 .info = snd_ctl_boolean_mono_info,
2533 .get = cxt5066_olpc_dc_get,
2534 .put = cxt5066_olpc_dc_put,
2535 },
2536 {
2537 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2538 .name = "DC Input Bias Enum",
2539 .info = cxt5066_olpc_dc_bias_enum_info,
2540 .get = cxt5066_olpc_dc_bias_enum_get,
2541 .put = cxt5066_olpc_dc_bias_enum_put,
2542 },
2543 {}
2544};
2545
2546static const struct snd_kcontrol_new cxt5066_mixers[] = { 2236static const struct snd_kcontrol_new cxt5066_mixers[] = {
2547 { 2237 {
2548 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2238 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -2633,67 +2323,6 @@ static const struct hda_verb cxt5066_init_verbs[] = {
2633 { } /* end */ 2323 { } /* end */
2634}; 2324};
2635 2325
2636static const struct hda_verb cxt5066_init_verbs_olpc[] = {
2637 /* Port A: headphones */
2638 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2639 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2640
2641 /* Port B: external microphone */
2642 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2643
2644 /* Port C: internal microphone */
2645 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2646
2647 /* Port D: unused */
2648 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2649
2650 /* Port E: unused, but has primary EAPD */
2651 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2652 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2653
2654 /* Port F: external DC input through microphone port */
2655 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2656
2657 /* Port G: internal speakers */
2658 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2659 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2660
2661 /* DAC1 */
2662 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2663
2664 /* DAC2: unused */
2665 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2666
2667 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2668 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2669 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2670 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2671 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2672 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2673 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2674 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2675 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2676 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2677 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2678 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2679
2680 /* Disable digital microphone port */
2681 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2682
2683 /* Audio input selectors */
2684 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
2685 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2686
2687 /* Disable SPDIF */
2688 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2689 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2690
2691 /* enable unsolicited events for Port A and B */
2692 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2693 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2694 { } /* end */
2695};
2696
2697static const struct hda_verb cxt5066_init_verbs_vostro[] = { 2326static const struct hda_verb cxt5066_init_verbs_vostro[] = {
2698 /* Port A: headphones */ 2327 /* Port A: headphones */
2699 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2328 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
@@ -2879,7 +2508,7 @@ static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2879/* initialize jack-sensing, too */ 2508/* initialize jack-sensing, too */
2880static int cxt5066_init(struct hda_codec *codec) 2509static int cxt5066_init(struct hda_codec *codec)
2881{ 2510{
2882 snd_printdd("CXT5066: init\n"); 2511 codec_dbg(codec, "CXT5066: init\n");
2883 conexant_init(codec); 2512 conexant_init(codec);
2884 if (codec->patch_ops.unsol_event) { 2513 if (codec->patch_ops.unsol_event) {
2885 cxt5066_hp_automute(codec); 2514 cxt5066_hp_automute(codec);
@@ -2889,25 +2518,9 @@ static int cxt5066_init(struct hda_codec *codec)
2889 return 0; 2518 return 0;
2890} 2519}
2891 2520
2892static int cxt5066_olpc_init(struct hda_codec *codec)
2893{
2894 struct conexant_spec *spec = codec->spec;
2895 snd_printdd("CXT5066: init\n");
2896 conexant_init(codec);
2897 cxt5066_hp_automute(codec);
2898 if (!spec->dc_enable) {
2899 cxt5066_set_mic_boost(codec);
2900 cxt5066_olpc_automic(codec);
2901 } else {
2902 cxt5066_enable_dc(codec);
2903 }
2904 return 0;
2905}
2906
2907enum { 2521enum {
2908 CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 2522 CXT5066_LAPTOP, /* Laptops w/ EAPD support */
2909 CXT5066_DELL_LAPTOP, /* Dell Laptop */ 2523 CXT5066_DELL_LAPTOP, /* Dell Laptop */
2910 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
2911 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 2524 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
2912 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 2525 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
2913 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 2526 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
@@ -2920,7 +2533,6 @@ enum {
2920static const char * const cxt5066_models[CXT5066_MODELS] = { 2533static const char * const cxt5066_models[CXT5066_MODELS] = {
2921 [CXT5066_LAPTOP] = "laptop", 2534 [CXT5066_LAPTOP] = "laptop",
2922 [CXT5066_DELL_LAPTOP] = "dell-laptop", 2535 [CXT5066_DELL_LAPTOP] = "dell-laptop",
2923 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
2924 [CXT5066_DELL_VOSTRO] = "dell-vostro", 2536 [CXT5066_DELL_VOSTRO] = "dell-vostro",
2925 [CXT5066_IDEAPAD] = "ideapad", 2537 [CXT5066_IDEAPAD] = "ideapad",
2926 [CXT5066_THINKPAD] = "thinkpad", 2538 [CXT5066_THINKPAD] = "thinkpad",
@@ -2941,10 +2553,8 @@ static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
2941 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 2553 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
2942 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 2554 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
2943 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 2555 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
2944 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
2945 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 2556 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2946 CXT5066_LAPTOP), 2557 CXT5066_LAPTOP),
2947 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
2948 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 2558 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
2949 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 2559 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
2950 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 2560 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
@@ -3030,32 +2640,11 @@ static int patch_cxt5066(struct hda_codec *codec)
3030 spec->mic_boost = 3; /* default 30dB gain */ 2640 spec->mic_boost = 3; /* default 30dB gain */
3031 break; 2641 break;
3032 2642
3033 case CXT5066_OLPC_XO_1_5:
3034 codec->patch_ops.init = cxt5066_olpc_init;
3035 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
3036 spec->init_verbs[0] = cxt5066_init_verbs_olpc;
3037 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3038 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
3039 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3040 spec->port_d_mode = 0;
3041 spec->mic_boost = 3; /* default 30dB gain */
3042
3043 /* no S/PDIF out */
3044 spec->multiout.dig_out_nid = 0;
3045
3046 /* input source automatically selected */
3047 spec->input_mux = NULL;
3048
3049 /* our capture hooks which allow us to turn on the microphone LED
3050 * at the right time */
3051 spec->capture_prepare = cxt5066_olpc_capture_prepare;
3052 spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
3053 break;
3054 case CXT5066_DELL_VOSTRO: 2643 case CXT5066_DELL_VOSTRO:
3055 codec->patch_ops.init = cxt5066_init; 2644 codec->patch_ops.init = cxt5066_init;
3056 codec->patch_ops.unsol_event = cxt5066_unsol_event; 2645 codec->patch_ops.unsol_event = cxt5066_unsol_event;
3057 spec->init_verbs[0] = cxt5066_init_verbs_vostro; 2646 spec->init_verbs[0] = cxt5066_init_verbs_vostro;
3058 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 2647 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3059 spec->mixers[spec->num_mixers++] = cxt5066_mixers; 2648 spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3060 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 2649 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
3061 spec->port_d_mode = 0; 2650 spec->port_d_mode = 0;
@@ -3207,11 +2796,7 @@ static int cx_auto_init(struct hda_codec *codec)
3207 return 0; 2796 return 0;
3208} 2797}
3209 2798
3210static void cx_auto_free(struct hda_codec *codec) 2799#define cx_auto_free snd_hda_gen_free
3211{
3212 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
3213 snd_hda_gen_free(codec);
3214}
3215 2800
3216static const struct hda_codec_ops cx_auto_patch_ops = { 2801static const struct hda_codec_ops cx_auto_patch_ops = {
3217 .build_controls = cx_auto_build_controls, 2802 .build_controls = cx_auto_build_controls,
@@ -3238,6 +2823,11 @@ enum {
3238 CXT_FIXUP_HEADPHONE_MIC, 2823 CXT_FIXUP_HEADPHONE_MIC,
3239 CXT_FIXUP_GPIO1, 2824 CXT_FIXUP_GPIO1,
3240 CXT_FIXUP_THINKPAD_ACPI, 2825 CXT_FIXUP_THINKPAD_ACPI,
2826 CXT_FIXUP_OLPC_XO,
2827 CXT_FIXUP_CAP_MIX_AMP,
2828 CXT_FIXUP_TOSHIBA_P105,
2829 CXT_FIXUP_HP_530,
2830 CXT_FIXUP_CAP_MIX_AMP_5047,
3241}; 2831};
3242 2832
3243/* for hda_fixup_thinkpad_acpi() */ 2833/* for hda_fixup_thinkpad_acpi() */
@@ -3316,6 +2906,288 @@ static void cxt_fixup_headphone_mic(struct hda_codec *codec,
3316 } 2906 }
3317} 2907}
3318 2908
2909/* OPLC XO 1.5 fixup */
2910
2911/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
2912 * through the microphone jack.
2913 * When the user enables this through a mixer switch, both internal and
2914 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
2915 * we also allow the bias to be configured through a separate mixer
2916 * control. */
2917
2918#define update_mic_pin(codec, nid, val) \
2919 snd_hda_codec_update_cache(codec, nid, 0, \
2920 AC_VERB_SET_PIN_WIDGET_CONTROL, val)
2921
2922static const struct hda_input_mux olpc_xo_dc_bias = {
2923 .num_items = 3,
2924 .items = {
2925 { "Off", PIN_IN },
2926 { "50%", PIN_VREF50 },
2927 { "80%", PIN_VREF80 },
2928 },
2929};
2930
2931static void olpc_xo_update_mic_boost(struct hda_codec *codec)
2932{
2933 struct conexant_spec *spec = codec->spec;
2934 int ch, val;
2935
2936 for (ch = 0; ch < 2; ch++) {
2937 val = AC_AMP_SET_OUTPUT |
2938 (ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT);
2939 if (!spec->dc_enable)
2940 val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
2941 snd_hda_codec_write(codec, 0x17, 0,
2942 AC_VERB_SET_AMP_GAIN_MUTE, val);
2943 }
2944}
2945
2946static void olpc_xo_update_mic_pins(struct hda_codec *codec)
2947{
2948 struct conexant_spec *spec = codec->spec;
2949 int cur_input, val;
2950 struct nid_path *path;
2951
2952 cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
2953
2954 /* Set up mic pins for port-B, C and F dynamically as the recording
2955 * LED is turned on/off by these pin controls
2956 */
2957 if (!spec->dc_enable) {
2958 /* disable DC bias path and pin for port F */
2959 update_mic_pin(codec, 0x1e, 0);
2960 snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
2961
2962 /* update port B (ext mic) and C (int mic) */
2963 /* OLPC defers mic widget control until when capture is
2964 * started because the microphone LED comes on as soon as
2965 * these settings are put in place. if we did this before
2966 * recording, it would give the false indication that
2967 * recording is happening when it is not.
2968 */
2969 update_mic_pin(codec, 0x1a, spec->recording ?
2970 snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
2971 update_mic_pin(codec, 0x1b, spec->recording ?
2972 snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
2973 /* enable normal mic path */
2974 path = snd_hda_get_path_from_idx(codec, cur_input);
2975 if (path)
2976 snd_hda_activate_path(codec, path, true, false);
2977 } else {
2978 /* disable normal mic path */
2979 path = snd_hda_get_path_from_idx(codec, cur_input);
2980 if (path)
2981 snd_hda_activate_path(codec, path, false, false);
2982
2983 /* Even though port F is the DC input, the bias is controlled
2984 * on port B. We also leave that port as an active input (but
2985 * unselected) in DC mode just in case that is necessary to
2986 * make the bias setting take effect.
2987 */
2988 if (spec->recording)
2989 val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
2990 else
2991 val = 0;
2992 update_mic_pin(codec, 0x1a, val);
2993 update_mic_pin(codec, 0x1b, 0);
2994 /* enable DC bias path and pin */
2995 update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
2996 snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
2997 }
2998}
2999
3000/* mic_autoswitch hook */
3001static void olpc_xo_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
3002{
3003 struct conexant_spec *spec = codec->spec;
3004 int saved_cached_write = codec->cached_write;
3005
3006 codec->cached_write = 1;
3007 /* in DC mode, we don't handle automic */
3008 if (!spec->dc_enable)
3009 snd_hda_gen_mic_autoswitch(codec, jack);
3010 olpc_xo_update_mic_pins(codec);
3011 snd_hda_codec_flush_cache(codec);
3012 codec->cached_write = saved_cached_write;
3013 if (spec->dc_enable)
3014 olpc_xo_update_mic_boost(codec);
3015}
3016
3017/* pcm_capture hook */
3018static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo,
3019 struct hda_codec *codec,
3020 struct snd_pcm_substream *substream,
3021 int action)
3022{
3023 struct conexant_spec *spec = codec->spec;
3024
3025 /* toggle spec->recording flag and update mic pins accordingly
3026 * for turning on/off LED
3027 */
3028 switch (action) {
3029 case HDA_GEN_PCM_ACT_PREPARE:
3030 spec->recording = 1;
3031 olpc_xo_update_mic_pins(codec);
3032 break;
3033 case HDA_GEN_PCM_ACT_CLEANUP:
3034 spec->recording = 0;
3035 olpc_xo_update_mic_pins(codec);
3036 break;
3037 }
3038}
3039
3040static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol,
3041 struct snd_ctl_elem_value *ucontrol)
3042{
3043 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3044 struct conexant_spec *spec = codec->spec;
3045 ucontrol->value.integer.value[0] = spec->dc_enable;
3046 return 0;
3047}
3048
3049static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol,
3050 struct snd_ctl_elem_value *ucontrol)
3051{
3052 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3053 struct conexant_spec *spec = codec->spec;
3054 int dc_enable = !!ucontrol->value.integer.value[0];
3055
3056 if (dc_enable == spec->dc_enable)
3057 return 0;
3058
3059 spec->dc_enable = dc_enable;
3060 olpc_xo_update_mic_pins(codec);
3061 olpc_xo_update_mic_boost(codec);
3062 return 1;
3063}
3064
3065static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
3066 struct snd_ctl_elem_value *ucontrol)
3067{
3068 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3069 struct conexant_spec *spec = codec->spec;
3070 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
3071 return 0;
3072}
3073
3074static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
3075 struct snd_ctl_elem_info *uinfo)
3076{
3077 return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo);
3078}
3079
3080static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
3081 struct snd_ctl_elem_value *ucontrol)
3082{
3083 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3084 struct conexant_spec *spec = codec->spec;
3085 const struct hda_input_mux *imux = &olpc_xo_dc_bias;
3086 unsigned int idx;
3087
3088 idx = ucontrol->value.enumerated.item[0];
3089 if (idx >= imux->num_items)
3090 idx = imux->num_items - 1;
3091 if (spec->dc_input_bias == idx)
3092 return 0;
3093
3094 spec->dc_input_bias = idx;
3095 if (spec->dc_enable)
3096 olpc_xo_update_mic_pins(codec);
3097 return 1;
3098}
3099
3100static const struct snd_kcontrol_new olpc_xo_mixers[] = {
3101 {
3102 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3103 .name = "DC Mode Enable Switch",
3104 .info = snd_ctl_boolean_mono_info,
3105 .get = olpc_xo_dc_mode_get,
3106 .put = olpc_xo_dc_mode_put,
3107 },
3108 {
3109 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3110 .name = "DC Input Bias Enum",
3111 .info = olpc_xo_dc_bias_enum_info,
3112 .get = olpc_xo_dc_bias_enum_get,
3113 .put = olpc_xo_dc_bias_enum_put,
3114 },
3115 {}
3116};
3117
3118/* overriding mic boost put callback; update mic boost volume only when
3119 * DC mode is disabled
3120 */
3121static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol,
3122 struct snd_ctl_elem_value *ucontrol)
3123{
3124 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3125 struct conexant_spec *spec = codec->spec;
3126 int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
3127 if (ret > 0 && spec->dc_enable)
3128 olpc_xo_update_mic_boost(codec);
3129 return ret;
3130}
3131
3132static void cxt_fixup_olpc_xo(struct hda_codec *codec,
3133 const struct hda_fixup *fix, int action)
3134{
3135 struct conexant_spec *spec = codec->spec;
3136 int i;
3137
3138 if (action != HDA_FIXUP_ACT_PROBE)
3139 return;
3140
3141 spec->gen.mic_autoswitch_hook = olpc_xo_automic;
3142 spec->gen.pcm_capture_hook = olpc_xo_capture_hook;
3143 spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0);
3144
3145 snd_hda_add_new_ctls(codec, olpc_xo_mixers);
3146
3147 /* OLPC's microphone port is DC coupled for use with external sensors,
3148 * therefore we use a 50% mic bias in order to center the input signal
3149 * with the DC input range of the codec.
3150 */
3151 snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50);
3152
3153 /* override mic boost control */
3154 for (i = 0; i < spec->gen.kctls.used; i++) {
3155 struct snd_kcontrol_new *kctl =
3156 snd_array_elem(&spec->gen.kctls, i);
3157 if (!strcmp(kctl->name, "Mic Boost Volume")) {
3158 kctl->put = olpc_xo_mic_boost_put;
3159 break;
3160 }
3161 }
3162}
3163
3164/*
3165 * Fix max input level on mixer widget to 0dB
3166 * (originally it has 0x2b steps with 0dB offset 0x14)
3167 */
3168static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
3169 const struct hda_fixup *fix, int action)
3170{
3171 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
3172 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
3173 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3174 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3175 (1 << AC_AMPCAP_MUTE_SHIFT));
3176}
3177
3178/*
3179 * Fix max input level on mixer widget to 0dB
3180 * (originally it has 0x1e steps with 0 dB offset 0x17)
3181 */
3182static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec,
3183 const struct hda_fixup *fix, int action)
3184{
3185 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
3186 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3187 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3188 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3189 (1 << AC_AMPCAP_MUTE_SHIFT));
3190}
3319 3191
3320/* ThinkPad X200 & co with cxt5051 */ 3192/* ThinkPad X200 & co with cxt5051 */
3321static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = { 3193static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
@@ -3401,6 +3273,68 @@ static const struct hda_fixup cxt_fixups[] = {
3401 .type = HDA_FIXUP_FUNC, 3273 .type = HDA_FIXUP_FUNC,
3402 .v.func = hda_fixup_thinkpad_acpi, 3274 .v.func = hda_fixup_thinkpad_acpi,
3403 }, 3275 },
3276 [CXT_FIXUP_OLPC_XO] = {
3277 .type = HDA_FIXUP_FUNC,
3278 .v.func = cxt_fixup_olpc_xo,
3279 },
3280 [CXT_FIXUP_CAP_MIX_AMP] = {
3281 .type = HDA_FIXUP_FUNC,
3282 .v.func = cxt_fixup_cap_mix_amp,
3283 },
3284 [CXT_FIXUP_TOSHIBA_P105] = {
3285 .type = HDA_FIXUP_PINS,
3286 .v.pins = (const struct hda_pintbl[]) {
3287 { 0x10, 0x961701f0 }, /* speaker/hp */
3288 { 0x12, 0x02a1901e }, /* ext mic */
3289 { 0x14, 0x95a70110 }, /* int mic */
3290 {}
3291 },
3292 },
3293 [CXT_FIXUP_HP_530] = {
3294 .type = HDA_FIXUP_PINS,
3295 .v.pins = (const struct hda_pintbl[]) {
3296 { 0x12, 0x90a60160 }, /* int mic */
3297 {}
3298 },
3299 .chained = true,
3300 .chain_id = CXT_FIXUP_CAP_MIX_AMP,
3301 },
3302 [CXT_FIXUP_CAP_MIX_AMP_5047] = {
3303 .type = HDA_FIXUP_FUNC,
3304 .v.func = cxt_fixup_cap_mix_amp_5047,
3305 },
3306};
3307
3308static const struct snd_pci_quirk cxt5045_fixups[] = {
3309 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530),
3310 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
3311 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
3312 * really bad sound over 0dB on NID 0x17.
3313 */
3314 SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
3315 SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
3316 SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
3317 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
3318 {}
3319};
3320
3321static const struct hda_model_fixup cxt5045_fixup_models[] = {
3322 { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
3323 { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
3324 { .id = CXT_FIXUP_HP_530, .name = "hp-530" },
3325 {}
3326};
3327
3328static const struct snd_pci_quirk cxt5047_fixups[] = {
3329 /* HP laptops have really bad sound over 0 dB on NID 0x10.
3330 */
3331 SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047),
3332 {}
3333};
3334
3335static const struct hda_model_fixup cxt5047_fixup_models[] = {
3336 { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" },
3337 {}
3404}; 3338};
3405 3339
3406static const struct snd_pci_quirk cxt5051_fixups[] = { 3340static const struct snd_pci_quirk cxt5051_fixups[] = {
@@ -3408,10 +3342,16 @@ static const struct snd_pci_quirk cxt5051_fixups[] = {
3408 {} 3342 {}
3409}; 3343};
3410 3344
3345static const struct hda_model_fixup cxt5051_fixup_models[] = {
3346 { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
3347 {}
3348};
3349
3411static const struct snd_pci_quirk cxt5066_fixups[] = { 3350static const struct snd_pci_quirk cxt5066_fixups[] = {
3412 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC), 3351 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
3413 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_GPIO1), 3352 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_GPIO1),
3414 SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN), 3353 SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
3354 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
3415 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), 3355 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
3416 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), 3356 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
3417 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), 3357 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
@@ -3428,6 +3368,17 @@ static const struct snd_pci_quirk cxt5066_fixups[] = {
3428 {} 3368 {}
3429}; 3369};
3430 3370
3371static const struct hda_model_fixup cxt5066_fixup_models[] = {
3372 { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
3373 { .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
3374 { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
3375 { .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
3376 { .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
3377 { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
3378 { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
3379 {}
3380};
3381
3431/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches 3382/* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
3432 * can be created (bko#42825) 3383 * can be created (bko#42825)
3433 */ 3384 */
@@ -3449,8 +3400,7 @@ static int patch_conexant_auto(struct hda_codec *codec)
3449 struct conexant_spec *spec; 3400 struct conexant_spec *spec;
3450 int err; 3401 int err;
3451 3402
3452 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 3403 codec_info(codec, "%s: BIOS auto-probing.\n", codec->chip_name);
3453 codec->chip_name);
3454 3404
3455 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3405 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3456 if (!spec) 3406 if (!spec)
@@ -3467,19 +3417,28 @@ static int patch_conexant_auto(struct hda_codec *codec)
3467 switch (codec->vendor_id) { 3417 switch (codec->vendor_id) {
3468 case 0x14f15045: 3418 case 0x14f15045:
3469 codec->single_adc_amp = 1; 3419 codec->single_adc_amp = 1;
3420 spec->gen.mixer_nid = 0x17;
3421 spec->gen.add_stereo_mix_input = 1;
3422 snd_hda_pick_fixup(codec, cxt5045_fixup_models,
3423 cxt5045_fixups, cxt_fixups);
3470 break; 3424 break;
3471 case 0x14f15047: 3425 case 0x14f15047:
3472 codec->pin_amp_workaround = 1; 3426 codec->pin_amp_workaround = 1;
3473 spec->gen.mixer_nid = 0x19; 3427 spec->gen.mixer_nid = 0x19;
3428 spec->gen.add_stereo_mix_input = 1;
3429 snd_hda_pick_fixup(codec, cxt5047_fixup_models,
3430 cxt5047_fixups, cxt_fixups);
3474 break; 3431 break;
3475 case 0x14f15051: 3432 case 0x14f15051:
3476 add_cx5051_fake_mutes(codec); 3433 add_cx5051_fake_mutes(codec);
3477 codec->pin_amp_workaround = 1; 3434 codec->pin_amp_workaround = 1;
3478 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups); 3435 snd_hda_pick_fixup(codec, cxt5051_fixup_models,
3436 cxt5051_fixups, cxt_fixups);
3479 break; 3437 break;
3480 default: 3438 default:
3481 codec->pin_amp_workaround = 1; 3439 codec->pin_amp_workaround = 1;
3482 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups); 3440 snd_hda_pick_fixup(codec, cxt5066_fixup_models,
3441 cxt5066_fixups, cxt_fixups);
3483 break; 3442 break;
3484 } 3443 }
3485 3444
@@ -3513,7 +3472,7 @@ static int patch_conexant_auto(struct hda_codec *codec)
3513 * Better to make reset, then. 3472 * Better to make reset, then.
3514 */ 3473 */
3515 if (!codec->bus->sync_write) { 3474 if (!codec->bus->sync_write) {
3516 snd_printd("hda_codec: " 3475 codec_info(codec,
3517 "Enable sync_write for stable communication\n"); 3476 "Enable sync_write for stable communication\n");
3518 codec->bus->sync_write = 1; 3477 codec->bus->sync_write = 1;
3519 codec->bus->allow_bus_reset = 1; 3478 codec->bus->allow_bus_reset = 1;
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 5ef95034d041..0cb5b89cd0c8 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -68,6 +68,7 @@ struct hdmi_spec_per_pin {
68 hda_nid_t pin_nid; 68 hda_nid_t pin_nid;
69 int num_mux_nids; 69 int num_mux_nids;
70 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS]; 70 hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
71 int mux_idx;
71 hda_nid_t cvt_nid; 72 hda_nid_t cvt_nid;
72 73
73 struct hda_codec *codec; 74 struct hda_codec *codec;
@@ -353,40 +354,43 @@ static struct cea_channel_speaker_allocation channel_allocations[] = {
353#define get_pcm_rec(spec, idx) \ 354#define get_pcm_rec(spec, idx) \
354 ((struct hda_pcm *)snd_array_elem(&spec->pcm_rec, idx)) 355 ((struct hda_pcm *)snd_array_elem(&spec->pcm_rec, idx))
355 356
356static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid) 357static int pin_nid_to_pin_index(struct hda_codec *codec, hda_nid_t pin_nid)
357{ 358{
359 struct hdmi_spec *spec = codec->spec;
358 int pin_idx; 360 int pin_idx;
359 361
360 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) 362 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
361 if (get_pin(spec, pin_idx)->pin_nid == pin_nid) 363 if (get_pin(spec, pin_idx)->pin_nid == pin_nid)
362 return pin_idx; 364 return pin_idx;
363 365
364 snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid); 366 codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
365 return -EINVAL; 367 return -EINVAL;
366} 368}
367 369
368static int hinfo_to_pin_index(struct hdmi_spec *spec, 370static int hinfo_to_pin_index(struct hda_codec *codec,
369 struct hda_pcm_stream *hinfo) 371 struct hda_pcm_stream *hinfo)
370{ 372{
373 struct hdmi_spec *spec = codec->spec;
371 int pin_idx; 374 int pin_idx;
372 375
373 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) 376 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
374 if (get_pcm_rec(spec, pin_idx)->stream == hinfo) 377 if (get_pcm_rec(spec, pin_idx)->stream == hinfo)
375 return pin_idx; 378 return pin_idx;
376 379
377 snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo); 380 codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo);
378 return -EINVAL; 381 return -EINVAL;
379} 382}
380 383
381static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid) 384static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
382{ 385{
386 struct hdmi_spec *spec = codec->spec;
383 int cvt_idx; 387 int cvt_idx;
384 388
385 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) 389 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
386 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid) 390 if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
387 return cvt_idx; 391 return cvt_idx;
388 392
389 snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid); 393 codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid);
390 return -EINVAL; 394 return -EINVAL;
391} 395}
392 396
@@ -706,7 +710,7 @@ static void hdmi_debug_channel_mapping(struct hda_codec *codec,
706 710
707 for (i = 0; i < 8; i++) { 711 for (i = 0; i < 8; i++) {
708 channel = spec->ops.pin_get_slot_channel(codec, pin_nid, i); 712 channel = spec->ops.pin_get_slot_channel(codec, pin_nid, i);
709 printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n", 713 codec_dbg(codec, "HDMI: ASP channel %d => slot %d\n",
710 channel, i); 714 channel, i);
711 } 715 }
712#endif 716#endif
@@ -755,8 +759,7 @@ static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
755 int channel = (slotsetup & 0xf0) >> 4; 759 int channel = (slotsetup & 0xf0) >> 4;
756 err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, channel); 760 err = spec->ops.pin_set_slot_channel(codec, pin_nid, hdmi_slot, channel);
757 if (err) { 761 if (err) {
758 snd_printdd(KERN_NOTICE 762 codec_dbg(codec, "HDMI: channel mapping failed\n");
759 "HDMI: channel mapping failed\n");
760 break; 763 break;
761 } 764 }
762 } 765 }
@@ -967,12 +970,12 @@ static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
967 int size; 970 int size;
968 971
969 size = snd_hdmi_get_eld_size(codec, pin_nid); 972 size = snd_hdmi_get_eld_size(codec, pin_nid);
970 printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size); 973 codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
971 974
972 for (i = 0; i < 8; i++) { 975 for (i = 0; i < 8; i++) {
973 size = snd_hda_codec_read(codec, pin_nid, 0, 976 size = snd_hda_codec_read(codec, pin_nid, 0,
974 AC_VERB_GET_HDMI_DIP_SIZE, i); 977 AC_VERB_GET_HDMI_DIP_SIZE, i);
975 printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size); 978 codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
976 } 979 }
977#endif 980#endif
978} 981}
@@ -994,12 +997,12 @@ static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
994 hdmi_write_dip_byte(codec, pin_nid, 0x0); 997 hdmi_write_dip_byte(codec, pin_nid, 0x0);
995 hdmi_get_dip_index(codec, pin_nid, &pi, &bi); 998 hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
996 if (pi != i) 999 if (pi != i)
997 snd_printd(KERN_INFO "dip index %d: %d != %d\n", 1000 codec_dbg(codec, "dip index %d: %d != %d\n",
998 bi, pi, i); 1001 bi, pi, i);
999 if (bi == 0) /* byte index wrapped around */ 1002 if (bi == 0) /* byte index wrapped around */
1000 break; 1003 break;
1001 } 1004 }
1002 snd_printd(KERN_INFO 1005 codec_dbg(codec,
1003 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n", 1006 "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
1004 i, size, j); 1007 i, size, j);
1005 } 1008 }
@@ -1062,6 +1065,7 @@ static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
1062{ 1065{
1063 union audio_infoframe ai; 1066 union audio_infoframe ai;
1064 1067
1068 memset(&ai, 0, sizeof(ai));
1065 if (conn_type == 0) { /* HDMI */ 1069 if (conn_type == 0) { /* HDMI */
1066 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi; 1070 struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
1067 1071
@@ -1080,7 +1084,7 @@ static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
1080 dp_ai->CC02_CT47 = active_channels - 1; 1084 dp_ai->CC02_CT47 = active_channels - 1;
1081 dp_ai->CA = ca; 1085 dp_ai->CA = ca;
1082 } else { 1086 } else {
1083 snd_printd("HDMI: unknown connection type at pin %d\n", 1087 codec_dbg(codec, "HDMI: unknown connection type at pin %d\n",
1084 pin_nid); 1088 pin_nid);
1085 return; 1089 return;
1086 } 1090 }
@@ -1092,8 +1096,8 @@ static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
1092 */ 1096 */
1093 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes, 1097 if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
1094 sizeof(ai))) { 1098 sizeof(ai))) {
1095 snd_printdd("hdmi_pin_setup_infoframe: " 1099 codec_dbg(codec,
1096 "pin=%d channels=%d ca=0x%02x\n", 1100 "hdmi_pin_setup_infoframe: pin=%d channels=%d ca=0x%02x\n",
1097 pin_nid, 1101 pin_nid,
1098 active_channels, ca); 1102 active_channels, ca);
1099 hdmi_stop_infoframe_trans(codec, pin_nid); 1103 hdmi_stop_infoframe_trans(codec, pin_nid);
@@ -1161,7 +1165,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
1161static void jack_callback(struct hda_codec *codec, struct hda_jack_tbl *jack) 1165static void jack_callback(struct hda_codec *codec, struct hda_jack_tbl *jack)
1162{ 1166{
1163 struct hdmi_spec *spec = codec->spec; 1167 struct hdmi_spec *spec = codec->spec;
1164 int pin_idx = pin_nid_to_pin_index(spec, jack->nid); 1168 int pin_idx = pin_nid_to_pin_index(codec, jack->nid);
1165 if (pin_idx < 0) 1169 if (pin_idx < 0)
1166 return; 1170 return;
1167 1171
@@ -1180,7 +1184,7 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
1180 return; 1184 return;
1181 jack->jack_dirty = 1; 1185 jack->jack_dirty = 1;
1182 1186
1183 _snd_printd(SND_PR_VERBOSE, 1187 codec_dbg(codec,
1184 "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n", 1188 "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
1185 codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA), 1189 codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
1186 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV)); 1190 !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
@@ -1195,7 +1199,7 @@ static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
1195 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE); 1199 int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
1196 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY); 1200 int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
1197 1201
1198 printk(KERN_INFO 1202 codec_info(codec,
1199 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n", 1203 "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
1200 codec->addr, 1204 codec->addr,
1201 tag, 1205 tag,
@@ -1217,7 +1221,7 @@ static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
1217 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 1221 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
1218 1222
1219 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) { 1223 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
1220 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag); 1224 codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
1221 return; 1225 return;
1222 } 1226 }
1223 1227
@@ -1244,7 +1248,7 @@ static void haswell_verify_D0(struct hda_codec *codec,
1244 msleep(40); 1248 msleep(40);
1245 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0); 1249 pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
1246 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT; 1250 pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
1247 snd_printd("Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr); 1251 codec_dbg(codec, "Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
1248 } 1252 }
1249} 1253}
1250 1254
@@ -1274,8 +1278,8 @@ static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
1274 else 1278 else
1275 new_pinctl |= AC_PINCTL_EPT_NATIVE; 1279 new_pinctl |= AC_PINCTL_EPT_NATIVE;
1276 1280
1277 snd_printdd("hdmi_pin_hbr_setup: " 1281 codec_dbg(codec,
1278 "NID=0x%x, %spinctl=0x%x\n", 1282 "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n",
1279 pin_nid, 1283 pin_nid,
1280 pinctl == new_pinctl ? "" : "new-", 1284 pinctl == new_pinctl ? "" : "new-",
1281 new_pinctl); 1285 new_pinctl);
@@ -1302,7 +1306,7 @@ static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
1302 err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format)); 1306 err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format));
1303 1307
1304 if (err) { 1308 if (err) {
1305 snd_printdd("hdmi_setup_stream: HBR is not supported\n"); 1309 codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
1306 return err; 1310 return err;
1307 } 1311 }
1308 1312
@@ -1341,6 +1345,8 @@ static int hdmi_choose_cvt(struct hda_codec *codec,
1341 if (cvt_idx == spec->num_cvts) 1345 if (cvt_idx == spec->num_cvts)
1342 return -ENODEV; 1346 return -ENODEV;
1343 1347
1348 per_pin->mux_idx = mux_idx;
1349
1344 if (cvt_id) 1350 if (cvt_id)
1345 *cvt_id = cvt_idx; 1351 *cvt_id = cvt_idx;
1346 if (mux_id) 1352 if (mux_id)
@@ -1349,6 +1355,22 @@ static int hdmi_choose_cvt(struct hda_codec *codec,
1349 return 0; 1355 return 0;
1350} 1356}
1351 1357
1358/* Assure the pin select the right convetor */
1359static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
1360 struct hdmi_spec_per_pin *per_pin)
1361{
1362 hda_nid_t pin_nid = per_pin->pin_nid;
1363 int mux_idx, curr;
1364
1365 mux_idx = per_pin->mux_idx;
1366 curr = snd_hda_codec_read(codec, pin_nid, 0,
1367 AC_VERB_GET_CONNECT_SEL, 0);
1368 if (curr != mux_idx)
1369 snd_hda_codec_write_cache(codec, pin_nid, 0,
1370 AC_VERB_SET_CONNECT_SEL,
1371 mux_idx);
1372}
1373
1352/* Intel HDMI workaround to fix audio routing issue: 1374/* Intel HDMI workaround to fix audio routing issue:
1353 * For some Intel display codecs, pins share the same connection list. 1375 * For some Intel display codecs, pins share the same connection list.
1354 * So a conveter can be selected by multiple pins and playback on any of these 1376 * So a conveter can be selected by multiple pins and playback on any of these
@@ -1389,7 +1411,8 @@ static void intel_not_share_assigned_cvt(struct hda_codec *codec,
1389 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) { 1411 for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
1390 per_cvt = get_cvt(spec, cvt_idx); 1412 per_cvt = get_cvt(spec, cvt_idx);
1391 if (!per_cvt->assigned) { 1413 if (!per_cvt->assigned) {
1392 snd_printdd("choose cvt %d for pin nid %d\n", 1414 codec_dbg(codec,
1415 "choose cvt %d for pin nid %d\n",
1393 cvt_idx, nid); 1416 cvt_idx, nid);
1394 snd_hda_codec_write_cache(codec, nid, 0, 1417 snd_hda_codec_write_cache(codec, nid, 0,
1395 AC_VERB_SET_CONNECT_SEL, 1418 AC_VERB_SET_CONNECT_SEL,
@@ -1416,7 +1439,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
1416 int err; 1439 int err;
1417 1440
1418 /* Validate hinfo */ 1441 /* Validate hinfo */
1419 pin_idx = hinfo_to_pin_index(spec, hinfo); 1442 pin_idx = hinfo_to_pin_index(codec, hinfo);
1420 if (snd_BUG_ON(pin_idx < 0)) 1443 if (snd_BUG_ON(pin_idx < 0))
1421 return -EINVAL; 1444 return -EINVAL;
1422 per_pin = get_pin(spec, pin_idx); 1445 per_pin = get_pin(spec, pin_idx);
@@ -1482,9 +1505,8 @@ static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
1482 hda_nid_t pin_nid = per_pin->pin_nid; 1505 hda_nid_t pin_nid = per_pin->pin_nid;
1483 1506
1484 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) { 1507 if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
1485 snd_printk(KERN_WARNING 1508 codec_warn(codec,
1486 "HDMI: pin %d wcaps %#x " 1509 "HDMI: pin %d wcaps %#x does not support connection list\n",
1487 "does not support connection list\n",
1488 pin_nid, get_wcaps(codec, pin_nid)); 1510 pin_nid, get_wcaps(codec, pin_nid));
1489 return -EINVAL; 1511 return -EINVAL;
1490 } 1512 }
@@ -1527,7 +1549,7 @@ static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
1527 else 1549 else
1528 eld->eld_valid = false; 1550 eld->eld_valid = false;
1529 1551
1530 _snd_printd(SND_PR_VERBOSE, 1552 codec_dbg(codec,
1531 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n", 1553 "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
1532 codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid); 1554 codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid);
1533 1555
@@ -1690,7 +1712,7 @@ static int hdmi_parse_codec(struct hda_codec *codec)
1690 1712
1691 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); 1713 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
1692 if (!nid || nodes < 0) { 1714 if (!nid || nodes < 0) {
1693 snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n"); 1715 codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
1694 return -EINVAL; 1716 return -EINVAL;
1695 } 1717 }
1696 1718
@@ -1744,12 +1766,25 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1744{ 1766{
1745 hda_nid_t cvt_nid = hinfo->nid; 1767 hda_nid_t cvt_nid = hinfo->nid;
1746 struct hdmi_spec *spec = codec->spec; 1768 struct hdmi_spec *spec = codec->spec;
1747 int pin_idx = hinfo_to_pin_index(spec, hinfo); 1769 int pin_idx = hinfo_to_pin_index(codec, hinfo);
1748 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); 1770 struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
1749 hda_nid_t pin_nid = per_pin->pin_nid; 1771 hda_nid_t pin_nid = per_pin->pin_nid;
1750 bool non_pcm; 1772 bool non_pcm;
1751 int pinctl; 1773 int pinctl;
1752 1774
1775 if (is_haswell_plus(codec) || is_valleyview(codec)) {
1776 /* Verify pin:cvt selections to avoid silent audio after S3.
1777 * After S3, the audio driver restores pin:cvt selections
1778 * but this can happen before gfx is ready and such selection
1779 * is overlooked by HW. Thus multiple pins can share a same
1780 * default convertor and mute control will affect each other,
1781 * which can cause a resumed audio playback become silent
1782 * after S3.
1783 */
1784 intel_verify_pin_cvt_connect(codec, per_pin);
1785 intel_not_share_assigned_cvt(codec, pin_nid, per_pin->mux_idx);
1786 }
1787
1753 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); 1788 non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
1754 mutex_lock(&per_pin->lock); 1789 mutex_lock(&per_pin->lock);
1755 per_pin->channels = substream->runtime->channels; 1790 per_pin->channels = substream->runtime->channels;
@@ -1788,7 +1823,7 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1788 int pinctl; 1823 int pinctl;
1789 1824
1790 if (hinfo->nid) { 1825 if (hinfo->nid) {
1791 cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid); 1826 cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
1792 if (snd_BUG_ON(cvt_idx < 0)) 1827 if (snd_BUG_ON(cvt_idx < 0))
1793 return -EINVAL; 1828 return -EINVAL;
1794 per_cvt = get_cvt(spec, cvt_idx); 1829 per_cvt = get_cvt(spec, cvt_idx);
@@ -1797,7 +1832,7 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
1797 per_cvt->assigned = 0; 1832 per_cvt->assigned = 0;
1798 hinfo->nid = 0; 1833 hinfo->nid = 0;
1799 1834
1800 pin_idx = hinfo_to_pin_index(spec, hinfo); 1835 pin_idx = hinfo_to_pin_index(codec, hinfo);
1801 if (snd_BUG_ON(pin_idx < 0)) 1836 if (snd_BUG_ON(pin_idx < 0))
1802 return -EINVAL; 1837 return -EINVAL;
1803 per_pin = get_pin(spec, pin_idx); 1838 per_pin = get_pin(spec, pin_idx);
@@ -2211,7 +2246,7 @@ static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
2211 return; 2246 return;
2212 2247
2213 /* override pins connection list */ 2248 /* override pins connection list */
2214 snd_printdd("hdmi: haswell: override pin connection 0x%x\n", nid); 2249 codec_dbg(codec, "hdmi: haswell: override pin connection 0x%x\n", nid);
2215 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids); 2250 snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
2216} 2251}
2217 2252
@@ -3132,8 +3167,8 @@ static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
3132 else 3167 else
3133 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE; 3168 hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
3134 3169
3135 snd_printdd("atihdmi_pin_hbr_setup: " 3170 codec_dbg(codec,
3136 "NID=0x%x, %shbr-ctl=0x%x\n", 3171 "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n",
3137 pin_nid, 3172 pin_nid,
3138 hbr_ctl == hbr_ctl_new ? "" : "new-", 3173 hbr_ctl == hbr_ctl_new ? "" : "new-",
3139 hbr_ctl_new); 3174 hbr_ctl_new);
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 8d0a84436674..ea2351d119f0 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -395,6 +395,8 @@ static int alc_auto_parse_customize_define(struct hda_codec *codec)
395 goto do_sku; 395 goto do_sku;
396 } 396 }
397 397
398 if (!codec->bus->pci)
399 return -1;
398 ass = codec->subsystem_id & 0xffff; 400 ass = codec->subsystem_id & 0xffff;
399 if (ass != codec->bus->pci->subsystem_device && (ass & 1)) 401 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
400 goto do_sku; 402 goto do_sku;
@@ -405,8 +407,8 @@ static int alc_auto_parse_customize_define(struct hda_codec *codec)
405 ass = snd_hda_codec_get_pincfg(codec, nid); 407 ass = snd_hda_codec_get_pincfg(codec, nid);
406 408
407 if (!(ass & 1)) { 409 if (!(ass & 1)) {
408 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n", 410 codec_info(codec, "%s: SKU not ready 0x%08x\n",
409 codec->chip_name, ass); 411 codec->chip_name, ass);
410 return -1; 412 return -1;
411 } 413 }
412 414
@@ -430,17 +432,17 @@ do_sku:
430 spec->cdefine.swap = (ass & 0x2) >> 1; 432 spec->cdefine.swap = (ass & 0x2) >> 1;
431 spec->cdefine.override = ass & 0x1; 433 spec->cdefine.override = ass & 0x1;
432 434
433 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n", 435 codec_dbg(codec, "SKU: Nid=0x%x sku_cfg=0x%08x\n",
434 nid, spec->cdefine.sku_cfg); 436 nid, spec->cdefine.sku_cfg);
435 snd_printd("SKU: port_connectivity=0x%x\n", 437 codec_dbg(codec, "SKU: port_connectivity=0x%x\n",
436 spec->cdefine.port_connectivity); 438 spec->cdefine.port_connectivity);
437 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep); 439 codec_dbg(codec, "SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
438 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum); 440 codec_dbg(codec, "SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
439 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization); 441 codec_dbg(codec, "SKU: customization=0x%08x\n", spec->cdefine.customization);
440 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp); 442 codec_dbg(codec, "SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
441 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type); 443 codec_dbg(codec, "SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
442 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap); 444 codec_dbg(codec, "SKU: swap=0x%x\n", spec->cdefine.swap);
443 snd_printd("SKU: override=0x%x\n", spec->cdefine.override); 445 codec_dbg(codec, "SKU: override=0x%x\n", spec->cdefine.override);
444 446
445 return 0; 447 return 0;
446} 448}
@@ -483,7 +485,8 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports)
483 } 485 }
484 486
485 ass = codec->subsystem_id & 0xffff; 487 ass = codec->subsystem_id & 0xffff;
486 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1)) 488 if (codec->bus->pci &&
489 ass != codec->bus->pci->subsystem_device && (ass & 1))
487 goto do_sku; 490 goto do_sku;
488 491
489 /* invalid SSID, check the special NID pin defcfg instead */ 492 /* invalid SSID, check the special NID pin defcfg instead */
@@ -499,8 +502,8 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports)
499 if (codec->vendor_id == 0x10ec0260) 502 if (codec->vendor_id == 0x10ec0260)
500 nid = 0x17; 503 nid = 0x17;
501 ass = snd_hda_codec_get_pincfg(codec, nid); 504 ass = snd_hda_codec_get_pincfg(codec, nid);
502 snd_printd("realtek: No valid SSID, " 505 codec_dbg(codec,
503 "checking pincfg 0x%08x for NID 0x%x\n", 506 "realtek: No valid SSID, checking pincfg 0x%08x for NID 0x%x\n",
504 ass, nid); 507 ass, nid);
505 if (!(ass & 1)) 508 if (!(ass & 1))
506 return 0; 509 return 0;
@@ -516,7 +519,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports)
516 if (((ass >> 16) & 0xf) != tmp) 519 if (((ass >> 16) & 0xf) != tmp)
517 return 0; 520 return 0;
518do_sku: 521do_sku:
519 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n", 522 codec_dbg(codec, "realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
520 ass & 0xffff, codec->vendor_id); 523 ass & 0xffff, codec->vendor_id);
521 /* 524 /*
522 * 0 : override 525 * 0 : override
@@ -574,8 +577,8 @@ static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
574{ 577{
575 if (!alc_subsystem_id(codec, ports)) { 578 if (!alc_subsystem_id(codec, ports)) {
576 struct alc_spec *spec = codec->spec; 579 struct alc_spec *spec = codec->spec;
577 snd_printd("realtek: " 580 codec_dbg(codec,
578 "Enable default setup for auto mode as fallback\n"); 581 "realtek: Enable default setup for auto mode as fallback\n");
579 spec->init_amp = ALC_INIT_DEFAULT; 582 spec->init_amp = ALC_INIT_DEFAULT;
580 } 583 }
581} 584}
@@ -845,11 +848,7 @@ static inline void alc_shutup(struct hda_codec *codec)
845 snd_hda_shutup_pins(codec); 848 snd_hda_shutup_pins(codec);
846} 849}
847 850
848static void alc_free(struct hda_codec *codec) 851#define alc_free snd_hda_gen_free
849{
850 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
851 snd_hda_gen_free(codec);
852}
853 852
854#ifdef CONFIG_PM 853#ifdef CONFIG_PM
855static void alc_power_eapd(struct hda_codec *codec) 854static void alc_power_eapd(struct hda_codec *codec)
@@ -970,6 +969,8 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec)
970 return alc_codec_rename(codec, p->name); 969 return alc_codec_rename(codec, p->name);
971 } 970 }
972 971
972 if (!codec->bus->pci)
973 return 0;
973 for (q = rename_pci_tbl; q->codec_vendor_id; q++) { 974 for (q = rename_pci_tbl; q->codec_vendor_id; q++) {
974 if (q->codec_vendor_id != codec->vendor_id) 975 if (q->codec_vendor_id != codec->vendor_id)
975 continue; 976 continue;
@@ -993,6 +994,7 @@ static int alc_codec_rename_from_preset(struct hda_codec *codec)
993 994
994static const struct snd_pci_quirk beep_white_list[] = { 995static const struct snd_pci_quirk beep_white_list[] = {
995 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1), 996 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
997 SND_PCI_QUIRK(0x1043, 0x115d, "ASUS", 1),
996 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1), 998 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
997 SND_PCI_QUIRK(0x1043, 0x8376, "EeePC", 1), 999 SND_PCI_QUIRK(0x1043, 0x8376, "EeePC", 1),
998 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1), 1000 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
@@ -2786,6 +2788,237 @@ static void alc269_shutup(struct hda_codec *codec)
2786 snd_hda_shutup_pins(codec); 2788 snd_hda_shutup_pins(codec);
2787} 2789}
2788 2790
2791static void alc282_restore_default_value(struct hda_codec *codec)
2792{
2793 int val;
2794
2795 /* Power Down Control */
2796 alc_write_coef_idx(codec, 0x03, 0x0002);
2797 /* FIFO and filter clock */
2798 alc_write_coef_idx(codec, 0x05, 0x0700);
2799 /* DMIC control */
2800 alc_write_coef_idx(codec, 0x07, 0x0200);
2801 /* Analog clock */
2802 val = alc_read_coef_idx(codec, 0x06);
2803 alc_write_coef_idx(codec, 0x06, (val & ~0x00f0) | 0x0);
2804 /* JD */
2805 val = alc_read_coef_idx(codec, 0x08);
2806 alc_write_coef_idx(codec, 0x08, (val & ~0xfffc) | 0x0c2c);
2807 /* JD offset1 */
2808 alc_write_coef_idx(codec, 0x0a, 0xcccc);
2809 /* JD offset2 */
2810 alc_write_coef_idx(codec, 0x0b, 0xcccc);
2811 /* LDO1/2/3, DAC/ADC */
2812 alc_write_coef_idx(codec, 0x0e, 0x6e00);
2813 /* JD */
2814 val = alc_read_coef_idx(codec, 0x0f);
2815 alc_write_coef_idx(codec, 0x0f, (val & ~0xf800) | 0x1000);
2816 /* Capless */
2817 val = alc_read_coef_idx(codec, 0x10);
2818 alc_write_coef_idx(codec, 0x10, (val & ~0xfc00) | 0x0c00);
2819 /* Class D test 4 */
2820 alc_write_coef_idx(codec, 0x6f, 0x0);
2821 /* IO power down directly */
2822 val = alc_read_coef_idx(codec, 0x0c);
2823 alc_write_coef_idx(codec, 0x0c, (val & ~0xfe00) | 0x0);
2824 /* ANC */
2825 alc_write_coef_idx(codec, 0x34, 0xa0c0);
2826 /* AGC MUX */
2827 val = alc_read_coef_idx(codec, 0x16);
2828 alc_write_coef_idx(codec, 0x16, (val & ~0x0008) | 0x0);
2829 /* DAC simple content protection */
2830 val = alc_read_coef_idx(codec, 0x1d);
2831 alc_write_coef_idx(codec, 0x1d, (val & ~0x00e0) | 0x0);
2832 /* ADC simple content protection */
2833 val = alc_read_coef_idx(codec, 0x1f);
2834 alc_write_coef_idx(codec, 0x1f, (val & ~0x00e0) | 0x0);
2835 /* DAC ADC Zero Detection */
2836 alc_write_coef_idx(codec, 0x21, 0x8804);
2837 /* PLL */
2838 alc_write_coef_idx(codec, 0x63, 0x2902);
2839 /* capless control 2 */
2840 alc_write_coef_idx(codec, 0x68, 0xa080);
2841 /* capless control 3 */
2842 alc_write_coef_idx(codec, 0x69, 0x3400);
2843 /* capless control 4 */
2844 alc_write_coef_idx(codec, 0x6a, 0x2f3e);
2845 /* capless control 5 */
2846 alc_write_coef_idx(codec, 0x6b, 0x0);
2847 /* class D test 2 */
2848 val = alc_read_coef_idx(codec, 0x6d);
2849 alc_write_coef_idx(codec, 0x6d, (val & ~0x0fff) | 0x0900);
2850 /* class D test 3 */
2851 alc_write_coef_idx(codec, 0x6e, 0x110a);
2852 /* class D test 5 */
2853 val = alc_read_coef_idx(codec, 0x70);
2854 alc_write_coef_idx(codec, 0x70, (val & ~0x00f8) | 0x00d8);
2855 /* class D test 6 */
2856 alc_write_coef_idx(codec, 0x71, 0x0014);
2857 /* classD OCP */
2858 alc_write_coef_idx(codec, 0x72, 0xc2ba);
2859 /* classD pure DC test */
2860 val = alc_read_coef_idx(codec, 0x77);
2861 alc_write_coef_idx(codec, 0x77, (val & ~0x0f80) | 0x0);
2862 /* Class D amp control */
2863 alc_write_coef_idx(codec, 0x6c, 0xfc06);
2864}
2865
2866static void alc282_init(struct hda_codec *codec)
2867{
2868 struct alc_spec *spec = codec->spec;
2869 hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2870 bool hp_pin_sense;
2871 int coef78;
2872
2873 alc282_restore_default_value(codec);
2874
2875 if (!hp_pin)
2876 return;
2877 hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2878 coef78 = alc_read_coef_idx(codec, 0x78);
2879
2880 /* Index 0x78 Direct Drive HP AMP LPM Control 1 */
2881 /* Headphone capless set to high power mode */
2882 alc_write_coef_idx(codec, 0x78, 0x9004);
2883
2884 if (hp_pin_sense)
2885 msleep(2);
2886
2887 snd_hda_codec_write(codec, hp_pin, 0,
2888 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2889
2890 if (hp_pin_sense)
2891 msleep(85);
2892
2893 snd_hda_codec_write(codec, hp_pin, 0,
2894 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
2895
2896 if (hp_pin_sense)
2897 msleep(100);
2898
2899 /* Headphone capless set to normal mode */
2900 alc_write_coef_idx(codec, 0x78, coef78);
2901}
2902
2903static void alc282_shutup(struct hda_codec *codec)
2904{
2905 struct alc_spec *spec = codec->spec;
2906 hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2907 bool hp_pin_sense;
2908 int coef78;
2909
2910 if (!hp_pin) {
2911 alc269_shutup(codec);
2912 return;
2913 }
2914
2915 hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
2916 coef78 = alc_read_coef_idx(codec, 0x78);
2917 alc_write_coef_idx(codec, 0x78, 0x9004);
2918
2919 if (hp_pin_sense)
2920 msleep(2);
2921
2922 snd_hda_codec_write(codec, hp_pin, 0,
2923 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
2924
2925 if (hp_pin_sense)
2926 msleep(85);
2927
2928 snd_hda_codec_write(codec, hp_pin, 0,
2929 AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0);
2930
2931 if (hp_pin_sense)
2932 msleep(100);
2933
2934 alc_auto_setup_eapd(codec, false);
2935 snd_hda_shutup_pins(codec);
2936 alc_write_coef_idx(codec, 0x78, coef78);
2937}
2938
2939static void alc283_restore_default_value(struct hda_codec *codec)
2940{
2941 int val;
2942
2943 /* Power Down Control */
2944 alc_write_coef_idx(codec, 0x03, 0x0002);
2945 /* FIFO and filter clock */
2946 alc_write_coef_idx(codec, 0x05, 0x0700);
2947 /* DMIC control */
2948 alc_write_coef_idx(codec, 0x07, 0x0200);
2949 /* Analog clock */
2950 val = alc_read_coef_idx(codec, 0x06);
2951 alc_write_coef_idx(codec, 0x06, (val & ~0x00f0) | 0x0);
2952 /* JD */
2953 val = alc_read_coef_idx(codec, 0x08);
2954 alc_write_coef_idx(codec, 0x08, (val & ~0xfffc) | 0x0c2c);
2955 /* JD offset1 */
2956 alc_write_coef_idx(codec, 0x0a, 0xcccc);
2957 /* JD offset2 */
2958 alc_write_coef_idx(codec, 0x0b, 0xcccc);
2959 /* LDO1/2/3, DAC/ADC */
2960 alc_write_coef_idx(codec, 0x0e, 0x6fc0);
2961 /* JD */
2962 val = alc_read_coef_idx(codec, 0x0f);
2963 alc_write_coef_idx(codec, 0x0f, (val & ~0xf800) | 0x1000);
2964 /* Capless */
2965 val = alc_read_coef_idx(codec, 0x10);
2966 alc_write_coef_idx(codec, 0x10, (val & ~0xfc00) | 0x0c00);
2967 /* Class D test 4 */
2968 alc_write_coef_idx(codec, 0x3a, 0x0);
2969 /* IO power down directly */
2970 val = alc_read_coef_idx(codec, 0x0c);
2971 alc_write_coef_idx(codec, 0x0c, (val & ~0xfe00) | 0x0);
2972 /* ANC */
2973 alc_write_coef_idx(codec, 0x22, 0xa0c0);
2974 /* AGC MUX */
2975 val = alc_read_coefex_idx(codec, 0x53, 0x01);
2976 alc_write_coefex_idx(codec, 0x53, 0x01, (val & ~0x000f) | 0x0008);
2977 /* DAC simple content protection */
2978 val = alc_read_coef_idx(codec, 0x1d);
2979 alc_write_coef_idx(codec, 0x1d, (val & ~0x00e0) | 0x0);
2980 /* ADC simple content protection */
2981 val = alc_read_coef_idx(codec, 0x1f);
2982 alc_write_coef_idx(codec, 0x1f, (val & ~0x00e0) | 0x0);
2983 /* DAC ADC Zero Detection */
2984 alc_write_coef_idx(codec, 0x21, 0x8804);
2985 /* PLL */
2986 alc_write_coef_idx(codec, 0x2e, 0x2902);
2987 /* capless control 2 */
2988 alc_write_coef_idx(codec, 0x33, 0xa080);
2989 /* capless control 3 */
2990 alc_write_coef_idx(codec, 0x34, 0x3400);
2991 /* capless control 4 */
2992 alc_write_coef_idx(codec, 0x35, 0x2f3e);
2993 /* capless control 5 */
2994 alc_write_coef_idx(codec, 0x36, 0x0);
2995 /* class D test 2 */
2996 val = alc_read_coef_idx(codec, 0x38);
2997 alc_write_coef_idx(codec, 0x38, (val & ~0x0fff) | 0x0900);
2998 /* class D test 3 */
2999 alc_write_coef_idx(codec, 0x39, 0x110a);
3000 /* class D test 5 */
3001 val = alc_read_coef_idx(codec, 0x3b);
3002 alc_write_coef_idx(codec, 0x3b, (val & ~0x00f8) | 0x00d8);
3003 /* class D test 6 */
3004 alc_write_coef_idx(codec, 0x3c, 0x0014);
3005 /* classD OCP */
3006 alc_write_coef_idx(codec, 0x3d, 0xc2ba);
3007 /* classD pure DC test */
3008 val = alc_read_coef_idx(codec, 0x42);
3009 alc_write_coef_idx(codec, 0x42, (val & ~0x0f80) | 0x0);
3010 /* test mode */
3011 alc_write_coef_idx(codec, 0x49, 0x0);
3012 /* Class D DC enable */
3013 val = alc_read_coef_idx(codec, 0x40);
3014 alc_write_coef_idx(codec, 0x40, (val & ~0xf800) | 0x9800);
3015 /* DC offset */
3016 val = alc_read_coef_idx(codec, 0x42);
3017 alc_write_coef_idx(codec, 0x42, (val & ~0xf000) | 0x2000);
3018 /* Class D amp control */
3019 alc_write_coef_idx(codec, 0x37, 0xfc06);
3020}
3021
2789static void alc283_init(struct hda_codec *codec) 3022static void alc283_init(struct hda_codec *codec)
2790{ 3023{
2791 struct alc_spec *spec = codec->spec; 3024 struct alc_spec *spec = codec->spec;
@@ -2793,6 +3026,8 @@ static void alc283_init(struct hda_codec *codec)
2793 bool hp_pin_sense; 3026 bool hp_pin_sense;
2794 int val; 3027 int val;
2795 3028
3029 alc283_restore_default_value(codec);
3030
2796 if (!hp_pin) 3031 if (!hp_pin)
2797 return; 3032 return;
2798 hp_pin_sense = snd_hda_jack_detect(codec, hp_pin); 3033 hp_pin_sense = snd_hda_jack_detect(codec, hp_pin);
@@ -3169,7 +3404,8 @@ static void alc269_fixup_hp_mute_led(struct hda_codec *codec,
3169 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook; 3404 spec->gen.vmaster_mute.hook = alc269_fixup_mic_mute_hook;
3170 spec->gen.vmaster_mute_enum = 1; 3405 spec->gen.vmaster_mute_enum = 1;
3171 codec->power_filter = led_power_filter; 3406 codec->power_filter = led_power_filter;
3172 snd_printd("Detected mute LED for %x:%d\n", spec->mute_led_nid, 3407 codec_dbg(codec,
3408 "Detected mute LED for %x:%d\n", spec->mute_led_nid,
3173 spec->mute_led_polarity); 3409 spec->mute_led_polarity);
3174 break; 3410 break;
3175 } 3411 }
@@ -3295,7 +3531,7 @@ static void alc_headset_mode_unplugged(struct hda_codec *codec)
3295 alc_write_coef_idx(codec, 0xb7, 0x802b); 3531 alc_write_coef_idx(codec, 0xb7, 0x802b);
3296 break; 3532 break;
3297 } 3533 }
3298 snd_printdd("Headset jack set to unplugged mode.\n"); 3534 codec_dbg(codec, "Headset jack set to unplugged mode.\n");
3299} 3535}
3300 3536
3301 3537
@@ -3338,7 +3574,7 @@ static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
3338 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50); 3574 snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
3339 break; 3575 break;
3340 } 3576 }
3341 snd_printdd("Headset jack set to mic-in mode.\n"); 3577 codec_dbg(codec, "Headset jack set to mic-in mode.\n");
3342} 3578}
3343 3579
3344static void alc_headset_mode_default(struct hda_codec *codec) 3580static void alc_headset_mode_default(struct hda_codec *codec)
@@ -3366,7 +3602,7 @@ static void alc_headset_mode_default(struct hda_codec *codec)
3366 alc_write_coef_idx(codec, 0xb7, 0x802b); 3602 alc_write_coef_idx(codec, 0xb7, 0x802b);
3367 break; 3603 break;
3368 } 3604 }
3369 snd_printdd("Headset jack set to headphone (default) mode.\n"); 3605 codec_dbg(codec, "Headset jack set to headphone (default) mode.\n");
3370} 3606}
3371 3607
3372/* Iphone type */ 3608/* Iphone type */
@@ -3395,7 +3631,7 @@ static void alc_headset_mode_ctia(struct hda_codec *codec)
3395 alc_write_coef_idx(codec, 0xc3, 0x0000); 3631 alc_write_coef_idx(codec, 0xc3, 0x0000);
3396 break; 3632 break;
3397 } 3633 }
3398 snd_printdd("Headset jack set to iPhone-style headset mode.\n"); 3634 codec_dbg(codec, "Headset jack set to iPhone-style headset mode.\n");
3399} 3635}
3400 3636
3401/* Nokia type */ 3637/* Nokia type */
@@ -3424,7 +3660,7 @@ static void alc_headset_mode_omtp(struct hda_codec *codec)
3424 alc_write_coef_idx(codec, 0xc3, 0x0000); 3660 alc_write_coef_idx(codec, 0xc3, 0x0000);
3425 break; 3661 break;
3426 } 3662 }
3427 snd_printdd("Headset jack set to Nokia-style headset mode.\n"); 3663 codec_dbg(codec, "Headset jack set to Nokia-style headset mode.\n");
3428} 3664}
3429 3665
3430static void alc_determine_headset_type(struct hda_codec *codec) 3666static void alc_determine_headset_type(struct hda_codec *codec)
@@ -3466,7 +3702,7 @@ static void alc_determine_headset_type(struct hda_codec *codec)
3466 break; 3702 break;
3467 } 3703 }
3468 3704
3469 snd_printdd("Headset jack detected iPhone-style headset: %s\n", 3705 codec_dbg(codec, "Headset jack detected iPhone-style headset: %s\n",
3470 is_ctia ? "yes" : "no"); 3706 is_ctia ? "yes" : "no");
3471 spec->current_headset_type = is_ctia ? ALC_HEADSET_TYPE_CTIA : ALC_HEADSET_TYPE_OMTP; 3707 spec->current_headset_type = is_ctia ? ALC_HEADSET_TYPE_CTIA : ALC_HEADSET_TYPE_OMTP;
3472} 3708}
@@ -3592,21 +3828,38 @@ static void alc_fixup_headset_mode_no_hp_mic(struct hda_codec *codec,
3592 alc_fixup_headset_mode(codec, fix, action); 3828 alc_fixup_headset_mode(codec, fix, action);
3593} 3829}
3594 3830
3831static void alc255_set_default_jack_type(struct hda_codec *codec)
3832{
3833 /* Set to iphone type */
3834 alc_write_coef_idx(codec, 0x1b, 0x880b);
3835 alc_write_coef_idx(codec, 0x45, 0xd089);
3836 alc_write_coef_idx(codec, 0x1b, 0x080b);
3837 alc_write_coef_idx(codec, 0x46, 0x0004);
3838 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
3839 msleep(30);
3840}
3841
3595static void alc_fixup_headset_mode_alc255(struct hda_codec *codec, 3842static void alc_fixup_headset_mode_alc255(struct hda_codec *codec,
3596 const struct hda_fixup *fix, int action) 3843 const struct hda_fixup *fix, int action)
3597{ 3844{
3598 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 3845 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3599 /* Set to iphone type */ 3846 alc255_set_default_jack_type(codec);
3600 alc_write_coef_idx(codec, 0x1b, 0x880b);
3601 alc_write_coef_idx(codec, 0x45, 0xd089);
3602 alc_write_coef_idx(codec, 0x1b, 0x080b);
3603 alc_write_coef_idx(codec, 0x46, 0x0004);
3604 alc_write_coef_idx(codec, 0x1b, 0x0c0b);
3605 msleep(30);
3606 } 3847 }
3607 alc_fixup_headset_mode(codec, fix, action); 3848 alc_fixup_headset_mode(codec, fix, action);
3608} 3849}
3609 3850
3851static void alc_fixup_headset_mode_alc255_no_hp_mic(struct hda_codec *codec,
3852 const struct hda_fixup *fix, int action)
3853{
3854 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3855 struct alc_spec *spec = codec->spec;
3856 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
3857 alc255_set_default_jack_type(codec);
3858 }
3859 else
3860 alc_fixup_headset_mode(codec, fix, action);
3861}
3862
3610static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec, 3863static void alc_fixup_auto_mute_via_amp(struct hda_codec *codec,
3611 const struct hda_fixup *fix, int action) 3864 const struct hda_fixup *fix, int action)
3612{ 3865{
@@ -3887,7 +4140,9 @@ enum {
3887 ALC290_FIXUP_SUBWOOFER_HSJACK, 4140 ALC290_FIXUP_SUBWOOFER_HSJACK,
3888 ALC269_FIXUP_THINKPAD_ACPI, 4141 ALC269_FIXUP_THINKPAD_ACPI,
3889 ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, 4142 ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
4143 ALC255_FIXUP_DELL2_MIC_NO_PRESENCE,
3890 ALC255_FIXUP_HEADSET_MODE, 4144 ALC255_FIXUP_HEADSET_MODE,
4145 ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC,
3891}; 4146};
3892 4147
3893static const struct hda_fixup alc269_fixups[] = { 4148static const struct hda_fixup alc269_fixups[] = {
@@ -4264,10 +4519,23 @@ static const struct hda_fixup alc269_fixups[] = {
4264 .chained = true, 4519 .chained = true,
4265 .chain_id = ALC255_FIXUP_HEADSET_MODE 4520 .chain_id = ALC255_FIXUP_HEADSET_MODE
4266 }, 4521 },
4522 [ALC255_FIXUP_DELL2_MIC_NO_PRESENCE] = {
4523 .type = HDA_FIXUP_PINS,
4524 .v.pins = (const struct hda_pintbl[]) {
4525 { 0x19, 0x01a1913c }, /* use as headset mic, without its own jack detect */
4526 { }
4527 },
4528 .chained = true,
4529 .chain_id = ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC
4530 },
4267 [ALC255_FIXUP_HEADSET_MODE] = { 4531 [ALC255_FIXUP_HEADSET_MODE] = {
4268 .type = HDA_FIXUP_FUNC, 4532 .type = HDA_FIXUP_FUNC,
4269 .v.func = alc_fixup_headset_mode_alc255, 4533 .v.func = alc_fixup_headset_mode_alc255,
4270 }, 4534 },
4535 [ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
4536 .type = HDA_FIXUP_FUNC,
4537 .v.func = alc_fixup_headset_mode_alc255_no_hp_mic,
4538 },
4271}; 4539};
4272 4540
4273static const struct snd_pci_quirk alc269_fixup_tbl[] = { 4541static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -4319,6 +4587,9 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4319 SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_SUBWOOFER_HSJACK), 4587 SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_SUBWOOFER_HSJACK),
4320 SND_PCI_QUIRK(0x1028, 0x061f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE), 4588 SND_PCI_QUIRK(0x1028, 0x061f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4321 SND_PCI_QUIRK(0x1028, 0x0629, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE), 4589 SND_PCI_QUIRK(0x1028, 0x0629, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4590 SND_PCI_QUIRK(0x1028, 0x062c, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4591 SND_PCI_QUIRK(0x1028, 0x062e, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4592 SND_PCI_QUIRK(0x1028, 0x0632, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4322 SND_PCI_QUIRK(0x1028, 0x0638, "Dell Inspiron 5439", ALC290_FIXUP_MONO_SPEAKERS_HSJACK), 4593 SND_PCI_QUIRK(0x1028, 0x0638, "Dell Inspiron 5439", ALC290_FIXUP_MONO_SPEAKERS_HSJACK),
4323 SND_PCI_QUIRK(0x1028, 0x063e, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE), 4594 SND_PCI_QUIRK(0x1028, 0x063e, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4324 SND_PCI_QUIRK(0x1028, 0x063f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE), 4595 SND_PCI_QUIRK(0x1028, 0x063f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
@@ -4331,6 +4602,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4331 SND_PCI_QUIRK(0x1028, 0x0658, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE), 4602 SND_PCI_QUIRK(0x1028, 0x0658, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4332 SND_PCI_QUIRK(0x1028, 0x065f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE), 4603 SND_PCI_QUIRK(0x1028, 0x065f, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4333 SND_PCI_QUIRK(0x1028, 0x0662, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE), 4604 SND_PCI_QUIRK(0x1028, 0x0662, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
4605 SND_PCI_QUIRK(0x1028, 0x0668, "Dell", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE),
4606 SND_PCI_QUIRK(0x1028, 0x0669, "Dell", ALC255_FIXUP_DELL2_MIC_NO_PRESENCE),
4334 SND_PCI_QUIRK(0x1028, 0x15cc, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE), 4607 SND_PCI_QUIRK(0x1028, 0x15cc, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
4335 SND_PCI_QUIRK(0x1028, 0x15cd, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE), 4608 SND_PCI_QUIRK(0x1028, 0x15cd, "Dell X5 Precision", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE),
4336 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2), 4609 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
@@ -4573,13 +4846,15 @@ static int patch_alc269(struct hda_codec *codec)
4573 spec->codec_variant = ALC269_TYPE_ALC269VA; 4846 spec->codec_variant = ALC269_TYPE_ALC269VA;
4574 switch (alc_get_coef0(codec) & 0x00f0) { 4847 switch (alc_get_coef0(codec) & 0x00f0) {
4575 case 0x0010: 4848 case 0x0010:
4576 if (codec->bus->pci->subsystem_vendor == 0x1025 && 4849 if (codec->bus->pci &&
4850 codec->bus->pci->subsystem_vendor == 0x1025 &&
4577 spec->cdefine.platform_type == 1) 4851 spec->cdefine.platform_type == 1)
4578 err = alc_codec_rename(codec, "ALC271X"); 4852 err = alc_codec_rename(codec, "ALC271X");
4579 spec->codec_variant = ALC269_TYPE_ALC269VB; 4853 spec->codec_variant = ALC269_TYPE_ALC269VB;
4580 break; 4854 break;
4581 case 0x0020: 4855 case 0x0020:
4582 if (codec->bus->pci->subsystem_vendor == 0x17aa && 4856 if (codec->bus->pci &&
4857 codec->bus->pci->subsystem_vendor == 0x17aa &&
4583 codec->bus->pci->subsystem_device == 0x21f3) 4858 codec->bus->pci->subsystem_device == 0x21f3)
4584 err = alc_codec_rename(codec, "ALC3202"); 4859 err = alc_codec_rename(codec, "ALC3202");
4585 spec->codec_variant = ALC269_TYPE_ALC269VC; 4860 spec->codec_variant = ALC269_TYPE_ALC269VC;
@@ -4602,6 +4877,8 @@ static int patch_alc269(struct hda_codec *codec)
4602 break; 4877 break;
4603 case 0x10ec0282: 4878 case 0x10ec0282:
4604 spec->codec_variant = ALC269_TYPE_ALC282; 4879 spec->codec_variant = ALC269_TYPE_ALC282;
4880 spec->shutup = alc282_shutup;
4881 spec->init_hook = alc282_init;
4605 break; 4882 break;
4606 case 0x10ec0233: 4883 case 0x10ec0233:
4607 case 0x10ec0283: 4884 case 0x10ec0283:
@@ -4919,8 +5196,7 @@ static void alc272_fixup_mario(struct hda_codec *codec,
4919 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) | 5196 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
4920 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) | 5197 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4921 (0 << AC_AMPCAP_MUTE_SHIFT))) 5198 (0 << AC_AMPCAP_MUTE_SHIFT)))
4922 printk(KERN_WARNING 5199 codec_warn(codec, "failed to override amp caps for NID 0x2\n");
4923 "hda_codec: failed to override amp caps for NID 0x2\n");
4924} 5200}
4925 5201
4926static const struct snd_pcm_chmap_elem asus_pcm_2_1_chmaps[] = { 5202static const struct snd_pcm_chmap_elem asus_pcm_2_1_chmaps[] = {
@@ -4942,8 +5218,54 @@ static void alc_fixup_bass_chmap(struct hda_codec *codec,
4942 } 5218 }
4943} 5219}
4944 5220
5221/* turn on/off mute LED per vmaster hook */
5222static void alc662_led_gpio1_mute_hook(void *private_data, int enabled)
5223{
5224 struct hda_codec *codec = private_data;
5225 struct alc_spec *spec = codec->spec;
5226 unsigned int oldval = spec->gpio_led;
5227
5228 if (enabled)
5229 spec->gpio_led &= ~0x01;
5230 else
5231 spec->gpio_led |= 0x01;
5232 if (spec->gpio_led != oldval)
5233 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5234 spec->gpio_led);
5235}
5236
5237/* avoid D3 for keeping GPIO up */
5238static unsigned int gpio_led_power_filter(struct hda_codec *codec,
5239 hda_nid_t nid,
5240 unsigned int power_state)
5241{
5242 struct alc_spec *spec = codec->spec;
5243 if (nid == codec->afg && power_state == AC_PWRST_D3 && spec->gpio_led)
5244 return AC_PWRST_D0;
5245 return power_state;
5246}
5247
5248static void alc662_fixup_led_gpio1(struct hda_codec *codec,
5249 const struct hda_fixup *fix, int action)
5250{
5251 struct alc_spec *spec = codec->spec;
5252 static const struct hda_verb gpio_init[] = {
5253 { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
5254 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
5255 {}
5256 };
5257
5258 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
5259 spec->gen.vmaster_mute.hook = alc662_led_gpio1_mute_hook;
5260 spec->gpio_led = 0;
5261 snd_hda_add_verbs(codec, gpio_init);
5262 codec->power_filter = gpio_led_power_filter;
5263 }
5264}
5265
4945enum { 5266enum {
4946 ALC662_FIXUP_ASPIRE, 5267 ALC662_FIXUP_ASPIRE,
5268 ALC662_FIXUP_LED_GPIO1,
4947 ALC662_FIXUP_IDEAPAD, 5269 ALC662_FIXUP_IDEAPAD,
4948 ALC272_FIXUP_MARIO, 5270 ALC272_FIXUP_MARIO,
4949 ALC662_FIXUP_CZC_P10T, 5271 ALC662_FIXUP_CZC_P10T,
@@ -4962,9 +5284,10 @@ enum {
4962 ALC662_FIXUP_INV_DMIC, 5284 ALC662_FIXUP_INV_DMIC,
4963 ALC668_FIXUP_DELL_MIC_NO_PRESENCE, 5285 ALC668_FIXUP_DELL_MIC_NO_PRESENCE,
4964 ALC668_FIXUP_HEADSET_MODE, 5286 ALC668_FIXUP_HEADSET_MODE,
4965 ALC662_FIXUP_BASS_CHMAP, 5287 ALC662_FIXUP_BASS_MODE4_CHMAP,
5288 ALC662_FIXUP_BASS_16,
4966 ALC662_FIXUP_BASS_1A, 5289 ALC662_FIXUP_BASS_1A,
4967 ALC662_FIXUP_BASS_1A_CHMAP, 5290 ALC662_FIXUP_BASS_CHMAP,
4968 ALC668_FIXUP_AUTO_MUTE, 5291 ALC668_FIXUP_AUTO_MUTE,
4969}; 5292};
4970 5293
@@ -4976,12 +5299,18 @@ static const struct hda_fixup alc662_fixups[] = {
4976 { } 5299 { }
4977 } 5300 }
4978 }, 5301 },
5302 [ALC662_FIXUP_LED_GPIO1] = {
5303 .type = HDA_FIXUP_FUNC,
5304 .v.func = alc662_fixup_led_gpio1,
5305 },
4979 [ALC662_FIXUP_IDEAPAD] = { 5306 [ALC662_FIXUP_IDEAPAD] = {
4980 .type = HDA_FIXUP_PINS, 5307 .type = HDA_FIXUP_PINS,
4981 .v.pins = (const struct hda_pintbl[]) { 5308 .v.pins = (const struct hda_pintbl[]) {
4982 { 0x17, 0x99130112 }, /* subwoofer */ 5309 { 0x17, 0x99130112 }, /* subwoofer */
4983 { } 5310 { }
4984 } 5311 },
5312 .chained = true,
5313 .chain_id = ALC662_FIXUP_LED_GPIO1,
4985 }, 5314 },
4986 [ALC272_FIXUP_MARIO] = { 5315 [ALC272_FIXUP_MARIO] = {
4987 .type = HDA_FIXUP_FUNC, 5316 .type = HDA_FIXUP_FUNC,
@@ -5146,24 +5475,33 @@ static const struct hda_fixup alc662_fixups[] = {
5146 .type = HDA_FIXUP_FUNC, 5475 .type = HDA_FIXUP_FUNC,
5147 .v.func = alc_fixup_headset_mode_alc668, 5476 .v.func = alc_fixup_headset_mode_alc668,
5148 }, 5477 },
5149 [ALC662_FIXUP_BASS_CHMAP] = { 5478 [ALC662_FIXUP_BASS_MODE4_CHMAP] = {
5150 .type = HDA_FIXUP_FUNC, 5479 .type = HDA_FIXUP_FUNC,
5151 .v.func = alc_fixup_bass_chmap, 5480 .v.func = alc_fixup_bass_chmap,
5152 .chained = true, 5481 .chained = true,
5153 .chain_id = ALC662_FIXUP_ASUS_MODE4 5482 .chain_id = ALC662_FIXUP_ASUS_MODE4
5154 }, 5483 },
5484 [ALC662_FIXUP_BASS_16] = {
5485 .type = HDA_FIXUP_PINS,
5486 .v.pins = (const struct hda_pintbl[]) {
5487 {0x16, 0x80106111}, /* bass speaker */
5488 {}
5489 },
5490 .chained = true,
5491 .chain_id = ALC662_FIXUP_BASS_CHMAP,
5492 },
5155 [ALC662_FIXUP_BASS_1A] = { 5493 [ALC662_FIXUP_BASS_1A] = {
5156 .type = HDA_FIXUP_PINS, 5494 .type = HDA_FIXUP_PINS,
5157 .v.pins = (const struct hda_pintbl[]) { 5495 .v.pins = (const struct hda_pintbl[]) {
5158 {0x1a, 0x80106111}, /* bass speaker */ 5496 {0x1a, 0x80106111}, /* bass speaker */
5159 {} 5497 {}
5160 }, 5498 },
5499 .chained = true,
5500 .chain_id = ALC662_FIXUP_BASS_CHMAP,
5161 }, 5501 },
5162 [ALC662_FIXUP_BASS_1A_CHMAP] = { 5502 [ALC662_FIXUP_BASS_CHMAP] = {
5163 .type = HDA_FIXUP_FUNC, 5503 .type = HDA_FIXUP_FUNC,
5164 .v.func = alc_fixup_bass_chmap, 5504 .v.func = alc_fixup_bass_chmap,
5165 .chained = true,
5166 .chain_id = ALC662_FIXUP_BASS_1A,
5167 }, 5505 },
5168}; 5506};
5169 5507
@@ -5185,9 +5523,11 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5185 SND_PCI_QUIRK(0x1028, 0x0628, "Dell", ALC668_FIXUP_AUTO_MUTE), 5523 SND_PCI_QUIRK(0x1028, 0x0628, "Dell", ALC668_FIXUP_AUTO_MUTE),
5186 SND_PCI_QUIRK(0x1028, 0x064e, "Dell", ALC668_FIXUP_AUTO_MUTE), 5524 SND_PCI_QUIRK(0x1028, 0x064e, "Dell", ALC668_FIXUP_AUTO_MUTE),
5187 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), 5525 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5188 SND_PCI_QUIRK(0x1043, 0x11cd, "Asus N550", ALC662_FIXUP_BASS_1A_CHMAP), 5526 SND_PCI_QUIRK(0x1043, 0x11cd, "Asus N550", ALC662_FIXUP_BASS_1A),
5189 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_CHMAP), 5527 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_BASS_MODE4_CHMAP),
5190 SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_BASS_CHMAP), 5528 SND_PCI_QUIRK(0x1043, 0x15a7, "ASUS UX51VZH", ALC662_FIXUP_BASS_16),
5529 SND_PCI_QUIRK(0x1043, 0x1b73, "ASUS N55SF", ALC662_FIXUP_BASS_16),
5530 SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_BASS_MODE4_CHMAP),
5191 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT), 5531 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
5192 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), 5532 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
5193 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), 5533 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
@@ -5328,7 +5668,7 @@ static int patch_alc662(struct hda_codec *codec)
5328 spec->gen.beep_nid = 0x01; 5668 spec->gen.beep_nid = 0x01;
5329 5669
5330 if ((alc_get_coef0(codec) & (1 << 14)) && 5670 if ((alc_get_coef0(codec) & (1 << 14)) &&
5331 codec->bus->pci->subsystem_vendor == 0x1025 && 5671 codec->bus->pci && codec->bus->pci->subsystem_vendor == 0x1025 &&
5332 spec->cdefine.platform_type == 1) { 5672 spec->cdefine.platform_type == 1) {
5333 err = alc_codec_rename(codec, "ALC272X"); 5673 err = alc_codec_rename(codec, "ALC272X");
5334 if (err < 0) 5674 if (err < 0)
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c
index 6679a5095e55..3208ad69583e 100644
--- a/sound/pci/hda/patch_si3054.c
+++ b/sound/pci/hda/patch_si3054.c
@@ -236,7 +236,7 @@ static int si3054_init(struct hda_codec *codec)
236 } while ((val & SI3054_MEI_READY) != SI3054_MEI_READY && wait_count--); 236 } while ((val & SI3054_MEI_READY) != SI3054_MEI_READY && wait_count--);
237 237
238 if((val&SI3054_MEI_READY) != SI3054_MEI_READY) { 238 if((val&SI3054_MEI_READY) != SI3054_MEI_READY) {
239 snd_printk(KERN_ERR "si3054: cannot initialize. EXT MID = %04x\n", val); 239 codec_err(codec, "si3054: cannot initialize. EXT MID = %04x\n", val);
240 /* let's pray that this is no fatal error */ 240 /* let's pray that this is no fatal error */
241 /* return -EACCES; */ 241 /* return -EACCES; */
242 } 242 }
@@ -247,7 +247,8 @@ static int si3054_init(struct hda_codec *codec)
247 SET_REG(codec, SI3054_LINE_CFG1,0x200); 247 SET_REG(codec, SI3054_LINE_CFG1,0x200);
248 248
249 if((GET_REG(codec,SI3054_LINE_STATUS) & (1<<6)) == 0) { 249 if((GET_REG(codec,SI3054_LINE_STATUS) & (1<<6)) == 0) {
250 snd_printd("Link Frame Detect(FDT) is not ready (line status: %04x)\n", 250 codec_dbg(codec,
251 "Link Frame Detect(FDT) is not ready (line status: %04x)\n",
251 GET_REG(codec,SI3054_LINE_STATUS)); 252 GET_REG(codec,SI3054_LINE_STATUS));
252 } 253 }
253 254
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 3bc29c9b2529..75515b494034 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -296,7 +296,7 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
296{ 296{
297 unsigned int gpiostate, gpiomask, gpiodir; 297 unsigned int gpiostate, gpiomask, gpiodir;
298 298
299 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data); 299 codec_dbg(codec, "%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
300 300
301 gpiostate = snd_hda_codec_read(codec, codec->afg, 0, 301 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
302 AC_VERB_GET_GPIO_DATA, 0); 302 AC_VERB_GET_GPIO_DATA, 0);
@@ -359,7 +359,7 @@ static int stac_vrefout_set(struct hda_codec *codec,
359{ 359{
360 int error, pinctl; 360 int error, pinctl;
361 361
362 snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref); 362 codec_dbg(codec, "%s, nid %x ctl %x\n", __func__, nid, new_vref);
363 pinctl = snd_hda_codec_read(codec, nid, 0, 363 pinctl = snd_hda_codec_read(codec, nid, 0,
364 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 364 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
365 365
@@ -2086,9 +2086,12 @@ static void stac92hd83xxx_fixup_hp(struct hda_codec *codec,
2086 } 2086 }
2087 2087
2088 if (find_mute_led_cfg(codec, spec->default_polarity)) 2088 if (find_mute_led_cfg(codec, spec->default_polarity))
2089 snd_printd("mute LED gpio %d polarity %d\n", 2089 codec_dbg(codec, "mute LED gpio %d polarity %d\n",
2090 spec->gpio_led, 2090 spec->gpio_led,
2091 spec->gpio_led_polarity); 2091 spec->gpio_led_polarity);
2092
2093 /* allow auto-switching of dock line-in */
2094 spec->gen.line_in_auto_switch = true;
2092} 2095}
2093 2096
2094static void stac92hd83xxx_fixup_hp_zephyr(struct hda_codec *codec, 2097static void stac92hd83xxx_fixup_hp_zephyr(struct hda_codec *codec,
@@ -3077,7 +3080,7 @@ static void stac92hd71bxx_fixup_hp(struct hda_codec *codec,
3077 } 3080 }
3078 3081
3079 if (find_mute_led_cfg(codec, 1)) 3082 if (find_mute_led_cfg(codec, 1))
3080 snd_printd("mute LED gpio %d polarity %d\n", 3083 codec_dbg(codec, "mute LED gpio %d polarity %d\n",
3081 spec->gpio_led, 3084 spec->gpio_led,
3082 spec->gpio_led_polarity); 3085 spec->gpio_led_polarity);
3083 3086
@@ -4422,8 +4425,8 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
4422 4425
4423 num_dacs = snd_hda_get_num_conns(codec, 0x0a) - 1; 4426 num_dacs = snd_hda_get_num_conns(codec, 0x0a) - 1;
4424 if (num_dacs < 3 || num_dacs > 5) { 4427 if (num_dacs < 3 || num_dacs > 5) {
4425 printk(KERN_WARNING "hda_codec: Could not determine " 4428 codec_warn(codec,
4426 "number of channels defaulting to DAC count\n"); 4429 "Could not determine number of channels defaulting to DAC count\n");
4427 num_dacs = 5; 4430 num_dacs = 5;
4428 } 4431 }
4429 4432
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index f84195f3ea31..778166259b3e 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -465,14 +465,8 @@ static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
465 465
466static void via_free(struct hda_codec *codec) 466static void via_free(struct hda_codec *codec)
467{ 467{
468 struct via_spec *spec = codec->spec;
469
470 if (!spec)
471 return;
472
473 vt1708_stop_hp_work(codec); 468 vt1708_stop_hp_work(codec);
474 snd_hda_gen_spec_free(&spec->gen); 469 snd_hda_gen_free(codec);
475 kfree(spec);
476} 470}
477 471
478#ifdef CONFIG_PM 472#ifdef CONFIG_PM
diff --git a/sound/pci/hda/thinkpad_helper.c b/sound/pci/hda/thinkpad_helper.c
index 8fe3b8c18ed4..6ba0b5517c40 100644
--- a/sound/pci/hda/thinkpad_helper.c
+++ b/sound/pci/hda/thinkpad_helper.c
@@ -63,7 +63,8 @@ static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
63 if (!led_set_func) 63 if (!led_set_func)
64 led_set_func = symbol_request(tpacpi_led_set); 64 led_set_func = symbol_request(tpacpi_led_set);
65 if (!led_set_func) { 65 if (!led_set_func) {
66 snd_printk(KERN_WARNING "Failed to find thinkpad-acpi symbol tpacpi_led_set\n"); 66 codec_warn(codec,
67 "Failed to find thinkpad-acpi symbol tpacpi_led_set\n");
67 return; 68 return;
68 } 69 }
69 70
@@ -75,7 +76,8 @@ static void hda_fixup_thinkpad_acpi(struct hda_codec *codec,
75 } 76 }
76 if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) { 77 if (led_set_func(TPACPI_LED_MICMUTE, false) >= 0) {
77 if (spec->num_adc_nids > 1) 78 if (spec->num_adc_nids > 1)
78 snd_printdd("Skipping micmute LED control due to several ADCs"); 79 codec_dbg(codec,
80 "Skipping micmute LED control due to several ADCs");
79 else { 81 else {
80 spec->cap_sync_hook = update_tpacpi_micmute_led; 82 spec->cap_sync_hook = update_tpacpi_micmute_led;
81 removefunc = false; 83 removefunc = false;
diff --git a/sound/pci/ice1712/aureon.c b/sound/pci/ice1712/aureon.c
index 55902ec40344..3b3cf4ac9060 100644
--- a/sound/pci/ice1712/aureon.c
+++ b/sound/pci/ice1712/aureon.c
@@ -1937,9 +1937,12 @@ static int aureon_add_controls(struct snd_ice1712 *ice)
1937 snd_ice1712_save_gpio_status(ice); 1937 snd_ice1712_save_gpio_status(ice);
1938 id = aureon_cs8415_get(ice, CS8415_ID); 1938 id = aureon_cs8415_get(ice, CS8415_ID);
1939 if (id != 0x41) 1939 if (id != 0x41)
1940 snd_printk(KERN_INFO "No CS8415 chip. Skipping CS8415 controls.\n"); 1940 dev_info(ice->card->dev,
1941 "No CS8415 chip. Skipping CS8415 controls.\n");
1941 else if ((id & 0x0F) != 0x01) 1942 else if ((id & 0x0F) != 0x01)
1942 snd_printk(KERN_INFO "Detected unsupported CS8415 rev. (%c)\n", (char)((id & 0x0F) + 'A' - 1)); 1943 dev_info(ice->card->dev,
1944 "Detected unsupported CS8415 rev. (%c)\n",
1945 (char)((id & 0x0F) + 'A' - 1));
1943 else { 1946 else {
1944 for (i = 0; i < ARRAY_SIZE(cs8415_controls); i++) { 1947 for (i = 0; i < ARRAY_SIZE(cs8415_controls); i++) {
1945 struct snd_kcontrol *kctl; 1948 struct snd_kcontrol *kctl;
diff --git a/sound/pci/ice1712/delta.c b/sound/pci/ice1712/delta.c
index 9e28cc12969b..98e5e955261e 100644
--- a/sound/pci/ice1712/delta.c
+++ b/sound/pci/ice1712/delta.c
@@ -425,7 +425,8 @@ static int snd_ice1712_delta1010lt_wordclock_status_get(struct snd_kcontrol *kco
425 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 425 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
426 426
427 if (snd_i2c_sendbytes(ice->cs8427, &reg, 1) != 1) 427 if (snd_i2c_sendbytes(ice->cs8427, &reg, 1) != 1)
428 snd_printk(KERN_ERR "unable to send register 0x%x byte to CS8427\n", reg); 428 dev_err(ice->card->dev,
429 "unable to send register 0x%x byte to CS8427\n", reg);
429 snd_i2c_readbytes(ice->cs8427, &reg, 1); 430 snd_i2c_readbytes(ice->cs8427, &reg, 1);
430 ucontrol->value.integer.value[0] = (reg & CS8427_UNLOCK) ? 1 : 0; 431 ucontrol->value.integer.value[0] = (reg & CS8427_UNLOCK) ? 1 : 0;
431 return 0; 432 return 0;
@@ -637,7 +638,7 @@ static int snd_ice1712_delta_init(struct snd_ice1712 *ice)
637 case ICE1712_SUBDEVICE_VX442: 638 case ICE1712_SUBDEVICE_VX442:
638 case ICE1712_SUBDEVICE_DELTA66E: 639 case ICE1712_SUBDEVICE_DELTA66E:
639 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { 640 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
640 snd_printk(KERN_ERR "unable to create I2C bus\n"); 641 dev_err(ice->card->dev, "unable to create I2C bus\n");
641 return err; 642 return err;
642 } 643 }
643 ice->i2c->private_data = ice; 644 ice->i2c->private_data = ice;
diff --git a/sound/pci/ice1712/ews.c b/sound/pci/ice1712/ews.c
index bc2e7011c55d..817a1bc50a60 100644
--- a/sound/pci/ice1712/ews.c
+++ b/sound/pci/ice1712/ews.c
@@ -163,7 +163,8 @@ static int snd_ice1712_ews88mt_chip_select(struct snd_ice1712 *ice, int chip_mas
163 163
164 __error: 164 __error:
165 snd_i2c_unlock(ice->i2c); 165 snd_i2c_unlock(ice->i2c);
166 snd_printk(KERN_ERR "AK4524 chip select failed, check cable to the front module\n"); 166 dev_err(ice->card->dev,
167 "AK4524 chip select failed, check cable to the front module\n");
167 return -EIO; 168 return -EIO;
168} 169}
169 170
@@ -174,7 +175,7 @@ static void ews88mt_ak4524_lock(struct snd_akm4xxx *ak, int chip)
174 unsigned char tmp; 175 unsigned char tmp;
175 /* assert AK4524 CS */ 176 /* assert AK4524 CS */
176 if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0) 177 if (snd_ice1712_ews88mt_chip_select(ice, ~(1 << chip) & 0x0f) < 0)
177 snd_printk(KERN_ERR "fatal error (ews88mt chip select)\n"); 178 dev_err(ice->card->dev, "fatal error (ews88mt chip select)\n");
178 snd_ice1712_save_gpio_status(ice); 179 snd_ice1712_save_gpio_status(ice);
179 tmp = ICE1712_EWS88_SERIAL_DATA | 180 tmp = ICE1712_EWS88_SERIAL_DATA |
180 ICE1712_EWS88_SERIAL_CLOCK | 181 ICE1712_EWS88_SERIAL_CLOCK |
@@ -456,7 +457,7 @@ static int snd_ice1712_ews_init(struct snd_ice1712 *ice)
456 457
457 /* create i2c */ 458 /* create i2c */
458 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { 459 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
459 snd_printk(KERN_ERR "unable to create I2C bus\n"); 460 dev_err(ice->card->dev, "unable to create I2C bus\n");
460 return err; 461 return err;
461 } 462 }
462 ice->i2c->private_data = ice; 463 ice->i2c->private_data = ice;
@@ -469,7 +470,8 @@ static int snd_ice1712_ews_init(struct snd_ice1712 *ice)
469 ICE1712_6FIRE_PCF9554_ADDR, 470 ICE1712_6FIRE_PCF9554_ADDR,
470 &spec->i2cdevs[EWS_I2C_6FIRE]); 471 &spec->i2cdevs[EWS_I2C_6FIRE]);
471 if (err < 0) { 472 if (err < 0) {
472 snd_printk(KERN_ERR "PCF9554 initialization failed\n"); 473 dev_err(ice->card->dev,
474 "PCF9554 initialization failed\n");
473 return err; 475 return err;
474 } 476 }
475 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80); 477 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
@@ -834,7 +836,7 @@ static int snd_ice1712_6fire_read_pca(struct snd_ice1712 *ice, unsigned char reg
834 byte = 0; 836 byte = 0;
835 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) { 837 if (snd_i2c_readbytes(spec->i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
836 snd_i2c_unlock(ice->i2c); 838 snd_i2c_unlock(ice->i2c);
837 printk(KERN_ERR "cannot read pca\n"); 839 dev_err(ice->card->dev, "cannot read pca\n");
838 return -EIO; 840 return -EIO;
839 } 841 }
840 snd_i2c_unlock(ice->i2c); 842 snd_i2c_unlock(ice->i2c);
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 28ec872e54c0..0710ec7e69d3 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -394,7 +394,7 @@ int snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr)
394 err = snd_cs8427_create(ice->i2c, addr, 394 err = snd_cs8427_create(ice->i2c, addr,
395 (ice->cs8427_timeout * HZ) / 1000, &ice->cs8427); 395 (ice->cs8427_timeout * HZ) / 1000, &ice->cs8427);
396 if (err < 0) { 396 if (err < 0) {
397 snd_printk(KERN_ERR "CS8427 initialization failed\n"); 397 dev_err(ice->card->dev, "CS8427 initialization failed\n");
398 return err; 398 return err;
399 } 399 }
400 ice->spdif.ops.open = open_cs8427; 400 ice->spdif.ops.open = open_cs8427;
@@ -467,7 +467,7 @@ static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id)
467 u16 pbkstatus; 467 u16 pbkstatus;
468 struct snd_pcm_substream *substream; 468 struct snd_pcm_substream *substream;
469 pbkstatus = inw(ICEDS(ice, INTSTAT)); 469 pbkstatus = inw(ICEDS(ice, INTSTAT));
470 /* printk(KERN_DEBUG "pbkstatus = 0x%x\n", pbkstatus); */ 470 /* dev_dbg(ice->card->dev, "pbkstatus = 0x%x\n", pbkstatus); */
471 for (idx = 0; idx < 6; idx++) { 471 for (idx = 0; idx < 6; idx++) {
472 if ((pbkstatus & (3 << (idx * 2))) == 0) 472 if ((pbkstatus & (3 << (idx * 2))) == 0)
473 continue; 473 continue;
@@ -903,7 +903,8 @@ static int snd_ice1712_pcm(struct snd_ice1712 *ice, int device, struct snd_pcm *
903 if (rpcm) 903 if (rpcm)
904 *rpcm = pcm; 904 *rpcm = pcm;
905 905
906 printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n"); 906 dev_warn(ice->card->dev,
907 "Consumer PCM code does not work well at the moment --jk\n");
907 908
908 return 0; 909 return 0;
909} 910}
@@ -1534,7 +1535,8 @@ static int snd_ice1712_ac97_mixer(struct snd_ice1712 *ice)
1534 ac97.private_free = snd_ice1712_mixer_free_ac97; 1535 ac97.private_free = snd_ice1712_mixer_free_ac97;
1535 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97); 1536 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1536 if (err < 0) 1537 if (err < 0)
1537 printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n"); 1538 dev_warn(ice->card->dev,
1539 "cannot initialize ac97 for consumer, skipped\n");
1538 else { 1540 else {
1539 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice)); 1541 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice));
1540 if (err < 0) 1542 if (err < 0)
@@ -1552,7 +1554,8 @@ static int snd_ice1712_ac97_mixer(struct snd_ice1712 *ice)
1552 ac97.private_free = snd_ice1712_mixer_free_ac97; 1554 ac97.private_free = snd_ice1712_mixer_free_ac97;
1553 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97); 1555 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1554 if (err < 0) 1556 if (err < 0)
1555 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n"); 1557 dev_warn(ice->card->dev,
1558 "cannot initialize pro ac97, skipped\n");
1556 else 1559 else
1557 return 0; 1560 return 0;
1558 } 1561 }
@@ -2332,7 +2335,8 @@ static int snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2332 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device); 2335 pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device);
2333 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device); 2336 ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device);
2334 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) { 2337 if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) {
2335 printk(KERN_ERR "ice1712: No valid ID is found\n"); 2338 dev_err(ice->card->dev,
2339 "No valid ID is found\n");
2336 return -ENXIO; 2340 return -ENXIO;
2337 } 2341 }
2338 } 2342 }
@@ -2340,21 +2344,22 @@ static int snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2340 for (tbl = card_tables; *tbl; tbl++) { 2344 for (tbl = card_tables; *tbl; tbl++) {
2341 for (c = *tbl; c->subvendor; c++) { 2345 for (c = *tbl; c->subvendor; c++) {
2342 if (modelname && c->model && !strcmp(modelname, c->model)) { 2346 if (modelname && c->model && !strcmp(modelname, c->model)) {
2343 printk(KERN_INFO "ice1712: Using board model %s\n", c->name); 2347 dev_info(ice->card->dev,
2348 "Using board model %s\n", c->name);
2344 ice->eeprom.subvendor = c->subvendor; 2349 ice->eeprom.subvendor = c->subvendor;
2345 } else if (c->subvendor != ice->eeprom.subvendor) 2350 } else if (c->subvendor != ice->eeprom.subvendor)
2346 continue; 2351 continue;
2347 if (!c->eeprom_size || !c->eeprom_data) 2352 if (!c->eeprom_size || !c->eeprom_data)
2348 goto found; 2353 goto found;
2349 /* if the EEPROM is given by the driver, use it */ 2354 /* if the EEPROM is given by the driver, use it */
2350 snd_printdd("using the defined eeprom..\n"); 2355 dev_dbg(ice->card->dev, "using the defined eeprom..\n");
2351 ice->eeprom.version = 1; 2356 ice->eeprom.version = 1;
2352 ice->eeprom.size = c->eeprom_size + 6; 2357 ice->eeprom.size = c->eeprom_size + 6;
2353 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size); 2358 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2354 goto read_skipped; 2359 goto read_skipped;
2355 } 2360 }
2356 } 2361 }
2357 printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n", 2362 dev_warn(ice->card->dev, "No matching model found for ID 0x%x\n",
2358 ice->eeprom.subvendor); 2363 ice->eeprom.subvendor);
2359 2364
2360 found: 2365 found:
@@ -2362,12 +2367,13 @@ static int snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2362 if (ice->eeprom.size < 6) 2367 if (ice->eeprom.size < 6)
2363 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */ 2368 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2364 else if (ice->eeprom.size > 32) { 2369 else if (ice->eeprom.size > 32) {
2365 snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size); 2370 dev_err(ice->card->dev,
2371 "invalid EEPROM (size = %i)\n", ice->eeprom.size);
2366 return -EIO; 2372 return -EIO;
2367 } 2373 }
2368 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05); 2374 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2369 if (ice->eeprom.version != 1) { 2375 if (ice->eeprom.version != 1) {
2370 snd_printk(KERN_ERR "invalid EEPROM version %i\n", 2376 dev_err(ice->card->dev, "invalid EEPROM version %i\n",
2371 ice->eeprom.version); 2377 ice->eeprom.version);
2372 /* return -EIO; */ 2378 /* return -EIO; */
2373 } 2379 }
@@ -2553,7 +2559,8 @@ static int snd_ice1712_create(struct snd_card *card,
2553 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2559 /* check, if we can restrict PCI DMA transfers to 28 bits */
2554 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || 2560 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
2555 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { 2561 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) {
2556 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n"); 2562 dev_err(card->dev,
2563 "architecture does not support 28bit PCI busmaster DMA\n");
2557 pci_disable_device(pci); 2564 pci_disable_device(pci);
2558 return -ENXIO; 2565 return -ENXIO;
2559 } 2566 }
@@ -2609,7 +2616,7 @@ static int snd_ice1712_create(struct snd_card *card,
2609 2616
2610 if (request_irq(pci->irq, snd_ice1712_interrupt, IRQF_SHARED, 2617 if (request_irq(pci->irq, snd_ice1712_interrupt, IRQF_SHARED,
2611 KBUILD_MODNAME, ice)) { 2618 KBUILD_MODNAME, ice)) {
2612 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 2619 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
2613 snd_ice1712_free(ice); 2620 snd_ice1712_free(ice);
2614 return -EIO; 2621 return -EIO;
2615 } 2622 }
@@ -2639,8 +2646,6 @@ static int snd_ice1712_create(struct snd_card *card,
2639 return err; 2646 return err;
2640 } 2647 }
2641 2648
2642 snd_card_set_dev(card, &pci->dev);
2643
2644 *r_ice1712 = ice; 2649 *r_ice1712 = ice;
2645 return 0; 2650 return 0;
2646} 2651}
@@ -2670,7 +2675,8 @@ static int snd_ice1712_probe(struct pci_dev *pci,
2670 return -ENOENT; 2675 return -ENOENT;
2671 } 2676 }
2672 2677
2673 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2678 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2679 0, &card);
2674 if (err < 0) 2680 if (err < 0)
2675 return err; 2681 return err;
2676 2682
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index 500471778291..5e7948f3efe9 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -146,7 +146,7 @@ static unsigned char snd_vt1724_ac97_ready(struct snd_ice1712 *ice)
146 continue; 146 continue;
147 return old_cmd; 147 return old_cmd;
148 } 148 }
149 snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n"); 149 dev_dbg(ice->card->dev, "snd_vt1724_ac97_ready: timeout\n");
150 return old_cmd; 150 return old_cmd;
151} 151}
152 152
@@ -156,7 +156,7 @@ static int snd_vt1724_ac97_wait_bit(struct snd_ice1712 *ice, unsigned char bit)
156 for (tm = 0; tm < 0x10000; tm++) 156 for (tm = 0; tm < 0x10000; tm++)
157 if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0) 157 if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0)
158 return 0; 158 return 0;
159 snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n"); 159 dev_dbg(ice->card->dev, "snd_vt1724_ac97_wait_bit: timeout\n");
160 return -EIO; 160 return -EIO;
161} 161}
162 162
@@ -430,10 +430,10 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
430 spin_lock(&ice->reg_lock); 430 spin_lock(&ice->reg_lock);
431 if (++timeout > 10) { 431 if (++timeout > 10) {
432 status = inb(ICEREG1724(ice, IRQSTAT)); 432 status = inb(ICEREG1724(ice, IRQSTAT));
433 printk(KERN_ERR "ice1724: Too long irq loop, " 433 dev_err(ice->card->dev,
434 "status = 0x%x\n", status); 434 "Too long irq loop, status = 0x%x\n", status);
435 if (status & VT1724_IRQ_MPU_TX) { 435 if (status & VT1724_IRQ_MPU_TX) {
436 printk(KERN_ERR "ice1724: Disabling MPU_TX\n"); 436 dev_err(ice->card->dev, "Disabling MPU_TX\n");
437 enable_midi_irq(ice, VT1724_IRQ_MPU_TX, 0); 437 enable_midi_irq(ice, VT1724_IRQ_MPU_TX, 0);
438 } 438 }
439 spin_unlock(&ice->reg_lock); 439 spin_unlock(&ice->reg_lock);
@@ -801,7 +801,7 @@ static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream)
801 spin_unlock_irq(&ice->reg_lock); 801 spin_unlock_irq(&ice->reg_lock);
802 802
803 /* 803 /*
804 printk(KERN_DEBUG "pro prepare: ch = %d, addr = 0x%x, " 804 dev_dbg(ice->card->dev, "pro prepare: ch = %d, addr = 0x%x, "
805 "buffer = 0x%x, period = 0x%x\n", 805 "buffer = 0x%x, period = 0x%x\n",
806 substream->runtime->channels, 806 substream->runtime->channels,
807 (unsigned int)substream->runtime->dma_addr, 807 (unsigned int)substream->runtime->dma_addr,
@@ -821,13 +821,13 @@ static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substrea
821#if 0 /* read PLAYBACK_ADDR */ 821#if 0 /* read PLAYBACK_ADDR */
822 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR)); 822 ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR));
823 if (ptr < substream->runtime->dma_addr) { 823 if (ptr < substream->runtime->dma_addr) {
824 snd_printd("ice1724: invalid negative ptr\n"); 824 dev_dbg(ice->card->dev, "invalid negative ptr\n");
825 return 0; 825 return 0;
826 } 826 }
827 ptr -= substream->runtime->dma_addr; 827 ptr -= substream->runtime->dma_addr;
828 ptr = bytes_to_frames(substream->runtime, ptr); 828 ptr = bytes_to_frames(substream->runtime, ptr);
829 if (ptr >= substream->runtime->buffer_size) { 829 if (ptr >= substream->runtime->buffer_size) {
830 snd_printd("ice1724: invalid ptr %d (size=%d)\n", 830 dev_dbg(ice->card->dev, "invalid ptr %d (size=%d)\n",
831 (int)ptr, (int)substream->runtime->period_size); 831 (int)ptr, (int)substream->runtime->period_size);
832 return 0; 832 return 0;
833 } 833 }
@@ -840,7 +840,7 @@ static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substrea
840 else if (ptr <= substream->runtime->buffer_size) 840 else if (ptr <= substream->runtime->buffer_size)
841 ptr = substream->runtime->buffer_size - ptr; 841 ptr = substream->runtime->buffer_size - ptr;
842 else { 842 else {
843 snd_printd("ice1724: invalid ptr %d (size=%d)\n", 843 dev_dbg(ice->card->dev, "invalid ptr %d (size=%d)\n",
844 (int)ptr, (int)substream->runtime->buffer_size); 844 (int)ptr, (int)substream->runtime->buffer_size);
845 ptr = 0; 845 ptr = 0;
846 } 846 }
@@ -884,7 +884,7 @@ static snd_pcm_uframes_t snd_vt1724_pcm_pointer(struct snd_pcm_substream *substr
884 else if (ptr <= substream->runtime->buffer_size) 884 else if (ptr <= substream->runtime->buffer_size)
885 ptr = substream->runtime->buffer_size - ptr; 885 ptr = substream->runtime->buffer_size - ptr;
886 else { 886 else {
887 snd_printd("ice1724: invalid ptr %d (size=%d)\n", 887 dev_dbg(ice->card->dev, "invalid ptr %d (size=%d)\n",
888 (int)ptr, (int)substream->runtime->buffer_size); 888 (int)ptr, (int)substream->runtime->buffer_size);
889 ptr = 0; 889 ptr = 0;
890 } 890 }
@@ -1508,7 +1508,8 @@ static int snd_vt1724_ac97_mixer(struct snd_ice1712 *ice)
1508 ac97.private_data = ice; 1508 ac97.private_data = ice;
1509 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97); 1509 err = snd_ac97_mixer(pbus, &ac97, &ice->ac97);
1510 if (err < 0) 1510 if (err < 0)
1511 printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n"); 1511 dev_warn(ice->card->dev,
1512 "cannot initialize pro ac97, skipped\n");
1512 else 1513 else
1513 return 0; 1514 return 0;
1514 } 1515 }
@@ -2271,7 +2272,7 @@ static void wait_i2c_busy(struct snd_ice1712 *ice)
2271 while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--) 2272 while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
2272 ; 2273 ;
2273 if (t == -1) 2274 if (t == -1)
2274 printk(KERN_ERR "ice1724: i2c busy timeout\n"); 2275 dev_err(ice->card->dev, "i2c busy timeout\n");
2275} 2276}
2276 2277
2277unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice, 2278unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
@@ -2287,7 +2288,7 @@ unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
2287 val = inb(ICEREG1724(ice, I2C_DATA)); 2288 val = inb(ICEREG1724(ice, I2C_DATA));
2288 mutex_unlock(&ice->i2c_mutex); 2289 mutex_unlock(&ice->i2c_mutex);
2289 /* 2290 /*
2290 printk(KERN_DEBUG "i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val); 2291 dev_dbg(ice->card->dev, "i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
2291 */ 2292 */
2292 return val; 2293 return val;
2293} 2294}
@@ -2298,7 +2299,7 @@ void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
2298 mutex_lock(&ice->i2c_mutex); 2299 mutex_lock(&ice->i2c_mutex);
2299 wait_i2c_busy(ice); 2300 wait_i2c_busy(ice);
2300 /* 2301 /*
2301 printk(KERN_DEBUG "i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data); 2302 dev_dbg(ice->card->dev, "i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
2302 */ 2303 */
2303 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR)); 2304 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
2304 outb(data, ICEREG1724(ice, I2C_DATA)); 2305 outb(data, ICEREG1724(ice, I2C_DATA));
@@ -2335,7 +2336,8 @@ static int snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
2335 ((unsigned int)swab16(vendor) << 16) | swab16(device); 2336 ((unsigned int)swab16(vendor) << 16) | swab16(device);
2336 if (ice->eeprom.subvendor == 0 || 2337 if (ice->eeprom.subvendor == 0 ||
2337 ice->eeprom.subvendor == (unsigned int)-1) { 2338 ice->eeprom.subvendor == (unsigned int)-1) {
2338 printk(KERN_ERR "ice1724: No valid ID is found\n"); 2339 dev_err(ice->card->dev,
2340 "No valid ID is found\n");
2339 return -ENXIO; 2341 return -ENXIO;
2340 } 2342 }
2341 } 2343 }
@@ -2344,7 +2346,8 @@ static int snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
2344 for (c = *tbl; c->name; c++) { 2346 for (c = *tbl; c->name; c++) {
2345 if (modelname && c->model && 2347 if (modelname && c->model &&
2346 !strcmp(modelname, c->model)) { 2348 !strcmp(modelname, c->model)) {
2347 printk(KERN_INFO "ice1724: Using board model %s\n", 2349 dev_info(ice->card->dev,
2350 "Using board model %s\n",
2348 c->name); 2351 c->name);
2349 ice->eeprom.subvendor = c->subvendor; 2352 ice->eeprom.subvendor = c->subvendor;
2350 } else if (c->subvendor != ice->eeprom.subvendor) 2353 } else if (c->subvendor != ice->eeprom.subvendor)
@@ -2353,14 +2356,14 @@ static int snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
2353 if (!c->eeprom_size || !c->eeprom_data) 2356 if (!c->eeprom_size || !c->eeprom_data)
2354 goto found; 2357 goto found;
2355 /* if the EEPROM is given by the driver, use it */ 2358 /* if the EEPROM is given by the driver, use it */
2356 snd_printdd("using the defined eeprom..\n"); 2359 dev_dbg(ice->card->dev, "using the defined eeprom..\n");
2357 ice->eeprom.version = 2; 2360 ice->eeprom.version = 2;
2358 ice->eeprom.size = c->eeprom_size + 6; 2361 ice->eeprom.size = c->eeprom_size + 6;
2359 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size); 2362 memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size);
2360 goto read_skipped; 2363 goto read_skipped;
2361 } 2364 }
2362 } 2365 }
2363 printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n", 2366 dev_warn(ice->card->dev, "No matching model found for ID 0x%x\n",
2364 ice->eeprom.subvendor); 2367 ice->eeprom.subvendor);
2365#ifdef CONFIG_PM_SLEEP 2368#ifdef CONFIG_PM_SLEEP
2366 /* assume AC97-only card which can suspend without additional code */ 2369 /* assume AC97-only card which can suspend without additional code */
@@ -2372,13 +2375,13 @@ static int snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
2372 if (ice->eeprom.size < 6) 2375 if (ice->eeprom.size < 6)
2373 ice->eeprom.size = 32; 2376 ice->eeprom.size = 32;
2374 else if (ice->eeprom.size > 32) { 2377 else if (ice->eeprom.size > 32) {
2375 printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n", 2378 dev_err(ice->card->dev, "Invalid EEPROM (size = %i)\n",
2376 ice->eeprom.size); 2379 ice->eeprom.size);
2377 return -EIO; 2380 return -EIO;
2378 } 2381 }
2379 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05); 2382 ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05);
2380 if (ice->eeprom.version != 1 && ice->eeprom.version != 2) 2383 if (ice->eeprom.version != 1 && ice->eeprom.version != 2)
2381 printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n", 2384 dev_warn(ice->card->dev, "Invalid EEPROM version %i\n",
2382 ice->eeprom.version); 2385 ice->eeprom.version);
2383 size = ice->eeprom.size - 6; 2386 size = ice->eeprom.size - 6;
2384 for (i = 0; i < size; i++) 2387 for (i = 0; i < size; i++)
@@ -2586,7 +2589,7 @@ static int snd_vt1724_create(struct snd_card *card,
2586 2589
2587 if (request_irq(pci->irq, snd_vt1724_interrupt, 2590 if (request_irq(pci->irq, snd_vt1724_interrupt,
2588 IRQF_SHARED, KBUILD_MODNAME, ice)) { 2591 IRQF_SHARED, KBUILD_MODNAME, ice)) {
2589 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 2592 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
2590 snd_vt1724_free(ice); 2593 snd_vt1724_free(ice);
2591 return -EIO; 2594 return -EIO;
2592 } 2595 }
@@ -2609,8 +2612,6 @@ static int snd_vt1724_create(struct snd_card *card,
2609 return err; 2612 return err;
2610 } 2613 }
2611 2614
2612 snd_card_set_dev(card, &pci->dev);
2613
2614 *r_ice1712 = ice; 2615 *r_ice1712 = ice;
2615 return 0; 2616 return 0;
2616} 2617}
@@ -2638,7 +2639,8 @@ static int snd_vt1724_probe(struct pci_dev *pci,
2638 return -ENOENT; 2639 return -ENOENT;
2639 } 2640 }
2640 2641
2641 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2642 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2643 0, &card);
2642 if (err < 0) 2644 if (err < 0)
2643 return err; 2645 return err;
2644 2646
diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c
index 8855933e710d..7a6c0786c55c 100644
--- a/sound/pci/ice1712/juli.c
+++ b/sound/pci/ice1712/juli.c
@@ -244,7 +244,7 @@ static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
244 /* AK5385 first, since it requires cold reset affecting both codecs */ 244 /* AK5385 first, since it requires cold reset affecting both codecs */
245 old_gpio = ice->gpio.get_data(ice); 245 old_gpio = ice->gpio.get_data(ice);
246 new_gpio = (old_gpio & ~GPIO_AK5385A_MASK) | ak5385_pins; 246 new_gpio = (old_gpio & ~GPIO_AK5385A_MASK) | ak5385_pins;
247 /* printk(KERN_DEBUG "JULI - ak5385 set_rate_val: new gpio 0x%x\n", 247 /* dev_dbg(ice->card->dev, "JULI - ak5385 set_rate_val: new gpio 0x%x\n",
248 new_gpio); */ 248 new_gpio); */
249 ice->gpio.set_data(ice, new_gpio); 249 ice->gpio.set_data(ice, new_gpio);
250 250
@@ -344,7 +344,7 @@ static int juli_mute_put(struct snd_kcontrol *kcontrol,
344 new_gpio = old_gpio & 344 new_gpio = old_gpio &
345 ~((unsigned int) kcontrol->private_value); 345 ~((unsigned int) kcontrol->private_value);
346 } 346 }
347 /* printk(KERN_DEBUG 347 /* dev_dbg(ice->card->dev,
348 "JULI - mute/unmute: control_value: 0x%x, old_gpio: 0x%x, " 348 "JULI - mute/unmute: control_value: 0x%x, old_gpio: 0x%x, "
349 "new_gpio 0x%x\n", 349 "new_gpio 0x%x\n",
350 (unsigned int)ucontrol->value.integer.value[0], old_gpio, 350 (unsigned int)ucontrol->value.integer.value[0], old_gpio,
@@ -439,9 +439,9 @@ static void add_slaves(struct snd_card *card,
439{ 439{
440 for (; *list; list++) { 440 for (; *list; list++) {
441 struct snd_kcontrol *slave = ctl_find(card, *list); 441 struct snd_kcontrol *slave = ctl_find(card, *list);
442 /* printk(KERN_DEBUG "add_slaves - %s\n", *list); */ 442 /* dev_dbg(card->dev, "add_slaves - %s\n", *list); */
443 if (slave) { 443 if (slave) {
444 /* printk(KERN_DEBUG "slave %s found\n", *list); */ 444 /* dev_dbg(card->dev, "slave %s found\n", *list); */
445 snd_ctl_add_slave(master, slave); 445 snd_ctl_add_slave(master, slave);
446 } 446 }
447 } 447 }
@@ -536,7 +536,7 @@ static void juli_set_rate(struct snd_ice1712 *ice, unsigned int rate)
536 536
537 old = ice->gpio.get_data(ice); 537 old = ice->gpio.get_data(ice);
538 new = (old & ~GPIO_RATE_MASK) | get_gpio_val(rate); 538 new = (old & ~GPIO_RATE_MASK) | get_gpio_val(rate);
539 /* printk(KERN_DEBUG "JULI - set_rate: old %x, new %x\n", 539 /* dev_dbg(ice->card->dev, "JULI - set_rate: old %x, new %x\n",
540 old & GPIO_RATE_MASK, 540 old & GPIO_RATE_MASK,
541 new & GPIO_RATE_MASK); */ 541 new & GPIO_RATE_MASK); */
542 542
@@ -573,7 +573,7 @@ static void juli_ak4114_change(struct ak4114 *ak4114, unsigned char c0,
573 if (ice->is_spdif_master(ice) && c1) { 573 if (ice->is_spdif_master(ice) && c1) {
574 /* only for SPDIF master mode, rate was changed */ 574 /* only for SPDIF master mode, rate was changed */
575 rate = snd_ak4114_external_rate(ak4114); 575 rate = snd_ak4114_external_rate(ak4114);
576 /* printk(KERN_DEBUG "ak4114 - input rate changed to %d\n", 576 /* dev_dbg(ice->card->dev, "ak4114 - input rate changed to %d\n",
577 rate); */ 577 rate); */
578 juli_akm_set_rate_val(ice->akm, rate); 578 juli_akm_set_rate_val(ice->akm, rate);
579 } 579 }
@@ -628,7 +628,7 @@ static int juli_init(struct snd_ice1712 *ice)
628#endif 628#endif
629 629
630 if (spec->analog) { 630 if (spec->analog) {
631 printk(KERN_INFO "juli@: analog I/O detected\n"); 631 dev_info(ice->card->dev, "juli@: analog I/O detected\n");
632 ice->num_total_dacs = 2; 632 ice->num_total_dacs = 2;
633 ice->num_total_adcs = 2; 633 ice->num_total_adcs = 2;
634 634
diff --git a/sound/pci/ice1712/prodigy192.c b/sound/pci/ice1712/prodigy192.c
index e610339f7601..f3b491aa3e22 100644
--- a/sound/pci/ice1712/prodigy192.c
+++ b/sound/pci/ice1712/prodigy192.c
@@ -98,7 +98,7 @@ static int stac9460_dac_mute(struct snd_ice1712 *ice, int idx,
98 new = (~mute << 7 & 0x80) | (old & ~0x80); 98 new = (~mute << 7 & 0x80) | (old & ~0x80);
99 change = (new != old); 99 change = (new != old);
100 if (change) 100 if (change)
101 /*printk ("Volume register 0x%02x: 0x%02x\n", idx, new);*/ 101 /* dev_dbg(ice->card->dev, "Volume register 0x%02x: 0x%02x\n", idx, new);*/
102 stac9460_put(ice, idx, new); 102 stac9460_put(ice, idx, new);
103 return change; 103 return change;
104} 104}
@@ -133,7 +133,7 @@ static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
133 /* due to possible conflicts with stac9460_set_rate_val, mutexing */ 133 /* due to possible conflicts with stac9460_set_rate_val, mutexing */
134 mutex_lock(&spec->mute_mutex); 134 mutex_lock(&spec->mute_mutex);
135 /* 135 /*
136 printk(KERN_DEBUG "Mute put: reg 0x%02x, ctrl value: 0x%02x\n", idx, 136 dev_dbg(ice->card->dev, "Mute put: reg 0x%02x, ctrl value: 0x%02x\n", idx,
137 ucontrol->value.integer.value[0]); 137 ucontrol->value.integer.value[0]);
138 */ 138 */
139 change = stac9460_dac_mute(ice, idx, ucontrol->value.integer.value[0]); 139 change = stac9460_dac_mute(ice, idx, ucontrol->value.integer.value[0]);
@@ -187,7 +187,7 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
187 if (change) { 187 if (change) {
188 ovol = (0x7f - nvol) | (tmp & 0x80); 188 ovol = (0x7f - nvol) | (tmp & 0x80);
189 /* 189 /*
190 printk(KERN_DEBUG "DAC Volume: reg 0x%02x: 0x%02x\n", 190 dev_dbg(ice->card->dev, "DAC Volume: reg 0x%02x: 0x%02x\n",
191 idx, ovol); 191 idx, ovol);
192 */ 192 */
193 stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80)); 193 stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
@@ -348,7 +348,7 @@ static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
348 for (idx = 0; idx < 7 ; ++idx) 348 for (idx = 0; idx < 7 ; ++idx)
349 changed[idx] = stac9460_dac_mute(ice, 349 changed[idx] = stac9460_dac_mute(ice,
350 STAC946X_MASTER_VOLUME + idx, 0); 350 STAC946X_MASTER_VOLUME + idx, 0);
351 /*printk(KERN_DEBUG "Rate change: %d, new MC: 0x%02x\n", rate, new);*/ 351 /*dev_dbg(ice->card->dev, "Rate change: %d, new MC: 0x%02x\n", rate, new);*/
352 stac9460_put(ice, STAC946X_MASTER_CLOCKING, new); 352 stac9460_put(ice, STAC946X_MASTER_CLOCKING, new);
353 udelay(10); 353 udelay(10);
354 /* unmuting - only originally unmuted dacs - 354 /* unmuting - only originally unmuted dacs -
@@ -768,9 +768,10 @@ static int prodigy192_init(struct snd_ice1712 *ice)
768 /* from this moment if err = 0 then 768 /* from this moment if err = 0 then
769 * spec->ak4114 should not be null 769 * spec->ak4114 should not be null
770 */ 770 */
771 snd_printdd("AK4114 initialized with status %d\n", err); 771 dev_dbg(ice->card->dev,
772 "AK4114 initialized with status %d\n", err);
772 } else 773 } else
773 snd_printdd("AK4114 not found\n"); 774 dev_dbg(ice->card->dev, "AK4114 not found\n");
774 if (err < 0) 775 if (err < 0)
775 return err; 776 return err;
776 777
diff --git a/sound/pci/ice1712/quartet.c b/sound/pci/ice1712/quartet.c
index 71c6003ef338..2c2df4b74e01 100644
--- a/sound/pci/ice1712/quartet.c
+++ b/sound/pci/ice1712/quartet.c
@@ -280,7 +280,7 @@ static void qtet_akm_write(struct snd_akm4xxx *ak, int chip,
280 280
281 if (snd_BUG_ON(chip < 0 || chip >= 4)) 281 if (snd_BUG_ON(chip < 0 || chip >= 4))
282 return; 282 return;
283 /*printk(KERN_DEBUG "Writing to AK4620: chip=%d, addr=0x%x, 283 /*dev_dbg(ice->card->dev, "Writing to AK4620: chip=%d, addr=0x%x,
284 data=0x%x\n", chip, addr, data);*/ 284 data=0x%x\n", chip, addr, data);*/
285 orig_dir = ice->gpio.get_dir(ice); 285 orig_dir = ice->gpio.get_dir(ice);
286 ice->gpio.set_dir(ice, orig_dir | GPIO_SPI_ALL); 286 ice->gpio.set_dir(ice, orig_dir | GPIO_SPI_ALL);
@@ -898,7 +898,7 @@ static void qtet_set_rate(struct snd_ice1712 *ice, unsigned int rate)
898 new = (get_cpld(ice) & ~CPLD_CKS_MASK) | get_cks_val(rate); 898 new = (get_cpld(ice) & ~CPLD_CKS_MASK) | get_cks_val(rate);
899 /* switch to internal clock, drop CPLD_SYNC_SEL */ 899 /* switch to internal clock, drop CPLD_SYNC_SEL */
900 new &= ~CPLD_SYNC_SEL; 900 new &= ~CPLD_SYNC_SEL;
901 /* printk(KERN_DEBUG "QT - set_rate: old %x, new %x\n", 901 /* dev_dbg(ice->card->dev, "QT - set_rate: old %x, new %x\n",
902 get_cpld(ice), new); */ 902 get_cpld(ice), new); */
903 set_cpld(ice, new); 903 set_cpld(ice, new);
904} 904}
@@ -978,7 +978,7 @@ static void qtet_ak4113_change(struct ak4113 *ak4113, unsigned char c0,
978 c1) { 978 c1) {
979 /* only for SPDIF master mode, rate was changed */ 979 /* only for SPDIF master mode, rate was changed */
980 rate = snd_ak4113_external_rate(ak4113); 980 rate = snd_ak4113_external_rate(ak4113);
981 /* printk(KERN_DEBUG "ak4113 - input rate changed to %d\n", 981 /* dev_dbg(ice->card->dev, "ak4113 - input rate changed to %d\n",
982 rate); */ 982 rate); */
983 qtet_akm_set_rate_val(ice->akm, rate); 983 qtet_akm_set_rate_val(ice->akm, rate);
984 } 984 }
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 08d8733604a2..68340d7df76d 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -547,7 +547,8 @@ static int snd_intel8x0_codec_semaphore(struct intel8x0 *chip, unsigned int code
547 /* access to some forbidden (non existent) ac97 registers will not 547 /* access to some forbidden (non existent) ac97 registers will not
548 * reset the semaphore. So even if you don't get the semaphore, still 548 * reset the semaphore. So even if you don't get the semaphore, still
549 * continue the access. We don't need the semaphore anyway. */ 549 * continue the access. We don't need the semaphore anyway. */
550 snd_printk(KERN_ERR "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n", 550 dev_err(chip->card->dev,
551 "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
551 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA))); 552 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
552 iagetword(chip, 0); /* clear semaphore flag */ 553 iagetword(chip, 0); /* clear semaphore flag */
553 /* I don't care about the semaphore */ 554 /* I don't care about the semaphore */
@@ -562,7 +563,9 @@ static void snd_intel8x0_codec_write(struct snd_ac97 *ac97,
562 563
563 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) { 564 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
564 if (! chip->in_ac97_init) 565 if (! chip->in_ac97_init)
565 snd_printk(KERN_ERR "codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 566 dev_err(chip->card->dev,
567 "codec_write %d: semaphore is not ready for register 0x%x\n",
568 ac97->num, reg);
566 } 569 }
567 iaputword(chip, reg + ac97->num * 0x80, val); 570 iaputword(chip, reg + ac97->num * 0x80, val);
568} 571}
@@ -576,7 +579,9 @@ static unsigned short snd_intel8x0_codec_read(struct snd_ac97 *ac97,
576 579
577 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) { 580 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
578 if (! chip->in_ac97_init) 581 if (! chip->in_ac97_init)
579 snd_printk(KERN_ERR "codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 582 dev_err(chip->card->dev,
583 "codec_read %d: semaphore is not ready for register 0x%x\n",
584 ac97->num, reg);
580 res = 0xffff; 585 res = 0xffff;
581 } else { 586 } else {
582 res = iagetword(chip, reg + ac97->num * 0x80); 587 res = iagetword(chip, reg + ac97->num * 0x80);
@@ -585,7 +590,9 @@ static unsigned short snd_intel8x0_codec_read(struct snd_ac97 *ac97,
585 iputdword(chip, ICHREG(GLOB_STA), tmp & 590 iputdword(chip, ICHREG(GLOB_STA), tmp &
586 ~(chip->codec_ready_bits | ICH_GSCI)); 591 ~(chip->codec_ready_bits | ICH_GSCI));
587 if (! chip->in_ac97_init) 592 if (! chip->in_ac97_init)
588 snd_printk(KERN_ERR "codec_read %d: read timeout for register 0x%x\n", ac97->num, reg); 593 dev_err(chip->card->dev,
594 "codec_read %d: read timeout for register 0x%x\n",
595 ac97->num, reg);
589 res = 0xffff; 596 res = 0xffff;
590 } 597 }
591 } 598 }
@@ -619,7 +626,7 @@ static int snd_intel8x0_ali_codec_ready(struct intel8x0 *chip, int mask)
619 return 0; 626 return 0;
620 } 627 }
621 if (! chip->in_ac97_init) 628 if (! chip->in_ac97_init)
622 snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.\n"); 629 dev_warn(chip->card->dev, "AC97 codec ready timeout.\n");
623 return -EBUSY; 630 return -EBUSY;
624} 631}
625 632
@@ -631,7 +638,7 @@ static int snd_intel8x0_ali_codec_semaphore(struct intel8x0 *chip)
631 while (--time && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY)) 638 while (--time && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY))
632 udelay(1); 639 udelay(1);
633 if (! time && ! chip->in_ac97_init) 640 if (! time && ! chip->in_ac97_init)
634 snd_printk(KERN_WARNING "ali_codec_semaphore timeout\n"); 641 dev_warn(chip->card->dev, "ali_codec_semaphore timeout\n");
635 return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY); 642 return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
636} 643}
637 644
@@ -700,7 +707,7 @@ static void snd_intel8x0_setup_periods(struct intel8x0 *chip, struct ichdev *ich
700 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */ 707 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
701 ichdev->fragsize >> ichdev->pos_shift); 708 ichdev->fragsize >> ichdev->pos_shift);
702#if 0 709#if 0
703 printk(KERN_DEBUG "bdbar[%i] = 0x%x [0x%x]\n", 710 dev_dbg(chip->card->dev, "bdbar[%i] = 0x%x [0x%x]\n",
704 idx + 0, bdbar[idx + 0], bdbar[idx + 1]); 711 idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
705#endif 712#endif
706 } 713 }
@@ -712,8 +719,8 @@ static void snd_intel8x0_setup_periods(struct intel8x0 *chip, struct ichdev *ich
712 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags; 719 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
713 ichdev->position = 0; 720 ichdev->position = 0;
714#if 0 721#if 0
715 printk(KERN_DEBUG "lvi_frag = %i, frags = %i, period_size = 0x%x, " 722 dev_dbg(chip->card->dev,
716 "period_size1 = 0x%x\n", 723 "lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
717 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize, 724 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize,
718 ichdev->fragsize1); 725 ichdev->fragsize1);
719#endif 726#endif
@@ -781,8 +788,8 @@ static inline void snd_intel8x0_update(struct intel8x0 *chip, struct ichdev *ich
781 ichdev->lvi_frag %= ichdev->frags; 788 ichdev->lvi_frag %= ichdev->frags;
782 ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1); 789 ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
783#if 0 790#if 0
784 printk(KERN_DEBUG "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, " 791 dev_dbg(chip->card->dev,
785 "all = 0x%x, 0x%x\n", 792 "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n",
786 ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2], 793 ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
787 ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port), 794 ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
788 inl(port + 4), inb(port + ICH_REG_OFF_CR)); 795 inl(port + 4), inb(port + ICH_REG_OFF_CR));
@@ -2289,7 +2296,8 @@ static int snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
2289 ac97.num = i; 2296 ac97.num = i;
2290 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) { 2297 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
2291 if (err != -EACCES) 2298 if (err != -EACCES)
2292 snd_printk(KERN_ERR "Unable to initialize codec #%d\n", i); 2299 dev_err(chip->card->dev,
2300 "Unable to initialize codec #%d\n", i);
2293 if (i == 0) 2301 if (i == 0)
2294 goto __err; 2302 goto __err;
2295 } 2303 }
@@ -2441,7 +2449,7 @@ static int snd_intel8x0_ich_chip_reset(struct intel8x0 *chip)
2441 return 0; 2449 return 0;
2442 schedule_timeout_uninterruptible(1); 2450 schedule_timeout_uninterruptible(1);
2443 } while (time_after_eq(end_time, jiffies)); 2451 } while (time_after_eq(end_time, jiffies));
2444 snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]\n", 2452 dev_err(chip->card->dev, "AC'97 warm reset still in progress? [0x%x]\n",
2445 igetdword(chip, ICHREG(GLOB_CNT))); 2453 igetdword(chip, ICHREG(GLOB_CNT)));
2446 return -EIO; 2454 return -EIO;
2447} 2455}
@@ -2483,7 +2491,8 @@ static int snd_intel8x0_ich_chip_init(struct intel8x0 *chip, int probing)
2483 } while (time_after_eq(end_time, jiffies)); 2491 } while (time_after_eq(end_time, jiffies));
2484 if (! status) { 2492 if (! status) {
2485 /* no codec is found */ 2493 /* no codec is found */
2486 snd_printk(KERN_ERR "codec_ready: codec is not ready [0x%x]\n", 2494 dev_err(chip->card->dev,
2495 "codec_ready: codec is not ready [0x%x]\n",
2487 igetdword(chip, ICHREG(GLOB_STA))); 2496 igetdword(chip, ICHREG(GLOB_STA)));
2488 return -EIO; 2497 return -EIO;
2489 } 2498 }
@@ -2547,7 +2556,7 @@ static int snd_intel8x0_ali_chip_init(struct intel8x0 *chip, int probing)
2547 goto __ok; 2556 goto __ok;
2548 schedule_timeout_uninterruptible(1); 2557 schedule_timeout_uninterruptible(1);
2549 } 2558 }
2550 snd_printk(KERN_ERR "AC'97 reset failed.\n"); 2559 dev_err(chip->card->dev, "AC'97 reset failed.\n");
2551 if (probing) 2560 if (probing)
2552 return -EIO; 2561 return -EIO;
2553 2562
@@ -2591,7 +2600,7 @@ static int snd_intel8x0_chip_init(struct intel8x0 *chip, int probing)
2591 break; 2600 break;
2592 } 2601 }
2593 if (timeout == 0) 2602 if (timeout == 0)
2594 printk(KERN_ERR "intel8x0: reset of registers failed?\n"); 2603 dev_err(chip->card->dev, "reset of registers failed?\n");
2595 } 2604 }
2596 /* initialize Buffer Descriptor Lists */ 2605 /* initialize Buffer Descriptor Lists */
2597 for (i = 0; i < chip->bdbars_count; i++) 2606 for (i = 0; i < chip->bdbars_count; i++)
@@ -2692,8 +2701,7 @@ static int intel8x0_resume(struct device *dev)
2692 pci_set_power_state(pci, PCI_D0); 2701 pci_set_power_state(pci, PCI_D0);
2693 pci_restore_state(pci); 2702 pci_restore_state(pci);
2694 if (pci_enable_device(pci) < 0) { 2703 if (pci_enable_device(pci) < 0) {
2695 printk(KERN_ERR "intel8x0: pci_enable_device failed, " 2704 dev_err(dev, "pci_enable_device failed, disabling device\n");
2696 "disabling device\n");
2697 snd_card_disconnect(card); 2705 snd_card_disconnect(card);
2698 return -EIO; 2706 return -EIO;
2699 } 2707 }
@@ -2701,8 +2709,8 @@ static int intel8x0_resume(struct device *dev)
2701 snd_intel8x0_chip_init(chip, 0); 2709 snd_intel8x0_chip_init(chip, 0);
2702 if (request_irq(pci->irq, snd_intel8x0_interrupt, 2710 if (request_irq(pci->irq, snd_intel8x0_interrupt,
2703 IRQF_SHARED, KBUILD_MODNAME, chip)) { 2711 IRQF_SHARED, KBUILD_MODNAME, chip)) {
2704 printk(KERN_ERR "intel8x0: unable to grab IRQ %d, " 2712 dev_err(dev, "unable to grab IRQ %d, disabling device\n",
2705 "disabling device\n", pci->irq); 2713 pci->irq);
2706 snd_card_disconnect(card); 2714 snd_card_disconnect(card);
2707 return -EIO; 2715 return -EIO;
2708 } 2716 }
@@ -2779,7 +2787,8 @@ static void intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2779 __again: 2787 __again:
2780 subs = chip->pcm[0]->streams[0].substream; 2788 subs = chip->pcm[0]->streams[0].substream;
2781 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) { 2789 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
2782 snd_printk(KERN_WARNING "no playback buffer allocated - aborting measure ac97 clock\n"); 2790 dev_warn(chip->card->dev,
2791 "no playback buffer allocated - aborting measure ac97 clock\n");
2783 return; 2792 return;
2784 } 2793 }
2785 ichdev = &chip->ichd[ICHD_PCMOUT]; 2794 ichdev = &chip->ichd[ICHD_PCMOUT];
@@ -2789,7 +2798,8 @@ static void intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2789 2798
2790 /* set rate */ 2799 /* set rate */
2791 if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) { 2800 if (snd_ac97_set_rate(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 48000) < 0) {
2792 snd_printk(KERN_ERR "cannot set ac97 rate: clock = %d\n", chip->ac97_bus->clock); 2801 dev_err(chip->card->dev, "cannot set ac97 rate: clock = %d\n",
2802 chip->ac97_bus->clock);
2793 return; 2803 return;
2794 } 2804 }
2795 snd_intel8x0_setup_periods(chip, ichdev); 2805 snd_intel8x0_setup_periods(chip, ichdev);
@@ -2843,7 +2853,8 @@ static void intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2843 spin_unlock_irq(&chip->reg_lock); 2853 spin_unlock_irq(&chip->reg_lock);
2844 2854
2845 if (pos == 0) { 2855 if (pos == 0) {
2846 snd_printk(KERN_ERR "intel8x0: measure - unreliable DMA position..\n"); 2856 dev_err(chip->card->dev,
2857 "measure - unreliable DMA position..\n");
2847 __retry: 2858 __retry:
2848 if (attempt < 3) { 2859 if (attempt < 3) {
2849 msleep(300); 2860 msleep(300);
@@ -2857,16 +2868,17 @@ static void intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2857 t = stop_time.tv_sec - start_time.tv_sec; 2868 t = stop_time.tv_sec - start_time.tv_sec;
2858 t *= 1000000; 2869 t *= 1000000;
2859 t += (stop_time.tv_nsec - start_time.tv_nsec) / 1000; 2870 t += (stop_time.tv_nsec - start_time.tv_nsec) / 1000;
2860 printk(KERN_INFO "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos); 2871 dev_info(chip->card->dev,
2872 "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos);
2861 if (t == 0) { 2873 if (t == 0) {
2862 snd_printk(KERN_ERR "intel8x0: ?? calculation error..\n"); 2874 dev_err(chip->card->dev, "?? calculation error..\n");
2863 goto __retry; 2875 goto __retry;
2864 } 2876 }
2865 pos *= 1000; 2877 pos *= 1000;
2866 pos = (pos / t) * 1000 + ((pos % t) * 1000) / t; 2878 pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
2867 if (pos < 40000 || pos >= 60000) { 2879 if (pos < 40000 || pos >= 60000) {
2868 /* abnormal value. hw problem? */ 2880 /* abnormal value. hw problem? */
2869 printk(KERN_INFO "intel8x0: measured clock %ld rejected\n", pos); 2881 dev_info(chip->card->dev, "measured clock %ld rejected\n", pos);
2870 goto __retry; 2882 goto __retry;
2871 } else if (pos > 40500 && pos < 41500) 2883 } else if (pos > 40500 && pos < 41500)
2872 /* first exception - 41000Hz reference clock */ 2884 /* first exception - 41000Hz reference clock */
@@ -2878,7 +2890,7 @@ static void intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2878 /* not 48000Hz, tuning the clock.. */ 2890 /* not 48000Hz, tuning the clock.. */
2879 chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos; 2891 chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
2880 __end: 2892 __end:
2881 printk(KERN_INFO "intel8x0: clocking to %d\n", chip->ac97_bus->clock); 2893 dev_info(chip->card->dev, "clocking to %d\n", chip->ac97_bus->clock);
2882 snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0); 2894 snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0);
2883} 2895}
2884 2896
@@ -2899,7 +2911,7 @@ static int intel8x0_in_clock_list(struct intel8x0 *chip)
2899 wl = snd_pci_quirk_lookup(pci, intel8x0_clock_list); 2911 wl = snd_pci_quirk_lookup(pci, intel8x0_clock_list);
2900 if (!wl) 2912 if (!wl)
2901 return 0; 2913 return 0;
2902 printk(KERN_INFO "intel8x0: white list rate for %04x:%04x is %i\n", 2914 dev_info(chip->card->dev, "white list rate for %04x:%04x is %i\n",
2903 pci->subsystem_vendor, pci->subsystem_device, wl->value); 2915 pci->subsystem_vendor, pci->subsystem_device, wl->value);
2904 chip->ac97_bus->clock = wl->value; 2916 chip->ac97_bus->clock = wl->value;
2905 return 1; 2917 return 1;
@@ -3003,7 +3015,7 @@ static int snd_intel8x0_inside_vm(struct pci_dev *pci)
3003 3015
3004fini: 3016fini:
3005 if (msg != NULL) 3017 if (msg != NULL)
3006 printk(KERN_INFO "intel8x0: %s optimization\n", msg); 3018 dev_info(&pci->dev, "%s optimization\n", msg);
3007 3019
3008 return result; 3020 return result;
3009} 3021}
@@ -3098,7 +3110,7 @@ static int snd_intel8x0_create(struct snd_card *card,
3098 else 3110 else
3099 chip->addr = pci_iomap(pci, 0, 0); 3111 chip->addr = pci_iomap(pci, 0, 0);
3100 if (!chip->addr) { 3112 if (!chip->addr) {
3101 snd_printk(KERN_ERR "AC'97 space ioremap problem\n"); 3113 dev_err(card->dev, "AC'97 space ioremap problem\n");
3102 snd_intel8x0_free(chip); 3114 snd_intel8x0_free(chip);
3103 return -EIO; 3115 return -EIO;
3104 } 3116 }
@@ -3107,7 +3119,7 @@ static int snd_intel8x0_create(struct snd_card *card,
3107 else 3119 else
3108 chip->bmaddr = pci_iomap(pci, 1, 0); 3120 chip->bmaddr = pci_iomap(pci, 1, 0);
3109 if (!chip->bmaddr) { 3121 if (!chip->bmaddr) {
3110 snd_printk(KERN_ERR "Controller space ioremap problem\n"); 3122 dev_err(card->dev, "Controller space ioremap problem\n");
3111 snd_intel8x0_free(chip); 3123 snd_intel8x0_free(chip);
3112 return -EIO; 3124 return -EIO;
3113 } 3125 }
@@ -3152,7 +3164,7 @@ static int snd_intel8x0_create(struct snd_card *card,
3152 chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2, 3164 chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2,
3153 &chip->bdbars) < 0) { 3165 &chip->bdbars) < 0) {
3154 snd_intel8x0_free(chip); 3166 snd_intel8x0_free(chip);
3155 snd_printk(KERN_ERR "intel8x0: cannot allocate buffer descriptors\n"); 3167 dev_err(card->dev, "cannot allocate buffer descriptors\n");
3156 return -ENOMEM; 3168 return -ENOMEM;
3157 } 3169 }
3158 /* tables must be aligned to 8 bytes here, but the kernel pages 3170 /* tables must be aligned to 8 bytes here, but the kernel pages
@@ -3206,7 +3218,7 @@ static int snd_intel8x0_create(struct snd_card *card,
3206 /* request irq after initializaing int_sta_mask, etc */ 3218 /* request irq after initializaing int_sta_mask, etc */
3207 if (request_irq(pci->irq, snd_intel8x0_interrupt, 3219 if (request_irq(pci->irq, snd_intel8x0_interrupt,
3208 IRQF_SHARED, KBUILD_MODNAME, chip)) { 3220 IRQF_SHARED, KBUILD_MODNAME, chip)) {
3209 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 3221 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
3210 snd_intel8x0_free(chip); 3222 snd_intel8x0_free(chip);
3211 return -EBUSY; 3223 return -EBUSY;
3212 } 3224 }
@@ -3217,8 +3229,6 @@ static int snd_intel8x0_create(struct snd_card *card,
3217 return err; 3229 return err;
3218 } 3230 }
3219 3231
3220 snd_card_set_dev(card, &pci->dev);
3221
3222 *r_intel8x0 = chip; 3232 *r_intel8x0 = chip;
3223 return 0; 3233 return 0;
3224} 3234}
@@ -3265,12 +3275,12 @@ static int check_default_spdif_aclink(struct pci_dev *pci)
3265 w = snd_pci_quirk_lookup(pci, spdif_aclink_defaults); 3275 w = snd_pci_quirk_lookup(pci, spdif_aclink_defaults);
3266 if (w) { 3276 if (w) {
3267 if (w->value) 3277 if (w->value)
3268 snd_printdd(KERN_INFO 3278 dev_dbg(&pci->dev,
3269 "intel8x0: Using SPDIF over AC-Link for %s\n", 3279 "Using SPDIF over AC-Link for %s\n",
3270 snd_pci_quirk_name(w)); 3280 snd_pci_quirk_name(w));
3271 else 3281 else
3272 snd_printdd(KERN_INFO 3282 dev_dbg(&pci->dev,
3273 "intel8x0: Using integrated SPDIF DMA for %s\n", 3283 "Using integrated SPDIF DMA for %s\n",
3274 snd_pci_quirk_name(w)); 3284 snd_pci_quirk_name(w));
3275 return w->value; 3285 return w->value;
3276 } 3286 }
@@ -3285,7 +3295,7 @@ static int snd_intel8x0_probe(struct pci_dev *pci,
3285 int err; 3295 int err;
3286 struct shortname_table *name; 3296 struct shortname_table *name;
3287 3297
3288 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 3298 err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
3289 if (err < 0) 3299 if (err < 0)
3290 return err; 3300 return err;
3291 3301
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index 3573c1193665..b54d3e93cab1 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -334,7 +334,8 @@ static int snd_intel8x0m_codec_semaphore(struct intel8x0m *chip, unsigned int co
334 /* access to some forbidden (non existent) ac97 registers will not 334 /* access to some forbidden (non existent) ac97 registers will not
335 * reset the semaphore. So even if you don't get the semaphore, still 335 * reset the semaphore. So even if you don't get the semaphore, still
336 * continue the access. We don't need the semaphore anyway. */ 336 * continue the access. We don't need the semaphore anyway. */
337 snd_printk(KERN_ERR "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n", 337 dev_err(chip->card->dev,
338 "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
338 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA))); 339 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
339 iagetword(chip, 0); /* clear semaphore flag */ 340 iagetword(chip, 0); /* clear semaphore flag */
340 /* I don't care about the semaphore */ 341 /* I don't care about the semaphore */
@@ -349,7 +350,9 @@ static void snd_intel8x0m_codec_write(struct snd_ac97 *ac97,
349 350
350 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) { 351 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) {
351 if (! chip->in_ac97_init) 352 if (! chip->in_ac97_init)
352 snd_printk(KERN_ERR "codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 353 dev_err(chip->card->dev,
354 "codec_write %d: semaphore is not ready for register 0x%x\n",
355 ac97->num, reg);
353 } 356 }
354 iaputword(chip, reg + ac97->num * 0x80, val); 357 iaputword(chip, reg + ac97->num * 0x80, val);
355} 358}
@@ -363,7 +366,9 @@ static unsigned short snd_intel8x0m_codec_read(struct snd_ac97 *ac97,
363 366
364 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) { 367 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) {
365 if (! chip->in_ac97_init) 368 if (! chip->in_ac97_init)
366 snd_printk(KERN_ERR "codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 369 dev_err(chip->card->dev,
370 "codec_read %d: semaphore is not ready for register 0x%x\n",
371 ac97->num, reg);
367 res = 0xffff; 372 res = 0xffff;
368 } else { 373 } else {
369 res = iagetword(chip, reg + ac97->num * 0x80); 374 res = iagetword(chip, reg + ac97->num * 0x80);
@@ -372,7 +377,9 @@ static unsigned short snd_intel8x0m_codec_read(struct snd_ac97 *ac97,
372 iputdword(chip, ICHREG(GLOB_STA), 377 iputdword(chip, ICHREG(GLOB_STA),
373 tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI)); 378 tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
374 if (! chip->in_ac97_init) 379 if (! chip->in_ac97_init)
375 snd_printk(KERN_ERR "codec_read %d: read timeout for register 0x%x\n", ac97->num, reg); 380 dev_err(chip->card->dev,
381 "codec_read %d: read timeout for register 0x%x\n",
382 ac97->num, reg);
376 res = 0xffff; 383 res = 0xffff;
377 } 384 }
378 } 385 }
@@ -412,7 +419,7 @@ static void snd_intel8x0m_setup_periods(struct intel8x0m *chip, struct ichdev *i
412 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */ 419 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
413 ichdev->fragsize >> chip->pcm_pos_shift); 420 ichdev->fragsize >> chip->pcm_pos_shift);
414 /* 421 /*
415 printk(KERN_DEBUG "bdbar[%i] = 0x%x [0x%x]\n", 422 dev_dbg(chip->card->dev, "bdbar[%i] = 0x%x [0x%x]\n",
416 idx + 0, bdbar[idx + 0], bdbar[idx + 1]); 423 idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
417 */ 424 */
418 } 425 }
@@ -424,8 +431,8 @@ static void snd_intel8x0m_setup_periods(struct intel8x0m *chip, struct ichdev *i
424 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags; 431 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
425 ichdev->position = 0; 432 ichdev->position = 0;
426#if 0 433#if 0
427 printk(KERN_DEBUG "lvi_frag = %i, frags = %i, period_size = 0x%x, " 434 dev_dbg(chip->card->dev,
428 "period_size1 = 0x%x\n", 435 "lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n",
429 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize, 436 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize,
430 ichdev->fragsize1); 437 ichdev->fragsize1);
431#endif 438#endif
@@ -470,8 +477,8 @@ static inline void snd_intel8x0m_update(struct intel8x0m *chip, struct ichdev *i
470 ichdev->lvi_frag * 477 ichdev->lvi_frag *
471 ichdev->fragsize1); 478 ichdev->fragsize1);
472#if 0 479#if 0
473 printk(KERN_DEBUG "new: bdbar[%i] = 0x%x [0x%x], " 480 dev_dbg(chip->card->dev,
474 "prefetch = %i, all = 0x%x, 0x%x\n", 481 "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n",
475 ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2], 482 ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
476 ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port), 483 ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
477 inl(port + 4), inb(port + ICH_REG_OFF_CR)); 484 inl(port + 4), inb(port + ICH_REG_OFF_CR));
@@ -850,7 +857,8 @@ static int snd_intel8x0m_mixer(struct intel8x0m *chip, int ac97_clock)
850 ac97.pci = chip->pci; 857 ac97.pci = chip->pci;
851 ac97.num = glob_sta & ICH_SCR ? 1 : 0; 858 ac97.num = glob_sta & ICH_SCR ? 1 : 0;
852 if ((err = snd_ac97_mixer(pbus, &ac97, &x97)) < 0) { 859 if ((err = snd_ac97_mixer(pbus, &ac97, &x97)) < 0) {
853 snd_printk(KERN_ERR "Unable to initialize codec #%d\n", ac97.num); 860 dev_err(chip->card->dev,
861 "Unable to initialize codec #%d\n", ac97.num);
854 if (ac97.num == 0) 862 if (ac97.num == 0)
855 goto __err; 863 goto __err;
856 return err; 864 return err;
@@ -901,7 +909,7 @@ static int snd_intel8x0m_ich_chip_init(struct intel8x0m *chip, int probing)
901 goto __ok; 909 goto __ok;
902 schedule_timeout_uninterruptible(1); 910 schedule_timeout_uninterruptible(1);
903 } while (time_after_eq(end_time, jiffies)); 911 } while (time_after_eq(end_time, jiffies));
904 snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]\n", 912 dev_err(chip->card->dev, "AC'97 warm reset still in progress? [0x%x]\n",
905 igetdword(chip, ICHREG(GLOB_CNT))); 913 igetdword(chip, ICHREG(GLOB_CNT)));
906 return -EIO; 914 return -EIO;
907 915
@@ -921,7 +929,8 @@ static int snd_intel8x0m_ich_chip_init(struct intel8x0m *chip, int probing)
921 } while (time_after_eq(end_time, jiffies)); 929 } while (time_after_eq(end_time, jiffies));
922 if (! status) { 930 if (! status) {
923 /* no codec is found */ 931 /* no codec is found */
924 snd_printk(KERN_ERR "codec_ready: codec is not ready [0x%x]\n", 932 dev_err(chip->card->dev,
933 "codec_ready: codec is not ready [0x%x]\n",
925 igetdword(chip, ICHREG(GLOB_STA))); 934 igetdword(chip, ICHREG(GLOB_STA)));
926 return -EIO; 935 return -EIO;
927 } 936 }
@@ -1042,16 +1051,15 @@ static int intel8x0m_resume(struct device *dev)
1042 pci_set_power_state(pci, PCI_D0); 1051 pci_set_power_state(pci, PCI_D0);
1043 pci_restore_state(pci); 1052 pci_restore_state(pci);
1044 if (pci_enable_device(pci) < 0) { 1053 if (pci_enable_device(pci) < 0) {
1045 printk(KERN_ERR "intel8x0m: pci_enable_device failed, " 1054 dev_err(dev, "pci_enable_device failed, disabling device\n");
1046 "disabling device\n");
1047 snd_card_disconnect(card); 1055 snd_card_disconnect(card);
1048 return -EIO; 1056 return -EIO;
1049 } 1057 }
1050 pci_set_master(pci); 1058 pci_set_master(pci);
1051 if (request_irq(pci->irq, snd_intel8x0m_interrupt, 1059 if (request_irq(pci->irq, snd_intel8x0m_interrupt,
1052 IRQF_SHARED, KBUILD_MODNAME, chip)) { 1060 IRQF_SHARED, KBUILD_MODNAME, chip)) {
1053 printk(KERN_ERR "intel8x0m: unable to grab IRQ %d, " 1061 dev_err(dev, "unable to grab IRQ %d, disabling device\n",
1054 "disabling device\n", pci->irq); 1062 pci->irq);
1055 snd_card_disconnect(card); 1063 snd_card_disconnect(card);
1056 return -EIO; 1064 return -EIO;
1057 } 1065 }
@@ -1165,7 +1173,7 @@ static int snd_intel8x0m_create(struct snd_card *card,
1165 else 1173 else
1166 chip->addr = pci_iomap(pci, 0, 0); 1174 chip->addr = pci_iomap(pci, 0, 0);
1167 if (!chip->addr) { 1175 if (!chip->addr) {
1168 snd_printk(KERN_ERR "AC'97 space ioremap problem\n"); 1176 dev_err(card->dev, "AC'97 space ioremap problem\n");
1169 snd_intel8x0m_free(chip); 1177 snd_intel8x0m_free(chip);
1170 return -EIO; 1178 return -EIO;
1171 } 1179 }
@@ -1174,7 +1182,7 @@ static int snd_intel8x0m_create(struct snd_card *card,
1174 else 1182 else
1175 chip->bmaddr = pci_iomap(pci, 1, 0); 1183 chip->bmaddr = pci_iomap(pci, 1, 0);
1176 if (!chip->bmaddr) { 1184 if (!chip->bmaddr) {
1177 snd_printk(KERN_ERR "Controller space ioremap problem\n"); 1185 dev_err(card->dev, "Controller space ioremap problem\n");
1178 snd_intel8x0m_free(chip); 1186 snd_intel8x0m_free(chip);
1179 return -EIO; 1187 return -EIO;
1180 } 1188 }
@@ -1182,7 +1190,7 @@ static int snd_intel8x0m_create(struct snd_card *card,
1182 port_inited: 1190 port_inited:
1183 if (request_irq(pci->irq, snd_intel8x0m_interrupt, IRQF_SHARED, 1191 if (request_irq(pci->irq, snd_intel8x0m_interrupt, IRQF_SHARED,
1184 KBUILD_MODNAME, chip)) { 1192 KBUILD_MODNAME, chip)) {
1185 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1193 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1186 snd_intel8x0m_free(chip); 1194 snd_intel8x0m_free(chip);
1187 return -EBUSY; 1195 return -EBUSY;
1188 } 1196 }
@@ -1243,8 +1251,6 @@ static int snd_intel8x0m_create(struct snd_card *card,
1243 return err; 1251 return err;
1244 } 1252 }
1245 1253
1246 snd_card_set_dev(card, &pci->dev);
1247
1248 *r_intel8x0m = chip; 1254 *r_intel8x0m = chip;
1249 return 0; 1255 return 0;
1250} 1256}
@@ -1283,7 +1289,7 @@ static int snd_intel8x0m_probe(struct pci_dev *pci,
1283 int err; 1289 int err;
1284 struct shortname_table *name; 1290 struct shortname_table *name;
1285 1291
1286 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 1292 err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
1287 if (err < 0) 1293 if (err < 0)
1288 return err; 1294 return err;
1289 1295
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 9cf9829555d4..8f36d77f01e5 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -2418,8 +2418,6 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
2418 2418
2419 snd_korg1212_proc_init(korg1212); 2419 snd_korg1212_proc_init(korg1212);
2420 2420
2421 snd_card_set_dev(card, &pci->dev);
2422
2423 * rchip = korg1212; 2421 * rchip = korg1212;
2424 return 0; 2422 return 0;
2425 2423
@@ -2445,7 +2443,8 @@ snd_korg1212_probe(struct pci_dev *pci,
2445 dev++; 2443 dev++;
2446 return -ENOENT; 2444 return -ENOENT;
2447 } 2445 }
2448 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2446 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2447 0, &card);
2449 if (err < 0) 2448 if (err < 0)
2450 return err; 2449 return err;
2451 2450
diff --git a/sound/pci/lola/lola.c b/sound/pci/lola/lola.c
index 0568540dc8d3..68824cdd137d 100644
--- a/sound/pci/lola/lola.c
+++ b/sound/pci/lola/lola.c
@@ -75,7 +75,7 @@ MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
75static int debug; 75static int debug;
76module_param(debug, int, 0644); 76module_param(debug, int, 0644);
77#define verbose_debug(fmt, args...) \ 77#define verbose_debug(fmt, args...) \
78 do { if (debug > 1) printk(KERN_DEBUG SFX fmt, ##args); } while (0) 78 do { if (debug > 1) pr_debug(SFX fmt, ##args); } while (0)
79#else 79#else
80#define verbose_debug(fmt, args...) 80#define verbose_debug(fmt, args...)
81#endif 81#endif
@@ -168,7 +168,7 @@ static int rirb_get_response(struct lola *chip, unsigned int *val,
168 verbose_debug("get_response: %x, %x\n", 168 verbose_debug("get_response: %x, %x\n",
169 chip->res, chip->res_ex); 169 chip->res, chip->res_ex);
170 if (chip->res_ex & LOLA_RIRB_EX_ERROR) { 170 if (chip->res_ex & LOLA_RIRB_EX_ERROR) {
171 printk(KERN_WARNING SFX "RIRB ERROR: " 171 dev_warn(chip->card->dev, "RIRB ERROR: "
172 "NID=%x, verb=%x, data=%x, ext=%x\n", 172 "NID=%x, verb=%x, data=%x, ext=%x\n",
173 chip->last_cmd_nid, 173 chip->last_cmd_nid,
174 chip->last_verb, chip->last_data, 174 chip->last_verb, chip->last_data,
@@ -182,9 +182,9 @@ static int rirb_get_response(struct lola *chip, unsigned int *val,
182 udelay(20); 182 udelay(20);
183 cond_resched(); 183 cond_resched();
184 } 184 }
185 printk(KERN_WARNING SFX "RIRB response error\n"); 185 dev_warn(chip->card->dev, "RIRB response error\n");
186 if (!chip->polling_mode) { 186 if (!chip->polling_mode) {
187 printk(KERN_WARNING SFX "switching to polling mode\n"); 187 dev_warn(chip->card->dev, "switching to polling mode\n");
188 chip->polling_mode = 1; 188 chip->polling_mode = 1;
189 goto again; 189 goto again;
190 } 190 }
@@ -327,7 +327,7 @@ static int reset_controller(struct lola *chip)
327 break; 327 break;
328 } while (time_before(jiffies, end_time)); 328 } while (time_before(jiffies, end_time));
329 if (!gctl) { 329 if (!gctl) {
330 printk(KERN_ERR SFX "cannot reset controller\n"); 330 dev_err(chip->card->dev, "cannot reset controller\n");
331 return -EIO; 331 return -EIO;
332 } 332 }
333 return 0; 333 return 0;
@@ -452,40 +452,40 @@ static int lola_parse_tree(struct lola *chip)
452 452
453 err = lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val); 453 err = lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val);
454 if (err < 0) { 454 if (err < 0) {
455 printk(KERN_ERR SFX "Can't read VENDOR_ID\n"); 455 dev_err(chip->card->dev, "Can't read VENDOR_ID\n");
456 return err; 456 return err;
457 } 457 }
458 val >>= 16; 458 val >>= 16;
459 if (val != 0x1369) { 459 if (val != 0x1369) {
460 printk(KERN_ERR SFX "Unknown codec vendor 0x%x\n", val); 460 dev_err(chip->card->dev, "Unknown codec vendor 0x%x\n", val);
461 return -EINVAL; 461 return -EINVAL;
462 } 462 }
463 463
464 err = lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val); 464 err = lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val);
465 if (err < 0) { 465 if (err < 0) {
466 printk(KERN_ERR SFX "Can't read FUNCTION_TYPE\n"); 466 dev_err(chip->card->dev, "Can't read FUNCTION_TYPE\n");
467 return err; 467 return err;
468 } 468 }
469 if (val != 1) { 469 if (val != 1) {
470 printk(KERN_ERR SFX "Unknown function type %d\n", val); 470 dev_err(chip->card->dev, "Unknown function type %d\n", val);
471 return -EINVAL; 471 return -EINVAL;
472 } 472 }
473 473
474 err = lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val); 474 err = lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val);
475 if (err < 0) { 475 if (err < 0) {
476 printk(KERN_ERR SFX "Can't read SPECCAPS\n"); 476 dev_err(chip->card->dev, "Can't read SPECCAPS\n");
477 return err; 477 return err;
478 } 478 }
479 chip->lola_caps = val; 479 chip->lola_caps = val;
480 chip->pin[CAPT].num_pins = LOLA_AFG_INPUT_PIN_COUNT(chip->lola_caps); 480 chip->pin[CAPT].num_pins = LOLA_AFG_INPUT_PIN_COUNT(chip->lola_caps);
481 chip->pin[PLAY].num_pins = LOLA_AFG_OUTPUT_PIN_COUNT(chip->lola_caps); 481 chip->pin[PLAY].num_pins = LOLA_AFG_OUTPUT_PIN_COUNT(chip->lola_caps);
482 snd_printdd(SFX "speccaps=0x%x, pins in=%d, out=%d\n", 482 dev_dbg(chip->card->dev, "speccaps=0x%x, pins in=%d, out=%d\n",
483 chip->lola_caps, 483 chip->lola_caps,
484 chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins); 484 chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins);
485 485
486 if (chip->pin[CAPT].num_pins > MAX_AUDIO_INOUT_COUNT || 486 if (chip->pin[CAPT].num_pins > MAX_AUDIO_INOUT_COUNT ||
487 chip->pin[PLAY].num_pins > MAX_AUDIO_INOUT_COUNT) { 487 chip->pin[PLAY].num_pins > MAX_AUDIO_INOUT_COUNT) {
488 printk(KERN_ERR SFX "Invalid Lola-spec caps 0x%x\n", val); 488 dev_err(chip->card->dev, "Invalid Lola-spec caps 0x%x\n", val);
489 return -EINVAL; 489 return -EINVAL;
490 } 490 }
491 491
@@ -586,7 +586,6 @@ static int lola_create(struct snd_card *card, struct pci_dev *pci,
586 586
587 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 587 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
588 if (!chip) { 588 if (!chip) {
589 snd_printk(KERN_ERR SFX "cannot allocate chip\n");
590 pci_disable_device(pci); 589 pci_disable_device(pci);
591 return -ENOMEM; 590 return -ENOMEM;
592 } 591 }
@@ -609,7 +608,7 @@ static int lola_create(struct snd_card *card, struct pci_dev *pci,
609 chip->sample_rate_max = 192000; 608 chip->sample_rate_max = 192000;
610 break; 609 break;
611 default: 610 default:
612 snd_printk(KERN_WARNING SFX 611 dev_warn(chip->card->dev,
613 "Invalid granularity %d, reset to %d\n", 612 "Invalid granularity %d, reset to %d\n",
614 chip->granularity, LOLA_GRANULARITY_MAX); 613 chip->granularity, LOLA_GRANULARITY_MAX);
615 chip->granularity = LOLA_GRANULARITY_MAX; 614 chip->granularity = LOLA_GRANULARITY_MAX;
@@ -618,7 +617,7 @@ static int lola_create(struct snd_card *card, struct pci_dev *pci,
618 } 617 }
619 chip->sample_rate_min = sample_rate_min[dev]; 618 chip->sample_rate_min = sample_rate_min[dev];
620 if (chip->sample_rate_min > chip->sample_rate_max) { 619 if (chip->sample_rate_min > chip->sample_rate_max) {
621 snd_printk(KERN_WARNING SFX 620 dev_warn(chip->card->dev,
622 "Invalid sample_rate_min %d, reset to 16000\n", 621 "Invalid sample_rate_min %d, reset to 16000\n",
623 chip->sample_rate_min); 622 chip->sample_rate_min);
624 chip->sample_rate_min = 16000; 623 chip->sample_rate_min = 16000;
@@ -636,7 +635,7 @@ static int lola_create(struct snd_card *card, struct pci_dev *pci,
636 chip->bar[1].addr = pci_resource_start(pci, 2); 635 chip->bar[1].addr = pci_resource_start(pci, 2);
637 chip->bar[1].remap_addr = pci_ioremap_bar(pci, 2); 636 chip->bar[1].remap_addr = pci_ioremap_bar(pci, 2);
638 if (!chip->bar[0].remap_addr || !chip->bar[1].remap_addr) { 637 if (!chip->bar[0].remap_addr || !chip->bar[1].remap_addr) {
639 snd_printk(KERN_ERR SFX "ioremap error\n"); 638 dev_err(chip->card->dev, "ioremap error\n");
640 err = -ENXIO; 639 err = -ENXIO;
641 goto errout; 640 goto errout;
642 } 641 }
@@ -649,7 +648,7 @@ static int lola_create(struct snd_card *card, struct pci_dev *pci,
649 648
650 if (request_irq(pci->irq, lola_interrupt, IRQF_SHARED, 649 if (request_irq(pci->irq, lola_interrupt, IRQF_SHARED,
651 KBUILD_MODNAME, chip)) { 650 KBUILD_MODNAME, chip)) {
652 printk(KERN_ERR SFX "unable to grab IRQ %d\n", pci->irq); 651 dev_err(chip->card->dev, "unable to grab IRQ %d\n", pci->irq);
653 err = -EBUSY; 652 err = -EBUSY;
654 goto errout; 653 goto errout;
655 } 654 }
@@ -660,7 +659,7 @@ static int lola_create(struct snd_card *card, struct pci_dev *pci,
660 chip->pcm[CAPT].num_streams = (dever >> 0) & 0x3ff; 659 chip->pcm[CAPT].num_streams = (dever >> 0) & 0x3ff;
661 chip->pcm[PLAY].num_streams = (dever >> 10) & 0x3ff; 660 chip->pcm[PLAY].num_streams = (dever >> 10) & 0x3ff;
662 chip->version = (dever >> 24) & 0xff; 661 chip->version = (dever >> 24) & 0xff;
663 snd_printdd(SFX "streams in=%d, out=%d, version=0x%x\n", 662 dev_dbg(chip->card->dev, "streams in=%d, out=%d, version=0x%x\n",
664 chip->pcm[CAPT].num_streams, chip->pcm[PLAY].num_streams, 663 chip->pcm[CAPT].num_streams, chip->pcm[PLAY].num_streams,
665 chip->version); 664 chip->version);
666 665
@@ -669,7 +668,7 @@ static int lola_create(struct snd_card *card, struct pci_dev *pci,
669 chip->pcm[PLAY].num_streams > MAX_STREAM_OUT_COUNT || 668 chip->pcm[PLAY].num_streams > MAX_STREAM_OUT_COUNT ||
670 (!chip->pcm[CAPT].num_streams && 669 (!chip->pcm[CAPT].num_streams &&
671 !chip->pcm[PLAY].num_streams)) { 670 !chip->pcm[PLAY].num_streams)) {
672 printk(KERN_ERR SFX "invalid DEVER = %x\n", dever); 671 dev_err(chip->card->dev, "invalid DEVER = %x\n", dever);
673 err = -EINVAL; 672 err = -EINVAL;
674 goto errout; 673 goto errout;
675 } 674 }
@@ -680,7 +679,7 @@ static int lola_create(struct snd_card *card, struct pci_dev *pci,
680 679
681 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 680 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
682 if (err < 0) { 681 if (err < 0) {
683 snd_printk(KERN_ERR SFX "Error creating device [card]!\n"); 682 dev_err(chip->card->dev, "Error creating device [card]!\n");
684 goto errout; 683 goto errout;
685 } 684 }
686 685
@@ -717,14 +716,13 @@ static int lola_probe(struct pci_dev *pci,
717 return -ENOENT; 716 return -ENOENT;
718 } 717 }
719 718
720 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 719 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
720 0, &card);
721 if (err < 0) { 721 if (err < 0) {
722 snd_printk(KERN_ERR SFX "Error creating card!\n"); 722 dev_err(card->dev, "Error creating card!\n");
723 return err; 723 return err;
724 } 724 }
725 725
726 snd_card_set_dev(card, &pci->dev);
727
728 err = lola_create(card, pci, dev, &chip); 726 err = lola_create(card, pci, dev, &chip);
729 if (err < 0) 727 if (err < 0)
730 goto out_free; 728 goto out_free;
diff --git a/sound/pci/lola/lola_clock.c b/sound/pci/lola/lola_clock.c
index eb1d6b97df16..2bef6b412aee 100644
--- a/sound/pci/lola/lola_clock.c
+++ b/sound/pci/lola/lola_clock.c
@@ -128,21 +128,21 @@ int lola_init_clock_widget(struct lola *chip, int nid)
128 128
129 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val); 129 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
130 if (err < 0) { 130 if (err < 0) {
131 printk(KERN_ERR SFX "Can't read wcaps for 0x%x\n", nid); 131 dev_err(chip->card->dev, "Can't read wcaps for 0x%x\n", nid);
132 return err; 132 return err;
133 } 133 }
134 134
135 if ((val & 0xfff00000) != 0x01f00000) { /* test SubType and Type */ 135 if ((val & 0xfff00000) != 0x01f00000) { /* test SubType and Type */
136 snd_printdd("No valid clock widget\n"); 136 dev_dbg(chip->card->dev, "No valid clock widget\n");
137 return 0; 137 return 0;
138 } 138 }
139 139
140 chip->clock.nid = nid; 140 chip->clock.nid = nid;
141 chip->clock.items = val & 0xff; 141 chip->clock.items = val & 0xff;
142 snd_printdd("clock_list nid=%x, entries=%d\n", nid, 142 dev_dbg(chip->card->dev, "clock_list nid=%x, entries=%d\n", nid,
143 chip->clock.items); 143 chip->clock.items);
144 if (chip->clock.items > MAX_SAMPLE_CLOCK_COUNT) { 144 if (chip->clock.items > MAX_SAMPLE_CLOCK_COUNT) {
145 printk(KERN_ERR SFX "CLOCK_LIST too big: %d\n", 145 dev_err(chip->card->dev, "CLOCK_LIST too big: %d\n",
146 chip->clock.items); 146 chip->clock.items);
147 return -EINVAL; 147 return -EINVAL;
148 } 148 }
@@ -158,7 +158,7 @@ int lola_init_clock_widget(struct lola *chip, int nid)
158 err = lola_codec_read(chip, nid, LOLA_VERB_GET_CLOCK_LIST, 158 err = lola_codec_read(chip, nid, LOLA_VERB_GET_CLOCK_LIST,
159 idx, 0, &val, &res_ex); 159 idx, 0, &val, &res_ex);
160 if (err < 0) { 160 if (err < 0) {
161 printk(KERN_ERR SFX "Can't read CLOCK_LIST\n"); 161 dev_err(chip->card->dev, "Can't read CLOCK_LIST\n");
162 return -EINVAL; 162 return -EINVAL;
163 } 163 }
164 164
@@ -223,7 +223,7 @@ int lola_enable_clock_events(struct lola *chip)
223 if (err < 0) 223 if (err < 0)
224 return err; 224 return err;
225 if (res) { 225 if (res) {
226 printk(KERN_WARNING SFX "error in enable_clock_events %d\n", 226 dev_warn(chip->card->dev, "error in enable_clock_events %d\n",
227 res); 227 res);
228 return -EINVAL; 228 return -EINVAL;
229 } 229 }
@@ -242,7 +242,7 @@ int lola_set_clock_index(struct lola *chip, unsigned int idx)
242 if (err < 0) 242 if (err < 0)
243 return err; 243 return err;
244 if (res) { 244 if (res) {
245 printk(KERN_WARNING SFX "error in set_clock %d\n", res); 245 dev_warn(chip->card->dev, "error in set_clock %d\n", res);
246 return -EINVAL; 246 return -EINVAL;
247 } 247 }
248 return 0; 248 return 0;
diff --git a/sound/pci/lola/lola_mixer.c b/sound/pci/lola/lola_mixer.c
index 52c8d6b0f39b..782f4d8299ae 100644
--- a/sound/pci/lola/lola_mixer.c
+++ b/sound/pci/lola/lola_mixer.c
@@ -37,7 +37,7 @@ static int lola_init_pin(struct lola *chip, struct lola_pin *pin,
37 pin->nid = nid; 37 pin->nid = nid;
38 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val); 38 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
39 if (err < 0) { 39 if (err < 0) {
40 printk(KERN_ERR SFX "Can't read wcaps for 0x%x\n", nid); 40 dev_err(chip->card->dev, "Can't read wcaps for 0x%x\n", nid);
41 return err; 41 return err;
42 } 42 }
43 val &= 0x00f00fff; /* test TYPE and bits 0..11 */ 43 val &= 0x00f00fff; /* test TYPE and bits 0..11 */
@@ -48,7 +48,7 @@ static int lola_init_pin(struct lola *chip, struct lola_pin *pin,
48 else if (val == 0x0040000c && dir == PLAY) /* Dig=0, OutAmp/ovrd */ 48 else if (val == 0x0040000c && dir == PLAY) /* Dig=0, OutAmp/ovrd */
49 pin->is_analog = true; 49 pin->is_analog = true;
50 else { 50 else {
51 printk(KERN_ERR SFX "Invalid wcaps 0x%x for 0x%x\n", val, nid); 51 dev_err(chip->card->dev, "Invalid wcaps 0x%x for 0x%x\n", val, nid);
52 return -EINVAL; 52 return -EINVAL;
53 } 53 }
54 54
@@ -62,7 +62,7 @@ static int lola_init_pin(struct lola *chip, struct lola_pin *pin,
62 else 62 else
63 err = lola_read_param(chip, nid, LOLA_PAR_AMP_IN_CAP, &val); 63 err = lola_read_param(chip, nid, LOLA_PAR_AMP_IN_CAP, &val);
64 if (err < 0) { 64 if (err < 0) {
65 printk(KERN_ERR SFX "Can't read AMP-caps for 0x%x\n", nid); 65 dev_err(chip->card->dev, "Can't read AMP-caps for 0x%x\n", nid);
66 return err; 66 return err;
67 } 67 }
68 68
@@ -79,7 +79,7 @@ static int lola_init_pin(struct lola *chip, struct lola_pin *pin,
79 err = lola_codec_read(chip, nid, LOLA_VERB_GET_MAX_LEVEL, 0, 0, &val, 79 err = lola_codec_read(chip, nid, LOLA_VERB_GET_MAX_LEVEL, 0, 0, &val,
80 NULL); 80 NULL);
81 if (err < 0) { 81 if (err < 0) {
82 printk(KERN_ERR SFX "Can't get MAX_LEVEL 0x%x\n", nid); 82 dev_err(chip->card->dev, "Can't get MAX_LEVEL 0x%x\n", nid);
83 return err; 83 return err;
84 } 84 }
85 pin->max_level = val & 0x3ff; /* 10 bits */ 85 pin->max_level = val & 0x3ff; /* 10 bits */
@@ -119,12 +119,12 @@ int lola_init_mixer_widget(struct lola *chip, int nid)
119 119
120 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val); 120 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
121 if (err < 0) { 121 if (err < 0) {
122 printk(KERN_ERR SFX "Can't read wcaps for 0x%x\n", nid); 122 dev_err(chip->card->dev, "Can't read wcaps for 0x%x\n", nid);
123 return err; 123 return err;
124 } 124 }
125 125
126 if ((val & 0xfff00000) != 0x02f00000) { /* test SubType and Type */ 126 if ((val & 0xfff00000) != 0x02f00000) { /* test SubType and Type */
127 snd_printdd("No valid mixer widget\n"); 127 dev_dbg(chip->card->dev, "No valid mixer widget\n");
128 return 0; 128 return 0;
129 } 129 }
130 130
@@ -202,7 +202,7 @@ int lola_init_mixer_widget(struct lola *chip, int nid)
202 */ 202 */
203 if (chip->mixer.src_stream_out_ofs > MAX_AUDIO_INOUT_COUNT || 203 if (chip->mixer.src_stream_out_ofs > MAX_AUDIO_INOUT_COUNT ||
204 chip->mixer.dest_phys_out_ofs > MAX_STREAM_IN_COUNT) { 204 chip->mixer.dest_phys_out_ofs > MAX_STREAM_IN_COUNT) {
205 printk(KERN_ERR SFX "Invalid mixer widget size\n"); 205 dev_err(chip->card->dev, "Invalid mixer widget size\n");
206 return -EINVAL; 206 return -EINVAL;
207 } 207 }
208 208
@@ -213,7 +213,7 @@ int lola_init_mixer_widget(struct lola *chip, int nid)
213 (((1U << chip->mixer.dest_phys_outs) - 1) 213 (((1U << chip->mixer.dest_phys_outs) - 1)
214 << chip->mixer.dest_phys_out_ofs); 214 << chip->mixer.dest_phys_out_ofs);
215 215
216 snd_printdd("Mixer src_mask=%x, dest_mask=%x\n", 216 dev_dbg(chip->card->dev, "Mixer src_mask=%x, dest_mask=%x\n",
217 chip->mixer.src_mask, chip->mixer.dest_mask); 217 chip->mixer.src_mask, chip->mixer.dest_mask);
218 218
219 return 0; 219 return 0;
@@ -236,7 +236,8 @@ static int lola_mixer_set_src_gain(struct lola *chip, unsigned int id,
236 (gain == readw(&chip->mixer.array->src_gain[id]))) 236 (gain == readw(&chip->mixer.array->src_gain[id])))
237 return 0; 237 return 0;
238 238
239 snd_printdd("lola_mixer_set_src_gain (id=%d, gain=%d) enable=%x\n", 239 dev_dbg(chip->card->dev,
240 "lola_mixer_set_src_gain (id=%d, gain=%d) enable=%x\n",
240 id, gain, val); 241 id, gain, val);
241 writew(gain, &chip->mixer.array->src_gain[id]); 242 writew(gain, &chip->mixer.array->src_gain[id]);
242 writel(val, &chip->mixer.array->src_gain_enable); 243 writel(val, &chip->mixer.array->src_gain_enable);
@@ -409,7 +410,8 @@ static int set_analog_volume(struct lola *chip, int dir,
409 return 0; 410 return 0;
410 if (external_call) 411 if (external_call)
411 lola_codec_flush(chip); 412 lola_codec_flush(chip);
412 snd_printdd("set_analog_volume (dir=%d idx=%d, volume=%d)\n", 413 dev_dbg(chip->card->dev,
414 "set_analog_volume (dir=%d idx=%d, volume=%d)\n",
413 dir, idx, val); 415 dir, idx, val);
414 err = lola_codec_write(chip, pin->nid, 416 err = lola_codec_write(chip, pin->nid,
415 LOLA_VERB_SET_AMP_GAIN_MUTE, val, 0); 417 LOLA_VERB_SET_AMP_GAIN_MUTE, val, 0);
diff --git a/sound/pci/lola/lola_pcm.c b/sound/pci/lola/lola_pcm.c
index 5ea85e8b83ab..3bd6985430e8 100644
--- a/sound/pci/lola/lola_pcm.c
+++ b/sound/pci/lola/lola_pcm.c
@@ -103,7 +103,7 @@ static void wait_for_srst_clear(struct lola *chip, struct lola_stream *str)
103 return; 103 return;
104 msleep(1); 104 msleep(1);
105 } 105 }
106 printk(KERN_WARNING SFX "SRST not clear (stream %d)\n", str->dsd); 106 dev_warn(chip->card->dev, "SRST not clear (stream %d)\n", str->dsd);
107} 107}
108 108
109static int lola_stream_wait_for_fifo(struct lola *chip, 109static int lola_stream_wait_for_fifo(struct lola *chip,
@@ -118,7 +118,7 @@ static int lola_stream_wait_for_fifo(struct lola *chip,
118 return 0; 118 return 0;
119 msleep(1); 119 msleep(1);
120 } 120 }
121 printk(KERN_WARNING SFX "FIFO not ready (stream %d)\n", str->dsd); 121 dev_warn(chip->card->dev, "FIFO not ready (stream %d)\n", str->dsd);
122 return -EIO; 122 return -EIO;
123} 123}
124 124
@@ -156,7 +156,7 @@ static int lola_sync_wait_for_fifo(struct lola *chip,
156 return 0; 156 return 0;
157 msleep(1); 157 msleep(1);
158 } 158 }
159 printk(KERN_WARNING SFX "FIFO not ready (pending %d)\n", pending - 1); 159 dev_warn(chip->card->dev, "FIFO not ready (pending %d)\n", pending - 1);
160 return -EIO; 160 return -EIO;
161} 161}
162 162
@@ -373,7 +373,7 @@ static int lola_setup_periods(struct lola *chip, struct lola_pcm *pcm,
373 return 0; 373 return 0;
374 374
375 error: 375 error:
376 snd_printk(KERN_ERR SFX "Too many BDL entries: buffer=%d, period=%d\n", 376 dev_err(chip->card->dev, "Too many BDL entries: buffer=%d, period=%d\n",
377 str->bufsize, period_bytes); 377 str->bufsize, period_bytes);
378 return -EINVAL; 378 return -EINVAL;
379} 379}
@@ -415,7 +415,7 @@ static int lola_set_stream_config(struct lola *chip,
415 err = lola_codec_read(chip, str->nid, LOLA_VERB_SET_STREAM_FORMAT, 415 err = lola_codec_read(chip, str->nid, LOLA_VERB_SET_STREAM_FORMAT,
416 str->format_verb, 0, &val, NULL); 416 str->format_verb, 0, &val, NULL);
417 if (err < 0) { 417 if (err < 0) {
418 printk(KERN_ERR SFX "Cannot set stream format 0x%x\n", 418 dev_err(chip->card->dev, "Cannot set stream format 0x%x\n",
419 str->format_verb); 419 str->format_verb);
420 return err; 420 return err;
421 } 421 }
@@ -427,7 +427,8 @@ static int lola_set_stream_config(struct lola *chip,
427 LOLA_VERB_SET_CHANNEL_STREAMID, 0, verb, 427 LOLA_VERB_SET_CHANNEL_STREAMID, 0, verb,
428 &val, NULL); 428 &val, NULL);
429 if (err < 0) { 429 if (err < 0) {
430 printk(KERN_ERR SFX "Cannot set stream channel %d\n", i); 430 dev_err(chip->card->dev,
431 "Cannot set stream channel %d\n", i);
431 return err; 432 return err;
432 } 433 }
433 } 434 }
@@ -651,13 +652,14 @@ static int lola_init_stream(struct lola *chip, struct lola_stream *str,
651 str->dsd += MAX_STREAM_IN_COUNT; 652 str->dsd += MAX_STREAM_IN_COUNT;
652 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val); 653 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
653 if (err < 0) { 654 if (err < 0) {
654 printk(KERN_ERR SFX "Can't read wcaps for 0x%x\n", nid); 655 dev_err(chip->card->dev, "Can't read wcaps for 0x%x\n", nid);
655 return err; 656 return err;
656 } 657 }
657 if (dir == PLAY) { 658 if (dir == PLAY) {
658 /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1) */ 659 /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1) */
659 if ((val & 0x00f00dff) != 0x00000010) { 660 if ((val & 0x00f00dff) != 0x00000010) {
660 printk(KERN_ERR SFX "Invalid wcaps 0x%x for 0x%x\n", 661 dev_err(chip->card->dev,
662 "Invalid wcaps 0x%x for 0x%x\n",
661 val, nid); 663 val, nid);
662 return -EINVAL; 664 return -EINVAL;
663 } 665 }
@@ -666,7 +668,8 @@ static int lola_init_stream(struct lola *chip, struct lola_stream *str,
666 * (bug : ignore bit8: Conn list = 0/1) 668 * (bug : ignore bit8: Conn list = 0/1)
667 */ 669 */
668 if ((val & 0x00f00cff) != 0x00100010) { 670 if ((val & 0x00f00cff) != 0x00100010) {
669 printk(KERN_ERR SFX "Invalid wcaps 0x%x for 0x%x\n", 671 dev_err(chip->card->dev,
672 "Invalid wcaps 0x%x for 0x%x\n",
670 val, nid); 673 val, nid);
671 return -EINVAL; 674 return -EINVAL;
672 } 675 }
@@ -677,14 +680,15 @@ static int lola_init_stream(struct lola *chip, struct lola_stream *str,
677 680
678 err = lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val); 681 err = lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val);
679 if (err < 0) { 682 if (err < 0) {
680 printk(KERN_ERR SFX "Can't read FORMATS 0x%x\n", nid); 683 dev_err(chip->card->dev, "Can't read FORMATS 0x%x\n", nid);
681 return err; 684 return err;
682 } 685 }
683 val &= 3; 686 val &= 3;
684 if (val == 3) 687 if (val == 3)
685 str->can_float = true; 688 str->can_float = true;
686 if (!(val & 1)) { 689 if (!(val & 1)) {
687 printk(KERN_ERR SFX "Invalid formats 0x%x for 0x%x", val, nid); 690 dev_err(chip->card->dev,
691 "Invalid formats 0x%x for 0x%x", val, nid);
688 return -EINVAL; 692 return -EINVAL;
689 } 693 }
690 return 0; 694 return 0;
diff --git a/sound/pci/lx6464es/lx6464es.c b/sound/pci/lx6464es/lx6464es.c
index 5fcaaa6da4a8..27f60ce8a55c 100644
--- a/sound/pci/lx6464es/lx6464es.c
+++ b/sound/pci/lx6464es/lx6464es.c
@@ -112,16 +112,16 @@ static int lx_hardware_open(struct lx6464es *chip,
112 112
113 snd_pcm_uframes_t period_size = runtime->period_size; 113 snd_pcm_uframes_t period_size = runtime->period_size;
114 114
115 snd_printd(LXP "allocating pipe for %d channels\n", channels); 115 dev_dbg(chip->card->dev, "allocating pipe for %d channels\n", channels);
116 err = lx_pipe_allocate(chip, 0, is_capture, channels); 116 err = lx_pipe_allocate(chip, 0, is_capture, channels);
117 if (err < 0) { 117 if (err < 0) {
118 snd_printk(KERN_ERR LXP "allocating pipe failed\n"); 118 dev_err(chip->card->dev, LXP "allocating pipe failed\n");
119 return err; 119 return err;
120 } 120 }
121 121
122 err = lx_set_granularity(chip, period_size); 122 err = lx_set_granularity(chip, period_size);
123 if (err < 0) { 123 if (err < 0) {
124 snd_printk(KERN_ERR LXP "setting granularity to %ld failed\n", 124 dev_err(chip->card->dev, "setting granularity to %ld failed\n",
125 period_size); 125 period_size);
126 return err; 126 return err;
127 } 127 }
@@ -136,24 +136,24 @@ static int lx_hardware_start(struct lx6464es *chip,
136 struct snd_pcm_runtime *runtime = substream->runtime; 136 struct snd_pcm_runtime *runtime = substream->runtime;
137 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); 137 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
138 138
139 snd_printd(LXP "setting stream format\n"); 139 dev_dbg(chip->card->dev, "setting stream format\n");
140 err = lx_stream_set_format(chip, runtime, 0, is_capture); 140 err = lx_stream_set_format(chip, runtime, 0, is_capture);
141 if (err < 0) { 141 if (err < 0) {
142 snd_printk(KERN_ERR LXP "setting stream format failed\n"); 142 dev_err(chip->card->dev, "setting stream format failed\n");
143 return err; 143 return err;
144 } 144 }
145 145
146 snd_printd(LXP "starting pipe\n"); 146 dev_dbg(chip->card->dev, "starting pipe\n");
147 err = lx_pipe_start(chip, 0, is_capture); 147 err = lx_pipe_start(chip, 0, is_capture);
148 if (err < 0) { 148 if (err < 0) {
149 snd_printk(KERN_ERR LXP "starting pipe failed\n"); 149 dev_err(chip->card->dev, "starting pipe failed\n");
150 return err; 150 return err;
151 } 151 }
152 152
153 snd_printd(LXP "waiting for pipe to start\n"); 153 dev_dbg(chip->card->dev, "waiting for pipe to start\n");
154 err = lx_pipe_wait_for_start(chip, 0, is_capture); 154 err = lx_pipe_wait_for_start(chip, 0, is_capture);
155 if (err < 0) { 155 if (err < 0) {
156 snd_printk(KERN_ERR LXP "waiting for pipe failed\n"); 156 dev_err(chip->card->dev, "waiting for pipe failed\n");
157 return err; 157 return err;
158 } 158 }
159 159
@@ -167,24 +167,24 @@ static int lx_hardware_stop(struct lx6464es *chip,
167 int err = 0; 167 int err = 0;
168 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); 168 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
169 169
170 snd_printd(LXP "pausing pipe\n"); 170 dev_dbg(chip->card->dev, "pausing pipe\n");
171 err = lx_pipe_pause(chip, 0, is_capture); 171 err = lx_pipe_pause(chip, 0, is_capture);
172 if (err < 0) { 172 if (err < 0) {
173 snd_printk(KERN_ERR LXP "pausing pipe failed\n"); 173 dev_err(chip->card->dev, "pausing pipe failed\n");
174 return err; 174 return err;
175 } 175 }
176 176
177 snd_printd(LXP "waiting for pipe to become idle\n"); 177 dev_dbg(chip->card->dev, "waiting for pipe to become idle\n");
178 err = lx_pipe_wait_for_idle(chip, 0, is_capture); 178 err = lx_pipe_wait_for_idle(chip, 0, is_capture);
179 if (err < 0) { 179 if (err < 0) {
180 snd_printk(KERN_ERR LXP "waiting for pipe failed\n"); 180 dev_err(chip->card->dev, "waiting for pipe failed\n");
181 return err; 181 return err;
182 } 182 }
183 183
184 snd_printd(LXP "stopping pipe\n"); 184 dev_dbg(chip->card->dev, "stopping pipe\n");
185 err = lx_pipe_stop(chip, 0, is_capture); 185 err = lx_pipe_stop(chip, 0, is_capture);
186 if (err < 0) { 186 if (err < 0) {
187 snd_printk(LXP "stopping pipe failed\n"); 187 dev_err(chip->card->dev, "stopping pipe failed\n");
188 return err; 188 return err;
189 } 189 }
190 190
@@ -198,10 +198,10 @@ static int lx_hardware_close(struct lx6464es *chip,
198 int err = 0; 198 int err = 0;
199 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); 199 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
200 200
201 snd_printd(LXP "releasing pipe\n"); 201 dev_dbg(chip->card->dev, "releasing pipe\n");
202 err = lx_pipe_release(chip, 0, is_capture); 202 err = lx_pipe_release(chip, 0, is_capture);
203 if (err < 0) { 203 if (err < 0) {
204 snd_printk(LXP "releasing pipe failed\n"); 204 dev_err(chip->card->dev, "releasing pipe failed\n");
205 return err; 205 return err;
206 } 206 }
207 207
@@ -216,7 +216,7 @@ static int lx_pcm_open(struct snd_pcm_substream *substream)
216 int err = 0; 216 int err = 0;
217 int board_rate; 217 int board_rate;
218 218
219 snd_printdd("->lx_pcm_open\n"); 219 dev_dbg(chip->card->dev, "->lx_pcm_open\n");
220 mutex_lock(&chip->setup_mutex); 220 mutex_lock(&chip->setup_mutex);
221 221
222 /* copy the struct snd_pcm_hardware struct */ 222 /* copy the struct snd_pcm_hardware struct */
@@ -227,7 +227,7 @@ static int lx_pcm_open(struct snd_pcm_substream *substream)
227 err = snd_pcm_hw_constraint_integer(runtime, 227 err = snd_pcm_hw_constraint_integer(runtime,
228 SNDRV_PCM_HW_PARAM_PERIODS); 228 SNDRV_PCM_HW_PARAM_PERIODS);
229 if (err < 0) { 229 if (err < 0) {
230 snd_printk(KERN_WARNING LXP "could not constrain periods\n"); 230 dev_warn(chip->card->dev, "could not constrain periods\n");
231 goto exit; 231 goto exit;
232 } 232 }
233#endif 233#endif
@@ -238,7 +238,7 @@ static int lx_pcm_open(struct snd_pcm_substream *substream)
238 board_rate, board_rate); 238 board_rate, board_rate);
239 239
240 if (err < 0) { 240 if (err < 0) {
241 snd_printk(KERN_WARNING LXP "could not constrain periods\n"); 241 dev_warn(chip->card->dev, "could not constrain periods\n");
242 goto exit; 242 goto exit;
243 } 243 }
244 244
@@ -248,7 +248,7 @@ static int lx_pcm_open(struct snd_pcm_substream *substream)
248 MICROBLAZE_IBL_MIN, 248 MICROBLAZE_IBL_MIN,
249 MICROBLAZE_IBL_MAX); 249 MICROBLAZE_IBL_MAX);
250 if (err < 0) { 250 if (err < 0) {
251 snd_printk(KERN_WARNING LXP 251 dev_warn(chip->card->dev,
252 "could not constrain period size\n"); 252 "could not constrain period size\n");
253 goto exit; 253 goto exit;
254 } 254 }
@@ -263,14 +263,14 @@ exit:
263 runtime->private_data = chip; 263 runtime->private_data = chip;
264 264
265 mutex_unlock(&chip->setup_mutex); 265 mutex_unlock(&chip->setup_mutex);
266 snd_printdd("<-lx_pcm_open, %d\n", err); 266 dev_dbg(chip->card->dev, "<-lx_pcm_open, %d\n", err);
267 return err; 267 return err;
268} 268}
269 269
270static int lx_pcm_close(struct snd_pcm_substream *substream) 270static int lx_pcm_close(struct snd_pcm_substream *substream)
271{ 271{
272 int err = 0; 272 int err = 0;
273 snd_printdd("->lx_pcm_close\n"); 273 dev_dbg(substream->pcm->card->dev, "->lx_pcm_close\n");
274 return err; 274 return err;
275} 275}
276 276
@@ -285,13 +285,13 @@ static snd_pcm_uframes_t lx_pcm_stream_pointer(struct snd_pcm_substream
285 struct lx_stream *lx_stream = is_capture ? &chip->capture_stream : 285 struct lx_stream *lx_stream = is_capture ? &chip->capture_stream :
286 &chip->playback_stream; 286 &chip->playback_stream;
287 287
288 snd_printdd("->lx_pcm_stream_pointer\n"); 288 dev_dbg(chip->card->dev, "->lx_pcm_stream_pointer\n");
289 289
290 spin_lock_irqsave(&chip->lock, flags); 290 spin_lock_irqsave(&chip->lock, flags);
291 pos = lx_stream->frame_pos * substream->runtime->period_size; 291 pos = lx_stream->frame_pos * substream->runtime->period_size;
292 spin_unlock_irqrestore(&chip->lock, flags); 292 spin_unlock_irqrestore(&chip->lock, flags);
293 293
294 snd_printdd(LXP "stream_pointer at %ld\n", pos); 294 dev_dbg(chip->card->dev, "stream_pointer at %ld\n", pos);
295 return pos; 295 return pos;
296} 296}
297 297
@@ -301,37 +301,37 @@ static int lx_pcm_prepare(struct snd_pcm_substream *substream)
301 int err = 0; 301 int err = 0;
302 const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); 302 const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
303 303
304 snd_printdd("->lx_pcm_prepare\n"); 304 dev_dbg(chip->card->dev, "->lx_pcm_prepare\n");
305 305
306 mutex_lock(&chip->setup_mutex); 306 mutex_lock(&chip->setup_mutex);
307 307
308 if (chip->hardware_running[is_capture]) { 308 if (chip->hardware_running[is_capture]) {
309 err = lx_hardware_stop(chip, substream); 309 err = lx_hardware_stop(chip, substream);
310 if (err < 0) { 310 if (err < 0) {
311 snd_printk(KERN_ERR LXP "failed to stop hardware. " 311 dev_err(chip->card->dev, "failed to stop hardware. "
312 "Error code %d\n", err); 312 "Error code %d\n", err);
313 goto exit; 313 goto exit;
314 } 314 }
315 315
316 err = lx_hardware_close(chip, substream); 316 err = lx_hardware_close(chip, substream);
317 if (err < 0) { 317 if (err < 0) {
318 snd_printk(KERN_ERR LXP "failed to close hardware. " 318 dev_err(chip->card->dev, "failed to close hardware. "
319 "Error code %d\n", err); 319 "Error code %d\n", err);
320 goto exit; 320 goto exit;
321 } 321 }
322 } 322 }
323 323
324 snd_printd(LXP "opening hardware\n"); 324 dev_dbg(chip->card->dev, "opening hardware\n");
325 err = lx_hardware_open(chip, substream); 325 err = lx_hardware_open(chip, substream);
326 if (err < 0) { 326 if (err < 0) {
327 snd_printk(KERN_ERR LXP "failed to open hardware. " 327 dev_err(chip->card->dev, "failed to open hardware. "
328 "Error code %d\n", err); 328 "Error code %d\n", err);
329 goto exit; 329 goto exit;
330 } 330 }
331 331
332 err = lx_hardware_start(chip, substream); 332 err = lx_hardware_start(chip, substream);
333 if (err < 0) { 333 if (err < 0) {
334 snd_printk(KERN_ERR LXP "failed to start hardware. " 334 dev_err(chip->card->dev, "failed to start hardware. "
335 "Error code %d\n", err); 335 "Error code %d\n", err);
336 goto exit; 336 goto exit;
337 } 337 }
@@ -354,7 +354,7 @@ static int lx_pcm_hw_params(struct snd_pcm_substream *substream,
354 struct lx6464es *chip = snd_pcm_substream_chip(substream); 354 struct lx6464es *chip = snd_pcm_substream_chip(substream);
355 int err = 0; 355 int err = 0;
356 356
357 snd_printdd("->lx_pcm_hw_params\n"); 357 dev_dbg(chip->card->dev, "->lx_pcm_hw_params\n");
358 358
359 mutex_lock(&chip->setup_mutex); 359 mutex_lock(&chip->setup_mutex);
360 360
@@ -389,20 +389,20 @@ static int lx_pcm_hw_free(struct snd_pcm_substream *substream)
389 int err = 0; 389 int err = 0;
390 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); 390 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
391 391
392 snd_printdd("->lx_pcm_hw_free\n"); 392 dev_dbg(chip->card->dev, "->lx_pcm_hw_free\n");
393 mutex_lock(&chip->setup_mutex); 393 mutex_lock(&chip->setup_mutex);
394 394
395 if (chip->hardware_running[is_capture]) { 395 if (chip->hardware_running[is_capture]) {
396 err = lx_hardware_stop(chip, substream); 396 err = lx_hardware_stop(chip, substream);
397 if (err < 0) { 397 if (err < 0) {
398 snd_printk(KERN_ERR LXP "failed to stop hardware. " 398 dev_err(chip->card->dev, "failed to stop hardware. "
399 "Error code %d\n", err); 399 "Error code %d\n", err);
400 goto exit; 400 goto exit;
401 } 401 }
402 402
403 err = lx_hardware_close(chip, substream); 403 err = lx_hardware_close(chip, substream);
404 if (err < 0) { 404 if (err < 0) {
405 snd_printk(KERN_ERR LXP "failed to close hardware. " 405 dev_err(chip->card->dev, "failed to close hardware. "
406 "Error code %d\n", err); 406 "Error code %d\n", err);
407 goto exit; 407 goto exit;
408 } 408 }
@@ -446,25 +446,25 @@ static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream)
446 446
447 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, 447 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed,
448 size_array); 448 size_array);
449 snd_printdd(LXP "starting: needed %d, freed %d\n", 449 dev_dbg(chip->card->dev, "starting: needed %d, freed %d\n",
450 needed, freed); 450 needed, freed);
451 451
452 err = lx_buffer_give(chip, 0, is_capture, period_bytes, 452 err = lx_buffer_give(chip, 0, is_capture, period_bytes,
453 lower_32_bits(buf), upper_32_bits(buf), 453 lower_32_bits(buf), upper_32_bits(buf),
454 &buffer_index); 454 &buffer_index);
455 455
456 snd_printdd(LXP "starting: buffer index %x on 0x%lx (%d bytes)\n", 456 dev_dbg(chip->card->dev, "starting: buffer index %x on 0x%lx (%d bytes)\n",
457 buffer_index, (unsigned long)buf, period_bytes); 457 buffer_index, (unsigned long)buf, period_bytes);
458 buf += period_bytes; 458 buf += period_bytes;
459 } 459 }
460 460
461 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array); 461 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array);
462 snd_printdd(LXP "starting: needed %d, freed %d\n", needed, freed); 462 dev_dbg(chip->card->dev, "starting: needed %d, freed %d\n", needed, freed);
463 463
464 snd_printd(LXP "starting: starting stream\n"); 464 dev_dbg(chip->card->dev, "starting: starting stream\n");
465 err = lx_stream_start(chip, 0, is_capture); 465 err = lx_stream_start(chip, 0, is_capture);
466 if (err < 0) 466 if (err < 0)
467 snd_printk(KERN_ERR LXP "couldn't start stream\n"); 467 dev_err(chip->card->dev, "couldn't start stream\n");
468 else 468 else
469 lx_stream->status = LX_STREAM_STATUS_RUNNING; 469 lx_stream->status = LX_STREAM_STATUS_RUNNING;
470 470
@@ -476,10 +476,10 @@ static void lx_trigger_stop(struct lx6464es *chip, struct lx_stream *lx_stream)
476 const unsigned int is_capture = lx_stream->is_capture; 476 const unsigned int is_capture = lx_stream->is_capture;
477 int err; 477 int err;
478 478
479 snd_printd(LXP "stopping: stopping stream\n"); 479 dev_dbg(chip->card->dev, "stopping: stopping stream\n");
480 err = lx_stream_stop(chip, 0, is_capture); 480 err = lx_stream_stop(chip, 0, is_capture);
481 if (err < 0) 481 if (err < 0)
482 snd_printk(KERN_ERR LXP "couldn't stop stream\n"); 482 dev_err(chip->card->dev, "couldn't stop stream\n");
483 else 483 else
484 lx_stream->status = LX_STREAM_STATUS_FREE; 484 lx_stream->status = LX_STREAM_STATUS_FREE;
485 485
@@ -507,7 +507,7 @@ static void lx_trigger_tasklet(unsigned long data)
507 struct lx6464es *chip = (struct lx6464es *)data; 507 struct lx6464es *chip = (struct lx6464es *)data;
508 unsigned long flags; 508 unsigned long flags;
509 509
510 snd_printdd("->lx_trigger_tasklet\n"); 510 dev_dbg(chip->card->dev, "->lx_trigger_tasklet\n");
511 511
512 spin_lock_irqsave(&chip->lock, flags); 512 spin_lock_irqsave(&chip->lock, flags);
513 lx_trigger_tasklet_dispatch_stream(chip, &chip->capture_stream); 513 lx_trigger_tasklet_dispatch_stream(chip, &chip->capture_stream);
@@ -547,14 +547,14 @@ static int lx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
547 struct lx_stream *stream = is_capture ? &chip->capture_stream : 547 struct lx_stream *stream = is_capture ? &chip->capture_stream :
548 &chip->playback_stream; 548 &chip->playback_stream;
549 549
550 snd_printdd("->lx_pcm_trigger\n"); 550 dev_dbg(chip->card->dev, "->lx_pcm_trigger\n");
551 551
552 return lx_pcm_trigger_dispatch(chip, stream, cmd); 552 return lx_pcm_trigger_dispatch(chip, stream, cmd);
553} 553}
554 554
555static int snd_lx6464es_free(struct lx6464es *chip) 555static int snd_lx6464es_free(struct lx6464es *chip)
556{ 556{
557 snd_printdd("->snd_lx6464es_free\n"); 557 dev_dbg(chip->card->dev, "->snd_lx6464es_free\n");
558 558
559 lx_irq_disable(chip); 559 lx_irq_disable(chip);
560 560
@@ -583,7 +583,7 @@ static int lx_init_xilinx_reset(struct lx6464es *chip)
583 int i; 583 int i;
584 u32 plx_reg = lx_plx_reg_read(chip, ePLX_CHIPSC); 584 u32 plx_reg = lx_plx_reg_read(chip, ePLX_CHIPSC);
585 585
586 snd_printdd("->lx_init_xilinx_reset\n"); 586 dev_dbg(chip->card->dev, "->lx_init_xilinx_reset\n");
587 587
588 /* activate reset of xilinx */ 588 /* activate reset of xilinx */
589 plx_reg &= ~CHIPSC_RESET_XILINX; 589 plx_reg &= ~CHIPSC_RESET_XILINX;
@@ -603,8 +603,8 @@ static int lx_init_xilinx_reset(struct lx6464es *chip)
603 msleep(10); 603 msleep(10);
604 reg_mbox3 = lx_plx_reg_read(chip, ePLX_MBOX3); 604 reg_mbox3 = lx_plx_reg_read(chip, ePLX_MBOX3);
605 if (reg_mbox3) { 605 if (reg_mbox3) {
606 snd_printd(LXP "xilinx reset done\n"); 606 dev_dbg(chip->card->dev, "xilinx reset done\n");
607 snd_printdd(LXP "xilinx took %d loops\n", i); 607 dev_dbg(chip->card->dev, "xilinx took %d loops\n", i);
608 break; 608 break;
609 } 609 }
610 } 610 }
@@ -624,7 +624,7 @@ static int lx_init_xilinx_test(struct lx6464es *chip)
624{ 624{
625 u32 reg; 625 u32 reg;
626 626
627 snd_printdd("->lx_init_xilinx_test\n"); 627 dev_dbg(chip->card->dev, "->lx_init_xilinx_test\n");
628 628
629 /* TEST if we have access to Xilinx/MicroBlaze */ 629 /* TEST if we have access to Xilinx/MicroBlaze */
630 lx_dsp_reg_write(chip, eReg_CSM, 0); 630 lx_dsp_reg_write(chip, eReg_CSM, 0);
@@ -632,19 +632,19 @@ static int lx_init_xilinx_test(struct lx6464es *chip)
632 reg = lx_dsp_reg_read(chip, eReg_CSM); 632 reg = lx_dsp_reg_read(chip, eReg_CSM);
633 633
634 if (reg) { 634 if (reg) {
635 snd_printk(KERN_ERR LXP "Problem: Reg_CSM %x.\n", reg); 635 dev_err(chip->card->dev, "Problem: Reg_CSM %x.\n", reg);
636 636
637 /* PCI9056_SPACE0_REMAP */ 637 /* PCI9056_SPACE0_REMAP */
638 lx_plx_reg_write(chip, ePLX_PCICR, 1); 638 lx_plx_reg_write(chip, ePLX_PCICR, 1);
639 639
640 reg = lx_dsp_reg_read(chip, eReg_CSM); 640 reg = lx_dsp_reg_read(chip, eReg_CSM);
641 if (reg) { 641 if (reg) {
642 snd_printk(KERN_ERR LXP "Error: Reg_CSM %x.\n", reg); 642 dev_err(chip->card->dev, "Error: Reg_CSM %x.\n", reg);
643 return -EAGAIN; /* seems to be appropriate */ 643 return -EAGAIN; /* seems to be appropriate */
644 } 644 }
645 } 645 }
646 646
647 snd_printd(LXP "Xilinx/MicroBlaze access test successful\n"); 647 dev_dbg(chip->card->dev, "Xilinx/MicroBlaze access test successful\n");
648 648
649 return 0; 649 return 0;
650} 650}
@@ -661,7 +661,7 @@ static int lx_init_ethersound_config(struct lx6464es *chip)
661 (64 << IOCR_OUTPUTS_OFFSET) | 661 (64 << IOCR_OUTPUTS_OFFSET) |
662 (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET); 662 (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET);
663 663
664 snd_printdd("->lx_init_ethersound\n"); 664 dev_dbg(chip->card->dev, "->lx_init_ethersound\n");
665 665
666 chip->freq_ratio = FREQ_RATIO_SINGLE_MODE; 666 chip->freq_ratio = FREQ_RATIO_SINGLE_MODE;
667 667
@@ -675,18 +675,18 @@ static int lx_init_ethersound_config(struct lx6464es *chip)
675 675
676 for (i = 0; i != 1000; ++i) { 676 for (i = 0; i != 1000; ++i) {
677 if (lx_dsp_reg_read(chip, eReg_CSES) & 4) { 677 if (lx_dsp_reg_read(chip, eReg_CSES) & 4) {
678 snd_printd(LXP "ethersound initialized after %dms\n", 678 dev_dbg(chip->card->dev, "ethersound initialized after %dms\n",
679 i); 679 i);
680 goto ethersound_initialized; 680 goto ethersound_initialized;
681 } 681 }
682 msleep(1); 682 msleep(1);
683 } 683 }
684 snd_printk(KERN_WARNING LXP 684 dev_warn(chip->card->dev,
685 "ethersound could not be initialized after %dms\n", i); 685 "ethersound could not be initialized after %dms\n", i);
686 return -ETIMEDOUT; 686 return -ETIMEDOUT;
687 687
688 ethersound_initialized: 688 ethersound_initialized:
689 snd_printd(LXP "ethersound initialized\n"); 689 dev_dbg(chip->card->dev, "ethersound initialized\n");
690 return 0; 690 return 0;
691} 691}
692 692
@@ -696,14 +696,14 @@ static int lx_init_get_version_features(struct lx6464es *chip)
696 696
697 int err; 697 int err;
698 698
699 snd_printdd("->lx_init_get_version_features\n"); 699 dev_dbg(chip->card->dev, "->lx_init_get_version_features\n");
700 700
701 err = lx_dsp_get_version(chip, &dsp_version); 701 err = lx_dsp_get_version(chip, &dsp_version);
702 702
703 if (err == 0) { 703 if (err == 0) {
704 u32 freq; 704 u32 freq;
705 705
706 snd_printk(LXP "DSP version: V%02d.%02d #%d\n", 706 dev_info(chip->card->dev, "DSP version: V%02d.%02d #%d\n",
707 (dsp_version>>16) & 0xff, (dsp_version>>8) & 0xff, 707 (dsp_version>>16) & 0xff, (dsp_version>>8) & 0xff,
708 dsp_version & 0xff); 708 dsp_version & 0xff);
709 709
@@ -718,9 +718,9 @@ static int lx_init_get_version_features(struct lx6464es *chip)
718 err = lx_dsp_get_clock_frequency(chip, &freq); 718 err = lx_dsp_get_clock_frequency(chip, &freq);
719 if (err == 0) 719 if (err == 0)
720 chip->board_sample_rate = freq; 720 chip->board_sample_rate = freq;
721 snd_printd(LXP "actual clock frequency %d\n", freq); 721 dev_dbg(chip->card->dev, "actual clock frequency %d\n", freq);
722 } else { 722 } else {
723 snd_printk(KERN_ERR LXP "DSP corrupted \n"); 723 dev_err(chip->card->dev, "DSP corrupted \n");
724 err = -EAGAIN; 724 err = -EAGAIN;
725 } 725 }
726 726
@@ -732,7 +732,7 @@ static int lx_set_granularity(struct lx6464es *chip, u32 gran)
732 int err = 0; 732 int err = 0;
733 u32 snapped_gran = MICROBLAZE_IBL_MIN; 733 u32 snapped_gran = MICROBLAZE_IBL_MIN;
734 734
735 snd_printdd("->lx_set_granularity\n"); 735 dev_dbg(chip->card->dev, "->lx_set_granularity\n");
736 736
737 /* blocksize is a power of 2 */ 737 /* blocksize is a power of 2 */
738 while ((snapped_gran < gran) && 738 while ((snapped_gran < gran) &&
@@ -745,14 +745,14 @@ static int lx_set_granularity(struct lx6464es *chip, u32 gran)
745 745
746 err = lx_dsp_set_granularity(chip, snapped_gran); 746 err = lx_dsp_set_granularity(chip, snapped_gran);
747 if (err < 0) { 747 if (err < 0) {
748 snd_printk(KERN_WARNING LXP "could not set granularity\n"); 748 dev_warn(chip->card->dev, "could not set granularity\n");
749 err = -EAGAIN; 749 err = -EAGAIN;
750 } 750 }
751 751
752 if (snapped_gran != gran) 752 if (snapped_gran != gran)
753 snd_printk(LXP "snapped blocksize to %d\n", snapped_gran); 753 dev_err(chip->card->dev, "snapped blocksize to %d\n", snapped_gran);
754 754
755 snd_printd(LXP "set blocksize on board %d\n", snapped_gran); 755 dev_dbg(chip->card->dev, "set blocksize on board %d\n", snapped_gran);
756 chip->pcm_granularity = snapped_gran; 756 chip->pcm_granularity = snapped_gran;
757 757
758 return err; 758 return err;
@@ -764,19 +764,19 @@ static int lx_init_dsp(struct lx6464es *chip)
764 int err; 764 int err;
765 int i; 765 int i;
766 766
767 snd_printdd("->lx_init_dsp\n"); 767 dev_dbg(chip->card->dev, "->lx_init_dsp\n");
768 768
769 snd_printd(LXP "initialize board\n"); 769 dev_dbg(chip->card->dev, "initialize board\n");
770 err = lx_init_xilinx_reset(chip); 770 err = lx_init_xilinx_reset(chip);
771 if (err) 771 if (err)
772 return err; 772 return err;
773 773
774 snd_printd(LXP "testing board\n"); 774 dev_dbg(chip->card->dev, "testing board\n");
775 err = lx_init_xilinx_test(chip); 775 err = lx_init_xilinx_test(chip);
776 if (err) 776 if (err)
777 return err; 777 return err;
778 778
779 snd_printd(LXP "initialize ethersound configuration\n"); 779 dev_dbg(chip->card->dev, "initialize ethersound configuration\n");
780 err = lx_init_ethersound_config(chip); 780 err = lx_init_ethersound_config(chip);
781 if (err) 781 if (err)
782 return err; 782 return err;
@@ -797,8 +797,9 @@ static int lx_init_dsp(struct lx6464es *chip)
797 return -ETIMEDOUT; 797 return -ETIMEDOUT;
798 798
799mac_ready: 799mac_ready:
800 snd_printd(LXP "mac address ready read after: %dms\n", i); 800 dev_dbg(chip->card->dev, "mac address ready read after: %dms\n", i);
801 snd_printk(LXP "mac address: %02X.%02X.%02X.%02X.%02X.%02X\n", 801 dev_info(chip->card->dev,
802 "mac address: %02X.%02X.%02X.%02X.%02X.%02X\n",
802 chip->mac_address[0], chip->mac_address[1], chip->mac_address[2], 803 chip->mac_address[0], chip->mac_address[1], chip->mac_address[2],
803 chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]); 804 chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]);
804 805
@@ -977,7 +978,7 @@ static int snd_lx6464es_create(struct snd_card *card,
977 .dev_free = snd_lx6464es_dev_free, 978 .dev_free = snd_lx6464es_dev_free,
978 }; 979 };
979 980
980 snd_printdd("->snd_lx6464es_create\n"); 981 dev_dbg(card->dev, "->snd_lx6464es_create\n");
981 982
982 *rchip = NULL; 983 *rchip = NULL;
983 984
@@ -991,8 +992,8 @@ static int snd_lx6464es_create(struct snd_card *card,
991 /* check if we can restrict PCI DMA transfers to 32 bits */ 992 /* check if we can restrict PCI DMA transfers to 32 bits */
992 err = pci_set_dma_mask(pci, DMA_BIT_MASK(32)); 993 err = pci_set_dma_mask(pci, DMA_BIT_MASK(32));
993 if (err < 0) { 994 if (err < 0) {
994 snd_printk(KERN_ERR "architecture does not support " 995 dev_err(card->dev,
995 "32bit PCI busmaster DMA\n"); 996 "architecture does not support 32bit PCI busmaster DMA\n");
996 pci_disable_device(pci); 997 pci_disable_device(pci);
997 return -ENXIO; 998 return -ENXIO;
998 } 999 }
@@ -1034,7 +1035,7 @@ static int snd_lx6464es_create(struct snd_card *card,
1034 err = request_irq(pci->irq, lx_interrupt, IRQF_SHARED, 1035 err = request_irq(pci->irq, lx_interrupt, IRQF_SHARED,
1035 KBUILD_MODNAME, chip); 1036 KBUILD_MODNAME, chip);
1036 if (err) { 1037 if (err) {
1037 snd_printk(KERN_ERR LXP "unable to grab IRQ %d\n", pci->irq); 1038 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1038 goto request_irq_failed; 1039 goto request_irq_failed;
1039 } 1040 }
1040 chip->irq = pci->irq; 1041 chip->irq = pci->irq;
@@ -1045,7 +1046,7 @@ static int snd_lx6464es_create(struct snd_card *card,
1045 1046
1046 err = lx_init_dsp(chip); 1047 err = lx_init_dsp(chip);
1047 if (err < 0) { 1048 if (err < 0) {
1048 snd_printk(KERN_ERR LXP "error during DSP initialization\n"); 1049 dev_err(card->dev, "error during DSP initialization\n");
1049 return err; 1050 return err;
1050 } 1051 }
1051 1052
@@ -1062,8 +1063,6 @@ static int snd_lx6464es_create(struct snd_card *card,
1062 if (err < 0) 1063 if (err < 0)
1063 return err; 1064 return err;
1064 1065
1065 snd_card_set_dev(card, &pci->dev);
1066
1067 *rchip = chip; 1066 *rchip = chip;
1068 return 0; 1067 return 0;
1069 1068
@@ -1090,7 +1089,7 @@ static int snd_lx6464es_probe(struct pci_dev *pci,
1090 struct lx6464es *chip; 1089 struct lx6464es *chip;
1091 int err; 1090 int err;
1092 1091
1093 snd_printdd("->snd_lx6464es_probe\n"); 1092 dev_dbg(&pci->dev, "->snd_lx6464es_probe\n");
1094 1093
1095 if (dev >= SNDRV_CARDS) 1094 if (dev >= SNDRV_CARDS)
1096 return -ENODEV; 1095 return -ENODEV;
@@ -1099,13 +1098,14 @@ static int snd_lx6464es_probe(struct pci_dev *pci,
1099 return -ENOENT; 1098 return -ENOENT;
1100 } 1099 }
1101 1100
1102 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1101 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1102 0, &card);
1103 if (err < 0) 1103 if (err < 0)
1104 return err; 1104 return err;
1105 1105
1106 err = snd_lx6464es_create(card, pci, &chip); 1106 err = snd_lx6464es_create(card, pci, &chip);
1107 if (err < 0) { 1107 if (err < 0) {
1108 snd_printk(KERN_ERR LXP "error during snd_lx6464es_create\n"); 1108 dev_err(card->dev, "error during snd_lx6464es_create\n");
1109 goto out_free; 1109 goto out_free;
1110 } 1110 }
1111 1111
@@ -1125,7 +1125,7 @@ static int snd_lx6464es_probe(struct pci_dev *pci,
1125 if (err < 0) 1125 if (err < 0)
1126 goto out_free; 1126 goto out_free;
1127 1127
1128 snd_printdd(LXP "initialization successful\n"); 1128 dev_dbg(chip->card->dev, "initialization successful\n");
1129 pci_set_drvdata(pci, card); 1129 pci_set_drvdata(pci, card);
1130 dev++; 1130 dev++;
1131 return 0; 1131 return 0;
diff --git a/sound/pci/lx6464es/lx_core.c b/sound/pci/lx6464es/lx_core.c
index 626ecad4dae7..2d8e95e9fbe5 100644
--- a/sound/pci/lx6464es/lx_core.c
+++ b/sound/pci/lx6464es/lx_core.c
@@ -141,63 +141,6 @@ void lx_plx_reg_write(struct lx6464es *chip, int port, u32 data)
141 iowrite32(data, address); 141 iowrite32(data, address);
142} 142}
143 143
144u32 lx_plx_mbox_read(struct lx6464es *chip, int mbox_nr)
145{
146 int index;
147
148 switch (mbox_nr) {
149 case 1:
150 index = ePLX_MBOX1; break;
151 case 2:
152 index = ePLX_MBOX2; break;
153 case 3:
154 index = ePLX_MBOX3; break;
155 case 4:
156 index = ePLX_MBOX4; break;
157 case 5:
158 index = ePLX_MBOX5; break;
159 case 6:
160 index = ePLX_MBOX6; break;
161 case 7:
162 index = ePLX_MBOX7; break;
163 case 0: /* reserved for HF flags */
164 snd_BUG();
165 default:
166 return 0xdeadbeef;
167 }
168
169 return lx_plx_reg_read(chip, index);
170}
171
172int lx_plx_mbox_write(struct lx6464es *chip, int mbox_nr, u32 value)
173{
174 int index = -1;
175
176 switch (mbox_nr) {
177 case 1:
178 index = ePLX_MBOX1; break;
179 case 3:
180 index = ePLX_MBOX3; break;
181 case 4:
182 index = ePLX_MBOX4; break;
183 case 5:
184 index = ePLX_MBOX5; break;
185 case 6:
186 index = ePLX_MBOX6; break;
187 case 7:
188 index = ePLX_MBOX7; break;
189 case 0: /* reserved for HF flags */
190 case 2: /* reserved for Pipe States
191 * the DSP keeps an image of it */
192 snd_BUG();
193 return -EBADRQC;
194 }
195
196 lx_plx_reg_write(chip, index, value);
197 return 0;
198}
199
200
201/* rmh */ 144/* rmh */
202 145
203#ifdef CONFIG_SND_DEBUG 146#ifdef CONFIG_SND_DEBUG
@@ -330,7 +273,7 @@ static int lx_message_send_atomic(struct lx6464es *chip, struct lx_rmh *rmh)
330 int dwloop; 273 int dwloop;
331 274
332 if (lx_dsp_reg_read(chip, eReg_CSM) & (Reg_CSM_MC | Reg_CSM_MR)) { 275 if (lx_dsp_reg_read(chip, eReg_CSM) & (Reg_CSM_MC | Reg_CSM_MR)) {
333 snd_printk(KERN_ERR LXP "PIOSendMessage eReg_CSM %x\n", reg); 276 dev_err(chip->card->dev, "PIOSendMessage eReg_CSM %x\n", reg);
334 return -EBUSY; 277 return -EBUSY;
335 } 278 }
336 279
@@ -351,7 +294,7 @@ static int lx_message_send_atomic(struct lx6464es *chip, struct lx_rmh *rmh)
351 } else 294 } else
352 udelay(1); 295 udelay(1);
353 } 296 }
354 snd_printk(KERN_WARNING LXP "TIMEOUT lx_message_send_atomic! " 297 dev_warn(chip->card->dev, "TIMEOUT lx_message_send_atomic! "
355 "polling failed\n"); 298 "polling failed\n");
356 299
357polling_successful: 300polling_successful:
@@ -363,18 +306,18 @@ polling_successful:
363 rmh->stat_len); 306 rmh->stat_len);
364 } 307 }
365 } else 308 } else
366 snd_printk(LXP "rmh error: %08x\n", reg); 309 dev_err(chip->card->dev, "rmh error: %08x\n", reg);
367 310
368 /* clear Reg_CSM_MR */ 311 /* clear Reg_CSM_MR */
369 lx_dsp_reg_write(chip, eReg_CSM, 0); 312 lx_dsp_reg_write(chip, eReg_CSM, 0);
370 313
371 switch (reg) { 314 switch (reg) {
372 case ED_DSP_TIMED_OUT: 315 case ED_DSP_TIMED_OUT:
373 snd_printk(KERN_WARNING LXP "lx_message_send: dsp timeout\n"); 316 dev_warn(chip->card->dev, "lx_message_send: dsp timeout\n");
374 return -ETIMEDOUT; 317 return -ETIMEDOUT;
375 318
376 case ED_DSP_CRASHED: 319 case ED_DSP_CRASHED:
377 snd_printk(KERN_WARNING LXP "lx_message_send: dsp crashed\n"); 320 dev_warn(chip->card->dev, "lx_message_send: dsp crashed\n");
378 return -EAGAIN; 321 return -EAGAIN;
379 } 322 }
380 323
@@ -491,33 +434,6 @@ int lx_dsp_read_async_events(struct lx6464es *chip, u32 *data)
491#define CSES_BROADCAST 0x0002 434#define CSES_BROADCAST 0x0002
492#define CSES_UPDATE_LDSV 0x0004 435#define CSES_UPDATE_LDSV 0x0004
493 436
494int lx_dsp_es_check_pipeline(struct lx6464es *chip)
495{
496 int i;
497
498 for (i = 0; i != CSES_TIMEOUT; ++i) {
499 /*
500 * le bit CSES_UPDATE_LDSV est à 1 dés que le macprog
501 * est pret. il re-passe à 0 lorsque le premier read a
502 * été fait. pour l'instant on retire le test car ce bit
503 * passe a 1 environ 200 à 400 ms aprés que le registre
504 * confES à été écrit (kick du xilinx ES).
505 *
506 * On ne teste que le bit CE.
507 * */
508
509 u32 cses = lx_dsp_reg_read(chip, eReg_CSES);
510
511 if ((cses & CSES_CE) == 0)
512 return 0;
513
514 udelay(1);
515 }
516
517 return -ETIMEDOUT;
518}
519
520
521#define PIPE_INFO_TO_CMD(capture, pipe) \ 437#define PIPE_INFO_TO_CMD(capture, pipe) \
522 ((u32)((u32)(pipe) | ((capture) ? ID_IS_CAPTURE : 0L)) << ID_OFFSET) 438 ((u32)((u32)(pipe) | ((capture) ? ID_IS_CAPTURE : 0L)) << ID_OFFSET)
523 439
@@ -542,7 +458,7 @@ int lx_pipe_allocate(struct lx6464es *chip, u32 pipe, int is_capture,
542 spin_unlock_irqrestore(&chip->msg_lock, flags); 458 spin_unlock_irqrestore(&chip->msg_lock, flags);
543 459
544 if (err != 0) 460 if (err != 0)
545 snd_printk(KERN_ERR "lx6464es: could not allocate pipe\n"); 461 dev_err(chip->card->dev, "could not allocate pipe\n");
546 462
547 return err; 463 return err;
548} 464}
@@ -604,11 +520,13 @@ int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture,
604 } 520 }
605 521
606#if 0 522#if 0
607 snd_printdd(LXP "CMD_08_ASK_BUFFERS: needed %d, freed %d\n", 523 dev_dbg(chip->card->dev,
524 "CMD_08_ASK_BUFFERS: needed %d, freed %d\n",
608 *r_needed, *r_freed); 525 *r_needed, *r_freed);
609 for (i = 0; i < MAX_STREAM_BUFFER; ++i) { 526 for (i = 0; i < MAX_STREAM_BUFFER; ++i) {
610 for (i = 0; i != chip->rmh.stat_len; ++i) 527 for (i = 0; i != chip->rmh.stat_len; ++i)
611 snd_printdd(" stat[%d]: %x, %x\n", i, 528 dev_dbg(chip->card->dev,
529 " stat[%d]: %x, %x\n", i,
612 chip->rmh.stat[i], 530 chip->rmh.stat[i],
613 chip->rmh.stat[i] & MASK_DATA_SIZE); 531 chip->rmh.stat[i] & MASK_DATA_SIZE);
614 } 532 }
@@ -701,8 +619,8 @@ int lx_pipe_sample_count(struct lx6464es *chip, u32 pipe, int is_capture,
701 err = lx_message_send_atomic(chip, &chip->rmh); /* don't sleep! */ 619 err = lx_message_send_atomic(chip, &chip->rmh); /* don't sleep! */
702 620
703 if (err != 0) 621 if (err != 0)
704 snd_printk(KERN_ERR 622 dev_err(chip->card->dev,
705 "lx6464es: could not query pipe's sample count\n"); 623 "could not query pipe's sample count\n");
706 else { 624 else {
707 *rsample_count = ((u64)(chip->rmh.stat[0] & MASK_SPL_COUNT_HI) 625 *rsample_count = ((u64)(chip->rmh.stat[0] & MASK_SPL_COUNT_HI)
708 << 24) /* hi part */ 626 << 24) /* hi part */
@@ -728,7 +646,7 @@ int lx_pipe_state(struct lx6464es *chip, u32 pipe, int is_capture, u16 *rstate)
728 err = lx_message_send_atomic(chip, &chip->rmh); 646 err = lx_message_send_atomic(chip, &chip->rmh);
729 647
730 if (err != 0) 648 if (err != 0)
731 snd_printk(KERN_ERR "lx6464es: could not query pipe's state\n"); 649 dev_err(chip->card->dev, "could not query pipe's state\n");
732 else 650 else
733 *rstate = (chip->rmh.stat[0] >> PSTATE_OFFSET) & 0x0F; 651 *rstate = (chip->rmh.stat[0] >> PSTATE_OFFSET) & 0x0F;
734 652
@@ -801,7 +719,7 @@ int lx_stream_set_format(struct lx6464es *chip, struct snd_pcm_runtime *runtime,
801 u32 channels = runtime->channels; 719 u32 channels = runtime->channels;
802 720
803 if (runtime->channels != channels) 721 if (runtime->channels != channels)
804 snd_printk(KERN_ERR LXP "channel count mismatch: %d vs %d", 722 dev_err(chip->card->dev, "channel count mismatch: %d vs %d",
805 runtime->channels, channels); 723 runtime->channels, channels);
806 724
807 spin_lock_irqsave(&chip->msg_lock, flags); 725 spin_lock_irqsave(&chip->msg_lock, flags);
@@ -904,13 +822,16 @@ int lx_buffer_give(struct lx6464es *chip, u32 pipe, int is_capture,
904 } 822 }
905 823
906 if (err == EB_RBUFFERS_TABLE_OVERFLOW) 824 if (err == EB_RBUFFERS_TABLE_OVERFLOW)
907 snd_printk(LXP "lx_buffer_give EB_RBUFFERS_TABLE_OVERFLOW\n"); 825 dev_err(chip->card->dev,
826 "lx_buffer_give EB_RBUFFERS_TABLE_OVERFLOW\n");
908 827
909 if (err == EB_INVALID_STREAM) 828 if (err == EB_INVALID_STREAM)
910 snd_printk(LXP "lx_buffer_give EB_INVALID_STREAM\n"); 829 dev_err(chip->card->dev,
830 "lx_buffer_give EB_INVALID_STREAM\n");
911 831
912 if (err == EB_CMD_REFUSED) 832 if (err == EB_CMD_REFUSED)
913 snd_printk(LXP "lx_buffer_give EB_CMD_REFUSED\n"); 833 dev_err(chip->card->dev,
834 "lx_buffer_give EB_CMD_REFUSED\n");
914 835
915 done: 836 done:
916 spin_unlock_irqrestore(&chip->msg_lock, flags); 837 spin_unlock_irqrestore(&chip->msg_lock, flags);
@@ -983,7 +904,8 @@ int lx_level_unmute(struct lx6464es *chip, int is_capture, int unmute)
983 chip->rmh.cmd[1] = (u32)(mute_mask >> (u64)32); /* hi part */ 904 chip->rmh.cmd[1] = (u32)(mute_mask >> (u64)32); /* hi part */
984 chip->rmh.cmd[2] = (u32)(mute_mask & (u64)0xFFFFFFFF); /* lo part */ 905 chip->rmh.cmd[2] = (u32)(mute_mask & (u64)0xFFFFFFFF); /* lo part */
985 906
986 snd_printk("mute %x %x %x\n", chip->rmh.cmd[0], chip->rmh.cmd[1], 907 dev_dbg(chip->card->dev,
908 "mute %x %x %x\n", chip->rmh.cmd[0], chip->rmh.cmd[1],
987 chip->rmh.cmd[2]); 909 chip->rmh.cmd[2]);
988 910
989 err = lx_message_send_atomic(chip, &chip->rmh); 911 err = lx_message_send_atomic(chip, &chip->rmh);
@@ -1093,7 +1015,7 @@ static int lx_interrupt_ack(struct lx6464es *chip, u32 *r_irqsrc,
1093 } 1015 }
1094 1016
1095 if (irq_async) { 1017 if (irq_async) {
1096 /* snd_printd("interrupt: async event pending\n"); */ 1018 /* dev_dbg(chip->card->dev, "interrupt: async event pending\n"); */
1097 *r_async_pending = 1; 1019 *r_async_pending = 1;
1098 } 1020 }
1099 1021
@@ -1139,13 +1061,13 @@ static int lx_interrupt_handle_async_events(struct lx6464es *chip, u32 irqsrc,
1139 if (eb_pending_in) { 1061 if (eb_pending_in) {
1140 *r_notified_in_pipe_mask = ((u64)stat[3] << 32) 1062 *r_notified_in_pipe_mask = ((u64)stat[3] << 32)
1141 + stat[4]; 1063 + stat[4];
1142 snd_printdd(LXP "interrupt: EOBI pending %llx\n", 1064 dev_dbg(chip->card->dev, "interrupt: EOBI pending %llx\n",
1143 *r_notified_in_pipe_mask); 1065 *r_notified_in_pipe_mask);
1144 } 1066 }
1145 if (eb_pending_out) { 1067 if (eb_pending_out) {
1146 *r_notified_out_pipe_mask = ((u64)stat[1] << 32) 1068 *r_notified_out_pipe_mask = ((u64)stat[1] << 32)
1147 + stat[2]; 1069 + stat[2];
1148 snd_printdd(LXP "interrupt: EOBO pending %llx\n", 1070 dev_dbg(chip->card->dev, "interrupt: EOBO pending %llx\n",
1149 *r_notified_out_pipe_mask); 1071 *r_notified_out_pipe_mask);
1150 } 1072 }
1151 1073
@@ -1181,17 +1103,19 @@ static int lx_interrupt_request_new_buffer(struct lx6464es *chip,
1181 u32 needed, freed; 1103 u32 needed, freed;
1182 u32 size_array[MAX_STREAM_BUFFER]; 1104 u32 size_array[MAX_STREAM_BUFFER];
1183 1105
1184 snd_printdd("->lx_interrupt_request_new_buffer\n"); 1106 dev_dbg(chip->card->dev, "->lx_interrupt_request_new_buffer\n");
1185 1107
1186 spin_lock_irqsave(&chip->lock, flags); 1108 spin_lock_irqsave(&chip->lock, flags);
1187 1109
1188 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array); 1110 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array);
1189 snd_printdd(LXP "interrupt: needed %d, freed %d\n", needed, freed); 1111 dev_dbg(chip->card->dev,
1112 "interrupt: needed %d, freed %d\n", needed, freed);
1190 1113
1191 unpack_pointer(buf, &buf_lo, &buf_hi); 1114 unpack_pointer(buf, &buf_lo, &buf_hi);
1192 err = lx_buffer_give(chip, 0, is_capture, period_bytes, buf_lo, buf_hi, 1115 err = lx_buffer_give(chip, 0, is_capture, period_bytes, buf_lo, buf_hi,
1193 &buffer_index); 1116 &buffer_index);
1194 snd_printdd(LXP "interrupt: gave buffer index %x on 0x%lx (%d bytes)\n", 1117 dev_dbg(chip->card->dev,
1118 "interrupt: gave buffer index %x on 0x%lx (%d bytes)\n",
1195 buffer_index, (unsigned long)buf, period_bytes); 1119 buffer_index, (unsigned long)buf, period_bytes);
1196 1120
1197 lx_stream->frame_pos = next_pos; 1121 lx_stream->frame_pos = next_pos;
@@ -1206,11 +1130,11 @@ void lx_tasklet_playback(unsigned long data)
1206 struct lx_stream *lx_stream = &chip->playback_stream; 1130 struct lx_stream *lx_stream = &chip->playback_stream;
1207 int err; 1131 int err;
1208 1132
1209 snd_printdd("->lx_tasklet_playback\n"); 1133 dev_dbg(chip->card->dev, "->lx_tasklet_playback\n");
1210 1134
1211 err = lx_interrupt_request_new_buffer(chip, lx_stream); 1135 err = lx_interrupt_request_new_buffer(chip, lx_stream);
1212 if (err < 0) 1136 if (err < 0)
1213 snd_printk(KERN_ERR LXP 1137 dev_err(chip->card->dev,
1214 "cannot request new buffer for playback\n"); 1138 "cannot request new buffer for playback\n");
1215 1139
1216 snd_pcm_period_elapsed(lx_stream->stream); 1140 snd_pcm_period_elapsed(lx_stream->stream);
@@ -1222,10 +1146,10 @@ void lx_tasklet_capture(unsigned long data)
1222 struct lx_stream *lx_stream = &chip->capture_stream; 1146 struct lx_stream *lx_stream = &chip->capture_stream;
1223 int err; 1147 int err;
1224 1148
1225 snd_printdd("->lx_tasklet_capture\n"); 1149 dev_dbg(chip->card->dev, "->lx_tasklet_capture\n");
1226 err = lx_interrupt_request_new_buffer(chip, lx_stream); 1150 err = lx_interrupt_request_new_buffer(chip, lx_stream);
1227 if (err < 0) 1151 if (err < 0)
1228 snd_printk(KERN_ERR LXP 1152 dev_err(chip->card->dev,
1229 "cannot request new buffer for capture\n"); 1153 "cannot request new buffer for capture\n");
1230 1154
1231 snd_pcm_period_elapsed(lx_stream->stream); 1155 snd_pcm_period_elapsed(lx_stream->stream);
@@ -1240,12 +1164,14 @@ static int lx_interrupt_handle_audio_transfer(struct lx6464es *chip,
1240 int err = 0; 1164 int err = 0;
1241 1165
1242 if (notified_in_pipe_mask) { 1166 if (notified_in_pipe_mask) {
1243 snd_printdd(LXP "requesting audio transfer for capture\n"); 1167 dev_dbg(chip->card->dev,
1168 "requesting audio transfer for capture\n");
1244 tasklet_hi_schedule(&chip->tasklet_capture); 1169 tasklet_hi_schedule(&chip->tasklet_capture);
1245 } 1170 }
1246 1171
1247 if (notified_out_pipe_mask) { 1172 if (notified_out_pipe_mask) {
1248 snd_printdd(LXP "requesting audio transfer for playback\n"); 1173 dev_dbg(chip->card->dev,
1174 "requesting audio transfer for playback\n");
1249 tasklet_hi_schedule(&chip->tasklet_playback); 1175 tasklet_hi_schedule(&chip->tasklet_playback);
1250 } 1176 }
1251 1177
@@ -1261,11 +1187,12 @@ irqreturn_t lx_interrupt(int irq, void *dev_id)
1261 1187
1262 spin_lock(&chip->lock); 1188 spin_lock(&chip->lock);
1263 1189
1264 snd_printdd("**************************************************\n"); 1190 dev_dbg(chip->card->dev,
1191 "**************************************************\n");
1265 1192
1266 if (!lx_interrupt_ack(chip, &irqsrc, &async_pending, &async_escmd)) { 1193 if (!lx_interrupt_ack(chip, &irqsrc, &async_pending, &async_escmd)) {
1267 spin_unlock(&chip->lock); 1194 spin_unlock(&chip->lock);
1268 snd_printdd("IRQ_NONE\n"); 1195 dev_dbg(chip->card->dev, "IRQ_NONE\n");
1269 return IRQ_NONE; /* this device did not cause the interrupt */ 1196 return IRQ_NONE; /* this device did not cause the interrupt */
1270 } 1197 }
1271 1198
@@ -1274,16 +1201,16 @@ irqreturn_t lx_interrupt(int irq, void *dev_id)
1274 1201
1275#if 0 1202#if 0
1276 if (irqsrc & MASK_SYS_STATUS_EOBI) 1203 if (irqsrc & MASK_SYS_STATUS_EOBI)
1277 snd_printdd(LXP "interrupt: EOBI\n"); 1204 dev_dgg(chip->card->dev, "interrupt: EOBI\n");
1278 1205
1279 if (irqsrc & MASK_SYS_STATUS_EOBO) 1206 if (irqsrc & MASK_SYS_STATUS_EOBO)
1280 snd_printdd(LXP "interrupt: EOBO\n"); 1207 dev_dbg(chip->card->dev, "interrupt: EOBO\n");
1281 1208
1282 if (irqsrc & MASK_SYS_STATUS_URUN) 1209 if (irqsrc & MASK_SYS_STATUS_URUN)
1283 snd_printdd(LXP "interrupt: URUN\n"); 1210 dev_dbg(chip->card->dev, "interrupt: URUN\n");
1284 1211
1285 if (irqsrc & MASK_SYS_STATUS_ORUN) 1212 if (irqsrc & MASK_SYS_STATUS_ORUN)
1286 snd_printdd(LXP "interrupt: ORUN\n"); 1213 dev_dbg(chip->card->dev, "interrupt: ORUN\n");
1287#endif 1214#endif
1288 1215
1289 if (async_pending) { 1216 if (async_pending) {
@@ -1298,7 +1225,7 @@ irqreturn_t lx_interrupt(int irq, void *dev_id)
1298 &notified_in_pipe_mask, 1225 &notified_in_pipe_mask,
1299 &notified_out_pipe_mask); 1226 &notified_out_pipe_mask);
1300 if (err) 1227 if (err)
1301 snd_printk(KERN_ERR LXP 1228 dev_err(chip->card->dev,
1302 "error handling async events\n"); 1229 "error handling async events\n");
1303 1230
1304 err = lx_interrupt_handle_audio_transfer(chip, 1231 err = lx_interrupt_handle_audio_transfer(chip,
@@ -1306,7 +1233,7 @@ irqreturn_t lx_interrupt(int irq, void *dev_id)
1306 notified_out_pipe_mask 1233 notified_out_pipe_mask
1307 ); 1234 );
1308 if (err) 1235 if (err)
1309 snd_printk(KERN_ERR LXP 1236 dev_err(chip->card->dev,
1310 "error during audio transfer\n"); 1237 "error during audio transfer\n");
1311 } 1238 }
1312 1239
@@ -1318,7 +1245,7 @@ irqreturn_t lx_interrupt(int irq, void *dev_id)
1318 * 1245 *
1319 * */ 1246 * */
1320 1247
1321 snd_printdd("lx6464es: interrupt requests escmd handling\n"); 1248 dev_dbg(chip->card->dev, "interrupt requests escmd handling\n");
1322#endif 1249#endif
1323 } 1250 }
1324 1251
@@ -1346,12 +1273,12 @@ static void lx_irq_set(struct lx6464es *chip, int enable)
1346 1273
1347void lx_irq_enable(struct lx6464es *chip) 1274void lx_irq_enable(struct lx6464es *chip)
1348{ 1275{
1349 snd_printdd("->lx_irq_enable\n"); 1276 dev_dbg(chip->card->dev, "->lx_irq_enable\n");
1350 lx_irq_set(chip, 1); 1277 lx_irq_set(chip, 1);
1351} 1278}
1352 1279
1353void lx_irq_disable(struct lx6464es *chip) 1280void lx_irq_disable(struct lx6464es *chip)
1354{ 1281{
1355 snd_printdd("->lx_irq_disable\n"); 1282 dev_dbg(chip->card->dev, "->lx_irq_disable\n");
1356 lx_irq_set(chip, 0); 1283 lx_irq_set(chip, 0);
1357} 1284}
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index d5417360f51f..0d3ea3e79952 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -1403,7 +1403,7 @@ static int snd_m3_pcm_hw_params(struct snd_pcm_substream *substream,
1403 /* set buffer address */ 1403 /* set buffer address */
1404 s->buffer_addr = substream->runtime->dma_addr; 1404 s->buffer_addr = substream->runtime->dma_addr;
1405 if (s->buffer_addr & 0x3) { 1405 if (s->buffer_addr & 0x3) {
1406 snd_printk(KERN_ERR "oh my, not aligned\n"); 1406 dev_err(substream->pcm->card->dev, "oh my, not aligned\n");
1407 s->buffer_addr = s->buffer_addr & ~0x3; 1407 s->buffer_addr = s->buffer_addr & ~0x3;
1408 } 1408 }
1409 return 0; 1409 return 0;
@@ -1900,7 +1900,7 @@ static int snd_m3_ac97_wait(struct snd_m3 *chip)
1900 cpu_relax(); 1900 cpu_relax();
1901 } while (i-- > 0); 1901 } while (i-- > 0);
1902 1902
1903 snd_printk(KERN_ERR "ac97 serial bus busy\n"); 1903 dev_err(chip->card->dev, "ac97 serial bus busy\n");
1904 return 1; 1904 return 1;
1905} 1905}
1906 1906
@@ -2015,7 +2015,8 @@ static void snd_m3_ac97_reset(struct snd_m3 *chip)
2015 delay1 += 10; 2015 delay1 += 10;
2016 delay2 += 100; 2016 delay2 += 100;
2017 2017
2018 snd_printd("maestro3: retrying codec reset with delays of %d and %d ms\n", 2018 dev_dbg(chip->card->dev,
2019 "retrying codec reset with delays of %d and %d ms\n",
2019 delay1, delay2); 2020 delay1, delay2);
2020 } 2021 }
2021 2022
@@ -2194,7 +2195,8 @@ static int snd_m3_assp_client_init(struct snd_m3 *chip, struct m3_dma *s, int in
2194 address = 0x1100 + ((data_bytes/2) * index); 2195 address = 0x1100 + ((data_bytes/2) * index);
2195 2196
2196 if ((address + (data_bytes/2)) >= 0x1c00) { 2197 if ((address + (data_bytes/2)) >= 0x1c00) {
2197 snd_printk(KERN_ERR "no memory for %d bytes at ind %d (addr 0x%x)\n", 2198 dev_err(chip->card->dev,
2199 "no memory for %d bytes at ind %d (addr 0x%x)\n",
2198 data_bytes, index, address); 2200 data_bytes, index, address);
2199 return -ENOMEM; 2201 return -ENOMEM;
2200 } 2202 }
@@ -2439,8 +2441,7 @@ static int m3_resume(struct device *dev)
2439 pci_set_power_state(pci, PCI_D0); 2441 pci_set_power_state(pci, PCI_D0);
2440 pci_restore_state(pci); 2442 pci_restore_state(pci);
2441 if (pci_enable_device(pci) < 0) { 2443 if (pci_enable_device(pci) < 0) {
2442 printk(KERN_ERR "maestor3: pci_enable_device failed, " 2444 dev_err(dev, "pci_enable_device failed, disabling device\n");
2443 "disabling device\n");
2444 snd_card_disconnect(card); 2445 snd_card_disconnect(card);
2445 return -EIO; 2446 return -EIO;
2446 } 2447 }
@@ -2553,7 +2554,8 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
2553 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2554 /* check, if we can restrict PCI DMA transfers to 28 bits */
2554 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || 2555 if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
2555 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { 2556 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) {
2556 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n"); 2557 dev_err(card->dev,
2558 "architecture does not support 28bit PCI busmaster DMA\n");
2557 pci_disable_device(pci); 2559 pci_disable_device(pci);
2558 return -ENXIO; 2560 return -ENXIO;
2559 } 2561 }
@@ -2586,9 +2588,8 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
2586 else { 2588 else {
2587 quirk = snd_pci_quirk_lookup(pci, m3_amp_quirk_list); 2589 quirk = snd_pci_quirk_lookup(pci, m3_amp_quirk_list);
2588 if (quirk) { 2590 if (quirk) {
2589 snd_printdd(KERN_INFO 2591 dev_info(card->dev, "set amp-gpio for '%s'\n",
2590 "maestro3: set amp-gpio for '%s'\n", 2592 snd_pci_quirk_name(quirk));
2591 snd_pci_quirk_name(quirk));
2592 chip->amp_gpio = quirk->value; 2593 chip->amp_gpio = quirk->value;
2593 } else if (chip->allegro_flag) 2594 } else if (chip->allegro_flag)
2594 chip->amp_gpio = GPO_EXT_AMP_ALLEGRO; 2595 chip->amp_gpio = GPO_EXT_AMP_ALLEGRO;
@@ -2598,9 +2599,8 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
2598 2599
2599 quirk = snd_pci_quirk_lookup(pci, m3_irda_quirk_list); 2600 quirk = snd_pci_quirk_lookup(pci, m3_irda_quirk_list);
2600 if (quirk) { 2601 if (quirk) {
2601 snd_printdd(KERN_INFO 2602 dev_info(card->dev, "enabled irda workaround for '%s'\n",
2602 "maestro3: enabled irda workaround for '%s'\n", 2603 snd_pci_quirk_name(quirk));
2603 snd_pci_quirk_name(quirk));
2604 chip->irda_workaround = 1; 2604 chip->irda_workaround = 1;
2605 } 2605 }
2606 quirk = snd_pci_quirk_lookup(pci, m3_hv_quirk_list); 2606 quirk = snd_pci_quirk_lookup(pci, m3_hv_quirk_list);
@@ -2652,7 +2652,7 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
2652 2652
2653 if (request_irq(pci->irq, snd_m3_interrupt, IRQF_SHARED, 2653 if (request_irq(pci->irq, snd_m3_interrupt, IRQF_SHARED,
2654 KBUILD_MODNAME, chip)) { 2654 KBUILD_MODNAME, chip)) {
2655 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 2655 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
2656 snd_m3_free(chip); 2656 snd_m3_free(chip);
2657 return -ENOMEM; 2657 return -ENOMEM;
2658 } 2658 }
@@ -2661,7 +2661,7 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
2661#ifdef CONFIG_PM_SLEEP 2661#ifdef CONFIG_PM_SLEEP
2662 chip->suspend_mem = vmalloc(sizeof(u16) * (REV_B_CODE_MEMORY_LENGTH + REV_B_DATA_MEMORY_LENGTH)); 2662 chip->suspend_mem = vmalloc(sizeof(u16) * (REV_B_CODE_MEMORY_LENGTH + REV_B_DATA_MEMORY_LENGTH));
2663 if (chip->suspend_mem == NULL) 2663 if (chip->suspend_mem == NULL)
2664 snd_printk(KERN_WARNING "can't allocate apm buffer\n"); 2664 dev_warn(card->dev, "can't allocate apm buffer\n");
2665#endif 2665#endif
2666 2666
2667 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 2667 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
@@ -2685,16 +2685,15 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
2685 if (chip->hv_config & HV_CTRL_ENABLE) { 2685 if (chip->hv_config & HV_CTRL_ENABLE) {
2686 err = snd_m3_input_register(chip); 2686 err = snd_m3_input_register(chip);
2687 if (err) 2687 if (err)
2688 snd_printk(KERN_WARNING "Input device registration " 2688 dev_warn(card->dev,
2689 "failed with error %i", err); 2689 "Input device registration failed with error %i",
2690 err);
2690 } 2691 }
2691#endif 2692#endif
2692 2693
2693 snd_m3_enable_ints(chip); 2694 snd_m3_enable_ints(chip);
2694 snd_m3_assp_continue(chip); 2695 snd_m3_assp_continue(chip);
2695 2696
2696 snd_card_set_dev(card, &pci->dev);
2697
2698 *chip_ret = chip; 2697 *chip_ret = chip;
2699 2698
2700 return 0; 2699 return 0;
@@ -2721,7 +2720,8 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2721 return -ENOENT; 2720 return -ENOENT;
2722 } 2721 }
2723 2722
2724 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2723 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2724 0, &card);
2725 if (err < 0) 2725 if (err < 0)
2726 return err; 2726 return err;
2727 2727
@@ -2764,7 +2764,7 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2764 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, 2764 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
2765 -1, &chip->rmidi); 2765 -1, &chip->rmidi);
2766 if (err < 0) 2766 if (err < 0)
2767 printk(KERN_WARNING "maestro3: no MIDI support.\n"); 2767 dev_warn(card->dev, "no MIDI support.\n");
2768#endif 2768#endif
2769 2769
2770 pci_set_drvdata(pci, card); 2770 pci_set_drvdata(pci, card);
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index 1e0f6ee193f0..a93e7af51eed 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -87,7 +87,8 @@ static int mixart_set_pipe_state(struct mixart_mgr *mgr,
87 if(!start) return 0; /* already stopped */ 87 if(!start) return 0; /* already stopped */
88 break; 88 break;
89 default: 89 default:
90 snd_printk(KERN_ERR "error mixart_set_pipe_state called with wrong pipe->status!\n"); 90 dev_err(&mgr->pci->dev,
91 "error mixart_set_pipe_state called with wrong pipe->status!\n");
91 return -EINVAL; /* function called with wrong pipe status */ 92 return -EINVAL; /* function called with wrong pipe status */
92 } 93 }
93 94
@@ -102,7 +103,8 @@ static int mixart_set_pipe_state(struct mixart_mgr *mgr,
102 103
103 err = snd_mixart_send_msg_wait_notif(mgr, &request, system_msg_uid); 104 err = snd_mixart_send_msg_wait_notif(mgr, &request, system_msg_uid);
104 if(err) { 105 if(err) {
105 snd_printk(KERN_ERR "error : MSG_SYSTEM_WAIT_SYNCHRO_CMD was not notified !\n"); 106 dev_err(&mgr->pci->dev,
107 "error : MSG_SYSTEM_WAIT_SYNCHRO_CMD was not notified !\n");
106 return err; 108 return err;
107 } 109 }
108 110
@@ -123,7 +125,9 @@ static int mixart_set_pipe_state(struct mixart_mgr *mgr,
123 125
124 err = snd_mixart_send_msg(mgr, &request, sizeof(group_state_resp), &group_state_resp); 126 err = snd_mixart_send_msg(mgr, &request, sizeof(group_state_resp), &group_state_resp);
125 if (err < 0 || group_state_resp.txx_status != 0) { 127 if (err < 0 || group_state_resp.txx_status != 0) {
126 snd_printk(KERN_ERR "error MSG_STREAM_ST***_STREAM_GRP_PACKET err=%x stat=%x !\n", err, group_state_resp.txx_status); 128 dev_err(&mgr->pci->dev,
129 "error MSG_STREAM_ST***_STREAM_GRP_PACKET err=%x stat=%x !\n",
130 err, group_state_resp.txx_status);
127 return -EINVAL; 131 return -EINVAL;
128 } 132 }
129 133
@@ -134,7 +138,9 @@ static int mixart_set_pipe_state(struct mixart_mgr *mgr,
134 138
135 err = snd_mixart_send_msg(mgr, &request, sizeof(group_state_resp), &group_state_resp); 139 err = snd_mixart_send_msg(mgr, &request, sizeof(group_state_resp), &group_state_resp);
136 if (err < 0 || group_state_resp.txx_status != 0) { 140 if (err < 0 || group_state_resp.txx_status != 0) {
137 snd_printk(KERN_ERR "error MSG_STREAM_START_STREAM_GRP_PACKET err=%x stat=%x !\n", err, group_state_resp.txx_status); 141 dev_err(&mgr->pci->dev,
142 "error MSG_STREAM_START_STREAM_GRP_PACKET err=%x stat=%x !\n",
143 err, group_state_resp.txx_status);
138 return -EINVAL; 144 return -EINVAL;
139 } 145 }
140 146
@@ -147,7 +153,9 @@ static int mixart_set_pipe_state(struct mixart_mgr *mgr,
147 153
148 err = snd_mixart_send_msg(mgr, &request, sizeof(stat), &stat); 154 err = snd_mixart_send_msg(mgr, &request, sizeof(stat), &stat);
149 if (err < 0 || stat != 0) { 155 if (err < 0 || stat != 0) {
150 snd_printk(KERN_ERR "error MSG_SYSTEM_SEND_SYNCHRO_CMD err=%x stat=%x !\n", err, stat); 156 dev_err(&mgr->pci->dev,
157 "error MSG_SYSTEM_SEND_SYNCHRO_CMD err=%x stat=%x !\n",
158 err, stat);
151 return -EINVAL; 159 return -EINVAL;
152 } 160 }
153 161
@@ -178,7 +186,9 @@ static int mixart_set_clock(struct mixart_mgr *mgr,
178 if(rate == 0) 186 if(rate == 0)
179 return 0; /* nothing to do */ 187 return 0; /* nothing to do */
180 else { 188 else {
181 snd_printk(KERN_ERR "error mixart_set_clock(%d) called with wrong pipe->status !\n", rate); 189 dev_err(&mgr->pci->dev,
190 "error mixart_set_clock(%d) called with wrong pipe->status !\n",
191 rate);
182 return -EINVAL; 192 return -EINVAL;
183 } 193 }
184 } 194 }
@@ -190,7 +200,7 @@ static int mixart_set_clock(struct mixart_mgr *mgr,
190 clock_properties.nb_callers = 1; /* only one entry in uid_caller ! */ 200 clock_properties.nb_callers = 1; /* only one entry in uid_caller ! */
191 clock_properties.uid_caller[0] = pipe->group_uid; 201 clock_properties.uid_caller[0] = pipe->group_uid;
192 202
193 snd_printdd("mixart_set_clock to %d kHz\n", rate); 203 dev_dbg(&mgr->pci->dev, "mixart_set_clock to %d kHz\n", rate);
194 204
195 request.message_id = MSG_CLOCK_SET_PROPERTIES; 205 request.message_id = MSG_CLOCK_SET_PROPERTIES;
196 request.uid = mgr->uid_console_manager; 206 request.uid = mgr->uid_console_manager;
@@ -199,7 +209,9 @@ static int mixart_set_clock(struct mixart_mgr *mgr,
199 209
200 err = snd_mixart_send_msg(mgr, &request, sizeof(clock_prop_resp), &clock_prop_resp); 210 err = snd_mixart_send_msg(mgr, &request, sizeof(clock_prop_resp), &clock_prop_resp);
201 if (err < 0 || clock_prop_resp.status != 0 || clock_prop_resp.clock_mode != CM_STANDALONE) { 211 if (err < 0 || clock_prop_resp.status != 0 || clock_prop_resp.clock_mode != CM_STANDALONE) {
202 snd_printk(KERN_ERR "error MSG_CLOCK_SET_PROPERTIES err=%x stat=%x mod=%x !\n", err, clock_prop_resp.status, clock_prop_resp.clock_mode); 212 dev_err(&mgr->pci->dev,
213 "error MSG_CLOCK_SET_PROPERTIES err=%x stat=%x mod=%x !\n",
214 err, clock_prop_resp.status, clock_prop_resp.clock_mode);
203 return -EINVAL; 215 return -EINVAL;
204 } 216 }
205 217
@@ -252,7 +264,9 @@ snd_mixart_add_ref_pipe(struct snd_mixart *chip, int pcm_number, int capture,
252 struct mixart_streaming_group sgroup_resp; 264 struct mixart_streaming_group sgroup_resp;
253 } *buf; 265 } *buf;
254 266
255 snd_printdd("add_ref_pipe audio chip(%d) pcm(%d)\n", chip->chip_idx, pcm_number); 267 dev_dbg(chip->card->dev,
268 "add_ref_pipe audio chip(%d) pcm(%d)\n",
269 chip->chip_idx, pcm_number);
256 270
257 buf = kmalloc(sizeof(*buf), GFP_KERNEL); 271 buf = kmalloc(sizeof(*buf), GFP_KERNEL);
258 if (!buf) 272 if (!buf)
@@ -302,7 +316,9 @@ snd_mixart_add_ref_pipe(struct snd_mixart *chip, int pcm_number, int capture,
302 316
303 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(buf->sgroup_resp), &buf->sgroup_resp); 317 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(buf->sgroup_resp), &buf->sgroup_resp);
304 if((err < 0) || (buf->sgroup_resp.status != 0)) { 318 if((err < 0) || (buf->sgroup_resp.status != 0)) {
305 snd_printk(KERN_ERR "error MSG_STREAM_ADD_**PUT_GROUP err=%x stat=%x !\n", err, buf->sgroup_resp.status); 319 dev_err(chip->card->dev,
320 "error MSG_STREAM_ADD_**PUT_GROUP err=%x stat=%x !\n",
321 err, buf->sgroup_resp.status);
306 kfree(buf); 322 kfree(buf);
307 return NULL; 323 return NULL;
308 } 324 }
@@ -343,13 +359,14 @@ int snd_mixart_kill_ref_pipe(struct mixart_mgr *mgr,
343 /* release the clock */ 359 /* release the clock */
344 err = mixart_set_clock( mgr, pipe, 0); 360 err = mixart_set_clock( mgr, pipe, 0);
345 if( err < 0 ) { 361 if( err < 0 ) {
346 snd_printk(KERN_ERR "mixart_set_clock(0) return error!\n"); 362 dev_err(&mgr->pci->dev,
363 "mixart_set_clock(0) return error!\n");
347 } 364 }
348 365
349 /* stop the pipe */ 366 /* stop the pipe */
350 err = mixart_set_pipe_state(mgr, pipe, 0); 367 err = mixart_set_pipe_state(mgr, pipe, 0);
351 if( err < 0 ) { 368 if( err < 0 ) {
352 snd_printk(KERN_ERR "error stopping pipe!\n"); 369 dev_err(&mgr->pci->dev, "error stopping pipe!\n");
353 } 370 }
354 371
355 request.message_id = MSG_STREAM_DELETE_GROUP; 372 request.message_id = MSG_STREAM_DELETE_GROUP;
@@ -360,7 +377,9 @@ int snd_mixart_kill_ref_pipe(struct mixart_mgr *mgr,
360 /* delete the pipe */ 377 /* delete the pipe */
361 err = snd_mixart_send_msg(mgr, &request, sizeof(delete_resp), &delete_resp); 378 err = snd_mixart_send_msg(mgr, &request, sizeof(delete_resp), &delete_resp);
362 if ((err < 0) || (delete_resp.status != 0)) { 379 if ((err < 0) || (delete_resp.status != 0)) {
363 snd_printk(KERN_ERR "error MSG_STREAM_DELETE_GROUP err(%x), status(%x)\n", err, delete_resp.status); 380 dev_err(&mgr->pci->dev,
381 "error MSG_STREAM_DELETE_GROUP err(%x), status(%x)\n",
382 err, delete_resp.status);
364 } 383 }
365 384
366 pipe->group_uid = (struct mixart_uid){0,0}; 385 pipe->group_uid = (struct mixart_uid){0,0};
@@ -414,7 +433,7 @@ static int snd_mixart_trigger(struct snd_pcm_substream *subs, int cmd)
414 switch (cmd) { 433 switch (cmd) {
415 case SNDRV_PCM_TRIGGER_START: 434 case SNDRV_PCM_TRIGGER_START:
416 435
417 snd_printdd("SNDRV_PCM_TRIGGER_START\n"); 436 dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_TRIGGER_START\n");
418 437
419 /* START_STREAM */ 438 /* START_STREAM */
420 if( mixart_set_stream_state(stream, 1) ) 439 if( mixart_set_stream_state(stream, 1) )
@@ -431,19 +450,19 @@ static int snd_mixart_trigger(struct snd_pcm_substream *subs, int cmd)
431 450
432 stream->status = MIXART_STREAM_STATUS_OPEN; 451 stream->status = MIXART_STREAM_STATUS_OPEN;
433 452
434 snd_printdd("SNDRV_PCM_TRIGGER_STOP\n"); 453 dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_TRIGGER_STOP\n");
435 454
436 break; 455 break;
437 456
438 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 457 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
439 /* TODO */ 458 /* TODO */
440 stream->status = MIXART_STREAM_STATUS_PAUSE; 459 stream->status = MIXART_STREAM_STATUS_PAUSE;
441 snd_printdd("SNDRV_PCM_PAUSE_PUSH\n"); 460 dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_PAUSE_PUSH\n");
442 break; 461 break;
443 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 462 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
444 /* TODO */ 463 /* TODO */
445 stream->status = MIXART_STREAM_STATUS_RUNNING; 464 stream->status = MIXART_STREAM_STATUS_RUNNING;
446 snd_printdd("SNDRV_PCM_PAUSE_RELEASE\n"); 465 dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_PAUSE_RELEASE\n");
447 break; 466 break;
448 default: 467 default:
449 return -EINVAL; 468 return -EINVAL;
@@ -456,7 +475,8 @@ static int mixart_sync_nonblock_events(struct mixart_mgr *mgr)
456 unsigned long timeout = jiffies + HZ; 475 unsigned long timeout = jiffies + HZ;
457 while (atomic_read(&mgr->msg_processed) > 0) { 476 while (atomic_read(&mgr->msg_processed) > 0) {
458 if (time_after(jiffies, timeout)) { 477 if (time_after(jiffies, timeout)) {
459 snd_printk(KERN_ERR "mixart: cannot process nonblock events!\n"); 478 dev_err(&mgr->pci->dev,
479 "mixart: cannot process nonblock events!\n");
460 return -EBUSY; 480 return -EBUSY;
461 } 481 }
462 schedule_timeout_uninterruptible(1); 482 schedule_timeout_uninterruptible(1);
@@ -474,7 +494,7 @@ static int snd_mixart_prepare(struct snd_pcm_substream *subs)
474 494
475 /* TODO de façon non bloquante, réappliquer les hw_params (rate, bits, codec) */ 495 /* TODO de façon non bloquante, réappliquer les hw_params (rate, bits, codec) */
476 496
477 snd_printdd("snd_mixart_prepare\n"); 497 dev_dbg(chip->card->dev, "snd_mixart_prepare\n");
478 498
479 mixart_sync_nonblock_events(chip->mgr); 499 mixart_sync_nonblock_events(chip->mgr);
480 500
@@ -542,11 +562,13 @@ static int mixart_set_format(struct mixart_stream *stream, snd_pcm_format_t form
542 stream_param.sample_size = 32; 562 stream_param.sample_size = 32;
543 break; 563 break;
544 default: 564 default:
545 snd_printk(KERN_ERR "error mixart_set_format() : unknown format\n"); 565 dev_err(chip->card->dev,
566 "error mixart_set_format() : unknown format\n");
546 return -EINVAL; 567 return -EINVAL;
547 } 568 }
548 569
549 snd_printdd("set SNDRV_PCM_FORMAT sample_type(%d) sample_size(%d) freq(%d) channels(%d)\n", 570 dev_dbg(chip->card->dev,
571 "set SNDRV_PCM_FORMAT sample_type(%d) sample_size(%d) freq(%d) channels(%d)\n",
550 stream_param.sample_type, stream_param.sample_size, stream_param.sampling_freq, stream->channels); 572 stream_param.sample_type, stream_param.sample_size, stream_param.sampling_freq, stream->channels);
551 573
552 /* TODO: what else to configure ? */ 574 /* TODO: what else to configure ? */
@@ -566,7 +588,9 @@ static int mixart_set_format(struct mixart_stream *stream, snd_pcm_format_t form
566 588
567 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp); 589 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp);
568 if((err < 0) || resp.error_code) { 590 if((err < 0) || resp.error_code) {
569 snd_printk(KERN_ERR "MSG_STREAM_SET_INPUT_STAGE_PARAM err=%x; resp=%x\n", err, resp.error_code); 591 dev_err(chip->card->dev,
592 "MSG_STREAM_SET_INPUT_STAGE_PARAM err=%x; resp=%x\n",
593 err, resp.error_code);
570 return -EINVAL; 594 return -EINVAL;
571 } 595 }
572 return 0; 596 return 0;
@@ -627,8 +651,9 @@ static int snd_mixart_hw_params(struct snd_pcm_substream *subs,
627 bufferinfo[i].available_length = subs->runtime->dma_bytes; 651 bufferinfo[i].available_length = subs->runtime->dma_bytes;
628 /* bufferinfo[i].buffer_id is already defined */ 652 /* bufferinfo[i].buffer_id is already defined */
629 653
630 snd_printdd("snd_mixart_hw_params(pcm %d) : dma_addr(%x) dma_bytes(%x) subs-number(%d)\n", i, 654 dev_dbg(chip->card->dev,
631 bufferinfo[i].buffer_address, 655 "snd_mixart_hw_params(pcm %d) : dma_addr(%x) dma_bytes(%x) subs-number(%d)\n",
656 i, bufferinfo[i].buffer_address,
632 bufferinfo[i].available_length, 657 bufferinfo[i].available_length,
633 subs->number); 658 subs->number);
634 } 659 }
@@ -714,14 +739,18 @@ static int snd_mixart_playback_open(struct snd_pcm_substream *subs)
714 pcm_number = MIXART_PCM_DIGITAL; 739 pcm_number = MIXART_PCM_DIGITAL;
715 runtime->hw = snd_mixart_digital_caps; 740 runtime->hw = snd_mixart_digital_caps;
716 } 741 }
717 snd_printdd("snd_mixart_playback_open C%d/P%d/Sub%d\n", chip->chip_idx, pcm_number, subs->number); 742 dev_dbg(chip->card->dev,
743 "snd_mixart_playback_open C%d/P%d/Sub%d\n",
744 chip->chip_idx, pcm_number, subs->number);
718 745
719 /* get stream info */ 746 /* get stream info */
720 stream = &(chip->playback_stream[pcm_number][subs->number]); 747 stream = &(chip->playback_stream[pcm_number][subs->number]);
721 748
722 if (stream->status != MIXART_STREAM_STATUS_FREE){ 749 if (stream->status != MIXART_STREAM_STATUS_FREE){
723 /* streams in use */ 750 /* streams in use */
724 snd_printk(KERN_ERR "snd_mixart_playback_open C%d/P%d/Sub%d in use\n", chip->chip_idx, pcm_number, subs->number); 751 dev_err(chip->card->dev,
752 "snd_mixart_playback_open C%d/P%d/Sub%d in use\n",
753 chip->chip_idx, pcm_number, subs->number);
725 err = -EBUSY; 754 err = -EBUSY;
726 goto _exit_open; 755 goto _exit_open;
727 } 756 }
@@ -737,7 +766,7 @@ static int snd_mixart_playback_open(struct snd_pcm_substream *subs)
737 /* start the pipe if necessary */ 766 /* start the pipe if necessary */
738 err = mixart_set_pipe_state(chip->mgr, pipe, 1); 767 err = mixart_set_pipe_state(chip->mgr, pipe, 1);
739 if( err < 0 ) { 768 if( err < 0 ) {
740 snd_printk(KERN_ERR "error starting pipe!\n"); 769 dev_err(chip->card->dev, "error starting pipe!\n");
741 snd_mixart_kill_ref_pipe(chip->mgr, pipe, 0); 770 snd_mixart_kill_ref_pipe(chip->mgr, pipe, 0);
742 err = -EINVAL; 771 err = -EINVAL;
743 goto _exit_open; 772 goto _exit_open;
@@ -792,14 +821,17 @@ static int snd_mixart_capture_open(struct snd_pcm_substream *subs)
792 821
793 runtime->hw.channels_min = 2; /* for instance, no mono */ 822 runtime->hw.channels_min = 2; /* for instance, no mono */
794 823
795 snd_printdd("snd_mixart_capture_open C%d/P%d/Sub%d\n", chip->chip_idx, pcm_number, subs->number); 824 dev_dbg(chip->card->dev, "snd_mixart_capture_open C%d/P%d/Sub%d\n",
825 chip->chip_idx, pcm_number, subs->number);
796 826
797 /* get stream info */ 827 /* get stream info */
798 stream = &(chip->capture_stream[pcm_number]); 828 stream = &(chip->capture_stream[pcm_number]);
799 829
800 if (stream->status != MIXART_STREAM_STATUS_FREE){ 830 if (stream->status != MIXART_STREAM_STATUS_FREE){
801 /* streams in use */ 831 /* streams in use */
802 snd_printk(KERN_ERR "snd_mixart_capture_open C%d/P%d/Sub%d in use\n", chip->chip_idx, pcm_number, subs->number); 832 dev_err(chip->card->dev,
833 "snd_mixart_capture_open C%d/P%d/Sub%d in use\n",
834 chip->chip_idx, pcm_number, subs->number);
803 err = -EBUSY; 835 err = -EBUSY;
804 goto _exit_open; 836 goto _exit_open;
805 } 837 }
@@ -815,7 +847,7 @@ static int snd_mixart_capture_open(struct snd_pcm_substream *subs)
815 /* start the pipe if necessary */ 847 /* start the pipe if necessary */
816 err = mixart_set_pipe_state(chip->mgr, pipe, 1); 848 err = mixart_set_pipe_state(chip->mgr, pipe, 1);
817 if( err < 0 ) { 849 if( err < 0 ) {
818 snd_printk(KERN_ERR "error starting pipe!\n"); 850 dev_err(chip->card->dev, "error starting pipe!\n");
819 snd_mixart_kill_ref_pipe(chip->mgr, pipe, 0); 851 snd_mixart_kill_ref_pipe(chip->mgr, pipe, 0);
820 err = -EINVAL; 852 err = -EINVAL;
821 goto _exit_open; 853 goto _exit_open;
@@ -855,7 +887,8 @@ static int snd_mixart_close(struct snd_pcm_substream *subs)
855 887
856 mutex_lock(&mgr->setup_mutex); 888 mutex_lock(&mgr->setup_mutex);
857 889
858 snd_printdd("snd_mixart_close C%d/P%d/Sub%d\n", chip->chip_idx, stream->pcm_number, subs->number); 890 dev_dbg(chip->card->dev, "snd_mixart_close C%d/P%d/Sub%d\n",
891 chip->chip_idx, stream->pcm_number, subs->number);
859 892
860 /* sample rate released */ 893 /* sample rate released */
861 if(--mgr->ref_count_rate == 0) { 894 if(--mgr->ref_count_rate == 0) {
@@ -865,7 +898,9 @@ static int snd_mixart_close(struct snd_pcm_substream *subs)
865 /* delete pipe */ 898 /* delete pipe */
866 if (snd_mixart_kill_ref_pipe(mgr, stream->pipe, 0 ) < 0) { 899 if (snd_mixart_kill_ref_pipe(mgr, stream->pipe, 0 ) < 0) {
867 900
868 snd_printk(KERN_ERR "error snd_mixart_kill_ref_pipe C%dP%d\n", chip->chip_idx, stream->pcm_number); 901 dev_err(chip->card->dev,
902 "error snd_mixart_kill_ref_pipe C%dP%d\n",
903 chip->chip_idx, stream->pcm_number);
869 } 904 }
870 905
871 stream->pipe = NULL; 906 stream->pipe = NULL;
@@ -940,7 +975,8 @@ static int snd_mixart_pcm_analog(struct snd_mixart *chip)
940 if ((err = snd_pcm_new(chip->card, name, MIXART_PCM_ANALOG, 975 if ((err = snd_pcm_new(chip->card, name, MIXART_PCM_ANALOG,
941 MIXART_PLAYBACK_STREAMS, 976 MIXART_PLAYBACK_STREAMS,
942 MIXART_CAPTURE_STREAMS, &pcm)) < 0) { 977 MIXART_CAPTURE_STREAMS, &pcm)) < 0) {
943 snd_printk(KERN_ERR "cannot create the analog pcm %d\n", chip->chip_idx); 978 dev_err(chip->card->dev,
979 "cannot create the analog pcm %d\n", chip->chip_idx);
944 return err; 980 return err;
945 } 981 }
946 982
@@ -971,7 +1007,8 @@ static int snd_mixart_pcm_digital(struct snd_mixart *chip)
971 if ((err = snd_pcm_new(chip->card, name, MIXART_PCM_DIGITAL, 1007 if ((err = snd_pcm_new(chip->card, name, MIXART_PCM_DIGITAL,
972 MIXART_PLAYBACK_STREAMS, 1008 MIXART_PLAYBACK_STREAMS,
973 MIXART_CAPTURE_STREAMS, &pcm)) < 0) { 1009 MIXART_CAPTURE_STREAMS, &pcm)) < 0) {
974 snd_printk(KERN_ERR "cannot create the digital pcm %d\n", chip->chip_idx); 1010 dev_err(chip->card->dev,
1011 "cannot create the digital pcm %d\n", chip->chip_idx);
975 return err; 1012 return err;
976 } 1013 }
977 1014
@@ -1014,7 +1051,7 @@ static int snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *card, int
1014 1051
1015 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1052 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1016 if (! chip) { 1053 if (! chip) {
1017 snd_printk(KERN_ERR "cannot allocate chip\n"); 1054 dev_err(card->dev, "cannot allocate chip\n");
1018 return -ENOMEM; 1055 return -ENOMEM;
1019 } 1056 }
1020 1057
@@ -1028,8 +1065,6 @@ static int snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *card, int
1028 } 1065 }
1029 1066
1030 mgr->chip[idx] = chip; 1067 mgr->chip[idx] = chip;
1031 snd_card_set_dev(card, &mgr->pci->dev);
1032
1033 return 0; 1068 return 0;
1034} 1069}
1035 1070
@@ -1073,7 +1108,7 @@ static int snd_mixart_free(struct mixart_mgr *mgr)
1073 /* reset board if some firmware was loaded */ 1108 /* reset board if some firmware was loaded */
1074 if(mgr->dsp_loaded) { 1109 if(mgr->dsp_loaded) {
1075 snd_mixart_reset_board(mgr); 1110 snd_mixart_reset_board(mgr);
1076 snd_printdd("reset miXart !\n"); 1111 dev_dbg(&mgr->pci->dev, "reset miXart !\n");
1077 } 1112 }
1078 1113
1079 /* release the i/o ports */ 1114 /* release the i/o ports */
@@ -1234,7 +1269,8 @@ static int snd_mixart_probe(struct pci_dev *pci,
1234 1269
1235 /* check if we can restrict PCI DMA transfers to 32 bits */ 1270 /* check if we can restrict PCI DMA transfers to 32 bits */
1236 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { 1271 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0) {
1237 snd_printk(KERN_ERR "architecture does not support 32bit PCI busmaster DMA\n"); 1272 dev_err(&pci->dev,
1273 "architecture does not support 32bit PCI busmaster DMA\n");
1238 pci_disable_device(pci); 1274 pci_disable_device(pci);
1239 return -ENXIO; 1275 return -ENXIO;
1240 } 1276 }
@@ -1260,7 +1296,7 @@ static int snd_mixart_probe(struct pci_dev *pci,
1260 mgr->mem[i].phys = pci_resource_start(pci, i); 1296 mgr->mem[i].phys = pci_resource_start(pci, i);
1261 mgr->mem[i].virt = pci_ioremap_bar(pci, i); 1297 mgr->mem[i].virt = pci_ioremap_bar(pci, i);
1262 if (!mgr->mem[i].virt) { 1298 if (!mgr->mem[i].virt) {
1263 printk(KERN_ERR "unable to remap resource 0x%lx\n", 1299 dev_err(&pci->dev, "unable to remap resource 0x%lx\n",
1264 mgr->mem[i].phys); 1300 mgr->mem[i].phys);
1265 snd_mixart_free(mgr); 1301 snd_mixart_free(mgr);
1266 return -EBUSY; 1302 return -EBUSY;
@@ -1269,7 +1305,7 @@ static int snd_mixart_probe(struct pci_dev *pci,
1269 1305
1270 if (request_irq(pci->irq, snd_mixart_interrupt, IRQF_SHARED, 1306 if (request_irq(pci->irq, snd_mixart_interrupt, IRQF_SHARED,
1271 KBUILD_MODNAME, mgr)) { 1307 KBUILD_MODNAME, mgr)) {
1272 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1308 dev_err(&pci->dev, "unable to grab IRQ %d\n", pci->irq);
1273 snd_mixart_free(mgr); 1309 snd_mixart_free(mgr);
1274 return -EBUSY; 1310 return -EBUSY;
1275 } 1311 }
@@ -1308,10 +1344,11 @@ static int snd_mixart_probe(struct pci_dev *pci,
1308 else 1344 else
1309 idx = index[dev] + i; 1345 idx = index[dev] + i;
1310 snprintf(tmpid, sizeof(tmpid), "%s-%d", id[dev] ? id[dev] : "MIXART", i); 1346 snprintf(tmpid, sizeof(tmpid), "%s-%d", id[dev] ? id[dev] : "MIXART", i);
1311 err = snd_card_create(idx, tmpid, THIS_MODULE, 0, &card); 1347 err = snd_card_new(&pci->dev, idx, tmpid, THIS_MODULE,
1348 0, &card);
1312 1349
1313 if (err < 0) { 1350 if (err < 0) {
1314 snd_printk(KERN_ERR "cannot allocate the card %d\n", i); 1351 dev_err(&pci->dev, "cannot allocate the card %d\n", i);
1315 snd_mixart_free(mgr); 1352 snd_mixart_free(mgr);
1316 return err; 1353 return err;
1317 } 1354 }
diff --git a/sound/pci/mixart/mixart_core.c b/sound/pci/mixart/mixart_core.c
index 3df0f530f67c..71f4bdcc4055 100644
--- a/sound/pci/mixart/mixart_core.c
+++ b/sound/pci/mixart/mixart_core.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/mutex.h> 24#include <linux/mutex.h>
25#include <linux/pci.h>
25 26
26#include <asm/io.h> 27#include <asm/io.h>
27#include <sound/core.h> 28#include <sound/core.h>
@@ -94,7 +95,8 @@ static int get_msg(struct mixart_mgr *mgr, struct mixart_msg *resp,
94 95
95 if( (size < MSG_DESCRIPTOR_SIZE) || (resp->size < (size - MSG_DESCRIPTOR_SIZE))) { 96 if( (size < MSG_DESCRIPTOR_SIZE) || (resp->size < (size - MSG_DESCRIPTOR_SIZE))) {
96 err = -EINVAL; 97 err = -EINVAL;
97 snd_printk(KERN_ERR "problem with response size = %d\n", size); 98 dev_err(&mgr->pci->dev,
99 "problem with response size = %d\n", size);
98 goto _clean_exit; 100 goto _clean_exit;
99 } 101 }
100 size -= MSG_DESCRIPTOR_SIZE; 102 size -= MSG_DESCRIPTOR_SIZE;
@@ -161,7 +163,7 @@ static int send_msg( struct mixart_mgr *mgr,
161 headptr = readl_be(MIXART_MEM(mgr, MSG_INBOUND_FREE_HEAD)); 163 headptr = readl_be(MIXART_MEM(mgr, MSG_INBOUND_FREE_HEAD));
162 164
163 if (tailptr == headptr) { 165 if (tailptr == headptr) {
164 snd_printk(KERN_ERR "error: no message frame available\n"); 166 dev_err(&mgr->pci->dev, "error: no message frame available\n");
165 return -EBUSY; 167 return -EBUSY;
166 } 168 }
167 169
@@ -265,7 +267,8 @@ int snd_mixart_send_msg(struct mixart_mgr *mgr, struct mixart_msg *request, int
265 if (! timeout) { 267 if (! timeout) {
266 /* error - no ack */ 268 /* error - no ack */
267 mutex_unlock(&mgr->msg_mutex); 269 mutex_unlock(&mgr->msg_mutex);
268 snd_printk(KERN_ERR "error: no response on msg %x\n", msg_frame); 270 dev_err(&mgr->pci->dev,
271 "error: no response on msg %x\n", msg_frame);
269 return -EIO; 272 return -EIO;
270 } 273 }
271 274
@@ -278,7 +281,7 @@ int snd_mixart_send_msg(struct mixart_mgr *mgr, struct mixart_msg *request, int
278 err = get_msg(mgr, &resp, msg_frame); 281 err = get_msg(mgr, &resp, msg_frame);
279 282
280 if( request->message_id != resp.message_id ) 283 if( request->message_id != resp.message_id )
281 snd_printk(KERN_ERR "RESPONSE ERROR!\n"); 284 dev_err(&mgr->pci->dev, "RESPONSE ERROR!\n");
282 285
283 mutex_unlock(&mgr->msg_mutex); 286 mutex_unlock(&mgr->msg_mutex);
284 return err; 287 return err;
@@ -321,7 +324,8 @@ int snd_mixart_send_msg_wait_notif(struct mixart_mgr *mgr,
321 if (! timeout) { 324 if (! timeout) {
322 /* error - no ack */ 325 /* error - no ack */
323 mutex_unlock(&mgr->msg_mutex); 326 mutex_unlock(&mgr->msg_mutex);
324 snd_printk(KERN_ERR "error: notification %x not received\n", notif_event); 327 dev_err(&mgr->pci->dev,
328 "error: notification %x not received\n", notif_event);
325 return -EIO; 329 return -EIO;
326 } 330 }
327 331
@@ -378,7 +382,9 @@ void snd_mixart_msg_tasklet(unsigned long arg)
378 resp.size = sizeof(mixart_msg_data); 382 resp.size = sizeof(mixart_msg_data);
379 err = get_msg(mgr, &resp, addr); 383 err = get_msg(mgr, &resp, addr);
380 if( err < 0 ) { 384 if( err < 0 ) {
381 snd_printk(KERN_ERR "tasklet: error(%d) reading mf %x\n", err, msg); 385 dev_err(&mgr->pci->dev,
386 "tasklet: error(%d) reading mf %x\n",
387 err, msg);
382 break; 388 break;
383 } 389 }
384 390
@@ -388,10 +394,13 @@ void snd_mixart_msg_tasklet(unsigned long arg)
388 case MSG_STREAM_STOP_INPUT_STAGE_PACKET: 394 case MSG_STREAM_STOP_INPUT_STAGE_PACKET:
389 case MSG_STREAM_STOP_OUTPUT_STAGE_PACKET: 395 case MSG_STREAM_STOP_OUTPUT_STAGE_PACKET:
390 if(mixart_msg_data[0]) 396 if(mixart_msg_data[0])
391 snd_printk(KERN_ERR "tasklet : error MSG_STREAM_ST***_***PUT_STAGE_PACKET status=%x\n", mixart_msg_data[0]); 397 dev_err(&mgr->pci->dev,
398 "tasklet : error MSG_STREAM_ST***_***PUT_STAGE_PACKET status=%x\n",
399 mixart_msg_data[0]);
392 break; 400 break;
393 default: 401 default:
394 snd_printdd("tasklet received mf(%x) : msg_id(%x) uid(%x, %x) size(%zd)\n", 402 dev_dbg(&mgr->pci->dev,
403 "tasklet received mf(%x) : msg_id(%x) uid(%x, %x) size(%zd)\n",
395 msg, resp.message_id, resp.uid.object_id, resp.uid.desc, resp.size); 404 msg, resp.message_id, resp.uid.object_id, resp.uid.desc, resp.size);
396 break; 405 break;
397 } 406 }
@@ -401,7 +410,9 @@ void snd_mixart_msg_tasklet(unsigned long arg)
401 case MSG_TYPE_COMMAND: 410 case MSG_TYPE_COMMAND:
402 /* get_msg() necessary */ 411 /* get_msg() necessary */
403 default: 412 default:
404 snd_printk(KERN_ERR "tasklet doesn't know what to do with message %x\n", msg); 413 dev_err(&mgr->pci->dev,
414 "tasklet doesn't know what to do with message %x\n",
415 msg);
405 } /* switch type */ 416 } /* switch type */
406 417
407 /* decrement counter */ 418 /* decrement counter */
@@ -451,7 +462,9 @@ irqreturn_t snd_mixart_interrupt(int irq, void *dev_id)
451 resp.size = sizeof(mixart_msg_data); 462 resp.size = sizeof(mixart_msg_data);
452 err = get_msg(mgr, &resp, msg & ~MSG_TYPE_MASK); 463 err = get_msg(mgr, &resp, msg & ~MSG_TYPE_MASK);
453 if( err < 0 ) { 464 if( err < 0 ) {
454 snd_printk(KERN_ERR "interrupt: error(%d) reading mf %x\n", err, msg); 465 dev_err(&mgr->pci->dev,
466 "interrupt: error(%d) reading mf %x\n",
467 err, msg);
455 break; 468 break;
456 } 469 }
457 470
@@ -472,7 +485,8 @@ irqreturn_t snd_mixart_interrupt(int irq, void *dev_id)
472 struct mixart_stream *stream; 485 struct mixart_stream *stream;
473 486
474 if ((chip_number >= mgr->num_cards) || (pcm_number >= MIXART_PCM_TOTAL) || (sub_number >= MIXART_PLAYBACK_STREAMS)) { 487 if ((chip_number >= mgr->num_cards) || (pcm_number >= MIXART_PCM_TOTAL) || (sub_number >= MIXART_PLAYBACK_STREAMS)) {
475 snd_printk(KERN_ERR "error MSG_SERVICES_TIMER_NOTIFY buffer_id (%x) pos(%d)\n", 488 dev_err(&mgr->pci->dev,
489 "error MSG_SERVICES_TIMER_NOTIFY buffer_id (%x) pos(%d)\n",
476 buffer_id, notify->streams[i].sample_pos_low_part); 490 buffer_id, notify->streams[i].sample_pos_low_part);
477 break; 491 break;
478 } 492 }
@@ -524,18 +538,22 @@ irqreturn_t snd_mixart_interrupt(int irq, void *dev_id)
524 } 538 }
525#endif 539#endif
526 ((char*)mixart_msg_data)[resp.size - 1] = 0; 540 ((char*)mixart_msg_data)[resp.size - 1] = 0;
527 snd_printdd("MIXART TRACE : %s\n", (char*)mixart_msg_data); 541 dev_dbg(&mgr->pci->dev,
542 "MIXART TRACE : %s\n",
543 (char *)mixart_msg_data);
528 } 544 }
529 break; 545 break;
530 } 546 }
531 547
532 snd_printdd("command %x not handled\n", resp.message_id); 548 dev_dbg(&mgr->pci->dev, "command %x not handled\n",
549 resp.message_id);
533 break; 550 break;
534 551
535 case MSG_TYPE_NOTIFY: 552 case MSG_TYPE_NOTIFY:
536 if(msg & MSG_CANCEL_NOTIFY_MASK) { 553 if(msg & MSG_CANCEL_NOTIFY_MASK) {
537 msg &= ~MSG_CANCEL_NOTIFY_MASK; 554 msg &= ~MSG_CANCEL_NOTIFY_MASK;
538 snd_printk(KERN_ERR "canceled notification %x !\n", msg); 555 dev_err(&mgr->pci->dev,
556 "canceled notification %x !\n", msg);
539 } 557 }
540 /* no break, continue ! */ 558 /* no break, continue ! */
541 case MSG_TYPE_ANSWER: 559 case MSG_TYPE_ANSWER:
@@ -556,7 +574,8 @@ irqreturn_t snd_mixart_interrupt(int irq, void *dev_id)
556 break; 574 break;
557 case MSG_TYPE_REQUEST: 575 case MSG_TYPE_REQUEST:
558 default: 576 default:
559 snd_printdd("interrupt received request %x\n", msg); 577 dev_dbg(&mgr->pci->dev,
578 "interrupt received request %x\n", msg);
560 /* TODO : are there things to do here ? */ 579 /* TODO : are there things to do here ? */
561 break; 580 break;
562 } /* switch on msg type */ 581 } /* switch on msg type */
diff --git a/sound/pci/mixart/mixart_hwdep.c b/sound/pci/mixart/mixart_hwdep.c
index ece1f831c16a..581e1e74863c 100644
--- a/sound/pci/mixart/mixart_hwdep.c
+++ b/sound/pci/mixart/mixart_hwdep.c
@@ -165,7 +165,8 @@ static int mixart_enum_connectors(struct mixart_mgr *mgr)
165 165
166 err = snd_mixart_send_msg(mgr, &request, sizeof(*connector), connector); 166 err = snd_mixart_send_msg(mgr, &request, sizeof(*connector), connector);
167 if((err < 0) || (connector->error_code) || (connector->uid_count > MIXART_MAX_PHYS_CONNECTORS)) { 167 if((err < 0) || (connector->error_code) || (connector->uid_count > MIXART_MAX_PHYS_CONNECTORS)) {
168 snd_printk(KERN_ERR "error MSG_SYSTEM_ENUM_PLAY_CONNECTOR\n"); 168 dev_err(&mgr->pci->dev,
169 "error MSG_SYSTEM_ENUM_PLAY_CONNECTOR\n");
169 err = -EINVAL; 170 err = -EINVAL;
170 goto __error; 171 goto __error;
171 } 172 }
@@ -184,7 +185,7 @@ static int mixart_enum_connectors(struct mixart_mgr *mgr)
184 pipe->uid_left_connector = connector->uid[k]; /* even */ 185 pipe->uid_left_connector = connector->uid[k]; /* even */
185 } 186 }
186 187
187 /* snd_printk(KERN_DEBUG "playback connector[%d].object_id = %x\n", k, connector->uid[k].object_id); */ 188 /* dev_dbg(&mgr->pci->dev, "playback connector[%d].object_id = %x\n", k, connector->uid[k].object_id); */
188 189
189 /* TODO: really need send_msg MSG_CONNECTOR_GET_AUDIO_INFO for each connector ? perhaps for analog level caps ? */ 190 /* TODO: really need send_msg MSG_CONNECTOR_GET_AUDIO_INFO for each connector ? perhaps for analog level caps ? */
190 request.message_id = MSG_CONNECTOR_GET_AUDIO_INFO; 191 request.message_id = MSG_CONNECTOR_GET_AUDIO_INFO;
@@ -194,10 +195,11 @@ static int mixart_enum_connectors(struct mixart_mgr *mgr)
194 195
195 err = snd_mixart_send_msg(mgr, &request, sizeof(*audio_info), audio_info); 196 err = snd_mixart_send_msg(mgr, &request, sizeof(*audio_info), audio_info);
196 if( err < 0 ) { 197 if( err < 0 ) {
197 snd_printk(KERN_ERR "error MSG_CONNECTOR_GET_AUDIO_INFO\n"); 198 dev_err(&mgr->pci->dev,
199 "error MSG_CONNECTOR_GET_AUDIO_INFO\n");
198 goto __error; 200 goto __error;
199 } 201 }
200 /*snd_printk(KERN_DEBUG "play analog_info.analog_level_present = %x\n", audio_info->info.analog_info.analog_level_present);*/ 202 /*dev_dbg(&mgr->pci->dev, "play analog_info.analog_level_present = %x\n", audio_info->info.analog_info.analog_level_present);*/
201 } 203 }
202 204
203 request.message_id = MSG_SYSTEM_ENUM_RECORD_CONNECTOR; 205 request.message_id = MSG_SYSTEM_ENUM_RECORD_CONNECTOR;
@@ -207,7 +209,8 @@ static int mixart_enum_connectors(struct mixart_mgr *mgr)
207 209
208 err = snd_mixart_send_msg(mgr, &request, sizeof(*connector), connector); 210 err = snd_mixart_send_msg(mgr, &request, sizeof(*connector), connector);
209 if((err < 0) || (connector->error_code) || (connector->uid_count > MIXART_MAX_PHYS_CONNECTORS)) { 211 if((err < 0) || (connector->error_code) || (connector->uid_count > MIXART_MAX_PHYS_CONNECTORS)) {
210 snd_printk(KERN_ERR "error MSG_SYSTEM_ENUM_RECORD_CONNECTOR\n"); 212 dev_err(&mgr->pci->dev,
213 "error MSG_SYSTEM_ENUM_RECORD_CONNECTOR\n");
211 err = -EINVAL; 214 err = -EINVAL;
212 goto __error; 215 goto __error;
213 } 216 }
@@ -226,7 +229,7 @@ static int mixart_enum_connectors(struct mixart_mgr *mgr)
226 pipe->uid_left_connector = connector->uid[k]; /* even */ 229 pipe->uid_left_connector = connector->uid[k]; /* even */
227 } 230 }
228 231
229 /* snd_printk(KERN_DEBUG "capture connector[%d].object_id = %x\n", k, connector->uid[k].object_id); */ 232 /* dev_dbg(&mgr->pci->dev, "capture connector[%d].object_id = %x\n", k, connector->uid[k].object_id); */
230 233
231 /* TODO: really need send_msg MSG_CONNECTOR_GET_AUDIO_INFO for each connector ? perhaps for analog level caps ? */ 234 /* TODO: really need send_msg MSG_CONNECTOR_GET_AUDIO_INFO for each connector ? perhaps for analog level caps ? */
232 request.message_id = MSG_CONNECTOR_GET_AUDIO_INFO; 235 request.message_id = MSG_CONNECTOR_GET_AUDIO_INFO;
@@ -236,10 +239,11 @@ static int mixart_enum_connectors(struct mixart_mgr *mgr)
236 239
237 err = snd_mixart_send_msg(mgr, &request, sizeof(*audio_info), audio_info); 240 err = snd_mixart_send_msg(mgr, &request, sizeof(*audio_info), audio_info);
238 if( err < 0 ) { 241 if( err < 0 ) {
239 snd_printk(KERN_ERR "error MSG_CONNECTOR_GET_AUDIO_INFO\n"); 242 dev_err(&mgr->pci->dev,
243 "error MSG_CONNECTOR_GET_AUDIO_INFO\n");
240 goto __error; 244 goto __error;
241 } 245 }
242 /*snd_printk(KERN_DEBUG "rec analog_info.analog_level_present = %x\n", audio_info->info.analog_info.analog_level_present);*/ 246 /*dev_dbg(&mgr->pci->dev, "rec analog_info.analog_level_present = %x\n", audio_info->info.analog_info.analog_level_present);*/
243 } 247 }
244 err = 0; 248 err = 0;
245 249
@@ -272,7 +276,9 @@ static int mixart_enum_physio(struct mixart_mgr *mgr)
272 err = snd_mixart_send_msg(mgr, &request, sizeof(console_mgr), &console_mgr); 276 err = snd_mixart_send_msg(mgr, &request, sizeof(console_mgr), &console_mgr);
273 277
274 if( (err < 0) || (console_mgr.error_code != 0) ) { 278 if( (err < 0) || (console_mgr.error_code != 0) ) {
275 snd_printk(KERN_DEBUG "error MSG_CONSOLE_GET_CLOCK_UID : err=%x\n", console_mgr.error_code); 279 dev_dbg(&mgr->pci->dev,
280 "error MSG_CONSOLE_GET_CLOCK_UID : err=%x\n",
281 console_mgr.error_code);
276 return -EINVAL; 282 return -EINVAL;
277 } 283 }
278 284
@@ -286,7 +292,9 @@ static int mixart_enum_physio(struct mixart_mgr *mgr)
286 292
287 err = snd_mixart_send_msg(mgr, &request, sizeof(phys_io), &phys_io); 293 err = snd_mixart_send_msg(mgr, &request, sizeof(phys_io), &phys_io);
288 if( (err < 0) || ( phys_io.error_code != 0 ) ) { 294 if( (err < 0) || ( phys_io.error_code != 0 ) ) {
289 snd_printk(KERN_ERR "error MSG_SYSTEM_ENUM_PHYSICAL_IO err(%x) error_code(%x)\n", err, phys_io.error_code ); 295 dev_err(&mgr->pci->dev,
296 "error MSG_SYSTEM_ENUM_PHYSICAL_IO err(%x) error_code(%x)\n",
297 err, phys_io.error_code);
290 return -EINVAL; 298 return -EINVAL;
291 } 299 }
292 300
@@ -322,7 +330,7 @@ static int mixart_first_init(struct mixart_mgr *mgr)
322 /* this command has no data. response is a 32 bit status */ 330 /* this command has no data. response is a 32 bit status */
323 err = snd_mixart_send_msg(mgr, &request, sizeof(k), &k); 331 err = snd_mixart_send_msg(mgr, &request, sizeof(k), &k);
324 if( (err < 0) || (k != 0) ) { 332 if( (err < 0) || (k != 0) ) {
325 snd_printk(KERN_ERR "error MSG_SYSTEM_SEND_SYNCHRO_CMD\n"); 333 dev_err(&mgr->pci->dev, "error MSG_SYSTEM_SEND_SYNCHRO_CMD\n");
326 return err == 0 ? -EINVAL : err; 334 return err == 0 ? -EINVAL : err;
327 } 335 }
328 336
@@ -348,7 +356,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
348 356
349 /* motherboard xilinx status 5 will say that the board is performing a reset */ 357 /* motherboard xilinx status 5 will say that the board is performing a reset */
350 if (status_xilinx == 5) { 358 if (status_xilinx == 5) {
351 snd_printk(KERN_ERR "miXart is resetting !\n"); 359 dev_err(&mgr->pci->dev, "miXart is resetting !\n");
352 return -EAGAIN; /* try again later */ 360 return -EAGAIN; /* try again later */
353 } 361 }
354 362
@@ -357,12 +365,13 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
357 365
358 /* xilinx already loaded ? */ 366 /* xilinx already loaded ? */
359 if (status_xilinx == 4) { 367 if (status_xilinx == 4) {
360 snd_printk(KERN_DEBUG "xilinx is already loaded !\n"); 368 dev_dbg(&mgr->pci->dev, "xilinx is already loaded !\n");
361 return 0; 369 return 0;
362 } 370 }
363 /* the status should be 0 == "idle" */ 371 /* the status should be 0 == "idle" */
364 if (status_xilinx != 0) { 372 if (status_xilinx != 0) {
365 snd_printk(KERN_ERR "xilinx load error ! status = %d\n", 373 dev_err(&mgr->pci->dev,
374 "xilinx load error ! status = %d\n",
366 status_xilinx); 375 status_xilinx);
367 return -EIO; /* modprob -r may help ? */ 376 return -EIO; /* modprob -r may help ? */
368 } 377 }
@@ -393,13 +402,14 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
393 case MIXART_MOTHERBOARD_ELF_INDEX: 402 case MIXART_MOTHERBOARD_ELF_INDEX:
394 403
395 if (status_elf == 4) { 404 if (status_elf == 4) {
396 snd_printk(KERN_DEBUG "elf file already loaded !\n"); 405 dev_dbg(&mgr->pci->dev, "elf file already loaded !\n");
397 return 0; 406 return 0;
398 } 407 }
399 408
400 /* the status should be 0 == "idle" */ 409 /* the status should be 0 == "idle" */
401 if (status_elf != 0) { 410 if (status_elf != 0) {
402 snd_printk(KERN_ERR "elf load error ! status = %d\n", 411 dev_err(&mgr->pci->dev,
412 "elf load error ! status = %d\n",
403 status_elf); 413 status_elf);
404 return -EIO; /* modprob -r may help ? */ 414 return -EIO; /* modprob -r may help ? */
405 } 415 }
@@ -407,7 +417,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
407 /* wait for xilinx status == 4 */ 417 /* wait for xilinx status == 4 */
408 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET, 1, 4, 500); /* 5sec */ 418 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET, 1, 4, 500); /* 5sec */
409 if (err < 0) { 419 if (err < 0) {
410 snd_printk(KERN_ERR "xilinx was not loaded or " 420 dev_err(&mgr->pci->dev, "xilinx was not loaded or "
411 "could not be started\n"); 421 "could not be started\n");
412 return err; 422 return err;
413 } 423 }
@@ -429,7 +439,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
429 /* wait for elf status == 4 */ 439 /* wait for elf status == 4 */
430 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET, 1, 4, 300); /* 3sec */ 440 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET, 1, 4, 300); /* 3sec */
431 if (err < 0) { 441 if (err < 0) {
432 snd_printk(KERN_ERR "elf could not be started\n"); 442 dev_err(&mgr->pci->dev, "elf could not be started\n");
433 return err; 443 return err;
434 } 444 }
435 445
@@ -443,7 +453,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
443 453
444 /* elf and xilinx should be loaded */ 454 /* elf and xilinx should be loaded */
445 if (status_elf != 4 || status_xilinx != 4) { 455 if (status_elf != 4 || status_xilinx != 4) {
446 printk(KERN_ERR "xilinx or elf not " 456 dev_err(&mgr->pci->dev, "xilinx or elf not "
447 "successfully loaded\n"); 457 "successfully loaded\n");
448 return -EIO; /* modprob -r may help ? */ 458 return -EIO; /* modprob -r may help ? */
449 } 459 }
@@ -451,7 +461,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
451 /* wait for daughter detection != 0 */ 461 /* wait for daughter detection != 0 */
452 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DBRD_PRESENCE_OFFSET, 0, 0, 30); /* 300msec */ 462 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DBRD_PRESENCE_OFFSET, 0, 0, 30); /* 300msec */
453 if (err < 0) { 463 if (err < 0) {
454 snd_printk(KERN_ERR "error starting elf file\n"); 464 dev_err(&mgr->pci->dev, "error starting elf file\n");
455 return err; 465 return err;
456 } 466 }
457 467
@@ -467,7 +477,8 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
467 477
468 /* daughter should be idle */ 478 /* daughter should be idle */
469 if (status_daught != 0) { 479 if (status_daught != 0) {
470 printk(KERN_ERR "daughter load error ! status = %d\n", 480 dev_err(&mgr->pci->dev,
481 "daughter load error ! status = %d\n",
471 status_daught); 482 status_daught);
472 return -EIO; /* modprob -r may help ? */ 483 return -EIO; /* modprob -r may help ? */
473 } 484 }
@@ -487,7 +498,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
487 /* wait for status == 2 */ 498 /* wait for status == 2 */
488 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 2, 30); /* 300msec */ 499 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 2, 30); /* 300msec */
489 if (err < 0) { 500 if (err < 0) {
490 snd_printk(KERN_ERR "daughter board load error\n"); 501 dev_err(&mgr->pci->dev, "daughter board load error\n");
491 return err; 502 return err;
492 } 503 }
493 504
@@ -509,7 +520,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
509 /* wait for daughter status == 3 */ 520 /* wait for daughter status == 3 */
510 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 3, 300); /* 3sec */ 521 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 3, 300); /* 3sec */
511 if (err < 0) { 522 if (err < 0) {
512 snd_printk(KERN_ERR 523 dev_err(&mgr->pci->dev,
513 "daughter board could not be initialised\n"); 524 "daughter board could not be initialised\n");
514 return err; 525 return err;
515 } 526 }
@@ -520,7 +531,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
520 /* first communication with embedded */ 531 /* first communication with embedded */
521 err = mixart_first_init(mgr); 532 err = mixart_first_init(mgr);
522 if (err < 0) { 533 if (err < 0) {
523 snd_printk(KERN_ERR "miXart could not be set up\n"); 534 dev_err(&mgr->pci->dev, "miXart could not be set up\n");
524 return err; 535 return err;
525 } 536 }
526 537
@@ -540,7 +551,8 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
540 return err; 551 return err;
541 } 552 }
542 553
543 snd_printdd("miXart firmware downloaded and successfully set up\n"); 554 dev_dbg(&mgr->pci->dev,
555 "miXart firmware downloaded and successfully set up\n");
544 556
545 return 0; 557 return 0;
546} 558}
@@ -559,7 +571,8 @@ int snd_mixart_setup_firmware(struct mixart_mgr *mgr)
559 for (i = 0; i < 3; i++) { 571 for (i = 0; i < 3; i++) {
560 sprintf(path, "mixart/%s", fw_files[i]); 572 sprintf(path, "mixart/%s", fw_files[i]);
561 if (request_firmware(&fw_entry, path, &mgr->pci->dev)) { 573 if (request_firmware(&fw_entry, path, &mgr->pci->dev)) {
562 snd_printk(KERN_ERR "miXart: can't load firmware %s\n", path); 574 dev_err(&mgr->pci->dev,
575 "miXart: can't load firmware %s\n", path);
563 return -ENOENT; 576 return -ENOENT;
564 } 577 }
565 /* fake hwdep dsp record */ 578 /* fake hwdep dsp record */
diff --git a/sound/pci/mixart/mixart_mixer.c b/sound/pci/mixart/mixart_mixer.c
index 3ba6174c3df1..24a1955b8c29 100644
--- a/sound/pci/mixart/mixart_mixer.c
+++ b/sound/pci/mixart/mixart_mixer.c
@@ -329,7 +329,9 @@ static int mixart_update_analog_audio_level(struct snd_mixart* chip, int is_capt
329 329
330 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp); 330 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp);
331 if((err<0) || (resp.error_code)) { 331 if((err<0) || (resp.error_code)) {
332 snd_printk(KERN_DEBUG "error MSG_PHYSICALIO_SET_LEVEL card(%d) is_capture(%d) error_code(%x)\n", chip->chip_idx, is_capture, resp.error_code); 332 dev_dbg(chip->card->dev,
333 "error MSG_PHYSICALIO_SET_LEVEL card(%d) is_capture(%d) error_code(%x)\n",
334 chip->chip_idx, is_capture, resp.error_code);
333 return -EINVAL; 335 return -EINVAL;
334 } 336 }
335 return 0; 337 return 0;
@@ -762,7 +764,9 @@ int mixart_update_playback_stream_level(struct snd_mixart* chip, int is_aes, int
762 764
763 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(status), &status); 765 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(status), &status);
764 if((err<0) || status) { 766 if((err<0) || status) {
765 snd_printk(KERN_DEBUG "error MSG_STREAM_SET_OUT_STREAM_LEVEL card(%d) status(%x)\n", chip->chip_idx, status); 767 dev_dbg(chip->card->dev,
768 "error MSG_STREAM_SET_OUT_STREAM_LEVEL card(%d) status(%x)\n",
769 chip->chip_idx, status);
766 return -EINVAL; 770 return -EINVAL;
767 } 771 }
768 return 0; 772 return 0;
@@ -805,7 +809,9 @@ int mixart_update_capture_stream_level(struct snd_mixart* chip, int is_aes)
805 809
806 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(status), &status); 810 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(status), &status);
807 if((err<0) || status) { 811 if((err<0) || status) {
808 snd_printk(KERN_DEBUG "error MSG_STREAM_SET_IN_AUDIO_LEVEL card(%d) status(%x)\n", chip->chip_idx, status); 812 dev_dbg(chip->card->dev,
813 "error MSG_STREAM_SET_IN_AUDIO_LEVEL card(%d) status(%x)\n",
814 chip->chip_idx, status);
809 return -EINVAL; 815 return -EINVAL;
810 } 816 }
811 return 0; 817 return 0;
@@ -977,7 +983,9 @@ static int mixart_update_monitoring(struct snd_mixart* chip, int channel)
977 983
978 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp); 984 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp);
979 if((err<0) || resp) { 985 if((err<0) || resp) {
980 snd_printk(KERN_DEBUG "error MSG_CONNECTOR_SET_OUT_AUDIO_LEVEL card(%d) resp(%x)\n", chip->chip_idx, resp); 986 dev_dbg(chip->card->dev,
987 "error MSG_CONNECTOR_SET_OUT_AUDIO_LEVEL card(%d) resp(%x)\n",
988 chip->chip_idx, resp);
981 return -EINVAL; 989 return -EINVAL;
982 } 990 }
983 return 0; 991 return 0;
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index fe79fff4c6dc..ddc60215cc10 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -318,7 +318,8 @@ snd_nm256_write_buffer(struct nm256 *chip, void *src, int offset, int size)
318 offset -= chip->buffer_start; 318 offset -= chip->buffer_start;
319#ifdef CONFIG_SND_DEBUG 319#ifdef CONFIG_SND_DEBUG
320 if (offset < 0 || offset >= chip->buffer_size) { 320 if (offset < 0 || offset >= chip->buffer_size) {
321 snd_printk(KERN_ERR "write_buffer invalid offset = %d size = %d\n", 321 dev_err(chip->card->dev,
322 "write_buffer invalid offset = %d size = %d\n",
322 offset, size); 323 offset, size);
323 return; 324 return;
324 } 325 }
@@ -366,7 +367,8 @@ snd_nm256_load_coefficient(struct nm256 *chip, int stream, int number)
366 NM_RECORD_REG_OFFSET : NM_PLAYBACK_REG_OFFSET); 367 NM_RECORD_REG_OFFSET : NM_PLAYBACK_REG_OFFSET);
367 368
368 if (snd_nm256_readb(chip, poffset) & 1) { 369 if (snd_nm256_readb(chip, poffset) & 1) {
369 snd_printd("NM256: Engine was enabled while loading coefficients!\n"); 370 dev_dbg(chip->card->dev,
371 "NM256: Engine was enabled while loading coefficients!\n");
370 return; 372 return;
371 } 373 }
372 374
@@ -466,7 +468,8 @@ static int snd_nm256_acquire_irq(struct nm256 *chip)
466 if (chip->irq < 0) { 468 if (chip->irq < 0) {
467 if (request_irq(chip->pci->irq, chip->interrupt, IRQF_SHARED, 469 if (request_irq(chip->pci->irq, chip->interrupt, IRQF_SHARED,
468 KBUILD_MODNAME, chip)) { 470 KBUILD_MODNAME, chip)) {
469 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->pci->irq); 471 dev_err(chip->card->dev,
472 "unable to grab IRQ %d\n", chip->pci->irq);
470 mutex_unlock(&chip->irq_mutex); 473 mutex_unlock(&chip->irq_mutex);
471 return -EBUSY; 474 return -EBUSY;
472 } 475 }
@@ -1039,7 +1042,7 @@ snd_nm256_interrupt(int irq, void *dev_id)
1039 if (status & NM_MISC_INT_1) { 1042 if (status & NM_MISC_INT_1) {
1040 status &= ~NM_MISC_INT_1; 1043 status &= ~NM_MISC_INT_1;
1041 NM_ACK_INT(chip, NM_MISC_INT_1); 1044 NM_ACK_INT(chip, NM_MISC_INT_1);
1042 snd_printd("NM256: Got misc interrupt #1\n"); 1045 dev_dbg(chip->card->dev, "NM256: Got misc interrupt #1\n");
1043 snd_nm256_writew(chip, NM_INT_REG, 0x8000); 1046 snd_nm256_writew(chip, NM_INT_REG, 0x8000);
1044 cbyte = snd_nm256_readb(chip, 0x400); 1047 cbyte = snd_nm256_readb(chip, 0x400);
1045 snd_nm256_writeb(chip, 0x400, cbyte | 2); 1048 snd_nm256_writeb(chip, 0x400, cbyte | 2);
@@ -1048,14 +1051,15 @@ snd_nm256_interrupt(int irq, void *dev_id)
1048 if (status & NM_MISC_INT_2) { 1051 if (status & NM_MISC_INT_2) {
1049 status &= ~NM_MISC_INT_2; 1052 status &= ~NM_MISC_INT_2;
1050 NM_ACK_INT(chip, NM_MISC_INT_2); 1053 NM_ACK_INT(chip, NM_MISC_INT_2);
1051 snd_printd("NM256: Got misc interrupt #2\n"); 1054 dev_dbg(chip->card->dev, "NM256: Got misc interrupt #2\n");
1052 cbyte = snd_nm256_readb(chip, 0x400); 1055 cbyte = snd_nm256_readb(chip, 0x400);
1053 snd_nm256_writeb(chip, 0x400, cbyte & ~2); 1056 snd_nm256_writeb(chip, 0x400, cbyte & ~2);
1054 } 1057 }
1055 1058
1056 /* Unknown interrupt. */ 1059 /* Unknown interrupt. */
1057 if (status) { 1060 if (status) {
1058 snd_printd("NM256: Fire in the hole! Unknown status 0x%x\n", 1061 dev_dbg(chip->card->dev,
1062 "NM256: Fire in the hole! Unknown status 0x%x\n",
1059 status); 1063 status);
1060 /* Pray. */ 1064 /* Pray. */
1061 NM_ACK_INT(chip, status); 1065 NM_ACK_INT(chip, status);
@@ -1104,7 +1108,7 @@ snd_nm256_interrupt_zx(int irq, void *dev_id)
1104 if (status & NM2_MISC_INT_1) { 1108 if (status & NM2_MISC_INT_1) {
1105 status &= ~NM2_MISC_INT_1; 1109 status &= ~NM2_MISC_INT_1;
1106 NM2_ACK_INT(chip, NM2_MISC_INT_1); 1110 NM2_ACK_INT(chip, NM2_MISC_INT_1);
1107 snd_printd("NM256: Got misc interrupt #1\n"); 1111 dev_dbg(chip->card->dev, "NM256: Got misc interrupt #1\n");
1108 cbyte = snd_nm256_readb(chip, 0x400); 1112 cbyte = snd_nm256_readb(chip, 0x400);
1109 snd_nm256_writeb(chip, 0x400, cbyte | 2); 1113 snd_nm256_writeb(chip, 0x400, cbyte | 2);
1110 } 1114 }
@@ -1112,14 +1116,15 @@ snd_nm256_interrupt_zx(int irq, void *dev_id)
1112 if (status & NM2_MISC_INT_2) { 1116 if (status & NM2_MISC_INT_2) {
1113 status &= ~NM2_MISC_INT_2; 1117 status &= ~NM2_MISC_INT_2;
1114 NM2_ACK_INT(chip, NM2_MISC_INT_2); 1118 NM2_ACK_INT(chip, NM2_MISC_INT_2);
1115 snd_printd("NM256: Got misc interrupt #2\n"); 1119 dev_dbg(chip->card->dev, "NM256: Got misc interrupt #2\n");
1116 cbyte = snd_nm256_readb(chip, 0x400); 1120 cbyte = snd_nm256_readb(chip, 0x400);
1117 snd_nm256_writeb(chip, 0x400, cbyte & ~2); 1121 snd_nm256_writeb(chip, 0x400, cbyte & ~2);
1118 } 1122 }
1119 1123
1120 /* Unknown interrupt. */ 1124 /* Unknown interrupt. */
1121 if (status) { 1125 if (status) {
1122 snd_printd("NM256: Fire in the hole! Unknown status 0x%x\n", 1126 dev_dbg(chip->card->dev,
1127 "NM256: Fire in the hole! Unknown status 0x%x\n",
1123 status); 1128 status);
1124 /* Pray. */ 1129 /* Pray. */
1125 NM2_ACK_INT(chip, status); 1130 NM2_ACK_INT(chip, status);
@@ -1245,7 +1250,7 @@ snd_nm256_ac97_write(struct snd_ac97 *ac97,
1245 return; 1250 return;
1246 } 1251 }
1247 } 1252 }
1248 snd_printd("nm256: ac97 codec not ready..\n"); 1253 dev_dbg(chip->card->dev, "nm256: ac97 codec not ready..\n");
1249} 1254}
1250 1255
1251/* static resolution table */ 1256/* static resolution table */
@@ -1347,7 +1352,8 @@ snd_nm256_peek_for_sig(struct nm256 *chip)
1347 1352
1348 temp = ioremap_nocache(chip->buffer_addr + chip->buffer_end - 0x400, 16); 1353 temp = ioremap_nocache(chip->buffer_addr + chip->buffer_end - 0x400, 16);
1349 if (temp == NULL) { 1354 if (temp == NULL) {
1350 snd_printk(KERN_ERR "Unable to scan for card signature in video RAM\n"); 1355 dev_err(chip->card->dev,
1356 "Unable to scan for card signature in video RAM\n");
1351 return -EBUSY; 1357 return -EBUSY;
1352 } 1358 }
1353 1359
@@ -1361,12 +1367,14 @@ snd_nm256_peek_for_sig(struct nm256 *chip)
1361 if (pointer == 0xffffffff || 1367 if (pointer == 0xffffffff ||
1362 pointer < chip->buffer_size || 1368 pointer < chip->buffer_size ||
1363 pointer > chip->buffer_end) { 1369 pointer > chip->buffer_end) {
1364 snd_printk(KERN_ERR "invalid signature found: 0x%x\n", pointer); 1370 dev_err(chip->card->dev,
1371 "invalid signature found: 0x%x\n", pointer);
1365 iounmap(temp); 1372 iounmap(temp);
1366 return -ENODEV; 1373 return -ENODEV;
1367 } else { 1374 } else {
1368 pointer_found = pointer; 1375 pointer_found = pointer;
1369 printk(KERN_INFO "nm256: found card signature in video RAM: 0x%x\n", 1376 dev_info(chip->card->dev,
1377 "found card signature in video RAM: 0x%x\n",
1370 pointer); 1378 pointer);
1371 } 1379 }
1372 } 1380 }
@@ -1411,8 +1419,7 @@ static int nm256_resume(struct device *dev)
1411 pci_set_power_state(pci, PCI_D0); 1419 pci_set_power_state(pci, PCI_D0);
1412 pci_restore_state(pci); 1420 pci_restore_state(pci);
1413 if (pci_enable_device(pci) < 0) { 1421 if (pci_enable_device(pci) < 0) {
1414 printk(KERN_ERR "nm256: pci_enable_device failed, " 1422 dev_err(dev, "pci_enable_device failed, disabling device\n");
1415 "disabling device\n");
1416 snd_card_disconnect(card); 1423 snd_card_disconnect(card);
1417 return -EIO; 1424 return -EIO;
1418 } 1425 }
@@ -1520,14 +1527,15 @@ snd_nm256_create(struct snd_card *card, struct pci_dev *pci,
1520 chip->res_cport = request_mem_region(chip->cport_addr, NM_PORT2_SIZE, 1527 chip->res_cport = request_mem_region(chip->cport_addr, NM_PORT2_SIZE,
1521 card->driver); 1528 card->driver);
1522 if (chip->res_cport == NULL) { 1529 if (chip->res_cport == NULL) {
1523 snd_printk(KERN_ERR "memory region 0x%lx (size 0x%x) busy\n", 1530 dev_err(card->dev, "memory region 0x%lx (size 0x%x) busy\n",
1524 chip->cport_addr, NM_PORT2_SIZE); 1531 chip->cport_addr, NM_PORT2_SIZE);
1525 err = -EBUSY; 1532 err = -EBUSY;
1526 goto __error; 1533 goto __error;
1527 } 1534 }
1528 chip->cport = ioremap_nocache(chip->cport_addr, NM_PORT2_SIZE); 1535 chip->cport = ioremap_nocache(chip->cport_addr, NM_PORT2_SIZE);
1529 if (chip->cport == NULL) { 1536 if (chip->cport == NULL) {
1530 snd_printk(KERN_ERR "unable to map control port %lx\n", chip->cport_addr); 1537 dev_err(card->dev, "unable to map control port %lx\n",
1538 chip->cport_addr);
1531 err = -ENOMEM; 1539 err = -ENOMEM;
1532 goto __error; 1540 goto __error;
1533 } 1541 }
@@ -1537,12 +1545,14 @@ snd_nm256_create(struct snd_card *card, struct pci_dev *pci,
1537 pval = snd_nm256_readw(chip, NM_MIXER_PRESENCE); 1545 pval = snd_nm256_readw(chip, NM_MIXER_PRESENCE);
1538 if ((pval & NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) { 1546 if ((pval & NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) {
1539 if (! force_ac97) { 1547 if (! force_ac97) {
1540 printk(KERN_ERR "nm256: no ac97 is found!\n"); 1548 dev_err(card->dev,
1541 printk(KERN_ERR " force the driver to load by " 1549 "no ac97 is found!\n");
1542 "passing in the module parameter\n"); 1550 dev_err(card->dev,
1543 printk(KERN_ERR " force_ac97=1\n"); 1551 "force the driver to load by passing in the module parameter\n");
1544 printk(KERN_ERR " or try sb16, opl3sa2, or " 1552 dev_err(card->dev,
1545 "cs423x drivers instead.\n"); 1553 " force_ac97=1\n");
1554 dev_err(card->dev,
1555 "or try sb16, opl3sa2, or cs423x drivers instead.\n");
1546 err = -ENXIO; 1556 err = -ENXIO;
1547 goto __error; 1557 goto __error;
1548 } 1558 }
@@ -1581,14 +1591,14 @@ snd_nm256_create(struct snd_card *card, struct pci_dev *pci,
1581 chip->buffer_start = chip->buffer_end - chip->buffer_size; 1591 chip->buffer_start = chip->buffer_end - chip->buffer_size;
1582 chip->buffer_addr += chip->buffer_start; 1592 chip->buffer_addr += chip->buffer_start;
1583 1593
1584 printk(KERN_INFO "nm256: Mapping port 1 from 0x%x - 0x%x\n", 1594 dev_info(card->dev, "Mapping port 1 from 0x%x - 0x%x\n",
1585 chip->buffer_start, chip->buffer_end); 1595 chip->buffer_start, chip->buffer_end);
1586 1596
1587 chip->res_buffer = request_mem_region(chip->buffer_addr, 1597 chip->res_buffer = request_mem_region(chip->buffer_addr,
1588 chip->buffer_size, 1598 chip->buffer_size,
1589 card->driver); 1599 card->driver);
1590 if (chip->res_buffer == NULL) { 1600 if (chip->res_buffer == NULL) {
1591 snd_printk(KERN_ERR "nm256: buffer 0x%lx (size 0x%x) busy\n", 1601 dev_err(card->dev, "buffer 0x%lx (size 0x%x) busy\n",
1592 chip->buffer_addr, chip->buffer_size); 1602 chip->buffer_addr, chip->buffer_size);
1593 err = -EBUSY; 1603 err = -EBUSY;
1594 goto __error; 1604 goto __error;
@@ -1596,7 +1606,8 @@ snd_nm256_create(struct snd_card *card, struct pci_dev *pci,
1596 chip->buffer = ioremap_nocache(chip->buffer_addr, chip->buffer_size); 1606 chip->buffer = ioremap_nocache(chip->buffer_addr, chip->buffer_size);
1597 if (chip->buffer == NULL) { 1607 if (chip->buffer == NULL) {
1598 err = -ENOMEM; 1608 err = -ENOMEM;
1599 snd_printk(KERN_ERR "unable to map ring buffer at %lx\n", chip->buffer_addr); 1609 dev_err(card->dev, "unable to map ring buffer at %lx\n",
1610 chip->buffer_addr);
1600 goto __error; 1611 goto __error;
1601 } 1612 }
1602 1613
@@ -1626,8 +1637,6 @@ snd_nm256_create(struct snd_card *card, struct pci_dev *pci,
1626 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) 1637 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0)
1627 goto __error; 1638 goto __error;
1628 1639
1629 snd_card_set_dev(card, &pci->dev);
1630
1631 *chip_ret = chip; 1640 *chip_ret = chip;
1632 return 0; 1641 return 0;
1633 1642
@@ -1660,12 +1669,12 @@ static int snd_nm256_probe(struct pci_dev *pci,
1660 1669
1661 q = snd_pci_quirk_lookup(pci, nm256_quirks); 1670 q = snd_pci_quirk_lookup(pci, nm256_quirks);
1662 if (q) { 1671 if (q) {
1663 snd_printdd(KERN_INFO "nm256: Enabled quirk for %s.\n", 1672 dev_dbg(&pci->dev, "Enabled quirk for %s.\n",
1664 snd_pci_quirk_name(q)); 1673 snd_pci_quirk_name(q));
1665 switch (q->value) { 1674 switch (q->value) {
1666 case NM_BLACKLISTED: 1675 case NM_BLACKLISTED:
1667 printk(KERN_INFO "nm256: The device is blacklisted. " 1676 dev_info(&pci->dev,
1668 "Loading stopped\n"); 1677 "The device is blacklisted. Loading stopped\n");
1669 return -ENODEV; 1678 return -ENODEV;
1670 case NM_RESET_WORKAROUND_2: 1679 case NM_RESET_WORKAROUND_2:
1671 reset_workaround_2 = 1; 1680 reset_workaround_2 = 1;
@@ -1676,7 +1685,7 @@ static int snd_nm256_probe(struct pci_dev *pci,
1676 } 1685 }
1677 } 1686 }
1678 1687
1679 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 1688 err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
1680 if (err < 0) 1689 if (err < 0)
1681 return err; 1690 return err;
1682 1691
@@ -1691,7 +1700,7 @@ static int snd_nm256_probe(struct pci_dev *pci,
1691 strcpy(card->driver, "NM256XL+"); 1700 strcpy(card->driver, "NM256XL+");
1692 break; 1701 break;
1693 default: 1702 default:
1694 snd_printk(KERN_ERR "invalid device id 0x%x\n", pci->device); 1703 dev_err(&pci->dev, "invalid device id 0x%x\n", pci->device);
1695 snd_card_free(card); 1704 snd_card_free(card);
1696 return -EINVAL; 1705 return -EINVAL;
1697 } 1706 }
@@ -1714,12 +1723,12 @@ static int snd_nm256_probe(struct pci_dev *pci,
1714 card->private_data = chip; 1723 card->private_data = chip;
1715 1724
1716 if (reset_workaround) { 1725 if (reset_workaround) {
1717 snd_printdd(KERN_INFO "nm256: reset_workaround activated\n"); 1726 dev_dbg(&pci->dev, "reset_workaround activated\n");
1718 chip->reset_workaround = 1; 1727 chip->reset_workaround = 1;
1719 } 1728 }
1720 1729
1721 if (reset_workaround_2) { 1730 if (reset_workaround_2) {
1722 snd_printdd(KERN_INFO "nm256: reset_workaround_2 activated\n"); 1731 dev_dbg(&pci->dev, "reset_workaround_2 activated\n");
1723 chip->reset_workaround_2 = 1; 1732 chip->reset_workaround_2 = 1;
1724 } 1733 }
1725 1734
diff --git a/sound/pci/oxygen/oxygen_io.c b/sound/pci/oxygen/oxygen_io.c
index 3274907189fe..4b8a32c37e31 100644
--- a/sound/pci/oxygen/oxygen_io.c
+++ b/sound/pci/oxygen/oxygen_io.c
@@ -147,7 +147,7 @@ void oxygen_write_ac97(struct oxygen *chip, unsigned int codec,
147 return; 147 return;
148 } 148 }
149 } 149 }
150 snd_printk(KERN_ERR "AC'97 write timeout\n"); 150 dev_err(chip->card->dev, "AC'97 write timeout\n");
151} 151}
152EXPORT_SYMBOL(oxygen_write_ac97); 152EXPORT_SYMBOL(oxygen_write_ac97);
153 153
@@ -179,7 +179,7 @@ u16 oxygen_read_ac97(struct oxygen *chip, unsigned int codec,
179 reg ^= 0xffff; 179 reg ^= 0xffff;
180 } 180 }
181 } 181 }
182 snd_printk(KERN_ERR "AC'97 read timeout on codec %u\n", codec); 182 dev_err(chip->card->dev, "AC'97 read timeout on codec %u\n", codec);
183 return 0; 183 return 0;
184} 184}
185EXPORT_SYMBOL(oxygen_read_ac97); 185EXPORT_SYMBOL(oxygen_read_ac97);
@@ -208,7 +208,7 @@ static int oxygen_wait_spi(struct oxygen *chip)
208 OXYGEN_SPI_BUSY) == 0) 208 OXYGEN_SPI_BUSY) == 0)
209 return 0; 209 return 0;
210 } 210 }
211 snd_printk(KERN_ERR "oxygen: SPI wait timeout\n"); 211 dev_err(chip->card->dev, "oxygen: SPI wait timeout\n");
212 return -EIO; 212 return -EIO;
213} 213}
214 214
@@ -288,5 +288,5 @@ void oxygen_write_eeprom(struct oxygen *chip, unsigned int index, u16 value)
288 & OXYGEN_EEPROM_BUSY)) 288 & OXYGEN_EEPROM_BUSY))
289 return; 289 return;
290 } 290 }
291 snd_printk(KERN_ERR "EEPROM write timeout\n"); 291 dev_err(chip->card->dev, "EEPROM write timeout\n");
292} 292}
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index b0cb48adddc7..b67e30602473 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -313,7 +313,7 @@ static void oxygen_restore_eeprom(struct oxygen *chip,
313 oxygen_clear_bits8(chip, OXYGEN_MISC, 313 oxygen_clear_bits8(chip, OXYGEN_MISC,
314 OXYGEN_MISC_WRITE_PCI_SUBID); 314 OXYGEN_MISC_WRITE_PCI_SUBID);
315 315
316 snd_printk(KERN_INFO "EEPROM ID restored\n"); 316 dev_info(chip->card->dev, "EEPROM ID restored\n");
317 } 317 }
318} 318}
319 319
@@ -595,7 +595,8 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
595 const struct pci_device_id *pci_id; 595 const struct pci_device_id *pci_id;
596 int err; 596 int err;
597 597
598 err = snd_card_create(index, id, owner, sizeof(*chip), &card); 598 err = snd_card_new(&pci->dev, index, id, owner,
599 sizeof(*chip), &card);
599 if (err < 0) 600 if (err < 0)
600 return err; 601 return err;
601 602
@@ -616,13 +617,13 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
616 617
617 err = pci_request_regions(pci, DRIVER); 618 err = pci_request_regions(pci, DRIVER);
618 if (err < 0) { 619 if (err < 0) {
619 snd_printk(KERN_ERR "cannot reserve PCI resources\n"); 620 dev_err(card->dev, "cannot reserve PCI resources\n");
620 goto err_pci_enable; 621 goto err_pci_enable;
621 } 622 }
622 623
623 if (!(pci_resource_flags(pci, 0) & IORESOURCE_IO) || 624 if (!(pci_resource_flags(pci, 0) & IORESOURCE_IO) ||
624 pci_resource_len(pci, 0) < OXYGEN_IO_SIZE) { 625 pci_resource_len(pci, 0) < OXYGEN_IO_SIZE) {
625 snd_printk(KERN_ERR "invalid PCI I/O range\n"); 626 dev_err(card->dev, "invalid PCI I/O range\n");
626 err = -ENXIO; 627 err = -ENXIO;
627 goto err_pci_regions; 628 goto err_pci_regions;
628 } 629 }
@@ -648,7 +649,6 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
648 } 649 }
649 650
650 pci_set_master(pci); 651 pci_set_master(pci);
651 snd_card_set_dev(card, &pci->dev);
652 card->private_free = oxygen_card_free; 652 card->private_free = oxygen_card_free;
653 653
654 configure_pcie_bridge(pci); 654 configure_pcie_bridge(pci);
@@ -658,7 +658,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
658 err = request_irq(pci->irq, oxygen_interrupt, IRQF_SHARED, 658 err = request_irq(pci->irq, oxygen_interrupt, IRQF_SHARED,
659 KBUILD_MODNAME, chip); 659 KBUILD_MODNAME, chip);
660 if (err < 0) { 660 if (err < 0) {
661 snd_printk(KERN_ERR "cannot grab interrupt %d\n", pci->irq); 661 dev_err(card->dev, "cannot grab interrupt %d\n", pci->irq);
662 goto err_card; 662 goto err_card;
663 } 663 }
664 chip->irq = pci->irq; 664 chip->irq = pci->irq;
@@ -796,7 +796,7 @@ static int oxygen_pci_resume(struct device *dev)
796 pci_set_power_state(pci, PCI_D0); 796 pci_set_power_state(pci, PCI_D0);
797 pci_restore_state(pci); 797 pci_restore_state(pci);
798 if (pci_enable_device(pci) < 0) { 798 if (pci_enable_device(pci) < 0) {
799 snd_printk(KERN_ERR "cannot reenable device"); 799 dev_err(dev, "cannot reenable device");
800 snd_card_disconnect(card); 800 snd_card_disconnect(card);
801 return -EIO; 801 return -EIO;
802 } 802 }
diff --git a/sound/pci/oxygen/xonar_hdmi.c b/sound/pci/oxygen/xonar_hdmi.c
index 136dac6a3964..91d92bc32b75 100644
--- a/sound/pci/oxygen/xonar_hdmi.c
+++ b/sound/pci/oxygen/xonar_hdmi.c
@@ -120,7 +120,7 @@ void xonar_hdmi_uart_input(struct oxygen *chip)
120 if (chip->uart_input_count >= 2 && 120 if (chip->uart_input_count >= 2 &&
121 chip->uart_input[chip->uart_input_count - 2] == 'O' && 121 chip->uart_input[chip->uart_input_count - 2] == 'O' &&
122 chip->uart_input[chip->uart_input_count - 1] == 'K') { 122 chip->uart_input[chip->uart_input_count - 1] == 'K') {
123 printk(KERN_DEBUG "message from HDMI chip received:\n"); 123 dev_dbg(chip->card->dev, "message from HDMI chip received:\n");
124 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, 124 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
125 chip->uart_input, chip->uart_input_count); 125 chip->uart_input, chip->uart_input_count);
126 chip->uart_input_count = 0; 126 chip->uart_input_count = 0;
diff --git a/sound/pci/oxygen/xonar_lib.c b/sound/pci/oxygen/xonar_lib.c
index 0ebe7f5916f9..706b1a42163f 100644
--- a/sound/pci/oxygen/xonar_lib.c
+++ b/sound/pci/oxygen/xonar_lib.c
@@ -56,9 +56,9 @@ static void xonar_ext_power_gpio_changed(struct oxygen *chip)
56 if (has_power != data->has_power) { 56 if (has_power != data->has_power) {
57 data->has_power = has_power; 57 data->has_power = has_power;
58 if (has_power) { 58 if (has_power) {
59 snd_printk(KERN_NOTICE "power restored\n"); 59 dev_notice(chip->card->dev, "power restored\n");
60 } else { 60 } else {
61 snd_printk(KERN_CRIT 61 dev_crit(chip->card->dev,
62 "Hey! Don't unplug the power cable!\n"); 62 "Hey! Don't unplug the power cable!\n");
63 /* TODO: stop PCMs */ 63 /* TODO: stop PCMs */
64 } 64 }
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index d379b284955b..8d09444ff88b 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -284,7 +284,7 @@ static int pcxhr_get_clock_reg(struct pcxhr_mgr *mgr, unsigned int rate,
284 rmh.cmd_len = 3; 284 rmh.cmd_len = 3;
285 err = pcxhr_send_msg(mgr, &rmh); 285 err = pcxhr_send_msg(mgr, &rmh);
286 if (err < 0) { 286 if (err < 0) {
287 snd_printk(KERN_ERR 287 dev_err(&mgr->pci->dev,
288 "error CMD_ACCESS_IO_WRITE " 288 "error CMD_ACCESS_IO_WRITE "
289 "for PLL register : %x!\n", err); 289 "for PLL register : %x!\n", err);
290 return err; 290 return err;
@@ -357,7 +357,7 @@ static int pcxhr_sub_set_clock(struct pcxhr_mgr *mgr,
357 return err; 357 return err;
358 } 358 }
359 /* set the new frequency */ 359 /* set the new frequency */
360 snd_printdd("clock register : set %x\n", val); 360 dev_dbg(&mgr->pci->dev, "clock register : set %x\n", val);
361 err = pcxhr_write_io_num_reg_cont(mgr, PCXHR_FREQ_REG_MASK, 361 err = pcxhr_write_io_num_reg_cont(mgr, PCXHR_FREQ_REG_MASK,
362 val, changed); 362 val, changed);
363 if (err) 363 if (err)
@@ -380,7 +380,7 @@ static int pcxhr_sub_set_clock(struct pcxhr_mgr *mgr,
380 mgr->codec_speed = speed; /* save new codec speed */ 380 mgr->codec_speed = speed; /* save new codec speed */
381 } 381 }
382 382
383 snd_printdd("pcxhr_sub_set_clock to %dHz (realfreq=%d)\n", 383 dev_dbg(&mgr->pci->dev, "pcxhr_sub_set_clock to %dHz (realfreq=%d)\n",
384 rate, realfreq); 384 rate, realfreq);
385 return 0; 385 return 0;
386} 386}
@@ -480,7 +480,7 @@ static int pcxhr_sub_get_external_clock(struct pcxhr_mgr *mgr,
480 case REG_STATUS_SYNC_192000 : rate = 192000; break; 480 case REG_STATUS_SYNC_192000 : rate = 192000; break;
481 default: rate = 0; 481 default: rate = 0;
482 } 482 }
483 snd_printdd("External clock is at %d Hz\n", rate); 483 dev_dbg(&mgr->pci->dev, "External clock is at %d Hz\n", rate);
484 *sample_rate = rate; 484 *sample_rate = rate;
485 return 0; 485 return 0;
486} 486}
@@ -537,8 +537,8 @@ static int pcxhr_set_stream_state(struct pcxhr_stream *stream)
537 537
538 err = pcxhr_send_msg(chip->mgr, &rmh); 538 err = pcxhr_send_msg(chip->mgr, &rmh);
539 if (err) 539 if (err)
540 snd_printk(KERN_ERR "ERROR pcxhr_set_stream_state err=%x;\n", 540 dev_err(chip->card->dev,
541 err); 541 "ERROR pcxhr_set_stream_state err=%x;\n", err);
542 stream->status = 542 stream->status =
543 start ? PCXHR_STREAM_STATUS_STARTED : PCXHR_STREAM_STATUS_STOPPED; 543 start ? PCXHR_STREAM_STATUS_STARTED : PCXHR_STREAM_STATUS_STOPPED;
544 return err; 544 return err;
@@ -628,7 +628,8 @@ static int pcxhr_set_format(struct pcxhr_stream *stream)
628 rmh.cmd[rmh.cmd_len++] = (header & 0xff) << 16; 628 rmh.cmd[rmh.cmd_len++] = (header & 0xff) << 16;
629 err = pcxhr_send_msg(chip->mgr, &rmh); 629 err = pcxhr_send_msg(chip->mgr, &rmh);
630 if (err) 630 if (err)
631 snd_printk(KERN_ERR "ERROR pcxhr_set_format err=%x;\n", err); 631 dev_err(chip->card->dev,
632 "ERROR pcxhr_set_format err=%x;\n", err);
632 return err; 633 return err;
633} 634}
634 635
@@ -665,7 +666,7 @@ static int pcxhr_update_r_buffer(struct pcxhr_stream *stream)
665 rmh.cmd_len = 4; 666 rmh.cmd_len = 4;
666 err = pcxhr_send_msg(chip->mgr, &rmh); 667 err = pcxhr_send_msg(chip->mgr, &rmh);
667 if (err) 668 if (err)
668 snd_printk(KERN_ERR 669 dev_err(chip->card->dev,
669 "ERROR CMD_UPDATE_R_BUFFERS err=%x;\n", err); 670 "ERROR CMD_UPDATE_R_BUFFERS err=%x;\n", err);
670 return err; 671 return err;
671} 672}
@@ -735,11 +736,11 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
735 } 736 }
736 if (capture_mask == 0 && playback_mask == 0) { 737 if (capture_mask == 0 && playback_mask == 0) {
737 mutex_unlock(&mgr->setup_mutex); 738 mutex_unlock(&mgr->setup_mutex);
738 snd_printk(KERN_ERR "pcxhr_trigger_tasklet : no pipes\n"); 739 dev_err(&mgr->pci->dev, "pcxhr_trigger_tasklet : no pipes\n");
739 return; 740 return;
740 } 741 }
741 742
742 snd_printdd("pcxhr_trigger_tasklet : " 743 dev_dbg(&mgr->pci->dev, "pcxhr_trigger_tasklet : "
743 "playback_mask=%x capture_mask=%x\n", 744 "playback_mask=%x capture_mask=%x\n",
744 playback_mask, capture_mask); 745 playback_mask, capture_mask);
745 746
@@ -747,7 +748,7 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
747 err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 0); 748 err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 0);
748 if (err) { 749 if (err) {
749 mutex_unlock(&mgr->setup_mutex); 750 mutex_unlock(&mgr->setup_mutex);
750 snd_printk(KERN_ERR "pcxhr_trigger_tasklet : " 751 dev_err(&mgr->pci->dev, "pcxhr_trigger_tasklet : "
751 "error stop pipes (P%x C%x)\n", 752 "error stop pipes (P%x C%x)\n",
752 playback_mask, capture_mask); 753 playback_mask, capture_mask);
753 return; 754 return;
@@ -792,7 +793,7 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
792 err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 1); 793 err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 1);
793 if (err) { 794 if (err) {
794 mutex_unlock(&mgr->setup_mutex); 795 mutex_unlock(&mgr->setup_mutex);
795 snd_printk(KERN_ERR "pcxhr_trigger_tasklet : " 796 dev_err(&mgr->pci->dev, "pcxhr_trigger_tasklet : "
796 "error start pipes (P%x C%x)\n", 797 "error start pipes (P%x C%x)\n",
797 playback_mask, capture_mask); 798 playback_mask, capture_mask);
798 return; 799 return;
@@ -825,7 +826,7 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
825 826
826#ifdef CONFIG_SND_DEBUG_VERBOSE 827#ifdef CONFIG_SND_DEBUG_VERBOSE
827 do_gettimeofday(&my_tv2); 828 do_gettimeofday(&my_tv2);
828 snd_printdd("***TRIGGER TASKLET*** TIME = %ld (err = %x)\n", 829 dev_dbg(&mgr->pci->dev, "***TRIGGER TASKLET*** TIME = %ld (err = %x)\n",
829 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err); 830 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
830#endif 831#endif
831} 832}
@@ -902,7 +903,7 @@ static int pcxhr_hardware_timer(struct pcxhr_mgr *mgr, int start)
902 } 903 }
903 err = pcxhr_send_msg(mgr, &rmh); 904 err = pcxhr_send_msg(mgr, &rmh);
904 if (err < 0) 905 if (err < 0)
905 snd_printk(KERN_ERR "error pcxhr_hardware_timer err(%x)\n", 906 dev_err(&mgr->pci->dev, "error pcxhr_hardware_timer err(%x)\n",
906 err); 907 err);
907 return err; 908 return err;
908} 909}
@@ -916,7 +917,8 @@ static int pcxhr_prepare(struct snd_pcm_substream *subs)
916 struct pcxhr_mgr *mgr = chip->mgr; 917 struct pcxhr_mgr *mgr = chip->mgr;
917 int err = 0; 918 int err = 0;
918 919
919 snd_printdd("pcxhr_prepare : period_size(%lx) periods(%x) buffer_size(%lx)\n", 920 dev_dbg(chip->card->dev,
921 "pcxhr_prepare : period_size(%lx) periods(%x) buffer_size(%lx)\n",
920 subs->runtime->period_size, subs->runtime->periods, 922 subs->runtime->period_size, subs->runtime->periods,
921 subs->runtime->buffer_size); 923 subs->runtime->buffer_size);
922 924
@@ -1025,11 +1027,11 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
1025 runtime->hw = pcxhr_caps; 1027 runtime->hw = pcxhr_caps;
1026 1028
1027 if( subs->stream == SNDRV_PCM_STREAM_PLAYBACK ) { 1029 if( subs->stream == SNDRV_PCM_STREAM_PLAYBACK ) {
1028 snd_printdd("pcxhr_open playback chip%d subs%d\n", 1030 dev_dbg(chip->card->dev, "pcxhr_open playback chip%d subs%d\n",
1029 chip->chip_idx, subs->number); 1031 chip->chip_idx, subs->number);
1030 stream = &chip->playback_stream[subs->number]; 1032 stream = &chip->playback_stream[subs->number];
1031 } else { 1033 } else {
1032 snd_printdd("pcxhr_open capture chip%d subs%d\n", 1034 dev_dbg(chip->card->dev, "pcxhr_open capture chip%d subs%d\n",
1033 chip->chip_idx, subs->number); 1035 chip->chip_idx, subs->number);
1034 if (mgr->mono_capture) 1036 if (mgr->mono_capture)
1035 runtime->hw.channels_max = 1; 1037 runtime->hw.channels_max = 1;
@@ -1039,7 +1041,7 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
1039 } 1041 }
1040 if (stream->status != PCXHR_STREAM_STATUS_FREE){ 1042 if (stream->status != PCXHR_STREAM_STATUS_FREE){
1041 /* streams in use */ 1043 /* streams in use */
1042 snd_printk(KERN_ERR "pcxhr_open chip%d subs%d in use\n", 1044 dev_err(chip->card->dev, "pcxhr_open chip%d subs%d in use\n",
1043 chip->chip_idx, subs->number); 1045 chip->chip_idx, subs->number);
1044 mutex_unlock(&mgr->setup_mutex); 1046 mutex_unlock(&mgr->setup_mutex);
1045 return -EBUSY; 1047 return -EBUSY;
@@ -1105,7 +1107,7 @@ static int pcxhr_close(struct snd_pcm_substream *subs)
1105 1107
1106 mutex_lock(&mgr->setup_mutex); 1108 mutex_lock(&mgr->setup_mutex);
1107 1109
1108 snd_printdd("pcxhr_close chip%d subs%d\n", 1110 dev_dbg(chip->card->dev, "pcxhr_close chip%d subs%d\n",
1109 chip->chip_idx, subs->number); 1111 chip->chip_idx, subs->number);
1110 1112
1111 /* sample rate released */ 1113 /* sample rate released */
@@ -1168,7 +1170,7 @@ int pcxhr_create_pcm(struct snd_pcxhr *chip)
1168 if ((err = snd_pcm_new(chip->card, name, 0, 1170 if ((err = snd_pcm_new(chip->card, name, 0,
1169 chip->nb_streams_play, 1171 chip->nb_streams_play,
1170 chip->nb_streams_capt, &pcm)) < 0) { 1172 chip->nb_streams_capt, &pcm)) < 0) {
1171 snd_printk(KERN_ERR "cannot create pcm %s\n", name); 1173 dev_err(chip->card->dev, "cannot create pcm %s\n", name);
1172 return err; 1174 return err;
1173 } 1175 }
1174 pcm->private_data = chip; 1176 pcm->private_data = chip;
@@ -1214,7 +1216,7 @@ static int pcxhr_create(struct pcxhr_mgr *mgr,
1214 1216
1215 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1217 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1216 if (! chip) { 1218 if (! chip) {
1217 snd_printk(KERN_ERR "cannot allocate chip\n"); 1219 dev_err(card->dev, "cannot allocate chip\n");
1218 return -ENOMEM; 1220 return -ENOMEM;
1219 } 1221 }
1220 1222
@@ -1239,7 +1241,6 @@ static int pcxhr_create(struct pcxhr_mgr *mgr,
1239 } 1241 }
1240 1242
1241 mgr->chip[idx] = chip; 1243 mgr->chip[idx] = chip;
1242 snd_card_set_dev(card, &mgr->pci->dev);
1243 1244
1244 return 0; 1245 return 0;
1245} 1246}
@@ -1488,7 +1489,7 @@ static int pcxhr_free(struct pcxhr_mgr *mgr)
1488 /* reset board if some firmware was loaded */ 1489 /* reset board if some firmware was loaded */
1489 if(mgr->dsp_loaded) { 1490 if(mgr->dsp_loaded) {
1490 pcxhr_reset_board(mgr); 1491 pcxhr_reset_board(mgr);
1491 snd_printdd("reset pcxhr !\n"); 1492 dev_dbg(&mgr->pci->dev, "reset pcxhr !\n");
1492 } 1493 }
1493 1494
1494 /* release irq */ 1495 /* release irq */
@@ -1537,8 +1538,8 @@ static int pcxhr_probe(struct pci_dev *pci,
1537 1538
1538 /* check if we can restrict PCI DMA transfers to 32 bits */ 1539 /* check if we can restrict PCI DMA transfers to 32 bits */
1539 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0) { 1540 if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0) {
1540 snd_printk(KERN_ERR "architecture does not support " 1541 dev_err(&pci->dev,
1541 "32bit PCI busmaster DMA\n"); 1542 "architecture does not support 32bit PCI busmaster DMA\n");
1542 pci_disable_device(pci); 1543 pci_disable_device(pci);
1543 return -ENXIO; 1544 return -ENXIO;
1544 } 1545 }
@@ -1589,7 +1590,7 @@ static int pcxhr_probe(struct pci_dev *pci,
1589 1590
1590 if (request_irq(pci->irq, pcxhr_interrupt, IRQF_SHARED, 1591 if (request_irq(pci->irq, pcxhr_interrupt, IRQF_SHARED,
1591 KBUILD_MODNAME, mgr)) { 1592 KBUILD_MODNAME, mgr)) {
1592 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1593 dev_err(&pci->dev, "unable to grab IRQ %d\n", pci->irq);
1593 pcxhr_free(mgr); 1594 pcxhr_free(mgr);
1594 return -EBUSY; 1595 return -EBUSY;
1595 } 1596 }
@@ -1638,10 +1639,11 @@ static int pcxhr_probe(struct pci_dev *pci,
1638 1639
1639 snprintf(tmpid, sizeof(tmpid), "%s-%d", 1640 snprintf(tmpid, sizeof(tmpid), "%s-%d",
1640 id[dev] ? id[dev] : card_name, i); 1641 id[dev] ? id[dev] : card_name, i);
1641 err = snd_card_create(idx, tmpid, THIS_MODULE, 0, &card); 1642 err = snd_card_new(&pci->dev, idx, tmpid, THIS_MODULE,
1643 0, &card);
1642 1644
1643 if (err < 0) { 1645 if (err < 0) {
1644 snd_printk(KERN_ERR "cannot allocate the card %d\n", i); 1646 dev_err(card->dev, "cannot allocate the card %d\n", i);
1645 pcxhr_free(mgr); 1647 pcxhr_free(mgr);
1646 return err; 1648 return err;
1647 } 1649 }
diff --git a/sound/pci/pcxhr/pcxhr_core.c b/sound/pci/pcxhr/pcxhr_core.c
index 37b431b9b69d..df9371918601 100644
--- a/sound/pci/pcxhr/pcxhr_core.c
+++ b/sound/pci/pcxhr/pcxhr_core.c
@@ -23,6 +23,7 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/firmware.h> 24#include <linux/firmware.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/pci.h>
26#include <asm/io.h> 27#include <asm/io.h>
27#include <sound/core.h> 28#include <sound/core.h>
28#include "pcxhr.h" 29#include "pcxhr.h"
@@ -132,14 +133,14 @@ static int pcxhr_check_reg_bit(struct pcxhr_mgr *mgr, unsigned int reg,
132 *read = PCXHR_INPB(mgr, reg); 133 *read = PCXHR_INPB(mgr, reg);
133 if ((*read & mask) == bit) { 134 if ((*read & mask) == bit) {
134 if (i > 100) 135 if (i > 100)
135 snd_printdd("ATTENTION! check_reg(%x) " 136 dev_dbg(&mgr->pci->dev,
136 "loopcount=%d\n", 137 "ATTENTION! check_reg(%x) loopcount=%d\n",
137 reg, i); 138 reg, i);
138 return 0; 139 return 0;
139 } 140 }
140 i++; 141 i++;
141 } while (time_after_eq(end_time, jiffies)); 142 } while (time_after_eq(end_time, jiffies));
142 snd_printk(KERN_ERR 143 dev_err(&mgr->pci->dev,
143 "pcxhr_check_reg_bit: timeout, reg=%x, mask=0x%x, val=%x\n", 144 "pcxhr_check_reg_bit: timeout, reg=%x, mask=0x%x, val=%x\n",
144 reg, mask, *read); 145 reg, mask, *read);
145 return -EIO; 146 return -EIO;
@@ -216,7 +217,7 @@ static int pcxhr_send_it_dsp(struct pcxhr_mgr *mgr,
216 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_CVR, PCXHR_CVR_HI08_HC, 0, 217 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_CVR, PCXHR_CVR_HI08_HC, 0,
217 PCXHR_TIMEOUT_DSP, &reg); 218 PCXHR_TIMEOUT_DSP, &reg);
218 if (err) { 219 if (err) {
219 snd_printk(KERN_ERR "pcxhr_send_it_dsp : TIMEOUT CVR\n"); 220 dev_err(&mgr->pci->dev, "pcxhr_send_it_dsp : TIMEOUT CVR\n");
220 return err; 221 return err;
221 } 222 }
222 if (itdsp & PCXHR_MASK_IT_MANAGE_HF5) { 223 if (itdsp & PCXHR_MASK_IT_MANAGE_HF5) {
@@ -227,7 +228,7 @@ static int pcxhr_send_it_dsp(struct pcxhr_mgr *mgr,
227 PCXHR_TIMEOUT_DSP, 228 PCXHR_TIMEOUT_DSP,
228 &reg); 229 &reg);
229 if (err) { 230 if (err) {
230 snd_printk(KERN_ERR 231 dev_err(&mgr->pci->dev,
231 "pcxhr_send_it_dsp : TIMEOUT HF5\n"); 232 "pcxhr_send_it_dsp : TIMEOUT HF5\n");
232 return err; 233 return err;
233 } 234 }
@@ -294,7 +295,7 @@ int pcxhr_load_xilinx_binary(struct pcxhr_mgr *mgr,
294 */ 295 */
295 if(second) { 296 if(second) {
296 if ((chipsc & PCXHR_CHIPSC_GPI_USERI) == 0) { 297 if ((chipsc & PCXHR_CHIPSC_GPI_USERI) == 0) {
297 snd_printk(KERN_ERR "error loading first xilinx\n"); 298 dev_err(&mgr->pci->dev, "error loading first xilinx\n");
298 return -EINVAL; 299 return -EINVAL;
299 } 300 }
300 /* activate second xilinx */ 301 /* activate second xilinx */
@@ -360,7 +361,7 @@ static int pcxhr_download_dsp(struct pcxhr_mgr *mgr, const struct firmware *dsp)
360 PCXHR_ISR_HI08_TRDY, 361 PCXHR_ISR_HI08_TRDY,
361 PCXHR_TIMEOUT_DSP, &dummy); 362 PCXHR_TIMEOUT_DSP, &dummy);
362 if (err) { 363 if (err) {
363 snd_printk(KERN_ERR 364 dev_err(&mgr->pci->dev,
364 "dsp loading error at position %d\n", i); 365 "dsp loading error at position %d\n", i);
365 return err; 366 return err;
366 } 367 }
@@ -396,7 +397,7 @@ int pcxhr_load_eeprom_binary(struct pcxhr_mgr *mgr,
396 msleep(PCXHR_WAIT_DEFAULT); 397 msleep(PCXHR_WAIT_DEFAULT);
397 PCXHR_OUTPB(mgr, PCXHR_DSP_ICR, reg); 398 PCXHR_OUTPB(mgr, PCXHR_DSP_ICR, reg);
398 msleep(PCXHR_WAIT_DEFAULT); 399 msleep(PCXHR_WAIT_DEFAULT);
399 snd_printdd("no need to load eeprom boot\n"); 400 dev_dbg(&mgr->pci->dev, "no need to load eeprom boot\n");
400 return 0; 401 return 0;
401 } 402 }
402 PCXHR_OUTPB(mgr, PCXHR_DSP_ICR, reg); 403 PCXHR_OUTPB(mgr, PCXHR_DSP_ICR, reg);
@@ -561,9 +562,9 @@ static int pcxhr_read_rmh_status(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
561 PCXHR_ISR_HI08_RXDF, 562 PCXHR_ISR_HI08_RXDF,
562 PCXHR_TIMEOUT_DSP, &reg); 563 PCXHR_TIMEOUT_DSP, &reg);
563 if (err) { 564 if (err) {
564 snd_printk(KERN_ERR "ERROR RMH stat: " 565 dev_err(&mgr->pci->dev,
565 "ISR:RXDF=1 (ISR = %x; i=%d )\n", 566 "ERROR RMH stat: ISR:RXDF=1 (ISR = %x; i=%d )\n",
566 reg, i); 567 reg, i);
567 return err; 568 return err;
568 } 569 }
569 /* read data */ 570 /* read data */
@@ -591,13 +592,13 @@ static int pcxhr_read_rmh_status(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
591 } 592 }
592#ifdef CONFIG_SND_DEBUG_VERBOSE 593#ifdef CONFIG_SND_DEBUG_VERBOSE
593 if (rmh->cmd_idx < CMD_LAST_INDEX) 594 if (rmh->cmd_idx < CMD_LAST_INDEX)
594 snd_printdd(" stat[%d]=%x\n", i, data); 595 dev_dbg(&mgr->pci->dev, " stat[%d]=%x\n", i, data);
595#endif 596#endif
596 if (i < max_stat_len) 597 if (i < max_stat_len)
597 rmh->stat[i] = data; 598 rmh->stat[i] = data;
598 } 599 }
599 if (rmh->stat_len > max_stat_len) { 600 if (rmh->stat_len > max_stat_len) {
600 snd_printdd("PCXHR : rmh->stat_len=%x too big\n", 601 dev_dbg(&mgr->pci->dev, "PCXHR : rmh->stat_len=%x too big\n",
601 rmh->stat_len); 602 rmh->stat_len);
602 rmh->stat_len = max_stat_len; 603 rmh->stat_len = max_stat_len;
603 } 604 }
@@ -615,7 +616,8 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
615 return -EINVAL; 616 return -EINVAL;
616 err = pcxhr_send_it_dsp(mgr, PCXHR_IT_MESSAGE, 1); 617 err = pcxhr_send_it_dsp(mgr, PCXHR_IT_MESSAGE, 1);
617 if (err) { 618 if (err) {
618 snd_printk(KERN_ERR "pcxhr_send_message : ED_DSP_CRASHED\n"); 619 dev_err(&mgr->pci->dev,
620 "pcxhr_send_message : ED_DSP_CRASHED\n");
619 return err; 621 return err;
620 } 622 }
621 /* wait for chk bit */ 623 /* wait for chk bit */
@@ -641,7 +643,7 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
641 data &= 0xff7fff; /* MASK_1_WORD_COMMAND */ 643 data &= 0xff7fff; /* MASK_1_WORD_COMMAND */
642#ifdef CONFIG_SND_DEBUG_VERBOSE 644#ifdef CONFIG_SND_DEBUG_VERBOSE
643 if (rmh->cmd_idx < CMD_LAST_INDEX) 645 if (rmh->cmd_idx < CMD_LAST_INDEX)
644 snd_printdd("MSG cmd[0]=%x (%s)\n", 646 dev_dbg(&mgr->pci->dev, "MSG cmd[0]=%x (%s)\n",
645 data, cmd_names[rmh->cmd_idx]); 647 data, cmd_names[rmh->cmd_idx]);
646#endif 648#endif
647 649
@@ -671,7 +673,8 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
671 data = rmh->cmd[i]; 673 data = rmh->cmd[i];
672#ifdef CONFIG_SND_DEBUG_VERBOSE 674#ifdef CONFIG_SND_DEBUG_VERBOSE
673 if (rmh->cmd_idx < CMD_LAST_INDEX) 675 if (rmh->cmd_idx < CMD_LAST_INDEX)
674 snd_printdd(" cmd[%d]=%x\n", i, data); 676 dev_dbg(&mgr->pci->dev,
677 " cmd[%d]=%x\n", i, data);
675#endif 678#endif
676 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR, 679 err = pcxhr_check_reg_bit(mgr, PCXHR_DSP_ISR,
677 PCXHR_ISR_HI08_TRDY, 680 PCXHR_ISR_HI08_TRDY,
@@ -697,14 +700,15 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
697 PCXHR_ISR_HI08_RXDF, 700 PCXHR_ISR_HI08_RXDF,
698 PCXHR_TIMEOUT_DSP, &reg); 701 PCXHR_TIMEOUT_DSP, &reg);
699 if (err) { 702 if (err) {
700 snd_printk(KERN_ERR "ERROR RMH: ISR:RXDF=1 (ISR = %x)\n", reg); 703 dev_err(&mgr->pci->dev,
704 "ERROR RMH: ISR:RXDF=1 (ISR = %x)\n", reg);
701 return err; 705 return err;
702 } 706 }
703 /* read error code */ 707 /* read error code */
704 data = PCXHR_INPB(mgr, PCXHR_DSP_TXH) << 16; 708 data = PCXHR_INPB(mgr, PCXHR_DSP_TXH) << 16;
705 data |= PCXHR_INPB(mgr, PCXHR_DSP_TXM) << 8; 709 data |= PCXHR_INPB(mgr, PCXHR_DSP_TXM) << 8;
706 data |= PCXHR_INPB(mgr, PCXHR_DSP_TXL); 710 data |= PCXHR_INPB(mgr, PCXHR_DSP_TXL);
707 snd_printk(KERN_ERR "ERROR RMH(%d): 0x%x\n", 711 dev_err(&mgr->pci->dev, "ERROR RMH(%d): 0x%x\n",
708 rmh->cmd_idx, data); 712 rmh->cmd_idx, data);
709 err = -EINVAL; 713 err = -EINVAL;
710 } else { 714 } else {
@@ -780,7 +784,7 @@ static inline int pcxhr_pipes_running(struct pcxhr_mgr *mgr)
780 * (PCXHR_PIPE_STATE_CAPTURE_OFFSET) 784 * (PCXHR_PIPE_STATE_CAPTURE_OFFSET)
781 */ 785 */
782 start_mask &= 0xffffff; 786 start_mask &= 0xffffff;
783 snd_printdd("CMD_PIPE_STATE MBOX2=0x%06x\n", start_mask); 787 dev_dbg(&mgr->pci->dev, "CMD_PIPE_STATE MBOX2=0x%06x\n", start_mask);
784 return start_mask; 788 return start_mask;
785} 789}
786 790
@@ -809,7 +813,7 @@ static int pcxhr_prepair_pipe_start(struct pcxhr_mgr *mgr,
809 } 813 }
810 err = pcxhr_send_msg(mgr, &rmh); 814 err = pcxhr_send_msg(mgr, &rmh);
811 if (err) { 815 if (err) {
812 snd_printk(KERN_ERR 816 dev_err(&mgr->pci->dev,
813 "error pipe start " 817 "error pipe start "
814 "(CMD_CAN_START_PIPE) err=%x!\n", 818 "(CMD_CAN_START_PIPE) err=%x!\n",
815 err); 819 err);
@@ -847,7 +851,7 @@ static int pcxhr_stop_pipes(struct pcxhr_mgr *mgr, int audio_mask)
847 } 851 }
848 err = pcxhr_send_msg(mgr, &rmh); 852 err = pcxhr_send_msg(mgr, &rmh);
849 if (err) { 853 if (err) {
850 snd_printk(KERN_ERR 854 dev_err(&mgr->pci->dev,
851 "error pipe stop " 855 "error pipe stop "
852 "(CMD_STOP_PIPE) err=%x!\n", err); 856 "(CMD_STOP_PIPE) err=%x!\n", err);
853 return err; 857 return err;
@@ -876,7 +880,7 @@ static int pcxhr_toggle_pipes(struct pcxhr_mgr *mgr, int audio_mask)
876 1 << (audio - PCXHR_PIPE_STATE_CAPTURE_OFFSET)); 880 1 << (audio - PCXHR_PIPE_STATE_CAPTURE_OFFSET));
877 err = pcxhr_send_msg(mgr, &rmh); 881 err = pcxhr_send_msg(mgr, &rmh);
878 if (err) { 882 if (err) {
879 snd_printk(KERN_ERR 883 dev_err(&mgr->pci->dev,
880 "error pipe start " 884 "error pipe start "
881 "(CMD_CONF_PIPE) err=%x!\n", err); 885 "(CMD_CONF_PIPE) err=%x!\n", err);
882 return err; 886 return err;
@@ -889,7 +893,7 @@ static int pcxhr_toggle_pipes(struct pcxhr_mgr *mgr, int audio_mask)
889 pcxhr_init_rmh(&rmh, CMD_SEND_IRQA); 893 pcxhr_init_rmh(&rmh, CMD_SEND_IRQA);
890 err = pcxhr_send_msg(mgr, &rmh); 894 err = pcxhr_send_msg(mgr, &rmh);
891 if (err) { 895 if (err) {
892 snd_printk(KERN_ERR 896 dev_err(&mgr->pci->dev,
893 "error pipe start (CMD_SEND_IRQA) err=%x!\n", 897 "error pipe start (CMD_SEND_IRQA) err=%x!\n",
894 err); 898 err);
895 return err; 899 return err;
@@ -913,7 +917,8 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask,
913 (capture_mask << PCXHR_PIPE_STATE_CAPTURE_OFFSET)); 917 (capture_mask << PCXHR_PIPE_STATE_CAPTURE_OFFSET));
914 /* current pipe state (playback + record) */ 918 /* current pipe state (playback + record) */
915 state = pcxhr_pipes_running(mgr); 919 state = pcxhr_pipes_running(mgr);
916 snd_printdd("pcxhr_set_pipe_state %s (mask %x current %x)\n", 920 dev_dbg(&mgr->pci->dev,
921 "pcxhr_set_pipe_state %s (mask %x current %x)\n",
917 start ? "START" : "STOP", audio_mask, state); 922 start ? "START" : "STOP", audio_mask, state);
918 if (start) { 923 if (start) {
919 /* start only pipes that are not yet started */ 924 /* start only pipes that are not yet started */
@@ -944,7 +949,7 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask,
944 if ((state & audio_mask) == (start ? audio_mask : 0)) 949 if ((state & audio_mask) == (start ? audio_mask : 0))
945 break; 950 break;
946 if (++i >= MAX_WAIT_FOR_DSP * 100) { 951 if (++i >= MAX_WAIT_FOR_DSP * 100) {
947 snd_printk(KERN_ERR "error pipe start/stop\n"); 952 dev_err(&mgr->pci->dev, "error pipe start/stop\n");
948 return -EBUSY; 953 return -EBUSY;
949 } 954 }
950 udelay(10); /* wait 10 microseconds */ 955 udelay(10); /* wait 10 microseconds */
@@ -956,7 +961,7 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask,
956 } 961 }
957#ifdef CONFIG_SND_DEBUG_VERBOSE 962#ifdef CONFIG_SND_DEBUG_VERBOSE
958 do_gettimeofday(&my_tv2); 963 do_gettimeofday(&my_tv2);
959 snd_printdd("***SET PIPE STATE*** TIME = %ld (err = %x)\n", 964 dev_dbg(&mgr->pci->dev, "***SET PIPE STATE*** TIME = %ld (err = %x)\n",
960 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err); 965 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
961#endif 966#endif
962 return 0; 967 return 0;
@@ -971,7 +976,8 @@ int pcxhr_write_io_num_reg_cont(struct pcxhr_mgr *mgr, unsigned int mask,
971 976
972 spin_lock_irqsave(&mgr->msg_lock, flags); 977 spin_lock_irqsave(&mgr->msg_lock, flags);
973 if ((mgr->io_num_reg_cont & mask) == value) { 978 if ((mgr->io_num_reg_cont & mask) == value) {
974 snd_printdd("IO_NUM_REG_CONT mask %x already is set to %x\n", 979 dev_dbg(&mgr->pci->dev,
980 "IO_NUM_REG_CONT mask %x already is set to %x\n",
975 mask, value); 981 mask, value);
976 if (changed) 982 if (changed)
977 *changed = 0; 983 *changed = 0;
@@ -1024,7 +1030,7 @@ static int pcxhr_handle_async_err(struct pcxhr_mgr *mgr, u32 err,
1024 err = ((err >> 12) & 0xfff); 1030 err = ((err >> 12) & 0xfff);
1025 if (!err) 1031 if (!err)
1026 return 0; 1032 return 0;
1027 snd_printdd("CMD_ASYNC : Error %s %s Pipe %d err=%x\n", 1033 dev_dbg(&mgr->pci->dev, "CMD_ASYNC : Error %s %s Pipe %d err=%x\n",
1028 err_src_name[err_src], 1034 err_src_name[err_src],
1029 is_capture ? "Record" : "Play", pipe, err); 1035 is_capture ? "Record" : "Play", pipe, err);
1030 if (err == 0xe01) 1036 if (err == 0xe01)
@@ -1045,20 +1051,24 @@ void pcxhr_msg_tasklet(unsigned long arg)
1045 int i, j; 1051 int i, j;
1046 1052
1047 if (mgr->src_it_dsp & PCXHR_IRQ_FREQ_CHANGE) 1053 if (mgr->src_it_dsp & PCXHR_IRQ_FREQ_CHANGE)
1048 snd_printdd("TASKLET : PCXHR_IRQ_FREQ_CHANGE event occurred\n"); 1054 dev_dbg(&mgr->pci->dev,
1055 "TASKLET : PCXHR_IRQ_FREQ_CHANGE event occurred\n");
1049 if (mgr->src_it_dsp & PCXHR_IRQ_TIME_CODE) 1056 if (mgr->src_it_dsp & PCXHR_IRQ_TIME_CODE)
1050 snd_printdd("TASKLET : PCXHR_IRQ_TIME_CODE event occurred\n"); 1057 dev_dbg(&mgr->pci->dev,
1058 "TASKLET : PCXHR_IRQ_TIME_CODE event occurred\n");
1051 if (mgr->src_it_dsp & PCXHR_IRQ_NOTIFY) 1059 if (mgr->src_it_dsp & PCXHR_IRQ_NOTIFY)
1052 snd_printdd("TASKLET : PCXHR_IRQ_NOTIFY event occurred\n"); 1060 dev_dbg(&mgr->pci->dev,
1061 "TASKLET : PCXHR_IRQ_NOTIFY event occurred\n");
1053 if (mgr->src_it_dsp & (PCXHR_IRQ_FREQ_CHANGE | PCXHR_IRQ_TIME_CODE)) { 1062 if (mgr->src_it_dsp & (PCXHR_IRQ_FREQ_CHANGE | PCXHR_IRQ_TIME_CODE)) {
1054 /* clear events FREQ_CHANGE and TIME_CODE */ 1063 /* clear events FREQ_CHANGE and TIME_CODE */
1055 pcxhr_init_rmh(prmh, CMD_TEST_IT); 1064 pcxhr_init_rmh(prmh, CMD_TEST_IT);
1056 err = pcxhr_send_msg(mgr, prmh); 1065 err = pcxhr_send_msg(mgr, prmh);
1057 snd_printdd("CMD_TEST_IT : err=%x, stat=%x\n", 1066 dev_dbg(&mgr->pci->dev, "CMD_TEST_IT : err=%x, stat=%x\n",
1058 err, prmh->stat[0]); 1067 err, prmh->stat[0]);
1059 } 1068 }
1060 if (mgr->src_it_dsp & PCXHR_IRQ_ASYNC) { 1069 if (mgr->src_it_dsp & PCXHR_IRQ_ASYNC) {
1061 snd_printdd("TASKLET : PCXHR_IRQ_ASYNC event occurred\n"); 1070 dev_dbg(&mgr->pci->dev,
1071 "TASKLET : PCXHR_IRQ_ASYNC event occurred\n");
1062 1072
1063 pcxhr_init_rmh(prmh, CMD_ASYNC); 1073 pcxhr_init_rmh(prmh, CMD_ASYNC);
1064 prmh->cmd[0] |= 1; /* add SEL_ASYNC_EVENTS */ 1074 prmh->cmd[0] |= 1; /* add SEL_ASYNC_EVENTS */
@@ -1066,7 +1076,7 @@ void pcxhr_msg_tasklet(unsigned long arg)
1066 prmh->stat_len = PCXHR_SIZE_MAX_LONG_STATUS; 1076 prmh->stat_len = PCXHR_SIZE_MAX_LONG_STATUS;
1067 err = pcxhr_send_msg(mgr, prmh); 1077 err = pcxhr_send_msg(mgr, prmh);
1068 if (err) 1078 if (err)
1069 snd_printk(KERN_ERR "ERROR pcxhr_msg_tasklet=%x;\n", 1079 dev_err(&mgr->pci->dev, "ERROR pcxhr_msg_tasklet=%x;\n",
1070 err); 1080 err);
1071 i = 1; 1081 i = 1;
1072 while (i < prmh->stat_len) { 1082 while (i < prmh->stat_len) {
@@ -1079,7 +1089,8 @@ void pcxhr_msg_tasklet(unsigned long arg)
1079 u32 err2; 1089 u32 err2;
1080 1090
1081 if (prmh->stat[i] & 0x800000) { /* if BIT_END */ 1091 if (prmh->stat[i] & 0x800000) { /* if BIT_END */
1082 snd_printdd("TASKLET : End%sPipe %d\n", 1092 dev_dbg(&mgr->pci->dev,
1093 "TASKLET : End%sPipe %d\n",
1083 is_capture ? "Record" : "Play", 1094 is_capture ? "Record" : "Play",
1084 pipe); 1095 pipe);
1085 } 1096 }
@@ -1136,7 +1147,8 @@ static u_int64_t pcxhr_stream_read_position(struct pcxhr_mgr *mgr,
1136 hw_sample_count = ((u_int64_t)rmh.stat[0]) << 24; 1147 hw_sample_count = ((u_int64_t)rmh.stat[0]) << 24;
1137 hw_sample_count += (u_int64_t)rmh.stat[1]; 1148 hw_sample_count += (u_int64_t)rmh.stat[1];
1138 1149
1139 snd_printdd("stream %c%d : abs samples real(%llu) timer(%llu)\n", 1150 dev_dbg(&mgr->pci->dev,
1151 "stream %c%d : abs samples real(%llu) timer(%llu)\n",
1140 stream->pipe->is_capture ? 'C' : 'P', 1152 stream->pipe->is_capture ? 'C' : 'P',
1141 stream->substream->number, 1153 stream->substream->number,
1142 hw_sample_count, 1154 hw_sample_count,
@@ -1202,7 +1214,7 @@ static void pcxhr_update_timer_pos(struct pcxhr_mgr *mgr,
1202 (u_int32_t)(new_sample_count - 1214 (u_int32_t)(new_sample_count -
1203 stream->timer_abs_periods); 1215 stream->timer_abs_periods);
1204 } else { 1216 } else {
1205 snd_printk(KERN_ERR 1217 dev_err(&mgr->pci->dev,
1206 "ERROR new_sample_count too small ??? %ld\n", 1218 "ERROR new_sample_count too small ??? %ld\n",
1207 (long unsigned int)new_sample_count); 1219 (long unsigned int)new_sample_count);
1208 } 1220 }
@@ -1247,33 +1259,39 @@ irqreturn_t pcxhr_interrupt(int irq, void *dev_id)
1247 (mgr->dsp_time_last != PCXHR_DSP_TIME_INVALID)) { 1259 (mgr->dsp_time_last != PCXHR_DSP_TIME_INVALID)) {
1248 /* handle dsp counter wraparound without resync */ 1260 /* handle dsp counter wraparound without resync */
1249 int tmp_diff = dsp_time_diff + PCXHR_DSP_TIME_MASK + 1; 1261 int tmp_diff = dsp_time_diff + PCXHR_DSP_TIME_MASK + 1;
1250 snd_printdd("WARNING DSP timestamp old(%d) new(%d)", 1262 dev_dbg(&mgr->pci->dev,
1263 "WARNING DSP timestamp old(%d) new(%d)",
1251 mgr->dsp_time_last, dsp_time_new); 1264 mgr->dsp_time_last, dsp_time_new);
1252 if (tmp_diff > 0 && tmp_diff <= (2*mgr->granularity)) { 1265 if (tmp_diff > 0 && tmp_diff <= (2*mgr->granularity)) {
1253 snd_printdd("-> timestamp wraparound OK: " 1266 dev_dbg(&mgr->pci->dev,
1267 "-> timestamp wraparound OK: "
1254 "diff=%d\n", tmp_diff); 1268 "diff=%d\n", tmp_diff);
1255 dsp_time_diff = tmp_diff; 1269 dsp_time_diff = tmp_diff;
1256 } else { 1270 } else {
1257 snd_printdd("-> resynchronize all streams\n"); 1271 dev_dbg(&mgr->pci->dev,
1272 "-> resynchronize all streams\n");
1258 mgr->dsp_time_err++; 1273 mgr->dsp_time_err++;
1259 } 1274 }
1260 } 1275 }
1261#ifdef CONFIG_SND_DEBUG_VERBOSE 1276#ifdef CONFIG_SND_DEBUG_VERBOSE
1262 if (dsp_time_diff == 0) 1277 if (dsp_time_diff == 0)
1263 snd_printdd("ERROR DSP TIME NO DIFF time(%d)\n", 1278 dev_dbg(&mgr->pci->dev,
1279 "ERROR DSP TIME NO DIFF time(%d)\n",
1264 dsp_time_new); 1280 dsp_time_new);
1265 else if (dsp_time_diff >= (2*mgr->granularity)) 1281 else if (dsp_time_diff >= (2*mgr->granularity))
1266 snd_printdd("ERROR DSP TIME TOO BIG old(%d) add(%d)\n", 1282 dev_dbg(&mgr->pci->dev,
1283 "ERROR DSP TIME TOO BIG old(%d) add(%d)\n",
1267 mgr->dsp_time_last, 1284 mgr->dsp_time_last,
1268 dsp_time_new - mgr->dsp_time_last); 1285 dsp_time_new - mgr->dsp_time_last);
1269 else if (dsp_time_diff % mgr->granularity) 1286 else if (dsp_time_diff % mgr->granularity)
1270 snd_printdd("ERROR DSP TIME increased by %d\n", 1287 dev_dbg(&mgr->pci->dev,
1288 "ERROR DSP TIME increased by %d\n",
1271 dsp_time_diff); 1289 dsp_time_diff);
1272#endif 1290#endif
1273 mgr->dsp_time_last = dsp_time_new; 1291 mgr->dsp_time_last = dsp_time_new;
1274 1292
1275 if (timer_toggle == mgr->timer_toggle) { 1293 if (timer_toggle == mgr->timer_toggle) {
1276 snd_printdd("ERROR TIMER TOGGLE\n"); 1294 dev_dbg(&mgr->pci->dev, "ERROR TIMER TOGGLE\n");
1277 mgr->dsp_time_err++; 1295 mgr->dsp_time_err++;
1278 } 1296 }
1279 mgr->timer_toggle = timer_toggle; 1297 mgr->timer_toggle = timer_toggle;
@@ -1308,7 +1326,7 @@ irqreturn_t pcxhr_interrupt(int irq, void *dev_id)
1308 } 1326 }
1309#ifdef CONFIG_SND_DEBUG_VERBOSE 1327#ifdef CONFIG_SND_DEBUG_VERBOSE
1310 if (reg & PCXHR_FATAL_DSP_ERR) 1328 if (reg & PCXHR_FATAL_DSP_ERR)
1311 snd_printdd("FATAL DSP ERROR : %x\n", reg); 1329 dev_dbg(&mgr->pci->dev, "FATAL DSP ERROR : %x\n", reg);
1312#endif 1330#endif
1313 spin_unlock(&mgr->lock); 1331 spin_unlock(&mgr->lock);
1314 return IRQ_HANDLED; /* this device caused the interrupt */ 1332 return IRQ_HANDLED; /* this device caused the interrupt */
diff --git a/sound/pci/pcxhr/pcxhr_hwdep.c b/sound/pci/pcxhr/pcxhr_hwdep.c
index d995175c1c48..15a8ce5f1f48 100644
--- a/sound/pci/pcxhr/pcxhr_hwdep.c
+++ b/sound/pci/pcxhr/pcxhr_hwdep.c
@@ -72,7 +72,8 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr)
72 /* test max nb substream per pipe */ 72 /* test max nb substream per pipe */
73 if (((rmh.stat[1] >> 7) & 0x5F) < PCXHR_PLAYBACK_STREAMS) 73 if (((rmh.stat[1] >> 7) & 0x5F) < PCXHR_PLAYBACK_STREAMS)
74 return -EINVAL; 74 return -EINVAL;
75 snd_printdd("supported formats : playback=%x capture=%x\n", 75 dev_dbg(&mgr->pci->dev,
76 "supported formats : playback=%x capture=%x\n",
76 rmh.stat[2], rmh.stat[3]); 77 rmh.stat[2], rmh.stat[3]);
77 78
78 pcxhr_init_rmh(&rmh, CMD_VERSION); 79 pcxhr_init_rmh(&rmh, CMD_VERSION);
@@ -84,7 +85,8 @@ static int pcxhr_init_board(struct pcxhr_mgr *mgr)
84 err = pcxhr_send_msg(mgr, &rmh); 85 err = pcxhr_send_msg(mgr, &rmh);
85 if (err) 86 if (err)
86 return err; 87 return err;
87 snd_printdd("PCXHR DSP version is %d.%d.%d\n", (rmh.stat[0]>>16)&0xff, 88 dev_dbg(&mgr->pci->dev,
89 "PCXHR DSP version is %d.%d.%d\n", (rmh.stat[0]>>16)&0xff,
88 (rmh.stat[0]>>8)&0xff, rmh.stat[0]&0xff); 90 (rmh.stat[0]>>8)&0xff, rmh.stat[0]&0xff);
89 mgr->dsp_version = rmh.stat[0]; 91 mgr->dsp_version = rmh.stat[0];
90 92
@@ -179,7 +181,7 @@ static int pcxhr_dsp_allocate_pipe(struct pcxhr_mgr *mgr,
179 stream_count = PCXHR_PLAYBACK_STREAMS; 181 stream_count = PCXHR_PLAYBACK_STREAMS;
180 audio_count = 2; /* always stereo */ 182 audio_count = 2; /* always stereo */
181 } 183 }
182 snd_printdd("snd_add_ref_pipe pin(%d) pcm%c0\n", 184 dev_dbg(&mgr->pci->dev, "snd_add_ref_pipe pin(%d) pcm%c0\n",
183 pin, is_capture ? 'c' : 'p'); 185 pin, is_capture ? 'c' : 'p');
184 pipe->is_capture = is_capture; 186 pipe->is_capture = is_capture;
185 pipe->first_audio = pin; 187 pipe->first_audio = pin;
@@ -194,7 +196,7 @@ static int pcxhr_dsp_allocate_pipe(struct pcxhr_mgr *mgr,
194 } 196 }
195 err = pcxhr_send_msg(mgr, &rmh); 197 err = pcxhr_send_msg(mgr, &rmh);
196 if (err < 0) { 198 if (err < 0) {
197 snd_printk(KERN_ERR "error pipe allocation " 199 dev_err(&mgr->pci->dev, "error pipe allocation "
198 "(CMD_RES_PIPE) err=%x!\n", err); 200 "(CMD_RES_PIPE) err=%x!\n", err);
199 return err; 201 return err;
200 } 202 }
@@ -222,14 +224,14 @@ static int pcxhr_dsp_free_pipe( struct pcxhr_mgr *mgr, struct pcxhr_pipe *pipe)
222 /* stop one pipe */ 224 /* stop one pipe */
223 err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 0); 225 err = pcxhr_set_pipe_state(mgr, playback_mask, capture_mask, 0);
224 if (err < 0) 226 if (err < 0)
225 snd_printk(KERN_ERR "error stopping pipe!\n"); 227 dev_err(&mgr->pci->dev, "error stopping pipe!\n");
226 /* release the pipe */ 228 /* release the pipe */
227 pcxhr_init_rmh(&rmh, CMD_FREE_PIPE); 229 pcxhr_init_rmh(&rmh, CMD_FREE_PIPE);
228 pcxhr_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->first_audio, 230 pcxhr_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->first_audio,
229 0, 0); 231 0, 0);
230 err = pcxhr_send_msg(mgr, &rmh); 232 err = pcxhr_send_msg(mgr, &rmh);
231 if (err < 0) 233 if (err < 0)
232 snd_printk(KERN_ERR "error pipe release " 234 dev_err(&mgr->pci->dev, "error pipe release "
233 "(CMD_FREE_PIPE) err(%x)\n", err); 235 "(CMD_FREE_PIPE) err(%x)\n", err);
234 pipe->status = PCXHR_PIPE_UNDEFINED; 236 pipe->status = PCXHR_PIPE_UNDEFINED;
235 return err; 237 return err;
@@ -289,7 +291,8 @@ static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index,
289{ 291{
290 int err, card_index; 292 int err, card_index;
291 293
292 snd_printdd("loading dsp [%d] size = %Zd\n", index, dsp->size); 294 dev_dbg(&mgr->pci->dev,
295 "loading dsp [%d] size = %Zd\n", index, dsp->size);
293 296
294 switch (index) { 297 switch (index) {
295 case PCXHR_FIRMWARE_XLX_INT_INDEX: 298 case PCXHR_FIRMWARE_XLX_INT_INDEX:
@@ -313,19 +316,19 @@ static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index,
313 return err; 316 return err;
314 break; /* continue with first init */ 317 break; /* continue with first init */
315 default: 318 default:
316 snd_printk(KERN_ERR "wrong file index\n"); 319 dev_err(&mgr->pci->dev, "wrong file index\n");
317 return -EFAULT; 320 return -EFAULT;
318 } /* end of switch file index*/ 321 } /* end of switch file index*/
319 322
320 /* first communication with embedded */ 323 /* first communication with embedded */
321 err = pcxhr_init_board(mgr); 324 err = pcxhr_init_board(mgr);
322 if (err < 0) { 325 if (err < 0) {
323 snd_printk(KERN_ERR "pcxhr could not be set up\n"); 326 dev_err(&mgr->pci->dev, "pcxhr could not be set up\n");
324 return err; 327 return err;
325 } 328 }
326 err = pcxhr_config_pipes(mgr); 329 err = pcxhr_config_pipes(mgr);
327 if (err < 0) { 330 if (err < 0) {
328 snd_printk(KERN_ERR "pcxhr pipes could not be set up\n"); 331 dev_err(&mgr->pci->dev, "pcxhr pipes could not be set up\n");
329 return err; 332 return err;
330 } 333 }
331 /* create devices and mixer in accordance with HW options*/ 334 /* create devices and mixer in accordance with HW options*/
@@ -344,10 +347,11 @@ static int pcxhr_dsp_load(struct pcxhr_mgr *mgr, int index,
344 } 347 }
345 err = pcxhr_start_pipes(mgr); 348 err = pcxhr_start_pipes(mgr);
346 if (err < 0) { 349 if (err < 0) {
347 snd_printk(KERN_ERR "pcxhr pipes could not be started\n"); 350 dev_err(&mgr->pci->dev, "pcxhr pipes could not be started\n");
348 return err; 351 return err;
349 } 352 }
350 snd_printdd("pcxhr firmware downloaded and successfully set up\n"); 353 dev_dbg(&mgr->pci->dev,
354 "pcxhr firmware downloaded and successfully set up\n");
351 355
352 return 0; 356 return 0;
353} 357}
@@ -382,7 +386,8 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
382 continue; 386 continue;
383 sprintf(path, "pcxhr/%s", fw_files[fw_set][i]); 387 sprintf(path, "pcxhr/%s", fw_files[fw_set][i]);
384 if (request_firmware(&fw_entry, path, &mgr->pci->dev)) { 388 if (request_firmware(&fw_entry, path, &mgr->pci->dev)) {
385 snd_printk(KERN_ERR "pcxhr: can't load firmware %s\n", 389 dev_err(&mgr->pci->dev,
390 "pcxhr: can't load firmware %s\n",
386 path); 391 path);
387 return -ENOENT; 392 return -ENOENT;
388 } 393 }
diff --git a/sound/pci/pcxhr/pcxhr_mix22.c b/sound/pci/pcxhr/pcxhr_mix22.c
index 84fe57626eba..6a56e5306a65 100644
--- a/sound/pci/pcxhr/pcxhr_mix22.c
+++ b/sound/pci/pcxhr/pcxhr_mix22.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/pci.h>
25#include <sound/core.h> 26#include <sound/core.h>
26#include <sound/control.h> 27#include <sound/control.h>
27#include <sound/tlv.h> 28#include <sound/tlv.h>
@@ -290,7 +291,8 @@ int hr222_sub_init(struct pcxhr_mgr *mgr)
290 reg = PCXHR_INPB(mgr, PCXHR_XLX_STATUS); 291 reg = PCXHR_INPB(mgr, PCXHR_XLX_STATUS);
291 if (reg & PCXHR_STAT_MIC_CAPS) 292 if (reg & PCXHR_STAT_MIC_CAPS)
292 mgr->board_has_mic = 1; /* microphone available */ 293 mgr->board_has_mic = 1; /* microphone available */
293 snd_printdd("MIC input available = %d\n", mgr->board_has_mic); 294 dev_dbg(&mgr->pci->dev,
295 "MIC input available = %d\n", mgr->board_has_mic);
294 296
295 /* reset codec */ 297 /* reset codec */
296 PCXHR_OUTPB(mgr, PCXHR_DSP_RESET, 298 PCXHR_OUTPB(mgr, PCXHR_DSP_RESET,
@@ -405,7 +407,7 @@ int hr222_sub_set_clock(struct pcxhr_mgr *mgr,
405 407
406 hr222_config_akm(mgr, AKM_UNMUTE_CMD); 408 hr222_config_akm(mgr, AKM_UNMUTE_CMD);
407 409
408 snd_printdd("set_clock to %dHz (realfreq=%d pllreg=%x)\n", 410 dev_dbg(&mgr->pci->dev, "set_clock to %dHz (realfreq=%d pllreg=%x)\n",
409 rate, realfreq, pllreg); 411 rate, realfreq, pllreg);
410 return 0; 412 return 0;
411} 413}
@@ -431,13 +433,15 @@ int hr222_get_external_clock(struct pcxhr_mgr *mgr,
431 reg = PCXHR_STAT_FREQ_UER1_MASK; 433 reg = PCXHR_STAT_FREQ_UER1_MASK;
432 434
433 } else { 435 } else {
434 snd_printdd("get_external_clock : type %d not supported\n", 436 dev_dbg(&mgr->pci->dev,
437 "get_external_clock : type %d not supported\n",
435 clock_type); 438 clock_type);
436 return -EINVAL; /* other clocks not supported */ 439 return -EINVAL; /* other clocks not supported */
437 } 440 }
438 441
439 if ((PCXHR_INPB(mgr, PCXHR_XLX_CSUER) & mask) != mask) { 442 if ((PCXHR_INPB(mgr, PCXHR_XLX_CSUER) & mask) != mask) {
440 snd_printdd("get_external_clock(%d) = 0 Hz\n", clock_type); 443 dev_dbg(&mgr->pci->dev,
444 "get_external_clock(%d) = 0 Hz\n", clock_type);
441 *sample_rate = 0; 445 *sample_rate = 0;
442 return 0; /* no external clock locked */ 446 return 0; /* no external clock locked */
443 } 447 }
@@ -495,7 +499,7 @@ int hr222_get_external_clock(struct pcxhr_mgr *mgr,
495 else 499 else
496 rate = 0; 500 rate = 0;
497 501
498 snd_printdd("External clock is at %d Hz (measured %d Hz)\n", 502 dev_dbg(&mgr->pci->dev, "External clock is at %d Hz (measured %d Hz)\n",
499 rate, calc_rate); 503 rate, calc_rate);
500 *sample_rate = rate; 504 *sample_rate = rate;
501 return 0; 505 return 0;
@@ -542,7 +546,8 @@ int hr222_manage_timecode(struct pcxhr_mgr *mgr, int enable)
542int hr222_update_analog_audio_level(struct snd_pcxhr *chip, 546int hr222_update_analog_audio_level(struct snd_pcxhr *chip,
543 int is_capture, int channel) 547 int is_capture, int channel)
544{ 548{
545 snd_printdd("hr222_update_analog_audio_level(%s chan=%d)\n", 549 dev_dbg(chip->card->dev,
550 "hr222_update_analog_audio_level(%s chan=%d)\n",
546 is_capture ? "capture" : "playback", channel); 551 is_capture ? "capture" : "playback", channel);
547 if (is_capture) { 552 if (is_capture) {
548 int level_l, level_r, level_mic; 553 int level_l, level_r, level_mic;
@@ -642,7 +647,7 @@ int hr222_iec958_capture_byte(struct snd_pcxhr *chip,
642 if (PCXHR_INPB(chip->mgr, PCXHR_XLX_CSUER) & mask) 647 if (PCXHR_INPB(chip->mgr, PCXHR_XLX_CSUER) & mask)
643 temp |= 1; 648 temp |= 1;
644 } 649 }
645 snd_printdd("read iec958 AES %d byte %d = 0x%x\n", 650 dev_dbg(chip->card->dev, "read iec958 AES %d byte %d = 0x%x\n",
646 chip->chip_idx, aes_idx, temp); 651 chip->chip_idx, aes_idx, temp);
647 *aes_bits = temp; 652 *aes_bits = temp;
648 return 0; 653 return 0;
@@ -684,7 +689,7 @@ static void hr222_micro_boost(struct pcxhr_mgr *mgr, int level)
684 689
685 PCXHR_OUTPB(mgr, PCXHR_XLX_SELMIC, mgr->xlx_selmic); 690 PCXHR_OUTPB(mgr, PCXHR_XLX_SELMIC, mgr->xlx_selmic);
686 691
687 snd_printdd("hr222_micro_boost : set %x\n", boost_mask); 692 dev_dbg(&mgr->pci->dev, "hr222_micro_boost : set %x\n", boost_mask);
688} 693}
689 694
690static void hr222_phantom_power(struct pcxhr_mgr *mgr, int power) 695static void hr222_phantom_power(struct pcxhr_mgr *mgr, int power)
@@ -696,7 +701,7 @@ static void hr222_phantom_power(struct pcxhr_mgr *mgr, int power)
696 701
697 PCXHR_OUTPB(mgr, PCXHR_XLX_SELMIC, mgr->xlx_selmic); 702 PCXHR_OUTPB(mgr, PCXHR_XLX_SELMIC, mgr->xlx_selmic);
698 703
699 snd_printdd("hr222_phantom_power : set %d\n", power); 704 dev_dbg(&mgr->pci->dev, "hr222_phantom_power : set %d\n", power);
700} 705}
701 706
702 707
diff --git a/sound/pci/pcxhr/pcxhr_mixer.c b/sound/pci/pcxhr/pcxhr_mixer.c
index fec049344621..95c9571780d8 100644
--- a/sound/pci/pcxhr/pcxhr_mixer.c
+++ b/sound/pci/pcxhr/pcxhr_mixer.c
@@ -72,7 +72,8 @@ static int pcxhr_update_analog_audio_level(struct snd_pcxhr *chip,
72 rmh.cmd_len = 3; 72 rmh.cmd_len = 3;
73 err = pcxhr_send_msg(chip->mgr, &rmh); 73 err = pcxhr_send_msg(chip->mgr, &rmh);
74 if (err < 0) { 74 if (err < 0) {
75 snd_printk(KERN_DEBUG "error update_analog_audio_level card(%d)" 75 dev_dbg(chip->card->dev,
76 "error update_analog_audio_level card(%d)"
76 " is_capture(%d) err(%x)\n", 77 " is_capture(%d) err(%x)\n",
77 chip->chip_idx, is_capture, err); 78 chip->chip_idx, is_capture, err);
78 return -EINVAL; 79 return -EINVAL;
@@ -284,7 +285,7 @@ static int pcxhr_update_playback_stream_level(struct snd_pcxhr* chip, int idx)
284 285
285 err = pcxhr_send_msg(chip->mgr, &rmh); 286 err = pcxhr_send_msg(chip->mgr, &rmh);
286 if (err < 0) { 287 if (err < 0) {
287 snd_printk(KERN_DEBUG "error update_playback_stream_level " 288 dev_dbg(chip->card->dev, "error update_playback_stream_level "
288 "card(%d) err(%x)\n", chip->chip_idx, err); 289 "card(%d) err(%x)\n", chip->chip_idx, err);
289 return -EINVAL; 290 return -EINVAL;
290 } 291 }
@@ -335,7 +336,8 @@ static int pcxhr_update_audio_pipe_level(struct snd_pcxhr *chip,
335 336
336 err = pcxhr_send_msg(chip->mgr, &rmh); 337 err = pcxhr_send_msg(chip->mgr, &rmh);
337 if (err < 0) { 338 if (err < 0) {
338 snd_printk(KERN_DEBUG "error update_audio_level(%d) err=%x\n", 339 dev_dbg(chip->card->dev,
340 "error update_audio_level(%d) err=%x\n",
339 chip->chip_idx, err); 341 chip->chip_idx, err);
340 return -EINVAL; 342 return -EINVAL;
341 } 343 }
@@ -930,7 +932,7 @@ static int pcxhr_iec958_capture_byte(struct snd_pcxhr *chip,
930 temp |= 1; 932 temp |= 1;
931 } 933 }
932 } 934 }
933 snd_printdd("read iec958 AES %d byte %d = 0x%x\n", 935 dev_dbg(chip->card->dev, "read iec958 AES %d byte %d = 0x%x\n",
934 chip->chip_idx, aes_idx, temp); 936 chip->chip_idx, aes_idx, temp);
935 *aes_bits = temp; 937 *aes_bits = temp;
936 return 0; 938 return 0;
@@ -992,7 +994,8 @@ static int pcxhr_iec958_update_byte(struct snd_pcxhr *chip,
992 rmh.cmd[0] |= IO_NUM_REG_CUER; 994 rmh.cmd[0] |= IO_NUM_REG_CUER;
993 rmh.cmd[1] = cmd; 995 rmh.cmd[1] = cmd;
994 rmh.cmd_len = 2; 996 rmh.cmd_len = 2;
995 snd_printdd("write iec958 AES %d byte %d bit %d (cmd %x)\n", 997 dev_dbg(chip->card->dev,
998 "write iec958 AES %d byte %d bit %d (cmd %x)\n",
996 chip->chip_idx, aes_idx, i, cmd); 999 chip->chip_idx, aes_idx, i, cmd);
997 err = pcxhr_send_msg(chip->mgr, &rmh); 1000 err = pcxhr_send_msg(chip->mgr, &rmh);
998 if (err) 1001 if (err)
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index 56cc891e395e..b4a8278241b1 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -1916,8 +1916,6 @@ snd_riptide_create(struct snd_card *card, struct pci_dev *pci,
1916 return err; 1916 return err;
1917 } 1917 }
1918 1918
1919 snd_card_set_dev(card, &pci->dev);
1920
1921 *rchip = chip; 1919 *rchip = chip;
1922 return 0; 1920 return 0;
1923} 1921}
@@ -2086,7 +2084,8 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2086 return -ENOENT; 2084 return -ENOENT;
2087 } 2085 }
2088 2086
2089 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2087 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2088 0, &card);
2090 if (err < 0) 2089 if (err < 0)
2091 return err; 2090 return err;
2092 err = snd_riptide_create(card, pci, &chip); 2091 err = snd_riptide_create(card, pci, &chip);
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index cc26346ae66b..cc2f0c1b6484 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -1349,14 +1349,15 @@ static int snd_rme32_create(struct rme32 *rme32)
1349 1349
1350 rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE); 1350 rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE);
1351 if (!rme32->iobase) { 1351 if (!rme32->iobase) {
1352 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", 1352 dev_err(rme32->card->dev,
1353 "unable to remap memory region 0x%lx-0x%lx\n",
1353 rme32->port, rme32->port + RME32_IO_SIZE - 1); 1354 rme32->port, rme32->port + RME32_IO_SIZE - 1);
1354 return -ENOMEM; 1355 return -ENOMEM;
1355 } 1356 }
1356 1357
1357 if (request_irq(pci->irq, snd_rme32_interrupt, IRQF_SHARED, 1358 if (request_irq(pci->irq, snd_rme32_interrupt, IRQF_SHARED,
1358 KBUILD_MODNAME, rme32)) { 1359 KBUILD_MODNAME, rme32)) {
1359 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1360 dev_err(rme32->card->dev, "unable to grab IRQ %d\n", pci->irq);
1360 return -EBUSY; 1361 return -EBUSY;
1361 } 1362 }
1362 rme32->irq = pci->irq; 1363 rme32->irq = pci->irq;
@@ -1938,15 +1939,14 @@ snd_rme32_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1938 return -ENOENT; 1939 return -ENOENT;
1939 } 1940 }
1940 1941
1941 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 1942 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1942 sizeof(struct rme32), &card); 1943 sizeof(struct rme32), &card);
1943 if (err < 0) 1944 if (err < 0)
1944 return err; 1945 return err;
1945 card->private_free = snd_rme32_card_free; 1946 card->private_free = snd_rme32_card_free;
1946 rme32 = (struct rme32 *) card->private_data; 1947 rme32 = (struct rme32 *) card->private_data;
1947 rme32->card = card; 1948 rme32->card = card;
1948 rme32->pci = pci; 1949 rme32->pci = pci;
1949 snd_card_set_dev(card, &pci->dev);
1950 if (fullduplex[dev]) 1950 if (fullduplex[dev])
1951 rme32->fullduplex_mode = 1; 1951 rme32->fullduplex_mode = 1;
1952 if ((err = snd_rme32_create(rme32)) < 0) { 1952 if ((err = snd_rme32_create(rme32)) < 0) {
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index 0236363c301f..76169929770d 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -240,7 +240,7 @@ struct rme96 {
240 240
241 u8 rev; /* card revision number */ 241 u8 rev; /* card revision number */
242 242
243#ifdef CONFIG_PM 243#ifdef CONFIG_PM_SLEEP
244 u32 playback_pointer; 244 u32 playback_pointer;
245 u32 capture_pointer; 245 u32 capture_pointer;
246 void *playback_suspend_buffer; 246 void *playback_suspend_buffer;
@@ -1570,7 +1570,7 @@ snd_rme96_free(void *private_data)
1570 pci_release_regions(rme96->pci); 1570 pci_release_regions(rme96->pci);
1571 rme96->port = 0; 1571 rme96->port = 0;
1572 } 1572 }
1573#ifdef CONFIG_PM 1573#ifdef CONFIG_PM_SLEEP
1574 vfree(rme96->playback_suspend_buffer); 1574 vfree(rme96->playback_suspend_buffer);
1575 vfree(rme96->capture_suspend_buffer); 1575 vfree(rme96->capture_suspend_buffer);
1576#endif 1576#endif
@@ -1609,13 +1609,15 @@ snd_rme96_create(struct rme96 *rme96)
1609 1609
1610 rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE); 1610 rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE);
1611 if (!rme96->iobase) { 1611 if (!rme96->iobase) {
1612 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1); 1612 dev_err(rme96->card->dev,
1613 "unable to remap memory region 0x%lx-0x%lx\n",
1614 rme96->port, rme96->port + RME96_IO_SIZE - 1);
1613 return -ENOMEM; 1615 return -ENOMEM;
1614 } 1616 }
1615 1617
1616 if (request_irq(pci->irq, snd_rme96_interrupt, IRQF_SHARED, 1618 if (request_irq(pci->irq, snd_rme96_interrupt, IRQF_SHARED,
1617 KBUILD_MODNAME, rme96)) { 1619 KBUILD_MODNAME, rme96)) {
1618 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1620 dev_err(rme96->card->dev, "unable to grab IRQ %d\n", pci->irq);
1619 return -EBUSY; 1621 return -EBUSY;
1620 } 1622 }
1621 rme96->irq = pci->irq; 1623 rme96->irq = pci->irq;
@@ -2372,13 +2374,12 @@ snd_rme96_create_switches(struct snd_card *card,
2372 * Card initialisation 2374 * Card initialisation
2373 */ 2375 */
2374 2376
2375#ifdef CONFIG_PM 2377#ifdef CONFIG_PM_SLEEP
2376 2378
2377static int 2379static int rme96_suspend(struct device *dev)
2378snd_rme96_suspend(struct pci_dev *pci,
2379 pm_message_t state)
2380{ 2380{
2381 struct snd_card *card = pci_get_drvdata(pci); 2381 struct pci_dev *pci = to_pci_dev(dev);
2382 struct snd_card *card = dev_get_drvdata(dev);
2382 struct rme96 *rme96 = card->private_data; 2383 struct rme96 *rme96 = card->private_data;
2383 2384
2384 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 2385 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
@@ -2407,15 +2408,15 @@ snd_rme96_suspend(struct pci_dev *pci,
2407 return 0; 2408 return 0;
2408} 2409}
2409 2410
2410static int 2411static int rme96_resume(struct device *dev)
2411snd_rme96_resume(struct pci_dev *pci)
2412{ 2412{
2413 struct snd_card *card = pci_get_drvdata(pci); 2413 struct pci_dev *pci = to_pci_dev(dev);
2414 struct snd_card *card = dev_get_drvdata(dev);
2414 struct rme96 *rme96 = card->private_data; 2415 struct rme96 *rme96 = card->private_data;
2415 2416
2416 pci_restore_state(pci); 2417 pci_restore_state(pci);
2417 if (pci_enable_device(pci) < 0) { 2418 if (pci_enable_device(pci) < 0) {
2418 printk(KERN_ERR "rme96: pci_enable_device failed, disabling device\n"); 2419 dev_err(dev, "pci_enable_device failed, disabling device\n");
2419 snd_card_disconnect(card); 2420 snd_card_disconnect(card);
2420 return -EIO; 2421 return -EIO;
2421 } 2422 }
@@ -2451,7 +2452,11 @@ snd_rme96_resume(struct pci_dev *pci)
2451 return 0; 2452 return 0;
2452} 2453}
2453 2454
2454#endif 2455static SIMPLE_DEV_PM_OPS(rme96_pm, rme96_suspend, rme96_resume);
2456#define RME96_PM_OPS &rme96_pm
2457#else
2458#define RME96_PM_OPS NULL
2459#endif /* CONFIG_PM_SLEEP */
2455 2460
2456static void snd_rme96_card_free(struct snd_card *card) 2461static void snd_rme96_card_free(struct snd_card *card)
2457{ 2462{
@@ -2475,31 +2480,30 @@ snd_rme96_probe(struct pci_dev *pci,
2475 dev++; 2480 dev++;
2476 return -ENOENT; 2481 return -ENOENT;
2477 } 2482 }
2478 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 2483 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2479 sizeof(struct rme96), &card); 2484 sizeof(struct rme96), &card);
2480 if (err < 0) 2485 if (err < 0)
2481 return err; 2486 return err;
2482 card->private_free = snd_rme96_card_free; 2487 card->private_free = snd_rme96_card_free;
2483 rme96 = card->private_data; 2488 rme96 = card->private_data;
2484 rme96->card = card; 2489 rme96->card = card;
2485 rme96->pci = pci; 2490 rme96->pci = pci;
2486 snd_card_set_dev(card, &pci->dev);
2487 if ((err = snd_rme96_create(rme96)) < 0) { 2491 if ((err = snd_rme96_create(rme96)) < 0) {
2488 snd_card_free(card); 2492 snd_card_free(card);
2489 return err; 2493 return err;
2490 } 2494 }
2491 2495
2492#ifdef CONFIG_PM 2496#ifdef CONFIG_PM_SLEEP
2493 rme96->playback_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); 2497 rme96->playback_suspend_buffer = vmalloc(RME96_BUFFER_SIZE);
2494 if (!rme96->playback_suspend_buffer) { 2498 if (!rme96->playback_suspend_buffer) {
2495 snd_printk(KERN_ERR 2499 dev_err(card->dev,
2496 "Failed to allocate playback suspend buffer!\n"); 2500 "Failed to allocate playback suspend buffer!\n");
2497 snd_card_free(card); 2501 snd_card_free(card);
2498 return -ENOMEM; 2502 return -ENOMEM;
2499 } 2503 }
2500 rme96->capture_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); 2504 rme96->capture_suspend_buffer = vmalloc(RME96_BUFFER_SIZE);
2501 if (!rme96->capture_suspend_buffer) { 2505 if (!rme96->capture_suspend_buffer) {
2502 snd_printk(KERN_ERR 2506 dev_err(card->dev,
2503 "Failed to allocate capture suspend buffer!\n"); 2507 "Failed to allocate capture suspend buffer!\n");
2504 snd_card_free(card); 2508 snd_card_free(card);
2505 return -ENOMEM; 2509 return -ENOMEM;
@@ -2548,10 +2552,9 @@ static struct pci_driver rme96_driver = {
2548 .id_table = snd_rme96_ids, 2552 .id_table = snd_rme96_ids,
2549 .probe = snd_rme96_probe, 2553 .probe = snd_rme96_probe,
2550 .remove = snd_rme96_remove, 2554 .remove = snd_rme96_remove,
2551#ifdef CONFIG_PM 2555 .driver = {
2552 .suspend = snd_rme96_suspend, 2556 .pm = RME96_PM_OPS,
2553 .resume = snd_rme96_resume, 2557 },
2554#endif
2555}; 2558};
2556 2559
2557module_pci_driver(rme96_driver); 2560module_pci_driver(rme96_driver);
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index bd90c80bb494..4c6f5d1c9882 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -675,14 +675,15 @@ static int hdsp_check_for_iobox (struct hdsp *hdsp)
675 if (0 == (hdsp_read(hdsp, HDSP_statusRegister) & 675 if (0 == (hdsp_read(hdsp, HDSP_statusRegister) &
676 HDSP_ConfigError)) { 676 HDSP_ConfigError)) {
677 if (i) { 677 if (i) {
678 snd_printd("Hammerfall-DSP: IO box found after %d ms\n", 678 dev_dbg(hdsp->card->dev,
679 "IO box found after %d ms\n",
679 (20 * i)); 680 (20 * i));
680 } 681 }
681 return 0; 682 return 0;
682 } 683 }
683 msleep(20); 684 msleep(20);
684 } 685 }
685 snd_printk(KERN_ERR "Hammerfall-DSP: no IO box connected!\n"); 686 dev_err(hdsp->card->dev, "no IO box connected!\n");
686 hdsp->state &= ~HDSP_FirmwareLoaded; 687 hdsp->state &= ~HDSP_FirmwareLoaded;
687 return -EIO; 688 return -EIO;
688} 689}
@@ -699,13 +700,13 @@ static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,
699 if (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError) 700 if (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError)
700 msleep(delay); 701 msleep(delay);
701 else { 702 else {
702 snd_printd("Hammerfall-DSP: iobox found after %ums!\n", 703 dev_dbg(hdsp->card->dev, "iobox found after %ums!\n",
703 i * delay); 704 i * delay);
704 return 0; 705 return 0;
705 } 706 }
706 } 707 }
707 708
708 snd_printk("Hammerfall-DSP: no IO box connected!\n"); 709 dev_info(hdsp->card->dev, "no IO box connected!\n");
709 hdsp->state &= ~HDSP_FirmwareLoaded; 710 hdsp->state &= ~HDSP_FirmwareLoaded;
710 return -EIO; 711 return -EIO;
711} 712}
@@ -728,13 +729,14 @@ static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
728 729
729 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 730 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
730 731
731 snd_printk ("Hammerfall-DSP: loading firmware\n"); 732 dev_info(hdsp->card->dev, "loading firmware\n");
732 733
733 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM); 734 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
734 hdsp_write (hdsp, HDSP_fifoData, 0); 735 hdsp_write (hdsp, HDSP_fifoData, 0);
735 736
736 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) { 737 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
737 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n"); 738 dev_info(hdsp->card->dev,
739 "timeout waiting for download preparation\n");
738 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200); 740 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
739 return -EIO; 741 return -EIO;
740 } 742 }
@@ -744,7 +746,8 @@ static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
744 for (i = 0; i < HDSP_FIRMWARE_SIZE / 4; ++i) { 746 for (i = 0; i < HDSP_FIRMWARE_SIZE / 4; ++i) {
745 hdsp_write(hdsp, HDSP_fifoData, cache[i]); 747 hdsp_write(hdsp, HDSP_fifoData, cache[i]);
746 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) { 748 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
747 snd_printk ("Hammerfall-DSP: timeout during firmware loading\n"); 749 dev_info(hdsp->card->dev,
750 "timeout during firmware loading\n");
748 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200); 751 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
749 return -EIO; 752 return -EIO;
750 } 753 }
@@ -760,11 +763,12 @@ static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
760 hdsp->control2_register = 0; 763 hdsp->control2_register = 0;
761#endif 764#endif
762 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register); 765 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
763 snd_printk ("Hammerfall-DSP: finished firmware loading\n"); 766 dev_info(hdsp->card->dev, "finished firmware loading\n");
764 767
765 } 768 }
766 if (hdsp->state & HDSP_InitializationComplete) { 769 if (hdsp->state & HDSP_InitializationComplete) {
767 snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n"); 770 dev_info(hdsp->card->dev,
771 "firmware loaded from cache, restoring defaults\n");
768 spin_lock_irqsave(&hdsp->lock, flags); 772 spin_lock_irqsave(&hdsp->lock, flags);
769 snd_hdsp_set_defaults(hdsp); 773 snd_hdsp_set_defaults(hdsp);
770 spin_unlock_irqrestore(&hdsp->lock, flags); 774 spin_unlock_irqrestore(&hdsp->lock, flags);
@@ -791,7 +795,7 @@ static int hdsp_get_iobox_version (struct hdsp *hdsp)
791 hdsp_write (hdsp, HDSP_fifoData, 0); 795 hdsp_write (hdsp, HDSP_fifoData, 0);
792 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) { 796 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
793 hdsp->io_type = Multiface; 797 hdsp->io_type = Multiface;
794 snd_printk("Hammerfall-DSP: Multiface found\n"); 798 dev_info(hdsp->card->dev, "Multiface found\n");
795 return 0; 799 return 0;
796 } 800 }
797 801
@@ -799,7 +803,7 @@ static int hdsp_get_iobox_version (struct hdsp *hdsp)
799 hdsp_write(hdsp, HDSP_fifoData, 0); 803 hdsp_write(hdsp, HDSP_fifoData, 0);
800 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) { 804 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) {
801 hdsp->io_type = Digiface; 805 hdsp->io_type = Digiface;
802 snd_printk("Hammerfall-DSP: Digiface found\n"); 806 dev_info(hdsp->card->dev, "Digiface found\n");
803 return 0; 807 return 0;
804 } 808 }
805 809
@@ -808,7 +812,7 @@ static int hdsp_get_iobox_version (struct hdsp *hdsp)
808 hdsp_write(hdsp, HDSP_fifoData, 0); 812 hdsp_write(hdsp, HDSP_fifoData, 0);
809 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) { 813 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) {
810 hdsp->io_type = Multiface; 814 hdsp->io_type = Multiface;
811 snd_printk("Hammerfall-DSP: Multiface found\n"); 815 dev_info(hdsp->card->dev, "Multiface found\n");
812 return 0; 816 return 0;
813 } 817 }
814 818
@@ -817,12 +821,12 @@ static int hdsp_get_iobox_version (struct hdsp *hdsp)
817 hdsp_write(hdsp, HDSP_fifoData, 0); 821 hdsp_write(hdsp, HDSP_fifoData, 0);
818 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) { 822 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
819 hdsp->io_type = Multiface; 823 hdsp->io_type = Multiface;
820 snd_printk("Hammerfall-DSP: Multiface found\n"); 824 dev_info(hdsp->card->dev, "Multiface found\n");
821 return 0; 825 return 0;
822 } 826 }
823 827
824 hdsp->io_type = RPM; 828 hdsp->io_type = RPM;
825 snd_printk("Hammerfall-DSP: RPM found\n"); 829 dev_info(hdsp->card->dev, "RPM found\n");
826 return 0; 830 return 0;
827 } else { 831 } else {
828 /* firmware was already loaded, get iobox type */ 832 /* firmware was already loaded, get iobox type */
@@ -847,20 +851,18 @@ static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
847 hdsp->state &= ~HDSP_FirmwareLoaded; 851 hdsp->state &= ~HDSP_FirmwareLoaded;
848 if (! load_on_demand) 852 if (! load_on_demand)
849 return -EIO; 853 return -EIO;
850 snd_printk(KERN_ERR "Hammerfall-DSP: firmware not present.\n"); 854 dev_err(hdsp->card->dev, "firmware not present.\n");
851 /* try to load firmware */ 855 /* try to load firmware */
852 if (! (hdsp->state & HDSP_FirmwareCached)) { 856 if (! (hdsp->state & HDSP_FirmwareCached)) {
853 if (! hdsp_request_fw_loader(hdsp)) 857 if (! hdsp_request_fw_loader(hdsp))
854 return 0; 858 return 0;
855 snd_printk(KERN_ERR 859 dev_err(hdsp->card->dev,
856 "Hammerfall-DSP: No firmware loaded nor " 860 "No firmware loaded nor cached, please upload firmware.\n");
857 "cached, please upload firmware.\n");
858 return -EIO; 861 return -EIO;
859 } 862 }
860 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) { 863 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
861 snd_printk(KERN_ERR 864 dev_err(hdsp->card->dev,
862 "Hammerfall-DSP: Firmware loading from " 865 "Firmware loading from cache failed, please upload manually.\n");
863 "cache failed, please upload manually.\n");
864 return -EIO; 866 return -EIO;
865 } 867 }
866 } 868 }
@@ -888,7 +890,8 @@ static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
888 udelay (100); 890 udelay (100);
889 } 891 }
890 892
891 snd_printk ("Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n", 893 dev_warn(hdsp->card->dev,
894 "wait for FIFO status <= %d failed after %d iterations\n",
892 count, timeout); 895 count, timeout);
893 return -1; 896 return -1;
894} 897}
@@ -1005,7 +1008,9 @@ static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
1005 default: 1008 default:
1006 break; 1009 break;
1007 } 1010 }
1008 snd_printk ("Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status); 1011 dev_warn(hdsp->card->dev,
1012 "unknown spdif frequency status; bits = 0x%x, status = 0x%x\n",
1013 rate_bits, status);
1009 return 0; 1014 return 0;
1010} 1015}
1011 1016
@@ -1139,7 +1144,8 @@ static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1139 if (!(hdsp->control_register & HDSP_ClockModeMaster)) { 1144 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1140 if (called_internally) { 1145 if (called_internally) {
1141 /* request from ctl or card initialization */ 1146 /* request from ctl or card initialization */
1142 snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n"); 1147 dev_err(hdsp->card->dev,
1148 "device is not running as a clock master: cannot set sample rate.\n");
1143 return -1; 1149 return -1;
1144 } else { 1150 } else {
1145 /* hw_param request while in AutoSync mode */ 1151 /* hw_param request while in AutoSync mode */
@@ -1147,11 +1153,14 @@ static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1147 int spdif_freq = hdsp_spdif_sample_rate(hdsp); 1153 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1148 1154
1149 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) 1155 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1150 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n"); 1156 dev_info(hdsp->card->dev,
1157 "Detected ADAT in double speed mode\n");
1151 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) 1158 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1152 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n"); 1159 dev_info(hdsp->card->dev,
1160 "Detected ADAT in quad speed mode\n");
1153 else if (rate != external_freq) { 1161 else if (rate != external_freq) {
1154 snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n"); 1162 dev_info(hdsp->card->dev,
1163 "No AutoSync source for requested rate\n");
1155 return -1; 1164 return -1;
1156 } 1165 }
1157 } 1166 }
@@ -1223,7 +1232,8 @@ static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1223 } 1232 }
1224 1233
1225 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) { 1234 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1226 snd_printk ("Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n", 1235 dev_warn(hdsp->card->dev,
1236 "cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1227 hdsp->capture_pid, 1237 hdsp->capture_pid,
1228 hdsp->playback_pid); 1238 hdsp->playback_pid);
1229 return -EBUSY; 1239 return -EBUSY;
@@ -3785,7 +3795,8 @@ static int snd_hdsp_initialize_memory(struct hdsp *hdsp)
3785 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) { 3795 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3786 if (hdsp->capture_dma_buf.area) 3796 if (hdsp->capture_dma_buf.area)
3787 snd_dma_free_pages(&hdsp->capture_dma_buf); 3797 snd_dma_free_pages(&hdsp->capture_dma_buf);
3788 printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name); 3798 dev_err(hdsp->card->dev,
3799 "%s: no buffers available\n", hdsp->card_name);
3789 return -ENOMEM; 3800 return -ENOMEM;
3790 } 3801 }
3791 3802
@@ -4747,7 +4758,8 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4747 return err; 4758 return err;
4748 4759
4749 if (!(hdsp->state & HDSP_FirmwareLoaded)) { 4760 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4750 snd_printk(KERN_ERR "Hammerfall-DSP: firmware needs to be uploaded to the card.\n"); 4761 dev_err(hdsp->card->dev,
4762 "firmware needs to be uploaded to the card.\n");
4751 return -EINVAL; 4763 return -EINVAL;
4752 } 4764 }
4753 4765
@@ -4858,7 +4870,8 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4858 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded)) 4870 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4859 return -EBUSY; 4871 return -EBUSY;
4860 4872
4861 snd_printk(KERN_INFO "Hammerfall-DSP: initializing firmware upload\n"); 4873 dev_info(hdsp->card->dev,
4874 "initializing firmware upload\n");
4862 firmware = (struct hdsp_firmware __user *)argp; 4875 firmware = (struct hdsp_firmware __user *)argp;
4863 4876
4864 if (get_user(firmware_data, &firmware->firmware_data)) 4877 if (get_user(firmware_data, &firmware->firmware_data))
@@ -4893,7 +4906,8 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4893 snd_hdsp_initialize_midi_flush(hdsp); 4906 snd_hdsp_initialize_midi_flush(hdsp);
4894 4907
4895 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 4908 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4896 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n"); 4909 dev_err(hdsp->card->dev,
4910 "error creating alsa devices\n");
4897 return err; 4911 return err;
4898 } 4912 }
4899 } 4913 }
@@ -4983,7 +4997,8 @@ static int snd_hdsp_enable_io (struct hdsp *hdsp)
4983 int i; 4997 int i;
4984 4998
4985 if (hdsp_fifo_wait (hdsp, 0, 100)) { 4999 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4986 snd_printk(KERN_ERR "Hammerfall-DSP: enable_io fifo_wait failed\n"); 5000 dev_err(hdsp->card->dev,
5001 "enable_io fifo_wait failed\n");
4987 return -EIO; 5002 return -EIO;
4988 } 5003 }
4989 5004
@@ -5057,25 +5072,29 @@ static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp
5057 int err; 5072 int err;
5058 5073
5059 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) { 5074 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
5060 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating pcm interface\n"); 5075 dev_err(card->dev,
5076 "Error creating pcm interface\n");
5061 return err; 5077 return err;
5062 } 5078 }
5063 5079
5064 5080
5065 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) { 5081 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
5066 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating first midi interface\n"); 5082 dev_err(card->dev,
5083 "Error creating first midi interface\n");
5067 return err; 5084 return err;
5068 } 5085 }
5069 5086
5070 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) { 5087 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
5071 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) { 5088 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
5072 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating second midi interface\n"); 5089 dev_err(card->dev,
5090 "Error creating second midi interface\n");
5073 return err; 5091 return err;
5074 } 5092 }
5075 } 5093 }
5076 5094
5077 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) { 5095 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
5078 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating ctl interface\n"); 5096 dev_err(card->dev,
5097 "Error creating ctl interface\n");
5079 return err; 5098 return err;
5080 } 5099 }
5081 5100
@@ -5088,7 +5107,8 @@ static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp
5088 hdsp->playback_substream = NULL; 5107 hdsp->playback_substream = NULL;
5089 5108
5090 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) { 5109 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
5091 snd_printk(KERN_ERR "Hammerfall-DSP: Error setting default values\n"); 5110 dev_err(card->dev,
5111 "Error setting default values\n");
5092 return err; 5112 return err;
5093 } 5113 }
5094 5114
@@ -5098,7 +5118,8 @@ static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp
5098 hdsp->port, hdsp->irq); 5118 hdsp->port, hdsp->irq);
5099 5119
5100 if ((err = snd_card_register(card)) < 0) { 5120 if ((err = snd_card_register(card)) < 0) {
5101 snd_printk(KERN_ERR "Hammerfall-DSP: error registering card\n"); 5121 dev_err(card->dev,
5122 "error registering card\n");
5102 return err; 5123 return err;
5103 } 5124 }
5104 hdsp->state |= HDSP_InitializationComplete; 5125 hdsp->state |= HDSP_InitializationComplete;
@@ -5141,16 +5162,19 @@ static int hdsp_request_fw_loader(struct hdsp *hdsp)
5141 fwfile = "digiface_firmware_rev11.bin"; 5162 fwfile = "digiface_firmware_rev11.bin";
5142 break; 5163 break;
5143 default: 5164 default:
5144 snd_printk(KERN_ERR "Hammerfall-DSP: invalid io_type %d\n", hdsp->io_type); 5165 dev_err(hdsp->card->dev,
5166 "invalid io_type %d\n", hdsp->io_type);
5145 return -EINVAL; 5167 return -EINVAL;
5146 } 5168 }
5147 5169
5148 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) { 5170 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
5149 snd_printk(KERN_ERR "Hammerfall-DSP: cannot load firmware %s\n", fwfile); 5171 dev_err(hdsp->card->dev,
5172 "cannot load firmware %s\n", fwfile);
5150 return -ENOENT; 5173 return -ENOENT;
5151 } 5174 }
5152 if (fw->size < HDSP_FIRMWARE_SIZE) { 5175 if (fw->size < HDSP_FIRMWARE_SIZE) {
5153 snd_printk(KERN_ERR "Hammerfall-DSP: too short firmware size %d (expected %d)\n", 5176 dev_err(hdsp->card->dev,
5177 "too short firmware size %d (expected %d)\n",
5154 (int)fw->size, HDSP_FIRMWARE_SIZE); 5178 (int)fw->size, HDSP_FIRMWARE_SIZE);
5155 return -EINVAL; 5179 return -EINVAL;
5156 } 5180 }
@@ -5167,13 +5191,15 @@ static int hdsp_request_fw_loader(struct hdsp *hdsp)
5167 return err; 5191 return err;
5168 5192
5169 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) { 5193 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
5170 snd_printk(KERN_ERR "Hammerfall-DSP: error creating hwdep device\n"); 5194 dev_err(hdsp->card->dev,
5195 "error creating hwdep device\n");
5171 return err; 5196 return err;
5172 } 5197 }
5173 snd_hdsp_initialize_channels(hdsp); 5198 snd_hdsp_initialize_channels(hdsp);
5174 snd_hdsp_initialize_midi_flush(hdsp); 5199 snd_hdsp_initialize_midi_flush(hdsp);
5175 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 5200 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
5176 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n"); 5201 dev_err(hdsp->card->dev,
5202 "error creating alsa devices\n");
5177 return err; 5203 return err;
5178 } 5204 }
5179 } 5205 }
@@ -5249,13 +5275,14 @@ static int snd_hdsp_create(struct snd_card *card,
5249 return err; 5275 return err;
5250 hdsp->port = pci_resource_start(pci, 0); 5276 hdsp->port = pci_resource_start(pci, 0);
5251 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) { 5277 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5252 snd_printk(KERN_ERR "Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1); 5278 dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n",
5279 hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5253 return -EBUSY; 5280 return -EBUSY;
5254 } 5281 }
5255 5282
5256 if (request_irq(pci->irq, snd_hdsp_interrupt, IRQF_SHARED, 5283 if (request_irq(pci->irq, snd_hdsp_interrupt, IRQF_SHARED,
5257 KBUILD_MODNAME, hdsp)) { 5284 KBUILD_MODNAME, hdsp)) {
5258 snd_printk(KERN_ERR "Hammerfall-DSP: unable to use IRQ %d\n", pci->irq); 5285 dev_err(hdsp->card->dev, "unable to use IRQ %d\n", pci->irq);
5259 return -EBUSY; 5286 return -EBUSY;
5260 } 5287 }
5261 5288
@@ -5281,17 +5308,20 @@ static int snd_hdsp_create(struct snd_card *card,
5281 if userspace is not ready for 5308 if userspace is not ready for
5282 firmware upload 5309 firmware upload
5283 */ 5310 */
5284 snd_printk(KERN_ERR "Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n"); 5311 dev_err(hdsp->card->dev,
5312 "couldn't get firmware from userspace. try using hdsploader\n");
5285 else 5313 else
5286 /* init is complete, we return */ 5314 /* init is complete, we return */
5287 return 0; 5315 return 0;
5288 /* we defer initialization */ 5316 /* we defer initialization */
5289 snd_printk(KERN_INFO "Hammerfall-DSP: card initialization pending : waiting for firmware\n"); 5317 dev_info(hdsp->card->dev,
5318 "card initialization pending : waiting for firmware\n");
5290 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) 5319 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5291 return err; 5320 return err;
5292 return 0; 5321 return 0;
5293 } else { 5322 } else {
5294 snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n"); 5323 dev_info(hdsp->card->dev,
5324 "Firmware already present, initializing card.\n");
5295 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2) 5325 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
5296 hdsp->io_type = RPM; 5326 hdsp->io_type = RPM;
5297 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) 5327 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
@@ -5375,8 +5405,8 @@ static int snd_hdsp_probe(struct pci_dev *pci,
5375 return -ENOENT; 5405 return -ENOENT;
5376 } 5406 }
5377 5407
5378 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 5408 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
5379 sizeof(struct hdsp), &card); 5409 sizeof(struct hdsp), &card);
5380 if (err < 0) 5410 if (err < 0)
5381 return err; 5411 return err;
5382 5412
@@ -5384,7 +5414,6 @@ static int snd_hdsp_probe(struct pci_dev *pci,
5384 card->private_free = snd_hdsp_card_free; 5414 card->private_free = snd_hdsp_card_free;
5385 hdsp->dev = dev; 5415 hdsp->dev = dev;
5386 hdsp->pci = pci; 5416 hdsp->pci = pci;
5387 snd_card_set_dev(card, &pci->dev);
5388 5417
5389 if ((err = snd_hdsp_create(card, hdsp)) < 0) { 5418 if ((err = snd_hdsp_create(card, hdsp)) < 0) {
5390 snd_card_free(card); 5419 snd_card_free(card);
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index e98dc008de0b..cb82b593473a 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -1651,9 +1651,8 @@ static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally)
1651 just make a warning an remember setting 1651 just make a warning an remember setting
1652 for future master mode switching */ 1652 for future master mode switching */
1653 1653
1654 snd_printk(KERN_WARNING "HDSPM: " 1654 dev_warn(hdspm->card->dev,
1655 "Warning: device is not running " 1655 "Warning: device is not running as a clock master.\n");
1656 "as a clock master.\n");
1657 not_set = 1; 1656 not_set = 1;
1658 } else { 1657 } else {
1659 1658
@@ -1664,15 +1663,14 @@ static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally)
1664 if (hdspm_autosync_ref(hdspm) == 1663 if (hdspm_autosync_ref(hdspm) ==
1665 HDSPM_AUTOSYNC_FROM_NONE) { 1664 HDSPM_AUTOSYNC_FROM_NONE) {
1666 1665
1667 snd_printk(KERN_WARNING "HDSPM: " 1666 dev_warn(hdspm->card->dev,
1668 "Detected no Externel Sync \n"); 1667 "Detected no Externel Sync\n");
1669 not_set = 1; 1668 not_set = 1;
1670 1669
1671 } else if (rate != external_freq) { 1670 } else if (rate != external_freq) {
1672 1671
1673 snd_printk(KERN_WARNING "HDSPM: " 1672 dev_warn(hdspm->card->dev,
1674 "Warning: No AutoSync source for " 1673 "Warning: No AutoSync source for requested rate\n");
1675 "requested rate\n");
1676 not_set = 1; 1674 not_set = 1;
1677 } 1675 }
1678 } 1676 }
@@ -1738,13 +1736,11 @@ static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally)
1738 1736
1739 if (current_speed != target_speed 1737 if (current_speed != target_speed
1740 && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) { 1738 && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) {
1741 snd_printk 1739 dev_err(hdspm->card->dev,
1742 (KERN_ERR "HDSPM: " 1740 "cannot change from %s speed to %s speed mode (capture PID = %d, playback PID = %d)\n",
1743 "cannot change from %s speed to %s speed mode " 1741 hdspm_speed_names[current_speed],
1744 "(capture PID = %d, playback PID = %d)\n", 1742 hdspm_speed_names[target_speed],
1745 hdspm_speed_names[current_speed], 1743 hdspm->capture_pid, hdspm->playback_pid);
1746 hdspm_speed_names[target_speed],
1747 hdspm->capture_pid, hdspm->playback_pid);
1748 return -EBUSY; 1744 return -EBUSY;
1749 } 1745 }
1750 1746
@@ -5446,7 +5442,7 @@ static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id)
5446 * 0 64 ~3998231 ~8191558 5442 * 0 64 ~3998231 ~8191558
5447 **/ 5443 **/
5448 /* 5444 /*
5449 snd_printk(KERN_INFO "snd_hdspm_interrupt %llu @ %llx\n", 5445 dev_info(hdspm->card->dev, "snd_hdspm_interrupt %llu @ %llx\n",
5450 now-hdspm->last_interrupt, status & 0xFFC0); 5446 now-hdspm->last_interrupt, status & 0xFFC0);
5451 hdspm->last_interrupt = now; 5447 hdspm->last_interrupt = now;
5452 */ 5448 */
@@ -5583,7 +5579,7 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
5583 spin_lock_irq(&hdspm->lock); 5579 spin_lock_irq(&hdspm->lock);
5584 err = hdspm_set_rate(hdspm, params_rate(params), 0); 5580 err = hdspm_set_rate(hdspm, params_rate(params), 0);
5585 if (err < 0) { 5581 if (err < 0) {
5586 snd_printk(KERN_INFO "err on hdspm_set_rate: %d\n", err); 5582 dev_info(hdspm->card->dev, "err on hdspm_set_rate: %d\n", err);
5587 spin_unlock_irq(&hdspm->lock); 5583 spin_unlock_irq(&hdspm->lock);
5588 _snd_pcm_hw_param_setempty(params, 5584 _snd_pcm_hw_param_setempty(params,
5589 SNDRV_PCM_HW_PARAM_RATE); 5585 SNDRV_PCM_HW_PARAM_RATE);
@@ -5594,7 +5590,8 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
5594 err = hdspm_set_interrupt_interval(hdspm, 5590 err = hdspm_set_interrupt_interval(hdspm,
5595 params_period_size(params)); 5591 params_period_size(params));
5596 if (err < 0) { 5592 if (err < 0) {
5597 snd_printk(KERN_INFO "err on hdspm_set_interrupt_interval: %d\n", err); 5593 dev_info(hdspm->card->dev,
5594 "err on hdspm_set_interrupt_interval: %d\n", err);
5598 _snd_pcm_hw_param_setempty(params, 5595 _snd_pcm_hw_param_setempty(params,
5599 SNDRV_PCM_HW_PARAM_PERIOD_SIZE); 5596 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
5600 return err; 5597 return err;
@@ -5610,7 +5607,8 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
5610 err = 5607 err =
5611 snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES); 5608 snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES);
5612 if (err < 0) { 5609 if (err < 0) {
5613 snd_printk(KERN_INFO "err on snd_pcm_lib_malloc_pages: %d\n", err); 5610 dev_info(hdspm->card->dev,
5611 "err on snd_pcm_lib_malloc_pages: %d\n", err);
5614 return err; 5612 return err;
5615 } 5613 }
5616 5614
@@ -5624,7 +5622,8 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
5624 5622
5625 hdspm->playback_buffer = 5623 hdspm->playback_buffer =
5626 (unsigned char *) substream->runtime->dma_area; 5624 (unsigned char *) substream->runtime->dma_area;
5627 snd_printdd("Allocated sample buffer for playback at %p\n", 5625 dev_dbg(hdspm->card->dev,
5626 "Allocated sample buffer for playback at %p\n",
5628 hdspm->playback_buffer); 5627 hdspm->playback_buffer);
5629 } else { 5628 } else {
5630 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn, 5629 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn,
@@ -5635,18 +5634,21 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
5635 5634
5636 hdspm->capture_buffer = 5635 hdspm->capture_buffer =
5637 (unsigned char *) substream->runtime->dma_area; 5636 (unsigned char *) substream->runtime->dma_area;
5638 snd_printdd("Allocated sample buffer for capture at %p\n", 5637 dev_dbg(hdspm->card->dev,
5638 "Allocated sample buffer for capture at %p\n",
5639 hdspm->capture_buffer); 5639 hdspm->capture_buffer);
5640 } 5640 }
5641 5641
5642 /* 5642 /*
5643 snd_printdd("Allocated sample buffer for %s at 0x%08X\n", 5643 dev_dbg(hdspm->card->dev,
5644 "Allocated sample buffer for %s at 0x%08X\n",
5644 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 5645 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
5645 "playback" : "capture", 5646 "playback" : "capture",
5646 snd_pcm_sgbuf_get_addr(substream, 0)); 5647 snd_pcm_sgbuf_get_addr(substream, 0));
5647 */ 5648 */
5648 /* 5649 /*
5649 snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n", 5650 dev_dbg(hdspm->card->dev,
5651 "set_hwparams: %s %d Hz, %d channels, bs = %d\n",
5650 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 5652 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
5651 "playback" : "capture", 5653 "playback" : "capture",
5652 params_rate(params), params_channels(params), 5654 params_rate(params), params_channels(params),
@@ -5667,12 +5669,14 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
5667 /* Switch to native float format if requested */ 5669 /* Switch to native float format if requested */
5668 if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) { 5670 if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) {
5669 if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT)) 5671 if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT))
5670 snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE float format.\n"); 5672 dev_info(hdspm->card->dev,
5673 "Switching to native 32bit LE float format.\n");
5671 5674
5672 hdspm->control_register |= HDSPe_FLOAT_FORMAT; 5675 hdspm->control_register |= HDSPe_FLOAT_FORMAT;
5673 } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) { 5676 } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) {
5674 if (hdspm->control_register & HDSPe_FLOAT_FORMAT) 5677 if (hdspm->control_register & HDSPe_FLOAT_FORMAT)
5675 snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE integer format.\n"); 5678 dev_info(hdspm->card->dev,
5679 "Switching to native 32bit LE integer format.\n");
5676 5680
5677 hdspm->control_register &= ~HDSPe_FLOAT_FORMAT; 5681 hdspm->control_register &= ~HDSPe_FLOAT_FORMAT;
5678 } 5682 }
@@ -5715,12 +5719,16 @@ static int snd_hdspm_channel_info(struct snd_pcm_substream *substream,
5715 5719
5716 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 5720 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5717 if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) { 5721 if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) {
5718 snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel out of range (%d)\n", info->channel); 5722 dev_info(hdspm->card->dev,
5723 "snd_hdspm_channel_info: output channel out of range (%d)\n",
5724 info->channel);
5719 return -EINVAL; 5725 return -EINVAL;
5720 } 5726 }
5721 5727
5722 if (hdspm->channel_map_out[info->channel] < 0) { 5728 if (hdspm->channel_map_out[info->channel] < 0) {
5723 snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel %d mapped out\n", info->channel); 5729 dev_info(hdspm->card->dev,
5730 "snd_hdspm_channel_info: output channel %d mapped out\n",
5731 info->channel);
5724 return -EINVAL; 5732 return -EINVAL;
5725 } 5733 }
5726 5734
@@ -5728,12 +5736,16 @@ static int snd_hdspm_channel_info(struct snd_pcm_substream *substream,
5728 HDSPM_CHANNEL_BUFFER_BYTES; 5736 HDSPM_CHANNEL_BUFFER_BYTES;
5729 } else { 5737 } else {
5730 if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) { 5738 if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) {
5731 snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel out of range (%d)\n", info->channel); 5739 dev_info(hdspm->card->dev,
5740 "snd_hdspm_channel_info: input channel out of range (%d)\n",
5741 info->channel);
5732 return -EINVAL; 5742 return -EINVAL;
5733 } 5743 }
5734 5744
5735 if (hdspm->channel_map_in[info->channel] < 0) { 5745 if (hdspm->channel_map_in[info->channel] < 0) {
5736 snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel %d mapped out\n", info->channel); 5746 dev_info(hdspm->card->dev,
5747 "snd_hdspm_channel_info: input channel %d mapped out\n",
5748 info->channel);
5737 return -EINVAL; 5749 return -EINVAL;
5738 } 5750 }
5739 5751
@@ -6283,7 +6295,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6283 6295
6284 s = copy_to_user(argp, levels, sizeof(struct hdspm_peak_rms)); 6296 s = copy_to_user(argp, levels, sizeof(struct hdspm_peak_rms));
6285 if (0 != s) { 6297 if (0 != s) {
6286 /* snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu 6298 /* dev_err(hdspm->card->dev, "copy_to_user(.., .., %lu): %lu
6287 [Levels]\n", sizeof(struct hdspm_peak_rms), s); 6299 [Levels]\n", sizeof(struct hdspm_peak_rms), s);
6288 */ 6300 */
6289 return -EFAULT; 6301 return -EFAULT;
@@ -6329,7 +6341,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6329 s = copy_to_user(argp, &ltc, sizeof(struct hdspm_ltc)); 6341 s = copy_to_user(argp, &ltc, sizeof(struct hdspm_ltc));
6330 if (0 != s) { 6342 if (0 != s) {
6331 /* 6343 /*
6332 snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */ 6344 dev_err(hdspm->card->dev, "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */
6333 return -EFAULT; 6345 return -EFAULT;
6334 } 6346 }
6335 6347
@@ -6494,11 +6506,13 @@ static int snd_hdspm_preallocate_memory(struct hdspm *hdspm)
6494 wanted, 6506 wanted,
6495 wanted); 6507 wanted);
6496 if (err < 0) { 6508 if (err < 0) {
6497 snd_printdd("Could not preallocate %zd Bytes\n", wanted); 6509 dev_dbg(hdspm->card->dev,
6510 "Could not preallocate %zd Bytes\n", wanted);
6498 6511
6499 return err; 6512 return err;
6500 } else 6513 } else
6501 snd_printdd(" Preallocated %zd Bytes\n", wanted); 6514 dev_dbg(hdspm->card->dev,
6515 " Preallocated %zd Bytes\n", wanted);
6502 6516
6503 return 0; 6517 return 0;
6504} 6518}
@@ -6559,7 +6573,7 @@ static int snd_hdspm_create_alsa_devices(struct snd_card *card,
6559{ 6573{
6560 int err, i; 6574 int err, i;
6561 6575
6562 snd_printdd("Create card...\n"); 6576 dev_dbg(card->dev, "Create card...\n");
6563 err = snd_hdspm_create_pcm(card, hdspm); 6577 err = snd_hdspm_create_pcm(card, hdspm);
6564 if (err < 0) 6578 if (err < 0)
6565 return err; 6579 return err;
@@ -6581,7 +6595,7 @@ static int snd_hdspm_create_alsa_devices(struct snd_card *card,
6581 if (err < 0) 6595 if (err < 0)
6582 return err; 6596 return err;
6583 6597
6584 snd_printdd("proc init...\n"); 6598 dev_dbg(card->dev, "proc init...\n");
6585 snd_hdspm_proc_init(hdspm); 6599 snd_hdspm_proc_init(hdspm);
6586 6600
6587 hdspm->system_sample_rate = -1; 6601 hdspm->system_sample_rate = -1;
@@ -6592,23 +6606,23 @@ static int snd_hdspm_create_alsa_devices(struct snd_card *card,
6592 hdspm->capture_substream = NULL; 6606 hdspm->capture_substream = NULL;
6593 hdspm->playback_substream = NULL; 6607 hdspm->playback_substream = NULL;
6594 6608
6595 snd_printdd("Set defaults...\n"); 6609 dev_dbg(card->dev, "Set defaults...\n");
6596 err = snd_hdspm_set_defaults(hdspm); 6610 err = snd_hdspm_set_defaults(hdspm);
6597 if (err < 0) 6611 if (err < 0)
6598 return err; 6612 return err;
6599 6613
6600 snd_printdd("Update mixer controls...\n"); 6614 dev_dbg(card->dev, "Update mixer controls...\n");
6601 hdspm_update_simple_mixer_controls(hdspm); 6615 hdspm_update_simple_mixer_controls(hdspm);
6602 6616
6603 snd_printdd("Initializeing complete ???\n"); 6617 dev_dbg(card->dev, "Initializeing complete ???\n");
6604 6618
6605 err = snd_card_register(card); 6619 err = snd_card_register(card);
6606 if (err < 0) { 6620 if (err < 0) {
6607 snd_printk(KERN_ERR "HDSPM: error registering card\n"); 6621 dev_err(card->dev, "error registering card\n");
6608 return err; 6622 return err;
6609 } 6623 }
6610 6624
6611 snd_printdd("... yes now\n"); 6625 dev_dbg(card->dev, "... yes now\n");
6612 6626
6613 return 0; 6627 return 0;
6614} 6628}
@@ -6662,8 +6676,8 @@ static int snd_hdspm_create(struct snd_card *card,
6662 hdspm->card_name = "RME MADI"; 6676 hdspm->card_name = "RME MADI";
6663 hdspm->midiPorts = 3; 6677 hdspm->midiPorts = 3;
6664 } else { 6678 } else {
6665 snd_printk(KERN_ERR 6679 dev_err(card->dev,
6666 "HDSPM: unknown firmware revision %x\n", 6680 "unknown firmware revision %x\n",
6667 hdspm->firmware_rev); 6681 hdspm->firmware_rev);
6668 return -ENODEV; 6682 return -ENODEV;
6669 } 6683 }
@@ -6682,36 +6696,35 @@ static int snd_hdspm_create(struct snd_card *card,
6682 hdspm->port = pci_resource_start(pci, 0); 6696 hdspm->port = pci_resource_start(pci, 0);
6683 io_extent = pci_resource_len(pci, 0); 6697 io_extent = pci_resource_len(pci, 0);
6684 6698
6685 snd_printdd("grabbed memory region 0x%lx-0x%lx\n", 6699 dev_dbg(card->dev, "grabbed memory region 0x%lx-0x%lx\n",
6686 hdspm->port, hdspm->port + io_extent - 1); 6700 hdspm->port, hdspm->port + io_extent - 1);
6687 6701
6688 hdspm->iobase = ioremap_nocache(hdspm->port, io_extent); 6702 hdspm->iobase = ioremap_nocache(hdspm->port, io_extent);
6689 if (!hdspm->iobase) { 6703 if (!hdspm->iobase) {
6690 snd_printk(KERN_ERR "HDSPM: " 6704 dev_err(card->dev, "unable to remap region 0x%lx-0x%lx\n",
6691 "unable to remap region 0x%lx-0x%lx\n",
6692 hdspm->port, hdspm->port + io_extent - 1); 6705 hdspm->port, hdspm->port + io_extent - 1);
6693 return -EBUSY; 6706 return -EBUSY;
6694 } 6707 }
6695 snd_printdd("remapped region (0x%lx) 0x%lx-0x%lx\n", 6708 dev_dbg(card->dev, "remapped region (0x%lx) 0x%lx-0x%lx\n",
6696 (unsigned long)hdspm->iobase, hdspm->port, 6709 (unsigned long)hdspm->iobase, hdspm->port,
6697 hdspm->port + io_extent - 1); 6710 hdspm->port + io_extent - 1);
6698 6711
6699 if (request_irq(pci->irq, snd_hdspm_interrupt, 6712 if (request_irq(pci->irq, snd_hdspm_interrupt,
6700 IRQF_SHARED, KBUILD_MODNAME, hdspm)) { 6713 IRQF_SHARED, KBUILD_MODNAME, hdspm)) {
6701 snd_printk(KERN_ERR "HDSPM: unable to use IRQ %d\n", pci->irq); 6714 dev_err(card->dev, "unable to use IRQ %d\n", pci->irq);
6702 return -EBUSY; 6715 return -EBUSY;
6703 } 6716 }
6704 6717
6705 snd_printdd("use IRQ %d\n", pci->irq); 6718 dev_dbg(card->dev, "use IRQ %d\n", pci->irq);
6706 6719
6707 hdspm->irq = pci->irq; 6720 hdspm->irq = pci->irq;
6708 6721
6709 snd_printdd("kmalloc Mixer memory of %zd Bytes\n", 6722 dev_dbg(card->dev, "kmalloc Mixer memory of %zd Bytes\n",
6710 sizeof(struct hdspm_mixer)); 6723 sizeof(struct hdspm_mixer));
6711 hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL); 6724 hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL);
6712 if (!hdspm->mixer) { 6725 if (!hdspm->mixer) {
6713 snd_printk(KERN_ERR "HDSPM: " 6726 dev_err(card->dev,
6714 "unable to kmalloc Mixer memory of %d Bytes\n", 6727 "unable to kmalloc Mixer memory of %d Bytes\n",
6715 (int)sizeof(struct hdspm_mixer)); 6728 (int)sizeof(struct hdspm_mixer));
6716 return -ENOMEM; 6729 return -ENOMEM;
6717 } 6730 }
@@ -6780,14 +6793,14 @@ static int snd_hdspm_create(struct snd_card *card,
6780 hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS; 6793 hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS;
6781 6794
6782 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) { 6795 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) {
6783 snd_printk(KERN_INFO "HDSPM: AEB input board found\n"); 6796 dev_info(card->dev, "AEB input board found\n");
6784 hdspm->ss_in_channels += 4; 6797 hdspm->ss_in_channels += 4;
6785 hdspm->ds_in_channels += 4; 6798 hdspm->ds_in_channels += 4;
6786 hdspm->qs_in_channels += 4; 6799 hdspm->qs_in_channels += 4;
6787 } 6800 }
6788 6801
6789 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBO_D)) { 6802 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBO_D)) {
6790 snd_printk(KERN_INFO "HDSPM: AEB output board found\n"); 6803 dev_info(card->dev, "AEB output board found\n");
6791 hdspm->ss_out_channels += 4; 6804 hdspm->ss_out_channels += 4;
6792 hdspm->ds_out_channels += 4; 6805 hdspm->ds_out_channels += 4;
6793 hdspm->qs_out_channels += 4; 6806 hdspm->qs_out_channels += 4;
@@ -6854,7 +6867,7 @@ static int snd_hdspm_create(struct snd_card *card,
6854 if (NULL != hdspm->tco) { 6867 if (NULL != hdspm->tco) {
6855 hdspm_tco_write(hdspm); 6868 hdspm_tco_write(hdspm);
6856 } 6869 }
6857 snd_printk(KERN_INFO "HDSPM: AIO/RayDAT TCO module found\n"); 6870 dev_info(card->dev, "AIO/RayDAT TCO module found\n");
6858 } else { 6871 } else {
6859 hdspm->tco = NULL; 6872 hdspm->tco = NULL;
6860 } 6873 }
@@ -6869,7 +6882,7 @@ static int snd_hdspm_create(struct snd_card *card,
6869 if (NULL != hdspm->tco) { 6882 if (NULL != hdspm->tco) {
6870 hdspm_tco_write(hdspm); 6883 hdspm_tco_write(hdspm);
6871 } 6884 }
6872 snd_printk(KERN_INFO "HDSPM: MADI/AES TCO module found\n"); 6885 dev_info(card->dev, "MADI/AES TCO module found\n");
6873 } else { 6886 } else {
6874 hdspm->tco = NULL; 6887 hdspm->tco = NULL;
6875 } 6888 }
@@ -6951,7 +6964,7 @@ static int snd_hdspm_create(struct snd_card *card,
6951 } 6964 }
6952 } 6965 }
6953 6966
6954 snd_printdd("create alsa devices.\n"); 6967 dev_dbg(card->dev, "create alsa devices.\n");
6955 err = snd_hdspm_create_alsa_devices(card, hdspm); 6968 err = snd_hdspm_create_alsa_devices(card, hdspm);
6956 if (err < 0) 6969 if (err < 0)
6957 return err; 6970 return err;
@@ -7016,8 +7029,8 @@ static int snd_hdspm_probe(struct pci_dev *pci,
7016 return -ENOENT; 7029 return -ENOENT;
7017 } 7030 }
7018 7031
7019 err = snd_card_create(index[dev], id[dev], 7032 err = snd_card_new(&pci->dev, index[dev], id[dev],
7020 THIS_MODULE, sizeof(struct hdspm), &card); 7033 THIS_MODULE, sizeof(struct hdspm), &card);
7021 if (err < 0) 7034 if (err < 0)
7022 return err; 7035 return err;
7023 7036
@@ -7026,8 +7039,6 @@ static int snd_hdspm_probe(struct pci_dev *pci,
7026 hdspm->dev = dev; 7039 hdspm->dev = dev;
7027 hdspm->pci = pci; 7040 hdspm->pci = pci;
7028 7041
7029 snd_card_set_dev(card, &pci->dev);
7030
7031 err = snd_hdspm_create(card, hdspm); 7042 err = snd_hdspm_create(card, hdspm);
7032 if (err < 0) { 7043 if (err < 0) {
7033 snd_card_free(card); 7044 snd_card_free(card);
diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index 1503ee3585fd..1d9be90f7748 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -394,7 +394,9 @@ static snd_pcm_uframes_t rme9652_hw_pointer(struct snd_rme9652 *rme9652)
394 if (offset < period_size) { 394 if (offset < period_size) {
395 if (offset > rme9652->max_jitter) { 395 if (offset > rme9652->max_jitter) {
396 if (frag) 396 if (frag)
397 printk(KERN_ERR "Unexpected hw_pointer position (bufid == 0): status: %x offset: %d\n", status, offset); 397 dev_err(rme9652->card->dev,
398 "Unexpected hw_pointer position (bufid == 0): status: %x offset: %d\n",
399 status, offset);
398 } else if (!frag) 400 } else if (!frag)
399 return 0; 401 return 0;
400 offset -= rme9652->max_jitter; 402 offset -= rme9652->max_jitter;
@@ -403,7 +405,9 @@ static snd_pcm_uframes_t rme9652_hw_pointer(struct snd_rme9652 *rme9652)
403 } else { 405 } else {
404 if (offset > period_size + rme9652->max_jitter) { 406 if (offset > period_size + rme9652->max_jitter) {
405 if (!frag) 407 if (!frag)
406 printk(KERN_ERR "Unexpected hw_pointer position (bufid == 1): status: %x offset: %d\n", status, offset); 408 dev_err(rme9652->card->dev,
409 "Unexpected hw_pointer position (bufid == 1): status: %x offset: %d\n",
410 status, offset);
407 } else if (frag) 411 } else if (frag)
408 return period_size; 412 return period_size;
409 offset -= rme9652->max_jitter; 413 offset -= rme9652->max_jitter;
@@ -769,7 +773,8 @@ static inline int rme9652_spdif_sample_rate(struct snd_rme9652 *s)
769 break; 773 break;
770 774
771 default: 775 default:
772 snd_printk(KERN_ERR "%s: unknown S/PDIF input rate (bits = 0x%x)\n", 776 dev_err(s->card->dev,
777 "%s: unknown S/PDIF input rate (bits = 0x%x)\n",
773 s->card_name, rate_bits); 778 s->card_name, rate_bits);
774 return 0; 779 return 0;
775 break; 780 break;
@@ -1790,7 +1795,8 @@ static int snd_rme9652_initialize_memory(struct snd_rme9652 *rme9652)
1790 snd_hammerfall_get_buffer(rme9652->pci, &rme9652->playback_dma_buf, RME9652_DMA_AREA_BYTES) < 0) { 1795 snd_hammerfall_get_buffer(rme9652->pci, &rme9652->playback_dma_buf, RME9652_DMA_AREA_BYTES) < 0) {
1791 if (rme9652->capture_dma_buf.area) 1796 if (rme9652->capture_dma_buf.area)
1792 snd_dma_free_pages(&rme9652->capture_dma_buf); 1797 snd_dma_free_pages(&rme9652->capture_dma_buf);
1793 printk(KERN_ERR "%s: no buffers available\n", rme9652->card_name); 1798 dev_err(rme9652->card->dev,
1799 "%s: no buffers available\n", rme9652->card_name);
1794 return -ENOMEM; 1800 return -ENOMEM;
1795 } 1801 }
1796 1802
@@ -2468,13 +2474,14 @@ static int snd_rme9652_create(struct snd_card *card,
2468 rme9652->port = pci_resource_start(pci, 0); 2474 rme9652->port = pci_resource_start(pci, 0);
2469 rme9652->iobase = ioremap_nocache(rme9652->port, RME9652_IO_EXTENT); 2475 rme9652->iobase = ioremap_nocache(rme9652->port, RME9652_IO_EXTENT);
2470 if (rme9652->iobase == NULL) { 2476 if (rme9652->iobase == NULL) {
2471 snd_printk(KERN_ERR "unable to remap region 0x%lx-0x%lx\n", rme9652->port, rme9652->port + RME9652_IO_EXTENT - 1); 2477 dev_err(card->dev, "unable to remap region 0x%lx-0x%lx\n",
2478 rme9652->port, rme9652->port + RME9652_IO_EXTENT - 1);
2472 return -EBUSY; 2479 return -EBUSY;
2473 } 2480 }
2474 2481
2475 if (request_irq(pci->irq, snd_rme9652_interrupt, IRQF_SHARED, 2482 if (request_irq(pci->irq, snd_rme9652_interrupt, IRQF_SHARED,
2476 KBUILD_MODNAME, rme9652)) { 2483 KBUILD_MODNAME, rme9652)) {
2477 snd_printk(KERN_ERR "unable to request IRQ %d\n", pci->irq); 2484 dev_err(card->dev, "unable to request IRQ %d\n", pci->irq);
2478 return -EBUSY; 2485 return -EBUSY;
2479 } 2486 }
2480 rme9652->irq = pci->irq; 2487 rme9652->irq = pci->irq;
@@ -2587,8 +2594,8 @@ static int snd_rme9652_probe(struct pci_dev *pci,
2587 return -ENOENT; 2594 return -ENOENT;
2588 } 2595 }
2589 2596
2590 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 2597 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
2591 sizeof(struct snd_rme9652), &card); 2598 sizeof(struct snd_rme9652), &card);
2592 2599
2593 if (err < 0) 2600 if (err < 0)
2594 return err; 2601 return err;
@@ -2597,7 +2604,6 @@ static int snd_rme9652_probe(struct pci_dev *pci,
2597 card->private_free = snd_rme9652_card_free; 2604 card->private_free = snd_rme9652_card_free;
2598 rme9652->dev = dev; 2605 rme9652->dev = dev;
2599 rme9652->pci = pci; 2606 rme9652->pci = pci;
2600 snd_card_set_dev(card, &pci->dev);
2601 2607
2602 if ((err = snd_rme9652_create(card, rme9652, precise_ptr[dev])) < 0) { 2608 if ((err = snd_rme9652_create(card, rme9652, precise_ptr[dev])) < 0) {
2603 snd_card_free(card); 2609 snd_card_free(card);
diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c
index e413b4e2c819..6b26b93e001d 100644
--- a/sound/pci/sis7019.c
+++ b/sound/pci/sis7019.c
@@ -1404,8 +1404,6 @@ static int sis_chip_create(struct snd_card *card,
1404 if (rc) 1404 if (rc)
1405 goto error_out_cleanup; 1405 goto error_out_cleanup;
1406 1406
1407 snd_card_set_dev(card, &pci->dev);
1408
1409 return 0; 1407 return 0;
1410 1408
1411error_out_cleanup: 1409error_out_cleanup:
@@ -1440,7 +1438,8 @@ static int snd_sis7019_probe(struct pci_dev *pci,
1440 if (!codecs) 1438 if (!codecs)
1441 codecs = SIS_PRIMARY_CODEC_PRESENT; 1439 codecs = SIS_PRIMARY_CODEC_PRESENT;
1442 1440
1443 rc = snd_card_create(index, id, THIS_MODULE, sizeof(*sis), &card); 1441 rc = snd_card_new(&pci->dev, index, id, THIS_MODULE,
1442 sizeof(*sis), &card);
1444 if (rc < 0) 1443 if (rc < 0)
1445 goto error_out; 1444 goto error_out;
1446 1445
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index 2a46bf98af30..2044dc742071 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -273,7 +273,7 @@ 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(KERN_DEBUG "program dmaa: addr = 0x%x, paddr = 0x%x\n", 276 dev_dbg(sonic->card->dev, "program dmaa: addr = 0x%x, paddr = 0x%x\n",
277 addr, inl(sonic->dmaa_port + SV_DMA_ADDR0)); 277 addr, inl(sonic->dmaa_port + SV_DMA_ADDR0));
278#endif 278#endif
279} 279}
@@ -289,7 +289,7 @@ static inline void snd_sonicvibes_setdmac(struct sonicvibes * sonic,
289 outl(count, sonic->dmac_port + SV_DMA_COUNT0); 289 outl(count, sonic->dmac_port + SV_DMA_COUNT0);
290 outb(0x14, sonic->dmac_port + SV_DMA_MODE); 290 outb(0x14, sonic->dmac_port + SV_DMA_MODE);
291#if 0 291#if 0
292 printk(KERN_DEBUG "program dmac: addr = 0x%x, paddr = 0x%x\n", 292 dev_dbg(sonic->card->dev, "program dmac: addr = 0x%x, paddr = 0x%x\n",
293 addr, inl(sonic->dmac_port + SV_DMA_ADDR0)); 293 addr, inl(sonic->dmac_port + SV_DMA_ADDR0));
294#endif 294#endif
295} 295}
@@ -357,105 +357,105 @@ static unsigned char snd_sonicvibes_in(struct sonicvibes * sonic, unsigned char
357#if 0 357#if 0
358static void snd_sonicvibes_debug(struct sonicvibes * sonic) 358static void snd_sonicvibes_debug(struct sonicvibes * sonic)
359{ 359{
360 printk(KERN_DEBUG 360 dev_dbg(sonic->card->dev,
361 "SV REGS: INDEX = 0x%02x ", inb(SV_REG(sonic, INDEX))); 361 "SV REGS: INDEX = 0x%02x STATUS = 0x%02x\n",
362 printk(" STATUS = 0x%02x\n", inb(SV_REG(sonic, STATUS))); 362 inb(SV_REG(sonic, INDEX)), inb(SV_REG(sonic, STATUS)));
363 printk(KERN_DEBUG 363 dev_dbg(sonic->card->dev,
364 " 0x00: left input = 0x%02x ", snd_sonicvibes_in(sonic, 0x00)); 364 " 0x00: left input = 0x%02x 0x20: synth rate low = 0x%02x\n",
365 printk(" 0x20: synth rate low = 0x%02x\n", snd_sonicvibes_in(sonic, 0x20)); 365 snd_sonicvibes_in(sonic, 0x00), snd_sonicvibes_in(sonic, 0x20));
366 printk(KERN_DEBUG 366 dev_dbg(sonic->card->dev,
367 " 0x01: right input = 0x%02x ", snd_sonicvibes_in(sonic, 0x01)); 367 " 0x01: right input = 0x%02x 0x21: synth rate high = 0x%02x\n",
368 printk(" 0x21: synth rate high = 0x%02x\n", snd_sonicvibes_in(sonic, 0x21)); 368 snd_sonicvibes_in(sonic, 0x01), snd_sonicvibes_in(sonic, 0x21));
369 printk(KERN_DEBUG 369 dev_dbg(sonic->card->dev,
370 " 0x02: left AUX1 = 0x%02x ", snd_sonicvibes_in(sonic, 0x02)); 370 " 0x02: left AUX1 = 0x%02x 0x22: ADC clock = 0x%02x\n",
371 printk(" 0x22: ADC clock = 0x%02x\n", snd_sonicvibes_in(sonic, 0x22)); 371 snd_sonicvibes_in(sonic, 0x02), snd_sonicvibes_in(sonic, 0x22));
372 printk(KERN_DEBUG 372 dev_dbg(sonic->card->dev,
373 " 0x03: right AUX1 = 0x%02x ", snd_sonicvibes_in(sonic, 0x03)); 373 " 0x03: right AUX1 = 0x%02x 0x23: ADC alt rate = 0x%02x\n",
374 printk(" 0x23: ADC alt rate = 0x%02x\n", snd_sonicvibes_in(sonic, 0x23)); 374 snd_sonicvibes_in(sonic, 0x03), snd_sonicvibes_in(sonic, 0x23));
375 printk(KERN_DEBUG 375 dev_dbg(sonic->card->dev,
376 " 0x04: left CD = 0x%02x ", snd_sonicvibes_in(sonic, 0x04)); 376 " 0x04: left CD = 0x%02x 0x24: ADC pll M = 0x%02x\n",
377 printk(" 0x24: ADC pll M = 0x%02x\n", snd_sonicvibes_in(sonic, 0x24)); 377 snd_sonicvibes_in(sonic, 0x04), snd_sonicvibes_in(sonic, 0x24));
378 printk(KERN_DEBUG 378 dev_dbg(sonic->card->dev,
379 " 0x05: right CD = 0x%02x ", snd_sonicvibes_in(sonic, 0x05)); 379 " 0x05: right CD = 0x%02x 0x25: ADC pll N = 0x%02x\n",
380 printk(" 0x25: ADC pll N = 0x%02x\n", snd_sonicvibes_in(sonic, 0x25)); 380 snd_sonicvibes_in(sonic, 0x05), snd_sonicvibes_in(sonic, 0x25));
381 printk(KERN_DEBUG 381 dev_dbg(sonic->card->dev,
382 " 0x06: left line = 0x%02x ", snd_sonicvibes_in(sonic, 0x06)); 382 " 0x06: left line = 0x%02x 0x26: Synth pll M = 0x%02x\n",
383 printk(" 0x26: Synth pll M = 0x%02x\n", snd_sonicvibes_in(sonic, 0x26)); 383 snd_sonicvibes_in(sonic, 0x06), snd_sonicvibes_in(sonic, 0x26));
384 printk(KERN_DEBUG 384 dev_dbg(sonic->card->dev,
385 " 0x07: right line = 0x%02x ", snd_sonicvibes_in(sonic, 0x07)); 385 " 0x07: right line = 0x%02x 0x27: Synth pll N = 0x%02x\n",
386 printk(" 0x27: Synth pll N = 0x%02x\n", snd_sonicvibes_in(sonic, 0x27)); 386 snd_sonicvibes_in(sonic, 0x07), snd_sonicvibes_in(sonic, 0x27));
387 printk(KERN_DEBUG 387 dev_dbg(sonic->card->dev,
388 " 0x08: MIC = 0x%02x ", snd_sonicvibes_in(sonic, 0x08)); 388 " 0x08: MIC = 0x%02x 0x28: --- = 0x%02x\n",
389 printk(" 0x28: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x28)); 389 snd_sonicvibes_in(sonic, 0x08), snd_sonicvibes_in(sonic, 0x28));
390 printk(KERN_DEBUG 390 dev_dbg(sonic->card->dev,
391 " 0x09: Game port = 0x%02x ", snd_sonicvibes_in(sonic, 0x09)); 391 " 0x09: Game port = 0x%02x 0x29: --- = 0x%02x\n",
392 printk(" 0x29: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x29)); 392 snd_sonicvibes_in(sonic, 0x09), snd_sonicvibes_in(sonic, 0x29));
393 printk(KERN_DEBUG 393 dev_dbg(sonic->card->dev,
394 " 0x0a: left synth = 0x%02x ", snd_sonicvibes_in(sonic, 0x0a)); 394 " 0x0a: left synth = 0x%02x 0x2a: MPU401 = 0x%02x\n",
395 printk(" 0x2a: MPU401 = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2a)); 395 snd_sonicvibes_in(sonic, 0x0a), snd_sonicvibes_in(sonic, 0x2a));
396 printk(KERN_DEBUG 396 dev_dbg(sonic->card->dev,
397 " 0x0b: right synth = 0x%02x ", snd_sonicvibes_in(sonic, 0x0b)); 397 " 0x0b: right synth = 0x%02x 0x2b: drive ctrl = 0x%02x\n",
398 printk(" 0x2b: drive ctrl = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2b)); 398 snd_sonicvibes_in(sonic, 0x0b), snd_sonicvibes_in(sonic, 0x2b));
399 printk(KERN_DEBUG 399 dev_dbg(sonic->card->dev,
400 " 0x0c: left AUX2 = 0x%02x ", snd_sonicvibes_in(sonic, 0x0c)); 400 " 0x0c: left AUX2 = 0x%02x 0x2c: SRS space = 0x%02x\n",
401 printk(" 0x2c: SRS space = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2c)); 401 snd_sonicvibes_in(sonic, 0x0c), snd_sonicvibes_in(sonic, 0x2c));
402 printk(KERN_DEBUG 402 dev_dbg(sonic->card->dev,
403 " 0x0d: right AUX2 = 0x%02x ", snd_sonicvibes_in(sonic, 0x0d)); 403 " 0x0d: right AUX2 = 0x%02x 0x2d: SRS center = 0x%02x\n",
404 printk(" 0x2d: SRS center = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2d)); 404 snd_sonicvibes_in(sonic, 0x0d), snd_sonicvibes_in(sonic, 0x2d));
405 printk(KERN_DEBUG 405 dev_dbg(sonic->card->dev,
406 " 0x0e: left analog = 0x%02x ", snd_sonicvibes_in(sonic, 0x0e)); 406 " 0x0e: left analog = 0x%02x 0x2e: wave source = 0x%02x\n",
407 printk(" 0x2e: wave source = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2e)); 407 snd_sonicvibes_in(sonic, 0x0e), snd_sonicvibes_in(sonic, 0x2e));
408 printk(KERN_DEBUG 408 dev_dbg(sonic->card->dev,
409 " 0x0f: right analog = 0x%02x ", snd_sonicvibes_in(sonic, 0x0f)); 409 " 0x0f: right analog = 0x%02x 0x2f: --- = 0x%02x\n",
410 printk(" 0x2f: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2f)); 410 snd_sonicvibes_in(sonic, 0x0f), snd_sonicvibes_in(sonic, 0x2f));
411 printk(KERN_DEBUG 411 dev_dbg(sonic->card->dev,
412 " 0x10: left PCM = 0x%02x ", snd_sonicvibes_in(sonic, 0x10)); 412 " 0x10: left PCM = 0x%02x 0x30: analog power = 0x%02x\n",
413 printk(" 0x30: analog power = 0x%02x\n", snd_sonicvibes_in(sonic, 0x30)); 413 snd_sonicvibes_in(sonic, 0x10), snd_sonicvibes_in(sonic, 0x30));
414 printk(KERN_DEBUG 414 dev_dbg(sonic->card->dev,
415 " 0x11: right PCM = 0x%02x ", snd_sonicvibes_in(sonic, 0x11)); 415 " 0x11: right PCM = 0x%02x 0x31: analog power = 0x%02x\n",
416 printk(" 0x31: analog power = 0x%02x\n", snd_sonicvibes_in(sonic, 0x31)); 416 snd_sonicvibes_in(sonic, 0x11), snd_sonicvibes_in(sonic, 0x31));
417 printk(KERN_DEBUG 417 dev_dbg(sonic->card->dev,
418 " 0x12: DMA data format = 0x%02x ", snd_sonicvibes_in(sonic, 0x12)); 418 " 0x12: DMA data format = 0x%02x 0x32: --- = 0x%02x\n",
419 printk(" 0x32: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x32)); 419 snd_sonicvibes_in(sonic, 0x12), snd_sonicvibes_in(sonic, 0x32));
420 printk(KERN_DEBUG 420 dev_dbg(sonic->card->dev,
421 " 0x13: P/C enable = 0x%02x ", snd_sonicvibes_in(sonic, 0x13)); 421 " 0x13: P/C enable = 0x%02x 0x33: --- = 0x%02x\n",
422 printk(" 0x33: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x33)); 422 snd_sonicvibes_in(sonic, 0x13), snd_sonicvibes_in(sonic, 0x33));
423 printk(KERN_DEBUG 423 dev_dbg(sonic->card->dev,
424 " 0x14: U/D button = 0x%02x ", snd_sonicvibes_in(sonic, 0x14)); 424 " 0x14: U/D button = 0x%02x 0x34: --- = 0x%02x\n",
425 printk(" 0x34: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x34)); 425 snd_sonicvibes_in(sonic, 0x14), snd_sonicvibes_in(sonic, 0x34));
426 printk(KERN_DEBUG 426 dev_dbg(sonic->card->dev,
427 " 0x15: revision = 0x%02x ", snd_sonicvibes_in(sonic, 0x15)); 427 " 0x15: revision = 0x%02x 0x35: --- = 0x%02x\n",
428 printk(" 0x35: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x35)); 428 snd_sonicvibes_in(sonic, 0x15), snd_sonicvibes_in(sonic, 0x35));
429 printk(KERN_DEBUG 429 dev_dbg(sonic->card->dev,
430 " 0x16: ADC output ctrl = 0x%02x ", snd_sonicvibes_in(sonic, 0x16)); 430 " 0x16: ADC output ctrl = 0x%02x 0x36: --- = 0x%02x\n",
431 printk(" 0x36: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x36)); 431 snd_sonicvibes_in(sonic, 0x16), snd_sonicvibes_in(sonic, 0x36));
432 printk(KERN_DEBUG 432 dev_dbg(sonic->card->dev,
433 " 0x17: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x17)); 433 " 0x17: --- = 0x%02x 0x37: --- = 0x%02x\n",
434 printk(" 0x37: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x37)); 434 snd_sonicvibes_in(sonic, 0x17), snd_sonicvibes_in(sonic, 0x37));
435 printk(KERN_DEBUG 435 dev_dbg(sonic->card->dev,
436 " 0x18: DMA A upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x18)); 436 " 0x18: DMA A upper cnt = 0x%02x 0x38: --- = 0x%02x\n",
437 printk(" 0x38: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x38)); 437 snd_sonicvibes_in(sonic, 0x18), snd_sonicvibes_in(sonic, 0x38));
438 printk(KERN_DEBUG 438 dev_dbg(sonic->card->dev,
439 " 0x19: DMA A lower cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x19)); 439 " 0x19: DMA A lower cnt = 0x%02x 0x39: --- = 0x%02x\n",
440 printk(" 0x39: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x39)); 440 snd_sonicvibes_in(sonic, 0x19), snd_sonicvibes_in(sonic, 0x39));
441 printk(KERN_DEBUG 441 dev_dbg(sonic->card->dev,
442 " 0x1a: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x1a)); 442 " 0x1a: --- = 0x%02x 0x3a: --- = 0x%02x\n",
443 printk(" 0x3a: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3a)); 443 snd_sonicvibes_in(sonic, 0x1a), snd_sonicvibes_in(sonic, 0x3a));
444 printk(KERN_DEBUG 444 dev_dbg(sonic->card->dev,
445 " 0x1b: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x1b)); 445 " 0x1b: --- = 0x%02x 0x3b: --- = 0x%02x\n",
446 printk(" 0x3b: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3b)); 446 snd_sonicvibes_in(sonic, 0x1b), snd_sonicvibes_in(sonic, 0x3b));
447 printk(KERN_DEBUG 447 dev_dbg(sonic->card->dev,
448 " 0x1c: DMA C upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x1c)); 448 " 0x1c: DMA C upper cnt = 0x%02x 0x3c: --- = 0x%02x\n",
449 printk(" 0x3c: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3c)); 449 snd_sonicvibes_in(sonic, 0x1c), snd_sonicvibes_in(sonic, 0x3c));
450 printk(KERN_DEBUG 450 dev_dbg(sonic->card->dev,
451 " 0x1d: DMA C upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x1d)); 451 " 0x1d: DMA C upper cnt = 0x%02x 0x3d: --- = 0x%02x\n",
452 printk(" 0x3d: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3d)); 452 snd_sonicvibes_in(sonic, 0x1d), snd_sonicvibes_in(sonic, 0x3d));
453 printk(KERN_DEBUG 453 dev_dbg(sonic->card->dev,
454 " 0x1e: PCM rate low = 0x%02x ", snd_sonicvibes_in(sonic, 0x1e)); 454 " 0x1e: PCM rate low = 0x%02x 0x3e: --- = 0x%02x\n",
455 printk(" 0x3e: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3e)); 455 snd_sonicvibes_in(sonic, 0x1e), snd_sonicvibes_in(sonic, 0x3e));
456 printk(KERN_DEBUG 456 dev_dbg(sonic->card->dev,
457 " 0x1f: PCM rate high = 0x%02x ", snd_sonicvibes_in(sonic, 0x1f)); 457 " 0x1f: PCM rate high = 0x%02x 0x3f: --- = 0x%02x\n",
458 printk(" 0x3f: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3f)); 458 snd_sonicvibes_in(sonic, 0x1f), snd_sonicvibes_in(sonic, 0x3f));
459} 459}
460 460
461#endif 461#endif
@@ -511,8 +511,10 @@ static void snd_sonicvibes_pll(unsigned int rate,
511 *res_m = m; 511 *res_m = m;
512 *res_n = n; 512 *res_n = n;
513#if 0 513#if 0
514 printk(KERN_DEBUG "metric = %i, xm = %i, xn = %i\n", metric, xm, xn); 514 dev_dbg(sonic->card->dev,
515 printk(KERN_DEBUG "pll: m = 0x%x, r = 0x%x, n = 0x%x\n", reg, m, r, n); 515 "metric = %i, xm = %i, xn = %i\n", metric, xm, xn);
516 dev_dbg(sonic->card->dev,
517 "pll: m = 0x%x, r = 0x%x, n = 0x%x\n", reg, m, r, n);
516#endif 518#endif
517} 519}
518 520
@@ -624,7 +626,8 @@ static irqreturn_t snd_sonicvibes_interrupt(int irq, void *dev_id)
624 return IRQ_NONE; 626 return IRQ_NONE;
625 if (status == 0xff) { /* failure */ 627 if (status == 0xff) { /* failure */
626 outb(sonic->irqmask = ~0, SV_REG(sonic, IRQMASK)); 628 outb(sonic->irqmask = ~0, SV_REG(sonic, IRQMASK));
627 snd_printk(KERN_ERR "IRQ failure - interrupts disabled!!\n"); 629 dev_err(sonic->card->dev,
630 "IRQ failure - interrupts disabled!!\n");
628 return IRQ_HANDLED; 631 return IRQ_HANDLED;
629 } 632 }
630 if (sonic->pcm) { 633 if (sonic->pcm) {
@@ -1198,7 +1201,8 @@ static int snd_sonicvibes_create_gameport(struct sonicvibes *sonic)
1198 1201
1199 sonic->gameport = gp = gameport_allocate_port(); 1202 sonic->gameport = gp = gameport_allocate_port();
1200 if (!gp) { 1203 if (!gp) {
1201 printk(KERN_ERR "sonicvibes: cannot allocate memory for gameport\n"); 1204 dev_err(sonic->card->dev,
1205 "sonicvibes: cannot allocate memory for gameport\n");
1202 return -ENOMEM; 1206 return -ENOMEM;
1203 } 1207 }
1204 1208
@@ -1267,7 +1271,8 @@ static int snd_sonicvibes_create(struct snd_card *card,
1267 /* check, if we can restrict PCI DMA transfers to 24 bits */ 1271 /* check, if we can restrict PCI DMA transfers to 24 bits */
1268 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 || 1272 if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 ||
1269 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) { 1273 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) {
1270 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n"); 1274 dev_err(card->dev,
1275 "architecture does not support 24bit PCI busmaster DMA\n");
1271 pci_disable_device(pci); 1276 pci_disable_device(pci);
1272 return -ENXIO; 1277 return -ENXIO;
1273 } 1278 }
@@ -1296,7 +1301,7 @@ static int snd_sonicvibes_create(struct snd_card *card,
1296 1301
1297 if (request_irq(pci->irq, snd_sonicvibes_interrupt, IRQF_SHARED, 1302 if (request_irq(pci->irq, snd_sonicvibes_interrupt, IRQF_SHARED,
1298 KBUILD_MODNAME, sonic)) { 1303 KBUILD_MODNAME, sonic)) {
1299 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1304 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1300 snd_sonicvibes_free(sonic); 1305 snd_sonicvibes_free(sonic);
1301 return -EBUSY; 1306 return -EBUSY;
1302 } 1307 }
@@ -1310,24 +1315,32 @@ static int snd_sonicvibes_create(struct snd_card *card,
1310 if (!dmaa) { 1315 if (!dmaa) {
1311 dmaa = dmaio; 1316 dmaa = dmaio;
1312 dmaio += 0x10; 1317 dmaio += 0x10;
1313 snd_printk(KERN_INFO "BIOS did not allocate DDMA channel A i/o, allocated at 0x%x\n", dmaa); 1318 dev_info(card->dev,
1319 "BIOS did not allocate DDMA channel A i/o, allocated at 0x%x\n",
1320 dmaa);
1314 } 1321 }
1315 if (!dmac) { 1322 if (!dmac) {
1316 dmac = dmaio; 1323 dmac = dmaio;
1317 dmaio += 0x10; 1324 dmaio += 0x10;
1318 snd_printk(KERN_INFO "BIOS did not allocate DDMA channel C i/o, allocated at 0x%x\n", dmac); 1325 dev_info(card->dev,
1326 "BIOS did not allocate DDMA channel C i/o, allocated at 0x%x\n",
1327 dmac);
1319 } 1328 }
1320 pci_write_config_dword(pci, 0x40, dmaa); 1329 pci_write_config_dword(pci, 0x40, dmaa);
1321 pci_write_config_dword(pci, 0x48, dmac); 1330 pci_write_config_dword(pci, 0x48, dmac);
1322 1331
1323 if ((sonic->res_dmaa = request_region(dmaa, 0x10, "S3 SonicVibes DDMA-A")) == NULL) { 1332 if ((sonic->res_dmaa = request_region(dmaa, 0x10, "S3 SonicVibes DDMA-A")) == NULL) {
1324 snd_sonicvibes_free(sonic); 1333 snd_sonicvibes_free(sonic);
1325 snd_printk(KERN_ERR "unable to grab DDMA-A port at 0x%x-0x%x\n", dmaa, dmaa + 0x10 - 1); 1334 dev_err(card->dev,
1335 "unable to grab DDMA-A port at 0x%x-0x%x\n",
1336 dmaa, dmaa + 0x10 - 1);
1326 return -EBUSY; 1337 return -EBUSY;
1327 } 1338 }
1328 if ((sonic->res_dmac = request_region(dmac, 0x10, "S3 SonicVibes DDMA-C")) == NULL) { 1339 if ((sonic->res_dmac = request_region(dmac, 0x10, "S3 SonicVibes DDMA-C")) == NULL) {
1329 snd_sonicvibes_free(sonic); 1340 snd_sonicvibes_free(sonic);
1330 snd_printk(KERN_ERR "unable to grab DDMA-C port at 0x%x-0x%x\n", dmac, dmac + 0x10 - 1); 1341 dev_err(card->dev,
1342 "unable to grab DDMA-C port at 0x%x-0x%x\n",
1343 dmac, dmac + 0x10 - 1);
1331 return -EBUSY; 1344 return -EBUSY;
1332 } 1345 }
1333 1346
@@ -1392,8 +1405,6 @@ static int snd_sonicvibes_create(struct snd_card *card,
1392 1405
1393 snd_sonicvibes_proc_init(sonic); 1406 snd_sonicvibes_proc_init(sonic);
1394 1407
1395 snd_card_set_dev(card, &pci->dev);
1396
1397 *rsonic = sonic; 1408 *rsonic = sonic;
1398 return 0; 1409 return 0;
1399} 1410}
@@ -1459,7 +1470,8 @@ static int snd_sonic_probe(struct pci_dev *pci,
1459 return -ENOENT; 1470 return -ENOENT;
1460 } 1471 }
1461 1472
1462 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 1473 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1474 0, &card);
1463 if (err < 0) 1475 if (err < 0)
1464 return err; 1476 return err;
1465 for (idx = 0; idx < 5; idx++) { 1477 for (idx = 0; idx < 5; idx++) {
diff --git a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c
index b3b588bc94c3..d852458caf38 100644
--- a/sound/pci/trident/trident.c
+++ b/sound/pci/trident/trident.c
@@ -89,7 +89,8 @@ static int snd_trident_probe(struct pci_dev *pci,
89 return -ENOENT; 89 return -ENOENT;
90 } 90 }
91 91
92 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 92 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
93 0, &card);
93 if (err < 0) 94 if (err < 0)
94 return err; 95 return err;
95 96
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index fb0e1586a6f8..1272c18a2544 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -69,40 +69,40 @@ static void snd_trident_print_voice_regs(struct snd_trident *trident, int voice)
69{ 69{
70 unsigned int val, tmp; 70 unsigned int val, tmp;
71 71
72 printk(KERN_DEBUG "Trident voice %i:\n", voice); 72 dev_dbg(trident->card->dev, "Trident voice %i:\n", voice);
73 outb(voice, TRID_REG(trident, T4D_LFO_GC_CIR)); 73 outb(voice, TRID_REG(trident, T4D_LFO_GC_CIR));
74 val = inl(TRID_REG(trident, CH_LBA)); 74 val = inl(TRID_REG(trident, CH_LBA));
75 printk(KERN_DEBUG "LBA: 0x%x\n", val); 75 dev_dbg(trident->card->dev, "LBA: 0x%x\n", val);
76 val = inl(TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC)); 76 val = inl(TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC));
77 printk(KERN_DEBUG "GVSel: %i\n", val >> 31); 77 dev_dbg(trident->card->dev, "GVSel: %i\n", val >> 31);
78 printk(KERN_DEBUG "Pan: 0x%x\n", (val >> 24) & 0x7f); 78 dev_dbg(trident->card->dev, "Pan: 0x%x\n", (val >> 24) & 0x7f);
79 printk(KERN_DEBUG "Vol: 0x%x\n", (val >> 16) & 0xff); 79 dev_dbg(trident->card->dev, "Vol: 0x%x\n", (val >> 16) & 0xff);
80 printk(KERN_DEBUG "CTRL: 0x%x\n", (val >> 12) & 0x0f); 80 dev_dbg(trident->card->dev, "CTRL: 0x%x\n", (val >> 12) & 0x0f);
81 printk(KERN_DEBUG "EC: 0x%x\n", val & 0x0fff); 81 dev_dbg(trident->card->dev, "EC: 0x%x\n", val & 0x0fff);
82 if (trident->device != TRIDENT_DEVICE_ID_NX) { 82 if (trident->device != TRIDENT_DEVICE_ID_NX) {
83 val = inl(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS)); 83 val = inl(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS));
84 printk(KERN_DEBUG "CSO: 0x%x\n", val >> 16); 84 dev_dbg(trident->card->dev, "CSO: 0x%x\n", val >> 16);
85 printk("Alpha: 0x%x\n", (val >> 4) & 0x0fff); 85 dev_dbg(trident->card->dev, "Alpha: 0x%x\n", (val >> 4) & 0x0fff);
86 printk(KERN_DEBUG "FMS: 0x%x\n", val & 0x0f); 86 dev_dbg(trident->card->dev, "FMS: 0x%x\n", val & 0x0f);
87 val = inl(TRID_REG(trident, CH_DX_ESO_DELTA)); 87 val = inl(TRID_REG(trident, CH_DX_ESO_DELTA));
88 printk(KERN_DEBUG "ESO: 0x%x\n", val >> 16); 88 dev_dbg(trident->card->dev, "ESO: 0x%x\n", val >> 16);
89 printk(KERN_DEBUG "Delta: 0x%x\n", val & 0xffff); 89 dev_dbg(trident->card->dev, "Delta: 0x%x\n", val & 0xffff);
90 val = inl(TRID_REG(trident, CH_DX_FMC_RVOL_CVOL)); 90 val = inl(TRID_REG(trident, CH_DX_FMC_RVOL_CVOL));
91 } else { // TRIDENT_DEVICE_ID_NX 91 } else { // TRIDENT_DEVICE_ID_NX
92 val = inl(TRID_REG(trident, CH_NX_DELTA_CSO)); 92 val = inl(TRID_REG(trident, CH_NX_DELTA_CSO));
93 tmp = (val >> 24) & 0xff; 93 tmp = (val >> 24) & 0xff;
94 printk(KERN_DEBUG "CSO: 0x%x\n", val & 0x00ffffff); 94 dev_dbg(trident->card->dev, "CSO: 0x%x\n", val & 0x00ffffff);
95 val = inl(TRID_REG(trident, CH_NX_DELTA_ESO)); 95 val = inl(TRID_REG(trident, CH_NX_DELTA_ESO));
96 tmp |= (val >> 16) & 0xff00; 96 tmp |= (val >> 16) & 0xff00;
97 printk(KERN_DEBUG "Delta: 0x%x\n", tmp); 97 dev_dbg(trident->card->dev, "Delta: 0x%x\n", tmp);
98 printk(KERN_DEBUG "ESO: 0x%x\n", val & 0x00ffffff); 98 dev_dbg(trident->card->dev, "ESO: 0x%x\n", val & 0x00ffffff);
99 val = inl(TRID_REG(trident, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL)); 99 val = inl(TRID_REG(trident, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL));
100 printk(KERN_DEBUG "Alpha: 0x%x\n", val >> 20); 100 dev_dbg(trident->card->dev, "Alpha: 0x%x\n", val >> 20);
101 printk(KERN_DEBUG "FMS: 0x%x\n", (val >> 16) & 0x0f); 101 dev_dbg(trident->card->dev, "FMS: 0x%x\n", (val >> 16) & 0x0f);
102 } 102 }
103 printk(KERN_DEBUG "FMC: 0x%x\n", (val >> 14) & 3); 103 dev_dbg(trident->card->dev, "FMC: 0x%x\n", (val >> 14) & 3);
104 printk(KERN_DEBUG "RVol: 0x%x\n", (val >> 7) & 0x7f); 104 dev_dbg(trident->card->dev, "RVol: 0x%x\n", (val >> 7) & 0x7f);
105 printk(KERN_DEBUG "CVol: 0x%x\n", val & 0x7f); 105 dev_dbg(trident->card->dev, "CVol: 0x%x\n", val & 0x7f);
106} 106}
107#endif 107#endif
108 108
@@ -156,7 +156,8 @@ static unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned sho
156 } 156 }
157 157
158 if (count == 0 && !trident->ac97_detect) { 158 if (count == 0 && !trident->ac97_detect) {
159 snd_printk(KERN_ERR "ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n", 159 dev_err(trident->card->dev,
160 "ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n",
160 reg, data); 161 reg, data);
161 data = 0; 162 data = 0;
162 } 163 }
@@ -497,16 +498,16 @@ void snd_trident_write_voice_regs(struct snd_trident * trident,
497 outl(regs[4], TRID_REG(trident, CH_START + 16)); 498 outl(regs[4], TRID_REG(trident, CH_START + 16));
498 499
499#if 0 500#if 0
500 printk(KERN_DEBUG "written %i channel:\n", voice->number); 501 dev_dbg(trident->card->dev, "written %i channel:\n", voice->number);
501 printk(KERN_DEBUG " regs[0] = 0x%x/0x%x\n", 502 dev_dbg(trident->card->dev, " regs[0] = 0x%x/0x%x\n",
502 regs[0], inl(TRID_REG(trident, CH_START + 0))); 503 regs[0], inl(TRID_REG(trident, CH_START + 0)));
503 printk(KERN_DEBUG " regs[1] = 0x%x/0x%x\n", 504 dev_dbg(trident->card->dev, " regs[1] = 0x%x/0x%x\n",
504 regs[1], inl(TRID_REG(trident, CH_START + 4))); 505 regs[1], inl(TRID_REG(trident, CH_START + 4)));
505 printk(KERN_DEBUG " regs[2] = 0x%x/0x%x\n", 506 dev_dbg(trident->card->dev, " regs[2] = 0x%x/0x%x\n",
506 regs[2], inl(TRID_REG(trident, CH_START + 8))); 507 regs[2], inl(TRID_REG(trident, CH_START + 8)));
507 printk(KERN_DEBUG " regs[3] = 0x%x/0x%x\n", 508 dev_dbg(trident->card->dev, " regs[3] = 0x%x/0x%x\n",
508 regs[3], inl(TRID_REG(trident, CH_START + 12))); 509 regs[3], inl(TRID_REG(trident, CH_START + 12)));
509 printk(KERN_DEBUG " regs[4] = 0x%x/0x%x\n", 510 dev_dbg(trident->card->dev, " regs[4] = 0x%x/0x%x\n",
510 regs[4], inl(TRID_REG(trident, CH_START + 16))); 511 regs[4], inl(TRID_REG(trident, CH_START + 16)));
511#endif 512#endif
512} 513}
@@ -589,7 +590,7 @@ static void snd_trident_write_vol_reg(struct snd_trident * trident,
589 outb(voice->Vol >> 2, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 2)); 590 outb(voice->Vol >> 2, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 2));
590 break; 591 break;
591 case TRIDENT_DEVICE_ID_SI7018: 592 case TRIDENT_DEVICE_ID_SI7018:
592 /* printk(KERN_DEBUG "voice->Vol = 0x%x\n", voice->Vol); */ 593 /* dev_dbg(trident->card->dev, "voice->Vol = 0x%x\n", voice->Vol); */
593 outw((voice->CTRL << 12) | voice->Vol, 594 outw((voice->CTRL << 12) | voice->Vol,
594 TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC)); 595 TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC));
595 break; 596 break;
@@ -3013,13 +3014,15 @@ static int snd_trident_mixer(struct snd_trident *trident, int pcm_spdif_device)
3013 _ac97.num = 1; 3014 _ac97.num = 1;
3014 err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec); 3015 err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec);
3015 if (err < 0) 3016 if (err < 0)
3016 snd_printk(KERN_ERR "SI7018: the secondary codec - invalid access\n"); 3017 dev_err(trident->card->dev,
3018 "SI7018: the secondary codec - invalid access\n");
3017#if 0 // only for my testing purpose --jk 3019#if 0 // only for my testing purpose --jk
3018 { 3020 {
3019 struct snd_ac97 *mc97; 3021 struct snd_ac97 *mc97;
3020 err = snd_ac97_modem(trident->card, &_ac97, &mc97); 3022 err = snd_ac97_modem(trident->card, &_ac97, &mc97);
3021 if (err < 0) 3023 if (err < 0)
3022 snd_printk(KERN_ERR "snd_ac97_modem returned error %i\n", err); 3024 dev_err(trident->card->dev,
3025 "snd_ac97_modem returned error %i\n", err);
3023 } 3026 }
3024#endif 3027#endif
3025 } 3028 }
@@ -3197,7 +3200,8 @@ int snd_trident_create_gameport(struct snd_trident *chip)
3197 3200
3198 chip->gameport = gp = gameport_allocate_port(); 3201 chip->gameport = gp = gameport_allocate_port();
3199 if (!gp) { 3202 if (!gp) {
3200 printk(KERN_ERR "trident: cannot allocate memory for gameport\n"); 3203 dev_err(chip->card->dev,
3204 "cannot allocate memory for gameport\n");
3201 return -ENOMEM; 3205 return -ENOMEM;
3202 } 3206 }
3203 3207
@@ -3270,7 +3274,8 @@ static int snd_trident_sis_reset(struct snd_trident *trident)
3270 goto __si7018_ok; 3274 goto __si7018_ok;
3271 do_delay(trident); 3275 do_delay(trident);
3272 } while (time_after_eq(end_time, jiffies)); 3276 } while (time_after_eq(end_time, jiffies));
3273 snd_printk(KERN_ERR "AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL))); 3277 dev_err(trident->card->dev, "AC'97 codec ready error [0x%x]\n",
3278 inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)));
3274 if (r-- > 0) { 3279 if (r-- > 0) {
3275 end_time = jiffies + HZ; 3280 end_time = jiffies + HZ;
3276 do { 3281 do {
@@ -3367,7 +3372,7 @@ static int snd_trident_tlb_alloc(struct snd_trident *trident)
3367 3372
3368 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci), 3373 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci),
3369 2 * SNDRV_TRIDENT_MAX_PAGES * 4, &trident->tlb.buffer) < 0) { 3374 2 * SNDRV_TRIDENT_MAX_PAGES * 4, &trident->tlb.buffer) < 0) {
3370 snd_printk(KERN_ERR "trident: unable to allocate TLB buffer\n"); 3375 dev_err(trident->card->dev, "unable to allocate TLB buffer\n");
3371 return -ENOMEM; 3376 return -ENOMEM;
3372 } 3377 }
3373 trident->tlb.entries = (unsigned int*)ALIGN((unsigned long)trident->tlb.buffer.area, SNDRV_TRIDENT_MAX_PAGES * 4); 3378 trident->tlb.entries = (unsigned int*)ALIGN((unsigned long)trident->tlb.buffer.area, SNDRV_TRIDENT_MAX_PAGES * 4);
@@ -3375,13 +3380,14 @@ static int snd_trident_tlb_alloc(struct snd_trident *trident)
3375 /* allocate shadow TLB page table (virtual addresses) */ 3380 /* allocate shadow TLB page table (virtual addresses) */
3376 trident->tlb.shadow_entries = vmalloc(SNDRV_TRIDENT_MAX_PAGES*sizeof(unsigned long)); 3381 trident->tlb.shadow_entries = vmalloc(SNDRV_TRIDENT_MAX_PAGES*sizeof(unsigned long));
3377 if (trident->tlb.shadow_entries == NULL) { 3382 if (trident->tlb.shadow_entries == NULL) {
3378 snd_printk(KERN_ERR "trident: unable to allocate shadow TLB entries\n"); 3383 dev_err(trident->card->dev,
3384 "unable to allocate shadow TLB entries\n");
3379 return -ENOMEM; 3385 return -ENOMEM;
3380 } 3386 }
3381 /* allocate and setup silent page and initialise TLB entries */ 3387 /* allocate and setup silent page and initialise TLB entries */
3382 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci), 3388 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci),
3383 SNDRV_TRIDENT_PAGE_SIZE, &trident->tlb.silent_page) < 0) { 3389 SNDRV_TRIDENT_PAGE_SIZE, &trident->tlb.silent_page) < 0) {
3384 snd_printk(KERN_ERR "trident: unable to allocate silent page\n"); 3390 dev_err(trident->card->dev, "unable to allocate silent page\n");
3385 return -ENOMEM; 3391 return -ENOMEM;
3386 } 3392 }
3387 memset(trident->tlb.silent_page.area, 0, SNDRV_TRIDENT_PAGE_SIZE); 3393 memset(trident->tlb.silent_page.area, 0, SNDRV_TRIDENT_PAGE_SIZE);
@@ -3439,7 +3445,7 @@ static int snd_trident_4d_dx_init(struct snd_trident *trident)
3439 goto __dx_ok; 3445 goto __dx_ok;
3440 do_delay(trident); 3446 do_delay(trident);
3441 } while (time_after_eq(end_time, jiffies)); 3447 } while (time_after_eq(end_time, jiffies));
3442 snd_printk(KERN_ERR "AC'97 codec ready error\n"); 3448 dev_err(trident->card->dev, "AC'97 codec ready error\n");
3443 return -EIO; 3449 return -EIO;
3444 3450
3445 __dx_ok: 3451 __dx_ok:
@@ -3477,7 +3483,8 @@ static int snd_trident_4d_nx_init(struct snd_trident *trident)
3477 goto __nx_ok; 3483 goto __nx_ok;
3478 do_delay(trident); 3484 do_delay(trident);
3479 } while (time_after_eq(end_time, jiffies)); 3485 } while (time_after_eq(end_time, jiffies));
3480 snd_printk(KERN_ERR "AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT))); 3486 dev_err(trident->card->dev, "AC'97 codec ready error [0x%x]\n",
3487 inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT)));
3481 return -EIO; 3488 return -EIO;
3482 3489
3483 __nx_ok: 3490 __nx_ok:
@@ -3562,7 +3569,8 @@ int snd_trident_create(struct snd_card *card,
3562 /* check, if we can restrict PCI DMA transfers to 30 bits */ 3569 /* check, if we can restrict PCI DMA transfers to 30 bits */
3563 if (pci_set_dma_mask(pci, DMA_BIT_MASK(30)) < 0 || 3570 if (pci_set_dma_mask(pci, DMA_BIT_MASK(30)) < 0 ||
3564 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(30)) < 0) { 3571 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(30)) < 0) {
3565 snd_printk(KERN_ERR "architecture does not support 30bit PCI busmaster DMA\n"); 3572 dev_err(card->dev,
3573 "architecture does not support 30bit PCI busmaster DMA\n");
3566 pci_disable_device(pci); 3574 pci_disable_device(pci);
3567 return -ENXIO; 3575 return -ENXIO;
3568 } 3576 }
@@ -3600,7 +3608,7 @@ int snd_trident_create(struct snd_card *card,
3600 3608
3601 if (request_irq(pci->irq, snd_trident_interrupt, IRQF_SHARED, 3609 if (request_irq(pci->irq, snd_trident_interrupt, IRQF_SHARED,
3602 KBUILD_MODNAME, trident)) { 3610 KBUILD_MODNAME, trident)) {
3603 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 3611 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
3604 snd_trident_free(trident); 3612 snd_trident_free(trident);
3605 return -EBUSY; 3613 return -EBUSY;
3606 } 3614 }
@@ -3664,7 +3672,6 @@ int snd_trident_create(struct snd_card *card,
3664 snd_trident_enable_eso(trident); 3672 snd_trident_enable_eso(trident);
3665 3673
3666 snd_trident_proc_init(trident); 3674 snd_trident_proc_init(trident);
3667 snd_card_set_dev(card, &pci->dev);
3668 *rtrident = trident; 3675 *rtrident = trident;
3669 return 0; 3676 return 0;
3670} 3677}
@@ -3950,8 +3957,7 @@ static int snd_trident_resume(struct device *dev)
3950 pci_set_power_state(pci, PCI_D0); 3957 pci_set_power_state(pci, PCI_D0);
3951 pci_restore_state(pci); 3958 pci_restore_state(pci);
3952 if (pci_enable_device(pci) < 0) { 3959 if (pci_enable_device(pci) < 0) {
3953 printk(KERN_ERR "trident: pci_enable_device failed, " 3960 dev_err(dev, "pci_enable_device failed, disabling device\n");
3954 "disabling device\n");
3955 snd_card_disconnect(card); 3961 snd_card_disconnect(card);
3956 return -EIO; 3962 return -EIO;
3957 } 3963 }
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 5ae6f042c586..95b98f537b67 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -459,7 +459,7 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
459 unsigned int addr; 459 unsigned int addr;
460 460
461 if (idx >= VIA_TABLE_SIZE) { 461 if (idx >= VIA_TABLE_SIZE) {
462 snd_printk(KERN_ERR "via82xx: too much table size!\n"); 462 dev_err(&pci->dev, "too much table size!\n");
463 return -EINVAL; 463 return -EINVAL;
464 } 464 }
465 addr = snd_pcm_sgbuf_get_addr(substream, ofs); 465 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
@@ -474,8 +474,9 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
474 } else 474 } else
475 flag = 0; /* period continues to the next */ 475 flag = 0; /* period continues to the next */
476 /* 476 /*
477 printk(KERN_DEBUG "via: tbl %d: at %d size %d " 477 dev_dbg(&pci->dev,
478 "(rest %d)\n", idx, ofs, r, rest); 478 "tbl %d: at %d size %d (rest %d)\n",
479 idx, ofs, r, rest);
479 */ 480 */
480 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag); 481 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag);
481 dev->idx_table[idx].offset = ofs; 482 dev->idx_table[idx].offset = ofs;
@@ -528,7 +529,7 @@ static int snd_via82xx_codec_ready(struct via82xx *chip, int secondary)
528 if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)) 529 if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY))
529 return val & 0xffff; 530 return val & 0xffff;
530 } 531 }
531 snd_printk(KERN_ERR "codec_ready: codec %i is not ready [0x%x]\n", 532 dev_err(chip->card->dev, "codec_ready: codec %i is not ready [0x%x]\n",
532 secondary, snd_via82xx_codec_xread(chip)); 533 secondary, snd_via82xx_codec_xread(chip));
533 return -EIO; 534 return -EIO;
534} 535}
@@ -587,7 +588,8 @@ static unsigned short snd_via82xx_codec_read(struct snd_ac97 *ac97, unsigned sho
587 xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT; 588 xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT;
588 while (1) { 589 while (1) {
589 if (again++ > 3) { 590 if (again++ > 3) {
590 snd_printk(KERN_ERR "codec_read: codec %i is not valid [0x%x]\n", 591 dev_err(chip->card->dev,
592 "codec_read: codec %i is not valid [0x%x]\n",
591 ac97->num, snd_via82xx_codec_xread(chip)); 593 ac97->num, snd_via82xx_codec_xread(chip));
592 return 0xffff; 594 return 0xffff;
593 } 595 }
@@ -777,7 +779,9 @@ static int snd_via82xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
777 ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\ 779 ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\
778 viadev->lastpos < viadev->bufsize2)) 780 viadev->lastpos < viadev->bufsize2))
779 781
780static inline unsigned int calc_linear_pos(struct viadev *viadev, unsigned int idx, 782static inline unsigned int calc_linear_pos(struct via82xx *chip,
783 struct viadev *viadev,
784 unsigned int idx,
781 unsigned int count) 785 unsigned int count)
782{ 786{
783 unsigned int size, base, res; 787 unsigned int size, base, res;
@@ -790,7 +794,8 @@ static inline unsigned int calc_linear_pos(struct viadev *viadev, unsigned int i
790 794
791 /* check the validity of the calculated position */ 795 /* check the validity of the calculated position */
792 if (size < count) { 796 if (size < count) {
793 snd_printd(KERN_ERR "invalid via82xx_cur_ptr (size = %d, count = %d)\n", 797 dev_dbg(chip->card->dev,
798 "invalid via82xx_cur_ptr (size = %d, count = %d)\n",
794 (int)size, (int)count); 799 (int)size, (int)count);
795 res = viadev->lastpos; 800 res = viadev->lastpos;
796 } else { 801 } else {
@@ -807,9 +812,9 @@ static inline unsigned int calc_linear_pos(struct viadev *viadev, unsigned int i
807 } 812 }
808 if (check_invalid_pos(viadev, res)) { 813 if (check_invalid_pos(viadev, res)) {
809#ifdef POINTER_DEBUG 814#ifdef POINTER_DEBUG
810 printk(KERN_DEBUG "fail: idx = %i/%i, lastpos = 0x%x, " 815 dev_dbg(chip->card->dev,
811 "bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, " 816 "fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n",
812 "count = 0x%x\n", idx, viadev->tbl_entries, 817 idx, viadev->tbl_entries,
813 viadev->lastpos, viadev->bufsize2, 818 viadev->lastpos, viadev->bufsize2,
814 viadev->idx_table[idx].offset, 819 viadev->idx_table[idx].offset,
815 viadev->idx_table[idx].size, count); 820 viadev->idx_table[idx].size, count);
@@ -817,8 +822,8 @@ static inline unsigned int calc_linear_pos(struct viadev *viadev, unsigned int i
817 /* count register returns full size when end of buffer is reached */ 822 /* count register returns full size when end of buffer is reached */
818 res = base + size; 823 res = base + size;
819 if (check_invalid_pos(viadev, res)) { 824 if (check_invalid_pos(viadev, res)) {
820 snd_printd(KERN_ERR "invalid via82xx_cur_ptr (2), " 825 dev_dbg(chip->card->dev,
821 "using last valid pointer\n"); 826 "invalid via82xx_cur_ptr (2), using last valid pointer\n");
822 res = viadev->lastpos; 827 res = viadev->lastpos;
823 } 828 }
824 } 829 }
@@ -850,7 +855,7 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substr
850 idx = 0; 855 idx = 0;
851 else /* CURR_PTR holds the address + 8 */ 856 else /* CURR_PTR holds the address + 8 */
852 idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries; 857 idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries;
853 res = calc_linear_pos(viadev, idx, count); 858 res = calc_linear_pos(chip, viadev, idx, count);
854 viadev->lastpos = res; /* remember the last position */ 859 viadev->lastpos = res; /* remember the last position */
855 spin_unlock(&chip->reg_lock); 860 spin_unlock(&chip->reg_lock);
856 861
@@ -889,13 +894,14 @@ static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *subst
889 idx = count >> 24; 894 idx = count >> 24;
890 if (idx >= viadev->tbl_entries) { 895 if (idx >= viadev->tbl_entries) {
891#ifdef POINTER_DEBUG 896#ifdef POINTER_DEBUG
892 printk(KERN_DEBUG "fail: invalid idx = %i/%i\n", idx, 897 dev_dbg(chip->card->dev,
898 "fail: invalid idx = %i/%i\n", idx,
893 viadev->tbl_entries); 899 viadev->tbl_entries);
894#endif 900#endif
895 res = viadev->lastpos; 901 res = viadev->lastpos;
896 } else { 902 } else {
897 count &= 0xffffff; 903 count &= 0xffffff;
898 res = calc_linear_pos(viadev, idx, count); 904 res = calc_linear_pos(chip, viadev, idx, count);
899 } 905 }
900 } else { 906 } else {
901 res = viadev->hwptr_done; 907 res = viadev->hwptr_done;
@@ -1940,14 +1946,15 @@ static int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legac
1940 1946
1941 r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport"); 1947 r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport");
1942 if (!r) { 1948 if (!r) {
1943 printk(KERN_WARNING "via82xx: cannot reserve joystick port %#x\n", 1949 dev_warn(chip->card->dev, "cannot reserve joystick port %#x\n",
1944 JOYSTICK_ADDR); 1950 JOYSTICK_ADDR);
1945 return -EBUSY; 1951 return -EBUSY;
1946 } 1952 }
1947 1953
1948 chip->gameport = gp = gameport_allocate_port(); 1954 chip->gameport = gp = gameport_allocate_port();
1949 if (!gp) { 1955 if (!gp) {
1950 printk(KERN_ERR "via82xx: cannot allocate memory for gameport\n"); 1956 dev_err(chip->card->dev,
1957 "cannot allocate memory for gameport\n");
1951 release_and_free_resource(r); 1958 release_and_free_resource(r);
1952 return -ENOMEM; 1959 return -ENOMEM;
1953 } 1960 }
@@ -2016,7 +2023,8 @@ static int snd_via8233_init_misc(struct via82xx *chip)
2016 strcpy(sid.name, "PCM Playback Volume"); 2023 strcpy(sid.name, "PCM Playback Volume");
2017 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2024 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2018 if (! snd_ctl_find_id(chip->card, &sid)) { 2025 if (! snd_ctl_find_id(chip->card, &sid)) {
2019 snd_printd(KERN_INFO "Using DXS as PCM Playback\n"); 2026 dev_info(chip->card->dev,
2027 "Using DXS as PCM Playback\n");
2020 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_pcmdxs_volume_control, chip)); 2028 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_pcmdxs_volume_control, chip));
2021 if (err < 0) 2029 if (err < 0)
2022 return err; 2030 return err;
@@ -2102,8 +2110,9 @@ static int snd_via686_init_misc(struct via82xx *chip)
2102 mpu_port, MPU401_INFO_INTEGRATED | 2110 mpu_port, MPU401_INFO_INTEGRATED |
2103 MPU401_INFO_IRQ_HOOK, -1, 2111 MPU401_INFO_IRQ_HOOK, -1,
2104 &chip->rmidi) < 0) { 2112 &chip->rmidi) < 0) {
2105 printk(KERN_WARNING "unable to initialize MPU-401" 2113 dev_warn(chip->card->dev,
2106 " at 0x%lx, skipping\n", mpu_port); 2114 "unable to initialize MPU-401 at 0x%lx, skipping\n",
2115 mpu_port);
2107 legacy &= ~VIA_FUNC_ENABLE_MIDI; 2116 legacy &= ~VIA_FUNC_ENABLE_MIDI;
2108 } else { 2117 } else {
2109 legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */ 2118 legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */
@@ -2203,7 +2212,8 @@ static int snd_via82xx_chip_init(struct via82xx *chip)
2203 } while (time_before(jiffies, end_time)); 2212 } while (time_before(jiffies, end_time));
2204 2213
2205 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 2214 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)
2206 snd_printk(KERN_ERR "AC'97 codec is not ready [0x%x]\n", val); 2215 dev_err(chip->card->dev,
2216 "AC'97 codec is not ready [0x%x]\n", val);
2207 2217
2208#if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */ 2218#if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */
2209 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 2219 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
@@ -2303,8 +2313,7 @@ static int snd_via82xx_resume(struct device *dev)
2303 pci_set_power_state(pci, PCI_D0); 2313 pci_set_power_state(pci, PCI_D0);
2304 pci_restore_state(pci); 2314 pci_restore_state(pci);
2305 if (pci_enable_device(pci) < 0) { 2315 if (pci_enable_device(pci) < 0) {
2306 printk(KERN_ERR "via82xx: pci_enable_device failed, " 2316 dev_err(dev, "pci_enable_device failed, disabling device\n");
2307 "disabling device\n");
2308 snd_card_disconnect(card); 2317 snd_card_disconnect(card);
2309 return -EIO; 2318 return -EIO;
2310 } 2319 }
@@ -2417,7 +2426,7 @@ static int snd_via82xx_create(struct snd_card *card,
2417 snd_via8233_interrupt : snd_via686_interrupt, 2426 snd_via8233_interrupt : snd_via686_interrupt,
2418 IRQF_SHARED, 2427 IRQF_SHARED,
2419 KBUILD_MODNAME, chip)) { 2428 KBUILD_MODNAME, chip)) {
2420 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 2429 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
2421 snd_via82xx_free(chip); 2430 snd_via82xx_free(chip);
2422 return -EBUSY; 2431 return -EBUSY;
2423 } 2432 }
@@ -2441,8 +2450,6 @@ static int snd_via82xx_create(struct snd_card *card,
2441 * We call pci_set_master here because it does not hurt. */ 2450 * We call pci_set_master here because it does not hurt. */
2442 pci_set_master(pci); 2451 pci_set_master(pci);
2443 2452
2444 snd_card_set_dev(card, &pci->dev);
2445
2446 *r_via = chip; 2453 *r_via = chip;
2447 return 0; 2454 return 0;
2448} 2455}
@@ -2516,7 +2523,7 @@ static int check_dxs_list(struct pci_dev *pci, int revision)
2516 2523
2517 w = snd_pci_quirk_lookup(pci, dxs_whitelist); 2524 w = snd_pci_quirk_lookup(pci, dxs_whitelist);
2518 if (w) { 2525 if (w) {
2519 snd_printdd(KERN_INFO "via82xx: DXS white list for %s found\n", 2526 dev_dbg(&pci->dev, "DXS white list for %s found\n",
2520 snd_pci_quirk_name(w)); 2527 snd_pci_quirk_name(w));
2521 return w->value; 2528 return w->value;
2522 } 2529 }
@@ -2528,10 +2535,10 @@ static int check_dxs_list(struct pci_dev *pci, int revision)
2528 /* 2535 /*
2529 * not detected, try 48k rate only to be sure. 2536 * not detected, try 48k rate only to be sure.
2530 */ 2537 */
2531 printk(KERN_INFO "via82xx: Assuming DXS channels with 48k fixed sample rate.\n"); 2538 dev_info(&pci->dev, "Assuming DXS channels with 48k fixed sample rate.\n");
2532 printk(KERN_INFO " Please try dxs_support=5 option\n"); 2539 dev_info(&pci->dev, " Please try dxs_support=5 option\n");
2533 printk(KERN_INFO " and report if it works on your machine.\n"); 2540 dev_info(&pci->dev, " and report if it works on your machine.\n");
2534 printk(KERN_INFO " For more details, read ALSA-Configuration.txt.\n"); 2541 dev_info(&pci->dev, " For more details, read ALSA-Configuration.txt.\n");
2535 return VIA_DXS_48K; 2542 return VIA_DXS_48K;
2536}; 2543};
2537 2544
@@ -2544,7 +2551,7 @@ static int snd_via82xx_probe(struct pci_dev *pci,
2544 unsigned int i; 2551 unsigned int i;
2545 int err; 2552 int err;
2546 2553
2547 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 2554 err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
2548 if (err < 0) 2555 if (err < 0)
2549 return err; 2556 return err;
2550 2557
@@ -2584,7 +2591,7 @@ static int snd_via82xx_probe(struct pci_dev *pci,
2584 strcpy(card->driver, "VIA8233"); 2591 strcpy(card->driver, "VIA8233");
2585 break; 2592 break;
2586 default: 2593 default:
2587 snd_printk(KERN_ERR "invalid card type %d\n", card_type); 2594 dev_err(card->dev, "invalid card type %d\n", card_type);
2588 err = -EINVAL; 2595 err = -EINVAL;
2589 goto __error; 2596 goto __error;
2590 } 2597 }
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index ca190283cbd7..46a0526b1d79 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -312,7 +312,7 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
312 unsigned int addr; 312 unsigned int addr;
313 313
314 if (idx >= VIA_TABLE_SIZE) { 314 if (idx >= VIA_TABLE_SIZE) {
315 snd_printk(KERN_ERR "via82xx: too much table size!\n"); 315 dev_err(&pci->dev, "too much table size!\n");
316 return -EINVAL; 316 return -EINVAL;
317 } 317 }
318 addr = snd_pcm_sgbuf_get_addr(substream, ofs); 318 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
@@ -329,8 +329,9 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
329 } else 329 } else
330 flag = 0; /* period continues to the next */ 330 flag = 0; /* period continues to the next */
331 /* 331 /*
332 printk(KERN_DEBUG "via: tbl %d: at %d size %d " 332 dev_dbg(&pci->dev,
333 "(rest %d)\n", idx, ofs, r, rest); 333 "tbl %d: at %d size %d (rest %d)\n",
334 idx, ofs, r, rest);
334 */ 335 */
335 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag); 336 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag);
336 dev->idx_table[idx].offset = ofs; 337 dev->idx_table[idx].offset = ofs;
@@ -382,7 +383,7 @@ static int snd_via82xx_codec_ready(struct via82xx_modem *chip, int secondary)
382 if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)) 383 if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY))
383 return val & 0xffff; 384 return val & 0xffff;
384 } 385 }
385 snd_printk(KERN_ERR "codec_ready: codec %i is not ready [0x%x]\n", 386 dev_err(chip->card->dev, "codec_ready: codec %i is not ready [0x%x]\n",
386 secondary, snd_via82xx_codec_xread(chip)); 387 secondary, snd_via82xx_codec_xread(chip));
387 return -EIO; 388 return -EIO;
388} 389}
@@ -443,7 +444,8 @@ static unsigned short snd_via82xx_codec_read(struct snd_ac97 *ac97, unsigned sho
443 xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT; 444 xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT;
444 while (1) { 445 while (1) {
445 if (again++ > 3) { 446 if (again++ > 3) {
446 snd_printk(KERN_ERR "codec_read: codec %i is not valid [0x%x]\n", 447 dev_err(chip->card->dev,
448 "codec_read: codec %i is not valid [0x%x]\n",
447 ac97->num, snd_via82xx_codec_xread(chip)); 449 ac97->num, snd_via82xx_codec_xread(chip));
448 return 0xffff; 450 return 0xffff;
449 } 451 }
@@ -560,7 +562,9 @@ static int snd_via82xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
560 ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\ 562 ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\
561 viadev->lastpos < viadev->bufsize2)) 563 viadev->lastpos < viadev->bufsize2))
562 564
563static inline unsigned int calc_linear_pos(struct viadev *viadev, unsigned int idx, 565static inline unsigned int calc_linear_pos(struct via82xx_modem *chip,
566 struct viadev *viadev,
567 unsigned int idx,
564 unsigned int count) 568 unsigned int count)
565{ 569{
566 unsigned int size, res; 570 unsigned int size, res;
@@ -570,20 +574,21 @@ static inline unsigned int calc_linear_pos(struct viadev *viadev, unsigned int i
570 574
571 /* check the validity of the calculated position */ 575 /* check the validity of the calculated position */
572 if (size < count) { 576 if (size < count) {
573 snd_printd(KERN_ERR "invalid via82xx_cur_ptr (size = %d, count = %d)\n", 577 dev_err(chip->card->dev,
578 "invalid via82xx_cur_ptr (size = %d, count = %d)\n",
574 (int)size, (int)count); 579 (int)size, (int)count);
575 res = viadev->lastpos; 580 res = viadev->lastpos;
576 } else if (check_invalid_pos(viadev, res)) { 581 } else if (check_invalid_pos(viadev, res)) {
577#ifdef POINTER_DEBUG 582#ifdef POINTER_DEBUG
578 printk(KERN_DEBUG "fail: idx = %i/%i, lastpos = 0x%x, " 583 dev_dbg(chip->card->dev,
579 "bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, " 584 "fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n",
580 "count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, 585 idx, viadev->tbl_entries, viadev->lastpos,
581 viadev->bufsize2, viadev->idx_table[idx].offset, 586 viadev->bufsize2, viadev->idx_table[idx].offset,
582 viadev->idx_table[idx].size, count); 587 viadev->idx_table[idx].size, count);
583#endif 588#endif
584 if (count && size < count) { 589 if (count && size < count) {
585 snd_printd(KERN_ERR "invalid via82xx_cur_ptr, " 590 dev_dbg(chip->card->dev,
586 "using last valid pointer\n"); 591 "invalid via82xx_cur_ptr, using last valid pointer\n");
587 res = viadev->lastpos; 592 res = viadev->lastpos;
588 } else { 593 } else {
589 if (! count) 594 if (! count)
@@ -595,8 +600,8 @@ static inline unsigned int calc_linear_pos(struct viadev *viadev, unsigned int i
595 */ 600 */
596 res = viadev->idx_table[idx].offset + size; 601 res = viadev->idx_table[idx].offset + size;
597 if (check_invalid_pos(viadev, res)) { 602 if (check_invalid_pos(viadev, res)) {
598 snd_printd(KERN_ERR "invalid via82xx_cur_ptr (2), " 603 dev_dbg(chip->card->dev,
599 "using last valid pointer\n"); 604 "invalid via82xx_cur_ptr (2), using last valid pointer\n");
600 res = viadev->lastpos; 605 res = viadev->lastpos;
601 } 606 }
602 } 607 }
@@ -632,7 +637,7 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substr
632 else /* CURR_PTR holds the address + 8 */ 637 else /* CURR_PTR holds the address + 8 */
633 idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % 638 idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) %
634 viadev->tbl_entries; 639 viadev->tbl_entries;
635 res = calc_linear_pos(viadev, idx, count); 640 res = calc_linear_pos(chip, viadev, idx, count);
636 spin_unlock(&chip->reg_lock); 641 spin_unlock(&chip->reg_lock);
637 642
638 return bytes_to_frames(substream->runtime, res); 643 return bytes_to_frames(substream->runtime, res);
@@ -991,7 +996,8 @@ static int snd_via82xx_chip_init(struct via82xx_modem *chip)
991 } while (time_before(jiffies, end_time)); 996 } while (time_before(jiffies, end_time));
992 997
993 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 998 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)
994 snd_printk(KERN_ERR "AC'97 codec is not ready [0x%x]\n", val); 999 dev_err(chip->card->dev,
1000 "AC'97 codec is not ready [0x%x]\n", val);
995 1001
996 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 1002 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
997 VIA_REG_AC97_SECONDARY_VALID | 1003 VIA_REG_AC97_SECONDARY_VALID |
@@ -1054,8 +1060,7 @@ static int snd_via82xx_resume(struct device *dev)
1054 pci_set_power_state(pci, PCI_D0); 1060 pci_set_power_state(pci, PCI_D0);
1055 pci_restore_state(pci); 1061 pci_restore_state(pci);
1056 if (pci_enable_device(pci) < 0) { 1062 if (pci_enable_device(pci) < 0) {
1057 printk(KERN_ERR "via82xx-modem: pci_enable_device failed, " 1063 dev_err(dev, "pci_enable_device failed, disabling device\n");
1058 "disabling device\n");
1059 snd_card_disconnect(card); 1064 snd_card_disconnect(card);
1060 return -EIO; 1065 return -EIO;
1061 } 1066 }
@@ -1137,7 +1142,7 @@ static int snd_via82xx_create(struct snd_card *card,
1137 chip->port = pci_resource_start(pci, 0); 1142 chip->port = pci_resource_start(pci, 0);
1138 if (request_irq(pci->irq, snd_via82xx_interrupt, IRQF_SHARED, 1143 if (request_irq(pci->irq, snd_via82xx_interrupt, IRQF_SHARED,
1139 KBUILD_MODNAME, chip)) { 1144 KBUILD_MODNAME, chip)) {
1140 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1145 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1141 snd_via82xx_free(chip); 1146 snd_via82xx_free(chip);
1142 return -EBUSY; 1147 return -EBUSY;
1143 } 1148 }
@@ -1161,8 +1166,6 @@ static int snd_via82xx_create(struct snd_card *card,
1161 * We call pci_set_master here because it does not hurt. */ 1166 * We call pci_set_master here because it does not hurt. */
1162 pci_set_master(pci); 1167 pci_set_master(pci);
1163 1168
1164 snd_card_set_dev(card, &pci->dev);
1165
1166 *r_via = chip; 1169 *r_via = chip;
1167 return 0; 1170 return 0;
1168} 1171}
@@ -1177,7 +1180,7 @@ static int snd_via82xx_probe(struct pci_dev *pci,
1177 unsigned int i; 1180 unsigned int i;
1178 int err; 1181 int err;
1179 1182
1180 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 1183 err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
1181 if (err < 0) 1184 if (err < 0)
1182 return err; 1185 return err;
1183 1186
@@ -1188,7 +1191,7 @@ static int snd_via82xx_probe(struct pci_dev *pci,
1188 sprintf(card->shortname, "VIA 82XX modem"); 1191 sprintf(card->shortname, "VIA 82XX modem");
1189 break; 1192 break;
1190 default: 1193 default:
1191 snd_printk(KERN_ERR "invalid card type %d\n", card_type); 1194 dev_err(card->dev, "invalid card type %d\n", card_type);
1192 err = -EINVAL; 1195 err = -EINVAL;
1193 goto __error; 1196 goto __error;
1194 } 1197 }
diff --git a/sound/pci/vx222/vx222.c b/sound/pci/vx222/vx222.c
index ab8a9b1bfb8e..ff9074d22607 100644
--- a/sound/pci/vx222/vx222.c
+++ b/sound/pci/vx222/vx222.c
@@ -170,7 +170,7 @@ static int snd_vx222_create(struct snd_card *card, struct pci_dev *pci,
170 170
171 if (request_irq(pci->irq, snd_vx_irq_handler, IRQF_SHARED, 171 if (request_irq(pci->irq, snd_vx_irq_handler, IRQF_SHARED,
172 KBUILD_MODNAME, chip)) { 172 KBUILD_MODNAME, chip)) {
173 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 173 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
174 snd_vx222_free(chip); 174 snd_vx222_free(chip);
175 return -EBUSY; 175 return -EBUSY;
176 } 176 }
@@ -181,8 +181,6 @@ static int snd_vx222_create(struct snd_card *card, struct pci_dev *pci,
181 return err; 181 return err;
182 } 182 }
183 183
184 snd_card_set_dev(card, &pci->dev);
185
186 *rchip = vx; 184 *rchip = vx;
187 return 0; 185 return 0;
188} 186}
@@ -204,7 +202,8 @@ static int snd_vx222_probe(struct pci_dev *pci,
204 return -ENOENT; 202 return -ENOENT;
205 } 203 }
206 204
207 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 205 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
206 0, &card);
208 if (err < 0) 207 if (err < 0)
209 return err; 208 return err;
210 209
@@ -229,7 +228,7 @@ static int snd_vx222_probe(struct pci_dev *pci,
229 228
230 sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i", 229 sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i",
231 card->shortname, vx->port[0], vx->port[1], vx->core.irq); 230 card->shortname, vx->port[0], vx->port[1], vx->core.irq);
232 snd_printdd("%s at 0x%lx & 0x%lx, irq %i\n", 231 dev_dbg(card->dev, "%s at 0x%lx & 0x%lx, irq %i\n",
233 card->shortname, vx->port[0], vx->port[1], vx->core.irq); 232 card->shortname, vx->port[0], vx->port[1], vx->core.irq);
234 233
235#ifdef SND_VX_FW_LOADER 234#ifdef SND_VX_FW_LOADER
@@ -280,8 +279,7 @@ static int snd_vx222_resume(struct device *dev)
280 pci_set_power_state(pci, PCI_D0); 279 pci_set_power_state(pci, PCI_D0);
281 pci_restore_state(pci); 280 pci_restore_state(pci);
282 if (pci_enable_device(pci) < 0) { 281 if (pci_enable_device(pci) < 0) {
283 printk(KERN_ERR "vx222: pci_enable_device failed, " 282 dev_err(dev, "pci_enable_device failed, disabling device\n");
284 "disabling device\n");
285 snd_card_disconnect(card); 283 snd_card_disconnect(card);
286 return -EIO; 284 return -EIO;
287 } 285 }
diff --git a/sound/pci/vx222/vx222_ops.c b/sound/pci/vx222/vx222_ops.c
index a69e774d0b13..2d1570273e99 100644
--- a/sound/pci/vx222/vx222_ops.c
+++ b/sound/pci/vx222/vx222_ops.c
@@ -108,7 +108,7 @@ static 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 /* 110 /*
111 printk(KERN_DEBUG "outb: %x -> %x\n", val, vx2_reg_addr(chip, offset)); 111 dev_dbg(chip->card->dev, "outb: %x -> %x\n", val, vx2_reg_addr(chip, offset));
112 */ 112 */
113} 113}
114 114
@@ -129,7 +129,7 @@ static unsigned int vx2_inl(struct vx_core *chip, int offset)
129static 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)
130{ 130{
131 /* 131 /*
132 printk(KERN_DEBUG "outl: %x -> %x\n", val, vx2_reg_addr(chip, offset)); 132 dev_dbg(chip->card->dev, "outl: %x -> %x\n", val, vx2_reg_addr(chip, offset));
133 */ 133 */
134 outl(val, vx2_reg_addr(chip, offset)); 134 outl(val, vx2_reg_addr(chip, offset));
135} 135}
@@ -173,7 +173,7 @@ static int vx2_test_xilinx(struct vx_core *_chip)
173 struct snd_vx222 *chip = (struct snd_vx222 *)_chip; 173 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
174 unsigned int data; 174 unsigned int data;
175 175
176 snd_printdd("testing xilinx...\n"); 176 dev_dbg(_chip->card->dev, "testing xilinx...\n");
177 /* This test uses several write/read sequences on TEST0 and TEST1 bits 177 /* This test uses several write/read sequences on TEST0 and TEST1 bits
178 * to figure out whever or not the xilinx was correctly loaded 178 * to figure out whever or not the xilinx was correctly loaded
179 */ 179 */
@@ -183,7 +183,7 @@ static int vx2_test_xilinx(struct vx_core *_chip)
183 vx_inl(chip, ISR); 183 vx_inl(chip, ISR);
184 data = vx_inl(chip, STATUS); 184 data = vx_inl(chip, STATUS);
185 if ((data & VX_STATUS_VAL_TEST0_MASK) == VX_STATUS_VAL_TEST0_MASK) { 185 if ((data & VX_STATUS_VAL_TEST0_MASK) == VX_STATUS_VAL_TEST0_MASK) {
186 snd_printdd("bad!\n"); 186 dev_dbg(_chip->card->dev, "bad!\n");
187 return -ENODEV; 187 return -ENODEV;
188 } 188 }
189 189
@@ -192,7 +192,7 @@ static int vx2_test_xilinx(struct vx_core *_chip)
192 vx_inl(chip, ISR); 192 vx_inl(chip, ISR);
193 data = vx_inl(chip, STATUS); 193 data = vx_inl(chip, STATUS);
194 if (! (data & VX_STATUS_VAL_TEST0_MASK)) { 194 if (! (data & VX_STATUS_VAL_TEST0_MASK)) {
195 snd_printdd("bad! #2\n"); 195 dev_dbg(_chip->card->dev, "bad! #2\n");
196 return -ENODEV; 196 return -ENODEV;
197 } 197 }
198 198
@@ -203,7 +203,7 @@ static int vx2_test_xilinx(struct vx_core *_chip)
203 vx_inl(chip, ISR); 203 vx_inl(chip, ISR);
204 data = vx_inl(chip, STATUS); 204 data = vx_inl(chip, STATUS);
205 if ((data & VX_STATUS_VAL_TEST1_MASK) == VX_STATUS_VAL_TEST1_MASK) { 205 if ((data & VX_STATUS_VAL_TEST1_MASK) == VX_STATUS_VAL_TEST1_MASK) {
206 snd_printdd("bad! #3\n"); 206 dev_dbg(_chip->card->dev, "bad! #3\n");
207 return -ENODEV; 207 return -ENODEV;
208 } 208 }
209 209
@@ -212,11 +212,11 @@ static int vx2_test_xilinx(struct vx_core *_chip)
212 vx_inl(chip, ISR); 212 vx_inl(chip, ISR);
213 data = vx_inl(chip, STATUS); 213 data = vx_inl(chip, STATUS);
214 if (! (data & VX_STATUS_VAL_TEST1_MASK)) { 214 if (! (data & VX_STATUS_VAL_TEST1_MASK)) {
215 snd_printdd("bad! #4\n"); 215 dev_dbg(_chip->card->dev, "bad! #4\n");
216 return -ENODEV; 216 return -ENODEV;
217 } 217 }
218 } 218 }
219 snd_printdd("ok, xilinx fine.\n"); 219 dev_dbg(_chip->card->dev, "ok, xilinx fine.\n");
220 return 0; 220 return 0;
221} 221}
222 222
@@ -397,7 +397,8 @@ static int vx2_load_xilinx_binary(struct vx_core *chip, const struct firmware *x
397 i = vx_inl(chip, GPIOC); 397 i = vx_inl(chip, GPIOC);
398 if (i & 0x0100) 398 if (i & 0x0100)
399 return 0; 399 return 0;
400 snd_printk(KERN_ERR "vx222: xilinx test failed after load, GPIOC=0x%x\n", i); 400 dev_err(chip->card->dev,
401 "xilinx test failed after load, GPIOC=0x%x\n", i);
401 return -EINVAL; 402 return -EINVAL;
402 } 403 }
403 404
diff --git a/sound/pci/ymfpci/ymfpci.c b/sound/pci/ymfpci/ymfpci.c
index e8932b2e4a5d..82eed164b275 100644
--- a/sound/pci/ymfpci/ymfpci.c
+++ b/sound/pci/ymfpci/ymfpci.c
@@ -106,7 +106,8 @@ static int snd_ymfpci_create_gameport(struct snd_ymfpci *chip, int dev,
106 break; 106 break;
107 } 107 }
108 if (!r) { 108 if (!r) {
109 printk(KERN_ERR "ymfpci: no gameport ports available\n"); 109 dev_err(chip->card->dev,
110 "no gameport ports available\n");
110 return -EBUSY; 111 return -EBUSY;
111 } 112 }
112 } 113 }
@@ -116,19 +117,22 @@ static int snd_ymfpci_create_gameport(struct snd_ymfpci *chip, int dev,
116 case 0x204: legacy_ctrl2 |= 2 << 6; break; 117 case 0x204: legacy_ctrl2 |= 2 << 6; break;
117 case 0x205: legacy_ctrl2 |= 3 << 6; break; 118 case 0x205: legacy_ctrl2 |= 3 << 6; break;
118 default: 119 default:
119 printk(KERN_ERR "ymfpci: invalid joystick port %#x", io_port); 120 dev_err(chip->card->dev,
121 "invalid joystick port %#x", io_port);
120 return -EINVAL; 122 return -EINVAL;
121 } 123 }
122 } 124 }
123 125
124 if (!r && !(r = request_region(io_port, 1, "YMFPCI gameport"))) { 126 if (!r && !(r = request_region(io_port, 1, "YMFPCI gameport"))) {
125 printk(KERN_ERR "ymfpci: joystick port %#x is in use.\n", io_port); 127 dev_err(chip->card->dev,
128 "joystick port %#x is in use.\n", io_port);
126 return -EBUSY; 129 return -EBUSY;
127 } 130 }
128 131
129 chip->gameport = gp = gameport_allocate_port(); 132 chip->gameport = gp = gameport_allocate_port();
130 if (!gp) { 133 if (!gp) {
131 printk(KERN_ERR "ymfpci: cannot allocate memory for gameport\n"); 134 dev_err(chip->card->dev,
135 "cannot allocate memory for gameport\n");
132 release_and_free_resource(r); 136 release_and_free_resource(r);
133 return -ENOMEM; 137 return -ENOMEM;
134 } 138 }
@@ -187,7 +191,8 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci,
187 return -ENOENT; 191 return -ENOENT;
188 } 192 }
189 193
190 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 194 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
195 0, &card);
191 if (err < 0) 196 if (err < 0)
192 return err; 197 return err;
193 198
@@ -313,7 +318,9 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci,
313 MPU401_INFO_INTEGRATED | 318 MPU401_INFO_INTEGRATED |
314 MPU401_INFO_IRQ_HOOK, 319 MPU401_INFO_IRQ_HOOK,
315 -1, &chip->rawmidi)) < 0) { 320 -1, &chip->rawmidi)) < 0) {
316 printk(KERN_WARNING "ymfpci: cannot initialize MPU401 at 0x%lx, skipping...\n", mpu_port[dev]); 321 dev_warn(card->dev,
322 "cannot initialize MPU401 at 0x%lx, skipping...\n",
323 mpu_port[dev]);
317 legacy_ctrl &= ~YMFPCI_LEGACY_MIEN; /* disable MPU401 irq */ 324 legacy_ctrl &= ~YMFPCI_LEGACY_MIEN; /* disable MPU401 irq */
318 pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl); 325 pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
319 } 326 }
@@ -323,12 +330,14 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci,
323 fm_port[dev], 330 fm_port[dev],
324 fm_port[dev] + 2, 331 fm_port[dev] + 2,
325 OPL3_HW_OPL3, 1, &opl3)) < 0) { 332 OPL3_HW_OPL3, 1, &opl3)) < 0) {
326 printk(KERN_WARNING "ymfpci: cannot initialize FM OPL3 at 0x%lx, skipping...\n", fm_port[dev]); 333 dev_warn(card->dev,
334 "cannot initialize FM OPL3 at 0x%lx, skipping...\n",
335 fm_port[dev]);
327 legacy_ctrl &= ~YMFPCI_LEGACY_FMEN; 336 legacy_ctrl &= ~YMFPCI_LEGACY_FMEN;
328 pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl); 337 pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
329 } else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { 338 } else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
330 snd_card_free(card); 339 snd_card_free(card);
331 snd_printk(KERN_ERR "cannot create opl3 hwdep\n"); 340 dev_err(card->dev, "cannot create opl3 hwdep\n");
332 return err; 341 return err;
333 } 342 }
334 } 343 }
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index d591c154fc58..81c916a5eb96 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -86,7 +86,9 @@ static int snd_ymfpci_codec_ready(struct snd_ymfpci *chip, int secondary)
86 return 0; 86 return 0;
87 schedule_timeout_uninterruptible(1); 87 schedule_timeout_uninterruptible(1);
88 } while (time_before(jiffies, end_time)); 88 } while (time_before(jiffies, end_time));
89 snd_printk(KERN_ERR "codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_ymfpci_readw(chip, reg)); 89 dev_err(chip->card->dev,
90 "codec_ready: codec %i is not ready [0x%x]\n",
91 secondary, snd_ymfpci_readw(chip, reg));
90 return -EBUSY; 92 return -EBUSY;
91} 93}
92 94
@@ -319,7 +321,7 @@ static void snd_ymfpci_pcm_interrupt(struct snd_ymfpci *chip, struct snd_ymfpci_
319 ypcm->last_pos = pos; 321 ypcm->last_pos = pos;
320 if (ypcm->period_pos >= ypcm->period_size) { 322 if (ypcm->period_pos >= ypcm->period_size) {
321 /* 323 /*
322 printk(KERN_DEBUG 324 dev_dbg(chip->card->dev,
323 "done - active_bank = 0x%x, start = 0x%x\n", 325 "done - active_bank = 0x%x, start = 0x%x\n",
324 chip->active_bank, 326 chip->active_bank,
325 voice->bank[chip->active_bank].start); 327 voice->bank[chip->active_bank].start);
@@ -372,7 +374,7 @@ static void snd_ymfpci_pcm_capture_interrupt(struct snd_pcm_substream *substream
372 if (ypcm->period_pos >= ypcm->period_size) { 374 if (ypcm->period_pos >= ypcm->period_size) {
373 ypcm->period_pos %= ypcm->period_size; 375 ypcm->period_pos %= ypcm->period_size;
374 /* 376 /*
375 printk(KERN_DEBUG 377 dev_dbg(chip->card->dev,
376 "done - active_bank = 0x%x, start = 0x%x\n", 378 "done - active_bank = 0x%x, start = 0x%x\n",
377 chip->active_bank, 379 chip->active_bank,
378 voice->bank[chip->active_bank].start); 380 voice->bank[chip->active_bank].start);
@@ -2067,7 +2069,8 @@ static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip)
2067 &chip->pci->dev); 2069 &chip->pci->dev);
2068 if (err >= 0) { 2070 if (err >= 0) {
2069 if (chip->dsp_microcode->size != YDSXG_DSPLENGTH) { 2071 if (chip->dsp_microcode->size != YDSXG_DSPLENGTH) {
2070 snd_printk(KERN_ERR "DSP microcode has wrong size\n"); 2072 dev_err(chip->card->dev,
2073 "DSP microcode has wrong size\n");
2071 err = -EINVAL; 2074 err = -EINVAL;
2072 } 2075 }
2073 } 2076 }
@@ -2082,8 +2085,8 @@ static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip)
2082 &chip->pci->dev); 2085 &chip->pci->dev);
2083 if (err >= 0) { 2086 if (err >= 0) {
2084 if (chip->controller_microcode->size != YDSXG_CTRLLENGTH) { 2087 if (chip->controller_microcode->size != YDSXG_CTRLLENGTH) {
2085 snd_printk(KERN_ERR "controller microcode" 2088 dev_err(chip->card->dev,
2086 " has wrong size\n"); 2089 "controller microcode has wrong size\n");
2087 err = -EINVAL; 2090 err = -EINVAL;
2088 } 2091 }
2089 } 2092 }
@@ -2360,8 +2363,7 @@ static int snd_ymfpci_resume(struct device *dev)
2360 pci_set_power_state(pci, PCI_D0); 2363 pci_set_power_state(pci, PCI_D0);
2361 pci_restore_state(pci); 2364 pci_restore_state(pci);
2362 if (pci_enable_device(pci) < 0) { 2365 if (pci_enable_device(pci) < 0) {
2363 printk(KERN_ERR "ymfpci: pci_enable_device failed, " 2366 dev_err(dev, "pci_enable_device failed, disabling device\n");
2364 "disabling device\n");
2365 snd_card_disconnect(card); 2367 snd_card_disconnect(card);
2366 return -EIO; 2368 return -EIO;
2367 } 2369 }
@@ -2433,13 +2435,15 @@ int snd_ymfpci_create(struct snd_card *card,
2433 chip->src441_used = -1; 2435 chip->src441_used = -1;
2434 2436
2435 if ((chip->res_reg_area = request_mem_region(chip->reg_area_phys, 0x8000, "YMFPCI")) == NULL) { 2437 if ((chip->res_reg_area = request_mem_region(chip->reg_area_phys, 0x8000, "YMFPCI")) == NULL) {
2436 snd_printk(KERN_ERR "unable to grab memory region 0x%lx-0x%lx\n", chip->reg_area_phys, chip->reg_area_phys + 0x8000 - 1); 2438 dev_err(chip->card->dev,
2439 "unable to grab memory region 0x%lx-0x%lx\n",
2440 chip->reg_area_phys, chip->reg_area_phys + 0x8000 - 1);
2437 snd_ymfpci_free(chip); 2441 snd_ymfpci_free(chip);
2438 return -EBUSY; 2442 return -EBUSY;
2439 } 2443 }
2440 if (request_irq(pci->irq, snd_ymfpci_interrupt, IRQF_SHARED, 2444 if (request_irq(pci->irq, snd_ymfpci_interrupt, IRQF_SHARED,
2441 KBUILD_MODNAME, chip)) { 2445 KBUILD_MODNAME, chip)) {
2442 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 2446 dev_err(chip->card->dev, "unable to grab IRQ %d\n", pci->irq);
2443 snd_ymfpci_free(chip); 2447 snd_ymfpci_free(chip);
2444 return -EBUSY; 2448 return -EBUSY;
2445 } 2449 }
@@ -2453,7 +2457,7 @@ int snd_ymfpci_create(struct snd_card *card,
2453 2457
2454 err = snd_ymfpci_request_firmware(chip); 2458 err = snd_ymfpci_request_firmware(chip);
2455 if (err < 0) { 2459 if (err < 0) {
2456 snd_printk(KERN_ERR "firmware request failed: %d\n", err); 2460 dev_err(chip->card->dev, "firmware request failed: %d\n", err);
2457 snd_ymfpci_free(chip); 2461 snd_ymfpci_free(chip);
2458 return err; 2462 return err;
2459 } 2463 }
@@ -2487,8 +2491,6 @@ int snd_ymfpci_create(struct snd_card *card,
2487 2491
2488 snd_ymfpci_proc_init(card, chip); 2492 snd_ymfpci_proc_init(card, chip);
2489 2493
2490 snd_card_set_dev(card, &pci->dev);
2491
2492 *rchip = chip; 2494 *rchip = chip;
2493 return 0; 2495 return 0;
2494} 2496}
diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf.c b/sound/pcmcia/pdaudiocf/pdaudiocf.c
index 8f489de5c4c6..56bda124cd4a 100644
--- a/sound/pcmcia/pdaudiocf/pdaudiocf.c
+++ b/sound/pcmcia/pdaudiocf/pdaudiocf.c
@@ -112,7 +112,8 @@ 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 err = snd_card_create(index[i], id[i], THIS_MODULE, 0, &card); 115 err = snd_card_new(&link->dev, index[i], id[i], THIS_MODULE,
116 0, &card);
116 if (err < 0) { 117 if (err < 0) {
117 snd_printk(KERN_ERR "pdacf: cannot create a card instance\n"); 118 snd_printk(KERN_ERR "pdacf: cannot create a card instance\n");
118 return err; 119 return err;
@@ -131,8 +132,6 @@ static int snd_pdacf_probe(struct pcmcia_device *link)
131 return err; 132 return err;
132 } 133 }
133 134
134 snd_card_set_dev(card, &link->dev);
135
136 pdacf->index = i; 135 pdacf->index = i;
137 card_list[i] = card; 136 card_list[i] = card;
138 137
diff --git a/sound/pcmcia/vx/vxpocket.c b/sound/pcmcia/vx/vxpocket.c
index d4db7ecaa6bf..786e7e139c9e 100644
--- a/sound/pcmcia/vx/vxpocket.c
+++ b/sound/pcmcia/vx/vxpocket.c
@@ -238,7 +238,6 @@ static int vxpocket_config(struct pcmcia_device *link)
238 goto failed; 238 goto failed;
239 239
240 chip->dev = &link->dev; 240 chip->dev = &link->dev;
241 snd_card_set_dev(chip->card, chip->dev);
242 241
243 if (snd_vxpocket_assign_resources(chip, link->resource[0]->start, 242 if (snd_vxpocket_assign_resources(chip, link->resource[0]->start,
244 link->irq) < 0) 243 link->irq) < 0)
@@ -307,7 +306,8 @@ static int vxpocket_probe(struct pcmcia_device *p_dev)
307 return -ENODEV; /* disabled explicitly */ 306 return -ENODEV; /* disabled explicitly */
308 307
309 /* ok, create a card instance */ 308 /* ok, create a card instance */
310 err = snd_card_create(index[i], id[i], THIS_MODULE, 0, &card); 309 err = snd_card_new(&p_dev->dev, index[i], id[i], THIS_MODULE,
310 0, &card);
311 if (err < 0) { 311 if (err < 0) {
312 snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n"); 312 snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n");
313 return err; 313 return err;
diff --git a/sound/ppc/powermac.c b/sound/ppc/powermac.c
index 8abb521b4814..350a7c8f86dd 100644
--- a/sound/ppc/powermac.c
+++ b/sound/ppc/powermac.c
@@ -58,7 +58,7 @@ static int snd_pmac_probe(struct platform_device *devptr)
58 char *name_ext; 58 char *name_ext;
59 int err; 59 int err;
60 60
61 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 61 err = snd_card_new(&devptr->dev, index, id, THIS_MODULE, 0, &card);
62 if (err < 0) 62 if (err < 0)
63 return err; 63 return err;
64 64
@@ -122,8 +122,6 @@ static int snd_pmac_probe(struct platform_device *devptr)
122 if (enable_beep) 122 if (enable_beep)
123 snd_pmac_attach_beep(chip); 123 snd_pmac_attach_beep(chip);
124 124
125 snd_card_set_dev(card, &devptr->dev);
126
127 if ((err = snd_card_register(card)) < 0) 125 if ((err = snd_card_register(card)) < 0)
128 goto __error; 126 goto __error;
129 127
diff --git a/sound/ppc/snd_ps3.c b/sound/ppc/snd_ps3.c
index ebb76f2d90d7..58f292a87f98 100644
--- a/sound/ppc/snd_ps3.c
+++ b/sound/ppc/snd_ps3.c
@@ -984,7 +984,8 @@ static int snd_ps3_driver_probe(struct ps3_system_bus_device *dev)
984 } 984 }
985 985
986 /* create card instance */ 986 /* create card instance */
987 ret = snd_card_create(index, id, THIS_MODULE, 0, &the_card.card); 987 ret = snd_card_new(&dev->core, index, id, THIS_MODULE,
988 0, &the_card.card);
988 if (ret < 0) 989 if (ret < 0)
989 goto clean_irq; 990 goto clean_irq;
990 991
@@ -1052,7 +1053,6 @@ static int snd_ps3_driver_probe(struct ps3_system_bus_device *dev)
1052 snd_ps3_init_avsetting(&the_card); 1053 snd_ps3_init_avsetting(&the_card);
1053 1054
1054 /* register the card */ 1055 /* register the card */
1055 snd_card_set_dev(the_card.card, &dev->core);
1056 ret = snd_card_register(the_card.card); 1056 ret = snd_card_register(the_card.card);
1057 if (ret < 0) 1057 if (ret < 0)
1058 goto clean_dma_map; 1058 goto clean_dma_map;
diff --git a/sound/sh/aica.c b/sound/sh/aica.c
index 78a369785a9e..47849eaf266d 100644
--- a/sound/sh/aica.c
+++ b/sound/sh/aica.c
@@ -608,8 +608,8 @@ static int snd_aica_probe(struct platform_device *devptr)
608 dreamcastcard = kmalloc(sizeof(struct snd_card_aica), GFP_KERNEL); 608 dreamcastcard = kmalloc(sizeof(struct snd_card_aica), GFP_KERNEL);
609 if (unlikely(!dreamcastcard)) 609 if (unlikely(!dreamcastcard))
610 return -ENOMEM; 610 return -ENOMEM;
611 err = snd_card_create(index, SND_AICA_DRIVER, THIS_MODULE, 0, 611 err = snd_card_new(&devptr->dev, index, SND_AICA_DRIVER,
612 &dreamcastcard->card); 612 THIS_MODULE, 0, &dreamcastcard->card);
613 if (unlikely(err < 0)) { 613 if (unlikely(err < 0)) {
614 kfree(dreamcastcard); 614 kfree(dreamcastcard);
615 return err; 615 return err;
@@ -624,7 +624,6 @@ static int snd_aica_probe(struct platform_device *devptr)
624 err = snd_aicapcmchip(dreamcastcard, 0); 624 err = snd_aicapcmchip(dreamcastcard, 0);
625 if (unlikely(err < 0)) 625 if (unlikely(err < 0))
626 goto freedreamcast; 626 goto freedreamcast;
627 snd_card_set_dev(dreamcastcard->card, &devptr->dev);
628 dreamcastcard->timer.data = 0; 627 dreamcastcard->timer.data = 0;
629 dreamcastcard->channel = NULL; 628 dreamcastcard->channel = NULL;
630 /* Add basic controls */ 629 /* Add basic controls */
diff --git a/sound/sh/sh_dac_audio.c b/sound/sh/sh_dac_audio.c
index 7c9422c4fc0f..d1fb74dabbd1 100644
--- a/sound/sh/sh_dac_audio.c
+++ b/sound/sh/sh_dac_audio.c
@@ -396,7 +396,7 @@ static int snd_sh_dac_probe(struct platform_device *devptr)
396 struct snd_card *card; 396 struct snd_card *card;
397 int err; 397 int err;
398 398
399 err = snd_card_create(index, id, THIS_MODULE, 0, &card); 399 err = snd_card_new(&devptr->dev, index, id, THIS_MODULE, 0, &card);
400 if (err < 0) { 400 if (err < 0) {
401 snd_printk(KERN_ERR "cannot allocate the card\n"); 401 snd_printk(KERN_ERR "cannot allocate the card\n");
402 return err; 402 return err;
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index d62ce483a443..0060b31cc3f3 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -50,6 +50,7 @@ source "sound/soc/pxa/Kconfig"
50source "sound/soc/samsung/Kconfig" 50source "sound/soc/samsung/Kconfig"
51source "sound/soc/s6000/Kconfig" 51source "sound/soc/s6000/Kconfig"
52source "sound/soc/sh/Kconfig" 52source "sound/soc/sh/Kconfig"
53source "sound/soc/sirf/Kconfig"
53source "sound/soc/spear/Kconfig" 54source "sound/soc/spear/Kconfig"
54source "sound/soc/tegra/Kconfig" 55source "sound/soc/tegra/Kconfig"
55source "sound/soc/txx9/Kconfig" 56source "sound/soc/txx9/Kconfig"
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 62a1822e77bf..5f1df02984f8 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_SND_SOC) += pxa/
27obj-$(CONFIG_SND_SOC) += samsung/ 27obj-$(CONFIG_SND_SOC) += samsung/
28obj-$(CONFIG_SND_SOC) += s6000/ 28obj-$(CONFIG_SND_SOC) += s6000/
29obj-$(CONFIG_SND_SOC) += sh/ 29obj-$(CONFIG_SND_SOC) += sh/
30obj-$(CONFIG_SND_SOC) += sirf/
30obj-$(CONFIG_SND_SOC) += spear/ 31obj-$(CONFIG_SND_SOC) += spear/
31obj-$(CONFIG_SND_SOC) += tegra/ 32obj-$(CONFIG_SND_SOC) += tegra/
32obj-$(CONFIG_SND_SOC) += txx9/ 33obj-$(CONFIG_SND_SOC) += txx9/
diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index e634eb78ed03..4789619a52d8 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -58,6 +58,6 @@ config SND_AT91_SOC_AFEB9260
58 depends on ARCH_AT91 && ATMEL_SSC && ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC 58 depends on ARCH_AT91 && ATMEL_SSC && ARCH_AT91 && MACH_AFEB9260 && SND_ATMEL_SOC
59 select SND_ATMEL_SOC_PDC 59 select SND_ATMEL_SOC_PDC
60 select SND_ATMEL_SOC_SSC 60 select SND_ATMEL_SOC_SSC
61 select SND_SOC_TLV320AIC23 61 select SND_SOC_TLV320AIC23_I2C
62 help 62 help
63 Say Y here to support sound on AFEB9260 board. 63 Say Y here to support sound on AFEB9260 board.
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index 1ead3c977a51..de433cfd044c 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -341,6 +341,7 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
341{ 341{
342 int id = dai->id; 342 int id = dai->id;
343 struct atmel_ssc_info *ssc_p = &ssc_info[id]; 343 struct atmel_ssc_info *ssc_p = &ssc_info[id];
344 struct ssc_device *ssc = ssc_p->ssc;
344 struct atmel_pcm_dma_params *dma_params; 345 struct atmel_pcm_dma_params *dma_params;
345 int dir, channels, bits; 346 int dir, channels, bits;
346 u32 tfmr, rfmr, tcmr, rcmr; 347 u32 tfmr, rfmr, tcmr, rcmr;
@@ -466,7 +467,8 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
466 | SSC_BF(RCMR_START, start_event) 467 | SSC_BF(RCMR_START, start_event)
467 | SSC_BF(RCMR_CKI, SSC_CKI_RISING) 468 | SSC_BF(RCMR_CKI, SSC_CKI_RISING)
468 | SSC_BF(RCMR_CKO, SSC_CKO_NONE) 469 | SSC_BF(RCMR_CKO, SSC_CKO_NONE)
469 | SSC_BF(RCMR_CKS, SSC_CKS_CLOCK); 470 | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ?
471 SSC_CKS_PIN : SSC_CKS_CLOCK);
470 472
471 rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE) 473 rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
472 | SSC_BF(RFMR_FSOS, SSC_FSOS_NONE) 474 | SSC_BF(RFMR_FSOS, SSC_FSOS_NONE)
@@ -481,7 +483,8 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
481 | SSC_BF(TCMR_START, start_event) 483 | SSC_BF(TCMR_START, start_event)
482 | SSC_BF(TCMR_CKI, SSC_CKI_FALLING) 484 | SSC_BF(TCMR_CKI, SSC_CKI_FALLING)
483 | SSC_BF(TCMR_CKO, SSC_CKO_NONE) 485 | SSC_BF(TCMR_CKO, SSC_CKO_NONE)
484 | SSC_BF(TCMR_CKS, SSC_CKS_PIN); 486 | SSC_BF(TCMR_CKS, ssc->clk_from_rk_pin ?
487 SSC_CKS_CLOCK : SSC_CKS_PIN);
485 488
486 tfmr = SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE) 489 tfmr = SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
487 | SSC_BF(TFMR_FSDEN, 0) 490 | SSC_BF(TFMR_FSDEN, 0)
@@ -550,7 +553,8 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
550 | SSC_BF(RCMR_START, SSC_START_RISING_RF) 553 | SSC_BF(RCMR_START, SSC_START_RISING_RF)
551 | SSC_BF(RCMR_CKI, SSC_CKI_RISING) 554 | SSC_BF(RCMR_CKI, SSC_CKI_RISING)
552 | SSC_BF(RCMR_CKO, SSC_CKO_NONE) 555 | SSC_BF(RCMR_CKO, SSC_CKO_NONE)
553 | SSC_BF(RCMR_CKS, SSC_CKS_PIN); 556 | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ?
557 SSC_CKS_PIN : SSC_CKS_CLOCK);
554 558
555 rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE) 559 rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
556 | SSC_BF(RFMR_FSOS, SSC_FSOS_NONE) 560 | SSC_BF(RFMR_FSOS, SSC_FSOS_NONE)
@@ -565,7 +569,8 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
565 | SSC_BF(TCMR_START, SSC_START_RISING_RF) 569 | SSC_BF(TCMR_START, SSC_START_RISING_RF)
566 | SSC_BF(TCMR_CKI, SSC_CKI_FALLING) 570 | SSC_BF(TCMR_CKI, SSC_CKI_FALLING)
567 | SSC_BF(TCMR_CKO, SSC_CKO_NONE) 571 | SSC_BF(TCMR_CKO, SSC_CKO_NONE)
568 | SSC_BF(TCMR_CKS, SSC_CKS_PIN); 572 | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ?
573 SSC_CKS_CLOCK : SSC_CKS_PIN);
569 574
570 tfmr = SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE) 575 tfmr = SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
571 | SSC_BF(TFMR_FSDEN, 0) 576 | SSC_BF(TFMR_FSDEN, 0)
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index f15bff1548f8..174bd546c08b 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -155,25 +155,14 @@ static int at91sam9g20ek_wm8731_init(struct snd_soc_pcm_runtime *rtd)
155 return ret; 155 return ret;
156 } 156 }
157 157
158 /* Add specific widgets */
159 snd_soc_dapm_new_controls(dapm, at91sam9g20ek_dapm_widgets,
160 ARRAY_SIZE(at91sam9g20ek_dapm_widgets));
161 /* Set up specific audio path interconnects */
162 snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
163
164 /* not connected */ 158 /* not connected */
165 snd_soc_dapm_nc_pin(dapm, "RLINEIN"); 159 snd_soc_dapm_nc_pin(dapm, "RLINEIN");
166 snd_soc_dapm_nc_pin(dapm, "LLINEIN"); 160 snd_soc_dapm_nc_pin(dapm, "LLINEIN");
167 161
168#ifdef ENABLE_MIC_INPUT 162#ifndef ENABLE_MIC_INPUT
169 snd_soc_dapm_enable_pin(dapm, "Int Mic"); 163 snd_soc_dapm_nc_pin(&rtd->card->dapm, "Int Mic");
170#else
171 snd_soc_dapm_nc_pin(dapm, "Int Mic");
172#endif 164#endif
173 165
174 /* always connected */
175 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
176
177 return 0; 166 return 0;
178} 167}
179 168
@@ -194,6 +183,11 @@ static struct snd_soc_card snd_soc_at91sam9g20ek = {
194 .dai_link = &at91sam9g20ek_dai, 183 .dai_link = &at91sam9g20ek_dai,
195 .num_links = 1, 184 .num_links = 1,
196 .set_bias_level = at91sam9g20ek_set_bias_level, 185 .set_bias_level = at91sam9g20ek_set_bias_level,
186
187 .dapm_widgets = at91sam9g20ek_dapm_widgets,
188 .num_dapm_widgets = ARRAY_SIZE(at91sam9g20ek_dapm_widgets),
189 .dapm_routes = intercon,
190 .num_dapm_routes = ARRAY_SIZE(intercon),
197}; 191};
198 192
199static int at91sam9g20ek_audio_probe(struct platform_device *pdev) 193static int at91sam9g20ek_audio_probe(struct platform_device *pdev)
diff --git a/sound/soc/blackfin/Kconfig b/sound/soc/blackfin/Kconfig
index 4544d8eb1452..6347d5910138 100644
--- a/sound/soc/blackfin/Kconfig
+++ b/sound/soc/blackfin/Kconfig
@@ -14,7 +14,8 @@ config SND_BF5XX_SOC_SSM2602
14 depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI 14 depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI
15 select SND_BF5XX_SOC_I2S if !BF60x 15 select SND_BF5XX_SOC_I2S if !BF60x
16 select SND_BF6XX_SOC_I2S if BF60x 16 select SND_BF6XX_SOC_I2S if BF60x
17 select SND_SOC_SSM2602 17 select SND_SOC_SSM2602_SPI if SPI_MASTER
18 select SND_SOC_SSM2602_I2C if I2C
18 help 19 help
19 Say Y if you want to add support for the Analog Devices 20 Say Y if you want to add support for the Analog Devices
20 SSM2602 Audio Codec Add-On Card. 21 SSM2602 Audio Codec Add-On Card.
@@ -46,7 +47,8 @@ config SND_SOC_BFIN_EVAL_ADAV80X
46 tristate "Support for the EVAL-ADAV80X boards on Blackfin eval boards" 47 tristate "Support for the EVAL-ADAV80X boards on Blackfin eval boards"
47 depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI 48 depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI
48 select SND_BF5XX_SOC_I2S 49 select SND_BF5XX_SOC_I2S
49 select SND_SOC_ADAV80X 50 select SND_SOC_ADAV801 if SPI_MASTER
51 select SND_SOC_ADAV803 if I2C
50 help 52 help
51 Say Y if you want to add support for the Analog Devices EVAL-ADAV801 or 53 Say Y if you want to add support for the Analog Devices EVAL-ADAV801 or
52 EVAL-ADAV803 board connected to one of the Blackfin evaluation boards 54 EVAL-ADAV803 board connected to one of the Blackfin evaluation boards
@@ -67,7 +69,8 @@ config SND_BF5XX_SOC_AD193X
67 tristate "SoC AD193X Audio support for Blackfin" 69 tristate "SoC AD193X Audio support for Blackfin"
68 depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI 70 depends on SND_BF5XX_I2S && SND_SOC_I2C_AND_SPI
69 select SND_BF5XX_SOC_I2S 71 select SND_BF5XX_SOC_I2S
70 select SND_SOC_AD193X 72 select SND_SOC_AD193X_I2C if I2C
73 select SND_SOC_AD193X_SPI if SPI_MASTER
71 help 74 help
72 Say Y if you want to add support for AD193X codec on Blackfin. 75 Say Y if you want to add support for AD193X codec on Blackfin.
73 This driver supports AD1936, AD1937, AD1938 and AD1939. 76 This driver supports AD1936, AD1937, AD1938 and AD1939.
diff --git a/sound/soc/cirrus/Kconfig b/sound/soc/cirrus/Kconfig
index 06f938deda15..5477c5475923 100644
--- a/sound/soc/cirrus/Kconfig
+++ b/sound/soc/cirrus/Kconfig
@@ -1,6 +1,6 @@
1config SND_EP93XX_SOC 1config SND_EP93XX_SOC
2 tristate "SoC Audio support for the Cirrus Logic EP93xx series" 2 tristate "SoC Audio support for the Cirrus Logic EP93xx series"
3 depends on (ARCH_EP93XX || COMPILE_TEST) && SND_SOC 3 depends on ARCH_EP93XX || COMPILE_TEST
4 select SND_SOC_GENERIC_DMAENGINE_PCM 4 select SND_SOC_GENERIC_DMAENGINE_PCM
5 help 5 help
6 Say Y or M if you want to add support for codecs attached to 6 Say Y or M if you want to add support for codecs attached to
@@ -18,7 +18,7 @@ config SND_EP93XX_SOC_SNAPPERCL15
18 tristate "SoC Audio support for Bluewater Systems Snapper CL15 module" 18 tristate "SoC Audio support for Bluewater Systems Snapper CL15 module"
19 depends on SND_EP93XX_SOC && MACH_SNAPPER_CL15 19 depends on SND_EP93XX_SOC && MACH_SNAPPER_CL15
20 select SND_EP93XX_SOC_I2S 20 select SND_EP93XX_SOC_I2S
21 select SND_SOC_TLV320AIC23 21 select SND_SOC_TLV320AIC23_I2C
22 help 22 help
23 Say Y or M here if you want to add support for I2S audio on the 23 Say Y or M here if you want to add support for I2S audio on the
24 Bluewater Systems Snapper CL15 module. 24 Bluewater Systems Snapper CL15 module.
diff --git a/sound/soc/cirrus/snappercl15.c b/sound/soc/cirrus/snappercl15.c
index 29238a7476dd..5b68b106cfc2 100644
--- a/sound/soc/cirrus/snappercl15.c
+++ b/sound/soc/cirrus/snappercl15.c
@@ -65,18 +65,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
65 {"MICIN", NULL, "Mic Jack"}, 65 {"MICIN", NULL, "Mic Jack"},
66}; 66};
67 67
68static int snappercl15_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
69{
70 struct snd_soc_codec *codec = rtd->codec;
71 struct snd_soc_dapm_context *dapm = &codec->dapm;
72
73 snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
74 ARRAY_SIZE(tlv320aic23_dapm_widgets));
75
76 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
77 return 0;
78}
79
80static struct snd_soc_dai_link snappercl15_dai = { 68static struct snd_soc_dai_link snappercl15_dai = {
81 .name = "tlv320aic23", 69 .name = "tlv320aic23",
82 .stream_name = "AIC23", 70 .stream_name = "AIC23",
@@ -84,7 +72,6 @@ static struct snd_soc_dai_link snappercl15_dai = {
84 .codec_dai_name = "tlv320aic23-hifi", 72 .codec_dai_name = "tlv320aic23-hifi",
85 .codec_name = "tlv320aic23-codec.0-001a", 73 .codec_name = "tlv320aic23-codec.0-001a",
86 .platform_name = "ep93xx-i2s", 74 .platform_name = "ep93xx-i2s",
87 .init = snappercl15_tlv320aic23_init,
88 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF | 75 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF |
89 SND_SOC_DAIFMT_CBS_CFS, 76 SND_SOC_DAIFMT_CBS_CFS,
90 .ops = &snappercl15_ops, 77 .ops = &snappercl15_ops,
@@ -95,6 +82,11 @@ static struct snd_soc_card snd_soc_snappercl15 = {
95 .owner = THIS_MODULE, 82 .owner = THIS_MODULE,
96 .dai_link = &snappercl15_dai, 83 .dai_link = &snappercl15_dai,
97 .num_links = 1, 84 .num_links = 1,
85
86 .dapm_widgets = tlv320aic23_dapm_widgets,
87 .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
88 .dapm_routes = audio_map,
89 .num_dapm_routes = ARRAY_SIZE(audio_map),
98}; 90};
99 91
100static int snappercl15_probe(struct platform_device *pdev) 92static int snappercl15_probe(struct platform_device *pdev)
diff --git a/sound/soc/codecs/88pm860x-codec.c b/sound/soc/codecs/88pm860x-codec.c
index 647a72cda005..b07e17160f94 100644
--- a/sound/soc/codecs/88pm860x-codec.c
+++ b/sound/soc/codecs/88pm860x-codec.c
@@ -448,38 +448,38 @@ static const char *pm860x_opamp_texts[] = {"-50%", "-25%", "0%", "75%"};
448 448
449static const char *pm860x_pa_texts[] = {"-33%", "0%", "33%", "66%"}; 449static const char *pm860x_pa_texts[] = {"-33%", "0%", "33%", "66%"};
450 450
451static const struct soc_enum pm860x_hs1_opamp_enum = 451static SOC_ENUM_SINGLE_DECL(pm860x_hs1_opamp_enum,
452 SOC_ENUM_SINGLE(PM860X_HS1_CTRL, 5, 4, pm860x_opamp_texts); 452 PM860X_HS1_CTRL, 5, pm860x_opamp_texts);
453 453
454static const struct soc_enum pm860x_hs2_opamp_enum = 454static SOC_ENUM_SINGLE_DECL(pm860x_hs2_opamp_enum,
455 SOC_ENUM_SINGLE(PM860X_HS2_CTRL, 5, 4, pm860x_opamp_texts); 455 PM860X_HS2_CTRL, 5, pm860x_opamp_texts);
456 456
457static const struct soc_enum pm860x_hs1_pa_enum = 457static SOC_ENUM_SINGLE_DECL(pm860x_hs1_pa_enum,
458 SOC_ENUM_SINGLE(PM860X_HS1_CTRL, 3, 4, pm860x_pa_texts); 458 PM860X_HS1_CTRL, 3, pm860x_pa_texts);
459 459
460static const struct soc_enum pm860x_hs2_pa_enum = 460static SOC_ENUM_SINGLE_DECL(pm860x_hs2_pa_enum,
461 SOC_ENUM_SINGLE(PM860X_HS2_CTRL, 3, 4, pm860x_pa_texts); 461 PM860X_HS2_CTRL, 3, pm860x_pa_texts);
462 462
463static const struct soc_enum pm860x_lo1_opamp_enum = 463static SOC_ENUM_SINGLE_DECL(pm860x_lo1_opamp_enum,
464 SOC_ENUM_SINGLE(PM860X_LO1_CTRL, 5, 4, pm860x_opamp_texts); 464 PM860X_LO1_CTRL, 5, pm860x_opamp_texts);
465 465
466static const struct soc_enum pm860x_lo2_opamp_enum = 466static SOC_ENUM_SINGLE_DECL(pm860x_lo2_opamp_enum,
467 SOC_ENUM_SINGLE(PM860X_LO2_CTRL, 5, 4, pm860x_opamp_texts); 467 PM860X_LO2_CTRL, 5, pm860x_opamp_texts);
468 468
469static const struct soc_enum pm860x_lo1_pa_enum = 469static SOC_ENUM_SINGLE_DECL(pm860x_lo1_pa_enum,
470 SOC_ENUM_SINGLE(PM860X_LO1_CTRL, 3, 4, pm860x_pa_texts); 470 PM860X_LO1_CTRL, 3, pm860x_pa_texts);
471 471
472static const struct soc_enum pm860x_lo2_pa_enum = 472static SOC_ENUM_SINGLE_DECL(pm860x_lo2_pa_enum,
473 SOC_ENUM_SINGLE(PM860X_LO2_CTRL, 3, 4, pm860x_pa_texts); 473 PM860X_LO2_CTRL, 3, pm860x_pa_texts);
474 474
475static const struct soc_enum pm860x_spk_pa_enum = 475static SOC_ENUM_SINGLE_DECL(pm860x_spk_pa_enum,
476 SOC_ENUM_SINGLE(PM860X_EAR_CTRL_1, 5, 4, pm860x_pa_texts); 476 PM860X_EAR_CTRL_1, 5, pm860x_pa_texts);
477 477
478static const struct soc_enum pm860x_ear_pa_enum = 478static SOC_ENUM_SINGLE_DECL(pm860x_ear_pa_enum,
479 SOC_ENUM_SINGLE(PM860X_EAR_CTRL_2, 0, 4, pm860x_pa_texts); 479 PM860X_EAR_CTRL_2, 0, pm860x_pa_texts);
480 480
481static const struct soc_enum pm860x_spk_ear_opamp_enum = 481static SOC_ENUM_SINGLE_DECL(pm860x_spk_ear_opamp_enum,
482 SOC_ENUM_SINGLE(PM860X_EAR_CTRL_1, 3, 4, pm860x_opamp_texts); 482 PM860X_EAR_CTRL_1, 3, pm860x_opamp_texts);
483 483
484static const struct snd_kcontrol_new pm860x_snd_controls[] = { 484static const struct snd_kcontrol_new pm860x_snd_controls[] = {
485 SOC_DOUBLE_R_TLV("ADC Capture Volume", PM860X_ADC_ANA_2, 485 SOC_DOUBLE_R_TLV("ADC Capture Volume", PM860X_ADC_ANA_2,
@@ -561,8 +561,8 @@ static const char *aif1_text[] = {
561 "PCM L", "PCM R", 561 "PCM L", "PCM R",
562}; 562};
563 563
564static const struct soc_enum aif1_enum = 564static SOC_ENUM_SINGLE_DECL(aif1_enum,
565 SOC_ENUM_SINGLE(PM860X_PCM_IFACE_3, 6, 2, aif1_text); 565 PM860X_PCM_IFACE_3, 6, aif1_text);
566 566
567static const struct snd_kcontrol_new aif1_mux = 567static const struct snd_kcontrol_new aif1_mux =
568 SOC_DAPM_ENUM("PCM Mux", aif1_enum); 568 SOC_DAPM_ENUM("PCM Mux", aif1_enum);
@@ -572,8 +572,8 @@ static const char *i2s_din_text[] = {
572 "DIN", "DIN1", 572 "DIN", "DIN1",
573}; 573};
574 574
575static const struct soc_enum i2s_din_enum = 575static SOC_ENUM_SINGLE_DECL(i2s_din_enum,
576 SOC_ENUM_SINGLE(PM860X_I2S_IFACE_3, 1, 2, i2s_din_text); 576 PM860X_I2S_IFACE_3, 1, i2s_din_text);
577 577
578static const struct snd_kcontrol_new i2s_din_mux = 578static const struct snd_kcontrol_new i2s_din_mux =
579 SOC_DAPM_ENUM("I2S DIN Mux", i2s_din_enum); 579 SOC_DAPM_ENUM("I2S DIN Mux", i2s_din_enum);
@@ -583,8 +583,8 @@ static const char *i2s_mic_text[] = {
583 "Ex PA", "ADC", 583 "Ex PA", "ADC",
584}; 584};
585 585
586static const struct soc_enum i2s_mic_enum = 586static SOC_ENUM_SINGLE_DECL(i2s_mic_enum,
587 SOC_ENUM_SINGLE(PM860X_I2S_IFACE_3, 4, 2, i2s_mic_text); 587 PM860X_I2S_IFACE_3, 4, i2s_mic_text);
588 588
589static const struct snd_kcontrol_new i2s_mic_mux = 589static const struct snd_kcontrol_new i2s_mic_mux =
590 SOC_DAPM_ENUM("I2S Mic Mux", i2s_mic_enum); 590 SOC_DAPM_ENUM("I2S Mic Mux", i2s_mic_enum);
@@ -594,8 +594,8 @@ static const char *adcl_text[] = {
594 "ADCR", "ADCL", 594 "ADCR", "ADCL",
595}; 595};
596 596
597static const struct soc_enum adcl_enum = 597static SOC_ENUM_SINGLE_DECL(adcl_enum,
598 SOC_ENUM_SINGLE(PM860X_PCM_IFACE_3, 4, 2, adcl_text); 598 PM860X_PCM_IFACE_3, 4, adcl_text);
599 599
600static const struct snd_kcontrol_new adcl_mux = 600static const struct snd_kcontrol_new adcl_mux =
601 SOC_DAPM_ENUM("ADC Left Mux", adcl_enum); 601 SOC_DAPM_ENUM("ADC Left Mux", adcl_enum);
@@ -605,8 +605,8 @@ static const char *adcr_text[] = {
605 "ADCL", "ADCR", 605 "ADCL", "ADCR",
606}; 606};
607 607
608static const struct soc_enum adcr_enum = 608static SOC_ENUM_SINGLE_DECL(adcr_enum,
609 SOC_ENUM_SINGLE(PM860X_PCM_IFACE_3, 2, 2, adcr_text); 609 PM860X_PCM_IFACE_3, 2, adcr_text);
610 610
611static const struct snd_kcontrol_new adcr_mux = 611static const struct snd_kcontrol_new adcr_mux =
612 SOC_DAPM_ENUM("ADC Right Mux", adcr_enum); 612 SOC_DAPM_ENUM("ADC Right Mux", adcr_enum);
@@ -616,8 +616,8 @@ static const char *adcr_ec_text[] = {
616 "ADCR", "EC", 616 "ADCR", "EC",
617}; 617};
618 618
619static const struct soc_enum adcr_ec_enum = 619static SOC_ENUM_SINGLE_DECL(adcr_ec_enum,
620 SOC_ENUM_SINGLE(PM860X_ADC_EN_2, 3, 2, adcr_ec_text); 620 PM860X_ADC_EN_2, 3, adcr_ec_text);
621 621
622static const struct snd_kcontrol_new adcr_ec_mux = 622static const struct snd_kcontrol_new adcr_ec_mux =
623 SOC_DAPM_ENUM("ADCR EC Mux", adcr_ec_enum); 623 SOC_DAPM_ENUM("ADCR EC Mux", adcr_ec_enum);
@@ -627,8 +627,8 @@ static const char *ec_text[] = {
627 "Left", "Right", "Left + Right", 627 "Left", "Right", "Left + Right",
628}; 628};
629 629
630static const struct soc_enum ec_enum = 630static SOC_ENUM_SINGLE_DECL(ec_enum,
631 SOC_ENUM_SINGLE(PM860X_EC_PATH, 1, 3, ec_text); 631 PM860X_EC_PATH, 1, ec_text);
632 632
633static const struct snd_kcontrol_new ec_mux = 633static const struct snd_kcontrol_new ec_mux =
634 SOC_DAPM_ENUM("EC Mux", ec_enum); 634 SOC_DAPM_ENUM("EC Mux", ec_enum);
@@ -638,36 +638,36 @@ static const char *dac_text[] = {
638}; 638};
639 639
640/* DAC Headset 1 Mux / Mux10 */ 640/* DAC Headset 1 Mux / Mux10 */
641static const struct soc_enum dac_hs1_enum = 641static SOC_ENUM_SINGLE_DECL(dac_hs1_enum,
642 SOC_ENUM_SINGLE(PM860X_ANA_INPUT_SEL_1, 0, 4, dac_text); 642 PM860X_ANA_INPUT_SEL_1, 0, dac_text);
643 643
644static const struct snd_kcontrol_new dac_hs1_mux = 644static const struct snd_kcontrol_new dac_hs1_mux =
645 SOC_DAPM_ENUM("DAC HS1 Mux", dac_hs1_enum); 645 SOC_DAPM_ENUM("DAC HS1 Mux", dac_hs1_enum);
646 646
647/* DAC Headset 2 Mux / Mux11 */ 647/* DAC Headset 2 Mux / Mux11 */
648static const struct soc_enum dac_hs2_enum = 648static SOC_ENUM_SINGLE_DECL(dac_hs2_enum,
649 SOC_ENUM_SINGLE(PM860X_ANA_INPUT_SEL_1, 2, 4, dac_text); 649 PM860X_ANA_INPUT_SEL_1, 2, dac_text);
650 650
651static const struct snd_kcontrol_new dac_hs2_mux = 651static const struct snd_kcontrol_new dac_hs2_mux =
652 SOC_DAPM_ENUM("DAC HS2 Mux", dac_hs2_enum); 652 SOC_DAPM_ENUM("DAC HS2 Mux", dac_hs2_enum);
653 653
654/* DAC Lineout 1 Mux / Mux12 */ 654/* DAC Lineout 1 Mux / Mux12 */
655static const struct soc_enum dac_lo1_enum = 655static SOC_ENUM_SINGLE_DECL(dac_lo1_enum,
656 SOC_ENUM_SINGLE(PM860X_ANA_INPUT_SEL_1, 4, 4, dac_text); 656 PM860X_ANA_INPUT_SEL_1, 4, dac_text);
657 657
658static const struct snd_kcontrol_new dac_lo1_mux = 658static const struct snd_kcontrol_new dac_lo1_mux =
659 SOC_DAPM_ENUM("DAC LO1 Mux", dac_lo1_enum); 659 SOC_DAPM_ENUM("DAC LO1 Mux", dac_lo1_enum);
660 660
661/* DAC Lineout 2 Mux / Mux13 */ 661/* DAC Lineout 2 Mux / Mux13 */
662static const struct soc_enum dac_lo2_enum = 662static SOC_ENUM_SINGLE_DECL(dac_lo2_enum,
663 SOC_ENUM_SINGLE(PM860X_ANA_INPUT_SEL_1, 6, 4, dac_text); 663 PM860X_ANA_INPUT_SEL_1, 6, dac_text);
664 664
665static const struct snd_kcontrol_new dac_lo2_mux = 665static const struct snd_kcontrol_new dac_lo2_mux =
666 SOC_DAPM_ENUM("DAC LO2 Mux", dac_lo2_enum); 666 SOC_DAPM_ENUM("DAC LO2 Mux", dac_lo2_enum);
667 667
668/* DAC Spearker Earphone Mux / Mux14 */ 668/* DAC Spearker Earphone Mux / Mux14 */
669static const struct soc_enum dac_spk_ear_enum = 669static SOC_ENUM_SINGLE_DECL(dac_spk_ear_enum,
670 SOC_ENUM_SINGLE(PM860X_ANA_INPUT_SEL_2, 0, 4, dac_text); 670 PM860X_ANA_INPUT_SEL_2, 0, dac_text);
671 671
672static const struct snd_kcontrol_new dac_spk_ear_mux = 672static const struct snd_kcontrol_new dac_spk_ear_mux =
673 SOC_DAPM_ENUM("DAC SP Mux", dac_spk_ear_enum); 673 SOC_DAPM_ENUM("DAC SP Mux", dac_spk_ear_enum);
@@ -677,29 +677,29 @@ static const char *in_text[] = {
677 "Digital", "Analog", 677 "Digital", "Analog",
678}; 678};
679 679
680static const struct soc_enum hs1_enum = 680static SOC_ENUM_SINGLE_DECL(hs1_enum,
681 SOC_ENUM_SINGLE(PM860X_ANA_TO_ANA, 0, 2, in_text); 681 PM860X_ANA_TO_ANA, 0, in_text);
682 682
683static const struct snd_kcontrol_new hs1_mux = 683static const struct snd_kcontrol_new hs1_mux =
684 SOC_DAPM_ENUM("Headset1 Mux", hs1_enum); 684 SOC_DAPM_ENUM("Headset1 Mux", hs1_enum);
685 685
686/* Headset 2 Mux / Mux16 */ 686/* Headset 2 Mux / Mux16 */
687static const struct soc_enum hs2_enum = 687static SOC_ENUM_SINGLE_DECL(hs2_enum,
688 SOC_ENUM_SINGLE(PM860X_ANA_TO_ANA, 1, 2, in_text); 688 PM860X_ANA_TO_ANA, 1, in_text);
689 689
690static const struct snd_kcontrol_new hs2_mux = 690static const struct snd_kcontrol_new hs2_mux =
691 SOC_DAPM_ENUM("Headset2 Mux", hs2_enum); 691 SOC_DAPM_ENUM("Headset2 Mux", hs2_enum);
692 692
693/* Lineout 1 Mux / Mux17 */ 693/* Lineout 1 Mux / Mux17 */
694static const struct soc_enum lo1_enum = 694static SOC_ENUM_SINGLE_DECL(lo1_enum,
695 SOC_ENUM_SINGLE(PM860X_ANA_TO_ANA, 2, 2, in_text); 695 PM860X_ANA_TO_ANA, 2, in_text);
696 696
697static const struct snd_kcontrol_new lo1_mux = 697static const struct snd_kcontrol_new lo1_mux =
698 SOC_DAPM_ENUM("Lineout1 Mux", lo1_enum); 698 SOC_DAPM_ENUM("Lineout1 Mux", lo1_enum);
699 699
700/* Lineout 2 Mux / Mux18 */ 700/* Lineout 2 Mux / Mux18 */
701static const struct soc_enum lo2_enum = 701static SOC_ENUM_SINGLE_DECL(lo2_enum,
702 SOC_ENUM_SINGLE(PM860X_ANA_TO_ANA, 3, 2, in_text); 702 PM860X_ANA_TO_ANA, 3, in_text);
703 703
704static const struct snd_kcontrol_new lo2_mux = 704static const struct snd_kcontrol_new lo2_mux =
705 SOC_DAPM_ENUM("Lineout2 Mux", lo2_enum); 705 SOC_DAPM_ENUM("Lineout2 Mux", lo2_enum);
@@ -709,8 +709,8 @@ static const char *spk_text[] = {
709 "Earpiece", "Speaker", 709 "Earpiece", "Speaker",
710}; 710};
711 711
712static const struct soc_enum spk_enum = 712static SOC_ENUM_SINGLE_DECL(spk_enum,
713 SOC_ENUM_SINGLE(PM860X_ANA_TO_ANA, 6, 2, spk_text); 713 PM860X_ANA_TO_ANA, 6, spk_text);
714 714
715static const struct snd_kcontrol_new spk_demux = 715static const struct snd_kcontrol_new spk_demux =
716 SOC_DAPM_ENUM("Speaker Earpiece Demux", spk_enum); 716 SOC_DAPM_ENUM("Speaker Earpiece Demux", spk_enum);
@@ -720,8 +720,8 @@ static const char *mic_text[] = {
720 "Mic 1", "Mic 2", 720 "Mic 1", "Mic 2",
721}; 721};
722 722
723static const struct soc_enum mic_enum = 723static SOC_ENUM_SINGLE_DECL(mic_enum,
724 SOC_ENUM_SINGLE(PM860X_ADC_ANA_4, 4, 2, mic_text); 724 PM860X_ADC_ANA_4, 4, mic_text);
725 725
726static const struct snd_kcontrol_new mic_mux = 726static const struct snd_kcontrol_new mic_mux =
727 SOC_DAPM_ENUM("MIC Mux", mic_enum); 727 SOC_DAPM_ENUM("MIC Mux", mic_enum);
@@ -1327,8 +1327,7 @@ static int pm860x_probe(struct snd_soc_codec *codec)
1327 1327
1328 pm860x->codec = codec; 1328 pm860x->codec = codec;
1329 1329
1330 codec->control_data = pm860x->regmap; 1330 ret = snd_soc_codec_set_cache_io(codec, pm860x->regmap);
1331 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
1332 if (ret) 1331 if (ret)
1333 return ret; 1332 return ret;
1334 1333
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 983d087aa92a..f0e840137887 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -8,6 +8,8 @@ config SND_SOC_I2C_AND_SPI
8 default y if I2C=y 8 default y if I2C=y
9 default y if SPI_MASTER=y 9 default y if SPI_MASTER=y
10 10
11menu "CODEC drivers"
12
11config SND_SOC_ALL_CODECS 13config SND_SOC_ALL_CODECS
12 tristate "Build all ASoC CODEC drivers" 14 tristate "Build all ASoC CODEC drivers"
13 depends on COMPILE_TEST 15 depends on COMPILE_TEST
@@ -16,15 +18,20 @@ config SND_SOC_ALL_CODECS
16 select SND_SOC_AB8500_CODEC if ABX500_CORE 18 select SND_SOC_AB8500_CODEC if ABX500_CORE
17 select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS 19 select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS
18 select SND_SOC_AD1836 if SPI_MASTER 20 select SND_SOC_AD1836 if SPI_MASTER
19 select SND_SOC_AD193X if SND_SOC_I2C_AND_SPI 21 select SND_SOC_AD193X_SPI if SPI_MASTER
22 select SND_SOC_AD193X_I2C if I2C
20 select SND_SOC_AD1980 if SND_SOC_AC97_BUS 23 select SND_SOC_AD1980 if SND_SOC_AC97_BUS
21 select SND_SOC_AD73311 24 select SND_SOC_AD73311
22 select SND_SOC_ADAU1373 if I2C 25 select SND_SOC_ADAU1373 if I2C
23 select SND_SOC_ADAV80X if SND_SOC_I2C_AND_SPI 26 select SND_SOC_ADAV801 if SPI_MASTER
27 select SND_SOC_ADAV803 if I2C
28 select SND_SOC_ADAU1977_SPI if SPI_MASTER
29 select SND_SOC_ADAU1977_I2C if I2C
24 select SND_SOC_ADAU1701 if I2C 30 select SND_SOC_ADAU1701 if I2C
25 select SND_SOC_ADS117X 31 select SND_SOC_ADS117X
26 select SND_SOC_AK4104 if SPI_MASTER 32 select SND_SOC_AK4104 if SPI_MASTER
27 select SND_SOC_AK4535 if I2C 33 select SND_SOC_AK4535 if I2C
34 select SND_SOC_AK4554
28 select SND_SOC_AK4641 if I2C 35 select SND_SOC_AK4641 if I2C
29 select SND_SOC_AK4642 if I2C 36 select SND_SOC_AK4642 if I2C
30 select SND_SOC_AK4671 if I2C 37 select SND_SOC_AK4671 if I2C
@@ -37,6 +44,7 @@ config SND_SOC_ALL_CODECS
37 select SND_SOC_CS42L73 if I2C 44 select SND_SOC_CS42L73 if I2C
38 select SND_SOC_CS4270 if I2C 45 select SND_SOC_CS4270 if I2C
39 select SND_SOC_CS4271 if SND_SOC_I2C_AND_SPI 46 select SND_SOC_CS4271 if SND_SOC_I2C_AND_SPI
47 select SND_SOC_CS42XX8_I2C if I2C
40 select SND_SOC_CX20442 if TTY 48 select SND_SOC_CX20442 if TTY
41 select SND_SOC_DA7210 if I2C 49 select SND_SOC_DA7210 if I2C
42 select SND_SOC_DA7213 if I2C 50 select SND_SOC_DA7213 if I2C
@@ -59,20 +67,26 @@ config SND_SOC_ALL_CODECS
59 select SND_SOC_PCM1681 if I2C 67 select SND_SOC_PCM1681 if I2C
60 select SND_SOC_PCM1792A if SPI_MASTER 68 select SND_SOC_PCM1792A if SPI_MASTER
61 select SND_SOC_PCM3008 69 select SND_SOC_PCM3008
70 select SND_SOC_PCM512x_I2C if I2C
71 select SND_SOC_PCM512x_SPI if SPI_MASTER
62 select SND_SOC_RT5631 if I2C 72 select SND_SOC_RT5631 if I2C
63 select SND_SOC_RT5640 if I2C 73 select SND_SOC_RT5640 if I2C
64 select SND_SOC_SGTL5000 if I2C 74 select SND_SOC_SGTL5000 if I2C
65 select SND_SOC_SI476X if MFD_SI476X_CORE 75 select SND_SOC_SI476X if MFD_SI476X_CORE
76 select SND_SOC_SIRF_AUDIO_CODEC
66 select SND_SOC_SN95031 if INTEL_SCU_IPC 77 select SND_SOC_SN95031 if INTEL_SCU_IPC
67 select SND_SOC_SPDIF 78 select SND_SOC_SPDIF
68 select SND_SOC_SSM2518 if I2C 79 select SND_SOC_SSM2518 if I2C
69 select SND_SOC_SSM2602 if SND_SOC_I2C_AND_SPI 80 select SND_SOC_SSM2602_SPI if SPI_MASTER
81 select SND_SOC_SSM2602_I2C if I2C
70 select SND_SOC_STA32X if I2C 82 select SND_SOC_STA32X if I2C
71 select SND_SOC_STA529 if I2C 83 select SND_SOC_STA529 if I2C
72 select SND_SOC_STAC9766 if SND_SOC_AC97_BUS 84 select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
73 select SND_SOC_TAS5086 if I2C 85 select SND_SOC_TAS5086 if I2C
74 select SND_SOC_TLV320AIC23 if I2C 86 select SND_SOC_TLV320AIC23_I2C if I2C
87 select SND_SOC_TLV320AIC23_SPI if SPI_MASTER
75 select SND_SOC_TLV320AIC26 if SPI_MASTER 88 select SND_SOC_TLV320AIC26 if SPI_MASTER
89 select SND_SOC_TLV320AIC31XX if I2C
76 select SND_SOC_TLV320AIC32X4 if I2C 90 select SND_SOC_TLV320AIC32X4 if I2C
77 select SND_SOC_TLV320AIC3X if I2C 91 select SND_SOC_TLV320AIC3X if I2C
78 select SND_SOC_TPA6130A2 if I2C 92 select SND_SOC_TPA6130A2 if I2C
@@ -182,6 +196,14 @@ config SND_SOC_AD1836
182config SND_SOC_AD193X 196config SND_SOC_AD193X
183 tristate 197 tristate
184 198
199config SND_SOC_AD193X_SPI
200 tristate
201 select SND_SOC_AD193X
202
203config SND_SOC_AD193X_I2C
204 tristate
205 select SND_SOC_AD193X
206
185config SND_SOC_AD1980 207config SND_SOC_AD1980
186 tristate 208 tristate
187 209
@@ -189,41 +211,66 @@ config SND_SOC_AD73311
189 tristate 211 tristate
190 212
191config SND_SOC_ADAU1701 213config SND_SOC_ADAU1701
214 tristate "Analog Devices ADAU1701 CODEC"
215 depends on I2C
192 select SND_SOC_SIGMADSP 216 select SND_SOC_SIGMADSP
193 tristate
194 217
195config SND_SOC_ADAU1373 218config SND_SOC_ADAU1373
196 tristate 219 tristate
197 220
221config SND_SOC_ADAU1977
222 tristate
223
224config SND_SOC_ADAU1977_SPI
225 tristate
226 select SND_SOC_ADAU1977
227 select REGMAP_SPI
228
229config SND_SOC_ADAU1977_I2C
230 tristate
231 select SND_SOC_ADAU1977
232 select REGMAP_I2C
233
198config SND_SOC_ADAV80X 234config SND_SOC_ADAV80X
199 tristate 235 tristate
200 236
237config SND_SOC_ADAV801
238 tristate
239 select SND_SOC_ADAV80X
240
241config SND_SOC_ADAV803
242 tristate
243 select SND_SOC_ADAV80X
244
201config SND_SOC_ADS117X 245config SND_SOC_ADS117X
202 tristate 246 tristate
203 247
204config SND_SOC_AK4104 248config SND_SOC_AK4104
205 tristate 249 tristate "AKM AK4104 CODEC"
250 depends on SPI_MASTER
206 251
207config SND_SOC_AK4535 252config SND_SOC_AK4535
208 tristate 253 tristate
209 254
210config SND_SOC_AK4554 255config SND_SOC_AK4554
211 tristate 256 tristate "AKM AK4554 CODEC"
212 257
213config SND_SOC_AK4641 258config SND_SOC_AK4641
214 tristate 259 tristate
215 260
216config SND_SOC_AK4642 261config SND_SOC_AK4642
217 tristate 262 tristate "AKM AK4642 CODEC"
263 depends on I2C
218 264
219config SND_SOC_AK4671 265config SND_SOC_AK4671
220 tristate 266 tristate
221 267
222config SND_SOC_AK5386 268config SND_SOC_AK5386
223 tristate 269 tristate "AKM AK5638 CODEC"
224 270
225config SND_SOC_ALC5623 271config SND_SOC_ALC5623
226 tristate 272 tristate
273
227config SND_SOC_ALC5632 274config SND_SOC_ALC5632
228 tristate 275 tristate
229 276
@@ -234,14 +281,17 @@ config SND_SOC_CS42L51
234 tristate 281 tristate
235 282
236config SND_SOC_CS42L52 283config SND_SOC_CS42L52
237 tristate 284 tristate "Cirrus Logic CS42L52 CODEC"
285 depends on I2C
238 286
239config SND_SOC_CS42L73 287config SND_SOC_CS42L73
240 tristate 288 tristate "Cirrus Logic CS42L73 CODEC"
289 depends on I2C
241 290
242# Cirrus Logic CS4270 Codec 291# Cirrus Logic CS4270 Codec
243config SND_SOC_CS4270 292config SND_SOC_CS4270
244 tristate 293 tristate "Cirrus Logic CS4270 CODEC"
294 depends on I2C
245 295
246# Cirrus Logic CS4270 Codec VD = 3.3V Errata 296# Cirrus Logic CS4270 Codec VD = 3.3V Errata
247# Select if you are affected by the errata where the part will not function 297# Select if you are affected by the errata where the part will not function
@@ -252,8 +302,18 @@ config SND_SOC_CS4270_VD33_ERRATA
252 depends on SND_SOC_CS4270 302 depends on SND_SOC_CS4270
253 303
254config SND_SOC_CS4271 304config SND_SOC_CS4271
305 tristate "Cirrus Logic CS4271 CODEC"
306 depends on SND_SOC_I2C_AND_SPI
307
308config SND_SOC_CS42XX8
255 tristate 309 tristate
256 310
311config SND_SOC_CS42XX8_I2C
312 tristate "Cirrus Logic CS42448/CS42888 CODEC (I2C)"
313 depends on I2C
314 select SND_SOC_CS42XX8
315 select REGMAP_I2C
316
257config SND_SOC_CX20442 317config SND_SOC_CX20442
258 tristate 318 tristate
259 depends on TTY 319 depends on TTY
@@ -283,6 +343,9 @@ config SND_SOC_BT_SCO
283config SND_SOC_DMIC 343config SND_SOC_DMIC
284 tristate 344 tristate
285 345
346config SND_SOC_HDMI_CODEC
347 tristate "HDMI stub CODEC"
348
286config SND_SOC_ISABELLE 349config SND_SOC_ISABELLE
287 tristate 350 tristate
288 351
@@ -301,18 +364,32 @@ config SND_SOC_MAX98095
301config SND_SOC_MAX9850 364config SND_SOC_MAX9850
302 tristate 365 tristate
303 366
304config SND_SOC_HDMI_CODEC
305 tristate
306
307config SND_SOC_PCM1681 367config SND_SOC_PCM1681
308 tristate 368 tristate "Texas Instruments PCM1681 CODEC"
369 depends on I2C
309 370
310config SND_SOC_PCM1792A 371config SND_SOC_PCM1792A
311 tristate 372 tristate "Texas Instruments PCM1792A CODEC"
373 depends on SPI_MASTER
312 374
313config SND_SOC_PCM3008 375config SND_SOC_PCM3008
314 tristate 376 tristate
315 377
378config SND_SOC_PCM512x
379 tristate
380
381config SND_SOC_PCM512x_I2C
382 tristate "Texas Instruments PCM512x CODECs - I2C"
383 depends on I2C
384 select SND_SOC_PCM512x
385 select REGMAP_I2C
386
387config SND_SOC_PCM512x_SPI
388 tristate "Texas Instruments PCM512x CODECs - SPI"
389 depends on SPI_MASTER
390 select SND_SOC_PCM512x
391 select REGMAP_SPI
392
316config SND_SOC_RT5631 393config SND_SOC_RT5631
317 tristate 394 tristate
318 395
@@ -321,7 +398,8 @@ config SND_SOC_RT5640
321 398
322#Freescale sgtl5000 codec 399#Freescale sgtl5000 codec
323config SND_SOC_SGTL5000 400config SND_SOC_SGTL5000
324 tristate 401 tristate "Freescale SGTL5000 CODEC"
402 depends on I2C
325 403
326config SND_SOC_SI476X 404config SND_SOC_SI476X
327 tristate 405 tristate
@@ -330,11 +408,15 @@ config SND_SOC_SIGMADSP
330 tristate 408 tristate
331 select CRC32 409 select CRC32
332 410
411config SND_SOC_SIRF_AUDIO_CODEC
412 tristate "SiRF SoC internal audio codec"
413 select REGMAP_MMIO
414
333config SND_SOC_SN95031 415config SND_SOC_SN95031
334 tristate 416 tristate
335 417
336config SND_SOC_SPDIF 418config SND_SOC_SPDIF
337 tristate 419 tristate "S/PDIF CODEC"
338 420
339config SND_SOC_SSM2518 421config SND_SOC_SSM2518
340 tristate 422 tristate
@@ -342,6 +424,14 @@ config SND_SOC_SSM2518
342config SND_SOC_SSM2602 424config SND_SOC_SSM2602
343 tristate 425 tristate
344 426
427config SND_SOC_SSM2602_SPI
428 select SND_SOC_SSM2602
429 tristate
430
431config SND_SOC_SSM2602_I2C
432 select SND_SOC_SSM2602
433 tristate
434
345config SND_SOC_STA32X 435config SND_SOC_STA32X
346 tristate 436 tristate
347 437
@@ -352,20 +442,33 @@ config SND_SOC_STAC9766
352 tristate 442 tristate
353 443
354config SND_SOC_TAS5086 444config SND_SOC_TAS5086
355 tristate 445 tristate "Texas Instruments TAS5086 speaker amplifier"
446 depends on I2C
356 447
357config SND_SOC_TLV320AIC23 448config SND_SOC_TLV320AIC23
358 tristate 449 tristate
359 450
451config SND_SOC_TLV320AIC23_I2C
452 tristate
453 select SND_SOC_TLV320AIC23
454
455config SND_SOC_TLV320AIC23_SPI
456 tristate
457 select SND_SOC_TLV320AIC23
458
360config SND_SOC_TLV320AIC26 459config SND_SOC_TLV320AIC26
361 tristate 460 tristate
362 depends on SPI 461 depends on SPI
363 462
463config SND_SOC_TLV320AIC31XX
464 tristate
465
364config SND_SOC_TLV320AIC32X4 466config SND_SOC_TLV320AIC32X4
365 tristate 467 tristate
366 468
367config SND_SOC_TLV320AIC3X 469config SND_SOC_TLV320AIC3X
368 tristate 470 tristate "Texas Instruments TLV320AIC3x CODECs"
471 depends on I2C
369 472
370config SND_SOC_TLV320DAC33 473config SND_SOC_TLV320DAC33
371 tristate 474 tristate
@@ -414,55 +517,69 @@ config SND_SOC_WM8400
414 tristate 517 tristate
415 518
416config SND_SOC_WM8510 519config SND_SOC_WM8510
417 tristate 520 tristate "Wolfson Microelectronics WM8510 CODEC"
521 depends on SND_SOC_I2C_AND_SPI
418 522
419config SND_SOC_WM8523 523config SND_SOC_WM8523
420 tristate 524 tristate "Wolfson Microelectronics WM8523 DAC"
525 depends on I2C
421 526
422config SND_SOC_WM8580 527config SND_SOC_WM8580
423 tristate 528 tristate "Wolfson Microelectronics WM8523 CODEC"
529 depends on I2C
424 530
425config SND_SOC_WM8711 531config SND_SOC_WM8711
426 tristate 532 tristate "Wolfson Microelectronics WM8711 CODEC"
533 depends on SND_SOC_I2C_AND_SPI
427 534
428config SND_SOC_WM8727 535config SND_SOC_WM8727
429 tristate 536 tristate
430 537
431config SND_SOC_WM8728 538config SND_SOC_WM8728
432 tristate 539 tristate "Wolfson Microelectronics WM8728 DAC"
540 depends on SND_SOC_I2C_AND_SPI
433 541
434config SND_SOC_WM8731 542config SND_SOC_WM8731
435 tristate 543 tristate "Wolfson Microelectronics WM8731 CODEC"
544 depends on SND_SOC_I2C_AND_SPI
436 545
437config SND_SOC_WM8737 546config SND_SOC_WM8737
438 tristate 547 tristate "Wolfson Microelectronics WM8737 ADC"
548 depends on SND_SOC_I2C_AND_SPI
439 549
440config SND_SOC_WM8741 550config SND_SOC_WM8741
441 tristate 551 tristate "Wolfson Microelectronics WM8737 DAC"
552 depends on SND_SOC_I2C_AND_SPI
442 553
443config SND_SOC_WM8750 554config SND_SOC_WM8750
444 tristate 555 tristate "Wolfson Microelectronics WM8750 CODEC"
556 depends on SND_SOC_I2C_AND_SPI
445 557
446config SND_SOC_WM8753 558config SND_SOC_WM8753
447 tristate 559 tristate "Wolfson Microelectronics WM8753 CODEC"
560 depends on SND_SOC_I2C_AND_SPI
448 561
449config SND_SOC_WM8770 562config SND_SOC_WM8770
450 tristate 563 tristate "Wolfson Microelectronics WM8770 CODEC"
564 depends on SPI_MASTER
451 565
452config SND_SOC_WM8776 566config SND_SOC_WM8776
453 tristate 567 tristate "Wolfson Microelectronics WM8776 CODEC"
568 depends on SND_SOC_I2C_AND_SPI
454 569
455config SND_SOC_WM8782 570config SND_SOC_WM8782
456 tristate 571 tristate
457 572
458config SND_SOC_WM8804 573config SND_SOC_WM8804
459 tristate 574 tristate "Wolfson Microelectronics WM8804 S/PDIF transceiver"
575 depends on SND_SOC_I2C_AND_SPI
460 576
461config SND_SOC_WM8900 577config SND_SOC_WM8900
462 tristate 578 tristate
463 579
464config SND_SOC_WM8903 580config SND_SOC_WM8903
465 tristate 581 tristate "Wolfson Microelectronics WM8903 CODEC"
582 depends on I2C
466 583
467config SND_SOC_WM8904 584config SND_SOC_WM8904
468 tristate 585 tristate
@@ -480,7 +597,8 @@ config SND_SOC_WM8961
480 tristate 597 tristate
481 598
482config SND_SOC_WM8962 599config SND_SOC_WM8962
483 tristate 600 tristate "Wolfson Microelectronics WM8962 CODEC"
601 depends on I2C
484 602
485config SND_SOC_WM8971 603config SND_SOC_WM8971
486 tristate 604 tristate
@@ -553,4 +671,7 @@ config SND_SOC_ML26124
553 tristate 671 tristate
554 672
555config SND_SOC_TPA6130A2 673config SND_SOC_TPA6130A2
556 tristate 674 tristate "Texas Instruments TPA6130A2 headphone amplifier"
675 depends on I2C
676
677endmenu
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index bc126764a44d..3c4d275d064b 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -3,11 +3,18 @@ snd-soc-ab8500-codec-objs := ab8500-codec.o
3snd-soc-ac97-objs := ac97.o 3snd-soc-ac97-objs := ac97.o
4snd-soc-ad1836-objs := ad1836.o 4snd-soc-ad1836-objs := ad1836.o
5snd-soc-ad193x-objs := ad193x.o 5snd-soc-ad193x-objs := ad193x.o
6snd-soc-ad193x-spi-objs := ad193x-spi.o
7snd-soc-ad193x-i2c-objs := ad193x-i2c.o
6snd-soc-ad1980-objs := ad1980.o 8snd-soc-ad1980-objs := ad1980.o
7snd-soc-ad73311-objs := ad73311.o 9snd-soc-ad73311-objs := ad73311.o
8snd-soc-adau1701-objs := adau1701.o 10snd-soc-adau1701-objs := adau1701.o
9snd-soc-adau1373-objs := adau1373.o 11snd-soc-adau1373-objs := adau1373.o
12snd-soc-adau1977-objs := adau1977.o
13snd-soc-adau1977-spi-objs := adau1977-spi.o
14snd-soc-adau1977-i2c-objs := adau1977-i2c.o
10snd-soc-adav80x-objs := adav80x.o 15snd-soc-adav80x-objs := adav80x.o
16snd-soc-adav801-objs := adav801.o
17snd-soc-adav803-objs := adav803.o
11snd-soc-ads117x-objs := ads117x.o 18snd-soc-ads117x-objs := ads117x.o
12snd-soc-ak4104-objs := ak4104.o 19snd-soc-ak4104-objs := ak4104.o
13snd-soc-ak4535-objs := ak4535.o 20snd-soc-ak4535-objs := ak4535.o
@@ -23,6 +30,8 @@ snd-soc-cs42l52-objs := cs42l52.o
23snd-soc-cs42l73-objs := cs42l73.o 30snd-soc-cs42l73-objs := cs42l73.o
24snd-soc-cs4270-objs := cs4270.o 31snd-soc-cs4270-objs := cs4270.o
25snd-soc-cs4271-objs := cs4271.o 32snd-soc-cs4271-objs := cs4271.o
33snd-soc-cs42xx8-objs := cs42xx8.o
34snd-soc-cs42xx8-i2c-objs := cs42xx8-i2c.o
26snd-soc-cx20442-objs := cx20442.o 35snd-soc-cx20442-objs := cx20442.o
27snd-soc-da7210-objs := da7210.o 36snd-soc-da7210-objs := da7210.o
28snd-soc-da7213-objs := da7213.o 37snd-soc-da7213-objs := da7213.o
@@ -46,6 +55,9 @@ snd-soc-hdmi-codec-objs := hdmi.o
46snd-soc-pcm1681-objs := pcm1681.o 55snd-soc-pcm1681-objs := pcm1681.o
47snd-soc-pcm1792a-codec-objs := pcm1792a.o 56snd-soc-pcm1792a-codec-objs := pcm1792a.o
48snd-soc-pcm3008-objs := pcm3008.o 57snd-soc-pcm3008-objs := pcm3008.o
58snd-soc-pcm512x-objs := pcm512x.o
59snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o
60snd-soc-pcm512x-spi-objs := pcm512x-spi.o
49snd-soc-rt5631-objs := rt5631.o 61snd-soc-rt5631-objs := rt5631.o
50snd-soc-rt5640-objs := rt5640.o 62snd-soc-rt5640-objs := rt5640.o
51snd-soc-sgtl5000-objs := sgtl5000.o 63snd-soc-sgtl5000-objs := sgtl5000.o
@@ -53,19 +65,25 @@ snd-soc-alc5623-objs := alc5623.o
53snd-soc-alc5632-objs := alc5632.o 65snd-soc-alc5632-objs := alc5632.o
54snd-soc-sigmadsp-objs := sigmadsp.o 66snd-soc-sigmadsp-objs := sigmadsp.o
55snd-soc-si476x-objs := si476x.o 67snd-soc-si476x-objs := si476x.o
68snd-soc-sirf-audio-codec-objs := sirf-audio-codec.o
56snd-soc-sn95031-objs := sn95031.o 69snd-soc-sn95031-objs := sn95031.o
57snd-soc-spdif-tx-objs := spdif_transmitter.o 70snd-soc-spdif-tx-objs := spdif_transmitter.o
58snd-soc-spdif-rx-objs := spdif_receiver.o 71snd-soc-spdif-rx-objs := spdif_receiver.o
59snd-soc-ssm2518-objs := ssm2518.o 72snd-soc-ssm2518-objs := ssm2518.o
60snd-soc-ssm2602-objs := ssm2602.o 73snd-soc-ssm2602-objs := ssm2602.o
74snd-soc-ssm2602-spi-objs := ssm2602-spi.o
75snd-soc-ssm2602-i2c-objs := ssm2602-i2c.o
61snd-soc-sta32x-objs := sta32x.o 76snd-soc-sta32x-objs := sta32x.o
62snd-soc-sta529-objs := sta529.o 77snd-soc-sta529-objs := sta529.o
63snd-soc-stac9766-objs := stac9766.o 78snd-soc-stac9766-objs := stac9766.o
64snd-soc-tas5086-objs := tas5086.o 79snd-soc-tas5086-objs := tas5086.o
65snd-soc-tlv320aic23-objs := tlv320aic23.o 80snd-soc-tlv320aic23-objs := tlv320aic23.o
81snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o
82snd-soc-tlv320aic23-spi-objs := tlv320aic23-spi.o
66snd-soc-tlv320aic26-objs := tlv320aic26.o 83snd-soc-tlv320aic26-objs := tlv320aic26.o
67snd-soc-tlv320aic3x-objs := tlv320aic3x.o 84snd-soc-tlv320aic31xx-objs := tlv320aic31xx.o
68snd-soc-tlv320aic32x4-objs := tlv320aic32x4.o 85snd-soc-tlv320aic32x4-objs := tlv320aic32x4.o
86snd-soc-tlv320aic3x-objs := tlv320aic3x.o
69snd-soc-tlv320dac33-objs := tlv320dac33.o 87snd-soc-tlv320dac33-objs := tlv320dac33.o
70snd-soc-twl4030-objs := twl4030.o 88snd-soc-twl4030-objs := twl4030.o
71snd-soc-twl6040-objs := twl6040.o 89snd-soc-twl6040-objs := twl6040.o
@@ -134,11 +152,18 @@ obj-$(CONFIG_SND_SOC_AB8500_CODEC) += snd-soc-ab8500-codec.o
134obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o 152obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o
135obj-$(CONFIG_SND_SOC_AD1836) += snd-soc-ad1836.o 153obj-$(CONFIG_SND_SOC_AD1836) += snd-soc-ad1836.o
136obj-$(CONFIG_SND_SOC_AD193X) += snd-soc-ad193x.o 154obj-$(CONFIG_SND_SOC_AD193X) += snd-soc-ad193x.o
155obj-$(CONFIG_SND_SOC_AD193X_SPI) += snd-soc-ad193x-spi.o
156obj-$(CONFIG_SND_SOC_AD193X_I2C) += snd-soc-ad193x-i2c.o
137obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o 157obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o
138obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o 158obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
139obj-$(CONFIG_SND_SOC_ADAU1373) += snd-soc-adau1373.o 159obj-$(CONFIG_SND_SOC_ADAU1373) += snd-soc-adau1373.o
160obj-$(CONFIG_SND_SOC_ADAU1977) += snd-soc-adau1977.o
161obj-$(CONFIG_SND_SOC_ADAU1977_SPI) += snd-soc-adau1977-spi.o
162obj-$(CONFIG_SND_SOC_ADAU1977_I2C) += snd-soc-adau1977-i2c.o
140obj-$(CONFIG_SND_SOC_ADAU1701) += snd-soc-adau1701.o 163obj-$(CONFIG_SND_SOC_ADAU1701) += snd-soc-adau1701.o
141obj-$(CONFIG_SND_SOC_ADAV80X) += snd-soc-adav80x.o 164obj-$(CONFIG_SND_SOC_ADAV80X) += snd-soc-adav80x.o
165obj-$(CONFIG_SND_SOC_ADAV801) += snd-soc-adav801.o
166obj-$(CONFIG_SND_SOC_ADAV803) += snd-soc-adav803.o
142obj-$(CONFIG_SND_SOC_ADS117X) += snd-soc-ads117x.o 167obj-$(CONFIG_SND_SOC_ADS117X) += snd-soc-ads117x.o
143obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o 168obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o
144obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o 169obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o
@@ -156,6 +181,8 @@ obj-$(CONFIG_SND_SOC_CS42L52) += snd-soc-cs42l52.o
156obj-$(CONFIG_SND_SOC_CS42L73) += snd-soc-cs42l73.o 181obj-$(CONFIG_SND_SOC_CS42L73) += snd-soc-cs42l73.o
157obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 182obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
158obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o 183obj-$(CONFIG_SND_SOC_CS4271) += snd-soc-cs4271.o
184obj-$(CONFIG_SND_SOC_CS42XX8) += snd-soc-cs42xx8.o
185obj-$(CONFIG_SND_SOC_CS42XX8_I2C) += snd-soc-cs42xx8-i2c.o
159obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o 186obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o
160obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o 187obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o
161obj-$(CONFIG_SND_SOC_DA7213) += snd-soc-da7213.o 188obj-$(CONFIG_SND_SOC_DA7213) += snd-soc-da7213.o
@@ -179,6 +206,9 @@ obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-soc-hdmi-codec.o
179obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o 206obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
180obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o 207obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
181obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o 208obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
209obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
210obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o
211obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
182obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o 212obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
183obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o 213obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
184obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o 214obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
@@ -188,14 +218,19 @@ obj-$(CONFIG_SND_SOC_SN95031) +=snd-soc-sn95031.o
188obj-$(CONFIG_SND_SOC_SPDIF) += snd-soc-spdif-rx.o snd-soc-spdif-tx.o 218obj-$(CONFIG_SND_SOC_SPDIF) += snd-soc-spdif-rx.o snd-soc-spdif-tx.o
189obj-$(CONFIG_SND_SOC_SSM2518) += snd-soc-ssm2518.o 219obj-$(CONFIG_SND_SOC_SSM2518) += snd-soc-ssm2518.o
190obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o 220obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o
221obj-$(CONFIG_SND_SOC_SSM2602_SPI) += snd-soc-ssm2602-spi.o
222obj-$(CONFIG_SND_SOC_SSM2602_I2C) += snd-soc-ssm2602-i2c.o
191obj-$(CONFIG_SND_SOC_STA32X) += snd-soc-sta32x.o 223obj-$(CONFIG_SND_SOC_STA32X) += snd-soc-sta32x.o
192obj-$(CONFIG_SND_SOC_STA529) += snd-soc-sta529.o 224obj-$(CONFIG_SND_SOC_STA529) += snd-soc-sta529.o
193obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o 225obj-$(CONFIG_SND_SOC_STAC9766) += snd-soc-stac9766.o
194obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o 226obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o
195obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o 227obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
228obj-$(CONFIG_SND_SOC_TLV320AIC23_I2C) += snd-soc-tlv320aic23-i2c.o
229obj-$(CONFIG_SND_SOC_TLV320AIC23_SPI) += snd-soc-tlv320aic23-spi.o
196obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o 230obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o
197obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o 231obj-$(CONFIG_SND_SOC_TLV320AIC31XX) += snd-soc-tlv320aic31xx.o
198obj-$(CONFIG_SND_SOC_TLV320AIC32X4) += snd-soc-tlv320aic32x4.o 232obj-$(CONFIG_SND_SOC_TLV320AIC32X4) += snd-soc-tlv320aic32x4.o
233obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o
199obj-$(CONFIG_SND_SOC_TLV320DAC33) += snd-soc-tlv320dac33.o 234obj-$(CONFIG_SND_SOC_TLV320DAC33) += snd-soc-tlv320dac33.o
200obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o 235obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o
201obj-$(CONFIG_SND_SOC_TWL6040) += snd-soc-twl6040.o 236obj-$(CONFIG_SND_SOC_TWL6040) += snd-soc-twl6040.o
diff --git a/sound/soc/codecs/ad1836.c b/sound/soc/codecs/ad1836.c
index 77f459868579..685998dd086e 100644
--- a/sound/soc/codecs/ad1836.c
+++ b/sound/soc/codecs/ad1836.c
@@ -40,8 +40,8 @@ struct ad1836_priv {
40 */ 40 */
41static const char *ad1836_deemp[] = {"None", "44.1kHz", "32kHz", "48kHz"}; 41static const char *ad1836_deemp[] = {"None", "44.1kHz", "32kHz", "48kHz"};
42 42
43static const struct soc_enum ad1836_deemp_enum = 43static SOC_ENUM_SINGLE_DECL(ad1836_deemp_enum,
44 SOC_ENUM_SINGLE(AD1836_DAC_CTRL1, 8, 4, ad1836_deemp); 44 AD1836_DAC_CTRL1, 8, ad1836_deemp);
45 45
46#define AD1836_DAC_VOLUME(x) \ 46#define AD1836_DAC_VOLUME(x) \
47 SOC_DOUBLE_R("DAC" #x " Playback Volume", AD1836_DAC_L_VOL(x), \ 47 SOC_DOUBLE_R("DAC" #x " Playback Volume", AD1836_DAC_L_VOL(x), \
diff --git a/sound/soc/codecs/ad193x-i2c.c b/sound/soc/codecs/ad193x-i2c.c
new file mode 100644
index 000000000000..df3a1a415825
--- /dev/null
+++ b/sound/soc/codecs/ad193x-i2c.c
@@ -0,0 +1,54 @@
1/*
2 * AD1936/AD1937 audio driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/module.h>
10#include <linux/i2c.h>
11#include <linux/regmap.h>
12
13#include <sound/soc.h>
14
15#include "ad193x.h"
16
17static const struct i2c_device_id ad193x_id[] = {
18 { "ad1936", 0 },
19 { "ad1937", 0 },
20 { }
21};
22MODULE_DEVICE_TABLE(i2c, ad193x_id);
23
24static int ad193x_i2c_probe(struct i2c_client *client,
25 const struct i2c_device_id *id)
26{
27 struct regmap_config config;
28
29 config = ad193x_regmap_config;
30 config.val_bits = 8;
31 config.reg_bits = 8;
32
33 return ad193x_probe(&client->dev, devm_regmap_init_i2c(client, &config));
34}
35
36static int ad193x_i2c_remove(struct i2c_client *client)
37{
38 snd_soc_unregister_codec(&client->dev);
39 return 0;
40}
41
42static struct i2c_driver ad193x_i2c_driver = {
43 .driver = {
44 .name = "ad193x",
45 },
46 .probe = ad193x_i2c_probe,
47 .remove = ad193x_i2c_remove,
48 .id_table = ad193x_id,
49};
50module_i2c_driver(ad193x_i2c_driver);
51
52MODULE_DESCRIPTION("ASoC AD1936/AD1937 audio CODEC driver");
53MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
54MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ad193x-spi.c b/sound/soc/codecs/ad193x-spi.c
new file mode 100644
index 000000000000..390cef9b9dc2
--- /dev/null
+++ b/sound/soc/codecs/ad193x-spi.c
@@ -0,0 +1,48 @@
1/*
2 * AD1938/AD1939 audio driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/module.h>
10#include <linux/spi/spi.h>
11#include <linux/regmap.h>
12
13#include <sound/soc.h>
14
15#include "ad193x.h"
16
17static int ad193x_spi_probe(struct spi_device *spi)
18{
19 struct regmap_config config;
20
21 config = ad193x_regmap_config;
22 config.val_bits = 8;
23 config.reg_bits = 16;
24 config.read_flag_mask = 0x09;
25 config.write_flag_mask = 0x08;
26
27 return ad193x_probe(&spi->dev, devm_regmap_init_spi(spi, &config));
28}
29
30static int ad193x_spi_remove(struct spi_device *spi)
31{
32 snd_soc_unregister_codec(&spi->dev);
33 return 0;
34}
35
36static struct spi_driver ad193x_spi_driver = {
37 .driver = {
38 .name = "ad193x",
39 .owner = THIS_MODULE,
40 },
41 .probe = ad193x_spi_probe,
42 .remove = ad193x_spi_remove,
43};
44module_spi_driver(ad193x_spi_driver);
45
46MODULE_DESCRIPTION("ASoC AD1938/AD1939 audio CODEC driver");
47MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
48MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c
index 5a42dca535b7..6844d0b2af68 100644
--- a/sound/soc/codecs/ad193x.c
+++ b/sound/soc/codecs/ad193x.c
@@ -6,12 +6,10 @@
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
8 8
9#include <linux/init.h>
10#include <linux/module.h> 9#include <linux/module.h>
11#include <linux/kernel.h> 10#include <linux/kernel.h>
12#include <linux/device.h> 11#include <linux/device.h>
13#include <linux/i2c.h> 12#include <linux/regmap.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h> 13#include <linux/slab.h>
16#include <sound/core.h> 14#include <sound/core.h>
17#include <sound/pcm.h> 15#include <sound/pcm.h>
@@ -19,6 +17,7 @@
19#include <sound/initval.h> 17#include <sound/initval.h>
20#include <sound/soc.h> 18#include <sound/soc.h>
21#include <sound/tlv.h> 19#include <sound/tlv.h>
20
22#include "ad193x.h" 21#include "ad193x.h"
23 22
24/* codec private data */ 23/* codec private data */
@@ -32,8 +31,8 @@ struct ad193x_priv {
32 */ 31 */
33static const char * const ad193x_deemp[] = {"None", "48kHz", "44.1kHz", "32kHz"}; 32static const char * const ad193x_deemp[] = {"None", "48kHz", "44.1kHz", "32kHz"};
34 33
35static const struct soc_enum ad193x_deemp_enum = 34static SOC_ENUM_SINGLE_DECL(ad193x_deemp_enum, AD193X_DAC_CTRL2, 1,
36 SOC_ENUM_SINGLE(AD193X_DAC_CTRL2, 1, 4, ad193x_deemp); 35 ad193x_deemp);
37 36
38static const DECLARE_TLV_DB_MINMAX(adau193x_tlv, -9563, 0); 37static const DECLARE_TLV_DB_MINMAX(adau193x_tlv, -9563, 0);
39 38
@@ -320,17 +319,9 @@ static struct snd_soc_dai_driver ad193x_dai = {
320 .ops = &ad193x_dai_ops, 319 .ops = &ad193x_dai_ops,
321}; 320};
322 321
323static int ad193x_probe(struct snd_soc_codec *codec) 322static int ad193x_codec_probe(struct snd_soc_codec *codec)
324{ 323{
325 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec); 324 struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec);
326 int ret;
327
328 codec->control_data = ad193x->regmap;
329 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
330 if (ret < 0) {
331 dev_err(codec->dev, "failed to set cache I/O: %d\n", ret);
332 return ret;
333 }
334 325
335 /* default setting for ad193x */ 326 /* default setting for ad193x */
336 327
@@ -348,11 +339,11 @@ static int ad193x_probe(struct snd_soc_codec *codec)
348 regmap_write(ad193x->regmap, AD193X_PLL_CLK_CTRL0, 0x99); /* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */ 339 regmap_write(ad193x->regmap, AD193X_PLL_CLK_CTRL0, 0x99); /* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */
349 regmap_write(ad193x->regmap, AD193X_PLL_CLK_CTRL1, 0x04); 340 regmap_write(ad193x->regmap, AD193X_PLL_CLK_CTRL1, 0x04);
350 341
351 return ret; 342 return 0;
352} 343}
353 344
354static struct snd_soc_codec_driver soc_codec_dev_ad193x = { 345static struct snd_soc_codec_driver soc_codec_dev_ad193x = {
355 .probe = ad193x_probe, 346 .probe = ad193x_codec_probe,
356 .controls = ad193x_snd_controls, 347 .controls = ad193x_snd_controls,
357 .num_controls = ARRAY_SIZE(ad193x_snd_controls), 348 .num_controls = ARRAY_SIZE(ad193x_snd_controls),
358 .dapm_widgets = ad193x_dapm_widgets, 349 .dapm_widgets = ad193x_dapm_widgets,
@@ -366,140 +357,31 @@ static bool adau193x_reg_volatile(struct device *dev, unsigned int reg)
366 return false; 357 return false;
367} 358}
368 359
369#if defined(CONFIG_SPI_MASTER) 360const struct regmap_config ad193x_regmap_config = {
370
371static const struct regmap_config ad193x_spi_regmap_config = {
372 .val_bits = 8,
373 .reg_bits = 16,
374 .read_flag_mask = 0x09,
375 .write_flag_mask = 0x08,
376
377 .max_register = AD193X_NUM_REGS - 1, 361 .max_register = AD193X_NUM_REGS - 1,
378 .volatile_reg = adau193x_reg_volatile, 362 .volatile_reg = adau193x_reg_volatile,
379}; 363};
364EXPORT_SYMBOL_GPL(ad193x_regmap_config);
380 365
381static int ad193x_spi_probe(struct spi_device *spi) 366int ad193x_probe(struct device *dev, struct regmap *regmap)
382{ 367{
383 struct ad193x_priv *ad193x; 368 struct ad193x_priv *ad193x;
384 369
385 ad193x = devm_kzalloc(&spi->dev, sizeof(struct ad193x_priv), 370 if (IS_ERR(regmap))
386 GFP_KERNEL); 371 return PTR_ERR(regmap);
387 if (ad193x == NULL)
388 return -ENOMEM;
389
390 ad193x->regmap = devm_regmap_init_spi(spi, &ad193x_spi_regmap_config);
391 if (IS_ERR(ad193x->regmap))
392 return PTR_ERR(ad193x->regmap);
393
394 spi_set_drvdata(spi, ad193x);
395
396 return snd_soc_register_codec(&spi->dev, &soc_codec_dev_ad193x,
397 &ad193x_dai, 1);
398}
399
400static int ad193x_spi_remove(struct spi_device *spi)
401{
402 snd_soc_unregister_codec(&spi->dev);
403 return 0;
404}
405
406static struct spi_driver ad193x_spi_driver = {
407 .driver = {
408 .name = "ad193x",
409 .owner = THIS_MODULE,
410 },
411 .probe = ad193x_spi_probe,
412 .remove = ad193x_spi_remove,
413};
414#endif
415
416#if IS_ENABLED(CONFIG_I2C)
417
418static const struct regmap_config ad193x_i2c_regmap_config = {
419 .val_bits = 8,
420 .reg_bits = 8,
421
422 .max_register = AD193X_NUM_REGS - 1,
423 .volatile_reg = adau193x_reg_volatile,
424};
425
426static const struct i2c_device_id ad193x_id[] = {
427 { "ad1936", 0 },
428 { "ad1937", 0 },
429 { }
430};
431MODULE_DEVICE_TABLE(i2c, ad193x_id);
432
433static int ad193x_i2c_probe(struct i2c_client *client,
434 const struct i2c_device_id *id)
435{
436 struct ad193x_priv *ad193x;
437 372
438 ad193x = devm_kzalloc(&client->dev, sizeof(struct ad193x_priv), 373 ad193x = devm_kzalloc(dev, sizeof(*ad193x), GFP_KERNEL);
439 GFP_KERNEL);
440 if (ad193x == NULL) 374 if (ad193x == NULL)
441 return -ENOMEM; 375 return -ENOMEM;
442 376
443 ad193x->regmap = devm_regmap_init_i2c(client, &ad193x_i2c_regmap_config); 377 ad193x->regmap = regmap;
444 if (IS_ERR(ad193x->regmap))
445 return PTR_ERR(ad193x->regmap);
446
447 i2c_set_clientdata(client, ad193x);
448
449 return snd_soc_register_codec(&client->dev, &soc_codec_dev_ad193x,
450 &ad193x_dai, 1);
451}
452
453static int ad193x_i2c_remove(struct i2c_client *client)
454{
455 snd_soc_unregister_codec(&client->dev);
456 return 0;
457}
458
459static struct i2c_driver ad193x_i2c_driver = {
460 .driver = {
461 .name = "ad193x",
462 },
463 .probe = ad193x_i2c_probe,
464 .remove = ad193x_i2c_remove,
465 .id_table = ad193x_id,
466};
467#endif
468
469static int __init ad193x_modinit(void)
470{
471 int ret;
472
473#if IS_ENABLED(CONFIG_I2C)
474 ret = i2c_add_driver(&ad193x_i2c_driver);
475 if (ret != 0) {
476 printk(KERN_ERR "Failed to register AD193X I2C driver: %d\n",
477 ret);
478 }
479#endif
480
481#if defined(CONFIG_SPI_MASTER)
482 ret = spi_register_driver(&ad193x_spi_driver);
483 if (ret != 0) {
484 printk(KERN_ERR "Failed to register AD193X SPI driver: %d\n",
485 ret);
486 }
487#endif
488 return ret;
489}
490module_init(ad193x_modinit);
491 378
492static void __exit ad193x_modexit(void) 379 dev_set_drvdata(dev, ad193x);
493{
494#if defined(CONFIG_SPI_MASTER)
495 spi_unregister_driver(&ad193x_spi_driver);
496#endif
497 380
498#if IS_ENABLED(CONFIG_I2C) 381 return snd_soc_register_codec(dev, &soc_codec_dev_ad193x,
499 i2c_del_driver(&ad193x_i2c_driver); 382 &ad193x_dai, 1);
500#endif
501} 383}
502module_exit(ad193x_modexit); 384EXPORT_SYMBOL_GPL(ad193x_probe);
503 385
504MODULE_DESCRIPTION("ASoC ad193x driver"); 386MODULE_DESCRIPTION("ASoC ad193x driver");
505MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 387MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
diff --git a/sound/soc/codecs/ad193x.h b/sound/soc/codecs/ad193x.h
index 473388049992..ab9a998f15be 100644
--- a/sound/soc/codecs/ad193x.h
+++ b/sound/soc/codecs/ad193x.h
@@ -9,6 +9,13 @@
9#ifndef __AD193X_H__ 9#ifndef __AD193X_H__
10#define __AD193X_H__ 10#define __AD193X_H__
11 11
12#include <linux/regmap.h>
13
14struct device;
15
16extern const struct regmap_config ad193x_regmap_config;
17int ad193x_probe(struct device *dev, struct regmap *regmap);
18
12#define AD193X_PLL_CLK_CTRL0 0x00 19#define AD193X_PLL_CLK_CTRL0 0x00
13#define AD193X_PLL_POWERDOWN 0x01 20#define AD193X_PLL_POWERDOWN 0x01
14#define AD193X_PLL_INPUT_MASK 0x6 21#define AD193X_PLL_INPUT_MASK 0x6
diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c
index eb836ed5271f..877f5737bb6b 100644
--- a/sound/soc/codecs/adau1373.c
+++ b/sound/soc/codecs/adau1373.c
@@ -345,15 +345,15 @@ static const char *adau1373_fdsp_sel_text[] = {
345 "Channel 5", 345 "Channel 5",
346}; 346};
347 347
348static const SOC_ENUM_SINGLE_DECL(adau1373_drc1_channel_enum, 348static SOC_ENUM_SINGLE_DECL(adau1373_drc1_channel_enum,
349 ADAU1373_FDSP_SEL1, 4, adau1373_fdsp_sel_text); 349 ADAU1373_FDSP_SEL1, 4, adau1373_fdsp_sel_text);
350static const SOC_ENUM_SINGLE_DECL(adau1373_drc2_channel_enum, 350static SOC_ENUM_SINGLE_DECL(adau1373_drc2_channel_enum,
351 ADAU1373_FDSP_SEL1, 0, adau1373_fdsp_sel_text); 351 ADAU1373_FDSP_SEL1, 0, adau1373_fdsp_sel_text);
352static const SOC_ENUM_SINGLE_DECL(adau1373_drc3_channel_enum, 352static SOC_ENUM_SINGLE_DECL(adau1373_drc3_channel_enum,
353 ADAU1373_FDSP_SEL2, 0, adau1373_fdsp_sel_text); 353 ADAU1373_FDSP_SEL2, 0, adau1373_fdsp_sel_text);
354static const SOC_ENUM_SINGLE_DECL(adau1373_hpf_channel_enum, 354static SOC_ENUM_SINGLE_DECL(adau1373_hpf_channel_enum,
355 ADAU1373_FDSP_SEL3, 0, adau1373_fdsp_sel_text); 355 ADAU1373_FDSP_SEL3, 0, adau1373_fdsp_sel_text);
356static const SOC_ENUM_SINGLE_DECL(adau1373_bass_channel_enum, 356static SOC_ENUM_SINGLE_DECL(adau1373_bass_channel_enum,
357 ADAU1373_FDSP_SEL4, 4, adau1373_fdsp_sel_text); 357 ADAU1373_FDSP_SEL4, 4, adau1373_fdsp_sel_text);
358 358
359static const char *adau1373_hpf_cutoff_text[] = { 359static const char *adau1373_hpf_cutoff_text[] = {
@@ -362,7 +362,7 @@ static const char *adau1373_hpf_cutoff_text[] = {
362 "800Hz", 362 "800Hz",
363}; 363};
364 364
365static const SOC_ENUM_SINGLE_DECL(adau1373_hpf_cutoff_enum, 365static SOC_ENUM_SINGLE_DECL(adau1373_hpf_cutoff_enum,
366 ADAU1373_HPF_CTRL, 3, adau1373_hpf_cutoff_text); 366 ADAU1373_HPF_CTRL, 3, adau1373_hpf_cutoff_text);
367 367
368static const char *adau1373_bass_lpf_cutoff_text[] = { 368static const char *adau1373_bass_lpf_cutoff_text[] = {
@@ -388,14 +388,14 @@ static const unsigned int adau1373_bass_tlv[] = {
388 5, 7, TLV_DB_SCALE_ITEM(1400, 150, 0), 388 5, 7, TLV_DB_SCALE_ITEM(1400, 150, 0),
389}; 389};
390 390
391static const SOC_ENUM_SINGLE_DECL(adau1373_bass_lpf_cutoff_enum, 391static SOC_ENUM_SINGLE_DECL(adau1373_bass_lpf_cutoff_enum,
392 ADAU1373_BASS1, 5, adau1373_bass_lpf_cutoff_text); 392 ADAU1373_BASS1, 5, adau1373_bass_lpf_cutoff_text);
393 393
394static const SOC_VALUE_ENUM_SINGLE_DECL(adau1373_bass_clip_level_enum, 394static SOC_VALUE_ENUM_SINGLE_DECL(adau1373_bass_clip_level_enum,
395 ADAU1373_BASS1, 2, 7, adau1373_bass_clip_level_text, 395 ADAU1373_BASS1, 2, 7, adau1373_bass_clip_level_text,
396 adau1373_bass_clip_level_values); 396 adau1373_bass_clip_level_values);
397 397
398static const SOC_ENUM_SINGLE_DECL(adau1373_bass_hpf_cutoff_enum, 398static SOC_ENUM_SINGLE_DECL(adau1373_bass_hpf_cutoff_enum,
399 ADAU1373_BASS1, 0, adau1373_bass_hpf_cutoff_text); 399 ADAU1373_BASS1, 0, adau1373_bass_hpf_cutoff_text);
400 400
401static const char *adau1373_3d_level_text[] = { 401static const char *adau1373_3d_level_text[] = {
@@ -409,9 +409,9 @@ static const char *adau1373_3d_cutoff_text[] = {
409 "0.16875 fs", "0.27083 fs" 409 "0.16875 fs", "0.27083 fs"
410}; 410};
411 411
412static const SOC_ENUM_SINGLE_DECL(adau1373_3d_level_enum, 412static SOC_ENUM_SINGLE_DECL(adau1373_3d_level_enum,
413 ADAU1373_3D_CTRL1, 4, adau1373_3d_level_text); 413 ADAU1373_3D_CTRL1, 4, adau1373_3d_level_text);
414static const SOC_ENUM_SINGLE_DECL(adau1373_3d_cutoff_enum, 414static SOC_ENUM_SINGLE_DECL(adau1373_3d_cutoff_enum,
415 ADAU1373_3D_CTRL1, 0, adau1373_3d_cutoff_text); 415 ADAU1373_3D_CTRL1, 0, adau1373_3d_cutoff_text);
416 416
417static const unsigned int adau1373_3d_tlv[] = { 417static const unsigned int adau1373_3d_tlv[] = {
@@ -427,11 +427,11 @@ static const char *adau1373_lr_mux_text[] = {
427 "Stereo", 427 "Stereo",
428}; 428};
429 429
430static const SOC_ENUM_SINGLE_DECL(adau1373_lineout1_lr_mux_enum, 430static SOC_ENUM_SINGLE_DECL(adau1373_lineout1_lr_mux_enum,
431 ADAU1373_OUTPUT_CTRL, 4, adau1373_lr_mux_text); 431 ADAU1373_OUTPUT_CTRL, 4, adau1373_lr_mux_text);
432static const SOC_ENUM_SINGLE_DECL(adau1373_lineout2_lr_mux_enum, 432static SOC_ENUM_SINGLE_DECL(adau1373_lineout2_lr_mux_enum,
433 ADAU1373_OUTPUT_CTRL, 6, adau1373_lr_mux_text); 433 ADAU1373_OUTPUT_CTRL, 6, adau1373_lr_mux_text);
434static const SOC_ENUM_SINGLE_DECL(adau1373_speaker_lr_mux_enum, 434static SOC_ENUM_SINGLE_DECL(adau1373_speaker_lr_mux_enum,
435 ADAU1373_LS_CTRL, 4, adau1373_lr_mux_text); 435 ADAU1373_LS_CTRL, 4, adau1373_lr_mux_text);
436 436
437static const struct snd_kcontrol_new adau1373_controls[] = { 437static const struct snd_kcontrol_new adau1373_controls[] = {
@@ -576,8 +576,8 @@ static const char *adau1373_decimator_text[] = {
576 "DMIC1", 576 "DMIC1",
577}; 577};
578 578
579static const struct soc_enum adau1373_decimator_enum = 579static SOC_ENUM_SINGLE_VIRT_DECL(adau1373_decimator_enum,
580 SOC_ENUM_SINGLE(0, 0, 2, adau1373_decimator_text); 580 adau1373_decimator_text);
581 581
582static const struct snd_kcontrol_new adau1373_decimator_mux = 582static const struct snd_kcontrol_new adau1373_decimator_mux =
583 SOC_DAPM_ENUM_VIRT("Decimator Mux", adau1373_decimator_enum); 583 SOC_DAPM_ENUM_VIRT("Decimator Mux", adau1373_decimator_enum);
@@ -1376,15 +1376,8 @@ static int adau1373_probe(struct snd_soc_codec *codec)
1376 struct adau1373_platform_data *pdata = codec->dev->platform_data; 1376 struct adau1373_platform_data *pdata = codec->dev->platform_data;
1377 bool lineout_differential = false; 1377 bool lineout_differential = false;
1378 unsigned int val; 1378 unsigned int val;
1379 int ret;
1380 int i; 1379 int i;
1381 1380
1382 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
1383 if (ret) {
1384 dev_err(codec->dev, "failed to set cache I/O: %d\n", ret);
1385 return ret;
1386 }
1387
1388 if (pdata) { 1381 if (pdata) {
1389 if (pdata->num_drc > ARRAY_SIZE(pdata->drc_setting)) 1382 if (pdata->num_drc > ARRAY_SIZE(pdata->drc_setting))
1390 return -EINVAL; 1383 return -EINVAL;
diff --git a/sound/soc/codecs/adau1977-i2c.c b/sound/soc/codecs/adau1977-i2c.c
new file mode 100644
index 000000000000..9700e8c838c9
--- /dev/null
+++ b/sound/soc/codecs/adau1977-i2c.c
@@ -0,0 +1,59 @@
1/*
2 * ADAU1977/ADAU1978/ADAU1979 driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
6 *
7 * Licensed under the GPL-2.
8 */
9
10#include <linux/i2c.h>
11#include <linux/mod_devicetable.h>
12#include <linux/module.h>
13#include <linux/regmap.h>
14#include <sound/soc.h>
15
16#include "adau1977.h"
17
18static int adau1977_i2c_probe(struct i2c_client *client,
19 const struct i2c_device_id *id)
20{
21 struct regmap_config config;
22
23 config = adau1977_regmap_config;
24 config.val_bits = 8;
25 config.reg_bits = 8;
26
27 return adau1977_probe(&client->dev,
28 devm_regmap_init_i2c(client, &config),
29 id->driver_data, NULL);
30}
31
32static int adau1977_i2c_remove(struct i2c_client *client)
33{
34 snd_soc_unregister_codec(&client->dev);
35 return 0;
36}
37
38static const struct i2c_device_id adau1977_i2c_ids[] = {
39 { "adau1977", ADAU1977 },
40 { "adau1978", ADAU1978 },
41 { "adau1979", ADAU1978 },
42 { }
43};
44MODULE_DEVICE_TABLE(i2c, adau1977_i2c_ids);
45
46static struct i2c_driver adau1977_i2c_driver = {
47 .driver = {
48 .name = "adau1977",
49 .owner = THIS_MODULE,
50 },
51 .probe = adau1977_i2c_probe,
52 .remove = adau1977_i2c_remove,
53 .id_table = adau1977_i2c_ids,
54};
55module_i2c_driver(adau1977_i2c_driver);
56
57MODULE_DESCRIPTION("ASoC ADAU1977/ADAU1978/ADAU1979 driver");
58MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
59MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/adau1977-spi.c b/sound/soc/codecs/adau1977-spi.c
new file mode 100644
index 000000000000..b05cf5da3a94
--- /dev/null
+++ b/sound/soc/codecs/adau1977-spi.c
@@ -0,0 +1,76 @@
1/*
2 * ADAU1977/ADAU1978/ADAU1979 driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
6 *
7 * Licensed under the GPL-2.
8 */
9
10#include <linux/mod_devicetable.h>
11#include <linux/module.h>
12#include <linux/regmap.h>
13#include <linux/spi/spi.h>
14#include <sound/soc.h>
15
16#include "adau1977.h"
17
18static void adau1977_spi_switch_mode(struct device *dev)
19{
20 struct spi_device *spi = to_spi_device(dev);
21
22 /*
23 * To get the device into SPI mode CLATCH has to be pulled low three
24 * times. Do this by issuing three dummy reads.
25 */
26 spi_w8r8(spi, 0x00);
27 spi_w8r8(spi, 0x00);
28 spi_w8r8(spi, 0x00);
29}
30
31static int adau1977_spi_probe(struct spi_device *spi)
32{
33 const struct spi_device_id *id = spi_get_device_id(spi);
34 struct regmap_config config;
35
36 if (!id)
37 return -EINVAL;
38
39 config = adau1977_regmap_config;
40 config.val_bits = 8;
41 config.reg_bits = 16;
42 config.read_flag_mask = 0x1;
43
44 return adau1977_probe(&spi->dev,
45 devm_regmap_init_spi(spi, &config),
46 id->driver_data, adau1977_spi_switch_mode);
47}
48
49static int adau1977_spi_remove(struct spi_device *spi)
50{
51 snd_soc_unregister_codec(&spi->dev);
52 return 0;
53}
54
55static const struct spi_device_id adau1977_spi_ids[] = {
56 { "adau1977", ADAU1977 },
57 { "adau1978", ADAU1978 },
58 { "adau1979", ADAU1978 },
59 { }
60};
61MODULE_DEVICE_TABLE(spi, adau1977_spi_ids);
62
63static struct spi_driver adau1977_spi_driver = {
64 .driver = {
65 .name = "adau1977",
66 .owner = THIS_MODULE,
67 },
68 .probe = adau1977_spi_probe,
69 .remove = adau1977_spi_remove,
70 .id_table = adau1977_spi_ids,
71};
72module_spi_driver(adau1977_spi_driver);
73
74MODULE_DESCRIPTION("ASoC ADAU1977/ADAU1978/ADAU1979 driver");
75MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
76MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/adau1977.c b/sound/soc/codecs/adau1977.c
new file mode 100644
index 000000000000..fd55da7cb9d4
--- /dev/null
+++ b/sound/soc/codecs/adau1977.c
@@ -0,0 +1,1018 @@
1/*
2 * ADAU1977/ADAU1978/ADAU1979 driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
6 *
7 * Licensed under the GPL-2.
8 */
9
10#include <linux/delay.h>
11#include <linux/device.h>
12#include <linux/gpio/consumer.h>
13#include <linux/i2c.h>
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/platform_data/adau1977.h>
17#include <linux/regmap.h>
18#include <linux/regulator/consumer.h>
19#include <linux/slab.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/soc.h>
26#include <sound/tlv.h>
27
28#include "adau1977.h"
29
30#define ADAU1977_REG_POWER 0x00
31#define ADAU1977_REG_PLL 0x01
32#define ADAU1977_REG_BOOST 0x02
33#define ADAU1977_REG_MICBIAS 0x03
34#define ADAU1977_REG_BLOCK_POWER_SAI 0x04
35#define ADAU1977_REG_SAI_CTRL0 0x05
36#define ADAU1977_REG_SAI_CTRL1 0x06
37#define ADAU1977_REG_CMAP12 0x07
38#define ADAU1977_REG_CMAP34 0x08
39#define ADAU1977_REG_SAI_OVERTEMP 0x09
40#define ADAU1977_REG_POST_ADC_GAIN(x) (0x0a + (x))
41#define ADAU1977_REG_MISC_CONTROL 0x0e
42#define ADAU1977_REG_DIAG_CONTROL 0x10
43#define ADAU1977_REG_STATUS(x) (0x11 + (x))
44#define ADAU1977_REG_DIAG_IRQ1 0x15
45#define ADAU1977_REG_DIAG_IRQ2 0x16
46#define ADAU1977_REG_ADJUST1 0x17
47#define ADAU1977_REG_ADJUST2 0x18
48#define ADAU1977_REG_ADC_CLIP 0x19
49#define ADAU1977_REG_DC_HPF_CAL 0x1a
50
51#define ADAU1977_POWER_RESET BIT(7)
52#define ADAU1977_POWER_PWUP BIT(0)
53
54#define ADAU1977_PLL_CLK_S BIT(4)
55#define ADAU1977_PLL_MCS_MASK 0x7
56
57#define ADAU1977_MICBIAS_MB_VOLTS_MASK 0xf0
58#define ADAU1977_MICBIAS_MB_VOLTS_OFFSET 4
59
60#define ADAU1977_BLOCK_POWER_SAI_LR_POL BIT(7)
61#define ADAU1977_BLOCK_POWER_SAI_BCLK_EDGE BIT(6)
62#define ADAU1977_BLOCK_POWER_SAI_LDO_EN BIT(5)
63
64#define ADAU1977_SAI_CTRL0_FMT_MASK (0x3 << 6)
65#define ADAU1977_SAI_CTRL0_FMT_I2S (0x0 << 6)
66#define ADAU1977_SAI_CTRL0_FMT_LJ (0x1 << 6)
67#define ADAU1977_SAI_CTRL0_FMT_RJ_24BIT (0x2 << 6)
68#define ADAU1977_SAI_CTRL0_FMT_RJ_16BIT (0x3 << 6)
69
70#define ADAU1977_SAI_CTRL0_SAI_MASK (0x7 << 3)
71#define ADAU1977_SAI_CTRL0_SAI_I2S (0x0 << 3)
72#define ADAU1977_SAI_CTRL0_SAI_TDM_2 (0x1 << 3)
73#define ADAU1977_SAI_CTRL0_SAI_TDM_4 (0x2 << 3)
74#define ADAU1977_SAI_CTRL0_SAI_TDM_8 (0x3 << 3)
75#define ADAU1977_SAI_CTRL0_SAI_TDM_16 (0x4 << 3)
76
77#define ADAU1977_SAI_CTRL0_FS_MASK (0x7)
78#define ADAU1977_SAI_CTRL0_FS_8000_12000 (0x0)
79#define ADAU1977_SAI_CTRL0_FS_16000_24000 (0x1)
80#define ADAU1977_SAI_CTRL0_FS_32000_48000 (0x2)
81#define ADAU1977_SAI_CTRL0_FS_64000_96000 (0x3)
82#define ADAU1977_SAI_CTRL0_FS_128000_192000 (0x4)
83
84#define ADAU1977_SAI_CTRL1_SLOT_WIDTH_MASK (0x3 << 5)
85#define ADAU1977_SAI_CTRL1_SLOT_WIDTH_32 (0x0 << 5)
86#define ADAU1977_SAI_CTRL1_SLOT_WIDTH_24 (0x1 << 5)
87#define ADAU1977_SAI_CTRL1_SLOT_WIDTH_16 (0x2 << 5)
88#define ADAU1977_SAI_CTRL1_DATA_WIDTH_MASK (0x1 << 4)
89#define ADAU1977_SAI_CTRL1_DATA_WIDTH_16BIT (0x1 << 4)
90#define ADAU1977_SAI_CTRL1_DATA_WIDTH_24BIT (0x0 << 4)
91#define ADAU1977_SAI_CTRL1_LRCLK_PULSE BIT(3)
92#define ADAU1977_SAI_CTRL1_MSB BIT(2)
93#define ADAU1977_SAI_CTRL1_BCLKRATE_16 (0x1 << 1)
94#define ADAU1977_SAI_CTRL1_BCLKRATE_32 (0x0 << 1)
95#define ADAU1977_SAI_CTRL1_BCLKRATE_MASK (0x1 << 1)
96#define ADAU1977_SAI_CTRL1_MASTER BIT(0)
97
98#define ADAU1977_SAI_OVERTEMP_DRV_C(x) BIT(4 + (x))
99#define ADAU1977_SAI_OVERTEMP_DRV_HIZ BIT(3)
100
101#define ADAU1977_MISC_CONTROL_SUM_MODE_MASK (0x3 << 6)
102#define ADAU1977_MISC_CONTROL_SUM_MODE_1CH (0x2 << 6)
103#define ADAU1977_MISC_CONTROL_SUM_MODE_2CH (0x1 << 6)
104#define ADAU1977_MISC_CONTROL_SUM_MODE_4CH (0x0 << 6)
105#define ADAU1977_MISC_CONTROL_MMUTE BIT(4)
106#define ADAU1977_MISC_CONTROL_DC_CAL BIT(0)
107
108#define ADAU1977_CHAN_MAP_SECOND_SLOT_OFFSET 4
109#define ADAU1977_CHAN_MAP_FIRST_SLOT_OFFSET 0
110
111struct adau1977 {
112 struct regmap *regmap;
113 bool right_j;
114 unsigned int sysclk;
115 enum adau1977_sysclk_src sysclk_src;
116 struct gpio_desc *reset_gpio;
117 enum adau1977_type type;
118
119 struct regulator *avdd_reg;
120 struct regulator *dvdd_reg;
121
122 struct snd_pcm_hw_constraint_list constraints;
123
124 struct device *dev;
125 void (*switch_mode)(struct device *dev);
126
127 unsigned int max_master_fs;
128 unsigned int slot_width;
129 bool enabled;
130 bool master;
131};
132
133static const struct reg_default adau1977_reg_defaults[] = {
134 { 0x00, 0x00 },
135 { 0x01, 0x41 },
136 { 0x02, 0x4a },
137 { 0x03, 0x7d },
138 { 0x04, 0x3d },
139 { 0x05, 0x02 },
140 { 0x06, 0x00 },
141 { 0x07, 0x10 },
142 { 0x08, 0x32 },
143 { 0x09, 0xf0 },
144 { 0x0a, 0xa0 },
145 { 0x0b, 0xa0 },
146 { 0x0c, 0xa0 },
147 { 0x0d, 0xa0 },
148 { 0x0e, 0x02 },
149 { 0x10, 0x0f },
150 { 0x15, 0x20 },
151 { 0x16, 0x00 },
152 { 0x17, 0x00 },
153 { 0x18, 0x00 },
154 { 0x1a, 0x00 },
155};
156
157static const DECLARE_TLV_DB_MINMAX_MUTE(adau1977_adc_gain, -3562, 6000);
158
159static const struct snd_soc_dapm_widget adau1977_micbias_dapm_widgets[] = {
160 SND_SOC_DAPM_SUPPLY("MICBIAS", ADAU1977_REG_MICBIAS,
161 3, 0, NULL, 0)
162};
163
164static const struct snd_soc_dapm_widget adau1977_dapm_widgets[] = {
165 SND_SOC_DAPM_SUPPLY("Vref", ADAU1977_REG_BLOCK_POWER_SAI,
166 4, 0, NULL, 0),
167
168 SND_SOC_DAPM_ADC("ADC1", "Capture", ADAU1977_REG_BLOCK_POWER_SAI, 0, 0),
169 SND_SOC_DAPM_ADC("ADC2", "Capture", ADAU1977_REG_BLOCK_POWER_SAI, 1, 0),
170 SND_SOC_DAPM_ADC("ADC3", "Capture", ADAU1977_REG_BLOCK_POWER_SAI, 2, 0),
171 SND_SOC_DAPM_ADC("ADC4", "Capture", ADAU1977_REG_BLOCK_POWER_SAI, 3, 0),
172
173 SND_SOC_DAPM_INPUT("AIN1"),
174 SND_SOC_DAPM_INPUT("AIN2"),
175 SND_SOC_DAPM_INPUT("AIN3"),
176 SND_SOC_DAPM_INPUT("AIN4"),
177
178 SND_SOC_DAPM_OUTPUT("VREF"),
179};
180
181static const struct snd_soc_dapm_route adau1977_dapm_routes[] = {
182 { "ADC1", NULL, "AIN1" },
183 { "ADC2", NULL, "AIN2" },
184 { "ADC3", NULL, "AIN3" },
185 { "ADC4", NULL, "AIN4" },
186
187 { "ADC1", NULL, "Vref" },
188 { "ADC2", NULL, "Vref" },
189 { "ADC3", NULL, "Vref" },
190 { "ADC4", NULL, "Vref" },
191
192 { "VREF", NULL, "Vref" },
193};
194
195#define ADAU1977_VOLUME(x) \
196 SOC_SINGLE_TLV("ADC" #x " Capture Volume", \
197 ADAU1977_REG_POST_ADC_GAIN((x) - 1), \
198 0, 255, 1, adau1977_adc_gain)
199
200#define ADAU1977_HPF_SWITCH(x) \
201 SOC_SINGLE("ADC" #x " Highpass-Filter Capture Switch", \
202 ADAU1977_REG_DC_HPF_CAL, (x) - 1, 1, 0)
203
204#define ADAU1977_DC_SUB_SWITCH(x) \
205 SOC_SINGLE("ADC" #x " DC Substraction Capture Switch", \
206 ADAU1977_REG_DC_HPF_CAL, (x) + 3, 1, 0)
207
208static const struct snd_kcontrol_new adau1977_snd_controls[] = {
209 ADAU1977_VOLUME(1),
210 ADAU1977_VOLUME(2),
211 ADAU1977_VOLUME(3),
212 ADAU1977_VOLUME(4),
213
214 ADAU1977_HPF_SWITCH(1),
215 ADAU1977_HPF_SWITCH(2),
216 ADAU1977_HPF_SWITCH(3),
217 ADAU1977_HPF_SWITCH(4),
218
219 ADAU1977_DC_SUB_SWITCH(1),
220 ADAU1977_DC_SUB_SWITCH(2),
221 ADAU1977_DC_SUB_SWITCH(3),
222 ADAU1977_DC_SUB_SWITCH(4),
223};
224
225static int adau1977_reset(struct adau1977 *adau1977)
226{
227 int ret;
228
229 /*
230 * The reset bit is obviously volatile, but we need to be able to cache
231 * the other bits in the register, so we can't just mark the whole
232 * register as volatile. Since this is the only place where we'll ever
233 * touch the reset bit just bypass the cache for this operation.
234 */
235 regcache_cache_bypass(adau1977->regmap, true);
236 ret = regmap_write(adau1977->regmap, ADAU1977_REG_POWER,
237 ADAU1977_POWER_RESET);
238 regcache_cache_bypass(adau1977->regmap, false);
239 if (ret)
240 return ret;
241
242 return ret;
243}
244
245/*
246 * Returns the appropriate setting for ths FS field in the CTRL0 register
247 * depending on the rate.
248 */
249static int adau1977_lookup_fs(unsigned int rate)
250{
251 if (rate >= 8000 && rate <= 12000)
252 return ADAU1977_SAI_CTRL0_FS_8000_12000;
253 else if (rate >= 16000 && rate <= 24000)
254 return ADAU1977_SAI_CTRL0_FS_16000_24000;
255 else if (rate >= 32000 && rate <= 48000)
256 return ADAU1977_SAI_CTRL0_FS_32000_48000;
257 else if (rate >= 64000 && rate <= 96000)
258 return ADAU1977_SAI_CTRL0_FS_64000_96000;
259 else if (rate >= 128000 && rate <= 192000)
260 return ADAU1977_SAI_CTRL0_FS_128000_192000;
261 else
262 return -EINVAL;
263}
264
265static int adau1977_lookup_mcs(struct adau1977 *adau1977, unsigned int rate,
266 unsigned int fs)
267{
268 unsigned int mcs;
269
270 /*
271 * rate = sysclk / (512 * mcs_lut[mcs]) * 2**fs
272 * => mcs_lut[mcs] = sysclk / (512 * rate) * 2**fs
273 * => mcs_lut[mcs] = sysclk / ((512 / 2**fs) * rate)
274 */
275
276 rate *= 512 >> fs;
277
278 if (adau1977->sysclk % rate != 0)
279 return -EINVAL;
280
281 mcs = adau1977->sysclk / rate;
282
283 /* The factors configured by MCS are 1, 2, 3, 4, 6 */
284 if (mcs < 1 || mcs > 6 || mcs == 5)
285 return -EINVAL;
286
287 mcs = mcs - 1;
288 if (mcs == 5)
289 mcs = 4;
290
291 return mcs;
292}
293
294static int adau1977_hw_params(struct snd_pcm_substream *substream,
295 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
296{
297 struct snd_soc_codec *codec = dai->codec;
298 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(codec);
299 unsigned int rate = params_rate(params);
300 unsigned int slot_width;
301 unsigned int ctrl0, ctrl0_mask;
302 unsigned int ctrl1;
303 int mcs, fs;
304 int ret;
305
306 fs = adau1977_lookup_fs(rate);
307 if (fs < 0)
308 return fs;
309
310 if (adau1977->sysclk_src == ADAU1977_SYSCLK_SRC_MCLK) {
311 mcs = adau1977_lookup_mcs(adau1977, rate, fs);
312 if (mcs < 0)
313 return mcs;
314 } else {
315 mcs = 0;
316 }
317
318 ctrl0_mask = ADAU1977_SAI_CTRL0_FS_MASK;
319 ctrl0 = fs;
320
321 if (adau1977->right_j) {
322 switch (params_width(params)) {
323 case 16:
324 ctrl0 |= ADAU1977_SAI_CTRL0_FMT_RJ_16BIT;
325 break;
326 case 24:
327 ctrl0 |= ADAU1977_SAI_CTRL0_FMT_RJ_24BIT;
328 break;
329 default:
330 return -EINVAL;
331 }
332 ctrl0_mask |= ADAU1977_SAI_CTRL0_FMT_MASK;
333 }
334
335 if (adau1977->master) {
336 switch (params_width(params)) {
337 case 16:
338 ctrl1 = ADAU1977_SAI_CTRL1_DATA_WIDTH_16BIT;
339 slot_width = 16;
340 break;
341 case 24:
342 case 32:
343 ctrl1 = ADAU1977_SAI_CTRL1_DATA_WIDTH_24BIT;
344 slot_width = 32;
345 break;
346 default:
347 return -EINVAL;
348 }
349
350 /* In TDM mode there is a fixed slot width */
351 if (adau1977->slot_width)
352 slot_width = adau1977->slot_width;
353
354 if (slot_width == 16)
355 ctrl1 |= ADAU1977_SAI_CTRL1_BCLKRATE_16;
356 else
357 ctrl1 |= ADAU1977_SAI_CTRL1_BCLKRATE_32;
358
359 ret = regmap_update_bits(adau1977->regmap,
360 ADAU1977_REG_SAI_CTRL1,
361 ADAU1977_SAI_CTRL1_DATA_WIDTH_MASK |
362 ADAU1977_SAI_CTRL1_BCLKRATE_MASK,
363 ctrl1);
364 if (ret < 0)
365 return ret;
366 }
367
368 ret = regmap_update_bits(adau1977->regmap, ADAU1977_REG_SAI_CTRL0,
369 ctrl0_mask, ctrl0);
370 if (ret < 0)
371 return ret;
372
373 return regmap_update_bits(adau1977->regmap, ADAU1977_REG_PLL,
374 ADAU1977_PLL_MCS_MASK, mcs);
375}
376
377static int adau1977_power_disable(struct adau1977 *adau1977)
378{
379 int ret = 0;
380
381 if (!adau1977->enabled)
382 return 0;
383
384 ret = regmap_update_bits(adau1977->regmap, ADAU1977_REG_POWER,
385 ADAU1977_POWER_PWUP, 0);
386 if (ret)
387 return ret;
388
389 regcache_mark_dirty(adau1977->regmap);
390
391 if (adau1977->reset_gpio)
392 gpiod_set_value_cansleep(adau1977->reset_gpio, 0);
393
394 regcache_cache_only(adau1977->regmap, true);
395
396 regulator_disable(adau1977->avdd_reg);
397 if (adau1977->dvdd_reg)
398 regulator_disable(adau1977->dvdd_reg);
399
400 adau1977->enabled = false;
401
402 return 0;
403}
404
405static int adau1977_power_enable(struct adau1977 *adau1977)
406{
407 unsigned int val;
408 int ret = 0;
409
410 if (adau1977->enabled)
411 return 0;
412
413 ret = regulator_enable(adau1977->avdd_reg);
414 if (ret)
415 return ret;
416
417 if (adau1977->dvdd_reg) {
418 ret = regulator_enable(adau1977->dvdd_reg);
419 if (ret)
420 goto err_disable_avdd;
421 }
422
423 if (adau1977->reset_gpio)
424 gpiod_set_value_cansleep(adau1977->reset_gpio, 1);
425
426 regcache_cache_only(adau1977->regmap, false);
427
428 if (adau1977->switch_mode)
429 adau1977->switch_mode(adau1977->dev);
430
431 ret = adau1977_reset(adau1977);
432 if (ret)
433 goto err_disable_dvdd;
434
435 ret = regmap_update_bits(adau1977->regmap, ADAU1977_REG_POWER,
436 ADAU1977_POWER_PWUP, ADAU1977_POWER_PWUP);
437 if (ret)
438 goto err_disable_dvdd;
439
440 ret = regcache_sync(adau1977->regmap);
441 if (ret)
442 goto err_disable_dvdd;
443
444 /*
445 * The PLL register is not affected by the software reset. It is
446 * possible that the value of the register was changed to the
447 * default value while we were in cache only mode. In this case
448 * regcache_sync will skip over it and we have to manually sync
449 * it.
450 */
451 ret = regmap_read(adau1977->regmap, ADAU1977_REG_PLL, &val);
452 if (ret)
453 goto err_disable_dvdd;
454
455 if (val == 0x41) {
456 regcache_cache_bypass(adau1977->regmap, true);
457 ret = regmap_write(adau1977->regmap, ADAU1977_REG_PLL,
458 0x41);
459 if (ret)
460 goto err_disable_dvdd;
461 regcache_cache_bypass(adau1977->regmap, false);
462 }
463
464 adau1977->enabled = true;
465
466 return ret;
467
468err_disable_dvdd:
469 if (adau1977->dvdd_reg)
470 regulator_disable(adau1977->dvdd_reg);
471err_disable_avdd:
472 regulator_disable(adau1977->avdd_reg);
473 return ret;
474}
475
476static int adau1977_set_bias_level(struct snd_soc_codec *codec,
477 enum snd_soc_bias_level level)
478{
479 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(codec);
480 int ret = 0;
481
482 switch (level) {
483 case SND_SOC_BIAS_ON:
484 break;
485 case SND_SOC_BIAS_PREPARE:
486 break;
487 case SND_SOC_BIAS_STANDBY:
488 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
489 ret = adau1977_power_enable(adau1977);
490 break;
491 case SND_SOC_BIAS_OFF:
492 ret = adau1977_power_disable(adau1977);
493 break;
494 }
495
496 if (ret)
497 return ret;
498
499 codec->dapm.bias_level = level;
500
501 return 0;
502}
503
504static int adau1977_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
505 unsigned int rx_mask, int slots, int width)
506{
507 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(dai->codec);
508 unsigned int ctrl0, ctrl1, drv;
509 unsigned int slot[4];
510 unsigned int i;
511 int ret;
512
513 if (slots == 0) {
514 /* 0 = No fixed slot width */
515 adau1977->slot_width = 0;
516 adau1977->max_master_fs = 192000;
517 return regmap_update_bits(adau1977->regmap,
518 ADAU1977_REG_SAI_CTRL0, ADAU1977_SAI_CTRL0_SAI_MASK,
519 ADAU1977_SAI_CTRL0_SAI_I2S);
520 }
521
522 if (rx_mask == 0 || tx_mask != 0)
523 return -EINVAL;
524
525 drv = 0;
526 for (i = 0; i < 4; i++) {
527 slot[i] = __ffs(rx_mask);
528 drv |= ADAU1977_SAI_OVERTEMP_DRV_C(i);
529 rx_mask &= ~(1 << slot[i]);
530 if (slot[i] >= slots)
531 return -EINVAL;
532 if (rx_mask == 0)
533 break;
534 }
535
536 if (rx_mask != 0)
537 return -EINVAL;
538
539 switch (width) {
540 case 16:
541 ctrl1 = ADAU1977_SAI_CTRL1_SLOT_WIDTH_16;
542 break;
543 case 24:
544 /* We can only generate 16 bit or 32 bit wide slots */
545 if (adau1977->master)
546 return -EINVAL;
547 ctrl1 = ADAU1977_SAI_CTRL1_SLOT_WIDTH_24;
548 break;
549 case 32:
550 ctrl1 = ADAU1977_SAI_CTRL1_SLOT_WIDTH_32;
551 break;
552 default:
553 return -EINVAL;
554 }
555
556 switch (slots) {
557 case 2:
558 ctrl0 = ADAU1977_SAI_CTRL0_SAI_TDM_2;
559 break;
560 case 4:
561 ctrl0 = ADAU1977_SAI_CTRL0_SAI_TDM_4;
562 break;
563 case 8:
564 ctrl0 = ADAU1977_SAI_CTRL0_SAI_TDM_8;
565 break;
566 case 16:
567 ctrl0 = ADAU1977_SAI_CTRL0_SAI_TDM_16;
568 break;
569 default:
570 return -EINVAL;
571 }
572
573 ret = regmap_update_bits(adau1977->regmap, ADAU1977_REG_SAI_OVERTEMP,
574 ADAU1977_SAI_OVERTEMP_DRV_C(0) |
575 ADAU1977_SAI_OVERTEMP_DRV_C(1) |
576 ADAU1977_SAI_OVERTEMP_DRV_C(2) |
577 ADAU1977_SAI_OVERTEMP_DRV_C(3), drv);
578 if (ret)
579 return ret;
580
581 ret = regmap_write(adau1977->regmap, ADAU1977_REG_CMAP12,
582 (slot[1] << ADAU1977_CHAN_MAP_SECOND_SLOT_OFFSET) |
583 (slot[0] << ADAU1977_CHAN_MAP_FIRST_SLOT_OFFSET));
584 if (ret)
585 return ret;
586
587 ret = regmap_write(adau1977->regmap, ADAU1977_REG_CMAP34,
588 (slot[3] << ADAU1977_CHAN_MAP_SECOND_SLOT_OFFSET) |
589 (slot[2] << ADAU1977_CHAN_MAP_FIRST_SLOT_OFFSET));
590 if (ret)
591 return ret;
592
593 ret = regmap_update_bits(adau1977->regmap, ADAU1977_REG_SAI_CTRL0,
594 ADAU1977_SAI_CTRL0_SAI_MASK, ctrl0);
595 if (ret)
596 return ret;
597
598 ret = regmap_update_bits(adau1977->regmap, ADAU1977_REG_SAI_CTRL1,
599 ADAU1977_SAI_CTRL1_SLOT_WIDTH_MASK, ctrl1);
600 if (ret)
601 return ret;
602
603 adau1977->slot_width = width;
604
605 /* In master mode the maximum bitclock is 24.576 MHz */
606 adau1977->max_master_fs = min(192000, 24576000 / width / slots);
607
608 return 0;
609}
610
611static int adau1977_mute(struct snd_soc_dai *dai, int mute, int stream)
612{
613 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(dai->codec);
614 unsigned int val;
615
616 if (mute)
617 val = ADAU1977_MISC_CONTROL_MMUTE;
618 else
619 val = 0;
620
621 return regmap_update_bits(adau1977->regmap, ADAU1977_REG_MISC_CONTROL,
622 ADAU1977_MISC_CONTROL_MMUTE, val);
623}
624
625static int adau1977_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
626{
627 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(dai->codec);
628 unsigned int ctrl0 = 0, ctrl1 = 0, block_power = 0;
629 bool invert_lrclk;
630 int ret;
631
632 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
633 case SND_SOC_DAIFMT_CBS_CFS:
634 adau1977->master = false;
635 break;
636 case SND_SOC_DAIFMT_CBM_CFM:
637 ctrl1 |= ADAU1977_SAI_CTRL1_MASTER;
638 adau1977->master = true;
639 break;
640 default:
641 return -EINVAL;
642 }
643
644 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
645 case SND_SOC_DAIFMT_NB_NF:
646 invert_lrclk = false;
647 break;
648 case SND_SOC_DAIFMT_IB_NF:
649 block_power |= ADAU1977_BLOCK_POWER_SAI_BCLK_EDGE;
650 invert_lrclk = false;
651 break;
652 case SND_SOC_DAIFMT_NB_IF:
653 invert_lrclk = true;
654 break;
655 case SND_SOC_DAIFMT_IB_IF:
656 block_power |= ADAU1977_BLOCK_POWER_SAI_BCLK_EDGE;
657 invert_lrclk = true;
658 break;
659 default:
660 return -EINVAL;
661 }
662
663 adau1977->right_j = false;
664 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
665 case SND_SOC_DAIFMT_I2S:
666 ctrl0 |= ADAU1977_SAI_CTRL0_FMT_I2S;
667 break;
668 case SND_SOC_DAIFMT_LEFT_J:
669 ctrl0 |= ADAU1977_SAI_CTRL0_FMT_LJ;
670 invert_lrclk = !invert_lrclk;
671 break;
672 case SND_SOC_DAIFMT_RIGHT_J:
673 ctrl0 |= ADAU1977_SAI_CTRL0_FMT_RJ_24BIT;
674 adau1977->right_j = true;
675 invert_lrclk = !invert_lrclk;
676 break;
677 case SND_SOC_DAIFMT_DSP_A:
678 ctrl1 |= ADAU1977_SAI_CTRL1_LRCLK_PULSE;
679 ctrl0 |= ADAU1977_SAI_CTRL0_FMT_I2S;
680 invert_lrclk = false;
681 break;
682 case SND_SOC_DAIFMT_DSP_B:
683 ctrl1 |= ADAU1977_SAI_CTRL1_LRCLK_PULSE;
684 ctrl0 |= ADAU1977_SAI_CTRL0_FMT_LJ;
685 invert_lrclk = false;
686 break;
687 default:
688 return -EINVAL;
689 }
690
691 if (invert_lrclk)
692 block_power |= ADAU1977_BLOCK_POWER_SAI_LR_POL;
693
694 ret = regmap_update_bits(adau1977->regmap, ADAU1977_REG_BLOCK_POWER_SAI,
695 ADAU1977_BLOCK_POWER_SAI_LR_POL |
696 ADAU1977_BLOCK_POWER_SAI_BCLK_EDGE, block_power);
697 if (ret)
698 return ret;
699
700 ret = regmap_update_bits(adau1977->regmap, ADAU1977_REG_SAI_CTRL0,
701 ADAU1977_SAI_CTRL0_FMT_MASK,
702 ctrl0);
703 if (ret)
704 return ret;
705
706 return regmap_update_bits(adau1977->regmap, ADAU1977_REG_SAI_CTRL1,
707 ADAU1977_SAI_CTRL1_MASTER | ADAU1977_SAI_CTRL1_LRCLK_PULSE,
708 ctrl1);
709}
710
711static int adau1977_startup(struct snd_pcm_substream *substream,
712 struct snd_soc_dai *dai)
713{
714 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(dai->codec);
715 u64 formats = 0;
716
717 if (adau1977->slot_width == 16)
718 formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE;
719 else if (adau1977->right_j || adau1977->slot_width == 24)
720 formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
721 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE;
722
723 snd_pcm_hw_constraint_list(substream->runtime, 0,
724 SNDRV_PCM_HW_PARAM_RATE, &adau1977->constraints);
725
726 if (adau1977->master)
727 snd_pcm_hw_constraint_minmax(substream->runtime,
728 SNDRV_PCM_HW_PARAM_RATE, 8000, adau1977->max_master_fs);
729
730 if (formats != 0)
731 snd_pcm_hw_constraint_mask64(substream->runtime,
732 SNDRV_PCM_HW_PARAM_FORMAT, formats);
733
734 return 0;
735}
736
737static int adau1977_set_tristate(struct snd_soc_dai *dai, int tristate)
738{
739 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(dai->codec);
740 unsigned int val;
741
742 if (tristate)
743 val = ADAU1977_SAI_OVERTEMP_DRV_HIZ;
744 else
745 val = 0;
746
747 return regmap_update_bits(adau1977->regmap, ADAU1977_REG_SAI_OVERTEMP,
748 ADAU1977_SAI_OVERTEMP_DRV_HIZ, val);
749}
750
751static const struct snd_soc_dai_ops adau1977_dai_ops = {
752 .startup = adau1977_startup,
753 .hw_params = adau1977_hw_params,
754 .mute_stream = adau1977_mute,
755 .set_fmt = adau1977_set_dai_fmt,
756 .set_tdm_slot = adau1977_set_tdm_slot,
757 .set_tristate = adau1977_set_tristate,
758};
759
760static struct snd_soc_dai_driver adau1977_dai = {
761 .name = "adau1977-hifi",
762 .capture = {
763 .stream_name = "Capture",
764 .channels_min = 1,
765 .channels_max = 4,
766 .rates = SNDRV_PCM_RATE_KNOT,
767 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |
768 SNDRV_PCM_FMTBIT_S32_LE,
769 .sig_bits = 24,
770 },
771 .ops = &adau1977_dai_ops,
772};
773
774static const unsigned int adau1977_rates[] = {
775 8000, 16000, 32000, 64000, 128000,
776 11025, 22050, 44100, 88200, 172400,
777 12000, 24000, 48000, 96000, 192000,
778};
779
780#define ADAU1977_RATE_CONSTRAINT_MASK_32000 0x001f
781#define ADAU1977_RATE_CONSTRAINT_MASK_44100 0x03e0
782#define ADAU1977_RATE_CONSTRAINT_MASK_48000 0x7c00
783/* All rates >= 32000 */
784#define ADAU1977_RATE_CONSTRAINT_MASK_LRCLK 0x739c
785
786static bool adau1977_check_sysclk(unsigned int mclk, unsigned int base_freq)
787{
788 unsigned int mcs;
789
790 if (mclk % (base_freq * 128) != 0)
791 return false;
792
793 mcs = mclk / (128 * base_freq);
794 if (mcs < 1 || mcs > 6 || mcs == 5)
795 return false;
796
797 return true;
798}
799
800static int adau1977_set_sysclk(struct snd_soc_codec *codec,
801 int clk_id, int source, unsigned int freq, int dir)
802{
803 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(codec);
804 unsigned int mask = 0;
805 unsigned int clk_src;
806 unsigned int ret;
807
808 if (dir != SND_SOC_CLOCK_IN)
809 return -EINVAL;
810
811 if (clk_id != ADAU1977_SYSCLK)
812 return -EINVAL;
813
814 switch (source) {
815 case ADAU1977_SYSCLK_SRC_MCLK:
816 clk_src = 0;
817 break;
818 case ADAU1977_SYSCLK_SRC_LRCLK:
819 clk_src = ADAU1977_PLL_CLK_S;
820 break;
821 default:
822 return -EINVAL;
823 }
824
825 if (freq != 0 && source == ADAU1977_SYSCLK_SRC_MCLK) {
826 if (freq < 4000000 || freq > 36864000)
827 return -EINVAL;
828
829 if (adau1977_check_sysclk(freq, 32000))
830 mask |= ADAU1977_RATE_CONSTRAINT_MASK_32000;
831 if (adau1977_check_sysclk(freq, 44100))
832 mask |= ADAU1977_RATE_CONSTRAINT_MASK_44100;
833 if (adau1977_check_sysclk(freq, 48000))
834 mask |= ADAU1977_RATE_CONSTRAINT_MASK_48000;
835
836 if (mask == 0)
837 return -EINVAL;
838 } else if (source == ADAU1977_SYSCLK_SRC_LRCLK) {
839 mask = ADAU1977_RATE_CONSTRAINT_MASK_LRCLK;
840 }
841
842 ret = regmap_update_bits(adau1977->regmap, ADAU1977_REG_PLL,
843 ADAU1977_PLL_CLK_S, clk_src);
844 if (ret)
845 return ret;
846
847 adau1977->constraints.mask = mask;
848 adau1977->sysclk_src = source;
849 adau1977->sysclk = freq;
850
851 return 0;
852}
853
854static int adau1977_codec_probe(struct snd_soc_codec *codec)
855{
856 struct adau1977 *adau1977 = snd_soc_codec_get_drvdata(codec);
857 int ret;
858
859 switch (adau1977->type) {
860 case ADAU1977:
861 ret = snd_soc_dapm_new_controls(&codec->dapm,
862 adau1977_micbias_dapm_widgets,
863 ARRAY_SIZE(adau1977_micbias_dapm_widgets));
864 if (ret < 0)
865 return ret;
866 break;
867 default:
868 break;
869 }
870
871 return 0;
872}
873
874static struct snd_soc_codec_driver adau1977_codec_driver = {
875 .probe = adau1977_codec_probe,
876 .set_bias_level = adau1977_set_bias_level,
877 .set_sysclk = adau1977_set_sysclk,
878 .idle_bias_off = true,
879
880 .controls = adau1977_snd_controls,
881 .num_controls = ARRAY_SIZE(adau1977_snd_controls),
882 .dapm_widgets = adau1977_dapm_widgets,
883 .num_dapm_widgets = ARRAY_SIZE(adau1977_dapm_widgets),
884 .dapm_routes = adau1977_dapm_routes,
885 .num_dapm_routes = ARRAY_SIZE(adau1977_dapm_routes),
886};
887
888static int adau1977_setup_micbias(struct adau1977 *adau1977)
889{
890 struct adau1977_platform_data *pdata = adau1977->dev->platform_data;
891 unsigned int micbias;
892
893 if (pdata) {
894 micbias = pdata->micbias;
895 if (micbias > ADAU1977_MICBIAS_9V0)
896 return -EINVAL;
897
898 } else {
899 micbias = ADAU1977_MICBIAS_8V5;
900 }
901
902 return regmap_update_bits(adau1977->regmap, ADAU1977_REG_MICBIAS,
903 ADAU1977_MICBIAS_MB_VOLTS_MASK,
904 micbias << ADAU1977_MICBIAS_MB_VOLTS_OFFSET);
905}
906
907int adau1977_probe(struct device *dev, struct regmap *regmap,
908 enum adau1977_type type, void (*switch_mode)(struct device *dev))
909{
910 unsigned int power_off_mask;
911 struct adau1977 *adau1977;
912 int ret;
913
914 if (IS_ERR(regmap))
915 return PTR_ERR(regmap);
916
917 adau1977 = devm_kzalloc(dev, sizeof(*adau1977), GFP_KERNEL);
918 if (adau1977 == NULL)
919 return -ENOMEM;
920
921 adau1977->dev = dev;
922 adau1977->type = type;
923 adau1977->regmap = regmap;
924 adau1977->switch_mode = switch_mode;
925 adau1977->max_master_fs = 192000;
926
927 adau1977->constraints.list = adau1977_rates;
928 adau1977->constraints.count = ARRAY_SIZE(adau1977_rates);
929
930 adau1977->avdd_reg = devm_regulator_get(dev, "AVDD");
931 if (IS_ERR(adau1977->avdd_reg))
932 return PTR_ERR(adau1977->avdd_reg);
933
934 adau1977->dvdd_reg = devm_regulator_get_optional(dev, "DVDD");
935 if (IS_ERR(adau1977->dvdd_reg)) {
936 if (PTR_ERR(adau1977->dvdd_reg) != -ENODEV)
937 return PTR_ERR(adau1977->dvdd_reg);
938 adau1977->dvdd_reg = NULL;
939 }
940
941 adau1977->reset_gpio = devm_gpiod_get(dev, "reset");
942 if (IS_ERR(adau1977->reset_gpio)) {
943 ret = PTR_ERR(adau1977->reset_gpio);
944 if (ret != -ENOENT && ret != -ENOSYS)
945 return PTR_ERR(adau1977->reset_gpio);
946 adau1977->reset_gpio = NULL;
947 }
948
949 dev_set_drvdata(dev, adau1977);
950
951 if (adau1977->reset_gpio) {
952 ret = gpiod_direction_output(adau1977->reset_gpio, 0);
953 if (ret)
954 return ret;
955 ndelay(100);
956 }
957
958 ret = adau1977_power_enable(adau1977);
959 if (ret)
960 return ret;
961
962 if (type == ADAU1977) {
963 ret = adau1977_setup_micbias(adau1977);
964 if (ret)
965 goto err_poweroff;
966 }
967
968 if (adau1977->dvdd_reg)
969 power_off_mask = ~0;
970 else
971 power_off_mask = ~ADAU1977_BLOCK_POWER_SAI_LDO_EN;
972
973 ret = regmap_update_bits(adau1977->regmap, ADAU1977_REG_BLOCK_POWER_SAI,
974 power_off_mask, 0x00);
975 if (ret)
976 goto err_poweroff;
977
978 ret = adau1977_power_disable(adau1977);
979 if (ret)
980 return ret;
981
982 return snd_soc_register_codec(dev, &adau1977_codec_driver,
983 &adau1977_dai, 1);
984
985err_poweroff:
986 adau1977_power_disable(adau1977);
987 return ret;
988
989}
990EXPORT_SYMBOL_GPL(adau1977_probe);
991
992static bool adau1977_register_volatile(struct device *dev, unsigned int reg)
993{
994 switch (reg) {
995 case ADAU1977_REG_STATUS(0):
996 case ADAU1977_REG_STATUS(1):
997 case ADAU1977_REG_STATUS(2):
998 case ADAU1977_REG_STATUS(3):
999 case ADAU1977_REG_ADC_CLIP:
1000 return true;
1001 }
1002
1003 return false;
1004}
1005
1006const struct regmap_config adau1977_regmap_config = {
1007 .max_register = ADAU1977_REG_DC_HPF_CAL,
1008 .volatile_reg = adau1977_register_volatile,
1009
1010 .cache_type = REGCACHE_RBTREE,
1011 .reg_defaults = adau1977_reg_defaults,
1012 .num_reg_defaults = ARRAY_SIZE(adau1977_reg_defaults),
1013};
1014EXPORT_SYMBOL_GPL(adau1977_regmap_config);
1015
1016MODULE_DESCRIPTION("ASoC ADAU1977/ADAU1978/ADAU1979 driver");
1017MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
1018MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/adau1977.h b/sound/soc/codecs/adau1977.h
new file mode 100644
index 000000000000..95e714345a86
--- /dev/null
+++ b/sound/soc/codecs/adau1977.h
@@ -0,0 +1,37 @@
1/*
2 * ADAU1977/ADAU1978/ADAU1979 driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
6 *
7 * Licensed under the GPL-2.
8 */
9
10#ifndef __SOUND_SOC_CODECS_ADAU1977_H__
11#define __SOUND_SOC_CODECS_ADAU1977_H__
12
13#include <linux/regmap.h>
14
15struct device;
16
17enum adau1977_type {
18 ADAU1977,
19 ADAU1978,
20 ADAU1979,
21};
22
23int adau1977_probe(struct device *dev, struct regmap *regmap,
24 enum adau1977_type type, void (*switch_mode)(struct device *dev));
25
26extern const struct regmap_config adau1977_regmap_config;
27
28enum adau1977_clk_id {
29 ADAU1977_SYSCLK,
30};
31
32enum adau1977_sysclk_src {
33 ADAU1977_SYSCLK_SRC_MCLK,
34 ADAU1977_SYSCLK_SRC_LRCLK,
35};
36
37#endif
diff --git a/sound/soc/codecs/adav801.c b/sound/soc/codecs/adav801.c
new file mode 100644
index 000000000000..790fce33ab10
--- /dev/null
+++ b/sound/soc/codecs/adav801.c
@@ -0,0 +1,53 @@
1/*
2 * ADAV801 audio driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/module.h>
10#include <linux/spi/spi.h>
11#include <linux/regmap.h>
12
13#include <sound/soc.h>
14
15#include "adav80x.h"
16
17static const struct spi_device_id adav80x_spi_id[] = {
18 { "adav801", 0 },
19 { }
20};
21MODULE_DEVICE_TABLE(spi, adav80x_spi_id);
22
23static int adav80x_spi_probe(struct spi_device *spi)
24{
25 struct regmap_config config;
26
27 config = adav80x_regmap_config;
28 config.read_flag_mask = 0x01;
29
30 return adav80x_bus_probe(&spi->dev, devm_regmap_init_spi(spi, &config));
31}
32
33static int adav80x_spi_remove(struct spi_device *spi)
34{
35 snd_soc_unregister_codec(&spi->dev);
36 return 0;
37}
38
39static struct spi_driver adav80x_spi_driver = {
40 .driver = {
41 .name = "adav801",
42 .owner = THIS_MODULE,
43 },
44 .probe = adav80x_spi_probe,
45 .remove = adav80x_spi_remove,
46 .id_table = adav80x_spi_id,
47};
48module_spi_driver(adav80x_spi_driver);
49
50MODULE_DESCRIPTION("ASoC ADAV801 driver");
51MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
52MODULE_AUTHOR("Yi Li <yi.li@analog.com>>");
53MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/adav803.c b/sound/soc/codecs/adav803.c
new file mode 100644
index 000000000000..66d9fce34e62
--- /dev/null
+++ b/sound/soc/codecs/adav803.c
@@ -0,0 +1,50 @@
1/*
2 * ADAV803 audio driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/module.h>
10#include <linux/i2c.h>
11#include <linux/regmap.h>
12
13#include <sound/soc.h>
14
15#include "adav80x.h"
16
17static const struct i2c_device_id adav803_id[] = {
18 { "adav803", 0 },
19 { }
20};
21MODULE_DEVICE_TABLE(i2c, adav803_id);
22
23static int adav803_probe(struct i2c_client *client,
24 const struct i2c_device_id *id)
25{
26 return adav80x_bus_probe(&client->dev,
27 devm_regmap_init_i2c(client, &adav80x_regmap_config));
28}
29
30static int adav803_remove(struct i2c_client *client)
31{
32 snd_soc_unregister_codec(&client->dev);
33 return 0;
34}
35
36static struct i2c_driver adav803_driver = {
37 .driver = {
38 .name = "adav803",
39 .owner = THIS_MODULE,
40 },
41 .probe = adav803_probe,
42 .remove = adav803_remove,
43 .id_table = adav803_id,
44};
45module_i2c_driver(adav803_driver);
46
47MODULE_DESCRIPTION("ASoC ADAV803 driver");
48MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
49MODULE_AUTHOR("Yi Li <yi.li@analog.com>>");
50MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/adav80x.c b/sound/soc/codecs/adav80x.c
index f78b27a7c461..5062e34ee8dc 100644
--- a/sound/soc/codecs/adav80x.c
+++ b/sound/soc/codecs/adav80x.c
@@ -8,17 +8,15 @@
8 * Licensed under the GPL-2 or later. 8 * Licensed under the GPL-2 or later.
9 */ 9 */
10 10
11#include <linux/init.h>
12#include <linux/module.h> 11#include <linux/module.h>
13#include <linux/kernel.h> 12#include <linux/kernel.h>
14#include <linux/i2c.h> 13#include <linux/regmap.h>
15#include <linux/spi/spi.h>
16#include <linux/slab.h> 14#include <linux/slab.h>
17#include <sound/core.h> 15
18#include <sound/pcm.h> 16#include <sound/pcm.h>
19#include <sound/pcm_params.h> 17#include <sound/pcm_params.h>
20#include <sound/tlv.h>
21#include <sound/soc.h> 18#include <sound/soc.h>
19#include <sound/tlv.h>
22 20
23#include "adav80x.h" 21#include "adav80x.h"
24 22
@@ -541,6 +539,7 @@ static int adav80x_set_sysclk(struct snd_soc_codec *codec,
541 unsigned int freq, int dir) 539 unsigned int freq, int dir)
542{ 540{
543 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec); 541 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
542 struct snd_soc_dapm_context *dapm = &codec->dapm;
544 543
545 if (dir == SND_SOC_CLOCK_IN) { 544 if (dir == SND_SOC_CLOCK_IN) {
546 switch (clk_id) { 545 switch (clk_id) {
@@ -573,7 +572,7 @@ static int adav80x_set_sysclk(struct snd_soc_codec *codec,
573 regmap_write(adav80x->regmap, ADAV80X_ICLK_CTRL2, 572 regmap_write(adav80x->regmap, ADAV80X_ICLK_CTRL2,
574 iclk_ctrl2); 573 iclk_ctrl2);
575 574
576 snd_soc_dapm_sync(&codec->dapm); 575 snd_soc_dapm_sync(dapm);
577 } 576 }
578 } else { 577 } else {
579 unsigned int mask; 578 unsigned int mask;
@@ -600,17 +599,21 @@ static int adav80x_set_sysclk(struct snd_soc_codec *codec,
600 adav80x->sysclk_pd[clk_id] = false; 599 adav80x->sysclk_pd[clk_id] = false;
601 } 600 }
602 601
602 snd_soc_dapm_mutex_lock(dapm);
603
603 if (adav80x->sysclk_pd[0]) 604 if (adav80x->sysclk_pd[0])
604 snd_soc_dapm_disable_pin(&codec->dapm, "PLL1"); 605 snd_soc_dapm_disable_pin_unlocked(dapm, "PLL1");
605 else 606 else
606 snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL1"); 607 snd_soc_dapm_force_enable_pin_unlocked(dapm, "PLL1");
607 608
608 if (adav80x->sysclk_pd[1] || adav80x->sysclk_pd[2]) 609 if (adav80x->sysclk_pd[1] || adav80x->sysclk_pd[2])
609 snd_soc_dapm_disable_pin(&codec->dapm, "PLL2"); 610 snd_soc_dapm_disable_pin_unlocked(dapm, "PLL2");
610 else 611 else
611 snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL2"); 612 snd_soc_dapm_force_enable_pin_unlocked(dapm, "PLL2");
612 613
613 snd_soc_dapm_sync(&codec->dapm); 614 snd_soc_dapm_sync_unlocked(dapm);
615
616 snd_soc_dapm_mutex_unlock(dapm);
614 } 617 }
615 618
616 return 0; 619 return 0;
@@ -722,7 +725,7 @@ static int adav80x_dai_startup(struct snd_pcm_substream *substream,
722 struct snd_soc_codec *codec = dai->codec; 725 struct snd_soc_codec *codec = dai->codec;
723 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec); 726 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
724 727
725 if (!codec->active || !adav80x->rate) 728 if (!snd_soc_codec_is_active(codec) || !adav80x->rate)
726 return 0; 729 return 0;
727 730
728 return snd_pcm_hw_constraint_minmax(substream->runtime, 731 return snd_pcm_hw_constraint_minmax(substream->runtime,
@@ -735,7 +738,7 @@ static void adav80x_dai_shutdown(struct snd_pcm_substream *substream,
735 struct snd_soc_codec *codec = dai->codec; 738 struct snd_soc_codec *codec = dai->codec;
736 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec); 739 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
737 740
738 if (!codec->active) 741 if (!snd_soc_codec_is_active(codec))
739 adav80x->rate = 0; 742 adav80x->rate = 0;
740} 743}
741 744
@@ -798,15 +801,8 @@ static struct snd_soc_dai_driver adav80x_dais[] = {
798 801
799static int adav80x_probe(struct snd_soc_codec *codec) 802static int adav80x_probe(struct snd_soc_codec *codec)
800{ 803{
801 int ret;
802 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec); 804 struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
803 805
804 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
805 if (ret) {
806 dev_err(codec->dev, "failed to set cache I/O: %d\n", ret);
807 return ret;
808 }
809
810 /* Force PLLs on for SYSCLK output */ 806 /* Force PLLs on for SYSCLK output */
811 snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL1"); 807 snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL1");
812 snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL2"); 808 snd_soc_dapm_force_enable_pin(&codec->dapm, "PLL2");
@@ -864,39 +860,26 @@ static struct snd_soc_codec_driver adav80x_codec_driver = {
864 .num_dapm_routes = ARRAY_SIZE(adav80x_dapm_routes), 860 .num_dapm_routes = ARRAY_SIZE(adav80x_dapm_routes),
865}; 861};
866 862
867static int adav80x_bus_probe(struct device *dev, struct regmap *regmap) 863int adav80x_bus_probe(struct device *dev, struct regmap *regmap)
868{ 864{
869 struct adav80x *adav80x; 865 struct adav80x *adav80x;
870 int ret;
871 866
872 if (IS_ERR(regmap)) 867 if (IS_ERR(regmap))
873 return PTR_ERR(regmap); 868 return PTR_ERR(regmap);
874 869
875 adav80x = kzalloc(sizeof(*adav80x), GFP_KERNEL); 870 adav80x = devm_kzalloc(dev, sizeof(*adav80x), GFP_KERNEL);
876 if (!adav80x) 871 if (!adav80x)
877 return -ENOMEM; 872 return -ENOMEM;
878 873
879
880 dev_set_drvdata(dev, adav80x); 874 dev_set_drvdata(dev, adav80x);
881 adav80x->regmap = regmap; 875 adav80x->regmap = regmap;
882 876
883 ret = snd_soc_register_codec(dev, &adav80x_codec_driver, 877 return snd_soc_register_codec(dev, &adav80x_codec_driver,
884 adav80x_dais, ARRAY_SIZE(adav80x_dais)); 878 adav80x_dais, ARRAY_SIZE(adav80x_dais));
885 if (ret)
886 kfree(adav80x);
887
888 return ret;
889}
890
891static int adav80x_bus_remove(struct device *dev)
892{
893 snd_soc_unregister_codec(dev);
894 kfree(dev_get_drvdata(dev));
895 return 0;
896} 879}
880EXPORT_SYMBOL_GPL(adav80x_bus_probe);
897 881
898#if defined(CONFIG_SPI_MASTER) 882const struct regmap_config adav80x_regmap_config = {
899static const struct regmap_config adav80x_spi_regmap_config = {
900 .val_bits = 8, 883 .val_bits = 8,
901 .pad_bits = 1, 884 .pad_bits = 1,
902 .reg_bits = 7, 885 .reg_bits = 7,
@@ -908,105 +891,7 @@ static const struct regmap_config adav80x_spi_regmap_config = {
908 .reg_defaults = adav80x_reg_defaults, 891 .reg_defaults = adav80x_reg_defaults,
909 .num_reg_defaults = ARRAY_SIZE(adav80x_reg_defaults), 892 .num_reg_defaults = ARRAY_SIZE(adav80x_reg_defaults),
910}; 893};
911 894EXPORT_SYMBOL_GPL(adav80x_regmap_config);
912static const struct spi_device_id adav80x_spi_id[] = {
913 { "adav801", 0 },
914 { }
915};
916MODULE_DEVICE_TABLE(spi, adav80x_spi_id);
917
918static int adav80x_spi_probe(struct spi_device *spi)
919{
920 return adav80x_bus_probe(&spi->dev,
921 devm_regmap_init_spi(spi, &adav80x_spi_regmap_config));
922}
923
924static int adav80x_spi_remove(struct spi_device *spi)
925{
926 return adav80x_bus_remove(&spi->dev);
927}
928
929static struct spi_driver adav80x_spi_driver = {
930 .driver = {
931 .name = "adav801",
932 .owner = THIS_MODULE,
933 },
934 .probe = adav80x_spi_probe,
935 .remove = adav80x_spi_remove,
936 .id_table = adav80x_spi_id,
937};
938#endif
939
940#if IS_ENABLED(CONFIG_I2C)
941static const struct regmap_config adav80x_i2c_regmap_config = {
942 .val_bits = 8,
943 .pad_bits = 1,
944 .reg_bits = 7,
945
946 .max_register = ADAV80X_PLL_OUTE,
947
948 .cache_type = REGCACHE_RBTREE,
949 .reg_defaults = adav80x_reg_defaults,
950 .num_reg_defaults = ARRAY_SIZE(adav80x_reg_defaults),
951};
952
953static const struct i2c_device_id adav80x_i2c_id[] = {
954 { "adav803", 0 },
955 { }
956};
957MODULE_DEVICE_TABLE(i2c, adav80x_i2c_id);
958
959static int adav80x_i2c_probe(struct i2c_client *client,
960 const struct i2c_device_id *id)
961{
962 return adav80x_bus_probe(&client->dev,
963 devm_regmap_init_i2c(client, &adav80x_i2c_regmap_config));
964}
965
966static int adav80x_i2c_remove(struct i2c_client *client)
967{
968 return adav80x_bus_remove(&client->dev);
969}
970
971static struct i2c_driver adav80x_i2c_driver = {
972 .driver = {
973 .name = "adav803",
974 .owner = THIS_MODULE,
975 },
976 .probe = adav80x_i2c_probe,
977 .remove = adav80x_i2c_remove,
978 .id_table = adav80x_i2c_id,
979};
980#endif
981
982static int __init adav80x_init(void)
983{
984 int ret = 0;
985
986#if IS_ENABLED(CONFIG_I2C)
987 ret = i2c_add_driver(&adav80x_i2c_driver);
988 if (ret)
989 return ret;
990#endif
991
992#if defined(CONFIG_SPI_MASTER)
993 ret = spi_register_driver(&adav80x_spi_driver);
994#endif
995
996 return ret;
997}
998module_init(adav80x_init);
999
1000static void __exit adav80x_exit(void)
1001{
1002#if IS_ENABLED(CONFIG_I2C)
1003 i2c_del_driver(&adav80x_i2c_driver);
1004#endif
1005#if defined(CONFIG_SPI_MASTER)
1006 spi_unregister_driver(&adav80x_spi_driver);
1007#endif
1008}
1009module_exit(adav80x_exit);
1010 895
1011MODULE_DESCRIPTION("ASoC ADAV80x driver"); 896MODULE_DESCRIPTION("ASoC ADAV80x driver");
1012MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 897MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
diff --git a/sound/soc/codecs/adav80x.h b/sound/soc/codecs/adav80x.h
index adb0fc76d4e3..8a1d7c09dca5 100644
--- a/sound/soc/codecs/adav80x.h
+++ b/sound/soc/codecs/adav80x.h
@@ -9,6 +9,13 @@
9#ifndef _ADAV80X_H 9#ifndef _ADAV80X_H
10#define _ADAV80X_H 10#define _ADAV80X_H
11 11
12#include <linux/regmap.h>
13
14struct device;
15
16extern const struct regmap_config adav80x_regmap_config;
17int adav80x_bus_probe(struct device *dev, struct regmap *regmap);
18
12enum adav80x_pll_src { 19enum adav80x_pll_src {
13 ADAV80X_PLL_SRC_XIN, 20 ADAV80X_PLL_SRC_XIN,
14 ADAV80X_PLL_SRC_XTAL, 21 ADAV80X_PLL_SRC_XTAL,
diff --git a/sound/soc/codecs/ak4104.c b/sound/soc/codecs/ak4104.c
index b4819dcd4f4d..10adf25d4c14 100644
--- a/sound/soc/codecs/ak4104.c
+++ b/sound/soc/codecs/ak4104.c
@@ -174,8 +174,6 @@ static int ak4104_probe(struct snd_soc_codec *codec)
174 struct ak4104_private *ak4104 = snd_soc_codec_get_drvdata(codec); 174 struct ak4104_private *ak4104 = snd_soc_codec_get_drvdata(codec);
175 int ret; 175 int ret;
176 176
177 codec->control_data = ak4104->regmap;
178
179 /* set power-up and non-reset bits */ 177 /* set power-up and non-reset bits */
180 ret = regmap_update_bits(ak4104->regmap, AK4104_REG_CONTROL1, 178 ret = regmap_update_bits(ak4104->regmap, AK4104_REG_CONTROL1,
181 AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN, 179 AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN,
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c
index 684fe910669f..30e297890fec 100644
--- a/sound/soc/codecs/ak4535.c
+++ b/sound/soc/codecs/ak4535.c
@@ -388,15 +388,6 @@ static int ak4535_resume(struct snd_soc_codec *codec)
388 388
389static int ak4535_probe(struct snd_soc_codec *codec) 389static int ak4535_probe(struct snd_soc_codec *codec)
390{ 390{
391 struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
392 int ret;
393
394 codec->control_data = ak4535->regmap;
395 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
396 if (ret < 0) {
397 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
398 return ret;
399 }
400 /* power on device */ 391 /* power on device */
401 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 392 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
402 393
diff --git a/sound/soc/codecs/ak4641.c b/sound/soc/codecs/ak4641.c
index 94cbe508dd37..868c0e2da1ec 100644
--- a/sound/soc/codecs/ak4641.c
+++ b/sound/soc/codecs/ak4641.c
@@ -113,14 +113,14 @@ static const DECLARE_TLV_DB_SCALE(alc_tlv, -800, 50, 0);
113static const DECLARE_TLV_DB_SCALE(aux_in_tlv, -2100, 300, 0); 113static const DECLARE_TLV_DB_SCALE(aux_in_tlv, -2100, 300, 0);
114 114
115 115
116static const struct soc_enum ak4641_mono_out_enum = 116static SOC_ENUM_SINGLE_DECL(ak4641_mono_out_enum,
117 SOC_ENUM_SINGLE(AK4641_SIG1, 6, 2, ak4641_mono_out); 117 AK4641_SIG1, 6, ak4641_mono_out);
118static const struct soc_enum ak4641_hp_out_enum = 118static SOC_ENUM_SINGLE_DECL(ak4641_hp_out_enum,
119 SOC_ENUM_SINGLE(AK4641_MODE2, 2, 2, ak4641_hp_out); 119 AK4641_MODE2, 2, ak4641_hp_out);
120static const struct soc_enum ak4641_mic_select_enum = 120static SOC_ENUM_SINGLE_DECL(ak4641_mic_select_enum,
121 SOC_ENUM_SINGLE(AK4641_MIC, 1, 2, ak4641_mic_select); 121 AK4641_MIC, 1, ak4641_mic_select);
122static const struct soc_enum ak4641_mic_or_dac_enum = 122static SOC_ENUM_SINGLE_DECL(ak4641_mic_or_dac_enum,
123 SOC_ENUM_SINGLE(AK4641_BTIF, 4, 2, ak4641_mic_or_dac); 123 AK4641_BTIF, 4, ak4641_mic_or_dac);
124 124
125static const struct snd_kcontrol_new ak4641_snd_controls[] = { 125static const struct snd_kcontrol_new ak4641_snd_controls[] = {
126 SOC_ENUM("Mono 1 Output", ak4641_mono_out_enum), 126 SOC_ENUM("Mono 1 Output", ak4641_mono_out_enum),
@@ -519,14 +519,6 @@ static int ak4641_resume(struct snd_soc_codec *codec)
519 519
520static int ak4641_probe(struct snd_soc_codec *codec) 520static int ak4641_probe(struct snd_soc_codec *codec)
521{ 521{
522 int ret;
523
524 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
525 if (ret != 0) {
526 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
527 return ret;
528 }
529
530 /* power on device */ 522 /* power on device */
531 ak4641_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 523 ak4641_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
532 524
diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index 1f646c6e90c6..92655cc189ae 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -465,14 +465,6 @@ static int ak4642_resume(struct snd_soc_codec *codec)
465 465
466static int ak4642_probe(struct snd_soc_codec *codec) 466static int ak4642_probe(struct snd_soc_codec *codec)
467{ 467{
468 int ret;
469
470 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
471 if (ret < 0) {
472 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
473 return ret;
474 }
475
476 ak4642_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 468 ak4642_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
477 469
478 return 0; 470 return 0;
diff --git a/sound/soc/codecs/ak4671.c b/sound/soc/codecs/ak4671.c
index 25bdf6ad4a54..998fa0c5a0b9 100644
--- a/sound/soc/codecs/ak4671.c
+++ b/sound/soc/codecs/ak4671.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/i2c.h> 16#include <linux/i2c.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/regmap.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <sound/soc.h> 20#include <sound/soc.h>
20#include <sound/initval.h> 21#include <sound/initval.h>
@@ -23,104 +24,99 @@
23#include "ak4671.h" 24#include "ak4671.h"
24 25
25 26
26/* codec private data */
27struct ak4671_priv {
28 enum snd_soc_control_type control_type;
29};
30
31/* ak4671 register cache & default register settings */ 27/* ak4671 register cache & default register settings */
32static const u8 ak4671_reg[AK4671_CACHEREGNUM] = { 28static const struct reg_default ak4671_reg_defaults[] = {
33 0x00, /* AK4671_AD_DA_POWER_MANAGEMENT (0x00) */ 29 { 0x00, 0x00 }, /* AK4671_AD_DA_POWER_MANAGEMENT (0x00) */
34 0xf6, /* AK4671_PLL_MODE_SELECT0 (0x01) */ 30 { 0x01, 0xf6 }, /* AK4671_PLL_MODE_SELECT0 (0x01) */
35 0x00, /* AK4671_PLL_MODE_SELECT1 (0x02) */ 31 { 0x02, 0x00 }, /* AK4671_PLL_MODE_SELECT1 (0x02) */
36 0x02, /* AK4671_FORMAT_SELECT (0x03) */ 32 { 0x03, 0x02 }, /* AK4671_FORMAT_SELECT (0x03) */
37 0x00, /* AK4671_MIC_SIGNAL_SELECT (0x04) */ 33 { 0x04, 0x00 }, /* AK4671_MIC_SIGNAL_SELECT (0x04) */
38 0x55, /* AK4671_MIC_AMP_GAIN (0x05) */ 34 { 0x05, 0x55 }, /* AK4671_MIC_AMP_GAIN (0x05) */
39 0x00, /* AK4671_MIXING_POWER_MANAGEMENT0 (0x06) */ 35 { 0x06, 0x00 }, /* AK4671_MIXING_POWER_MANAGEMENT0 (0x06) */
40 0x00, /* AK4671_MIXING_POWER_MANAGEMENT1 (0x07) */ 36 { 0x07, 0x00 }, /* AK4671_MIXING_POWER_MANAGEMENT1 (0x07) */
41 0xb5, /* AK4671_OUTPUT_VOLUME_CONTROL (0x08) */ 37 { 0x08, 0xb5 }, /* AK4671_OUTPUT_VOLUME_CONTROL (0x08) */
42 0x00, /* AK4671_LOUT1_SIGNAL_SELECT (0x09) */ 38 { 0x09, 0x00 }, /* AK4671_LOUT1_SIGNAL_SELECT (0x09) */
43 0x00, /* AK4671_ROUT1_SIGNAL_SELECT (0x0a) */ 39 { 0x0a, 0x00 }, /* AK4671_ROUT1_SIGNAL_SELECT (0x0a) */
44 0x00, /* AK4671_LOUT2_SIGNAL_SELECT (0x0b) */ 40 { 0x0b, 0x00 }, /* AK4671_LOUT2_SIGNAL_SELECT (0x0b) */
45 0x00, /* AK4671_ROUT2_SIGNAL_SELECT (0x0c) */ 41 { 0x0c, 0x00 }, /* AK4671_ROUT2_SIGNAL_SELECT (0x0c) */
46 0x00, /* AK4671_LOUT3_SIGNAL_SELECT (0x0d) */ 42 { 0x0d, 0x00 }, /* AK4671_LOUT3_SIGNAL_SELECT (0x0d) */
47 0x00, /* AK4671_ROUT3_SIGNAL_SELECT (0x0e) */ 43 { 0x0e, 0x00 }, /* AK4671_ROUT3_SIGNAL_SELECT (0x0e) */
48 0x00, /* AK4671_LOUT1_POWER_MANAGERMENT (0x0f) */ 44 { 0x0f, 0x00 }, /* AK4671_LOUT1_POWER_MANAGERMENT (0x0f) */
49 0x00, /* AK4671_LOUT2_POWER_MANAGERMENT (0x10) */ 45 { 0x10, 0x00 }, /* AK4671_LOUT2_POWER_MANAGERMENT (0x10) */
50 0x80, /* AK4671_LOUT3_POWER_MANAGERMENT (0x11) */ 46 { 0x11, 0x80 }, /* AK4671_LOUT3_POWER_MANAGERMENT (0x11) */
51 0x91, /* AK4671_LCH_INPUT_VOLUME_CONTROL (0x12) */ 47 { 0x12, 0x91 }, /* AK4671_LCH_INPUT_VOLUME_CONTROL (0x12) */
52 0x91, /* AK4671_RCH_INPUT_VOLUME_CONTROL (0x13) */ 48 { 0x13, 0x91 }, /* AK4671_RCH_INPUT_VOLUME_CONTROL (0x13) */
53 0xe1, /* AK4671_ALC_REFERENCE_SELECT (0x14) */ 49 { 0x14, 0xe1 }, /* AK4671_ALC_REFERENCE_SELECT (0x14) */
54 0x00, /* AK4671_DIGITAL_MIXING_CONTROL (0x15) */ 50 { 0x15, 0x00 }, /* AK4671_DIGITAL_MIXING_CONTROL (0x15) */
55 0x00, /* AK4671_ALC_TIMER_SELECT (0x16) */ 51 { 0x16, 0x00 }, /* AK4671_ALC_TIMER_SELECT (0x16) */
56 0x00, /* AK4671_ALC_MODE_CONTROL (0x17) */ 52 { 0x17, 0x00 }, /* AK4671_ALC_MODE_CONTROL (0x17) */
57 0x02, /* AK4671_MODE_CONTROL1 (0x18) */ 53 { 0x18, 0x02 }, /* AK4671_MODE_CONTROL1 (0x18) */
58 0x01, /* AK4671_MODE_CONTROL2 (0x19) */ 54 { 0x19, 0x01 }, /* AK4671_MODE_CONTROL2 (0x19) */
59 0x18, /* AK4671_LCH_OUTPUT_VOLUME_CONTROL (0x1a) */ 55 { 0x1a, 0x18 }, /* AK4671_LCH_OUTPUT_VOLUME_CONTROL (0x1a) */
60 0x18, /* AK4671_RCH_OUTPUT_VOLUME_CONTROL (0x1b) */ 56 { 0x1b, 0x18 }, /* AK4671_RCH_OUTPUT_VOLUME_CONTROL (0x1b) */
61 0x00, /* AK4671_SIDETONE_A_CONTROL (0x1c) */ 57 { 0x1c, 0x00 }, /* AK4671_SIDETONE_A_CONTROL (0x1c) */
62 0x02, /* AK4671_DIGITAL_FILTER_SELECT (0x1d) */ 58 { 0x1d, 0x02 }, /* AK4671_DIGITAL_FILTER_SELECT (0x1d) */
63 0x00, /* AK4671_FIL3_COEFFICIENT0 (0x1e) */ 59 { 0x1e, 0x00 }, /* AK4671_FIL3_COEFFICIENT0 (0x1e) */
64 0x00, /* AK4671_FIL3_COEFFICIENT1 (0x1f) */ 60 { 0x1f, 0x00 }, /* AK4671_FIL3_COEFFICIENT1 (0x1f) */
65 0x00, /* AK4671_FIL3_COEFFICIENT2 (0x20) */ 61 { 0x20, 0x00 }, /* AK4671_FIL3_COEFFICIENT2 (0x20) */
66 0x00, /* AK4671_FIL3_COEFFICIENT3 (0x21) */ 62 { 0x21, 0x00 }, /* AK4671_FIL3_COEFFICIENT3 (0x21) */
67 0x00, /* AK4671_EQ_COEFFICIENT0 (0x22) */ 63 { 0x22, 0x00 }, /* AK4671_EQ_COEFFICIENT0 (0x22) */
68 0x00, /* AK4671_EQ_COEFFICIENT1 (0x23) */ 64 { 0x23, 0x00 }, /* AK4671_EQ_COEFFICIENT1 (0x23) */
69 0x00, /* AK4671_EQ_COEFFICIENT2 (0x24) */ 65 { 0x24, 0x00 }, /* AK4671_EQ_COEFFICIENT2 (0x24) */
70 0x00, /* AK4671_EQ_COEFFICIENT3 (0x25) */ 66 { 0x25, 0x00 }, /* AK4671_EQ_COEFFICIENT3 (0x25) */
71 0x00, /* AK4671_EQ_COEFFICIENT4 (0x26) */ 67 { 0x26, 0x00 }, /* AK4671_EQ_COEFFICIENT4 (0x26) */
72 0x00, /* AK4671_EQ_COEFFICIENT5 (0x27) */ 68 { 0x27, 0x00 }, /* AK4671_EQ_COEFFICIENT5 (0x27) */
73 0xa9, /* AK4671_FIL1_COEFFICIENT0 (0x28) */ 69 { 0x28, 0xa9 }, /* AK4671_FIL1_COEFFICIENT0 (0x28) */
74 0x1f, /* AK4671_FIL1_COEFFICIENT1 (0x29) */ 70 { 0x29, 0x1f }, /* AK4671_FIL1_COEFFICIENT1 (0x29) */
75 0xad, /* AK4671_FIL1_COEFFICIENT2 (0x2a) */ 71 { 0x2a, 0xad }, /* AK4671_FIL1_COEFFICIENT2 (0x2a) */
76 0x20, /* AK4671_FIL1_COEFFICIENT3 (0x2b) */ 72 { 0x2b, 0x20 }, /* AK4671_FIL1_COEFFICIENT3 (0x2b) */
77 0x00, /* AK4671_FIL2_COEFFICIENT0 (0x2c) */ 73 { 0x2c, 0x00 }, /* AK4671_FIL2_COEFFICIENT0 (0x2c) */
78 0x00, /* AK4671_FIL2_COEFFICIENT1 (0x2d) */ 74 { 0x2d, 0x00 }, /* AK4671_FIL2_COEFFICIENT1 (0x2d) */
79 0x00, /* AK4671_FIL2_COEFFICIENT2 (0x2e) */ 75 { 0x2e, 0x00 }, /* AK4671_FIL2_COEFFICIENT2 (0x2e) */
80 0x00, /* AK4671_FIL2_COEFFICIENT3 (0x2f) */ 76 { 0x2f, 0x00 }, /* AK4671_FIL2_COEFFICIENT3 (0x2f) */
81 0x00, /* AK4671_DIGITAL_FILTER_SELECT2 (0x30) */ 77 { 0x30, 0x00 }, /* AK4671_DIGITAL_FILTER_SELECT2 (0x30) */
82 0x00, /* this register not used */ 78
83 0x00, /* AK4671_E1_COEFFICIENT0 (0x32) */ 79 { 0x32, 0x00 }, /* AK4671_E1_COEFFICIENT0 (0x32) */
84 0x00, /* AK4671_E1_COEFFICIENT1 (0x33) */ 80 { 0x33, 0x00 }, /* AK4671_E1_COEFFICIENT1 (0x33) */
85 0x00, /* AK4671_E1_COEFFICIENT2 (0x34) */ 81 { 0x34, 0x00 }, /* AK4671_E1_COEFFICIENT2 (0x34) */
86 0x00, /* AK4671_E1_COEFFICIENT3 (0x35) */ 82 { 0x35, 0x00 }, /* AK4671_E1_COEFFICIENT3 (0x35) */
87 0x00, /* AK4671_E1_COEFFICIENT4 (0x36) */ 83 { 0x36, 0x00 }, /* AK4671_E1_COEFFICIENT4 (0x36) */
88 0x00, /* AK4671_E1_COEFFICIENT5 (0x37) */ 84 { 0x37, 0x00 }, /* AK4671_E1_COEFFICIENT5 (0x37) */
89 0x00, /* AK4671_E2_COEFFICIENT0 (0x38) */ 85 { 0x38, 0x00 }, /* AK4671_E2_COEFFICIENT0 (0x38) */
90 0x00, /* AK4671_E2_COEFFICIENT1 (0x39) */ 86 { 0x39, 0x00 }, /* AK4671_E2_COEFFICIENT1 (0x39) */
91 0x00, /* AK4671_E2_COEFFICIENT2 (0x3a) */ 87 { 0x3a, 0x00 }, /* AK4671_E2_COEFFICIENT2 (0x3a) */
92 0x00, /* AK4671_E2_COEFFICIENT3 (0x3b) */ 88 { 0x3b, 0x00 }, /* AK4671_E2_COEFFICIENT3 (0x3b) */
93 0x00, /* AK4671_E2_COEFFICIENT4 (0x3c) */ 89 { 0x3c, 0x00 }, /* AK4671_E2_COEFFICIENT4 (0x3c) */
94 0x00, /* AK4671_E2_COEFFICIENT5 (0x3d) */ 90 { 0x3d, 0x00 }, /* AK4671_E2_COEFFICIENT5 (0x3d) */
95 0x00, /* AK4671_E3_COEFFICIENT0 (0x3e) */ 91 { 0x3e, 0x00 }, /* AK4671_E3_COEFFICIENT0 (0x3e) */
96 0x00, /* AK4671_E3_COEFFICIENT1 (0x3f) */ 92 { 0x3f, 0x00 }, /* AK4671_E3_COEFFICIENT1 (0x3f) */
97 0x00, /* AK4671_E3_COEFFICIENT2 (0x40) */ 93 { 0x40, 0x00 }, /* AK4671_E3_COEFFICIENT2 (0x40) */
98 0x00, /* AK4671_E3_COEFFICIENT3 (0x41) */ 94 { 0x41, 0x00 }, /* AK4671_E3_COEFFICIENT3 (0x41) */
99 0x00, /* AK4671_E3_COEFFICIENT4 (0x42) */ 95 { 0x42, 0x00 }, /* AK4671_E3_COEFFICIENT4 (0x42) */
100 0x00, /* AK4671_E3_COEFFICIENT5 (0x43) */ 96 { 0x43, 0x00 }, /* AK4671_E3_COEFFICIENT5 (0x43) */
101 0x00, /* AK4671_E4_COEFFICIENT0 (0x44) */ 97 { 0x44, 0x00 }, /* AK4671_E4_COEFFICIENT0 (0x44) */
102 0x00, /* AK4671_E4_COEFFICIENT1 (0x45) */ 98 { 0x45, 0x00 }, /* AK4671_E4_COEFFICIENT1 (0x45) */
103 0x00, /* AK4671_E4_COEFFICIENT2 (0x46) */ 99 { 0x46, 0x00 }, /* AK4671_E4_COEFFICIENT2 (0x46) */
104 0x00, /* AK4671_E4_COEFFICIENT3 (0x47) */ 100 { 0x47, 0x00 }, /* AK4671_E4_COEFFICIENT3 (0x47) */
105 0x00, /* AK4671_E4_COEFFICIENT4 (0x48) */ 101 { 0x48, 0x00 }, /* AK4671_E4_COEFFICIENT4 (0x48) */
106 0x00, /* AK4671_E4_COEFFICIENT5 (0x49) */ 102 { 0x49, 0x00 }, /* AK4671_E4_COEFFICIENT5 (0x49) */
107 0x00, /* AK4671_E5_COEFFICIENT0 (0x4a) */ 103 { 0x4a, 0x00 }, /* AK4671_E5_COEFFICIENT0 (0x4a) */
108 0x00, /* AK4671_E5_COEFFICIENT1 (0x4b) */ 104 { 0x4b, 0x00 }, /* AK4671_E5_COEFFICIENT1 (0x4b) */
109 0x00, /* AK4671_E5_COEFFICIENT2 (0x4c) */ 105 { 0x4c, 0x00 }, /* AK4671_E5_COEFFICIENT2 (0x4c) */
110 0x00, /* AK4671_E5_COEFFICIENT3 (0x4d) */ 106 { 0x4d, 0x00 }, /* AK4671_E5_COEFFICIENT3 (0x4d) */
111 0x00, /* AK4671_E5_COEFFICIENT4 (0x4e) */ 107 { 0x4e, 0x00 }, /* AK4671_E5_COEFFICIENT4 (0x4e) */
112 0x00, /* AK4671_E5_COEFFICIENT5 (0x4f) */ 108 { 0x4f, 0x00 }, /* AK4671_E5_COEFFICIENT5 (0x4f) */
113 0x88, /* AK4671_EQ_CONTROL_250HZ_100HZ (0x50) */ 109 { 0x50, 0x88 }, /* AK4671_EQ_CONTROL_250HZ_100HZ (0x50) */
114 0x88, /* AK4671_EQ_CONTROL_3500HZ_1KHZ (0x51) */ 110 { 0x51, 0x88 }, /* AK4671_EQ_CONTROL_3500HZ_1KHZ (0x51) */
115 0x08, /* AK4671_EQ_CONTRO_10KHZ (0x52) */ 111 { 0x52, 0x08 }, /* AK4671_EQ_CONTRO_10KHZ (0x52) */
116 0x00, /* AK4671_PCM_IF_CONTROL0 (0x53) */ 112 { 0x53, 0x00 }, /* AK4671_PCM_IF_CONTROL0 (0x53) */
117 0x00, /* AK4671_PCM_IF_CONTROL1 (0x54) */ 113 { 0x54, 0x00 }, /* AK4671_PCM_IF_CONTROL1 (0x54) */
118 0x00, /* AK4671_PCM_IF_CONTROL2 (0x55) */ 114 { 0x55, 0x00 }, /* AK4671_PCM_IF_CONTROL2 (0x55) */
119 0x18, /* AK4671_DIGITAL_VOLUME_B_CONTROL (0x56) */ 115 { 0x56, 0x18 }, /* AK4671_DIGITAL_VOLUME_B_CONTROL (0x56) */
120 0x18, /* AK4671_DIGITAL_VOLUME_C_CONTROL (0x57) */ 116 { 0x57, 0x18 }, /* AK4671_DIGITAL_VOLUME_C_CONTROL (0x57) */
121 0x00, /* AK4671_SIDETONE_VOLUME_CONTROL (0x58) */ 117 { 0x58, 0x00 }, /* AK4671_SIDETONE_VOLUME_CONTROL (0x58) */
122 0x00, /* AK4671_DIGITAL_MIXING_CONTROL2 (0x59) */ 118 { 0x59, 0x00 }, /* AK4671_DIGITAL_MIXING_CONTROL2 (0x59) */
123 0x00, /* AK4671_SAR_ADC_CONTROL (0x5a) */ 119 { 0x5a, 0x00 }, /* AK4671_SAR_ADC_CONTROL (0x5a) */
124}; 120};
125 121
126/* 122/*
@@ -241,19 +237,17 @@ static const struct snd_kcontrol_new ak4671_rout3_mixer_controls[] = {
241/* Input MUXs */ 237/* Input MUXs */
242static const char *ak4671_lin_mux_texts[] = 238static const char *ak4671_lin_mux_texts[] =
243 {"LIN1", "LIN2", "LIN3", "LIN4"}; 239 {"LIN1", "LIN2", "LIN3", "LIN4"};
244static const struct soc_enum ak4671_lin_mux_enum = 240static SOC_ENUM_SINGLE_DECL(ak4671_lin_mux_enum,
245 SOC_ENUM_SINGLE(AK4671_MIC_SIGNAL_SELECT, 0, 241 AK4671_MIC_SIGNAL_SELECT, 0,
246 ARRAY_SIZE(ak4671_lin_mux_texts), 242 ak4671_lin_mux_texts);
247 ak4671_lin_mux_texts);
248static const struct snd_kcontrol_new ak4671_lin_mux_control = 243static const struct snd_kcontrol_new ak4671_lin_mux_control =
249 SOC_DAPM_ENUM("Route", ak4671_lin_mux_enum); 244 SOC_DAPM_ENUM("Route", ak4671_lin_mux_enum);
250 245
251static const char *ak4671_rin_mux_texts[] = 246static const char *ak4671_rin_mux_texts[] =
252 {"RIN1", "RIN2", "RIN3", "RIN4"}; 247 {"RIN1", "RIN2", "RIN3", "RIN4"};
253static const struct soc_enum ak4671_rin_mux_enum = 248static SOC_ENUM_SINGLE_DECL(ak4671_rin_mux_enum,
254 SOC_ENUM_SINGLE(AK4671_MIC_SIGNAL_SELECT, 2, 249 AK4671_MIC_SIGNAL_SELECT, 2,
255 ARRAY_SIZE(ak4671_rin_mux_texts), 250 ak4671_rin_mux_texts);
256 ak4671_rin_mux_texts);
257static const struct snd_kcontrol_new ak4671_rin_mux_control = 251static const struct snd_kcontrol_new ak4671_rin_mux_control =
258 SOC_DAPM_ENUM("Route", ak4671_rin_mux_enum); 252 SOC_DAPM_ENUM("Route", ak4671_rin_mux_enum);
259 253
@@ -619,21 +613,7 @@ static struct snd_soc_dai_driver ak4671_dai = {
619 613
620static int ak4671_probe(struct snd_soc_codec *codec) 614static int ak4671_probe(struct snd_soc_codec *codec)
621{ 615{
622 struct ak4671_priv *ak4671 = snd_soc_codec_get_drvdata(codec); 616 return ak4671_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
623 int ret;
624
625 ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4671->control_type);
626 if (ret < 0) {
627 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
628 return ret;
629 }
630
631 snd_soc_add_codec_controls(codec, ak4671_snd_controls,
632 ARRAY_SIZE(ak4671_snd_controls));
633
634 ak4671_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
635
636 return ret;
637} 617}
638 618
639static int ak4671_remove(struct snd_soc_codec *codec) 619static int ak4671_remove(struct snd_soc_codec *codec)
@@ -646,28 +626,36 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4671 = {
646 .probe = ak4671_probe, 626 .probe = ak4671_probe,
647 .remove = ak4671_remove, 627 .remove = ak4671_remove,
648 .set_bias_level = ak4671_set_bias_level, 628 .set_bias_level = ak4671_set_bias_level,
649 .reg_cache_size = AK4671_CACHEREGNUM, 629 .controls = ak4671_snd_controls,
650 .reg_word_size = sizeof(u8), 630 .num_controls = ARRAY_SIZE(ak4671_snd_controls),
651 .reg_cache_default = ak4671_reg,
652 .dapm_widgets = ak4671_dapm_widgets, 631 .dapm_widgets = ak4671_dapm_widgets,
653 .num_dapm_widgets = ARRAY_SIZE(ak4671_dapm_widgets), 632 .num_dapm_widgets = ARRAY_SIZE(ak4671_dapm_widgets),
654 .dapm_routes = ak4671_intercon, 633 .dapm_routes = ak4671_intercon,
655 .num_dapm_routes = ARRAY_SIZE(ak4671_intercon), 634 .num_dapm_routes = ARRAY_SIZE(ak4671_intercon),
656}; 635};
657 636
637static const struct regmap_config ak4671_regmap = {
638 .reg_bits = 8,
639 .val_bits = 8,
640
641 .max_register = AK4671_SAR_ADC_CONTROL,
642 .reg_defaults = ak4671_reg_defaults,
643 .num_reg_defaults = ARRAY_SIZE(ak4671_reg_defaults),
644 .cache_type = REGCACHE_RBTREE,
645};
646
658static int ak4671_i2c_probe(struct i2c_client *client, 647static int ak4671_i2c_probe(struct i2c_client *client,
659 const struct i2c_device_id *id) 648 const struct i2c_device_id *id)
660{ 649{
661 struct ak4671_priv *ak4671; 650 struct regmap *regmap;
662 int ret; 651 int ret;
663 652
664 ak4671 = devm_kzalloc(&client->dev, sizeof(struct ak4671_priv), 653 regmap = devm_regmap_init_i2c(client, &ak4671_regmap);
665 GFP_KERNEL); 654 if (IS_ERR(regmap)) {
666 if (ak4671 == NULL) 655 ret = PTR_ERR(regmap);
667 return -ENOMEM; 656 dev_err(&client->dev, "Failed to create regmap: %d\n", ret);
668 657 return ret;
669 i2c_set_clientdata(client, ak4671); 658 }
670 ak4671->control_type = SND_SOC_I2C;
671 659
672 ret = snd_soc_register_codec(&client->dev, 660 ret = snd_soc_register_codec(&client->dev,
673 &soc_codec_dev_ak4671, &ak4671_dai, 1); 661 &soc_codec_dev_ak4671, &ak4671_dai, 1);
diff --git a/sound/soc/codecs/ak4671.h b/sound/soc/codecs/ak4671.h
index 61cb7ab7552c..394a34d3f50a 100644
--- a/sound/soc/codecs/ak4671.h
+++ b/sound/soc/codecs/ak4671.h
@@ -105,8 +105,6 @@
105#define AK4671_DIGITAL_MIXING_CONTROL2 0x59 105#define AK4671_DIGITAL_MIXING_CONTROL2 0x59
106#define AK4671_SAR_ADC_CONTROL 0x5a 106#define AK4671_SAR_ADC_CONTROL 0x5a
107 107
108#define AK4671_CACHEREGNUM (AK4671_SAR_ADC_CONTROL + 1)
109
110/* Bitfield Definitions */ 108/* Bitfield Definitions */
111 109
112/* AK4671_AD_DA_POWER_MANAGEMENT (0x00) Fields */ 110/* AK4671_AD_DA_POWER_MANAGEMENT (0x00) Fields */
diff --git a/sound/soc/codecs/alc5623.c b/sound/soc/codecs/alc5623.c
index d3036283482a..09f7e773bafb 100644
--- a/sound/soc/codecs/alc5623.c
+++ b/sound/soc/codecs/alc5623.c
@@ -21,6 +21,7 @@
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/pm.h> 22#include <linux/pm.h>
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <linux/regmap.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <sound/core.h> 26#include <sound/core.h>
26#include <sound/pcm.h> 27#include <sound/pcm.h>
@@ -38,26 +39,13 @@ MODULE_PARM_DESC(caps_charge, "ALC5623 cap charge time (msecs)");
38 39
39/* codec private data */ 40/* codec private data */
40struct alc5623_priv { 41struct alc5623_priv {
41 enum snd_soc_control_type control_type; 42 struct regmap *regmap;
42 u8 id; 43 u8 id;
43 unsigned int sysclk; 44 unsigned int sysclk;
44 u16 reg_cache[ALC5623_VENDOR_ID2+2];
45 unsigned int add_ctrl; 45 unsigned int add_ctrl;
46 unsigned int jack_det_ctrl; 46 unsigned int jack_det_ctrl;
47}; 47};
48 48
49static void alc5623_fill_cache(struct snd_soc_codec *codec)
50{
51 int i, step = codec->driver->reg_cache_step;
52 u16 *cache = codec->reg_cache;
53
54 /* not really efficient ... */
55 codec->cache_bypass = 1;
56 for (i = 0 ; i < codec->driver->reg_cache_size ; i += step)
57 cache[i] = snd_soc_read(codec, i);
58 codec->cache_bypass = 0;
59}
60
61static inline int alc5623_reset(struct snd_soc_codec *codec) 49static inline int alc5623_reset(struct snd_soc_codec *codec)
62{ 50{
63 return snd_soc_write(codec, ALC5623_RESET, 0); 51 return snd_soc_write(codec, ALC5623_RESET, 0);
@@ -228,32 +216,37 @@ static const char *alc5623_aux_out_input_sel[] = {
228 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"}; 216 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
229 217
230/* auxout output mux */ 218/* auxout output mux */
231static const struct soc_enum alc5623_aux_out_input_enum = 219static SOC_ENUM_SINGLE_DECL(alc5623_aux_out_input_enum,
232SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 6, 4, alc5623_aux_out_input_sel); 220 ALC5623_OUTPUT_MIXER_CTRL, 6,
221 alc5623_aux_out_input_sel);
233static const struct snd_kcontrol_new alc5623_auxout_mux_controls = 222static const struct snd_kcontrol_new alc5623_auxout_mux_controls =
234SOC_DAPM_ENUM("Route", alc5623_aux_out_input_enum); 223SOC_DAPM_ENUM("Route", alc5623_aux_out_input_enum);
235 224
236/* speaker output mux */ 225/* speaker output mux */
237static const struct soc_enum alc5623_spkout_input_enum = 226static SOC_ENUM_SINGLE_DECL(alc5623_spkout_input_enum,
238SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 10, 4, alc5623_spkout_input_sel); 227 ALC5623_OUTPUT_MIXER_CTRL, 10,
228 alc5623_spkout_input_sel);
239static const struct snd_kcontrol_new alc5623_spkout_mux_controls = 229static const struct snd_kcontrol_new alc5623_spkout_mux_controls =
240SOC_DAPM_ENUM("Route", alc5623_spkout_input_enum); 230SOC_DAPM_ENUM("Route", alc5623_spkout_input_enum);
241 231
242/* headphone left output mux */ 232/* headphone left output mux */
243static const struct soc_enum alc5623_hpl_out_input_enum = 233static SOC_ENUM_SINGLE_DECL(alc5623_hpl_out_input_enum,
244SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 9, 2, alc5623_hpl_out_input_sel); 234 ALC5623_OUTPUT_MIXER_CTRL, 9,
235 alc5623_hpl_out_input_sel);
245static const struct snd_kcontrol_new alc5623_hpl_out_mux_controls = 236static const struct snd_kcontrol_new alc5623_hpl_out_mux_controls =
246SOC_DAPM_ENUM("Route", alc5623_hpl_out_input_enum); 237SOC_DAPM_ENUM("Route", alc5623_hpl_out_input_enum);
247 238
248/* headphone right output mux */ 239/* headphone right output mux */
249static const struct soc_enum alc5623_hpr_out_input_enum = 240static SOC_ENUM_SINGLE_DECL(alc5623_hpr_out_input_enum,
250SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 8, 2, alc5623_hpr_out_input_sel); 241 ALC5623_OUTPUT_MIXER_CTRL, 8,
242 alc5623_hpr_out_input_sel);
251static const struct snd_kcontrol_new alc5623_hpr_out_mux_controls = 243static const struct snd_kcontrol_new alc5623_hpr_out_mux_controls =
252SOC_DAPM_ENUM("Route", alc5623_hpr_out_input_enum); 244SOC_DAPM_ENUM("Route", alc5623_hpr_out_input_enum);
253 245
254/* speaker output N select */ 246/* speaker output N select */
255static const struct soc_enum alc5623_spk_n_sour_enum = 247static SOC_ENUM_SINGLE_DECL(alc5623_spk_n_sour_enum,
256SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 14, 4, alc5623_spk_n_sour_sel); 248 ALC5623_OUTPUT_MIXER_CTRL, 14,
249 alc5623_spk_n_sour_sel);
257static const struct snd_kcontrol_new alc5623_spkoutn_mux_controls = 250static const struct snd_kcontrol_new alc5623_spkoutn_mux_controls =
258SOC_DAPM_ENUM("Route", alc5623_spk_n_sour_enum); 251SOC_DAPM_ENUM("Route", alc5623_spk_n_sour_enum);
259 252
@@ -338,8 +331,9 @@ SND_SOC_DAPM_VMID("Vmid"),
338}; 331};
339 332
340static const char *alc5623_amp_names[] = {"AB Amp", "D Amp"}; 333static const char *alc5623_amp_names[] = {"AB Amp", "D Amp"};
341static const struct soc_enum alc5623_amp_enum = 334static SOC_ENUM_SINGLE_DECL(alc5623_amp_enum,
342 SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL, 13, 2, alc5623_amp_names); 335 ALC5623_OUTPUT_MIXER_CTRL, 13,
336 alc5623_amp_names);
343static const struct snd_kcontrol_new alc5623_amp_mux_controls = 337static const struct snd_kcontrol_new alc5623_amp_mux_controls =
344 SOC_DAPM_ENUM("Route", alc5623_amp_enum); 338 SOC_DAPM_ENUM("Route", alc5623_amp_enum);
345 339
@@ -869,18 +863,28 @@ static struct snd_soc_dai_driver alc5623_dai = {
869 863
870static int alc5623_suspend(struct snd_soc_codec *codec) 864static int alc5623_suspend(struct snd_soc_codec *codec)
871{ 865{
866 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
867
872 alc5623_set_bias_level(codec, SND_SOC_BIAS_OFF); 868 alc5623_set_bias_level(codec, SND_SOC_BIAS_OFF);
869 regcache_cache_only(alc5623->regmap, true);
870
873 return 0; 871 return 0;
874} 872}
875 873
876static int alc5623_resume(struct snd_soc_codec *codec) 874static int alc5623_resume(struct snd_soc_codec *codec)
877{ 875{
878 int i, step = codec->driver->reg_cache_step; 876 struct alc5623_priv *alc5623 = snd_soc_codec_get_drvdata(codec);
879 u16 *cache = codec->reg_cache; 877 int ret;
880 878
881 /* Sync reg_cache with the hardware */ 879 /* Sync reg_cache with the hardware */
882 for (i = 2 ; i < codec->driver->reg_cache_size ; i += step) 880 regcache_cache_only(alc5623->regmap, false);
883 snd_soc_write(codec, i, cache[i]); 881 ret = regcache_sync(alc5623->regmap);
882 if (ret != 0) {
883 dev_err(codec->dev, "Failed to sync register cache: %d\n",
884 ret);
885 regcache_cache_only(alc5623->regmap, true);
886 return ret;
887 }
884 888
885 alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 889 alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
886 890
@@ -900,14 +904,7 @@ static int alc5623_probe(struct snd_soc_codec *codec)
900 struct snd_soc_dapm_context *dapm = &codec->dapm; 904 struct snd_soc_dapm_context *dapm = &codec->dapm;
901 int ret; 905 int ret;
902 906
903 ret = snd_soc_codec_set_cache_io(codec, 8, 16, alc5623->control_type);
904 if (ret < 0) {
905 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
906 return ret;
907 }
908
909 alc5623_reset(codec); 907 alc5623_reset(codec);
910 alc5623_fill_cache(codec);
911 908
912 /* power on device */ 909 /* power on device */
913 alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 910 alc5623_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
@@ -980,9 +977,15 @@ static struct snd_soc_codec_driver soc_codec_device_alc5623 = {
980 .suspend = alc5623_suspend, 977 .suspend = alc5623_suspend,
981 .resume = alc5623_resume, 978 .resume = alc5623_resume,
982 .set_bias_level = alc5623_set_bias_level, 979 .set_bias_level = alc5623_set_bias_level,
983 .reg_cache_size = ALC5623_VENDOR_ID2+2, 980};
984 .reg_word_size = sizeof(u16), 981
985 .reg_cache_step = 2, 982static const struct regmap_config alc5623_regmap = {
983 .reg_bits = 8,
984 .val_bits = 16,
985 .reg_stride = 2,
986
987 .max_register = ALC5623_VENDOR_ID2,
988 .cache_type = REGCACHE_RBTREE,
986}; 989};
987 990
988/* 991/*
@@ -996,19 +999,32 @@ static int alc5623_i2c_probe(struct i2c_client *client,
996{ 999{
997 struct alc5623_platform_data *pdata; 1000 struct alc5623_platform_data *pdata;
998 struct alc5623_priv *alc5623; 1001 struct alc5623_priv *alc5623;
999 int ret, vid1, vid2; 1002 unsigned int vid1, vid2;
1003 int ret;
1000 1004
1001 vid1 = i2c_smbus_read_word_data(client, ALC5623_VENDOR_ID1); 1005 alc5623 = devm_kzalloc(&client->dev, sizeof(struct alc5623_priv),
1002 if (vid1 < 0) { 1006 GFP_KERNEL);
1003 dev_err(&client->dev, "failed to read I2C\n"); 1007 if (alc5623 == NULL)
1004 return -EIO; 1008 return -ENOMEM;
1009
1010 alc5623->regmap = devm_regmap_init_i2c(client, &alc5623_regmap);
1011 if (IS_ERR(alc5623->regmap)) {
1012 ret = PTR_ERR(alc5623->regmap);
1013 dev_err(&client->dev, "Failed to initialise I/O: %d\n", ret);
1014 return ret;
1015 }
1016
1017 ret = regmap_read(alc5623->regmap, ALC5623_VENDOR_ID1, &vid1);
1018 if (ret < 0) {
1019 dev_err(&client->dev, "failed to read vendor ID1: %d\n", ret);
1020 return ret;
1005 } 1021 }
1006 vid1 = ((vid1 & 0xff) << 8) | (vid1 >> 8); 1022 vid1 = ((vid1 & 0xff) << 8) | (vid1 >> 8);
1007 1023
1008 vid2 = i2c_smbus_read_byte_data(client, ALC5623_VENDOR_ID2); 1024 ret = regmap_read(alc5623->regmap, ALC5623_VENDOR_ID2, &vid2);
1009 if (vid2 < 0) { 1025 if (ret < 0) {
1010 dev_err(&client->dev, "failed to read I2C\n"); 1026 dev_err(&client->dev, "failed to read vendor ID2: %d\n", ret);
1011 return -EIO; 1027 return ret;
1012 } 1028 }
1013 1029
1014 if ((vid1 != 0x10ec) || (vid2 != id->driver_data)) { 1030 if ((vid1 != 0x10ec) || (vid2 != id->driver_data)) {
@@ -1021,11 +1037,6 @@ static int alc5623_i2c_probe(struct i2c_client *client,
1021 1037
1022 dev_dbg(&client->dev, "Found codec id : alc56%02x\n", vid2); 1038 dev_dbg(&client->dev, "Found codec id : alc56%02x\n", vid2);
1023 1039
1024 alc5623 = devm_kzalloc(&client->dev, sizeof(struct alc5623_priv),
1025 GFP_KERNEL);
1026 if (alc5623 == NULL)
1027 return -ENOMEM;
1028
1029 pdata = client->dev.platform_data; 1040 pdata = client->dev.platform_data;
1030 if (pdata) { 1041 if (pdata) {
1031 alc5623->add_ctrl = pdata->add_ctrl; 1042 alc5623->add_ctrl = pdata->add_ctrl;
@@ -1048,7 +1059,6 @@ static int alc5623_i2c_probe(struct i2c_client *client,
1048 } 1059 }
1049 1060
1050 i2c_set_clientdata(client, alc5623); 1061 i2c_set_clientdata(client, alc5623);
1051 alc5623->control_type = SND_SOC_I2C;
1052 1062
1053 ret = snd_soc_register_codec(&client->dev, 1063 ret = snd_soc_register_codec(&client->dev,
1054 &soc_codec_device_alc5623, &alc5623_dai, 1); 1064 &soc_codec_device_alc5623, &alc5623_dai, 1);
diff --git a/sound/soc/codecs/alc5632.c b/sound/soc/codecs/alc5632.c
index fb001c56cf8d..ec071a6306ef 100644
--- a/sound/soc/codecs/alc5632.c
+++ b/sound/soc/codecs/alc5632.c
@@ -293,51 +293,59 @@ static const char * const alc5632_i2s_out_sel[] = {
293 "ADC LR", "Voice Stereo Digital"}; 293 "ADC LR", "Voice Stereo Digital"};
294 294
295/* auxout output mux */ 295/* auxout output mux */
296static const struct soc_enum alc5632_aux_out_input_enum = 296static SOC_ENUM_SINGLE_DECL(alc5632_aux_out_input_enum,
297SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 6, 4, alc5632_aux_out_input_sel); 297 ALC5632_OUTPUT_MIXER_CTRL, 6,
298 alc5632_aux_out_input_sel);
298static const struct snd_kcontrol_new alc5632_auxout_mux_controls = 299static const struct snd_kcontrol_new alc5632_auxout_mux_controls =
299SOC_DAPM_ENUM("AuxOut Mux", alc5632_aux_out_input_enum); 300SOC_DAPM_ENUM("AuxOut Mux", alc5632_aux_out_input_enum);
300 301
301/* speaker output mux */ 302/* speaker output mux */
302static const struct soc_enum alc5632_spkout_input_enum = 303static SOC_ENUM_SINGLE_DECL(alc5632_spkout_input_enum,
303SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 10, 4, alc5632_spkout_input_sel); 304 ALC5632_OUTPUT_MIXER_CTRL, 10,
305 alc5632_spkout_input_sel);
304static const struct snd_kcontrol_new alc5632_spkout_mux_controls = 306static const struct snd_kcontrol_new alc5632_spkout_mux_controls =
305SOC_DAPM_ENUM("SpeakerOut Mux", alc5632_spkout_input_enum); 307SOC_DAPM_ENUM("SpeakerOut Mux", alc5632_spkout_input_enum);
306 308
307/* headphone left output mux */ 309/* headphone left output mux */
308static const struct soc_enum alc5632_hpl_out_input_enum = 310static SOC_ENUM_SINGLE_DECL(alc5632_hpl_out_input_enum,
309SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 9, 2, alc5632_hpl_out_input_sel); 311 ALC5632_OUTPUT_MIXER_CTRL, 9,
312 alc5632_hpl_out_input_sel);
310static const struct snd_kcontrol_new alc5632_hpl_out_mux_controls = 313static const struct snd_kcontrol_new alc5632_hpl_out_mux_controls =
311SOC_DAPM_ENUM("Left Headphone Mux", alc5632_hpl_out_input_enum); 314SOC_DAPM_ENUM("Left Headphone Mux", alc5632_hpl_out_input_enum);
312 315
313/* headphone right output mux */ 316/* headphone right output mux */
314static const struct soc_enum alc5632_hpr_out_input_enum = 317static SOC_ENUM_SINGLE_DECL(alc5632_hpr_out_input_enum,
315SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 8, 2, alc5632_hpr_out_input_sel); 318 ALC5632_OUTPUT_MIXER_CTRL, 8,
319 alc5632_hpr_out_input_sel);
316static const struct snd_kcontrol_new alc5632_hpr_out_mux_controls = 320static const struct snd_kcontrol_new alc5632_hpr_out_mux_controls =
317SOC_DAPM_ENUM("Right Headphone Mux", alc5632_hpr_out_input_enum); 321SOC_DAPM_ENUM("Right Headphone Mux", alc5632_hpr_out_input_enum);
318 322
319/* speaker output N select */ 323/* speaker output N select */
320static const struct soc_enum alc5632_spk_n_sour_enum = 324static SOC_ENUM_SINGLE_DECL(alc5632_spk_n_sour_enum,
321SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 14, 4, alc5632_spk_n_sour_sel); 325 ALC5632_OUTPUT_MIXER_CTRL, 14,
326 alc5632_spk_n_sour_sel);
322static const struct snd_kcontrol_new alc5632_spkoutn_mux_controls = 327static const struct snd_kcontrol_new alc5632_spkoutn_mux_controls =
323SOC_DAPM_ENUM("SpeakerOut N Mux", alc5632_spk_n_sour_enum); 328SOC_DAPM_ENUM("SpeakerOut N Mux", alc5632_spk_n_sour_enum);
324 329
325/* speaker amplifier */ 330/* speaker amplifier */
326static const char *alc5632_amp_names[] = {"AB Amp", "D Amp"}; 331static const char *alc5632_amp_names[] = {"AB Amp", "D Amp"};
327static const struct soc_enum alc5632_amp_enum = 332static SOC_ENUM_SINGLE_DECL(alc5632_amp_enum,
328 SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL, 13, 2, alc5632_amp_names); 333 ALC5632_OUTPUT_MIXER_CTRL, 13,
334 alc5632_amp_names);
329static const struct snd_kcontrol_new alc5632_amp_mux_controls = 335static const struct snd_kcontrol_new alc5632_amp_mux_controls =
330 SOC_DAPM_ENUM("AB-D Amp Mux", alc5632_amp_enum); 336 SOC_DAPM_ENUM("AB-D Amp Mux", alc5632_amp_enum);
331 337
332/* ADC output select */ 338/* ADC output select */
333static const struct soc_enum alc5632_adcr_func_enum = 339static SOC_ENUM_SINGLE_DECL(alc5632_adcr_func_enum,
334 SOC_ENUM_SINGLE(ALC5632_DAC_FUNC_SELECT, 5, 2, alc5632_adcr_func_sel); 340 ALC5632_DAC_FUNC_SELECT, 5,
341 alc5632_adcr_func_sel);
335static const struct snd_kcontrol_new alc5632_adcr_func_controls = 342static const struct snd_kcontrol_new alc5632_adcr_func_controls =
336 SOC_DAPM_ENUM("ADCR Mux", alc5632_adcr_func_enum); 343 SOC_DAPM_ENUM("ADCR Mux", alc5632_adcr_func_enum);
337 344
338/* I2S out select */ 345/* I2S out select */
339static const struct soc_enum alc5632_i2s_out_enum = 346static SOC_ENUM_SINGLE_DECL(alc5632_i2s_out_enum,
340 SOC_ENUM_SINGLE(ALC5632_I2S_OUT_CTL, 5, 2, alc5632_i2s_out_sel); 347 ALC5632_I2S_OUT_CTL, 5,
348 alc5632_i2s_out_sel);
341static const struct snd_kcontrol_new alc5632_i2s_out_controls = 349static const struct snd_kcontrol_new alc5632_i2s_out_controls =
342 SOC_DAPM_ENUM("I2SOut Mux", alc5632_i2s_out_enum); 350 SOC_DAPM_ENUM("I2SOut Mux", alc5632_i2s_out_enum);
343 351
@@ -1055,14 +1063,6 @@ static int alc5632_probe(struct snd_soc_codec *codec)
1055 struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec); 1063 struct alc5632_priv *alc5632 = snd_soc_codec_get_drvdata(codec);
1056 int ret; 1064 int ret;
1057 1065
1058 codec->control_data = alc5632->regmap;
1059
1060 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1061 if (ret != 0) {
1062 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1063 return ret;
1064 }
1065
1066 /* power on device */ 1066 /* power on device */
1067 alc5632_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1067 alc5632_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1068 1068
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index e4295fee8f13..29e198f57d4c 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -53,6 +53,14 @@
53#define ARIZONA_AIF_RX_ENABLES 0x1A 53#define ARIZONA_AIF_RX_ENABLES 0x1A
54#define ARIZONA_AIF_FORCE_WRITE 0x1B 54#define ARIZONA_AIF_FORCE_WRITE 0x1B
55 55
56#define ARIZONA_FLL_VCO_CORNER 141900000
57#define ARIZONA_FLL_MAX_FREF 13500000
58#define ARIZONA_FLL_MIN_FVCO 90000000
59#define ARIZONA_FLL_MAX_FRATIO 16
60#define ARIZONA_FLL_MAX_REFDIV 8
61#define ARIZONA_FLL_MIN_OUTDIV 2
62#define ARIZONA_FLL_MAX_OUTDIV 7
63
56#define arizona_fll_err(_fll, fmt, ...) \ 64#define arizona_fll_err(_fll, fmt, ...) \
57 dev_err(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__) 65 dev_err(_fll->arizona->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__)
58#define arizona_fll_warn(_fll, fmt, ...) \ 66#define arizona_fll_warn(_fll, fmt, ...) \
@@ -542,67 +550,76 @@ static const char *arizona_vol_ramp_text[] = {
542 "15ms/6dB", "30ms/6dB", 550 "15ms/6dB", "30ms/6dB",
543}; 551};
544 552
545const struct soc_enum arizona_in_vd_ramp = 553SOC_ENUM_SINGLE_DECL(arizona_in_vd_ramp,
546 SOC_ENUM_SINGLE(ARIZONA_INPUT_VOLUME_RAMP, 554 ARIZONA_INPUT_VOLUME_RAMP,
547 ARIZONA_IN_VD_RAMP_SHIFT, 7, arizona_vol_ramp_text); 555 ARIZONA_IN_VD_RAMP_SHIFT,
556 arizona_vol_ramp_text);
548EXPORT_SYMBOL_GPL(arizona_in_vd_ramp); 557EXPORT_SYMBOL_GPL(arizona_in_vd_ramp);
549 558
550const struct soc_enum arizona_in_vi_ramp = 559SOC_ENUM_SINGLE_DECL(arizona_in_vi_ramp,
551 SOC_ENUM_SINGLE(ARIZONA_INPUT_VOLUME_RAMP, 560 ARIZONA_INPUT_VOLUME_RAMP,
552 ARIZONA_IN_VI_RAMP_SHIFT, 7, arizona_vol_ramp_text); 561 ARIZONA_IN_VI_RAMP_SHIFT,
562 arizona_vol_ramp_text);
553EXPORT_SYMBOL_GPL(arizona_in_vi_ramp); 563EXPORT_SYMBOL_GPL(arizona_in_vi_ramp);
554 564
555const struct soc_enum arizona_out_vd_ramp = 565SOC_ENUM_SINGLE_DECL(arizona_out_vd_ramp,
556 SOC_ENUM_SINGLE(ARIZONA_OUTPUT_VOLUME_RAMP, 566 ARIZONA_OUTPUT_VOLUME_RAMP,
557 ARIZONA_OUT_VD_RAMP_SHIFT, 7, arizona_vol_ramp_text); 567 ARIZONA_OUT_VD_RAMP_SHIFT,
568 arizona_vol_ramp_text);
558EXPORT_SYMBOL_GPL(arizona_out_vd_ramp); 569EXPORT_SYMBOL_GPL(arizona_out_vd_ramp);
559 570
560const struct soc_enum arizona_out_vi_ramp = 571SOC_ENUM_SINGLE_DECL(arizona_out_vi_ramp,
561 SOC_ENUM_SINGLE(ARIZONA_OUTPUT_VOLUME_RAMP, 572 ARIZONA_OUTPUT_VOLUME_RAMP,
562 ARIZONA_OUT_VI_RAMP_SHIFT, 7, arizona_vol_ramp_text); 573 ARIZONA_OUT_VI_RAMP_SHIFT,
574 arizona_vol_ramp_text);
563EXPORT_SYMBOL_GPL(arizona_out_vi_ramp); 575EXPORT_SYMBOL_GPL(arizona_out_vi_ramp);
564 576
565static const char *arizona_lhpf_mode_text[] = { 577static const char *arizona_lhpf_mode_text[] = {
566 "Low-pass", "High-pass" 578 "Low-pass", "High-pass"
567}; 579};
568 580
569const struct soc_enum arizona_lhpf1_mode = 581SOC_ENUM_SINGLE_DECL(arizona_lhpf1_mode,
570 SOC_ENUM_SINGLE(ARIZONA_HPLPF1_1, ARIZONA_LHPF1_MODE_SHIFT, 2, 582 ARIZONA_HPLPF1_1,
571 arizona_lhpf_mode_text); 583 ARIZONA_LHPF1_MODE_SHIFT,
584 arizona_lhpf_mode_text);
572EXPORT_SYMBOL_GPL(arizona_lhpf1_mode); 585EXPORT_SYMBOL_GPL(arizona_lhpf1_mode);
573 586
574const struct soc_enum arizona_lhpf2_mode = 587SOC_ENUM_SINGLE_DECL(arizona_lhpf2_mode,
575 SOC_ENUM_SINGLE(ARIZONA_HPLPF2_1, ARIZONA_LHPF2_MODE_SHIFT, 2, 588 ARIZONA_HPLPF2_1,
576 arizona_lhpf_mode_text); 589 ARIZONA_LHPF2_MODE_SHIFT,
590 arizona_lhpf_mode_text);
577EXPORT_SYMBOL_GPL(arizona_lhpf2_mode); 591EXPORT_SYMBOL_GPL(arizona_lhpf2_mode);
578 592
579const struct soc_enum arizona_lhpf3_mode = 593SOC_ENUM_SINGLE_DECL(arizona_lhpf3_mode,
580 SOC_ENUM_SINGLE(ARIZONA_HPLPF3_1, ARIZONA_LHPF3_MODE_SHIFT, 2, 594 ARIZONA_HPLPF3_1,
581 arizona_lhpf_mode_text); 595 ARIZONA_LHPF3_MODE_SHIFT,
596 arizona_lhpf_mode_text);
582EXPORT_SYMBOL_GPL(arizona_lhpf3_mode); 597EXPORT_SYMBOL_GPL(arizona_lhpf3_mode);
583 598
584const struct soc_enum arizona_lhpf4_mode = 599SOC_ENUM_SINGLE_DECL(arizona_lhpf4_mode,
585 SOC_ENUM_SINGLE(ARIZONA_HPLPF4_1, ARIZONA_LHPF4_MODE_SHIFT, 2, 600 ARIZONA_HPLPF4_1,
586 arizona_lhpf_mode_text); 601 ARIZONA_LHPF4_MODE_SHIFT,
602 arizona_lhpf_mode_text);
587EXPORT_SYMBOL_GPL(arizona_lhpf4_mode); 603EXPORT_SYMBOL_GPL(arizona_lhpf4_mode);
588 604
589static const char *arizona_ng_hold_text[] = { 605static const char *arizona_ng_hold_text[] = {
590 "30ms", "120ms", "250ms", "500ms", 606 "30ms", "120ms", "250ms", "500ms",
591}; 607};
592 608
593const struct soc_enum arizona_ng_hold = 609SOC_ENUM_SINGLE_DECL(arizona_ng_hold,
594 SOC_ENUM_SINGLE(ARIZONA_NOISE_GATE_CONTROL, ARIZONA_NGATE_HOLD_SHIFT, 610 ARIZONA_NOISE_GATE_CONTROL,
595 4, arizona_ng_hold_text); 611 ARIZONA_NGATE_HOLD_SHIFT,
612 arizona_ng_hold_text);
596EXPORT_SYMBOL_GPL(arizona_ng_hold); 613EXPORT_SYMBOL_GPL(arizona_ng_hold);
597 614
598static const char * const arizona_in_hpf_cut_text[] = { 615static const char * const arizona_in_hpf_cut_text[] = {
599 "2.5Hz", "5Hz", "10Hz", "20Hz", "40Hz" 616 "2.5Hz", "5Hz", "10Hz", "20Hz", "40Hz"
600}; 617};
601 618
602const struct soc_enum arizona_in_hpf_cut_enum = 619SOC_ENUM_SINGLE_DECL(arizona_in_hpf_cut_enum,
603 SOC_ENUM_SINGLE(ARIZONA_HPF_CONTROL, ARIZONA_IN_HPF_CUT_SHIFT, 620 ARIZONA_HPF_CONTROL,
604 ARRAY_SIZE(arizona_in_hpf_cut_text), 621 ARIZONA_IN_HPF_CUT_SHIFT,
605 arizona_in_hpf_cut_text); 622 arizona_in_hpf_cut_text);
606EXPORT_SYMBOL_GPL(arizona_in_hpf_cut_enum); 623EXPORT_SYMBOL_GPL(arizona_in_hpf_cut_enum);
607 624
608static const char * const arizona_in_dmic_osr_text[] = { 625static const char * const arizona_in_dmic_osr_text[] = {
@@ -1377,74 +1394,147 @@ struct arizona_fll_cfg {
1377 int gain; 1394 int gain;
1378}; 1395};
1379 1396
1380static int arizona_calc_fll(struct arizona_fll *fll, 1397static int arizona_validate_fll(struct arizona_fll *fll,
1381 struct arizona_fll_cfg *cfg, 1398 unsigned int Fref,
1382 unsigned int Fref, 1399 unsigned int Fout)
1383 unsigned int Fout)
1384{ 1400{
1385 unsigned int target, div, gcd_fll; 1401 unsigned int Fvco_min;
1386 int i, ratio; 1402
1403 if (Fref / ARIZONA_FLL_MAX_REFDIV > ARIZONA_FLL_MAX_FREF) {
1404 arizona_fll_err(fll,
1405 "Can't scale %dMHz in to <=13.5MHz\n",
1406 Fref);
1407 return -EINVAL;
1408 }
1387 1409
1388 arizona_fll_dbg(fll, "Fref=%u Fout=%u\n", Fref, Fout); 1410 Fvco_min = ARIZONA_FLL_MIN_FVCO * fll->vco_mult;
1411 if (Fout * ARIZONA_FLL_MAX_OUTDIV < Fvco_min) {
1412 arizona_fll_err(fll, "No FLL_OUTDIV for Fout=%uHz\n",
1413 Fout);
1414 return -EINVAL;
1415 }
1416
1417 return 0;
1418}
1419
1420static int arizona_find_fratio(unsigned int Fref, int *fratio)
1421{
1422 int i;
1423
1424 /* Find an appropriate FLL_FRATIO */
1425 for (i = 0; i < ARRAY_SIZE(fll_fratios); i++) {
1426 if (fll_fratios[i].min <= Fref && Fref <= fll_fratios[i].max) {
1427 if (fratio)
1428 *fratio = fll_fratios[i].fratio;
1429 return fll_fratios[i].ratio;
1430 }
1431 }
1432
1433 return -EINVAL;
1434}
1435
1436static int arizona_calc_fratio(struct arizona_fll *fll,
1437 struct arizona_fll_cfg *cfg,
1438 unsigned int target,
1439 unsigned int Fref, bool sync)
1440{
1441 int init_ratio, ratio;
1442 int refdiv, div;
1389 1443
1390 /* Fref must be <=13.5MHz */ 1444 /* Fref must be <=13.5MHz, find initial refdiv */
1391 div = 1; 1445 div = 1;
1392 cfg->refdiv = 0; 1446 cfg->refdiv = 0;
1393 while ((Fref / div) > 13500000) { 1447 while (Fref > ARIZONA_FLL_MAX_FREF) {
1394 div *= 2; 1448 div *= 2;
1449 Fref /= 2;
1395 cfg->refdiv++; 1450 cfg->refdiv++;
1396 1451
1397 if (div > 8) { 1452 if (div > ARIZONA_FLL_MAX_REFDIV)
1398 arizona_fll_err(fll,
1399 "Can't scale %dMHz in to <=13.5MHz\n",
1400 Fref);
1401 return -EINVAL; 1453 return -EINVAL;
1454 }
1455
1456 /* Find an appropriate FLL_FRATIO */
1457 init_ratio = arizona_find_fratio(Fref, &cfg->fratio);
1458 if (init_ratio < 0) {
1459 arizona_fll_err(fll, "Unable to find FRATIO for Fref=%uHz\n",
1460 Fref);
1461 return init_ratio;
1462 }
1463
1464 switch (fll->arizona->type) {
1465 case WM5110:
1466 if (fll->arizona->rev < 3 || sync)
1467 return init_ratio;
1468 break;
1469 default:
1470 return init_ratio;
1471 }
1472
1473 cfg->fratio = init_ratio - 1;
1474
1475 /* Adjust FRATIO/refdiv to avoid integer mode if possible */
1476 refdiv = cfg->refdiv;
1477
1478 while (div <= ARIZONA_FLL_MAX_REFDIV) {
1479 for (ratio = init_ratio; ratio <= ARIZONA_FLL_MAX_FRATIO;
1480 ratio++) {
1481 if (target % (ratio * Fref)) {
1482 cfg->refdiv = refdiv;
1483 cfg->fratio = ratio - 1;
1484 return ratio;
1485 }
1402 } 1486 }
1487
1488 for (ratio = init_ratio - 1; ratio >= 0; ratio--) {
1489 if (ARIZONA_FLL_VCO_CORNER / (fll->vco_mult * ratio) <
1490 Fref)
1491 break;
1492
1493 if (target % (ratio * Fref)) {
1494 cfg->refdiv = refdiv;
1495 cfg->fratio = ratio - 1;
1496 return ratio;
1497 }
1498 }
1499
1500 div *= 2;
1501 Fref /= 2;
1502 refdiv++;
1503 init_ratio = arizona_find_fratio(Fref, NULL);
1403 } 1504 }
1404 1505
1405 /* Apply the division for our remaining calculations */ 1506 arizona_fll_warn(fll, "Falling back to integer mode operation\n");
1406 Fref /= div; 1507 return cfg->fratio + 1;
1508}
1509
1510static int arizona_calc_fll(struct arizona_fll *fll,
1511 struct arizona_fll_cfg *cfg,
1512 unsigned int Fref, bool sync)
1513{
1514 unsigned int target, div, gcd_fll;
1515 int i, ratio;
1516
1517 arizona_fll_dbg(fll, "Fref=%u Fout=%u\n", Fref, fll->fout);
1407 1518
1408 /* Fvco should be over the targt; don't check the upper bound */ 1519 /* Fvco should be over the targt; don't check the upper bound */
1409 div = 1; 1520 div = ARIZONA_FLL_MIN_OUTDIV;
1410 while (Fout * div < 90000000 * fll->vco_mult) { 1521 while (fll->fout * div < ARIZONA_FLL_MIN_FVCO * fll->vco_mult) {
1411 div++; 1522 div++;
1412 if (div > 7) { 1523 if (div > ARIZONA_FLL_MAX_OUTDIV)
1413 arizona_fll_err(fll, "No FLL_OUTDIV for Fout=%uHz\n",
1414 Fout);
1415 return -EINVAL; 1524 return -EINVAL;
1416 }
1417 } 1525 }
1418 target = Fout * div / fll->vco_mult; 1526 target = fll->fout * div / fll->vco_mult;
1419 cfg->outdiv = div; 1527 cfg->outdiv = div;
1420 1528
1421 arizona_fll_dbg(fll, "Fvco=%dHz\n", target); 1529 arizona_fll_dbg(fll, "Fvco=%dHz\n", target);
1422 1530
1423 /* Find an appropraite FLL_FRATIO and factor it out of the target */ 1531 /* Find an appropriate FLL_FRATIO and refdiv */
1424 for (i = 0; i < ARRAY_SIZE(fll_fratios); i++) { 1532 ratio = arizona_calc_fratio(fll, cfg, target, Fref, sync);
1425 if (fll_fratios[i].min <= Fref && Fref <= fll_fratios[i].max) { 1533 if (ratio < 0)
1426 cfg->fratio = fll_fratios[i].fratio; 1534 return ratio;
1427 ratio = fll_fratios[i].ratio;
1428 break;
1429 }
1430 }
1431 if (i == ARRAY_SIZE(fll_fratios)) {
1432 arizona_fll_err(fll, "Unable to find FRATIO for Fref=%uHz\n",
1433 Fref);
1434 return -EINVAL;
1435 }
1436 1535
1437 for (i = 0; i < ARRAY_SIZE(fll_gains); i++) { 1536 /* Apply the division for our remaining calculations */
1438 if (fll_gains[i].min <= Fref && Fref <= fll_gains[i].max) { 1537 Fref = Fref / (1 << cfg->refdiv);
1439 cfg->gain = fll_gains[i].gain;
1440 break;
1441 }
1442 }
1443 if (i == ARRAY_SIZE(fll_gains)) {
1444 arizona_fll_err(fll, "Unable to find gain for Fref=%uHz\n",
1445 Fref);
1446 return -EINVAL;
1447 }
1448 1538
1449 cfg->n = target / (ratio * Fref); 1539 cfg->n = target / (ratio * Fref);
1450 1540
@@ -1469,6 +1559,18 @@ static int arizona_calc_fll(struct arizona_fll *fll,
1469 cfg->lambda >>= 1; 1559 cfg->lambda >>= 1;
1470 } 1560 }
1471 1561
1562 for (i = 0; i < ARRAY_SIZE(fll_gains); i++) {
1563 if (fll_gains[i].min <= Fref && Fref <= fll_gains[i].max) {
1564 cfg->gain = fll_gains[i].gain;
1565 break;
1566 }
1567 }
1568 if (i == ARRAY_SIZE(fll_gains)) {
1569 arizona_fll_err(fll, "Unable to find gain for Fref=%uHz\n",
1570 Fref);
1571 return -EINVAL;
1572 }
1573
1472 arizona_fll_dbg(fll, "N=%x THETA=%x LAMBDA=%x\n", 1574 arizona_fll_dbg(fll, "N=%x THETA=%x LAMBDA=%x\n",
1473 cfg->n, cfg->theta, cfg->lambda); 1575 cfg->n, cfg->theta, cfg->lambda);
1474 arizona_fll_dbg(fll, "FRATIO=%x(%d) OUTDIV=%x REFCLK_DIV=%x\n", 1576 arizona_fll_dbg(fll, "FRATIO=%x(%d) OUTDIV=%x REFCLK_DIV=%x\n",
@@ -1496,14 +1598,18 @@ static void arizona_apply_fll(struct arizona *arizona, unsigned int base,
1496 cfg->refdiv << ARIZONA_FLL1_CLK_REF_DIV_SHIFT | 1598 cfg->refdiv << ARIZONA_FLL1_CLK_REF_DIV_SHIFT |
1497 source << ARIZONA_FLL1_CLK_REF_SRC_SHIFT); 1599 source << ARIZONA_FLL1_CLK_REF_SRC_SHIFT);
1498 1600
1499 if (sync) 1601 if (sync) {
1500 regmap_update_bits_async(arizona->regmap, base + 0x7, 1602 regmap_update_bits(arizona->regmap, base + 0x7,
1501 ARIZONA_FLL1_GAIN_MASK, 1603 ARIZONA_FLL1_GAIN_MASK,
1502 cfg->gain << ARIZONA_FLL1_GAIN_SHIFT); 1604 cfg->gain << ARIZONA_FLL1_GAIN_SHIFT);
1503 else 1605 } else {
1504 regmap_update_bits_async(arizona->regmap, base + 0x9, 1606 regmap_update_bits(arizona->regmap, base + 0x5,
1505 ARIZONA_FLL1_GAIN_MASK, 1607 ARIZONA_FLL1_OUTDIV_MASK,
1506 cfg->gain << ARIZONA_FLL1_GAIN_SHIFT); 1608 cfg->outdiv << ARIZONA_FLL1_OUTDIV_SHIFT);
1609 regmap_update_bits(arizona->regmap, base + 0x9,
1610 ARIZONA_FLL1_GAIN_MASK,
1611 cfg->gain << ARIZONA_FLL1_GAIN_SHIFT);
1612 }
1507 1613
1508 regmap_update_bits_async(arizona->regmap, base + 2, 1614 regmap_update_bits_async(arizona->regmap, base + 2,
1509 ARIZONA_FLL1_CTRL_UPD | ARIZONA_FLL1_N_MASK, 1615 ARIZONA_FLL1_CTRL_UPD | ARIZONA_FLL1_N_MASK,
@@ -1526,13 +1632,12 @@ static bool arizona_is_enabled_fll(struct arizona_fll *fll)
1526 return reg & ARIZONA_FLL1_ENA; 1632 return reg & ARIZONA_FLL1_ENA;
1527} 1633}
1528 1634
1529static void arizona_enable_fll(struct arizona_fll *fll, 1635static void arizona_enable_fll(struct arizona_fll *fll)
1530 struct arizona_fll_cfg *ref,
1531 struct arizona_fll_cfg *sync)
1532{ 1636{
1533 struct arizona *arizona = fll->arizona; 1637 struct arizona *arizona = fll->arizona;
1534 int ret; 1638 int ret;
1535 bool use_sync = false; 1639 bool use_sync = false;
1640 struct arizona_fll_cfg cfg;
1536 1641
1537 /* 1642 /*
1538 * If we have both REFCLK and SYNCCLK then enable both, 1643 * If we have both REFCLK and SYNCCLK then enable both,
@@ -1540,23 +1645,21 @@ static void arizona_enable_fll(struct arizona_fll *fll,
1540 */ 1645 */
1541 if (fll->ref_src >= 0 && fll->ref_freq && 1646 if (fll->ref_src >= 0 && fll->ref_freq &&
1542 fll->ref_src != fll->sync_src) { 1647 fll->ref_src != fll->sync_src) {
1543 regmap_update_bits_async(arizona->regmap, fll->base + 5, 1648 arizona_calc_fll(fll, &cfg, fll->ref_freq, false);
1544 ARIZONA_FLL1_OUTDIV_MASK,
1545 ref->outdiv << ARIZONA_FLL1_OUTDIV_SHIFT);
1546 1649
1547 arizona_apply_fll(arizona, fll->base, ref, fll->ref_src, 1650 arizona_apply_fll(arizona, fll->base, &cfg, fll->ref_src,
1548 false); 1651 false);
1549 if (fll->sync_src >= 0) { 1652 if (fll->sync_src >= 0) {
1550 arizona_apply_fll(arizona, fll->base + 0x10, sync, 1653 arizona_calc_fll(fll, &cfg, fll->sync_freq, true);
1654
1655 arizona_apply_fll(arizona, fll->base + 0x10, &cfg,
1551 fll->sync_src, true); 1656 fll->sync_src, true);
1552 use_sync = true; 1657 use_sync = true;
1553 } 1658 }
1554 } else if (fll->sync_src >= 0) { 1659 } else if (fll->sync_src >= 0) {
1555 regmap_update_bits_async(arizona->regmap, fll->base + 5, 1660 arizona_calc_fll(fll, &cfg, fll->sync_freq, false);
1556 ARIZONA_FLL1_OUTDIV_MASK,
1557 sync->outdiv << ARIZONA_FLL1_OUTDIV_SHIFT);
1558 1661
1559 arizona_apply_fll(arizona, fll->base, sync, 1662 arizona_apply_fll(arizona, fll->base, &cfg,
1560 fll->sync_src, false); 1663 fll->sync_src, false);
1561 1664
1562 regmap_update_bits_async(arizona->regmap, fll->base + 0x11, 1665 regmap_update_bits_async(arizona->regmap, fll->base + 0x11,
@@ -1618,32 +1721,22 @@ static void arizona_disable_fll(struct arizona_fll *fll)
1618int arizona_set_fll_refclk(struct arizona_fll *fll, int source, 1721int arizona_set_fll_refclk(struct arizona_fll *fll, int source,
1619 unsigned int Fref, unsigned int Fout) 1722 unsigned int Fref, unsigned int Fout)
1620{ 1723{
1621 struct arizona_fll_cfg ref, sync;
1622 int ret; 1724 int ret;
1623 1725
1624 if (fll->ref_src == source && fll->ref_freq == Fref) 1726 if (fll->ref_src == source && fll->ref_freq == Fref)
1625 return 0; 1727 return 0;
1626 1728
1627 if (fll->fout) { 1729 if (fll->fout && Fref > 0) {
1628 if (Fref > 0) { 1730 ret = arizona_validate_fll(fll, Fref, fll->fout);
1629 ret = arizona_calc_fll(fll, &ref, Fref, fll->fout); 1731 if (ret != 0)
1630 if (ret != 0) 1732 return ret;
1631 return ret;
1632 }
1633
1634 if (fll->sync_src >= 0) {
1635 ret = arizona_calc_fll(fll, &sync, fll->sync_freq,
1636 fll->fout);
1637 if (ret != 0)
1638 return ret;
1639 }
1640 } 1733 }
1641 1734
1642 fll->ref_src = source; 1735 fll->ref_src = source;
1643 fll->ref_freq = Fref; 1736 fll->ref_freq = Fref;
1644 1737
1645 if (fll->fout && Fref > 0) { 1738 if (fll->fout && Fref > 0) {
1646 arizona_enable_fll(fll, &ref, &sync); 1739 arizona_enable_fll(fll);
1647 } 1740 }
1648 1741
1649 return 0; 1742 return 0;
@@ -1653,7 +1746,6 @@ EXPORT_SYMBOL_GPL(arizona_set_fll_refclk);
1653int arizona_set_fll(struct arizona_fll *fll, int source, 1746int arizona_set_fll(struct arizona_fll *fll, int source,
1654 unsigned int Fref, unsigned int Fout) 1747 unsigned int Fref, unsigned int Fout)
1655{ 1748{
1656 struct arizona_fll_cfg ref, sync;
1657 int ret; 1749 int ret;
1658 1750
1659 if (fll->sync_src == source && 1751 if (fll->sync_src == source &&
@@ -1662,13 +1754,12 @@ int arizona_set_fll(struct arizona_fll *fll, int source,
1662 1754
1663 if (Fout) { 1755 if (Fout) {
1664 if (fll->ref_src >= 0) { 1756 if (fll->ref_src >= 0) {
1665 ret = arizona_calc_fll(fll, &ref, fll->ref_freq, 1757 ret = arizona_validate_fll(fll, fll->ref_freq, Fout);
1666 Fout);
1667 if (ret != 0) 1758 if (ret != 0)
1668 return ret; 1759 return ret;
1669 } 1760 }
1670 1761
1671 ret = arizona_calc_fll(fll, &sync, Fref, Fout); 1762 ret = arizona_validate_fll(fll, Fref, Fout);
1672 if (ret != 0) 1763 if (ret != 0)
1673 return ret; 1764 return ret;
1674 } 1765 }
@@ -1678,7 +1769,7 @@ int arizona_set_fll(struct arizona_fll *fll, int source,
1678 fll->fout = Fout; 1769 fll->fout = Fout;
1679 1770
1680 if (Fout) { 1771 if (Fout) {
1681 arizona_enable_fll(fll, &ref, &sync); 1772 arizona_enable_fll(fll);
1682 } else { 1773 } else {
1683 arizona_disable_fll(fll); 1774 arizona_disable_fll(fll);
1684 } 1775 }
diff --git a/sound/soc/codecs/cq93vc.c b/sound/soc/codecs/cq93vc.c
index 43737a27d79c..1e25c7af853b 100644
--- a/sound/soc/codecs/cq93vc.c
+++ b/sound/soc/codecs/cq93vc.c
@@ -138,9 +138,8 @@ static int cq93vc_probe(struct snd_soc_codec *codec)
138 struct davinci_vc *davinci_vc = codec->dev->platform_data; 138 struct davinci_vc *davinci_vc = codec->dev->platform_data;
139 139
140 davinci_vc->cq93vc.codec = codec; 140 davinci_vc->cq93vc.codec = codec;
141 codec->control_data = davinci_vc->regmap;
142 141
143 snd_soc_codec_set_cache_io(codec, 32, 32, SND_SOC_REGMAP); 142 snd_soc_codec_set_cache_io(codec, davinci_vc->regmap);
144 143
145 /* Off, with power on */ 144 /* Off, with power on */
146 cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 145 cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index 83c835d9fd88..3920e6264948 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -506,15 +506,6 @@ static int cs4270_probe(struct snd_soc_codec *codec)
506 struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec); 506 struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
507 int ret; 507 int ret;
508 508
509 /* Tell ASoC what kind of I/O to use to read the registers. ASoC will
510 * then do the I2C transactions itself.
511 */
512 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
513 if (ret < 0) {
514 dev_err(codec->dev, "failed to set cache I/O (ret=%i)\n", ret);
515 return ret;
516 }
517
518 /* Disable auto-mute. This feature appears to be buggy. In some 509 /* Disable auto-mute. This feature appears to be buggy. In some
519 * situations, auto-mute will not deactivate when it should, so we want 510 * situations, auto-mute will not deactivate when it should, so we want
520 * this feature disabled by default. An application (e.g. alsactl) can 511 * this feature disabled by default. An application (e.g. alsactl) can
diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c
index ce05fd93dc74..aef4965750c7 100644
--- a/sound/soc/codecs/cs4271.c
+++ b/sound/soc/codecs/cs4271.c
@@ -159,7 +159,6 @@ static bool cs4271_volatile_reg(struct device *dev, unsigned int reg)
159} 159}
160 160
161struct cs4271_private { 161struct cs4271_private {
162 /* SND_SOC_I2C or SND_SOC_SPI */
163 unsigned int mclk; 162 unsigned int mclk;
164 bool master; 163 bool master;
165 bool deemph; 164 bool deemph;
@@ -540,14 +539,10 @@ static int cs4271_probe(struct snd_soc_codec *codec)
540 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); 539 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec);
541 struct cs4271_platform_data *cs4271plat = codec->dev->platform_data; 540 struct cs4271_platform_data *cs4271plat = codec->dev->platform_data;
542 int ret; 541 int ret;
543 int gpio_nreset = -EINVAL;
544 bool amutec_eq_bmutec = false; 542 bool amutec_eq_bmutec = false;
545 543
546#ifdef CONFIG_OF 544#ifdef CONFIG_OF
547 if (of_match_device(cs4271_dt_ids, codec->dev)) { 545 if (of_match_device(cs4271_dt_ids, codec->dev)) {
548 gpio_nreset = of_get_named_gpio(codec->dev->of_node,
549 "reset-gpio", 0);
550
551 if (of_get_property(codec->dev->of_node, 546 if (of_get_property(codec->dev->of_node,
552 "cirrus,amutec-eq-bmutec", NULL)) 547 "cirrus,amutec-eq-bmutec", NULL))
553 amutec_eq_bmutec = true; 548 amutec_eq_bmutec = true;
@@ -559,27 +554,19 @@ static int cs4271_probe(struct snd_soc_codec *codec)
559#endif 554#endif
560 555
561 if (cs4271plat) { 556 if (cs4271plat) {
562 if (gpio_is_valid(cs4271plat->gpio_nreset))
563 gpio_nreset = cs4271plat->gpio_nreset;
564
565 amutec_eq_bmutec = cs4271plat->amutec_eq_bmutec; 557 amutec_eq_bmutec = cs4271plat->amutec_eq_bmutec;
566 cs4271->enable_soft_reset = cs4271plat->enable_soft_reset; 558 cs4271->enable_soft_reset = cs4271plat->enable_soft_reset;
567 } 559 }
568 560
569 if (gpio_nreset >= 0) 561 if (gpio_is_valid(cs4271->gpio_nreset)) {
570 if (devm_gpio_request(codec->dev, gpio_nreset, "CS4271 Reset"))
571 gpio_nreset = -EINVAL;
572 if (gpio_nreset >= 0) {
573 /* Reset codec */ 562 /* Reset codec */
574 gpio_direction_output(gpio_nreset, 0); 563 gpio_direction_output(cs4271->gpio_nreset, 0);
575 udelay(1); 564 udelay(1);
576 gpio_set_value(gpio_nreset, 1); 565 gpio_set_value(cs4271->gpio_nreset, 1);
577 /* Give the codec time to wake up */ 566 /* Give the codec time to wake up */
578 udelay(1); 567 udelay(1);
579 } 568 }
580 569
581 cs4271->gpio_nreset = gpio_nreset;
582
583 ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, 570 ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2,
584 CS4271_MODE2_PDN | CS4271_MODE2_CPEN, 571 CS4271_MODE2_PDN | CS4271_MODE2_CPEN,
585 CS4271_MODE2_PDN | CS4271_MODE2_CPEN); 572 CS4271_MODE2_PDN | CS4271_MODE2_CPEN);
@@ -625,6 +612,36 @@ static struct snd_soc_codec_driver soc_codec_dev_cs4271 = {
625 .num_dapm_routes = ARRAY_SIZE(cs4271_dapm_routes), 612 .num_dapm_routes = ARRAY_SIZE(cs4271_dapm_routes),
626}; 613};
627 614
615static int cs4271_common_probe(struct device *dev,
616 struct cs4271_private **c)
617{
618 struct cs4271_platform_data *cs4271plat = dev->platform_data;
619 struct cs4271_private *cs4271;
620
621 cs4271 = devm_kzalloc(dev, sizeof(*cs4271), GFP_KERNEL);
622 if (!cs4271)
623 return -ENOMEM;
624
625 if (of_match_device(cs4271_dt_ids, dev))
626 cs4271->gpio_nreset =
627 of_get_named_gpio(dev->of_node, "reset-gpio", 0);
628
629 if (cs4271plat)
630 cs4271->gpio_nreset = cs4271plat->gpio_nreset;
631
632 if (gpio_is_valid(cs4271->gpio_nreset)) {
633 int ret;
634
635 ret = devm_gpio_request(dev, cs4271->gpio_nreset,
636 "CS4271 Reset");
637 if (ret < 0)
638 return ret;
639 }
640
641 *c = cs4271;
642 return 0;
643}
644
628#if defined(CONFIG_SPI_MASTER) 645#if defined(CONFIG_SPI_MASTER)
629 646
630static const struct regmap_config cs4271_spi_regmap = { 647static const struct regmap_config cs4271_spi_regmap = {
@@ -644,10 +661,11 @@ static const struct regmap_config cs4271_spi_regmap = {
644static int cs4271_spi_probe(struct spi_device *spi) 661static int cs4271_spi_probe(struct spi_device *spi)
645{ 662{
646 struct cs4271_private *cs4271; 663 struct cs4271_private *cs4271;
664 int ret;
647 665
648 cs4271 = devm_kzalloc(&spi->dev, sizeof(*cs4271), GFP_KERNEL); 666 ret = cs4271_common_probe(&spi->dev, &cs4271);
649 if (!cs4271) 667 if (ret < 0)
650 return -ENOMEM; 668 return ret;
651 669
652 spi_set_drvdata(spi, cs4271); 670 spi_set_drvdata(spi, cs4271);
653 cs4271->regmap = devm_regmap_init_spi(spi, &cs4271_spi_regmap); 671 cs4271->regmap = devm_regmap_init_spi(spi, &cs4271_spi_regmap);
@@ -698,10 +716,11 @@ static int cs4271_i2c_probe(struct i2c_client *client,
698 const struct i2c_device_id *id) 716 const struct i2c_device_id *id)
699{ 717{
700 struct cs4271_private *cs4271; 718 struct cs4271_private *cs4271;
719 int ret;
701 720
702 cs4271 = devm_kzalloc(&client->dev, sizeof(*cs4271), GFP_KERNEL); 721 ret = cs4271_common_probe(&client->dev, &cs4271);
703 if (!cs4271) 722 if (ret < 0)
704 return -ENOMEM; 723 return ret;
705 724
706 i2c_set_clientdata(client, cs4271); 725 i2c_set_clientdata(client, cs4271);
707 cs4271->regmap = devm_regmap_init_i2c(client, &cs4271_i2c_regmap); 726 cs4271->regmap = devm_regmap_init_i2c(client, &cs4271_i2c_regmap);
diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c
index 6e9ea8379a91..6c0da2baa154 100644
--- a/sound/soc/codecs/cs42l51.c
+++ b/sound/soc/codecs/cs42l51.c
@@ -30,6 +30,7 @@
30#include <sound/pcm_params.h> 30#include <sound/pcm_params.h>
31#include <sound/pcm.h> 31#include <sound/pcm.h>
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/regmap.h>
33 34
34#include "cs42l51.h" 35#include "cs42l51.h"
35 36
@@ -40,7 +41,6 @@ enum master_slave_mode {
40}; 41};
41 42
42struct cs42l51_private { 43struct cs42l51_private {
43 enum snd_soc_control_type control_type;
44 unsigned int mclk; 44 unsigned int mclk;
45 unsigned int audio_mode; /* The mode (I2S or left-justified) */ 45 unsigned int audio_mode; /* The mode (I2S or left-justified) */
46 enum master_slave_mode func; 46 enum master_slave_mode func;
@@ -52,24 +52,6 @@ struct cs42l51_private {
52 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \ 52 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
53 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) 53 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
54 54
55static int cs42l51_fill_cache(struct snd_soc_codec *codec)
56{
57 u8 *cache = codec->reg_cache + 1;
58 struct i2c_client *i2c_client = to_i2c_client(codec->dev);
59 s32 length;
60
61 length = i2c_smbus_read_i2c_block_data(i2c_client,
62 CS42L51_FIRSTREG | 0x80, CS42L51_NUMREGS, cache);
63 if (length != CS42L51_NUMREGS) {
64 dev_err(&i2c_client->dev,
65 "I2C read failure, addr=0x%x (ret=%d vs %d)\n",
66 i2c_client->addr, length, CS42L51_NUMREGS);
67 return -EIO;
68 }
69
70 return 0;
71}
72
73static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol, 55static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol,
74 struct snd_ctl_elem_value *ucontrol) 56 struct snd_ctl_elem_value *ucontrol)
75{ 57{
@@ -124,9 +106,8 @@ static int cs42l51_set_chan_mix(struct snd_kcontrol *kcontrol,
124 106
125static const DECLARE_TLV_DB_SCALE(adc_pcm_tlv, -5150, 50, 0); 107static const DECLARE_TLV_DB_SCALE(adc_pcm_tlv, -5150, 50, 0);
126static const DECLARE_TLV_DB_SCALE(tone_tlv, -1050, 150, 0); 108static const DECLARE_TLV_DB_SCALE(tone_tlv, -1050, 150, 0);
127/* This is a lie. after -102 db, it stays at -102 */ 109
128/* maybe a range would be better */ 110static const DECLARE_TLV_DB_SCALE(aout_tlv, -10200, 50, 0);
129static const DECLARE_TLV_DB_SCALE(aout_tlv, -11550, 50, 0);
130 111
131static const DECLARE_TLV_DB_SCALE(boost_tlv, 1600, 1600, 0); 112static const DECLARE_TLV_DB_SCALE(boost_tlv, 1600, 1600, 0);
132static const char *chan_mix[] = { 113static const char *chan_mix[] = {
@@ -135,13 +116,12 @@ static const char *chan_mix[] = {
135 "R L", 116 "R L",
136}; 117};
137 118
138static const struct soc_enum cs42l51_chan_mix = 119static SOC_ENUM_SINGLE_EXT_DECL(cs42l51_chan_mix, chan_mix);
139 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(chan_mix), chan_mix);
140 120
141static const struct snd_kcontrol_new cs42l51_snd_controls[] = { 121static const struct snd_kcontrol_new cs42l51_snd_controls[] = {
142 SOC_DOUBLE_R_SX_TLV("PCM Playback Volume", 122 SOC_DOUBLE_R_SX_TLV("PCM Playback Volume",
143 CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, 123 CS42L51_PCMA_VOL, CS42L51_PCMB_VOL,
144 6, 0x19, 0x7F, adc_pcm_tlv), 124 0, 0x19, 0x7F, adc_pcm_tlv),
145 SOC_DOUBLE_R("PCM Playback Switch", 125 SOC_DOUBLE_R("PCM Playback Switch",
146 CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, 7, 1, 1), 126 CS42L51_PCMA_VOL, CS42L51_PCMB_VOL, 7, 1, 1),
147 SOC_DOUBLE_R_SX_TLV("Analog Playback Volume", 127 SOC_DOUBLE_R_SX_TLV("Analog Playback Volume",
@@ -149,7 +129,7 @@ static const struct snd_kcontrol_new cs42l51_snd_controls[] = {
149 0, 0x34, 0xE4, aout_tlv), 129 0, 0x34, 0xE4, aout_tlv),
150 SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume", 130 SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume",
151 CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, 131 CS42L51_ADCA_VOL, CS42L51_ADCB_VOL,
152 6, 0x19, 0x7F, adc_pcm_tlv), 132 0, 0x19, 0x7F, adc_pcm_tlv),
153 SOC_DOUBLE_R("ADC Mixer Switch", 133 SOC_DOUBLE_R("ADC Mixer Switch",
154 CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, 7, 1, 1), 134 CS42L51_ADCA_VOL, CS42L51_ADCB_VOL, 7, 1, 1),
155 SOC_SINGLE("Playback Deemphasis Switch", CS42L51_DAC_CTL, 3, 1, 0), 135 SOC_SINGLE("Playback Deemphasis Switch", CS42L51_DAC_CTL, 3, 1, 0),
@@ -192,22 +172,22 @@ static int cs42l51_pdn_event(struct snd_soc_dapm_widget *w,
192 172
193static const char *cs42l51_dac_names[] = {"Direct PCM", 173static const char *cs42l51_dac_names[] = {"Direct PCM",
194 "DSP PCM", "ADC"}; 174 "DSP PCM", "ADC"};
195static const struct soc_enum cs42l51_dac_mux_enum = 175static SOC_ENUM_SINGLE_DECL(cs42l51_dac_mux_enum,
196 SOC_ENUM_SINGLE(CS42L51_DAC_CTL, 6, 3, cs42l51_dac_names); 176 CS42L51_DAC_CTL, 6, cs42l51_dac_names);
197static const struct snd_kcontrol_new cs42l51_dac_mux_controls = 177static const struct snd_kcontrol_new cs42l51_dac_mux_controls =
198 SOC_DAPM_ENUM("Route", cs42l51_dac_mux_enum); 178 SOC_DAPM_ENUM("Route", cs42l51_dac_mux_enum);
199 179
200static const char *cs42l51_adcl_names[] = {"AIN1 Left", "AIN2 Left", 180static const char *cs42l51_adcl_names[] = {"AIN1 Left", "AIN2 Left",
201 "MIC Left", "MIC+preamp Left"}; 181 "MIC Left", "MIC+preamp Left"};
202static const struct soc_enum cs42l51_adcl_mux_enum = 182static SOC_ENUM_SINGLE_DECL(cs42l51_adcl_mux_enum,
203 SOC_ENUM_SINGLE(CS42L51_ADC_INPUT, 4, 4, cs42l51_adcl_names); 183 CS42L51_ADC_INPUT, 4, cs42l51_adcl_names);
204static const struct snd_kcontrol_new cs42l51_adcl_mux_controls = 184static const struct snd_kcontrol_new cs42l51_adcl_mux_controls =
205 SOC_DAPM_ENUM("Route", cs42l51_adcl_mux_enum); 185 SOC_DAPM_ENUM("Route", cs42l51_adcl_mux_enum);
206 186
207static const char *cs42l51_adcr_names[] = {"AIN1 Right", "AIN2 Right", 187static const char *cs42l51_adcr_names[] = {"AIN1 Right", "AIN2 Right",
208 "MIC Right", "MIC+preamp Right"}; 188 "MIC Right", "MIC+preamp Right"};
209static const struct soc_enum cs42l51_adcr_mux_enum = 189static SOC_ENUM_SINGLE_DECL(cs42l51_adcr_mux_enum,
210 SOC_ENUM_SINGLE(CS42L51_ADC_INPUT, 6, 4, cs42l51_adcr_names); 190 CS42L51_ADC_INPUT, 6, cs42l51_adcr_names);
211static const struct snd_kcontrol_new cs42l51_adcr_mux_controls = 191static const struct snd_kcontrol_new cs42l51_adcr_mux_controls =
212 SOC_DAPM_ENUM("Route", cs42l51_adcr_mux_enum); 192 SOC_DAPM_ENUM("Route", cs42l51_adcr_mux_enum);
213 193
@@ -505,21 +485,8 @@ static struct snd_soc_dai_driver cs42l51_dai = {
505 485
506static int cs42l51_probe(struct snd_soc_codec *codec) 486static int cs42l51_probe(struct snd_soc_codec *codec)
507{ 487{
508 struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec);
509 int ret, reg; 488 int ret, reg;
510 489
511 ret = cs42l51_fill_cache(codec);
512 if (ret < 0) {
513 dev_err(codec->dev, "failed to fill register cache\n");
514 return ret;
515 }
516
517 ret = snd_soc_codec_set_cache_io(codec, 8, 8, cs42l51->control_type);
518 if (ret < 0) {
519 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
520 return ret;
521 }
522
523 /* 490 /*
524 * DAC configuration 491 * DAC configuration
525 * - Use signal processor 492 * - Use signal processor
@@ -538,8 +505,6 @@ static int cs42l51_probe(struct snd_soc_codec *codec)
538 505
539static struct snd_soc_codec_driver soc_codec_device_cs42l51 = { 506static struct snd_soc_codec_driver soc_codec_device_cs42l51 = {
540 .probe = cs42l51_probe, 507 .probe = cs42l51_probe,
541 .reg_cache_size = CS42L51_NUMREGS + 1,
542 .reg_word_size = sizeof(u8),
543 508
544 .controls = cs42l51_snd_controls, 509 .controls = cs42l51_snd_controls,
545 .num_controls = ARRAY_SIZE(cs42l51_snd_controls), 510 .num_controls = ARRAY_SIZE(cs42l51_snd_controls),
@@ -549,38 +514,53 @@ static struct snd_soc_codec_driver soc_codec_device_cs42l51 = {
549 .num_dapm_routes = ARRAY_SIZE(cs42l51_routes), 514 .num_dapm_routes = ARRAY_SIZE(cs42l51_routes),
550}; 515};
551 516
517static const struct regmap_config cs42l51_regmap = {
518 .reg_bits = 8,
519 .val_bits = 8,
520
521 .max_register = CS42L51_CHARGE_FREQ,
522 .cache_type = REGCACHE_RBTREE,
523};
524
552static int cs42l51_i2c_probe(struct i2c_client *i2c_client, 525static int cs42l51_i2c_probe(struct i2c_client *i2c_client,
553 const struct i2c_device_id *id) 526 const struct i2c_device_id *id)
554{ 527{
555 struct cs42l51_private *cs42l51; 528 struct cs42l51_private *cs42l51;
529 struct regmap *regmap;
530 unsigned int val;
556 int ret; 531 int ret;
557 532
533 regmap = devm_regmap_init_i2c(i2c_client, &cs42l51_regmap);
534 if (IS_ERR(regmap)) {
535 ret = PTR_ERR(regmap);
536 dev_err(&i2c_client->dev, "Failed to create regmap: %d\n",
537 ret);
538 return ret;
539 }
540
558 /* Verify that we have a CS42L51 */ 541 /* Verify that we have a CS42L51 */
559 ret = i2c_smbus_read_byte_data(i2c_client, CS42L51_CHIP_REV_ID); 542 ret = regmap_read(regmap, CS42L51_CHIP_REV_ID, &val);
560 if (ret < 0) { 543 if (ret < 0) {
561 dev_err(&i2c_client->dev, "failed to read I2C\n"); 544 dev_err(&i2c_client->dev, "failed to read I2C\n");
562 goto error; 545 goto error;
563 } 546 }
564 547
565 if ((ret != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) && 548 if ((val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) &&
566 (ret != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) { 549 (val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) {
567 dev_err(&i2c_client->dev, "Invalid chip id\n"); 550 dev_err(&i2c_client->dev, "Invalid chip id: %x\n", val);
568 ret = -ENODEV; 551 ret = -ENODEV;
569 goto error; 552 goto error;
570 } 553 }
571 554
572 dev_info(&i2c_client->dev, "found device cs42l51 rev %d\n", 555 dev_info(&i2c_client->dev, "found device cs42l51 rev %d\n",
573 ret & 7); 556 val & 7);
574 557
575 cs42l51 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l51_private), 558 cs42l51 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l51_private),
576 GFP_KERNEL); 559 GFP_KERNEL);
577 if (!cs42l51) { 560 if (!cs42l51)
578 dev_err(&i2c_client->dev, "could not allocate codec\n");
579 return -ENOMEM; 561 return -ENOMEM;
580 }
581 562
582 i2c_set_clientdata(i2c_client, cs42l51); 563 i2c_set_clientdata(i2c_client, cs42l51);
583 cs42l51->control_type = SND_SOC_I2C;
584 564
585 ret = snd_soc_register_codec(&i2c_client->dev, 565 ret = snd_soc_register_codec(&i2c_client->dev,
586 &soc_codec_device_cs42l51, &cs42l51_dai, 1); 566 &soc_codec_device_cs42l51, &cs42l51_dai, 1);
@@ -600,10 +580,17 @@ static const struct i2c_device_id cs42l51_id[] = {
600}; 580};
601MODULE_DEVICE_TABLE(i2c, cs42l51_id); 581MODULE_DEVICE_TABLE(i2c, cs42l51_id);
602 582
583static const struct of_device_id cs42l51_of_match[] = {
584 { .compatible = "cirrus,cs42l51", },
585 { }
586};
587MODULE_DEVICE_TABLE(of, cs42l51_of_match);
588
603static struct i2c_driver cs42l51_i2c_driver = { 589static struct i2c_driver cs42l51_i2c_driver = {
604 .driver = { 590 .driver = {
605 .name = "cs42l51-codec", 591 .name = "cs42l51-codec",
606 .owner = THIS_MODULE, 592 .owner = THIS_MODULE,
593 .of_match_table = cs42l51_of_match,
607 }, 594 },
608 .id_table = cs42l51_id, 595 .id_table = cs42l51_id,
609 .probe = cs42l51_i2c_probe, 596 .probe = cs42l51_i2c_probe,
diff --git a/sound/soc/codecs/cs42l52.c b/sound/soc/codecs/cs42l52.c
index 0bac6d5a4ac8..f0ca6bee6771 100644
--- a/sound/soc/codecs/cs42l52.c
+++ b/sound/soc/codecs/cs42l52.c
@@ -210,13 +210,11 @@ static const char * const cs42l52_adca_text[] = {
210static const char * const cs42l52_adcb_text[] = { 210static const char * const cs42l52_adcb_text[] = {
211 "Input1B", "Input2B", "Input3B", "Input4B", "PGA Input Right"}; 211 "Input1B", "Input2B", "Input3B", "Input4B", "PGA Input Right"};
212 212
213static const struct soc_enum adca_enum = 213static SOC_ENUM_SINGLE_DECL(adca_enum,
214 SOC_ENUM_SINGLE(CS42L52_ADC_PGA_A, 5, 214 CS42L52_ADC_PGA_A, 5, cs42l52_adca_text);
215 ARRAY_SIZE(cs42l52_adca_text), cs42l52_adca_text);
216 215
217static const struct soc_enum adcb_enum = 216static SOC_ENUM_SINGLE_DECL(adcb_enum,
218 SOC_ENUM_SINGLE(CS42L52_ADC_PGA_B, 5, 217 CS42L52_ADC_PGA_B, 5, cs42l52_adcb_text);
219 ARRAY_SIZE(cs42l52_adcb_text), cs42l52_adcb_text);
220 218
221static const struct snd_kcontrol_new adca_mux = 219static const struct snd_kcontrol_new adca_mux =
222 SOC_DAPM_ENUM("Left ADC Input Capture Mux", adca_enum); 220 SOC_DAPM_ENUM("Left ADC Input Capture Mux", adca_enum);
@@ -229,26 +227,22 @@ static const char * const mic_bias_level_text[] = {
229 "0.8 +VA", "0.83 +VA", "0.91 +VA" 227 "0.8 +VA", "0.83 +VA", "0.91 +VA"
230}; 228};
231 229
232static const struct soc_enum mic_bias_level_enum = 230static SOC_ENUM_SINGLE_DECL(mic_bias_level_enum,
233 SOC_ENUM_SINGLE(CS42L52_IFACE_CTL2, 0, 231 CS42L52_IFACE_CTL2, 0, mic_bias_level_text);
234 ARRAY_SIZE(mic_bias_level_text), mic_bias_level_text);
235 232
236static const char * const cs42l52_mic_text[] = { "MIC1", "MIC2" }; 233static const char * const cs42l52_mic_text[] = { "MIC1", "MIC2" };
237 234
238static const struct soc_enum mica_enum = 235static SOC_ENUM_SINGLE_DECL(mica_enum,
239 SOC_ENUM_SINGLE(CS42L52_MICA_CTL, 5, 236 CS42L52_MICA_CTL, 5, cs42l52_mic_text);
240 ARRAY_SIZE(cs42l52_mic_text), cs42l52_mic_text);
241 237
242static const struct soc_enum micb_enum = 238static SOC_ENUM_SINGLE_DECL(micb_enum,
243 SOC_ENUM_SINGLE(CS42L52_MICB_CTL, 5, 239 CS42L52_MICB_CTL, 5, cs42l52_mic_text);
244 ARRAY_SIZE(cs42l52_mic_text), cs42l52_mic_text);
245 240
246static const char * const digital_output_mux_text[] = {"ADC", "DSP"}; 241static const char * const digital_output_mux_text[] = {"ADC", "DSP"};
247 242
248static const struct soc_enum digital_output_mux_enum = 243static SOC_ENUM_SINGLE_DECL(digital_output_mux_enum,
249 SOC_ENUM_SINGLE(CS42L52_ADC_MISC_CTL, 6, 244 CS42L52_ADC_MISC_CTL, 6,
250 ARRAY_SIZE(digital_output_mux_text), 245 digital_output_mux_text);
251 digital_output_mux_text);
252 246
253static const struct snd_kcontrol_new digital_output_mux = 247static const struct snd_kcontrol_new digital_output_mux =
254 SOC_DAPM_ENUM("Digital Output Mux", digital_output_mux_enum); 248 SOC_DAPM_ENUM("Digital Output Mux", digital_output_mux_enum);
@@ -258,18 +252,18 @@ static const char * const hp_gain_num_text[] = {
258 "0.7099", "0.8399", "1.000", "1.1430" 252 "0.7099", "0.8399", "1.000", "1.1430"
259}; 253};
260 254
261static const struct soc_enum hp_gain_enum = 255static SOC_ENUM_SINGLE_DECL(hp_gain_enum,
262 SOC_ENUM_SINGLE(CS42L52_PB_CTL1, 5, 256 CS42L52_PB_CTL1, 5,
263 ARRAY_SIZE(hp_gain_num_text), hp_gain_num_text); 257 hp_gain_num_text);
264 258
265static const char * const beep_pitch_text[] = { 259static const char * const beep_pitch_text[] = {
266 "C4", "C5", "D5", "E5", "F5", "G5", "A5", "B5", 260 "C4", "C5", "D5", "E5", "F5", "G5", "A5", "B5",
267 "C6", "D6", "E6", "F6", "G6", "A6", "B6", "C7" 261 "C6", "D6", "E6", "F6", "G6", "A6", "B6", "C7"
268}; 262};
269 263
270static const struct soc_enum beep_pitch_enum = 264static SOC_ENUM_SINGLE_DECL(beep_pitch_enum,
271 SOC_ENUM_SINGLE(CS42L52_BEEP_FREQ, 4, 265 CS42L52_BEEP_FREQ, 4,
272 ARRAY_SIZE(beep_pitch_text), beep_pitch_text); 266 beep_pitch_text);
273 267
274static const char * const beep_ontime_text[] = { 268static const char * const beep_ontime_text[] = {
275 "86 ms", "430 ms", "780 ms", "1.20 s", "1.50 s", 269 "86 ms", "430 ms", "780 ms", "1.20 s", "1.50 s",
@@ -277,66 +271,66 @@ static const char * const beep_ontime_text[] = {
277 "3.50 s", "3.80 s", "4.20 s", "4.50 s", "4.80 s", "5.20 s" 271 "3.50 s", "3.80 s", "4.20 s", "4.50 s", "4.80 s", "5.20 s"
278}; 272};
279 273
280static const struct soc_enum beep_ontime_enum = 274static SOC_ENUM_SINGLE_DECL(beep_ontime_enum,
281 SOC_ENUM_SINGLE(CS42L52_BEEP_FREQ, 0, 275 CS42L52_BEEP_FREQ, 0,
282 ARRAY_SIZE(beep_ontime_text), beep_ontime_text); 276 beep_ontime_text);
283 277
284static const char * const beep_offtime_text[] = { 278static const char * const beep_offtime_text[] = {
285 "1.23 s", "2.58 s", "3.90 s", "5.20 s", 279 "1.23 s", "2.58 s", "3.90 s", "5.20 s",
286 "6.60 s", "8.05 s", "9.35 s", "10.80 s" 280 "6.60 s", "8.05 s", "9.35 s", "10.80 s"
287}; 281};
288 282
289static const struct soc_enum beep_offtime_enum = 283static SOC_ENUM_SINGLE_DECL(beep_offtime_enum,
290 SOC_ENUM_SINGLE(CS42L52_BEEP_VOL, 5, 284 CS42L52_BEEP_VOL, 5,
291 ARRAY_SIZE(beep_offtime_text), beep_offtime_text); 285 beep_offtime_text);
292 286
293static const char * const beep_config_text[] = { 287static const char * const beep_config_text[] = {
294 "Off", "Single", "Multiple", "Continuous" 288 "Off", "Single", "Multiple", "Continuous"
295}; 289};
296 290
297static const struct soc_enum beep_config_enum = 291static SOC_ENUM_SINGLE_DECL(beep_config_enum,
298 SOC_ENUM_SINGLE(CS42L52_BEEP_TONE_CTL, 6, 292 CS42L52_BEEP_TONE_CTL, 6,
299 ARRAY_SIZE(beep_config_text), beep_config_text); 293 beep_config_text);
300 294
301static const char * const beep_bass_text[] = { 295static const char * const beep_bass_text[] = {
302 "50 Hz", "100 Hz", "200 Hz", "250 Hz" 296 "50 Hz", "100 Hz", "200 Hz", "250 Hz"
303}; 297};
304 298
305static const struct soc_enum beep_bass_enum = 299static SOC_ENUM_SINGLE_DECL(beep_bass_enum,
306 SOC_ENUM_SINGLE(CS42L52_BEEP_TONE_CTL, 1, 300 CS42L52_BEEP_TONE_CTL, 1,
307 ARRAY_SIZE(beep_bass_text), beep_bass_text); 301 beep_bass_text);
308 302
309static const char * const beep_treble_text[] = { 303static const char * const beep_treble_text[] = {
310 "5 kHz", "7 kHz", "10 kHz", " 15 kHz" 304 "5 kHz", "7 kHz", "10 kHz", " 15 kHz"
311}; 305};
312 306
313static const struct soc_enum beep_treble_enum = 307static SOC_ENUM_SINGLE_DECL(beep_treble_enum,
314 SOC_ENUM_SINGLE(CS42L52_BEEP_TONE_CTL, 3, 308 CS42L52_BEEP_TONE_CTL, 3,
315 ARRAY_SIZE(beep_treble_text), beep_treble_text); 309 beep_treble_text);
316 310
317static const char * const ng_threshold_text[] = { 311static const char * const ng_threshold_text[] = {
318 "-34dB", "-37dB", "-40dB", "-43dB", 312 "-34dB", "-37dB", "-40dB", "-43dB",
319 "-46dB", "-52dB", "-58dB", "-64dB" 313 "-46dB", "-52dB", "-58dB", "-64dB"
320}; 314};
321 315
322static const struct soc_enum ng_threshold_enum = 316static SOC_ENUM_SINGLE_DECL(ng_threshold_enum,
323 SOC_ENUM_SINGLE(CS42L52_NOISE_GATE_CTL, 2, 317 CS42L52_NOISE_GATE_CTL, 2,
324 ARRAY_SIZE(ng_threshold_text), ng_threshold_text); 318 ng_threshold_text);
325 319
326static const char * const cs42l52_ng_delay_text[] = { 320static const char * const cs42l52_ng_delay_text[] = {
327 "50ms", "100ms", "150ms", "200ms"}; 321 "50ms", "100ms", "150ms", "200ms"};
328 322
329static const struct soc_enum ng_delay_enum = 323static SOC_ENUM_SINGLE_DECL(ng_delay_enum,
330 SOC_ENUM_SINGLE(CS42L52_NOISE_GATE_CTL, 0, 324 CS42L52_NOISE_GATE_CTL, 0,
331 ARRAY_SIZE(cs42l52_ng_delay_text), cs42l52_ng_delay_text); 325 cs42l52_ng_delay_text);
332 326
333static const char * const cs42l52_ng_type_text[] = { 327static const char * const cs42l52_ng_type_text[] = {
334 "Apply Specific", "Apply All" 328 "Apply Specific", "Apply All"
335}; 329};
336 330
337static const struct soc_enum ng_type_enum = 331static SOC_ENUM_SINGLE_DECL(ng_type_enum,
338 SOC_ENUM_SINGLE(CS42L52_NOISE_GATE_CTL, 6, 332 CS42L52_NOISE_GATE_CTL, 6,
339 ARRAY_SIZE(cs42l52_ng_type_text), cs42l52_ng_type_text); 333 cs42l52_ng_type_text);
340 334
341static const char * const left_swap_text[] = { 335static const char * const left_swap_text[] = {
342 "Left", "LR 2", "Right"}; 336 "Left", "LR 2", "Right"};
@@ -347,7 +341,7 @@ static const char * const right_swap_text[] = {
347static const unsigned int swap_values[] = { 0, 1, 3 }; 341static const unsigned int swap_values[] = { 0, 1, 3 };
348 342
349static const struct soc_enum adca_swap_enum = 343static const struct soc_enum adca_swap_enum =
350 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 2, 1, 344 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 2, 3,
351 ARRAY_SIZE(left_swap_text), 345 ARRAY_SIZE(left_swap_text),
352 left_swap_text, 346 left_swap_text,
353 swap_values); 347 swap_values);
@@ -356,7 +350,7 @@ static const struct snd_kcontrol_new adca_mixer =
356 SOC_DAPM_ENUM("Route", adca_swap_enum); 350 SOC_DAPM_ENUM("Route", adca_swap_enum);
357 351
358static const struct soc_enum pcma_swap_enum = 352static const struct soc_enum pcma_swap_enum =
359 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 6, 1, 353 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 6, 3,
360 ARRAY_SIZE(left_swap_text), 354 ARRAY_SIZE(left_swap_text),
361 left_swap_text, 355 left_swap_text,
362 swap_values); 356 swap_values);
@@ -365,7 +359,7 @@ static const struct snd_kcontrol_new pcma_mixer =
365 SOC_DAPM_ENUM("Route", pcma_swap_enum); 359 SOC_DAPM_ENUM("Route", pcma_swap_enum);
366 360
367static const struct soc_enum adcb_swap_enum = 361static const struct soc_enum adcb_swap_enum =
368 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 0, 1, 362 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 0, 3,
369 ARRAY_SIZE(right_swap_text), 363 ARRAY_SIZE(right_swap_text),
370 right_swap_text, 364 right_swap_text,
371 swap_values); 365 swap_values);
@@ -374,7 +368,7 @@ static const struct snd_kcontrol_new adcb_mixer =
374 SOC_DAPM_ENUM("Route", adcb_swap_enum); 368 SOC_DAPM_ENUM("Route", adcb_swap_enum);
375 369
376static const struct soc_enum pcmb_swap_enum = 370static const struct soc_enum pcmb_swap_enum =
377 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 4, 1, 371 SOC_VALUE_ENUM_SINGLE(CS42L52_ADC_PCM_MIXER, 4, 3,
378 ARRAY_SIZE(right_swap_text), 372 ARRAY_SIZE(right_swap_text),
379 right_swap_text, 373 right_swap_text,
380 swap_values); 374 swap_values);
@@ -1115,14 +1109,7 @@ static void cs42l52_free_beep(struct snd_soc_codec *codec)
1115static int cs42l52_probe(struct snd_soc_codec *codec) 1109static int cs42l52_probe(struct snd_soc_codec *codec)
1116{ 1110{
1117 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec); 1111 struct cs42l52_private *cs42l52 = snd_soc_codec_get_drvdata(codec);
1118 int ret;
1119 1112
1120 codec->control_data = cs42l52->regmap;
1121 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1122 if (ret < 0) {
1123 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1124 return ret;
1125 }
1126 regcache_cache_only(cs42l52->regmap, true); 1113 regcache_cache_only(cs42l52->regmap, true);
1127 1114
1128 cs42l52_add_mic_controls(codec); 1115 cs42l52_add_mic_controls(codec);
@@ -1134,7 +1121,7 @@ static int cs42l52_probe(struct snd_soc_codec *codec)
1134 cs42l52->sysclk = CS42L52_DEFAULT_CLK; 1121 cs42l52->sysclk = CS42L52_DEFAULT_CLK;
1135 cs42l52->config.format = CS42L52_DEFAULT_FORMAT; 1122 cs42l52->config.format = CS42L52_DEFAULT_FORMAT;
1136 1123
1137 return ret; 1124 return 0;
1138} 1125}
1139 1126
1140static int cs42l52_remove(struct snd_soc_codec *codec) 1127static int cs42l52_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c
index 549d5d6a3fef..0ee60a19a263 100644
--- a/sound/soc/codecs/cs42l73.c
+++ b/sound/soc/codecs/cs42l73.c
@@ -278,13 +278,13 @@ static const DECLARE_TLV_DB_SCALE(attn_tlv, -6300, 100, 1);
278static const char * const cs42l73_pgaa_text[] = { "Line A", "Mic 1" }; 278static const char * const cs42l73_pgaa_text[] = { "Line A", "Mic 1" };
279static const char * const cs42l73_pgab_text[] = { "Line B", "Mic 2" }; 279static const char * const cs42l73_pgab_text[] = { "Line B", "Mic 2" };
280 280
281static const struct soc_enum pgaa_enum = 281static SOC_ENUM_SINGLE_DECL(pgaa_enum,
282 SOC_ENUM_SINGLE(CS42L73_ADCIPC, 3, 282 CS42L73_ADCIPC, 3,
283 ARRAY_SIZE(cs42l73_pgaa_text), cs42l73_pgaa_text); 283 cs42l73_pgaa_text);
284 284
285static const struct soc_enum pgab_enum = 285static SOC_ENUM_SINGLE_DECL(pgab_enum,
286 SOC_ENUM_SINGLE(CS42L73_ADCIPC, 7, 286 CS42L73_ADCIPC, 7,
287 ARRAY_SIZE(cs42l73_pgab_text), cs42l73_pgab_text); 287 cs42l73_pgab_text);
288 288
289static const struct snd_kcontrol_new pgaa_mux = 289static const struct snd_kcontrol_new pgaa_mux =
290 SOC_DAPM_ENUM("Left Analog Input Capture Mux", pgaa_enum); 290 SOC_DAPM_ENUM("Left Analog Input Capture Mux", pgaa_enum);
@@ -309,9 +309,9 @@ static const struct snd_kcontrol_new input_right_mixer[] = {
309static const char * const cs42l73_ng_delay_text[] = { 309static const char * const cs42l73_ng_delay_text[] = {
310 "50ms", "100ms", "150ms", "200ms" }; 310 "50ms", "100ms", "150ms", "200ms" };
311 311
312static const struct soc_enum ng_delay_enum = 312static SOC_ENUM_SINGLE_DECL(ng_delay_enum,
313 SOC_ENUM_SINGLE(CS42L73_NGCAB, 0, 313 CS42L73_NGCAB, 0,
314 ARRAY_SIZE(cs42l73_ng_delay_text), cs42l73_ng_delay_text); 314 cs42l73_ng_delay_text);
315 315
316static const char * const cs42l73_mono_mix_texts[] = { 316static const char * const cs42l73_mono_mix_texts[] = {
317 "Left", "Right", "Mono Mix"}; 317 "Left", "Right", "Mono Mix"};
@@ -319,7 +319,7 @@ static const char * const cs42l73_mono_mix_texts[] = {
319static const unsigned int cs42l73_mono_mix_values[] = { 0, 1, 2 }; 319static const unsigned int cs42l73_mono_mix_values[] = { 0, 1, 2 };
320 320
321static const struct soc_enum spk_asp_enum = 321static const struct soc_enum spk_asp_enum =
322 SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 6, 1, 322 SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 6, 3,
323 ARRAY_SIZE(cs42l73_mono_mix_texts), 323 ARRAY_SIZE(cs42l73_mono_mix_texts),
324 cs42l73_mono_mix_texts, 324 cs42l73_mono_mix_texts,
325 cs42l73_mono_mix_values); 325 cs42l73_mono_mix_values);
@@ -337,7 +337,7 @@ static const struct snd_kcontrol_new spk_xsp_mixer =
337 SOC_DAPM_ENUM("Route", spk_xsp_enum); 337 SOC_DAPM_ENUM("Route", spk_xsp_enum);
338 338
339static const struct soc_enum esl_asp_enum = 339static const struct soc_enum esl_asp_enum =
340 SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 2, 5, 340 SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 2, 3,
341 ARRAY_SIZE(cs42l73_mono_mix_texts), 341 ARRAY_SIZE(cs42l73_mono_mix_texts),
342 cs42l73_mono_mix_texts, 342 cs42l73_mono_mix_texts,
343 cs42l73_mono_mix_values); 343 cs42l73_mono_mix_values);
@@ -346,7 +346,7 @@ static const struct snd_kcontrol_new esl_asp_mixer =
346 SOC_DAPM_ENUM("Route", esl_asp_enum); 346 SOC_DAPM_ENUM("Route", esl_asp_enum);
347 347
348static const struct soc_enum esl_xsp_enum = 348static const struct soc_enum esl_xsp_enum =
349 SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 0, 7, 349 SOC_VALUE_ENUM_SINGLE(CS42L73_MMIXCTL, 0, 3,
350 ARRAY_SIZE(cs42l73_mono_mix_texts), 350 ARRAY_SIZE(cs42l73_mono_mix_texts),
351 cs42l73_mono_mix_texts, 351 cs42l73_mono_mix_texts,
352 cs42l73_mono_mix_values); 352 cs42l73_mono_mix_values);
@@ -357,19 +357,19 @@ static const struct snd_kcontrol_new esl_xsp_mixer =
357static const char * const cs42l73_ip_swap_text[] = { 357static const char * const cs42l73_ip_swap_text[] = {
358 "Stereo", "Mono A", "Mono B", "Swap A-B"}; 358 "Stereo", "Mono A", "Mono B", "Swap A-B"};
359 359
360static const struct soc_enum ip_swap_enum = 360static SOC_ENUM_SINGLE_DECL(ip_swap_enum,
361 SOC_ENUM_SINGLE(CS42L73_MIOPC, 6, 361 CS42L73_MIOPC, 6,
362 ARRAY_SIZE(cs42l73_ip_swap_text), cs42l73_ip_swap_text); 362 cs42l73_ip_swap_text);
363 363
364static const char * const cs42l73_spo_mixer_text[] = {"Mono", "Stereo"}; 364static const char * const cs42l73_spo_mixer_text[] = {"Mono", "Stereo"};
365 365
366static const struct soc_enum vsp_output_mux_enum = 366static SOC_ENUM_SINGLE_DECL(vsp_output_mux_enum,
367 SOC_ENUM_SINGLE(CS42L73_MIXERCTL, 5, 367 CS42L73_MIXERCTL, 5,
368 ARRAY_SIZE(cs42l73_spo_mixer_text), cs42l73_spo_mixer_text); 368 cs42l73_spo_mixer_text);
369 369
370static const struct soc_enum xsp_output_mux_enum = 370static SOC_ENUM_SINGLE_DECL(xsp_output_mux_enum,
371 SOC_ENUM_SINGLE(CS42L73_MIXERCTL, 4, 371 CS42L73_MIXERCTL, 4,
372 ARRAY_SIZE(cs42l73_spo_mixer_text), cs42l73_spo_mixer_text); 372 cs42l73_spo_mixer_text);
373 373
374static const struct snd_kcontrol_new vsp_output_mux = 374static const struct snd_kcontrol_new vsp_output_mux =
375 SOC_DAPM_ENUM("Route", vsp_output_mux_enum); 375 SOC_DAPM_ENUM("Route", vsp_output_mux_enum);
@@ -1108,7 +1108,7 @@ static int cs42l73_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1108 return 0; 1108 return 0;
1109} 1109}
1110 1110
1111static u32 cs42l73_asrc_rates[] = { 1111static const unsigned int cs42l73_asrc_rates[] = {
1112 8000, 11025, 12000, 16000, 22050, 1112 8000, 11025, 12000, 16000, 22050,
1113 24000, 32000, 44100, 48000 1113 24000, 32000, 44100, 48000
1114}; 1114};
@@ -1241,7 +1241,7 @@ static int cs42l73_set_tristate(struct snd_soc_dai *dai, int tristate)
1241 0x7F, tristate << 7); 1241 0x7F, tristate << 7);
1242} 1242}
1243 1243
1244static struct snd_pcm_hw_constraint_list constraints_12_24 = { 1244static const struct snd_pcm_hw_constraint_list constraints_12_24 = {
1245 .count = ARRAY_SIZE(cs42l73_asrc_rates), 1245 .count = ARRAY_SIZE(cs42l73_asrc_rates),
1246 .list = cs42l73_asrc_rates, 1246 .list = cs42l73_asrc_rates,
1247}; 1247};
@@ -1255,9 +1255,6 @@ static int cs42l73_pcm_startup(struct snd_pcm_substream *substream,
1255 return 0; 1255 return 0;
1256} 1256}
1257 1257
1258/* SNDRV_PCM_RATE_KNOT -> 12000, 24000 Hz, limit with constraint list */
1259#define CS42L73_RATES (SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_KNOT)
1260
1261 1258
1262#define CS42L73_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 1259#define CS42L73_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1263 SNDRV_PCM_FMTBIT_S24_LE) 1260 SNDRV_PCM_FMTBIT_S24_LE)
@@ -1278,14 +1275,14 @@ static struct snd_soc_dai_driver cs42l73_dai[] = {
1278 .stream_name = "XSP Playback", 1275 .stream_name = "XSP Playback",
1279 .channels_min = 1, 1276 .channels_min = 1,
1280 .channels_max = 2, 1277 .channels_max = 2,
1281 .rates = CS42L73_RATES, 1278 .rates = SNDRV_PCM_RATE_KNOT,
1282 .formats = CS42L73_FORMATS, 1279 .formats = CS42L73_FORMATS,
1283 }, 1280 },
1284 .capture = { 1281 .capture = {
1285 .stream_name = "XSP Capture", 1282 .stream_name = "XSP Capture",
1286 .channels_min = 1, 1283 .channels_min = 1,
1287 .channels_max = 2, 1284 .channels_max = 2,
1288 .rates = CS42L73_RATES, 1285 .rates = SNDRV_PCM_RATE_KNOT,
1289 .formats = CS42L73_FORMATS, 1286 .formats = CS42L73_FORMATS,
1290 }, 1287 },
1291 .ops = &cs42l73_ops, 1288 .ops = &cs42l73_ops,
@@ -1298,14 +1295,14 @@ static struct snd_soc_dai_driver cs42l73_dai[] = {
1298 .stream_name = "ASP Playback", 1295 .stream_name = "ASP Playback",
1299 .channels_min = 2, 1296 .channels_min = 2,
1300 .channels_max = 2, 1297 .channels_max = 2,
1301 .rates = CS42L73_RATES, 1298 .rates = SNDRV_PCM_RATE_KNOT,
1302 .formats = CS42L73_FORMATS, 1299 .formats = CS42L73_FORMATS,
1303 }, 1300 },
1304 .capture = { 1301 .capture = {
1305 .stream_name = "ASP Capture", 1302 .stream_name = "ASP Capture",
1306 .channels_min = 2, 1303 .channels_min = 2,
1307 .channels_max = 2, 1304 .channels_max = 2,
1308 .rates = CS42L73_RATES, 1305 .rates = SNDRV_PCM_RATE_KNOT,
1309 .formats = CS42L73_FORMATS, 1306 .formats = CS42L73_FORMATS,
1310 }, 1307 },
1311 .ops = &cs42l73_ops, 1308 .ops = &cs42l73_ops,
@@ -1318,14 +1315,14 @@ static struct snd_soc_dai_driver cs42l73_dai[] = {
1318 .stream_name = "VSP Playback", 1315 .stream_name = "VSP Playback",
1319 .channels_min = 1, 1316 .channels_min = 1,
1320 .channels_max = 2, 1317 .channels_max = 2,
1321 .rates = CS42L73_RATES, 1318 .rates = SNDRV_PCM_RATE_KNOT,
1322 .formats = CS42L73_FORMATS, 1319 .formats = CS42L73_FORMATS,
1323 }, 1320 },
1324 .capture = { 1321 .capture = {
1325 .stream_name = "VSP Capture", 1322 .stream_name = "VSP Capture",
1326 .channels_min = 1, 1323 .channels_min = 1,
1327 .channels_max = 2, 1324 .channels_max = 2,
1328 .rates = CS42L73_RATES, 1325 .rates = SNDRV_PCM_RATE_KNOT,
1329 .formats = CS42L73_FORMATS, 1326 .formats = CS42L73_FORMATS,
1330 }, 1327 },
1331 .ops = &cs42l73_ops, 1328 .ops = &cs42l73_ops,
@@ -1348,17 +1345,8 @@ static int cs42l73_resume(struct snd_soc_codec *codec)
1348 1345
1349static int cs42l73_probe(struct snd_soc_codec *codec) 1346static int cs42l73_probe(struct snd_soc_codec *codec)
1350{ 1347{
1351 int ret;
1352 struct cs42l73_private *cs42l73 = snd_soc_codec_get_drvdata(codec); 1348 struct cs42l73_private *cs42l73 = snd_soc_codec_get_drvdata(codec);
1353 1349
1354 codec->control_data = cs42l73->regmap;
1355
1356 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1357 if (ret < 0) {
1358 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1359 return ret;
1360 }
1361
1362 cs42l73_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1350 cs42l73_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1363 1351
1364 /* Set Charge Pump Frequency */ 1352 /* Set Charge Pump Frequency */
@@ -1371,7 +1359,7 @@ static int cs42l73_probe(struct snd_soc_codec *codec)
1371 cs42l73->mclksel = CS42L73_CLKID_MCLK1; 1359 cs42l73->mclksel = CS42L73_CLKID_MCLK1;
1372 cs42l73->mclk = 0; 1360 cs42l73->mclk = 0;
1373 1361
1374 return ret; 1362 return 0;
1375} 1363}
1376 1364
1377static int cs42l73_remove(struct snd_soc_codec *codec) 1365static int cs42l73_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/cs42xx8-i2c.c b/sound/soc/codecs/cs42xx8-i2c.c
new file mode 100644
index 000000000000..657dce27eade
--- /dev/null
+++ b/sound/soc/codecs/cs42xx8-i2c.c
@@ -0,0 +1,64 @@
1/*
2 * Cirrus Logic CS42448/CS42888 Audio CODEC DAI I2C driver
3 *
4 * Copyright (C) 2014 Freescale Semiconductor, Inc.
5 *
6 * Author: Nicolin Chen <Guangyu.Chen@freescale.com>
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
11 */
12
13#include <linux/i2c.h>
14#include <linux/module.h>
15#include <linux/pm_runtime.h>
16#include <sound/soc.h>
17
18#include "cs42xx8.h"
19
20static int cs42xx8_i2c_probe(struct i2c_client *i2c,
21 const struct i2c_device_id *id)
22{
23 u32 ret = cs42xx8_probe(&i2c->dev,
24 devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config));
25 if (ret)
26 return ret;
27
28 pm_runtime_enable(&i2c->dev);
29 pm_request_idle(&i2c->dev);
30
31 return 0;
32}
33
34static int cs42xx8_i2c_remove(struct i2c_client *i2c)
35{
36 snd_soc_unregister_codec(&i2c->dev);
37 pm_runtime_disable(&i2c->dev);
38
39 return 0;
40}
41
42static struct i2c_device_id cs42xx8_i2c_id[] = {
43 {"cs42448", (kernel_ulong_t)&cs42448_data},
44 {"cs42888", (kernel_ulong_t)&cs42888_data},
45 {}
46};
47MODULE_DEVICE_TABLE(i2c, cs42xx8_i2c_id);
48
49static struct i2c_driver cs42xx8_i2c_driver = {
50 .driver = {
51 .name = "cs42xx8",
52 .owner = THIS_MODULE,
53 .pm = &cs42xx8_pm,
54 },
55 .probe = cs42xx8_i2c_probe,
56 .remove = cs42xx8_i2c_remove,
57 .id_table = cs42xx8_i2c_id,
58};
59
60module_i2c_driver(cs42xx8_i2c_driver);
61
62MODULE_DESCRIPTION("Cirrus Logic CS42448/CS42888 ALSA SoC Codec I2C Driver");
63MODULE_AUTHOR("Freescale Semiconductor, Inc.");
64MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs42xx8.c b/sound/soc/codecs/cs42xx8.c
new file mode 100644
index 000000000000..082299a4e2fa
--- /dev/null
+++ b/sound/soc/codecs/cs42xx8.c
@@ -0,0 +1,602 @@
1/*
2 * Cirrus Logic CS42448/CS42888 Audio CODEC Digital Audio Interface (DAI) driver
3 *
4 * Copyright (C) 2014 Freescale Semiconductor, Inc.
5 *
6 * Author: Nicolin Chen <Guangyu.Chen@freescale.com>
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
11 */
12
13#include <linux/clk.h>
14#include <linux/delay.h>
15#include <linux/module.h>
16#include <linux/of_device.h>
17#include <linux/pm_runtime.h>
18#include <linux/regulator/consumer.h>
19#include <sound/pcm_params.h>
20#include <sound/soc.h>
21#include <sound/tlv.h>
22
23#include "cs42xx8.h"
24
25#define CS42XX8_NUM_SUPPLIES 4
26static const char *const cs42xx8_supply_names[CS42XX8_NUM_SUPPLIES] = {
27 "VA",
28 "VD",
29 "VLS",
30 "VLC",
31};
32
33#define CS42XX8_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
34 SNDRV_PCM_FMTBIT_S20_3LE | \
35 SNDRV_PCM_FMTBIT_S24_LE | \
36 SNDRV_PCM_FMTBIT_S32_LE)
37
38/* codec private data */
39struct cs42xx8_priv {
40 struct regulator_bulk_data supplies[CS42XX8_NUM_SUPPLIES];
41 const struct cs42xx8_driver_data *drvdata;
42 struct regmap *regmap;
43 struct clk *clk;
44
45 bool slave_mode;
46 unsigned long sysclk;
47};
48
49/* -127.5dB to 0dB with step of 0.5dB */
50static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1);
51/* -64dB to 24dB with step of 0.5dB */
52static const DECLARE_TLV_DB_SCALE(adc_tlv, -6400, 50, 0);
53
54static const char *const cs42xx8_adc_single[] = { "Differential", "Single-Ended" };
55static const char *const cs42xx8_szc[] = { "Immediate Change", "Zero Cross",
56 "Soft Ramp", "Soft Ramp on Zero Cross" };
57
58static const struct soc_enum adc1_single_enum =
59 SOC_ENUM_SINGLE(CS42XX8_ADCCTL, 4, 2, cs42xx8_adc_single);
60static const struct soc_enum adc2_single_enum =
61 SOC_ENUM_SINGLE(CS42XX8_ADCCTL, 3, 2, cs42xx8_adc_single);
62static const struct soc_enum adc3_single_enum =
63 SOC_ENUM_SINGLE(CS42XX8_ADCCTL, 2, 2, cs42xx8_adc_single);
64static const struct soc_enum dac_szc_enum =
65 SOC_ENUM_SINGLE(CS42XX8_TXCTL, 5, 4, cs42xx8_szc);
66static const struct soc_enum adc_szc_enum =
67 SOC_ENUM_SINGLE(CS42XX8_TXCTL, 0, 4, cs42xx8_szc);
68
69static const struct snd_kcontrol_new cs42xx8_snd_controls[] = {
70 SOC_DOUBLE_R_TLV("DAC1 Playback Volume", CS42XX8_VOLAOUT1,
71 CS42XX8_VOLAOUT2, 0, 0xff, 1, dac_tlv),
72 SOC_DOUBLE_R_TLV("DAC2 Playback Volume", CS42XX8_VOLAOUT3,
73 CS42XX8_VOLAOUT4, 0, 0xff, 1, dac_tlv),
74 SOC_DOUBLE_R_TLV("DAC3 Playback Volume", CS42XX8_VOLAOUT5,
75 CS42XX8_VOLAOUT6, 0, 0xff, 1, dac_tlv),
76 SOC_DOUBLE_R_TLV("DAC4 Playback Volume", CS42XX8_VOLAOUT7,
77 CS42XX8_VOLAOUT8, 0, 0xff, 1, dac_tlv),
78 SOC_DOUBLE_R_S_TLV("ADC1 Capture Volume", CS42XX8_VOLAIN1,
79 CS42XX8_VOLAIN2, 0, -0x80, 0x30, 7, 0, adc_tlv),
80 SOC_DOUBLE_R_S_TLV("ADC2 Capture Volume", CS42XX8_VOLAIN3,
81 CS42XX8_VOLAIN4, 0, -0x80, 0x30, 7, 0, adc_tlv),
82 SOC_DOUBLE("DAC1 Invert Switch", CS42XX8_DACINV, 0, 1, 1, 0),
83 SOC_DOUBLE("DAC2 Invert Switch", CS42XX8_DACINV, 2, 3, 1, 0),
84 SOC_DOUBLE("DAC3 Invert Switch", CS42XX8_DACINV, 4, 5, 1, 0),
85 SOC_DOUBLE("DAC4 Invert Switch", CS42XX8_DACINV, 6, 7, 1, 0),
86 SOC_DOUBLE("ADC1 Invert Switch", CS42XX8_ADCINV, 0, 1, 1, 0),
87 SOC_DOUBLE("ADC2 Invert Switch", CS42XX8_ADCINV, 2, 3, 1, 0),
88 SOC_SINGLE("ADC High-Pass Filter Switch", CS42XX8_ADCCTL, 7, 1, 1),
89 SOC_SINGLE("DAC De-emphasis Switch", CS42XX8_ADCCTL, 5, 1, 0),
90 SOC_ENUM("ADC1 Single Ended Mode Switch", adc1_single_enum),
91 SOC_ENUM("ADC2 Single Ended Mode Switch", adc2_single_enum),
92 SOC_SINGLE("DAC Single Volume Control Switch", CS42XX8_TXCTL, 7, 1, 0),
93 SOC_ENUM("DAC Soft Ramp & Zero Cross Control Switch", dac_szc_enum),
94 SOC_SINGLE("DAC Auto Mute Switch", CS42XX8_TXCTL, 4, 1, 0),
95 SOC_SINGLE("Mute ADC Serial Port Switch", CS42XX8_TXCTL, 3, 1, 0),
96 SOC_SINGLE("ADC Single Volume Control Switch", CS42XX8_TXCTL, 2, 1, 0),
97 SOC_ENUM("ADC Soft Ramp & Zero Cross Control Switch", adc_szc_enum),
98};
99
100static const struct snd_kcontrol_new cs42xx8_adc3_snd_controls[] = {
101 SOC_DOUBLE_R_S_TLV("ADC3 Capture Volume", CS42XX8_VOLAIN5,
102 CS42XX8_VOLAIN6, 0, -0x80, 0x30, 7, 0, adc_tlv),
103 SOC_DOUBLE("ADC3 Invert Switch", CS42XX8_ADCINV, 4, 5, 1, 0),
104 SOC_ENUM("ADC3 Single Ended Mode Switch", adc3_single_enum),
105};
106
107static const struct snd_soc_dapm_widget cs42xx8_dapm_widgets[] = {
108 SND_SOC_DAPM_DAC("DAC1", "Playback", CS42XX8_PWRCTL, 1, 1),
109 SND_SOC_DAPM_DAC("DAC2", "Playback", CS42XX8_PWRCTL, 2, 1),
110 SND_SOC_DAPM_DAC("DAC3", "Playback", CS42XX8_PWRCTL, 3, 1),
111 SND_SOC_DAPM_DAC("DAC4", "Playback", CS42XX8_PWRCTL, 4, 1),
112
113 SND_SOC_DAPM_OUTPUT("AOUT1L"),
114 SND_SOC_DAPM_OUTPUT("AOUT1R"),
115 SND_SOC_DAPM_OUTPUT("AOUT2L"),
116 SND_SOC_DAPM_OUTPUT("AOUT2R"),
117 SND_SOC_DAPM_OUTPUT("AOUT3L"),
118 SND_SOC_DAPM_OUTPUT("AOUT3R"),
119 SND_SOC_DAPM_OUTPUT("AOUT4L"),
120 SND_SOC_DAPM_OUTPUT("AOUT4R"),
121
122 SND_SOC_DAPM_ADC("ADC1", "Capture", CS42XX8_PWRCTL, 5, 1),
123 SND_SOC_DAPM_ADC("ADC2", "Capture", CS42XX8_PWRCTL, 6, 1),
124
125 SND_SOC_DAPM_INPUT("AIN1L"),
126 SND_SOC_DAPM_INPUT("AIN1R"),
127 SND_SOC_DAPM_INPUT("AIN2L"),
128 SND_SOC_DAPM_INPUT("AIN2R"),
129
130 SND_SOC_DAPM_SUPPLY("PWR", CS42XX8_PWRCTL, 0, 1, NULL, 0),
131};
132
133static const struct snd_soc_dapm_widget cs42xx8_adc3_dapm_widgets[] = {
134 SND_SOC_DAPM_ADC("ADC3", "Capture", CS42XX8_PWRCTL, 7, 1),
135
136 SND_SOC_DAPM_INPUT("AIN3L"),
137 SND_SOC_DAPM_INPUT("AIN3R"),
138};
139
140static const struct snd_soc_dapm_route cs42xx8_dapm_routes[] = {
141 /* Playback */
142 { "AOUT1L", NULL, "DAC1" },
143 { "AOUT1R", NULL, "DAC1" },
144 { "DAC1", NULL, "PWR" },
145
146 { "AOUT2L", NULL, "DAC2" },
147 { "AOUT2R", NULL, "DAC2" },
148 { "DAC2", NULL, "PWR" },
149
150 { "AOUT3L", NULL, "DAC3" },
151 { "AOUT3R", NULL, "DAC3" },
152 { "DAC3", NULL, "PWR" },
153
154 { "AOUT4L", NULL, "DAC4" },
155 { "AOUT4R", NULL, "DAC4" },
156 { "DAC4", NULL, "PWR" },
157
158 /* Capture */
159 { "ADC1", NULL, "AIN1L" },
160 { "ADC1", NULL, "AIN1R" },
161 { "ADC1", NULL, "PWR" },
162
163 { "ADC2", NULL, "AIN2L" },
164 { "ADC2", NULL, "AIN2R" },
165 { "ADC2", NULL, "PWR" },
166};
167
168static const struct snd_soc_dapm_route cs42xx8_adc3_dapm_routes[] = {
169 /* Capture */
170 { "ADC3", NULL, "AIN3L" },
171 { "ADC3", NULL, "AIN3R" },
172 { "ADC3", NULL, "PWR" },
173};
174
175struct cs42xx8_ratios {
176 unsigned int ratio;
177 unsigned char speed;
178 unsigned char mclk;
179};
180
181static const struct cs42xx8_ratios cs42xx8_ratios[] = {
182 { 64, CS42XX8_FM_QUAD, CS42XX8_FUNCMOD_MFREQ_256(4) },
183 { 96, CS42XX8_FM_QUAD, CS42XX8_FUNCMOD_MFREQ_384(4) },
184 { 128, CS42XX8_FM_QUAD, CS42XX8_FUNCMOD_MFREQ_512(4) },
185 { 192, CS42XX8_FM_QUAD, CS42XX8_FUNCMOD_MFREQ_768(4) },
186 { 256, CS42XX8_FM_SINGLE, CS42XX8_FUNCMOD_MFREQ_256(1) },
187 { 384, CS42XX8_FM_SINGLE, CS42XX8_FUNCMOD_MFREQ_384(1) },
188 { 512, CS42XX8_FM_SINGLE, CS42XX8_FUNCMOD_MFREQ_512(1) },
189 { 768, CS42XX8_FM_SINGLE, CS42XX8_FUNCMOD_MFREQ_768(1) },
190 { 1024, CS42XX8_FM_SINGLE, CS42XX8_FUNCMOD_MFREQ_1024(1) }
191};
192
193static int cs42xx8_set_dai_sysclk(struct snd_soc_dai *codec_dai,
194 int clk_id, unsigned int freq, int dir)
195{
196 struct snd_soc_codec *codec = codec_dai->codec;
197 struct cs42xx8_priv *cs42xx8 = snd_soc_codec_get_drvdata(codec);
198
199 cs42xx8->sysclk = freq;
200
201 return 0;
202}
203
204static int cs42xx8_set_dai_fmt(struct snd_soc_dai *codec_dai,
205 unsigned int format)
206{
207 struct snd_soc_codec *codec = codec_dai->codec;
208 struct cs42xx8_priv *cs42xx8 = snd_soc_codec_get_drvdata(codec);
209 u32 val;
210
211 /* Set DAI format */
212 switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
213 case SND_SOC_DAIFMT_LEFT_J:
214 val = CS42XX8_INTF_DAC_DIF_LEFTJ | CS42XX8_INTF_ADC_DIF_LEFTJ;
215 break;
216 case SND_SOC_DAIFMT_I2S:
217 val = CS42XX8_INTF_DAC_DIF_I2S | CS42XX8_INTF_ADC_DIF_I2S;
218 break;
219 case SND_SOC_DAIFMT_RIGHT_J:
220 val = CS42XX8_INTF_DAC_DIF_RIGHTJ | CS42XX8_INTF_ADC_DIF_RIGHTJ;
221 break;
222 default:
223 dev_err(codec->dev, "unsupported dai format\n");
224 return -EINVAL;
225 }
226
227 regmap_update_bits(cs42xx8->regmap, CS42XX8_INTF,
228 CS42XX8_INTF_DAC_DIF_MASK |
229 CS42XX8_INTF_ADC_DIF_MASK, val);
230
231 /* Set master/slave audio interface */
232 switch (format & SND_SOC_DAIFMT_MASTER_MASK) {
233 case SND_SOC_DAIFMT_CBS_CFS:
234 cs42xx8->slave_mode = true;
235 break;
236 case SND_SOC_DAIFMT_CBM_CFM:
237 cs42xx8->slave_mode = false;
238 break;
239 default:
240 dev_err(codec->dev, "unsupported master/slave mode\n");
241 return -EINVAL;
242 }
243
244 return 0;
245}
246
247static int cs42xx8_hw_params(struct snd_pcm_substream *substream,
248 struct snd_pcm_hw_params *params,
249 struct snd_soc_dai *dai)
250{
251 struct snd_soc_pcm_runtime *rtd = substream->private_data;
252 struct snd_soc_codec *codec = rtd->codec;
253 struct cs42xx8_priv *cs42xx8 = snd_soc_codec_get_drvdata(codec);
254 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
255 u32 ratio = cs42xx8->sysclk / params_rate(params);
256 u32 i, fm, val, mask;
257
258 for (i = 0; i < ARRAY_SIZE(cs42xx8_ratios); i++) {
259 if (cs42xx8_ratios[i].ratio == ratio)
260 break;
261 }
262
263 if (i == ARRAY_SIZE(cs42xx8_ratios)) {
264 dev_err(codec->dev, "unsupported sysclk ratio\n");
265 return -EINVAL;
266 }
267
268 mask = CS42XX8_FUNCMOD_MFREQ_MASK;
269 val = cs42xx8_ratios[i].mclk;
270
271 fm = cs42xx8->slave_mode ? CS42XX8_FM_AUTO : cs42xx8_ratios[i].speed;
272
273 regmap_update_bits(cs42xx8->regmap, CS42XX8_FUNCMOD,
274 CS42XX8_FUNCMOD_xC_FM_MASK(tx) | mask,
275 CS42XX8_FUNCMOD_xC_FM(tx, fm) | val);
276
277 return 0;
278}
279
280static int cs42xx8_digital_mute(struct snd_soc_dai *dai, int mute)
281{
282 struct snd_soc_codec *codec = dai->codec;
283 struct cs42xx8_priv *cs42xx8 = snd_soc_codec_get_drvdata(codec);
284
285 regmap_update_bits(cs42xx8->regmap, CS42XX8_DACMUTE,
286 CS42XX8_DACMUTE_ALL, mute ? CS42XX8_DACMUTE_ALL : 0);
287
288 return 0;
289}
290
291static const struct snd_soc_dai_ops cs42xx8_dai_ops = {
292 .set_fmt = cs42xx8_set_dai_fmt,
293 .set_sysclk = cs42xx8_set_dai_sysclk,
294 .hw_params = cs42xx8_hw_params,
295 .digital_mute = cs42xx8_digital_mute,
296};
297
298static struct snd_soc_dai_driver cs42xx8_dai = {
299 .playback = {
300 .stream_name = "Playback",
301 .channels_min = 1,
302 .channels_max = 8,
303 .rates = SNDRV_PCM_RATE_8000_192000,
304 .formats = CS42XX8_FORMATS,
305 },
306 .capture = {
307 .stream_name = "Capture",
308 .channels_min = 1,
309 .rates = SNDRV_PCM_RATE_8000_192000,
310 .formats = CS42XX8_FORMATS,
311 },
312 .ops = &cs42xx8_dai_ops,
313};
314
315static const struct reg_default cs42xx8_reg[] = {
316 { 0x01, 0x01 }, /* Chip I.D. and Revision Register */
317 { 0x02, 0x00 }, /* Power Control */
318 { 0x03, 0xF0 }, /* Functional Mode */
319 { 0x04, 0x46 }, /* Interface Formats */
320 { 0x05, 0x00 }, /* ADC Control & DAC De-Emphasis */
321 { 0x06, 0x10 }, /* Transition Control */
322 { 0x07, 0x00 }, /* DAC Channel Mute */
323 { 0x08, 0x00 }, /* Volume Control AOUT1 */
324 { 0x09, 0x00 }, /* Volume Control AOUT2 */
325 { 0x0a, 0x00 }, /* Volume Control AOUT3 */
326 { 0x0b, 0x00 }, /* Volume Control AOUT4 */
327 { 0x0c, 0x00 }, /* Volume Control AOUT5 */
328 { 0x0d, 0x00 }, /* Volume Control AOUT6 */
329 { 0x0e, 0x00 }, /* Volume Control AOUT7 */
330 { 0x0f, 0x00 }, /* Volume Control AOUT8 */
331 { 0x10, 0x00 }, /* DAC Channel Invert */
332 { 0x11, 0x00 }, /* Volume Control AIN1 */
333 { 0x12, 0x00 }, /* Volume Control AIN2 */
334 { 0x13, 0x00 }, /* Volume Control AIN3 */
335 { 0x14, 0x00 }, /* Volume Control AIN4 */
336 { 0x15, 0x00 }, /* Volume Control AIN5 */
337 { 0x16, 0x00 }, /* Volume Control AIN6 */
338 { 0x17, 0x00 }, /* ADC Channel Invert */
339 { 0x18, 0x00 }, /* Status Control */
340 { 0x1a, 0x00 }, /* Status Mask */
341 { 0x1b, 0x00 }, /* MUTEC Pin Control */
342};
343
344static bool cs42xx8_volatile_register(struct device *dev, unsigned int reg)
345{
346 switch (reg) {
347 case CS42XX8_STATUS:
348 return true;
349 default:
350 return false;
351 }
352}
353
354static bool cs42xx8_writeable_register(struct device *dev, unsigned int reg)
355{
356 switch (reg) {
357 case CS42XX8_CHIPID:
358 case CS42XX8_STATUS:
359 return false;
360 default:
361 return true;
362 }
363}
364
365const struct regmap_config cs42xx8_regmap_config = {
366 .reg_bits = 8,
367 .val_bits = 8,
368
369 .max_register = CS42XX8_LASTREG,
370 .reg_defaults = cs42xx8_reg,
371 .num_reg_defaults = ARRAY_SIZE(cs42xx8_reg),
372 .volatile_reg = cs42xx8_volatile_register,
373 .writeable_reg = cs42xx8_writeable_register,
374 .cache_type = REGCACHE_RBTREE,
375};
376EXPORT_SYMBOL_GPL(cs42xx8_regmap_config);
377
378static int cs42xx8_codec_probe(struct snd_soc_codec *codec)
379{
380 struct cs42xx8_priv *cs42xx8 = snd_soc_codec_get_drvdata(codec);
381 struct snd_soc_dapm_context *dapm = &codec->dapm;
382
383 switch (cs42xx8->drvdata->num_adcs) {
384 case 3:
385 snd_soc_add_codec_controls(codec, cs42xx8_adc3_snd_controls,
386 ARRAY_SIZE(cs42xx8_adc3_snd_controls));
387 snd_soc_dapm_new_controls(dapm, cs42xx8_adc3_dapm_widgets,
388 ARRAY_SIZE(cs42xx8_adc3_dapm_widgets));
389 snd_soc_dapm_add_routes(dapm, cs42xx8_adc3_dapm_routes,
390 ARRAY_SIZE(cs42xx8_adc3_dapm_routes));
391 break;
392 default:
393 break;
394 }
395
396 /* Mute all DAC channels */
397 regmap_write(cs42xx8->regmap, CS42XX8_DACMUTE, CS42XX8_DACMUTE_ALL);
398
399 return 0;
400}
401
402static const struct snd_soc_codec_driver cs42xx8_driver = {
403 .probe = cs42xx8_codec_probe,
404 .idle_bias_off = true,
405
406 .controls = cs42xx8_snd_controls,
407 .num_controls = ARRAY_SIZE(cs42xx8_snd_controls),
408 .dapm_widgets = cs42xx8_dapm_widgets,
409 .num_dapm_widgets = ARRAY_SIZE(cs42xx8_dapm_widgets),
410 .dapm_routes = cs42xx8_dapm_routes,
411 .num_dapm_routes = ARRAY_SIZE(cs42xx8_dapm_routes),
412};
413
414const struct cs42xx8_driver_data cs42448_data = {
415 .name = "cs42448",
416 .num_adcs = 3,
417};
418EXPORT_SYMBOL_GPL(cs42448_data);
419
420const struct cs42xx8_driver_data cs42888_data = {
421 .name = "cs42888",
422 .num_adcs = 2,
423};
424EXPORT_SYMBOL_GPL(cs42888_data);
425
426const struct of_device_id cs42xx8_of_match[] = {
427 { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
428 { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
429 { /* sentinel */ }
430};
431MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
432EXPORT_SYMBOL_GPL(cs42xx8_of_match);
433
434int cs42xx8_probe(struct device *dev, struct regmap *regmap)
435{
436 const struct of_device_id *of_id = of_match_device(cs42xx8_of_match, dev);
437 struct cs42xx8_priv *cs42xx8;
438 int ret, val, i;
439
440 cs42xx8 = devm_kzalloc(dev, sizeof(*cs42xx8), GFP_KERNEL);
441 if (cs42xx8 == NULL)
442 return -ENOMEM;
443
444 dev_set_drvdata(dev, cs42xx8);
445
446 if (of_id)
447 cs42xx8->drvdata = of_id->data;
448
449 if (!cs42xx8->drvdata) {
450 dev_err(dev, "failed to find driver data\n");
451 return -EINVAL;
452 }
453
454 cs42xx8->clk = devm_clk_get(dev, "mclk");
455 if (IS_ERR(cs42xx8->clk)) {
456 dev_err(dev, "failed to get the clock: %ld\n",
457 PTR_ERR(cs42xx8->clk));
458 return -EINVAL;
459 }
460
461 cs42xx8->sysclk = clk_get_rate(cs42xx8->clk);
462
463 for (i = 0; i < ARRAY_SIZE(cs42xx8->supplies); i++)
464 cs42xx8->supplies[i].supply = cs42xx8_supply_names[i];
465
466 ret = devm_regulator_bulk_get(dev,
467 ARRAY_SIZE(cs42xx8->supplies), cs42xx8->supplies);
468 if (ret) {
469 dev_err(dev, "failed to request supplies: %d\n", ret);
470 return ret;
471 }
472
473 ret = regulator_bulk_enable(ARRAY_SIZE(cs42xx8->supplies),
474 cs42xx8->supplies);
475 if (ret) {
476 dev_err(dev, "failed to enable supplies: %d\n", ret);
477 return ret;
478 }
479
480 /* Make sure hardware reset done */
481 msleep(5);
482
483 cs42xx8->regmap = regmap;
484 if (IS_ERR(cs42xx8->regmap)) {
485 ret = PTR_ERR(cs42xx8->regmap);
486 dev_err(dev, "failed to allocate regmap: %d\n", ret);
487 goto err_enable;
488 }
489
490 /*
491 * We haven't marked the chip revision as volatile due to
492 * sharing a register with the right input volume; explicitly
493 * bypass the cache to read it.
494 */
495 regcache_cache_bypass(cs42xx8->regmap, true);
496
497 /* Validate the chip ID */
498 regmap_read(cs42xx8->regmap, CS42XX8_CHIPID, &val);
499 if (val < 0) {
500 dev_err(dev, "failed to get device ID: %x", val);
501 ret = -EINVAL;
502 goto err_enable;
503 }
504
505 /* The top four bits of the chip ID should be 0000 */
506 if ((val & CS42XX8_CHIPID_CHIP_ID_MASK) != 0x00) {
507 dev_err(dev, "unmatched chip ID: %d\n",
508 val & CS42XX8_CHIPID_CHIP_ID_MASK);
509 ret = -EINVAL;
510 goto err_enable;
511 }
512
513 dev_info(dev, "found device, revision %X\n",
514 val & CS42XX8_CHIPID_REV_ID_MASK);
515
516 regcache_cache_bypass(cs42xx8->regmap, false);
517
518 cs42xx8_dai.name = cs42xx8->drvdata->name;
519
520 /* Each adc supports stereo input */
521 cs42xx8_dai.capture.channels_max = cs42xx8->drvdata->num_adcs * 2;
522
523 ret = snd_soc_register_codec(dev, &cs42xx8_driver, &cs42xx8_dai, 1);
524 if (ret) {
525 dev_err(dev, "failed to register codec:%d\n", ret);
526 goto err_enable;
527 }
528
529 regcache_cache_only(cs42xx8->regmap, true);
530
531err_enable:
532 regulator_bulk_disable(ARRAY_SIZE(cs42xx8->supplies),
533 cs42xx8->supplies);
534
535 return ret;
536}
537EXPORT_SYMBOL_GPL(cs42xx8_probe);
538
539#ifdef CONFIG_PM_RUNTIME
540static int cs42xx8_runtime_resume(struct device *dev)
541{
542 struct cs42xx8_priv *cs42xx8 = dev_get_drvdata(dev);
543 int ret;
544
545 ret = clk_prepare_enable(cs42xx8->clk);
546 if (ret) {
547 dev_err(dev, "failed to enable mclk: %d\n", ret);
548 return ret;
549 }
550
551 ret = regulator_bulk_enable(ARRAY_SIZE(cs42xx8->supplies),
552 cs42xx8->supplies);
553 if (ret) {
554 dev_err(dev, "failed to enable supplies: %d\n", ret);
555 goto err_clk;
556 }
557
558 /* Make sure hardware reset done */
559 msleep(5);
560
561 regcache_cache_only(cs42xx8->regmap, false);
562
563 ret = regcache_sync(cs42xx8->regmap);
564 if (ret) {
565 dev_err(dev, "failed to sync regmap: %d\n", ret);
566 goto err_bulk;
567 }
568
569 return 0;
570
571err_bulk:
572 regulator_bulk_disable(ARRAY_SIZE(cs42xx8->supplies),
573 cs42xx8->supplies);
574err_clk:
575 clk_disable_unprepare(cs42xx8->clk);
576
577 return ret;
578}
579
580static int cs42xx8_runtime_suspend(struct device *dev)
581{
582 struct cs42xx8_priv *cs42xx8 = dev_get_drvdata(dev);
583
584 regcache_cache_only(cs42xx8->regmap, true);
585
586 regulator_bulk_disable(ARRAY_SIZE(cs42xx8->supplies),
587 cs42xx8->supplies);
588
589 clk_disable_unprepare(cs42xx8->clk);
590
591 return 0;
592}
593#endif
594
595const struct dev_pm_ops cs42xx8_pm = {
596 SET_RUNTIME_PM_OPS(cs42xx8_runtime_suspend, cs42xx8_runtime_resume, NULL)
597};
598EXPORT_SYMBOL_GPL(cs42xx8_pm);
599
600MODULE_DESCRIPTION("Cirrus Logic CS42448/CS42888 ALSA SoC Codec Driver");
601MODULE_AUTHOR("Freescale Semiconductor, Inc.");
602MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs42xx8.h b/sound/soc/codecs/cs42xx8.h
new file mode 100644
index 000000000000..da0b94aee419
--- /dev/null
+++ b/sound/soc/codecs/cs42xx8.h
@@ -0,0 +1,238 @@
1/*
2 * cs42xx8.h - Cirrus Logic CS42448/CS42888 Audio CODEC driver header file
3 *
4 * Copyright (C) 2014 Freescale Semiconductor, Inc.
5 *
6 * Author: Nicolin Chen <Guangyu.Chen@freescale.com>
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
11 */
12
13#ifndef _CS42XX8_H
14#define _CS42XX8_H
15
16struct cs42xx8_driver_data {
17 char name[32];
18 int num_adcs;
19};
20
21extern const struct dev_pm_ops cs42xx8_pm;
22extern const struct cs42xx8_driver_data cs42448_data;
23extern const struct cs42xx8_driver_data cs42888_data;
24extern const struct regmap_config cs42xx8_regmap_config;
25int cs42xx8_probe(struct device *dev, struct regmap *regmap);
26
27/* CS42888 register map */
28#define CS42XX8_CHIPID 0x01 /* Chip ID */
29#define CS42XX8_PWRCTL 0x02 /* Power Control */
30#define CS42XX8_FUNCMOD 0x03 /* Functional Mode */
31#define CS42XX8_INTF 0x04 /* Interface Formats */
32#define CS42XX8_ADCCTL 0x05 /* ADC Control */
33#define CS42XX8_TXCTL 0x06 /* Transition Control */
34#define CS42XX8_DACMUTE 0x07 /* DAC Mute Control */
35#define CS42XX8_VOLAOUT1 0x08 /* Volume Control AOUT1 */
36#define CS42XX8_VOLAOUT2 0x09 /* Volume Control AOUT2 */
37#define CS42XX8_VOLAOUT3 0x0A /* Volume Control AOUT3 */
38#define CS42XX8_VOLAOUT4 0x0B /* Volume Control AOUT4 */
39#define CS42XX8_VOLAOUT5 0x0C /* Volume Control AOUT5 */
40#define CS42XX8_VOLAOUT6 0x0D /* Volume Control AOUT6 */
41#define CS42XX8_VOLAOUT7 0x0E /* Volume Control AOUT7 */
42#define CS42XX8_VOLAOUT8 0x0F /* Volume Control AOUT8 */
43#define CS42XX8_DACINV 0x10 /* DAC Channel Invert */
44#define CS42XX8_VOLAIN1 0x11 /* Volume Control AIN1 */
45#define CS42XX8_VOLAIN2 0x12 /* Volume Control AIN2 */
46#define CS42XX8_VOLAIN3 0x13 /* Volume Control AIN3 */
47#define CS42XX8_VOLAIN4 0x14 /* Volume Control AIN4 */
48#define CS42XX8_VOLAIN5 0x15 /* Volume Control AIN5 */
49#define CS42XX8_VOLAIN6 0x16 /* Volume Control AIN6 */
50#define CS42XX8_ADCINV 0x17 /* ADC Channel Invert */
51#define CS42XX8_STATUSCTL 0x18 /* Status Control */
52#define CS42XX8_STATUS 0x19 /* Status */
53#define CS42XX8_STATUSM 0x1A /* Status Mask */
54#define CS42XX8_MUTEC 0x1B /* MUTEC Pin Control */
55
56#define CS42XX8_FIRSTREG CS42XX8_CHIPID
57#define CS42XX8_LASTREG CS42XX8_MUTEC
58#define CS42XX8_NUMREGS (CS42XX8_LASTREG - CS42XX8_FIRSTREG + 1)
59#define CS42XX8_I2C_INCR 0x80
60
61/* Chip I.D. and Revision Register (Address 01h) */
62#define CS42XX8_CHIPID_CHIP_ID_MASK 0xF0
63#define CS42XX8_CHIPID_REV_ID_MASK 0x0F
64
65/* Power Control (Address 02h) */
66#define CS42XX8_PWRCTL_PDN_ADC3_SHIFT 7
67#define CS42XX8_PWRCTL_PDN_ADC3_MASK (1 << CS42XX8_PWRCTL_PDN_ADC3_SHIFT)
68#define CS42XX8_PWRCTL_PDN_ADC3 (1 << CS42XX8_PWRCTL_PDN_ADC3_SHIFT)
69#define CS42XX8_PWRCTL_PDN_ADC2_SHIFT 6
70#define CS42XX8_PWRCTL_PDN_ADC2_MASK (1 << CS42XX8_PWRCTL_PDN_ADC2_SHIFT)
71#define CS42XX8_PWRCTL_PDN_ADC2 (1 << CS42XX8_PWRCTL_PDN_ADC2_SHIFT)
72#define CS42XX8_PWRCTL_PDN_ADC1_SHIFT 5
73#define CS42XX8_PWRCTL_PDN_ADC1_MASK (1 << CS42XX8_PWRCTL_PDN_ADC1_SHIFT)
74#define CS42XX8_PWRCTL_PDN_ADC1 (1 << CS42XX8_PWRCTL_PDN_ADC1_SHIFT)
75#define CS42XX8_PWRCTL_PDN_DAC4_SHIFT 4
76#define CS42XX8_PWRCTL_PDN_DAC4_MASK (1 << CS42XX8_PWRCTL_PDN_DAC4_SHIFT)
77#define CS42XX8_PWRCTL_PDN_DAC4 (1 << CS42XX8_PWRCTL_PDN_DAC4_SHIFT)
78#define CS42XX8_PWRCTL_PDN_DAC3_SHIFT 3
79#define CS42XX8_PWRCTL_PDN_DAC3_MASK (1 << CS42XX8_PWRCTL_PDN_DAC3_SHIFT)
80#define CS42XX8_PWRCTL_PDN_DAC3 (1 << CS42XX8_PWRCTL_PDN_DAC3_SHIFT)
81#define CS42XX8_PWRCTL_PDN_DAC2_SHIFT 2
82#define CS42XX8_PWRCTL_PDN_DAC2_MASK (1 << CS42XX8_PWRCTL_PDN_DAC2_SHIFT)
83#define CS42XX8_PWRCTL_PDN_DAC2 (1 << CS42XX8_PWRCTL_PDN_DAC2_SHIFT)
84#define CS42XX8_PWRCTL_PDN_DAC1_SHIFT 1
85#define CS42XX8_PWRCTL_PDN_DAC1_MASK (1 << CS42XX8_PWRCTL_PDN_DAC1_SHIFT)
86#define CS42XX8_PWRCTL_PDN_DAC1 (1 << CS42XX8_PWRCTL_PDN_DAC1_SHIFT)
87#define CS42XX8_PWRCTL_PDN_SHIFT 0
88#define CS42XX8_PWRCTL_PDN_MASK (1 << CS42XX8_PWRCTL_PDN_SHIFT)
89#define CS42XX8_PWRCTL_PDN (1 << CS42XX8_PWRCTL_PDN_SHIFT)
90
91/* Functional Mode (Address 03h) */
92#define CS42XX8_FUNCMOD_DAC_FM_SHIFT 6
93#define CS42XX8_FUNCMOD_DAC_FM_WIDTH 2
94#define CS42XX8_FUNCMOD_DAC_FM_MASK (((1 << CS42XX8_FUNCMOD_DAC_FM_WIDTH) - 1) << CS42XX8_FUNCMOD_DAC_FM_SHIFT)
95#define CS42XX8_FUNCMOD_DAC_FM(v) ((v) << CS42XX8_FUNCMOD_DAC_FM_SHIFT)
96#define CS42XX8_FUNCMOD_ADC_FM_SHIFT 4
97#define CS42XX8_FUNCMOD_ADC_FM_WIDTH 2
98#define CS42XX8_FUNCMOD_ADC_FM_MASK (((1 << CS42XX8_FUNCMOD_ADC_FM_WIDTH) - 1) << CS42XX8_FUNCMOD_ADC_FM_SHIFT)
99#define CS42XX8_FUNCMOD_ADC_FM(v) ((v) << CS42XX8_FUNCMOD_ADC_FM_SHIFT)
100#define CS42XX8_FUNCMOD_xC_FM_MASK(x) ((x) ? CS42XX8_FUNCMOD_DAC_FM_MASK : CS42XX8_FUNCMOD_ADC_FM_MASK)
101#define CS42XX8_FUNCMOD_xC_FM(x, v) ((x) ? CS42XX8_FUNCMOD_DAC_FM(v) : CS42XX8_FUNCMOD_ADC_FM(v))
102#define CS42XX8_FUNCMOD_MFREQ_SHIFT 1
103#define CS42XX8_FUNCMOD_MFREQ_WIDTH 3
104#define CS42XX8_FUNCMOD_MFREQ_MASK (((1 << CS42XX8_FUNCMOD_MFREQ_WIDTH) - 1) << CS42XX8_FUNCMOD_MFREQ_SHIFT)
105#define CS42XX8_FUNCMOD_MFREQ_256(s) ((0 << CS42XX8_FUNCMOD_MFREQ_SHIFT) >> (s >> 1))
106#define CS42XX8_FUNCMOD_MFREQ_384(s) ((1 << CS42XX8_FUNCMOD_MFREQ_SHIFT) >> (s >> 1))
107#define CS42XX8_FUNCMOD_MFREQ_512(s) ((2 << CS42XX8_FUNCMOD_MFREQ_SHIFT) >> (s >> 1))
108#define CS42XX8_FUNCMOD_MFREQ_768(s) ((3 << CS42XX8_FUNCMOD_MFREQ_SHIFT) >> (s >> 1))
109#define CS42XX8_FUNCMOD_MFREQ_1024(s) ((4 << CS42XX8_FUNCMOD_MFREQ_SHIFT) >> (s >> 1))
110
111#define CS42XX8_FM_SINGLE 0
112#define CS42XX8_FM_DOUBLE 1
113#define CS42XX8_FM_QUAD 2
114#define CS42XX8_FM_AUTO 3
115
116/* Interface Formats (Address 04h) */
117#define CS42XX8_INTF_FREEZE_SHIFT 7
118#define CS42XX8_INTF_FREEZE_MASK (1 << CS42XX8_INTF_FREEZE_SHIFT)
119#define CS42XX8_INTF_FREEZE (1 << CS42XX8_INTF_FREEZE_SHIFT)
120#define CS42XX8_INTF_AUX_DIF_SHIFT 6
121#define CS42XX8_INTF_AUX_DIF_MASK (1 << CS42XX8_INTF_AUX_DIF_SHIFT)
122#define CS42XX8_INTF_AUX_DIF (1 << CS42XX8_INTF_AUX_DIF_SHIFT)
123#define CS42XX8_INTF_DAC_DIF_SHIFT 3
124#define CS42XX8_INTF_DAC_DIF_WIDTH 3
125#define CS42XX8_INTF_DAC_DIF_MASK (((1 << CS42XX8_INTF_DAC_DIF_WIDTH) - 1) << CS42XX8_INTF_DAC_DIF_SHIFT)
126#define CS42XX8_INTF_DAC_DIF_LEFTJ (0 << CS42XX8_INTF_DAC_DIF_SHIFT)
127#define CS42XX8_INTF_DAC_DIF_I2S (1 << CS42XX8_INTF_DAC_DIF_SHIFT)
128#define CS42XX8_INTF_DAC_DIF_RIGHTJ (2 << CS42XX8_INTF_DAC_DIF_SHIFT)
129#define CS42XX8_INTF_DAC_DIF_RIGHTJ_16 (3 << CS42XX8_INTF_DAC_DIF_SHIFT)
130#define CS42XX8_INTF_DAC_DIF_ONELINE_20 (4 << CS42XX8_INTF_DAC_DIF_SHIFT)
131#define CS42XX8_INTF_DAC_DIF_ONELINE_24 (6 << CS42XX8_INTF_DAC_DIF_SHIFT)
132#define CS42XX8_INTF_DAC_DIF_TDM (7 << CS42XX8_INTF_DAC_DIF_SHIFT)
133#define CS42XX8_INTF_ADC_DIF_SHIFT 0
134#define CS42XX8_INTF_ADC_DIF_WIDTH 3
135#define CS42XX8_INTF_ADC_DIF_MASK (((1 << CS42XX8_INTF_ADC_DIF_WIDTH) - 1) << CS42XX8_INTF_ADC_DIF_SHIFT)
136#define CS42XX8_INTF_ADC_DIF_LEFTJ (0 << CS42XX8_INTF_ADC_DIF_SHIFT)
137#define CS42XX8_INTF_ADC_DIF_I2S (1 << CS42XX8_INTF_ADC_DIF_SHIFT)
138#define CS42XX8_INTF_ADC_DIF_RIGHTJ (2 << CS42XX8_INTF_ADC_DIF_SHIFT)
139#define CS42XX8_INTF_ADC_DIF_RIGHTJ_16 (3 << CS42XX8_INTF_ADC_DIF_SHIFT)
140#define CS42XX8_INTF_ADC_DIF_ONELINE_20 (4 << CS42XX8_INTF_ADC_DIF_SHIFT)
141#define CS42XX8_INTF_ADC_DIF_ONELINE_24 (6 << CS42XX8_INTF_ADC_DIF_SHIFT)
142#define CS42XX8_INTF_ADC_DIF_TDM (7 << CS42XX8_INTF_ADC_DIF_SHIFT)
143
144/* ADC Control & DAC De-Emphasis (Address 05h) */
145#define CS42XX8_ADCCTL_ADC_HPF_FREEZE_SHIFT 7
146#define CS42XX8_ADCCTL_ADC_HPF_FREEZE_MASK (1 << CS42XX8_ADCCTL_ADC_HPF_FREEZE_SHIFT)
147#define CS42XX8_ADCCTL_ADC_HPF_FREEZE (1 << CS42XX8_ADCCTL_ADC_HPF_FREEZE_SHIFT)
148#define CS42XX8_ADCCTL_DAC_DEM_SHIFT 5
149#define CS42XX8_ADCCTL_DAC_DEM_MASK (1 << CS42XX8_ADCCTL_DAC_DEM_SHIFT)
150#define CS42XX8_ADCCTL_DAC_DEM (1 << CS42XX8_ADCCTL_DAC_DEM_SHIFT)
151#define CS42XX8_ADCCTL_ADC1_SINGLE_SHIFT 4
152#define CS42XX8_ADCCTL_ADC1_SINGLE_MASK (1 << CS42XX8_ADCCTL_ADC1_SINGLE_SHIFT)
153#define CS42XX8_ADCCTL_ADC1_SINGLE (1 << CS42XX8_ADCCTL_ADC1_SINGLE_SHIFT)
154#define CS42XX8_ADCCTL_ADC2_SINGLE_SHIFT 3
155#define CS42XX8_ADCCTL_ADC2_SINGLE_MASK (1 << CS42XX8_ADCCTL_ADC2_SINGLE_SHIFT)
156#define CS42XX8_ADCCTL_ADC2_SINGLE (1 << CS42XX8_ADCCTL_ADC2_SINGLE_SHIFT)
157#define CS42XX8_ADCCTL_ADC3_SINGLE_SHIFT 2
158#define CS42XX8_ADCCTL_ADC3_SINGLE_MASK (1 << CS42XX8_ADCCTL_ADC3_SINGLE_SHIFT)
159#define CS42XX8_ADCCTL_ADC3_SINGLE (1 << CS42XX8_ADCCTL_ADC3_SINGLE_SHIFT)
160#define CS42XX8_ADCCTL_AIN5_MUX_SHIFT 1
161#define CS42XX8_ADCCTL_AIN5_MUX_MASK (1 << CS42XX8_ADCCTL_AIN5_MUX_SHIFT)
162#define CS42XX8_ADCCTL_AIN5_MUX (1 << CS42XX8_ADCCTL_AIN5_MUX_SHIFT)
163#define CS42XX8_ADCCTL_AIN6_MUX_SHIFT 0
164#define CS42XX8_ADCCTL_AIN6_MUX_MASK (1 << CS42XX8_ADCCTL_AIN6_MUX_SHIFT)
165#define CS42XX8_ADCCTL_AIN6_MUX (1 << CS42XX8_ADCCTL_AIN6_MUX_SHIFT)
166
167/* Transition Control (Address 06h) */
168#define CS42XX8_TXCTL_DAC_SNGVOL_SHIFT 7
169#define CS42XX8_TXCTL_DAC_SNGVOL_MASK (1 << CS42XX8_TXCTL_DAC_SNGVOL_SHIFT)
170#define CS42XX8_TXCTL_DAC_SNGVOL (1 << CS42XX8_TXCTL_DAC_SNGVOL_SHIFT)
171#define CS42XX8_TXCTL_DAC_SZC_SHIFT 5
172#define CS42XX8_TXCTL_DAC_SZC_WIDTH 2
173#define CS42XX8_TXCTL_DAC_SZC_MASK (((1 << CS42XX8_TXCTL_DAC_SZC_WIDTH) - 1) << CS42XX8_TXCTL_DAC_SZC_SHIFT)
174#define CS42XX8_TXCTL_DAC_SZC_IC (0 << CS42XX8_TXCTL_DAC_SZC_SHIFT)
175#define CS42XX8_TXCTL_DAC_SZC_ZC (1 << CS42XX8_TXCTL_DAC_SZC_SHIFT)
176#define CS42XX8_TXCTL_DAC_SZC_SR (2 << CS42XX8_TXCTL_DAC_SZC_SHIFT)
177#define CS42XX8_TXCTL_DAC_SZC_SRZC (3 << CS42XX8_TXCTL_DAC_SZC_SHIFT)
178#define CS42XX8_TXCTL_AMUTE_SHIFT 4
179#define CS42XX8_TXCTL_AMUTE_MASK (1 << CS42XX8_TXCTL_AMUTE_SHIFT)
180#define CS42XX8_TXCTL_AMUTE (1 << CS42XX8_TXCTL_AMUTE_SHIFT)
181#define CS42XX8_TXCTL_MUTE_ADC_SP_SHIFT 3
182#define CS42XX8_TXCTL_MUTE_ADC_SP_MASK (1 << CS42XX8_TXCTL_MUTE_ADC_SP_SHIFT)
183#define CS42XX8_TXCTL_MUTE_ADC_SP (1 << CS42XX8_TXCTL_MUTE_ADC_SP_SHIFT)
184#define CS42XX8_TXCTL_ADC_SNGVOL_SHIFT 2
185#define CS42XX8_TXCTL_ADC_SNGVOL_MASK (1 << CS42XX8_TXCTL_ADC_SNGVOL_SHIFT)
186#define CS42XX8_TXCTL_ADC_SNGVOL (1 << CS42XX8_TXCTL_ADC_SNGVOL_SHIFT)
187#define CS42XX8_TXCTL_ADC_SZC_SHIFT 0
188#define CS42XX8_TXCTL_ADC_SZC_MASK (((1 << CS42XX8_TXCTL_ADC_SZC_WIDTH) - 1) << CS42XX8_TXCTL_ADC_SZC_SHIFT)
189#define CS42XX8_TXCTL_ADC_SZC_IC (0 << CS42XX8_TXCTL_ADC_SZC_SHIFT)
190#define CS42XX8_TXCTL_ADC_SZC_ZC (1 << CS42XX8_TXCTL_ADC_SZC_SHIFT)
191#define CS42XX8_TXCTL_ADC_SZC_SR (2 << CS42XX8_TXCTL_ADC_SZC_SHIFT)
192#define CS42XX8_TXCTL_ADC_SZC_SRZC (3 << CS42XX8_TXCTL_ADC_SZC_SHIFT)
193
194/* DAC Channel Mute (Address 07h) */
195#define CS42XX8_DACMUTE_AOUT(n) (0x1 << n)
196#define CS42XX8_DACMUTE_ALL 0xff
197
198/* Status Control (Address 18h)*/
199#define CS42XX8_STATUSCTL_INI_SHIFT 2
200#define CS42XX8_STATUSCTL_INI_WIDTH 2
201#define CS42XX8_STATUSCTL_INI_MASK (((1 << CS42XX8_STATUSCTL_INI_WIDTH) - 1) << CS42XX8_STATUSCTL_INI_SHIFT)
202#define CS42XX8_STATUSCTL_INT_ACTIVE_HIGH (0 << CS42XX8_STATUSCTL_INI_SHIFT)
203#define CS42XX8_STATUSCTL_INT_ACTIVE_LOW (1 << CS42XX8_STATUSCTL_INI_SHIFT)
204#define CS42XX8_STATUSCTL_INT_OPEN_DRAIN (2 << CS42XX8_STATUSCTL_INI_SHIFT)
205
206/* Status (Address 19h)*/
207#define CS42XX8_STATUS_DAC_CLK_ERR_SHIFT 4
208#define CS42XX8_STATUS_DAC_CLK_ERR_MASK (1 << CS42XX8_STATUS_DAC_CLK_ERR_SHIFT)
209#define CS42XX8_STATUS_ADC_CLK_ERR_SHIFT 3
210#define CS42XX8_STATUS_ADC_CLK_ERR_MASK (1 << CS42XX8_STATUS_ADC_CLK_ERR_SHIFT)
211#define CS42XX8_STATUS_ADC3_OVFL_SHIFT 2
212#define CS42XX8_STATUS_ADC3_OVFL_MASK (1 << CS42XX8_STATUS_ADC3_OVFL_SHIFT)
213#define CS42XX8_STATUS_ADC2_OVFL_SHIFT 1
214#define CS42XX8_STATUS_ADC2_OVFL_MASK (1 << CS42XX8_STATUS_ADC2_OVFL_SHIFT)
215#define CS42XX8_STATUS_ADC1_OVFL_SHIFT 0
216#define CS42XX8_STATUS_ADC1_OVFL_MASK (1 << CS42XX8_STATUS_ADC1_OVFL_SHIFT)
217
218/* Status Mask (Address 1Ah) */
219#define CS42XX8_STATUS_DAC_CLK_ERR_M_SHIFT 4
220#define CS42XX8_STATUS_DAC_CLK_ERR_M_MASK (1 << CS42XX8_STATUS_DAC_CLK_ERR_M_SHIFT)
221#define CS42XX8_STATUS_ADC_CLK_ERR_M_SHIFT 3
222#define CS42XX8_STATUS_ADC_CLK_ERR_M_MASK (1 << CS42XX8_STATUS_ADC_CLK_ERR_M_SHIFT)
223#define CS42XX8_STATUS_ADC3_OVFL_M_SHIFT 2
224#define CS42XX8_STATUS_ADC3_OVFL_M_MASK (1 << CS42XX8_STATUS_ADC3_OVFL_M_SHIFT)
225#define CS42XX8_STATUS_ADC2_OVFL_M_SHIFT 1
226#define CS42XX8_STATUS_ADC2_OVFL_M_MASK (1 << CS42XX8_STATUS_ADC2_OVFL_M_SHIFT)
227#define CS42XX8_STATUS_ADC1_OVFL_M_SHIFT 0
228#define CS42XX8_STATUS_ADC1_OVFL_M_MASK (1 << CS42XX8_STATUS_ADC1_OVFL_M_SHIFT)
229
230/* MUTEC Pin Control (Address 1Bh) */
231#define CS42XX8_MUTEC_MCPOLARITY_SHIFT 1
232#define CS42XX8_MUTEC_MCPOLARITY_MASK (1 << CS42XX8_MUTEC_MCPOLARITY_SHIFT)
233#define CS42XX8_MUTEC_MCPOLARITY_ACTIVE_LOW (0 << CS42XX8_MUTEC_MCPOLARITY_SHIFT)
234#define CS42XX8_MUTEC_MCPOLARITY_ACTIVE_HIGH (1 << CS42XX8_MUTEC_MCPOLARITY_SHIFT)
235#define CS42XX8_MUTEC_MUTEC_ACTIVE_SHIFT 0
236#define CS42XX8_MUTEC_MUTEC_ACTIVE_MASK (1 << CS42XX8_MUTEC_MUTEC_ACTIVE_SHIFT)
237#define CS42XX8_MUTEC_MUTEC_ACTIVE (1 << CS42XX8_MUTEC_MUTEC_ACTIVE_SHIFT)
238#endif /* _CS42XX8_H */
diff --git a/sound/soc/codecs/da7210.c b/sound/soc/codecs/da7210.c
index e62e294a8033..137e8ebc092c 100644
--- a/sound/soc/codecs/da7210.c
+++ b/sound/soc/codecs/da7210.c
@@ -307,29 +307,29 @@ static const char * const da7210_hpf_cutoff_txt[] = {
307 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi" 307 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
308}; 308};
309 309
310static const struct soc_enum da7210_dac_hpf_cutoff = 310static SOC_ENUM_SINGLE_DECL(da7210_dac_hpf_cutoff,
311 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt); 311 DA7210_DAC_HPF, 0, da7210_hpf_cutoff_txt);
312 312
313static const struct soc_enum da7210_adc_hpf_cutoff = 313static SOC_ENUM_SINGLE_DECL(da7210_adc_hpf_cutoff,
314 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt); 314 DA7210_ADC_HPF, 0, da7210_hpf_cutoff_txt);
315 315
316/* ADC and DAC voice (8kHz) high pass cutoff value */ 316/* ADC and DAC voice (8kHz) high pass cutoff value */
317static const char * const da7210_vf_cutoff_txt[] = { 317static const char * const da7210_vf_cutoff_txt[] = {
318 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz" 318 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
319}; 319};
320 320
321static const struct soc_enum da7210_dac_vf_cutoff = 321static SOC_ENUM_SINGLE_DECL(da7210_dac_vf_cutoff,
322 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt); 322 DA7210_DAC_HPF, 4, da7210_vf_cutoff_txt);
323 323
324static const struct soc_enum da7210_adc_vf_cutoff = 324static SOC_ENUM_SINGLE_DECL(da7210_adc_vf_cutoff,
325 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt); 325 DA7210_ADC_HPF, 4, da7210_vf_cutoff_txt);
326 326
327static const char *da7210_hp_mode_txt[] = { 327static const char *da7210_hp_mode_txt[] = {
328 "Class H", "Class G" 328 "Class H", "Class G"
329}; 329};
330 330
331static const struct soc_enum da7210_hp_mode_sel = 331static SOC_ENUM_SINGLE_DECL(da7210_hp_mode_sel,
332 SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt); 332 DA7210_HP_CFG, 0, da7210_hp_mode_txt);
333 333
334/* ALC can be enabled only if noise suppression is disabled */ 334/* ALC can be enabled only if noise suppression is disabled */
335static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol, 335static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
@@ -1071,17 +1071,9 @@ static struct snd_soc_dai_driver da7210_dai = {
1071static int da7210_probe(struct snd_soc_codec *codec) 1071static int da7210_probe(struct snd_soc_codec *codec)
1072{ 1072{
1073 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); 1073 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
1074 int ret;
1075 1074
1076 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); 1075 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
1077 1076
1078 codec->control_data = da7210->regmap;
1079 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1080 if (ret < 0) {
1081 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1082 return ret;
1083 }
1084
1085 da7210->mclk_rate = 0; /* This will be set from set_sysclk() */ 1077 da7210->mclk_rate = 0; /* This will be set from set_sysclk() */
1086 da7210->master = 0; /* This will be set from set_fmt() */ 1078 da7210->master = 0; /* This will be set from set_fmt() */
1087 1079
diff --git a/sound/soc/codecs/da7213.c b/sound/soc/codecs/da7213.c
index 0c77e7ad7423..738fa18a50d2 100644
--- a/sound/soc/codecs/da7213.c
+++ b/sound/soc/codecs/da7213.c
@@ -63,30 +63,30 @@ static const char * const da7213_voice_hpf_corner_txt[] = {
63 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz" 63 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
64}; 64};
65 65
66static const struct soc_enum da7213_dac_voice_hpf_corner = 66static SOC_ENUM_SINGLE_DECL(da7213_dac_voice_hpf_corner,
67 SOC_ENUM_SINGLE(DA7213_DAC_FILTERS1, DA7213_VOICE_HPF_CORNER_SHIFT, 67 DA7213_DAC_FILTERS1,
68 DA7213_VOICE_HPF_CORNER_MAX, 68 DA7213_VOICE_HPF_CORNER_SHIFT,
69 da7213_voice_hpf_corner_txt); 69 da7213_voice_hpf_corner_txt);
70 70
71static const struct soc_enum da7213_adc_voice_hpf_corner = 71static SOC_ENUM_SINGLE_DECL(da7213_adc_voice_hpf_corner,
72 SOC_ENUM_SINGLE(DA7213_ADC_FILTERS1, DA7213_VOICE_HPF_CORNER_SHIFT, 72 DA7213_ADC_FILTERS1,
73 DA7213_VOICE_HPF_CORNER_MAX, 73 DA7213_VOICE_HPF_CORNER_SHIFT,
74 da7213_voice_hpf_corner_txt); 74 da7213_voice_hpf_corner_txt);
75 75
76/* ADC and DAC high pass filter cutoff value */ 76/* ADC and DAC high pass filter cutoff value */
77static const char * const da7213_audio_hpf_corner_txt[] = { 77static const char * const da7213_audio_hpf_corner_txt[] = {
78 "Fs/24000", "Fs/12000", "Fs/6000", "Fs/3000" 78 "Fs/24000", "Fs/12000", "Fs/6000", "Fs/3000"
79}; 79};
80 80
81static const struct soc_enum da7213_dac_audio_hpf_corner = 81static SOC_ENUM_SINGLE_DECL(da7213_dac_audio_hpf_corner,
82 SOC_ENUM_SINGLE(DA7213_DAC_FILTERS1, DA7213_AUDIO_HPF_CORNER_SHIFT, 82 DA7213_DAC_FILTERS1
83 DA7213_AUDIO_HPF_CORNER_MAX, 83 , DA7213_AUDIO_HPF_CORNER_SHIFT,
84 da7213_audio_hpf_corner_txt); 84 da7213_audio_hpf_corner_txt);
85 85
86static const struct soc_enum da7213_adc_audio_hpf_corner = 86static SOC_ENUM_SINGLE_DECL(da7213_adc_audio_hpf_corner,
87 SOC_ENUM_SINGLE(DA7213_ADC_FILTERS1, DA7213_AUDIO_HPF_CORNER_SHIFT, 87 DA7213_ADC_FILTERS1,
88 DA7213_AUDIO_HPF_CORNER_MAX, 88 DA7213_AUDIO_HPF_CORNER_SHIFT,
89 da7213_audio_hpf_corner_txt); 89 da7213_audio_hpf_corner_txt);
90 90
91/* Gain ramping rate value */ 91/* Gain ramping rate value */
92static const char * const da7213_gain_ramp_rate_txt[] = { 92static const char * const da7213_gain_ramp_rate_txt[] = {
@@ -94,52 +94,50 @@ static const char * const da7213_gain_ramp_rate_txt[] = {
94 "nominal rate / 32" 94 "nominal rate / 32"
95}; 95};
96 96
97static const struct soc_enum da7213_gain_ramp_rate = 97static SOC_ENUM_SINGLE_DECL(da7213_gain_ramp_rate,
98 SOC_ENUM_SINGLE(DA7213_GAIN_RAMP_CTRL, DA7213_GAIN_RAMP_RATE_SHIFT, 98 DA7213_GAIN_RAMP_CTRL,
99 DA7213_GAIN_RAMP_RATE_MAX, da7213_gain_ramp_rate_txt); 99 DA7213_GAIN_RAMP_RATE_SHIFT,
100 da7213_gain_ramp_rate_txt);
100 101
101/* DAC noise gate setup time value */ 102/* DAC noise gate setup time value */
102static const char * const da7213_dac_ng_setup_time_txt[] = { 103static const char * const da7213_dac_ng_setup_time_txt[] = {
103 "256 samples", "512 samples", "1024 samples", "2048 samples" 104 "256 samples", "512 samples", "1024 samples", "2048 samples"
104}; 105};
105 106
106static const struct soc_enum da7213_dac_ng_setup_time = 107static SOC_ENUM_SINGLE_DECL(da7213_dac_ng_setup_time,
107 SOC_ENUM_SINGLE(DA7213_DAC_NG_SETUP_TIME, 108 DA7213_DAC_NG_SETUP_TIME,
108 DA7213_DAC_NG_SETUP_TIME_SHIFT, 109 DA7213_DAC_NG_SETUP_TIME_SHIFT,
109 DA7213_DAC_NG_SETUP_TIME_MAX, 110 da7213_dac_ng_setup_time_txt);
110 da7213_dac_ng_setup_time_txt);
111 111
112/* DAC noise gate rampup rate value */ 112/* DAC noise gate rampup rate value */
113static const char * const da7213_dac_ng_rampup_txt[] = { 113static const char * const da7213_dac_ng_rampup_txt[] = {
114 "0.02 ms/dB", "0.16 ms/dB" 114 "0.02 ms/dB", "0.16 ms/dB"
115}; 115};
116 116
117static const struct soc_enum da7213_dac_ng_rampup_rate = 117static SOC_ENUM_SINGLE_DECL(da7213_dac_ng_rampup_rate,
118 SOC_ENUM_SINGLE(DA7213_DAC_NG_SETUP_TIME, 118 DA7213_DAC_NG_SETUP_TIME,
119 DA7213_DAC_NG_RAMPUP_RATE_SHIFT, 119 DA7213_DAC_NG_RAMPUP_RATE_SHIFT,
120 DA7213_DAC_NG_RAMP_RATE_MAX, 120 da7213_dac_ng_rampup_txt);
121 da7213_dac_ng_rampup_txt);
122 121
123/* DAC noise gate rampdown rate value */ 122/* DAC noise gate rampdown rate value */
124static const char * const da7213_dac_ng_rampdown_txt[] = { 123static const char * const da7213_dac_ng_rampdown_txt[] = {
125 "0.64 ms/dB", "20.48 ms/dB" 124 "0.64 ms/dB", "20.48 ms/dB"
126}; 125};
127 126
128static const struct soc_enum da7213_dac_ng_rampdown_rate = 127static SOC_ENUM_SINGLE_DECL(da7213_dac_ng_rampdown_rate,
129 SOC_ENUM_SINGLE(DA7213_DAC_NG_SETUP_TIME, 128 DA7213_DAC_NG_SETUP_TIME,
130 DA7213_DAC_NG_RAMPDN_RATE_SHIFT, 129 DA7213_DAC_NG_RAMPDN_RATE_SHIFT,
131 DA7213_DAC_NG_RAMP_RATE_MAX, 130 da7213_dac_ng_rampdown_txt);
132 da7213_dac_ng_rampdown_txt);
133 131
134/* DAC soft mute rate value */ 132/* DAC soft mute rate value */
135static const char * const da7213_dac_soft_mute_rate_txt[] = { 133static const char * const da7213_dac_soft_mute_rate_txt[] = {
136 "1", "2", "4", "8", "16", "32", "64" 134 "1", "2", "4", "8", "16", "32", "64"
137}; 135};
138 136
139static const struct soc_enum da7213_dac_soft_mute_rate = 137static SOC_ENUM_SINGLE_DECL(da7213_dac_soft_mute_rate,
140 SOC_ENUM_SINGLE(DA7213_DAC_FILTERS5, DA7213_DAC_SOFTMUTE_RATE_SHIFT, 138 DA7213_DAC_FILTERS5,
141 DA7213_DAC_SOFTMUTE_RATE_MAX, 139 DA7213_DAC_SOFTMUTE_RATE_SHIFT,
142 da7213_dac_soft_mute_rate_txt); 140 da7213_dac_soft_mute_rate_txt);
143 141
144/* ALC Attack Rate select */ 142/* ALC Attack Rate select */
145static const char * const da7213_alc_attack_rate_txt[] = { 143static const char * const da7213_alc_attack_rate_txt[] = {
@@ -147,9 +145,10 @@ static const char * const da7213_alc_attack_rate_txt[] = {
147 "5632/fs", "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs" 145 "5632/fs", "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs"
148}; 146};
149 147
150static const struct soc_enum da7213_alc_attack_rate = 148static SOC_ENUM_SINGLE_DECL(da7213_alc_attack_rate,
151 SOC_ENUM_SINGLE(DA7213_ALC_CTRL2, DA7213_ALC_ATTACK_SHIFT, 149 DA7213_ALC_CTRL2,
152 DA7213_ALC_ATTACK_MAX, da7213_alc_attack_rate_txt); 150 DA7213_ALC_ATTACK_SHIFT,
151 da7213_alc_attack_rate_txt);
153 152
154/* ALC Release Rate select */ 153/* ALC Release Rate select */
155static const char * const da7213_alc_release_rate_txt[] = { 154static const char * const da7213_alc_release_rate_txt[] = {
@@ -157,9 +156,10 @@ static const char * const da7213_alc_release_rate_txt[] = {
157 "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs" 156 "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs"
158}; 157};
159 158
160static const struct soc_enum da7213_alc_release_rate = 159static SOC_ENUM_SINGLE_DECL(da7213_alc_release_rate,
161 SOC_ENUM_SINGLE(DA7213_ALC_CTRL2, DA7213_ALC_RELEASE_SHIFT, 160 DA7213_ALC_CTRL2,
162 DA7213_ALC_RELEASE_MAX, da7213_alc_release_rate_txt); 161 DA7213_ALC_RELEASE_SHIFT,
162 da7213_alc_release_rate_txt);
163 163
164/* ALC Hold Time select */ 164/* ALC Hold Time select */
165static const char * const da7213_alc_hold_time_txt[] = { 165static const char * const da7213_alc_hold_time_txt[] = {
@@ -168,22 +168,25 @@ static const char * const da7213_alc_hold_time_txt[] = {
168 "253952/fs", "507904/fs", "1015808/fs", "2031616/fs" 168 "253952/fs", "507904/fs", "1015808/fs", "2031616/fs"
169}; 169};
170 170
171static const struct soc_enum da7213_alc_hold_time = 171static SOC_ENUM_SINGLE_DECL(da7213_alc_hold_time,
172 SOC_ENUM_SINGLE(DA7213_ALC_CTRL3, DA7213_ALC_HOLD_SHIFT, 172 DA7213_ALC_CTRL3,
173 DA7213_ALC_HOLD_MAX, da7213_alc_hold_time_txt); 173 DA7213_ALC_HOLD_SHIFT,
174 da7213_alc_hold_time_txt);
174 175
175/* ALC Input Signal Tracking rate select */ 176/* ALC Input Signal Tracking rate select */
176static const char * const da7213_alc_integ_rate_txt[] = { 177static const char * const da7213_alc_integ_rate_txt[] = {
177 "1/4", "1/16", "1/256", "1/65536" 178 "1/4", "1/16", "1/256", "1/65536"
178}; 179};
179 180
180static const struct soc_enum da7213_alc_integ_attack_rate = 181static SOC_ENUM_SINGLE_DECL(da7213_alc_integ_attack_rate,
181 SOC_ENUM_SINGLE(DA7213_ALC_CTRL3, DA7213_ALC_INTEG_ATTACK_SHIFT, 182 DA7213_ALC_CTRL3,
182 DA7213_ALC_INTEG_MAX, da7213_alc_integ_rate_txt); 183 DA7213_ALC_INTEG_ATTACK_SHIFT,
184 da7213_alc_integ_rate_txt);
183 185
184static const struct soc_enum da7213_alc_integ_release_rate = 186static SOC_ENUM_SINGLE_DECL(da7213_alc_integ_release_rate,
185 SOC_ENUM_SINGLE(DA7213_ALC_CTRL3, DA7213_ALC_INTEG_RELEASE_SHIFT, 187 DA7213_ALC_CTRL3,
186 DA7213_ALC_INTEG_MAX, da7213_alc_integ_rate_txt); 188 DA7213_ALC_INTEG_RELEASE_SHIFT,
189 da7213_alc_integ_rate_txt);
187 190
188 191
189/* 192/*
@@ -584,15 +587,17 @@ static const char * const da7213_mic_amp_in_sel_txt[] = {
584 "Differential", "MIC_P", "MIC_N" 587 "Differential", "MIC_P", "MIC_N"
585}; 588};
586 589
587static const struct soc_enum da7213_mic_1_amp_in_sel = 590static SOC_ENUM_SINGLE_DECL(da7213_mic_1_amp_in_sel,
588 SOC_ENUM_SINGLE(DA7213_MIC_1_CTRL, DA7213_MIC_AMP_IN_SEL_SHIFT, 591 DA7213_MIC_1_CTRL,
589 DA7213_MIC_AMP_IN_SEL_MAX, da7213_mic_amp_in_sel_txt); 592 DA7213_MIC_AMP_IN_SEL_SHIFT,
593 da7213_mic_amp_in_sel_txt);
590static const struct snd_kcontrol_new da7213_mic_1_amp_in_sel_mux = 594static const struct snd_kcontrol_new da7213_mic_1_amp_in_sel_mux =
591 SOC_DAPM_ENUM("Mic 1 Amp Source MUX", da7213_mic_1_amp_in_sel); 595 SOC_DAPM_ENUM("Mic 1 Amp Source MUX", da7213_mic_1_amp_in_sel);
592 596
593static const struct soc_enum da7213_mic_2_amp_in_sel = 597static SOC_ENUM_SINGLE_DECL(da7213_mic_2_amp_in_sel,
594 SOC_ENUM_SINGLE(DA7213_MIC_2_CTRL, DA7213_MIC_AMP_IN_SEL_SHIFT, 598 DA7213_MIC_2_CTRL,
595 DA7213_MIC_AMP_IN_SEL_MAX, da7213_mic_amp_in_sel_txt); 599 DA7213_MIC_AMP_IN_SEL_SHIFT,
600 da7213_mic_amp_in_sel_txt);
596static const struct snd_kcontrol_new da7213_mic_2_amp_in_sel_mux = 601static const struct snd_kcontrol_new da7213_mic_2_amp_in_sel_mux =
597 SOC_DAPM_ENUM("Mic 2 Amp Source MUX", da7213_mic_2_amp_in_sel); 602 SOC_DAPM_ENUM("Mic 2 Amp Source MUX", da7213_mic_2_amp_in_sel);
598 603
@@ -601,15 +606,17 @@ static const char * const da7213_dai_src_txt[] = {
601 "ADC Left", "ADC Right", "DAI Input Left", "DAI Input Right" 606 "ADC Left", "ADC Right", "DAI Input Left", "DAI Input Right"
602}; 607};
603 608
604static const struct soc_enum da7213_dai_l_src = 609static SOC_ENUM_SINGLE_DECL(da7213_dai_l_src,
605 SOC_ENUM_SINGLE(DA7213_DIG_ROUTING_DAI, DA7213_DAI_L_SRC_SHIFT, 610 DA7213_DIG_ROUTING_DAI,
606 DA7213_DAI_SRC_MAX, da7213_dai_src_txt); 611 DA7213_DAI_L_SRC_SHIFT,
612 da7213_dai_src_txt);
607static const struct snd_kcontrol_new da7213_dai_l_src_mux = 613static const struct snd_kcontrol_new da7213_dai_l_src_mux =
608 SOC_DAPM_ENUM("DAI Left Source MUX", da7213_dai_l_src); 614 SOC_DAPM_ENUM("DAI Left Source MUX", da7213_dai_l_src);
609 615
610static const struct soc_enum da7213_dai_r_src = 616static SOC_ENUM_SINGLE_DECL(da7213_dai_r_src,
611 SOC_ENUM_SINGLE(DA7213_DIG_ROUTING_DAI, DA7213_DAI_R_SRC_SHIFT, 617 DA7213_DIG_ROUTING_DAI,
612 DA7213_DAI_SRC_MAX, da7213_dai_src_txt); 618 DA7213_DAI_R_SRC_SHIFT,
619 da7213_dai_src_txt);
613static const struct snd_kcontrol_new da7213_dai_r_src_mux = 620static const struct snd_kcontrol_new da7213_dai_r_src_mux =
614 SOC_DAPM_ENUM("DAI Right Source MUX", da7213_dai_r_src); 621 SOC_DAPM_ENUM("DAI Right Source MUX", da7213_dai_r_src);
615 622
@@ -619,15 +626,17 @@ static const char * const da7213_dac_src_txt[] = {
619 "DAI Input Right" 626 "DAI Input Right"
620}; 627};
621 628
622static const struct soc_enum da7213_dac_l_src = 629static SOC_ENUM_SINGLE_DECL(da7213_dac_l_src,
623 SOC_ENUM_SINGLE(DA7213_DIG_ROUTING_DAC, DA7213_DAC_L_SRC_SHIFT, 630 DA7213_DIG_ROUTING_DAC,
624 DA7213_DAC_SRC_MAX, da7213_dac_src_txt); 631 DA7213_DAC_L_SRC_SHIFT,
632 da7213_dac_src_txt);
625static const struct snd_kcontrol_new da7213_dac_l_src_mux = 633static const struct snd_kcontrol_new da7213_dac_l_src_mux =
626 SOC_DAPM_ENUM("DAC Left Source MUX", da7213_dac_l_src); 634 SOC_DAPM_ENUM("DAC Left Source MUX", da7213_dac_l_src);
627 635
628static const struct soc_enum da7213_dac_r_src = 636static SOC_ENUM_SINGLE_DECL(da7213_dac_r_src,
629 SOC_ENUM_SINGLE(DA7213_DIG_ROUTING_DAC, DA7213_DAC_R_SRC_SHIFT, 637 DA7213_DIG_ROUTING_DAC,
630 DA7213_DAC_SRC_MAX, da7213_dac_src_txt); 638 DA7213_DAC_R_SRC_SHIFT,
639 da7213_dac_src_txt);
631static const struct snd_kcontrol_new da7213_dac_r_src_mux = 640static const struct snd_kcontrol_new da7213_dac_r_src_mux =
632 SOC_DAPM_ENUM("DAC Right Source MUX", da7213_dac_r_src); 641 SOC_DAPM_ENUM("DAC Right Source MUX", da7213_dac_r_src);
633 642
@@ -1384,17 +1393,9 @@ static int da7213_set_bias_level(struct snd_soc_codec *codec,
1384 1393
1385static int da7213_probe(struct snd_soc_codec *codec) 1394static int da7213_probe(struct snd_soc_codec *codec)
1386{ 1395{
1387 int ret;
1388 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec); 1396 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
1389 struct da7213_platform_data *pdata = da7213->pdata; 1397 struct da7213_platform_data *pdata = da7213->pdata;
1390 1398
1391 codec->control_data = da7213->regmap;
1392 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1393 if (ret < 0) {
1394 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1395 return ret;
1396 }
1397
1398 /* Default to using ALC auto offset calibration mode. */ 1399 /* Default to using ALC auto offset calibration mode. */
1399 snd_soc_update_bits(codec, DA7213_ALC_CTRL1, 1400 snd_soc_update_bits(codec, DA7213_ALC_CTRL1,
1400 DA7213_ALC_CALIB_MODE_MAN, 0); 1401 DA7213_ALC_CALIB_MODE_MAN, 0);
diff --git a/sound/soc/codecs/da732x.c b/sound/soc/codecs/da732x.c
index f4d965ebc29e..7d168ec71cd7 100644
--- a/sound/soc/codecs/da732x.c
+++ b/sound/soc/codecs/da732x.c
@@ -269,81 +269,65 @@ static const char *da732x_hpf_voice[] = {
269 "150Hz", "200Hz", "300Hz", "400Hz" 269 "150Hz", "200Hz", "300Hz", "400Hz"
270}; 270};
271 271
272static const struct soc_enum da732x_dac1_hpf_mode_enum[] = { 272static SOC_ENUM_SINGLE_DECL(da732x_dac1_hpf_mode_enum,
273 SOC_ENUM_SINGLE(DA732X_REG_DAC1_HPF, DA732X_HPF_MODE_SHIFT, 273 DA732X_REG_DAC1_HPF, DA732X_HPF_MODE_SHIFT,
274 DA732X_HPF_MODE_MAX, da732x_hpf_mode) 274 da732x_hpf_mode);
275};
276
277static const struct soc_enum da732x_dac2_hpf_mode_enum[] = {
278 SOC_ENUM_SINGLE(DA732X_REG_DAC2_HPF, DA732X_HPF_MODE_SHIFT,
279 DA732X_HPF_MODE_MAX, da732x_hpf_mode)
280};
281 275
282static const struct soc_enum da732x_dac3_hpf_mode_enum[] = { 276static SOC_ENUM_SINGLE_DECL(da732x_dac2_hpf_mode_enum,
283 SOC_ENUM_SINGLE(DA732X_REG_DAC3_HPF, DA732X_HPF_MODE_SHIFT, 277 DA732X_REG_DAC2_HPF, DA732X_HPF_MODE_SHIFT,
284 DA732X_HPF_MODE_MAX, da732x_hpf_mode) 278 da732x_hpf_mode);
285};
286 279
287static const struct soc_enum da732x_adc1_hpf_mode_enum[] = { 280static SOC_ENUM_SINGLE_DECL(da732x_dac3_hpf_mode_enum,
288 SOC_ENUM_SINGLE(DA732X_REG_ADC1_HPF, DA732X_HPF_MODE_SHIFT, 281 DA732X_REG_DAC3_HPF, DA732X_HPF_MODE_SHIFT,
289 DA732X_HPF_MODE_MAX, da732x_hpf_mode) 282 da732x_hpf_mode);
290};
291 283
292static const struct soc_enum da732x_adc2_hpf_mode_enum[] = { 284static SOC_ENUM_SINGLE_DECL(da732x_adc1_hpf_mode_enum,
293 SOC_ENUM_SINGLE(DA732X_REG_ADC2_HPF, DA732X_HPF_MODE_SHIFT, 285 DA732X_REG_ADC1_HPF, DA732X_HPF_MODE_SHIFT,
294 DA732X_HPF_MODE_MAX, da732x_hpf_mode) 286 da732x_hpf_mode);
295};
296 287
297static const struct soc_enum da732x_dac1_hp_filter_enum[] = { 288static SOC_ENUM_SINGLE_DECL(da732x_adc2_hpf_mode_enum,
298 SOC_ENUM_SINGLE(DA732X_REG_DAC1_HPF, DA732X_HPF_MUSIC_SHIFT, 289 DA732X_REG_ADC2_HPF, DA732X_HPF_MODE_SHIFT,
299 DA732X_HPF_MUSIC_MAX, da732x_hpf_music) 290 da732x_hpf_mode);
300};
301 291
302static const struct soc_enum da732x_dac2_hp_filter_enum[] = { 292static SOC_ENUM_SINGLE_DECL(da732x_dac1_hp_filter_enum,
303 SOC_ENUM_SINGLE(DA732X_REG_DAC2_HPF, DA732X_HPF_MUSIC_SHIFT, 293 DA732X_REG_DAC1_HPF, DA732X_HPF_MUSIC_SHIFT,
304 DA732X_HPF_MUSIC_MAX, da732x_hpf_music) 294 da732x_hpf_music);
305};
306 295
307static const struct soc_enum da732x_dac3_hp_filter_enum[] = { 296static SOC_ENUM_SINGLE_DECL(da732x_dac2_hp_filter_enum,
308 SOC_ENUM_SINGLE(DA732X_REG_DAC3_HPF, DA732X_HPF_MUSIC_SHIFT, 297 DA732X_REG_DAC2_HPF, DA732X_HPF_MUSIC_SHIFT,
309 DA732X_HPF_MUSIC_MAX, da732x_hpf_music) 298 da732x_hpf_music);
310};
311 299
312static const struct soc_enum da732x_adc1_hp_filter_enum[] = { 300static SOC_ENUM_SINGLE_DECL(da732x_dac3_hp_filter_enum,
313 SOC_ENUM_SINGLE(DA732X_REG_ADC1_HPF, DA732X_HPF_MUSIC_SHIFT, 301 DA732X_REG_DAC3_HPF, DA732X_HPF_MUSIC_SHIFT,
314 DA732X_HPF_MUSIC_MAX, da732x_hpf_music) 302 da732x_hpf_music);
315};
316 303
317static const struct soc_enum da732x_adc2_hp_filter_enum[] = { 304static SOC_ENUM_SINGLE_DECL(da732x_adc1_hp_filter_enum,
318 SOC_ENUM_SINGLE(DA732X_REG_ADC2_HPF, DA732X_HPF_MUSIC_SHIFT, 305 DA732X_REG_ADC1_HPF, DA732X_HPF_MUSIC_SHIFT,
319 DA732X_HPF_MUSIC_MAX, da732x_hpf_music) 306 da732x_hpf_music);
320};
321 307
322static const struct soc_enum da732x_dac1_voice_filter_enum[] = { 308static SOC_ENUM_SINGLE_DECL(da732x_adc2_hp_filter_enum,
323 SOC_ENUM_SINGLE(DA732X_REG_DAC1_HPF, DA732X_HPF_VOICE_SHIFT, 309 DA732X_REG_ADC2_HPF, DA732X_HPF_MUSIC_SHIFT,
324 DA732X_HPF_VOICE_MAX, da732x_hpf_voice) 310 da732x_hpf_music);
325};
326 311
327static const struct soc_enum da732x_dac2_voice_filter_enum[] = { 312static SOC_ENUM_SINGLE_DECL(da732x_dac1_voice_filter_enum,
328 SOC_ENUM_SINGLE(DA732X_REG_DAC2_HPF, DA732X_HPF_VOICE_SHIFT, 313 DA732X_REG_DAC1_HPF, DA732X_HPF_VOICE_SHIFT,
329 DA732X_HPF_VOICE_MAX, da732x_hpf_voice) 314 da732x_hpf_voice);
330};
331 315
332static const struct soc_enum da732x_dac3_voice_filter_enum[] = { 316static SOC_ENUM_SINGLE_DECL(da732x_dac2_voice_filter_enum,
333 SOC_ENUM_SINGLE(DA732X_REG_DAC3_HPF, DA732X_HPF_VOICE_SHIFT, 317 DA732X_REG_DAC2_HPF, DA732X_HPF_VOICE_SHIFT,
334 DA732X_HPF_VOICE_MAX, da732x_hpf_voice) 318 da732x_hpf_voice);
335};
336 319
337static const struct soc_enum da732x_adc1_voice_filter_enum[] = { 320static SOC_ENUM_SINGLE_DECL(da732x_dac3_voice_filter_enum,
338 SOC_ENUM_SINGLE(DA732X_REG_ADC1_HPF, DA732X_HPF_VOICE_SHIFT, 321 DA732X_REG_DAC3_HPF, DA732X_HPF_VOICE_SHIFT,
339 DA732X_HPF_VOICE_MAX, da732x_hpf_voice) 322 da732x_hpf_voice);
340};
341 323
342static const struct soc_enum da732x_adc2_voice_filter_enum[] = { 324static SOC_ENUM_SINGLE_DECL(da732x_adc1_voice_filter_enum,
343 SOC_ENUM_SINGLE(DA732X_REG_ADC2_HPF, DA732X_HPF_VOICE_SHIFT, 325 DA732X_REG_ADC1_HPF, DA732X_HPF_VOICE_SHIFT,
344 DA732X_HPF_VOICE_MAX, da732x_hpf_voice) 326 da732x_hpf_voice);
345};
346 327
328static SOC_ENUM_SINGLE_DECL(da732x_adc2_voice_filter_enum,
329 DA732X_REG_ADC2_HPF, DA732X_HPF_VOICE_SHIFT,
330 da732x_hpf_voice);
347 331
348static int da732x_hpf_set(struct snd_kcontrol *kcontrol, 332static int da732x_hpf_set(struct snd_kcontrol *kcontrol,
349 struct snd_ctl_elem_value *ucontrol) 333 struct snd_ctl_elem_value *ucontrol)
@@ -714,65 +698,65 @@ static const char *enable_text[] = {
714}; 698};
715 699
716/* ADC1LMUX */ 700/* ADC1LMUX */
717static const struct soc_enum adc1l_enum = 701static SOC_ENUM_SINGLE_DECL(adc1l_enum,
718 SOC_ENUM_SINGLE(DA732X_REG_INP_MUX, DA732X_ADC1L_MUX_SEL_SHIFT, 702 DA732X_REG_INP_MUX, DA732X_ADC1L_MUX_SEL_SHIFT,
719 DA732X_ADCL_MUX_MAX, adcl_text); 703 adcl_text);
720static const struct snd_kcontrol_new adc1l_mux = 704static const struct snd_kcontrol_new adc1l_mux =
721 SOC_DAPM_ENUM("ADC Route", adc1l_enum); 705 SOC_DAPM_ENUM("ADC Route", adc1l_enum);
722 706
723/* ADC1RMUX */ 707/* ADC1RMUX */
724static const struct soc_enum adc1r_enum = 708static SOC_ENUM_SINGLE_DECL(adc1r_enum,
725 SOC_ENUM_SINGLE(DA732X_REG_INP_MUX, DA732X_ADC1R_MUX_SEL_SHIFT, 709 DA732X_REG_INP_MUX, DA732X_ADC1R_MUX_SEL_SHIFT,
726 DA732X_ADCR_MUX_MAX, adcr_text); 710 adcr_text);
727static const struct snd_kcontrol_new adc1r_mux = 711static const struct snd_kcontrol_new adc1r_mux =
728 SOC_DAPM_ENUM("ADC Route", adc1r_enum); 712 SOC_DAPM_ENUM("ADC Route", adc1r_enum);
729 713
730/* ADC2LMUX */ 714/* ADC2LMUX */
731static const struct soc_enum adc2l_enum = 715static SOC_ENUM_SINGLE_DECL(adc2l_enum,
732 SOC_ENUM_SINGLE(DA732X_REG_INP_MUX, DA732X_ADC2L_MUX_SEL_SHIFT, 716 DA732X_REG_INP_MUX, DA732X_ADC2L_MUX_SEL_SHIFT,
733 DA732X_ADCL_MUX_MAX, adcl_text); 717 adcl_text);
734static const struct snd_kcontrol_new adc2l_mux = 718static const struct snd_kcontrol_new adc2l_mux =
735 SOC_DAPM_ENUM("ADC Route", adc2l_enum); 719 SOC_DAPM_ENUM("ADC Route", adc2l_enum);
736 720
737/* ADC2RMUX */ 721/* ADC2RMUX */
738static const struct soc_enum adc2r_enum = 722static SOC_ENUM_SINGLE_DECL(adc2r_enum,
739 SOC_ENUM_SINGLE(DA732X_REG_INP_MUX, DA732X_ADC2R_MUX_SEL_SHIFT, 723 DA732X_REG_INP_MUX, DA732X_ADC2R_MUX_SEL_SHIFT,
740 DA732X_ADCR_MUX_MAX, adcr_text); 724 adcr_text);
741 725
742static const struct snd_kcontrol_new adc2r_mux = 726static const struct snd_kcontrol_new adc2r_mux =
743 SOC_DAPM_ENUM("ADC Route", adc2r_enum); 727 SOC_DAPM_ENUM("ADC Route", adc2r_enum);
744 728
745static const struct soc_enum da732x_hp_left_output = 729static SOC_ENUM_SINGLE_DECL(da732x_hp_left_output,
746 SOC_ENUM_SINGLE(DA732X_REG_HPL, DA732X_HP_OUT_DAC_EN_SHIFT, 730 DA732X_REG_HPL, DA732X_HP_OUT_DAC_EN_SHIFT,
747 DA732X_DAC_EN_MAX, enable_text); 731 enable_text);
748 732
749static const struct snd_kcontrol_new hpl_mux = 733static const struct snd_kcontrol_new hpl_mux =
750 SOC_DAPM_ENUM("HPL Switch", da732x_hp_left_output); 734 SOC_DAPM_ENUM("HPL Switch", da732x_hp_left_output);
751 735
752static const struct soc_enum da732x_hp_right_output = 736static SOC_ENUM_SINGLE_DECL(da732x_hp_right_output,
753 SOC_ENUM_SINGLE(DA732X_REG_HPR, DA732X_HP_OUT_DAC_EN_SHIFT, 737 DA732X_REG_HPR, DA732X_HP_OUT_DAC_EN_SHIFT,
754 DA732X_DAC_EN_MAX, enable_text); 738 enable_text);
755 739
756static const struct snd_kcontrol_new hpr_mux = 740static const struct snd_kcontrol_new hpr_mux =
757 SOC_DAPM_ENUM("HPR Switch", da732x_hp_right_output); 741 SOC_DAPM_ENUM("HPR Switch", da732x_hp_right_output);
758 742
759static const struct soc_enum da732x_speaker_output = 743static SOC_ENUM_SINGLE_DECL(da732x_speaker_output,
760 SOC_ENUM_SINGLE(DA732X_REG_LIN3, DA732X_LOUT_DAC_EN_SHIFT, 744 DA732X_REG_LIN3, DA732X_LOUT_DAC_EN_SHIFT,
761 DA732X_DAC_EN_MAX, enable_text); 745 enable_text);
762 746
763static const struct snd_kcontrol_new spk_mux = 747static const struct snd_kcontrol_new spk_mux =
764 SOC_DAPM_ENUM("SPK Switch", da732x_speaker_output); 748 SOC_DAPM_ENUM("SPK Switch", da732x_speaker_output);
765 749
766static const struct soc_enum da732x_lout4_output = 750static SOC_ENUM_SINGLE_DECL(da732x_lout4_output,
767 SOC_ENUM_SINGLE(DA732X_REG_LIN4, DA732X_LOUT_DAC_EN_SHIFT, 751 DA732X_REG_LIN4, DA732X_LOUT_DAC_EN_SHIFT,
768 DA732X_DAC_EN_MAX, enable_text); 752 enable_text);
769 753
770static const struct snd_kcontrol_new lout4_mux = 754static const struct snd_kcontrol_new lout4_mux =
771 SOC_DAPM_ENUM("LOUT4 Switch", da732x_lout4_output); 755 SOC_DAPM_ENUM("LOUT4 Switch", da732x_lout4_output);
772 756
773static const struct soc_enum da732x_lout2_output = 757static SOC_ENUM_SINGLE_DECL(da732x_lout2_output,
774 SOC_ENUM_SINGLE(DA732X_REG_LIN2, DA732X_LOUT_DAC_EN_SHIFT, 758 DA732X_REG_LIN2, DA732X_LOUT_DAC_EN_SHIFT,
775 DA732X_DAC_EN_MAX, enable_text); 759 enable_text);
776 760
777static const struct snd_kcontrol_new lout2_mux = 761static const struct snd_kcontrol_new lout2_mux =
778 SOC_DAPM_ENUM("LOUT2 Switch", da732x_lout2_output); 762 SOC_DAPM_ENUM("LOUT2 Switch", da732x_lout2_output);
@@ -1313,9 +1297,9 @@ static void da732x_dac_offset_adjust(struct snd_soc_codec *codec)
1313 msleep(DA732X_WAIT_FOR_STABILIZATION); 1297 msleep(DA732X_WAIT_FOR_STABILIZATION);
1314 1298
1315 /* Check DAC offset sign */ 1299 /* Check DAC offset sign */
1316 sign[DA732X_HPL_DAC] = (codec->hw_read(codec, DA732X_REG_HPL_DAC_OFF_CNTL) & 1300 sign[DA732X_HPL_DAC] = (snd_soc_read(codec, DA732X_REG_HPL_DAC_OFF_CNTL) &
1317 DA732X_HP_DAC_OFF_CNTL_COMPO); 1301 DA732X_HP_DAC_OFF_CNTL_COMPO);
1318 sign[DA732X_HPR_DAC] = (codec->hw_read(codec, DA732X_REG_HPR_DAC_OFF_CNTL) & 1302 sign[DA732X_HPR_DAC] = (snd_soc_read(codec, DA732X_REG_HPR_DAC_OFF_CNTL) &
1319 DA732X_HP_DAC_OFF_CNTL_COMPO); 1303 DA732X_HP_DAC_OFF_CNTL_COMPO);
1320 1304
1321 /* Binary search DAC offset values (both channels at once) */ 1305 /* Binary search DAC offset values (both channels at once) */
@@ -1332,10 +1316,10 @@ static void da732x_dac_offset_adjust(struct snd_soc_codec *codec)
1332 1316
1333 msleep(DA732X_WAIT_FOR_STABILIZATION); 1317 msleep(DA732X_WAIT_FOR_STABILIZATION);
1334 1318
1335 if ((codec->hw_read(codec, DA732X_REG_HPL_DAC_OFF_CNTL) & 1319 if ((snd_soc_read(codec, DA732X_REG_HPL_DAC_OFF_CNTL) &
1336 DA732X_HP_DAC_OFF_CNTL_COMPO) ^ sign[DA732X_HPL_DAC]) 1320 DA732X_HP_DAC_OFF_CNTL_COMPO) ^ sign[DA732X_HPL_DAC])
1337 offset[DA732X_HPL_DAC] &= ~step; 1321 offset[DA732X_HPL_DAC] &= ~step;
1338 if ((codec->hw_read(codec, DA732X_REG_HPR_DAC_OFF_CNTL) & 1322 if ((snd_soc_read(codec, DA732X_REG_HPR_DAC_OFF_CNTL) &
1339 DA732X_HP_DAC_OFF_CNTL_COMPO) ^ sign[DA732X_HPR_DAC]) 1323 DA732X_HP_DAC_OFF_CNTL_COMPO) ^ sign[DA732X_HPR_DAC])
1340 offset[DA732X_HPR_DAC] &= ~step; 1324 offset[DA732X_HPR_DAC] &= ~step;
1341 1325
@@ -1376,9 +1360,9 @@ static void da732x_output_offset_adjust(struct snd_soc_codec *codec)
1376 msleep(DA732X_WAIT_FOR_STABILIZATION); 1360 msleep(DA732X_WAIT_FOR_STABILIZATION);
1377 1361
1378 /* Check output offset sign */ 1362 /* Check output offset sign */
1379 sign[DA732X_HPL_AMP] = codec->hw_read(codec, DA732X_REG_HPL) & 1363 sign[DA732X_HPL_AMP] = snd_soc_read(codec, DA732X_REG_HPL) &
1380 DA732X_HP_OUT_COMPO; 1364 DA732X_HP_OUT_COMPO;
1381 sign[DA732X_HPR_AMP] = codec->hw_read(codec, DA732X_REG_HPR) & 1365 sign[DA732X_HPR_AMP] = snd_soc_read(codec, DA732X_REG_HPR) &
1382 DA732X_HP_OUT_COMPO; 1366 DA732X_HP_OUT_COMPO;
1383 1367
1384 snd_soc_write(codec, DA732X_REG_HPL, DA732X_HP_OUT_COMP | 1368 snd_soc_write(codec, DA732X_REG_HPL, DA732X_HP_OUT_COMP |
@@ -1399,10 +1383,10 @@ static void da732x_output_offset_adjust(struct snd_soc_codec *codec)
1399 1383
1400 msleep(DA732X_WAIT_FOR_STABILIZATION); 1384 msleep(DA732X_WAIT_FOR_STABILIZATION);
1401 1385
1402 if ((codec->hw_read(codec, DA732X_REG_HPL) & 1386 if ((snd_soc_read(codec, DA732X_REG_HPL) &
1403 DA732X_HP_OUT_COMPO) ^ sign[DA732X_HPL_AMP]) 1387 DA732X_HP_OUT_COMPO) ^ sign[DA732X_HPL_AMP])
1404 offset[DA732X_HPL_AMP] &= ~step; 1388 offset[DA732X_HPL_AMP] &= ~step;
1405 if ((codec->hw_read(codec, DA732X_REG_HPR) & 1389 if ((snd_soc_read(codec, DA732X_REG_HPR) &
1406 DA732X_HP_OUT_COMPO) ^ sign[DA732X_HPR_AMP]) 1390 DA732X_HP_OUT_COMPO) ^ sign[DA732X_HPR_AMP])
1407 offset[DA732X_HPR_AMP] &= ~step; 1391 offset[DA732X_HPR_AMP] &= ~step;
1408 1392
@@ -1499,8 +1483,8 @@ static int da732x_set_bias_level(struct snd_soc_codec *codec,
1499 1483
1500 da732x_hp_dc_offset_cancellation(codec); 1484 da732x_hp_dc_offset_cancellation(codec);
1501 1485
1502 regcache_cache_only(codec->control_data, false); 1486 regcache_cache_only(da732x->regmap, false);
1503 regcache_sync(codec->control_data); 1487 regcache_sync(da732x->regmap);
1504 } else { 1488 } else {
1505 snd_soc_update_bits(codec, DA732X_REG_BIAS_EN, 1489 snd_soc_update_bits(codec, DA732X_REG_BIAS_EN,
1506 DA732X_BIAS_BOOST_MASK, 1490 DA732X_BIAS_BOOST_MASK,
@@ -1511,7 +1495,7 @@ static int da732x_set_bias_level(struct snd_soc_codec *codec,
1511 } 1495 }
1512 break; 1496 break;
1513 case SND_SOC_BIAS_OFF: 1497 case SND_SOC_BIAS_OFF:
1514 regcache_cache_only(codec->control_data, true); 1498 regcache_cache_only(da732x->regmap, true);
1515 da732x_set_charge_pump(codec, DA732X_DISABLE_CP); 1499 da732x_set_charge_pump(codec, DA732X_DISABLE_CP);
1516 snd_soc_update_bits(codec, DA732X_REG_BIAS_EN, DA732X_BIAS_EN, 1500 snd_soc_update_bits(codec, DA732X_REG_BIAS_EN, DA732X_BIAS_EN,
1517 DA732X_BIAS_DIS); 1501 DA732X_BIAS_DIS);
@@ -1528,23 +1512,14 @@ static int da732x_probe(struct snd_soc_codec *codec)
1528{ 1512{
1529 struct da732x_priv *da732x = snd_soc_codec_get_drvdata(codec); 1513 struct da732x_priv *da732x = snd_soc_codec_get_drvdata(codec);
1530 struct snd_soc_dapm_context *dapm = &codec->dapm; 1514 struct snd_soc_dapm_context *dapm = &codec->dapm;
1531 int ret = 0;
1532 1515
1533 da732x->codec = codec; 1516 da732x->codec = codec;
1534 1517
1535 dapm->idle_bias_off = false; 1518 dapm->idle_bias_off = false;
1536 1519
1537 codec->control_data = da732x->regmap;
1538
1539 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1540 if (ret != 0) {
1541 dev_err(codec->dev, "Failed to register codec.\n");
1542 goto err;
1543 }
1544
1545 da732x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1520 da732x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1546err: 1521
1547 return ret; 1522 return 0;
1548} 1523}
1549 1524
1550static int da732x_remove(struct snd_soc_codec *codec) 1525static int da732x_remove(struct snd_soc_codec *codec)
@@ -1566,7 +1541,6 @@ static struct snd_soc_codec_driver soc_codec_dev_da732x = {
1566 .dapm_routes = da732x_dapm_routes, 1541 .dapm_routes = da732x_dapm_routes,
1567 .num_dapm_routes = ARRAY_SIZE(da732x_dapm_routes), 1542 .num_dapm_routes = ARRAY_SIZE(da732x_dapm_routes),
1568 .set_pll = da732x_set_dai_pll, 1543 .set_pll = da732x_set_dai_pll,
1569 .reg_cache_size = ARRAY_SIZE(da732x_reg_cache),
1570}; 1544};
1571 1545
1572static int da732x_i2c_probe(struct i2c_client *i2c, 1546static int da732x_i2c_probe(struct i2c_client *i2c,
diff --git a/sound/soc/codecs/da732x.h b/sound/soc/codecs/da732x.h
index c8ce5475de22..1dceafeec415 100644
--- a/sound/soc/codecs/da732x.h
+++ b/sound/soc/codecs/da732x.h
@@ -113,9 +113,6 @@
113#define DA732X_EQ_OVERALL_VOL_DB_MIN -1800 113#define DA732X_EQ_OVERALL_VOL_DB_MIN -1800
114#define DA732X_EQ_OVERALL_VOL_DB_INC 600 114#define DA732X_EQ_OVERALL_VOL_DB_INC 600
115 115
116#define DA732X_SOC_ENUM_DOUBLE_R(xreg, xrreg, xmax, xtext) \
117 {.reg = xreg, .reg2 = xrreg, .max = xmax, .texts = xtext}
118
119enum da732x_sysctl { 116enum da732x_sysctl {
120 DA732X_SR_8KHZ = 0x1, 117 DA732X_SR_8KHZ = 0x1,
121 DA732X_SR_11_025KHZ = 0x2, 118 DA732X_SR_11_025KHZ = 0x2,
diff --git a/sound/soc/codecs/da9055.c b/sound/soc/codecs/da9055.c
index 422812613a28..4ff06b50fbba 100644
--- a/sound/soc/codecs/da9055.c
+++ b/sound/soc/codecs/da9055.c
@@ -18,6 +18,8 @@
18#include <linux/regmap.h> 18#include <linux/regmap.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/of.h>
22#include <linux/of_device.h>
21#include <sound/pcm.h> 23#include <sound/pcm.h>
22#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
23#include <sound/soc.h> 25#include <sound/soc.h>
@@ -321,22 +323,22 @@ static const char * const da9055_hpf_cutoff_txt[] = {
321 "Fs/24000", "Fs/12000", "Fs/6000", "Fs/3000" 323 "Fs/24000", "Fs/12000", "Fs/6000", "Fs/3000"
322}; 324};
323 325
324static const struct soc_enum da9055_dac_hpf_cutoff = 326static SOC_ENUM_SINGLE_DECL(da9055_dac_hpf_cutoff,
325 SOC_ENUM_SINGLE(DA9055_DAC_FILTERS1, 4, 4, da9055_hpf_cutoff_txt); 327 DA9055_DAC_FILTERS1, 4, da9055_hpf_cutoff_txt);
326 328
327static const struct soc_enum da9055_adc_hpf_cutoff = 329static SOC_ENUM_SINGLE_DECL(da9055_adc_hpf_cutoff,
328 SOC_ENUM_SINGLE(DA9055_ADC_FILTERS1, 4, 4, da9055_hpf_cutoff_txt); 330 DA9055_ADC_FILTERS1, 4, da9055_hpf_cutoff_txt);
329 331
330/* ADC and DAC voice mode (8kHz) high pass cutoff value */ 332/* ADC and DAC voice mode (8kHz) high pass cutoff value */
331static const char * const da9055_vf_cutoff_txt[] = { 333static const char * const da9055_vf_cutoff_txt[] = {
332 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz" 334 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
333}; 335};
334 336
335static const struct soc_enum da9055_dac_vf_cutoff = 337static SOC_ENUM_SINGLE_DECL(da9055_dac_vf_cutoff,
336 SOC_ENUM_SINGLE(DA9055_DAC_FILTERS1, 0, 8, da9055_vf_cutoff_txt); 338 DA9055_DAC_FILTERS1, 0, da9055_vf_cutoff_txt);
337 339
338static const struct soc_enum da9055_adc_vf_cutoff = 340static SOC_ENUM_SINGLE_DECL(da9055_adc_vf_cutoff,
339 SOC_ENUM_SINGLE(DA9055_ADC_FILTERS1, 0, 8, da9055_vf_cutoff_txt); 341 DA9055_ADC_FILTERS1, 0, da9055_vf_cutoff_txt);
340 342
341/* Gain ramping rate value */ 343/* Gain ramping rate value */
342static const char * const da9055_gain_ramping_txt[] = { 344static const char * const da9055_gain_ramping_txt[] = {
@@ -344,44 +346,44 @@ static const char * const da9055_gain_ramping_txt[] = {
344 "nominal rate / 8" 346 "nominal rate / 8"
345}; 347};
346 348
347static const struct soc_enum da9055_gain_ramping_rate = 349static SOC_ENUM_SINGLE_DECL(da9055_gain_ramping_rate,
348 SOC_ENUM_SINGLE(DA9055_GAIN_RAMP_CTRL, 0, 4, da9055_gain_ramping_txt); 350 DA9055_GAIN_RAMP_CTRL, 0, da9055_gain_ramping_txt);
349 351
350/* DAC noise gate setup time value */ 352/* DAC noise gate setup time value */
351static const char * const da9055_dac_ng_setup_time_txt[] = { 353static const char * const da9055_dac_ng_setup_time_txt[] = {
352 "256 samples", "512 samples", "1024 samples", "2048 samples" 354 "256 samples", "512 samples", "1024 samples", "2048 samples"
353}; 355};
354 356
355static const struct soc_enum da9055_dac_ng_setup_time = 357static SOC_ENUM_SINGLE_DECL(da9055_dac_ng_setup_time,
356 SOC_ENUM_SINGLE(DA9055_DAC_NG_SETUP_TIME, 0, 4, 358 DA9055_DAC_NG_SETUP_TIME, 0,
357 da9055_dac_ng_setup_time_txt); 359 da9055_dac_ng_setup_time_txt);
358 360
359/* DAC noise gate rampup rate value */ 361/* DAC noise gate rampup rate value */
360static const char * const da9055_dac_ng_rampup_txt[] = { 362static const char * const da9055_dac_ng_rampup_txt[] = {
361 "0.02 ms/dB", "0.16 ms/dB" 363 "0.02 ms/dB", "0.16 ms/dB"
362}; 364};
363 365
364static const struct soc_enum da9055_dac_ng_rampup_rate = 366static SOC_ENUM_SINGLE_DECL(da9055_dac_ng_rampup_rate,
365 SOC_ENUM_SINGLE(DA9055_DAC_NG_SETUP_TIME, 2, 2, 367 DA9055_DAC_NG_SETUP_TIME, 2,
366 da9055_dac_ng_rampup_txt); 368 da9055_dac_ng_rampup_txt);
367 369
368/* DAC noise gate rampdown rate value */ 370/* DAC noise gate rampdown rate value */
369static const char * const da9055_dac_ng_rampdown_txt[] = { 371static const char * const da9055_dac_ng_rampdown_txt[] = {
370 "0.64 ms/dB", "20.48 ms/dB" 372 "0.64 ms/dB", "20.48 ms/dB"
371}; 373};
372 374
373static const struct soc_enum da9055_dac_ng_rampdown_rate = 375static SOC_ENUM_SINGLE_DECL(da9055_dac_ng_rampdown_rate,
374 SOC_ENUM_SINGLE(DA9055_DAC_NG_SETUP_TIME, 3, 2, 376 DA9055_DAC_NG_SETUP_TIME, 3,
375 da9055_dac_ng_rampdown_txt); 377 da9055_dac_ng_rampdown_txt);
376 378
377/* DAC soft mute rate value */ 379/* DAC soft mute rate value */
378static const char * const da9055_dac_soft_mute_rate_txt[] = { 380static const char * const da9055_dac_soft_mute_rate_txt[] = {
379 "1", "2", "4", "8", "16", "32", "64" 381 "1", "2", "4", "8", "16", "32", "64"
380}; 382};
381 383
382static const struct soc_enum da9055_dac_soft_mute_rate = 384static SOC_ENUM_SINGLE_DECL(da9055_dac_soft_mute_rate,
383 SOC_ENUM_SINGLE(DA9055_DAC_FILTERS5, 4, 7, 385 DA9055_DAC_FILTERS5, 4,
384 da9055_dac_soft_mute_rate_txt); 386 da9055_dac_soft_mute_rate_txt);
385 387
386/* DAC routing select */ 388/* DAC routing select */
387static const char * const da9055_dac_src_txt[] = { 389static const char * const da9055_dac_src_txt[] = {
@@ -389,40 +391,40 @@ static const char * const da9055_dac_src_txt[] = {
389 "AIF input right" 391 "AIF input right"
390}; 392};
391 393
392static const struct soc_enum da9055_dac_l_src = 394static SOC_ENUM_SINGLE_DECL(da9055_dac_l_src,
393 SOC_ENUM_SINGLE(DA9055_DIG_ROUTING_DAC, 0, 4, da9055_dac_src_txt); 395 DA9055_DIG_ROUTING_DAC, 0, da9055_dac_src_txt);
394 396
395static const struct soc_enum da9055_dac_r_src = 397static SOC_ENUM_SINGLE_DECL(da9055_dac_r_src,
396 SOC_ENUM_SINGLE(DA9055_DIG_ROUTING_DAC, 4, 4, da9055_dac_src_txt); 398 DA9055_DIG_ROUTING_DAC, 4, da9055_dac_src_txt);
397 399
398/* MIC PGA Left source select */ 400/* MIC PGA Left source select */
399static const char * const da9055_mic_l_src_txt[] = { 401static const char * const da9055_mic_l_src_txt[] = {
400 "MIC1_P_N", "MIC1_P", "MIC1_N", "MIC2_L" 402 "MIC1_P_N", "MIC1_P", "MIC1_N", "MIC2_L"
401}; 403};
402 404
403static const struct soc_enum da9055_mic_l_src = 405static SOC_ENUM_SINGLE_DECL(da9055_mic_l_src,
404 SOC_ENUM_SINGLE(DA9055_MIXIN_L_SELECT, 4, 4, da9055_mic_l_src_txt); 406 DA9055_MIXIN_L_SELECT, 4, da9055_mic_l_src_txt);
405 407
406/* MIC PGA Right source select */ 408/* MIC PGA Right source select */
407static const char * const da9055_mic_r_src_txt[] = { 409static const char * const da9055_mic_r_src_txt[] = {
408 "MIC2_R_L", "MIC2_R", "MIC2_L" 410 "MIC2_R_L", "MIC2_R", "MIC2_L"
409}; 411};
410 412
411static const struct soc_enum da9055_mic_r_src = 413static SOC_ENUM_SINGLE_DECL(da9055_mic_r_src,
412 SOC_ENUM_SINGLE(DA9055_MIXIN_R_SELECT, 4, 3, da9055_mic_r_src_txt); 414 DA9055_MIXIN_R_SELECT, 4, da9055_mic_r_src_txt);
413 415
414/* ALC Input Signal Tracking rate select */ 416/* ALC Input Signal Tracking rate select */
415static const char * const da9055_signal_tracking_rate_txt[] = { 417static const char * const da9055_signal_tracking_rate_txt[] = {
416 "1/4", "1/16", "1/256", "1/65536" 418 "1/4", "1/16", "1/256", "1/65536"
417}; 419};
418 420
419static const struct soc_enum da9055_integ_attack_rate = 421static SOC_ENUM_SINGLE_DECL(da9055_integ_attack_rate,
420 SOC_ENUM_SINGLE(DA9055_ALC_CTRL3, 4, 4, 422 DA9055_ALC_CTRL3, 4,
421 da9055_signal_tracking_rate_txt); 423 da9055_signal_tracking_rate_txt);
422 424
423static const struct soc_enum da9055_integ_release_rate = 425static SOC_ENUM_SINGLE_DECL(da9055_integ_release_rate,
424 SOC_ENUM_SINGLE(DA9055_ALC_CTRL3, 6, 4, 426 DA9055_ALC_CTRL3, 6,
425 da9055_signal_tracking_rate_txt); 427 da9055_signal_tracking_rate_txt);
426 428
427/* ALC Attack Rate select */ 429/* ALC Attack Rate select */
428static const char * const da9055_attack_rate_txt[] = { 430static const char * const da9055_attack_rate_txt[] = {
@@ -430,8 +432,8 @@ static const char * const da9055_attack_rate_txt[] = {
430 "5632/fs", "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs" 432 "5632/fs", "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs"
431}; 433};
432 434
433static const struct soc_enum da9055_attack_rate = 435static SOC_ENUM_SINGLE_DECL(da9055_attack_rate,
434 SOC_ENUM_SINGLE(DA9055_ALC_CTRL2, 0, 13, da9055_attack_rate_txt); 436 DA9055_ALC_CTRL2, 0, da9055_attack_rate_txt);
435 437
436/* ALC Release Rate select */ 438/* ALC Release Rate select */
437static const char * const da9055_release_rate_txt[] = { 439static const char * const da9055_release_rate_txt[] = {
@@ -439,8 +441,8 @@ static const char * const da9055_release_rate_txt[] = {
439 "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs" 441 "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs"
440}; 442};
441 443
442static const struct soc_enum da9055_release_rate = 444static SOC_ENUM_SINGLE_DECL(da9055_release_rate,
443 SOC_ENUM_SINGLE(DA9055_ALC_CTRL2, 4, 11, da9055_release_rate_txt); 445 DA9055_ALC_CTRL2, 4, da9055_release_rate_txt);
444 446
445/* ALC Hold Time select */ 447/* ALC Hold Time select */
446static const char * const da9055_hold_time_txt[] = { 448static const char * const da9055_hold_time_txt[] = {
@@ -449,8 +451,8 @@ static const char * const da9055_hold_time_txt[] = {
449 "253952/fs", "507904/fs", "1015808/fs", "2031616/fs" 451 "253952/fs", "507904/fs", "1015808/fs", "2031616/fs"
450}; 452};
451 453
452static const struct soc_enum da9055_hold_time = 454static SOC_ENUM_SINGLE_DECL(da9055_hold_time,
453 SOC_ENUM_SINGLE(DA9055_ALC_CTRL3, 0, 16, da9055_hold_time_txt); 455 DA9055_ALC_CTRL3, 0, da9055_hold_time_txt);
454 456
455static int da9055_get_alc_data(struct snd_soc_codec *codec, u8 reg_val) 457static int da9055_get_alc_data(struct snd_soc_codec *codec, u8 reg_val)
456{ 458{
@@ -1381,16 +1383,8 @@ static int da9055_set_bias_level(struct snd_soc_codec *codec,
1381 1383
1382static int da9055_probe(struct snd_soc_codec *codec) 1384static int da9055_probe(struct snd_soc_codec *codec)
1383{ 1385{
1384 int ret;
1385 struct da9055_priv *da9055 = snd_soc_codec_get_drvdata(codec); 1386 struct da9055_priv *da9055 = snd_soc_codec_get_drvdata(codec);
1386 1387
1387 codec->control_data = da9055->regmap;
1388 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1389 if (ret < 0) {
1390 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1391 return ret;
1392 }
1393
1394 /* Enable all Gain Ramps */ 1388 /* Enable all Gain Ramps */
1395 snd_soc_update_bits(codec, DA9055_AUX_L_CTRL, 1389 snd_soc_update_bits(codec, DA9055_AUX_L_CTRL,
1396 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN); 1390 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
@@ -1536,11 +1530,17 @@ static const struct i2c_device_id da9055_i2c_id[] = {
1536}; 1530};
1537MODULE_DEVICE_TABLE(i2c, da9055_i2c_id); 1531MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
1538 1532
1533static const struct of_device_id da9055_of_match[] = {
1534 { .compatible = "dlg,da9055-codec", },
1535 { }
1536};
1537
1539/* I2C codec control layer */ 1538/* I2C codec control layer */
1540static struct i2c_driver da9055_i2c_driver = { 1539static struct i2c_driver da9055_i2c_driver = {
1541 .driver = { 1540 .driver = {
1542 .name = "da9055-codec", 1541 .name = "da9055-codec",
1543 .owner = THIS_MODULE, 1542 .owner = THIS_MODULE,
1543 .of_match_table = of_match_ptr(da9055_of_match),
1544 }, 1544 },
1545 .probe = da9055_i2c_probe, 1545 .probe = da9055_i2c_probe,
1546 .remove = da9055_remove, 1546 .remove = da9055_remove,
diff --git a/sound/soc/codecs/isabelle.c b/sound/soc/codecs/isabelle.c
index cb736ddc446d..3a89ce66d51d 100644
--- a/sound/soc/codecs/isabelle.c
+++ b/sound/soc/codecs/isabelle.c
@@ -918,8 +918,7 @@ static int isabelle_hw_params(struct snd_pcm_substream *substream,
918 struct snd_pcm_hw_params *params, 918 struct snd_pcm_hw_params *params,
919 struct snd_soc_dai *dai) 919 struct snd_soc_dai *dai)
920{ 920{
921 struct snd_soc_pcm_runtime *rtd = substream->private_data; 921 struct snd_soc_codec *codec = dai->codec;
922 struct snd_soc_codec *codec = rtd->codec;
923 u16 aif = 0; 922 u16 aif = 0;
924 unsigned int fs_val = 0; 923 unsigned int fs_val = 0;
925 924
@@ -1090,23 +1089,7 @@ static struct snd_soc_dai_driver isabelle_dai[] = {
1090 }, 1089 },
1091}; 1090};
1092 1091
1093static int isabelle_probe(struct snd_soc_codec *codec)
1094{
1095 int ret = 0;
1096
1097 codec->control_data = dev_get_regmap(codec->dev, NULL);
1098
1099 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1100 if (ret < 0) {
1101 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1102 return ret;
1103 }
1104
1105 return 0;
1106}
1107
1108static struct snd_soc_codec_driver soc_codec_dev_isabelle = { 1092static struct snd_soc_codec_driver soc_codec_dev_isabelle = {
1109 .probe = isabelle_probe,
1110 .set_bias_level = isabelle_set_bias_level, 1093 .set_bias_level = isabelle_set_bias_level,
1111 .controls = isabelle_snd_controls, 1094 .controls = isabelle_snd_controls,
1112 .num_controls = ARRAY_SIZE(isabelle_snd_controls), 1095 .num_controls = ARRAY_SIZE(isabelle_snd_controls),
diff --git a/sound/soc/codecs/lm4857.c b/sound/soc/codecs/lm4857.c
index 0e5743ea79df..4f048db9f55f 100644
--- a/sound/soc/codecs/lm4857.c
+++ b/sound/soc/codecs/lm4857.c
@@ -101,8 +101,7 @@ static const char *lm4857_mode[] = {
101 "Headphone", 101 "Headphone",
102}; 102};
103 103
104static const struct soc_enum lm4857_mode_enum = 104static SOC_ENUM_SINGLE_EXT_DECL(lm4857_mode_enum, lm4857_mode);
105 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lm4857_mode), lm4857_mode);
106 105
107static const struct snd_soc_dapm_widget lm4857_dapm_widgets[] = { 106static const struct snd_soc_dapm_widget lm4857_dapm_widgets[] = {
108 SND_SOC_DAPM_INPUT("IN"), 107 SND_SOC_DAPM_INPUT("IN"),
diff --git a/sound/soc/codecs/lm49453.c b/sound/soc/codecs/lm49453.c
index e19490cfb3a8..275b3f72f3f4 100644
--- a/sound/soc/codecs/lm49453.c
+++ b/sound/soc/codecs/lm49453.c
@@ -195,33 +195,31 @@ struct lm49453_priv {
195 195
196static const char *lm49453_mic2mode_text[] = {"Single Ended", "Differential"}; 196static const char *lm49453_mic2mode_text[] = {"Single Ended", "Differential"};
197 197
198static const SOC_ENUM_SINGLE_DECL(lm49453_mic2mode_enum, LM49453_P0_MICR_REG, 5, 198static SOC_ENUM_SINGLE_DECL(lm49453_mic2mode_enum, LM49453_P0_MICR_REG, 5,
199 lm49453_mic2mode_text); 199 lm49453_mic2mode_text);
200 200
201static const char *lm49453_dmic_cfg_text[] = {"DMICDAT1", "DMICDAT2"}; 201static const char *lm49453_dmic_cfg_text[] = {"DMICDAT1", "DMICDAT2"};
202 202
203static const SOC_ENUM_SINGLE_DECL(lm49453_dmic12_cfg_enum, 203static SOC_ENUM_SINGLE_DECL(lm49453_dmic12_cfg_enum,
204 LM49453_P0_DIGITAL_MIC1_CONFIG_REG, 204 LM49453_P0_DIGITAL_MIC1_CONFIG_REG, 7,
205 7, lm49453_dmic_cfg_text); 205 lm49453_dmic_cfg_text);
206 206
207static const SOC_ENUM_SINGLE_DECL(lm49453_dmic34_cfg_enum, 207static SOC_ENUM_SINGLE_DECL(lm49453_dmic34_cfg_enum,
208 LM49453_P0_DIGITAL_MIC2_CONFIG_REG, 208 LM49453_P0_DIGITAL_MIC2_CONFIG_REG, 7,
209 7, lm49453_dmic_cfg_text); 209 lm49453_dmic_cfg_text);
210 210
211/* MUX Controls */ 211/* MUX Controls */
212static const char *lm49453_adcl_mux_text[] = { "MIC1", "Aux_L" }; 212static const char *lm49453_adcl_mux_text[] = { "MIC1", "Aux_L" };
213 213
214static const char *lm49453_adcr_mux_text[] = { "MIC2", "Aux_R" }; 214static const char *lm49453_adcr_mux_text[] = { "MIC2", "Aux_R" };
215 215
216static const struct soc_enum lm49453_adcl_enum = 216static SOC_ENUM_SINGLE_DECL(lm49453_adcl_enum,
217 SOC_ENUM_SINGLE(LM49453_P0_ANALOG_MIXER_ADC_REG, 0, 217 LM49453_P0_ANALOG_MIXER_ADC_REG, 0,
218 ARRAY_SIZE(lm49453_adcl_mux_text), 218 lm49453_adcl_mux_text);
219 lm49453_adcl_mux_text);
220 219
221static const struct soc_enum lm49453_adcr_enum = 220static SOC_ENUM_SINGLE_DECL(lm49453_adcr_enum,
222 SOC_ENUM_SINGLE(LM49453_P0_ANALOG_MIXER_ADC_REG, 1, 221 LM49453_P0_ANALOG_MIXER_ADC_REG, 1,
223 ARRAY_SIZE(lm49453_adcr_mux_text), 222 lm49453_adcr_mux_text);
224 lm49453_adcr_mux_text);
225 223
226static const struct snd_kcontrol_new lm49453_adcl_mux_control = 224static const struct snd_kcontrol_new lm49453_adcl_mux_control =
227 SOC_DAPM_ENUM("ADC Left Mux", lm49453_adcl_enum); 225 SOC_DAPM_ENUM("ADC Left Mux", lm49453_adcl_enum);
@@ -1409,22 +1407,6 @@ static int lm49453_resume(struct snd_soc_codec *codec)
1409 return 0; 1407 return 0;
1410} 1408}
1411 1409
1412static int lm49453_probe(struct snd_soc_codec *codec)
1413{
1414 struct lm49453_priv *lm49453 = snd_soc_codec_get_drvdata(codec);
1415 int ret = 0;
1416
1417 codec->control_data = lm49453->regmap;
1418
1419 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1420 if (ret < 0) {
1421 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1422 return ret;
1423 }
1424
1425 return 0;
1426}
1427
1428/* power down chip */ 1410/* power down chip */
1429static int lm49453_remove(struct snd_soc_codec *codec) 1411static int lm49453_remove(struct snd_soc_codec *codec)
1430{ 1412{
@@ -1433,7 +1415,6 @@ static int lm49453_remove(struct snd_soc_codec *codec)
1433} 1415}
1434 1416
1435static struct snd_soc_codec_driver soc_codec_dev_lm49453 = { 1417static struct snd_soc_codec_driver soc_codec_dev_lm49453 = {
1436 .probe = lm49453_probe,
1437 .remove = lm49453_remove, 1418 .remove = lm49453_remove,
1438 .suspend = lm49453_suspend, 1419 .suspend = lm49453_suspend,
1439 .resume = lm49453_resume, 1420 .resume = lm49453_resume,
diff --git a/sound/soc/codecs/max9768.c b/sound/soc/codecs/max9768.c
index 31f91560e9f6..ec481fc428c7 100644
--- a/sound/soc/codecs/max9768.c
+++ b/sound/soc/codecs/max9768.c
@@ -135,11 +135,6 @@ static int max9768_probe(struct snd_soc_codec *codec)
135 struct max9768 *max9768 = snd_soc_codec_get_drvdata(codec); 135 struct max9768 *max9768 = snd_soc_codec_get_drvdata(codec);
136 int ret; 136 int ret;
137 137
138 codec->control_data = max9768->regmap;
139 ret = snd_soc_codec_set_cache_io(codec, 2, 6, SND_SOC_REGMAP);
140 if (ret)
141 return ret;
142
143 if (max9768->flags & MAX9768_FLAG_CLASSIC_PWM) { 138 if (max9768->flags & MAX9768_FLAG_CLASSIC_PWM) {
144 ret = snd_soc_write(codec, MAX9768_CTRL, MAX9768_CTRL_PWM); 139 ret = snd_soc_write(codec, MAX9768_CTRL, MAX9768_CTRL_PWM);
145 if (ret) 140 if (ret)
diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index ee660e2d3df3..ef7cf89f5623 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -597,28 +597,27 @@ static const unsigned int max98088_exmode_values[] = {
597 0x00, 0x43, 0x10, 0x20, 0x30, 0x40, 0x11, 0x22, 0x32 597 0x00, 0x43, 0x10, 0x20, 0x30, 0x40, 0x11, 0x22, 0x32
598}; 598};
599 599
600static const struct soc_enum max98088_exmode_enum = 600static SOC_VALUE_ENUM_SINGLE_DECL(max98088_exmode_enum,
601 SOC_VALUE_ENUM_SINGLE(M98088_REG_41_SPKDHP, 0, 127, 601 M98088_REG_41_SPKDHP, 0, 127,
602 ARRAY_SIZE(max98088_exmode_texts), 602 max98088_exmode_texts,
603 max98088_exmode_texts, 603 max98088_exmode_values);
604 max98088_exmode_values);
605 604
606static const char *max98088_ex_thresh[] = { /* volts PP */ 605static const char *max98088_ex_thresh[] = { /* volts PP */
607 "0.6", "1.2", "1.8", "2.4", "3.0", "3.6", "4.2", "4.8"}; 606 "0.6", "1.2", "1.8", "2.4", "3.0", "3.6", "4.2", "4.8"};
608static const struct soc_enum max98088_ex_thresh_enum[] = { 607static SOC_ENUM_SINGLE_DECL(max98088_ex_thresh_enum,
609 SOC_ENUM_SINGLE(M98088_REG_42_SPKDHP_THRESH, 0, 8, 608 M98088_REG_42_SPKDHP_THRESH, 0,
610 max98088_ex_thresh), 609 max98088_ex_thresh);
611};
612 610
613static const char *max98088_fltr_mode[] = {"Voice", "Music" }; 611static const char *max98088_fltr_mode[] = {"Voice", "Music" };
614static const struct soc_enum max98088_filter_mode_enum[] = { 612static SOC_ENUM_SINGLE_DECL(max98088_filter_mode_enum,
615 SOC_ENUM_SINGLE(M98088_REG_18_DAI1_FILTERS, 7, 2, max98088_fltr_mode), 613 M98088_REG_18_DAI1_FILTERS, 7,
616}; 614 max98088_fltr_mode);
617 615
618static const char *max98088_extmic_text[] = { "None", "MIC1", "MIC2" }; 616static const char *max98088_extmic_text[] = { "None", "MIC1", "MIC2" };
619 617
620static const struct soc_enum max98088_extmic_enum = 618static SOC_ENUM_SINGLE_DECL(max98088_extmic_enum,
621 SOC_ENUM_SINGLE(M98088_REG_48_CFG_MIC, 0, 3, max98088_extmic_text); 619 M98088_REG_48_CFG_MIC, 0,
620 max98088_extmic_text);
622 621
623static const struct snd_kcontrol_new max98088_extmic_mux = 622static const struct snd_kcontrol_new max98088_extmic_mux =
624 SOC_DAPM_ENUM("External MIC Mux", max98088_extmic_enum); 623 SOC_DAPM_ENUM("External MIC Mux", max98088_extmic_enum);
@@ -626,12 +625,12 @@ static const struct snd_kcontrol_new max98088_extmic_mux =
626static const char *max98088_dai1_fltr[] = { 625static const char *max98088_dai1_fltr[] = {
627 "Off", "fc=258/fs=16k", "fc=500/fs=16k", 626 "Off", "fc=258/fs=16k", "fc=500/fs=16k",
628 "fc=258/fs=8k", "fc=500/fs=8k", "fc=200"}; 627 "fc=258/fs=8k", "fc=500/fs=8k", "fc=200"};
629static const struct soc_enum max98088_dai1_dac_filter_enum[] = { 628static SOC_ENUM_SINGLE_DECL(max98088_dai1_dac_filter_enum,
630 SOC_ENUM_SINGLE(M98088_REG_18_DAI1_FILTERS, 0, 6, max98088_dai1_fltr), 629 M98088_REG_18_DAI1_FILTERS, 0,
631}; 630 max98088_dai1_fltr);
632static const struct soc_enum max98088_dai1_adc_filter_enum[] = { 631static SOC_ENUM_SINGLE_DECL(max98088_dai1_adc_filter_enum,
633 SOC_ENUM_SINGLE(M98088_REG_18_DAI1_FILTERS, 4, 6, max98088_dai1_fltr), 632 M98088_REG_18_DAI1_FILTERS, 4,
634}; 633 max98088_dai1_fltr);
635 634
636static int max98088_mic1pre_set(struct snd_kcontrol *kcontrol, 635static int max98088_mic1pre_set(struct snd_kcontrol *kcontrol,
637 struct snd_ctl_elem_value *ucontrol) 636 struct snd_ctl_elem_value *ucontrol)
@@ -1849,7 +1848,7 @@ static void max98088_handle_eq_pdata(struct snd_soc_codec *codec)
1849 1848
1850 /* Now point the soc_enum to .texts array items */ 1849 /* Now point the soc_enum to .texts array items */
1851 max98088->eq_enum.texts = max98088->eq_texts; 1850 max98088->eq_enum.texts = max98088->eq_texts;
1852 max98088->eq_enum.max = max98088->eq_textcnt; 1851 max98088->eq_enum.items = max98088->eq_textcnt;
1853 1852
1854 ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls)); 1853 ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls));
1855 if (ret != 0) 1854 if (ret != 0)
@@ -1915,12 +1914,6 @@ static int max98088_probe(struct snd_soc_codec *codec)
1915 1914
1916 regcache_mark_dirty(max98088->regmap); 1915 regcache_mark_dirty(max98088->regmap);
1917 1916
1918 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1919 if (ret != 0) {
1920 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1921 return ret;
1922 }
1923
1924 /* initialize private data */ 1917 /* initialize private data */
1925 1918
1926 max98088->sysclk = (unsigned)-1; 1919 max98088->sysclk = (unsigned)-1;
diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c
index 9f714ea86613..98c6e104357c 100644
--- a/sound/soc/codecs/max98090.c
+++ b/sound/soc/codecs/max98090.c
@@ -513,65 +513,75 @@ static const char *max98090_perf_pwr_text[] =
513static const char *max98090_pwr_perf_text[] = 513static const char *max98090_pwr_perf_text[] =
514 { "Low Power", "High Performance" }; 514 { "Low Power", "High Performance" };
515 515
516static const struct soc_enum max98090_vcmbandgap_enum = 516static SOC_ENUM_SINGLE_DECL(max98090_vcmbandgap_enum,
517 SOC_ENUM_SINGLE(M98090_REG_BIAS_CONTROL, M98090_VCM_MODE_SHIFT, 517 M98090_REG_BIAS_CONTROL,
518 ARRAY_SIZE(max98090_pwr_perf_text), max98090_pwr_perf_text); 518 M98090_VCM_MODE_SHIFT,
519 max98090_pwr_perf_text);
519 520
520static const char *max98090_osr128_text[] = { "64*fs", "128*fs" }; 521static const char *max98090_osr128_text[] = { "64*fs", "128*fs" };
521 522
522static const struct soc_enum max98090_osr128_enum = 523static SOC_ENUM_SINGLE_DECL(max98090_osr128_enum,
523 SOC_ENUM_SINGLE(M98090_REG_ADC_CONTROL, M98090_OSR128_SHIFT, 524 M98090_REG_ADC_CONTROL,
524 ARRAY_SIZE(max98090_osr128_text), max98090_osr128_text); 525 M98090_OSR128_SHIFT,
526 max98090_osr128_text);
525 527
526static const char *max98090_mode_text[] = { "Voice", "Music" }; 528static const char *max98090_mode_text[] = { "Voice", "Music" };
527 529
528static const struct soc_enum max98090_mode_enum = 530static SOC_ENUM_SINGLE_DECL(max98090_mode_enum,
529 SOC_ENUM_SINGLE(M98090_REG_FILTER_CONFIG, M98090_MODE_SHIFT, 531 M98090_REG_FILTER_CONFIG,
530 ARRAY_SIZE(max98090_mode_text), max98090_mode_text); 532 M98090_MODE_SHIFT,
533 max98090_mode_text);
531 534
532static const struct soc_enum max98090_filter_dmic34mode_enum = 535static SOC_ENUM_SINGLE_DECL(max98090_filter_dmic34mode_enum,
533 SOC_ENUM_SINGLE(M98090_REG_FILTER_CONFIG, 536 M98090_REG_FILTER_CONFIG,
534 M98090_FLT_DMIC34MODE_SHIFT, 537 M98090_FLT_DMIC34MODE_SHIFT,
535 ARRAY_SIZE(max98090_mode_text), max98090_mode_text); 538 max98090_mode_text);
536 539
537static const char *max98090_drcatk_text[] = 540static const char *max98090_drcatk_text[] =
538 { "0.5ms", "1ms", "5ms", "10ms", "25ms", "50ms", "100ms", "200ms" }; 541 { "0.5ms", "1ms", "5ms", "10ms", "25ms", "50ms", "100ms", "200ms" };
539 542
540static const struct soc_enum max98090_drcatk_enum = 543static SOC_ENUM_SINGLE_DECL(max98090_drcatk_enum,
541 SOC_ENUM_SINGLE(M98090_REG_DRC_TIMING, M98090_DRCATK_SHIFT, 544 M98090_REG_DRC_TIMING,
542 ARRAY_SIZE(max98090_drcatk_text), max98090_drcatk_text); 545 M98090_DRCATK_SHIFT,
546 max98090_drcatk_text);
543 547
544static const char *max98090_drcrls_text[] = 548static const char *max98090_drcrls_text[] =
545 { "8s", "4s", "2s", "1s", "0.5s", "0.25s", "0.125s", "0.0625s" }; 549 { "8s", "4s", "2s", "1s", "0.5s", "0.25s", "0.125s", "0.0625s" };
546 550
547static const struct soc_enum max98090_drcrls_enum = 551static SOC_ENUM_SINGLE_DECL(max98090_drcrls_enum,
548 SOC_ENUM_SINGLE(M98090_REG_DRC_TIMING, M98090_DRCRLS_SHIFT, 552 M98090_REG_DRC_TIMING,
549 ARRAY_SIZE(max98090_drcrls_text), max98090_drcrls_text); 553 M98090_DRCRLS_SHIFT,
554 max98090_drcrls_text);
550 555
551static const char *max98090_alccmp_text[] = 556static const char *max98090_alccmp_text[] =
552 { "1:1", "1:1.5", "1:2", "1:4", "1:INF" }; 557 { "1:1", "1:1.5", "1:2", "1:4", "1:INF" };
553 558
554static const struct soc_enum max98090_alccmp_enum = 559static SOC_ENUM_SINGLE_DECL(max98090_alccmp_enum,
555 SOC_ENUM_SINGLE(M98090_REG_DRC_COMPRESSOR, M98090_DRCCMP_SHIFT, 560 M98090_REG_DRC_COMPRESSOR,
556 ARRAY_SIZE(max98090_alccmp_text), max98090_alccmp_text); 561 M98090_DRCCMP_SHIFT,
562 max98090_alccmp_text);
557 563
558static const char *max98090_drcexp_text[] = { "1:1", "2:1", "3:1" }; 564static const char *max98090_drcexp_text[] = { "1:1", "2:1", "3:1" };
559 565
560static const struct soc_enum max98090_drcexp_enum = 566static SOC_ENUM_SINGLE_DECL(max98090_drcexp_enum,
561 SOC_ENUM_SINGLE(M98090_REG_DRC_EXPANDER, M98090_DRCEXP_SHIFT, 567 M98090_REG_DRC_EXPANDER,
562 ARRAY_SIZE(max98090_drcexp_text), max98090_drcexp_text); 568 M98090_DRCEXP_SHIFT,
569 max98090_drcexp_text);
563 570
564static const struct soc_enum max98090_dac_perfmode_enum = 571static SOC_ENUM_SINGLE_DECL(max98090_dac_perfmode_enum,
565 SOC_ENUM_SINGLE(M98090_REG_DAC_CONTROL, M98090_PERFMODE_SHIFT, 572 M98090_REG_DAC_CONTROL,
566 ARRAY_SIZE(max98090_perf_pwr_text), max98090_perf_pwr_text); 573 M98090_PERFMODE_SHIFT,
574 max98090_perf_pwr_text);
567 575
568static const struct soc_enum max98090_dachp_enum = 576static SOC_ENUM_SINGLE_DECL(max98090_dachp_enum,
569 SOC_ENUM_SINGLE(M98090_REG_DAC_CONTROL, M98090_DACHP_SHIFT, 577 M98090_REG_DAC_CONTROL,
570 ARRAY_SIZE(max98090_pwr_perf_text), max98090_pwr_perf_text); 578 M98090_DACHP_SHIFT,
579 max98090_pwr_perf_text);
571 580
572static const struct soc_enum max98090_adchp_enum = 581static SOC_ENUM_SINGLE_DECL(max98090_adchp_enum,
573 SOC_ENUM_SINGLE(M98090_REG_ADC_CONTROL, M98090_ADCHP_SHIFT, 582 M98090_REG_ADC_CONTROL,
574 ARRAY_SIZE(max98090_pwr_perf_text), max98090_pwr_perf_text); 583 M98090_ADCHP_SHIFT,
584 max98090_pwr_perf_text);
575 585
576static const struct snd_kcontrol_new max98090_snd_controls[] = { 586static const struct snd_kcontrol_new max98090_snd_controls[] = {
577 SOC_ENUM("MIC Bias VCM Bandgap", max98090_vcmbandgap_enum), 587 SOC_ENUM("MIC Bias VCM Bandgap", max98090_vcmbandgap_enum),
@@ -842,39 +852,42 @@ static int max98090_micinput_event(struct snd_soc_dapm_widget *w,
842 852
843static const char *mic1_mux_text[] = { "IN12", "IN56" }; 853static const char *mic1_mux_text[] = { "IN12", "IN56" };
844 854
845static const struct soc_enum mic1_mux_enum = 855static SOC_ENUM_SINGLE_DECL(mic1_mux_enum,
846 SOC_ENUM_SINGLE(M98090_REG_INPUT_MODE, M98090_EXTMIC1_SHIFT, 856 M98090_REG_INPUT_MODE,
847 ARRAY_SIZE(mic1_mux_text), mic1_mux_text); 857 M98090_EXTMIC1_SHIFT,
858 mic1_mux_text);
848 859
849static const struct snd_kcontrol_new max98090_mic1_mux = 860static const struct snd_kcontrol_new max98090_mic1_mux =
850 SOC_DAPM_ENUM("MIC1 Mux", mic1_mux_enum); 861 SOC_DAPM_ENUM("MIC1 Mux", mic1_mux_enum);
851 862
852static const char *mic2_mux_text[] = { "IN34", "IN56" }; 863static const char *mic2_mux_text[] = { "IN34", "IN56" };
853 864
854static const struct soc_enum mic2_mux_enum = 865static SOC_ENUM_SINGLE_DECL(mic2_mux_enum,
855 SOC_ENUM_SINGLE(M98090_REG_INPUT_MODE, M98090_EXTMIC2_SHIFT, 866 M98090_REG_INPUT_MODE,
856 ARRAY_SIZE(mic2_mux_text), mic2_mux_text); 867 M98090_EXTMIC2_SHIFT,
868 mic2_mux_text);
857 869
858static const struct snd_kcontrol_new max98090_mic2_mux = 870static const struct snd_kcontrol_new max98090_mic2_mux =
859 SOC_DAPM_ENUM("MIC2 Mux", mic2_mux_enum); 871 SOC_DAPM_ENUM("MIC2 Mux", mic2_mux_enum);
860 872
861static const char *dmic_mux_text[] = { "ADC", "DMIC" }; 873static const char *dmic_mux_text[] = { "ADC", "DMIC" };
862 874
863static const struct soc_enum dmic_mux_enum = 875static SOC_ENUM_SINGLE_VIRT_DECL(dmic_mux_enum, dmic_mux_text);
864 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dmic_mux_text), dmic_mux_text);
865 876
866static const struct snd_kcontrol_new max98090_dmic_mux = 877static const struct snd_kcontrol_new max98090_dmic_mux =
867 SOC_DAPM_ENUM_VIRT("DMIC Mux", dmic_mux_enum); 878 SOC_DAPM_ENUM_VIRT("DMIC Mux", dmic_mux_enum);
868 879
869static const char *max98090_micpre_text[] = { "Off", "On" }; 880static const char *max98090_micpre_text[] = { "Off", "On" };
870 881
871static const struct soc_enum max98090_pa1en_enum = 882static SOC_ENUM_SINGLE_DECL(max98090_pa1en_enum,
872 SOC_ENUM_SINGLE(M98090_REG_MIC1_INPUT_LEVEL, M98090_MIC_PA1EN_SHIFT, 883 M98090_REG_MIC1_INPUT_LEVEL,
873 ARRAY_SIZE(max98090_micpre_text), max98090_micpre_text); 884 M98090_MIC_PA1EN_SHIFT,
885 max98090_micpre_text);
874 886
875static const struct soc_enum max98090_pa2en_enum = 887static SOC_ENUM_SINGLE_DECL(max98090_pa2en_enum,
876 SOC_ENUM_SINGLE(M98090_REG_MIC2_INPUT_LEVEL, M98090_MIC_PA2EN_SHIFT, 888 M98090_REG_MIC2_INPUT_LEVEL,
877 ARRAY_SIZE(max98090_micpre_text), max98090_micpre_text); 889 M98090_MIC_PA2EN_SHIFT,
890 max98090_micpre_text);
878 891
879/* LINEA mixer switch */ 892/* LINEA mixer switch */
880static const struct snd_kcontrol_new max98090_linea_mixer_controls[] = { 893static const struct snd_kcontrol_new max98090_linea_mixer_controls[] = {
@@ -938,13 +951,15 @@ static const struct snd_kcontrol_new max98090_right_adc_mixer_controls[] = {
938 951
939static const char *lten_mux_text[] = { "Normal", "Loopthrough" }; 952static const char *lten_mux_text[] = { "Normal", "Loopthrough" };
940 953
941static const struct soc_enum ltenl_mux_enum = 954static SOC_ENUM_SINGLE_DECL(ltenl_mux_enum,
942 SOC_ENUM_SINGLE(M98090_REG_IO_CONFIGURATION, M98090_LTEN_SHIFT, 955 M98090_REG_IO_CONFIGURATION,
943 ARRAY_SIZE(lten_mux_text), lten_mux_text); 956 M98090_LTEN_SHIFT,
957 lten_mux_text);
944 958
945static const struct soc_enum ltenr_mux_enum = 959static SOC_ENUM_SINGLE_DECL(ltenr_mux_enum,
946 SOC_ENUM_SINGLE(M98090_REG_IO_CONFIGURATION, M98090_LTEN_SHIFT, 960 M98090_REG_IO_CONFIGURATION,
947 ARRAY_SIZE(lten_mux_text), lten_mux_text); 961 M98090_LTEN_SHIFT,
962 lten_mux_text);
948 963
949static const struct snd_kcontrol_new max98090_ltenl_mux = 964static const struct snd_kcontrol_new max98090_ltenl_mux =
950 SOC_DAPM_ENUM("LTENL Mux", ltenl_mux_enum); 965 SOC_DAPM_ENUM("LTENL Mux", ltenl_mux_enum);
@@ -954,13 +969,15 @@ static const struct snd_kcontrol_new max98090_ltenr_mux =
954 969
955static const char *lben_mux_text[] = { "Normal", "Loopback" }; 970static const char *lben_mux_text[] = { "Normal", "Loopback" };
956 971
957static const struct soc_enum lbenl_mux_enum = 972static SOC_ENUM_SINGLE_DECL(lbenl_mux_enum,
958 SOC_ENUM_SINGLE(M98090_REG_IO_CONFIGURATION, M98090_LBEN_SHIFT, 973 M98090_REG_IO_CONFIGURATION,
959 ARRAY_SIZE(lben_mux_text), lben_mux_text); 974 M98090_LBEN_SHIFT,
975 lben_mux_text);
960 976
961static const struct soc_enum lbenr_mux_enum = 977static SOC_ENUM_SINGLE_DECL(lbenr_mux_enum,
962 SOC_ENUM_SINGLE(M98090_REG_IO_CONFIGURATION, M98090_LBEN_SHIFT, 978 M98090_REG_IO_CONFIGURATION,
963 ARRAY_SIZE(lben_mux_text), lben_mux_text); 979 M98090_LBEN_SHIFT,
980 lben_mux_text);
964 981
965static const struct snd_kcontrol_new max98090_lbenl_mux = 982static const struct snd_kcontrol_new max98090_lbenl_mux =
966 SOC_DAPM_ENUM("LBENL Mux", lbenl_mux_enum); 983 SOC_DAPM_ENUM("LBENL Mux", lbenl_mux_enum);
@@ -972,13 +989,15 @@ static const char *stenl_mux_text[] = { "Normal", "Sidetone Left" };
972 989
973static const char *stenr_mux_text[] = { "Normal", "Sidetone Right" }; 990static const char *stenr_mux_text[] = { "Normal", "Sidetone Right" };
974 991
975static const struct soc_enum stenl_mux_enum = 992static SOC_ENUM_SINGLE_DECL(stenl_mux_enum,
976 SOC_ENUM_SINGLE(M98090_REG_ADC_SIDETONE, M98090_DSTSL_SHIFT, 993 M98090_REG_ADC_SIDETONE,
977 ARRAY_SIZE(stenl_mux_text), stenl_mux_text); 994 M98090_DSTSL_SHIFT,
995 stenl_mux_text);
978 996
979static const struct soc_enum stenr_mux_enum = 997static SOC_ENUM_SINGLE_DECL(stenr_mux_enum,
980 SOC_ENUM_SINGLE(M98090_REG_ADC_SIDETONE, M98090_DSTSR_SHIFT, 998 M98090_REG_ADC_SIDETONE,
981 ARRAY_SIZE(stenr_mux_text), stenr_mux_text); 999 M98090_DSTSR_SHIFT,
1000 stenr_mux_text);
982 1001
983static const struct snd_kcontrol_new max98090_stenl_mux = 1002static const struct snd_kcontrol_new max98090_stenl_mux =
984 SOC_DAPM_ENUM("STENL Mux", stenl_mux_enum); 1003 SOC_DAPM_ENUM("STENL Mux", stenl_mux_enum);
@@ -1086,9 +1105,10 @@ static const struct snd_kcontrol_new max98090_right_rcv_mixer_controls[] = {
1086 1105
1087static const char *linmod_mux_text[] = { "Left Only", "Left and Right" }; 1106static const char *linmod_mux_text[] = { "Left Only", "Left and Right" };
1088 1107
1089static const struct soc_enum linmod_mux_enum = 1108static SOC_ENUM_SINGLE_DECL(linmod_mux_enum,
1090 SOC_ENUM_SINGLE(M98090_REG_LOUTR_MIXER, M98090_LINMOD_SHIFT, 1109 M98090_REG_LOUTR_MIXER,
1091 ARRAY_SIZE(linmod_mux_text), linmod_mux_text); 1110 M98090_LINMOD_SHIFT,
1111 linmod_mux_text);
1092 1112
1093static const struct snd_kcontrol_new max98090_linmod_mux = 1113static const struct snd_kcontrol_new max98090_linmod_mux =
1094 SOC_DAPM_ENUM("LINMOD Mux", linmod_mux_enum); 1114 SOC_DAPM_ENUM("LINMOD Mux", linmod_mux_enum);
@@ -1098,16 +1118,18 @@ static const char *mixhpsel_mux_text[] = { "DAC Only", "HP Mixer" };
1098/* 1118/*
1099 * This is a mux as it selects the HP output, but to DAPM it is a Mixer enable 1119 * This is a mux as it selects the HP output, but to DAPM it is a Mixer enable
1100 */ 1120 */
1101static const struct soc_enum mixhplsel_mux_enum = 1121static SOC_ENUM_SINGLE_DECL(mixhplsel_mux_enum,
1102 SOC_ENUM_SINGLE(M98090_REG_HP_CONTROL, M98090_MIXHPLSEL_SHIFT, 1122 M98090_REG_HP_CONTROL,
1103 ARRAY_SIZE(mixhpsel_mux_text), mixhpsel_mux_text); 1123 M98090_MIXHPLSEL_SHIFT,
1124 mixhpsel_mux_text);
1104 1125
1105static const struct snd_kcontrol_new max98090_mixhplsel_mux = 1126static const struct snd_kcontrol_new max98090_mixhplsel_mux =
1106 SOC_DAPM_ENUM("MIXHPLSEL Mux", mixhplsel_mux_enum); 1127 SOC_DAPM_ENUM("MIXHPLSEL Mux", mixhplsel_mux_enum);
1107 1128
1108static const struct soc_enum mixhprsel_mux_enum = 1129static SOC_ENUM_SINGLE_DECL(mixhprsel_mux_enum,
1109 SOC_ENUM_SINGLE(M98090_REG_HP_CONTROL, M98090_MIXHPRSEL_SHIFT, 1130 M98090_REG_HP_CONTROL,
1110 ARRAY_SIZE(mixhpsel_mux_text), mixhpsel_mux_text); 1131 M98090_MIXHPRSEL_SHIFT,
1132 mixhpsel_mux_text);
1111 1133
1112static const struct snd_kcontrol_new max98090_mixhprsel_mux = 1134static const struct snd_kcontrol_new max98090_mixhprsel_mux =
1113 SOC_DAPM_ENUM("MIXHPRSEL Mux", mixhprsel_mux_enum); 1135 SOC_DAPM_ENUM("MIXHPRSEL Mux", mixhprsel_mux_enum);
@@ -2196,14 +2218,6 @@ static int max98090_probe(struct snd_soc_codec *codec)
2196 2218
2197 max98090->codec = codec; 2219 max98090->codec = codec;
2198 2220
2199 codec->control_data = max98090->regmap;
2200
2201 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
2202 if (ret != 0) {
2203 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
2204 return ret;
2205 }
2206
2207 /* Reset the codec, the DSP core, and disable all interrupts */ 2221 /* Reset the codec, the DSP core, and disable all interrupts */
2208 max98090_reset(max98090); 2222 max98090_reset(max98090);
2209 2223
@@ -2329,7 +2343,6 @@ static int max98090_i2c_probe(struct i2c_client *i2c,
2329 2343
2330 max98090->devtype = id->driver_data; 2344 max98090->devtype = id->driver_data;
2331 i2c_set_clientdata(i2c, max98090); 2345 i2c_set_clientdata(i2c, max98090);
2332 max98090->control_data = i2c;
2333 max98090->pdata = i2c->dev.platform_data; 2346 max98090->pdata = i2c->dev.platform_data;
2334 max98090->irq = i2c->irq; 2347 max98090->irq = i2c->irq;
2335 2348
diff --git a/sound/soc/codecs/max98090.h b/sound/soc/codecs/max98090.h
index 7e103f249053..1a4e2334a7b2 100644
--- a/sound/soc/codecs/max98090.h
+++ b/sound/soc/codecs/max98090.h
@@ -1523,7 +1523,6 @@ struct max98090_priv {
1523 struct regmap *regmap; 1523 struct regmap *regmap;
1524 struct snd_soc_codec *codec; 1524 struct snd_soc_codec *codec;
1525 enum max98090_type devtype; 1525 enum max98090_type devtype;
1526 void *control_data;
1527 struct max98090_pdata *pdata; 1526 struct max98090_pdata *pdata;
1528 unsigned int sysclk; 1527 unsigned int sysclk;
1529 unsigned int bclk; 1528 unsigned int bclk;
diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 3ba1170ebb53..03f0536e6f61 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -560,25 +560,27 @@ static void m98095_biquad_band(struct snd_soc_codec *codec, unsigned int dai,
560} 560}
561 561
562static const char * const max98095_fltr_mode[] = { "Voice", "Music" }; 562static const char * const max98095_fltr_mode[] = { "Voice", "Music" };
563static const struct soc_enum max98095_dai1_filter_mode_enum[] = { 563static SOC_ENUM_SINGLE_DECL(max98095_dai1_filter_mode_enum,
564 SOC_ENUM_SINGLE(M98095_02E_DAI1_FILTERS, 7, 2, max98095_fltr_mode), 564 M98095_02E_DAI1_FILTERS, 7,
565}; 565 max98095_fltr_mode);
566static const struct soc_enum max98095_dai2_filter_mode_enum[] = { 566static SOC_ENUM_SINGLE_DECL(max98095_dai2_filter_mode_enum,
567 SOC_ENUM_SINGLE(M98095_038_DAI2_FILTERS, 7, 2, max98095_fltr_mode), 567 M98095_038_DAI2_FILTERS, 7,
568}; 568 max98095_fltr_mode);
569 569
570static const char * const max98095_extmic_text[] = { "None", "MIC1", "MIC2" }; 570static const char * const max98095_extmic_text[] = { "None", "MIC1", "MIC2" };
571 571
572static const struct soc_enum max98095_extmic_enum = 572static SOC_ENUM_SINGLE_DECL(max98095_extmic_enum,
573 SOC_ENUM_SINGLE(M98095_087_CFG_MIC, 0, 3, max98095_extmic_text); 573 M98095_087_CFG_MIC, 0,
574 max98095_extmic_text);
574 575
575static const struct snd_kcontrol_new max98095_extmic_mux = 576static const struct snd_kcontrol_new max98095_extmic_mux =
576 SOC_DAPM_ENUM("External MIC Mux", max98095_extmic_enum); 577 SOC_DAPM_ENUM("External MIC Mux", max98095_extmic_enum);
577 578
578static const char * const max98095_linein_text[] = { "INA", "INB" }; 579static const char * const max98095_linein_text[] = { "INA", "INB" };
579 580
580static const struct soc_enum max98095_linein_enum = 581static SOC_ENUM_SINGLE_DECL(max98095_linein_enum,
581 SOC_ENUM_SINGLE(M98095_086_CFG_LINE, 6, 2, max98095_linein_text); 582 M98095_086_CFG_LINE, 6,
583 max98095_linein_text);
582 584
583static const struct snd_kcontrol_new max98095_linein_mux = 585static const struct snd_kcontrol_new max98095_linein_mux =
584 SOC_DAPM_ENUM("Linein Input Mux", max98095_linein_enum); 586 SOC_DAPM_ENUM("Linein Input Mux", max98095_linein_enum);
@@ -586,24 +588,26 @@ static const struct snd_kcontrol_new max98095_linein_mux =
586static const char * const max98095_line_mode_text[] = { 588static const char * const max98095_line_mode_text[] = {
587 "Stereo", "Differential"}; 589 "Stereo", "Differential"};
588 590
589static const struct soc_enum max98095_linein_mode_enum = 591static SOC_ENUM_SINGLE_DECL(max98095_linein_mode_enum,
590 SOC_ENUM_SINGLE(M98095_086_CFG_LINE, 7, 2, max98095_line_mode_text); 592 M98095_086_CFG_LINE, 7,
593 max98095_line_mode_text);
591 594
592static const struct soc_enum max98095_lineout_mode_enum = 595static SOC_ENUM_SINGLE_DECL(max98095_lineout_mode_enum,
593 SOC_ENUM_SINGLE(M98095_086_CFG_LINE, 4, 2, max98095_line_mode_text); 596 M98095_086_CFG_LINE, 4,
597 max98095_line_mode_text);
594 598
595static const char * const max98095_dai_fltr[] = { 599static const char * const max98095_dai_fltr[] = {
596 "Off", "Elliptical-HPF-16k", "Butterworth-HPF-16k", 600 "Off", "Elliptical-HPF-16k", "Butterworth-HPF-16k",
597 "Elliptical-HPF-8k", "Butterworth-HPF-8k", "Butterworth-HPF-Fs/240"}; 601 "Elliptical-HPF-8k", "Butterworth-HPF-8k", "Butterworth-HPF-Fs/240"};
598static const struct soc_enum max98095_dai1_dac_filter_enum[] = { 602static SOC_ENUM_SINGLE_DECL(max98095_dai1_dac_filter_enum,
599 SOC_ENUM_SINGLE(M98095_02E_DAI1_FILTERS, 0, 6, max98095_dai_fltr), 603 M98095_02E_DAI1_FILTERS, 0,
600}; 604 max98095_dai_fltr);
601static const struct soc_enum max98095_dai2_dac_filter_enum[] = { 605static SOC_ENUM_SINGLE_DECL(max98095_dai2_dac_filter_enum,
602 SOC_ENUM_SINGLE(M98095_038_DAI2_FILTERS, 0, 6, max98095_dai_fltr), 606 M98095_038_DAI2_FILTERS, 0,
603}; 607 max98095_dai_fltr);
604static const struct soc_enum max98095_dai3_dac_filter_enum[] = { 608static SOC_ENUM_SINGLE_DECL(max98095_dai3_dac_filter_enum,
605 SOC_ENUM_SINGLE(M98095_042_DAI3_FILTERS, 0, 6, max98095_dai_fltr), 609 M98095_042_DAI3_FILTERS, 0,
606}; 610 max98095_dai_fltr);
607 611
608static int max98095_mic1pre_set(struct snd_kcontrol *kcontrol, 612static int max98095_mic1pre_set(struct snd_kcontrol *kcontrol,
609 struct snd_ctl_elem_value *ucontrol) 613 struct snd_ctl_elem_value *ucontrol)
@@ -1861,7 +1865,7 @@ static void max98095_handle_eq_pdata(struct snd_soc_codec *codec)
1861 1865
1862 /* Now point the soc_enum to .texts array items */ 1866 /* Now point the soc_enum to .texts array items */
1863 max98095->eq_enum.texts = max98095->eq_texts; 1867 max98095->eq_enum.texts = max98095->eq_texts;
1864 max98095->eq_enum.max = max98095->eq_textcnt; 1868 max98095->eq_enum.items = max98095->eq_textcnt;
1865 1869
1866 ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls)); 1870 ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls));
1867 if (ret != 0) 1871 if (ret != 0)
@@ -2016,7 +2020,7 @@ static void max98095_handle_bq_pdata(struct snd_soc_codec *codec)
2016 2020
2017 /* Now point the soc_enum to .texts array items */ 2021 /* Now point the soc_enum to .texts array items */
2018 max98095->bq_enum.texts = max98095->bq_texts; 2022 max98095->bq_enum.texts = max98095->bq_texts;
2019 max98095->bq_enum.max = max98095->bq_textcnt; 2023 max98095->bq_enum.items = max98095->bq_textcnt;
2020 2024
2021 ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls)); 2025 ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls));
2022 if (ret != 0) 2026 if (ret != 0)
@@ -2234,12 +2238,6 @@ static int max98095_probe(struct snd_soc_codec *codec)
2234 struct i2c_client *client; 2238 struct i2c_client *client;
2235 int ret = 0; 2239 int ret = 0;
2236 2240
2237 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
2238 if (ret != 0) {
2239 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
2240 return ret;
2241 }
2242
2243 /* reset the codec, the DSP core, and disable all interrupts */ 2241 /* reset the codec, the DSP core, and disable all interrupts */
2244 max98095_reset(codec); 2242 max98095_reset(codec);
2245 2243
diff --git a/sound/soc/codecs/max9850.c b/sound/soc/codecs/max9850.c
index 82757ebf0301..4fdf5aaa236f 100644
--- a/sound/soc/codecs/max9850.c
+++ b/sound/soc/codecs/max9850.c
@@ -312,14 +312,6 @@ static int max9850_resume(struct snd_soc_codec *codec)
312 312
313static int max9850_probe(struct snd_soc_codec *codec) 313static int max9850_probe(struct snd_soc_codec *codec)
314{ 314{
315 int ret;
316
317 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
318 if (ret < 0) {
319 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
320 return ret;
321 }
322
323 /* enable zero-detect */ 315 /* enable zero-detect */
324 snd_soc_update_bits(codec, MAX9850_GENERAL_PURPOSE, 1, 1); 316 snd_soc_update_bits(codec, MAX9850_GENERAL_PURPOSE, 1, 1);
325 /* enable slew-rate control */ 317 /* enable slew-rate control */
diff --git a/sound/soc/codecs/mc13783.c b/sound/soc/codecs/mc13783.c
index 582c2bbd42cb..2c59b1fb69dc 100644
--- a/sound/soc/codecs/mc13783.c
+++ b/sound/soc/codecs/mc13783.c
@@ -106,8 +106,7 @@ static int mc13783_pcm_hw_params_dac(struct snd_pcm_substream *substream,
106 struct snd_pcm_hw_params *params, 106 struct snd_pcm_hw_params *params,
107 struct snd_soc_dai *dai) 107 struct snd_soc_dai *dai)
108{ 108{
109 struct snd_soc_pcm_runtime *rtd = substream->private_data; 109 struct snd_soc_codec *codec = dai->codec;
110 struct snd_soc_codec *codec = rtd->codec;
111 unsigned int rate = params_rate(params); 110 unsigned int rate = params_rate(params);
112 int i; 111 int i;
113 112
@@ -126,8 +125,7 @@ static int mc13783_pcm_hw_params_codec(struct snd_pcm_substream *substream,
126 struct snd_pcm_hw_params *params, 125 struct snd_pcm_hw_params *params,
127 struct snd_soc_dai *dai) 126 struct snd_soc_dai *dai)
128{ 127{
129 struct snd_soc_pcm_runtime *rtd = substream->private_data; 128 struct snd_soc_codec *codec = dai->codec;
130 struct snd_soc_codec *codec = rtd->codec;
131 unsigned int rate = params_rate(params); 129 unsigned int rate = params_rate(params);
132 unsigned int val; 130 unsigned int val;
133 131
@@ -408,8 +406,7 @@ static const char * const adcl_enum_text[] = {
408 "MC1L", "RXINL", 406 "MC1L", "RXINL",
409}; 407};
410 408
411static const struct soc_enum adcl_enum = 409static SOC_ENUM_SINGLE_VIRT_DECL(adcl_enum, adcl_enum_text);
412 SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(adcl_enum_text), adcl_enum_text);
413 410
414static const struct snd_kcontrol_new left_input_mux = 411static const struct snd_kcontrol_new left_input_mux =
415 SOC_DAPM_ENUM_VIRT("Route", adcl_enum); 412 SOC_DAPM_ENUM_VIRT("Route", adcl_enum);
@@ -418,8 +415,7 @@ static const char * const adcr_enum_text[] = {
418 "MC1R", "MC2", "RXINR", "TXIN", 415 "MC1R", "MC2", "RXINR", "TXIN",
419}; 416};
420 417
421static const struct soc_enum adcr_enum = 418static SOC_ENUM_SINGLE_VIRT_DECL(adcr_enum, adcr_enum_text);
422 SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(adcr_enum_text), adcr_enum_text);
423 419
424static const struct snd_kcontrol_new right_input_mux = 420static const struct snd_kcontrol_new right_input_mux =
425 SOC_DAPM_ENUM_VIRT("Route", adcr_enum); 421 SOC_DAPM_ENUM_VIRT("Route", adcr_enum);
@@ -430,8 +426,8 @@ static const struct snd_kcontrol_new samp_ctl =
430static const char * const speaker_amp_source_text[] = { 426static const char * const speaker_amp_source_text[] = {
431 "CODEC", "Right" 427 "CODEC", "Right"
432}; 428};
433static const SOC_ENUM_SINGLE_DECL(speaker_amp_source, MC13783_AUDIO_RX0, 4, 429static SOC_ENUM_SINGLE_DECL(speaker_amp_source, MC13783_AUDIO_RX0, 4,
434 speaker_amp_source_text); 430 speaker_amp_source_text);
435static const struct snd_kcontrol_new speaker_amp_source_mux = 431static const struct snd_kcontrol_new speaker_amp_source_mux =
436 SOC_DAPM_ENUM("Speaker Amp Source MUX", speaker_amp_source); 432 SOC_DAPM_ENUM("Speaker Amp Source MUX", speaker_amp_source);
437 433
@@ -439,8 +435,8 @@ static const char * const headset_amp_source_text[] = {
439 "CODEC", "Mixer" 435 "CODEC", "Mixer"
440}; 436};
441 437
442static const SOC_ENUM_SINGLE_DECL(headset_amp_source, MC13783_AUDIO_RX0, 11, 438static SOC_ENUM_SINGLE_DECL(headset_amp_source, MC13783_AUDIO_RX0, 11,
443 headset_amp_source_text); 439 headset_amp_source_text);
444static const struct snd_kcontrol_new headset_amp_source_mux = 440static const struct snd_kcontrol_new headset_amp_source_mux =
445 SOC_DAPM_ENUM("Headset Amp Source MUX", headset_amp_source); 441 SOC_DAPM_ENUM("Headset Amp Source MUX", headset_amp_source);
446 442
@@ -580,9 +576,9 @@ static struct snd_soc_dapm_route mc13783_routes[] = {
580static const char * const mc13783_3d_mixer[] = {"Stereo", "Phase Mix", 576static const char * const mc13783_3d_mixer[] = {"Stereo", "Phase Mix",
581 "Mono", "Mono Mix"}; 577 "Mono", "Mono Mix"};
582 578
583static const struct soc_enum mc13783_enum_3d_mixer = 579static SOC_ENUM_SINGLE_DECL(mc13783_enum_3d_mixer,
584 SOC_ENUM_SINGLE(MC13783_AUDIO_RX1, 16, ARRAY_SIZE(mc13783_3d_mixer), 580 MC13783_AUDIO_RX1, 16,
585 mc13783_3d_mixer); 581 mc13783_3d_mixer);
586 582
587static struct snd_kcontrol_new mc13783_control_list[] = { 583static struct snd_kcontrol_new mc13783_control_list[] = {
588 SOC_SINGLE("Loudspeaker enable", MC13783_AUDIO_RX0, 5, 1, 0), 584 SOC_SINGLE("Loudspeaker enable", MC13783_AUDIO_RX0, 5, 1, 0),
@@ -614,8 +610,8 @@ static int mc13783_probe(struct snd_soc_codec *codec)
614 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec); 610 struct mc13783_priv *priv = snd_soc_codec_get_drvdata(codec);
615 int ret; 611 int ret;
616 612
617 codec->control_data = dev_get_regmap(codec->dev->parent, NULL); 613 ret = snd_soc_codec_set_cache_io(codec,
618 ret = snd_soc_codec_set_cache_io(codec, 8, 24, SND_SOC_REGMAP); 614 dev_get_regmap(codec->dev->parent, NULL));
619 if (ret != 0) { 615 if (ret != 0) {
620 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 616 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
621 return ret; 617 return ret;
diff --git a/sound/soc/codecs/ml26124.c b/sound/soc/codecs/ml26124.c
index 185fa3bc3052..e661e8420e3d 100644
--- a/sound/soc/codecs/ml26124.c
+++ b/sound/soc/codecs/ml26124.c
@@ -73,11 +73,11 @@ static const DECLARE_TLV_DB_SCALE(ngth, -7650, 150, 0);
73static const char * const ml26124_companding[] = {"16bit PCM", "u-law", 73static const char * const ml26124_companding[] = {"16bit PCM", "u-law",
74 "A-law"}; 74 "A-law"};
75 75
76static const struct soc_enum ml26124_adc_companding_enum 76static SOC_ENUM_SINGLE_DECL(ml26124_adc_companding_enum,
77 = SOC_ENUM_SINGLE(ML26124_SAI_TRANS_CTL, 6, 3, ml26124_companding); 77 ML26124_SAI_TRANS_CTL, 6, ml26124_companding);
78 78
79static const struct soc_enum ml26124_dac_companding_enum 79static SOC_ENUM_SINGLE_DECL(ml26124_dac_companding_enum,
80 = SOC_ENUM_SINGLE(ML26124_SAI_RCV_CTL, 6, 3, ml26124_companding); 80 ML26124_SAI_RCV_CTL, 6, ml26124_companding);
81 81
82static const struct snd_kcontrol_new ml26124_snd_controls[] = { 82static const struct snd_kcontrol_new ml26124_snd_controls[] = {
83 SOC_SINGLE_TLV("Capture Digital Volume", ML26124_RECORD_DIG_VOL, 0, 83 SOC_SINGLE_TLV("Capture Digital Volume", ML26124_RECORD_DIG_VOL, 0,
@@ -136,8 +136,8 @@ static const struct snd_kcontrol_new ml26124_output_mixer_controls[] = {
136static const char * const ml26124_input_select[] = {"Analog MIC SingleEnded in", 136static const char * const ml26124_input_select[] = {"Analog MIC SingleEnded in",
137 "Digital MIC in", "Analog MIC Differential in"}; 137 "Digital MIC in", "Analog MIC Differential in"};
138 138
139static const struct soc_enum ml26124_insel_enum = 139static SOC_ENUM_SINGLE_DECL(ml26124_insel_enum,
140 SOC_ENUM_SINGLE(ML26124_MIC_IF_CTL, 0, 3, ml26124_input_select); 140 ML26124_MIC_IF_CTL, 0, ml26124_input_select);
141 141
142static const struct snd_kcontrol_new ml26124_input_mux_controls = 142static const struct snd_kcontrol_new ml26124_input_mux_controls =
143 SOC_DAPM_ENUM("Input Select", ml26124_insel_enum); 143 SOC_DAPM_ENUM("Input Select", ml26124_insel_enum);
@@ -586,16 +586,6 @@ static int ml26124_resume(struct snd_soc_codec *codec)
586 586
587static int ml26124_probe(struct snd_soc_codec *codec) 587static int ml26124_probe(struct snd_soc_codec *codec)
588{ 588{
589 int ret;
590 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
591 codec->control_data = priv->regmap;
592
593 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
594 if (ret < 0) {
595 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
596 return ret;
597 }
598
599 /* Software Reset */ 589 /* Software Reset */
600 snd_soc_update_bits(codec, ML26124_SW_RST, 0x01, 1); 590 snd_soc_update_bits(codec, ML26124_SW_RST, 0x01, 1);
601 snd_soc_update_bits(codec, ML26124_SW_RST, 0x01, 0); 591 snd_soc_update_bits(codec, ML26124_SW_RST, 0x01, 0);
diff --git a/sound/soc/codecs/pcm1681.c b/sound/soc/codecs/pcm1681.c
index 73f9c3630e2c..e427544183d7 100644
--- a/sound/soc/codecs/pcm1681.c
+++ b/sound/soc/codecs/pcm1681.c
@@ -172,16 +172,21 @@ static int pcm1681_hw_params(struct snd_pcm_substream *substream,
172 struct snd_soc_codec *codec = dai->codec; 172 struct snd_soc_codec *codec = dai->codec;
173 struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); 173 struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec);
174 int val = 0, ret; 174 int val = 0, ret;
175 int pcm_format = params_format(params);
176 175
177 priv->rate = params_rate(params); 176 priv->rate = params_rate(params);
178 177
179 switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) { 178 switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) {
180 case SND_SOC_DAIFMT_RIGHT_J: 179 case SND_SOC_DAIFMT_RIGHT_J:
181 if (pcm_format == SNDRV_PCM_FORMAT_S24_LE) 180 switch (params_width(params)) {
182 val = 0x00; 181 case 24:
183 else if (pcm_format == SNDRV_PCM_FORMAT_S16_LE) 182 val = 0;
184 val = 0x03; 183 break;
184 case 16:
185 val = 3;
186 break;
187 default:
188 return -EINVAL;
189 }
185 break; 190 break;
186 case SND_SOC_DAIFMT_I2S: 191 case SND_SOC_DAIFMT_I2S:
187 val = 0x04; 192 val = 0x04;
diff --git a/sound/soc/codecs/pcm1792a.c b/sound/soc/codecs/pcm1792a.c
index 7146653a8e16..3a80ba4452df 100644
--- a/sound/soc/codecs/pcm1792a.c
+++ b/sound/soc/codecs/pcm1792a.c
@@ -107,24 +107,35 @@ static int pcm1792a_hw_params(struct snd_pcm_substream *substream,
107 struct snd_soc_codec *codec = dai->codec; 107 struct snd_soc_codec *codec = dai->codec;
108 struct pcm1792a_private *priv = snd_soc_codec_get_drvdata(codec); 108 struct pcm1792a_private *priv = snd_soc_codec_get_drvdata(codec);
109 int val = 0, ret; 109 int val = 0, ret;
110 int pcm_format = params_format(params);
111 110
112 priv->rate = params_rate(params); 111 priv->rate = params_rate(params);
113 112
114 switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) { 113 switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) {
115 case SND_SOC_DAIFMT_RIGHT_J: 114 case SND_SOC_DAIFMT_RIGHT_J:
116 if (pcm_format == SNDRV_PCM_FORMAT_S24_LE || 115 switch (params_width(params)) {
117 pcm_format == SNDRV_PCM_FORMAT_S32_LE) 116 case 24:
118 val = 0x02; 117 case 32:
119 else if (pcm_format == SNDRV_PCM_FORMAT_S16_LE) 118 val = 2;
120 val = 0x00; 119 break;
120 case 16:
121 val = 0;
122 break;
123 default:
124 return -EINVAL;
125 }
121 break; 126 break;
122 case SND_SOC_DAIFMT_I2S: 127 case SND_SOC_DAIFMT_I2S:
123 if (pcm_format == SNDRV_PCM_FORMAT_S24_LE || 128 switch (params_width(params)) {
124 pcm_format == SNDRV_PCM_FORMAT_S32_LE) 129 case 24:
125 val = 0x05; 130 case 32:
126 else if (pcm_format == SNDRV_PCM_FORMAT_S16_LE) 131 val = 5;
127 val = 0x04; 132 break;
133 case 16:
134 val = 4;
135 break;
136 default:
137 return -EINVAL;
138 }
128 break; 139 break;
129 default: 140 default:
130 dev_err(codec->dev, "Invalid DAI format\n"); 141 dev_err(codec->dev, "Invalid DAI format\n");
diff --git a/sound/soc/codecs/pcm512x-i2c.c b/sound/soc/codecs/pcm512x-i2c.c
new file mode 100644
index 000000000000..4d62230bd378
--- /dev/null
+++ b/sound/soc/codecs/pcm512x-i2c.c
@@ -0,0 +1,71 @@
1/*
2 * Driver for the PCM512x CODECs
3 *
4 * Author: Mark Brown <broonie@linaro.org>
5 * Copyright 2014 Linaro Ltd
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 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 */
16
17#include <linux/init.h>
18#include <linux/module.h>
19#include <linux/i2c.h>
20
21#include "pcm512x.h"
22
23static int pcm512x_i2c_probe(struct i2c_client *i2c,
24 const struct i2c_device_id *id)
25{
26 struct regmap *regmap;
27
28 regmap = devm_regmap_init_i2c(i2c, &pcm512x_regmap);
29 if (IS_ERR(regmap))
30 return PTR_ERR(regmap);
31
32 return pcm512x_probe(&i2c->dev, regmap);
33}
34
35static int pcm512x_i2c_remove(struct i2c_client *i2c)
36{
37 pcm512x_remove(&i2c->dev);
38 return 0;
39}
40
41static const struct i2c_device_id pcm512x_i2c_id[] = {
42 { "pcm5121", },
43 { "pcm5122", },
44 { }
45};
46MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id);
47
48static const struct of_device_id pcm512x_of_match[] = {
49 { .compatible = "ti,pcm5121", },
50 { .compatible = "ti,pcm5122", },
51 { }
52};
53MODULE_DEVICE_TABLE(of, pcm512x_of_match);
54
55static struct i2c_driver pcm512x_i2c_driver = {
56 .probe = pcm512x_i2c_probe,
57 .remove = pcm512x_i2c_remove,
58 .id_table = pcm512x_i2c_id,
59 .driver = {
60 .name = "pcm512x",
61 .owner = THIS_MODULE,
62 .of_match_table = pcm512x_of_match,
63 .pm = &pcm512x_pm_ops,
64 },
65};
66
67module_i2c_driver(pcm512x_i2c_driver);
68
69MODULE_DESCRIPTION("ASoC PCM512x codec driver - I2C");
70MODULE_AUTHOR("Mark Brown <broonie@linaro.org>");
71MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/pcm512x-spi.c b/sound/soc/codecs/pcm512x-spi.c
new file mode 100644
index 000000000000..f297058c0038
--- /dev/null
+++ b/sound/soc/codecs/pcm512x-spi.c
@@ -0,0 +1,69 @@
1/*
2 * Driver for the PCM512x CODECs
3 *
4 * Author: Mark Brown <broonie@linaro.org>
5 * Copyright 2014 Linaro Ltd
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 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 */
16
17#include <linux/init.h>
18#include <linux/module.h>
19#include <linux/spi/spi.h>
20
21#include "pcm512x.h"
22
23static int pcm512x_spi_probe(struct spi_device *spi)
24{
25 struct regmap *regmap;
26 int ret;
27
28 regmap = devm_regmap_init_spi(spi, &pcm512x_regmap);
29 if (IS_ERR(regmap)) {
30 ret = PTR_ERR(regmap);
31 return ret;
32 }
33
34 return pcm512x_probe(&spi->dev, regmap);
35}
36
37static int pcm512x_spi_remove(struct spi_device *spi)
38{
39 pcm512x_remove(&spi->dev);
40 return 0;
41}
42
43static const struct spi_device_id pcm512x_spi_id[] = {
44 { "pcm5121", },
45 { "pcm5122", },
46 { },
47};
48MODULE_DEVICE_TABLE(spi, pcm512x_spi_id);
49
50static const struct of_device_id pcm512x_of_match[] = {
51 { .compatible = "ti,pcm5121", },
52 { .compatible = "ti,pcm5122", },
53 { }
54};
55MODULE_DEVICE_TABLE(of, pcm512x_of_match);
56
57static struct spi_driver pcm512x_spi_driver = {
58 .probe = pcm512x_spi_probe,
59 .remove = pcm512x_spi_remove,
60 .id_table = pcm512x_spi_id,
61 .driver = {
62 .name = "pcm512x",
63 .owner = THIS_MODULE,
64 .of_match_table = pcm512x_of_match,
65 .pm = &pcm512x_pm_ops,
66 },
67};
68
69module_spi_driver(pcm512x_spi_driver);
diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c
new file mode 100644
index 000000000000..4b4c0c7bb918
--- /dev/null
+++ b/sound/soc/codecs/pcm512x.c
@@ -0,0 +1,589 @@
1/*
2 * Driver for the PCM512x CODECs
3 *
4 * Author: Mark Brown <broonie@linaro.org>
5 * Copyright 2014 Linaro Ltd
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 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 */
16
17
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/clk.h>
21#include <linux/pm_runtime.h>
22#include <linux/regmap.h>
23#include <linux/regulator/consumer.h>
24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26#include <sound/tlv.h>
27
28#include "pcm512x.h"
29
30#define PCM512x_NUM_SUPPLIES 3
31static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
32 "AVDD",
33 "DVDD",
34 "CPVDD",
35};
36
37struct pcm512x_priv {
38 struct regmap *regmap;
39 struct clk *sclk;
40 struct regulator_bulk_data supplies[PCM512x_NUM_SUPPLIES];
41 struct notifier_block supply_nb[PCM512x_NUM_SUPPLIES];
42};
43
44/*
45 * We can't use the same notifier block for more than one supply and
46 * there's no way I can see to get from a callback to the caller
47 * except container_of().
48 */
49#define PCM512x_REGULATOR_EVENT(n) \
50static int pcm512x_regulator_event_##n(struct notifier_block *nb, \
51 unsigned long event, void *data) \
52{ \
53 struct pcm512x_priv *pcm512x = container_of(nb, struct pcm512x_priv, \
54 supply_nb[n]); \
55 if (event & REGULATOR_EVENT_DISABLE) { \
56 regcache_mark_dirty(pcm512x->regmap); \
57 regcache_cache_only(pcm512x->regmap, true); \
58 } \
59 return 0; \
60}
61
62PCM512x_REGULATOR_EVENT(0)
63PCM512x_REGULATOR_EVENT(1)
64PCM512x_REGULATOR_EVENT(2)
65
66static const struct reg_default pcm512x_reg_defaults[] = {
67 { PCM512x_RESET, 0x00 },
68 { PCM512x_POWER, 0x00 },
69 { PCM512x_MUTE, 0x00 },
70 { PCM512x_DSP, 0x00 },
71 { PCM512x_PLL_REF, 0x00 },
72 { PCM512x_DAC_ROUTING, 0x11 },
73 { PCM512x_DSP_PROGRAM, 0x01 },
74 { PCM512x_CLKDET, 0x00 },
75 { PCM512x_AUTO_MUTE, 0x00 },
76 { PCM512x_ERROR_DETECT, 0x00 },
77 { PCM512x_DIGITAL_VOLUME_1, 0x00 },
78 { PCM512x_DIGITAL_VOLUME_2, 0x30 },
79 { PCM512x_DIGITAL_VOLUME_3, 0x30 },
80 { PCM512x_DIGITAL_MUTE_1, 0x22 },
81 { PCM512x_DIGITAL_MUTE_2, 0x00 },
82 { PCM512x_DIGITAL_MUTE_3, 0x07 },
83 { PCM512x_OUTPUT_AMPLITUDE, 0x00 },
84 { PCM512x_ANALOG_GAIN_CTRL, 0x00 },
85 { PCM512x_UNDERVOLTAGE_PROT, 0x00 },
86 { PCM512x_ANALOG_MUTE_CTRL, 0x00 },
87 { PCM512x_ANALOG_GAIN_BOOST, 0x00 },
88 { PCM512x_VCOM_CTRL_1, 0x00 },
89 { PCM512x_VCOM_CTRL_2, 0x01 },
90};
91
92static bool pcm512x_readable(struct device *dev, unsigned int reg)
93{
94 switch (reg) {
95 case PCM512x_RESET:
96 case PCM512x_POWER:
97 case PCM512x_MUTE:
98 case PCM512x_PLL_EN:
99 case PCM512x_SPI_MISO_FUNCTION:
100 case PCM512x_DSP:
101 case PCM512x_GPIO_EN:
102 case PCM512x_BCLK_LRCLK_CFG:
103 case PCM512x_DSP_GPIO_INPUT:
104 case PCM512x_MASTER_MODE:
105 case PCM512x_PLL_REF:
106 case PCM512x_PLL_COEFF_0:
107 case PCM512x_PLL_COEFF_1:
108 case PCM512x_PLL_COEFF_2:
109 case PCM512x_PLL_COEFF_3:
110 case PCM512x_PLL_COEFF_4:
111 case PCM512x_DSP_CLKDIV:
112 case PCM512x_DAC_CLKDIV:
113 case PCM512x_NCP_CLKDIV:
114 case PCM512x_OSR_CLKDIV:
115 case PCM512x_MASTER_CLKDIV_1:
116 case PCM512x_MASTER_CLKDIV_2:
117 case PCM512x_FS_SPEED_MODE:
118 case PCM512x_IDAC_1:
119 case PCM512x_IDAC_2:
120 case PCM512x_ERROR_DETECT:
121 case PCM512x_I2S_1:
122 case PCM512x_I2S_2:
123 case PCM512x_DAC_ROUTING:
124 case PCM512x_DSP_PROGRAM:
125 case PCM512x_CLKDET:
126 case PCM512x_AUTO_MUTE:
127 case PCM512x_DIGITAL_VOLUME_1:
128 case PCM512x_DIGITAL_VOLUME_2:
129 case PCM512x_DIGITAL_VOLUME_3:
130 case PCM512x_DIGITAL_MUTE_1:
131 case PCM512x_DIGITAL_MUTE_2:
132 case PCM512x_DIGITAL_MUTE_3:
133 case PCM512x_GPIO_OUTPUT_1:
134 case PCM512x_GPIO_OUTPUT_2:
135 case PCM512x_GPIO_OUTPUT_3:
136 case PCM512x_GPIO_OUTPUT_4:
137 case PCM512x_GPIO_OUTPUT_5:
138 case PCM512x_GPIO_OUTPUT_6:
139 case PCM512x_GPIO_CONTROL_1:
140 case PCM512x_GPIO_CONTROL_2:
141 case PCM512x_OVERFLOW:
142 case PCM512x_RATE_DET_1:
143 case PCM512x_RATE_DET_2:
144 case PCM512x_RATE_DET_3:
145 case PCM512x_RATE_DET_4:
146 case PCM512x_ANALOG_MUTE_DET:
147 case PCM512x_GPIN:
148 case PCM512x_DIGITAL_MUTE_DET:
149 case PCM512x_OUTPUT_AMPLITUDE:
150 case PCM512x_ANALOG_GAIN_CTRL:
151 case PCM512x_UNDERVOLTAGE_PROT:
152 case PCM512x_ANALOG_MUTE_CTRL:
153 case PCM512x_ANALOG_GAIN_BOOST:
154 case PCM512x_VCOM_CTRL_1:
155 case PCM512x_VCOM_CTRL_2:
156 case PCM512x_CRAM_CTRL:
157 return true;
158 default:
159 /* There are 256 raw register addresses */
160 return reg < 0xff;
161 }
162}
163
164static bool pcm512x_volatile(struct device *dev, unsigned int reg)
165{
166 switch (reg) {
167 case PCM512x_PLL_EN:
168 case PCM512x_OVERFLOW:
169 case PCM512x_RATE_DET_1:
170 case PCM512x_RATE_DET_2:
171 case PCM512x_RATE_DET_3:
172 case PCM512x_RATE_DET_4:
173 case PCM512x_ANALOG_MUTE_DET:
174 case PCM512x_GPIN:
175 case PCM512x_DIGITAL_MUTE_DET:
176 case PCM512x_CRAM_CTRL:
177 return true;
178 default:
179 /* There are 256 raw register addresses */
180 return reg < 0xff;
181 }
182}
183
184static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1);
185static const DECLARE_TLV_DB_SCALE(analog_tlv, -600, 600, 0);
186static const DECLARE_TLV_DB_SCALE(boost_tlv, 0, 80, 0);
187
188static const char * const pcm512x_dsp_program_texts[] = {
189 "FIR interpolation with de-emphasis",
190 "Low latency IIR with de-emphasis",
191 "Fixed process flow",
192 "High attenuation with de-emphasis",
193 "Ringing-less low latency FIR",
194};
195
196static const unsigned int pcm512x_dsp_program_values[] = {
197 1,
198 2,
199 3,
200 5,
201 7,
202};
203
204static SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program,
205 PCM512x_DSP_PROGRAM, 0, 0x1f,
206 pcm512x_dsp_program_texts,
207 pcm512x_dsp_program_values);
208
209static const char * const pcm512x_clk_missing_text[] = {
210 "1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s"
211};
212
213static const struct soc_enum pcm512x_clk_missing =
214 SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 8, pcm512x_clk_missing_text);
215
216static const char * const pcm512x_autom_text[] = {
217 "21ms", "106ms", "213ms", "533ms", "1.07s", "2.13s", "5.33s", "10.66s"
218};
219
220static const struct soc_enum pcm512x_autom_l =
221 SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 8,
222 pcm512x_autom_text);
223
224static const struct soc_enum pcm512x_autom_r =
225 SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 8,
226 pcm512x_autom_text);
227
228static const char * const pcm512x_ramp_rate_text[] = {
229 "1 sample/update", "2 samples/update", "4 samples/update",
230 "Immediate"
231};
232
233static const struct soc_enum pcm512x_vndf =
234 SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNDF_SHIFT, 4,
235 pcm512x_ramp_rate_text);
236
237static const struct soc_enum pcm512x_vnuf =
238 SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNUF_SHIFT, 4,
239 pcm512x_ramp_rate_text);
240
241static const struct soc_enum pcm512x_vedf =
242 SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDF_SHIFT, 4,
243 pcm512x_ramp_rate_text);
244
245static const char * const pcm512x_ramp_step_text[] = {
246 "4dB/step", "2dB/step", "1dB/step", "0.5dB/step"
247};
248
249static const struct soc_enum pcm512x_vnds =
250 SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNDS_SHIFT, 4,
251 pcm512x_ramp_step_text);
252
253static const struct soc_enum pcm512x_vnus =
254 SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNUS_SHIFT, 4,
255 pcm512x_ramp_step_text);
256
257static const struct soc_enum pcm512x_veds =
258 SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDS_SHIFT, 4,
259 pcm512x_ramp_step_text);
260
261static const struct snd_kcontrol_new pcm512x_controls[] = {
262SOC_DOUBLE_R_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2,
263 PCM512x_DIGITAL_VOLUME_3, 0, 255, 1, digital_tlv),
264SOC_DOUBLE_TLV("Playback Volume", PCM512x_ANALOG_GAIN_CTRL,
265 PCM512x_LAGN_SHIFT, PCM512x_RAGN_SHIFT, 1, 1, analog_tlv),
266SOC_DOUBLE_TLV("Playback Boost Volume", PCM512x_ANALOG_GAIN_BOOST,
267 PCM512x_AGBL_SHIFT, PCM512x_AGBR_SHIFT, 1, 0, boost_tlv),
268SOC_DOUBLE("Playback Digital Switch", PCM512x_MUTE, PCM512x_RQML_SHIFT,
269 PCM512x_RQMR_SHIFT, 1, 1),
270
271SOC_SINGLE("Deemphasis Switch", PCM512x_DSP, PCM512x_DEMP_SHIFT, 1, 1),
272SOC_VALUE_ENUM("DSP Program", pcm512x_dsp_program),
273
274SOC_ENUM("Clock Missing Period", pcm512x_clk_missing),
275SOC_ENUM("Auto Mute Time Left", pcm512x_autom_l),
276SOC_ENUM("Auto Mute Time Right", pcm512x_autom_r),
277SOC_SINGLE("Auto Mute Mono Switch", PCM512x_DIGITAL_MUTE_3,
278 PCM512x_ACTL_SHIFT, 1, 0),
279SOC_DOUBLE("Auto Mute Switch", PCM512x_DIGITAL_MUTE_3, PCM512x_AMLE_SHIFT,
280 PCM512x_AMLR_SHIFT, 1, 0),
281
282SOC_ENUM("Volume Ramp Down Rate", pcm512x_vndf),
283SOC_ENUM("Volume Ramp Down Step", pcm512x_vnds),
284SOC_ENUM("Volume Ramp Up Rate", pcm512x_vnuf),
285SOC_ENUM("Volume Ramp Up Step", pcm512x_vnus),
286SOC_ENUM("Volume Ramp Down Emergency Rate", pcm512x_vedf),
287SOC_ENUM("Volume Ramp Down Emergency Step", pcm512x_veds),
288};
289
290static const struct snd_soc_dapm_widget pcm512x_dapm_widgets[] = {
291SND_SOC_DAPM_DAC("DACL", NULL, SND_SOC_NOPM, 0, 0),
292SND_SOC_DAPM_DAC("DACR", NULL, SND_SOC_NOPM, 0, 0),
293
294SND_SOC_DAPM_OUTPUT("OUTL"),
295SND_SOC_DAPM_OUTPUT("OUTR"),
296};
297
298static const struct snd_soc_dapm_route pcm512x_dapm_routes[] = {
299 { "DACL", NULL, "Playback" },
300 { "DACR", NULL, "Playback" },
301
302 { "OUTL", NULL, "DACL" },
303 { "OUTR", NULL, "DACR" },
304};
305
306static int pcm512x_set_bias_level(struct snd_soc_codec *codec,
307 enum snd_soc_bias_level level)
308{
309 struct pcm512x_priv *pcm512x = dev_get_drvdata(codec->dev);
310 int ret;
311
312 switch (level) {
313 case SND_SOC_BIAS_ON:
314 case SND_SOC_BIAS_PREPARE:
315 break;
316
317 case SND_SOC_BIAS_STANDBY:
318 ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
319 PCM512x_RQST, 0);
320 if (ret != 0) {
321 dev_err(codec->dev, "Failed to remove standby: %d\n",
322 ret);
323 return ret;
324 }
325 break;
326
327 case SND_SOC_BIAS_OFF:
328 ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
329 PCM512x_RQST, PCM512x_RQST);
330 if (ret != 0) {
331 dev_err(codec->dev, "Failed to request standby: %d\n",
332 ret);
333 return ret;
334 }
335 break;
336 }
337
338 codec->dapm.bias_level = level;
339
340 return 0;
341}
342
343static struct snd_soc_dai_driver pcm512x_dai = {
344 .name = "pcm512x-hifi",
345 .playback = {
346 .stream_name = "Playback",
347 .channels_min = 2,
348 .channels_max = 2,
349 .rates = SNDRV_PCM_RATE_8000_192000,
350 .formats = SNDRV_PCM_FMTBIT_S16_LE |
351 SNDRV_PCM_FMTBIT_S24_LE |
352 SNDRV_PCM_FMTBIT_S32_LE
353 },
354};
355
356static struct snd_soc_codec_driver pcm512x_codec_driver = {
357 .set_bias_level = pcm512x_set_bias_level,
358 .idle_bias_off = true,
359
360 .controls = pcm512x_controls,
361 .num_controls = ARRAY_SIZE(pcm512x_controls),
362 .dapm_widgets = pcm512x_dapm_widgets,
363 .num_dapm_widgets = ARRAY_SIZE(pcm512x_dapm_widgets),
364 .dapm_routes = pcm512x_dapm_routes,
365 .num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes),
366};
367
368static const struct regmap_range_cfg pcm512x_range = {
369 .name = "Pages", .range_min = PCM512x_VIRT_BASE,
370 .range_max = PCM512x_MAX_REGISTER,
371 .selector_reg = PCM512x_PAGE,
372 .selector_mask = 0xff,
373 .window_start = 0, .window_len = 0x100,
374};
375
376const struct regmap_config pcm512x_regmap = {
377 .reg_bits = 8,
378 .val_bits = 8,
379
380 .readable_reg = pcm512x_readable,
381 .volatile_reg = pcm512x_volatile,
382
383 .ranges = &pcm512x_range,
384 .num_ranges = 1,
385
386 .max_register = PCM512x_MAX_REGISTER,
387 .reg_defaults = pcm512x_reg_defaults,
388 .num_reg_defaults = ARRAY_SIZE(pcm512x_reg_defaults),
389 .cache_type = REGCACHE_RBTREE,
390};
391EXPORT_SYMBOL_GPL(pcm512x_regmap);
392
393int pcm512x_probe(struct device *dev, struct regmap *regmap)
394{
395 struct pcm512x_priv *pcm512x;
396 int i, ret;
397
398 pcm512x = devm_kzalloc(dev, sizeof(struct pcm512x_priv), GFP_KERNEL);
399 if (!pcm512x)
400 return -ENOMEM;
401
402 dev_set_drvdata(dev, pcm512x);
403 pcm512x->regmap = regmap;
404
405 for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++)
406 pcm512x->supplies[i].supply = pcm512x_supply_names[i];
407
408 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pcm512x->supplies),
409 pcm512x->supplies);
410 if (ret != 0) {
411 dev_err(dev, "Failed to get supplies: %d\n", ret);
412 return ret;
413 }
414
415 pcm512x->supply_nb[0].notifier_call = pcm512x_regulator_event_0;
416 pcm512x->supply_nb[1].notifier_call = pcm512x_regulator_event_1;
417 pcm512x->supply_nb[2].notifier_call = pcm512x_regulator_event_2;
418
419 for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++) {
420 ret = regulator_register_notifier(pcm512x->supplies[i].consumer,
421 &pcm512x->supply_nb[i]);
422 if (ret != 0) {
423 dev_err(dev,
424 "Failed to register regulator notifier: %d\n",
425 ret);
426 }
427 }
428
429 ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies),
430 pcm512x->supplies);
431 if (ret != 0) {
432 dev_err(dev, "Failed to enable supplies: %d\n", ret);
433 return ret;
434 }
435
436 /* Reset the device, verifying I/O in the process for I2C */
437 ret = regmap_write(regmap, PCM512x_RESET,
438 PCM512x_RSTM | PCM512x_RSTR);
439 if (ret != 0) {
440 dev_err(dev, "Failed to reset device: %d\n", ret);
441 goto err;
442 }
443
444 ret = regmap_write(regmap, PCM512x_RESET, 0);
445 if (ret != 0) {
446 dev_err(dev, "Failed to reset device: %d\n", ret);
447 goto err;
448 }
449
450 pcm512x->sclk = devm_clk_get(dev, NULL);
451 if (IS_ERR(pcm512x->sclk)) {
452 if (PTR_ERR(pcm512x->sclk) == -EPROBE_DEFER)
453 return -EPROBE_DEFER;
454
455 dev_info(dev, "No SCLK, using BCLK: %ld\n",
456 PTR_ERR(pcm512x->sclk));
457
458 /* Disable reporting of missing SCLK as an error */
459 regmap_update_bits(regmap, PCM512x_ERROR_DETECT,
460 PCM512x_IDCH, PCM512x_IDCH);
461
462 /* Switch PLL input to BCLK */
463 regmap_update_bits(regmap, PCM512x_PLL_REF,
464 PCM512x_SREF, PCM512x_SREF);
465 } else {
466 ret = clk_prepare_enable(pcm512x->sclk);
467 if (ret != 0) {
468 dev_err(dev, "Failed to enable SCLK: %d\n", ret);
469 return ret;
470 }
471 }
472
473 /* Default to standby mode */
474 ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
475 PCM512x_RQST, PCM512x_RQST);
476 if (ret != 0) {
477 dev_err(dev, "Failed to request standby: %d\n",
478 ret);
479 goto err_clk;
480 }
481
482 pm_runtime_set_active(dev);
483 pm_runtime_enable(dev);
484 pm_runtime_idle(dev);
485
486 ret = snd_soc_register_codec(dev, &pcm512x_codec_driver,
487 &pcm512x_dai, 1);
488 if (ret != 0) {
489 dev_err(dev, "Failed to register CODEC: %d\n", ret);
490 goto err_pm;
491 }
492
493 return 0;
494
495err_pm:
496 pm_runtime_disable(dev);
497err_clk:
498 if (!IS_ERR(pcm512x->sclk))
499 clk_disable_unprepare(pcm512x->sclk);
500err:
501 regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
502 pcm512x->supplies);
503 return ret;
504}
505EXPORT_SYMBOL_GPL(pcm512x_probe);
506
507void pcm512x_remove(struct device *dev)
508{
509 struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
510
511 snd_soc_unregister_codec(dev);
512 pm_runtime_disable(dev);
513 if (!IS_ERR(pcm512x->sclk))
514 clk_disable_unprepare(pcm512x->sclk);
515 regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
516 pcm512x->supplies);
517}
518EXPORT_SYMBOL_GPL(pcm512x_remove);
519
520static int pcm512x_suspend(struct device *dev)
521{
522 struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
523 int ret;
524
525 ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
526 PCM512x_RQPD, PCM512x_RQPD);
527 if (ret != 0) {
528 dev_err(dev, "Failed to request power down: %d\n", ret);
529 return ret;
530 }
531
532 ret = regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
533 pcm512x->supplies);
534 if (ret != 0) {
535 dev_err(dev, "Failed to disable supplies: %d\n", ret);
536 return ret;
537 }
538
539 if (!IS_ERR(pcm512x->sclk))
540 clk_disable_unprepare(pcm512x->sclk);
541
542 return 0;
543}
544
545static int pcm512x_resume(struct device *dev)
546{
547 struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
548 int ret;
549
550 if (!IS_ERR(pcm512x->sclk)) {
551 ret = clk_prepare_enable(pcm512x->sclk);
552 if (ret != 0) {
553 dev_err(dev, "Failed to enable SCLK: %d\n", ret);
554 return ret;
555 }
556 }
557
558 ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies),
559 pcm512x->supplies);
560 if (ret != 0) {
561 dev_err(dev, "Failed to enable supplies: %d\n", ret);
562 return ret;
563 }
564
565 regcache_cache_only(pcm512x->regmap, false);
566 ret = regcache_sync(pcm512x->regmap);
567 if (ret != 0) {
568 dev_err(dev, "Failed to sync cache: %d\n", ret);
569 return ret;
570 }
571
572 ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
573 PCM512x_RQPD, 0);
574 if (ret != 0) {
575 dev_err(dev, "Failed to remove power down: %d\n", ret);
576 return ret;
577 }
578
579 return 0;
580}
581
582const struct dev_pm_ops pcm512x_pm_ops = {
583 SET_RUNTIME_PM_OPS(pcm512x_suspend, pcm512x_resume, NULL)
584};
585EXPORT_SYMBOL_GPL(pcm512x_pm_ops);
586
587MODULE_DESCRIPTION("ASoC PCM512x codec driver");
588MODULE_AUTHOR("Mark Brown <broonie@linaro.org>");
589MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/pcm512x.h b/sound/soc/codecs/pcm512x.h
new file mode 100644
index 000000000000..6ee76aaca09a
--- /dev/null
+++ b/sound/soc/codecs/pcm512x.h
@@ -0,0 +1,171 @@
1/*
2 * Driver for the PCM512x CODECs
3 *
4 * Author: Mark Brown <broonie@linaro.org>
5 * Copyright 2014 Linaro Ltd
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 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 */
16
17#ifndef _SND_SOC_PCM512X
18#define _SND_SOC_PCM512X
19
20#include <linux/pm.h>
21#include <linux/regmap.h>
22
23#define PCM512x_VIRT_BASE 0x100
24#define PCM512x_PAGE_LEN 0x100
25#define PCM512x_PAGE_BASE(n) (PCM512x_VIRT_BASE + (PCM512x_PAGE_LEN * n))
26
27#define PCM512x_PAGE 0
28
29#define PCM512x_RESET (PCM512x_PAGE_BASE(0) + 1)
30#define PCM512x_POWER (PCM512x_PAGE_BASE(0) + 2)
31#define PCM512x_MUTE (PCM512x_PAGE_BASE(0) + 3)
32#define PCM512x_PLL_EN (PCM512x_PAGE_BASE(0) + 4)
33#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_BASE(0) + 6)
34#define PCM512x_DSP (PCM512x_PAGE_BASE(0) + 7)
35#define PCM512x_GPIO_EN (PCM512x_PAGE_BASE(0) + 8)
36#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_BASE(0) + 9)
37#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_BASE(0) + 10)
38#define PCM512x_MASTER_MODE (PCM512x_PAGE_BASE(0) + 12)
39#define PCM512x_PLL_REF (PCM512x_PAGE_BASE(0) + 13)
40#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_BASE(0) + 20)
41#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_BASE(0) + 21)
42#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_BASE(0) + 22)
43#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_BASE(0) + 23)
44#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_BASE(0) + 24)
45#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_BASE(0) + 27)
46#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_BASE(0) + 28)
47#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_BASE(0) + 29)
48#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_BASE(0) + 30)
49#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_BASE(0) + 32)
50#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_BASE(0) + 33)
51#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_BASE(0) + 34)
52#define PCM512x_IDAC_1 (PCM512x_PAGE_BASE(0) + 35)
53#define PCM512x_IDAC_2 (PCM512x_PAGE_BASE(0) + 36)
54#define PCM512x_ERROR_DETECT (PCM512x_PAGE_BASE(0) + 37)
55#define PCM512x_I2S_1 (PCM512x_PAGE_BASE(0) + 40)
56#define PCM512x_I2S_2 (PCM512x_PAGE_BASE(0) + 41)
57#define PCM512x_DAC_ROUTING (PCM512x_PAGE_BASE(0) + 42)
58#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_BASE(0) + 43)
59#define PCM512x_CLKDET (PCM512x_PAGE_BASE(0) + 44)
60#define PCM512x_AUTO_MUTE (PCM512x_PAGE_BASE(0) + 59)
61#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_BASE(0) + 60)
62#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_BASE(0) + 61)
63#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_BASE(0) + 62)
64#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_BASE(0) + 63)
65#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_BASE(0) + 64)
66#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_BASE(0) + 65)
67#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_BASE(0) + 80)
68#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_BASE(0) + 81)
69#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_BASE(0) + 82)
70#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_BASE(0) + 83)
71#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_BASE(0) + 84)
72#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_BASE(0) + 85)
73#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_BASE(0) + 86)
74#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_BASE(0) + 87)
75#define PCM512x_OVERFLOW (PCM512x_PAGE_BASE(0) + 90)
76#define PCM512x_RATE_DET_1 (PCM512x_PAGE_BASE(0) + 91)
77#define PCM512x_RATE_DET_2 (PCM512x_PAGE_BASE(0) + 92)
78#define PCM512x_RATE_DET_3 (PCM512x_PAGE_BASE(0) + 93)
79#define PCM512x_RATE_DET_4 (PCM512x_PAGE_BASE(0) + 94)
80#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_BASE(0) + 108)
81#define PCM512x_GPIN (PCM512x_PAGE_BASE(0) + 119)
82#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_BASE(0) + 120)
83
84#define PCM512x_OUTPUT_AMPLITUDE (PCM512x_PAGE_BASE(1) + 1)
85#define PCM512x_ANALOG_GAIN_CTRL (PCM512x_PAGE_BASE(1) + 2)
86#define PCM512x_UNDERVOLTAGE_PROT (PCM512x_PAGE_BASE(1) + 5)
87#define PCM512x_ANALOG_MUTE_CTRL (PCM512x_PAGE_BASE(1) + 6)
88#define PCM512x_ANALOG_GAIN_BOOST (PCM512x_PAGE_BASE(1) + 7)
89#define PCM512x_VCOM_CTRL_1 (PCM512x_PAGE_BASE(1) + 8)
90#define PCM512x_VCOM_CTRL_2 (PCM512x_PAGE_BASE(1) + 9)
91
92#define PCM512x_CRAM_CTRL (PCM512x_PAGE_BASE(44) + 1)
93
94#define PCM512x_MAX_REGISTER (PCM512x_PAGE_BASE(44) + 1)
95
96/* Page 0, Register 1 - reset */
97#define PCM512x_RSTR (1 << 0)
98#define PCM512x_RSTM (1 << 4)
99
100/* Page 0, Register 2 - power */
101#define PCM512x_RQPD (1 << 0)
102#define PCM512x_RQPD_SHIFT 0
103#define PCM512x_RQST (1 << 4)
104#define PCM512x_RQST_SHIFT 4
105
106/* Page 0, Register 3 - mute */
107#define PCM512x_RQMR_SHIFT 0
108#define PCM512x_RQML_SHIFT 4
109
110/* Page 0, Register 4 - PLL */
111#define PCM512x_PLCE (1 << 0)
112#define PCM512x_RLCE_SHIFT 0
113#define PCM512x_PLCK (1 << 4)
114#define PCM512x_PLCK_SHIFT 4
115
116/* Page 0, Register 7 - DSP */
117#define PCM512x_SDSL (1 << 0)
118#define PCM512x_SDSL_SHIFT 0
119#define PCM512x_DEMP (1 << 4)
120#define PCM512x_DEMP_SHIFT 4
121
122/* Page 0, Register 13 - PLL reference */
123#define PCM512x_SREF (1 << 4)
124
125/* Page 0, Register 37 - Error detection */
126#define PCM512x_IPLK (1 << 0)
127#define PCM512x_DCAS (1 << 1)
128#define PCM512x_IDCM (1 << 2)
129#define PCM512x_IDCH (1 << 3)
130#define PCM512x_IDSK (1 << 4)
131#define PCM512x_IDBK (1 << 5)
132#define PCM512x_IDFS (1 << 6)
133
134/* Page 0, Register 42 - DAC routing */
135#define PCM512x_AUPR_SHIFT 0
136#define PCM512x_AUPL_SHIFT 4
137
138/* Page 0, Register 59 - auto mute */
139#define PCM512x_ATMR_SHIFT 0
140#define PCM512x_ATML_SHIFT 4
141
142/* Page 0, Register 63 - ramp rates */
143#define PCM512x_VNDF_SHIFT 6
144#define PCM512x_VNDS_SHIFT 4
145#define PCM512x_VNUF_SHIFT 2
146#define PCM512x_VNUS_SHIFT 0
147
148/* Page 0, Register 64 - emergency ramp rates */
149#define PCM512x_VEDF_SHIFT 6
150#define PCM512x_VEDS_SHIFT 4
151
152/* Page 0, Register 65 - Digital mute enables */
153#define PCM512x_ACTL_SHIFT 2
154#define PCM512x_AMLE_SHIFT 1
155#define PCM512x_AMLR_SHIFT 0
156
157/* Page 1, Register 2 - analog volume control */
158#define PCM512x_RAGN_SHIFT 0
159#define PCM512x_LAGN_SHIFT 4
160
161/* Page 1, Register 7 - analog boost control */
162#define PCM512x_AGBR_SHIFT 0
163#define PCM512x_AGBL_SHIFT 4
164
165extern const struct dev_pm_ops pcm512x_pm_ops;
166extern const struct regmap_config pcm512x_regmap;
167
168int pcm512x_probe(struct device *dev, struct regmap *regmap);
169void pcm512x_remove(struct device *dev);
170
171#endif
diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c
index 912c9cbc2724..d4c229f0233f 100644
--- a/sound/soc/codecs/rt5631.c
+++ b/sound/soc/codecs/rt5631.c
@@ -210,26 +210,22 @@ static int rt5631_dmic_put(struct snd_kcontrol *kcontrol,
210static const char *rt5631_input_mode[] = { 210static const char *rt5631_input_mode[] = {
211 "Single ended", "Differential"}; 211 "Single ended", "Differential"};
212 212
213static const SOC_ENUM_SINGLE_DECL( 213static SOC_ENUM_SINGLE_DECL(rt5631_mic1_mode_enum, RT5631_MIC_CTRL_1,
214 rt5631_mic1_mode_enum, RT5631_MIC_CTRL_1, 214 RT5631_MIC1_DIFF_INPUT_SHIFT, rt5631_input_mode);
215 RT5631_MIC1_DIFF_INPUT_SHIFT, rt5631_input_mode);
216 215
217static const SOC_ENUM_SINGLE_DECL( 216static SOC_ENUM_SINGLE_DECL(rt5631_mic2_mode_enum, RT5631_MIC_CTRL_1,
218 rt5631_mic2_mode_enum, RT5631_MIC_CTRL_1, 217 RT5631_MIC2_DIFF_INPUT_SHIFT, rt5631_input_mode);
219 RT5631_MIC2_DIFF_INPUT_SHIFT, rt5631_input_mode);
220 218
221/* MONO Input Type */ 219/* MONO Input Type */
222static const SOC_ENUM_SINGLE_DECL( 220static SOC_ENUM_SINGLE_DECL(rt5631_monoin_mode_enum, RT5631_MONO_INPUT_VOL,
223 rt5631_monoin_mode_enum, RT5631_MONO_INPUT_VOL, 221 RT5631_MONO_DIFF_INPUT_SHIFT, rt5631_input_mode);
224 RT5631_MONO_DIFF_INPUT_SHIFT, rt5631_input_mode);
225 222
226/* SPK Ratio Gain Control */ 223/* SPK Ratio Gain Control */
227static const char *rt5631_spk_ratio[] = {"1.00x", "1.09x", "1.27x", "1.44x", 224static const char *rt5631_spk_ratio[] = {"1.00x", "1.09x", "1.27x", "1.44x",
228 "1.56x", "1.68x", "1.99x", "2.34x"}; 225 "1.56x", "1.68x", "1.99x", "2.34x"};
229 226
230static const SOC_ENUM_SINGLE_DECL( 227static SOC_ENUM_SINGLE_DECL(rt5631_spk_ratio_enum, RT5631_GEN_PUR_CTRL_REG,
231 rt5631_spk_ratio_enum, RT5631_GEN_PUR_CTRL_REG, 228 RT5631_SPK_AMP_RATIO_CTRL_SHIFT, rt5631_spk_ratio);
232 RT5631_SPK_AMP_RATIO_CTRL_SHIFT, rt5631_spk_ratio);
233 229
234static const struct snd_kcontrol_new rt5631_snd_controls[] = { 230static const struct snd_kcontrol_new rt5631_snd_controls[] = {
235 /* MIC */ 231 /* MIC */
@@ -759,9 +755,8 @@ static const struct snd_kcontrol_new rt5631_monomix_mixer_controls[] = {
759/* Left SPK Volume Input */ 755/* Left SPK Volume Input */
760static const char *rt5631_spkvoll_sel[] = {"Vmid", "SPKMIXL"}; 756static const char *rt5631_spkvoll_sel[] = {"Vmid", "SPKMIXL"};
761 757
762static const SOC_ENUM_SINGLE_DECL( 758static SOC_ENUM_SINGLE_DECL(rt5631_spkvoll_enum, RT5631_SPK_OUT_VOL,
763 rt5631_spkvoll_enum, RT5631_SPK_OUT_VOL, 759 RT5631_L_EN_SHIFT, rt5631_spkvoll_sel);
764 RT5631_L_EN_SHIFT, rt5631_spkvoll_sel);
765 760
766static const struct snd_kcontrol_new rt5631_spkvoll_mux_control = 761static const struct snd_kcontrol_new rt5631_spkvoll_mux_control =
767 SOC_DAPM_ENUM("Left SPKVOL SRC", rt5631_spkvoll_enum); 762 SOC_DAPM_ENUM("Left SPKVOL SRC", rt5631_spkvoll_enum);
@@ -769,9 +764,8 @@ static const struct snd_kcontrol_new rt5631_spkvoll_mux_control =
769/* Left HP Volume Input */ 764/* Left HP Volume Input */
770static const char *rt5631_hpvoll_sel[] = {"Vmid", "OUTMIXL"}; 765static const char *rt5631_hpvoll_sel[] = {"Vmid", "OUTMIXL"};
771 766
772static const SOC_ENUM_SINGLE_DECL( 767static SOC_ENUM_SINGLE_DECL(rt5631_hpvoll_enum, RT5631_HP_OUT_VOL,
773 rt5631_hpvoll_enum, RT5631_HP_OUT_VOL, 768 RT5631_L_EN_SHIFT, rt5631_hpvoll_sel);
774 RT5631_L_EN_SHIFT, rt5631_hpvoll_sel);
775 769
776static const struct snd_kcontrol_new rt5631_hpvoll_mux_control = 770static const struct snd_kcontrol_new rt5631_hpvoll_mux_control =
777 SOC_DAPM_ENUM("Left HPVOL SRC", rt5631_hpvoll_enum); 771 SOC_DAPM_ENUM("Left HPVOL SRC", rt5631_hpvoll_enum);
@@ -779,9 +773,8 @@ static const struct snd_kcontrol_new rt5631_hpvoll_mux_control =
779/* Left Out Volume Input */ 773/* Left Out Volume Input */
780static const char *rt5631_outvoll_sel[] = {"Vmid", "OUTMIXL"}; 774static const char *rt5631_outvoll_sel[] = {"Vmid", "OUTMIXL"};
781 775
782static const SOC_ENUM_SINGLE_DECL( 776static SOC_ENUM_SINGLE_DECL(rt5631_outvoll_enum, RT5631_MONO_AXO_1_2_VOL,
783 rt5631_outvoll_enum, RT5631_MONO_AXO_1_2_VOL, 777 RT5631_L_EN_SHIFT, rt5631_outvoll_sel);
784 RT5631_L_EN_SHIFT, rt5631_outvoll_sel);
785 778
786static const struct snd_kcontrol_new rt5631_outvoll_mux_control = 779static const struct snd_kcontrol_new rt5631_outvoll_mux_control =
787 SOC_DAPM_ENUM("Left OUTVOL SRC", rt5631_outvoll_enum); 780 SOC_DAPM_ENUM("Left OUTVOL SRC", rt5631_outvoll_enum);
@@ -789,9 +782,8 @@ static const struct snd_kcontrol_new rt5631_outvoll_mux_control =
789/* Right Out Volume Input */ 782/* Right Out Volume Input */
790static const char *rt5631_outvolr_sel[] = {"Vmid", "OUTMIXR"}; 783static const char *rt5631_outvolr_sel[] = {"Vmid", "OUTMIXR"};
791 784
792static const SOC_ENUM_SINGLE_DECL( 785static SOC_ENUM_SINGLE_DECL(rt5631_outvolr_enum, RT5631_MONO_AXO_1_2_VOL,
793 rt5631_outvolr_enum, RT5631_MONO_AXO_1_2_VOL, 786 RT5631_R_EN_SHIFT, rt5631_outvolr_sel);
794 RT5631_R_EN_SHIFT, rt5631_outvolr_sel);
795 787
796static const struct snd_kcontrol_new rt5631_outvolr_mux_control = 788static const struct snd_kcontrol_new rt5631_outvolr_mux_control =
797 SOC_DAPM_ENUM("Right OUTVOL SRC", rt5631_outvolr_enum); 789 SOC_DAPM_ENUM("Right OUTVOL SRC", rt5631_outvolr_enum);
@@ -799,9 +791,8 @@ static const struct snd_kcontrol_new rt5631_outvolr_mux_control =
799/* Right HP Volume Input */ 791/* Right HP Volume Input */
800static const char *rt5631_hpvolr_sel[] = {"Vmid", "OUTMIXR"}; 792static const char *rt5631_hpvolr_sel[] = {"Vmid", "OUTMIXR"};
801 793
802static const SOC_ENUM_SINGLE_DECL( 794static SOC_ENUM_SINGLE_DECL(rt5631_hpvolr_enum, RT5631_HP_OUT_VOL,
803 rt5631_hpvolr_enum, RT5631_HP_OUT_VOL, 795 RT5631_R_EN_SHIFT, rt5631_hpvolr_sel);
804 RT5631_R_EN_SHIFT, rt5631_hpvolr_sel);
805 796
806static const struct snd_kcontrol_new rt5631_hpvolr_mux_control = 797static const struct snd_kcontrol_new rt5631_hpvolr_mux_control =
807 SOC_DAPM_ENUM("Right HPVOL SRC", rt5631_hpvolr_enum); 798 SOC_DAPM_ENUM("Right HPVOL SRC", rt5631_hpvolr_enum);
@@ -809,9 +800,8 @@ static const struct snd_kcontrol_new rt5631_hpvolr_mux_control =
809/* Right SPK Volume Input */ 800/* Right SPK Volume Input */
810static const char *rt5631_spkvolr_sel[] = {"Vmid", "SPKMIXR"}; 801static const char *rt5631_spkvolr_sel[] = {"Vmid", "SPKMIXR"};
811 802
812static const SOC_ENUM_SINGLE_DECL( 803static SOC_ENUM_SINGLE_DECL(rt5631_spkvolr_enum, RT5631_SPK_OUT_VOL,
813 rt5631_spkvolr_enum, RT5631_SPK_OUT_VOL, 804 RT5631_R_EN_SHIFT, rt5631_spkvolr_sel);
814 RT5631_R_EN_SHIFT, rt5631_spkvolr_sel);
815 805
816static const struct snd_kcontrol_new rt5631_spkvolr_mux_control = 806static const struct snd_kcontrol_new rt5631_spkvolr_mux_control =
817 SOC_DAPM_ENUM("Right SPKVOL SRC", rt5631_spkvolr_enum); 807 SOC_DAPM_ENUM("Right SPKVOL SRC", rt5631_spkvolr_enum);
@@ -820,9 +810,8 @@ static const struct snd_kcontrol_new rt5631_spkvolr_mux_control =
820static const char *rt5631_spol_src_sel[] = { 810static const char *rt5631_spol_src_sel[] = {
821 "SPOLMIX", "MONOIN_RX", "VDAC", "DACL"}; 811 "SPOLMIX", "MONOIN_RX", "VDAC", "DACL"};
822 812
823static const SOC_ENUM_SINGLE_DECL( 813static SOC_ENUM_SINGLE_DECL(rt5631_spol_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
824 rt5631_spol_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL, 814 RT5631_SPK_L_MUX_SEL_SHIFT, rt5631_spol_src_sel);
825 RT5631_SPK_L_MUX_SEL_SHIFT, rt5631_spol_src_sel);
826 815
827static const struct snd_kcontrol_new rt5631_spol_mux_control = 816static const struct snd_kcontrol_new rt5631_spol_mux_control =
828 SOC_DAPM_ENUM("SPOL SRC", rt5631_spol_src_enum); 817 SOC_DAPM_ENUM("SPOL SRC", rt5631_spol_src_enum);
@@ -831,9 +820,8 @@ static const struct snd_kcontrol_new rt5631_spol_mux_control =
831static const char *rt5631_spor_src_sel[] = { 820static const char *rt5631_spor_src_sel[] = {
832 "SPORMIX", "MONOIN_RX", "VDAC", "DACR"}; 821 "SPORMIX", "MONOIN_RX", "VDAC", "DACR"};
833 822
834static const SOC_ENUM_SINGLE_DECL( 823static SOC_ENUM_SINGLE_DECL(rt5631_spor_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
835 rt5631_spor_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL, 824 RT5631_SPK_R_MUX_SEL_SHIFT, rt5631_spor_src_sel);
836 RT5631_SPK_R_MUX_SEL_SHIFT, rt5631_spor_src_sel);
837 825
838static const struct snd_kcontrol_new rt5631_spor_mux_control = 826static const struct snd_kcontrol_new rt5631_spor_mux_control =
839 SOC_DAPM_ENUM("SPOR SRC", rt5631_spor_src_enum); 827 SOC_DAPM_ENUM("SPOR SRC", rt5631_spor_src_enum);
@@ -841,9 +829,8 @@ static const struct snd_kcontrol_new rt5631_spor_mux_control =
841/* MONO Input */ 829/* MONO Input */
842static const char *rt5631_mono_src_sel[] = {"MONOMIX", "MONOIN_RX", "VDAC"}; 830static const char *rt5631_mono_src_sel[] = {"MONOMIX", "MONOIN_RX", "VDAC"};
843 831
844static const SOC_ENUM_SINGLE_DECL( 832static SOC_ENUM_SINGLE_DECL(rt5631_mono_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
845 rt5631_mono_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL, 833 RT5631_MONO_MUX_SEL_SHIFT, rt5631_mono_src_sel);
846 RT5631_MONO_MUX_SEL_SHIFT, rt5631_mono_src_sel);
847 834
848static const struct snd_kcontrol_new rt5631_mono_mux_control = 835static const struct snd_kcontrol_new rt5631_mono_mux_control =
849 SOC_DAPM_ENUM("MONO SRC", rt5631_mono_src_enum); 836 SOC_DAPM_ENUM("MONO SRC", rt5631_mono_src_enum);
@@ -851,9 +838,8 @@ static const struct snd_kcontrol_new rt5631_mono_mux_control =
851/* Left HPO Input */ 838/* Left HPO Input */
852static const char *rt5631_hpl_src_sel[] = {"Left HPVOL", "Left DAC"}; 839static const char *rt5631_hpl_src_sel[] = {"Left HPVOL", "Left DAC"};
853 840
854static const SOC_ENUM_SINGLE_DECL( 841static SOC_ENUM_SINGLE_DECL(rt5631_hpl_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
855 rt5631_hpl_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL, 842 RT5631_HP_L_MUX_SEL_SHIFT, rt5631_hpl_src_sel);
856 RT5631_HP_L_MUX_SEL_SHIFT, rt5631_hpl_src_sel);
857 843
858static const struct snd_kcontrol_new rt5631_hpl_mux_control = 844static const struct snd_kcontrol_new rt5631_hpl_mux_control =
859 SOC_DAPM_ENUM("HPL SRC", rt5631_hpl_src_enum); 845 SOC_DAPM_ENUM("HPL SRC", rt5631_hpl_src_enum);
@@ -861,9 +847,8 @@ static const struct snd_kcontrol_new rt5631_hpl_mux_control =
861/* Right HPO Input */ 847/* Right HPO Input */
862static const char *rt5631_hpr_src_sel[] = {"Right HPVOL", "Right DAC"}; 848static const char *rt5631_hpr_src_sel[] = {"Right HPVOL", "Right DAC"};
863 849
864static const SOC_ENUM_SINGLE_DECL( 850static SOC_ENUM_SINGLE_DECL(rt5631_hpr_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL,
865 rt5631_hpr_src_enum, RT5631_SPK_MONO_HP_OUT_CTRL, 851 RT5631_HP_R_MUX_SEL_SHIFT, rt5631_hpr_src_sel);
866 RT5631_HP_R_MUX_SEL_SHIFT, rt5631_hpr_src_sel);
867 852
868static const struct snd_kcontrol_new rt5631_hpr_mux_control = 853static const struct snd_kcontrol_new rt5631_hpr_mux_control =
869 SOC_DAPM_ENUM("HPR SRC", rt5631_hpr_src_enum); 854 SOC_DAPM_ENUM("HPR SRC", rt5631_hpr_src_enum);
@@ -1585,15 +1570,6 @@ static int rt5631_probe(struct snd_soc_codec *codec)
1585{ 1570{
1586 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec); 1571 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
1587 unsigned int val; 1572 unsigned int val;
1588 int ret;
1589
1590 codec->control_data = rt5631->regmap;
1591
1592 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1593 if (ret != 0) {
1594 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1595 return ret;
1596 }
1597 1573
1598 val = rt5631_read_index(codec, RT5631_ADDA_MIXER_INTL_REG3); 1574 val = rt5631_read_index(codec, RT5631_ADDA_MIXER_INTL_REG3);
1599 if (val & 0x0002) 1575 if (val & 0x0002)
diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index 886924934aa5..0061ae6b6716 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -361,25 +361,24 @@ static unsigned int bst_tlv[] = {
361static const char * const rt5640_data_select[] = { 361static const char * const rt5640_data_select[] = {
362 "Normal", "left copy to right", "right copy to left", "Swap"}; 362 "Normal", "left copy to right", "right copy to left", "Swap"};
363 363
364static const SOC_ENUM_SINGLE_DECL(rt5640_if1_dac_enum, RT5640_DIG_INF_DATA, 364static SOC_ENUM_SINGLE_DECL(rt5640_if1_dac_enum, RT5640_DIG_INF_DATA,
365 RT5640_IF1_DAC_SEL_SFT, rt5640_data_select); 365 RT5640_IF1_DAC_SEL_SFT, rt5640_data_select);
366 366
367static const SOC_ENUM_SINGLE_DECL(rt5640_if1_adc_enum, RT5640_DIG_INF_DATA, 367static SOC_ENUM_SINGLE_DECL(rt5640_if1_adc_enum, RT5640_DIG_INF_DATA,
368 RT5640_IF1_ADC_SEL_SFT, rt5640_data_select); 368 RT5640_IF1_ADC_SEL_SFT, rt5640_data_select);
369 369
370static const SOC_ENUM_SINGLE_DECL(rt5640_if2_dac_enum, RT5640_DIG_INF_DATA, 370static SOC_ENUM_SINGLE_DECL(rt5640_if2_dac_enum, RT5640_DIG_INF_DATA,
371 RT5640_IF2_DAC_SEL_SFT, rt5640_data_select); 371 RT5640_IF2_DAC_SEL_SFT, rt5640_data_select);
372 372
373static const SOC_ENUM_SINGLE_DECL(rt5640_if2_adc_enum, RT5640_DIG_INF_DATA, 373static SOC_ENUM_SINGLE_DECL(rt5640_if2_adc_enum, RT5640_DIG_INF_DATA,
374 RT5640_IF2_ADC_SEL_SFT, rt5640_data_select); 374 RT5640_IF2_ADC_SEL_SFT, rt5640_data_select);
375 375
376/* Class D speaker gain ratio */ 376/* Class D speaker gain ratio */
377static const char * const rt5640_clsd_spk_ratio[] = {"1.66x", "1.83x", "1.94x", 377static const char * const rt5640_clsd_spk_ratio[] = {"1.66x", "1.83x", "1.94x",
378 "2x", "2.11x", "2.22x", "2.33x", "2.44x", "2.55x", "2.66x", "2.77x"}; 378 "2x", "2.11x", "2.22x", "2.33x", "2.44x", "2.55x", "2.66x", "2.77x"};
379 379
380static const SOC_ENUM_SINGLE_DECL( 380static SOC_ENUM_SINGLE_DECL(rt5640_clsd_spk_ratio_enum, RT5640_CLS_D_OUT,
381 rt5640_clsd_spk_ratio_enum, RT5640_CLS_D_OUT, 381 RT5640_CLSD_RATIO_SFT, rt5640_clsd_spk_ratio);
382 RT5640_CLSD_RATIO_SFT, rt5640_clsd_spk_ratio);
383 382
384static const struct snd_kcontrol_new rt5640_snd_controls[] = { 383static const struct snd_kcontrol_new rt5640_snd_controls[] = {
385 /* Speaker Output Volume */ 384 /* Speaker Output Volume */
@@ -753,9 +752,8 @@ static const char * const rt5640_stereo_adc1_src[] = {
753 "DIG MIX", "ADC" 752 "DIG MIX", "ADC"
754}; 753};
755 754
756static const SOC_ENUM_SINGLE_DECL( 755static SOC_ENUM_SINGLE_DECL(rt5640_stereo_adc1_enum, RT5640_STO_ADC_MIXER,
757 rt5640_stereo_adc1_enum, RT5640_STO_ADC_MIXER, 756 RT5640_ADC_1_SRC_SFT, rt5640_stereo_adc1_src);
758 RT5640_ADC_1_SRC_SFT, rt5640_stereo_adc1_src);
759 757
760static const struct snd_kcontrol_new rt5640_sto_adc_1_mux = 758static const struct snd_kcontrol_new rt5640_sto_adc_1_mux =
761 SOC_DAPM_ENUM("Stereo ADC1 Mux", rt5640_stereo_adc1_enum); 759 SOC_DAPM_ENUM("Stereo ADC1 Mux", rt5640_stereo_adc1_enum);
@@ -764,9 +762,8 @@ static const char * const rt5640_stereo_adc2_src[] = {
764 "DMIC1", "DMIC2", "DIG MIX" 762 "DMIC1", "DMIC2", "DIG MIX"
765}; 763};
766 764
767static const SOC_ENUM_SINGLE_DECL( 765static SOC_ENUM_SINGLE_DECL(rt5640_stereo_adc2_enum, RT5640_STO_ADC_MIXER,
768 rt5640_stereo_adc2_enum, RT5640_STO_ADC_MIXER, 766 RT5640_ADC_2_SRC_SFT, rt5640_stereo_adc2_src);
769 RT5640_ADC_2_SRC_SFT, rt5640_stereo_adc2_src);
770 767
771static const struct snd_kcontrol_new rt5640_sto_adc_2_mux = 768static const struct snd_kcontrol_new rt5640_sto_adc_2_mux =
772 SOC_DAPM_ENUM("Stereo ADC2 Mux", rt5640_stereo_adc2_enum); 769 SOC_DAPM_ENUM("Stereo ADC2 Mux", rt5640_stereo_adc2_enum);
@@ -776,9 +773,8 @@ static const char * const rt5640_mono_adc_l1_src[] = {
776 "Mono DAC MIXL", "ADCL" 773 "Mono DAC MIXL", "ADCL"
777}; 774};
778 775
779static const SOC_ENUM_SINGLE_DECL( 776static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_l1_enum, RT5640_MONO_ADC_MIXER,
780 rt5640_mono_adc_l1_enum, RT5640_MONO_ADC_MIXER, 777 RT5640_MONO_ADC_L1_SRC_SFT, rt5640_mono_adc_l1_src);
781 RT5640_MONO_ADC_L1_SRC_SFT, rt5640_mono_adc_l1_src);
782 778
783static const struct snd_kcontrol_new rt5640_mono_adc_l1_mux = 779static const struct snd_kcontrol_new rt5640_mono_adc_l1_mux =
784 SOC_DAPM_ENUM("Mono ADC1 left source", rt5640_mono_adc_l1_enum); 780 SOC_DAPM_ENUM("Mono ADC1 left source", rt5640_mono_adc_l1_enum);
@@ -787,9 +783,8 @@ static const char * const rt5640_mono_adc_l2_src[] = {
787 "DMIC L1", "DMIC L2", "Mono DAC MIXL" 783 "DMIC L1", "DMIC L2", "Mono DAC MIXL"
788}; 784};
789 785
790static const SOC_ENUM_SINGLE_DECL( 786static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_l2_enum, RT5640_MONO_ADC_MIXER,
791 rt5640_mono_adc_l2_enum, RT5640_MONO_ADC_MIXER, 787 RT5640_MONO_ADC_L2_SRC_SFT, rt5640_mono_adc_l2_src);
792 RT5640_MONO_ADC_L2_SRC_SFT, rt5640_mono_adc_l2_src);
793 788
794static const struct snd_kcontrol_new rt5640_mono_adc_l2_mux = 789static const struct snd_kcontrol_new rt5640_mono_adc_l2_mux =
795 SOC_DAPM_ENUM("Mono ADC2 left source", rt5640_mono_adc_l2_enum); 790 SOC_DAPM_ENUM("Mono ADC2 left source", rt5640_mono_adc_l2_enum);
@@ -798,9 +793,8 @@ static const char * const rt5640_mono_adc_r1_src[] = {
798 "Mono DAC MIXR", "ADCR" 793 "Mono DAC MIXR", "ADCR"
799}; 794};
800 795
801static const SOC_ENUM_SINGLE_DECL( 796static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_r1_enum, RT5640_MONO_ADC_MIXER,
802 rt5640_mono_adc_r1_enum, RT5640_MONO_ADC_MIXER, 797 RT5640_MONO_ADC_R1_SRC_SFT, rt5640_mono_adc_r1_src);
803 RT5640_MONO_ADC_R1_SRC_SFT, rt5640_mono_adc_r1_src);
804 798
805static const struct snd_kcontrol_new rt5640_mono_adc_r1_mux = 799static const struct snd_kcontrol_new rt5640_mono_adc_r1_mux =
806 SOC_DAPM_ENUM("Mono ADC1 right source", rt5640_mono_adc_r1_enum); 800 SOC_DAPM_ENUM("Mono ADC1 right source", rt5640_mono_adc_r1_enum);
@@ -809,9 +803,8 @@ static const char * const rt5640_mono_adc_r2_src[] = {
809 "DMIC R1", "DMIC R2", "Mono DAC MIXR" 803 "DMIC R1", "DMIC R2", "Mono DAC MIXR"
810}; 804};
811 805
812static const SOC_ENUM_SINGLE_DECL( 806static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_r2_enum, RT5640_MONO_ADC_MIXER,
813 rt5640_mono_adc_r2_enum, RT5640_MONO_ADC_MIXER, 807 RT5640_MONO_ADC_R2_SRC_SFT, rt5640_mono_adc_r2_src);
814 RT5640_MONO_ADC_R2_SRC_SFT, rt5640_mono_adc_r2_src);
815 808
816static const struct snd_kcontrol_new rt5640_mono_adc_r2_mux = 809static const struct snd_kcontrol_new rt5640_mono_adc_r2_mux =
817 SOC_DAPM_ENUM("Mono ADC2 right source", rt5640_mono_adc_r2_enum); 810 SOC_DAPM_ENUM("Mono ADC2 right source", rt5640_mono_adc_r2_enum);
@@ -826,9 +819,9 @@ static int rt5640_dac_l2_values[] = {
826 3, 819 3,
827}; 820};
828 821
829static const SOC_VALUE_ENUM_SINGLE_DECL( 822static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dac_l2_enum,
830 rt5640_dac_l2_enum, RT5640_DSP_PATH2, RT5640_DAC_L2_SEL_SFT, 823 RT5640_DSP_PATH2, RT5640_DAC_L2_SEL_SFT,
831 0x3, rt5640_dac_l2_src, rt5640_dac_l2_values); 824 0x3, rt5640_dac_l2_src, rt5640_dac_l2_values);
832 825
833static const struct snd_kcontrol_new rt5640_dac_l2_mux = 826static const struct snd_kcontrol_new rt5640_dac_l2_mux =
834 SOC_DAPM_VALUE_ENUM("DAC2 left channel source", rt5640_dac_l2_enum); 827 SOC_DAPM_VALUE_ENUM("DAC2 left channel source", rt5640_dac_l2_enum);
@@ -841,9 +834,9 @@ static int rt5640_dac_r2_values[] = {
841 0, 834 0,
842}; 835};
843 836
844static const SOC_VALUE_ENUM_SINGLE_DECL( 837static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dac_r2_enum,
845 rt5640_dac_r2_enum, RT5640_DSP_PATH2, RT5640_DAC_R2_SEL_SFT, 838 RT5640_DSP_PATH2, RT5640_DAC_R2_SEL_SFT,
846 0x3, rt5640_dac_r2_src, rt5640_dac_r2_values); 839 0x3, rt5640_dac_r2_src, rt5640_dac_r2_values);
847 840
848static const struct snd_kcontrol_new rt5640_dac_r2_mux = 841static const struct snd_kcontrol_new rt5640_dac_r2_mux =
849 SOC_DAPM_ENUM("DAC2 right channel source", rt5640_dac_r2_enum); 842 SOC_DAPM_ENUM("DAC2 right channel source", rt5640_dac_r2_enum);
@@ -860,9 +853,10 @@ static int rt5640_dai_iis_map_values[] = {
860 7, 853 7,
861}; 854};
862 855
863static const SOC_VALUE_ENUM_SINGLE_DECL( 856static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dai_iis_map_enum,
864 rt5640_dai_iis_map_enum, RT5640_I2S1_SDP, RT5640_I2S_IF_SFT, 857 RT5640_I2S1_SDP, RT5640_I2S_IF_SFT,
865 0x7, rt5640_dai_iis_map, rt5640_dai_iis_map_values); 858 0x7, rt5640_dai_iis_map,
859 rt5640_dai_iis_map_values);
866 860
867static const struct snd_kcontrol_new rt5640_dai_mux = 861static const struct snd_kcontrol_new rt5640_dai_mux =
868 SOC_DAPM_VALUE_ENUM("DAI select", rt5640_dai_iis_map_enum); 862 SOC_DAPM_VALUE_ENUM("DAI select", rt5640_dai_iis_map_enum);
@@ -872,9 +866,8 @@ static const char * const rt5640_sdi_sel[] = {
872 "IF1", "IF2" 866 "IF1", "IF2"
873}; 867};
874 868
875static const SOC_ENUM_SINGLE_DECL( 869static SOC_ENUM_SINGLE_DECL(rt5640_sdi_sel_enum, RT5640_I2S2_SDP,
876 rt5640_sdi_sel_enum, RT5640_I2S2_SDP, 870 RT5640_I2S2_SDI_SFT, rt5640_sdi_sel);
877 RT5640_I2S2_SDI_SFT, rt5640_sdi_sel);
878 871
879static const struct snd_kcontrol_new rt5640_sdi_mux = 872static const struct snd_kcontrol_new rt5640_sdi_mux =
880 SOC_DAPM_ENUM("SDI select", rt5640_sdi_sel_enum); 873 SOC_DAPM_ENUM("SDI select", rt5640_sdi_sel_enum);
@@ -1601,8 +1594,7 @@ static int get_clk_info(int sclk, int rate)
1601static int rt5640_hw_params(struct snd_pcm_substream *substream, 1594static int rt5640_hw_params(struct snd_pcm_substream *substream,
1602 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 1595 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
1603{ 1596{
1604 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1597 struct snd_soc_codec *codec = dai->codec;
1605 struct snd_soc_codec *codec = rtd->codec;
1606 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 1598 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
1607 unsigned int val_len = 0, val_clk, mask_clk; 1599 unsigned int val_len = 0, val_clk, mask_clk;
1608 int dai_sel, pre_div, bclk_ms, frame_size; 1600 int dai_sel, pre_div, bclk_ms, frame_size;
@@ -1943,16 +1935,8 @@ static int rt5640_set_bias_level(struct snd_soc_codec *codec,
1943static int rt5640_probe(struct snd_soc_codec *codec) 1935static int rt5640_probe(struct snd_soc_codec *codec)
1944{ 1936{
1945 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 1937 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
1946 int ret;
1947 1938
1948 rt5640->codec = codec; 1939 rt5640->codec = codec;
1949 codec->control_data = rt5640->regmap;
1950
1951 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1952 if (ret != 0) {
1953 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1954 return ret;
1955 }
1956 1940
1957 codec->dapm.idle_bias_off = 1; 1941 codec->dapm.idle_bias_off = 1;
1958 rt5640_set_bias_level(codec, SND_SOC_BIAS_OFF); 1942 rt5640_set_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index 0fcbe90f3ef2..d3ed1be5a186 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -187,8 +187,9 @@ static const char *adc_mux_text[] = {
187 "MIC_IN", "LINE_IN" 187 "MIC_IN", "LINE_IN"
188}; 188};
189 189
190static const struct soc_enum adc_enum = 190static SOC_ENUM_SINGLE_DECL(adc_enum,
191SOC_ENUM_SINGLE(SGTL5000_CHIP_ANA_CTRL, 2, 2, adc_mux_text); 191 SGTL5000_CHIP_ANA_CTRL, 2,
192 adc_mux_text);
192 193
193static const struct snd_kcontrol_new adc_mux = 194static const struct snd_kcontrol_new adc_mux =
194SOC_DAPM_ENUM("Capture Mux", adc_enum); 195SOC_DAPM_ENUM("Capture Mux", adc_enum);
@@ -198,8 +199,9 @@ static const char *dac_mux_text[] = {
198 "DAC", "LINE_IN" 199 "DAC", "LINE_IN"
199}; 200};
200 201
201static const struct soc_enum dac_enum = 202static SOC_ENUM_SINGLE_DECL(dac_enum,
202SOC_ENUM_SINGLE(SGTL5000_CHIP_ANA_CTRL, 6, 2, dac_mux_text); 203 SGTL5000_CHIP_ANA_CTRL, 6,
204 dac_mux_text);
203 205
204static const struct snd_kcontrol_new dac_mux = 206static const struct snd_kcontrol_new dac_mux =
205SOC_DAPM_ENUM("Headphone Mux", dac_enum); 207SOC_DAPM_ENUM("Headphone Mux", dac_enum);
@@ -1350,14 +1352,6 @@ static int sgtl5000_probe(struct snd_soc_codec *codec)
1350 int ret; 1352 int ret;
1351 struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec); 1353 struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec);
1352 1354
1353 /* setup i2c data ops */
1354 codec->control_data = sgtl5000->regmap;
1355 ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
1356 if (ret < 0) {
1357 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1358 return ret;
1359 }
1360
1361 ret = sgtl5000_enable_regulators(codec); 1355 ret = sgtl5000_enable_regulators(codec);
1362 if (ret) 1356 if (ret)
1363 return ret; 1357 return ret;
diff --git a/sound/soc/codecs/si476x.c b/sound/soc/codecs/si476x.c
index fa2b8e07f420..244c097cd905 100644
--- a/sound/soc/codecs/si476x.c
+++ b/sound/soc/codecs/si476x.c
@@ -21,6 +21,7 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/pcm_params.h> 23#include <sound/pcm_params.h>
24#include <linux/regmap.h>
24#include <sound/soc.h> 25#include <sound/soc.h>
25#include <sound/initval.h> 26#include <sound/initval.h>
26 27
@@ -209,8 +210,9 @@ out:
209 210
210static int si476x_codec_probe(struct snd_soc_codec *codec) 211static int si476x_codec_probe(struct snd_soc_codec *codec)
211{ 212{
212 codec->control_data = dev_get_regmap(codec->dev->parent, NULL); 213 struct regmap *regmap = dev_get_regmap(codec->dev->parent, NULL);
213 return snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP); 214
215 return snd_soc_codec_set_cache_io(codec, regmap);
214} 216}
215 217
216static struct snd_soc_dai_ops si476x_dai_ops = { 218static struct snd_soc_dai_ops si476x_dai_ops = {
diff --git a/sound/soc/codecs/sirf-audio-codec.c b/sound/soc/codecs/sirf-audio-codec.c
new file mode 100644
index 000000000000..58e7c1f23771
--- /dev/null
+++ b/sound/soc/codecs/sirf-audio-codec.c
@@ -0,0 +1,524 @@
1/*
2 * SiRF audio codec driver
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#include <linux/module.h>
10#include <linux/platform_device.h>
11#include <linux/pm_runtime.h>
12#include <linux/of.h>
13#include <linux/of_device.h>
14#include <linux/clk.h>
15#include <linux/delay.h>
16#include <linux/io.h>
17#include <linux/regmap.h>
18#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/pcm_params.h>
21#include <sound/initval.h>
22#include <sound/tlv.h>
23#include <sound/soc.h>
24#include <sound/dmaengine_pcm.h>
25
26#include "sirf-audio-codec.h"
27
28struct sirf_audio_codec {
29 struct clk *clk;
30 struct regmap *regmap;
31 u32 reg_ctrl0, reg_ctrl1;
32};
33
34static const char * const input_mode_mux[] = {"Single-ended",
35 "Differential"};
36
37static const struct soc_enum input_mode_mux_enum =
38 SOC_ENUM_SINGLE(AUDIO_IC_CODEC_CTRL1, 4, 2, input_mode_mux);
39
40static const struct snd_kcontrol_new sirf_audio_codec_input_mode_control =
41 SOC_DAPM_ENUM("Route", input_mode_mux_enum);
42
43static const DECLARE_TLV_DB_SCALE(playback_vol_tlv, -12400, 100, 0);
44static const DECLARE_TLV_DB_SCALE(capture_vol_tlv_prima2, 500, 100, 0);
45static const DECLARE_TLV_DB_RANGE(capture_vol_tlv_atlas6,
46 0, 7, TLV_DB_SCALE_ITEM(-100, 100, 0),
47 0x22, 0x3F, TLV_DB_SCALE_ITEM(700, 100, 0),
48);
49
50static struct snd_kcontrol_new volume_controls_atlas6[] = {
51 SOC_DOUBLE_TLV("Playback Volume", AUDIO_IC_CODEC_CTRL0, 21, 14,
52 0x7F, 0, playback_vol_tlv),
53 SOC_DOUBLE_TLV("Capture Volume", AUDIO_IC_CODEC_CTRL1, 16, 10,
54 0x3F, 0, capture_vol_tlv_atlas6),
55};
56
57static struct snd_kcontrol_new volume_controls_prima2[] = {
58 SOC_DOUBLE_TLV("Speaker Volume", AUDIO_IC_CODEC_CTRL0, 21, 14,
59 0x7F, 0, playback_vol_tlv),
60 SOC_DOUBLE_TLV("Capture Volume", AUDIO_IC_CODEC_CTRL1, 15, 10,
61 0x1F, 0, capture_vol_tlv_prima2),
62};
63
64static struct snd_kcontrol_new left_input_path_controls[] = {
65 SOC_DAPM_SINGLE("Line Left Switch", AUDIO_IC_CODEC_CTRL1, 6, 1, 0),
66 SOC_DAPM_SINGLE("Mic Left Switch", AUDIO_IC_CODEC_CTRL1, 3, 1, 0),
67};
68
69static struct snd_kcontrol_new right_input_path_controls[] = {
70 SOC_DAPM_SINGLE("Line Right Switch", AUDIO_IC_CODEC_CTRL1, 5, 1, 0),
71 SOC_DAPM_SINGLE("Mic Right Switch", AUDIO_IC_CODEC_CTRL1, 2, 1, 0),
72};
73
74static struct snd_kcontrol_new left_dac_to_hp_left_amp_switch_control =
75 SOC_DAPM_SINGLE("Switch", AUDIO_IC_CODEC_CTRL0, 9, 1, 0);
76
77static struct snd_kcontrol_new left_dac_to_hp_right_amp_switch_control =
78 SOC_DAPM_SINGLE("Switch", AUDIO_IC_CODEC_CTRL0, 8, 1, 0);
79
80static struct snd_kcontrol_new right_dac_to_hp_left_amp_switch_control =
81 SOC_DAPM_SINGLE("Switch", AUDIO_IC_CODEC_CTRL0, 7, 1, 0);
82
83static struct snd_kcontrol_new right_dac_to_hp_right_amp_switch_control =
84 SOC_DAPM_SINGLE("Switch", AUDIO_IC_CODEC_CTRL0, 6, 1, 0);
85
86static struct snd_kcontrol_new left_dac_to_speaker_lineout_switch_control =
87 SOC_DAPM_SINGLE("Switch", AUDIO_IC_CODEC_CTRL0, 11, 1, 0);
88
89static struct snd_kcontrol_new right_dac_to_speaker_lineout_switch_control =
90 SOC_DAPM_SINGLE("Switch", AUDIO_IC_CODEC_CTRL0, 10, 1, 0);
91
92/* After enable adc, Delay 200ms to avoid pop noise */
93static int adc_enable_delay_event(struct snd_soc_dapm_widget *w,
94 struct snd_kcontrol *kcontrol, int event)
95{
96 switch (event) {
97 case SND_SOC_DAPM_POST_PMU:
98 msleep(200);
99 break;
100 default:
101 break;
102 }
103
104 return 0;
105}
106
107static void enable_and_reset_codec(struct regmap *regmap,
108 u32 codec_enable_bits, u32 codec_reset_bits)
109{
110 regmap_update_bits(regmap, AUDIO_IC_CODEC_CTRL1,
111 codec_enable_bits | codec_reset_bits,
112 codec_enable_bits | ~codec_reset_bits);
113 msleep(20);
114 regmap_update_bits(regmap, AUDIO_IC_CODEC_CTRL1,
115 codec_reset_bits, codec_reset_bits);
116}
117
118static int atlas6_codec_enable_and_reset_event(struct snd_soc_dapm_widget *w,
119 struct snd_kcontrol *kcontrol, int event)
120{
121#define ATLAS6_CODEC_ENABLE_BITS (1 << 29)
122#define ATLAS6_CODEC_RESET_BITS (1 << 28)
123 struct sirf_audio_codec *sirf_audio_codec = dev_get_drvdata(w->codec->dev);
124 switch (event) {
125 case SND_SOC_DAPM_PRE_PMU:
126 enable_and_reset_codec(sirf_audio_codec->regmap,
127 ATLAS6_CODEC_ENABLE_BITS, ATLAS6_CODEC_RESET_BITS);
128 break;
129 case SND_SOC_DAPM_POST_PMD:
130 regmap_update_bits(sirf_audio_codec->regmap,
131 AUDIO_IC_CODEC_CTRL1, ATLAS6_CODEC_ENABLE_BITS,
132 ~ATLAS6_CODEC_ENABLE_BITS);
133 break;
134 default:
135 break;
136 }
137
138 return 0;
139}
140
141static int prima2_codec_enable_and_reset_event(struct snd_soc_dapm_widget *w,
142 struct snd_kcontrol *kcontrol, int event)
143{
144#define PRIMA2_CODEC_ENABLE_BITS (1 << 27)
145#define PRIMA2_CODEC_RESET_BITS (1 << 26)
146 struct sirf_audio_codec *sirf_audio_codec = dev_get_drvdata(w->codec->dev);
147 switch (event) {
148 case SND_SOC_DAPM_POST_PMU:
149 enable_and_reset_codec(sirf_audio_codec->regmap,
150 PRIMA2_CODEC_ENABLE_BITS, PRIMA2_CODEC_RESET_BITS);
151 break;
152 case SND_SOC_DAPM_POST_PMD:
153 regmap_update_bits(sirf_audio_codec->regmap,
154 AUDIO_IC_CODEC_CTRL1, PRIMA2_CODEC_ENABLE_BITS,
155 ~PRIMA2_CODEC_ENABLE_BITS);
156 break;
157 default:
158 break;
159 }
160
161 return 0;
162}
163
164static const struct snd_soc_dapm_widget atlas6_output_driver_dapm_widgets[] = {
165 SND_SOC_DAPM_OUT_DRV("HP Left Driver", AUDIO_IC_CODEC_CTRL1,
166 25, 0, NULL, 0),
167 SND_SOC_DAPM_OUT_DRV("HP Right Driver", AUDIO_IC_CODEC_CTRL1,
168 26, 0, NULL, 0),
169 SND_SOC_DAPM_OUT_DRV("Speaker Driver", AUDIO_IC_CODEC_CTRL1,
170 27, 0, NULL, 0),
171};
172
173static const struct snd_soc_dapm_widget prima2_output_driver_dapm_widgets[] = {
174 SND_SOC_DAPM_OUT_DRV("HP Left Driver", AUDIO_IC_CODEC_CTRL1,
175 23, 0, NULL, 0),
176 SND_SOC_DAPM_OUT_DRV("HP Right Driver", AUDIO_IC_CODEC_CTRL1,
177 24, 0, NULL, 0),
178 SND_SOC_DAPM_OUT_DRV("Speaker Driver", AUDIO_IC_CODEC_CTRL1,
179 25, 0, NULL, 0),
180};
181
182static const struct snd_soc_dapm_widget atlas6_codec_clock_dapm_widget =
183 SND_SOC_DAPM_SUPPLY("codecclk", SND_SOC_NOPM, 0, 0,
184 atlas6_codec_enable_and_reset_event,
185 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD);
186
187static const struct snd_soc_dapm_widget prima2_codec_clock_dapm_widget =
188 SND_SOC_DAPM_SUPPLY("codecclk", SND_SOC_NOPM, 0, 0,
189 prima2_codec_enable_and_reset_event,
190 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD);
191
192static const struct snd_soc_dapm_widget sirf_audio_codec_dapm_widgets[] = {
193 SND_SOC_DAPM_DAC("DAC left", NULL, AUDIO_IC_CODEC_CTRL0, 1, 0),
194 SND_SOC_DAPM_DAC("DAC right", NULL, AUDIO_IC_CODEC_CTRL0, 0, 0),
195 SND_SOC_DAPM_SWITCH("Left dac to hp left amp", SND_SOC_NOPM, 0, 0,
196 &left_dac_to_hp_left_amp_switch_control),
197 SND_SOC_DAPM_SWITCH("Left dac to hp right amp", SND_SOC_NOPM, 0, 0,
198 &left_dac_to_hp_right_amp_switch_control),
199 SND_SOC_DAPM_SWITCH("Right dac to hp left amp", SND_SOC_NOPM, 0, 0,
200 &right_dac_to_hp_left_amp_switch_control),
201 SND_SOC_DAPM_SWITCH("Right dac to hp right amp", SND_SOC_NOPM, 0, 0,
202 &right_dac_to_hp_right_amp_switch_control),
203 SND_SOC_DAPM_OUT_DRV("HP amp left driver", AUDIO_IC_CODEC_CTRL0, 3, 0,
204 NULL, 0),
205 SND_SOC_DAPM_OUT_DRV("HP amp right driver", AUDIO_IC_CODEC_CTRL0, 3, 0,
206 NULL, 0),
207
208 SND_SOC_DAPM_SWITCH("Left dac to speaker lineout", SND_SOC_NOPM, 0, 0,
209 &left_dac_to_speaker_lineout_switch_control),
210 SND_SOC_DAPM_SWITCH("Right dac to speaker lineout", SND_SOC_NOPM, 0, 0,
211 &right_dac_to_speaker_lineout_switch_control),
212 SND_SOC_DAPM_OUT_DRV("Speaker amp driver", AUDIO_IC_CODEC_CTRL0, 4, 0,
213 NULL, 0),
214
215 SND_SOC_DAPM_OUTPUT("HPOUTL"),
216 SND_SOC_DAPM_OUTPUT("HPOUTR"),
217 SND_SOC_DAPM_OUTPUT("SPKOUT"),
218
219 SND_SOC_DAPM_ADC_E("ADC left", NULL, AUDIO_IC_CODEC_CTRL1, 8, 0,
220 adc_enable_delay_event, SND_SOC_DAPM_POST_PMU),
221 SND_SOC_DAPM_ADC_E("ADC right", NULL, AUDIO_IC_CODEC_CTRL1, 7, 0,
222 adc_enable_delay_event, SND_SOC_DAPM_POST_PMU),
223 SND_SOC_DAPM_MIXER("Left PGA mixer", AUDIO_IC_CODEC_CTRL1, 1, 0,
224 &left_input_path_controls[0],
225 ARRAY_SIZE(left_input_path_controls)),
226 SND_SOC_DAPM_MIXER("Right PGA mixer", AUDIO_IC_CODEC_CTRL1, 0, 0,
227 &right_input_path_controls[0],
228 ARRAY_SIZE(right_input_path_controls)),
229
230 SND_SOC_DAPM_MUX("Mic input mode mux", SND_SOC_NOPM, 0, 0,
231 &sirf_audio_codec_input_mode_control),
232 SND_SOC_DAPM_MICBIAS("Mic Bias", AUDIO_IC_CODEC_PWR, 3, 0),
233 SND_SOC_DAPM_INPUT("MICIN1"),
234 SND_SOC_DAPM_INPUT("MICIN2"),
235 SND_SOC_DAPM_INPUT("LINEIN1"),
236 SND_SOC_DAPM_INPUT("LINEIN2"),
237
238 SND_SOC_DAPM_SUPPLY("HSL Phase Opposite", AUDIO_IC_CODEC_CTRL0,
239 30, 0, NULL, 0),
240};
241
242static const struct snd_soc_dapm_route sirf_audio_codec_map[] = {
243 {"SPKOUT", NULL, "Speaker Driver"},
244 {"Speaker Driver", NULL, "Speaker amp driver"},
245 {"Speaker amp driver", NULL, "Left dac to speaker lineout"},
246 {"Speaker amp driver", NULL, "Right dac to speaker lineout"},
247 {"Left dac to speaker lineout", "Switch", "DAC left"},
248 {"Right dac to speaker lineout", "Switch", "DAC right"},
249 {"HPOUTL", NULL, "HP Left Driver"},
250 {"HPOUTR", NULL, "HP Right Driver"},
251 {"HP Left Driver", NULL, "HP amp left driver"},
252 {"HP Right Driver", NULL, "HP amp right driver"},
253 {"HP amp left driver", NULL, "Right dac to hp left amp"},
254 {"HP amp right driver", NULL , "Right dac to hp right amp"},
255 {"HP amp left driver", NULL, "Left dac to hp left amp"},
256 {"HP amp right driver", NULL , "Right dac to hp right amp"},
257 {"Right dac to hp left amp", "Switch", "DAC left"},
258 {"Right dac to hp right amp", "Switch", "DAC right"},
259 {"Left dac to hp left amp", "Switch", "DAC left"},
260 {"Left dac to hp right amp", "Switch", "DAC right"},
261 {"DAC left", NULL, "codecclk"},
262 {"DAC right", NULL, "codecclk"},
263 {"DAC left", NULL, "Playback"},
264 {"DAC right", NULL, "Playback"},
265 {"DAC left", NULL, "HSL Phase Opposite"},
266 {"DAC right", NULL, "HSL Phase Opposite"},
267
268 {"Capture", NULL, "ADC left"},
269 {"Capture", NULL, "ADC right"},
270 {"ADC left", NULL, "codecclk"},
271 {"ADC right", NULL, "codecclk"},
272 {"ADC left", NULL, "Left PGA mixer"},
273 {"ADC right", NULL, "Right PGA mixer"},
274 {"Left PGA mixer", "Line Left Switch", "LINEIN2"},
275 {"Right PGA mixer", "Line Right Switch", "LINEIN1"},
276 {"Left PGA mixer", "Mic Left Switch", "MICIN2"},
277 {"Right PGA mixer", "Mic Right Switch", "Mic input mode mux"},
278 {"Mic input mode mux", "Single-ended", "MICIN1"},
279 {"Mic input mode mux", "Differential", "MICIN1"},
280};
281
282static int sirf_audio_codec_trigger(struct snd_pcm_substream *substream,
283 int cmd,
284 struct snd_soc_dai *dai)
285{
286 int playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
287 struct snd_soc_codec *codec = dai->codec;
288 u32 val = 0;
289
290 /*
291 * This is a workaround, When stop playback,
292 * need disable HP amp, avoid the current noise.
293 */
294 switch (cmd) {
295 case SNDRV_PCM_TRIGGER_STOP:
296 case SNDRV_PCM_TRIGGER_SUSPEND:
297 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
298 break;
299 case SNDRV_PCM_TRIGGER_START:
300 case SNDRV_PCM_TRIGGER_RESUME:
301 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
302 if (playback)
303 val = IC_HSLEN | IC_HSREN;
304 break;
305 default:
306 return -EINVAL;
307 }
308
309 if (playback)
310 snd_soc_update_bits(codec, AUDIO_IC_CODEC_CTRL0,
311 IC_HSLEN | IC_HSREN, val);
312 return 0;
313}
314
315struct snd_soc_dai_ops sirf_audio_codec_dai_ops = {
316 .trigger = sirf_audio_codec_trigger,
317};
318
319struct snd_soc_dai_driver sirf_audio_codec_dai = {
320 .name = "sirf-audio-codec",
321 .playback = {
322 .stream_name = "Playback",
323 .channels_min = 2,
324 .channels_max = 2,
325 .rates = SNDRV_PCM_RATE_48000,
326 .formats = SNDRV_PCM_FMTBIT_S16_LE,
327 },
328 .capture = {
329 .stream_name = "Capture",
330 .channels_min = 1,
331 .channels_max = 2,
332 .rates = SNDRV_PCM_RATE_48000,
333 .formats = SNDRV_PCM_FMTBIT_S16_LE,
334 },
335 .ops = &sirf_audio_codec_dai_ops,
336};
337
338static int sirf_audio_codec_probe(struct snd_soc_codec *codec)
339{
340 struct snd_soc_dapm_context *dapm = &codec->dapm;
341
342 pm_runtime_enable(codec->dev);
343
344 if (of_device_is_compatible(codec->dev->of_node, "sirf,prima2-audio-codec")) {
345 snd_soc_dapm_new_controls(dapm,
346 prima2_output_driver_dapm_widgets,
347 ARRAY_SIZE(prima2_output_driver_dapm_widgets));
348 snd_soc_dapm_new_controls(dapm,
349 &prima2_codec_clock_dapm_widget, 1);
350 return snd_soc_add_codec_controls(codec,
351 volume_controls_prima2,
352 ARRAY_SIZE(volume_controls_prima2));
353 }
354 if (of_device_is_compatible(codec->dev->of_node, "sirf,atlas6-audio-codec")) {
355 snd_soc_dapm_new_controls(dapm,
356 atlas6_output_driver_dapm_widgets,
357 ARRAY_SIZE(atlas6_output_driver_dapm_widgets));
358 snd_soc_dapm_new_controls(dapm,
359 &atlas6_codec_clock_dapm_widget, 1);
360 return snd_soc_add_codec_controls(codec,
361 volume_controls_atlas6,
362 ARRAY_SIZE(volume_controls_atlas6));
363 }
364
365 return -EINVAL;
366}
367
368static int sirf_audio_codec_remove(struct snd_soc_codec *codec)
369{
370 pm_runtime_disable(codec->dev);
371 return 0;
372}
373
374static struct snd_soc_codec_driver soc_codec_device_sirf_audio_codec = {
375 .probe = sirf_audio_codec_probe,
376 .remove = sirf_audio_codec_remove,
377 .dapm_widgets = sirf_audio_codec_dapm_widgets,
378 .num_dapm_widgets = ARRAY_SIZE(sirf_audio_codec_dapm_widgets),
379 .dapm_routes = sirf_audio_codec_map,
380 .num_dapm_routes = ARRAY_SIZE(sirf_audio_codec_map),
381 .idle_bias_off = true,
382};
383
384static const struct of_device_id sirf_audio_codec_of_match[] = {
385 { .compatible = "sirf,prima2-audio-codec" },
386 { .compatible = "sirf,atlas6-audio-codec" },
387 {}
388};
389MODULE_DEVICE_TABLE(of, sirf_audio_codec_of_match);
390
391static const struct regmap_config sirf_audio_codec_regmap_config = {
392 .reg_bits = 32,
393 .reg_stride = 4,
394 .val_bits = 32,
395 .max_register = AUDIO_IC_CODEC_CTRL3,
396 .cache_type = REGCACHE_NONE,
397};
398
399static int sirf_audio_codec_driver_probe(struct platform_device *pdev)
400{
401 int ret;
402 struct sirf_audio_codec *sirf_audio_codec;
403 void __iomem *base;
404 struct resource *mem_res;
405 const struct of_device_id *match;
406
407 match = of_match_node(sirf_audio_codec_of_match, pdev->dev.of_node);
408
409 sirf_audio_codec = devm_kzalloc(&pdev->dev,
410 sizeof(struct sirf_audio_codec), GFP_KERNEL);
411 if (!sirf_audio_codec)
412 return -ENOMEM;
413
414 platform_set_drvdata(pdev, sirf_audio_codec);
415
416 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
417 base = devm_ioremap_resource(&pdev->dev, mem_res);
418 if (base == NULL)
419 return -ENOMEM;
420
421 sirf_audio_codec->regmap = devm_regmap_init_mmio(&pdev->dev, base,
422 &sirf_audio_codec_regmap_config);
423 if (IS_ERR(sirf_audio_codec->regmap))
424 return PTR_ERR(sirf_audio_codec->regmap);
425
426 sirf_audio_codec->clk = devm_clk_get(&pdev->dev, NULL);
427 if (IS_ERR(sirf_audio_codec->clk)) {
428 dev_err(&pdev->dev, "Get clock failed.\n");
429 return PTR_ERR(sirf_audio_codec->clk);
430 }
431
432 ret = clk_prepare_enable(sirf_audio_codec->clk);
433 if (ret) {
434 dev_err(&pdev->dev, "Enable clock failed.\n");
435 return ret;
436 }
437
438 ret = snd_soc_register_codec(&(pdev->dev),
439 &soc_codec_device_sirf_audio_codec,
440 &sirf_audio_codec_dai, 1);
441 if (ret) {
442 dev_err(&pdev->dev, "Register Audio Codec dai failed.\n");
443 goto err_clk_put;
444 }
445
446 /*
447 * Always open charge pump, if not, when the charge pump closed the
448 * adc will not stable
449 */
450 regmap_update_bits(sirf_audio_codec->regmap, AUDIO_IC_CODEC_CTRL0,
451 IC_CPFREQ, IC_CPFREQ);
452
453 if (of_device_is_compatible(pdev->dev.of_node, "sirf,atlas6-audio-codec"))
454 regmap_update_bits(sirf_audio_codec->regmap,
455 AUDIO_IC_CODEC_CTRL0, IC_CPEN, IC_CPEN);
456 return 0;
457
458err_clk_put:
459 clk_disable_unprepare(sirf_audio_codec->clk);
460 return ret;
461}
462
463static int sirf_audio_codec_driver_remove(struct platform_device *pdev)
464{
465 struct sirf_audio_codec *sirf_audio_codec = platform_get_drvdata(pdev);
466
467 clk_disable_unprepare(sirf_audio_codec->clk);
468 snd_soc_unregister_codec(&(pdev->dev));
469
470 return 0;
471}
472
473#ifdef CONFIG_PM_SLEEP
474static int sirf_audio_codec_suspend(struct device *dev)
475{
476 struct sirf_audio_codec *sirf_audio_codec = dev_get_drvdata(dev);
477
478 regmap_read(sirf_audio_codec->regmap, AUDIO_IC_CODEC_CTRL0,
479 &sirf_audio_codec->reg_ctrl0);
480 regmap_read(sirf_audio_codec->regmap, AUDIO_IC_CODEC_CTRL1,
481 &sirf_audio_codec->reg_ctrl1);
482 clk_disable_unprepare(sirf_audio_codec->clk);
483
484 return 0;
485}
486
487static int sirf_audio_codec_resume(struct device *dev)
488{
489 struct sirf_audio_codec *sirf_audio_codec = dev_get_drvdata(dev);
490 int ret;
491
492 ret = clk_prepare_enable(sirf_audio_codec->clk);
493 if (ret)
494 return ret;
495
496 regmap_write(sirf_audio_codec->regmap, AUDIO_IC_CODEC_CTRL0,
497 sirf_audio_codec->reg_ctrl0);
498 regmap_write(sirf_audio_codec->regmap, AUDIO_IC_CODEC_CTRL1,
499 sirf_audio_codec->reg_ctrl1);
500
501 return 0;
502}
503#endif
504
505static const struct dev_pm_ops sirf_audio_codec_pm_ops = {
506 SET_SYSTEM_SLEEP_PM_OPS(sirf_audio_codec_suspend, sirf_audio_codec_resume)
507};
508
509static struct platform_driver sirf_audio_codec_driver = {
510 .driver = {
511 .name = "sirf-audio-codec",
512 .owner = THIS_MODULE,
513 .of_match_table = sirf_audio_codec_of_match,
514 .pm = &sirf_audio_codec_pm_ops,
515 },
516 .probe = sirf_audio_codec_driver_probe,
517 .remove = sirf_audio_codec_driver_remove,
518};
519
520module_platform_driver(sirf_audio_codec_driver);
521
522MODULE_DESCRIPTION("SiRF audio codec driver");
523MODULE_AUTHOR("RongJun Ying <Rongjun.Ying@csr.com>");
524MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/sirf-audio-codec.h b/sound/soc/codecs/sirf-audio-codec.h
new file mode 100644
index 000000000000..d4c187b8e54a
--- /dev/null
+++ b/sound/soc/codecs/sirf-audio-codec.h
@@ -0,0 +1,75 @@
1/*
2 * SiRF inner codec controllers define
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#ifndef _SIRF_AUDIO_CODEC_H
10#define _SIRF_AUDIO_CODEC_H
11
12
13#define AUDIO_IC_CODEC_PWR (0x00E0)
14#define AUDIO_IC_CODEC_CTRL0 (0x00E4)
15#define AUDIO_IC_CODEC_CTRL1 (0x00E8)
16#define AUDIO_IC_CODEC_CTRL2 (0x00EC)
17#define AUDIO_IC_CODEC_CTRL3 (0x00F0)
18
19#define MICBIASEN (1 << 3)
20
21#define IC_RDACEN (1 << 0)
22#define IC_LDACEN (1 << 1)
23#define IC_HSREN (1 << 2)
24#define IC_HSLEN (1 << 3)
25#define IC_SPEN (1 << 4)
26#define IC_CPEN (1 << 5)
27
28#define IC_HPRSELR (1 << 6)
29#define IC_HPLSELR (1 << 7)
30#define IC_HPRSELL (1 << 8)
31#define IC_HPLSELL (1 << 9)
32#define IC_SPSELR (1 << 10)
33#define IC_SPSELL (1 << 11)
34
35#define IC_MONOR (1 << 12)
36#define IC_MONOL (1 << 13)
37
38#define IC_RXOSRSEL (1 << 28)
39#define IC_CPFREQ (1 << 29)
40#define IC_HSINVEN (1 << 30)
41
42#define IC_MICINREN (1 << 0)
43#define IC_MICINLEN (1 << 1)
44#define IC_MICIN1SEL (1 << 2)
45#define IC_MICIN2SEL (1 << 3)
46#define IC_MICDIFSEL (1 << 4)
47#define IC_LINEIN1SEL (1 << 5)
48#define IC_LINEIN2SEL (1 << 6)
49#define IC_RADCEN (1 << 7)
50#define IC_LADCEN (1 << 8)
51#define IC_ALM (1 << 9)
52
53#define IC_DIGMICEN (1 << 22)
54#define IC_DIGMICFREQ (1 << 23)
55#define IC_ADC14B_12 (1 << 24)
56#define IC_FIRDAC_HSL_EN (1 << 25)
57#define IC_FIRDAC_HSR_EN (1 << 26)
58#define IC_FIRDAC_LOUT_EN (1 << 27)
59#define IC_POR (1 << 28)
60#define IC_CODEC_CLK_EN (1 << 29)
61#define IC_HP_3DB_BOOST (1 << 30)
62
63#define IC_ADC_LEFT_GAIN_SHIFT 16
64#define IC_ADC_RIGHT_GAIN_SHIFT 10
65#define IC_ADC_GAIN_MASK 0x3F
66#define IC_MIC_MAX_GAIN 0x39
67
68#define IC_RXPGAR_MASK 0x3F
69#define IC_RXPGAR_SHIFT 14
70#define IC_RXPGAL_MASK 0x3F
71#define IC_RXPGAL_SHIFT 21
72#define IC_RXPGAR 0x7B
73#define IC_RXPGAL 0x7B
74
75#endif /*__SIRF_AUDIO_CODEC_H*/
diff --git a/sound/soc/codecs/sn95031.c b/sound/soc/codecs/sn95031.c
index 13045f2af4d3..42dff26b3a2a 100644
--- a/sound/soc/codecs/sn95031.c
+++ b/sound/soc/codecs/sn95031.c
@@ -312,14 +312,14 @@ static int sn95031_dmic56_event(struct snd_soc_dapm_widget *w,
312/* mux controls */ 312/* mux controls */
313static const char *sn95031_mic_texts[] = { "AMIC", "LineIn" }; 313static const char *sn95031_mic_texts[] = { "AMIC", "LineIn" };
314 314
315static const struct soc_enum sn95031_micl_enum = 315static SOC_ENUM_SINGLE_DECL(sn95031_micl_enum,
316 SOC_ENUM_SINGLE(SN95031_ADCCONFIG, 1, 2, sn95031_mic_texts); 316 SN95031_ADCCONFIG, 1, sn95031_mic_texts);
317 317
318static const struct snd_kcontrol_new sn95031_micl_mux_control = 318static const struct snd_kcontrol_new sn95031_micl_mux_control =
319 SOC_DAPM_ENUM("Route", sn95031_micl_enum); 319 SOC_DAPM_ENUM("Route", sn95031_micl_enum);
320 320
321static const struct soc_enum sn95031_micr_enum = 321static SOC_ENUM_SINGLE_DECL(sn95031_micr_enum,
322 SOC_ENUM_SINGLE(SN95031_ADCCONFIG, 3, 2, sn95031_mic_texts); 322 SN95031_ADCCONFIG, 3, sn95031_mic_texts);
323 323
324static const struct snd_kcontrol_new sn95031_micr_mux_control = 324static const struct snd_kcontrol_new sn95031_micr_mux_control =
325 SOC_DAPM_ENUM("Route", sn95031_micr_enum); 325 SOC_DAPM_ENUM("Route", sn95031_micr_enum);
@@ -328,26 +328,26 @@ static const char *sn95031_input_texts[] = { "DMIC1", "DMIC2", "DMIC3",
328 "DMIC4", "DMIC5", "DMIC6", 328 "DMIC4", "DMIC5", "DMIC6",
329 "ADC Left", "ADC Right" }; 329 "ADC Left", "ADC Right" };
330 330
331static const struct soc_enum sn95031_input1_enum = 331static SOC_ENUM_SINGLE_DECL(sn95031_input1_enum,
332 SOC_ENUM_SINGLE(SN95031_AUDIOMUX12, 0, 8, sn95031_input_texts); 332 SN95031_AUDIOMUX12, 0, sn95031_input_texts);
333 333
334static const struct snd_kcontrol_new sn95031_input1_mux_control = 334static const struct snd_kcontrol_new sn95031_input1_mux_control =
335 SOC_DAPM_ENUM("Route", sn95031_input1_enum); 335 SOC_DAPM_ENUM("Route", sn95031_input1_enum);
336 336
337static const struct soc_enum sn95031_input2_enum = 337static SOC_ENUM_SINGLE_DECL(sn95031_input2_enum,
338 SOC_ENUM_SINGLE(SN95031_AUDIOMUX12, 4, 8, sn95031_input_texts); 338 SN95031_AUDIOMUX12, 4, sn95031_input_texts);
339 339
340static const struct snd_kcontrol_new sn95031_input2_mux_control = 340static const struct snd_kcontrol_new sn95031_input2_mux_control =
341 SOC_DAPM_ENUM("Route", sn95031_input2_enum); 341 SOC_DAPM_ENUM("Route", sn95031_input2_enum);
342 342
343static const struct soc_enum sn95031_input3_enum = 343static SOC_ENUM_SINGLE_DECL(sn95031_input3_enum,
344 SOC_ENUM_SINGLE(SN95031_AUDIOMUX34, 0, 8, sn95031_input_texts); 344 SN95031_AUDIOMUX34, 0, sn95031_input_texts);
345 345
346static const struct snd_kcontrol_new sn95031_input3_mux_control = 346static const struct snd_kcontrol_new sn95031_input3_mux_control =
347 SOC_DAPM_ENUM("Route", sn95031_input3_enum); 347 SOC_DAPM_ENUM("Route", sn95031_input3_enum);
348 348
349static const struct soc_enum sn95031_input4_enum = 349static SOC_ENUM_SINGLE_DECL(sn95031_input4_enum,
350 SOC_ENUM_SINGLE(SN95031_AUDIOMUX34, 4, 8, sn95031_input_texts); 350 SN95031_AUDIOMUX34, 4, sn95031_input_texts);
351 351
352static const struct snd_kcontrol_new sn95031_input4_mux_control = 352static const struct snd_kcontrol_new sn95031_input4_mux_control =
353 SOC_DAPM_ENUM("Route", sn95031_input4_enum); 353 SOC_DAPM_ENUM("Route", sn95031_input4_enum);
@@ -359,19 +359,19 @@ static const char *sn95031_micmode_text[] = {"Single Ended", "Differential"};
359/* 0dB to 30dB in 10dB steps */ 359/* 0dB to 30dB in 10dB steps */
360static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 10, 0); 360static const DECLARE_TLV_DB_SCALE(mic_tlv, 0, 10, 0);
361 361
362static const struct soc_enum sn95031_micmode1_enum = 362static SOC_ENUM_SINGLE_DECL(sn95031_micmode1_enum,
363 SOC_ENUM_SINGLE(SN95031_MICAMP1, 1, 2, sn95031_micmode_text); 363 SN95031_MICAMP1, 1, sn95031_micmode_text);
364static const struct soc_enum sn95031_micmode2_enum = 364static SOC_ENUM_SINGLE_DECL(sn95031_micmode2_enum,
365 SOC_ENUM_SINGLE(SN95031_MICAMP2, 1, 2, sn95031_micmode_text); 365 SN95031_MICAMP2, 1, sn95031_micmode_text);
366 366
367static const char *sn95031_dmic_cfg_text[] = {"GPO", "DMIC"}; 367static const char *sn95031_dmic_cfg_text[] = {"GPO", "DMIC"};
368 368
369static const struct soc_enum sn95031_dmic12_cfg_enum = 369static SOC_ENUM_SINGLE_DECL(sn95031_dmic12_cfg_enum,
370 SOC_ENUM_SINGLE(SN95031_DMICMUX, 0, 2, sn95031_dmic_cfg_text); 370 SN95031_DMICMUX, 0, sn95031_dmic_cfg_text);
371static const struct soc_enum sn95031_dmic34_cfg_enum = 371static SOC_ENUM_SINGLE_DECL(sn95031_dmic34_cfg_enum,
372 SOC_ENUM_SINGLE(SN95031_DMICMUX, 1, 2, sn95031_dmic_cfg_text); 372 SN95031_DMICMUX, 1, sn95031_dmic_cfg_text);
373static const struct soc_enum sn95031_dmic56_cfg_enum = 373static SOC_ENUM_SINGLE_DECL(sn95031_dmic56_cfg_enum,
374 SOC_ENUM_SINGLE(SN95031_DMICMUX, 2, 2, sn95031_dmic_cfg_text); 374 SN95031_DMICMUX, 2, sn95031_dmic_cfg_text);
375 375
376static const struct snd_kcontrol_new sn95031_snd_controls[] = { 376static const struct snd_kcontrol_new sn95031_snd_controls[] = {
377 SOC_ENUM("Mic1Mode Capture Route", sn95031_micmode1_enum), 377 SOC_ENUM("Mic1Mode Capture Route", sn95031_micmode1_enum),
@@ -825,8 +825,6 @@ static int sn95031_codec_probe(struct snd_soc_codec *codec)
825{ 825{
826 pr_debug("codec_probe called\n"); 826 pr_debug("codec_probe called\n");
827 827
828 snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
829
830 /* PCM interface config 828 /* PCM interface config
831 * This sets the pcm rx slot conguration to max 6 slots 829 * This sets the pcm rx slot conguration to max 6 slots
832 * for max 4 dais (2 stereo and 2 mono) 830 * for max 4 dais (2 stereo and 2 mono)
diff --git a/sound/soc/codecs/ssm2518.c b/sound/soc/codecs/ssm2518.c
index cc8debce752f..56adb3e2def9 100644
--- a/sound/soc/codecs/ssm2518.c
+++ b/sound/soc/codecs/ssm2518.c
@@ -169,19 +169,19 @@ static const char * const ssm2518_drc_hold_time_text[] = {
169 "682.24 ms", "1364 ms", 169 "682.24 ms", "1364 ms",
170}; 170};
171 171
172static const SOC_ENUM_SINGLE_DECL(ssm2518_drc_peak_detector_attack_time_enum, 172static SOC_ENUM_SINGLE_DECL(ssm2518_drc_peak_detector_attack_time_enum,
173 SSM2518_REG_DRC_2, 4, ssm2518_drc_peak_detector_attack_time_text); 173 SSM2518_REG_DRC_2, 4, ssm2518_drc_peak_detector_attack_time_text);
174static const SOC_ENUM_SINGLE_DECL(ssm2518_drc_peak_detector_release_time_enum, 174static SOC_ENUM_SINGLE_DECL(ssm2518_drc_peak_detector_release_time_enum,
175 SSM2518_REG_DRC_2, 0, ssm2518_drc_peak_detector_release_time_text); 175 SSM2518_REG_DRC_2, 0, ssm2518_drc_peak_detector_release_time_text);
176static const SOC_ENUM_SINGLE_DECL(ssm2518_drc_attack_time_enum, 176static SOC_ENUM_SINGLE_DECL(ssm2518_drc_attack_time_enum,
177 SSM2518_REG_DRC_6, 4, ssm2518_drc_peak_detector_attack_time_text); 177 SSM2518_REG_DRC_6, 4, ssm2518_drc_peak_detector_attack_time_text);
178static const SOC_ENUM_SINGLE_DECL(ssm2518_drc_decay_time_enum, 178static SOC_ENUM_SINGLE_DECL(ssm2518_drc_decay_time_enum,
179 SSM2518_REG_DRC_6, 0, ssm2518_drc_peak_detector_release_time_text); 179 SSM2518_REG_DRC_6, 0, ssm2518_drc_peak_detector_release_time_text);
180static const SOC_ENUM_SINGLE_DECL(ssm2518_drc_hold_time_enum, 180static SOC_ENUM_SINGLE_DECL(ssm2518_drc_hold_time_enum,
181 SSM2518_REG_DRC_7, 4, ssm2518_drc_hold_time_text); 181 SSM2518_REG_DRC_7, 4, ssm2518_drc_hold_time_text);
182static const SOC_ENUM_SINGLE_DECL(ssm2518_drc_noise_gate_hold_time_enum, 182static SOC_ENUM_SINGLE_DECL(ssm2518_drc_noise_gate_hold_time_enum,
183 SSM2518_REG_DRC_7, 0, ssm2518_drc_hold_time_text); 183 SSM2518_REG_DRC_7, 0, ssm2518_drc_hold_time_text);
184static const SOC_ENUM_SINGLE_DECL(ssm2518_drc_rms_averaging_time_enum, 184static SOC_ENUM_SINGLE_DECL(ssm2518_drc_rms_averaging_time_enum,
185 SSM2518_REG_DRC_9, 0, ssm2518_drc_peak_detector_release_time_text); 185 SSM2518_REG_DRC_9, 0, ssm2518_drc_peak_detector_release_time_text);
186 186
187static const struct snd_kcontrol_new ssm2518_snd_controls[] = { 187static const struct snd_kcontrol_new ssm2518_snd_controls[] = {
@@ -648,16 +648,6 @@ static struct snd_soc_dai_driver ssm2518_dai = {
648 648
649static int ssm2518_probe(struct snd_soc_codec *codec) 649static int ssm2518_probe(struct snd_soc_codec *codec)
650{ 650{
651 struct ssm2518 *ssm2518 = snd_soc_codec_get_drvdata(codec);
652 int ret;
653
654 codec->control_data = ssm2518->regmap;
655 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
656 if (ret < 0) {
657 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
658 return ret;
659 }
660
661 return ssm2518_set_bias_level(codec, SND_SOC_BIAS_OFF); 651 return ssm2518_set_bias_level(codec, SND_SOC_BIAS_OFF);
662} 652}
663 653
diff --git a/sound/soc/codecs/ssm2602-i2c.c b/sound/soc/codecs/ssm2602-i2c.c
new file mode 100644
index 000000000000..abd63d537173
--- /dev/null
+++ b/sound/soc/codecs/ssm2602-i2c.c
@@ -0,0 +1,57 @@
1/*
2 * SSM2602/SSM2603/SSM2604 I2C audio driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/module.h>
10#include <linux/i2c.h>
11#include <linux/regmap.h>
12
13#include <sound/soc.h>
14
15#include "ssm2602.h"
16
17/*
18 * ssm2602 2 wire address is determined by GPIO5
19 * state during powerup.
20 * low = 0x1a
21 * high = 0x1b
22 */
23static int ssm2602_i2c_probe(struct i2c_client *client,
24 const struct i2c_device_id *id)
25{
26 return ssm2602_probe(&client->dev, id->driver_data,
27 devm_regmap_init_i2c(client, &ssm2602_regmap_config));
28}
29
30static int ssm2602_i2c_remove(struct i2c_client *client)
31{
32 snd_soc_unregister_codec(&client->dev);
33 return 0;
34}
35
36static const struct i2c_device_id ssm2602_i2c_id[] = {
37 { "ssm2602", SSM2602 },
38 { "ssm2603", SSM2602 },
39 { "ssm2604", SSM2604 },
40 { }
41};
42MODULE_DEVICE_TABLE(i2c, ssm2602_i2c_id);
43
44static struct i2c_driver ssm2602_i2c_driver = {
45 .driver = {
46 .name = "ssm2602",
47 .owner = THIS_MODULE,
48 },
49 .probe = ssm2602_i2c_probe,
50 .remove = ssm2602_i2c_remove,
51 .id_table = ssm2602_i2c_id,
52};
53module_i2c_driver(ssm2602_i2c_driver);
54
55MODULE_DESCRIPTION("ASoC SSM2602/SSM2603/SSM2604 I2C driver");
56MODULE_AUTHOR("Cliff Cai");
57MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ssm2602-spi.c b/sound/soc/codecs/ssm2602-spi.c
new file mode 100644
index 000000000000..2bf55e24a7bb
--- /dev/null
+++ b/sound/soc/codecs/ssm2602-spi.c
@@ -0,0 +1,41 @@
1/*
2 * SSM2602 SPI audio driver
3 *
4 * Copyright 2014 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#include <linux/module.h>
10#include <linux/spi/spi.h>
11#include <linux/regmap.h>
12
13#include <sound/soc.h>
14
15#include "ssm2602.h"
16
17static int ssm2602_spi_probe(struct spi_device *spi)
18{
19 return ssm2602_probe(&spi->dev, SSM2602,
20 devm_regmap_init_spi(spi, &ssm2602_regmap_config));
21}
22
23static int ssm2602_spi_remove(struct spi_device *spi)
24{
25 snd_soc_unregister_codec(&spi->dev);
26 return 0;
27}
28
29static struct spi_driver ssm2602_spi_driver = {
30 .driver = {
31 .name = "ssm2602",
32 .owner = THIS_MODULE,
33 },
34 .probe = ssm2602_spi_probe,
35 .remove = ssm2602_spi_remove,
36};
37module_spi_driver(ssm2602_spi_driver);
38
39MODULE_DESCRIPTION("ASoC SSM2602 SPI driver");
40MODULE_AUTHOR("Cliff Cai");
41MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c
index af76bbd1b24f..97b0454eb346 100644
--- a/sound/soc/codecs/ssm2602.c
+++ b/sound/soc/codecs/ssm2602.c
@@ -27,32 +27,20 @@
27 */ 27 */
28 28
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/moduleparam.h>
31#include <linux/init.h>
32#include <linux/delay.h>
33#include <linux/pm.h>
34#include <linux/i2c.h>
35#include <linux/spi/spi.h>
36#include <linux/regmap.h> 30#include <linux/regmap.h>
37#include <linux/slab.h> 31#include <linux/slab.h>
38#include <sound/core.h> 32
39#include <sound/pcm.h> 33#include <sound/pcm.h>
40#include <sound/pcm_params.h> 34#include <sound/pcm_params.h>
41#include <sound/soc.h> 35#include <sound/soc.h>
42#include <sound/initval.h>
43#include <sound/tlv.h> 36#include <sound/tlv.h>
44 37
45#include "ssm2602.h" 38#include "ssm2602.h"
46 39
47enum ssm2602_type {
48 SSM2602,
49 SSM2604,
50};
51
52/* codec private data */ 40/* codec private data */
53struct ssm2602_priv { 41struct ssm2602_priv {
54 unsigned int sysclk; 42 unsigned int sysclk;
55 struct snd_pcm_hw_constraint_list *sysclk_constraints; 43 const struct snd_pcm_hw_constraint_list *sysclk_constraints;
56 44
57 struct regmap *regmap; 45 struct regmap *regmap;
58 46
@@ -75,15 +63,16 @@ static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = {
75 63
76/*Appending several "None"s just for OSS mixer use*/ 64/*Appending several "None"s just for OSS mixer use*/
77static const char *ssm2602_input_select[] = { 65static const char *ssm2602_input_select[] = {
78 "Line", "Mic", "None", "None", "None", 66 "Line", "Mic",
79 "None", "None", "None",
80}; 67};
81 68
82static const char *ssm2602_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"}; 69static const char *ssm2602_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};
83 70
84static const struct soc_enum ssm2602_enum[] = { 71static const struct soc_enum ssm2602_enum[] = {
85 SOC_ENUM_SINGLE(SSM2602_APANA, 2, 2, ssm2602_input_select), 72 SOC_ENUM_SINGLE(SSM2602_APANA, 2, ARRAY_SIZE(ssm2602_input_select),
86 SOC_ENUM_SINGLE(SSM2602_APDIGI, 1, 4, ssm2602_deemph), 73 ssm2602_input_select),
74 SOC_ENUM_SINGLE(SSM2602_APDIGI, 1, ARRAY_SIZE(ssm2602_deemph),
75 ssm2602_deemph),
87}; 76};
88 77
89static const unsigned int ssm260x_outmix_tlv[] = { 78static const unsigned int ssm260x_outmix_tlv[] = {
@@ -197,7 +186,7 @@ static const unsigned int ssm2602_rates_12288000[] = {
197 8000, 16000, 32000, 48000, 96000, 186 8000, 16000, 32000, 48000, 96000,
198}; 187};
199 188
200static struct snd_pcm_hw_constraint_list ssm2602_constraints_12288000 = { 189static const struct snd_pcm_hw_constraint_list ssm2602_constraints_12288000 = {
201 .list = ssm2602_rates_12288000, 190 .list = ssm2602_rates_12288000,
202 .count = ARRAY_SIZE(ssm2602_rates_12288000), 191 .count = ARRAY_SIZE(ssm2602_rates_12288000),
203}; 192};
@@ -206,7 +195,7 @@ static const unsigned int ssm2602_rates_11289600[] = {
206 8000, 44100, 88200, 195 8000, 44100, 88200,
207}; 196};
208 197
209static struct snd_pcm_hw_constraint_list ssm2602_constraints_11289600 = { 198static const struct snd_pcm_hw_constraint_list ssm2602_constraints_11289600 = {
210 .list = ssm2602_rates_11289600, 199 .list = ssm2602_rates_11289600,
211 .count = ARRAY_SIZE(ssm2602_rates_11289600), 200 .count = ARRAY_SIZE(ssm2602_rates_11289600),
212}; 201};
@@ -529,7 +518,7 @@ static int ssm2602_resume(struct snd_soc_codec *codec)
529 return 0; 518 return 0;
530} 519}
531 520
532static int ssm2602_probe(struct snd_soc_codec *codec) 521static int ssm2602_codec_probe(struct snd_soc_codec *codec)
533{ 522{
534 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); 523 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
535 struct snd_soc_dapm_context *dapm = &codec->dapm; 524 struct snd_soc_dapm_context *dapm = &codec->dapm;
@@ -554,7 +543,7 @@ static int ssm2602_probe(struct snd_soc_codec *codec)
554 ARRAY_SIZE(ssm2602_routes)); 543 ARRAY_SIZE(ssm2602_routes));
555} 544}
556 545
557static int ssm2604_probe(struct snd_soc_codec *codec) 546static int ssm2604_codec_probe(struct snd_soc_codec *codec)
558{ 547{
559 struct snd_soc_dapm_context *dapm = &codec->dapm; 548 struct snd_soc_dapm_context *dapm = &codec->dapm;
560 int ret; 549 int ret;
@@ -568,18 +557,11 @@ static int ssm2604_probe(struct snd_soc_codec *codec)
568 ARRAY_SIZE(ssm2604_routes)); 557 ARRAY_SIZE(ssm2604_routes));
569} 558}
570 559
571static int ssm260x_probe(struct snd_soc_codec *codec) 560static int ssm260x_codec_probe(struct snd_soc_codec *codec)
572{ 561{
573 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); 562 struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
574 int ret; 563 int ret;
575 564
576 codec->control_data = ssm2602->regmap;
577 ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
578 if (ret < 0) {
579 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
580 return ret;
581 }
582
583 ret = regmap_write(ssm2602->regmap, SSM2602_RESET, 0); 565 ret = regmap_write(ssm2602->regmap, SSM2602_RESET, 0);
584 if (ret < 0) { 566 if (ret < 0) {
585 dev_err(codec->dev, "Failed to issue reset: %d\n", ret); 567 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
@@ -597,10 +579,10 @@ static int ssm260x_probe(struct snd_soc_codec *codec)
597 579
598 switch (ssm2602->type) { 580 switch (ssm2602->type) {
599 case SSM2602: 581 case SSM2602:
600 ret = ssm2602_probe(codec); 582 ret = ssm2602_codec_probe(codec);
601 break; 583 break;
602 case SSM2604: 584 case SSM2604:
603 ret = ssm2604_probe(codec); 585 ret = ssm2604_codec_probe(codec);
604 break; 586 break;
605 } 587 }
606 588
@@ -620,7 +602,7 @@ static int ssm2602_remove(struct snd_soc_codec *codec)
620} 602}
621 603
622static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = { 604static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = {
623 .probe = ssm260x_probe, 605 .probe = ssm260x_codec_probe,
624 .remove = ssm2602_remove, 606 .remove = ssm2602_remove,
625 .suspend = ssm2602_suspend, 607 .suspend = ssm2602_suspend,
626 .resume = ssm2602_resume, 608 .resume = ssm2602_resume,
@@ -639,7 +621,7 @@ static bool ssm2602_register_volatile(struct device *dev, unsigned int reg)
639 return reg == SSM2602_RESET; 621 return reg == SSM2602_RESET;
640} 622}
641 623
642static const struct regmap_config ssm2602_regmap_config = { 624const struct regmap_config ssm2602_regmap_config = {
643 .val_bits = 9, 625 .val_bits = 9,
644 .reg_bits = 7, 626 .reg_bits = 7,
645 627
@@ -650,134 +632,28 @@ static const struct regmap_config ssm2602_regmap_config = {
650 .reg_defaults_raw = ssm2602_reg, 632 .reg_defaults_raw = ssm2602_reg,
651 .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg), 633 .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg),
652}; 634};
635EXPORT_SYMBOL_GPL(ssm2602_regmap_config);
653 636
654#if defined(CONFIG_SPI_MASTER) 637int ssm2602_probe(struct device *dev, enum ssm2602_type type,
655static int ssm2602_spi_probe(struct spi_device *spi) 638 struct regmap *regmap)
656{ 639{
657 struct ssm2602_priv *ssm2602; 640 struct ssm2602_priv *ssm2602;
658 int ret;
659
660 ssm2602 = devm_kzalloc(&spi->dev, sizeof(struct ssm2602_priv),
661 GFP_KERNEL);
662 if (ssm2602 == NULL)
663 return -ENOMEM;
664
665 spi_set_drvdata(spi, ssm2602);
666 ssm2602->type = SSM2602;
667 641
668 ssm2602->regmap = devm_regmap_init_spi(spi, &ssm2602_regmap_config); 642 if (IS_ERR(regmap))
669 if (IS_ERR(ssm2602->regmap)) 643 return PTR_ERR(regmap);
670 return PTR_ERR(ssm2602->regmap);
671 644
672 ret = snd_soc_register_codec(&spi->dev, 645 ssm2602 = devm_kzalloc(dev, sizeof(*ssm2602), GFP_KERNEL);
673 &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
674 return ret;
675}
676
677static int ssm2602_spi_remove(struct spi_device *spi)
678{
679 snd_soc_unregister_codec(&spi->dev);
680 return 0;
681}
682
683static struct spi_driver ssm2602_spi_driver = {
684 .driver = {
685 .name = "ssm2602",
686 .owner = THIS_MODULE,
687 },
688 .probe = ssm2602_spi_probe,
689 .remove = ssm2602_spi_remove,
690};
691#endif
692
693#if IS_ENABLED(CONFIG_I2C)
694/*
695 * ssm2602 2 wire address is determined by GPIO5
696 * state during powerup.
697 * low = 0x1a
698 * high = 0x1b
699 */
700static int ssm2602_i2c_probe(struct i2c_client *i2c,
701 const struct i2c_device_id *id)
702{
703 struct ssm2602_priv *ssm2602;
704 int ret;
705
706 ssm2602 = devm_kzalloc(&i2c->dev, sizeof(struct ssm2602_priv),
707 GFP_KERNEL);
708 if (ssm2602 == NULL) 646 if (ssm2602 == NULL)
709 return -ENOMEM; 647 return -ENOMEM;
710 648
711 i2c_set_clientdata(i2c, ssm2602); 649 dev_set_drvdata(dev, ssm2602);
712 ssm2602->type = id->driver_data; 650 ssm2602->type = SSM2602;
713 651 ssm2602->regmap = regmap;
714 ssm2602->regmap = devm_regmap_init_i2c(i2c, &ssm2602_regmap_config);
715 if (IS_ERR(ssm2602->regmap))
716 return PTR_ERR(ssm2602->regmap);
717
718 ret = snd_soc_register_codec(&i2c->dev,
719 &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
720 return ret;
721}
722
723static int ssm2602_i2c_remove(struct i2c_client *client)
724{
725 snd_soc_unregister_codec(&client->dev);
726 return 0;
727}
728
729static const struct i2c_device_id ssm2602_i2c_id[] = {
730 { "ssm2602", SSM2602 },
731 { "ssm2603", SSM2602 },
732 { "ssm2604", SSM2604 },
733 { }
734};
735MODULE_DEVICE_TABLE(i2c, ssm2602_i2c_id);
736
737/* corgi i2c codec control layer */
738static struct i2c_driver ssm2602_i2c_driver = {
739 .driver = {
740 .name = "ssm2602",
741 .owner = THIS_MODULE,
742 },
743 .probe = ssm2602_i2c_probe,
744 .remove = ssm2602_i2c_remove,
745 .id_table = ssm2602_i2c_id,
746};
747#endif
748
749
750static int __init ssm2602_modinit(void)
751{
752 int ret = 0;
753
754#if defined(CONFIG_SPI_MASTER)
755 ret = spi_register_driver(&ssm2602_spi_driver);
756 if (ret)
757 return ret;
758#endif
759
760#if IS_ENABLED(CONFIG_I2C)
761 ret = i2c_add_driver(&ssm2602_i2c_driver);
762 if (ret)
763 return ret;
764#endif
765
766 return ret;
767}
768module_init(ssm2602_modinit);
769
770static void __exit ssm2602_exit(void)
771{
772#if defined(CONFIG_SPI_MASTER)
773 spi_unregister_driver(&ssm2602_spi_driver);
774#endif
775 652
776#if IS_ENABLED(CONFIG_I2C) 653 return snd_soc_register_codec(dev, &soc_codec_dev_ssm2602,
777 i2c_del_driver(&ssm2602_i2c_driver); 654 &ssm2602_dai, 1);
778#endif
779} 655}
780module_exit(ssm2602_exit); 656EXPORT_SYMBOL_GPL(ssm2602_probe);
781 657
782MODULE_DESCRIPTION("ASoC SSM2602/SSM2603/SSM2604 driver"); 658MODULE_DESCRIPTION("ASoC SSM2602/SSM2603/SSM2604 driver");
783MODULE_AUTHOR("Cliff Cai"); 659MODULE_AUTHOR("Cliff Cai");
diff --git a/sound/soc/codecs/ssm2602.h b/sound/soc/codecs/ssm2602.h
index fbd07d7b73ca..747538847689 100644
--- a/sound/soc/codecs/ssm2602.h
+++ b/sound/soc/codecs/ssm2602.h
@@ -28,6 +28,20 @@
28#ifndef _SSM2602_H 28#ifndef _SSM2602_H
29#define _SSM2602_H 29#define _SSM2602_H
30 30
31#include <linux/regmap.h>
32
33struct device;
34
35enum ssm2602_type {
36 SSM2602,
37 SSM2604,
38};
39
40extern const struct regmap_config ssm2602_regmap_config;
41
42int ssm2602_probe(struct device *dev, enum ssm2602_type type,
43 struct regmap *regmap);
44
31/* SSM2602 Codec Register definitions */ 45/* SSM2602 Codec Register definitions */
32 46
33#define SSM2602_LINVOL 0x00 47#define SSM2602_LINVOL 0x00
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 2735361a4c3c..12577749b17b 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -872,16 +872,6 @@ static int sta32x_probe(struct snd_soc_codec *codec)
872 return ret; 872 return ret;
873 } 873 }
874 874
875 /* Tell ASoC what kind of I/O to use to read the registers. ASoC will
876 * then do the I2C transactions itself.
877 */
878 codec->control_data = sta32x->regmap;
879 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
880 if (ret < 0) {
881 dev_err(codec->dev, "failed to set cache I/O (ret=%i)\n", ret);
882 goto err;
883 }
884
885 /* Chip documentation explicitly requires that the reset values 875 /* Chip documentation explicitly requires that the reset values
886 * of reserved register bits are left untouched. 876 * of reserved register bits are left untouched.
887 * Write the register default value to cache for reserved registers, 877 * Write the register default value to cache for reserved registers,
@@ -946,10 +936,6 @@ static int sta32x_probe(struct snd_soc_codec *codec)
946 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies); 936 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies);
947 937
948 return 0; 938 return 0;
949
950err:
951 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), sta32x->supplies);
952 return ret;
953} 939}
954 940
955static int sta32x_remove(struct snd_soc_codec *codec) 941static int sta32x_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/sta529.c b/sound/soc/codecs/sta529.c
index 40c07be9b581..a40c4b0196a3 100644
--- a/sound/soc/codecs/sta529.c
+++ b/sound/soc/codecs/sta529.c
@@ -141,7 +141,7 @@ static const char *pwm_mode_text[] = { "Binary", "Headphone", "Ternary",
141 141
142static const DECLARE_TLV_DB_SCALE(out_gain_tlv, -9150, 50, 0); 142static const DECLARE_TLV_DB_SCALE(out_gain_tlv, -9150, 50, 0);
143static const DECLARE_TLV_DB_SCALE(master_vol_tlv, -12750, 50, 0); 143static const DECLARE_TLV_DB_SCALE(master_vol_tlv, -12750, 50, 0);
144static const SOC_ENUM_SINGLE_DECL(pwm_src, STA529_FFXCFG1, 4, pwm_mode_text); 144static SOC_ENUM_SINGLE_DECL(pwm_src, STA529_FFXCFG1, 4, pwm_mode_text);
145 145
146static const struct snd_kcontrol_new sta529_snd_controls[] = { 146static const struct snd_kcontrol_new sta529_snd_controls[] = {
147 SOC_DOUBLE_R_TLV("Digital Playback Volume", STA529_LVOL, STA529_RVOL, 0, 147 SOC_DOUBLE_R_TLV("Digital Playback Volume", STA529_LVOL, STA529_RVOL, 0,
@@ -193,8 +193,7 @@ static int sta529_hw_params(struct snd_pcm_substream *substream,
193 struct snd_pcm_hw_params *params, 193 struct snd_pcm_hw_params *params,
194 struct snd_soc_dai *dai) 194 struct snd_soc_dai *dai)
195{ 195{
196 struct snd_soc_pcm_runtime *rtd = substream->private_data; 196 struct snd_soc_codec *codec = dai->codec;
197 struct snd_soc_codec *codec = rtd->codec;
198 int pdata, play_freq_val, record_freq_val; 197 int pdata, play_freq_val, record_freq_val;
199 int bclk_to_fs_ratio; 198 int bclk_to_fs_ratio;
200 199
@@ -322,16 +321,6 @@ static struct snd_soc_dai_driver sta529_dai = {
322 321
323static int sta529_probe(struct snd_soc_codec *codec) 322static int sta529_probe(struct snd_soc_codec *codec)
324{ 323{
325 struct sta529 *sta529 = snd_soc_codec_get_drvdata(codec);
326 int ret;
327
328 codec->control_data = sta529->regmap;
329 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
330
331 if (ret < 0) {
332 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
333 return ret;
334 }
335 sta529_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 324 sta529_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
336 325
337 return 0; 326 return 0;
diff --git a/sound/soc/codecs/stac9766.c b/sound/soc/codecs/stac9766.c
index a5455c1aea42..53b810d23fea 100644
--- a/sound/soc/codecs/stac9766.c
+++ b/sound/soc/codecs/stac9766.c
@@ -62,25 +62,25 @@ static const char *stac9766_boost1[] = {"0dB", "10dB"};
62static const char *stac9766_boost2[] = {"0dB", "20dB"}; 62static const char *stac9766_boost2[] = {"0dB", "20dB"};
63static const char *stac9766_stereo_mic[] = {"Off", "On"}; 63static const char *stac9766_stereo_mic[] = {"Off", "On"};
64 64
65static const struct soc_enum stac9766_record_enum = 65static SOC_ENUM_DOUBLE_DECL(stac9766_record_enum,
66 SOC_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 8, stac9766_record_mux); 66 AC97_REC_SEL, 8, 0, stac9766_record_mux);
67static const struct soc_enum stac9766_mono_enum = 67static SOC_ENUM_SINGLE_DECL(stac9766_mono_enum,
68 SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 9, 2, stac9766_mono_mux); 68 AC97_GENERAL_PURPOSE, 9, stac9766_mono_mux);
69static const struct soc_enum stac9766_mic_enum = 69static SOC_ENUM_SINGLE_DECL(stac9766_mic_enum,
70 SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 8, 2, stac9766_mic_mux); 70 AC97_GENERAL_PURPOSE, 8, stac9766_mic_mux);
71static const struct soc_enum stac9766_SPDIF_enum = 71static SOC_ENUM_SINGLE_DECL(stac9766_SPDIF_enum,
72 SOC_ENUM_SINGLE(AC97_STAC_DA_CONTROL, 1, 2, stac9766_SPDIF_mux); 72 AC97_STAC_DA_CONTROL, 1, stac9766_SPDIF_mux);
73static const struct soc_enum stac9766_popbypass_enum = 73static SOC_ENUM_SINGLE_DECL(stac9766_popbypass_enum,
74 SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, stac9766_popbypass_mux); 74 AC97_GENERAL_PURPOSE, 15, stac9766_popbypass_mux);
75static const struct soc_enum stac9766_record_all_enum = 75static SOC_ENUM_SINGLE_DECL(stac9766_record_all_enum,
76 SOC_ENUM_SINGLE(AC97_STAC_ANALOG_SPECIAL, 12, 2, 76 AC97_STAC_ANALOG_SPECIAL, 12,
77 stac9766_record_all_mux); 77 stac9766_record_all_mux);
78static const struct soc_enum stac9766_boost1_enum = 78static SOC_ENUM_SINGLE_DECL(stac9766_boost1_enum,
79 SOC_ENUM_SINGLE(AC97_MIC, 6, 2, stac9766_boost1); /* 0/10dB */ 79 AC97_MIC, 6, stac9766_boost1); /* 0/10dB */
80static const struct soc_enum stac9766_boost2_enum = 80static SOC_ENUM_SINGLE_DECL(stac9766_boost2_enum,
81 SOC_ENUM_SINGLE(AC97_STAC_ANALOG_SPECIAL, 2, 2, stac9766_boost2); /* 0/20dB */ 81 AC97_STAC_ANALOG_SPECIAL, 2, stac9766_boost2); /* 0/20dB */
82static const struct soc_enum stac9766_stereo_mic_enum = 82static SOC_ENUM_SINGLE_DECL(stac9766_stereo_mic_enum,
83 SOC_ENUM_SINGLE(AC97_STAC_STEREO_MIC, 2, 1, stac9766_stereo_mic); 83 AC97_STAC_STEREO_MIC, 2, stac9766_stereo_mic);
84 84
85static const DECLARE_TLV_DB_LINEAR(master_tlv, -4600, 0); 85static const DECLARE_TLV_DB_LINEAR(master_tlv, -4600, 0);
86static const DECLARE_TLV_DB_LINEAR(record_tlv, 0, 2250); 86static const DECLARE_TLV_DB_LINEAR(record_tlv, 0, 2250);
diff --git a/sound/soc/codecs/tlv320aic23-i2c.c b/sound/soc/codecs/tlv320aic23-i2c.c
new file mode 100644
index 000000000000..20fc46092c2c
--- /dev/null
+++ b/sound/soc/codecs/tlv320aic23-i2c.c
@@ -0,0 +1,59 @@
1/*
2 * ALSA SoC TLV320AIC23 codec driver I2C interface
3 *
4 * Author: Arun KS, <arunks@mistralsolutions.com>
5 * Copyright: (C) 2008 Mistral Solutions Pvt Ltd.,
6 *
7 * Based on sound/soc/codecs/wm8731.c by Richard Purdie
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/i2c.h>
15#include <linux/module.h>
16#include <linux/regmap.h>
17#include <sound/soc.h>
18
19#include "tlv320aic23.h"
20
21static int tlv320aic23_i2c_probe(struct i2c_client *i2c,
22 const struct i2c_device_id *i2c_id)
23{
24 struct regmap *regmap;
25
26 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
27 return -EINVAL;
28
29 regmap = devm_regmap_init_i2c(i2c, &tlv320aic23_regmap);
30 return tlv320aic23_probe(&i2c->dev, regmap);
31}
32
33static int __exit tlv320aic23_i2c_remove(struct i2c_client *i2c)
34{
35 snd_soc_unregister_codec(&i2c->dev);
36 return 0;
37}
38
39static const struct i2c_device_id tlv320aic23_id[] = {
40 {"tlv320aic23", 0},
41 {}
42};
43
44MODULE_DEVICE_TABLE(i2c, tlv320aic23_id);
45
46static struct i2c_driver tlv320aic23_i2c_driver = {
47 .driver = {
48 .name = "tlv320aic23-codec",
49 },
50 .probe = tlv320aic23_i2c_probe,
51 .remove = __exit_p(tlv320aic23_i2c_remove),
52 .id_table = tlv320aic23_id,
53};
54
55module_i2c_driver(tlv320aic23_i2c_driver);
56
57MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver I2C");
58MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
59MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/tlv320aic23-spi.c b/sound/soc/codecs/tlv320aic23-spi.c
new file mode 100644
index 000000000000..3b387e41d75d
--- /dev/null
+++ b/sound/soc/codecs/tlv320aic23-spi.c
@@ -0,0 +1,56 @@
1/*
2 * ALSA SoC TLV320AIC23 codec driver SPI interface
3 *
4 * Author: Arun KS, <arunks@mistralsolutions.com>
5 * Copyright: (C) 2008 Mistral Solutions Pvt Ltd.,
6 *
7 * Based on sound/soc/codecs/wm8731.c by Richard Purdie
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/regmap.h>
16#include <linux/spi/spi.h>
17#include <sound/soc.h>
18
19#include "tlv320aic23.h"
20
21static int aic23_spi_probe(struct spi_device *spi)
22{
23 int ret;
24 struct regmap *regmap;
25
26 dev_dbg(&spi->dev, "probing tlv320aic23 spi device\n");
27
28 spi->mode = SPI_MODE_0;
29 ret = spi_setup(spi);
30 if (ret < 0)
31 return ret;
32
33 regmap = devm_regmap_init_spi(spi, &tlv320aic23_regmap);
34 return tlv320aic23_probe(&spi->dev, regmap);
35}
36
37static int aic23_spi_remove(struct spi_device *spi)
38{
39 snd_soc_unregister_codec(&spi->dev);
40 return 0;
41}
42
43static struct spi_driver aic23_spi = {
44 .driver = {
45 .name = "tlv320aic23",
46 .owner = THIS_MODULE,
47 },
48 .probe = aic23_spi_probe,
49 .remove = aic23_spi_remove,
50};
51
52module_spi_driver(aic23_spi);
53
54MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver SPI");
55MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
56MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index 5d430cc56f51..20864ee8793b 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/pm.h> 25#include <linux/pm.h>
26#include <linux/i2c.h>
27#include <linux/regmap.h> 26#include <linux/regmap.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include <sound/core.h> 28#include <sound/core.h>
@@ -51,7 +50,7 @@ static const struct reg_default tlv320aic23_reg[] = {
51 { 9, 0x0000 }, 50 { 9, 0x0000 },
52}; 51};
53 52
54static const struct regmap_config tlv320aic23_regmap = { 53const struct regmap_config tlv320aic23_regmap = {
55 .reg_bits = 7, 54 .reg_bits = 7,
56 .val_bits = 9, 55 .val_bits = 9,
57 56
@@ -60,20 +59,21 @@ static const struct regmap_config tlv320aic23_regmap = {
60 .num_reg_defaults = ARRAY_SIZE(tlv320aic23_reg), 59 .num_reg_defaults = ARRAY_SIZE(tlv320aic23_reg),
61 .cache_type = REGCACHE_RBTREE, 60 .cache_type = REGCACHE_RBTREE,
62}; 61};
62EXPORT_SYMBOL(tlv320aic23_regmap);
63 63
64static const char *rec_src_text[] = { "Line", "Mic" }; 64static const char *rec_src_text[] = { "Line", "Mic" };
65static const char *deemph_text[] = {"None", "32Khz", "44.1Khz", "48Khz"}; 65static const char *deemph_text[] = {"None", "32Khz", "44.1Khz", "48Khz"};
66 66
67static const struct soc_enum rec_src_enum = 67static SOC_ENUM_SINGLE_DECL(rec_src_enum,
68 SOC_ENUM_SINGLE(TLV320AIC23_ANLG, 2, 2, rec_src_text); 68 TLV320AIC23_ANLG, 2, rec_src_text);
69 69
70static const struct snd_kcontrol_new tlv320aic23_rec_src_mux_controls = 70static const struct snd_kcontrol_new tlv320aic23_rec_src_mux_controls =
71SOC_DAPM_ENUM("Input Select", rec_src_enum); 71SOC_DAPM_ENUM("Input Select", rec_src_enum);
72 72
73static const struct soc_enum tlv320aic23_rec_src = 73static SOC_ENUM_SINGLE_DECL(tlv320aic23_rec_src,
74 SOC_ENUM_SINGLE(TLV320AIC23_ANLG, 2, 2, rec_src_text); 74 TLV320AIC23_ANLG, 2, rec_src_text);
75static const struct soc_enum tlv320aic23_deemph = 75static SOC_ENUM_SINGLE_DECL(tlv320aic23_deemph,
76 SOC_ENUM_SINGLE(TLV320AIC23_DIGT, 1, 4, deemph_text); 76 TLV320AIC23_DIGT, 1, deemph_text);
77 77
78static const DECLARE_TLV_DB_SCALE(out_gain_tlv, -12100, 100, 0); 78static const DECLARE_TLV_DB_SCALE(out_gain_tlv, -12100, 100, 0);
79static const DECLARE_TLV_DB_SCALE(input_gain_tlv, -1725, 75, 0); 79static const DECLARE_TLV_DB_SCALE(input_gain_tlv, -1725, 75, 0);
@@ -400,7 +400,7 @@ static void tlv320aic23_shutdown(struct snd_pcm_substream *substream,
400 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec); 400 struct aic23 *aic23 = snd_soc_codec_get_drvdata(codec);
401 401
402 /* deactivate */ 402 /* deactivate */
403 if (!codec->active) { 403 if (!snd_soc_codec_is_active(codec)) {
404 udelay(50); 404 udelay(50);
405 snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0); 405 snd_soc_write(codec, TLV320AIC23_ACTIVE, 0x0);
406 } 406 }
@@ -557,16 +557,8 @@ static int tlv320aic23_resume(struct snd_soc_codec *codec)
557 return 0; 557 return 0;
558} 558}
559 559
560static int tlv320aic23_probe(struct snd_soc_codec *codec) 560static int tlv320aic23_codec_probe(struct snd_soc_codec *codec)
561{ 561{
562 int ret;
563
564 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
565 if (ret < 0) {
566 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
567 return ret;
568 }
569
570 /* Reset codec */ 562 /* Reset codec */
571 snd_soc_write(codec, TLV320AIC23_RESET, 0); 563 snd_soc_write(codec, TLV320AIC23_RESET, 0);
572 564
@@ -604,7 +596,7 @@ static int tlv320aic23_remove(struct snd_soc_codec *codec)
604} 596}
605 597
606static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = { 598static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = {
607 .probe = tlv320aic23_probe, 599 .probe = tlv320aic23_codec_probe,
608 .remove = tlv320aic23_remove, 600 .remove = tlv320aic23_remove,
609 .suspend = tlv320aic23_suspend, 601 .suspend = tlv320aic23_suspend,
610 .resume = tlv320aic23_resume, 602 .resume = tlv320aic23_resume,
@@ -617,56 +609,25 @@ static struct snd_soc_codec_driver soc_codec_dev_tlv320aic23 = {
617 .num_dapm_routes = ARRAY_SIZE(tlv320aic23_intercon), 609 .num_dapm_routes = ARRAY_SIZE(tlv320aic23_intercon),
618}; 610};
619 611
620/* 612int tlv320aic23_probe(struct device *dev, struct regmap *regmap)
621 * If the i2c layer weren't so broken, we could pass this kind of data
622 * around
623 */
624static int tlv320aic23_codec_probe(struct i2c_client *i2c,
625 const struct i2c_device_id *i2c_id)
626{ 613{
627 struct aic23 *aic23; 614 struct aic23 *aic23;
628 int ret;
629 615
630 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 616 if (IS_ERR(regmap))
631 return -EINVAL; 617 return PTR_ERR(regmap);
632 618
633 aic23 = devm_kzalloc(&i2c->dev, sizeof(struct aic23), GFP_KERNEL); 619 aic23 = devm_kzalloc(dev, sizeof(struct aic23), GFP_KERNEL);
634 if (aic23 == NULL) 620 if (aic23 == NULL)
635 return -ENOMEM; 621 return -ENOMEM;
636 622
637 aic23->regmap = devm_regmap_init_i2c(i2c, &tlv320aic23_regmap); 623 aic23->regmap = regmap;
638 if (IS_ERR(aic23->regmap))
639 return PTR_ERR(aic23->regmap);
640 624
641 i2c_set_clientdata(i2c, aic23); 625 dev_set_drvdata(dev, aic23);
642 626
643 ret = snd_soc_register_codec(&i2c->dev, 627 return snd_soc_register_codec(dev, &soc_codec_dev_tlv320aic23,
644 &soc_codec_dev_tlv320aic23, &tlv320aic23_dai, 1); 628 &tlv320aic23_dai, 1);
645 return ret;
646} 629}
647static int __exit tlv320aic23_i2c_remove(struct i2c_client *i2c) 630EXPORT_SYMBOL(tlv320aic23_probe);
648{
649 snd_soc_unregister_codec(&i2c->dev);
650 return 0;
651}
652
653static const struct i2c_device_id tlv320aic23_id[] = {
654 {"tlv320aic23", 0},
655 {}
656};
657
658MODULE_DEVICE_TABLE(i2c, tlv320aic23_id);
659
660static struct i2c_driver tlv320aic23_i2c_driver = {
661 .driver = {
662 .name = "tlv320aic23-codec",
663 },
664 .probe = tlv320aic23_codec_probe,
665 .remove = __exit_p(tlv320aic23_i2c_remove),
666 .id_table = tlv320aic23_id,
667};
668
669module_i2c_driver(tlv320aic23_i2c_driver);
670 631
671MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver"); 632MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver");
672MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>"); 633MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
diff --git a/sound/soc/codecs/tlv320aic23.h b/sound/soc/codecs/tlv320aic23.h
index e804120bd3da..3a7235a04a89 100644
--- a/sound/soc/codecs/tlv320aic23.h
+++ b/sound/soc/codecs/tlv320aic23.h
@@ -12,6 +12,12 @@
12#ifndef _TLV320AIC23_H 12#ifndef _TLV320AIC23_H
13#define _TLV320AIC23_H 13#define _TLV320AIC23_H
14 14
15struct device;
16struct regmap_config;
17
18extern const struct regmap_config tlv320aic23_regmap;
19int tlv320aic23_probe(struct device *dev, struct regmap *regmap);
20
15/* Codec TLV320AIC23 */ 21/* Codec TLV320AIC23 */
16#define TLV320AIC23_LINVOL 0x00 22#define TLV320AIC23_LINVOL 0x00
17#define TLV320AIC23_RINVOL 0x01 23#define TLV320AIC23_RINVOL 0x01
diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index 94a658fa6d97..43069de3d56a 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -238,8 +238,9 @@ static struct snd_soc_dai_driver aic26_dai = {
238 * ALSA controls 238 * ALSA controls
239 */ 239 */
240static const char *aic26_capture_src_text[] = {"Mic", "Aux"}; 240static const char *aic26_capture_src_text[] = {"Mic", "Aux"};
241static const struct soc_enum aic26_capture_src_enum = 241static SOC_ENUM_SINGLE_DECL(aic26_capture_src_enum,
242 SOC_ENUM_SINGLE(AIC26_REG_AUDIO_CTRL1, 12, 2, aic26_capture_src_text); 242 AIC26_REG_AUDIO_CTRL1, 12,
243 aic26_capture_src_text);
243 244
244static const struct snd_kcontrol_new aic26_snd_controls[] = { 245static const struct snd_kcontrol_new aic26_snd_controls[] = {
245 /* Output */ 246 /* Output */
@@ -295,8 +296,6 @@ static int aic26_probe(struct snd_soc_codec *codec)
295 struct aic26 *aic26 = dev_get_drvdata(codec->dev); 296 struct aic26 *aic26 = dev_get_drvdata(codec->dev);
296 int ret, reg; 297 int ret, reg;
297 298
298 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
299
300 aic26->codec = codec; 299 aic26->codec = codec;
301 300
302 /* Reset the codec to power on defaults */ 301 /* Reset the codec to power on defaults */
diff --git a/sound/soc/codecs/tlv320aic31xx.c b/sound/soc/codecs/tlv320aic31xx.c
new file mode 100644
index 000000000000..fa158cfe9b32
--- /dev/null
+++ b/sound/soc/codecs/tlv320aic31xx.c
@@ -0,0 +1,1280 @@
1/*
2 * ALSA SoC TLV320AIC31XX codec driver
3 *
4 * Copyright (C) 2014 Texas Instruments, Inc.
5 *
6 * Author: Jyri Sarha <jsarha@ti.com>
7 *
8 * Based on ground work by: Ajit Kulkarni <x0175765@ti.com>
9 *
10 * This package 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 * THIS PACKAGE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 *
18 * The TLV320AIC31xx series of audio codec is a low-power, highly integrated
19 * high performance codec which provides a stereo DAC, a mono ADC,
20 * and mono/stereo Class-D speaker driver.
21 */
22
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/init.h>
26#include <linux/delay.h>
27#include <linux/pm.h>
28#include <linux/i2c.h>
29#include <linux/gpio.h>
30#include <linux/regulator/consumer.h>
31#include <linux/of_gpio.h>
32#include <linux/slab.h>
33#include <sound/core.h>
34#include <sound/pcm.h>
35#include <sound/pcm_params.h>
36#include <sound/soc.h>
37#include <sound/initval.h>
38#include <sound/tlv.h>
39#include <dt-bindings/sound/tlv320aic31xx-micbias.h>
40
41#include "tlv320aic31xx.h"
42
43static const struct reg_default aic31xx_reg_defaults[] = {
44 { AIC31XX_CLKMUX, 0x00 },
45 { AIC31XX_PLLPR, 0x11 },
46 { AIC31XX_PLLJ, 0x04 },
47 { AIC31XX_PLLDMSB, 0x00 },
48 { AIC31XX_PLLDLSB, 0x00 },
49 { AIC31XX_NDAC, 0x01 },
50 { AIC31XX_MDAC, 0x01 },
51 { AIC31XX_DOSRMSB, 0x00 },
52 { AIC31XX_DOSRLSB, 0x80 },
53 { AIC31XX_NADC, 0x01 },
54 { AIC31XX_MADC, 0x01 },
55 { AIC31XX_AOSR, 0x80 },
56 { AIC31XX_IFACE1, 0x00 },
57 { AIC31XX_DATA_OFFSET, 0x00 },
58 { AIC31XX_IFACE2, 0x00 },
59 { AIC31XX_BCLKN, 0x01 },
60 { AIC31XX_DACSETUP, 0x14 },
61 { AIC31XX_DACMUTE, 0x0c },
62 { AIC31XX_LDACVOL, 0x00 },
63 { AIC31XX_RDACVOL, 0x00 },
64 { AIC31XX_ADCSETUP, 0x00 },
65 { AIC31XX_ADCFGA, 0x80 },
66 { AIC31XX_ADCVOL, 0x00 },
67 { AIC31XX_HPDRIVER, 0x04 },
68 { AIC31XX_SPKAMP, 0x06 },
69 { AIC31XX_DACMIXERROUTE, 0x00 },
70 { AIC31XX_LANALOGHPL, 0x7f },
71 { AIC31XX_RANALOGHPR, 0x7f },
72 { AIC31XX_LANALOGSPL, 0x7f },
73 { AIC31XX_RANALOGSPR, 0x7f },
74 { AIC31XX_HPLGAIN, 0x02 },
75 { AIC31XX_HPRGAIN, 0x02 },
76 { AIC31XX_SPLGAIN, 0x00 },
77 { AIC31XX_SPRGAIN, 0x00 },
78 { AIC31XX_MICBIAS, 0x00 },
79 { AIC31XX_MICPGA, 0x80 },
80 { AIC31XX_MICPGAPI, 0x00 },
81 { AIC31XX_MICPGAMI, 0x00 },
82};
83
84static bool aic31xx_volatile(struct device *dev, unsigned int reg)
85{
86 switch (reg) {
87 case AIC31XX_PAGECTL: /* regmap implementation requires this */
88 case AIC31XX_RESET: /* always clears after write */
89 case AIC31XX_OT_FLAG:
90 case AIC31XX_ADCFLAG:
91 case AIC31XX_DACFLAG1:
92 case AIC31XX_DACFLAG2:
93 case AIC31XX_OFFLAG: /* Sticky interrupt flags */
94 case AIC31XX_INTRDACFLAG: /* Sticky interrupt flags */
95 case AIC31XX_INTRADCFLAG: /* Sticky interrupt flags */
96 case AIC31XX_INTRDACFLAG2:
97 case AIC31XX_INTRADCFLAG2:
98 return true;
99 }
100 return false;
101}
102
103static bool aic31xx_writeable(struct device *dev, unsigned int reg)
104{
105 switch (reg) {
106 case AIC31XX_OT_FLAG:
107 case AIC31XX_ADCFLAG:
108 case AIC31XX_DACFLAG1:
109 case AIC31XX_DACFLAG2:
110 case AIC31XX_OFFLAG: /* Sticky interrupt flags */
111 case AIC31XX_INTRDACFLAG: /* Sticky interrupt flags */
112 case AIC31XX_INTRADCFLAG: /* Sticky interrupt flags */
113 case AIC31XX_INTRDACFLAG2:
114 case AIC31XX_INTRADCFLAG2:
115 return false;
116 }
117 return true;
118}
119
120static const struct regmap_range_cfg aic31xx_ranges[] = {
121 {
122 .range_min = 0,
123 .range_max = 12 * 128,
124 .selector_reg = AIC31XX_PAGECTL,
125 .selector_mask = 0xff,
126 .selector_shift = 0,
127 .window_start = 0,
128 .window_len = 128,
129 },
130};
131
132static const struct regmap_config aic31xx_i2c_regmap = {
133 .reg_bits = 8,
134 .val_bits = 8,
135 .writeable_reg = aic31xx_writeable,
136 .volatile_reg = aic31xx_volatile,
137 .reg_defaults = aic31xx_reg_defaults,
138 .num_reg_defaults = ARRAY_SIZE(aic31xx_reg_defaults),
139 .cache_type = REGCACHE_RBTREE,
140 .ranges = aic31xx_ranges,
141 .num_ranges = ARRAY_SIZE(aic31xx_ranges),
142 .max_register = 12 * 128,
143};
144
145#define AIC31XX_NUM_SUPPLIES 6
146static const char * const aic31xx_supply_names[AIC31XX_NUM_SUPPLIES] = {
147 "HPVDD",
148 "SPRVDD",
149 "SPLVDD",
150 "AVDD",
151 "IOVDD",
152 "DVDD",
153};
154
155struct aic31xx_disable_nb {
156 struct notifier_block nb;
157 struct aic31xx_priv *aic31xx;
158};
159
160struct aic31xx_priv {
161 struct snd_soc_codec *codec;
162 u8 i2c_regs_status;
163 struct device *dev;
164 struct regmap *regmap;
165 struct aic31xx_pdata pdata;
166 struct regulator_bulk_data supplies[AIC31XX_NUM_SUPPLIES];
167 struct aic31xx_disable_nb disable_nb[AIC31XX_NUM_SUPPLIES];
168 unsigned int sysclk;
169 int rate_div_line;
170};
171
172struct aic31xx_rate_divs {
173 u32 mclk;
174 u32 rate;
175 u8 p_val;
176 u8 pll_j;
177 u16 pll_d;
178 u16 dosr;
179 u8 ndac;
180 u8 mdac;
181 u8 aosr;
182 u8 nadc;
183 u8 madc;
184};
185
186/* ADC dividers can be disabled by cofiguring them to 0 */
187static const struct aic31xx_rate_divs aic31xx_divs[] = {
188 /* mclk rate pll: p j d dosr ndac mdac aors nadc madc */
189 /* 8k rate */
190 {12000000, 8000, 1, 8, 1920, 128, 48, 2, 128, 48, 2},
191 {24000000, 8000, 2, 8, 1920, 128, 48, 2, 128, 48, 2},
192 {25000000, 8000, 2, 7, 8643, 128, 48, 2, 128, 48, 2},
193 /* 11.025k rate */
194 {12000000, 11025, 1, 7, 5264, 128, 32, 2, 128, 32, 2},
195 {24000000, 11025, 2, 7, 5264, 128, 32, 2, 128, 32, 2},
196 {25000000, 11025, 2, 7, 2253, 128, 32, 2, 128, 32, 2},
197 /* 16k rate */
198 {12000000, 16000, 1, 8, 1920, 128, 24, 2, 128, 24, 2},
199 {24000000, 16000, 2, 8, 1920, 128, 24, 2, 128, 24, 2},
200 {25000000, 16000, 2, 7, 8643, 128, 24, 2, 128, 24, 2},
201 /* 22.05k rate */
202 {12000000, 22050, 1, 7, 5264, 128, 16, 2, 128, 16, 2},
203 {24000000, 22050, 2, 7, 5264, 128, 16, 2, 128, 16, 2},
204 {25000000, 22050, 2, 7, 2253, 128, 16, 2, 128, 16, 2},
205 /* 32k rate */
206 {12000000, 32000, 1, 8, 1920, 128, 12, 2, 128, 12, 2},
207 {24000000, 32000, 2, 8, 1920, 128, 12, 2, 128, 12, 2},
208 {25000000, 32000, 2, 7, 8643, 128, 12, 2, 128, 12, 2},
209 /* 44.1k rate */
210 {12000000, 44100, 1, 7, 5264, 128, 8, 2, 128, 8, 2},
211 {24000000, 44100, 2, 7, 5264, 128, 8, 2, 128, 8, 2},
212 {25000000, 44100, 2, 7, 2253, 128, 8, 2, 128, 8, 2},
213 /* 48k rate */
214 {12000000, 48000, 1, 8, 1920, 128, 8, 2, 128, 8, 2},
215 {24000000, 48000, 2, 8, 1920, 128, 8, 2, 128, 8, 2},
216 {25000000, 48000, 2, 7, 8643, 128, 8, 2, 128, 8, 2},
217 /* 88.2k rate */
218 {12000000, 88200, 1, 7, 5264, 64, 8, 2, 64, 8, 2},
219 {24000000, 88200, 2, 7, 5264, 64, 8, 2, 64, 8, 2},
220 {25000000, 88200, 2, 7, 2253, 64, 8, 2, 64, 8, 2},
221 /* 96k rate */
222 {12000000, 96000, 1, 8, 1920, 64, 8, 2, 64, 8, 2},
223 {24000000, 96000, 2, 8, 1920, 64, 8, 2, 64, 8, 2},
224 {25000000, 96000, 2, 7, 8643, 64, 8, 2, 64, 8, 2},
225 /* 176.4k rate */
226 {12000000, 176400, 1, 7, 5264, 32, 8, 2, 32, 8, 2},
227 {24000000, 176400, 2, 7, 5264, 32, 8, 2, 32, 8, 2},
228 {25000000, 176400, 2, 7, 2253, 32, 8, 2, 32, 8, 2},
229 /* 192k rate */
230 {12000000, 192000, 1, 8, 1920, 32, 8, 2, 32, 8, 2},
231 {24000000, 192000, 2, 8, 1920, 32, 8, 2, 32, 8, 2},
232 {25000000, 192000, 2, 7, 8643, 32, 8, 2, 32, 8, 2},
233};
234
235static const char * const ldac_in_text[] = {
236 "Off", "Left Data", "Right Data", "Mono"
237};
238
239static const char * const rdac_in_text[] = {
240 "Off", "Right Data", "Left Data", "Mono"
241};
242
243static SOC_ENUM_SINGLE_DECL(ldac_in_enum, AIC31XX_DACSETUP, 4, ldac_in_text);
244
245static SOC_ENUM_SINGLE_DECL(rdac_in_enum, AIC31XX_DACSETUP, 2, rdac_in_text);
246
247static const char * const mic_select_text[] = {
248 "Off", "FFR 10 Ohm", "FFR 20 Ohm", "FFR 40 Ohm"
249};
250
251static const
252SOC_ENUM_SINGLE_DECL(mic1lp_p_enum, AIC31XX_MICPGAPI, 6, mic_select_text);
253static const
254SOC_ENUM_SINGLE_DECL(mic1rp_p_enum, AIC31XX_MICPGAPI, 4, mic_select_text);
255static const
256SOC_ENUM_SINGLE_DECL(mic1lm_p_enum, AIC31XX_MICPGAPI, 2, mic_select_text);
257
258static const
259SOC_ENUM_SINGLE_DECL(cm_m_enum, AIC31XX_MICPGAMI, 6, mic_select_text);
260static const
261SOC_ENUM_SINGLE_DECL(mic1lm_m_enum, AIC31XX_MICPGAMI, 4, mic_select_text);
262
263static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6350, 50, 0);
264static const DECLARE_TLV_DB_SCALE(adc_fgain_tlv, 0, 10, 0);
265static const DECLARE_TLV_DB_SCALE(adc_cgain_tlv, -2000, 50, 0);
266static const DECLARE_TLV_DB_SCALE(mic_pga_tlv, 0, 50, 0);
267static const DECLARE_TLV_DB_SCALE(hp_drv_tlv, 0, 100, 0);
268static const DECLARE_TLV_DB_SCALE(class_D_drv_tlv, 600, 600, 0);
269static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -6350, 50, 0);
270static const DECLARE_TLV_DB_SCALE(sp_vol_tlv, -6350, 50, 0);
271
272/*
273 * controls to be exported to the user space
274 */
275static const struct snd_kcontrol_new aic31xx_snd_controls[] = {
276 SOC_DOUBLE_R_S_TLV("DAC Playback Volume", AIC31XX_LDACVOL,
277 AIC31XX_RDACVOL, 0, -127, 48, 7, 0, dac_vol_tlv),
278
279 SOC_SINGLE_TLV("ADC Fine Capture Volume", AIC31XX_ADCFGA, 4, 4, 1,
280 adc_fgain_tlv),
281
282 SOC_SINGLE("ADC Capture Switch", AIC31XX_ADCFGA, 7, 1, 1),
283 SOC_DOUBLE_R_S_TLV("ADC Capture Volume", AIC31XX_ADCVOL, AIC31XX_ADCVOL,
284 0, -24, 40, 6, 0, adc_cgain_tlv),
285
286 SOC_SINGLE_TLV("Mic PGA Capture Volume", AIC31XX_MICPGA, 0,
287 119, 0, mic_pga_tlv),
288
289 SOC_DOUBLE_R("HP Driver Playback Switch", AIC31XX_HPLGAIN,
290 AIC31XX_HPRGAIN, 2, 1, 0),
291 SOC_DOUBLE_R_TLV("HP Driver Playback Volume", AIC31XX_HPLGAIN,
292 AIC31XX_HPRGAIN, 3, 0x09, 0, hp_drv_tlv),
293
294 SOC_DOUBLE_R_TLV("HP Analog Playback Volume", AIC31XX_LANALOGHPL,
295 AIC31XX_RANALOGHPR, 0, 0x7F, 1, hp_vol_tlv),
296};
297
298static const struct snd_kcontrol_new aic311x_snd_controls[] = {
299 SOC_DOUBLE_R("Speaker Driver Playback Switch", AIC31XX_SPLGAIN,
300 AIC31XX_SPRGAIN, 2, 1, 0),
301 SOC_DOUBLE_R_TLV("Speaker Driver Playback Volume", AIC31XX_SPLGAIN,
302 AIC31XX_SPRGAIN, 3, 3, 0, class_D_drv_tlv),
303
304 SOC_DOUBLE_R_TLV("Speaker Analog Playback Volume", AIC31XX_LANALOGSPL,
305 AIC31XX_RANALOGSPR, 0, 0x7F, 1, sp_vol_tlv),
306};
307
308static const struct snd_kcontrol_new aic310x_snd_controls[] = {
309 SOC_SINGLE("Speaker Driver Playback Switch", AIC31XX_SPLGAIN,
310 2, 1, 0),
311 SOC_SINGLE_TLV("Speaker Driver Playback Volume", AIC31XX_SPLGAIN,
312 3, 3, 0, class_D_drv_tlv),
313
314 SOC_SINGLE_TLV("Speaker Analog Playback Volume", AIC31XX_LANALOGSPL,
315 0, 0x7F, 1, sp_vol_tlv),
316};
317
318static const struct snd_kcontrol_new ldac_in_control =
319 SOC_DAPM_ENUM("DAC Left Input", ldac_in_enum);
320
321static const struct snd_kcontrol_new rdac_in_control =
322 SOC_DAPM_ENUM("DAC Right Input", rdac_in_enum);
323
324static int aic31xx_wait_bits(struct aic31xx_priv *aic31xx, unsigned int reg,
325 unsigned int mask, unsigned int wbits, int sleep,
326 int count)
327{
328 unsigned int bits;
329 int counter = count;
330 int ret = regmap_read(aic31xx->regmap, reg, &bits);
331 while ((bits & mask) != wbits && counter && !ret) {
332 usleep_range(sleep, sleep * 2);
333 ret = regmap_read(aic31xx->regmap, reg, &bits);
334 counter--;
335 }
336 if ((bits & mask) != wbits) {
337 dev_err(aic31xx->dev,
338 "%s: Failed! 0x%x was 0x%x expected 0x%x (%d, 0x%x, %d us)\n",
339 __func__, reg, bits, wbits, ret, mask,
340 (count - counter) * sleep);
341 ret = -1;
342 }
343 return ret;
344}
345
346#define WIDGET_BIT(reg, shift) (((shift) << 8) | (reg))
347
348static int aic31xx_dapm_power_event(struct snd_soc_dapm_widget *w,
349 struct snd_kcontrol *kcontrol, int event)
350{
351 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(w->codec);
352 unsigned int reg = AIC31XX_DACFLAG1;
353 unsigned int mask;
354
355 switch (WIDGET_BIT(w->reg, w->shift)) {
356 case WIDGET_BIT(AIC31XX_DACSETUP, 7):
357 mask = AIC31XX_LDACPWRSTATUS_MASK;
358 break;
359 case WIDGET_BIT(AIC31XX_DACSETUP, 6):
360 mask = AIC31XX_RDACPWRSTATUS_MASK;
361 break;
362 case WIDGET_BIT(AIC31XX_HPDRIVER, 7):
363 mask = AIC31XX_HPLDRVPWRSTATUS_MASK;
364 break;
365 case WIDGET_BIT(AIC31XX_HPDRIVER, 6):
366 mask = AIC31XX_HPRDRVPWRSTATUS_MASK;
367 break;
368 case WIDGET_BIT(AIC31XX_SPKAMP, 7):
369 mask = AIC31XX_SPLDRVPWRSTATUS_MASK;
370 break;
371 case WIDGET_BIT(AIC31XX_SPKAMP, 6):
372 mask = AIC31XX_SPRDRVPWRSTATUS_MASK;
373 break;
374 case WIDGET_BIT(AIC31XX_ADCSETUP, 7):
375 mask = AIC31XX_ADCPWRSTATUS_MASK;
376 reg = AIC31XX_ADCFLAG;
377 break;
378 default:
379 dev_err(w->codec->dev, "Unknown widget '%s' calling %s/n",
380 w->name, __func__);
381 return -EINVAL;
382 }
383
384 switch (event) {
385 case SND_SOC_DAPM_POST_PMU:
386 return aic31xx_wait_bits(aic31xx, reg, mask, mask, 5000, 100);
387 case SND_SOC_DAPM_POST_PMD:
388 return aic31xx_wait_bits(aic31xx, reg, mask, 0, 5000, 100);
389 default:
390 dev_dbg(w->codec->dev,
391 "Unhandled dapm widget event %d from %s\n",
392 event, w->name);
393 }
394 return 0;
395}
396
397static const struct snd_kcontrol_new left_output_switches[] = {
398 SOC_DAPM_SINGLE("From Left DAC", AIC31XX_DACMIXERROUTE, 6, 1, 0),
399 SOC_DAPM_SINGLE("From MIC1LP", AIC31XX_DACMIXERROUTE, 5, 1, 0),
400 SOC_DAPM_SINGLE("From MIC1RP", AIC31XX_DACMIXERROUTE, 4, 1, 0),
401};
402
403static const struct snd_kcontrol_new right_output_switches[] = {
404 SOC_DAPM_SINGLE("From Right DAC", AIC31XX_DACMIXERROUTE, 2, 1, 0),
405 SOC_DAPM_SINGLE("From MIC1RP", AIC31XX_DACMIXERROUTE, 1, 1, 0),
406};
407
408static const struct snd_kcontrol_new p_term_mic1lp =
409 SOC_DAPM_ENUM("MIC1LP P-Terminal", mic1lp_p_enum);
410
411static const struct snd_kcontrol_new p_term_mic1rp =
412 SOC_DAPM_ENUM("MIC1RP P-Terminal", mic1rp_p_enum);
413
414static const struct snd_kcontrol_new p_term_mic1lm =
415 SOC_DAPM_ENUM("MIC1LM P-Terminal", mic1lm_p_enum);
416
417static const struct snd_kcontrol_new m_term_mic1lm =
418 SOC_DAPM_ENUM("MIC1LM M-Terminal", mic1lm_m_enum);
419
420static const struct snd_kcontrol_new aic31xx_dapm_hpl_switch =
421 SOC_DAPM_SINGLE("Switch", AIC31XX_LANALOGHPL, 7, 1, 0);
422
423static const struct snd_kcontrol_new aic31xx_dapm_hpr_switch =
424 SOC_DAPM_SINGLE("Switch", AIC31XX_RANALOGHPR, 7, 1, 0);
425
426static const struct snd_kcontrol_new aic31xx_dapm_spl_switch =
427 SOC_DAPM_SINGLE("Switch", AIC31XX_LANALOGSPL, 7, 1, 0);
428
429static const struct snd_kcontrol_new aic31xx_dapm_spr_switch =
430 SOC_DAPM_SINGLE("Switch", AIC31XX_RANALOGSPR, 7, 1, 0);
431
432static int mic_bias_event(struct snd_soc_dapm_widget *w,
433 struct snd_kcontrol *kcontrol, int event)
434{
435 struct snd_soc_codec *codec = w->codec;
436 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
437 switch (event) {
438 case SND_SOC_DAPM_POST_PMU:
439 /* change mic bias voltage to user defined */
440 snd_soc_update_bits(codec, AIC31XX_MICBIAS,
441 AIC31XX_MICBIAS_MASK,
442 aic31xx->pdata.micbias_vg <<
443 AIC31XX_MICBIAS_SHIFT);
444 dev_dbg(codec->dev, "%s: turned on\n", __func__);
445 break;
446 case SND_SOC_DAPM_PRE_PMD:
447 /* turn mic bias off */
448 snd_soc_update_bits(codec, AIC31XX_MICBIAS,
449 AIC31XX_MICBIAS_MASK, 0);
450 dev_dbg(codec->dev, "%s: turned off\n", __func__);
451 break;
452 }
453 return 0;
454}
455
456static const struct snd_soc_dapm_widget aic31xx_dapm_widgets[] = {
457 SND_SOC_DAPM_AIF_IN("DAC IN", "DAC Playback", 0, SND_SOC_NOPM, 0, 0),
458
459 SND_SOC_DAPM_MUX("DAC Left Input",
460 SND_SOC_NOPM, 0, 0, &ldac_in_control),
461 SND_SOC_DAPM_MUX("DAC Right Input",
462 SND_SOC_NOPM, 0, 0, &rdac_in_control),
463 /* DACs */
464 SND_SOC_DAPM_DAC_E("DAC Left", "Left Playback",
465 AIC31XX_DACSETUP, 7, 0, aic31xx_dapm_power_event,
466 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
467
468 SND_SOC_DAPM_DAC_E("DAC Right", "Right Playback",
469 AIC31XX_DACSETUP, 6, 0, aic31xx_dapm_power_event,
470 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
471
472 /* Output Mixers */
473 SND_SOC_DAPM_MIXER("Output Left", SND_SOC_NOPM, 0, 0,
474 left_output_switches,
475 ARRAY_SIZE(left_output_switches)),
476 SND_SOC_DAPM_MIXER("Output Right", SND_SOC_NOPM, 0, 0,
477 right_output_switches,
478 ARRAY_SIZE(right_output_switches)),
479
480 SND_SOC_DAPM_SWITCH("HP Left", SND_SOC_NOPM, 0, 0,
481 &aic31xx_dapm_hpl_switch),
482 SND_SOC_DAPM_SWITCH("HP Right", SND_SOC_NOPM, 0, 0,
483 &aic31xx_dapm_hpr_switch),
484
485 /* Output drivers */
486 SND_SOC_DAPM_OUT_DRV_E("HPL Driver", AIC31XX_HPDRIVER, 7, 0,
487 NULL, 0, aic31xx_dapm_power_event,
488 SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU),
489 SND_SOC_DAPM_OUT_DRV_E("HPR Driver", AIC31XX_HPDRIVER, 6, 0,
490 NULL, 0, aic31xx_dapm_power_event,
491 SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU),
492
493 /* ADC */
494 SND_SOC_DAPM_ADC_E("ADC", "Capture", AIC31XX_ADCSETUP, 7, 0,
495 aic31xx_dapm_power_event, SND_SOC_DAPM_POST_PMU |
496 SND_SOC_DAPM_POST_PMD),
497
498 /* Input Selection to MIC_PGA */
499 SND_SOC_DAPM_MUX("MIC1LP P-Terminal", SND_SOC_NOPM, 0, 0,
500 &p_term_mic1lp),
501 SND_SOC_DAPM_MUX("MIC1RP P-Terminal", SND_SOC_NOPM, 0, 0,
502 &p_term_mic1rp),
503 SND_SOC_DAPM_MUX("MIC1LM P-Terminal", SND_SOC_NOPM, 0, 0,
504 &p_term_mic1lm),
505
506 SND_SOC_DAPM_MUX("MIC1LM M-Terminal", SND_SOC_NOPM, 0, 0,
507 &m_term_mic1lm),
508 /* Enabling & Disabling MIC Gain Ctl */
509 SND_SOC_DAPM_PGA("MIC_GAIN_CTL", AIC31XX_MICPGA,
510 7, 1, NULL, 0),
511
512 /* Mic Bias */
513 SND_SOC_DAPM_SUPPLY("MICBIAS", SND_SOC_NOPM, 0, 0, mic_bias_event,
514 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
515
516 /* Outputs */
517 SND_SOC_DAPM_OUTPUT("HPL"),
518 SND_SOC_DAPM_OUTPUT("HPR"),
519
520 /* Inputs */
521 SND_SOC_DAPM_INPUT("MIC1LP"),
522 SND_SOC_DAPM_INPUT("MIC1RP"),
523 SND_SOC_DAPM_INPUT("MIC1LM"),
524};
525
526static const struct snd_soc_dapm_widget aic311x_dapm_widgets[] = {
527 /* AIC3111 and AIC3110 have stereo class-D amplifier */
528 SND_SOC_DAPM_OUT_DRV_E("SPL ClassD", AIC31XX_SPKAMP, 7, 0, NULL, 0,
529 aic31xx_dapm_power_event, SND_SOC_DAPM_POST_PMU |
530 SND_SOC_DAPM_POST_PMD),
531 SND_SOC_DAPM_OUT_DRV_E("SPR ClassD", AIC31XX_SPKAMP, 6, 0, NULL, 0,
532 aic31xx_dapm_power_event, SND_SOC_DAPM_POST_PMU |
533 SND_SOC_DAPM_POST_PMD),
534 SND_SOC_DAPM_SWITCH("Speaker Left", SND_SOC_NOPM, 0, 0,
535 &aic31xx_dapm_spl_switch),
536 SND_SOC_DAPM_SWITCH("Speaker Right", SND_SOC_NOPM, 0, 0,
537 &aic31xx_dapm_spr_switch),
538 SND_SOC_DAPM_OUTPUT("SPL"),
539 SND_SOC_DAPM_OUTPUT("SPR"),
540};
541
542/* AIC3100 and AIC3120 have only mono class-D amplifier */
543static const struct snd_soc_dapm_widget aic310x_dapm_widgets[] = {
544 SND_SOC_DAPM_OUT_DRV_E("SPK ClassD", AIC31XX_SPKAMP, 7, 0, NULL, 0,
545 aic31xx_dapm_power_event, SND_SOC_DAPM_POST_PMU |
546 SND_SOC_DAPM_POST_PMD),
547 SND_SOC_DAPM_SWITCH("Speaker", SND_SOC_NOPM, 0, 0,
548 &aic31xx_dapm_spl_switch),
549 SND_SOC_DAPM_OUTPUT("SPK"),
550};
551
552static const struct snd_soc_dapm_route
553aic31xx_audio_map[] = {
554 /* DAC Input Routing */
555 {"DAC Left Input", "Left Data", "DAC IN"},
556 {"DAC Left Input", "Right Data", "DAC IN"},
557 {"DAC Left Input", "Mono", "DAC IN"},
558 {"DAC Right Input", "Left Data", "DAC IN"},
559 {"DAC Right Input", "Right Data", "DAC IN"},
560 {"DAC Right Input", "Mono", "DAC IN"},
561 {"DAC Left", NULL, "DAC Left Input"},
562 {"DAC Right", NULL, "DAC Right Input"},
563
564 /* Mic input */
565 {"MIC1LP P-Terminal", "FFR 10 Ohm", "MIC1LP"},
566 {"MIC1LP P-Terminal", "FFR 20 Ohm", "MIC1LP"},
567 {"MIC1LP P-Terminal", "FFR 40 Ohm", "MIC1LP"},
568 {"MIC1RP P-Terminal", "FFR 10 Ohm", "MIC1RP"},
569 {"MIC1RP P-Terminal", "FFR 20 Ohm", "MIC1RP"},
570 {"MIC1RP P-Terminal", "FFR 40 Ohm", "MIC1RP"},
571 {"MIC1LM P-Terminal", "FFR 10 Ohm", "MIC1LM"},
572 {"MIC1LM P-Terminal", "FFR 20 Ohm", "MIC1LM"},
573 {"MIC1LM P-Terminal", "FFR 40 Ohm", "MIC1LM"},
574
575 {"MIC1LM M-Terminal", "FFR 10 Ohm", "MIC1LM"},
576 {"MIC1LM M-Terminal", "FFR 20 Ohm", "MIC1LM"},
577 {"MIC1LM M-Terminal", "FFR 40 Ohm", "MIC1LM"},
578
579 {"MIC_GAIN_CTL", NULL, "MIC1LP P-Terminal"},
580 {"MIC_GAIN_CTL", NULL, "MIC1RP P-Terminal"},
581 {"MIC_GAIN_CTL", NULL, "MIC1LM P-Terminal"},
582 {"MIC_GAIN_CTL", NULL, "MIC1LM M-Terminal"},
583
584 {"ADC", NULL, "MIC_GAIN_CTL"},
585
586 /* Left Output */
587 {"Output Left", "From Left DAC", "DAC Left"},
588 {"Output Left", "From MIC1LP", "MIC1LP"},
589 {"Output Left", "From MIC1RP", "MIC1RP"},
590
591 /* Right Output */
592 {"Output Right", "From Right DAC", "DAC Right"},
593 {"Output Right", "From MIC1RP", "MIC1RP"},
594
595 /* HPL path */
596 {"HP Left", "Switch", "Output Left"},
597 {"HPL Driver", NULL, "HP Left"},
598 {"HPL", NULL, "HPL Driver"},
599
600 /* HPR path */
601 {"HP Right", "Switch", "Output Right"},
602 {"HPR Driver", NULL, "HP Right"},
603 {"HPR", NULL, "HPR Driver"},
604};
605
606static const struct snd_soc_dapm_route
607aic311x_audio_map[] = {
608 /* SP L path */
609 {"Speaker Left", "Switch", "Output Left"},
610 {"SPL ClassD", NULL, "Speaker Left"},
611 {"SPL", NULL, "SPL ClassD"},
612
613 /* SP R path */
614 {"Speaker Right", "Switch", "Output Right"},
615 {"SPR ClassD", NULL, "Speaker Right"},
616 {"SPR", NULL, "SPR ClassD"},
617};
618
619static const struct snd_soc_dapm_route
620aic310x_audio_map[] = {
621 /* SP L path */
622 {"Speaker", "Switch", "Output Left"},
623 {"SPK ClassD", NULL, "Speaker"},
624 {"SPK", NULL, "SPK ClassD"},
625};
626
627static int aic31xx_add_controls(struct snd_soc_codec *codec)
628{
629 int ret = 0;
630 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
631
632 if (aic31xx->pdata.codec_type & AIC31XX_STEREO_CLASS_D_BIT)
633 ret = snd_soc_add_codec_controls(
634 codec, aic311x_snd_controls,
635 ARRAY_SIZE(aic311x_snd_controls));
636 else
637 ret = snd_soc_add_codec_controls(
638 codec, aic310x_snd_controls,
639 ARRAY_SIZE(aic310x_snd_controls));
640
641 return ret;
642}
643
644static int aic31xx_add_widgets(struct snd_soc_codec *codec)
645{
646 struct snd_soc_dapm_context *dapm = &codec->dapm;
647 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
648 int ret = 0;
649
650 if (aic31xx->pdata.codec_type & AIC31XX_STEREO_CLASS_D_BIT) {
651 ret = snd_soc_dapm_new_controls(
652 dapm, aic311x_dapm_widgets,
653 ARRAY_SIZE(aic311x_dapm_widgets));
654 if (ret)
655 return ret;
656
657 ret = snd_soc_dapm_add_routes(dapm, aic311x_audio_map,
658 ARRAY_SIZE(aic311x_audio_map));
659 if (ret)
660 return ret;
661 } else {
662 ret = snd_soc_dapm_new_controls(
663 dapm, aic310x_dapm_widgets,
664 ARRAY_SIZE(aic310x_dapm_widgets));
665 if (ret)
666 return ret;
667
668 ret = snd_soc_dapm_add_routes(dapm, aic310x_audio_map,
669 ARRAY_SIZE(aic310x_audio_map));
670 if (ret)
671 return ret;
672 }
673
674 return 0;
675}
676
677static int aic31xx_setup_pll(struct snd_soc_codec *codec,
678 struct snd_pcm_hw_params *params)
679{
680 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
681 int bclk_n = 0;
682 int i;
683
684 /* Use PLL as CODEC_CLKIN and DAC_CLK as BDIV_CLKIN */
685 snd_soc_update_bits(codec, AIC31XX_CLKMUX,
686 AIC31XX_CODEC_CLKIN_MASK, AIC31XX_CODEC_CLKIN_PLL);
687 snd_soc_update_bits(codec, AIC31XX_IFACE2,
688 AIC31XX_BDIVCLK_MASK, AIC31XX_DAC2BCLK);
689
690 for (i = 0; i < ARRAY_SIZE(aic31xx_divs); i++) {
691 if (aic31xx_divs[i].rate == params_rate(params) &&
692 aic31xx_divs[i].mclk == aic31xx->sysclk)
693 break;
694 }
695
696 if (i == ARRAY_SIZE(aic31xx_divs)) {
697 dev_err(codec->dev, "%s: Sampling rate %u not supported\n",
698 __func__, params_rate(params));
699 return -EINVAL;
700 }
701
702 /* PLL configuration */
703 snd_soc_update_bits(codec, AIC31XX_PLLPR, AIC31XX_PLL_MASK,
704 (aic31xx_divs[i].p_val << 4) | 0x01);
705 snd_soc_write(codec, AIC31XX_PLLJ, aic31xx_divs[i].pll_j);
706
707 snd_soc_write(codec, AIC31XX_PLLDMSB,
708 aic31xx_divs[i].pll_d >> 8);
709 snd_soc_write(codec, AIC31XX_PLLDLSB,
710 aic31xx_divs[i].pll_d & 0xff);
711
712 /* DAC dividers configuration */
713 snd_soc_update_bits(codec, AIC31XX_NDAC, AIC31XX_PLL_MASK,
714 aic31xx_divs[i].ndac);
715 snd_soc_update_bits(codec, AIC31XX_MDAC, AIC31XX_PLL_MASK,
716 aic31xx_divs[i].mdac);
717
718 snd_soc_write(codec, AIC31XX_DOSRMSB, aic31xx_divs[i].dosr >> 8);
719 snd_soc_write(codec, AIC31XX_DOSRLSB, aic31xx_divs[i].dosr & 0xff);
720
721 /* ADC dividers configuration. Write reset value 1 if not used. */
722 snd_soc_update_bits(codec, AIC31XX_NADC, AIC31XX_PLL_MASK,
723 aic31xx_divs[i].nadc ? aic31xx_divs[i].nadc : 1);
724 snd_soc_update_bits(codec, AIC31XX_MADC, AIC31XX_PLL_MASK,
725 aic31xx_divs[i].madc ? aic31xx_divs[i].madc : 1);
726
727 snd_soc_write(codec, AIC31XX_AOSR, aic31xx_divs[i].aosr);
728
729 /* Bit clock divider configuration. */
730 bclk_n = (aic31xx_divs[i].dosr * aic31xx_divs[i].mdac)
731 / snd_soc_params_to_frame_size(params);
732 if (bclk_n == 0) {
733 dev_err(codec->dev, "%s: Not enough BLCK bandwidth\n",
734 __func__);
735 return -EINVAL;
736 }
737
738 snd_soc_update_bits(codec, AIC31XX_BCLKN,
739 AIC31XX_PLL_MASK, bclk_n);
740
741 aic31xx->rate_div_line = i;
742
743 dev_dbg(codec->dev,
744 "pll %d.%04d/%d dosr %d n %d m %d aosr %d n %d m %d bclk_n %d\n",
745 aic31xx_divs[i].pll_j, aic31xx_divs[i].pll_d,
746 aic31xx_divs[i].p_val, aic31xx_divs[i].dosr,
747 aic31xx_divs[i].ndac, aic31xx_divs[i].mdac,
748 aic31xx_divs[i].aosr, aic31xx_divs[i].nadc,
749 aic31xx_divs[i].madc, bclk_n);
750
751 return 0;
752}
753
754static int aic31xx_hw_params(struct snd_pcm_substream *substream,
755 struct snd_pcm_hw_params *params,
756 struct snd_soc_dai *dai)
757{
758 struct snd_soc_codec *codec = dai->codec;
759 u8 data = 0;
760
761 dev_dbg(codec->dev, "## %s: format %d width %d rate %d\n",
762 __func__, params_format(params), params_width(params),
763 params_rate(params));
764
765 switch (params_width(params)) {
766 case 16:
767 break;
768 case 20:
769 data = (AIC31XX_WORD_LEN_20BITS <<
770 AIC31XX_IFACE1_DATALEN_SHIFT);
771 break;
772 case 24:
773 data = (AIC31XX_WORD_LEN_24BITS <<
774 AIC31XX_IFACE1_DATALEN_SHIFT);
775 break;
776 case 32:
777 data = (AIC31XX_WORD_LEN_32BITS <<
778 AIC31XX_IFACE1_DATALEN_SHIFT);
779 break;
780 default:
781 dev_err(codec->dev, "%s: Unsupported format %d\n",
782 __func__, params_format(params));
783 return -EINVAL;
784 }
785
786 snd_soc_update_bits(codec, AIC31XX_IFACE1,
787 AIC31XX_IFACE1_DATALEN_MASK,
788 data);
789
790 return aic31xx_setup_pll(codec, params);
791}
792
793static int aic31xx_dac_mute(struct snd_soc_dai *codec_dai, int mute)
794{
795 struct snd_soc_codec *codec = codec_dai->codec;
796
797 if (mute) {
798 snd_soc_update_bits(codec, AIC31XX_DACMUTE,
799 AIC31XX_DACMUTE_MASK,
800 AIC31XX_DACMUTE_MASK);
801 } else {
802 snd_soc_update_bits(codec, AIC31XX_DACMUTE,
803 AIC31XX_DACMUTE_MASK, 0x0);
804 }
805
806 return 0;
807}
808
809static int aic31xx_set_dai_fmt(struct snd_soc_dai *codec_dai,
810 unsigned int fmt)
811{
812 struct snd_soc_codec *codec = codec_dai->codec;
813 u8 iface_reg1 = 0;
814 u8 iface_reg3 = 0;
815 u8 dsp_a_val = 0;
816
817 dev_dbg(codec->dev, "## %s: fmt = 0x%x\n", __func__, fmt);
818
819 /* set master/slave audio interface */
820 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
821 case SND_SOC_DAIFMT_CBM_CFM:
822 iface_reg1 |= AIC31XX_BCLK_MASTER | AIC31XX_WCLK_MASTER;
823 break;
824 default:
825 dev_alert(codec->dev, "Invalid DAI master/slave interface\n");
826 return -EINVAL;
827 }
828
829 /* interface format */
830 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
831 case SND_SOC_DAIFMT_I2S:
832 break;
833 case SND_SOC_DAIFMT_DSP_A:
834 dsp_a_val = 0x1;
835 case SND_SOC_DAIFMT_DSP_B:
836 /* NOTE: BCLKINV bit value 1 equas NB and 0 equals IB */
837 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
838 case SND_SOC_DAIFMT_NB_NF:
839 iface_reg3 |= AIC31XX_BCLKINV_MASK;
840 break;
841 case SND_SOC_DAIFMT_IB_NF:
842 break;
843 default:
844 return -EINVAL;
845 }
846 iface_reg1 |= (AIC31XX_DSP_MODE <<
847 AIC31XX_IFACE1_DATATYPE_SHIFT);
848 break;
849 case SND_SOC_DAIFMT_RIGHT_J:
850 iface_reg1 |= (AIC31XX_RIGHT_JUSTIFIED_MODE <<
851 AIC31XX_IFACE1_DATATYPE_SHIFT);
852 break;
853 case SND_SOC_DAIFMT_LEFT_J:
854 iface_reg1 |= (AIC31XX_LEFT_JUSTIFIED_MODE <<
855 AIC31XX_IFACE1_DATATYPE_SHIFT);
856 break;
857 default:
858 dev_err(codec->dev, "Invalid DAI interface format\n");
859 return -EINVAL;
860 }
861
862 snd_soc_update_bits(codec, AIC31XX_IFACE1,
863 AIC31XX_IFACE1_DATATYPE_MASK |
864 AIC31XX_IFACE1_MASTER_MASK,
865 iface_reg1);
866 snd_soc_update_bits(codec, AIC31XX_DATA_OFFSET,
867 AIC31XX_DATA_OFFSET_MASK,
868 dsp_a_val);
869 snd_soc_update_bits(codec, AIC31XX_IFACE2,
870 AIC31XX_BCLKINV_MASK,
871 iface_reg3);
872
873 return 0;
874}
875
876static int aic31xx_set_dai_sysclk(struct snd_soc_dai *codec_dai,
877 int clk_id, unsigned int freq, int dir)
878{
879 struct snd_soc_codec *codec = codec_dai->codec;
880 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
881 int i;
882
883 dev_dbg(codec->dev, "## %s: clk_id = %d, freq = %d, dir = %d\n",
884 __func__, clk_id, freq, dir);
885
886 for (i = 0; aic31xx_divs[i].mclk != freq; i++) {
887 if (i == ARRAY_SIZE(aic31xx_divs)) {
888 dev_err(aic31xx->dev, "%s: Unsupported frequency %d\n",
889 __func__, freq);
890 return -EINVAL;
891 }
892 }
893
894 /* set clock on MCLK, BCLK, or GPIO1 as PLL input */
895 snd_soc_update_bits(codec, AIC31XX_CLKMUX, AIC31XX_PLL_CLKIN_MASK,
896 clk_id << AIC31XX_PLL_CLKIN_SHIFT);
897
898 aic31xx->sysclk = freq;
899 return 0;
900}
901
902static int aic31xx_regulator_event(struct notifier_block *nb,
903 unsigned long event, void *data)
904{
905 struct aic31xx_disable_nb *disable_nb =
906 container_of(nb, struct aic31xx_disable_nb, nb);
907 struct aic31xx_priv *aic31xx = disable_nb->aic31xx;
908
909 if (event & REGULATOR_EVENT_DISABLE) {
910 /*
911 * Put codec to reset and as at least one of the
912 * supplies was disabled.
913 */
914 if (gpio_is_valid(aic31xx->pdata.gpio_reset))
915 gpio_set_value(aic31xx->pdata.gpio_reset, 0);
916
917 regcache_mark_dirty(aic31xx->regmap);
918 dev_dbg(aic31xx->dev, "## %s: DISABLE received\n", __func__);
919 }
920
921 return 0;
922}
923
924static void aic31xx_clk_on(struct snd_soc_codec *codec)
925{
926 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
927 u8 mask = AIC31XX_PM_MASK;
928 u8 on = AIC31XX_PM_MASK;
929
930 dev_dbg(codec->dev, "codec clock -> on (rate %d)\n",
931 aic31xx_divs[aic31xx->rate_div_line].rate);
932 snd_soc_update_bits(codec, AIC31XX_PLLPR, mask, on);
933 mdelay(10);
934 snd_soc_update_bits(codec, AIC31XX_NDAC, mask, on);
935 snd_soc_update_bits(codec, AIC31XX_MDAC, mask, on);
936 if (aic31xx_divs[aic31xx->rate_div_line].nadc)
937 snd_soc_update_bits(codec, AIC31XX_NADC, mask, on);
938 if (aic31xx_divs[aic31xx->rate_div_line].madc)
939 snd_soc_update_bits(codec, AIC31XX_MADC, mask, on);
940 snd_soc_update_bits(codec, AIC31XX_BCLKN, mask, on);
941}
942
943static void aic31xx_clk_off(struct snd_soc_codec *codec)
944{
945 u8 mask = AIC31XX_PM_MASK;
946 u8 off = 0;
947
948 dev_dbg(codec->dev, "codec clock -> off\n");
949 snd_soc_update_bits(codec, AIC31XX_BCLKN, mask, off);
950 snd_soc_update_bits(codec, AIC31XX_MADC, mask, off);
951 snd_soc_update_bits(codec, AIC31XX_NADC, mask, off);
952 snd_soc_update_bits(codec, AIC31XX_MDAC, mask, off);
953 snd_soc_update_bits(codec, AIC31XX_NDAC, mask, off);
954 snd_soc_update_bits(codec, AIC31XX_PLLPR, mask, off);
955}
956
957static int aic31xx_power_on(struct snd_soc_codec *codec)
958{
959 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
960 int ret = 0;
961
962 ret = regulator_bulk_enable(ARRAY_SIZE(aic31xx->supplies),
963 aic31xx->supplies);
964 if (ret)
965 return ret;
966
967 if (gpio_is_valid(aic31xx->pdata.gpio_reset)) {
968 gpio_set_value(aic31xx->pdata.gpio_reset, 1);
969 udelay(100);
970 }
971 regcache_cache_only(aic31xx->regmap, false);
972 ret = regcache_sync(aic31xx->regmap);
973 if (ret != 0) {
974 dev_err(codec->dev,
975 "Failed to restore cache: %d\n", ret);
976 regcache_cache_only(aic31xx->regmap, true);
977 regulator_bulk_disable(ARRAY_SIZE(aic31xx->supplies),
978 aic31xx->supplies);
979 return ret;
980 }
981 return 0;
982}
983
984static int aic31xx_power_off(struct snd_soc_codec *codec)
985{
986 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
987 int ret = 0;
988
989 regcache_cache_only(aic31xx->regmap, true);
990 ret = regulator_bulk_disable(ARRAY_SIZE(aic31xx->supplies),
991 aic31xx->supplies);
992
993 return ret;
994}
995
996static int aic31xx_set_bias_level(struct snd_soc_codec *codec,
997 enum snd_soc_bias_level level)
998{
999 dev_dbg(codec->dev, "## %s: %d -> %d\n", __func__,
1000 codec->dapm.bias_level, level);
1001
1002 switch (level) {
1003 case SND_SOC_BIAS_ON:
1004 break;
1005 case SND_SOC_BIAS_PREPARE:
1006 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
1007 aic31xx_clk_on(codec);
1008 break;
1009 case SND_SOC_BIAS_STANDBY:
1010 switch (codec->dapm.bias_level) {
1011 case SND_SOC_BIAS_OFF:
1012 aic31xx_power_on(codec);
1013 break;
1014 case SND_SOC_BIAS_PREPARE:
1015 aic31xx_clk_off(codec);
1016 break;
1017 default:
1018 BUG();
1019 }
1020 break;
1021 case SND_SOC_BIAS_OFF:
1022 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
1023 aic31xx_power_off(codec);
1024 break;
1025 }
1026 codec->dapm.bias_level = level;
1027
1028 return 0;
1029}
1030
1031static int aic31xx_suspend(struct snd_soc_codec *codec)
1032{
1033 aic31xx_set_bias_level(codec, SND_SOC_BIAS_OFF);
1034 return 0;
1035}
1036
1037static int aic31xx_resume(struct snd_soc_codec *codec)
1038{
1039 aic31xx_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1040 return 0;
1041}
1042
1043static int aic31xx_codec_probe(struct snd_soc_codec *codec)
1044{
1045 int ret = 0;
1046 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
1047 int i;
1048
1049 dev_dbg(aic31xx->dev, "## %s\n", __func__);
1050
1051 aic31xx = snd_soc_codec_get_drvdata(codec);
1052
1053 aic31xx->codec = codec;
1054
1055 for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++) {
1056 aic31xx->disable_nb[i].nb.notifier_call =
1057 aic31xx_regulator_event;
1058 aic31xx->disable_nb[i].aic31xx = aic31xx;
1059 ret = regulator_register_notifier(aic31xx->supplies[i].consumer,
1060 &aic31xx->disable_nb[i].nb);
1061 if (ret) {
1062 dev_err(codec->dev,
1063 "Failed to request regulator notifier: %d\n",
1064 ret);
1065 return ret;
1066 }
1067 }
1068
1069 regcache_cache_only(aic31xx->regmap, true);
1070 regcache_mark_dirty(aic31xx->regmap);
1071
1072 ret = aic31xx_add_controls(codec);
1073 if (ret)
1074 return ret;
1075
1076 ret = aic31xx_add_widgets(codec);
1077
1078 return ret;
1079}
1080
1081static int aic31xx_codec_remove(struct snd_soc_codec *codec)
1082{
1083 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
1084 int i;
1085 /* power down chip */
1086 aic31xx_set_bias_level(codec, SND_SOC_BIAS_OFF);
1087
1088 for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++)
1089 regulator_unregister_notifier(aic31xx->supplies[i].consumer,
1090 &aic31xx->disable_nb[i].nb);
1091
1092 return 0;
1093}
1094
1095static struct snd_soc_codec_driver soc_codec_driver_aic31xx = {
1096 .probe = aic31xx_codec_probe,
1097 .remove = aic31xx_codec_remove,
1098 .suspend = aic31xx_suspend,
1099 .resume = aic31xx_resume,
1100 .set_bias_level = aic31xx_set_bias_level,
1101 .controls = aic31xx_snd_controls,
1102 .num_controls = ARRAY_SIZE(aic31xx_snd_controls),
1103 .dapm_widgets = aic31xx_dapm_widgets,
1104 .num_dapm_widgets = ARRAY_SIZE(aic31xx_dapm_widgets),
1105 .dapm_routes = aic31xx_audio_map,
1106 .num_dapm_routes = ARRAY_SIZE(aic31xx_audio_map),
1107};
1108
1109static struct snd_soc_dai_ops aic31xx_dai_ops = {
1110 .hw_params = aic31xx_hw_params,
1111 .set_sysclk = aic31xx_set_dai_sysclk,
1112 .set_fmt = aic31xx_set_dai_fmt,
1113 .digital_mute = aic31xx_dac_mute,
1114};
1115
1116static struct snd_soc_dai_driver aic31xx_dai_driver[] = {
1117 {
1118 .name = "tlv320aic31xx-hifi",
1119 .playback = {
1120 .stream_name = "Playback",
1121 .channels_min = 1,
1122 .channels_max = 2,
1123 .rates = AIC31XX_RATES,
1124 .formats = AIC31XX_FORMATS,
1125 },
1126 .capture = {
1127 .stream_name = "Capture",
1128 .channels_min = 1,
1129 .channels_max = 2,
1130 .rates = AIC31XX_RATES,
1131 .formats = AIC31XX_FORMATS,
1132 },
1133 .ops = &aic31xx_dai_ops,
1134 .symmetric_rates = 1,
1135 }
1136};
1137
1138#if defined(CONFIG_OF)
1139static const struct of_device_id tlv320aic31xx_of_match[] = {
1140 { .compatible = "ti,tlv320aic310x" },
1141 { .compatible = "ti,tlv320aic311x" },
1142 { .compatible = "ti,tlv320aic3100" },
1143 { .compatible = "ti,tlv320aic3110" },
1144 { .compatible = "ti,tlv320aic3120" },
1145 { .compatible = "ti,tlv320aic3111" },
1146 {},
1147};
1148MODULE_DEVICE_TABLE(of, tlv320aic31xx_of_match);
1149
1150static void aic31xx_pdata_from_of(struct aic31xx_priv *aic31xx)
1151{
1152 struct device_node *np = aic31xx->dev->of_node;
1153 unsigned int value = MICBIAS_2_0V;
1154 int ret;
1155
1156 of_property_read_u32(np, "ai31xx-micbias-vg", &value);
1157 switch (value) {
1158 case MICBIAS_2_0V:
1159 case MICBIAS_2_5V:
1160 case MICBIAS_AVDDV:
1161 aic31xx->pdata.micbias_vg = value;
1162 break;
1163 default:
1164 dev_err(aic31xx->dev,
1165 "Bad ai31xx-micbias-vg value %d DT\n",
1166 value);
1167 aic31xx->pdata.micbias_vg = MICBIAS_2_0V;
1168 }
1169
1170 ret = of_get_named_gpio(np, "gpio-reset", 0);
1171 if (ret > 0)
1172 aic31xx->pdata.gpio_reset = ret;
1173}
1174#else /* CONFIG_OF */
1175static void aic31xx_pdata_from_of(struct aic31xx_priv *aic31xx)
1176{
1177}
1178#endif /* CONFIG_OF */
1179
1180static void aic31xx_device_init(struct aic31xx_priv *aic31xx)
1181{
1182 int ret, i;
1183
1184 dev_set_drvdata(aic31xx->dev, aic31xx);
1185
1186 if (dev_get_platdata(aic31xx->dev))
1187 memcpy(&aic31xx->pdata, dev_get_platdata(aic31xx->dev),
1188 sizeof(aic31xx->pdata));
1189 else if (aic31xx->dev->of_node)
1190 aic31xx_pdata_from_of(aic31xx);
1191
1192 if (aic31xx->pdata.gpio_reset) {
1193 ret = devm_gpio_request_one(aic31xx->dev,
1194 aic31xx->pdata.gpio_reset,
1195 GPIOF_OUT_INIT_HIGH,
1196 "aic31xx-reset-pin");
1197 if (ret < 0) {
1198 dev_err(aic31xx->dev, "not able to acquire gpio\n");
1199 return;
1200 }
1201 }
1202
1203 for (i = 0; i < ARRAY_SIZE(aic31xx->supplies); i++)
1204 aic31xx->supplies[i].supply = aic31xx_supply_names[i];
1205
1206 ret = devm_regulator_bulk_get(aic31xx->dev,
1207 ARRAY_SIZE(aic31xx->supplies),
1208 aic31xx->supplies);
1209 if (ret != 0)
1210 dev_err(aic31xx->dev, "Failed to request supplies: %d\n", ret);
1211
1212}
1213
1214static int aic31xx_i2c_probe(struct i2c_client *i2c,
1215 const struct i2c_device_id *id)
1216{
1217 struct aic31xx_priv *aic31xx;
1218 int ret;
1219 const struct regmap_config *regmap_config;
1220
1221 dev_dbg(&i2c->dev, "## %s: %s codec_type = %d\n", __func__,
1222 id->name, (int) id->driver_data);
1223
1224 regmap_config = &aic31xx_i2c_regmap;
1225
1226 aic31xx = devm_kzalloc(&i2c->dev, sizeof(*aic31xx), GFP_KERNEL);
1227 if (aic31xx == NULL)
1228 return -ENOMEM;
1229
1230 aic31xx->regmap = devm_regmap_init_i2c(i2c, regmap_config);
1231 if (IS_ERR(aic31xx->regmap)) {
1232 ret = PTR_ERR(aic31xx->regmap);
1233 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
1234 ret);
1235 return ret;
1236 }
1237 aic31xx->dev = &i2c->dev;
1238
1239 aic31xx->pdata.codec_type = id->driver_data;
1240
1241 aic31xx_device_init(aic31xx);
1242
1243 return snd_soc_register_codec(&i2c->dev, &soc_codec_driver_aic31xx,
1244 aic31xx_dai_driver,
1245 ARRAY_SIZE(aic31xx_dai_driver));
1246}
1247
1248static int aic31xx_i2c_remove(struct i2c_client *i2c)
1249{
1250 snd_soc_unregister_codec(&i2c->dev);
1251 return 0;
1252}
1253
1254static const struct i2c_device_id aic31xx_i2c_id[] = {
1255 { "tlv320aic310x", AIC3100 },
1256 { "tlv320aic311x", AIC3110 },
1257 { "tlv320aic3100", AIC3100 },
1258 { "tlv320aic3110", AIC3110 },
1259 { "tlv320aic3120", AIC3120 },
1260 { "tlv320aic3111", AIC3111 },
1261 { }
1262};
1263MODULE_DEVICE_TABLE(i2c, aic31xx_i2c_id);
1264
1265static struct i2c_driver aic31xx_i2c_driver = {
1266 .driver = {
1267 .name = "tlv320aic31xx-codec",
1268 .owner = THIS_MODULE,
1269 .of_match_table = of_match_ptr(tlv320aic31xx_of_match),
1270 },
1271 .probe = aic31xx_i2c_probe,
1272 .remove = aic31xx_i2c_remove,
1273 .id_table = aic31xx_i2c_id,
1274};
1275
1276module_i2c_driver(aic31xx_i2c_driver);
1277
1278MODULE_DESCRIPTION("ASoC TLV320AIC3111 codec driver");
1279MODULE_AUTHOR("Jyri Sarha");
1280MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/tlv320aic31xx.h b/sound/soc/codecs/tlv320aic31xx.h
new file mode 100644
index 000000000000..52ed57c69dfa
--- /dev/null
+++ b/sound/soc/codecs/tlv320aic31xx.h
@@ -0,0 +1,258 @@
1/*
2 * ALSA SoC TLV320AIC31XX codec driver
3 *
4 * Copyright (C) 2013 Texas Instruments, Inc.
5 *
6 * This package 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 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
11 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 */
15#ifndef _TLV320AIC31XX_H
16#define _TLV320AIC31XX_H
17
18#define AIC31XX_RATES SNDRV_PCM_RATE_8000_192000
19
20#define AIC31XX_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE \
21 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
22
23
24#define AIC31XX_STEREO_CLASS_D_BIT 0x1
25#define AIC31XX_MINIDSP_BIT 0x2
26
27enum aic31xx_type {
28 AIC3100 = 0,
29 AIC3110 = AIC31XX_STEREO_CLASS_D_BIT,
30 AIC3120 = AIC31XX_MINIDSP_BIT,
31 AIC3111 = (AIC31XX_STEREO_CLASS_D_BIT | AIC31XX_MINIDSP_BIT),
32};
33
34struct aic31xx_pdata {
35 enum aic31xx_type codec_type;
36 unsigned int gpio_reset;
37 int micbias_vg;
38};
39
40/* Page Control Register */
41#define AIC31XX_PAGECTL 0x00
42
43/* Page 0 Registers */
44/* Software reset register */
45#define AIC31XX_RESET 0x01
46/* OT FLAG register */
47#define AIC31XX_OT_FLAG 0x03
48/* Clock clock Gen muxing, Multiplexers*/
49#define AIC31XX_CLKMUX 0x04
50/* PLL P and R-VAL register */
51#define AIC31XX_PLLPR 0x05
52/* PLL J-VAL register */
53#define AIC31XX_PLLJ 0x06
54/* PLL D-VAL MSB register */
55#define AIC31XX_PLLDMSB 0x07
56/* PLL D-VAL LSB register */
57#define AIC31XX_PLLDLSB 0x08
58/* DAC NDAC_VAL register*/
59#define AIC31XX_NDAC 0x0B
60/* DAC MDAC_VAL register */
61#define AIC31XX_MDAC 0x0C
62/* DAC OSR setting register 1, MSB value */
63#define AIC31XX_DOSRMSB 0x0D
64/* DAC OSR setting register 2, LSB value */
65#define AIC31XX_DOSRLSB 0x0E
66#define AIC31XX_MINI_DSP_INPOL 0x10
67/* Clock setting register 8, PLL */
68#define AIC31XX_NADC 0x12
69/* Clock setting register 9, PLL */
70#define AIC31XX_MADC 0x13
71/* ADC Oversampling (AOSR) Register */
72#define AIC31XX_AOSR 0x14
73/* Clock setting register 9, Multiplexers */
74#define AIC31XX_CLKOUTMUX 0x19
75/* Clock setting register 10, CLOCKOUT M divider value */
76#define AIC31XX_CLKOUTMVAL 0x1A
77/* Audio Interface Setting Register 1 */
78#define AIC31XX_IFACE1 0x1B
79/* Audio Data Slot Offset Programming */
80#define AIC31XX_DATA_OFFSET 0x1C
81/* Audio Interface Setting Register 2 */
82#define AIC31XX_IFACE2 0x1D
83/* Clock setting register 11, BCLK N Divider */
84#define AIC31XX_BCLKN 0x1E
85/* Audio Interface Setting Register 3, Secondary Audio Interface */
86#define AIC31XX_IFACESEC1 0x1F
87/* Audio Interface Setting Register 4 */
88#define AIC31XX_IFACESEC2 0x20
89/* Audio Interface Setting Register 5 */
90#define AIC31XX_IFACESEC3 0x21
91/* I2C Bus Condition */
92#define AIC31XX_I2C 0x22
93/* ADC FLAG */
94#define AIC31XX_ADCFLAG 0x24
95/* DAC Flag Registers */
96#define AIC31XX_DACFLAG1 0x25
97#define AIC31XX_DACFLAG2 0x26
98/* Sticky Interrupt flag (overflow) */
99#define AIC31XX_OFFLAG 0x27
100/* Sticy DAC Interrupt flags */
101#define AIC31XX_INTRDACFLAG 0x2C
102/* Sticy ADC Interrupt flags */
103#define AIC31XX_INTRADCFLAG 0x2D
104/* DAC Interrupt flags 2 */
105#define AIC31XX_INTRDACFLAG2 0x2E
106/* ADC Interrupt flags 2 */
107#define AIC31XX_INTRADCFLAG2 0x2F
108/* INT1 interrupt control */
109#define AIC31XX_INT1CTRL 0x30
110/* INT2 interrupt control */
111#define AIC31XX_INT2CTRL 0x31
112/* GPIO1 control */
113#define AIC31XX_GPIO1 0x33
114
115#define AIC31XX_DACPRB 0x3C
116/* ADC Instruction Set Register */
117#define AIC31XX_ADCPRB 0x3D
118/* DAC channel setup register */
119#define AIC31XX_DACSETUP 0x3F
120/* DAC Mute and volume control register */
121#define AIC31XX_DACMUTE 0x40
122/* Left DAC channel digital volume control */
123#define AIC31XX_LDACVOL 0x41
124/* Right DAC channel digital volume control */
125#define AIC31XX_RDACVOL 0x42
126/* Headset detection */
127#define AIC31XX_HSDETECT 0x43
128/* ADC Digital Mic */
129#define AIC31XX_ADCSETUP 0x51
130/* ADC Digital Volume Control Fine Adjust */
131#define AIC31XX_ADCFGA 0x52
132/* ADC Digital Volume Control Coarse Adjust */
133#define AIC31XX_ADCVOL 0x53
134
135
136/* Page 1 Registers */
137/* Headphone drivers */
138#define AIC31XX_HPDRIVER 0x9F
139/* Class-D Speakear Amplifier */
140#define AIC31XX_SPKAMP 0xA0
141/* HP Output Drivers POP Removal Settings */
142#define AIC31XX_HPPOP 0xA1
143/* Output Driver PGA Ramp-Down Period Control */
144#define AIC31XX_SPPGARAMP 0xA2
145/* DAC_L and DAC_R Output Mixer Routing */
146#define AIC31XX_DACMIXERROUTE 0xA3
147/* Left Analog Vol to HPL */
148#define AIC31XX_LANALOGHPL 0xA4
149/* Right Analog Vol to HPR */
150#define AIC31XX_RANALOGHPR 0xA5
151/* Left Analog Vol to SPL */
152#define AIC31XX_LANALOGSPL 0xA6
153/* Right Analog Vol to SPR */
154#define AIC31XX_RANALOGSPR 0xA7
155/* HPL Driver */
156#define AIC31XX_HPLGAIN 0xA8
157/* HPR Driver */
158#define AIC31XX_HPRGAIN 0xA9
159/* SPL Driver */
160#define AIC31XX_SPLGAIN 0xAA
161/* SPR Driver */
162#define AIC31XX_SPRGAIN 0xAB
163/* HP Driver Control */
164#define AIC31XX_HPCONTROL 0xAC
165/* MIC Bias Control */
166#define AIC31XX_MICBIAS 0xAE
167/* MIC PGA*/
168#define AIC31XX_MICPGA 0xAF
169/* Delta-Sigma Mono ADC Channel Fine-Gain Input Selection for P-Terminal */
170#define AIC31XX_MICPGAPI 0xB0
171/* ADC Input Selection for M-Terminal */
172#define AIC31XX_MICPGAMI 0xB1
173/* Input CM Settings */
174#define AIC31XX_MICPGACM 0xB2
175
176/* Bits, masks and shifts */
177
178/* AIC31XX_CLKMUX */
179#define AIC31XX_PLL_CLKIN_MASK 0x0c
180#define AIC31XX_PLL_CLKIN_SHIFT 2
181#define AIC31XX_PLL_CLKIN_MCLK 0
182#define AIC31XX_CODEC_CLKIN_MASK 0x03
183#define AIC31XX_CODEC_CLKIN_SHIFT 0
184#define AIC31XX_CODEC_CLKIN_PLL 3
185#define AIC31XX_CODEC_CLKIN_BCLK 1
186
187/* AIC31XX_PLLPR, AIC31XX_NDAC, AIC31XX_MDAC, AIC31XX_NADC, AIC31XX_MADC,
188 AIC31XX_BCLKN */
189#define AIC31XX_PLL_MASK 0x7f
190#define AIC31XX_PM_MASK 0x80
191
192/* AIC31XX_IFACE1 */
193#define AIC31XX_WORD_LEN_16BITS 0x00
194#define AIC31XX_WORD_LEN_20BITS 0x01
195#define AIC31XX_WORD_LEN_24BITS 0x02
196#define AIC31XX_WORD_LEN_32BITS 0x03
197#define AIC31XX_IFACE1_DATALEN_MASK 0x30
198#define AIC31XX_IFACE1_DATALEN_SHIFT (4)
199#define AIC31XX_IFACE1_DATATYPE_MASK 0xC0
200#define AIC31XX_IFACE1_DATATYPE_SHIFT (6)
201#define AIC31XX_I2S_MODE 0x00
202#define AIC31XX_DSP_MODE 0x01
203#define AIC31XX_RIGHT_JUSTIFIED_MODE 0x02
204#define AIC31XX_LEFT_JUSTIFIED_MODE 0x03
205#define AIC31XX_IFACE1_MASTER_MASK 0x0C
206#define AIC31XX_BCLK_MASTER 0x08
207#define AIC31XX_WCLK_MASTER 0x04
208
209/* AIC31XX_DATA_OFFSET */
210#define AIC31XX_DATA_OFFSET_MASK 0xFF
211
212/* AIC31XX_IFACE2 */
213#define AIC31XX_BCLKINV_MASK 0x08
214#define AIC31XX_BDIVCLK_MASK 0x03
215#define AIC31XX_DAC2BCLK 0x00
216#define AIC31XX_DACMOD2BCLK 0x01
217#define AIC31XX_ADC2BCLK 0x02
218#define AIC31XX_ADCMOD2BCLK 0x03
219
220/* AIC31XX_ADCFLAG */
221#define AIC31XX_ADCPWRSTATUS_MASK 0x40
222
223/* AIC31XX_DACFLAG1 */
224#define AIC31XX_LDACPWRSTATUS_MASK 0x80
225#define AIC31XX_RDACPWRSTATUS_MASK 0x08
226#define AIC31XX_HPLDRVPWRSTATUS_MASK 0x20
227#define AIC31XX_HPRDRVPWRSTATUS_MASK 0x02
228#define AIC31XX_SPLDRVPWRSTATUS_MASK 0x10
229#define AIC31XX_SPRDRVPWRSTATUS_MASK 0x01
230
231/* AIC31XX_INTRDACFLAG */
232#define AIC31XX_HPSCDETECT_MASK 0x80
233#define AIC31XX_BUTTONPRESS_MASK 0x20
234#define AIC31XX_HSPLUG_MASK 0x10
235#define AIC31XX_LDRCTHRES_MASK 0x08
236#define AIC31XX_RDRCTHRES_MASK 0x04
237#define AIC31XX_DACSINT_MASK 0x02
238#define AIC31XX_DACAINT_MASK 0x01
239
240/* AIC31XX_INT1CTRL */
241#define AIC31XX_HSPLUGDET_MASK 0x80
242#define AIC31XX_BUTTONPRESSDET_MASK 0x40
243#define AIC31XX_DRCTHRES_MASK 0x20
244#define AIC31XX_AGCNOISE_MASK 0x10
245#define AIC31XX_OC_MASK 0x08
246#define AIC31XX_ENGINE_MASK 0x04
247
248/* AIC31XX_DACSETUP */
249#define AIC31XX_SOFTSTEP_MASK 0x03
250
251/* AIC31XX_DACMUTE */
252#define AIC31XX_DACMUTE_MASK 0x0C
253
254/* AIC31XX_MICBIAS */
255#define AIC31XX_MICBIAS_MASK 0x03
256#define AIC31XX_MICBIAS_SHIFT 0
257
258#endif /* _TLV320AIC31XX_H */
diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c
index 688151ba309a..1d9b117345a3 100644
--- a/sound/soc/codecs/tlv320aic32x4.c
+++ b/sound/soc/codecs/tlv320aic32x4.c
@@ -29,9 +29,12 @@
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/pm.h> 30#include <linux/pm.h>
31#include <linux/gpio.h> 31#include <linux/gpio.h>
32#include <linux/of_gpio.h>
32#include <linux/i2c.h> 33#include <linux/i2c.h>
33#include <linux/cdev.h> 34#include <linux/cdev.h>
34#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/clk.h>
37#include <linux/regulator/consumer.h>
35 38
36#include <sound/tlv320aic32x4.h> 39#include <sound/tlv320aic32x4.h>
37#include <sound/core.h> 40#include <sound/core.h>
@@ -66,20 +69,32 @@ struct aic32x4_priv {
66 u32 micpga_routing; 69 u32 micpga_routing;
67 bool swapdacs; 70 bool swapdacs;
68 int rstn_gpio; 71 int rstn_gpio;
72 struct clk *mclk;
73
74 struct regulator *supply_ldo;
75 struct regulator *supply_iov;
76 struct regulator *supply_dv;
77 struct regulator *supply_av;
69}; 78};
70 79
71/* 0dB min, 1dB steps */
72static DECLARE_TLV_DB_SCALE(tlv_step_1, 0, 100, 0);
73/* 0dB min, 0.5dB steps */ 80/* 0dB min, 0.5dB steps */
74static DECLARE_TLV_DB_SCALE(tlv_step_0_5, 0, 50, 0); 81static DECLARE_TLV_DB_SCALE(tlv_step_0_5, 0, 50, 0);
82/* -63.5dB min, 0.5dB steps */
83static DECLARE_TLV_DB_SCALE(tlv_pcm, -6350, 50, 0);
84/* -6dB min, 1dB steps */
85static DECLARE_TLV_DB_SCALE(tlv_driver_gain, -600, 100, 0);
86/* -12dB min, 0.5dB steps */
87static DECLARE_TLV_DB_SCALE(tlv_adc_vol, -1200, 50, 0);
75 88
76static const struct snd_kcontrol_new aic32x4_snd_controls[] = { 89static const struct snd_kcontrol_new aic32x4_snd_controls[] = {
77 SOC_DOUBLE_R_TLV("PCM Playback Volume", AIC32X4_LDACVOL, 90 SOC_DOUBLE_R_S_TLV("PCM Playback Volume", AIC32X4_LDACVOL,
78 AIC32X4_RDACVOL, 0, 0x30, 0, tlv_step_0_5), 91 AIC32X4_RDACVOL, 0, -0x7f, 0x30, 7, 0, tlv_pcm),
79 SOC_DOUBLE_R_TLV("HP Driver Gain Volume", AIC32X4_HPLGAIN, 92 SOC_DOUBLE_R_S_TLV("HP Driver Gain Volume", AIC32X4_HPLGAIN,
80 AIC32X4_HPRGAIN, 0, 0x1D, 0, tlv_step_1), 93 AIC32X4_HPRGAIN, 0, -0x6, 0x1d, 5, 0,
81 SOC_DOUBLE_R_TLV("LO Driver Gain Volume", AIC32X4_LOLGAIN, 94 tlv_driver_gain),
82 AIC32X4_LORGAIN, 0, 0x1D, 0, tlv_step_1), 95 SOC_DOUBLE_R_S_TLV("LO Driver Gain Volume", AIC32X4_LOLGAIN,
96 AIC32X4_LORGAIN, 0, -0x6, 0x1d, 5, 0,
97 tlv_driver_gain),
83 SOC_DOUBLE_R("HP DAC Playback Switch", AIC32X4_HPLGAIN, 98 SOC_DOUBLE_R("HP DAC Playback Switch", AIC32X4_HPLGAIN,
84 AIC32X4_HPRGAIN, 6, 0x01, 1), 99 AIC32X4_HPRGAIN, 6, 0x01, 1),
85 SOC_DOUBLE_R("LO DAC Playback Switch", AIC32X4_LOLGAIN, 100 SOC_DOUBLE_R("LO DAC Playback Switch", AIC32X4_LOLGAIN,
@@ -90,8 +105,8 @@ static const struct snd_kcontrol_new aic32x4_snd_controls[] = {
90 SOC_SINGLE("ADCFGA Left Mute Switch", AIC32X4_ADCFGA, 7, 1, 0), 105 SOC_SINGLE("ADCFGA Left Mute Switch", AIC32X4_ADCFGA, 7, 1, 0),
91 SOC_SINGLE("ADCFGA Right Mute Switch", AIC32X4_ADCFGA, 3, 1, 0), 106 SOC_SINGLE("ADCFGA Right Mute Switch", AIC32X4_ADCFGA, 3, 1, 0),
92 107
93 SOC_DOUBLE_R_TLV("ADC Level Volume", AIC32X4_LADCVOL, 108 SOC_DOUBLE_R_S_TLV("ADC Level Volume", AIC32X4_LADCVOL,
94 AIC32X4_RADCVOL, 0, 0x28, 0, tlv_step_0_5), 109 AIC32X4_RADCVOL, 0, -0x18, 0x28, 6, 0, tlv_adc_vol),
95 SOC_DOUBLE_R_TLV("PGA Level Volume", AIC32X4_LMICPGAVOL, 110 SOC_DOUBLE_R_TLV("PGA Level Volume", AIC32X4_LMICPGAVOL,
96 AIC32X4_RMICPGAVOL, 0, 0x5f, 0, tlv_step_0_5), 111 AIC32X4_RMICPGAVOL, 0, 0x5f, 0, tlv_step_0_5),
97 112
@@ -480,8 +495,18 @@ static int aic32x4_mute(struct snd_soc_dai *dai, int mute)
480static int aic32x4_set_bias_level(struct snd_soc_codec *codec, 495static int aic32x4_set_bias_level(struct snd_soc_codec *codec,
481 enum snd_soc_bias_level level) 496 enum snd_soc_bias_level level)
482{ 497{
498 struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
499 int ret;
500
483 switch (level) { 501 switch (level) {
484 case SND_SOC_BIAS_ON: 502 case SND_SOC_BIAS_ON:
503 /* Switch on master clock */
504 ret = clk_prepare_enable(aic32x4->mclk);
505 if (ret) {
506 dev_err(codec->dev, "Failed to enable master clock\n");
507 return ret;
508 }
509
485 /* Switch on PLL */ 510 /* Switch on PLL */
486 snd_soc_update_bits(codec, AIC32X4_PLLPR, 511 snd_soc_update_bits(codec, AIC32X4_PLLPR,
487 AIC32X4_PLLEN, AIC32X4_PLLEN); 512 AIC32X4_PLLEN, AIC32X4_PLLEN);
@@ -509,29 +534,32 @@ static int aic32x4_set_bias_level(struct snd_soc_codec *codec,
509 case SND_SOC_BIAS_PREPARE: 534 case SND_SOC_BIAS_PREPARE:
510 break; 535 break;
511 case SND_SOC_BIAS_STANDBY: 536 case SND_SOC_BIAS_STANDBY:
512 /* Switch off PLL */ 537 /* Switch off BCLK_N Divider */
513 snd_soc_update_bits(codec, AIC32X4_PLLPR, 538 snd_soc_update_bits(codec, AIC32X4_BCLKN,
514 AIC32X4_PLLEN, 0); 539 AIC32X4_BCLKEN, 0);
515 540
516 /* Switch off NDAC Divider */ 541 /* Switch off MADC Divider */
517 snd_soc_update_bits(codec, AIC32X4_NDAC, 542 snd_soc_update_bits(codec, AIC32X4_MADC,
518 AIC32X4_NDACEN, 0); 543 AIC32X4_MADCEN, 0);
544
545 /* Switch off NADC Divider */
546 snd_soc_update_bits(codec, AIC32X4_NADC,
547 AIC32X4_NADCEN, 0);
519 548
520 /* Switch off MDAC Divider */ 549 /* Switch off MDAC Divider */
521 snd_soc_update_bits(codec, AIC32X4_MDAC, 550 snd_soc_update_bits(codec, AIC32X4_MDAC,
522 AIC32X4_MDACEN, 0); 551 AIC32X4_MDACEN, 0);
523 552
524 /* Switch off NADC Divider */ 553 /* Switch off NDAC Divider */
525 snd_soc_update_bits(codec, AIC32X4_NADC, 554 snd_soc_update_bits(codec, AIC32X4_NDAC,
526 AIC32X4_NADCEN, 0); 555 AIC32X4_NDACEN, 0);
527 556
528 /* Switch off MADC Divider */ 557 /* Switch off PLL */
529 snd_soc_update_bits(codec, AIC32X4_MADC, 558 snd_soc_update_bits(codec, AIC32X4_PLLPR,
530 AIC32X4_MADCEN, 0); 559 AIC32X4_PLLEN, 0);
531 560
532 /* Switch off BCLK_N Divider */ 561 /* Switch off master clock */
533 snd_soc_update_bits(codec, AIC32X4_BCLKN, 562 clk_disable_unprepare(aic32x4->mclk);
534 AIC32X4_BCLKEN, 0);
535 break; 563 break;
536 case SND_SOC_BIAS_OFF: 564 case SND_SOC_BIAS_OFF:
537 break; 565 break;
@@ -586,9 +614,7 @@ static int aic32x4_probe(struct snd_soc_codec *codec)
586 struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec); 614 struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
587 u32 tmp_reg; 615 u32 tmp_reg;
588 616
589 snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP); 617 if (gpio_is_valid(aic32x4->rstn_gpio)) {
590
591 if (aic32x4->rstn_gpio >= 0) {
592 ndelay(10); 618 ndelay(10);
593 gpio_set_value(aic32x4->rstn_gpio, 1); 619 gpio_set_value(aic32x4->rstn_gpio, 1);
594 } 620 }
@@ -663,11 +689,122 @@ static struct snd_soc_codec_driver soc_codec_dev_aic32x4 = {
663 .num_dapm_routes = ARRAY_SIZE(aic32x4_dapm_routes), 689 .num_dapm_routes = ARRAY_SIZE(aic32x4_dapm_routes),
664}; 690};
665 691
692static int aic32x4_parse_dt(struct aic32x4_priv *aic32x4,
693 struct device_node *np)
694{
695 aic32x4->swapdacs = false;
696 aic32x4->micpga_routing = 0;
697 aic32x4->rstn_gpio = of_get_named_gpio(np, "reset-gpios", 0);
698
699 return 0;
700}
701
702static void aic32x4_disable_regulators(struct aic32x4_priv *aic32x4)
703{
704 regulator_disable(aic32x4->supply_iov);
705
706 if (!IS_ERR(aic32x4->supply_ldo))
707 regulator_disable(aic32x4->supply_ldo);
708
709 if (!IS_ERR(aic32x4->supply_dv))
710 regulator_disable(aic32x4->supply_dv);
711
712 if (!IS_ERR(aic32x4->supply_av))
713 regulator_disable(aic32x4->supply_av);
714}
715
716static int aic32x4_setup_regulators(struct device *dev,
717 struct aic32x4_priv *aic32x4)
718{
719 int ret = 0;
720
721 aic32x4->supply_ldo = devm_regulator_get_optional(dev, "ldoin");
722 aic32x4->supply_iov = devm_regulator_get(dev, "iov");
723 aic32x4->supply_dv = devm_regulator_get_optional(dev, "dv");
724 aic32x4->supply_av = devm_regulator_get_optional(dev, "av");
725
726 /* Check if the regulator requirements are fulfilled */
727
728 if (IS_ERR(aic32x4->supply_iov)) {
729 dev_err(dev, "Missing supply 'iov'\n");
730 return PTR_ERR(aic32x4->supply_iov);
731 }
732
733 if (IS_ERR(aic32x4->supply_ldo)) {
734 if (PTR_ERR(aic32x4->supply_ldo) == -EPROBE_DEFER)
735 return -EPROBE_DEFER;
736
737 if (IS_ERR(aic32x4->supply_dv)) {
738 dev_err(dev, "Missing supply 'dv' or 'ldoin'\n");
739 return PTR_ERR(aic32x4->supply_dv);
740 }
741 if (IS_ERR(aic32x4->supply_av)) {
742 dev_err(dev, "Missing supply 'av' or 'ldoin'\n");
743 return PTR_ERR(aic32x4->supply_av);
744 }
745 } else {
746 if (IS_ERR(aic32x4->supply_dv) &&
747 PTR_ERR(aic32x4->supply_dv) == -EPROBE_DEFER)
748 return -EPROBE_DEFER;
749 if (IS_ERR(aic32x4->supply_av) &&
750 PTR_ERR(aic32x4->supply_av) == -EPROBE_DEFER)
751 return -EPROBE_DEFER;
752 }
753
754 ret = regulator_enable(aic32x4->supply_iov);
755 if (ret) {
756 dev_err(dev, "Failed to enable regulator iov\n");
757 return ret;
758 }
759
760 if (!IS_ERR(aic32x4->supply_ldo)) {
761 ret = regulator_enable(aic32x4->supply_ldo);
762 if (ret) {
763 dev_err(dev, "Failed to enable regulator ldo\n");
764 goto error_ldo;
765 }
766 }
767
768 if (!IS_ERR(aic32x4->supply_dv)) {
769 ret = regulator_enable(aic32x4->supply_dv);
770 if (ret) {
771 dev_err(dev, "Failed to enable regulator dv\n");
772 goto error_dv;
773 }
774 }
775
776 if (!IS_ERR(aic32x4->supply_av)) {
777 ret = regulator_enable(aic32x4->supply_av);
778 if (ret) {
779 dev_err(dev, "Failed to enable regulator av\n");
780 goto error_av;
781 }
782 }
783
784 if (!IS_ERR(aic32x4->supply_ldo) && IS_ERR(aic32x4->supply_av))
785 aic32x4->power_cfg |= AIC32X4_PWR_AIC32X4_LDO_ENABLE;
786
787 return 0;
788
789error_av:
790 if (!IS_ERR(aic32x4->supply_dv))
791 regulator_disable(aic32x4->supply_dv);
792
793error_dv:
794 if (!IS_ERR(aic32x4->supply_ldo))
795 regulator_disable(aic32x4->supply_ldo);
796
797error_ldo:
798 regulator_disable(aic32x4->supply_iov);
799 return ret;
800}
801
666static int aic32x4_i2c_probe(struct i2c_client *i2c, 802static int aic32x4_i2c_probe(struct i2c_client *i2c,
667 const struct i2c_device_id *id) 803 const struct i2c_device_id *id)
668{ 804{
669 struct aic32x4_pdata *pdata = i2c->dev.platform_data; 805 struct aic32x4_pdata *pdata = i2c->dev.platform_data;
670 struct aic32x4_priv *aic32x4; 806 struct aic32x4_priv *aic32x4;
807 struct device_node *np = i2c->dev.of_node;
671 int ret; 808 int ret;
672 809
673 aic32x4 = devm_kzalloc(&i2c->dev, sizeof(struct aic32x4_priv), 810 aic32x4 = devm_kzalloc(&i2c->dev, sizeof(struct aic32x4_priv),
@@ -686,6 +823,12 @@ static int aic32x4_i2c_probe(struct i2c_client *i2c,
686 aic32x4->swapdacs = pdata->swapdacs; 823 aic32x4->swapdacs = pdata->swapdacs;
687 aic32x4->micpga_routing = pdata->micpga_routing; 824 aic32x4->micpga_routing = pdata->micpga_routing;
688 aic32x4->rstn_gpio = pdata->rstn_gpio; 825 aic32x4->rstn_gpio = pdata->rstn_gpio;
826 } else if (np) {
827 ret = aic32x4_parse_dt(aic32x4, np);
828 if (ret) {
829 dev_err(&i2c->dev, "Failed to parse DT node\n");
830 return ret;
831 }
689 } else { 832 } else {
690 aic32x4->power_cfg = 0; 833 aic32x4->power_cfg = 0;
691 aic32x4->swapdacs = false; 834 aic32x4->swapdacs = false;
@@ -693,20 +836,44 @@ static int aic32x4_i2c_probe(struct i2c_client *i2c,
693 aic32x4->rstn_gpio = -1; 836 aic32x4->rstn_gpio = -1;
694 } 837 }
695 838
696 if (aic32x4->rstn_gpio >= 0) { 839 aic32x4->mclk = devm_clk_get(&i2c->dev, "mclk");
840 if (IS_ERR(aic32x4->mclk)) {
841 dev_err(&i2c->dev, "Failed getting the mclk. The current implementation does not support the usage of this codec without mclk\n");
842 return PTR_ERR(aic32x4->mclk);
843 }
844
845 if (gpio_is_valid(aic32x4->rstn_gpio)) {
697 ret = devm_gpio_request_one(&i2c->dev, aic32x4->rstn_gpio, 846 ret = devm_gpio_request_one(&i2c->dev, aic32x4->rstn_gpio,
698 GPIOF_OUT_INIT_LOW, "tlv320aic32x4 rstn"); 847 GPIOF_OUT_INIT_LOW, "tlv320aic32x4 rstn");
699 if (ret != 0) 848 if (ret != 0)
700 return ret; 849 return ret;
701 } 850 }
702 851
852 ret = aic32x4_setup_regulators(&i2c->dev, aic32x4);
853 if (ret) {
854 dev_err(&i2c->dev, "Failed to setup regulators\n");
855 return ret;
856 }
857
703 ret = snd_soc_register_codec(&i2c->dev, 858 ret = snd_soc_register_codec(&i2c->dev,
704 &soc_codec_dev_aic32x4, &aic32x4_dai, 1); 859 &soc_codec_dev_aic32x4, &aic32x4_dai, 1);
705 return ret; 860 if (ret) {
861 dev_err(&i2c->dev, "Failed to register codec\n");
862 aic32x4_disable_regulators(aic32x4);
863 return ret;
864 }
865
866 i2c_set_clientdata(i2c, aic32x4);
867
868 return 0;
706} 869}
707 870
708static int aic32x4_i2c_remove(struct i2c_client *client) 871static int aic32x4_i2c_remove(struct i2c_client *client)
709{ 872{
873 struct aic32x4_priv *aic32x4 = i2c_get_clientdata(client);
874
875 aic32x4_disable_regulators(aic32x4);
876
710 snd_soc_unregister_codec(&client->dev); 877 snd_soc_unregister_codec(&client->dev);
711 return 0; 878 return 0;
712} 879}
@@ -717,10 +884,17 @@ static const struct i2c_device_id aic32x4_i2c_id[] = {
717}; 884};
718MODULE_DEVICE_TABLE(i2c, aic32x4_i2c_id); 885MODULE_DEVICE_TABLE(i2c, aic32x4_i2c_id);
719 886
887static const struct of_device_id aic32x4_of_id[] = {
888 { .compatible = "ti,tlv320aic32x4", },
889 { /* senitel */ }
890};
891MODULE_DEVICE_TABLE(of, aic32x4_of_id);
892
720static struct i2c_driver aic32x4_i2c_driver = { 893static struct i2c_driver aic32x4_i2c_driver = {
721 .driver = { 894 .driver = {
722 .name = "tlv320aic32x4", 895 .name = "tlv320aic32x4",
723 .owner = THIS_MODULE, 896 .owner = THIS_MODULE,
897 .of_match_table = aic32x4_of_id,
724 }, 898 },
725 .probe = aic32x4_i2c_probe, 899 .probe = aic32x4_i2c_probe,
726 .remove = aic32x4_i2c_remove, 900 .remove = aic32x4_i2c_remove,
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 470fbfb4b386..b1835103e9b4 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -1344,12 +1344,6 @@ static int aic3x_probe(struct snd_soc_codec *codec)
1344 INIT_LIST_HEAD(&aic3x->list); 1344 INIT_LIST_HEAD(&aic3x->list);
1345 aic3x->codec = codec; 1345 aic3x->codec = codec;
1346 1346
1347 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1348 if (ret != 0) {
1349 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1350 return ret;
1351 }
1352
1353 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) { 1347 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) {
1354 aic3x->disable_nb[i].nb.notifier_call = aic3x_regulator_event; 1348 aic3x->disable_nb[i].nb.notifier_call = aic3x_regulator_event;
1355 aic3x->disable_nb[i].aic3x = aic3x; 1349 aic3x->disable_nb[i].aic3x = aic3x;
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index 4f358393d6d6..6bfc8a17331b 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -122,7 +122,6 @@ struct tlv320dac33_priv {
122 unsigned int uthr; 122 unsigned int uthr;
123 123
124 enum dac33_state state; 124 enum dac33_state state;
125 enum snd_soc_control_type control_type;
126 void *control_data; 125 void *control_data;
127}; 126};
128 127
@@ -461,7 +460,7 @@ static int dac33_set_fifo_mode(struct snd_kcontrol *kcontrol,
461 if (dac33->fifo_mode == ucontrol->value.integer.value[0]) 460 if (dac33->fifo_mode == ucontrol->value.integer.value[0])
462 return 0; 461 return 0;
463 /* Do not allow changes while stream is running*/ 462 /* Do not allow changes while stream is running*/
464 if (codec->active) 463 if (snd_soc_codec_is_active(codec))
465 return -EPERM; 464 return -EPERM;
466 465
467 if (ucontrol->value.integer.value[0] < 0 || 466 if (ucontrol->value.integer.value[0] < 0 ||
@@ -478,9 +477,7 @@ static const char *dac33_fifo_mode_texts[] = {
478 "Bypass", "Mode 1", "Mode 7" 477 "Bypass", "Mode 1", "Mode 7"
479}; 478};
480 479
481static const struct soc_enum dac33_fifo_mode_enum = 480static SOC_ENUM_SINGLE_EXT_DECL(dac33_fifo_mode_enum, dac33_fifo_mode_texts);
482 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dac33_fifo_mode_texts),
483 dac33_fifo_mode_texts);
484 481
485/* L/R Line Output Gain */ 482/* L/R Line Output Gain */
486static const char *lr_lineout_gain_texts[] = { 483static const char *lr_lineout_gain_texts[] = {
@@ -488,15 +485,13 @@ static const char *lr_lineout_gain_texts[] = {
488 "Line 0dB DAC 12dB", "Line 6dB DAC 18dB", 485 "Line 0dB DAC 12dB", "Line 6dB DAC 18dB",
489}; 486};
490 487
491static const struct soc_enum l_lineout_gain_enum = 488static SOC_ENUM_SINGLE_DECL(l_lineout_gain_enum,
492 SOC_ENUM_SINGLE(DAC33_LDAC_PWR_CTRL, 0, 489 DAC33_LDAC_PWR_CTRL, 0,
493 ARRAY_SIZE(lr_lineout_gain_texts), 490 lr_lineout_gain_texts);
494 lr_lineout_gain_texts);
495 491
496static const struct soc_enum r_lineout_gain_enum = 492static SOC_ENUM_SINGLE_DECL(r_lineout_gain_enum,
497 SOC_ENUM_SINGLE(DAC33_RDAC_PWR_CTRL, 0, 493 DAC33_RDAC_PWR_CTRL, 0,
498 ARRAY_SIZE(lr_lineout_gain_texts), 494 lr_lineout_gain_texts);
499 lr_lineout_gain_texts);
500 495
501/* 496/*
502 * DACL/R digital volume control: 497 * DACL/R digital volume control:
@@ -534,18 +529,16 @@ static const struct snd_kcontrol_new dac33_dapm_abypassr_control =
534/* LOP L/R invert selection */ 529/* LOP L/R invert selection */
535static const char *dac33_lr_lom_texts[] = {"DAC", "LOP"}; 530static const char *dac33_lr_lom_texts[] = {"DAC", "LOP"};
536 531
537static const struct soc_enum dac33_left_lom_enum = 532static SOC_ENUM_SINGLE_DECL(dac33_left_lom_enum,
538 SOC_ENUM_SINGLE(DAC33_OUT_AMP_CTRL, 3, 533 DAC33_OUT_AMP_CTRL, 3,
539 ARRAY_SIZE(dac33_lr_lom_texts), 534 dac33_lr_lom_texts);
540 dac33_lr_lom_texts);
541 535
542static const struct snd_kcontrol_new dac33_dapm_left_lom_control = 536static const struct snd_kcontrol_new dac33_dapm_left_lom_control =
543SOC_DAPM_ENUM("Route", dac33_left_lom_enum); 537SOC_DAPM_ENUM("Route", dac33_left_lom_enum);
544 538
545static const struct soc_enum dac33_right_lom_enum = 539static SOC_ENUM_SINGLE_DECL(dac33_right_lom_enum,
546 SOC_ENUM_SINGLE(DAC33_OUT_AMP_CTRL, 2, 540 DAC33_OUT_AMP_CTRL, 2,
547 ARRAY_SIZE(dac33_lr_lom_texts), 541 dac33_lr_lom_texts);
548 dac33_lr_lom_texts);
549 542
550static const struct snd_kcontrol_new dac33_dapm_right_lom_control = 543static const struct snd_kcontrol_new dac33_dapm_right_lom_control =
551SOC_DAPM_ENUM("Route", dac33_right_lom_enum); 544SOC_DAPM_ENUM("Route", dac33_right_lom_enum);
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 00665ada23e2..975e0f760ac1 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -415,10 +415,9 @@ static const struct snd_kcontrol_new twl4030_dapm_carkitr_controls[] = {
415static const char *twl4030_handsfreel_texts[] = 415static const char *twl4030_handsfreel_texts[] =
416 {"Voice", "AudioL1", "AudioL2", "AudioR2"}; 416 {"Voice", "AudioL1", "AudioL2", "AudioR2"};
417 417
418static const struct soc_enum twl4030_handsfreel_enum = 418static SOC_ENUM_SINGLE_DECL(twl4030_handsfreel_enum,
419 SOC_ENUM_SINGLE(TWL4030_REG_HFL_CTL, 0, 419 TWL4030_REG_HFL_CTL, 0,
420 ARRAY_SIZE(twl4030_handsfreel_texts), 420 twl4030_handsfreel_texts);
421 twl4030_handsfreel_texts);
422 421
423static const struct snd_kcontrol_new twl4030_dapm_handsfreel_control = 422static const struct snd_kcontrol_new twl4030_dapm_handsfreel_control =
424SOC_DAPM_ENUM("Route", twl4030_handsfreel_enum); 423SOC_DAPM_ENUM("Route", twl4030_handsfreel_enum);
@@ -431,10 +430,9 @@ static const struct snd_kcontrol_new twl4030_dapm_handsfreelmute_control =
431static const char *twl4030_handsfreer_texts[] = 430static const char *twl4030_handsfreer_texts[] =
432 {"Voice", "AudioR1", "AudioR2", "AudioL2"}; 431 {"Voice", "AudioR1", "AudioR2", "AudioL2"};
433 432
434static const struct soc_enum twl4030_handsfreer_enum = 433static SOC_ENUM_SINGLE_DECL(twl4030_handsfreer_enum,
435 SOC_ENUM_SINGLE(TWL4030_REG_HFR_CTL, 0, 434 TWL4030_REG_HFR_CTL, 0,
436 ARRAY_SIZE(twl4030_handsfreer_texts), 435 twl4030_handsfreer_texts);
437 twl4030_handsfreer_texts);
438 436
439static const struct snd_kcontrol_new twl4030_dapm_handsfreer_control = 437static const struct snd_kcontrol_new twl4030_dapm_handsfreer_control =
440SOC_DAPM_ENUM("Route", twl4030_handsfreer_enum); 438SOC_DAPM_ENUM("Route", twl4030_handsfreer_enum);
@@ -448,10 +446,9 @@ static const struct snd_kcontrol_new twl4030_dapm_handsfreermute_control =
448static const char *twl4030_vibra_texts[] = 446static const char *twl4030_vibra_texts[] =
449 {"AudioL1", "AudioR1", "AudioL2", "AudioR2"}; 447 {"AudioL1", "AudioR1", "AudioL2", "AudioR2"};
450 448
451static const struct soc_enum twl4030_vibra_enum = 449static SOC_ENUM_SINGLE_DECL(twl4030_vibra_enum,
452 SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 2, 450 TWL4030_REG_VIBRA_CTL, 2,
453 ARRAY_SIZE(twl4030_vibra_texts), 451 twl4030_vibra_texts);
454 twl4030_vibra_texts);
455 452
456static const struct snd_kcontrol_new twl4030_dapm_vibra_control = 453static const struct snd_kcontrol_new twl4030_dapm_vibra_control =
457SOC_DAPM_ENUM("Route", twl4030_vibra_enum); 454SOC_DAPM_ENUM("Route", twl4030_vibra_enum);
@@ -460,10 +457,9 @@ SOC_DAPM_ENUM("Route", twl4030_vibra_enum);
460static const char *twl4030_vibrapath_texts[] = 457static const char *twl4030_vibrapath_texts[] =
461 {"Local vibrator", "Audio"}; 458 {"Local vibrator", "Audio"};
462 459
463static const struct soc_enum twl4030_vibrapath_enum = 460static SOC_ENUM_SINGLE_DECL(twl4030_vibrapath_enum,
464 SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 4, 461 TWL4030_REG_VIBRA_CTL, 4,
465 ARRAY_SIZE(twl4030_vibrapath_texts), 462 twl4030_vibrapath_texts);
466 twl4030_vibrapath_texts);
467 463
468static const struct snd_kcontrol_new twl4030_dapm_vibrapath_control = 464static const struct snd_kcontrol_new twl4030_dapm_vibrapath_control =
469SOC_DAPM_ENUM("Route", twl4030_vibrapath_enum); 465SOC_DAPM_ENUM("Route", twl4030_vibrapath_enum);
@@ -490,10 +486,9 @@ static const struct snd_kcontrol_new twl4030_dapm_analogrmic_controls[] = {
490static const char *twl4030_micpathtx1_texts[] = 486static const char *twl4030_micpathtx1_texts[] =
491 {"Analog", "Digimic0"}; 487 {"Analog", "Digimic0"};
492 488
493static const struct soc_enum twl4030_micpathtx1_enum = 489static SOC_ENUM_SINGLE_DECL(twl4030_micpathtx1_enum,
494 SOC_ENUM_SINGLE(TWL4030_REG_ADCMICSEL, 0, 490 TWL4030_REG_ADCMICSEL, 0,
495 ARRAY_SIZE(twl4030_micpathtx1_texts), 491 twl4030_micpathtx1_texts);
496 twl4030_micpathtx1_texts);
497 492
498static const struct snd_kcontrol_new twl4030_dapm_micpathtx1_control = 493static const struct snd_kcontrol_new twl4030_dapm_micpathtx1_control =
499SOC_DAPM_ENUM("Route", twl4030_micpathtx1_enum); 494SOC_DAPM_ENUM("Route", twl4030_micpathtx1_enum);
@@ -502,10 +497,9 @@ SOC_DAPM_ENUM("Route", twl4030_micpathtx1_enum);
502static const char *twl4030_micpathtx2_texts[] = 497static const char *twl4030_micpathtx2_texts[] =
503 {"Analog", "Digimic1"}; 498 {"Analog", "Digimic1"};
504 499
505static const struct soc_enum twl4030_micpathtx2_enum = 500static SOC_ENUM_SINGLE_DECL(twl4030_micpathtx2_enum,
506 SOC_ENUM_SINGLE(TWL4030_REG_ADCMICSEL, 2, 501 TWL4030_REG_ADCMICSEL, 2,
507 ARRAY_SIZE(twl4030_micpathtx2_texts), 502 twl4030_micpathtx2_texts);
508 twl4030_micpathtx2_texts);
509 503
510static const struct snd_kcontrol_new twl4030_dapm_micpathtx2_control = 504static const struct snd_kcontrol_new twl4030_dapm_micpathtx2_control =
511SOC_DAPM_ENUM("Route", twl4030_micpathtx2_enum); 505SOC_DAPM_ENUM("Route", twl4030_micpathtx2_enum);
@@ -955,19 +949,15 @@ static const char *twl4030_op_modes_texts[] = {
955 "Option 2 (voice/audio)", "Option 1 (audio)" 949 "Option 2 (voice/audio)", "Option 1 (audio)"
956}; 950};
957 951
958static const struct soc_enum twl4030_op_modes_enum = 952static SOC_ENUM_SINGLE_DECL(twl4030_op_modes_enum,
959 SOC_ENUM_SINGLE(TWL4030_REG_CODEC_MODE, 0, 953 TWL4030_REG_CODEC_MODE, 0,
960 ARRAY_SIZE(twl4030_op_modes_texts), 954 twl4030_op_modes_texts);
961 twl4030_op_modes_texts);
962 955
963static int snd_soc_put_twl4030_opmode_enum_double(struct snd_kcontrol *kcontrol, 956static int snd_soc_put_twl4030_opmode_enum_double(struct snd_kcontrol *kcontrol,
964 struct snd_ctl_elem_value *ucontrol) 957 struct snd_ctl_elem_value *ucontrol)
965{ 958{
966 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 959 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
967 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); 960 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
968 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
969 unsigned short val;
970 unsigned short mask;
971 961
972 if (twl4030->configured) { 962 if (twl4030->configured) {
973 dev_err(codec->dev, 963 dev_err(codec->dev,
@@ -975,19 +965,7 @@ static int snd_soc_put_twl4030_opmode_enum_double(struct snd_kcontrol *kcontrol,
975 return -EBUSY; 965 return -EBUSY;
976 } 966 }
977 967
978 if (ucontrol->value.enumerated.item[0] > e->max - 1) 968 return snd_soc_put_enum_double(kcontrol, ucontrol);
979 return -EINVAL;
980
981 val = ucontrol->value.enumerated.item[0] << e->shift_l;
982 mask = e->mask << e->shift_l;
983 if (e->shift_l != e->shift_r) {
984 if (ucontrol->value.enumerated.item[1] > e->max - 1)
985 return -EINVAL;
986 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
987 mask |= e->mask << e->shift_r;
988 }
989
990 return snd_soc_update_bits(codec, e->reg, mask, val);
991} 969}
992 970
993/* 971/*
@@ -1044,10 +1022,9 @@ static const char *twl4030_avadc_clk_priority_texts[] = {
1044 "Voice high priority", "HiFi high priority" 1022 "Voice high priority", "HiFi high priority"
1045}; 1023};
1046 1024
1047static const struct soc_enum twl4030_avadc_clk_priority_enum = 1025static SOC_ENUM_SINGLE_DECL(twl4030_avadc_clk_priority_enum,
1048 SOC_ENUM_SINGLE(TWL4030_REG_AVADC_CTL, 2, 1026 TWL4030_REG_AVADC_CTL, 2,
1049 ARRAY_SIZE(twl4030_avadc_clk_priority_texts), 1027 twl4030_avadc_clk_priority_texts);
1050 twl4030_avadc_clk_priority_texts);
1051 1028
1052static const char *twl4030_rampdelay_texts[] = { 1029static const char *twl4030_rampdelay_texts[] = {
1053 "27/20/14 ms", "55/40/27 ms", "109/81/55 ms", "218/161/109 ms", 1030 "27/20/14 ms", "55/40/27 ms", "109/81/55 ms", "218/161/109 ms",
@@ -1055,40 +1032,36 @@ static const char *twl4030_rampdelay_texts[] = {
1055 "3495/2581/1748 ms" 1032 "3495/2581/1748 ms"
1056}; 1033};
1057 1034
1058static const struct soc_enum twl4030_rampdelay_enum = 1035static SOC_ENUM_SINGLE_DECL(twl4030_rampdelay_enum,
1059 SOC_ENUM_SINGLE(TWL4030_REG_HS_POPN_SET, 2, 1036 TWL4030_REG_HS_POPN_SET, 2,
1060 ARRAY_SIZE(twl4030_rampdelay_texts), 1037 twl4030_rampdelay_texts);
1061 twl4030_rampdelay_texts);
1062 1038
1063/* Vibra H-bridge direction mode */ 1039/* Vibra H-bridge direction mode */
1064static const char *twl4030_vibradirmode_texts[] = { 1040static const char *twl4030_vibradirmode_texts[] = {
1065 "Vibra H-bridge direction", "Audio data MSB", 1041 "Vibra H-bridge direction", "Audio data MSB",
1066}; 1042};
1067 1043
1068static const struct soc_enum twl4030_vibradirmode_enum = 1044static SOC_ENUM_SINGLE_DECL(twl4030_vibradirmode_enum,
1069 SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 5, 1045 TWL4030_REG_VIBRA_CTL, 5,
1070 ARRAY_SIZE(twl4030_vibradirmode_texts), 1046 twl4030_vibradirmode_texts);
1071 twl4030_vibradirmode_texts);
1072 1047
1073/* Vibra H-bridge direction */ 1048/* Vibra H-bridge direction */
1074static const char *twl4030_vibradir_texts[] = { 1049static const char *twl4030_vibradir_texts[] = {
1075 "Positive polarity", "Negative polarity", 1050 "Positive polarity", "Negative polarity",
1076}; 1051};
1077 1052
1078static const struct soc_enum twl4030_vibradir_enum = 1053static SOC_ENUM_SINGLE_DECL(twl4030_vibradir_enum,
1079 SOC_ENUM_SINGLE(TWL4030_REG_VIBRA_CTL, 1, 1054 TWL4030_REG_VIBRA_CTL, 1,
1080 ARRAY_SIZE(twl4030_vibradir_texts), 1055 twl4030_vibradir_texts);
1081 twl4030_vibradir_texts);
1082 1056
1083/* Digimic Left and right swapping */ 1057/* Digimic Left and right swapping */
1084static const char *twl4030_digimicswap_texts[] = { 1058static const char *twl4030_digimicswap_texts[] = {
1085 "Not swapped", "Swapped", 1059 "Not swapped", "Swapped",
1086}; 1060};
1087 1061
1088static const struct soc_enum twl4030_digimicswap_enum = 1062static SOC_ENUM_SINGLE_DECL(twl4030_digimicswap_enum,
1089 SOC_ENUM_SINGLE(TWL4030_REG_MISC_SET_1, 0, 1063 TWL4030_REG_MISC_SET_1, 0,
1090 ARRAY_SIZE(twl4030_digimicswap_texts), 1064 twl4030_digimicswap_texts);
1091 twl4030_digimicswap_texts);
1092 1065
1093static const struct snd_kcontrol_new twl4030_snd_controls[] = { 1066static const struct snd_kcontrol_new twl4030_snd_controls[] = {
1094 /* Codec operation mode control */ 1067 /* Codec operation mode control */
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c
index 0afe8bef6765..bd3a20647fdf 100644
--- a/sound/soc/codecs/twl6040.c
+++ b/sound/soc/codecs/twl6040.c
@@ -81,7 +81,7 @@ struct twl6040_data {
81}; 81};
82 82
83/* set of rates for each pll: low-power and high-performance */ 83/* set of rates for each pll: low-power and high-performance */
84static unsigned int lp_rates[] = { 84static const unsigned int lp_rates[] = {
85 8000, 85 8000,
86 11250, 86 11250,
87 16000, 87 16000,
@@ -93,7 +93,7 @@ static unsigned int lp_rates[] = {
93 96000, 93 96000,
94}; 94};
95 95
96static unsigned int hp_rates[] = { 96static const unsigned int hp_rates[] = {
97 8000, 97 8000,
98 16000, 98 16000,
99 32000, 99 32000,
@@ -101,7 +101,7 @@ static unsigned int hp_rates[] = {
101 96000, 101 96000,
102}; 102};
103 103
104static struct snd_pcm_hw_constraint_list sysclk_constraints[] = { 104static const struct snd_pcm_hw_constraint_list sysclk_constraints[] = {
105 { .count = ARRAY_SIZE(lp_rates), .list = lp_rates, }, 105 { .count = ARRAY_SIZE(lp_rates), .list = lp_rates, },
106 { .count = ARRAY_SIZE(hp_rates), .list = hp_rates, }, 106 { .count = ARRAY_SIZE(hp_rates), .list = hp_rates, },
107}; 107};
@@ -392,8 +392,10 @@ static const char *twl6040_amicr_texts[] =
392 {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"}; 392 {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"};
393 393
394static const struct soc_enum twl6040_enum[] = { 394static const struct soc_enum twl6040_enum[] = {
395 SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 4, twl6040_amicl_texts), 395 SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3,
396 SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 4, twl6040_amicr_texts), 396 ARRAY_SIZE(twl6040_amicl_texts), twl6040_amicl_texts),
397 SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3,
398 ARRAY_SIZE(twl6040_amicr_texts), twl6040_amicr_texts),
397}; 399};
398 400
399static const char *twl6040_hs_texts[] = { 401static const char *twl6040_hs_texts[] = {
@@ -476,9 +478,8 @@ static const char *twl6040_power_mode_texts[] = {
476 "Low-Power", "High-Performance", 478 "Low-Power", "High-Performance",
477}; 479};
478 480
479static const struct soc_enum twl6040_power_mode_enum = 481static SOC_ENUM_SINGLE_EXT_DECL(twl6040_power_mode_enum,
480 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(twl6040_power_mode_texts), 482 twl6040_power_mode_texts);
481 twl6040_power_mode_texts);
482 483
483static int twl6040_headset_power_get_enum(struct snd_kcontrol *kcontrol, 484static int twl6040_headset_power_get_enum(struct snd_kcontrol *kcontrol,
484 struct snd_ctl_elem_value *ucontrol) 485 struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c
index c94d4c1e3dac..edf27acc1d77 100644
--- a/sound/soc/codecs/uda134x.c
+++ b/sound/soc/codecs/uda134x.c
@@ -203,8 +203,7 @@ static int uda134x_hw_params(struct snd_pcm_substream *substream,
203 struct snd_pcm_hw_params *params, 203 struct snd_pcm_hw_params *params,
204 struct snd_soc_dai *dai) 204 struct snd_soc_dai *dai)
205{ 205{
206 struct snd_soc_pcm_runtime *rtd = substream->private_data; 206 struct snd_soc_codec *codec = dai->codec;
207 struct snd_soc_codec *codec = rtd->codec;
208 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); 207 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
209 u8 hw_params; 208 u8 hw_params;
210 209
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index 726df6d43c2b..e62e70781ec2 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -108,7 +108,7 @@ static int uda1380_write(struct snd_soc_codec *codec, unsigned int reg,
108 /* the interpolator & decimator regs must only be written when the 108 /* the interpolator & decimator regs must only be written when the
109 * codec DAI is active. 109 * codec DAI is active.
110 */ 110 */
111 if (!codec->active && (reg >= UDA1380_MVOL)) 111 if (!snd_soc_codec_is_active(codec) && (reg >= UDA1380_MVOL))
112 return 0; 112 return 0;
113 pr_debug("uda1380: hw write %x val %x\n", reg, value); 113 pr_debug("uda1380: hw write %x val %x\n", reg, value);
114 if (codec->hw_write(codec->control_data, data, 3) == 3) { 114 if (codec->hw_write(codec->control_data, data, 3) == 3) {
@@ -237,25 +237,27 @@ static const char *uda1380_os_setting[] = {
237}; 237};
238 238
239static const struct soc_enum uda1380_deemp_enum[] = { 239static const struct soc_enum uda1380_deemp_enum[] = {
240 SOC_ENUM_SINGLE(UDA1380_DEEMP, 8, 5, uda1380_deemp), 240 SOC_ENUM_SINGLE(UDA1380_DEEMP, 8, ARRAY_SIZE(uda1380_deemp),
241 SOC_ENUM_SINGLE(UDA1380_DEEMP, 0, 5, uda1380_deemp), 241 uda1380_deemp),
242 SOC_ENUM_SINGLE(UDA1380_DEEMP, 0, ARRAY_SIZE(uda1380_deemp),
243 uda1380_deemp),
242}; 244};
243static const struct soc_enum uda1380_input_sel_enum = 245static SOC_ENUM_SINGLE_DECL(uda1380_input_sel_enum,
244 SOC_ENUM_SINGLE(UDA1380_ADC, 2, 4, uda1380_input_sel); /* SEL_MIC, SEL_LNA */ 246 UDA1380_ADC, 2, uda1380_input_sel); /* SEL_MIC, SEL_LNA */
245static const struct soc_enum uda1380_output_sel_enum = 247static SOC_ENUM_SINGLE_DECL(uda1380_output_sel_enum,
246 SOC_ENUM_SINGLE(UDA1380_PM, 7, 2, uda1380_output_sel); /* R02_EN_AVC */ 248 UDA1380_PM, 7, uda1380_output_sel); /* R02_EN_AVC */
247static const struct soc_enum uda1380_spf_enum = 249static SOC_ENUM_SINGLE_DECL(uda1380_spf_enum,
248 SOC_ENUM_SINGLE(UDA1380_MODE, 14, 4, uda1380_spf_mode); /* M */ 250 UDA1380_MODE, 14, uda1380_spf_mode); /* M */
249static const struct soc_enum uda1380_capture_sel_enum = 251static SOC_ENUM_SINGLE_DECL(uda1380_capture_sel_enum,
250 SOC_ENUM_SINGLE(UDA1380_IFACE, 6, 2, uda1380_capture_sel); /* SEL_SOURCE */ 252 UDA1380_IFACE, 6, uda1380_capture_sel); /* SEL_SOURCE */
251static const struct soc_enum uda1380_sel_ns_enum = 253static SOC_ENUM_SINGLE_DECL(uda1380_sel_ns_enum,
252 SOC_ENUM_SINGLE(UDA1380_MIXER, 14, 2, uda1380_sel_ns); /* SEL_NS */ 254 UDA1380_MIXER, 14, uda1380_sel_ns); /* SEL_NS */
253static const struct soc_enum uda1380_mix_enum = 255static SOC_ENUM_SINGLE_DECL(uda1380_mix_enum,
254 SOC_ENUM_SINGLE(UDA1380_MIXER, 12, 4, uda1380_mix_control); /* MIX, MIX_POS */ 256 UDA1380_MIXER, 12, uda1380_mix_control); /* MIX, MIX_POS */
255static const struct soc_enum uda1380_sdet_enum = 257static SOC_ENUM_SINGLE_DECL(uda1380_sdet_enum,
256 SOC_ENUM_SINGLE(UDA1380_MIXER, 4, 4, uda1380_sdet_setting); /* SD_VALUE */ 258 UDA1380_MIXER, 4, uda1380_sdet_setting); /* SD_VALUE */
257static const struct soc_enum uda1380_os_enum = 259static SOC_ENUM_SINGLE_DECL(uda1380_os_enum,
258 SOC_ENUM_SINGLE(UDA1380_MIXER, 0, 3, uda1380_os_setting); /* OS */ 260 UDA1380_MIXER, 0, uda1380_os_setting); /* OS */
259 261
260/* 262/*
261 * from -48 dB in 1.5 dB steps (mute instead of -49.5 dB) 263 * from -48 dB in 1.5 dB steps (mute instead of -49.5 dB)
@@ -564,8 +566,7 @@ static int uda1380_pcm_hw_params(struct snd_pcm_substream *substream,
564static void uda1380_pcm_shutdown(struct snd_pcm_substream *substream, 566static void uda1380_pcm_shutdown(struct snd_pcm_substream *substream,
565 struct snd_soc_dai *dai) 567 struct snd_soc_dai *dai)
566{ 568{
567 struct snd_soc_pcm_runtime *rtd = substream->private_data; 569 struct snd_soc_codec *codec = dai->codec;
568 struct snd_soc_codec *codec = rtd->codec;
569 u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); 570 u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
570 571
571 /* shut down WSPLL power if running from this clock */ 572 /* shut down WSPLL power if running from this clock */
diff --git a/sound/soc/codecs/wl1273.c b/sound/soc/codecs/wl1273.c
index b7ab2ef567c8..6be5f80b65f1 100644
--- a/sound/soc/codecs/wl1273.c
+++ b/sound/soc/codecs/wl1273.c
@@ -197,7 +197,7 @@ static int snd_wl1273_set_audio_route(struct snd_kcontrol *kcontrol,
197 return 0; 197 return 0;
198 198
199 /* Do not allow changes while stream is running */ 199 /* Do not allow changes while stream is running */
200 if (codec->active) 200 if (snd_soc_codec_is_active(codec))
201 return -EPERM; 201 return -EPERM;
202 202
203 if (ucontrol->value.integer.value[0] < 0 || 203 if (ucontrol->value.integer.value[0] < 0 ||
@@ -209,8 +209,7 @@ static int snd_wl1273_set_audio_route(struct snd_kcontrol *kcontrol,
209 return 1; 209 return 1;
210} 210}
211 211
212static const struct soc_enum wl1273_enum = 212static SOC_ENUM_SINGLE_EXT_DECL(wl1273_enum, wl1273_audio_route);
213 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wl1273_audio_route), wl1273_audio_route);
214 213
215static int snd_wl1273_fm_audio_get(struct snd_kcontrol *kcontrol, 214static int snd_wl1273_fm_audio_get(struct snd_kcontrol *kcontrol,
216 struct snd_ctl_elem_value *ucontrol) 215 struct snd_ctl_elem_value *ucontrol)
@@ -247,9 +246,7 @@ static int snd_wl1273_fm_audio_put(struct snd_kcontrol *kcontrol,
247 246
248static const char * const wl1273_audio_strings[] = { "Digital", "Analog" }; 247static const char * const wl1273_audio_strings[] = { "Digital", "Analog" };
249 248
250static const struct soc_enum wl1273_audio_enum = 249static SOC_ENUM_SINGLE_EXT_DECL(wl1273_audio_enum, wl1273_audio_strings);
251 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wl1273_audio_strings),
252 wl1273_audio_strings);
253 250
254static int snd_wl1273_fm_volume_get(struct snd_kcontrol *kcontrol, 251static int snd_wl1273_fm_volume_get(struct snd_kcontrol *kcontrol,
255 struct snd_ctl_elem_value *ucontrol) 252 struct snd_ctl_elem_value *ucontrol)
diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c
index 8ae50274ea8f..83a2c872925c 100644
--- a/sound/soc/codecs/wm2000.c
+++ b/sound/soc/codecs/wm2000.c
@@ -786,8 +786,6 @@ static int wm2000_probe(struct snd_soc_codec *codec)
786{ 786{
787 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev); 787 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev);
788 788
789 snd_soc_codec_set_cache_io(codec, 16, 8, SND_SOC_REGMAP);
790
791 /* This will trigger a transition to standby mode by default */ 789 /* This will trigger a transition to standby mode by default */
792 wm2000_anc_set_mode(wm2000); 790 wm2000_anc_set_mode(wm2000);
793 791
diff --git a/sound/soc/codecs/wm2200.c b/sound/soc/codecs/wm2200.c
index 57ba315d0c84..2e721e06671b 100644
--- a/sound/soc/codecs/wm2200.c
+++ b/sound/soc/codecs/wm2200.c
@@ -1113,11 +1113,10 @@ static const char *wm2200_rxanc_input_sel_texts[] = {
1113 "None", "IN1", "IN2", "IN3", 1113 "None", "IN1", "IN2", "IN3",
1114}; 1114};
1115 1115
1116static const struct soc_enum wm2200_rxanc_input_sel = 1116static SOC_ENUM_SINGLE_DECL(wm2200_rxanc_input_sel,
1117 SOC_ENUM_SINGLE(WM2200_RXANC_SRC, 1117 WM2200_RXANC_SRC,
1118 WM2200_IN_RXANC_SEL_SHIFT, 1118 WM2200_IN_RXANC_SEL_SHIFT,
1119 ARRAY_SIZE(wm2200_rxanc_input_sel_texts), 1119 wm2200_rxanc_input_sel_texts);
1120 wm2200_rxanc_input_sel_texts);
1121 1120
1122static const struct snd_kcontrol_new wm2200_snd_controls[] = { 1121static const struct snd_kcontrol_new wm2200_snd_controls[] = {
1123SOC_SINGLE("IN1 High Performance Switch", WM2200_IN1L_CONTROL, 1122SOC_SINGLE("IN1 High Performance Switch", WM2200_IN1L_CONTROL,
@@ -1288,11 +1287,10 @@ static const char *wm2200_aec_loopback_texts[] = {
1288 "OUT1L", "OUT1R", "OUT2L", "OUT2R", 1287 "OUT1L", "OUT1R", "OUT2L", "OUT2R",
1289}; 1288};
1290 1289
1291static const struct soc_enum wm2200_aec_loopback = 1290static SOC_ENUM_SINGLE_DECL(wm2200_aec_loopback,
1292 SOC_ENUM_SINGLE(WM2200_DAC_AEC_CONTROL_1, 1291 WM2200_DAC_AEC_CONTROL_1,
1293 WM2200_AEC_LOOPBACK_SRC_SHIFT, 1292 WM2200_AEC_LOOPBACK_SRC_SHIFT,
1294 ARRAY_SIZE(wm2200_aec_loopback_texts), 1293 wm2200_aec_loopback_texts);
1295 wm2200_aec_loopback_texts);
1296 1294
1297static const struct snd_kcontrol_new wm2200_aec_loopback_mux = 1295static const struct snd_kcontrol_new wm2200_aec_loopback_mux =
1298 SOC_DAPM_ENUM("AEC Loopback", wm2200_aec_loopback); 1296 SOC_DAPM_ENUM("AEC Loopback", wm2200_aec_loopback);
@@ -1556,15 +1554,8 @@ static int wm2200_probe(struct snd_soc_codec *codec)
1556 int ret; 1554 int ret;
1557 1555
1558 wm2200->codec = codec; 1556 wm2200->codec = codec;
1559 codec->control_data = wm2200->regmap;
1560 codec->dapm.bias_level = SND_SOC_BIAS_OFF; 1557 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
1561 1558
1562 ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
1563 if (ret != 0) {
1564 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1565 return ret;
1566 }
1567
1568 ret = snd_soc_add_codec_controls(codec, wm_adsp1_fw_controls, 2); 1559 ret = snd_soc_add_codec_controls(codec, wm_adsp1_fw_controls, 2);
1569 if (ret != 0) 1560 if (ret != 0)
1570 return ret; 1561 return ret;
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c
index 4e3e31aaf509..eca983fad891 100644
--- a/sound/soc/codecs/wm5100.c
+++ b/sound/soc/codecs/wm5100.c
@@ -506,21 +506,21 @@ static const char *wm5100_lhpf_mode_text[] = {
506 "Low-pass", "High-pass" 506 "Low-pass", "High-pass"
507}; 507};
508 508
509static const struct soc_enum wm5100_lhpf1_mode = 509static SOC_ENUM_SINGLE_DECL(wm5100_lhpf1_mode,
510 SOC_ENUM_SINGLE(WM5100_HPLPF1_1, WM5100_LHPF1_MODE_SHIFT, 2, 510 WM5100_HPLPF1_1, WM5100_LHPF1_MODE_SHIFT,
511 wm5100_lhpf_mode_text); 511 wm5100_lhpf_mode_text);
512 512
513static const struct soc_enum wm5100_lhpf2_mode = 513static SOC_ENUM_SINGLE_DECL(wm5100_lhpf2_mode,
514 SOC_ENUM_SINGLE(WM5100_HPLPF2_1, WM5100_LHPF2_MODE_SHIFT, 2, 514 WM5100_HPLPF2_1, WM5100_LHPF2_MODE_SHIFT,
515 wm5100_lhpf_mode_text); 515 wm5100_lhpf_mode_text);
516 516
517static const struct soc_enum wm5100_lhpf3_mode = 517static SOC_ENUM_SINGLE_DECL(wm5100_lhpf3_mode,
518 SOC_ENUM_SINGLE(WM5100_HPLPF3_1, WM5100_LHPF3_MODE_SHIFT, 2, 518 WM5100_HPLPF3_1, WM5100_LHPF3_MODE_SHIFT,
519 wm5100_lhpf_mode_text); 519 wm5100_lhpf_mode_text);
520 520
521static const struct soc_enum wm5100_lhpf4_mode = 521static SOC_ENUM_SINGLE_DECL(wm5100_lhpf4_mode,
522 SOC_ENUM_SINGLE(WM5100_HPLPF4_1, WM5100_LHPF4_MODE_SHIFT, 2, 522 WM5100_HPLPF4_1, WM5100_LHPF4_MODE_SHIFT,
523 wm5100_lhpf_mode_text); 523 wm5100_lhpf_mode_text);
524 524
525static const struct snd_kcontrol_new wm5100_snd_controls[] = { 525static const struct snd_kcontrol_new wm5100_snd_controls[] = {
526SOC_SINGLE("IN1 High Performance Switch", WM5100_IN1L_CONTROL, 526SOC_SINGLE("IN1 High Performance Switch", WM5100_IN1L_CONTROL,
@@ -2100,6 +2100,7 @@ static void wm5100_micd_irq(struct wm5100_priv *wm5100)
2100int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack) 2100int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
2101{ 2101{
2102 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); 2102 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
2103 struct snd_soc_dapm_context *dapm = &codec->dapm;
2103 2104
2104 if (jack) { 2105 if (jack) {
2105 wm5100->jack = jack; 2106 wm5100->jack = jack;
@@ -2117,9 +2118,14 @@ int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
2117 WM5100_ACCDET_RATE_MASK); 2118 WM5100_ACCDET_RATE_MASK);
2118 2119
2119 /* We need the charge pump to power MICBIAS */ 2120 /* We need the charge pump to power MICBIAS */
2120 snd_soc_dapm_force_enable_pin(&codec->dapm, "CP2"); 2121 snd_soc_dapm_mutex_lock(dapm);
2121 snd_soc_dapm_force_enable_pin(&codec->dapm, "SYSCLK"); 2122
2122 snd_soc_dapm_sync(&codec->dapm); 2123 snd_soc_dapm_force_enable_pin_unlocked(dapm, "CP2");
2124 snd_soc_dapm_force_enable_pin_unlocked(dapm, "SYSCLK");
2125
2126 snd_soc_dapm_sync_unlocked(dapm);
2127
2128 snd_soc_dapm_mutex_unlock(dapm);
2123 2129
2124 /* We start off just enabling microphone detection - even a 2130 /* We start off just enabling microphone detection - even a
2125 * plain headphone will trigger detection. 2131 * plain headphone will trigger detection.
@@ -2337,13 +2343,6 @@ static int wm5100_probe(struct snd_soc_codec *codec)
2337 int ret, i; 2343 int ret, i;
2338 2344
2339 wm5100->codec = codec; 2345 wm5100->codec = codec;
2340 codec->control_data = wm5100->regmap;
2341
2342 ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
2343 if (ret != 0) {
2344 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
2345 return ret;
2346 }
2347 2346
2348 for (i = 0; i < ARRAY_SIZE(wm5100_dig_vu); i++) 2347 for (i = 0; i < ARRAY_SIZE(wm5100_dig_vu); i++)
2349 snd_soc_update_bits(codec, wm5100_dig_vu[i], WM5100_OUT_VU, 2348 snd_soc_update_bits(codec, wm5100_dig_vu[i], WM5100_OUT_VU,
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index ce9c8e14d4bd..dcf1d12cfef8 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -582,7 +582,7 @@ static int wm5102_sysclk_ev(struct snd_soc_dapm_widget *w,
582{ 582{
583 struct snd_soc_codec *codec = w->codec; 583 struct snd_soc_codec *codec = w->codec;
584 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 584 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
585 struct regmap *regmap = codec->control_data; 585 struct regmap *regmap = arizona->regmap;
586 const struct reg_default *patch = NULL; 586 const struct reg_default *patch = NULL;
587 int i, patch_size; 587 int i, patch_size;
588 588
@@ -622,13 +622,16 @@ static const unsigned int wm5102_osr_val[] = {
622 622
623static const struct soc_enum wm5102_hpout_osr[] = { 623static const struct soc_enum wm5102_hpout_osr[] = {
624 SOC_VALUE_ENUM_SINGLE(ARIZONA_OUTPUT_PATH_CONFIG_1L, 624 SOC_VALUE_ENUM_SINGLE(ARIZONA_OUTPUT_PATH_CONFIG_1L,
625 ARIZONA_OUT1_OSR_SHIFT, 0x7, 3, 625 ARIZONA_OUT1_OSR_SHIFT, 0x7,
626 ARRAY_SIZE(wm5102_osr_text),
626 wm5102_osr_text, wm5102_osr_val), 627 wm5102_osr_text, wm5102_osr_val),
627 SOC_VALUE_ENUM_SINGLE(ARIZONA_OUTPUT_PATH_CONFIG_2L, 628 SOC_VALUE_ENUM_SINGLE(ARIZONA_OUTPUT_PATH_CONFIG_2L,
628 ARIZONA_OUT2_OSR_SHIFT, 0x7, 3, 629 ARIZONA_OUT2_OSR_SHIFT, 0x7,
630 ARRAY_SIZE(wm5102_osr_text),
629 wm5102_osr_text, wm5102_osr_val), 631 wm5102_osr_text, wm5102_osr_val),
630 SOC_VALUE_ENUM_SINGLE(ARIZONA_OUTPUT_PATH_CONFIG_3L, 632 SOC_VALUE_ENUM_SINGLE(ARIZONA_OUTPUT_PATH_CONFIG_3L,
631 ARIZONA_OUT3_OSR_SHIFT, 0x7, 3, 633 ARIZONA_OUT3_OSR_SHIFT, 0x7,
634 ARRAY_SIZE(wm5102_osr_text),
632 wm5102_osr_text, wm5102_osr_val), 635 wm5102_osr_text, wm5102_osr_val),
633}; 636};
634 637
@@ -685,15 +688,8 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
685ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE), 688ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
686ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE), 689ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
687 690
688SND_SOC_BYTES_MASK("EQ1 Coefficients", ARIZONA_EQ1_1, 21, 691SND_SOC_BYTES("EQ1 Coefficients", ARIZONA_EQ1_3, 19),
689 ARIZONA_EQ1_ENA_MASK), 692SOC_SINGLE("EQ1 Mode Switch", ARIZONA_EQ1_2, ARIZONA_EQ1_B1_MODE, 1, 0),
690SND_SOC_BYTES_MASK("EQ2 Coefficients", ARIZONA_EQ2_1, 21,
691 ARIZONA_EQ2_ENA_MASK),
692SND_SOC_BYTES_MASK("EQ3 Coefficients", ARIZONA_EQ3_1, 21,
693 ARIZONA_EQ3_ENA_MASK),
694SND_SOC_BYTES_MASK("EQ4 Coefficients", ARIZONA_EQ4_1, 21,
695 ARIZONA_EQ4_ENA_MASK),
696
697SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT, 693SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
698 24, 0, eq_tlv), 694 24, 0, eq_tlv),
699SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT, 695SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT,
@@ -705,6 +701,8 @@ SOC_SINGLE_TLV("EQ1 B4 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B4_GAIN_SHIFT,
705SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT, 701SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT,
706 24, 0, eq_tlv), 702 24, 0, eq_tlv),
707 703
704SND_SOC_BYTES("EQ2 Coefficients", ARIZONA_EQ2_3, 19),
705SOC_SINGLE("EQ2 Mode Switch", ARIZONA_EQ2_2, ARIZONA_EQ2_B1_MODE, 1, 0),
708SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT, 706SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT,
709 24, 0, eq_tlv), 707 24, 0, eq_tlv),
710SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT, 708SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT,
@@ -716,6 +714,8 @@ SOC_SINGLE_TLV("EQ2 B4 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B4_GAIN_SHIFT,
716SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT, 714SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT,
717 24, 0, eq_tlv), 715 24, 0, eq_tlv),
718 716
717SND_SOC_BYTES("EQ3 Coefficients", ARIZONA_EQ3_3, 19),
718SOC_SINGLE("EQ3 Mode Switch", ARIZONA_EQ3_2, ARIZONA_EQ3_B1_MODE, 1, 0),
719SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT, 719SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT,
720 24, 0, eq_tlv), 720 24, 0, eq_tlv),
721SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT, 721SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT,
@@ -727,6 +727,8 @@ SOC_SINGLE_TLV("EQ3 B4 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B4_GAIN_SHIFT,
727SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT, 727SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT,
728 24, 0, eq_tlv), 728 24, 0, eq_tlv),
729 729
730SND_SOC_BYTES("EQ4 Coefficients", ARIZONA_EQ4_3, 19),
731SOC_SINGLE("EQ4 Mode Switch", ARIZONA_EQ4_2, ARIZONA_EQ4_B1_MODE, 1, 0),
730SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT, 732SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT,
731 24, 0, eq_tlv), 733 24, 0, eq_tlv),
732SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT, 734SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT,
@@ -1758,9 +1760,7 @@ static int wm5102_codec_probe(struct snd_soc_codec *codec)
1758 struct wm5102_priv *priv = snd_soc_codec_get_drvdata(codec); 1760 struct wm5102_priv *priv = snd_soc_codec_get_drvdata(codec);
1759 int ret; 1761 int ret;
1760 1762
1761 codec->control_data = priv->core.arizona->regmap; 1763 ret = snd_soc_codec_set_cache_io(codec, priv->core.arizona->regmap);
1762
1763 ret = snd_soc_codec_set_cache_io(codec, 32, 16, SND_SOC_REGMAP);
1764 if (ret != 0) 1764 if (ret != 0)
1765 return ret; 1765 return ret;
1766 1766
diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
index 2c3c962d9a85..df5a38dd8328 100644
--- a/sound/soc/codecs/wm5110.c
+++ b/sound/soc/codecs/wm5110.c
@@ -136,7 +136,7 @@ static int wm5110_sysclk_ev(struct snd_soc_dapm_widget *w,
136{ 136{
137 struct snd_soc_codec *codec = w->codec; 137 struct snd_soc_codec *codec = w->codec;
138 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 138 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
139 struct regmap *regmap = codec->control_data; 139 struct regmap *regmap = arizona->regmap;
140 const struct reg_default *patch = NULL; 140 const struct reg_default *patch = NULL;
141 int i, patch_size; 141 int i, patch_size;
142 142
@@ -247,15 +247,8 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
247ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE), 247ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
248ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE), 248ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
249 249
250SND_SOC_BYTES_MASK("EQ1 Coefficients", ARIZONA_EQ1_1, 21, 250SND_SOC_BYTES("EQ1 Coefficients", ARIZONA_EQ1_3, 19),
251 ARIZONA_EQ1_ENA_MASK), 251SOC_SINGLE("EQ1 Mode Switch", ARIZONA_EQ1_2, ARIZONA_EQ1_B1_MODE, 1, 0),
252SND_SOC_BYTES_MASK("EQ2 Coefficients", ARIZONA_EQ2_1, 21,
253 ARIZONA_EQ2_ENA_MASK),
254SND_SOC_BYTES_MASK("EQ3 Coefficients", ARIZONA_EQ3_1, 21,
255 ARIZONA_EQ3_ENA_MASK),
256SND_SOC_BYTES_MASK("EQ4 Coefficients", ARIZONA_EQ4_1, 21,
257 ARIZONA_EQ4_ENA_MASK),
258
259SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT, 252SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
260 24, 0, eq_tlv), 253 24, 0, eq_tlv),
261SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT, 254SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT,
@@ -267,6 +260,8 @@ SOC_SINGLE_TLV("EQ1 B4 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B4_GAIN_SHIFT,
267SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT, 260SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT,
268 24, 0, eq_tlv), 261 24, 0, eq_tlv),
269 262
263SND_SOC_BYTES("EQ2 Coefficients", ARIZONA_EQ2_3, 19),
264SOC_SINGLE("EQ2 Mode Switch", ARIZONA_EQ2_2, ARIZONA_EQ2_B1_MODE, 1, 0),
270SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT, 265SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT,
271 24, 0, eq_tlv), 266 24, 0, eq_tlv),
272SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT, 267SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT,
@@ -278,6 +273,8 @@ SOC_SINGLE_TLV("EQ2 B4 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B4_GAIN_SHIFT,
278SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT, 273SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT,
279 24, 0, eq_tlv), 274 24, 0, eq_tlv),
280 275
276SND_SOC_BYTES("EQ3 Coefficients", ARIZONA_EQ3_3, 19),
277SOC_SINGLE("EQ3 Mode Switch", ARIZONA_EQ3_2, ARIZONA_EQ3_B1_MODE, 1, 0),
281SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT, 278SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT,
282 24, 0, eq_tlv), 279 24, 0, eq_tlv),
283SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT, 280SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT,
@@ -289,6 +286,8 @@ SOC_SINGLE_TLV("EQ3 B4 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B4_GAIN_SHIFT,
289SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT, 286SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT,
290 24, 0, eq_tlv), 287 24, 0, eq_tlv),
291 288
289SND_SOC_BYTES("EQ4 Coefficients", ARIZONA_EQ4_3, 19),
290SOC_SINGLE("EQ4 Mode Switch", ARIZONA_EQ4_2, ARIZONA_EQ4_B1_MODE, 1, 0),
292SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT, 291SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT,
293 24, 0, eq_tlv), 292 24, 0, eq_tlv),
294SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT, 293SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT,
@@ -1588,10 +1587,9 @@ static int wm5110_codec_probe(struct snd_soc_codec *codec)
1588 struct wm5110_priv *priv = snd_soc_codec_get_drvdata(codec); 1587 struct wm5110_priv *priv = snd_soc_codec_get_drvdata(codec);
1589 int ret; 1588 int ret;
1590 1589
1591 codec->control_data = priv->core.arizona->regmap;
1592 priv->core.arizona->dapm = &codec->dapm; 1590 priv->core.arizona->dapm = &codec->dapm;
1593 1591
1594 ret = snd_soc_codec_set_cache_io(codec, 32, 16, SND_SOC_REGMAP); 1592 ret = snd_soc_codec_set_cache_io(codec, priv->core.arizona->regmap);
1595 if (ret != 0) 1593 if (ret != 0)
1596 return ret; 1594 return ret;
1597 1595
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index a183dcf3d5c1..757256bf7672 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -1505,9 +1505,7 @@ static int wm8350_codec_probe(struct snd_soc_codec *codec)
1505 if (ret != 0) 1505 if (ret != 0)
1506 return ret; 1506 return ret;
1507 1507
1508 codec->control_data = wm8350->regmap; 1508 snd_soc_codec_set_cache_io(codec, wm8350->regmap);
1509
1510 snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1511 1509
1512 /* Put the codec into reset if it wasn't already */ 1510 /* Put the codec into reset if it wasn't already */
1513 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA); 1511 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c
index 6d684d934f4d..146564feaea0 100644
--- a/sound/soc/codecs/wm8400.c
+++ b/sound/soc/codecs/wm8400.c
@@ -1316,10 +1316,9 @@ static int wm8400_codec_probe(struct snd_soc_codec *codec)
1316 1316
1317 snd_soc_codec_set_drvdata(codec, priv); 1317 snd_soc_codec_set_drvdata(codec, priv);
1318 priv->wm8400 = wm8400; 1318 priv->wm8400 = wm8400;
1319 codec->control_data = wm8400->regmap;
1320 priv->codec = codec; 1319 priv->codec = codec;
1321 1320
1322 snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP); 1321 snd_soc_codec_set_cache_io(codec, wm8400->regmap);
1323 1322
1324 ret = devm_regulator_bulk_get(wm8400->dev, 1323 ret = devm_regulator_bulk_get(wm8400->dev,
1325 ARRAY_SIZE(power), &power[0]); 1324 ARRAY_SIZE(power), &power[0]);
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c
index 7df7d4572755..1c1e328feeb8 100644
--- a/sound/soc/codecs/wm8510.c
+++ b/sound/soc/codecs/wm8510.c
@@ -589,20 +589,12 @@ static int wm8510_resume(struct snd_soc_codec *codec)
589 589
590static int wm8510_probe(struct snd_soc_codec *codec) 590static int wm8510_probe(struct snd_soc_codec *codec)
591{ 591{
592 int ret;
593
594 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
595 if (ret < 0) {
596 printk(KERN_ERR "wm8510: failed to set cache I/O: %d\n", ret);
597 return ret;
598 }
599
600 wm8510_reset(codec); 592 wm8510_reset(codec);
601 593
602 /* power on device */ 594 /* power on device */
603 wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 595 wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
604 596
605 return ret; 597 return 0;
606} 598}
607 599
608/* power down chip */ 600/* power down chip */
diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c
index 74d106dc7667..601ee8178af1 100644
--- a/sound/soc/codecs/wm8523.c
+++ b/sound/soc/codecs/wm8523.c
@@ -75,8 +75,8 @@ static const char *wm8523_zd_count_text[] = {
75 "2048", 75 "2048",
76}; 76};
77 77
78static const struct soc_enum wm8523_zc_count = 78static SOC_ENUM_SINGLE_DECL(wm8523_zc_count, WM8523_ZERO_DETECT, 0,
79 SOC_ENUM_SINGLE(WM8523_ZERO_DETECT, 0, 2, wm8523_zd_count_text); 79 wm8523_zd_count_text);
80 80
81static const struct snd_kcontrol_new wm8523_controls[] = { 81static const struct snd_kcontrol_new wm8523_controls[] = {
82SOC_DOUBLE_R_TLV("Playback Volume", WM8523_DAC_GAINL, WM8523_DAC_GAINR, 82SOC_DOUBLE_R_TLV("Playback Volume", WM8523_DAC_GAINL, WM8523_DAC_GAINR,
@@ -392,18 +392,11 @@ static int wm8523_resume(struct snd_soc_codec *codec)
392static int wm8523_probe(struct snd_soc_codec *codec) 392static int wm8523_probe(struct snd_soc_codec *codec)
393{ 393{
394 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec); 394 struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
395 int ret;
396 395
397 wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0]; 396 wm8523->rate_constraint.list = &wm8523->rate_constraint_list[0];
398 wm8523->rate_constraint.count = 397 wm8523->rate_constraint.count =
399 ARRAY_SIZE(wm8523->rate_constraint_list); 398 ARRAY_SIZE(wm8523->rate_constraint_list);
400 399
401 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
402 if (ret != 0) {
403 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
404 return ret;
405 }
406
407 /* Change some default settings - latch VU and enable ZC */ 400 /* Change some default settings - latch VU and enable ZC */
408 snd_soc_update_bits(codec, WM8523_DAC_GAINR, 401 snd_soc_update_bits(codec, WM8523_DAC_GAINR,
409 WM8523_DACR_VU, WM8523_DACR_VU); 402 WM8523_DACR_VU, WM8523_DACR_VU);
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index 318989acbbe5..af7ed8b5d4e1 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -504,8 +504,7 @@ static int wm8580_paif_hw_params(struct snd_pcm_substream *substream,
504 struct snd_pcm_hw_params *params, 504 struct snd_pcm_hw_params *params,
505 struct snd_soc_dai *dai) 505 struct snd_soc_dai *dai)
506{ 506{
507 struct snd_soc_pcm_runtime *rtd = substream->private_data; 507 struct snd_soc_codec *codec = dai->codec;
508 struct snd_soc_codec *codec = rtd->codec;
509 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec); 508 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
510 u16 paifa = 0; 509 u16 paifa = 0;
511 u16 paifb = 0; 510 u16 paifb = 0;
@@ -869,12 +868,6 @@ static int wm8580_probe(struct snd_soc_codec *codec)
869 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec); 868 struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
870 int ret = 0; 869 int ret = 0;
871 870
872 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
873 if (ret < 0) {
874 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
875 return ret;
876 }
877
878 ret = regulator_bulk_enable(ARRAY_SIZE(wm8580->supplies), 871 ret = regulator_bulk_enable(ARRAY_SIZE(wm8580->supplies),
879 wm8580->supplies); 872 wm8580->supplies);
880 if (ret != 0) { 873 if (ret != 0) {
diff --git a/sound/soc/codecs/wm8711.c b/sound/soc/codecs/wm8711.c
index d99f948c513c..b0fbcb377baf 100644
--- a/sound/soc/codecs/wm8711.c
+++ b/sound/soc/codecs/wm8711.c
@@ -201,7 +201,7 @@ static void wm8711_shutdown(struct snd_pcm_substream *substream,
201 struct snd_soc_codec *codec = dai->codec; 201 struct snd_soc_codec *codec = dai->codec;
202 202
203 /* deactivate */ 203 /* deactivate */
204 if (!codec->active) { 204 if (!snd_soc_codec_is_active(codec)) {
205 udelay(50); 205 udelay(50);
206 snd_soc_write(codec, WM8711_ACTIVE, 0x0); 206 snd_soc_write(codec, WM8711_ACTIVE, 0x0);
207 } 207 }
@@ -367,12 +367,6 @@ static int wm8711_probe(struct snd_soc_codec *codec)
367{ 367{
368 int ret; 368 int ret;
369 369
370 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
371 if (ret < 0) {
372 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
373 return ret;
374 }
375
376 ret = wm8711_reset(codec); 370 ret = wm8711_reset(codec);
377 if (ret < 0) { 371 if (ret < 0) {
378 dev_err(codec->dev, "Failed to issue reset\n"); 372 dev_err(codec->dev, "Failed to issue reset\n");
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c
index cd89033e84c0..bac7fc28fe71 100644
--- a/sound/soc/codecs/wm8728.c
+++ b/sound/soc/codecs/wm8728.c
@@ -228,19 +228,10 @@ static int wm8728_resume(struct snd_soc_codec *codec)
228 228
229static int wm8728_probe(struct snd_soc_codec *codec) 229static int wm8728_probe(struct snd_soc_codec *codec)
230{ 230{
231 int ret;
232
233 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
234 if (ret < 0) {
235 printk(KERN_ERR "wm8728: failed to configure cache I/O: %d\n",
236 ret);
237 return ret;
238 }
239
240 /* power on device */ 231 /* power on device */
241 wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 232 wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
242 233
243 return ret; 234 return 0;
244} 235}
245 236
246static int wm8728_remove(struct snd_soc_codec *codec) 237static int wm8728_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index 029720366ff8..d74f43975b90 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -83,8 +83,8 @@ static bool wm8731_writeable(struct device *dev, unsigned int reg)
83 83
84static const char *wm8731_input_select[] = {"Line In", "Mic"}; 84static const char *wm8731_input_select[] = {"Line In", "Mic"};
85 85
86static const struct soc_enum wm8731_insel_enum = 86static SOC_ENUM_SINGLE_DECL(wm8731_insel_enum,
87 SOC_ENUM_SINGLE(WM8731_APANA, 2, 2, wm8731_input_select); 87 WM8731_APANA, 2, wm8731_input_select);
88 88
89static int wm8731_deemph[] = { 0, 32000, 44100, 48000 }; 89static int wm8731_deemph[] = { 0, 32000, 44100, 48000 };
90 90
@@ -583,13 +583,6 @@ static int wm8731_probe(struct snd_soc_codec *codec)
583 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 583 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
584 int ret = 0, i; 584 int ret = 0, i;
585 585
586 codec->control_data = wm8731->regmap;
587 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
588 if (ret < 0) {
589 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
590 return ret;
591 }
592
593 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++) 586 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++)
594 wm8731->supplies[i].supply = wm8731_supply_names[i]; 587 wm8731->supplies[i].supply = wm8731_supply_names[i];
595 588
diff --git a/sound/soc/codecs/wm8737.c b/sound/soc/codecs/wm8737.c
index 2f167a8ca01b..b27f26cdc049 100644
--- a/sound/soc/codecs/wm8737.c
+++ b/sound/soc/codecs/wm8737.c
@@ -99,29 +99,29 @@ static const char *micbias_enum_text[] = {
99 "100%", 99 "100%",
100}; 100};
101 101
102static const struct soc_enum micbias_enum = 102static SOC_ENUM_SINGLE_DECL(micbias_enum,
103 SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL, 0, 4, micbias_enum_text); 103 WM8737_MIC_PREAMP_CONTROL, 0, micbias_enum_text);
104 104
105static const char *low_cutoff_text[] = { 105static const char *low_cutoff_text[] = {
106 "Low", "High" 106 "Low", "High"
107}; 107};
108 108
109static const struct soc_enum low_3d = 109static SOC_ENUM_SINGLE_DECL(low_3d,
110 SOC_ENUM_SINGLE(WM8737_3D_ENHANCE, 6, 2, low_cutoff_text); 110 WM8737_3D_ENHANCE, 6, low_cutoff_text);
111 111
112static const char *high_cutoff_text[] = { 112static const char *high_cutoff_text[] = {
113 "High", "Low" 113 "High", "Low"
114}; 114};
115 115
116static const struct soc_enum high_3d = 116static SOC_ENUM_SINGLE_DECL(high_3d,
117 SOC_ENUM_SINGLE(WM8737_3D_ENHANCE, 5, 2, high_cutoff_text); 117 WM8737_3D_ENHANCE, 5, high_cutoff_text);
118 118
119static const char *alc_fn_text[] = { 119static const char *alc_fn_text[] = {
120 "Disabled", "Right", "Left", "Stereo" 120 "Disabled", "Right", "Left", "Stereo"
121}; 121};
122 122
123static const struct soc_enum alc_fn = 123static SOC_ENUM_SINGLE_DECL(alc_fn,
124 SOC_ENUM_SINGLE(WM8737_ALC1, 7, 4, alc_fn_text); 124 WM8737_ALC1, 7, alc_fn_text);
125 125
126static const char *alc_hold_text[] = { 126static const char *alc_hold_text[] = {
127 "0", "2.67ms", "5.33ms", "10.66ms", "21.32ms", "42.64ms", "85.28ms", 127 "0", "2.67ms", "5.33ms", "10.66ms", "21.32ms", "42.64ms", "85.28ms",
@@ -129,24 +129,24 @@ static const char *alc_hold_text[] = {
129 "10.916s", "21.832s", "43.691s" 129 "10.916s", "21.832s", "43.691s"
130}; 130};
131 131
132static const struct soc_enum alc_hold = 132static SOC_ENUM_SINGLE_DECL(alc_hold,
133 SOC_ENUM_SINGLE(WM8737_ALC2, 0, 16, alc_hold_text); 133 WM8737_ALC2, 0, alc_hold_text);
134 134
135static const char *alc_atk_text[] = { 135static const char *alc_atk_text[] = {
136 "8.4ms", "16.8ms", "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", 136 "8.4ms", "16.8ms", "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms",
137 "1.075s", "2.15s", "4.3s", "8.6s" 137 "1.075s", "2.15s", "4.3s", "8.6s"
138}; 138};
139 139
140static const struct soc_enum alc_atk = 140static SOC_ENUM_SINGLE_DECL(alc_atk,
141 SOC_ENUM_SINGLE(WM8737_ALC3, 0, 11, alc_atk_text); 141 WM8737_ALC3, 0, alc_atk_text);
142 142
143static const char *alc_dcy_text[] = { 143static const char *alc_dcy_text[] = {
144 "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", "1.075s", "2.15s", 144 "33.6ms", "67.2ms", "134.4ms", "268.8ms", "537.6ms", "1.075s", "2.15s",
145 "4.3s", "8.6s", "17.2s", "34.41s" 145 "4.3s", "8.6s", "17.2s", "34.41s"
146}; 146};
147 147
148static const struct soc_enum alc_dcy = 148static SOC_ENUM_SINGLE_DECL(alc_dcy,
149 SOC_ENUM_SINGLE(WM8737_ALC3, 4, 11, alc_dcy_text); 149 WM8737_ALC3, 4, alc_dcy_text);
150 150
151static const struct snd_kcontrol_new wm8737_snd_controls[] = { 151static const struct snd_kcontrol_new wm8737_snd_controls[] = {
152SOC_DOUBLE_R_TLV("Mic Boost Volume", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R, 152SOC_DOUBLE_R_TLV("Mic Boost Volume", WM8737_AUDIO_PATH_L, WM8737_AUDIO_PATH_R,
@@ -191,8 +191,8 @@ static const char *linsel_text[] = {
191 "LINPUT1", "LINPUT2", "LINPUT3", "LINPUT1 DC", 191 "LINPUT1", "LINPUT2", "LINPUT3", "LINPUT1 DC",
192}; 192};
193 193
194static const struct soc_enum linsel_enum = 194static SOC_ENUM_SINGLE_DECL(linsel_enum,
195 SOC_ENUM_SINGLE(WM8737_AUDIO_PATH_L, 7, 4, linsel_text); 195 WM8737_AUDIO_PATH_L, 7, linsel_text);
196 196
197static const struct snd_kcontrol_new linsel_mux = 197static const struct snd_kcontrol_new linsel_mux =
198 SOC_DAPM_ENUM("LINSEL", linsel_enum); 198 SOC_DAPM_ENUM("LINSEL", linsel_enum);
@@ -202,8 +202,8 @@ static const char *rinsel_text[] = {
202 "RINPUT1", "RINPUT2", "RINPUT3", "RINPUT1 DC", 202 "RINPUT1", "RINPUT2", "RINPUT3", "RINPUT1 DC",
203}; 203};
204 204
205static const struct soc_enum rinsel_enum = 205static SOC_ENUM_SINGLE_DECL(rinsel_enum,
206 SOC_ENUM_SINGLE(WM8737_AUDIO_PATH_R, 7, 4, rinsel_text); 206 WM8737_AUDIO_PATH_R, 7, rinsel_text);
207 207
208static const struct snd_kcontrol_new rinsel_mux = 208static const struct snd_kcontrol_new rinsel_mux =
209 SOC_DAPM_ENUM("RINSEL", rinsel_enum); 209 SOC_DAPM_ENUM("RINSEL", rinsel_enum);
@@ -212,15 +212,15 @@ static const char *bypass_text[] = {
212 "Direct", "Preamp" 212 "Direct", "Preamp"
213}; 213};
214 214
215static const struct soc_enum lbypass_enum = 215static SOC_ENUM_SINGLE_DECL(lbypass_enum,
216 SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL, 2, 2, bypass_text); 216 WM8737_MIC_PREAMP_CONTROL, 2, bypass_text);
217 217
218static const struct snd_kcontrol_new lbypass_mux = 218static const struct snd_kcontrol_new lbypass_mux =
219 SOC_DAPM_ENUM("Left Bypass", lbypass_enum); 219 SOC_DAPM_ENUM("Left Bypass", lbypass_enum);
220 220
221 221
222static const struct soc_enum rbypass_enum = 222static SOC_ENUM_SINGLE_DECL(rbypass_enum,
223 SOC_ENUM_SINGLE(WM8737_MIC_PREAMP_CONTROL, 3, 2, bypass_text); 223 WM8737_MIC_PREAMP_CONTROL, 3, bypass_text);
224 224
225static const struct snd_kcontrol_new rbypass_mux = 225static const struct snd_kcontrol_new rbypass_mux =
226 SOC_DAPM_ENUM("Left Bypass", rbypass_enum); 226 SOC_DAPM_ENUM("Left Bypass", rbypass_enum);
@@ -570,12 +570,6 @@ static int wm8737_probe(struct snd_soc_codec *codec)
570 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 570 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec);
571 int ret; 571 int ret;
572 572
573 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
574 if (ret != 0) {
575 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
576 return ret;
577 }
578
579 ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies), 573 ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies),
580 wm8737->supplies); 574 wm8737->supplies);
581 if (ret != 0) { 575 if (ret != 0) {
@@ -644,7 +638,7 @@ static const struct regmap_config wm8737_regmap = {
644 .volatile_reg = wm8737_volatile, 638 .volatile_reg = wm8737_volatile,
645}; 639};
646 640
647#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 641#if IS_ENABLED(CONFIG_I2C)
648static int wm8737_i2c_probe(struct i2c_client *i2c, 642static int wm8737_i2c_probe(struct i2c_client *i2c,
649 const struct i2c_device_id *id) 643 const struct i2c_device_id *id)
650{ 644{
@@ -758,7 +752,7 @@ static struct spi_driver wm8737_spi_driver = {
758static int __init wm8737_modinit(void) 752static int __init wm8737_modinit(void)
759{ 753{
760 int ret; 754 int ret;
761#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 755#if IS_ENABLED(CONFIG_I2C)
762 ret = i2c_add_driver(&wm8737_i2c_driver); 756 ret = i2c_add_driver(&wm8737_i2c_driver);
763 if (ret != 0) { 757 if (ret != 0) {
764 printk(KERN_ERR "Failed to register WM8737 I2C driver: %d\n", 758 printk(KERN_ERR "Failed to register WM8737 I2C driver: %d\n",
@@ -781,7 +775,7 @@ static void __exit wm8737_exit(void)
781#if defined(CONFIG_SPI_MASTER) 775#if defined(CONFIG_SPI_MASTER)
782 spi_unregister_driver(&wm8737_spi_driver); 776 spi_unregister_driver(&wm8737_spi_driver);
783#endif 777#endif
784#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 778#if IS_ENABLED(CONFIG_I2C)
785 i2c_del_driver(&wm8737_i2c_driver); 779 i2c_del_driver(&wm8737_i2c_driver);
786#endif 780#endif
787} 781}
diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c
index 2895c8d3b5e4..b33542a04607 100644
--- a/sound/soc/codecs/wm8741.c
+++ b/sound/soc/codecs/wm8741.c
@@ -44,7 +44,7 @@ struct wm8741_priv {
44 struct regmap *regmap; 44 struct regmap *regmap;
45 struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES]; 45 struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES];
46 unsigned int sysclk; 46 unsigned int sysclk;
47 struct snd_pcm_hw_constraint_list *sysclk_constraints; 47 const struct snd_pcm_hw_constraint_list *sysclk_constraints;
48}; 48};
49 49
50static const struct reg_default wm8741_reg_defaults[] = { 50static const struct reg_default wm8741_reg_defaults[] = {
@@ -122,74 +122,74 @@ static struct {
122 { 6, 768 }, 122 { 6, 768 },
123}; 123};
124 124
125static unsigned int rates_11289[] = { 125static const unsigned int rates_11289[] = {
126 44100, 88235, 126 44100, 88235,
127}; 127};
128 128
129static struct snd_pcm_hw_constraint_list constraints_11289 = { 129static const struct snd_pcm_hw_constraint_list constraints_11289 = {
130 .count = ARRAY_SIZE(rates_11289), 130 .count = ARRAY_SIZE(rates_11289),
131 .list = rates_11289, 131 .list = rates_11289,
132}; 132};
133 133
134static unsigned int rates_12288[] = { 134static const unsigned int rates_12288[] = {
135 32000, 48000, 96000, 135 32000, 48000, 96000,
136}; 136};
137 137
138static struct snd_pcm_hw_constraint_list constraints_12288 = { 138static const struct snd_pcm_hw_constraint_list constraints_12288 = {
139 .count = ARRAY_SIZE(rates_12288), 139 .count = ARRAY_SIZE(rates_12288),
140 .list = rates_12288, 140 .list = rates_12288,
141}; 141};
142 142
143static unsigned int rates_16384[] = { 143static const unsigned int rates_16384[] = {
144 32000, 144 32000,
145}; 145};
146 146
147static struct snd_pcm_hw_constraint_list constraints_16384 = { 147static const struct snd_pcm_hw_constraint_list constraints_16384 = {
148 .count = ARRAY_SIZE(rates_16384), 148 .count = ARRAY_SIZE(rates_16384),
149 .list = rates_16384, 149 .list = rates_16384,
150}; 150};
151 151
152static unsigned int rates_16934[] = { 152static const unsigned int rates_16934[] = {
153 44100, 88235, 153 44100, 88235,
154}; 154};
155 155
156static struct snd_pcm_hw_constraint_list constraints_16934 = { 156static const struct snd_pcm_hw_constraint_list constraints_16934 = {
157 .count = ARRAY_SIZE(rates_16934), 157 .count = ARRAY_SIZE(rates_16934),
158 .list = rates_16934, 158 .list = rates_16934,
159}; 159};
160 160
161static unsigned int rates_18432[] = { 161static const unsigned int rates_18432[] = {
162 48000, 96000, 162 48000, 96000,
163}; 163};
164 164
165static struct snd_pcm_hw_constraint_list constraints_18432 = { 165static const struct snd_pcm_hw_constraint_list constraints_18432 = {
166 .count = ARRAY_SIZE(rates_18432), 166 .count = ARRAY_SIZE(rates_18432),
167 .list = rates_18432, 167 .list = rates_18432,
168}; 168};
169 169
170static unsigned int rates_22579[] = { 170static const unsigned int rates_22579[] = {
171 44100, 88235, 1764000 171 44100, 88235, 1764000
172}; 172};
173 173
174static struct snd_pcm_hw_constraint_list constraints_22579 = { 174static const struct snd_pcm_hw_constraint_list constraints_22579 = {
175 .count = ARRAY_SIZE(rates_22579), 175 .count = ARRAY_SIZE(rates_22579),
176 .list = rates_22579, 176 .list = rates_22579,
177}; 177};
178 178
179static unsigned int rates_24576[] = { 179static const unsigned int rates_24576[] = {
180 32000, 48000, 96000, 192000 180 32000, 48000, 96000, 192000
181}; 181};
182 182
183static struct snd_pcm_hw_constraint_list constraints_24576 = { 183static const struct snd_pcm_hw_constraint_list constraints_24576 = {
184 .count = ARRAY_SIZE(rates_24576), 184 .count = ARRAY_SIZE(rates_24576),
185 .list = rates_24576, 185 .list = rates_24576,
186}; 186};
187 187
188static unsigned int rates_36864[] = { 188static const unsigned int rates_36864[] = {
189 48000, 96000, 19200 189 48000, 96000, 19200
190}; 190};
191 191
192static struct snd_pcm_hw_constraint_list constraints_36864 = { 192static const struct snd_pcm_hw_constraint_list constraints_36864 = {
193 .count = ARRAY_SIZE(rates_36864), 193 .count = ARRAY_SIZE(rates_36864),
194 .list = rates_36864, 194 .list = rates_36864,
195}; 195};
@@ -429,12 +429,6 @@ static int wm8741_probe(struct snd_soc_codec *codec)
429 goto err_get; 429 goto err_get;
430 } 430 }
431 431
432 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
433 if (ret != 0) {
434 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
435 goto err_enable;
436 }
437
438 ret = wm8741_reset(codec); 432 ret = wm8741_reset(codec);
439 if (ret < 0) { 433 if (ret < 0) {
440 dev_err(codec->dev, "Failed to issue reset\n"); 434 dev_err(codec->dev, "Failed to issue reset\n");
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index 78616a638a55..33990b63d214 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -702,12 +702,6 @@ static int wm8750_probe(struct snd_soc_codec *codec)
702{ 702{
703 int ret; 703 int ret;
704 704
705 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
706 if (ret < 0) {
707 printk(KERN_ERR "wm8750: failed to set cache I/O: %d\n", ret);
708 return ret;
709 }
710
711 ret = wm8750_reset(codec); 705 ret = wm8750_reset(codec);
712 if (ret < 0) { 706 if (ret < 0) {
713 printk(KERN_ERR "wm8750: failed to reset: %d\n", ret); 707 printk(KERN_ERR "wm8750: failed to reset: %d\n", ret);
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index be85da93a268..cbb8d55052a4 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -251,7 +251,7 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol,
251 if (wm8753->dai_func == ucontrol->value.integer.value[0]) 251 if (wm8753->dai_func == ucontrol->value.integer.value[0])
252 return 0; 252 return 0;
253 253
254 if (codec->active) 254 if (snd_soc_codec_is_active(codec))
255 return -EBUSY; 255 return -EBUSY;
256 256
257 ioctl = snd_soc_read(codec, WM8753_IOCTL); 257 ioctl = snd_soc_read(codec, WM8753_IOCTL);
@@ -1314,7 +1314,7 @@ static int wm8753_mute(struct snd_soc_dai *dai, int mute)
1314 /* the digital mute covers the HiFi and Voice DAC's on the WM8753. 1314 /* the digital mute covers the HiFi and Voice DAC's on the WM8753.
1315 * make sure we check if they are not both active when we mute */ 1315 * make sure we check if they are not both active when we mute */
1316 if (mute && wm8753->dai_func == 1) { 1316 if (mute && wm8753->dai_func == 1) {
1317 if (!codec->active) 1317 if (!snd_soc_codec_is_active(codec))
1318 snd_soc_write(codec, WM8753_DAC, mute_reg | 0x8); 1318 snd_soc_write(codec, WM8753_DAC, mute_reg | 0x8);
1319 } else { 1319 } else {
1320 if (mute) 1320 if (mute)
@@ -1440,7 +1440,6 @@ static void wm8753_work(struct work_struct *work)
1440static int wm8753_suspend(struct snd_soc_codec *codec) 1440static int wm8753_suspend(struct snd_soc_codec *codec)
1441{ 1441{
1442 wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); 1442 wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF);
1443 codec->cache_sync = 1;
1444 return 0; 1443 return 0;
1445} 1444}
1446 1445
@@ -1471,13 +1470,6 @@ static int wm8753_probe(struct snd_soc_codec *codec)
1471 1470
1472 INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8753_work); 1471 INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8753_work);
1473 1472
1474 codec->control_data = wm8753->regmap;
1475 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
1476 if (ret < 0) {
1477 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1478 return ret;
1479 }
1480
1481 ret = wm8753_reset(codec); 1473 ret = wm8753_reset(codec);
1482 if (ret < 0) { 1474 if (ret < 0) {
1483 dev_err(codec->dev, "Failed to issue reset: %d\n", ret); 1475 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
diff --git a/sound/soc/codecs/wm8770.c b/sound/soc/codecs/wm8770.c
index 5bce21013485..c61aeb38efb8 100644
--- a/sound/soc/codecs/wm8770.c
+++ b/sound/soc/codecs/wm8770.c
@@ -580,12 +580,6 @@ static int wm8770_probe(struct snd_soc_codec *codec)
580 wm8770 = snd_soc_codec_get_drvdata(codec); 580 wm8770 = snd_soc_codec_get_drvdata(codec);
581 wm8770->codec = codec; 581 wm8770->codec = codec;
582 582
583 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
584 if (ret < 0) {
585 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
586 return ret;
587 }
588
589 ret = regulator_bulk_enable(ARRAY_SIZE(wm8770->supplies), 583 ret = regulator_bulk_enable(ARRAY_SIZE(wm8770->supplies),
590 wm8770->supplies); 584 wm8770->supplies);
591 if (ret) { 585 if (ret) {
diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c
index ef8246725232..70952ceb278b 100644
--- a/sound/soc/codecs/wm8776.c
+++ b/sound/soc/codecs/wm8776.c
@@ -430,12 +430,6 @@ static int wm8776_probe(struct snd_soc_codec *codec)
430{ 430{
431 int ret = 0; 431 int ret = 0;
432 432
433 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
434 if (ret < 0) {
435 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
436 return ret;
437 }
438
439 ret = wm8776_reset(codec); 433 ret = wm8776_reset(codec);
440 if (ret < 0) { 434 if (ret < 0) {
441 dev_err(codec->dev, "Failed to issue reset: %d\n", ret); 435 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c
index 9bc8206a6807..ee76f0fb4299 100644
--- a/sound/soc/codecs/wm8804.c
+++ b/sound/soc/codecs/wm8804.c
@@ -92,7 +92,7 @@ WM8804_REGULATOR_EVENT(0)
92WM8804_REGULATOR_EVENT(1) 92WM8804_REGULATOR_EVENT(1)
93 93
94static const char *txsrc_text[] = { "S/PDIF RX", "AIF" }; 94static const char *txsrc_text[] = { "S/PDIF RX", "AIF" };
95static const SOC_ENUM_SINGLE_EXT_DECL(txsrc, txsrc_text); 95static SOC_ENUM_SINGLE_EXT_DECL(txsrc, txsrc_text);
96 96
97static const struct snd_kcontrol_new wm8804_snd_controls[] = { 97static const struct snd_kcontrol_new wm8804_snd_controls[] = {
98 SOC_ENUM_EXT("Input Source", txsrc, txsrc_get, txsrc_put), 98 SOC_ENUM_EXT("Input Source", txsrc, txsrc_get, txsrc_put),
@@ -546,14 +546,6 @@ static int wm8804_probe(struct snd_soc_codec *codec)
546 546
547 wm8804 = snd_soc_codec_get_drvdata(codec); 547 wm8804 = snd_soc_codec_get_drvdata(codec);
548 548
549 codec->control_data = wm8804->regmap;
550
551 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
552 if (ret < 0) {
553 dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret);
554 return ret;
555 }
556
557 for (i = 0; i < ARRAY_SIZE(wm8804->supplies); i++) 549 for (i = 0; i < ARRAY_SIZE(wm8804->supplies); i++)
558 wm8804->supplies[i].supply = wm8804_supply_names[i]; 550 wm8804->supplies[i].supply = wm8804_supply_names[i];
559 551
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index 43c2201cb901..d09fdce57f5a 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -1178,13 +1178,7 @@ static int wm8900_resume(struct snd_soc_codec *codec)
1178 1178
1179static int wm8900_probe(struct snd_soc_codec *codec) 1179static int wm8900_probe(struct snd_soc_codec *codec)
1180{ 1180{
1181 int ret = 0, reg; 1181 int reg;
1182
1183 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1184 if (ret != 0) {
1185 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1186 return ret;
1187 }
1188 1182
1189 reg = snd_soc_read(codec, WM8900_REG_ID); 1183 reg = snd_soc_read(codec, WM8900_REG_ID);
1190 if (reg != 0x8900) { 1184 if (reg != 0x8900) {
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index eebcb1da3b7b..b0084a127d18 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -489,28 +489,28 @@ static const char *hpf_mode_text[] = {
489 "Hi-fi", "Voice 1", "Voice 2", "Voice 3" 489 "Hi-fi", "Voice 1", "Voice 2", "Voice 3"
490}; 490};
491 491
492static const struct soc_enum hpf_mode = 492static SOC_ENUM_SINGLE_DECL(hpf_mode,
493 SOC_ENUM_SINGLE(WM8903_ADC_DIGITAL_0, 5, 4, hpf_mode_text); 493 WM8903_ADC_DIGITAL_0, 5, hpf_mode_text);
494 494
495static const char *osr_text[] = { 495static const char *osr_text[] = {
496 "Low power", "High performance" 496 "Low power", "High performance"
497}; 497};
498 498
499static const struct soc_enum adc_osr = 499static SOC_ENUM_SINGLE_DECL(adc_osr,
500 SOC_ENUM_SINGLE(WM8903_ANALOGUE_ADC_0, 0, 2, osr_text); 500 WM8903_ANALOGUE_ADC_0, 0, osr_text);
501 501
502static const struct soc_enum dac_osr = 502static SOC_ENUM_SINGLE_DECL(dac_osr,
503 SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_1, 0, 2, osr_text); 503 WM8903_DAC_DIGITAL_1, 0, osr_text);
504 504
505static const char *drc_slope_text[] = { 505static const char *drc_slope_text[] = {
506 "1", "1/2", "1/4", "1/8", "1/16", "0" 506 "1", "1/2", "1/4", "1/8", "1/16", "0"
507}; 507};
508 508
509static const struct soc_enum drc_slope_r0 = 509static SOC_ENUM_SINGLE_DECL(drc_slope_r0,
510 SOC_ENUM_SINGLE(WM8903_DRC_2, 3, 6, drc_slope_text); 510 WM8903_DRC_2, 3, drc_slope_text);
511 511
512static const struct soc_enum drc_slope_r1 = 512static SOC_ENUM_SINGLE_DECL(drc_slope_r1,
513 SOC_ENUM_SINGLE(WM8903_DRC_2, 0, 6, drc_slope_text); 513 WM8903_DRC_2, 0, drc_slope_text);
514 514
515static const char *drc_attack_text[] = { 515static const char *drc_attack_text[] = {
516 "instantaneous", 516 "instantaneous",
@@ -518,125 +518,125 @@ static const char *drc_attack_text[] = {
518 "46.4ms", "92.8ms", "185.6ms" 518 "46.4ms", "92.8ms", "185.6ms"
519}; 519};
520 520
521static const struct soc_enum drc_attack = 521static SOC_ENUM_SINGLE_DECL(drc_attack,
522 SOC_ENUM_SINGLE(WM8903_DRC_1, 12, 11, drc_attack_text); 522 WM8903_DRC_1, 12, drc_attack_text);
523 523
524static const char *drc_decay_text[] = { 524static const char *drc_decay_text[] = {
525 "186ms", "372ms", "743ms", "1.49s", "2.97s", "5.94s", "11.89s", 525 "186ms", "372ms", "743ms", "1.49s", "2.97s", "5.94s", "11.89s",
526 "23.87s", "47.56s" 526 "23.87s", "47.56s"
527}; 527};
528 528
529static const struct soc_enum drc_decay = 529static SOC_ENUM_SINGLE_DECL(drc_decay,
530 SOC_ENUM_SINGLE(WM8903_DRC_1, 8, 9, drc_decay_text); 530 WM8903_DRC_1, 8, drc_decay_text);
531 531
532static const char *drc_ff_delay_text[] = { 532static const char *drc_ff_delay_text[] = {
533 "5 samples", "9 samples" 533 "5 samples", "9 samples"
534}; 534};
535 535
536static const struct soc_enum drc_ff_delay = 536static SOC_ENUM_SINGLE_DECL(drc_ff_delay,
537 SOC_ENUM_SINGLE(WM8903_DRC_0, 5, 2, drc_ff_delay_text); 537 WM8903_DRC_0, 5, drc_ff_delay_text);
538 538
539static const char *drc_qr_decay_text[] = { 539static const char *drc_qr_decay_text[] = {
540 "0.725ms", "1.45ms", "5.8ms" 540 "0.725ms", "1.45ms", "5.8ms"
541}; 541};
542 542
543static const struct soc_enum drc_qr_decay = 543static SOC_ENUM_SINGLE_DECL(drc_qr_decay,
544 SOC_ENUM_SINGLE(WM8903_DRC_1, 4, 3, drc_qr_decay_text); 544 WM8903_DRC_1, 4, drc_qr_decay_text);
545 545
546static const char *drc_smoothing_text[] = { 546static const char *drc_smoothing_text[] = {
547 "Low", "Medium", "High" 547 "Low", "Medium", "High"
548}; 548};
549 549
550static const struct soc_enum drc_smoothing = 550static SOC_ENUM_SINGLE_DECL(drc_smoothing,
551 SOC_ENUM_SINGLE(WM8903_DRC_0, 11, 3, drc_smoothing_text); 551 WM8903_DRC_0, 11, drc_smoothing_text);
552 552
553static const char *soft_mute_text[] = { 553static const char *soft_mute_text[] = {
554 "Fast (fs/2)", "Slow (fs/32)" 554 "Fast (fs/2)", "Slow (fs/32)"
555}; 555};
556 556
557static const struct soc_enum soft_mute = 557static SOC_ENUM_SINGLE_DECL(soft_mute,
558 SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_1, 10, 2, soft_mute_text); 558 WM8903_DAC_DIGITAL_1, 10, soft_mute_text);
559 559
560static const char *mute_mode_text[] = { 560static const char *mute_mode_text[] = {
561 "Hard", "Soft" 561 "Hard", "Soft"
562}; 562};
563 563
564static const struct soc_enum mute_mode = 564static SOC_ENUM_SINGLE_DECL(mute_mode,
565 SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_1, 9, 2, mute_mode_text); 565 WM8903_DAC_DIGITAL_1, 9, mute_mode_text);
566 566
567static const char *companding_text[] = { 567static const char *companding_text[] = {
568 "ulaw", "alaw" 568 "ulaw", "alaw"
569}; 569};
570 570
571static const struct soc_enum dac_companding = 571static SOC_ENUM_SINGLE_DECL(dac_companding,
572 SOC_ENUM_SINGLE(WM8903_AUDIO_INTERFACE_0, 0, 2, companding_text); 572 WM8903_AUDIO_INTERFACE_0, 0, companding_text);
573 573
574static const struct soc_enum adc_companding = 574static SOC_ENUM_SINGLE_DECL(adc_companding,
575 SOC_ENUM_SINGLE(WM8903_AUDIO_INTERFACE_0, 2, 2, companding_text); 575 WM8903_AUDIO_INTERFACE_0, 2, companding_text);
576 576
577static const char *input_mode_text[] = { 577static const char *input_mode_text[] = {
578 "Single-Ended", "Differential Line", "Differential Mic" 578 "Single-Ended", "Differential Line", "Differential Mic"
579}; 579};
580 580
581static const struct soc_enum linput_mode_enum = 581static SOC_ENUM_SINGLE_DECL(linput_mode_enum,
582 SOC_ENUM_SINGLE(WM8903_ANALOGUE_LEFT_INPUT_1, 0, 3, input_mode_text); 582 WM8903_ANALOGUE_LEFT_INPUT_1, 0, input_mode_text);
583 583
584static const struct soc_enum rinput_mode_enum = 584static SOC_ENUM_SINGLE_DECL(rinput_mode_enum,
585 SOC_ENUM_SINGLE(WM8903_ANALOGUE_RIGHT_INPUT_1, 0, 3, input_mode_text); 585 WM8903_ANALOGUE_RIGHT_INPUT_1, 0, input_mode_text);
586 586
587static const char *linput_mux_text[] = { 587static const char *linput_mux_text[] = {
588 "IN1L", "IN2L", "IN3L" 588 "IN1L", "IN2L", "IN3L"
589}; 589};
590 590
591static const struct soc_enum linput_enum = 591static SOC_ENUM_SINGLE_DECL(linput_enum,
592 SOC_ENUM_SINGLE(WM8903_ANALOGUE_LEFT_INPUT_1, 2, 3, linput_mux_text); 592 WM8903_ANALOGUE_LEFT_INPUT_1, 2, linput_mux_text);
593 593
594static const struct soc_enum linput_inv_enum = 594static SOC_ENUM_SINGLE_DECL(linput_inv_enum,
595 SOC_ENUM_SINGLE(WM8903_ANALOGUE_LEFT_INPUT_1, 4, 3, linput_mux_text); 595 WM8903_ANALOGUE_LEFT_INPUT_1, 4, linput_mux_text);
596 596
597static const char *rinput_mux_text[] = { 597static const char *rinput_mux_text[] = {
598 "IN1R", "IN2R", "IN3R" 598 "IN1R", "IN2R", "IN3R"
599}; 599};
600 600
601static const struct soc_enum rinput_enum = 601static SOC_ENUM_SINGLE_DECL(rinput_enum,
602 SOC_ENUM_SINGLE(WM8903_ANALOGUE_RIGHT_INPUT_1, 2, 3, rinput_mux_text); 602 WM8903_ANALOGUE_RIGHT_INPUT_1, 2, rinput_mux_text);
603 603
604static const struct soc_enum rinput_inv_enum = 604static SOC_ENUM_SINGLE_DECL(rinput_inv_enum,
605 SOC_ENUM_SINGLE(WM8903_ANALOGUE_RIGHT_INPUT_1, 4, 3, rinput_mux_text); 605 WM8903_ANALOGUE_RIGHT_INPUT_1, 4, rinput_mux_text);
606 606
607 607
608static const char *sidetone_text[] = { 608static const char *sidetone_text[] = {
609 "None", "Left", "Right" 609 "None", "Left", "Right"
610}; 610};
611 611
612static const struct soc_enum lsidetone_enum = 612static SOC_ENUM_SINGLE_DECL(lsidetone_enum,
613 SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_0, 2, 3, sidetone_text); 613 WM8903_DAC_DIGITAL_0, 2, sidetone_text);
614 614
615static const struct soc_enum rsidetone_enum = 615static SOC_ENUM_SINGLE_DECL(rsidetone_enum,
616 SOC_ENUM_SINGLE(WM8903_DAC_DIGITAL_0, 0, 3, sidetone_text); 616 WM8903_DAC_DIGITAL_0, 0, sidetone_text);
617 617
618static const char *adcinput_text[] = { 618static const char *adcinput_text[] = {
619 "ADC", "DMIC" 619 "ADC", "DMIC"
620}; 620};
621 621
622static const struct soc_enum adcinput_enum = 622static SOC_ENUM_SINGLE_DECL(adcinput_enum,
623 SOC_ENUM_SINGLE(WM8903_CLOCK_RATE_TEST_4, 9, 2, adcinput_text); 623 WM8903_CLOCK_RATE_TEST_4, 9, adcinput_text);
624 624
625static const char *aif_text[] = { 625static const char *aif_text[] = {
626 "Left", "Right" 626 "Left", "Right"
627}; 627};
628 628
629static const struct soc_enum lcapture_enum = 629static SOC_ENUM_SINGLE_DECL(lcapture_enum,
630 SOC_ENUM_SINGLE(WM8903_AUDIO_INTERFACE_0, 7, 2, aif_text); 630 WM8903_AUDIO_INTERFACE_0, 7, aif_text);
631 631
632static const struct soc_enum rcapture_enum = 632static SOC_ENUM_SINGLE_DECL(rcapture_enum,
633 SOC_ENUM_SINGLE(WM8903_AUDIO_INTERFACE_0, 6, 2, aif_text); 633 WM8903_AUDIO_INTERFACE_0, 6, aif_text);
634 634
635static const struct soc_enum lplay_enum = 635static SOC_ENUM_SINGLE_DECL(lplay_enum,
636 SOC_ENUM_SINGLE(WM8903_AUDIO_INTERFACE_0, 5, 2, aif_text); 636 WM8903_AUDIO_INTERFACE_0, 5, aif_text);
637 637
638static const struct soc_enum rplay_enum = 638static SOC_ENUM_SINGLE_DECL(rplay_enum,
639 SOC_ENUM_SINGLE(WM8903_AUDIO_INTERFACE_0, 4, 2, aif_text); 639 WM8903_AUDIO_INTERFACE_0, 4, aif_text);
640 640
641static const struct snd_kcontrol_new wm8903_snd_controls[] = { 641static const struct snd_kcontrol_new wm8903_snd_controls[] = {
642 642
@@ -1897,21 +1897,13 @@ static void wm8903_free_gpio(struct wm8903_priv *wm8903)
1897static int wm8903_probe(struct snd_soc_codec *codec) 1897static int wm8903_probe(struct snd_soc_codec *codec)
1898{ 1898{
1899 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); 1899 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
1900 int ret;
1901 1900
1902 wm8903->codec = codec; 1901 wm8903->codec = codec;
1903 codec->control_data = wm8903->regmap;
1904
1905 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1906 if (ret != 0) {
1907 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1908 return ret;
1909 }
1910 1902
1911 /* power on device */ 1903 /* power on device */
1912 wm8903_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1904 wm8903_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1913 1905
1914 return ret; 1906 return 0;
1915} 1907}
1916 1908
1917/* power down chip */ 1909/* power down chip */
diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index 53bbfac6a83a..49c35c36935e 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -552,18 +552,20 @@ static const char *input_mode_text[] = {
552 "Single-Ended", "Differential Line", "Differential Mic" 552 "Single-Ended", "Differential Line", "Differential Mic"
553}; 553};
554 554
555static const struct soc_enum lin_mode = 555static SOC_ENUM_SINGLE_DECL(lin_mode,
556 SOC_ENUM_SINGLE(WM8904_ANALOGUE_LEFT_INPUT_1, 0, 3, input_mode_text); 556 WM8904_ANALOGUE_LEFT_INPUT_1, 0,
557 input_mode_text);
557 558
558static const struct soc_enum rin_mode = 559static SOC_ENUM_SINGLE_DECL(rin_mode,
559 SOC_ENUM_SINGLE(WM8904_ANALOGUE_RIGHT_INPUT_1, 0, 3, input_mode_text); 560 WM8904_ANALOGUE_RIGHT_INPUT_1, 0,
561 input_mode_text);
560 562
561static const char *hpf_mode_text[] = { 563static const char *hpf_mode_text[] = {
562 "Hi-fi", "Voice 1", "Voice 2", "Voice 3" 564 "Hi-fi", "Voice 1", "Voice 2", "Voice 3"
563}; 565};
564 566
565static const struct soc_enum hpf_mode = 567static SOC_ENUM_SINGLE_DECL(hpf_mode, WM8904_ADC_DIGITAL_0, 5,
566 SOC_ENUM_SINGLE(WM8904_ADC_DIGITAL_0, 5, 4, hpf_mode_text); 568 hpf_mode_text);
567 569
568static int wm8904_adc_osr_put(struct snd_kcontrol *kcontrol, 570static int wm8904_adc_osr_put(struct snd_kcontrol *kcontrol,
569 struct snd_ctl_elem_value *ucontrol) 571 struct snd_ctl_elem_value *ucontrol)
@@ -611,8 +613,7 @@ static const char *drc_path_text[] = {
611 "ADC", "DAC" 613 "ADC", "DAC"
612}; 614};
613 615
614static const struct soc_enum drc_path = 616static SOC_ENUM_SINGLE_DECL(drc_path, WM8904_DRC_0, 14, drc_path_text);
615 SOC_ENUM_SINGLE(WM8904_DRC_0, 14, 2, drc_path_text);
616 617
617static const struct snd_kcontrol_new wm8904_dac_snd_controls[] = { 618static const struct snd_kcontrol_new wm8904_dac_snd_controls[] = {
618SOC_SINGLE_TLV("Digital Playback Boost Volume", 619SOC_SINGLE_TLV("Digital Playback Boost Volume",
@@ -858,14 +859,14 @@ static const char *lin_text[] = {
858 "IN1L", "IN2L", "IN3L" 859 "IN1L", "IN2L", "IN3L"
859}; 860};
860 861
861static const struct soc_enum lin_enum = 862static SOC_ENUM_SINGLE_DECL(lin_enum, WM8904_ANALOGUE_LEFT_INPUT_1, 2,
862 SOC_ENUM_SINGLE(WM8904_ANALOGUE_LEFT_INPUT_1, 2, 3, lin_text); 863 lin_text);
863 864
864static const struct snd_kcontrol_new lin_mux = 865static const struct snd_kcontrol_new lin_mux =
865 SOC_DAPM_ENUM("Left Capture Mux", lin_enum); 866 SOC_DAPM_ENUM("Left Capture Mux", lin_enum);
866 867
867static const struct soc_enum lin_inv_enum = 868static SOC_ENUM_SINGLE_DECL(lin_inv_enum, WM8904_ANALOGUE_LEFT_INPUT_1, 4,
868 SOC_ENUM_SINGLE(WM8904_ANALOGUE_LEFT_INPUT_1, 4, 3, lin_text); 869 lin_text);
869 870
870static const struct snd_kcontrol_new lin_inv_mux = 871static const struct snd_kcontrol_new lin_inv_mux =
871 SOC_DAPM_ENUM("Left Capture Inveting Mux", lin_inv_enum); 872 SOC_DAPM_ENUM("Left Capture Inveting Mux", lin_inv_enum);
@@ -874,14 +875,14 @@ static const char *rin_text[] = {
874 "IN1R", "IN2R", "IN3R" 875 "IN1R", "IN2R", "IN3R"
875}; 876};
876 877
877static const struct soc_enum rin_enum = 878static SOC_ENUM_SINGLE_DECL(rin_enum, WM8904_ANALOGUE_RIGHT_INPUT_1, 2,
878 SOC_ENUM_SINGLE(WM8904_ANALOGUE_RIGHT_INPUT_1, 2, 3, rin_text); 879 rin_text);
879 880
880static const struct snd_kcontrol_new rin_mux = 881static const struct snd_kcontrol_new rin_mux =
881 SOC_DAPM_ENUM("Right Capture Mux", rin_enum); 882 SOC_DAPM_ENUM("Right Capture Mux", rin_enum);
882 883
883static const struct soc_enum rin_inv_enum = 884static SOC_ENUM_SINGLE_DECL(rin_inv_enum, WM8904_ANALOGUE_RIGHT_INPUT_1, 4,
884 SOC_ENUM_SINGLE(WM8904_ANALOGUE_RIGHT_INPUT_1, 4, 3, rin_text); 885 rin_text);
885 886
886static const struct snd_kcontrol_new rin_inv_mux = 887static const struct snd_kcontrol_new rin_inv_mux =
887 SOC_DAPM_ENUM("Right Capture Inveting Mux", rin_inv_enum); 888 SOC_DAPM_ENUM("Right Capture Inveting Mux", rin_inv_enum);
@@ -890,26 +891,26 @@ static const char *aif_text[] = {
890 "Left", "Right" 891 "Left", "Right"
891}; 892};
892 893
893static const struct soc_enum aifoutl_enum = 894static SOC_ENUM_SINGLE_DECL(aifoutl_enum, WM8904_AUDIO_INTERFACE_0, 7,
894 SOC_ENUM_SINGLE(WM8904_AUDIO_INTERFACE_0, 7, 2, aif_text); 895 aif_text);
895 896
896static const struct snd_kcontrol_new aifoutl_mux = 897static const struct snd_kcontrol_new aifoutl_mux =
897 SOC_DAPM_ENUM("AIFOUTL Mux", aifoutl_enum); 898 SOC_DAPM_ENUM("AIFOUTL Mux", aifoutl_enum);
898 899
899static const struct soc_enum aifoutr_enum = 900static SOC_ENUM_SINGLE_DECL(aifoutr_enum, WM8904_AUDIO_INTERFACE_0, 6,
900 SOC_ENUM_SINGLE(WM8904_AUDIO_INTERFACE_0, 6, 2, aif_text); 901 aif_text);
901 902
902static const struct snd_kcontrol_new aifoutr_mux = 903static const struct snd_kcontrol_new aifoutr_mux =
903 SOC_DAPM_ENUM("AIFOUTR Mux", aifoutr_enum); 904 SOC_DAPM_ENUM("AIFOUTR Mux", aifoutr_enum);
904 905
905static const struct soc_enum aifinl_enum = 906static SOC_ENUM_SINGLE_DECL(aifinl_enum, WM8904_AUDIO_INTERFACE_0, 5,
906 SOC_ENUM_SINGLE(WM8904_AUDIO_INTERFACE_0, 5, 2, aif_text); 907 aif_text);
907 908
908static const struct snd_kcontrol_new aifinl_mux = 909static const struct snd_kcontrol_new aifinl_mux =
909 SOC_DAPM_ENUM("AIFINL Mux", aifinl_enum); 910 SOC_DAPM_ENUM("AIFINL Mux", aifinl_enum);
910 911
911static const struct soc_enum aifinr_enum = 912static SOC_ENUM_SINGLE_DECL(aifinr_enum, WM8904_AUDIO_INTERFACE_0, 4,
912 SOC_ENUM_SINGLE(WM8904_AUDIO_INTERFACE_0, 4, 2, aif_text); 913 aif_text);
913 914
914static const struct snd_kcontrol_new aifinr_mux = 915static const struct snd_kcontrol_new aifinr_mux =
915 SOC_DAPM_ENUM("AIFINR Mux", aifinr_enum); 916 SOC_DAPM_ENUM("AIFINR Mux", aifinr_enum);
@@ -991,26 +992,26 @@ static const char *out_mux_text[] = {
991 "DAC", "Bypass" 992 "DAC", "Bypass"
992}; 993};
993 994
994static const struct soc_enum hpl_enum = 995static SOC_ENUM_SINGLE_DECL(hpl_enum, WM8904_ANALOGUE_OUT12_ZC, 3,
995 SOC_ENUM_SINGLE(WM8904_ANALOGUE_OUT12_ZC, 3, 2, out_mux_text); 996 out_mux_text);
996 997
997static const struct snd_kcontrol_new hpl_mux = 998static const struct snd_kcontrol_new hpl_mux =
998 SOC_DAPM_ENUM("HPL Mux", hpl_enum); 999 SOC_DAPM_ENUM("HPL Mux", hpl_enum);
999 1000
1000static const struct soc_enum hpr_enum = 1001static SOC_ENUM_SINGLE_DECL(hpr_enum, WM8904_ANALOGUE_OUT12_ZC, 2,
1001 SOC_ENUM_SINGLE(WM8904_ANALOGUE_OUT12_ZC, 2, 2, out_mux_text); 1002 out_mux_text);
1002 1003
1003static const struct snd_kcontrol_new hpr_mux = 1004static const struct snd_kcontrol_new hpr_mux =
1004 SOC_DAPM_ENUM("HPR Mux", hpr_enum); 1005 SOC_DAPM_ENUM("HPR Mux", hpr_enum);
1005 1006
1006static const struct soc_enum linel_enum = 1007static SOC_ENUM_SINGLE_DECL(linel_enum, WM8904_ANALOGUE_OUT12_ZC, 1,
1007 SOC_ENUM_SINGLE(WM8904_ANALOGUE_OUT12_ZC, 1, 2, out_mux_text); 1008 out_mux_text);
1008 1009
1009static const struct snd_kcontrol_new linel_mux = 1010static const struct snd_kcontrol_new linel_mux =
1010 SOC_DAPM_ENUM("LINEL Mux", linel_enum); 1011 SOC_DAPM_ENUM("LINEL Mux", linel_enum);
1011 1012
1012static const struct soc_enum liner_enum = 1013static SOC_ENUM_SINGLE_DECL(liner_enum, WM8904_ANALOGUE_OUT12_ZC, 0,
1013 SOC_ENUM_SINGLE(WM8904_ANALOGUE_OUT12_ZC, 0, 2, out_mux_text); 1014 out_mux_text);
1014 1015
1015static const struct snd_kcontrol_new liner_mux = 1016static const struct snd_kcontrol_new liner_mux =
1016 SOC_DAPM_ENUM("LINER Mux", liner_enum); 1017 SOC_DAPM_ENUM("LINER Mux", liner_enum);
@@ -1019,14 +1020,14 @@ static const char *sidetone_text[] = {
1019 "None", "Left", "Right" 1020 "None", "Left", "Right"
1020}; 1021};
1021 1022
1022static const struct soc_enum dacl_sidetone_enum = 1023static SOC_ENUM_SINGLE_DECL(dacl_sidetone_enum, WM8904_DAC_DIGITAL_0, 2,
1023 SOC_ENUM_SINGLE(WM8904_DAC_DIGITAL_0, 2, 3, sidetone_text); 1024 sidetone_text);
1024 1025
1025static const struct snd_kcontrol_new dacl_sidetone_mux = 1026static const struct snd_kcontrol_new dacl_sidetone_mux =
1026 SOC_DAPM_ENUM("Left Sidetone Mux", dacl_sidetone_enum); 1027 SOC_DAPM_ENUM("Left Sidetone Mux", dacl_sidetone_enum);
1027 1028
1028static const struct soc_enum dacr_sidetone_enum = 1029static SOC_ENUM_SINGLE_DECL(dacr_sidetone_enum, WM8904_DAC_DIGITAL_0, 0,
1029 SOC_ENUM_SINGLE(WM8904_DAC_DIGITAL_0, 0, 3, sidetone_text); 1030 sidetone_text);
1030 1031
1031static const struct snd_kcontrol_new dacr_sidetone_mux = 1032static const struct snd_kcontrol_new dacr_sidetone_mux =
1032 SOC_DAPM_ENUM("Right Sidetone Mux", dacr_sidetone_enum); 1033 SOC_DAPM_ENUM("Right Sidetone Mux", dacr_sidetone_enum);
@@ -1981,7 +1982,7 @@ static void wm8904_handle_retune_mobile_pdata(struct snd_soc_codec *codec)
1981 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n", 1982 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
1982 wm8904->num_retune_mobile_texts); 1983 wm8904->num_retune_mobile_texts);
1983 1984
1984 wm8904->retune_mobile_enum.max = wm8904->num_retune_mobile_texts; 1985 wm8904->retune_mobile_enum.items = wm8904->num_retune_mobile_texts;
1985 wm8904->retune_mobile_enum.texts = wm8904->retune_mobile_texts; 1986 wm8904->retune_mobile_enum.texts = wm8904->retune_mobile_texts;
1986 1987
1987 ret = snd_soc_add_codec_controls(codec, &control, 1); 1988 ret = snd_soc_add_codec_controls(codec, &control, 1);
@@ -2022,7 +2023,7 @@ static void wm8904_handle_pdata(struct snd_soc_codec *codec)
2022 for (i = 0; i < pdata->num_drc_cfgs; i++) 2023 for (i = 0; i < pdata->num_drc_cfgs; i++)
2023 wm8904->drc_texts[i] = pdata->drc_cfgs[i].name; 2024 wm8904->drc_texts[i] = pdata->drc_cfgs[i].name;
2024 2025
2025 wm8904->drc_enum.max = pdata->num_drc_cfgs; 2026 wm8904->drc_enum.items = pdata->num_drc_cfgs;
2026 wm8904->drc_enum.texts = wm8904->drc_texts; 2027 wm8904->drc_enum.texts = wm8904->drc_texts;
2027 2028
2028 ret = snd_soc_add_codec_controls(codec, &control, 1); 2029 ret = snd_soc_add_codec_controls(codec, &control, 1);
@@ -2047,9 +2048,6 @@ static void wm8904_handle_pdata(struct snd_soc_codec *codec)
2047static int wm8904_probe(struct snd_soc_codec *codec) 2048static int wm8904_probe(struct snd_soc_codec *codec)
2048{ 2049{
2049 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); 2050 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
2050 int ret;
2051
2052 codec->control_data = wm8904->regmap;
2053 2051
2054 switch (wm8904->devtype) { 2052 switch (wm8904->devtype) {
2055 case WM8904: 2053 case WM8904:
@@ -2063,12 +2061,6 @@ static int wm8904_probe(struct snd_soc_codec *codec)
2063 return -EINVAL; 2061 return -EINVAL;
2064 } 2062 }
2065 2063
2066 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
2067 if (ret != 0) {
2068 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
2069 return ret;
2070 }
2071
2072 wm8904_handle_pdata(codec); 2064 wm8904_handle_pdata(codec);
2073 2065
2074 wm8904_add_widgets(codec); 2066 wm8904_add_widgets(codec);
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c
index b404c26c1753..fc6eec9ad66b 100644
--- a/sound/soc/codecs/wm8940.c
+++ b/sound/soc/codecs/wm8940.c
@@ -154,22 +154,22 @@ static const struct reg_default wm8940_reg_defaults[] = {
154}; 154};
155 155
156static const char *wm8940_companding[] = { "Off", "NC", "u-law", "A-law" }; 156static const char *wm8940_companding[] = { "Off", "NC", "u-law", "A-law" };
157static const struct soc_enum wm8940_adc_companding_enum 157static SOC_ENUM_SINGLE_DECL(wm8940_adc_companding_enum,
158= SOC_ENUM_SINGLE(WM8940_COMPANDINGCTL, 1, 4, wm8940_companding); 158 WM8940_COMPANDINGCTL, 1, wm8940_companding);
159static const struct soc_enum wm8940_dac_companding_enum 159static SOC_ENUM_SINGLE_DECL(wm8940_dac_companding_enum,
160= SOC_ENUM_SINGLE(WM8940_COMPANDINGCTL, 3, 4, wm8940_companding); 160 WM8940_COMPANDINGCTL, 3, wm8940_companding);
161 161
162static const char *wm8940_alc_mode_text[] = {"ALC", "Limiter"}; 162static const char *wm8940_alc_mode_text[] = {"ALC", "Limiter"};
163static const struct soc_enum wm8940_alc_mode_enum 163static SOC_ENUM_SINGLE_DECL(wm8940_alc_mode_enum,
164= SOC_ENUM_SINGLE(WM8940_ALC3, 8, 2, wm8940_alc_mode_text); 164 WM8940_ALC3, 8, wm8940_alc_mode_text);
165 165
166static const char *wm8940_mic_bias_level_text[] = {"0.9", "0.65"}; 166static const char *wm8940_mic_bias_level_text[] = {"0.9", "0.65"};
167static const struct soc_enum wm8940_mic_bias_level_enum 167static SOC_ENUM_SINGLE_DECL(wm8940_mic_bias_level_enum,
168= SOC_ENUM_SINGLE(WM8940_INPUTCTL, 8, 2, wm8940_mic_bias_level_text); 168 WM8940_INPUTCTL, 8, wm8940_mic_bias_level_text);
169 169
170static const char *wm8940_filter_mode_text[] = {"Audio", "Application"}; 170static const char *wm8940_filter_mode_text[] = {"Audio", "Application"};
171static const struct soc_enum wm8940_filter_mode_enum 171static SOC_ENUM_SINGLE_DECL(wm8940_filter_mode_enum,
172= SOC_ENUM_SINGLE(WM8940_ADC, 7, 2, wm8940_filter_mode_text); 172 WM8940_ADC, 7, wm8940_filter_mode_text);
173 173
174static DECLARE_TLV_DB_SCALE(wm8940_spk_vol_tlv, -5700, 100, 1); 174static DECLARE_TLV_DB_SCALE(wm8940_spk_vol_tlv, -5700, 100, 1);
175static DECLARE_TLV_DB_SCALE(wm8940_att_tlv, -1000, 1000, 0); 175static DECLARE_TLV_DB_SCALE(wm8940_att_tlv, -1000, 1000, 0);
@@ -712,12 +712,6 @@ static int wm8940_probe(struct snd_soc_codec *codec)
712 int ret; 712 int ret;
713 u16 reg; 713 u16 reg;
714 714
715 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
716 if (ret < 0) {
717 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
718 return ret;
719 }
720
721 ret = wm8940_reset(codec); 715 ret = wm8940_reset(codec);
722 if (ret < 0) { 716 if (ret < 0) {
723 dev_err(codec->dev, "Failed to issue reset\n"); 717 dev_err(codec->dev, "Failed to issue reset\n");
diff --git a/sound/soc/codecs/wm8955.c b/sound/soc/codecs/wm8955.c
index 82c8ba975720..fecd4e4f4c57 100644
--- a/sound/soc/codecs/wm8955.c
+++ b/sound/soc/codecs/wm8955.c
@@ -416,22 +416,21 @@ static const char *bass_mode_text[] = {
416 "Linear", "Adaptive", 416 "Linear", "Adaptive",
417}; 417};
418 418
419static const struct soc_enum bass_mode = 419static SOC_ENUM_SINGLE_DECL(bass_mode, WM8955_BASS_CONTROL, 7, bass_mode_text);
420 SOC_ENUM_SINGLE(WM8955_BASS_CONTROL, 7, 2, bass_mode_text);
421 420
422static const char *bass_cutoff_text[] = { 421static const char *bass_cutoff_text[] = {
423 "Low", "High" 422 "Low", "High"
424}; 423};
425 424
426static const struct soc_enum bass_cutoff = 425static SOC_ENUM_SINGLE_DECL(bass_cutoff, WM8955_BASS_CONTROL, 6,
427 SOC_ENUM_SINGLE(WM8955_BASS_CONTROL, 6, 2, bass_cutoff_text); 426 bass_cutoff_text);
428 427
429static const char *treble_cutoff_text[] = { 428static const char *treble_cutoff_text[] = {
430 "High", "Low" 429 "High", "Low"
431}; 430};
432 431
433static const struct soc_enum treble_cutoff = 432static SOC_ENUM_SINGLE_DECL(treble_cutoff, WM8955_TREBLE_CONTROL, 2,
434 SOC_ENUM_SINGLE(WM8955_TREBLE_CONTROL, 6, 2, treble_cutoff_text); 433 treble_cutoff_text);
435 434
436static const DECLARE_TLV_DB_SCALE(digital_tlv, -12750, 50, 1); 435static const DECLARE_TLV_DB_SCALE(digital_tlv, -12750, 50, 1);
437static const DECLARE_TLV_DB_SCALE(atten_tlv, -600, 600, 0); 436static const DECLARE_TLV_DB_SCALE(atten_tlv, -600, 600, 0);
@@ -896,14 +895,6 @@ static int wm8955_probe(struct snd_soc_codec *codec)
896 struct wm8955_pdata *pdata = dev_get_platdata(codec->dev); 895 struct wm8955_pdata *pdata = dev_get_platdata(codec->dev);
897 int ret, i; 896 int ret, i;
898 897
899 codec->control_data = wm8955->regmap;
900
901 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
902 if (ret != 0) {
903 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
904 return ret;
905 }
906
907 for (i = 0; i < ARRAY_SIZE(wm8955->supplies); i++) 898 for (i = 0; i < ARRAY_SIZE(wm8955->supplies); i++)
908 wm8955->supplies[i].supply = wm8955_supply_names[i]; 899 wm8955->supplies[i].supply = wm8955_supply_names[i];
909 900
diff --git a/sound/soc/codecs/wm8958-dsp2.c b/sound/soc/codecs/wm8958-dsp2.c
index d4248e00160e..7ac2e511403c 100644
--- a/sound/soc/codecs/wm8958-dsp2.c
+++ b/sound/soc/codecs/wm8958-dsp2.c
@@ -944,7 +944,7 @@ void wm8958_dsp2_init(struct snd_soc_codec *codec)
944 for (i = 0; i < pdata->num_mbc_cfgs; i++) 944 for (i = 0; i < pdata->num_mbc_cfgs; i++)
945 wm8994->mbc_texts[i] = pdata->mbc_cfgs[i].name; 945 wm8994->mbc_texts[i] = pdata->mbc_cfgs[i].name;
946 946
947 wm8994->mbc_enum.max = pdata->num_mbc_cfgs; 947 wm8994->mbc_enum.items = pdata->num_mbc_cfgs;
948 wm8994->mbc_enum.texts = wm8994->mbc_texts; 948 wm8994->mbc_enum.texts = wm8994->mbc_texts;
949 949
950 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, 950 ret = snd_soc_add_codec_controls(wm8994->hubs.codec,
@@ -973,7 +973,7 @@ void wm8958_dsp2_init(struct snd_soc_codec *codec)
973 for (i = 0; i < pdata->num_vss_cfgs; i++) 973 for (i = 0; i < pdata->num_vss_cfgs; i++)
974 wm8994->vss_texts[i] = pdata->vss_cfgs[i].name; 974 wm8994->vss_texts[i] = pdata->vss_cfgs[i].name;
975 975
976 wm8994->vss_enum.max = pdata->num_vss_cfgs; 976 wm8994->vss_enum.items = pdata->num_vss_cfgs;
977 wm8994->vss_enum.texts = wm8994->vss_texts; 977 wm8994->vss_enum.texts = wm8994->vss_texts;
978 978
979 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, 979 ret = snd_soc_add_codec_controls(wm8994->hubs.codec,
@@ -1003,7 +1003,7 @@ void wm8958_dsp2_init(struct snd_soc_codec *codec)
1003 for (i = 0; i < pdata->num_vss_hpf_cfgs; i++) 1003 for (i = 0; i < pdata->num_vss_hpf_cfgs; i++)
1004 wm8994->vss_hpf_texts[i] = pdata->vss_hpf_cfgs[i].name; 1004 wm8994->vss_hpf_texts[i] = pdata->vss_hpf_cfgs[i].name;
1005 1005
1006 wm8994->vss_hpf_enum.max = pdata->num_vss_hpf_cfgs; 1006 wm8994->vss_hpf_enum.items = pdata->num_vss_hpf_cfgs;
1007 wm8994->vss_hpf_enum.texts = wm8994->vss_hpf_texts; 1007 wm8994->vss_hpf_enum.texts = wm8994->vss_hpf_texts;
1008 1008
1009 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, 1009 ret = snd_soc_add_codec_controls(wm8994->hubs.codec,
@@ -1034,7 +1034,7 @@ void wm8958_dsp2_init(struct snd_soc_codec *codec)
1034 for (i = 0; i < pdata->num_enh_eq_cfgs; i++) 1034 for (i = 0; i < pdata->num_enh_eq_cfgs; i++)
1035 wm8994->enh_eq_texts[i] = pdata->enh_eq_cfgs[i].name; 1035 wm8994->enh_eq_texts[i] = pdata->enh_eq_cfgs[i].name;
1036 1036
1037 wm8994->enh_eq_enum.max = pdata->num_enh_eq_cfgs; 1037 wm8994->enh_eq_enum.items = pdata->num_enh_eq_cfgs;
1038 wm8994->enh_eq_enum.texts = wm8994->enh_eq_texts; 1038 wm8994->enh_eq_enum.texts = wm8994->enh_eq_texts;
1039 1039
1040 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, 1040 ret = snd_soc_add_codec_controls(wm8994->hubs.codec,
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index f156010e52bc..d04e9cad445c 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -976,12 +976,6 @@ static int wm8960_probe(struct snd_soc_codec *codec)
976 wm8960->set_bias_level = wm8960_set_bias_level_capless; 976 wm8960->set_bias_level = wm8960_set_bias_level_capless;
977 } 977 }
978 978
979 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
980 if (ret < 0) {
981 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
982 return ret;
983 }
984
985 ret = wm8960_reset(codec); 979 ret = wm8960_reset(codec);
986 if (ret < 0) { 980 if (ret < 0) {
987 dev_err(codec->dev, "Failed to issue reset\n"); 981 dev_err(codec->dev, "Failed to issue reset\n");
diff --git a/sound/soc/codecs/wm8961.c b/sound/soc/codecs/wm8961.c
index 900328e28a15..9c88f04442b3 100644
--- a/sound/soc/codecs/wm8961.c
+++ b/sound/soc/codecs/wm8961.c
@@ -317,15 +317,15 @@ static const char *adc_hpf_text[] = {
317 "Hi-fi", "Voice 1", "Voice 2", "Voice 3", 317 "Hi-fi", "Voice 1", "Voice 2", "Voice 3",
318}; 318};
319 319
320static const struct soc_enum adc_hpf = 320static SOC_ENUM_SINGLE_DECL(adc_hpf,
321 SOC_ENUM_SINGLE(WM8961_ADC_DAC_CONTROL_2, 7, 4, adc_hpf_text); 321 WM8961_ADC_DAC_CONTROL_2, 7, adc_hpf_text);
322 322
323static const char *dac_deemph_text[] = { 323static const char *dac_deemph_text[] = {
324 "None", "32kHz", "44.1kHz", "48kHz", 324 "None", "32kHz", "44.1kHz", "48kHz",
325}; 325};
326 326
327static const struct soc_enum dac_deemph = 327static SOC_ENUM_SINGLE_DECL(dac_deemph,
328 SOC_ENUM_SINGLE(WM8961_ADC_DAC_CONTROL_1, 1, 4, dac_deemph_text); 328 WM8961_ADC_DAC_CONTROL_1, 1, dac_deemph_text);
329 329
330static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); 330static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
331static const DECLARE_TLV_DB_SCALE(hp_sec_tlv, -700, 100, 0); 331static const DECLARE_TLV_DB_SCALE(hp_sec_tlv, -700, 100, 0);
@@ -385,11 +385,11 @@ static const char *sidetone_text[] = {
385 "None", "Left", "Right" 385 "None", "Left", "Right"
386}; 386};
387 387
388static const struct soc_enum dacl_sidetone = 388static SOC_ENUM_SINGLE_DECL(dacl_sidetone,
389 SOC_ENUM_SINGLE(WM8961_DSP_SIDETONE_0, 2, 3, sidetone_text); 389 WM8961_DSP_SIDETONE_0, 2, sidetone_text);
390 390
391static const struct soc_enum dacr_sidetone = 391static SOC_ENUM_SINGLE_DECL(dacr_sidetone,
392 SOC_ENUM_SINGLE(WM8961_DSP_SIDETONE_1, 2, 3, sidetone_text); 392 WM8961_DSP_SIDETONE_1, 2, sidetone_text);
393 393
394static const struct snd_kcontrol_new dacl_mux = 394static const struct snd_kcontrol_new dacl_mux =
395 SOC_DAPM_ENUM("DACL Sidetone", dacl_sidetone); 395 SOC_DAPM_ENUM("DACL Sidetone", dacl_sidetone);
@@ -836,15 +836,8 @@ static struct snd_soc_dai_driver wm8961_dai = {
836static int wm8961_probe(struct snd_soc_codec *codec) 836static int wm8961_probe(struct snd_soc_codec *codec)
837{ 837{
838 struct snd_soc_dapm_context *dapm = &codec->dapm; 838 struct snd_soc_dapm_context *dapm = &codec->dapm;
839 int ret = 0;
840 u16 reg; 839 u16 reg;
841 840
842 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
843 if (ret != 0) {
844 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
845 return ret;
846 }
847
848 /* Enable class W */ 841 /* Enable class W */
849 reg = snd_soc_read(codec, WM8961_CHARGE_PUMP_B); 842 reg = snd_soc_read(codec, WM8961_CHARGE_PUMP_B);
850 reg |= WM8961_CP_DYN_PWR_MASK; 843 reg |= WM8961_CP_DYN_PWR_MASK;
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index 97db3b45b411..5522d2566c67 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -1479,7 +1479,9 @@ static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
1479 1479
1480static int wm8962_dsp2_write_config(struct snd_soc_codec *codec) 1480static int wm8962_dsp2_write_config(struct snd_soc_codec *codec)
1481{ 1481{
1482 return regcache_sync_region(codec->control_data, 1482 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
1483
1484 return regcache_sync_region(wm8962->regmap,
1483 WM8962_HDBASS_AI_1, WM8962_MAX_REGISTER); 1485 WM8962_HDBASS_AI_1, WM8962_MAX_REGISTER);
1484} 1486}
1485 1487
@@ -1658,16 +1660,16 @@ static const char *cap_hpf_mode_text[] = {
1658 "Hi-fi", "Application" 1660 "Hi-fi", "Application"
1659}; 1661};
1660 1662
1661static const struct soc_enum cap_hpf_mode = 1663static SOC_ENUM_SINGLE_DECL(cap_hpf_mode,
1662 SOC_ENUM_SINGLE(WM8962_ADC_DAC_CONTROL_2, 10, 2, cap_hpf_mode_text); 1664 WM8962_ADC_DAC_CONTROL_2, 10, cap_hpf_mode_text);
1663 1665
1664 1666
1665static const char *cap_lhpf_mode_text[] = { 1667static const char *cap_lhpf_mode_text[] = {
1666 "LPF", "HPF" 1668 "LPF", "HPF"
1667}; 1669};
1668 1670
1669static const struct soc_enum cap_lhpf_mode = 1671static SOC_ENUM_SINGLE_DECL(cap_lhpf_mode,
1670 SOC_ENUM_SINGLE(WM8962_LHPF1, 1, 2, cap_lhpf_mode_text); 1672 WM8962_LHPF1, 1, cap_lhpf_mode_text);
1671 1673
1672static const struct snd_kcontrol_new wm8962_snd_controls[] = { 1674static const struct snd_kcontrol_new wm8962_snd_controls[] = {
1673SOC_DOUBLE("Input Mixer Switch", WM8962_INPUT_MIXER_CONTROL_1, 3, 2, 1, 1), 1675SOC_DOUBLE("Input Mixer Switch", WM8962_INPUT_MIXER_CONTROL_1, 3, 2, 1, 1),
@@ -2014,40 +2016,40 @@ static int dsp2_event(struct snd_soc_dapm_widget *w,
2014 2016
2015static const char *st_text[] = { "None", "Left", "Right" }; 2017static const char *st_text[] = { "None", "Left", "Right" };
2016 2018
2017static const struct soc_enum str_enum = 2019static SOC_ENUM_SINGLE_DECL(str_enum,
2018 SOC_ENUM_SINGLE(WM8962_DAC_DSP_MIXING_1, 2, 3, st_text); 2020 WM8962_DAC_DSP_MIXING_1, 2, st_text);
2019 2021
2020static const struct snd_kcontrol_new str_mux = 2022static const struct snd_kcontrol_new str_mux =
2021 SOC_DAPM_ENUM("Right Sidetone", str_enum); 2023 SOC_DAPM_ENUM("Right Sidetone", str_enum);
2022 2024
2023static const struct soc_enum stl_enum = 2025static SOC_ENUM_SINGLE_DECL(stl_enum,
2024 SOC_ENUM_SINGLE(WM8962_DAC_DSP_MIXING_2, 2, 3, st_text); 2026 WM8962_DAC_DSP_MIXING_2, 2, st_text);
2025 2027
2026static const struct snd_kcontrol_new stl_mux = 2028static const struct snd_kcontrol_new stl_mux =
2027 SOC_DAPM_ENUM("Left Sidetone", stl_enum); 2029 SOC_DAPM_ENUM("Left Sidetone", stl_enum);
2028 2030
2029static const char *outmux_text[] = { "DAC", "Mixer" }; 2031static const char *outmux_text[] = { "DAC", "Mixer" };
2030 2032
2031static const struct soc_enum spkoutr_enum = 2033static SOC_ENUM_SINGLE_DECL(spkoutr_enum,
2032 SOC_ENUM_SINGLE(WM8962_SPEAKER_MIXER_2, 7, 2, outmux_text); 2034 WM8962_SPEAKER_MIXER_2, 7, outmux_text);
2033 2035
2034static const struct snd_kcontrol_new spkoutr_mux = 2036static const struct snd_kcontrol_new spkoutr_mux =
2035 SOC_DAPM_ENUM("SPKOUTR Mux", spkoutr_enum); 2037 SOC_DAPM_ENUM("SPKOUTR Mux", spkoutr_enum);
2036 2038
2037static const struct soc_enum spkoutl_enum = 2039static SOC_ENUM_SINGLE_DECL(spkoutl_enum,
2038 SOC_ENUM_SINGLE(WM8962_SPEAKER_MIXER_1, 7, 2, outmux_text); 2040 WM8962_SPEAKER_MIXER_1, 7, outmux_text);
2039 2041
2040static const struct snd_kcontrol_new spkoutl_mux = 2042static const struct snd_kcontrol_new spkoutl_mux =
2041 SOC_DAPM_ENUM("SPKOUTL Mux", spkoutl_enum); 2043 SOC_DAPM_ENUM("SPKOUTL Mux", spkoutl_enum);
2042 2044
2043static const struct soc_enum hpoutr_enum = 2045static SOC_ENUM_SINGLE_DECL(hpoutr_enum,
2044 SOC_ENUM_SINGLE(WM8962_HEADPHONE_MIXER_2, 7, 2, outmux_text); 2046 WM8962_HEADPHONE_MIXER_2, 7, outmux_text);
2045 2047
2046static const struct snd_kcontrol_new hpoutr_mux = 2048static const struct snd_kcontrol_new hpoutr_mux =
2047 SOC_DAPM_ENUM("HPOUTR Mux", hpoutr_enum); 2049 SOC_DAPM_ENUM("HPOUTR Mux", hpoutr_enum);
2048 2050
2049static const struct soc_enum hpoutl_enum = 2051static SOC_ENUM_SINGLE_DECL(hpoutl_enum,
2050 SOC_ENUM_SINGLE(WM8962_HEADPHONE_MIXER_1, 7, 2, outmux_text); 2052 WM8962_HEADPHONE_MIXER_1, 7, outmux_text);
2051 2053
2052static const struct snd_kcontrol_new hpoutl_mux = 2054static const struct snd_kcontrol_new hpoutl_mux =
2053 SOC_DAPM_ENUM("HPOUTL Mux", hpoutl_enum); 2055 SOC_DAPM_ENUM("HPOUTL Mux", hpoutl_enum);
@@ -2884,9 +2886,13 @@ static int wm8962_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
2884 snd_soc_write(codec, WM8962_FLL_CONTROL_7, fll_div.lambda); 2886 snd_soc_write(codec, WM8962_FLL_CONTROL_7, fll_div.lambda);
2885 snd_soc_write(codec, WM8962_FLL_CONTROL_8, fll_div.n); 2887 snd_soc_write(codec, WM8962_FLL_CONTROL_8, fll_div.n);
2886 2888
2887 try_wait_for_completion(&wm8962->fll_lock); 2889 reinit_completion(&wm8962->fll_lock);
2888 2890
2889 pm_runtime_get_sync(codec->dev); 2891 ret = pm_runtime_get_sync(codec->dev);
2892 if (ret < 0) {
2893 dev_err(codec->dev, "Failed to resume device: %d\n", ret);
2894 return ret;
2895 }
2890 2896
2891 snd_soc_update_bits(codec, WM8962_FLL_CONTROL_1, 2897 snd_soc_update_bits(codec, WM8962_FLL_CONTROL_1,
2892 WM8962_FLL_FRAC | WM8962_FLL_REFCLK_SRC_MASK | 2898 WM8962_FLL_FRAC | WM8962_FLL_REFCLK_SRC_MASK |
@@ -2894,8 +2900,6 @@ static int wm8962_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
2894 2900
2895 dev_dbg(codec->dev, "FLL configured for %dHz->%dHz\n", Fref, Fout); 2901 dev_dbg(codec->dev, "FLL configured for %dHz->%dHz\n", Fref, Fout);
2896 2902
2897 ret = 0;
2898
2899 /* This should be a massive overestimate but go even 2903 /* This should be a massive overestimate but go even
2900 * higher if we'll error out 2904 * higher if we'll error out
2901 */ 2905 */
@@ -2909,14 +2913,17 @@ static int wm8962_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
2909 2913
2910 if (timeout == 0 && wm8962->irq) { 2914 if (timeout == 0 && wm8962->irq) {
2911 dev_err(codec->dev, "FLL lock timed out"); 2915 dev_err(codec->dev, "FLL lock timed out");
2912 ret = -ETIMEDOUT; 2916 snd_soc_update_bits(codec, WM8962_FLL_CONTROL_1,
2917 WM8962_FLL_ENA, 0);
2918 pm_runtime_put(codec->dev);
2919 return -ETIMEDOUT;
2913 } 2920 }
2914 2921
2915 wm8962->fll_fref = Fref; 2922 wm8962->fll_fref = Fref;
2916 wm8962->fll_fout = Fout; 2923 wm8962->fll_fout = Fout;
2917 wm8962->fll_src = source; 2924 wm8962->fll_src = source;
2918 2925
2919 return ret; 2926 return 0;
2920} 2927}
2921 2928
2922static int wm8962_mute(struct snd_soc_dai *dai, int mute) 2929static int wm8962_mute(struct snd_soc_dai *dai, int mute)
@@ -3003,9 +3010,16 @@ static irqreturn_t wm8962_irq(int irq, void *data)
3003 unsigned int active; 3010 unsigned int active;
3004 int reg, ret; 3011 int reg, ret;
3005 3012
3013 ret = pm_runtime_get_sync(dev);
3014 if (ret < 0) {
3015 dev_err(dev, "Failed to resume: %d\n", ret);
3016 return IRQ_NONE;
3017 }
3018
3006 ret = regmap_read(wm8962->regmap, WM8962_INTERRUPT_STATUS_2_MASK, 3019 ret = regmap_read(wm8962->regmap, WM8962_INTERRUPT_STATUS_2_MASK,
3007 &mask); 3020 &mask);
3008 if (ret != 0) { 3021 if (ret != 0) {
3022 pm_runtime_put(dev);
3009 dev_err(dev, "Failed to read interrupt mask: %d\n", 3023 dev_err(dev, "Failed to read interrupt mask: %d\n",
3010 ret); 3024 ret);
3011 return IRQ_NONE; 3025 return IRQ_NONE;
@@ -3013,14 +3027,17 @@ static irqreturn_t wm8962_irq(int irq, void *data)
3013 3027
3014 ret = regmap_read(wm8962->regmap, WM8962_INTERRUPT_STATUS_2, &active); 3028 ret = regmap_read(wm8962->regmap, WM8962_INTERRUPT_STATUS_2, &active);
3015 if (ret != 0) { 3029 if (ret != 0) {
3030 pm_runtime_put(dev);
3016 dev_err(dev, "Failed to read interrupt: %d\n", ret); 3031 dev_err(dev, "Failed to read interrupt: %d\n", ret);
3017 return IRQ_NONE; 3032 return IRQ_NONE;
3018 } 3033 }
3019 3034
3020 active &= ~mask; 3035 active &= ~mask;
3021 3036
3022 if (!active) 3037 if (!active) {
3038 pm_runtime_put(dev);
3023 return IRQ_NONE; 3039 return IRQ_NONE;
3040 }
3024 3041
3025 /* Acknowledge the interrupts */ 3042 /* Acknowledge the interrupts */
3026 ret = regmap_write(wm8962->regmap, WM8962_INTERRUPT_STATUS_2, active); 3043 ret = regmap_write(wm8962->regmap, WM8962_INTERRUPT_STATUS_2, active);
@@ -3070,6 +3087,8 @@ static irqreturn_t wm8962_irq(int irq, void *data)
3070 msecs_to_jiffies(250)); 3087 msecs_to_jiffies(250));
3071 } 3088 }
3072 3089
3090 pm_runtime_put(dev);
3091
3073 return IRQ_HANDLED; 3092 return IRQ_HANDLED;
3074} 3093}
3075 3094
@@ -3089,6 +3108,7 @@ static irqreturn_t wm8962_irq(int irq, void *data)
3089int wm8962_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack) 3108int wm8962_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
3090{ 3109{
3091 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 3110 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
3111 struct snd_soc_dapm_context *dapm = &codec->dapm;
3092 int irq_mask, enable; 3112 int irq_mask, enable;
3093 3113
3094 wm8962->jack = jack; 3114 wm8962->jack = jack;
@@ -3109,14 +3129,18 @@ int wm8962_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
3109 snd_soc_jack_report(wm8962->jack, 0, 3129 snd_soc_jack_report(wm8962->jack, 0,
3110 SND_JACK_MICROPHONE | SND_JACK_BTN_0); 3130 SND_JACK_MICROPHONE | SND_JACK_BTN_0);
3111 3131
3132 snd_soc_dapm_mutex_lock(dapm);
3133
3112 if (jack) { 3134 if (jack) {
3113 snd_soc_dapm_force_enable_pin(&codec->dapm, "SYSCLK"); 3135 snd_soc_dapm_force_enable_pin_unlocked(dapm, "SYSCLK");
3114 snd_soc_dapm_force_enable_pin(&codec->dapm, "MICBIAS"); 3136 snd_soc_dapm_force_enable_pin_unlocked(dapm, "MICBIAS");
3115 } else { 3137 } else {
3116 snd_soc_dapm_disable_pin(&codec->dapm, "SYSCLK"); 3138 snd_soc_dapm_disable_pin_unlocked(dapm, "SYSCLK");
3117 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS"); 3139 snd_soc_dapm_disable_pin_unlocked(dapm, "MICBIAS");
3118 } 3140 }
3119 3141
3142 snd_soc_dapm_mutex_unlock(dapm);
3143
3120 return 0; 3144 return 0;
3121} 3145}
3122EXPORT_SYMBOL_GPL(wm8962_mic_detect); 3146EXPORT_SYMBOL_GPL(wm8962_mic_detect);
@@ -3400,13 +3424,6 @@ static int wm8962_probe(struct snd_soc_codec *codec)
3400 bool dmicclk, dmicdat; 3424 bool dmicclk, dmicdat;
3401 3425
3402 wm8962->codec = codec; 3426 wm8962->codec = codec;
3403 codec->control_data = wm8962->regmap;
3404
3405 ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
3406 if (ret != 0) {
3407 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
3408 return ret;
3409 }
3410 3427
3411 wm8962->disable_nb[0].notifier_call = wm8962_regulator_event_0; 3428 wm8962->disable_nb[0].notifier_call = wm8962_regulator_event_0;
3412 wm8962->disable_nb[1].notifier_call = wm8962_regulator_event_1; 3429 wm8962->disable_nb[1].notifier_call = wm8962_regulator_event_1;
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
index 67aba78a7ca5..09b7b4200221 100644
--- a/sound/soc/codecs/wm8971.c
+++ b/sound/soc/codecs/wm8971.c
@@ -648,12 +648,6 @@ static int wm8971_probe(struct snd_soc_codec *codec)
648 int ret = 0; 648 int ret = 0;
649 u16 reg; 649 u16 reg;
650 650
651 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
652 if (ret < 0) {
653 printk(KERN_ERR "wm8971: failed to set cache I/O: %d\n", ret);
654 return ret;
655 }
656
657 INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8971_work); 651 INIT_DELAYED_WORK(&codec->dapm.delayed_work, wm8971_work);
658 wm8971_workq = create_workqueue("wm8971"); 652 wm8971_workq = create_workqueue("wm8971");
659 if (wm8971_workq == NULL) 653 if (wm8971_workq == NULL)
diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c
index 15f45c7bd833..0627c56fa44e 100644
--- a/sound/soc/codecs/wm8974.c
+++ b/sound/soc/codecs/wm8974.c
@@ -84,8 +84,8 @@ static const struct soc_enum wm8974_enum[] = {
84 84
85static const char *wm8974_auxmode_text[] = { "Buffer", "Mixer" }; 85static const char *wm8974_auxmode_text[] = { "Buffer", "Mixer" };
86 86
87static const struct soc_enum wm8974_auxmode = 87static SOC_ENUM_SINGLE_DECL(wm8974_auxmode,
88 SOC_ENUM_SINGLE(WM8974_INPUT, 3, 2, wm8974_auxmode_text); 88 WM8974_INPUT, 3, wm8974_auxmode_text);
89 89
90static const DECLARE_TLV_DB_SCALE(digital_tlv, -12750, 50, 1); 90static const DECLARE_TLV_DB_SCALE(digital_tlv, -12750, 50, 1);
91static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); 91static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
@@ -593,12 +593,6 @@ static int wm8974_probe(struct snd_soc_codec *codec)
593{ 593{
594 int ret = 0; 594 int ret = 0;
595 595
596 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
597 if (ret < 0) {
598 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
599 return ret;
600 }
601
602 ret = wm8974_reset(codec); 596 ret = wm8974_reset(codec);
603 if (ret < 0) { 597 if (ret < 0) {
604 dev_err(codec->dev, "Failed to issue reset\n"); 598 dev_err(codec->dev, "Failed to issue reset\n");
diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c
index d8fc531c0e59..28ef46c91f62 100644
--- a/sound/soc/codecs/wm8978.c
+++ b/sound/soc/codecs/wm8978.c
@@ -117,21 +117,21 @@ static const char *wm8978_eq5[] = {"5.3kHz", "6.9kHz", "9kHz", "11.7kHz"};
117static const char *wm8978_alc3[] = {"ALC", "Limiter"}; 117static const char *wm8978_alc3[] = {"ALC", "Limiter"};
118static const char *wm8978_alc1[] = {"Off", "Right", "Left", "Both"}; 118static const char *wm8978_alc1[] = {"Off", "Right", "Left", "Both"};
119 119
120static const SOC_ENUM_SINGLE_DECL(adc_compand, WM8978_COMPANDING_CONTROL, 1, 120static SOC_ENUM_SINGLE_DECL(adc_compand, WM8978_COMPANDING_CONTROL, 1,
121 wm8978_companding); 121 wm8978_companding);
122static const SOC_ENUM_SINGLE_DECL(dac_compand, WM8978_COMPANDING_CONTROL, 3, 122static SOC_ENUM_SINGLE_DECL(dac_compand, WM8978_COMPANDING_CONTROL, 3,
123 wm8978_companding); 123 wm8978_companding);
124static const SOC_ENUM_SINGLE_DECL(eqmode, WM8978_EQ1, 8, wm8978_eqmode); 124static SOC_ENUM_SINGLE_DECL(eqmode, WM8978_EQ1, 8, wm8978_eqmode);
125static const SOC_ENUM_SINGLE_DECL(eq1, WM8978_EQ1, 5, wm8978_eq1); 125static SOC_ENUM_SINGLE_DECL(eq1, WM8978_EQ1, 5, wm8978_eq1);
126static const SOC_ENUM_SINGLE_DECL(eq2bw, WM8978_EQ2, 8, wm8978_bw); 126static SOC_ENUM_SINGLE_DECL(eq2bw, WM8978_EQ2, 8, wm8978_bw);
127static const SOC_ENUM_SINGLE_DECL(eq2, WM8978_EQ2, 5, wm8978_eq2); 127static SOC_ENUM_SINGLE_DECL(eq2, WM8978_EQ2, 5, wm8978_eq2);
128static const SOC_ENUM_SINGLE_DECL(eq3bw, WM8978_EQ3, 8, wm8978_bw); 128static SOC_ENUM_SINGLE_DECL(eq3bw, WM8978_EQ3, 8, wm8978_bw);
129static const SOC_ENUM_SINGLE_DECL(eq3, WM8978_EQ3, 5, wm8978_eq3); 129static SOC_ENUM_SINGLE_DECL(eq3, WM8978_EQ3, 5, wm8978_eq3);
130static const SOC_ENUM_SINGLE_DECL(eq4bw, WM8978_EQ4, 8, wm8978_bw); 130static SOC_ENUM_SINGLE_DECL(eq4bw, WM8978_EQ4, 8, wm8978_bw);
131static const SOC_ENUM_SINGLE_DECL(eq4, WM8978_EQ4, 5, wm8978_eq4); 131static SOC_ENUM_SINGLE_DECL(eq4, WM8978_EQ4, 5, wm8978_eq4);
132static const SOC_ENUM_SINGLE_DECL(eq5, WM8978_EQ5, 5, wm8978_eq5); 132static SOC_ENUM_SINGLE_DECL(eq5, WM8978_EQ5, 5, wm8978_eq5);
133static const SOC_ENUM_SINGLE_DECL(alc3, WM8978_ALC_CONTROL_3, 8, wm8978_alc3); 133static SOC_ENUM_SINGLE_DECL(alc3, WM8978_ALC_CONTROL_3, 8, wm8978_alc3);
134static const SOC_ENUM_SINGLE_DECL(alc1, WM8978_ALC_CONTROL_1, 7, wm8978_alc1); 134static SOC_ENUM_SINGLE_DECL(alc1, WM8978_ALC_CONTROL_1, 7, wm8978_alc1);
135 135
136static const DECLARE_TLV_DB_SCALE(digital_tlv, -12750, 50, 1); 136static const DECLARE_TLV_DB_SCALE(digital_tlv, -12750, 50, 1);
137static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); 137static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
@@ -975,19 +975,13 @@ static const int update_reg[] = {
975static int wm8978_probe(struct snd_soc_codec *codec) 975static int wm8978_probe(struct snd_soc_codec *codec)
976{ 976{
977 struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec); 977 struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec);
978 int ret = 0, i; 978 int i;
979 979
980 /* 980 /*
981 * Set default system clock to PLL, it is more precise, this is also the 981 * Set default system clock to PLL, it is more precise, this is also the
982 * default hardware setting 982 * default hardware setting
983 */ 983 */
984 wm8978->sysclk = WM8978_PLL; 984 wm8978->sysclk = WM8978_PLL;
985 codec->control_data = wm8978->regmap;
986 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
987 if (ret < 0) {
988 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
989 return ret;
990 }
991 985
992 /* 986 /*
993 * Set the update bit in all registers, that have one. This way all 987 * Set the update bit in all registers, that have one. This way all
diff --git a/sound/soc/codecs/wm8983.c b/sound/soc/codecs/wm8983.c
index aa41ba0dfff4..2b9bfa53efbf 100644
--- a/sound/soc/codecs/wm8983.c
+++ b/sound/soc/codecs/wm8983.c
@@ -205,49 +205,44 @@ static const DECLARE_TLV_DB_SCALE(bypass_tlv, -1500, 300, 0);
205static const DECLARE_TLV_DB_SCALE(pga_boost_tlv, 0, 2000, 0); 205static const DECLARE_TLV_DB_SCALE(pga_boost_tlv, 0, 2000, 0);
206 206
207static const char *alc_sel_text[] = { "Off", "Right", "Left", "Stereo" }; 207static const char *alc_sel_text[] = { "Off", "Right", "Left", "Stereo" };
208static const SOC_ENUM_SINGLE_DECL(alc_sel, WM8983_ALC_CONTROL_1, 7, 208static SOC_ENUM_SINGLE_DECL(alc_sel, WM8983_ALC_CONTROL_1, 7, alc_sel_text);
209 alc_sel_text);
210 209
211static const char *alc_mode_text[] = { "ALC", "Limiter" }; 210static const char *alc_mode_text[] = { "ALC", "Limiter" };
212static const SOC_ENUM_SINGLE_DECL(alc_mode, WM8983_ALC_CONTROL_3, 8, 211static SOC_ENUM_SINGLE_DECL(alc_mode, WM8983_ALC_CONTROL_3, 8, alc_mode_text);
213 alc_mode_text);
214 212
215static const char *filter_mode_text[] = { "Audio", "Application" }; 213static const char *filter_mode_text[] = { "Audio", "Application" };
216static const SOC_ENUM_SINGLE_DECL(filter_mode, WM8983_ADC_CONTROL, 7, 214static SOC_ENUM_SINGLE_DECL(filter_mode, WM8983_ADC_CONTROL, 7,
217 filter_mode_text); 215 filter_mode_text);
218 216
219static const char *eq_bw_text[] = { "Narrow", "Wide" }; 217static const char *eq_bw_text[] = { "Narrow", "Wide" };
220static const char *eqmode_text[] = { "Capture", "Playback" }; 218static const char *eqmode_text[] = { "Capture", "Playback" };
221static const SOC_ENUM_SINGLE_EXT_DECL(eqmode, eqmode_text); 219static SOC_ENUM_SINGLE_EXT_DECL(eqmode, eqmode_text);
222 220
223static const char *eq1_cutoff_text[] = { 221static const char *eq1_cutoff_text[] = {
224 "80Hz", "105Hz", "135Hz", "175Hz" 222 "80Hz", "105Hz", "135Hz", "175Hz"
225}; 223};
226static const SOC_ENUM_SINGLE_DECL(eq1_cutoff, WM8983_EQ1_LOW_SHELF, 5, 224static SOC_ENUM_SINGLE_DECL(eq1_cutoff, WM8983_EQ1_LOW_SHELF, 5,
227 eq1_cutoff_text); 225 eq1_cutoff_text);
228static const char *eq2_cutoff_text[] = { 226static const char *eq2_cutoff_text[] = {
229 "230Hz", "300Hz", "385Hz", "500Hz" 227 "230Hz", "300Hz", "385Hz", "500Hz"
230}; 228};
231static const SOC_ENUM_SINGLE_DECL(eq2_bw, WM8983_EQ2_PEAK_1, 8, eq_bw_text); 229static SOC_ENUM_SINGLE_DECL(eq2_bw, WM8983_EQ2_PEAK_1, 8, eq_bw_text);
232static const SOC_ENUM_SINGLE_DECL(eq2_cutoff, WM8983_EQ2_PEAK_1, 5, 230static SOC_ENUM_SINGLE_DECL(eq2_cutoff, WM8983_EQ2_PEAK_1, 5, eq2_cutoff_text);
233 eq2_cutoff_text);
234static const char *eq3_cutoff_text[] = { 231static const char *eq3_cutoff_text[] = {
235 "650Hz", "850Hz", "1.1kHz", "1.4kHz" 232 "650Hz", "850Hz", "1.1kHz", "1.4kHz"
236}; 233};
237static const SOC_ENUM_SINGLE_DECL(eq3_bw, WM8983_EQ3_PEAK_2, 8, eq_bw_text); 234static SOC_ENUM_SINGLE_DECL(eq3_bw, WM8983_EQ3_PEAK_2, 8, eq_bw_text);
238static const SOC_ENUM_SINGLE_DECL(eq3_cutoff, WM8983_EQ3_PEAK_2, 5, 235static SOC_ENUM_SINGLE_DECL(eq3_cutoff, WM8983_EQ3_PEAK_2, 5, eq3_cutoff_text);
239 eq3_cutoff_text);
240static const char *eq4_cutoff_text[] = { 236static const char *eq4_cutoff_text[] = {
241 "1.8kHz", "2.4kHz", "3.2kHz", "4.1kHz" 237 "1.8kHz", "2.4kHz", "3.2kHz", "4.1kHz"
242}; 238};
243static const SOC_ENUM_SINGLE_DECL(eq4_bw, WM8983_EQ4_PEAK_3, 8, eq_bw_text); 239static SOC_ENUM_SINGLE_DECL(eq4_bw, WM8983_EQ4_PEAK_3, 8, eq_bw_text);
244static const SOC_ENUM_SINGLE_DECL(eq4_cutoff, WM8983_EQ4_PEAK_3, 5, 240static SOC_ENUM_SINGLE_DECL(eq4_cutoff, WM8983_EQ4_PEAK_3, 5, eq4_cutoff_text);
245 eq4_cutoff_text);
246static const char *eq5_cutoff_text[] = { 241static const char *eq5_cutoff_text[] = {
247 "5.3kHz", "6.9kHz", "9kHz", "11.7kHz" 242 "5.3kHz", "6.9kHz", "9kHz", "11.7kHz"
248}; 243};
249static const SOC_ENUM_SINGLE_DECL(eq5_cutoff, WM8983_EQ5_HIGH_SHELF, 5, 244static SOC_ENUM_SINGLE_DECL(eq5_cutoff, WM8983_EQ5_HIGH_SHELF, 5,
250 eq5_cutoff_text); 245 eq5_cutoff_text);
251 246
252static const char *depth_3d_text[] = { 247static const char *depth_3d_text[] = {
253 "Off", 248 "Off",
@@ -267,8 +262,8 @@ static const char *depth_3d_text[] = {
267 "93.3%", 262 "93.3%",
268 "100%" 263 "100%"
269}; 264};
270static const SOC_ENUM_SINGLE_DECL(depth_3d, WM8983_3D_CONTROL, 0, 265static SOC_ENUM_SINGLE_DECL(depth_3d, WM8983_3D_CONTROL, 0,
271 depth_3d_text); 266 depth_3d_text);
272 267
273static const struct snd_kcontrol_new wm8983_snd_controls[] = { 268static const struct snd_kcontrol_new wm8983_snd_controls[] = {
274 SOC_SINGLE("Digital Loopback Switch", WM8983_COMPANDING_CONTROL, 269 SOC_SINGLE("Digital Loopback Switch", WM8983_COMPANDING_CONTROL,
@@ -1000,12 +995,6 @@ static int wm8983_probe(struct snd_soc_codec *codec)
1000 int ret; 995 int ret;
1001 int i; 996 int i;
1002 997
1003 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
1004 if (ret < 0) {
1005 dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret);
1006 return ret;
1007 }
1008
1009 ret = snd_soc_write(codec, WM8983_SOFTWARE_RESET, 0); 998 ret = snd_soc_write(codec, WM8983_SOFTWARE_RESET, 0);
1010 if (ret < 0) { 999 if (ret < 0) {
1011 dev_err(codec->dev, "Failed to issue reset: %d\n", ret); 1000 dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
@@ -1129,7 +1118,7 @@ static struct spi_driver wm8983_spi_driver = {
1129}; 1118};
1130#endif 1119#endif
1131 1120
1132#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1121#if IS_ENABLED(CONFIG_I2C)
1133static int wm8983_i2c_probe(struct i2c_client *i2c, 1122static int wm8983_i2c_probe(struct i2c_client *i2c,
1134 const struct i2c_device_id *id) 1123 const struct i2c_device_id *id)
1135{ 1124{
@@ -1182,7 +1171,7 @@ static int __init wm8983_modinit(void)
1182{ 1171{
1183 int ret = 0; 1172 int ret = 0;
1184 1173
1185#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1174#if IS_ENABLED(CONFIG_I2C)
1186 ret = i2c_add_driver(&wm8983_i2c_driver); 1175 ret = i2c_add_driver(&wm8983_i2c_driver);
1187 if (ret) { 1176 if (ret) {
1188 printk(KERN_ERR "Failed to register wm8983 I2C driver: %d\n", 1177 printk(KERN_ERR "Failed to register wm8983 I2C driver: %d\n",
@@ -1202,7 +1191,7 @@ module_init(wm8983_modinit);
1202 1191
1203static void __exit wm8983_exit(void) 1192static void __exit wm8983_exit(void)
1204{ 1193{
1205#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1194#if IS_ENABLED(CONFIG_I2C)
1206 i2c_del_driver(&wm8983_i2c_driver); 1195 i2c_del_driver(&wm8983_i2c_driver);
1207#endif 1196#endif
1208#if defined(CONFIG_SPI_MASTER) 1197#if defined(CONFIG_SPI_MASTER)
diff --git a/sound/soc/codecs/wm8985.c b/sound/soc/codecs/wm8985.c
index 271b517911a4..5473dc969585 100644
--- a/sound/soc/codecs/wm8985.c
+++ b/sound/soc/codecs/wm8985.c
@@ -226,52 +226,48 @@ static const DECLARE_TLV_DB_SCALE(bypass_tlv, -1500, 300, 0);
226static const DECLARE_TLV_DB_SCALE(pga_boost_tlv, 0, 2000, 0); 226static const DECLARE_TLV_DB_SCALE(pga_boost_tlv, 0, 2000, 0);
227 227
228static const char *alc_sel_text[] = { "Off", "Right", "Left", "Stereo" }; 228static const char *alc_sel_text[] = { "Off", "Right", "Left", "Stereo" };
229static const SOC_ENUM_SINGLE_DECL(alc_sel, WM8985_ALC_CONTROL_1, 7, 229static SOC_ENUM_SINGLE_DECL(alc_sel, WM8985_ALC_CONTROL_1, 7, alc_sel_text);
230 alc_sel_text);
231 230
232static const char *alc_mode_text[] = { "ALC", "Limiter" }; 231static const char *alc_mode_text[] = { "ALC", "Limiter" };
233static const SOC_ENUM_SINGLE_DECL(alc_mode, WM8985_ALC_CONTROL_3, 8, 232static SOC_ENUM_SINGLE_DECL(alc_mode, WM8985_ALC_CONTROL_3, 8, alc_mode_text);
234 alc_mode_text);
235 233
236static const char *filter_mode_text[] = { "Audio", "Application" }; 234static const char *filter_mode_text[] = { "Audio", "Application" };
237static const SOC_ENUM_SINGLE_DECL(filter_mode, WM8985_ADC_CONTROL, 7, 235static SOC_ENUM_SINGLE_DECL(filter_mode, WM8985_ADC_CONTROL, 7,
238 filter_mode_text); 236 filter_mode_text);
239 237
240static const char *eq_bw_text[] = { "Narrow", "Wide" }; 238static const char *eq_bw_text[] = { "Narrow", "Wide" };
241static const char *eqmode_text[] = { "Capture", "Playback" }; 239static const char *eqmode_text[] = { "Capture", "Playback" };
242static const SOC_ENUM_SINGLE_EXT_DECL(eqmode, eqmode_text); 240static SOC_ENUM_SINGLE_EXT_DECL(eqmode, eqmode_text);
243 241
244static const char *eq1_cutoff_text[] = { 242static const char *eq1_cutoff_text[] = {
245 "80Hz", "105Hz", "135Hz", "175Hz" 243 "80Hz", "105Hz", "135Hz", "175Hz"
246}; 244};
247static const SOC_ENUM_SINGLE_DECL(eq1_cutoff, WM8985_EQ1_LOW_SHELF, 5, 245static SOC_ENUM_SINGLE_DECL(eq1_cutoff, WM8985_EQ1_LOW_SHELF, 5,
248 eq1_cutoff_text); 246 eq1_cutoff_text);
249static const char *eq2_cutoff_text[] = { 247static const char *eq2_cutoff_text[] = {
250 "230Hz", "300Hz", "385Hz", "500Hz" 248 "230Hz", "300Hz", "385Hz", "500Hz"
251}; 249};
252static const SOC_ENUM_SINGLE_DECL(eq2_bw, WM8985_EQ2_PEAK_1, 8, eq_bw_text); 250static SOC_ENUM_SINGLE_DECL(eq2_bw, WM8985_EQ2_PEAK_1, 8, eq_bw_text);
253static const SOC_ENUM_SINGLE_DECL(eq2_cutoff, WM8985_EQ2_PEAK_1, 5, 251static SOC_ENUM_SINGLE_DECL(eq2_cutoff, WM8985_EQ2_PEAK_1, 5, eq2_cutoff_text);
254 eq2_cutoff_text);
255static const char *eq3_cutoff_text[] = { 252static const char *eq3_cutoff_text[] = {
256 "650Hz", "850Hz", "1.1kHz", "1.4kHz" 253 "650Hz", "850Hz", "1.1kHz", "1.4kHz"
257}; 254};
258static const SOC_ENUM_SINGLE_DECL(eq3_bw, WM8985_EQ3_PEAK_2, 8, eq_bw_text); 255static SOC_ENUM_SINGLE_DECL(eq3_bw, WM8985_EQ3_PEAK_2, 8, eq_bw_text);
259static const SOC_ENUM_SINGLE_DECL(eq3_cutoff, WM8985_EQ3_PEAK_2, 5, 256static SOC_ENUM_SINGLE_DECL(eq3_cutoff, WM8985_EQ3_PEAK_2, 5,
260 eq3_cutoff_text); 257 eq3_cutoff_text);
261static const char *eq4_cutoff_text[] = { 258static const char *eq4_cutoff_text[] = {
262 "1.8kHz", "2.4kHz", "3.2kHz", "4.1kHz" 259 "1.8kHz", "2.4kHz", "3.2kHz", "4.1kHz"
263}; 260};
264static const SOC_ENUM_SINGLE_DECL(eq4_bw, WM8985_EQ4_PEAK_3, 8, eq_bw_text); 261static SOC_ENUM_SINGLE_DECL(eq4_bw, WM8985_EQ4_PEAK_3, 8, eq_bw_text);
265static const SOC_ENUM_SINGLE_DECL(eq4_cutoff, WM8985_EQ4_PEAK_3, 5, 262static SOC_ENUM_SINGLE_DECL(eq4_cutoff, WM8985_EQ4_PEAK_3, 5, eq4_cutoff_text);
266 eq4_cutoff_text);
267static const char *eq5_cutoff_text[] = { 263static const char *eq5_cutoff_text[] = {
268 "5.3kHz", "6.9kHz", "9kHz", "11.7kHz" 264 "5.3kHz", "6.9kHz", "9kHz", "11.7kHz"
269}; 265};
270static const SOC_ENUM_SINGLE_DECL(eq5_cutoff, WM8985_EQ5_HIGH_SHELF, 5, 266static SOC_ENUM_SINGLE_DECL(eq5_cutoff, WM8985_EQ5_HIGH_SHELF, 5,
271 eq5_cutoff_text); 267 eq5_cutoff_text);
272 268
273static const char *speaker_mode_text[] = { "Class A/B", "Class D" }; 269static const char *speaker_mode_text[] = { "Class A/B", "Class D" };
274static const SOC_ENUM_SINGLE_DECL(speaker_mode, 0x17, 8, speaker_mode_text); 270static SOC_ENUM_SINGLE_DECL(speaker_mode, 0x17, 8, speaker_mode_text);
275 271
276static const char *depth_3d_text[] = { 272static const char *depth_3d_text[] = {
277 "Off", 273 "Off",
@@ -291,8 +287,7 @@ static const char *depth_3d_text[] = {
291 "93.3%", 287 "93.3%",
292 "100%" 288 "100%"
293}; 289};
294static const SOC_ENUM_SINGLE_DECL(depth_3d, WM8985_3D_CONTROL, 0, 290static SOC_ENUM_SINGLE_DECL(depth_3d, WM8985_3D_CONTROL, 0, depth_3d_text);
295 depth_3d_text);
296 291
297static const struct snd_kcontrol_new wm8985_snd_controls[] = { 292static const struct snd_kcontrol_new wm8985_snd_controls[] = {
298 SOC_SINGLE("Digital Loopback Switch", WM8985_COMPANDING_CONTROL, 293 SOC_SINGLE("Digital Loopback Switch", WM8985_COMPANDING_CONTROL,
@@ -1000,13 +995,6 @@ static int wm8985_probe(struct snd_soc_codec *codec)
1000 int ret; 995 int ret;
1001 996
1002 wm8985 = snd_soc_codec_get_drvdata(codec); 997 wm8985 = snd_soc_codec_get_drvdata(codec);
1003 codec->control_data = wm8985->regmap;
1004
1005 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
1006 if (ret < 0) {
1007 dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret);
1008 return ret;
1009 }
1010 998
1011 for (i = 0; i < ARRAY_SIZE(wm8985->supplies); i++) 999 for (i = 0; i < ARRAY_SIZE(wm8985->supplies); i++)
1012 wm8985->supplies[i].supply = wm8985_supply_names[i]; 1000 wm8985->supplies[i].supply = wm8985_supply_names[i];
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c
index a55e1c2c382e..3a1ae4f5164d 100644
--- a/sound/soc/codecs/wm8988.c
+++ b/sound/soc/codecs/wm8988.c
@@ -116,7 +116,7 @@ static bool wm8988_writeable(struct device *dev, unsigned int reg)
116struct wm8988_priv { 116struct wm8988_priv {
117 struct regmap *regmap; 117 struct regmap *regmap;
118 unsigned int sysclk; 118 unsigned int sysclk;
119 struct snd_pcm_hw_constraint_list *sysclk_constraints; 119 const struct snd_pcm_hw_constraint_list *sysclk_constraints;
120}; 120};
121 121
122#define wm8988_reset(c) snd_soc_write(c, WM8988_RESET, 0) 122#define wm8988_reset(c) snd_soc_write(c, WM8988_RESET, 0)
@@ -126,46 +126,46 @@ struct wm8988_priv {
126 */ 126 */
127 127
128static const char *bass_boost_txt[] = {"Linear Control", "Adaptive Boost"}; 128static const char *bass_boost_txt[] = {"Linear Control", "Adaptive Boost"};
129static const struct soc_enum bass_boost = 129static SOC_ENUM_SINGLE_DECL(bass_boost,
130 SOC_ENUM_SINGLE(WM8988_BASS, 7, 2, bass_boost_txt); 130 WM8988_BASS, 7, bass_boost_txt);
131 131
132static const char *bass_filter_txt[] = { "130Hz @ 48kHz", "200Hz @ 48kHz" }; 132static const char *bass_filter_txt[] = { "130Hz @ 48kHz", "200Hz @ 48kHz" };
133static const struct soc_enum bass_filter = 133static SOC_ENUM_SINGLE_DECL(bass_filter,
134 SOC_ENUM_SINGLE(WM8988_BASS, 6, 2, bass_filter_txt); 134 WM8988_BASS, 6, bass_filter_txt);
135 135
136static const char *treble_txt[] = {"8kHz", "4kHz"}; 136static const char *treble_txt[] = {"8kHz", "4kHz"};
137static const struct soc_enum treble = 137static SOC_ENUM_SINGLE_DECL(treble,
138 SOC_ENUM_SINGLE(WM8988_TREBLE, 6, 2, treble_txt); 138 WM8988_TREBLE, 6, treble_txt);
139 139
140static const char *stereo_3d_lc_txt[] = {"200Hz", "500Hz"}; 140static const char *stereo_3d_lc_txt[] = {"200Hz", "500Hz"};
141static const struct soc_enum stereo_3d_lc = 141static SOC_ENUM_SINGLE_DECL(stereo_3d_lc,
142 SOC_ENUM_SINGLE(WM8988_3D, 5, 2, stereo_3d_lc_txt); 142 WM8988_3D, 5, stereo_3d_lc_txt);
143 143
144static const char *stereo_3d_uc_txt[] = {"2.2kHz", "1.5kHz"}; 144static const char *stereo_3d_uc_txt[] = {"2.2kHz", "1.5kHz"};
145static const struct soc_enum stereo_3d_uc = 145static SOC_ENUM_SINGLE_DECL(stereo_3d_uc,
146 SOC_ENUM_SINGLE(WM8988_3D, 6, 2, stereo_3d_uc_txt); 146 WM8988_3D, 6, stereo_3d_uc_txt);
147 147
148static const char *stereo_3d_func_txt[] = {"Capture", "Playback"}; 148static const char *stereo_3d_func_txt[] = {"Capture", "Playback"};
149static const struct soc_enum stereo_3d_func = 149static SOC_ENUM_SINGLE_DECL(stereo_3d_func,
150 SOC_ENUM_SINGLE(WM8988_3D, 7, 2, stereo_3d_func_txt); 150 WM8988_3D, 7, stereo_3d_func_txt);
151 151
152static const char *alc_func_txt[] = {"Off", "Right", "Left", "Stereo"}; 152static const char *alc_func_txt[] = {"Off", "Right", "Left", "Stereo"};
153static const struct soc_enum alc_func = 153static SOC_ENUM_SINGLE_DECL(alc_func,
154 SOC_ENUM_SINGLE(WM8988_ALC1, 7, 4, alc_func_txt); 154 WM8988_ALC1, 7, alc_func_txt);
155 155
156static const char *ng_type_txt[] = {"Constant PGA Gain", 156static const char *ng_type_txt[] = {"Constant PGA Gain",
157 "Mute ADC Output"}; 157 "Mute ADC Output"};
158static const struct soc_enum ng_type = 158static SOC_ENUM_SINGLE_DECL(ng_type,
159 SOC_ENUM_SINGLE(WM8988_NGATE, 1, 2, ng_type_txt); 159 WM8988_NGATE, 1, ng_type_txt);
160 160
161static const char *deemph_txt[] = {"None", "32Khz", "44.1Khz", "48Khz"}; 161static const char *deemph_txt[] = {"None", "32Khz", "44.1Khz", "48Khz"};
162static const struct soc_enum deemph = 162static SOC_ENUM_SINGLE_DECL(deemph,
163 SOC_ENUM_SINGLE(WM8988_ADCDAC, 1, 4, deemph_txt); 163 WM8988_ADCDAC, 1, deemph_txt);
164 164
165static const char *adcpol_txt[] = {"Normal", "L Invert", "R Invert", 165static const char *adcpol_txt[] = {"Normal", "L Invert", "R Invert",
166 "L + R Invert"}; 166 "L + R Invert"};
167static const struct soc_enum adcpol = 167static SOC_ENUM_SINGLE_DECL(adcpol,
168 SOC_ENUM_SINGLE(WM8988_ADCDAC, 5, 4, adcpol_txt); 168 WM8988_ADCDAC, 5, adcpol_txt);
169 169
170static const DECLARE_TLV_DB_SCALE(pga_tlv, -1725, 75, 0); 170static const DECLARE_TLV_DB_SCALE(pga_tlv, -1725, 75, 0);
171static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1); 171static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1);
@@ -317,16 +317,16 @@ static const struct snd_kcontrol_new wm8988_right_pga_controls =
317 317
318/* Differential Mux */ 318/* Differential Mux */
319static const char *wm8988_diff_sel[] = {"Line 1", "Line 2"}; 319static const char *wm8988_diff_sel[] = {"Line 1", "Line 2"};
320static const struct soc_enum diffmux = 320static SOC_ENUM_SINGLE_DECL(diffmux,
321 SOC_ENUM_SINGLE(WM8988_ADCIN, 8, 2, wm8988_diff_sel); 321 WM8988_ADCIN, 8, wm8988_diff_sel);
322static const struct snd_kcontrol_new wm8988_diffmux_controls = 322static const struct snd_kcontrol_new wm8988_diffmux_controls =
323 SOC_DAPM_ENUM("Route", diffmux); 323 SOC_DAPM_ENUM("Route", diffmux);
324 324
325/* Mono ADC Mux */ 325/* Mono ADC Mux */
326static const char *wm8988_mono_mux[] = {"Stereo", "Mono (Left)", 326static const char *wm8988_mono_mux[] = {"Stereo", "Mono (Left)",
327 "Mono (Right)", "Digital Mono"}; 327 "Mono (Right)", "Digital Mono"};
328static const struct soc_enum monomux = 328static SOC_ENUM_SINGLE_DECL(monomux,
329 SOC_ENUM_SINGLE(WM8988_ADCIN, 6, 4, wm8988_mono_mux); 329 WM8988_ADCIN, 6, wm8988_mono_mux);
330static const struct snd_kcontrol_new wm8988_monomux_controls = 330static const struct snd_kcontrol_new wm8988_monomux_controls =
331 SOC_DAPM_ENUM("Route", monomux); 331 SOC_DAPM_ENUM("Route", monomux);
332 332
@@ -521,30 +521,30 @@ static inline int get_coeff(int mclk, int rate)
521 521
522/* The set of rates we can generate from the above for each SYSCLK */ 522/* The set of rates we can generate from the above for each SYSCLK */
523 523
524static unsigned int rates_12288[] = { 524static const unsigned int rates_12288[] = {
525 8000, 12000, 16000, 24000, 24000, 32000, 48000, 96000, 525 8000, 12000, 16000, 24000, 24000, 32000, 48000, 96000,
526}; 526};
527 527
528static struct snd_pcm_hw_constraint_list constraints_12288 = { 528static const struct snd_pcm_hw_constraint_list constraints_12288 = {
529 .count = ARRAY_SIZE(rates_12288), 529 .count = ARRAY_SIZE(rates_12288),
530 .list = rates_12288, 530 .list = rates_12288,
531}; 531};
532 532
533static unsigned int rates_112896[] = { 533static const unsigned int rates_112896[] = {
534 8000, 11025, 22050, 44100, 534 8000, 11025, 22050, 44100,
535}; 535};
536 536
537static struct snd_pcm_hw_constraint_list constraints_112896 = { 537static const struct snd_pcm_hw_constraint_list constraints_112896 = {
538 .count = ARRAY_SIZE(rates_112896), 538 .count = ARRAY_SIZE(rates_112896),
539 .list = rates_112896, 539 .list = rates_112896,
540}; 540};
541 541
542static unsigned int rates_12[] = { 542static const unsigned int rates_12[] = {
543 8000, 11025, 12000, 16000, 22050, 2400, 32000, 41100, 48000, 543 8000, 11025, 12000, 16000, 22050, 2400, 32000, 41100, 48000,
544 48000, 88235, 96000, 544 48000, 88235, 96000,
545}; 545};
546 546
547static struct snd_pcm_hw_constraint_list constraints_12 = { 547static const struct snd_pcm_hw_constraint_list constraints_12 = {
548 .count = ARRAY_SIZE(rates_12), 548 .count = ARRAY_SIZE(rates_12),
549 .list = rates_12, 549 .list = rates_12,
550}; 550};
@@ -810,16 +810,8 @@ static int wm8988_resume(struct snd_soc_codec *codec)
810 810
811static int wm8988_probe(struct snd_soc_codec *codec) 811static int wm8988_probe(struct snd_soc_codec *codec)
812{ 812{
813 struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
814 int ret = 0; 813 int ret = 0;
815 814
816 codec->control_data = wm8988->regmap;
817 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
818 if (ret < 0) {
819 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
820 return ret;
821 }
822
823 ret = wm8988_reset(codec); 815 ret = wm8988_reset(codec);
824 if (ret < 0) { 816 if (ret < 0) {
825 dev_err(codec->dev, "Failed to issue reset\n"); 817 dev_err(codec->dev, "Failed to issue reset\n");
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index 0ccd4d8d043b..c413c1991453 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -157,26 +157,23 @@ static int wm899x_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol,
157static const char *wm8990_digital_sidetone[] = 157static const char *wm8990_digital_sidetone[] =
158 {"None", "Left ADC", "Right ADC", "Reserved"}; 158 {"None", "Left ADC", "Right ADC", "Reserved"};
159 159
160static const struct soc_enum wm8990_left_digital_sidetone_enum = 160static SOC_ENUM_SINGLE_DECL(wm8990_left_digital_sidetone_enum,
161SOC_ENUM_SINGLE(WM8990_DIGITAL_SIDE_TONE, 161 WM8990_DIGITAL_SIDE_TONE,
162 WM8990_ADC_TO_DACL_SHIFT, 162 WM8990_ADC_TO_DACL_SHIFT,
163 WM8990_ADC_TO_DACL_MASK, 163 wm8990_digital_sidetone);
164 wm8990_digital_sidetone); 164
165 165static SOC_ENUM_SINGLE_DECL(wm8990_right_digital_sidetone_enum,
166static const struct soc_enum wm8990_right_digital_sidetone_enum = 166 WM8990_DIGITAL_SIDE_TONE,
167SOC_ENUM_SINGLE(WM8990_DIGITAL_SIDE_TONE, 167 WM8990_ADC_TO_DACR_SHIFT,
168 WM8990_ADC_TO_DACR_SHIFT, 168 wm8990_digital_sidetone);
169 WM8990_ADC_TO_DACR_MASK,
170 wm8990_digital_sidetone);
171 169
172static const char *wm8990_adcmode[] = 170static const char *wm8990_adcmode[] =
173 {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"}; 171 {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"};
174 172
175static const struct soc_enum wm8990_right_adcmode_enum = 173static SOC_ENUM_SINGLE_DECL(wm8990_right_adcmode_enum,
176SOC_ENUM_SINGLE(WM8990_ADC_CTRL, 174 WM8990_ADC_CTRL,
177 WM8990_ADC_HPF_CUT_SHIFT, 175 WM8990_ADC_HPF_CUT_SHIFT,
178 WM8990_ADC_HPF_CUT_MASK, 176 wm8990_adcmode);
179 wm8990_adcmode);
180 177
181static const struct snd_kcontrol_new wm8990_snd_controls[] = { 178static const struct snd_kcontrol_new wm8990_snd_controls[] = {
182/* INMIXL */ 179/* INMIXL */
@@ -475,9 +472,9 @@ SOC_DAPM_SINGLE("RINPGA34 Switch", WM8990_INPUT_MIXER3, WM8990_L34MNB_BIT,
475static const char *wm8990_ainlmux[] = 472static const char *wm8990_ainlmux[] =
476 {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"}; 473 {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"};
477 474
478static const struct soc_enum wm8990_ainlmux_enum = 475static SOC_ENUM_SINGLE_DECL(wm8990_ainlmux_enum,
479SOC_ENUM_SINGLE(WM8990_INPUT_MIXER1, WM8990_AINLMODE_SHIFT, 476 WM8990_INPUT_MIXER1, WM8990_AINLMODE_SHIFT,
480 ARRAY_SIZE(wm8990_ainlmux), wm8990_ainlmux); 477 wm8990_ainlmux);
481 478
482static const struct snd_kcontrol_new wm8990_dapm_ainlmux_controls = 479static const struct snd_kcontrol_new wm8990_dapm_ainlmux_controls =
483SOC_DAPM_ENUM("Route", wm8990_ainlmux_enum); 480SOC_DAPM_ENUM("Route", wm8990_ainlmux_enum);
@@ -488,9 +485,9 @@ SOC_DAPM_ENUM("Route", wm8990_ainlmux_enum);
488static const char *wm8990_ainrmux[] = 485static const char *wm8990_ainrmux[] =
489 {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"}; 486 {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"};
490 487
491static const struct soc_enum wm8990_ainrmux_enum = 488static SOC_ENUM_SINGLE_DECL(wm8990_ainrmux_enum,
492SOC_ENUM_SINGLE(WM8990_INPUT_MIXER1, WM8990_AINRMODE_SHIFT, 489 WM8990_INPUT_MIXER1, WM8990_AINRMODE_SHIFT,
493 ARRAY_SIZE(wm8990_ainrmux), wm8990_ainrmux); 490 wm8990_ainrmux);
494 491
495static const struct snd_kcontrol_new wm8990_dapm_ainrmux_controls = 492static const struct snd_kcontrol_new wm8990_dapm_ainrmux_controls =
496SOC_DAPM_ENUM("Route", wm8990_ainrmux_enum); 493SOC_DAPM_ENUM("Route", wm8990_ainrmux_enum);
@@ -1292,14 +1289,6 @@ static int wm8990_resume(struct snd_soc_codec *codec)
1292 */ 1289 */
1293static int wm8990_probe(struct snd_soc_codec *codec) 1290static int wm8990_probe(struct snd_soc_codec *codec)
1294{ 1291{
1295 int ret;
1296
1297 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1298 if (ret < 0) {
1299 printk(KERN_ERR "wm8990: failed to set cache I/O: %d\n", ret);
1300 return ret;
1301 }
1302
1303 wm8990_reset(codec); 1292 wm8990_reset(codec);
1304 1293
1305 /* charge output caps */ 1294 /* charge output caps */
diff --git a/sound/soc/codecs/wm8991.c b/sound/soc/codecs/wm8991.c
index dba0306c42a5..844cc4a60d66 100644
--- a/sound/soc/codecs/wm8991.c
+++ b/sound/soc/codecs/wm8991.c
@@ -171,26 +171,23 @@ static int wm899x_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol,
171static const char *wm8991_digital_sidetone[] = 171static const char *wm8991_digital_sidetone[] =
172{"None", "Left ADC", "Right ADC", "Reserved"}; 172{"None", "Left ADC", "Right ADC", "Reserved"};
173 173
174static const struct soc_enum wm8991_left_digital_sidetone_enum = 174static SOC_ENUM_SINGLE_DECL(wm8991_left_digital_sidetone_enum,
175 SOC_ENUM_SINGLE(WM8991_DIGITAL_SIDE_TONE, 175 WM8991_DIGITAL_SIDE_TONE,
176 WM8991_ADC_TO_DACL_SHIFT, 176 WM8991_ADC_TO_DACL_SHIFT,
177 WM8991_ADC_TO_DACL_MASK, 177 wm8991_digital_sidetone);
178 wm8991_digital_sidetone); 178
179 179static SOC_ENUM_SINGLE_DECL(wm8991_right_digital_sidetone_enum,
180static const struct soc_enum wm8991_right_digital_sidetone_enum = 180 WM8991_DIGITAL_SIDE_TONE,
181 SOC_ENUM_SINGLE(WM8991_DIGITAL_SIDE_TONE, 181 WM8991_ADC_TO_DACR_SHIFT,
182 WM8991_ADC_TO_DACR_SHIFT, 182 wm8991_digital_sidetone);
183 WM8991_ADC_TO_DACR_MASK,
184 wm8991_digital_sidetone);
185 183
186static const char *wm8991_adcmode[] = 184static const char *wm8991_adcmode[] =
187{"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"}; 185{"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"};
188 186
189static const struct soc_enum wm8991_right_adcmode_enum = 187static SOC_ENUM_SINGLE_DECL(wm8991_right_adcmode_enum,
190 SOC_ENUM_SINGLE(WM8991_ADC_CTRL, 188 WM8991_ADC_CTRL,
191 WM8991_ADC_HPF_CUT_SHIFT, 189 WM8991_ADC_HPF_CUT_SHIFT,
192 WM8991_ADC_HPF_CUT_MASK, 190 wm8991_adcmode);
193 wm8991_adcmode);
194 191
195static const struct snd_kcontrol_new wm8991_snd_controls[] = { 192static const struct snd_kcontrol_new wm8991_snd_controls[] = {
196 /* INMIXL */ 193 /* INMIXL */
@@ -486,9 +483,9 @@ static const struct snd_kcontrol_new wm8991_dapm_inmixr_controls[] = {
486static const char *wm8991_ainlmux[] = 483static const char *wm8991_ainlmux[] =
487{"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"}; 484{"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"};
488 485
489static const struct soc_enum wm8991_ainlmux_enum = 486static SOC_ENUM_SINGLE_DECL(wm8991_ainlmux_enum,
490 SOC_ENUM_SINGLE(WM8991_INPUT_MIXER1, WM8991_AINLMODE_SHIFT, 487 WM8991_INPUT_MIXER1, WM8991_AINLMODE_SHIFT,
491 ARRAY_SIZE(wm8991_ainlmux), wm8991_ainlmux); 488 wm8991_ainlmux);
492 489
493static const struct snd_kcontrol_new wm8991_dapm_ainlmux_controls = 490static const struct snd_kcontrol_new wm8991_dapm_ainlmux_controls =
494 SOC_DAPM_ENUM("Route", wm8991_ainlmux_enum); 491 SOC_DAPM_ENUM("Route", wm8991_ainlmux_enum);
@@ -499,9 +496,9 @@ static const struct snd_kcontrol_new wm8991_dapm_ainlmux_controls =
499static const char *wm8991_ainrmux[] = 496static const char *wm8991_ainrmux[] =
500{"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"}; 497{"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"};
501 498
502static const struct soc_enum wm8991_ainrmux_enum = 499static SOC_ENUM_SINGLE_DECL(wm8991_ainrmux_enum,
503 SOC_ENUM_SINGLE(WM8991_INPUT_MIXER1, WM8991_AINRMODE_SHIFT, 500 WM8991_INPUT_MIXER1, WM8991_AINRMODE_SHIFT,
504 ARRAY_SIZE(wm8991_ainrmux), wm8991_ainrmux); 501 wm8991_ainrmux);
505 502
506static const struct snd_kcontrol_new wm8991_dapm_ainrmux_controls = 503static const struct snd_kcontrol_new wm8991_dapm_ainrmux_controls =
507 SOC_DAPM_ENUM("Route", wm8991_ainrmux_enum); 504 SOC_DAPM_ENUM("Route", wm8991_ainrmux_enum);
@@ -1251,17 +1248,6 @@ static int wm8991_remove(struct snd_soc_codec *codec)
1251 1248
1252static int wm8991_probe(struct snd_soc_codec *codec) 1249static int wm8991_probe(struct snd_soc_codec *codec)
1253{ 1250{
1254 struct wm8991_priv *wm8991;
1255 int ret;
1256
1257 wm8991 = snd_soc_codec_get_drvdata(codec);
1258
1259 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1260 if (ret < 0) {
1261 dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret);
1262 return ret;
1263 }
1264
1265 wm8991_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1251 wm8991_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1266 1252
1267 return 0; 1253 return 0;
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index 2ee23a39622c..f825dc04ebe1 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -646,8 +646,8 @@ static const char *dac_deemph_text[] = {
646 "48kHz", 646 "48kHz",
647}; 647};
648 648
649static const struct soc_enum dac_deemph = 649static SOC_ENUM_SINGLE_DECL(dac_deemph,
650 SOC_ENUM_SINGLE(WM8993_DAC_CTRL, 4, 4, dac_deemph_text); 650 WM8993_DAC_CTRL, 4, dac_deemph_text);
651 651
652static const char *adc_hpf_text[] = { 652static const char *adc_hpf_text[] = {
653 "Hi-Fi", 653 "Hi-Fi",
@@ -656,16 +656,16 @@ static const char *adc_hpf_text[] = {
656 "Voice 3", 656 "Voice 3",
657}; 657};
658 658
659static const struct soc_enum adc_hpf = 659static SOC_ENUM_SINGLE_DECL(adc_hpf,
660 SOC_ENUM_SINGLE(WM8993_ADC_CTRL, 5, 4, adc_hpf_text); 660 WM8993_ADC_CTRL, 5, adc_hpf_text);
661 661
662static const char *drc_path_text[] = { 662static const char *drc_path_text[] = {
663 "ADC", 663 "ADC",
664 "DAC" 664 "DAC"
665}; 665};
666 666
667static const struct soc_enum drc_path = 667static SOC_ENUM_SINGLE_DECL(drc_path,
668 SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_1, 14, 2, drc_path_text); 668 WM8993_DRC_CONTROL_1, 14, drc_path_text);
669 669
670static const char *drc_r0_text[] = { 670static const char *drc_r0_text[] = {
671 "1", 671 "1",
@@ -676,8 +676,8 @@ static const char *drc_r0_text[] = {
676 "0", 676 "0",
677}; 677};
678 678
679static const struct soc_enum drc_r0 = 679static SOC_ENUM_SINGLE_DECL(drc_r0,
680 SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_3, 8, 6, drc_r0_text); 680 WM8993_DRC_CONTROL_3, 8, drc_r0_text);
681 681
682static const char *drc_r1_text[] = { 682static const char *drc_r1_text[] = {
683 "1", 683 "1",
@@ -687,8 +687,8 @@ static const char *drc_r1_text[] = {
687 "0", 687 "0",
688}; 688};
689 689
690static const struct soc_enum drc_r1 = 690static SOC_ENUM_SINGLE_DECL(drc_r1,
691 SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_4, 13, 5, drc_r1_text); 691 WM8993_DRC_CONTROL_4, 13, drc_r1_text);
692 692
693static const char *drc_attack_text[] = { 693static const char *drc_attack_text[] = {
694 "Reserved", 694 "Reserved",
@@ -705,8 +705,8 @@ static const char *drc_attack_text[] = {
705 "185.6ms", 705 "185.6ms",
706}; 706};
707 707
708static const struct soc_enum drc_attack = 708static SOC_ENUM_SINGLE_DECL(drc_attack,
709 SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_2, 12, 12, drc_attack_text); 709 WM8993_DRC_CONTROL_2, 12, drc_attack_text);
710 710
711static const char *drc_decay_text[] = { 711static const char *drc_decay_text[] = {
712 "186ms", 712 "186ms",
@@ -720,16 +720,16 @@ static const char *drc_decay_text[] = {
720 "47.56ms", 720 "47.56ms",
721}; 721};
722 722
723static const struct soc_enum drc_decay = 723static SOC_ENUM_SINGLE_DECL(drc_decay,
724 SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_2, 8, 9, drc_decay_text); 724 WM8993_DRC_CONTROL_2, 8, drc_decay_text);
725 725
726static const char *drc_ff_text[] = { 726static const char *drc_ff_text[] = {
727 "5 samples", 727 "5 samples",
728 "9 samples", 728 "9 samples",
729}; 729};
730 730
731static const struct soc_enum drc_ff = 731static SOC_ENUM_SINGLE_DECL(drc_ff,
732 SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_3, 7, 2, drc_ff_text); 732 WM8993_DRC_CONTROL_3, 7, drc_ff_text);
733 733
734static const char *drc_qr_rate_text[] = { 734static const char *drc_qr_rate_text[] = {
735 "0.725ms", 735 "0.725ms",
@@ -737,8 +737,8 @@ static const char *drc_qr_rate_text[] = {
737 "5.8ms", 737 "5.8ms",
738}; 738};
739 739
740static const struct soc_enum drc_qr_rate = 740static SOC_ENUM_SINGLE_DECL(drc_qr_rate,
741 SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_3, 0, 3, drc_qr_rate_text); 741 WM8993_DRC_CONTROL_3, 0, drc_qr_rate_text);
742 742
743static const char *drc_smooth_text[] = { 743static const char *drc_smooth_text[] = {
744 "Low", 744 "Low",
@@ -746,8 +746,8 @@ static const char *drc_smooth_text[] = {
746 "High", 746 "High",
747}; 747};
748 748
749static const struct soc_enum drc_smooth = 749static SOC_ENUM_SINGLE_DECL(drc_smooth,
750 SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_1, 4, 3, drc_smooth_text); 750 WM8993_DRC_CONTROL_1, 4, drc_smooth_text);
751 751
752static const struct snd_kcontrol_new wm8993_snd_controls[] = { 752static const struct snd_kcontrol_new wm8993_snd_controls[] = {
753SOC_DOUBLE_TLV("Digital Sidetone Volume", WM8993_DIGITAL_SIDE_TONE, 753SOC_DOUBLE_TLV("Digital Sidetone Volume", WM8993_DIGITAL_SIDE_TONE,
@@ -841,26 +841,26 @@ static const char *aif_text[] = {
841 "Left", "Right" 841 "Left", "Right"
842}; 842};
843 843
844static const struct soc_enum aifoutl_enum = 844static SOC_ENUM_SINGLE_DECL(aifoutl_enum,
845 SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_1, 15, 2, aif_text); 845 WM8993_AUDIO_INTERFACE_1, 15, aif_text);
846 846
847static const struct snd_kcontrol_new aifoutl_mux = 847static const struct snd_kcontrol_new aifoutl_mux =
848 SOC_DAPM_ENUM("AIFOUTL Mux", aifoutl_enum); 848 SOC_DAPM_ENUM("AIFOUTL Mux", aifoutl_enum);
849 849
850static const struct soc_enum aifoutr_enum = 850static SOC_ENUM_SINGLE_DECL(aifoutr_enum,
851 SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_1, 14, 2, aif_text); 851 WM8993_AUDIO_INTERFACE_1, 14, aif_text);
852 852
853static const struct snd_kcontrol_new aifoutr_mux = 853static const struct snd_kcontrol_new aifoutr_mux =
854 SOC_DAPM_ENUM("AIFOUTR Mux", aifoutr_enum); 854 SOC_DAPM_ENUM("AIFOUTR Mux", aifoutr_enum);
855 855
856static const struct soc_enum aifinl_enum = 856static SOC_ENUM_SINGLE_DECL(aifinl_enum,
857 SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_2, 15, 2, aif_text); 857 WM8993_AUDIO_INTERFACE_2, 15, aif_text);
858 858
859static const struct snd_kcontrol_new aifinl_mux = 859static const struct snd_kcontrol_new aifinl_mux =
860 SOC_DAPM_ENUM("AIFINL Mux", aifinl_enum); 860 SOC_DAPM_ENUM("AIFINL Mux", aifinl_enum);
861 861
862static const struct soc_enum aifinr_enum = 862static SOC_ENUM_SINGLE_DECL(aifinr_enum,
863 SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_2, 14, 2, aif_text); 863 WM8993_AUDIO_INTERFACE_2, 14, aif_text);
864 864
865static const struct snd_kcontrol_new aifinr_mux = 865static const struct snd_kcontrol_new aifinr_mux =
866 SOC_DAPM_ENUM("AIFINR Mux", aifinr_enum); 866 SOC_DAPM_ENUM("AIFINR Mux", aifinr_enum);
@@ -869,14 +869,14 @@ static const char *sidetone_text[] = {
869 "None", "Left", "Right" 869 "None", "Left", "Right"
870}; 870};
871 871
872static const struct soc_enum sidetonel_enum = 872static SOC_ENUM_SINGLE_DECL(sidetonel_enum,
873 SOC_ENUM_SINGLE(WM8993_DIGITAL_SIDE_TONE, 2, 3, sidetone_text); 873 WM8993_DIGITAL_SIDE_TONE, 2, sidetone_text);
874 874
875static const struct snd_kcontrol_new sidetonel_mux = 875static const struct snd_kcontrol_new sidetonel_mux =
876 SOC_DAPM_ENUM("Left Sidetone", sidetonel_enum); 876 SOC_DAPM_ENUM("Left Sidetone", sidetonel_enum);
877 877
878static const struct soc_enum sidetoner_enum = 878static SOC_ENUM_SINGLE_DECL(sidetoner_enum,
879 SOC_ENUM_SINGLE(WM8993_DIGITAL_SIDE_TONE, 0, 3, sidetone_text); 879 WM8993_DIGITAL_SIDE_TONE, 0, sidetone_text);
880 880
881static const struct snd_kcontrol_new sidetoner_mux = 881static const struct snd_kcontrol_new sidetoner_mux =
882 SOC_DAPM_ENUM("Right Sidetone", sidetoner_enum); 882 SOC_DAPM_ENUM("Right Sidetone", sidetoner_enum);
@@ -1493,13 +1493,6 @@ static int wm8993_probe(struct snd_soc_codec *codec)
1493 wm8993->hubs_data.dcs_codes_r = -2; 1493 wm8993->hubs_data.dcs_codes_r = -2;
1494 wm8993->hubs_data.series_startup = 1; 1494 wm8993->hubs_data.series_startup = 1;
1495 1495
1496 codec->control_data = wm8993->regmap;
1497 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1498 if (ret != 0) {
1499 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1500 return ret;
1501 }
1502
1503 /* Latch volume update bits and default ZC on */ 1496 /* Latch volume update bits and default ZC on */
1504 snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME, 1497 snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME,
1505 WM8993_DAC_VU, WM8993_DAC_VU); 1498 WM8993_DAC_VU, WM8993_DAC_VU);
@@ -1559,8 +1552,6 @@ static int wm8993_probe(struct snd_soc_codec *codec)
1559 1552
1560static int wm8993_remove(struct snd_soc_codec *codec) 1553static int wm8993_remove(struct snd_soc_codec *codec)
1561{ 1554{
1562 struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
1563
1564 wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF); 1555 wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF);
1565 return 0; 1556 return 0;
1566} 1557}
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index adb72063d44e..6303537f54c6 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -1344,8 +1344,7 @@ static const char *adc_mux_text[] = {
1344 "DMIC", 1344 "DMIC",
1345}; 1345};
1346 1346
1347static SOC_ENUM_SINGLE_DECL(adc_enum, 1347static SOC_ENUM_SINGLE_VIRT_DECL(adc_enum, adc_mux_text);
1348 0, 0, adc_mux_text);
1349 1348
1350static const struct snd_kcontrol_new adcl_mux = 1349static const struct snd_kcontrol_new adcl_mux =
1351 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum); 1350 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
@@ -2554,43 +2553,52 @@ static int wm8994_set_bias_level(struct snd_soc_codec *codec,
2554int wm8994_vmid_mode(struct snd_soc_codec *codec, enum wm8994_vmid_mode mode) 2553int wm8994_vmid_mode(struct snd_soc_codec *codec, enum wm8994_vmid_mode mode)
2555{ 2554{
2556 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 2555 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
2556 struct snd_soc_dapm_context *dapm = &codec->dapm;
2557 2557
2558 switch (mode) { 2558 switch (mode) {
2559 case WM8994_VMID_NORMAL: 2559 case WM8994_VMID_NORMAL:
2560 snd_soc_dapm_mutex_lock(dapm);
2561
2560 if (wm8994->hubs.lineout1_se) { 2562 if (wm8994->hubs.lineout1_se) {
2561 snd_soc_dapm_disable_pin(&codec->dapm, 2563 snd_soc_dapm_disable_pin_unlocked(dapm,
2562 "LINEOUT1N Driver"); 2564 "LINEOUT1N Driver");
2563 snd_soc_dapm_disable_pin(&codec->dapm, 2565 snd_soc_dapm_disable_pin_unlocked(dapm,
2564 "LINEOUT1P Driver"); 2566 "LINEOUT1P Driver");
2565 } 2567 }
2566 if (wm8994->hubs.lineout2_se) { 2568 if (wm8994->hubs.lineout2_se) {
2567 snd_soc_dapm_disable_pin(&codec->dapm, 2569 snd_soc_dapm_disable_pin_unlocked(dapm,
2568 "LINEOUT2N Driver"); 2570 "LINEOUT2N Driver");
2569 snd_soc_dapm_disable_pin(&codec->dapm, 2571 snd_soc_dapm_disable_pin_unlocked(dapm,
2570 "LINEOUT2P Driver"); 2572 "LINEOUT2P Driver");
2571 } 2573 }
2572 2574
2573 /* Do the sync with the old mode to allow it to clean up */ 2575 /* Do the sync with the old mode to allow it to clean up */
2574 snd_soc_dapm_sync(&codec->dapm); 2576 snd_soc_dapm_sync_unlocked(dapm);
2575 wm8994->vmid_mode = mode; 2577 wm8994->vmid_mode = mode;
2578
2579 snd_soc_dapm_mutex_unlock(dapm);
2576 break; 2580 break;
2577 2581
2578 case WM8994_VMID_FORCE: 2582 case WM8994_VMID_FORCE:
2583 snd_soc_dapm_mutex_lock(dapm);
2584
2579 if (wm8994->hubs.lineout1_se) { 2585 if (wm8994->hubs.lineout1_se) {
2580 snd_soc_dapm_force_enable_pin(&codec->dapm, 2586 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2581 "LINEOUT1N Driver"); 2587 "LINEOUT1N Driver");
2582 snd_soc_dapm_force_enable_pin(&codec->dapm, 2588 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2583 "LINEOUT1P Driver"); 2589 "LINEOUT1P Driver");
2584 } 2590 }
2585 if (wm8994->hubs.lineout2_se) { 2591 if (wm8994->hubs.lineout2_se) {
2586 snd_soc_dapm_force_enable_pin(&codec->dapm, 2592 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2587 "LINEOUT2N Driver"); 2593 "LINEOUT2N Driver");
2588 snd_soc_dapm_force_enable_pin(&codec->dapm, 2594 snd_soc_dapm_force_enable_pin_unlocked(dapm,
2589 "LINEOUT2P Driver"); 2595 "LINEOUT2P Driver");
2590 } 2596 }
2591 2597
2592 wm8994->vmid_mode = mode; 2598 wm8994->vmid_mode = mode;
2593 snd_soc_dapm_sync(&codec->dapm); 2599 snd_soc_dapm_sync_unlocked(dapm);
2600
2601 snd_soc_dapm_mutex_unlock(dapm);
2594 break; 2602 break;
2595 2603
2596 default: 2604 default:
@@ -3242,7 +3250,7 @@ static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
3242 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n", 3250 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
3243 wm8994->num_retune_mobile_texts); 3251 wm8994->num_retune_mobile_texts);
3244 3252
3245 wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts; 3253 wm8994->retune_mobile_enum.items = wm8994->num_retune_mobile_texts;
3246 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts; 3254 wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
3247 3255
3248 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, controls, 3256 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, controls,
@@ -3298,7 +3306,7 @@ static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
3298 for (i = 0; i < pdata->num_drc_cfgs; i++) 3306 for (i = 0; i < pdata->num_drc_cfgs; i++)
3299 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name; 3307 wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
3300 3308
3301 wm8994->drc_enum.max = pdata->num_drc_cfgs; 3309 wm8994->drc_enum.items = pdata->num_drc_cfgs;
3302 wm8994->drc_enum.texts = wm8994->drc_texts; 3310 wm8994->drc_enum.texts = wm8994->drc_texts;
3303 3311
3304 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, controls, 3312 ret = snd_soc_add_codec_controls(wm8994->hubs.codec, controls,
@@ -3990,9 +3998,8 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)
3990 int ret, i; 3998 int ret, i;
3991 3999
3992 wm8994->hubs.codec = codec; 4000 wm8994->hubs.codec = codec;
3993 codec->control_data = control->regmap;
3994 4001
3995 snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP); 4002 snd_soc_codec_set_cache_io(codec, control->regmap);
3996 4003
3997 mutex_init(&wm8994->accdet_lock); 4004 mutex_init(&wm8994->accdet_lock);
3998 INIT_DELAYED_WORK(&wm8994->jackdet_bootstrap, 4005 INIT_DELAYED_WORK(&wm8994->jackdet_bootstrap,
diff --git a/sound/soc/codecs/wm8995.c b/sound/soc/codecs/wm8995.c
index 4300caff1783..d3152cf5bd56 100644
--- a/sound/soc/codecs/wm8995.c
+++ b/sound/soc/codecs/wm8995.c
@@ -423,24 +423,24 @@ static const char *in1l_text[] = {
423 "Differential", "Single-ended IN1LN", "Single-ended IN1LP" 423 "Differential", "Single-ended IN1LN", "Single-ended IN1LP"
424}; 424};
425 425
426static const SOC_ENUM_SINGLE_DECL(in1l_enum, WM8995_LEFT_LINE_INPUT_CONTROL, 426static SOC_ENUM_SINGLE_DECL(in1l_enum, WM8995_LEFT_LINE_INPUT_CONTROL,
427 2, in1l_text); 427 2, in1l_text);
428 428
429static const char *in1r_text[] = { 429static const char *in1r_text[] = {
430 "Differential", "Single-ended IN1RN", "Single-ended IN1RP" 430 "Differential", "Single-ended IN1RN", "Single-ended IN1RP"
431}; 431};
432 432
433static const SOC_ENUM_SINGLE_DECL(in1r_enum, WM8995_LEFT_LINE_INPUT_CONTROL, 433static SOC_ENUM_SINGLE_DECL(in1r_enum, WM8995_LEFT_LINE_INPUT_CONTROL,
434 0, in1r_text); 434 0, in1r_text);
435 435
436static const char *dmic_src_text[] = { 436static const char *dmic_src_text[] = {
437 "DMICDAT1", "DMICDAT2", "DMICDAT3" 437 "DMICDAT1", "DMICDAT2", "DMICDAT3"
438}; 438};
439 439
440static const SOC_ENUM_SINGLE_DECL(dmic_src1_enum, WM8995_POWER_MANAGEMENT_5, 440static SOC_ENUM_SINGLE_DECL(dmic_src1_enum, WM8995_POWER_MANAGEMENT_5,
441 8, dmic_src_text); 441 8, dmic_src_text);
442static const SOC_ENUM_SINGLE_DECL(dmic_src2_enum, WM8995_POWER_MANAGEMENT_5, 442static SOC_ENUM_SINGLE_DECL(dmic_src2_enum, WM8995_POWER_MANAGEMENT_5,
443 6, dmic_src_text); 443 6, dmic_src_text);
444 444
445static const struct snd_kcontrol_new wm8995_snd_controls[] = { 445static const struct snd_kcontrol_new wm8995_snd_controls[] = {
446 SOC_DOUBLE_R_TLV("DAC1 Volume", WM8995_DAC1_LEFT_VOLUME, 446 SOC_DOUBLE_R_TLV("DAC1 Volume", WM8995_DAC1_LEFT_VOLUME,
@@ -561,10 +561,8 @@ static int hp_supply_event(struct snd_soc_dapm_widget *w,
561 struct snd_kcontrol *kcontrol, int event) 561 struct snd_kcontrol *kcontrol, int event)
562{ 562{
563 struct snd_soc_codec *codec; 563 struct snd_soc_codec *codec;
564 struct wm8995_priv *wm8995;
565 564
566 codec = w->codec; 565 codec = w->codec;
567 wm8995 = snd_soc_codec_get_drvdata(codec);
568 566
569 switch (event) { 567 switch (event) {
570 case SND_SOC_DAPM_PRE_PMU: 568 case SND_SOC_DAPM_PRE_PMU:
@@ -783,14 +781,12 @@ static const char *sidetone_text[] = {
783 "ADC/DMIC1", "DMIC2", 781 "ADC/DMIC1", "DMIC2",
784}; 782};
785 783
786static const struct soc_enum sidetone1_enum = 784static SOC_ENUM_SINGLE_DECL(sidetone1_enum, WM8995_SIDETONE, 0, sidetone_text);
787 SOC_ENUM_SINGLE(WM8995_SIDETONE, 0, 2, sidetone_text);
788 785
789static const struct snd_kcontrol_new sidetone1_mux = 786static const struct snd_kcontrol_new sidetone1_mux =
790 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum); 787 SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
791 788
792static const struct soc_enum sidetone2_enum = 789static SOC_ENUM_SINGLE_DECL(sidetone2_enum, WM8995_SIDETONE, 1, sidetone_text);
793 SOC_ENUM_SINGLE(WM8995_SIDETONE, 1, 2, sidetone_text);
794 790
795static const struct snd_kcontrol_new sidetone2_mux = 791static const struct snd_kcontrol_new sidetone2_mux =
796 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum); 792 SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
@@ -886,8 +882,7 @@ static const char *adc_mux_text[] = {
886 "DMIC", 882 "DMIC",
887}; 883};
888 884
889static const struct soc_enum adc_enum = 885static SOC_ENUM_SINGLE_VIRT_DECL(adc_enum, adc_mux_text);
890 SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
891 886
892static const struct snd_kcontrol_new adcl_mux = 887static const struct snd_kcontrol_new adcl_mux =
893 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum); 888 SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
@@ -899,14 +894,14 @@ static const char *spk_src_text[] = {
899 "DAC1L", "DAC1R", "DAC2L", "DAC2R" 894 "DAC1L", "DAC1R", "DAC2L", "DAC2R"
900}; 895};
901 896
902static const SOC_ENUM_SINGLE_DECL(spk1l_src_enum, WM8995_LEFT_PDM_SPEAKER_1, 897static SOC_ENUM_SINGLE_DECL(spk1l_src_enum, WM8995_LEFT_PDM_SPEAKER_1,
903 0, spk_src_text); 898 0, spk_src_text);
904static const SOC_ENUM_SINGLE_DECL(spk1r_src_enum, WM8995_RIGHT_PDM_SPEAKER_1, 899static SOC_ENUM_SINGLE_DECL(spk1r_src_enum, WM8995_RIGHT_PDM_SPEAKER_1,
905 0, spk_src_text); 900 0, spk_src_text);
906static const SOC_ENUM_SINGLE_DECL(spk2l_src_enum, WM8995_LEFT_PDM_SPEAKER_2, 901static SOC_ENUM_SINGLE_DECL(spk2l_src_enum, WM8995_LEFT_PDM_SPEAKER_2,
907 0, spk_src_text); 902 0, spk_src_text);
908static const SOC_ENUM_SINGLE_DECL(spk2r_src_enum, WM8995_RIGHT_PDM_SPEAKER_2, 903static SOC_ENUM_SINGLE_DECL(spk2r_src_enum, WM8995_RIGHT_PDM_SPEAKER_2,
909 0, spk_src_text); 904 0, spk_src_text);
910 905
911static const struct snd_kcontrol_new spk1l_mux = 906static const struct snd_kcontrol_new spk1l_mux =
912 SOC_DAPM_ENUM("SPK1L SRC", spk1l_src_enum); 907 SOC_DAPM_ENUM("SPK1L SRC", spk1l_src_enum);
@@ -2047,13 +2042,6 @@ static int wm8995_probe(struct snd_soc_codec *codec)
2047 wm8995 = snd_soc_codec_get_drvdata(codec); 2042 wm8995 = snd_soc_codec_get_drvdata(codec);
2048 wm8995->codec = codec; 2043 wm8995->codec = codec;
2049 2044
2050 codec->control_data = wm8995->regmap;
2051 ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
2052 if (ret < 0) {
2053 dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret);
2054 return ret;
2055 }
2056
2057 for (i = 0; i < ARRAY_SIZE(wm8995->supplies); i++) 2045 for (i = 0; i < ARRAY_SIZE(wm8995->supplies); i++)
2058 wm8995->supplies[i].supply = wm8995_supply_names[i]; 2046 wm8995->supplies[i].supply = wm8995_supply_names[i];
2059 2047
diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c
index 1a7655b0aa22..c6cbb3b8ace9 100644
--- a/sound/soc/codecs/wm8996.c
+++ b/sound/soc/codecs/wm8996.c
@@ -311,28 +311,28 @@ static const char *sidetone_hpf_text[] = {
311 "2.9kHz", "1.5kHz", "735Hz", "403Hz", "196Hz", "98Hz", "49Hz" 311 "2.9kHz", "1.5kHz", "735Hz", "403Hz", "196Hz", "98Hz", "49Hz"
312}; 312};
313 313
314static const struct soc_enum sidetone_hpf = 314static SOC_ENUM_SINGLE_DECL(sidetone_hpf,
315 SOC_ENUM_SINGLE(WM8996_SIDETONE, 7, 7, sidetone_hpf_text); 315 WM8996_SIDETONE, 7, sidetone_hpf_text);
316 316
317static const char *hpf_mode_text[] = { 317static const char *hpf_mode_text[] = {
318 "HiFi", "Custom", "Voice" 318 "HiFi", "Custom", "Voice"
319}; 319};
320 320
321static const struct soc_enum dsp1tx_hpf_mode = 321static SOC_ENUM_SINGLE_DECL(dsp1tx_hpf_mode,
322 SOC_ENUM_SINGLE(WM8996_DSP1_TX_FILTERS, 3, 3, hpf_mode_text); 322 WM8996_DSP1_TX_FILTERS, 3, hpf_mode_text);
323 323
324static const struct soc_enum dsp2tx_hpf_mode = 324static SOC_ENUM_SINGLE_DECL(dsp2tx_hpf_mode,
325 SOC_ENUM_SINGLE(WM8996_DSP2_TX_FILTERS, 3, 3, hpf_mode_text); 325 WM8996_DSP2_TX_FILTERS, 3, hpf_mode_text);
326 326
327static const char *hpf_cutoff_text[] = { 327static const char *hpf_cutoff_text[] = {
328 "50Hz", "75Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz" 328 "50Hz", "75Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
329}; 329};
330 330
331static const struct soc_enum dsp1tx_hpf_cutoff = 331static SOC_ENUM_SINGLE_DECL(dsp1tx_hpf_cutoff,
332 SOC_ENUM_SINGLE(WM8996_DSP1_TX_FILTERS, 0, 7, hpf_cutoff_text); 332 WM8996_DSP1_TX_FILTERS, 0, hpf_cutoff_text);
333 333
334static const struct soc_enum dsp2tx_hpf_cutoff = 334static SOC_ENUM_SINGLE_DECL(dsp2tx_hpf_cutoff,
335 SOC_ENUM_SINGLE(WM8996_DSP2_TX_FILTERS, 0, 7, hpf_cutoff_text); 335 WM8996_DSP2_TX_FILTERS, 0, hpf_cutoff_text);
336 336
337static void wm8996_set_retune_mobile(struct snd_soc_codec *codec, int block) 337static void wm8996_set_retune_mobile(struct snd_soc_codec *codec, int block)
338{ 338{
@@ -780,14 +780,14 @@ static const char *sidetone_text[] = {
780 "IN1", "IN2", 780 "IN1", "IN2",
781}; 781};
782 782
783static const struct soc_enum left_sidetone_enum = 783static SOC_ENUM_SINGLE_DECL(left_sidetone_enum,
784 SOC_ENUM_SINGLE(WM8996_SIDETONE, 0, 2, sidetone_text); 784 WM8996_SIDETONE, 0, sidetone_text);
785 785
786static const struct snd_kcontrol_new left_sidetone = 786static const struct snd_kcontrol_new left_sidetone =
787 SOC_DAPM_ENUM("Left Sidetone", left_sidetone_enum); 787 SOC_DAPM_ENUM("Left Sidetone", left_sidetone_enum);
788 788
789static const struct soc_enum right_sidetone_enum = 789static SOC_ENUM_SINGLE_DECL(right_sidetone_enum,
790 SOC_ENUM_SINGLE(WM8996_SIDETONE, 1, 2, sidetone_text); 790 WM8996_SIDETONE, 1, sidetone_text);
791 791
792static const struct snd_kcontrol_new right_sidetone = 792static const struct snd_kcontrol_new right_sidetone =
793 SOC_DAPM_ENUM("Right Sidetone", right_sidetone_enum); 793 SOC_DAPM_ENUM("Right Sidetone", right_sidetone_enum);
@@ -796,14 +796,14 @@ static const char *spk_text[] = {
796 "DAC1L", "DAC1R", "DAC2L", "DAC2R" 796 "DAC1L", "DAC1R", "DAC2L", "DAC2R"
797}; 797};
798 798
799static const struct soc_enum spkl_enum = 799static SOC_ENUM_SINGLE_DECL(spkl_enum,
800 SOC_ENUM_SINGLE(WM8996_LEFT_PDM_SPEAKER, 0, 4, spk_text); 800 WM8996_LEFT_PDM_SPEAKER, 0, spk_text);
801 801
802static const struct snd_kcontrol_new spkl_mux = 802static const struct snd_kcontrol_new spkl_mux =
803 SOC_DAPM_ENUM("SPKL", spkl_enum); 803 SOC_DAPM_ENUM("SPKL", spkl_enum);
804 804
805static const struct soc_enum spkr_enum = 805static SOC_ENUM_SINGLE_DECL(spkr_enum,
806 SOC_ENUM_SINGLE(WM8996_RIGHT_PDM_SPEAKER, 0, 4, spk_text); 806 WM8996_RIGHT_PDM_SPEAKER, 0, spk_text);
807 807
808static const struct snd_kcontrol_new spkr_mux = 808static const struct snd_kcontrol_new spkr_mux =
809 SOC_DAPM_ENUM("SPKR", spkr_enum); 809 SOC_DAPM_ENUM("SPKR", spkr_enum);
@@ -812,8 +812,8 @@ static const char *dsp1rx_text[] = {
812 "AIF1", "AIF2" 812 "AIF1", "AIF2"
813}; 813};
814 814
815static const struct soc_enum dsp1rx_enum = 815static SOC_ENUM_SINGLE_DECL(dsp1rx_enum,
816 SOC_ENUM_SINGLE(WM8996_POWER_MANAGEMENT_8, 0, 2, dsp1rx_text); 816 WM8996_POWER_MANAGEMENT_8, 0, dsp1rx_text);
817 817
818static const struct snd_kcontrol_new dsp1rx = 818static const struct snd_kcontrol_new dsp1rx =
819 SOC_DAPM_ENUM("DSP1RX", dsp1rx_enum); 819 SOC_DAPM_ENUM("DSP1RX", dsp1rx_enum);
@@ -822,8 +822,8 @@ static const char *dsp2rx_text[] = {
822 "AIF2", "AIF1" 822 "AIF2", "AIF1"
823}; 823};
824 824
825static const struct soc_enum dsp2rx_enum = 825static SOC_ENUM_SINGLE_DECL(dsp2rx_enum,
826 SOC_ENUM_SINGLE(WM8996_POWER_MANAGEMENT_8, 4, 2, dsp2rx_text); 826 WM8996_POWER_MANAGEMENT_8, 4, dsp2rx_text);
827 827
828static const struct snd_kcontrol_new dsp2rx = 828static const struct snd_kcontrol_new dsp2rx =
829 SOC_DAPM_ENUM("DSP2RX", dsp2rx_enum); 829 SOC_DAPM_ENUM("DSP2RX", dsp2rx_enum);
@@ -832,8 +832,8 @@ static const char *aif2tx_text[] = {
832 "DSP2", "DSP1", "AIF1" 832 "DSP2", "DSP1", "AIF1"
833}; 833};
834 834
835static const struct soc_enum aif2tx_enum = 835static SOC_ENUM_SINGLE_DECL(aif2tx_enum,
836 SOC_ENUM_SINGLE(WM8996_POWER_MANAGEMENT_8, 6, 3, aif2tx_text); 836 WM8996_POWER_MANAGEMENT_8, 6, aif2tx_text);
837 837
838static const struct snd_kcontrol_new aif2tx = 838static const struct snd_kcontrol_new aif2tx =
839 SOC_DAPM_ENUM("AIF2TX", aif2tx_enum); 839 SOC_DAPM_ENUM("AIF2TX", aif2tx_enum);
@@ -842,14 +842,14 @@ static const char *inmux_text[] = {
842 "ADC", "DMIC1", "DMIC2" 842 "ADC", "DMIC1", "DMIC2"
843}; 843};
844 844
845static const struct soc_enum in1_enum = 845static SOC_ENUM_SINGLE_DECL(in1_enum,
846 SOC_ENUM_SINGLE(WM8996_POWER_MANAGEMENT_7, 0, 3, inmux_text); 846 WM8996_POWER_MANAGEMENT_7, 0, inmux_text);
847 847
848static const struct snd_kcontrol_new in1_mux = 848static const struct snd_kcontrol_new in1_mux =
849 SOC_DAPM_ENUM("IN1 Mux", in1_enum); 849 SOC_DAPM_ENUM("IN1 Mux", in1_enum);
850 850
851static const struct soc_enum in2_enum = 851static SOC_ENUM_SINGLE_DECL(in2_enum,
852 SOC_ENUM_SINGLE(WM8996_POWER_MANAGEMENT_7, 4, 3, inmux_text); 852 WM8996_POWER_MANAGEMENT_7, 4, inmux_text);
853 853
854static const struct snd_kcontrol_new in2_mux = 854static const struct snd_kcontrol_new in2_mux =
855 SOC_DAPM_ENUM("IN2 Mux", in2_enum); 855 SOC_DAPM_ENUM("IN2 Mux", in2_enum);
@@ -1608,8 +1608,8 @@ static int wm8996_set_bias_level(struct snd_soc_codec *codec,
1608 msleep(5); 1608 msleep(5);
1609 } 1609 }
1610 1610
1611 regcache_cache_only(codec->control_data, false); 1611 regcache_cache_only(wm8996->regmap, false);
1612 regcache_sync(codec->control_data); 1612 regcache_sync(wm8996->regmap);
1613 } 1613 }
1614 1614
1615 /* Bypass the MICBIASes for lowest power */ 1615 /* Bypass the MICBIASes for lowest power */
@@ -1620,10 +1620,10 @@ static int wm8996_set_bias_level(struct snd_soc_codec *codec,
1620 break; 1620 break;
1621 1621
1622 case SND_SOC_BIAS_OFF: 1622 case SND_SOC_BIAS_OFF:
1623 regcache_cache_only(codec->control_data, true); 1623 regcache_cache_only(wm8996->regmap, true);
1624 if (wm8996->pdata.ldo_ena >= 0) { 1624 if (wm8996->pdata.ldo_ena >= 0) {
1625 gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0); 1625 gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0);
1626 regcache_cache_only(codec->control_data, true); 1626 regcache_cache_only(wm8996->regmap, true);
1627 } 1627 }
1628 regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), 1628 regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies),
1629 wm8996->supplies); 1629 wm8996->supplies);
@@ -2251,6 +2251,7 @@ int wm8996_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
2251 wm8996_polarity_fn polarity_cb) 2251 wm8996_polarity_fn polarity_cb)
2252{ 2252{
2253 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); 2253 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
2254 struct snd_soc_dapm_context *dapm = &codec->dapm;
2254 2255
2255 wm8996->jack = jack; 2256 wm8996->jack = jack;
2256 wm8996->detecting = true; 2257 wm8996->detecting = true;
@@ -2267,8 +2268,12 @@ int wm8996_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
2267 WM8996_MICB2_DISCH, 0); 2268 WM8996_MICB2_DISCH, 0);
2268 2269
2269 /* LDO2 powers the microphones, SYSCLK clocks detection */ 2270 /* LDO2 powers the microphones, SYSCLK clocks detection */
2270 snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO2"); 2271 snd_soc_dapm_mutex_lock(dapm);
2271 snd_soc_dapm_force_enable_pin(&codec->dapm, "SYSCLK"); 2272
2273 snd_soc_dapm_force_enable_pin_unlocked(dapm, "LDO2");
2274 snd_soc_dapm_force_enable_pin_unlocked(dapm, "SYSCLK");
2275
2276 snd_soc_dapm_mutex_unlock(dapm);
2272 2277
2273 /* We start off just enabling microphone detection - even a 2278 /* We start off just enabling microphone detection - even a
2274 * plain headphone will trigger detection. 2279 * plain headphone will trigger detection.
@@ -2595,7 +2600,7 @@ static void wm8996_retune_mobile_pdata(struct snd_soc_codec *codec)
2595 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n", 2600 dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
2596 wm8996->num_retune_mobile_texts); 2601 wm8996->num_retune_mobile_texts);
2597 2602
2598 wm8996->retune_mobile_enum.max = wm8996->num_retune_mobile_texts; 2603 wm8996->retune_mobile_enum.items = wm8996->num_retune_mobile_texts;
2599 wm8996->retune_mobile_enum.texts = wm8996->retune_mobile_texts; 2604 wm8996->retune_mobile_enum.texts = wm8996->retune_mobile_texts;
2600 2605
2601 ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls)); 2606 ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls));
@@ -2628,14 +2633,6 @@ static int wm8996_probe(struct snd_soc_codec *codec)
2628 init_completion(&wm8996->dcs_done); 2633 init_completion(&wm8996->dcs_done);
2629 init_completion(&wm8996->fll_lock); 2634 init_completion(&wm8996->fll_lock);
2630 2635
2631 codec->control_data = wm8996->regmap;
2632
2633 ret = snd_soc_codec_set_cache_io(codec, 16, 16, SND_SOC_REGMAP);
2634 if (ret != 0) {
2635 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
2636 goto err;
2637 }
2638
2639 if (wm8996->pdata.num_retune_mobile_cfgs) 2636 if (wm8996->pdata.num_retune_mobile_cfgs)
2640 wm8996_retune_mobile_pdata(codec); 2637 wm8996_retune_mobile_pdata(codec);
2641 else 2638 else
@@ -2674,13 +2671,11 @@ static int wm8996_probe(struct snd_soc_codec *codec)
2674 } else { 2671 } else {
2675 dev_err(codec->dev, "Failed to request IRQ: %d\n", 2672 dev_err(codec->dev, "Failed to request IRQ: %d\n",
2676 ret); 2673 ret);
2674 return ret;
2677 } 2675 }
2678 } 2676 }
2679 2677
2680 return 0; 2678 return 0;
2681
2682err:
2683 return ret;
2684} 2679}
2685 2680
2686static int wm8996_remove(struct snd_soc_codec *codec) 2681static int wm8996_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/wm8997.c b/sound/soc/codecs/wm8997.c
index 555115ee2159..004186b6bd48 100644
--- a/sound/soc/codecs/wm8997.c
+++ b/sound/soc/codecs/wm8997.c
@@ -86,7 +86,7 @@ static int wm8997_sysclk_ev(struct snd_soc_dapm_widget *w,
86{ 86{
87 struct snd_soc_codec *codec = w->codec; 87 struct snd_soc_codec *codec = w->codec;
88 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 88 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
89 struct regmap *regmap = codec->control_data; 89 struct regmap *regmap = arizona->regmap;
90 const struct reg_default *patch = NULL; 90 const struct reg_default *patch = NULL;
91 int i, patch_size; 91 int i, patch_size;
92 92
@@ -123,10 +123,12 @@ static const unsigned int wm8997_osr_val[] = {
123 123
124static const struct soc_enum wm8997_hpout_osr[] = { 124static const struct soc_enum wm8997_hpout_osr[] = {
125 SOC_VALUE_ENUM_SINGLE(ARIZONA_OUTPUT_PATH_CONFIG_1L, 125 SOC_VALUE_ENUM_SINGLE(ARIZONA_OUTPUT_PATH_CONFIG_1L,
126 ARIZONA_OUT1_OSR_SHIFT, 0x7, 3, 126 ARIZONA_OUT1_OSR_SHIFT, 0x7,
127 ARRAY_SIZE(wm8997_osr_text),
127 wm8997_osr_text, wm8997_osr_val), 128 wm8997_osr_text, wm8997_osr_val),
128 SOC_VALUE_ENUM_SINGLE(ARIZONA_OUTPUT_PATH_CONFIG_3L, 129 SOC_VALUE_ENUM_SINGLE(ARIZONA_OUTPUT_PATH_CONFIG_3L,
129 ARIZONA_OUT3_OSR_SHIFT, 0x7, 3, 130 ARIZONA_OUT3_OSR_SHIFT, 0x7,
131 ARRAY_SIZE(wm8997_osr_text),
130 wm8997_osr_text, wm8997_osr_val), 132 wm8997_osr_text, wm8997_osr_val),
131}; 133};
132 134
@@ -170,15 +172,8 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
170ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE), 172ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
171ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE), 173ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
172 174
173SND_SOC_BYTES_MASK("EQ1 Coefficients", ARIZONA_EQ1_1, 21, 175SND_SOC_BYTES("EQ1 Coefficients", ARIZONA_EQ1_3, 19),
174 ARIZONA_EQ1_ENA_MASK), 176SOC_SINGLE("EQ1 Mode Switch", ARIZONA_EQ1_2, ARIZONA_EQ1_B1_MODE, 1, 0),
175SND_SOC_BYTES_MASK("EQ2 Coefficients", ARIZONA_EQ2_1, 21,
176 ARIZONA_EQ2_ENA_MASK),
177SND_SOC_BYTES_MASK("EQ3 Coefficients", ARIZONA_EQ3_1, 21,
178 ARIZONA_EQ3_ENA_MASK),
179SND_SOC_BYTES_MASK("EQ4 Coefficients", ARIZONA_EQ4_1, 21,
180 ARIZONA_EQ4_ENA_MASK),
181
182SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT, 177SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
183 24, 0, eq_tlv), 178 24, 0, eq_tlv),
184SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT, 179SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT,
@@ -190,6 +185,8 @@ SOC_SINGLE_TLV("EQ1 B4 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B4_GAIN_SHIFT,
190SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT, 185SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT,
191 24, 0, eq_tlv), 186 24, 0, eq_tlv),
192 187
188SND_SOC_BYTES("EQ2 Coefficients", ARIZONA_EQ2_3, 19),
189SOC_SINGLE("EQ2 Mode Switch", ARIZONA_EQ2_2, ARIZONA_EQ2_B1_MODE, 1, 0),
193SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT, 190SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT,
194 24, 0, eq_tlv), 191 24, 0, eq_tlv),
195SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT, 192SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT,
@@ -201,6 +198,8 @@ SOC_SINGLE_TLV("EQ2 B4 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B4_GAIN_SHIFT,
201SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT, 198SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT,
202 24, 0, eq_tlv), 199 24, 0, eq_tlv),
203 200
201SND_SOC_BYTES("EQ3 Coefficients", ARIZONA_EQ3_3, 19),
202SOC_SINGLE("EQ3 Mode Switch", ARIZONA_EQ3_2, ARIZONA_EQ3_B1_MODE, 1, 0),
204SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT, 203SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT,
205 24, 0, eq_tlv), 204 24, 0, eq_tlv),
206SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT, 205SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT,
@@ -212,6 +211,8 @@ SOC_SINGLE_TLV("EQ3 B4 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B4_GAIN_SHIFT,
212SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT, 211SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT,
213 24, 0, eq_tlv), 212 24, 0, eq_tlv),
214 213
214SND_SOC_BYTES("EQ4 Coefficients", ARIZONA_EQ4_3, 19),
215SOC_SINGLE("EQ4 Mode Switch", ARIZONA_EQ4_2, ARIZONA_EQ4_B1_MODE, 1, 0),
215SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT, 216SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT,
216 24, 0, eq_tlv), 217 24, 0, eq_tlv),
217SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT, 218SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT,
@@ -1052,9 +1053,7 @@ static int wm8997_codec_probe(struct snd_soc_codec *codec)
1052 struct wm8997_priv *priv = snd_soc_codec_get_drvdata(codec); 1053 struct wm8997_priv *priv = snd_soc_codec_get_drvdata(codec);
1053 int ret; 1054 int ret;
1054 1055
1055 codec->control_data = priv->core.arizona->regmap; 1056 ret = snd_soc_codec_set_cache_io(codec, priv->core.arizona->regmap);
1056
1057 ret = snd_soc_codec_set_cache_io(codec, 32, 16, SND_SOC_REGMAP);
1058 if (ret != 0) 1057 if (ret != 0)
1059 return ret; 1058 return ret;
1060 1059
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c
index 0982c1d38ec4..d18eff31fbbc 100644
--- a/sound/soc/codecs/wm9081.c
+++ b/sound/soc/codecs/wm9081.c
@@ -268,8 +268,7 @@ static const char *drc_high_text[] = {
268 "0", 268 "0",
269}; 269};
270 270
271static const struct soc_enum drc_high = 271static SOC_ENUM_SINGLE_DECL(drc_high, WM9081_DRC_3, 3, drc_high_text);
272 SOC_ENUM_SINGLE(WM9081_DRC_3, 3, 6, drc_high_text);
273 272
274static const char *drc_low_text[] = { 273static const char *drc_low_text[] = {
275 "1", 274 "1",
@@ -279,8 +278,7 @@ static const char *drc_low_text[] = {
279 "0", 278 "0",
280}; 279};
281 280
282static const struct soc_enum drc_low = 281static SOC_ENUM_SINGLE_DECL(drc_low, WM9081_DRC_3, 0, drc_low_text);
283 SOC_ENUM_SINGLE(WM9081_DRC_3, 0, 5, drc_low_text);
284 282
285static const char *drc_atk_text[] = { 283static const char *drc_atk_text[] = {
286 "181us", 284 "181us",
@@ -297,8 +295,7 @@ static const char *drc_atk_text[] = {
297 "185.6ms", 295 "185.6ms",
298}; 296};
299 297
300static const struct soc_enum drc_atk = 298static SOC_ENUM_SINGLE_DECL(drc_atk, WM9081_DRC_2, 12, drc_atk_text);
301 SOC_ENUM_SINGLE(WM9081_DRC_2, 12, 12, drc_atk_text);
302 299
303static const char *drc_dcy_text[] = { 300static const char *drc_dcy_text[] = {
304 "186ms", 301 "186ms",
@@ -312,8 +309,7 @@ static const char *drc_dcy_text[] = {
312 "47.56s", 309 "47.56s",
313}; 310};
314 311
315static const struct soc_enum drc_dcy = 312static SOC_ENUM_SINGLE_DECL(drc_dcy, WM9081_DRC_2, 8, drc_dcy_text);
316 SOC_ENUM_SINGLE(WM9081_DRC_2, 8, 9, drc_dcy_text);
317 313
318static const char *drc_qr_dcy_text[] = { 314static const char *drc_qr_dcy_text[] = {
319 "0.725ms", 315 "0.725ms",
@@ -321,8 +317,7 @@ static const char *drc_qr_dcy_text[] = {
321 "5.8ms", 317 "5.8ms",
322}; 318};
323 319
324static const struct soc_enum drc_qr_dcy = 320static SOC_ENUM_SINGLE_DECL(drc_qr_dcy, WM9081_DRC_2, 4, drc_qr_dcy_text);
325 SOC_ENUM_SINGLE(WM9081_DRC_2, 4, 3, drc_qr_dcy_text);
326 321
327static const char *dac_deemph_text[] = { 322static const char *dac_deemph_text[] = {
328 "None", 323 "None",
@@ -331,16 +326,16 @@ static const char *dac_deemph_text[] = {
331 "48kHz", 326 "48kHz",
332}; 327};
333 328
334static const struct soc_enum dac_deemph = 329static SOC_ENUM_SINGLE_DECL(dac_deemph, WM9081_DAC_DIGITAL_2, 1,
335 SOC_ENUM_SINGLE(WM9081_DAC_DIGITAL_2, 1, 4, dac_deemph_text); 330 dac_deemph_text);
336 331
337static const char *speaker_mode_text[] = { 332static const char *speaker_mode_text[] = {
338 "Class D", 333 "Class D",
339 "Class AB", 334 "Class AB",
340}; 335};
341 336
342static const struct soc_enum speaker_mode = 337static SOC_ENUM_SINGLE_DECL(speaker_mode, WM9081_ANALOGUE_SPEAKER_2, 6,
343 SOC_ENUM_SINGLE(WM9081_ANALOGUE_SPEAKER_2, 6, 2, speaker_mode_text); 338 speaker_mode_text);
344 339
345static int speaker_mode_get(struct snd_kcontrol *kcontrol, 340static int speaker_mode_get(struct snd_kcontrol *kcontrol,
346 struct snd_ctl_elem_value *ucontrol) 341 struct snd_ctl_elem_value *ucontrol)
@@ -1265,15 +1260,6 @@ static struct snd_soc_dai_driver wm9081_dai = {
1265static int wm9081_probe(struct snd_soc_codec *codec) 1260static int wm9081_probe(struct snd_soc_codec *codec)
1266{ 1261{
1267 struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec); 1262 struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
1268 int ret;
1269
1270 codec->control_data = wm9081->regmap;
1271
1272 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
1273 if (ret != 0) {
1274 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1275 return ret;
1276 }
1277 1263
1278 /* Enable zero cross by default */ 1264 /* Enable zero cross by default */
1279 snd_soc_update_bits(codec, WM9081_ANALOGUE_LINEOUT, 1265 snd_soc_update_bits(codec, WM9081_ANALOGUE_LINEOUT,
@@ -1288,7 +1274,7 @@ static int wm9081_probe(struct snd_soc_codec *codec)
1288 ARRAY_SIZE(wm9081_eq_controls)); 1274 ARRAY_SIZE(wm9081_eq_controls));
1289 } 1275 }
1290 1276
1291 return ret; 1277 return 0;
1292} 1278}
1293 1279
1294static int wm9081_remove(struct snd_soc_codec *codec) 1280static int wm9081_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c
index a07fe1618eec..87934171f063 100644
--- a/sound/soc/codecs/wm9090.c
+++ b/sound/soc/codecs/wm9090.c
@@ -522,16 +522,6 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec,
522 522
523static int wm9090_probe(struct snd_soc_codec *codec) 523static int wm9090_probe(struct snd_soc_codec *codec)
524{ 524{
525 struct wm9090_priv *wm9090 = dev_get_drvdata(codec->dev);
526 int ret;
527
528 codec->control_data = wm9090->regmap;
529 ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP);
530 if (ret != 0) {
531 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
532 return ret;
533 }
534
535 /* Configure some defaults; they will be written out when we 525 /* Configure some defaults; they will be written out when we
536 * bring the bias up. 526 * bring the bias up.
537 */ 527 */
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c
index 70ce6793c5bd..c0b7f45dfa37 100644
--- a/sound/soc/codecs/wm9705.c
+++ b/sound/soc/codecs/wm9705.c
@@ -67,12 +67,12 @@ static const char *wm9705_mic[] = {"Mic 1", "Mic 2"};
67static const char *wm9705_rec_sel[] = {"Mic", "CD", "NC", "NC", 67static const char *wm9705_rec_sel[] = {"Mic", "CD", "NC", "NC",
68 "Line", "Stereo Mix", "Mono Mix", "Phone"}; 68 "Line", "Stereo Mix", "Mono Mix", "Phone"};
69 69
70static const struct soc_enum wm9705_enum_mic = 70static SOC_ENUM_SINGLE_DECL(wm9705_enum_mic,
71 SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 8, 2, wm9705_mic); 71 AC97_GENERAL_PURPOSE, 8, wm9705_mic);
72static const struct soc_enum wm9705_enum_rec_l = 72static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_l,
73 SOC_ENUM_SINGLE(AC97_REC_SEL, 8, 8, wm9705_rec_sel); 73 AC97_REC_SEL, 8, wm9705_rec_sel);
74static const struct soc_enum wm9705_enum_rec_r = 74static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_r,
75 SOC_ENUM_SINGLE(AC97_REC_SEL, 0, 8, wm9705_rec_sel); 75 AC97_REC_SEL, 0, wm9705_rec_sel);
76 76
77/* Headphone Mixer */ 77/* Headphone Mixer */
78static const struct snd_kcontrol_new wm9705_hp_mixer_controls[] = { 78static const struct snd_kcontrol_new wm9705_hp_mixer_controls[] = {
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index 444626fcab40..bb5f7b4e3ebb 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -684,24 +684,38 @@ static int wm_adsp_load(struct wm_adsp *dsp)
684 } 684 }
685 685
686 if (reg) { 686 if (reg) {
687 buf = wm_adsp_buf_alloc(region->data, 687 size_t to_write = PAGE_SIZE;
688 le32_to_cpu(region->len), 688 size_t remain = le32_to_cpu(region->len);
689 &buf_list); 689 const u8 *data = region->data;
690 if (!buf) { 690
691 adsp_err(dsp, "Out of memory\n"); 691 while (remain > 0) {
692 ret = -ENOMEM; 692 if (remain < PAGE_SIZE)
693 goto out_fw; 693 to_write = remain;
694 } 694
695 buf = wm_adsp_buf_alloc(data,
696 to_write,
697 &buf_list);
698 if (!buf) {
699 adsp_err(dsp, "Out of memory\n");
700 ret = -ENOMEM;
701 goto out_fw;
702 }
695 703
696 ret = regmap_raw_write_async(regmap, reg, buf->buf, 704 ret = regmap_raw_write_async(regmap, reg,
697 le32_to_cpu(region->len)); 705 buf->buf,
698 if (ret != 0) { 706 to_write);
699 adsp_err(dsp, 707 if (ret != 0) {
700 "%s.%d: Failed to write %d bytes at %d in %s: %d\n", 708 adsp_err(dsp,
701 file, regions, 709 "%s.%d: Failed to write %zd bytes at %d in %s: %d\n",
702 le32_to_cpu(region->len), offset, 710 file, regions,
703 region_name, ret); 711 to_write, offset,
704 goto out_fw; 712 region_name, ret);
713 goto out_fw;
714 }
715
716 data += to_write;
717 reg += to_write / 2;
718 remain -= to_write;
705 } 719 }
706 } 720 }
707 721
@@ -1679,6 +1693,8 @@ int wm_adsp2_event(struct snd_soc_dapm_widget *w,
1679 list_del(&alg_region->list); 1693 list_del(&alg_region->list);
1680 kfree(alg_region); 1694 kfree(alg_region);
1681 } 1695 }
1696
1697 adsp_dbg(dsp, "Shutdown complete\n");
1682 break; 1698 break;
1683 1699
1684 default: 1700 default:
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c
index b371066dd5bc..b6209662ab13 100644
--- a/sound/soc/codecs/wm_hubs.c
+++ b/sound/soc/codecs/wm_hubs.c
@@ -50,16 +50,16 @@ static const char *speaker_ref_text[] = {
50 "VMID", 50 "VMID",
51}; 51};
52 52
53static const struct soc_enum speaker_ref = 53static SOC_ENUM_SINGLE_DECL(speaker_ref,
54 SOC_ENUM_SINGLE(WM8993_SPEAKER_MIXER, 8, 2, speaker_ref_text); 54 WM8993_SPEAKER_MIXER, 8, speaker_ref_text);
55 55
56static const char *speaker_mode_text[] = { 56static const char *speaker_mode_text[] = {
57 "Class D", 57 "Class D",
58 "Class AB", 58 "Class AB",
59}; 59};
60 60
61static const struct soc_enum speaker_mode = 61static SOC_ENUM_SINGLE_DECL(speaker_mode,
62 SOC_ENUM_SINGLE(WM8993_SPKMIXR_ATTENUATION, 8, 2, speaker_mode_text); 62 WM8993_SPKMIXR_ATTENUATION, 8, speaker_mode_text);
63 63
64static void wait_for_dc_servo(struct snd_soc_codec *codec, unsigned int op) 64static void wait_for_dc_servo(struct snd_soc_codec *codec, unsigned int op)
65{ 65{
@@ -735,15 +735,15 @@ static const char *hp_mux_text[] = {
735 "DAC", 735 "DAC",
736}; 736};
737 737
738static const struct soc_enum hpl_enum = 738static SOC_ENUM_SINGLE_DECL(hpl_enum,
739 SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER1, 8, 2, hp_mux_text); 739 WM8993_OUTPUT_MIXER1, 8, hp_mux_text);
740 740
741const struct snd_kcontrol_new wm_hubs_hpl_mux = 741const struct snd_kcontrol_new wm_hubs_hpl_mux =
742 WM_HUBS_ENUM_W("Left Headphone Mux", hpl_enum); 742 WM_HUBS_ENUM_W("Left Headphone Mux", hpl_enum);
743EXPORT_SYMBOL_GPL(wm_hubs_hpl_mux); 743EXPORT_SYMBOL_GPL(wm_hubs_hpl_mux);
744 744
745static const struct soc_enum hpr_enum = 745static SOC_ENUM_SINGLE_DECL(hpr_enum,
746 SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER2, 8, 2, hp_mux_text); 746 WM8993_OUTPUT_MIXER2, 8, hp_mux_text);
747 747
748const struct snd_kcontrol_new wm_hubs_hpr_mux = 748const struct snd_kcontrol_new wm_hubs_hpr_mux =
749 WM_HUBS_ENUM_W("Right Headphone Mux", hpr_enum); 749 WM_HUBS_ENUM_W("Right Headphone Mux", hpr_enum);
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index 5e3bc3c6801a..cab98a580053 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -17,6 +17,7 @@
17#include <linux/platform_data/edma.h> 17#include <linux/platform_data/edma.h>
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/of_platform.h> 19#include <linux/of_platform.h>
20#include <linux/clk.h>
20#include <sound/core.h> 21#include <sound/core.h>
21#include <sound/pcm.h> 22#include <sound/pcm.h>
22#include <sound/soc.h> 23#include <sound/soc.h>
@@ -30,9 +31,34 @@
30#include "davinci-i2s.h" 31#include "davinci-i2s.h"
31 32
32struct snd_soc_card_drvdata_davinci { 33struct snd_soc_card_drvdata_davinci {
34 struct clk *mclk;
33 unsigned sysclk; 35 unsigned sysclk;
34}; 36};
35 37
38static int evm_startup(struct snd_pcm_substream *substream)
39{
40 struct snd_soc_pcm_runtime *rtd = substream->private_data;
41 struct snd_soc_card *soc_card = rtd->codec->card;
42 struct snd_soc_card_drvdata_davinci *drvdata =
43 snd_soc_card_get_drvdata(soc_card);
44
45 if (drvdata->mclk)
46 return clk_prepare_enable(drvdata->mclk);
47
48 return 0;
49}
50
51static void evm_shutdown(struct snd_pcm_substream *substream)
52{
53 struct snd_soc_pcm_runtime *rtd = substream->private_data;
54 struct snd_soc_card *soc_card = rtd->codec->card;
55 struct snd_soc_card_drvdata_davinci *drvdata =
56 snd_soc_card_get_drvdata(soc_card);
57
58 if (drvdata->mclk)
59 clk_disable_unprepare(drvdata->mclk);
60}
61
36static int evm_hw_params(struct snd_pcm_substream *substream, 62static int evm_hw_params(struct snd_pcm_substream *substream,
37 struct snd_pcm_hw_params *params) 63 struct snd_pcm_hw_params *params)
38{ 64{
@@ -59,6 +85,8 @@ static int evm_hw_params(struct snd_pcm_substream *substream,
59} 85}
60 86
61static struct snd_soc_ops evm_ops = { 87static struct snd_soc_ops evm_ops = {
88 .startup = evm_startup,
89 .shutdown = evm_shutdown,
62 .hw_params = evm_hw_params, 90 .hw_params = evm_hw_params,
63}; 91};
64 92
@@ -95,35 +123,29 @@ static const struct snd_soc_dapm_route audio_map[] = {
95/* Logic for a aic3x as connected on a davinci-evm */ 123/* Logic for a aic3x as connected on a davinci-evm */
96static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd) 124static int evm_aic3x_init(struct snd_soc_pcm_runtime *rtd)
97{ 125{
126 struct snd_soc_card *card = rtd->card;
98 struct snd_soc_codec *codec = rtd->codec; 127 struct snd_soc_codec *codec = rtd->codec;
99 struct snd_soc_dapm_context *dapm = &codec->dapm;
100 struct device_node *np = codec->card->dev->of_node; 128 struct device_node *np = codec->card->dev->of_node;
101 int ret; 129 int ret;
102 130
103 /* Add davinci-evm specific widgets */ 131 /* Add davinci-evm specific widgets */
104 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets, 132 snd_soc_dapm_new_controls(&card->dapm, aic3x_dapm_widgets,
105 ARRAY_SIZE(aic3x_dapm_widgets)); 133 ARRAY_SIZE(aic3x_dapm_widgets));
106 134
107 if (np) { 135 if (np) {
108 ret = snd_soc_of_parse_audio_routing(codec->card, 136 ret = snd_soc_of_parse_audio_routing(card, "ti,audio-routing");
109 "ti,audio-routing");
110 if (ret) 137 if (ret)
111 return ret; 138 return ret;
112 } else { 139 } else {
113 /* Set up davinci-evm specific audio path audio_map */ 140 /* Set up davinci-evm specific audio path audio_map */
114 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); 141 snd_soc_dapm_add_routes(&card->dapm, audio_map,
142 ARRAY_SIZE(audio_map));
115 } 143 }
116 144
117 /* not connected */ 145 /* not connected */
118 snd_soc_dapm_disable_pin(dapm, "MONO_LOUT"); 146 snd_soc_dapm_nc_pin(&codec->dapm, "MONO_LOUT");
119 snd_soc_dapm_disable_pin(dapm, "HPLCOM"); 147 snd_soc_dapm_nc_pin(&codec->dapm, "HPLCOM");
120 snd_soc_dapm_disable_pin(dapm, "HPRCOM"); 148 snd_soc_dapm_nc_pin(&codec->dapm, "HPRCOM");
121
122 /* always connected */
123 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
124 snd_soc_dapm_enable_pin(dapm, "Line Out");
125 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
126 snd_soc_dapm_enable_pin(dapm, "Line In");
127 149
128 return 0; 150 return 0;
129} 151}
@@ -348,6 +370,7 @@ static int davinci_evm_probe(struct platform_device *pdev)
348 of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev); 370 of_match_device(of_match_ptr(davinci_evm_dt_ids), &pdev->dev);
349 struct snd_soc_dai_link *dai = (struct snd_soc_dai_link *) match->data; 371 struct snd_soc_dai_link *dai = (struct snd_soc_dai_link *) match->data;
350 struct snd_soc_card_drvdata_davinci *drvdata = NULL; 372 struct snd_soc_card_drvdata_davinci *drvdata = NULL;
373 struct clk *mclk;
351 int ret = 0; 374 int ret = 0;
352 375
353 evm_soc_card.dai_link = dai; 376 evm_soc_card.dai_link = dai;
@@ -367,13 +390,38 @@ static int davinci_evm_probe(struct platform_device *pdev)
367 if (ret) 390 if (ret)
368 return ret; 391 return ret;
369 392
393 mclk = devm_clk_get(&pdev->dev, "mclk");
394 if (PTR_ERR(mclk) == -EPROBE_DEFER) {
395 return -EPROBE_DEFER;
396 } else if (IS_ERR(mclk)) {
397 dev_dbg(&pdev->dev, "mclk not found.\n");
398 mclk = NULL;
399 }
400
370 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL); 401 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
371 if (!drvdata) 402 if (!drvdata)
372 return -ENOMEM; 403 return -ENOMEM;
373 404
405 drvdata->mclk = mclk;
406
374 ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk); 407 ret = of_property_read_u32(np, "ti,codec-clock-rate", &drvdata->sysclk);
375 if (ret < 0) 408
376 return -EINVAL; 409 if (ret < 0) {
410 if (!drvdata->mclk) {
411 dev_err(&pdev->dev,
412 "No clock or clock rate defined.\n");
413 return -EINVAL;
414 }
415 drvdata->sysclk = clk_get_rate(drvdata->mclk);
416 } else if (drvdata->mclk) {
417 unsigned int requestd_rate = drvdata->sysclk;
418 clk_set_rate(drvdata->mclk, drvdata->sysclk);
419 drvdata->sysclk = clk_get_rate(drvdata->mclk);
420 if (drvdata->sysclk != requestd_rate)
421 dev_warn(&pdev->dev,
422 "Could not get requested rate %u using %u.\n",
423 requestd_rate, drvdata->sysclk);
424 }
377 425
378 snd_soc_card_set_drvdata(&evm_soc_card, drvdata); 426 snd_soc_card_set_drvdata(&evm_soc_card, drvdata);
379 ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card); 427 ret = devm_snd_soc_register_card(&pdev->dev, &evm_soc_card);
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 670afa29e30d..a01ae97c90aa 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -37,6 +37,16 @@
37#include "davinci-pcm.h" 37#include "davinci-pcm.h"
38#include "davinci-mcasp.h" 38#include "davinci-mcasp.h"
39 39
40struct davinci_mcasp_context {
41 u32 txfmtctl;
42 u32 rxfmtctl;
43 u32 txfmt;
44 u32 rxfmt;
45 u32 aclkxctl;
46 u32 aclkrctl;
47 u32 pdir;
48};
49
40struct davinci_mcasp { 50struct davinci_mcasp {
41 struct davinci_pcm_dma_params dma_params[2]; 51 struct davinci_pcm_dma_params dma_params[2];
42 struct snd_dmaengine_dai_dma_data dma_data[2]; 52 struct snd_dmaengine_dai_dma_data dma_data[2];
@@ -53,6 +63,9 @@ struct davinci_mcasp {
53 u16 bclk_lrclk_ratio; 63 u16 bclk_lrclk_ratio;
54 int streams; 64 int streams;
55 65
66 int sysclk_freq;
67 bool bclk_master;
68
56 /* McASP FIFO related */ 69 /* McASP FIFO related */
57 u8 txnumevt; 70 u8 txnumevt;
58 u8 rxnumevt; 71 u8 rxnumevt;
@@ -60,15 +73,7 @@ struct davinci_mcasp {
60 bool dat_port; 73 bool dat_port;
61 74
62#ifdef CONFIG_PM_SLEEP 75#ifdef CONFIG_PM_SLEEP
63 struct { 76 struct davinci_mcasp_context context;
64 u32 txfmtctl;
65 u32 rxfmtctl;
66 u32 txfmt;
67 u32 rxfmt;
68 u32 aclkxctl;
69 u32 aclkrctl;
70 u32 pdir;
71 } context;
72#endif 77#endif
73}; 78};
74 79
@@ -294,6 +299,7 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
294 299
295 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR); 300 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR);
296 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR); 301 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR);
302 mcasp->bclk_master = 1;
297 break; 303 break;
298 case SND_SOC_DAIFMT_CBM_CFS: 304 case SND_SOC_DAIFMT_CBM_CFS:
299 /* codec is clock master and frame slave */ 305 /* codec is clock master and frame slave */
@@ -305,6 +311,7 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
305 311
306 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR); 312 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR);
307 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR); 313 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR);
314 mcasp->bclk_master = 0;
308 break; 315 break;
309 case SND_SOC_DAIFMT_CBM_CFM: 316 case SND_SOC_DAIFMT_CBM_CFM:
310 /* codec is clock and frame master */ 317 /* codec is clock and frame master */
@@ -316,6 +323,7 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
316 323
317 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, 324 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG,
318 ACLKX | AHCLKX | AFSX | ACLKR | AHCLKR | AFSR); 325 ACLKX | AHCLKX | AFSX | ACLKR | AHCLKR | AFSR);
326 mcasp->bclk_master = 0;
319 break; 327 break;
320 328
321 default: 329 default:
@@ -410,6 +418,8 @@ static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id,
410 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AHCLKX); 418 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AHCLKX);
411 } 419 }
412 420
421 mcasp->sysclk_freq = freq;
422
413 return 0; 423 return 0;
414} 424}
415 425
@@ -603,20 +613,23 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
603 u8 fifo_level; 613 u8 fifo_level;
604 u8 slots = mcasp->tdm_slots; 614 u8 slots = mcasp->tdm_slots;
605 u8 active_serializers; 615 u8 active_serializers;
606 int channels; 616 int channels = params_channels(params);
607 int ret; 617 int ret;
608 struct snd_interval *pcm_channels = hw_param_interval(params,
609 SNDRV_PCM_HW_PARAM_CHANNELS);
610 channels = pcm_channels->min;
611 618
612 active_serializers = (channels + slots - 1) / slots; 619 /* If mcasp is BCLK master we need to set BCLK divider */
620 if (mcasp->bclk_master) {
621 unsigned int bclk_freq = snd_soc_params_to_bclk(params);
622 if (mcasp->sysclk_freq % bclk_freq != 0) {
623 dev_err(mcasp->dev, "Can't produce requred BCLK\n");
624 return -EINVAL;
625 }
626 davinci_mcasp_set_clkdiv(
627 cpu_dai, 1, mcasp->sysclk_freq / bclk_freq);
628 }
613 629
614 if (mcasp_common_hw_param(mcasp, substream->stream, channels) == -EINVAL) 630 ret = mcasp_common_hw_param(mcasp, substream->stream, channels);
615 return -EINVAL; 631 if (ret)
616 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 632 return ret;
617 fifo_level = mcasp->txnumevt * active_serializers;
618 else
619 fifo_level = mcasp->rxnumevt * active_serializers;
620 633
621 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE) 634 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
622 ret = mcasp_dit_hw_param(mcasp); 635 ret = mcasp_dit_hw_param(mcasp);
@@ -658,6 +671,13 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
658 return -EINVAL; 671 return -EINVAL;
659 } 672 }
660 673
674 /* Calculate FIFO level */
675 active_serializers = (channels + slots - 1) / slots;
676 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
677 fifo_level = mcasp->txnumevt * active_serializers;
678 else
679 fifo_level = mcasp->rxnumevt * active_serializers;
680
661 if (mcasp->version == MCASP_VERSION_2 && !fifo_level) 681 if (mcasp->version == MCASP_VERSION_2 && !fifo_level)
662 dma_params->acnt = 4; 682 dma_params->acnt = 4;
663 else 683 else
@@ -719,6 +739,43 @@ static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
719 .set_sysclk = davinci_mcasp_set_sysclk, 739 .set_sysclk = davinci_mcasp_set_sysclk,
720}; 740};
721 741
742#ifdef CONFIG_PM_SLEEP
743static int davinci_mcasp_suspend(struct snd_soc_dai *dai)
744{
745 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
746 struct davinci_mcasp_context *context = &mcasp->context;
747
748 context->txfmtctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG);
749 context->rxfmtctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
750 context->txfmt = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXFMT_REG);
751 context->rxfmt = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMT_REG);
752 context->aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG);
753 context->aclkrctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKRCTL_REG);
754 context->pdir = mcasp_get_reg(mcasp, DAVINCI_MCASP_PDIR_REG);
755
756 return 0;
757}
758
759static int davinci_mcasp_resume(struct snd_soc_dai *dai)
760{
761 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
762 struct davinci_mcasp_context *context = &mcasp->context;
763
764 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG, context->txfmtctl);
765 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG, context->rxfmtctl);
766 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMT_REG, context->txfmt);
767 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXFMT_REG, context->rxfmt);
768 mcasp_set_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, context->aclkxctl);
769 mcasp_set_reg(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, context->aclkrctl);
770 mcasp_set_reg(mcasp, DAVINCI_MCASP_PDIR_REG, context->pdir);
771
772 return 0;
773}
774#else
775#define davinci_mcasp_suspend NULL
776#define davinci_mcasp_resume NULL
777#endif
778
722#define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_192000 779#define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_192000
723 780
724#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \ 781#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \
@@ -735,6 +792,8 @@ static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
735static struct snd_soc_dai_driver davinci_mcasp_dai[] = { 792static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
736 { 793 {
737 .name = "davinci-mcasp.0", 794 .name = "davinci-mcasp.0",
795 .suspend = davinci_mcasp_suspend,
796 .resume = davinci_mcasp_resume,
738 .playback = { 797 .playback = {
739 .channels_min = 2, 798 .channels_min = 2,
740 .channels_max = 32 * 16, 799 .channels_max = 32 * 16,
@@ -768,28 +827,28 @@ static const struct snd_soc_component_driver davinci_mcasp_component = {
768}; 827};
769 828
770/* Some HW specific values and defaults. The rest is filled in from DT. */ 829/* Some HW specific values and defaults. The rest is filled in from DT. */
771static struct snd_platform_data dm646x_mcasp_pdata = { 830static struct davinci_mcasp_pdata dm646x_mcasp_pdata = {
772 .tx_dma_offset = 0x400, 831 .tx_dma_offset = 0x400,
773 .rx_dma_offset = 0x400, 832 .rx_dma_offset = 0x400,
774 .asp_chan_q = EVENTQ_0, 833 .asp_chan_q = EVENTQ_0,
775 .version = MCASP_VERSION_1, 834 .version = MCASP_VERSION_1,
776}; 835};
777 836
778static struct snd_platform_data da830_mcasp_pdata = { 837static struct davinci_mcasp_pdata da830_mcasp_pdata = {
779 .tx_dma_offset = 0x2000, 838 .tx_dma_offset = 0x2000,
780 .rx_dma_offset = 0x2000, 839 .rx_dma_offset = 0x2000,
781 .asp_chan_q = EVENTQ_0, 840 .asp_chan_q = EVENTQ_0,
782 .version = MCASP_VERSION_2, 841 .version = MCASP_VERSION_2,
783}; 842};
784 843
785static struct snd_platform_data am33xx_mcasp_pdata = { 844static struct davinci_mcasp_pdata am33xx_mcasp_pdata = {
786 .tx_dma_offset = 0, 845 .tx_dma_offset = 0,
787 .rx_dma_offset = 0, 846 .rx_dma_offset = 0,
788 .asp_chan_q = EVENTQ_0, 847 .asp_chan_q = EVENTQ_0,
789 .version = MCASP_VERSION_3, 848 .version = MCASP_VERSION_3,
790}; 849};
791 850
792static struct snd_platform_data dra7_mcasp_pdata = { 851static struct davinci_mcasp_pdata dra7_mcasp_pdata = {
793 .tx_dma_offset = 0x200, 852 .tx_dma_offset = 0x200,
794 .rx_dma_offset = 0x284, 853 .rx_dma_offset = 0x284,
795 .asp_chan_q = EVENTQ_0, 854 .asp_chan_q = EVENTQ_0,
@@ -857,11 +916,11 @@ err1:
857 return ret; 916 return ret;
858} 917}
859 918
860static struct snd_platform_data *davinci_mcasp_set_pdata_from_of( 919static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
861 struct platform_device *pdev) 920 struct platform_device *pdev)
862{ 921{
863 struct device_node *np = pdev->dev.of_node; 922 struct device_node *np = pdev->dev.of_node;
864 struct snd_platform_data *pdata = NULL; 923 struct davinci_mcasp_pdata *pdata = NULL;
865 const struct of_device_id *match = 924 const struct of_device_id *match =
866 of_match_device(mcasp_dt_ids, &pdev->dev); 925 of_match_device(mcasp_dt_ids, &pdev->dev);
867 struct of_phandle_args dma_spec; 926 struct of_phandle_args dma_spec;
@@ -874,7 +933,7 @@ static struct snd_platform_data *davinci_mcasp_set_pdata_from_of(
874 pdata = pdev->dev.platform_data; 933 pdata = pdev->dev.platform_data;
875 return pdata; 934 return pdata;
876 } else if (match) { 935 } else if (match) {
877 pdata = (struct snd_platform_data *) match->data; 936 pdata = (struct davinci_mcasp_pdata*) match->data;
878 } else { 937 } else {
879 /* control shouldn't reach here. something is wrong */ 938 /* control shouldn't reach here. something is wrong */
880 ret = -EINVAL; 939 ret = -EINVAL;
@@ -966,9 +1025,10 @@ nodata:
966 1025
967static int davinci_mcasp_probe(struct platform_device *pdev) 1026static int davinci_mcasp_probe(struct platform_device *pdev)
968{ 1027{
969 struct davinci_pcm_dma_params *dma_data; 1028 struct davinci_pcm_dma_params *dma_params;
1029 struct snd_dmaengine_dai_dma_data *dma_data;
970 struct resource *mem, *ioarea, *res, *dat; 1030 struct resource *mem, *ioarea, *res, *dat;
971 struct snd_platform_data *pdata; 1031 struct davinci_mcasp_pdata *pdata;
972 struct davinci_mcasp *mcasp; 1032 struct davinci_mcasp *mcasp;
973 int ret; 1033 int ret;
974 1034
@@ -1035,41 +1095,49 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1035 if (dat) 1095 if (dat)
1036 mcasp->dat_port = true; 1096 mcasp->dat_port = true;
1037 1097
1038 dma_data = &mcasp->dma_params[SNDRV_PCM_STREAM_PLAYBACK]; 1098 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
1039 dma_data->asp_chan_q = pdata->asp_chan_q; 1099 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
1040 dma_data->ram_chan_q = pdata->ram_chan_q; 1100 dma_params->asp_chan_q = pdata->asp_chan_q;
1041 dma_data->sram_pool = pdata->sram_pool; 1101 dma_params->ram_chan_q = pdata->ram_chan_q;
1042 dma_data->sram_size = pdata->sram_size_playback; 1102 dma_params->sram_pool = pdata->sram_pool;
1103 dma_params->sram_size = pdata->sram_size_playback;
1043 if (dat) 1104 if (dat)
1044 dma_data->dma_addr = dat->start; 1105 dma_params->dma_addr = dat->start;
1045 else 1106 else
1046 dma_data->dma_addr = mem->start + pdata->tx_dma_offset; 1107 dma_params->dma_addr = mem->start + pdata->tx_dma_offset;
1047 1108
1048 /* Unconditional dmaengine stuff */ 1109 /* Unconditional dmaengine stuff */
1049 mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr = dma_data->dma_addr; 1110 dma_data->addr = dma_params->dma_addr;
1050 1111
1051 res = platform_get_resource(pdev, IORESOURCE_DMA, 0); 1112 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1052 if (res) 1113 if (res)
1053 dma_data->channel = res->start; 1114 dma_params->channel = res->start;
1054 else 1115 else
1055 dma_data->channel = pdata->tx_dma_channel; 1116 dma_params->channel = pdata->tx_dma_channel;
1056 1117
1057 dma_data = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE]; 1118 /* dmaengine filter data for DT and non-DT boot */
1058 dma_data->asp_chan_q = pdata->asp_chan_q; 1119 if (pdev->dev.of_node)
1059 dma_data->ram_chan_q = pdata->ram_chan_q; 1120 dma_data->filter_data = "tx";
1060 dma_data->sram_pool = pdata->sram_pool; 1121 else
1061 dma_data->sram_size = pdata->sram_size_capture; 1122 dma_data->filter_data = &dma_params->channel;
1123
1124 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE];
1125 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
1126 dma_params->asp_chan_q = pdata->asp_chan_q;
1127 dma_params->ram_chan_q = pdata->ram_chan_q;
1128 dma_params->sram_pool = pdata->sram_pool;
1129 dma_params->sram_size = pdata->sram_size_capture;
1062 if (dat) 1130 if (dat)
1063 dma_data->dma_addr = dat->start; 1131 dma_params->dma_addr = dat->start;
1064 else 1132 else
1065 dma_data->dma_addr = mem->start + pdata->rx_dma_offset; 1133 dma_params->dma_addr = mem->start + pdata->rx_dma_offset;
1066 1134
1067 /* Unconditional dmaengine stuff */ 1135 /* Unconditional dmaengine stuff */
1068 mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr = dma_data->dma_addr; 1136 dma_data->addr = dma_params->dma_addr;
1069 1137
1070 if (mcasp->version < MCASP_VERSION_3) { 1138 if (mcasp->version < MCASP_VERSION_3) {
1071 mcasp->fifo_base = DAVINCI_MCASP_V2_AFIFO_BASE; 1139 mcasp->fifo_base = DAVINCI_MCASP_V2_AFIFO_BASE;
1072 /* dma_data->dma_addr is pointing to the data port address */ 1140 /* dma_params->dma_addr is pointing to the data port address */
1073 mcasp->dat_port = true; 1141 mcasp->dat_port = true;
1074 } else { 1142 } else {
1075 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE; 1143 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE;
@@ -1077,13 +1145,15 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1077 1145
1078 res = platform_get_resource(pdev, IORESOURCE_DMA, 1); 1146 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1079 if (res) 1147 if (res)
1080 dma_data->channel = res->start; 1148 dma_params->channel = res->start;
1081 else 1149 else
1082 dma_data->channel = pdata->rx_dma_channel; 1150 dma_params->channel = pdata->rx_dma_channel;
1083 1151
1084 /* Unconditional dmaengine stuff */ 1152 /* dmaengine filter data for DT and non-DT boot */
1085 mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK].filter_data = "tx"; 1153 if (pdev->dev.of_node)
1086 mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE].filter_data = "rx"; 1154 dma_data->filter_data = "rx";
1155 else
1156 dma_data->filter_data = &dma_params->channel;
1087 1157
1088 dev_set_drvdata(&pdev->dev, mcasp); 1158 dev_set_drvdata(&pdev->dev, mcasp);
1089 1159
@@ -1127,49 +1197,12 @@ static int davinci_mcasp_remove(struct platform_device *pdev)
1127 return 0; 1197 return 0;
1128} 1198}
1129 1199
1130#ifdef CONFIG_PM_SLEEP
1131static int davinci_mcasp_suspend(struct device *dev)
1132{
1133 struct davinci_mcasp *mcasp = dev_get_drvdata(dev);
1134
1135 mcasp->context.txfmtctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG);
1136 mcasp->context.rxfmtctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
1137 mcasp->context.txfmt = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXFMT_REG);
1138 mcasp->context.rxfmt = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMT_REG);
1139 mcasp->context.aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG);
1140 mcasp->context.aclkrctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKRCTL_REG);
1141 mcasp->context.pdir = mcasp_get_reg(mcasp, DAVINCI_MCASP_PDIR_REG);
1142
1143 return 0;
1144}
1145
1146static int davinci_mcasp_resume(struct device *dev)
1147{
1148 struct davinci_mcasp *mcasp = dev_get_drvdata(dev);
1149
1150 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG, mcasp->context.txfmtctl);
1151 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG, mcasp->context.rxfmtctl);
1152 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMT_REG, mcasp->context.txfmt);
1153 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXFMT_REG, mcasp->context.rxfmt);
1154 mcasp_set_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, mcasp->context.aclkxctl);
1155 mcasp_set_reg(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, mcasp->context.aclkrctl);
1156 mcasp_set_reg(mcasp, DAVINCI_MCASP_PDIR_REG, mcasp->context.pdir);
1157
1158 return 0;
1159}
1160#endif
1161
1162SIMPLE_DEV_PM_OPS(davinci_mcasp_pm_ops,
1163 davinci_mcasp_suspend,
1164 davinci_mcasp_resume);
1165
1166static struct platform_driver davinci_mcasp_driver = { 1200static struct platform_driver davinci_mcasp_driver = {
1167 .probe = davinci_mcasp_probe, 1201 .probe = davinci_mcasp_probe,
1168 .remove = davinci_mcasp_remove, 1202 .remove = davinci_mcasp_remove,
1169 .driver = { 1203 .driver = {
1170 .name = "davinci-mcasp", 1204 .name = "davinci-mcasp",
1171 .owner = THIS_MODULE, 1205 .owner = THIS_MODULE,
1172 .pm = &davinci_mcasp_pm_ops,
1173 .of_match_table = mcasp_dt_ids, 1206 .of_match_table = mcasp_dt_ids,
1174 }, 1207 },
1175}; 1208};
diff --git a/sound/soc/davinci/edma-pcm.c b/sound/soc/davinci/edma-pcm.c
new file mode 100644
index 000000000000..d38afb1c61ae
--- /dev/null
+++ b/sound/soc/davinci/edma-pcm.c
@@ -0,0 +1,57 @@
1/*
2 * edma-pcm.c - eDMA PCM driver using dmaengine for AM3xxx, AM4xxx
3 *
4 * Copyright (C) 2014 Texas Instruments, Inc.
5 *
6 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
7 *
8 * Based on: sound/soc/tegra/tegra_pcm.c
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 */
19
20#include <linux/module.h>
21#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/pcm_params.h>
24#include <sound/soc.h>
25#include <sound/dmaengine_pcm.h>
26#include <linux/edma.h>
27
28static const struct snd_pcm_hardware edma_pcm_hardware = {
29 .info = SNDRV_PCM_INFO_MMAP |
30 SNDRV_PCM_INFO_MMAP_VALID |
31 SNDRV_PCM_INFO_BATCH |
32 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
33 SNDRV_PCM_INFO_INTERLEAVED,
34 .buffer_bytes_max = 128 * 1024,
35 .period_bytes_min = 32,
36 .period_bytes_max = 64 * 1024,
37 .periods_min = 2,
38 .periods_max = 19, /* Limit by edma dmaengine driver */
39};
40
41static const struct snd_dmaengine_pcm_config edma_dmaengine_pcm_config = {
42 .pcm_hardware = &edma_pcm_hardware,
43 .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
44 .compat_filter_fn = edma_filter_fn,
45 .prealloc_buffer_size = 128 * 1024,
46};
47
48int edma_pcm_platform_register(struct device *dev)
49{
50 return devm_snd_dmaengine_pcm_register(dev, &edma_dmaengine_pcm_config,
51 SND_DMAENGINE_PCM_FLAG_COMPAT);
52}
53EXPORT_SYMBOL_GPL(edma_pcm_platform_register);
54
55MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
56MODULE_DESCRIPTION("eDMA PCM ASoC platform driver");
57MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/edma-pcm.h b/sound/soc/davinci/edma-pcm.h
new file mode 100644
index 000000000000..894c378c0f74
--- /dev/null
+++ b/sound/soc/davinci/edma-pcm.h
@@ -0,0 +1,25 @@
1/*
2 * edma-pcm.h - eDMA PCM driver using dmaengine for AM3xxx, AM4xxx
3 *
4 * Copyright (C) 2014 Texas Instruments, Inc.
5 *
6 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
7 *
8 * Based on: sound/soc/tegra/tegra_pcm.h
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 */
19
20#ifndef __EDMA_PCM_H__
21#define __EDMA_PCM_H__
22
23int edma_pcm_platform_register(struct device *dev);
24
25#endif /* __EDMA_PCM_H__ */
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 07f8f141727d..597962ec28fa 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -1,5 +1,6 @@
1config SND_SOC_FSL_SAI 1config SND_SOC_FSL_SAI
2 tristate 2 tristate
3 select REGMAP_MMIO
3 select SND_SOC_GENERIC_DMAENGINE_PCM 4 select SND_SOC_GENERIC_DMAENGINE_PCM
4 5
5config SND_SOC_FSL_SSI 6config SND_SOC_FSL_SSI
@@ -7,9 +8,11 @@ config SND_SOC_FSL_SSI
7 8
8config SND_SOC_FSL_SPDIF 9config SND_SOC_FSL_SPDIF
9 tristate 10 tristate
11 select REGMAP_MMIO
10 12
11config SND_SOC_FSL_ESAI 13config SND_SOC_FSL_ESAI
12 tristate 14 tristate
15 select REGMAP_MMIO
13 16
14config SND_SOC_FSL_UTILS 17config SND_SOC_FSL_UTILS
15 tristate 18 tristate
@@ -168,12 +171,14 @@ config SND_SOC_EUKREA_TLV320
168 depends on MACH_EUKREA_MBIMX27_BASEBOARD \ 171 depends on MACH_EUKREA_MBIMX27_BASEBOARD \
169 || MACH_EUKREA_MBIMXSD25_BASEBOARD \ 172 || MACH_EUKREA_MBIMXSD25_BASEBOARD \
170 || MACH_EUKREA_MBIMXSD35_BASEBOARD \ 173 || MACH_EUKREA_MBIMXSD35_BASEBOARD \
171 || MACH_EUKREA_MBIMXSD51_BASEBOARD 174 || MACH_EUKREA_MBIMXSD51_BASEBOARD \
175 || (OF && ARM)
172 depends on I2C 176 depends on I2C
173 select SND_SOC_TLV320AIC23 177 select SND_SOC_TLV320AIC23_I2C
174 select SND_SOC_IMX_PCM_FIQ
175 select SND_SOC_IMX_AUDMUX 178 select SND_SOC_IMX_AUDMUX
176 select SND_SOC_IMX_SSI 179 select SND_SOC_IMX_SSI
180 select SND_SOC_FSL_SSI
181 select SND_SOC_IMX_PCM_DMA
177 help 182 help
178 Enable I2S based access to the TLV320AIC23B codec attached 183 Enable I2S based access to the TLV320AIC23B codec attached
179 to the SSI interface 184 to the SSI interface
@@ -204,7 +209,6 @@ config SND_SOC_IMX_SPDIF
204 tristate "SoC Audio support for i.MX boards with S/PDIF" 209 tristate "SoC Audio support for i.MX boards with S/PDIF"
205 select SND_SOC_IMX_PCM_DMA 210 select SND_SOC_IMX_PCM_DMA
206 select SND_SOC_FSL_SPDIF 211 select SND_SOC_FSL_SPDIF
207 select REGMAP_MMIO
208 help 212 help
209 SoC Audio support for i.MX boards with S/PDIF 213 SoC Audio support for i.MX boards with S/PDIF
210 Say Y if you want to add support for SoC audio on an i.MX board with 214 Say Y if you want to add support for SoC audio on an i.MX board with
diff --git a/sound/soc/fsl/eukrea-tlv320.c b/sound/soc/fsl/eukrea-tlv320.c
index 5983740be123..eb093d5b85c4 100644
--- a/sound/soc/fsl/eukrea-tlv320.c
+++ b/sound/soc/fsl/eukrea-tlv320.c
@@ -15,8 +15,11 @@
15 * 15 *
16 */ 16 */
17 17
18#include <linux/errno.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/moduleparam.h> 20#include <linux/moduleparam.h>
21#include <linux/of.h>
22#include <linux/of_platform.h>
20#include <linux/device.h> 23#include <linux/device.h>
21#include <linux/i2c.h> 24#include <linux/i2c.h>
22#include <sound/core.h> 25#include <sound/core.h>
@@ -26,6 +29,7 @@
26 29
27#include "../codecs/tlv320aic23.h" 30#include "../codecs/tlv320aic23.h"
28#include "imx-ssi.h" 31#include "imx-ssi.h"
32#include "fsl_ssi.h"
29#include "imx-audmux.h" 33#include "imx-audmux.h"
30 34
31#define CODEC_CLOCK 12000000 35#define CODEC_CLOCK 12000000
@@ -41,7 +45,8 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
41 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | 45 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
42 SND_SOC_DAIFMT_NB_NF | 46 SND_SOC_DAIFMT_NB_NF |
43 SND_SOC_DAIFMT_CBM_CFM); 47 SND_SOC_DAIFMT_CBM_CFM);
44 if (ret) { 48 /* fsl_ssi lacks the set_fmt ops. */
49 if (ret && ret != -ENOTSUPP) {
45 dev_err(cpu_dai->dev, 50 dev_err(cpu_dai->dev,
46 "Failed to set the cpu dai format.\n"); 51 "Failed to set the cpu dai format.\n");
47 return ret; 52 return ret;
@@ -63,11 +68,13 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
63 "Failed to set the codec sysclk.\n"); 68 "Failed to set the codec sysclk.\n");
64 return ret; 69 return ret;
65 } 70 }
71
66 snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0); 72 snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0);
67 73
68 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0, 74 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
69 SND_SOC_CLOCK_IN); 75 SND_SOC_CLOCK_IN);
70 if (ret) { 76 /* fsl_ssi lacks the set_sysclk ops */
77 if (ret && ret != -EINVAL) {
71 dev_err(cpu_dai->dev, 78 dev_err(cpu_dai->dev,
72 "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n"); 79 "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n");
73 return ret; 80 return ret;
@@ -84,14 +91,10 @@ static struct snd_soc_dai_link eukrea_tlv320_dai = {
84 .name = "tlv320aic23", 91 .name = "tlv320aic23",
85 .stream_name = "TLV320AIC23", 92 .stream_name = "TLV320AIC23",
86 .codec_dai_name = "tlv320aic23-hifi", 93 .codec_dai_name = "tlv320aic23-hifi",
87 .platform_name = "imx-ssi.0",
88 .codec_name = "tlv320aic23-codec.0-001a",
89 .cpu_dai_name = "imx-ssi.0",
90 .ops = &eukrea_tlv320_snd_ops, 94 .ops = &eukrea_tlv320_snd_ops,
91}; 95};
92 96
93static struct snd_soc_card eukrea_tlv320 = { 97static struct snd_soc_card eukrea_tlv320 = {
94 .name = "cpuimx-audio",
95 .owner = THIS_MODULE, 98 .owner = THIS_MODULE,
96 .dai_link = &eukrea_tlv320_dai, 99 .dai_link = &eukrea_tlv320_dai,
97 .num_links = 1, 100 .num_links = 1,
@@ -101,8 +104,65 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
101{ 104{
102 int ret; 105 int ret;
103 int int_port = 0, ext_port; 106 int int_port = 0, ext_port;
107 struct device_node *np = pdev->dev.of_node;
108 struct device_node *ssi_np, *codec_np;
104 109
105 if (machine_is_eukrea_cpuimx27()) { 110 eukrea_tlv320.dev = &pdev->dev;
111 if (np) {
112 ret = snd_soc_of_parse_card_name(&eukrea_tlv320,
113 "eukrea,model");
114 if (ret) {
115 dev_err(&pdev->dev,
116 "eukrea,model node missing or invalid.\n");
117 goto err;
118 }
119
120 ssi_np = of_parse_phandle(pdev->dev.of_node,
121 "ssi-controller", 0);
122 if (!ssi_np) {
123 dev_err(&pdev->dev,
124 "ssi-controller missing or invalid.\n");
125 ret = -ENODEV;
126 goto err;
127 }
128
129 codec_np = of_parse_phandle(ssi_np, "codec-handle", 0);
130 if (codec_np)
131 eukrea_tlv320_dai.codec_of_node = codec_np;
132 else
133 dev_err(&pdev->dev, "codec-handle node missing or invalid.\n");
134
135 ret = of_property_read_u32(np, "fsl,mux-int-port", &int_port);
136 if (ret) {
137 dev_err(&pdev->dev,
138 "fsl,mux-int-port node missing or invalid.\n");
139 return ret;
140 }
141 ret = of_property_read_u32(np, "fsl,mux-ext-port", &ext_port);
142 if (ret) {
143 dev_err(&pdev->dev,
144 "fsl,mux-ext-port node missing or invalid.\n");
145 return ret;
146 }
147
148 /*
149 * The port numbering in the hardware manual starts at 1, while
150 * the audmux API expects it starts at 0.
151 */
152 int_port--;
153 ext_port--;
154
155 eukrea_tlv320_dai.cpu_of_node = ssi_np;
156 eukrea_tlv320_dai.platform_of_node = ssi_np;
157 } else {
158 eukrea_tlv320_dai.cpu_dai_name = "imx-ssi.0";
159 eukrea_tlv320_dai.platform_name = "imx-ssi.0";
160 eukrea_tlv320_dai.codec_name = "tlv320aic23-codec.0-001a";
161 eukrea_tlv320.name = "cpuimx-audio";
162 }
163
164 if (machine_is_eukrea_cpuimx27() ||
165 of_find_compatible_node(NULL, NULL, "fsl,imx21-audmux")) {
106 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0, 166 imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
107 IMX_AUDMUX_V1_PCR_SYN | 167 IMX_AUDMUX_V1_PCR_SYN |
108 IMX_AUDMUX_V1_PCR_TFSDIR | 168 IMX_AUDMUX_V1_PCR_TFSDIR |
@@ -119,8 +179,12 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
119 ); 179 );
120 } else if (machine_is_eukrea_cpuimx25sd() || 180 } else if (machine_is_eukrea_cpuimx25sd() ||
121 machine_is_eukrea_cpuimx35sd() || 181 machine_is_eukrea_cpuimx35sd() ||
122 machine_is_eukrea_cpuimx51sd()) { 182 machine_is_eukrea_cpuimx51sd() ||
123 ext_port = machine_is_eukrea_cpuimx25sd() ? 4 : 3; 183 of_find_compatible_node(NULL, NULL, "fsl,imx31-audmux")) {
184 if (!np)
185 ext_port = machine_is_eukrea_cpuimx25sd() ?
186 4 : 3;
187
124 imx_audmux_v2_configure_port(int_port, 188 imx_audmux_v2_configure_port(int_port,
125 IMX_AUDMUX_V2_PTCR_SYN | 189 IMX_AUDMUX_V2_PTCR_SYN |
126 IMX_AUDMUX_V2_PTCR_TFSDIR | 190 IMX_AUDMUX_V2_PTCR_TFSDIR |
@@ -134,14 +198,27 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
134 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port) 198 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port)
135 ); 199 );
136 } else { 200 } else {
137 /* return happy. We might run on a totally different machine */ 201 if (np) {
138 return 0; 202 /* The eukrea,asoc-tlv320 driver was explicitely
203 * requested (through the device tree).
204 */
205 dev_err(&pdev->dev,
206 "Missing or invalid audmux DT node.\n");
207 return -ENODEV;
208 } else {
209 /* Return happy.
210 * We might run on a totally different machine.
211 */
212 return 0;
213 }
139 } 214 }
140 215
141 eukrea_tlv320.dev = &pdev->dev;
142 ret = snd_soc_register_card(&eukrea_tlv320); 216 ret = snd_soc_register_card(&eukrea_tlv320);
217err:
143 if (ret) 218 if (ret)
144 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); 219 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
220 if (np)
221 of_node_put(ssi_np);
145 222
146 return ret; 223 return ret;
147} 224}
@@ -153,10 +230,17 @@ static int eukrea_tlv320_remove(struct platform_device *pdev)
153 return 0; 230 return 0;
154} 231}
155 232
233static const struct of_device_id imx_tlv320_dt_ids[] = {
234 { .compatible = "eukrea,asoc-tlv320"},
235 { /* sentinel */ }
236};
237MODULE_DEVICE_TABLE(of, imx_tlv320_dt_ids);
238
156static struct platform_driver eukrea_tlv320_driver = { 239static struct platform_driver eukrea_tlv320_driver = {
157 .driver = { 240 .driver = {
158 .name = "eukrea_tlv320", 241 .name = "eukrea_tlv320",
159 .owner = THIS_MODULE, 242 .owner = THIS_MODULE,
243 .of_match_table = imx_tlv320_dt_ids,
160 }, 244 },
161 .probe = eukrea_tlv320_probe, 245 .probe = eukrea_tlv320_probe,
162 .remove = eukrea_tlv320_remove, 246 .remove = eukrea_tlv320_remove,
diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c
index c84026c99134..0ba37005ab04 100644
--- a/sound/soc/fsl/fsl_esai.c
+++ b/sound/soc/fsl/fsl_esai.c
@@ -431,17 +431,26 @@ static int fsl_esai_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
431static int fsl_esai_startup(struct snd_pcm_substream *substream, 431static int fsl_esai_startup(struct snd_pcm_substream *substream,
432 struct snd_soc_dai *dai) 432 struct snd_soc_dai *dai)
433{ 433{
434 int ret;
434 struct fsl_esai *esai_priv = snd_soc_dai_get_drvdata(dai); 435 struct fsl_esai *esai_priv = snd_soc_dai_get_drvdata(dai);
435 436
436 /* 437 /*
437 * Some platforms might use the same bit to gate all three or two of 438 * Some platforms might use the same bit to gate all three or two of
438 * clocks, so keep all clocks open/close at the same time for safety 439 * clocks, so keep all clocks open/close at the same time for safety
439 */ 440 */
440 clk_prepare_enable(esai_priv->coreclk); 441 ret = clk_prepare_enable(esai_priv->coreclk);
441 if (!IS_ERR(esai_priv->extalclk)) 442 if (ret)
442 clk_prepare_enable(esai_priv->extalclk); 443 return ret;
443 if (!IS_ERR(esai_priv->fsysclk)) 444 if (!IS_ERR(esai_priv->extalclk)) {
444 clk_prepare_enable(esai_priv->fsysclk); 445 ret = clk_prepare_enable(esai_priv->extalclk);
446 if (ret)
447 goto err_extalck;
448 }
449 if (!IS_ERR(esai_priv->fsysclk)) {
450 ret = clk_prepare_enable(esai_priv->fsysclk);
451 if (ret)
452 goto err_fsysclk;
453 }
445 454
446 if (!dai->active) { 455 if (!dai->active) {
447 /* Reset Port C */ 456 /* Reset Port C */
@@ -463,6 +472,14 @@ static int fsl_esai_startup(struct snd_pcm_substream *substream,
463 } 472 }
464 473
465 return 0; 474 return 0;
475
476err_fsysclk:
477 if (!IS_ERR(esai_priv->extalclk))
478 clk_disable_unprepare(esai_priv->extalclk);
479err_extalck:
480 clk_disable_unprepare(esai_priv->coreclk);
481
482 return ret;
466} 483}
467 484
468static int fsl_esai_hw_params(struct snd_pcm_substream *substream, 485static int fsl_esai_hw_params(struct snd_pcm_substream *substream,
@@ -661,7 +678,7 @@ static bool fsl_esai_writeable_reg(struct device *dev, unsigned int reg)
661 } 678 }
662} 679}
663 680
664static const struct regmap_config fsl_esai_regmap_config = { 681static struct regmap_config fsl_esai_regmap_config = {
665 .reg_bits = 32, 682 .reg_bits = 32,
666 .reg_stride = 4, 683 .reg_stride = 4,
667 .val_bits = 32, 684 .val_bits = 32,
@@ -687,6 +704,9 @@ static int fsl_esai_probe(struct platform_device *pdev)
687 esai_priv->pdev = pdev; 704 esai_priv->pdev = pdev;
688 strcpy(esai_priv->name, np->name); 705 strcpy(esai_priv->name, np->name);
689 706
707 if (of_property_read_bool(np, "big-endian"))
708 fsl_esai_regmap_config.val_format_endian = REGMAP_ENDIAN_BIG;
709
690 /* Get the addresses and IRQ */ 710 /* Get the addresses and IRQ */
691 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 711 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
692 regs = devm_ioremap_resource(&pdev->dev, res); 712 regs = devm_ioremap_resource(&pdev->dev, res);
diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index cdd3fa830704..c4a423111673 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -15,6 +15,7 @@
15#include <linux/dmaengine.h> 15#include <linux/dmaengine.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/of_address.h> 17#include <linux/of_address.h>
18#include <linux/regmap.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <sound/core.h> 20#include <sound/core.h>
20#include <sound/dmaengine_pcm.h> 21#include <sound/dmaengine_pcm.h>
@@ -22,34 +23,6 @@
22 23
23#include "fsl_sai.h" 24#include "fsl_sai.h"
24 25
25static inline u32 sai_readl(struct fsl_sai *sai,
26 const void __iomem *addr)
27{
28 u32 val;
29
30 val = __raw_readl(addr);
31
32 if (likely(sai->big_endian_regs))
33 val = be32_to_cpu(val);
34 else
35 val = le32_to_cpu(val);
36 rmb();
37
38 return val;
39}
40
41static inline void sai_writel(struct fsl_sai *sai,
42 u32 val, void __iomem *addr)
43{
44 wmb();
45 if (likely(sai->big_endian_regs))
46 val = cpu_to_be32(val);
47 else
48 val = cpu_to_le32(val);
49
50 __raw_writel(val, addr);
51}
52
53static int fsl_sai_set_dai_sysclk_tr(struct snd_soc_dai *cpu_dai, 26static int fsl_sai_set_dai_sysclk_tr(struct snd_soc_dai *cpu_dai,
54 int clk_id, unsigned int freq, int fsl_dir) 27 int clk_id, unsigned int freq, int fsl_dir)
55{ 28{
@@ -61,7 +34,8 @@ static int fsl_sai_set_dai_sysclk_tr(struct snd_soc_dai *cpu_dai,
61 else 34 else
62 reg_cr2 = FSL_SAI_RCR2; 35 reg_cr2 = FSL_SAI_RCR2;
63 36
64 val_cr2 = sai_readl(sai, sai->base + reg_cr2); 37 regmap_read(sai->regmap, reg_cr2, &val_cr2);
38
65 val_cr2 &= ~FSL_SAI_CR2_MSEL_MASK; 39 val_cr2 &= ~FSL_SAI_CR2_MSEL_MASK;
66 40
67 switch (clk_id) { 41 switch (clk_id) {
@@ -81,7 +55,7 @@ static int fsl_sai_set_dai_sysclk_tr(struct snd_soc_dai *cpu_dai,
81 return -EINVAL; 55 return -EINVAL;
82 } 56 }
83 57
84 sai_writel(sai, val_cr2, sai->base + reg_cr2); 58 regmap_write(sai->regmap, reg_cr2, val_cr2);
85 59
86 return 0; 60 return 0;
87} 61}
@@ -89,32 +63,22 @@ static int fsl_sai_set_dai_sysclk_tr(struct snd_soc_dai *cpu_dai,
89static int fsl_sai_set_dai_sysclk(struct snd_soc_dai *cpu_dai, 63static int fsl_sai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
90 int clk_id, unsigned int freq, int dir) 64 int clk_id, unsigned int freq, int dir)
91{ 65{
92 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai);
93 int ret; 66 int ret;
94 67
95 if (dir == SND_SOC_CLOCK_IN) 68 if (dir == SND_SOC_CLOCK_IN)
96 return 0; 69 return 0;
97 70
98 ret = clk_prepare_enable(sai->clk);
99 if (ret)
100 return ret;
101
102 ret = fsl_sai_set_dai_sysclk_tr(cpu_dai, clk_id, freq, 71 ret = fsl_sai_set_dai_sysclk_tr(cpu_dai, clk_id, freq,
103 FSL_FMT_TRANSMITTER); 72 FSL_FMT_TRANSMITTER);
104 if (ret) { 73 if (ret) {
105 dev_err(cpu_dai->dev, "Cannot set tx sysclk: %d\n", ret); 74 dev_err(cpu_dai->dev, "Cannot set tx sysclk: %d\n", ret);
106 goto err_clk; 75 return ret;
107 } 76 }
108 77
109 ret = fsl_sai_set_dai_sysclk_tr(cpu_dai, clk_id, freq, 78 ret = fsl_sai_set_dai_sysclk_tr(cpu_dai, clk_id, freq,
110 FSL_FMT_RECEIVER); 79 FSL_FMT_RECEIVER);
111 if (ret) { 80 if (ret)
112 dev_err(cpu_dai->dev, "Cannot set rx sysclk: %d\n", ret); 81 dev_err(cpu_dai->dev, "Cannot set rx sysclk: %d\n", ret);
113 goto err_clk;
114 }
115
116err_clk:
117 clk_disable_unprepare(sai->clk);
118 82
119 return ret; 83 return ret;
120} 84}
@@ -133,43 +97,84 @@ static int fsl_sai_set_dai_fmt_tr(struct snd_soc_dai *cpu_dai,
133 reg_cr4 = FSL_SAI_RCR4; 97 reg_cr4 = FSL_SAI_RCR4;
134 } 98 }
135 99
136 val_cr2 = sai_readl(sai, sai->base + reg_cr2); 100 regmap_read(sai->regmap, reg_cr2, &val_cr2);
137 val_cr4 = sai_readl(sai, sai->base + reg_cr4); 101 regmap_read(sai->regmap, reg_cr4, &val_cr4);
138 102
139 if (sai->big_endian_data) 103 if (sai->big_endian_data)
140 val_cr4 &= ~FSL_SAI_CR4_MF; 104 val_cr4 &= ~FSL_SAI_CR4_MF;
141 else 105 else
142 val_cr4 |= FSL_SAI_CR4_MF; 106 val_cr4 |= FSL_SAI_CR4_MF;
143 107
108 /* DAI mode */
144 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 109 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
145 case SND_SOC_DAIFMT_I2S: 110 case SND_SOC_DAIFMT_I2S:
111 /*
112 * Frame low, 1clk before data, one word length for frame sync,
113 * frame sync starts one serial clock cycle earlier,
114 * that is, together with the last bit of the previous
115 * data word.
116 */
117 val_cr2 &= ~FSL_SAI_CR2_BCP;
118 val_cr4 |= FSL_SAI_CR4_FSE | FSL_SAI_CR4_FSP;
119 break;
120 case SND_SOC_DAIFMT_LEFT_J:
121 /*
122 * Frame high, one word length for frame sync,
123 * frame sync asserts with the first bit of the frame.
124 */
125 val_cr2 &= ~FSL_SAI_CR2_BCP;
126 val_cr4 &= ~(FSL_SAI_CR4_FSE | FSL_SAI_CR4_FSP);
127 break;
128 case SND_SOC_DAIFMT_DSP_A:
129 /*
130 * Frame high, 1clk before data, one bit for frame sync,
131 * frame sync starts one serial clock cycle earlier,
132 * that is, together with the last bit of the previous
133 * data word.
134 */
135 val_cr2 &= ~FSL_SAI_CR2_BCP;
136 val_cr4 &= ~FSL_SAI_CR4_FSP;
146 val_cr4 |= FSL_SAI_CR4_FSE; 137 val_cr4 |= FSL_SAI_CR4_FSE;
138 sai->is_dsp_mode = true;
139 break;
140 case SND_SOC_DAIFMT_DSP_B:
141 /*
142 * Frame high, one bit for frame sync,
143 * frame sync asserts with the first bit of the frame.
144 */
145 val_cr2 &= ~FSL_SAI_CR2_BCP;
146 val_cr4 &= ~(FSL_SAI_CR4_FSE | FSL_SAI_CR4_FSP);
147 sai->is_dsp_mode = true;
147 break; 148 break;
149 case SND_SOC_DAIFMT_RIGHT_J:
150 /* To be done */
148 default: 151 default:
149 return -EINVAL; 152 return -EINVAL;
150 } 153 }
151 154
155 /* DAI clock inversion */
152 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 156 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
153 case SND_SOC_DAIFMT_IB_IF: 157 case SND_SOC_DAIFMT_IB_IF:
154 val_cr4 |= FSL_SAI_CR4_FSP; 158 /* Invert both clocks */
155 val_cr2 &= ~FSL_SAI_CR2_BCP; 159 val_cr2 ^= FSL_SAI_CR2_BCP;
160 val_cr4 ^= FSL_SAI_CR4_FSP;
156 break; 161 break;
157 case SND_SOC_DAIFMT_IB_NF: 162 case SND_SOC_DAIFMT_IB_NF:
158 val_cr4 &= ~FSL_SAI_CR4_FSP; 163 /* Invert bit clock */
159 val_cr2 &= ~FSL_SAI_CR2_BCP; 164 val_cr2 ^= FSL_SAI_CR2_BCP;
160 break; 165 break;
161 case SND_SOC_DAIFMT_NB_IF: 166 case SND_SOC_DAIFMT_NB_IF:
162 val_cr4 |= FSL_SAI_CR4_FSP; 167 /* Invert frame clock */
163 val_cr2 |= FSL_SAI_CR2_BCP; 168 val_cr4 ^= FSL_SAI_CR4_FSP;
164 break; 169 break;
165 case SND_SOC_DAIFMT_NB_NF: 170 case SND_SOC_DAIFMT_NB_NF:
166 val_cr4 &= ~FSL_SAI_CR4_FSP; 171 /* Nothing to do for both normal cases */
167 val_cr2 |= FSL_SAI_CR2_BCP;
168 break; 172 break;
169 default: 173 default:
170 return -EINVAL; 174 return -EINVAL;
171 } 175 }
172 176
177 /* DAI clock master masks */
173 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 178 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
174 case SND_SOC_DAIFMT_CBS_CFS: 179 case SND_SOC_DAIFMT_CBS_CFS:
175 val_cr2 |= FSL_SAI_CR2_BCD_MSTR; 180 val_cr2 |= FSL_SAI_CR2_BCD_MSTR;
@@ -179,39 +184,37 @@ static int fsl_sai_set_dai_fmt_tr(struct snd_soc_dai *cpu_dai,
179 val_cr2 &= ~FSL_SAI_CR2_BCD_MSTR; 184 val_cr2 &= ~FSL_SAI_CR2_BCD_MSTR;
180 val_cr4 &= ~FSL_SAI_CR4_FSD_MSTR; 185 val_cr4 &= ~FSL_SAI_CR4_FSD_MSTR;
181 break; 186 break;
187 case SND_SOC_DAIFMT_CBS_CFM:
188 val_cr2 |= FSL_SAI_CR2_BCD_MSTR;
189 val_cr4 &= ~FSL_SAI_CR4_FSD_MSTR;
190 break;
191 case SND_SOC_DAIFMT_CBM_CFS:
192 val_cr2 &= ~FSL_SAI_CR2_BCD_MSTR;
193 val_cr4 |= FSL_SAI_CR4_FSD_MSTR;
194 break;
182 default: 195 default:
183 return -EINVAL; 196 return -EINVAL;
184 } 197 }
185 198
186 sai_writel(sai, val_cr2, sai->base + reg_cr2); 199 regmap_write(sai->regmap, reg_cr2, val_cr2);
187 sai_writel(sai, val_cr4, sai->base + reg_cr4); 200 regmap_write(sai->regmap, reg_cr4, val_cr4);
188 201
189 return 0; 202 return 0;
190} 203}
191 204
192static int fsl_sai_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) 205static int fsl_sai_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
193{ 206{
194 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai);
195 int ret; 207 int ret;
196 208
197 ret = clk_prepare_enable(sai->clk);
198 if (ret)
199 return ret;
200
201 ret = fsl_sai_set_dai_fmt_tr(cpu_dai, fmt, FSL_FMT_TRANSMITTER); 209 ret = fsl_sai_set_dai_fmt_tr(cpu_dai, fmt, FSL_FMT_TRANSMITTER);
202 if (ret) { 210 if (ret) {
203 dev_err(cpu_dai->dev, "Cannot set tx format: %d\n", ret); 211 dev_err(cpu_dai->dev, "Cannot set tx format: %d\n", ret);
204 goto err_clk; 212 return ret;
205 } 213 }
206 214
207 ret = fsl_sai_set_dai_fmt_tr(cpu_dai, fmt, FSL_FMT_RECEIVER); 215 ret = fsl_sai_set_dai_fmt_tr(cpu_dai, fmt, FSL_FMT_RECEIVER);
208 if (ret) { 216 if (ret)
209 dev_err(cpu_dai->dev, "Cannot set rx format: %d\n", ret); 217 dev_err(cpu_dai->dev, "Cannot set rx format: %d\n", ret);
210 goto err_clk;
211 }
212
213err_clk:
214 clk_disable_unprepare(sai->clk);
215 218
216 return ret; 219 return ret;
217} 220}
@@ -235,16 +238,19 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
235 reg_mr = FSL_SAI_RMR; 238 reg_mr = FSL_SAI_RMR;
236 } 239 }
237 240
238 val_cr4 = sai_readl(sai, sai->base + reg_cr4); 241 regmap_read(sai->regmap, reg_cr4, &val_cr4);
242 regmap_read(sai->regmap, reg_cr4, &val_cr5);
243
239 val_cr4 &= ~FSL_SAI_CR4_SYWD_MASK; 244 val_cr4 &= ~FSL_SAI_CR4_SYWD_MASK;
240 val_cr4 &= ~FSL_SAI_CR4_FRSZ_MASK; 245 val_cr4 &= ~FSL_SAI_CR4_FRSZ_MASK;
241 246
242 val_cr5 = sai_readl(sai, sai->base + reg_cr5);
243 val_cr5 &= ~FSL_SAI_CR5_WNW_MASK; 247 val_cr5 &= ~FSL_SAI_CR5_WNW_MASK;
244 val_cr5 &= ~FSL_SAI_CR5_W0W_MASK; 248 val_cr5 &= ~FSL_SAI_CR5_W0W_MASK;
245 val_cr5 &= ~FSL_SAI_CR5_FBT_MASK; 249 val_cr5 &= ~FSL_SAI_CR5_FBT_MASK;
246 250
247 val_cr4 |= FSL_SAI_CR4_SYWD(word_width); 251 if (!sai->is_dsp_mode)
252 val_cr4 |= FSL_SAI_CR4_SYWD(word_width);
253
248 val_cr5 |= FSL_SAI_CR5_WNW(word_width); 254 val_cr5 |= FSL_SAI_CR5_WNW(word_width);
249 val_cr5 |= FSL_SAI_CR5_W0W(word_width); 255 val_cr5 |= FSL_SAI_CR5_W0W(word_width);
250 256
@@ -257,9 +263,9 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
257 val_cr4 |= FSL_SAI_CR4_FRSZ(channels); 263 val_cr4 |= FSL_SAI_CR4_FRSZ(channels);
258 val_mr = ~0UL - ((1 << channels) - 1); 264 val_mr = ~0UL - ((1 << channels) - 1);
259 265
260 sai_writel(sai, val_cr4, sai->base + reg_cr4); 266 regmap_write(sai->regmap, reg_cr4, val_cr4);
261 sai_writel(sai, val_cr5, sai->base + reg_cr5); 267 regmap_write(sai->regmap, reg_cr5, val_cr5);
262 sai_writel(sai, val_mr, sai->base + reg_mr); 268 regmap_write(sai->regmap, reg_mr, val_mr);
263 269
264 return 0; 270 return 0;
265} 271}
@@ -268,44 +274,42 @@ static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd,
268 struct snd_soc_dai *cpu_dai) 274 struct snd_soc_dai *cpu_dai)
269{ 275{
270 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); 276 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai);
271 u32 tcsr, rcsr, val_cr2, val_cr3, reg_cr3; 277 u32 tcsr, rcsr;
272
273 val_cr2 = sai_readl(sai, sai->base + FSL_SAI_TCR2);
274 val_cr2 &= ~FSL_SAI_CR2_SYNC;
275 sai_writel(sai, val_cr2, sai->base + FSL_SAI_TCR2);
276 278
277 val_cr2 = sai_readl(sai, sai->base + FSL_SAI_RCR2); 279 /*
278 val_cr2 |= FSL_SAI_CR2_SYNC; 280 * The transmitter bit clock and frame sync are to be
279 sai_writel(sai, val_cr2, sai->base + FSL_SAI_RCR2); 281 * used by both the transmitter and receiver.
282 */
283 regmap_update_bits(sai->regmap, FSL_SAI_TCR2, FSL_SAI_CR2_SYNC,
284 ~FSL_SAI_CR2_SYNC);
285 regmap_update_bits(sai->regmap, FSL_SAI_RCR2, FSL_SAI_CR2_SYNC,
286 FSL_SAI_CR2_SYNC);
280 287
281 tcsr = sai_readl(sai, sai->base + FSL_SAI_TCSR); 288 regmap_read(sai->regmap, FSL_SAI_TCSR, &tcsr);
282 rcsr = sai_readl(sai, sai->base + FSL_SAI_RCSR); 289 regmap_read(sai->regmap, FSL_SAI_RCSR, &rcsr);
283 290
284 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 291 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
285 tcsr |= FSL_SAI_CSR_FRDE; 292 tcsr |= FSL_SAI_CSR_FRDE;
286 rcsr &= ~FSL_SAI_CSR_FRDE; 293 rcsr &= ~FSL_SAI_CSR_FRDE;
287 reg_cr3 = FSL_SAI_TCR3;
288 } else { 294 } else {
289 rcsr |= FSL_SAI_CSR_FRDE; 295 rcsr |= FSL_SAI_CSR_FRDE;
290 tcsr &= ~FSL_SAI_CSR_FRDE; 296 tcsr &= ~FSL_SAI_CSR_FRDE;
291 reg_cr3 = FSL_SAI_RCR3;
292 } 297 }
293 298
294 val_cr3 = sai_readl(sai, sai->base + reg_cr3); 299 /*
295 300 * It is recommended that the transmitter is the last enabled
301 * and the first disabled.
302 */
296 switch (cmd) { 303 switch (cmd) {
297 case SNDRV_PCM_TRIGGER_START: 304 case SNDRV_PCM_TRIGGER_START:
298 case SNDRV_PCM_TRIGGER_RESUME: 305 case SNDRV_PCM_TRIGGER_RESUME:
299 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 306 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
300 tcsr |= FSL_SAI_CSR_TERE; 307 tcsr |= FSL_SAI_CSR_TERE;
301 rcsr |= FSL_SAI_CSR_TERE; 308 rcsr |= FSL_SAI_CSR_TERE;
302 val_cr3 |= FSL_SAI_CR3_TRCE;
303 309
304 sai_writel(sai, val_cr3, sai->base + reg_cr3); 310 regmap_write(sai->regmap, FSL_SAI_RCSR, rcsr);
305 sai_writel(sai, rcsr, sai->base + FSL_SAI_RCSR); 311 regmap_write(sai->regmap, FSL_SAI_TCSR, tcsr);
306 sai_writel(sai, tcsr, sai->base + FSL_SAI_TCSR);
307 break; 312 break;
308
309 case SNDRV_PCM_TRIGGER_STOP: 313 case SNDRV_PCM_TRIGGER_STOP:
310 case SNDRV_PCM_TRIGGER_SUSPEND: 314 case SNDRV_PCM_TRIGGER_SUSPEND:
311 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 315 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
@@ -314,11 +318,8 @@ static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd,
314 rcsr &= ~FSL_SAI_CSR_TERE; 318 rcsr &= ~FSL_SAI_CSR_TERE;
315 } 319 }
316 320
317 val_cr3 &= ~FSL_SAI_CR3_TRCE; 321 regmap_write(sai->regmap, FSL_SAI_TCSR, tcsr);
318 322 regmap_write(sai->regmap, FSL_SAI_RCSR, rcsr);
319 sai_writel(sai, tcsr, sai->base + FSL_SAI_TCSR);
320 sai_writel(sai, rcsr, sai->base + FSL_SAI_RCSR);
321 sai_writel(sai, val_cr3, sai->base + reg_cr3);
322 break; 323 break;
323 default: 324 default:
324 return -EINVAL; 325 return -EINVAL;
@@ -331,16 +332,32 @@ static int fsl_sai_startup(struct snd_pcm_substream *substream,
331 struct snd_soc_dai *cpu_dai) 332 struct snd_soc_dai *cpu_dai)
332{ 333{
333 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); 334 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai);
335 u32 reg;
336
337 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
338 reg = FSL_SAI_TCR3;
339 else
340 reg = FSL_SAI_RCR3;
341
342 regmap_update_bits(sai->regmap, reg, FSL_SAI_CR3_TRCE,
343 FSL_SAI_CR3_TRCE);
334 344
335 return clk_prepare_enable(sai->clk); 345 return 0;
336} 346}
337 347
338static void fsl_sai_shutdown(struct snd_pcm_substream *substream, 348static void fsl_sai_shutdown(struct snd_pcm_substream *substream,
339 struct snd_soc_dai *cpu_dai) 349 struct snd_soc_dai *cpu_dai)
340{ 350{
341 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); 351 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai);
352 u32 reg;
353
354 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
355 reg = FSL_SAI_TCR3;
356 else
357 reg = FSL_SAI_RCR3;
342 358
343 clk_disable_unprepare(sai->clk); 359 regmap_update_bits(sai->regmap, reg, FSL_SAI_CR3_TRCE,
360 ~FSL_SAI_CR3_TRCE);
344} 361}
345 362
346static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = { 363static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = {
@@ -355,18 +372,13 @@ static const struct snd_soc_dai_ops fsl_sai_pcm_dai_ops = {
355static int fsl_sai_dai_probe(struct snd_soc_dai *cpu_dai) 372static int fsl_sai_dai_probe(struct snd_soc_dai *cpu_dai)
356{ 373{
357 struct fsl_sai *sai = dev_get_drvdata(cpu_dai->dev); 374 struct fsl_sai *sai = dev_get_drvdata(cpu_dai->dev);
358 int ret;
359 375
360 ret = clk_prepare_enable(sai->clk); 376 regmap_update_bits(sai->regmap, FSL_SAI_TCSR, 0xffffffff, 0x0);
361 if (ret) 377 regmap_update_bits(sai->regmap, FSL_SAI_RCSR, 0xffffffff, 0x0);
362 return ret; 378 regmap_update_bits(sai->regmap, FSL_SAI_TCR1, FSL_SAI_CR1_RFW_MASK,
363 379 FSL_SAI_MAXBURST_TX * 2);
364 sai_writel(sai, 0x0, sai->base + FSL_SAI_RCSR); 380 regmap_update_bits(sai->regmap, FSL_SAI_RCR1, FSL_SAI_CR1_RFW_MASK,
365 sai_writel(sai, 0x0, sai->base + FSL_SAI_TCSR); 381 FSL_SAI_MAXBURST_RX - 1);
366 sai_writel(sai, FSL_SAI_MAXBURST_TX * 2, sai->base + FSL_SAI_TCR1);
367 sai_writel(sai, FSL_SAI_MAXBURST_RX - 1, sai->base + FSL_SAI_RCR1);
368
369 clk_disable_unprepare(sai->clk);
370 382
371 snd_soc_dai_init_dma_data(cpu_dai, &sai->dma_params_tx, 383 snd_soc_dai_init_dma_data(cpu_dai, &sai->dma_params_tx,
372 &sai->dma_params_rx); 384 &sai->dma_params_rx);
@@ -397,26 +409,109 @@ static const struct snd_soc_component_driver fsl_component = {
397 .name = "fsl-sai", 409 .name = "fsl-sai",
398}; 410};
399 411
412static bool fsl_sai_readable_reg(struct device *dev, unsigned int reg)
413{
414 switch (reg) {
415 case FSL_SAI_TCSR:
416 case FSL_SAI_TCR1:
417 case FSL_SAI_TCR2:
418 case FSL_SAI_TCR3:
419 case FSL_SAI_TCR4:
420 case FSL_SAI_TCR5:
421 case FSL_SAI_TFR:
422 case FSL_SAI_TMR:
423 case FSL_SAI_RCSR:
424 case FSL_SAI_RCR1:
425 case FSL_SAI_RCR2:
426 case FSL_SAI_RCR3:
427 case FSL_SAI_RCR4:
428 case FSL_SAI_RCR5:
429 case FSL_SAI_RDR:
430 case FSL_SAI_RFR:
431 case FSL_SAI_RMR:
432 return true;
433 default:
434 return false;
435 }
436}
437
438static bool fsl_sai_volatile_reg(struct device *dev, unsigned int reg)
439{
440 switch (reg) {
441 case FSL_SAI_TFR:
442 case FSL_SAI_RFR:
443 case FSL_SAI_TDR:
444 case FSL_SAI_RDR:
445 return true;
446 default:
447 return false;
448 }
449
450}
451
452static bool fsl_sai_writeable_reg(struct device *dev, unsigned int reg)
453{
454 switch (reg) {
455 case FSL_SAI_TCSR:
456 case FSL_SAI_TCR1:
457 case FSL_SAI_TCR2:
458 case FSL_SAI_TCR3:
459 case FSL_SAI_TCR4:
460 case FSL_SAI_TCR5:
461 case FSL_SAI_TDR:
462 case FSL_SAI_TMR:
463 case FSL_SAI_RCSR:
464 case FSL_SAI_RCR1:
465 case FSL_SAI_RCR2:
466 case FSL_SAI_RCR3:
467 case FSL_SAI_RCR4:
468 case FSL_SAI_RCR5:
469 case FSL_SAI_RMR:
470 return true;
471 default:
472 return false;
473 }
474}
475
476static struct regmap_config fsl_sai_regmap_config = {
477 .reg_bits = 32,
478 .reg_stride = 4,
479 .val_bits = 32,
480
481 .max_register = FSL_SAI_RMR,
482 .readable_reg = fsl_sai_readable_reg,
483 .volatile_reg = fsl_sai_volatile_reg,
484 .writeable_reg = fsl_sai_writeable_reg,
485};
486
400static int fsl_sai_probe(struct platform_device *pdev) 487static int fsl_sai_probe(struct platform_device *pdev)
401{ 488{
402 struct device_node *np = pdev->dev.of_node; 489 struct device_node *np = pdev->dev.of_node;
403 struct fsl_sai *sai; 490 struct fsl_sai *sai;
404 struct resource *res; 491 struct resource *res;
492 void __iomem *base;
405 int ret; 493 int ret;
406 494
407 sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); 495 sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL);
408 if (!sai) 496 if (!sai)
409 return -ENOMEM; 497 return -ENOMEM;
410 498
499 sai->big_endian_regs = of_property_read_bool(np, "big-endian-regs");
500 if (sai->big_endian_regs)
501 fsl_sai_regmap_config.val_format_endian = REGMAP_ENDIAN_BIG;
502
503 sai->big_endian_data = of_property_read_bool(np, "big-endian-data");
504
411 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 505 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
412 sai->base = devm_ioremap_resource(&pdev->dev, res); 506 base = devm_ioremap_resource(&pdev->dev, res);
413 if (IS_ERR(sai->base)) 507 if (IS_ERR(base))
414 return PTR_ERR(sai->base); 508 return PTR_ERR(base);
415 509
416 sai->clk = devm_clk_get(&pdev->dev, "sai"); 510 sai->regmap = devm_regmap_init_mmio_clk(&pdev->dev,
417 if (IS_ERR(sai->clk)) { 511 "sai", base, &fsl_sai_regmap_config);
418 dev_err(&pdev->dev, "Cannot get SAI's clock\n"); 512 if (IS_ERR(sai->regmap)) {
419 return PTR_ERR(sai->clk); 513 dev_err(&pdev->dev, "regmap init failed\n");
514 return PTR_ERR(sai->regmap);
420 } 515 }
421 516
422 sai->dma_params_rx.addr = res->start + FSL_SAI_RDR; 517 sai->dma_params_rx.addr = res->start + FSL_SAI_RDR;
@@ -424,9 +519,6 @@ static int fsl_sai_probe(struct platform_device *pdev)
424 sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX; 519 sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX;
425 sai->dma_params_tx.maxburst = FSL_SAI_MAXBURST_TX; 520 sai->dma_params_tx.maxburst = FSL_SAI_MAXBURST_TX;
426 521
427 sai->big_endian_regs = of_property_read_bool(np, "big-endian-regs");
428 sai->big_endian_data = of_property_read_bool(np, "big-endian-data");
429
430 platform_set_drvdata(pdev, sai); 522 platform_set_drvdata(pdev, sai);
431 523
432 ret = devm_snd_soc_register_component(&pdev->dev, &fsl_component, 524 ret = devm_snd_soc_register_component(&pdev->dev, &fsl_component,
diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h
index 41bb62e69361..e432260be598 100644
--- a/sound/soc/fsl/fsl_sai.h
+++ b/sound/soc/fsl/fsl_sai.h
@@ -15,31 +15,36 @@
15 SNDRV_PCM_FMTBIT_S20_3LE |\ 15 SNDRV_PCM_FMTBIT_S20_3LE |\
16 SNDRV_PCM_FMTBIT_S24_LE) 16 SNDRV_PCM_FMTBIT_S24_LE)
17 17
18/* SAI Register Map Register */
19#define FSL_SAI_TCSR 0x00 /* SAI Transmit Control */
20#define FSL_SAI_TCR1 0x04 /* SAI Transmit Configuration 1 */
21#define FSL_SAI_TCR2 0x08 /* SAI Transmit Configuration 2 */
22#define FSL_SAI_TCR3 0x0c /* SAI Transmit Configuration 3 */
23#define FSL_SAI_TCR4 0x10 /* SAI Transmit Configuration 4 */
24#define FSL_SAI_TCR5 0x14 /* SAI Transmit Configuration 5 */
25#define FSL_SAI_TDR 0x20 /* SAI Transmit Data */
26#define FSL_SAI_TFR 0x40 /* SAI Transmit FIFO */
27#define FSL_SAI_TMR 0x60 /* SAI Transmit Mask */
28#define FSL_SAI_RCSR 0x80 /* SAI Receive Control */
29#define FSL_SAI_RCR1 0x84 /* SAI Receive Configuration 1 */
30#define FSL_SAI_RCR2 0x88 /* SAI Receive Configuration 2 */
31#define FSL_SAI_RCR3 0x8c /* SAI Receive Configuration 3 */
32#define FSL_SAI_RCR4 0x90 /* SAI Receive Configuration 4 */
33#define FSL_SAI_RCR5 0x94 /* SAI Receive Configuration 5 */
34#define FSL_SAI_RDR 0xa0 /* SAI Receive Data */
35#define FSL_SAI_RFR 0xc0 /* SAI Receive FIFO */
36#define FSL_SAI_RMR 0xe0 /* SAI Receive Mask */
37
18/* SAI Transmit/Recieve Control Register */ 38/* SAI Transmit/Recieve Control Register */
19#define FSL_SAI_TCSR 0x00
20#define FSL_SAI_RCSR 0x80
21#define FSL_SAI_CSR_TERE BIT(31) 39#define FSL_SAI_CSR_TERE BIT(31)
22#define FSL_SAI_CSR_FWF BIT(17) 40#define FSL_SAI_CSR_FWF BIT(17)
23#define FSL_SAI_CSR_FRIE BIT(8) 41#define FSL_SAI_CSR_FRIE BIT(8)
24#define FSL_SAI_CSR_FRDE BIT(0) 42#define FSL_SAI_CSR_FRDE BIT(0)
25 43
26/* SAI Transmit Data/FIFO/MASK Register */
27#define FSL_SAI_TDR 0x20
28#define FSL_SAI_TFR 0x40
29#define FSL_SAI_TMR 0x60
30
31/* SAI Recieve Data/FIFO/MASK Register */
32#define FSL_SAI_RDR 0xa0
33#define FSL_SAI_RFR 0xc0
34#define FSL_SAI_RMR 0xe0
35
36/* SAI Transmit and Recieve Configuration 1 Register */ 44/* SAI Transmit and Recieve Configuration 1 Register */
37#define FSL_SAI_TCR1 0x04 45#define FSL_SAI_CR1_RFW_MASK 0x1f
38#define FSL_SAI_RCR1 0x84
39 46
40/* SAI Transmit and Recieve Configuration 2 Register */ 47/* SAI Transmit and Recieve Configuration 2 Register */
41#define FSL_SAI_TCR2 0x08
42#define FSL_SAI_RCR2 0x88
43#define FSL_SAI_CR2_SYNC BIT(30) 48#define FSL_SAI_CR2_SYNC BIT(30)
44#define FSL_SAI_CR2_MSEL_MASK (0xff << 26) 49#define FSL_SAI_CR2_MSEL_MASK (0xff << 26)
45#define FSL_SAI_CR2_MSEL_BUS 0 50#define FSL_SAI_CR2_MSEL_BUS 0
@@ -50,15 +55,11 @@
50#define FSL_SAI_CR2_BCD_MSTR BIT(24) 55#define FSL_SAI_CR2_BCD_MSTR BIT(24)
51 56
52/* SAI Transmit and Recieve Configuration 3 Register */ 57/* SAI Transmit and Recieve Configuration 3 Register */
53#define FSL_SAI_TCR3 0x0c
54#define FSL_SAI_RCR3 0x8c
55#define FSL_SAI_CR3_TRCE BIT(16) 58#define FSL_SAI_CR3_TRCE BIT(16)
56#define FSL_SAI_CR3_WDFL(x) (x) 59#define FSL_SAI_CR3_WDFL(x) (x)
57#define FSL_SAI_CR3_WDFL_MASK 0x1f 60#define FSL_SAI_CR3_WDFL_MASK 0x1f
58 61
59/* SAI Transmit and Recieve Configuration 4 Register */ 62/* SAI Transmit and Recieve Configuration 4 Register */
60#define FSL_SAI_TCR4 0x10
61#define FSL_SAI_RCR4 0x90
62#define FSL_SAI_CR4_FRSZ(x) (((x) - 1) << 16) 63#define FSL_SAI_CR4_FRSZ(x) (((x) - 1) << 16)
63#define FSL_SAI_CR4_FRSZ_MASK (0x1f << 16) 64#define FSL_SAI_CR4_FRSZ_MASK (0x1f << 16)
64#define FSL_SAI_CR4_SYWD(x) (((x) - 1) << 8) 65#define FSL_SAI_CR4_SYWD(x) (((x) - 1) << 8)
@@ -69,8 +70,6 @@
69#define FSL_SAI_CR4_FSD_MSTR BIT(0) 70#define FSL_SAI_CR4_FSD_MSTR BIT(0)
70 71
71/* SAI Transmit and Recieve Configuration 5 Register */ 72/* SAI Transmit and Recieve Configuration 5 Register */
72#define FSL_SAI_TCR5 0x14
73#define FSL_SAI_RCR5 0x94
74#define FSL_SAI_CR5_WNW(x) (((x) - 1) << 24) 73#define FSL_SAI_CR5_WNW(x) (((x) - 1) << 24)
75#define FSL_SAI_CR5_WNW_MASK (0x1f << 24) 74#define FSL_SAI_CR5_WNW_MASK (0x1f << 24)
76#define FSL_SAI_CR5_W0W(x) (((x) - 1) << 16) 75#define FSL_SAI_CR5_W0W(x) (((x) - 1) << 16)
@@ -100,12 +99,11 @@
100#define FSL_SAI_MAXBURST_RX 6 99#define FSL_SAI_MAXBURST_RX 6
101 100
102struct fsl_sai { 101struct fsl_sai {
103 struct clk *clk; 102 struct regmap *regmap;
104
105 void __iomem *base;
106 103
107 bool big_endian_regs; 104 bool big_endian_regs;
108 bool big_endian_data; 105 bool big_endian_data;
106 bool is_dsp_mode;
109 107
110 struct snd_dmaengine_dai_dma_data dma_params_rx; 108 struct snd_dmaengine_dai_dma_data dma_params_rx;
111 struct snd_dmaengine_dai_dma_data dma_params_tx; 109 struct snd_dmaengine_dai_dma_data dma_params_tx;
diff --git a/sound/soc/fsl/fsl_spdif.c b/sound/soc/fsl/fsl_spdif.c
index 4d075f1abe78..6452ca83d889 100644
--- a/sound/soc/fsl/fsl_spdif.c
+++ b/sound/soc/fsl/fsl_spdif.c
@@ -911,8 +911,8 @@ static int fsl_spdif_dai_probe(struct snd_soc_dai *dai)
911{ 911{
912 struct fsl_spdif_priv *spdif_private = snd_soc_dai_get_drvdata(dai); 912 struct fsl_spdif_priv *spdif_private = snd_soc_dai_get_drvdata(dai);
913 913
914 dai->playback_dma_data = &spdif_private->dma_params_tx; 914 snd_soc_dai_init_dma_data(dai, &spdif_private->dma_params_tx,
915 dai->capture_dma_data = &spdif_private->dma_params_rx; 915 &spdif_private->dma_params_rx);
916 916
917 snd_soc_add_dai_controls(dai, fsl_spdif_ctrls, ARRAY_SIZE(fsl_spdif_ctrls)); 917 snd_soc_add_dai_controls(dai, fsl_spdif_ctrls, ARRAY_SIZE(fsl_spdif_ctrls));
918 918
@@ -985,7 +985,7 @@ static bool fsl_spdif_writeable_reg(struct device *dev, unsigned int reg)
985 } 985 }
986} 986}
987 987
988static const struct regmap_config fsl_spdif_regmap_config = { 988static struct regmap_config fsl_spdif_regmap_config = {
989 .reg_bits = 32, 989 .reg_bits = 32,
990 .reg_stride = 4, 990 .reg_stride = 4,
991 .val_bits = 32, 991 .val_bits = 32,
@@ -1105,6 +1105,9 @@ static int fsl_spdif_probe(struct platform_device *pdev)
1105 memcpy(&spdif_priv->cpu_dai_drv, &fsl_spdif_dai, sizeof(fsl_spdif_dai)); 1105 memcpy(&spdif_priv->cpu_dai_drv, &fsl_spdif_dai, sizeof(fsl_spdif_dai));
1106 spdif_priv->cpu_dai_drv.name = spdif_priv->name; 1106 spdif_priv->cpu_dai_drv.name = spdif_priv->name;
1107 1107
1108 if (of_property_read_bool(np, "big-endian"))
1109 fsl_spdif_regmap_config.val_format_endian = REGMAP_ENDIAN_BIG;
1110
1108 /* Get the addresses and IRQ */ 1111 /* Get the addresses and IRQ */
1109 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1112 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1110 regs = devm_ioremap_resource(&pdev->dev, res); 1113 regs = devm_ioremap_resource(&pdev->dev, res);
diff --git a/sound/soc/fsl/imx-pcm-fiq.c b/sound/soc/fsl/imx-pcm-fiq.c
index 6553202dd48c..7abf6a079574 100644
--- a/sound/soc/fsl/imx-pcm-fiq.c
+++ b/sound/soc/fsl/imx-pcm-fiq.c
@@ -270,18 +270,17 @@ static int imx_pcm_new(struct snd_soc_pcm_runtime *rtd)
270 ret = imx_pcm_preallocate_dma_buffer(pcm, 270 ret = imx_pcm_preallocate_dma_buffer(pcm,
271 SNDRV_PCM_STREAM_PLAYBACK); 271 SNDRV_PCM_STREAM_PLAYBACK);
272 if (ret) 272 if (ret)
273 goto out; 273 return ret;
274 } 274 }
275 275
276 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { 276 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
277 ret = imx_pcm_preallocate_dma_buffer(pcm, 277 ret = imx_pcm_preallocate_dma_buffer(pcm,
278 SNDRV_PCM_STREAM_CAPTURE); 278 SNDRV_PCM_STREAM_CAPTURE);
279 if (ret) 279 if (ret)
280 goto out; 280 return ret;
281 } 281 }
282 282
283out: 283 return 0;
284 return ret;
285} 284}
286 285
287static int ssi_irq = 0; 286static int ssi_irq = 0;
diff --git a/sound/soc/fsl/wm1133-ev1.c b/sound/soc/fsl/wm1133-ev1.c
index fce63252bdbb..804749a6c61e 100644
--- a/sound/soc/fsl/wm1133-ev1.c
+++ b/sound/soc/fsl/wm1133-ev1.c
@@ -214,12 +214,6 @@ static int wm1133_ev1_init(struct snd_soc_pcm_runtime *rtd)
214 struct snd_soc_codec *codec = rtd->codec; 214 struct snd_soc_codec *codec = rtd->codec;
215 struct snd_soc_dapm_context *dapm = &codec->dapm; 215 struct snd_soc_dapm_context *dapm = &codec->dapm;
216 216
217 snd_soc_dapm_new_controls(dapm, wm1133_ev1_widgets,
218 ARRAY_SIZE(wm1133_ev1_widgets));
219
220 snd_soc_dapm_add_routes(dapm, wm1133_ev1_map,
221 ARRAY_SIZE(wm1133_ev1_map));
222
223 /* Headphone jack detection */ 217 /* Headphone jack detection */
224 snd_soc_jack_new(codec, "Headphone", SND_JACK_HEADPHONE, &hp_jack); 218 snd_soc_jack_new(codec, "Headphone", SND_JACK_HEADPHONE, &hp_jack);
225 snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins), 219 snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
@@ -257,6 +251,11 @@ static struct snd_soc_card wm1133_ev1 = {
257 .owner = THIS_MODULE, 251 .owner = THIS_MODULE,
258 .dai_link = &wm1133_ev1_dai, 252 .dai_link = &wm1133_ev1_dai,
259 .num_links = 1, 253 .num_links = 1,
254
255 .dapm_widgets = wm1133_ev1_widgets,
256 .num_dapm_widgets = ARRAY_SIZE(wm1133_ev1_widgets),
257 .dapm_routes = wm1133_ev1_map,
258 .num_dapm_routes = ARRAY_SIZE(wm1133_ev1_map),
260}; 259};
261 260
262static struct platform_device *wm1133_ev1_snd_device; 261static struct platform_device *wm1133_ev1_snd_device;
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 2a1b1b5b5221..2ee8ed56bcf1 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -9,48 +9,72 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11#include <linux/clk.h> 11#include <linux/clk.h>
12#include <linux/device.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/of.h> 14#include <linux/of.h>
14#include <linux/platform_device.h> 15#include <linux/platform_device.h>
15#include <linux/string.h> 16#include <linux/string.h>
16#include <sound/simple_card.h> 17#include <sound/simple_card.h>
18#include <sound/soc-dai.h>
19#include <sound/soc.h>
20
21struct simple_card_data {
22 struct snd_soc_card snd_card;
23 struct asoc_simple_dai cpu_dai;
24 struct asoc_simple_dai codec_dai;
25 struct snd_soc_dai_link snd_link;
26};
17 27
18static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, 28static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
19 struct asoc_simple_dai *set, 29 struct asoc_simple_dai *set)
20 unsigned int daifmt)
21{ 30{
22 int ret = 0; 31 int ret;
23 32
24 daifmt |= set->fmt; 33 if (set->fmt) {
34 ret = snd_soc_dai_set_fmt(dai, set->fmt);
35 if (ret && ret != -ENOTSUPP) {
36 dev_err(dai->dev, "simple-card: set_fmt error\n");
37 goto err;
38 }
39 }
25 40
26 if (daifmt) 41 if (set->sysclk) {
27 ret = snd_soc_dai_set_fmt(dai, daifmt); 42 ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0);
43 if (ret && ret != -ENOTSUPP) {
44 dev_err(dai->dev, "simple-card: set_sysclk error\n");
45 goto err;
46 }
47 }
28 48
29 if (ret == -ENOTSUPP) { 49 if (set->slots) {
30 dev_dbg(dai->dev, "ASoC: set_fmt is not supported\n"); 50 ret = snd_soc_dai_set_tdm_slot(dai, 0, 0,
31 ret = 0; 51 set->slots,
52 set->slot_width);
53 if (ret && ret != -ENOTSUPP) {
54 dev_err(dai->dev, "simple-card: set_tdm_slot error\n");
55 goto err;
56 }
32 } 57 }
33 58
34 if (!ret && set->sysclk) 59 ret = 0;
35 ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0);
36 60
61err:
37 return ret; 62 return ret;
38} 63}
39 64
40static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) 65static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
41{ 66{
42 struct asoc_simple_card_info *info = 67 struct simple_card_data *priv =
43 snd_soc_card_get_drvdata(rtd->card); 68 snd_soc_card_get_drvdata(rtd->card);
44 struct snd_soc_dai *codec = rtd->codec_dai; 69 struct snd_soc_dai *codec = rtd->codec_dai;
45 struct snd_soc_dai *cpu = rtd->cpu_dai; 70 struct snd_soc_dai *cpu = rtd->cpu_dai;
46 unsigned int daifmt = info->daifmt;
47 int ret; 71 int ret;
48 72
49 ret = __asoc_simple_card_dai_init(codec, &info->codec_dai, daifmt); 73 ret = __asoc_simple_card_dai_init(codec, &priv->codec_dai);
50 if (ret < 0) 74 if (ret < 0)
51 return ret; 75 return ret;
52 76
53 ret = __asoc_simple_card_dai_init(cpu, &info->cpu_dai, daifmt); 77 ret = __asoc_simple_card_dai_init(cpu, &priv->cpu_dai);
54 if (ret < 0) 78 if (ret < 0)
55 return ret; 79 return ret;
56 80
@@ -59,9 +83,12 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
59 83
60static int 84static int
61asoc_simple_card_sub_parse_of(struct device_node *np, 85asoc_simple_card_sub_parse_of(struct device_node *np,
86 unsigned int daifmt,
62 struct asoc_simple_dai *dai, 87 struct asoc_simple_dai *dai,
63 struct device_node **node) 88 const struct device_node **p_node,
89 const char **name)
64{ 90{
91 struct device_node *node;
65 struct clk *clk; 92 struct clk *clk;
66 int ret; 93 int ret;
67 94
@@ -69,14 +96,20 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
69 * get node via "sound-dai = <&phandle port>" 96 * get node via "sound-dai = <&phandle port>"
70 * it will be used as xxx_of_node on soc_bind_dai_link() 97 * it will be used as xxx_of_node on soc_bind_dai_link()
71 */ 98 */
72 *node = of_parse_phandle(np, "sound-dai", 0); 99 node = of_parse_phandle(np, "sound-dai", 0);
73 if (!*node) 100 if (!node)
74 return -ENODEV; 101 return -ENODEV;
102 *p_node = node;
75 103
76 /* get dai->name */ 104 /* get dai->name */
77 ret = snd_soc_of_get_dai_name(np, &dai->name); 105 ret = snd_soc_of_get_dai_name(np, name);
78 if (ret < 0) 106 if (ret < 0)
79 goto parse_error; 107 return ret;
108
109 /* parse TDM slot */
110 ret = snd_soc_of_parse_tdm_slot(np, &dai->slots, &dai->slot_width);
111 if (ret)
112 return ret;
80 113
81 /* 114 /*
82 * bitclock-inversion, frame-inversion 115 * bitclock-inversion, frame-inversion
@@ -84,6 +117,7 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
84 * and specific "format" if it has 117 * and specific "format" if it has
85 */ 118 */
86 dai->fmt = snd_soc_of_parse_daifmt(np, NULL); 119 dai->fmt = snd_soc_of_parse_daifmt(np, NULL);
120 dai->fmt |= daifmt;
87 121
88 /* 122 /*
89 * dai->sysclk come from 123 * dai->sysclk come from
@@ -95,7 +129,7 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
95 clk = of_clk_get(np, 0); 129 clk = of_clk_get(np, 0);
96 if (IS_ERR(clk)) { 130 if (IS_ERR(clk)) {
97 ret = PTR_ERR(clk); 131 ret = PTR_ERR(clk);
98 goto parse_error; 132 return ret;
99 } 133 }
100 134
101 dai->sysclk = clk_get_rate(clk); 135 dai->sysclk = clk_get_rate(clk);
@@ -104,37 +138,44 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
104 "system-clock-frequency", 138 "system-clock-frequency",
105 &dai->sysclk); 139 &dai->sysclk);
106 } else { 140 } else {
107 clk = of_clk_get(*node, 0); 141 clk = of_clk_get(node, 0);
108 if (!IS_ERR(clk)) 142 if (!IS_ERR(clk))
109 dai->sysclk = clk_get_rate(clk); 143 dai->sysclk = clk_get_rate(clk);
110 } 144 }
111 145
112 ret = 0; 146 return 0;
113
114parse_error:
115 of_node_put(*node);
116
117 return ret;
118} 147}
119 148
120static int asoc_simple_card_parse_of(struct device_node *node, 149static int asoc_simple_card_parse_of(struct device_node *node,
121 struct asoc_simple_card_info *info, 150 struct simple_card_data *priv,
122 struct device *dev, 151 struct device *dev)
123 struct device_node **of_cpu,
124 struct device_node **of_codec,
125 struct device_node **of_platform)
126{ 152{
153 struct snd_soc_dai_link *dai_link = priv->snd_card.dai_link;
154 struct asoc_simple_dai *codec_dai = &priv->codec_dai;
155 struct asoc_simple_dai *cpu_dai = &priv->cpu_dai;
127 struct device_node *np; 156 struct device_node *np;
128 char *name; 157 char *name;
158 unsigned int daifmt;
129 int ret; 159 int ret;
130 160
161 /* parsing the card name from DT */
162 snd_soc_of_parse_card_name(&priv->snd_card, "simple-audio-card,name");
163
131 /* get CPU/CODEC common format via simple-audio-card,format */ 164 /* get CPU/CODEC common format via simple-audio-card,format */
132 info->daifmt = snd_soc_of_parse_daifmt(node, "simple-audio-card,") & 165 daifmt = snd_soc_of_parse_daifmt(node, "simple-audio-card,") &
133 (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_INV_MASK); 166 (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_INV_MASK);
134 167
168 /* off-codec widgets */
169 if (of_property_read_bool(node, "simple-audio-card,widgets")) {
170 ret = snd_soc_of_parse_audio_simple_widgets(&priv->snd_card,
171 "simple-audio-card,widgets");
172 if (ret)
173 return ret;
174 }
175
135 /* DAPM routes */ 176 /* DAPM routes */
136 if (of_property_read_bool(node, "simple-audio-card,routing")) { 177 if (of_property_read_bool(node, "simple-audio-card,routing")) {
137 ret = snd_soc_of_parse_audio_routing(&info->snd_card, 178 ret = snd_soc_of_parse_audio_routing(&priv->snd_card,
138 "simple-audio-card,routing"); 179 "simple-audio-card,routing");
139 if (ret) 180 if (ret)
140 return ret; 181 return ret;
@@ -143,125 +184,173 @@ static int asoc_simple_card_parse_of(struct device_node *node,
143 /* CPU sub-node */ 184 /* CPU sub-node */
144 ret = -EINVAL; 185 ret = -EINVAL;
145 np = of_get_child_by_name(node, "simple-audio-card,cpu"); 186 np = of_get_child_by_name(node, "simple-audio-card,cpu");
146 if (np) 187 if (np) {
147 ret = asoc_simple_card_sub_parse_of(np, 188 ret = asoc_simple_card_sub_parse_of(np, daifmt,
148 &info->cpu_dai, 189 cpu_dai,
149 of_cpu); 190 &dai_link->cpu_of_node,
191 &dai_link->cpu_dai_name);
192 of_node_put(np);
193 }
150 if (ret < 0) 194 if (ret < 0)
151 return ret; 195 return ret;
152 196
153 /* CODEC sub-node */ 197 /* CODEC sub-node */
154 ret = -EINVAL; 198 ret = -EINVAL;
155 np = of_get_child_by_name(node, "simple-audio-card,codec"); 199 np = of_get_child_by_name(node, "simple-audio-card,codec");
156 if (np) 200 if (np) {
157 ret = asoc_simple_card_sub_parse_of(np, 201 ret = asoc_simple_card_sub_parse_of(np, daifmt,
158 &info->codec_dai, 202 codec_dai,
159 of_codec); 203 &dai_link->codec_of_node,
204 &dai_link->codec_dai_name);
205 of_node_put(np);
206 }
160 if (ret < 0) 207 if (ret < 0)
161 return ret; 208 return ret;
162 209
163 if (!info->cpu_dai.name || !info->codec_dai.name) 210 /*
211 * overwrite cpu_dai->fmt as its DAIFMT_MASTER bit is based on CODEC
212 * while the other bits should be identical unless buggy SW/HW design.
213 */
214 cpu_dai->fmt = codec_dai->fmt;
215
216 if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name)
164 return -EINVAL; 217 return -EINVAL;
165 218
166 /* card name is created from CPU/CODEC dai name */ 219 /* card name is created from CPU/CODEC dai name */
167 name = devm_kzalloc(dev, 220 name = devm_kzalloc(dev,
168 strlen(info->cpu_dai.name) + 221 strlen(dai_link->cpu_dai_name) +
169 strlen(info->codec_dai.name) + 2, 222 strlen(dai_link->codec_dai_name) + 2,
170 GFP_KERNEL); 223 GFP_KERNEL);
171 sprintf(name, "%s-%s", info->cpu_dai.name, info->codec_dai.name); 224 sprintf(name, "%s-%s", dai_link->cpu_dai_name,
172 info->name = info->card = name; 225 dai_link->codec_dai_name);
226 if (!priv->snd_card.name)
227 priv->snd_card.name = name;
228 dai_link->name = dai_link->stream_name = name;
173 229
174 /* simple-card assumes platform == cpu */ 230 /* simple-card assumes platform == cpu */
175 *of_platform = *of_cpu; 231 dai_link->platform_of_node = dai_link->cpu_of_node;
176 232
177 dev_dbg(dev, "card-name : %s\n", info->card); 233 dev_dbg(dev, "card-name : %s\n", name);
178 dev_dbg(dev, "platform : %04x\n", info->daifmt); 234 dev_dbg(dev, "platform : %04x\n", daifmt);
179 dev_dbg(dev, "cpu : %s / %04x / %d\n", 235 dev_dbg(dev, "cpu : %s / %04x / %d\n",
180 info->cpu_dai.name, 236 dai_link->cpu_dai_name,
181 info->cpu_dai.fmt, 237 cpu_dai->fmt,
182 info->cpu_dai.sysclk); 238 cpu_dai->sysclk);
183 dev_dbg(dev, "codec : %s / %04x / %d\n", 239 dev_dbg(dev, "codec : %s / %04x / %d\n",
184 info->codec_dai.name, 240 dai_link->codec_dai_name,
185 info->codec_dai.fmt, 241 codec_dai->fmt,
186 info->codec_dai.sysclk); 242 codec_dai->sysclk);
243
244 /*
245 * soc_bind_dai_link() will check cpu name
246 * after of_node matching if dai_link has cpu_dai_name.
247 * but, it will never match if name was created by fmt_single_name()
248 * remove cpu_dai_name to escape name matching.
249 * see
250 * fmt_single_name()
251 * fmt_multiple_name()
252 */
253 dai_link->cpu_dai_name = NULL;
187 254
188 return 0; 255 return 0;
189} 256}
190 257
258/* update the reference count of the devices nodes at end of probe */
259static int asoc_simple_card_unref(struct platform_device *pdev)
260{
261 struct snd_soc_card *card = platform_get_drvdata(pdev);
262 struct snd_soc_dai_link *dai_link;
263 struct device_node *np;
264 int num_links;
265
266 for (num_links = 0, dai_link = card->dai_link;
267 num_links < card->num_links;
268 num_links++, dai_link++) {
269 np = (struct device_node *) dai_link->cpu_of_node;
270 if (np)
271 of_node_put(np);
272 np = (struct device_node *) dai_link->codec_of_node;
273 if (np)
274 of_node_put(np);
275 }
276 return 0;
277}
278
191static int asoc_simple_card_probe(struct platform_device *pdev) 279static int asoc_simple_card_probe(struct platform_device *pdev)
192{ 280{
193 struct asoc_simple_card_info *cinfo; 281 struct simple_card_data *priv;
282 struct snd_soc_dai_link *dai_link;
194 struct device_node *np = pdev->dev.of_node; 283 struct device_node *np = pdev->dev.of_node;
195 struct device_node *of_cpu, *of_codec, *of_platform;
196 struct device *dev = &pdev->dev; 284 struct device *dev = &pdev->dev;
197 int ret; 285 int ret;
198 286
199 cinfo = NULL; 287 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
200 of_cpu = NULL; 288 if (!priv)
201 of_codec = NULL;
202 of_platform = NULL;
203
204 cinfo = devm_kzalloc(dev, sizeof(*cinfo), GFP_KERNEL);
205 if (!cinfo)
206 return -ENOMEM; 289 return -ENOMEM;
207 290
291 /*
292 * init snd_soc_card
293 */
294 priv->snd_card.owner = THIS_MODULE;
295 priv->snd_card.dev = dev;
296 dai_link = &priv->snd_link;
297 priv->snd_card.dai_link = dai_link;
298 priv->snd_card.num_links = 1;
299
208 if (np && of_device_is_available(np)) { 300 if (np && of_device_is_available(np)) {
209 cinfo->snd_card.dev = dev;
210 301
211 ret = asoc_simple_card_parse_of(np, cinfo, dev, 302 ret = asoc_simple_card_parse_of(np, priv, dev);
212 &of_cpu,
213 &of_codec,
214 &of_platform);
215 if (ret < 0) { 303 if (ret < 0) {
216 if (ret != -EPROBE_DEFER) 304 if (ret != -EPROBE_DEFER)
217 dev_err(dev, "parse error %d\n", ret); 305 dev_err(dev, "parse error %d\n", ret);
218 return ret; 306 goto err;
219 } 307 }
220 } else { 308 } else {
221 if (!dev->platform_data) { 309 struct asoc_simple_card_info *cinfo;
310
311 cinfo = dev->platform_data;
312 if (!cinfo) {
222 dev_err(dev, "no info for asoc-simple-card\n"); 313 dev_err(dev, "no info for asoc-simple-card\n");
223 return -EINVAL; 314 return -EINVAL;
224 } 315 }
225 316
226 memcpy(cinfo, dev->platform_data, sizeof(*cinfo)); 317 if (!cinfo->name ||
227 cinfo->snd_card.dev = dev; 318 !cinfo->codec_dai.name ||
228 } 319 !cinfo->codec ||
320 !cinfo->platform ||
321 !cinfo->cpu_dai.name) {
322 dev_err(dev, "insufficient asoc_simple_card_info settings\n");
323 return -EINVAL;
324 }
229 325
230 if (!cinfo->name || 326 priv->snd_card.name = (cinfo->card) ? cinfo->card : cinfo->name;
231 !cinfo->card || 327 dai_link->name = cinfo->name;
232 !cinfo->codec_dai.name || 328 dai_link->stream_name = cinfo->name;
233 !(cinfo->codec || of_codec) || 329 dai_link->platform_name = cinfo->platform;
234 !(cinfo->platform || of_platform) || 330 dai_link->codec_name = cinfo->codec;
235 !(cinfo->cpu_dai.name || of_cpu)) { 331 dai_link->cpu_dai_name = cinfo->cpu_dai.name;
236 dev_err(dev, "insufficient asoc_simple_card_info settings\n"); 332 dai_link->codec_dai_name = cinfo->codec_dai.name;
237 return -EINVAL; 333 memcpy(&priv->cpu_dai, &cinfo->cpu_dai,
334 sizeof(priv->cpu_dai));
335 memcpy(&priv->codec_dai, &cinfo->codec_dai,
336 sizeof(priv->codec_dai));
337
338 priv->cpu_dai.fmt |= cinfo->daifmt;
339 priv->codec_dai.fmt |= cinfo->daifmt;
238 } 340 }
239 341
240 /* 342 /*
241 * init snd_soc_dai_link 343 * init snd_soc_dai_link
242 */ 344 */
243 cinfo->snd_link.name = cinfo->name; 345 dai_link->init = asoc_simple_card_dai_init;
244 cinfo->snd_link.stream_name = cinfo->name;
245 cinfo->snd_link.cpu_dai_name = cinfo->cpu_dai.name;
246 cinfo->snd_link.platform_name = cinfo->platform;
247 cinfo->snd_link.codec_name = cinfo->codec;
248 cinfo->snd_link.codec_dai_name = cinfo->codec_dai.name;
249 cinfo->snd_link.cpu_of_node = of_cpu;
250 cinfo->snd_link.codec_of_node = of_codec;
251 cinfo->snd_link.platform_of_node = of_platform;
252 cinfo->snd_link.init = asoc_simple_card_dai_init;
253 346
254 /* 347 snd_soc_card_set_drvdata(&priv->snd_card, priv);
255 * init snd_soc_card
256 */
257 cinfo->snd_card.name = cinfo->card;
258 cinfo->snd_card.owner = THIS_MODULE;
259 cinfo->snd_card.dai_link = &cinfo->snd_link;
260 cinfo->snd_card.num_links = 1;
261 348
262 snd_soc_card_set_drvdata(&cinfo->snd_card, cinfo); 349 ret = devm_snd_soc_register_card(&pdev->dev, &priv->snd_card);
263 350
264 return devm_snd_soc_register_card(&pdev->dev, &cinfo->snd_card); 351err:
352 asoc_simple_card_unref(pdev);
353 return ret;
265} 354}
266 355
267static const struct of_device_id asoc_simple_of_match[] = { 356static const struct of_device_id asoc_simple_of_match[] = {
diff --git a/sound/soc/intel/Kconfig b/sound/soc/intel/Kconfig
index 61c10bf503d2..3c81b3891209 100644
--- a/sound/soc/intel/Kconfig
+++ b/sound/soc/intel/Kconfig
@@ -2,12 +2,50 @@ config SND_MFLD_MACHINE
2 tristate "SOC Machine Audio driver for Intel Medfield MID platform" 2 tristate "SOC Machine Audio driver for Intel Medfield MID platform"
3 depends on INTEL_SCU_IPC 3 depends on INTEL_SCU_IPC
4 select SND_SOC_SN95031 4 select SND_SOC_SN95031
5 select SND_SST_PLATFORM 5 select SND_SST_MFLD_PLATFORM
6 help 6 help
7 This adds support for ASoC machine driver for Intel(R) MID Medfield platform 7 This adds support for ASoC machine driver for Intel(R) MID Medfield platform
8 used as alsa device in audio substem in Intel(R) MID devices 8 used as alsa device in audio substem in Intel(R) MID devices
9 Say Y if you have such a device 9 Say Y if you have such a device
10 If unsure select "N". 10 If unsure select "N".
11 11
12config SND_SST_PLATFORM 12config SND_SST_MFLD_PLATFORM
13 tristate 13 tristate
14
15config SND_SOC_INTEL_SST
16 tristate "ASoC support for Intel(R) Smart Sound Technology"
17 select SND_SOC_INTEL_SST_ACPI if ACPI
18 depends on (X86 || COMPILE_TEST)
19 help
20 This adds support for Intel(R) Smart Sound Technology (SST).
21 Say Y if you have such a device
22 If unsure select "N".
23
24config SND_SOC_INTEL_SST_ACPI
25 tristate
26
27config SND_SOC_INTEL_HASWELL
28 tristate
29
30config SND_SOC_INTEL_BAYTRAIL
31 tristate
32
33config SND_SOC_INTEL_HASWELL_MACH
34 tristate "ASoC Audio DSP support for Intel Haswell Lynxpoint"
35 depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS && I2C
36 select SND_SOC_INTEL_HASWELL
37 select SND_SOC_RT5640
38 help
39 This adds support for the Lynxpoint Audio DSP on Intel(R) Haswell
40 Ultrabook platforms.
41 Say Y if you have such a device
42 If unsure select "N".
43
44config SND_SOC_INTEL_BYT_RT5640_MACH
45 tristate "ASoC Audio driver for Intel Baytrail with RT5640 codec"
46 depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS && I2C
47 select SND_SOC_INTEL_BAYTRAIL
48 select SND_SOC_RT5640
49 help
50 This adds audio driver for Intel Baytrail platform based boards
51 with the RT5640 audio codec.
diff --git a/sound/soc/intel/Makefile b/sound/soc/intel/Makefile
index 639883339465..edeb79ae3dff 100644
--- a/sound/soc/intel/Makefile
+++ b/sound/soc/intel/Makefile
@@ -1,5 +1,28 @@
1snd-soc-sst-platform-objs := sst_platform.o 1# Core support
2snd-soc-sst-dsp-objs := sst-dsp.o sst-firmware.o
3snd-soc-sst-acpi-objs := sst-acpi.o
4
5snd-soc-sst-mfld-platform-objs := sst-mfld-platform.o
2snd-soc-mfld-machine-objs := mfld_machine.o 6snd-soc-mfld-machine-objs := mfld_machine.o
3 7
4obj-$(CONFIG_SND_SST_PLATFORM) += snd-soc-sst-platform.o 8obj-$(CONFIG_SND_SST_MFLD_PLATFORM) += snd-soc-sst-mfld-platform.o
5obj-$(CONFIG_SND_MFLD_MACHINE) += snd-soc-mfld-machine.o 9obj-$(CONFIG_SND_MFLD_MACHINE) += snd-soc-mfld-machine.o
10
11obj-$(CONFIG_SND_SOC_INTEL_SST) += snd-soc-sst-dsp.o
12obj-$(CONFIG_SND_SOC_INTEL_SST_ACPI) += snd-soc-sst-acpi.o
13
14# Platform Support
15snd-soc-sst-haswell-pcm-objs := \
16 sst-haswell-ipc.o sst-haswell-pcm.o sst-haswell-dsp.o
17snd-soc-sst-baytrail-pcm-objs := \
18 sst-baytrail-ipc.o sst-baytrail-pcm.o sst-baytrail-dsp.o
19
20obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += snd-soc-sst-haswell-pcm.o
21obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += snd-soc-sst-baytrail-pcm.o
22
23# Machine support
24snd-soc-sst-haswell-objs := haswell.o
25snd-soc-sst-byt-rt5640-mach-objs := byt-rt5640.o
26
27obj-$(CONFIG_SND_SOC_INTEL_HASWELL_MACH) += snd-soc-sst-haswell.o
28obj-$(CONFIG_SND_SOC_INTEL_BYT_RT5640_MACH) += snd-soc-sst-byt-rt5640-mach.o
diff --git a/sound/soc/intel/byt-rt5640.c b/sound/soc/intel/byt-rt5640.c
new file mode 100644
index 000000000000..eff97c8e5218
--- /dev/null
+++ b/sound/soc/intel/byt-rt5640.c
@@ -0,0 +1,187 @@
1/*
2 * Intel Baytrail SST RT5640 machine driver
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/acpi.h>
19#include <linux/device.h>
20#include <linux/slab.h>
21#include <sound/pcm.h>
22#include <sound/pcm_params.h>
23#include <sound/soc.h>
24#include <sound/jack.h>
25#include "../codecs/rt5640.h"
26
27#include "sst-dsp.h"
28
29static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
30 SND_SOC_DAPM_HP("Headphone", NULL),
31 SND_SOC_DAPM_MIC("Headset Mic", NULL),
32 SND_SOC_DAPM_MIC("Internal Mic", NULL),
33 SND_SOC_DAPM_SPK("Speaker", NULL),
34};
35
36static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
37 {"IN2P", NULL, "Headset Mic"},
38 {"IN2N", NULL, "Headset Mic"},
39 {"DMIC1", NULL, "Internal Mic"},
40 {"Headphone", NULL, "HPOL"},
41 {"Headphone", NULL, "HPOR"},
42 {"Speaker", NULL, "SPOLP"},
43 {"Speaker", NULL, "SPOLN"},
44 {"Speaker", NULL, "SPORP"},
45 {"Speaker", NULL, "SPORN"},
46};
47
48static const struct snd_kcontrol_new byt_rt5640_controls[] = {
49 SOC_DAPM_PIN_SWITCH("Headphone"),
50 SOC_DAPM_PIN_SWITCH("Headset Mic"),
51 SOC_DAPM_PIN_SWITCH("Internal Mic"),
52 SOC_DAPM_PIN_SWITCH("Speaker"),
53};
54
55static int byt_rt5640_hw_params(struct snd_pcm_substream *substream,
56 struct snd_pcm_hw_params *params)
57{
58 struct snd_soc_pcm_runtime *rtd = substream->private_data;
59 struct snd_soc_dai *codec_dai = rtd->codec_dai;
60 int ret;
61
62 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
63 params_rate(params) * 256,
64 SND_SOC_CLOCK_IN);
65 if (ret < 0) {
66 dev_err(codec_dai->dev, "can't set codec clock %d\n", ret);
67 return ret;
68 }
69 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
70 params_rate(params) * 64,
71 params_rate(params) * 256);
72 if (ret < 0) {
73 dev_err(codec_dai->dev, "can't set codec pll: %d\n", ret);
74 return ret;
75 }
76 return 0;
77}
78
79static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
80{
81 int ret;
82 struct snd_soc_codec *codec = runtime->codec;
83 struct snd_soc_dapm_context *dapm = &codec->dapm;
84 struct snd_soc_card *card = runtime->card;
85
86 card->dapm.idle_bias_off = true;
87
88 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
89 ARRAY_SIZE(byt_rt5640_controls));
90 if (ret) {
91 dev_err(card->dev, "unable to add card controls\n");
92 return ret;
93 }
94
95 snd_soc_dapm_ignore_suspend(dapm, "HPOL");
96 snd_soc_dapm_ignore_suspend(dapm, "HPOR");
97
98 snd_soc_dapm_ignore_suspend(dapm, "SPOLP");
99 snd_soc_dapm_ignore_suspend(dapm, "SPOLN");
100 snd_soc_dapm_ignore_suspend(dapm, "SPORP");
101 snd_soc_dapm_ignore_suspend(dapm, "SPORN");
102
103 snd_soc_dapm_enable_pin(dapm, "Headset Mic");
104 snd_soc_dapm_enable_pin(dapm, "Headphone");
105 snd_soc_dapm_enable_pin(dapm, "Speaker");
106 snd_soc_dapm_enable_pin(dapm, "Internal Mic");
107
108 snd_soc_dapm_sync(dapm);
109 return ret;
110}
111
112static struct snd_soc_ops byt_rt5640_ops = {
113 .hw_params = byt_rt5640_hw_params,
114};
115
116static struct snd_soc_dai_link byt_rt5640_dais[] = {
117 {
118 .name = "Baytrail Audio",
119 .stream_name = "Audio",
120 .cpu_dai_name = "Front-cpu-dai",
121 .codec_dai_name = "rt5640-aif1",
122 .codec_name = "i2c-10EC5640:00",
123 .platform_name = "baytrail-pcm-audio",
124 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
125 SND_SOC_DAIFMT_CBS_CFS,
126 .init = byt_rt5640_init,
127 .ignore_suspend = 1,
128 .ops = &byt_rt5640_ops,
129 },
130 {
131 .name = "Baytrail Voice",
132 .stream_name = "Voice",
133 .cpu_dai_name = "Mic1-cpu-dai",
134 .codec_dai_name = "rt5640-aif1",
135 .codec_name = "i2c-10EC5640:00",
136 .platform_name = "baytrail-pcm-audio",
137 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
138 SND_SOC_DAIFMT_CBS_CFS,
139 .init = NULL,
140 .ignore_suspend = 1,
141 .ops = &byt_rt5640_ops,
142 },
143};
144
145static struct snd_soc_card byt_rt5640_card = {
146 .name = "byt-rt5640",
147 .dai_link = byt_rt5640_dais,
148 .num_links = ARRAY_SIZE(byt_rt5640_dais),
149 .dapm_widgets = byt_rt5640_widgets,
150 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
151 .dapm_routes = byt_rt5640_audio_map,
152 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
153};
154
155static int byt_rt5640_probe(struct platform_device *pdev)
156{
157 struct snd_soc_card *card = &byt_rt5640_card;
158 struct device *dev = &pdev->dev;
159
160 card->dev = &pdev->dev;
161 dev_set_drvdata(dev, card);
162 return snd_soc_register_card(card);
163}
164
165static int byt_rt5640_remove(struct platform_device *pdev)
166{
167 struct snd_soc_card *card = platform_get_drvdata(pdev);
168
169 snd_soc_unregister_card(card);
170
171 return 0;
172}
173
174static struct platform_driver byt_rt5640_audio = {
175 .probe = byt_rt5640_probe,
176 .remove = byt_rt5640_remove,
177 .driver = {
178 .name = "byt-rt5640",
179 .owner = THIS_MODULE,
180 },
181};
182module_platform_driver(byt_rt5640_audio)
183
184MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
185MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
186MODULE_LICENSE("GPL v2");
187MODULE_ALIAS("platform:byt-rt5640");
diff --git a/sound/soc/intel/haswell.c b/sound/soc/intel/haswell.c
new file mode 100644
index 000000000000..54345a2a7386
--- /dev/null
+++ b/sound/soc/intel/haswell.c
@@ -0,0 +1,235 @@
1/*
2 * Intel Haswell Lynxpoint SST Audio
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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 version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/soc.h>
22#include <sound/pcm_params.h>
23
24#include "sst-dsp.h"
25#include "sst-haswell-ipc.h"
26
27#include "../codecs/rt5640.h"
28
29/* Haswell ULT platforms have a Headphone and Mic jack */
30static const struct snd_soc_dapm_widget haswell_widgets[] = {
31 SND_SOC_DAPM_HP("Headphones", NULL),
32 SND_SOC_DAPM_MIC("Mic", NULL),
33};
34
35static const struct snd_soc_dapm_route haswell_rt5640_map[] = {
36
37 {"Headphones", NULL, "HPOR"},
38 {"Headphones", NULL, "HPOL"},
39 {"IN2P", NULL, "Mic"},
40
41 /* CODEC BE connections */
42 {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
43 {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
44};
45
46static int haswell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
47 struct snd_pcm_hw_params *params)
48{
49 struct snd_interval *rate = hw_param_interval(params,
50 SNDRV_PCM_HW_PARAM_RATE);
51 struct snd_interval *channels = hw_param_interval(params,
52 SNDRV_PCM_HW_PARAM_CHANNELS);
53
54 /* The ADSP will covert the FE rate to 48k, stereo */
55 rate->min = rate->max = 48000;
56 channels->min = channels->max = 2;
57
58 /* set SSP0 to 16 bit */
59 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
60 SNDRV_PCM_HW_PARAM_FIRST_MASK],
61 SNDRV_PCM_FORMAT_S16_LE);
62 return 0;
63}
64
65static int haswell_rt5640_hw_params(struct snd_pcm_substream *substream,
66 struct snd_pcm_hw_params *params)
67{
68 struct snd_soc_pcm_runtime *rtd = substream->private_data;
69 struct snd_soc_dai *codec_dai = rtd->codec_dai;
70 int ret;
71
72 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_MCLK, 12288000,
73 SND_SOC_CLOCK_IN);
74
75 if (ret < 0) {
76 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
77 return ret;
78 }
79
80 /* set correct codec filter for DAI format and clock config */
81 snd_soc_update_bits(rtd->codec, 0x83, 0xffff, 0x8000);
82
83 return ret;
84}
85
86static struct snd_soc_ops haswell_rt5640_ops = {
87 .hw_params = haswell_rt5640_hw_params,
88};
89
90static int haswell_rtd_init(struct snd_soc_pcm_runtime *rtd)
91{
92 struct snd_soc_codec *codec = rtd->codec;
93 struct snd_soc_dapm_context *dapm = &codec->dapm;
94 struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
95 struct sst_hsw *haswell = pdata->dsp;
96 int ret;
97
98 /* Set ADSP SSP port settings */
99 ret = sst_hsw_device_set_config(haswell, SST_HSW_DEVICE_SSP_0,
100 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
101 SST_HSW_DEVICE_CLOCK_MASTER, 9);
102 if (ret < 0) {
103 dev_err(rtd->dev, "failed to set device config\n");
104 return ret;
105 }
106
107 /* always connected */
108 snd_soc_dapm_enable_pin(dapm, "Headphones");
109 snd_soc_dapm_enable_pin(dapm, "Mic");
110
111 return 0;
112}
113
114static struct snd_soc_dai_link haswell_rt5640_dais[] = {
115 /* Front End DAI links */
116 {
117 .name = "System",
118 .stream_name = "System Playback",
119 .cpu_dai_name = "System Pin",
120 .platform_name = "haswell-pcm-audio",
121 .dynamic = 1,
122 .codec_name = "snd-soc-dummy",
123 .codec_dai_name = "snd-soc-dummy-dai",
124 .init = haswell_rtd_init,
125 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
126 .dpcm_playback = 1,
127 },
128 {
129 .name = "Offload0",
130 .stream_name = "Offload0 Playback",
131 .cpu_dai_name = "Offload0 Pin",
132 .platform_name = "haswell-pcm-audio",
133 .dynamic = 1,
134 .codec_name = "snd-soc-dummy",
135 .codec_dai_name = "snd-soc-dummy-dai",
136 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
137 .dpcm_playback = 1,
138 },
139 {
140 .name = "Offload1",
141 .stream_name = "Offload1 Playback",
142 .cpu_dai_name = "Offload1 Pin",
143 .platform_name = "haswell-pcm-audio",
144 .dynamic = 1,
145 .codec_name = "snd-soc-dummy",
146 .codec_dai_name = "snd-soc-dummy-dai",
147 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
148 .dpcm_playback = 1,
149 },
150 {
151 .name = "Loopback",
152 .stream_name = "Loopback",
153 .cpu_dai_name = "Loopback Pin",
154 .platform_name = "haswell-pcm-audio",
155 .dynamic = 0,
156 .codec_name = "snd-soc-dummy",
157 .codec_dai_name = "snd-soc-dummy-dai",
158 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
159 .dpcm_capture = 1,
160 },
161 {
162 .name = "Capture",
163 .stream_name = "Capture",
164 .cpu_dai_name = "Capture Pin",
165 .platform_name = "haswell-pcm-audio",
166 .dynamic = 1,
167 .codec_name = "snd-soc-dummy",
168 .codec_dai_name = "snd-soc-dummy-dai",
169 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
170 .dpcm_capture = 1,
171 },
172
173 /* Back End DAI links */
174 {
175 /* SSP0 - Codec */
176 .name = "Codec",
177 .be_id = 0,
178 .cpu_dai_name = "snd-soc-dummy-dai",
179 .platform_name = "snd-soc-dummy",
180 .no_pcm = 1,
181 .codec_name = "i2c-INT33CA:00",
182 .codec_dai_name = "rt5640-aif1",
183 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
184 SND_SOC_DAIFMT_CBS_CFS,
185 .ignore_suspend = 1,
186 .ignore_pmdown_time = 1,
187 .be_hw_params_fixup = haswell_ssp0_fixup,
188 .ops = &haswell_rt5640_ops,
189 .dpcm_playback = 1,
190 .dpcm_capture = 1,
191 },
192};
193
194/* audio machine driver for Haswell Lynxpoint DSP + RT5640 */
195static struct snd_soc_card haswell_rt5640 = {
196 .name = "haswell-rt5640",
197 .owner = THIS_MODULE,
198 .dai_link = haswell_rt5640_dais,
199 .num_links = ARRAY_SIZE(haswell_rt5640_dais),
200 .dapm_widgets = haswell_widgets,
201 .num_dapm_widgets = ARRAY_SIZE(haswell_widgets),
202 .dapm_routes = haswell_rt5640_map,
203 .num_dapm_routes = ARRAY_SIZE(haswell_rt5640_map),
204 .fully_routed = true,
205};
206
207static int haswell_audio_probe(struct platform_device *pdev)
208{
209 haswell_rt5640.dev = &pdev->dev;
210
211 return snd_soc_register_card(&haswell_rt5640);
212}
213
214static int haswell_audio_remove(struct platform_device *pdev)
215{
216 snd_soc_unregister_card(&haswell_rt5640);
217 return 0;
218}
219
220static struct platform_driver haswell_audio = {
221 .probe = haswell_audio_probe,
222 .remove = haswell_audio_remove,
223 .driver = {
224 .name = "haswell-audio",
225 .owner = THIS_MODULE,
226 },
227};
228
229module_platform_driver(haswell_audio)
230
231/* Module information */
232MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
233MODULE_DESCRIPTION("Intel SST Audio for Haswell Lynxpoint");
234MODULE_LICENSE("GPL v2");
235MODULE_ALIAS("platform:haswell-audio");
diff --git a/sound/soc/intel/mfld_machine.c b/sound/soc/intel/mfld_machine.c
index d3d4c32434f7..031d78783fc8 100644
--- a/sound/soc/intel/mfld_machine.c
+++ b/sound/soc/intel/mfld_machine.c
@@ -53,6 +53,7 @@ enum soc_mic_bias_zones {
53 53
54static unsigned int hs_switch; 54static unsigned int hs_switch;
55static unsigned int lo_dac; 55static unsigned int lo_dac;
56static struct snd_soc_codec *mfld_codec;
56 57
57struct mfld_mc_private { 58struct mfld_mc_private {
58 void __iomem *int_base; 59 void __iomem *int_base;
@@ -100,40 +101,47 @@ static int headset_get_switch(struct snd_kcontrol *kcontrol,
100static int headset_set_switch(struct snd_kcontrol *kcontrol, 101static int headset_set_switch(struct snd_kcontrol *kcontrol,
101 struct snd_ctl_elem_value *ucontrol) 102 struct snd_ctl_elem_value *ucontrol)
102{ 103{
103 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 104 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
105 struct snd_soc_dapm_context *dapm = &card->dapm;
104 106
105 if (ucontrol->value.integer.value[0] == hs_switch) 107 if (ucontrol->value.integer.value[0] == hs_switch)
106 return 0; 108 return 0;
107 109
110 snd_soc_dapm_mutex_lock(dapm);
111
108 if (ucontrol->value.integer.value[0]) { 112 if (ucontrol->value.integer.value[0]) {
109 pr_debug("hs_set HS path\n"); 113 pr_debug("hs_set HS path\n");
110 snd_soc_dapm_enable_pin(&codec->dapm, "Headphones"); 114 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphones");
111 snd_soc_dapm_disable_pin(&codec->dapm, "EPOUT"); 115 snd_soc_dapm_disable_pin_unlocked(dapm, "EPOUT");
112 } else { 116 } else {
113 pr_debug("hs_set EP path\n"); 117 pr_debug("hs_set EP path\n");
114 snd_soc_dapm_disable_pin(&codec->dapm, "Headphones"); 118 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphones");
115 snd_soc_dapm_enable_pin(&codec->dapm, "EPOUT"); 119 snd_soc_dapm_enable_pin_unlocked(dapm, "EPOUT");
116 } 120 }
117 snd_soc_dapm_sync(&codec->dapm); 121
122 snd_soc_dapm_sync_unlocked(dapm);
123
124 snd_soc_dapm_mutex_unlock(dapm);
125
118 hs_switch = ucontrol->value.integer.value[0]; 126 hs_switch = ucontrol->value.integer.value[0];
119 127
120 return 0; 128 return 0;
121} 129}
122 130
123static void lo_enable_out_pins(struct snd_soc_codec *codec) 131static void lo_enable_out_pins(struct snd_soc_dapm_context *dapm)
124{ 132{
125 snd_soc_dapm_enable_pin(&codec->dapm, "IHFOUTL"); 133 snd_soc_dapm_enable_pin_unlocked(dapm, "IHFOUTL");
126 snd_soc_dapm_enable_pin(&codec->dapm, "IHFOUTR"); 134 snd_soc_dapm_enable_pin_unlocked(dapm, "IHFOUTR");
127 snd_soc_dapm_enable_pin(&codec->dapm, "LINEOUTL"); 135 snd_soc_dapm_enable_pin_unlocked(dapm, "LINEOUTL");
128 snd_soc_dapm_enable_pin(&codec->dapm, "LINEOUTR"); 136 snd_soc_dapm_enable_pin_unlocked(dapm, "LINEOUTR");
129 snd_soc_dapm_enable_pin(&codec->dapm, "VIB1OUT"); 137 snd_soc_dapm_enable_pin_unlocked(dapm, "VIB1OUT");
130 snd_soc_dapm_enable_pin(&codec->dapm, "VIB2OUT"); 138 snd_soc_dapm_enable_pin_unlocked(dapm, "VIB2OUT");
131 if (hs_switch) { 139 if (hs_switch) {
132 snd_soc_dapm_enable_pin(&codec->dapm, "Headphones"); 140 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphones");
133 snd_soc_dapm_disable_pin(&codec->dapm, "EPOUT"); 141 snd_soc_dapm_disable_pin_unlocked(dapm, "EPOUT");
134 } else { 142 } else {
135 snd_soc_dapm_disable_pin(&codec->dapm, "Headphones"); 143 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphones");
136 snd_soc_dapm_enable_pin(&codec->dapm, "EPOUT"); 144 snd_soc_dapm_enable_pin_unlocked(dapm, "EPOUT");
137 } 145 }
138} 146}
139 147
@@ -147,45 +155,53 @@ static int lo_get_switch(struct snd_kcontrol *kcontrol,
147static int lo_set_switch(struct snd_kcontrol *kcontrol, 155static int lo_set_switch(struct snd_kcontrol *kcontrol,
148 struct snd_ctl_elem_value *ucontrol) 156 struct snd_ctl_elem_value *ucontrol)
149{ 157{
150 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 158 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
159 struct snd_soc_dapm_context *dapm = &card->dapm;
151 160
152 if (ucontrol->value.integer.value[0] == lo_dac) 161 if (ucontrol->value.integer.value[0] == lo_dac)
153 return 0; 162 return 0;
154 163
164 snd_soc_dapm_mutex_lock(dapm);
165
155 /* we dont want to work with last state of lineout so just enable all 166 /* we dont want to work with last state of lineout so just enable all
156 * pins and then disable pins not required 167 * pins and then disable pins not required
157 */ 168 */
158 lo_enable_out_pins(codec); 169 lo_enable_out_pins(dapm);
170
159 switch (ucontrol->value.integer.value[0]) { 171 switch (ucontrol->value.integer.value[0]) {
160 case 0: 172 case 0:
161 pr_debug("set vibra path\n"); 173 pr_debug("set vibra path\n");
162 snd_soc_dapm_disable_pin(&codec->dapm, "VIB1OUT"); 174 snd_soc_dapm_disable_pin_unlocked(dapm, "VIB1OUT");
163 snd_soc_dapm_disable_pin(&codec->dapm, "VIB2OUT"); 175 snd_soc_dapm_disable_pin_unlocked(dapm, "VIB2OUT");
164 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0); 176 snd_soc_update_bits(mfld_codec, SN95031_LOCTL, 0x66, 0);
165 break; 177 break;
166 178
167 case 1: 179 case 1:
168 pr_debug("set hs path\n"); 180 pr_debug("set hs path\n");
169 snd_soc_dapm_disable_pin(&codec->dapm, "Headphones"); 181 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphones");
170 snd_soc_dapm_disable_pin(&codec->dapm, "EPOUT"); 182 snd_soc_dapm_disable_pin_unlocked(dapm, "EPOUT");
171 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0x22); 183 snd_soc_update_bits(mfld_codec, SN95031_LOCTL, 0x66, 0x22);
172 break; 184 break;
173 185
174 case 2: 186 case 2:
175 pr_debug("set spkr path\n"); 187 pr_debug("set spkr path\n");
176 snd_soc_dapm_disable_pin(&codec->dapm, "IHFOUTL"); 188 snd_soc_dapm_disable_pin_unlocked(dapm, "IHFOUTL");
177 snd_soc_dapm_disable_pin(&codec->dapm, "IHFOUTR"); 189 snd_soc_dapm_disable_pin_unlocked(dapm, "IHFOUTR");
178 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0x44); 190 snd_soc_update_bits(mfld_codec, SN95031_LOCTL, 0x66, 0x44);
179 break; 191 break;
180 192
181 case 3: 193 case 3:
182 pr_debug("set null path\n"); 194 pr_debug("set null path\n");
183 snd_soc_dapm_disable_pin(&codec->dapm, "LINEOUTL"); 195 snd_soc_dapm_disable_pin_unlocked(dapm, "LINEOUTL");
184 snd_soc_dapm_disable_pin(&codec->dapm, "LINEOUTR"); 196 snd_soc_dapm_disable_pin_unlocked(dapm, "LINEOUTR");
185 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0x66); 197 snd_soc_update_bits(mfld_codec, SN95031_LOCTL, 0x66, 0x66);
186 break; 198 break;
187 } 199 }
188 snd_soc_dapm_sync(&codec->dapm); 200
201 snd_soc_dapm_sync_unlocked(dapm);
202
203 snd_soc_dapm_mutex_unlock(dapm);
204
189 lo_dac = ucontrol->value.integer.value[0]; 205 lo_dac = ucontrol->value.integer.value[0];
190 return 0; 206 return 0;
191} 207}
@@ -221,26 +237,11 @@ static void mfld_jack_check(unsigned int intr_status)
221 237
222static int mfld_init(struct snd_soc_pcm_runtime *runtime) 238static int mfld_init(struct snd_soc_pcm_runtime *runtime)
223{ 239{
224 struct snd_soc_codec *codec = runtime->codec; 240 struct snd_soc_dapm_context *dapm = &runtime->card->dapm;
225 struct snd_soc_dapm_context *dapm = &codec->dapm;
226 int ret_val; 241 int ret_val;
227 242
228 /* Add jack sense widgets */ 243 mfld_codec = runtime->codec;
229 snd_soc_dapm_new_controls(dapm, mfld_widgets, ARRAY_SIZE(mfld_widgets));
230
231 /* Set up the map */
232 snd_soc_dapm_add_routes(dapm, mfld_map, ARRAY_SIZE(mfld_map));
233 244
234 /* always connected */
235 snd_soc_dapm_enable_pin(dapm, "Headphones");
236 snd_soc_dapm_enable_pin(dapm, "Mic");
237
238 ret_val = snd_soc_add_codec_controls(codec, mfld_snd_controls,
239 ARRAY_SIZE(mfld_snd_controls));
240 if (ret_val) {
241 pr_err("soc_add_controls failed %d", ret_val);
242 return ret_val;
243 }
244 /* default is earpiece pin, userspace sets it explcitly */ 245 /* default is earpiece pin, userspace sets it explcitly */
245 snd_soc_dapm_disable_pin(dapm, "Headphones"); 246 snd_soc_dapm_disable_pin(dapm, "Headphones");
246 /* default is lineout NC, userspace sets it explcitly */ 247 /* default is lineout NC, userspace sets it explcitly */
@@ -253,7 +254,7 @@ static int mfld_init(struct snd_soc_pcm_runtime *runtime)
253 snd_soc_dapm_disable_pin(dapm, "LINEINR"); 254 snd_soc_dapm_disable_pin(dapm, "LINEINR");
254 255
255 /* Headset and button jack detection */ 256 /* Headset and button jack detection */
256 ret_val = snd_soc_jack_new(codec, "Intel(R) MID Audio Jack", 257 ret_val = snd_soc_jack_new(mfld_codec, "Intel(R) MID Audio Jack",
257 SND_JACK_HEADSET | SND_JACK_BTN_0 | 258 SND_JACK_HEADSET | SND_JACK_BTN_0 |
258 SND_JACK_BTN_1, &mfld_jack); 259 SND_JACK_BTN_1, &mfld_jack);
259 if (ret_val) { 260 if (ret_val) {
@@ -335,6 +336,13 @@ static struct snd_soc_card snd_soc_card_mfld = {
335 .owner = THIS_MODULE, 336 .owner = THIS_MODULE,
336 .dai_link = mfld_msic_dailink, 337 .dai_link = mfld_msic_dailink,
337 .num_links = ARRAY_SIZE(mfld_msic_dailink), 338 .num_links = ARRAY_SIZE(mfld_msic_dailink),
339
340 .controls = mfld_snd_controls,
341 .num_controls = ARRAY_SIZE(mfld_snd_controls),
342 .dapm_widgets = mfld_widgets,
343 .num_dapm_widgets = ARRAY_SIZE(mfld_widgets),
344 .dapm_routes = mfld_map,
345 .num_dapm_routes = ARRAY_SIZE(mfld_map),
338}; 346};
339 347
340static irqreturn_t snd_mfld_jack_intr_handler(int irq, void *dev) 348static irqreturn_t snd_mfld_jack_intr_handler(int irq, void *dev)
diff --git a/sound/soc/intel/sst-acpi.c b/sound/soc/intel/sst-acpi.c
new file mode 100644
index 000000000000..5d06eecb6198
--- /dev/null
+++ b/sound/soc/intel/sst-acpi.c
@@ -0,0 +1,284 @@
1/*
2 * Intel SST loader on ACPI systems
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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 version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/acpi.h>
18#include <linux/device.h>
19#include <linux/firmware.h>
20#include <linux/module.h>
21#include <linux/platform_device.h>
22
23#include "sst-dsp.h"
24
25#define SST_LPT_DSP_DMA_ADDR_OFFSET 0x0F0000
26#define SST_WPT_DSP_DMA_ADDR_OFFSET 0x0FE000
27#define SST_LPT_DSP_DMA_SIZE (1024 - 1)
28
29/* Descriptor for SST ASoC machine driver */
30struct sst_acpi_mach {
31 /* ACPI ID for the matching machine driver. Audio codec for instance */
32 const u8 id[ACPI_ID_LEN];
33 /* machine driver name */
34 const char *drv_name;
35 /* firmware file name */
36 const char *fw_filename;
37};
38
39/* Descriptor for setting up SST platform data */
40struct sst_acpi_desc {
41 const char *drv_name;
42 struct sst_acpi_mach *machines;
43 /* Platform resource indexes. Must set to -1 if not used */
44 int resindex_lpe_base;
45 int resindex_pcicfg_base;
46 int resindex_fw_base;
47 int irqindex_host_ipc;
48 int resindex_dma_base;
49 /* Unique number identifying the SST core on platform */
50 int sst_id;
51 /* DMA only valid when resindex_dma_base != -1*/
52 int dma_engine;
53 int dma_size;
54};
55
56struct sst_acpi_priv {
57 struct platform_device *pdev_mach;
58 struct platform_device *pdev_pcm;
59 struct sst_pdata sst_pdata;
60 struct sst_acpi_desc *desc;
61 struct sst_acpi_mach *mach;
62};
63
64static void sst_acpi_fw_cb(const struct firmware *fw, void *context)
65{
66 struct platform_device *pdev = context;
67 struct device *dev = &pdev->dev;
68 struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev);
69 struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata;
70 struct sst_acpi_desc *desc = sst_acpi->desc;
71 struct sst_acpi_mach *mach = sst_acpi->mach;
72
73 sst_pdata->fw = fw;
74 if (!fw) {
75 dev_err(dev, "Cannot load firmware %s\n", mach->fw_filename);
76 return;
77 }
78
79 /* register PCM and DAI driver */
80 sst_acpi->pdev_pcm =
81 platform_device_register_data(dev, desc->drv_name, -1,
82 sst_pdata, sizeof(*sst_pdata));
83 if (IS_ERR(sst_acpi->pdev_pcm)) {
84 dev_err(dev, "Cannot register device %s. Error %d\n",
85 desc->drv_name, (int)PTR_ERR(sst_acpi->pdev_pcm));
86 }
87
88 return;
89}
90
91static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level,
92 void *context, void **ret)
93{
94 *(bool *)context = true;
95 return AE_OK;
96}
97
98static struct sst_acpi_mach *sst_acpi_find_machine(
99 struct sst_acpi_mach *machines)
100{
101 struct sst_acpi_mach *mach;
102 bool found = false;
103
104 for (mach = machines; mach->id[0]; mach++)
105 if (ACPI_SUCCESS(acpi_get_devices(mach->id,
106 sst_acpi_mach_match,
107 &found, NULL)) && found)
108 return mach;
109
110 return NULL;
111}
112
113static int sst_acpi_probe(struct platform_device *pdev)
114{
115 const struct acpi_device_id *id;
116 struct device *dev = &pdev->dev;
117 struct sst_acpi_priv *sst_acpi;
118 struct sst_pdata *sst_pdata;
119 struct sst_acpi_mach *mach;
120 struct sst_acpi_desc *desc;
121 struct resource *mmio;
122 int ret = 0;
123
124 sst_acpi = devm_kzalloc(dev, sizeof(*sst_acpi), GFP_KERNEL);
125 if (sst_acpi == NULL)
126 return -ENOMEM;
127
128 id = acpi_match_device(dev->driver->acpi_match_table, dev);
129 if (!id)
130 return -ENODEV;
131
132 desc = (struct sst_acpi_desc *)id->driver_data;
133 mach = sst_acpi_find_machine(desc->machines);
134 if (mach == NULL) {
135 dev_err(dev, "No matching ASoC machine driver found\n");
136 return -ENODEV;
137 }
138
139 sst_pdata = &sst_acpi->sst_pdata;
140 sst_pdata->id = desc->sst_id;
141 sst_acpi->desc = desc;
142 sst_acpi->mach = mach;
143
144 if (desc->resindex_dma_base >= 0) {
145 sst_pdata->dma_engine = desc->dma_engine;
146 sst_pdata->dma_base = desc->resindex_dma_base;
147 sst_pdata->dma_size = desc->dma_size;
148 }
149
150 if (desc->irqindex_host_ipc >= 0)
151 sst_pdata->irq = platform_get_irq(pdev, desc->irqindex_host_ipc);
152
153 if (desc->resindex_lpe_base >= 0) {
154 mmio = platform_get_resource(pdev, IORESOURCE_MEM,
155 desc->resindex_lpe_base);
156 if (mmio) {
157 sst_pdata->lpe_base = mmio->start;
158 sst_pdata->lpe_size = resource_size(mmio);
159 }
160 }
161
162 if (desc->resindex_pcicfg_base >= 0) {
163 mmio = platform_get_resource(pdev, IORESOURCE_MEM,
164 desc->resindex_pcicfg_base);
165 if (mmio) {
166 sst_pdata->pcicfg_base = mmio->start;
167 sst_pdata->pcicfg_size = resource_size(mmio);
168 }
169 }
170
171 if (desc->resindex_fw_base >= 0) {
172 mmio = platform_get_resource(pdev, IORESOURCE_MEM,
173 desc->resindex_fw_base);
174 if (mmio) {
175 sst_pdata->fw_base = mmio->start;
176 sst_pdata->fw_size = resource_size(mmio);
177 }
178 }
179
180 platform_set_drvdata(pdev, sst_acpi);
181
182 /* register machine driver */
183 sst_acpi->pdev_mach =
184 platform_device_register_data(dev, mach->drv_name, -1,
185 sst_pdata, sizeof(*sst_pdata));
186 if (IS_ERR(sst_acpi->pdev_mach))
187 return PTR_ERR(sst_acpi->pdev_mach);
188
189 /* continue SST probing after firmware is loaded */
190 ret = request_firmware_nowait(THIS_MODULE, true, mach->fw_filename,
191 dev, GFP_KERNEL, pdev, sst_acpi_fw_cb);
192 if (ret)
193 platform_device_unregister(sst_acpi->pdev_mach);
194
195 return ret;
196}
197
198static int sst_acpi_remove(struct platform_device *pdev)
199{
200 struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev);
201 struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata;
202
203 platform_device_unregister(sst_acpi->pdev_mach);
204 if (!IS_ERR_OR_NULL(sst_acpi->pdev_pcm))
205 platform_device_unregister(sst_acpi->pdev_pcm);
206 release_firmware(sst_pdata->fw);
207
208 return 0;
209}
210
211static struct sst_acpi_mach haswell_machines[] = {
212 { "INT33CA", "haswell-audio", "intel/IntcSST1.bin" },
213 {}
214};
215
216static struct sst_acpi_desc sst_acpi_haswell_desc = {
217 .drv_name = "haswell-pcm-audio",
218 .machines = haswell_machines,
219 .resindex_lpe_base = 0,
220 .resindex_pcicfg_base = 1,
221 .resindex_fw_base = -1,
222 .irqindex_host_ipc = 0,
223 .sst_id = SST_DEV_ID_LYNX_POINT,
224 .dma_engine = SST_DMA_TYPE_DW,
225 .resindex_dma_base = SST_LPT_DSP_DMA_ADDR_OFFSET,
226 .dma_size = SST_LPT_DSP_DMA_SIZE,
227};
228
229static struct sst_acpi_mach broadwell_machines[] = {
230 { "INT343A", "broadwell-audio", "intel/IntcSST2.bin" },
231 {}
232};
233
234static struct sst_acpi_desc sst_acpi_broadwell_desc = {
235 .drv_name = "haswell-pcm-audio",
236 .machines = broadwell_machines,
237 .resindex_lpe_base = 0,
238 .resindex_pcicfg_base = 1,
239 .resindex_fw_base = -1,
240 .irqindex_host_ipc = 0,
241 .sst_id = SST_DEV_ID_WILDCAT_POINT,
242 .dma_engine = SST_DMA_TYPE_DW,
243 .resindex_dma_base = SST_WPT_DSP_DMA_ADDR_OFFSET,
244 .dma_size = SST_LPT_DSP_DMA_SIZE,
245};
246
247static struct sst_acpi_mach baytrail_machines[] = {
248 { "10EC5640", "byt-rt5640", "intel/fw_sst_0f28.bin-i2s_master" },
249 {}
250};
251
252static struct sst_acpi_desc sst_acpi_baytrail_desc = {
253 .drv_name = "baytrail-pcm-audio",
254 .machines = baytrail_machines,
255 .resindex_lpe_base = 0,
256 .resindex_pcicfg_base = 1,
257 .resindex_fw_base = 2,
258 .irqindex_host_ipc = 5,
259 .sst_id = SST_DEV_ID_BYT,
260 .resindex_dma_base = -1,
261};
262
263static struct acpi_device_id sst_acpi_match[] = {
264 { "INT33C8", (unsigned long)&sst_acpi_haswell_desc },
265 { "INT3438", (unsigned long)&sst_acpi_broadwell_desc },
266 { "80860F28", (unsigned long)&sst_acpi_baytrail_desc },
267 { }
268};
269MODULE_DEVICE_TABLE(acpi, sst_acpi_match);
270
271static struct platform_driver sst_acpi_driver = {
272 .probe = sst_acpi_probe,
273 .remove = sst_acpi_remove,
274 .driver = {
275 .name = "sst-acpi",
276 .owner = THIS_MODULE,
277 .acpi_match_table = ACPI_PTR(sst_acpi_match),
278 },
279};
280module_platform_driver(sst_acpi_driver);
281
282MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@linux.intel.com>");
283MODULE_DESCRIPTION("Intel SST loader on ACPI systems");
284MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/intel/sst-baytrail-dsp.c b/sound/soc/intel/sst-baytrail-dsp.c
new file mode 100644
index 000000000000..a50bf7fc0e3a
--- /dev/null
+++ b/sound/soc/intel/sst-baytrail-dsp.c
@@ -0,0 +1,372 @@
1/*
2 * Intel Baytrail SST DSP driver
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/delay.h>
16#include <linux/fs.h>
17#include <linux/slab.h>
18#include <linux/device.h>
19#include <linux/interrupt.h>
20#include <linux/module.h>
21#include <linux/dma-mapping.h>
22#include <linux/platform_device.h>
23#include <linux/firmware.h>
24
25#include "sst-dsp.h"
26#include "sst-dsp-priv.h"
27#include "sst-baytrail-ipc.h"
28
29#define SST_BYT_FW_SIGNATURE_SIZE 4
30#define SST_BYT_FW_SIGN "$SST"
31
32#define SST_BYT_IRAM_OFFSET 0xC0000
33#define SST_BYT_DRAM_OFFSET 0x100000
34#define SST_BYT_SHIM_OFFSET 0x140000
35
36enum sst_ram_type {
37 SST_BYT_IRAM = 1,
38 SST_BYT_DRAM = 2,
39 SST_BYT_CACHE = 3,
40};
41
42struct dma_block_info {
43 enum sst_ram_type type; /* IRAM/DRAM */
44 u32 size; /* Bytes */
45 u32 ram_offset; /* Offset in I/DRAM */
46 u32 rsvd; /* Reserved field */
47};
48
49struct fw_header {
50 unsigned char signature[SST_BYT_FW_SIGNATURE_SIZE];
51 u32 file_size; /* size of fw minus this header */
52 u32 modules; /* # of modules */
53 u32 file_format; /* version of header format */
54 u32 reserved[4];
55};
56
57struct sst_byt_fw_module_header {
58 unsigned char signature[SST_BYT_FW_SIGNATURE_SIZE];
59 u32 mod_size; /* size of module */
60 u32 blocks; /* # of blocks */
61 u32 type; /* codec type, pp lib */
62 u32 entry_point;
63};
64
65static int sst_byt_parse_module(struct sst_dsp *dsp, struct sst_fw *fw,
66 struct sst_byt_fw_module_header *module)
67{
68 struct dma_block_info *block;
69 struct sst_module *mod;
70 struct sst_module_data block_data;
71 struct sst_module_template template;
72 int count;
73
74 memset(&template, 0, sizeof(template));
75 template.id = module->type;
76 template.entry = module->entry_point;
77 template.p.type = SST_MEM_DRAM;
78 template.p.data_type = SST_DATA_P;
79 template.s.type = SST_MEM_DRAM;
80 template.s.data_type = SST_DATA_S;
81
82 mod = sst_module_new(fw, &template, NULL);
83 if (mod == NULL)
84 return -ENOMEM;
85
86 block = (void *)module + sizeof(*module);
87
88 for (count = 0; count < module->blocks; count++) {
89
90 if (block->size <= 0) {
91 dev_err(dsp->dev, "block %d size invalid\n", count);
92 return -EINVAL;
93 }
94
95 switch (block->type) {
96 case SST_BYT_IRAM:
97 block_data.offset = block->ram_offset +
98 dsp->addr.iram_offset;
99 block_data.type = SST_MEM_IRAM;
100 break;
101 case SST_BYT_DRAM:
102 block_data.offset = block->ram_offset +
103 dsp->addr.dram_offset;
104 block_data.type = SST_MEM_DRAM;
105 break;
106 case SST_BYT_CACHE:
107 block_data.offset = block->ram_offset +
108 (dsp->addr.fw_ext - dsp->addr.lpe);
109 block_data.type = SST_MEM_CACHE;
110 break;
111 default:
112 dev_err(dsp->dev, "wrong ram type 0x%x in block0x%x\n",
113 block->type, count);
114 return -EINVAL;
115 }
116
117 block_data.size = block->size;
118 block_data.data_type = SST_DATA_M;
119 block_data.data = (void *)block + sizeof(*block);
120
121 sst_module_insert_fixed_block(mod, &block_data);
122
123 block = (void *)block + sizeof(*block) + block->size;
124 }
125 return 0;
126}
127
128static int sst_byt_parse_fw_image(struct sst_fw *sst_fw)
129{
130 struct fw_header *header;
131 struct sst_byt_fw_module_header *module;
132 struct sst_dsp *dsp = sst_fw->dsp;
133 int ret, count;
134
135 /* Read the header information from the data pointer */
136 header = (struct fw_header *)sst_fw->dma_buf;
137
138 /* verify FW */
139 if ((strncmp(header->signature, SST_BYT_FW_SIGN, 4) != 0) ||
140 (sst_fw->size != header->file_size + sizeof(*header))) {
141 /* Invalid FW signature */
142 dev_err(dsp->dev, "Invalid FW sign/filesize mismatch\n");
143 return -EINVAL;
144 }
145
146 dev_dbg(dsp->dev,
147 "header sign=%4s size=0x%x modules=0x%x fmt=0x%x size=%zu\n",
148 header->signature, header->file_size, header->modules,
149 header->file_format, sizeof(*header));
150
151 module = (void *)sst_fw->dma_buf + sizeof(*header);
152 for (count = 0; count < header->modules; count++) {
153 /* module */
154 ret = sst_byt_parse_module(dsp, sst_fw, module);
155 if (ret < 0) {
156 dev_err(dsp->dev, "invalid module %d\n", count);
157 return ret;
158 }
159 module = (void *)module + sizeof(*module) + module->mod_size;
160 }
161
162 return 0;
163}
164
165static void sst_byt_dump_shim(struct sst_dsp *sst)
166{
167 int i;
168 u64 reg;
169
170 for (i = 0; i <= 0xF0; i += 8) {
171 reg = sst_dsp_shim_read64_unlocked(sst, i);
172 if (reg)
173 dev_dbg(sst->dev, "shim 0x%2.2x value 0x%16.16llx\n",
174 i, reg);
175 }
176
177 for (i = 0x00; i <= 0xff; i += 4) {
178 reg = readl(sst->addr.pci_cfg + i);
179 if (reg)
180 dev_dbg(sst->dev, "pci 0x%2.2x value 0x%8.8x\n",
181 i, (u32)reg);
182 }
183}
184
185static irqreturn_t sst_byt_irq(int irq, void *context)
186{
187 struct sst_dsp *sst = (struct sst_dsp *) context;
188 u64 isrx;
189 irqreturn_t ret = IRQ_NONE;
190
191 spin_lock(&sst->spinlock);
192
193 isrx = sst_dsp_shim_read64_unlocked(sst, SST_ISRX);
194 if (isrx & SST_ISRX_DONE) {
195 /* ADSP has processed the message request from IA */
196 sst_dsp_shim_update_bits64_unlocked(sst, SST_IPCX,
197 SST_BYT_IPCX_DONE, 0);
198 ret = IRQ_WAKE_THREAD;
199 }
200 if (isrx & SST_BYT_ISRX_REQUEST) {
201 /* mask message request from ADSP and do processing later */
202 sst_dsp_shim_update_bits64_unlocked(sst, SST_IMRX,
203 SST_BYT_IMRX_REQUEST,
204 SST_BYT_IMRX_REQUEST);
205 ret = IRQ_WAKE_THREAD;
206 }
207
208 spin_unlock(&sst->spinlock);
209
210 return ret;
211}
212
213static void sst_byt_boot(struct sst_dsp *sst)
214{
215 int tries = 10;
216
217 /* release stall and wait to unstall */
218 sst_dsp_shim_update_bits64(sst, SST_CSR, SST_BYT_CSR_STALL, 0x0);
219 while (tries--) {
220 if (!(sst_dsp_shim_read64(sst, SST_CSR) &
221 SST_BYT_CSR_PWAITMODE))
222 break;
223 msleep(100);
224 }
225 if (tries < 0) {
226 dev_err(sst->dev, "unable to start DSP\n");
227 sst_byt_dump_shim(sst);
228 }
229}
230
231static void sst_byt_reset(struct sst_dsp *sst)
232{
233 /* put DSP into reset, set reset vector and stall */
234 sst_dsp_shim_update_bits64(sst, SST_CSR,
235 SST_BYT_CSR_RST | SST_BYT_CSR_VECTOR_SEL | SST_BYT_CSR_STALL,
236 SST_BYT_CSR_RST | SST_BYT_CSR_VECTOR_SEL | SST_BYT_CSR_STALL);
237
238 udelay(10);
239
240 /* take DSP out of reset and keep stalled for FW loading */
241 sst_dsp_shim_update_bits64(sst, SST_CSR, SST_BYT_CSR_RST, 0);
242}
243
244struct sst_adsp_memregion {
245 u32 start;
246 u32 end;
247 int blocks;
248 enum sst_mem_type type;
249};
250
251/* BYT test stuff */
252static const struct sst_adsp_memregion byt_region[] = {
253 {0xC0000, 0x100000, 8, SST_MEM_IRAM}, /* I-SRAM - 8 * 32kB */
254 {0x100000, 0x140000, 8, SST_MEM_DRAM}, /* D-SRAM0 - 8 * 32kB */
255};
256
257static int sst_byt_resource_map(struct sst_dsp *sst, struct sst_pdata *pdata)
258{
259 sst->addr.lpe_base = pdata->lpe_base;
260 sst->addr.lpe = ioremap(pdata->lpe_base, pdata->lpe_size);
261 if (!sst->addr.lpe)
262 return -ENODEV;
263
264 /* ADSP PCI MMIO config space */
265 sst->addr.pci_cfg = ioremap(pdata->pcicfg_base, pdata->pcicfg_size);
266 if (!sst->addr.pci_cfg) {
267 iounmap(sst->addr.lpe);
268 return -ENODEV;
269 }
270
271 /* SST Extended FW allocation */
272 sst->addr.fw_ext = ioremap(pdata->fw_base, pdata->fw_size);
273 if (!sst->addr.fw_ext) {
274 iounmap(sst->addr.pci_cfg);
275 iounmap(sst->addr.lpe);
276 return -ENODEV;
277 }
278
279 /* SST Shim */
280 sst->addr.shim = sst->addr.lpe + sst->addr.shim_offset;
281
282 sst_dsp_mailbox_init(sst, SST_BYT_MAILBOX_OFFSET + 0x204,
283 SST_BYT_IPC_MAX_PAYLOAD_SIZE,
284 SST_BYT_MAILBOX_OFFSET,
285 SST_BYT_IPC_MAX_PAYLOAD_SIZE);
286
287 sst->irq = pdata->irq;
288
289 return 0;
290}
291
292static int sst_byt_init(struct sst_dsp *sst, struct sst_pdata *pdata)
293{
294 const struct sst_adsp_memregion *region;
295 struct device *dev;
296 int ret = -ENODEV, i, j, region_count;
297 u32 offset, size;
298
299 dev = sst->dev;
300
301 switch (sst->id) {
302 case SST_DEV_ID_BYT:
303 region = byt_region;
304 region_count = ARRAY_SIZE(byt_region);
305 sst->addr.iram_offset = SST_BYT_IRAM_OFFSET;
306 sst->addr.dram_offset = SST_BYT_DRAM_OFFSET;
307 sst->addr.shim_offset = SST_BYT_SHIM_OFFSET;
308 break;
309 default:
310 dev_err(dev, "failed to get mem resources\n");
311 return ret;
312 }
313
314 ret = sst_byt_resource_map(sst, pdata);
315 if (ret < 0) {
316 dev_err(dev, "failed to map resources\n");
317 return ret;
318 }
319
320 /*
321 * save the physical address of extended firmware block in the first
322 * 4 bytes of the mailbox
323 */
324 memcpy_toio(sst->addr.lpe + SST_BYT_MAILBOX_OFFSET,
325 &pdata->fw_base, sizeof(u32));
326
327 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
328 if (ret)
329 return ret;
330
331 /* enable Interrupt from both sides */
332 sst_dsp_shim_update_bits64(sst, SST_IMRX, 0x3, 0x0);
333 sst_dsp_shim_update_bits64(sst, SST_IMRD, 0x3, 0x0);
334
335 /* register DSP memory blocks - ideally we should get this from ACPI */
336 for (i = 0; i < region_count; i++) {
337 offset = region[i].start;
338 size = (region[i].end - region[i].start) / region[i].blocks;
339
340 /* register individual memory blocks */
341 for (j = 0; j < region[i].blocks; j++) {
342 sst_mem_block_register(sst, offset, size,
343 region[i].type, NULL, j, sst);
344 offset += size;
345 }
346 }
347
348 return 0;
349}
350
351static void sst_byt_free(struct sst_dsp *sst)
352{
353 sst_mem_block_unregister_all(sst);
354 iounmap(sst->addr.lpe);
355 iounmap(sst->addr.pci_cfg);
356 iounmap(sst->addr.fw_ext);
357}
358
359struct sst_ops sst_byt_ops = {
360 .reset = sst_byt_reset,
361 .boot = sst_byt_boot,
362 .write = sst_shim32_write,
363 .read = sst_shim32_read,
364 .write64 = sst_shim32_write64,
365 .read64 = sst_shim32_read64,
366 .ram_read = sst_memcpy_fromio_32,
367 .ram_write = sst_memcpy_toio_32,
368 .irq_handler = sst_byt_irq,
369 .init = sst_byt_init,
370 .free = sst_byt_free,
371 .parse_fw = sst_byt_parse_fw_image,
372};
diff --git a/sound/soc/intel/sst-baytrail-ipc.c b/sound/soc/intel/sst-baytrail-ipc.c
new file mode 100644
index 000000000000..d0eaeee21be4
--- /dev/null
+++ b/sound/soc/intel/sst-baytrail-ipc.c
@@ -0,0 +1,867 @@
1/*
2 * Intel Baytrail SST IPC Support
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/kernel.h>
17#include <linux/list.h>
18#include <linux/device.h>
19#include <linux/wait.h>
20#include <linux/spinlock.h>
21#include <linux/workqueue.h>
22#include <linux/export.h>
23#include <linux/slab.h>
24#include <linux/delay.h>
25#include <linux/list.h>
26#include <linux/platform_device.h>
27#include <linux/kthread.h>
28#include <linux/firmware.h>
29#include <linux/io.h>
30#include <asm/div64.h>
31
32#include "sst-baytrail-ipc.h"
33#include "sst-dsp.h"
34#include "sst-dsp-priv.h"
35
36/* IPC message timeout */
37#define IPC_TIMEOUT_MSECS 300
38#define IPC_BOOT_MSECS 200
39
40#define IPC_EMPTY_LIST_SIZE 8
41
42/* IPC header bits */
43#define IPC_HEADER_MSG_ID_MASK 0xff
44#define IPC_HEADER_MSG_ID(x) ((x) & IPC_HEADER_MSG_ID_MASK)
45#define IPC_HEADER_STR_ID_SHIFT 8
46#define IPC_HEADER_STR_ID_MASK 0x1f
47#define IPC_HEADER_STR_ID(x) (((x) & 0x1f) << IPC_HEADER_STR_ID_SHIFT)
48#define IPC_HEADER_LARGE_SHIFT 13
49#define IPC_HEADER_LARGE(x) (((x) & 0x1) << IPC_HEADER_LARGE_SHIFT)
50#define IPC_HEADER_DATA_SHIFT 16
51#define IPC_HEADER_DATA_MASK 0x3fff
52#define IPC_HEADER_DATA(x) (((x) & 0x3fff) << IPC_HEADER_DATA_SHIFT)
53
54/* mask for differentiating between notification and reply message */
55#define IPC_NOTIFICATION (0x1 << 7)
56
57/* I2L Stream config/control msgs */
58#define IPC_IA_ALLOC_STREAM 0x20
59#define IPC_IA_FREE_STREAM 0x21
60#define IPC_IA_PAUSE_STREAM 0x24
61#define IPC_IA_RESUME_STREAM 0x25
62#define IPC_IA_DROP_STREAM 0x26
63#define IPC_IA_START_STREAM 0x30
64
65/* notification messages */
66#define IPC_IA_FW_INIT_CMPLT 0x81
67#define IPC_SST_PERIOD_ELAPSED 0x97
68
69/* IPC messages between host and ADSP */
70struct sst_byt_address_info {
71 u32 addr;
72 u32 size;
73} __packed;
74
75struct sst_byt_str_type {
76 u8 codec_type;
77 u8 str_type;
78 u8 operation;
79 u8 protected_str;
80 u8 time_slots;
81 u8 reserved;
82 u16 result;
83} __packed;
84
85struct sst_byt_pcm_params {
86 u8 num_chan;
87 u8 pcm_wd_sz;
88 u8 use_offload_path;
89 u8 reserved;
90 u32 sfreq;
91 u8 channel_map[8];
92} __packed;
93
94struct sst_byt_frames_info {
95 u16 num_entries;
96 u16 rsrvd;
97 u32 frag_size;
98 struct sst_byt_address_info ring_buf_info[8];
99} __packed;
100
101struct sst_byt_alloc_params {
102 struct sst_byt_str_type str_type;
103 struct sst_byt_pcm_params pcm_params;
104 struct sst_byt_frames_info frame_info;
105} __packed;
106
107struct sst_byt_alloc_response {
108 struct sst_byt_str_type str_type;
109 u8 reserved[88];
110} __packed;
111
112struct sst_byt_start_stream_params {
113 u32 byte_offset;
114} __packed;
115
116struct sst_byt_tstamp {
117 u64 ring_buffer_counter;
118 u64 hardware_counter;
119 u64 frames_decoded;
120 u64 bytes_decoded;
121 u64 bytes_copied;
122 u32 sampling_frequency;
123 u32 channel_peak[8];
124} __packed;
125
126/* driver internal IPC message structure */
127struct ipc_message {
128 struct list_head list;
129 u64 header;
130
131 /* direction wrt host CPU */
132 char tx_data[SST_BYT_IPC_MAX_PAYLOAD_SIZE];
133 size_t tx_size;
134 char rx_data[SST_BYT_IPC_MAX_PAYLOAD_SIZE];
135 size_t rx_size;
136
137 wait_queue_head_t waitq;
138 bool complete;
139 bool wait;
140 int errno;
141};
142
143struct sst_byt_stream;
144struct sst_byt;
145
146/* stream infomation */
147struct sst_byt_stream {
148 struct list_head node;
149
150 /* configuration */
151 struct sst_byt_alloc_params request;
152 struct sst_byt_alloc_response reply;
153
154 /* runtime info */
155 struct sst_byt *byt;
156 int str_id;
157 bool commited;
158 bool running;
159
160 /* driver callback */
161 u32 (*notify_position)(struct sst_byt_stream *stream, void *data);
162 void *pdata;
163};
164
165/* SST Baytrail IPC data */
166struct sst_byt {
167 struct device *dev;
168 struct sst_dsp *dsp;
169
170 /* stream */
171 struct list_head stream_list;
172
173 /* boot */
174 wait_queue_head_t boot_wait;
175 bool boot_complete;
176
177 /* IPC messaging */
178 struct list_head tx_list;
179 struct list_head rx_list;
180 struct list_head empty_list;
181 wait_queue_head_t wait_txq;
182 struct task_struct *tx_thread;
183 struct kthread_worker kworker;
184 struct kthread_work kwork;
185 struct ipc_message *msg;
186};
187
188static inline u64 sst_byt_header(int msg_id, int data, bool large, int str_id)
189{
190 u64 header;
191
192 header = IPC_HEADER_MSG_ID(msg_id) |
193 IPC_HEADER_STR_ID(str_id) |
194 IPC_HEADER_LARGE(large) |
195 IPC_HEADER_DATA(data) |
196 SST_BYT_IPCX_BUSY;
197
198 return header;
199}
200
201static inline u16 sst_byt_header_msg_id(u64 header)
202{
203 return header & IPC_HEADER_MSG_ID_MASK;
204}
205
206static inline u8 sst_byt_header_str_id(u64 header)
207{
208 return (header >> IPC_HEADER_STR_ID_SHIFT) & IPC_HEADER_STR_ID_MASK;
209}
210
211static inline u16 sst_byt_header_data(u64 header)
212{
213 return (header >> IPC_HEADER_DATA_SHIFT) & IPC_HEADER_DATA_MASK;
214}
215
216static struct sst_byt_stream *sst_byt_get_stream(struct sst_byt *byt,
217 int stream_id)
218{
219 struct sst_byt_stream *stream;
220
221 list_for_each_entry(stream, &byt->stream_list, node) {
222 if (stream->str_id == stream_id)
223 return stream;
224 }
225
226 return NULL;
227}
228
229static void sst_byt_ipc_shim_dbg(struct sst_byt *byt, const char *text)
230{
231 struct sst_dsp *sst = byt->dsp;
232 u64 isr, ipcd, imrx, ipcx;
233
234 ipcx = sst_dsp_shim_read64_unlocked(sst, SST_IPCX);
235 isr = sst_dsp_shim_read64_unlocked(sst, SST_ISRX);
236 ipcd = sst_dsp_shim_read64_unlocked(sst, SST_IPCD);
237 imrx = sst_dsp_shim_read64_unlocked(sst, SST_IMRX);
238
239 dev_err(byt->dev,
240 "ipc: --%s-- ipcx 0x%llx isr 0x%llx ipcd 0x%llx imrx 0x%llx\n",
241 text, ipcx, isr, ipcd, imrx);
242}
243
244/* locks held by caller */
245static struct ipc_message *sst_byt_msg_get_empty(struct sst_byt *byt)
246{
247 struct ipc_message *msg = NULL;
248
249 if (!list_empty(&byt->empty_list)) {
250 msg = list_first_entry(&byt->empty_list,
251 struct ipc_message, list);
252 list_del(&msg->list);
253 }
254
255 return msg;
256}
257
258static void sst_byt_ipc_tx_msgs(struct kthread_work *work)
259{
260 struct sst_byt *byt =
261 container_of(work, struct sst_byt, kwork);
262 struct ipc_message *msg;
263 u64 ipcx;
264 unsigned long flags;
265
266 spin_lock_irqsave(&byt->dsp->spinlock, flags);
267 if (list_empty(&byt->tx_list)) {
268 spin_unlock_irqrestore(&byt->dsp->spinlock, flags);
269 return;
270 }
271
272 /* if the DSP is busy we will TX messages after IRQ */
273 ipcx = sst_dsp_shim_read64_unlocked(byt->dsp, SST_IPCX);
274 if (ipcx & SST_BYT_IPCX_BUSY) {
275 spin_unlock_irqrestore(&byt->dsp->spinlock, flags);
276 return;
277 }
278
279 msg = list_first_entry(&byt->tx_list, struct ipc_message, list);
280
281 list_move(&msg->list, &byt->rx_list);
282
283 /* send the message */
284 if (msg->header & IPC_HEADER_LARGE(true))
285 sst_dsp_outbox_write(byt->dsp, msg->tx_data, msg->tx_size);
286 sst_dsp_shim_write64_unlocked(byt->dsp, SST_IPCX, msg->header);
287
288 spin_unlock_irqrestore(&byt->dsp->spinlock, flags);
289}
290
291static inline void sst_byt_tx_msg_reply_complete(struct sst_byt *byt,
292 struct ipc_message *msg)
293{
294 msg->complete = true;
295
296 if (!msg->wait)
297 list_add_tail(&msg->list, &byt->empty_list);
298 else
299 wake_up(&msg->waitq);
300}
301
302static int sst_byt_tx_wait_done(struct sst_byt *byt, struct ipc_message *msg,
303 void *rx_data)
304{
305 unsigned long flags;
306 int ret;
307
308 /* wait for DSP completion */
309 ret = wait_event_timeout(msg->waitq, msg->complete,
310 msecs_to_jiffies(IPC_TIMEOUT_MSECS));
311
312 spin_lock_irqsave(&byt->dsp->spinlock, flags);
313 if (ret == 0) {
314 list_del(&msg->list);
315 sst_byt_ipc_shim_dbg(byt, "message timeout");
316
317 ret = -ETIMEDOUT;
318 } else {
319
320 /* copy the data returned from DSP */
321 if (msg->rx_size)
322 memcpy(rx_data, msg->rx_data, msg->rx_size);
323 ret = msg->errno;
324 }
325
326 list_add_tail(&msg->list, &byt->empty_list);
327 spin_unlock_irqrestore(&byt->dsp->spinlock, flags);
328 return ret;
329}
330
331static int sst_byt_ipc_tx_message(struct sst_byt *byt, u64 header,
332 void *tx_data, size_t tx_bytes,
333 void *rx_data, size_t rx_bytes, int wait)
334{
335 unsigned long flags;
336 struct ipc_message *msg;
337
338 spin_lock_irqsave(&byt->dsp->spinlock, flags);
339
340 msg = sst_byt_msg_get_empty(byt);
341 if (msg == NULL) {
342 spin_unlock_irqrestore(&byt->dsp->spinlock, flags);
343 return -EBUSY;
344 }
345
346 msg->header = header;
347 msg->tx_size = tx_bytes;
348 msg->rx_size = rx_bytes;
349 msg->wait = wait;
350 msg->errno = 0;
351 msg->complete = false;
352
353 if (tx_bytes) {
354 /* msg content = lower 32-bit of the header + data */
355 *(u32 *)msg->tx_data = (u32)(header & (u32)-1);
356 memcpy(msg->tx_data + sizeof(u32), tx_data, tx_bytes);
357 msg->tx_size += sizeof(u32);
358 }
359
360 list_add_tail(&msg->list, &byt->tx_list);
361 spin_unlock_irqrestore(&byt->dsp->spinlock, flags);
362
363 queue_kthread_work(&byt->kworker, &byt->kwork);
364
365 if (wait)
366 return sst_byt_tx_wait_done(byt, msg, rx_data);
367 else
368 return 0;
369}
370
371static inline int sst_byt_ipc_tx_msg_wait(struct sst_byt *byt, u64 header,
372 void *tx_data, size_t tx_bytes,
373 void *rx_data, size_t rx_bytes)
374{
375 return sst_byt_ipc_tx_message(byt, header, tx_data, tx_bytes,
376 rx_data, rx_bytes, 1);
377}
378
379static inline int sst_byt_ipc_tx_msg_nowait(struct sst_byt *byt, u64 header,
380 void *tx_data, size_t tx_bytes)
381{
382 return sst_byt_ipc_tx_message(byt, header, tx_data, tx_bytes,
383 NULL, 0, 0);
384}
385
386static struct ipc_message *sst_byt_reply_find_msg(struct sst_byt *byt,
387 u64 header)
388{
389 struct ipc_message *msg = NULL, *_msg;
390 u64 mask;
391
392 /* match reply to message sent based on msg and stream IDs */
393 mask = IPC_HEADER_MSG_ID_MASK |
394 IPC_HEADER_STR_ID_MASK << IPC_HEADER_STR_ID_SHIFT;
395 header &= mask;
396
397 if (list_empty(&byt->rx_list)) {
398 dev_err(byt->dev,
399 "ipc: rx list is empty but received 0x%llx\n", header);
400 goto out;
401 }
402
403 list_for_each_entry(_msg, &byt->rx_list, list) {
404 if ((_msg->header & mask) == header) {
405 msg = _msg;
406 break;
407 }
408 }
409
410out:
411 return msg;
412}
413
414static void sst_byt_stream_update(struct sst_byt *byt, struct ipc_message *msg)
415{
416 struct sst_byt_stream *stream;
417 u64 header = msg->header;
418 u8 stream_id = sst_byt_header_str_id(header);
419 u8 stream_msg = sst_byt_header_msg_id(header);
420
421 stream = sst_byt_get_stream(byt, stream_id);
422 if (stream == NULL)
423 return;
424
425 switch (stream_msg) {
426 case IPC_IA_DROP_STREAM:
427 case IPC_IA_PAUSE_STREAM:
428 case IPC_IA_FREE_STREAM:
429 stream->running = false;
430 break;
431 case IPC_IA_START_STREAM:
432 case IPC_IA_RESUME_STREAM:
433 stream->running = true;
434 break;
435 }
436}
437
438static int sst_byt_process_reply(struct sst_byt *byt, u64 header)
439{
440 struct ipc_message *msg;
441
442 msg = sst_byt_reply_find_msg(byt, header);
443 if (msg == NULL)
444 return 1;
445
446 if (header & IPC_HEADER_LARGE(true)) {
447 msg->rx_size = sst_byt_header_data(header);
448 sst_dsp_inbox_read(byt->dsp, msg->rx_data, msg->rx_size);
449 }
450
451 /* update any stream states */
452 sst_byt_stream_update(byt, msg);
453
454 list_del(&msg->list);
455 /* wake up */
456 sst_byt_tx_msg_reply_complete(byt, msg);
457
458 return 1;
459}
460
461static void sst_byt_fw_ready(struct sst_byt *byt, u64 header)
462{
463 dev_dbg(byt->dev, "ipc: DSP is ready 0x%llX\n", header);
464
465 byt->boot_complete = true;
466 wake_up(&byt->boot_wait);
467}
468
469static int sst_byt_process_notification(struct sst_byt *byt,
470 unsigned long *flags)
471{
472 struct sst_dsp *sst = byt->dsp;
473 struct sst_byt_stream *stream;
474 u64 header;
475 u8 msg_id, stream_id;
476 int handled = 1;
477
478 header = sst_dsp_shim_read64_unlocked(sst, SST_IPCD);
479 msg_id = sst_byt_header_msg_id(header);
480
481 switch (msg_id) {
482 case IPC_SST_PERIOD_ELAPSED:
483 stream_id = sst_byt_header_str_id(header);
484 stream = sst_byt_get_stream(byt, stream_id);
485 if (stream && stream->running && stream->notify_position) {
486 spin_unlock_irqrestore(&sst->spinlock, *flags);
487 stream->notify_position(stream, stream->pdata);
488 spin_lock_irqsave(&sst->spinlock, *flags);
489 }
490 break;
491 case IPC_IA_FW_INIT_CMPLT:
492 sst_byt_fw_ready(byt, header);
493 break;
494 }
495
496 return handled;
497}
498
499static irqreturn_t sst_byt_irq_thread(int irq, void *context)
500{
501 struct sst_dsp *sst = (struct sst_dsp *) context;
502 struct sst_byt *byt = sst_dsp_get_thread_context(sst);
503 u64 header;
504 unsigned long flags;
505
506 spin_lock_irqsave(&sst->spinlock, flags);
507
508 header = sst_dsp_shim_read64_unlocked(sst, SST_IPCD);
509 if (header & SST_BYT_IPCD_BUSY) {
510 if (header & IPC_NOTIFICATION) {
511 /* message from ADSP */
512 sst_byt_process_notification(byt, &flags);
513 } else {
514 /* reply from ADSP */
515 sst_byt_process_reply(byt, header);
516 }
517 /*
518 * clear IPCD BUSY bit and set DONE bit. Tell DSP we have
519 * processed the message and can accept new. Clear data part
520 * of the header
521 */
522 sst_dsp_shim_update_bits64_unlocked(sst, SST_IPCD,
523 SST_BYT_IPCD_DONE | SST_BYT_IPCD_BUSY |
524 IPC_HEADER_DATA(IPC_HEADER_DATA_MASK),
525 SST_BYT_IPCD_DONE);
526 /* unmask message request interrupts */
527 sst_dsp_shim_update_bits64_unlocked(sst, SST_IMRX,
528 SST_BYT_IMRX_REQUEST, 0);
529 }
530
531 spin_unlock_irqrestore(&sst->spinlock, flags);
532
533 /* continue to send any remaining messages... */
534 queue_kthread_work(&byt->kworker, &byt->kwork);
535
536 return IRQ_HANDLED;
537}
538
539/* stream API */
540struct sst_byt_stream *sst_byt_stream_new(struct sst_byt *byt, int id,
541 u32 (*notify_position)(struct sst_byt_stream *stream, void *data),
542 void *data)
543{
544 struct sst_byt_stream *stream;
545
546 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
547 if (stream == NULL)
548 return NULL;
549
550 list_add(&stream->node, &byt->stream_list);
551 stream->notify_position = notify_position;
552 stream->pdata = data;
553 stream->byt = byt;
554 stream->str_id = id;
555
556 return stream;
557}
558
559int sst_byt_stream_set_bits(struct sst_byt *byt, struct sst_byt_stream *stream,
560 int bits)
561{
562 stream->request.pcm_params.pcm_wd_sz = bits;
563 return 0;
564}
565
566int sst_byt_stream_set_channels(struct sst_byt *byt,
567 struct sst_byt_stream *stream, u8 channels)
568{
569 stream->request.pcm_params.num_chan = channels;
570 return 0;
571}
572
573int sst_byt_stream_set_rate(struct sst_byt *byt, struct sst_byt_stream *stream,
574 unsigned int rate)
575{
576 stream->request.pcm_params.sfreq = rate;
577 return 0;
578}
579
580/* stream sonfiguration */
581int sst_byt_stream_type(struct sst_byt *byt, struct sst_byt_stream *stream,
582 int codec_type, int stream_type, int operation)
583{
584 stream->request.str_type.codec_type = codec_type;
585 stream->request.str_type.str_type = stream_type;
586 stream->request.str_type.operation = operation;
587 stream->request.str_type.time_slots = 0xc;
588
589 return 0;
590}
591
592int sst_byt_stream_buffer(struct sst_byt *byt, struct sst_byt_stream *stream,
593 uint32_t buffer_addr, uint32_t buffer_size)
594{
595 stream->request.frame_info.num_entries = 1;
596 stream->request.frame_info.ring_buf_info[0].addr = buffer_addr;
597 stream->request.frame_info.ring_buf_info[0].size = buffer_size;
598 /* calculate bytes per 4 ms fragment */
599 stream->request.frame_info.frag_size =
600 stream->request.pcm_params.sfreq *
601 stream->request.pcm_params.num_chan *
602 stream->request.pcm_params.pcm_wd_sz / 8 *
603 4 / 1000;
604 return 0;
605}
606
607int sst_byt_stream_commit(struct sst_byt *byt, struct sst_byt_stream *stream)
608{
609 struct sst_byt_alloc_params *str_req = &stream->request;
610 struct sst_byt_alloc_response *reply = &stream->reply;
611 u64 header;
612 int ret;
613
614 header = sst_byt_header(IPC_IA_ALLOC_STREAM,
615 sizeof(*str_req) + sizeof(u32),
616 true, stream->str_id);
617 ret = sst_byt_ipc_tx_msg_wait(byt, header, str_req, sizeof(*str_req),
618 reply, sizeof(*reply));
619 if (ret < 0) {
620 dev_err(byt->dev, "ipc: error stream commit failed\n");
621 return ret;
622 }
623
624 stream->commited = true;
625
626 return 0;
627}
628
629int sst_byt_stream_free(struct sst_byt *byt, struct sst_byt_stream *stream)
630{
631 u64 header;
632 int ret = 0;
633
634 if (!stream->commited)
635 goto out;
636
637 header = sst_byt_header(IPC_IA_FREE_STREAM, 0, false, stream->str_id);
638 ret = sst_byt_ipc_tx_msg_wait(byt, header, NULL, 0, NULL, 0);
639 if (ret < 0) {
640 dev_err(byt->dev, "ipc: free stream %d failed\n",
641 stream->str_id);
642 return -EAGAIN;
643 }
644
645 stream->commited = false;
646out:
647 list_del(&stream->node);
648 kfree(stream);
649
650 return ret;
651}
652
653static int sst_byt_stream_operations(struct sst_byt *byt, int type,
654 int stream_id, int wait)
655{
656 struct sst_byt_start_stream_params start_stream;
657 u64 header;
658 void *tx_msg = NULL;
659 size_t size = 0;
660
661 if (type != IPC_IA_START_STREAM) {
662 header = sst_byt_header(type, 0, false, stream_id);
663 } else {
664 start_stream.byte_offset = 0;
665 header = sst_byt_header(IPC_IA_START_STREAM,
666 sizeof(start_stream) + sizeof(u32),
667 true, stream_id);
668 tx_msg = &start_stream;
669 size = sizeof(start_stream);
670 }
671
672 if (wait)
673 return sst_byt_ipc_tx_msg_wait(byt, header,
674 tx_msg, size, NULL, 0);
675 else
676 return sst_byt_ipc_tx_msg_nowait(byt, header, tx_msg, size);
677}
678
679/* stream ALSA trigger operations */
680int sst_byt_stream_start(struct sst_byt *byt, struct sst_byt_stream *stream)
681{
682 int ret;
683
684 ret = sst_byt_stream_operations(byt, IPC_IA_START_STREAM,
685 stream->str_id, 0);
686 if (ret < 0)
687 dev_err(byt->dev, "ipc: error failed to start stream %d\n",
688 stream->str_id);
689
690 return ret;
691}
692
693int sst_byt_stream_stop(struct sst_byt *byt, struct sst_byt_stream *stream)
694{
695 int ret;
696
697 /* don't stop streams that are not commited */
698 if (!stream->commited)
699 return 0;
700
701 ret = sst_byt_stream_operations(byt, IPC_IA_DROP_STREAM,
702 stream->str_id, 0);
703 if (ret < 0)
704 dev_err(byt->dev, "ipc: error failed to stop stream %d\n",
705 stream->str_id);
706 return ret;
707}
708
709int sst_byt_stream_pause(struct sst_byt *byt, struct sst_byt_stream *stream)
710{
711 int ret;
712
713 ret = sst_byt_stream_operations(byt, IPC_IA_PAUSE_STREAM,
714 stream->str_id, 0);
715 if (ret < 0)
716 dev_err(byt->dev, "ipc: error failed to pause stream %d\n",
717 stream->str_id);
718
719 return ret;
720}
721
722int sst_byt_stream_resume(struct sst_byt *byt, struct sst_byt_stream *stream)
723{
724 int ret;
725
726 ret = sst_byt_stream_operations(byt, IPC_IA_RESUME_STREAM,
727 stream->str_id, 0);
728 if (ret < 0)
729 dev_err(byt->dev, "ipc: error failed to resume stream %d\n",
730 stream->str_id);
731
732 return ret;
733}
734
735int sst_byt_get_dsp_position(struct sst_byt *byt,
736 struct sst_byt_stream *stream, int buffer_size)
737{
738 struct sst_dsp *sst = byt->dsp;
739 struct sst_byt_tstamp fw_tstamp;
740 u8 str_id = stream->str_id;
741 u32 tstamp_offset;
742
743 tstamp_offset = SST_BYT_TIMESTAMP_OFFSET + str_id * sizeof(fw_tstamp);
744 memcpy_fromio(&fw_tstamp,
745 sst->addr.lpe + tstamp_offset, sizeof(fw_tstamp));
746
747 return do_div(fw_tstamp.ring_buffer_counter, buffer_size);
748}
749
750static int msg_empty_list_init(struct sst_byt *byt)
751{
752 struct ipc_message *msg;
753 int i;
754
755 byt->msg = kzalloc(sizeof(*msg) * IPC_EMPTY_LIST_SIZE, GFP_KERNEL);
756 if (byt->msg == NULL)
757 return -ENOMEM;
758
759 for (i = 0; i < IPC_EMPTY_LIST_SIZE; i++) {
760 init_waitqueue_head(&byt->msg[i].waitq);
761 list_add(&byt->msg[i].list, &byt->empty_list);
762 }
763
764 return 0;
765}
766
767struct sst_dsp *sst_byt_get_dsp(struct sst_byt *byt)
768{
769 return byt->dsp;
770}
771
772static struct sst_dsp_device byt_dev = {
773 .thread = sst_byt_irq_thread,
774 .ops = &sst_byt_ops,
775};
776
777int sst_byt_dsp_init(struct device *dev, struct sst_pdata *pdata)
778{
779 struct sst_byt *byt;
780 struct sst_fw *byt_sst_fw;
781 int err;
782
783 dev_dbg(dev, "initialising Byt DSP IPC\n");
784
785 byt = devm_kzalloc(dev, sizeof(*byt), GFP_KERNEL);
786 if (byt == NULL)
787 return -ENOMEM;
788
789 byt->dev = dev;
790 INIT_LIST_HEAD(&byt->stream_list);
791 INIT_LIST_HEAD(&byt->tx_list);
792 INIT_LIST_HEAD(&byt->rx_list);
793 INIT_LIST_HEAD(&byt->empty_list);
794 init_waitqueue_head(&byt->boot_wait);
795 init_waitqueue_head(&byt->wait_txq);
796
797 err = msg_empty_list_init(byt);
798 if (err < 0)
799 return -ENOMEM;
800
801 /* start the IPC message thread */
802 init_kthread_worker(&byt->kworker);
803 byt->tx_thread = kthread_run(kthread_worker_fn,
804 &byt->kworker,
805 dev_name(byt->dev));
806 if (IS_ERR(byt->tx_thread)) {
807 err = PTR_ERR(byt->tx_thread);
808 dev_err(byt->dev, "error failed to create message TX task\n");
809 goto err_free_msg;
810 }
811 init_kthread_work(&byt->kwork, sst_byt_ipc_tx_msgs);
812
813 byt_dev.thread_context = byt;
814
815 /* init SST shim */
816 byt->dsp = sst_dsp_new(dev, &byt_dev, pdata);
817 if (byt->dsp == NULL) {
818 err = -ENODEV;
819 goto err_free_msg;
820 }
821
822 /* keep the DSP in reset state for base FW loading */
823 sst_dsp_reset(byt->dsp);
824
825 byt_sst_fw = sst_fw_new(byt->dsp, pdata->fw, byt);
826 if (byt_sst_fw == NULL) {
827 err = -ENODEV;
828 dev_err(dev, "error: failed to load firmware\n");
829 goto fw_err;
830 }
831
832 /* wait for DSP boot completion */
833 sst_dsp_boot(byt->dsp);
834 err = wait_event_timeout(byt->boot_wait, byt->boot_complete,
835 msecs_to_jiffies(IPC_BOOT_MSECS));
836 if (err == 0) {
837 err = -EIO;
838 dev_err(byt->dev, "ipc: error DSP boot timeout\n");
839 goto boot_err;
840 }
841
842 pdata->dsp = byt;
843
844 return 0;
845
846boot_err:
847 sst_dsp_reset(byt->dsp);
848 sst_fw_free(byt_sst_fw);
849fw_err:
850 sst_dsp_free(byt->dsp);
851err_free_msg:
852 kfree(byt->msg);
853
854 return err;
855}
856EXPORT_SYMBOL_GPL(sst_byt_dsp_init);
857
858void sst_byt_dsp_free(struct device *dev, struct sst_pdata *pdata)
859{
860 struct sst_byt *byt = pdata->dsp;
861
862 sst_dsp_reset(byt->dsp);
863 sst_fw_free_all(byt->dsp);
864 sst_dsp_free(byt->dsp);
865 kfree(byt->msg);
866}
867EXPORT_SYMBOL_GPL(sst_byt_dsp_free);
diff --git a/sound/soc/intel/sst-baytrail-ipc.h b/sound/soc/intel/sst-baytrail-ipc.h
new file mode 100644
index 000000000000..f172b6440fa9
--- /dev/null
+++ b/sound/soc/intel/sst-baytrail-ipc.h
@@ -0,0 +1,69 @@
1/*
2 * Intel Baytrail SST IPC Support
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef __SST_BYT_IPC_H
16#define __SST_BYT_IPC_H
17
18#include <linux/types.h>
19
20struct sst_byt;
21struct sst_byt_stream;
22struct sst_pdata;
23extern struct sst_ops sst_byt_ops;
24
25
26#define SST_BYT_MAILBOX_OFFSET 0x144000
27#define SST_BYT_TIMESTAMP_OFFSET (SST_BYT_MAILBOX_OFFSET + 0x800)
28
29/**
30 * Upfront defined maximum message size that is
31 * expected by the in/out communication pipes in FW.
32 */
33#define SST_BYT_IPC_MAX_PAYLOAD_SIZE 200
34
35/* stream API */
36struct sst_byt_stream *sst_byt_stream_new(struct sst_byt *byt, int id,
37 uint32_t (*get_write_position)(struct sst_byt_stream *stream,
38 void *data),
39 void *data);
40
41/* stream configuration */
42int sst_byt_stream_set_bits(struct sst_byt *byt, struct sst_byt_stream *stream,
43 int bits);
44int sst_byt_stream_set_channels(struct sst_byt *byt,
45 struct sst_byt_stream *stream, u8 channels);
46int sst_byt_stream_set_rate(struct sst_byt *byt, struct sst_byt_stream *stream,
47 unsigned int rate);
48int sst_byt_stream_type(struct sst_byt *byt, struct sst_byt_stream *stream,
49 int codec_type, int stream_type, int operation);
50int sst_byt_stream_buffer(struct sst_byt *byt, struct sst_byt_stream *stream,
51 uint32_t buffer_addr, uint32_t buffer_size);
52int sst_byt_stream_commit(struct sst_byt *byt, struct sst_byt_stream *stream);
53int sst_byt_stream_free(struct sst_byt *byt, struct sst_byt_stream *stream);
54
55/* stream ALSA trigger operations */
56int sst_byt_stream_start(struct sst_byt *byt, struct sst_byt_stream *stream);
57int sst_byt_stream_stop(struct sst_byt *byt, struct sst_byt_stream *stream);
58int sst_byt_stream_pause(struct sst_byt *byt, struct sst_byt_stream *stream);
59int sst_byt_stream_resume(struct sst_byt *byt, struct sst_byt_stream *stream);
60
61int sst_byt_get_dsp_position(struct sst_byt *byt,
62 struct sst_byt_stream *stream, int buffer_size);
63
64/* init */
65int sst_byt_dsp_init(struct device *dev, struct sst_pdata *pdata);
66void sst_byt_dsp_free(struct device *dev, struct sst_pdata *pdata);
67struct sst_dsp *sst_byt_get_dsp(struct sst_byt *byt);
68
69#endif
diff --git a/sound/soc/intel/sst-baytrail-pcm.c b/sound/soc/intel/sst-baytrail-pcm.c
new file mode 100644
index 000000000000..6d101f3813b4
--- /dev/null
+++ b/sound/soc/intel/sst-baytrail-pcm.c
@@ -0,0 +1,422 @@
1/*
2 * Intel Baytrail SST PCM Support
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/module.h>
16#include <linux/dma-mapping.h>
17#include <linux/slab.h>
18#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/pcm_params.h>
21#include <sound/soc.h>
22#include "sst-baytrail-ipc.h"
23#include "sst-dsp-priv.h"
24#include "sst-dsp.h"
25
26#define BYT_PCM_COUNT 2
27
28static const struct snd_pcm_hardware sst_byt_pcm_hardware = {
29 .info = SNDRV_PCM_INFO_MMAP |
30 SNDRV_PCM_INFO_MMAP_VALID |
31 SNDRV_PCM_INFO_INTERLEAVED |
32 SNDRV_PCM_INFO_PAUSE |
33 SNDRV_PCM_INFO_RESUME,
34 .formats = SNDRV_PCM_FMTBIT_S16_LE |
35 SNDRV_PCM_FORMAT_S24_LE,
36 .period_bytes_min = 384,
37 .period_bytes_max = 48000,
38 .periods_min = 2,
39 .periods_max = 250,
40 .buffer_bytes_max = 96000,
41};
42
43/* private data for each PCM DSP stream */
44struct sst_byt_pcm_data {
45 struct sst_byt_stream *stream;
46 struct snd_pcm_substream *substream;
47 struct mutex mutex;
48};
49
50/* private data for the driver */
51struct sst_byt_priv_data {
52 /* runtime DSP */
53 struct sst_byt *byt;
54
55 /* DAI data */
56 struct sst_byt_pcm_data pcm[BYT_PCM_COUNT];
57};
58
59/* this may get called several times by oss emulation */
60static int sst_byt_pcm_hw_params(struct snd_pcm_substream *substream,
61 struct snd_pcm_hw_params *params)
62{
63 struct snd_soc_pcm_runtime *rtd = substream->private_data;
64 struct sst_byt_priv_data *pdata =
65 snd_soc_platform_get_drvdata(rtd->platform);
66 struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
67 struct sst_byt *byt = pdata->byt;
68 u32 rate, bits;
69 u8 channels;
70 int ret, playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
71
72 dev_dbg(rtd->dev, "PCM: hw_params, pcm_data %p\n", pcm_data);
73
74 ret = sst_byt_stream_type(byt, pcm_data->stream,
75 1, 1, !playback);
76 if (ret < 0) {
77 dev_err(rtd->dev, "failed to set stream format %d\n", ret);
78 return ret;
79 }
80
81 rate = params_rate(params);
82 ret = sst_byt_stream_set_rate(byt, pcm_data->stream, rate);
83 if (ret < 0) {
84 dev_err(rtd->dev, "could not set rate %d\n", rate);
85 return ret;
86 }
87
88 bits = snd_pcm_format_width(params_format(params));
89 ret = sst_byt_stream_set_bits(byt, pcm_data->stream, bits);
90 if (ret < 0) {
91 dev_err(rtd->dev, "could not set formats %d\n",
92 params_rate(params));
93 return ret;
94 }
95
96 channels = (u8)(params_channels(params) & 0xF);
97 ret = sst_byt_stream_set_channels(byt, pcm_data->stream, channels);
98 if (ret < 0) {
99 dev_err(rtd->dev, "could not set channels %d\n",
100 params_rate(params));
101 return ret;
102 }
103
104 snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
105
106 ret = sst_byt_stream_buffer(byt, pcm_data->stream,
107 substream->dma_buffer.addr,
108 params_buffer_bytes(params));
109 if (ret < 0) {
110 dev_err(rtd->dev, "PCM: failed to set DMA buffer %d\n", ret);
111 return ret;
112 }
113
114 ret = sst_byt_stream_commit(byt, pcm_data->stream);
115 if (ret < 0) {
116 dev_err(rtd->dev, "PCM: failed stream commit %d\n", ret);
117 return ret;
118 }
119
120 return 0;
121}
122
123static int sst_byt_pcm_hw_free(struct snd_pcm_substream *substream)
124{
125 struct snd_soc_pcm_runtime *rtd = substream->private_data;
126
127 dev_dbg(rtd->dev, "PCM: hw_free\n");
128 snd_pcm_lib_free_pages(substream);
129
130 return 0;
131}
132
133static int sst_byt_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
134{
135 struct snd_soc_pcm_runtime *rtd = substream->private_data;
136 struct sst_byt_priv_data *pdata =
137 snd_soc_platform_get_drvdata(rtd->platform);
138 struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
139 struct sst_byt *byt = pdata->byt;
140
141 dev_dbg(rtd->dev, "PCM: trigger %d\n", cmd);
142
143 switch (cmd) {
144 case SNDRV_PCM_TRIGGER_START:
145 sst_byt_stream_start(byt, pcm_data->stream);
146 break;
147 case SNDRV_PCM_TRIGGER_RESUME:
148 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
149 sst_byt_stream_resume(byt, pcm_data->stream);
150 break;
151 case SNDRV_PCM_TRIGGER_STOP:
152 sst_byt_stream_stop(byt, pcm_data->stream);
153 break;
154 case SNDRV_PCM_TRIGGER_SUSPEND:
155 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
156 sst_byt_stream_pause(byt, pcm_data->stream);
157 break;
158 default:
159 break;
160 }
161
162 return 0;
163}
164
165static u32 byt_notify_pointer(struct sst_byt_stream *stream, void *data)
166{
167 struct sst_byt_pcm_data *pcm_data = data;
168 struct snd_pcm_substream *substream = pcm_data->substream;
169 struct snd_pcm_runtime *runtime = substream->runtime;
170 struct snd_soc_pcm_runtime *rtd = substream->private_data;
171 u32 pos;
172
173 pos = frames_to_bytes(runtime,
174 (runtime->control->appl_ptr %
175 runtime->buffer_size));
176
177 dev_dbg(rtd->dev, "PCM: App pointer %d bytes\n", pos);
178
179 snd_pcm_period_elapsed(substream);
180 return pos;
181}
182
183static snd_pcm_uframes_t sst_byt_pcm_pointer(struct snd_pcm_substream *substream)
184{
185 struct snd_soc_pcm_runtime *rtd = substream->private_data;
186 struct snd_pcm_runtime *runtime = substream->runtime;
187 struct sst_byt_priv_data *pdata =
188 snd_soc_platform_get_drvdata(rtd->platform);
189 struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
190 struct sst_byt *byt = pdata->byt;
191 snd_pcm_uframes_t offset;
192 int pos;
193
194 pos = sst_byt_get_dsp_position(byt, pcm_data->stream,
195 snd_pcm_lib_buffer_bytes(substream));
196 offset = bytes_to_frames(runtime, pos);
197
198 dev_dbg(rtd->dev, "PCM: DMA pointer %zu bytes\n",
199 frames_to_bytes(runtime, (u32)offset));
200 return offset;
201}
202
203static int sst_byt_pcm_open(struct snd_pcm_substream *substream)
204{
205 struct snd_soc_pcm_runtime *rtd = substream->private_data;
206 struct sst_byt_priv_data *pdata =
207 snd_soc_platform_get_drvdata(rtd->platform);
208 struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
209 struct sst_byt *byt = pdata->byt;
210
211 dev_dbg(rtd->dev, "PCM: open\n");
212
213 pcm_data = &pdata->pcm[rtd->cpu_dai->id];
214 mutex_lock(&pcm_data->mutex);
215
216 snd_soc_pcm_set_drvdata(rtd, pcm_data);
217 pcm_data->substream = substream;
218
219 snd_soc_set_runtime_hwparams(substream, &sst_byt_pcm_hardware);
220
221 pcm_data->stream = sst_byt_stream_new(byt, rtd->cpu_dai->id + 1,
222 byt_notify_pointer, pcm_data);
223 if (pcm_data->stream == NULL) {
224 dev_err(rtd->dev, "failed to create stream\n");
225 mutex_unlock(&pcm_data->mutex);
226 return -EINVAL;
227 }
228
229 mutex_unlock(&pcm_data->mutex);
230 return 0;
231}
232
233static int sst_byt_pcm_close(struct snd_pcm_substream *substream)
234{
235 struct snd_soc_pcm_runtime *rtd = substream->private_data;
236 struct sst_byt_priv_data *pdata =
237 snd_soc_platform_get_drvdata(rtd->platform);
238 struct sst_byt_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
239 struct sst_byt *byt = pdata->byt;
240 int ret;
241
242 dev_dbg(rtd->dev, "PCM: close\n");
243
244 mutex_lock(&pcm_data->mutex);
245 ret = sst_byt_stream_free(byt, pcm_data->stream);
246 if (ret < 0) {
247 dev_dbg(rtd->dev, "Free stream fail\n");
248 goto out;
249 }
250 pcm_data->stream = NULL;
251
252out:
253 mutex_unlock(&pcm_data->mutex);
254 return ret;
255}
256
257static int sst_byt_pcm_mmap(struct snd_pcm_substream *substream,
258 struct vm_area_struct *vma)
259{
260 struct snd_soc_pcm_runtime *rtd = substream->private_data;
261
262 dev_dbg(rtd->dev, "PCM: mmap\n");
263 return snd_pcm_lib_default_mmap(substream, vma);
264}
265
266static struct snd_pcm_ops sst_byt_pcm_ops = {
267 .open = sst_byt_pcm_open,
268 .close = sst_byt_pcm_close,
269 .ioctl = snd_pcm_lib_ioctl,
270 .hw_params = sst_byt_pcm_hw_params,
271 .hw_free = sst_byt_pcm_hw_free,
272 .trigger = sst_byt_pcm_trigger,
273 .pointer = sst_byt_pcm_pointer,
274 .mmap = sst_byt_pcm_mmap,
275};
276
277static void sst_byt_pcm_free(struct snd_pcm *pcm)
278{
279 snd_pcm_lib_preallocate_free_for_all(pcm);
280}
281
282static int sst_byt_pcm_new(struct snd_soc_pcm_runtime *rtd)
283{
284 struct snd_pcm *pcm = rtd->pcm;
285 size_t size;
286 int ret = 0;
287
288 ret = dma_coerce_mask_and_coherent(rtd->card->dev, DMA_BIT_MASK(32));
289 if (ret)
290 return ret;
291
292 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream ||
293 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
294 size = sst_byt_pcm_hardware.buffer_bytes_max;
295 ret = snd_pcm_lib_preallocate_pages_for_all(pcm,
296 SNDRV_DMA_TYPE_DEV,
297 rtd->card->dev,
298 size, size);
299 if (ret) {
300 dev_err(rtd->dev, "dma buffer allocation failed %d\n",
301 ret);
302 return ret;
303 }
304 }
305
306 return ret;
307}
308
309static struct snd_soc_dai_driver byt_dais[] = {
310 {
311 .name = "Front-cpu-dai",
312 .playback = {
313 .stream_name = "System Playback",
314 .channels_min = 2,
315 .channels_max = 2,
316 .rates = SNDRV_PCM_RATE_48000,
317 .formats = SNDRV_PCM_FMTBIT_S24_3LE |
318 SNDRV_PCM_FMTBIT_S16_LE,
319 },
320 },
321 {
322 .name = "Mic1-cpu-dai",
323 .capture = {
324 .stream_name = "Analog Capture",
325 .channels_min = 2,
326 .channels_max = 2,
327 .rates = SNDRV_PCM_RATE_48000,
328 .formats = SNDRV_PCM_FMTBIT_S16_LE,
329 },
330 },
331};
332
333static int sst_byt_pcm_probe(struct snd_soc_platform *platform)
334{
335 struct sst_pdata *plat_data = dev_get_platdata(platform->dev);
336 struct sst_byt_priv_data *priv_data;
337 int i;
338
339 if (!plat_data)
340 return -ENODEV;
341
342 priv_data = devm_kzalloc(platform->dev, sizeof(*priv_data),
343 GFP_KERNEL);
344 priv_data->byt = plat_data->dsp;
345 snd_soc_platform_set_drvdata(platform, priv_data);
346
347 for (i = 0; i < ARRAY_SIZE(byt_dais); i++)
348 mutex_init(&priv_data->pcm[i].mutex);
349
350 return 0;
351}
352
353static int sst_byt_pcm_remove(struct snd_soc_platform *platform)
354{
355 return 0;
356}
357
358static struct snd_soc_platform_driver byt_soc_platform = {
359 .probe = sst_byt_pcm_probe,
360 .remove = sst_byt_pcm_remove,
361 .ops = &sst_byt_pcm_ops,
362 .pcm_new = sst_byt_pcm_new,
363 .pcm_free = sst_byt_pcm_free,
364};
365
366static const struct snd_soc_component_driver byt_dai_component = {
367 .name = "byt-dai",
368};
369
370static int sst_byt_pcm_dev_probe(struct platform_device *pdev)
371{
372 struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev);
373 int ret;
374
375 ret = sst_byt_dsp_init(&pdev->dev, sst_pdata);
376 if (ret < 0)
377 return -ENODEV;
378
379 ret = snd_soc_register_platform(&pdev->dev, &byt_soc_platform);
380 if (ret < 0)
381 goto err_plat;
382
383 ret = snd_soc_register_component(&pdev->dev, &byt_dai_component,
384 byt_dais, ARRAY_SIZE(byt_dais));
385 if (ret < 0)
386 goto err_comp;
387
388 return 0;
389
390err_comp:
391 snd_soc_unregister_platform(&pdev->dev);
392err_plat:
393 sst_byt_dsp_free(&pdev->dev, sst_pdata);
394 return ret;
395}
396
397static int sst_byt_pcm_dev_remove(struct platform_device *pdev)
398{
399 struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev);
400
401 snd_soc_unregister_platform(&pdev->dev);
402 snd_soc_unregister_component(&pdev->dev);
403 sst_byt_dsp_free(&pdev->dev, sst_pdata);
404
405 return 0;
406}
407
408static struct platform_driver sst_byt_pcm_driver = {
409 .driver = {
410 .name = "baytrail-pcm-audio",
411 .owner = THIS_MODULE,
412 },
413
414 .probe = sst_byt_pcm_dev_probe,
415 .remove = sst_byt_pcm_dev_remove,
416};
417module_platform_driver(sst_byt_pcm_driver);
418
419MODULE_AUTHOR("Jarkko Nikula");
420MODULE_DESCRIPTION("Baytrail PCM");
421MODULE_LICENSE("GPL v2");
422MODULE_ALIAS("platform:baytrail-pcm-audio");
diff --git a/sound/soc/intel/sst-dsp-priv.h b/sound/soc/intel/sst-dsp-priv.h
new file mode 100644
index 000000000000..fe8e81aad646
--- /dev/null
+++ b/sound/soc/intel/sst-dsp-priv.h
@@ -0,0 +1,309 @@
1/*
2 * Intel Smart Sound Technology
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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 version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#ifndef __SOUND_SOC_SST_DSP_PRIV_H
18#define __SOUND_SOC_SST_DSP_PRIV_H
19
20#include <linux/kernel.h>
21#include <linux/types.h>
22#include <linux/interrupt.h>
23#include <linux/firmware.h>
24
25struct sst_mem_block;
26struct sst_module;
27struct sst_fw;
28
29/*
30 * DSP Operations exported by platform Audio DSP driver.
31 */
32struct sst_ops {
33 /* DSP core boot / reset */
34 void (*boot)(struct sst_dsp *);
35 void (*reset)(struct sst_dsp *);
36
37 /* Shim IO */
38 void (*write)(void __iomem *addr, u32 offset, u32 value);
39 u32 (*read)(void __iomem *addr, u32 offset);
40 void (*write64)(void __iomem *addr, u32 offset, u64 value);
41 u64 (*read64)(void __iomem *addr, u32 offset);
42
43 /* DSP I/DRAM IO */
44 void (*ram_read)(struct sst_dsp *sst, void *dest, void __iomem *src,
45 size_t bytes);
46 void (*ram_write)(struct sst_dsp *sst, void __iomem *dest, void *src,
47 size_t bytes);
48
49 void (*dump)(struct sst_dsp *);
50
51 /* IRQ handlers */
52 irqreturn_t (*irq_handler)(int irq, void *context);
53
54 /* SST init and free */
55 int (*init)(struct sst_dsp *sst, struct sst_pdata *pdata);
56 void (*free)(struct sst_dsp *sst);
57
58 /* FW module parser/loader */
59 int (*parse_fw)(struct sst_fw *sst_fw);
60};
61
62/*
63 * Audio DSP memory offsets and addresses.
64 */
65struct sst_addr {
66 u32 lpe_base;
67 u32 shim_offset;
68 u32 iram_offset;
69 u32 dram_offset;
70 void __iomem *lpe;
71 void __iomem *shim;
72 void __iomem *pci_cfg;
73 void __iomem *fw_ext;
74};
75
76/*
77 * Audio DSP Mailbox configuration.
78 */
79struct sst_mailbox {
80 void __iomem *in_base;
81 void __iomem *out_base;
82 size_t in_size;
83 size_t out_size;
84};
85
86/*
87 * Audio DSP Firmware data types.
88 */
89enum sst_data_type {
90 SST_DATA_M = 0, /* module block data */
91 SST_DATA_P = 1, /* peristant data (text, data) */
92 SST_DATA_S = 2, /* scratch data (usually buffers) */
93};
94
95/*
96 * Audio DSP memory block types.
97 */
98enum sst_mem_type {
99 SST_MEM_IRAM = 0,
100 SST_MEM_DRAM = 1,
101 SST_MEM_ANY = 2,
102 SST_MEM_CACHE= 3,
103};
104
105/*
106 * Audio DSP Generic Firmware File.
107 *
108 * SST Firmware files can consist of 1..N modules. This generic structure is
109 * used to manage each firmware file and it's modules regardless of SST firmware
110 * type. A SST driver may load multiple FW files.
111 */
112struct sst_fw {
113 struct sst_dsp *dsp;
114
115 /* base addresses of FW file data */
116 dma_addr_t dmable_fw_paddr; /* physical address of fw data */
117 void *dma_buf; /* virtual address of fw data */
118 u32 size; /* size of fw data */
119
120 /* lists */
121 struct list_head list; /* DSP list of FW */
122 struct list_head module_list; /* FW list of modules */
123
124 void *private; /* core doesn't touch this */
125};
126
127/*
128 * Audio DSP Generic Module data.
129 *
130 * This is used to dsecribe any sections of persistent (text and data) and
131 * scratch (buffers) of module data in ADSP memory space.
132 */
133struct sst_module_data {
134
135 enum sst_mem_type type; /* destination memory type */
136 enum sst_data_type data_type; /* type of module data */
137
138 u32 size; /* size in bytes */
139 u32 offset; /* offset in FW file */
140 u32 data_offset; /* offset in ADSP memory space */
141 void *data; /* module data */
142};
143
144/*
145 * Audio DSP Generic Module Template.
146 *
147 * Used to define and register a new FW module. This data is extracted from
148 * FW module header information.
149 */
150struct sst_module_template {
151 u32 id;
152 u32 entry; /* entry point */
153 struct sst_module_data s; /* scratch data */
154 struct sst_module_data p; /* peristant data */
155};
156
157/*
158 * Audio DSP Generic Module.
159 *
160 * Each Firmware file can consist of 1..N modules. A module can span multiple
161 * ADSP memory blocks. The simplest FW will be a file with 1 module.
162 */
163struct sst_module {
164 struct sst_dsp *dsp;
165 struct sst_fw *sst_fw; /* parent FW we belong too */
166
167 /* module configuration */
168 u32 id;
169 u32 entry; /* module entry point */
170 u32 offset; /* module offset in firmware file */
171 u32 size; /* module size */
172 struct sst_module_data s; /* scratch data */
173 struct sst_module_data p; /* peristant data */
174
175 /* runtime */
176 u32 usage_count; /* can be unloaded if count == 0 */
177 void *private; /* core doesn't touch this */
178
179 /* lists */
180 struct list_head block_list; /* Module list of blocks in use */
181 struct list_head list; /* DSP list of modules */
182 struct list_head list_fw; /* FW list of modules */
183};
184
185/*
186 * SST Memory Block operations.
187 */
188struct sst_block_ops {
189 int (*enable)(struct sst_mem_block *block);
190 int (*disable)(struct sst_mem_block *block);
191};
192
193/*
194 * SST Generic Memory Block.
195 *
196 * SST ADP memory has multiple IRAM and DRAM blocks. Some ADSP blocks can be
197 * power gated.
198 */
199struct sst_mem_block {
200 struct sst_dsp *dsp;
201 struct sst_module *module; /* module that uses this block */
202
203 /* block config */
204 u32 offset; /* offset from base */
205 u32 size; /* block size */
206 u32 index; /* block index 0..N */
207 enum sst_mem_type type; /* block memory type IRAM/DRAM */
208 struct sst_block_ops *ops; /* block operations, if any */
209
210 /* block status */
211 enum sst_data_type data_type; /* data type held in this block */
212 u32 bytes_used; /* bytes in use by modules */
213 void *private; /* generic core does not touch this */
214 int users; /* number of modules using this block */
215
216 /* block lists */
217 struct list_head module_list; /* Module list of blocks */
218 struct list_head list; /* Map list of free/used blocks */
219};
220
221/*
222 * Generic SST Shim Interface.
223 */
224struct sst_dsp {
225
226 /* runtime */
227 struct sst_dsp_device *sst_dev;
228 spinlock_t spinlock; /* IPC locking */
229 struct mutex mutex; /* DSP FW lock */
230 struct device *dev;
231 void *thread_context;
232 int irq;
233 u32 id;
234
235 /* list of free and used ADSP memory blocks */
236 struct list_head used_block_list;
237 struct list_head free_block_list;
238
239 /* operations */
240 struct sst_ops *ops;
241
242 /* debug FS */
243 struct dentry *debugfs_root;
244
245 /* base addresses */
246 struct sst_addr addr;
247
248 /* mailbox */
249 struct sst_mailbox mailbox;
250
251 /* SST FW files loaded and their modules */
252 struct list_head module_list;
253 struct list_head fw_list;
254
255 /* platform data */
256 struct sst_pdata *pdata;
257
258 /* DMA FW loading */
259 struct sst_dma *dma;
260 bool fw_use_dma;
261};
262
263/* Size optimised DRAM/IRAM memcpy */
264static inline void sst_dsp_write(struct sst_dsp *sst, void *src,
265 u32 dest_offset, size_t bytes)
266{
267 sst->ops->ram_write(sst, sst->addr.lpe + dest_offset, src, bytes);
268}
269
270static inline void sst_dsp_read(struct sst_dsp *sst, void *dest,
271 u32 src_offset, size_t bytes)
272{
273 sst->ops->ram_read(sst, dest, sst->addr.lpe + src_offset, bytes);
274}
275
276static inline void *sst_dsp_get_thread_context(struct sst_dsp *sst)
277{
278 return sst->thread_context;
279}
280
281/* Create/Free FW files - can contain multiple modules */
282struct sst_fw *sst_fw_new(struct sst_dsp *dsp,
283 const struct firmware *fw, void *private);
284void sst_fw_free(struct sst_fw *sst_fw);
285void sst_fw_free_all(struct sst_dsp *dsp);
286
287/* Create/Free firmware modules */
288struct sst_module *sst_module_new(struct sst_fw *sst_fw,
289 struct sst_module_template *template, void *private);
290void sst_module_free(struct sst_module *sst_module);
291int sst_module_insert(struct sst_module *sst_module);
292int sst_module_remove(struct sst_module *sst_module);
293int sst_module_insert_fixed_block(struct sst_module *module,
294 struct sst_module_data *data);
295struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id);
296
297/* allocate/free pesistent/scratch memory regions managed by drv */
298struct sst_module *sst_mem_block_alloc_scratch(struct sst_dsp *dsp);
299void sst_mem_block_free_scratch(struct sst_dsp *dsp,
300 struct sst_module *scratch);
301int sst_block_module_remove(struct sst_module *module);
302
303/* Register the DSPs memory blocks - would be nice to read from ACPI */
304struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset,
305 u32 size, enum sst_mem_type type, struct sst_block_ops *ops, u32 index,
306 void *private);
307void sst_mem_block_unregister_all(struct sst_dsp *dsp);
308
309#endif
diff --git a/sound/soc/intel/sst-dsp.c b/sound/soc/intel/sst-dsp.c
new file mode 100644
index 000000000000..0c129fd85ecf
--- /dev/null
+++ b/sound/soc/intel/sst-dsp.c
@@ -0,0 +1,385 @@
1/*
2 * Intel Smart Sound Technology (SST) DSP Core Driver
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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 version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/slab.h>
18#include <linux/export.h>
19#include <linux/interrupt.h>
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/io.h>
23
24#include "sst-dsp.h"
25#include "sst-dsp-priv.h"
26
27#define CREATE_TRACE_POINTS
28#include <trace/events/intel-sst.h>
29
30/* Internal generic low-level SST IO functions - can be overidden */
31void sst_shim32_write(void __iomem *addr, u32 offset, u32 value)
32{
33 writel(value, addr + offset);
34}
35EXPORT_SYMBOL_GPL(sst_shim32_write);
36
37u32 sst_shim32_read(void __iomem *addr, u32 offset)
38{
39 return readl(addr + offset);
40}
41EXPORT_SYMBOL_GPL(sst_shim32_read);
42
43void sst_shim32_write64(void __iomem *addr, u32 offset, u64 value)
44{
45 memcpy_toio(addr + offset, &value, sizeof(value));
46}
47EXPORT_SYMBOL_GPL(sst_shim32_write64);
48
49u64 sst_shim32_read64(void __iomem *addr, u32 offset)
50{
51 u64 val;
52
53 memcpy_fromio(&val, addr + offset, sizeof(val));
54 return val;
55}
56EXPORT_SYMBOL_GPL(sst_shim32_read64);
57
58static inline void _sst_memcpy_toio_32(volatile u32 __iomem *dest,
59 u32 *src, size_t bytes)
60{
61 int i, words = bytes >> 2;
62
63 for (i = 0; i < words; i++)
64 writel(src[i], dest + i);
65}
66
67static inline void _sst_memcpy_fromio_32(u32 *dest,
68 const volatile __iomem u32 *src, size_t bytes)
69{
70 int i, words = bytes >> 2;
71
72 for (i = 0; i < words; i++)
73 dest[i] = readl(src + i);
74}
75
76void sst_memcpy_toio_32(struct sst_dsp *sst,
77 void __iomem *dest, void *src, size_t bytes)
78{
79 _sst_memcpy_toio_32(dest, src, bytes);
80}
81EXPORT_SYMBOL_GPL(sst_memcpy_toio_32);
82
83void sst_memcpy_fromio_32(struct sst_dsp *sst, void *dest,
84 void __iomem *src, size_t bytes)
85{
86 _sst_memcpy_fromio_32(dest, src, bytes);
87}
88EXPORT_SYMBOL_GPL(sst_memcpy_fromio_32);
89
90/* Public API */
91void sst_dsp_shim_write(struct sst_dsp *sst, u32 offset, u32 value)
92{
93 unsigned long flags;
94
95 spin_lock_irqsave(&sst->spinlock, flags);
96 sst->ops->write(sst->addr.shim, offset, value);
97 spin_unlock_irqrestore(&sst->spinlock, flags);
98}
99EXPORT_SYMBOL_GPL(sst_dsp_shim_write);
100
101u32 sst_dsp_shim_read(struct sst_dsp *sst, u32 offset)
102{
103 unsigned long flags;
104 u32 val;
105
106 spin_lock_irqsave(&sst->spinlock, flags);
107 val = sst->ops->read(sst->addr.shim, offset);
108 spin_unlock_irqrestore(&sst->spinlock, flags);
109
110 return val;
111}
112EXPORT_SYMBOL_GPL(sst_dsp_shim_read);
113
114void sst_dsp_shim_write64(struct sst_dsp *sst, u32 offset, u64 value)
115{
116 unsigned long flags;
117
118 spin_lock_irqsave(&sst->spinlock, flags);
119 sst->ops->write64(sst->addr.shim, offset, value);
120 spin_unlock_irqrestore(&sst->spinlock, flags);
121}
122EXPORT_SYMBOL_GPL(sst_dsp_shim_write64);
123
124u64 sst_dsp_shim_read64(struct sst_dsp *sst, u32 offset)
125{
126 unsigned long flags;
127 u64 val;
128
129 spin_lock_irqsave(&sst->spinlock, flags);
130 val = sst->ops->read64(sst->addr.shim, offset);
131 spin_unlock_irqrestore(&sst->spinlock, flags);
132
133 return val;
134}
135EXPORT_SYMBOL_GPL(sst_dsp_shim_read64);
136
137void sst_dsp_shim_write_unlocked(struct sst_dsp *sst, u32 offset, u32 value)
138{
139 sst->ops->write(sst->addr.shim, offset, value);
140}
141EXPORT_SYMBOL_GPL(sst_dsp_shim_write_unlocked);
142
143u32 sst_dsp_shim_read_unlocked(struct sst_dsp *sst, u32 offset)
144{
145 return sst->ops->read(sst->addr.shim, offset);
146}
147EXPORT_SYMBOL_GPL(sst_dsp_shim_read_unlocked);
148
149void sst_dsp_shim_write64_unlocked(struct sst_dsp *sst, u32 offset, u64 value)
150{
151 sst->ops->write64(sst->addr.shim, offset, value);
152}
153EXPORT_SYMBOL_GPL(sst_dsp_shim_write64_unlocked);
154
155u64 sst_dsp_shim_read64_unlocked(struct sst_dsp *sst, u32 offset)
156{
157 return sst->ops->read64(sst->addr.shim, offset);
158}
159EXPORT_SYMBOL_GPL(sst_dsp_shim_read64_unlocked);
160
161int sst_dsp_shim_update_bits_unlocked(struct sst_dsp *sst, u32 offset,
162 u32 mask, u32 value)
163{
164 bool change;
165 unsigned int old, new;
166 u32 ret;
167
168 ret = sst_dsp_shim_read_unlocked(sst, offset);
169
170 old = ret;
171 new = (old & (~mask)) | (value & mask);
172
173 change = (old != new);
174 if (change)
175 sst_dsp_shim_write_unlocked(sst, offset, new);
176
177 return change;
178}
179EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits_unlocked);
180
181int sst_dsp_shim_update_bits64_unlocked(struct sst_dsp *sst, u32 offset,
182 u64 mask, u64 value)
183{
184 bool change;
185 u64 old, new;
186
187 old = sst_dsp_shim_read64_unlocked(sst, offset);
188
189 new = (old & (~mask)) | (value & mask);
190
191 change = (old != new);
192 if (change)
193 sst_dsp_shim_write64_unlocked(sst, offset, new);
194
195 return change;
196}
197EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits64_unlocked);
198
199int sst_dsp_shim_update_bits(struct sst_dsp *sst, u32 offset,
200 u32 mask, u32 value)
201{
202 unsigned long flags;
203 bool change;
204
205 spin_lock_irqsave(&sst->spinlock, flags);
206 change = sst_dsp_shim_update_bits_unlocked(sst, offset, mask, value);
207 spin_unlock_irqrestore(&sst->spinlock, flags);
208 return change;
209}
210EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits);
211
212int sst_dsp_shim_update_bits64(struct sst_dsp *sst, u32 offset,
213 u64 mask, u64 value)
214{
215 unsigned long flags;
216 bool change;
217
218 spin_lock_irqsave(&sst->spinlock, flags);
219 change = sst_dsp_shim_update_bits64_unlocked(sst, offset, mask, value);
220 spin_unlock_irqrestore(&sst->spinlock, flags);
221 return change;
222}
223EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits64);
224
225void sst_dsp_dump(struct sst_dsp *sst)
226{
227 sst->ops->dump(sst);
228}
229EXPORT_SYMBOL_GPL(sst_dsp_dump);
230
231void sst_dsp_reset(struct sst_dsp *sst)
232{
233 sst->ops->reset(sst);
234}
235EXPORT_SYMBOL_GPL(sst_dsp_reset);
236
237int sst_dsp_boot(struct sst_dsp *sst)
238{
239 sst->ops->boot(sst);
240 return 0;
241}
242EXPORT_SYMBOL_GPL(sst_dsp_boot);
243
244void sst_dsp_ipc_msg_tx(struct sst_dsp *dsp, u32 msg)
245{
246 sst_dsp_shim_write_unlocked(dsp, SST_IPCX, msg | SST_IPCX_BUSY);
247 trace_sst_ipc_msg_tx(msg);
248}
249EXPORT_SYMBOL_GPL(sst_dsp_ipc_msg_tx);
250
251u32 sst_dsp_ipc_msg_rx(struct sst_dsp *dsp)
252{
253 u32 msg;
254
255 msg = sst_dsp_shim_read_unlocked(dsp, SST_IPCX);
256 trace_sst_ipc_msg_rx(msg);
257
258 return msg;
259}
260EXPORT_SYMBOL_GPL(sst_dsp_ipc_msg_rx);
261
262int sst_dsp_mailbox_init(struct sst_dsp *sst, u32 inbox_offset, size_t inbox_size,
263 u32 outbox_offset, size_t outbox_size)
264{
265 sst->mailbox.in_base = sst->addr.lpe + inbox_offset;
266 sst->mailbox.out_base = sst->addr.lpe + outbox_offset;
267 sst->mailbox.in_size = inbox_size;
268 sst->mailbox.out_size = outbox_size;
269 return 0;
270}
271EXPORT_SYMBOL_GPL(sst_dsp_mailbox_init);
272
273void sst_dsp_outbox_write(struct sst_dsp *sst, void *message, size_t bytes)
274{
275 u32 i;
276
277 trace_sst_ipc_outbox_write(bytes);
278
279 memcpy_toio(sst->mailbox.out_base, message, bytes);
280
281 for (i = 0; i < bytes; i += 4)
282 trace_sst_ipc_outbox_wdata(i, *(u32 *)(message + i));
283}
284EXPORT_SYMBOL_GPL(sst_dsp_outbox_write);
285
286void sst_dsp_outbox_read(struct sst_dsp *sst, void *message, size_t bytes)
287{
288 u32 i;
289
290 trace_sst_ipc_outbox_read(bytes);
291
292 memcpy_fromio(message, sst->mailbox.out_base, bytes);
293
294 for (i = 0; i < bytes; i += 4)
295 trace_sst_ipc_outbox_rdata(i, *(u32 *)(message + i));
296}
297EXPORT_SYMBOL_GPL(sst_dsp_outbox_read);
298
299void sst_dsp_inbox_write(struct sst_dsp *sst, void *message, size_t bytes)
300{
301 u32 i;
302
303 trace_sst_ipc_inbox_write(bytes);
304
305 memcpy_toio(sst->mailbox.in_base, message, bytes);
306
307 for (i = 0; i < bytes; i += 4)
308 trace_sst_ipc_inbox_wdata(i, *(u32 *)(message + i));
309}
310EXPORT_SYMBOL_GPL(sst_dsp_inbox_write);
311
312void sst_dsp_inbox_read(struct sst_dsp *sst, void *message, size_t bytes)
313{
314 u32 i;
315
316 trace_sst_ipc_inbox_read(bytes);
317
318 memcpy_fromio(message, sst->mailbox.in_base, bytes);
319
320 for (i = 0; i < bytes; i += 4)
321 trace_sst_ipc_inbox_rdata(i, *(u32 *)(message + i));
322}
323EXPORT_SYMBOL_GPL(sst_dsp_inbox_read);
324
325struct sst_dsp *sst_dsp_new(struct device *dev,
326 struct sst_dsp_device *sst_dev, struct sst_pdata *pdata)
327{
328 struct sst_dsp *sst;
329 int err;
330
331 dev_dbg(dev, "initialising audio DSP id 0x%x\n", pdata->id);
332
333 sst = devm_kzalloc(dev, sizeof(*sst), GFP_KERNEL);
334 if (sst == NULL)
335 return NULL;
336
337 spin_lock_init(&sst->spinlock);
338 mutex_init(&sst->mutex);
339 sst->dev = dev;
340 sst->thread_context = sst_dev->thread_context;
341 sst->sst_dev = sst_dev;
342 sst->id = pdata->id;
343 sst->irq = pdata->irq;
344 sst->ops = sst_dev->ops;
345 sst->pdata = pdata;
346 INIT_LIST_HEAD(&sst->used_block_list);
347 INIT_LIST_HEAD(&sst->free_block_list);
348 INIT_LIST_HEAD(&sst->module_list);
349 INIT_LIST_HEAD(&sst->fw_list);
350
351 /* Initialise SST Audio DSP */
352 if (sst->ops->init) {
353 err = sst->ops->init(sst, pdata);
354 if (err < 0)
355 return NULL;
356 }
357
358 /* Register the ISR */
359 err = request_threaded_irq(sst->irq, sst->ops->irq_handler,
360 sst_dev->thread, IRQF_SHARED, "AudioDSP", sst);
361 if (err)
362 goto irq_err;
363
364 return sst;
365
366irq_err:
367 if (sst->ops->free)
368 sst->ops->free(sst);
369
370 return NULL;
371}
372EXPORT_SYMBOL_GPL(sst_dsp_new);
373
374void sst_dsp_free(struct sst_dsp *sst)
375{
376 free_irq(sst->irq, sst);
377 if (sst->ops->free)
378 sst->ops->free(sst);
379}
380EXPORT_SYMBOL_GPL(sst_dsp_free);
381
382/* Module information */
383MODULE_AUTHOR("Liam Girdwood");
384MODULE_DESCRIPTION("Intel SST Core");
385MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/intel/sst-dsp.h b/sound/soc/intel/sst-dsp.h
new file mode 100644
index 000000000000..74052b59485c
--- /dev/null
+++ b/sound/soc/intel/sst-dsp.h
@@ -0,0 +1,233 @@
1/*
2 * Intel Smart Sound Technology (SST) Core
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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 version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#ifndef __SOUND_SOC_SST_DSP_H
18#define __SOUND_SOC_SST_DSP_H
19
20#include <linux/kernel.h>
21#include <linux/types.h>
22#include <linux/interrupt.h>
23
24/* SST Device IDs */
25#define SST_DEV_ID_LYNX_POINT 0x33C8
26#define SST_DEV_ID_WILDCAT_POINT 0x3438
27#define SST_DEV_ID_BYT 0x0F28
28
29/* Supported SST DMA Devices */
30#define SST_DMA_TYPE_DW 1
31#define SST_DMA_TYPE_MID 2
32
33/* SST Shim register map
34 * The register naming can differ between products. Some products also
35 * contain extra functionality.
36 */
37#define SST_CSR 0x00
38#define SST_PISR 0x08
39#define SST_PIMR 0x10
40#define SST_ISRX 0x18
41#define SST_ISRD 0x20
42#define SST_IMRX 0x28
43#define SST_IMRD 0x30
44#define SST_IPCX 0x38 /* IPC IA -> SST */
45#define SST_IPCD 0x40 /* IPC SST -> IA */
46#define SST_ISRSC 0x48
47#define SST_ISRLPESC 0x50
48#define SST_IMRSC 0x58
49#define SST_IMRLPESC 0x60
50#define SST_IPCSC 0x68
51#define SST_IPCLPESC 0x70
52#define SST_CLKCTL 0x78
53#define SST_CSR2 0x80
54#define SST_LTRC 0xE0
55#define SST_HDMC 0xE8
56#define SST_DBGO 0xF0
57
58#define SST_SHIM_SIZE 0x100
59#define SST_PWMCTRL 0x1000
60
61/* SST Shim Register bits
62 * The register bit naming can differ between products. Some products also
63 * contain extra functionality.
64 */
65
66/* CSR / CS */
67#define SST_CSR_RST (0x1 << 1)
68#define SST_CSR_SBCS0 (0x1 << 2)
69#define SST_CSR_SBCS1 (0x1 << 3)
70#define SST_CSR_DCS(x) (x << 4)
71#define SST_CSR_DCS_MASK (0x7 << 4)
72#define SST_CSR_STALL (0x1 << 10)
73#define SST_CSR_S0IOCS (0x1 << 21)
74#define SST_CSR_S1IOCS (0x1 << 23)
75#define SST_CSR_LPCS (0x1 << 31)
76#define SST_BYT_CSR_RST (0x1 << 0)
77#define SST_BYT_CSR_VECTOR_SEL (0x1 << 1)
78#define SST_BYT_CSR_STALL (0x1 << 2)
79#define SST_BYT_CSR_PWAITMODE (0x1 << 3)
80
81/* ISRX / ISC */
82#define SST_ISRX_BUSY (0x1 << 1)
83#define SST_ISRX_DONE (0x1 << 0)
84#define SST_BYT_ISRX_REQUEST (0x1 << 1)
85
86/* ISRD / ISD */
87#define SST_ISRD_BUSY (0x1 << 1)
88#define SST_ISRD_DONE (0x1 << 0)
89
90/* IMRX / IMC */
91#define SST_IMRX_BUSY (0x1 << 1)
92#define SST_IMRX_DONE (0x1 << 0)
93#define SST_BYT_IMRX_REQUEST (0x1 << 1)
94
95/* IPCX / IPCC */
96#define SST_IPCX_DONE (0x1 << 30)
97#define SST_IPCX_BUSY (0x1 << 31)
98#define SST_BYT_IPCX_DONE ((u64)0x1 << 62)
99#define SST_BYT_IPCX_BUSY ((u64)0x1 << 63)
100
101/* IPCD */
102#define SST_IPCD_DONE (0x1 << 30)
103#define SST_IPCD_BUSY (0x1 << 31)
104#define SST_BYT_IPCD_DONE ((u64)0x1 << 62)
105#define SST_BYT_IPCD_BUSY ((u64)0x1 << 63)
106
107/* CLKCTL */
108#define SST_CLKCTL_SMOS(x) (x << 24)
109#define SST_CLKCTL_MASK (3 << 24)
110#define SST_CLKCTL_DCPLCG (1 << 18)
111#define SST_CLKCTL_SCOE1 (1 << 17)
112#define SST_CLKCTL_SCOE0 (1 << 16)
113
114/* CSR2 / CS2 */
115#define SST_CSR2_SDFD_SSP0 (1 << 1)
116#define SST_CSR2_SDFD_SSP1 (1 << 2)
117
118/* LTRC */
119#define SST_LTRC_VAL(x) (x << 0)
120
121/* HDMC */
122#define SST_HDMC_HDDA0(x) (x << 0)
123#define SST_HDMC_HDDA1(x) (x << 7)
124
125
126/* SST Vendor Defined Registers and bits */
127#define SST_VDRTCTL0 0xa0
128#define SST_VDRTCTL1 0xa4
129#define SST_VDRTCTL2 0xa8
130#define SST_VDRTCTL3 0xaC
131
132/* VDRTCTL0 */
133#define SST_VDRTCL0_DSRAMPGE_SHIFT 16
134#define SST_VDRTCL0_DSRAMPGE_MASK (0xffff << SST_VDRTCL0_DSRAMPGE_SHIFT)
135#define SST_VDRTCL0_ISRAMPGE_SHIFT 6
136#define SST_VDRTCL0_ISRAMPGE_MASK (0x3ff << SST_VDRTCL0_ISRAMPGE_SHIFT)
137
138struct sst_dsp;
139
140/*
141 * SST Device.
142 *
143 * This structure is populated by the SST core driver.
144 */
145struct sst_dsp_device {
146 /* Mandatory fields */
147 struct sst_ops *ops;
148 irqreturn_t (*thread)(int irq, void *context);
149 void *thread_context;
150};
151
152/*
153 * SST Platform Data.
154 */
155struct sst_pdata {
156 /* ACPI data */
157 u32 lpe_base;
158 u32 lpe_size;
159 u32 pcicfg_base;
160 u32 pcicfg_size;
161 u32 fw_base;
162 u32 fw_size;
163 int irq;
164
165 /* Firmware */
166 const struct firmware *fw;
167
168 /* DMA */
169 u32 dma_base;
170 u32 dma_size;
171 int dma_engine;
172
173 /* DSP */
174 u32 id;
175 void *dsp;
176};
177
178/* Initialization */
179struct sst_dsp *sst_dsp_new(struct device *dev,
180 struct sst_dsp_device *sst_dev, struct sst_pdata *pdata);
181void sst_dsp_free(struct sst_dsp *sst);
182
183/* SHIM Read / Write */
184void sst_dsp_shim_write(struct sst_dsp *sst, u32 offset, u32 value);
185u32 sst_dsp_shim_read(struct sst_dsp *sst, u32 offset);
186int sst_dsp_shim_update_bits(struct sst_dsp *sst, u32 offset,
187 u32 mask, u32 value);
188void sst_dsp_shim_write64(struct sst_dsp *sst, u32 offset, u64 value);
189u64 sst_dsp_shim_read64(struct sst_dsp *sst, u32 offset);
190int sst_dsp_shim_update_bits64(struct sst_dsp *sst, u32 offset,
191 u64 mask, u64 value);
192
193/* SHIM Read / Write Unlocked for callers already holding sst lock */
194void sst_dsp_shim_write_unlocked(struct sst_dsp *sst, u32 offset, u32 value);
195u32 sst_dsp_shim_read_unlocked(struct sst_dsp *sst, u32 offset);
196int sst_dsp_shim_update_bits_unlocked(struct sst_dsp *sst, u32 offset,
197 u32 mask, u32 value);
198void sst_dsp_shim_write64_unlocked(struct sst_dsp *sst, u32 offset, u64 value);
199u64 sst_dsp_shim_read64_unlocked(struct sst_dsp *sst, u32 offset);
200int sst_dsp_shim_update_bits64_unlocked(struct sst_dsp *sst, u32 offset,
201 u64 mask, u64 value);
202
203/* Internal generic low-level SST IO functions - can be overidden */
204void sst_shim32_write(void __iomem *addr, u32 offset, u32 value);
205u32 sst_shim32_read(void __iomem *addr, u32 offset);
206void sst_shim32_write64(void __iomem *addr, u32 offset, u64 value);
207u64 sst_shim32_read64(void __iomem *addr, u32 offset);
208void sst_memcpy_toio_32(struct sst_dsp *sst,
209 void __iomem *dest, void *src, size_t bytes);
210void sst_memcpy_fromio_32(struct sst_dsp *sst,
211 void *dest, void __iomem *src, size_t bytes);
212
213/* DSP reset & boot */
214void sst_dsp_reset(struct sst_dsp *sst);
215int sst_dsp_boot(struct sst_dsp *sst);
216
217/* Msg IO */
218void sst_dsp_ipc_msg_tx(struct sst_dsp *dsp, u32 msg);
219u32 sst_dsp_ipc_msg_rx(struct sst_dsp *dsp);
220
221/* Mailbox management */
222int sst_dsp_mailbox_init(struct sst_dsp *dsp, u32 inbox_offset,
223 size_t inbox_size, u32 outbox_offset, size_t outbox_size);
224void sst_dsp_inbox_write(struct sst_dsp *dsp, void *message, size_t bytes);
225void sst_dsp_inbox_read(struct sst_dsp *dsp, void *message, size_t bytes);
226void sst_dsp_outbox_write(struct sst_dsp *dsp, void *message, size_t bytes);
227void sst_dsp_outbox_read(struct sst_dsp *dsp, void *message, size_t bytes);
228void sst_dsp_mailbox_dump(struct sst_dsp *dsp, size_t bytes);
229
230/* Debug */
231void sst_dsp_dump(struct sst_dsp *sst);
232
233#endif
diff --git a/sound/soc/intel/sst-firmware.c b/sound/soc/intel/sst-firmware.c
new file mode 100644
index 000000000000..f7687107cf7f
--- /dev/null
+++ b/sound/soc/intel/sst-firmware.c
@@ -0,0 +1,587 @@
1/*
2 * Intel SST Firmware Loader
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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 version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/kernel.h>
18#include <linux/slab.h>
19#include <linux/sched.h>
20#include <linux/firmware.h>
21#include <linux/export.h>
22#include <linux/platform_device.h>
23#include <linux/dma-mapping.h>
24#include <linux/dmaengine.h>
25#include <linux/pci.h>
26
27#include <asm/page.h>
28#include <asm/pgtable.h>
29
30#include "sst-dsp.h"
31#include "sst-dsp-priv.h"
32
33static void sst_memcpy32(volatile void __iomem *dest, void *src, u32 bytes)
34{
35 u32 i;
36
37 /* copy one 32 bit word at a time as 64 bit access is not supported */
38 for (i = 0; i < bytes; i += 4)
39 memcpy_toio(dest + i, src + i, 4);
40}
41
42/* create new generic firmware object */
43struct sst_fw *sst_fw_new(struct sst_dsp *dsp,
44 const struct firmware *fw, void *private)
45{
46 struct sst_fw *sst_fw;
47 int err;
48
49 if (!dsp->ops->parse_fw)
50 return NULL;
51
52 sst_fw = kzalloc(sizeof(*sst_fw), GFP_KERNEL);
53 if (sst_fw == NULL)
54 return NULL;
55
56 sst_fw->dsp = dsp;
57 sst_fw->private = private;
58 sst_fw->size = fw->size;
59
60 err = dma_coerce_mask_and_coherent(dsp->dev, DMA_BIT_MASK(32));
61 if (err < 0) {
62 kfree(sst_fw);
63 return NULL;
64 }
65
66 /* allocate DMA buffer to store FW data */
67 sst_fw->dma_buf = dma_alloc_coherent(dsp->dev, sst_fw->size,
68 &sst_fw->dmable_fw_paddr, GFP_DMA | GFP_KERNEL);
69 if (!sst_fw->dma_buf) {
70 dev_err(dsp->dev, "error: DMA alloc failed\n");
71 kfree(sst_fw);
72 return NULL;
73 }
74
75 /* copy FW data to DMA-able memory */
76 memcpy((void *)sst_fw->dma_buf, (void *)fw->data, fw->size);
77
78 /* call core specific FW paser to load FW data into DSP */
79 err = dsp->ops->parse_fw(sst_fw);
80 if (err < 0) {
81 dev_err(dsp->dev, "error: parse fw failed %d\n", err);
82 goto parse_err;
83 }
84
85 mutex_lock(&dsp->mutex);
86 list_add(&sst_fw->list, &dsp->fw_list);
87 mutex_unlock(&dsp->mutex);
88
89 return sst_fw;
90
91parse_err:
92 dma_free_coherent(dsp->dev, sst_fw->size,
93 sst_fw->dma_buf,
94 sst_fw->dmable_fw_paddr);
95 kfree(sst_fw);
96 return NULL;
97}
98EXPORT_SYMBOL_GPL(sst_fw_new);
99
100/* free single firmware object */
101void sst_fw_free(struct sst_fw *sst_fw)
102{
103 struct sst_dsp *dsp = sst_fw->dsp;
104
105 mutex_lock(&dsp->mutex);
106 list_del(&sst_fw->list);
107 mutex_unlock(&dsp->mutex);
108
109 dma_free_coherent(dsp->dev, sst_fw->size, sst_fw->dma_buf,
110 sst_fw->dmable_fw_paddr);
111 kfree(sst_fw);
112}
113EXPORT_SYMBOL_GPL(sst_fw_free);
114
115/* free all firmware objects */
116void sst_fw_free_all(struct sst_dsp *dsp)
117{
118 struct sst_fw *sst_fw, *t;
119
120 mutex_lock(&dsp->mutex);
121 list_for_each_entry_safe(sst_fw, t, &dsp->fw_list, list) {
122
123 list_del(&sst_fw->list);
124 dma_free_coherent(dsp->dev, sst_fw->size, sst_fw->dma_buf,
125 sst_fw->dmable_fw_paddr);
126 kfree(sst_fw);
127 }
128 mutex_unlock(&dsp->mutex);
129}
130EXPORT_SYMBOL_GPL(sst_fw_free_all);
131
132/* create a new SST generic module from FW template */
133struct sst_module *sst_module_new(struct sst_fw *sst_fw,
134 struct sst_module_template *template, void *private)
135{
136 struct sst_dsp *dsp = sst_fw->dsp;
137 struct sst_module *sst_module;
138
139 sst_module = kzalloc(sizeof(*sst_module), GFP_KERNEL);
140 if (sst_module == NULL)
141 return NULL;
142
143 sst_module->id = template->id;
144 sst_module->dsp = dsp;
145 sst_module->sst_fw = sst_fw;
146
147 memcpy(&sst_module->s, &template->s, sizeof(struct sst_module_data));
148 memcpy(&sst_module->p, &template->p, sizeof(struct sst_module_data));
149
150 INIT_LIST_HEAD(&sst_module->block_list);
151
152 mutex_lock(&dsp->mutex);
153 list_add(&sst_module->list, &dsp->module_list);
154 mutex_unlock(&dsp->mutex);
155
156 return sst_module;
157}
158EXPORT_SYMBOL_GPL(sst_module_new);
159
160/* free firmware module and remove from available list */
161void sst_module_free(struct sst_module *sst_module)
162{
163 struct sst_dsp *dsp = sst_module->dsp;
164
165 mutex_lock(&dsp->mutex);
166 list_del(&sst_module->list);
167 mutex_unlock(&dsp->mutex);
168
169 kfree(sst_module);
170}
171EXPORT_SYMBOL_GPL(sst_module_free);
172
173static struct sst_mem_block *find_block(struct sst_dsp *dsp, int type,
174 u32 offset)
175{
176 struct sst_mem_block *block;
177
178 list_for_each_entry(block, &dsp->free_block_list, list) {
179 if (block->type == type && block->offset == offset)
180 return block;
181 }
182
183 return NULL;
184}
185
186static int block_alloc_contiguous(struct sst_module *module,
187 struct sst_module_data *data, u32 offset, int size)
188{
189 struct list_head tmp = LIST_HEAD_INIT(tmp);
190 struct sst_dsp *dsp = module->dsp;
191 struct sst_mem_block *block;
192
193 while (size > 0) {
194 block = find_block(dsp, data->type, offset);
195 if (!block) {
196 list_splice(&tmp, &dsp->free_block_list);
197 return -ENOMEM;
198 }
199
200 list_move_tail(&block->list, &tmp);
201 offset += block->size;
202 size -= block->size;
203 }
204
205 list_splice(&tmp, &dsp->used_block_list);
206 return 0;
207}
208
209/* allocate free DSP blocks for module data - callers hold locks */
210static int block_alloc(struct sst_module *module,
211 struct sst_module_data *data)
212{
213 struct sst_dsp *dsp = module->dsp;
214 struct sst_mem_block *block, *tmp;
215 int ret = 0;
216
217 if (data->size == 0)
218 return 0;
219
220 /* find first free whole blocks that can hold module */
221 list_for_each_entry_safe(block, tmp, &dsp->free_block_list, list) {
222
223 /* ignore blocks with wrong type */
224 if (block->type != data->type)
225 continue;
226
227 if (data->size > block->size)
228 continue;
229
230 data->offset = block->offset;
231 block->data_type = data->data_type;
232 block->bytes_used = data->size % block->size;
233 list_add(&block->module_list, &module->block_list);
234 list_move(&block->list, &dsp->used_block_list);
235 dev_dbg(dsp->dev, " *module %d added block %d:%d\n",
236 module->id, block->type, block->index);
237 return 0;
238 }
239
240 /* then find free multiple blocks that can hold module */
241 list_for_each_entry_safe(block, tmp, &dsp->free_block_list, list) {
242
243 /* ignore blocks with wrong type */
244 if (block->type != data->type)
245 continue;
246
247 /* do we span > 1 blocks */
248 if (data->size > block->size) {
249 ret = block_alloc_contiguous(module, data,
250 block->offset + block->size,
251 data->size - block->size);
252 if (ret == 0)
253 return ret;
254 }
255 }
256
257 /* not enough free block space */
258 return -ENOMEM;
259}
260
261/* remove module from memory - callers hold locks */
262static void block_module_remove(struct sst_module *module)
263{
264 struct sst_mem_block *block, *tmp;
265 struct sst_dsp *dsp = module->dsp;
266 int err;
267
268 /* disable each block */
269 list_for_each_entry(block, &module->block_list, module_list) {
270
271 if (block->ops && block->ops->disable) {
272 err = block->ops->disable(block);
273 if (err < 0)
274 dev_err(dsp->dev,
275 "error: cant disable block %d:%d\n",
276 block->type, block->index);
277 }
278 }
279
280 /* mark each block as free */
281 list_for_each_entry_safe(block, tmp, &module->block_list, module_list) {
282 list_del(&block->module_list);
283 list_move(&block->list, &dsp->free_block_list);
284 }
285}
286
287/* prepare the memory block to receive data from host - callers hold locks */
288static int block_module_prepare(struct sst_module *module)
289{
290 struct sst_mem_block *block;
291 int ret = 0;
292
293 /* enable each block so that's it'e ready for module P/S data */
294 list_for_each_entry(block, &module->block_list, module_list) {
295
296 if (block->ops && block->ops->enable) {
297 ret = block->ops->enable(block);
298 if (ret < 0) {
299 dev_err(module->dsp->dev,
300 "error: cant disable block %d:%d\n",
301 block->type, block->index);
302 goto err;
303 }
304 }
305 }
306 return ret;
307
308err:
309 list_for_each_entry(block, &module->block_list, module_list) {
310 if (block->ops && block->ops->disable)
311 block->ops->disable(block);
312 }
313 return ret;
314}
315
316/* allocate memory blocks for static module addresses - callers hold locks */
317static int block_alloc_fixed(struct sst_module *module,
318 struct sst_module_data *data)
319{
320 struct sst_dsp *dsp = module->dsp;
321 struct sst_mem_block *block, *tmp;
322 u32 end = data->offset + data->size, block_end;
323 int err;
324
325 /* only IRAM/DRAM blocks are managed */
326 if (data->type != SST_MEM_IRAM && data->type != SST_MEM_DRAM)
327 return 0;
328
329 /* are blocks already attached to this module */
330 list_for_each_entry_safe(block, tmp, &module->block_list, module_list) {
331
332 /* force compacting mem blocks of the same data_type */
333 if (block->data_type != data->data_type)
334 continue;
335
336 block_end = block->offset + block->size;
337
338 /* find block that holds section */
339 if (data->offset >= block->offset && end < block_end)
340 return 0;
341
342 /* does block span more than 1 section */
343 if (data->offset >= block->offset && data->offset < block_end) {
344
345 err = block_alloc_contiguous(module, data,
346 block->offset + block->size,
347 data->size - block->size + data->offset - block->offset);
348 if (err < 0)
349 return -ENOMEM;
350
351 /* module already owns blocks */
352 return 0;
353 }
354 }
355
356 /* find first free blocks that can hold section in free list */
357 list_for_each_entry_safe(block, tmp, &dsp->free_block_list, list) {
358 block_end = block->offset + block->size;
359
360 /* find block that holds section */
361 if (data->offset >= block->offset && end < block_end) {
362
363 /* add block */
364 block->data_type = data->data_type;
365 list_move(&block->list, &dsp->used_block_list);
366 list_add(&block->module_list, &module->block_list);
367 return 0;
368 }
369
370 /* does block span more than 1 section */
371 if (data->offset >= block->offset && data->offset < block_end) {
372
373 err = block_alloc_contiguous(module, data,
374 block->offset + block->size,
375 data->size - block->size);
376 if (err < 0)
377 return -ENOMEM;
378
379 /* add block */
380 block->data_type = data->data_type;
381 list_move(&block->list, &dsp->used_block_list);
382 list_add(&block->module_list, &module->block_list);
383 return 0;
384 }
385
386 }
387
388 return -ENOMEM;
389}
390
391/* Load fixed module data into DSP memory blocks */
392int sst_module_insert_fixed_block(struct sst_module *module,
393 struct sst_module_data *data)
394{
395 struct sst_dsp *dsp = module->dsp;
396 int ret;
397
398 mutex_lock(&dsp->mutex);
399
400 /* alloc blocks that includes this section */
401 ret = block_alloc_fixed(module, data);
402 if (ret < 0) {
403 dev_err(dsp->dev,
404 "error: no free blocks for section at offset 0x%x size 0x%x\n",
405 data->offset, data->size);
406 mutex_unlock(&dsp->mutex);
407 return -ENOMEM;
408 }
409
410 /* prepare DSP blocks for module copy */
411 ret = block_module_prepare(module);
412 if (ret < 0) {
413 dev_err(dsp->dev, "error: fw module prepare failed\n");
414 goto err;
415 }
416
417 /* copy partial module data to blocks */
418 sst_memcpy32(dsp->addr.lpe + data->offset, data->data, data->size);
419
420 mutex_unlock(&dsp->mutex);
421 return ret;
422
423err:
424 block_module_remove(module);
425 mutex_unlock(&dsp->mutex);
426 return ret;
427}
428EXPORT_SYMBOL_GPL(sst_module_insert_fixed_block);
429
430/* Unload entire module from DSP memory */
431int sst_block_module_remove(struct sst_module *module)
432{
433 struct sst_dsp *dsp = module->dsp;
434
435 mutex_lock(&dsp->mutex);
436 block_module_remove(module);
437 mutex_unlock(&dsp->mutex);
438 return 0;
439}
440EXPORT_SYMBOL_GPL(sst_block_module_remove);
441
442/* register a DSP memory block for use with FW based modules */
443struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset,
444 u32 size, enum sst_mem_type type, struct sst_block_ops *ops, u32 index,
445 void *private)
446{
447 struct sst_mem_block *block;
448
449 block = kzalloc(sizeof(*block), GFP_KERNEL);
450 if (block == NULL)
451 return NULL;
452
453 block->offset = offset;
454 block->size = size;
455 block->index = index;
456 block->type = type;
457 block->dsp = dsp;
458 block->private = private;
459 block->ops = ops;
460
461 mutex_lock(&dsp->mutex);
462 list_add(&block->list, &dsp->free_block_list);
463 mutex_unlock(&dsp->mutex);
464
465 return block;
466}
467EXPORT_SYMBOL_GPL(sst_mem_block_register);
468
469/* unregister all DSP memory blocks */
470void sst_mem_block_unregister_all(struct sst_dsp *dsp)
471{
472 struct sst_mem_block *block, *tmp;
473
474 mutex_lock(&dsp->mutex);
475
476 /* unregister used blocks */
477 list_for_each_entry_safe(block, tmp, &dsp->used_block_list, list) {
478 list_del(&block->list);
479 kfree(block);
480 }
481
482 /* unregister free blocks */
483 list_for_each_entry_safe(block, tmp, &dsp->free_block_list, list) {
484 list_del(&block->list);
485 kfree(block);
486 }
487
488 mutex_unlock(&dsp->mutex);
489}
490EXPORT_SYMBOL_GPL(sst_mem_block_unregister_all);
491
492/* allocate scratch buffer blocks */
493struct sst_module *sst_mem_block_alloc_scratch(struct sst_dsp *dsp)
494{
495 struct sst_module *sst_module, *scratch;
496 struct sst_mem_block *block, *tmp;
497 u32 block_size;
498 int ret = 0;
499
500 scratch = kzalloc(sizeof(struct sst_module), GFP_KERNEL);
501 if (scratch == NULL)
502 return NULL;
503
504 mutex_lock(&dsp->mutex);
505
506 /* calculate required scratch size */
507 list_for_each_entry(sst_module, &dsp->module_list, list) {
508 if (scratch->s.size > sst_module->s.size)
509 scratch->s.size = scratch->s.size;
510 else
511 scratch->s.size = sst_module->s.size;
512 }
513
514 dev_dbg(dsp->dev, "scratch buffer required is %d bytes\n",
515 scratch->s.size);
516
517 /* init scratch module */
518 scratch->dsp = dsp;
519 scratch->s.type = SST_MEM_DRAM;
520 scratch->s.data_type = SST_DATA_S;
521 INIT_LIST_HEAD(&scratch->block_list);
522
523 /* check free blocks before looking at used blocks for space */
524 if (!list_empty(&dsp->free_block_list))
525 block = list_first_entry(&dsp->free_block_list,
526 struct sst_mem_block, list);
527 else
528 block = list_first_entry(&dsp->used_block_list,
529 struct sst_mem_block, list);
530 block_size = block->size;
531
532 /* allocate blocks for module scratch buffers */
533 dev_dbg(dsp->dev, "allocating scratch blocks\n");
534 ret = block_alloc(scratch, &scratch->s);
535 if (ret < 0) {
536 dev_err(dsp->dev, "error: can't alloc scratch blocks\n");
537 goto err;
538 }
539
540 /* assign the same offset of scratch to each module */
541 list_for_each_entry(sst_module, &dsp->module_list, list)
542 sst_module->s.offset = scratch->s.offset;
543
544 mutex_unlock(&dsp->mutex);
545 return scratch;
546
547err:
548 list_for_each_entry_safe(block, tmp, &scratch->block_list, module_list)
549 list_del(&block->module_list);
550 mutex_unlock(&dsp->mutex);
551 return NULL;
552}
553EXPORT_SYMBOL_GPL(sst_mem_block_alloc_scratch);
554
555/* free all scratch blocks */
556void sst_mem_block_free_scratch(struct sst_dsp *dsp,
557 struct sst_module *scratch)
558{
559 struct sst_mem_block *block, *tmp;
560
561 mutex_lock(&dsp->mutex);
562
563 list_for_each_entry_safe(block, tmp, &scratch->block_list, module_list)
564 list_del(&block->module_list);
565
566 mutex_unlock(&dsp->mutex);
567}
568EXPORT_SYMBOL_GPL(sst_mem_block_free_scratch);
569
570/* get a module from it's unique ID */
571struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id)
572{
573 struct sst_module *module;
574
575 mutex_lock(&dsp->mutex);
576
577 list_for_each_entry(module, &dsp->module_list, list) {
578 if (module->id == id) {
579 mutex_unlock(&dsp->mutex);
580 return module;
581 }
582 }
583
584 mutex_unlock(&dsp->mutex);
585 return NULL;
586}
587EXPORT_SYMBOL_GPL(sst_module_get_from_id);
diff --git a/sound/soc/intel/sst-haswell-dsp.c b/sound/soc/intel/sst-haswell-dsp.c
new file mode 100644
index 000000000000..f5ebf36af889
--- /dev/null
+++ b/sound/soc/intel/sst-haswell-dsp.c
@@ -0,0 +1,517 @@
1/*
2 * Intel Haswell SST DSP driver
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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 version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/delay.h>
18#include <linux/fs.h>
19#include <linux/slab.h>
20#include <linux/device.h>
21#include <linux/sched.h>
22#include <linux/export.h>
23#include <linux/interrupt.h>
24#include <linux/module.h>
25#include <linux/dma-mapping.h>
26#include <linux/platform_device.h>
27#include <linux/pci.h>
28#include <linux/firmware.h>
29#include <linux/pm_runtime.h>
30
31#include <linux/acpi.h>
32#include <acpi/acpi_bus.h>
33
34#include "sst-dsp.h"
35#include "sst-dsp-priv.h"
36#include "sst-haswell-ipc.h"
37
38#include <trace/events/hswadsp.h>
39
40#define SST_HSW_FW_SIGNATURE_SIZE 4
41#define SST_HSW_FW_SIGN "$SST"
42#define SST_HSW_FW_LIB_SIGN "$LIB"
43
44#define SST_WPT_SHIM_OFFSET 0xFB000
45#define SST_LP_SHIM_OFFSET 0xE7000
46#define SST_WPT_IRAM_OFFSET 0xA0000
47#define SST_LP_IRAM_OFFSET 0x80000
48
49#define SST_SHIM_PM_REG 0x84
50
51#define SST_HSW_IRAM 1
52#define SST_HSW_DRAM 2
53#define SST_HSW_REGS 3
54
55struct dma_block_info {
56 __le32 type; /* IRAM/DRAM */
57 __le32 size; /* Bytes */
58 __le32 ram_offset; /* Offset in I/DRAM */
59 __le32 rsvd; /* Reserved field */
60} __attribute__((packed));
61
62struct fw_module_info {
63 __le32 persistent_size;
64 __le32 scratch_size;
65} __attribute__((packed));
66
67struct fw_header {
68 unsigned char signature[SST_HSW_FW_SIGNATURE_SIZE]; /* FW signature */
69 __le32 file_size; /* size of fw minus this header */
70 __le32 modules; /* # of modules */
71 __le32 file_format; /* version of header format */
72 __le32 reserved[4];
73} __attribute__((packed));
74
75struct fw_module_header {
76 unsigned char signature[SST_HSW_FW_SIGNATURE_SIZE]; /* module signature */
77 __le32 mod_size; /* size of module */
78 __le32 blocks; /* # of blocks */
79 __le16 padding;
80 __le16 type; /* codec type, pp lib */
81 __le32 entry_point;
82 struct fw_module_info info;
83} __attribute__((packed));
84
85static void hsw_free(struct sst_dsp *sst);
86
87static int hsw_parse_module(struct sst_dsp *dsp, struct sst_fw *fw,
88 struct fw_module_header *module)
89{
90 struct dma_block_info *block;
91 struct sst_module *mod;
92 struct sst_module_data block_data;
93 struct sst_module_template template;
94 int count;
95 void __iomem *ram;
96
97 /* TODO: allowed module types need to be configurable */
98 if (module->type != SST_HSW_MODULE_BASE_FW
99 && module->type != SST_HSW_MODULE_PCM_SYSTEM
100 && module->type != SST_HSW_MODULE_PCM
101 && module->type != SST_HSW_MODULE_PCM_REFERENCE
102 && module->type != SST_HSW_MODULE_PCM_CAPTURE
103 && module->type != SST_HSW_MODULE_LPAL)
104 return 0;
105
106 dev_dbg(dsp->dev, "new module sign 0x%s size 0x%x blocks 0x%x type 0x%x\n",
107 module->signature, module->mod_size,
108 module->blocks, module->type);
109 dev_dbg(dsp->dev, " entrypoint 0x%x\n", module->entry_point);
110 dev_dbg(dsp->dev, " persistent 0x%x scratch 0x%x\n",
111 module->info.persistent_size, module->info.scratch_size);
112
113 memset(&template, 0, sizeof(template));
114 template.id = module->type;
115 template.entry = module->entry_point;
116 template.p.size = module->info.persistent_size;
117 template.p.type = SST_MEM_DRAM;
118 template.p.data_type = SST_DATA_P;
119 template.s.size = module->info.scratch_size;
120 template.s.type = SST_MEM_DRAM;
121 template.s.data_type = SST_DATA_S;
122
123 mod = sst_module_new(fw, &template, NULL);
124 if (mod == NULL)
125 return -ENOMEM;
126
127 block = (void *)module + sizeof(*module);
128
129 for (count = 0; count < module->blocks; count++) {
130
131 if (block->size <= 0) {
132 dev_err(dsp->dev,
133 "error: block %d size invalid\n", count);
134 sst_module_free(mod);
135 return -EINVAL;
136 }
137
138 switch (block->type) {
139 case SST_HSW_IRAM:
140 ram = dsp->addr.lpe;
141 block_data.offset =
142 block->ram_offset + dsp->addr.iram_offset;
143 block_data.type = SST_MEM_IRAM;
144 break;
145 case SST_HSW_DRAM:
146 ram = dsp->addr.lpe;
147 block_data.offset = block->ram_offset;
148 block_data.type = SST_MEM_DRAM;
149 break;
150 default:
151 dev_err(dsp->dev, "error: bad type 0x%x for block 0x%x\n",
152 block->type, count);
153 sst_module_free(mod);
154 return -EINVAL;
155 }
156
157 block_data.size = block->size;
158 block_data.data_type = SST_DATA_M;
159 block_data.data = (void *)block + sizeof(*block);
160 block_data.data_offset = block_data.data - fw->dma_buf;
161
162 dev_dbg(dsp->dev, "copy firmware block %d type 0x%x "
163 "size 0x%x ==> ram %p offset 0x%x\n",
164 count, block->type, block->size, ram,
165 block->ram_offset);
166
167 sst_module_insert_fixed_block(mod, &block_data);
168
169 block = (void *)block + sizeof(*block) + block->size;
170 }
171 return 0;
172}
173
174static int hsw_parse_fw_image(struct sst_fw *sst_fw)
175{
176 struct fw_header *header;
177 struct sst_module *scratch;
178 struct fw_module_header *module;
179 struct sst_dsp *dsp = sst_fw->dsp;
180 struct sst_hsw *hsw = sst_fw->private;
181 int ret, count;
182
183 /* Read the header information from the data pointer */
184 header = (struct fw_header *)sst_fw->dma_buf;
185
186 /* verify FW */
187 if ((strncmp(header->signature, SST_HSW_FW_SIGN, 4) != 0) ||
188 (sst_fw->size != header->file_size + sizeof(*header))) {
189 dev_err(dsp->dev, "error: invalid fw sign/filesize mismatch\n");
190 return -EINVAL;
191 }
192
193 dev_dbg(dsp->dev, "header size=0x%x modules=0x%x fmt=0x%x size=%zu\n",
194 header->file_size, header->modules,
195 header->file_format, sizeof(*header));
196
197 /* parse each module */
198 module = (void *)sst_fw->dma_buf + sizeof(*header);
199 for (count = 0; count < header->modules; count++) {
200
201 /* module */
202 ret = hsw_parse_module(dsp, sst_fw, module);
203 if (ret < 0) {
204 dev_err(dsp->dev, "error: invalid module %d\n", count);
205 return ret;
206 }
207 module = (void *)module + sizeof(*module) + module->mod_size;
208 }
209
210 /* allocate persistent/scratch mem regions */
211 scratch = sst_mem_block_alloc_scratch(dsp);
212 if (scratch == NULL)
213 return -ENOMEM;
214
215 sst_hsw_set_scratch_module(hsw, scratch);
216
217 return 0;
218}
219
220static irqreturn_t hsw_irq(int irq, void *context)
221{
222 struct sst_dsp *sst = (struct sst_dsp *) context;
223 u32 isr;
224 int ret = IRQ_NONE;
225
226 spin_lock(&sst->spinlock);
227
228 /* Interrupt arrived, check src */
229 isr = sst_dsp_shim_read_unlocked(sst, SST_ISRX);
230 if (isr & SST_ISRX_DONE) {
231 trace_sst_irq_done(isr,
232 sst_dsp_shim_read_unlocked(sst, SST_IMRX));
233
234 /* Mask Done interrupt before return */
235 sst_dsp_shim_update_bits_unlocked(sst, SST_IMRX,
236 SST_IMRX_DONE, SST_IMRX_DONE);
237 ret = IRQ_WAKE_THREAD;
238 }
239
240 if (isr & SST_ISRX_BUSY) {
241 trace_sst_irq_busy(isr,
242 sst_dsp_shim_read_unlocked(sst, SST_IMRX));
243
244 /* Mask Busy interrupt before return */
245 sst_dsp_shim_update_bits_unlocked(sst, SST_IMRX,
246 SST_IMRX_BUSY, SST_IMRX_BUSY);
247 ret = IRQ_WAKE_THREAD;
248 }
249
250 spin_unlock(&sst->spinlock);
251 return ret;
252}
253
254static void hsw_boot(struct sst_dsp *sst)
255{
256 /* select SSP1 19.2MHz base clock, SSP clock 0, turn off Low Power Clock */
257 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR,
258 SST_CSR_S1IOCS | SST_CSR_SBCS1 | SST_CSR_LPCS, 0x0);
259
260 /* stall DSP core, set clk to 192/96Mhz */
261 sst_dsp_shim_update_bits_unlocked(sst,
262 SST_CSR, SST_CSR_STALL | SST_CSR_DCS_MASK,
263 SST_CSR_STALL | SST_CSR_DCS(4));
264
265 /* Set 24MHz MCLK, prevent local clock gating, enable SSP0 clock */
266 sst_dsp_shim_update_bits_unlocked(sst, SST_CLKCTL,
267 SST_CLKCTL_MASK | SST_CLKCTL_DCPLCG | SST_CLKCTL_SCOE0,
268 SST_CLKCTL_MASK | SST_CLKCTL_DCPLCG | SST_CLKCTL_SCOE0);
269
270 /* disable DMA finish function for SSP0 & SSP1 */
271 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR2, SST_CSR2_SDFD_SSP1,
272 SST_CSR2_SDFD_SSP1);
273
274 /* enable DMA engine 0,1 all channels to access host memory */
275 sst_dsp_shim_update_bits_unlocked(sst, SST_HDMC,
276 SST_HDMC_HDDA1(0xff) | SST_HDMC_HDDA0(0xff),
277 SST_HDMC_HDDA1(0xff) | SST_HDMC_HDDA0(0xff));
278
279 /* disable all clock gating */
280 writel(0x0, sst->addr.pci_cfg + SST_VDRTCTL2);
281
282 /* set DSP to RUN */
283 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR, SST_CSR_STALL, 0x0);
284}
285
286static void hsw_reset(struct sst_dsp *sst)
287{
288 /* put DSP into reset and stall */
289 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR,
290 SST_CSR_RST | SST_CSR_STALL, SST_CSR_RST | SST_CSR_STALL);
291
292 /* keep in reset for 10ms */
293 mdelay(10);
294
295 /* take DSP out of reset and keep stalled for FW loading */
296 sst_dsp_shim_update_bits_unlocked(sst, SST_CSR,
297 SST_CSR_RST | SST_CSR_STALL, SST_CSR_STALL);
298}
299
300struct sst_adsp_memregion {
301 u32 start;
302 u32 end;
303 int blocks;
304 enum sst_mem_type type;
305};
306
307/* lynx point ADSP mem regions */
308static const struct sst_adsp_memregion lp_region[] = {
309 {0x00000, 0x40000, 8, SST_MEM_DRAM}, /* D-SRAM0 - 8 * 32kB */
310 {0x40000, 0x80000, 8, SST_MEM_DRAM}, /* D-SRAM1 - 8 * 32kB */
311 {0x80000, 0xE0000, 12, SST_MEM_IRAM}, /* I-SRAM - 12 * 32kB */
312};
313
314/* wild cat point ADSP mem regions */
315static const struct sst_adsp_memregion wpt_region[] = {
316 {0x00000, 0x40000, 8, SST_MEM_DRAM}, /* D-SRAM0 - 8 * 32kB */
317 {0x40000, 0x80000, 8, SST_MEM_DRAM}, /* D-SRAM1 - 8 * 32kB */
318 {0x80000, 0xA0000, 4, SST_MEM_DRAM}, /* D-SRAM2 - 4 * 32kB */
319 {0xA0000, 0xF0000, 10, SST_MEM_IRAM}, /* I-SRAM - 10 * 32kB */
320};
321
322static int hsw_acpi_resource_map(struct sst_dsp *sst, struct sst_pdata *pdata)
323{
324 /* ADSP DRAM & IRAM */
325 sst->addr.lpe_base = pdata->lpe_base;
326 sst->addr.lpe = ioremap(pdata->lpe_base, pdata->lpe_size);
327 if (!sst->addr.lpe)
328 return -ENODEV;
329
330 /* ADSP PCI MMIO config space */
331 sst->addr.pci_cfg = ioremap(pdata->pcicfg_base, pdata->pcicfg_size);
332 if (!sst->addr.pci_cfg) {
333 iounmap(sst->addr.lpe);
334 return -ENODEV;
335 }
336
337 /* SST Shim */
338 sst->addr.shim = sst->addr.lpe + sst->addr.shim_offset;
339 return 0;
340}
341
342static u32 hsw_block_get_bit(struct sst_mem_block *block)
343{
344 u32 bit = 0, shift = 0;
345
346 switch (block->type) {
347 case SST_MEM_DRAM:
348 shift = 16;
349 break;
350 case SST_MEM_IRAM:
351 shift = 6;
352 break;
353 default:
354 return 0;
355 }
356
357 bit = 1 << (block->index + shift);
358
359 return bit;
360}
361
362/* enable 32kB memory block - locks held by caller */
363static int hsw_block_enable(struct sst_mem_block *block)
364{
365 struct sst_dsp *sst = block->dsp;
366 u32 bit, val;
367
368 if (block->users++ > 0)
369 return 0;
370
371 dev_dbg(block->dsp->dev, " enabled block %d:%d at offset 0x%x\n",
372 block->type, block->index, block->offset);
373
374 val = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
375 bit = hsw_block_get_bit(block);
376 writel(val & ~bit, sst->addr.pci_cfg + SST_VDRTCTL0);
377
378 /* wait 18 DSP clock ticks */
379 udelay(10);
380
381 return 0;
382}
383
384/* disable 32kB memory block - locks held by caller */
385static int hsw_block_disable(struct sst_mem_block *block)
386{
387 struct sst_dsp *sst = block->dsp;
388 u32 bit, val;
389
390 if (--block->users > 0)
391 return 0;
392
393 dev_dbg(block->dsp->dev, " disabled block %d:%d at offset 0x%x\n",
394 block->type, block->index, block->offset);
395
396 val = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
397 bit = hsw_block_get_bit(block);
398 writel(val | bit, sst->addr.pci_cfg + SST_VDRTCTL0);
399
400 return 0;
401}
402
403static struct sst_block_ops sst_hsw_ops = {
404 .enable = hsw_block_enable,
405 .disable = hsw_block_disable,
406};
407
408static int hsw_enable_shim(struct sst_dsp *sst)
409{
410 int tries = 10;
411 u32 reg;
412
413 /* enable shim */
414 reg = readl(sst->addr.pci_cfg + SST_SHIM_PM_REG);
415 writel(reg & ~0x3, sst->addr.pci_cfg + SST_SHIM_PM_REG);
416
417 /* check that ADSP shim is enabled */
418 while (tries--) {
419 reg = sst_dsp_shim_read_unlocked(sst, SST_CSR);
420 if (reg != 0xffffffff)
421 return 0;
422
423 msleep(1);
424 }
425
426 return -ENODEV;
427}
428
429static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata)
430{
431 const struct sst_adsp_memregion *region;
432 struct device *dev;
433 int ret = -ENODEV, i, j, region_count;
434 u32 offset, size;
435
436 dev = sst->dev;
437
438 switch (sst->id) {
439 case SST_DEV_ID_LYNX_POINT:
440 region = lp_region;
441 region_count = ARRAY_SIZE(lp_region);
442 sst->addr.iram_offset = SST_LP_IRAM_OFFSET;
443 sst->addr.shim_offset = SST_LP_SHIM_OFFSET;
444 break;
445 case SST_DEV_ID_WILDCAT_POINT:
446 region = wpt_region;
447 region_count = ARRAY_SIZE(wpt_region);
448 sst->addr.iram_offset = SST_WPT_IRAM_OFFSET;
449 sst->addr.shim_offset = SST_WPT_SHIM_OFFSET;
450 break;
451 default:
452 dev_err(dev, "error: failed to get mem resources\n");
453 return ret;
454 }
455
456 ret = hsw_acpi_resource_map(sst, pdata);
457 if (ret < 0) {
458 dev_err(dev, "error: failed to map resources\n");
459 return ret;
460 }
461
462 /* enable the DSP SHIM */
463 ret = hsw_enable_shim(sst);
464 if (ret < 0) {
465 dev_err(dev, "error: failed to set DSP D0 and reset SHIM\n");
466 return ret;
467 }
468
469 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
470 if (ret)
471 return ret;
472
473 /* Enable Interrupt from both sides */
474 sst_dsp_shim_update_bits_unlocked(sst, SST_IMRX, 0x3, 0x0);
475 sst_dsp_shim_update_bits_unlocked(sst, SST_IMRD,
476 (0x3 | 0x1 << 16 | 0x3 << 21), 0x0);
477
478 /* register DSP memory blocks - ideally we should get this from ACPI */
479 for (i = 0; i < region_count; i++) {
480 offset = region[i].start;
481 size = (region[i].end - region[i].start) / region[i].blocks;
482
483 /* register individual memory blocks */
484 for (j = 0; j < region[i].blocks; j++) {
485 sst_mem_block_register(sst, offset, size,
486 region[i].type, &sst_hsw_ops, j, sst);
487 offset += size;
488 }
489 }
490
491 /* set default power gating mask */
492 writel(0x0, sst->addr.pci_cfg + SST_VDRTCTL0);
493
494 return 0;
495}
496
497static void hsw_free(struct sst_dsp *sst)
498{
499 sst_mem_block_unregister_all(sst);
500 iounmap(sst->addr.lpe);
501 iounmap(sst->addr.pci_cfg);
502}
503
504struct sst_ops haswell_ops = {
505 .reset = hsw_reset,
506 .boot = hsw_boot,
507 .write = sst_shim32_write,
508 .read = sst_shim32_read,
509 .write64 = sst_shim32_write64,
510 .read64 = sst_shim32_read64,
511 .ram_read = sst_memcpy_fromio_32,
512 .ram_write = sst_memcpy_toio_32,
513 .irq_handler = hsw_irq,
514 .init = hsw_init,
515 .free = hsw_free,
516 .parse_fw = hsw_parse_fw_image,
517};
diff --git a/sound/soc/intel/sst-haswell-ipc.c b/sound/soc/intel/sst-haswell-ipc.c
new file mode 100644
index 000000000000..f46bb4ddde6f
--- /dev/null
+++ b/sound/soc/intel/sst-haswell-ipc.c
@@ -0,0 +1,1785 @@
1/*
2 * Intel SST Haswell/Broadwell IPC Support
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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 version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/types.h>
18#include <linux/kernel.h>
19#include <linux/list.h>
20#include <linux/device.h>
21#include <linux/wait.h>
22#include <linux/spinlock.h>
23#include <linux/workqueue.h>
24#include <linux/export.h>
25#include <linux/slab.h>
26#include <linux/delay.h>
27#include <linux/sched.h>
28#include <linux/list.h>
29#include <linux/platform_device.h>
30#include <linux/kthread.h>
31#include <linux/firmware.h>
32#include <linux/dma-mapping.h>
33#include <linux/debugfs.h>
34
35#include "sst-haswell-ipc.h"
36#include "sst-dsp.h"
37#include "sst-dsp-priv.h"
38
39/* Global Message - Generic */
40#define IPC_GLB_TYPE_SHIFT 24
41#define IPC_GLB_TYPE_MASK (0x1f << IPC_GLB_TYPE_SHIFT)
42#define IPC_GLB_TYPE(x) (x << IPC_GLB_TYPE_SHIFT)
43
44/* Global Message - Reply */
45#define IPC_GLB_REPLY_SHIFT 0
46#define IPC_GLB_REPLY_MASK (0x1f << IPC_GLB_REPLY_SHIFT)
47#define IPC_GLB_REPLY_TYPE(x) (x << IPC_GLB_REPLY_TYPE_SHIFT)
48
49/* Stream Message - Generic */
50#define IPC_STR_TYPE_SHIFT 20
51#define IPC_STR_TYPE_MASK (0xf << IPC_STR_TYPE_SHIFT)
52#define IPC_STR_TYPE(x) (x << IPC_STR_TYPE_SHIFT)
53#define IPC_STR_ID_SHIFT 16
54#define IPC_STR_ID_MASK (0xf << IPC_STR_ID_SHIFT)
55#define IPC_STR_ID(x) (x << IPC_STR_ID_SHIFT)
56
57/* Stream Message - Reply */
58#define IPC_STR_REPLY_SHIFT 0
59#define IPC_STR_REPLY_MASK (0x1f << IPC_STR_REPLY_SHIFT)
60
61/* Stream Stage Message - Generic */
62#define IPC_STG_TYPE_SHIFT 12
63#define IPC_STG_TYPE_MASK (0xf << IPC_STG_TYPE_SHIFT)
64#define IPC_STG_TYPE(x) (x << IPC_STG_TYPE_SHIFT)
65#define IPC_STG_ID_SHIFT 10
66#define IPC_STG_ID_MASK (0x3 << IPC_STG_ID_SHIFT)
67#define IPC_STG_ID(x) (x << IPC_STG_ID_SHIFT)
68
69/* Stream Stage Message - Reply */
70#define IPC_STG_REPLY_SHIFT 0
71#define IPC_STG_REPLY_MASK (0x1f << IPC_STG_REPLY_SHIFT)
72
73/* Debug Log Message - Generic */
74#define IPC_LOG_OP_SHIFT 20
75#define IPC_LOG_OP_MASK (0xf << IPC_LOG_OP_SHIFT)
76#define IPC_LOG_OP_TYPE(x) (x << IPC_LOG_OP_SHIFT)
77#define IPC_LOG_ID_SHIFT 16
78#define IPC_LOG_ID_MASK (0xf << IPC_LOG_ID_SHIFT)
79#define IPC_LOG_ID(x) (x << IPC_LOG_ID_SHIFT)
80
81/* IPC message timeout (msecs) */
82#define IPC_TIMEOUT_MSECS 300
83#define IPC_BOOT_MSECS 200
84#define IPC_MSG_WAIT 0
85#define IPC_MSG_NOWAIT 1
86
87/* Firmware Ready Message */
88#define IPC_FW_READY (0x1 << 29)
89#define IPC_STATUS_MASK (0x3 << 30)
90
91#define IPC_EMPTY_LIST_SIZE 8
92#define IPC_MAX_STREAMS 4
93
94/* Mailbox */
95#define IPC_MAX_MAILBOX_BYTES 256
96
97/* Global Message - Types and Replies */
98enum ipc_glb_type {
99 IPC_GLB_GET_FW_VERSION = 0, /* Retrieves firmware version */
100 IPC_GLB_PERFORMANCE_MONITOR = 1, /* Performance monitoring actions */
101 IPC_GLB_ALLOCATE_STREAM = 3, /* Request to allocate new stream */
102 IPC_GLB_FREE_STREAM = 4, /* Request to free stream */
103 IPC_GLB_GET_FW_CAPABILITIES = 5, /* Retrieves firmware capabilities */
104 IPC_GLB_STREAM_MESSAGE = 6, /* Message directed to stream or its stages */
105 /* Request to store firmware context during D0->D3 transition */
106 IPC_GLB_REQUEST_DUMP = 7,
107 /* Request to restore firmware context during D3->D0 transition */
108 IPC_GLB_RESTORE_CONTEXT = 8,
109 IPC_GLB_GET_DEVICE_FORMATS = 9, /* Set device format */
110 IPC_GLB_SET_DEVICE_FORMATS = 10, /* Get device format */
111 IPC_GLB_SHORT_REPLY = 11,
112 IPC_GLB_ENTER_DX_STATE = 12,
113 IPC_GLB_GET_MIXER_STREAM_INFO = 13, /* Request mixer stream params */
114 IPC_GLB_DEBUG_LOG_MESSAGE = 14, /* Message to or from the debug logger. */
115 IPC_GLB_REQUEST_TRANSFER = 16, /* < Request Transfer for host */
116 IPC_GLB_MAX_IPC_MESSAGE_TYPE = 17, /* Maximum message number */
117};
118
119enum ipc_glb_reply {
120 IPC_GLB_REPLY_SUCCESS = 0, /* The operation was successful. */
121 IPC_GLB_REPLY_ERROR_INVALID_PARAM = 1, /* Invalid parameter was passed. */
122 IPC_GLB_REPLY_UNKNOWN_MESSAGE_TYPE = 2, /* Uknown message type was resceived. */
123 IPC_GLB_REPLY_OUT_OF_RESOURCES = 3, /* No resources to satisfy the request. */
124 IPC_GLB_REPLY_BUSY = 4, /* The system or resource is busy. */
125 IPC_GLB_REPLY_PENDING = 5, /* The action was scheduled for processing. */
126 IPC_GLB_REPLY_FAILURE = 6, /* Critical error happened. */
127 IPC_GLB_REPLY_INVALID_REQUEST = 7, /* Request can not be completed. */
128 IPC_GLB_REPLY_STAGE_UNINITIALIZED = 8, /* Processing stage was uninitialized. */
129 IPC_GLB_REPLY_NOT_FOUND = 9, /* Required resource can not be found. */
130 IPC_GLB_REPLY_SOURCE_NOT_STARTED = 10, /* Source was not started. */
131};
132
133/* Stream Message - Types */
134enum ipc_str_operation {
135 IPC_STR_RESET = 0,
136 IPC_STR_PAUSE = 1,
137 IPC_STR_RESUME = 2,
138 IPC_STR_STAGE_MESSAGE = 3,
139 IPC_STR_NOTIFICATION = 4,
140 IPC_STR_MAX_MESSAGE
141};
142
143/* Stream Stage Message Types */
144enum ipc_stg_operation {
145 IPC_STG_GET_VOLUME = 0,
146 IPC_STG_SET_VOLUME,
147 IPC_STG_SET_WRITE_POSITION,
148 IPC_STG_SET_FX_ENABLE,
149 IPC_STG_SET_FX_DISABLE,
150 IPC_STG_SET_FX_GET_PARAM,
151 IPC_STG_SET_FX_SET_PARAM,
152 IPC_STG_SET_FX_GET_INFO,
153 IPC_STG_MUTE_LOOPBACK,
154 IPC_STG_MAX_MESSAGE
155};
156
157/* Stream Stage Message Types For Notification*/
158enum ipc_stg_operation_notify {
159 IPC_POSITION_CHANGED = 0,
160 IPC_STG_GLITCH,
161 IPC_STG_MAX_NOTIFY
162};
163
164enum ipc_glitch_type {
165 IPC_GLITCH_UNDERRUN = 1,
166 IPC_GLITCH_DECODER_ERROR,
167 IPC_GLITCH_DOUBLED_WRITE_POS,
168 IPC_GLITCH_MAX
169};
170
171/* Debug Control */
172enum ipc_debug_operation {
173 IPC_DEBUG_ENABLE_LOG = 0,
174 IPC_DEBUG_DISABLE_LOG = 1,
175 IPC_DEBUG_REQUEST_LOG_DUMP = 2,
176 IPC_DEBUG_NOTIFY_LOG_DUMP = 3,
177 IPC_DEBUG_MAX_DEBUG_LOG
178};
179
180/* Firmware Ready */
181struct sst_hsw_ipc_fw_ready {
182 u32 inbox_offset;
183 u32 outbox_offset;
184 u32 inbox_size;
185 u32 outbox_size;
186 u32 fw_info_size;
187 u8 fw_info[1];
188} __attribute__((packed));
189
190struct ipc_message {
191 struct list_head list;
192 u32 header;
193
194 /* direction wrt host CPU */
195 char tx_data[IPC_MAX_MAILBOX_BYTES];
196 size_t tx_size;
197 char rx_data[IPC_MAX_MAILBOX_BYTES];
198 size_t rx_size;
199
200 wait_queue_head_t waitq;
201 bool pending;
202 bool complete;
203 bool wait;
204 int errno;
205};
206
207struct sst_hsw_stream;
208struct sst_hsw;
209
210/* Stream infomation */
211struct sst_hsw_stream {
212 /* configuration */
213 struct sst_hsw_ipc_stream_alloc_req request;
214 struct sst_hsw_ipc_stream_alloc_reply reply;
215 struct sst_hsw_ipc_stream_free_req free_req;
216
217 /* Mixer info */
218 u32 mute_volume[SST_HSW_NO_CHANNELS];
219 u32 mute[SST_HSW_NO_CHANNELS];
220
221 /* runtime info */
222 struct sst_hsw *hsw;
223 int host_id;
224 bool commited;
225 bool running;
226
227 /* Notification work */
228 struct work_struct notify_work;
229 u32 header;
230
231 /* Position info from DSP */
232 struct sst_hsw_ipc_stream_set_position wpos;
233 struct sst_hsw_ipc_stream_get_position rpos;
234 struct sst_hsw_ipc_stream_glitch_position glitch;
235
236 /* Volume info */
237 struct sst_hsw_ipc_volume_req vol_req;
238
239 /* driver callback */
240 u32 (*notify_position)(struct sst_hsw_stream *stream, void *data);
241 void *pdata;
242
243 struct list_head node;
244};
245
246/* FW log ring information */
247struct sst_hsw_log_stream {
248 dma_addr_t dma_addr;
249 unsigned char *dma_area;
250 unsigned char *ring_descr;
251 int pages;
252 int size;
253
254 /* Notification work */
255 struct work_struct notify_work;
256 wait_queue_head_t readers_wait_q;
257 struct mutex rw_mutex;
258
259 u32 last_pos;
260 u32 curr_pos;
261 u32 reader_pos;
262
263 /* fw log config */
264 u32 config[SST_HSW_FW_LOG_CONFIG_DWORDS];
265
266 struct sst_hsw *hsw;
267};
268
269/* SST Haswell IPC data */
270struct sst_hsw {
271 struct device *dev;
272 struct sst_dsp *dsp;
273 struct platform_device *pdev_pcm;
274
275 /* FW config */
276 struct sst_hsw_ipc_fw_ready fw_ready;
277 struct sst_hsw_ipc_fw_version version;
278 struct sst_module *scratch;
279 bool fw_done;
280
281 /* stream */
282 struct list_head stream_list;
283
284 /* global mixer */
285 struct sst_hsw_ipc_stream_info_reply mixer_info;
286 enum sst_hsw_volume_curve curve_type;
287 u32 curve_duration;
288 u32 mute[SST_HSW_NO_CHANNELS];
289 u32 mute_volume[SST_HSW_NO_CHANNELS];
290
291 /* DX */
292 struct sst_hsw_ipc_dx_reply dx;
293
294 /* boot */
295 wait_queue_head_t boot_wait;
296 bool boot_complete;
297 bool shutdown;
298
299 /* IPC messaging */
300 struct list_head tx_list;
301 struct list_head rx_list;
302 struct list_head empty_list;
303 wait_queue_head_t wait_txq;
304 struct task_struct *tx_thread;
305 struct kthread_worker kworker;
306 struct kthread_work kwork;
307 bool pending;
308 struct ipc_message *msg;
309
310 /* FW log stream */
311 struct sst_hsw_log_stream log_stream;
312};
313
314#define CREATE_TRACE_POINTS
315#include <trace/events/hswadsp.h>
316
317static inline u32 msg_get_global_type(u32 msg)
318{
319 return (msg & IPC_GLB_TYPE_MASK) >> IPC_GLB_TYPE_SHIFT;
320}
321
322static inline u32 msg_get_global_reply(u32 msg)
323{
324 return (msg & IPC_GLB_REPLY_MASK) >> IPC_GLB_REPLY_SHIFT;
325}
326
327static inline u32 msg_get_stream_type(u32 msg)
328{
329 return (msg & IPC_STR_TYPE_MASK) >> IPC_STR_TYPE_SHIFT;
330}
331
332static inline u32 msg_get_stage_type(u32 msg)
333{
334 return (msg & IPC_STG_TYPE_MASK) >> IPC_STG_TYPE_SHIFT;
335}
336
337static inline u32 msg_set_stage_type(u32 msg, u32 type)
338{
339 return (msg & ~IPC_STG_TYPE_MASK) +
340 (type << IPC_STG_TYPE_SHIFT);
341}
342
343static inline u32 msg_get_stream_id(u32 msg)
344{
345 return (msg & IPC_STR_ID_MASK) >> IPC_STR_ID_SHIFT;
346}
347
348static inline u32 msg_get_notify_reason(u32 msg)
349{
350 return (msg & IPC_STG_TYPE_MASK) >> IPC_STG_TYPE_SHIFT;
351}
352
353u32 create_channel_map(enum sst_hsw_channel_config config)
354{
355 switch (config) {
356 case SST_HSW_CHANNEL_CONFIG_MONO:
357 return (0xFFFFFFF0 | SST_HSW_CHANNEL_CENTER);
358 case SST_HSW_CHANNEL_CONFIG_STEREO:
359 return (0xFFFFFF00 | SST_HSW_CHANNEL_LEFT
360 | (SST_HSW_CHANNEL_RIGHT << 4));
361 case SST_HSW_CHANNEL_CONFIG_2_POINT_1:
362 return (0xFFFFF000 | SST_HSW_CHANNEL_LEFT
363 | (SST_HSW_CHANNEL_RIGHT << 4)
364 | (SST_HSW_CHANNEL_LFE << 8 ));
365 case SST_HSW_CHANNEL_CONFIG_3_POINT_0:
366 return (0xFFFFF000 | SST_HSW_CHANNEL_LEFT
367 | (SST_HSW_CHANNEL_CENTER << 4)
368 | (SST_HSW_CHANNEL_RIGHT << 8));
369 case SST_HSW_CHANNEL_CONFIG_3_POINT_1:
370 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
371 | (SST_HSW_CHANNEL_CENTER << 4)
372 | (SST_HSW_CHANNEL_RIGHT << 8)
373 | (SST_HSW_CHANNEL_LFE << 12));
374 case SST_HSW_CHANNEL_CONFIG_QUATRO:
375 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
376 | (SST_HSW_CHANNEL_RIGHT << 4)
377 | (SST_HSW_CHANNEL_LEFT_SURROUND << 8)
378 | (SST_HSW_CHANNEL_RIGHT_SURROUND << 12));
379 case SST_HSW_CHANNEL_CONFIG_4_POINT_0:
380 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
381 | (SST_HSW_CHANNEL_CENTER << 4)
382 | (SST_HSW_CHANNEL_RIGHT << 8)
383 | (SST_HSW_CHANNEL_CENTER_SURROUND << 12));
384 case SST_HSW_CHANNEL_CONFIG_5_POINT_0:
385 return (0xFFF00000 | SST_HSW_CHANNEL_LEFT
386 | (SST_HSW_CHANNEL_CENTER << 4)
387 | (SST_HSW_CHANNEL_RIGHT << 8)
388 | (SST_HSW_CHANNEL_LEFT_SURROUND << 12)
389 | (SST_HSW_CHANNEL_RIGHT_SURROUND << 16));
390 case SST_HSW_CHANNEL_CONFIG_5_POINT_1:
391 return (0xFF000000 | SST_HSW_CHANNEL_CENTER
392 | (SST_HSW_CHANNEL_LEFT << 4)
393 | (SST_HSW_CHANNEL_RIGHT << 8)
394 | (SST_HSW_CHANNEL_LEFT_SURROUND << 12)
395 | (SST_HSW_CHANNEL_RIGHT_SURROUND << 16)
396 | (SST_HSW_CHANNEL_LFE << 20));
397 case SST_HSW_CHANNEL_CONFIG_DUAL_MONO:
398 return (0xFFFFFF00 | SST_HSW_CHANNEL_LEFT
399 | (SST_HSW_CHANNEL_LEFT << 4));
400 default:
401 return 0xFFFFFFFF;
402 }
403}
404
405static struct sst_hsw_stream *get_stream_by_id(struct sst_hsw *hsw,
406 int stream_id)
407{
408 struct sst_hsw_stream *stream;
409
410 list_for_each_entry(stream, &hsw->stream_list, node) {
411 if (stream->reply.stream_hw_id == stream_id)
412 return stream;
413 }
414
415 return NULL;
416}
417
418static void ipc_shim_dbg(struct sst_hsw *hsw, const char *text)
419{
420 struct sst_dsp *sst = hsw->dsp;
421 u32 isr, ipcd, imrx, ipcx;
422
423 ipcx = sst_dsp_shim_read_unlocked(sst, SST_IPCX);
424 isr = sst_dsp_shim_read_unlocked(sst, SST_ISRX);
425 ipcd = sst_dsp_shim_read_unlocked(sst, SST_IPCD);
426 imrx = sst_dsp_shim_read_unlocked(sst, SST_IMRX);
427
428 dev_err(hsw->dev, "ipc: --%s-- ipcx 0x%8.8x isr 0x%8.8x ipcd 0x%8.8x imrx 0x%8.8x\n",
429 text, ipcx, isr, ipcd, imrx);
430}
431
432/* locks held by caller */
433static struct ipc_message *msg_get_empty(struct sst_hsw *hsw)
434{
435 struct ipc_message *msg = NULL;
436
437 if (!list_empty(&hsw->empty_list)) {
438 msg = list_first_entry(&hsw->empty_list, struct ipc_message,
439 list);
440 list_del(&msg->list);
441 }
442
443 return msg;
444}
445
446static void ipc_tx_msgs(struct kthread_work *work)
447{
448 struct sst_hsw *hsw =
449 container_of(work, struct sst_hsw, kwork);
450 struct ipc_message *msg;
451 unsigned long flags;
452 u32 ipcx;
453
454 spin_lock_irqsave(&hsw->dsp->spinlock, flags);
455
456 if (list_empty(&hsw->tx_list) || hsw->pending) {
457 spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
458 return;
459 }
460
461 /* if the DSP is busy we will TX messages after IRQ */
462 ipcx = sst_dsp_shim_read_unlocked(hsw->dsp, SST_IPCX);
463 if (ipcx & SST_IPCX_BUSY) {
464 spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
465 return;
466 }
467
468 msg = list_first_entry(&hsw->tx_list, struct ipc_message, list);
469
470 list_move(&msg->list, &hsw->rx_list);
471
472 /* send the message */
473 sst_dsp_outbox_write(hsw->dsp, msg->tx_data, msg->tx_size);
474 sst_dsp_ipc_msg_tx(hsw->dsp, msg->header | SST_IPCX_BUSY);
475
476 spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
477}
478
479/* locks held by caller */
480static void tx_msg_reply_complete(struct sst_hsw *hsw, struct ipc_message *msg)
481{
482 msg->complete = true;
483 trace_ipc_reply("completed", msg->header);
484
485 if (!msg->wait)
486 list_add_tail(&msg->list, &hsw->empty_list);
487 else
488 wake_up(&msg->waitq);
489}
490
491static int tx_wait_done(struct sst_hsw *hsw, struct ipc_message *msg,
492 void *rx_data)
493{
494 unsigned long flags;
495 int ret;
496
497 /* wait for DSP completion (in all cases atm inc pending) */
498 ret = wait_event_timeout(msg->waitq, msg->complete,
499 msecs_to_jiffies(IPC_TIMEOUT_MSECS));
500
501 spin_lock_irqsave(&hsw->dsp->spinlock, flags);
502 if (ret == 0) {
503 ipc_shim_dbg(hsw, "message timeout");
504
505 trace_ipc_error("error message timeout for", msg->header);
506 ret = -ETIMEDOUT;
507 } else {
508
509 /* copy the data returned from DSP */
510 if (msg->rx_size)
511 memcpy(rx_data, msg->rx_data, msg->rx_size);
512 ret = msg->errno;
513 }
514
515 list_add_tail(&msg->list, &hsw->empty_list);
516 spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
517 return ret;
518}
519
520static int ipc_tx_message(struct sst_hsw *hsw, u32 header, void *tx_data,
521 size_t tx_bytes, void *rx_data, size_t rx_bytes, int wait)
522{
523 struct ipc_message *msg;
524 unsigned long flags;
525
526 spin_lock_irqsave(&hsw->dsp->spinlock, flags);
527
528 msg = msg_get_empty(hsw);
529 if (msg == NULL) {
530 spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
531 return -EBUSY;
532 }
533
534 if (tx_bytes)
535 memcpy(msg->tx_data, tx_data, tx_bytes);
536
537 msg->header = header;
538 msg->tx_size = tx_bytes;
539 msg->rx_size = rx_bytes;
540 msg->wait = wait;
541 msg->errno = 0;
542 msg->pending = false;
543 msg->complete = false;
544
545 list_add_tail(&msg->list, &hsw->tx_list);
546 spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
547
548 queue_kthread_work(&hsw->kworker, &hsw->kwork);
549
550 if (wait)
551 return tx_wait_done(hsw, msg, rx_data);
552 else
553 return 0;
554}
555
556static inline int ipc_tx_message_wait(struct sst_hsw *hsw, u32 header,
557 void *tx_data, size_t tx_bytes, void *rx_data, size_t rx_bytes)
558{
559 return ipc_tx_message(hsw, header, tx_data, tx_bytes, rx_data,
560 rx_bytes, 1);
561}
562
563static inline int ipc_tx_message_nowait(struct sst_hsw *hsw, u32 header,
564 void *tx_data, size_t tx_bytes)
565{
566 return ipc_tx_message(hsw, header, tx_data, tx_bytes, NULL, 0, 0);
567}
568
569static void hsw_fw_ready(struct sst_hsw *hsw, u32 header)
570{
571 struct sst_hsw_ipc_fw_ready fw_ready;
572 u32 offset;
573
574 offset = (header & 0x1FFFFFFF) << 3;
575
576 dev_dbg(hsw->dev, "ipc: DSP is ready 0x%8.8x offset %d\n",
577 header, offset);
578
579 /* copy data from the DSP FW ready offset */
580 sst_dsp_read(hsw->dsp, &fw_ready, offset, sizeof(fw_ready));
581
582 sst_dsp_mailbox_init(hsw->dsp, fw_ready.inbox_offset,
583 fw_ready.inbox_size, fw_ready.outbox_offset,
584 fw_ready.outbox_size);
585
586 hsw->boot_complete = true;
587 wake_up(&hsw->boot_wait);
588
589 dev_dbg(hsw->dev, " mailbox upstream 0x%x - size 0x%x\n",
590 fw_ready.inbox_offset, fw_ready.inbox_size);
591 dev_dbg(hsw->dev, " mailbox downstream 0x%x - size 0x%x\n",
592 fw_ready.outbox_offset, fw_ready.outbox_size);
593}
594
595static void hsw_notification_work(struct work_struct *work)
596{
597 struct sst_hsw_stream *stream = container_of(work,
598 struct sst_hsw_stream, notify_work);
599 struct sst_hsw_ipc_stream_glitch_position *glitch = &stream->glitch;
600 struct sst_hsw_ipc_stream_get_position *pos = &stream->rpos;
601 struct sst_hsw *hsw = stream->hsw;
602 u32 reason;
603
604 reason = msg_get_notify_reason(stream->header);
605
606 switch (reason) {
607 case IPC_STG_GLITCH:
608 trace_ipc_notification("DSP stream under/overrun",
609 stream->reply.stream_hw_id);
610 sst_dsp_inbox_read(hsw->dsp, glitch, sizeof(*glitch));
611
612 dev_err(hsw->dev, "glitch %d pos 0x%x write pos 0x%x\n",
613 glitch->glitch_type, glitch->present_pos,
614 glitch->write_pos);
615 break;
616
617 case IPC_POSITION_CHANGED:
618 trace_ipc_notification("DSP stream position changed for",
619 stream->reply.stream_hw_id);
620 sst_dsp_inbox_read(hsw->dsp, pos, sizeof(pos));
621
622 if (stream->notify_position)
623 stream->notify_position(stream, stream->pdata);
624
625 break;
626 default:
627 dev_err(hsw->dev, "error: unknown notification 0x%x\n",
628 stream->header);
629 break;
630 }
631
632 /* tell DSP that notification has been handled */
633 sst_dsp_shim_update_bits_unlocked(hsw->dsp, SST_IPCD,
634 SST_IPCD_BUSY | SST_IPCD_DONE, SST_IPCD_DONE);
635
636 /* unmask busy interrupt */
637 sst_dsp_shim_update_bits_unlocked(hsw->dsp, SST_IMRX, SST_IMRX_BUSY, 0);
638}
639
640static struct ipc_message *reply_find_msg(struct sst_hsw *hsw, u32 header)
641{
642 struct ipc_message *msg;
643
644 /* clear reply bits & status bits */
645 header &= ~(IPC_STATUS_MASK | IPC_GLB_REPLY_MASK);
646
647 if (list_empty(&hsw->rx_list)) {
648 dev_err(hsw->dev, "error: rx list empty but received 0x%x\n",
649 header);
650 return NULL;
651 }
652
653 list_for_each_entry(msg, &hsw->rx_list, list) {
654 if (msg->header == header)
655 return msg;
656 }
657
658 return NULL;
659}
660
661static void hsw_stream_update(struct sst_hsw *hsw, struct ipc_message *msg)
662{
663 struct sst_hsw_stream *stream;
664 u32 header = msg->header & ~(IPC_STATUS_MASK | IPC_GLB_REPLY_MASK);
665 u32 stream_id = msg_get_stream_id(header);
666 u32 stream_msg = msg_get_stream_type(header);
667
668 stream = get_stream_by_id(hsw, stream_id);
669 if (stream == NULL)
670 return;
671
672 switch (stream_msg) {
673 case IPC_STR_STAGE_MESSAGE:
674 case IPC_STR_NOTIFICATION:
675 case IPC_STR_RESET:
676 break;
677 case IPC_STR_PAUSE:
678 stream->running = false;
679 trace_ipc_notification("stream paused",
680 stream->reply.stream_hw_id);
681 break;
682 case IPC_STR_RESUME:
683 stream->running = true;
684 trace_ipc_notification("stream running",
685 stream->reply.stream_hw_id);
686 break;
687 }
688}
689
690static int hsw_process_reply(struct sst_hsw *hsw, u32 header)
691{
692 struct ipc_message *msg;
693 u32 reply = msg_get_global_reply(header);
694
695 trace_ipc_reply("processing -->", header);
696
697 msg = reply_find_msg(hsw, header);
698 if (msg == NULL) {
699 trace_ipc_error("error: can't find message header", header);
700 return -EIO;
701 }
702
703 /* first process the header */
704 switch (reply) {
705 case IPC_GLB_REPLY_PENDING:
706 trace_ipc_pending_reply("received", header);
707 msg->pending = true;
708 hsw->pending = true;
709 return 1;
710 case IPC_GLB_REPLY_SUCCESS:
711 if (msg->pending) {
712 trace_ipc_pending_reply("completed", header);
713 sst_dsp_inbox_read(hsw->dsp, msg->rx_data,
714 msg->rx_size);
715 hsw->pending = false;
716 } else {
717 /* copy data from the DSP */
718 sst_dsp_outbox_read(hsw->dsp, msg->rx_data,
719 msg->rx_size);
720 }
721 break;
722 /* these will be rare - but useful for debug */
723 case IPC_GLB_REPLY_UNKNOWN_MESSAGE_TYPE:
724 trace_ipc_error("error: unknown message type", header);
725 msg->errno = -EBADMSG;
726 break;
727 case IPC_GLB_REPLY_OUT_OF_RESOURCES:
728 trace_ipc_error("error: out of resources", header);
729 msg->errno = -ENOMEM;
730 break;
731 case IPC_GLB_REPLY_BUSY:
732 trace_ipc_error("error: reply busy", header);
733 msg->errno = -EBUSY;
734 break;
735 case IPC_GLB_REPLY_FAILURE:
736 trace_ipc_error("error: reply failure", header);
737 msg->errno = -EINVAL;
738 break;
739 case IPC_GLB_REPLY_STAGE_UNINITIALIZED:
740 trace_ipc_error("error: stage uninitialized", header);
741 msg->errno = -EINVAL;
742 break;
743 case IPC_GLB_REPLY_NOT_FOUND:
744 trace_ipc_error("error: reply not found", header);
745 msg->errno = -EINVAL;
746 break;
747 case IPC_GLB_REPLY_SOURCE_NOT_STARTED:
748 trace_ipc_error("error: source not started", header);
749 msg->errno = -EINVAL;
750 break;
751 case IPC_GLB_REPLY_INVALID_REQUEST:
752 trace_ipc_error("error: invalid request", header);
753 msg->errno = -EINVAL;
754 break;
755 case IPC_GLB_REPLY_ERROR_INVALID_PARAM:
756 trace_ipc_error("error: invalid parameter", header);
757 msg->errno = -EINVAL;
758 break;
759 default:
760 trace_ipc_error("error: unknown reply", header);
761 msg->errno = -EINVAL;
762 break;
763 }
764
765 /* update any stream states */
766 hsw_stream_update(hsw, msg);
767
768 /* wake up and return the error if we have waiters on this message ? */
769 list_del(&msg->list);
770 tx_msg_reply_complete(hsw, msg);
771
772 return 1;
773}
774
775static int hsw_stream_message(struct sst_hsw *hsw, u32 header)
776{
777 u32 stream_msg, stream_id, stage_type;
778 struct sst_hsw_stream *stream;
779 int handled = 0;
780
781 stream_msg = msg_get_stream_type(header);
782 stream_id = msg_get_stream_id(header);
783 stage_type = msg_get_stage_type(header);
784
785 stream = get_stream_by_id(hsw, stream_id);
786 if (stream == NULL)
787 return handled;
788
789 stream->header = header;
790
791 switch (stream_msg) {
792 case IPC_STR_STAGE_MESSAGE:
793 dev_err(hsw->dev, "error: stage msg not implemented 0x%8.8x\n",
794 header);
795 break;
796 case IPC_STR_NOTIFICATION:
797 schedule_work(&stream->notify_work);
798 break;
799 default:
800 /* handle pending message complete request */
801 handled = hsw_process_reply(hsw, header);
802 break;
803 }
804
805 return handled;
806}
807
808static int hsw_log_message(struct sst_hsw *hsw, u32 header)
809{
810 u32 operation = (header & IPC_LOG_OP_MASK) >> IPC_LOG_OP_SHIFT;
811 struct sst_hsw_log_stream *stream = &hsw->log_stream;
812 int ret = 1;
813
814 if (operation != IPC_DEBUG_REQUEST_LOG_DUMP) {
815 dev_err(hsw->dev,
816 "error: log msg not implemented 0x%8.8x\n", header);
817 return 0;
818 }
819
820 mutex_lock(&stream->rw_mutex);
821 stream->last_pos = stream->curr_pos;
822 sst_dsp_inbox_read(
823 hsw->dsp, &stream->curr_pos, sizeof(stream->curr_pos));
824 mutex_unlock(&stream->rw_mutex);
825
826 schedule_work(&stream->notify_work);
827
828 return ret;
829}
830
831static int hsw_process_notification(struct sst_hsw *hsw)
832{
833 struct sst_dsp *sst = hsw->dsp;
834 u32 type, header;
835 int handled = 1;
836
837 header = sst_dsp_shim_read_unlocked(sst, SST_IPCD);
838 type = msg_get_global_type(header);
839
840 trace_ipc_request("processing -->", header);
841
842 /* FW Ready is a special case */
843 if (!hsw->boot_complete && header & IPC_FW_READY) {
844 hsw_fw_ready(hsw, header);
845 return handled;
846 }
847
848 switch (type) {
849 case IPC_GLB_GET_FW_VERSION:
850 case IPC_GLB_ALLOCATE_STREAM:
851 case IPC_GLB_FREE_STREAM:
852 case IPC_GLB_GET_FW_CAPABILITIES:
853 case IPC_GLB_REQUEST_DUMP:
854 case IPC_GLB_GET_DEVICE_FORMATS:
855 case IPC_GLB_SET_DEVICE_FORMATS:
856 case IPC_GLB_ENTER_DX_STATE:
857 case IPC_GLB_GET_MIXER_STREAM_INFO:
858 case IPC_GLB_MAX_IPC_MESSAGE_TYPE:
859 case IPC_GLB_RESTORE_CONTEXT:
860 case IPC_GLB_SHORT_REPLY:
861 dev_err(hsw->dev, "error: message type %d header 0x%x\n",
862 type, header);
863 break;
864 case IPC_GLB_STREAM_MESSAGE:
865 handled = hsw_stream_message(hsw, header);
866 break;
867 case IPC_GLB_DEBUG_LOG_MESSAGE:
868 handled = hsw_log_message(hsw, header);
869 break;
870 default:
871 dev_err(hsw->dev, "error: unexpected type %d hdr 0x%8.8x\n",
872 type, header);
873 break;
874 }
875
876 return handled;
877}
878
879static irqreturn_t hsw_irq_thread(int irq, void *context)
880{
881 struct sst_dsp *sst = (struct sst_dsp *) context;
882 struct sst_hsw *hsw = sst_dsp_get_thread_context(sst);
883 u32 ipcx, ipcd;
884 int handled;
885 unsigned long flags;
886
887 spin_lock_irqsave(&sst->spinlock, flags);
888
889 ipcx = sst_dsp_ipc_msg_rx(hsw->dsp);
890 ipcd = sst_dsp_shim_read_unlocked(sst, SST_IPCD);
891
892 /* reply message from DSP */
893 if (ipcx & SST_IPCX_DONE) {
894
895 /* Handle Immediate reply from DSP Core */
896 handled = hsw_process_reply(hsw, ipcx);
897
898 if (handled > 0) {
899 /* clear DONE bit - tell DSP we have completed */
900 sst_dsp_shim_update_bits_unlocked(sst, SST_IPCX,
901 SST_IPCX_DONE, 0);
902
903 /* unmask Done interrupt */
904 sst_dsp_shim_update_bits_unlocked(sst, SST_IMRX,
905 SST_IMRX_DONE, 0);
906 }
907 }
908
909 /* new message from DSP */
910 if (ipcd & SST_IPCD_BUSY) {
911
912 /* Handle Notification and Delayed reply from DSP Core */
913 handled = hsw_process_notification(hsw);
914
915 /* clear BUSY bit and set DONE bit - accept new messages */
916 if (handled > 0) {
917 sst_dsp_shim_update_bits_unlocked(sst, SST_IPCD,
918 SST_IPCD_BUSY | SST_IPCD_DONE, SST_IPCD_DONE);
919
920 /* unmask busy interrupt */
921 sst_dsp_shim_update_bits_unlocked(sst, SST_IMRX,
922 SST_IMRX_BUSY, 0);
923 }
924 }
925
926 spin_unlock_irqrestore(&sst->spinlock, flags);
927
928 /* continue to send any remaining messages... */
929 queue_kthread_work(&hsw->kworker, &hsw->kwork);
930
931 return IRQ_HANDLED;
932}
933
934int sst_hsw_fw_get_version(struct sst_hsw *hsw,
935 struct sst_hsw_ipc_fw_version *version)
936{
937 int ret;
938
939 ret = ipc_tx_message_wait(hsw, IPC_GLB_TYPE(IPC_GLB_GET_FW_VERSION),
940 NULL, 0, version, sizeof(*version));
941 if (ret < 0)
942 dev_err(hsw->dev, "error: get version failed\n");
943
944 return ret;
945}
946
947/* Mixer Controls */
948int sst_hsw_stream_mute(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
949 u32 stage_id, u32 channel)
950{
951 int ret;
952
953 ret = sst_hsw_stream_get_volume(hsw, stream, stage_id, channel,
954 &stream->mute_volume[channel]);
955 if (ret < 0)
956 return ret;
957
958 ret = sst_hsw_stream_set_volume(hsw, stream, stage_id, channel, 0);
959 if (ret < 0) {
960 dev_err(hsw->dev, "error: can't unmute stream %d channel %d\n",
961 stream->reply.stream_hw_id, channel);
962 return ret;
963 }
964
965 stream->mute[channel] = 1;
966 return 0;
967}
968
969int sst_hsw_stream_unmute(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
970 u32 stage_id, u32 channel)
971
972{
973 int ret;
974
975 stream->mute[channel] = 0;
976 ret = sst_hsw_stream_set_volume(hsw, stream, stage_id, channel,
977 stream->mute_volume[channel]);
978 if (ret < 0) {
979 dev_err(hsw->dev, "error: can't unmute stream %d channel %d\n",
980 stream->reply.stream_hw_id, channel);
981 return ret;
982 }
983
984 return 0;
985}
986
987int sst_hsw_stream_get_volume(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
988 u32 stage_id, u32 channel, u32 *volume)
989{
990 if (channel > 1)
991 return -EINVAL;
992
993 sst_dsp_read(hsw->dsp, volume,
994 stream->reply.volume_register_address[channel], sizeof(volume));
995
996 return 0;
997}
998
999int sst_hsw_stream_set_volume_curve(struct sst_hsw *hsw,
1000 struct sst_hsw_stream *stream, u64 curve_duration,
1001 enum sst_hsw_volume_curve curve)
1002{
1003 /* curve duration in steps of 100ns */
1004 stream->vol_req.curve_duration = curve_duration;
1005 stream->vol_req.curve_type = curve;
1006
1007 return 0;
1008}
1009
1010/* stream volume */
1011int sst_hsw_stream_set_volume(struct sst_hsw *hsw,
1012 struct sst_hsw_stream *stream, u32 stage_id, u32 channel, u32 volume)
1013{
1014 struct sst_hsw_ipc_volume_req *req;
1015 u32 header;
1016 int ret;
1017
1018 trace_ipc_request("set stream volume", stream->reply.stream_hw_id);
1019
1020 if (channel > 1)
1021 return -EINVAL;
1022
1023 if (stream->mute[channel]) {
1024 stream->mute_volume[channel] = volume;
1025 return 0;
1026 }
1027
1028 header = IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE) |
1029 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE);
1030 header |= (stream->reply.stream_hw_id << IPC_STR_ID_SHIFT);
1031 header |= (IPC_STG_SET_VOLUME << IPC_STG_TYPE_SHIFT);
1032 header |= (stage_id << IPC_STG_ID_SHIFT);
1033
1034 req = &stream->vol_req;
1035 req->channel = channel;
1036 req->target_volume = volume;
1037
1038 ret = ipc_tx_message_wait(hsw, header, req, sizeof(*req), NULL, 0);
1039 if (ret < 0) {
1040 dev_err(hsw->dev, "error: set stream volume failed\n");
1041 return ret;
1042 }
1043
1044 return 0;
1045}
1046
1047int sst_hsw_mixer_mute(struct sst_hsw *hsw, u32 stage_id, u32 channel)
1048{
1049 int ret;
1050
1051 ret = sst_hsw_mixer_get_volume(hsw, stage_id, channel,
1052 &hsw->mute_volume[channel]);
1053 if (ret < 0)
1054 return ret;
1055
1056 ret = sst_hsw_mixer_set_volume(hsw, stage_id, channel, 0);
1057 if (ret < 0) {
1058 dev_err(hsw->dev, "error: failed to unmute mixer channel %d\n",
1059 channel);
1060 return ret;
1061 }
1062
1063 hsw->mute[channel] = 1;
1064 return 0;
1065}
1066
1067int sst_hsw_mixer_unmute(struct sst_hsw *hsw, u32 stage_id, u32 channel)
1068{
1069 int ret;
1070
1071 ret = sst_hsw_mixer_set_volume(hsw, stage_id, channel,
1072 hsw->mixer_info.volume_register_address[channel]);
1073 if (ret < 0) {
1074 dev_err(hsw->dev, "error: failed to unmute mixer channel %d\n",
1075 channel);
1076 return ret;
1077 }
1078
1079 hsw->mute[channel] = 0;
1080 return 0;
1081}
1082
1083int sst_hsw_mixer_get_volume(struct sst_hsw *hsw, u32 stage_id, u32 channel,
1084 u32 *volume)
1085{
1086 if (channel > 1)
1087 return -EINVAL;
1088
1089 sst_dsp_read(hsw->dsp, volume,
1090 hsw->mixer_info.volume_register_address[channel],
1091 sizeof(*volume));
1092
1093 return 0;
1094}
1095
1096int sst_hsw_mixer_set_volume_curve(struct sst_hsw *hsw,
1097 u64 curve_duration, enum sst_hsw_volume_curve curve)
1098{
1099 /* curve duration in steps of 100ns */
1100 hsw->curve_duration = curve_duration;
1101 hsw->curve_type = curve;
1102
1103 return 0;
1104}
1105
1106/* global mixer volume */
1107int sst_hsw_mixer_set_volume(struct sst_hsw *hsw, u32 stage_id, u32 channel,
1108 u32 volume)
1109{
1110 struct sst_hsw_ipc_volume_req req;
1111 u32 header;
1112 int ret;
1113
1114 trace_ipc_request("set mixer volume", volume);
1115
1116 /* set both at same time ? */
1117 if (channel == 2) {
1118 if (hsw->mute[0] && hsw->mute[1]) {
1119 hsw->mute_volume[0] = hsw->mute_volume[1] = volume;
1120 return 0;
1121 } else if (hsw->mute[0])
1122 req.channel = 1;
1123 else if (hsw->mute[1])
1124 req.channel = 0;
1125 else
1126 req.channel = 0xffffffff;
1127 } else {
1128 /* set only 1 channel */
1129 if (hsw->mute[channel]) {
1130 hsw->mute_volume[channel] = volume;
1131 return 0;
1132 }
1133 req.channel = channel;
1134 }
1135
1136 header = IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE) |
1137 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE);
1138 header |= (hsw->mixer_info.mixer_hw_id << IPC_STR_ID_SHIFT);
1139 header |= (IPC_STG_SET_VOLUME << IPC_STG_TYPE_SHIFT);
1140 header |= (stage_id << IPC_STG_ID_SHIFT);
1141
1142 req.curve_duration = hsw->curve_duration;
1143 req.curve_type = hsw->curve_type;
1144 req.target_volume = volume;
1145
1146 ret = ipc_tx_message_wait(hsw, header, &req, sizeof(req), NULL, 0);
1147 if (ret < 0) {
1148 dev_err(hsw->dev, "error: set mixer volume failed\n");
1149 return ret;
1150 }
1151
1152 return 0;
1153}
1154
1155/* Stream API */
1156struct sst_hsw_stream *sst_hsw_stream_new(struct sst_hsw *hsw, int id,
1157 u32 (*notify_position)(struct sst_hsw_stream *stream, void *data),
1158 void *data)
1159{
1160 struct sst_hsw_stream *stream;
1161
1162 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
1163 if (stream == NULL)
1164 return NULL;
1165
1166 list_add(&stream->node, &hsw->stream_list);
1167 stream->notify_position = notify_position;
1168 stream->pdata = data;
1169 stream->hsw = hsw;
1170 stream->host_id = id;
1171
1172 /* work to process notification messages */
1173 INIT_WORK(&stream->notify_work, hsw_notification_work);
1174
1175 return stream;
1176}
1177
1178int sst_hsw_stream_free(struct sst_hsw *hsw, struct sst_hsw_stream *stream)
1179{
1180 u32 header;
1181 int ret = 0;
1182
1183 /* dont free DSP streams that are not commited */
1184 if (!stream->commited)
1185 goto out;
1186
1187 trace_ipc_request("stream free", stream->host_id);
1188
1189 stream->free_req.stream_id = stream->reply.stream_hw_id;
1190 header = IPC_GLB_TYPE(IPC_GLB_FREE_STREAM);
1191
1192 ret = ipc_tx_message_wait(hsw, header, &stream->free_req,
1193 sizeof(stream->free_req), NULL, 0);
1194 if (ret < 0) {
1195 dev_err(hsw->dev, "error: free stream %d failed\n",
1196 stream->free_req.stream_id);
1197 return -EAGAIN;
1198 }
1199
1200 trace_hsw_stream_free_req(stream, &stream->free_req);
1201
1202out:
1203 list_del(&stream->node);
1204 kfree(stream);
1205
1206 return ret;
1207}
1208
1209int sst_hsw_stream_set_bits(struct sst_hsw *hsw,
1210 struct sst_hsw_stream *stream, enum sst_hsw_bitdepth bits)
1211{
1212 if (stream->commited) {
1213 dev_err(hsw->dev, "error: stream committed for set bits\n");
1214 return -EINVAL;
1215 }
1216
1217 stream->request.format.bitdepth = bits;
1218 return 0;
1219}
1220
1221int sst_hsw_stream_set_channels(struct sst_hsw *hsw,
1222 struct sst_hsw_stream *stream, int channels)
1223{
1224 if (stream->commited) {
1225 dev_err(hsw->dev, "error: stream committed for set channels\n");
1226 return -EINVAL;
1227 }
1228
1229 /* stereo is only supported atm */
1230 if (channels != 2)
1231 return -EINVAL;
1232
1233 stream->request.format.ch_num = channels;
1234 return 0;
1235}
1236
1237int sst_hsw_stream_set_rate(struct sst_hsw *hsw,
1238 struct sst_hsw_stream *stream, int rate)
1239{
1240 if (stream->commited) {
1241 dev_err(hsw->dev, "error: stream committed for set rate\n");
1242 return -EINVAL;
1243 }
1244
1245 stream->request.format.frequency = rate;
1246 return 0;
1247}
1248
1249int sst_hsw_stream_set_map_config(struct sst_hsw *hsw,
1250 struct sst_hsw_stream *stream, u32 map,
1251 enum sst_hsw_channel_config config)
1252{
1253 if (stream->commited) {
1254 dev_err(hsw->dev, "error: stream committed for set map\n");
1255 return -EINVAL;
1256 }
1257
1258 stream->request.format.map = map;
1259 stream->request.format.config = config;
1260 return 0;
1261}
1262
1263int sst_hsw_stream_set_style(struct sst_hsw *hsw,
1264 struct sst_hsw_stream *stream, enum sst_hsw_interleaving style)
1265{
1266 if (stream->commited) {
1267 dev_err(hsw->dev, "error: stream committed for set style\n");
1268 return -EINVAL;
1269 }
1270
1271 stream->request.format.style = style;
1272 return 0;
1273}
1274
1275int sst_hsw_stream_set_valid(struct sst_hsw *hsw,
1276 struct sst_hsw_stream *stream, u32 bits)
1277{
1278 if (stream->commited) {
1279 dev_err(hsw->dev, "error: stream committed for set valid bits\n");
1280 return -EINVAL;
1281 }
1282
1283 stream->request.format.valid_bit = bits;
1284 return 0;
1285}
1286
1287/* Stream Configuration */
1288int sst_hsw_stream_format(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
1289 enum sst_hsw_stream_path_id path_id,
1290 enum sst_hsw_stream_type stream_type,
1291 enum sst_hsw_stream_format format_id)
1292{
1293 if (stream->commited) {
1294 dev_err(hsw->dev, "error: stream committed for set format\n");
1295 return -EINVAL;
1296 }
1297
1298 stream->request.path_id = path_id;
1299 stream->request.stream_type = stream_type;
1300 stream->request.format_id = format_id;
1301
1302 trace_hsw_stream_alloc_request(stream, &stream->request);
1303
1304 return 0;
1305}
1306
1307int sst_hsw_stream_buffer(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
1308 u32 ring_pt_address, u32 num_pages,
1309 u32 ring_size, u32 ring_offset, u32 ring_first_pfn)
1310{
1311 if (stream->commited) {
1312 dev_err(hsw->dev, "error: stream committed for buffer\n");
1313 return -EINVAL;
1314 }
1315
1316 stream->request.ringinfo.ring_pt_address = ring_pt_address;
1317 stream->request.ringinfo.num_pages = num_pages;
1318 stream->request.ringinfo.ring_size = ring_size;
1319 stream->request.ringinfo.ring_offset = ring_offset;
1320 stream->request.ringinfo.ring_first_pfn = ring_first_pfn;
1321
1322 trace_hsw_stream_buffer(stream);
1323
1324 return 0;
1325}
1326
1327int sst_hsw_stream_set_module_info(struct sst_hsw *hsw,
1328 struct sst_hsw_stream *stream, enum sst_hsw_module_id module_id,
1329 u32 entry_point)
1330{
1331 struct sst_hsw_module_map *map = &stream->request.map;
1332
1333 if (stream->commited) {
1334 dev_err(hsw->dev, "error: stream committed for set module\n");
1335 return -EINVAL;
1336 }
1337
1338 /* only support initial module atm */
1339 map->module_entries_count = 1;
1340 map->module_entries[0].module_id = module_id;
1341 map->module_entries[0].entry_point = entry_point;
1342
1343 return 0;
1344}
1345
1346int sst_hsw_stream_set_pmemory_info(struct sst_hsw *hsw,
1347 struct sst_hsw_stream *stream, u32 offset, u32 size)
1348{
1349 if (stream->commited) {
1350 dev_err(hsw->dev, "error: stream committed for set pmem\n");
1351 return -EINVAL;
1352 }
1353
1354 stream->request.persistent_mem.offset = offset;
1355 stream->request.persistent_mem.size = size;
1356
1357 return 0;
1358}
1359
1360int sst_hsw_stream_set_smemory_info(struct sst_hsw *hsw,
1361 struct sst_hsw_stream *stream, u32 offset, u32 size)
1362{
1363 if (stream->commited) {
1364 dev_err(hsw->dev, "error: stream committed for set smem\n");
1365 return -EINVAL;
1366 }
1367
1368 stream->request.scratch_mem.offset = offset;
1369 stream->request.scratch_mem.size = size;
1370
1371 return 0;
1372}
1373
1374int sst_hsw_stream_commit(struct sst_hsw *hsw, struct sst_hsw_stream *stream)
1375{
1376 struct sst_hsw_ipc_stream_alloc_req *str_req = &stream->request;
1377 struct sst_hsw_ipc_stream_alloc_reply *reply = &stream->reply;
1378 u32 header;
1379 int ret;
1380
1381 trace_ipc_request("stream alloc", stream->host_id);
1382
1383 header = IPC_GLB_TYPE(IPC_GLB_ALLOCATE_STREAM);
1384
1385 ret = ipc_tx_message_wait(hsw, header, str_req, sizeof(*str_req),
1386 reply, sizeof(*reply));
1387 if (ret < 0) {
1388 dev_err(hsw->dev, "error: stream commit failed\n");
1389 return ret;
1390 }
1391
1392 stream->commited = 1;
1393 trace_hsw_stream_alloc_reply(stream);
1394
1395 return 0;
1396}
1397
1398/* Stream Information - these calls could be inline but we want the IPC
1399 ABI to be opaque to client PCM drivers to cope with any future ABI changes */
1400int sst_hsw_stream_get_hw_id(struct sst_hsw *hsw,
1401 struct sst_hsw_stream *stream)
1402{
1403 return stream->reply.stream_hw_id;
1404}
1405
1406int sst_hsw_stream_get_mixer_id(struct sst_hsw *hsw,
1407 struct sst_hsw_stream *stream)
1408{
1409 return stream->reply.mixer_hw_id;
1410}
1411
1412u32 sst_hsw_stream_get_read_reg(struct sst_hsw *hsw,
1413 struct sst_hsw_stream *stream)
1414{
1415 return stream->reply.read_position_register_address;
1416}
1417
1418u32 sst_hsw_stream_get_pointer_reg(struct sst_hsw *hsw,
1419 struct sst_hsw_stream *stream)
1420{
1421 return stream->reply.presentation_position_register_address;
1422}
1423
1424u32 sst_hsw_stream_get_peak_reg(struct sst_hsw *hsw,
1425 struct sst_hsw_stream *stream, u32 channel)
1426{
1427 if (channel >= 2)
1428 return 0;
1429
1430 return stream->reply.peak_meter_register_address[channel];
1431}
1432
1433u32 sst_hsw_stream_get_vol_reg(struct sst_hsw *hsw,
1434 struct sst_hsw_stream *stream, u32 channel)
1435{
1436 if (channel >= 2)
1437 return 0;
1438
1439 return stream->reply.volume_register_address[channel];
1440}
1441
1442int sst_hsw_mixer_get_info(struct sst_hsw *hsw)
1443{
1444 struct sst_hsw_ipc_stream_info_reply *reply;
1445 u32 header;
1446 int ret;
1447
1448 reply = &hsw->mixer_info;
1449 header = IPC_GLB_TYPE(IPC_GLB_GET_MIXER_STREAM_INFO);
1450
1451 trace_ipc_request("get global mixer info", 0);
1452
1453 ret = ipc_tx_message_wait(hsw, header, NULL, 0, reply, sizeof(*reply));
1454 if (ret < 0) {
1455 dev_err(hsw->dev, "error: get stream info failed\n");
1456 return ret;
1457 }
1458
1459 trace_hsw_mixer_info_reply(reply);
1460
1461 return 0;
1462}
1463
1464/* Send stream command */
1465static int sst_hsw_stream_operations(struct sst_hsw *hsw, int type,
1466 int stream_id, int wait)
1467{
1468 u32 header;
1469
1470 header = IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE) | IPC_STR_TYPE(type);
1471 header |= (stream_id << IPC_STR_ID_SHIFT);
1472
1473 if (wait)
1474 return ipc_tx_message_wait(hsw, header, NULL, 0, NULL, 0);
1475 else
1476 return ipc_tx_message_nowait(hsw, header, NULL, 0);
1477}
1478
1479/* Stream ALSA trigger operations */
1480int sst_hsw_stream_pause(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
1481 int wait)
1482{
1483 int ret;
1484
1485 trace_ipc_request("stream pause", stream->reply.stream_hw_id);
1486
1487 ret = sst_hsw_stream_operations(hsw, IPC_STR_PAUSE,
1488 stream->reply.stream_hw_id, wait);
1489 if (ret < 0)
1490 dev_err(hsw->dev, "error: failed to pause stream %d\n",
1491 stream->reply.stream_hw_id);
1492
1493 return ret;
1494}
1495
1496int sst_hsw_stream_resume(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
1497 int wait)
1498{
1499 int ret;
1500
1501 trace_ipc_request("stream resume", stream->reply.stream_hw_id);
1502
1503 ret = sst_hsw_stream_operations(hsw, IPC_STR_RESUME,
1504 stream->reply.stream_hw_id, wait);
1505 if (ret < 0)
1506 dev_err(hsw->dev, "error: failed to resume stream %d\n",
1507 stream->reply.stream_hw_id);
1508
1509 return ret;
1510}
1511
1512int sst_hsw_stream_reset(struct sst_hsw *hsw, struct sst_hsw_stream *stream)
1513{
1514 int ret, tries = 10;
1515
1516 /* dont reset streams that are not commited */
1517 if (!stream->commited)
1518 return 0;
1519
1520 /* wait for pause to complete before we reset the stream */
1521 while (stream->running && tries--)
1522 msleep(1);
1523 if (!tries) {
1524 dev_err(hsw->dev, "error: reset stream %d still running\n",
1525 stream->reply.stream_hw_id);
1526 return -EINVAL;
1527 }
1528
1529 trace_ipc_request("stream reset", stream->reply.stream_hw_id);
1530
1531 ret = sst_hsw_stream_operations(hsw, IPC_STR_RESET,
1532 stream->reply.stream_hw_id, 1);
1533 if (ret < 0)
1534 dev_err(hsw->dev, "error: failed to reset stream %d\n",
1535 stream->reply.stream_hw_id);
1536 return ret;
1537}
1538
1539/* Stream pointer positions */
1540int sst_hsw_get_dsp_position(struct sst_hsw *hsw,
1541 struct sst_hsw_stream *stream)
1542{
1543 return stream->rpos.position;
1544}
1545
1546int sst_hsw_stream_set_write_position(struct sst_hsw *hsw,
1547 struct sst_hsw_stream *stream, u32 stage_id, u32 position)
1548{
1549 u32 header;
1550 int ret;
1551
1552 trace_stream_write_position(stream->reply.stream_hw_id, position);
1553
1554 header = IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE) |
1555 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE);
1556 header |= (stream->reply.stream_hw_id << IPC_STR_ID_SHIFT);
1557 header |= (IPC_STG_SET_WRITE_POSITION << IPC_STG_TYPE_SHIFT);
1558 header |= (stage_id << IPC_STG_ID_SHIFT);
1559 stream->wpos.position = position;
1560
1561 ret = ipc_tx_message_nowait(hsw, header, &stream->wpos,
1562 sizeof(stream->wpos));
1563 if (ret < 0)
1564 dev_err(hsw->dev, "error: stream %d set position %d failed\n",
1565 stream->reply.stream_hw_id, position);
1566
1567 return ret;
1568}
1569
1570/* physical BE config */
1571int sst_hsw_device_set_config(struct sst_hsw *hsw,
1572 enum sst_hsw_device_id dev, enum sst_hsw_device_mclk mclk,
1573 enum sst_hsw_device_mode mode, u32 clock_divider)
1574{
1575 struct sst_hsw_ipc_device_config_req config;
1576 u32 header;
1577 int ret;
1578
1579 trace_ipc_request("set device config", dev);
1580
1581 config.ssp_interface = dev;
1582 config.clock_frequency = mclk;
1583 config.mode = mode;
1584 config.clock_divider = clock_divider;
1585
1586 trace_hsw_device_config_req(&config);
1587
1588 header = IPC_GLB_TYPE(IPC_GLB_SET_DEVICE_FORMATS);
1589
1590 ret = ipc_tx_message_wait(hsw, header, &config, sizeof(config),
1591 NULL, 0);
1592 if (ret < 0)
1593 dev_err(hsw->dev, "error: set device formats failed\n");
1594
1595 return ret;
1596}
1597EXPORT_SYMBOL_GPL(sst_hsw_device_set_config);
1598
1599/* DX Config */
1600int sst_hsw_dx_set_state(struct sst_hsw *hsw,
1601 enum sst_hsw_dx_state state, struct sst_hsw_ipc_dx_reply *dx)
1602{
1603 u32 header, state_;
1604 int ret;
1605
1606 header = IPC_GLB_TYPE(IPC_GLB_ENTER_DX_STATE);
1607 state_ = state;
1608
1609 trace_ipc_request("PM enter Dx state", state);
1610
1611 ret = ipc_tx_message_wait(hsw, header, &state_, sizeof(state_),
1612 dx, sizeof(dx));
1613 if (ret < 0) {
1614 dev_err(hsw->dev, "ipc: error set dx state %d failed\n", state);
1615 return ret;
1616 }
1617
1618 dev_dbg(hsw->dev, "ipc: got %d entry numbers for state %d\n",
1619 dx->entries_no, state);
1620
1621 memcpy(&hsw->dx, dx, sizeof(*dx));
1622 return 0;
1623}
1624
1625/* Used to save state into hsw->dx_reply */
1626int sst_hsw_dx_get_state(struct sst_hsw *hsw, u32 item,
1627 u32 *offset, u32 *size, u32 *source)
1628{
1629 struct sst_hsw_ipc_dx_memory_item *dx_mem;
1630 struct sst_hsw_ipc_dx_reply *dx_reply;
1631 int entry_no;
1632
1633 dx_reply = &hsw->dx;
1634 entry_no = dx_reply->entries_no;
1635
1636 trace_ipc_request("PM get Dx state", entry_no);
1637
1638 if (item >= entry_no)
1639 return -EINVAL;
1640
1641 dx_mem = &dx_reply->mem_info[item];
1642 *offset = dx_mem->offset;
1643 *size = dx_mem->size;
1644 *source = dx_mem->source;
1645
1646 return 0;
1647}
1648
1649static int msg_empty_list_init(struct sst_hsw *hsw)
1650{
1651 int i;
1652
1653 hsw->msg = kzalloc(sizeof(struct ipc_message) *
1654 IPC_EMPTY_LIST_SIZE, GFP_KERNEL);
1655 if (hsw->msg == NULL)
1656 return -ENOMEM;
1657
1658 for (i = 0; i < IPC_EMPTY_LIST_SIZE; i++) {
1659 init_waitqueue_head(&hsw->msg[i].waitq);
1660 list_add(&hsw->msg[i].list, &hsw->empty_list);
1661 }
1662
1663 return 0;
1664}
1665
1666void sst_hsw_set_scratch_module(struct sst_hsw *hsw,
1667 struct sst_module *scratch)
1668{
1669 hsw->scratch = scratch;
1670}
1671
1672struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw)
1673{
1674 return hsw->dsp;
1675}
1676
1677static struct sst_dsp_device hsw_dev = {
1678 .thread = hsw_irq_thread,
1679 .ops = &haswell_ops,
1680};
1681
1682int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
1683{
1684 struct sst_hsw_ipc_fw_version version;
1685 struct sst_hsw *hsw;
1686 struct sst_fw *hsw_sst_fw;
1687 int ret;
1688
1689 dev_dbg(dev, "initialising Audio DSP IPC\n");
1690
1691 hsw = devm_kzalloc(dev, sizeof(*hsw), GFP_KERNEL);
1692 if (hsw == NULL)
1693 return -ENOMEM;
1694
1695 hsw->dev = dev;
1696 INIT_LIST_HEAD(&hsw->stream_list);
1697 INIT_LIST_HEAD(&hsw->tx_list);
1698 INIT_LIST_HEAD(&hsw->rx_list);
1699 INIT_LIST_HEAD(&hsw->empty_list);
1700 init_waitqueue_head(&hsw->boot_wait);
1701 init_waitqueue_head(&hsw->wait_txq);
1702
1703 ret = msg_empty_list_init(hsw);
1704 if (ret < 0)
1705 goto list_err;
1706
1707 /* start the IPC message thread */
1708 init_kthread_worker(&hsw->kworker);
1709 hsw->tx_thread = kthread_run(kthread_worker_fn,
1710 &hsw->kworker,
1711 dev_name(hsw->dev));
1712 if (IS_ERR(hsw->tx_thread)) {
1713 ret = PTR_ERR(hsw->tx_thread);
1714 dev_err(hsw->dev, "error: failed to create message TX task\n");
1715 goto list_err;
1716 }
1717 init_kthread_work(&hsw->kwork, ipc_tx_msgs);
1718
1719 hsw_dev.thread_context = hsw;
1720
1721 /* init SST shim */
1722 hsw->dsp = sst_dsp_new(dev, &hsw_dev, pdata);
1723 if (hsw->dsp == NULL) {
1724 ret = -ENODEV;
1725 goto list_err;
1726 }
1727
1728 /* keep the DSP in reset state for base FW loading */
1729 sst_dsp_reset(hsw->dsp);
1730
1731 hsw_sst_fw = sst_fw_new(hsw->dsp, pdata->fw, hsw);
1732
1733 if (hsw_sst_fw == NULL) {
1734 ret = -ENODEV;
1735 dev_err(dev, "error: failed to load firmware\n");
1736 goto fw_err;
1737 }
1738
1739 /* wait for DSP boot completion */
1740 sst_dsp_boot(hsw->dsp);
1741 ret = wait_event_timeout(hsw->boot_wait, hsw->boot_complete,
1742 msecs_to_jiffies(IPC_BOOT_MSECS));
1743 if (ret == 0) {
1744 ret = -EIO;
1745 dev_err(hsw->dev, "error: ADSP boot timeout\n");
1746 goto boot_err;
1747 }
1748
1749 /* get the FW version */
1750 sst_hsw_fw_get_version(hsw, &version);
1751 dev_info(hsw->dev, "FW loaded: type %d - version: %d.%d build %d\n",
1752 version.type, version.major, version.minor, version.build);
1753
1754 /* get the globalmixer */
1755 ret = sst_hsw_mixer_get_info(hsw);
1756 if (ret < 0) {
1757 dev_err(hsw->dev, "error: failed to get stream info\n");
1758 goto boot_err;
1759 }
1760
1761 pdata->dsp = hsw;
1762 return 0;
1763
1764boot_err:
1765 sst_dsp_reset(hsw->dsp);
1766 sst_fw_free(hsw_sst_fw);
1767fw_err:
1768 sst_dsp_free(hsw->dsp);
1769 kfree(hsw->msg);
1770list_err:
1771 return ret;
1772}
1773EXPORT_SYMBOL_GPL(sst_hsw_dsp_init);
1774
1775void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata)
1776{
1777 struct sst_hsw *hsw = pdata->dsp;
1778
1779 sst_dsp_reset(hsw->dsp);
1780 sst_fw_free_all(hsw->dsp);
1781 sst_dsp_free(hsw->dsp);
1782 kfree(hsw->scratch);
1783 kfree(hsw->msg);
1784}
1785EXPORT_SYMBOL_GPL(sst_hsw_dsp_free);
diff --git a/sound/soc/intel/sst-haswell-ipc.h b/sound/soc/intel/sst-haswell-ipc.h
new file mode 100644
index 000000000000..d517929ccc38
--- /dev/null
+++ b/sound/soc/intel/sst-haswell-ipc.h
@@ -0,0 +1,488 @@
1/*
2 * Intel SST Haswell/Broadwell IPC Support
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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 version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#ifndef __SST_HASWELL_IPC_H
18#define __SST_HASWELL_IPC_H
19
20#include <linux/types.h>
21#include <linux/kernel.h>
22#include <linux/platform_device.h>
23
24#define SST_HSW_NO_CHANNELS 2
25#define SST_HSW_MAX_DX_REGIONS 14
26
27#define SST_HSW_FW_LOG_CONFIG_DWORDS 12
28#define SST_HSW_GLOBAL_LOG 15
29
30/**
31 * Upfront defined maximum message size that is
32 * expected by the in/out communication pipes in FW.
33 */
34#define SST_HSW_IPC_MAX_PAYLOAD_SIZE 400
35#define SST_HSW_MAX_INFO_SIZE 64
36#define SST_HSW_BUILD_HASH_LENGTH 40
37
38struct sst_hsw;
39struct sst_hsw_stream;
40struct sst_hsw_log_stream;
41struct sst_pdata;
42struct sst_module;
43extern struct sst_ops haswell_ops;
44
45/* Stream Allocate Path ID */
46enum sst_hsw_stream_path_id {
47 SST_HSW_STREAM_PATH_SSP0_OUT = 0,
48 SST_HSW_STREAM_PATH_SSP0_IN = 1,
49 SST_HSW_STREAM_PATH_MAX_PATH_ID = 2,
50};
51
52/* Stream Allocate Stream Type */
53enum sst_hsw_stream_type {
54 SST_HSW_STREAM_TYPE_RENDER = 0,
55 SST_HSW_STREAM_TYPE_SYSTEM = 1,
56 SST_HSW_STREAM_TYPE_CAPTURE = 2,
57 SST_HSW_STREAM_TYPE_LOOPBACK = 3,
58 SST_HSW_STREAM_TYPE_MAX_STREAM_TYPE = 4,
59};
60
61/* Stream Allocate Stream Format */
62enum sst_hsw_stream_format {
63 SST_HSW_STREAM_FORMAT_PCM_FORMAT = 0,
64 SST_HSW_STREAM_FORMAT_MP3_FORMAT = 1,
65 SST_HSW_STREAM_FORMAT_AAC_FORMAT = 2,
66 SST_HSW_STREAM_FORMAT_MAX_FORMAT_ID = 3,
67};
68
69/* Device ID */
70enum sst_hsw_device_id {
71 SST_HSW_DEVICE_SSP_0 = 0,
72 SST_HSW_DEVICE_SSP_1 = 1,
73};
74
75/* Device Master Clock Frequency */
76enum sst_hsw_device_mclk {
77 SST_HSW_DEVICE_MCLK_OFF = 0,
78 SST_HSW_DEVICE_MCLK_FREQ_6_MHZ = 1,
79 SST_HSW_DEVICE_MCLK_FREQ_12_MHZ = 2,
80 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ = 3,
81};
82
83/* Device Clock Master */
84enum sst_hsw_device_mode {
85 SST_HSW_DEVICE_CLOCK_SLAVE = 0,
86 SST_HSW_DEVICE_CLOCK_MASTER = 1,
87};
88
89/* DX Power State */
90enum sst_hsw_dx_state {
91 SST_HSW_DX_STATE_D0 = 0,
92 SST_HSW_DX_STATE_D1 = 1,
93 SST_HSW_DX_STATE_D3 = 3,
94 SST_HSW_DX_STATE_MAX = 3,
95};
96
97/* Audio stream stage IDs */
98enum sst_hsw_fx_stage_id {
99 SST_HSW_STAGE_ID_WAVES = 0,
100 SST_HSW_STAGE_ID_DTS = 1,
101 SST_HSW_STAGE_ID_DOLBY = 2,
102 SST_HSW_STAGE_ID_BOOST = 3,
103 SST_HSW_STAGE_ID_MAX_FX_ID
104};
105
106/* DX State Type */
107enum sst_hsw_dx_type {
108 SST_HSW_DX_TYPE_FW_IMAGE = 0,
109 SST_HSW_DX_TYPE_MEMORY_DUMP = 1
110};
111
112/* Volume Curve Type*/
113enum sst_hsw_volume_curve {
114 SST_HSW_VOLUME_CURVE_NONE = 0,
115 SST_HSW_VOLUME_CURVE_FADE = 1
116};
117
118/* Sample ordering */
119enum sst_hsw_interleaving {
120 SST_HSW_INTERLEAVING_PER_CHANNEL = 0,
121 SST_HSW_INTERLEAVING_PER_SAMPLE = 1,
122};
123
124/* Channel indices */
125enum sst_hsw_channel_index {
126 SST_HSW_CHANNEL_LEFT = 0,
127 SST_HSW_CHANNEL_CENTER = 1,
128 SST_HSW_CHANNEL_RIGHT = 2,
129 SST_HSW_CHANNEL_LEFT_SURROUND = 3,
130 SST_HSW_CHANNEL_CENTER_SURROUND = 3,
131 SST_HSW_CHANNEL_RIGHT_SURROUND = 4,
132 SST_HSW_CHANNEL_LFE = 7,
133 SST_HSW_CHANNEL_INVALID = 0xF,
134};
135
136/* List of supported channel maps. */
137enum sst_hsw_channel_config {
138 SST_HSW_CHANNEL_CONFIG_MONO = 0, /* mono only. */
139 SST_HSW_CHANNEL_CONFIG_STEREO = 1, /* L & R. */
140 SST_HSW_CHANNEL_CONFIG_2_POINT_1 = 2, /* L, R & LFE; PCM only. */
141 SST_HSW_CHANNEL_CONFIG_3_POINT_0 = 3, /* L, C & R; MP3 & AAC only. */
142 SST_HSW_CHANNEL_CONFIG_3_POINT_1 = 4, /* L, C, R & LFE; PCM only. */
143 SST_HSW_CHANNEL_CONFIG_QUATRO = 5, /* L, R, Ls & Rs; PCM only. */
144 SST_HSW_CHANNEL_CONFIG_4_POINT_0 = 6, /* L, C, R & Cs; MP3 & AAC only. */
145 SST_HSW_CHANNEL_CONFIG_5_POINT_0 = 7, /* L, C, R, Ls & Rs. */
146 SST_HSW_CHANNEL_CONFIG_5_POINT_1 = 8, /* L, C, R, Ls, Rs & LFE. */
147 SST_HSW_CHANNEL_CONFIG_DUAL_MONO = 9, /* One channel replicated in two. */
148 SST_HSW_CHANNEL_CONFIG_INVALID,
149};
150
151/* List of supported bit depths. */
152enum sst_hsw_bitdepth {
153 SST_HSW_DEPTH_8BIT = 8,
154 SST_HSW_DEPTH_16BIT = 16,
155 SST_HSW_DEPTH_24BIT = 24, /* Default. */
156 SST_HSW_DEPTH_32BIT = 32,
157 SST_HSW_DEPTH_INVALID = 33,
158};
159
160enum sst_hsw_module_id {
161 SST_HSW_MODULE_BASE_FW = 0x0,
162 SST_HSW_MODULE_MP3 = 0x1,
163 SST_HSW_MODULE_AAC_5_1 = 0x2,
164 SST_HSW_MODULE_AAC_2_0 = 0x3,
165 SST_HSW_MODULE_SRC = 0x4,
166 SST_HSW_MODULE_WAVES = 0x5,
167 SST_HSW_MODULE_DOLBY = 0x6,
168 SST_HSW_MODULE_BOOST = 0x7,
169 SST_HSW_MODULE_LPAL = 0x8,
170 SST_HSW_MODULE_DTS = 0x9,
171 SST_HSW_MODULE_PCM_CAPTURE = 0xA,
172 SST_HSW_MODULE_PCM_SYSTEM = 0xB,
173 SST_HSW_MODULE_PCM_REFERENCE = 0xC,
174 SST_HSW_MODULE_PCM = 0xD,
175 SST_HSW_MODULE_BLUETOOTH_RENDER_MODULE = 0xE,
176 SST_HSW_MODULE_BLUETOOTH_CAPTURE_MODULE = 0xF,
177 SST_HSW_MAX_MODULE_ID,
178};
179
180enum sst_hsw_performance_action {
181 SST_HSW_PERF_START = 0,
182 SST_HSW_PERF_STOP = 1,
183};
184
185/* SST firmware module info */
186struct sst_hsw_module_info {
187 u8 name[SST_HSW_MAX_INFO_SIZE];
188 u8 version[SST_HSW_MAX_INFO_SIZE];
189} __attribute__((packed));
190
191/* Module entry point */
192struct sst_hsw_module_entry {
193 enum sst_hsw_module_id module_id;
194 u32 entry_point;
195} __attribute__((packed));
196
197/* Module map - alignement matches DSP */
198struct sst_hsw_module_map {
199 u8 module_entries_count;
200 struct sst_hsw_module_entry module_entries[1];
201} __attribute__((packed));
202
203struct sst_hsw_memory_info {
204 u32 offset;
205 u32 size;
206} __attribute__((packed));
207
208struct sst_hsw_fx_enable {
209 struct sst_hsw_module_map module_map;
210 struct sst_hsw_memory_info persistent_mem;
211} __attribute__((packed));
212
213struct sst_hsw_get_fx_param {
214 u32 parameter_id;
215 u32 param_size;
216} __attribute__((packed));
217
218struct sst_hsw_perf_action {
219 u32 action;
220} __attribute__((packed));
221
222struct sst_hsw_perf_data {
223 u64 timestamp;
224 u64 cycles;
225 u64 datatime;
226} __attribute__((packed));
227
228/* FW version */
229struct sst_hsw_ipc_fw_version {
230 u8 build;
231 u8 minor;
232 u8 major;
233 u8 type;
234 u8 fw_build_hash[SST_HSW_BUILD_HASH_LENGTH];
235 u32 fw_log_providers_hash;
236} __attribute__((packed));
237
238/* Stream ring info */
239struct sst_hsw_ipc_stream_ring {
240 u32 ring_pt_address;
241 u32 num_pages;
242 u32 ring_size;
243 u32 ring_offset;
244 u32 ring_first_pfn;
245} __attribute__((packed));
246
247/* Debug Dump Log Enable Request */
248struct sst_hsw_ipc_debug_log_enable_req {
249 struct sst_hsw_ipc_stream_ring ringinfo;
250 u32 config[SST_HSW_FW_LOG_CONFIG_DWORDS];
251} __attribute__((packed));
252
253/* Debug Dump Log Reply */
254struct sst_hsw_ipc_debug_log_reply {
255 u32 log_buffer_begining;
256 u32 log_buffer_size;
257} __attribute__((packed));
258
259/* Stream glitch position */
260struct sst_hsw_ipc_stream_glitch_position {
261 u32 glitch_type;
262 u32 present_pos;
263 u32 write_pos;
264} __attribute__((packed));
265
266/* Stream get position */
267struct sst_hsw_ipc_stream_get_position {
268 u32 position;
269 u32 fw_cycle_count;
270} __attribute__((packed));
271
272/* Stream set position */
273struct sst_hsw_ipc_stream_set_position {
274 u32 position;
275 u32 end_of_buffer;
276} __attribute__((packed));
277
278/* Stream Free Request */
279struct sst_hsw_ipc_stream_free_req {
280 u8 stream_id;
281 u8 reserved[3];
282} __attribute__((packed));
283
284/* Set Volume Request */
285struct sst_hsw_ipc_volume_req {
286 u32 channel;
287 u32 target_volume;
288 u64 curve_duration;
289 u32 curve_type;
290} __attribute__((packed));
291
292/* Device Configuration Request */
293struct sst_hsw_ipc_device_config_req {
294 u32 ssp_interface;
295 u32 clock_frequency;
296 u32 mode;
297 u16 clock_divider;
298 u16 reserved;
299} __attribute__((packed));
300
301/* Audio Data formats */
302struct sst_hsw_audio_data_format_ipc {
303 u32 frequency;
304 u32 bitdepth;
305 u32 map;
306 u32 config;
307 u32 style;
308 u8 ch_num;
309 u8 valid_bit;
310 u8 reserved[2];
311} __attribute__((packed));
312
313/* Stream Allocate Request */
314struct sst_hsw_ipc_stream_alloc_req {
315 u8 path_id;
316 u8 stream_type;
317 u8 format_id;
318 u8 reserved;
319 struct sst_hsw_audio_data_format_ipc format;
320 struct sst_hsw_ipc_stream_ring ringinfo;
321 struct sst_hsw_module_map map;
322 struct sst_hsw_memory_info persistent_mem;
323 struct sst_hsw_memory_info scratch_mem;
324 u32 number_of_notifications;
325} __attribute__((packed));
326
327/* Stream Allocate Reply */
328struct sst_hsw_ipc_stream_alloc_reply {
329 u32 stream_hw_id;
330 u32 mixer_hw_id; // returns rate ????
331 u32 read_position_register_address;
332 u32 presentation_position_register_address;
333 u32 peak_meter_register_address[SST_HSW_NO_CHANNELS];
334 u32 volume_register_address[SST_HSW_NO_CHANNELS];
335} __attribute__((packed));
336
337/* Get Mixer Stream Info */
338struct sst_hsw_ipc_stream_info_reply {
339 u32 mixer_hw_id;
340 u32 peak_meter_register_address[SST_HSW_NO_CHANNELS];
341 u32 volume_register_address[SST_HSW_NO_CHANNELS];
342} __attribute__((packed));
343
344/* DX State Request */
345struct sst_hsw_ipc_dx_req {
346 u8 state;
347 u8 reserved[3];
348} __attribute__((packed));
349
350/* DX State Reply Memory Info Item */
351struct sst_hsw_ipc_dx_memory_item {
352 u32 offset;
353 u32 size;
354 u32 source;
355} __attribute__((packed));
356
357/* DX State Reply */
358struct sst_hsw_ipc_dx_reply {
359 u32 entries_no;
360 struct sst_hsw_ipc_dx_memory_item mem_info[SST_HSW_MAX_DX_REGIONS];
361} __attribute__((packed));
362
363struct sst_hsw_ipc_fw_version;
364
365/* SST Init & Free */
366struct sst_hsw *sst_hsw_new(struct device *dev, const u8 *fw, size_t fw_length,
367 u32 fw_offset);
368void sst_hsw_free(struct sst_hsw *hsw);
369int sst_hsw_fw_get_version(struct sst_hsw *hsw,
370 struct sst_hsw_ipc_fw_version *version);
371u32 create_channel_map(enum sst_hsw_channel_config config);
372
373/* Stream Mixer Controls - */
374int sst_hsw_stream_mute(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
375 u32 stage_id, u32 channel);
376int sst_hsw_stream_unmute(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
377 u32 stage_id, u32 channel);
378
379int sst_hsw_stream_set_volume(struct sst_hsw *hsw,
380 struct sst_hsw_stream *stream, u32 stage_id, u32 channel, u32 volume);
381int sst_hsw_stream_get_volume(struct sst_hsw *hsw,
382 struct sst_hsw_stream *stream, u32 stage_id, u32 channel, u32 *volume);
383
384int sst_hsw_stream_set_volume_curve(struct sst_hsw *hsw,
385 struct sst_hsw_stream *stream, u64 curve_duration,
386 enum sst_hsw_volume_curve curve);
387
388/* Global Mixer Controls - */
389int sst_hsw_mixer_mute(struct sst_hsw *hsw, u32 stage_id, u32 channel);
390int sst_hsw_mixer_unmute(struct sst_hsw *hsw, u32 stage_id, u32 channel);
391
392int sst_hsw_mixer_set_volume(struct sst_hsw *hsw, u32 stage_id, u32 channel,
393 u32 volume);
394int sst_hsw_mixer_get_volume(struct sst_hsw *hsw, u32 stage_id, u32 channel,
395 u32 *volume);
396
397int sst_hsw_mixer_set_volume_curve(struct sst_hsw *hsw,
398 u64 curve_duration, enum sst_hsw_volume_curve curve);
399
400/* Stream API */
401struct sst_hsw_stream *sst_hsw_stream_new(struct sst_hsw *hsw, int id,
402 u32 (*get_write_position)(struct sst_hsw_stream *stream, void *data),
403 void *data);
404
405int sst_hsw_stream_free(struct sst_hsw *hsw, struct sst_hsw_stream *stream);
406
407/* Stream Configuration */
408int sst_hsw_stream_format(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
409 enum sst_hsw_stream_path_id path_id,
410 enum sst_hsw_stream_type stream_type,
411 enum sst_hsw_stream_format format_id);
412
413int sst_hsw_stream_buffer(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
414 u32 ring_pt_address, u32 num_pages,
415 u32 ring_size, u32 ring_offset, u32 ring_first_pfn);
416
417int sst_hsw_stream_commit(struct sst_hsw *hsw, struct sst_hsw_stream *stream);
418
419int sst_hsw_stream_set_valid(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
420 u32 bits);
421int sst_hsw_stream_set_rate(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
422 int rate);
423int sst_hsw_stream_set_bits(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
424 enum sst_hsw_bitdepth bits);
425int sst_hsw_stream_set_channels(struct sst_hsw *hsw,
426 struct sst_hsw_stream *stream, int channels);
427int sst_hsw_stream_set_map_config(struct sst_hsw *hsw,
428 struct sst_hsw_stream *stream, u32 map,
429 enum sst_hsw_channel_config config);
430int sst_hsw_stream_set_style(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
431 enum sst_hsw_interleaving style);
432int sst_hsw_stream_set_module_info(struct sst_hsw *hsw,
433 struct sst_hsw_stream *stream, enum sst_hsw_module_id module_id,
434 u32 entry_point);
435int sst_hsw_stream_set_pmemory_info(struct sst_hsw *hsw,
436 struct sst_hsw_stream *stream, u32 offset, u32 size);
437int sst_hsw_stream_set_smemory_info(struct sst_hsw *hsw,
438 struct sst_hsw_stream *stream, u32 offset, u32 size);
439int sst_hsw_stream_get_hw_id(struct sst_hsw *hsw,
440 struct sst_hsw_stream *stream);
441int sst_hsw_stream_get_mixer_id(struct sst_hsw *hsw,
442 struct sst_hsw_stream *stream);
443u32 sst_hsw_stream_get_read_reg(struct sst_hsw *hsw,
444 struct sst_hsw_stream *stream);
445u32 sst_hsw_stream_get_pointer_reg(struct sst_hsw *hsw,
446 struct sst_hsw_stream *stream);
447u32 sst_hsw_stream_get_peak_reg(struct sst_hsw *hsw,
448 struct sst_hsw_stream *stream, u32 channel);
449u32 sst_hsw_stream_get_vol_reg(struct sst_hsw *hsw,
450 struct sst_hsw_stream *stream, u32 channel);
451int sst_hsw_mixer_get_info(struct sst_hsw *hsw);
452
453/* Stream ALSA trigger operations */
454int sst_hsw_stream_pause(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
455 int wait);
456int sst_hsw_stream_resume(struct sst_hsw *hsw, struct sst_hsw_stream *stream,
457 int wait);
458int sst_hsw_stream_reset(struct sst_hsw *hsw, struct sst_hsw_stream *stream);
459
460/* Stream pointer positions */
461int sst_hsw_stream_get_read_pos(struct sst_hsw *hsw,
462 struct sst_hsw_stream *stream, u32 *position);
463int sst_hsw_stream_get_write_pos(struct sst_hsw *hsw,
464 struct sst_hsw_stream *stream, u32 *position);
465int sst_hsw_stream_set_write_position(struct sst_hsw *hsw,
466 struct sst_hsw_stream *stream, u32 stage_id, u32 position);
467int sst_hsw_get_dsp_position(struct sst_hsw *hsw,
468 struct sst_hsw_stream *stream);
469
470/* HW port config */
471int sst_hsw_device_set_config(struct sst_hsw *hsw,
472 enum sst_hsw_device_id dev, enum sst_hsw_device_mclk mclk,
473 enum sst_hsw_device_mode mode, u32 clock_divider);
474
475/* DX Config */
476int sst_hsw_dx_set_state(struct sst_hsw *hsw,
477 enum sst_hsw_dx_state state, struct sst_hsw_ipc_dx_reply *dx);
478int sst_hsw_dx_get_state(struct sst_hsw *hsw, u32 item,
479 u32 *offset, u32 *size, u32 *source);
480
481/* init */
482int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata);
483void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata);
484struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw);
485void sst_hsw_set_scratch_module(struct sst_hsw *hsw,
486 struct sst_module *scratch);
487
488#endif
diff --git a/sound/soc/intel/sst-haswell-pcm.c b/sound/soc/intel/sst-haswell-pcm.c
new file mode 100644
index 000000000000..0a32dd13a23d
--- /dev/null
+++ b/sound/soc/intel/sst-haswell-pcm.c
@@ -0,0 +1,872 @@
1/*
2 * Intel SST Haswell/Broadwell PCM Support
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
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 version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/dma-mapping.h>
19#include <linux/slab.h>
20#include <linux/module.h>
21#include <linux/delay.h>
22#include <asm/page.h>
23#include <asm/pgtable.h>
24#include <sound/core.h>
25#include <sound/pcm.h>
26#include <sound/pcm_params.h>
27#include <sound/dmaengine_pcm.h>
28#include <sound/soc.h>
29#include <sound/tlv.h>
30#include <sound/compress_driver.h>
31
32#include "sst-haswell-ipc.h"
33#include "sst-dsp-priv.h"
34#include "sst-dsp.h"
35
36#define HSW_PCM_COUNT 6
37#define HSW_VOLUME_MAX 0x7FFFFFFF /* 0dB */
38
39/* simple volume table */
40static const u32 volume_map[] = {
41 HSW_VOLUME_MAX >> 30,
42 HSW_VOLUME_MAX >> 29,
43 HSW_VOLUME_MAX >> 28,
44 HSW_VOLUME_MAX >> 27,
45 HSW_VOLUME_MAX >> 26,
46 HSW_VOLUME_MAX >> 25,
47 HSW_VOLUME_MAX >> 24,
48 HSW_VOLUME_MAX >> 23,
49 HSW_VOLUME_MAX >> 22,
50 HSW_VOLUME_MAX >> 21,
51 HSW_VOLUME_MAX >> 20,
52 HSW_VOLUME_MAX >> 19,
53 HSW_VOLUME_MAX >> 18,
54 HSW_VOLUME_MAX >> 17,
55 HSW_VOLUME_MAX >> 16,
56 HSW_VOLUME_MAX >> 15,
57 HSW_VOLUME_MAX >> 14,
58 HSW_VOLUME_MAX >> 13,
59 HSW_VOLUME_MAX >> 12,
60 HSW_VOLUME_MAX >> 11,
61 HSW_VOLUME_MAX >> 10,
62 HSW_VOLUME_MAX >> 9,
63 HSW_VOLUME_MAX >> 8,
64 HSW_VOLUME_MAX >> 7,
65 HSW_VOLUME_MAX >> 6,
66 HSW_VOLUME_MAX >> 5,
67 HSW_VOLUME_MAX >> 4,
68 HSW_VOLUME_MAX >> 3,
69 HSW_VOLUME_MAX >> 2,
70 HSW_VOLUME_MAX >> 1,
71 HSW_VOLUME_MAX >> 0,
72};
73
74#define HSW_PCM_PERIODS_MAX 64
75#define HSW_PCM_PERIODS_MIN 2
76
77static const struct snd_pcm_hardware hsw_pcm_hardware = {
78 .info = SNDRV_PCM_INFO_MMAP |
79 SNDRV_PCM_INFO_MMAP_VALID |
80 SNDRV_PCM_INFO_INTERLEAVED |
81 SNDRV_PCM_INFO_PAUSE |
82 SNDRV_PCM_INFO_RESUME |
83 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
84 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE |
85 SNDRV_PCM_FMTBIT_S32_LE,
86 .period_bytes_min = PAGE_SIZE,
87 .period_bytes_max = (HSW_PCM_PERIODS_MAX / HSW_PCM_PERIODS_MIN) * PAGE_SIZE,
88 .periods_min = HSW_PCM_PERIODS_MIN,
89 .periods_max = HSW_PCM_PERIODS_MAX,
90 .buffer_bytes_max = HSW_PCM_PERIODS_MAX * PAGE_SIZE,
91};
92
93/* private data for each PCM DSP stream */
94struct hsw_pcm_data {
95 int dai_id;
96 struct sst_hsw_stream *stream;
97 u32 volume[2];
98 struct snd_pcm_substream *substream;
99 struct snd_compr_stream *cstream;
100 unsigned int wpos;
101 struct mutex mutex;
102};
103
104/* private data for the driver */
105struct hsw_priv_data {
106 /* runtime DSP */
107 struct sst_hsw *hsw;
108
109 /* page tables */
110 unsigned char *pcm_pg[HSW_PCM_COUNT][2];
111
112 /* DAI data */
113 struct hsw_pcm_data pcm[HSW_PCM_COUNT];
114};
115
116static inline u32 hsw_mixer_to_ipc(unsigned int value)
117{
118 if (value >= ARRAY_SIZE(volume_map))
119 return volume_map[0];
120 else
121 return volume_map[value];
122}
123
124static inline unsigned int hsw_ipc_to_mixer(u32 value)
125{
126 int i;
127
128 for (i = 0; i < ARRAY_SIZE(volume_map); i++) {
129 if (volume_map[i] >= value)
130 return i;
131 }
132
133 return i - 1;
134}
135
136static int hsw_stream_volume_put(struct snd_kcontrol *kcontrol,
137 struct snd_ctl_elem_value *ucontrol)
138{
139 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
140 struct soc_mixer_control *mc =
141 (struct soc_mixer_control *)kcontrol->private_value;
142 struct hsw_priv_data *pdata =
143 snd_soc_platform_get_drvdata(platform);
144 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg];
145 struct sst_hsw *hsw = pdata->hsw;
146 u32 volume;
147
148 mutex_lock(&pcm_data->mutex);
149
150 if (!pcm_data->stream) {
151 pcm_data->volume[0] =
152 hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
153 pcm_data->volume[1] =
154 hsw_mixer_to_ipc(ucontrol->value.integer.value[1]);
155 mutex_unlock(&pcm_data->mutex);
156 return 0;
157 }
158
159 if (ucontrol->value.integer.value[0] ==
160 ucontrol->value.integer.value[1]) {
161 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
162 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 2, volume);
163 } else {
164 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
165 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 0, volume);
166 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[1]);
167 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0, 1, volume);
168 }
169
170 mutex_unlock(&pcm_data->mutex);
171 return 0;
172}
173
174static int hsw_stream_volume_get(struct snd_kcontrol *kcontrol,
175 struct snd_ctl_elem_value *ucontrol)
176{
177 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
178 struct soc_mixer_control *mc =
179 (struct soc_mixer_control *)kcontrol->private_value;
180 struct hsw_priv_data *pdata =
181 snd_soc_platform_get_drvdata(platform);
182 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg];
183 struct sst_hsw *hsw = pdata->hsw;
184 u32 volume;
185
186 mutex_lock(&pcm_data->mutex);
187
188 if (!pcm_data->stream) {
189 ucontrol->value.integer.value[0] =
190 hsw_ipc_to_mixer(pcm_data->volume[0]);
191 ucontrol->value.integer.value[1] =
192 hsw_ipc_to_mixer(pcm_data->volume[1]);
193 mutex_unlock(&pcm_data->mutex);
194 return 0;
195 }
196
197 sst_hsw_stream_get_volume(hsw, pcm_data->stream, 0, 0, &volume);
198 ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume);
199 sst_hsw_stream_get_volume(hsw, pcm_data->stream, 0, 1, &volume);
200 ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume);
201 mutex_unlock(&pcm_data->mutex);
202
203 return 0;
204}
205
206static int hsw_volume_put(struct snd_kcontrol *kcontrol,
207 struct snd_ctl_elem_value *ucontrol)
208{
209 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
210 struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform);
211 struct sst_hsw *hsw = pdata->hsw;
212 u32 volume;
213
214 if (ucontrol->value.integer.value[0] ==
215 ucontrol->value.integer.value[1]) {
216
217 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
218 sst_hsw_mixer_set_volume(hsw, 0, 2, volume);
219
220 } else {
221 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[0]);
222 sst_hsw_mixer_set_volume(hsw, 0, 0, volume);
223
224 volume = hsw_mixer_to_ipc(ucontrol->value.integer.value[1]);
225 sst_hsw_mixer_set_volume(hsw, 0, 1, volume);
226 }
227
228 return 0;
229}
230
231static int hsw_volume_get(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_value *ucontrol)
233{
234 struct snd_soc_platform *platform = snd_kcontrol_chip(kcontrol);
235 struct hsw_priv_data *pdata = snd_soc_platform_get_drvdata(platform);
236 struct sst_hsw *hsw = pdata->hsw;
237 unsigned int volume = 0;
238
239 sst_hsw_mixer_get_volume(hsw, 0, 0, &volume);
240 ucontrol->value.integer.value[0] = hsw_ipc_to_mixer(volume);
241
242 sst_hsw_mixer_get_volume(hsw, 0, 1, &volume);
243 ucontrol->value.integer.value[1] = hsw_ipc_to_mixer(volume);
244
245 return 0;
246}
247
248/* TLV used by both global and stream volumes */
249static const DECLARE_TLV_DB_SCALE(hsw_vol_tlv, -9000, 300, 1);
250
251/* System Pin has no volume control */
252static const struct snd_kcontrol_new hsw_volume_controls[] = {
253 /* Global DSP volume */
254 SOC_DOUBLE_EXT_TLV("Master Playback Volume", 0, 0, 8,
255 ARRAY_SIZE(volume_map) -1, 0,
256 hsw_volume_get, hsw_volume_put, hsw_vol_tlv),
257 /* Offload 0 volume */
258 SOC_DOUBLE_EXT_TLV("Media0 Playback Volume", 1, 0, 8,
259 ARRAY_SIZE(volume_map), 0,
260 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
261 /* Offload 1 volume */
262 SOC_DOUBLE_EXT_TLV("Media1 Playback Volume", 2, 0, 8,
263 ARRAY_SIZE(volume_map), 0,
264 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
265 /* Loopback volume */
266 SOC_DOUBLE_EXT_TLV("Loopback Capture Volume", 3, 0, 8,
267 ARRAY_SIZE(volume_map), 0,
268 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
269 /* Mic Capture volume */
270 SOC_DOUBLE_EXT_TLV("Mic Capture Volume", 4, 0, 8,
271 ARRAY_SIZE(volume_map), 0,
272 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
273};
274
275/* Create DMA buffer page table for DSP */
276static int create_adsp_page_table(struct hsw_priv_data *pdata,
277 struct snd_soc_pcm_runtime *rtd,
278 unsigned char *dma_area, size_t size, int pcm, int stream)
279{
280 int i, pages;
281
282 if (size % PAGE_SIZE)
283 pages = (size / PAGE_SIZE) + 1;
284 else
285 pages = size / PAGE_SIZE;
286
287 dev_dbg(rtd->dev, "generating page table for %p size 0x%zu pages %d\n",
288 dma_area, size, pages);
289
290 for (i = 0; i < pages; i++) {
291 u32 idx = (((i << 2) + i)) >> 1;
292 u32 pfn = (virt_to_phys(dma_area + i * PAGE_SIZE)) >> PAGE_SHIFT;
293 u32 *pg_table;
294
295 dev_dbg(rtd->dev, "pfn i %i idx %d pfn %x\n", i, idx, pfn);
296
297 pg_table = (u32*)(pdata->pcm_pg[pcm][stream] + idx);
298
299 if (i & 1)
300 *pg_table |= (pfn << 4);
301 else
302 *pg_table |= pfn;
303 }
304
305 return 0;
306}
307
308/* this may get called several times by oss emulation */
309static int hsw_pcm_hw_params(struct snd_pcm_substream *substream,
310 struct snd_pcm_hw_params *params)
311{
312 struct snd_soc_pcm_runtime *rtd = substream->private_data;
313 struct snd_pcm_runtime *runtime = substream->runtime;
314 struct hsw_priv_data *pdata =
315 snd_soc_platform_get_drvdata(rtd->platform);
316 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
317 struct sst_hsw *hsw = pdata->hsw;
318 struct sst_module *module_data;
319 struct sst_dsp *dsp;
320 enum sst_hsw_stream_type stream_type;
321 enum sst_hsw_stream_path_id path_id;
322 u32 rate, bits, map, pages, module_id;
323 u8 channels;
324 int ret;
325
326 /* stream direction */
327 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
328 path_id = SST_HSW_STREAM_PATH_SSP0_OUT;
329 else
330 path_id = SST_HSW_STREAM_PATH_SSP0_IN;
331
332 /* DSP stream type depends on DAI ID */
333 switch (rtd->cpu_dai->id) {
334 case 0:
335 stream_type = SST_HSW_STREAM_TYPE_SYSTEM;
336 module_id = SST_HSW_MODULE_PCM_SYSTEM;
337 break;
338 case 1:
339 case 2:
340 stream_type = SST_HSW_STREAM_TYPE_RENDER;
341 module_id = SST_HSW_MODULE_PCM;
342 break;
343 case 3:
344 /* path ID needs to be OUT for loopback */
345 stream_type = SST_HSW_STREAM_TYPE_LOOPBACK;
346 path_id = SST_HSW_STREAM_PATH_SSP0_OUT;
347 module_id = SST_HSW_MODULE_PCM_REFERENCE;
348 break;
349 case 4:
350 stream_type = SST_HSW_STREAM_TYPE_CAPTURE;
351 module_id = SST_HSW_MODULE_PCM_CAPTURE;
352 break;
353 default:
354 dev_err(rtd->dev, "error: invalid DAI ID %d\n",
355 rtd->cpu_dai->id);
356 return -EINVAL;
357 };
358
359 ret = sst_hsw_stream_format(hsw, pcm_data->stream,
360 path_id, stream_type, SST_HSW_STREAM_FORMAT_PCM_FORMAT);
361 if (ret < 0) {
362 dev_err(rtd->dev, "error: failed to set format %d\n", ret);
363 return ret;
364 }
365
366 rate = params_rate(params);
367 ret = sst_hsw_stream_set_rate(hsw, pcm_data->stream, rate);
368 if (ret < 0) {
369 dev_err(rtd->dev, "error: could not set rate %d\n", rate);
370 return ret;
371 }
372
373 switch (params_format(params)) {
374 case SNDRV_PCM_FORMAT_S16_LE:
375 bits = SST_HSW_DEPTH_16BIT;
376 sst_hsw_stream_set_valid(hsw, pcm_data->stream, 16);
377 break;
378 case SNDRV_PCM_FORMAT_S24_LE:
379 bits = SST_HSW_DEPTH_24BIT;
380 sst_hsw_stream_set_valid(hsw, pcm_data->stream, 32);
381 break;
382 default:
383 dev_err(rtd->dev, "error: invalid format %d\n",
384 params_format(params));
385 return -EINVAL;
386 }
387
388 ret = sst_hsw_stream_set_bits(hsw, pcm_data->stream, bits);
389 if (ret < 0) {
390 dev_err(rtd->dev, "error: could not set bits %d\n", bits);
391 return ret;
392 }
393
394 /* we only support stereo atm */
395 channels = params_channels(params);
396 if (channels != 2) {
397 dev_err(rtd->dev, "error: invalid channels %d\n", channels);
398 return -EINVAL;
399 }
400
401 map = create_channel_map(SST_HSW_CHANNEL_CONFIG_STEREO);
402 sst_hsw_stream_set_map_config(hsw, pcm_data->stream,
403 map, SST_HSW_CHANNEL_CONFIG_STEREO);
404
405 ret = sst_hsw_stream_set_channels(hsw, pcm_data->stream, channels);
406 if (ret < 0) {
407 dev_err(rtd->dev, "error: could not set channels %d\n",
408 channels);
409 return ret;
410 }
411
412 ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
413 if (ret < 0) {
414 dev_err(rtd->dev, "error: could not allocate %d bytes for PCM %d\n",
415 params_buffer_bytes(params), ret);
416 return ret;
417 }
418
419 ret = create_adsp_page_table(pdata, rtd, runtime->dma_area,
420 runtime->dma_bytes, rtd->cpu_dai->id, substream->stream);
421 if (ret < 0)
422 return ret;
423
424 sst_hsw_stream_set_style(hsw, pcm_data->stream,
425 SST_HSW_INTERLEAVING_PER_CHANNEL);
426
427 if (runtime->dma_bytes % PAGE_SIZE)
428 pages = (runtime->dma_bytes / PAGE_SIZE) + 1;
429 else
430 pages = runtime->dma_bytes / PAGE_SIZE;
431
432 ret = sst_hsw_stream_buffer(hsw, pcm_data->stream,
433 virt_to_phys(pdata->pcm_pg[rtd->cpu_dai->id][substream->stream]),
434 pages, runtime->dma_bytes, 0,
435 (u32)(virt_to_phys(runtime->dma_area) >> PAGE_SHIFT));
436 if (ret < 0) {
437 dev_err(rtd->dev, "error: failed to set DMA buffer %d\n", ret);
438 return ret;
439 }
440
441 dsp = sst_hsw_get_dsp(hsw);
442
443 module_data = sst_module_get_from_id(dsp, module_id);
444 if (module_data == NULL) {
445 dev_err(rtd->dev, "error: failed to get module config\n");
446 return -EINVAL;
447 }
448
449 /* we use hardcoded memory offsets atm, will be updated for new FW */
450 if (stream_type == SST_HSW_STREAM_TYPE_CAPTURE) {
451 sst_hsw_stream_set_module_info(hsw, pcm_data->stream,
452 SST_HSW_MODULE_PCM_CAPTURE, module_data->entry);
453 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
454 0x449400, 0x4000);
455 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
456 0x400000, 0);
457 } else { /* stream_type == SST_HSW_STREAM_TYPE_SYSTEM */
458 sst_hsw_stream_set_module_info(hsw, pcm_data->stream,
459 SST_HSW_MODULE_PCM_SYSTEM, module_data->entry);
460
461 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
462 module_data->offset, module_data->size);
463 sst_hsw_stream_set_pmemory_info(hsw, pcm_data->stream,
464 0x44d400, 0x3800);
465
466 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
467 module_data->offset, module_data->size);
468 sst_hsw_stream_set_smemory_info(hsw, pcm_data->stream,
469 0x400000, 0);
470 }
471
472 ret = sst_hsw_stream_commit(hsw, pcm_data->stream);
473 if (ret < 0) {
474 dev_err(rtd->dev, "error: failed to commit stream %d\n", ret);
475 return ret;
476 }
477
478 ret = sst_hsw_stream_pause(hsw, pcm_data->stream, 1);
479 if (ret < 0)
480 dev_err(rtd->dev, "error: failed to pause %d\n", ret);
481
482 return 0;
483}
484
485static int hsw_pcm_hw_free(struct snd_pcm_substream *substream)
486{
487 snd_pcm_lib_free_pages(substream);
488 return 0;
489}
490
491static int hsw_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
492{
493 struct snd_soc_pcm_runtime *rtd = substream->private_data;
494 struct hsw_priv_data *pdata =
495 snd_soc_platform_get_drvdata(rtd->platform);
496 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
497 struct sst_hsw *hsw = pdata->hsw;
498
499 switch (cmd) {
500 case SNDRV_PCM_TRIGGER_START:
501 case SNDRV_PCM_TRIGGER_RESUME:
502 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
503 sst_hsw_stream_resume(hsw, pcm_data->stream, 0);
504 break;
505 case SNDRV_PCM_TRIGGER_STOP:
506 case SNDRV_PCM_TRIGGER_SUSPEND:
507 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
508 sst_hsw_stream_pause(hsw, pcm_data->stream, 0);
509 break;
510 default:
511 break;
512 }
513
514 return 0;
515}
516
517static u32 hsw_notify_pointer(struct sst_hsw_stream *stream, void *data)
518{
519 struct hsw_pcm_data *pcm_data = data;
520 struct snd_pcm_substream *substream = pcm_data->substream;
521 struct snd_pcm_runtime *runtime = substream->runtime;
522 struct snd_soc_pcm_runtime *rtd = substream->private_data;
523 u32 pos;
524
525 pos = frames_to_bytes(runtime,
526 (runtime->control->appl_ptr % runtime->buffer_size));
527
528 dev_dbg(rtd->dev, "PCM: App pointer %d bytes\n", pos);
529
530 /* let alsa know we have play a period */
531 snd_pcm_period_elapsed(substream);
532 return pos;
533}
534
535static snd_pcm_uframes_t hsw_pcm_pointer(struct snd_pcm_substream *substream)
536{
537 struct snd_soc_pcm_runtime *rtd = substream->private_data;
538 struct snd_pcm_runtime *runtime = substream->runtime;
539 struct hsw_priv_data *pdata =
540 snd_soc_platform_get_drvdata(rtd->platform);
541 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
542 struct sst_hsw *hsw = pdata->hsw;
543 snd_pcm_uframes_t offset;
544
545 offset = bytes_to_frames(runtime,
546 sst_hsw_get_dsp_position(hsw, pcm_data->stream));
547
548 dev_dbg(rtd->dev, "PCM: DMA pointer %zu bytes\n",
549 frames_to_bytes(runtime, (u32)offset));
550 return offset;
551}
552
553static int hsw_pcm_open(struct snd_pcm_substream *substream)
554{
555 struct snd_soc_pcm_runtime *rtd = substream->private_data;
556 struct hsw_priv_data *pdata =
557 snd_soc_platform_get_drvdata(rtd->platform);
558 struct hsw_pcm_data *pcm_data;
559 struct sst_hsw *hsw = pdata->hsw;
560
561 pcm_data = &pdata->pcm[rtd->cpu_dai->id];
562
563 mutex_lock(&pcm_data->mutex);
564
565 snd_soc_pcm_set_drvdata(rtd, pcm_data);
566 pcm_data->substream = substream;
567
568 snd_soc_set_runtime_hwparams(substream, &hsw_pcm_hardware);
569
570 pcm_data->stream = sst_hsw_stream_new(hsw, rtd->cpu_dai->id,
571 hsw_notify_pointer, pcm_data);
572 if (pcm_data->stream == NULL) {
573 dev_err(rtd->dev, "error: failed to create stream\n");
574 mutex_unlock(&pcm_data->mutex);
575 return -EINVAL;
576 }
577
578 /* Set previous saved volume */
579 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
580 0, pcm_data->volume[0]);
581 sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
582 1, pcm_data->volume[1]);
583
584 mutex_unlock(&pcm_data->mutex);
585 return 0;
586}
587
588static int hsw_pcm_close(struct snd_pcm_substream *substream)
589{
590 struct snd_soc_pcm_runtime *rtd = substream->private_data;
591 struct hsw_priv_data *pdata =
592 snd_soc_platform_get_drvdata(rtd->platform);
593 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd);
594 struct sst_hsw *hsw = pdata->hsw;
595 int ret;
596
597 mutex_lock(&pcm_data->mutex);
598 ret = sst_hsw_stream_reset(hsw, pcm_data->stream);
599 if (ret < 0) {
600 dev_dbg(rtd->dev, "error: reset stream failed %d\n", ret);
601 goto out;
602 }
603
604 ret = sst_hsw_stream_free(hsw, pcm_data->stream);
605 if (ret < 0) {
606 dev_dbg(rtd->dev, "error: free stream failed %d\n", ret);
607 goto out;
608 }
609 pcm_data->stream = NULL;
610
611out:
612 mutex_unlock(&pcm_data->mutex);
613 return ret;
614}
615
616static struct snd_pcm_ops hsw_pcm_ops = {
617 .open = hsw_pcm_open,
618 .close = hsw_pcm_close,
619 .ioctl = snd_pcm_lib_ioctl,
620 .hw_params = hsw_pcm_hw_params,
621 .hw_free = hsw_pcm_hw_free,
622 .trigger = hsw_pcm_trigger,
623 .pointer = hsw_pcm_pointer,
624 .mmap = snd_pcm_lib_default_mmap,
625};
626
627static void hsw_pcm_free(struct snd_pcm *pcm)
628{
629 snd_pcm_lib_preallocate_free_for_all(pcm);
630}
631
632static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd)
633{
634 struct snd_pcm *pcm = rtd->pcm;
635 int ret = 0;
636
637 ret = dma_coerce_mask_and_coherent(rtd->card->dev, DMA_BIT_MASK(32));
638 if (ret)
639 return ret;
640
641 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream ||
642 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
643 ret = snd_pcm_lib_preallocate_pages_for_all(pcm,
644 SNDRV_DMA_TYPE_DEV,
645 rtd->card->dev,
646 hsw_pcm_hardware.buffer_bytes_max,
647 hsw_pcm_hardware.buffer_bytes_max);
648 if (ret) {
649 dev_err(rtd->dev, "dma buffer allocation failed %d\n",
650 ret);
651 return ret;
652 }
653 }
654
655 return ret;
656}
657
658#define HSW_FORMATS \
659 (SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S16_LE |\
660 SNDRV_PCM_FMTBIT_S32_LE)
661
662static struct snd_soc_dai_driver hsw_dais[] = {
663 {
664 .name = "System Pin",
665 .playback = {
666 .stream_name = "System Playback",
667 .channels_min = 2,
668 .channels_max = 2,
669 .rates = SNDRV_PCM_RATE_48000,
670 .formats = SNDRV_PCM_FMTBIT_S16_LE,
671 },
672 },
673 {
674 /* PCM */
675 .name = "Offload0 Pin",
676 .playback = {
677 .stream_name = "Offload0 Playback",
678 .channels_min = 2,
679 .channels_max = 2,
680 .rates = SNDRV_PCM_RATE_8000_192000,
681 .formats = HSW_FORMATS,
682 },
683 },
684 {
685 /* PCM */
686 .name = "Offload1 Pin",
687 .playback = {
688 .stream_name = "Offload1 Playback",
689 .channels_min = 2,
690 .channels_max = 2,
691 .rates = SNDRV_PCM_RATE_8000_192000,
692 .formats = HSW_FORMATS,
693 },
694 },
695 {
696 .name = "Loopback Pin",
697 .capture = {
698 .stream_name = "Loopback Capture",
699 .channels_min = 2,
700 .channels_max = 2,
701 .rates = SNDRV_PCM_RATE_8000_192000,
702 .formats = HSW_FORMATS,
703 },
704 },
705 {
706 .name = "Capture Pin",
707 .capture = {
708 .stream_name = "Analog Capture",
709 .channels_min = 2,
710 .channels_max = 2,
711 .rates = SNDRV_PCM_RATE_8000_192000,
712 .formats = HSW_FORMATS,
713 },
714 },
715};
716
717static const struct snd_soc_dapm_widget widgets[] = {
718
719 /* Backend DAIs */
720 SND_SOC_DAPM_AIF_IN("SSP0 CODEC IN", NULL, 0, SND_SOC_NOPM, 0, 0),
721 SND_SOC_DAPM_AIF_OUT("SSP0 CODEC OUT", NULL, 0, SND_SOC_NOPM, 0, 0),
722 SND_SOC_DAPM_AIF_IN("SSP1 BT IN", NULL, 0, SND_SOC_NOPM, 0, 0),
723 SND_SOC_DAPM_AIF_OUT("SSP1 BT OUT", NULL, 0, SND_SOC_NOPM, 0, 0),
724
725 /* Global Playback Mixer */
726 SND_SOC_DAPM_MIXER("Playback VMixer", SND_SOC_NOPM, 0, 0, NULL, 0),
727};
728
729static const struct snd_soc_dapm_route graph[] = {
730
731 /* Playback Mixer */
732 {"Playback VMixer", NULL, "System Playback"},
733 {"Playback VMixer", NULL, "Offload0 Playback"},
734 {"Playback VMixer", NULL, "Offload1 Playback"},
735
736 {"SSP0 CODEC OUT", NULL, "Playback VMixer"},
737
738 {"Analog Capture", NULL, "SSP0 CODEC IN"},
739};
740
741static int hsw_pcm_probe(struct snd_soc_platform *platform)
742{
743 struct sst_pdata *pdata = dev_get_platdata(platform->dev);
744 struct hsw_priv_data *priv_data;
745 int i;
746
747 if (!pdata)
748 return -ENODEV;
749
750 priv_data = devm_kzalloc(platform->dev, sizeof(*priv_data), GFP_KERNEL);
751 priv_data->hsw = pdata->dsp;
752 snd_soc_platform_set_drvdata(platform, priv_data);
753
754 /* allocate DSP buffer page tables */
755 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) {
756
757 mutex_init(&priv_data->pcm[i].mutex);
758
759 /* playback */
760 if (hsw_dais[i].playback.channels_min) {
761 priv_data->pcm_pg[i][0] = kzalloc(PAGE_SIZE, GFP_DMA);
762 if (priv_data->pcm_pg[i][0] == NULL)
763 goto err;
764 }
765
766 /* capture */
767 if (hsw_dais[i].capture.channels_min) {
768 priv_data->pcm_pg[i][1] = kzalloc(PAGE_SIZE, GFP_DMA);
769 if (priv_data->pcm_pg[i][1] == NULL)
770 goto err;
771 }
772 }
773
774 return 0;
775
776err:
777 for (;i >= 0; i--) {
778 if (hsw_dais[i].playback.channels_min)
779 kfree(priv_data->pcm_pg[i][0]);
780 if (hsw_dais[i].capture.channels_min)
781 kfree(priv_data->pcm_pg[i][1]);
782 }
783 return -ENOMEM;
784}
785
786static int hsw_pcm_remove(struct snd_soc_platform *platform)
787{
788 struct hsw_priv_data *priv_data =
789 snd_soc_platform_get_drvdata(platform);
790 int i;
791
792 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) {
793 if (hsw_dais[i].playback.channels_min)
794 kfree(priv_data->pcm_pg[i][0]);
795 if (hsw_dais[i].capture.channels_min)
796 kfree(priv_data->pcm_pg[i][1]);
797 }
798
799 return 0;
800}
801
802static struct snd_soc_platform_driver hsw_soc_platform = {
803 .probe = hsw_pcm_probe,
804 .remove = hsw_pcm_remove,
805 .ops = &hsw_pcm_ops,
806 .pcm_new = hsw_pcm_new,
807 .pcm_free = hsw_pcm_free,
808 .controls = hsw_volume_controls,
809 .num_controls = ARRAY_SIZE(hsw_volume_controls),
810 .dapm_widgets = widgets,
811 .num_dapm_widgets = ARRAY_SIZE(widgets),
812 .dapm_routes = graph,
813 .num_dapm_routes = ARRAY_SIZE(graph),
814};
815
816static const struct snd_soc_component_driver hsw_dai_component = {
817 .name = "haswell-dai",
818};
819
820static int hsw_pcm_dev_probe(struct platform_device *pdev)
821{
822 struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev);
823 int ret;
824
825 ret = sst_hsw_dsp_init(&pdev->dev, sst_pdata);
826 if (ret < 0)
827 return -ENODEV;
828
829 ret = snd_soc_register_platform(&pdev->dev, &hsw_soc_platform);
830 if (ret < 0)
831 goto err_plat;
832
833 ret = snd_soc_register_component(&pdev->dev, &hsw_dai_component,
834 hsw_dais, ARRAY_SIZE(hsw_dais));
835 if (ret < 0)
836 goto err_comp;
837
838 return 0;
839
840err_comp:
841 snd_soc_unregister_platform(&pdev->dev);
842err_plat:
843 sst_hsw_dsp_free(&pdev->dev, sst_pdata);
844 return 0;
845}
846
847static int hsw_pcm_dev_remove(struct platform_device *pdev)
848{
849 struct sst_pdata *sst_pdata = dev_get_platdata(&pdev->dev);
850
851 snd_soc_unregister_platform(&pdev->dev);
852 snd_soc_unregister_component(&pdev->dev);
853 sst_hsw_dsp_free(&pdev->dev, sst_pdata);
854
855 return 0;
856}
857
858static struct platform_driver hsw_pcm_driver = {
859 .driver = {
860 .name = "haswell-pcm-audio",
861 .owner = THIS_MODULE,
862 },
863
864 .probe = hsw_pcm_dev_probe,
865 .remove = hsw_pcm_dev_remove,
866};
867module_platform_driver(hsw_pcm_driver);
868
869MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
870MODULE_DESCRIPTION("Haswell/Lynxpoint + Broadwell/Wildcatpoint PCM");
871MODULE_LICENSE("GPL v2");
872MODULE_ALIAS("platform:haswell-pcm-audio");
diff --git a/sound/soc/intel/sst_dsp.h b/sound/soc/intel/sst-mfld-dsp.h
index 0fce1de284ff..3b63edc04b7f 100644
--- a/sound/soc/intel/sst_dsp.h
+++ b/sound/soc/intel/sst-mfld-dsp.h
@@ -1,7 +1,7 @@
1#ifndef __SST_DSP_H__ 1#ifndef __SST_MFLD_DSP_H__
2#define __SST_DSP_H__ 2#define __SST_MFLD_DSP_H__
3/* 3/*
4 * sst_dsp.h - Intel SST Driver for audio engine 4 * sst_mfld_dsp.h - Intel SST Driver for audio engine
5 * 5 *
6 * Copyright (C) 2008-12 Intel Corporation 6 * Copyright (C) 2008-12 Intel Corporation
7 * Authors: Vinod Koul <vinod.koul@linux.intel.com> 7 * Authors: Vinod Koul <vinod.koul@linux.intel.com>
@@ -131,4 +131,4 @@ struct snd_sst_params {
131 struct snd_sst_alloc_params_ext aparams; 131 struct snd_sst_alloc_params_ext aparams;
132}; 132};
133 133
134#endif /* __SST_DSP_H__ */ 134#endif /* __SST_MFLD_DSP_H__ */
diff --git a/sound/soc/intel/sst_platform.c b/sound/soc/intel/sst-mfld-platform.c
index f465a8180863..840306c2ef14 100644
--- a/sound/soc/intel/sst_platform.c
+++ b/sound/soc/intel/sst-mfld-platform.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * sst_platform.c - Intel MID Platform driver 2 * sst_mfld_platform.c - Intel MID Platform driver
3 * 3 *
4 * Copyright (C) 2010-2013 Intel Corp 4 * Copyright (C) 2010-2013 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com> 5 * Author: Vinod Koul <vinod.koul@intel.com>
@@ -33,7 +33,7 @@
33#include <sound/pcm_params.h> 33#include <sound/pcm_params.h>
34#include <sound/soc.h> 34#include <sound/soc.h>
35#include <sound/compress_driver.h> 35#include <sound/compress_driver.h>
36#include "sst_platform.h" 36#include "sst-mfld-platform.h"
37 37
38static struct sst_device *sst; 38static struct sst_device *sst;
39static DEFINE_MUTEX(sst_lock); 39static DEFINE_MUTEX(sst_lock);
@@ -709,7 +709,7 @@ static int sst_platform_remove(struct platform_device *pdev)
709 709
710static struct platform_driver sst_platform_driver = { 710static struct platform_driver sst_platform_driver = {
711 .driver = { 711 .driver = {
712 .name = "sst-platform", 712 .name = "sst-mfld-platform",
713 .owner = THIS_MODULE, 713 .owner = THIS_MODULE,
714 }, 714 },
715 .probe = sst_platform_probe, 715 .probe = sst_platform_probe,
@@ -722,4 +722,4 @@ MODULE_DESCRIPTION("ASoC Intel(R) MID Platform driver");
722MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>"); 722MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
723MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>"); 723MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
724MODULE_LICENSE("GPL v2"); 724MODULE_LICENSE("GPL v2");
725MODULE_ALIAS("platform:sst-platform"); 725MODULE_ALIAS("platform:sst-mfld-platform");
diff --git a/sound/soc/intel/sst_platform.h b/sound/soc/intel/sst-mfld-platform.h
index bee64fb7d2ef..0c4e2ddcecb1 100644
--- a/sound/soc/intel/sst_platform.h
+++ b/sound/soc/intel/sst-mfld-platform.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * sst_platform.h - Intel MID Platform driver header file 2 * sst_mfld_platform.h - Intel MID Platform driver header file
3 * 3 *
4 * Copyright (C) 2010 Intel Corp 4 * Copyright (C) 2010 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com> 5 * Author: Vinod Koul <vinod.koul@intel.com>
@@ -27,7 +27,7 @@
27#ifndef __SST_PLATFORMDRV_H__ 27#ifndef __SST_PLATFORMDRV_H__
28#define __SST_PLATFORMDRV_H__ 28#define __SST_PLATFORMDRV_H__
29 29
30#include "sst_dsp.h" 30#include "sst-mfld-dsp.h"
31 31
32#define SST_MONO 1 32#define SST_MONO 1
33#define SST_STEREO 2 33#define SST_STEREO 2
diff --git a/sound/soc/kirkwood/Kconfig b/sound/soc/kirkwood/Kconfig
index 78ed4a42ad21..49f8437665de 100644
--- a/sound/soc/kirkwood/Kconfig
+++ b/sound/soc/kirkwood/Kconfig
@@ -1,11 +1,20 @@
1config SND_KIRKWOOD_SOC 1config SND_KIRKWOOD_SOC
2 tristate "SoC Audio for the Marvell Kirkwood and Dove chips" 2 tristate "SoC Audio for the Marvell Kirkwood and Dove chips"
3 depends on ARCH_KIRKWOOD || ARCH_DOVE || COMPILE_TEST 3 depends on ARCH_KIRKWOOD || ARCH_DOVE || ARCH_MVEBU || COMPILE_TEST
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 Kirkwood I2S interface. You will also need to select the 6 the Kirkwood I2S interface. You will also need to select the
7 audio interfaces to support below. 7 audio interfaces to support below.
8 8
9config SND_KIRKWOOD_SOC_ARMADA370_DB
10 tristate "SoC Audio support for Armada 370 DB"
11 depends on SND_KIRKWOOD_SOC && (ARCH_MVEBU || COMPILE_TEST) && I2C
12 select SND_SOC_CS42L51
13 select SND_SOC_SPDIF
14 help
15 Say Y if you want to add support for SoC audio on
16 the Armada 370 Development Board.
17
9config SND_KIRKWOOD_SOC_OPENRD 18config SND_KIRKWOOD_SOC_OPENRD
10 tristate "SoC Audio support for Kirkwood Openrd Client" 19 tristate "SoC Audio support for Kirkwood Openrd Client"
11 depends on SND_KIRKWOOD_SOC && (MACH_OPENRD_CLIENT || MACH_OPENRD_ULTIMATE || COMPILE_TEST) 20 depends on SND_KIRKWOOD_SOC && (MACH_OPENRD_CLIENT || MACH_OPENRD_ULTIMATE || COMPILE_TEST)
diff --git a/sound/soc/kirkwood/Makefile b/sound/soc/kirkwood/Makefile
index 9e781385cb88..7c1d8fe09e6b 100644
--- a/sound/soc/kirkwood/Makefile
+++ b/sound/soc/kirkwood/Makefile
@@ -4,6 +4,8 @@ obj-$(CONFIG_SND_KIRKWOOD_SOC) += snd-soc-kirkwood.o
4 4
5snd-soc-openrd-objs := kirkwood-openrd.o 5snd-soc-openrd-objs := kirkwood-openrd.o
6snd-soc-t5325-objs := kirkwood-t5325.o 6snd-soc-t5325-objs := kirkwood-t5325.o
7snd-soc-armada-370-db-objs := armada-370-db.o
7 8
9obj-$(CONFIG_SND_KIRKWOOD_SOC_ARMADA370_DB) += snd-soc-armada-370-db.o
8obj-$(CONFIG_SND_KIRKWOOD_SOC_OPENRD) += snd-soc-openrd.o 10obj-$(CONFIG_SND_KIRKWOOD_SOC_OPENRD) += snd-soc-openrd.o
9obj-$(CONFIG_SND_KIRKWOOD_SOC_T5325) += snd-soc-t5325.o 11obj-$(CONFIG_SND_KIRKWOOD_SOC_T5325) += snd-soc-t5325.o
diff --git a/sound/soc/kirkwood/armada-370-db.c b/sound/soc/kirkwood/armada-370-db.c
new file mode 100644
index 000000000000..c44333849259
--- /dev/null
+++ b/sound/soc/kirkwood/armada-370-db.c
@@ -0,0 +1,148 @@
1/*
2 * Copyright (C) 2014 Marvell
3 *
4 * Thomas Petazzoni <thomas.petazzoni@free-electrons.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 as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/interrupt.h>
15#include <linux/platform_device.h>
16#include <linux/slab.h>
17#include <sound/soc.h>
18#include <linux/of.h>
19#include <linux/platform_data/asoc-kirkwood.h>
20#include "../codecs/cs42l51.h"
21
22static int a370db_hw_params(struct snd_pcm_substream *substream,
23 struct snd_pcm_hw_params *params)
24{
25 struct snd_soc_pcm_runtime *rtd = substream->private_data;
26 struct snd_soc_dai *codec_dai = rtd->codec_dai;
27 unsigned int freq;
28
29 switch (params_rate(params)) {
30 default:
31 case 44100:
32 freq = 11289600;
33 break;
34 case 48000:
35 freq = 12288000;
36 break;
37 case 96000:
38 freq = 24576000;
39 break;
40 }
41
42 return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);
43}
44
45static struct snd_soc_ops a370db_ops = {
46 .hw_params = a370db_hw_params,
47};
48
49static const struct snd_soc_dapm_widget a370db_dapm_widgets[] = {
50 SND_SOC_DAPM_HP("Out Jack", NULL),
51 SND_SOC_DAPM_LINE("In Jack", NULL),
52};
53
54static const struct snd_soc_dapm_route a370db_route[] = {
55 { "Out Jack", NULL, "HPL" },
56 { "Out Jack", NULL, "HPR" },
57 { "AIN1L", NULL, "In Jack" },
58 { "AIN1L", NULL, "In Jack" },
59};
60
61static struct snd_soc_dai_link a370db_dai[] = {
62{
63 .name = "CS42L51",
64 .stream_name = "analog",
65 .cpu_dai_name = "i2s",
66 .codec_dai_name = "cs42l51-hifi",
67 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS,
68 .ops = &a370db_ops,
69},
70{
71 .name = "S/PDIF out",
72 .stream_name = "spdif-out",
73 .cpu_dai_name = "spdif",
74 .codec_dai_name = "dit-hifi",
75 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS,
76},
77{
78 .name = "S/PDIF in",
79 .stream_name = "spdif-in",
80 .cpu_dai_name = "spdif",
81 .codec_dai_name = "dir-hifi",
82 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS,
83},
84};
85
86static struct snd_soc_card a370db = {
87 .name = "a370db",
88 .owner = THIS_MODULE,
89 .dai_link = a370db_dai,
90 .num_links = ARRAY_SIZE(a370db_dai),
91 .dapm_widgets = a370db_dapm_widgets,
92 .num_dapm_widgets = ARRAY_SIZE(a370db_dapm_widgets),
93 .dapm_routes = a370db_route,
94 .num_dapm_routes = ARRAY_SIZE(a370db_route),
95};
96
97static int a370db_probe(struct platform_device *pdev)
98{
99 struct snd_soc_card *card = &a370db;
100
101 card->dev = &pdev->dev;
102
103 a370db_dai[0].cpu_of_node =
104 of_parse_phandle(pdev->dev.of_node,
105 "marvell,audio-controller", 0);
106 a370db_dai[0].platform_of_node = a370db_dai[0].cpu_of_node;
107
108 a370db_dai[0].codec_of_node =
109 of_parse_phandle(pdev->dev.of_node,
110 "marvell,audio-codec", 0);
111
112 a370db_dai[1].cpu_of_node = a370db_dai[0].cpu_of_node;
113 a370db_dai[1].platform_of_node = a370db_dai[0].cpu_of_node;
114
115 a370db_dai[1].codec_of_node =
116 of_parse_phandle(pdev->dev.of_node,
117 "marvell,audio-codec", 1);
118
119 a370db_dai[2].cpu_of_node = a370db_dai[0].cpu_of_node;
120 a370db_dai[2].platform_of_node = a370db_dai[0].cpu_of_node;
121
122 a370db_dai[2].codec_of_node =
123 of_parse_phandle(pdev->dev.of_node,
124 "marvell,audio-codec", 2);
125
126 return devm_snd_soc_register_card(card->dev, card);
127}
128
129static const struct of_device_id a370db_dt_ids[] = {
130 { .compatible = "marvell,a370db-audio" },
131 { },
132};
133
134static struct platform_driver a370db_driver = {
135 .driver = {
136 .name = "a370db-audio",
137 .owner = THIS_MODULE,
138 .of_match_table = of_match_ptr(a370db_dt_ids),
139 },
140 .probe = a370db_probe,
141};
142
143module_platform_driver(a370db_driver);
144
145MODULE_AUTHOR("Thomas Petazzoni <thomas.petazzoni@free-electrons.com>");
146MODULE_DESCRIPTION("ALSA SoC a370db audio client");
147MODULE_LICENSE("GPL");
148MODULE_ALIAS("platform:a370db-audio");
diff --git a/sound/soc/kirkwood/kirkwood-i2s.c b/sound/soc/kirkwood/kirkwood-i2s.c
index 3920a5e8125f..9f842222e798 100644
--- a/sound/soc/kirkwood/kirkwood-i2s.c
+++ b/sound/soc/kirkwood/kirkwood-i2s.c
@@ -633,6 +633,7 @@ static int kirkwood_i2s_dev_remove(struct platform_device *pdev)
633static struct of_device_id mvebu_audio_of_match[] = { 633static struct of_device_id mvebu_audio_of_match[] = {
634 { .compatible = "marvell,kirkwood-audio" }, 634 { .compatible = "marvell,kirkwood-audio" },
635 { .compatible = "marvell,dove-audio" }, 635 { .compatible = "marvell,dove-audio" },
636 { .compatible = "marvell,armada370-audio" },
636 { } 637 { }
637}; 638};
638MODULE_DEVICE_TABLE(of, mvebu_audio_of_match); 639MODULE_DEVICE_TABLE(of, mvebu_audio_of_match);
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
index 22ad9c5654b5..e00659351a4e 100644
--- a/sound/soc/omap/Kconfig
+++ b/sound/soc/omap/Kconfig
@@ -58,7 +58,7 @@ config SND_OMAP_SOC_OSK5912
58 tristate "SoC Audio support for omap osk5912" 58 tristate "SoC Audio support for omap osk5912"
59 depends on SND_OMAP_SOC && MACH_OMAP_OSK && I2C 59 depends on SND_OMAP_SOC && MACH_OMAP_OSK && I2C
60 select SND_OMAP_SOC_MCBSP 60 select SND_OMAP_SOC_MCBSP
61 select SND_SOC_TLV320AIC23 61 select SND_SOC_TLV320AIC23_I2C
62 help 62 help
63 Say Y if you want to add support for SoC audio on osk5912. 63 Say Y if you want to add support for SoC audio on osk5912.
64 64
@@ -66,7 +66,7 @@ config SND_OMAP_SOC_AM3517EVM
66 tristate "SoC Audio support for OMAP3517 / AM3517 EVM" 66 tristate "SoC Audio support for OMAP3517 / AM3517 EVM"
67 depends on SND_OMAP_SOC && MACH_OMAP3517EVM && I2C 67 depends on SND_OMAP_SOC && MACH_OMAP3517EVM && I2C
68 select SND_OMAP_SOC_MCBSP 68 select SND_OMAP_SOC_MCBSP
69 select SND_SOC_TLV320AIC23 69 select SND_SOC_TLV320AIC23_I2C
70 help 70 help
71 Say Y if you want to add support for SoC audio on the OMAP3517 / AM3517 71 Say Y if you want to add support for SoC audio on the OMAP3517 / AM3517
72 EVM. 72 EVM.
diff --git a/sound/soc/omap/ams-delta.c b/sound/soc/omap/ams-delta.c
index 629446482a91..56a5219c0a00 100644
--- a/sound/soc/omap/ams-delta.c
+++ b/sound/soc/omap/ams-delta.c
@@ -103,60 +103,62 @@ static int ams_delta_set_audio_mode(struct snd_kcontrol *kcontrol,
103 if (!codec->hw_write) 103 if (!codec->hw_write)
104 return -EUNATCH; 104 return -EUNATCH;
105 105
106 if (ucontrol->value.enumerated.item[0] >= control->max) 106 if (ucontrol->value.enumerated.item[0] >= control->items)
107 return -EINVAL; 107 return -EINVAL;
108 108
109 mutex_lock(&codec->mutex); 109 snd_soc_dapm_mutex_lock(dapm);
110 110
111 /* Translate selection to bitmap */ 111 /* Translate selection to bitmap */
112 pins = ams_delta_audio_mode_pins[ucontrol->value.enumerated.item[0]]; 112 pins = ams_delta_audio_mode_pins[ucontrol->value.enumerated.item[0]];
113 113
114 /* Setup pins after corresponding bits if changed */ 114 /* Setup pins after corresponding bits if changed */
115 pin = !!(pins & (1 << AMS_DELTA_MOUTHPIECE)); 115 pin = !!(pins & (1 << AMS_DELTA_MOUTHPIECE));
116
116 if (pin != snd_soc_dapm_get_pin_status(dapm, "Mouthpiece")) { 117 if (pin != snd_soc_dapm_get_pin_status(dapm, "Mouthpiece")) {
117 changed = 1; 118 changed = 1;
118 if (pin) 119 if (pin)
119 snd_soc_dapm_enable_pin(dapm, "Mouthpiece"); 120 snd_soc_dapm_enable_pin_unlocked(dapm, "Mouthpiece");
120 else 121 else
121 snd_soc_dapm_disable_pin(dapm, "Mouthpiece"); 122 snd_soc_dapm_disable_pin_unlocked(dapm, "Mouthpiece");
122 } 123 }
123 pin = !!(pins & (1 << AMS_DELTA_EARPIECE)); 124 pin = !!(pins & (1 << AMS_DELTA_EARPIECE));
124 if (pin != snd_soc_dapm_get_pin_status(dapm, "Earpiece")) { 125 if (pin != snd_soc_dapm_get_pin_status(dapm, "Earpiece")) {
125 changed = 1; 126 changed = 1;
126 if (pin) 127 if (pin)
127 snd_soc_dapm_enable_pin(dapm, "Earpiece"); 128 snd_soc_dapm_enable_pin_unlocked(dapm, "Earpiece");
128 else 129 else
129 snd_soc_dapm_disable_pin(dapm, "Earpiece"); 130 snd_soc_dapm_disable_pin_unlocked(dapm, "Earpiece");
130 } 131 }
131 pin = !!(pins & (1 << AMS_DELTA_MICROPHONE)); 132 pin = !!(pins & (1 << AMS_DELTA_MICROPHONE));
132 if (pin != snd_soc_dapm_get_pin_status(dapm, "Microphone")) { 133 if (pin != snd_soc_dapm_get_pin_status(dapm, "Microphone")) {
133 changed = 1; 134 changed = 1;
134 if (pin) 135 if (pin)
135 snd_soc_dapm_enable_pin(dapm, "Microphone"); 136 snd_soc_dapm_enable_pin_unlocked(dapm, "Microphone");
136 else 137 else
137 snd_soc_dapm_disable_pin(dapm, "Microphone"); 138 snd_soc_dapm_disable_pin_unlocked(dapm, "Microphone");
138 } 139 }
139 pin = !!(pins & (1 << AMS_DELTA_SPEAKER)); 140 pin = !!(pins & (1 << AMS_DELTA_SPEAKER));
140 if (pin != snd_soc_dapm_get_pin_status(dapm, "Speaker")) { 141 if (pin != snd_soc_dapm_get_pin_status(dapm, "Speaker")) {
141 changed = 1; 142 changed = 1;
142 if (pin) 143 if (pin)
143 snd_soc_dapm_enable_pin(dapm, "Speaker"); 144 snd_soc_dapm_enable_pin_unlocked(dapm, "Speaker");
144 else 145 else
145 snd_soc_dapm_disable_pin(dapm, "Speaker"); 146 snd_soc_dapm_disable_pin_unlocked(dapm, "Speaker");
146 } 147 }
147 pin = !!(pins & (1 << AMS_DELTA_AGC)); 148 pin = !!(pins & (1 << AMS_DELTA_AGC));
148 if (pin != ams_delta_audio_agc) { 149 if (pin != ams_delta_audio_agc) {
149 ams_delta_audio_agc = pin; 150 ams_delta_audio_agc = pin;
150 changed = 1; 151 changed = 1;
151 if (pin) 152 if (pin)
152 snd_soc_dapm_enable_pin(dapm, "AGCIN"); 153 snd_soc_dapm_enable_pin_unlocked(dapm, "AGCIN");
153 else 154 else
154 snd_soc_dapm_disable_pin(dapm, "AGCIN"); 155 snd_soc_dapm_disable_pin_unlocked(dapm, "AGCIN");
155 } 156 }
157
156 if (changed) 158 if (changed)
157 snd_soc_dapm_sync(dapm); 159 snd_soc_dapm_sync_unlocked(dapm);
158 160
159 mutex_unlock(&codec->mutex); 161 snd_soc_dapm_mutex_unlock(dapm);
160 162
161 return changed; 163 return changed;
162} 164}
@@ -194,13 +196,11 @@ static int ams_delta_get_audio_mode(struct snd_kcontrol *kcontrol,
194 return 0; 196 return 0;
195} 197}
196 198
197static const struct soc_enum ams_delta_audio_enum[] = { 199static const SOC_ENUM_SINGLE_EXT_DECL(ams_delta_audio_enum,
198 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(ams_delta_audio_mode), 200 ams_delta_audio_mode);
199 ams_delta_audio_mode),
200};
201 201
202static const struct snd_kcontrol_new ams_delta_audio_controls[] = { 202static const struct snd_kcontrol_new ams_delta_audio_controls[] = {
203 SOC_ENUM_EXT("Audio Mode", ams_delta_audio_enum[0], 203 SOC_ENUM_EXT("Audio Mode", ams_delta_audio_enum,
204 ams_delta_get_audio_mode, ams_delta_set_audio_mode), 204 ams_delta_get_audio_mode, ams_delta_set_audio_mode),
205}; 205};
206 206
@@ -315,12 +315,17 @@ static void cx81801_close(struct tty_struct *tty)
315 v253_ops.close(tty); 315 v253_ops.close(tty);
316 316
317 /* Revert back to default audio input/output constellation */ 317 /* Revert back to default audio input/output constellation */
318 snd_soc_dapm_disable_pin(dapm, "Mouthpiece"); 318 snd_soc_dapm_mutex_lock(dapm);
319 snd_soc_dapm_enable_pin(dapm, "Earpiece"); 319
320 snd_soc_dapm_enable_pin(dapm, "Microphone"); 320 snd_soc_dapm_disable_pin_unlocked(dapm, "Mouthpiece");
321 snd_soc_dapm_disable_pin(dapm, "Speaker"); 321 snd_soc_dapm_enable_pin_unlocked(dapm, "Earpiece");
322 snd_soc_dapm_disable_pin(dapm, "AGCIN"); 322 snd_soc_dapm_enable_pin_unlocked(dapm, "Microphone");
323 snd_soc_dapm_sync(dapm); 323 snd_soc_dapm_disable_pin_unlocked(dapm, "Speaker");
324 snd_soc_dapm_disable_pin_unlocked(dapm, "AGCIN");
325
326 snd_soc_dapm_sync_unlocked(dapm);
327
328 snd_soc_dapm_mutex_unlock(dapm);
324} 329}
325 330
326/* Line discipline .hangup() */ 331/* Line discipline .hangup() */
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c
index d163e18d85d4..fd4d9c809e50 100644
--- a/sound/soc/omap/n810.c
+++ b/sound/soc/omap/n810.c
@@ -68,26 +68,30 @@ static void n810_ext_control(struct snd_soc_dapm_context *dapm)
68 break; 68 break;
69 } 69 }
70 70
71 snd_soc_dapm_mutex_lock(dapm);
72
71 if (n810_spk_func) 73 if (n810_spk_func)
72 snd_soc_dapm_enable_pin(dapm, "Ext Spk"); 74 snd_soc_dapm_enable_pin_unlocked(dapm, "Ext Spk");
73 else 75 else
74 snd_soc_dapm_disable_pin(dapm, "Ext Spk"); 76 snd_soc_dapm_disable_pin_unlocked(dapm, "Ext Spk");
75 77
76 if (hp) 78 if (hp)
77 snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); 79 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
78 else 80 else
79 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 81 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
80 if (line1l) 82 if (line1l)
81 snd_soc_dapm_enable_pin(dapm, "LINE1L"); 83 snd_soc_dapm_enable_pin_unlocked(dapm, "LINE1L");
82 else 84 else
83 snd_soc_dapm_disable_pin(dapm, "LINE1L"); 85 snd_soc_dapm_disable_pin_unlocked(dapm, "LINE1L");
84 86
85 if (n810_dmic_func) 87 if (n810_dmic_func)
86 snd_soc_dapm_enable_pin(dapm, "DMic"); 88 snd_soc_dapm_enable_pin_unlocked(dapm, "DMic");
87 else 89 else
88 snd_soc_dapm_disable_pin(dapm, "DMic"); 90 snd_soc_dapm_disable_pin_unlocked(dapm, "DMic");
91
92 snd_soc_dapm_sync_unlocked(dapm);
89 93
90 snd_soc_dapm_sync(dapm); 94 snd_soc_dapm_mutex_unlock(dapm);
91} 95}
92 96
93static int n810_startup(struct snd_pcm_substream *substream) 97static int n810_startup(struct snd_pcm_substream *substream)
diff --git a/sound/soc/omap/omap-abe-twl6040.c b/sound/soc/omap/omap-abe-twl6040.c
index ebb13906b3a0..024dafc3e298 100644
--- a/sound/soc/omap/omap-abe-twl6040.c
+++ b/sound/soc/omap/omap-abe-twl6040.c
@@ -203,8 +203,7 @@ static const struct snd_soc_dapm_route dmic_audio_map[] = {
203 203
204static int omap_abe_dmic_init(struct snd_soc_pcm_runtime *rtd) 204static int omap_abe_dmic_init(struct snd_soc_pcm_runtime *rtd)
205{ 205{
206 struct snd_soc_codec *codec = rtd->codec; 206 struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
207 struct snd_soc_dapm_context *dapm = &codec->dapm;
208 207
209 return snd_soc_dapm_add_routes(dapm, dmic_audio_map, 208 return snd_soc_dapm_add_routes(dapm, dmic_audio_map,
210 ARRAY_SIZE(dmic_audio_map)); 209 ARRAY_SIZE(dmic_audio_map));
diff --git a/sound/soc/omap/rx51.c b/sound/soc/omap/rx51.c
index 611179c3bca4..7fb3d4b10370 100644
--- a/sound/soc/omap/rx51.c
+++ b/sound/soc/omap/rx51.c
@@ -74,26 +74,30 @@ static void rx51_ext_control(struct snd_soc_dapm_context *dapm)
74 break; 74 break;
75 } 75 }
76 76
77 snd_soc_dapm_mutex_lock(dapm);
78
77 if (rx51_spk_func) 79 if (rx51_spk_func)
78 snd_soc_dapm_enable_pin(dapm, "Ext Spk"); 80 snd_soc_dapm_enable_pin_unlocked(dapm, "Ext Spk");
79 else 81 else
80 snd_soc_dapm_disable_pin(dapm, "Ext Spk"); 82 snd_soc_dapm_disable_pin_unlocked(dapm, "Ext Spk");
81 if (rx51_dmic_func) 83 if (rx51_dmic_func)
82 snd_soc_dapm_enable_pin(dapm, "DMic"); 84 snd_soc_dapm_enable_pin_unlocked(dapm, "DMic");
83 else 85 else
84 snd_soc_dapm_disable_pin(dapm, "DMic"); 86 snd_soc_dapm_disable_pin_unlocked(dapm, "DMic");
85 if (hp) 87 if (hp)
86 snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); 88 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
87 else 89 else
88 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 90 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
89 if (hs) 91 if (hs)
90 snd_soc_dapm_enable_pin(dapm, "HS Mic"); 92 snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic");
91 else 93 else
92 snd_soc_dapm_disable_pin(dapm, "HS Mic"); 94 snd_soc_dapm_disable_pin_unlocked(dapm, "HS Mic");
93 95
94 gpio_set_value(RX51_TVOUT_SEL_GPIO, tvout); 96 gpio_set_value(RX51_TVOUT_SEL_GPIO, tvout);
95 97
96 snd_soc_dapm_sync(dapm); 98 snd_soc_dapm_sync_unlocked(dapm);
99
100 snd_soc_dapm_mutex_unlock(dapm);
97} 101}
98 102
99static int rx51_startup(struct snd_pcm_substream *substream) 103static int rx51_startup(struct snd_pcm_substream *substream)
diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c
index 1853d41034bf..5a88136aa800 100644
--- a/sound/soc/pxa/corgi.c
+++ b/sound/soc/pxa/corgi.c
@@ -47,64 +47,63 @@ static int corgi_spk_func;
47 47
48static void corgi_ext_control(struct snd_soc_dapm_context *dapm) 48static void corgi_ext_control(struct snd_soc_dapm_context *dapm)
49{ 49{
50 snd_soc_dapm_mutex_lock(dapm);
51
50 /* set up jack connection */ 52 /* set up jack connection */
51 switch (corgi_jack_func) { 53 switch (corgi_jack_func) {
52 case CORGI_HP: 54 case CORGI_HP:
53 /* set = unmute headphone */ 55 /* set = unmute headphone */
54 gpio_set_value(CORGI_GPIO_MUTE_L, 1); 56 gpio_set_value(CORGI_GPIO_MUTE_L, 1);
55 gpio_set_value(CORGI_GPIO_MUTE_R, 1); 57 gpio_set_value(CORGI_GPIO_MUTE_R, 1);
56 snd_soc_dapm_disable_pin(dapm, "Mic Jack"); 58 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
57 snd_soc_dapm_disable_pin(dapm, "Line Jack"); 59 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
58 snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); 60 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
59 snd_soc_dapm_disable_pin(dapm, "Headset Jack"); 61 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
60 break; 62 break;
61 case CORGI_MIC: 63 case CORGI_MIC:
62 /* reset = mute headphone */ 64 /* reset = mute headphone */
63 gpio_set_value(CORGI_GPIO_MUTE_L, 0); 65 gpio_set_value(CORGI_GPIO_MUTE_L, 0);
64 gpio_set_value(CORGI_GPIO_MUTE_R, 0); 66 gpio_set_value(CORGI_GPIO_MUTE_R, 0);
65 snd_soc_dapm_enable_pin(dapm, "Mic Jack"); 67 snd_soc_dapm_enable_pin_unlocked(dapm, "Mic Jack");
66 snd_soc_dapm_disable_pin(dapm, "Line Jack"); 68 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
67 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 69 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
68 snd_soc_dapm_disable_pin(dapm, "Headset Jack"); 70 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
69 break; 71 break;
70 case CORGI_LINE: 72 case CORGI_LINE:
71 gpio_set_value(CORGI_GPIO_MUTE_L, 0); 73 gpio_set_value(CORGI_GPIO_MUTE_L, 0);
72 gpio_set_value(CORGI_GPIO_MUTE_R, 0); 74 gpio_set_value(CORGI_GPIO_MUTE_R, 0);
73 snd_soc_dapm_disable_pin(dapm, "Mic Jack"); 75 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
74 snd_soc_dapm_enable_pin(dapm, "Line Jack"); 76 snd_soc_dapm_enable_pin_unlocked(dapm, "Line Jack");
75 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 77 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
76 snd_soc_dapm_disable_pin(dapm, "Headset Jack"); 78 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
77 break; 79 break;
78 case CORGI_HEADSET: 80 case CORGI_HEADSET:
79 gpio_set_value(CORGI_GPIO_MUTE_L, 0); 81 gpio_set_value(CORGI_GPIO_MUTE_L, 0);
80 gpio_set_value(CORGI_GPIO_MUTE_R, 1); 82 gpio_set_value(CORGI_GPIO_MUTE_R, 1);
81 snd_soc_dapm_enable_pin(dapm, "Mic Jack"); 83 snd_soc_dapm_enable_pin_unlocked(dapm, "Mic Jack");
82 snd_soc_dapm_disable_pin(dapm, "Line Jack"); 84 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
83 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 85 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
84 snd_soc_dapm_enable_pin(dapm, "Headset Jack"); 86 snd_soc_dapm_enable_pin_unlocked(dapm, "Headset Jack");
85 break; 87 break;
86 } 88 }
87 89
88 if (corgi_spk_func == CORGI_SPK_ON) 90 if (corgi_spk_func == CORGI_SPK_ON)
89 snd_soc_dapm_enable_pin(dapm, "Ext Spk"); 91 snd_soc_dapm_enable_pin_unlocked(dapm, "Ext Spk");
90 else 92 else
91 snd_soc_dapm_disable_pin(dapm, "Ext Spk"); 93 snd_soc_dapm_disable_pin_unlocked(dapm, "Ext Spk");
92 94
93 /* signal a DAPM event */ 95 /* signal a DAPM event */
94 snd_soc_dapm_sync(dapm); 96 snd_soc_dapm_sync_unlocked(dapm);
97
98 snd_soc_dapm_mutex_unlock(dapm);
95} 99}
96 100
97static int corgi_startup(struct snd_pcm_substream *substream) 101static int corgi_startup(struct snd_pcm_substream *substream)
98{ 102{
99 struct snd_soc_pcm_runtime *rtd = substream->private_data; 103 struct snd_soc_pcm_runtime *rtd = substream->private_data;
100 struct snd_soc_codec *codec = rtd->codec;
101
102 mutex_lock(&codec->mutex);
103 104
104 /* check the jack status at stream startup */ 105 /* check the jack status at stream startup */
105 corgi_ext_control(&codec->dapm); 106 corgi_ext_control(&rtd->card->dapm);
106
107 mutex_unlock(&codec->mutex);
108 107
109 return 0; 108 return 0;
110} 109}
diff --git a/sound/soc/pxa/e740_wm9705.c b/sound/soc/pxa/e740_wm9705.c
index 44b5c09d296b..c29fedab2f49 100644
--- a/sound/soc/pxa/e740_wm9705.c
+++ b/sound/soc/pxa/e740_wm9705.c
@@ -103,11 +103,6 @@ static int e740_ac97_init(struct snd_soc_pcm_runtime *rtd)
103 snd_soc_dapm_nc_pin(dapm, "PCBEEP"); 103 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
104 snd_soc_dapm_nc_pin(dapm, "MIC2"); 104 snd_soc_dapm_nc_pin(dapm, "MIC2");
105 105
106 snd_soc_dapm_new_controls(dapm, e740_dapm_widgets,
107 ARRAY_SIZE(e740_dapm_widgets));
108
109 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
110
111 return 0; 106 return 0;
112} 107}
113 108
@@ -136,6 +131,11 @@ static struct snd_soc_card e740 = {
136 .owner = THIS_MODULE, 131 .owner = THIS_MODULE,
137 .dai_link = e740_dai, 132 .dai_link = e740_dai,
138 .num_links = ARRAY_SIZE(e740_dai), 133 .num_links = ARRAY_SIZE(e740_dai),
134
135 .dapm_widgets = e740_dapm_widgets,
136 .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets),
137 .dapm_routes = audio_map,
138 .num_dapm_routes = ARRAY_SIZE(audio_map),
139}; 139};
140 140
141static struct gpio e740_audio_gpios[] = { 141static struct gpio e740_audio_gpios[] = {
diff --git a/sound/soc/pxa/e750_wm9705.c b/sound/soc/pxa/e750_wm9705.c
index c34e447eb991..ee36aba88063 100644
--- a/sound/soc/pxa/e750_wm9705.c
+++ b/sound/soc/pxa/e750_wm9705.c
@@ -85,11 +85,6 @@ static int e750_ac97_init(struct snd_soc_pcm_runtime *rtd)
85 snd_soc_dapm_nc_pin(dapm, "PCBEEP"); 85 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
86 snd_soc_dapm_nc_pin(dapm, "MIC2"); 86 snd_soc_dapm_nc_pin(dapm, "MIC2");
87 87
88 snd_soc_dapm_new_controls(dapm, e750_dapm_widgets,
89 ARRAY_SIZE(e750_dapm_widgets));
90
91 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
92
93 return 0; 88 return 0;
94} 89}
95 90
@@ -119,6 +114,11 @@ static struct snd_soc_card e750 = {
119 .owner = THIS_MODULE, 114 .owner = THIS_MODULE,
120 .dai_link = e750_dai, 115 .dai_link = e750_dai,
121 .num_links = ARRAY_SIZE(e750_dai), 116 .num_links = ARRAY_SIZE(e750_dai),
117
118 .dapm_widgets = e750_dapm_widgets,
119 .num_dapm_widgets = ARRAY_SIZE(e750_dapm_widgets),
120 .dapm_routes = audio_map,
121 .num_dapm_routes = ARRAY_SIZE(audio_map),
122}; 122};
123 123
124static struct gpio e750_audio_gpios[] = { 124static struct gpio e750_audio_gpios[] = {
diff --git a/sound/soc/pxa/e800_wm9712.c b/sound/soc/pxa/e800_wm9712.c
index 3137f800b43f..24c2078ce70b 100644
--- a/sound/soc/pxa/e800_wm9712.c
+++ b/sound/soc/pxa/e800_wm9712.c
@@ -71,19 +71,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
71 {"MIC2", NULL, "Mic (Internal2)"}, 71 {"MIC2", NULL, "Mic (Internal2)"},
72}; 72};
73 73
74static int e800_ac97_init(struct snd_soc_pcm_runtime *rtd)
75{
76 struct snd_soc_codec *codec = rtd->codec;
77 struct snd_soc_dapm_context *dapm = &codec->dapm;
78
79 snd_soc_dapm_new_controls(dapm, e800_dapm_widgets,
80 ARRAY_SIZE(e800_dapm_widgets));
81
82 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
83
84 return 0;
85}
86
87static struct snd_soc_dai_link e800_dai[] = { 74static struct snd_soc_dai_link e800_dai[] = {
88 { 75 {
89 .name = "AC97", 76 .name = "AC97",
@@ -92,7 +79,6 @@ static struct snd_soc_dai_link e800_dai[] = {
92 .codec_dai_name = "wm9712-hifi", 79 .codec_dai_name = "wm9712-hifi",
93 .platform_name = "pxa-pcm-audio", 80 .platform_name = "pxa-pcm-audio",
94 .codec_name = "wm9712-codec", 81 .codec_name = "wm9712-codec",
95 .init = e800_ac97_init,
96 }, 82 },
97 { 83 {
98 .name = "AC97 Aux", 84 .name = "AC97 Aux",
@@ -109,6 +95,11 @@ static struct snd_soc_card e800 = {
109 .owner = THIS_MODULE, 95 .owner = THIS_MODULE,
110 .dai_link = e800_dai, 96 .dai_link = e800_dai,
111 .num_links = ARRAY_SIZE(e800_dai), 97 .num_links = ARRAY_SIZE(e800_dai),
98
99 .dapm_widgets = e800_dapm_widgets,
100 .num_dapm_widgets = ARRAY_SIZE(e800_dapm_widgets),
101 .dapm_routes = audio_map,
102 .num_dapm_routes = ARRAY_SIZE(audio_map),
112}; 103};
113 104
114static struct gpio e800_audio_gpios[] = { 105static struct gpio e800_audio_gpios[] = {
diff --git a/sound/soc/pxa/magician.c b/sound/soc/pxa/magician.c
index aace19e0fe2c..259e048681c0 100644
--- a/sound/soc/pxa/magician.c
+++ b/sound/soc/pxa/magician.c
@@ -41,44 +41,42 @@ static int magician_hp_switch;
41static int magician_spk_switch = 1; 41static int magician_spk_switch = 1;
42static int magician_in_sel = MAGICIAN_MIC; 42static int magician_in_sel = MAGICIAN_MIC;
43 43
44static void magician_ext_control(struct snd_soc_codec *codec) 44static void magician_ext_control(struct snd_soc_dapm_context *dapm)
45{ 45{
46 struct snd_soc_dapm_context *dapm = &codec->dapm; 46
47 snd_soc_dapm_mutex_lock(dapm);
47 48
48 if (magician_spk_switch) 49 if (magician_spk_switch)
49 snd_soc_dapm_enable_pin(dapm, "Speaker"); 50 snd_soc_dapm_enable_pin_unlocked(dapm, "Speaker");
50 else 51 else
51 snd_soc_dapm_disable_pin(dapm, "Speaker"); 52 snd_soc_dapm_disable_pin_unlocked(dapm, "Speaker");
52 if (magician_hp_switch) 53 if (magician_hp_switch)
53 snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); 54 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
54 else 55 else
55 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 56 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
56 57
57 switch (magician_in_sel) { 58 switch (magician_in_sel) {
58 case MAGICIAN_MIC: 59 case MAGICIAN_MIC:
59 snd_soc_dapm_disable_pin(dapm, "Headset Mic"); 60 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Mic");
60 snd_soc_dapm_enable_pin(dapm, "Call Mic"); 61 snd_soc_dapm_enable_pin_unlocked(dapm, "Call Mic");
61 break; 62 break;
62 case MAGICIAN_MIC_EXT: 63 case MAGICIAN_MIC_EXT:
63 snd_soc_dapm_disable_pin(dapm, "Call Mic"); 64 snd_soc_dapm_disable_pin_unlocked(dapm, "Call Mic");
64 snd_soc_dapm_enable_pin(dapm, "Headset Mic"); 65 snd_soc_dapm_enable_pin_unlocked(dapm, "Headset Mic");
65 break; 66 break;
66 } 67 }
67 68
68 snd_soc_dapm_sync(dapm); 69 snd_soc_dapm_sync_unlocked(dapm);
70
71 snd_soc_dapm_mutex_unlock(dapm);
69} 72}
70 73
71static int magician_startup(struct snd_pcm_substream *substream) 74static int magician_startup(struct snd_pcm_substream *substream)
72{ 75{
73 struct snd_soc_pcm_runtime *rtd = substream->private_data; 76 struct snd_soc_pcm_runtime *rtd = substream->private_data;
74 struct snd_soc_codec *codec = rtd->codec;
75
76 mutex_lock(&codec->mutex);
77 77
78 /* check the jack status at stream startup */ 78 /* check the jack status at stream startup */
79 magician_ext_control(codec); 79 magician_ext_control(&rtd->card->dapm);
80
81 mutex_unlock(&codec->mutex);
82 80
83 return 0; 81 return 0;
84} 82}
@@ -277,13 +275,13 @@ static int magician_get_hp(struct snd_kcontrol *kcontrol,
277static int magician_set_hp(struct snd_kcontrol *kcontrol, 275static int magician_set_hp(struct snd_kcontrol *kcontrol,
278 struct snd_ctl_elem_value *ucontrol) 276 struct snd_ctl_elem_value *ucontrol)
279{ 277{
280 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 278 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
281 279
282 if (magician_hp_switch == ucontrol->value.integer.value[0]) 280 if (magician_hp_switch == ucontrol->value.integer.value[0])
283 return 0; 281 return 0;
284 282
285 magician_hp_switch = ucontrol->value.integer.value[0]; 283 magician_hp_switch = ucontrol->value.integer.value[0];
286 magician_ext_control(codec); 284 magician_ext_control(&card->dapm);
287 return 1; 285 return 1;
288} 286}
289 287
@@ -297,13 +295,13 @@ static int magician_get_spk(struct snd_kcontrol *kcontrol,
297static int magician_set_spk(struct snd_kcontrol *kcontrol, 295static int magician_set_spk(struct snd_kcontrol *kcontrol,
298 struct snd_ctl_elem_value *ucontrol) 296 struct snd_ctl_elem_value *ucontrol)
299{ 297{
300 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 298 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
301 299
302 if (magician_spk_switch == ucontrol->value.integer.value[0]) 300 if (magician_spk_switch == ucontrol->value.integer.value[0])
303 return 0; 301 return 0;
304 302
305 magician_spk_switch = ucontrol->value.integer.value[0]; 303 magician_spk_switch = ucontrol->value.integer.value[0];
306 magician_ext_control(codec); 304 magician_ext_control(&card->dapm);
307 return 1; 305 return 1;
308} 306}
309 307
@@ -400,7 +398,6 @@ static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd)
400{ 398{
401 struct snd_soc_codec *codec = rtd->codec; 399 struct snd_soc_codec *codec = rtd->codec;
402 struct snd_soc_dapm_context *dapm = &codec->dapm; 400 struct snd_soc_dapm_context *dapm = &codec->dapm;
403 int err;
404 401
405 /* NC codec pins */ 402 /* NC codec pins */
406 snd_soc_dapm_nc_pin(dapm, "VOUTLHP"); 403 snd_soc_dapm_nc_pin(dapm, "VOUTLHP");
@@ -410,19 +407,6 @@ static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd)
410 snd_soc_dapm_nc_pin(dapm, "VINL"); 407 snd_soc_dapm_nc_pin(dapm, "VINL");
411 snd_soc_dapm_nc_pin(dapm, "VINR"); 408 snd_soc_dapm_nc_pin(dapm, "VINR");
412 409
413 /* Add magician specific controls */
414 err = snd_soc_add_codec_controls(codec, uda1380_magician_controls,
415 ARRAY_SIZE(uda1380_magician_controls));
416 if (err < 0)
417 return err;
418
419 /* Add magician specific widgets */
420 snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
421 ARRAY_SIZE(uda1380_dapm_widgets));
422
423 /* Set up magician specific audio path interconnects */
424 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
425
426 return 0; 410 return 0;
427} 411}
428 412
@@ -456,6 +440,12 @@ static struct snd_soc_card snd_soc_card_magician = {
456 .dai_link = magician_dai, 440 .dai_link = magician_dai,
457 .num_links = ARRAY_SIZE(magician_dai), 441 .num_links = ARRAY_SIZE(magician_dai),
458 442
443 .controls = uda1380_magician_controls,
444 .num_controls = ARRAY_SIZE(uda1380_magician_controls),
445 .dapm_widgets = uda1380_dapm_widgets,
446 .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
447 .dapm_routes = audio_map,
448 .num_dapm_routes = ARRAY_SIZE(audio_map),
459}; 449};
460 450
461static struct platform_device *magician_snd_device; 451static struct platform_device *magician_snd_device;
diff --git a/sound/soc/pxa/mioa701_wm9713.c b/sound/soc/pxa/mioa701_wm9713.c
index 160c5245448f..595eee341e90 100644
--- a/sound/soc/pxa/mioa701_wm9713.c
+++ b/sound/soc/pxa/mioa701_wm9713.c
@@ -127,16 +127,8 @@ static const struct snd_soc_dapm_route audio_map[] = {
127static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd) 127static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
128{ 128{
129 struct snd_soc_codec *codec = rtd->codec; 129 struct snd_soc_codec *codec = rtd->codec;
130 struct snd_soc_dapm_context *dapm = &codec->dapm;
131 unsigned short reg; 130 unsigned short reg;
132 131
133 /* Add mioa701 specific widgets */
134 snd_soc_dapm_new_controls(dapm, mioa701_dapm_widgets,
135 ARRAY_SIZE(mioa701_dapm_widgets));
136
137 /* Set up mioa701 specific audio path audio_mapnects */
138 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
139
140 /* Prepare GPIO8 for rear speaker amplifier */ 132 /* Prepare GPIO8 for rear speaker amplifier */
141 reg = codec->driver->read(codec, AC97_GPIO_CFG); 133 reg = codec->driver->read(codec, AC97_GPIO_CFG);
142 codec->driver->write(codec, AC97_GPIO_CFG, reg | 0x0100); 134 codec->driver->write(codec, AC97_GPIO_CFG, reg | 0x0100);
@@ -145,12 +137,6 @@ static int mioa701_wm9713_init(struct snd_soc_pcm_runtime *rtd)
145 reg = codec->driver->read(codec, AC97_3D_CONTROL); 137 reg = codec->driver->read(codec, AC97_3D_CONTROL);
146 codec->driver->write(codec, AC97_3D_CONTROL, reg | 0xc000); 138 codec->driver->write(codec, AC97_3D_CONTROL, reg | 0xc000);
147 139
148 snd_soc_dapm_enable_pin(dapm, "Front Speaker");
149 snd_soc_dapm_enable_pin(dapm, "Rear Speaker");
150 snd_soc_dapm_enable_pin(dapm, "Front Mic");
151 snd_soc_dapm_enable_pin(dapm, "GSM Line In");
152 snd_soc_dapm_enable_pin(dapm, "GSM Line Out");
153
154 return 0; 140 return 0;
155} 141}
156 142
@@ -183,6 +169,11 @@ static struct snd_soc_card mioa701 = {
183 .owner = THIS_MODULE, 169 .owner = THIS_MODULE,
184 .dai_link = mioa701_dai, 170 .dai_link = mioa701_dai,
185 .num_links = ARRAY_SIZE(mioa701_dai), 171 .num_links = ARRAY_SIZE(mioa701_dai),
172
173 .dapm_widgets = mioa701_dapm_widgets,
174 .num_dapm_widgets = ARRAY_SIZE(mioa701_dapm_widgets),
175 .dapm_routes = audio_map,
176 .num_dapm_routes = ARRAY_SIZE(audio_map),
186}; 177};
187 178
188static int mioa701_wm9713_probe(struct platform_device *pdev) 179static int mioa701_wm9713_probe(struct platform_device *pdev)
diff --git a/sound/soc/pxa/poodle.c b/sound/soc/pxa/poodle.c
index c93e138d8dc3..c6bdc6c0eff6 100644
--- a/sound/soc/pxa/poodle.c
+++ b/sound/soc/pxa/poodle.c
@@ -74,14 +74,9 @@ static void poodle_ext_control(struct snd_soc_dapm_context *dapm)
74static int poodle_startup(struct snd_pcm_substream *substream) 74static int poodle_startup(struct snd_pcm_substream *substream)
75{ 75{
76 struct snd_soc_pcm_runtime *rtd = substream->private_data; 76 struct snd_soc_pcm_runtime *rtd = substream->private_data;
77 struct snd_soc_codec *codec = rtd->codec;
78
79 mutex_lock(&codec->mutex);
80 77
81 /* check the jack status at stream startup */ 78 /* check the jack status at stream startup */
82 poodle_ext_control(&codec->dapm); 79 poodle_ext_control(&rtd->card->dapm);
83
84 mutex_unlock(&codec->mutex);
85 80
86 return 0; 81 return 0;
87} 82}
diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c
index fc052d8247ff..1373b017a951 100644
--- a/sound/soc/pxa/spitz.c
+++ b/sound/soc/pxa/spitz.c
@@ -46,74 +46,74 @@ static int spitz_mic_gpio;
46 46
47static void spitz_ext_control(struct snd_soc_dapm_context *dapm) 47static void spitz_ext_control(struct snd_soc_dapm_context *dapm)
48{ 48{
49 snd_soc_dapm_mutex_lock(dapm);
50
49 if (spitz_spk_func == SPITZ_SPK_ON) 51 if (spitz_spk_func == SPITZ_SPK_ON)
50 snd_soc_dapm_enable_pin(dapm, "Ext Spk"); 52 snd_soc_dapm_enable_pin_unlocked(dapm, "Ext Spk");
51 else 53 else
52 snd_soc_dapm_disable_pin(dapm, "Ext Spk"); 54 snd_soc_dapm_disable_pin_unlocked(dapm, "Ext Spk");
53 55
54 /* set up jack connection */ 56 /* set up jack connection */
55 switch (spitz_jack_func) { 57 switch (spitz_jack_func) {
56 case SPITZ_HP: 58 case SPITZ_HP:
57 /* enable and unmute hp jack, disable mic bias */ 59 /* enable and unmute hp jack, disable mic bias */
58 snd_soc_dapm_disable_pin(dapm, "Headset Jack"); 60 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
59 snd_soc_dapm_disable_pin(dapm, "Mic Jack"); 61 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
60 snd_soc_dapm_disable_pin(dapm, "Line Jack"); 62 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
61 snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); 63 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
62 gpio_set_value(SPITZ_GPIO_MUTE_L, 1); 64 gpio_set_value(SPITZ_GPIO_MUTE_L, 1);
63 gpio_set_value(SPITZ_GPIO_MUTE_R, 1); 65 gpio_set_value(SPITZ_GPIO_MUTE_R, 1);
64 break; 66 break;
65 case SPITZ_MIC: 67 case SPITZ_MIC:
66 /* enable mic jack and bias, mute hp */ 68 /* enable mic jack and bias, mute hp */
67 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 69 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
68 snd_soc_dapm_disable_pin(dapm, "Headset Jack"); 70 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
69 snd_soc_dapm_disable_pin(dapm, "Line Jack"); 71 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
70 snd_soc_dapm_enable_pin(dapm, "Mic Jack"); 72 snd_soc_dapm_enable_pin_unlocked(dapm, "Mic Jack");
71 gpio_set_value(SPITZ_GPIO_MUTE_L, 0); 73 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
72 gpio_set_value(SPITZ_GPIO_MUTE_R, 0); 74 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
73 break; 75 break;
74 case SPITZ_LINE: 76 case SPITZ_LINE:
75 /* enable line jack, disable mic bias and mute hp */ 77 /* enable line jack, disable mic bias and mute hp */
76 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 78 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
77 snd_soc_dapm_disable_pin(dapm, "Headset Jack"); 79 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
78 snd_soc_dapm_disable_pin(dapm, "Mic Jack"); 80 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
79 snd_soc_dapm_enable_pin(dapm, "Line Jack"); 81 snd_soc_dapm_enable_pin_unlocked(dapm, "Line Jack");
80 gpio_set_value(SPITZ_GPIO_MUTE_L, 0); 82 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
81 gpio_set_value(SPITZ_GPIO_MUTE_R, 0); 83 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
82 break; 84 break;
83 case SPITZ_HEADSET: 85 case SPITZ_HEADSET:
84 /* enable and unmute headset jack enable mic bias, mute L hp */ 86 /* enable and unmute headset jack enable mic bias, mute L hp */
85 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 87 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
86 snd_soc_dapm_enable_pin(dapm, "Mic Jack"); 88 snd_soc_dapm_enable_pin_unlocked(dapm, "Mic Jack");
87 snd_soc_dapm_disable_pin(dapm, "Line Jack"); 89 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
88 snd_soc_dapm_enable_pin(dapm, "Headset Jack"); 90 snd_soc_dapm_enable_pin_unlocked(dapm, "Headset Jack");
89 gpio_set_value(SPITZ_GPIO_MUTE_L, 0); 91 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
90 gpio_set_value(SPITZ_GPIO_MUTE_R, 1); 92 gpio_set_value(SPITZ_GPIO_MUTE_R, 1);
91 break; 93 break;
92 case SPITZ_HP_OFF: 94 case SPITZ_HP_OFF:
93 95
94 /* jack removed, everything off */ 96 /* jack removed, everything off */
95 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 97 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
96 snd_soc_dapm_disable_pin(dapm, "Headset Jack"); 98 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
97 snd_soc_dapm_disable_pin(dapm, "Mic Jack"); 99 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack");
98 snd_soc_dapm_disable_pin(dapm, "Line Jack"); 100 snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack");
99 gpio_set_value(SPITZ_GPIO_MUTE_L, 0); 101 gpio_set_value(SPITZ_GPIO_MUTE_L, 0);
100 gpio_set_value(SPITZ_GPIO_MUTE_R, 0); 102 gpio_set_value(SPITZ_GPIO_MUTE_R, 0);
101 break; 103 break;
102 } 104 }
103 snd_soc_dapm_sync(dapm); 105
106 snd_soc_dapm_sync_unlocked(dapm);
107
108 snd_soc_dapm_mutex_unlock(dapm);
104} 109}
105 110
106static int spitz_startup(struct snd_pcm_substream *substream) 111static int spitz_startup(struct snd_pcm_substream *substream)
107{ 112{
108 struct snd_soc_pcm_runtime *rtd = substream->private_data; 113 struct snd_soc_pcm_runtime *rtd = substream->private_data;
109 struct snd_soc_codec *codec = rtd->codec;
110
111 mutex_lock(&codec->mutex);
112 114
113 /* check the jack status at stream startup */ 115 /* check the jack status at stream startup */
114 spitz_ext_control(&codec->dapm); 116 spitz_ext_control(&rtd->card->dapm);
115
116 mutex_unlock(&codec->mutex);
117 117
118 return 0; 118 return 0;
119} 119}
diff --git a/sound/soc/pxa/tosa.c b/sound/soc/pxa/tosa.c
index 1d9c2ed223bc..4a956d1cb269 100644
--- a/sound/soc/pxa/tosa.c
+++ b/sound/soc/pxa/tosa.c
@@ -44,48 +44,46 @@
44static int tosa_jack_func; 44static int tosa_jack_func;
45static int tosa_spk_func; 45static int tosa_spk_func;
46 46
47static void tosa_ext_control(struct snd_soc_codec *codec) 47static void tosa_ext_control(struct snd_soc_dapm_context *dapm)
48{ 48{
49 struct snd_soc_dapm_context *dapm = &codec->dapm; 49
50 snd_soc_dapm_mutex_lock(dapm);
50 51
51 /* set up jack connection */ 52 /* set up jack connection */
52 switch (tosa_jack_func) { 53 switch (tosa_jack_func) {
53 case TOSA_HP: 54 case TOSA_HP:
54 snd_soc_dapm_disable_pin(dapm, "Mic (Internal)"); 55 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic (Internal)");
55 snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); 56 snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
56 snd_soc_dapm_disable_pin(dapm, "Headset Jack"); 57 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
57 break; 58 break;
58 case TOSA_MIC_INT: 59 case TOSA_MIC_INT:
59 snd_soc_dapm_enable_pin(dapm, "Mic (Internal)"); 60 snd_soc_dapm_enable_pin_unlocked(dapm, "Mic (Internal)");
60 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 61 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
61 snd_soc_dapm_disable_pin(dapm, "Headset Jack"); 62 snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack");
62 break; 63 break;
63 case TOSA_HEADSET: 64 case TOSA_HEADSET:
64 snd_soc_dapm_disable_pin(dapm, "Mic (Internal)"); 65 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic (Internal)");
65 snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); 66 snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
66 snd_soc_dapm_enable_pin(dapm, "Headset Jack"); 67 snd_soc_dapm_enable_pin_unlocked(dapm, "Headset Jack");
67 break; 68 break;
68 } 69 }
69 70
70 if (tosa_spk_func == TOSA_SPK_ON) 71 if (tosa_spk_func == TOSA_SPK_ON)
71 snd_soc_dapm_enable_pin(dapm, "Speaker"); 72 snd_soc_dapm_enable_pin_unlocked(dapm, "Speaker");
72 else 73 else
73 snd_soc_dapm_disable_pin(dapm, "Speaker"); 74 snd_soc_dapm_disable_pin_unlocked(dapm, "Speaker");
75
76 snd_soc_dapm_sync_unlocked(dapm);
74 77
75 snd_soc_dapm_sync(dapm); 78 snd_soc_dapm_mutex_unlock(dapm);
76} 79}
77 80
78static int tosa_startup(struct snd_pcm_substream *substream) 81static int tosa_startup(struct snd_pcm_substream *substream)
79{ 82{
80 struct snd_soc_pcm_runtime *rtd = substream->private_data; 83 struct snd_soc_pcm_runtime *rtd = substream->private_data;
81 struct snd_soc_codec *codec = rtd->codec;
82
83 mutex_lock(&codec->mutex);
84 84
85 /* check the jack status at stream startup */ 85 /* check the jack status at stream startup */
86 tosa_ext_control(codec); 86 tosa_ext_control(&rtd->card->dapm);
87
88 mutex_unlock(&codec->mutex);
89 87
90 return 0; 88 return 0;
91} 89}
@@ -104,13 +102,13 @@ static int tosa_get_jack(struct snd_kcontrol *kcontrol,
104static int tosa_set_jack(struct snd_kcontrol *kcontrol, 102static int tosa_set_jack(struct snd_kcontrol *kcontrol,
105 struct snd_ctl_elem_value *ucontrol) 103 struct snd_ctl_elem_value *ucontrol)
106{ 104{
107 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 105 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
108 106
109 if (tosa_jack_func == ucontrol->value.integer.value[0]) 107 if (tosa_jack_func == ucontrol->value.integer.value[0])
110 return 0; 108 return 0;
111 109
112 tosa_jack_func = ucontrol->value.integer.value[0]; 110 tosa_jack_func = ucontrol->value.integer.value[0];
113 tosa_ext_control(codec); 111 tosa_ext_control(&card->dapm);
114 return 1; 112 return 1;
115} 113}
116 114
@@ -124,13 +122,13 @@ static int tosa_get_spk(struct snd_kcontrol *kcontrol,
124static int tosa_set_spk(struct snd_kcontrol *kcontrol, 122static int tosa_set_spk(struct snd_kcontrol *kcontrol,
125 struct snd_ctl_elem_value *ucontrol) 123 struct snd_ctl_elem_value *ucontrol)
126{ 124{
127 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 125 struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
128 126
129 if (tosa_spk_func == ucontrol->value.integer.value[0]) 127 if (tosa_spk_func == ucontrol->value.integer.value[0])
130 return 0; 128 return 0;
131 129
132 tosa_spk_func = ucontrol->value.integer.value[0]; 130 tosa_spk_func = ucontrol->value.integer.value[0];
133 tosa_ext_control(codec); 131 tosa_ext_control(&card->dapm);
134 return 1; 132 return 1;
135} 133}
136 134
@@ -191,24 +189,10 @@ static int tosa_ac97_init(struct snd_soc_pcm_runtime *rtd)
191{ 189{
192 struct snd_soc_codec *codec = rtd->codec; 190 struct snd_soc_codec *codec = rtd->codec;
193 struct snd_soc_dapm_context *dapm = &codec->dapm; 191 struct snd_soc_dapm_context *dapm = &codec->dapm;
194 int err;
195 192
196 snd_soc_dapm_nc_pin(dapm, "OUT3"); 193 snd_soc_dapm_nc_pin(dapm, "OUT3");
197 snd_soc_dapm_nc_pin(dapm, "MONOOUT"); 194 snd_soc_dapm_nc_pin(dapm, "MONOOUT");
198 195
199 /* add tosa specific controls */
200 err = snd_soc_add_codec_controls(codec, tosa_controls,
201 ARRAY_SIZE(tosa_controls));
202 if (err < 0)
203 return err;
204
205 /* add tosa specific widgets */
206 snd_soc_dapm_new_controls(dapm, tosa_dapm_widgets,
207 ARRAY_SIZE(tosa_dapm_widgets));
208
209 /* set up tosa specific audio path audio_map */
210 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
211
212 return 0; 196 return 0;
213} 197}
214 198
@@ -239,6 +223,13 @@ static struct snd_soc_card tosa = {
239 .owner = THIS_MODULE, 223 .owner = THIS_MODULE,
240 .dai_link = tosa_dai, 224 .dai_link = tosa_dai,
241 .num_links = ARRAY_SIZE(tosa_dai), 225 .num_links = ARRAY_SIZE(tosa_dai),
226
227 .controls = tosa_controls,
228 .num_controls = ARRAY_SIZE(tosa_controls),
229 .dapm_widgets = tosa_dapm_widgets,
230 .num_dapm_widgets = ARRAY_SIZE(tosa_dapm_widgets),
231 .dapm_routes = audio_map,
232 .num_dapm_routes = ARRAY_SIZE(audio_map),
242}; 233};
243 234
244static int tosa_probe(struct platform_device *pdev) 235static int tosa_probe(struct platform_device *pdev)
diff --git a/sound/soc/pxa/zylonite.c b/sound/soc/pxa/zylonite.c
index db8aadf8932d..23bf991e95d5 100644
--- a/sound/soc/pxa/zylonite.c
+++ b/sound/soc/pxa/zylonite.c
@@ -71,22 +71,10 @@ static const struct snd_soc_dapm_route audio_map[] = {
71 71
72static int zylonite_wm9713_init(struct snd_soc_pcm_runtime *rtd) 72static int zylonite_wm9713_init(struct snd_soc_pcm_runtime *rtd)
73{ 73{
74 struct snd_soc_codec *codec = rtd->codec;
75 struct snd_soc_dapm_context *dapm = &codec->dapm;
76
77 if (clk_pout) 74 if (clk_pout)
78 snd_soc_dai_set_pll(rtd->codec_dai, 0, 0, 75 snd_soc_dai_set_pll(rtd->codec_dai, 0, 0,
79 clk_get_rate(pout), 0); 76 clk_get_rate(pout), 0);
80 77
81 snd_soc_dapm_new_controls(dapm, zylonite_dapm_widgets,
82 ARRAY_SIZE(zylonite_dapm_widgets));
83
84 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
85
86 /* Static setup for now */
87 snd_soc_dapm_enable_pin(dapm, "Headphone");
88 snd_soc_dapm_enable_pin(dapm, "Headset Earpiece");
89
90 return 0; 78 return 0;
91} 79}
92 80
@@ -256,6 +244,11 @@ static struct snd_soc_card zylonite = {
256 .resume_pre = &zylonite_resume_pre, 244 .resume_pre = &zylonite_resume_pre,
257 .dai_link = zylonite_dai, 245 .dai_link = zylonite_dai,
258 .num_links = ARRAY_SIZE(zylonite_dai), 246 .num_links = ARRAY_SIZE(zylonite_dai),
247
248 .dapm_widgets = zylonite_dapm_widgets,
249 .num_dapm_widgets = ARRAY_SIZE(zylonite_dapm_widgets),
250 .dapm_routes = audio_map,
251 .num_dapm_routes = ARRAY_SIZE(audio_map),
259}; 252};
260 253
261static struct platform_device *zylonite_snd_ac97_device; 254static struct platform_device *zylonite_snd_ac97_device;
diff --git a/sound/soc/s6000/s6105-ipcam.c b/sound/soc/s6000/s6105-ipcam.c
index 945e8abdc10f..0b21d1dc80c1 100644
--- a/sound/soc/s6000/s6105-ipcam.c
+++ b/sound/soc/s6000/s6105-ipcam.c
@@ -104,8 +104,8 @@ static int output_type_get(struct snd_kcontrol *kcontrol,
104static int output_type_put(struct snd_kcontrol *kcontrol, 104static int output_type_put(struct snd_kcontrol *kcontrol,
105 struct snd_ctl_elem_value *ucontrol) 105 struct snd_ctl_elem_value *ucontrol)
106{ 106{
107 struct snd_soc_codec *codec = kcontrol->private_data; 107 struct snd_soc_card *card = kcontrol->private_data;
108 struct snd_soc_dapm_context *dapm = &codec->dapm; 108 struct snd_soc_dapm_context *dapm = &card->dapm;
109 unsigned int val = (ucontrol->value.enumerated.item[0] != 0); 109 unsigned int val = (ucontrol->value.enumerated.item[0] != 0);
110 char *differential = "Audio Out Differential"; 110 char *differential = "Audio Out Differential";
111 char *stereo = "Audio Out Stereo"; 111 char *stereo = "Audio Out Stereo";
@@ -137,13 +137,7 @@ static int s6105_aic3x_init(struct snd_soc_pcm_runtime *rtd)
137{ 137{
138 struct snd_soc_codec *codec = rtd->codec; 138 struct snd_soc_codec *codec = rtd->codec;
139 struct snd_soc_dapm_context *dapm = &codec->dapm; 139 struct snd_soc_dapm_context *dapm = &codec->dapm;
140 140 struct snd_soc_card *card = rtd->card;
141 /* Add s6105 specific widgets */
142 snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
143 ARRAY_SIZE(aic3x_dapm_widgets));
144
145 /* Set up s6105 specific audio path audio_map */
146 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
147 141
148 /* not present */ 142 /* not present */
149 snd_soc_dapm_nc_pin(dapm, "MONO_LOUT"); 143 snd_soc_dapm_nc_pin(dapm, "MONO_LOUT");
@@ -157,17 +151,10 @@ static int s6105_aic3x_init(struct snd_soc_pcm_runtime *rtd)
157 snd_soc_dapm_nc_pin(dapm, "RLOUT"); 151 snd_soc_dapm_nc_pin(dapm, "RLOUT");
158 snd_soc_dapm_nc_pin(dapm, "HPRCOM"); 152 snd_soc_dapm_nc_pin(dapm, "HPRCOM");
159 153
160 /* always connected */
161 snd_soc_dapm_enable_pin(dapm, "Audio In");
162
163 /* must correspond to audio_out_mux.private_value initializer */ 154 /* must correspond to audio_out_mux.private_value initializer */
164 snd_soc_dapm_disable_pin(dapm, "Audio Out Differential"); 155 snd_soc_dapm_disable_pin(&card->dapm, "Audio Out Differential");
165 snd_soc_dapm_sync(dapm);
166 snd_soc_dapm_enable_pin(dapm, "Audio Out Stereo");
167
168 snd_soc_dapm_sync(dapm);
169 156
170 snd_ctl_add(codec->card->snd_card, snd_ctl_new1(&audio_out_mux, codec)); 157 snd_ctl_add(card->snd_card, snd_ctl_new1(&audio_out_mux, card));
171 158
172 return 0; 159 return 0;
173} 160}
@@ -190,6 +177,11 @@ static struct snd_soc_card snd_soc_card_s6105 = {
190 .owner = THIS_MODULE, 177 .owner = THIS_MODULE,
191 .dai_link = &s6105_dai, 178 .dai_link = &s6105_dai,
192 .num_links = 1, 179 .num_links = 1,
180
181 .dapm_widgets = aic3x_dapm_widgets,
182 .num_dapm_widgets = ARRAY_SIZE(aic3x_dapm_widgets),
183 .dapm_routes = audio_map,
184 .num_dapm_routes = ARRAY_SIZE(audio_map),
193}; 185};
194 186
195static struct s6000_snd_platform_data s6105_snd_data __initdata = { 187static struct s6000_snd_platform_data s6105_snd_data __initdata = {
diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig
index 350757400391..f2e289180e46 100644
--- a/sound/soc/samsung/Kconfig
+++ b/sound/soc/samsung/Kconfig
@@ -117,7 +117,7 @@ config SND_SOC_SAMSUNG_SIMTEC_TLV320AIC23
117 tristate "SoC I2S Audio support for TLV320AIC23 on Simtec boards" 117 tristate "SoC I2S Audio support for TLV320AIC23 on Simtec boards"
118 depends on SND_SOC_SAMSUNG && ARCH_S3C24XX 118 depends on SND_SOC_SAMSUNG && ARCH_S3C24XX
119 select SND_S3C24XX_I2S 119 select SND_S3C24XX_I2S
120 select SND_SOC_TLV320AIC23 120 select SND_SOC_TLV320AIC23_I2C
121 select SND_SOC_SAMSUNG_SIMTEC 121 select SND_SOC_SAMSUNG_SIMTEC
122 122
123config SND_SOC_SAMSUNG_SIMTEC_HERMES 123config SND_SOC_SAMSUNG_SIMTEC_HERMES
diff --git a/sound/soc/samsung/h1940_uda1380.c b/sound/soc/samsung/h1940_uda1380.c
index fbced589d077..88b09e022503 100644
--- a/sound/soc/samsung/h1940_uda1380.c
+++ b/sound/soc/samsung/h1940_uda1380.c
@@ -66,10 +66,6 @@ static int h1940_startup(struct snd_pcm_substream *substream)
66{ 66{
67 struct snd_pcm_runtime *runtime = substream->runtime; 67 struct snd_pcm_runtime *runtime = substream->runtime;
68 68
69 runtime->hw.rate_min = hw_rates.list[0];
70 runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1];
71 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
72
73 return snd_pcm_hw_constraint_list(runtime, 0, 69 return snd_pcm_hw_constraint_list(runtime, 0,
74 SNDRV_PCM_HW_PARAM_RATE, 70 SNDRV_PCM_HW_PARAM_RATE,
75 &hw_rates); 71 &hw_rates);
@@ -94,7 +90,7 @@ static int h1940_hw_params(struct snd_pcm_substream *substream,
94 div++; 90 div++;
95 break; 91 break;
96 default: 92 default:
97 dev_err(&rtd->dev, "%s: rate %d is not supported\n", 93 dev_err(rtd->dev, "%s: rate %d is not supported\n",
98 __func__, rate); 94 __func__, rate);
99 return -EINVAL; 95 return -EINVAL;
100 } 96 }
@@ -181,7 +177,6 @@ static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd)
181{ 177{
182 struct snd_soc_codec *codec = rtd->codec; 178 struct snd_soc_codec *codec = rtd->codec;
183 struct snd_soc_dapm_context *dapm = &codec->dapm; 179 struct snd_soc_dapm_context *dapm = &codec->dapm;
184 int err;
185 180
186 snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); 181 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
187 snd_soc_dapm_enable_pin(dapm, "Speaker"); 182 snd_soc_dapm_enable_pin(dapm, "Speaker");
diff --git a/sound/soc/samsung/neo1973_wm8753.c b/sound/soc/samsung/neo1973_wm8753.c
index 98a04c11202d..b0800337b79e 100644
--- a/sound/soc/samsung/neo1973_wm8753.c
+++ b/sound/soc/samsung/neo1973_wm8753.c
@@ -192,44 +192,6 @@ static struct snd_soc_ops neo1973_voice_ops = {
192 .hw_free = neo1973_voice_hw_free, 192 .hw_free = neo1973_voice_hw_free,
193}; 193};
194 194
195/* Shared routes and controls */
196
197static const struct snd_soc_dapm_widget neo1973_wm8753_dapm_widgets[] = {
198 SND_SOC_DAPM_LINE("GSM Line Out", NULL),
199 SND_SOC_DAPM_LINE("GSM Line In", NULL),
200 SND_SOC_DAPM_MIC("Headset Mic", NULL),
201 SND_SOC_DAPM_MIC("Handset Mic", NULL),
202};
203
204static const struct snd_soc_dapm_route neo1973_wm8753_routes[] = {
205 /* Connections to the GSM Module */
206 {"GSM Line Out", NULL, "MONO1"},
207 {"GSM Line Out", NULL, "MONO2"},
208 {"RXP", NULL, "GSM Line In"},
209 {"RXN", NULL, "GSM Line In"},
210
211 /* Connections to Headset */
212 {"MIC1", NULL, "Mic Bias"},
213 {"Mic Bias", NULL, "Headset Mic"},
214
215 /* Call Mic */
216 {"MIC2", NULL, "Mic Bias"},
217 {"MIC2N", NULL, "Mic Bias"},
218 {"Mic Bias", NULL, "Handset Mic"},
219
220 /* Connect the ALC pins */
221 {"ACIN", NULL, "ACOP"},
222};
223
224static const struct snd_kcontrol_new neo1973_wm8753_controls[] = {
225 SOC_DAPM_PIN_SWITCH("GSM Line Out"),
226 SOC_DAPM_PIN_SWITCH("GSM Line In"),
227 SOC_DAPM_PIN_SWITCH("Headset Mic"),
228 SOC_DAPM_PIN_SWITCH("Handset Mic"),
229};
230
231/* GTA02 specific routes and controls */
232
233static int gta02_speaker_enabled; 195static int gta02_speaker_enabled;
234 196
235static int lm4853_set_spk(struct snd_kcontrol *kcontrol, 197static int lm4853_set_spk(struct snd_kcontrol *kcontrol,
@@ -257,7 +219,34 @@ static int lm4853_event(struct snd_soc_dapm_widget *w,
257 return 0; 219 return 0;
258} 220}
259 221
260static const struct snd_soc_dapm_route neo1973_gta02_routes[] = { 222static const struct snd_soc_dapm_widget neo1973_wm8753_dapm_widgets[] = {
223 SND_SOC_DAPM_LINE("GSM Line Out", NULL),
224 SND_SOC_DAPM_LINE("GSM Line In", NULL),
225 SND_SOC_DAPM_MIC("Headset Mic", NULL),
226 SND_SOC_DAPM_MIC("Handset Mic", NULL),
227 SND_SOC_DAPM_SPK("Handset Spk", NULL),
228 SND_SOC_DAPM_SPK("Stereo Out", lm4853_event),
229};
230
231static const struct snd_soc_dapm_route neo1973_wm8753_routes[] = {
232 /* Connections to the GSM Module */
233 {"GSM Line Out", NULL, "MONO1"},
234 {"GSM Line Out", NULL, "MONO2"},
235 {"RXP", NULL, "GSM Line In"},
236 {"RXN", NULL, "GSM Line In"},
237
238 /* Connections to Headset */
239 {"MIC1", NULL, "Mic Bias"},
240 {"Mic Bias", NULL, "Headset Mic"},
241
242 /* Call Mic */
243 {"MIC2", NULL, "Mic Bias"},
244 {"MIC2N", NULL, "Mic Bias"},
245 {"Mic Bias", NULL, "Handset Mic"},
246
247 /* Connect the ALC pins */
248 {"ACIN", NULL, "ACOP"},
249
261 /* Connections to the amp */ 250 /* Connections to the amp */
262 {"Stereo Out", NULL, "LOUT1"}, 251 {"Stereo Out", NULL, "LOUT1"},
263 {"Stereo Out", NULL, "ROUT1"}, 252 {"Stereo Out", NULL, "ROUT1"},
@@ -267,7 +256,11 @@ static const struct snd_soc_dapm_route neo1973_gta02_routes[] = {
267 {"Handset Spk", NULL, "ROUT2"}, 256 {"Handset Spk", NULL, "ROUT2"},
268}; 257};
269 258
270static const struct snd_kcontrol_new neo1973_gta02_wm8753_controls[] = { 259static const struct snd_kcontrol_new neo1973_wm8753_controls[] = {
260 SOC_DAPM_PIN_SWITCH("GSM Line Out"),
261 SOC_DAPM_PIN_SWITCH("GSM Line In"),
262 SOC_DAPM_PIN_SWITCH("Headset Mic"),
263 SOC_DAPM_PIN_SWITCH("Handset Mic"),
271 SOC_DAPM_PIN_SWITCH("Handset Spk"), 264 SOC_DAPM_PIN_SWITCH("Handset Spk"),
272 SOC_DAPM_PIN_SWITCH("Stereo Out"), 265 SOC_DAPM_PIN_SWITCH("Stereo Out"),
273 266
@@ -276,86 +269,32 @@ static const struct snd_kcontrol_new neo1973_gta02_wm8753_controls[] = {
276 lm4853_set_spk), 269 lm4853_set_spk),
277}; 270};
278 271
279static const struct snd_soc_dapm_widget neo1973_gta02_wm8753_dapm_widgets[] = {
280 SND_SOC_DAPM_SPK("Handset Spk", NULL),
281 SND_SOC_DAPM_SPK("Stereo Out", lm4853_event),
282};
283
284static int neo1973_gta02_wm8753_init(struct snd_soc_codec *codec)
285{
286 struct snd_soc_dapm_context *dapm = &codec->dapm;
287 int ret;
288
289 ret = snd_soc_dapm_new_controls(dapm, neo1973_gta02_wm8753_dapm_widgets,
290 ARRAY_SIZE(neo1973_gta02_wm8753_dapm_widgets));
291 if (ret)
292 return ret;
293
294 ret = snd_soc_dapm_add_routes(dapm, neo1973_gta02_routes,
295 ARRAY_SIZE(neo1973_gta02_routes));
296 if (ret)
297 return ret;
298
299 ret = snd_soc_add_card_controls(codec->card, neo1973_gta02_wm8753_controls,
300 ARRAY_SIZE(neo1973_gta02_wm8753_controls));
301 if (ret)
302 return ret;
303
304 snd_soc_dapm_disable_pin(dapm, "Stereo Out");
305 snd_soc_dapm_disable_pin(dapm, "Handset Spk");
306 snd_soc_dapm_ignore_suspend(dapm, "Stereo Out");
307 snd_soc_dapm_ignore_suspend(dapm, "Handset Spk");
308
309 return 0;
310}
311
312static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd) 272static int neo1973_wm8753_init(struct snd_soc_pcm_runtime *rtd)
313{ 273{
314 struct snd_soc_codec *codec = rtd->codec; 274 struct snd_soc_codec *codec = rtd->codec;
315 struct snd_soc_dapm_context *dapm = &codec->dapm; 275 struct snd_soc_card *card = rtd->card;
316 int ret;
317 276
318 /* set up NC codec pins */ 277 /* set up NC codec pins */
319 snd_soc_dapm_nc_pin(dapm, "OUT3"); 278 snd_soc_dapm_nc_pin(&codec->dapm, "OUT3");
320 snd_soc_dapm_nc_pin(dapm, "OUT4"); 279 snd_soc_dapm_nc_pin(&codec->dapm, "OUT4");
321 snd_soc_dapm_nc_pin(dapm, "LINE1"); 280 snd_soc_dapm_nc_pin(&codec->dapm, "LINE1");
322 snd_soc_dapm_nc_pin(dapm, "LINE2"); 281 snd_soc_dapm_nc_pin(&codec->dapm, "LINE2");
323
324 /* Add neo1973 specific widgets */
325 ret = snd_soc_dapm_new_controls(dapm, neo1973_wm8753_dapm_widgets,
326 ARRAY_SIZE(neo1973_wm8753_dapm_widgets));
327 if (ret)
328 return ret;
329
330 /* add neo1973 specific controls */
331 ret = snd_soc_add_card_controls(rtd->card, neo1973_wm8753_controls,
332 ARRAY_SIZE(neo1973_wm8753_controls));
333 if (ret)
334 return ret;
335
336 /* set up neo1973 specific audio routes */
337 ret = snd_soc_dapm_add_routes(dapm, neo1973_wm8753_routes,
338 ARRAY_SIZE(neo1973_wm8753_routes));
339 if (ret)
340 return ret;
341 282
342 /* set endpoints to default off mode */ 283 /* set endpoints to default off mode */
343 snd_soc_dapm_disable_pin(dapm, "GSM Line Out"); 284 snd_soc_dapm_disable_pin(&card->dapm, "GSM Line Out");
344 snd_soc_dapm_disable_pin(dapm, "GSM Line In"); 285 snd_soc_dapm_disable_pin(&card->dapm, "GSM Line In");
345 snd_soc_dapm_disable_pin(dapm, "Headset Mic"); 286 snd_soc_dapm_disable_pin(&card->dapm, "Headset Mic");
346 snd_soc_dapm_disable_pin(dapm, "Handset Mic"); 287 snd_soc_dapm_disable_pin(&card->dapm, "Handset Mic");
288 snd_soc_dapm_disable_pin(&card->dapm, "Stereo Out");
289 snd_soc_dapm_disable_pin(&card->dapm, "Handset Spk");
347 290
348 /* allow audio paths from the GSM modem to run during suspend */ 291 /* allow audio paths from the GSM modem to run during suspend */
349 snd_soc_dapm_ignore_suspend(dapm, "GSM Line Out"); 292 snd_soc_dapm_ignore_suspend(&card->dapm, "GSM Line Out");
350 snd_soc_dapm_ignore_suspend(dapm, "GSM Line In"); 293 snd_soc_dapm_ignore_suspend(&card->dapm, "GSM Line In");
351 snd_soc_dapm_ignore_suspend(dapm, "Headset Mic"); 294 snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic");
352 snd_soc_dapm_ignore_suspend(dapm, "Handset Mic"); 295 snd_soc_dapm_ignore_suspend(&card->dapm, "Handset Mic");
353 296 snd_soc_dapm_ignore_suspend(&card->dapm, "Stereo Out");
354 if (machine_is_neo1973_gta02()) { 297 snd_soc_dapm_ignore_suspend(&card->dapm, "Handset Spk");
355 ret = neo1973_gta02_wm8753_init(codec);
356 if (ret)
357 return ret;
358 }
359 298
360 return 0; 299 return 0;
361} 300}
@@ -409,6 +348,13 @@ static struct snd_soc_card neo1973 = {
409 .num_aux_devs = ARRAY_SIZE(neo1973_aux_devs), 348 .num_aux_devs = ARRAY_SIZE(neo1973_aux_devs),
410 .codec_conf = neo1973_codec_conf, 349 .codec_conf = neo1973_codec_conf,
411 .num_configs = ARRAY_SIZE(neo1973_codec_conf), 350 .num_configs = ARRAY_SIZE(neo1973_codec_conf),
351
352 .controls = neo1973_wm8753_controls,
353 .num_controls = ARRAY_SIZE(neo1973_wm8753_controls),
354 .dapm_widgets = neo1973_wm8753_dapm_widgets,
355 .num_dapm_widgets = ARRAY_SIZE(neo1973_wm8753_dapm_widgets),
356 .dapm_routes = neo1973_wm8753_routes,
357 .num_dapm_routes = ARRAY_SIZE(neo1973_wm8753_routes),
412}; 358};
413 359
414static struct platform_device *neo1973_snd_device; 360static struct platform_device *neo1973_snd_device;
diff --git a/sound/soc/samsung/rx1950_uda1380.c b/sound/soc/samsung/rx1950_uda1380.c
index 06ebdc061770..2982d9e7f268 100644
--- a/sound/soc/samsung/rx1950_uda1380.c
+++ b/sound/soc/samsung/rx1950_uda1380.c
@@ -131,10 +131,6 @@ static int rx1950_startup(struct snd_pcm_substream *substream)
131{ 131{
132 struct snd_pcm_runtime *runtime = substream->runtime; 132 struct snd_pcm_runtime *runtime = substream->runtime;
133 133
134 runtime->hw.rate_min = hw_rates.list[0];
135 runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1];
136 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
137
138 return snd_pcm_hw_constraint_list(runtime, 0, 134 return snd_pcm_hw_constraint_list(runtime, 0,
139 SNDRV_PCM_HW_PARAM_RATE, 135 SNDRV_PCM_HW_PARAM_RATE,
140 &hw_rates); 136 &hw_rates);
@@ -226,7 +222,6 @@ static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd)
226{ 222{
227 struct snd_soc_codec *codec = rtd->codec; 223 struct snd_soc_codec *codec = rtd->codec;
228 struct snd_soc_dapm_context *dapm = &codec->dapm; 224 struct snd_soc_dapm_context *dapm = &codec->dapm;
229 int err;
230 225
231 snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); 226 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
232 snd_soc_dapm_enable_pin(dapm, "Speaker"); 227 snd_soc_dapm_enable_pin(dapm, "Speaker");
diff --git a/sound/soc/samsung/smdk_wm8994.c b/sound/soc/samsung/smdk_wm8994.c
index d38ae98e2f32..682eb4f7ba0c 100644
--- a/sound/soc/samsung/smdk_wm8994.c
+++ b/sound/soc/samsung/smdk_wm8994.c
@@ -202,7 +202,7 @@ static int smdk_audio_probe(struct platform_device *pdev)
202 202
203static struct platform_driver smdk_audio_driver = { 203static struct platform_driver smdk_audio_driver = {
204 .driver = { 204 .driver = {
205 .name = "smdk-audio-wm8894", 205 .name = "smdk-audio-wm8994",
206 .owner = THIS_MODULE, 206 .owner = THIS_MODULE,
207 .of_match_table = of_match_ptr(samsung_wm8994_of_match), 207 .of_match_table = of_match_ptr(samsung_wm8994_of_match),
208 .pm = &snd_soc_pm_ops, 208 .pm = &snd_soc_pm_ops,
diff --git a/sound/soc/samsung/tobermory.c b/sound/soc/samsung/tobermory.c
index f21ff608a819..1807b75ccc12 100644
--- a/sound/soc/samsung/tobermory.c
+++ b/sound/soc/samsung/tobermory.c
@@ -44,6 +44,8 @@ static int tobermory_set_bias_level(struct snd_soc_card *card,
44 SND_SOC_CLOCK_IN); 44 SND_SOC_CLOCK_IN);
45 if (ret < 0) { 45 if (ret < 0) {
46 pr_err("Failed to set SYSCLK: %d\n", ret); 46 pr_err("Failed to set SYSCLK: %d\n", ret);
47 snd_soc_dai_set_pll(codec_dai, WM8962_FLL,
48 0, 0, 0);
47 return ret; 49 return ret;
48 } 50 }
49 } 51 }
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 1967f44e7cd4..710a079a7377 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -1711,9 +1711,9 @@ static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1711 /* set master/slave audio interface */ 1711 /* set master/slave audio interface */
1712 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1712 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1713 case SND_SOC_DAIFMT_CBM_CFM: 1713 case SND_SOC_DAIFMT_CBM_CFM:
1714 fsi->clk_master = 1;
1715 break; 1714 break;
1716 case SND_SOC_DAIFMT_CBS_CFS: 1715 case SND_SOC_DAIFMT_CBS_CFS:
1716 fsi->clk_master = 1; /* codec is slave, cpu is master */
1717 break; 1717 break;
1718 default: 1718 default:
1719 return -EINVAL; 1719 return -EINVAL;
diff --git a/sound/soc/sh/migor.c b/sound/soc/sh/migor.c
index 5014a884afee..c58c2529f103 100644
--- a/sound/soc/sh/migor.c
+++ b/sound/soc/sh/migor.c
@@ -136,19 +136,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
136 { "Mic Bias", NULL, "External Microphone" }, 136 { "Mic Bias", NULL, "External Microphone" },
137}; 137};
138 138
139static int migor_dai_init(struct snd_soc_pcm_runtime *rtd)
140{
141 struct snd_soc_codec *codec = rtd->codec;
142 struct snd_soc_dapm_context *dapm = &codec->dapm;
143
144 snd_soc_dapm_new_controls(dapm, migor_dapm_widgets,
145 ARRAY_SIZE(migor_dapm_widgets));
146
147 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
148
149 return 0;
150}
151
152/* migor digital audio interface glue - connects codec <--> CPU */ 139/* migor digital audio interface glue - connects codec <--> CPU */
153static struct snd_soc_dai_link migor_dai = { 140static struct snd_soc_dai_link migor_dai = {
154 .name = "wm8978", 141 .name = "wm8978",
@@ -158,7 +145,6 @@ static struct snd_soc_dai_link migor_dai = {
158 .platform_name = "siu-pcm-audio", 145 .platform_name = "siu-pcm-audio",
159 .codec_name = "wm8978.0-001a", 146 .codec_name = "wm8978.0-001a",
160 .ops = &migor_dai_ops, 147 .ops = &migor_dai_ops,
161 .init = migor_dai_init,
162}; 148};
163 149
164/* migor audio machine driver */ 150/* migor audio machine driver */
@@ -167,6 +153,11 @@ static struct snd_soc_card snd_soc_migor = {
167 .owner = THIS_MODULE, 153 .owner = THIS_MODULE,
168 .dai_link = &migor_dai, 154 .dai_link = &migor_dai,
169 .num_links = 1, 155 .num_links = 1,
156
157 .dapm_widgets = migor_dapm_widgets,
158 .num_dapm_widgets = ARRAY_SIZE(migor_dapm_widgets),
159 .dapm_routes = audio_map,
160 .num_dapm_routes = ARRAY_SIZE(audio_map),
170}; 161};
171 162
172static struct platform_device *migor_snd_device; 163static struct platform_device *migor_snd_device;
diff --git a/sound/soc/sh/rcar/Makefile b/sound/soc/sh/rcar/Makefile
index 0ff492df7929..7d0051ced838 100644
--- a/sound/soc/sh/rcar/Makefile
+++ b/sound/soc/sh/rcar/Makefile
@@ -1,2 +1,2 @@
1snd-soc-rcar-objs := core.o gen.o scu.o adg.o ssi.o 1snd-soc-rcar-objs := core.o gen.o src.o adg.o ssi.o
2obj-$(CONFIG_SND_SOC_RCAR) += snd-soc-rcar.o \ No newline at end of file 2obj-$(CONFIG_SND_SOC_RCAR) += snd-soc-rcar.o \ No newline at end of file
diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c
index a53235c4d1b0..69c44269ebdb 100644
--- a/sound/soc/sh/rcar/adg.c
+++ b/sound/soc/sh/rcar/adg.c
@@ -25,15 +25,165 @@ struct rsnd_adg {
25}; 25};
26 26
27#define for_each_rsnd_clk(pos, adg, i) \ 27#define for_each_rsnd_clk(pos, adg, i) \
28 for (i = 0, (pos) = adg->clk[i]; \ 28 for (i = 0; \
29 i < CLKMAX; \ 29 (i < CLKMAX) && \
30 i++, (pos) = adg->clk[i]) 30 ((pos) = adg->clk[i]); \
31 i++)
31#define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg) 32#define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg)
32 33
33static int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv, 34
34 struct rsnd_mod *mod, 35static u32 rsnd_adg_ssi_ws_timing_gen2(struct rsnd_dai_stream *io)
35 unsigned int src_rate, 36{
36 unsigned int dst_rate) 37 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
38 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
39 int id = rsnd_mod_id(mod);
40 int ws = id;
41
42 if (rsnd_ssi_is_pin_sharing(rsnd_ssi_mod_get(priv, id))) {
43 switch (id) {
44 case 1:
45 case 2:
46 ws = 0;
47 break;
48 case 4:
49 ws = 3;
50 break;
51 case 8:
52 ws = 7;
53 break;
54 }
55 }
56
57 return (0x6 + ws) << 8;
58}
59
60static int rsnd_adg_set_src_timsel_gen2(struct rsnd_dai *rdai,
61 struct rsnd_mod *mod,
62 struct rsnd_dai_stream *io,
63 u32 timsel)
64{
65 int is_play = rsnd_dai_is_play(rdai, io);
66 int id = rsnd_mod_id(mod);
67 int shift = (id % 2) ? 16 : 0;
68 u32 mask, ws;
69 u32 in, out;
70
71 ws = rsnd_adg_ssi_ws_timing_gen2(io);
72
73 in = (is_play) ? timsel : ws;
74 out = (is_play) ? ws : timsel;
75
76 in = in << shift;
77 out = out << shift;
78 mask = 0xffff << shift;
79
80 switch (id / 2) {
81 case 0:
82 rsnd_mod_bset(mod, SRCIN_TIMSEL0, mask, in);
83 rsnd_mod_bset(mod, SRCOUT_TIMSEL0, mask, out);
84 break;
85 case 1:
86 rsnd_mod_bset(mod, SRCIN_TIMSEL1, mask, in);
87 rsnd_mod_bset(mod, SRCOUT_TIMSEL1, mask, out);
88 break;
89 case 2:
90 rsnd_mod_bset(mod, SRCIN_TIMSEL2, mask, in);
91 rsnd_mod_bset(mod, SRCOUT_TIMSEL2, mask, out);
92 break;
93 case 3:
94 rsnd_mod_bset(mod, SRCIN_TIMSEL3, mask, in);
95 rsnd_mod_bset(mod, SRCOUT_TIMSEL3, mask, out);
96 break;
97 case 4:
98 rsnd_mod_bset(mod, SRCIN_TIMSEL4, mask, in);
99 rsnd_mod_bset(mod, SRCOUT_TIMSEL4, mask, out);
100 break;
101 }
102
103 return 0;
104}
105
106int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod,
107 struct rsnd_dai *rdai,
108 struct rsnd_dai_stream *io,
109 unsigned int src_rate,
110 unsigned int dst_rate)
111{
112 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
113 struct rsnd_adg *adg = rsnd_priv_to_adg(priv);
114 struct device *dev = rsnd_priv_to_dev(priv);
115 int idx, sel, div, step, ret;
116 u32 val, en;
117 unsigned int min, diff;
118 unsigned int sel_rate [] = {
119 clk_get_rate(adg->clk[CLKA]), /* 0000: CLKA */
120 clk_get_rate(adg->clk[CLKB]), /* 0001: CLKB */
121 clk_get_rate(adg->clk[CLKC]), /* 0010: CLKC */
122 adg->rbga_rate_for_441khz_div_6,/* 0011: RBGA */
123 adg->rbgb_rate_for_48khz_div_6, /* 0100: RBGB */
124 };
125
126 min = ~0;
127 val = 0;
128 en = 0;
129 for (sel = 0; sel < ARRAY_SIZE(sel_rate); sel++) {
130 idx = 0;
131 step = 2;
132
133 if (!sel_rate[sel])
134 continue;
135
136 for (div = 2; div <= 98304; div += step) {
137 diff = abs(src_rate - sel_rate[sel] / div);
138 if (min > diff) {
139 val = (sel << 8) | idx;
140 min = diff;
141 en = 1 << (sel + 1); /* fixme */
142 }
143
144 /*
145 * step of 0_0000 / 0_0001 / 0_1101
146 * are out of order
147 */
148 if ((idx > 2) && (idx % 2))
149 step *= 2;
150 if (idx == 0x1c) {
151 div += step;
152 step *= 2;
153 }
154 idx++;
155 }
156 }
157
158 if (min == ~0) {
159 dev_err(dev, "no Input clock\n");
160 return -EIO;
161 }
162
163 ret = rsnd_adg_set_src_timsel_gen2(rdai, mod, io, val);
164 if (ret < 0) {
165 dev_err(dev, "timsel error\n");
166 return ret;
167 }
168
169 rsnd_mod_bset(mod, DIV_EN, en, en);
170
171 return 0;
172}
173
174int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *mod,
175 struct rsnd_dai *rdai,
176 struct rsnd_dai_stream *io)
177{
178 u32 val = rsnd_adg_ssi_ws_timing_gen2(io);
179
180 return rsnd_adg_set_src_timsel_gen2(rdai, mod, io, val);
181}
182
183int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv,
184 struct rsnd_mod *mod,
185 unsigned int src_rate,
186 unsigned int dst_rate)
37{ 187{
38 struct rsnd_adg *adg = rsnd_priv_to_adg(priv); 188 struct rsnd_adg *adg = rsnd_priv_to_adg(priv);
39 struct device *dev = rsnd_priv_to_dev(priv); 189 struct device *dev = rsnd_priv_to_dev(priv);
@@ -91,18 +241,6 @@ find_rate:
91 return 0; 241 return 0;
92} 242}
93 243
94int rsnd_adg_set_convert_clk(struct rsnd_priv *priv,
95 struct rsnd_mod *mod,
96 unsigned int src_rate,
97 unsigned int dst_rate)
98{
99 if (rsnd_is_gen1(priv))
100 return rsnd_adg_set_convert_clk_gen1(priv, mod,
101 src_rate, dst_rate);
102
103 return -EINVAL;
104}
105
106static void rsnd_adg_set_ssi_clk(struct rsnd_mod *mod, u32 val) 244static void rsnd_adg_set_ssi_clk(struct rsnd_mod *mod, u32 val)
107{ 245{
108 int id = rsnd_mod_id(mod); 246 int id = rsnd_mod_id(mod);
@@ -254,13 +392,14 @@ static void rsnd_adg_ssi_clk_init(struct rsnd_priv *priv, struct rsnd_adg *adg)
254} 392}
255 393
256int rsnd_adg_probe(struct platform_device *pdev, 394int rsnd_adg_probe(struct platform_device *pdev,
257 struct rcar_snd_info *info, 395 const struct rsnd_of_data *of_data,
258 struct rsnd_priv *priv) 396 struct rsnd_priv *priv)
259{ 397{
260 struct rsnd_adg *adg; 398 struct rsnd_adg *adg;
261 struct device *dev = rsnd_priv_to_dev(priv); 399 struct device *dev = rsnd_priv_to_dev(priv);
262 struct clk *clk; 400 struct clk *clk, *clk_orig;
263 int i; 401 int i;
402 bool use_old_style = false;
264 403
265 adg = devm_kzalloc(dev, sizeof(*adg), GFP_KERNEL); 404 adg = devm_kzalloc(dev, sizeof(*adg), GFP_KERNEL);
266 if (!adg) { 405 if (!adg) {
@@ -268,10 +407,39 @@ int rsnd_adg_probe(struct platform_device *pdev,
268 return -ENOMEM; 407 return -ENOMEM;
269 } 408 }
270 409
271 adg->clk[CLKA] = clk_get(NULL, "audio_clk_a"); 410 clk_orig = devm_clk_get(dev, NULL);
272 adg->clk[CLKB] = clk_get(NULL, "audio_clk_b"); 411 adg->clk[CLKA] = devm_clk_get(dev, "clk_a");
273 adg->clk[CLKC] = clk_get(NULL, "audio_clk_c"); 412 adg->clk[CLKB] = devm_clk_get(dev, "clk_b");
274 adg->clk[CLKI] = clk_get(NULL, "audio_clk_internal"); 413 adg->clk[CLKC] = devm_clk_get(dev, "clk_c");
414 adg->clk[CLKI] = devm_clk_get(dev, "clk_i");
415
416 /*
417 * It request device dependent audio clock.
418 * But above all clks will indicate rsnd module clock
419 * if platform doesn't it
420 */
421 for_each_rsnd_clk(clk, adg, i) {
422 if (clk_orig == clk) {
423 dev_warn(dev,
424 "doesn't have device dependent clock, use independent clock\n");
425 use_old_style = true;
426 break;
427 }
428 }
429
430 /*
431 * note:
432 * these exist in order to keep compatible with
433 * platform which has device independent audio clock,
434 * but will be removed soon
435 */
436 if (use_old_style) {
437 adg->clk[CLKA] = devm_clk_get(NULL, "audio_clk_a");
438 adg->clk[CLKB] = devm_clk_get(NULL, "audio_clk_b");
439 adg->clk[CLKC] = devm_clk_get(NULL, "audio_clk_c");
440 adg->clk[CLKI] = devm_clk_get(NULL, "audio_clk_internal");
441 }
442
275 for_each_rsnd_clk(clk, adg, i) { 443 for_each_rsnd_clk(clk, adg, i) {
276 if (IS_ERR(clk)) { 444 if (IS_ERR(clk)) {
277 dev_err(dev, "Audio clock failed\n"); 445 dev_err(dev, "Audio clock failed\n");
@@ -287,14 +455,3 @@ int rsnd_adg_probe(struct platform_device *pdev,
287 455
288 return 0; 456 return 0;
289} 457}
290
291void rsnd_adg_remove(struct platform_device *pdev,
292 struct rsnd_priv *priv)
293{
294 struct rsnd_adg *adg = priv->adg;
295 struct clk *clk;
296 int i;
297
298 for_each_rsnd_clk(clk, adg, i)
299 clk_put(clk);
300}
diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index 743de5e3b1e1..215b668166be 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -73,13 +73,13 @@
73 * | +- ssi[2] 73 * | +- ssi[2]
74 * | ... 74 * | ...
75 * | 75 * |
76 * | ** these control scu 76 * | ** these control src
77 * | 77 * |
78 * +- scu 78 * +- src
79 * | 79 * |
80 * +- scu[0] 80 * +- src[0]
81 * +- scu[1] 81 * +- src[1]
82 * +- scu[2] 82 * +- src[2]
83 * ... 83 * ...
84 * 84 *
85 * 85 *
@@ -100,6 +100,21 @@
100#define RSND_RATES SNDRV_PCM_RATE_8000_96000 100#define RSND_RATES SNDRV_PCM_RATE_8000_96000
101#define RSND_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) 101#define RSND_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
102 102
103static struct rsnd_of_data rsnd_of_data_gen1 = {
104 .flags = RSND_GEN1,
105};
106
107static struct rsnd_of_data rsnd_of_data_gen2 = {
108 .flags = RSND_GEN2,
109};
110
111static struct of_device_id rsnd_of_match[] = {
112 { .compatible = "renesas,rcar_sound-gen1", .data = &rsnd_of_data_gen1 },
113 { .compatible = "renesas,rcar_sound-gen2", .data = &rsnd_of_data_gen2 },
114 {},
115};
116MODULE_DEVICE_TABLE(of, rsnd_of_match);
117
103/* 118/*
104 * rsnd_platform functions 119 * rsnd_platform functions
105 */ 120 */
@@ -107,6 +122,11 @@
107 (!(priv->info->func) ? 0 : \ 122 (!(priv->info->func) ? 0 : \
108 priv->info->func(param)) 123 priv->info->func(param))
109 124
125#define rsnd_is_enable_path(io, name) \
126 ((io)->info ? (io)->info->name : NULL)
127#define rsnd_info_id(priv, io, name) \
128 ((io)->info->name - priv->info->name##_info)
129
110/* 130/*
111 * rsnd_mod functions 131 * rsnd_mod functions
112 */ 132 */
@@ -121,17 +141,19 @@ char *rsnd_mod_name(struct rsnd_mod *mod)
121void rsnd_mod_init(struct rsnd_priv *priv, 141void rsnd_mod_init(struct rsnd_priv *priv,
122 struct rsnd_mod *mod, 142 struct rsnd_mod *mod,
123 struct rsnd_mod_ops *ops, 143 struct rsnd_mod_ops *ops,
144 enum rsnd_mod_type type,
124 int id) 145 int id)
125{ 146{
126 mod->priv = priv; 147 mod->priv = priv;
127 mod->id = id; 148 mod->id = id;
128 mod->ops = ops; 149 mod->ops = ops;
129 INIT_LIST_HEAD(&mod->list); 150 mod->type = type;
130} 151}
131 152
132/* 153/*
133 * rsnd_dma functions 154 * rsnd_dma functions
134 */ 155 */
156static void __rsnd_dma_start(struct rsnd_dma *dma);
135static void rsnd_dma_continue(struct rsnd_dma *dma) 157static void rsnd_dma_continue(struct rsnd_dma *dma)
136{ 158{
137 /* push next A or B plane */ 159 /* push next A or B plane */
@@ -142,8 +164,9 @@ static void rsnd_dma_continue(struct rsnd_dma *dma)
142void rsnd_dma_start(struct rsnd_dma *dma) 164void rsnd_dma_start(struct rsnd_dma *dma)
143{ 165{
144 /* push both A and B plane*/ 166 /* push both A and B plane*/
167 dma->offset = 0;
145 dma->submit_loop = 2; 168 dma->submit_loop = 2;
146 schedule_work(&dma->work); 169 __rsnd_dma_start(dma);
147} 170}
148 171
149void rsnd_dma_stop(struct rsnd_dma *dma) 172void rsnd_dma_stop(struct rsnd_dma *dma)
@@ -156,12 +179,26 @@ void rsnd_dma_stop(struct rsnd_dma *dma)
156static void rsnd_dma_complete(void *data) 179static void rsnd_dma_complete(void *data)
157{ 180{
158 struct rsnd_dma *dma = (struct rsnd_dma *)data; 181 struct rsnd_dma *dma = (struct rsnd_dma *)data;
159 struct rsnd_priv *priv = dma->priv; 182 struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
183 struct rsnd_priv *priv = rsnd_mod_to_priv(rsnd_dma_to_mod(dma));
184 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
160 unsigned long flags; 185 unsigned long flags;
161 186
162 rsnd_lock(priv, flags); 187 rsnd_lock(priv, flags);
163 188
164 dma->complete(dma); 189 /*
190 * Renesas sound Gen1 needs 1 DMAC,
191 * Gen2 needs 2 DMAC.
192 * In Gen2 case, it are Audio-DMAC, and Audio-DMAC-peri-peri.
193 * But, Audio-DMAC-peri-peri doesn't have interrupt,
194 * and this driver is assuming that here.
195 *
196 * If Audio-DMAC-peri-peri has interrpt,
197 * rsnd_dai_pointer_update() will be called twice,
198 * ant it will breaks io->byte_pos
199 */
200
201 rsnd_dai_pointer_update(io, io->byte_per_period);
165 202
166 if (dma->submit_loop) 203 if (dma->submit_loop)
167 rsnd_dma_continue(dma); 204 rsnd_dma_continue(dma);
@@ -169,20 +206,23 @@ static void rsnd_dma_complete(void *data)
169 rsnd_unlock(priv, flags); 206 rsnd_unlock(priv, flags);
170} 207}
171 208
172static void rsnd_dma_do_work(struct work_struct *work) 209static void __rsnd_dma_start(struct rsnd_dma *dma)
173{ 210{
174 struct rsnd_dma *dma = container_of(work, struct rsnd_dma, work); 211 struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
175 struct rsnd_priv *priv = dma->priv; 212 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
213 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
214 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
176 struct device *dev = rsnd_priv_to_dev(priv); 215 struct device *dev = rsnd_priv_to_dev(priv);
177 struct dma_async_tx_descriptor *desc; 216 struct dma_async_tx_descriptor *desc;
178 dma_addr_t buf; 217 dma_addr_t buf;
179 size_t len; 218 size_t len = io->byte_per_period;
180 int i; 219 int i;
181 220
182 for (i = 0; i < dma->submit_loop; i++) { 221 for (i = 0; i < dma->submit_loop; i++) {
183 222
184 if (dma->inquiry(dma, &buf, &len) < 0) 223 buf = runtime->dma_addr +
185 return; 224 rsnd_dai_pointer_offset(io, dma->offset + len);
225 dma->offset = len;
186 226
187 desc = dmaengine_prep_slave_single( 227 desc = dmaengine_prep_slave_single(
188 dma->chan, buf, len, dma->dir, 228 dma->chan, buf, len, dma->dir,
@@ -204,16 +244,20 @@ static void rsnd_dma_do_work(struct work_struct *work)
204 } 244 }
205} 245}
206 246
247static void rsnd_dma_do_work(struct work_struct *work)
248{
249 struct rsnd_dma *dma = container_of(work, struct rsnd_dma, work);
250
251 __rsnd_dma_start(dma);
252}
253
207int rsnd_dma_available(struct rsnd_dma *dma) 254int rsnd_dma_available(struct rsnd_dma *dma)
208{ 255{
209 return !!dma->chan; 256 return !!dma->chan;
210} 257}
211 258
212int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, 259int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
213 int is_play, int id, 260 int is_play, int id)
214 int (*inquiry)(struct rsnd_dma *dma,
215 dma_addr_t *buf, int *len),
216 int (*complete)(struct rsnd_dma *dma))
217{ 261{
218 struct device *dev = rsnd_priv_to_dev(priv); 262 struct device *dev = rsnd_priv_to_dev(priv);
219 struct dma_slave_config cfg; 263 struct dma_slave_config cfg;
@@ -246,9 +290,6 @@ int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
246 goto rsnd_dma_init_err; 290 goto rsnd_dma_init_err;
247 291
248 dma->dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE; 292 dma->dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
249 dma->priv = priv;
250 dma->inquiry = inquiry;
251 dma->complete = complete;
252 INIT_WORK(&dma->work, rsnd_dma_do_work); 293 INIT_WORK(&dma->work, rsnd_dma_do_work);
253 294
254 return 0; 295 return 0;
@@ -271,26 +312,42 @@ void rsnd_dma_quit(struct rsnd_priv *priv,
271/* 312/*
272 * rsnd_dai functions 313 * rsnd_dai functions
273 */ 314 */
274#define rsnd_dai_call(rdai, io, fn) \ 315#define __rsnd_mod_call(mod, func, rdai, io) \
275({ \ 316({ \
276 struct rsnd_mod *mod, *n; \ 317 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \
277 int ret = 0; \ 318 struct device *dev = rsnd_priv_to_dev(priv); \
278 for_each_rsnd_mod(mod, n, io) { \ 319 dev_dbg(dev, "%s [%d] %s\n", \
279 ret = rsnd_mod_call(mod, fn, rdai, io); \ 320 rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \
280 if (ret < 0) \ 321 (mod)->ops->func(mod, rdai, io); \
281 break; \ 322})
282 } \ 323
283 ret; \ 324#define rsnd_mod_call(mod, func, rdai, io) \
325 (!(mod) ? -ENODEV : \
326 !((mod)->ops->func) ? 0 : \
327 __rsnd_mod_call(mod, func, (rdai), (io)))
328
329#define rsnd_dai_call(rdai, io, fn) \
330({ \
331 struct rsnd_mod *mod; \
332 int ret = 0, i; \
333 for (i = 0; i < RSND_MOD_MAX; i++) { \
334 mod = (io)->mod[i]; \
335 if (!mod) \
336 continue; \
337 ret = rsnd_mod_call(mod, fn, (rdai), (io)); \
338 if (ret < 0) \
339 break; \
340 } \
341 ret; \
284}) 342})
285 343
286int rsnd_dai_connect(struct rsnd_dai *rdai, 344static int rsnd_dai_connect(struct rsnd_mod *mod,
287 struct rsnd_mod *mod, 345 struct rsnd_dai_stream *io)
288 struct rsnd_dai_stream *io)
289{ 346{
290 if (!mod) 347 if (!mod)
291 return -EIO; 348 return -EIO;
292 349
293 if (!list_empty(&mod->list)) { 350 if (io->mod[mod->type]) {
294 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 351 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
295 struct device *dev = rsnd_priv_to_dev(priv); 352 struct device *dev = rsnd_priv_to_dev(priv);
296 353
@@ -300,14 +357,8 @@ int rsnd_dai_connect(struct rsnd_dai *rdai,
300 return -EIO; 357 return -EIO;
301 } 358 }
302 359
303 list_add_tail(&mod->list, &io->head); 360 io->mod[mod->type] = mod;
304 361 mod->io = io;
305 return 0;
306}
307
308int rsnd_dai_disconnect(struct rsnd_mod *mod)
309{
310 list_del_init(&mod->list);
311 362
312 return 0; 363 return 0;
313} 364}
@@ -316,7 +367,7 @@ int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai)
316{ 367{
317 int id = rdai - priv->rdai; 368 int id = rdai - priv->rdai;
318 369
319 if ((id < 0) || (id >= rsnd_dai_nr(priv))) 370 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
320 return -EINVAL; 371 return -EINVAL;
321 372
322 return id; 373 return id;
@@ -324,7 +375,7 @@ int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai)
324 375
325struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id) 376struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id)
326{ 377{
327 if ((id < 0) || (id >= rsnd_dai_nr(priv))) 378 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
328 return NULL; 379 return NULL;
329 380
330 return priv->rdai + id; 381 return priv->rdai + id;
@@ -382,10 +433,6 @@ static int rsnd_dai_stream_init(struct rsnd_dai_stream *io,
382{ 433{
383 struct snd_pcm_runtime *runtime = substream->runtime; 434 struct snd_pcm_runtime *runtime = substream->runtime;
384 435
385 if (!list_empty(&io->head))
386 return -EIO;
387
388 INIT_LIST_HEAD(&io->head);
389 io->substream = substream; 436 io->substream = substream;
390 io->byte_pos = 0; 437 io->byte_pos = 0;
391 io->period_pos = 0; 438 io->period_pos = 0;
@@ -440,10 +487,6 @@ static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
440 if (ret < 0) 487 if (ret < 0)
441 goto dai_trigger_end; 488 goto dai_trigger_end;
442 489
443 ret = rsnd_gen_path_init(priv, rdai, io);
444 if (ret < 0)
445 goto dai_trigger_end;
446
447 ret = rsnd_dai_call(rdai, io, init); 490 ret = rsnd_dai_call(rdai, io, init);
448 if (ret < 0) 491 if (ret < 0)
449 goto dai_trigger_end; 492 goto dai_trigger_end;
@@ -461,10 +504,6 @@ static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
461 if (ret < 0) 504 if (ret < 0)
462 goto dai_trigger_end; 505 goto dai_trigger_end;
463 506
464 ret = rsnd_gen_path_exit(priv, rdai, io);
465 if (ret < 0)
466 goto dai_trigger_end;
467
468 ret = rsnd_platform_call(priv, dai, stop, ssi_id); 507 ret = rsnd_platform_call(priv, dai, stop, ssi_id);
469 if (ret < 0) 508 if (ret < 0)
470 goto dai_trigger_end; 509 goto dai_trigger_end;
@@ -486,10 +525,10 @@ static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
486 /* set master/slave audio interface */ 525 /* set master/slave audio interface */
487 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 526 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
488 case SND_SOC_DAIFMT_CBM_CFM: 527 case SND_SOC_DAIFMT_CBM_CFM:
489 rdai->clk_master = 1; 528 rdai->clk_master = 0;
490 break; 529 break;
491 case SND_SOC_DAIFMT_CBS_CFS: 530 case SND_SOC_DAIFMT_CBS_CFS:
492 rdai->clk_master = 0; 531 rdai->clk_master = 1; /* codec is slave, cpu is master */
493 break; 532 break;
494 default: 533 default:
495 return -EINVAL; 534 return -EINVAL;
@@ -540,24 +579,174 @@ static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
540 .set_fmt = rsnd_soc_dai_set_fmt, 579 .set_fmt = rsnd_soc_dai_set_fmt,
541}; 580};
542 581
582static int rsnd_path_init(struct rsnd_priv *priv,
583 struct rsnd_dai *rdai,
584 struct rsnd_dai_stream *io)
585{
586 struct rsnd_mod *mod;
587 struct rsnd_dai_platform_info *dai_info = rdai->info;
588 int ret;
589 int ssi_id = -1;
590 int src_id = -1;
591
592 /*
593 * Gen1 is created by SRU/SSI, and this SRU is base module of
594 * Gen2's SCU/SSIU/SSI. (Gen2 SCU/SSIU came from SRU)
595 *
596 * Easy image is..
597 * Gen1 SRU = Gen2 SCU + SSIU + etc
598 *
599 * Gen2 SCU path is very flexible, but, Gen1 SRU (SCU parts) is
600 * using fixed path.
601 */
602 if (dai_info) {
603 if (rsnd_is_enable_path(io, ssi))
604 ssi_id = rsnd_info_id(priv, io, ssi);
605 if (rsnd_is_enable_path(io, src))
606 src_id = rsnd_info_id(priv, io, src);
607 } else {
608 /* get SSI's ID */
609 mod = rsnd_ssi_mod_get_frm_dai(priv,
610 rsnd_dai_id(priv, rdai),
611 rsnd_dai_is_play(rdai, io));
612 if (!mod)
613 return 0;
614 ssi_id = src_id = rsnd_mod_id(mod);
615 }
616
617 ret = 0;
618
619 /* SRC */
620 if (src_id >= 0) {
621 mod = rsnd_src_mod_get(priv, src_id);
622 ret = rsnd_dai_connect(mod, io);
623 if (ret < 0)
624 return ret;
625 }
626
627 /* SSI */
628 if (ssi_id >= 0) {
629 mod = rsnd_ssi_mod_get(priv, ssi_id);
630 ret = rsnd_dai_connect(mod, io);
631 if (ret < 0)
632 return ret;
633 }
634
635 return ret;
636}
637
638static void rsnd_of_parse_dai(struct platform_device *pdev,
639 const struct rsnd_of_data *of_data,
640 struct rsnd_priv *priv)
641{
642 struct device_node *dai_node, *dai_np;
643 struct device_node *ssi_node, *ssi_np;
644 struct device_node *src_node, *src_np;
645 struct device_node *playback, *capture;
646 struct rsnd_dai_platform_info *dai_info;
647 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
648 struct device *dev = &pdev->dev;
649 int nr, i;
650 int dai_i, ssi_i, src_i;
651
652 if (!of_data)
653 return;
654
655 dai_node = of_get_child_by_name(dev->of_node, "rcar_sound,dai");
656 if (!dai_node)
657 return;
658
659 nr = of_get_child_count(dai_node);
660 if (!nr)
661 return;
662
663 dai_info = devm_kzalloc(dev,
664 sizeof(struct rsnd_dai_platform_info) * nr,
665 GFP_KERNEL);
666 if (!dai_info) {
667 dev_err(dev, "dai info allocation error\n");
668 return;
669 }
670
671 info->dai_info_nr = nr;
672 info->dai_info = dai_info;
673
674 ssi_node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi");
675 src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
676
677#define mod_parse(name) \
678if (name##_node) { \
679 struct rsnd_##name##_platform_info *name##_info; \
680 \
681 name##_i = 0; \
682 for_each_child_of_node(name##_node, name##_np) { \
683 name##_info = info->name##_info + name##_i; \
684 \
685 if (name##_np == playback) \
686 dai_info->playback.name = name##_info; \
687 if (name##_np == capture) \
688 dai_info->capture.name = name##_info; \
689 \
690 name##_i++; \
691 } \
692}
693
694 /*
695 * parse all dai
696 */
697 dai_i = 0;
698 for_each_child_of_node(dai_node, dai_np) {
699 dai_info = info->dai_info + dai_i;
700
701 for (i = 0;; i++) {
702
703 playback = of_parse_phandle(dai_np, "playback", i);
704 capture = of_parse_phandle(dai_np, "capture", i);
705
706 if (!playback && !capture)
707 break;
708
709 mod_parse(ssi);
710 mod_parse(src);
711
712 if (playback)
713 of_node_put(playback);
714 if (capture)
715 of_node_put(capture);
716 }
717
718 dai_i++;
719 }
720}
721
543static int rsnd_dai_probe(struct platform_device *pdev, 722static int rsnd_dai_probe(struct platform_device *pdev,
544 struct rcar_snd_info *info, 723 const struct rsnd_of_data *of_data,
545 struct rsnd_priv *priv) 724 struct rsnd_priv *priv)
546{ 725{
547 struct snd_soc_dai_driver *drv; 726 struct snd_soc_dai_driver *drv;
727 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
548 struct rsnd_dai *rdai; 728 struct rsnd_dai *rdai;
549 struct rsnd_mod *pmod, *cmod; 729 struct rsnd_mod *pmod, *cmod;
550 struct device *dev = rsnd_priv_to_dev(priv); 730 struct device *dev = rsnd_priv_to_dev(priv);
551 int dai_nr; 731 int dai_nr;
552 int i; 732 int i;
553 733
554 /* get max dai nr */ 734 rsnd_of_parse_dai(pdev, of_data, priv);
555 for (dai_nr = 0; dai_nr < 32; dai_nr++) {
556 pmod = rsnd_ssi_mod_get_frm_dai(priv, dai_nr, 1);
557 cmod = rsnd_ssi_mod_get_frm_dai(priv, dai_nr, 0);
558 735
559 if (!pmod && !cmod) 736 /*
560 break; 737 * dai_nr should be set via dai_info_nr,
738 * but allow it to keeping compatible
739 */
740 dai_nr = info->dai_info_nr;
741 if (!dai_nr) {
742 /* get max dai nr */
743 for (dai_nr = 0; dai_nr < 32; dai_nr++) {
744 pmod = rsnd_ssi_mod_get_frm_dai(priv, dai_nr, 1);
745 cmod = rsnd_ssi_mod_get_frm_dai(priv, dai_nr, 0);
746
747 if (!pmod && !cmod)
748 break;
749 }
561 } 750 }
562 751
563 if (!dai_nr) { 752 if (!dai_nr) {
@@ -572,7 +761,13 @@ static int rsnd_dai_probe(struct platform_device *pdev,
572 return -ENOMEM; 761 return -ENOMEM;
573 } 762 }
574 763
764 priv->rdai_nr = dai_nr;
765 priv->daidrv = drv;
766 priv->rdai = rdai;
767
575 for (i = 0; i < dai_nr; i++) { 768 for (i = 0; i < dai_nr; i++) {
769 if (info->dai_info)
770 rdai[i].info = &info->dai_info[i];
576 771
577 pmod = rsnd_ssi_mod_get_frm_dai(priv, i, 1); 772 pmod = rsnd_ssi_mod_get_frm_dai(priv, i, 1);
578 cmod = rsnd_ssi_mod_get_frm_dai(priv, i, 0); 773 cmod = rsnd_ssi_mod_get_frm_dai(priv, i, 0);
@@ -580,9 +775,6 @@ static int rsnd_dai_probe(struct platform_device *pdev,
580 /* 775 /*
581 * init rsnd_dai 776 * init rsnd_dai
582 */ 777 */
583 INIT_LIST_HEAD(&rdai[i].playback.head);
584 INIT_LIST_HEAD(&rdai[i].capture.head);
585
586 snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i); 778 snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i);
587 779
588 /* 780 /*
@@ -595,12 +787,20 @@ static int rsnd_dai_probe(struct platform_device *pdev,
595 drv[i].playback.formats = RSND_FMTS; 787 drv[i].playback.formats = RSND_FMTS;
596 drv[i].playback.channels_min = 2; 788 drv[i].playback.channels_min = 2;
597 drv[i].playback.channels_max = 2; 789 drv[i].playback.channels_max = 2;
790
791 if (info->dai_info)
792 rdai[i].playback.info = &info->dai_info[i].playback;
793 rsnd_path_init(priv, &rdai[i], &rdai[i].playback);
598 } 794 }
599 if (cmod) { 795 if (cmod) {
600 drv[i].capture.rates = RSND_RATES; 796 drv[i].capture.rates = RSND_RATES;
601 drv[i].capture.formats = RSND_FMTS; 797 drv[i].capture.formats = RSND_FMTS;
602 drv[i].capture.channels_min = 2; 798 drv[i].capture.channels_min = 2;
603 drv[i].capture.channels_max = 2; 799 drv[i].capture.channels_max = 2;
800
801 if (info->dai_info)
802 rdai[i].capture.info = &info->dai_info[i].capture;
803 rsnd_path_init(priv, &rdai[i], &rdai[i].capture);
604 } 804 }
605 805
606 dev_dbg(dev, "%s (%s/%s)\n", rdai[i].name, 806 dev_dbg(dev, "%s (%s/%s)\n", rdai[i].name,
@@ -608,18 +808,9 @@ static int rsnd_dai_probe(struct platform_device *pdev,
608 cmod ? "capture" : " -- "); 808 cmod ? "capture" : " -- ");
609 } 809 }
610 810
611 priv->dai_nr = dai_nr;
612 priv->daidrv = drv;
613 priv->rdai = rdai;
614
615 return 0; 811 return 0;
616} 812}
617 813
618static void rsnd_dai_remove(struct platform_device *pdev,
619 struct rsnd_priv *priv)
620{
621}
622
623/* 814/*
624 * pcm ops 815 * pcm ops
625 */ 816 */
@@ -713,9 +904,30 @@ static int rsnd_probe(struct platform_device *pdev)
713 struct rcar_snd_info *info; 904 struct rcar_snd_info *info;
714 struct rsnd_priv *priv; 905 struct rsnd_priv *priv;
715 struct device *dev = &pdev->dev; 906 struct device *dev = &pdev->dev;
716 int ret; 907 struct rsnd_dai *rdai;
908 const struct of_device_id *of_id = of_match_device(rsnd_of_match, dev);
909 const struct rsnd_of_data *of_data;
910 int (*probe_func[])(struct platform_device *pdev,
911 const struct rsnd_of_data *of_data,
912 struct rsnd_priv *priv) = {
913 rsnd_gen_probe,
914 rsnd_ssi_probe,
915 rsnd_src_probe,
916 rsnd_adg_probe,
917 rsnd_dai_probe,
918 };
919 int ret, i;
920
921 info = NULL;
922 of_data = NULL;
923 if (of_id) {
924 info = devm_kzalloc(&pdev->dev,
925 sizeof(struct rcar_snd_info), GFP_KERNEL);
926 of_data = of_id->data;
927 } else {
928 info = pdev->dev.platform_data;
929 }
717 930
718 info = pdev->dev.platform_data;
719 if (!info) { 931 if (!info) {
720 dev_err(dev, "driver needs R-Car sound information\n"); 932 dev_err(dev, "driver needs R-Car sound information\n");
721 return -ENODEV; 933 return -ENODEV;
@@ -737,25 +949,21 @@ static int rsnd_probe(struct platform_device *pdev)
737 /* 949 /*
738 * init each module 950 * init each module
739 */ 951 */
740 ret = rsnd_gen_probe(pdev, info, priv); 952 for (i = 0; i < ARRAY_SIZE(probe_func); i++) {
741 if (ret < 0) 953 ret = probe_func[i](pdev, of_data, priv);
742 return ret; 954 if (ret)
743 955 return ret;
744 ret = rsnd_scu_probe(pdev, info, priv); 956 }
745 if (ret < 0)
746 return ret;
747 957
748 ret = rsnd_adg_probe(pdev, info, priv); 958 for_each_rsnd_dai(rdai, priv, i) {
749 if (ret < 0) 959 ret = rsnd_dai_call(rdai, &rdai->playback, probe);
750 return ret; 960 if (ret)
961 return ret;
751 962
752 ret = rsnd_ssi_probe(pdev, info, priv); 963 ret = rsnd_dai_call(rdai, &rdai->capture, probe);
753 if (ret < 0) 964 if (ret)
754 return ret; 965 return ret;
755 966 }
756 ret = rsnd_dai_probe(pdev, info, priv);
757 if (ret < 0)
758 return ret;
759 967
760 /* 968 /*
761 * asoc register 969 * asoc register
@@ -767,7 +975,7 @@ static int rsnd_probe(struct platform_device *pdev)
767 } 975 }
768 976
769 ret = snd_soc_register_component(dev, &rsnd_soc_component, 977 ret = snd_soc_register_component(dev, &rsnd_soc_component,
770 priv->daidrv, rsnd_dai_nr(priv)); 978 priv->daidrv, rsnd_rdai_nr(priv));
771 if (ret < 0) { 979 if (ret < 0) {
772 dev_err(dev, "cannot snd dai register\n"); 980 dev_err(dev, "cannot snd dai register\n");
773 goto exit_snd_soc; 981 goto exit_snd_soc;
@@ -789,17 +997,20 @@ exit_snd_soc:
789static int rsnd_remove(struct platform_device *pdev) 997static int rsnd_remove(struct platform_device *pdev)
790{ 998{
791 struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev); 999 struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev);
1000 struct rsnd_dai *rdai;
1001 int ret, i;
792 1002
793 pm_runtime_disable(&pdev->dev); 1003 pm_runtime_disable(&pdev->dev);
794 1004
795 /* 1005 for_each_rsnd_dai(rdai, priv, i) {
796 * remove each module 1006 ret = rsnd_dai_call(rdai, &rdai->playback, remove);
797 */ 1007 if (ret)
798 rsnd_ssi_remove(pdev, priv); 1008 return ret;
799 rsnd_adg_remove(pdev, priv); 1009
800 rsnd_scu_remove(pdev, priv); 1010 ret = rsnd_dai_call(rdai, &rdai->capture, remove);
801 rsnd_dai_remove(pdev, priv); 1011 if (ret)
802 rsnd_gen_remove(pdev, priv); 1012 return ret;
1013 }
803 1014
804 return 0; 1015 return 0;
805} 1016}
@@ -807,6 +1018,7 @@ static int rsnd_remove(struct platform_device *pdev)
807static struct platform_driver rsnd_driver = { 1018static struct platform_driver rsnd_driver = {
808 .driver = { 1019 .driver = {
809 .name = "rcar_sound", 1020 .name = "rcar_sound",
1021 .of_match_table = rsnd_of_match,
810 }, 1022 },
811 .probe = rsnd_probe, 1023 .probe = rsnd_probe,
812 .remove = rsnd_remove, 1024 .remove = rsnd_remove,
diff --git a/sound/soc/sh/rcar/gen.c b/sound/soc/sh/rcar/gen.c
index add088bd4b2a..50a1ef3eb1c6 100644
--- a/sound/soc/sh/rcar/gen.c
+++ b/sound/soc/sh/rcar/gen.c
@@ -155,62 +155,6 @@ static int rsnd_gen_regmap_init(struct rsnd_priv *priv,
155 return 0; 155 return 0;
156} 156}
157 157
158int rsnd_gen_path_init(struct rsnd_priv *priv,
159 struct rsnd_dai *rdai,
160 struct rsnd_dai_stream *io)
161{
162 struct rsnd_mod *mod;
163 int ret;
164 int id;
165
166 /*
167 * Gen1 is created by SRU/SSI, and this SRU is base module of
168 * Gen2's SCU/SSIU/SSI. (Gen2 SCU/SSIU came from SRU)
169 *
170 * Easy image is..
171 * Gen1 SRU = Gen2 SCU + SSIU + etc
172 *
173 * Gen2 SCU path is very flexible, but, Gen1 SRU (SCU parts) is
174 * using fixed path.
175 *
176 * Then, SSI id = SCU id here
177 */
178
179 /* get SSI's ID */
180 mod = rsnd_ssi_mod_get_frm_dai(priv,
181 rsnd_dai_id(priv, rdai),
182 rsnd_dai_is_play(rdai, io));
183 id = rsnd_mod_id(mod);
184
185 /* SSI */
186 mod = rsnd_ssi_mod_get(priv, id);
187 ret = rsnd_dai_connect(rdai, mod, io);
188 if (ret < 0)
189 return ret;
190
191 /* SCU */
192 mod = rsnd_scu_mod_get(priv, id);
193 ret = rsnd_dai_connect(rdai, mod, io);
194
195 return ret;
196}
197
198int rsnd_gen_path_exit(struct rsnd_priv *priv,
199 struct rsnd_dai *rdai,
200 struct rsnd_dai_stream *io)
201{
202 struct rsnd_mod *mod, *n;
203 int ret = 0;
204
205 /*
206 * remove all mod from rdai
207 */
208 for_each_rsnd_mod(mod, n, io)
209 ret |= rsnd_dai_disconnect(mod);
210
211 return ret;
212}
213
214/* 158/*
215 * Gen2 159 * Gen2
216 */ 160 */
@@ -229,14 +173,40 @@ static int rsnd_gen2_regmap_init(struct rsnd_priv *priv, struct rsnd_gen *gen)
229 RSND_GEN2_S_REG(gen, SSIU, SSI_MODE0, 0x800), 173 RSND_GEN2_S_REG(gen, SSIU, SSI_MODE0, 0x800),
230 RSND_GEN2_S_REG(gen, SSIU, SSI_MODE1, 0x804), 174 RSND_GEN2_S_REG(gen, SSIU, SSI_MODE1, 0x804),
231 /* FIXME: it needs SSI_MODE2/3 in the future */ 175 /* FIXME: it needs SSI_MODE2/3 in the future */
176 RSND_GEN2_M_REG(gen, SSIU, SSI_BUSIF_MODE, 0x0, 0x80),
177 RSND_GEN2_M_REG(gen, SSIU, SSI_BUSIF_ADINR,0x4, 0x80),
178 RSND_GEN2_M_REG(gen, SSIU, SSI_CTRL, 0x10, 0x80),
232 RSND_GEN2_M_REG(gen, SSIU, INT_ENABLE, 0x18, 0x80), 179 RSND_GEN2_M_REG(gen, SSIU, INT_ENABLE, 0x18, 0x80),
233 180
181 RSND_GEN2_M_REG(gen, SCU, SRC_BUSIF_MODE, 0x0, 0x20),
182 RSND_GEN2_M_REG(gen, SCU, SRC_ROUTE_MODE0,0xc, 0x20),
183 RSND_GEN2_M_REG(gen, SCU, SRC_CTRL, 0x10, 0x20),
184 RSND_GEN2_M_REG(gen, SCU, SRC_SWRSR, 0x200, 0x40),
185 RSND_GEN2_M_REG(gen, SCU, SRC_SRCIR, 0x204, 0x40),
186 RSND_GEN2_M_REG(gen, SCU, SRC_ADINR, 0x214, 0x40),
187 RSND_GEN2_M_REG(gen, SCU, SRC_IFSCR, 0x21c, 0x40),
188 RSND_GEN2_M_REG(gen, SCU, SRC_IFSVR, 0x220, 0x40),
189 RSND_GEN2_M_REG(gen, SCU, SRC_SRCCR, 0x224, 0x40),
190 RSND_GEN2_M_REG(gen, SCU, SRC_BSDSR, 0x22c, 0x40),
191 RSND_GEN2_M_REG(gen, SCU, SRC_BSISR, 0x238, 0x40),
192
234 RSND_GEN2_S_REG(gen, ADG, BRRA, 0x00), 193 RSND_GEN2_S_REG(gen, ADG, BRRA, 0x00),
235 RSND_GEN2_S_REG(gen, ADG, BRRB, 0x04), 194 RSND_GEN2_S_REG(gen, ADG, BRRB, 0x04),
236 RSND_GEN2_S_REG(gen, ADG, SSICKR, 0x08), 195 RSND_GEN2_S_REG(gen, ADG, SSICKR, 0x08),
237 RSND_GEN2_S_REG(gen, ADG, AUDIO_CLK_SEL0, 0x0c), 196 RSND_GEN2_S_REG(gen, ADG, AUDIO_CLK_SEL0, 0x0c),
238 RSND_GEN2_S_REG(gen, ADG, AUDIO_CLK_SEL1, 0x10), 197 RSND_GEN2_S_REG(gen, ADG, AUDIO_CLK_SEL1, 0x10),
239 RSND_GEN2_S_REG(gen, ADG, AUDIO_CLK_SEL2, 0x14), 198 RSND_GEN2_S_REG(gen, ADG, AUDIO_CLK_SEL2, 0x14),
199 RSND_GEN2_S_REG(gen, ADG, DIV_EN, 0x30),
200 RSND_GEN2_S_REG(gen, ADG, SRCIN_TIMSEL0, 0x34),
201 RSND_GEN2_S_REG(gen, ADG, SRCIN_TIMSEL1, 0x38),
202 RSND_GEN2_S_REG(gen, ADG, SRCIN_TIMSEL2, 0x3c),
203 RSND_GEN2_S_REG(gen, ADG, SRCIN_TIMSEL3, 0x40),
204 RSND_GEN2_S_REG(gen, ADG, SRCIN_TIMSEL4, 0x44),
205 RSND_GEN2_S_REG(gen, ADG, SRCOUT_TIMSEL0, 0x48),
206 RSND_GEN2_S_REG(gen, ADG, SRCOUT_TIMSEL1, 0x4c),
207 RSND_GEN2_S_REG(gen, ADG, SRCOUT_TIMSEL2, 0x50),
208 RSND_GEN2_S_REG(gen, ADG, SRCOUT_TIMSEL3, 0x54),
209 RSND_GEN2_S_REG(gen, ADG, SRCOUT_TIMSEL4, 0x58),
240 210
241 RSND_GEN2_M_REG(gen, SSI, SSICR, 0x00, 0x40), 211 RSND_GEN2_M_REG(gen, SSI, SSICR, 0x00, 0x40),
242 RSND_GEN2_M_REG(gen, SSI, SSISR, 0x04, 0x40), 212 RSND_GEN2_M_REG(gen, SSI, SSISR, 0x04, 0x40),
@@ -249,7 +219,6 @@ static int rsnd_gen2_regmap_init(struct rsnd_priv *priv, struct rsnd_gen *gen)
249} 219}
250 220
251static int rsnd_gen2_probe(struct platform_device *pdev, 221static int rsnd_gen2_probe(struct platform_device *pdev,
252 struct rcar_snd_info *info,
253 struct rsnd_priv *priv) 222 struct rsnd_priv *priv)
254{ 223{
255 struct device *dev = rsnd_priv_to_dev(priv); 224 struct device *dev = rsnd_priv_to_dev(priv);
@@ -283,7 +252,7 @@ static int rsnd_gen2_probe(struct platform_device *pdev,
283 return ret; 252 return ret;
284 253
285 dev_dbg(dev, "Gen2 device probed\n"); 254 dev_dbg(dev, "Gen2 device probed\n");
286 dev_dbg(dev, "SRU : %08x => %p\n", scu_res->start, 255 dev_dbg(dev, "SCU : %08x => %p\n", scu_res->start,
287 gen->base[RSND_GEN2_SCU]); 256 gen->base[RSND_GEN2_SCU]);
288 dev_dbg(dev, "ADG : %08x => %p\n", adg_res->start, 257 dev_dbg(dev, "ADG : %08x => %p\n", adg_res->start,
289 gen->base[RSND_GEN2_ADG]); 258 gen->base[RSND_GEN2_ADG]);
@@ -317,7 +286,7 @@ static int rsnd_gen1_regmap_init(struct rsnd_priv *priv, struct rsnd_gen *gen)
317 RSND_GEN1_S_REG(gen, SRU, SRC_ROUTE_CTRL, 0xc0), 286 RSND_GEN1_S_REG(gen, SRU, SRC_ROUTE_CTRL, 0xc0),
318 RSND_GEN1_S_REG(gen, SRU, SSI_MODE0, 0xD0), 287 RSND_GEN1_S_REG(gen, SRU, SSI_MODE0, 0xD0),
319 RSND_GEN1_S_REG(gen, SRU, SSI_MODE1, 0xD4), 288 RSND_GEN1_S_REG(gen, SRU, SSI_MODE1, 0xD4),
320 RSND_GEN1_M_REG(gen, SRU, BUSIF_MODE, 0x20, 0x4), 289 RSND_GEN1_M_REG(gen, SRU, SRC_BUSIF_MODE, 0x20, 0x4),
321 RSND_GEN1_M_REG(gen, SRU, SRC_ROUTE_MODE0,0x50, 0x8), 290 RSND_GEN1_M_REG(gen, SRU, SRC_ROUTE_MODE0,0x50, 0x8),
322 RSND_GEN1_M_REG(gen, SRU, SRC_SWRSR, 0x200, 0x40), 291 RSND_GEN1_M_REG(gen, SRU, SRC_SWRSR, 0x200, 0x40),
323 RSND_GEN1_M_REG(gen, SRU, SRC_SRCIR, 0x204, 0x40), 292 RSND_GEN1_M_REG(gen, SRU, SRC_SRCIR, 0x204, 0x40),
@@ -347,7 +316,6 @@ static int rsnd_gen1_regmap_init(struct rsnd_priv *priv, struct rsnd_gen *gen)
347} 316}
348 317
349static int rsnd_gen1_probe(struct platform_device *pdev, 318static int rsnd_gen1_probe(struct platform_device *pdev,
350 struct rcar_snd_info *info,
351 struct rsnd_priv *priv) 319 struct rsnd_priv *priv)
352{ 320{
353 struct device *dev = rsnd_priv_to_dev(priv); 321 struct device *dev = rsnd_priv_to_dev(priv);
@@ -391,14 +359,28 @@ static int rsnd_gen1_probe(struct platform_device *pdev,
391/* 359/*
392 * Gen 360 * Gen
393 */ 361 */
362static void rsnd_of_parse_gen(struct platform_device *pdev,
363 const struct rsnd_of_data *of_data,
364 struct rsnd_priv *priv)
365{
366 struct rcar_snd_info *info = priv->info;
367
368 if (!of_data)
369 return;
370
371 info->flags = of_data->flags;
372}
373
394int rsnd_gen_probe(struct platform_device *pdev, 374int rsnd_gen_probe(struct platform_device *pdev,
395 struct rcar_snd_info *info, 375 const struct rsnd_of_data *of_data,
396 struct rsnd_priv *priv) 376 struct rsnd_priv *priv)
397{ 377{
398 struct device *dev = rsnd_priv_to_dev(priv); 378 struct device *dev = rsnd_priv_to_dev(priv);
399 struct rsnd_gen *gen; 379 struct rsnd_gen *gen;
400 int ret; 380 int ret;
401 381
382 rsnd_of_parse_gen(pdev, of_data, priv);
383
402 gen = devm_kzalloc(dev, sizeof(*gen), GFP_KERNEL); 384 gen = devm_kzalloc(dev, sizeof(*gen), GFP_KERNEL);
403 if (!gen) { 385 if (!gen) {
404 dev_err(dev, "GEN allocate failed\n"); 386 dev_err(dev, "GEN allocate failed\n");
@@ -409,17 +391,12 @@ int rsnd_gen_probe(struct platform_device *pdev,
409 391
410 ret = -ENODEV; 392 ret = -ENODEV;
411 if (rsnd_is_gen1(priv)) 393 if (rsnd_is_gen1(priv))
412 ret = rsnd_gen1_probe(pdev, info, priv); 394 ret = rsnd_gen1_probe(pdev, priv);
413 else if (rsnd_is_gen2(priv)) 395 else if (rsnd_is_gen2(priv))
414 ret = rsnd_gen2_probe(pdev, info, priv); 396 ret = rsnd_gen2_probe(pdev, priv);
415 397
416 if (ret < 0) 398 if (ret < 0)
417 dev_err(dev, "unknown generation R-Car sound device\n"); 399 dev_err(dev, "unknown generation R-Car sound device\n");
418 400
419 return ret; 401 return ret;
420} 402}
421
422void rsnd_gen_remove(struct platform_device *pdev,
423 struct rsnd_priv *priv)
424{
425}
diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h
index 4ca66cd899c8..619d198c7d2e 100644
--- a/sound/soc/sh/rcar/rsnd.h
+++ b/sound/soc/sh/rcar/rsnd.h
@@ -17,6 +17,8 @@
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/of_device.h>
21#include <linux/of_irq.h>
20#include <linux/sh_dma.h> 22#include <linux/sh_dma.h>
21#include <linux/workqueue.h> 23#include <linux/workqueue.h>
22#include <sound/rcar_snd.h> 24#include <sound/rcar_snd.h>
@@ -32,15 +34,9 @@
32 */ 34 */
33enum rsnd_reg { 35enum rsnd_reg {
34 /* SRU/SCU/SSIU */ 36 /* SRU/SCU/SSIU */
35 RSND_REG_SRC_ROUTE_SEL, /* for Gen1 */
36 RSND_REG_SRC_TMG_SEL0, /* for Gen1 */
37 RSND_REG_SRC_TMG_SEL1, /* for Gen1 */
38 RSND_REG_SRC_TMG_SEL2, /* for Gen1 */
39 RSND_REG_SRC_ROUTE_CTRL, /* for Gen1 */
40 RSND_REG_SSI_MODE0, 37 RSND_REG_SSI_MODE0,
41 RSND_REG_SSI_MODE1, 38 RSND_REG_SSI_MODE1,
42 RSND_REG_BUSIF_MODE, 39 RSND_REG_SRC_BUSIF_MODE,
43 RSND_REG_INT_ENABLE, /* for Gen2 */
44 RSND_REG_SRC_ROUTE_MODE0, 40 RSND_REG_SRC_ROUTE_MODE0,
45 RSND_REG_SRC_SWRSR, 41 RSND_REG_SRC_SWRSR,
46 RSND_REG_SRC_SRCIR, 42 RSND_REG_SRC_SRCIR,
@@ -48,7 +44,6 @@ enum rsnd_reg {
48 RSND_REG_SRC_IFSCR, 44 RSND_REG_SRC_IFSCR,
49 RSND_REG_SRC_IFSVR, 45 RSND_REG_SRC_IFSVR,
50 RSND_REG_SRC_SRCCR, 46 RSND_REG_SRC_SRCCR,
51 RSND_REG_SRC_MNFSR,
52 47
53 /* ADG */ 48 /* ADG */
54 RSND_REG_BRRA, 49 RSND_REG_BRRA,
@@ -56,10 +51,6 @@ enum rsnd_reg {
56 RSND_REG_SSICKR, 51 RSND_REG_SSICKR,
57 RSND_REG_AUDIO_CLK_SEL0, 52 RSND_REG_AUDIO_CLK_SEL0,
58 RSND_REG_AUDIO_CLK_SEL1, 53 RSND_REG_AUDIO_CLK_SEL1,
59 RSND_REG_AUDIO_CLK_SEL2,
60 RSND_REG_AUDIO_CLK_SEL3, /* for Gen1 */
61 RSND_REG_AUDIO_CLK_SEL4, /* for Gen1 */
62 RSND_REG_AUDIO_CLK_SEL5, /* for Gen1 */
63 54
64 /* SSI */ 55 /* SSI */
65 RSND_REG_SSICR, 56 RSND_REG_SSICR,
@@ -68,9 +59,63 @@ enum rsnd_reg {
68 RSND_REG_SSIRDR, 59 RSND_REG_SSIRDR,
69 RSND_REG_SSIWSR, 60 RSND_REG_SSIWSR,
70 61
62 /* SHARE see below */
63 RSND_REG_SHARE01,
64 RSND_REG_SHARE02,
65 RSND_REG_SHARE03,
66 RSND_REG_SHARE04,
67 RSND_REG_SHARE05,
68 RSND_REG_SHARE06,
69 RSND_REG_SHARE07,
70 RSND_REG_SHARE08,
71 RSND_REG_SHARE09,
72 RSND_REG_SHARE10,
73 RSND_REG_SHARE11,
74 RSND_REG_SHARE12,
75 RSND_REG_SHARE13,
76 RSND_REG_SHARE14,
77 RSND_REG_SHARE15,
78 RSND_REG_SHARE16,
79 RSND_REG_SHARE17,
80 RSND_REG_SHARE18,
81 RSND_REG_SHARE19,
82
71 RSND_REG_MAX, 83 RSND_REG_MAX,
72}; 84};
73 85
86/* Gen1 only */
87#define RSND_REG_SRC_ROUTE_SEL RSND_REG_SHARE01
88#define RSND_REG_SRC_TMG_SEL0 RSND_REG_SHARE02
89#define RSND_REG_SRC_TMG_SEL1 RSND_REG_SHARE03
90#define RSND_REG_SRC_TMG_SEL2 RSND_REG_SHARE04
91#define RSND_REG_SRC_ROUTE_CTRL RSND_REG_SHARE05
92#define RSND_REG_SRC_MNFSR RSND_REG_SHARE06
93#define RSND_REG_AUDIO_CLK_SEL3 RSND_REG_SHARE07
94#define RSND_REG_AUDIO_CLK_SEL4 RSND_REG_SHARE08
95#define RSND_REG_AUDIO_CLK_SEL5 RSND_REG_SHARE09
96
97/* Gen2 only */
98#define RSND_REG_SRC_CTRL RSND_REG_SHARE01
99#define RSND_REG_SSI_CTRL RSND_REG_SHARE02
100#define RSND_REG_SSI_BUSIF_MODE RSND_REG_SHARE03
101#define RSND_REG_SSI_BUSIF_ADINR RSND_REG_SHARE04
102#define RSND_REG_INT_ENABLE RSND_REG_SHARE05
103#define RSND_REG_SRC_BSDSR RSND_REG_SHARE06
104#define RSND_REG_SRC_BSISR RSND_REG_SHARE07
105#define RSND_REG_DIV_EN RSND_REG_SHARE08
106#define RSND_REG_SRCIN_TIMSEL0 RSND_REG_SHARE09
107#define RSND_REG_SRCIN_TIMSEL1 RSND_REG_SHARE10
108#define RSND_REG_SRCIN_TIMSEL2 RSND_REG_SHARE11
109#define RSND_REG_SRCIN_TIMSEL3 RSND_REG_SHARE12
110#define RSND_REG_SRCIN_TIMSEL4 RSND_REG_SHARE13
111#define RSND_REG_SRCOUT_TIMSEL0 RSND_REG_SHARE14
112#define RSND_REG_SRCOUT_TIMSEL1 RSND_REG_SHARE15
113#define RSND_REG_SRCOUT_TIMSEL2 RSND_REG_SHARE16
114#define RSND_REG_SRCOUT_TIMSEL3 RSND_REG_SHARE17
115#define RSND_REG_SRCOUT_TIMSEL4 RSND_REG_SHARE18
116#define RSND_REG_AUDIO_CLK_SEL2 RSND_REG_SHARE19
117
118struct rsnd_of_data;
74struct rsnd_priv; 119struct rsnd_priv;
75struct rsnd_mod; 120struct rsnd_mod;
76struct rsnd_dai; 121struct rsnd_dai;
@@ -96,24 +141,20 @@ void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
96 * R-Car DMA 141 * R-Car DMA
97 */ 142 */
98struct rsnd_dma { 143struct rsnd_dma {
99 struct rsnd_priv *priv;
100 struct sh_dmae_slave slave; 144 struct sh_dmae_slave slave;
101 struct work_struct work; 145 struct work_struct work;
102 struct dma_chan *chan; 146 struct dma_chan *chan;
103 enum dma_data_direction dir; 147 enum dma_data_direction dir;
104 int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len);
105 int (*complete)(struct rsnd_dma *dma);
106 148
107 int submit_loop; 149 int submit_loop;
150 int offset; /* it cares A/B plane */
108}; 151};
109 152
110void rsnd_dma_start(struct rsnd_dma *dma); 153void rsnd_dma_start(struct rsnd_dma *dma);
111void rsnd_dma_stop(struct rsnd_dma *dma); 154void rsnd_dma_stop(struct rsnd_dma *dma);
112int rsnd_dma_available(struct rsnd_dma *dma); 155int rsnd_dma_available(struct rsnd_dma *dma);
113int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, 156int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
114 int is_play, int id, 157 int is_play, int id);
115 int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len),
116 int (*complete)(struct rsnd_dma *dma));
117void rsnd_dma_quit(struct rsnd_priv *priv, 158void rsnd_dma_quit(struct rsnd_priv *priv,
118 struct rsnd_dma *dma); 159 struct rsnd_dma *dma);
119 160
@@ -121,9 +162,20 @@ void rsnd_dma_quit(struct rsnd_priv *priv,
121/* 162/*
122 * R-Car sound mod 163 * R-Car sound mod
123 */ 164 */
165enum rsnd_mod_type {
166 RSND_MOD_SRC = 0,
167 RSND_MOD_SSI,
168 RSND_MOD_MAX,
169};
124 170
125struct rsnd_mod_ops { 171struct rsnd_mod_ops {
126 char *name; 172 char *name;
173 int (*probe)(struct rsnd_mod *mod,
174 struct rsnd_dai *rdai,
175 struct rsnd_dai_stream *io);
176 int (*remove)(struct rsnd_mod *mod,
177 struct rsnd_dai *rdai,
178 struct rsnd_dai_stream *io);
127 int (*init)(struct rsnd_mod *mod, 179 int (*init)(struct rsnd_mod *mod,
128 struct rsnd_dai *rdai, 180 struct rsnd_dai *rdai,
129 struct rsnd_dai_stream *io); 181 struct rsnd_dai_stream *io);
@@ -138,28 +190,26 @@ struct rsnd_mod_ops {
138 struct rsnd_dai_stream *io); 190 struct rsnd_dai_stream *io);
139}; 191};
140 192
193struct rsnd_dai_stream;
141struct rsnd_mod { 194struct rsnd_mod {
142 int id; 195 int id;
196 enum rsnd_mod_type type;
143 struct rsnd_priv *priv; 197 struct rsnd_priv *priv;
144 struct rsnd_mod_ops *ops; 198 struct rsnd_mod_ops *ops;
145 struct list_head list; /* connect to rsnd_dai playback/capture */
146 struct rsnd_dma dma; 199 struct rsnd_dma dma;
200 struct rsnd_dai_stream *io;
147}; 201};
148 202
149#define rsnd_mod_to_priv(mod) ((mod)->priv) 203#define rsnd_mod_to_priv(mod) ((mod)->priv)
150#define rsnd_mod_to_dma(mod) (&(mod)->dma) 204#define rsnd_mod_to_dma(mod) (&(mod)->dma)
151#define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma) 205#define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma)
206#define rsnd_mod_to_io(mod) ((mod)->io)
152#define rsnd_mod_id(mod) ((mod)->id) 207#define rsnd_mod_id(mod) ((mod)->id)
153#define for_each_rsnd_mod(pos, n, io) \
154 list_for_each_entry_safe(pos, n, &(io)->head, list)
155#define rsnd_mod_call(mod, func, rdai, io) \
156 (!(mod) ? -ENODEV : \
157 !((mod)->ops->func) ? 0 : \
158 (mod)->ops->func(mod, rdai, io))
159 208
160void rsnd_mod_init(struct rsnd_priv *priv, 209void rsnd_mod_init(struct rsnd_priv *priv,
161 struct rsnd_mod *mod, 210 struct rsnd_mod *mod,
162 struct rsnd_mod_ops *ops, 211 struct rsnd_mod_ops *ops,
212 enum rsnd_mod_type type,
163 int id); 213 int id);
164char *rsnd_mod_name(struct rsnd_mod *mod); 214char *rsnd_mod_name(struct rsnd_mod *mod);
165 215
@@ -168,13 +218,16 @@ char *rsnd_mod_name(struct rsnd_mod *mod);
168 */ 218 */
169#define RSND_DAI_NAME_SIZE 16 219#define RSND_DAI_NAME_SIZE 16
170struct rsnd_dai_stream { 220struct rsnd_dai_stream {
171 struct list_head head; /* head of rsnd_mod list */
172 struct snd_pcm_substream *substream; 221 struct snd_pcm_substream *substream;
222 struct rsnd_mod *mod[RSND_MOD_MAX];
223 struct rsnd_dai_path_info *info; /* rcar_snd.h */
173 int byte_pos; 224 int byte_pos;
174 int period_pos; 225 int period_pos;
175 int byte_per_period; 226 int byte_per_period;
176 int next_period_byte; 227 int next_period_byte;
177}; 228};
229#define rsnd_io_to_mod_ssi(io) ((io)->mod[RSND_MOD_SSI])
230#define rsnd_io_to_mod_src(io) ((io)->mod[RSND_MOD_SRC])
178 231
179struct rsnd_dai { 232struct rsnd_dai {
180 char name[RSND_DAI_NAME_SIZE]; 233 char name[RSND_DAI_NAME_SIZE];
@@ -189,16 +242,14 @@ struct rsnd_dai {
189 unsigned int data_alignment:1; 242 unsigned int data_alignment:1;
190}; 243};
191 244
192#define rsnd_dai_nr(priv) ((priv)->dai_nr) 245#define rsnd_rdai_nr(priv) ((priv)->rdai_nr)
193#define for_each_rsnd_dai(rdai, priv, i) \ 246#define for_each_rsnd_dai(rdai, priv, i) \
194 for (i = 0, (rdai) = rsnd_dai_get(priv, i); \ 247 for (i = 0; \
195 i < rsnd_dai_nr(priv); \ 248 (i < rsnd_rdai_nr(priv)) && \
196 i++, (rdai) = rsnd_dai_get(priv, i)) 249 ((rdai) = rsnd_dai_get(priv, i)); \
250 i++)
197 251
198struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id); 252struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id);
199int rsnd_dai_disconnect(struct rsnd_mod *mod);
200int rsnd_dai_connect(struct rsnd_dai *rdai, struct rsnd_mod *mod,
201 struct rsnd_dai_stream *io);
202int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io); 253int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io);
203int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai); 254int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai);
204#define rsnd_dai_get_platform_info(rdai) ((rdai)->info) 255#define rsnd_dai_get_platform_info(rdai) ((rdai)->info)
@@ -206,21 +257,14 @@ int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai);
206 257
207void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt); 258void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
208int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional); 259int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
260#define rsnd_dai_is_clk_master(rdai) ((rdai)->clk_master)
209 261
210/* 262/*
211 * R-Car Gen1/Gen2 263 * R-Car Gen1/Gen2
212 */ 264 */
213int rsnd_gen_probe(struct platform_device *pdev, 265int rsnd_gen_probe(struct platform_device *pdev,
214 struct rcar_snd_info *info, 266 const struct rsnd_of_data *of_data,
215 struct rsnd_priv *priv); 267 struct rsnd_priv *priv);
216void rsnd_gen_remove(struct platform_device *pdev,
217 struct rsnd_priv *priv);
218int rsnd_gen_path_init(struct rsnd_priv *priv,
219 struct rsnd_dai *rdai,
220 struct rsnd_dai_stream *io);
221int rsnd_gen_path_exit(struct rsnd_priv *priv,
222 struct rsnd_dai *rdai,
223 struct rsnd_dai_stream *io);
224void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv, 268void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
225 struct rsnd_mod *mod, 269 struct rsnd_mod *mod,
226 enum rsnd_reg reg); 270 enum rsnd_reg reg);
@@ -233,18 +277,28 @@ void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
233int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod); 277int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod);
234int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate); 278int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate);
235int rsnd_adg_probe(struct platform_device *pdev, 279int rsnd_adg_probe(struct platform_device *pdev,
236 struct rcar_snd_info *info, 280 const struct rsnd_of_data *of_data,
237 struct rsnd_priv *priv); 281 struct rsnd_priv *priv);
238void rsnd_adg_remove(struct platform_device *pdev, 282int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv,
239 struct rsnd_priv *priv); 283 struct rsnd_mod *mod,
240int rsnd_adg_set_convert_clk(struct rsnd_priv *priv, 284 unsigned int src_rate,
241 struct rsnd_mod *mod, 285 unsigned int dst_rate);
242 unsigned int src_rate, 286int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod,
243 unsigned int dst_rate); 287 struct rsnd_dai *rdai,
288 struct rsnd_dai_stream *io,
289 unsigned int src_rate,
290 unsigned int dst_rate);
291int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *mod,
292 struct rsnd_dai *rdai,
293 struct rsnd_dai_stream *io);
244 294
245/* 295/*
246 * R-Car sound priv 296 * R-Car sound priv
247 */ 297 */
298struct rsnd_of_data {
299 u32 flags;
300};
301
248struct rsnd_priv { 302struct rsnd_priv {
249 303
250 struct device *dev; 304 struct device *dev;
@@ -257,10 +311,10 @@ struct rsnd_priv {
257 void *gen; 311 void *gen;
258 312
259 /* 313 /*
260 * below value will be filled on rsnd_scu_probe() 314 * below value will be filled on rsnd_src_probe()
261 */ 315 */
262 void *scu; 316 void *src;
263 int scu_nr; 317 int src_nr;
264 318
265 /* 319 /*
266 * below value will be filled on rsnd_adg_probe() 320 * below value will be filled on rsnd_adg_probe()
@@ -270,46 +324,64 @@ struct rsnd_priv {
270 /* 324 /*
271 * below value will be filled on rsnd_ssi_probe() 325 * below value will be filled on rsnd_ssi_probe()
272 */ 326 */
273 void *ssiu; 327 void *ssi;
328 int ssi_nr;
274 329
275 /* 330 /*
276 * below value will be filled on rsnd_dai_probe() 331 * below value will be filled on rsnd_dai_probe()
277 */ 332 */
278 struct snd_soc_dai_driver *daidrv; 333 struct snd_soc_dai_driver *daidrv;
279 struct rsnd_dai *rdai; 334 struct rsnd_dai *rdai;
280 int dai_nr; 335 int rdai_nr;
281}; 336};
282 337
283#define rsnd_priv_to_dev(priv) ((priv)->dev) 338#define rsnd_priv_to_dev(priv) ((priv)->dev)
339#define rsnd_priv_to_info(priv) ((priv)->info)
284#define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags) 340#define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags)
285#define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags) 341#define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags)
286 342
343#define rsnd_info_is_playback(priv, type) \
344({ \
345 struct rcar_snd_info *info = rsnd_priv_to_info(priv); \
346 int i, is_play = 0; \
347 for (i = 0; i < info->dai_info_nr; i++) { \
348 if (info->dai_info[i].playback.type == (type)->info) { \
349 is_play = 1; \
350 break; \
351 } \
352 } \
353 is_play; \
354})
355
287/* 356/*
288 * R-Car SCU 357 * R-Car SRC
289 */ 358 */
290int rsnd_scu_probe(struct platform_device *pdev, 359int rsnd_src_probe(struct platform_device *pdev,
291 struct rcar_snd_info *info, 360 const struct rsnd_of_data *of_data,
292 struct rsnd_priv *priv); 361 struct rsnd_priv *priv);
293void rsnd_scu_remove(struct platform_device *pdev, 362struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id);
294 struct rsnd_priv *priv); 363unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
295struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id); 364 struct rsnd_dai_stream *io,
296bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod);
297unsigned int rsnd_scu_get_ssi_rate(struct rsnd_priv *priv,
298 struct rsnd_mod *ssi_mod,
299 struct snd_pcm_runtime *runtime); 365 struct snd_pcm_runtime *runtime);
366int rsnd_src_ssi_mode_init(struct rsnd_mod *ssi_mod,
367 struct rsnd_dai *rdai,
368 struct rsnd_dai_stream *io);
369int rsnd_src_enable_ssi_irq(struct rsnd_mod *ssi_mod,
370 struct rsnd_dai *rdai,
371 struct rsnd_dai_stream *io);
300 372
301#define rsnd_scu_nr(priv) ((priv)->scu_nr) 373#define rsnd_src_nr(priv) ((priv)->src_nr)
302 374
303/* 375/*
304 * R-Car SSI 376 * R-Car SSI
305 */ 377 */
306int rsnd_ssi_probe(struct platform_device *pdev, 378int rsnd_ssi_probe(struct platform_device *pdev,
307 struct rcar_snd_info *info, 379 const struct rsnd_of_data *of_data,
308 struct rsnd_priv *priv);
309void rsnd_ssi_remove(struct platform_device *pdev,
310 struct rsnd_priv *priv); 380 struct rsnd_priv *priv);
311struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id); 381struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
312struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv, 382struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv,
313 int dai_id, int is_play); 383 int dai_id, int is_play);
384int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
385int rsnd_ssi_is_play(struct rsnd_mod *mod);
314 386
315#endif 387#endif
diff --git a/sound/soc/sh/rcar/scu.c b/sound/soc/sh/rcar/scu.c
deleted file mode 100644
index 9bb08bb1d455..000000000000
--- a/sound/soc/sh/rcar/scu.c
+++ /dev/null
@@ -1,384 +0,0 @@
1/*
2 * Renesas R-Car SCU support
3 *
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include "rsnd.h"
12
13struct rsnd_scu {
14 struct rsnd_scu_platform_info *info; /* rcar_snd.h */
15 struct rsnd_mod mod;
16 struct clk *clk;
17};
18
19#define rsnd_scu_mode_flags(p) ((p)->info->flags)
20#define rsnd_scu_convert_rate(p) ((p)->info->convert_rate)
21
22#define RSND_SCU_NAME_SIZE 16
23
24/*
25 * ADINR
26 */
27#define OTBL_24 (0 << 16)
28#define OTBL_22 (2 << 16)
29#define OTBL_20 (4 << 16)
30#define OTBL_18 (6 << 16)
31#define OTBL_16 (8 << 16)
32
33/*
34 * image of SRC (Sampling Rate Converter)
35 *
36 * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
37 * 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
38 * 44.1kHz <-> +-----+ +-----+ +-------+
39 * ...
40 *
41 */
42
43#define rsnd_mod_to_scu(_mod) \
44 container_of((_mod), struct rsnd_scu, mod)
45
46#define for_each_rsnd_scu(pos, priv, i) \
47 for ((i) = 0; \
48 ((i) < rsnd_scu_nr(priv)) && \
49 ((pos) = (struct rsnd_scu *)(priv)->scu + i); \
50 i++)
51
52/* Gen1 only */
53static int rsnd_src_set_route_if_gen1(struct rsnd_priv *priv,
54 struct rsnd_mod *mod,
55 struct rsnd_dai *rdai,
56 struct rsnd_dai_stream *io)
57{
58 struct scu_route_config {
59 u32 mask;
60 int shift;
61 } routes[] = {
62 { 0xF, 0, }, /* 0 */
63 { 0xF, 4, }, /* 1 */
64 { 0xF, 8, }, /* 2 */
65 { 0x7, 12, }, /* 3 */
66 { 0x7, 16, }, /* 4 */
67 { 0x7, 20, }, /* 5 */
68 { 0x7, 24, }, /* 6 */
69 { 0x3, 28, }, /* 7 */
70 { 0x3, 30, }, /* 8 */
71 };
72 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
73 u32 mask;
74 u32 val;
75 int shift;
76 int id;
77
78 /*
79 * Gen1 only
80 */
81 if (!rsnd_is_gen1(priv))
82 return 0;
83
84 id = rsnd_mod_id(mod);
85 if (id < 0 || id >= ARRAY_SIZE(routes))
86 return -EIO;
87
88 /*
89 * SRC_ROUTE_SELECT
90 */
91 val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2;
92 val = val << routes[id].shift;
93 mask = routes[id].mask << routes[id].shift;
94
95 rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val);
96
97 /*
98 * SRC_TIMING_SELECT
99 */
100 shift = (id % 4) * 8;
101 mask = 0x1F << shift;
102
103 /*
104 * ADG is used as source clock if SRC was used,
105 * then, SSI WS is used as destination clock.
106 * SSI WS is used as source clock if SRC is not used
107 * (when playback, source/destination become reverse when capture)
108 */
109 if (rsnd_scu_convert_rate(scu)) /* use ADG */
110 val = 0;
111 else if (8 == id) /* use SSI WS, but SRU8 is special */
112 val = id << shift;
113 else /* use SSI WS */
114 val = (id + 1) << shift;
115
116 switch (id / 4) {
117 case 0:
118 rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val);
119 break;
120 case 1:
121 rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val);
122 break;
123 case 2:
124 rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val);
125 break;
126 }
127
128 return 0;
129}
130
131unsigned int rsnd_scu_get_ssi_rate(struct rsnd_priv *priv,
132 struct rsnd_mod *ssi_mod,
133 struct snd_pcm_runtime *runtime)
134{
135 struct rsnd_scu *scu;
136 unsigned int rate;
137
138 /* this function is assuming SSI id = SCU id here */
139 scu = rsnd_mod_to_scu(rsnd_scu_mod_get(priv, rsnd_mod_id(ssi_mod)));
140
141 /*
142 * return convert rate if SRC is used,
143 * otherwise, return runtime->rate as usual
144 */
145 rate = rsnd_scu_convert_rate(scu);
146 if (!rate)
147 rate = runtime->rate;
148
149 return rate;
150}
151
152static int rsnd_scu_convert_rate_ctrl(struct rsnd_priv *priv,
153 struct rsnd_mod *mod,
154 struct rsnd_dai *rdai,
155 struct rsnd_dai_stream *io)
156{
157 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
158 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
159 u32 convert_rate = rsnd_scu_convert_rate(scu);
160 u32 adinr = runtime->channels;
161
162 /* set/clear soft reset */
163 rsnd_mod_write(mod, SRC_SWRSR, 0);
164 rsnd_mod_write(mod, SRC_SWRSR, 1);
165
166 /* Initialize the operation of the SRC internal circuits */
167 rsnd_mod_write(mod, SRC_SRCIR, 1);
168
169 /* Set channel number and output bit length */
170 switch (runtime->sample_bits) {
171 case 16:
172 adinr |= OTBL_16;
173 break;
174 case 32:
175 adinr |= OTBL_24;
176 break;
177 default:
178 return -EIO;
179 }
180 rsnd_mod_write(mod, SRC_ADINR, adinr);
181
182 if (convert_rate) {
183 u32 fsrate = 0x0400000 / convert_rate * runtime->rate;
184 int ret;
185
186 /* Enable the initial value of IFS */
187 rsnd_mod_write(mod, SRC_IFSCR, 1);
188
189 /* Set initial value of IFS */
190 rsnd_mod_write(mod, SRC_IFSVR, fsrate);
191
192 /* Select SRC mode (fixed value) */
193 rsnd_mod_write(mod, SRC_SRCCR, 0x00010110);
194
195 /* Set the restriction value of the FS ratio (98%) */
196 rsnd_mod_write(mod, SRC_MNFSR, fsrate / 100 * 98);
197
198 if (rsnd_is_gen1(priv)) {
199 /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
200 }
201
202 /* set convert clock */
203 ret = rsnd_adg_set_convert_clk(priv, mod,
204 runtime->rate,
205 convert_rate);
206 if (ret < 0)
207 return ret;
208 }
209
210 /* Cancel the initialization and operate the SRC function */
211 rsnd_mod_write(mod, SRC_SRCIR, 0);
212
213 /* use DMA transfer */
214 rsnd_mod_write(mod, BUSIF_MODE, 1);
215
216 return 0;
217}
218
219static int rsnd_scu_transfer_start(struct rsnd_priv *priv,
220 struct rsnd_mod *mod,
221 struct rsnd_dai *rdai,
222 struct rsnd_dai_stream *io)
223{
224 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
225 int id = rsnd_mod_id(mod);
226 u32 val;
227
228 if (rsnd_is_gen1(priv)) {
229 val = (1 << id);
230 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, val, val);
231 }
232
233 if (rsnd_scu_convert_rate(scu))
234 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
235
236 return 0;
237}
238
239static int rsnd_scu_transfer_stop(struct rsnd_priv *priv,
240 struct rsnd_mod *mod,
241 struct rsnd_dai *rdai,
242 struct rsnd_dai_stream *io)
243{
244 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
245 int id = rsnd_mod_id(mod);
246 u32 mask;
247
248 if (rsnd_is_gen1(priv)) {
249 mask = (1 << id);
250 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, mask, 0);
251 }
252
253 if (rsnd_scu_convert_rate(scu))
254 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0);
255
256 return 0;
257}
258
259bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod)
260{
261 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
262 u32 flags = rsnd_scu_mode_flags(scu);
263
264 return !!(flags & RSND_SCU_USE_HPBIF);
265}
266
267static int rsnd_scu_start(struct rsnd_mod *mod,
268 struct rsnd_dai *rdai,
269 struct rsnd_dai_stream *io)
270{
271 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
272 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
273 struct device *dev = rsnd_priv_to_dev(priv);
274 int ret;
275
276 /*
277 * SCU will be used if it has RSND_SCU_USE_HPBIF flags
278 */
279 if (!rsnd_scu_hpbif_is_enable(mod)) {
280 /* it use PIO transter */
281 dev_dbg(dev, "%s%d is not used\n",
282 rsnd_mod_name(mod), rsnd_mod_id(mod));
283
284 return 0;
285 }
286
287 clk_enable(scu->clk);
288
289 /* it use DMA transter */
290
291 ret = rsnd_src_set_route_if_gen1(priv, mod, rdai, io);
292 if (ret < 0)
293 return ret;
294
295 ret = rsnd_scu_convert_rate_ctrl(priv, mod, rdai, io);
296 if (ret < 0)
297 return ret;
298
299 ret = rsnd_scu_transfer_start(priv, mod, rdai, io);
300 if (ret < 0)
301 return ret;
302
303 dev_dbg(dev, "%s%d start\n", rsnd_mod_name(mod), rsnd_mod_id(mod));
304
305 return 0;
306}
307
308static int rsnd_scu_stop(struct rsnd_mod *mod,
309 struct rsnd_dai *rdai,
310 struct rsnd_dai_stream *io)
311{
312 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
313 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
314
315 if (!rsnd_scu_hpbif_is_enable(mod))
316 return 0;
317
318 rsnd_scu_transfer_stop(priv, mod, rdai, io);
319
320 clk_disable(scu->clk);
321
322 return 0;
323}
324
325static struct rsnd_mod_ops rsnd_scu_ops = {
326 .name = "scu",
327 .start = rsnd_scu_start,
328 .stop = rsnd_scu_stop,
329};
330
331struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id)
332{
333 if (WARN_ON(id < 0 || id >= rsnd_scu_nr(priv)))
334 id = 0;
335
336 return &((struct rsnd_scu *)(priv->scu) + id)->mod;
337}
338
339int rsnd_scu_probe(struct platform_device *pdev,
340 struct rcar_snd_info *info,
341 struct rsnd_priv *priv)
342{
343 struct device *dev = rsnd_priv_to_dev(priv);
344 struct rsnd_scu *scu;
345 struct clk *clk;
346 char name[RSND_SCU_NAME_SIZE];
347 int i, nr;
348
349 /*
350 * init SCU
351 */
352 nr = info->scu_info_nr;
353 scu = devm_kzalloc(dev, sizeof(*scu) * nr, GFP_KERNEL);
354 if (!scu) {
355 dev_err(dev, "SCU allocate failed\n");
356 return -ENOMEM;
357 }
358
359 priv->scu_nr = nr;
360 priv->scu = scu;
361
362 for_each_rsnd_scu(scu, priv, i) {
363 snprintf(name, RSND_SCU_NAME_SIZE, "scu.%d", i);
364
365 clk = devm_clk_get(dev, name);
366 if (IS_ERR(clk))
367 return PTR_ERR(clk);
368
369 rsnd_mod_init(priv, &scu->mod,
370 &rsnd_scu_ops, i);
371 scu->info = &info->scu_info[i];
372 scu->clk = clk;
373
374 dev_dbg(dev, "SCU%d probed\n", i);
375 }
376 dev_dbg(dev, "scu probed\n");
377
378 return 0;
379}
380
381void rsnd_scu_remove(struct platform_device *pdev,
382 struct rsnd_priv *priv)
383{
384}
diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c
new file mode 100644
index 000000000000..eee75ebf961c
--- /dev/null
+++ b/sound/soc/sh/rcar/src.c
@@ -0,0 +1,723 @@
1/*
2 * Renesas R-Car SRC support
3 *
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include "rsnd.h"
12
13struct rsnd_src {
14 struct rsnd_src_platform_info *info; /* rcar_snd.h */
15 struct rsnd_mod mod;
16 struct clk *clk;
17};
18
19#define RSND_SRC_NAME_SIZE 16
20
21/*
22 * ADINR
23 */
24#define OTBL_24 (0 << 16)
25#define OTBL_22 (2 << 16)
26#define OTBL_20 (4 << 16)
27#define OTBL_18 (6 << 16)
28#define OTBL_16 (8 << 16)
29
30#define rsnd_src_mode_flags(p) ((p)->info->flags)
31#define rsnd_src_convert_rate(p) ((p)->info->convert_rate)
32#define rsnd_mod_to_src(_mod) \
33 container_of((_mod), struct rsnd_src, mod)
34#define rsnd_src_hpbif_is_enable(src) \
35 (rsnd_src_mode_flags(src) & RSND_SCU_USE_HPBIF)
36#define rsnd_src_dma_available(src) \
37 rsnd_dma_available(rsnd_mod_to_dma(&(src)->mod))
38
39#define for_each_rsnd_src(pos, priv, i) \
40 for ((i) = 0; \
41 ((i) < rsnd_src_nr(priv)) && \
42 ((pos) = (struct rsnd_src *)(priv)->src + i); \
43 i++)
44
45
46/*
47 * image of SRC (Sampling Rate Converter)
48 *
49 * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
50 * 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
51 * 44.1kHz <-> +-----+ +-----+ +-------+
52 * ...
53 *
54 */
55
56/*
57 * src.c is caring...
58 *
59 * Gen1
60 *
61 * [mem] -> [SRU] -> [SSI]
62 * |--------|
63 *
64 * Gen2
65 *
66 * [mem] -> [SRC] -> [SSIU] -> [SSI]
67 * |-----------------|
68 */
69
70/*
71 * How to use SRC bypass mode for debugging
72 *
73 * SRC has bypass mode, and it is useful for debugging.
74 * In Gen2 case,
75 * SRCm_MODE controls whether SRC is used or not
76 * SSI_MODE0 controls whether SSIU which receives SRC data
77 * is used or not.
78 * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC,
79 * but SRC bypass mode needs SSI_MODE0 only.
80 *
81 * This driver request
82 * struct rsnd_src_platform_info {
83 * u32 flags;
84 * u32 convert_rate;
85 * }
86 *
87 * rsnd_src_hpbif_is_enable() will be true
88 * if flags had RSND_SRC_USE_HPBIF,
89 * and it controls whether SSIU is used or not.
90 *
91 * rsnd_src_convert_rate() indicates
92 * above convert_rate, and it controls
93 * whether SRC is used or not.
94 *
95 * ex) doesn't use SRC
96 * struct rsnd_src_platform_info info = {
97 * .flags = 0,
98 * .convert_rate = 0,
99 * };
100 *
101 * ex) uses SRC
102 * struct rsnd_src_platform_info info = {
103 * .flags = RSND_SRC_USE_HPBIF,
104 * .convert_rate = 48000,
105 * };
106 *
107 * ex) uses SRC bypass mode
108 * struct rsnd_src_platform_info info = {
109 * .flags = RSND_SRC_USE_HPBIF,
110 * .convert_rate = 0,
111 * };
112 *
113 */
114
115/*
116 * Gen1/Gen2 common functions
117 */
118int rsnd_src_ssi_mode_init(struct rsnd_mod *ssi_mod,
119 struct rsnd_dai *rdai,
120 struct rsnd_dai_stream *io)
121{
122 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
123 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
124 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
125 int ssi_id = rsnd_mod_id(ssi_mod);
126 int has_src = 0;
127
128 /*
129 * SSI_MODE0
130 */
131 if (info->dai_info) {
132 has_src = !!src_mod;
133 } else {
134 struct rsnd_src *src = rsnd_mod_to_src(src_mod);
135 has_src = rsnd_src_hpbif_is_enable(src);
136 }
137
138 rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id),
139 has_src ? 0 : (1 << ssi_id));
140
141 /*
142 * SSI_MODE1
143 */
144 if (rsnd_ssi_is_pin_sharing(ssi_mod)) {
145 int shift = -1;
146 switch (ssi_id) {
147 case 1:
148 shift = 0;
149 break;
150 case 2:
151 shift = 2;
152 break;
153 case 4:
154 shift = 16;
155 break;
156 }
157
158 if (shift >= 0)
159 rsnd_mod_bset(ssi_mod, SSI_MODE1,
160 0x3 << shift,
161 rsnd_dai_is_clk_master(rdai) ?
162 0x2 << shift : 0x1 << shift);
163 }
164
165 return 0;
166}
167
168int rsnd_src_enable_ssi_irq(struct rsnd_mod *ssi_mod,
169 struct rsnd_dai *rdai,
170 struct rsnd_dai_stream *io)
171{
172 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
173
174 /* enable PIO interrupt if Gen2 */
175 if (rsnd_is_gen2(priv))
176 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000);
177
178 return 0;
179}
180
181unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
182 struct rsnd_dai_stream *io,
183 struct snd_pcm_runtime *runtime)
184{
185 struct rsnd_src *src;
186 unsigned int rate;
187
188 src = rsnd_mod_to_src(rsnd_io_to_mod_src(io));
189
190 /*
191 * return convert rate if SRC is used,
192 * otherwise, return runtime->rate as usual
193 */
194 rate = rsnd_src_convert_rate(src);
195 if (!rate)
196 rate = runtime->rate;
197
198 return rate;
199}
200
201static int rsnd_src_set_convert_rate(struct rsnd_mod *mod,
202 struct rsnd_dai *rdai,
203 struct rsnd_dai_stream *io)
204{
205 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
206 struct rsnd_src *src = rsnd_mod_to_src(mod);
207 u32 convert_rate = rsnd_src_convert_rate(src);
208 u32 adinr = runtime->channels;
209 u32 fsrate = 0;
210
211 if (convert_rate)
212 fsrate = 0x0400000 / convert_rate * runtime->rate;
213
214 /* set/clear soft reset */
215 rsnd_mod_write(mod, SRC_SWRSR, 0);
216 rsnd_mod_write(mod, SRC_SWRSR, 1);
217
218 /*
219 * Initialize the operation of the SRC internal circuits
220 * see rsnd_src_start()
221 */
222 rsnd_mod_write(mod, SRC_SRCIR, 1);
223
224 /* Set channel number and output bit length */
225 switch (runtime->sample_bits) {
226 case 16:
227 adinr |= OTBL_16;
228 break;
229 case 32:
230 adinr |= OTBL_24;
231 break;
232 default:
233 return -EIO;
234 }
235 rsnd_mod_write(mod, SRC_ADINR, adinr);
236
237 /* Enable the initial value of IFS */
238 if (fsrate) {
239 rsnd_mod_write(mod, SRC_IFSCR, 1);
240
241 /* Set initial value of IFS */
242 rsnd_mod_write(mod, SRC_IFSVR, fsrate);
243 }
244
245 /* use DMA transfer */
246 rsnd_mod_write(mod, SRC_BUSIF_MODE, 1);
247
248 return 0;
249}
250
251static int rsnd_src_init(struct rsnd_mod *mod,
252 struct rsnd_dai *rdai,
253 struct rsnd_dai_stream *io)
254{
255 struct rsnd_src *src = rsnd_mod_to_src(mod);
256
257 clk_enable(src->clk);
258
259 return 0;
260}
261
262static int rsnd_src_quit(struct rsnd_mod *mod,
263 struct rsnd_dai *rdai,
264 struct rsnd_dai_stream *io)
265{
266 struct rsnd_src *src = rsnd_mod_to_src(mod);
267
268 clk_disable(src->clk);
269
270 return 0;
271}
272
273static int rsnd_src_start(struct rsnd_mod *mod,
274 struct rsnd_dai *rdai,
275 struct rsnd_dai_stream *io)
276{
277 struct rsnd_src *src = rsnd_mod_to_src(mod);
278
279 /*
280 * Cancel the initialization and operate the SRC function
281 * see rsnd_src_set_convert_rate()
282 */
283 rsnd_mod_write(mod, SRC_SRCIR, 0);
284
285 if (rsnd_src_convert_rate(src))
286 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
287
288 return 0;
289}
290
291
292static int rsnd_src_stop(struct rsnd_mod *mod,
293 struct rsnd_dai *rdai,
294 struct rsnd_dai_stream *io)
295{
296 struct rsnd_src *src = rsnd_mod_to_src(mod);
297
298 if (rsnd_src_convert_rate(src))
299 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0);
300
301 return 0;
302}
303
304static struct rsnd_mod_ops rsnd_src_non_ops = {
305 .name = "src (non)",
306};
307
308/*
309 * Gen1 functions
310 */
311static int rsnd_src_set_route_gen1(struct rsnd_mod *mod,
312 struct rsnd_dai *rdai,
313 struct rsnd_dai_stream *io)
314{
315 struct src_route_config {
316 u32 mask;
317 int shift;
318 } routes[] = {
319 { 0xF, 0, }, /* 0 */
320 { 0xF, 4, }, /* 1 */
321 { 0xF, 8, }, /* 2 */
322 { 0x7, 12, }, /* 3 */
323 { 0x7, 16, }, /* 4 */
324 { 0x7, 20, }, /* 5 */
325 { 0x7, 24, }, /* 6 */
326 { 0x3, 28, }, /* 7 */
327 { 0x3, 30, }, /* 8 */
328 };
329 u32 mask;
330 u32 val;
331 int id;
332
333 id = rsnd_mod_id(mod);
334 if (id < 0 || id >= ARRAY_SIZE(routes))
335 return -EIO;
336
337 /*
338 * SRC_ROUTE_SELECT
339 */
340 val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2;
341 val = val << routes[id].shift;
342 mask = routes[id].mask << routes[id].shift;
343
344 rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val);
345
346 return 0;
347}
348
349static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod,
350 struct rsnd_dai *rdai,
351 struct rsnd_dai_stream *io)
352{
353 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
354 struct rsnd_src *src = rsnd_mod_to_src(mod);
355 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
356 u32 convert_rate = rsnd_src_convert_rate(src);
357 u32 mask;
358 u32 val;
359 int shift;
360 int id = rsnd_mod_id(mod);
361 int ret;
362
363 /*
364 * SRC_TIMING_SELECT
365 */
366 shift = (id % 4) * 8;
367 mask = 0x1F << shift;
368
369 /*
370 * ADG is used as source clock if SRC was used,
371 * then, SSI WS is used as destination clock.
372 * SSI WS is used as source clock if SRC is not used
373 * (when playback, source/destination become reverse when capture)
374 */
375 ret = 0;
376 if (convert_rate) {
377 /* use ADG */
378 val = 0;
379 ret = rsnd_adg_set_convert_clk_gen1(priv, mod,
380 runtime->rate,
381 convert_rate);
382 } else if (8 == id) {
383 /* use SSI WS, but SRU8 is special */
384 val = id << shift;
385 } else {
386 /* use SSI WS */
387 val = (id + 1) << shift;
388 }
389
390 if (ret < 0)
391 return ret;
392
393 switch (id / 4) {
394 case 0:
395 rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val);
396 break;
397 case 1:
398 rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val);
399 break;
400 case 2:
401 rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val);
402 break;
403 }
404
405 return 0;
406}
407
408static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod,
409 struct rsnd_dai *rdai,
410 struct rsnd_dai_stream *io)
411{
412 int ret;
413
414 ret = rsnd_src_set_convert_rate(mod, rdai, io);
415 if (ret < 0)
416 return ret;
417
418 /* Select SRC mode (fixed value) */
419 rsnd_mod_write(mod, SRC_SRCCR, 0x00010110);
420
421 /* Set the restriction value of the FS ratio (98%) */
422 rsnd_mod_write(mod, SRC_MNFSR,
423 rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98);
424
425 /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
426
427 return 0;
428}
429
430static int rsnd_src_init_gen1(struct rsnd_mod *mod,
431 struct rsnd_dai *rdai,
432 struct rsnd_dai_stream *io)
433{
434 int ret;
435
436 ret = rsnd_src_init(mod, rdai, io);
437 if (ret < 0)
438 return ret;
439
440 ret = rsnd_src_set_route_gen1(mod, rdai, io);
441 if (ret < 0)
442 return ret;
443
444 ret = rsnd_src_set_convert_rate_gen1(mod, rdai, io);
445 if (ret < 0)
446 return ret;
447
448 ret = rsnd_src_set_convert_timing_gen1(mod, rdai, io);
449 if (ret < 0)
450 return ret;
451
452 return 0;
453}
454
455static int rsnd_src_start_gen1(struct rsnd_mod *mod,
456 struct rsnd_dai *rdai,
457 struct rsnd_dai_stream *io)
458{
459 int id = rsnd_mod_id(mod);
460
461 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id));
462
463 return rsnd_src_start(mod, rdai, io);
464}
465
466static int rsnd_src_stop_gen1(struct rsnd_mod *mod,
467 struct rsnd_dai *rdai,
468 struct rsnd_dai_stream *io)
469{
470 int id = rsnd_mod_id(mod);
471
472 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0);
473
474 return rsnd_src_stop(mod, rdai, io);
475}
476
477static struct rsnd_mod_ops rsnd_src_gen1_ops = {
478 .name = "sru (gen1)",
479 .init = rsnd_src_init_gen1,
480 .quit = rsnd_src_quit,
481 .start = rsnd_src_start_gen1,
482 .stop = rsnd_src_stop_gen1,
483};
484
485/*
486 * Gen2 functions
487 */
488static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
489 struct rsnd_dai *rdai,
490 struct rsnd_dai_stream *io)
491{
492 int ret;
493
494 ret = rsnd_src_set_convert_rate(mod, rdai, io);
495 if (ret < 0)
496 return ret;
497
498 rsnd_mod_write(mod, SSI_BUSIF_ADINR, rsnd_mod_read(mod, SRC_ADINR));
499 rsnd_mod_write(mod, SSI_BUSIF_MODE, rsnd_mod_read(mod, SRC_BUSIF_MODE));
500
501 rsnd_mod_write(mod, SRC_SRCCR, 0x00011110);
502
503 rsnd_mod_write(mod, SRC_BSDSR, 0x01800000);
504 rsnd_mod_write(mod, SRC_BSISR, 0x00100060);
505
506 return 0;
507}
508
509static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod,
510 struct rsnd_dai *rdai,
511 struct rsnd_dai_stream *io)
512{
513 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
514 struct rsnd_src *src = rsnd_mod_to_src(mod);
515 u32 convert_rate = rsnd_src_convert_rate(src);
516 int ret;
517
518 if (convert_rate)
519 ret = rsnd_adg_set_convert_clk_gen2(mod, rdai, io,
520 runtime->rate,
521 convert_rate);
522 else
523 ret = rsnd_adg_set_convert_timing_gen2(mod, rdai, io);
524
525 return ret;
526}
527
528static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
529 struct rsnd_dai *rdai,
530 struct rsnd_dai_stream *io)
531{
532 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
533 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
534 struct rsnd_src *src = rsnd_mod_to_src(mod);
535 struct rsnd_mod *ssi = rsnd_ssi_mod_get(priv, rsnd_mod_id(mod));
536 struct device *dev = rsnd_priv_to_dev(priv);
537 int ret;
538 int is_play;
539
540 if (info->dai_info)
541 is_play = rsnd_info_is_playback(priv, src);
542 else
543 is_play = rsnd_ssi_is_play(ssi);
544
545 ret = rsnd_dma_init(priv,
546 rsnd_mod_to_dma(mod),
547 is_play,
548 src->info->dma_id);
549 if (ret < 0)
550 dev_err(dev, "SRC DMA failed\n");
551
552 return ret;
553}
554
555static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
556 struct rsnd_dai *rdai,
557 struct rsnd_dai_stream *io)
558{
559 rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod));
560
561 return 0;
562}
563
564static int rsnd_src_init_gen2(struct rsnd_mod *mod,
565 struct rsnd_dai *rdai,
566 struct rsnd_dai_stream *io)
567{
568 int ret;
569
570 ret = rsnd_src_init(mod, rdai, io);
571 if (ret < 0)
572 return ret;
573
574 ret = rsnd_src_set_convert_rate_gen2(mod, rdai, io);
575 if (ret < 0)
576 return ret;
577
578 ret = rsnd_src_set_convert_timing_gen2(mod, rdai, io);
579 if (ret < 0)
580 return ret;
581
582 return 0;
583}
584
585static int rsnd_src_start_gen2(struct rsnd_mod *mod,
586 struct rsnd_dai *rdai,
587 struct rsnd_dai_stream *io)
588{
589 struct rsnd_src *src = rsnd_mod_to_src(mod);
590
591 rsnd_dma_start(rsnd_mod_to_dma(&src->mod));
592
593 rsnd_mod_write(mod, SSI_CTRL, 0x1);
594 rsnd_mod_write(mod, SRC_CTRL, 0x11);
595
596 return rsnd_src_start(mod, rdai, io);
597}
598
599static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
600 struct rsnd_dai *rdai,
601 struct rsnd_dai_stream *io)
602{
603 struct rsnd_src *src = rsnd_mod_to_src(mod);
604
605 rsnd_mod_write(mod, SSI_CTRL, 0);
606 rsnd_mod_write(mod, SRC_CTRL, 0);
607
608 rsnd_dma_stop(rsnd_mod_to_dma(&src->mod));
609
610 return rsnd_src_stop(mod, rdai, io);
611}
612
613static struct rsnd_mod_ops rsnd_src_gen2_ops = {
614 .name = "src (gen2)",
615 .probe = rsnd_src_probe_gen2,
616 .remove = rsnd_src_remove_gen2,
617 .init = rsnd_src_init_gen2,
618 .quit = rsnd_src_quit,
619 .start = rsnd_src_start_gen2,
620 .stop = rsnd_src_stop_gen2,
621};
622
623struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
624{
625 if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
626 id = 0;
627
628 return &((struct rsnd_src *)(priv->src) + id)->mod;
629}
630
631static void rsnd_of_parse_src(struct platform_device *pdev,
632 const struct rsnd_of_data *of_data,
633 struct rsnd_priv *priv)
634{
635 struct device_node *src_node;
636 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
637 struct rsnd_src_platform_info *src_info;
638 struct device *dev = &pdev->dev;
639 int nr;
640
641 if (!of_data)
642 return;
643
644 src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
645 if (!src_node)
646 return;
647
648 nr = of_get_child_count(src_node);
649 if (!nr)
650 return;
651
652 src_info = devm_kzalloc(dev,
653 sizeof(struct rsnd_src_platform_info) * nr,
654 GFP_KERNEL);
655 if (!src_info) {
656 dev_err(dev, "src info allocation error\n");
657 return;
658 }
659
660 info->src_info = src_info;
661 info->src_info_nr = nr;
662}
663
664int rsnd_src_probe(struct platform_device *pdev,
665 const struct rsnd_of_data *of_data,
666 struct rsnd_priv *priv)
667{
668 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
669 struct device *dev = rsnd_priv_to_dev(priv);
670 struct rsnd_src *src;
671 struct rsnd_mod_ops *ops;
672 struct clk *clk;
673 char name[RSND_SRC_NAME_SIZE];
674 int i, nr;
675
676 rsnd_of_parse_src(pdev, of_data, priv);
677
678 /*
679 * init SRC
680 */
681 nr = info->src_info_nr;
682 if (!nr)
683 return 0;
684
685 src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL);
686 if (!src) {
687 dev_err(dev, "SRC allocate failed\n");
688 return -ENOMEM;
689 }
690
691 priv->src_nr = nr;
692 priv->src = src;
693
694 for_each_rsnd_src(src, priv, i) {
695 snprintf(name, RSND_SRC_NAME_SIZE, "src.%d", i);
696
697 clk = devm_clk_get(dev, name);
698 if (IS_ERR(clk)) {
699 snprintf(name, RSND_SRC_NAME_SIZE, "scu.%d", i);
700 clk = devm_clk_get(dev, name);
701 }
702
703 if (IS_ERR(clk))
704 return PTR_ERR(clk);
705
706 src->info = &info->src_info[i];
707 src->clk = clk;
708
709 ops = &rsnd_src_non_ops;
710 if (rsnd_src_hpbif_is_enable(src)) {
711 if (rsnd_is_gen1(priv))
712 ops = &rsnd_src_gen1_ops;
713 if (rsnd_is_gen2(priv))
714 ops = &rsnd_src_gen2_ops;
715 }
716
717 rsnd_mod_init(priv, &src->mod, ops, RSND_MOD_SRC, i);
718
719 dev_dbg(dev, "SRC%d probed\n", i);
720 }
721
722 return 0;
723}
diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c
index 4b8cf7ca9d19..4b7e20603dd7 100644
--- a/sound/soc/sh/rcar/ssi.c
+++ b/sound/soc/sh/rcar/ssi.c
@@ -64,108 +64,29 @@ struct rsnd_ssi {
64 struct rsnd_mod mod; 64 struct rsnd_mod mod;
65 65
66 struct rsnd_dai *rdai; 66 struct rsnd_dai *rdai;
67 struct rsnd_dai_stream *io;
68 u32 cr_own; 67 u32 cr_own;
69 u32 cr_clk; 68 u32 cr_clk;
70 u32 cr_etc; 69 u32 cr_etc;
71 int err; 70 int err;
72 int dma_offset;
73 unsigned int usrcnt; 71 unsigned int usrcnt;
74 unsigned int rate; 72 unsigned int rate;
75}; 73};
76 74
77struct rsnd_ssiu {
78 u32 ssi_mode0;
79 u32 ssi_mode1;
80
81 int ssi_nr;
82 struct rsnd_ssi *ssi;
83};
84
85#define for_each_rsnd_ssi(pos, priv, i) \ 75#define for_each_rsnd_ssi(pos, priv, i) \
86 for (i = 0; \ 76 for (i = 0; \
87 (i < rsnd_ssi_nr(priv)) && \ 77 (i < rsnd_ssi_nr(priv)) && \
88 ((pos) = ((struct rsnd_ssiu *)((priv)->ssiu))->ssi + i); \ 78 ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \
89 i++) 79 i++)
90 80
91#define rsnd_ssi_nr(priv) (((struct rsnd_ssiu *)((priv)->ssiu))->ssi_nr) 81#define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
92#define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod) 82#define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
93#define rsnd_dma_to_ssi(dma) rsnd_mod_to_ssi(rsnd_dma_to_mod(dma)) 83#define rsnd_dma_to_ssi(dma) rsnd_mod_to_ssi(rsnd_dma_to_mod(dma))
94#define rsnd_ssi_pio_available(ssi) ((ssi)->info->pio_irq > 0) 84#define rsnd_ssi_pio_available(ssi) ((ssi)->info->pio_irq > 0)
95#define rsnd_ssi_dma_available(ssi) \ 85#define rsnd_ssi_dma_available(ssi) \
96 rsnd_dma_available(rsnd_mod_to_dma(&(ssi)->mod)) 86 rsnd_dma_available(rsnd_mod_to_dma(&(ssi)->mod))
97#define rsnd_ssi_clk_from_parent(ssi) ((ssi)->parent) 87#define rsnd_ssi_clk_from_parent(ssi) ((ssi)->parent)
98#define rsnd_rdai_is_clk_master(rdai) ((rdai)->clk_master)
99#define rsnd_ssi_mode_flags(p) ((p)->info->flags) 88#define rsnd_ssi_mode_flags(p) ((p)->info->flags)
100#define rsnd_ssi_dai_id(ssi) ((ssi)->info->dai_id) 89#define rsnd_ssi_dai_id(ssi) ((ssi)->info->dai_id)
101#define rsnd_ssi_to_ssiu(ssi)\
102 (((struct rsnd_ssiu *)((ssi) - rsnd_mod_id(&(ssi)->mod))) - 1)
103
104static void rsnd_ssi_mode_set(struct rsnd_priv *priv,
105 struct rsnd_dai *rdai,
106 struct rsnd_ssi *ssi)
107{
108 struct device *dev = rsnd_priv_to_dev(priv);
109 struct rsnd_mod *scu;
110 struct rsnd_ssiu *ssiu = rsnd_ssi_to_ssiu(ssi);
111 int id = rsnd_mod_id(&ssi->mod);
112 u32 flags;
113 u32 val;
114
115 scu = rsnd_scu_mod_get(priv, rsnd_mod_id(&ssi->mod));
116
117 /*
118 * SSI_MODE0
119 */
120
121 /* see also BUSIF_MODE */
122 if (rsnd_scu_hpbif_is_enable(scu)) {
123 ssiu->ssi_mode0 &= ~(1 << id);
124 dev_dbg(dev, "SSI%d uses DEPENDENT mode\n", id);
125 } else {
126 ssiu->ssi_mode0 |= (1 << id);
127 dev_dbg(dev, "SSI%d uses INDEPENDENT mode\n", id);
128 }
129
130 /*
131 * SSI_MODE1
132 */
133#define ssi_parent_set(p, sync, adg, ext) \
134 do { \
135 ssi->parent = ssiu->ssi + p; \
136 if (rsnd_rdai_is_clk_master(rdai)) \
137 val = adg; \
138 else \
139 val = ext; \
140 if (flags & RSND_SSI_SYNC) \
141 val |= sync; \
142 } while (0)
143
144 flags = rsnd_ssi_mode_flags(ssi);
145 if (flags & RSND_SSI_CLK_PIN_SHARE) {
146
147 val = 0;
148 switch (id) {
149 case 1:
150 ssi_parent_set(0, (1 << 4), (0x2 << 0), (0x1 << 0));
151 break;
152 case 2:
153 ssi_parent_set(0, (1 << 4), (0x2 << 2), (0x1 << 2));
154 break;
155 case 4:
156 ssi_parent_set(3, (1 << 20), (0x2 << 16), (0x1 << 16));
157 break;
158 case 8:
159 ssi_parent_set(7, 0, 0, 0);
160 break;
161 }
162
163 ssiu->ssi_mode1 |= val;
164 }
165
166 rsnd_mod_write(&ssi->mod, SSI_MODE0, ssiu->ssi_mode0);
167 rsnd_mod_write(&ssi->mod, SSI_MODE1, ssiu->ssi_mode1);
168}
169 90
170static void rsnd_ssi_status_check(struct rsnd_mod *mod, 91static void rsnd_ssi_status_check(struct rsnd_mod *mod,
171 u32 bit) 92 u32 bit)
@@ -200,7 +121,7 @@ static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
200 1, 2, 4, 8, 16, 6, 12, 121 1, 2, 4, 8, 16, 6, 12,
201 }; 122 };
202 unsigned int main_rate; 123 unsigned int main_rate;
203 unsigned int rate = rsnd_scu_get_ssi_rate(priv, &ssi->mod, runtime); 124 unsigned int rate = rsnd_src_get_ssi_rate(priv, io, runtime);
204 125
205 /* 126 /*
206 * Find best clock, and try to start ADG 127 * Find best clock, and try to start ADG
@@ -252,7 +173,7 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
252 if (0 == ssi->usrcnt) { 173 if (0 == ssi->usrcnt) {
253 clk_enable(ssi->clk); 174 clk_enable(ssi->clk);
254 175
255 if (rsnd_rdai_is_clk_master(rdai)) { 176 if (rsnd_dai_is_clk_master(rdai)) {
256 if (rsnd_ssi_clk_from_parent(ssi)) 177 if (rsnd_ssi_clk_from_parent(ssi))
257 rsnd_ssi_hw_start(ssi->parent, rdai, io); 178 rsnd_ssi_hw_start(ssi->parent, rdai, io);
258 else 179 else
@@ -302,7 +223,7 @@ static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi,
302 rsnd_mod_write(&ssi->mod, SSICR, cr); /* disabled all */ 223 rsnd_mod_write(&ssi->mod, SSICR, cr); /* disabled all */
303 rsnd_ssi_status_check(&ssi->mod, IIRQ); 224 rsnd_ssi_status_check(&ssi->mod, IIRQ);
304 225
305 if (rsnd_rdai_is_clk_master(rdai)) { 226 if (rsnd_dai_is_clk_master(rdai)) {
306 if (rsnd_ssi_clk_from_parent(ssi)) 227 if (rsnd_ssi_clk_from_parent(ssi))
307 rsnd_ssi_hw_stop(ssi->parent, rdai); 228 rsnd_ssi_hw_stop(ssi->parent, rdai);
308 else 229 else
@@ -323,8 +244,6 @@ static int rsnd_ssi_init(struct rsnd_mod *mod,
323 struct rsnd_dai_stream *io) 244 struct rsnd_dai_stream *io)
324{ 245{
325 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 246 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
326 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
327 struct device *dev = rsnd_priv_to_dev(priv);
328 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 247 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
329 u32 cr; 248 u32 cr;
330 249
@@ -365,13 +284,10 @@ static int rsnd_ssi_init(struct rsnd_mod *mod,
365 * set ssi parameter 284 * set ssi parameter
366 */ 285 */
367 ssi->rdai = rdai; 286 ssi->rdai = rdai;
368 ssi->io = io;
369 ssi->cr_own = cr; 287 ssi->cr_own = cr;
370 ssi->err = -1; /* ignore 1st error */ 288 ssi->err = -1; /* ignore 1st error */
371 289
372 rsnd_ssi_mode_set(priv, rdai, ssi); 290 rsnd_src_ssi_mode_init(mod, rdai, io);
373
374 dev_dbg(dev, "%s.%d init\n", rsnd_mod_name(mod), rsnd_mod_id(mod));
375 291
376 return 0; 292 return 0;
377} 293}
@@ -384,13 +300,10 @@ static int rsnd_ssi_quit(struct rsnd_mod *mod,
384 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 300 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
385 struct device *dev = rsnd_priv_to_dev(priv); 301 struct device *dev = rsnd_priv_to_dev(priv);
386 302
387 dev_dbg(dev, "%s.%d quit\n", rsnd_mod_name(mod), rsnd_mod_id(mod));
388
389 if (ssi->err > 0) 303 if (ssi->err > 0)
390 dev_warn(dev, "ssi under/over flow err = %d\n", ssi->err); 304 dev_warn(dev, "ssi under/over flow err = %d\n", ssi->err);
391 305
392 ssi->rdai = NULL; 306 ssi->rdai = NULL;
393 ssi->io = NULL;
394 ssi->cr_own = 0; 307 ssi->cr_own = 0;
395 ssi->err = 0; 308 ssi->err = 0;
396 309
@@ -414,8 +327,9 @@ static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status)
414static irqreturn_t rsnd_ssi_pio_interrupt(int irq, void *data) 327static irqreturn_t rsnd_ssi_pio_interrupt(int irq, void *data)
415{ 328{
416 struct rsnd_ssi *ssi = data; 329 struct rsnd_ssi *ssi = data;
417 struct rsnd_dai_stream *io = ssi->io; 330 struct rsnd_mod *mod = &ssi->mod;
418 u32 status = rsnd_mod_read(&ssi->mod, SSISR); 331 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
332 u32 status = rsnd_mod_read(mod, SSISR);
419 irqreturn_t ret = IRQ_NONE; 333 irqreturn_t ret = IRQ_NONE;
420 334
421 if (io && (status & DIRQ)) { 335 if (io && (status & DIRQ)) {
@@ -432,9 +346,9 @@ static irqreturn_t rsnd_ssi_pio_interrupt(int irq, void *data)
432 * see rsnd_ssi_init() 346 * see rsnd_ssi_init()
433 */ 347 */
434 if (rsnd_dai_is_play(rdai, io)) 348 if (rsnd_dai_is_play(rdai, io))
435 rsnd_mod_write(&ssi->mod, SSITDR, *buf); 349 rsnd_mod_write(mod, SSITDR, *buf);
436 else 350 else
437 *buf = rsnd_mod_read(&ssi->mod, SSIRDR); 351 *buf = rsnd_mod_read(mod, SSIRDR);
438 352
439 rsnd_dai_pointer_update(io, sizeof(*buf)); 353 rsnd_dai_pointer_update(io, sizeof(*buf));
440 354
@@ -444,25 +358,39 @@ static irqreturn_t rsnd_ssi_pio_interrupt(int irq, void *data)
444 return ret; 358 return ret;
445} 359}
446 360
447static int rsnd_ssi_pio_start(struct rsnd_mod *mod, 361static int rsnd_ssi_pio_probe(struct rsnd_mod *mod,
448 struct rsnd_dai *rdai, 362 struct rsnd_dai *rdai,
449 struct rsnd_dai_stream *io) 363 struct rsnd_dai_stream *io)
450{ 364{
451 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 365 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
452 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
453 struct device *dev = rsnd_priv_to_dev(priv); 366 struct device *dev = rsnd_priv_to_dev(priv);
367 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
368 int irq = ssi->info->pio_irq;
369 int ret;
370
371 ret = devm_request_irq(dev, irq,
372 rsnd_ssi_pio_interrupt,
373 IRQF_SHARED,
374 dev_name(dev), ssi);
375 if (ret)
376 dev_err(dev, "SSI request interrupt failed\n");
377
378 return ret;
379}
380
381static int rsnd_ssi_pio_start(struct rsnd_mod *mod,
382 struct rsnd_dai *rdai,
383 struct rsnd_dai_stream *io)
384{
385 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
454 386
455 /* enable PIO IRQ */ 387 /* enable PIO IRQ */
456 ssi->cr_etc = UIEN | OIEN | DIEN; 388 ssi->cr_etc = UIEN | OIEN | DIEN;
457 389
458 /* enable PIO interrupt if gen2 */ 390 rsnd_src_enable_ssi_irq(mod, rdai, io);
459 if (rsnd_is_gen2(priv))
460 rsnd_mod_write(&ssi->mod, INT_ENABLE, 0x0f000000);
461 391
462 rsnd_ssi_hw_start(ssi, rdai, io); 392 rsnd_ssi_hw_start(ssi, rdai, io);
463 393
464 dev_dbg(dev, "%s.%d start\n", rsnd_mod_name(mod), rsnd_mod_id(mod));
465
466 return 0; 394 return 0;
467} 395}
468 396
@@ -470,12 +398,8 @@ static int rsnd_ssi_pio_stop(struct rsnd_mod *mod,
470 struct rsnd_dai *rdai, 398 struct rsnd_dai *rdai,
471 struct rsnd_dai_stream *io) 399 struct rsnd_dai_stream *io)
472{ 400{
473 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
474 struct device *dev = rsnd_priv_to_dev(priv);
475 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 401 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
476 402
477 dev_dbg(dev, "%s.%d stop\n", rsnd_mod_name(mod), rsnd_mod_id(mod));
478
479 ssi->cr_etc = 0; 403 ssi->cr_etc = 0;
480 404
481 rsnd_ssi_hw_stop(ssi, rdai); 405 rsnd_ssi_hw_stop(ssi, rdai);
@@ -485,35 +409,46 @@ static int rsnd_ssi_pio_stop(struct rsnd_mod *mod,
485 409
486static struct rsnd_mod_ops rsnd_ssi_pio_ops = { 410static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
487 .name = "ssi (pio)", 411 .name = "ssi (pio)",
412 .probe = rsnd_ssi_pio_probe,
488 .init = rsnd_ssi_init, 413 .init = rsnd_ssi_init,
489 .quit = rsnd_ssi_quit, 414 .quit = rsnd_ssi_quit,
490 .start = rsnd_ssi_pio_start, 415 .start = rsnd_ssi_pio_start,
491 .stop = rsnd_ssi_pio_stop, 416 .stop = rsnd_ssi_pio_stop,
492}; 417};
493 418
494static int rsnd_ssi_dma_inquiry(struct rsnd_dma *dma, dma_addr_t *buf, int *len) 419static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
420 struct rsnd_dai *rdai,
421 struct rsnd_dai_stream *io)
495{ 422{
496 struct rsnd_ssi *ssi = rsnd_dma_to_ssi(dma); 423 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
497 struct rsnd_dai_stream *io = ssi->io; 424 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
498 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 425 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
426 struct device *dev = rsnd_priv_to_dev(priv);
427 int dma_id = ssi->info->dma_id;
428 int is_play;
429 int ret;
499 430
500 *len = io->byte_per_period; 431 if (info->dai_info)
501 *buf = runtime->dma_addr + 432 is_play = rsnd_info_is_playback(priv, ssi);
502 rsnd_dai_pointer_offset(io, ssi->dma_offset + *len); 433 else
503 ssi->dma_offset = *len; /* it cares A/B plane */ 434 is_play = rsnd_ssi_is_play(&ssi->mod);
504 435
505 return 0; 436 ret = rsnd_dma_init(
506} 437 priv, rsnd_mod_to_dma(mod),
438 is_play,
439 dma_id);
507 440
508static int rsnd_ssi_dma_complete(struct rsnd_dma *dma) 441 if (ret < 0)
509{ 442 dev_err(dev, "SSI DMA failed\n");
510 struct rsnd_ssi *ssi = rsnd_dma_to_ssi(dma);
511 struct rsnd_dai_stream *io = ssi->io;
512 u32 status = rsnd_mod_read(&ssi->mod, SSISR);
513 443
514 rsnd_ssi_record_error(ssi, status); 444 return ret;
445}
515 446
516 rsnd_dai_pointer_update(ssi->io, io->byte_per_period); 447static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
448 struct rsnd_dai *rdai,
449 struct rsnd_dai_stream *io)
450{
451 rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod));
517 452
518 return 0; 453 return 0;
519} 454}
@@ -527,14 +462,13 @@ static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
527 462
528 /* enable DMA transfer */ 463 /* enable DMA transfer */
529 ssi->cr_etc = DMEN; 464 ssi->cr_etc = DMEN;
530 ssi->dma_offset = 0;
531 465
532 rsnd_dma_start(dma); 466 rsnd_dma_start(dma);
533 467
534 rsnd_ssi_hw_start(ssi, ssi->rdai, io); 468 rsnd_ssi_hw_start(ssi, ssi->rdai, io);
535 469
536 /* enable WS continue */ 470 /* enable WS continue */
537 if (rsnd_rdai_is_clk_master(rdai)) 471 if (rsnd_dai_is_clk_master(rdai))
538 rsnd_mod_write(&ssi->mod, SSIWSR, CONT); 472 rsnd_mod_write(&ssi->mod, SSIWSR, CONT);
539 473
540 return 0; 474 return 0;
@@ -549,6 +483,8 @@ static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
549 483
550 ssi->cr_etc = 0; 484 ssi->cr_etc = 0;
551 485
486 rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR));
487
552 rsnd_ssi_hw_stop(ssi, rdai); 488 rsnd_ssi_hw_stop(ssi, rdai);
553 489
554 rsnd_dma_stop(dma); 490 rsnd_dma_stop(dma);
@@ -558,6 +494,8 @@ static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
558 494
559static struct rsnd_mod_ops rsnd_ssi_dma_ops = { 495static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
560 .name = "ssi (dma)", 496 .name = "ssi (dma)",
497 .probe = rsnd_ssi_dma_probe,
498 .remove = rsnd_ssi_dma_remove,
561 .init = rsnd_ssi_init, 499 .init = rsnd_ssi_init,
562 .quit = rsnd_ssi_quit, 500 .quit = rsnd_ssi_quit,
563 .start = rsnd_ssi_dma_start, 501 .start = rsnd_ssi_dma_start,
@@ -567,24 +505,8 @@ static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
567/* 505/*
568 * Non SSI 506 * Non SSI
569 */ 507 */
570static int rsnd_ssi_non(struct rsnd_mod *mod,
571 struct rsnd_dai *rdai,
572 struct rsnd_dai_stream *io)
573{
574 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
575 struct device *dev = rsnd_priv_to_dev(priv);
576
577 dev_dbg(dev, "%s\n", __func__);
578
579 return 0;
580}
581
582static struct rsnd_mod_ops rsnd_ssi_non_ops = { 508static struct rsnd_mod_ops rsnd_ssi_non_ops = {
583 .name = "ssi (non)", 509 .name = "ssi (non)",
584 .init = rsnd_ssi_non,
585 .quit = rsnd_ssi_non,
586 .start = rsnd_ssi_non,
587 .stop = rsnd_ssi_non,
588}; 510};
589 511
590/* 512/*
@@ -593,16 +515,30 @@ static struct rsnd_mod_ops rsnd_ssi_non_ops = {
593struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv, 515struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv,
594 int dai_id, int is_play) 516 int dai_id, int is_play)
595{ 517{
518 struct rsnd_dai_platform_info *dai_info = NULL;
519 struct rsnd_dai_path_info *path_info = NULL;
520 struct rsnd_ssi_platform_info *target_info = NULL;
596 struct rsnd_ssi *ssi; 521 struct rsnd_ssi *ssi;
597 int i, has_play; 522 int i, has_play;
598 523
524 if (priv->rdai)
525 dai_info = priv->rdai[dai_id].info;
526 if (dai_info)
527 path_info = (is_play) ? &dai_info->playback : &dai_info->capture;
528 if (path_info)
529 target_info = path_info->ssi;
530
599 is_play = !!is_play; 531 is_play = !!is_play;
600 532
601 for_each_rsnd_ssi(ssi, priv, i) { 533 for_each_rsnd_ssi(ssi, priv, i) {
534 if (target_info == ssi->info)
535 return &ssi->mod;
536
537 /* for compatible */
602 if (rsnd_ssi_dai_id(ssi) != dai_id) 538 if (rsnd_ssi_dai_id(ssi) != dai_id)
603 continue; 539 continue;
604 540
605 has_play = !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_PLAY); 541 has_play = rsnd_ssi_is_play(&ssi->mod);
606 542
607 if (is_play == has_play) 543 if (is_play == has_play)
608 return &ssi->mod; 544 return &ssi->mod;
@@ -616,36 +552,122 @@ struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
616 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv))) 552 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
617 id = 0; 553 id = 0;
618 554
619 return &(((struct rsnd_ssiu *)(priv->ssiu))->ssi + id)->mod; 555 return &((struct rsnd_ssi *)(priv->ssi) + id)->mod;
556}
557
558int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
559{
560 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
561
562 return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE);
563}
564
565int rsnd_ssi_is_play(struct rsnd_mod *mod)
566{
567 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
568
569 return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_PLAY);
570}
571
572static void rsnd_ssi_parent_clk_setup(struct rsnd_priv *priv, struct rsnd_ssi *ssi)
573{
574 if (!rsnd_ssi_is_pin_sharing(&ssi->mod))
575 return;
576
577 switch (rsnd_mod_id(&ssi->mod)) {
578 case 1:
579 case 2:
580 ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 0));
581 break;
582 case 4:
583 ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 3));
584 break;
585 case 8:
586 ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 7));
587 break;
588 }
589}
590
591
592static void rsnd_of_parse_ssi(struct platform_device *pdev,
593 const struct rsnd_of_data *of_data,
594 struct rsnd_priv *priv)
595{
596 struct device_node *node;
597 struct device_node *np;
598 struct rsnd_ssi_platform_info *ssi_info;
599 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
600 struct device *dev = &pdev->dev;
601 int nr, i;
602
603 if (!of_data)
604 return;
605
606 node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi");
607 if (!node)
608 return;
609
610 nr = of_get_child_count(node);
611 if (!nr)
612 return;
613
614 ssi_info = devm_kzalloc(dev,
615 sizeof(struct rsnd_ssi_platform_info) * nr,
616 GFP_KERNEL);
617 if (!ssi_info) {
618 dev_err(dev, "ssi info allocation error\n");
619 return;
620 }
621
622 info->ssi_info = ssi_info;
623 info->ssi_info_nr = nr;
624
625 i = -1;
626 for_each_child_of_node(node, np) {
627 i++;
628
629 ssi_info = info->ssi_info + i;
630
631 /*
632 * pin settings
633 */
634 if (of_get_property(np, "shared-pin", NULL))
635 ssi_info->flags |= RSND_SSI_CLK_PIN_SHARE;
636
637 /*
638 * irq
639 */
640 ssi_info->pio_irq = irq_of_parse_and_map(np, 0);
641 }
620} 642}
621 643
622int rsnd_ssi_probe(struct platform_device *pdev, 644int rsnd_ssi_probe(struct platform_device *pdev,
623 struct rcar_snd_info *info, 645 const struct rsnd_of_data *of_data,
624 struct rsnd_priv *priv) 646 struct rsnd_priv *priv)
625{ 647{
648 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
626 struct rsnd_ssi_platform_info *pinfo; 649 struct rsnd_ssi_platform_info *pinfo;
627 struct device *dev = rsnd_priv_to_dev(priv); 650 struct device *dev = rsnd_priv_to_dev(priv);
628 struct rsnd_mod_ops *ops; 651 struct rsnd_mod_ops *ops;
629 struct clk *clk; 652 struct clk *clk;
630 struct rsnd_ssiu *ssiu;
631 struct rsnd_ssi *ssi; 653 struct rsnd_ssi *ssi;
632 char name[RSND_SSI_NAME_SIZE]; 654 char name[RSND_SSI_NAME_SIZE];
633 int i, nr, ret; 655 int i, nr;
656
657 rsnd_of_parse_ssi(pdev, of_data, priv);
634 658
635 /* 659 /*
636 * init SSI 660 * init SSI
637 */ 661 */
638 nr = info->ssi_info_nr; 662 nr = info->ssi_info_nr;
639 ssiu = devm_kzalloc(dev, sizeof(*ssiu) + (sizeof(*ssi) * nr), 663 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
640 GFP_KERNEL); 664 if (!ssi) {
641 if (!ssiu) {
642 dev_err(dev, "SSI allocate failed\n"); 665 dev_err(dev, "SSI allocate failed\n");
643 return -ENOMEM; 666 return -ENOMEM;
644 } 667 }
645 668
646 priv->ssiu = ssiu; 669 priv->ssi = ssi;
647 ssiu->ssi = (struct rsnd_ssi *)(ssiu + 1); 670 priv->ssi_nr = nr;
648 ssiu->ssi_nr = nr;
649 671
650 for_each_rsnd_ssi(ssi, priv, i) { 672 for_each_rsnd_ssi(ssi, priv, i) {
651 pinfo = &info->ssi_info[i]; 673 pinfo = &info->ssi_info[i];
@@ -660,61 +682,15 @@ int rsnd_ssi_probe(struct platform_device *pdev,
660 ssi->clk = clk; 682 ssi->clk = clk;
661 683
662 ops = &rsnd_ssi_non_ops; 684 ops = &rsnd_ssi_non_ops;
685 if (pinfo->dma_id > 0)
686 ops = &rsnd_ssi_dma_ops;
687 else if (rsnd_ssi_pio_available(ssi))
688 ops = &rsnd_ssi_pio_ops;
663 689
664 /* 690 rsnd_mod_init(priv, &ssi->mod, ops, RSND_MOD_SSI, i);
665 * SSI DMA case
666 */
667 if (pinfo->dma_id > 0) {
668 ret = rsnd_dma_init(
669 priv, rsnd_mod_to_dma(&ssi->mod),
670 (rsnd_ssi_mode_flags(ssi) & RSND_SSI_PLAY),
671 pinfo->dma_id,
672 rsnd_ssi_dma_inquiry,
673 rsnd_ssi_dma_complete);
674 if (ret < 0)
675 dev_info(dev, "SSI DMA failed. try PIO transter\n");
676 else
677 ops = &rsnd_ssi_dma_ops;
678
679 dev_dbg(dev, "SSI%d use DMA transfer\n", i);
680 }
681
682 /*
683 * SSI PIO case
684 */
685 if (!rsnd_ssi_dma_available(ssi) &&
686 rsnd_ssi_pio_available(ssi)) {
687 ret = devm_request_irq(dev, pinfo->pio_irq,
688 &rsnd_ssi_pio_interrupt,
689 IRQF_SHARED,
690 dev_name(dev), ssi);
691 if (ret) {
692 dev_err(dev, "SSI request interrupt failed\n");
693 return ret;
694 }
695
696 ops = &rsnd_ssi_pio_ops;
697
698 dev_dbg(dev, "SSI%d use PIO transfer\n", i);
699 }
700 691
701 rsnd_mod_init(priv, &ssi->mod, ops, i); 692 rsnd_ssi_parent_clk_setup(priv, ssi);
702 } 693 }
703 694
704 dev_dbg(dev, "ssi probed\n");
705
706 return 0; 695 return 0;
707} 696}
708
709void rsnd_ssi_remove(struct platform_device *pdev,
710 struct rsnd_priv *priv)
711{
712 struct rsnd_ssi *ssi;
713 int i;
714
715 for_each_rsnd_ssi(ssi, priv, i) {
716 if (rsnd_ssi_dma_available(ssi))
717 rsnd_dma_quit(priv, rsnd_mod_to_dma(&ssi->mod));
718 }
719
720}
diff --git a/sound/soc/sirf/Kconfig b/sound/soc/sirf/Kconfig
new file mode 100644
index 000000000000..89e89429b04a
--- /dev/null
+++ b/sound/soc/sirf/Kconfig
@@ -0,0 +1,14 @@
1config SND_SOC_SIRF
2 tristate "SoC Audio for the SiRF SoC chips"
3 depends on ARCH_SIRF || COMPILE_TEST
4 select SND_SOC_GENERIC_DMAENGINE_PCM
5
6config SND_SOC_SIRF_AUDIO
7 tristate "SoC Audio support for SiRF internal audio codec"
8 depends on SND_SOC_SIRF
9 select SND_SOC_SIRF_AUDIO_CODEC
10 select SND_SOC_SIRF_AUDIO_PORT
11
12config SND_SOC_SIRF_AUDIO_PORT
13 select REGMAP_MMIO
14 tristate
diff --git a/sound/soc/sirf/Makefile b/sound/soc/sirf/Makefile
new file mode 100644
index 000000000000..913b93231d4e
--- /dev/null
+++ b/sound/soc/sirf/Makefile
@@ -0,0 +1,5 @@
1snd-soc-sirf-audio-objs := sirf-audio.o
2snd-soc-sirf-audio-port-objs := sirf-audio-port.o
3
4obj-$(CONFIG_SND_SOC_SIRF_AUDIO) += snd-soc-sirf-audio.o
5obj-$(CONFIG_SND_SOC_SIRF_AUDIO_PORT) += snd-soc-sirf-audio-port.o
diff --git a/sound/soc/sirf/sirf-audio-port.c b/sound/soc/sirf/sirf-audio-port.c
new file mode 100644
index 000000000000..b04a53f2b4f6
--- /dev/null
+++ b/sound/soc/sirf/sirf-audio-port.c
@@ -0,0 +1,194 @@
1/*
2 * SiRF Audio port driver
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8#include <linux/module.h>
9#include <linux/io.h>
10#include <linux/regmap.h>
11#include <sound/soc.h>
12#include <sound/dmaengine_pcm.h>
13
14#include "sirf-audio-port.h"
15
16struct sirf_audio_port {
17 struct regmap *regmap;
18 struct snd_dmaengine_dai_dma_data playback_dma_data;
19 struct snd_dmaengine_dai_dma_data capture_dma_data;
20};
21
22static void sirf_audio_port_tx_enable(struct sirf_audio_port *port)
23{
24 regmap_update_bits(port->regmap, AUDIO_PORT_IC_TXFIFO_OP,
25 AUDIO_FIFO_RESET, AUDIO_FIFO_RESET);
26 regmap_write(port->regmap, AUDIO_PORT_IC_TXFIFO_INT_MSK, 0);
27 regmap_write(port->regmap, AUDIO_PORT_IC_TXFIFO_OP, 0);
28 regmap_update_bits(port->regmap, AUDIO_PORT_IC_TXFIFO_OP,
29 AUDIO_FIFO_START, AUDIO_FIFO_START);
30 regmap_update_bits(port->regmap, AUDIO_PORT_IC_CODEC_TX_CTRL,
31 IC_TX_ENABLE, IC_TX_ENABLE);
32}
33
34static void sirf_audio_port_tx_disable(struct sirf_audio_port *port)
35{
36 regmap_write(port->regmap, AUDIO_PORT_IC_TXFIFO_OP, 0);
37 regmap_update_bits(port->regmap, AUDIO_PORT_IC_CODEC_TX_CTRL,
38 IC_TX_ENABLE, ~IC_TX_ENABLE);
39}
40
41static void sirf_audio_port_rx_enable(struct sirf_audio_port *port,
42 int channels)
43{
44 regmap_update_bits(port->regmap, AUDIO_PORT_IC_RXFIFO_OP,
45 AUDIO_FIFO_RESET, AUDIO_FIFO_RESET);
46 regmap_write(port->regmap, AUDIO_PORT_IC_RXFIFO_INT_MSK, 0);
47 regmap_write(port->regmap, AUDIO_PORT_IC_RXFIFO_OP, 0);
48 regmap_update_bits(port->regmap, AUDIO_PORT_IC_RXFIFO_OP,
49 AUDIO_FIFO_START, AUDIO_FIFO_START);
50 if (channels == 1)
51 regmap_update_bits(port->regmap, AUDIO_PORT_IC_CODEC_RX_CTRL,
52 IC_RX_ENABLE_MONO, IC_RX_ENABLE_MONO);
53 else
54 regmap_update_bits(port->regmap, AUDIO_PORT_IC_CODEC_RX_CTRL,
55 IC_RX_ENABLE_STEREO, IC_RX_ENABLE_STEREO);
56}
57
58static void sirf_audio_port_rx_disable(struct sirf_audio_port *port)
59{
60 regmap_update_bits(port->regmap, AUDIO_PORT_IC_CODEC_RX_CTRL,
61 IC_RX_ENABLE_STEREO, ~IC_RX_ENABLE_STEREO);
62}
63
64static int sirf_audio_port_dai_probe(struct snd_soc_dai *dai)
65{
66 struct sirf_audio_port *port = snd_soc_dai_get_drvdata(dai);
67 snd_soc_dai_init_dma_data(dai, &port->playback_dma_data,
68 &port->capture_dma_data);
69 return 0;
70}
71
72static int sirf_audio_port_trigger(struct snd_pcm_substream *substream, int cmd,
73 struct snd_soc_dai *dai)
74{
75 struct sirf_audio_port *port = snd_soc_dai_get_drvdata(dai);
76 int playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
77
78 switch (cmd) {
79 case SNDRV_PCM_TRIGGER_STOP:
80 case SNDRV_PCM_TRIGGER_SUSPEND:
81 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
82 if (playback)
83 sirf_audio_port_tx_disable(port);
84 else
85 sirf_audio_port_rx_disable(port);
86 break;
87 case SNDRV_PCM_TRIGGER_START:
88 case SNDRV_PCM_TRIGGER_RESUME:
89 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
90 if (playback)
91 sirf_audio_port_tx_enable(port);
92 else
93 sirf_audio_port_rx_enable(port,
94 substream->runtime->channels);
95 break;
96 default:
97 return -EINVAL;
98 }
99
100 return 0;
101}
102
103static const struct snd_soc_dai_ops sirf_audio_port_dai_ops = {
104 .trigger = sirf_audio_port_trigger,
105};
106
107static struct snd_soc_dai_driver sirf_audio_port_dai = {
108 .probe = sirf_audio_port_dai_probe,
109 .name = "sirf-audio-port",
110 .id = 0,
111 .playback = {
112 .channels_min = 2,
113 .channels_max = 2,
114 .rates = SNDRV_PCM_RATE_48000,
115 .formats = SNDRV_PCM_FMTBIT_S16_LE,
116 },
117 .capture = {
118 .channels_min = 1,
119 .channels_max = 2,
120 .rates = SNDRV_PCM_RATE_48000,
121 .formats = SNDRV_PCM_FMTBIT_S16_LE,
122 },
123 .ops = &sirf_audio_port_dai_ops,
124};
125
126static const struct snd_soc_component_driver sirf_audio_port_component = {
127 .name = "sirf-audio-port",
128};
129
130static const struct regmap_config sirf_audio_port_regmap_config = {
131 .reg_bits = 32,
132 .reg_stride = 4,
133 .val_bits = 32,
134 .max_register = AUDIO_PORT_IC_RXFIFO_INT_MSK,
135 .cache_type = REGCACHE_NONE,
136};
137
138static int sirf_audio_port_probe(struct platform_device *pdev)
139{
140 int ret;
141 struct sirf_audio_port *port;
142 void __iomem *base;
143 struct resource *mem_res;
144
145 port = devm_kzalloc(&pdev->dev,
146 sizeof(struct sirf_audio_port), GFP_KERNEL);
147 if (!port)
148 return -ENOMEM;
149
150 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
151 if (!mem_res) {
152 dev_err(&pdev->dev, "no mem resource?\n");
153 return -ENODEV;
154 }
155
156 base = devm_ioremap(&pdev->dev, mem_res->start,
157 resource_size(mem_res));
158 if (base == NULL)
159 return -ENOMEM;
160
161 port->regmap = devm_regmap_init_mmio(&pdev->dev, base,
162 &sirf_audio_port_regmap_config);
163 if (IS_ERR(port->regmap))
164 return PTR_ERR(port->regmap);
165
166 ret = devm_snd_soc_register_component(&pdev->dev,
167 &sirf_audio_port_component, &sirf_audio_port_dai, 1);
168 if (ret)
169 return ret;
170
171 platform_set_drvdata(pdev, port);
172 return devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
173}
174
175static const struct of_device_id sirf_audio_port_of_match[] = {
176 { .compatible = "sirf,audio-port", },
177 {}
178};
179MODULE_DEVICE_TABLE(of, sirf_audio_port_of_match);
180
181static struct platform_driver sirf_audio_port_driver = {
182 .driver = {
183 .name = "sirf-audio-port",
184 .owner = THIS_MODULE,
185 .of_match_table = sirf_audio_port_of_match,
186 },
187 .probe = sirf_audio_port_probe,
188};
189
190module_platform_driver(sirf_audio_port_driver);
191
192MODULE_DESCRIPTION("SiRF Audio Port driver");
193MODULE_AUTHOR("RongJun Ying <Rongjun.Ying@csr.com>");
194MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/sirf/sirf-audio-port.h b/sound/soc/sirf/sirf-audio-port.h
new file mode 100644
index 000000000000..f32dc54f4499
--- /dev/null
+++ b/sound/soc/sirf/sirf-audio-port.h
@@ -0,0 +1,62 @@
1/*
2 * SiRF Audio port controllers define
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#ifndef _SIRF_AUDIO_PORT_H
10#define _SIRF_AUDIO_PORT_H
11
12#define AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK 0x3F
13#define AUDIO_PORT_TX_FIFO_SC_OFFSET 0
14#define AUDIO_PORT_TX_FIFO_LC_OFFSET 10
15#define AUDIO_PORT_TX_FIFO_HC_OFFSET 20
16
17#define TX_FIFO_SC(x) (((x) & AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK) \
18 << AUDIO_PORT_TX_FIFO_SC_OFFSET)
19#define TX_FIFO_LC(x) (((x) & AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK) \
20 << AUDIO_PORT_TX_FIFO_LC_OFFSET)
21#define TX_FIFO_HC(x) (((x) & AUDIO_PORT_TX_FIFO_LEVEL_CHECK_MASK) \
22 << AUDIO_PORT_TX_FIFO_HC_OFFSET)
23
24#define AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK 0x0F
25#define AUDIO_PORT_RX_FIFO_SC_OFFSET 0
26#define AUDIO_PORT_RX_FIFO_LC_OFFSET 10
27#define AUDIO_PORT_RX_FIFO_HC_OFFSET 20
28
29#define RX_FIFO_SC(x) (((x) & AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK) \
30 << AUDIO_PORT_RX_FIFO_SC_OFFSET)
31#define RX_FIFO_LC(x) (((x) & AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK) \
32 << AUDIO_PORT_RX_FIFO_LC_OFFSET)
33#define RX_FIFO_HC(x) (((x) & AUDIO_PORT_RX_FIFO_LEVEL_CHECK_MASK) \
34 << AUDIO_PORT_RX_FIFO_HC_OFFSET)
35#define AUDIO_PORT_IC_CODEC_TX_CTRL (0x00F4)
36#define AUDIO_PORT_IC_CODEC_RX_CTRL (0x00F8)
37
38#define AUDIO_PORT_IC_TXFIFO_OP (0x00FC)
39#define AUDIO_PORT_IC_TXFIFO_LEV_CHK (0x0100)
40#define AUDIO_PORT_IC_TXFIFO_STS (0x0104)
41#define AUDIO_PORT_IC_TXFIFO_INT (0x0108)
42#define AUDIO_PORT_IC_TXFIFO_INT_MSK (0x010C)
43
44#define AUDIO_PORT_IC_RXFIFO_OP (0x0110)
45#define AUDIO_PORT_IC_RXFIFO_LEV_CHK (0x0114)
46#define AUDIO_PORT_IC_RXFIFO_STS (0x0118)
47#define AUDIO_PORT_IC_RXFIFO_INT (0x011C)
48#define AUDIO_PORT_IC_RXFIFO_INT_MSK (0x0120)
49
50#define AUDIO_FIFO_START (1 << 0)
51#define AUDIO_FIFO_RESET (1 << 1)
52
53#define AUDIO_FIFO_FULL (1 << 0)
54#define AUDIO_FIFO_EMPTY (1 << 1)
55#define AUDIO_FIFO_OFLOW (1 << 2)
56#define AUDIO_FIFO_UFLOW (1 << 3)
57
58#define IC_TX_ENABLE (0x03)
59#define IC_RX_ENABLE_MONO (0x01)
60#define IC_RX_ENABLE_STEREO (0x03)
61
62#endif /*__SIRF_AUDIO_PORT_H*/
diff --git a/sound/soc/sirf/sirf-audio.c b/sound/soc/sirf/sirf-audio.c
new file mode 100644
index 000000000000..ecef51021653
--- /dev/null
+++ b/sound/soc/sirf/sirf-audio.c
@@ -0,0 +1,156 @@
1/*
2 * SiRF audio card driver
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#include <linux/platform_device.h>
10#include <linux/module.h>
11#include <linux/of.h>
12#include <linux/gpio.h>
13#include <linux/of_gpio.h>
14#include <sound/core.h>
15#include <sound/pcm.h>
16#include <sound/soc.h>
17
18struct sirf_audio_card {
19 unsigned int gpio_hp_pa;
20 unsigned int gpio_spk_pa;
21};
22
23static int sirf_audio_hp_event(struct snd_soc_dapm_widget *w,
24 struct snd_kcontrol *ctrl, int event)
25{
26 struct snd_soc_dapm_context *dapm = w->dapm;
27 struct snd_soc_card *card = dapm->card;
28 struct sirf_audio_card *sirf_audio_card = snd_soc_card_get_drvdata(card);
29 int on = !SND_SOC_DAPM_EVENT_OFF(event);
30 if (gpio_is_valid(sirf_audio_card->gpio_hp_pa))
31 gpio_set_value(sirf_audio_card->gpio_hp_pa, on);
32 return 0;
33}
34
35static int sirf_audio_spk_event(struct snd_soc_dapm_widget *w,
36 struct snd_kcontrol *ctrl, int event)
37{
38 struct snd_soc_dapm_context *dapm = w->dapm;
39 struct snd_soc_card *card = dapm->card;
40 struct sirf_audio_card *sirf_audio_card = snd_soc_card_get_drvdata(card);
41 int on = !SND_SOC_DAPM_EVENT_OFF(event);
42
43 if (gpio_is_valid(sirf_audio_card->gpio_spk_pa))
44 gpio_set_value(sirf_audio_card->gpio_spk_pa, on);
45
46 return 0;
47}
48static const struct snd_soc_dapm_widget sirf_audio_dapm_widgets[] = {
49 SND_SOC_DAPM_HP("Hp", sirf_audio_hp_event),
50 SND_SOC_DAPM_SPK("Ext Spk", sirf_audio_spk_event),
51 SND_SOC_DAPM_MIC("Ext Mic", NULL),
52};
53
54static const struct snd_soc_dapm_route intercon[] = {
55 {"Hp", NULL, "HPOUTL"},
56 {"Hp", NULL, "HPOUTR"},
57 {"Ext Spk", NULL, "SPKOUT"},
58 {"MICIN1", NULL, "Mic Bias"},
59 {"Mic Bias", NULL, "Ext Mic"},
60};
61
62/* Digital audio interface glue - connects codec <--> CPU */
63static struct snd_soc_dai_link sirf_audio_dai_link[] = {
64 {
65 .name = "SiRF audio card",
66 .stream_name = "SiRF audio HiFi",
67 .codec_dai_name = "sirf-audio-codec",
68 },
69};
70
71/* Audio machine driver */
72static struct snd_soc_card snd_soc_sirf_audio_card = {
73 .name = "SiRF audio card",
74 .owner = THIS_MODULE,
75 .dai_link = sirf_audio_dai_link,
76 .num_links = ARRAY_SIZE(sirf_audio_dai_link),
77 .dapm_widgets = sirf_audio_dapm_widgets,
78 .num_dapm_widgets = ARRAY_SIZE(sirf_audio_dapm_widgets),
79 .dapm_routes = intercon,
80 .num_dapm_routes = ARRAY_SIZE(intercon),
81};
82
83static int sirf_audio_probe(struct platform_device *pdev)
84{
85 struct snd_soc_card *card = &snd_soc_sirf_audio_card;
86 struct sirf_audio_card *sirf_audio_card;
87 int ret;
88
89 sirf_audio_card = devm_kzalloc(&pdev->dev, sizeof(struct sirf_audio_card),
90 GFP_KERNEL);
91 if (sirf_audio_card == NULL)
92 return -ENOMEM;
93
94 sirf_audio_dai_link[0].cpu_of_node =
95 of_parse_phandle(pdev->dev.of_node, "sirf,audio-platform", 0);
96 sirf_audio_dai_link[0].platform_of_node =
97 of_parse_phandle(pdev->dev.of_node, "sirf,audio-platform", 0);
98 sirf_audio_dai_link[0].codec_of_node =
99 of_parse_phandle(pdev->dev.of_node, "sirf,audio-codec", 0);
100 sirf_audio_card->gpio_spk_pa = of_get_named_gpio(pdev->dev.of_node,
101 "spk-pa-gpios", 0);
102 sirf_audio_card->gpio_hp_pa = of_get_named_gpio(pdev->dev.of_node,
103 "hp-pa-gpios", 0);
104 if (gpio_is_valid(sirf_audio_card->gpio_spk_pa)) {
105 ret = devm_gpio_request_one(&pdev->dev,
106 sirf_audio_card->gpio_spk_pa,
107 GPIOF_OUT_INIT_LOW, "SPA_PA_SD");
108 if (ret) {
109 dev_err(&pdev->dev,
110 "Failed to request GPIO_%d for reset: %d\n",
111 sirf_audio_card->gpio_spk_pa, ret);
112 return ret;
113 }
114 }
115 if (gpio_is_valid(sirf_audio_card->gpio_hp_pa)) {
116 ret = devm_gpio_request_one(&pdev->dev,
117 sirf_audio_card->gpio_hp_pa,
118 GPIOF_OUT_INIT_LOW, "HP_PA_SD");
119 if (ret) {
120 dev_err(&pdev->dev,
121 "Failed to request GPIO_%d for reset: %d\n",
122 sirf_audio_card->gpio_hp_pa, ret);
123 return ret;
124 }
125 }
126
127 card->dev = &pdev->dev;
128 snd_soc_card_set_drvdata(card, sirf_audio_card);
129
130 ret = devm_snd_soc_register_card(&pdev->dev, card);
131 if (ret)
132 dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
133
134 return ret;
135}
136
137static const struct of_device_id sirf_audio_of_match[] = {
138 {.compatible = "sirf,sirf-audio-card", },
139 { },
140};
141MODULE_DEVICE_TABLE(of, sirf_audio_of_match);
142
143static struct platform_driver sirf_audio_driver = {
144 .driver = {
145 .name = "sirf-audio-card",
146 .owner = THIS_MODULE,
147 .pm = &snd_soc_pm_ops,
148 .of_match_table = sirf_audio_of_match,
149 },
150 .probe = sirf_audio_probe,
151};
152module_platform_driver(sirf_audio_driver);
153
154MODULE_AUTHOR("RongJun Ying <RongJun.Ying@csr.com>");
155MODULE_DESCRIPTION("ALSA SoC SIRF audio card driver");
156MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index 375dc6dfba4e..bfed3e4c45ff 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -96,8 +96,7 @@ int snd_soc_cache_exit(struct snd_soc_codec *codec)
96{ 96{
97 dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n", 97 dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n",
98 codec->name); 98 codec->name);
99 if (!codec->reg_cache) 99
100 return 0;
101 kfree(codec->reg_cache); 100 kfree(codec->reg_cache);
102 codec->reg_cache = NULL; 101 codec->reg_cache = NULL;
103 return 0; 102 return 0;
@@ -117,8 +116,9 @@ int snd_soc_cache_read(struct snd_soc_codec *codec,
117 return -EINVAL; 116 return -EINVAL;
118 117
119 mutex_lock(&codec->cache_rw_mutex); 118 mutex_lock(&codec->cache_rw_mutex);
120 *value = snd_soc_get_cache_val(codec->reg_cache, reg, 119 if (!ZERO_OR_NULL_PTR(codec->reg_cache))
121 codec->driver->reg_word_size); 120 *value = snd_soc_get_cache_val(codec->reg_cache, reg,
121 codec->driver->reg_word_size);
122 mutex_unlock(&codec->cache_rw_mutex); 122 mutex_unlock(&codec->cache_rw_mutex);
123 123
124 return 0; 124 return 0;
@@ -136,8 +136,9 @@ int snd_soc_cache_write(struct snd_soc_codec *codec,
136 unsigned int reg, unsigned int value) 136 unsigned int reg, unsigned int value)
137{ 137{
138 mutex_lock(&codec->cache_rw_mutex); 138 mutex_lock(&codec->cache_rw_mutex);
139 snd_soc_set_cache_val(codec->reg_cache, reg, value, 139 if (!ZERO_OR_NULL_PTR(codec->reg_cache))
140 codec->driver->reg_word_size); 140 snd_soc_set_cache_val(codec->reg_cache, reg, value,
141 codec->driver->reg_word_size);
141 mutex_unlock(&codec->cache_rw_mutex); 142 mutex_unlock(&codec->cache_rw_mutex);
142 143
143 return 0; 144 return 0;
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index 5e9690c85d8f..91083e6a6b38 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -30,8 +30,6 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
30{ 30{
31 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 31 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
32 struct snd_soc_platform *platform = rtd->platform; 32 struct snd_soc_platform *platform = rtd->platform;
33 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
34 struct snd_soc_dai *codec_dai = rtd->codec_dai;
35 int ret = 0; 33 int ret = 0;
36 34
37 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 35 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
@@ -52,17 +50,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
52 } 50 }
53 } 51 }
54 52
55 if (cstream->direction == SND_COMPRESS_PLAYBACK) { 53 snd_soc_runtime_activate(rtd, cstream->direction);
56 cpu_dai->playback_active++;
57 codec_dai->playback_active++;
58 } else {
59 cpu_dai->capture_active++;
60 codec_dai->capture_active++;
61 }
62
63 cpu_dai->active++;
64 codec_dai->active++;
65 rtd->codec->active++;
66 54
67 mutex_unlock(&rtd->pcm_mutex); 55 mutex_unlock(&rtd->pcm_mutex);
68 56
@@ -81,8 +69,6 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
81 struct snd_soc_pcm_runtime *fe = cstream->private_data; 69 struct snd_soc_pcm_runtime *fe = cstream->private_data;
82 struct snd_pcm_substream *fe_substream = fe->pcm->streams[0].substream; 70 struct snd_pcm_substream *fe_substream = fe->pcm->streams[0].substream;
83 struct snd_soc_platform *platform = fe->platform; 71 struct snd_soc_platform *platform = fe->platform;
84 struct snd_soc_dai *cpu_dai = fe->cpu_dai;
85 struct snd_soc_dai *codec_dai = fe->codec_dai;
86 struct snd_soc_dpcm *dpcm; 72 struct snd_soc_dpcm *dpcm;
87 struct snd_soc_dapm_widget_list *list; 73 struct snd_soc_dapm_widget_list *list;
88 int stream; 74 int stream;
@@ -140,17 +126,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
140 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN; 126 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
141 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 127 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
142 128
143 if (cstream->direction == SND_COMPRESS_PLAYBACK) { 129 snd_soc_runtime_activate(fe, stream);
144 cpu_dai->playback_active++;
145 codec_dai->playback_active++;
146 } else {
147 cpu_dai->capture_active++;
148 codec_dai->capture_active++;
149 }
150
151 cpu_dai->active++;
152 codec_dai->active++;
153 fe->codec->active++;
154 130
155 mutex_unlock(&fe->card->mutex); 131 mutex_unlock(&fe->card->mutex);
156 132
@@ -202,23 +178,18 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
202 struct snd_soc_platform *platform = rtd->platform; 178 struct snd_soc_platform *platform = rtd->platform;
203 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 179 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
204 struct snd_soc_dai *codec_dai = rtd->codec_dai; 180 struct snd_soc_dai *codec_dai = rtd->codec_dai;
205 struct snd_soc_codec *codec = rtd->codec; 181 int stream;
206 182
207 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 183 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
208 184
209 if (cstream->direction == SND_COMPRESS_PLAYBACK) { 185 if (cstream->direction == SND_COMPRESS_PLAYBACK)
210 cpu_dai->playback_active--; 186 stream = SNDRV_PCM_STREAM_PLAYBACK;
211 codec_dai->playback_active--; 187 else
212 } else { 188 stream = SNDRV_PCM_STREAM_CAPTURE;
213 cpu_dai->capture_active--;
214 codec_dai->capture_active--;
215 }
216 189
217 snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); 190 snd_soc_runtime_deactivate(rtd, stream);
218 191
219 cpu_dai->active--; 192 snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
220 codec_dai->active--;
221 codec->active--;
222 193
223 if (!cpu_dai->active) 194 if (!cpu_dai->active)
224 cpu_dai->rate = 0; 195 cpu_dai->rate = 0;
@@ -235,8 +206,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
235 cpu_dai->runtime = NULL; 206 cpu_dai->runtime = NULL;
236 207
237 if (cstream->direction == SND_COMPRESS_PLAYBACK) { 208 if (cstream->direction == SND_COMPRESS_PLAYBACK) {
238 if (!rtd->pmdown_time || codec->ignore_pmdown_time || 209 if (snd_soc_runtime_ignore_pmdown_time(rtd)) {
239 rtd->dai_link->ignore_pmdown_time) {
240 snd_soc_dapm_stream_event(rtd, 210 snd_soc_dapm_stream_event(rtd,
241 SNDRV_PCM_STREAM_PLAYBACK, 211 SNDRV_PCM_STREAM_PLAYBACK,
242 SND_SOC_DAPM_STREAM_STOP); 212 SND_SOC_DAPM_STREAM_STOP);
@@ -261,26 +231,17 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
261{ 231{
262 struct snd_soc_pcm_runtime *fe = cstream->private_data; 232 struct snd_soc_pcm_runtime *fe = cstream->private_data;
263 struct snd_soc_platform *platform = fe->platform; 233 struct snd_soc_platform *platform = fe->platform;
264 struct snd_soc_dai *cpu_dai = fe->cpu_dai;
265 struct snd_soc_dai *codec_dai = fe->codec_dai;
266 struct snd_soc_dpcm *dpcm; 234 struct snd_soc_dpcm *dpcm;
267 int stream, ret; 235 int stream, ret;
268 236
269 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); 237 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
270 238
271 if (cstream->direction == SND_COMPRESS_PLAYBACK) { 239 if (cstream->direction == SND_COMPRESS_PLAYBACK)
272 stream = SNDRV_PCM_STREAM_PLAYBACK; 240 stream = SNDRV_PCM_STREAM_PLAYBACK;
273 cpu_dai->playback_active--; 241 else
274 codec_dai->playback_active--;
275 } else {
276 stream = SNDRV_PCM_STREAM_CAPTURE; 242 stream = SNDRV_PCM_STREAM_CAPTURE;
277 cpu_dai->capture_active--;
278 codec_dai->capture_active--;
279 }
280 243
281 cpu_dai->active--; 244 snd_soc_runtime_deactivate(fe, stream);
282 codec_dai->active--;
283 fe->codec->active--;
284 245
285 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; 246 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
286 247
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index fe1df50805a3..b65ca10ca0d4 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -56,7 +56,6 @@ EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
56#endif 56#endif
57 57
58static DEFINE_MUTEX(client_mutex); 58static DEFINE_MUTEX(client_mutex);
59static LIST_HEAD(dai_list);
60static LIST_HEAD(platform_list); 59static LIST_HEAD(platform_list);
61static LIST_HEAD(codec_list); 60static LIST_HEAD(codec_list);
62static LIST_HEAD(component_list); 61static LIST_HEAD(component_list);
@@ -370,18 +369,22 @@ static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
370{ 369{
371 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 370 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
372 ssize_t len, ret = 0; 371 ssize_t len, ret = 0;
372 struct snd_soc_component *component;
373 struct snd_soc_dai *dai; 373 struct snd_soc_dai *dai;
374 374
375 if (!buf) 375 if (!buf)
376 return -ENOMEM; 376 return -ENOMEM;
377 377
378 list_for_each_entry(dai, &dai_list, list) { 378 list_for_each_entry(component, &component_list, list) {
379 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); 379 list_for_each_entry(dai, &component->dai_list, list) {
380 if (len >= 0) 380 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
381 ret += len; 381 dai->name);
382 if (ret > PAGE_SIZE) { 382 if (len >= 0)
383 ret = PAGE_SIZE; 383 ret += len;
384 break; 384 if (ret > PAGE_SIZE) {
385 ret = PAGE_SIZE;
386 break;
387 }
385 } 388 }
386 } 389 }
387 390
@@ -855,6 +858,7 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
855{ 858{
856 struct snd_soc_dai_link *dai_link = &card->dai_link[num]; 859 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
857 struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; 860 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
861 struct snd_soc_component *component;
858 struct snd_soc_codec *codec; 862 struct snd_soc_codec *codec;
859 struct snd_soc_platform *platform; 863 struct snd_soc_platform *platform;
860 struct snd_soc_dai *codec_dai, *cpu_dai; 864 struct snd_soc_dai *codec_dai, *cpu_dai;
@@ -863,18 +867,20 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
863 dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num); 867 dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
864 868
865 /* Find CPU DAI from registered DAIs*/ 869 /* Find CPU DAI from registered DAIs*/
866 list_for_each_entry(cpu_dai, &dai_list, list) { 870 list_for_each_entry(component, &component_list, list) {
867 if (dai_link->cpu_of_node && 871 if (dai_link->cpu_of_node &&
868 (cpu_dai->dev->of_node != dai_link->cpu_of_node)) 872 component->dev->of_node != dai_link->cpu_of_node)
869 continue; 873 continue;
870 if (dai_link->cpu_name && 874 if (dai_link->cpu_name &&
871 strcmp(dev_name(cpu_dai->dev), dai_link->cpu_name)) 875 strcmp(dev_name(component->dev), dai_link->cpu_name))
872 continue;
873 if (dai_link->cpu_dai_name &&
874 strcmp(cpu_dai->name, dai_link->cpu_dai_name))
875 continue; 876 continue;
877 list_for_each_entry(cpu_dai, &component->dai_list, list) {
878 if (dai_link->cpu_dai_name &&
879 strcmp(cpu_dai->name, dai_link->cpu_dai_name))
880 continue;
876 881
877 rtd->cpu_dai = cpu_dai; 882 rtd->cpu_dai = cpu_dai;
883 }
878 } 884 }
879 885
880 if (!rtd->cpu_dai) { 886 if (!rtd->cpu_dai) {
@@ -899,12 +905,10 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
899 * CODEC found, so find CODEC DAI from registered DAIs from 905 * CODEC found, so find CODEC DAI from registered DAIs from
900 * this CODEC 906 * this CODEC
901 */ 907 */
902 list_for_each_entry(codec_dai, &dai_list, list) { 908 list_for_each_entry(codec_dai, &codec->component.dai_list, list) {
903 if (codec->dev == codec_dai->dev && 909 if (!strcmp(codec_dai->name, dai_link->codec_dai_name)) {
904 !strcmp(codec_dai->name,
905 dai_link->codec_dai_name)) {
906
907 rtd->codec_dai = codec_dai; 910 rtd->codec_dai = codec_dai;
911 break;
908 } 912 }
909 } 913 }
910 914
@@ -1128,15 +1132,21 @@ static int soc_probe_codec(struct snd_soc_card *card,
1128 driver->num_dapm_widgets); 1132 driver->num_dapm_widgets);
1129 1133
1130 /* Create DAPM widgets for each DAI stream */ 1134 /* Create DAPM widgets for each DAI stream */
1131 list_for_each_entry(dai, &dai_list, list) { 1135 list_for_each_entry(dai, &codec->component.dai_list, list)
1132 if (dai->dev != codec->dev)
1133 continue;
1134
1135 snd_soc_dapm_new_dai_widgets(&codec->dapm, dai); 1136 snd_soc_dapm_new_dai_widgets(&codec->dapm, dai);
1136 }
1137 1137
1138 codec->dapm.idle_bias_off = driver->idle_bias_off; 1138 codec->dapm.idle_bias_off = driver->idle_bias_off;
1139 1139
1140 if (!codec->write && dev_get_regmap(codec->dev, NULL)) {
1141 /* Set the default I/O up try regmap */
1142 ret = snd_soc_codec_set_cache_io(codec, NULL);
1143 if (ret < 0) {
1144 dev_err(codec->dev,
1145 "Failed to set cache I/O: %d\n", ret);
1146 goto err_probe;
1147 }
1148 }
1149
1140 if (driver->probe) { 1150 if (driver->probe) {
1141 ret = driver->probe(codec); 1151 ret = driver->probe(codec);
1142 if (ret < 0) { 1152 if (ret < 0) {
@@ -1150,10 +1160,6 @@ static int soc_probe_codec(struct snd_soc_card *card,
1150 codec->name); 1160 codec->name);
1151 } 1161 }
1152 1162
1153 /* If the driver didn't set I/O up try regmap */
1154 if (!codec->write && dev_get_regmap(codec->dev, NULL))
1155 snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP);
1156
1157 if (driver->controls) 1163 if (driver->controls)
1158 snd_soc_add_codec_controls(codec, driver->controls, 1164 snd_soc_add_codec_controls(codec, driver->controls,
1159 driver->num_controls); 1165 driver->num_controls);
@@ -1180,6 +1186,7 @@ static int soc_probe_platform(struct snd_soc_card *card,
1180{ 1186{
1181 int ret = 0; 1187 int ret = 0;
1182 const struct snd_soc_platform_driver *driver = platform->driver; 1188 const struct snd_soc_platform_driver *driver = platform->driver;
1189 struct snd_soc_component *component;
1183 struct snd_soc_dai *dai; 1190 struct snd_soc_dai *dai;
1184 1191
1185 platform->card = card; 1192 platform->card = card;
@@ -1195,11 +1202,11 @@ static int soc_probe_platform(struct snd_soc_card *card,
1195 driver->dapm_widgets, driver->num_dapm_widgets); 1202 driver->dapm_widgets, driver->num_dapm_widgets);
1196 1203
1197 /* Create DAPM widgets for each DAI stream */ 1204 /* Create DAPM widgets for each DAI stream */
1198 list_for_each_entry(dai, &dai_list, list) { 1205 list_for_each_entry(component, &component_list, list) {
1199 if (dai->dev != platform->dev) 1206 if (component->dev != platform->dev)
1200 continue; 1207 continue;
1201 1208 list_for_each_entry(dai, &component->dai_list, list)
1202 snd_soc_dapm_new_dai_widgets(&platform->dapm, dai); 1209 snd_soc_dapm_new_dai_widgets(&platform->dapm, dai);
1203 } 1210 }
1204 1211
1205 platform->dapm.idle_bias_off = 1; 1212 platform->dapm.idle_bias_off = 1;
@@ -1654,7 +1661,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1654 } 1661 }
1655 1662
1656 /* card bind complete so register a sound card */ 1663 /* card bind complete so register a sound card */
1657 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 1664 ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1658 card->owner, 0, &card->snd_card); 1665 card->owner, 0, &card->snd_card);
1659 if (ret < 0) { 1666 if (ret < 0) {
1660 dev_err(card->dev, 1667 dev_err(card->dev,
@@ -1662,7 +1669,6 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1662 card->name, ret); 1669 card->name, ret);
1663 goto base_error; 1670 goto base_error;
1664 } 1671 }
1665 card->snd_card->dev = card->dev;
1666 1672
1667 card->dapm.bias_level = SND_SOC_BIAS_OFF; 1673 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1668 card->dapm.dev = card->dev; 1674 card->dapm.dev = card->dev;
@@ -2571,10 +2577,10 @@ int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2571 2577
2572 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2578 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2573 uinfo->count = e->shift_l == e->shift_r ? 1 : 2; 2579 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
2574 uinfo->value.enumerated.items = e->max; 2580 uinfo->value.enumerated.items = e->items;
2575 2581
2576 if (uinfo->value.enumerated.item > e->max - 1) 2582 if (uinfo->value.enumerated.item >= e->items)
2577 uinfo->value.enumerated.item = e->max - 1; 2583 uinfo->value.enumerated.item = e->items - 1;
2578 strlcpy(uinfo->value.enumerated.name, 2584 strlcpy(uinfo->value.enumerated.name,
2579 e->texts[uinfo->value.enumerated.item], 2585 e->texts[uinfo->value.enumerated.item],
2580 sizeof(uinfo->value.enumerated.name)); 2586 sizeof(uinfo->value.enumerated.name));
@@ -2596,14 +2602,18 @@ int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2596{ 2602{
2597 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2603 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2598 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2604 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2599 unsigned int val; 2605 unsigned int val, item;
2606 unsigned int reg_val;
2600 2607
2601 val = snd_soc_read(codec, e->reg); 2608 reg_val = snd_soc_read(codec, e->reg);
2602 ucontrol->value.enumerated.item[0] 2609 val = (reg_val >> e->shift_l) & e->mask;
2603 = (val >> e->shift_l) & e->mask; 2610 item = snd_soc_enum_val_to_item(e, val);
2604 if (e->shift_l != e->shift_r) 2611 ucontrol->value.enumerated.item[0] = item;
2605 ucontrol->value.enumerated.item[1] = 2612 if (e->shift_l != e->shift_r) {
2606 (val >> e->shift_r) & e->mask; 2613 val = (reg_val >> e->shift_l) & e->mask;
2614 item = snd_soc_enum_val_to_item(e, val);
2615 ucontrol->value.enumerated.item[1] = item;
2616 }
2607 2617
2608 return 0; 2618 return 0;
2609} 2619}
@@ -2623,17 +2633,18 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2623{ 2633{
2624 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2634 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2625 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2635 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2636 unsigned int *item = ucontrol->value.enumerated.item;
2626 unsigned int val; 2637 unsigned int val;
2627 unsigned int mask; 2638 unsigned int mask;
2628 2639
2629 if (ucontrol->value.enumerated.item[0] > e->max - 1) 2640 if (item[0] >= e->items)
2630 return -EINVAL; 2641 return -EINVAL;
2631 val = ucontrol->value.enumerated.item[0] << e->shift_l; 2642 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
2632 mask = e->mask << e->shift_l; 2643 mask = e->mask << e->shift_l;
2633 if (e->shift_l != e->shift_r) { 2644 if (e->shift_l != e->shift_r) {
2634 if (ucontrol->value.enumerated.item[1] > e->max - 1) 2645 if (item[1] >= e->items)
2635 return -EINVAL; 2646 return -EINVAL;
2636 val |= ucontrol->value.enumerated.item[1] << e->shift_r; 2647 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r;
2637 mask |= e->mask << e->shift_r; 2648 mask |= e->mask << e->shift_r;
2638 } 2649 }
2639 2650
@@ -2642,78 +2653,46 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2642EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); 2653EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2643 2654
2644/** 2655/**
2645 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback 2656 * snd_soc_read_signed - Read a codec register and interprete as signed value
2646 * @kcontrol: mixer control 2657 * @codec: codec
2647 * @ucontrol: control element information 2658 * @reg: Register to read
2659 * @mask: Mask to use after shifting the register value
2660 * @shift: Right shift of register value
2661 * @sign_bit: Bit that describes if a number is negative or not.
2648 * 2662 *
2649 * Callback to get the value of a double semi enumerated mixer. 2663 * This functions reads a codec register. The register value is shifted right
2664 * by 'shift' bits and masked with the given 'mask'. Afterwards it translates
2665 * the given registervalue into a signed integer if sign_bit is non-zero.
2650 * 2666 *
2651 * Semi enumerated mixer: the enumerated items are referred as values. Can be 2667 * Returns the register value as signed int.
2652 * used for handling bitfield coded enumeration for example.
2653 *
2654 * Returns 0 for success.
2655 */ 2668 */
2656int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol, 2669static int snd_soc_read_signed(struct snd_soc_codec *codec, unsigned int reg,
2657 struct snd_ctl_elem_value *ucontrol) 2670 unsigned int mask, unsigned int shift, unsigned int sign_bit)
2658{ 2671{
2659 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2672 int ret;
2660 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2673 unsigned int val;
2661 unsigned int reg_val, val, mux;
2662 2674
2663 reg_val = snd_soc_read(codec, e->reg); 2675 val = (snd_soc_read(codec, reg) >> shift) & mask;
2664 val = (reg_val >> e->shift_l) & e->mask;
2665 for (mux = 0; mux < e->max; mux++) {
2666 if (val == e->values[mux])
2667 break;
2668 }
2669 ucontrol->value.enumerated.item[0] = mux;
2670 if (e->shift_l != e->shift_r) {
2671 val = (reg_val >> e->shift_r) & e->mask;
2672 for (mux = 0; mux < e->max; mux++) {
2673 if (val == e->values[mux])
2674 break;
2675 }
2676 ucontrol->value.enumerated.item[1] = mux;
2677 }
2678 2676
2679 return 0; 2677 if (!sign_bit)
2680} 2678 return val;
2681EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
2682 2679
2683/** 2680 /* non-negative number */
2684 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback 2681 if (!(val & BIT(sign_bit)))
2685 * @kcontrol: mixer control 2682 return val;
2686 * @ucontrol: control element information
2687 *
2688 * Callback to set the value of a double semi enumerated mixer.
2689 *
2690 * Semi enumerated mixer: the enumerated items are referred as values. Can be
2691 * used for handling bitfield coded enumeration for example.
2692 *
2693 * Returns 0 for success.
2694 */
2695int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2696 struct snd_ctl_elem_value *ucontrol)
2697{
2698 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2699 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2700 unsigned int val;
2701 unsigned int mask;
2702 2683
2703 if (ucontrol->value.enumerated.item[0] > e->max - 1) 2684 ret = val;
2704 return -EINVAL;
2705 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2706 mask = e->mask << e->shift_l;
2707 if (e->shift_l != e->shift_r) {
2708 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2709 return -EINVAL;
2710 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2711 mask |= e->mask << e->shift_r;
2712 }
2713 2685
2714 return snd_soc_update_bits_locked(codec, e->reg, mask, val); 2686 /*
2687 * The register most probably does not contain a full-sized int.
2688 * Instead we have an arbitrary number of bits in a signed
2689 * representation which has to be translated into a full-sized int.
2690 * This is done by filling up all bits above the sign-bit.
2691 */
2692 ret |= ~((int)(BIT(sign_bit) - 1));
2693
2694 return ret;
2715} 2695}
2716EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
2717 2696
2718/** 2697/**
2719 * snd_soc_info_volsw - single mixer info callback 2698 * snd_soc_info_volsw - single mixer info callback
@@ -2743,7 +2722,7 @@ int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2743 2722
2744 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; 2723 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
2745 uinfo->value.integer.min = 0; 2724 uinfo->value.integer.min = 0;
2746 uinfo->value.integer.max = platform_max; 2725 uinfo->value.integer.max = platform_max - mc->min;
2747 return 0; 2726 return 0;
2748} 2727}
2749EXPORT_SYMBOL_GPL(snd_soc_info_volsw); 2728EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
@@ -2769,11 +2748,16 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2769 unsigned int shift = mc->shift; 2748 unsigned int shift = mc->shift;
2770 unsigned int rshift = mc->rshift; 2749 unsigned int rshift = mc->rshift;
2771 int max = mc->max; 2750 int max = mc->max;
2751 int min = mc->min;
2752 int sign_bit = mc->sign_bit;
2772 unsigned int mask = (1 << fls(max)) - 1; 2753 unsigned int mask = (1 << fls(max)) - 1;
2773 unsigned int invert = mc->invert; 2754 unsigned int invert = mc->invert;
2774 2755
2775 ucontrol->value.integer.value[0] = 2756 if (sign_bit)
2776 (snd_soc_read(codec, reg) >> shift) & mask; 2757 mask = BIT(sign_bit + 1) - 1;
2758
2759 ucontrol->value.integer.value[0] = snd_soc_read_signed(codec, reg, mask,
2760 shift, sign_bit) - min;
2777 if (invert) 2761 if (invert)
2778 ucontrol->value.integer.value[0] = 2762 ucontrol->value.integer.value[0] =
2779 max - ucontrol->value.integer.value[0]; 2763 max - ucontrol->value.integer.value[0];
@@ -2781,10 +2765,12 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2781 if (snd_soc_volsw_is_stereo(mc)) { 2765 if (snd_soc_volsw_is_stereo(mc)) {
2782 if (reg == reg2) 2766 if (reg == reg2)
2783 ucontrol->value.integer.value[1] = 2767 ucontrol->value.integer.value[1] =
2784 (snd_soc_read(codec, reg) >> rshift) & mask; 2768 snd_soc_read_signed(codec, reg, mask, rshift,
2769 sign_bit) - min;
2785 else 2770 else
2786 ucontrol->value.integer.value[1] = 2771 ucontrol->value.integer.value[1] =
2787 (snd_soc_read(codec, reg2) >> shift) & mask; 2772 snd_soc_read_signed(codec, reg2, mask, shift,
2773 sign_bit) - min;
2788 if (invert) 2774 if (invert)
2789 ucontrol->value.integer.value[1] = 2775 ucontrol->value.integer.value[1] =
2790 max - ucontrol->value.integer.value[1]; 2776 max - ucontrol->value.integer.value[1];
@@ -2815,20 +2801,25 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2815 unsigned int shift = mc->shift; 2801 unsigned int shift = mc->shift;
2816 unsigned int rshift = mc->rshift; 2802 unsigned int rshift = mc->rshift;
2817 int max = mc->max; 2803 int max = mc->max;
2804 int min = mc->min;
2805 unsigned int sign_bit = mc->sign_bit;
2818 unsigned int mask = (1 << fls(max)) - 1; 2806 unsigned int mask = (1 << fls(max)) - 1;
2819 unsigned int invert = mc->invert; 2807 unsigned int invert = mc->invert;
2820 int err; 2808 int err;
2821 bool type_2r = 0; 2809 bool type_2r = false;
2822 unsigned int val2 = 0; 2810 unsigned int val2 = 0;
2823 unsigned int val, val_mask; 2811 unsigned int val, val_mask;
2824 2812
2825 val = (ucontrol->value.integer.value[0] & mask); 2813 if (sign_bit)
2814 mask = BIT(sign_bit + 1) - 1;
2815
2816 val = ((ucontrol->value.integer.value[0] + min) & mask);
2826 if (invert) 2817 if (invert)
2827 val = max - val; 2818 val = max - val;
2828 val_mask = mask << shift; 2819 val_mask = mask << shift;
2829 val = val << shift; 2820 val = val << shift;
2830 if (snd_soc_volsw_is_stereo(mc)) { 2821 if (snd_soc_volsw_is_stereo(mc)) {
2831 val2 = (ucontrol->value.integer.value[1] & mask); 2822 val2 = ((ucontrol->value.integer.value[1] + min) & mask);
2832 if (invert) 2823 if (invert)
2833 val2 = max - val2; 2824 val2 = max - val2;
2834 if (reg == reg2) { 2825 if (reg == reg2) {
@@ -2836,7 +2827,7 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2836 val |= val2 << rshift; 2827 val |= val2 << rshift;
2837 } else { 2828 } else {
2838 val2 = val2 << shift; 2829 val2 = val2 << shift;
2839 type_2r = 1; 2830 type_2r = true;
2840 } 2831 }
2841 } 2832 }
2842 err = snd_soc_update_bits_locked(codec, reg, val_mask, val); 2833 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
@@ -3234,7 +3225,7 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3234 struct soc_bytes *params = (void *)kcontrol->private_value; 3225 struct soc_bytes *params = (void *)kcontrol->private_value;
3235 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 3226 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3236 int ret, len; 3227 int ret, len;
3237 unsigned int val; 3228 unsigned int val, mask;
3238 void *data; 3229 void *data;
3239 3230
3240 if (!codec->using_regmap) 3231 if (!codec->using_regmap)
@@ -3264,12 +3255,36 @@ int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3264 ((u8 *)data)[0] |= val; 3255 ((u8 *)data)[0] |= val;
3265 break; 3256 break;
3266 case 2: 3257 case 2:
3267 ((u16 *)data)[0] &= cpu_to_be16(~params->mask); 3258 mask = ~params->mask;
3268 ((u16 *)data)[0] |= cpu_to_be16(val); 3259 ret = regmap_parse_val(codec->control_data,
3260 &mask, &mask);
3261 if (ret != 0)
3262 goto out;
3263
3264 ((u16 *)data)[0] &= mask;
3265
3266 ret = regmap_parse_val(codec->control_data,
3267 &val, &val);
3268 if (ret != 0)
3269 goto out;
3270
3271 ((u16 *)data)[0] |= val;
3269 break; 3272 break;
3270 case 4: 3273 case 4:
3271 ((u32 *)data)[0] &= cpu_to_be32(~params->mask); 3274 mask = ~params->mask;
3272 ((u32 *)data)[0] |= cpu_to_be32(val); 3275 ret = regmap_parse_val(codec->control_data,
3276 &mask, &mask);
3277 if (ret != 0)
3278 goto out;
3279
3280 ((u32 *)data)[0] &= mask;
3281
3282 ret = regmap_parse_val(codec->control_data,
3283 &val, &val);
3284 if (ret != 0)
3285 goto out;
3286
3287 ((u32 *)data)[0] |= val;
3273 break; 3288 break;
3274 default: 3289 default:
3275 ret = -EINVAL; 3290 ret = -EINVAL;
@@ -3609,6 +3624,30 @@ int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3609EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); 3624EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
3610 3625
3611/** 3626/**
3627 * snd_soc_of_xlate_tdm_slot - generate tx/rx slot mask.
3628 * @slots: Number of slots in use.
3629 * @tx_mask: bitmask representing active TX slots.
3630 * @rx_mask: bitmask representing active RX slots.
3631 *
3632 * Generates the TDM tx and rx slot default masks for DAI.
3633 */
3634static int snd_soc_of_xlate_tdm_slot_mask(unsigned int slots,
3635 unsigned int *tx_mask,
3636 unsigned int *rx_mask)
3637{
3638 if (*tx_mask || *rx_mask)
3639 return 0;
3640
3641 if (!slots)
3642 return -EINVAL;
3643
3644 *tx_mask = (1 << slots) - 1;
3645 *rx_mask = (1 << slots) - 1;
3646
3647 return 0;
3648}
3649
3650/**
3612 * snd_soc_dai_set_tdm_slot - configure DAI TDM. 3651 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3613 * @dai: DAI 3652 * @dai: DAI
3614 * @tx_mask: bitmask representing active TX slots. 3653 * @tx_mask: bitmask representing active TX slots.
@@ -3622,11 +3661,17 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
3622int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 3661int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
3623 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 3662 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
3624{ 3663{
3664 if (dai->driver && dai->driver->ops->of_xlate_tdm_slot_mask)
3665 dai->driver->ops->of_xlate_tdm_slot_mask(slots,
3666 &tx_mask, &rx_mask);
3667 else
3668 snd_soc_of_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
3669
3625 if (dai->driver && dai->driver->ops->set_tdm_slot) 3670 if (dai->driver && dai->driver->ops->set_tdm_slot)
3626 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, 3671 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
3627 slots, slot_width); 3672 slots, slot_width);
3628 else 3673 else
3629 return -EINVAL; 3674 return -ENOTSUPP;
3630} 3675}
3631EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); 3676EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
3632 3677
@@ -3882,95 +3927,42 @@ static inline char *fmt_multiple_name(struct device *dev,
3882} 3927}
3883 3928
3884/** 3929/**
3885 * snd_soc_register_dai - Register a DAI with the ASoC core 3930 * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
3886 * 3931 *
3887 * @dai: DAI to register 3932 * @component: The component for which the DAIs should be unregistered
3888 */ 3933 */
3889static int snd_soc_register_dai(struct device *dev, 3934static void snd_soc_unregister_dais(struct snd_soc_component *component)
3890 struct snd_soc_dai_driver *dai_drv)
3891{ 3935{
3892 struct snd_soc_codec *codec; 3936 struct snd_soc_dai *dai, *_dai;
3893 struct snd_soc_dai *dai;
3894
3895 dev_dbg(dev, "ASoC: dai register %s\n", dev_name(dev));
3896 3937
3897 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); 3938 list_for_each_entry_safe(dai, _dai, &component->dai_list, list) {
3898 if (dai == NULL) 3939 dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
3899 return -ENOMEM; 3940 dai->name);
3900 3941 list_del(&dai->list);
3901 /* create DAI component name */ 3942 kfree(dai->name);
3902 dai->name = fmt_single_name(dev, &dai->id);
3903 if (dai->name == NULL) {
3904 kfree(dai); 3943 kfree(dai);
3905 return -ENOMEM;
3906 } 3944 }
3907
3908 dai->dev = dev;
3909 dai->driver = dai_drv;
3910 dai->dapm.dev = dev;
3911 if (!dai->driver->ops)
3912 dai->driver->ops = &null_dai_ops;
3913
3914 mutex_lock(&client_mutex);
3915
3916 list_for_each_entry(codec, &codec_list, list) {
3917 if (codec->dev == dev) {
3918 dev_dbg(dev, "ASoC: Mapped DAI %s to CODEC %s\n",
3919 dai->name, codec->name);
3920 dai->codec = codec;
3921 break;
3922 }
3923 }
3924
3925 if (!dai->codec)
3926 dai->dapm.idle_bias_off = 1;
3927
3928 list_add(&dai->list, &dai_list);
3929
3930 mutex_unlock(&client_mutex);
3931
3932 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
3933
3934 return 0;
3935}
3936
3937/**
3938 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
3939 *
3940 * @dai: DAI to unregister
3941 */
3942static void snd_soc_unregister_dai(struct device *dev)
3943{
3944 struct snd_soc_dai *dai;
3945
3946 list_for_each_entry(dai, &dai_list, list) {
3947 if (dev == dai->dev)
3948 goto found;
3949 }
3950 return;
3951
3952found:
3953 mutex_lock(&client_mutex);
3954 list_del(&dai->list);
3955 mutex_unlock(&client_mutex);
3956
3957 dev_dbg(dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
3958 kfree(dai->name);
3959 kfree(dai);
3960} 3945}
3961 3946
3962/** 3947/**
3963 * snd_soc_register_dais - Register multiple DAIs with the ASoC core 3948 * snd_soc_register_dais - Register a DAI with the ASoC core
3964 * 3949 *
3965 * @dai: Array of DAIs to register 3950 * @component: The component the DAIs are registered for
3951 * @codec: The CODEC that the DAIs are registered for, NULL if the component is
3952 * not a CODEC.
3953 * @dai_drv: DAI driver to use for the DAIs
3966 * @count: Number of DAIs 3954 * @count: Number of DAIs
3955 * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
3956 * parent's name.
3967 */ 3957 */
3968static int snd_soc_register_dais(struct device *dev, 3958static int snd_soc_register_dais(struct snd_soc_component *component,
3969 struct snd_soc_dai_driver *dai_drv, size_t count) 3959 struct snd_soc_codec *codec, struct snd_soc_dai_driver *dai_drv,
3960 size_t count, bool legacy_dai_naming)
3970{ 3961{
3971 struct snd_soc_codec *codec; 3962 struct device *dev = component->dev;
3972 struct snd_soc_dai *dai; 3963 struct snd_soc_dai *dai;
3973 int i, ret = 0; 3964 unsigned int i;
3965 int ret;
3974 3966
3975 dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count); 3967 dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count);
3976 3968
@@ -3982,70 +3974,54 @@ static int snd_soc_register_dais(struct device *dev,
3982 goto err; 3974 goto err;
3983 } 3975 }
3984 3976
3985 /* create DAI component name */ 3977 /*
3986 dai->name = fmt_multiple_name(dev, &dai_drv[i]); 3978 * Back in the old days when we still had component-less DAIs,
3979 * instead of having a static name, component-less DAIs would
3980 * inherit the name of the parent device so it is possible to
3981 * register multiple instances of the DAI. We still need to keep
3982 * the same naming style even though those DAIs are not
3983 * component-less anymore.
3984 */
3985 if (count == 1 && legacy_dai_naming) {
3986 dai->name = fmt_single_name(dev, &dai->id);
3987 } else {
3988 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
3989 if (dai_drv[i].id)
3990 dai->id = dai_drv[i].id;
3991 else
3992 dai->id = i;
3993 }
3987 if (dai->name == NULL) { 3994 if (dai->name == NULL) {
3988 kfree(dai); 3995 kfree(dai);
3989 ret = -EINVAL; 3996 ret = -ENOMEM;
3990 goto err; 3997 goto err;
3991 } 3998 }
3992 3999
4000 dai->component = component;
4001 dai->codec = codec;
3993 dai->dev = dev; 4002 dai->dev = dev;
3994 dai->driver = &dai_drv[i]; 4003 dai->driver = &dai_drv[i];
3995 if (dai->driver->id)
3996 dai->id = dai->driver->id;
3997 else
3998 dai->id = i;
3999 dai->dapm.dev = dev; 4004 dai->dapm.dev = dev;
4000 if (!dai->driver->ops) 4005 if (!dai->driver->ops)
4001 dai->driver->ops = &null_dai_ops; 4006 dai->driver->ops = &null_dai_ops;
4002 4007
4003 mutex_lock(&client_mutex);
4004
4005 list_for_each_entry(codec, &codec_list, list) {
4006 if (codec->dev == dev) {
4007 dev_dbg(dev,
4008 "ASoC: Mapped DAI %s to CODEC %s\n",
4009 dai->name, codec->name);
4010 dai->codec = codec;
4011 break;
4012 }
4013 }
4014
4015 if (!dai->codec) 4008 if (!dai->codec)
4016 dai->dapm.idle_bias_off = 1; 4009 dai->dapm.idle_bias_off = 1;
4017 4010
4018 list_add(&dai->list, &dai_list); 4011 list_add(&dai->list, &component->dai_list);
4019 4012
4020 mutex_unlock(&client_mutex); 4013 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
4021
4022 dev_dbg(dai->dev, "ASoC: Registered DAI '%s'\n", dai->name);
4023 } 4014 }
4024 4015
4025 return 0; 4016 return 0;
4026 4017
4027err: 4018err:
4028 for (i--; i >= 0; i--) 4019 snd_soc_unregister_dais(component);
4029 snd_soc_unregister_dai(dev);
4030 4020
4031 return ret; 4021 return ret;
4032} 4022}
4033 4023
4034/** 4024/**
4035 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
4036 *
4037 * @dai: Array of DAIs to unregister
4038 * @count: Number of DAIs
4039 */
4040static void snd_soc_unregister_dais(struct device *dev, size_t count)
4041{
4042 int i;
4043
4044 for (i = 0; i < count; i++)
4045 snd_soc_unregister_dai(dev);
4046}
4047
4048/**
4049 * snd_soc_register_component - Register a component with the ASoC core 4025 * snd_soc_register_component - Register a component with the ASoC core
4050 * 4026 *
4051 */ 4027 */
@@ -4053,6 +4029,7 @@ static int
4053__snd_soc_register_component(struct device *dev, 4029__snd_soc_register_component(struct device *dev,
4054 struct snd_soc_component *cmpnt, 4030 struct snd_soc_component *cmpnt,
4055 const struct snd_soc_component_driver *cmpnt_drv, 4031 const struct snd_soc_component_driver *cmpnt_drv,
4032 struct snd_soc_codec *codec,
4056 struct snd_soc_dai_driver *dai_drv, 4033 struct snd_soc_dai_driver *dai_drv,
4057 int num_dai, bool allow_single_dai) 4034 int num_dai, bool allow_single_dai)
4058{ 4035{
@@ -4075,20 +4052,10 @@ __snd_soc_register_component(struct device *dev,
4075 cmpnt->driver = cmpnt_drv; 4052 cmpnt->driver = cmpnt_drv;
4076 cmpnt->dai_drv = dai_drv; 4053 cmpnt->dai_drv = dai_drv;
4077 cmpnt->num_dai = num_dai; 4054 cmpnt->num_dai = num_dai;
4055 INIT_LIST_HEAD(&cmpnt->dai_list);
4078 4056
4079 /* 4057 ret = snd_soc_register_dais(cmpnt, codec, dai_drv, num_dai,
4080 * snd_soc_register_dai() uses fmt_single_name(), and 4058 allow_single_dai);
4081 * snd_soc_register_dais() uses fmt_multiple_name()
4082 * for dai->name which is used for name based matching
4083 *
4084 * this function is used from cpu/codec.
4085 * allow_single_dai flag can ignore "codec" driver reworking
4086 * since it had been used snd_soc_register_dais(),
4087 */
4088 if ((1 == num_dai) && allow_single_dai)
4089 ret = snd_soc_register_dai(dev, dai_drv);
4090 else
4091 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
4092 if (ret < 0) { 4059 if (ret < 0) {
4093 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); 4060 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4094 goto error_component_name; 4061 goto error_component_name;
@@ -4121,7 +4088,9 @@ int snd_soc_register_component(struct device *dev,
4121 return -ENOMEM; 4088 return -ENOMEM;
4122 } 4089 }
4123 4090
4124 return __snd_soc_register_component(dev, cmpnt, cmpnt_drv, 4091 cmpnt->ignore_pmdown_time = true;
4092
4093 return __snd_soc_register_component(dev, cmpnt, cmpnt_drv, NULL,
4125 dai_drv, num_dai, true); 4094 dai_drv, num_dai, true);
4126} 4095}
4127EXPORT_SYMBOL_GPL(snd_soc_register_component); 4096EXPORT_SYMBOL_GPL(snd_soc_register_component);
@@ -4141,7 +4110,7 @@ void snd_soc_unregister_component(struct device *dev)
4141 return; 4110 return;
4142 4111
4143found: 4112found:
4144 snd_soc_unregister_dais(dev, cmpnt->num_dai); 4113 snd_soc_unregister_dais(cmpnt);
4145 4114
4146 mutex_lock(&client_mutex); 4115 mutex_lock(&client_mutex);
4147 list_del(&cmpnt->list); 4116 list_del(&cmpnt->list);
@@ -4319,7 +4288,7 @@ int snd_soc_register_codec(struct device *dev,
4319 codec->volatile_register = codec_drv->volatile_register; 4288 codec->volatile_register = codec_drv->volatile_register;
4320 codec->readable_register = codec_drv->readable_register; 4289 codec->readable_register = codec_drv->readable_register;
4321 codec->writable_register = codec_drv->writable_register; 4290 codec->writable_register = codec_drv->writable_register;
4322 codec->ignore_pmdown_time = codec_drv->ignore_pmdown_time; 4291 codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time;
4323 codec->dapm.bias_level = SND_SOC_BIAS_OFF; 4292 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
4324 codec->dapm.dev = dev; 4293 codec->dapm.dev = dev;
4325 codec->dapm.codec = codec; 4294 codec->dapm.codec = codec;
@@ -4342,7 +4311,7 @@ int snd_soc_register_codec(struct device *dev,
4342 /* register component */ 4311 /* register component */
4343 ret = __snd_soc_register_component(dev, &codec->component, 4312 ret = __snd_soc_register_component(dev, &codec->component,
4344 &codec_drv->component_driver, 4313 &codec_drv->component_driver,
4345 dai_drv, num_dai, false); 4314 codec, dai_drv, num_dai, false);
4346 if (ret < 0) { 4315 if (ret < 0) {
4347 dev_err(codec->dev, "ASoC: Failed to regster component: %d\n", ret); 4316 dev_err(codec->dev, "ASoC: Failed to regster component: %d\n", ret);
4348 goto fail_codec_name; 4317 goto fail_codec_name;
@@ -4417,6 +4386,122 @@ int snd_soc_of_parse_card_name(struct snd_soc_card *card,
4417} 4386}
4418EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); 4387EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
4419 4388
4389static const struct snd_soc_dapm_widget simple_widgets[] = {
4390 SND_SOC_DAPM_MIC("Microphone", NULL),
4391 SND_SOC_DAPM_LINE("Line", NULL),
4392 SND_SOC_DAPM_HP("Headphone", NULL),
4393 SND_SOC_DAPM_SPK("Speaker", NULL),
4394};
4395
4396int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
4397 const char *propname)
4398{
4399 struct device_node *np = card->dev->of_node;
4400 struct snd_soc_dapm_widget *widgets;
4401 const char *template, *wname;
4402 int i, j, num_widgets, ret;
4403
4404 num_widgets = of_property_count_strings(np, propname);
4405 if (num_widgets < 0) {
4406 dev_err(card->dev,
4407 "ASoC: Property '%s' does not exist\n", propname);
4408 return -EINVAL;
4409 }
4410 if (num_widgets & 1) {
4411 dev_err(card->dev,
4412 "ASoC: Property '%s' length is not even\n", propname);
4413 return -EINVAL;
4414 }
4415
4416 num_widgets /= 2;
4417 if (!num_widgets) {
4418 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
4419 propname);
4420 return -EINVAL;
4421 }
4422
4423 widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
4424 GFP_KERNEL);
4425 if (!widgets) {
4426 dev_err(card->dev,
4427 "ASoC: Could not allocate memory for widgets\n");
4428 return -ENOMEM;
4429 }
4430
4431 for (i = 0; i < num_widgets; i++) {
4432 ret = of_property_read_string_index(np, propname,
4433 2 * i, &template);
4434 if (ret) {
4435 dev_err(card->dev,
4436 "ASoC: Property '%s' index %d read error:%d\n",
4437 propname, 2 * i, ret);
4438 return -EINVAL;
4439 }
4440
4441 for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) {
4442 if (!strncmp(template, simple_widgets[j].name,
4443 strlen(simple_widgets[j].name))) {
4444 widgets[i] = simple_widgets[j];
4445 break;
4446 }
4447 }
4448
4449 if (j >= ARRAY_SIZE(simple_widgets)) {
4450 dev_err(card->dev,
4451 "ASoC: DAPM widget '%s' is not supported\n",
4452 template);
4453 return -EINVAL;
4454 }
4455
4456 ret = of_property_read_string_index(np, propname,
4457 (2 * i) + 1,
4458 &wname);
4459 if (ret) {
4460 dev_err(card->dev,
4461 "ASoC: Property '%s' index %d read error:%d\n",
4462 propname, (2 * i) + 1, ret);
4463 return -EINVAL;
4464 }
4465
4466 widgets[i].name = wname;
4467 }
4468
4469 card->dapm_widgets = widgets;
4470 card->num_dapm_widgets = num_widgets;
4471
4472 return 0;
4473}
4474EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
4475
4476int snd_soc_of_parse_tdm_slot(struct device_node *np,
4477 unsigned int *slots,
4478 unsigned int *slot_width)
4479{
4480 u32 val;
4481 int ret;
4482
4483 if (of_property_read_bool(np, "dai-tdm-slot-num")) {
4484 ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
4485 if (ret)
4486 return ret;
4487
4488 if (slots)
4489 *slots = val;
4490 }
4491
4492 if (of_property_read_bool(np, "dai-tdm-slot-width")) {
4493 ret = of_property_read_u32(np, "dai-tdm-slot-width", &val);
4494 if (ret)
4495 return ret;
4496
4497 if (slot_width)
4498 *slot_width = val;
4499 }
4500
4501 return 0;
4502}
4503EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
4504
4420int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, 4505int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4421 const char *propname) 4506 const char *propname)
4422{ 4507{
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index b9dc6acbba8c..c8a780d0d057 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -70,8 +70,6 @@ static int dapm_up_seq[] = {
70 [snd_soc_dapm_aif_out] = 4, 70 [snd_soc_dapm_aif_out] = 4,
71 [snd_soc_dapm_mic] = 5, 71 [snd_soc_dapm_mic] = 5,
72 [snd_soc_dapm_mux] = 6, 72 [snd_soc_dapm_mux] = 6,
73 [snd_soc_dapm_virt_mux] = 6,
74 [snd_soc_dapm_value_mux] = 6,
75 [snd_soc_dapm_dac] = 7, 73 [snd_soc_dapm_dac] = 7,
76 [snd_soc_dapm_switch] = 8, 74 [snd_soc_dapm_switch] = 8,
77 [snd_soc_dapm_mixer] = 8, 75 [snd_soc_dapm_mixer] = 8,
@@ -102,8 +100,6 @@ static int dapm_down_seq[] = {
102 [snd_soc_dapm_mic] = 7, 100 [snd_soc_dapm_mic] = 7,
103 [snd_soc_dapm_micbias] = 8, 101 [snd_soc_dapm_micbias] = 8,
104 [snd_soc_dapm_mux] = 9, 102 [snd_soc_dapm_mux] = 9,
105 [snd_soc_dapm_virt_mux] = 9,
106 [snd_soc_dapm_value_mux] = 9,
107 [snd_soc_dapm_aif_in] = 10, 103 [snd_soc_dapm_aif_in] = 10,
108 [snd_soc_dapm_aif_out] = 10, 104 [snd_soc_dapm_aif_out] = 10,
109 [snd_soc_dapm_dai_in] = 10, 105 [snd_soc_dapm_dai_in] = 10,
@@ -115,6 +111,12 @@ static int dapm_down_seq[] = {
115 [snd_soc_dapm_post] = 14, 111 [snd_soc_dapm_post] = 14,
116}; 112};
117 113
114static void dapm_assert_locked(struct snd_soc_dapm_context *dapm)
115{
116 if (dapm->card && dapm->card->instantiated)
117 lockdep_assert_held(&dapm->card->dapm_mutex);
118}
119
118static void pop_wait(u32 pop_time) 120static void pop_wait(u32 pop_time)
119{ 121{
120 if (pop_time) 122 if (pop_time)
@@ -146,15 +148,16 @@ static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
146 return !list_empty(&w->dirty); 148 return !list_empty(&w->dirty);
147} 149}
148 150
149void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason) 151static void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
150{ 152{
153 dapm_assert_locked(w->dapm);
154
151 if (!dapm_dirty_widget(w)) { 155 if (!dapm_dirty_widget(w)) {
152 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n", 156 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n",
153 w->name, reason); 157 w->name, reason);
154 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty); 158 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty);
155 } 159 }
156} 160}
157EXPORT_SYMBOL_GPL(dapm_mark_dirty);
158 161
159void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm) 162void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm)
160{ 163{
@@ -361,6 +364,8 @@ static void dapm_reset(struct snd_soc_card *card)
361{ 364{
362 struct snd_soc_dapm_widget *w; 365 struct snd_soc_dapm_widget *w;
363 366
367 lockdep_assert_held(&card->dapm_mutex);
368
364 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats)); 369 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
365 370
366 list_for_each_entry(w, &card->widgets, list) { 371 list_for_each_entry(w, &card->widgets, list) {
@@ -386,7 +391,8 @@ static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg,
386 return -1; 391 return -1;
387} 392}
388 393
389static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val) 394static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg,
395 unsigned int val)
390{ 396{
391 if (w->codec) 397 if (w->codec)
392 return snd_soc_write(w->codec, reg, val); 398 return snd_soc_write(w->codec, reg, val);
@@ -498,131 +504,40 @@ out:
498 return ret; 504 return ret;
499} 505}
500 506
501/* set up initial codec paths */ 507/* connect mux widget to its interconnecting audio paths */
502static void dapm_set_path_status(struct snd_soc_dapm_widget *w, 508static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
503 struct snd_soc_dapm_path *p, int i) 509 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
510 struct snd_soc_dapm_path *path, const char *control_name,
511 const struct snd_kcontrol_new *kcontrol)
504{ 512{
505 switch (w->id) { 513 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
506 case snd_soc_dapm_switch: 514 unsigned int val, item;
507 case snd_soc_dapm_mixer: 515 int i;
508 case snd_soc_dapm_mixer_named_ctl: {
509 int val;
510 struct soc_mixer_control *mc = (struct soc_mixer_control *)
511 w->kcontrol_news[i].private_value;
512 int reg = mc->reg;
513 unsigned int shift = mc->shift;
514 int max = mc->max;
515 unsigned int mask = (1 << fls(max)) - 1;
516 unsigned int invert = mc->invert;
517
518 if (reg != SND_SOC_NOPM) {
519 soc_widget_read(w, reg, &val);
520 val = (val >> shift) & mask;
521 if (invert)
522 val = max - val;
523 p->connect = !!val;
524 } else {
525 p->connect = 0;
526 }
527
528 }
529 break;
530 case snd_soc_dapm_mux: {
531 struct soc_enum *e = (struct soc_enum *)
532 w->kcontrol_news[i].private_value;
533 int val, item;
534
535 soc_widget_read(w, e->reg, &val);
536 item = (val >> e->shift_l) & e->mask;
537
538 if (item < e->max && !strcmp(p->name, e->texts[item]))
539 p->connect = 1;
540 else
541 p->connect = 0;
542 }
543 break;
544 case snd_soc_dapm_virt_mux: {
545 struct soc_enum *e = (struct soc_enum *)
546 w->kcontrol_news[i].private_value;
547 516
548 p->connect = 0; 517 if (e->reg != SND_SOC_NOPM) {
518 soc_widget_read(dest, e->reg, &val);
519 val = (val >> e->shift_l) & e->mask;
520 item = snd_soc_enum_val_to_item(e, val);
521 } else {
549 /* since a virtual mux has no backing registers to 522 /* since a virtual mux has no backing registers to
550 * decide which path to connect, it will try to match 523 * decide which path to connect, it will try to match
551 * with the first enumeration. This is to ensure 524 * with the first enumeration. This is to ensure
552 * that the default mux choice (the first) will be 525 * that the default mux choice (the first) will be
553 * correctly powered up during initialization. 526 * correctly powered up during initialization.
554 */ 527 */
555 if (!strcmp(p->name, e->texts[0])) 528 item = 0;
556 p->connect = 1;
557 } 529 }
558 break;
559 case snd_soc_dapm_value_mux: {
560 struct soc_enum *e = (struct soc_enum *)
561 w->kcontrol_news[i].private_value;
562 int val, item;
563 530
564 soc_widget_read(w, e->reg, &val); 531 for (i = 0; i < e->items; i++) {
565 val = (val >> e->shift_l) & e->mask;
566 for (item = 0; item < e->max; item++) {
567 if (val == e->values[item])
568 break;
569 }
570
571 if (item < e->max && !strcmp(p->name, e->texts[item]))
572 p->connect = 1;
573 else
574 p->connect = 0;
575 }
576 break;
577 /* does not affect routing - always connected */
578 case snd_soc_dapm_pga:
579 case snd_soc_dapm_out_drv:
580 case snd_soc_dapm_output:
581 case snd_soc_dapm_adc:
582 case snd_soc_dapm_input:
583 case snd_soc_dapm_siggen:
584 case snd_soc_dapm_dac:
585 case snd_soc_dapm_micbias:
586 case snd_soc_dapm_vmid:
587 case snd_soc_dapm_supply:
588 case snd_soc_dapm_regulator_supply:
589 case snd_soc_dapm_clock_supply:
590 case snd_soc_dapm_aif_in:
591 case snd_soc_dapm_aif_out:
592 case snd_soc_dapm_dai_in:
593 case snd_soc_dapm_dai_out:
594 case snd_soc_dapm_hp:
595 case snd_soc_dapm_mic:
596 case snd_soc_dapm_spk:
597 case snd_soc_dapm_line:
598 case snd_soc_dapm_dai_link:
599 case snd_soc_dapm_kcontrol:
600 p->connect = 1;
601 break;
602 /* does affect routing - dynamically connected */
603 case snd_soc_dapm_pre:
604 case snd_soc_dapm_post:
605 p->connect = 0;
606 break;
607 }
608}
609
610/* connect mux widget to its interconnecting audio paths */
611static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
612 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
613 struct snd_soc_dapm_path *path, const char *control_name,
614 const struct snd_kcontrol_new *kcontrol)
615{
616 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
617 int i;
618
619 for (i = 0; i < e->max; i++) {
620 if (!(strcmp(control_name, e->texts[i]))) { 532 if (!(strcmp(control_name, e->texts[i]))) {
621 list_add(&path->list, &dapm->card->paths); 533 list_add(&path->list, &dapm->card->paths);
622 list_add(&path->list_sink, &dest->sources); 534 list_add(&path->list_sink, &dest->sources);
623 list_add(&path->list_source, &src->sinks); 535 list_add(&path->list_source, &src->sinks);
624 path->name = (char*)e->texts[i]; 536 path->name = (char*)e->texts[i];
625 dapm_set_path_status(dest, path, 0); 537 if (i == item)
538 path->connect = 1;
539 else
540 path->connect = 0;
626 return 0; 541 return 0;
627 } 542 }
628 } 543 }
@@ -630,6 +545,30 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
630 return -ENODEV; 545 return -ENODEV;
631} 546}
632 547
548/* set up initial codec paths */
549static void dapm_set_mixer_path_status(struct snd_soc_dapm_widget *w,
550 struct snd_soc_dapm_path *p, int i)
551{
552 struct soc_mixer_control *mc = (struct soc_mixer_control *)
553 w->kcontrol_news[i].private_value;
554 unsigned int reg = mc->reg;
555 unsigned int shift = mc->shift;
556 unsigned int max = mc->max;
557 unsigned int mask = (1 << fls(max)) - 1;
558 unsigned int invert = mc->invert;
559 unsigned int val;
560
561 if (reg != SND_SOC_NOPM) {
562 soc_widget_read(w, reg, &val);
563 val = (val >> shift) & mask;
564 if (invert)
565 val = max - val;
566 p->connect = !!val;
567 } else {
568 p->connect = 0;
569 }
570}
571
633/* connect mixer widget to its interconnecting audio paths */ 572/* connect mixer widget to its interconnecting audio paths */
634static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm, 573static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
635 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, 574 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
@@ -644,7 +583,7 @@ static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
644 list_add(&path->list_sink, &dest->sources); 583 list_add(&path->list_sink, &dest->sources);
645 list_add(&path->list_source, &src->sinks); 584 list_add(&path->list_source, &src->sinks);
646 path->name = dest->kcontrol_news[i].name; 585 path->name = dest->kcontrol_news[i].name;
647 dapm_set_path_status(dest, path, i); 586 dapm_set_mixer_path_status(dest, path, i);
648 return 0; 587 return 0;
649 } 588 }
650 } 589 }
@@ -723,8 +662,6 @@ static int dapm_create_or_share_mixmux_kcontrol(struct snd_soc_dapm_widget *w,
723 kcname_in_long_name = true; 662 kcname_in_long_name = true;
724 break; 663 break;
725 case snd_soc_dapm_mux: 664 case snd_soc_dapm_mux:
726 case snd_soc_dapm_virt_mux:
727 case snd_soc_dapm_value_mux:
728 wname_in_long_name = true; 665 wname_in_long_name = true;
729 kcname_in_long_name = false; 666 kcname_in_long_name = false;
730 break; 667 break;
@@ -1823,6 +1760,8 @@ static int dapm_power_widgets(struct snd_soc_card *card, int event)
1823 ASYNC_DOMAIN_EXCLUSIVE(async_domain); 1760 ASYNC_DOMAIN_EXCLUSIVE(async_domain);
1824 enum snd_soc_bias_level bias; 1761 enum snd_soc_bias_level bias;
1825 1762
1763 lockdep_assert_held(&card->dapm_mutex);
1764
1826 trace_snd_soc_dapm_start(card); 1765 trace_snd_soc_dapm_start(card);
1827 1766
1828 list_for_each_entry(d, &card->dapm_list, list) { 1767 list_for_each_entry(d, &card->dapm_list, list) {
@@ -1897,10 +1836,14 @@ static int dapm_power_widgets(struct snd_soc_card *card, int event)
1897 1836
1898 trace_snd_soc_dapm_walk_done(card); 1837 trace_snd_soc_dapm_walk_done(card);
1899 1838
1900 /* Run all the bias changes in parallel */ 1839 /* Run card bias changes at first */
1901 list_for_each_entry(d, &card->dapm_list, list) 1840 dapm_pre_sequence_async(&card->dapm, 0);
1902 async_schedule_domain(dapm_pre_sequence_async, d, 1841 /* Run other bias changes in parallel */
1903 &async_domain); 1842 list_for_each_entry(d, &card->dapm_list, list) {
1843 if (d != &card->dapm)
1844 async_schedule_domain(dapm_pre_sequence_async, d,
1845 &async_domain);
1846 }
1904 async_synchronize_full_domain(&async_domain); 1847 async_synchronize_full_domain(&async_domain);
1905 1848
1906 list_for_each_entry(w, &down_list, power_list) { 1849 list_for_each_entry(w, &down_list, power_list) {
@@ -1920,10 +1863,14 @@ static int dapm_power_widgets(struct snd_soc_card *card, int event)
1920 dapm_seq_run(card, &up_list, event, true); 1863 dapm_seq_run(card, &up_list, event, true);
1921 1864
1922 /* Run all the bias changes in parallel */ 1865 /* Run all the bias changes in parallel */
1923 list_for_each_entry(d, &card->dapm_list, list) 1866 list_for_each_entry(d, &card->dapm_list, list) {
1924 async_schedule_domain(dapm_post_sequence_async, d, 1867 if (d != &card->dapm)
1925 &async_domain); 1868 async_schedule_domain(dapm_post_sequence_async, d,
1869 &async_domain);
1870 }
1926 async_synchronize_full_domain(&async_domain); 1871 async_synchronize_full_domain(&async_domain);
1872 /* Run card bias changes at last */
1873 dapm_post_sequence_async(&card->dapm, 0);
1927 1874
1928 /* do we need to notify any clients that DAPM event is complete */ 1875 /* do we need to notify any clients that DAPM event is complete */
1929 list_for_each_entry(d, &card->dapm_list, list) { 1876 list_for_each_entry(d, &card->dapm_list, list) {
@@ -2110,6 +2057,8 @@ static int soc_dapm_mux_update_power(struct snd_soc_card *card,
2110 struct snd_soc_dapm_path *path; 2057 struct snd_soc_dapm_path *path;
2111 int found = 0; 2058 int found = 0;
2112 2059
2060 lockdep_assert_held(&card->dapm_mutex);
2061
2113 /* find dapm widget path assoc with kcontrol */ 2062 /* find dapm widget path assoc with kcontrol */
2114 dapm_kcontrol_for_each_path(path, kcontrol) { 2063 dapm_kcontrol_for_each_path(path, kcontrol) {
2115 if (!path->name || !e->texts[mux]) 2064 if (!path->name || !e->texts[mux])
@@ -2160,6 +2109,8 @@ static int soc_dapm_mixer_update_power(struct snd_soc_card *card,
2160 struct snd_soc_dapm_path *path; 2109 struct snd_soc_dapm_path *path;
2161 int found = 0; 2110 int found = 0;
2162 2111
2112 lockdep_assert_held(&card->dapm_mutex);
2113
2163 /* find dapm widget path assoc with kcontrol */ 2114 /* find dapm widget path assoc with kcontrol */
2164 dapm_kcontrol_for_each_path(path, kcontrol) { 2115 dapm_kcontrol_for_each_path(path, kcontrol) {
2165 found = 1; 2116 found = 1;
@@ -2325,6 +2276,8 @@ static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
2325{ 2276{
2326 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); 2277 struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
2327 2278
2279 dapm_assert_locked(dapm);
2280
2328 if (!w) { 2281 if (!w) {
2329 dev_err(dapm->dev, "ASoC: DAPM unknown pin %s\n", pin); 2282 dev_err(dapm->dev, "ASoC: DAPM unknown pin %s\n", pin);
2330 return -EINVAL; 2283 return -EINVAL;
@@ -2341,18 +2294,18 @@ static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
2341} 2294}
2342 2295
2343/** 2296/**
2344 * snd_soc_dapm_sync - scan and power dapm paths 2297 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2345 * @dapm: DAPM context 2298 * @dapm: DAPM context
2346 * 2299 *
2347 * Walks all dapm audio paths and powers widgets according to their 2300 * Walks all dapm audio paths and powers widgets according to their
2348 * stream or path usage. 2301 * stream or path usage.
2349 * 2302 *
2303 * Requires external locking.
2304 *
2350 * Returns 0 for success. 2305 * Returns 0 for success.
2351 */ 2306 */
2352int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) 2307int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context *dapm)
2353{ 2308{
2354 int ret;
2355
2356 /* 2309 /*
2357 * Suppress early reports (eg, jacks syncing their state) to avoid 2310 * Suppress early reports (eg, jacks syncing their state) to avoid
2358 * silly DAPM runs during card startup. 2311 * silly DAPM runs during card startup.
@@ -2360,8 +2313,25 @@ int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
2360 if (!dapm->card || !dapm->card->instantiated) 2313 if (!dapm->card || !dapm->card->instantiated)
2361 return 0; 2314 return 0;
2362 2315
2316 return dapm_power_widgets(dapm->card, SND_SOC_DAPM_STREAM_NOP);
2317}
2318EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_unlocked);
2319
2320/**
2321 * snd_soc_dapm_sync - scan and power dapm paths
2322 * @dapm: DAPM context
2323 *
2324 * Walks all dapm audio paths and powers widgets according to their
2325 * stream or path usage.
2326 *
2327 * Returns 0 for success.
2328 */
2329int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
2330{
2331 int ret;
2332
2363 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 2333 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2364 ret = dapm_power_widgets(dapm->card, SND_SOC_DAPM_STREAM_NOP); 2334 ret = snd_soc_dapm_sync_unlocked(dapm);
2365 mutex_unlock(&dapm->card->dapm_mutex); 2335 mutex_unlock(&dapm->card->dapm_mutex);
2366 return ret; 2336 return ret;
2367} 2337}
@@ -2444,8 +2414,6 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2444 path->connect = 1; 2414 path->connect = 1;
2445 return 0; 2415 return 0;
2446 case snd_soc_dapm_mux: 2416 case snd_soc_dapm_mux:
2447 case snd_soc_dapm_virt_mux:
2448 case snd_soc_dapm_value_mux:
2449 ret = dapm_connect_mux(dapm, wsource, wsink, path, control, 2417 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
2450 &wsink->kcontrol_news[0]); 2418 &wsink->kcontrol_news[0]);
2451 if (ret != 0) 2419 if (ret != 0)
@@ -2772,8 +2740,6 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card)
2772 dapm_new_mixer(w); 2740 dapm_new_mixer(w);
2773 break; 2741 break;
2774 case snd_soc_dapm_mux: 2742 case snd_soc_dapm_mux:
2775 case snd_soc_dapm_virt_mux:
2776 case snd_soc_dapm_value_mux:
2777 dapm_new_mux(w); 2743 dapm_new_mux(w);
2778 break; 2744 break;
2779 case snd_soc_dapm_pga: 2745 case snd_soc_dapm_pga:
@@ -2935,213 +2901,75 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
2935{ 2901{
2936 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); 2902 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
2937 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2903 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2938 unsigned int val; 2904 unsigned int reg_val, val;
2939
2940 val = snd_soc_read(codec, e->reg);
2941 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & e->mask;
2942 if (e->shift_l != e->shift_r)
2943 ucontrol->value.enumerated.item[1] =
2944 (val >> e->shift_r) & e->mask;
2945
2946 return 0;
2947}
2948EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
2949
2950/**
2951 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
2952 * @kcontrol: mixer control
2953 * @ucontrol: control element information
2954 *
2955 * Callback to set the value of a dapm enumerated double mixer control.
2956 *
2957 * Returns 0 for success.
2958 */
2959int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
2960 struct snd_ctl_elem_value *ucontrol)
2961{
2962 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
2963 struct snd_soc_card *card = codec->card;
2964 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2965 unsigned int val, mux, change;
2966 unsigned int mask;
2967 struct snd_soc_dapm_update update;
2968 int ret = 0;
2969
2970 if (ucontrol->value.enumerated.item[0] > e->max - 1)
2971 return -EINVAL;
2972 mux = ucontrol->value.enumerated.item[0];
2973 val = mux << e->shift_l;
2974 mask = e->mask << e->shift_l;
2975 if (e->shift_l != e->shift_r) {
2976 if (ucontrol->value.enumerated.item[1] > e->max - 1)
2977 return -EINVAL;
2978 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2979 mask |= e->mask << e->shift_r;
2980 }
2981
2982 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2983
2984 change = snd_soc_test_bits(codec, e->reg, mask, val);
2985 if (change) {
2986 update.kcontrol = kcontrol;
2987 update.reg = e->reg;
2988 update.mask = mask;
2989 update.val = val;
2990 card->update = &update;
2991
2992 ret = soc_dapm_mux_update_power(card, kcontrol, mux, e);
2993
2994 card->update = NULL;
2995 }
2996
2997 mutex_unlock(&card->dapm_mutex);
2998
2999 if (ret > 0)
3000 soc_dpcm_runtime_update(card);
3001
3002 return change;
3003}
3004EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
3005
3006/**
3007 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
3008 * @kcontrol: mixer control
3009 * @ucontrol: control element information
3010 *
3011 * Returns 0 for success.
3012 */
3013int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
3014 struct snd_ctl_elem_value *ucontrol)
3015{
3016 ucontrol->value.enumerated.item[0] = dapm_kcontrol_get_value(kcontrol);
3017 return 0;
3018}
3019EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
3020
3021/**
3022 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
3023 * @kcontrol: mixer control
3024 * @ucontrol: control element information
3025 *
3026 * Returns 0 for success.
3027 */
3028int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
3029 struct snd_ctl_elem_value *ucontrol)
3030{
3031 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
3032 struct snd_soc_card *card = codec->card;
3033 unsigned int value;
3034 struct soc_enum *e =
3035 (struct soc_enum *)kcontrol->private_value;
3036 int change;
3037 int ret = 0;
3038
3039 if (ucontrol->value.enumerated.item[0] >= e->max)
3040 return -EINVAL;
3041 2905
3042 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 2906 if (e->reg != SND_SOC_NOPM)
3043 2907 reg_val = snd_soc_read(codec, e->reg);
3044 value = ucontrol->value.enumerated.item[0]; 2908 else
3045 change = dapm_kcontrol_set_value(kcontrol, value); 2909 reg_val = dapm_kcontrol_get_value(kcontrol);
3046 if (change)
3047 ret = soc_dapm_mux_update_power(card, kcontrol, value, e);
3048
3049 mutex_unlock(&card->dapm_mutex);
3050
3051 if (ret > 0)
3052 soc_dpcm_runtime_update(card);
3053
3054 return change;
3055}
3056EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
3057
3058/**
3059 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
3060 * callback
3061 * @kcontrol: mixer control
3062 * @ucontrol: control element information
3063 *
3064 * Callback to get the value of a dapm semi enumerated double mixer control.
3065 *
3066 * Semi enumerated mixer: the enumerated items are referred as values. Can be
3067 * used for handling bitfield coded enumeration for example.
3068 *
3069 * Returns 0 for success.
3070 */
3071int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
3072 struct snd_ctl_elem_value *ucontrol)
3073{
3074 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
3075 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
3076 unsigned int reg_val, val, mux;
3077 2910
3078 reg_val = snd_soc_read(codec, e->reg);
3079 val = (reg_val >> e->shift_l) & e->mask; 2911 val = (reg_val >> e->shift_l) & e->mask;
3080 for (mux = 0; mux < e->max; mux++) { 2912 ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val);
3081 if (val == e->values[mux])
3082 break;
3083 }
3084 ucontrol->value.enumerated.item[0] = mux;
3085 if (e->shift_l != e->shift_r) { 2913 if (e->shift_l != e->shift_r) {
3086 val = (reg_val >> e->shift_r) & e->mask; 2914 val = (reg_val >> e->shift_r) & e->mask;
3087 for (mux = 0; mux < e->max; mux++) { 2915 val = snd_soc_enum_val_to_item(e, val);
3088 if (val == e->values[mux]) 2916 ucontrol->value.enumerated.item[1] = val;
3089 break;
3090 }
3091 ucontrol->value.enumerated.item[1] = mux;
3092 } 2917 }
3093 2918
3094 return 0; 2919 return 0;
3095} 2920}
3096EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double); 2921EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
3097 2922
3098/** 2923/**
3099 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set 2924 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
3100 * callback
3101 * @kcontrol: mixer control 2925 * @kcontrol: mixer control
3102 * @ucontrol: control element information 2926 * @ucontrol: control element information
3103 * 2927 *
3104 * Callback to set the value of a dapm semi enumerated double mixer control. 2928 * Callback to set the value of a dapm enumerated double mixer control.
3105 *
3106 * Semi enumerated mixer: the enumerated items are referred as values. Can be
3107 * used for handling bitfield coded enumeration for example.
3108 * 2929 *
3109 * Returns 0 for success. 2930 * Returns 0 for success.
3110 */ 2931 */
3111int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, 2932int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
3112 struct snd_ctl_elem_value *ucontrol) 2933 struct snd_ctl_elem_value *ucontrol)
3113{ 2934{
3114 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); 2935 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
3115 struct snd_soc_card *card = codec->card; 2936 struct snd_soc_card *card = codec->card;
3116 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 2937 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
3117 unsigned int val, mux, change; 2938 unsigned int *item = ucontrol->value.enumerated.item;
2939 unsigned int val, change;
3118 unsigned int mask; 2940 unsigned int mask;
3119 struct snd_soc_dapm_update update; 2941 struct snd_soc_dapm_update update;
3120 int ret = 0; 2942 int ret = 0;
3121 2943
3122 if (ucontrol->value.enumerated.item[0] > e->max - 1) 2944 if (item[0] >= e->items)
3123 return -EINVAL; 2945 return -EINVAL;
3124 mux = ucontrol->value.enumerated.item[0]; 2946
3125 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; 2947 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
3126 mask = e->mask << e->shift_l; 2948 mask = e->mask << e->shift_l;
3127 if (e->shift_l != e->shift_r) { 2949 if (e->shift_l != e->shift_r) {
3128 if (ucontrol->value.enumerated.item[1] > e->max - 1) 2950 if (item[1] > e->items)
3129 return -EINVAL; 2951 return -EINVAL;
3130 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; 2952 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_l;
3131 mask |= e->mask << e->shift_r; 2953 mask |= e->mask << e->shift_r;
3132 } 2954 }
3133 2955
3134 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 2956 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
3135 2957
3136 change = snd_soc_test_bits(codec, e->reg, mask, val); 2958 if (e->reg != SND_SOC_NOPM)
2959 change = snd_soc_test_bits(codec, e->reg, mask, val);
2960 else
2961 change = dapm_kcontrol_set_value(kcontrol, val);
2962
3137 if (change) { 2963 if (change) {
3138 update.kcontrol = kcontrol; 2964 if (e->reg != SND_SOC_NOPM) {
3139 update.reg = e->reg; 2965 update.kcontrol = kcontrol;
3140 update.mask = mask; 2966 update.reg = e->reg;
3141 update.val = val; 2967 update.mask = mask;
3142 card->update = &update; 2968 update.val = val;
2969 card->update = &update;
2970 }
3143 2971
3144 ret = soc_dapm_mux_update_power(card, kcontrol, mux, e); 2972 ret = soc_dapm_mux_update_power(card, kcontrol, item[0], e);
3145 2973
3146 card->update = NULL; 2974 card->update = NULL;
3147 } 2975 }
@@ -3153,7 +2981,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
3153 2981
3154 return change; 2982 return change;
3155} 2983}
3156EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); 2984EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
3157 2985
3158/** 2986/**
3159 * snd_soc_dapm_info_pin_switch - Info for a pin switch 2987 * snd_soc_dapm_info_pin_switch - Info for a pin switch
@@ -3283,8 +3111,6 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3283 w->power_check = dapm_generic_check_power; 3111 w->power_check = dapm_generic_check_power;
3284 break; 3112 break;
3285 case snd_soc_dapm_mux: 3113 case snd_soc_dapm_mux:
3286 case snd_soc_dapm_virt_mux:
3287 case snd_soc_dapm_value_mux:
3288 w->power_check = dapm_generic_check_power; 3114 w->power_check = dapm_generic_check_power;
3289 break; 3115 break;
3290 case snd_soc_dapm_dai_out: 3116 case snd_soc_dapm_dai_out:
@@ -4098,7 +3924,7 @@ void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
4098} 3924}
4099EXPORT_SYMBOL_GPL(snd_soc_dapm_free); 3925EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
4100 3926
4101static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm) 3927static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context *dapm)
4102{ 3928{
4103 struct snd_soc_card *card = dapm->card; 3929 struct snd_soc_card *card = dapm->card;
4104 struct snd_soc_dapm_widget *w; 3930 struct snd_soc_dapm_widget *w;
@@ -4138,14 +3964,21 @@ static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
4138 */ 3964 */
4139void snd_soc_dapm_shutdown(struct snd_soc_card *card) 3965void snd_soc_dapm_shutdown(struct snd_soc_card *card)
4140{ 3966{
4141 struct snd_soc_codec *codec; 3967 struct snd_soc_dapm_context *dapm;
4142 3968
4143 list_for_each_entry(codec, &card->codec_dev_list, card_list) { 3969 list_for_each_entry(dapm, &card->dapm_list, list) {
4144 soc_dapm_shutdown_codec(&codec->dapm); 3970 if (dapm != &card->dapm) {
4145 if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) 3971 soc_dapm_shutdown_dapm(dapm);
4146 snd_soc_dapm_set_bias_level(&codec->dapm, 3972 if (dapm->bias_level == SND_SOC_BIAS_STANDBY)
4147 SND_SOC_BIAS_OFF); 3973 snd_soc_dapm_set_bias_level(dapm,
3974 SND_SOC_BIAS_OFF);
3975 }
4148 } 3976 }
3977
3978 soc_dapm_shutdown_dapm(&card->dapm);
3979 if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY)
3980 snd_soc_dapm_set_bias_level(&card->dapm,
3981 SND_SOC_BIAS_OFF);
4149} 3982}
4150 3983
4151/* Module information */ 3984/* Module information */
diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c
index aa886cca3ecf..260efc8466fc 100644
--- a/sound/soc/soc-io.c
+++ b/sound/soc/soc-io.c
@@ -23,21 +23,6 @@
23static int hw_write(struct snd_soc_codec *codec, unsigned int reg, 23static int hw_write(struct snd_soc_codec *codec, unsigned int reg,
24 unsigned int value) 24 unsigned int value)
25{ 25{
26 int ret;
27
28 if (!snd_soc_codec_volatile_register(codec, reg) &&
29 reg < codec->driver->reg_cache_size &&
30 !codec->cache_bypass) {
31 ret = snd_soc_cache_write(codec, reg, value);
32 if (ret < 0)
33 return -1;
34 }
35
36 if (codec->cache_only) {
37 codec->cache_sync = 1;
38 return 0;
39 }
40
41 return regmap_write(codec->control_data, reg, value); 26 return regmap_write(codec->control_data, reg, value);
42} 27}
43 28
@@ -46,32 +31,18 @@ static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg)
46 int ret; 31 int ret;
47 unsigned int val; 32 unsigned int val;
48 33
49 if (reg >= codec->driver->reg_cache_size || 34 ret = regmap_read(codec->control_data, reg, &val);
50 snd_soc_codec_volatile_register(codec, reg) || 35 if (ret == 0)
51 codec->cache_bypass) { 36 return val;
52 if (codec->cache_only) 37 else
53 return -1;
54
55 ret = regmap_read(codec->control_data, reg, &val);
56 if (ret == 0)
57 return val;
58 else
59 return -1;
60 }
61
62 ret = snd_soc_cache_read(codec, reg, &val);
63 if (ret < 0)
64 return -1; 38 return -1;
65 return val;
66} 39}
67 40
68/** 41/**
69 * snd_soc_codec_set_cache_io: Set up standard I/O functions. 42 * snd_soc_codec_set_cache_io: Set up standard I/O functions.
70 * 43 *
71 * @codec: CODEC to configure. 44 * @codec: CODEC to configure.
72 * @addr_bits: Number of bits of register address data. 45 * @map: Register map to write to
73 * @data_bits: Number of bits of data per register.
74 * @control: Control bus used.
75 * 46 *
76 * Register formats are frequently shared between many I2C and SPI 47 * Register formats are frequently shared between many I2C and SPI
77 * devices. In order to promote code reuse the ASoC core provides 48 * devices. In order to promote code reuse the ASoC core provides
@@ -85,60 +56,36 @@ static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg)
85 * volatile registers. 56 * volatile registers.
86 */ 57 */
87int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, 58int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
88 int addr_bits, int data_bits, 59 struct regmap *regmap)
89 enum snd_soc_control_type control)
90{ 60{
91 struct regmap_config config;
92 int ret; 61 int ret;
93 62
94 memset(&config, 0, sizeof(config)); 63 /* Device has made its own regmap arrangements */
95 codec->write = hw_write; 64 if (!regmap)
96 codec->read = hw_read; 65 codec->control_data = dev_get_regmap(codec->dev, NULL);
97 66 else
98 config.reg_bits = addr_bits; 67 codec->control_data = regmap;
99 config.val_bits = data_bits;
100 68
101 switch (control) { 69 if (IS_ERR(codec->control_data))
102#if IS_ENABLED(CONFIG_REGMAP_I2C) 70 return PTR_ERR(codec->control_data);
103 case SND_SOC_I2C:
104 codec->control_data = regmap_init_i2c(to_i2c_client(codec->dev),
105 &config);
106 break;
107#endif
108 71
109#if IS_ENABLED(CONFIG_REGMAP_SPI) 72 codec->write = hw_write;
110 case SND_SOC_SPI: 73 codec->read = hw_read;
111 codec->control_data = regmap_init_spi(to_spi_device(codec->dev),
112 &config);
113 break;
114#endif
115
116 case SND_SOC_REGMAP:
117 /* Device has made its own regmap arrangements */
118 codec->using_regmap = true;
119 if (!codec->control_data)
120 codec->control_data = dev_get_regmap(codec->dev, NULL);
121 74
122 if (codec->control_data) { 75 ret = regmap_get_val_bytes(codec->control_data);
123 ret = regmap_get_val_bytes(codec->control_data); 76 /* Errors are legitimate for non-integer byte
124 /* Errors are legitimate for non-integer byte 77 * multiples */
125 * multiples */ 78 if (ret > 0)
126 if (ret > 0) 79 codec->val_bytes = ret;
127 codec->val_bytes = ret;
128 }
129 break;
130 80
131 default: 81 codec->using_regmap = true;
132 return -EINVAL;
133 }
134 82
135 return PTR_ERR_OR_ZERO(codec->control_data); 83 return 0;
136} 84}
137EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io); 85EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
138#else 86#else
139int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, 87int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
140 int addr_bits, int data_bits, 88 struct regmap *regmap)
141 enum snd_soc_control_type control)
142{ 89{
143 return -ENOTSUPP; 90 return -ENOTSUPP;
144} 91}
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index 23d43dac91da..b903f822d1b2 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -250,7 +250,7 @@ static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio)
250 report = 0; 250 report = 0;
251 251
252 if (gpio->jack_status_check) 252 if (gpio->jack_status_check)
253 report = gpio->jack_status_check(); 253 report = gpio->jack_status_check(gpio->data);
254 254
255 snd_soc_jack_report(jack, report, gpio->report); 255 snd_soc_jack_report(jack, report, gpio->report);
256} 256}
@@ -342,7 +342,8 @@ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
342 gpio_export(gpios[i].gpio, false); 342 gpio_export(gpios[i].gpio, false);
343 343
344 /* Update initial jack status */ 344 /* Update initial jack status */
345 snd_soc_jack_gpio_detect(&gpios[i]); 345 schedule_delayed_work(&gpios[i].work,
346 msecs_to_jiffies(gpios[i].debounce_time));
346 } 347 }
347 348
348 return 0; 349 return 0;
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 28522bd03b8e..2cedf09f6d96 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -35,6 +35,86 @@
35#define DPCM_MAX_BE_USERS 8 35#define DPCM_MAX_BE_USERS 8
36 36
37/** 37/**
38 * snd_soc_runtime_activate() - Increment active count for PCM runtime components
39 * @rtd: ASoC PCM runtime that is activated
40 * @stream: Direction of the PCM stream
41 *
42 * Increments the active count for all the DAIs and components attached to a PCM
43 * runtime. Should typically be called when a stream is opened.
44 *
45 * Must be called with the rtd->pcm_mutex being held
46 */
47void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream)
48{
49 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
50 struct snd_soc_dai *codec_dai = rtd->codec_dai;
51
52 lockdep_assert_held(&rtd->pcm_mutex);
53
54 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
55 cpu_dai->playback_active++;
56 codec_dai->playback_active++;
57 } else {
58 cpu_dai->capture_active++;
59 codec_dai->capture_active++;
60 }
61
62 cpu_dai->active++;
63 codec_dai->active++;
64 cpu_dai->component->active++;
65 codec_dai->component->active++;
66}
67
68/**
69 * snd_soc_runtime_deactivate() - Decrement active count for PCM runtime components
70 * @rtd: ASoC PCM runtime that is deactivated
71 * @stream: Direction of the PCM stream
72 *
73 * Decrements the active count for all the DAIs and components attached to a PCM
74 * runtime. Should typically be called when a stream is closed.
75 *
76 * Must be called with the rtd->pcm_mutex being held
77 */
78void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream)
79{
80 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
81 struct snd_soc_dai *codec_dai = rtd->codec_dai;
82
83 lockdep_assert_held(&rtd->pcm_mutex);
84
85 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
86 cpu_dai->playback_active--;
87 codec_dai->playback_active--;
88 } else {
89 cpu_dai->capture_active--;
90 codec_dai->capture_active--;
91 }
92
93 cpu_dai->active--;
94 codec_dai->active--;
95 cpu_dai->component->active--;
96 codec_dai->component->active--;
97}
98
99/**
100 * snd_soc_runtime_ignore_pmdown_time() - Check whether to ignore the power down delay
101 * @rtd: The ASoC PCM runtime that should be checked.
102 *
103 * This function checks whether the power down delay should be ignored for a
104 * specific PCM runtime. Returns true if the delay is 0, if it the DAI link has
105 * been configured to ignore the delay, or if none of the components benefits
106 * from having the delay.
107 */
108bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd)
109{
110 if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)
111 return true;
112
113 return rtd->cpu_dai->component->ignore_pmdown_time &&
114 rtd->codec_dai->component->ignore_pmdown_time;
115}
116
117/**
38 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters 118 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
39 * @substream: the pcm substream 119 * @substream: the pcm substream
40 * @hw: the hardware parameters 120 * @hw: the hardware parameters
@@ -378,16 +458,9 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
378 runtime->hw.rate_max); 458 runtime->hw.rate_max);
379 459
380dynamic: 460dynamic:
381 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 461
382 cpu_dai->playback_active++; 462 snd_soc_runtime_activate(rtd, substream->stream);
383 codec_dai->playback_active++; 463
384 } else {
385 cpu_dai->capture_active++;
386 codec_dai->capture_active++;
387 }
388 cpu_dai->active++;
389 codec_dai->active++;
390 rtd->codec->active++;
391 mutex_unlock(&rtd->pcm_mutex); 464 mutex_unlock(&rtd->pcm_mutex);
392 return 0; 465 return 0;
393 466
@@ -459,21 +532,10 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
459 struct snd_soc_platform *platform = rtd->platform; 532 struct snd_soc_platform *platform = rtd->platform;
460 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 533 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
461 struct snd_soc_dai *codec_dai = rtd->codec_dai; 534 struct snd_soc_dai *codec_dai = rtd->codec_dai;
462 struct snd_soc_codec *codec = rtd->codec;
463 535
464 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 536 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
465 537
466 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 538 snd_soc_runtime_deactivate(rtd, substream->stream);
467 cpu_dai->playback_active--;
468 codec_dai->playback_active--;
469 } else {
470 cpu_dai->capture_active--;
471 codec_dai->capture_active--;
472 }
473
474 cpu_dai->active--;
475 codec_dai->active--;
476 codec->active--;
477 539
478 /* clear the corresponding DAIs rate when inactive */ 540 /* clear the corresponding DAIs rate when inactive */
479 if (!cpu_dai->active) 541 if (!cpu_dai->active)
@@ -496,8 +558,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
496 cpu_dai->runtime = NULL; 558 cpu_dai->runtime = NULL;
497 559
498 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 560 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
499 if (!rtd->pmdown_time || codec->ignore_pmdown_time || 561 if (snd_soc_runtime_ignore_pmdown_time(rtd)) {
500 rtd->dai_link->ignore_pmdown_time) {
501 /* powered down playback stream now */ 562 /* powered down playback stream now */
502 snd_soc_dapm_stream_event(rtd, 563 snd_soc_dapm_stream_event(rtd,
503 SNDRV_PCM_STREAM_PLAYBACK, 564 SNDRV_PCM_STREAM_PLAYBACK,
@@ -1989,7 +2050,6 @@ int soc_dpcm_runtime_update(struct snd_soc_card *card)
1989 2050
1990 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list); 2051 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list);
1991 if (paths < 0) { 2052 if (paths < 0) {
1992 dpcm_path_put(&list);
1993 dev_warn(fe->dev, "ASoC: %s no valid %s path\n", 2053 dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
1994 fe->dai_link->name, "playback"); 2054 fe->dai_link->name, "playback");
1995 mutex_unlock(&card->mutex); 2055 mutex_unlock(&card->mutex);
@@ -2019,7 +2079,6 @@ capture:
2019 2079
2020 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list); 2080 paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list);
2021 if (paths < 0) { 2081 if (paths < 0) {
2022 dpcm_path_put(&list);
2023 dev_warn(fe->dev, "ASoC: %s no valid %s path\n", 2082 dev_warn(fe->dev, "ASoC: %s no valid %s path\n",
2024 fe->dai_link->name, "capture"); 2083 fe->dai_link->name, "capture");
2025 mutex_unlock(&card->mutex); 2084 mutex_unlock(&card->mutex);
@@ -2084,7 +2143,6 @@ static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
2084 fe->dpcm[stream].runtime = fe_substream->runtime; 2143 fe->dpcm[stream].runtime = fe_substream->runtime;
2085 2144
2086 if (dpcm_path_get(fe, stream, &list) <= 0) { 2145 if (dpcm_path_get(fe, stream, &list) <= 0) {
2087 dpcm_path_put(&list);
2088 dev_dbg(fe->dev, "ASoC: %s no valid %s route\n", 2146 dev_dbg(fe->dev, "ASoC: %s no valid %s route\n",
2089 fe->dai_link->name, stream ? "capture" : "playback"); 2147 fe->dai_link->name, stream ? "capture" : "playback");
2090 } 2148 }
diff --git a/sound/soc/spear/spdif_out.c b/sound/soc/spear/spdif_out.c
index fe99f461aff0..19cca043e6e4 100644
--- a/sound/soc/spear/spdif_out.c
+++ b/sound/soc/spear/spdif_out.c
@@ -213,10 +213,7 @@ static int spdif_digital_mute(struct snd_soc_dai *dai, int mute)
213static int spdif_mute_get(struct snd_kcontrol *kcontrol, 213static int spdif_mute_get(struct snd_kcontrol *kcontrol,
214 struct snd_ctl_elem_value *ucontrol) 214 struct snd_ctl_elem_value *ucontrol)
215{ 215{
216 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 216 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
217 struct snd_soc_card *card = codec->card;
218 struct snd_soc_pcm_runtime *rtd = card->rtd;
219 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
220 struct spdif_out_dev *host = snd_soc_dai_get_drvdata(cpu_dai); 217 struct spdif_out_dev *host = snd_soc_dai_get_drvdata(cpu_dai);
221 218
222 ucontrol->value.integer.value[0] = host->saved_params.mute; 219 ucontrol->value.integer.value[0] = host->saved_params.mute;
@@ -226,10 +223,7 @@ static int spdif_mute_get(struct snd_kcontrol *kcontrol,
226static int spdif_mute_put(struct snd_kcontrol *kcontrol, 223static int spdif_mute_put(struct snd_kcontrol *kcontrol,
227 struct snd_ctl_elem_value *ucontrol) 224 struct snd_ctl_elem_value *ucontrol)
228{ 225{
229 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 226 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
230 struct snd_soc_card *card = codec->card;
231 struct snd_soc_pcm_runtime *rtd = card->rtd;
232 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
233 struct spdif_out_dev *host = snd_soc_dai_get_drvdata(cpu_dai); 227 struct spdif_out_dev *host = snd_soc_dai_get_drvdata(cpu_dai);
234 228
235 if (host->saved_params.mute == ucontrol->value.integer.value[0]) 229 if (host->saved_params.mute == ucontrol->value.integer.value[0])
diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig
index 9f9c1856f822..31198cf7f88d 100644
--- a/sound/soc/tegra/Kconfig
+++ b/sound/soc/tegra/Kconfig
@@ -105,7 +105,7 @@ config SND_SOC_TEGRA_TRIMSLICE
105 tristate "SoC Audio support for TrimSlice board" 105 tristate "SoC Audio support for TrimSlice board"
106 depends on SND_SOC_TEGRA && I2C 106 depends on SND_SOC_TEGRA && I2C
107 select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC 107 select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC
108 select SND_SOC_TLV320AIC23 108 select SND_SOC_TLV320AIC23_I2C
109 help 109 help
110 Say Y or M here if you want to add support for SoC audio on the 110 Say Y or M here if you want to add support for SoC audio on the
111 TrimSlice platform. 111 TrimSlice platform.
diff --git a/sound/soc/tegra/tegra20_ac97.c b/sound/soc/tegra/tegra20_ac97.c
index cf5e1cfe818d..0a59e2383ef3 100644
--- a/sound/soc/tegra/tegra20_ac97.c
+++ b/sound/soc/tegra/tegra20_ac97.c
@@ -306,7 +306,7 @@ static const struct regmap_config tegra20_ac97_regmap_config = {
306 .readable_reg = tegra20_ac97_wr_rd_reg, 306 .readable_reg = tegra20_ac97_wr_rd_reg,
307 .volatile_reg = tegra20_ac97_volatile_reg, 307 .volatile_reg = tegra20_ac97_volatile_reg,
308 .precious_reg = tegra20_ac97_precious_reg, 308 .precious_reg = tegra20_ac97_precious_reg,
309 .cache_type = REGCACHE_RBTREE, 309 .cache_type = REGCACHE_FLAT,
310}; 310};
311 311
312static int tegra20_ac97_platform_probe(struct platform_device *pdev) 312static int tegra20_ac97_platform_probe(struct platform_device *pdev)
diff --git a/sound/soc/tegra/tegra20_das.c b/sound/soc/tegra/tegra20_das.c
index e72392927bd2..a634f13b3ffc 100644
--- a/sound/soc/tegra/tegra20_das.c
+++ b/sound/soc/tegra/tegra20_das.c
@@ -128,7 +128,7 @@ static const struct regmap_config tegra20_das_regmap_config = {
128 .max_register = LAST_REG(DAC_INPUT_DATA_CLK_SEL), 128 .max_register = LAST_REG(DAC_INPUT_DATA_CLK_SEL),
129 .writeable_reg = tegra20_das_wr_rd_reg, 129 .writeable_reg = tegra20_das_wr_rd_reg,
130 .readable_reg = tegra20_das_wr_rd_reg, 130 .readable_reg = tegra20_das_wr_rd_reg,
131 .cache_type = REGCACHE_RBTREE, 131 .cache_type = REGCACHE_FLAT,
132}; 132};
133 133
134static int tegra20_das_probe(struct platform_device *pdev) 134static int tegra20_das_probe(struct platform_device *pdev)
diff --git a/sound/soc/tegra/tegra20_i2s.c b/sound/soc/tegra/tegra20_i2s.c
index 42c1f6bfaf2e..79a9932ffe6e 100644
--- a/sound/soc/tegra/tegra20_i2s.c
+++ b/sound/soc/tegra/tegra20_i2s.c
@@ -333,7 +333,7 @@ static const struct regmap_config tegra20_i2s_regmap_config = {
333 .readable_reg = tegra20_i2s_wr_rd_reg, 333 .readable_reg = tegra20_i2s_wr_rd_reg,
334 .volatile_reg = tegra20_i2s_volatile_reg, 334 .volatile_reg = tegra20_i2s_volatile_reg,
335 .precious_reg = tegra20_i2s_precious_reg, 335 .precious_reg = tegra20_i2s_precious_reg,
336 .cache_type = REGCACHE_RBTREE, 336 .cache_type = REGCACHE_FLAT,
337}; 337};
338 338
339static int tegra20_i2s_platform_probe(struct platform_device *pdev) 339static int tegra20_i2s_platform_probe(struct platform_device *pdev)
diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c
index 8c7c1028e579..a0ce92400faf 100644
--- a/sound/soc/tegra/tegra20_spdif.c
+++ b/sound/soc/tegra/tegra20_spdif.c
@@ -259,7 +259,7 @@ static const struct regmap_config tegra20_spdif_regmap_config = {
259 .readable_reg = tegra20_spdif_wr_rd_reg, 259 .readable_reg = tegra20_spdif_wr_rd_reg,
260 .volatile_reg = tegra20_spdif_volatile_reg, 260 .volatile_reg = tegra20_spdif_volatile_reg,
261 .precious_reg = tegra20_spdif_precious_reg, 261 .precious_reg = tegra20_spdif_precious_reg,
262 .cache_type = REGCACHE_RBTREE, 262 .cache_type = REGCACHE_FLAT,
263}; 263};
264 264
265static int tegra20_spdif_platform_probe(struct platform_device *pdev) 265static int tegra20_spdif_platform_probe(struct platform_device *pdev)
diff --git a/sound/soc/tegra/tegra30_ahub.c b/sound/soc/tegra/tegra30_ahub.c
index d6f4c9940e0c..0db68f49f4d9 100644
--- a/sound/soc/tegra/tegra30_ahub.c
+++ b/sound/soc/tegra/tegra30_ahub.c
@@ -471,7 +471,7 @@ static const struct regmap_config tegra30_ahub_apbif_regmap_config = {
471 .readable_reg = tegra30_ahub_apbif_wr_rd_reg, 471 .readable_reg = tegra30_ahub_apbif_wr_rd_reg,
472 .volatile_reg = tegra30_ahub_apbif_volatile_reg, 472 .volatile_reg = tegra30_ahub_apbif_volatile_reg,
473 .precious_reg = tegra30_ahub_apbif_precious_reg, 473 .precious_reg = tegra30_ahub_apbif_precious_reg,
474 .cache_type = REGCACHE_RBTREE, 474 .cache_type = REGCACHE_FLAT,
475}; 475};
476 476
477static bool tegra30_ahub_ahub_wr_rd_reg(struct device *dev, unsigned int reg) 477static bool tegra30_ahub_ahub_wr_rd_reg(struct device *dev, unsigned int reg)
@@ -490,7 +490,7 @@ static const struct regmap_config tegra30_ahub_ahub_regmap_config = {
490 .max_register = LAST_REG(AUDIO_RX), 490 .max_register = LAST_REG(AUDIO_RX),
491 .writeable_reg = tegra30_ahub_ahub_wr_rd_reg, 491 .writeable_reg = tegra30_ahub_ahub_wr_rd_reg,
492 .readable_reg = tegra30_ahub_ahub_wr_rd_reg, 492 .readable_reg = tegra30_ahub_ahub_wr_rd_reg,
493 .cache_type = REGCACHE_RBTREE, 493 .cache_type = REGCACHE_FLAT,
494}; 494};
495 495
496static struct tegra30_ahub_soc_data soc_data_tegra30 = { 496static struct tegra30_ahub_soc_data soc_data_tegra30 = {
diff --git a/sound/soc/tegra/tegra30_i2s.c b/sound/soc/tegra/tegra30_i2s.c
index 49ad9366add8..f146c41dd3ec 100644
--- a/sound/soc/tegra/tegra30_i2s.c
+++ b/sound/soc/tegra/tegra30_i2s.c
@@ -357,7 +357,7 @@ static const struct regmap_config tegra30_i2s_regmap_config = {
357 .writeable_reg = tegra30_i2s_wr_rd_reg, 357 .writeable_reg = tegra30_i2s_wr_rd_reg,
358 .readable_reg = tegra30_i2s_wr_rd_reg, 358 .readable_reg = tegra30_i2s_wr_rd_reg,
359 .volatile_reg = tegra30_i2s_volatile_reg, 359 .volatile_reg = tegra30_i2s_volatile_reg,
360 .cache_type = REGCACHE_RBTREE, 360 .cache_type = REGCACHE_FLAT,
361}; 361};
362 362
363static const struct tegra30_i2s_soc_data tegra30_i2s_config = { 363static const struct tegra30_i2s_soc_data tegra30_i2s_config = {
diff --git a/sound/sparc/amd7930.c b/sound/sparc/amd7930.c
index 174d21fb56e2..4a85e1433472 100644
--- a/sound/sparc/amd7930.c
+++ b/sound/sparc/amd7930.c
@@ -1019,8 +1019,8 @@ static int amd7930_sbus_probe(struct platform_device *op)
1019 return -ENOENT; 1019 return -ENOENT;
1020 } 1020 }
1021 1021
1022 err = snd_card_create(index[dev_num], id[dev_num], THIS_MODULE, 0, 1022 err = snd_card_new(&op->dev, index[dev_num], id[dev_num],
1023 &card); 1023 THIS_MODULE, 0, &card);
1024 if (err < 0) 1024 if (err < 0)
1025 return err; 1025 return err;
1026 1026
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c
index dbb1b625eb2f..4e91bcaa3664 100644
--- a/sound/sparc/cs4231.c
+++ b/sound/sparc/cs4231.c
@@ -1565,7 +1565,8 @@ static int snd_cs4231_mixer(struct snd_card *card)
1565 1565
1566static int dev; 1566static int dev;
1567 1567
1568static int cs4231_attach_begin(struct snd_card **rcard) 1568static int cs4231_attach_begin(struct platform_device *op,
1569 struct snd_card **rcard)
1569{ 1570{
1570 struct snd_card *card; 1571 struct snd_card *card;
1571 struct snd_cs4231 *chip; 1572 struct snd_cs4231 *chip;
@@ -1581,8 +1582,8 @@ static int cs4231_attach_begin(struct snd_card **rcard)
1581 return -ENOENT; 1582 return -ENOENT;
1582 } 1583 }
1583 1584
1584 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 1585 err = snd_card_new(&op->dev, index[dev], id[dev], THIS_MODULE,
1585 sizeof(struct snd_cs4231), &card); 1586 sizeof(struct snd_cs4231), &card);
1586 if (err < 0) 1587 if (err < 0)
1587 return err; 1588 return err;
1588 1589
@@ -1869,7 +1870,7 @@ static int cs4231_sbus_probe(struct platform_device *op)
1869 struct snd_card *card; 1870 struct snd_card *card;
1870 int err; 1871 int err;
1871 1872
1872 err = cs4231_attach_begin(&card); 1873 err = cs4231_attach_begin(op, &card);
1873 if (err) 1874 if (err)
1874 return err; 1875 return err;
1875 1876
@@ -2060,7 +2061,7 @@ static int cs4231_ebus_probe(struct platform_device *op)
2060 struct snd_card *card; 2061 struct snd_card *card;
2061 int err; 2062 int err;
2062 2063
2063 err = cs4231_attach_begin(&card); 2064 err = cs4231_attach_begin(op, &card);
2064 if (err) 2065 if (err)
2065 return err; 2066 return err;
2066 2067
diff --git a/sound/sparc/dbri.c b/sound/sparc/dbri.c
index eee7afcae375..be1b1aa96b7e 100644
--- a/sound/sparc/dbri.c
+++ b/sound/sparc/dbri.c
@@ -2615,8 +2615,8 @@ static int dbri_probe(struct platform_device *op)
2615 return -ENODEV; 2615 return -ENODEV;
2616 } 2616 }
2617 2617
2618 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 2618 err = snd_card_new(&op->dev, index[dev], id[dev], THIS_MODULE,
2619 sizeof(struct snd_dbri), &card); 2619 sizeof(struct snd_dbri), &card);
2620 if (err < 0) 2620 if (err < 0)
2621 return err; 2621 return err;
2622 2622
diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
index 25c38afaee49..39522367897c 100644
--- a/sound/spi/at73c213.c
+++ b/sound/spi/at73c213.c
@@ -927,8 +927,6 @@ static int snd_at73c213_dev_init(struct snd_card *card,
927 if (retval) 927 if (retval)
928 goto out_snd_dev; 928 goto out_snd_dev;
929 929
930 snd_card_set_dev(card, &spi->dev);
931
932 goto out; 930 goto out;
933 931
934out_snd_dev: 932out_snd_dev:
@@ -966,8 +964,8 @@ static int snd_at73c213_probe(struct spi_device *spi)
966 964
967 /* Allocate "card" using some unused identifiers. */ 965 /* Allocate "card" using some unused identifiers. */
968 snprintf(id, sizeof id, "at73c213_%d", board->ssc_id); 966 snprintf(id, sizeof id, "at73c213_%d", board->ssc_id);
969 retval = snd_card_create(-1, id, THIS_MODULE, 967 retval = snd_card_new(&spi->dev, -1, id, THIS_MODULE,
970 sizeof(struct snd_at73c213), &card); 968 sizeof(struct snd_at73c213), &card);
971 if (retval < 0) 969 if (retval < 0)
972 goto out; 970 goto out;
973 971
diff --git a/sound/usb/6fire/chip.c b/sound/usb/6fire/chip.c
index 66edc4a7917f..dcddfc354ba6 100644
--- a/sound/usb/6fire/chip.c
+++ b/sound/usb/6fire/chip.c
@@ -106,7 +106,7 @@ static int usb6fire_chip_probe(struct usb_interface *intf,
106 } 106 }
107 if (regidx < 0) { 107 if (regidx < 0) {
108 mutex_unlock(&register_mutex); 108 mutex_unlock(&register_mutex);
109 snd_printk(KERN_ERR PREFIX "too many cards registered.\n"); 109 dev_err(&intf->dev, "too many cards registered.\n");
110 return -ENODEV; 110 return -ENODEV;
111 } 111 }
112 devices[regidx] = device; 112 devices[regidx] = device;
@@ -121,20 +121,19 @@ static int usb6fire_chip_probe(struct usb_interface *intf,
121 121
122 /* if we are here, card can be registered in alsa. */ 122 /* if we are here, card can be registered in alsa. */
123 if (usb_set_interface(device, 0, 0) != 0) { 123 if (usb_set_interface(device, 0, 0) != 0) {
124 snd_printk(KERN_ERR PREFIX "can't set first interface.\n"); 124 dev_err(&intf->dev, "can't set first interface.\n");
125 return -EIO; 125 return -EIO;
126 } 126 }
127 ret = snd_card_create(index[regidx], id[regidx], THIS_MODULE, 127 ret = snd_card_new(&intf->dev, index[regidx], id[regidx],
128 sizeof(struct sfire_chip), &card); 128 THIS_MODULE, sizeof(struct sfire_chip), &card);
129 if (ret < 0) { 129 if (ret < 0) {
130 snd_printk(KERN_ERR PREFIX "cannot create alsa card.\n"); 130 dev_err(&intf->dev, "cannot create alsa card.\n");
131 return ret; 131 return ret;
132 } 132 }
133 strcpy(card->driver, "6FireUSB"); 133 strcpy(card->driver, "6FireUSB");
134 strcpy(card->shortname, "TerraTec DMX6FireUSB"); 134 strcpy(card->shortname, "TerraTec DMX6FireUSB");
135 sprintf(card->longname, "%s at %d:%d", card->shortname, 135 sprintf(card->longname, "%s at %d:%d", card->shortname,
136 device->bus->busnum, device->devnum); 136 device->bus->busnum, device->devnum);
137 snd_card_set_dev(card, &intf->dev);
138 137
139 chip = card->private_data; 138 chip = card->private_data;
140 chips[regidx] = chip; 139 chips[regidx] = chip;
@@ -169,7 +168,7 @@ static int usb6fire_chip_probe(struct usb_interface *intf,
169 168
170 ret = snd_card_register(card); 169 ret = snd_card_register(card);
171 if (ret < 0) { 170 if (ret < 0) {
172 snd_printk(KERN_ERR PREFIX "cannot register card."); 171 dev_err(&intf->dev, "cannot register card.");
173 usb6fire_chip_destroy(chip); 172 usb6fire_chip_destroy(chip);
174 return ret; 173 return ret;
175 } 174 }
diff --git a/sound/usb/6fire/comm.c b/sound/usb/6fire/comm.c
index 23452ee617e1..161215d78d95 100644
--- a/sound/usb/6fire/comm.c
+++ b/sound/usb/6fire/comm.c
@@ -51,7 +51,7 @@ static void usb6fire_comm_receiver_handler(struct urb *urb)
51 urb->status = 0; 51 urb->status = 0;
52 urb->actual_length = 0; 52 urb->actual_length = 0;
53 if (usb_submit_urb(urb, GFP_ATOMIC) < 0) 53 if (usb_submit_urb(urb, GFP_ATOMIC) < 0)
54 snd_printk(KERN_WARNING PREFIX 54 dev_warn(&urb->dev->dev,
55 "comm data receiver aborted.\n"); 55 "comm data receiver aborted.\n");
56 } 56 }
57} 57}
@@ -179,7 +179,7 @@ int usb6fire_comm_init(struct sfire_chip *chip)
179 if (ret < 0) { 179 if (ret < 0) {
180 kfree(rt->receiver_buffer); 180 kfree(rt->receiver_buffer);
181 kfree(rt); 181 kfree(rt);
182 snd_printk(KERN_ERR PREFIX "cannot create comm data receiver."); 182 dev_err(&chip->dev->dev, "cannot create comm data receiver.");
183 return ret; 183 return ret;
184 } 184 }
185 chip->comm = rt; 185 chip->comm = rt;
diff --git a/sound/usb/6fire/control.c b/sound/usb/6fire/control.c
index f6434c245720..184e3987ac24 100644
--- a/sound/usb/6fire/control.c
+++ b/sound/usb/6fire/control.c
@@ -194,7 +194,8 @@ static int usb6fire_control_output_vol_put(struct snd_kcontrol *kcontrol,
194 int changed = 0; 194 int changed = 0;
195 195
196 if (ch > 4) { 196 if (ch > 4) {
197 snd_printk(KERN_ERR PREFIX "Invalid channel in volume control."); 197 dev_err(&rt->chip->dev->dev,
198 "Invalid channel in volume control.");
198 return -EINVAL; 199 return -EINVAL;
199 } 200 }
200 201
@@ -222,7 +223,8 @@ static int usb6fire_control_output_vol_get(struct snd_kcontrol *kcontrol,
222 unsigned int ch = kcontrol->private_value; 223 unsigned int ch = kcontrol->private_value;
223 224
224 if (ch > 4) { 225 if (ch > 4) {
225 snd_printk(KERN_ERR PREFIX "Invalid channel in volume control."); 226 dev_err(&rt->chip->dev->dev,
227 "Invalid channel in volume control.");
226 return -EINVAL; 228 return -EINVAL;
227 } 229 }
228 230
@@ -240,7 +242,8 @@ static int usb6fire_control_output_mute_put(struct snd_kcontrol *kcontrol,
240 u8 value = 0; 242 u8 value = 0;
241 243
242 if (ch > 4) { 244 if (ch > 4) {
243 snd_printk(KERN_ERR PREFIX "Invalid channel in volume control."); 245 dev_err(&rt->chip->dev->dev,
246 "Invalid channel in volume control.");
244 return -EINVAL; 247 return -EINVAL;
245 } 248 }
246 249
@@ -265,7 +268,8 @@ static int usb6fire_control_output_mute_get(struct snd_kcontrol *kcontrol,
265 u8 value = rt->output_mute >> ch; 268 u8 value = rt->output_mute >> ch;
266 269
267 if (ch > 4) { 270 if (ch > 4) {
268 snd_printk(KERN_ERR PREFIX "Invalid channel in volume control."); 271 dev_err(&rt->chip->dev->dev,
272 "Invalid channel in volume control.");
269 return -EINVAL; 273 return -EINVAL;
270 } 274 }
271 275
@@ -594,14 +598,14 @@ int usb6fire_control_init(struct sfire_chip *chip)
594 ret = usb6fire_control_add_virtual(rt, chip->card, 598 ret = usb6fire_control_add_virtual(rt, chip->card,
595 "Master Playback Volume", vol_elements); 599 "Master Playback Volume", vol_elements);
596 if (ret) { 600 if (ret) {
597 snd_printk(KERN_ERR PREFIX "cannot add control.\n"); 601 dev_err(&chip->dev->dev, "cannot add control.\n");
598 kfree(rt); 602 kfree(rt);
599 return ret; 603 return ret;
600 } 604 }
601 ret = usb6fire_control_add_virtual(rt, chip->card, 605 ret = usb6fire_control_add_virtual(rt, chip->card,
602 "Master Playback Switch", mute_elements); 606 "Master Playback Switch", mute_elements);
603 if (ret) { 607 if (ret) {
604 snd_printk(KERN_ERR PREFIX "cannot add control.\n"); 608 dev_err(&chip->dev->dev, "cannot add control.\n");
605 kfree(rt); 609 kfree(rt);
606 return ret; 610 return ret;
607 } 611 }
@@ -611,7 +615,7 @@ int usb6fire_control_init(struct sfire_chip *chip)
611 ret = snd_ctl_add(chip->card, snd_ctl_new1(&elements[i], rt)); 615 ret = snd_ctl_add(chip->card, snd_ctl_new1(&elements[i], rt));
612 if (ret < 0) { 616 if (ret < 0) {
613 kfree(rt); 617 kfree(rt);
614 snd_printk(KERN_ERR PREFIX "cannot add control.\n"); 618 dev_err(&chip->dev->dev, "cannot add control.\n");
615 return ret; 619 return ret;
616 } 620 }
617 i++; 621 i++;
diff --git a/sound/usb/6fire/firmware.c b/sound/usb/6fire/firmware.c
index 780bf3f62d28..3b02e54b8f6d 100644
--- a/sound/usb/6fire/firmware.c
+++ b/sound/usb/6fire/firmware.c
@@ -219,16 +219,16 @@ static int usb6fire_fw_ezusb_upload(
219 ret = request_firmware(&fw, fwname, &device->dev); 219 ret = request_firmware(&fw, fwname, &device->dev);
220 if (ret < 0) { 220 if (ret < 0) {
221 kfree(rec); 221 kfree(rec);
222 snd_printk(KERN_ERR PREFIX "error requesting ezusb " 222 dev_err(&intf->dev,
223 "firmware %s.\n", fwname); 223 "error requesting ezusb firmware %s.\n", fwname);
224 return ret; 224 return ret;
225 } 225 }
226 ret = usb6fire_fw_ihex_init(fw, rec); 226 ret = usb6fire_fw_ihex_init(fw, rec);
227 if (ret < 0) { 227 if (ret < 0) {
228 kfree(rec); 228 kfree(rec);
229 release_firmware(fw); 229 release_firmware(fw);
230 snd_printk(KERN_ERR PREFIX "error validating ezusb " 230 dev_err(&intf->dev,
231 "firmware %s.\n", fwname); 231 "error validating ezusb firmware %s.\n", fwname);
232 return ret; 232 return ret;
233 } 233 }
234 /* upload firmware image */ 234 /* upload firmware image */
@@ -237,8 +237,9 @@ static int usb6fire_fw_ezusb_upload(
237 if (ret < 0) { 237 if (ret < 0) {
238 kfree(rec); 238 kfree(rec);
239 release_firmware(fw); 239 release_firmware(fw);
240 snd_printk(KERN_ERR PREFIX "unable to upload ezusb " 240 dev_err(&intf->dev,
241 "firmware %s: begin message.\n", fwname); 241 "unable to upload ezusb firmware %s: begin message.\n",
242 fwname);
242 return ret; 243 return ret;
243 } 244 }
244 245
@@ -248,8 +249,9 @@ static int usb6fire_fw_ezusb_upload(
248 if (ret < 0) { 249 if (ret < 0) {
249 kfree(rec); 250 kfree(rec);
250 release_firmware(fw); 251 release_firmware(fw);
251 snd_printk(KERN_ERR PREFIX "unable to upload ezusb " 252 dev_err(&intf->dev,
252 "firmware %s: data urb.\n", fwname); 253 "unable to upload ezusb firmware %s: data urb.\n",
254 fwname);
253 return ret; 255 return ret;
254 } 256 }
255 } 257 }
@@ -260,8 +262,9 @@ static int usb6fire_fw_ezusb_upload(
260 ret = usb6fire_fw_ezusb_write(device, 0xa0, postaddr, 262 ret = usb6fire_fw_ezusb_write(device, 0xa0, postaddr,
261 postdata, postlen); 263 postdata, postlen);
262 if (ret < 0) { 264 if (ret < 0) {
263 snd_printk(KERN_ERR PREFIX "unable to upload ezusb " 265 dev_err(&intf->dev,
264 "firmware %s: post urb.\n", fwname); 266 "unable to upload ezusb firmware %s: post urb.\n",
267 fwname);
265 return ret; 268 return ret;
266 } 269 }
267 } 270 }
@@ -269,8 +272,9 @@ static int usb6fire_fw_ezusb_upload(
269 data = 0x00; /* resume ezusb cpu */ 272 data = 0x00; /* resume ezusb cpu */
270 ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1); 273 ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1);
271 if (ret < 0) { 274 if (ret < 0) {
272 snd_printk(KERN_ERR PREFIX "unable to upload ezusb " 275 dev_err(&intf->dev,
273 "firmware %s: end message.\n", fwname); 276 "unable to upload ezusb firmware %s: end message.\n",
277 fwname);
274 return ret; 278 return ret;
275 } 279 }
276 return 0; 280 return 0;
@@ -292,7 +296,7 @@ static int usb6fire_fw_fpga_upload(
292 296
293 ret = request_firmware(&fw, fwname, &device->dev); 297 ret = request_firmware(&fw, fwname, &device->dev);
294 if (ret < 0) { 298 if (ret < 0) {
295 snd_printk(KERN_ERR PREFIX "unable to get fpga firmware %s.\n", 299 dev_err(&intf->dev, "unable to get fpga firmware %s.\n",
296 fwname); 300 fwname);
297 kfree(buffer); 301 kfree(buffer);
298 return -EIO; 302 return -EIO;
@@ -305,8 +309,8 @@ static int usb6fire_fw_fpga_upload(
305 if (ret < 0) { 309 if (ret < 0) {
306 kfree(buffer); 310 kfree(buffer);
307 release_firmware(fw); 311 release_firmware(fw);
308 snd_printk(KERN_ERR PREFIX "unable to upload fpga firmware: " 312 dev_err(&intf->dev,
309 "begin urb.\n"); 313 "unable to upload fpga firmware: begin urb.\n");
310 return ret; 314 return ret;
311 } 315 }
312 316
@@ -318,8 +322,8 @@ static int usb6fire_fw_fpga_upload(
318 if (ret < 0) { 322 if (ret < 0) {
319 release_firmware(fw); 323 release_firmware(fw);
320 kfree(buffer); 324 kfree(buffer);
321 snd_printk(KERN_ERR PREFIX "unable to upload fpga " 325 dev_err(&intf->dev,
322 "firmware: fw urb.\n"); 326 "unable to upload fpga firmware: fw urb.\n");
323 return ret; 327 return ret;
324 } 328 }
325 } 329 }
@@ -328,8 +332,8 @@ static int usb6fire_fw_fpga_upload(
328 332
329 ret = usb6fire_fw_ezusb_write(device, 9, 0, NULL, 0); 333 ret = usb6fire_fw_ezusb_write(device, 9, 0, NULL, 0);
330 if (ret < 0) { 334 if (ret < 0) {
331 snd_printk(KERN_ERR PREFIX "unable to upload fpga firmware: " 335 dev_err(&intf->dev,
332 "end urb.\n"); 336 "unable to upload fpga firmware: end urb.\n");
333 return ret; 337 return ret;
334 } 338 }
335 return 0; 339 return 0;
@@ -338,7 +342,7 @@ static int usb6fire_fw_fpga_upload(
338/* check, if the firmware version the devices has currently loaded 342/* check, if the firmware version the devices has currently loaded
339 * is known by this driver. 'version' needs to have 4 bytes version 343 * is known by this driver. 'version' needs to have 4 bytes version
340 * info data. */ 344 * info data. */
341static int usb6fire_fw_check(u8 *version) 345static int usb6fire_fw_check(struct usb_interface *intf, const u8 *version)
342{ 346{
343 int i; 347 int i;
344 348
@@ -346,7 +350,7 @@ static int usb6fire_fw_check(u8 *version)
346 if (!memcmp(version, known_fw_versions + i, 2)) 350 if (!memcmp(version, known_fw_versions + i, 2))
347 return 0; 351 return 0;
348 352
349 snd_printk(KERN_ERR PREFIX "invalid fimware version in device: %4ph. " 353 dev_err(&intf->dev, "invalid fimware version in device: %4ph. "
350 "please reconnect to power. if this failure " 354 "please reconnect to power. if this failure "
351 "still happens, check your firmware installation.", 355 "still happens, check your firmware installation.",
352 version); 356 version);
@@ -364,16 +368,16 @@ int usb6fire_fw_init(struct usb_interface *intf)
364 368
365 ret = usb6fire_fw_ezusb_read(device, 1, 0, buffer, 8); 369 ret = usb6fire_fw_ezusb_read(device, 1, 0, buffer, 8);
366 if (ret < 0) { 370 if (ret < 0) {
367 snd_printk(KERN_ERR PREFIX "unable to receive device " 371 dev_err(&intf->dev,
368 "firmware state.\n"); 372 "unable to receive device firmware state.\n");
369 return ret; 373 return ret;
370 } 374 }
371 if (buffer[0] != 0xeb || buffer[1] != 0xaa || buffer[2] != 0x55) { 375 if (buffer[0] != 0xeb || buffer[1] != 0xaa || buffer[2] != 0x55) {
372 snd_printk(KERN_ERR PREFIX "unknown device firmware state " 376 dev_err(&intf->dev,
373 "received from device: "); 377 "unknown device firmware state received from device:");
374 for (i = 0; i < 8; i++) 378 for (i = 0; i < 8; i++)
375 snd_printk("%02x ", buffer[i]); 379 printk(KERN_CONT "%02x ", buffer[i]);
376 snd_printk("\n"); 380 printk(KERN_CONT "\n");
377 return -EIO; 381 return -EIO;
378 } 382 }
379 /* do we need fpga loader ezusb firmware? */ 383 /* do we need fpga loader ezusb firmware? */
@@ -386,7 +390,7 @@ int usb6fire_fw_init(struct usb_interface *intf)
386 } 390 }
387 /* do we need fpga firmware and application ezusb firmware? */ 391 /* do we need fpga firmware and application ezusb firmware? */
388 else if (buffer[3] == 0x02) { 392 else if (buffer[3] == 0x02) {
389 ret = usb6fire_fw_check(buffer + 4); 393 ret = usb6fire_fw_check(intf, buffer + 4);
390 if (ret < 0) 394 if (ret < 0)
391 return ret; 395 return ret;
392 ret = usb6fire_fw_fpga_upload(intf, "6fire/dmx6firecf.bin"); 396 ret = usb6fire_fw_fpga_upload(intf, "6fire/dmx6firecf.bin");
@@ -402,14 +406,14 @@ int usb6fire_fw_init(struct usb_interface *intf)
402 } 406 }
403 /* all fw loaded? */ 407 /* all fw loaded? */
404 else if (buffer[3] == 0x03) 408 else if (buffer[3] == 0x03)
405 return usb6fire_fw_check(buffer + 4); 409 return usb6fire_fw_check(intf, buffer + 4);
406 /* unknown data? */ 410 /* unknown data? */
407 else { 411 else {
408 snd_printk(KERN_ERR PREFIX "unknown device firmware state " 412 dev_err(&intf->dev,
409 "received from device: "); 413 "unknown device firmware state received from device: ");
410 for (i = 0; i < 8; i++) 414 for (i = 0; i < 8; i++)
411 snd_printk("%02x ", buffer[i]); 415 printk(KERN_CONT "%02x ", buffer[i]);
412 snd_printk("\n"); 416 printk(KERN_CONT "\n");
413 return -EIO; 417 return -EIO;
414 } 418 }
415 return 0; 419 return 0;
diff --git a/sound/usb/6fire/midi.c b/sound/usb/6fire/midi.c
index f3dd7266c391..3d410969553e 100644
--- a/sound/usb/6fire/midi.c
+++ b/sound/usb/6fire/midi.c
@@ -41,8 +41,9 @@ static void usb6fire_midi_out_handler(struct urb *urb)
41 41
42 ret = usb_submit_urb(urb, GFP_ATOMIC); 42 ret = usb_submit_urb(urb, GFP_ATOMIC);
43 if (ret < 0) 43 if (ret < 0)
44 snd_printk(KERN_ERR PREFIX "midi out urb " 44 dev_err(&urb->dev->dev,
45 "submit failed: %d\n", ret); 45 "midi out urb submit failed: %d\n",
46 ret);
46 } else /* no more data to transmit */ 47 } else /* no more data to transmit */
47 rt->out = NULL; 48 rt->out = NULL;
48 } 49 }
@@ -94,8 +95,9 @@ static void usb6fire_midi_out_trigger(
94 95
95 ret = usb_submit_urb(urb, GFP_ATOMIC); 96 ret = usb_submit_urb(urb, GFP_ATOMIC);
96 if (ret < 0) 97 if (ret < 0)
97 snd_printk(KERN_ERR PREFIX "midi out urb " 98 dev_err(&urb->dev->dev,
98 "submit failed: %d\n", ret); 99 "midi out urb submit failed: %d\n",
100 ret);
99 else 101 else
100 rt->out = alsa_sub; 102 rt->out = alsa_sub;
101 } 103 }
@@ -181,7 +183,7 @@ int usb6fire_midi_init(struct sfire_chip *chip)
181 if (ret < 0) { 183 if (ret < 0) {
182 kfree(rt->out_buffer); 184 kfree(rt->out_buffer);
183 kfree(rt); 185 kfree(rt);
184 snd_printk(KERN_ERR PREFIX "unable to create midi.\n"); 186 dev_err(&chip->dev->dev, "unable to create midi.\n");
185 return ret; 187 return ret;
186 } 188 }
187 rt->instance->private_data = rt; 189 rt->instance->private_data = rt;
diff --git a/sound/usb/6fire/pcm.c b/sound/usb/6fire/pcm.c
index b5eb97fdc842..ba40489b2de4 100644
--- a/sound/usb/6fire/pcm.c
+++ b/sound/usb/6fire/pcm.c
@@ -79,32 +79,35 @@ static int usb6fire_pcm_set_rate(struct pcm_runtime *rt)
79 ctrl_rt->usb_streaming = false; 79 ctrl_rt->usb_streaming = false;
80 ret = ctrl_rt->update_streaming(ctrl_rt); 80 ret = ctrl_rt->update_streaming(ctrl_rt);
81 if (ret < 0) { 81 if (ret < 0) {
82 snd_printk(KERN_ERR PREFIX "error stopping streaming while " 82 dev_err(&rt->chip->dev->dev,
83 "setting samplerate %d.\n", rates[rt->rate]); 83 "error stopping streaming while setting samplerate %d.\n",
84 rates[rt->rate]);
84 return ret; 85 return ret;
85 } 86 }
86 87
87 ret = ctrl_rt->set_rate(ctrl_rt, rt->rate); 88 ret = ctrl_rt->set_rate(ctrl_rt, rt->rate);
88 if (ret < 0) { 89 if (ret < 0) {
89 snd_printk(KERN_ERR PREFIX "error setting samplerate %d.\n", 90 dev_err(&rt->chip->dev->dev,
90 rates[rt->rate]); 91 "error setting samplerate %d.\n",
92 rates[rt->rate]);
91 return ret; 93 return ret;
92 } 94 }
93 95
94 ret = ctrl_rt->set_channels(ctrl_rt, OUT_N_CHANNELS, IN_N_CHANNELS, 96 ret = ctrl_rt->set_channels(ctrl_rt, OUT_N_CHANNELS, IN_N_CHANNELS,
95 false, false); 97 false, false);
96 if (ret < 0) { 98 if (ret < 0) {
97 snd_printk(KERN_ERR PREFIX "error initializing channels " 99 dev_err(&rt->chip->dev->dev,
98 "while setting samplerate %d.\n", 100 "error initializing channels while setting samplerate %d.\n",
99 rates[rt->rate]); 101 rates[rt->rate]);
100 return ret; 102 return ret;
101 } 103 }
102 104
103 ctrl_rt->usb_streaming = true; 105 ctrl_rt->usb_streaming = true;
104 ret = ctrl_rt->update_streaming(ctrl_rt); 106 ret = ctrl_rt->update_streaming(ctrl_rt);
105 if (ret < 0) { 107 if (ret < 0) {
106 snd_printk(KERN_ERR PREFIX "error starting streaming while " 108 dev_err(&rt->chip->dev->dev,
107 "setting samplerate %d.\n", rates[rt->rate]); 109 "error starting streaming while setting samplerate %d.\n",
110 rates[rt->rate]);
108 return ret; 111 return ret;
109 } 112 }
110 113
@@ -124,7 +127,7 @@ static struct pcm_substream *usb6fire_pcm_get_substream(
124 return &rt->playback; 127 return &rt->playback;
125 else if (alsa_sub->stream == SNDRV_PCM_STREAM_CAPTURE) 128 else if (alsa_sub->stream == SNDRV_PCM_STREAM_CAPTURE)
126 return &rt->capture; 129 return &rt->capture;
127 snd_printk(KERN_ERR PREFIX "error getting pcm substream slot.\n"); 130 dev_err(&rt->chip->dev->dev, "error getting pcm substream slot.\n");
128 return NULL; 131 return NULL;
129} 132}
130 133
@@ -257,7 +260,7 @@ static void usb6fire_pcm_playback(struct pcm_substream *sub,
257 else if (alsa_rt->format == SNDRV_PCM_FORMAT_S24_LE) 260 else if (alsa_rt->format == SNDRV_PCM_FORMAT_S24_LE)
258 dest = (u32 *) (urb->buffer); 261 dest = (u32 *) (urb->buffer);
259 else { 262 else {
260 snd_printk(KERN_ERR PREFIX "Unknown sample format."); 263 dev_err(&rt->chip->dev->dev, "Unknown sample format.");
261 return; 264 return;
262 } 265 }
263 266
@@ -307,8 +310,8 @@ static void usb6fire_pcm_in_urb_handler(struct urb *usb_urb)
307 } 310 }
308 311
309 if (rt->stream_state == STREAM_DISABLED) { 312 if (rt->stream_state == STREAM_DISABLED) {
310 snd_printk(KERN_ERR PREFIX "internal error: " 313 dev_err(&rt->chip->dev->dev,
311 "stream disabled in in-urb handler.\n"); 314 "internal error: stream disabled in in-urb handler.\n");
312 return; 315 return;
313 } 316 }
314 317
@@ -410,7 +413,7 @@ static int usb6fire_pcm_open(struct snd_pcm_substream *alsa_sub)
410 413
411 if (!sub) { 414 if (!sub) {
412 mutex_unlock(&rt->stream_mutex); 415 mutex_unlock(&rt->stream_mutex);
413 snd_printk(KERN_ERR PREFIX "invalid stream type.\n"); 416 dev_err(&rt->chip->dev->dev, "invalid stream type.\n");
414 return -EINVAL; 417 return -EINVAL;
415 } 418 }
416 419
@@ -481,8 +484,9 @@ static int usb6fire_pcm_prepare(struct snd_pcm_substream *alsa_sub)
481 break; 484 break;
482 if (rt->rate == ARRAY_SIZE(rates)) { 485 if (rt->rate == ARRAY_SIZE(rates)) {
483 mutex_unlock(&rt->stream_mutex); 486 mutex_unlock(&rt->stream_mutex);
484 snd_printk("invalid rate %d in prepare.\n", 487 dev_err(&rt->chip->dev->dev,
485 alsa_rt->rate); 488 "invalid rate %d in prepare.\n",
489 alsa_rt->rate);
486 return -EINVAL; 490 return -EINVAL;
487 } 491 }
488 492
@@ -494,8 +498,8 @@ static int usb6fire_pcm_prepare(struct snd_pcm_substream *alsa_sub)
494 ret = usb6fire_pcm_stream_start(rt); 498 ret = usb6fire_pcm_stream_start(rt);
495 if (ret) { 499 if (ret) {
496 mutex_unlock(&rt->stream_mutex); 500 mutex_unlock(&rt->stream_mutex);
497 snd_printk(KERN_ERR PREFIX 501 dev_err(&rt->chip->dev->dev,
498 "could not start pcm stream.\n"); 502 "could not start pcm stream.\n");
499 return ret; 503 return ret;
500 } 504 }
501 } 505 }
@@ -650,7 +654,7 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
650 if (ret < 0) { 654 if (ret < 0) {
651 usb6fire_pcm_buffers_destroy(rt); 655 usb6fire_pcm_buffers_destroy(rt);
652 kfree(rt); 656 kfree(rt);
653 snd_printk(KERN_ERR PREFIX "cannot create pcm instance.\n"); 657 dev_err(&chip->dev->dev, "cannot create pcm instance.\n");
654 return ret; 658 return ret;
655 } 659 }
656 660
@@ -662,8 +666,8 @@ int usb6fire_pcm_init(struct sfire_chip *chip)
662 if (ret) { 666 if (ret) {
663 usb6fire_pcm_buffers_destroy(rt); 667 usb6fire_pcm_buffers_destroy(rt);
664 kfree(rt); 668 kfree(rt);
665 snd_printk(KERN_ERR PREFIX 669 dev_err(&chip->dev->dev,
666 "error preallocating pcm buffers.\n"); 670 "error preallocating pcm buffers.\n");
667 return ret; 671 return ret;
668 } 672 }
669 rt->instance = pcm; 673 rt->instance = pcm;
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index bc55f708a696..b871ba407e4e 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -418,8 +418,9 @@ static int create_card(struct usb_device *usb_dev,
418 if (devnum >= SNDRV_CARDS) 418 if (devnum >= SNDRV_CARDS)
419 return -ENODEV; 419 return -ENODEV;
420 420
421 err = snd_card_create(index[devnum], id[devnum], THIS_MODULE, 421 err = snd_card_new(&intf->dev,
422 sizeof(struct snd_usb_caiaqdev), &card); 422 index[devnum], id[devnum], THIS_MODULE,
423 sizeof(struct snd_usb_caiaqdev), &card);
423 if (err < 0) 424 if (err < 0)
424 return err; 425 return err;
425 426
@@ -429,7 +430,6 @@ static int create_card(struct usb_device *usb_dev,
429 cdev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor), 430 cdev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor),
430 le16_to_cpu(usb_dev->descriptor.idProduct)); 431 le16_to_cpu(usb_dev->descriptor.idProduct));
431 spin_lock_init(&cdev->spinlock); 432 spin_lock_init(&cdev->spinlock);
432 snd_card_set_dev(card, &intf->dev);
433 433
434 *cardp = card; 434 *cardp = card;
435 return 0; 435 return 0;
diff --git a/sound/usb/card.c b/sound/usb/card.c
index d979050e6a6a..893d5a1afc3c 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -139,8 +139,8 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
139 struct usb_interface *iface = usb_ifnum_to_if(dev, interface); 139 struct usb_interface *iface = usb_ifnum_to_if(dev, interface);
140 140
141 if (!iface) { 141 if (!iface) {
142 snd_printk(KERN_ERR "%d:%u:%d : does not exist\n", 142 dev_err(&dev->dev, "%u:%d : does not exist\n",
143 dev->devnum, ctrlif, interface); 143 ctrlif, interface);
144 return -EINVAL; 144 return -EINVAL;
145 } 145 }
146 146
@@ -165,8 +165,8 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
165 } 165 }
166 166
167 if (usb_interface_claimed(iface)) { 167 if (usb_interface_claimed(iface)) {
168 snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n", 168 dev_dbg(&dev->dev, "%d:%d: skipping, already claimed\n",
169 dev->devnum, ctrlif, interface); 169 ctrlif, interface);
170 return -EINVAL; 170 return -EINVAL;
171 } 171 }
172 172
@@ -176,8 +176,9 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
176 int err = snd_usbmidi_create(chip->card, iface, 176 int err = snd_usbmidi_create(chip->card, iface,
177 &chip->midi_list, NULL); 177 &chip->midi_list, NULL);
178 if (err < 0) { 178 if (err < 0) {
179 snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n", 179 dev_err(&dev->dev,
180 dev->devnum, ctrlif, interface); 180 "%u:%d: cannot create sequencer device\n",
181 ctrlif, interface);
181 return -EINVAL; 182 return -EINVAL;
182 } 183 }
183 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); 184 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
@@ -188,14 +189,15 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
188 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO && 189 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
189 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || 190 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
190 altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) { 191 altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) {
191 snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n", 192 dev_dbg(&dev->dev,
192 dev->devnum, ctrlif, interface, altsd->bInterfaceClass); 193 "%u:%d: skipping non-supported interface %d\n",
194 ctrlif, interface, altsd->bInterfaceClass);
193 /* skip non-supported classes */ 195 /* skip non-supported classes */
194 return -EINVAL; 196 return -EINVAL;
195 } 197 }
196 198
197 if (snd_usb_get_speed(dev) == USB_SPEED_LOW) { 199 if (snd_usb_get_speed(dev) == USB_SPEED_LOW) {
198 snd_printk(KERN_ERR "low speed audio streaming not supported\n"); 200 dev_err(&dev->dev, "low speed audio streaming not supported\n");
199 return -EINVAL; 201 return -EINVAL;
200 } 202 }
201 203
@@ -228,26 +230,27 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
228 protocol = altsd->bInterfaceProtocol; 230 protocol = altsd->bInterfaceProtocol;
229 231
230 if (!control_header) { 232 if (!control_header) {
231 snd_printk(KERN_ERR "cannot find UAC_HEADER\n"); 233 dev_err(&dev->dev, "cannot find UAC_HEADER\n");
232 return -EINVAL; 234 return -EINVAL;
233 } 235 }
234 236
235 switch (protocol) { 237 switch (protocol) {
236 default: 238 default:
237 snd_printdd(KERN_WARNING "unknown interface protocol %#02x, assuming v1\n", 239 dev_warn(&dev->dev,
238 protocol); 240 "unknown interface protocol %#02x, assuming v1\n",
241 protocol);
239 /* fall through */ 242 /* fall through */
240 243
241 case UAC_VERSION_1: { 244 case UAC_VERSION_1: {
242 struct uac1_ac_header_descriptor *h1 = control_header; 245 struct uac1_ac_header_descriptor *h1 = control_header;
243 246
244 if (!h1->bInCollection) { 247 if (!h1->bInCollection) {
245 snd_printk(KERN_INFO "skipping empty audio interface (v1)\n"); 248 dev_info(&dev->dev, "skipping empty audio interface (v1)\n");
246 return -EINVAL; 249 return -EINVAL;
247 } 250 }
248 251
249 if (h1->bLength < sizeof(*h1) + h1->bInCollection) { 252 if (h1->bLength < sizeof(*h1) + h1->bInCollection) {
250 snd_printk(KERN_ERR "invalid UAC_HEADER (v1)\n"); 253 dev_err(&dev->dev, "invalid UAC_HEADER (v1)\n");
251 return -EINVAL; 254 return -EINVAL;
252 } 255 }
253 256
@@ -277,7 +280,7 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
277 } 280 }
278 281
279 if (!assoc) { 282 if (!assoc) {
280 snd_printk(KERN_ERR "Audio class v2 interfaces need an interface association\n"); 283 dev_err(&dev->dev, "Audio class v2 interfaces need an interface association\n");
281 return -EINVAL; 284 return -EINVAL;
282 } 285 }
283 286
@@ -328,7 +331,8 @@ static void remove_trailing_spaces(char *str)
328/* 331/*
329 * create a chip instance and set its names. 332 * create a chip instance and set its names.
330 */ 333 */
331static int snd_usb_audio_create(struct usb_device *dev, int idx, 334static int snd_usb_audio_create(struct usb_interface *intf,
335 struct usb_device *dev, int idx,
332 const struct snd_usb_audio_quirk *quirk, 336 const struct snd_usb_audio_quirk *quirk,
333 struct snd_usb_audio **rchip) 337 struct snd_usb_audio **rchip)
334{ 338{
@@ -350,13 +354,14 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
350 case USB_SPEED_SUPER: 354 case USB_SPEED_SUPER:
351 break; 355 break;
352 default: 356 default:
353 snd_printk(KERN_ERR "unknown device speed %d\n", snd_usb_get_speed(dev)); 357 dev_err(&dev->dev, "unknown device speed %d\n", snd_usb_get_speed(dev));
354 return -ENXIO; 358 return -ENXIO;
355 } 359 }
356 360
357 err = snd_card_create(index[idx], id[idx], THIS_MODULE, 0, &card); 361 err = snd_card_new(&intf->dev, index[idx], id[idx], THIS_MODULE,
362 0, &card);
358 if (err < 0) { 363 if (err < 0) {
359 snd_printk(KERN_ERR "cannot create card instance %d\n", idx); 364 dev_err(&dev->dev, "cannot create card instance %d\n", idx);
360 return err; 365 return err;
361 } 366 }
362 367
@@ -497,7 +502,7 @@ snd_usb_audio_probe(struct usb_device *dev,
497 for (i = 0; i < SNDRV_CARDS; i++) { 502 for (i = 0; i < SNDRV_CARDS; i++) {
498 if (usb_chip[i] && usb_chip[i]->dev == dev) { 503 if (usb_chip[i] && usb_chip[i]->dev == dev) {
499 if (usb_chip[i]->shutdown) { 504 if (usb_chip[i]->shutdown) {
500 snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n"); 505 dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n");
501 goto __error; 506 goto __error;
502 } 507 }
503 chip = usb_chip[i]; 508 chip = usb_chip[i];
@@ -513,15 +518,15 @@ snd_usb_audio_probe(struct usb_device *dev,
513 if (enable[i] && ! usb_chip[i] && 518 if (enable[i] && ! usb_chip[i] &&
514 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) && 519 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
515 (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) { 520 (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
516 if (snd_usb_audio_create(dev, i, quirk, &chip) < 0) { 521 if (snd_usb_audio_create(intf, dev, i, quirk,
522 &chip) < 0) {
517 goto __error; 523 goto __error;
518 } 524 }
519 snd_card_set_dev(chip->card, &intf->dev);
520 chip->pm_intf = intf; 525 chip->pm_intf = intf;
521 break; 526 break;
522 } 527 }
523 if (!chip) { 528 if (!chip) {
524 printk(KERN_ERR "no available usb audio device\n"); 529 dev_err(&dev->dev, "no available usb audio device\n");
525 goto __error; 530 goto __error;
526 } 531 }
527 } 532 }
@@ -691,12 +696,12 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
691 } 696 }
692 697
693 list_for_each_entry(mixer, &chip->mixer_list, list) 698 list_for_each_entry(mixer, &chip->mixer_list, list)
694 snd_usb_mixer_inactivate(mixer); 699 snd_usb_mixer_suspend(mixer);
695 700
696 return 0; 701 return 0;
697} 702}
698 703
699static int usb_audio_resume(struct usb_interface *intf) 704static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
700{ 705{
701 struct snd_usb_audio *chip = usb_get_intfdata(intf); 706 struct snd_usb_audio *chip = usb_get_intfdata(intf);
702 struct usb_mixer_interface *mixer; 707 struct usb_mixer_interface *mixer;
@@ -711,7 +716,7 @@ static int usb_audio_resume(struct usb_interface *intf)
711 * we just notify and restart the mixers 716 * we just notify and restart the mixers
712 */ 717 */
713 list_for_each_entry(mixer, &chip->mixer_list, list) { 718 list_for_each_entry(mixer, &chip->mixer_list, list) {
714 err = snd_usb_mixer_activate(mixer); 719 err = snd_usb_mixer_resume(mixer, reset_resume);
715 if (err < 0) 720 if (err < 0)
716 goto err_out; 721 goto err_out;
717 } 722 }
@@ -723,9 +728,20 @@ static int usb_audio_resume(struct usb_interface *intf)
723err_out: 728err_out:
724 return err; 729 return err;
725} 730}
731
732static int usb_audio_resume(struct usb_interface *intf)
733{
734 return __usb_audio_resume(intf, false);
735}
736
737static int usb_audio_reset_resume(struct usb_interface *intf)
738{
739 return __usb_audio_resume(intf, true);
740}
726#else 741#else
727#define usb_audio_suspend NULL 742#define usb_audio_suspend NULL
728#define usb_audio_resume NULL 743#define usb_audio_resume NULL
744#define usb_audio_reset_resume NULL
729#endif /* CONFIG_PM */ 745#endif /* CONFIG_PM */
730 746
731static struct usb_device_id usb_audio_ids [] = { 747static struct usb_device_id usb_audio_ids [] = {
@@ -747,6 +763,7 @@ static struct usb_driver usb_audio_driver = {
747 .disconnect = usb_audio_disconnect, 763 .disconnect = usb_audio_disconnect,
748 .suspend = usb_audio_suspend, 764 .suspend = usb_audio_suspend,
749 .resume = usb_audio_resume, 765 .resume = usb_audio_resume,
766 .reset_resume = usb_audio_reset_resume,
750 .id_table = usb_audio_ids, 767 .id_table = usb_audio_ids,
751 .supports_autosuspend = 1, 768 .supports_autosuspend = 1,
752}; 769};
diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index 86f80c60b21f..03fed6611d9e 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -115,9 +115,9 @@ static int uac_clock_selector_set_val(struct snd_usb_audio *chip, int selector_i
115 return ret; 115 return ret;
116 116
117 if (ret != sizeof(pin)) { 117 if (ret != sizeof(pin)) {
118 snd_printk(KERN_ERR 118 usb_audio_err(chip,
119 "usb-audio:%d: setting selector (id %d) unexpected length %d\n", 119 "setting selector (id %d) unexpected length %d\n",
120 chip->dev->devnum, selector_id, ret); 120 selector_id, ret);
121 return -EINVAL; 121 return -EINVAL;
122 } 122 }
123 123
@@ -126,9 +126,9 @@ static int uac_clock_selector_set_val(struct snd_usb_audio *chip, int selector_i
126 return ret; 126 return ret;
127 127
128 if (ret != pin) { 128 if (ret != pin) {
129 snd_printk(KERN_ERR 129 usb_audio_err(chip,
130 "usb-audio:%d: setting selector (id %d) to %x failed (current: %d)\n", 130 "setting selector (id %d) to %x failed (current: %d)\n",
131 chip->dev->devnum, selector_id, pin, ret); 131 selector_id, pin, ret);
132 return -EINVAL; 132 return -EINVAL;
133 } 133 }
134 134
@@ -158,7 +158,8 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
158 &data, sizeof(data)); 158 &data, sizeof(data));
159 159
160 if (err < 0) { 160 if (err < 0) {
161 snd_printk(KERN_WARNING "%s(): cannot get clock validity for id %d\n", 161 dev_warn(&dev->dev,
162 "%s(): cannot get clock validity for id %d\n",
162 __func__, source_id); 163 __func__, source_id);
163 return 0; 164 return 0;
164 } 165 }
@@ -177,9 +178,9 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
177 entity_id &= 0xff; 178 entity_id &= 0xff;
178 179
179 if (test_and_set_bit(entity_id, visited)) { 180 if (test_and_set_bit(entity_id, visited)) {
180 snd_printk(KERN_WARNING 181 usb_audio_warn(chip,
181 "%s(): recursive clock topology detected, id %d.\n", 182 "%s(): recursive clock topology detected, id %d.\n",
182 __func__, entity_id); 183 __func__, entity_id);
183 return -EINVAL; 184 return -EINVAL;
184 } 185 }
185 186
@@ -188,8 +189,9 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
188 if (source) { 189 if (source) {
189 entity_id = source->bClockID; 190 entity_id = source->bClockID;
190 if (validate && !uac_clock_source_is_valid(chip, entity_id)) { 191 if (validate && !uac_clock_source_is_valid(chip, entity_id)) {
191 snd_printk(KERN_ERR "usb-audio:%d: clock source %d is not valid, cannot use\n", 192 usb_audio_err(chip,
192 chip->dev->devnum, entity_id); 193 "clock source %d is not valid, cannot use\n",
194 entity_id);
193 return -ENXIO; 195 return -ENXIO;
194 } 196 }
195 return entity_id; 197 return entity_id;
@@ -208,7 +210,7 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
208 /* Selector values are one-based */ 210 /* Selector values are one-based */
209 211
210 if (ret > selector->bNrInPins || ret < 1) { 212 if (ret > selector->bNrInPins || ret < 1) {
211 snd_printk(KERN_ERR 213 usb_audio_err(chip,
212 "%s(): selector reported illegal value, id %d, ret %d\n", 214 "%s(): selector reported illegal value, id %d, ret %d\n",
213 __func__, selector->bClockID, ret); 215 __func__, selector->bClockID, ret);
214 216
@@ -237,9 +239,9 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
237 if (err < 0) 239 if (err < 0)
238 continue; 240 continue;
239 241
240 snd_printk(KERN_INFO 242 usb_audio_info(chip,
241 "usb-audio:%d: found and selected valid clock source %d\n", 243 "found and selected valid clock source %d\n",
242 chip->dev->devnum, ret); 244 ret);
243 return ret; 245 return ret;
244 } 246 }
245 247
@@ -296,8 +298,8 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
296 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, 298 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT,
297 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, 299 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep,
298 data, sizeof(data))) < 0) { 300 data, sizeof(data))) < 0) {
299 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n", 301 dev_err(&dev->dev, "%d:%d: cannot set freq %d to ep %#x\n",
300 dev->devnum, iface, fmt->altsetting, rate, ep); 302 iface, fmt->altsetting, rate, ep);
301 return err; 303 return err;
302 } 304 }
303 305
@@ -305,14 +307,14 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
305 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, 307 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
306 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, 308 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep,
307 data, sizeof(data))) < 0) { 309 data, sizeof(data))) < 0) {
308 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n", 310 dev_err(&dev->dev, "%d:%d: cannot get freq at ep %#x\n",
309 dev->devnum, iface, fmt->altsetting, ep); 311 iface, fmt->altsetting, ep);
310 return 0; /* some devices don't support reading */ 312 return 0; /* some devices don't support reading */
311 } 313 }
312 314
313 crate = data[0] | (data[1] << 8) | (data[2] << 16); 315 crate = data[0] | (data[1] << 8) | (data[2] << 16);
314 if (crate != rate) { 316 if (crate != rate) {
315 snd_printd(KERN_WARNING "current rate %d is different from the runtime rate %d\n", crate, rate); 317 dev_warn(&dev->dev, "current rate %d is different from the runtime rate %d\n", crate, rate);
316 // runtime->rate = crate; 318 // runtime->rate = crate;
317 } 319 }
318 320
@@ -332,8 +334,8 @@ static int get_sample_rate_v2(struct snd_usb_audio *chip, int iface,
332 snd_usb_ctrl_intf(chip) | (clock << 8), 334 snd_usb_ctrl_intf(chip) | (clock << 8),
333 &data, sizeof(data)); 335 &data, sizeof(data));
334 if (err < 0) { 336 if (err < 0) {
335 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2): err %d\n", 337 dev_warn(&dev->dev, "%d:%d: cannot get freq (v2): err %d\n",
336 dev->devnum, iface, altsetting, err); 338 iface, altsetting, err);
337 return 0; 339 return 0;
338 } 340 }
339 341
@@ -369,8 +371,9 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
369 snd_usb_ctrl_intf(chip) | (clock << 8), 371 snd_usb_ctrl_intf(chip) | (clock << 8),
370 &data, sizeof(data)); 372 &data, sizeof(data));
371 if (err < 0) { 373 if (err < 0) {
372 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2): err %d\n", 374 usb_audio_err(chip,
373 dev->devnum, iface, fmt->altsetting, rate, err); 375 "%d:%d: cannot set freq %d (v2): err %d\n",
376 iface, fmt->altsetting, rate, err);
374 return err; 377 return err;
375 } 378 }
376 379
@@ -381,14 +384,14 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
381 384
382 if (cur_rate != rate) { 385 if (cur_rate != rate) {
383 if (!writeable) { 386 if (!writeable) {
384 snd_printk(KERN_WARNING 387 usb_audio_warn(chip,
385 "%d:%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n", 388 "%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n",
386 dev->devnum, iface, fmt->altsetting, rate, cur_rate); 389 iface, fmt->altsetting, rate, cur_rate);
387 return -ENXIO; 390 return -ENXIO;
388 } 391 }
389 snd_printd(KERN_WARNING 392 usb_audio_dbg(chip,
390 "current rate %d is different from the runtime rate %d\n", 393 "current rate %d is different from the runtime rate %d\n",
391 cur_rate, rate); 394 cur_rate, rate);
392 } 395 }
393 396
394 /* Some devices doesn't respond to sample rate changes while the 397 /* Some devices doesn't respond to sample rate changes while the
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 83aabea259d7..e70a87e0d9fe 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -333,8 +333,9 @@ static void queue_pending_output_urbs(struct snd_usb_endpoint *ep)
333 333
334 err = usb_submit_urb(ctx->urb, GFP_ATOMIC); 334 err = usb_submit_urb(ctx->urb, GFP_ATOMIC);
335 if (err < 0) 335 if (err < 0)
336 snd_printk(KERN_ERR "Unable to submit urb #%d: %d (urb %p)\n", 336 usb_audio_err(ep->chip,
337 ctx->index, err, ctx->urb); 337 "Unable to submit urb #%d: %d (urb %p)\n",
338 ctx->index, err, ctx->urb);
338 else 339 else
339 set_bit(ctx->index, &ep->active_mask); 340 set_bit(ctx->index, &ep->active_mask);
340 } 341 }
@@ -387,7 +388,7 @@ static void snd_complete_urb(struct urb *urb)
387 if (err == 0) 388 if (err == 0)
388 return; 389 return;
389 390
390 snd_printk(KERN_ERR "cannot submit urb (err = %d)\n", err); 391 usb_audio_err(ep->chip, "cannot submit urb (err = %d)\n", err);
391 //snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); 392 //snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
392 393
393exit_clear: 394exit_clear:
@@ -426,13 +427,14 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
426 if (ep->ep_num == ep_num && 427 if (ep->ep_num == ep_num &&
427 ep->iface == alts->desc.bInterfaceNumber && 428 ep->iface == alts->desc.bInterfaceNumber &&
428 ep->altsetting == alts->desc.bAlternateSetting) { 429 ep->altsetting == alts->desc.bAlternateSetting) {
429 snd_printdd(KERN_DEBUG "Re-using EP %x in iface %d,%d @%p\n", 430 usb_audio_dbg(ep->chip,
431 "Re-using EP %x in iface %d,%d @%p\n",
430 ep_num, ep->iface, ep->altsetting, ep); 432 ep_num, ep->iface, ep->altsetting, ep);
431 goto __exit_unlock; 433 goto __exit_unlock;
432 } 434 }
433 } 435 }
434 436
435 snd_printdd(KERN_DEBUG "Creating new %s %s endpoint #%x\n", 437 usb_audio_dbg(chip, "Creating new %s %s endpoint #%x\n",
436 is_playback ? "playback" : "capture", 438 is_playback ? "playback" : "capture",
437 type == SND_USB_ENDPOINT_TYPE_DATA ? "data" : "sync", 439 type == SND_USB_ENDPOINT_TYPE_DATA ? "data" : "sync",
438 ep_num); 440 ep_num);
@@ -496,8 +498,9 @@ static int wait_clear_urbs(struct snd_usb_endpoint *ep)
496 } while (time_before(jiffies, end_time)); 498 } while (time_before(jiffies, end_time));
497 499
498 if (alive) 500 if (alive)
499 snd_printk(KERN_ERR "timeout: still %d active urbs on EP #%x\n", 501 usb_audio_err(ep->chip,
500 alive, ep->ep_num); 502 "timeout: still %d active urbs on EP #%x\n",
503 alive, ep->ep_num);
501 clear_bit(EP_FLAG_STOPPING, &ep->flags); 504 clear_bit(EP_FLAG_STOPPING, &ep->flags);
502 505
503 return 0; 506 return 0;
@@ -794,8 +797,9 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
794 int err; 797 int err;
795 798
796 if (ep->use_count != 0) { 799 if (ep->use_count != 0) {
797 snd_printk(KERN_WARNING "Unable to change format on ep #%x: already in use\n", 800 usb_audio_warn(ep->chip,
798 ep->ep_num); 801 "Unable to change format on ep #%x: already in use\n",
802 ep->ep_num);
799 return -EBUSY; 803 return -EBUSY;
800 } 804 }
801 805
@@ -830,8 +834,9 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
830 err = -EINVAL; 834 err = -EINVAL;
831 } 835 }
832 836
833 snd_printdd(KERN_DEBUG "Setting params for ep #%x (type %d, %d urbs), ret=%d\n", 837 usb_audio_dbg(ep->chip,
834 ep->ep_num, ep->type, ep->nurbs, err); 838 "Setting params for ep #%x (type %d, %d urbs), ret=%d\n",
839 ep->ep_num, ep->type, ep->nurbs, err);
835 840
836 return err; 841 return err;
837} 842}
@@ -906,8 +911,9 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, bool can_sleep)
906 911
907 err = usb_submit_urb(urb, GFP_ATOMIC); 912 err = usb_submit_urb(urb, GFP_ATOMIC);
908 if (err < 0) { 913 if (err < 0) {
909 snd_printk(KERN_ERR "cannot submit urb %d, error %d: %s\n", 914 usb_audio_err(ep->chip,
910 i, err, usb_error_string(err)); 915 "cannot submit urb %d, error %d: %s\n",
916 i, err, usb_error_string(err));
911 goto __error; 917 goto __error;
912 } 918 }
913 set_bit(i, &ep->active_mask); 919 set_bit(i, &ep->active_mask);
diff --git a/sound/usb/format.c b/sound/usb/format.c
index d244fd3703d8..8bcc87cf5667 100644
--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -74,8 +74,8 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
74 if ((pcm_formats == 0) && 74 if ((pcm_formats == 0) &&
75 (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) { 75 (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) {
76 /* some devices don't define this correctly... */ 76 /* some devices don't define this correctly... */
77 snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n", 77 usb_audio_info(chip, "%u:%d : format type 0 is detected, processed as PCM\n",
78 chip->dev->devnum, fp->iface, fp->altsetting); 78 fp->iface, fp->altsetting);
79 format = 1 << UAC_FORMAT_TYPE_I_PCM; 79 format = 1 << UAC_FORMAT_TYPE_I_PCM;
80 } 80 }
81 if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) { 81 if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) {
@@ -83,9 +83,9 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
83 sample_width == 24 && sample_bytes == 2) 83 sample_width == 24 && sample_bytes == 2)
84 sample_bytes = 3; 84 sample_bytes = 3;
85 else if (sample_width > sample_bytes * 8) { 85 else if (sample_width > sample_bytes * 8) {
86 snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n", 86 usb_audio_info(chip, "%u:%d : sample bitwidth %d in over sample bytes %d\n",
87 chip->dev->devnum, fp->iface, fp->altsetting, 87 fp->iface, fp->altsetting,
88 sample_width, sample_bytes); 88 sample_width, sample_bytes);
89 } 89 }
90 /* check the format byte size */ 90 /* check the format byte size */
91 switch (sample_bytes) { 91 switch (sample_bytes) {
@@ -108,9 +108,10 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
108 pcm_formats |= SNDRV_PCM_FMTBIT_S32_LE; 108 pcm_formats |= SNDRV_PCM_FMTBIT_S32_LE;
109 break; 109 break;
110 default: 110 default:
111 snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n", 111 usb_audio_info(chip,
112 chip->dev->devnum, fp->iface, fp->altsetting, 112 "%u:%d : unsupported sample bitwidth %d in %d bytes\n",
113 sample_width, sample_bytes); 113 fp->iface, fp->altsetting,
114 sample_width, sample_bytes);
114 break; 115 break;
115 } 116 }
116 } 117 }
@@ -132,8 +133,9 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
132 pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW; 133 pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW;
133 } 134 }
134 if (format & ~0x3f) { 135 if (format & ~0x3f) {
135 snd_printk(KERN_INFO "%d:%u:%d : unsupported format bits %#x\n", 136 usb_audio_info(chip,
136 chip->dev->devnum, fp->iface, fp->altsetting, format); 137 "%u:%d : unsupported format bits %#x\n",
138 fp->iface, fp->altsetting, format);
137 } 139 }
138 140
139 pcm_formats |= snd_usb_interface_dsd_format_quirks(chip, fp, sample_bytes); 141 pcm_formats |= snd_usb_interface_dsd_format_quirks(chip, fp, sample_bytes);
@@ -158,8 +160,9 @@ static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audiof
158 int nr_rates = fmt[offset]; 160 int nr_rates = fmt[offset];
159 161
160 if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) { 162 if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) {
161 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n", 163 usb_audio_err(chip,
162 chip->dev->devnum, fp->iface, fp->altsetting); 164 "%u:%d : invalid UAC_FORMAT_TYPE desc\n",
165 fp->iface, fp->altsetting);
163 return -EINVAL; 166 return -EINVAL;
164 } 167 }
165 168
@@ -171,7 +174,7 @@ static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audiof
171 174
172 fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL); 175 fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
173 if (fp->rate_table == NULL) { 176 if (fp->rate_table == NULL) {
174 snd_printk(KERN_ERR "cannot malloc\n"); 177 usb_audio_err(chip, "cannot malloc\n");
175 return -ENOMEM; 178 return -ENOMEM;
176 } 179 }
177 180
@@ -222,7 +225,8 @@ static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audiof
222 * get to know how many sample rates we have to expect. 225 * get to know how many sample rates we have to expect.
223 * Then fp->rate_table can be allocated and filled. 226 * Then fp->rate_table can be allocated and filled.
224 */ 227 */
225static int parse_uac2_sample_rate_range(struct audioformat *fp, int nr_triplets, 228static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip,
229 struct audioformat *fp, int nr_triplets,
226 const unsigned char *data) 230 const unsigned char *data)
227{ 231{
228 int i, nr_rates = 0; 232 int i, nr_rates = 0;
@@ -261,7 +265,7 @@ static int parse_uac2_sample_rate_range(struct audioformat *fp, int nr_triplets,
261 265
262 nr_rates++; 266 nr_rates++;
263 if (nr_rates >= MAX_NR_RATES) { 267 if (nr_rates >= MAX_NR_RATES) {
264 snd_printk(KERN_ERR "invalid uac2 rates\n"); 268 usb_audio_err(chip, "invalid uac2 rates\n");
265 break; 269 break;
266 } 270 }
267 271
@@ -287,7 +291,8 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
287 int clock = snd_usb_clock_find_source(chip, fp->clock, false); 291 int clock = snd_usb_clock_find_source(chip, fp->clock, false);
288 292
289 if (clock < 0) { 293 if (clock < 0) {
290 snd_printk(KERN_ERR "%s(): unable to find clock source (clock %d)\n", 294 dev_err(&dev->dev,
295 "%s(): unable to find clock source (clock %d)\n",
291 __func__, clock); 296 __func__, clock);
292 goto err; 297 goto err;
293 } 298 }
@@ -300,7 +305,8 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
300 tmp, sizeof(tmp)); 305 tmp, sizeof(tmp));
301 306
302 if (ret < 0) { 307 if (ret < 0) {
303 snd_printk(KERN_ERR "%s(): unable to retrieve number of sample rates (clock %d)\n", 308 dev_err(&dev->dev,
309 "%s(): unable to retrieve number of sample rates (clock %d)\n",
304 __func__, clock); 310 __func__, clock);
305 goto err; 311 goto err;
306 } 312 }
@@ -321,7 +327,8 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
321 data, data_size); 327 data, data_size);
322 328
323 if (ret < 0) { 329 if (ret < 0) {
324 snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range (clock %d)\n", 330 dev_err(&dev->dev,
331 "%s(): unable to retrieve sample rate range (clock %d)\n",
325 __func__, clock); 332 __func__, clock);
326 ret = -EINVAL; 333 ret = -EINVAL;
327 goto err_free; 334 goto err_free;
@@ -332,7 +339,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
332 * will have to deal with. */ 339 * will have to deal with. */
333 kfree(fp->rate_table); 340 kfree(fp->rate_table);
334 fp->rate_table = NULL; 341 fp->rate_table = NULL;
335 fp->nr_rates = parse_uac2_sample_rate_range(fp, nr_triplets, data); 342 fp->nr_rates = parse_uac2_sample_rate_range(chip, fp, nr_triplets, data);
336 343
337 if (fp->nr_rates == 0) { 344 if (fp->nr_rates == 0) {
338 /* SNDRV_PCM_RATE_CONTINUOUS */ 345 /* SNDRV_PCM_RATE_CONTINUOUS */
@@ -348,7 +355,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
348 355
349 /* Call the triplet parser again, but this time, fp->rate_table is 356 /* Call the triplet parser again, but this time, fp->rate_table is
350 * allocated, so the rates will be stored */ 357 * allocated, so the rates will be stored */
351 parse_uac2_sample_rate_range(fp, nr_triplets, data); 358 parse_uac2_sample_rate_range(chip, fp, nr_triplets, data);
352 359
353err_free: 360err_free:
354 kfree(data); 361 kfree(data);
@@ -408,8 +415,9 @@ static int parse_audio_format_i(struct snd_usb_audio *chip,
408 } 415 }
409 416
410 if (fp->channels < 1) { 417 if (fp->channels < 1) {
411 snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n", 418 usb_audio_err(chip,
412 chip->dev->devnum, fp->iface, fp->altsetting, fp->channels); 419 "%u:%d : invalid channels %d\n",
420 fp->iface, fp->altsetting, fp->channels);
413 return -EINVAL; 421 return -EINVAL;
414 } 422 }
415 423
@@ -435,8 +443,9 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
435 fp->formats = SNDRV_PCM_FMTBIT_MPEG; 443 fp->formats = SNDRV_PCM_FMTBIT_MPEG;
436 break; 444 break;
437 default: 445 default:
438 snd_printd(KERN_INFO "%d:%u:%d : unknown format tag %#x is detected. processed as MPEG.\n", 446 usb_audio_info(chip,
439 chip->dev->devnum, fp->iface, fp->altsetting, format); 447 "%u:%d : unknown format tag %#x is detected. processed as MPEG.\n",
448 fp->iface, fp->altsetting, format);
440 fp->formats = SNDRV_PCM_FMTBIT_MPEG; 449 fp->formats = SNDRV_PCM_FMTBIT_MPEG;
441 break; 450 break;
442 } 451 }
@@ -449,7 +458,7 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
449 struct uac_format_type_ii_discrete_descriptor *fmt = _fmt; 458 struct uac_format_type_ii_discrete_descriptor *fmt = _fmt;
450 brate = le16_to_cpu(fmt->wMaxBitRate); 459 brate = le16_to_cpu(fmt->wMaxBitRate);
451 framesize = le16_to_cpu(fmt->wSamplesPerFrame); 460 framesize = le16_to_cpu(fmt->wSamplesPerFrame);
452 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 461 usb_audio_info(chip, "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
453 fp->frame_size = framesize; 462 fp->frame_size = framesize;
454 ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */ 463 ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */
455 break; 464 break;
@@ -458,7 +467,7 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
458 struct uac_format_type_ii_ext_descriptor *fmt = _fmt; 467 struct uac_format_type_ii_ext_descriptor *fmt = _fmt;
459 brate = le16_to_cpu(fmt->wMaxBitRate); 468 brate = le16_to_cpu(fmt->wMaxBitRate);
460 framesize = le16_to_cpu(fmt->wSamplesPerFrame); 469 framesize = le16_to_cpu(fmt->wSamplesPerFrame);
461 snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize); 470 usb_audio_info(chip, "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
462 fp->frame_size = framesize; 471 fp->frame_size = framesize;
463 ret = parse_audio_format_rates_v2(chip, fp); 472 ret = parse_audio_format_rates_v2(chip, fp);
464 break; 473 break;
@@ -484,9 +493,10 @@ int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
484 err = parse_audio_format_ii(chip, fp, format, fmt); 493 err = parse_audio_format_ii(chip, fp, format, fmt);
485 break; 494 break;
486 default: 495 default:
487 snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n", 496 usb_audio_info(chip,
488 chip->dev->devnum, fp->iface, fp->altsetting, 497 "%u:%d : format type %d is not supported yet\n",
489 fmt->bFormatType); 498 fp->iface, fp->altsetting,
499 fmt->bFormatType);
490 return -ENOTSUPP; 500 return -ENOTSUPP;
491 } 501 }
492 fp->fmt_type = fmt->bFormatType; 502 fp->fmt_type = fmt->bFormatType;
diff --git a/sound/usb/hiface/chip.c b/sound/usb/hiface/chip.c
index b0dcb3924ce5..2670d646bda9 100644
--- a/sound/usb/hiface/chip.c
+++ b/sound/usb/hiface/chip.c
@@ -64,7 +64,8 @@ struct hiface_vendor_quirk {
64 u8 extra_freq; 64 u8 extra_freq;
65}; 65};
66 66
67static int hiface_chip_create(struct usb_device *device, int idx, 67static int hiface_chip_create(struct usb_interface *intf,
68 struct usb_device *device, int idx,
68 const struct hiface_vendor_quirk *quirk, 69 const struct hiface_vendor_quirk *quirk,
69 struct hiface_chip **rchip) 70 struct hiface_chip **rchip)
70{ 71{
@@ -76,7 +77,8 @@ static int hiface_chip_create(struct usb_device *device, int idx,
76 *rchip = NULL; 77 *rchip = NULL;
77 78
78 /* if we are here, card can be registered in alsa. */ 79 /* if we are here, card can be registered in alsa. */
79 ret = snd_card_create(index[idx], id[idx], THIS_MODULE, sizeof(*chip), &card); 80 ret = snd_card_new(&intf->dev, index[idx], id[idx], THIS_MODULE,
81 sizeof(*chip), &card);
80 if (ret < 0) { 82 if (ret < 0) {
81 dev_err(&device->dev, "cannot create alsa card.\n"); 83 dev_err(&device->dev, "cannot create alsa card.\n");
82 return ret; 84 return ret;
@@ -132,12 +134,10 @@ static int hiface_chip_probe(struct usb_interface *intf,
132 goto err; 134 goto err;
133 } 135 }
134 136
135 ret = hiface_chip_create(device, i, quirk, &chip); 137 ret = hiface_chip_create(intf, device, i, quirk, &chip);
136 if (ret < 0) 138 if (ret < 0)
137 goto err; 139 goto err;
138 140
139 snd_card_set_dev(chip->card, &intf->dev);
140
141 ret = hiface_pcm_init(chip, quirk ? quirk->extra_freq : 0); 141 ret = hiface_pcm_init(chip, quirk ? quirk->extra_freq : 0);
142 if (ret < 0) 142 if (ret < 0)
143 goto err_chip_destroy; 143 goto err_chip_destroy;
diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index b901f468b67a..9da74d2e8eee 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -191,16 +191,16 @@ static int snd_usbmidi_submit_urb(struct urb* urb, gfp_t flags)
191{ 191{
192 int err = usb_submit_urb(urb, flags); 192 int err = usb_submit_urb(urb, flags);
193 if (err < 0 && err != -ENODEV) 193 if (err < 0 && err != -ENODEV)
194 snd_printk(KERN_ERR "usb_submit_urb: %d\n", err); 194 dev_err(&urb->dev->dev, "usb_submit_urb: %d\n", err);
195 return err; 195 return err;
196} 196}
197 197
198/* 198/*
199 * Error handling for URB completion functions. 199 * Error handling for URB completion functions.
200 */ 200 */
201static int snd_usbmidi_urb_error(int status) 201static int snd_usbmidi_urb_error(const struct urb *urb)
202{ 202{
203 switch (status) { 203 switch (urb->status) {
204 /* manually unlinked, or device gone */ 204 /* manually unlinked, or device gone */
205 case -ENOENT: 205 case -ENOENT:
206 case -ECONNRESET: 206 case -ECONNRESET:
@@ -213,7 +213,7 @@ static int snd_usbmidi_urb_error(int status)
213 case -EILSEQ: 213 case -EILSEQ:
214 return -EIO; 214 return -EIO;
215 default: 215 default:
216 snd_printk(KERN_ERR "urb status %d\n", status); 216 dev_err(&urb->dev->dev, "urb status %d\n", urb->status);
217 return 0; /* continue */ 217 return 0; /* continue */
218 } 218 }
219} 219}
@@ -227,7 +227,7 @@ static void snd_usbmidi_input_data(struct snd_usb_midi_in_endpoint* ep, int port
227 struct usbmidi_in_port* port = &ep->ports[portidx]; 227 struct usbmidi_in_port* port = &ep->ports[portidx];
228 228
229 if (!port->substream) { 229 if (!port->substream) {
230 snd_printd("unexpected port %d!\n", portidx); 230 dev_dbg(&ep->umidi->dev->dev, "unexpected port %d!\n", portidx);
231 return; 231 return;
232 } 232 }
233 if (!test_bit(port->substream->number, &ep->umidi->input_triggered)) 233 if (!test_bit(port->substream->number, &ep->umidi->input_triggered))
@@ -259,7 +259,7 @@ static void snd_usbmidi_in_urb_complete(struct urb* urb)
259 ep->umidi->usb_protocol_ops->input(ep, urb->transfer_buffer, 259 ep->umidi->usb_protocol_ops->input(ep, urb->transfer_buffer,
260 urb->actual_length); 260 urb->actual_length);
261 } else { 261 } else {
262 int err = snd_usbmidi_urb_error(urb->status); 262 int err = snd_usbmidi_urb_error(urb);
263 if (err < 0) { 263 if (err < 0) {
264 if (err != -ENODEV) { 264 if (err != -ENODEV) {
265 ep->error_resubmit = 1; 265 ep->error_resubmit = 1;
@@ -289,7 +289,7 @@ static void snd_usbmidi_out_urb_complete(struct urb* urb)
289 } 289 }
290 spin_unlock(&ep->buffer_lock); 290 spin_unlock(&ep->buffer_lock);
291 if (urb->status < 0) { 291 if (urb->status < 0) {
292 int err = snd_usbmidi_urb_error(urb->status); 292 int err = snd_usbmidi_urb_error(urb);
293 if (err < 0) { 293 if (err < 0) {
294 if (err != -ENODEV) 294 if (err != -ENODEV)
295 mod_timer(&ep->umidi->error_timer, 295 mod_timer(&ep->umidi->error_timer,
@@ -1668,7 +1668,7 @@ static void snd_usbmidi_init_substream(struct snd_usb_midi* umidi,
1668 1668
1669 struct snd_rawmidi_substream *substream = snd_usbmidi_find_substream(umidi, stream, number); 1669 struct snd_rawmidi_substream *substream = snd_usbmidi_find_substream(umidi, stream, number);
1670 if (!substream) { 1670 if (!substream) {
1671 snd_printd(KERN_ERR "substream %d:%d not found\n", stream, number); 1671 dev_err(&umidi->dev->dev, "substream %d:%d not found\n", stream, number);
1672 return; 1672 return;
1673 } 1673 }
1674 1674
@@ -1717,7 +1717,7 @@ static int snd_usbmidi_create_endpoints(struct snd_usb_midi* umidi,
1717 } 1717 }
1718 } 1718 }
1719 } 1719 }
1720 snd_printdd(KERN_INFO "created %d output and %d input ports\n", 1720 dev_dbg(&umidi->dev->dev, "created %d output and %d input ports\n",
1721 out_ports, in_ports); 1721 out_ports, in_ports);
1722 return 0; 1722 return 0;
1723} 1723}
@@ -1747,10 +1747,11 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1747 ms_header->bLength >= 7 && 1747 ms_header->bLength >= 7 &&
1748 ms_header->bDescriptorType == USB_DT_CS_INTERFACE && 1748 ms_header->bDescriptorType == USB_DT_CS_INTERFACE &&
1749 ms_header->bDescriptorSubtype == UAC_HEADER) 1749 ms_header->bDescriptorSubtype == UAC_HEADER)
1750 snd_printdd(KERN_INFO "MIDIStreaming version %02x.%02x\n", 1750 dev_dbg(&umidi->dev->dev, "MIDIStreaming version %02x.%02x\n",
1751 ms_header->bcdMSC[1], ms_header->bcdMSC[0]); 1751 ms_header->bcdMSC[1], ms_header->bcdMSC[0]);
1752 else 1752 else
1753 snd_printk(KERN_WARNING "MIDIStreaming interface descriptor not found\n"); 1753 dev_warn(&umidi->dev->dev,
1754 "MIDIStreaming interface descriptor not found\n");
1754 1755
1755 epidx = 0; 1756 epidx = 0;
1756 for (i = 0; i < intfd->bNumEndpoints; ++i) { 1757 for (i = 0; i < intfd->bNumEndpoints; ++i) {
@@ -1767,7 +1768,8 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1767 if (usb_endpoint_dir_out(ep)) { 1768 if (usb_endpoint_dir_out(ep)) {
1768 if (endpoints[epidx].out_ep) { 1769 if (endpoints[epidx].out_ep) {
1769 if (++epidx >= MIDI_MAX_ENDPOINTS) { 1770 if (++epidx >= MIDI_MAX_ENDPOINTS) {
1770 snd_printk(KERN_WARNING "too many endpoints\n"); 1771 dev_warn(&umidi->dev->dev,
1772 "too many endpoints\n");
1771 break; 1773 break;
1772 } 1774 }
1773 } 1775 }
@@ -1782,12 +1784,13 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1782 */ 1784 */
1783 endpoints[epidx].out_interval = 1; 1785 endpoints[epidx].out_interval = 1;
1784 endpoints[epidx].out_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1; 1786 endpoints[epidx].out_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
1785 snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n", 1787 dev_dbg(&umidi->dev->dev, "EP %02X: %d jack(s)\n",
1786 ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack); 1788 ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
1787 } else { 1789 } else {
1788 if (endpoints[epidx].in_ep) { 1790 if (endpoints[epidx].in_ep) {
1789 if (++epidx >= MIDI_MAX_ENDPOINTS) { 1791 if (++epidx >= MIDI_MAX_ENDPOINTS) {
1790 snd_printk(KERN_WARNING "too many endpoints\n"); 1792 dev_warn(&umidi->dev->dev,
1793 "too many endpoints\n");
1791 break; 1794 break;
1792 } 1795 }
1793 } 1796 }
@@ -1797,7 +1800,7 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi* umidi,
1797 else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW) 1800 else if (snd_usb_get_speed(umidi->dev) == USB_SPEED_LOW)
1798 endpoints[epidx].in_interval = 1; 1801 endpoints[epidx].in_interval = 1;
1799 endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1; 1802 endpoints[epidx].in_cables = (1 << ms_ep->bNumEmbMIDIJack) - 1;
1800 snd_printdd(KERN_INFO "EP %02X: %d jack(s)\n", 1803 dev_dbg(&umidi->dev->dev, "EP %02X: %d jack(s)\n",
1801 ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack); 1804 ep->bEndpointAddress, ms_ep->bNumEmbMIDIJack);
1802 } 1805 }
1803 } 1806 }
@@ -1865,7 +1868,7 @@ static void snd_usbmidi_switch_roland_altsetting(struct snd_usb_midi* umidi)
1865 (get_endpoint(hostif, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT) 1868 (get_endpoint(hostif, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
1866 return; 1869 return;
1867 1870
1868 snd_printdd(KERN_INFO "switching to altsetting %d with int ep\n", 1871 dev_dbg(&umidi->dev->dev, "switching to altsetting %d with int ep\n",
1869 intfd->bAlternateSetting); 1872 intfd->bAlternateSetting);
1870 usb_set_interface(umidi->dev, intfd->bInterfaceNumber, 1873 usb_set_interface(umidi->dev, intfd->bInterfaceNumber,
1871 intfd->bAlternateSetting); 1874 intfd->bAlternateSetting);
@@ -2047,25 +2050,25 @@ static int snd_usbmidi_create_endpoints_midiman(struct snd_usb_midi* umidi,
2047 * input bulk endpoints (at indices 1 and 3) which aren't used. 2050 * input bulk endpoints (at indices 1 and 3) which aren't used.
2048 */ 2051 */
2049 if (intfd->bNumEndpoints < (endpoint->out_cables > 0x0001 ? 5 : 3)) { 2052 if (intfd->bNumEndpoints < (endpoint->out_cables > 0x0001 ? 5 : 3)) {
2050 snd_printdd(KERN_ERR "not enough endpoints\n"); 2053 dev_dbg(&umidi->dev->dev, "not enough endpoints\n");
2051 return -ENOENT; 2054 return -ENOENT;
2052 } 2055 }
2053 2056
2054 epd = get_endpoint(hostif, 0); 2057 epd = get_endpoint(hostif, 0);
2055 if (!usb_endpoint_dir_in(epd) || !usb_endpoint_xfer_int(epd)) { 2058 if (!usb_endpoint_dir_in(epd) || !usb_endpoint_xfer_int(epd)) {
2056 snd_printdd(KERN_ERR "endpoint[0] isn't interrupt\n"); 2059 dev_dbg(&umidi->dev->dev, "endpoint[0] isn't interrupt\n");
2057 return -ENXIO; 2060 return -ENXIO;
2058 } 2061 }
2059 epd = get_endpoint(hostif, 2); 2062 epd = get_endpoint(hostif, 2);
2060 if (!usb_endpoint_dir_out(epd) || !usb_endpoint_xfer_bulk(epd)) { 2063 if (!usb_endpoint_dir_out(epd) || !usb_endpoint_xfer_bulk(epd)) {
2061 snd_printdd(KERN_ERR "endpoint[2] isn't bulk output\n"); 2064 dev_dbg(&umidi->dev->dev, "endpoint[2] isn't bulk output\n");
2062 return -ENXIO; 2065 return -ENXIO;
2063 } 2066 }
2064 if (endpoint->out_cables > 0x0001) { 2067 if (endpoint->out_cables > 0x0001) {
2065 epd = get_endpoint(hostif, 4); 2068 epd = get_endpoint(hostif, 4);
2066 if (!usb_endpoint_dir_out(epd) || 2069 if (!usb_endpoint_dir_out(epd) ||
2067 !usb_endpoint_xfer_bulk(epd)) { 2070 !usb_endpoint_xfer_bulk(epd)) {
2068 snd_printdd(KERN_ERR "endpoint[4] isn't bulk output\n"); 2071 dev_dbg(&umidi->dev->dev, "endpoint[4] isn't bulk output\n");
2069 return -ENXIO; 2072 return -ENXIO;
2070 } 2073 }
2071 } 2074 }
@@ -2289,7 +2292,7 @@ int snd_usbmidi_create(struct snd_card *card,
2289 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); 2292 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
2290 break; 2293 break;
2291 default: 2294 default:
2292 snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); 2295 dev_err(&umidi->dev->dev, "invalid quirk type %d\n", quirk->type);
2293 err = -ENXIO; 2296 err = -ENXIO;
2294 break; 2297 break;
2295 } 2298 }
diff --git a/sound/usb/misc/ua101.c b/sound/usb/misc/ua101.c
index 509315937f25..a1bab149df4d 100644
--- a/sound/usb/misc/ua101.c
+++ b/sound/usb/misc/ua101.c
@@ -1243,8 +1243,9 @@ static int ua101_probe(struct usb_interface *interface,
1243 mutex_unlock(&devices_mutex); 1243 mutex_unlock(&devices_mutex);
1244 return -ENOENT; 1244 return -ENOENT;
1245 } 1245 }
1246 err = snd_card_create(index[card_index], id[card_index], THIS_MODULE, 1246 err = snd_card_new(&interface->dev,
1247 sizeof(*ua), &card); 1247 index[card_index], id[card_index], THIS_MODULE,
1248 sizeof(*ua), &card);
1248 if (err < 0) { 1249 if (err < 0) {
1249 mutex_unlock(&devices_mutex); 1250 mutex_unlock(&devices_mutex);
1250 return err; 1251 return err;
@@ -1283,8 +1284,6 @@ static int ua101_probe(struct usb_interface *interface,
1283 } 1284 }
1284 } 1285 }
1285 1286
1286 snd_card_set_dev(card, &interface->dev);
1287
1288 err = detect_usb_format(ua); 1287 err = detect_usb_format(ua);
1289 if (err < 0) 1288 if (err < 0)
1290 goto probe_error; 1289 goto probe_error;
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 1bed780e21d9..d40a2850e270 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -305,8 +305,9 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v
305 goto out; 305 goto out;
306 } 306 }
307 } 307 }
308 snd_printdd(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n", 308 usb_audio_dbg(chip,
309 request, validx, idx, cval->val_type); 309 "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n",
310 request, validx, idx, cval->val_type);
310 err = -EINVAL; 311 err = -EINVAL;
311 312
312 out: 313 out:
@@ -351,8 +352,9 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int v
351 352
352 if (ret < 0) { 353 if (ret < 0) {
353error: 354error:
354 snd_printk(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n", 355 usb_audio_err(chip,
355 request, validx, idx, cval->val_type); 356 "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n",
357 request, validx, idx, cval->val_type);
356 return ret; 358 return ret;
357 } 359 }
358 360
@@ -413,7 +415,8 @@ static int get_cur_mix_value(struct usb_mixer_elem_info *cval,
413 err = get_cur_mix_raw(cval, channel, value); 415 err = get_cur_mix_raw(cval, channel, value);
414 if (err < 0) { 416 if (err < 0) {
415 if (!cval->mixer->ignore_ctl_error) 417 if (!cval->mixer->ignore_ctl_error)
416 snd_printd(KERN_ERR "cannot get current value for control %d ch %d: err = %d\n", 418 usb_audio_dbg(cval->mixer->chip,
419 "cannot get current value for control %d ch %d: err = %d\n",
417 cval->control, channel, err); 420 cval->control, channel, err);
418 return err; 421 return err;
419 } 422 }
@@ -444,7 +447,7 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
444 447
445 /* FIXME */ 448 /* FIXME */
446 if (request != UAC_SET_CUR) { 449 if (request != UAC_SET_CUR) {
447 snd_printdd(KERN_WARNING "RANGE setting not yet supported\n"); 450 usb_audio_dbg(chip, "RANGE setting not yet supported\n");
448 return -EINVAL; 451 return -EINVAL;
449 } 452 }
450 453
@@ -470,7 +473,7 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
470 goto out; 473 goto out;
471 } 474 }
472 } 475 }
473 snd_printdd(KERN_ERR "cannot set ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d, data = %#x/%#x\n", 476 usb_audio_dbg(chip, "cannot set ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d, data = %#x/%#x\n",
474 request, validx, idx, cval->val_type, buf[0], buf[1]); 477 request, validx, idx, cval->val_type, buf[0], buf[1]);
475 err = -EINVAL; 478 err = -EINVAL;
476 479
@@ -494,7 +497,8 @@ static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
494 cval->ch_readonly & (1 << (channel - 1)); 497 cval->ch_readonly & (1 << (channel - 1));
495 498
496 if (read_only) { 499 if (read_only) {
497 snd_printdd(KERN_INFO "%s(): channel %d of control %d is read_only\n", 500 usb_audio_dbg(cval->mixer->chip,
501 "%s(): channel %d of control %d is read_only\n",
498 __func__, channel, cval->control); 502 __func__, channel, cval->control);
499 return 0; 503 return 0;
500 } 504 }
@@ -560,7 +564,7 @@ int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer,
560 while (snd_ctl_find_id(mixer->chip->card, &kctl->id)) 564 while (snd_ctl_find_id(mixer->chip->card, &kctl->id))
561 kctl->id.index++; 565 kctl->id.index++;
562 if ((err = snd_ctl_add(mixer->chip->card, kctl)) < 0) { 566 if ((err = snd_ctl_add(mixer->chip->card, kctl)) < 0) {
563 snd_printd(KERN_ERR "cannot add control (err = %d)\n", err); 567 usb_audio_dbg(mixer->chip, "cannot add control (err = %d)\n", err);
564 return err; 568 return err;
565 } 569 }
566 cval->elem_id = &kctl->id; 570 cval->elem_id = &kctl->id;
@@ -807,7 +811,8 @@ static void usb_mixer_elem_free(struct snd_kcontrol *kctl)
807static void volume_control_quirks(struct usb_mixer_elem_info *cval, 811static void volume_control_quirks(struct usb_mixer_elem_info *cval,
808 struct snd_kcontrol *kctl) 812 struct snd_kcontrol *kctl)
809{ 813{
810 switch (cval->mixer->chip->usb_id) { 814 struct snd_usb_audio *chip = cval->mixer->chip;
815 switch (chip->usb_id) {
811 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ 816 case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
812 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C600 */ 817 case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C600 */
813 if (strcmp(kctl->id.name, "Effect Duration") == 0) { 818 if (strcmp(kctl->id.name, "Effect Duration") == 0) {
@@ -839,8 +844,8 @@ static void volume_control_quirks(struct usb_mixer_elem_info *cval,
839 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ 844 case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
840 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ 845 case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */
841 if (strcmp(kctl->id.name, "Effect Duration") == 0) { 846 if (strcmp(kctl->id.name, "Effect Duration") == 0) {
842 snd_printk(KERN_INFO 847 usb_audio_info(chip,
843 "usb-audio: set quirk for FTU Effect Duration\n"); 848 "set quirk for FTU Effect Duration\n");
844 cval->min = 0x0000; 849 cval->min = 0x0000;
845 cval->max = 0x7f00; 850 cval->max = 0x7f00;
846 cval->res = 0x0100; 851 cval->res = 0x0100;
@@ -848,8 +853,8 @@ static void volume_control_quirks(struct usb_mixer_elem_info *cval,
848 } 853 }
849 if (strcmp(kctl->id.name, "Effect Volume") == 0 || 854 if (strcmp(kctl->id.name, "Effect Volume") == 0 ||
850 strcmp(kctl->id.name, "Effect Feedback Volume") == 0) { 855 strcmp(kctl->id.name, "Effect Feedback Volume") == 0) {
851 snd_printk(KERN_INFO 856 usb_audio_info(chip,
852 "usb-audio: set quirks for FTU Effect Feedback/Volume\n"); 857 "set quirks for FTU Effect Feedback/Volume\n");
853 cval->min = 0x00; 858 cval->min = 0x00;
854 cval->max = 0x7f; 859 cval->max = 0x7f;
855 break; 860 break;
@@ -867,7 +872,7 @@ static void volume_control_quirks(struct usb_mixer_elem_info *cval,
867 */ 872 */
868 if (!strcmp(kctl->id.name, "PCM Playback Volume") && 873 if (!strcmp(kctl->id.name, "PCM Playback Volume") &&
869 cval->min == -15616) { 874 cval->min == -15616) {
870 snd_printk(KERN_INFO 875 usb_audio_info(chip,
871 "set volume quirk for UDA1321/N101 chip\n"); 876 "set volume quirk for UDA1321/N101 chip\n");
872 cval->max = -256; 877 cval->max = -256;
873 } 878 }
@@ -875,7 +880,7 @@ static void volume_control_quirks(struct usb_mixer_elem_info *cval,
875 880
876 case USB_ID(0x046d, 0x09a4): 881 case USB_ID(0x046d, 0x09a4):
877 if (!strcmp(kctl->id.name, "Mic Capture Volume")) { 882 if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
878 snd_printk(KERN_INFO 883 usb_audio_info(chip,
879 "set volume quirk for QuickCam E3500\n"); 884 "set volume quirk for QuickCam E3500\n");
880 cval->min = 6080; 885 cval->min = 6080;
881 cval->max = 8768; 886 cval->max = 8768;
@@ -896,7 +901,7 @@ static void volume_control_quirks(struct usb_mixer_elem_info *cval,
896 * Proboly there is some logitech magic behind this number --fishor 901 * Proboly there is some logitech magic behind this number --fishor
897 */ 902 */
898 if (!strcmp(kctl->id.name, "Mic Capture Volume")) { 903 if (!strcmp(kctl->id.name, "Mic Capture Volume")) {
899 snd_printk(KERN_INFO 904 usb_audio_info(chip,
900 "set resolution quirk: cval->res = 384\n"); 905 "set resolution quirk: cval->res = 384\n");
901 cval->res = 384; 906 cval->res = 384;
902 } 907 }
@@ -932,7 +937,8 @@ static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
932 } 937 }
933 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 || 938 if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 ||
934 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) { 939 get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) {
935 snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n", 940 usb_audio_err(cval->mixer->chip,
941 "%d:%d: cannot get min/max values for control %d (id %d)\n",
936 cval->id, snd_usb_ctrl_intf(cval->mixer->chip), cval->control, cval->id); 942 cval->id, snd_usb_ctrl_intf(cval->mixer->chip), cval->control, cval->id);
937 return -EINVAL; 943 return -EINVAL;
938 } 944 }
@@ -1196,7 +1202,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1196 1202
1197 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1203 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1198 if (! cval) { 1204 if (! cval) {
1199 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1205 usb_audio_err(state->chip, "cannot malloc kcontrol\n");
1200 return; 1206 return;
1201 } 1207 }
1202 cval->mixer = state->mixer; 1208 cval->mixer = state->mixer;
@@ -1225,7 +1231,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1225 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); 1231 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
1226 1232
1227 if (! kctl) { 1233 if (! kctl) {
1228 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1234 usb_audio_err(state->chip, "cannot malloc kcontrol\n");
1229 kfree(cval); 1235 kfree(cval);
1230 return; 1236 return;
1231 } 1237 }
@@ -1299,16 +1305,16 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1299 * devices. It will definitively catch all buggy Logitech devices. 1305 * devices. It will definitively catch all buggy Logitech devices.
1300 */ 1306 */
1301 if (range > 384) { 1307 if (range > 384) {
1302 snd_printk(KERN_WARNING "usb_audio: Warning! Unlikely big " 1308 usb_audio_warn(state->chip, "Warning! Unlikely big "
1303 "volume range (=%u), cval->res is probably wrong.", 1309 "volume range (=%u), cval->res is probably wrong.",
1304 range); 1310 range);
1305 snd_printk(KERN_WARNING "usb_audio: [%d] FU [%s] ch = %d, " 1311 usb_audio_warn(state->chip, "[%d] FU [%s] ch = %d, "
1306 "val = %d/%d/%d", cval->id, 1312 "val = %d/%d/%d", cval->id,
1307 kctl->id.name, cval->channels, 1313 kctl->id.name, cval->channels,
1308 cval->min, cval->max, cval->res); 1314 cval->min, cval->max, cval->res);
1309 } 1315 }
1310 1316
1311 snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d/%d\n", 1317 usb_audio_dbg(state->chip, "[%d] FU [%s] ch = %d, val = %d/%d/%d\n",
1312 cval->id, kctl->id.name, cval->channels, cval->min, cval->max, cval->res); 1318 cval->id, kctl->id.name, cval->channels, cval->min, cval->max, cval->res);
1313 snd_usb_mixer_add_control(state->mixer, kctl); 1319 snd_usb_mixer_add_control(state->mixer, kctl);
1314} 1320}
@@ -1332,16 +1338,17 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
1332 if (state->mixer->protocol == UAC_VERSION_1) { 1338 if (state->mixer->protocol == UAC_VERSION_1) {
1333 csize = hdr->bControlSize; 1339 csize = hdr->bControlSize;
1334 if (!csize) { 1340 if (!csize) {
1335 snd_printdd(KERN_ERR "usbaudio: unit %u: " 1341 usb_audio_dbg(state->chip,
1336 "invalid bControlSize == 0\n", unitid); 1342 "unit %u: invalid bControlSize == 0\n",
1343 unitid);
1337 return -EINVAL; 1344 return -EINVAL;
1338 } 1345 }
1339 channels = (hdr->bLength - 7) / csize - 1; 1346 channels = (hdr->bLength - 7) / csize - 1;
1340 bmaControls = hdr->bmaControls; 1347 bmaControls = hdr->bmaControls;
1341 if (hdr->bLength < 7 + csize) { 1348 if (hdr->bLength < 7 + csize) {
1342 snd_printk(KERN_ERR "usbaudio: unit %u: " 1349 usb_audio_err(state->chip,
1343 "invalid UAC_FEATURE_UNIT descriptor\n", 1350 "unit %u: invalid UAC_FEATURE_UNIT descriptor\n",
1344 unitid); 1351 unitid);
1345 return -EINVAL; 1352 return -EINVAL;
1346 } 1353 }
1347 } else { 1354 } else {
@@ -1350,9 +1357,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
1350 channels = (hdr->bLength - 6) / 4 - 1; 1357 channels = (hdr->bLength - 6) / 4 - 1;
1351 bmaControls = ftr->bmaControls; 1358 bmaControls = ftr->bmaControls;
1352 if (hdr->bLength < 6 + csize) { 1359 if (hdr->bLength < 6 + csize) {
1353 snd_printk(KERN_ERR "usbaudio: unit %u: " 1360 usb_audio_err(state->chip,
1354 "invalid UAC_FEATURE_UNIT descriptor\n", 1361 "unit %u: invalid UAC_FEATURE_UNIT descriptor\n",
1355 unitid); 1362 unitid);
1356 return -EINVAL; 1363 return -EINVAL;
1357 } 1364 }
1358 } 1365 }
@@ -1370,14 +1377,14 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
1370 /* master configuration quirks */ 1377 /* master configuration quirks */
1371 switch (state->chip->usb_id) { 1378 switch (state->chip->usb_id) {
1372 case USB_ID(0x08bb, 0x2702): 1379 case USB_ID(0x08bb, 0x2702):
1373 snd_printk(KERN_INFO 1380 usb_audio_info(state->chip,
1374 "usbmixer: master volume quirk for PCM2702 chip\n"); 1381 "usbmixer: master volume quirk for PCM2702 chip\n");
1375 /* disable non-functional volume control */ 1382 /* disable non-functional volume control */
1376 master_bits &= ~UAC_CONTROL_BIT(UAC_FU_VOLUME); 1383 master_bits &= ~UAC_CONTROL_BIT(UAC_FU_VOLUME);
1377 break; 1384 break;
1378 case USB_ID(0x1130, 0xf211): 1385 case USB_ID(0x1130, 0xf211):
1379 snd_printk(KERN_INFO 1386 usb_audio_info(state->chip,
1380 "usbmixer: volume control quirk for Tenx TP6911 Audio Headset\n"); 1387 "usbmixer: volume control quirk for Tenx TP6911 Audio Headset\n");
1381 /* disable non-functional volume control */ 1388 /* disable non-functional volume control */
1382 channels = 0; 1389 channels = 0;
1383 break; 1390 break;
@@ -1479,7 +1486,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state,
1479 1486
1480 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); 1487 kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
1481 if (! kctl) { 1488 if (! kctl) {
1482 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1489 usb_audio_err(state->chip, "cannot malloc kcontrol\n");
1483 kfree(cval); 1490 kfree(cval);
1484 return; 1491 return;
1485 } 1492 }
@@ -1492,7 +1499,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state,
1492 len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1); 1499 len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1);
1493 append_ctl_name(kctl, " Volume"); 1500 append_ctl_name(kctl, " Volume");
1494 1501
1495 snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n", 1502 usb_audio_dbg(state->chip, "[%d] MU [%s] ch = %d, val = %d/%d\n",
1496 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1503 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
1497 snd_usb_mixer_add_control(state->mixer, kctl); 1504 snd_usb_mixer_add_control(state->mixer, kctl);
1498} 1505}
@@ -1509,12 +1516,12 @@ static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, void *r
1509 int pin, ich, err; 1516 int pin, ich, err;
1510 1517
1511 if (desc->bLength < 11 || ! (input_pins = desc->bNrInPins) || ! (num_outs = uac_mixer_unit_bNrChannels(desc))) { 1518 if (desc->bLength < 11 || ! (input_pins = desc->bNrInPins) || ! (num_outs = uac_mixer_unit_bNrChannels(desc))) {
1512 snd_printk(KERN_ERR "invalid MIXER UNIT descriptor %d\n", unitid); 1519 usb_audio_err(state->chip, "invalid MIXER UNIT descriptor %d\n", unitid);
1513 return -EINVAL; 1520 return -EINVAL;
1514 } 1521 }
1515 /* no bmControls field (e.g. Maya44) -> ignore */ 1522 /* no bmControls field (e.g. Maya44) -> ignore */
1516 if (desc->bLength <= 10 + input_pins) { 1523 if (desc->bLength <= 10 + input_pins) {
1517 snd_printdd(KERN_INFO "MU %d has no bmControls field\n", unitid); 1524 usb_audio_dbg(state->chip, "MU %d has no bmControls field\n", unitid);
1518 return 0; 1525 return 0;
1519 } 1526 }
1520 1527
@@ -1713,7 +1720,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, void *raw
1713 1720
1714 if (desc->bLength < 13 || desc->bLength < 13 + num_ins || 1721 if (desc->bLength < 13 || desc->bLength < 13 + num_ins ||
1715 desc->bLength < num_ins + uac_processing_unit_bControlSize(desc, state->mixer->protocol)) { 1722 desc->bLength < num_ins + uac_processing_unit_bControlSize(desc, state->mixer->protocol)) {
1716 snd_printk(KERN_ERR "invalid %s descriptor (id %d)\n", name, unitid); 1723 usb_audio_err(state->chip, "invalid %s descriptor (id %d)\n", name, unitid);
1717 return -EINVAL; 1724 return -EINVAL;
1718 } 1725 }
1719 1726
@@ -1739,7 +1746,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, void *raw
1739 continue; 1746 continue;
1740 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1747 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1741 if (! cval) { 1748 if (! cval) {
1742 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1749 usb_audio_err(state->chip, "cannot malloc kcontrol\n");
1743 return -ENOMEM; 1750 return -ENOMEM;
1744 } 1751 }
1745 cval->mixer = state->mixer; 1752 cval->mixer = state->mixer;
@@ -1771,7 +1778,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, void *raw
1771 1778
1772 kctl = snd_ctl_new1(&mixer_procunit_ctl, cval); 1779 kctl = snd_ctl_new1(&mixer_procunit_ctl, cval);
1773 if (! kctl) { 1780 if (! kctl) {
1774 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1781 usb_audio_err(state->chip, "cannot malloc kcontrol\n");
1775 kfree(cval); 1782 kfree(cval);
1776 return -ENOMEM; 1783 return -ENOMEM;
1777 } 1784 }
@@ -1793,7 +1800,8 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, void *raw
1793 append_ctl_name(kctl, " "); 1800 append_ctl_name(kctl, " ");
1794 append_ctl_name(kctl, valinfo->suffix); 1801 append_ctl_name(kctl, valinfo->suffix);
1795 1802
1796 snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n", 1803 usb_audio_dbg(state->chip,
1804 "[%d] PU [%s] ch = %d, val = %d/%d\n",
1797 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1805 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
1798 if ((err = snd_usb_mixer_add_control(state->mixer, kctl)) < 0) 1806 if ((err = snd_usb_mixer_add_control(state->mixer, kctl)) < 0)
1799 return err; 1807 return err;
@@ -1918,7 +1926,8 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, void
1918 char **namelist; 1926 char **namelist;
1919 1927
1920 if (!desc->bNrInPins || desc->bLength < 5 + desc->bNrInPins) { 1928 if (!desc->bNrInPins || desc->bLength < 5 + desc->bNrInPins) {
1921 snd_printk(KERN_ERR "invalid SELECTOR UNIT descriptor %d\n", unitid); 1929 usb_audio_err(state->chip,
1930 "invalid SELECTOR UNIT descriptor %d\n", unitid);
1922 return -EINVAL; 1931 return -EINVAL;
1923 } 1932 }
1924 1933
@@ -1936,7 +1945,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, void
1936 1945
1937 cval = kzalloc(sizeof(*cval), GFP_KERNEL); 1946 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
1938 if (! cval) { 1947 if (! cval) {
1939 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1948 usb_audio_err(state->chip, "cannot malloc kcontrol\n");
1940 return -ENOMEM; 1949 return -ENOMEM;
1941 } 1950 }
1942 cval->mixer = state->mixer; 1951 cval->mixer = state->mixer;
@@ -1955,7 +1964,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, void
1955 1964
1956 namelist = kmalloc(sizeof(char *) * desc->bNrInPins, GFP_KERNEL); 1965 namelist = kmalloc(sizeof(char *) * desc->bNrInPins, GFP_KERNEL);
1957 if (! namelist) { 1966 if (! namelist) {
1958 snd_printk(KERN_ERR "cannot malloc\n"); 1967 usb_audio_err(state->chip, "cannot malloc\n");
1959 kfree(cval); 1968 kfree(cval);
1960 return -ENOMEM; 1969 return -ENOMEM;
1961 } 1970 }
@@ -1965,7 +1974,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, void
1965 len = 0; 1974 len = 0;
1966 namelist[i] = kmalloc(MAX_ITEM_NAME_LEN, GFP_KERNEL); 1975 namelist[i] = kmalloc(MAX_ITEM_NAME_LEN, GFP_KERNEL);
1967 if (! namelist[i]) { 1976 if (! namelist[i]) {
1968 snd_printk(KERN_ERR "cannot malloc\n"); 1977 usb_audio_err(state->chip, "cannot malloc\n");
1969 while (i--) 1978 while (i--)
1970 kfree(namelist[i]); 1979 kfree(namelist[i]);
1971 kfree(namelist); 1980 kfree(namelist);
@@ -1982,7 +1991,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, void
1982 1991
1983 kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval); 1992 kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval);
1984 if (! kctl) { 1993 if (! kctl) {
1985 snd_printk(KERN_ERR "cannot malloc kcontrol\n"); 1994 usb_audio_err(state->chip, "cannot malloc kcontrol\n");
1986 kfree(namelist); 1995 kfree(namelist);
1987 kfree(cval); 1996 kfree(cval);
1988 return -ENOMEM; 1997 return -ENOMEM;
@@ -2010,7 +2019,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, void
2010 append_ctl_name(kctl, " Playback Source"); 2019 append_ctl_name(kctl, " Playback Source");
2011 } 2020 }
2012 2021
2013 snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n", 2022 usb_audio_dbg(state->chip, "[%d] SU [%s] items = %d\n",
2014 cval->id, kctl->id.name, desc->bNrInPins); 2023 cval->id, kctl->id.name, desc->bNrInPins);
2015 if ((err = snd_usb_mixer_add_control(state->mixer, kctl)) < 0) 2024 if ((err = snd_usb_mixer_add_control(state->mixer, kctl)) < 0)
2016 return err; 2025 return err;
@@ -2032,7 +2041,7 @@ static int parse_audio_unit(struct mixer_build *state, int unitid)
2032 2041
2033 p1 = find_audio_control_unit(state, unitid); 2042 p1 = find_audio_control_unit(state, unitid);
2034 if (!p1) { 2043 if (!p1) {
2035 snd_printk(KERN_ERR "usbaudio: unit %d not found!\n", unitid); 2044 usb_audio_err(state->chip, "unit %d not found!\n", unitid);
2036 return -EINVAL; 2045 return -EINVAL;
2037 } 2046 }
2038 2047
@@ -2062,7 +2071,8 @@ static int parse_audio_unit(struct mixer_build *state, int unitid)
2062 case UAC2_EXTENSION_UNIT_V2: 2071 case UAC2_EXTENSION_UNIT_V2:
2063 return parse_audio_extension_unit(state, unitid, p1); 2072 return parse_audio_extension_unit(state, unitid, p1);
2064 default: 2073 default:
2065 snd_printk(KERN_ERR "usbaudio: unit %u: unexpected type 0x%02x\n", unitid, p1[2]); 2074 usb_audio_err(state->chip,
2075 "unit %u: unexpected type 0x%02x\n", unitid, p1[2]);
2066 return -EINVAL; 2076 return -EINVAL;
2067 } 2077 }
2068} 2078}
@@ -2210,8 +2220,9 @@ static void snd_usb_mixer_interrupt_v2(struct usb_mixer_interface *mixer,
2210 __u8 channel = value & 0xff; 2220 __u8 channel = value & 0xff;
2211 2221
2212 if (channel >= MAX_CHANNELS) { 2222 if (channel >= MAX_CHANNELS) {
2213 snd_printk(KERN_DEBUG "%s(): bogus channel number %d\n", 2223 usb_audio_dbg(mixer->chip,
2214 __func__, channel); 2224 "%s(): bogus channel number %d\n",
2225 __func__, channel);
2215 return; 2226 return;
2216 } 2227 }
2217 2228
@@ -2240,8 +2251,9 @@ static void snd_usb_mixer_interrupt_v2(struct usb_mixer_interface *mixer,
2240 break; 2251 break;
2241 2252
2242 default: 2253 default:
2243 snd_printk(KERN_DEBUG "unknown attribute %d in interrupt\n", 2254 usb_audio_dbg(mixer->chip,
2244 attribute); 2255 "unknown attribute %d in interrupt\n",
2256 attribute);
2245 break; 2257 break;
2246 } /* switch */ 2258 } /* switch */
2247 } 2259 }
@@ -2262,7 +2274,7 @@ static void snd_usb_mixer_interrupt(struct urb *urb)
2262 for (status = urb->transfer_buffer; 2274 for (status = urb->transfer_buffer;
2263 len >= sizeof(*status); 2275 len >= sizeof(*status);
2264 len -= sizeof(*status), status++) { 2276 len -= sizeof(*status), status++) {
2265 snd_printd(KERN_DEBUG "status interrupt: %02x %02x\n", 2277 dev_dbg(&urb->dev->dev, "status interrupt: %02x %02x\n",
2266 status->bStatusType, 2278 status->bStatusType,
2267 status->bOriginator); 2279 status->bOriginator);
2268 2280
@@ -2300,26 +2312,6 @@ requeue:
2300 } 2312 }
2301} 2313}
2302 2314
2303/* stop any bus activity of a mixer */
2304void snd_usb_mixer_inactivate(struct usb_mixer_interface *mixer)
2305{
2306 usb_kill_urb(mixer->urb);
2307 usb_kill_urb(mixer->rc_urb);
2308}
2309
2310int snd_usb_mixer_activate(struct usb_mixer_interface *mixer)
2311{
2312 int err;
2313
2314 if (mixer->urb) {
2315 err = usb_submit_urb(mixer->urb, GFP_NOIO);
2316 if (err < 0)
2317 return err;
2318 }
2319
2320 return 0;
2321}
2322
2323/* create the handler for the optional status interrupt endpoint */ 2315/* create the handler for the optional status interrupt endpoint */
2324static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer) 2316static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer)
2325{ 2317{
@@ -2394,7 +2386,7 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2394 2386
2395 snd_usb_mixer_apply_create_quirk(mixer); 2387 snd_usb_mixer_apply_create_quirk(mixer);
2396 2388
2397 err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops); 2389 err = snd_device_new(chip->card, SNDRV_DEV_CODEC, mixer, &dev_ops);
2398 if (err < 0) 2390 if (err < 0)
2399 goto _error; 2391 goto _error;
2400 2392
@@ -2418,3 +2410,82 @@ void snd_usb_mixer_disconnect(struct list_head *p)
2418 usb_kill_urb(mixer->urb); 2410 usb_kill_urb(mixer->urb);
2419 usb_kill_urb(mixer->rc_urb); 2411 usb_kill_urb(mixer->rc_urb);
2420} 2412}
2413
2414#ifdef CONFIG_PM
2415/* stop any bus activity of a mixer */
2416static void snd_usb_mixer_inactivate(struct usb_mixer_interface *mixer)
2417{
2418 usb_kill_urb(mixer->urb);
2419 usb_kill_urb(mixer->rc_urb);
2420}
2421
2422static int snd_usb_mixer_activate(struct usb_mixer_interface *mixer)
2423{
2424 int err;
2425
2426 if (mixer->urb) {
2427 err = usb_submit_urb(mixer->urb, GFP_NOIO);
2428 if (err < 0)
2429 return err;
2430 }
2431
2432 return 0;
2433}
2434
2435int snd_usb_mixer_suspend(struct usb_mixer_interface *mixer)
2436{
2437 snd_usb_mixer_inactivate(mixer);
2438 return 0;
2439}
2440
2441static int restore_mixer_value(struct usb_mixer_elem_info *cval)
2442{
2443 int c, err, idx;
2444
2445 if (cval->cmask) {
2446 idx = 0;
2447 for (c = 0; c < MAX_CHANNELS; c++) {
2448 if (!(cval->cmask & (1 << c)))
2449 continue;
2450 if (cval->cached & (1 << c)) {
2451 err = set_cur_mix_value(cval, c + 1, idx,
2452 cval->cache_val[idx]);
2453 if (err < 0)
2454 return err;
2455 }
2456 idx++;
2457 }
2458 } else {
2459 /* master */
2460 if (cval->cached) {
2461 err = set_cur_mix_value(cval, 0, 0, *cval->cache_val);
2462 if (err < 0)
2463 return err;
2464 }
2465 }
2466
2467 return 0;
2468}
2469
2470int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume)
2471{
2472 struct usb_mixer_elem_info *cval;
2473 int id, err;
2474
2475 /* FIXME: any mixer quirks? */
2476
2477 if (reset_resume) {
2478 /* restore cached mixer values */
2479 for (id = 0; id < MAX_ID_ELEMS; id++) {
2480 for (cval = mixer->id_elems[id]; cval;
2481 cval = cval->next_id_elem) {
2482 err = restore_mixer_value(cval);
2483 if (err < 0)
2484 return err;
2485 }
2486 }
2487 }
2488
2489 return snd_usb_mixer_activate(mixer);
2490}
2491#endif
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index aab80df201bd..73b1f649447b 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -63,8 +63,6 @@ void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid);
63 63
64int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval, 64int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
65 int request, int validx, int value_set); 65 int request, int validx, int value_set);
66void snd_usb_mixer_inactivate(struct usb_mixer_interface *mixer);
67int snd_usb_mixer_activate(struct usb_mixer_interface *mixer);
68 66
69int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer, 67int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer,
70 struct snd_kcontrol *kctl); 68 struct snd_kcontrol *kctl);
@@ -72,4 +70,9 @@ int snd_usb_mixer_add_control(struct usb_mixer_interface *mixer,
72int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, 70int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
73 unsigned int size, unsigned int __user *_tlv); 71 unsigned int size, unsigned int __user *_tlv);
74 72
73#ifdef CONFIG_PM
74int snd_usb_mixer_suspend(struct usb_mixer_interface *mixer);
75int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume);
76#endif
77
75#endif /* __USBMIXER_H */ 78#endif /* __USBMIXER_H */
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index f4b12c216f1c..f119a41ed9a9 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -600,8 +600,8 @@ static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
600 up_read(&mixer->chip->shutdown_rwsem); 600 up_read(&mixer->chip->shutdown_rwsem);
601 601
602 if (ret < 0) { 602 if (ret < 0) {
603 snd_printk(KERN_ERR 603 dev_err(&dev->dev,
604 "unable to issue vendor read request (ret = %d)", ret); 604 "unable to issue vendor read request (ret = %d)", ret);
605 return ret; 605 return ret;
606 } 606 }
607 607
@@ -631,8 +631,8 @@ static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol,
631 up_read(&mixer->chip->shutdown_rwsem); 631 up_read(&mixer->chip->shutdown_rwsem);
632 632
633 if (ret < 0) { 633 if (ret < 0) {
634 snd_printk(KERN_ERR 634 dev_err(&dev->dev,
635 "unable to issue vendor write request (ret = %d)", ret); 635 "unable to issue vendor write request (ret = %d)", ret);
636 return ret; 636 return ret;
637 } 637 }
638 638
@@ -1699,7 +1699,7 @@ void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
1699 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); 1699 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1700 break; 1700 break;
1701 default: 1701 default:
1702 snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid); 1702 usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid);
1703 break; 1703 break;
1704 } 1704 }
1705} 1705}
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index ca3256d6fde3..49de5c1284f6 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -166,8 +166,8 @@ static int init_pitch_v1(struct snd_usb_audio *chip, int iface,
166 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, 166 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
167 UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep, 167 UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep,
168 data, sizeof(data))) < 0) { 168 data, sizeof(data))) < 0) {
169 snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n", 169 usb_audio_err(chip, "%d:%d: cannot set enable PITCH\n",
170 dev->devnum, iface, ep); 170 iface, ep);
171 return err; 171 return err;
172 } 172 }
173 173
@@ -187,8 +187,8 @@ static int init_pitch_v2(struct snd_usb_audio *chip, int iface,
187 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, 187 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT,
188 UAC2_EP_CS_PITCH << 8, 0, 188 UAC2_EP_CS_PITCH << 8, 0,
189 data, sizeof(data))) < 0) { 189 data, sizeof(data))) < 0) {
190 snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH (v2)\n", 190 usb_audio_err(chip, "%d:%d: cannot set enable PITCH (v2)\n",
191 dev->devnum, iface, fmt->altsetting); 191 iface, fmt->altsetting);
192 return err; 192 return err;
193 } 193 }
194 194
@@ -226,7 +226,7 @@ static int start_endpoints(struct snd_usb_substream *subs, bool can_sleep)
226 if (!test_and_set_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) { 226 if (!test_and_set_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) {
227 struct snd_usb_endpoint *ep = subs->data_endpoint; 227 struct snd_usb_endpoint *ep = subs->data_endpoint;
228 228
229 snd_printdd(KERN_DEBUG "Starting data EP @%p\n", ep); 229 dev_dbg(&subs->dev->dev, "Starting data EP @%p\n", ep);
230 230
231 ep->data_subs = subs; 231 ep->data_subs = subs;
232 err = snd_usb_endpoint_start(ep, can_sleep); 232 err = snd_usb_endpoint_start(ep, can_sleep);
@@ -247,16 +247,15 @@ static int start_endpoints(struct snd_usb_substream *subs, bool can_sleep)
247 subs->sync_endpoint->altsetting); 247 subs->sync_endpoint->altsetting);
248 if (err < 0) { 248 if (err < 0) {
249 clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags); 249 clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags);
250 snd_printk(KERN_ERR 250 dev_err(&subs->dev->dev,
251 "%d:%d:%d: cannot set interface (%d)\n", 251 "%d:%d: cannot set interface (%d)\n",
252 subs->dev->devnum,
253 subs->sync_endpoint->iface, 252 subs->sync_endpoint->iface,
254 subs->sync_endpoint->altsetting, err); 253 subs->sync_endpoint->altsetting, err);
255 return -EIO; 254 return -EIO;
256 } 255 }
257 } 256 }
258 257
259 snd_printdd(KERN_DEBUG "Starting sync EP @%p\n", ep); 258 dev_dbg(&subs->dev->dev, "Starting sync EP @%p\n", ep);
260 259
261 ep->sync_slave = subs->data_endpoint; 260 ep->sync_slave = subs->data_endpoint;
262 err = snd_usb_endpoint_start(ep, can_sleep); 261 err = snd_usb_endpoint_start(ep, can_sleep);
@@ -410,8 +409,9 @@ static int set_sync_endpoint(struct snd_usb_substream *subs,
410 if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_ISOC || 409 if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_ISOC ||
411 (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && 410 (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
412 get_endpoint(alts, 1)->bSynchAddress != 0)) { 411 get_endpoint(alts, 1)->bSynchAddress != 0)) {
413 snd_printk(KERN_ERR "%d:%d:%d : invalid sync pipe. bmAttributes %02x, bLength %d, bSynchAddress %02x\n", 412 dev_err(&dev->dev,
414 dev->devnum, fmt->iface, fmt->altsetting, 413 "%d:%d : invalid sync pipe. bmAttributes %02x, bLength %d, bSynchAddress %02x\n",
414 fmt->iface, fmt->altsetting,
415 get_endpoint(alts, 1)->bmAttributes, 415 get_endpoint(alts, 1)->bmAttributes,
416 get_endpoint(alts, 1)->bLength, 416 get_endpoint(alts, 1)->bLength,
417 get_endpoint(alts, 1)->bSynchAddress); 417 get_endpoint(alts, 1)->bSynchAddress);
@@ -421,8 +421,9 @@ static int set_sync_endpoint(struct snd_usb_substream *subs,
421 if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE && 421 if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
422 ((is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress | USB_DIR_IN)) || 422 ((is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress | USB_DIR_IN)) ||
423 (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)))) { 423 (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)))) {
424 snd_printk(KERN_ERR "%d:%d:%d : invalid sync pipe. is_playback %d, ep %02x, bSynchAddress %02x\n", 424 dev_err(&dev->dev,
425 dev->devnum, fmt->iface, fmt->altsetting, 425 "%d:%d : invalid sync pipe. is_playback %d, ep %02x, bSynchAddress %02x\n",
426 fmt->iface, fmt->altsetting,
426 is_playback, ep, get_endpoint(alts, 0)->bSynchAddress); 427 is_playback, ep, get_endpoint(alts, 0)->bSynchAddress);
427 return -EINVAL; 428 return -EINVAL;
428 } 429 }
@@ -469,8 +470,9 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
469 if (subs->interface >= 0 && subs->interface != fmt->iface) { 470 if (subs->interface >= 0 && subs->interface != fmt->iface) {
470 err = usb_set_interface(subs->dev, subs->interface, 0); 471 err = usb_set_interface(subs->dev, subs->interface, 0);
471 if (err < 0) { 472 if (err < 0) {
472 snd_printk(KERN_ERR "%d:%d:%d: return to setting 0 failed (%d)\n", 473 dev_err(&dev->dev,
473 dev->devnum, fmt->iface, fmt->altsetting, err); 474 "%d:%d: return to setting 0 failed (%d)\n",
475 fmt->iface, fmt->altsetting, err);
474 return -EIO; 476 return -EIO;
475 } 477 }
476 subs->interface = -1; 478 subs->interface = -1;
@@ -482,12 +484,13 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
482 subs->altset_idx != fmt->altset_idx) { 484 subs->altset_idx != fmt->altset_idx) {
483 err = usb_set_interface(dev, fmt->iface, fmt->altsetting); 485 err = usb_set_interface(dev, fmt->iface, fmt->altsetting);
484 if (err < 0) { 486 if (err < 0) {
485 snd_printk(KERN_ERR "%d:%d:%d: usb_set_interface failed (%d)\n", 487 dev_err(&dev->dev,
486 dev->devnum, fmt->iface, fmt->altsetting, err); 488 "%d:%d: usb_set_interface failed (%d)\n",
489 fmt->iface, fmt->altsetting, err);
487 return -EIO; 490 return -EIO;
488 } 491 }
489 snd_printdd(KERN_INFO "setting usb interface %d:%d\n", 492 dev_dbg(&dev->dev, "setting usb interface %d:%d\n",
490 fmt->iface, fmt->altsetting); 493 fmt->iface, fmt->altsetting);
491 subs->interface = fmt->iface; 494 subs->interface = fmt->iface;
492 subs->altset_idx = fmt->altset_idx; 495 subs->altset_idx = fmt->altset_idx;
493 496
@@ -523,20 +526,23 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
523 * - Requested PCM format is not supported. 526 * - Requested PCM format is not supported.
524 * - Requested sample rate is not supported. 527 * - Requested sample rate is not supported.
525 */ 528 */
526static int match_endpoint_audioformats(struct audioformat *fp, 529static int match_endpoint_audioformats(struct snd_usb_substream *subs,
527 struct audioformat *match, int rate, 530 struct audioformat *fp,
528 snd_pcm_format_t pcm_format) 531 struct audioformat *match, int rate,
532 snd_pcm_format_t pcm_format)
529{ 533{
530 int i; 534 int i;
531 int score = 0; 535 int score = 0;
532 536
533 if (fp->channels < 1) { 537 if (fp->channels < 1) {
534 snd_printdd("%s: (fmt @%p) no channels\n", __func__, fp); 538 dev_dbg(&subs->dev->dev,
539 "%s: (fmt @%p) no channels\n", __func__, fp);
535 return 0; 540 return 0;
536 } 541 }
537 542
538 if (!(fp->formats & pcm_format_to_bits(pcm_format))) { 543 if (!(fp->formats & pcm_format_to_bits(pcm_format))) {
539 snd_printdd("%s: (fmt @%p) no match for format %d\n", __func__, 544 dev_dbg(&subs->dev->dev,
545 "%s: (fmt @%p) no match for format %d\n", __func__,
540 fp, pcm_format); 546 fp, pcm_format);
541 return 0; 547 return 0;
542 } 548 }
@@ -548,7 +554,8 @@ static int match_endpoint_audioformats(struct audioformat *fp,
548 } 554 }
549 } 555 }
550 if (!score) { 556 if (!score) {
551 snd_printdd("%s: (fmt @%p) no match for rate %d\n", __func__, 557 dev_dbg(&subs->dev->dev,
558 "%s: (fmt @%p) no match for rate %d\n", __func__,
552 fp, rate); 559 fp, rate);
553 return 0; 560 return 0;
554 } 561 }
@@ -556,7 +563,8 @@ static int match_endpoint_audioformats(struct audioformat *fp,
556 if (fp->channels == match->channels) 563 if (fp->channels == match->channels)
557 score++; 564 score++;
558 565
559 snd_printdd("%s: (fmt @%p) score %d\n", __func__, fp, score); 566 dev_dbg(&subs->dev->dev,
567 "%s: (fmt @%p) score %d\n", __func__, fp, score);
560 568
561 return score; 569 return score;
562} 570}
@@ -587,7 +595,8 @@ static int configure_sync_endpoint(struct snd_usb_substream *subs)
587 595
588 /* Try to find the best matching audioformat. */ 596 /* Try to find the best matching audioformat. */
589 list_for_each_entry(fp, &sync_subs->fmt_list, list) { 597 list_for_each_entry(fp, &sync_subs->fmt_list, list) {
590 int score = match_endpoint_audioformats(fp, subs->cur_audiofmt, 598 int score = match_endpoint_audioformats(subs,
599 fp, subs->cur_audiofmt,
591 subs->cur_rate, subs->pcm_format); 600 subs->cur_rate, subs->pcm_format);
592 601
593 if (score > cur_score) { 602 if (score > cur_score) {
@@ -597,7 +606,8 @@ static int configure_sync_endpoint(struct snd_usb_substream *subs)
597 } 606 }
598 607
599 if (unlikely(sync_fp == NULL)) { 608 if (unlikely(sync_fp == NULL)) {
600 snd_printk(KERN_ERR "%s: no valid audioformat for sync ep %x found\n", 609 dev_err(&subs->dev->dev,
610 "%s: no valid audioformat for sync ep %x found\n",
601 __func__, sync_subs->ep_num); 611 __func__, sync_subs->ep_num);
602 return -EINVAL; 612 return -EINVAL;
603 } 613 }
@@ -609,7 +619,8 @@ static int configure_sync_endpoint(struct snd_usb_substream *subs)
609 if (sync_fp->channels != subs->channels) { 619 if (sync_fp->channels != subs->channels) {
610 sync_period_bytes = (subs->period_bytes / subs->channels) * 620 sync_period_bytes = (subs->period_bytes / subs->channels) *
611 sync_fp->channels; 621 sync_fp->channels;
612 snd_printdd("%s: adjusted sync ep period bytes (%d -> %d)\n", 622 dev_dbg(&subs->dev->dev,
623 "%s: adjusted sync ep period bytes (%d -> %d)\n",
613 __func__, subs->period_bytes, sync_period_bytes); 624 __func__, subs->period_bytes, sync_period_bytes);
614 } 625 }
615 626
@@ -685,7 +696,8 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
685 696
686 fmt = find_format(subs); 697 fmt = find_format(subs);
687 if (!fmt) { 698 if (!fmt) {
688 snd_printd(KERN_DEBUG "cannot set format: format = %#x, rate = %d, channels = %d\n", 699 dev_dbg(&subs->dev->dev,
700 "cannot set format: format = %#x, rate = %d, channels = %d\n",
689 subs->pcm_format, subs->cur_rate, subs->channels); 701 subs->pcm_format, subs->cur_rate, subs->channels);
690 return -EINVAL; 702 return -EINVAL;
691 } 703 }
@@ -742,7 +754,7 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
742 int ret; 754 int ret;
743 755
744 if (! subs->cur_audiofmt) { 756 if (! subs->cur_audiofmt) {
745 snd_printk(KERN_ERR "usbaudio: no format is specified!\n"); 757 dev_err(&subs->dev->dev, "no format is specified!\n");
746 return -ENXIO; 758 return -ENXIO;
747 } 759 }
748 760
@@ -1235,7 +1247,8 @@ static void retire_capture_urb(struct snd_usb_substream *subs,
1235 for (i = 0; i < urb->number_of_packets; i++) { 1247 for (i = 0; i < urb->number_of_packets; i++) {
1236 cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset + subs->pkt_offset_adj; 1248 cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset + subs->pkt_offset_adj;
1237 if (urb->iso_frame_desc[i].status && printk_ratelimit()) { 1249 if (urb->iso_frame_desc[i].status && printk_ratelimit()) {
1238 snd_printdd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status); 1250 dev_dbg(&subs->dev->dev, "frame %d active: %d\n",
1251 i, urb->iso_frame_desc[i].status);
1239 // continue; 1252 // continue;
1240 } 1253 }
1241 bytes = urb->iso_frame_desc[i].actual_length; 1254 bytes = urb->iso_frame_desc[i].actual_length;
@@ -1245,7 +1258,8 @@ static void retire_capture_urb(struct snd_usb_substream *subs,
1245 if (bytes % (runtime->sample_bits >> 3) != 0) { 1258 if (bytes % (runtime->sample_bits >> 3) != 0) {
1246 int oldbytes = bytes; 1259 int oldbytes = bytes;
1247 bytes = frames * stride; 1260 bytes = frames * stride;
1248 snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n", 1261 dev_warn(&subs->dev->dev,
1262 "Corrected urb data len. %d->%d\n",
1249 oldbytes, bytes); 1263 oldbytes, bytes);
1250 } 1264 }
1251 /* update the current pointer */ 1265 /* update the current pointer */
@@ -1488,7 +1502,8 @@ static void retire_playback_urb(struct snd_usb_substream *subs,
1488 * on two reads of a counter updated every ms. 1502 * on two reads of a counter updated every ms.
1489 */ 1503 */
1490 if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2) 1504 if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
1491 snd_printk(KERN_DEBUG "delay: estimated %d, actual %d\n", 1505 dev_dbg(&subs->dev->dev,
1506 "delay: estimated %d, actual %d\n",
1492 est_delay, subs->last_delay); 1507 est_delay, subs->last_delay);
1493 1508
1494 if (!subs->running) { 1509 if (!subs->running) {
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 89730707614c..7c57f2268dd7 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -110,7 +110,7 @@ static int create_standard_audio_quirk(struct snd_usb_audio *chip,
110 altsd = get_iface_desc(alts); 110 altsd = get_iface_desc(alts);
111 err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber); 111 err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber);
112 if (err < 0) { 112 if (err < 0) {
113 snd_printk(KERN_ERR "cannot setup if %d: error %d\n", 113 usb_audio_err(chip, "cannot setup if %d: error %d\n",
114 altsd->bInterfaceNumber, err); 114 altsd->bInterfaceNumber, err);
115 return err; 115 return err;
116 } 116 }
@@ -135,7 +135,7 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
135 135
136 fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL); 136 fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
137 if (!fp) { 137 if (!fp) {
138 snd_printk(KERN_ERR "cannot memdup\n"); 138 usb_audio_err(chip, "cannot memdup\n");
139 return -ENOMEM; 139 return -ENOMEM;
140 } 140 }
141 if (fp->nr_rates > MAX_NR_RATES) { 141 if (fp->nr_rates > MAX_NR_RATES) {
@@ -464,7 +464,7 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
464 fp->rate_max = fp->rate_min = 96000; 464 fp->rate_max = fp->rate_min = 96000;
465 break; 465 break;
466 default: 466 default:
467 snd_printk(KERN_ERR "unknown sample rate\n"); 467 usb_audio_err(chip, "unknown sample rate\n");
468 kfree(fp); 468 kfree(fp);
469 return -ENXIO; 469 return -ENXIO;
470 } 470 }
@@ -536,7 +536,7 @@ int snd_usb_create_quirk(struct snd_usb_audio *chip,
536 if (quirk->type < QUIRK_TYPE_COUNT) { 536 if (quirk->type < QUIRK_TYPE_COUNT) {
537 return quirk_funcs[quirk->type](chip, iface, driver, quirk); 537 return quirk_funcs[quirk->type](chip, iface, driver, quirk);
538 } else { 538 } else {
539 snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); 539 usb_audio_err(chip, "invalid quirk type %d\n", quirk->type);
540 return -ENXIO; 540 return -ENXIO;
541 } 541 }
542} 542}
@@ -555,18 +555,21 @@ static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interfac
555 555
556 if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD || 556 if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
557 le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) { 557 le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
558 snd_printdd("sending Extigy boot sequence...\n"); 558 dev_dbg(&dev->dev, "sending Extigy boot sequence...\n");
559 /* Send message to force it to reconnect with full interface. */ 559 /* Send message to force it to reconnect with full interface. */
560 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0), 560 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
561 0x10, 0x43, 0x0001, 0x000a, NULL, 0); 561 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
562 if (err < 0) snd_printdd("error sending boot message: %d\n", err); 562 if (err < 0)
563 dev_dbg(&dev->dev, "error sending boot message: %d\n", err);
563 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, 564 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
564 &dev->descriptor, sizeof(dev->descriptor)); 565 &dev->descriptor, sizeof(dev->descriptor));
565 config = dev->actconfig; 566 config = dev->actconfig;
566 if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err); 567 if (err < 0)
568 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
567 err = usb_reset_configuration(dev); 569 err = usb_reset_configuration(dev);
568 if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err); 570 if (err < 0)
569 snd_printdd("extigy_boot: new boot length = %d\n", 571 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
572 dev_dbg(&dev->dev, "extigy_boot: new boot length = %d\n",
570 le16_to_cpu(get_cfg_desc(config)->wTotalLength)); 573 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
571 return -ENODEV; /* quit this anyway */ 574 return -ENODEV; /* quit this anyway */
572 } 575 }
@@ -594,7 +597,7 @@ static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
594 int err; 597 int err;
595 598
596 if (dev->actconfig->desc.bConfigurationValue == 1) { 599 if (dev->actconfig->desc.bConfigurationValue == 1) {
597 snd_printk(KERN_INFO "usb-audio: " 600 dev_info(&dev->dev,
598 "Fast Track Pro switching to config #2\n"); 601 "Fast Track Pro switching to config #2\n");
599 /* This function has to be available by the usb core module. 602 /* This function has to be available by the usb core module.
600 * if it is not avialable the boot quirk has to be left out 603 * if it is not avialable the boot quirk has to be left out
@@ -603,14 +606,15 @@ static int snd_usb_fasttrackpro_boot_quirk(struct usb_device *dev)
603 */ 606 */
604 err = usb_driver_set_configuration(dev, 2); 607 err = usb_driver_set_configuration(dev, 2);
605 if (err < 0) 608 if (err < 0)
606 snd_printdd("error usb_driver_set_configuration: %d\n", 609 dev_dbg(&dev->dev,
607 err); 610 "error usb_driver_set_configuration: %d\n",
611 err);
608 /* Always return an error, so that we stop creating a device 612 /* Always return an error, so that we stop creating a device
609 that will just be destroyed and recreated with a new 613 that will just be destroyed and recreated with a new
610 configuration */ 614 configuration */
611 return -ENODEV; 615 return -ENODEV;
612 } else 616 } else
613 snd_printk(KERN_INFO "usb-audio: Fast Track Pro config OK\n"); 617 dev_info(&dev->dev, "Fast Track Pro config OK\n");
614 618
615 return 0; 619 return 0;
616} 620}
@@ -779,11 +783,11 @@ static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
779 fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength); 783 fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength);
780 784
781 if (fwsize != MBOX2_FIRMWARE_SIZE) { 785 if (fwsize != MBOX2_FIRMWARE_SIZE) {
782 snd_printk(KERN_ERR "usb-audio: Invalid firmware size=%d.\n", fwsize); 786 dev_err(&dev->dev, "Invalid firmware size=%d.\n", fwsize);
783 return -ENODEV; 787 return -ENODEV;
784 } 788 }
785 789
786 snd_printd("usb-audio: Sending Digidesign Mbox 2 boot sequence...\n"); 790 dev_dbg(&dev->dev, "Sending Digidesign Mbox 2 boot sequence...\n");
787 791
788 count = 0; 792 count = 0;
789 bootresponse[0] = MBOX2_BOOT_LOADING; 793 bootresponse[0] = MBOX2_BOOT_LOADING;
@@ -794,32 +798,32 @@ static int snd_usb_mbox2_boot_quirk(struct usb_device *dev)
794 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012); 798 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012);
795 if (bootresponse[0] == MBOX2_BOOT_READY) 799 if (bootresponse[0] == MBOX2_BOOT_READY)
796 break; 800 break;
797 snd_printd("usb-audio: device not ready, resending boot sequence...\n"); 801 dev_dbg(&dev->dev, "device not ready, resending boot sequence...\n");
798 count++; 802 count++;
799 } 803 }
800 804
801 if (bootresponse[0] != MBOX2_BOOT_READY) { 805 if (bootresponse[0] != MBOX2_BOOT_READY) {
802 snd_printk(KERN_ERR "usb-audio: Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]); 806 dev_err(&dev->dev, "Unknown bootresponse=%d, or timed out, ignoring device.\n", bootresponse[0]);
803 return -ENODEV; 807 return -ENODEV;
804 } 808 }
805 809
806 snd_printdd("usb-audio: device initialised!\n"); 810 dev_dbg(&dev->dev, "device initialised!\n");
807 811
808 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, 812 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
809 &dev->descriptor, sizeof(dev->descriptor)); 813 &dev->descriptor, sizeof(dev->descriptor));
810 config = dev->actconfig; 814 config = dev->actconfig;
811 if (err < 0) 815 if (err < 0)
812 snd_printd("error usb_get_descriptor: %d\n", err); 816 dev_dbg(&dev->dev, "error usb_get_descriptor: %d\n", err);
813 817
814 err = usb_reset_configuration(dev); 818 err = usb_reset_configuration(dev);
815 if (err < 0) 819 if (err < 0)
816 snd_printd("error usb_reset_configuration: %d\n", err); 820 dev_dbg(&dev->dev, "error usb_reset_configuration: %d\n", err);
817 snd_printdd("mbox2_boot: new boot length = %d\n", 821 dev_dbg(&dev->dev, "mbox2_boot: new boot length = %d\n",
818 le16_to_cpu(get_cfg_desc(config)->wTotalLength)); 822 le16_to_cpu(get_cfg_desc(config)->wTotalLength));
819 823
820 mbox2_setup_48_24_magic(dev); 824 mbox2_setup_48_24_magic(dev);
821 825
822 snd_printk(KERN_INFO "usb-audio: Digidesign Mbox 2: 24bit 48kHz"); 826 dev_info(&dev->dev, "Digidesign Mbox 2: 24bit 48kHz");
823 827
824 return 0; /* Successful boot */ 828 return 0; /* Successful boot */
825} 829}
@@ -865,7 +869,7 @@ static int quattro_skip_setting_quirk(struct snd_usb_audio *chip,
865 return 1; /* skip this altsetting */ 869 return 1; /* skip this altsetting */
866 } 870 }
867 } 871 }
868 snd_printdd(KERN_INFO 872 usb_audio_dbg(chip,
869 "using altsetting %d for interface %d config %d\n", 873 "using altsetting %d for interface %d config %d\n",
870 altno, iface, chip->setup); 874 altno, iface, chip->setup);
871 return 0; /* keep this altsetting */ 875 return 0; /* keep this altsetting */
@@ -932,7 +936,7 @@ static int fasttrackpro_skip_setting_quirk(struct snd_usb_audio *chip,
932 return 1; 936 return 1;
933 } 937 }
934 938
935 snd_printdd(KERN_INFO 939 usb_audio_dbg(chip,
936 "using altsetting %d for interface %d config %d\n", 940 "using altsetting %d for interface %d config %d\n",
937 altno, iface, chip->setup); 941 altno, iface, chip->setup);
938 return 0; /* keep this altsetting */ 942 return 0; /* keep this altsetting */
diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index 2fb71be5e100..310a3822d2b7 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -411,10 +411,9 @@ static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
411 411
412 if (!csep || csep->bLength < 7 || 412 if (!csep || csep->bLength < 7 ||
413 csep->bDescriptorSubtype != UAC_EP_GENERAL) { 413 csep->bDescriptorSubtype != UAC_EP_GENERAL) {
414 snd_printk(KERN_WARNING "%d:%u:%d : no or invalid" 414 usb_audio_warn(chip,
415 " class specific endpoint descriptor\n", 415 "%u:%d : no or invalid class specific endpoint descriptor\n",
416 chip->dev->devnum, iface_no, 416 iface_no, altsd->bAlternateSetting);
417 altsd->bAlternateSetting);
418 return 0; 417 return 0;
419 } 418 }
420 419
@@ -533,8 +532,8 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
533 /* get audio formats */ 532 /* get audio formats */
534 switch (protocol) { 533 switch (protocol) {
535 default: 534 default:
536 snd_printdd(KERN_WARNING "%d:%u:%d: unknown interface protocol %#02x, assuming v1\n", 535 dev_dbg(&dev->dev, "%u:%d: unknown interface protocol %#02x, assuming v1\n",
537 dev->devnum, iface_no, altno, protocol); 536 iface_no, altno, protocol);
538 protocol = UAC_VERSION_1; 537 protocol = UAC_VERSION_1;
539 /* fall through */ 538 /* fall through */
540 539
@@ -544,14 +543,16 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
544 struct uac_input_terminal_descriptor *iterm; 543 struct uac_input_terminal_descriptor *iterm;
545 544
546 if (!as) { 545 if (!as) {
547 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n", 546 dev_err(&dev->dev,
548 dev->devnum, iface_no, altno); 547 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
548 iface_no, altno);
549 continue; 549 continue;
550 } 550 }
551 551
552 if (as->bLength < sizeof(*as)) { 552 if (as->bLength < sizeof(*as)) {
553 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n", 553 dev_err(&dev->dev,
554 dev->devnum, iface_no, altno); 554 "%u:%d : invalid UAC_AS_GENERAL desc\n",
555 iface_no, altno);
555 continue; 556 continue;
556 } 557 }
557 558
@@ -574,14 +575,16 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
574 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL); 575 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
575 576
576 if (!as) { 577 if (!as) {
577 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n", 578 dev_err(&dev->dev,
578 dev->devnum, iface_no, altno); 579 "%u:%d : UAC_AS_GENERAL descriptor not found\n",
580 iface_no, altno);
579 continue; 581 continue;
580 } 582 }
581 583
582 if (as->bLength < sizeof(*as)) { 584 if (as->bLength < sizeof(*as)) {
583 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n", 585 dev_err(&dev->dev,
584 dev->devnum, iface_no, altno); 586 "%u:%d : invalid UAC_AS_GENERAL desc\n",
587 iface_no, altno);
585 continue; 588 continue;
586 } 589 }
587 590
@@ -607,8 +610,9 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
607 break; 610 break;
608 } 611 }
609 612
610 snd_printk(KERN_ERR "%d:%u:%d : bogus bTerminalLink %d\n", 613 dev_err(&dev->dev,
611 dev->devnum, iface_no, altno, as->bTerminalLink); 614 "%u:%d : bogus bTerminalLink %d\n",
615 iface_no, altno, as->bTerminalLink);
612 continue; 616 continue;
613 } 617 }
614 } 618 }
@@ -616,14 +620,16 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
616 /* get format type */ 620 /* get format type */
617 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE); 621 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE);
618 if (!fmt) { 622 if (!fmt) {
619 snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n", 623 dev_err(&dev->dev,
620 dev->devnum, iface_no, altno); 624 "%u:%d : no UAC_FORMAT_TYPE desc\n",
625 iface_no, altno);
621 continue; 626 continue;
622 } 627 }
623 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) || 628 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) ||
624 ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) { 629 ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) {
625 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n", 630 dev_err(&dev->dev,
626 dev->devnum, iface_no, altno); 631 "%u:%d : invalid UAC_FORMAT_TYPE desc\n",
632 iface_no, altno);
627 continue; 633 continue;
628 } 634 }
629 635
@@ -644,7 +650,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
644 650
645 fp = kzalloc(sizeof(*fp), GFP_KERNEL); 651 fp = kzalloc(sizeof(*fp), GFP_KERNEL);
646 if (! fp) { 652 if (! fp) {
647 snd_printk(KERN_ERR "cannot malloc\n"); 653 dev_err(&dev->dev, "cannot malloc\n");
648 return -ENOMEM; 654 return -ENOMEM;
649 } 655 }
650 656
@@ -707,7 +713,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
707 chconfig = 0; 713 chconfig = 0;
708 fp->chmap = convert_chmap(fp->channels, chconfig, protocol); 714 fp->chmap = convert_chmap(fp->channels, chconfig, protocol);
709 715
710 snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint); 716 dev_dbg(&dev->dev, "%u:%d: add audio endpoint %#x\n", iface_no, altno, fp->endpoint);
711 err = snd_usb_add_audio_stream(chip, stream, fp); 717 err = snd_usb_add_audio_stream(chip, stream, fp);
712 if (err < 0) { 718 if (err < 0) {
713 kfree(fp->rate_table); 719 kfree(fp->rate_table);
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 5d2fe0530745..25c4c7e217de 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -60,6 +60,15 @@ struct snd_usb_audio {
60 struct usb_host_interface *ctrl_intf; /* the audio control interface */ 60 struct usb_host_interface *ctrl_intf; /* the audio control interface */
61}; 61};
62 62
63#define usb_audio_err(chip, fmt, args...) \
64 dev_err(&(chip)->dev->dev, fmt, ##args)
65#define usb_audio_warn(chip, fmt, args...) \
66 dev_warn(&(chip)->dev->dev, fmt, ##args)
67#define usb_audio_info(chip, fmt, args...) \
68 dev_info(&(chip)->dev->dev, fmt, ##args)
69#define usb_audio_dbg(chip, fmt, args...) \
70 dev_dbg(&(chip)->dev->dev, fmt, ##args)
71
63/* 72/*
64 * Information about devices with broken descriptors 73 * Information about devices with broken descriptors
65 */ 74 */
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index 999550bbad40..cf5dc33f4a6d 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -535,7 +535,9 @@ static void snd_us122l_free(struct snd_card *card)
535 snd_us122l_card_used[index] = 0; 535 snd_us122l_card_used[index] = 0;
536} 536}
537 537
538static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp) 538static int usx2y_create_card(struct usb_device *device,
539 struct usb_interface *intf,
540 struct snd_card **cardp)
539{ 541{
540 int dev; 542 int dev;
541 struct snd_card *card; 543 struct snd_card *card;
@@ -546,8 +548,8 @@ static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
546 break; 548 break;
547 if (dev >= SNDRV_CARDS) 549 if (dev >= SNDRV_CARDS)
548 return -ENODEV; 550 return -ENODEV;
549 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 551 err = snd_card_new(&intf->dev, index[dev], id[dev], THIS_MODULE,
550 sizeof(struct us122l), &card); 552 sizeof(struct us122l), &card);
551 if (err < 0) 553 if (err < 0)
552 return err; 554 return err;
553 snd_us122l_card_used[US122L(card)->card_index = dev] = 1; 555 snd_us122l_card_used[US122L(card)->card_index = dev] = 1;
@@ -578,11 +580,10 @@ static int us122l_usb_probe(struct usb_interface *intf,
578 struct snd_card *card; 580 struct snd_card *card;
579 int err; 581 int err;
580 582
581 err = usx2y_create_card(device, &card); 583 err = usx2y_create_card(device, intf, &card);
582 if (err < 0) 584 if (err < 0)
583 return err; 585 return err;
584 586
585 snd_card_set_dev(card, &intf->dev);
586 if (!us122l_create_card(card)) { 587 if (!us122l_create_card(card)) {
587 snd_card_free(card); 588 snd_card_free(card);
588 return -EINVAL; 589 return -EINVAL;
diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c
index 5a51b18c50fe..91e0e2a4808c 100644
--- a/sound/usb/usx2y/usbusx2y.c
+++ b/sound/usb/usx2y/usbusx2y.c
@@ -332,7 +332,9 @@ static struct usb_device_id snd_usX2Y_usb_id_table[] = {
332 { /* terminator */ } 332 { /* terminator */ }
333}; 333};
334 334
335static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp) 335static int usX2Y_create_card(struct usb_device *device,
336 struct usb_interface *intf,
337 struct snd_card **cardp)
336{ 338{
337 int dev; 339 int dev;
338 struct snd_card * card; 340 struct snd_card * card;
@@ -343,15 +345,15 @@ static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp)
343 break; 345 break;
344 if (dev >= SNDRV_CARDS) 346 if (dev >= SNDRV_CARDS)
345 return -ENODEV; 347 return -ENODEV;
346 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 348 err = snd_card_new(&intf->dev, index[dev], id[dev], THIS_MODULE,
347 sizeof(struct usX2Ydev), &card); 349 sizeof(struct usX2Ydev), &card);
348 if (err < 0) 350 if (err < 0)
349 return err; 351 return err;
350 snd_usX2Y_card_used[usX2Y(card)->card_index = dev] = 1; 352 snd_usX2Y_card_used[usX2Y(card)->card_index = dev] = 1;
351 card->private_free = snd_usX2Y_card_private_free; 353 card->private_free = snd_usX2Y_card_private_free;
352 usX2Y(card)->dev = device; 354 usX2Y(card)->dev = device;
353 init_waitqueue_head(&usX2Y(card)->prepare_wait_queue); 355 init_waitqueue_head(&usX2Y(card)->prepare_wait_queue);
354 mutex_init(&usX2Y(card)->prepare_mutex); 356 mutex_init(&usX2Y(card)->pcm_mutex);
355 INIT_LIST_HEAD(&usX2Y(card)->midi_list); 357 INIT_LIST_HEAD(&usX2Y(card)->midi_list);
356 strcpy(card->driver, "USB "NAME_ALLCAPS""); 358 strcpy(card->driver, "USB "NAME_ALLCAPS"");
357 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS""); 359 sprintf(card->shortname, "TASCAM "NAME_ALLCAPS"");
@@ -382,10 +384,9 @@ static int usX2Y_usb_probe(struct usb_device *device,
382 le16_to_cpu(device->descriptor.idProduct) != USB_ID_US428)) 384 le16_to_cpu(device->descriptor.idProduct) != USB_ID_US428))
383 return -EINVAL; 385 return -EINVAL;
384 386
385 err = usX2Y_create_card(device, &card); 387 err = usX2Y_create_card(device, intf, &card);
386 if (err < 0) 388 if (err < 0)
387 return err; 389 return err;
388 snd_card_set_dev(card, &intf->dev);
389 if ((err = usX2Y_hwdep_new(card, device)) < 0 || 390 if ((err = usX2Y_hwdep_new(card, device)) < 0 ||
390 (err = snd_card_register(card)) < 0) { 391 (err = snd_card_register(card)) < 0) {
391 snd_card_free(card); 392 snd_card_free(card);
diff --git a/sound/usb/usx2y/usbusx2y.h b/sound/usb/usx2y/usbusx2y.h
index e43c0a86441a..6ae6b0806938 100644
--- a/sound/usb/usx2y/usbusx2y.h
+++ b/sound/usb/usx2y/usbusx2y.h
@@ -36,7 +36,7 @@ struct usX2Ydev {
36 unsigned int rate, 36 unsigned int rate,
37 format; 37 format;
38 int chip_status; 38 int chip_status;
39 struct mutex prepare_mutex; 39 struct mutex pcm_mutex;
40 struct us428ctls_sharedmem *us428ctls_sharedmem; 40 struct us428ctls_sharedmem *us428ctls_sharedmem;
41 int wait_iso_frame; 41 int wait_iso_frame;
42 wait_queue_head_t us428ctls_wait_queue_head; 42 wait_queue_head_t us428ctls_wait_queue_head;
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index 6234a51625b1..a63330dd1407 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -752,36 +752,44 @@ static int snd_usX2Y_pcm_hw_params(struct snd_pcm_substream *substream,
752 unsigned int rate = params_rate(hw_params); 752 unsigned int rate = params_rate(hw_params);
753 snd_pcm_format_t format = params_format(hw_params); 753 snd_pcm_format_t format = params_format(hw_params);
754 struct snd_card *card = substream->pstr->pcm->card; 754 struct snd_card *card = substream->pstr->pcm->card;
755 struct list_head *list; 755 struct usX2Ydev *dev = usX2Y(card);
756 int i;
756 757
758 mutex_lock(&usX2Y(card)->pcm_mutex);
757 snd_printdd("snd_usX2Y_hw_params(%p, %p)\n", substream, hw_params); 759 snd_printdd("snd_usX2Y_hw_params(%p, %p)\n", substream, hw_params);
758 // all pcm substreams off one usX2Y have to operate at the same rate & format 760 /* all pcm substreams off one usX2Y have to operate at the same
759 list_for_each(list, &card->devices) { 761 * rate & format
760 struct snd_device *dev; 762 */
761 struct snd_pcm *pcm; 763 for (i = 0; i < dev->pcm_devs * 2; i++) {
762 int s; 764 struct snd_usX2Y_substream *subs = dev->subs[i];
763 dev = snd_device(list); 765 struct snd_pcm_substream *test_substream;
764 if (dev->type != SNDRV_DEV_PCM) 766
767 if (!subs)
768 continue;
769 test_substream = subs->pcm_substream;
770 if (!test_substream || test_substream == substream ||
771 !test_substream->runtime)
765 continue; 772 continue;
766 pcm = dev->device_data; 773 if ((test_substream->runtime->format &&
767 for (s = 0; s < 2; ++s) { 774 test_substream->runtime->format != format) ||
768 struct snd_pcm_substream *test_substream; 775 (test_substream->runtime->rate &&
769 test_substream = pcm->streams[s].substream; 776 test_substream->runtime->rate != rate)) {
770 if (test_substream && test_substream != substream && 777 err = -EINVAL;
771 test_substream->runtime && 778 goto error;
772 ((test_substream->runtime->format &&
773 test_substream->runtime->format != format) ||
774 (test_substream->runtime->rate &&
775 test_substream->runtime->rate != rate)))
776 return -EINVAL;
777 } 779 }
778 } 780 }
779 if (0 > (err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)))) { 781
782 err = snd_pcm_lib_malloc_pages(substream,
783 params_buffer_bytes(hw_params));
784 if (err < 0) {
780 snd_printk(KERN_ERR "snd_pcm_lib_malloc_pages(%p, %i) returned %i\n", 785 snd_printk(KERN_ERR "snd_pcm_lib_malloc_pages(%p, %i) returned %i\n",
781 substream, params_buffer_bytes(hw_params), err); 786 substream, params_buffer_bytes(hw_params), err);
782 return err; 787 goto error;
783 } 788 }
784 return 0; 789
790 error:
791 mutex_unlock(&usX2Y(card)->pcm_mutex);
792 return err;
785} 793}
786 794
787/* 795/*
@@ -791,7 +799,7 @@ static int snd_usX2Y_pcm_hw_free(struct snd_pcm_substream *substream)
791{ 799{
792 struct snd_pcm_runtime *runtime = substream->runtime; 800 struct snd_pcm_runtime *runtime = substream->runtime;
793 struct snd_usX2Y_substream *subs = runtime->private_data; 801 struct snd_usX2Y_substream *subs = runtime->private_data;
794 mutex_lock(&subs->usX2Y->prepare_mutex); 802 mutex_lock(&subs->usX2Y->pcm_mutex);
795 snd_printdd("snd_usX2Y_hw_free(%p)\n", substream); 803 snd_printdd("snd_usX2Y_hw_free(%p)\n", substream);
796 804
797 if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) { 805 if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) {
@@ -812,7 +820,7 @@ static int snd_usX2Y_pcm_hw_free(struct snd_pcm_substream *substream)
812 usX2Y_urbs_release(subs); 820 usX2Y_urbs_release(subs);
813 } 821 }
814 } 822 }
815 mutex_unlock(&subs->usX2Y->prepare_mutex); 823 mutex_unlock(&subs->usX2Y->pcm_mutex);
816 return snd_pcm_lib_free_pages(substream); 824 return snd_pcm_lib_free_pages(substream);
817} 825}
818/* 826/*
@@ -829,7 +837,7 @@ static int snd_usX2Y_pcm_prepare(struct snd_pcm_substream *substream)
829 int err = 0; 837 int err = 0;
830 snd_printdd("snd_usX2Y_pcm_prepare(%p)\n", substream); 838 snd_printdd("snd_usX2Y_pcm_prepare(%p)\n", substream);
831 839
832 mutex_lock(&usX2Y->prepare_mutex); 840 mutex_lock(&usX2Y->pcm_mutex);
833 usX2Y_subs_prepare(subs); 841 usX2Y_subs_prepare(subs);
834// Start hardware streams 842// Start hardware streams
835// SyncStream first.... 843// SyncStream first....
@@ -849,7 +857,7 @@ static int snd_usX2Y_pcm_prepare(struct snd_pcm_substream *substream)
849 err = usX2Y_urbs_start(subs); 857 err = usX2Y_urbs_start(subs);
850 858
851 up_prepare_mutex: 859 up_prepare_mutex:
852 mutex_unlock(&usX2Y->prepare_mutex); 860 mutex_unlock(&usX2Y->pcm_mutex);
853 return err; 861 return err;
854} 862}
855 863
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.c b/sound/usb/usx2y/usx2yhwdeppcm.c
index 814d0e887c62..90766a92e7fd 100644
--- a/sound/usb/usx2y/usx2yhwdeppcm.c
+++ b/sound/usb/usx2y/usx2yhwdeppcm.c
@@ -358,7 +358,7 @@ static int snd_usX2Y_usbpcm_hw_free(struct snd_pcm_substream *substream)
358 struct snd_pcm_runtime *runtime = substream->runtime; 358 struct snd_pcm_runtime *runtime = substream->runtime;
359 struct snd_usX2Y_substream *subs = runtime->private_data, 359 struct snd_usX2Y_substream *subs = runtime->private_data,
360 *cap_subs2 = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2]; 360 *cap_subs2 = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2];
361 mutex_lock(&subs->usX2Y->prepare_mutex); 361 mutex_lock(&subs->usX2Y->pcm_mutex);
362 snd_printdd("snd_usX2Y_usbpcm_hw_free(%p)\n", substream); 362 snd_printdd("snd_usX2Y_usbpcm_hw_free(%p)\n", substream);
363 363
364 if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) { 364 if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) {
@@ -387,7 +387,7 @@ static int snd_usX2Y_usbpcm_hw_free(struct snd_pcm_substream *substream)
387 usX2Y_usbpcm_urbs_release(cap_subs2); 387 usX2Y_usbpcm_urbs_release(cap_subs2);
388 } 388 }
389 } 389 }
390 mutex_unlock(&subs->usX2Y->prepare_mutex); 390 mutex_unlock(&subs->usX2Y->pcm_mutex);
391 return snd_pcm_lib_free_pages(substream); 391 return snd_pcm_lib_free_pages(substream);
392} 392}
393 393
@@ -493,7 +493,7 @@ static int snd_usX2Y_usbpcm_prepare(struct snd_pcm_substream *substream)
493 memset(usX2Y->hwdep_pcm_shm, 0, sizeof(struct snd_usX2Y_hwdep_pcm_shm)); 493 memset(usX2Y->hwdep_pcm_shm, 0, sizeof(struct snd_usX2Y_hwdep_pcm_shm));
494 } 494 }
495 495
496 mutex_lock(&usX2Y->prepare_mutex); 496 mutex_lock(&usX2Y->pcm_mutex);
497 usX2Y_subs_prepare(subs); 497 usX2Y_subs_prepare(subs);
498// Start hardware streams 498// Start hardware streams
499// SyncStream first.... 499// SyncStream first....
@@ -534,7 +534,7 @@ static int snd_usX2Y_usbpcm_prepare(struct snd_pcm_substream *substream)
534 usX2Y->hwdep_pcm_shm->capture_iso_start = -1; 534 usX2Y->hwdep_pcm_shm->capture_iso_start = -1;
535 535
536 up_prepare_mutex: 536 up_prepare_mutex:
537 mutex_unlock(&usX2Y->prepare_mutex); 537 mutex_unlock(&usX2Y->pcm_mutex);
538 return err; 538 return err;
539} 539}
540 540
@@ -600,59 +600,30 @@ static struct snd_pcm_ops snd_usX2Y_usbpcm_ops =
600}; 600};
601 601
602 602
603static int usX2Y_pcms_lock_check(struct snd_card *card) 603static int usX2Y_pcms_busy_check(struct snd_card *card)
604{ 604{
605 struct list_head *list; 605 struct usX2Ydev *dev = usX2Y(card);
606 struct snd_device *dev; 606 int i;
607 struct snd_pcm *pcm;
608 int err = 0;
609 list_for_each(list, &card->devices) {
610 dev = snd_device(list);
611 if (dev->type != SNDRV_DEV_PCM)
612 continue;
613 pcm = dev->device_data;
614 mutex_lock(&pcm->open_mutex);
615 }
616 list_for_each(list, &card->devices) {
617 int s;
618 dev = snd_device(list);
619 if (dev->type != SNDRV_DEV_PCM)
620 continue;
621 pcm = dev->device_data;
622 for (s = 0; s < 2; ++s) {
623 struct snd_pcm_substream *substream;
624 substream = pcm->streams[s].substream;
625 if (substream && SUBSTREAM_BUSY(substream))
626 err = -EBUSY;
627 }
628 }
629 return err;
630}
631
632 607
633static void usX2Y_pcms_unlock(struct snd_card *card) 608 for (i = 0; i < dev->pcm_devs * 2; i++) {
634{ 609 struct snd_usX2Y_substream *subs = dev->subs[i];
635 struct list_head *list; 610 if (subs && subs->pcm_substream &&
636 struct snd_device *dev; 611 SUBSTREAM_BUSY(subs->pcm_substream))
637 struct snd_pcm *pcm; 612 return -EBUSY;
638 list_for_each(list, &card->devices) {
639 dev = snd_device(list);
640 if (dev->type != SNDRV_DEV_PCM)
641 continue;
642 pcm = dev->device_data;
643 mutex_unlock(&pcm->open_mutex);
644 } 613 }
614 return 0;
645} 615}
646 616
647
648static int snd_usX2Y_hwdep_pcm_open(struct snd_hwdep *hw, struct file *file) 617static int snd_usX2Y_hwdep_pcm_open(struct snd_hwdep *hw, struct file *file)
649{ 618{
650 // we need to be the first
651 struct snd_card *card = hw->card; 619 struct snd_card *card = hw->card;
652 int err = usX2Y_pcms_lock_check(card); 620 int err;
653 if (0 == err) 621
622 mutex_lock(&usX2Y(card)->pcm_mutex);
623 err = usX2Y_pcms_busy_check(card);
624 if (!err)
654 usX2Y(card)->chip_status |= USX2Y_STAT_CHIP_MMAP_PCM_URBS; 625 usX2Y(card)->chip_status |= USX2Y_STAT_CHIP_MMAP_PCM_URBS;
655 usX2Y_pcms_unlock(card); 626 mutex_unlock(&usX2Y(card)->pcm_mutex);
656 return err; 627 return err;
657} 628}
658 629
@@ -660,10 +631,13 @@ static int snd_usX2Y_hwdep_pcm_open(struct snd_hwdep *hw, struct file *file)
660static int snd_usX2Y_hwdep_pcm_release(struct snd_hwdep *hw, struct file *file) 631static int snd_usX2Y_hwdep_pcm_release(struct snd_hwdep *hw, struct file *file)
661{ 632{
662 struct snd_card *card = hw->card; 633 struct snd_card *card = hw->card;
663 int err = usX2Y_pcms_lock_check(card); 634 int err;
664 if (0 == err) 635
636 mutex_lock(&usX2Y(card)->pcm_mutex);
637 err = usX2Y_pcms_busy_check(card);
638 if (!err)
665 usX2Y(hw->card)->chip_status &= ~USX2Y_STAT_CHIP_MMAP_PCM_URBS; 639 usX2Y(hw->card)->chip_status &= ~USX2Y_STAT_CHIP_MMAP_PCM_URBS;
666 usX2Y_pcms_unlock(card); 640 mutex_unlock(&usX2Y(card)->pcm_mutex);
667 return err; 641 return err;
668} 642}
669 643
diff --git a/tools/net/Makefile b/tools/net/Makefile
index 004cd74734b6..ee577ea03ba5 100644
--- a/tools/net/Makefile
+++ b/tools/net/Makefile
@@ -12,7 +12,7 @@ YACC = bison
12 12
13all : bpf_jit_disasm bpf_dbg bpf_asm 13all : bpf_jit_disasm bpf_dbg bpf_asm
14 14
15bpf_jit_disasm : CFLAGS = -Wall -O2 15bpf_jit_disasm : CFLAGS = -Wall -O2 -DPACKAGE='bpf_jit_disasm'
16bpf_jit_disasm : LDLIBS = -lopcodes -lbfd -ldl 16bpf_jit_disasm : LDLIBS = -lopcodes -lbfd -ldl
17bpf_jit_disasm : bpf_jit_disasm.o 17bpf_jit_disasm : bpf_jit_disasm.o
18 18
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 6aa6fb6f7bd9..f954c26de231 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -825,7 +825,6 @@ static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscal
825 P_SIGNUM(PIPE); 825 P_SIGNUM(PIPE);
826 P_SIGNUM(ALRM); 826 P_SIGNUM(ALRM);
827 P_SIGNUM(TERM); 827 P_SIGNUM(TERM);
828 P_SIGNUM(STKFLT);
829 P_SIGNUM(CHLD); 828 P_SIGNUM(CHLD);
830 P_SIGNUM(CONT); 829 P_SIGNUM(CONT);
831 P_SIGNUM(STOP); 830 P_SIGNUM(STOP);
@@ -841,6 +840,15 @@ static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscal
841 P_SIGNUM(IO); 840 P_SIGNUM(IO);
842 P_SIGNUM(PWR); 841 P_SIGNUM(PWR);
843 P_SIGNUM(SYS); 842 P_SIGNUM(SYS);
843#ifdef SIGEMT
844 P_SIGNUM(EMT);
845#endif
846#ifdef SIGSTKFLT
847 P_SIGNUM(STKFLT);
848#endif
849#ifdef SIGSWI
850 P_SIGNUM(SWI);
851#endif
844 default: break; 852 default: break;
845 } 853 }
846 854
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index c872991e0f65..620a1983b76b 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1213,7 +1213,7 @@ static void ip__resolve_ams(struct machine *machine, struct thread *thread,
1213 */ 1213 */
1214 thread__find_addr_location(thread, machine, m, MAP__FUNCTION, 1214 thread__find_addr_location(thread, machine, m, MAP__FUNCTION,
1215 ip, &al); 1215 ip, &al);
1216 if (al.sym) 1216 if (al.map)
1217 goto found; 1217 goto found;
1218 } 1218 }
1219found: 1219found:
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 3e9f336740fa..516d19fb999b 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -151,15 +151,15 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
151 151
152 gelf_getshdr(sec, shp); 152 gelf_getshdr(sec, shp);
153 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name); 153 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
154 if (!strcmp(name, str)) { 154 if (str && !strcmp(name, str)) {
155 if (idx) 155 if (idx)
156 *idx = cnt; 156 *idx = cnt;
157 break; 157 return sec;
158 } 158 }
159 ++cnt; 159 ++cnt;
160 } 160 }
161 161
162 return sec; 162 return NULL;
163} 163}
164 164
165#define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \ 165#define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \
diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
index d66418237d21..aa290c0de6f5 100644
--- a/tools/testing/selftests/ipc/msgque.c
+++ b/tools/testing/selftests/ipc/msgque.c
@@ -201,6 +201,7 @@ int main(int argc, char **argv)
201 201
202 msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666); 202 msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666);
203 if (msgque.msq_id == -1) { 203 if (msgque.msq_id == -1) {
204 err = -errno;
204 printf("Can't create queue\n"); 205 printf("Can't create queue\n");
205 goto err_out; 206 goto err_out;
206 } 207 }