aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CREDITS8
-rw-r--r--Documentation/filesystems/proc.txt38
-rw-r--r--Documentation/sound/alsa/ALSA-Configuration.txt47
-rw-r--r--MAINTAINERS6
-rw-r--r--Makefile2
-rw-r--r--arch/alpha/kernel/osf_sys.c1
-rw-r--r--arch/alpha/kernel/pci.c22
-rw-r--r--arch/alpha/kernel/sys_nautilus.c2
-rw-r--r--arch/arm/mach-lh7a40x/arch-kev7a400.c5
-rw-r--r--arch/arm/mm/Kconfig6
-rw-r--r--arch/arm/mm/proc-arm1020.S2
-rw-r--r--arch/arm/mm/proc-arm1020e.S2
-rw-r--r--arch/arm/mm/proc-arm1022.S2
-rw-r--r--arch/arm/mm/proc-arm1026.S2
-rw-r--r--arch/arm/mm/proc-arm6_7.S4
-rw-r--r--arch/arm/mm/proc-arm720.S2
-rw-r--r--arch/arm/mm/proc-arm740.S1
-rw-r--r--arch/arm/mm/proc-arm7tdmi.S1
-rw-r--r--arch/arm/mm/proc-arm920.S2
-rw-r--r--arch/arm/mm/proc-arm922.S2
-rw-r--r--arch/arm/mm/proc-arm925.S2
-rw-r--r--arch/arm/mm/proc-arm926.S2
-rw-r--r--arch/arm/mm/proc-arm940.S1
-rw-r--r--arch/arm/mm/proc-arm946.S1
-rw-r--r--arch/arm/mm/proc-arm9tdmi.S1
-rw-r--r--arch/arm/mm/proc-feroceon.S2
-rw-r--r--arch/arm/mm/proc-sa110.S2
-rw-r--r--arch/arm/mm/proc-sa1100.S2
-rw-r--r--arch/arm/mm/proc-v6.S2
-rw-r--r--arch/arm/mm/proc-v7.S2
-rw-r--r--arch/arm/mm/proc-xsc3.S1
-rw-r--r--arch/arm/mm/proc-xscale.S2
-rw-r--r--arch/ia64/Kconfig11
-rw-r--r--arch/ia64/kernel/crash.c4
-rw-r--r--arch/ia64/kernel/entry.S1
-rw-r--r--arch/ia64/kernel/mca.c77
-rw-r--r--arch/ia64/kernel/perfmon.c4
-rw-r--r--arch/ia64/sn/kernel/Makefile7
-rw-r--r--arch/ia64/sn/kernel/huberror.c4
-rw-r--r--arch/ia64/sn/pci/tioce_provider.c6
-rw-r--r--arch/sparc/kernel/entry.S1
-rw-r--r--arch/sparc/kernel/signal.c5
-rw-r--r--arch/sparc64/Kconfig20
-rw-r--r--arch/sparc64/defconfig99
-rw-r--r--arch/sparc64/kernel/ebus.c1
-rw-r--r--arch/sparc64/kernel/entry.S37
-rw-r--r--arch/sparc64/kernel/entry.h1
-rw-r--r--arch/sparc64/kernel/etrap.S4
-rw-r--r--arch/sparc64/kernel/iommu.c33
-rw-r--r--arch/sparc64/kernel/isa.c1
-rw-r--r--arch/sparc64/kernel/mdesc.c28
-rw-r--r--arch/sparc64/kernel/of_device.c12
-rw-r--r--arch/sparc64/kernel/pci.c12
-rw-r--r--arch/sparc64/kernel/pci_fire.c5
-rw-r--r--arch/sparc64/kernel/pci_impl.h4
-rw-r--r--arch/sparc64/kernel/pci_msi.c8
-rw-r--r--arch/sparc64/kernel/pci_psycho.c5
-rw-r--r--arch/sparc64/kernel/pci_sabre.c4
-rw-r--r--arch/sparc64/kernel/pci_schizo.c5
-rw-r--r--arch/sparc64/kernel/pci_sun4v.c13
-rw-r--r--arch/sparc64/kernel/prom.c14
-rw-r--r--arch/sparc64/kernel/rtrap.S21
-rw-r--r--arch/sparc64/kernel/sbus.c3
-rw-r--r--arch/sparc64/kernel/setup.c3
-rw-r--r--arch/sparc64/kernel/signal.c25
-rw-r--r--arch/sparc64/kernel/signal32.c20
-rw-r--r--arch/sparc64/kernel/smp.c11
-rw-r--r--arch/sparc64/kernel/sparc64_ksyms.c2
-rw-r--r--arch/sparc64/kernel/stacktrace.c16
-rw-r--r--arch/sparc64/kernel/sun4v_tlb_miss.S16
-rw-r--r--arch/sparc64/kernel/sysfs.c12
-rw-r--r--arch/sparc64/kernel/traps.c19
-rw-r--r--arch/sparc64/kernel/tsb.S2
-rw-r--r--arch/sparc64/kernel/winfixup.S12
-rw-r--r--arch/sparc64/mm/init.c989
-rw-r--r--arch/sparc64/mm/tsb.c3
-rw-r--r--arch/sparc64/mm/ultra.S4
-rw-r--r--drivers/base/bus.c3
-rw-r--r--drivers/base/power/main.c15
-rw-r--r--drivers/block/brd.c2
-rw-r--r--drivers/hid/hid-core.c19
-rw-r--r--drivers/hid/hid-debug.c2
-rw-r--r--drivers/hid/hid-input-quirks.c24
-rw-r--r--drivers/hid/usbhid/Kconfig12
-rw-r--r--drivers/hid/usbhid/Makefile3
-rw-r--r--drivers/hid/usbhid/hid-core.c69
-rw-r--r--drivers/hid/usbhid/hid-ff.c3
-rw-r--r--drivers/hid/usbhid/hid-lg2ff.c114
-rw-r--r--drivers/hid/usbhid/hid-quirks.c85
-rw-r--r--drivers/hid/usbhid/hiddev.c286
-rw-r--r--drivers/hid/usbhid/usbhid.h3
-rw-r--r--drivers/i2c/algos/Kconfig39
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c126
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.h26
-rw-r--r--drivers/i2c/busses/Kconfig73
-rw-r--r--drivers/i2c/busses/Makefile3
-rw-r--r--drivers/i2c/busses/i2c-at91.c2
-rw-r--r--drivers/i2c/busses/i2c-au1550.c1
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c475
-rw-r--r--drivers/i2c/busses/i2c-davinci.c9
-rw-r--r--drivers/i2c/busses/i2c-gpio.c1
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c197
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c1
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c1
-rw-r--r--drivers/i2c/busses/i2c-mpc.c3
-rw-r--r--drivers/i2c/busses/i2c-ocores.c3
-rw-r--r--drivers/i2c/busses/i2c-omap.c1
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c53
-rw-r--r--drivers/i2c/busses/i2c-pca-platform.c298
-rw-r--r--drivers/i2c/busses/i2c-pmcmsp.c7
-rw-r--r--drivers/i2c/busses/i2c-pnx.c45
-rw-r--r--drivers/i2c/busses/i2c-powermac.c3
-rw-r--r--drivers/i2c/busses/i2c-pxa.c3
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c5
-rw-r--r--drivers/i2c/busses/i2c-sh7760.c577
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c500
-rw-r--r--drivers/i2c/busses/i2c-simtec.c3
-rw-r--r--drivers/i2c/busses/i2c-versatile.c1
-rw-r--r--drivers/i2c/busses/scx200_acb.c2
-rw-r--r--drivers/i2c/chips/isp1301_omap.c28
-rw-r--r--drivers/i2c/i2c-core.c2
-rw-r--r--drivers/i2c/i2c-dev.c329
-rw-r--r--drivers/input/misc/Kconfig1
-rw-r--r--drivers/leds/Kconfig1
-rw-r--r--drivers/media/video/cx88/cx88-alsa.c4
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c4
-rw-r--r--drivers/mfd/htc-pasic3.c3
-rw-r--r--drivers/misc/Kconfig12
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/sgi-xp/Makefile11
-rw-r--r--drivers/misc/sgi-xp/xp.h (renamed from include/asm-ia64/sn/xp.h)94
-rw-r--r--drivers/misc/sgi-xp/xp_main.c (renamed from arch/ia64/sn/kernel/xp_main.c)141
-rw-r--r--drivers/misc/sgi-xp/xp_nofault.S (renamed from arch/ia64/sn/kernel/xp_nofault.S)3
-rw-r--r--drivers/misc/sgi-xp/xpc.h (renamed from include/asm-ia64/sn/xpc.h)500
-rw-r--r--drivers/misc/sgi-xp/xpc_channel.c (renamed from arch/ia64/sn/kernel/xpc_channel.c)528
-rw-r--r--drivers/misc/sgi-xp/xpc_main.c (renamed from arch/ia64/sn/kernel/xpc_main.c)432
-rw-r--r--drivers/misc/sgi-xp/xpc_partition.c (renamed from arch/ia64/sn/kernel/xpc_partition.c)409
-rw-r--r--drivers/misc/sgi-xp/xpnet.c (renamed from arch/ia64/sn/kernel/xpnet.c)139
-rw-r--r--drivers/net/hamradio/dmascc.c3
-rw-r--r--drivers/net/ppp_generic.c48
-rw-r--r--drivers/net/tun.c21
-rw-r--r--drivers/net/wireless/Makefile3
-rw-r--r--drivers/net/wireless/ath5k/hw.c14
-rw-r--r--drivers/net/wireless/b43/dma.c47
-rw-r--r--drivers/net/wireless/b43/main.c32
-rw-r--r--drivers/net/wireless/b43/phy.c2
-rw-r--r--drivers/net/wireless/iwlwifi/Kconfig8
-rw-r--r--drivers/net/wireless/iwlwifi/Makefile2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl4965-base.c1
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.c2
-rw-r--r--drivers/net/wireless/rndis_wlan.c5
-rw-r--r--drivers/net/wireless/rt2x00/Kconfig15
-rw-r--r--drivers/pci/setup-bus.c30
-rw-r--r--drivers/pcmcia/Kconfig2
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c10
-rw-r--r--drivers/serial/sunzilog.c30
-rw-r--r--drivers/ssb/pci.c5
-rw-r--r--fs/Kconfig1
-rw-r--r--fs/dcache.c114
-rw-r--r--fs/dlm/Makefile1
-rw-r--r--fs/dlm/config.c50
-rw-r--r--fs/dlm/config.h3
-rw-r--r--fs/dlm/dlm_internal.h8
-rw-r--r--fs/dlm/lock.c5
-rw-r--r--fs/dlm/lock.h1
-rw-r--r--fs/dlm/main.c7
-rw-r--r--fs/dlm/member.c34
-rw-r--r--fs/dlm/plock.c (renamed from fs/gfs2/locking/dlm/plock.c)169
-rw-r--r--fs/dlm/recoverd.c1
-rw-r--r--fs/gfs2/locking/dlm/Makefile2
-rw-r--r--fs/gfs2/locking/dlm/lock_dlm.h12
-rw-r--r--fs/gfs2/locking/dlm/main.c8
-rw-r--r--fs/gfs2/locking/dlm/mount.c21
-rw-r--r--fs/internal.h11
-rw-r--r--fs/namespace.c331
-rw-r--r--fs/pipe.c3
-rw-r--r--fs/pnode.c60
-rw-r--r--fs/pnode.h2
-rw-r--r--fs/proc/base.c125
-rw-r--r--fs/read_write.c6
-rw-r--r--fs/seq_file.c113
-rw-r--r--fs/super.c1
-rw-r--r--fs/udf/Makefile2
-rw-r--r--fs/udf/balloc.c13
-rw-r--r--fs/udf/crc.c172
-rw-r--r--fs/udf/dir.c83
-rw-r--r--fs/udf/ecma_167.h13
-rw-r--r--fs/udf/file.c47
-rw-r--r--fs/udf/ialloc.c13
-rw-r--r--fs/udf/inode.c208
-rw-r--r--fs/udf/lowlevel.c1
-rw-r--r--fs/udf/misc.c26
-rw-r--r--fs/udf/namei.c218
-rw-r--r--fs/udf/partition.c67
-rw-r--r--fs/udf/super.c1262
-rw-r--r--fs/udf/symlink.c1
-rw-r--r--fs/udf/truncate.c81
-rw-r--r--fs/udf/udf_i.h30
-rw-r--r--fs/udf/udf_sb.h109
-rw-r--r--fs/udf/udfdecl.h67
-rw-r--r--fs/udf/udfend.h22
-rw-r--r--fs/udf/udftime.c35
-rw-r--r--fs/udf/unicode.c62
-rw-r--r--fs/xattr.c1
-rw-r--r--include/asm-ia64/mca.h1
-rw-r--r--include/asm-sh/i2c-sh7760.h22
-rw-r--r--include/asm-sparc/device.h2
-rw-r--r--include/asm-sparc/prom.h5
-rw-r--r--include/asm-sparc64/iommu.h3
-rw-r--r--include/asm-sparc64/mmzone.h17
-rw-r--r--include/asm-sparc64/numnodes.h6
-rw-r--r--include/asm-sparc64/ptrace.h18
-rw-r--r--include/asm-sparc64/sparsemem.h2
-rw-r--r--include/asm-sparc64/topology.h73
-rw-r--r--include/asm-sparc64/ttable.h14
-rw-r--r--include/linux/Kbuild6
-rw-r--r--include/linux/dcache.h3
-rw-r--r--include/linux/dlm.h7
-rw-r--r--include/linux/dlm_device.h11
-rw-r--r--include/linux/dlm_plock.h50
-rw-r--r--include/linux/dlmconstants.h4
-rw-r--r--include/linux/fs.h6
-rw-r--r--include/linux/hid.h17
-rw-r--r--include/linux/hidraw.h1
-rw-r--r--include/linux/i2c-algo-pca.h37
-rw-r--r--include/linux/i2c-pca-platform.h12
-rw-r--r--include/linux/ieee80211.h20
-rw-r--r--include/linux/lock_dlm_plock.h41
-rw-r--r--include/linux/mnt_namespace.h12
-rw-r--r--include/linux/mount.h4
-rw-r--r--include/linux/rtnetlink.h4
-rw-r--r--include/linux/security.h52
-rw-r--r--include/linux/seq_file.h6
-rw-r--r--include/linux/udf_fs.h51
-rw-r--r--include/linux/udf_fs_i.h31
-rw-r--r--include/linux/udf_fs_sb.h117
-rw-r--r--include/net/xfrm.h3
-rw-r--r--include/sound/ac97_codec.h1
-rw-r--r--include/sound/ak4114.h1
-rw-r--r--include/sound/ak4xxx-adda.h2
-rw-r--r--include/sound/asoundef.h8
-rw-r--r--include/sound/control.h7
-rw-r--r--include/sound/core.h10
-rw-r--r--include/sound/mpu401.h15
-rw-r--r--include/sound/version.h4
-rw-r--r--kernel/exit.c27
-rw-r--r--kernel/sched.c1
-rw-r--r--kernel/time.c1
-rw-r--r--lib/lmb.c2
-rw-r--r--mm/slub.c4
-rw-r--r--net/core/net-sysfs.c2
-rw-r--r--net/core/rtnetlink.c6
-rw-r--r--net/dccp/probe.c17
-rw-r--r--net/ipv4/fib_hash.c17
-rw-r--r--net/ipv4/fib_trie.c18
-rw-r--r--net/ipv4/icmp.c10
-rw-r--r--net/ipv4/ip_options.c12
-rw-r--r--net/ipv4/route.c11
-rw-r--r--net/ipv4/tcp.c2
-rw-r--r--net/ipv4/tcp_input.c2
-rw-r--r--net/ipv4/tcp_ipv4.c36
-rw-r--r--net/ipv4/udp.c15
-rw-r--r--net/ipv6/addrconf.c7
-rw-r--r--net/ipv6/ip6_fib.c2
-rw-r--r--net/ipv6/route.c5
-rw-r--r--net/key/af_key.c2
-rw-r--r--net/mac80211/mlme.c28
-rw-r--r--net/mac80211/rx.c2
-rw-r--r--net/mac80211/wme.c2
-rw-r--r--net/rose/rose_route.c2
-rw-r--r--net/sctp/objcnt.c9
-rw-r--r--net/socket.c3
-rw-r--r--net/unix/af_unix.c6
-rw-r--r--net/xfrm/xfrm_policy.c2
-rw-r--r--net/xfrm/xfrm_user.c2
-rw-r--r--security/dummy.c10
-rw-r--r--security/security.c20
-rw-r--r--security/selinux/avc.c9
-rw-r--r--security/selinux/hooks.c23
-rw-r--r--security/selinux/netif.c2
-rw-r--r--security/smack/smack_lsm.c4
-rw-r--r--sound/arm/pxa2xx-ac97.c34
-rw-r--r--sound/core/Kconfig4
-rw-r--r--sound/core/Makefile1
-rw-r--r--sound/core/init.c38
-rw-r--r--sound/core/misc.c4
-rw-r--r--sound/core/oss/mixer_oss.c2
-rw-r--r--sound/core/seq/oss/seq_oss_synth.c9
-rw-r--r--sound/core/vmaster.c (renamed from sound/pci/hda/vmaster.c)13
-rw-r--r--sound/drivers/Kconfig18
-rw-r--r--sound/drivers/Makefile2
-rw-r--r--sound/drivers/dummy.c37
-rw-r--r--sound/drivers/ml403-ac97cr.c6
-rw-r--r--sound/drivers/mpu401/mpu401_uart.c23
-rw-r--r--sound/drivers/pcsp/Makefile2
-rw-r--r--sound/drivers/pcsp/pcsp.c235
-rw-r--r--sound/drivers/pcsp/pcsp.h82
-rw-r--r--sound/drivers/pcsp/pcsp_input.c116
-rw-r--r--sound/drivers/pcsp/pcsp_input.h14
-rw-r--r--sound/drivers/pcsp/pcsp_lib.c338
-rw-r--r--sound/drivers/pcsp/pcsp_mixer.c143
-rw-r--r--sound/i2c/other/ak4114.c24
-rw-r--r--sound/i2c/other/ak4xxx-adda.c16
-rw-r--r--sound/isa/sb/sb16_csp.c28
-rw-r--r--sound/isa/sb/sb_common.c6
-rw-r--r--sound/oss/dmabuf.c4
-rw-r--r--sound/oss/trident.c12
-rw-r--r--sound/oss/trident.h2
-rw-r--r--sound/oss/vwsnd.c6
-rw-r--r--sound/pci/Kconfig22
-rw-r--r--sound/pci/Makefile1
-rw-r--r--sound/pci/ac97/ac97_patch.c46
-rw-r--r--sound/pci/ac97/ac97_pcm.c1
-rw-r--r--sound/pci/ad1889.c6
-rw-r--r--sound/pci/ali5451/ali5451.c32
-rw-r--r--sound/pci/als300.c4
-rw-r--r--sound/pci/atiixp.c2
-rw-r--r--sound/pci/atiixp_modem.c2
-rw-r--r--sound/pci/au88x0/au88x0.c2
-rw-r--r--sound/pci/au88x0/au88x0_pcm.c10
-rw-r--r--sound/pci/aw2/Makefile3
-rw-r--r--sound/pci/aw2/aw2-alsa.c794
-rw-r--r--sound/pci/aw2/aw2-saa7146.c465
-rw-r--r--sound/pci/aw2/aw2-saa7146.h105
-rw-r--r--sound/pci/aw2/aw2-tsl.c110
-rw-r--r--sound/pci/aw2/saa7146.h168
-rw-r--r--sound/pci/azt3328.c7
-rw-r--r--sound/pci/ca0106/ca0106_main.c21
-rw-r--r--sound/pci/ca0106/ca0106_mixer.c59
-rw-r--r--sound/pci/cmipci.c13
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.c6
-rw-r--r--sound/pci/echoaudio/echoaudio.c7
-rw-r--r--sound/pci/emu10k1/emu10k1_main.c15
-rw-r--r--sound/pci/emu10k1/emu10k1x.c30
-rw-r--r--sound/pci/emu10k1/emuproc.c2
-rw-r--r--sound/pci/ens1370.c9
-rw-r--r--sound/pci/es1938.c5
-rw-r--r--sound/pci/es1968.c42
-rw-r--r--sound/pci/fm801.c8
-rw-r--r--sound/pci/hda/Makefile2
-rw-r--r--sound/pci/hda/hda_codec.c201
-rw-r--r--sound/pci/hda/hda_codec.h13
-rw-r--r--sound/pci/hda/hda_generic.c4
-rw-r--r--sound/pci/hda/hda_intel.c459
-rw-r--r--sound/pci/hda/hda_local.h20
-rw-r--r--sound/pci/hda/hda_patch.h28
-rw-r--r--sound/pci/hda/patch_analog.c581
-rw-r--r--sound/pci/hda/patch_atihdmi.c8
-rw-r--r--sound/pci/hda/patch_cmedia.c13
-rw-r--r--sound/pci/hda/patch_conexant.c68
-rw-r--r--sound/pci/hda/patch_realtek.c1248
-rw-r--r--sound/pci/hda/patch_si3054.c4
-rw-r--r--sound/pci/hda/patch_sigmatel.c391
-rw-r--r--sound/pci/hda/patch_via.c14
-rw-r--r--sound/pci/ice1712/delta.c22
-rw-r--r--sound/pci/ice1712/delta.h2
-rw-r--r--sound/pci/ice1712/ews.c15
-rw-r--r--sound/pci/ice1712/ews.h4
-rw-r--r--sound/pci/ice1712/hoontech.c21
-rw-r--r--sound/pci/ice1712/ice1712.c45
-rw-r--r--sound/pci/ice1712/ice1712.h17
-rw-r--r--sound/pci/ice1712/ice1724.c431
-rw-r--r--sound/pci/ice1712/juli.c486
-rw-r--r--sound/pci/ice1712/pontis.c4
-rw-r--r--sound/pci/ice1712/prodigy192.c37
-rw-r--r--sound/pci/ice1712/revo.c55
-rw-r--r--sound/pci/intel8x0.c33
-rw-r--r--sound/pci/intel8x0m.c9
-rw-r--r--sound/pci/korg1212/korg1212.c1
-rw-r--r--sound/pci/maestro3.c38
-rw-r--r--sound/pci/nm256/nm256.c4
-rw-r--r--sound/pci/oxygen/cs4362a.h69
-rw-r--r--sound/pci/oxygen/cs4398.h69
-rw-r--r--sound/pci/oxygen/hifier.c36
-rw-r--r--sound/pci/oxygen/oxygen.c129
-rw-r--r--sound/pci/oxygen/oxygen.h23
-rw-r--r--sound/pci/oxygen/oxygen_io.c23
-rw-r--r--sound/pci/oxygen/oxygen_lib.c113
-rw-r--r--sound/pci/oxygen/oxygen_mixer.c217
-rw-r--r--sound/pci/oxygen/oxygen_pcm.c78
-rw-r--r--sound/pci/oxygen/pcm1796.h58
-rw-r--r--sound/pci/oxygen/virtuoso.c594
-rw-r--r--sound/pci/oxygen/wm8785.h45
-rw-r--r--sound/pci/pcxhr/pcxhr.c7
-rw-r--r--sound/pci/pcxhr/pcxhr_core.c33
-rw-r--r--sound/pci/riptide/riptide.c14
-rw-r--r--sound/pci/rme32.c3
-rw-r--r--sound/pci/rme96.c3
-rw-r--r--sound/pci/rme9652/hdsp.c54
-rw-r--r--sound/pci/rme9652/hdspm.c19
-rw-r--r--sound/pci/sis7019.c1
-rw-r--r--sound/pci/trident/trident_main.c4
-rw-r--r--sound/pci/via82xx.c2
-rw-r--r--sound/pci/via82xx_modem.c2
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c4
-rw-r--r--sound/ppc/awacs.c265
-rw-r--r--sound/ppc/awacs.h21
-rw-r--r--sound/ppc/burgundy.c465
-rw-r--r--sound/ppc/burgundy.h31
-rw-r--r--sound/ppc/pmac.c10
-rw-r--r--sound/soc/Kconfig1
-rw-r--r--sound/soc/Makefile2
-rw-r--r--sound/soc/codecs/Kconfig4
-rw-r--r--sound/soc/codecs/Makefile2
-rw-r--r--sound/soc/codecs/ac97.c16
-rw-r--r--sound/soc/codecs/cs4270.c2
-rw-r--r--sound/soc/codecs/tlv320aic3x.c22
-rw-r--r--sound/soc/codecs/wm8731.c23
-rw-r--r--sound/soc/codecs/wm8750.c27
-rw-r--r--sound/soc/codecs/wm8753.c5
-rw-r--r--sound/soc/codecs/wm9712.c8
-rw-r--r--sound/soc/codecs/wm9713.c1300
-rw-r--r--sound/soc/codecs/wm9713.h53
-rw-r--r--sound/soc/davinci/Kconfig19
-rw-r--r--sound/soc/davinci/Makefile11
-rw-r--r--sound/soc/davinci/davinci-evm.c208
-rw-r--r--sound/soc/davinci/davinci-i2s.c407
-rw-r--r--sound/soc/davinci/davinci-i2s.h17
-rw-r--r--sound/soc/davinci/davinci-pcm.c389
-rw-r--r--sound/soc/davinci/davinci-pcm.h29
-rw-r--r--sound/soc/fsl/fsl_dma.c1
-rw-r--r--sound/soc/fsl/fsl_ssi.c1
-rw-r--r--sound/soc/pxa/corgi.c11
-rw-r--r--sound/soc/pxa/poodle.c8
-rw-r--r--sound/soc/pxa/pxa2xx-ac97.c37
-rw-r--r--sound/soc/pxa/pxa2xx-pcm.c9
-rw-r--r--sound/soc/pxa/spitz.c6
-rw-r--r--sound/soc/s3c24xx/neo1973_wm8753.c1
-rw-r--r--sound/soc/s3c24xx/s3c24xx-i2s.c41
-rw-r--r--sound/soc/s3c24xx/s3c24xx-pcm.c30
-rw-r--r--sound/soc/sh/Kconfig1
-rw-r--r--sound/soc/soc-core.c2
-rw-r--r--sound/soc/soc-dapm.c7
-rw-r--r--sound/spi/at73c213.c44
-rw-r--r--sound/usb/caiaq/caiaq-audio.c81
-rw-r--r--sound/usb/caiaq/caiaq-device.c4
-rw-r--r--sound/usb/usbaudio.c98
-rw-r--r--sound/usb/usbquirks.h75
439 files changed, 18104 insertions, 7217 deletions
diff --git a/CREDITS b/CREDITS
index da0a56e23bee..8fec7b3f96d5 100644
--- a/CREDITS
+++ b/CREDITS
@@ -403,6 +403,8 @@ D: Linux CD and Support Giveaway List
403N: Erik Inge Bolsø 403N: Erik Inge Bolsø
404E: knan@mo.himolde.no 404E: knan@mo.himolde.no
405D: Misc kernel hacks 405D: Misc kernel hacks
406D: Updated PC speaker driver for 2.3
407S: Norway
406 408
407N: Andreas E. Bombe 409N: Andreas E. Bombe
408E: andreas.bombe@munich.netsurf.de 410E: andreas.bombe@munich.netsurf.de
@@ -3116,6 +3118,12 @@ S: Post Office Box 64132
3116S: Sunnyvale, California 94088-4132 3118S: Sunnyvale, California 94088-4132
3117S: USA 3119S: USA
3118 3120
3121N: Stas Sergeev
3122E: stsp@users.sourceforge.net
3123D: PCM PC-Speaker driver
3124D: misc fixes
3125S: Russia
3126
3119N: Simon Shapiro 3127N: Simon Shapiro
3120E: shimon@i-Connect.Net 3128E: shimon@i-Connect.Net
3121W: http://www.-i-Connect.Net/~shimon 3129W: http://www.-i-Connect.Net/~shimon
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index 518ebe609e2b..2a99116edc47 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -43,6 +43,7 @@ Table of Contents
43 2.13 /proc/<pid>/oom_score - Display current oom-killer score 43 2.13 /proc/<pid>/oom_score - Display current oom-killer score
44 2.14 /proc/<pid>/io - Display the IO accounting fields 44 2.14 /proc/<pid>/io - Display the IO accounting fields
45 2.15 /proc/<pid>/coredump_filter - Core dump filtering settings 45 2.15 /proc/<pid>/coredump_filter - Core dump filtering settings
46 2.16 /proc/<pid>/mountinfo - Information about mounts
46 47
47------------------------------------------------------------------------------ 48------------------------------------------------------------------------------
48Preface 49Preface
@@ -2348,4 +2349,41 @@ For example:
2348 $ echo 0x7 > /proc/self/coredump_filter 2349 $ echo 0x7 > /proc/self/coredump_filter
2349 $ ./some_program 2350 $ ./some_program
2350 2351
23522.16 /proc/<pid>/mountinfo - Information about mounts
2353--------------------------------------------------------
2354
2355This file contains lines of the form:
2356
235736 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
2358(1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11)
2359
2360(1) mount ID: unique identifier of the mount (may be reused after umount)
2361(2) parent ID: ID of parent (or of self for the top of the mount tree)
2362(3) major:minor: value of st_dev for files on filesystem
2363(4) root: root of the mount within the filesystem
2364(5) mount point: mount point relative to the process's root
2365(6) mount options: per mount options
2366(7) optional fields: zero or more fields of the form "tag[:value]"
2367(8) separator: marks the end of the optional fields
2368(9) filesystem type: name of filesystem of the form "type[.subtype]"
2369(10) mount source: filesystem specific information or "none"
2370(11) super options: per super block options
2371
2372Parsers should ignore all unrecognised optional fields. Currently the
2373possible optional fields are:
2374
2375shared:X mount is shared in peer group X
2376master:X mount is slave to peer group X
2377propagate_from:X mount is slave and receives propagation from peer group X (*)
2378unbindable mount is unbindable
2379
2380(*) X is the closest dominant peer group under the process's root. If
2381X is the immediate master of the mount, or if there's no dominant peer
2382group under the same root, then only the "master:X" field is present
2383and not the "propagate_from:X" field.
2384
2385For more information on mount propagation see:
2386
2387 Documentation/filesystems/sharedsubtree.txt
2388
2351------------------------------------------------------------------------------ 2389------------------------------------------------------------------------------
diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
index e985cf5e0410..fd4c32a031c9 100644
--- a/Documentation/sound/alsa/ALSA-Configuration.txt
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt
@@ -284,6 +284,13 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
284 control correctly. If you have problems regarding this, try 284 control correctly. If you have problems regarding this, try
285 another ALSA compliant mixer (alsamixer works). 285 another ALSA compliant mixer (alsamixer works).
286 286
287 Module snd-aw2
288 --------------
289
290 Module for Audiowerk2 sound card
291
292 This module supports multiple cards.
293
287 Module snd-azt2320 294 Module snd-azt2320
288 ------------------ 295 ------------------
289 296
@@ -818,19 +825,25 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
818 hippo_1 Hippo (Benq) with jack detection 825 hippo_1 Hippo (Benq) with jack detection
819 sony-assamd Sony ASSAMD 826 sony-assamd Sony ASSAMD
820 ultra Samsung Q1 Ultra Vista model 827 ultra Samsung Q1 Ultra Vista model
828 lenovo-3000 Lenovo 3000 y410
821 basic fixed pin assignment w/o SPDIF 829 basic fixed pin assignment w/o SPDIF
822 auto auto-config reading BIOS (default) 830 auto auto-config reading BIOS (default)
823 831
824 ALC268 832 ALC267/268
833 quanta-il1 Quanta IL1 mini-notebook
825 3stack 3-stack model 834 3stack 3-stack model
826 toshiba Toshiba A205 835 toshiba Toshiba A205
827 acer Acer laptops 836 acer Acer laptops
828 dell Dell OEM laptops (Vostro 1200) 837 dell Dell OEM laptops (Vostro 1200)
838 zepto Zepto laptops
829 test for testing/debugging purpose, almost all controls can 839 test for testing/debugging purpose, almost all controls can
830 adjusted. Appearing only when compiled with 840 adjusted. Appearing only when compiled with
831 $CONFIG_SND_DEBUG=y 841 $CONFIG_SND_DEBUG=y
832 auto auto-config reading BIOS (default) 842 auto auto-config reading BIOS (default)
833 843
844 ALC269
845 basic Basic preset
846
834 ALC662 847 ALC662
835 3stack-dig 3-stack (2-channel) with SPDIF 848 3stack-dig 3-stack (2-channel) with SPDIF
836 3stack-6ch 3-stack (6-channel) 849 3stack-6ch 3-stack (6-channel)
@@ -871,10 +884,11 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
871 lenovo-nb0763 Lenovo NB0763 884 lenovo-nb0763 Lenovo NB0763
872 lenovo-ms7195-dig Lenovo MS7195 885 lenovo-ms7195-dig Lenovo MS7195
873 haier-w66 Haier W66 886 haier-w66 Haier W66
874 6stack-hp HP machines with 6stack (Nettle boards)
875 3stack-hp HP machines with 3stack (Lucknow, Samba boards) 887 3stack-hp HP machines with 3stack (Lucknow, Samba boards)
876 6stack-dell Dell machines with 6stack (Inspiron 530) 888 6stack-dell Dell machines with 6stack (Inspiron 530)
877 mitac Mitac 8252D 889 mitac Mitac 8252D
890 clevo-m720 Clevo M720 laptop series
891 fujitsu-pi2515 Fujitsu AMILO Pi2515
878 auto auto-config reading BIOS (default) 892 auto auto-config reading BIOS (default)
879 893
880 ALC861/660 894 ALC861/660
@@ -911,6 +925,12 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
911 3stack 3-stack mode (default) 925 3stack 3-stack mode (default)
912 6stack 6-stack mode 926 6stack 6-stack mode
913 927
928 AD1884A / AD1883 / AD1984A / AD1984B
929 desktop 3-stack desktop (default)
930 laptop laptop with HP jack sensing
931 mobile mobile devices with HP jack sensing
932 thinkpad Lenovo Thinkpad X300
933
914 AD1884 934 AD1884
915 N/A 935 N/A
916 936
@@ -936,7 +956,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
936 laptop-automute 2-channel with EAPD and HP-automute (Lenovo N100) 956 laptop-automute 2-channel with EAPD and HP-automute (Lenovo N100)
937 ultra 2-channel with EAPD (Samsung Ultra tablet PC) 957 ultra 2-channel with EAPD (Samsung Ultra tablet PC)
938 958
939 AD1988 959 AD1988/AD1988B/AD1989A/AD1989B
940 6stack 6-jack 960 6stack 6-jack
941 6stack-dig ditto with SPDIF 961 6stack-dig ditto with SPDIF
942 3stack 3-jack 962 3stack 3-jack
@@ -979,6 +999,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
979 dell-m26 Dell Inspiron 1501 999 dell-m26 Dell Inspiron 1501
980 dell-m27 Dell Inspiron E1705/9400 1000 dell-m27 Dell Inspiron E1705/9400
981 gateway Gateway laptops with EAPD control 1001 gateway Gateway laptops with EAPD control
1002 panasonic Panasonic CF-74
982 1003
983 STAC9205/9254 1004 STAC9205/9254
984 ref Reference board 1005 ref Reference board
@@ -1017,6 +1038,16 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1017 3stack D965 3stack 1038 3stack D965 3stack
1018 5stack D965 5stack + SPDIF 1039 5stack D965 5stack + SPDIF
1019 dell-3stack Dell Dimension E520 1040 dell-3stack Dell Dimension E520
1041 dell-bios Fixes with Dell BIOS setup
1042
1043 STAC92HD71B*
1044 ref Reference board
1045 dell-m4-1 Dell desktops
1046 dell-m4-2 Dell desktops
1047
1048 STAC92HD73*
1049 ref Reference board
1050 dell-m6 Dell desktops
1020 1051
1021 STAC9872 1052 STAC9872
1022 vaio Setup for VAIO FE550G/SZ110 1053 vaio Setup for VAIO FE550G/SZ110
@@ -1590,6 +1621,16 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1590 1621
1591 Power management is _not_ supported. 1622 Power management is _not_ supported.
1592 1623
1624 Module snd-pcsp
1625 -----------------
1626
1627 Module for internal PC-Speaker.
1628
1629 nforce_wa - enable NForce chipset workaround. Expect bad sound.
1630
1631 This module supports system beeps, some kind of PCM playback and
1632 even a few mixer controls.
1633
1593 Module snd-pcxhr 1634 Module snd-pcxhr
1594 ---------------- 1635 ----------------
1595 1636
diff --git a/MAINTAINERS b/MAINTAINERS
index c0cc52a9afe5..f50e927a1189 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2558,12 +2558,10 @@ W: http://www.tazenda.demon.co.uk/phil/linux-hp
2558S: Maintained 2558S: Maintained
2559 2559
2560MAC80211 2560MAC80211
2561P: Michael Wu
2562M: flamingice@sourmilk.net
2563P: Johannes Berg 2561P: Johannes Berg
2564M: johannes@sipsolutions.net 2562M: johannes@sipsolutions.net
2565P: Jiri Benc 2563P: Michael Wu
2566M: jbenc@suse.cz 2564M: flamingice@sourmilk.net
2567L: linux-wireless@vger.kernel.org 2565L: linux-wireless@vger.kernel.org
2568W: http://linuxwireless.org/ 2566W: http://linuxwireless.org/
2569T: git kernel.org:/pub/scm/linux/kernel/git/linville/wireless-2.6.git 2567T: git kernel.org:/pub/scm/linux/kernel/git/linville/wireless-2.6.git
diff --git a/Makefile b/Makefile
index 3dbc826bb8e6..d35c5246fce5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 2 1VERSION = 2
2PATCHLEVEL = 6 2PATCHLEVEL = 6
3SUBLEVEL = 25 3SUBLEVEL = 25
4EXTRAVERSION = 4EXTRAVERSION = -numa
5NAME = Funky Weasel is Jiggy wit it 5NAME = Funky Weasel is Jiggy wit it
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 8c71daf94a59..9fee37e2596f 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -75,6 +75,7 @@ osf_set_program_attributes(unsigned long text_start, unsigned long text_len,
75 lock_kernel(); 75 lock_kernel();
76 mm = current->mm; 76 mm = current->mm;
77 mm->end_code = bss_start + bss_len; 77 mm->end_code = bss_start + bss_len;
78 mm->start_brk = bss_start + bss_len;
78 mm->brk = bss_start + bss_len; 79 mm->brk = bss_start + bss_len;
79#if 0 80#if 0
80 printk("set_program_attributes(%lx %lx %lx %lx)\n", 81 printk("set_program_attributes(%lx %lx %lx %lx)\n",
diff --git a/arch/alpha/kernel/pci.c b/arch/alpha/kernel/pci.c
index c107cc08daf4..78357798b6fd 100644
--- a/arch/alpha/kernel/pci.c
+++ b/arch/alpha/kernel/pci.c
@@ -71,25 +71,13 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82378, quirk_i
71static void __init 71static void __init
72quirk_cypress(struct pci_dev *dev) 72quirk_cypress(struct pci_dev *dev)
73{ 73{
74 /* The Notorious Cy82C693 chip. */
75
76 /* The Cypress IDE controller doesn't support native mode, but it
77 has programmable addresses of IDE command/control registers.
78 This violates PCI specifications, confuses the IDE subsystem and
79 causes resource conflicts between the primary HD_CMD register and
80 the floppy controller. Ugh. Fix that. */
81 if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE) {
82 dev->resource[0].flags = 0;
83 dev->resource[1].flags = 0;
84 }
85
86 /* The Cypress bridge responds on the PCI bus in the address range 74 /* The Cypress bridge responds on the PCI bus in the address range
87 0xffff0000-0xffffffff (conventional x86 BIOS ROM). There is no 75 0xffff0000-0xffffffff (conventional x86 BIOS ROM). There is no
88 way to turn this off. The bridge also supports several extended 76 way to turn this off. The bridge also supports several extended
89 BIOS ranges (disabled after power-up), and some consoles do turn 77 BIOS ranges (disabled after power-up), and some consoles do turn
90 them on. So if we use a large direct-map window, or a large SG 78 them on. So if we use a large direct-map window, or a large SG
91 window, we must avoid the entire 0xfff00000-0xffffffff region. */ 79 window, we must avoid the entire 0xfff00000-0xffffffff region. */
92 else if (dev->class >> 8 == PCI_CLASS_BRIDGE_ISA) { 80 if (dev->class >> 8 == PCI_CLASS_BRIDGE_ISA) {
93 if (__direct_map_base + __direct_map_size >= 0xfff00000UL) 81 if (__direct_map_base + __direct_map_size >= 0xfff00000UL)
94 __direct_map_size = 0xfff00000UL - __direct_map_base; 82 __direct_map_size = 0xfff00000UL - __direct_map_base;
95 else { 83 else {
@@ -391,7 +379,7 @@ pcibios_set_master(struct pci_dev *dev)
391 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64); 379 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
392} 380}
393 381
394static void __init 382void __init
395pcibios_claim_one_bus(struct pci_bus *b) 383pcibios_claim_one_bus(struct pci_bus *b)
396{ 384{
397 struct pci_dev *dev; 385 struct pci_dev *dev;
@@ -405,7 +393,8 @@ pcibios_claim_one_bus(struct pci_bus *b)
405 393
406 if (r->parent || !r->start || !r->flags) 394 if (r->parent || !r->start || !r->flags)
407 continue; 395 continue;
408 pci_claim_resource(dev, i); 396 if (pci_probe_only || (r->flags & IORESOURCE_PCI_FIXED))
397 pci_claim_resource(dev, i);
409 } 398 }
410 } 399 }
411 400
@@ -444,8 +433,7 @@ common_init_pci(void)
444 } 433 }
445 } 434 }
446 435
447 if (pci_probe_only) 436 pcibios_claim_console_setup();
448 pcibios_claim_console_setup();
449 437
450 pci_assign_unassigned_resources(); 438 pci_assign_unassigned_resources();
451 pci_fixup_irqs(alpha_mv.pci_swizzle, alpha_mv.pci_map_irq); 439 pci_fixup_irqs(alpha_mv.pci_swizzle, alpha_mv.pci_map_irq);
diff --git a/arch/alpha/kernel/sys_nautilus.c b/arch/alpha/kernel/sys_nautilus.c
index 920196bcbb61..a7f23b5ab814 100644
--- a/arch/alpha/kernel/sys_nautilus.c
+++ b/arch/alpha/kernel/sys_nautilus.c
@@ -187,6 +187,7 @@ nautilus_machine_check(unsigned long vector, unsigned long la_ptr)
187} 187}
188 188
189extern void free_reserved_mem(void *, void *); 189extern void free_reserved_mem(void *, void *);
190extern void pcibios_claim_one_bus(struct pci_bus *);
190 191
191static struct resource irongate_mem = { 192static struct resource irongate_mem = {
192 .name = "Irongate PCI MEM", 193 .name = "Irongate PCI MEM",
@@ -205,6 +206,7 @@ nautilus_init_pci(void)
205 /* Scan our single hose. */ 206 /* Scan our single hose. */
206 bus = pci_scan_bus(0, alpha_mv.pci_ops, hose); 207 bus = pci_scan_bus(0, alpha_mv.pci_ops, hose);
207 hose->bus = bus; 208 hose->bus = bus;
209 pcibios_claim_one_bus(bus);
208 210
209 irongate = pci_get_bus_and_slot(0, 0); 211 irongate = pci_get_bus_and_slot(0, 0);
210 bus->self = irongate; 212 bus->self = irongate;
diff --git a/arch/arm/mach-lh7a40x/arch-kev7a400.c b/arch/arm/mach-lh7a40x/arch-kev7a400.c
index 6d26661d99f6..2ef7d0097b38 100644
--- a/arch/arm/mach-lh7a40x/arch-kev7a400.c
+++ b/arch/arm/mach-lh7a40x/arch-kev7a400.c
@@ -75,10 +75,9 @@ static void kev7a400_cpld_handler (unsigned int irq, struct irq_desc *desc)
75{ 75{
76 u32 mask = CPLD_LATCHED_INTS; 76 u32 mask = CPLD_LATCHED_INTS;
77 irq = IRQ_KEV7A400_CPLD; 77 irq = IRQ_KEV7A400_CPLD;
78 for (; mask; mask >>= 1, ++irq) { 78 for (; mask; mask >>= 1, ++irq)
79 if (mask & 1) 79 if (mask & 1)
80 desc[irq].handle (irq, desc); 80 desc_handle_irq(irq, desc);
81 }
82} 81}
83 82
84void __init lh7a40x_init_board_irq (void) 83void __init lh7a40x_init_board_irq (void)
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index 746cbb7c8e95..1b8229d9c9d5 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -32,6 +32,7 @@ config CPU_ARM7TDMI
32 depends on !MMU 32 depends on !MMU
33 select CPU_32v4T 33 select CPU_32v4T
34 select CPU_ABRT_LV4T 34 select CPU_ABRT_LV4T
35 select CPU_PABRT_NOIFAR
35 select CPU_CACHE_V4 36 select CPU_CACHE_V4
36 help 37 help
37 A 32-bit RISC microprocessor based on the ARM7 processor core 38 A 32-bit RISC microprocessor based on the ARM7 processor core
@@ -85,6 +86,7 @@ config CPU_ARM740T
85 depends on !MMU 86 depends on !MMU
86 select CPU_32v4T 87 select CPU_32v4T
87 select CPU_ABRT_LV4T 88 select CPU_ABRT_LV4T
89 select CPU_PABRT_NOIFAR
88 select CPU_CACHE_V3 # although the core is v4t 90 select CPU_CACHE_V3 # although the core is v4t
89 select CPU_CP15_MPU 91 select CPU_CP15_MPU
90 help 92 help
@@ -101,6 +103,7 @@ config CPU_ARM9TDMI
101 depends on !MMU 103 depends on !MMU
102 select CPU_32v4T 104 select CPU_32v4T
103 select CPU_ABRT_NOMMU 105 select CPU_ABRT_NOMMU
106 select CPU_PABRT_NOIFAR
104 select CPU_CACHE_V4 107 select CPU_CACHE_V4
105 help 108 help
106 A 32-bit RISC microprocessor based on the ARM9 processor core 109 A 32-bit RISC microprocessor based on the ARM9 processor core
@@ -200,6 +203,7 @@ config CPU_ARM940T
200 depends on !MMU 203 depends on !MMU
201 select CPU_32v4T 204 select CPU_32v4T
202 select CPU_ABRT_NOMMU 205 select CPU_ABRT_NOMMU
206 select CPU_PABRT_NOIFAR
203 select CPU_CACHE_VIVT 207 select CPU_CACHE_VIVT
204 select CPU_CP15_MPU 208 select CPU_CP15_MPU
205 help 209 help
@@ -217,6 +221,7 @@ config CPU_ARM946E
217 depends on !MMU 221 depends on !MMU
218 select CPU_32v5 222 select CPU_32v5
219 select CPU_ABRT_NOMMU 223 select CPU_ABRT_NOMMU
224 select CPU_PABRT_NOIFAR
220 select CPU_CACHE_VIVT 225 select CPU_CACHE_VIVT
221 select CPU_CP15_MPU 226 select CPU_CP15_MPU
222 help 227 help
@@ -351,6 +356,7 @@ config CPU_XSC3
351 default y 356 default y
352 select CPU_32v5 357 select CPU_32v5
353 select CPU_ABRT_EV5T 358 select CPU_ABRT_EV5T
359 select CPU_PABRT_NOIFAR
354 select CPU_CACHE_VIVT 360 select CPU_CACHE_VIVT
355 select CPU_CP15_MMU 361 select CPU_CP15_MMU
356 select CPU_TLB_V4WBI if MMU 362 select CPU_TLB_V4WBI if MMU
diff --git a/arch/arm/mm/proc-arm1020.S b/arch/arm/mm/proc-arm1020.S
index 32fd7ea533f2..5673f4d6113b 100644
--- a/arch/arm/mm/proc-arm1020.S
+++ b/arch/arm/mm/proc-arm1020.S
@@ -471,6 +471,7 @@ arm1020_crval:
471 .type arm1020_processor_functions, #object 471 .type arm1020_processor_functions, #object
472arm1020_processor_functions: 472arm1020_processor_functions:
473 .word v4t_early_abort 473 .word v4t_early_abort
474 .word pabort_noifar
474 .word cpu_arm1020_proc_init 475 .word cpu_arm1020_proc_init
475 .word cpu_arm1020_proc_fin 476 .word cpu_arm1020_proc_fin
476 .word cpu_arm1020_reset 477 .word cpu_arm1020_reset
@@ -478,7 +479,6 @@ arm1020_processor_functions:
478 .word cpu_arm1020_dcache_clean_area 479 .word cpu_arm1020_dcache_clean_area
479 .word cpu_arm1020_switch_mm 480 .word cpu_arm1020_switch_mm
480 .word cpu_arm1020_set_pte_ext 481 .word cpu_arm1020_set_pte_ext
481 .word pabort_noifar
482 .size arm1020_processor_functions, . - arm1020_processor_functions 482 .size arm1020_processor_functions, . - arm1020_processor_functions
483 483
484 .section ".rodata" 484 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm1020e.S b/arch/arm/mm/proc-arm1020e.S
index fe2b0ae70274..4343fdb0e9e5 100644
--- a/arch/arm/mm/proc-arm1020e.S
+++ b/arch/arm/mm/proc-arm1020e.S
@@ -452,6 +452,7 @@ arm1020e_crval:
452 .type arm1020e_processor_functions, #object 452 .type arm1020e_processor_functions, #object
453arm1020e_processor_functions: 453arm1020e_processor_functions:
454 .word v4t_early_abort 454 .word v4t_early_abort
455 .word pabort_noifar
455 .word cpu_arm1020e_proc_init 456 .word cpu_arm1020e_proc_init
456 .word cpu_arm1020e_proc_fin 457 .word cpu_arm1020e_proc_fin
457 .word cpu_arm1020e_reset 458 .word cpu_arm1020e_reset
@@ -459,7 +460,6 @@ arm1020e_processor_functions:
459 .word cpu_arm1020e_dcache_clean_area 460 .word cpu_arm1020e_dcache_clean_area
460 .word cpu_arm1020e_switch_mm 461 .word cpu_arm1020e_switch_mm
461 .word cpu_arm1020e_set_pte_ext 462 .word cpu_arm1020e_set_pte_ext
462 .word pabort_noifar
463 .size arm1020e_processor_functions, . - arm1020e_processor_functions 463 .size arm1020e_processor_functions, . - arm1020e_processor_functions
464 464
465 .section ".rodata" 465 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm1022.S b/arch/arm/mm/proc-arm1022.S
index 06dde678e19d..2a4ea1659e96 100644
--- a/arch/arm/mm/proc-arm1022.S
+++ b/arch/arm/mm/proc-arm1022.S
@@ -435,6 +435,7 @@ arm1022_crval:
435 .type arm1022_processor_functions, #object 435 .type arm1022_processor_functions, #object
436arm1022_processor_functions: 436arm1022_processor_functions:
437 .word v4t_early_abort 437 .word v4t_early_abort
438 .word pabort_noifar
438 .word cpu_arm1022_proc_init 439 .word cpu_arm1022_proc_init
439 .word cpu_arm1022_proc_fin 440 .word cpu_arm1022_proc_fin
440 .word cpu_arm1022_reset 441 .word cpu_arm1022_reset
@@ -442,7 +443,6 @@ arm1022_processor_functions:
442 .word cpu_arm1022_dcache_clean_area 443 .word cpu_arm1022_dcache_clean_area
443 .word cpu_arm1022_switch_mm 444 .word cpu_arm1022_switch_mm
444 .word cpu_arm1022_set_pte_ext 445 .word cpu_arm1022_set_pte_ext
445 .word pabort_noifar
446 .size arm1022_processor_functions, . - arm1022_processor_functions 446 .size arm1022_processor_functions, . - arm1022_processor_functions
447 447
448 .section ".rodata" 448 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm1026.S b/arch/arm/mm/proc-arm1026.S
index f5506e6e681e..77a1babd421c 100644
--- a/arch/arm/mm/proc-arm1026.S
+++ b/arch/arm/mm/proc-arm1026.S
@@ -430,6 +430,7 @@ arm1026_crval:
430 .type arm1026_processor_functions, #object 430 .type arm1026_processor_functions, #object
431arm1026_processor_functions: 431arm1026_processor_functions:
432 .word v5t_early_abort 432 .word v5t_early_abort
433 .word pabort_noifar
433 .word cpu_arm1026_proc_init 434 .word cpu_arm1026_proc_init
434 .word cpu_arm1026_proc_fin 435 .word cpu_arm1026_proc_fin
435 .word cpu_arm1026_reset 436 .word cpu_arm1026_reset
@@ -437,7 +438,6 @@ arm1026_processor_functions:
437 .word cpu_arm1026_dcache_clean_area 438 .word cpu_arm1026_dcache_clean_area
438 .word cpu_arm1026_switch_mm 439 .word cpu_arm1026_switch_mm
439 .word cpu_arm1026_set_pte_ext 440 .word cpu_arm1026_set_pte_ext
440 .word pabort_noifar
441 .size arm1026_processor_functions, . - arm1026_processor_functions 441 .size arm1026_processor_functions, . - arm1026_processor_functions
442 442
443 .section .rodata 443 .section .rodata
diff --git a/arch/arm/mm/proc-arm6_7.S b/arch/arm/mm/proc-arm6_7.S
index 14b6a95c8d45..c371fc87776e 100644
--- a/arch/arm/mm/proc-arm6_7.S
+++ b/arch/arm/mm/proc-arm6_7.S
@@ -293,6 +293,7 @@ __arm7_setup: mov r0, #0
293 .type arm6_processor_functions, #object 293 .type arm6_processor_functions, #object
294ENTRY(arm6_processor_functions) 294ENTRY(arm6_processor_functions)
295 .word cpu_arm6_data_abort 295 .word cpu_arm6_data_abort
296 .word pabort_noifar
296 .word cpu_arm6_proc_init 297 .word cpu_arm6_proc_init
297 .word cpu_arm6_proc_fin 298 .word cpu_arm6_proc_fin
298 .word cpu_arm6_reset 299 .word cpu_arm6_reset
@@ -300,7 +301,6 @@ ENTRY(arm6_processor_functions)
300 .word cpu_arm6_dcache_clean_area 301 .word cpu_arm6_dcache_clean_area
301 .word cpu_arm6_switch_mm 302 .word cpu_arm6_switch_mm
302 .word cpu_arm6_set_pte_ext 303 .word cpu_arm6_set_pte_ext
303 .word pabort_noifar
304 .size arm6_processor_functions, . - arm6_processor_functions 304 .size arm6_processor_functions, . - arm6_processor_functions
305 305
306/* 306/*
@@ -310,6 +310,7 @@ ENTRY(arm6_processor_functions)
310 .type arm7_processor_functions, #object 310 .type arm7_processor_functions, #object
311ENTRY(arm7_processor_functions) 311ENTRY(arm7_processor_functions)
312 .word cpu_arm7_data_abort 312 .word cpu_arm7_data_abort
313 .word pabort_noifar
313 .word cpu_arm7_proc_init 314 .word cpu_arm7_proc_init
314 .word cpu_arm7_proc_fin 315 .word cpu_arm7_proc_fin
315 .word cpu_arm7_reset 316 .word cpu_arm7_reset
@@ -317,7 +318,6 @@ ENTRY(arm7_processor_functions)
317 .word cpu_arm7_dcache_clean_area 318 .word cpu_arm7_dcache_clean_area
318 .word cpu_arm7_switch_mm 319 .word cpu_arm7_switch_mm
319 .word cpu_arm7_set_pte_ext 320 .word cpu_arm7_set_pte_ext
320 .word pabort_noifar
321 .size arm7_processor_functions, . - arm7_processor_functions 321 .size arm7_processor_functions, . - arm7_processor_functions
322 322
323 .section ".rodata" 323 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm720.S b/arch/arm/mm/proc-arm720.S
index ca5e7aac2da7..d64f8e6f75ab 100644
--- a/arch/arm/mm/proc-arm720.S
+++ b/arch/arm/mm/proc-arm720.S
@@ -198,6 +198,7 @@ arm720_crval:
198 .type arm720_processor_functions, #object 198 .type arm720_processor_functions, #object
199ENTRY(arm720_processor_functions) 199ENTRY(arm720_processor_functions)
200 .word v4t_late_abort 200 .word v4t_late_abort
201 .word pabort_noifar
201 .word cpu_arm720_proc_init 202 .word cpu_arm720_proc_init
202 .word cpu_arm720_proc_fin 203 .word cpu_arm720_proc_fin
203 .word cpu_arm720_reset 204 .word cpu_arm720_reset
@@ -205,7 +206,6 @@ ENTRY(arm720_processor_functions)
205 .word cpu_arm720_dcache_clean_area 206 .word cpu_arm720_dcache_clean_area
206 .word cpu_arm720_switch_mm 207 .word cpu_arm720_switch_mm
207 .word cpu_arm720_set_pte_ext 208 .word cpu_arm720_set_pte_ext
208 .word pabort_noifar
209 .size arm720_processor_functions, . - arm720_processor_functions 209 .size arm720_processor_functions, . - arm720_processor_functions
210 210
211 .section ".rodata" 211 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm740.S b/arch/arm/mm/proc-arm740.S
index 7069f495cf9b..3a57376c8bc9 100644
--- a/arch/arm/mm/proc-arm740.S
+++ b/arch/arm/mm/proc-arm740.S
@@ -126,6 +126,7 @@ __arm740_setup:
126 .type arm740_processor_functions, #object 126 .type arm740_processor_functions, #object
127ENTRY(arm740_processor_functions) 127ENTRY(arm740_processor_functions)
128 .word v4t_late_abort 128 .word v4t_late_abort
129 .word pabort_noifar
129 .word cpu_arm740_proc_init 130 .word cpu_arm740_proc_init
130 .word cpu_arm740_proc_fin 131 .word cpu_arm740_proc_fin
131 .word cpu_arm740_reset 132 .word cpu_arm740_reset
diff --git a/arch/arm/mm/proc-arm7tdmi.S b/arch/arm/mm/proc-arm7tdmi.S
index d091c2571823..7b3ecdeb5370 100644
--- a/arch/arm/mm/proc-arm7tdmi.S
+++ b/arch/arm/mm/proc-arm7tdmi.S
@@ -64,6 +64,7 @@ __arm7tdmi_setup:
64 .type arm7tdmi_processor_functions, #object 64 .type arm7tdmi_processor_functions, #object
65ENTRY(arm7tdmi_processor_functions) 65ENTRY(arm7tdmi_processor_functions)
66 .word v4t_late_abort 66 .word v4t_late_abort
67 .word pabort_noifar
67 .word cpu_arm7tdmi_proc_init 68 .word cpu_arm7tdmi_proc_init
68 .word cpu_arm7tdmi_proc_fin 69 .word cpu_arm7tdmi_proc_fin
69 .word cpu_arm7tdmi_reset 70 .word cpu_arm7tdmi_reset
diff --git a/arch/arm/mm/proc-arm920.S b/arch/arm/mm/proc-arm920.S
index 0170d4f466ea..28cdb060df45 100644
--- a/arch/arm/mm/proc-arm920.S
+++ b/arch/arm/mm/proc-arm920.S
@@ -417,6 +417,7 @@ arm920_crval:
417 .type arm920_processor_functions, #object 417 .type arm920_processor_functions, #object
418arm920_processor_functions: 418arm920_processor_functions:
419 .word v4t_early_abort 419 .word v4t_early_abort
420 .word pabort_noifar
420 .word cpu_arm920_proc_init 421 .word cpu_arm920_proc_init
421 .word cpu_arm920_proc_fin 422 .word cpu_arm920_proc_fin
422 .word cpu_arm920_reset 423 .word cpu_arm920_reset
@@ -424,7 +425,6 @@ arm920_processor_functions:
424 .word cpu_arm920_dcache_clean_area 425 .word cpu_arm920_dcache_clean_area
425 .word cpu_arm920_switch_mm 426 .word cpu_arm920_switch_mm
426 .word cpu_arm920_set_pte_ext 427 .word cpu_arm920_set_pte_ext
427 .word pabort_noifar
428 .size arm920_processor_functions, . - arm920_processor_functions 428 .size arm920_processor_functions, . - arm920_processor_functions
429 429
430 .section ".rodata" 430 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm922.S b/arch/arm/mm/proc-arm922.S
index b7952493d404..94ddcb4a4b76 100644
--- a/arch/arm/mm/proc-arm922.S
+++ b/arch/arm/mm/proc-arm922.S
@@ -421,6 +421,7 @@ arm922_crval:
421 .type arm922_processor_functions, #object 421 .type arm922_processor_functions, #object
422arm922_processor_functions: 422arm922_processor_functions:
423 .word v4t_early_abort 423 .word v4t_early_abort
424 .word pabort_noifar
424 .word cpu_arm922_proc_init 425 .word cpu_arm922_proc_init
425 .word cpu_arm922_proc_fin 426 .word cpu_arm922_proc_fin
426 .word cpu_arm922_reset 427 .word cpu_arm922_reset
@@ -428,7 +429,6 @@ arm922_processor_functions:
428 .word cpu_arm922_dcache_clean_area 429 .word cpu_arm922_dcache_clean_area
429 .word cpu_arm922_switch_mm 430 .word cpu_arm922_switch_mm
430 .word cpu_arm922_set_pte_ext 431 .word cpu_arm922_set_pte_ext
431 .word pabort_noifar
432 .size arm922_processor_functions, . - arm922_processor_functions 432 .size arm922_processor_functions, . - arm922_processor_functions
433 433
434 .section ".rodata" 434 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm925.S b/arch/arm/mm/proc-arm925.S
index e2988eba4cf6..065087afb772 100644
--- a/arch/arm/mm/proc-arm925.S
+++ b/arch/arm/mm/proc-arm925.S
@@ -484,6 +484,7 @@ arm925_crval:
484 .type arm925_processor_functions, #object 484 .type arm925_processor_functions, #object
485arm925_processor_functions: 485arm925_processor_functions:
486 .word v4t_early_abort 486 .word v4t_early_abort
487 .word pabort_noifar
487 .word cpu_arm925_proc_init 488 .word cpu_arm925_proc_init
488 .word cpu_arm925_proc_fin 489 .word cpu_arm925_proc_fin
489 .word cpu_arm925_reset 490 .word cpu_arm925_reset
@@ -491,7 +492,6 @@ arm925_processor_functions:
491 .word cpu_arm925_dcache_clean_area 492 .word cpu_arm925_dcache_clean_area
492 .word cpu_arm925_switch_mm 493 .word cpu_arm925_switch_mm
493 .word cpu_arm925_set_pte_ext 494 .word cpu_arm925_set_pte_ext
494 .word pabort_noifar
495 .size arm925_processor_functions, . - arm925_processor_functions 495 .size arm925_processor_functions, . - arm925_processor_functions
496 496
497 .section ".rodata" 497 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm926.S b/arch/arm/mm/proc-arm926.S
index 62f7d1dfe016..997db8472b5c 100644
--- a/arch/arm/mm/proc-arm926.S
+++ b/arch/arm/mm/proc-arm926.S
@@ -437,6 +437,7 @@ arm926_crval:
437 .type arm926_processor_functions, #object 437 .type arm926_processor_functions, #object
438arm926_processor_functions: 438arm926_processor_functions:
439 .word v5tj_early_abort 439 .word v5tj_early_abort
440 .word pabort_noifar
440 .word cpu_arm926_proc_init 441 .word cpu_arm926_proc_init
441 .word cpu_arm926_proc_fin 442 .word cpu_arm926_proc_fin
442 .word cpu_arm926_reset 443 .word cpu_arm926_reset
@@ -444,7 +445,6 @@ arm926_processor_functions:
444 .word cpu_arm926_dcache_clean_area 445 .word cpu_arm926_dcache_clean_area
445 .word cpu_arm926_switch_mm 446 .word cpu_arm926_switch_mm
446 .word cpu_arm926_set_pte_ext 447 .word cpu_arm926_set_pte_ext
447 .word pabort_noifar
448 .size arm926_processor_functions, . - arm926_processor_functions 448 .size arm926_processor_functions, . - arm926_processor_functions
449 449
450 .section ".rodata" 450 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm940.S b/arch/arm/mm/proc-arm940.S
index 786c593778f0..44ead902bd54 100644
--- a/arch/arm/mm/proc-arm940.S
+++ b/arch/arm/mm/proc-arm940.S
@@ -321,6 +321,7 @@ __arm940_setup:
321 .type arm940_processor_functions, #object 321 .type arm940_processor_functions, #object
322ENTRY(arm940_processor_functions) 322ENTRY(arm940_processor_functions)
323 .word nommu_early_abort 323 .word nommu_early_abort
324 .word pabort_noifar
324 .word cpu_arm940_proc_init 325 .word cpu_arm940_proc_init
325 .word cpu_arm940_proc_fin 326 .word cpu_arm940_proc_fin
326 .word cpu_arm940_reset 327 .word cpu_arm940_reset
diff --git a/arch/arm/mm/proc-arm946.S b/arch/arm/mm/proc-arm946.S
index a60c1421d450..2218b0c01330 100644
--- a/arch/arm/mm/proc-arm946.S
+++ b/arch/arm/mm/proc-arm946.S
@@ -376,6 +376,7 @@ __arm946_setup:
376 .type arm946_processor_functions, #object 376 .type arm946_processor_functions, #object
377ENTRY(arm946_processor_functions) 377ENTRY(arm946_processor_functions)
378 .word nommu_early_abort 378 .word nommu_early_abort
379 .word pabort_noifar
379 .word cpu_arm946_proc_init 380 .word cpu_arm946_proc_init
380 .word cpu_arm946_proc_fin 381 .word cpu_arm946_proc_fin
381 .word cpu_arm946_reset 382 .word cpu_arm946_reset
diff --git a/arch/arm/mm/proc-arm9tdmi.S b/arch/arm/mm/proc-arm9tdmi.S
index 4848eeac86b6..c85c1f50e396 100644
--- a/arch/arm/mm/proc-arm9tdmi.S
+++ b/arch/arm/mm/proc-arm9tdmi.S
@@ -64,6 +64,7 @@ __arm9tdmi_setup:
64 .type arm9tdmi_processor_functions, #object 64 .type arm9tdmi_processor_functions, #object
65ENTRY(arm9tdmi_processor_functions) 65ENTRY(arm9tdmi_processor_functions)
66 .word nommu_early_abort 66 .word nommu_early_abort
67 .word pabort_noifar
67 .word cpu_arm9tdmi_proc_init 68 .word cpu_arm9tdmi_proc_init
68 .word cpu_arm9tdmi_proc_fin 69 .word cpu_arm9tdmi_proc_fin
69 .word cpu_arm9tdmi_reset 70 .word cpu_arm9tdmi_reset
diff --git a/arch/arm/mm/proc-feroceon.S b/arch/arm/mm/proc-feroceon.S
index 2f169b28e938..90e7594e29b1 100644
--- a/arch/arm/mm/proc-feroceon.S
+++ b/arch/arm/mm/proc-feroceon.S
@@ -423,6 +423,7 @@ feroceon_crval:
423 .type feroceon_processor_functions, #object 423 .type feroceon_processor_functions, #object
424feroceon_processor_functions: 424feroceon_processor_functions:
425 .word v5t_early_abort 425 .word v5t_early_abort
426 .word pabort_noifar
426 .word cpu_feroceon_proc_init 427 .word cpu_feroceon_proc_init
427 .word cpu_feroceon_proc_fin 428 .word cpu_feroceon_proc_fin
428 .word cpu_feroceon_reset 429 .word cpu_feroceon_reset
@@ -430,7 +431,6 @@ feroceon_processor_functions:
430 .word cpu_feroceon_dcache_clean_area 431 .word cpu_feroceon_dcache_clean_area
431 .word cpu_feroceon_switch_mm 432 .word cpu_feroceon_switch_mm
432 .word cpu_feroceon_set_pte_ext 433 .word cpu_feroceon_set_pte_ext
433 .word pabort_noifar
434 .size feroceon_processor_functions, . - feroceon_processor_functions 434 .size feroceon_processor_functions, . - feroceon_processor_functions
435 435
436 .section ".rodata" 436 .section ".rodata"
diff --git a/arch/arm/mm/proc-sa110.S b/arch/arm/mm/proc-sa110.S
index 4db3d6299a2b..9818195dbf11 100644
--- a/arch/arm/mm/proc-sa110.S
+++ b/arch/arm/mm/proc-sa110.S
@@ -216,6 +216,7 @@ sa110_crval:
216 .type sa110_processor_functions, #object 216 .type sa110_processor_functions, #object
217ENTRY(sa110_processor_functions) 217ENTRY(sa110_processor_functions)
218 .word v4_early_abort 218 .word v4_early_abort
219 .word pabort_noifar
219 .word cpu_sa110_proc_init 220 .word cpu_sa110_proc_init
220 .word cpu_sa110_proc_fin 221 .word cpu_sa110_proc_fin
221 .word cpu_sa110_reset 222 .word cpu_sa110_reset
@@ -223,7 +224,6 @@ ENTRY(sa110_processor_functions)
223 .word cpu_sa110_dcache_clean_area 224 .word cpu_sa110_dcache_clean_area
224 .word cpu_sa110_switch_mm 225 .word cpu_sa110_switch_mm
225 .word cpu_sa110_set_pte_ext 226 .word cpu_sa110_set_pte_ext
226 .word pabort_noifar
227 .size sa110_processor_functions, . - sa110_processor_functions 227 .size sa110_processor_functions, . - sa110_processor_functions
228 228
229 .section ".rodata" 229 .section ".rodata"
diff --git a/arch/arm/mm/proc-sa1100.S b/arch/arm/mm/proc-sa1100.S
index 3cdef043760f..c5fe27ad2892 100644
--- a/arch/arm/mm/proc-sa1100.S
+++ b/arch/arm/mm/proc-sa1100.S
@@ -231,6 +231,7 @@ sa1100_crval:
231 .type sa1100_processor_functions, #object 231 .type sa1100_processor_functions, #object
232ENTRY(sa1100_processor_functions) 232ENTRY(sa1100_processor_functions)
233 .word v4_early_abort 233 .word v4_early_abort
234 .word pabort_noifar
234 .word cpu_sa1100_proc_init 235 .word cpu_sa1100_proc_init
235 .word cpu_sa1100_proc_fin 236 .word cpu_sa1100_proc_fin
236 .word cpu_sa1100_reset 237 .word cpu_sa1100_reset
@@ -238,7 +239,6 @@ ENTRY(sa1100_processor_functions)
238 .word cpu_sa1100_dcache_clean_area 239 .word cpu_sa1100_dcache_clean_area
239 .word cpu_sa1100_switch_mm 240 .word cpu_sa1100_switch_mm
240 .word cpu_sa1100_set_pte_ext 241 .word cpu_sa1100_set_pte_ext
241 .word pabort_noifar
242 .size sa1100_processor_functions, . - sa1100_processor_functions 242 .size sa1100_processor_functions, . - sa1100_processor_functions
243 243
244 .section ".rodata" 244 .section ".rodata"
diff --git a/arch/arm/mm/proc-v6.S b/arch/arm/mm/proc-v6.S
index bf760ea2f789..5702ec58b2a2 100644
--- a/arch/arm/mm/proc-v6.S
+++ b/arch/arm/mm/proc-v6.S
@@ -219,6 +219,7 @@ v6_crval:
219 .type v6_processor_functions, #object 219 .type v6_processor_functions, #object
220ENTRY(v6_processor_functions) 220ENTRY(v6_processor_functions)
221 .word v6_early_abort 221 .word v6_early_abort
222 .word pabort_noifar
222 .word cpu_v6_proc_init 223 .word cpu_v6_proc_init
223 .word cpu_v6_proc_fin 224 .word cpu_v6_proc_fin
224 .word cpu_v6_reset 225 .word cpu_v6_reset
@@ -226,7 +227,6 @@ ENTRY(v6_processor_functions)
226 .word cpu_v6_dcache_clean_area 227 .word cpu_v6_dcache_clean_area
227 .word cpu_v6_switch_mm 228 .word cpu_v6_switch_mm
228 .word cpu_v6_set_pte_ext 229 .word cpu_v6_set_pte_ext
229 .word pabort_noifar
230 .size v6_processor_functions, . - v6_processor_functions 230 .size v6_processor_functions, . - v6_processor_functions
231 231
232 .type cpu_arch_name, #object 232 .type cpu_arch_name, #object
diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S
index a1d7331cd64c..b49f9a4c82c8 100644
--- a/arch/arm/mm/proc-v7.S
+++ b/arch/arm/mm/proc-v7.S
@@ -205,6 +205,7 @@ __v7_setup_stack:
205 .type v7_processor_functions, #object 205 .type v7_processor_functions, #object
206ENTRY(v7_processor_functions) 206ENTRY(v7_processor_functions)
207 .word v7_early_abort 207 .word v7_early_abort
208 .word pabort_ifar
208 .word cpu_v7_proc_init 209 .word cpu_v7_proc_init
209 .word cpu_v7_proc_fin 210 .word cpu_v7_proc_fin
210 .word cpu_v7_reset 211 .word cpu_v7_reset
@@ -212,7 +213,6 @@ ENTRY(v7_processor_functions)
212 .word cpu_v7_dcache_clean_area 213 .word cpu_v7_dcache_clean_area
213 .word cpu_v7_switch_mm 214 .word cpu_v7_switch_mm
214 .word cpu_v7_set_pte_ext 215 .word cpu_v7_set_pte_ext
215 .word pabort_ifar
216 .size v7_processor_functions, . - v7_processor_functions 216 .size v7_processor_functions, . - v7_processor_functions
217 217
218 .type cpu_arch_name, #object 218 .type cpu_arch_name, #object
diff --git a/arch/arm/mm/proc-xsc3.S b/arch/arm/mm/proc-xsc3.S
index d95921a2ab99..3533741a76f6 100644
--- a/arch/arm/mm/proc-xsc3.S
+++ b/arch/arm/mm/proc-xsc3.S
@@ -450,6 +450,7 @@ xsc3_crval:
450 .type xsc3_processor_functions, #object 450 .type xsc3_processor_functions, #object
451ENTRY(xsc3_processor_functions) 451ENTRY(xsc3_processor_functions)
452 .word v5t_early_abort 452 .word v5t_early_abort
453 .word pabort_noifar
453 .word cpu_xsc3_proc_init 454 .word cpu_xsc3_proc_init
454 .word cpu_xsc3_proc_fin 455 .word cpu_xsc3_proc_fin
455 .word cpu_xsc3_reset 456 .word cpu_xsc3_reset
diff --git a/arch/arm/mm/proc-xscale.S b/arch/arm/mm/proc-xscale.S
index 1a6d89823dff..2dd85273976f 100644
--- a/arch/arm/mm/proc-xscale.S
+++ b/arch/arm/mm/proc-xscale.S
@@ -527,6 +527,7 @@ xscale_crval:
527 .type xscale_processor_functions, #object 527 .type xscale_processor_functions, #object
528ENTRY(xscale_processor_functions) 528ENTRY(xscale_processor_functions)
529 .word v5t_early_abort 529 .word v5t_early_abort
530 .word pabort_noifar
530 .word cpu_xscale_proc_init 531 .word cpu_xscale_proc_init
531 .word cpu_xscale_proc_fin 532 .word cpu_xscale_proc_fin
532 .word cpu_xscale_reset 533 .word cpu_xscale_reset
@@ -534,7 +535,6 @@ ENTRY(xscale_processor_functions)
534 .word cpu_xscale_dcache_clean_area 535 .word cpu_xscale_dcache_clean_area
535 .word cpu_xscale_switch_mm 536 .word cpu_xscale_switch_mm
536 .word cpu_xscale_set_pte_ext 537 .word cpu_xscale_set_pte_ext
537 .word pabort_noifar
538 .size xscale_processor_functions, . - xscale_processor_functions 538 .size xscale_processor_functions, . - xscale_processor_functions
539 539
540 .section ".rodata" 540 .section ".rodata"
diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
index ed21737a00c5..cd13e138bd03 100644
--- a/arch/ia64/Kconfig
+++ b/arch/ia64/Kconfig
@@ -266,17 +266,6 @@ config IOSAPIC
266 depends on !IA64_HP_SIM 266 depends on !IA64_HP_SIM
267 default y 267 default y
268 268
269config IA64_SGI_SN_XP
270 tristate "Support communication between SGI SSIs"
271 depends on IA64_GENERIC || IA64_SGI_SN2
272 select IA64_UNCACHED_ALLOCATOR
273 help
274 An SGI machine can be divided into multiple Single System
275 Images which act independently of each other and have
276 hardware based memory protection from the others. Enabling
277 this feature will allow for direct communication between SSIs
278 based on a network adapter and DMA messaging.
279
280config FORCE_MAX_ZONEORDER 269config FORCE_MAX_ZONEORDER
281 int "MAX_ORDER (11 - 17)" if !HUGETLB_PAGE 270 int "MAX_ORDER (11 - 17)" if !HUGETLB_PAGE
282 range 11 17 if !HUGETLB_PAGE 271 range 11 17 if !HUGETLB_PAGE
diff --git a/arch/ia64/kernel/crash.c b/arch/ia64/kernel/crash.c
index 90ef338cf46f..f065093f8e9b 100644
--- a/arch/ia64/kernel/crash.c
+++ b/arch/ia64/kernel/crash.c
@@ -194,8 +194,8 @@ kdump_init_notifier(struct notifier_block *self, unsigned long val, void *data)
194 unw_init_running(kdump_cpu_freeze, NULL); 194 unw_init_running(kdump_cpu_freeze, NULL);
195 break; 195 break;
196 case DIE_MCA_MONARCH_LEAVE: 196 case DIE_MCA_MONARCH_LEAVE:
197 /* die_register->signr indicate if MCA is recoverable */ 197 /* *(nd->data) indicate if MCA is recoverable */
198 if (kdump_on_fatal_mca && !args->signr) { 198 if (kdump_on_fatal_mca && !(*(nd->data))) {
199 atomic_set(&kdump_in_progress, 1); 199 atomic_set(&kdump_in_progress, 1);
200 *(nd->monarch_cpu) = -1; 200 *(nd->monarch_cpu) = -1;
201 machine_kdump_on_init(); 201 machine_kdump_on_init();
diff --git a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S
index b0be4a280174..e49ad8c5dc69 100644
--- a/arch/ia64/kernel/entry.S
+++ b/arch/ia64/kernel/entry.S
@@ -570,6 +570,7 @@ GLOBAL_ENTRY(ia64_trace_syscall)
570 br.call.sptk.many rp=syscall_trace_leave // give parent a chance to catch return value 570 br.call.sptk.many rp=syscall_trace_leave // give parent a chance to catch return value
571.ret3: 571.ret3:
572(pUStk) cmp.eq.unc p6,p0=r0,r0 // p6 <- pUStk 572(pUStk) cmp.eq.unc p6,p0=r0,r0 // p6 <- pUStk
573(pUStk) rsm psr.i // disable interrupts
573 br.cond.sptk .work_pending_syscall_end 574 br.cond.sptk .work_pending_syscall_end
574 575
575strace_error: 576strace_error:
diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
index e51bced3b0fa..705176b434b3 100644
--- a/arch/ia64/kernel/mca.c
+++ b/arch/ia64/kernel/mca.c
@@ -109,6 +109,20 @@
109# define IA64_MCA_DEBUG(fmt...) 109# define IA64_MCA_DEBUG(fmt...)
110#endif 110#endif
111 111
112#define NOTIFY_INIT(event, regs, arg, spin) \
113do { \
114 if ((notify_die((event), "INIT", (regs), (arg), 0, 0) \
115 == NOTIFY_STOP) && ((spin) == 1)) \
116 ia64_mca_spin(__func__); \
117} while (0)
118
119#define NOTIFY_MCA(event, regs, arg, spin) \
120do { \
121 if ((notify_die((event), "MCA", (regs), (arg), 0, 0) \
122 == NOTIFY_STOP) && ((spin) == 1)) \
123 ia64_mca_spin(__func__); \
124} while (0)
125
112/* Used by mca_asm.S */ 126/* Used by mca_asm.S */
113DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */ 127DEFINE_PER_CPU(u64, ia64_mca_data); /* == __per_cpu_mca[smp_processor_id()] */
114DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */ 128DEFINE_PER_CPU(u64, ia64_mca_per_cpu_pte); /* PTE to map per-CPU area */
@@ -766,9 +780,8 @@ ia64_mca_rendez_int_handler(int rendez_irq, void *arg)
766 780
767 /* Mask all interrupts */ 781 /* Mask all interrupts */
768 local_irq_save(flags); 782 local_irq_save(flags);
769 if (notify_die(DIE_MCA_RENDZVOUS_ENTER, "MCA", get_irq_regs(), 783
770 (long)&nd, 0, 0) == NOTIFY_STOP) 784 NOTIFY_MCA(DIE_MCA_RENDZVOUS_ENTER, get_irq_regs(), (long)&nd, 1);
771 ia64_mca_spin(__func__);
772 785
773 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE; 786 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_DONE;
774 /* Register with the SAL monarch that the slave has 787 /* Register with the SAL monarch that the slave has
@@ -776,17 +789,13 @@ ia64_mca_rendez_int_handler(int rendez_irq, void *arg)
776 */ 789 */
777 ia64_sal_mc_rendez(); 790 ia64_sal_mc_rendez();
778 791
779 if (notify_die(DIE_MCA_RENDZVOUS_PROCESS, "MCA", get_irq_regs(), 792 NOTIFY_MCA(DIE_MCA_RENDZVOUS_PROCESS, get_irq_regs(), (long)&nd, 1);
780 (long)&nd, 0, 0) == NOTIFY_STOP)
781 ia64_mca_spin(__func__);
782 793
783 /* Wait for the monarch cpu to exit. */ 794 /* Wait for the monarch cpu to exit. */
784 while (monarch_cpu != -1) 795 while (monarch_cpu != -1)
785 cpu_relax(); /* spin until monarch leaves */ 796 cpu_relax(); /* spin until monarch leaves */
786 797
787 if (notify_die(DIE_MCA_RENDZVOUS_LEAVE, "MCA", get_irq_regs(), 798 NOTIFY_MCA(DIE_MCA_RENDZVOUS_LEAVE, get_irq_regs(), (long)&nd, 1);
788 (long)&nd, 0, 0) == NOTIFY_STOP)
789 ia64_mca_spin(__func__);
790 799
791 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; 800 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
792 /* Enable all interrupts */ 801 /* Enable all interrupts */
@@ -1256,7 +1265,7 @@ ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
1256 int recover, cpu = smp_processor_id(); 1265 int recover, cpu = smp_processor_id();
1257 struct task_struct *previous_current; 1266 struct task_struct *previous_current;
1258 struct ia64_mca_notify_die nd = 1267 struct ia64_mca_notify_die nd =
1259 { .sos = sos, .monarch_cpu = &monarch_cpu }; 1268 { .sos = sos, .monarch_cpu = &monarch_cpu, .data = &recover };
1260 static atomic_t mca_count; 1269 static atomic_t mca_count;
1261 static cpumask_t mca_cpu; 1270 static cpumask_t mca_cpu;
1262 1271
@@ -1272,9 +1281,7 @@ ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
1272 1281
1273 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA"); 1282 previous_current = ia64_mca_modify_original_stack(regs, sw, sos, "MCA");
1274 1283
1275 if (notify_die(DIE_MCA_MONARCH_ENTER, "MCA", regs, (long)&nd, 0, 0) 1284 NOTIFY_MCA(DIE_MCA_MONARCH_ENTER, regs, (long)&nd, 1);
1276 == NOTIFY_STOP)
1277 ia64_mca_spin(__func__);
1278 1285
1279 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_CONCURRENT_MCA; 1286 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_CONCURRENT_MCA;
1280 if (sos->monarch) { 1287 if (sos->monarch) {
@@ -1288,13 +1295,12 @@ ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
1288 * does not work. 1295 * does not work.
1289 */ 1296 */
1290 ia64_mca_wakeup_all(); 1297 ia64_mca_wakeup_all();
1291 if (notify_die(DIE_MCA_MONARCH_PROCESS, "MCA", regs, (long)&nd, 0, 0)
1292 == NOTIFY_STOP)
1293 ia64_mca_spin(__func__);
1294 } else { 1298 } else {
1295 while (cpu_isset(cpu, mca_cpu)) 1299 while (cpu_isset(cpu, mca_cpu))
1296 cpu_relax(); /* spin until monarch wakes us */ 1300 cpu_relax(); /* spin until monarch wakes us */
1297 } 1301 }
1302
1303 NOTIFY_MCA(DIE_MCA_MONARCH_PROCESS, regs, (long)&nd, 1);
1298 1304
1299 /* Get the MCA error record and log it */ 1305 /* Get the MCA error record and log it */
1300 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA); 1306 ia64_mca_log_sal_error_record(SAL_INFO_TYPE_MCA);
@@ -1320,9 +1326,7 @@ ia64_mca_handler(struct pt_regs *regs, struct switch_stack *sw,
1320 mca_insert_tr(0x2); /*Reload dynamic itrs*/ 1326 mca_insert_tr(0x2); /*Reload dynamic itrs*/
1321 } 1327 }
1322 1328
1323 if (notify_die(DIE_MCA_MONARCH_LEAVE, "MCA", regs, (long)&nd, 0, recover) 1329 NOTIFY_MCA(DIE_MCA_MONARCH_LEAVE, regs, (long)&nd, 1);
1324 == NOTIFY_STOP)
1325 ia64_mca_spin(__func__);
1326 1330
1327 if (atomic_dec_return(&mca_count) > 0) { 1331 if (atomic_dec_return(&mca_count) > 0) {
1328 int i; 1332 int i;
@@ -1643,7 +1647,7 @@ ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
1643 struct ia64_mca_notify_die nd = 1647 struct ia64_mca_notify_die nd =
1644 { .sos = sos, .monarch_cpu = &monarch_cpu }; 1648 { .sos = sos, .monarch_cpu = &monarch_cpu };
1645 1649
1646 (void) notify_die(DIE_INIT_ENTER, "INIT", regs, (long)&nd, 0, 0); 1650 NOTIFY_INIT(DIE_INIT_ENTER, regs, (long)&nd, 0);
1647 1651
1648 mprintk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n", 1652 mprintk(KERN_INFO "Entered OS INIT handler. PSP=%lx cpu=%d monarch=%ld\n",
1649 sos->proc_state_param, cpu, sos->monarch); 1653 sos->proc_state_param, cpu, sos->monarch);
@@ -1680,17 +1684,15 @@ ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
1680 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT; 1684 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_INIT;
1681 while (monarch_cpu == -1) 1685 while (monarch_cpu == -1)
1682 cpu_relax(); /* spin until monarch enters */ 1686 cpu_relax(); /* spin until monarch enters */
1683 if (notify_die(DIE_INIT_SLAVE_ENTER, "INIT", regs, (long)&nd, 0, 0) 1687
1684 == NOTIFY_STOP) 1688 NOTIFY_INIT(DIE_INIT_SLAVE_ENTER, regs, (long)&nd, 1);
1685 ia64_mca_spin(__func__); 1689 NOTIFY_INIT(DIE_INIT_SLAVE_PROCESS, regs, (long)&nd, 1);
1686 if (notify_die(DIE_INIT_SLAVE_PROCESS, "INIT", regs, (long)&nd, 0, 0) 1690
1687 == NOTIFY_STOP)
1688 ia64_mca_spin(__func__);
1689 while (monarch_cpu != -1) 1691 while (monarch_cpu != -1)
1690 cpu_relax(); /* spin until monarch leaves */ 1692 cpu_relax(); /* spin until monarch leaves */
1691 if (notify_die(DIE_INIT_SLAVE_LEAVE, "INIT", regs, (long)&nd, 0, 0) 1693
1692 == NOTIFY_STOP) 1694 NOTIFY_INIT(DIE_INIT_SLAVE_LEAVE, regs, (long)&nd, 1);
1693 ia64_mca_spin(__func__); 1695
1694 mprintk("Slave on cpu %d returning to normal service.\n", cpu); 1696 mprintk("Slave on cpu %d returning to normal service.\n", cpu);
1695 set_curr_task(cpu, previous_current); 1697 set_curr_task(cpu, previous_current);
1696 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE; 1698 ia64_mc_info.imi_rendez_checkin[cpu] = IA64_MCA_RENDEZ_CHECKIN_NOTDONE;
@@ -1699,9 +1701,7 @@ ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
1699 } 1701 }
1700 1702
1701 monarch_cpu = cpu; 1703 monarch_cpu = cpu;
1702 if (notify_die(DIE_INIT_MONARCH_ENTER, "INIT", regs, (long)&nd, 0, 0) 1704 NOTIFY_INIT(DIE_INIT_MONARCH_ENTER, regs, (long)&nd, 1);
1703 == NOTIFY_STOP)
1704 ia64_mca_spin(__func__);
1705 1705
1706 /* 1706 /*
1707 * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be 1707 * Wait for a bit. On some machines (e.g., HP's zx2000 and zx6000, INIT can be
@@ -1716,12 +1716,9 @@ ia64_init_handler(struct pt_regs *regs, struct switch_stack *sw,
1716 * to default_monarch_init_process() above and just print all the 1716 * to default_monarch_init_process() above and just print all the
1717 * tasks. 1717 * tasks.
1718 */ 1718 */
1719 if (notify_die(DIE_INIT_MONARCH_PROCESS, "INIT", regs, (long)&nd, 0, 0) 1719 NOTIFY_INIT(DIE_INIT_MONARCH_PROCESS, regs, (long)&nd, 1);
1720 == NOTIFY_STOP) 1720 NOTIFY_INIT(DIE_INIT_MONARCH_LEAVE, regs, (long)&nd, 1);
1721 ia64_mca_spin(__func__); 1721
1722 if (notify_die(DIE_INIT_MONARCH_LEAVE, "INIT", regs, (long)&nd, 0, 0)
1723 == NOTIFY_STOP)
1724 ia64_mca_spin(__func__);
1725 mprintk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu); 1722 mprintk("\nINIT dump complete. Monarch on cpu %d returning to normal service.\n", cpu);
1726 atomic_dec(&monarchs); 1723 atomic_dec(&monarchs);
1727 set_curr_task(cpu, previous_current); 1724 set_curr_task(cpu, previous_current);
@@ -1953,7 +1950,7 @@ ia64_mca_init(void)
1953 printk(KERN_INFO "Increasing MCA rendezvous timeout from " 1950 printk(KERN_INFO "Increasing MCA rendezvous timeout from "
1954 "%ld to %ld milliseconds\n", timeout, isrv.v0); 1951 "%ld to %ld milliseconds\n", timeout, isrv.v0);
1955 timeout = isrv.v0; 1952 timeout = isrv.v0;
1956 (void) notify_die(DIE_MCA_NEW_TIMEOUT, "MCA", NULL, timeout, 0, 0); 1953 NOTIFY_MCA(DIE_MCA_NEW_TIMEOUT, NULL, timeout, 0);
1957 continue; 1954 continue;
1958 } 1955 }
1959 printk(KERN_ERR "Failed to register rendezvous interrupt " 1956 printk(KERN_ERR "Failed to register rendezvous interrupt "
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index d1d24f4598da..c8e403752a0c 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -5511,7 +5511,7 @@ stop_monitoring:
5511} 5511}
5512 5512
5513static int 5513static int
5514pfm_do_interrupt_handler(int irq, void *arg, struct pt_regs *regs) 5514pfm_do_interrupt_handler(void *arg, struct pt_regs *regs)
5515{ 5515{
5516 struct task_struct *task; 5516 struct task_struct *task;
5517 pfm_context_t *ctx; 5517 pfm_context_t *ctx;
@@ -5591,7 +5591,7 @@ pfm_interrupt_handler(int irq, void *arg)
5591 5591
5592 start_cycles = ia64_get_itc(); 5592 start_cycles = ia64_get_itc();
5593 5593
5594 ret = pfm_do_interrupt_handler(irq, arg, regs); 5594 ret = pfm_do_interrupt_handler(arg, regs);
5595 5595
5596 total_cycles = ia64_get_itc(); 5596 total_cycles = ia64_get_itc();
5597 5597
diff --git a/arch/ia64/sn/kernel/Makefile b/arch/ia64/sn/kernel/Makefile
index 688a3c27e0f6..0591038735af 100644
--- a/arch/ia64/sn/kernel/Makefile
+++ b/arch/ia64/sn/kernel/Makefile
@@ -4,7 +4,7 @@
4# License. See the file "COPYING" in the main directory of this archive 4# License. See the file "COPYING" in the main directory of this archive
5# for more details. 5# for more details.
6# 6#
7# Copyright (C) 1999,2001-2006 Silicon Graphics, Inc. All Rights Reserved. 7# Copyright (C) 1999,2001-2006,2008 Silicon Graphics, Inc. All Rights Reserved.
8# 8#
9 9
10EXTRA_CFLAGS += -Iarch/ia64/sn/include 10EXTRA_CFLAGS += -Iarch/ia64/sn/include
@@ -15,9 +15,4 @@ obj-y += setup.o bte.o bte_error.o irq.o mca.o idle.o \
15 sn2/ 15 sn2/
16obj-$(CONFIG_IA64_GENERIC) += machvec.o 16obj-$(CONFIG_IA64_GENERIC) += machvec.o
17obj-$(CONFIG_SGI_TIOCX) += tiocx.o 17obj-$(CONFIG_SGI_TIOCX) += tiocx.o
18obj-$(CONFIG_IA64_SGI_SN_XP) += xp.o
19xp-y := xp_main.o xp_nofault.o
20obj-$(CONFIG_IA64_SGI_SN_XP) += xpc.o
21xpc-y := xpc_main.o xpc_channel.o xpc_partition.o
22obj-$(CONFIG_IA64_SGI_SN_XP) += xpnet.o
23obj-$(CONFIG_PCI_MSI) += msi_sn.o 18obj-$(CONFIG_PCI_MSI) += msi_sn.o
diff --git a/arch/ia64/sn/kernel/huberror.c b/arch/ia64/sn/kernel/huberror.c
index 0101c7924a4d..08b0d9bb62ec 100644
--- a/arch/ia64/sn/kernel/huberror.c
+++ b/arch/ia64/sn/kernel/huberror.c
@@ -187,8 +187,8 @@ void hub_error_init(struct hubdev_info *hubdev_info)
187{ 187{
188 188
189 if (request_irq(SGI_II_ERROR, hub_eint_handler, IRQF_SHARED, 189 if (request_irq(SGI_II_ERROR, hub_eint_handler, IRQF_SHARED,
190 "SN_hub_error", (void *)hubdev_info)) { 190 "SN_hub_error", hubdev_info)) {
191 printk("hub_error_init: Failed to request_irq for 0x%p\n", 191 printk(KERN_ERR "hub_error_init: Failed to request_irq for 0x%p\n",
192 hubdev_info); 192 hubdev_info);
193 return; 193 return;
194 } 194 }
diff --git a/arch/ia64/sn/pci/tioce_provider.c b/arch/ia64/sn/pci/tioce_provider.c
index 9b3c11373022..94e584527f48 100644
--- a/arch/ia64/sn/pci/tioce_provider.c
+++ b/arch/ia64/sn/pci/tioce_provider.c
@@ -655,7 +655,8 @@ tioce_dma(struct pci_dev *pdev, u64 paddr, size_t byte_count, int dma_flags)
655 * 655 *
656 * Simply call tioce_do_dma_map() to create a map with the barrier bit set 656 * Simply call tioce_do_dma_map() to create a map with the barrier bit set
657 * in the address. 657 * in the address.
658 */ static u64 658 */
659static u64
659tioce_dma_consistent(struct pci_dev *pdev, u64 paddr, size_t byte_count, int dma_flags) 660tioce_dma_consistent(struct pci_dev *pdev, u64 paddr, size_t byte_count, int dma_flags)
660{ 661{
661 return tioce_do_dma_map(pdev, paddr, byte_count, 1, dma_flags); 662 return tioce_do_dma_map(pdev, paddr, byte_count, 1, dma_flags);
@@ -668,7 +669,8 @@ tioce_dma_consistent(struct pci_dev *pdev, u64 paddr, size_t byte_count, int dma
668 * 669 *
669 * Handle a CE error interrupt. Simply a wrapper around a SAL call which 670 * Handle a CE error interrupt. Simply a wrapper around a SAL call which
670 * defers processing to the SGI prom. 671 * defers processing to the SGI prom.
671 */ static irqreturn_t 672 */
673static irqreturn_t
672tioce_error_intr_handler(int irq, void *arg) 674tioce_error_intr_handler(int irq, void *arg)
673{ 675{
674 struct tioce_common *soft = arg; 676 struct tioce_common *soft = arg;
diff --git a/arch/sparc/kernel/entry.S b/arch/sparc/kernel/entry.S
index 135644f8add7..484c83d23eef 100644
--- a/arch/sparc/kernel/entry.S
+++ b/arch/sparc/kernel/entry.S
@@ -1409,7 +1409,6 @@ syscall_is_too_hard:
1409 1409
1410 st %o0, [%sp + STACKFRAME_SZ + PT_I0] 1410 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1411 1411
1412 .globl ret_sys_call
1413ret_sys_call: 1412ret_sys_call:
1414 ld [%curptr + TI_FLAGS], %l6 1413 ld [%curptr + TI_FLAGS], %l6
1415 cmp %o0, -ERESTART_RESTARTBLOCK 1414 cmp %o0, -ERESTART_RESTARTBLOCK
diff --git a/arch/sparc/kernel/signal.c b/arch/sparc/kernel/signal.c
index 1f730619a24a..3e849e8e3480 100644
--- a/arch/sparc/kernel/signal.c
+++ b/arch/sparc/kernel/signal.c
@@ -105,11 +105,6 @@ static int _sigpause_common(old_sigset_t set)
105 return -ERESTARTNOHAND; 105 return -ERESTARTNOHAND;
106} 106}
107 107
108asmlinkage int sys_sigpause(unsigned int set)
109{
110 return _sigpause_common(set);
111}
112
113asmlinkage int sys_sigsuspend(old_sigset_t set) 108asmlinkage int sys_sigsuspend(old_sigset_t set)
114{ 109{
115 return _sigpause_common(set); 110 return _sigpause_common(set);
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index df3eacb5ca15..8acc5cc38621 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -250,6 +250,26 @@ endchoice
250 250
251endmenu 251endmenu
252 252
253config NUMA
254 bool "NUMA support"
255
256config NODES_SHIFT
257 int
258 default "4"
259 depends on NEED_MULTIPLE_NODES
260
261# Some NUMA nodes have memory ranges that span
262# other nodes. Even though a pfn is valid and
263# between a node's start and end pfns, it may not
264# reside on that node. See memmap_init_zone()
265# for details.
266config NODES_SPAN_OTHER_NODES
267 def_bool y
268 depends on NEED_MULTIPLE_NODES
269
270config ARCH_POPULATES_NODE_MAP
271 def_bool y
272
253config ARCH_SELECT_MEMORY_MODEL 273config ARCH_SELECT_MEMORY_MODEL
254 def_bool y 274 def_bool y
255 275
diff --git a/arch/sparc64/defconfig b/arch/sparc64/defconfig
index e1835868ad36..92f79680f70d 100644
--- a/arch/sparc64/defconfig
+++ b/arch/sparc64/defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.25 3# Linux kernel version: 2.6.25-numa
4# Sun Apr 20 01:33:21 2008 4# Wed Apr 23 04:49:08 2008
5# 5#
6CONFIG_SPARC=y 6CONFIG_SPARC=y
7CONFIG_SPARC64=y 7CONFIG_SPARC64=y
@@ -152,6 +152,8 @@ CONFIG_GENERIC_CALIBRATE_DELAY=y
152CONFIG_HUGETLB_PAGE_SIZE_4MB=y 152CONFIG_HUGETLB_PAGE_SIZE_4MB=y
153# CONFIG_HUGETLB_PAGE_SIZE_512K is not set 153# CONFIG_HUGETLB_PAGE_SIZE_512K is not set
154# CONFIG_HUGETLB_PAGE_SIZE_64K is not set 154# CONFIG_HUGETLB_PAGE_SIZE_64K is not set
155# CONFIG_NUMA is not set
156CONFIG_ARCH_POPULATES_NODE_MAP=y
155CONFIG_ARCH_SELECT_MEMORY_MODEL=y 157CONFIG_ARCH_SELECT_MEMORY_MODEL=y
156CONFIG_ARCH_SPARSEMEM_ENABLE=y 158CONFIG_ARCH_SPARSEMEM_ENABLE=y
157CONFIG_ARCH_SPARSEMEM_DEFAULT=y 159CONFIG_ARCH_SPARSEMEM_DEFAULT=y
@@ -787,7 +789,6 @@ CONFIG_I2C_ALGOBIT=y
787# CONFIG_SENSORS_PCF8574 is not set 789# CONFIG_SENSORS_PCF8574 is not set
788# CONFIG_PCF8575 is not set 790# CONFIG_PCF8575 is not set
789# CONFIG_SENSORS_PCF8591 is not set 791# CONFIG_SENSORS_PCF8591 is not set
790# CONFIG_TPS65010 is not set
791# CONFIG_SENSORS_MAX6875 is not set 792# CONFIG_SENSORS_MAX6875 is not set
792# CONFIG_SENSORS_TSL2550 is not set 793# CONFIG_SENSORS_TSL2550 is not set
793# CONFIG_I2C_DEBUG_CORE is not set 794# CONFIG_I2C_DEBUG_CORE is not set
@@ -869,6 +870,7 @@ CONFIG_SSB_POSSIBLE=y
869# Multifunction device drivers 870# Multifunction device drivers
870# 871#
871# CONFIG_MFD_SM501 is not set 872# CONFIG_MFD_SM501 is not set
873# CONFIG_HTC_PASIC3 is not set
872 874
873# 875#
874# Multimedia devices 876# Multimedia devices
@@ -1219,10 +1221,6 @@ CONFIG_USB_STORAGE=m
1219# CONFIG_NEW_LEDS is not set 1221# CONFIG_NEW_LEDS is not set
1220# CONFIG_INFINIBAND is not set 1222# CONFIG_INFINIBAND is not set
1221# CONFIG_RTC_CLASS is not set 1223# CONFIG_RTC_CLASS is not set
1222
1223#
1224# Userspace I/O
1225#
1226# CONFIG_UIO is not set 1224# CONFIG_UIO is not set
1227 1225
1228# 1226#
@@ -1399,6 +1397,7 @@ CONFIG_SCHEDSTATS=y
1399CONFIG_DEBUG_BUGVERBOSE=y 1397CONFIG_DEBUG_BUGVERBOSE=y
1400# CONFIG_DEBUG_INFO is not set 1398# CONFIG_DEBUG_INFO is not set
1401# CONFIG_DEBUG_VM is not set 1399# CONFIG_DEBUG_VM is not set
1400# CONFIG_DEBUG_WRITECOUNT is not set
1402# CONFIG_DEBUG_LIST is not set 1401# CONFIG_DEBUG_LIST is not set
1403# CONFIG_DEBUG_SG is not set 1402# CONFIG_DEBUG_SG is not set
1404# CONFIG_BOOT_PRINTK_DELAY is not set 1403# CONFIG_BOOT_PRINTK_DELAY is not set
@@ -1425,53 +1424,82 @@ CONFIG_ASYNC_CORE=m
1425CONFIG_ASYNC_MEMCPY=m 1424CONFIG_ASYNC_MEMCPY=m
1426CONFIG_ASYNC_XOR=m 1425CONFIG_ASYNC_XOR=m
1427CONFIG_CRYPTO=y 1426CONFIG_CRYPTO=y
1427
1428#
1429# Crypto core or helper
1430#
1428CONFIG_CRYPTO_ALGAPI=y 1431CONFIG_CRYPTO_ALGAPI=y
1429CONFIG_CRYPTO_AEAD=y 1432CONFIG_CRYPTO_AEAD=y
1430CONFIG_CRYPTO_BLKCIPHER=y 1433CONFIG_CRYPTO_BLKCIPHER=y
1431# CONFIG_CRYPTO_SEQIV is not set
1432CONFIG_CRYPTO_HASH=y 1434CONFIG_CRYPTO_HASH=y
1433CONFIG_CRYPTO_MANAGER=y 1435CONFIG_CRYPTO_MANAGER=y
1436CONFIG_CRYPTO_GF128MUL=m
1437CONFIG_CRYPTO_NULL=m
1438# CONFIG_CRYPTO_CRYPTD is not set
1439CONFIG_CRYPTO_AUTHENC=y
1440CONFIG_CRYPTO_TEST=m
1441
1442#
1443# Authenticated Encryption with Associated Data
1444#
1445# CONFIG_CRYPTO_CCM is not set
1446# CONFIG_CRYPTO_GCM is not set
1447# CONFIG_CRYPTO_SEQIV is not set
1448
1449#
1450# Block modes
1451#
1452CONFIG_CRYPTO_CBC=y
1453# CONFIG_CRYPTO_CTR is not set
1454# CONFIG_CRYPTO_CTS is not set
1455CONFIG_CRYPTO_ECB=m
1456CONFIG_CRYPTO_LRW=m
1457CONFIG_CRYPTO_PCBC=m
1458CONFIG_CRYPTO_XTS=m
1459
1460#
1461# Hash modes
1462#
1434CONFIG_CRYPTO_HMAC=y 1463CONFIG_CRYPTO_HMAC=y
1435CONFIG_CRYPTO_XCBC=y 1464CONFIG_CRYPTO_XCBC=y
1436CONFIG_CRYPTO_NULL=m 1465
1466#
1467# Digest
1468#
1469CONFIG_CRYPTO_CRC32C=m
1437CONFIG_CRYPTO_MD4=y 1470CONFIG_CRYPTO_MD4=y
1438CONFIG_CRYPTO_MD5=y 1471CONFIG_CRYPTO_MD5=y
1472CONFIG_CRYPTO_MICHAEL_MIC=m
1439CONFIG_CRYPTO_SHA1=y 1473CONFIG_CRYPTO_SHA1=y
1440CONFIG_CRYPTO_SHA256=m 1474CONFIG_CRYPTO_SHA256=m
1441CONFIG_CRYPTO_SHA512=m 1475CONFIG_CRYPTO_SHA512=m
1442CONFIG_CRYPTO_WP512=m
1443CONFIG_CRYPTO_TGR192=m 1476CONFIG_CRYPTO_TGR192=m
1444CONFIG_CRYPTO_GF128MUL=m 1477CONFIG_CRYPTO_WP512=m
1445CONFIG_CRYPTO_ECB=m 1478
1446CONFIG_CRYPTO_CBC=y 1479#
1447CONFIG_CRYPTO_PCBC=m 1480# Ciphers
1448CONFIG_CRYPTO_LRW=m 1481#
1449CONFIG_CRYPTO_XTS=m
1450# CONFIG_CRYPTO_CTR is not set
1451# CONFIG_CRYPTO_GCM is not set
1452# CONFIG_CRYPTO_CCM is not set
1453# CONFIG_CRYPTO_CRYPTD is not set
1454CONFIG_CRYPTO_DES=y
1455CONFIG_CRYPTO_FCRYPT=m
1456CONFIG_CRYPTO_BLOWFISH=m
1457CONFIG_CRYPTO_TWOFISH=m
1458CONFIG_CRYPTO_TWOFISH_COMMON=m
1459CONFIG_CRYPTO_SERPENT=m
1460CONFIG_CRYPTO_AES=m 1482CONFIG_CRYPTO_AES=m
1483CONFIG_CRYPTO_ANUBIS=m
1484CONFIG_CRYPTO_ARC4=m
1485CONFIG_CRYPTO_BLOWFISH=m
1486CONFIG_CRYPTO_CAMELLIA=m
1461CONFIG_CRYPTO_CAST5=m 1487CONFIG_CRYPTO_CAST5=m
1462CONFIG_CRYPTO_CAST6=m 1488CONFIG_CRYPTO_CAST6=m
1463CONFIG_CRYPTO_TEA=m 1489CONFIG_CRYPTO_DES=y
1464CONFIG_CRYPTO_ARC4=m 1490CONFIG_CRYPTO_FCRYPT=m
1465CONFIG_CRYPTO_KHAZAD=m 1491CONFIG_CRYPTO_KHAZAD=m
1466CONFIG_CRYPTO_ANUBIS=m
1467CONFIG_CRYPTO_SEED=m
1468# CONFIG_CRYPTO_SALSA20 is not set 1492# CONFIG_CRYPTO_SALSA20 is not set
1493CONFIG_CRYPTO_SEED=m
1494CONFIG_CRYPTO_SERPENT=m
1495CONFIG_CRYPTO_TEA=m
1496CONFIG_CRYPTO_TWOFISH=m
1497CONFIG_CRYPTO_TWOFISH_COMMON=m
1498
1499#
1500# Compression
1501#
1469CONFIG_CRYPTO_DEFLATE=y 1502CONFIG_CRYPTO_DEFLATE=y
1470CONFIG_CRYPTO_MICHAEL_MIC=m
1471CONFIG_CRYPTO_CRC32C=m
1472CONFIG_CRYPTO_CAMELLIA=m
1473CONFIG_CRYPTO_TEST=m
1474CONFIG_CRYPTO_AUTHENC=y
1475# CONFIG_CRYPTO_LZO is not set 1503# CONFIG_CRYPTO_LZO is not set
1476CONFIG_CRYPTO_HW=y 1504CONFIG_CRYPTO_HW=y
1477# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1505# CONFIG_CRYPTO_DEV_HIFN_795X is not set
@@ -1492,3 +1520,4 @@ CONFIG_PLIST=y
1492CONFIG_HAS_IOMEM=y 1520CONFIG_HAS_IOMEM=y
1493CONFIG_HAS_IOPORT=y 1521CONFIG_HAS_IOPORT=y
1494CONFIG_HAS_DMA=y 1522CONFIG_HAS_DMA=y
1523CONFIG_HAVE_LMB=y
diff --git a/arch/sparc64/kernel/ebus.c b/arch/sparc64/kernel/ebus.c
index 04ab81cb4f48..bc2632274840 100644
--- a/arch/sparc64/kernel/ebus.c
+++ b/arch/sparc64/kernel/ebus.c
@@ -396,6 +396,7 @@ static void __init fill_ebus_device(struct device_node *dp, struct linux_ebus_de
396 sd->op = &dev->ofdev; 396 sd->op = &dev->ofdev;
397 sd->iommu = dev->bus->ofdev.dev.parent->archdata.iommu; 397 sd->iommu = dev->bus->ofdev.dev.parent->archdata.iommu;
398 sd->stc = dev->bus->ofdev.dev.parent->archdata.stc; 398 sd->stc = dev->bus->ofdev.dev.parent->archdata.stc;
399 sd->numa_node = dev->bus->ofdev.dev.parent->archdata.numa_node;
399 400
400 dev->ofdev.node = dp; 401 dev->ofdev.node = dp;
401 dev->ofdev.dev.parent = &dev->bus->ofdev.dev; 402 dev->ofdev.dev.parent = &dev->bus->ofdev.dev;
diff --git a/arch/sparc64/kernel/entry.S b/arch/sparc64/kernel/entry.S
index fb43c76bdc26..fd06e937ae1e 100644
--- a/arch/sparc64/kernel/entry.S
+++ b/arch/sparc64/kernel/entry.S
@@ -47,7 +47,7 @@ do_fpdis:
47 ba,pt %xcc, etrap 47 ba,pt %xcc, etrap
48109: or %g7, %lo(109b), %g7 48109: or %g7, %lo(109b), %g7
49 add %g0, %g0, %g0 49 add %g0, %g0, %g0
50 ba,a,pt %xcc, rtrap_clr_l6 50 ba,a,pt %xcc, rtrap
51 51
521: TRAP_LOAD_THREAD_REG(%g6, %g1) 521: TRAP_LOAD_THREAD_REG(%g6, %g1)
53 ldub [%g6 + TI_FPSAVED], %g5 53 ldub [%g6 + TI_FPSAVED], %g5
@@ -226,7 +226,7 @@ fp_other_bounce:
226 call do_fpother 226 call do_fpother
227 add %sp, PTREGS_OFF, %o0 227 add %sp, PTREGS_OFF, %o0
228 ba,pt %xcc, rtrap 228 ba,pt %xcc, rtrap
229 clr %l6 229 nop
230 230
231 .globl do_fpother_check_fitos 231 .globl do_fpother_check_fitos
232 .align 32 232 .align 32
@@ -489,7 +489,7 @@ utrap_trap: /* %g3=handler,%g4=level */
489 call bad_trap 489 call bad_trap
490 add %sp, PTREGS_OFF, %o0 490 add %sp, PTREGS_OFF, %o0
491 ba,pt %xcc, rtrap 491 ba,pt %xcc, rtrap
492 clr %l6 492 nop
493 493
494invoke_utrap: 494invoke_utrap:
495 sllx %g3, 3, %g3 495 sllx %g3, 3, %g3
@@ -607,7 +607,7 @@ __spitfire_cee_trap_continue:
607 call spitfire_access_error 607 call spitfire_access_error
608 add %sp, PTREGS_OFF, %o0 608 add %sp, PTREGS_OFF, %o0
609 ba,pt %xcc, rtrap 609 ba,pt %xcc, rtrap
610 clr %l6 610 nop
611 611
612 /* This is the trap handler entry point for ECC correctable 612 /* This is the trap handler entry point for ECC correctable
613 * errors. They are corrected, but we listen for the trap 613 * errors. They are corrected, but we listen for the trap
@@ -686,7 +686,7 @@ __spitfire_data_access_exception_tl1:
686 call spitfire_data_access_exception_tl1 686 call spitfire_data_access_exception_tl1
687 add %sp, PTREGS_OFF, %o0 687 add %sp, PTREGS_OFF, %o0
688 ba,pt %xcc, rtrap 688 ba,pt %xcc, rtrap
689 clr %l6 689 nop
690 690
691__spitfire_data_access_exception: 691__spitfire_data_access_exception:
692 rdpr %pstate, %g4 692 rdpr %pstate, %g4
@@ -705,7 +705,7 @@ __spitfire_data_access_exception:
705 call spitfire_data_access_exception 705 call spitfire_data_access_exception
706 add %sp, PTREGS_OFF, %o0 706 add %sp, PTREGS_OFF, %o0
707 ba,pt %xcc, rtrap 707 ba,pt %xcc, rtrap
708 clr %l6 708 nop
709 709
710 .globl __spitfire_insn_access_exception 710 .globl __spitfire_insn_access_exception
711 .globl __spitfire_insn_access_exception_tl1 711 .globl __spitfire_insn_access_exception_tl1
@@ -725,7 +725,7 @@ __spitfire_insn_access_exception_tl1:
725 call spitfire_insn_access_exception_tl1 725 call spitfire_insn_access_exception_tl1
726 add %sp, PTREGS_OFF, %o0 726 add %sp, PTREGS_OFF, %o0
727 ba,pt %xcc, rtrap 727 ba,pt %xcc, rtrap
728 clr %l6 728 nop
729 729
730__spitfire_insn_access_exception: 730__spitfire_insn_access_exception:
731 rdpr %pstate, %g4 731 rdpr %pstate, %g4
@@ -743,7 +743,7 @@ __spitfire_insn_access_exception:
743 call spitfire_insn_access_exception 743 call spitfire_insn_access_exception
744 add %sp, PTREGS_OFF, %o0 744 add %sp, PTREGS_OFF, %o0
745 ba,pt %xcc, rtrap 745 ba,pt %xcc, rtrap
746 clr %l6 746 nop
747 747
748 /* These get patched into the trap table at boot time 748 /* These get patched into the trap table at boot time
749 * once we know we have a cheetah processor. 749 * once we know we have a cheetah processor.
@@ -937,7 +937,7 @@ do_dcpe_tl1_fatal:
937 call cheetah_plus_parity_error 937 call cheetah_plus_parity_error
938 add %sp, PTREGS_OFF, %o1 938 add %sp, PTREGS_OFF, %o1
939 ba,pt %xcc, rtrap 939 ba,pt %xcc, rtrap
940 clr %l6 940 nop
941 941
942do_icpe_tl1: 942do_icpe_tl1:
943 rdpr %tl, %g1 ! Save original trap level 943 rdpr %tl, %g1 ! Save original trap level
@@ -979,7 +979,7 @@ do_icpe_tl1_fatal:
979 call cheetah_plus_parity_error 979 call cheetah_plus_parity_error
980 add %sp, PTREGS_OFF, %o1 980 add %sp, PTREGS_OFF, %o1
981 ba,pt %xcc, rtrap 981 ba,pt %xcc, rtrap
982 clr %l6 982 nop
983 983
984dcpe_icpe_tl1_common: 984dcpe_icpe_tl1_common:
985 /* Flush D-cache, re-enable D/I caches in DCU and finally 985 /* Flush D-cache, re-enable D/I caches in DCU and finally
@@ -1281,7 +1281,7 @@ __do_privact:
1281 call do_privact 1281 call do_privact
1282 add %sp, PTREGS_OFF, %o0 1282 add %sp, PTREGS_OFF, %o0
1283 ba,pt %xcc, rtrap 1283 ba,pt %xcc, rtrap
1284 clr %l6 1284 nop
1285 1285
1286 .globl do_mna 1286 .globl do_mna
1287do_mna: 1287do_mna:
@@ -1308,7 +1308,7 @@ do_mna:
1308 call mem_address_unaligned 1308 call mem_address_unaligned
1309 add %sp, PTREGS_OFF, %o0 1309 add %sp, PTREGS_OFF, %o0
1310 ba,pt %xcc, rtrap 1310 ba,pt %xcc, rtrap
1311 clr %l6 1311 nop
1312 1312
1313 .globl do_lddfmna 1313 .globl do_lddfmna
1314do_lddfmna: 1314do_lddfmna:
@@ -1326,7 +1326,7 @@ do_lddfmna:
1326 call handle_lddfmna 1326 call handle_lddfmna
1327 add %sp, PTREGS_OFF, %o0 1327 add %sp, PTREGS_OFF, %o0
1328 ba,pt %xcc, rtrap 1328 ba,pt %xcc, rtrap
1329 clr %l6 1329 nop
1330 1330
1331 .globl do_stdfmna 1331 .globl do_stdfmna
1332do_stdfmna: 1332do_stdfmna:
@@ -1344,7 +1344,7 @@ do_stdfmna:
1344 call handle_stdfmna 1344 call handle_stdfmna
1345 add %sp, PTREGS_OFF, %o0 1345 add %sp, PTREGS_OFF, %o0
1346 ba,pt %xcc, rtrap 1346 ba,pt %xcc, rtrap
1347 clr %l6 1347 nop
1348 1348
1349 .globl breakpoint_trap 1349 .globl breakpoint_trap
1350breakpoint_trap: 1350breakpoint_trap:
@@ -1424,13 +1424,13 @@ sys32_rt_sigreturn:
14241: ldx [%curptr + TI_FLAGS], %l5 14241: ldx [%curptr + TI_FLAGS], %l5
1425 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0 1425 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1426 be,pt %icc, rtrap 1426 be,pt %icc, rtrap
1427 clr %l6 1427 nop
1428 add %sp, PTREGS_OFF, %o0 1428 add %sp, PTREGS_OFF, %o0
1429 call syscall_trace 1429 call syscall_trace
1430 mov 1, %o1 1430 mov 1, %o1
1431 1431
1432 ba,pt %xcc, rtrap 1432 ba,pt %xcc, rtrap
1433 clr %l6 1433 nop
1434 1434
1435 /* This is how fork() was meant to be done, 8 instruction entry. 1435 /* This is how fork() was meant to be done, 8 instruction entry.
1436 * 1436 *
@@ -1559,7 +1559,7 @@ linux_sparc_syscall32:
1559 1559
1560 /* Linux native system calls enter here... */ 1560 /* Linux native system calls enter here... */
1561 .align 32 1561 .align 32
1562 .globl linux_sparc_syscall, ret_sys_call 1562 .globl linux_sparc_syscall
1563linux_sparc_syscall: 1563linux_sparc_syscall:
1564 /* Direct access to user regs, much faster. */ 1564 /* Direct access to user regs, much faster. */
1565 cmp %g1, NR_SYSCALLS ! IEU1 Group 1565 cmp %g1, NR_SYSCALLS ! IEU1 Group
@@ -1605,7 +1605,7 @@ ret_sys_call:
1605 bne,pn %icc, linux_syscall_trace2 1605 bne,pn %icc, linux_syscall_trace2
1606 add %l1, 0x4, %l2 ! npc = npc+4 1606 add %l1, 0x4, %l2 ! npc = npc+4
1607 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC] 1607 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1608 ba,pt %xcc, rtrap_clr_l6 1608 ba,pt %xcc, rtrap
1609 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC] 1609 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1610 1610
16111: 16111:
@@ -1616,7 +1616,6 @@ ret_sys_call:
1616 sub %g0, %o0, %o0 1616 sub %g0, %o0, %o0
1617 or %g3, %g2, %g3 1617 or %g3, %g2, %g3
1618 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0] 1618 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1619 mov 1, %l6
1620 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE] 1619 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1621 bne,pn %icc, linux_syscall_trace2 1620 bne,pn %icc, linux_syscall_trace2
1622 add %l1, 0x4, %l2 ! npc = npc+4 1621 add %l1, 0x4, %l2 ! npc = npc+4
diff --git a/arch/sparc64/kernel/entry.h b/arch/sparc64/kernel/entry.h
index 4a91e9c6d31b..32fbab620852 100644
--- a/arch/sparc64/kernel/entry.h
+++ b/arch/sparc64/kernel/entry.h
@@ -20,7 +20,6 @@ extern void timer_interrupt(int irq, struct pt_regs *regs);
20 20
21extern void do_notify_resume(struct pt_regs *regs, 21extern void do_notify_resume(struct pt_regs *regs,
22 unsigned long orig_i0, 22 unsigned long orig_i0,
23 int restart_syscall,
24 unsigned long thread_info_flags); 23 unsigned long thread_info_flags);
25 24
26extern asmlinkage void syscall_trace(struct pt_regs *regs, 25extern asmlinkage void syscall_trace(struct pt_regs *regs,
diff --git a/arch/sparc64/kernel/etrap.S b/arch/sparc64/kernel/etrap.S
index 4b2bf9eb447a..b49d3b60bc0c 100644
--- a/arch/sparc64/kernel/etrap.S
+++ b/arch/sparc64/kernel/etrap.S
@@ -53,7 +53,11 @@ etrap_irq:
53 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC] 53 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
54 rd %y, %g3 54 rd %y, %g3
55 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC] 55 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
56 rdpr %tt, %g1
56 st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y] 57 st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y]
58 sethi %hi(PT_REGS_MAGIC), %g3
59 or %g3, %g1, %g1
60 st %g1, [%g2 + STACKFRAME_SZ + PT_V9_MAGIC]
57 61
58 rdpr %cansave, %g1 62 rdpr %cansave, %g1
59 brnz,pt %g1, etrap_save 63 brnz,pt %g1, etrap_save
diff --git a/arch/sparc64/kernel/iommu.c b/arch/sparc64/kernel/iommu.c
index 756fa24eeefa..2a37a6ca2a16 100644
--- a/arch/sparc64/kernel/iommu.c
+++ b/arch/sparc64/kernel/iommu.c
@@ -173,9 +173,11 @@ void iommu_range_free(struct iommu *iommu, dma_addr_t dma_addr, unsigned long np
173} 173}
174 174
175int iommu_table_init(struct iommu *iommu, int tsbsize, 175int iommu_table_init(struct iommu *iommu, int tsbsize,
176 u32 dma_offset, u32 dma_addr_mask) 176 u32 dma_offset, u32 dma_addr_mask,
177 int numa_node)
177{ 178{
178 unsigned long i, tsbbase, order, sz, num_tsb_entries; 179 unsigned long i, order, sz, num_tsb_entries;
180 struct page *page;
179 181
180 num_tsb_entries = tsbsize / sizeof(iopte_t); 182 num_tsb_entries = tsbsize / sizeof(iopte_t);
181 183
@@ -188,11 +190,12 @@ int iommu_table_init(struct iommu *iommu, int tsbsize,
188 /* Allocate and initialize the free area map. */ 190 /* Allocate and initialize the free area map. */
189 sz = num_tsb_entries / 8; 191 sz = num_tsb_entries / 8;
190 sz = (sz + 7UL) & ~7UL; 192 sz = (sz + 7UL) & ~7UL;
191 iommu->arena.map = kzalloc(sz, GFP_KERNEL); 193 iommu->arena.map = kmalloc_node(sz, GFP_KERNEL, numa_node);
192 if (!iommu->arena.map) { 194 if (!iommu->arena.map) {
193 printk(KERN_ERR "IOMMU: Error, kmalloc(arena.map) failed.\n"); 195 printk(KERN_ERR "IOMMU: Error, kmalloc(arena.map) failed.\n");
194 return -ENOMEM; 196 return -ENOMEM;
195 } 197 }
198 memset(iommu->arena.map, 0, sz);
196 iommu->arena.limit = num_tsb_entries; 199 iommu->arena.limit = num_tsb_entries;
197 200
198 if (tlb_type != hypervisor) 201 if (tlb_type != hypervisor)
@@ -201,21 +204,23 @@ int iommu_table_init(struct iommu *iommu, int tsbsize,
201 /* Allocate and initialize the dummy page which we 204 /* Allocate and initialize the dummy page which we
202 * set inactive IO PTEs to point to. 205 * set inactive IO PTEs to point to.
203 */ 206 */
204 iommu->dummy_page = get_zeroed_page(GFP_KERNEL); 207 page = alloc_pages_node(numa_node, GFP_KERNEL, 0);
205 if (!iommu->dummy_page) { 208 if (!page) {
206 printk(KERN_ERR "IOMMU: Error, gfp(dummy_page) failed.\n"); 209 printk(KERN_ERR "IOMMU: Error, gfp(dummy_page) failed.\n");
207 goto out_free_map; 210 goto out_free_map;
208 } 211 }
212 iommu->dummy_page = (unsigned long) page_address(page);
213 memset((void *)iommu->dummy_page, 0, PAGE_SIZE);
209 iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page); 214 iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page);
210 215
211 /* Now allocate and setup the IOMMU page table itself. */ 216 /* Now allocate and setup the IOMMU page table itself. */
212 order = get_order(tsbsize); 217 order = get_order(tsbsize);
213 tsbbase = __get_free_pages(GFP_KERNEL, order); 218 page = alloc_pages_node(numa_node, GFP_KERNEL, order);
214 if (!tsbbase) { 219 if (!page) {
215 printk(KERN_ERR "IOMMU: Error, gfp(tsb) failed.\n"); 220 printk(KERN_ERR "IOMMU: Error, gfp(tsb) failed.\n");
216 goto out_free_dummy_page; 221 goto out_free_dummy_page;
217 } 222 }
218 iommu->page_table = (iopte_t *)tsbbase; 223 iommu->page_table = (iopte_t *)page_address(page);
219 224
220 for (i = 0; i < num_tsb_entries; i++) 225 for (i = 0; i < num_tsb_entries; i++)
221 iopte_make_dummy(iommu, &iommu->page_table[i]); 226 iopte_make_dummy(iommu, &iommu->page_table[i]);
@@ -276,20 +281,24 @@ static inline void iommu_free_ctx(struct iommu *iommu, int ctx)
276static void *dma_4u_alloc_coherent(struct device *dev, size_t size, 281static void *dma_4u_alloc_coherent(struct device *dev, size_t size,
277 dma_addr_t *dma_addrp, gfp_t gfp) 282 dma_addr_t *dma_addrp, gfp_t gfp)
278{ 283{
284 unsigned long flags, order, first_page;
279 struct iommu *iommu; 285 struct iommu *iommu;
286 struct page *page;
287 int npages, nid;
280 iopte_t *iopte; 288 iopte_t *iopte;
281 unsigned long flags, order, first_page;
282 void *ret; 289 void *ret;
283 int npages;
284 290
285 size = IO_PAGE_ALIGN(size); 291 size = IO_PAGE_ALIGN(size);
286 order = get_order(size); 292 order = get_order(size);
287 if (order >= 10) 293 if (order >= 10)
288 return NULL; 294 return NULL;
289 295
290 first_page = __get_free_pages(gfp, order); 296 nid = dev->archdata.numa_node;
291 if (first_page == 0UL) 297 page = alloc_pages_node(nid, gfp, order);
298 if (unlikely(!page))
292 return NULL; 299 return NULL;
300
301 first_page = (unsigned long) page_address(page);
293 memset((char *)first_page, 0, PAGE_SIZE << order); 302 memset((char *)first_page, 0, PAGE_SIZE << order);
294 303
295 iommu = dev->archdata.iommu; 304 iommu = dev->archdata.iommu;
diff --git a/arch/sparc64/kernel/isa.c b/arch/sparc64/kernel/isa.c
index b5f7b354084f..a2af5ed784c9 100644
--- a/arch/sparc64/kernel/isa.c
+++ b/arch/sparc64/kernel/isa.c
@@ -92,6 +92,7 @@ static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
92 sd->op = &isa_dev->ofdev; 92 sd->op = &isa_dev->ofdev;
93 sd->iommu = isa_br->ofdev.dev.parent->archdata.iommu; 93 sd->iommu = isa_br->ofdev.dev.parent->archdata.iommu;
94 sd->stc = isa_br->ofdev.dev.parent->archdata.stc; 94 sd->stc = isa_br->ofdev.dev.parent->archdata.stc;
95 sd->numa_node = isa_br->ofdev.dev.parent->archdata.numa_node;
95 96
96 isa_dev->ofdev.node = dp; 97 isa_dev->ofdev.node = dp;
97 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev; 98 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
diff --git a/arch/sparc64/kernel/mdesc.c b/arch/sparc64/kernel/mdesc.c
index 910083589569..dde52bcf5c64 100644
--- a/arch/sparc64/kernel/mdesc.c
+++ b/arch/sparc64/kernel/mdesc.c
@@ -1,10 +1,10 @@
1/* mdesc.c: Sun4V machine description handling. 1/* mdesc.c: Sun4V machine description handling.
2 * 2 *
3 * Copyright (C) 2007 David S. Miller <davem@davemloft.net> 3 * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
4 */ 4 */
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/types.h> 6#include <linux/types.h>
7#include <linux/bootmem.h> 7#include <linux/lmb.h>
8#include <linux/log2.h> 8#include <linux/log2.h>
9#include <linux/list.h> 9#include <linux/list.h>
10#include <linux/slab.h> 10#include <linux/slab.h>
@@ -84,24 +84,28 @@ static void mdesc_handle_init(struct mdesc_handle *hp,
84 hp->handle_size = handle_size; 84 hp->handle_size = handle_size;
85} 85}
86 86
87static struct mdesc_handle * __init mdesc_bootmem_alloc(unsigned int mdesc_size) 87static struct mdesc_handle * __init mdesc_lmb_alloc(unsigned int mdesc_size)
88{ 88{
89 struct mdesc_handle *hp;
90 unsigned int handle_size, alloc_size; 89 unsigned int handle_size, alloc_size;
90 struct mdesc_handle *hp;
91 unsigned long paddr;
91 92
92 handle_size = (sizeof(struct mdesc_handle) - 93 handle_size = (sizeof(struct mdesc_handle) -
93 sizeof(struct mdesc_hdr) + 94 sizeof(struct mdesc_hdr) +
94 mdesc_size); 95 mdesc_size);
95 alloc_size = PAGE_ALIGN(handle_size); 96 alloc_size = PAGE_ALIGN(handle_size);
96 97
97 hp = __alloc_bootmem(alloc_size, PAGE_SIZE, 0UL); 98 paddr = lmb_alloc(alloc_size, PAGE_SIZE);
98 if (hp)
99 mdesc_handle_init(hp, handle_size, hp);
100 99
100 hp = NULL;
101 if (paddr) {
102 hp = __va(paddr);
103 mdesc_handle_init(hp, handle_size, hp);
104 }
101 return hp; 105 return hp;
102} 106}
103 107
104static void mdesc_bootmem_free(struct mdesc_handle *hp) 108static void mdesc_lmb_free(struct mdesc_handle *hp)
105{ 109{
106 unsigned int alloc_size, handle_size = hp->handle_size; 110 unsigned int alloc_size, handle_size = hp->handle_size;
107 unsigned long start, end; 111 unsigned long start, end;
@@ -124,9 +128,9 @@ static void mdesc_bootmem_free(struct mdesc_handle *hp)
124 } 128 }
125} 129}
126 130
127static struct mdesc_mem_ops bootmem_mdesc_ops = { 131static struct mdesc_mem_ops lmb_mdesc_ops = {
128 .alloc = mdesc_bootmem_alloc, 132 .alloc = mdesc_lmb_alloc,
129 .free = mdesc_bootmem_free, 133 .free = mdesc_lmb_free,
130}; 134};
131 135
132static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size) 136static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
@@ -888,7 +892,7 @@ void __init sun4v_mdesc_init(void)
888 892
889 printk("MDESC: Size is %lu bytes.\n", len); 893 printk("MDESC: Size is %lu bytes.\n", len);
890 894
891 hp = mdesc_alloc(len, &bootmem_mdesc_ops); 895 hp = mdesc_alloc(len, &lmb_mdesc_ops);
892 if (hp == NULL) { 896 if (hp == NULL) {
893 prom_printf("MDESC: alloc of %lu bytes failed.\n", len); 897 prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
894 prom_halt(); 898 prom_halt();
diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c
index 0fd9db95b896..9e58e8cba1c3 100644
--- a/arch/sparc64/kernel/of_device.c
+++ b/arch/sparc64/kernel/of_device.c
@@ -6,6 +6,7 @@
6#include <linux/mod_devicetable.h> 6#include <linux/mod_devicetable.h>
7#include <linux/slab.h> 7#include <linux/slab.h>
8#include <linux/errno.h> 8#include <linux/errno.h>
9#include <linux/irq.h>
9#include <linux/of_device.h> 10#include <linux/of_device.h>
10#include <linux/of_platform.h> 11#include <linux/of_platform.h>
11 12
@@ -660,6 +661,7 @@ static unsigned int __init build_one_device_irq(struct of_device *op,
660 struct device_node *dp = op->node; 661 struct device_node *dp = op->node;
661 struct device_node *pp, *ip; 662 struct device_node *pp, *ip;
662 unsigned int orig_irq = irq; 663 unsigned int orig_irq = irq;
664 int nid;
663 665
664 if (irq == 0xffffffff) 666 if (irq == 0xffffffff)
665 return irq; 667 return irq;
@@ -672,7 +674,7 @@ static unsigned int __init build_one_device_irq(struct of_device *op,
672 printk("%s: direct translate %x --> %x\n", 674 printk("%s: direct translate %x --> %x\n",
673 dp->full_name, orig_irq, irq); 675 dp->full_name, orig_irq, irq);
674 676
675 return irq; 677 goto out;
676 } 678 }
677 679
678 /* Something more complicated. Walk up to the root, applying 680 /* Something more complicated. Walk up to the root, applying
@@ -744,6 +746,14 @@ static unsigned int __init build_one_device_irq(struct of_device *op,
744 printk("%s: Apply IRQ trans [%s] %x --> %x\n", 746 printk("%s: Apply IRQ trans [%s] %x --> %x\n",
745 op->node->full_name, ip->full_name, orig_irq, irq); 747 op->node->full_name, ip->full_name, orig_irq, irq);
746 748
749out:
750 nid = of_node_to_nid(dp);
751 if (nid != -1) {
752 cpumask_t numa_mask = node_to_cpumask(nid);
753
754 irq_set_affinity(irq, numa_mask);
755 }
756
747 return irq; 757 return irq;
748} 758}
749 759
diff --git a/arch/sparc64/kernel/pci.c b/arch/sparc64/kernel/pci.c
index 545356b00e2e..49f912766519 100644
--- a/arch/sparc64/kernel/pci.c
+++ b/arch/sparc64/kernel/pci.c
@@ -369,10 +369,12 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
369 sd->host_controller = pbm; 369 sd->host_controller = pbm;
370 sd->prom_node = node; 370 sd->prom_node = node;
371 sd->op = of_find_device_by_node(node); 371 sd->op = of_find_device_by_node(node);
372 sd->numa_node = pbm->numa_node;
372 373
373 sd = &sd->op->dev.archdata; 374 sd = &sd->op->dev.archdata;
374 sd->iommu = pbm->iommu; 375 sd->iommu = pbm->iommu;
375 sd->stc = &pbm->stc; 376 sd->stc = &pbm->stc;
377 sd->numa_node = pbm->numa_node;
376 378
377 type = of_get_property(node, "device_type", NULL); 379 type = of_get_property(node, "device_type", NULL);
378 if (type == NULL) 380 if (type == NULL)
@@ -1159,6 +1161,16 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
1159 return 0; 1161 return 0;
1160} 1162}
1161 1163
1164#ifdef CONFIG_NUMA
1165int pcibus_to_node(struct pci_bus *pbus)
1166{
1167 struct pci_pbm_info *pbm = pbus->sysdata;
1168
1169 return pbm->numa_node;
1170}
1171EXPORT_SYMBOL(pcibus_to_node);
1172#endif
1173
1162/* Return the domain nuber for this pci bus */ 1174/* Return the domain nuber for this pci bus */
1163 1175
1164int pci_domain_nr(struct pci_bus *pbus) 1176int pci_domain_nr(struct pci_bus *pbus)
diff --git a/arch/sparc64/kernel/pci_fire.c b/arch/sparc64/kernel/pci_fire.c
index 7571ed563147..d23bb6f53cda 100644
--- a/arch/sparc64/kernel/pci_fire.c
+++ b/arch/sparc64/kernel/pci_fire.c
@@ -71,7 +71,8 @@ static int pci_fire_pbm_iommu_init(struct pci_pbm_info *pbm)
71 */ 71 */
72 fire_write(iommu->iommu_flushinv, ~(u64)0); 72 fire_write(iommu->iommu_flushinv, ~(u64)0);
73 73
74 err = iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask); 74 err = iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask,
75 pbm->numa_node);
75 if (err) 76 if (err)
76 return err; 77 return err;
77 78
@@ -449,6 +450,8 @@ static int __init pci_fire_pbm_init(struct pci_controller_info *p,
449 pbm->next = pci_pbm_root; 450 pbm->next = pci_pbm_root;
450 pci_pbm_root = pbm; 451 pci_pbm_root = pbm;
451 452
453 pbm->numa_node = -1;
454
452 pbm->scan_bus = pci_fire_scan_bus; 455 pbm->scan_bus = pci_fire_scan_bus;
453 pbm->pci_ops = &sun4u_pci_ops; 456 pbm->pci_ops = &sun4u_pci_ops;
454 pbm->config_space_reg_bits = 12; 457 pbm->config_space_reg_bits = 12;
diff --git a/arch/sparc64/kernel/pci_impl.h b/arch/sparc64/kernel/pci_impl.h
index 4a50da13ce48..218bac4ff79b 100644
--- a/arch/sparc64/kernel/pci_impl.h
+++ b/arch/sparc64/kernel/pci_impl.h
@@ -148,6 +148,8 @@ struct pci_pbm_info {
148 struct pci_bus *pci_bus; 148 struct pci_bus *pci_bus;
149 void (*scan_bus)(struct pci_pbm_info *); 149 void (*scan_bus)(struct pci_pbm_info *);
150 struct pci_ops *pci_ops; 150 struct pci_ops *pci_ops;
151
152 int numa_node;
151}; 153};
152 154
153struct pci_controller_info { 155struct pci_controller_info {
@@ -161,8 +163,6 @@ extern struct pci_pbm_info *pci_pbm_root;
161extern int pci_num_pbms; 163extern int pci_num_pbms;
162 164
163/* PCI bus scanning and fixup support. */ 165/* PCI bus scanning and fixup support. */
164extern void pci_iommu_table_init(struct iommu *iommu, int tsbsize,
165 u32 dma_offset, u32 dma_addr_mask);
166extern void pci_get_pbm_props(struct pci_pbm_info *pbm); 166extern void pci_get_pbm_props(struct pci_pbm_info *pbm);
167extern struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm); 167extern struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm);
168extern void pci_determine_mem_io_space(struct pci_pbm_info *pbm); 168extern void pci_determine_mem_io_space(struct pci_pbm_info *pbm);
diff --git a/arch/sparc64/kernel/pci_msi.c b/arch/sparc64/kernel/pci_msi.c
index d6d64b44af63..db5e8fd8f674 100644
--- a/arch/sparc64/kernel/pci_msi.c
+++ b/arch/sparc64/kernel/pci_msi.c
@@ -279,11 +279,17 @@ static int bringup_one_msi_queue(struct pci_pbm_info *pbm,
279 unsigned long devino) 279 unsigned long devino)
280{ 280{
281 int irq = ops->msiq_build_irq(pbm, msiqid, devino); 281 int irq = ops->msiq_build_irq(pbm, msiqid, devino);
282 int err; 282 int err, nid;
283 283
284 if (irq < 0) 284 if (irq < 0)
285 return irq; 285 return irq;
286 286
287 nid = pbm->numa_node;
288 if (nid != -1) {
289 cpumask_t numa_mask = node_to_cpumask(nid);
290
291 irq_set_affinity(irq, numa_mask);
292 }
287 err = request_irq(irq, sparc64_msiq_interrupt, 0, 293 err = request_irq(irq, sparc64_msiq_interrupt, 0,
288 "MSIQ", 294 "MSIQ",
289 &pbm->msiq_irq_cookies[msiqid - pbm->msiq_first]); 295 &pbm->msiq_irq_cookies[msiqid - pbm->msiq_first]);
diff --git a/arch/sparc64/kernel/pci_psycho.c b/arch/sparc64/kernel/pci_psycho.c
index 0bad96e5d184..994dbe0603da 100644
--- a/arch/sparc64/kernel/pci_psycho.c
+++ b/arch/sparc64/kernel/pci_psycho.c
@@ -848,7 +848,8 @@ static int psycho_iommu_init(struct pci_pbm_info *pbm)
848 /* Leave diag mode enabled for full-flushing done 848 /* Leave diag mode enabled for full-flushing done
849 * in pci_iommu.c 849 * in pci_iommu.c
850 */ 850 */
851 err = iommu_table_init(iommu, IO_TSB_SIZE, 0xc0000000, 0xffffffff); 851 err = iommu_table_init(iommu, IO_TSB_SIZE, 0xc0000000, 0xffffffff,
852 pbm->numa_node);
852 if (err) 853 if (err)
853 return err; 854 return err;
854 855
@@ -979,6 +980,8 @@ static void __init psycho_pbm_init(struct pci_controller_info *p,
979 pbm->next = pci_pbm_root; 980 pbm->next = pci_pbm_root;
980 pci_pbm_root = pbm; 981 pci_pbm_root = pbm;
981 982
983 pbm->numa_node = -1;
984
982 pbm->scan_bus = psycho_scan_bus; 985 pbm->scan_bus = psycho_scan_bus;
983 pbm->pci_ops = &sun4u_pci_ops; 986 pbm->pci_ops = &sun4u_pci_ops;
984 pbm->config_space_reg_bits = 8; 987 pbm->config_space_reg_bits = 8;
diff --git a/arch/sparc64/kernel/pci_sabre.c b/arch/sparc64/kernel/pci_sabre.c
index 1c5f5fa2339f..4c34195baf37 100644
--- a/arch/sparc64/kernel/pci_sabre.c
+++ b/arch/sparc64/kernel/pci_sabre.c
@@ -704,7 +704,7 @@ static int sabre_iommu_init(struct pci_pbm_info *pbm,
704 * in pci_iommu.c 704 * in pci_iommu.c
705 */ 705 */
706 err = iommu_table_init(iommu, tsbsize * 1024 * 8, 706 err = iommu_table_init(iommu, tsbsize * 1024 * 8,
707 dvma_offset, dma_mask); 707 dvma_offset, dma_mask, pbm->numa_node);
708 if (err) 708 if (err)
709 return err; 709 return err;
710 710
@@ -737,6 +737,8 @@ static void __init sabre_pbm_init(struct pci_controller_info *p,
737 pbm->name = dp->full_name; 737 pbm->name = dp->full_name;
738 printk("%s: SABRE PCI Bus Module\n", pbm->name); 738 printk("%s: SABRE PCI Bus Module\n", pbm->name);
739 739
740 pbm->numa_node = -1;
741
740 pbm->scan_bus = sabre_scan_bus; 742 pbm->scan_bus = sabre_scan_bus;
741 pbm->pci_ops = &sun4u_pci_ops; 743 pbm->pci_ops = &sun4u_pci_ops;
742 pbm->config_space_reg_bits = 8; 744 pbm->config_space_reg_bits = 8;
diff --git a/arch/sparc64/kernel/pci_schizo.c b/arch/sparc64/kernel/pci_schizo.c
index e30609362322..615edd9c8e2a 100644
--- a/arch/sparc64/kernel/pci_schizo.c
+++ b/arch/sparc64/kernel/pci_schizo.c
@@ -1220,7 +1220,8 @@ static int schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
1220 /* Leave diag mode enabled for full-flushing done 1220 /* Leave diag mode enabled for full-flushing done
1221 * in pci_iommu.c 1221 * in pci_iommu.c
1222 */ 1222 */
1223 err = iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask); 1223 err = iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask,
1224 pbm->numa_node);
1224 if (err) 1225 if (err)
1225 return err; 1226 return err;
1226 1227
@@ -1379,6 +1380,8 @@ static int __init schizo_pbm_init(struct pci_controller_info *p,
1379 pbm->next = pci_pbm_root; 1380 pbm->next = pci_pbm_root;
1380 pci_pbm_root = pbm; 1381 pci_pbm_root = pbm;
1381 1382
1383 pbm->numa_node = -1;
1384
1382 pbm->scan_bus = schizo_scan_bus; 1385 pbm->scan_bus = schizo_scan_bus;
1383 pbm->pci_ops = &sun4u_pci_ops; 1386 pbm->pci_ops = &sun4u_pci_ops;
1384 pbm->config_space_reg_bits = 8; 1387 pbm->config_space_reg_bits = 8;
diff --git a/arch/sparc64/kernel/pci_sun4v.c b/arch/sparc64/kernel/pci_sun4v.c
index 01839706bd52..e2bb9790039c 100644
--- a/arch/sparc64/kernel/pci_sun4v.c
+++ b/arch/sparc64/kernel/pci_sun4v.c
@@ -127,10 +127,12 @@ static inline long iommu_batch_end(void)
127static void *dma_4v_alloc_coherent(struct device *dev, size_t size, 127static void *dma_4v_alloc_coherent(struct device *dev, size_t size,
128 dma_addr_t *dma_addrp, gfp_t gfp) 128 dma_addr_t *dma_addrp, gfp_t gfp)
129{ 129{
130 struct iommu *iommu;
131 unsigned long flags, order, first_page, npages, n; 130 unsigned long flags, order, first_page, npages, n;
131 struct iommu *iommu;
132 struct page *page;
132 void *ret; 133 void *ret;
133 long entry; 134 long entry;
135 int nid;
134 136
135 size = IO_PAGE_ALIGN(size); 137 size = IO_PAGE_ALIGN(size);
136 order = get_order(size); 138 order = get_order(size);
@@ -139,10 +141,12 @@ static void *dma_4v_alloc_coherent(struct device *dev, size_t size,
139 141
140 npages = size >> IO_PAGE_SHIFT; 142 npages = size >> IO_PAGE_SHIFT;
141 143
142 first_page = __get_free_pages(gfp, order); 144 nid = dev->archdata.numa_node;
143 if (unlikely(first_page == 0UL)) 145 page = alloc_pages_node(nid, gfp, order);
146 if (unlikely(!page))
144 return NULL; 147 return NULL;
145 148
149 first_page = (unsigned long) page_address(page);
146 memset((char *)first_page, 0, PAGE_SIZE << order); 150 memset((char *)first_page, 0, PAGE_SIZE << order);
147 151
148 iommu = dev->archdata.iommu; 152 iommu = dev->archdata.iommu;
@@ -899,6 +903,8 @@ static void __init pci_sun4v_pbm_init(struct pci_controller_info *p,
899 pbm->next = pci_pbm_root; 903 pbm->next = pci_pbm_root;
900 pci_pbm_root = pbm; 904 pci_pbm_root = pbm;
901 905
906 pbm->numa_node = of_node_to_nid(dp);
907
902 pbm->scan_bus = pci_sun4v_scan_bus; 908 pbm->scan_bus = pci_sun4v_scan_bus;
903 pbm->pci_ops = &sun4v_pci_ops; 909 pbm->pci_ops = &sun4v_pci_ops;
904 pbm->config_space_reg_bits = 12; 910 pbm->config_space_reg_bits = 12;
@@ -913,6 +919,7 @@ static void __init pci_sun4v_pbm_init(struct pci_controller_info *p,
913 pbm->name = dp->full_name; 919 pbm->name = dp->full_name;
914 920
915 printk("%s: SUN4V PCI Bus Module\n", pbm->name); 921 printk("%s: SUN4V PCI Bus Module\n", pbm->name);
922 printk("%s: On NUMA node %d\n", pbm->name, pbm->numa_node);
916 923
917 pci_determine_mem_io_space(pbm); 924 pci_determine_mem_io_space(pbm);
918 925
diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c
index 68964ddcde1e..ed03a18d3b36 100644
--- a/arch/sparc64/kernel/prom.c
+++ b/arch/sparc64/kernel/prom.c
@@ -19,8 +19,8 @@
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/string.h> 20#include <linux/string.h>
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/bootmem.h>
23#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/lmb.h>
24 24
25#include <asm/prom.h> 25#include <asm/prom.h>
26#include <asm/of_device.h> 26#include <asm/of_device.h>
@@ -122,16 +122,20 @@ int of_find_in_proplist(const char *list, const char *match, int len)
122} 122}
123EXPORT_SYMBOL(of_find_in_proplist); 123EXPORT_SYMBOL(of_find_in_proplist);
124 124
125static unsigned int prom_early_allocated; 125static unsigned int prom_early_allocated __initdata;
126 126
127static void * __init prom_early_alloc(unsigned long size) 127static void * __init prom_early_alloc(unsigned long size)
128{ 128{
129 unsigned long paddr = lmb_alloc(size, SMP_CACHE_BYTES);
129 void *ret; 130 void *ret;
130 131
131 ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL); 132 if (!paddr) {
132 if (ret != NULL) 133 prom_printf("prom_early_alloc(%lu) failed\n");
133 memset(ret, 0, size); 134 prom_halt();
135 }
134 136
137 ret = __va(paddr);
138 memset(ret, 0, size);
135 prom_early_allocated += size; 139 prom_early_allocated += size;
136 140
137 return ret; 141 return ret;
diff --git a/arch/sparc64/kernel/rtrap.S b/arch/sparc64/kernel/rtrap.S
index 079d18a11d24..ecf6753b204a 100644
--- a/arch/sparc64/kernel/rtrap.S
+++ b/arch/sparc64/kernel/rtrap.S
@@ -18,12 +18,6 @@
18#define RTRAP_PSTATE_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV) 18#define RTRAP_PSTATE_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV)
19#define RTRAP_PSTATE_AG_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG) 19#define RTRAP_PSTATE_AG_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG)
20 20
21 /* Register %l6 keeps track of whether we are returning
22 * from a system call or not. It is cleared if we call
23 * do_notify_resume, and it must not be otherwise modified
24 * until we fully commit to returning to userspace.
25 */
26
27 .text 21 .text
28 .align 32 22 .align 32
29__handle_softirq: 23__handle_softirq:
@@ -56,14 +50,12 @@ __handle_user_windows:
56 be,pt %xcc, __handle_user_windows_continue 50 be,pt %xcc, __handle_user_windows_continue
57 nop 51 nop
58 mov %l5, %o1 52 mov %l5, %o1
59 mov %l6, %o2
60 add %sp, PTREGS_OFF, %o0 53 add %sp, PTREGS_OFF, %o0
61 mov %l0, %o3 54 mov %l0, %o2
62 55
63 call do_notify_resume 56 call do_notify_resume
64 wrpr %g0, RTRAP_PSTATE, %pstate 57 wrpr %g0, RTRAP_PSTATE, %pstate
65 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate 58 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
66 clr %l6
67 /* Signal delivery can modify pt_regs tstate, so we must 59 /* Signal delivery can modify pt_regs tstate, so we must
68 * reload it. 60 * reload it.
69 */ 61 */
@@ -99,14 +91,12 @@ __handle_perfctrs:
99 be,pt %xcc, __handle_perfctrs_continue 91 be,pt %xcc, __handle_perfctrs_continue
100 sethi %hi(TSTATE_PEF), %o0 92 sethi %hi(TSTATE_PEF), %o0
101 mov %l5, %o1 93 mov %l5, %o1
102 mov %l6, %o2
103 add %sp, PTREGS_OFF, %o0 94 add %sp, PTREGS_OFF, %o0
104 mov %l0, %o3 95 mov %l0, %o2
105 call do_notify_resume 96 call do_notify_resume
106 97
107 wrpr %g0, RTRAP_PSTATE, %pstate 98 wrpr %g0, RTRAP_PSTATE, %pstate
108 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate 99 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
109 clr %l6
110 /* Signal delivery can modify pt_regs tstate, so we must 100 /* Signal delivery can modify pt_regs tstate, so we must
111 * reload it. 101 * reload it.
112 */ 102 */
@@ -127,13 +117,11 @@ __handle_userfpu:
127 117
128__handle_signal: 118__handle_signal:
129 mov %l5, %o1 119 mov %l5, %o1
130 mov %l6, %o2
131 add %sp, PTREGS_OFF, %o0 120 add %sp, PTREGS_OFF, %o0
132 mov %l0, %o3 121 mov %l0, %o2
133 call do_notify_resume 122 call do_notify_resume
134 wrpr %g0, RTRAP_PSTATE, %pstate 123 wrpr %g0, RTRAP_PSTATE, %pstate
135 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate 124 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
136 clr %l6
137 125
138 /* Signal delivery can modify pt_regs tstate, so we must 126 /* Signal delivery can modify pt_regs tstate, so we must
139 * reload it. 127 * reload it.
@@ -145,9 +133,8 @@ __handle_signal:
145 andn %l1, %l4, %l1 133 andn %l1, %l4, %l1
146 134
147 .align 64 135 .align 64
148 .globl rtrap_irq, rtrap_clr_l6, rtrap, irqsz_patchme, rtrap_xcall 136 .globl rtrap_irq, rtrap, irqsz_patchme, rtrap_xcall
149rtrap_irq: 137rtrap_irq:
150rtrap_clr_l6: clr %l6
151rtrap: 138rtrap:
152#ifndef CONFIG_SMP 139#ifndef CONFIG_SMP
153 sethi %hi(per_cpu____cpu_data), %l0 140 sethi %hi(per_cpu____cpu_data), %l0
diff --git a/arch/sparc64/kernel/sbus.c b/arch/sparc64/kernel/sbus.c
index d1fb13ba02b5..fa2827c4a3ad 100644
--- a/arch/sparc64/kernel/sbus.c
+++ b/arch/sparc64/kernel/sbus.c
@@ -544,6 +544,7 @@ static void __init sbus_iommu_init(int __node, struct sbus_bus *sbus)
544 544
545 sbus->ofdev.dev.archdata.iommu = iommu; 545 sbus->ofdev.dev.archdata.iommu = iommu;
546 sbus->ofdev.dev.archdata.stc = strbuf; 546 sbus->ofdev.dev.archdata.stc = strbuf;
547 sbus->ofdev.dev.archdata.numa_node = -1;
547 548
548 reg_base = regs + SYSIO_IOMMUREG_BASE; 549 reg_base = regs + SYSIO_IOMMUREG_BASE;
549 iommu->iommu_control = reg_base + IOMMU_CONTROL; 550 iommu->iommu_control = reg_base + IOMMU_CONTROL;
@@ -575,7 +576,7 @@ static void __init sbus_iommu_init(int __node, struct sbus_bus *sbus)
575 sbus->portid, regs); 576 sbus->portid, regs);
576 577
577 /* Setup for TSB_SIZE=7, TBW_SIZE=0, MMU_DE=1, MMU_EN=1 */ 578 /* Setup for TSB_SIZE=7, TBW_SIZE=0, MMU_DE=1, MMU_EN=1 */
578 if (iommu_table_init(iommu, IO_TSB_SIZE, MAP_BASE, 0xffffffff)) 579 if (iommu_table_init(iommu, IO_TSB_SIZE, MAP_BASE, 0xffffffff, -1))
579 goto fatal_memory_error; 580 goto fatal_memory_error;
580 581
581 control = upa_readq(iommu->iommu_control); 582 control = upa_readq(iommu->iommu_control);
diff --git a/arch/sparc64/kernel/setup.c b/arch/sparc64/kernel/setup.c
index 6acb4c51cfe4..da5e6ee0c661 100644
--- a/arch/sparc64/kernel/setup.c
+++ b/arch/sparc64/kernel/setup.c
@@ -82,7 +82,7 @@ unsigned long cmdline_memory_size = 0;
82static struct console prom_early_console = { 82static struct console prom_early_console = {
83 .name = "earlyprom", 83 .name = "earlyprom",
84 .write = prom_console_write, 84 .write = prom_console_write,
85 .flags = CON_PRINTBUFFER | CON_BOOT, 85 .flags = CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
86 .index = -1, 86 .index = -1,
87}; 87};
88 88
@@ -281,6 +281,7 @@ void __init setup_arch(char **cmdline_p)
281 /* Initialize PROM console and command line. */ 281 /* Initialize PROM console and command line. */
282 *cmdline_p = prom_getbootargs(); 282 *cmdline_p = prom_getbootargs();
283 strcpy(boot_command_line, *cmdline_p); 283 strcpy(boot_command_line, *cmdline_p);
284 parse_early_param();
284 285
285 boot_flags_init(*cmdline_p); 286 boot_flags_init(*cmdline_p);
286 register_console(&prom_early_console); 287 register_console(&prom_early_console);
diff --git a/arch/sparc64/kernel/signal.c b/arch/sparc64/kernel/signal.c
index 1c47009eb5ec..77a3e8592cbc 100644
--- a/arch/sparc64/kernel/signal.c
+++ b/arch/sparc64/kernel/signal.c
@@ -510,15 +510,20 @@ static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
510 * want to handle. Thus you cannot kill init even with a SIGKILL even by 510 * want to handle. Thus you cannot kill init even with a SIGKILL even by
511 * mistake. 511 * mistake.
512 */ 512 */
513static void do_signal(struct pt_regs *regs, unsigned long orig_i0, int restart_syscall) 513static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
514{ 514{
515 siginfo_t info;
516 struct signal_deliver_cookie cookie; 515 struct signal_deliver_cookie cookie;
517 struct k_sigaction ka; 516 struct k_sigaction ka;
518 int signr;
519 sigset_t *oldset; 517 sigset_t *oldset;
518 siginfo_t info;
519 int signr, tt;
520 520
521 cookie.restart_syscall = restart_syscall; 521 tt = regs->magic & 0x1ff;
522 if (tt == 0x110 || tt == 0x111 || tt == 0x16d) {
523 regs->magic &= ~0x1ff;
524 cookie.restart_syscall = 1;
525 } else
526 cookie.restart_syscall = 0;
522 cookie.orig_i0 = orig_i0; 527 cookie.orig_i0 = orig_i0;
523 528
524 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 529 if (test_thread_flag(TIF_RESTORE_SIGMASK))
@@ -529,9 +534,8 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0, int restart_s
529#ifdef CONFIG_SPARC32_COMPAT 534#ifdef CONFIG_SPARC32_COMPAT
530 if (test_thread_flag(TIF_32BIT)) { 535 if (test_thread_flag(TIF_32BIT)) {
531 extern void do_signal32(sigset_t *, struct pt_regs *, 536 extern void do_signal32(sigset_t *, struct pt_regs *,
532 unsigned long, int); 537 struct signal_deliver_cookie *);
533 do_signal32(oldset, regs, orig_i0, 538 do_signal32(oldset, regs, &cookie);
534 cookie.restart_syscall);
535 return; 539 return;
536 } 540 }
537#endif 541#endif
@@ -539,7 +543,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0, int restart_s
539 signr = get_signal_to_deliver(&info, &ka, regs, &cookie); 543 signr = get_signal_to_deliver(&info, &ka, regs, &cookie);
540 if (signr > 0) { 544 if (signr > 0) {
541 if (cookie.restart_syscall) 545 if (cookie.restart_syscall)
542 syscall_restart(orig_i0, regs, &ka.sa); 546 syscall_restart(cookie.orig_i0, regs, &ka.sa);
543 handle_signal(signr, &ka, &info, oldset, regs); 547 handle_signal(signr, &ka, &info, oldset, regs);
544 548
545 /* a signal was successfully delivered; the saved 549 /* a signal was successfully delivered; the saved
@@ -576,11 +580,10 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0, int restart_s
576 } 580 }
577} 581}
578 582
579void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, int restart_syscall, 583void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags)
580 unsigned long thread_info_flags)
581{ 584{
582 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 585 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
583 do_signal(regs, orig_i0, restart_syscall); 586 do_signal(regs, orig_i0);
584} 587}
585 588
586void ptrace_signal_deliver(struct pt_regs *regs, void *cookie) 589void ptrace_signal_deliver(struct pt_regs *regs, void *cookie)
diff --git a/arch/sparc64/kernel/signal32.c b/arch/sparc64/kernel/signal32.c
index 74e0512f135c..43cdec64d9c9 100644
--- a/arch/sparc64/kernel/signal32.c
+++ b/arch/sparc64/kernel/signal32.c
@@ -982,20 +982,16 @@ static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs
982 * mistake. 982 * mistake.
983 */ 983 */
984void do_signal32(sigset_t *oldset, struct pt_regs * regs, 984void do_signal32(sigset_t *oldset, struct pt_regs * regs,
985 unsigned long orig_i0, int restart_syscall) 985 struct signal_deliver_cookie *cookie)
986{ 986{
987 siginfo_t info;
988 struct signal_deliver_cookie cookie;
989 struct k_sigaction ka; 987 struct k_sigaction ka;
988 siginfo_t info;
990 int signr; 989 int signr;
991 990
992 cookie.restart_syscall = restart_syscall; 991 signr = get_signal_to_deliver(&info, &ka, regs, cookie);
993 cookie.orig_i0 = orig_i0;
994
995 signr = get_signal_to_deliver(&info, &ka, regs, &cookie);
996 if (signr > 0) { 992 if (signr > 0) {
997 if (cookie.restart_syscall) 993 if (cookie->restart_syscall)
998 syscall_restart32(orig_i0, regs, &ka.sa); 994 syscall_restart32(cookie->orig_i0, regs, &ka.sa);
999 handle_signal32(signr, &ka, &info, oldset, regs); 995 handle_signal32(signr, &ka, &info, oldset, regs);
1000 996
1001 /* a signal was successfully delivered; the saved 997 /* a signal was successfully delivered; the saved
@@ -1007,16 +1003,16 @@ void do_signal32(sigset_t *oldset, struct pt_regs * regs,
1007 clear_thread_flag(TIF_RESTORE_SIGMASK); 1003 clear_thread_flag(TIF_RESTORE_SIGMASK);
1008 return; 1004 return;
1009 } 1005 }
1010 if (cookie.restart_syscall && 1006 if (cookie->restart_syscall &&
1011 (regs->u_regs[UREG_I0] == ERESTARTNOHAND || 1007 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
1012 regs->u_regs[UREG_I0] == ERESTARTSYS || 1008 regs->u_regs[UREG_I0] == ERESTARTSYS ||
1013 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) { 1009 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
1014 /* replay the system call when we are done */ 1010 /* replay the system call when we are done */
1015 regs->u_regs[UREG_I0] = cookie.orig_i0; 1011 regs->u_regs[UREG_I0] = cookie->orig_i0;
1016 regs->tpc -= 4; 1012 regs->tpc -= 4;
1017 regs->tnpc -= 4; 1013 regs->tnpc -= 4;
1018 } 1014 }
1019 if (cookie.restart_syscall && 1015 if (cookie->restart_syscall &&
1020 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) { 1016 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
1021 regs->u_regs[UREG_G1] = __NR_restart_syscall; 1017 regs->u_regs[UREG_G1] = __NR_restart_syscall;
1022 regs->tpc -= 4; 1018 regs->tpc -= 4;
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c
index 59f020d69d4c..524b88920947 100644
--- a/arch/sparc64/kernel/smp.c
+++ b/arch/sparc64/kernel/smp.c
@@ -20,7 +20,7 @@
20#include <linux/cache.h> 20#include <linux/cache.h>
21#include <linux/jiffies.h> 21#include <linux/jiffies.h>
22#include <linux/profile.h> 22#include <linux/profile.h>
23#include <linux/bootmem.h> 23#include <linux/lmb.h>
24 24
25#include <asm/head.h> 25#include <asm/head.h>
26#include <asm/ptrace.h> 26#include <asm/ptrace.h>
@@ -1431,7 +1431,7 @@ EXPORT_SYMBOL(__per_cpu_shift);
1431 1431
1432void __init real_setup_per_cpu_areas(void) 1432void __init real_setup_per_cpu_areas(void)
1433{ 1433{
1434 unsigned long goal, size, i; 1434 unsigned long paddr, goal, size, i;
1435 char *ptr; 1435 char *ptr;
1436 1436
1437 /* Copy section for each CPU (we discard the original) */ 1437 /* Copy section for each CPU (we discard the original) */
@@ -1441,8 +1441,13 @@ void __init real_setup_per_cpu_areas(void)
1441 for (size = PAGE_SIZE; size < goal; size <<= 1UL) 1441 for (size = PAGE_SIZE; size < goal; size <<= 1UL)
1442 __per_cpu_shift++; 1442 __per_cpu_shift++;
1443 1443
1444 ptr = alloc_bootmem_pages(size * NR_CPUS); 1444 paddr = lmb_alloc(size * NR_CPUS, PAGE_SIZE);
1445 if (!paddr) {
1446 prom_printf("Cannot allocate per-cpu memory.\n");
1447 prom_halt();
1448 }
1445 1449
1450 ptr = __va(paddr);
1446 __per_cpu_base = ptr - __per_cpu_start; 1451 __per_cpu_base = ptr - __per_cpu_start;
1447 1452
1448 for (i = 0; i < NR_CPUS; i++, ptr += size) 1453 for (i = 0; i < NR_CPUS; i++, ptr += size)
diff --git a/arch/sparc64/kernel/sparc64_ksyms.c b/arch/sparc64/kernel/sparc64_ksyms.c
index 38736460b8db..66336590e830 100644
--- a/arch/sparc64/kernel/sparc64_ksyms.c
+++ b/arch/sparc64/kernel/sparc64_ksyms.c
@@ -68,8 +68,6 @@ extern void *__memscan_zero(void *, size_t);
68extern void *__memscan_generic(void *, int, size_t); 68extern void *__memscan_generic(void *, int, size_t);
69extern int __memcmp(const void *, const void *, __kernel_size_t); 69extern int __memcmp(const void *, const void *, __kernel_size_t);
70extern __kernel_size_t strlen(const char *); 70extern __kernel_size_t strlen(const char *);
71extern void linux_sparc_syscall(void);
72extern void rtrap(void);
73extern void show_regs(struct pt_regs *); 71extern void show_regs(struct pt_regs *);
74extern void syscall_trace(struct pt_regs *, int); 72extern void syscall_trace(struct pt_regs *, int);
75extern void sys_sigsuspend(void); 73extern void sys_sigsuspend(void);
diff --git a/arch/sparc64/kernel/stacktrace.c b/arch/sparc64/kernel/stacktrace.c
index 84d39e873e88..01b52f561af4 100644
--- a/arch/sparc64/kernel/stacktrace.c
+++ b/arch/sparc64/kernel/stacktrace.c
@@ -20,6 +20,8 @@ void save_stack_trace(struct stack_trace *trace)
20 thread_base = (unsigned long) tp; 20 thread_base = (unsigned long) tp;
21 do { 21 do {
22 struct reg_window *rw; 22 struct reg_window *rw;
23 struct pt_regs *regs;
24 unsigned long pc;
23 25
24 /* Bogus frame pointer? */ 26 /* Bogus frame pointer? */
25 if (fp < (thread_base + sizeof(struct thread_info)) || 27 if (fp < (thread_base + sizeof(struct thread_info)) ||
@@ -27,11 +29,19 @@ void save_stack_trace(struct stack_trace *trace)
27 break; 29 break;
28 30
29 rw = (struct reg_window *) fp; 31 rw = (struct reg_window *) fp;
32 regs = (struct pt_regs *) (rw + 1);
33
34 if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
35 pc = regs->tpc;
36 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
37 } else {
38 pc = rw->ins[7];
39 fp = rw->ins[6] + STACK_BIAS;
40 }
41
30 if (trace->skip > 0) 42 if (trace->skip > 0)
31 trace->skip--; 43 trace->skip--;
32 else 44 else
33 trace->entries[trace->nr_entries++] = rw->ins[7]; 45 trace->entries[trace->nr_entries++] = pc;
34
35 fp = rw->ins[6] + STACK_BIAS;
36 } while (trace->nr_entries < trace->max_entries); 46 } while (trace->nr_entries < trace->max_entries);
37} 47}
diff --git a/arch/sparc64/kernel/sun4v_tlb_miss.S b/arch/sparc64/kernel/sun4v_tlb_miss.S
index fd9430562e0b..e1fbf8c75787 100644
--- a/arch/sparc64/kernel/sun4v_tlb_miss.S
+++ b/arch/sparc64/kernel/sun4v_tlb_miss.S
@@ -262,7 +262,7 @@ sun4v_iacc:
262 mov %l5, %o2 262 mov %l5, %o2
263 call sun4v_insn_access_exception 263 call sun4v_insn_access_exception
264 add %sp, PTREGS_OFF, %o0 264 add %sp, PTREGS_OFF, %o0
265 ba,a,pt %xcc, rtrap_clr_l6 265 ba,a,pt %xcc, rtrap
266 266
267 /* Instruction Access Exception, tl1. */ 267 /* Instruction Access Exception, tl1. */
268sun4v_iacc_tl1: 268sun4v_iacc_tl1:
@@ -278,7 +278,7 @@ sun4v_iacc_tl1:
278 mov %l5, %o2 278 mov %l5, %o2
279 call sun4v_insn_access_exception_tl1 279 call sun4v_insn_access_exception_tl1
280 add %sp, PTREGS_OFF, %o0 280 add %sp, PTREGS_OFF, %o0
281 ba,a,pt %xcc, rtrap_clr_l6 281 ba,a,pt %xcc, rtrap
282 282
283 /* Data Access Exception, tl0. */ 283 /* Data Access Exception, tl0. */
284sun4v_dacc: 284sun4v_dacc:
@@ -294,7 +294,7 @@ sun4v_dacc:
294 mov %l5, %o2 294 mov %l5, %o2
295 call sun4v_data_access_exception 295 call sun4v_data_access_exception
296 add %sp, PTREGS_OFF, %o0 296 add %sp, PTREGS_OFF, %o0
297 ba,a,pt %xcc, rtrap_clr_l6 297 ba,a,pt %xcc, rtrap
298 298
299 /* Data Access Exception, tl1. */ 299 /* Data Access Exception, tl1. */
300sun4v_dacc_tl1: 300sun4v_dacc_tl1:
@@ -310,7 +310,7 @@ sun4v_dacc_tl1:
310 mov %l5, %o2 310 mov %l5, %o2
311 call sun4v_data_access_exception_tl1 311 call sun4v_data_access_exception_tl1
312 add %sp, PTREGS_OFF, %o0 312 add %sp, PTREGS_OFF, %o0
313 ba,a,pt %xcc, rtrap_clr_l6 313 ba,a,pt %xcc, rtrap
314 314
315 /* Memory Address Unaligned. */ 315 /* Memory Address Unaligned. */
316sun4v_mna: 316sun4v_mna:
@@ -344,7 +344,7 @@ sun4v_mna:
344 mov %l5, %o2 344 mov %l5, %o2
345 call sun4v_do_mna 345 call sun4v_do_mna
346 add %sp, PTREGS_OFF, %o0 346 add %sp, PTREGS_OFF, %o0
347 ba,a,pt %xcc, rtrap_clr_l6 347 ba,a,pt %xcc, rtrap
348 348
349 /* Privileged Action. */ 349 /* Privileged Action. */
350sun4v_privact: 350sun4v_privact:
@@ -352,7 +352,7 @@ sun4v_privact:
352 rd %pc, %g7 352 rd %pc, %g7
353 call do_privact 353 call do_privact
354 add %sp, PTREGS_OFF, %o0 354 add %sp, PTREGS_OFF, %o0
355 ba,a,pt %xcc, rtrap_clr_l6 355 ba,a,pt %xcc, rtrap
356 356
357 /* Unaligned ldd float, tl0. */ 357 /* Unaligned ldd float, tl0. */
358sun4v_lddfmna: 358sun4v_lddfmna:
@@ -368,7 +368,7 @@ sun4v_lddfmna:
368 mov %l5, %o2 368 mov %l5, %o2
369 call handle_lddfmna 369 call handle_lddfmna
370 add %sp, PTREGS_OFF, %o0 370 add %sp, PTREGS_OFF, %o0
371 ba,a,pt %xcc, rtrap_clr_l6 371 ba,a,pt %xcc, rtrap
372 372
373 /* Unaligned std float, tl0. */ 373 /* Unaligned std float, tl0. */
374sun4v_stdfmna: 374sun4v_stdfmna:
@@ -384,7 +384,7 @@ sun4v_stdfmna:
384 mov %l5, %o2 384 mov %l5, %o2
385 call handle_stdfmna 385 call handle_stdfmna
386 add %sp, PTREGS_OFF, %o0 386 add %sp, PTREGS_OFF, %o0
387 ba,a,pt %xcc, rtrap_clr_l6 387 ba,a,pt %xcc, rtrap
388 388
389#define BRANCH_ALWAYS 0x10680000 389#define BRANCH_ALWAYS 0x10680000
390#define NOP 0x01000000 390#define NOP 0x01000000
diff --git a/arch/sparc64/kernel/sysfs.c b/arch/sparc64/kernel/sysfs.c
index 52816c7be0b9..e885034a6b73 100644
--- a/arch/sparc64/kernel/sysfs.c
+++ b/arch/sparc64/kernel/sysfs.c
@@ -273,10 +273,22 @@ static void __init check_mmu_stats(void)
273 mmu_stats_supported = 1; 273 mmu_stats_supported = 1;
274} 274}
275 275
276static void register_nodes(void)
277{
278#ifdef CONFIG_NUMA
279 int i;
280
281 for (i = 0; i < MAX_NUMNODES; i++)
282 register_one_node(i);
283#endif
284}
285
276static int __init topology_init(void) 286static int __init topology_init(void)
277{ 287{
278 int cpu; 288 int cpu;
279 289
290 register_nodes();
291
280 check_mmu_stats(); 292 check_mmu_stats();
281 293
282 register_cpu_notifier(&sysfs_cpu_nb); 294 register_cpu_notifier(&sysfs_cpu_nb);
diff --git a/arch/sparc64/kernel/traps.c b/arch/sparc64/kernel/traps.c
index 96da847023f3..d9b8d46707d1 100644
--- a/arch/sparc64/kernel/traps.c
+++ b/arch/sparc64/kernel/traps.c
@@ -2091,9 +2091,8 @@ static void user_instruction_dump(unsigned int __user *pc)
2091 2091
2092void show_stack(struct task_struct *tsk, unsigned long *_ksp) 2092void show_stack(struct task_struct *tsk, unsigned long *_ksp)
2093{ 2093{
2094 unsigned long pc, fp, thread_base, ksp; 2094 unsigned long fp, thread_base, ksp;
2095 struct thread_info *tp; 2095 struct thread_info *tp;
2096 struct reg_window *rw;
2097 int count = 0; 2096 int count = 0;
2098 2097
2099 ksp = (unsigned long) _ksp; 2098 ksp = (unsigned long) _ksp;
@@ -2117,15 +2116,27 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
2117 printk("\n"); 2116 printk("\n");
2118#endif 2117#endif
2119 do { 2118 do {
2119 struct reg_window *rw;
2120 struct pt_regs *regs;
2121 unsigned long pc;
2122
2120 /* Bogus frame pointer? */ 2123 /* Bogus frame pointer? */
2121 if (fp < (thread_base + sizeof(struct thread_info)) || 2124 if (fp < (thread_base + sizeof(struct thread_info)) ||
2122 fp >= (thread_base + THREAD_SIZE)) 2125 fp >= (thread_base + THREAD_SIZE))
2123 break; 2126 break;
2124 rw = (struct reg_window *)fp; 2127 rw = (struct reg_window *)fp;
2125 pc = rw->ins[7]; 2128 regs = (struct pt_regs *) (rw + 1);
2129
2130 if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
2131 pc = regs->tpc;
2132 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
2133 } else {
2134 pc = rw->ins[7];
2135 fp = rw->ins[6] + STACK_BIAS;
2136 }
2137
2126 printk(" [%016lx] ", pc); 2138 printk(" [%016lx] ", pc);
2127 print_symbol("%s\n", pc); 2139 print_symbol("%s\n", pc);
2128 fp = rw->ins[6] + STACK_BIAS;
2129 } while (++count < 16); 2140 } while (++count < 16);
2130#ifndef CONFIG_KALLSYMS 2141#ifndef CONFIG_KALLSYMS
2131 printk("\n"); 2142 printk("\n");
diff --git a/arch/sparc64/kernel/tsb.S b/arch/sparc64/kernel/tsb.S
index 10adb2fb8ffe..c499214b501d 100644
--- a/arch/sparc64/kernel/tsb.S
+++ b/arch/sparc64/kernel/tsb.S
@@ -275,7 +275,7 @@ sparc64_realfault_common:
275 stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address 275 stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address
276 call do_sparc64_fault ! Call fault handler 276 call do_sparc64_fault ! Call fault handler
277 add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg 277 add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg
278 ba,pt %xcc, rtrap_clr_l6 ! Restore cpu state 278 ba,pt %xcc, rtrap ! Restore cpu state
279 nop ! Delay slot (fill me) 279 nop ! Delay slot (fill me)
280 280
281winfix_trampoline: 281winfix_trampoline:
diff --git a/arch/sparc64/kernel/winfixup.S b/arch/sparc64/kernel/winfixup.S
index c4aa110a10e5..a6b0863c27df 100644
--- a/arch/sparc64/kernel/winfixup.S
+++ b/arch/sparc64/kernel/winfixup.S
@@ -32,7 +32,7 @@ fill_fixup:
32 rd %pc, %g7 32 rd %pc, %g7
33 call do_sparc64_fault 33 call do_sparc64_fault
34 add %sp, PTREGS_OFF, %o0 34 add %sp, PTREGS_OFF, %o0
35 ba,pt %xcc, rtrap_clr_l6 35 ba,pt %xcc, rtrap
36 nop 36 nop
37 37
38 /* Be very careful about usage of the trap globals here. 38 /* Be very careful about usage of the trap globals here.
@@ -100,7 +100,7 @@ spill_fixup_dax:
100 rd %pc, %g7 100 rd %pc, %g7
101 call do_sparc64_fault 101 call do_sparc64_fault
102 add %sp, PTREGS_OFF, %o0 102 add %sp, PTREGS_OFF, %o0
103 ba,a,pt %xcc, rtrap_clr_l6 103 ba,a,pt %xcc, rtrap
104 104
105winfix_mna: 105winfix_mna:
106 andn %g3, 0x7f, %g3 106 andn %g3, 0x7f, %g3
@@ -122,12 +122,12 @@ fill_fixup_mna:
122 mov %l4, %o2 122 mov %l4, %o2
123 call sun4v_do_mna 123 call sun4v_do_mna
124 mov %l5, %o1 124 mov %l5, %o1
125 ba,a,pt %xcc, rtrap_clr_l6 125 ba,a,pt %xcc, rtrap
1261: mov %l4, %o1 1261: mov %l4, %o1
127 mov %l5, %o2 127 mov %l5, %o2
128 call mem_address_unaligned 128 call mem_address_unaligned
129 nop 129 nop
130 ba,a,pt %xcc, rtrap_clr_l6 130 ba,a,pt %xcc, rtrap
131 131
132winfix_dax: 132winfix_dax:
133 andn %g3, 0x7f, %g3 133 andn %g3, 0x7f, %g3
@@ -150,7 +150,7 @@ fill_fixup_dax:
150 add %sp, PTREGS_OFF, %o0 150 add %sp, PTREGS_OFF, %o0
151 call sun4v_data_access_exception 151 call sun4v_data_access_exception
152 nop 152 nop
153 ba,a,pt %xcc, rtrap_clr_l6 153 ba,a,pt %xcc, rtrap
1541: call spitfire_data_access_exception 1541: call spitfire_data_access_exception
155 nop 155 nop
156 ba,a,pt %xcc, rtrap_clr_l6 156 ba,a,pt %xcc, rtrap
diff --git a/arch/sparc64/mm/init.c b/arch/sparc64/mm/init.c
index f37078d96407..177d8aaeec42 100644
--- a/arch/sparc64/mm/init.c
+++ b/arch/sparc64/mm/init.c
@@ -24,6 +24,8 @@
24#include <linux/cache.h> 24#include <linux/cache.h>
25#include <linux/sort.h> 25#include <linux/sort.h>
26#include <linux/percpu.h> 26#include <linux/percpu.h>
27#include <linux/lmb.h>
28#include <linux/mmzone.h>
27 29
28#include <asm/head.h> 30#include <asm/head.h>
29#include <asm/system.h> 31#include <asm/system.h>
@@ -72,9 +74,7 @@ extern struct tsb swapper_4m_tsb[KERNEL_TSB4M_NENTRIES];
72#define MAX_BANKS 32 74#define MAX_BANKS 32
73 75
74static struct linux_prom64_registers pavail[MAX_BANKS] __initdata; 76static struct linux_prom64_registers pavail[MAX_BANKS] __initdata;
75static struct linux_prom64_registers pavail_rescan[MAX_BANKS] __initdata;
76static int pavail_ents __initdata; 77static int pavail_ents __initdata;
77static int pavail_rescan_ents __initdata;
78 78
79static int cmp_p64(const void *a, const void *b) 79static int cmp_p64(const void *a, const void *b)
80{ 80{
@@ -715,285 +715,684 @@ out:
715 smp_new_mmu_context_version(); 715 smp_new_mmu_context_version();
716} 716}
717 717
718/* Find a free area for the bootmem map, avoiding the kernel image 718static int numa_enabled = 1;
719 * and the initial ramdisk. 719static int numa_debug;
720 */ 720
721static unsigned long __init choose_bootmap_pfn(unsigned long start_pfn, 721static int __init early_numa(char *p)
722 unsigned long end_pfn)
723{ 722{
724 unsigned long avoid_start, avoid_end, bootmap_size; 723 if (!p)
725 int i; 724 return 0;
725
726 if (strstr(p, "off"))
727 numa_enabled = 0;
728
729 if (strstr(p, "debug"))
730 numa_debug = 1;
731
732 return 0;
733}
734early_param("numa", early_numa);
726 735
727 bootmap_size = bootmem_bootmap_pages(end_pfn - start_pfn); 736#define numadbg(f, a...) \
728 bootmap_size <<= PAGE_SHIFT; 737do { if (numa_debug) \
738 printk(KERN_INFO f, ## a); \
739} while (0)
729 740
730 avoid_start = avoid_end = 0; 741static void __init find_ramdisk(unsigned long phys_base)
742{
731#ifdef CONFIG_BLK_DEV_INITRD 743#ifdef CONFIG_BLK_DEV_INITRD
732 avoid_start = initrd_start; 744 if (sparc_ramdisk_image || sparc_ramdisk_image64) {
733 avoid_end = PAGE_ALIGN(initrd_end); 745 unsigned long ramdisk_image;
746
747 /* Older versions of the bootloader only supported a
748 * 32-bit physical address for the ramdisk image
749 * location, stored at sparc_ramdisk_image. Newer
750 * SILO versions set sparc_ramdisk_image to zero and
751 * provide a full 64-bit physical address at
752 * sparc_ramdisk_image64.
753 */
754 ramdisk_image = sparc_ramdisk_image;
755 if (!ramdisk_image)
756 ramdisk_image = sparc_ramdisk_image64;
757
758 /* Another bootloader quirk. The bootloader normalizes
759 * the physical address to KERNBASE, so we have to
760 * factor that back out and add in the lowest valid
761 * physical page address to get the true physical address.
762 */
763 ramdisk_image -= KERNBASE;
764 ramdisk_image += phys_base;
765
766 numadbg("Found ramdisk at physical address 0x%lx, size %u\n",
767 ramdisk_image, sparc_ramdisk_size);
768
769 initrd_start = ramdisk_image;
770 initrd_end = ramdisk_image + sparc_ramdisk_size;
771
772 lmb_reserve(initrd_start, initrd_end);
773 }
734#endif 774#endif
775}
735 776
736 for (i = 0; i < pavail_ents; i++) { 777struct node_mem_mask {
737 unsigned long start, end; 778 unsigned long mask;
779 unsigned long val;
780 unsigned long bootmem_paddr;
781};
782static struct node_mem_mask node_masks[MAX_NUMNODES];
783static int num_node_masks;
738 784
739 start = pavail[i].phys_addr; 785int numa_cpu_lookup_table[NR_CPUS];
740 end = start + pavail[i].reg_size; 786cpumask_t numa_cpumask_lookup_table[MAX_NUMNODES];
741 787
742 while (start < end) { 788#ifdef CONFIG_NEED_MULTIPLE_NODES
743 if (start >= kern_base && 789static bootmem_data_t plat_node_bdata[MAX_NUMNODES];
744 start < PAGE_ALIGN(kern_base + kern_size)) {
745 start = PAGE_ALIGN(kern_base + kern_size);
746 continue;
747 }
748 if (start >= avoid_start && start < avoid_end) {
749 start = avoid_end;
750 continue;
751 }
752 790
753 if ((end - start) < bootmap_size) 791struct mdesc_mblock {
754 break; 792 u64 base;
793 u64 size;
794 u64 offset; /* RA-to-PA */
795};
796static struct mdesc_mblock *mblocks;
797static int num_mblocks;
755 798
756 if (start < kern_base && 799static unsigned long ra_to_pa(unsigned long addr)
757 (start + bootmap_size) > kern_base) { 800{
758 start = PAGE_ALIGN(kern_base + kern_size); 801 int i;
759 continue;
760 }
761 802
762 if (start < avoid_start && 803 for (i = 0; i < num_mblocks; i++) {
763 (start + bootmap_size) > avoid_start) { 804 struct mdesc_mblock *m = &mblocks[i];
764 start = avoid_end;
765 continue;
766 }
767 805
768 /* OK, it doesn't overlap anything, use it. */ 806 if (addr >= m->base &&
769 return start >> PAGE_SHIFT; 807 addr < (m->base + m->size)) {
808 addr += m->offset;
809 break;
770 } 810 }
771 } 811 }
772 812 return addr;
773 prom_printf("Cannot find free area for bootmap, aborting.\n");
774 prom_halt();
775} 813}
776 814
777static void __init trim_pavail(unsigned long *cur_size_p, 815static int find_node(unsigned long addr)
778 unsigned long *end_of_phys_p)
779{ 816{
780 unsigned long to_trim = *cur_size_p - cmdline_memory_size;
781 unsigned long avoid_start, avoid_end;
782 int i; 817 int i;
783 818
784 to_trim = PAGE_ALIGN(to_trim); 819 addr = ra_to_pa(addr);
820 for (i = 0; i < num_node_masks; i++) {
821 struct node_mem_mask *p = &node_masks[i];
785 822
786 avoid_start = avoid_end = 0; 823 if ((addr & p->mask) == p->val)
787#ifdef CONFIG_BLK_DEV_INITRD 824 return i;
788 avoid_start = initrd_start; 825 }
789 avoid_end = PAGE_ALIGN(initrd_end); 826 return -1;
827}
828
829static unsigned long nid_range(unsigned long start, unsigned long end,
830 int *nid)
831{
832 *nid = find_node(start);
833 start += PAGE_SIZE;
834 while (start < end) {
835 int n = find_node(start);
836
837 if (n != *nid)
838 break;
839 start += PAGE_SIZE;
840 }
841
842 return start;
843}
844#else
845static unsigned long nid_range(unsigned long start, unsigned long end,
846 int *nid)
847{
848 *nid = 0;
849 return end;
850}
790#endif 851#endif
791 852
792 /* Trim some pavail[] entries in order to satisfy the 853/* This must be invoked after performing all of the necessary
793 * requested "mem=xxx" kernel command line specification. 854 * add_active_range() calls for 'nid'. We need to be able to get
794 * 855 * correct data from get_pfn_range_for_nid().
795 * We must not trim off the kernel image area nor the 856 */
796 * initial ramdisk range (if any). Also, we must not trim 857static void __init allocate_node_data(int nid)
797 * any pavail[] entry down to zero in order to preserve 858{
798 * the invariant that all pavail[] entries have a non-zero 859 unsigned long paddr, num_pages, start_pfn, end_pfn;
799 * size which is assumed by all of the code in here. 860 struct pglist_data *p;
800 */ 861
801 for (i = 0; i < pavail_ents; i++) { 862#ifdef CONFIG_NEED_MULTIPLE_NODES
802 unsigned long start, end, kern_end; 863 paddr = lmb_alloc_nid(sizeof(struct pglist_data),
803 unsigned long trim_low, trim_high, n; 864 SMP_CACHE_BYTES, nid, nid_range);
865 if (!paddr) {
866 prom_printf("Cannot allocate pglist_data for nid[%d]\n", nid);
867 prom_halt();
868 }
869 NODE_DATA(nid) = __va(paddr);
870 memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
804 871
805 kern_end = PAGE_ALIGN(kern_base + kern_size); 872 NODE_DATA(nid)->bdata = &plat_node_bdata[nid];
873#endif
806 874
807 trim_low = start = pavail[i].phys_addr; 875 p = NODE_DATA(nid);
808 trim_high = end = start + pavail[i].reg_size;
809 876
810 if (kern_base >= start && 877 get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
811 kern_base < end) { 878 p->node_start_pfn = start_pfn;
812 trim_low = kern_base; 879 p->node_spanned_pages = end_pfn - start_pfn;
813 if (kern_end >= end) 880
814 continue; 881 if (p->node_spanned_pages) {
815 } 882 num_pages = bootmem_bootmap_pages(p->node_spanned_pages);
816 if (kern_end >= start && 883
817 kern_end < end) { 884 paddr = lmb_alloc_nid(num_pages << PAGE_SHIFT, PAGE_SIZE, nid,
818 trim_high = kern_end; 885 nid_range);
819 } 886 if (!paddr) {
820 if (avoid_start && 887 prom_printf("Cannot allocate bootmap for nid[%d]\n",
821 avoid_start >= start && 888 nid);
822 avoid_start < end) { 889 prom_halt();
823 if (trim_low > avoid_start)
824 trim_low = avoid_start;
825 if (avoid_end >= end)
826 continue;
827 }
828 if (avoid_end &&
829 avoid_end >= start &&
830 avoid_end < end) {
831 if (trim_high < avoid_end)
832 trim_high = avoid_end;
833 } 890 }
891 node_masks[nid].bootmem_paddr = paddr;
892 }
893}
894
895static void init_node_masks_nonnuma(void)
896{
897 int i;
898
899 numadbg("Initializing tables for non-numa.\n");
900
901 node_masks[0].mask = node_masks[0].val = 0;
902 num_node_masks = 1;
903
904 for (i = 0; i < NR_CPUS; i++)
905 numa_cpu_lookup_table[i] = 0;
906
907 numa_cpumask_lookup_table[0] = CPU_MASK_ALL;
908}
909
910#ifdef CONFIG_NEED_MULTIPLE_NODES
911struct pglist_data *node_data[MAX_NUMNODES];
912
913EXPORT_SYMBOL(numa_cpu_lookup_table);
914EXPORT_SYMBOL(numa_cpumask_lookup_table);
915EXPORT_SYMBOL(node_data);
916
917struct mdesc_mlgroup {
918 u64 node;
919 u64 latency;
920 u64 match;
921 u64 mask;
922};
923static struct mdesc_mlgroup *mlgroups;
924static int num_mlgroups;
925
926static int scan_pio_for_cfg_handle(struct mdesc_handle *md, u64 pio,
927 u32 cfg_handle)
928{
929 u64 arc;
834 930
835 if (trim_high <= trim_low) 931 mdesc_for_each_arc(arc, md, pio, MDESC_ARC_TYPE_FWD) {
932 u64 target = mdesc_arc_target(md, arc);
933 const u64 *val;
934
935 val = mdesc_get_property(md, target,
936 "cfg-handle", NULL);
937 if (val && *val == cfg_handle)
938 return 0;
939 }
940 return -ENODEV;
941}
942
943static int scan_arcs_for_cfg_handle(struct mdesc_handle *md, u64 grp,
944 u32 cfg_handle)
945{
946 u64 arc, candidate, best_latency = ~(u64)0;
947
948 candidate = MDESC_NODE_NULL;
949 mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) {
950 u64 target = mdesc_arc_target(md, arc);
951 const char *name = mdesc_node_name(md, target);
952 const u64 *val;
953
954 if (strcmp(name, "pio-latency-group"))
836 continue; 955 continue;
837 956
838 if (trim_low == start && trim_high == end) { 957 val = mdesc_get_property(md, target, "latency", NULL);
839 /* Whole chunk is available for trimming. 958 if (!val)
840 * Trim all except one page, in order to keep 959 continue;
841 * entry non-empty. 960
842 */ 961 if (*val < best_latency) {
843 n = (end - start) - PAGE_SIZE; 962 candidate = target;
844 if (n > to_trim) 963 best_latency = *val;
845 n = to_trim;
846
847 if (n) {
848 pavail[i].phys_addr += n;
849 pavail[i].reg_size -= n;
850 to_trim -= n;
851 }
852 } else {
853 n = (trim_low - start);
854 if (n > to_trim)
855 n = to_trim;
856
857 if (n) {
858 pavail[i].phys_addr += n;
859 pavail[i].reg_size -= n;
860 to_trim -= n;
861 }
862 if (to_trim) {
863 n = end - trim_high;
864 if (n > to_trim)
865 n = to_trim;
866 if (n) {
867 pavail[i].reg_size -= n;
868 to_trim -= n;
869 }
870 }
871 } 964 }
965 }
966
967 if (candidate == MDESC_NODE_NULL)
968 return -ENODEV;
969
970 return scan_pio_for_cfg_handle(md, candidate, cfg_handle);
971}
972
973int of_node_to_nid(struct device_node *dp)
974{
975 const struct linux_prom64_registers *regs;
976 struct mdesc_handle *md;
977 u32 cfg_handle;
978 int count, nid;
979 u64 grp;
872 980
873 if (!to_trim) 981 if (!mlgroups)
982 return -1;
983
984 regs = of_get_property(dp, "reg", NULL);
985 if (!regs)
986 return -1;
987
988 cfg_handle = (regs->phys_addr >> 32UL) & 0x0fffffff;
989
990 md = mdesc_grab();
991
992 count = 0;
993 nid = -1;
994 mdesc_for_each_node_by_name(md, grp, "group") {
995 if (!scan_arcs_for_cfg_handle(md, grp, cfg_handle)) {
996 nid = count;
874 break; 997 break;
998 }
999 count++;
875 } 1000 }
876 1001
877 /* Recalculate. */ 1002 mdesc_release(md);
878 *cur_size_p = 0UL; 1003
879 for (i = 0; i < pavail_ents; i++) { 1004 return nid;
880 *end_of_phys_p = pavail[i].phys_addr +
881 pavail[i].reg_size;
882 *cur_size_p += pavail[i].reg_size;
883 }
884} 1005}
885 1006
886/* About pages_avail, this is the value we will use to calculate 1007static void add_node_ranges(void)
887 * the zholes_size[] argument given to free_area_init_node(). The
888 * page allocator uses this to calculate nr_kernel_pages,
889 * nr_all_pages and zone->present_pages. On NUMA it is used
890 * to calculate zone->min_unmapped_pages and zone->min_slab_pages.
891 *
892 * So this number should really be set to what the page allocator
893 * actually ends up with. This means:
894 * 1) It should include bootmem map pages, we'll release those.
895 * 2) It should not include the kernel image, except for the
896 * __init sections which we will also release.
897 * 3) It should include the initrd image, since we'll release
898 * that too.
899 */
900static unsigned long __init bootmem_init(unsigned long *pages_avail,
901 unsigned long phys_base)
902{ 1008{
903 unsigned long bootmap_size, end_pfn;
904 unsigned long end_of_phys_memory = 0UL;
905 unsigned long bootmap_pfn, bytes_avail, size;
906 int i; 1009 int i;
907 1010
908 bytes_avail = 0UL; 1011 for (i = 0; i < lmb.memory.cnt; i++) {
909 for (i = 0; i < pavail_ents; i++) { 1012 unsigned long size = lmb_size_bytes(&lmb.memory, i);
910 end_of_phys_memory = pavail[i].phys_addr + 1013 unsigned long start, end;
911 pavail[i].reg_size; 1014
912 bytes_avail += pavail[i].reg_size; 1015 start = lmb.memory.region[i].base;
1016 end = start + size;
1017 while (start < end) {
1018 unsigned long this_end;
1019 int nid;
1020
1021 this_end = nid_range(start, end, &nid);
1022
1023 numadbg("Adding active range nid[%d] "
1024 "start[%lx] end[%lx]\n",
1025 nid, start, this_end);
1026
1027 add_active_range(nid,
1028 start >> PAGE_SHIFT,
1029 this_end >> PAGE_SHIFT);
1030
1031 start = this_end;
1032 }
913 } 1033 }
1034}
914 1035
915 /* Determine the location of the initial ramdisk before trying 1036static int __init grab_mlgroups(struct mdesc_handle *md)
916 * to honor the "mem=xxx" command line argument. We must know 1037{
917 * where the kernel image and the ramdisk image are so that we 1038 unsigned long paddr;
918 * do not trim those two areas from the physical memory map. 1039 int count = 0;
919 */ 1040 u64 node;
1041
1042 mdesc_for_each_node_by_name(md, node, "memory-latency-group")
1043 count++;
1044 if (!count)
1045 return -ENOENT;
1046
1047 paddr = lmb_alloc(count * sizeof(struct mdesc_mlgroup),
1048 SMP_CACHE_BYTES);
1049 if (!paddr)
1050 return -ENOMEM;
1051
1052 mlgroups = __va(paddr);
1053 num_mlgroups = count;
1054
1055 count = 0;
1056 mdesc_for_each_node_by_name(md, node, "memory-latency-group") {
1057 struct mdesc_mlgroup *m = &mlgroups[count++];
1058 const u64 *val;
1059
1060 m->node = node;
1061
1062 val = mdesc_get_property(md, node, "latency", NULL);
1063 m->latency = *val;
1064 val = mdesc_get_property(md, node, "address-match", NULL);
1065 m->match = *val;
1066 val = mdesc_get_property(md, node, "address-mask", NULL);
1067 m->mask = *val;
1068
1069 numadbg("MLGROUP[%d]: node[%lx] latency[%lx] "
1070 "match[%lx] mask[%lx]\n",
1071 count - 1, m->node, m->latency, m->match, m->mask);
1072 }
920 1073
921#ifdef CONFIG_BLK_DEV_INITRD 1074 return 0;
922 /* Now have to check initial ramdisk, so that bootmap does not overwrite it */ 1075}
923 if (sparc_ramdisk_image || sparc_ramdisk_image64) { 1076
924 unsigned long ramdisk_image = sparc_ramdisk_image ? 1077static int __init grab_mblocks(struct mdesc_handle *md)
925 sparc_ramdisk_image : sparc_ramdisk_image64; 1078{
926 ramdisk_image -= KERNBASE; 1079 unsigned long paddr;
927 initrd_start = ramdisk_image + phys_base; 1080 int count = 0;
928 initrd_end = initrd_start + sparc_ramdisk_size; 1081 u64 node;
929 if (initrd_end > end_of_phys_memory) { 1082
930 printk(KERN_CRIT "initrd extends beyond end of memory " 1083 mdesc_for_each_node_by_name(md, node, "mblock")
931 "(0x%016lx > 0x%016lx)\ndisabling initrd\n", 1084 count++;
932 initrd_end, end_of_phys_memory); 1085 if (!count)
933 initrd_start = 0; 1086 return -ENOENT;
934 initrd_end = 0; 1087
1088 paddr = lmb_alloc(count * sizeof(struct mdesc_mblock),
1089 SMP_CACHE_BYTES);
1090 if (!paddr)
1091 return -ENOMEM;
1092
1093 mblocks = __va(paddr);
1094 num_mblocks = count;
1095
1096 count = 0;
1097 mdesc_for_each_node_by_name(md, node, "mblock") {
1098 struct mdesc_mblock *m = &mblocks[count++];
1099 const u64 *val;
1100
1101 val = mdesc_get_property(md, node, "base", NULL);
1102 m->base = *val;
1103 val = mdesc_get_property(md, node, "size", NULL);
1104 m->size = *val;
1105 val = mdesc_get_property(md, node,
1106 "address-congruence-offset", NULL);
1107 m->offset = *val;
1108
1109 numadbg("MBLOCK[%d]: base[%lx] size[%lx] offset[%lx]\n",
1110 count - 1, m->base, m->size, m->offset);
1111 }
1112
1113 return 0;
1114}
1115
1116static void __init numa_parse_mdesc_group_cpus(struct mdesc_handle *md,
1117 u64 grp, cpumask_t *mask)
1118{
1119 u64 arc;
1120
1121 cpus_clear(*mask);
1122
1123 mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_BACK) {
1124 u64 target = mdesc_arc_target(md, arc);
1125 const char *name = mdesc_node_name(md, target);
1126 const u64 *id;
1127
1128 if (strcmp(name, "cpu"))
1129 continue;
1130 id = mdesc_get_property(md, target, "id", NULL);
1131 if (*id < NR_CPUS)
1132 cpu_set(*id, *mask);
1133 }
1134}
1135
1136static struct mdesc_mlgroup * __init find_mlgroup(u64 node)
1137{
1138 int i;
1139
1140 for (i = 0; i < num_mlgroups; i++) {
1141 struct mdesc_mlgroup *m = &mlgroups[i];
1142 if (m->node == node)
1143 return m;
1144 }
1145 return NULL;
1146}
1147
1148static int __init numa_attach_mlgroup(struct mdesc_handle *md, u64 grp,
1149 int index)
1150{
1151 struct mdesc_mlgroup *candidate = NULL;
1152 u64 arc, best_latency = ~(u64)0;
1153 struct node_mem_mask *n;
1154
1155 mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) {
1156 u64 target = mdesc_arc_target(md, arc);
1157 struct mdesc_mlgroup *m = find_mlgroup(target);
1158 if (!m)
1159 continue;
1160 if (m->latency < best_latency) {
1161 candidate = m;
1162 best_latency = m->latency;
935 } 1163 }
936 } 1164 }
937#endif 1165 if (!candidate)
1166 return -ENOENT;
1167
1168 if (num_node_masks != index) {
1169 printk(KERN_ERR "Inconsistent NUMA state, "
1170 "index[%d] != num_node_masks[%d]\n",
1171 index, num_node_masks);
1172 return -EINVAL;
1173 }
938 1174
939 if (cmdline_memory_size && 1175 n = &node_masks[num_node_masks++];
940 bytes_avail > cmdline_memory_size)
941 trim_pavail(&bytes_avail,
942 &end_of_phys_memory);
943 1176
944 *pages_avail = bytes_avail >> PAGE_SHIFT; 1177 n->mask = candidate->mask;
1178 n->val = candidate->match;
945 1179
946 end_pfn = end_of_phys_memory >> PAGE_SHIFT; 1180 numadbg("NUMA NODE[%d]: mask[%lx] val[%lx] (latency[%lx])\n",
1181 index, n->mask, n->val, candidate->latency);
947 1182
948 /* Initialize the boot-time allocator. */ 1183 return 0;
949 max_pfn = max_low_pfn = end_pfn; 1184}
950 min_low_pfn = (phys_base >> PAGE_SHIFT); 1185
1186static int __init numa_parse_mdesc_group(struct mdesc_handle *md, u64 grp,
1187 int index)
1188{
1189 cpumask_t mask;
1190 int cpu;
951 1191
952 bootmap_pfn = choose_bootmap_pfn(min_low_pfn, end_pfn); 1192 numa_parse_mdesc_group_cpus(md, grp, &mask);
953 1193
954 bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap_pfn, 1194 for_each_cpu_mask(cpu, mask)
955 min_low_pfn, end_pfn); 1195 numa_cpu_lookup_table[cpu] = index;
1196 numa_cpumask_lookup_table[index] = mask;
956 1197
957 /* Now register the available physical memory with the 1198 if (numa_debug) {
958 * allocator. 1199 printk(KERN_INFO "NUMA GROUP[%d]: cpus [ ", index);
959 */ 1200 for_each_cpu_mask(cpu, mask)
960 for (i = 0; i < pavail_ents; i++) 1201 printk("%d ", cpu);
961 free_bootmem(pavail[i].phys_addr, pavail[i].reg_size); 1202 printk("]\n");
1203 }
962 1204
963#ifdef CONFIG_BLK_DEV_INITRD 1205 return numa_attach_mlgroup(md, grp, index);
964 if (initrd_start) { 1206}
965 size = initrd_end - initrd_start; 1207
1208static int __init numa_parse_mdesc(void)
1209{
1210 struct mdesc_handle *md = mdesc_grab();
1211 int i, err, count;
1212 u64 node;
1213
1214 node = mdesc_node_by_name(md, MDESC_NODE_NULL, "latency-groups");
1215 if (node == MDESC_NODE_NULL) {
1216 mdesc_release(md);
1217 return -ENOENT;
1218 }
1219
1220 err = grab_mblocks(md);
1221 if (err < 0)
1222 goto out;
1223
1224 err = grab_mlgroups(md);
1225 if (err < 0)
1226 goto out;
1227
1228 count = 0;
1229 mdesc_for_each_node_by_name(md, node, "group") {
1230 err = numa_parse_mdesc_group(md, node, count);
1231 if (err < 0)
1232 break;
1233 count++;
1234 }
1235
1236 add_node_ranges();
1237
1238 for (i = 0; i < num_node_masks; i++) {
1239 allocate_node_data(i);
1240 node_set_online(i);
1241 }
1242
1243 err = 0;
1244out:
1245 mdesc_release(md);
1246 return err;
1247}
1248
1249static int __init numa_parse_sun4u(void)
1250{
1251 return -1;
1252}
966 1253
967 /* Reserve the initrd image area. */ 1254static int __init bootmem_init_numa(void)
968 reserve_bootmem(initrd_start, size, BOOTMEM_DEFAULT); 1255{
1256 int err = -1;
969 1257
970 initrd_start += PAGE_OFFSET; 1258 numadbg("bootmem_init_numa()\n");
971 initrd_end += PAGE_OFFSET; 1259
1260 if (numa_enabled) {
1261 if (tlb_type == hypervisor)
1262 err = numa_parse_mdesc();
1263 else
1264 err = numa_parse_sun4u();
972 } 1265 }
1266 return err;
1267}
1268
1269#else
1270
1271static int bootmem_init_numa(void)
1272{
1273 return -1;
1274}
1275
973#endif 1276#endif
974 /* Reserve the kernel text/data/bss. */
975 reserve_bootmem(kern_base, kern_size, BOOTMEM_DEFAULT);
976 *pages_avail -= PAGE_ALIGN(kern_size) >> PAGE_SHIFT;
977
978 /* Add back in the initmem pages. */
979 size = ((unsigned long)(__init_end) & PAGE_MASK) -
980 PAGE_ALIGN((unsigned long)__init_begin);
981 *pages_avail += size >> PAGE_SHIFT;
982
983 /* Reserve the bootmem map. We do not account for it
984 * in pages_avail because we will release that memory
985 * in free_all_bootmem.
986 */
987 size = bootmap_size;
988 reserve_bootmem((bootmap_pfn << PAGE_SHIFT), size, BOOTMEM_DEFAULT);
989 1277
990 for (i = 0; i < pavail_ents; i++) { 1278static void __init bootmem_init_nonnuma(void)
1279{
1280 unsigned long top_of_ram = lmb_end_of_DRAM();
1281 unsigned long total_ram = lmb_phys_mem_size();
1282 unsigned int i;
1283
1284 numadbg("bootmem_init_nonnuma()\n");
1285
1286 printk(KERN_INFO "Top of RAM: 0x%lx, Total RAM: 0x%lx\n",
1287 top_of_ram, total_ram);
1288 printk(KERN_INFO "Memory hole size: %ldMB\n",
1289 (top_of_ram - total_ram) >> 20);
1290
1291 init_node_masks_nonnuma();
1292
1293 for (i = 0; i < lmb.memory.cnt; i++) {
1294 unsigned long size = lmb_size_bytes(&lmb.memory, i);
991 unsigned long start_pfn, end_pfn; 1295 unsigned long start_pfn, end_pfn;
992 1296
993 start_pfn = pavail[i].phys_addr >> PAGE_SHIFT; 1297 if (!size)
994 end_pfn = (start_pfn + (pavail[i].reg_size >> PAGE_SHIFT)); 1298 continue;
995 memory_present(0, start_pfn, end_pfn); 1299
1300 start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;
1301 end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);
1302 add_active_range(0, start_pfn, end_pfn);
1303 }
1304
1305 allocate_node_data(0);
1306
1307 node_set_online(0);
1308}
1309
1310static void __init reserve_range_in_node(int nid, unsigned long start,
1311 unsigned long end)
1312{
1313 numadbg(" reserve_range_in_node(nid[%d],start[%lx],end[%lx]\n",
1314 nid, start, end);
1315 while (start < end) {
1316 unsigned long this_end;
1317 int n;
1318
1319 this_end = nid_range(start, end, &n);
1320 if (n == nid) {
1321 numadbg(" MATCH reserving range [%lx:%lx]\n",
1322 start, this_end);
1323 reserve_bootmem_node(NODE_DATA(nid), start,
1324 (this_end - start), BOOTMEM_DEFAULT);
1325 } else
1326 numadbg(" NO MATCH, advancing start to %lx\n",
1327 this_end);
1328
1329 start = this_end;
1330 }
1331}
1332
1333static void __init trim_reserved_in_node(int nid)
1334{
1335 int i;
1336
1337 numadbg(" trim_reserved_in_node(%d)\n", nid);
1338
1339 for (i = 0; i < lmb.reserved.cnt; i++) {
1340 unsigned long start = lmb.reserved.region[i].base;
1341 unsigned long size = lmb_size_bytes(&lmb.reserved, i);
1342 unsigned long end = start + size;
1343
1344 reserve_range_in_node(nid, start, end);
1345 }
1346}
1347
1348static void __init bootmem_init_one_node(int nid)
1349{
1350 struct pglist_data *p;
1351
1352 numadbg("bootmem_init_one_node(%d)\n", nid);
1353
1354 p = NODE_DATA(nid);
1355
1356 if (p->node_spanned_pages) {
1357 unsigned long paddr = node_masks[nid].bootmem_paddr;
1358 unsigned long end_pfn;
1359
1360 end_pfn = p->node_start_pfn + p->node_spanned_pages;
1361
1362 numadbg(" init_bootmem_node(%d, %lx, %lx, %lx)\n",
1363 nid, paddr >> PAGE_SHIFT, p->node_start_pfn, end_pfn);
1364
1365 init_bootmem_node(p, paddr >> PAGE_SHIFT,
1366 p->node_start_pfn, end_pfn);
1367
1368 numadbg(" free_bootmem_with_active_regions(%d, %lx)\n",
1369 nid, end_pfn);
1370 free_bootmem_with_active_regions(nid, end_pfn);
1371
1372 trim_reserved_in_node(nid);
1373
1374 numadbg(" sparse_memory_present_with_active_regions(%d)\n",
1375 nid);
1376 sparse_memory_present_with_active_regions(nid);
996 } 1377 }
1378}
1379
1380static unsigned long __init bootmem_init(unsigned long phys_base)
1381{
1382 unsigned long end_pfn;
1383 int nid;
1384
1385 end_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT;
1386 max_pfn = max_low_pfn = end_pfn;
1387 min_low_pfn = (phys_base >> PAGE_SHIFT);
1388
1389 if (bootmem_init_numa() < 0)
1390 bootmem_init_nonnuma();
1391
1392 /* XXX cpu notifier XXX */
1393
1394 for_each_online_node(nid)
1395 bootmem_init_one_node(nid);
997 1396
998 sparse_init(); 1397 sparse_init();
999 1398
@@ -1289,7 +1688,7 @@ void __init setup_per_cpu_areas(void)
1289 1688
1290void __init paging_init(void) 1689void __init paging_init(void)
1291{ 1690{
1292 unsigned long end_pfn, pages_avail, shift, phys_base; 1691 unsigned long end_pfn, shift, phys_base;
1293 unsigned long real_end, i; 1692 unsigned long real_end, i;
1294 1693
1295 /* These build time checkes make sure that the dcache_dirty_cpu() 1694 /* These build time checkes make sure that the dcache_dirty_cpu()
@@ -1330,12 +1729,26 @@ void __init paging_init(void)
1330 sun4v_ktsb_init(); 1729 sun4v_ktsb_init();
1331 } 1730 }
1332 1731
1732 lmb_init();
1733
1333 /* Find available physical memory... */ 1734 /* Find available physical memory... */
1334 read_obp_memory("available", &pavail[0], &pavail_ents); 1735 read_obp_memory("available", &pavail[0], &pavail_ents);
1335 1736
1336 phys_base = 0xffffffffffffffffUL; 1737 phys_base = 0xffffffffffffffffUL;
1337 for (i = 0; i < pavail_ents; i++) 1738 for (i = 0; i < pavail_ents; i++) {
1338 phys_base = min(phys_base, pavail[i].phys_addr); 1739 phys_base = min(phys_base, pavail[i].phys_addr);
1740 lmb_add(pavail[i].phys_addr, pavail[i].reg_size);
1741 }
1742
1743 lmb_reserve(kern_base, kern_size);
1744
1745 find_ramdisk(phys_base);
1746
1747 if (cmdline_memory_size)
1748 lmb_enforce_memory_limit(phys_base + cmdline_memory_size);
1749
1750 lmb_analyze();
1751 lmb_dump_all();
1339 1752
1340 set_bit(0, mmu_context_bmap); 1753 set_bit(0, mmu_context_bmap);
1341 1754
@@ -1371,14 +1784,10 @@ void __init paging_init(void)
1371 if (tlb_type == hypervisor) 1784 if (tlb_type == hypervisor)
1372 sun4v_ktsb_register(); 1785 sun4v_ktsb_register();
1373 1786
1374 /* Setup bootmem... */ 1787 /* We must setup the per-cpu areas before we pull in the
1375 pages_avail = 0; 1788 * PROM and the MDESC. The code there fills in cpu and
1376 last_valid_pfn = end_pfn = bootmem_init(&pages_avail, phys_base); 1789 * other information into per-cpu data structures.
1377 1790 */
1378 max_mapnr = last_valid_pfn;
1379
1380 kernel_physical_mapping_init();
1381
1382 real_setup_per_cpu_areas(); 1791 real_setup_per_cpu_areas();
1383 1792
1384 prom_build_devicetree(); 1793 prom_build_devicetree();
@@ -1386,20 +1795,22 @@ void __init paging_init(void)
1386 if (tlb_type == hypervisor) 1795 if (tlb_type == hypervisor)
1387 sun4v_mdesc_init(); 1796 sun4v_mdesc_init();
1388 1797
1798 /* Setup bootmem... */
1799 last_valid_pfn = end_pfn = bootmem_init(phys_base);
1800
1801#ifndef CONFIG_NEED_MULTIPLE_NODES
1802 max_mapnr = last_valid_pfn;
1803#endif
1804 kernel_physical_mapping_init();
1805
1389 { 1806 {
1390 unsigned long zones_size[MAX_NR_ZONES]; 1807 unsigned long max_zone_pfns[MAX_NR_ZONES];
1391 unsigned long zholes_size[MAX_NR_ZONES];
1392 int znum;
1393 1808
1394 for (znum = 0; znum < MAX_NR_ZONES; znum++) 1809 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
1395 zones_size[znum] = zholes_size[znum] = 0;
1396 1810
1397 zones_size[ZONE_NORMAL] = end_pfn; 1811 max_zone_pfns[ZONE_NORMAL] = end_pfn;
1398 zholes_size[ZONE_NORMAL] = end_pfn - pages_avail;
1399 1812
1400 free_area_init_node(0, &contig_page_data, zones_size, 1813 free_area_init_nodes(max_zone_pfns);
1401 __pa(PAGE_OFFSET) >> PAGE_SHIFT,
1402 zholes_size);
1403 } 1814 }
1404 1815
1405 printk("Booting Linux...\n"); 1816 printk("Booting Linux...\n");
@@ -1408,21 +1819,52 @@ void __init paging_init(void)
1408 cpu_probe(); 1819 cpu_probe();
1409} 1820}
1410 1821
1411static void __init taint_real_pages(void) 1822int __init page_in_phys_avail(unsigned long paddr)
1823{
1824 int i;
1825
1826 paddr &= PAGE_MASK;
1827
1828 for (i = 0; i < pavail_ents; i++) {
1829 unsigned long start, end;
1830
1831 start = pavail[i].phys_addr;
1832 end = start + pavail[i].reg_size;
1833
1834 if (paddr >= start && paddr < end)
1835 return 1;
1836 }
1837 if (paddr >= kern_base && paddr < (kern_base + kern_size))
1838 return 1;
1839#ifdef CONFIG_BLK_DEV_INITRD
1840 if (paddr >= __pa(initrd_start) &&
1841 paddr < __pa(PAGE_ALIGN(initrd_end)))
1842 return 1;
1843#endif
1844
1845 return 0;
1846}
1847
1848static struct linux_prom64_registers pavail_rescan[MAX_BANKS] __initdata;
1849static int pavail_rescan_ents __initdata;
1850
1851/* Certain OBP calls, such as fetching "available" properties, can
1852 * claim physical memory. So, along with initializing the valid
1853 * address bitmap, what we do here is refetch the physical available
1854 * memory list again, and make sure it provides at least as much
1855 * memory as 'pavail' does.
1856 */
1857static void setup_valid_addr_bitmap_from_pavail(void)
1412{ 1858{
1413 int i; 1859 int i;
1414 1860
1415 read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents); 1861 read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents);
1416 1862
1417 /* Find changes discovered in the physmem available rescan and
1418 * reserve the lost portions in the bootmem maps.
1419 */
1420 for (i = 0; i < pavail_ents; i++) { 1863 for (i = 0; i < pavail_ents; i++) {
1421 unsigned long old_start, old_end; 1864 unsigned long old_start, old_end;
1422 1865
1423 old_start = pavail[i].phys_addr; 1866 old_start = pavail[i].phys_addr;
1424 old_end = old_start + 1867 old_end = old_start + pavail[i].reg_size;
1425 pavail[i].reg_size;
1426 while (old_start < old_end) { 1868 while (old_start < old_end) {
1427 int n; 1869 int n;
1428 1870
@@ -1440,7 +1882,16 @@ static void __init taint_real_pages(void)
1440 goto do_next_page; 1882 goto do_next_page;
1441 } 1883 }
1442 } 1884 }
1443 reserve_bootmem(old_start, PAGE_SIZE, BOOTMEM_DEFAULT); 1885
1886 prom_printf("mem_init: Lost memory in pavail\n");
1887 prom_printf("mem_init: OLD start[%lx] size[%lx]\n",
1888 pavail[i].phys_addr,
1889 pavail[i].reg_size);
1890 prom_printf("mem_init: NEW start[%lx] size[%lx]\n",
1891 pavail_rescan[i].phys_addr,
1892 pavail_rescan[i].reg_size);
1893 prom_printf("mem_init: Cannot continue, aborting.\n");
1894 prom_halt();
1444 1895
1445 do_next_page: 1896 do_next_page:
1446 old_start += PAGE_SIZE; 1897 old_start += PAGE_SIZE;
@@ -1448,32 +1899,6 @@ static void __init taint_real_pages(void)
1448 } 1899 }
1449} 1900}
1450 1901
1451int __init page_in_phys_avail(unsigned long paddr)
1452{
1453 int i;
1454
1455 paddr &= PAGE_MASK;
1456
1457 for (i = 0; i < pavail_rescan_ents; i++) {
1458 unsigned long start, end;
1459
1460 start = pavail_rescan[i].phys_addr;
1461 end = start + pavail_rescan[i].reg_size;
1462
1463 if (paddr >= start && paddr < end)
1464 return 1;
1465 }
1466 if (paddr >= kern_base && paddr < (kern_base + kern_size))
1467 return 1;
1468#ifdef CONFIG_BLK_DEV_INITRD
1469 if (paddr >= __pa(initrd_start) &&
1470 paddr < __pa(PAGE_ALIGN(initrd_end)))
1471 return 1;
1472#endif
1473
1474 return 0;
1475}
1476
1477void __init mem_init(void) 1902void __init mem_init(void)
1478{ 1903{
1479 unsigned long codepages, datapages, initpages; 1904 unsigned long codepages, datapages, initpages;
@@ -1496,14 +1921,26 @@ void __init mem_init(void)
1496 addr += PAGE_SIZE; 1921 addr += PAGE_SIZE;
1497 } 1922 }
1498 1923
1499 taint_real_pages(); 1924 setup_valid_addr_bitmap_from_pavail();
1500 1925
1501 high_memory = __va(last_valid_pfn << PAGE_SHIFT); 1926 high_memory = __va(last_valid_pfn << PAGE_SHIFT);
1502 1927
1928#ifdef CONFIG_NEED_MULTIPLE_NODES
1929 for_each_online_node(i) {
1930 if (NODE_DATA(i)->node_spanned_pages != 0) {
1931 totalram_pages +=
1932 free_all_bootmem_node(NODE_DATA(i));
1933 }
1934 }
1935#else
1936 totalram_pages = free_all_bootmem();
1937#endif
1938
1503 /* We subtract one to account for the mem_map_zero page 1939 /* We subtract one to account for the mem_map_zero page
1504 * allocated below. 1940 * allocated below.
1505 */ 1941 */
1506 totalram_pages = num_physpages = free_all_bootmem() - 1; 1942 totalram_pages -= 1;
1943 num_physpages = totalram_pages;
1507 1944
1508 /* 1945 /*
1509 * Set up the zero page, mark it reserved, so that page count 1946 * Set up the zero page, mark it reserved, so that page count
diff --git a/arch/sparc64/mm/tsb.c b/arch/sparc64/mm/tsb.c
index a3e6e4b635b3..fe70c8a557b5 100644
--- a/arch/sparc64/mm/tsb.c
+++ b/arch/sparc64/mm/tsb.c
@@ -321,7 +321,8 @@ retry_tsb_alloc:
321 if (new_size > (PAGE_SIZE * 2)) 321 if (new_size > (PAGE_SIZE * 2))
322 gfp_flags = __GFP_NOWARN | __GFP_NORETRY; 322 gfp_flags = __GFP_NOWARN | __GFP_NORETRY;
323 323
324 new_tsb = kmem_cache_alloc(tsb_caches[new_cache_index], gfp_flags); 324 new_tsb = kmem_cache_alloc_node(tsb_caches[new_cache_index],
325 gfp_flags, numa_node_id());
325 if (unlikely(!new_tsb)) { 326 if (unlikely(!new_tsb)) {
326 /* Not being able to fork due to a high-order TSB 327 /* Not being able to fork due to a high-order TSB
327 * allocation failure is very bad behavior. Just back 328 * allocation failure is very bad behavior. Just back
diff --git a/arch/sparc64/mm/ultra.S b/arch/sparc64/mm/ultra.S
index 2865c105b6a4..e686a67561af 100644
--- a/arch/sparc64/mm/ultra.S
+++ b/arch/sparc64/mm/ultra.S
@@ -476,7 +476,6 @@ xcall_sync_tick:
476#endif 476#endif
477 call smp_synchronize_tick_client 477 call smp_synchronize_tick_client
478 nop 478 nop
479 clr %l6
480 b rtrap_xcall 479 b rtrap_xcall
481 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1 480 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
482 481
@@ -511,7 +510,6 @@ xcall_report_regs:
511#endif 510#endif
512 call __show_regs 511 call __show_regs
513 add %sp, PTREGS_OFF, %o0 512 add %sp, PTREGS_OFF, %o0
514 clr %l6
515 /* Has to be a non-v9 branch due to the large distance. */ 513 /* Has to be a non-v9 branch due to the large distance. */
516 b rtrap_xcall 514 b rtrap_xcall
517 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1 515 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
@@ -576,7 +574,7 @@ __hypervisor_tlb_xcall_error:
576 mov %l4, %o0 574 mov %l4, %o0
577 call hypervisor_tlbop_error_xcall 575 call hypervisor_tlbop_error_xcall
578 mov %l5, %o1 576 mov %l5, %o1
579 ba,a,pt %xcc, rtrap_clr_l6 577 ba,a,pt %xcc, rtrap
580 578
581 .globl __hypervisor_xcall_flush_tlb_mm 579 .globl __hypervisor_xcall_flush_tlb_mm
582__hypervisor_xcall_flush_tlb_mm: /* 21 insns */ 580__hypervisor_xcall_flush_tlb_mm: /* 21 insns */
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index be1cc5143354..ef522ae55480 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -530,7 +530,8 @@ void bus_remove_device(struct device *dev)
530 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, 530 sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
531 dev->bus_id); 531 dev->bus_id);
532 device_remove_attrs(dev->bus, dev); 532 device_remove_attrs(dev->bus, dev);
533 klist_del(&dev->knode_bus); 533 if (klist_node_attached(&dev->knode_bus))
534 klist_del(&dev->knode_bus);
534 535
535 pr_debug("bus: '%s': remove device %s\n", 536 pr_debug("bus: '%s': remove device %s\n",
536 dev->bus->name, dev->bus_id); 537 dev->bus->name, dev->bus_id);
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index c4568b82875b..7b76fd3b93a4 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -62,7 +62,7 @@ static bool all_sleeping;
62 */ 62 */
63int device_pm_add(struct device *dev) 63int device_pm_add(struct device *dev)
64{ 64{
65 int error = 0; 65 int error;
66 66
67 pr_debug("PM: Adding info for %s:%s\n", 67 pr_debug("PM: Adding info for %s:%s\n",
68 dev->bus ? dev->bus->name : "No Bus", 68 dev->bus ? dev->bus->name : "No Bus",
@@ -70,18 +70,15 @@ int device_pm_add(struct device *dev)
70 mutex_lock(&dpm_list_mtx); 70 mutex_lock(&dpm_list_mtx);
71 if ((dev->parent && dev->parent->power.sleeping) || all_sleeping) { 71 if ((dev->parent && dev->parent->power.sleeping) || all_sleeping) {
72 if (dev->parent->power.sleeping) 72 if (dev->parent->power.sleeping)
73 dev_warn(dev, 73 dev_warn(dev, "parent %s is sleeping\n",
74 "parent %s is sleeping, will not add\n",
75 dev->parent->bus_id); 74 dev->parent->bus_id);
76 else 75 else
77 dev_warn(dev, "devices are sleeping, will not add\n"); 76 dev_warn(dev, "all devices are sleeping\n");
78 WARN_ON(true); 77 WARN_ON(true);
79 error = -EBUSY;
80 } else {
81 error = dpm_sysfs_add(dev);
82 if (!error)
83 list_add_tail(&dev->power.entry, &dpm_active);
84 } 78 }
79 error = dpm_sysfs_add(dev);
80 if (!error)
81 list_add_tail(&dev->power.entry, &dpm_active);
85 mutex_unlock(&dpm_list_mtx); 82 mutex_unlock(&dpm_list_mtx);
86 return error; 83 return error;
87} 84}
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 85364804364f..7bd76639544c 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -108,7 +108,7 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
108#ifndef CONFIG_BLK_DEV_XIP 108#ifndef CONFIG_BLK_DEV_XIP
109 gfp_flags |= __GFP_HIGHMEM; 109 gfp_flags |= __GFP_HIGHMEM;
110#endif 110#endif
111 page = alloc_page(GFP_NOIO | __GFP_HIGHMEM | __GFP_ZERO); 111 page = alloc_page(gfp_flags);
112 if (!page) 112 if (!page)
113 return NULL; 113 return NULL;
114 114
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index f0b00ec1e47e..e03c67dd3e63 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -44,8 +44,8 @@
44 44
45#ifdef CONFIG_HID_DEBUG 45#ifdef CONFIG_HID_DEBUG
46int hid_debug = 0; 46int hid_debug = 0;
47module_param_named(debug, hid_debug, bool, 0600); 47module_param_named(debug, hid_debug, int, 0600);
48MODULE_PARM_DESC(debug, "Turn HID debugging mode on and off"); 48MODULE_PARM_DESC(debug, "HID debugging (0=off, 1=probing info, 2=continuous data dumping)");
49EXPORT_SYMBOL_GPL(hid_debug); 49EXPORT_SYMBOL_GPL(hid_debug);
50#endif 50#endif
51 51
@@ -97,7 +97,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
97 field->index = report->maxfield++; 97 field->index = report->maxfield++;
98 report->field[field->index] = field; 98 report->field[field->index] = field;
99 field->usage = (struct hid_usage *)(field + 1); 99 field->usage = (struct hid_usage *)(field + 1);
100 field->value = (unsigned *)(field->usage + usages); 100 field->value = (s32 *)(field->usage + usages);
101 field->report = report; 101 field->report = report;
102 102
103 return field; 103 return field;
@@ -830,7 +830,8 @@ static void hid_process_event(struct hid_device *hid, struct hid_field *field, s
830 * reporting to the layer). 830 * reporting to the layer).
831 */ 831 */
832 832
833void hid_input_field(struct hid_device *hid, struct hid_field *field, __u8 *data, int interrupt) 833static void hid_input_field(struct hid_device *hid, struct hid_field *field,
834 __u8 *data, int interrupt)
834{ 835{
835 unsigned n; 836 unsigned n;
836 unsigned count = field->report_count; 837 unsigned count = field->report_count;
@@ -876,7 +877,6 @@ void hid_input_field(struct hid_device *hid, struct hid_field *field, __u8 *data
876exit: 877exit:
877 kfree(value); 878 kfree(value);
878} 879}
879EXPORT_SYMBOL_GPL(hid_input_field);
880 880
881/* 881/*
882 * Output the field into the report. 882 * Output the field into the report.
@@ -988,8 +988,13 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i
988 988
989 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event) 989 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
990 hid->hiddev_report_event(hid, report); 990 hid->hiddev_report_event(hid, report);
991 if (hid->claimed & HID_CLAIMED_HIDRAW) 991 if (hid->claimed & HID_CLAIMED_HIDRAW) {
992 hidraw_report_event(hid, data, size); 992 /* numbered reports need to be passed with the report num */
993 if (report_enum->numbered)
994 hidraw_report_event(hid, data - 1, size + 1);
995 else
996 hidraw_report_event(hid, data, size);
997 }
993 998
994 for (n = 0; n < report->maxfield; n++) 999 for (n = 0; n < report->maxfield; n++)
995 hid_input_field(hid, report->field[n], data, interrupt); 1000 hid_input_field(hid, report->field[n], data, interrupt);
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 5c24fe46d8eb..f88714b06000 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -498,7 +498,7 @@ void hid_dump_device(struct hid_device *device) {
498EXPORT_SYMBOL_GPL(hid_dump_device); 498EXPORT_SYMBOL_GPL(hid_dump_device);
499 499
500void hid_dump_input(struct hid_usage *usage, __s32 value) { 500void hid_dump_input(struct hid_usage *usage, __s32 value) {
501 if (!hid_debug) 501 if (hid_debug < 2)
502 return; 502 return;
503 503
504 printk(KERN_DEBUG "hid-debug: input "); 504 printk(KERN_DEBUG "hid-debug: input ");
diff --git a/drivers/hid/hid-input-quirks.c b/drivers/hid/hid-input-quirks.c
index dceadd0c1419..4c2052c658f1 100644
--- a/drivers/hid/hid-input-quirks.c
+++ b/drivers/hid/hid-input-quirks.c
@@ -276,6 +276,21 @@ static int quirk_btc_8193(struct hid_usage *usage, struct input_dev *input,
276 return 1; 276 return 1;
277} 277}
278 278
279static int quirk_sunplus_wdesktop(struct hid_usage *usage, struct input_dev *input,
280 unsigned long **bit, int *max)
281{
282 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
283 return 0;
284
285 switch (usage->hid & HID_USAGE) {
286 case 0x2003: map_key_clear(KEY_ZOOMIN); break;
287 case 0x2103: map_key_clear(KEY_ZOOMOUT); break;
288 default:
289 return 0;
290 }
291 return 1;
292}
293
279#define VENDOR_ID_BELKIN 0x1020 294#define VENDOR_ID_BELKIN 0x1020
280#define DEVICE_ID_BELKIN_WIRELESS_KEYBOARD 0x0006 295#define DEVICE_ID_BELKIN_WIRELESS_KEYBOARD 0x0006
281 296
@@ -306,6 +321,9 @@ static int quirk_btc_8193(struct hid_usage *usage, struct input_dev *input,
306#define VENDOR_ID_PETALYNX 0x18b1 321#define VENDOR_ID_PETALYNX 0x18b1
307#define DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037 322#define DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037
308 323
324#define VENDOR_ID_SUNPLUS 0x04fc
325#define DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8
326
309static const struct hid_input_blacklist { 327static const struct hid_input_blacklist {
310 __u16 idVendor; 328 __u16 idVendor;
311 __u16 idProduct; 329 __u16 idProduct;
@@ -332,8 +350,10 @@ static const struct hid_input_blacklist {
332 { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e }, 350 { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e },
333 351
334 { VENDOR_ID_PETALYNX, DEVICE_ID_PETALYNX_MAXTER_REMOTE, quirk_petalynx_remote }, 352 { VENDOR_ID_PETALYNX, DEVICE_ID_PETALYNX_MAXTER_REMOTE, quirk_petalynx_remote },
335 353
336 { 0, 0, 0 } 354 { VENDOR_ID_SUNPLUS, DEVICE_ID_SUNPLUS_WDESKTOP, quirk_sunplus_wdesktop },
355
356 { 0, 0, NULL }
337}; 357};
338 358
339int hidinput_mapping_quirks(struct hid_usage *usage, 359int hidinput_mapping_quirks(struct hid_usage *usage,
diff --git a/drivers/hid/usbhid/Kconfig b/drivers/hid/usbhid/Kconfig
index 7160fa65d79b..18f09104765c 100644
--- a/drivers/hid/usbhid/Kconfig
+++ b/drivers/hid/usbhid/Kconfig
@@ -71,6 +71,14 @@ config LOGITECH_FF
71 Note: if you say N here, this device will still be supported, but without 71 Note: if you say N here, this device will still be supported, but without
72 force feedback. 72 force feedback.
73 73
74config LOGIRUMBLEPAD2_FF
75 bool "Logitech Rumblepad 2 support"
76 depends on HID_FF
77 select INPUT_FF_MEMLESS if USB_HID
78 help
79 Say Y here if you want to enable force feedback support for Logitech
80 Rumblepad 2 devices.
81
74config PANTHERLORD_FF 82config PANTHERLORD_FF
75 bool "PantherLord/GreenAsia based device support" 83 bool "PantherLord/GreenAsia based device support"
76 depends on HID_FF 84 depends on HID_FF
@@ -80,8 +88,8 @@ config PANTHERLORD_FF
80 or adapter and want to enable force feedback support for it. 88 or adapter and want to enable force feedback support for it.
81 89
82config THRUSTMASTER_FF 90config THRUSTMASTER_FF
83 bool "ThrustMaster devices support (EXPERIMENTAL)" 91 bool "ThrustMaster devices support"
84 depends on HID_FF && EXPERIMENTAL 92 depends on HID_FF
85 select INPUT_FF_MEMLESS if USB_HID 93 select INPUT_FF_MEMLESS if USB_HID
86 help 94 help
87 Say Y here if you have a THRUSTMASTER FireStore Dual Power 2 or 95 Say Y here if you have a THRUSTMASTER FireStore Dual Power 2 or
diff --git a/drivers/hid/usbhid/Makefile b/drivers/hid/usbhid/Makefile
index 8e6ab5b164a2..00a7b7090192 100644
--- a/drivers/hid/usbhid/Makefile
+++ b/drivers/hid/usbhid/Makefile
@@ -16,6 +16,9 @@ endif
16ifeq ($(CONFIG_LOGITECH_FF),y) 16ifeq ($(CONFIG_LOGITECH_FF),y)
17 usbhid-objs += hid-lgff.o 17 usbhid-objs += hid-lgff.o
18endif 18endif
19ifeq ($(CONFIG_LOGIRUMBLEPAD2_FF),y)
20 usbhid-objs += hid-lg2ff.o
21endif
19ifeq ($(CONFIG_PANTHERLORD_FF),y) 22ifeq ($(CONFIG_PANTHERLORD_FF),y)
20 usbhid-objs += hid-plff.o 23 usbhid-objs += hid-plff.o
21endif 24endif
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index d95979f0e028..e0d805f1b2bf 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -82,6 +82,7 @@ static int hid_start_in(struct hid_device *hid)
82 82
83 spin_lock_irqsave(&usbhid->inlock, flags); 83 spin_lock_irqsave(&usbhid->inlock, flags);
84 if (hid->open > 0 && !test_bit(HID_SUSPENDED, &usbhid->iofl) && 84 if (hid->open > 0 && !test_bit(HID_SUSPENDED, &usbhid->iofl) &&
85 !test_bit(HID_DISCONNECTED, &usbhid->iofl) &&
85 !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) { 86 !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) {
86 rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC); 87 rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC);
87 if (rc != 0) 88 if (rc != 0)
@@ -155,7 +156,7 @@ static void hid_io_error(struct hid_device *hid)
155 spin_lock_irqsave(&usbhid->inlock, flags); 156 spin_lock_irqsave(&usbhid->inlock, flags);
156 157
157 /* Stop when disconnected */ 158 /* Stop when disconnected */
158 if (usb_get_intfdata(usbhid->intf) == NULL) 159 if (test_bit(HID_DISCONNECTED, &usbhid->iofl))
159 goto done; 160 goto done;
160 161
161 /* If it has been a while since the last error, we'll assume 162 /* If it has been a while since the last error, we'll assume
@@ -341,7 +342,7 @@ static void hid_irq_out(struct urb *urb)
341 if (usbhid->outhead != usbhid->outtail) { 342 if (usbhid->outhead != usbhid->outtail) {
342 if (hid_submit_out(hid)) { 343 if (hid_submit_out(hid)) {
343 clear_bit(HID_OUT_RUNNING, &usbhid->iofl); 344 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
344 wake_up(&hid->wait); 345 wake_up(&usbhid->wait);
345 } 346 }
346 spin_unlock_irqrestore(&usbhid->outlock, flags); 347 spin_unlock_irqrestore(&usbhid->outlock, flags);
347 return; 348 return;
@@ -349,7 +350,7 @@ static void hid_irq_out(struct urb *urb)
349 350
350 clear_bit(HID_OUT_RUNNING, &usbhid->iofl); 351 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
351 spin_unlock_irqrestore(&usbhid->outlock, flags); 352 spin_unlock_irqrestore(&usbhid->outlock, flags);
352 wake_up(&hid->wait); 353 wake_up(&usbhid->wait);
353} 354}
354 355
355/* 356/*
@@ -391,7 +392,7 @@ static void hid_ctrl(struct urb *urb)
391 if (usbhid->ctrlhead != usbhid->ctrltail) { 392 if (usbhid->ctrlhead != usbhid->ctrltail) {
392 if (hid_submit_ctrl(hid)) { 393 if (hid_submit_ctrl(hid)) {
393 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); 394 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
394 wake_up(&hid->wait); 395 wake_up(&usbhid->wait);
395 } 396 }
396 spin_unlock_irqrestore(&usbhid->ctrllock, flags); 397 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
397 return; 398 return;
@@ -399,7 +400,7 @@ static void hid_ctrl(struct urb *urb)
399 400
400 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); 401 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
401 spin_unlock_irqrestore(&usbhid->ctrllock, flags); 402 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
402 wake_up(&hid->wait); 403 wake_up(&usbhid->wait);
403} 404}
404 405
405void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir) 406void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir)
@@ -478,8 +479,9 @@ int usbhid_wait_io(struct hid_device *hid)
478{ 479{
479 struct usbhid_device *usbhid = hid->driver_data; 480 struct usbhid_device *usbhid = hid->driver_data;
480 481
481 if (!wait_event_timeout(hid->wait, (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl) && 482 if (!wait_event_timeout(usbhid->wait,
482 !test_bit(HID_OUT_RUNNING, &usbhid->iofl)), 483 (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl) &&
484 !test_bit(HID_OUT_RUNNING, &usbhid->iofl)),
483 10*HZ)) { 485 10*HZ)) {
484 dbg_hid("timeout waiting for ctrl or out queue to clear\n"); 486 dbg_hid("timeout waiting for ctrl or out queue to clear\n");
485 return -1; 487 return -1;
@@ -610,10 +612,11 @@ static void usbhid_set_leds(struct hid_device *hid)
610/* 612/*
611 * Traverse the supplied list of reports and find the longest 613 * Traverse the supplied list of reports and find the longest
612 */ 614 */
613static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *max) 615static void hid_find_max_report(struct hid_device *hid, unsigned int type,
616 unsigned int *max)
614{ 617{
615 struct hid_report *report; 618 struct hid_report *report;
616 int size; 619 unsigned int size;
617 620
618 list_for_each_entry(report, &hid->report_enum[type].report_list, list) { 621 list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
619 size = ((report->size - 1) >> 3) + 1; 622 size = ((report->size - 1) >> 3) + 1;
@@ -705,9 +708,9 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
705 struct hid_descriptor *hdesc; 708 struct hid_descriptor *hdesc;
706 struct hid_device *hid; 709 struct hid_device *hid;
707 u32 quirks = 0; 710 u32 quirks = 0;
708 unsigned rsize = 0; 711 unsigned int insize = 0, rsize = 0;
709 char *rdesc; 712 char *rdesc;
710 int n, len, insize = 0; 713 int n, len;
711 struct usbhid_device *usbhid; 714 struct usbhid_device *usbhid;
712 715
713 quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor), 716 quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor),
@@ -800,6 +803,22 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
800 goto fail; 803 goto fail;
801 } 804 }
802 805
806 hid->name[0] = 0;
807
808 if (dev->manufacturer)
809 strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
810
811 if (dev->product) {
812 if (dev->manufacturer)
813 strlcat(hid->name, " ", sizeof(hid->name));
814 strlcat(hid->name, dev->product, sizeof(hid->name));
815 }
816
817 if (!strlen(hid->name))
818 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
819 le16_to_cpu(dev->descriptor.idVendor),
820 le16_to_cpu(dev->descriptor.idProduct));
821
803 for (n = 0; n < interface->desc.bNumEndpoints; n++) { 822 for (n = 0; n < interface->desc.bNumEndpoints; n++) {
804 823
805 struct usb_endpoint_descriptor *endpoint; 824 struct usb_endpoint_descriptor *endpoint;
@@ -812,6 +831,14 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
812 831
813 interval = endpoint->bInterval; 832 interval = endpoint->bInterval;
814 833
834 /* Some vendors give fullspeed interval on highspeed devides */
835 if (quirks & HID_QUIRK_FULLSPEED_INTERVAL &&
836 dev->speed == USB_SPEED_HIGH) {
837 interval = fls(endpoint->bInterval*8);
838 printk(KERN_INFO "%s: Fixing fullspeed to highspeed interval: %d -> %d\n",
839 hid->name, endpoint->bInterval, interval);
840 }
841
815 /* Change the polling interval of mice. */ 842 /* Change the polling interval of mice. */
816 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) 843 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
817 interval = hid_mousepoll_interval; 844 interval = hid_mousepoll_interval;
@@ -844,8 +871,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
844 goto fail; 871 goto fail;
845 } 872 }
846 873
847 init_waitqueue_head(&hid->wait); 874 init_waitqueue_head(&usbhid->wait);
848
849 INIT_WORK(&usbhid->reset_work, hid_reset); 875 INIT_WORK(&usbhid->reset_work, hid_reset);
850 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid); 876 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid);
851 877
@@ -859,22 +885,6 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
859 usbhid->intf = intf; 885 usbhid->intf = intf;
860 usbhid->ifnum = interface->desc.bInterfaceNumber; 886 usbhid->ifnum = interface->desc.bInterfaceNumber;
861 887
862 hid->name[0] = 0;
863
864 if (dev->manufacturer)
865 strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
866
867 if (dev->product) {
868 if (dev->manufacturer)
869 strlcat(hid->name, " ", sizeof(hid->name));
870 strlcat(hid->name, dev->product, sizeof(hid->name));
871 }
872
873 if (!strlen(hid->name))
874 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
875 le16_to_cpu(dev->descriptor.idVendor),
876 le16_to_cpu(dev->descriptor.idProduct));
877
878 hid->bus = BUS_USB; 888 hid->bus = BUS_USB;
879 hid->vendor = le16_to_cpu(dev->descriptor.idVendor); 889 hid->vendor = le16_to_cpu(dev->descriptor.idVendor);
880 hid->product = le16_to_cpu(dev->descriptor.idProduct); 890 hid->product = le16_to_cpu(dev->descriptor.idProduct);
@@ -932,6 +942,7 @@ static void hid_disconnect(struct usb_interface *intf)
932 942
933 spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ 943 spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
934 usb_set_intfdata(intf, NULL); 944 usb_set_intfdata(intf, NULL);
945 set_bit(HID_DISCONNECTED, &usbhid->iofl);
935 spin_unlock_irq(&usbhid->inlock); 946 spin_unlock_irq(&usbhid->inlock);
936 usb_kill_urb(usbhid->urbin); 947 usb_kill_urb(usbhid->urbin);
937 usb_kill_urb(usbhid->urbout); 948 usb_kill_urb(usbhid->urbout);
diff --git a/drivers/hid/usbhid/hid-ff.c b/drivers/hid/usbhid/hid-ff.c
index 4c210e16b1b4..1d0dac52f166 100644
--- a/drivers/hid/usbhid/hid-ff.c
+++ b/drivers/hid/usbhid/hid-ff.c
@@ -59,6 +59,9 @@ static struct hid_ff_initializer inits[] = {
59 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */ 59 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */
60 { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */ 60 { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */
61#endif 61#endif
62#ifdef CONFIG_LOGIRUMBLEPAD2_FF
63 { 0x46d, 0xc218, hid_lg2ff_init }, /* Logitech Rumblepad 2 */
64#endif
62#ifdef CONFIG_PANTHERLORD_FF 65#ifdef CONFIG_PANTHERLORD_FF
63 { 0x810, 0x0001, hid_plff_init }, /* "Twin USB Joystick" */ 66 { 0x810, 0x0001, hid_plff_init }, /* "Twin USB Joystick" */
64 { 0xe8f, 0x0003, hid_plff_init }, /* "GreenAsia Inc. USB Joystick " */ 67 { 0xe8f, 0x0003, hid_plff_init }, /* "GreenAsia Inc. USB Joystick " */
diff --git a/drivers/hid/usbhid/hid-lg2ff.c b/drivers/hid/usbhid/hid-lg2ff.c
new file mode 100644
index 000000000000..d469bd0061c9
--- /dev/null
+++ b/drivers/hid/usbhid/hid-lg2ff.c
@@ -0,0 +1,114 @@
1/*
2 * Force feedback support for Logitech Rumblepad 2
3 *
4 * Copyright (c) 2008 Anssi Hannula <anssi.hannula@gmail.com>
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23
24#include <linux/input.h>
25#include <linux/usb.h>
26#include <linux/hid.h>
27#include "usbhid.h"
28
29struct lg2ff_device {
30 struct hid_report *report;
31};
32
33static int play_effect(struct input_dev *dev, void *data,
34 struct ff_effect *effect)
35{
36 struct hid_device *hid = input_get_drvdata(dev);
37 struct lg2ff_device *lg2ff = data;
38 int weak, strong;
39
40 strong = effect->u.rumble.strong_magnitude;
41 weak = effect->u.rumble.weak_magnitude;
42
43 if (weak || strong) {
44 weak = weak * 0xff / 0xffff;
45 strong = strong * 0xff / 0xffff;
46
47 lg2ff->report->field[0]->value[0] = 0x51;
48 lg2ff->report->field[0]->value[2] = weak;
49 lg2ff->report->field[0]->value[4] = strong;
50 } else {
51 lg2ff->report->field[0]->value[0] = 0xf3;
52 lg2ff->report->field[0]->value[2] = 0x00;
53 lg2ff->report->field[0]->value[4] = 0x00;
54 }
55
56 usbhid_submit_report(hid, lg2ff->report, USB_DIR_OUT);
57 return 0;
58}
59
60int hid_lg2ff_init(struct hid_device *hid)
61{
62 struct lg2ff_device *lg2ff;
63 struct hid_report *report;
64 struct hid_input *hidinput = list_entry(hid->inputs.next,
65 struct hid_input, list);
66 struct list_head *report_list =
67 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
68 struct input_dev *dev = hidinput->input;
69 int error;
70
71 if (list_empty(report_list)) {
72 printk(KERN_ERR "hid-lg2ff: no output report found\n");
73 return -ENODEV;
74 }
75
76 report = list_entry(report_list->next, struct hid_report, list);
77
78 if (report->maxfield < 1) {
79 printk(KERN_ERR "hid-lg2ff: output report is empty\n");
80 return -ENODEV;
81 }
82 if (report->field[0]->report_count < 7) {
83 printk(KERN_ERR "hid-lg2ff: not enough values in the field\n");
84 return -ENODEV;
85 }
86
87 lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
88 if (!lg2ff)
89 return -ENOMEM;
90
91 set_bit(FF_RUMBLE, dev->ffbit);
92
93 error = input_ff_create_memless(dev, lg2ff, play_effect);
94 if (error) {
95 kfree(lg2ff);
96 return error;
97 }
98
99 lg2ff->report = report;
100 report->field[0]->value[0] = 0xf3;
101 report->field[0]->value[1] = 0x00;
102 report->field[0]->value[2] = 0x00;
103 report->field[0]->value[3] = 0x00;
104 report->field[0]->value[4] = 0x00;
105 report->field[0]->value[5] = 0x00;
106 report->field[0]->value[6] = 0x00;
107
108 usbhid_submit_report(hid, report, USB_DIR_OUT);
109
110 printk(KERN_INFO "Force feedback for Logitech Rumblepad 2 by "
111 "Anssi Hannula <anssi.hannula@gmail.com>\n");
112
113 return 0;
114}
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index e29a057cbea2..28ddc3fdd3d1 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -32,6 +32,9 @@
32#define USB_VENDOR_ID_ADS_TECH 0x06e1 32#define USB_VENDOR_ID_ADS_TECH 0x06e1
33#define USB_DEVICE_ID_ADS_TECH_RADIO_SI470X 0xa155 33#define USB_DEVICE_ID_ADS_TECH_RADIO_SI470X 0xa155
34 34
35#define USB_VENDOR_ID_AFATECH 0x15a4
36#define USB_DEVICE_ID_AFATECH_AF9016 0x9016
37
35#define USB_VENDOR_ID_AIPTEK 0x08ca 38#define USB_VENDOR_ID_AIPTEK 0x08ca
36#define USB_DEVICE_ID_AIPTEK_01 0x0001 39#define USB_DEVICE_ID_AIPTEK_01 0x0001
37#define USB_DEVICE_ID_AIPTEK_10 0x0010 40#define USB_DEVICE_ID_AIPTEK_10 0x0010
@@ -124,6 +127,9 @@
124#define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100 127#define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100
125#define USB_DEVICE_ID_DELORME_EM_LT20 0x0200 128#define USB_DEVICE_ID_DELORME_EM_LT20 0x0200
126 129
130#define USB_VENDOR_ID_DMI 0x0c0b
131#define USB_DEVICE_ID_DMI_ENC 0x5fab
132
127#define USB_VENDOR_ID_ELO 0x04E7 133#define USB_VENDOR_ID_ELO 0x04E7
128#define USB_DEVICE_ID_ELO_TS2700 0x0020 134#define USB_DEVICE_ID_ELO_TS2700 0x0020
129 135
@@ -199,17 +205,6 @@
199#define USB_DEVICE_ID_GTCO_502 0x0502 205#define USB_DEVICE_ID_GTCO_502 0x0502
200#define USB_DEVICE_ID_GTCO_503 0x0503 206#define USB_DEVICE_ID_GTCO_503 0x0503
201#define USB_DEVICE_ID_GTCO_504 0x0504 207#define USB_DEVICE_ID_GTCO_504 0x0504
202#define USB_DEVICE_ID_GTCO_600 0x0600
203#define USB_DEVICE_ID_GTCO_601 0x0601
204#define USB_DEVICE_ID_GTCO_602 0x0602
205#define USB_DEVICE_ID_GTCO_603 0x0603
206#define USB_DEVICE_ID_GTCO_604 0x0604
207#define USB_DEVICE_ID_GTCO_605 0x0605
208#define USB_DEVICE_ID_GTCO_606 0x0606
209#define USB_DEVICE_ID_GTCO_607 0x0607
210#define USB_DEVICE_ID_GTCO_608 0x0608
211#define USB_DEVICE_ID_GTCO_609 0x0609
212#define USB_DEVICE_ID_GTCO_609 0x0609
213#define USB_DEVICE_ID_GTCO_1000 0x1000 208#define USB_DEVICE_ID_GTCO_1000 0x1000
214#define USB_DEVICE_ID_GTCO_1001 0x1001 209#define USB_DEVICE_ID_GTCO_1001 0x1001
215#define USB_DEVICE_ID_GTCO_1002 0x1002 210#define USB_DEVICE_ID_GTCO_1002 0x1002
@@ -320,6 +315,7 @@
320#define USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xc512 315#define USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xc512
321#define USB_DEVICE_ID_MX3000_RECEIVER 0xc513 316#define USB_DEVICE_ID_MX3000_RECEIVER 0xc513
322#define USB_DEVICE_ID_DINOVO_EDGE 0xc714 317#define USB_DEVICE_ID_DINOVO_EDGE 0xc714
318#define USB_DEVICE_ID_DINOVO_MINI 0xc71f
323 319
324#define USB_VENDOR_ID_MCC 0x09db 320#define USB_VENDOR_ID_MCC 0x09db
325#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076 321#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076
@@ -332,6 +328,7 @@
332#define USB_VENDOR_ID_MICROSOFT 0x045e 328#define USB_VENDOR_ID_MICROSOFT 0x045e
333#define USB_DEVICE_ID_SIDEWINDER_GV 0x003b 329#define USB_DEVICE_ID_SIDEWINDER_GV 0x003b
334#define USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0 0x009d 330#define USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0 0x009d
331#define USB_DEVICE_ID_DESKTOP_RECV_1028 0x00f9
335#define USB_DEVICE_ID_MS_NE4K 0x00db 332#define USB_DEVICE_ID_MS_NE4K 0x00db
336#define USB_DEVICE_ID_MS_LK6K 0x00f9 333#define USB_DEVICE_ID_MS_LK6K 0x00f9
337 334
@@ -377,6 +374,9 @@
377#define USB_VENDOR_ID_SUN 0x0430 374#define USB_VENDOR_ID_SUN 0x0430
378#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab 375#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
379 376
377#define USB_VENDOR_ID_SUNPLUS 0x04fc
378#define USB_DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8
379
380#define USB_VENDOR_ID_TOPMAX 0x0663 380#define USB_VENDOR_ID_TOPMAX 0x0663
381#define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103 381#define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103
382 382
@@ -435,9 +435,13 @@ static const struct hid_blacklist {
435 { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD }, 435 { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
436 436
437 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE, HID_QUIRK_DUPLICATE_USAGES }, 437 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE, HID_QUIRK_DUPLICATE_USAGES },
438 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI, HID_QUIRK_DUPLICATE_USAGES },
439
440 { USB_VENDOR_ID_AFATECH, USB_DEVICE_ID_AFATECH_AF9016, HID_QUIRK_FULLSPEED_INTERVAL },
438 441
439 { USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM, HID_QUIRK_HIDDEV }, 442 { USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM, HID_QUIRK_HIDDEV },
440 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4, HID_QUIRK_HIDDEV | HID_QUIRK_IGNORE_HIDINPUT }, 443 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4, HID_QUIRK_HIDDEV | HID_QUIRK_IGNORE_HIDINPUT },
444 { USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE, HID_QUIRK_HIDDEV | HID_QUIRK_IGNORE_HIDINPUT },
441 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV, HID_QUIRK_HIDINPUT }, 445 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV, HID_QUIRK_HIDINPUT },
442 446
443 { USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193, HID_QUIRK_HWHEEL_WHEEL_INVERT }, 447 { USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193, HID_QUIRK_HWHEEL_WHEEL_INVERT },
@@ -518,16 +522,6 @@ static const struct hid_blacklist {
518 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502, HID_QUIRK_IGNORE }, 522 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502, HID_QUIRK_IGNORE },
519 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503, HID_QUIRK_IGNORE }, 523 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503, HID_QUIRK_IGNORE },
520 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504, HID_QUIRK_IGNORE }, 524 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504, HID_QUIRK_IGNORE },
521 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_600, HID_QUIRK_IGNORE },
522 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_601, HID_QUIRK_IGNORE },
523 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_602, HID_QUIRK_IGNORE },
524 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_603, HID_QUIRK_IGNORE },
525 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_604, HID_QUIRK_IGNORE },
526 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_605, HID_QUIRK_IGNORE },
527 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_606, HID_QUIRK_IGNORE },
528 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_607, HID_QUIRK_IGNORE },
529 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_608, HID_QUIRK_IGNORE },
530 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_609, HID_QUIRK_IGNORE },
531 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000, HID_QUIRK_IGNORE }, 525 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000, HID_QUIRK_IGNORE },
532 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001, HID_QUIRK_IGNORE }, 526 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001, HID_QUIRK_IGNORE },
533 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002, HID_QUIRK_IGNORE }, 527 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002, HID_QUIRK_IGNORE },
@@ -601,6 +595,7 @@ static const struct hid_blacklist {
601 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, 595 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
602 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET }, 596 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET },
603 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, 597 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
598 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET },
604 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, 599 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET },
605 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D, HID_QUIRK_NOGET }, 600 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D, HID_QUIRK_NOGET },
606 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL, HID_QUIRK_NOGET }, 601 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL, HID_QUIRK_NOGET },
@@ -608,7 +603,7 @@ static const struct hid_blacklist {
608 { USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE, HID_QUIRK_NOGET }, 603 { USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE, HID_QUIRK_NOGET },
609 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, 604 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
610 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, 605 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
611 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 606 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS },
612 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_QUAD_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 607 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_QUAD_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
613 608
614 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 609 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
@@ -719,6 +714,7 @@ static const struct hid_rdesc_blacklist {
719 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER, HID_QUIRK_RDESC_LOGITECH }, 714 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER, HID_QUIRK_RDESC_LOGITECH },
720 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER, HID_QUIRK_RDESC_LOGITECH }, 715 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER, HID_QUIRK_RDESC_LOGITECH },
721 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2, HID_QUIRK_RDESC_LOGITECH }, 716 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2, HID_QUIRK_RDESC_LOGITECH },
717 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_DESKTOP_RECV_1028, HID_QUIRK_RDESC_MICROSOFT_RECV_1028 },
722 718
723 { USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E, HID_QUIRK_RDESC_BUTTON_CONSUMER }, 719 { USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E, HID_QUIRK_RDESC_BUTTON_CONSUMER },
724 720
@@ -728,6 +724,8 @@ static const struct hid_rdesc_blacklist {
728 724
729 { USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE, HID_QUIRK_RDESC_SAMSUNG_REMOTE }, 725 { USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE, HID_QUIRK_RDESC_SAMSUNG_REMOTE },
730 726
727 { USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP, HID_QUIRK_RDESC_SUNPLUS_WDESKTOP },
728
731 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1, HID_QUIRK_RDESC_SWAPPED_MIN_MAX }, 729 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1, HID_QUIRK_RDESC_SWAPPED_MIN_MAX },
732 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2, HID_QUIRK_RDESC_SWAPPED_MIN_MAX }, 730 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2, HID_QUIRK_RDESC_SWAPPED_MIN_MAX },
733 731
@@ -793,8 +791,8 @@ static struct hid_blacklist *usbhid_exists_dquirk(const u16 idVendor,
793 * 791 *
794 * Returns: 0 OK, -error on failure. 792 * Returns: 0 OK, -error on failure.
795 */ 793 */
796int usbhid_modify_dquirk(const u16 idVendor, const u16 idProduct, 794static int usbhid_modify_dquirk(const u16 idVendor, const u16 idProduct,
797 const u32 quirks) 795 const u32 quirks)
798{ 796{
799 struct quirks_list_struct *q_new, *q; 797 struct quirks_list_struct *q_new, *q;
800 int list_edited = 0; 798 int list_edited = 0;
@@ -1002,6 +1000,17 @@ static void usbhid_fixup_logitech_descriptor(unsigned char *rdesc, int rsize)
1002 } 1000 }
1003} 1001}
1004 1002
1003static void usbhid_fixup_sunplus_wdesktop(unsigned char *rdesc, int rsize)
1004{
1005 if (rsize >= 107 && rdesc[104] == 0x26
1006 && rdesc[105] == 0x80
1007 && rdesc[106] == 0x03) {
1008 printk(KERN_INFO "Fixing up Sunplus Wireless Desktop report descriptor\n");
1009 rdesc[105] = rdesc[110] = 0x03;
1010 rdesc[106] = rdesc[111] = 0x21;
1011 }
1012}
1013
1005/* 1014/*
1006 * Samsung IrDA remote controller (reports as Cypress USB Mouse). 1015 * Samsung IrDA remote controller (reports as Cypress USB Mouse).
1007 * 1016 *
@@ -1089,6 +1098,28 @@ static void usbhid_fixup_button_consumer_descriptor(unsigned char *rdesc, int rs
1089 } 1098 }
1090} 1099}
1091 1100
1101/*
1102 * Microsoft Wireless Desktop Receiver (Model 1028) has several
1103 * 'Usage Min/Max' where it ought to have 'Physical Min/Max'
1104 */
1105static void usbhid_fixup_microsoft_descriptor(unsigned char *rdesc, int rsize)
1106{
1107 if (rsize == 571 && rdesc[284] == 0x19
1108 && rdesc[286] == 0x2a
1109 && rdesc[304] == 0x19
1110 && rdesc[306] == 0x29
1111 && rdesc[352] == 0x1a
1112 && rdesc[355] == 0x2a
1113 && rdesc[557] == 0x19
1114 && rdesc[559] == 0x29) {
1115 printk(KERN_INFO "Fixing up Microsoft Wireless Receiver Model 1028 report descriptor\n");
1116 rdesc[284] = rdesc[304] = rdesc[558] = 0x35;
1117 rdesc[352] = 0x36;
1118 rdesc[286] = rdesc[355] = 0x46;
1119 rdesc[306] = rdesc[559] = 0x45;
1120 }
1121}
1122
1092static void __usbhid_fixup_report_descriptor(__u32 quirks, char *rdesc, unsigned rsize) 1123static void __usbhid_fixup_report_descriptor(__u32 quirks, char *rdesc, unsigned rsize)
1093{ 1124{
1094 if ((quirks & HID_QUIRK_RDESC_CYMOTION)) 1125 if ((quirks & HID_QUIRK_RDESC_CYMOTION))
@@ -1112,6 +1143,11 @@ static void __usbhid_fixup_report_descriptor(__u32 quirks, char *rdesc, unsigned
1112 if (quirks & HID_QUIRK_RDESC_SAMSUNG_REMOTE) 1143 if (quirks & HID_QUIRK_RDESC_SAMSUNG_REMOTE)
1113 usbhid_fixup_samsung_irda_descriptor(rdesc, rsize); 1144 usbhid_fixup_samsung_irda_descriptor(rdesc, rsize);
1114 1145
1146 if (quirks & HID_QUIRK_RDESC_MICROSOFT_RECV_1028)
1147 usbhid_fixup_microsoft_descriptor(rdesc, rsize);
1148
1149 if (quirks & HID_QUIRK_RDESC_SUNPLUS_WDESKTOP)
1150 usbhid_fixup_sunplus_wdesktop(rdesc, rsize);
1115} 1151}
1116 1152
1117/** 1153/**
@@ -1150,5 +1186,4 @@ void usbhid_fixup_report_descriptor(const u16 idVendor, const u16 idProduct,
1150 else if (paramVendor == idVendor && paramProduct == idProduct) 1186 else if (paramVendor == idVendor && paramProduct == idProduct)
1151 __usbhid_fixup_report_descriptor(quirks, rdesc, rsize); 1187 __usbhid_fixup_report_descriptor(quirks, rdesc, rsize);
1152 } 1188 }
1153
1154} 1189}
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index 5fc4019956ba..95cc192bc7af 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -393,6 +393,153 @@ static unsigned int hiddev_poll(struct file *file, poll_table *wait)
393/* 393/*
394 * "ioctl" file op 394 * "ioctl" file op
395 */ 395 */
396static noinline int hiddev_ioctl_usage(struct hiddev *hiddev, unsigned int cmd, void __user *user_arg)
397{
398 struct hid_device *hid = hiddev->hid;
399 struct hiddev_report_info rinfo;
400 struct hiddev_usage_ref_multi *uref_multi = NULL;
401 struct hiddev_usage_ref *uref;
402 struct hid_report *report;
403 struct hid_field *field;
404 int i;
405
406 uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL);
407 if (!uref_multi)
408 return -ENOMEM;
409 uref = &uref_multi->uref;
410 if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) {
411 if (copy_from_user(uref_multi, user_arg,
412 sizeof(*uref_multi)))
413 goto fault;
414 } else {
415 if (copy_from_user(uref, user_arg, sizeof(*uref)))
416 goto fault;
417 }
418
419 switch (cmd) {
420 case HIDIOCGUCODE:
421 rinfo.report_type = uref->report_type;
422 rinfo.report_id = uref->report_id;
423 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
424 goto inval;
425
426 if (uref->field_index >= report->maxfield)
427 goto inval;
428
429 field = report->field[uref->field_index];
430 if (uref->usage_index >= field->maxusage)
431 goto inval;
432
433 uref->usage_code = field->usage[uref->usage_index].hid;
434
435 if (copy_to_user(user_arg, uref, sizeof(*uref)))
436 goto fault;
437
438 kfree(uref_multi);
439 return 0;
440
441 default:
442 if (cmd != HIDIOCGUSAGE &&
443 cmd != HIDIOCGUSAGES &&
444 uref->report_type == HID_REPORT_TYPE_INPUT)
445 goto inval;
446
447 if (uref->report_id == HID_REPORT_ID_UNKNOWN) {
448 field = hiddev_lookup_usage(hid, uref);
449 if (field == NULL)
450 goto inval;
451 } else {
452 rinfo.report_type = uref->report_type;
453 rinfo.report_id = uref->report_id;
454 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
455 goto inval;
456
457 if (uref->field_index >= report->maxfield)
458 goto inval;
459
460 field = report->field[uref->field_index];
461
462 if (cmd == HIDIOCGCOLLECTIONINDEX) {
463 if (uref->usage_index >= field->maxusage)
464 goto inval;
465 } else if (uref->usage_index >= field->report_count)
466 goto inval;
467
468 else if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) &&
469 (uref_multi->num_values > HID_MAX_MULTI_USAGES ||
470 uref->usage_index + uref_multi->num_values > field->report_count))
471 goto inval;
472 }
473
474 switch (cmd) {
475 case HIDIOCGUSAGE:
476 uref->value = field->value[uref->usage_index];
477 if (copy_to_user(user_arg, uref, sizeof(*uref)))
478 goto fault;
479 goto goodreturn;
480
481 case HIDIOCSUSAGE:
482 field->value[uref->usage_index] = uref->value;
483 goto goodreturn;
484
485 case HIDIOCGCOLLECTIONINDEX:
486 kfree(uref_multi);
487 return field->usage[uref->usage_index].collection_index;
488 case HIDIOCGUSAGES:
489 for (i = 0; i < uref_multi->num_values; i++)
490 uref_multi->values[i] =
491 field->value[uref->usage_index + i];
492 if (copy_to_user(user_arg, uref_multi,
493 sizeof(*uref_multi)))
494 goto fault;
495 goto goodreturn;
496 case HIDIOCSUSAGES:
497 for (i = 0; i < uref_multi->num_values; i++)
498 field->value[uref->usage_index + i] =
499 uref_multi->values[i];
500 goto goodreturn;
501 }
502
503goodreturn:
504 kfree(uref_multi);
505 return 0;
506fault:
507 kfree(uref_multi);
508 return -EFAULT;
509inval:
510 kfree(uref_multi);
511 return -EINVAL;
512 }
513}
514
515static noinline int hiddev_ioctl_string(struct hiddev *hiddev, unsigned int cmd, void __user *user_arg)
516{
517 struct hid_device *hid = hiddev->hid;
518 struct usb_device *dev = hid_to_usb_dev(hid);
519 int idx, len;
520 char *buf;
521
522 if (get_user(idx, (int __user *)user_arg))
523 return -EFAULT;
524
525 if ((buf = kmalloc(HID_STRING_SIZE, GFP_KERNEL)) == NULL)
526 return -ENOMEM;
527
528 if ((len = usb_string(dev, idx, buf, HID_STRING_SIZE-1)) < 0) {
529 kfree(buf);
530 return -EINVAL;
531 }
532
533 if (copy_to_user(user_arg+sizeof(int), buf, len+1)) {
534 kfree(buf);
535 return -EFAULT;
536 }
537
538 kfree(buf);
539
540 return len;
541}
542
396static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 543static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
397{ 544{
398 struct hiddev_list *list = file->private_data; 545 struct hiddev_list *list = file->private_data;
@@ -402,8 +549,6 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
402 struct hiddev_collection_info cinfo; 549 struct hiddev_collection_info cinfo;
403 struct hiddev_report_info rinfo; 550 struct hiddev_report_info rinfo;
404 struct hiddev_field_info finfo; 551 struct hiddev_field_info finfo;
405 struct hiddev_usage_ref_multi *uref_multi = NULL;
406 struct hiddev_usage_ref *uref;
407 struct hiddev_devinfo dinfo; 552 struct hiddev_devinfo dinfo;
408 struct hid_report *report; 553 struct hid_report *report;
409 struct hid_field *field; 554 struct hid_field *field;
@@ -470,30 +615,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
470 } 615 }
471 616
472 case HIDIOCGSTRING: 617 case HIDIOCGSTRING:
473 { 618 return hiddev_ioctl_string(hiddev, cmd, user_arg);
474 int idx, len;
475 char *buf;
476
477 if (get_user(idx, (int __user *)arg))
478 return -EFAULT;
479
480 if ((buf = kmalloc(HID_STRING_SIZE, GFP_KERNEL)) == NULL)
481 return -ENOMEM;
482
483 if ((len = usb_string(dev, idx, buf, HID_STRING_SIZE-1)) < 0) {
484 kfree(buf);
485 return -EINVAL;
486 }
487
488 if (copy_to_user(user_arg+sizeof(int), buf, len+1)) {
489 kfree(buf);
490 return -EFAULT;
491 }
492
493 kfree(buf);
494
495 return len;
496 }
497 619
498 case HIDIOCINITREPORT: 620 case HIDIOCINITREPORT:
499 usbhid_init_reports(hid); 621 usbhid_init_reports(hid);
@@ -578,121 +700,13 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
578 return 0; 700 return 0;
579 701
580 case HIDIOCGUCODE: 702 case HIDIOCGUCODE:
581 uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL); 703 /* fall through */
582 if (!uref_multi)
583 return -ENOMEM;
584 uref = &uref_multi->uref;
585 if (copy_from_user(uref, user_arg, sizeof(*uref)))
586 goto fault;
587
588 rinfo.report_type = uref->report_type;
589 rinfo.report_id = uref->report_id;
590 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
591 goto inval;
592
593 if (uref->field_index >= report->maxfield)
594 goto inval;
595
596 field = report->field[uref->field_index];
597 if (uref->usage_index >= field->maxusage)
598 goto inval;
599
600 uref->usage_code = field->usage[uref->usage_index].hid;
601
602 if (copy_to_user(user_arg, uref, sizeof(*uref)))
603 goto fault;
604
605 kfree(uref_multi);
606 return 0;
607
608 case HIDIOCGUSAGE: 704 case HIDIOCGUSAGE:
609 case HIDIOCSUSAGE: 705 case HIDIOCSUSAGE:
610 case HIDIOCGUSAGES: 706 case HIDIOCGUSAGES:
611 case HIDIOCSUSAGES: 707 case HIDIOCSUSAGES:
612 case HIDIOCGCOLLECTIONINDEX: 708 case HIDIOCGCOLLECTIONINDEX:
613 uref_multi = kmalloc(sizeof(struct hiddev_usage_ref_multi), GFP_KERNEL); 709 return hiddev_ioctl_usage(hiddev, cmd, user_arg);
614 if (!uref_multi)
615 return -ENOMEM;
616 uref = &uref_multi->uref;
617 if (cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) {
618 if (copy_from_user(uref_multi, user_arg,
619 sizeof(*uref_multi)))
620 goto fault;
621 } else {
622 if (copy_from_user(uref, user_arg, sizeof(*uref)))
623 goto fault;
624 }
625
626 if (cmd != HIDIOCGUSAGE &&
627 cmd != HIDIOCGUSAGES &&
628 uref->report_type == HID_REPORT_TYPE_INPUT)
629 goto inval;
630
631 if (uref->report_id == HID_REPORT_ID_UNKNOWN) {
632 field = hiddev_lookup_usage(hid, uref);
633 if (field == NULL)
634 goto inval;
635 } else {
636 rinfo.report_type = uref->report_type;
637 rinfo.report_id = uref->report_id;
638 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
639 goto inval;
640
641 if (uref->field_index >= report->maxfield)
642 goto inval;
643
644 field = report->field[uref->field_index];
645
646 if (cmd == HIDIOCGCOLLECTIONINDEX) {
647 if (uref->usage_index >= field->maxusage)
648 goto inval;
649 } else if (uref->usage_index >= field->report_count)
650 goto inval;
651
652 else if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) &&
653 (uref_multi->num_values > HID_MAX_MULTI_USAGES ||
654 uref->usage_index + uref_multi->num_values > field->report_count))
655 goto inval;
656 }
657
658 switch (cmd) {
659 case HIDIOCGUSAGE:
660 uref->value = field->value[uref->usage_index];
661 if (copy_to_user(user_arg, uref, sizeof(*uref)))
662 goto fault;
663 goto goodreturn;
664
665 case HIDIOCSUSAGE:
666 field->value[uref->usage_index] = uref->value;
667 goto goodreturn;
668
669 case HIDIOCGCOLLECTIONINDEX:
670 kfree(uref_multi);
671 return field->usage[uref->usage_index].collection_index;
672 case HIDIOCGUSAGES:
673 for (i = 0; i < uref_multi->num_values; i++)
674 uref_multi->values[i] =
675 field->value[uref->usage_index + i];
676 if (copy_to_user(user_arg, uref_multi,
677 sizeof(*uref_multi)))
678 goto fault;
679 goto goodreturn;
680 case HIDIOCSUSAGES:
681 for (i = 0; i < uref_multi->num_values; i++)
682 field->value[uref->usage_index + i] =
683 uref_multi->values[i];
684 goto goodreturn;
685 }
686
687goodreturn:
688 kfree(uref_multi);
689 return 0;
690fault:
691 kfree(uref_multi);
692 return -EFAULT;
693inval:
694 kfree(uref_multi);
695 return -EINVAL;
696 710
697 case HIDIOCGCOLLECTIONINFO: 711 case HIDIOCGCOLLECTIONINFO:
698 if (copy_from_user(&cinfo, user_arg, sizeof(cinfo))) 712 if (copy_from_user(&cinfo, user_arg, sizeof(cinfo)))
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index 0023f96d4294..62d2d7c925bd 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -28,6 +28,7 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/list.h> 29#include <linux/list.h>
30#include <linux/timer.h> 30#include <linux/timer.h>
31#include <linux/wait.h>
31#include <linux/workqueue.h> 32#include <linux/workqueue.h>
32#include <linux/input.h> 33#include <linux/input.h>
33 34
@@ -77,7 +78,7 @@ struct usbhid_device {
77 unsigned long stop_retry; /* Time to give up, in jiffies */ 78 unsigned long stop_retry; /* Time to give up, in jiffies */
78 unsigned int retry_delay; /* Delay length in ms */ 79 unsigned int retry_delay; /* Delay length in ms */
79 struct work_struct reset_work; /* Task context for resets */ 80 struct work_struct reset_work; /* Task context for resets */
80 81 wait_queue_head_t wait; /* For sleeping */
81}; 82};
82 83
83#define hid_to_usb_dev(hid_dev) \ 84#define hid_to_usb_dev(hid_dev) \
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig
index 014dfa575be7..7137a17402fe 100644
--- a/drivers/i2c/algos/Kconfig
+++ b/drivers/i2c/algos/Kconfig
@@ -1,45 +1,16 @@
1# 1#
2# Character device configuration 2# I2C algorithm drivers configuration
3# 3#
4 4
5menu "I2C Algorithms"
6
7config I2C_ALGOBIT 5config I2C_ALGOBIT
8 tristate "I2C bit-banging interfaces" 6 tristate
9 help
10 This allows you to use a range of I2C adapters called bit-banging
11 adapters. Say Y if you own an I2C adapter belonging to this class
12 and then say Y to the specific driver for you adapter below.
13
14 This support is also available as a module. If so, the module
15 will be called i2c-algo-bit.
16 7
17config I2C_ALGOPCF 8config I2C_ALGOPCF
18 tristate "I2C PCF 8584 interfaces" 9 tristate
19 help
20 This allows you to use a range of I2C adapters called PCF adapters.
21 Say Y if you own an I2C adapter belonging to this class and then say
22 Y to the specific driver for you adapter below.
23
24 This support is also available as a module. If so, the module
25 will be called i2c-algo-pcf.
26 10
27config I2C_ALGOPCA 11config I2C_ALGOPCA
28 tristate "I2C PCA 9564 interfaces" 12 tristate
29 help
30 This allows you to use a range of I2C adapters called PCA adapters.
31 Say Y if you own an I2C adapter belonging to this class and then say
32 Y to the specific driver for you adapter below.
33
34 This support is also available as a module. If so, the module
35 will be called i2c-algo-pca.
36 13
37config I2C_ALGO_SGI 14config I2C_ALGO_SGI
38 tristate "I2C SGI interfaces" 15 tristate
39 depends on SGI_IP22 || SGI_IP32 || X86_VISWS 16 depends on SGI_IP22 || SGI_IP32 || X86_VISWS
40 help
41 Supports the SGI interfaces like the ones found on SGI Indy VINO
42 or SGI O2 MACE.
43
44endmenu
45
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index 2a16211f12e5..e954a20b97a6 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * i2c-algo-pca.c i2c driver algorithms for PCA9564 adapters 2 * i2c-algo-pca.c i2c driver algorithms for PCA9564 adapters
3 * Copyright (C) 2004 Arcom Control Systems 3 * Copyright (C) 2004 Arcom Control Systems
4 * Copyright (C) 2008 Pengutronix
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -21,14 +22,10 @@
21#include <linux/module.h> 22#include <linux/module.h>
22#include <linux/moduleparam.h> 23#include <linux/moduleparam.h>
23#include <linux/delay.h> 24#include <linux/delay.h>
24#include <linux/slab.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/i2c-algo-pca.h> 28#include <linux/i2c-algo-pca.h>
29#include "i2c-algo-pca.h"
30
31#define DRIVER "i2c-algo-pca"
32 29
33#define DEB1(fmt, args...) do { if (i2c_debug>=1) printk(fmt, ## args); } while(0) 30#define DEB1(fmt, args...) do { if (i2c_debug>=1) printk(fmt, ## args); } while(0)
34#define DEB2(fmt, args...) do { if (i2c_debug>=2) printk(fmt, ## args); } while(0) 31#define DEB2(fmt, args...) do { if (i2c_debug>=2) printk(fmt, ## args); } while(0)
@@ -36,15 +33,15 @@
36 33
37static int i2c_debug; 34static int i2c_debug;
38 35
39#define pca_outw(adap, reg, val) adap->write_byte(adap, reg, val) 36#define pca_outw(adap, reg, val) adap->write_byte(adap->data, reg, val)
40#define pca_inw(adap, reg) adap->read_byte(adap, reg) 37#define pca_inw(adap, reg) adap->read_byte(adap->data, reg)
41 38
42#define pca_status(adap) pca_inw(adap, I2C_PCA_STA) 39#define pca_status(adap) pca_inw(adap, I2C_PCA_STA)
43#define pca_clock(adap) adap->get_clock(adap) 40#define pca_clock(adap) adap->i2c_clock
44#define pca_own(adap) adap->get_own(adap)
45#define pca_set_con(adap, val) pca_outw(adap, I2C_PCA_CON, val) 41#define pca_set_con(adap, val) pca_outw(adap, I2C_PCA_CON, val)
46#define pca_get_con(adap) pca_inw(adap, I2C_PCA_CON) 42#define pca_get_con(adap) pca_inw(adap, I2C_PCA_CON)
47#define pca_wait(adap) adap->wait_for_interrupt(adap) 43#define pca_wait(adap) adap->wait_for_completion(adap->data)
44#define pca_reset(adap) adap->reset_chip(adap->data)
48 45
49/* 46/*
50 * Generate a start condition on the i2c bus. 47 * Generate a start condition on the i2c bus.
@@ -99,7 +96,7 @@ static void pca_stop(struct i2c_algo_pca_data *adap)
99 * 96 *
100 * returns after the address has been sent 97 * returns after the address has been sent
101 */ 98 */
102static void pca_address(struct i2c_algo_pca_data *adap, 99static void pca_address(struct i2c_algo_pca_data *adap,
103 struct i2c_msg *msg) 100 struct i2c_msg *msg)
104{ 101{
105 int sta = pca_get_con(adap); 102 int sta = pca_get_con(adap);
@@ -108,9 +105,9 @@ static void pca_address(struct i2c_algo_pca_data *adap,
108 addr = ( (0x7f & msg->addr) << 1 ); 105 addr = ( (0x7f & msg->addr) << 1 );
109 if (msg->flags & I2C_M_RD ) 106 if (msg->flags & I2C_M_RD )
110 addr |= 1; 107 addr |= 1;
111 DEB2("=== SLAVE ADDRESS %#04x+%c=%#04x\n", 108 DEB2("=== SLAVE ADDRESS %#04x+%c=%#04x\n",
112 msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W', addr); 109 msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W', addr);
113 110
114 pca_outw(adap, I2C_PCA_DAT, addr); 111 pca_outw(adap, I2C_PCA_DAT, addr);
115 112
116 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_STA|I2C_PCA_CON_SI); 113 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_STA|I2C_PCA_CON_SI);
@@ -124,7 +121,7 @@ static void pca_address(struct i2c_algo_pca_data *adap,
124 * 121 *
125 * Returns after the byte has been transmitted 122 * Returns after the byte has been transmitted
126 */ 123 */
127static void pca_tx_byte(struct i2c_algo_pca_data *adap, 124static void pca_tx_byte(struct i2c_algo_pca_data *adap,
128 __u8 b) 125 __u8 b)
129{ 126{
130 int sta = pca_get_con(adap); 127 int sta = pca_get_con(adap);
@@ -142,19 +139,19 @@ static void pca_tx_byte(struct i2c_algo_pca_data *adap,
142 * 139 *
143 * returns immediately. 140 * returns immediately.
144 */ 141 */
145static void pca_rx_byte(struct i2c_algo_pca_data *adap, 142static void pca_rx_byte(struct i2c_algo_pca_data *adap,
146 __u8 *b, int ack) 143 __u8 *b, int ack)
147{ 144{
148 *b = pca_inw(adap, I2C_PCA_DAT); 145 *b = pca_inw(adap, I2C_PCA_DAT);
149 DEB2("=== READ %#04x %s\n", *b, ack ? "ACK" : "NACK"); 146 DEB2("=== READ %#04x %s\n", *b, ack ? "ACK" : "NACK");
150} 147}
151 148
152/* 149/*
153 * Setup ACK or NACK for next received byte and wait for it to arrive. 150 * Setup ACK or NACK for next received byte and wait for it to arrive.
154 * 151 *
155 * Returns after next byte has arrived. 152 * Returns after next byte has arrived.
156 */ 153 */
157static void pca_rx_ack(struct i2c_algo_pca_data *adap, 154static void pca_rx_ack(struct i2c_algo_pca_data *adap,
158 int ack) 155 int ack)
159{ 156{
160 int sta = pca_get_con(adap); 157 int sta = pca_get_con(adap);
@@ -168,15 +165,6 @@ static void pca_rx_ack(struct i2c_algo_pca_data *adap,
168 pca_wait(adap); 165 pca_wait(adap);
169} 166}
170 167
171/*
172 * Reset the i2c bus / SIO
173 */
174static void pca_reset(struct i2c_algo_pca_data *adap)
175{
176 /* apparently only an external reset will do it. not a lot can be done */
177 printk(KERN_ERR DRIVER ": Haven't figured out how to do a reset yet\n");
178}
179
180static int pca_xfer(struct i2c_adapter *i2c_adap, 168static int pca_xfer(struct i2c_adapter *i2c_adap,
181 struct i2c_msg *msgs, 169 struct i2c_msg *msgs,
182 int num) 170 int num)
@@ -187,7 +175,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
187 int numbytes = 0; 175 int numbytes = 0;
188 int state; 176 int state;
189 int ret; 177 int ret;
190 int timeout = 100; 178 int timeout = i2c_adap->timeout;
191 179
192 while ((state = pca_status(adap)) != 0xf8 && timeout--) { 180 while ((state = pca_status(adap)) != 0xf8 && timeout--) {
193 msleep(10); 181 msleep(10);
@@ -203,14 +191,14 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
203 for (curmsg = 0; curmsg < num; curmsg++) { 191 for (curmsg = 0; curmsg < num; curmsg++) {
204 int addr, i; 192 int addr, i;
205 msg = &msgs[curmsg]; 193 msg = &msgs[curmsg];
206 194
207 addr = (0x7f & msg->addr) ; 195 addr = (0x7f & msg->addr) ;
208 196
209 if (msg->flags & I2C_M_RD ) 197 if (msg->flags & I2C_M_RD )
210 printk(KERN_INFO " [%02d] RD %d bytes from %#02x [%#02x, ...]\n", 198 printk(KERN_INFO " [%02d] RD %d bytes from %#02x [%#02x, ...]\n",
211 curmsg, msg->len, addr, (addr<<1) | 1); 199 curmsg, msg->len, addr, (addr<<1) | 1);
212 else { 200 else {
213 printk(KERN_INFO " [%02d] WR %d bytes to %#02x [%#02x%s", 201 printk(KERN_INFO " [%02d] WR %d bytes to %#02x [%#02x%s",
214 curmsg, msg->len, addr, addr<<1, 202 curmsg, msg->len, addr, addr<<1,
215 msg->len == 0 ? "" : ", "); 203 msg->len == 0 ? "" : ", ");
216 for(i=0; i < msg->len; i++) 204 for(i=0; i < msg->len; i++)
@@ -237,7 +225,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
237 case 0x10: /* A repeated start condition has been transmitted */ 225 case 0x10: /* A repeated start condition has been transmitted */
238 pca_address(adap, msg); 226 pca_address(adap, msg);
239 break; 227 break;
240 228
241 case 0x18: /* SLA+W has been transmitted; ACK has been received */ 229 case 0x18: /* SLA+W has been transmitted; ACK has been received */
242 case 0x28: /* Data byte in I2CDAT has been transmitted; ACK has been received */ 230 case 0x28: /* Data byte in I2CDAT has been transmitted; ACK has been received */
243 if (numbytes < msg->len) { 231 if (numbytes < msg->len) {
@@ -287,7 +275,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
287 case 0x38: /* Arbitration lost during SLA+W, SLA+R or data bytes */ 275 case 0x38: /* Arbitration lost during SLA+W, SLA+R or data bytes */
288 DEB2("Arbitration lost\n"); 276 DEB2("Arbitration lost\n");
289 goto out; 277 goto out;
290 278
291 case 0x58: /* Data byte has been received; NOT ACK has been returned */ 279 case 0x58: /* Data byte has been received; NOT ACK has been returned */
292 if ( numbytes == msg->len - 1 ) { 280 if ( numbytes == msg->len - 1 ) {
293 pca_rx_byte(adap, &msg->buf[numbytes], 0); 281 pca_rx_byte(adap, &msg->buf[numbytes], 0);
@@ -317,16 +305,16 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
317 pca_reset(adap); 305 pca_reset(adap);
318 goto out; 306 goto out;
319 default: 307 default:
320 printk(KERN_ERR DRIVER ": unhandled SIO state 0x%02x\n", state); 308 dev_err(&i2c_adap->dev, "unhandled SIO state 0x%02x\n", state);
321 break; 309 break;
322 } 310 }
323 311
324 } 312 }
325 313
326 ret = curmsg; 314 ret = curmsg;
327 out: 315 out:
328 DEB1(KERN_CRIT "}}} transfered %d/%d messages. " 316 DEB1(KERN_CRIT "}}} transfered %d/%d messages. "
329 "status is %#04x. control is %#04x\n", 317 "status is %#04x. control is %#04x\n",
330 curmsg, num, pca_status(adap), 318 curmsg, num, pca_status(adap),
331 pca_get_con(adap)); 319 pca_get_con(adap));
332 return ret; 320 return ret;
@@ -337,53 +325,65 @@ static u32 pca_func(struct i2c_adapter *adap)
337 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 325 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
338} 326}
339 327
340static int pca_init(struct i2c_algo_pca_data *adap) 328static const struct i2c_algorithm pca_algo = {
329 .master_xfer = pca_xfer,
330 .functionality = pca_func,
331};
332
333static int pca_init(struct i2c_adapter *adap)
341{ 334{
342 static int freqs[] = {330,288,217,146,88,59,44,36}; 335 static int freqs[] = {330,288,217,146,88,59,44,36};
343 int own, clock; 336 int clock;
337 struct i2c_algo_pca_data *pca_data = adap->algo_data;
338
339 if (pca_data->i2c_clock > 7) {
340 printk(KERN_WARNING "%s: Invalid I2C clock speed selected. Trying default.\n",
341 adap->name);
342 pca_data->i2c_clock = I2C_PCA_CON_59kHz;
343 }
344
345 adap->algo = &pca_algo;
344 346
345 own = pca_own(adap); 347 pca_reset(pca_data);
346 clock = pca_clock(adap);
347 DEB1(KERN_INFO DRIVER ": own address is %#04x\n", own);
348 DEB1(KERN_INFO DRIVER ": clock freqeuncy is %dkHz\n", freqs[clock]);
349 348
350 pca_outw(adap, I2C_PCA_ADR, own << 1); 349 clock = pca_clock(pca_data);
350 DEB1(KERN_INFO "%s: Clock frequency is %dkHz\n", adap->name, freqs[clock]);
351 351
352 pca_set_con(adap, I2C_PCA_CON_ENSIO | clock); 352 pca_set_con(pca_data, I2C_PCA_CON_ENSIO | clock);
353 udelay(500); /* 500 µs for oscilator to stabilise */ 353 udelay(500); /* 500 us for oscilator to stabilise */
354 354
355 return 0; 355 return 0;
356} 356}
357 357
358static const struct i2c_algorithm pca_algo = { 358/*
359 .master_xfer = pca_xfer, 359 * registering functions to load algorithms at runtime
360 .functionality = pca_func,
361};
362
363/*
364 * registering functions to load algorithms at runtime
365 */ 360 */
366int i2c_pca_add_bus(struct i2c_adapter *adap) 361int i2c_pca_add_bus(struct i2c_adapter *adap)
367{ 362{
368 struct i2c_algo_pca_data *pca_adap = adap->algo_data;
369 int rval; 363 int rval;
370 364
371 /* register new adapter to i2c module... */ 365 rval = pca_init(adap);
372 adap->algo = &pca_algo; 366 if (rval)
367 return rval;
373 368
374 adap->timeout = 100; /* default values, should */ 369 return i2c_add_adapter(adap);
375 adap->retries = 3; /* be replaced by defines */ 370}
371EXPORT_SYMBOL(i2c_pca_add_bus);
376 372
377 if ((rval = pca_init(pca_adap))) 373int i2c_pca_add_numbered_bus(struct i2c_adapter *adap)
378 return rval; 374{
375 int rval;
379 376
380 rval = i2c_add_adapter(adap); 377 rval = pca_init(adap);
378 if (rval)
379 return rval;
381 380
382 return rval; 381 return i2c_add_numbered_adapter(adap);
383} 382}
384EXPORT_SYMBOL(i2c_pca_add_bus); 383EXPORT_SYMBOL(i2c_pca_add_numbered_bus);
385 384
386MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); 385MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>, "
386 "Wolfram Sang <w.sang@pengutronix.de>");
387MODULE_DESCRIPTION("I2C-Bus PCA9564 algorithm"); 387MODULE_DESCRIPTION("I2C-Bus PCA9564 algorithm");
388MODULE_LICENSE("GPL"); 388MODULE_LICENSE("GPL");
389 389
diff --git a/drivers/i2c/algos/i2c-algo-pca.h b/drivers/i2c/algos/i2c-algo-pca.h
deleted file mode 100644
index 2fee07e05211..000000000000
--- a/drivers/i2c/algos/i2c-algo-pca.h
+++ /dev/null
@@ -1,26 +0,0 @@
1#ifndef I2C_PCA9564_H
2#define I2C_PCA9564_H 1
3
4#define I2C_PCA_STA 0x00 /* STATUS Read Only */
5#define I2C_PCA_TO 0x00 /* TIMEOUT Write Only */
6#define I2C_PCA_DAT 0x01 /* DATA Read/Write */
7#define I2C_PCA_ADR 0x02 /* OWN ADR Read/Write */
8#define I2C_PCA_CON 0x03 /* CONTROL Read/Write */
9
10#define I2C_PCA_CON_AA 0x80 /* Assert Acknowledge */
11#define I2C_PCA_CON_ENSIO 0x40 /* Enable */
12#define I2C_PCA_CON_STA 0x20 /* Start */
13#define I2C_PCA_CON_STO 0x10 /* Stop */
14#define I2C_PCA_CON_SI 0x08 /* Serial Interrupt */
15#define I2C_PCA_CON_CR 0x07 /* Clock Rate (MASK) */
16
17#define I2C_PCA_CON_330kHz 0x00
18#define I2C_PCA_CON_288kHz 0x01
19#define I2C_PCA_CON_217kHz 0x02
20#define I2C_PCA_CON_146kHz 0x03
21#define I2C_PCA_CON_88kHz 0x04
22#define I2C_PCA_CON_59kHz 0x05
23#define I2C_PCA_CON_44kHz 0x06
24#define I2C_PCA_CON_36kHz 0x07
25
26#endif /* I2C_PCA9564_H */
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index b04c99580d0d..48438cc5d0ca 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -100,9 +100,12 @@ config I2C_AU1550
100 100
101config I2C_BLACKFIN_TWI 101config I2C_BLACKFIN_TWI
102 tristate "Blackfin TWI I2C support" 102 tristate "Blackfin TWI I2C support"
103 depends on BF534 || BF536 || BF537 103 depends on BLACKFIN
104 help 104 help
105 This is the TWI I2C device driver for Blackfin 534/536/537/54x. 105 This is the TWI I2C device driver for Blackfin BF522, BF525,
106 BF527, BF534, BF536, BF537 and BF54x. For other Blackfin processors,
107 please don't use this driver.
108
106 This driver can also be built as a module. If so, the module 109 This driver can also be built as a module. If so, the module
107 will be called i2c-bfin-twi. 110 will be called i2c-bfin-twi.
108 111
@@ -135,7 +138,7 @@ config I2C_ELEKTOR
135 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own 138 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own
136 such an adapter. 139 such an adapter.
137 140
138 This support is also available as a module. If so, the module 141 This support is also available as a module. If so, the module
139 will be called i2c-elektor. 142 will be called i2c-elektor.
140 143
141config I2C_GPIO 144config I2C_GPIO
@@ -190,7 +193,7 @@ config I2C_I810
190 select I2C_ALGOBIT 193 select I2C_ALGOBIT
191 help 194 help
192 If you say yes to this option, support will be included for the Intel 195 If you say yes to this option, support will be included for the Intel
193 810/815 family of mainboard I2C interfaces. Specifically, the 196 810/815 family of mainboard I2C interfaces. Specifically, the
194 following versions of the chipset are supported: 197 following versions of the chipset are supported:
195 i810AA 198 i810AA
196 i810AB 199 i810AB
@@ -246,10 +249,10 @@ config I2C_PIIX4
246 249
247config I2C_IBM_IIC 250config I2C_IBM_IIC
248 tristate "IBM PPC 4xx on-chip I2C interface" 251 tristate "IBM PPC 4xx on-chip I2C interface"
249 depends on IBM_OCP 252 depends on 4xx
250 help 253 help
251 Say Y here if you want to use IIC peripheral found on 254 Say Y here if you want to use IIC peripheral found on
252 embedded IBM PPC 4xx based systems. 255 embedded IBM PPC 4xx based systems.
253 256
254 This driver can also be built as a module. If so, the module 257 This driver can also be built as a module. If so, the module
255 will be called i2c-ibm_iic. 258 will be called i2c-ibm_iic.
@@ -269,7 +272,7 @@ config I2C_IXP2000
269 depends on ARCH_IXP2000 272 depends on ARCH_IXP2000
270 select I2C_ALGOBIT 273 select I2C_ALGOBIT
271 help 274 help
272 Say Y here if you have an Intel IXP2000 (2400, 2800, 2850) based 275 Say Y here if you have an Intel IXP2000 (2400, 2800, 2850) based
273 system and are using GPIO lines for an I2C bus. 276 system and are using GPIO lines for an I2C bus.
274 277
275 This support is also available as a module. If so, the module 278 This support is also available as a module. If so, the module
@@ -354,7 +357,7 @@ config I2C_PARPORT
354 on the parport driver. This is meant for embedded systems. Don't say 357 on the parport driver. This is meant for embedded systems. Don't say
355 Y here if you intend to say Y or M there. 358 Y here if you intend to say Y or M there.
356 359
357 This support is also available as a module. If so, the module 360 This support is also available as a module. If so, the module
358 will be called i2c-parport. 361 will be called i2c-parport.
359 362
360config I2C_PARPORT_LIGHT 363config I2C_PARPORT_LIGHT
@@ -372,12 +375,12 @@ config I2C_PARPORT_LIGHT
372 the clean but heavy parport handling is not an option. The 375 the clean but heavy parport handling is not an option. The
373 drawback is a reduced portability and the impossibility to 376 drawback is a reduced portability and the impossibility to
374 daisy-chain other parallel port devices. 377 daisy-chain other parallel port devices.
375 378
376 Don't say Y here if you said Y or M to i2c-parport. Saying M to 379 Don't say Y here if you said Y or M to i2c-parport. Saying M to
377 both is possible but both modules should not be loaded at the same 380 both is possible but both modules should not be loaded at the same
378 time. 381 time.
379 382
380 This support is also available as a module. If so, the module 383 This support is also available as a module. If so, the module
381 will be called i2c-parport-light. 384 will be called i2c-parport-light.
382 385
383config I2C_PASEMI 386config I2C_PASEMI
@@ -401,7 +404,7 @@ config I2C_PROSAVAGE
401 404
402 This driver is deprecated in favor of the savagefb driver. 405 This driver is deprecated in favor of the savagefb driver.
403 406
404 This support is also available as a module. If so, the module 407 This support is also available as a module. If so, the module
405 will be called i2c-prosavage. 408 will be called i2c-prosavage.
406 409
407config I2C_S3C2410 410config I2C_S3C2410
@@ -417,7 +420,7 @@ config I2C_SAVAGE4
417 depends on PCI 420 depends on PCI
418 select I2C_ALGOBIT 421 select I2C_ALGOBIT
419 help 422 help
420 If you say yes to this option, support will be included for the 423 If you say yes to this option, support will be included for the
421 S3 Savage 4 I2C interface. 424 S3 Savage 4 I2C interface.
422 425
423 This driver is deprecated in favor of the savagefb driver. 426 This driver is deprecated in favor of the savagefb driver.
@@ -452,7 +455,7 @@ config SCx200_I2C
452 455
453 If you don't know what to do here, say N. 456 If you don't know what to do here, say N.
454 457
455 This support is also available as a module. If so, the module 458 This support is also available as a module. If so, the module
456 will be called scx200_i2c. 459 will be called scx200_i2c.
457 460
458 This driver is deprecated and will be dropped soon. Use i2c-gpio 461 This driver is deprecated and will be dropped soon. Use i2c-gpio
@@ -483,14 +486,14 @@ config SCx200_ACB
483 486
484 If you don't know what to do here, say N. 487 If you don't know what to do here, say N.
485 488
486 This support is also available as a module. If so, the module 489 This support is also available as a module. If so, the module
487 will be called scx200_acb. 490 will be called scx200_acb.
488 491
489config I2C_SIS5595 492config I2C_SIS5595
490 tristate "SiS 5595" 493 tristate "SiS 5595"
491 depends on PCI 494 depends on PCI
492 help 495 help
493 If you say yes to this option, support will be included for the 496 If you say yes to this option, support will be included for the
494 SiS5595 SMBus (a subset of I2C) interface. 497 SiS5595 SMBus (a subset of I2C) interface.
495 498
496 This driver can also be built as a module. If so, the module 499 This driver can also be built as a module. If so, the module
@@ -500,7 +503,7 @@ config I2C_SIS630
500 tristate "SiS 630/730" 503 tristate "SiS 630/730"
501 depends on PCI 504 depends on PCI
502 help 505 help
503 If you say yes to this option, support will be included for the 506 If you say yes to this option, support will be included for the
504 SiS630 and SiS730 SMBus (a subset of I2C) interface. 507 SiS630 and SiS730 SMBus (a subset of I2C) interface.
505 508
506 This driver can also be built as a module. If so, the module 509 This driver can also be built as a module. If so, the module
@@ -632,9 +635,9 @@ config I2C_PCA_ISA
632 select I2C_ALGOPCA 635 select I2C_ALGOPCA
633 default n 636 default n
634 help 637 help
635 This driver supports ISA boards using the Philips PCA 9564 638 This driver supports ISA boards using the Philips PCA9564
636 Parallel bus to I2C bus controller 639 parallel bus to I2C bus controller.
637 640
638 This driver can also be built as a module. If so, the module 641 This driver can also be built as a module. If so, the module
639 will be called i2c-pca-isa. 642 will be called i2c-pca-isa.
640 643
@@ -643,6 +646,17 @@ config I2C_PCA_ISA
643 delays when I2C/SMBus chip drivers are loaded (e.g. at boot 646 delays when I2C/SMBus chip drivers are loaded (e.g. at boot
644 time). If unsure, say N. 647 time). If unsure, say N.
645 648
649config I2C_PCA_PLATFORM
650 tristate "PCA9564 as platform device"
651 select I2C_ALGOPCA
652 default n
653 help
654 This driver supports a memory mapped Philips PCA9564
655 parallel bus to I2C bus controller.
656
657 This driver can also be built as a module. If so, the module
658 will be called i2c-pca-platform.
659
646config I2C_MV64XXX 660config I2C_MV64XXX
647 tristate "Marvell mv64xxx I2C Controller" 661 tristate "Marvell mv64xxx I2C Controller"
648 depends on (MV64X60 || PLAT_ORION) && EXPERIMENTAL 662 depends on (MV64X60 || PLAT_ORION) && EXPERIMENTAL
@@ -672,4 +686,23 @@ config I2C_PMCMSP
672 This driver can also be built as module. If so, the module 686 This driver can also be built as module. If so, the module
673 will be called i2c-pmcmsp. 687 will be called i2c-pmcmsp.
674 688
689config I2C_SH7760
690 tristate "Renesas SH7760 I2C Controller"
691 depends on CPU_SUBTYPE_SH7760
692 help
693 This driver supports the 2 I2C interfaces on the Renesas SH7760.
694
695 This driver can also be built as a module. If so, the module
696 will be called i2c-sh7760.
697
698config I2C_SH_MOBILE
699 tristate "SuperH Mobile I2C Controller"
700 depends on SUPERH
701 help
702 If you say yes to this option, support will be included for the
703 built-in I2C interface on the Renesas SH-Mobile processor.
704
705 This driver can also be built as a module. If so, the module
706 will be called i2c-sh_mobile.
707
675endmenu 708endmenu
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index ea7068f1eb6b..e8c882a5ea66 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
30obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o 30obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
31obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o 31obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o
32obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o 32obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
33obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o
33obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o 34obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o
34obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o 35obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o
35obj-$(CONFIG_I2C_PNX) += i2c-pnx.o 36obj-$(CONFIG_I2C_PNX) += i2c-pnx.o
@@ -37,6 +38,8 @@ obj-$(CONFIG_I2C_PROSAVAGE) += i2c-prosavage.o
37obj-$(CONFIG_I2C_PXA) += i2c-pxa.o 38obj-$(CONFIG_I2C_PXA) += i2c-pxa.o
38obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o 39obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o
39obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o 40obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o
41obj-$(CONFIG_I2C_SH7760) += i2c-sh7760.o
42obj-$(CONFIG_I2C_SH_MOBILE) += i2c-sh_mobile.o
40obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o 43obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
41obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o 44obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o
42obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o 45obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index c09b036913bd..73d61946a534 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -298,7 +298,7 @@ static int at91_i2c_resume(struct platform_device *pdev)
298#endif 298#endif
299 299
300/* work with "modprobe at91_i2c" from hotplugging or coldplugging */ 300/* work with "modprobe at91_i2c" from hotplugging or coldplugging */
301MODULE_ALIAS("at91_i2c"); 301MODULE_ALIAS("platform:at91_i2c");
302 302
303static struct platform_driver at91_i2c_driver = { 303static struct platform_driver at91_i2c_driver = {
304 .probe = at91_i2c_probe, 304 .probe = at91_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index 1953b26da56a..491718fe46b7 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -472,6 +472,7 @@ i2c_au1550_exit(void)
472MODULE_AUTHOR("Dan Malek, Embedded Edge, LLC."); 472MODULE_AUTHOR("Dan Malek, Embedded Edge, LLC.");
473MODULE_DESCRIPTION("SMBus adapter Alchemy pb1550"); 473MODULE_DESCRIPTION("SMBus adapter Alchemy pb1550");
474MODULE_LICENSE("GPL"); 474MODULE_LICENSE("GPL");
475MODULE_ALIAS("platform:au1xpsc_smbus");
475 476
476module_init (i2c_au1550_init); 477module_init (i2c_au1550_init);
477module_exit (i2c_au1550_exit); 478module_exit (i2c_au1550_exit);
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 7dbdaeb707a9..48d084bdf7c8 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -1,25 +1,11 @@
1/* 1/*
2 * drivers/i2c/busses/i2c-bfin-twi.c 2 * Blackfin On-Chip Two Wire Interface Driver
3 * 3 *
4 * Description: Driver for Blackfin Two Wire Interface 4 * Copyright 2005-2007 Analog Devices Inc.
5 * 5 *
6 * Author: sonicz <sonic.zhang@analog.com> 6 * Enter bugs at http://blackfin.uclinux.org/
7 * 7 *
8 * Copyright (c) 2005-2007 Analog Devices, Inc. 8 * Licensed under the GPL-2 or later.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */ 9 */
24 10
25#include <linux/module.h> 11#include <linux/module.h>
@@ -34,14 +20,16 @@
34#include <linux/platform_device.h> 20#include <linux/platform_device.h>
35 21
36#include <asm/blackfin.h> 22#include <asm/blackfin.h>
23#include <asm/portmux.h>
37#include <asm/irq.h> 24#include <asm/irq.h>
38 25
39#define POLL_TIMEOUT (2 * HZ) 26#define POLL_TIMEOUT (2 * HZ)
40 27
41/* SMBus mode*/ 28/* SMBus mode*/
42#define TWI_I2C_MODE_STANDARD 0x01 29#define TWI_I2C_MODE_STANDARD 1
43#define TWI_I2C_MODE_STANDARDSUB 0x02 30#define TWI_I2C_MODE_STANDARDSUB 2
44#define TWI_I2C_MODE_COMBINED 0x04 31#define TWI_I2C_MODE_COMBINED 3
32#define TWI_I2C_MODE_REPEAT 4
45 33
46struct bfin_twi_iface { 34struct bfin_twi_iface {
47 int irq; 35 int irq;
@@ -58,39 +46,74 @@ struct bfin_twi_iface {
58 struct timer_list timeout_timer; 46 struct timer_list timeout_timer;
59 struct i2c_adapter adap; 47 struct i2c_adapter adap;
60 struct completion complete; 48 struct completion complete;
49 struct i2c_msg *pmsg;
50 int msg_num;
51 int cur_msg;
52 void __iomem *regs_base;
61}; 53};
62 54
63static struct bfin_twi_iface twi_iface; 55
56#define DEFINE_TWI_REG(reg, off) \
57static inline u16 read_##reg(struct bfin_twi_iface *iface) \
58 { return bfin_read16(iface->regs_base + (off)); } \
59static inline void write_##reg(struct bfin_twi_iface *iface, u16 v) \
60 { bfin_write16(iface->regs_base + (off), v); }
61
62DEFINE_TWI_REG(CLKDIV, 0x00)
63DEFINE_TWI_REG(CONTROL, 0x04)
64DEFINE_TWI_REG(SLAVE_CTL, 0x08)
65DEFINE_TWI_REG(SLAVE_STAT, 0x0C)
66DEFINE_TWI_REG(SLAVE_ADDR, 0x10)
67DEFINE_TWI_REG(MASTER_CTL, 0x14)
68DEFINE_TWI_REG(MASTER_STAT, 0x18)
69DEFINE_TWI_REG(MASTER_ADDR, 0x1C)
70DEFINE_TWI_REG(INT_STAT, 0x20)
71DEFINE_TWI_REG(INT_MASK, 0x24)
72DEFINE_TWI_REG(FIFO_CTL, 0x28)
73DEFINE_TWI_REG(FIFO_STAT, 0x2C)
74DEFINE_TWI_REG(XMT_DATA8, 0x80)
75DEFINE_TWI_REG(XMT_DATA16, 0x84)
76DEFINE_TWI_REG(RCV_DATA8, 0x88)
77DEFINE_TWI_REG(RCV_DATA16, 0x8C)
78
79static const u16 pin_req[2][3] = {
80 {P_TWI0_SCL, P_TWI0_SDA, 0},
81 {P_TWI1_SCL, P_TWI1_SDA, 0},
82};
64 83
65static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) 84static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
66{ 85{
67 unsigned short twi_int_status = bfin_read_TWI_INT_STAT(); 86 unsigned short twi_int_status = read_INT_STAT(iface);
68 unsigned short mast_stat = bfin_read_TWI_MASTER_STAT(); 87 unsigned short mast_stat = read_MASTER_STAT(iface);
69 88
70 if (twi_int_status & XMTSERV) { 89 if (twi_int_status & XMTSERV) {
71 /* Transmit next data */ 90 /* Transmit next data */
72 if (iface->writeNum > 0) { 91 if (iface->writeNum > 0) {
73 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++)); 92 write_XMT_DATA8(iface, *(iface->transPtr++));
74 iface->writeNum--; 93 iface->writeNum--;
75 } 94 }
76 /* start receive immediately after complete sending in 95 /* start receive immediately after complete sending in
77 * combine mode. 96 * combine mode.
78 */ 97 */
79 else if (iface->cur_mode == TWI_I2C_MODE_COMBINED) { 98 else if (iface->cur_mode == TWI_I2C_MODE_COMBINED)
80 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() 99 write_MASTER_CTL(iface,
81 | MDIR | RSTART); 100 read_MASTER_CTL(iface) | MDIR | RSTART);
82 } else if (iface->manual_stop) 101 else if (iface->manual_stop)
83 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() 102 write_MASTER_CTL(iface,
84 | STOP); 103 read_MASTER_CTL(iface) | STOP);
104 else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
105 iface->cur_msg+1 < iface->msg_num)
106 write_MASTER_CTL(iface,
107 read_MASTER_CTL(iface) | RSTART);
85 SSYNC(); 108 SSYNC();
86 /* Clear status */ 109 /* Clear status */
87 bfin_write_TWI_INT_STAT(XMTSERV); 110 write_INT_STAT(iface, XMTSERV);
88 SSYNC(); 111 SSYNC();
89 } 112 }
90 if (twi_int_status & RCVSERV) { 113 if (twi_int_status & RCVSERV) {
91 if (iface->readNum > 0) { 114 if (iface->readNum > 0) {
92 /* Receive next data */ 115 /* Receive next data */
93 *(iface->transPtr) = bfin_read_TWI_RCV_DATA8(); 116 *(iface->transPtr) = read_RCV_DATA8(iface);
94 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) { 117 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
95 /* Change combine mode into sub mode after 118 /* Change combine mode into sub mode after
96 * read first data. 119 * read first data.
@@ -105,28 +128,33 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
105 iface->transPtr++; 128 iface->transPtr++;
106 iface->readNum--; 129 iface->readNum--;
107 } else if (iface->manual_stop) { 130 } else if (iface->manual_stop) {
108 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() 131 write_MASTER_CTL(iface,
109 | STOP); 132 read_MASTER_CTL(iface) | STOP);
133 SSYNC();
134 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
135 iface->cur_msg+1 < iface->msg_num) {
136 write_MASTER_CTL(iface,
137 read_MASTER_CTL(iface) | RSTART);
110 SSYNC(); 138 SSYNC();
111 } 139 }
112 /* Clear interrupt source */ 140 /* Clear interrupt source */
113 bfin_write_TWI_INT_STAT(RCVSERV); 141 write_INT_STAT(iface, RCVSERV);
114 SSYNC(); 142 SSYNC();
115 } 143 }
116 if (twi_int_status & MERR) { 144 if (twi_int_status & MERR) {
117 bfin_write_TWI_INT_STAT(MERR); 145 write_INT_STAT(iface, MERR);
118 bfin_write_TWI_INT_MASK(0); 146 write_INT_MASK(iface, 0);
119 bfin_write_TWI_MASTER_STAT(0x3e); 147 write_MASTER_STAT(iface, 0x3e);
120 bfin_write_TWI_MASTER_CTL(0); 148 write_MASTER_CTL(iface, 0);
121 SSYNC(); 149 SSYNC();
122 iface->result = -1; 150 iface->result = -EIO;
123 /* if both err and complete int stats are set, return proper 151 /* if both err and complete int stats are set, return proper
124 * results. 152 * results.
125 */ 153 */
126 if (twi_int_status & MCOMP) { 154 if (twi_int_status & MCOMP) {
127 bfin_write_TWI_INT_STAT(MCOMP); 155 write_INT_STAT(iface, MCOMP);
128 bfin_write_TWI_INT_MASK(0); 156 write_INT_MASK(iface, 0);
129 bfin_write_TWI_MASTER_CTL(0); 157 write_MASTER_CTL(iface, 0);
130 SSYNC(); 158 SSYNC();
131 /* If it is a quick transfer, only address bug no data, 159 /* If it is a quick transfer, only address bug no data,
132 * not an err, return 1. 160 * not an err, return 1.
@@ -143,7 +171,7 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
143 return; 171 return;
144 } 172 }
145 if (twi_int_status & MCOMP) { 173 if (twi_int_status & MCOMP) {
146 bfin_write_TWI_INT_STAT(MCOMP); 174 write_INT_STAT(iface, MCOMP);
147 SSYNC(); 175 SSYNC();
148 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) { 176 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
149 if (iface->readNum == 0) { 177 if (iface->readNum == 0) {
@@ -152,28 +180,63 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
152 */ 180 */
153 iface->readNum = 1; 181 iface->readNum = 1;
154 iface->manual_stop = 1; 182 iface->manual_stop = 1;
155 bfin_write_TWI_MASTER_CTL( 183 write_MASTER_CTL(iface,
156 bfin_read_TWI_MASTER_CTL() 184 read_MASTER_CTL(iface) | (0xff << 6));
157 | (0xff << 6));
158 } else { 185 } else {
159 /* set the readd number in other 186 /* set the readd number in other
160 * combine mode. 187 * combine mode.
161 */ 188 */
162 bfin_write_TWI_MASTER_CTL( 189 write_MASTER_CTL(iface,
163 (bfin_read_TWI_MASTER_CTL() & 190 (read_MASTER_CTL(iface) &
164 (~(0xff << 6))) | 191 (~(0xff << 6))) |
165 ( iface->readNum << 6)); 192 (iface->readNum << 6));
193 }
194 /* remove restart bit and enable master receive */
195 write_MASTER_CTL(iface,
196 read_MASTER_CTL(iface) & ~RSTART);
197 write_MASTER_CTL(iface,
198 read_MASTER_CTL(iface) | MEN | MDIR);
199 SSYNC();
200 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
201 iface->cur_msg+1 < iface->msg_num) {
202 iface->cur_msg++;
203 iface->transPtr = iface->pmsg[iface->cur_msg].buf;
204 iface->writeNum = iface->readNum =
205 iface->pmsg[iface->cur_msg].len;
206 /* Set Transmit device address */
207 write_MASTER_ADDR(iface,
208 iface->pmsg[iface->cur_msg].addr);
209 if (iface->pmsg[iface->cur_msg].flags & I2C_M_RD)
210 iface->read_write = I2C_SMBUS_READ;
211 else {
212 iface->read_write = I2C_SMBUS_WRITE;
213 /* Transmit first data */
214 if (iface->writeNum > 0) {
215 write_XMT_DATA8(iface,
216 *(iface->transPtr++));
217 iface->writeNum--;
218 SSYNC();
219 }
220 }
221
222 if (iface->pmsg[iface->cur_msg].len <= 255)
223 write_MASTER_CTL(iface,
224 iface->pmsg[iface->cur_msg].len << 6);
225 else {
226 write_MASTER_CTL(iface, 0xff << 6);
227 iface->manual_stop = 1;
166 } 228 }
167 /* remove restart bit and enable master receive */ 229 /* remove restart bit and enable master receive */
168 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() & 230 write_MASTER_CTL(iface,
169 ~RSTART); 231 read_MASTER_CTL(iface) & ~RSTART);
170 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | 232 write_MASTER_CTL(iface, read_MASTER_CTL(iface) |
171 MEN | MDIR); 233 MEN | ((iface->read_write == I2C_SMBUS_READ) ?
234 MDIR : 0));
172 SSYNC(); 235 SSYNC();
173 } else { 236 } else {
174 iface->result = 1; 237 iface->result = 1;
175 bfin_write_TWI_INT_MASK(0); 238 write_INT_MASK(iface, 0);
176 bfin_write_TWI_MASTER_CTL(0); 239 write_MASTER_CTL(iface, 0);
177 SSYNC(); 240 SSYNC();
178 complete(&iface->complete); 241 complete(&iface->complete);
179 } 242 }
@@ -221,91 +284,85 @@ static int bfin_twi_master_xfer(struct i2c_adapter *adap,
221{ 284{
222 struct bfin_twi_iface *iface = adap->algo_data; 285 struct bfin_twi_iface *iface = adap->algo_data;
223 struct i2c_msg *pmsg; 286 struct i2c_msg *pmsg;
224 int i, ret;
225 int rc = 0; 287 int rc = 0;
226 288
227 if (!(bfin_read_TWI_CONTROL() & TWI_ENA)) 289 if (!(read_CONTROL(iface) & TWI_ENA))
228 return -ENXIO; 290 return -ENXIO;
229 291
230 while (bfin_read_TWI_MASTER_STAT() & BUSBUSY) { 292 while (read_MASTER_STAT(iface) & BUSBUSY)
231 yield(); 293 yield();
294
295 iface->pmsg = msgs;
296 iface->msg_num = num;
297 iface->cur_msg = 0;
298
299 pmsg = &msgs[0];
300 if (pmsg->flags & I2C_M_TEN) {
301 dev_err(&adap->dev, "10 bits addr not supported!\n");
302 return -EINVAL;
232 } 303 }
233 304
234 ret = 0; 305 iface->cur_mode = TWI_I2C_MODE_REPEAT;
235 for (i = 0; rc >= 0 && i < num; i++) { 306 iface->manual_stop = 0;
236 pmsg = &msgs[i]; 307 iface->transPtr = pmsg->buf;
237 if (pmsg->flags & I2C_M_TEN) { 308 iface->writeNum = iface->readNum = pmsg->len;
238 dev_err(&(adap->dev), "i2c-bfin-twi: 10 bits addr " 309 iface->result = 0;
239 "not supported !\n"); 310 iface->timeout_count = 10;
240 rc = -EINVAL; 311 init_completion(&(iface->complete));
241 break; 312 /* Set Transmit device address */
242 } 313 write_MASTER_ADDR(iface, pmsg->addr);
243 314
244 iface->cur_mode = TWI_I2C_MODE_STANDARD; 315 /* FIFO Initiation. Data in FIFO should be
245 iface->manual_stop = 0; 316 * discarded before start a new operation.
246 iface->transPtr = pmsg->buf; 317 */
247 iface->writeNum = iface->readNum = pmsg->len; 318 write_FIFO_CTL(iface, 0x3);
248 iface->result = 0; 319 SSYNC();
249 iface->timeout_count = 10; 320 write_FIFO_CTL(iface, 0);
250 /* Set Transmit device address */ 321 SSYNC();
251 bfin_write_TWI_MASTER_ADDR(pmsg->addr);
252
253 /* FIFO Initiation. Data in FIFO should be
254 * discarded before start a new operation.
255 */
256 bfin_write_TWI_FIFO_CTL(0x3);
257 SSYNC();
258 bfin_write_TWI_FIFO_CTL(0);
259 SSYNC();
260 322
261 if (pmsg->flags & I2C_M_RD) 323 if (pmsg->flags & I2C_M_RD)
262 iface->read_write = I2C_SMBUS_READ; 324 iface->read_write = I2C_SMBUS_READ;
263 else { 325 else {
264 iface->read_write = I2C_SMBUS_WRITE; 326 iface->read_write = I2C_SMBUS_WRITE;
265 /* Transmit first data */ 327 /* Transmit first data */
266 if (iface->writeNum > 0) { 328 if (iface->writeNum > 0) {
267 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++)); 329 write_XMT_DATA8(iface, *(iface->transPtr++));
268 iface->writeNum--; 330 iface->writeNum--;
269 SSYNC(); 331 SSYNC();
270 }
271 } 332 }
333 }
272 334
273 /* clear int stat */ 335 /* clear int stat */
274 bfin_write_TWI_INT_STAT(MERR|MCOMP|XMTSERV|RCVSERV); 336 write_INT_STAT(iface, MERR | MCOMP | XMTSERV | RCVSERV);
275 337
276 /* Interrupt mask . Enable XMT, RCV interrupt */ 338 /* Interrupt mask . Enable XMT, RCV interrupt */
277 bfin_write_TWI_INT_MASK(MCOMP | MERR | 339 write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV);
278 ((iface->read_write == I2C_SMBUS_READ)? 340 SSYNC();
279 RCVSERV : XMTSERV));
280 SSYNC();
281 341
282 if (pmsg->len > 0 && pmsg->len <= 255) 342 if (pmsg->len <= 255)
283 bfin_write_TWI_MASTER_CTL(pmsg->len << 6); 343 write_MASTER_CTL(iface, pmsg->len << 6);
284 else if (pmsg->len > 255) { 344 else {
285 bfin_write_TWI_MASTER_CTL(0xff << 6); 345 write_MASTER_CTL(iface, 0xff << 6);
286 iface->manual_stop = 1; 346 iface->manual_stop = 1;
287 } else 347 }
288 break;
289 348
290 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT; 349 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
291 add_timer(&iface->timeout_timer); 350 add_timer(&iface->timeout_timer);
292 351
293 /* Master enable */ 352 /* Master enable */
294 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN | 353 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
295 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) | 354 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
296 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0)); 355 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
297 SSYNC(); 356 SSYNC();
298 357
299 wait_for_completion(&iface->complete); 358 wait_for_completion(&iface->complete);
300 359
301 rc = iface->result; 360 rc = iface->result;
302 if (rc == 1)
303 ret++;
304 else if (rc == -1)
305 break;
306 }
307 361
308 return ret; 362 if (rc == 1)
363 return num;
364 else
365 return rc;
309} 366}
310 367
311/* 368/*
@@ -319,12 +376,11 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
319 struct bfin_twi_iface *iface = adap->algo_data; 376 struct bfin_twi_iface *iface = adap->algo_data;
320 int rc = 0; 377 int rc = 0;
321 378
322 if (!(bfin_read_TWI_CONTROL() & TWI_ENA)) 379 if (!(read_CONTROL(iface) & TWI_ENA))
323 return -ENXIO; 380 return -ENXIO;
324 381
325 while (bfin_read_TWI_MASTER_STAT() & BUSBUSY) { 382 while (read_MASTER_STAT(iface) & BUSBUSY)
326 yield(); 383 yield();
327 }
328 384
329 iface->writeNum = 0; 385 iface->writeNum = 0;
330 iface->readNum = 0; 386 iface->readNum = 0;
@@ -392,19 +448,20 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
392 iface->read_write = read_write; 448 iface->read_write = read_write;
393 iface->command = command; 449 iface->command = command;
394 iface->timeout_count = 10; 450 iface->timeout_count = 10;
451 init_completion(&(iface->complete));
395 452
396 /* FIFO Initiation. Data in FIFO should be discarded before 453 /* FIFO Initiation. Data in FIFO should be discarded before
397 * start a new operation. 454 * start a new operation.
398 */ 455 */
399 bfin_write_TWI_FIFO_CTL(0x3); 456 write_FIFO_CTL(iface, 0x3);
400 SSYNC(); 457 SSYNC();
401 bfin_write_TWI_FIFO_CTL(0); 458 write_FIFO_CTL(iface, 0);
402 459
403 /* clear int stat */ 460 /* clear int stat */
404 bfin_write_TWI_INT_STAT(MERR|MCOMP|XMTSERV|RCVSERV); 461 write_INT_STAT(iface, MERR | MCOMP | XMTSERV | RCVSERV);
405 462
406 /* Set Transmit device address */ 463 /* Set Transmit device address */
407 bfin_write_TWI_MASTER_ADDR(addr); 464 write_MASTER_ADDR(iface, addr);
408 SSYNC(); 465 SSYNC();
409 466
410 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT; 467 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
@@ -412,60 +469,64 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
412 469
413 switch (iface->cur_mode) { 470 switch (iface->cur_mode) {
414 case TWI_I2C_MODE_STANDARDSUB: 471 case TWI_I2C_MODE_STANDARDSUB:
415 bfin_write_TWI_XMT_DATA8(iface->command); 472 write_XMT_DATA8(iface, iface->command);
416 bfin_write_TWI_INT_MASK(MCOMP | MERR | 473 write_INT_MASK(iface, MCOMP | MERR |
417 ((iface->read_write == I2C_SMBUS_READ) ? 474 ((iface->read_write == I2C_SMBUS_READ) ?
418 RCVSERV : XMTSERV)); 475 RCVSERV : XMTSERV));
419 SSYNC(); 476 SSYNC();
420 477
421 if (iface->writeNum + 1 <= 255) 478 if (iface->writeNum + 1 <= 255)
422 bfin_write_TWI_MASTER_CTL((iface->writeNum + 1) << 6); 479 write_MASTER_CTL(iface, (iface->writeNum + 1) << 6);
423 else { 480 else {
424 bfin_write_TWI_MASTER_CTL(0xff << 6); 481 write_MASTER_CTL(iface, 0xff << 6);
425 iface->manual_stop = 1; 482 iface->manual_stop = 1;
426 } 483 }
427 /* Master enable */ 484 /* Master enable */
428 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN | 485 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
429 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0)); 486 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
430 break; 487 break;
431 case TWI_I2C_MODE_COMBINED: 488 case TWI_I2C_MODE_COMBINED:
432 bfin_write_TWI_XMT_DATA8(iface->command); 489 write_XMT_DATA8(iface, iface->command);
433 bfin_write_TWI_INT_MASK(MCOMP | MERR | RCVSERV | XMTSERV); 490 write_INT_MASK(iface, MCOMP | MERR | RCVSERV | XMTSERV);
434 SSYNC(); 491 SSYNC();
435 492
436 if (iface->writeNum > 0) 493 if (iface->writeNum > 0)
437 bfin_write_TWI_MASTER_CTL((iface->writeNum + 1) << 6); 494 write_MASTER_CTL(iface, (iface->writeNum + 1) << 6);
438 else 495 else
439 bfin_write_TWI_MASTER_CTL(0x1 << 6); 496 write_MASTER_CTL(iface, 0x1 << 6);
440 /* Master enable */ 497 /* Master enable */
441 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN | 498 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
442 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0)); 499 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
443 break; 500 break;
444 default: 501 default:
445 bfin_write_TWI_MASTER_CTL(0); 502 write_MASTER_CTL(iface, 0);
446 if (size != I2C_SMBUS_QUICK) { 503 if (size != I2C_SMBUS_QUICK) {
447 /* Don't access xmit data register when this is a 504 /* Don't access xmit data register when this is a
448 * read operation. 505 * read operation.
449 */ 506 */
450 if (iface->read_write != I2C_SMBUS_READ) { 507 if (iface->read_write != I2C_SMBUS_READ) {
451 if (iface->writeNum > 0) { 508 if (iface->writeNum > 0) {
452 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++)); 509 write_XMT_DATA8(iface,
510 *(iface->transPtr++));
453 if (iface->writeNum <= 255) 511 if (iface->writeNum <= 255)
454 bfin_write_TWI_MASTER_CTL(iface->writeNum << 6); 512 write_MASTER_CTL(iface,
513 iface->writeNum << 6);
455 else { 514 else {
456 bfin_write_TWI_MASTER_CTL(0xff << 6); 515 write_MASTER_CTL(iface,
516 0xff << 6);
457 iface->manual_stop = 1; 517 iface->manual_stop = 1;
458 } 518 }
459 iface->writeNum--; 519 iface->writeNum--;
460 } else { 520 } else {
461 bfin_write_TWI_XMT_DATA8(iface->command); 521 write_XMT_DATA8(iface, iface->command);
462 bfin_write_TWI_MASTER_CTL(1 << 6); 522 write_MASTER_CTL(iface, 1 << 6);
463 } 523 }
464 } else { 524 } else {
465 if (iface->readNum > 0 && iface->readNum <= 255) 525 if (iface->readNum > 0 && iface->readNum <= 255)
466 bfin_write_TWI_MASTER_CTL(iface->readNum << 6); 526 write_MASTER_CTL(iface,
527 iface->readNum << 6);
467 else if (iface->readNum > 255) { 528 else if (iface->readNum > 255) {
468 bfin_write_TWI_MASTER_CTL(0xff << 6); 529 write_MASTER_CTL(iface, 0xff << 6);
469 iface->manual_stop = 1; 530 iface->manual_stop = 1;
470 } else { 531 } else {
471 del_timer(&iface->timeout_timer); 532 del_timer(&iface->timeout_timer);
@@ -473,13 +534,13 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
473 } 534 }
474 } 535 }
475 } 536 }
476 bfin_write_TWI_INT_MASK(MCOMP | MERR | 537 write_INT_MASK(iface, MCOMP | MERR |
477 ((iface->read_write == I2C_SMBUS_READ) ? 538 ((iface->read_write == I2C_SMBUS_READ) ?
478 RCVSERV : XMTSERV)); 539 RCVSERV : XMTSERV));
479 SSYNC(); 540 SSYNC();
480 541
481 /* Master enable */ 542 /* Master enable */
482 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN | 543 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
483 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) | 544 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
484 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0)); 545 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
485 break; 546 break;
@@ -514,10 +575,10 @@ static struct i2c_algorithm bfin_twi_algorithm = {
514 575
515static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state) 576static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
516{ 577{
517/* struct bfin_twi_iface *iface = platform_get_drvdata(dev);*/ 578 struct bfin_twi_iface *iface = platform_get_drvdata(dev);
518 579
519 /* Disable TWI */ 580 /* Disable TWI */
520 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() & ~TWI_ENA); 581 write_CONTROL(iface, read_CONTROL(iface) & ~TWI_ENA);
521 SSYNC(); 582 SSYNC();
522 583
523 return 0; 584 return 0;
@@ -525,24 +586,52 @@ static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
525 586
526static int i2c_bfin_twi_resume(struct platform_device *dev) 587static int i2c_bfin_twi_resume(struct platform_device *dev)
527{ 588{
528/* struct bfin_twi_iface *iface = platform_get_drvdata(dev);*/ 589 struct bfin_twi_iface *iface = platform_get_drvdata(dev);
529 590
530 /* Enable TWI */ 591 /* Enable TWI */
531 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA); 592 write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
532 SSYNC(); 593 SSYNC();
533 594
534 return 0; 595 return 0;
535} 596}
536 597
537static int i2c_bfin_twi_probe(struct platform_device *dev) 598static int i2c_bfin_twi_probe(struct platform_device *pdev)
538{ 599{
539 struct bfin_twi_iface *iface = &twi_iface; 600 struct bfin_twi_iface *iface;
540 struct i2c_adapter *p_adap; 601 struct i2c_adapter *p_adap;
602 struct resource *res;
541 int rc; 603 int rc;
542 604
605 iface = kzalloc(sizeof(struct bfin_twi_iface), GFP_KERNEL);
606 if (!iface) {
607 dev_err(&pdev->dev, "Cannot allocate memory\n");
608 rc = -ENOMEM;
609 goto out_error_nomem;
610 }
611
543 spin_lock_init(&(iface->lock)); 612 spin_lock_init(&(iface->lock));
544 init_completion(&(iface->complete)); 613
545 iface->irq = IRQ_TWI; 614 /* Find and map our resources */
615 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
616 if (res == NULL) {
617 dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n");
618 rc = -ENOENT;
619 goto out_error_get_res;
620 }
621
622 iface->regs_base = ioremap(res->start, res->end - res->start + 1);
623 if (iface->regs_base == NULL) {
624 dev_err(&pdev->dev, "Cannot map IO\n");
625 rc = -ENXIO;
626 goto out_error_ioremap;
627 }
628
629 iface->irq = platform_get_irq(pdev, 0);
630 if (iface->irq < 0) {
631 dev_err(&pdev->dev, "No IRQ specified\n");
632 rc = -ENOENT;
633 goto out_error_no_irq;
634 }
546 635
547 init_timer(&(iface->timeout_timer)); 636 init_timer(&(iface->timeout_timer));
548 iface->timeout_timer.function = bfin_twi_timeout; 637 iface->timeout_timer.function = bfin_twi_timeout;
@@ -550,39 +639,63 @@ static int i2c_bfin_twi_probe(struct platform_device *dev)
550 639
551 p_adap = &iface->adap; 640 p_adap = &iface->adap;
552 p_adap->id = I2C_HW_BLACKFIN; 641 p_adap->id = I2C_HW_BLACKFIN;
553 p_adap->nr = dev->id; 642 p_adap->nr = pdev->id;
554 strlcpy(p_adap->name, dev->name, sizeof(p_adap->name)); 643 strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name));
555 p_adap->algo = &bfin_twi_algorithm; 644 p_adap->algo = &bfin_twi_algorithm;
556 p_adap->algo_data = iface; 645 p_adap->algo_data = iface;
557 p_adap->class = I2C_CLASS_ALL; 646 p_adap->class = I2C_CLASS_ALL;
558 p_adap->dev.parent = &dev->dev; 647 p_adap->dev.parent = &pdev->dev;
648
649 rc = peripheral_request_list(pin_req[pdev->id], "i2c-bfin-twi");
650 if (rc) {
651 dev_err(&pdev->dev, "Can't setup pin mux!\n");
652 goto out_error_pin_mux;
653 }
559 654
560 rc = request_irq(iface->irq, bfin_twi_interrupt_entry, 655 rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
561 IRQF_DISABLED, dev->name, iface); 656 IRQF_DISABLED, pdev->name, iface);
562 if (rc) { 657 if (rc) {
563 dev_err(&(p_adap->dev), "i2c-bfin-twi: can't get IRQ %d !\n", 658 dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
564 iface->irq); 659 rc = -ENODEV;
565 return -ENODEV; 660 goto out_error_req_irq;
566 } 661 }
567 662
568 /* Set TWI internal clock as 10MHz */ 663 /* Set TWI internal clock as 10MHz */
569 bfin_write_TWI_CONTROL(((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F); 664 write_CONTROL(iface, ((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F);
570 665
571 /* Set Twi interface clock as specified */ 666 /* Set Twi interface clock as specified */
572 bfin_write_TWI_CLKDIV((( 5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ ) 667 write_CLKDIV(iface, ((5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ)
573 << 8) | (( 5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ ) 668 << 8) | ((5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ)
574 & 0xFF)); 669 & 0xFF));
575 670
576 /* Enable TWI */ 671 /* Enable TWI */
577 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA); 672 write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
578 SSYNC(); 673 SSYNC();
579 674
580 rc = i2c_add_numbered_adapter(p_adap); 675 rc = i2c_add_numbered_adapter(p_adap);
581 if (rc < 0) 676 if (rc < 0) {
582 free_irq(iface->irq, iface); 677 dev_err(&pdev->dev, "Can't add i2c adapter!\n");
583 else 678 goto out_error_add_adapter;
584 platform_set_drvdata(dev, iface); 679 }
680
681 platform_set_drvdata(pdev, iface);
585 682
683 dev_info(&pdev->dev, "Blackfin BF5xx on-chip I2C TWI Contoller, "
684 "regs_base@%p\n", iface->regs_base);
685
686 return 0;
687
688out_error_add_adapter:
689 free_irq(iface->irq, iface);
690out_error_req_irq:
691out_error_no_irq:
692 peripheral_free_list(pin_req[pdev->id]);
693out_error_pin_mux:
694 iounmap(iface->regs_base);
695out_error_ioremap:
696out_error_get_res:
697 kfree(iface);
698out_error_nomem:
586 return rc; 699 return rc;
587} 700}
588 701
@@ -594,6 +707,9 @@ static int i2c_bfin_twi_remove(struct platform_device *pdev)
594 707
595 i2c_del_adapter(&(iface->adap)); 708 i2c_del_adapter(&(iface->adap));
596 free_irq(iface->irq, iface); 709 free_irq(iface->irq, iface);
710 peripheral_free_list(pin_req[pdev->id]);
711 iounmap(iface->regs_base);
712 kfree(iface);
597 713
598 return 0; 714 return 0;
599} 715}
@@ -611,8 +727,6 @@ static struct platform_driver i2c_bfin_twi_driver = {
611 727
612static int __init i2c_bfin_twi_init(void) 728static int __init i2c_bfin_twi_init(void)
613{ 729{
614 pr_info("I2C: Blackfin I2C TWI driver\n");
615
616 return platform_driver_register(&i2c_bfin_twi_driver); 730 return platform_driver_register(&i2c_bfin_twi_driver);
617} 731}
618 732
@@ -621,9 +735,10 @@ static void __exit i2c_bfin_twi_exit(void)
621 platform_driver_unregister(&i2c_bfin_twi_driver); 735 platform_driver_unregister(&i2c_bfin_twi_driver);
622} 736}
623 737
624MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
625MODULE_DESCRIPTION("I2C-Bus adapter routines for Blackfin TWI");
626MODULE_LICENSE("GPL");
627
628module_init(i2c_bfin_twi_init); 738module_init(i2c_bfin_twi_init);
629module_exit(i2c_bfin_twi_exit); 739module_exit(i2c_bfin_twi_exit);
740
741MODULE_AUTHOR("Bryan Wu, Sonic Zhang");
742MODULE_DESCRIPTION("Blackfin BF5xx on-chip I2C TWI Contoller Driver");
743MODULE_LICENSE("GPL");
744MODULE_ALIAS("platform:i2c-bfin-twi");
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index fde26345a379..7ecbfc429b19 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -328,7 +328,7 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
328 int i; 328 int i;
329 int ret; 329 int ret;
330 330
331 dev_dbg(dev->dev, "%s: msgs: %d\n", __FUNCTION__, num); 331 dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
332 332
333 ret = i2c_davinci_wait_bus_not_busy(dev, 1); 333 ret = i2c_davinci_wait_bus_not_busy(dev, 1);
334 if (ret < 0) { 334 if (ret < 0) {
@@ -342,7 +342,7 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
342 return ret; 342 return ret;
343 } 343 }
344 344
345 dev_dbg(dev->dev, "%s:%d ret: %d\n", __FUNCTION__, __LINE__, ret); 345 dev_dbg(dev->dev, "%s:%d ret: %d\n", __func__, __LINE__, ret);
346 346
347 return num; 347 return num;
348} 348}
@@ -364,7 +364,7 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
364 u16 w; 364 u16 w;
365 365
366 while ((stat = davinci_i2c_read_reg(dev, DAVINCI_I2C_IVR_REG))) { 366 while ((stat = davinci_i2c_read_reg(dev, DAVINCI_I2C_IVR_REG))) {
367 dev_dbg(dev->dev, "%s: stat=0x%x\n", __FUNCTION__, stat); 367 dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat);
368 if (count++ == 100) { 368 if (count++ == 100) {
369 dev_warn(dev->dev, "Too much work in one IRQ\n"); 369 dev_warn(dev->dev, "Too much work in one IRQ\n");
370 break; 370 break;
@@ -553,6 +553,9 @@ static int davinci_i2c_remove(struct platform_device *pdev)
553 return 0; 553 return 0;
554} 554}
555 555
556/* work with hotplug and coldplug */
557MODULE_ALIAS("platform:i2c_davinci");
558
556static struct platform_driver davinci_i2c_driver = { 559static struct platform_driver davinci_i2c_driver = {
557 .probe = davinci_i2c_probe, 560 .probe = davinci_i2c_probe,
558 .remove = davinci_i2c_remove, 561 .remove = davinci_i2c_remove,
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 3ca19fc234fb..7c1b762aa681 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -220,3 +220,4 @@ module_exit(i2c_gpio_exit);
220MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>"); 220MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
221MODULE_DESCRIPTION("Platform-independent bitbanging I2C driver"); 221MODULE_DESCRIPTION("Platform-independent bitbanging I2C driver");
222MODULE_LICENSE("GPL"); 222MODULE_LICENSE("GPL");
223MODULE_ALIAS("platform:i2c-gpio");
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 22bb247d0e60..85dbf34382e1 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -6,6 +6,9 @@
6 * Copyright (c) 2003, 2004 Zultys Technologies. 6 * Copyright (c) 2003, 2004 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 8 *
9 * Copyright (c) 2008 PIKA Technologies
10 * Sean MacLennan <smaclennan@pikatech.com>
11 *
9 * Based on original work by 12 * Based on original work by
10 * Ian DaSilva <idasilva@mvista.com> 13 * Ian DaSilva <idasilva@mvista.com>
11 * Armin Kuster <akuster@mvista.com> 14 * Armin Kuster <akuster@mvista.com>
@@ -39,12 +42,17 @@
39#include <asm/io.h> 42#include <asm/io.h>
40#include <linux/i2c.h> 43#include <linux/i2c.h>
41#include <linux/i2c-id.h> 44#include <linux/i2c-id.h>
45
46#ifdef CONFIG_IBM_OCP
42#include <asm/ocp.h> 47#include <asm/ocp.h>
43#include <asm/ibm4xx.h> 48#include <asm/ibm4xx.h>
49#else
50#include <linux/of_platform.h>
51#endif
44 52
45#include "i2c-ibm_iic.h" 53#include "i2c-ibm_iic.h"
46 54
47#define DRIVER_VERSION "2.1" 55#define DRIVER_VERSION "2.2"
48 56
49MODULE_DESCRIPTION("IBM IIC driver v" DRIVER_VERSION); 57MODULE_DESCRIPTION("IBM IIC driver v" DRIVER_VERSION);
50MODULE_LICENSE("GPL"); 58MODULE_LICENSE("GPL");
@@ -650,13 +658,14 @@ static inline u8 iic_clckdiv(unsigned int opb)
650 opb /= 1000000; 658 opb /= 1000000;
651 659
652 if (opb < 20 || opb > 150){ 660 if (opb < 20 || opb > 150){
653 printk(KERN_CRIT "ibm-iic: invalid OPB clock frequency %u MHz\n", 661 printk(KERN_WARNING "ibm-iic: invalid OPB clock frequency %u MHz\n",
654 opb); 662 opb);
655 opb = opb < 20 ? 20 : 150; 663 opb = opb < 20 ? 20 : 150;
656 } 664 }
657 return (u8)((opb + 9) / 10 - 1); 665 return (u8)((opb + 9) / 10 - 1);
658} 666}
659 667
668#ifdef CONFIG_IBM_OCP
660/* 669/*
661 * Register single IIC interface 670 * Register single IIC interface
662 */ 671 */
@@ -672,7 +681,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
672 ocp->def->index); 681 ocp->def->index);
673 682
674 if (!(dev = kzalloc(sizeof(*dev), GFP_KERNEL))) { 683 if (!(dev = kzalloc(sizeof(*dev), GFP_KERNEL))) {
675 printk(KERN_CRIT "ibm-iic%d: failed to allocate device data\n", 684 printk(KERN_ERR "ibm-iic%d: failed to allocate device data\n",
676 ocp->def->index); 685 ocp->def->index);
677 return -ENOMEM; 686 return -ENOMEM;
678 } 687 }
@@ -687,7 +696,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
687 } 696 }
688 697
689 if (!(dev->vaddr = ioremap(ocp->def->paddr, sizeof(struct iic_regs)))){ 698 if (!(dev->vaddr = ioremap(ocp->def->paddr, sizeof(struct iic_regs)))){
690 printk(KERN_CRIT "ibm-iic%d: failed to ioremap device registers\n", 699 printk(KERN_ERR "ibm-iic%d: failed to ioremap device registers\n",
691 dev->idx); 700 dev->idx);
692 ret = -ENXIO; 701 ret = -ENXIO;
693 goto fail2; 702 goto fail2;
@@ -745,7 +754,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
745 adap->nr = dev->idx >= 0 ? dev->idx : 0; 754 adap->nr = dev->idx >= 0 ? dev->idx : 0;
746 755
747 if ((ret = i2c_add_numbered_adapter(adap)) < 0) { 756 if ((ret = i2c_add_numbered_adapter(adap)) < 0) {
748 printk(KERN_CRIT "ibm-iic%d: failed to register i2c adapter\n", 757 printk(KERN_ERR "ibm-iic%d: failed to register i2c adapter\n",
749 dev->idx); 758 dev->idx);
750 goto fail; 759 goto fail;
751 } 760 }
@@ -778,7 +787,7 @@ static void __devexit iic_remove(struct ocp_device *ocp)
778 struct ibm_iic_private* dev = (struct ibm_iic_private*)ocp_get_drvdata(ocp); 787 struct ibm_iic_private* dev = (struct ibm_iic_private*)ocp_get_drvdata(ocp);
779 BUG_ON(dev == NULL); 788 BUG_ON(dev == NULL);
780 if (i2c_del_adapter(&dev->adap)){ 789 if (i2c_del_adapter(&dev->adap)){
781 printk(KERN_CRIT "ibm-iic%d: failed to delete i2c adapter :(\n", 790 printk(KERN_ERR "ibm-iic%d: failed to delete i2c adapter :(\n",
782 dev->idx); 791 dev->idx);
783 /* That's *very* bad, just shutdown IRQ ... */ 792 /* That's *very* bad, just shutdown IRQ ... */
784 if (dev->irq >= 0){ 793 if (dev->irq >= 0){
@@ -828,5 +837,181 @@ static void __exit iic_exit(void)
828 ocp_unregister_driver(&ibm_iic_driver); 837 ocp_unregister_driver(&ibm_iic_driver);
829} 838}
830 839
840#else /* !CONFIG_IBM_OCP */
841
842static int __devinit iic_request_irq(struct of_device *ofdev,
843 struct ibm_iic_private *dev)
844{
845 struct device_node *np = ofdev->node;
846 int irq;
847
848 if (iic_force_poll)
849 return NO_IRQ;
850
851 irq = irq_of_parse_and_map(np, 0);
852 if (irq == NO_IRQ) {
853 dev_err(&ofdev->dev, "irq_of_parse_and_map failed\n");
854 return NO_IRQ;
855 }
856
857 /* Disable interrupts until we finish initialization, assumes
858 * level-sensitive IRQ setup...
859 */
860 iic_interrupt_mode(dev, 0);
861 if (request_irq(irq, iic_handler, 0, "IBM IIC", dev)) {
862 dev_err(&ofdev->dev, "request_irq %d failed\n", irq);
863 /* Fallback to the polling mode */
864 return NO_IRQ;
865 }
866
867 return irq;
868}
869
870/*
871 * Register single IIC interface
872 */
873static int __devinit iic_probe(struct of_device *ofdev,
874 const struct of_device_id *match)
875{
876 struct device_node *np = ofdev->node;
877 struct ibm_iic_private *dev;
878 struct i2c_adapter *adap;
879 const u32 *indexp, *freq;
880 int ret;
881
882 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
883 if (!dev) {
884 dev_err(&ofdev->dev, "failed to allocate device data\n");
885 return -ENOMEM;
886 }
887
888 dev_set_drvdata(&ofdev->dev, dev);
889
890 indexp = of_get_property(np, "index", NULL);
891 if (!indexp) {
892 dev_err(&ofdev->dev, "no index specified\n");
893 ret = -EINVAL;
894 goto error_cleanup;
895 }
896 dev->idx = *indexp;
897
898 dev->vaddr = of_iomap(np, 0);
899 if (dev->vaddr == NULL) {
900 dev_err(&ofdev->dev, "failed to iomap device\n");
901 ret = -ENXIO;
902 goto error_cleanup;
903 }
904
905 init_waitqueue_head(&dev->wq);
906
907 dev->irq = iic_request_irq(ofdev, dev);
908 if (dev->irq == NO_IRQ)
909 dev_warn(&ofdev->dev, "using polling mode\n");
910
911 /* Board specific settings */
912 if (iic_force_fast || of_get_property(np, "fast-mode", NULL))
913 dev->fast_mode = 1;
914
915 freq = of_get_property(np, "clock-frequency", NULL);
916 if (freq == NULL) {
917 freq = of_get_property(np->parent, "clock-frequency", NULL);
918 if (freq == NULL) {
919 dev_err(&ofdev->dev, "Unable to get bus frequency\n");
920 ret = -EINVAL;
921 goto error_cleanup;
922 }
923 }
924
925 dev->clckdiv = iic_clckdiv(*freq);
926 dev_dbg(&ofdev->dev, "clckdiv = %d\n", dev->clckdiv);
927
928 /* Initialize IIC interface */
929 iic_dev_init(dev);
930
931 /* Register it with i2c layer */
932 adap = &dev->adap;
933 adap->dev.parent = &ofdev->dev;
934 strlcpy(adap->name, "IBM IIC", sizeof(adap->name));
935 i2c_set_adapdata(adap, dev);
936 adap->id = I2C_HW_OCP;
937 adap->class = I2C_CLASS_HWMON;
938 adap->algo = &iic_algo;
939 adap->timeout = 1;
940 adap->nr = dev->idx;
941
942 ret = i2c_add_numbered_adapter(adap);
943 if (ret < 0) {
944 dev_err(&ofdev->dev, "failed to register i2c adapter\n");
945 goto error_cleanup;
946 }
947
948 dev_info(&ofdev->dev, "using %s mode\n",
949 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
950
951 return 0;
952
953error_cleanup:
954 if (dev->irq != NO_IRQ) {
955 iic_interrupt_mode(dev, 0);
956 free_irq(dev->irq, dev);
957 }
958
959 if (dev->vaddr)
960 iounmap(dev->vaddr);
961
962 dev_set_drvdata(&ofdev->dev, NULL);
963 kfree(dev);
964 return ret;
965}
966
967/*
968 * Cleanup initialized IIC interface
969 */
970static int __devexit iic_remove(struct of_device *ofdev)
971{
972 struct ibm_iic_private *dev = dev_get_drvdata(&ofdev->dev);
973
974 dev_set_drvdata(&ofdev->dev, NULL);
975
976 i2c_del_adapter(&dev->adap);
977
978 if (dev->irq != NO_IRQ) {
979 iic_interrupt_mode(dev, 0);
980 free_irq(dev->irq, dev);
981 }
982
983 iounmap(dev->vaddr);
984 kfree(dev);
985
986 return 0;
987}
988
989static const struct of_device_id ibm_iic_match[] = {
990 { .compatible = "ibm,iic-405ex", },
991 { .compatible = "ibm,iic-405gp", },
992 { .compatible = "ibm,iic-440gp", },
993 { .compatible = "ibm,iic-440gpx", },
994 { .compatible = "ibm,iic-440grx", },
995 {}
996};
997
998static struct of_platform_driver ibm_iic_driver = {
999 .name = "ibm-iic",
1000 .match_table = ibm_iic_match,
1001 .probe = iic_probe,
1002 .remove = __devexit_p(iic_remove),
1003};
1004
1005static int __init iic_init(void)
1006{
1007 return of_register_platform_driver(&ibm_iic_driver);
1008}
1009
1010static void __exit iic_exit(void)
1011{
1012 of_unregister_platform_driver(&ibm_iic_driver);
1013}
1014#endif /* CONFIG_IBM_OCP */
1015
831module_init(iic_init); 1016module_init(iic_init);
832module_exit(iic_exit); 1017module_exit(iic_exit);
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index ab41400c883e..39884e797594 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -550,3 +550,4 @@ module_exit (i2c_iop3xx_exit);
550MODULE_AUTHOR("D-TACQ Solutions Ltd <www.d-tacq.com>"); 550MODULE_AUTHOR("D-TACQ Solutions Ltd <www.d-tacq.com>");
551MODULE_DESCRIPTION("IOP3xx iic algorithm and driver"); 551MODULE_DESCRIPTION("IOP3xx iic algorithm and driver");
552MODULE_LICENSE("GPL"); 552MODULE_LICENSE("GPL");
553MODULE_ALIAS("platform:IOP3xx-I2C");
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index 6352121a2827..5af9e6521e6c 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -164,4 +164,5 @@ module_exit(ixp2000_i2c_exit);
164MODULE_AUTHOR ("Deepak Saxena <dsaxena@plexity.net>"); 164MODULE_AUTHOR ("Deepak Saxena <dsaxena@plexity.net>");
165MODULE_DESCRIPTION("IXP2000 GPIO-based I2C bus driver"); 165MODULE_DESCRIPTION("IXP2000 GPIO-based I2C bus driver");
166MODULE_LICENSE("GPL"); 166MODULE_LICENSE("GPL");
167MODULE_ALIAS("platform:IXP2000-I2C");
167 168
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index bbe787b243b7..18beb0ad7bf3 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -392,6 +392,9 @@ static int fsl_i2c_remove(struct platform_device *pdev)
392 return 0; 392 return 0;
393}; 393};
394 394
395/* work with hotplug and coldplug */
396MODULE_ALIAS("platform:fsl-i2c");
397
395/* Structure for a device driver */ 398/* Structure for a device driver */
396static struct platform_driver fsl_i2c_driver = { 399static struct platform_driver fsl_i2c_driver = {
397 .probe = fsl_i2c_probe, 400 .probe = fsl_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index e417c2c3ca22..f145692cbb76 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -312,6 +312,9 @@ static int __devexit ocores_i2c_remove(struct platform_device* pdev)
312 return 0; 312 return 0;
313} 313}
314 314
315/* work with hotplug and coldplug */
316MODULE_ALIAS("platform:ocores-i2c");
317
315static struct platform_driver ocores_i2c_driver = { 318static struct platform_driver ocores_i2c_driver = {
316 .probe = ocores_i2c_probe, 319 .probe = ocores_i2c_probe,
317 .remove = __devexit_p(ocores_i2c_remove), 320 .remove = __devexit_p(ocores_i2c_remove),
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 7ba31770d773..e7eb7bf9ddec 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -693,3 +693,4 @@ module_exit(omap_i2c_exit_driver);
693MODULE_AUTHOR("MontaVista Software, Inc. (and others)"); 693MODULE_AUTHOR("MontaVista Software, Inc. (and others)");
694MODULE_DESCRIPTION("TI OMAP I2C bus adapter"); 694MODULE_DESCRIPTION("TI OMAP I2C bus adapter");
695MODULE_LICENSE("GPL"); 695MODULE_LICENSE("GPL");
696MODULE_ALIAS("platform:i2c_omap");
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index 496ee875eb4f..a119784bae10 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * i2c-pca-isa.c driver for PCA9564 on ISA boards 2 * i2c-pca-isa.c driver for PCA9564 on ISA boards
3 * Copyright (C) 2004 Arcom Control Systems 3 * Copyright (C) 2004 Arcom Control Systems
4 * Copyright (C) 2008 Pengutronix
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -22,11 +23,9 @@
22#include <linux/module.h> 23#include <linux/module.h>
23#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
24#include <linux/delay.h> 25#include <linux/delay.h>
25#include <linux/slab.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/wait.h> 28#include <linux/wait.h>
29
30#include <linux/isa.h> 29#include <linux/isa.h>
31#include <linux/i2c.h> 30#include <linux/i2c.h>
32#include <linux/i2c-algo-pca.h> 31#include <linux/i2c-algo-pca.h>
@@ -34,13 +33,9 @@
34#include <asm/io.h> 33#include <asm/io.h>
35#include <asm/irq.h> 34#include <asm/irq.h>
36 35
37#include "../algos/i2c-algo-pca.h" 36#define DRIVER "i2c-pca-isa"
38
39#define IO_SIZE 4 37#define IO_SIZE 4
40 38
41#undef DEBUG_IO
42//#define DEBUG_IO
43
44static unsigned long base = 0x330; 39static unsigned long base = 0x330;
45static int irq = 10; 40static int irq = 10;
46 41
@@ -48,22 +43,9 @@ static int irq = 10;
48 * in the actual clock rate */ 43 * in the actual clock rate */
49static int clock = I2C_PCA_CON_59kHz; 44static int clock = I2C_PCA_CON_59kHz;
50 45
51static int own = 0x55;
52
53static wait_queue_head_t pca_wait; 46static wait_queue_head_t pca_wait;
54 47
55static int pca_isa_getown(struct i2c_algo_pca_data *adap) 48static void pca_isa_writebyte(void *pd, int reg, int val)
56{
57 return (own);
58}
59
60static int pca_isa_getclock(struct i2c_algo_pca_data *adap)
61{
62 return (clock);
63}
64
65static void
66pca_isa_writebyte(struct i2c_algo_pca_data *adap, int reg, int val)
67{ 49{
68#ifdef DEBUG_IO 50#ifdef DEBUG_IO
69 static char *names[] = { "T/O", "DAT", "ADR", "CON" }; 51 static char *names[] = { "T/O", "DAT", "ADR", "CON" };
@@ -72,44 +54,49 @@ pca_isa_writebyte(struct i2c_algo_pca_data *adap, int reg, int val)
72 outb(val, base+reg); 54 outb(val, base+reg);
73} 55}
74 56
75static int 57static int pca_isa_readbyte(void *pd, int reg)
76pca_isa_readbyte(struct i2c_algo_pca_data *adap, int reg)
77{ 58{
78 int res = inb(base+reg); 59 int res = inb(base+reg);
79#ifdef DEBUG_IO 60#ifdef DEBUG_IO
80 { 61 {
81 static char *names[] = { "STA", "DAT", "ADR", "CON" }; 62 static char *names[] = { "STA", "DAT", "ADR", "CON" };
82 printk("*** read %s => %#04x\n", names[reg], res); 63 printk("*** read %s => %#04x\n", names[reg], res);
83 } 64 }
84#endif 65#endif
85 return res; 66 return res;
86} 67}
87 68
88static int pca_isa_waitforinterrupt(struct i2c_algo_pca_data *adap) 69static int pca_isa_waitforcompletion(void *pd)
89{ 70{
90 int ret = 0; 71 int ret = 0;
91 72
92 if (irq > -1) { 73 if (irq > -1) {
93 ret = wait_event_interruptible(pca_wait, 74 ret = wait_event_interruptible(pca_wait,
94 pca_isa_readbyte(adap, I2C_PCA_CON) & I2C_PCA_CON_SI); 75 pca_isa_readbyte(pd, I2C_PCA_CON) & I2C_PCA_CON_SI);
95 } else { 76 } else {
96 while ((pca_isa_readbyte(adap, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0) 77 while ((pca_isa_readbyte(pd, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0)
97 udelay(100); 78 udelay(100);
98 } 79 }
99 return ret; 80 return ret;
100} 81}
101 82
83static void pca_isa_resetchip(void *pd)
84{
85 /* apparently only an external reset will do it. not a lot can be done */
86 printk(KERN_WARNING DRIVER ": Haven't figured out how to do a reset yet\n");
87}
88
102static irqreturn_t pca_handler(int this_irq, void *dev_id) { 89static irqreturn_t pca_handler(int this_irq, void *dev_id) {
103 wake_up_interruptible(&pca_wait); 90 wake_up_interruptible(&pca_wait);
104 return IRQ_HANDLED; 91 return IRQ_HANDLED;
105} 92}
106 93
107static struct i2c_algo_pca_data pca_isa_data = { 94static struct i2c_algo_pca_data pca_isa_data = {
108 .get_own = pca_isa_getown, 95 /* .data intentionally left NULL, not needed with ISA */
109 .get_clock = pca_isa_getclock,
110 .write_byte = pca_isa_writebyte, 96 .write_byte = pca_isa_writebyte,
111 .read_byte = pca_isa_readbyte, 97 .read_byte = pca_isa_readbyte,
112 .wait_for_interrupt = pca_isa_waitforinterrupt, 98 .wait_for_completion = pca_isa_waitforcompletion,
99 .reset_chip = pca_isa_resetchip,
113}; 100};
114 101
115static struct i2c_adapter pca_isa_ops = { 102static struct i2c_adapter pca_isa_ops = {
@@ -117,6 +104,7 @@ static struct i2c_adapter pca_isa_ops = {
117 .id = I2C_HW_A_ISA, 104 .id = I2C_HW_A_ISA,
118 .algo_data = &pca_isa_data, 105 .algo_data = &pca_isa_data,
119 .name = "PCA9564 ISA Adapter", 106 .name = "PCA9564 ISA Adapter",
107 .timeout = 100,
120}; 108};
121 109
122static int __devinit pca_isa_probe(struct device *dev, unsigned int id) 110static int __devinit pca_isa_probe(struct device *dev, unsigned int id)
@@ -144,6 +132,7 @@ static int __devinit pca_isa_probe(struct device *dev, unsigned int id)
144 } 132 }
145 } 133 }
146 134
135 pca_isa_data.i2c_clock = clock;
147 if (i2c_pca_add_bus(&pca_isa_ops) < 0) { 136 if (i2c_pca_add_bus(&pca_isa_ops) < 0) {
148 dev_err(dev, "Failed to add i2c bus\n"); 137 dev_err(dev, "Failed to add i2c bus\n");
149 goto out_irq; 138 goto out_irq;
@@ -178,7 +167,7 @@ static struct isa_driver pca_isa_driver = {
178 .remove = __devexit_p(pca_isa_remove), 167 .remove = __devexit_p(pca_isa_remove),
179 .driver = { 168 .driver = {
180 .owner = THIS_MODULE, 169 .owner = THIS_MODULE,
181 .name = "i2c-pca-isa", 170 .name = DRIVER,
182 } 171 }
183}; 172};
184 173
@@ -204,7 +193,5 @@ MODULE_PARM_DESC(irq, "IRQ");
204module_param(clock, int, 0); 193module_param(clock, int, 0);
205MODULE_PARM_DESC(clock, "Clock rate as described in table 1 of PCA9564 datasheet"); 194MODULE_PARM_DESC(clock, "Clock rate as described in table 1 of PCA9564 datasheet");
206 195
207module_param(own, int, 0); /* the driver can't do slave mode, so there's no real point in this */
208
209module_init(pca_isa_init); 196module_init(pca_isa_init);
210module_exit(pca_isa_exit); 197module_exit(pca_isa_exit);
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
new file mode 100644
index 000000000000..9d75f51e8f0e
--- /dev/null
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -0,0 +1,298 @@
1/*
2 * i2c_pca_platform.c
3 *
4 * Platform driver for the PCA9564 I2C controller.
5 *
6 * Copyright (C) 2008 Pengutronix
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11
12 */
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/slab.h>
17#include <linux/delay.h>
18#include <linux/errno.h>
19#include <linux/i2c.h>
20#include <linux/interrupt.h>
21#include <linux/platform_device.h>
22#include <linux/i2c-algo-pca.h>
23#include <linux/i2c-pca-platform.h>
24#include <linux/gpio.h>
25
26#include <asm/irq.h>
27#include <asm/io.h>
28
29#define res_len(r) ((r)->end - (r)->start + 1)
30
31struct i2c_pca_pf_data {
32 void __iomem *reg_base;
33 int irq; /* if 0, use polling */
34 int gpio;
35 wait_queue_head_t wait;
36 struct i2c_adapter adap;
37 struct i2c_algo_pca_data algo_data;
38 unsigned long io_base;
39 unsigned long io_size;
40};
41
42/* Read/Write functions for different register alignments */
43
44static int i2c_pca_pf_readbyte8(void *pd, int reg)
45{
46 struct i2c_pca_pf_data *i2c = pd;
47 return ioread8(i2c->reg_base + reg);
48}
49
50static int i2c_pca_pf_readbyte16(void *pd, int reg)
51{
52 struct i2c_pca_pf_data *i2c = pd;
53 return ioread8(i2c->reg_base + reg * 2);
54}
55
56static int i2c_pca_pf_readbyte32(void *pd, int reg)
57{
58 struct i2c_pca_pf_data *i2c = pd;
59 return ioread8(i2c->reg_base + reg * 4);
60}
61
62static void i2c_pca_pf_writebyte8(void *pd, int reg, int val)
63{
64 struct i2c_pca_pf_data *i2c = pd;
65 iowrite8(val, i2c->reg_base + reg);
66}
67
68static void i2c_pca_pf_writebyte16(void *pd, int reg, int val)
69{
70 struct i2c_pca_pf_data *i2c = pd;
71 iowrite8(val, i2c->reg_base + reg * 2);
72}
73
74static void i2c_pca_pf_writebyte32(void *pd, int reg, int val)
75{
76 struct i2c_pca_pf_data *i2c = pd;
77 iowrite8(val, i2c->reg_base + reg * 4);
78}
79
80
81static int i2c_pca_pf_waitforcompletion(void *pd)
82{
83 struct i2c_pca_pf_data *i2c = pd;
84 int ret = 0;
85
86 if (i2c->irq) {
87 ret = wait_event_interruptible(i2c->wait,
88 i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
89 & I2C_PCA_CON_SI);
90 } else {
91 /*
92 * Do polling...
93 * XXX: Could get stuck in extreme cases!
94 * Maybe add timeout, but using irqs is preferred anyhow.
95 */
96 while ((i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
97 & I2C_PCA_CON_SI) == 0)
98 udelay(100);
99 }
100
101 return ret;
102}
103
104static void i2c_pca_pf_dummyreset(void *pd)
105{
106 struct i2c_pca_pf_data *i2c = pd;
107 printk(KERN_WARNING "%s: No reset-pin found. Chip may get stuck!\n",
108 i2c->adap.name);
109}
110
111static void i2c_pca_pf_resetchip(void *pd)
112{
113 struct i2c_pca_pf_data *i2c = pd;
114
115 gpio_set_value(i2c->gpio, 0);
116 ndelay(100);
117 gpio_set_value(i2c->gpio, 1);
118}
119
120static irqreturn_t i2c_pca_pf_handler(int this_irq, void *dev_id)
121{
122 struct i2c_pca_pf_data *i2c = dev_id;
123
124 if ((i2c->algo_data.read_byte(i2c, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0)
125 return IRQ_NONE;
126
127 wake_up_interruptible(&i2c->wait);
128
129 return IRQ_HANDLED;
130}
131
132
133static int __devinit i2c_pca_pf_probe(struct platform_device *pdev)
134{
135 struct i2c_pca_pf_data *i2c;
136 struct resource *res;
137 struct i2c_pca9564_pf_platform_data *platform_data =
138 pdev->dev.platform_data;
139 int ret = 0;
140 int irq;
141
142 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
143 irq = platform_get_irq(pdev, 0);
144 /* If irq is 0, we do polling. */
145
146 if (res == NULL) {
147 ret = -ENODEV;
148 goto e_print;
149 }
150
151 if (!request_mem_region(res->start, res_len(res), res->name)) {
152 ret = -ENOMEM;
153 goto e_print;
154 }
155
156 i2c = kzalloc(sizeof(struct i2c_pca_pf_data), GFP_KERNEL);
157 if (!i2c) {
158 ret = -ENOMEM;
159 goto e_alloc;
160 }
161
162 init_waitqueue_head(&i2c->wait);
163
164 i2c->reg_base = ioremap(res->start, res_len(res));
165 if (!i2c->reg_base) {
166 ret = -EIO;
167 goto e_remap;
168 }
169 i2c->io_base = res->start;
170 i2c->io_size = res_len(res);
171 i2c->irq = irq;
172
173 i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0;
174 i2c->adap.owner = THIS_MODULE;
175 snprintf(i2c->adap.name, sizeof(i2c->adap.name), "PCA9564 at 0x%08lx",
176 (unsigned long) res->start);
177 i2c->adap.algo_data = &i2c->algo_data;
178 i2c->adap.dev.parent = &pdev->dev;
179 i2c->adap.timeout = platform_data->timeout;
180
181 i2c->algo_data.i2c_clock = platform_data->i2c_clock_speed;
182 i2c->algo_data.data = i2c;
183
184 switch (res->flags & IORESOURCE_MEM_TYPE_MASK) {
185 case IORESOURCE_MEM_32BIT:
186 i2c->algo_data.write_byte = i2c_pca_pf_writebyte32;
187 i2c->algo_data.read_byte = i2c_pca_pf_readbyte32;
188 break;
189 case IORESOURCE_MEM_16BIT:
190 i2c->algo_data.write_byte = i2c_pca_pf_writebyte16;
191 i2c->algo_data.read_byte = i2c_pca_pf_readbyte16;
192 break;
193 case IORESOURCE_MEM_8BIT:
194 default:
195 i2c->algo_data.write_byte = i2c_pca_pf_writebyte8;
196 i2c->algo_data.read_byte = i2c_pca_pf_readbyte8;
197 break;
198 }
199
200 i2c->algo_data.wait_for_completion = i2c_pca_pf_waitforcompletion;
201
202 i2c->gpio = platform_data->gpio;
203 i2c->algo_data.reset_chip = i2c_pca_pf_dummyreset;
204
205 /* Use gpio_is_valid() when in mainline */
206 if (i2c->gpio > -1) {
207 ret = gpio_request(i2c->gpio, i2c->adap.name);
208 if (ret == 0) {
209 gpio_direction_output(i2c->gpio, 1);
210 i2c->algo_data.reset_chip = i2c_pca_pf_resetchip;
211 } else {
212 printk(KERN_WARNING "%s: Registering gpio failed!\n",
213 i2c->adap.name);
214 i2c->gpio = ret;
215 }
216 }
217
218 if (irq) {
219 ret = request_irq(irq, i2c_pca_pf_handler,
220 IRQF_TRIGGER_FALLING, i2c->adap.name, i2c);
221 if (ret)
222 goto e_reqirq;
223 }
224
225 if (i2c_pca_add_numbered_bus(&i2c->adap) < 0) {
226 ret = -ENODEV;
227 goto e_adapt;
228 }
229
230 platform_set_drvdata(pdev, i2c);
231
232 printk(KERN_INFO "%s registered.\n", i2c->adap.name);
233
234 return 0;
235
236e_adapt:
237 if (irq)
238 free_irq(irq, i2c);
239e_reqirq:
240 if (i2c->gpio > -1)
241 gpio_free(i2c->gpio);
242
243 iounmap(i2c->reg_base);
244e_remap:
245 kfree(i2c);
246e_alloc:
247 release_mem_region(res->start, res_len(res));
248e_print:
249 printk(KERN_ERR "Registering PCA9564 FAILED! (%d)\n", ret);
250 return ret;
251}
252
253static int __devexit i2c_pca_pf_remove(struct platform_device *pdev)
254{
255 struct i2c_pca_pf_data *i2c = platform_get_drvdata(pdev);
256 platform_set_drvdata(pdev, NULL);
257
258 i2c_del_adapter(&i2c->adap);
259
260 if (i2c->irq)
261 free_irq(i2c->irq, i2c);
262
263 if (i2c->gpio > -1)
264 gpio_free(i2c->gpio);
265
266 iounmap(i2c->reg_base);
267 release_mem_region(i2c->io_base, i2c->io_size);
268 kfree(i2c);
269
270 return 0;
271}
272
273static struct platform_driver i2c_pca_pf_driver = {
274 .probe = i2c_pca_pf_probe,
275 .remove = __devexit_p(i2c_pca_pf_remove),
276 .driver = {
277 .name = "i2c-pca-platform",
278 .owner = THIS_MODULE,
279 },
280};
281
282static int __init i2c_pca_pf_init(void)
283{
284 return platform_driver_register(&i2c_pca_pf_driver);
285}
286
287static void __exit i2c_pca_pf_exit(void)
288{
289 platform_driver_unregister(&i2c_pca_pf_driver);
290}
291
292MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
293MODULE_DESCRIPTION("I2C-PCA9564 platform driver");
294MODULE_LICENSE("GPL");
295
296module_init(i2c_pca_pf_init);
297module_exit(i2c_pca_pf_exit);
298
diff --git a/drivers/i2c/busses/i2c-pmcmsp.c b/drivers/i2c/busses/i2c-pmcmsp.c
index b03af5653c65..63b3e2c11cff 100644
--- a/drivers/i2c/busses/i2c-pmcmsp.c
+++ b/drivers/i2c/busses/i2c-pmcmsp.c
@@ -467,7 +467,7 @@ static enum pmcmsptwi_xfer_result pmcmsptwi_xfer_cmd(
467 (cmd->read_len == 0 || cmd->write_len == 0))) { 467 (cmd->read_len == 0 || cmd->write_len == 0))) {
468 dev_err(&pmcmsptwi_adapter.dev, 468 dev_err(&pmcmsptwi_adapter.dev,
469 "%s: Cannot transfer less than 1 byte\n", 469 "%s: Cannot transfer less than 1 byte\n",
470 __FUNCTION__); 470 __func__);
471 return -EINVAL; 471 return -EINVAL;
472 } 472 }
473 473
@@ -475,7 +475,7 @@ static enum pmcmsptwi_xfer_result pmcmsptwi_xfer_cmd(
475 cmd->write_len > MSP_MAX_BYTES_PER_RW) { 475 cmd->write_len > MSP_MAX_BYTES_PER_RW) {
476 dev_err(&pmcmsptwi_adapter.dev, 476 dev_err(&pmcmsptwi_adapter.dev,
477 "%s: Cannot transfer more than %d bytes\n", 477 "%s: Cannot transfer more than %d bytes\n",
478 __FUNCTION__, MSP_MAX_BYTES_PER_RW); 478 __func__, MSP_MAX_BYTES_PER_RW);
479 return -EINVAL; 479 return -EINVAL;
480 } 480 }
481 481
@@ -627,6 +627,9 @@ static struct i2c_adapter pmcmsptwi_adapter = {
627 .name = DRV_NAME, 627 .name = DRV_NAME,
628}; 628};
629 629
630/* work with hotplug and coldplug */
631MODULE_ALIAS("platform:" DRV_NAME);
632
630static struct platform_driver pmcmsptwi_driver = { 633static struct platform_driver pmcmsptwi_driver = {
631 .probe = pmcmsptwi_probe, 634 .probe = pmcmsptwi_probe,
632 .remove = __devexit_p(pmcmsptwi_remove), 635 .remove = __devexit_p(pmcmsptwi_remove),
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index f8d0dff0de7e..1ca21084ffcf 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -76,7 +76,7 @@ static int i2c_pnx_start(unsigned char slave_addr, struct i2c_adapter *adap)
76{ 76{
77 struct i2c_pnx_algo_data *alg_data = adap->algo_data; 77 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
78 78
79 dev_dbg(&adap->dev, "%s(): addr 0x%x mode %d\n", __FUNCTION__, 79 dev_dbg(&adap->dev, "%s(): addr 0x%x mode %d\n", __func__,
80 slave_addr, alg_data->mif.mode); 80 slave_addr, alg_data->mif.mode);
81 81
82 /* Check for 7 bit slave addresses only */ 82 /* Check for 7 bit slave addresses only */
@@ -110,14 +110,14 @@ static int i2c_pnx_start(unsigned char slave_addr, struct i2c_adapter *adap)
110 iowrite32(ioread32(I2C_REG_STS(alg_data)) | mstatus_tdi | mstatus_afi, 110 iowrite32(ioread32(I2C_REG_STS(alg_data)) | mstatus_tdi | mstatus_afi,
111 I2C_REG_STS(alg_data)); 111 I2C_REG_STS(alg_data));
112 112
113 dev_dbg(&adap->dev, "%s(): sending %#x\n", __FUNCTION__, 113 dev_dbg(&adap->dev, "%s(): sending %#x\n", __func__,
114 (slave_addr << 1) | start_bit | alg_data->mif.mode); 114 (slave_addr << 1) | start_bit | alg_data->mif.mode);
115 115
116 /* Write the slave address, START bit and R/W bit */ 116 /* Write the slave address, START bit and R/W bit */
117 iowrite32((slave_addr << 1) | start_bit | alg_data->mif.mode, 117 iowrite32((slave_addr << 1) | start_bit | alg_data->mif.mode,
118 I2C_REG_TX(alg_data)); 118 I2C_REG_TX(alg_data));
119 119
120 dev_dbg(&adap->dev, "%s(): exit\n", __FUNCTION__); 120 dev_dbg(&adap->dev, "%s(): exit\n", __func__);
121 121
122 return 0; 122 return 0;
123} 123}
@@ -135,7 +135,7 @@ static void i2c_pnx_stop(struct i2c_adapter *adap)
135 long timeout = 1000; 135 long timeout = 1000;
136 136
137 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n", 137 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n",
138 __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); 138 __func__, ioread32(I2C_REG_STS(alg_data)));
139 139
140 /* Write a STOP bit to TX FIFO */ 140 /* Write a STOP bit to TX FIFO */
141 iowrite32(0xff | stop_bit, I2C_REG_TX(alg_data)); 141 iowrite32(0xff | stop_bit, I2C_REG_TX(alg_data));
@@ -149,7 +149,7 @@ static void i2c_pnx_stop(struct i2c_adapter *adap)
149 } 149 }
150 150
151 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n", 151 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n",
152 __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); 152 __func__, ioread32(I2C_REG_STS(alg_data)));
153} 153}
154 154
155/** 155/**
@@ -164,7 +164,7 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap)
164 u32 val; 164 u32 val;
165 165
166 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n", 166 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n",
167 __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); 167 __func__, ioread32(I2C_REG_STS(alg_data)));
168 168
169 if (alg_data->mif.len > 0) { 169 if (alg_data->mif.len > 0) {
170 /* We still have something to talk about... */ 170 /* We still have something to talk about... */
@@ -179,7 +179,7 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap)
179 alg_data->mif.len--; 179 alg_data->mif.len--;
180 iowrite32(val, I2C_REG_TX(alg_data)); 180 iowrite32(val, I2C_REG_TX(alg_data));
181 181
182 dev_dbg(&adap->dev, "%s(): xmit %#x [%d]\n", __FUNCTION__, 182 dev_dbg(&adap->dev, "%s(): xmit %#x [%d]\n", __func__,
183 val, alg_data->mif.len + 1); 183 val, alg_data->mif.len + 1);
184 184
185 if (alg_data->mif.len == 0) { 185 if (alg_data->mif.len == 0) {
@@ -197,7 +197,7 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap)
197 del_timer_sync(&alg_data->mif.timer); 197 del_timer_sync(&alg_data->mif.timer);
198 198
199 dev_dbg(&adap->dev, "%s(): Waking up xfer routine.\n", 199 dev_dbg(&adap->dev, "%s(): Waking up xfer routine.\n",
200 __FUNCTION__); 200 __func__);
201 201
202 complete(&alg_data->mif.complete); 202 complete(&alg_data->mif.complete);
203 } 203 }
@@ -213,13 +213,13 @@ static int i2c_pnx_master_xmit(struct i2c_adapter *adap)
213 /* Stop timer. */ 213 /* Stop timer. */
214 del_timer_sync(&alg_data->mif.timer); 214 del_timer_sync(&alg_data->mif.timer);
215 dev_dbg(&adap->dev, "%s(): Waking up xfer routine after " 215 dev_dbg(&adap->dev, "%s(): Waking up xfer routine after "
216 "zero-xfer.\n", __FUNCTION__); 216 "zero-xfer.\n", __func__);
217 217
218 complete(&alg_data->mif.complete); 218 complete(&alg_data->mif.complete);
219 } 219 }
220 220
221 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n", 221 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n",
222 __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); 222 __func__, ioread32(I2C_REG_STS(alg_data)));
223 223
224 return 0; 224 return 0;
225} 225}
@@ -237,14 +237,14 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap)
237 u32 ctl = 0; 237 u32 ctl = 0;
238 238
239 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n", 239 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n",
240 __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); 240 __func__, ioread32(I2C_REG_STS(alg_data)));
241 241
242 /* Check, whether there is already data, 242 /* Check, whether there is already data,
243 * or we didn't 'ask' for it yet. 243 * or we didn't 'ask' for it yet.
244 */ 244 */
245 if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) { 245 if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) {
246 dev_dbg(&adap->dev, "%s(): Write dummy data to fill " 246 dev_dbg(&adap->dev, "%s(): Write dummy data to fill "
247 "Rx-fifo...\n", __FUNCTION__); 247 "Rx-fifo...\n", __func__);
248 248
249 if (alg_data->mif.len == 1) { 249 if (alg_data->mif.len == 1) {
250 /* Last byte, do not acknowledge next rcv. */ 250 /* Last byte, do not acknowledge next rcv. */
@@ -276,7 +276,7 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap)
276 if (alg_data->mif.len > 0) { 276 if (alg_data->mif.len > 0) {
277 val = ioread32(I2C_REG_RX(alg_data)); 277 val = ioread32(I2C_REG_RX(alg_data));
278 *alg_data->mif.buf++ = (u8) (val & 0xff); 278 *alg_data->mif.buf++ = (u8) (val & 0xff);
279 dev_dbg(&adap->dev, "%s(): rcv 0x%x [%d]\n", __FUNCTION__, val, 279 dev_dbg(&adap->dev, "%s(): rcv 0x%x [%d]\n", __func__, val,
280 alg_data->mif.len); 280 alg_data->mif.len);
281 281
282 alg_data->mif.len--; 282 alg_data->mif.len--;
@@ -300,7 +300,7 @@ static int i2c_pnx_master_rcv(struct i2c_adapter *adap)
300 } 300 }
301 301
302 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n", 302 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n",
303 __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); 303 __func__, ioread32(I2C_REG_STS(alg_data)));
304 304
305 return 0; 305 return 0;
306} 306}
@@ -312,7 +312,7 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)
312 struct i2c_pnx_algo_data *alg_data = adap->algo_data; 312 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
313 313
314 dev_dbg(&adap->dev, "%s(): mstat = %x mctrl = %x, mode = %d\n", 314 dev_dbg(&adap->dev, "%s(): mstat = %x mctrl = %x, mode = %d\n",
315 __FUNCTION__, 315 __func__,
316 ioread32(I2C_REG_STS(alg_data)), 316 ioread32(I2C_REG_STS(alg_data)),
317 ioread32(I2C_REG_CTL(alg_data)), 317 ioread32(I2C_REG_CTL(alg_data)),
318 alg_data->mif.mode); 318 alg_data->mif.mode);
@@ -336,7 +336,7 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)
336 /* Slave did not acknowledge, generate a STOP */ 336 /* Slave did not acknowledge, generate a STOP */
337 dev_dbg(&adap->dev, "%s(): " 337 dev_dbg(&adap->dev, "%s(): "
338 "Slave did not acknowledge, generating a STOP.\n", 338 "Slave did not acknowledge, generating a STOP.\n",
339 __FUNCTION__); 339 __func__);
340 i2c_pnx_stop(adap); 340 i2c_pnx_stop(adap);
341 341
342 /* Disable master interrupts. */ 342 /* Disable master interrupts. */
@@ -375,7 +375,7 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev_id)
375 iowrite32(stat | mstatus_tdi | mstatus_afi, I2C_REG_STS(alg_data)); 375 iowrite32(stat | mstatus_tdi | mstatus_afi, I2C_REG_STS(alg_data));
376 376
377 dev_dbg(&adap->dev, "%s(): exiting, stat = %x ctrl = %x.\n", 377 dev_dbg(&adap->dev, "%s(): exiting, stat = %x ctrl = %x.\n",
378 __FUNCTION__, ioread32(I2C_REG_STS(alg_data)), 378 __func__, ioread32(I2C_REG_STS(alg_data)),
379 ioread32(I2C_REG_CTL(alg_data))); 379 ioread32(I2C_REG_CTL(alg_data)));
380 380
381 return IRQ_HANDLED; 381 return IRQ_HANDLED;
@@ -447,7 +447,7 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
447 u32 stat = ioread32(I2C_REG_STS(alg_data)); 447 u32 stat = ioread32(I2C_REG_STS(alg_data));
448 448
449 dev_dbg(&adap->dev, "%s(): entering: %d messages, stat = %04x.\n", 449 dev_dbg(&adap->dev, "%s(): entering: %d messages, stat = %04x.\n",
450 __FUNCTION__, num, ioread32(I2C_REG_STS(alg_data))); 450 __func__, num, ioread32(I2C_REG_STS(alg_data)));
451 451
452 bus_reset_if_active(adap); 452 bus_reset_if_active(adap);
453 453
@@ -473,7 +473,7 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
473 alg_data->mif.ret = 0; 473 alg_data->mif.ret = 0;
474 alg_data->last = (i == num - 1); 474 alg_data->last = (i == num - 1);
475 475
476 dev_dbg(&adap->dev, "%s(): mode %d, %d bytes\n", __FUNCTION__, 476 dev_dbg(&adap->dev, "%s(): mode %d, %d bytes\n", __func__,
477 alg_data->mif.mode, 477 alg_data->mif.mode,
478 alg_data->mif.len); 478 alg_data->mif.len);
479 479
@@ -498,7 +498,7 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
498 if (!(rc = alg_data->mif.ret)) 498 if (!(rc = alg_data->mif.ret))
499 completed++; 499 completed++;
500 dev_dbg(&adap->dev, "%s(): Complete, return code = %d.\n", 500 dev_dbg(&adap->dev, "%s(): Complete, return code = %d.\n",
501 __FUNCTION__, rc); 501 __func__, rc);
502 502
503 /* Clear TDI and AFI bits in case they are set. */ 503 /* Clear TDI and AFI bits in case they are set. */
504 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_tdi) { 504 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_tdi) {
@@ -522,7 +522,7 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
522 alg_data->mif.len = 0; 522 alg_data->mif.len = 0;
523 523
524 dev_dbg(&adap->dev, "%s(): exiting, stat = %x\n", 524 dev_dbg(&adap->dev, "%s(): exiting, stat = %x\n",
525 __FUNCTION__, ioread32(I2C_REG_STS(alg_data))); 525 __func__, ioread32(I2C_REG_STS(alg_data)));
526 526
527 if (completed != num) 527 if (completed != num)
528 return ((rc < 0) ? rc : -EREMOTEIO); 528 return ((rc < 0) ? rc : -EREMOTEIO);
@@ -563,7 +563,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
563 563
564 if (!i2c_pnx || !i2c_pnx->adapter) { 564 if (!i2c_pnx || !i2c_pnx->adapter) {
565 dev_err(&pdev->dev, "%s: no platform data supplied\n", 565 dev_err(&pdev->dev, "%s: no platform data supplied\n",
566 __FUNCTION__); 566 __func__);
567 ret = -EINVAL; 567 ret = -EINVAL;
568 goto out; 568 goto out;
569 } 569 }
@@ -697,6 +697,7 @@ static void __exit i2c_adap_pnx_exit(void)
697MODULE_AUTHOR("Vitaly Wool, Dennis Kovalev <source@mvista.com>"); 697MODULE_AUTHOR("Vitaly Wool, Dennis Kovalev <source@mvista.com>");
698MODULE_DESCRIPTION("I2C driver for Philips IP3204-based I2C busses"); 698MODULE_DESCRIPTION("I2C driver for Philips IP3204-based I2C busses");
699MODULE_LICENSE("GPL"); 699MODULE_LICENSE("GPL");
700MODULE_ALIAS("platform:pnx-i2c");
700 701
701/* We need to make sure I2C is initialized before USB */ 702/* We need to make sure I2C is initialized before USB */
702subsys_initcall(i2c_adap_pnx_init); 703subsys_initcall(i2c_adap_pnx_init);
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 7813127649a1..22f6d5c00d80 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -263,6 +263,9 @@ static int __devexit i2c_powermac_probe(struct platform_device *dev)
263} 263}
264 264
265 265
266/* work with hotplug and coldplug */
267MODULE_ALIAS("platform:i2c-powermac");
268
266static struct platform_driver i2c_powermac_driver = { 269static struct platform_driver i2c_powermac_driver = {
267 .probe = i2c_powermac_probe, 270 .probe = i2c_powermac_probe,
268 .remove = __devexit_p(i2c_powermac_remove), 271 .remove = __devexit_p(i2c_powermac_remove),
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 6fd2d6a84eff..eb69fbadc9cb 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -155,7 +155,7 @@ static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
155 readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c))); 155 readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
156} 156}
157 157
158#define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __FUNCTION__) 158#define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__)
159#else 159#else
160#define i2c_debug 0 160#define i2c_debug 0
161 161
@@ -1132,6 +1132,7 @@ static void __exit i2c_adap_pxa_exit(void)
1132} 1132}
1133 1133
1134MODULE_LICENSE("GPL"); 1134MODULE_LICENSE("GPL");
1135MODULE_ALIAS("platform:pxa2xx-i2c");
1135 1136
1136module_init(i2c_adap_pxa_init); 1137module_init(i2c_adap_pxa_init);
1137module_exit(i2c_adap_pxa_exit); 1138module_exit(i2c_adap_pxa_exit);
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index c44ada5f4292..1305ef190fc1 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -276,12 +276,12 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
276 switch (i2c->state) { 276 switch (i2c->state) {
277 277
278 case STATE_IDLE: 278 case STATE_IDLE:
279 dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __FUNCTION__); 279 dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __func__);
280 goto out; 280 goto out;
281 break; 281 break;
282 282
283 case STATE_STOP: 283 case STATE_STOP:
284 dev_err(i2c->dev, "%s: called in STATE_STOP\n", __FUNCTION__); 284 dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__);
285 s3c24xx_i2c_disable_irq(i2c); 285 s3c24xx_i2c_disable_irq(i2c);
286 goto out_ack; 286 goto out_ack;
287 287
@@ -948,3 +948,4 @@ module_exit(i2c_adap_s3c_exit);
948MODULE_DESCRIPTION("S3C24XX I2C Bus driver"); 948MODULE_DESCRIPTION("S3C24XX I2C Bus driver");
949MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 949MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
950MODULE_LICENSE("GPL"); 950MODULE_LICENSE("GPL");
951MODULE_ALIAS("platform:s3c2410-i2c");
diff --git a/drivers/i2c/busses/i2c-sh7760.c b/drivers/i2c/busses/i2c-sh7760.c
new file mode 100644
index 000000000000..5e0e254976de
--- /dev/null
+++ b/drivers/i2c/busses/i2c-sh7760.c
@@ -0,0 +1,577 @@
1/*
2 * I2C bus driver for the SH7760 I2C Interfaces.
3 *
4 * (c) 2005-2008 MSC Vertriebsges.m.b.H, Manuel Lauss <mlau@msc-ge.com>
5 *
6 * licensed under the terms outlined in the file COPYING.
7 *
8 */
9
10#include <linux/completion.h>
11#include <linux/delay.h>
12#include <linux/err.h>
13#include <linux/i2c.h>
14#include <linux/init.h>
15#include <linux/interrupt.h>
16#include <linux/ioport.h>
17#include <linux/platform_device.h>
18#include <linux/slab.h>
19
20#include <asm/clock.h>
21#include <asm/i2c-sh7760.h>
22#include <asm/io.h>
23
24/* register offsets */
25#define I2CSCR 0x0 /* slave ctrl */
26#define I2CMCR 0x4 /* master ctrl */
27#define I2CSSR 0x8 /* slave status */
28#define I2CMSR 0xC /* master status */
29#define I2CSIER 0x10 /* slave irq enable */
30#define I2CMIER 0x14 /* master irq enable */
31#define I2CCCR 0x18 /* clock dividers */
32#define I2CSAR 0x1c /* slave address */
33#define I2CMAR 0x20 /* master address */
34#define I2CRXTX 0x24 /* data port */
35#define I2CFCR 0x28 /* fifo control */
36#define I2CFSR 0x2C /* fifo status */
37#define I2CFIER 0x30 /* fifo irq enable */
38#define I2CRFDR 0x34 /* rx fifo count */
39#define I2CTFDR 0x38 /* tx fifo count */
40
41#define REGSIZE 0x3C
42
43#define MCR_MDBS 0x80 /* non-fifo mode switch */
44#define MCR_FSCL 0x40 /* override SCL pin */
45#define MCR_FSDA 0x20 /* override SDA pin */
46#define MCR_OBPC 0x10 /* override pins */
47#define MCR_MIE 0x08 /* master if enable */
48#define MCR_TSBE 0x04
49#define MCR_FSB 0x02 /* force stop bit */
50#define MCR_ESG 0x01 /* en startbit gen. */
51
52#define MSR_MNR 0x40 /* nack received */
53#define MSR_MAL 0x20 /* arbitration lost */
54#define MSR_MST 0x10 /* sent a stop */
55#define MSR_MDE 0x08
56#define MSR_MDT 0x04
57#define MSR_MDR 0x02
58#define MSR_MAT 0x01 /* slave addr xfer done */
59
60#define MIE_MNRE 0x40 /* nack irq en */
61#define MIE_MALE 0x20 /* arblos irq en */
62#define MIE_MSTE 0x10 /* stop irq en */
63#define MIE_MDEE 0x08
64#define MIE_MDTE 0x04
65#define MIE_MDRE 0x02
66#define MIE_MATE 0x01 /* address sent irq en */
67
68#define FCR_RFRST 0x02 /* reset rx fifo */
69#define FCR_TFRST 0x01 /* reset tx fifo */
70
71#define FSR_TEND 0x04 /* last byte sent */
72#define FSR_RDF 0x02 /* rx fifo trigger */
73#define FSR_TDFE 0x01 /* tx fifo empty */
74
75#define FIER_TEIE 0x04 /* tx fifo empty irq en */
76#define FIER_RXIE 0x02 /* rx fifo trig irq en */
77#define FIER_TXIE 0x01 /* tx fifo trig irq en */
78
79#define FIFO_SIZE 16
80
81struct cami2c {
82 void __iomem *iobase;
83 struct i2c_adapter adap;
84
85 /* message processing */
86 struct i2c_msg *msg;
87#define IDF_SEND 1
88#define IDF_RECV 2
89#define IDF_STOP 4
90 int flags;
91
92#define IDS_DONE 1
93#define IDS_ARBLOST 2
94#define IDS_NACK 4
95 int status;
96 struct completion xfer_done;
97
98 int irq;
99 struct resource *ioarea;
100};
101
102static inline void OUT32(struct cami2c *cam, int reg, unsigned long val)
103{
104 ctrl_outl(val, (unsigned long)cam->iobase + reg);
105}
106
107static inline unsigned long IN32(struct cami2c *cam, int reg)
108{
109 return ctrl_inl((unsigned long)cam->iobase + reg);
110}
111
112static irqreturn_t sh7760_i2c_irq(int irq, void *ptr)
113{
114 struct cami2c *id = ptr;
115 struct i2c_msg *msg = id->msg;
116 char *data = msg->buf;
117 unsigned long msr, fsr, fier, len;
118
119 msr = IN32(id, I2CMSR);
120 fsr = IN32(id, I2CFSR);
121
122 /* arbitration lost */
123 if (msr & MSR_MAL) {
124 OUT32(id, I2CMCR, 0);
125 OUT32(id, I2CSCR, 0);
126 OUT32(id, I2CSAR, 0);
127 id->status |= IDS_DONE | IDS_ARBLOST;
128 goto out;
129 }
130
131 if (msr & MSR_MNR) {
132 /* NACK handling is very screwed up. After receiving a
133 * NAK IRQ one has to wait a bit before writing to any
134 * registers, or the ctl will lock up. After that delay
135 * do a normal i2c stop. Then wait at least 1 ms before
136 * attempting another transfer or ctl will stop working
137 */
138 udelay(100); /* wait or risk ctl hang */
139 OUT32(id, I2CFCR, FCR_RFRST | FCR_TFRST);
140 OUT32(id, I2CMCR, MCR_MIE | MCR_FSB);
141 OUT32(id, I2CFIER, 0);
142 OUT32(id, I2CMIER, MIE_MSTE);
143 OUT32(id, I2CSCR, 0);
144 OUT32(id, I2CSAR, 0);
145 id->status |= IDS_NACK;
146 msr &= ~MSR_MAT;
147 fsr = 0;
148 /* In some cases the MST bit is also set. */
149 }
150
151 /* i2c-stop was sent */
152 if (msr & MSR_MST) {
153 id->status |= IDS_DONE;
154 goto out;
155 }
156
157 /* i2c slave addr was sent; set to "normal" operation */
158 if (msr & MSR_MAT)
159 OUT32(id, I2CMCR, MCR_MIE);
160
161 fier = IN32(id, I2CFIER);
162
163 if (fsr & FSR_RDF) {
164 len = IN32(id, I2CRFDR);
165 if (msg->len <= len) {
166 if (id->flags & IDF_STOP) {
167 OUT32(id, I2CMCR, MCR_MIE | MCR_FSB);
168 OUT32(id, I2CFIER, 0);
169 /* manual says: wait >= 0.5 SCL times */
170 udelay(5);
171 /* next int should be MST */
172 } else {
173 id->status |= IDS_DONE;
174 /* keep the RDF bit: ctrl holds SCL low
175 * until the setup for the next i2c_msg
176 * clears this bit.
177 */
178 fsr &= ~FSR_RDF;
179 }
180 }
181 while (msg->len && len) {
182 *data++ = IN32(id, I2CRXTX);
183 msg->len--;
184 len--;
185 }
186
187 if (msg->len) {
188 len = (msg->len >= FIFO_SIZE) ? FIFO_SIZE - 1
189 : msg->len - 1;
190
191 OUT32(id, I2CFCR, FCR_TFRST | ((len & 0xf) << 4));
192 }
193
194 } else if (id->flags & IDF_SEND) {
195 if ((fsr & FSR_TEND) && (msg->len < 1)) {
196 if (id->flags & IDF_STOP) {
197 OUT32(id, I2CMCR, MCR_MIE | MCR_FSB);
198 } else {
199 id->status |= IDS_DONE;
200 /* keep the TEND bit: ctl holds SCL low
201 * until the setup for the next i2c_msg
202 * clears this bit.
203 */
204 fsr &= ~FSR_TEND;
205 }
206 }
207 if (fsr & FSR_TDFE) {
208 while (msg->len && (IN32(id, I2CTFDR) < FIFO_SIZE)) {
209 OUT32(id, I2CRXTX, *data++);
210 msg->len--;
211 }
212
213 if (msg->len < 1) {
214 fier &= ~FIER_TXIE;
215 OUT32(id, I2CFIER, fier);
216 } else {
217 len = (msg->len >= FIFO_SIZE) ? 2 : 0;
218 OUT32(id, I2CFCR,
219 FCR_RFRST | ((len & 3) << 2));
220 }
221 }
222 }
223out:
224 if (id->status & IDS_DONE) {
225 OUT32(id, I2CMIER, 0);
226 OUT32(id, I2CFIER, 0);
227 id->msg = NULL;
228 complete(&id->xfer_done);
229 }
230 /* clear status flags and ctrl resumes work */
231 OUT32(id, I2CMSR, ~msr);
232 OUT32(id, I2CFSR, ~fsr);
233 OUT32(id, I2CSSR, 0);
234
235 return IRQ_HANDLED;
236}
237
238
239/* prepare and start a master receive operation */
240static void sh7760_i2c_mrecv(struct cami2c *id)
241{
242 int len;
243
244 id->flags |= IDF_RECV;
245
246 /* set the slave addr reg; otherwise rcv wont work! */
247 OUT32(id, I2CSAR, 0xfe);
248 OUT32(id, I2CMAR, (id->msg->addr << 1) | 1);
249
250 /* adjust rx fifo trigger */
251 if (id->msg->len >= FIFO_SIZE)
252 len = FIFO_SIZE - 1; /* trigger at fifo full */
253 else
254 len = id->msg->len - 1; /* trigger before all received */
255
256 OUT32(id, I2CFCR, FCR_RFRST | FCR_TFRST);
257 OUT32(id, I2CFCR, FCR_TFRST | ((len & 0xF) << 4));
258
259 OUT32(id, I2CMSR, 0);
260 OUT32(id, I2CMCR, MCR_MIE | MCR_ESG);
261 OUT32(id, I2CMIER, MIE_MNRE | MIE_MALE | MIE_MSTE | MIE_MATE);
262 OUT32(id, I2CFIER, FIER_RXIE);
263}
264
265/* prepare and start a master send operation */
266static void sh7760_i2c_msend(struct cami2c *id)
267{
268 int len;
269
270 id->flags |= IDF_SEND;
271
272 /* set the slave addr reg; otherwise xmit wont work! */
273 OUT32(id, I2CSAR, 0xfe);
274 OUT32(id, I2CMAR, (id->msg->addr << 1) | 0);
275
276 /* adjust tx fifo trigger */
277 if (id->msg->len >= FIFO_SIZE)
278 len = 2; /* trig: 2 bytes left in TX fifo */
279 else
280 len = 0; /* trig: 8 bytes left in TX fifo */
281
282 OUT32(id, I2CFCR, FCR_RFRST | FCR_TFRST);
283 OUT32(id, I2CFCR, FCR_RFRST | ((len & 3) << 2));
284
285 while (id->msg->len && IN32(id, I2CTFDR) < FIFO_SIZE) {
286 OUT32(id, I2CRXTX, *(id->msg->buf));
287 (id->msg->len)--;
288 (id->msg->buf)++;
289 }
290
291 OUT32(id, I2CMSR, 0);
292 OUT32(id, I2CMCR, MCR_MIE | MCR_ESG);
293 OUT32(id, I2CFSR, 0);
294 OUT32(id, I2CMIER, MIE_MNRE | MIE_MALE | MIE_MSTE | MIE_MATE);
295 OUT32(id, I2CFIER, FIER_TEIE | (id->msg->len ? FIER_TXIE : 0));
296}
297
298static inline int sh7760_i2c_busy_check(struct cami2c *id)
299{
300 return (IN32(id, I2CMCR) & MCR_FSDA);
301}
302
303static int sh7760_i2c_master_xfer(struct i2c_adapter *adap,
304 struct i2c_msg *msgs,
305 int num)
306{
307 struct cami2c *id = adap->algo_data;
308 int i, retr;
309
310 if (sh7760_i2c_busy_check(id)) {
311 dev_err(&adap->dev, "sh7760-i2c%d: bus busy!\n", adap->nr);
312 return -EBUSY;
313 }
314
315 i = 0;
316 while (i < num) {
317 retr = adap->retries;
318retry:
319 id->flags = ((i == (num-1)) ? IDF_STOP : 0);
320 id->status = 0;
321 id->msg = msgs;
322 init_completion(&id->xfer_done);
323
324 if (msgs->flags & I2C_M_RD)
325 sh7760_i2c_mrecv(id);
326 else
327 sh7760_i2c_msend(id);
328
329 wait_for_completion(&id->xfer_done);
330
331 if (id->status == 0) {
332 num = -EIO;
333 break;
334 }
335
336 if (id->status & IDS_NACK) {
337 /* wait a bit or i2c module stops working */
338 mdelay(1);
339 num = -EREMOTEIO;
340 break;
341 }
342
343 if (id->status & IDS_ARBLOST) {
344 if (retr--) {
345 mdelay(2);
346 goto retry;
347 }
348 num = -EREMOTEIO;
349 break;
350 }
351
352 msgs++;
353 i++;
354 }
355
356 id->msg = NULL;
357 id->flags = 0;
358 id->status = 0;
359
360 OUT32(id, I2CMCR, 0);
361 OUT32(id, I2CMSR, 0);
362 OUT32(id, I2CMIER, 0);
363 OUT32(id, I2CFIER, 0);
364
365 /* reset slave module registers too: master mode enables slave
366 * module for receive ops (ack, data). Without this reset,
367 * eternal bus activity might be reported after NACK / ARBLOST.
368 */
369 OUT32(id, I2CSCR, 0);
370 OUT32(id, I2CSAR, 0);
371 OUT32(id, I2CSSR, 0);
372
373 return num;
374}
375
376static u32 sh7760_i2c_func(struct i2c_adapter *adap)
377{
378 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
379}
380
381static const struct i2c_algorithm sh7760_i2c_algo = {
382 .master_xfer = sh7760_i2c_master_xfer,
383 .functionality = sh7760_i2c_func,
384};
385
386/* calculate CCR register setting for a desired scl clock. SCL clock is
387 * derived from I2C module clock (iclk) which in turn is derived from
388 * peripheral module clock (mclk, usually around 33MHz):
389 * iclk = mclk/(CDF + 1). iclk must be < 20MHz.
390 * scl = iclk/(SCGD*8 + 20).
391 */
392static int __devinit calc_CCR(unsigned long scl_hz)
393{
394 struct clk *mclk;
395 unsigned long mck, m1, dff, odff, iclk;
396 signed char cdf, cdfm;
397 int scgd, scgdm, scgds;
398
399 mclk = clk_get(NULL, "module_clk");
400 if (IS_ERR(mclk)) {
401 return PTR_ERR(mclk);
402 } else {
403 mck = mclk->rate;
404 clk_put(mclk);
405 }
406
407 odff = scl_hz;
408 scgdm = cdfm = m1 = 0;
409 for (cdf = 3; cdf >= 0; cdf--) {
410 iclk = mck / (1 + cdf);
411 if (iclk >= 20000000)
412 continue;
413 scgds = ((iclk / scl_hz) - 20) >> 3;
414 for (scgd = scgds; (scgd < 63) && scgd <= scgds + 1; scgd++) {
415 m1 = iclk / (20 + (scgd << 3));
416 dff = abs(scl_hz - m1);
417 if (dff < odff) {
418 odff = dff;
419 cdfm = cdf;
420 scgdm = scgd;
421 }
422 }
423 }
424 /* fail if more than 25% off of requested SCL */
425 if (odff > (scl_hz >> 2))
426 return -EINVAL;
427
428 /* create a CCR register value */
429 return ((scgdm << 2) | cdfm);
430}
431
432static int __devinit sh7760_i2c_probe(struct platform_device *pdev)
433{
434 struct sh7760_i2c_platdata *pd;
435 struct resource *res;
436 struct cami2c *id;
437 int ret;
438
439 pd = pdev->dev.platform_data;
440 if (!pd) {
441 dev_err(&pdev->dev, "no platform_data!\n");
442 ret = -ENODEV;
443 goto out0;
444 }
445
446 id = kzalloc(sizeof(struct cami2c), GFP_KERNEL);
447 if (!id) {
448 dev_err(&pdev->dev, "no mem for private data\n");
449 ret = -ENOMEM;
450 goto out0;
451 }
452
453 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
454 if (!res) {
455 dev_err(&pdev->dev, "no mmio resources\n");
456 ret = -ENODEV;
457 goto out1;
458 }
459
460 id->ioarea = request_mem_region(res->start, REGSIZE, pdev->name);
461 if (!id->ioarea) {
462 dev_err(&pdev->dev, "mmio already reserved\n");
463 ret = -EBUSY;
464 goto out1;
465 }
466
467 id->iobase = ioremap(res->start, REGSIZE);
468 if (!id->iobase) {
469 dev_err(&pdev->dev, "cannot ioremap\n");
470 ret = -ENODEV;
471 goto out2;
472 }
473
474 id->irq = platform_get_irq(pdev, 0);
475
476 id->adap.nr = pdev->id;
477 id->adap.algo = &sh7760_i2c_algo;
478 id->adap.class = I2C_CLASS_ALL;
479 id->adap.retries = 3;
480 id->adap.algo_data = id;
481 id->adap.dev.parent = &pdev->dev;
482 snprintf(id->adap.name, sizeof(id->adap.name),
483 "SH7760 I2C at %08lx", (unsigned long)res->start);
484
485 OUT32(id, I2CMCR, 0);
486 OUT32(id, I2CMSR, 0);
487 OUT32(id, I2CMIER, 0);
488 OUT32(id, I2CMAR, 0);
489 OUT32(id, I2CSIER, 0);
490 OUT32(id, I2CSAR, 0);
491 OUT32(id, I2CSCR, 0);
492 OUT32(id, I2CSSR, 0);
493 OUT32(id, I2CFIER, 0);
494 OUT32(id, I2CFCR, FCR_RFRST | FCR_TFRST);
495 OUT32(id, I2CFSR, 0);
496
497 ret = calc_CCR(pd->speed_khz * 1000);
498 if (ret < 0) {
499 dev_err(&pdev->dev, "invalid SCL clock: %dkHz\n",
500 pd->speed_khz);
501 goto out3;
502 }
503 OUT32(id, I2CCCR, ret);
504
505 if (request_irq(id->irq, sh7760_i2c_irq, IRQF_DISABLED,
506 SH7760_I2C_DEVNAME, id)) {
507 dev_err(&pdev->dev, "cannot get irq %d\n", id->irq);
508 ret = -EBUSY;
509 goto out3;
510 }
511
512 ret = i2c_add_numbered_adapter(&id->adap);
513 if (ret < 0) {
514 dev_err(&pdev->dev, "reg adap failed: %d\n", ret);
515 goto out4;
516 }
517
518 platform_set_drvdata(pdev, id);
519
520 dev_info(&pdev->dev, "%d kHz mmio %08x irq %d\n",
521 pd->speed_khz, res->start, id->irq);
522
523 return 0;
524
525out4:
526 free_irq(id->irq, id);
527out3:
528 iounmap(id->iobase);
529out2:
530 release_resource(id->ioarea);
531 kfree(id->ioarea);
532out1:
533 kfree(id);
534out0:
535 return ret;
536}
537
538static int __devexit sh7760_i2c_remove(struct platform_device *pdev)
539{
540 struct cami2c *id = platform_get_drvdata(pdev);
541
542 i2c_del_adapter(&id->adap);
543 free_irq(id->irq, id);
544 iounmap(id->iobase);
545 release_resource(id->ioarea);
546 kfree(id->ioarea);
547 kfree(id);
548 platform_set_drvdata(pdev, NULL);
549
550 return 0;
551}
552
553static struct platform_driver sh7760_i2c_drv = {
554 .driver = {
555 .name = SH7760_I2C_DEVNAME,
556 .owner = THIS_MODULE,
557 },
558 .probe = sh7760_i2c_probe,
559 .remove = __devexit_p(sh7760_i2c_remove),
560};
561
562static int __init sh7760_i2c_init(void)
563{
564 return platform_driver_register(&sh7760_i2c_drv);
565}
566
567static void __exit sh7760_i2c_exit(void)
568{
569 platform_driver_unregister(&sh7760_i2c_drv);
570}
571
572module_init(sh7760_i2c_init);
573module_exit(sh7760_i2c_exit);
574
575MODULE_LICENSE("GPL");
576MODULE_DESCRIPTION("SH7760 I2C bus driver");
577MODULE_AUTHOR("Manuel Lauss <mano@roarinelk.homelinux.net>");
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
new file mode 100644
index 000000000000..840e634fa31f
--- /dev/null
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -0,0 +1,500 @@
1/*
2 * SuperH Mobile I2C Controller
3 *
4 * Copyright (C) 2008 Magnus Damm
5 *
6 * Portions of the code based on out-of-tree driver i2c-sh7343.c
7 * Copyright (c) 2006 Carlos Munoz <carlos@kenati.com>
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 as published by
11 * the Free Software Foundation; either version 2 of the License
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/delay.h>
27#include <linux/platform_device.h>
28#include <linux/interrupt.h>
29#include <linux/i2c.h>
30#include <linux/err.h>
31#include <linux/clk.h>
32#include <linux/io.h>
33
34enum sh_mobile_i2c_op {
35 OP_START = 0,
36 OP_TX_ONLY,
37 OP_TX_STOP,
38 OP_TX_TO_RX,
39 OP_RX_ONLY,
40 OP_RX_STOP,
41};
42
43struct sh_mobile_i2c_data {
44 struct device *dev;
45 void __iomem *reg;
46 struct i2c_adapter adap;
47
48 struct clk *clk;
49 u_int8_t iccl;
50 u_int8_t icch;
51
52 spinlock_t lock;
53 wait_queue_head_t wait;
54 struct i2c_msg *msg;
55 int pos;
56 int sr;
57};
58
59#define NORMAL_SPEED 100000 /* FAST_SPEED 400000 */
60
61/* Register offsets */
62#define ICDR(pd) (pd->reg + 0x00)
63#define ICCR(pd) (pd->reg + 0x04)
64#define ICSR(pd) (pd->reg + 0x08)
65#define ICIC(pd) (pd->reg + 0x0c)
66#define ICCL(pd) (pd->reg + 0x10)
67#define ICCH(pd) (pd->reg + 0x14)
68
69/* Register bits */
70#define ICCR_ICE 0x80
71#define ICCR_RACK 0x40
72#define ICCR_TRS 0x10
73#define ICCR_BBSY 0x04
74#define ICCR_SCP 0x01
75
76#define ICSR_SCLM 0x80
77#define ICSR_SDAM 0x40
78#define SW_DONE 0x20
79#define ICSR_BUSY 0x10
80#define ICSR_AL 0x08
81#define ICSR_TACK 0x04
82#define ICSR_WAIT 0x02
83#define ICSR_DTE 0x01
84
85#define ICIC_ALE 0x08
86#define ICIC_TACKE 0x04
87#define ICIC_WAITE 0x02
88#define ICIC_DTEE 0x01
89
90static void activate_ch(struct sh_mobile_i2c_data *pd)
91{
92 /* Make sure the clock is enabled */
93 clk_enable(pd->clk);
94
95 /* Enable channel and configure rx ack */
96 iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd));
97
98 /* Mask all interrupts */
99 iowrite8(0, ICIC(pd));
100
101 /* Set the clock */
102 iowrite8(pd->iccl, ICCL(pd));
103 iowrite8(pd->icch, ICCH(pd));
104}
105
106static void deactivate_ch(struct sh_mobile_i2c_data *pd)
107{
108 /* Clear/disable interrupts */
109 iowrite8(0, ICSR(pd));
110 iowrite8(0, ICIC(pd));
111
112 /* Disable channel */
113 iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd));
114
115 /* Disable clock */
116 clk_disable(pd->clk);
117}
118
119static unsigned char i2c_op(struct sh_mobile_i2c_data *pd,
120 enum sh_mobile_i2c_op op, unsigned char data)
121{
122 unsigned char ret = 0;
123 unsigned long flags;
124
125 dev_dbg(pd->dev, "op %d, data in 0x%02x\n", op, data);
126
127 spin_lock_irqsave(&pd->lock, flags);
128
129 switch (op) {
130 case OP_START:
131 iowrite8(0x94, ICCR(pd));
132 break;
133 case OP_TX_ONLY:
134 iowrite8(data, ICDR(pd));
135 break;
136 case OP_TX_STOP:
137 iowrite8(data, ICDR(pd));
138 iowrite8(0x90, ICCR(pd));
139 iowrite8(ICIC_ALE | ICIC_TACKE, ICIC(pd));
140 break;
141 case OP_TX_TO_RX:
142 iowrite8(data, ICDR(pd));
143 iowrite8(0x81, ICCR(pd));
144 break;
145 case OP_RX_ONLY:
146 ret = ioread8(ICDR(pd));
147 break;
148 case OP_RX_STOP:
149 ret = ioread8(ICDR(pd));
150 iowrite8(0xc0, ICCR(pd));
151 break;
152 }
153
154 spin_unlock_irqrestore(&pd->lock, flags);
155
156 dev_dbg(pd->dev, "op %d, data out 0x%02x\n", op, ret);
157 return ret;
158}
159
160static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
161{
162 struct platform_device *dev = dev_id;
163 struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev);
164 struct i2c_msg *msg = pd->msg;
165 unsigned char data, sr;
166 int wakeup = 0;
167
168 sr = ioread8(ICSR(pd));
169 pd->sr |= sr;
170
171 dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr,
172 (msg->flags & I2C_M_RD) ? "read" : "write",
173 pd->pos, msg->len);
174
175 if (sr & (ICSR_AL | ICSR_TACK)) {
176 iowrite8(0, ICIC(pd)); /* disable interrupts */
177 wakeup = 1;
178 goto do_wakeup;
179 }
180
181 if (pd->pos == msg->len) {
182 i2c_op(pd, OP_RX_ONLY, 0);
183 wakeup = 1;
184 goto do_wakeup;
185 }
186
187 if (pd->pos == -1) {
188 data = (msg->addr & 0x7f) << 1;
189 data |= (msg->flags & I2C_M_RD) ? 1 : 0;
190 } else
191 data = msg->buf[pd->pos];
192
193 if ((pd->pos == -1) || !(msg->flags & I2C_M_RD)) {
194 if (msg->flags & I2C_M_RD)
195 i2c_op(pd, OP_TX_TO_RX, data);
196 else if (pd->pos == (msg->len - 1)) {
197 i2c_op(pd, OP_TX_STOP, data);
198 wakeup = 1;
199 } else
200 i2c_op(pd, OP_TX_ONLY, data);
201 } else {
202 if (pd->pos == (msg->len - 1))
203 data = i2c_op(pd, OP_RX_STOP, 0);
204 else
205 data = i2c_op(pd, OP_RX_ONLY, 0);
206
207 msg->buf[pd->pos] = data;
208 }
209 pd->pos++;
210
211 do_wakeup:
212 if (wakeup) {
213 pd->sr |= SW_DONE;
214 wake_up(&pd->wait);
215 }
216
217 return IRQ_HANDLED;
218}
219
220static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg)
221{
222 /* Initialize channel registers */
223 iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd));
224
225 /* Enable channel and configure rx ack */
226 iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd));
227
228 /* Set the clock */
229 iowrite8(pd->iccl, ICCL(pd));
230 iowrite8(pd->icch, ICCH(pd));
231
232 pd->msg = usr_msg;
233 pd->pos = -1;
234 pd->sr = 0;
235
236 /* Enable all interrupts except wait */
237 iowrite8(ioread8(ICIC(pd)) | ICIC_ALE | ICIC_TACKE | ICIC_DTEE,
238 ICIC(pd));
239 return 0;
240}
241
242static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
243 struct i2c_msg *msgs,
244 int num)
245{
246 struct sh_mobile_i2c_data *pd = i2c_get_adapdata(adapter);
247 struct i2c_msg *msg;
248 int err = 0;
249 u_int8_t val;
250 int i, k, retry_count;
251
252 activate_ch(pd);
253
254 /* Process all messages */
255 for (i = 0; i < num; i++) {
256 msg = &msgs[i];
257
258 err = start_ch(pd, msg);
259 if (err)
260 break;
261
262 i2c_op(pd, OP_START, 0);
263
264 /* The interrupt handler takes care of the rest... */
265 k = wait_event_timeout(pd->wait,
266 pd->sr & (ICSR_TACK | SW_DONE),
267 5 * HZ);
268 if (!k)
269 dev_err(pd->dev, "Transfer request timed out\n");
270
271 retry_count = 10;
272again:
273 val = ioread8(ICSR(pd));
274
275 dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr);
276
277 if ((val | pd->sr) & (ICSR_TACK | ICSR_AL)) {
278 err = -EIO;
279 break;
280 }
281
282 /* the interrupt handler may wake us up before the
283 * transfer is finished, so poll the hardware
284 * until we're done.
285 */
286
287 if (!(!(val & ICSR_BUSY) && (val & ICSR_SCLM) &&
288 (val & ICSR_SDAM))) {
289 msleep(1);
290 if (retry_count--)
291 goto again;
292
293 err = -EIO;
294 dev_err(pd->dev, "Polling timed out\n");
295 break;
296 }
297 }
298
299 deactivate_ch(pd);
300
301 if (!err)
302 err = num;
303 return err;
304}
305
306static u32 sh_mobile_i2c_func(struct i2c_adapter *adapter)
307{
308 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
309}
310
311static struct i2c_algorithm sh_mobile_i2c_algorithm = {
312 .functionality = sh_mobile_i2c_func,
313 .master_xfer = sh_mobile_i2c_xfer,
314};
315
316static void sh_mobile_i2c_setup_channel(struct platform_device *dev)
317{
318 struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev);
319 unsigned long peripheral_clk = clk_get_rate(pd->clk);
320 u_int32_t num;
321 u_int32_t denom;
322 u_int32_t tmp;
323
324 spin_lock_init(&pd->lock);
325 init_waitqueue_head(&pd->wait);
326
327 /* Calculate the value for iccl. From the data sheet:
328 * iccl = (p clock / transfer rate) * (L / (L + H))
329 * where L and H are the SCL low/high ratio (5/4 in this case).
330 * We also round off the result.
331 */
332 num = peripheral_clk * 5;
333 denom = NORMAL_SPEED * 9;
334 tmp = num * 10 / denom;
335 if (tmp % 10 >= 5)
336 pd->iccl = (u_int8_t)((num/denom) + 1);
337 else
338 pd->iccl = (u_int8_t)(num/denom);
339
340 /* Calculate the value for icch. From the data sheet:
341 icch = (p clock / transfer rate) * (H / (L + H)) */
342 num = peripheral_clk * 4;
343 tmp = num * 10 / denom;
344 if (tmp % 10 >= 5)
345 pd->icch = (u_int8_t)((num/denom) + 1);
346 else
347 pd->icch = (u_int8_t)(num/denom);
348}
349
350static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
351{
352 struct resource *res;
353 int ret = -ENXIO;
354 int q, m;
355 int k = 0;
356 int n = 0;
357
358 while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
359 for (n = res->start; hook && n <= res->end; n++) {
360 if (request_irq(n, sh_mobile_i2c_isr, IRQF_DISABLED,
361 dev->dev.bus_id, dev))
362 goto rollback;
363 }
364 k++;
365 }
366
367 if (hook)
368 return k > 0 ? 0 : -ENOENT;
369
370 k--;
371 ret = 0;
372
373 rollback:
374 for (q = k; k >= 0; k--) {
375 for (m = n; m >= res->start; m--)
376 free_irq(m, dev);
377
378 res = platform_get_resource(dev, IORESOURCE_IRQ, k - 1);
379 m = res->end;
380 }
381
382 return ret;
383}
384
385static int sh_mobile_i2c_probe(struct platform_device *dev)
386{
387 struct sh_mobile_i2c_data *pd;
388 struct i2c_adapter *adap;
389 struct resource *res;
390 int size;
391 int ret;
392
393 pd = kzalloc(sizeof(struct sh_mobile_i2c_data), GFP_KERNEL);
394 if (pd == NULL) {
395 dev_err(&dev->dev, "cannot allocate private data\n");
396 return -ENOMEM;
397 }
398
399 pd->clk = clk_get(&dev->dev, "peripheral_clk");
400 if (IS_ERR(pd->clk)) {
401 dev_err(&dev->dev, "cannot get peripheral clock\n");
402 ret = PTR_ERR(pd->clk);
403 goto err;
404 }
405
406 ret = sh_mobile_i2c_hook_irqs(dev, 1);
407 if (ret) {
408 dev_err(&dev->dev, "cannot request IRQ\n");
409 goto err_clk;
410 }
411
412 pd->dev = &dev->dev;
413 platform_set_drvdata(dev, pd);
414
415 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
416 if (res == NULL) {
417 dev_err(&dev->dev, "cannot find IO resource\n");
418 ret = -ENOENT;
419 goto err_irq;
420 }
421
422 size = (res->end - res->start) + 1;
423
424 pd->reg = ioremap(res->start, size);
425 if (pd->reg == NULL) {
426 dev_err(&dev->dev, "cannot map IO\n");
427 ret = -ENXIO;
428 goto err_irq;
429 }
430
431 /* setup the private data */
432 adap = &pd->adap;
433 i2c_set_adapdata(adap, pd);
434
435 adap->owner = THIS_MODULE;
436 adap->algo = &sh_mobile_i2c_algorithm;
437 adap->dev.parent = &dev->dev;
438 adap->retries = 5;
439 adap->nr = dev->id;
440
441 strlcpy(adap->name, dev->name, sizeof(adap->name));
442
443 sh_mobile_i2c_setup_channel(dev);
444
445 ret = i2c_add_numbered_adapter(adap);
446 if (ret < 0) {
447 dev_err(&dev->dev, "cannot add numbered adapter\n");
448 goto err_all;
449 }
450
451 return 0;
452
453 err_all:
454 iounmap(pd->reg);
455 err_irq:
456 sh_mobile_i2c_hook_irqs(dev, 0);
457 err_clk:
458 clk_put(pd->clk);
459 err:
460 kfree(pd);
461 return ret;
462}
463
464static int sh_mobile_i2c_remove(struct platform_device *dev)
465{
466 struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev);
467
468 i2c_del_adapter(&pd->adap);
469 iounmap(pd->reg);
470 sh_mobile_i2c_hook_irqs(dev, 0);
471 clk_put(pd->clk);
472 kfree(pd);
473 return 0;
474}
475
476static struct platform_driver sh_mobile_i2c_driver = {
477 .driver = {
478 .name = "i2c-sh_mobile",
479 .owner = THIS_MODULE,
480 },
481 .probe = sh_mobile_i2c_probe,
482 .remove = sh_mobile_i2c_remove,
483};
484
485static int __init sh_mobile_i2c_adap_init(void)
486{
487 return platform_driver_register(&sh_mobile_i2c_driver);
488}
489
490static void __exit sh_mobile_i2c_adap_exit(void)
491{
492 platform_driver_unregister(&sh_mobile_i2c_driver);
493}
494
495module_init(sh_mobile_i2c_adap_init);
496module_exit(sh_mobile_i2c_adap_exit);
497
498MODULE_DESCRIPTION("SuperH Mobile I2C Bus Controller driver");
499MODULE_AUTHOR("Magnus Damm");
500MODULE_LICENSE("GPL v2");
diff --git a/drivers/i2c/busses/i2c-simtec.c b/drivers/i2c/busses/i2c-simtec.c
index 10af8d31e12a..042fda295f3a 100644
--- a/drivers/i2c/busses/i2c-simtec.c
+++ b/drivers/i2c/busses/i2c-simtec.c
@@ -159,6 +159,9 @@ static int simtec_i2c_remove(struct platform_device *dev)
159 159
160/* device driver */ 160/* device driver */
161 161
162/* work with hotplug and coldplug */
163MODULE_ALIAS("platform:simtec-i2c");
164
162static struct platform_driver simtec_i2c_driver = { 165static struct platform_driver simtec_i2c_driver = {
163 .driver = { 166 .driver = {
164 .name = "simtec-i2c", 167 .name = "simtec-i2c",
diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c
index 081d9578ce10..4678babd3ce6 100644
--- a/drivers/i2c/busses/i2c-versatile.c
+++ b/drivers/i2c/busses/i2c-versatile.c
@@ -151,3 +151,4 @@ module_exit(i2c_versatile_exit);
151 151
152MODULE_DESCRIPTION("ARM Versatile I2C bus driver"); 152MODULE_DESCRIPTION("ARM Versatile I2C bus driver");
153MODULE_LICENSE("GPL"); 153MODULE_LICENSE("GPL");
154MODULE_ALIAS("platform:versatile-i2c");
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index f5e7a70da831..61abe0f33255 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -527,7 +527,7 @@ static int __init scx200_create_isa(const char *text, unsigned long base,
527 if (iface == NULL) 527 if (iface == NULL)
528 return -ENOMEM; 528 return -ENOMEM;
529 529
530 if (request_region(base, 8, iface->adapter.name) == 0) { 530 if (!request_region(base, 8, iface->adapter.name)) {
531 printk(KERN_ERR NAME ": can't allocate io 0x%lx-0x%lx\n", 531 printk(KERN_ERR NAME ": can't allocate io 0x%lx-0x%lx\n",
532 base, base + 8 - 1); 532 base, base + 8 - 1);
533 rc = -EBUSY; 533 rc = -EBUSY;
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index 2a3160153f54..b1b45dddb17e 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -658,7 +658,7 @@ pulldown:
658 OTG_CTRL_REG |= OTG_PULLUP; 658 OTG_CTRL_REG |= OTG_PULLUP;
659 } 659 }
660 660
661 check_state(isp, __FUNCTION__); 661 check_state(isp, __func__);
662 dump_regs(isp, "otg->isp1301"); 662 dump_regs(isp, "otg->isp1301");
663} 663}
664 664
@@ -782,7 +782,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
782 if (otg_ctrl & OTG_DRIVER_SEL) { 782 if (otg_ctrl & OTG_DRIVER_SEL) {
783 switch (isp->otg.state) { 783 switch (isp->otg.state) {
784 case OTG_STATE_A_IDLE: 784 case OTG_STATE_A_IDLE:
785 b_idle(isp, __FUNCTION__); 785 b_idle(isp, __func__);
786 break; 786 break;
787 default: 787 default:
788 break; 788 break;
@@ -826,7 +826,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
826 isp->otg.host->otg_port); 826 isp->otg.host->otg_port);
827 } 827 }
828 828
829 check_state(isp, __FUNCTION__); 829 check_state(isp, __func__);
830 return ret; 830 return ret;
831} 831}
832 832
@@ -837,7 +837,7 @@ static int otg_init(struct isp1301 *isp)
837 if (!otg_dev) 837 if (!otg_dev)
838 return -ENODEV; 838 return -ENODEV;
839 839
840 dump_regs(isp, __FUNCTION__); 840 dump_regs(isp, __func__);
841 /* some of these values are board-specific... */ 841 /* some of these values are board-specific... */
842 OTG_SYSCON_2_REG |= OTG_EN 842 OTG_SYSCON_2_REG |= OTG_EN
843 /* for B-device: */ 843 /* for B-device: */
@@ -853,9 +853,9 @@ static int otg_init(struct isp1301 *isp)
853 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE)); 853 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
854 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS)); 854 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
855 855
856 check_state(isp, __FUNCTION__); 856 check_state(isp, __func__);
857 pr_debug("otg: %s, %s %06x\n", 857 pr_debug("otg: %s, %s %06x\n",
858 state_name(isp), __FUNCTION__, OTG_CTRL_REG); 858 state_name(isp), __func__, OTG_CTRL_REG);
859 859
860 OTG_IRQ_EN_REG = DRIVER_SWITCH | OPRT_CHG 860 OTG_IRQ_EN_REG = DRIVER_SWITCH | OPRT_CHG
861 | B_SRP_TMROUT | B_HNP_FAIL 861 | B_SRP_TMROUT | B_HNP_FAIL
@@ -1041,11 +1041,11 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
1041 OTG1_DP_PULLDOWN); 1041 OTG1_DP_PULLDOWN);
1042 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, 1042 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1043 OTG1_DP_PULLUP); 1043 OTG1_DP_PULLUP);
1044 dump_regs(isp, __FUNCTION__); 1044 dump_regs(isp, __func__);
1045#endif 1045#endif
1046 /* FALLTHROUGH */ 1046 /* FALLTHROUGH */
1047 case OTG_STATE_B_SRP_INIT: 1047 case OTG_STATE_B_SRP_INIT:
1048 b_idle(isp, __FUNCTION__); 1048 b_idle(isp, __func__);
1049 OTG_CTRL_REG &= OTG_CTRL_REG & OTG_XCEIV_OUTPUTS; 1049 OTG_CTRL_REG &= OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
1050 /* FALLTHROUGH */ 1050 /* FALLTHROUGH */
1051 case OTG_STATE_B_IDLE: 1051 case OTG_STATE_B_IDLE:
@@ -1077,7 +1077,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
1077 */ 1077 */
1078 update_otg1(isp, isp_stat); 1078 update_otg1(isp, isp_stat);
1079 update_otg2(isp, isp_bstat); 1079 update_otg2(isp, isp_bstat);
1080 check_state(isp, __FUNCTION__); 1080 check_state(isp, __func__);
1081#endif 1081#endif
1082 1082
1083 dump_regs(isp, "isp1301->otg"); 1083 dump_regs(isp, "isp1301->otg");
@@ -1310,7 +1310,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1310 */ 1310 */
1311 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV); 1311 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV);
1312 1312
1313 dump_regs(isp, __FUNCTION__); 1313 dump_regs(isp, __func__);
1314 1314
1315 return 0; 1315 return 0;
1316 1316
@@ -1365,7 +1365,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1365 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, 1365 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1366 INTR_VBUS_VLD); 1366 INTR_VBUS_VLD);
1367 dev_info(&isp->client.dev, "B-Peripheral sessions ok\n"); 1367 dev_info(&isp->client.dev, "B-Peripheral sessions ok\n");
1368 dump_regs(isp, __FUNCTION__); 1368 dump_regs(isp, __func__);
1369 1369
1370 /* If this has a Mini-AB connector, this mode is highly 1370 /* If this has a Mini-AB connector, this mode is highly
1371 * nonstandard ... but can be handy for testing, so long 1371 * nonstandard ... but can be handy for testing, so long
@@ -1416,7 +1416,7 @@ isp1301_start_srp(struct otg_transceiver *dev)
1416 1416
1417 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp), OTG_CTRL_REG); 1417 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp), OTG_CTRL_REG);
1418#ifdef CONFIG_USB_OTG 1418#ifdef CONFIG_USB_OTG
1419 check_state(isp, __FUNCTION__); 1419 check_state(isp, __func__);
1420#endif 1420#endif
1421 return 0; 1421 return 0;
1422} 1422}
@@ -1463,7 +1463,7 @@ isp1301_start_hnp(struct otg_transceiver *dev)
1463 } 1463 }
1464 pr_debug("otg: HNP %s, %06x ...\n", 1464 pr_debug("otg: HNP %s, %06x ...\n",
1465 state_name(isp), OTG_CTRL_REG); 1465 state_name(isp), OTG_CTRL_REG);
1466 check_state(isp, __FUNCTION__); 1466 check_state(isp, __func__);
1467 return 0; 1467 return 0;
1468#else 1468#else
1469 /* srp-only */ 1469 /* srp-only */
@@ -1601,7 +1601,7 @@ fail2:
1601 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS)); 1601 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
1602#endif 1602#endif
1603 1603
1604 dump_regs(isp, __FUNCTION__); 1604 dump_regs(isp, __func__);
1605 1605
1606#ifdef VERBOSE 1606#ifdef VERBOSE
1607 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); 1607 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index e186df657119..6c7fa8d53c0e 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1506,7 +1506,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1506 read_write = I2C_SMBUS_READ; 1506 read_write = I2C_SMBUS_READ;
1507 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { 1507 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) {
1508 dev_err(&adapter->dev, "%s called with invalid " 1508 dev_err(&adapter->dev, "%s called with invalid "
1509 "block proc call size (%d)\n", __FUNCTION__, 1509 "block proc call size (%d)\n", __func__,
1510 data->block[0]); 1510 data->block[0]);
1511 return -1; 1511 return -1;
1512 } 1512 }
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 393e679d9faa..d34c14c81c29 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -200,16 +200,176 @@ static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr)
200 return device_for_each_child(&adapter->dev, &addr, i2cdev_check); 200 return device_for_each_child(&adapter->dev, &addr, i2cdev_check);
201} 201}
202 202
203static int i2cdev_ioctl(struct inode *inode, struct file *file, 203static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
204 unsigned int cmd, unsigned long arg) 204 unsigned long arg)
205{ 205{
206 struct i2c_client *client = (struct i2c_client *)file->private_data;
207 struct i2c_rdwr_ioctl_data rdwr_arg; 206 struct i2c_rdwr_ioctl_data rdwr_arg;
208 struct i2c_smbus_ioctl_data data_arg;
209 union i2c_smbus_data temp;
210 struct i2c_msg *rdwr_pa; 207 struct i2c_msg *rdwr_pa;
211 u8 __user **data_ptrs; 208 u8 __user **data_ptrs;
212 int i,datasize,res; 209 int i, res;
210
211 if (copy_from_user(&rdwr_arg,
212 (struct i2c_rdwr_ioctl_data __user *)arg,
213 sizeof(rdwr_arg)))
214 return -EFAULT;
215
216 /* Put an arbitrary limit on the number of messages that can
217 * be sent at once */
218 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
219 return -EINVAL;
220
221 rdwr_pa = (struct i2c_msg *)
222 kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg),
223 GFP_KERNEL);
224 if (!rdwr_pa)
225 return -ENOMEM;
226
227 if (copy_from_user(rdwr_pa, rdwr_arg.msgs,
228 rdwr_arg.nmsgs * sizeof(struct i2c_msg))) {
229 kfree(rdwr_pa);
230 return -EFAULT;
231 }
232
233 data_ptrs = kmalloc(rdwr_arg.nmsgs * sizeof(u8 __user *), GFP_KERNEL);
234 if (data_ptrs == NULL) {
235 kfree(rdwr_pa);
236 return -ENOMEM;
237 }
238
239 res = 0;
240 for (i = 0; i < rdwr_arg.nmsgs; i++) {
241 /* Limit the size of the message to a sane amount;
242 * and don't let length change either. */
243 if ((rdwr_pa[i].len > 8192) ||
244 (rdwr_pa[i].flags & I2C_M_RECV_LEN)) {
245 res = -EINVAL;
246 break;
247 }
248 data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
249 rdwr_pa[i].buf = kmalloc(rdwr_pa[i].len, GFP_KERNEL);
250 if (rdwr_pa[i].buf == NULL) {
251 res = -ENOMEM;
252 break;
253 }
254 if (copy_from_user(rdwr_pa[i].buf, data_ptrs[i],
255 rdwr_pa[i].len)) {
256 ++i; /* Needs to be kfreed too */
257 res = -EFAULT;
258 break;
259 }
260 }
261 if (res < 0) {
262 int j;
263 for (j = 0; j < i; ++j)
264 kfree(rdwr_pa[j].buf);
265 kfree(data_ptrs);
266 kfree(rdwr_pa);
267 return res;
268 }
269
270 res = i2c_transfer(client->adapter, rdwr_pa, rdwr_arg.nmsgs);
271 while (i-- > 0) {
272 if (res >= 0 && (rdwr_pa[i].flags & I2C_M_RD)) {
273 if (copy_to_user(data_ptrs[i], rdwr_pa[i].buf,
274 rdwr_pa[i].len))
275 res = -EFAULT;
276 }
277 kfree(rdwr_pa[i].buf);
278 }
279 kfree(data_ptrs);
280 kfree(rdwr_pa);
281 return res;
282}
283
284static noinline int i2cdev_ioctl_smbus(struct i2c_client *client,
285 unsigned long arg)
286{
287 struct i2c_smbus_ioctl_data data_arg;
288 union i2c_smbus_data temp;
289 int datasize, res;
290
291 if (copy_from_user(&data_arg,
292 (struct i2c_smbus_ioctl_data __user *) arg,
293 sizeof(struct i2c_smbus_ioctl_data)))
294 return -EFAULT;
295 if ((data_arg.size != I2C_SMBUS_BYTE) &&
296 (data_arg.size != I2C_SMBUS_QUICK) &&
297 (data_arg.size != I2C_SMBUS_BYTE_DATA) &&
298 (data_arg.size != I2C_SMBUS_WORD_DATA) &&
299 (data_arg.size != I2C_SMBUS_PROC_CALL) &&
300 (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
301 (data_arg.size != I2C_SMBUS_I2C_BLOCK_BROKEN) &&
302 (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&
303 (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {
304 dev_dbg(&client->adapter->dev,
305 "size out of range (%x) in ioctl I2C_SMBUS.\n",
306 data_arg.size);
307 return -EINVAL;
308 }
309 /* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1,
310 so the check is valid if size==I2C_SMBUS_QUICK too. */
311 if ((data_arg.read_write != I2C_SMBUS_READ) &&
312 (data_arg.read_write != I2C_SMBUS_WRITE)) {
313 dev_dbg(&client->adapter->dev,
314 "read_write out of range (%x) in ioctl I2C_SMBUS.\n",
315 data_arg.read_write);
316 return -EINVAL;
317 }
318
319 /* Note that command values are always valid! */
320
321 if ((data_arg.size == I2C_SMBUS_QUICK) ||
322 ((data_arg.size == I2C_SMBUS_BYTE) &&
323 (data_arg.read_write == I2C_SMBUS_WRITE)))
324 /* These are special: we do not use data */
325 return i2c_smbus_xfer(client->adapter, client->addr,
326 client->flags, data_arg.read_write,
327 data_arg.command, data_arg.size, NULL);
328
329 if (data_arg.data == NULL) {
330 dev_dbg(&client->adapter->dev,
331 "data is NULL pointer in ioctl I2C_SMBUS.\n");
332 return -EINVAL;
333 }
334
335 if ((data_arg.size == I2C_SMBUS_BYTE_DATA) ||
336 (data_arg.size == I2C_SMBUS_BYTE))
337 datasize = sizeof(data_arg.data->byte);
338 else if ((data_arg.size == I2C_SMBUS_WORD_DATA) ||
339 (data_arg.size == I2C_SMBUS_PROC_CALL))
340 datasize = sizeof(data_arg.data->word);
341 else /* size == smbus block, i2c block, or block proc. call */
342 datasize = sizeof(data_arg.data->block);
343
344 if ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
345 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
346 (data_arg.size == I2C_SMBUS_I2C_BLOCK_DATA) ||
347 (data_arg.read_write == I2C_SMBUS_WRITE)) {
348 if (copy_from_user(&temp, data_arg.data, datasize))
349 return -EFAULT;
350 }
351 if (data_arg.size == I2C_SMBUS_I2C_BLOCK_BROKEN) {
352 /* Convert old I2C block commands to the new
353 convention. This preserves binary compatibility. */
354 data_arg.size = I2C_SMBUS_I2C_BLOCK_DATA;
355 if (data_arg.read_write == I2C_SMBUS_READ)
356 temp.block[0] = I2C_SMBUS_BLOCK_MAX;
357 }
358 res = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
359 data_arg.read_write, data_arg.command, data_arg.size, &temp);
360 if (!res && ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
361 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
362 (data_arg.read_write == I2C_SMBUS_READ))) {
363 if (copy_to_user(data_arg.data, &temp, datasize))
364 return -EFAULT;
365 }
366 return res;
367}
368
369static int i2cdev_ioctl(struct inode *inode, struct file *file,
370 unsigned int cmd, unsigned long arg)
371{
372 struct i2c_client *client = (struct i2c_client *)file->private_data;
213 unsigned long funcs; 373 unsigned long funcs;
214 374
215 dev_dbg(&client->adapter->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n", 375 dev_dbg(&client->adapter->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n",
@@ -253,164 +413,11 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
253 return put_user(funcs, (unsigned long __user *)arg); 413 return put_user(funcs, (unsigned long __user *)arg);
254 414
255 case I2C_RDWR: 415 case I2C_RDWR:
256 if (copy_from_user(&rdwr_arg, 416 return i2cdev_ioctl_rdrw(client, arg);
257 (struct i2c_rdwr_ioctl_data __user *)arg,
258 sizeof(rdwr_arg)))
259 return -EFAULT;
260
261 /* Put an arbitrary limit on the number of messages that can
262 * be sent at once */
263 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
264 return -EINVAL;
265
266 rdwr_pa = (struct i2c_msg *)
267 kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg),
268 GFP_KERNEL);
269
270 if (rdwr_pa == NULL) return -ENOMEM;
271
272 if (copy_from_user(rdwr_pa, rdwr_arg.msgs,
273 rdwr_arg.nmsgs * sizeof(struct i2c_msg))) {
274 kfree(rdwr_pa);
275 return -EFAULT;
276 }
277
278 data_ptrs = kmalloc(rdwr_arg.nmsgs * sizeof(u8 __user *), GFP_KERNEL);
279 if (data_ptrs == NULL) {
280 kfree(rdwr_pa);
281 return -ENOMEM;
282 }
283
284 res = 0;
285 for( i=0; i<rdwr_arg.nmsgs; i++ ) {
286 /* Limit the size of the message to a sane amount;
287 * and don't let length change either. */
288 if ((rdwr_pa[i].len > 8192) ||
289 (rdwr_pa[i].flags & I2C_M_RECV_LEN)) {
290 res = -EINVAL;
291 break;
292 }
293 data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
294 rdwr_pa[i].buf = kmalloc(rdwr_pa[i].len, GFP_KERNEL);
295 if(rdwr_pa[i].buf == NULL) {
296 res = -ENOMEM;
297 break;
298 }
299 if(copy_from_user(rdwr_pa[i].buf,
300 data_ptrs[i],
301 rdwr_pa[i].len)) {
302 ++i; /* Needs to be kfreed too */
303 res = -EFAULT;
304 break;
305 }
306 }
307 if (res < 0) {
308 int j;
309 for (j = 0; j < i; ++j)
310 kfree(rdwr_pa[j].buf);
311 kfree(data_ptrs);
312 kfree(rdwr_pa);
313 return res;
314 }
315
316 res = i2c_transfer(client->adapter,
317 rdwr_pa,
318 rdwr_arg.nmsgs);
319 while(i-- > 0) {
320 if( res>=0 && (rdwr_pa[i].flags & I2C_M_RD)) {
321 if(copy_to_user(
322 data_ptrs[i],
323 rdwr_pa[i].buf,
324 rdwr_pa[i].len)) {
325 res = -EFAULT;
326 }
327 }
328 kfree(rdwr_pa[i].buf);
329 }
330 kfree(data_ptrs);
331 kfree(rdwr_pa);
332 return res;
333 417
334 case I2C_SMBUS: 418 case I2C_SMBUS:
335 if (copy_from_user(&data_arg, 419 return i2cdev_ioctl_smbus(client, arg);
336 (struct i2c_smbus_ioctl_data __user *) arg,
337 sizeof(struct i2c_smbus_ioctl_data)))
338 return -EFAULT;
339 if ((data_arg.size != I2C_SMBUS_BYTE) &&
340 (data_arg.size != I2C_SMBUS_QUICK) &&
341 (data_arg.size != I2C_SMBUS_BYTE_DATA) &&
342 (data_arg.size != I2C_SMBUS_WORD_DATA) &&
343 (data_arg.size != I2C_SMBUS_PROC_CALL) &&
344 (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
345 (data_arg.size != I2C_SMBUS_I2C_BLOCK_BROKEN) &&
346 (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&
347 (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {
348 dev_dbg(&client->adapter->dev,
349 "size out of range (%x) in ioctl I2C_SMBUS.\n",
350 data_arg.size);
351 return -EINVAL;
352 }
353 /* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1,
354 so the check is valid if size==I2C_SMBUS_QUICK too. */
355 if ((data_arg.read_write != I2C_SMBUS_READ) &&
356 (data_arg.read_write != I2C_SMBUS_WRITE)) {
357 dev_dbg(&client->adapter->dev,
358 "read_write out of range (%x) in ioctl I2C_SMBUS.\n",
359 data_arg.read_write);
360 return -EINVAL;
361 }
362
363 /* Note that command values are always valid! */
364
365 if ((data_arg.size == I2C_SMBUS_QUICK) ||
366 ((data_arg.size == I2C_SMBUS_BYTE) &&
367 (data_arg.read_write == I2C_SMBUS_WRITE)))
368 /* These are special: we do not use data */
369 return i2c_smbus_xfer(client->adapter, client->addr,
370 client->flags,
371 data_arg.read_write,
372 data_arg.command,
373 data_arg.size, NULL);
374
375 if (data_arg.data == NULL) {
376 dev_dbg(&client->adapter->dev,
377 "data is NULL pointer in ioctl I2C_SMBUS.\n");
378 return -EINVAL;
379 }
380 420
381 if ((data_arg.size == I2C_SMBUS_BYTE_DATA) ||
382 (data_arg.size == I2C_SMBUS_BYTE))
383 datasize = sizeof(data_arg.data->byte);
384 else if ((data_arg.size == I2C_SMBUS_WORD_DATA) ||
385 (data_arg.size == I2C_SMBUS_PROC_CALL))
386 datasize = sizeof(data_arg.data->word);
387 else /* size == smbus block, i2c block, or block proc. call */
388 datasize = sizeof(data_arg.data->block);
389
390 if ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
391 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
392 (data_arg.size == I2C_SMBUS_I2C_BLOCK_DATA) ||
393 (data_arg.read_write == I2C_SMBUS_WRITE)) {
394 if (copy_from_user(&temp, data_arg.data, datasize))
395 return -EFAULT;
396 }
397 if (data_arg.size == I2C_SMBUS_I2C_BLOCK_BROKEN) {
398 /* Convert old I2C block commands to the new
399 convention. This preserves binary compatibility. */
400 data_arg.size = I2C_SMBUS_I2C_BLOCK_DATA;
401 if (data_arg.read_write == I2C_SMBUS_READ)
402 temp.block[0] = I2C_SMBUS_BLOCK_MAX;
403 }
404 res = i2c_smbus_xfer(client->adapter,client->addr,client->flags,
405 data_arg.read_write,
406 data_arg.command,data_arg.size,&temp);
407 if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
408 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
409 (data_arg.read_write == I2C_SMBUS_READ))) {
410 if (copy_to_user(data_arg.data, &temp, datasize))
411 return -EFAULT;
412 }
413 return res;
414 case I2C_RETRIES: 421 case I2C_RETRIES:
415 client->adapter->retries = arg; 422 client->adapter->retries = arg;
416 break; 423 break;
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index c5263d63aca3..92b683411d5a 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -15,6 +15,7 @@ if INPUT_MISC
15config INPUT_PCSPKR 15config INPUT_PCSPKR
16 tristate "PC Speaker support" 16 tristate "PC Speaker support"
17 depends on ALPHA || X86 || MIPS || PPC_PREP || PPC_CHRP || PPC_PSERIES 17 depends on ALPHA || X86 || MIPS || PPC_PREP || PPC_CHRP || PPC_PSERIES
18 depends on SND_PCSP=n
18 help 19 help
19 Say Y here if you want the standard PC Speaker to be used for 20 Say Y here if you want the standard PC Speaker to be used for
20 bells and whistles. 21 bells and whistles.
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index a3a6199639f9..eb97c4113d78 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -1,6 +1,5 @@
1menuconfig NEW_LEDS 1menuconfig NEW_LEDS
2 bool "LED Support" 2 bool "LED Support"
3 depends on HAS_IOMEM
4 help 3 help
5 Say Y to enable Linux LED support. This allows control of supported 4 Say Y to enable Linux LED support. This allows control of supported
6 LEDs from both userspace and optionally, by kernel events (triggers). 5 LEDs from both userspace and optionally, by kernel events (triggers).
diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
index 316b106c3511..03feb5b49e1b 100644
--- a/drivers/media/video/cx88/cx88-alsa.c
+++ b/drivers/media/video/cx88/cx88-alsa.c
@@ -690,10 +690,8 @@ MODULE_DEVICE_TABLE(pci, cx88_audio_pci_tbl);
690static int snd_cx88_free(snd_cx88_card_t *chip) 690static int snd_cx88_free(snd_cx88_card_t *chip)
691{ 691{
692 692
693 if (chip->irq >= 0){ 693 if (chip->irq >= 0)
694 synchronize_irq(chip->irq);
695 free_irq(chip->irq, chip); 694 free_irq(chip->irq, chip);
696 }
697 695
698 cx88_core_put(chip->core,chip->pci); 696 cx88_core_put(chip->core,chip->pci);
699 697
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index 047add8f3010..ec6bdb9680a3 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -954,10 +954,8 @@ static void snd_saa7134_free(struct snd_card * card)
954 if (chip->dev->dmasound.priv_data == NULL) 954 if (chip->dev->dmasound.priv_data == NULL)
955 return; 955 return;
956 956
957 if (chip->irq >= 0) { 957 if (chip->irq >= 0)
958 synchronize_irq(chip->irq);
959 free_irq(chip->irq, &chip->dev->dmasound); 958 free_irq(chip->irq, &chip->dev->dmasound);
960 }
961 959
962 chip->dev->dmasound.priv_data = NULL; 960 chip->dev->dmasound.priv_data = NULL;
963 961
diff --git a/drivers/mfd/htc-pasic3.c b/drivers/mfd/htc-pasic3.c
index af66f4f28300..4edc120a6359 100644
--- a/drivers/mfd/htc-pasic3.c
+++ b/drivers/mfd/htc-pasic3.c
@@ -19,8 +19,6 @@
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/mfd/htc-pasic3.h> 20#include <linux/mfd/htc-pasic3.h>
21 21
22#include <asm/arch/pxa-regs.h>
23
24struct pasic3_data { 22struct pasic3_data {
25 void __iomem *mapping; 23 void __iomem *mapping;
26 unsigned int bus_shift; 24 unsigned int bus_shift;
@@ -30,7 +28,6 @@ struct pasic3_data {
30 28
31#define REG_ADDR 5 29#define REG_ADDR 5
32#define REG_DATA 6 30#define REG_DATA 6
33#define NUM_REGS 7
34 31
35#define READ_MODE 0x80 32#define READ_MODE 0x80
36 33
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index bb94ce78a6d0..297a48f85446 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -360,4 +360,16 @@ config ENCLOSURE_SERVICES
360 driver (SCSI/ATA) which supports enclosures 360 driver (SCSI/ATA) which supports enclosures
361 or a SCSI enclosure device (SES) to use these services. 361 or a SCSI enclosure device (SES) to use these services.
362 362
363config SGI_XP
364 tristate "Support communication between SGI SSIs"
365 depends on IA64_GENERIC || IA64_SGI_SN2
366 select IA64_UNCACHED_ALLOCATOR if IA64_GENERIC || IA64_SGI_SN2
367 select GENERIC_ALLOCATOR if IA64_GENERIC || IA64_SGI_SN2
368 ---help---
369 An SGI machine can be divided into multiple Single System
370 Images which act independently of each other and have
371 hardware based memory protection from the others. Enabling
372 this feature will allow for direct communication between SSIs
373 based on a network adapter and DMA messaging.
374
363endif # MISC_DEVICES 375endif # MISC_DEVICES
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 4581b2533111..5914da434854 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -24,3 +24,4 @@ obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o
24obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o 24obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
25obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o 25obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
26obj-$(CONFIG_KGDB_TESTS) += kgdbts.o 26obj-$(CONFIG_KGDB_TESTS) += kgdbts.o
27obj-$(CONFIG_SGI_XP) += sgi-xp/
diff --git a/drivers/misc/sgi-xp/Makefile b/drivers/misc/sgi-xp/Makefile
new file mode 100644
index 000000000000..b6e40a7958ce
--- /dev/null
+++ b/drivers/misc/sgi-xp/Makefile
@@ -0,0 +1,11 @@
1#
2# Makefile for SGI's XP devices.
3#
4
5obj-$(CONFIG_SGI_XP) += xp.o
6xp-y := xp_main.o xp_nofault.o
7
8obj-$(CONFIG_SGI_XP) += xpc.o
9xpc-y := xpc_main.o xpc_channel.o xpc_partition.o
10
11obj-$(CONFIG_SGI_XP) += xpnet.o
diff --git a/include/asm-ia64/sn/xp.h b/drivers/misc/sgi-xp/xp.h
index f7711b308e48..5515234be86a 100644
--- a/include/asm-ia64/sn/xp.h
+++ b/drivers/misc/sgi-xp/xp.h
@@ -3,18 +3,15 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (C) 2004-2005 Silicon Graphics, Inc. All rights reserved. 6 * Copyright (C) 2004-2008 Silicon Graphics, Inc. All rights reserved.
7 */ 7 */
8 8
9
10/* 9/*
11 * External Cross Partition (XP) structures and defines. 10 * External Cross Partition (XP) structures and defines.
12 */ 11 */
13 12
14 13#ifndef _DRIVERS_MISC_SGIXP_XP_H
15#ifndef _ASM_IA64_SN_XP_H 14#define _DRIVERS_MISC_SGIXP_XP_H
16#define _ASM_IA64_SN_XP_H
17
18 15
19#include <linux/cache.h> 16#include <linux/cache.h>
20#include <linux/hardirq.h> 17#include <linux/hardirq.h>
@@ -22,14 +19,12 @@
22#include <asm/sn/types.h> 19#include <asm/sn/types.h>
23#include <asm/sn/bte.h> 20#include <asm/sn/bte.h>
24 21
25
26#ifdef USE_DBUG_ON 22#ifdef USE_DBUG_ON
27#define DBUG_ON(condition) BUG_ON(condition) 23#define DBUG_ON(condition) BUG_ON(condition)
28#else 24#else
29#define DBUG_ON(condition) 25#define DBUG_ON(condition)
30#endif 26#endif
31 27
32
33/* 28/*
34 * Define the maximum number of logically defined partitions the system 29 * Define the maximum number of logically defined partitions the system
35 * can support. It is constrained by the maximum number of hardware 30 * can support. It is constrained by the maximum number of hardware
@@ -43,7 +38,6 @@
43 */ 38 */
44#define XP_MAX_PARTITIONS 64 39#define XP_MAX_PARTITIONS 64
45 40
46
47/* 41/*
48 * Define the number of u64s required to represent all the C-brick nasids 42 * Define the number of u64s required to represent all the C-brick nasids
49 * as a bitmap. The cross-partition kernel modules deal only with 43 * as a bitmap. The cross-partition kernel modules deal only with
@@ -54,7 +48,6 @@
54#define XP_NASID_MASK_BYTES ((XP_MAX_PHYSNODE_ID + 7) / 8) 48#define XP_NASID_MASK_BYTES ((XP_MAX_PHYSNODE_ID + 7) / 8)
55#define XP_NASID_MASK_WORDS ((XP_MAX_PHYSNODE_ID + 63) / 64) 49#define XP_NASID_MASK_WORDS ((XP_MAX_PHYSNODE_ID + 63) / 64)
56 50
57
58/* 51/*
59 * Wrapper for bte_copy() that should it return a failure status will retry 52 * Wrapper for bte_copy() that should it return a failure status will retry
60 * the bte_copy() once in the hope that the failure was due to a temporary 53 * the bte_copy() once in the hope that the failure was due to a temporary
@@ -74,7 +67,6 @@ xp_bte_copy(u64 src, u64 vdst, u64 len, u64 mode, void *notification)
74 bte_result_t ret; 67 bte_result_t ret;
75 u64 pdst = ia64_tpa(vdst); 68 u64 pdst = ia64_tpa(vdst);
76 69
77
78 /* 70 /*
79 * Ensure that the physically mapped memory is contiguous. 71 * Ensure that the physically mapped memory is contiguous.
80 * 72 *
@@ -87,16 +79,15 @@ xp_bte_copy(u64 src, u64 vdst, u64 len, u64 mode, void *notification)
87 79
88 ret = bte_copy(src, pdst, len, mode, notification); 80 ret = bte_copy(src, pdst, len, mode, notification);
89 if ((ret != BTE_SUCCESS) && BTE_ERROR_RETRY(ret)) { 81 if ((ret != BTE_SUCCESS) && BTE_ERROR_RETRY(ret)) {
90 if (!in_interrupt()) { 82 if (!in_interrupt())
91 cond_resched(); 83 cond_resched();
92 } 84
93 ret = bte_copy(src, pdst, len, mode, notification); 85 ret = bte_copy(src, pdst, len, mode, notification);
94 } 86 }
95 87
96 return ret; 88 return ret;
97} 89}
98 90
99
100/* 91/*
101 * XPC establishes channel connections between the local partition and any 92 * XPC establishes channel connections between the local partition and any
102 * other partition that is currently up. Over these channels, kernel-level 93 * other partition that is currently up. Over these channels, kernel-level
@@ -122,7 +113,6 @@ xp_bte_copy(u64 src, u64 vdst, u64 len, u64 mode, void *notification)
122#error XPC_NCHANNELS exceeds MAXIMUM allowed. 113#error XPC_NCHANNELS exceeds MAXIMUM allowed.
123#endif 114#endif
124 115
125
126/* 116/*
127 * The format of an XPC message is as follows: 117 * The format of an XPC message is as follows:
128 * 118 *
@@ -160,12 +150,10 @@ struct xpc_msg {
160 u64 payload; /* user defined portion of message */ 150 u64 payload; /* user defined portion of message */
161}; 151};
162 152
163
164#define XPC_MSG_PAYLOAD_OFFSET (u64) (&((struct xpc_msg *)0)->payload) 153#define XPC_MSG_PAYLOAD_OFFSET (u64) (&((struct xpc_msg *)0)->payload)
165#define XPC_MSG_SIZE(_payload_size) \ 154#define XPC_MSG_SIZE(_payload_size) \
166 L1_CACHE_ALIGN(XPC_MSG_PAYLOAD_OFFSET + (_payload_size)) 155 L1_CACHE_ALIGN(XPC_MSG_PAYLOAD_OFFSET + (_payload_size))
167 156
168
169/* 157/*
170 * Define the return values and values passed to user's callout functions. 158 * Define the return values and values passed to user's callout functions.
171 * (It is important to add new value codes at the end just preceding 159 * (It is important to add new value codes at the end just preceding
@@ -267,10 +255,9 @@ enum xpc_retval {
267 /* 115: BTE end */ 255 /* 115: BTE end */
268 xpcBteSh2End = xpcBteSh2Start + BTEFAIL_SH2_ALL, 256 xpcBteSh2End = xpcBteSh2Start + BTEFAIL_SH2_ALL,
269 257
270 xpcUnknownReason /* 116: unknown reason -- must be last in list */ 258 xpcUnknownReason /* 116: unknown reason - must be last in enum */
271}; 259};
272 260
273
274/* 261/*
275 * Define the callout function types used by XPC to update the user on 262 * Define the callout function types used by XPC to update the user on
276 * connection activity and state changes (via the user function registered by 263 * connection activity and state changes (via the user function registered by
@@ -375,12 +362,11 @@ enum xpc_retval {
375 * =====================+================================+===================== 362 * =====================+================================+=====================
376 */ 363 */
377 364
378typedef void (*xpc_channel_func)(enum xpc_retval reason, partid_t partid, 365typedef void (*xpc_channel_func) (enum xpc_retval reason, partid_t partid,
379 int ch_number, void *data, void *key); 366 int ch_number, void *data, void *key);
380
381typedef void (*xpc_notify_func)(enum xpc_retval reason, partid_t partid,
382 int ch_number, void *key);
383 367
368typedef void (*xpc_notify_func) (enum xpc_retval reason, partid_t partid,
369 int ch_number, void *key);
384 370
385/* 371/*
386 * The following is a registration entry. There is a global array of these, 372 * The following is a registration entry. There is a global array of these,
@@ -398,50 +384,45 @@ typedef void (*xpc_notify_func)(enum xpc_retval reason, partid_t partid,
398 */ 384 */
399struct xpc_registration { 385struct xpc_registration {
400 struct mutex mutex; 386 struct mutex mutex;
401 xpc_channel_func func; /* function to call */ 387 xpc_channel_func func; /* function to call */
402 void *key; /* pointer to user's key */ 388 void *key; /* pointer to user's key */
403 u16 nentries; /* #of msg entries in local msg queue */ 389 u16 nentries; /* #of msg entries in local msg queue */
404 u16 msg_size; /* message queue's message size */ 390 u16 msg_size; /* message queue's message size */
405 u32 assigned_limit; /* limit on #of assigned kthreads */ 391 u32 assigned_limit; /* limit on #of assigned kthreads */
406 u32 idle_limit; /* limit on #of idle kthreads */ 392 u32 idle_limit; /* limit on #of idle kthreads */
407} ____cacheline_aligned; 393} ____cacheline_aligned;
408 394
409
410#define XPC_CHANNEL_REGISTERED(_c) (xpc_registrations[_c].func != NULL) 395#define XPC_CHANNEL_REGISTERED(_c) (xpc_registrations[_c].func != NULL)
411 396
412
413/* the following are valid xpc_allocate() flags */ 397/* the following are valid xpc_allocate() flags */
414#define XPC_WAIT 0 /* wait flag */ 398#define XPC_WAIT 0 /* wait flag */
415#define XPC_NOWAIT 1 /* no wait flag */ 399#define XPC_NOWAIT 1 /* no wait flag */
416
417 400
418struct xpc_interface { 401struct xpc_interface {
419 void (*connect)(int); 402 void (*connect) (int);
420 void (*disconnect)(int); 403 void (*disconnect) (int);
421 enum xpc_retval (*allocate)(partid_t, int, u32, void **); 404 enum xpc_retval (*allocate) (partid_t, int, u32, void **);
422 enum xpc_retval (*send)(partid_t, int, void *); 405 enum xpc_retval (*send) (partid_t, int, void *);
423 enum xpc_retval (*send_notify)(partid_t, int, void *, 406 enum xpc_retval (*send_notify) (partid_t, int, void *,
424 xpc_notify_func, void *); 407 xpc_notify_func, void *);
425 void (*received)(partid_t, int, void *); 408 void (*received) (partid_t, int, void *);
426 enum xpc_retval (*partid_to_nasids)(partid_t, void *); 409 enum xpc_retval (*partid_to_nasids) (partid_t, void *);
427}; 410};
428 411
429
430extern struct xpc_interface xpc_interface; 412extern struct xpc_interface xpc_interface;
431 413
432extern void xpc_set_interface(void (*)(int), 414extern void xpc_set_interface(void (*)(int),
433 void (*)(int), 415 void (*)(int),
434 enum xpc_retval (*)(partid_t, int, u32, void **), 416 enum xpc_retval (*)(partid_t, int, u32, void **),
435 enum xpc_retval (*)(partid_t, int, void *), 417 enum xpc_retval (*)(partid_t, int, void *),
436 enum xpc_retval (*)(partid_t, int, void *, xpc_notify_func, 418 enum xpc_retval (*)(partid_t, int, void *,
437 void *), 419 xpc_notify_func, void *),
438 void (*)(partid_t, int, void *), 420 void (*)(partid_t, int, void *),
439 enum xpc_retval (*)(partid_t, void *)); 421 enum xpc_retval (*)(partid_t, void *));
440extern void xpc_clear_interface(void); 422extern void xpc_clear_interface(void);
441 423
442
443extern enum xpc_retval xpc_connect(int, xpc_channel_func, void *, u16, 424extern enum xpc_retval xpc_connect(int, xpc_channel_func, void *, u16,
444 u16, u32, u32); 425 u16, u32, u32);
445extern void xpc_disconnect(int); 426extern void xpc_disconnect(int);
446 427
447static inline enum xpc_retval 428static inline enum xpc_retval
@@ -458,7 +439,7 @@ xpc_send(partid_t partid, int ch_number, void *payload)
458 439
459static inline enum xpc_retval 440static inline enum xpc_retval
460xpc_send_notify(partid_t partid, int ch_number, void *payload, 441xpc_send_notify(partid_t partid, int ch_number, void *payload,
461 xpc_notify_func func, void *key) 442 xpc_notify_func func, void *key)
462{ 443{
463 return xpc_interface.send_notify(partid, ch_number, payload, func, key); 444 return xpc_interface.send_notify(partid, ch_number, payload, func, key);
464} 445}
@@ -475,11 +456,8 @@ xpc_partid_to_nasids(partid_t partid, void *nasids)
475 return xpc_interface.partid_to_nasids(partid, nasids); 456 return xpc_interface.partid_to_nasids(partid, nasids);
476} 457}
477 458
478
479extern u64 xp_nofault_PIOR_target; 459extern u64 xp_nofault_PIOR_target;
480extern int xp_nofault_PIOR(void *); 460extern int xp_nofault_PIOR(void *);
481extern int xp_error_PIOR(void); 461extern int xp_error_PIOR(void);
482 462
483 463#endif /* _DRIVERS_MISC_SGIXP_XP_H */
484#endif /* _ASM_IA64_SN_XP_H */
485
diff --git a/arch/ia64/sn/kernel/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
index b7ea46645e12..1fbf99bae963 100644
--- a/arch/ia64/sn/kernel/xp_main.c
+++ b/drivers/misc/sgi-xp/xp_main.c
@@ -3,10 +3,9 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved. 6 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
7 */ 7 */
8 8
9
10/* 9/*
11 * Cross Partition (XP) base. 10 * Cross Partition (XP) base.
12 * 11 *
@@ -15,58 +14,64 @@
15 * 14 *
16 */ 15 */
17 16
18
19#include <linux/kernel.h> 17#include <linux/kernel.h>
20#include <linux/interrupt.h> 18#include <linux/interrupt.h>
21#include <linux/module.h> 19#include <linux/module.h>
22#include <linux/mutex.h> 20#include <linux/mutex.h>
23#include <asm/sn/intr.h> 21#include <asm/sn/intr.h>
24#include <asm/sn/sn_sal.h> 22#include <asm/sn/sn_sal.h>
25#include <asm/sn/xp.h> 23#include "xp.h"
26
27 24
28/* 25/*
29 * Target of nofault PIO read. 26 * The export of xp_nofault_PIOR needs to happen here since it is defined
27 * in drivers/misc/sgi-xp/xp_nofault.S. The target of the nofault read is
28 * defined here.
30 */ 29 */
31u64 xp_nofault_PIOR_target; 30EXPORT_SYMBOL_GPL(xp_nofault_PIOR);
32 31
32u64 xp_nofault_PIOR_target;
33EXPORT_SYMBOL_GPL(xp_nofault_PIOR_target);
33 34
34/* 35/*
35 * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level 36 * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level
36 * users of XPC. 37 * users of XPC.
37 */ 38 */
38struct xpc_registration xpc_registrations[XPC_NCHANNELS]; 39struct xpc_registration xpc_registrations[XPC_NCHANNELS];
39 40EXPORT_SYMBOL_GPL(xpc_registrations);
40 41
41/* 42/*
42 * Initialize the XPC interface to indicate that XPC isn't loaded. 43 * Initialize the XPC interface to indicate that XPC isn't loaded.
43 */ 44 */
44static enum xpc_retval xpc_notloaded(void) { return xpcNotLoaded; } 45static enum xpc_retval
46xpc_notloaded(void)
47{
48 return xpcNotLoaded;
49}
45 50
46struct xpc_interface xpc_interface = { 51struct xpc_interface xpc_interface = {
47 (void (*)(int)) xpc_notloaded, 52 (void (*)(int))xpc_notloaded,
48 (void (*)(int)) xpc_notloaded, 53 (void (*)(int))xpc_notloaded,
49 (enum xpc_retval (*)(partid_t, int, u32, void **)) xpc_notloaded, 54 (enum xpc_retval(*)(partid_t, int, u32, void **))xpc_notloaded,
50 (enum xpc_retval (*)(partid_t, int, void *)) xpc_notloaded, 55 (enum xpc_retval(*)(partid_t, int, void *))xpc_notloaded,
51 (enum xpc_retval (*)(partid_t, int, void *, xpc_notify_func, void *)) 56 (enum xpc_retval(*)(partid_t, int, void *, xpc_notify_func, void *))
52 xpc_notloaded, 57 xpc_notloaded,
53 (void (*)(partid_t, int, void *)) xpc_notloaded, 58 (void (*)(partid_t, int, void *))xpc_notloaded,
54 (enum xpc_retval (*)(partid_t, void *)) xpc_notloaded 59 (enum xpc_retval(*)(partid_t, void *))xpc_notloaded
55}; 60};
56 61EXPORT_SYMBOL_GPL(xpc_interface);
57 62
58/* 63/*
59 * XPC calls this when it (the XPC module) has been loaded. 64 * XPC calls this when it (the XPC module) has been loaded.
60 */ 65 */
61void 66void
62xpc_set_interface(void (*connect)(int), 67xpc_set_interface(void (*connect) (int),
63 void (*disconnect)(int), 68 void (*disconnect) (int),
64 enum xpc_retval (*allocate)(partid_t, int, u32, void **), 69 enum xpc_retval (*allocate) (partid_t, int, u32, void **),
65 enum xpc_retval (*send)(partid_t, int, void *), 70 enum xpc_retval (*send) (partid_t, int, void *),
66 enum xpc_retval (*send_notify)(partid_t, int, void *, 71 enum xpc_retval (*send_notify) (partid_t, int, void *,
67 xpc_notify_func, void *), 72 xpc_notify_func, void *),
68 void (*received)(partid_t, int, void *), 73 void (*received) (partid_t, int, void *),
69 enum xpc_retval (*partid_to_nasids)(partid_t, void *)) 74 enum xpc_retval (*partid_to_nasids) (partid_t, void *))
70{ 75{
71 xpc_interface.connect = connect; 76 xpc_interface.connect = connect;
72 xpc_interface.disconnect = disconnect; 77 xpc_interface.disconnect = disconnect;
@@ -76,7 +81,7 @@ xpc_set_interface(void (*connect)(int),
76 xpc_interface.received = received; 81 xpc_interface.received = received;
77 xpc_interface.partid_to_nasids = partid_to_nasids; 82 xpc_interface.partid_to_nasids = partid_to_nasids;
78} 83}
79 84EXPORT_SYMBOL_GPL(xpc_set_interface);
80 85
81/* 86/*
82 * XPC calls this when it (the XPC module) is being unloaded. 87 * XPC calls this when it (the XPC module) is being unloaded.
@@ -84,20 +89,21 @@ xpc_set_interface(void (*connect)(int),
84void 89void
85xpc_clear_interface(void) 90xpc_clear_interface(void)
86{ 91{
87 xpc_interface.connect = (void (*)(int)) xpc_notloaded; 92 xpc_interface.connect = (void (*)(int))xpc_notloaded;
88 xpc_interface.disconnect = (void (*)(int)) xpc_notloaded; 93 xpc_interface.disconnect = (void (*)(int))xpc_notloaded;
89 xpc_interface.allocate = (enum xpc_retval (*)(partid_t, int, u32, 94 xpc_interface.allocate = (enum xpc_retval(*)(partid_t, int, u32,
90 void **)) xpc_notloaded; 95 void **))xpc_notloaded;
91 xpc_interface.send = (enum xpc_retval (*)(partid_t, int, void *)) 96 xpc_interface.send = (enum xpc_retval(*)(partid_t, int, void *))
92 xpc_notloaded; 97 xpc_notloaded;
93 xpc_interface.send_notify = (enum xpc_retval (*)(partid_t, int, void *, 98 xpc_interface.send_notify = (enum xpc_retval(*)(partid_t, int, void *,
94 xpc_notify_func, void *)) xpc_notloaded; 99 xpc_notify_func,
100 void *))xpc_notloaded;
95 xpc_interface.received = (void (*)(partid_t, int, void *)) 101 xpc_interface.received = (void (*)(partid_t, int, void *))
96 xpc_notloaded; 102 xpc_notloaded;
97 xpc_interface.partid_to_nasids = (enum xpc_retval (*)(partid_t, void *)) 103 xpc_interface.partid_to_nasids = (enum xpc_retval(*)(partid_t, void *))
98 xpc_notloaded; 104 xpc_notloaded;
99} 105}
100 106EXPORT_SYMBOL_GPL(xpc_clear_interface);
101 107
102/* 108/*
103 * Register for automatic establishment of a channel connection whenever 109 * Register for automatic establishment of a channel connection whenever
@@ -125,11 +131,10 @@ xpc_clear_interface(void)
125 */ 131 */
126enum xpc_retval 132enum xpc_retval
127xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size, 133xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
128 u16 nentries, u32 assigned_limit, u32 idle_limit) 134 u16 nentries, u32 assigned_limit, u32 idle_limit)
129{ 135{
130 struct xpc_registration *registration; 136 struct xpc_registration *registration;
131 137
132
133 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS); 138 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS);
134 DBUG_ON(payload_size == 0 || nentries == 0); 139 DBUG_ON(payload_size == 0 || nentries == 0);
135 DBUG_ON(func == NULL); 140 DBUG_ON(func == NULL);
@@ -137,9 +142,8 @@ xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
137 142
138 registration = &xpc_registrations[ch_number]; 143 registration = &xpc_registrations[ch_number];
139 144
140 if (mutex_lock_interruptible(&registration->mutex) != 0) { 145 if (mutex_lock_interruptible(&registration->mutex) != 0)
141 return xpcInterrupted; 146 return xpcInterrupted;
142 }
143 147
144 /* if XPC_CHANNEL_REGISTERED(ch_number) */ 148 /* if XPC_CHANNEL_REGISTERED(ch_number) */
145 if (registration->func != NULL) { 149 if (registration->func != NULL) {
@@ -161,7 +165,7 @@ xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
161 165
162 return xpcSuccess; 166 return xpcSuccess;
163} 167}
164 168EXPORT_SYMBOL_GPL(xpc_connect);
165 169
166/* 170/*
167 * Remove the registration for automatic connection of the specified channel 171 * Remove the registration for automatic connection of the specified channel
@@ -181,7 +185,6 @@ xpc_disconnect(int ch_number)
181{ 185{
182 struct xpc_registration *registration; 186 struct xpc_registration *registration;
183 187
184
185 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS); 188 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS);
186 189
187 registration = &xpc_registrations[ch_number]; 190 registration = &xpc_registrations[ch_number];
@@ -213,19 +216,17 @@ xpc_disconnect(int ch_number)
213 216
214 return; 217 return;
215} 218}
216 219EXPORT_SYMBOL_GPL(xpc_disconnect);
217 220
218int __init 221int __init
219xp_init(void) 222xp_init(void)
220{ 223{
221 int ret, ch_number; 224 int ret, ch_number;
222 u64 func_addr = *(u64 *) xp_nofault_PIOR; 225 u64 func_addr = *(u64 *)xp_nofault_PIOR;
223 u64 err_func_addr = *(u64 *) xp_error_PIOR; 226 u64 err_func_addr = *(u64 *)xp_error_PIOR;
224 227
225 228 if (!ia64_platform_is("sn2"))
226 if (!ia64_platform_is("sn2")) {
227 return -ENODEV; 229 return -ENODEV;
228 }
229 230
230 /* 231 /*
231 * Register a nofault code region which performs a cross-partition 232 * Register a nofault code region which performs a cross-partition
@@ -236,55 +237,43 @@ xp_init(void)
236 * least some CPUs on Shubs <= v1.2, which unfortunately we have to 237 * least some CPUs on Shubs <= v1.2, which unfortunately we have to
237 * work around). 238 * work around).
238 */ 239 */
239 if ((ret = sn_register_nofault_code(func_addr, err_func_addr, 240 ret = sn_register_nofault_code(func_addr, err_func_addr, err_func_addr,
240 err_func_addr, 1, 1)) != 0) { 241 1, 1);
242 if (ret != 0) {
241 printk(KERN_ERR "XP: can't register nofault code, error=%d\n", 243 printk(KERN_ERR "XP: can't register nofault code, error=%d\n",
242 ret); 244 ret);
243 } 245 }
244 /* 246 /*
245 * Setup the nofault PIO read target. (There is no special reason why 247 * Setup the nofault PIO read target. (There is no special reason why
246 * SH_IPI_ACCESS was selected.) 248 * SH_IPI_ACCESS was selected.)
247 */ 249 */
248 if (is_shub2()) { 250 if (is_shub2())
249 xp_nofault_PIOR_target = SH2_IPI_ACCESS0; 251 xp_nofault_PIOR_target = SH2_IPI_ACCESS0;
250 } else { 252 else
251 xp_nofault_PIOR_target = SH1_IPI_ACCESS; 253 xp_nofault_PIOR_target = SH1_IPI_ACCESS;
252 }
253 254
254 /* initialize the connection registration mutex */ 255 /* initialize the connection registration mutex */
255 for (ch_number = 0; ch_number < XPC_NCHANNELS; ch_number++) { 256 for (ch_number = 0; ch_number < XPC_NCHANNELS; ch_number++)
256 mutex_init(&xpc_registrations[ch_number].mutex); 257 mutex_init(&xpc_registrations[ch_number].mutex);
257 }
258 258
259 return 0; 259 return 0;
260} 260}
261module_init(xp_init);
262 261
262module_init(xp_init);
263 263
264void __exit 264void __exit
265xp_exit(void) 265xp_exit(void)
266{ 266{
267 u64 func_addr = *(u64 *) xp_nofault_PIOR; 267 u64 func_addr = *(u64 *)xp_nofault_PIOR;
268 u64 err_func_addr = *(u64 *) xp_error_PIOR; 268 u64 err_func_addr = *(u64 *)xp_error_PIOR;
269
270 269
271 /* unregister the PIO read nofault code region */ 270 /* unregister the PIO read nofault code region */
272 (void) sn_register_nofault_code(func_addr, err_func_addr, 271 (void)sn_register_nofault_code(func_addr, err_func_addr,
273 err_func_addr, 1, 0); 272 err_func_addr, 1, 0);
274} 273}
275module_exit(xp_exit);
276 274
275module_exit(xp_exit);
277 276
278MODULE_AUTHOR("Silicon Graphics, Inc."); 277MODULE_AUTHOR("Silicon Graphics, Inc.");
279MODULE_DESCRIPTION("Cross Partition (XP) base"); 278MODULE_DESCRIPTION("Cross Partition (XP) base");
280MODULE_LICENSE("GPL"); 279MODULE_LICENSE("GPL");
281
282EXPORT_SYMBOL(xp_nofault_PIOR);
283EXPORT_SYMBOL(xp_nofault_PIOR_target);
284EXPORT_SYMBOL(xpc_registrations);
285EXPORT_SYMBOL(xpc_interface);
286EXPORT_SYMBOL(xpc_clear_interface);
287EXPORT_SYMBOL(xpc_set_interface);
288EXPORT_SYMBOL(xpc_connect);
289EXPORT_SYMBOL(xpc_disconnect);
290
diff --git a/arch/ia64/sn/kernel/xp_nofault.S b/drivers/misc/sgi-xp/xp_nofault.S
index 98e7c7dbfdd8..e38d43319429 100644
--- a/arch/ia64/sn/kernel/xp_nofault.S
+++ b/drivers/misc/sgi-xp/xp_nofault.S
@@ -3,10 +3,9 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (c) 2004-2007 Silicon Graphics, Inc. All Rights Reserved. 6 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
7 */ 7 */
8 8
9
10/* 9/*
11 * The xp_nofault_PIOR function takes a pointer to a remote PIO register 10 * The xp_nofault_PIOR function takes a pointer to a remote PIO register
12 * and attempts to load and consume a value from it. This function 11 * and attempts to load and consume a value from it. This function
diff --git a/include/asm-ia64/sn/xpc.h b/drivers/misc/sgi-xp/xpc.h
index 3c0900ab8003..9eb6d4a3269c 100644
--- a/include/asm-ia64/sn/xpc.h
+++ b/drivers/misc/sgi-xp/xpc.h
@@ -3,17 +3,15 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (c) 2004-2007 Silicon Graphics, Inc. All Rights Reserved. 6 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
7 */ 7 */
8 8
9
10/* 9/*
11 * Cross Partition Communication (XPC) structures and macros. 10 * Cross Partition Communication (XPC) structures and macros.
12 */ 11 */
13 12
14#ifndef _ASM_IA64_SN_XPC_H 13#ifndef _DRIVERS_MISC_SGIXP_XPC_H
15#define _ASM_IA64_SN_XPC_H 14#define _DRIVERS_MISC_SGIXP_XPC_H
16
17 15
18#include <linux/interrupt.h> 16#include <linux/interrupt.h>
19#include <linux/sysctl.h> 17#include <linux/sysctl.h>
@@ -27,8 +25,7 @@
27#include <asm/sn/addrs.h> 25#include <asm/sn/addrs.h>
28#include <asm/sn/mspec.h> 26#include <asm/sn/mspec.h>
29#include <asm/sn/shub_mmr.h> 27#include <asm/sn/shub_mmr.h>
30#include <asm/sn/xp.h> 28#include "xp.h"
31
32 29
33/* 30/*
34 * XPC Version numbers consist of a major and minor number. XPC can always 31 * XPC Version numbers consist of a major and minor number. XPC can always
@@ -39,7 +36,6 @@
39#define XPC_VERSION_MAJOR(_v) ((_v) >> 4) 36#define XPC_VERSION_MAJOR(_v) ((_v) >> 4)
40#define XPC_VERSION_MINOR(_v) ((_v) & 0xf) 37#define XPC_VERSION_MINOR(_v) ((_v) & 0xf)
41 38
42
43/* 39/*
44 * The next macros define word or bit representations for given 40 * The next macros define word or bit representations for given
45 * C-brick nasid in either the SAL provided bit array representing 41 * C-brick nasid in either the SAL provided bit array representing
@@ -67,7 +63,6 @@
67/* define the process name of the discovery thread */ 63/* define the process name of the discovery thread */
68#define XPC_DISCOVERY_THREAD_NAME "xpc_discovery" 64#define XPC_DISCOVERY_THREAD_NAME "xpc_discovery"
69 65
70
71/* 66/*
72 * the reserved page 67 * the reserved page
73 * 68 *
@@ -115,16 +110,16 @@ struct xpc_rsvd_page {
115 u8 partid; /* SAL: partition ID */ 110 u8 partid; /* SAL: partition ID */
116 u8 version; 111 u8 version;
117 u8 pad1[6]; /* align to next u64 in cacheline */ 112 u8 pad1[6]; /* align to next u64 in cacheline */
118 volatile u64 vars_pa; 113 u64 vars_pa; /* physical address of struct xpc_vars */
119 struct timespec stamp; /* time when reserved page was setup by XPC */ 114 struct timespec stamp; /* time when reserved page was setup by XPC */
120 u64 pad2[9]; /* align to last u64 in cacheline */ 115 u64 pad2[9]; /* align to last u64 in cacheline */
121 u64 nasids_size; /* SAL: size of each nasid mask in bytes */ 116 u64 nasids_size; /* SAL: size of each nasid mask in bytes */
122}; 117};
123 118
124#define XPC_RP_VERSION _XPC_VERSION(1,1) /* version 1.1 of the reserved page */ 119#define XPC_RP_VERSION _XPC_VERSION(1, 1) /* version 1.1 of the reserved page */
125 120
126#define XPC_SUPPORTS_RP_STAMP(_version) \ 121#define XPC_SUPPORTS_RP_STAMP(_version) \
127 (_version >= _XPC_VERSION(1,1)) 122 (_version >= _XPC_VERSION(1, 1))
128 123
129/* 124/*
130 * compare stamps - the return value is: 125 * compare stamps - the return value is:
@@ -138,14 +133,13 @@ xpc_compare_stamps(struct timespec *stamp1, struct timespec *stamp2)
138{ 133{
139 int ret; 134 int ret;
140 135
141 136 ret = stamp1->tv_sec - stamp2->tv_sec;
142 if ((ret = stamp1->tv_sec - stamp2->tv_sec) == 0) { 137 if (ret == 0)
143 ret = stamp1->tv_nsec - stamp2->tv_nsec; 138 ret = stamp1->tv_nsec - stamp2->tv_nsec;
144 } 139
145 return ret; 140 return ret;
146} 141}
147 142
148
149/* 143/*
150 * Define the structures by which XPC variables can be exported to other 144 * Define the structures by which XPC variables can be exported to other
151 * partitions. (There are two: struct xpc_vars and struct xpc_vars_part) 145 * partitions. (There are two: struct xpc_vars and struct xpc_vars_part)
@@ -172,11 +166,10 @@ struct xpc_vars {
172 AMO_t *amos_page; /* vaddr of page of AMOs from MSPEC driver */ 166 AMO_t *amos_page; /* vaddr of page of AMOs from MSPEC driver */
173}; 167};
174 168
175#define XPC_V_VERSION _XPC_VERSION(3,1) /* version 3.1 of the cross vars */ 169#define XPC_V_VERSION _XPC_VERSION(3, 1) /* version 3.1 of the cross vars */
176 170
177#define XPC_SUPPORTS_DISENGAGE_REQUEST(_version) \ 171#define XPC_SUPPORTS_DISENGAGE_REQUEST(_version) \
178 (_version >= _XPC_VERSION(3,1)) 172 (_version >= _XPC_VERSION(3, 1))
179
180 173
181static inline int 174static inline int
182xpc_hb_allowed(partid_t partid, struct xpc_vars *vars) 175xpc_hb_allowed(partid_t partid, struct xpc_vars *vars)
@@ -193,7 +186,7 @@ xpc_allow_hb(partid_t partid, struct xpc_vars *vars)
193 old_mask = vars->heartbeating_to_mask; 186 old_mask = vars->heartbeating_to_mask;
194 new_mask = (old_mask | (1UL << partid)); 187 new_mask = (old_mask | (1UL << partid));
195 } while (cmpxchg(&vars->heartbeating_to_mask, old_mask, new_mask) != 188 } while (cmpxchg(&vars->heartbeating_to_mask, old_mask, new_mask) !=
196 old_mask); 189 old_mask);
197} 190}
198 191
199static inline void 192static inline void
@@ -205,10 +198,9 @@ xpc_disallow_hb(partid_t partid, struct xpc_vars *vars)
205 old_mask = vars->heartbeating_to_mask; 198 old_mask = vars->heartbeating_to_mask;
206 new_mask = (old_mask & ~(1UL << partid)); 199 new_mask = (old_mask & ~(1UL << partid));
207 } while (cmpxchg(&vars->heartbeating_to_mask, old_mask, new_mask) != 200 } while (cmpxchg(&vars->heartbeating_to_mask, old_mask, new_mask) !=
208 old_mask); 201 old_mask);
209} 202}
210 203
211
212/* 204/*
213 * The AMOs page consists of a number of AMO variables which are divided into 205 * The AMOs page consists of a number of AMO variables which are divided into
214 * four groups, The first two groups are used to identify an IRQ's sender. 206 * four groups, The first two groups are used to identify an IRQ's sender.
@@ -222,7 +214,6 @@ xpc_disallow_hb(partid_t partid, struct xpc_vars *vars)
222#define XPC_ENGAGED_PARTITIONS_AMO (XPC_ACTIVATE_IRQ_AMOS + XP_NASID_MASK_WORDS) 214#define XPC_ENGAGED_PARTITIONS_AMO (XPC_ACTIVATE_IRQ_AMOS + XP_NASID_MASK_WORDS)
223#define XPC_DISENGAGE_REQUEST_AMO (XPC_ENGAGED_PARTITIONS_AMO + 1) 215#define XPC_DISENGAGE_REQUEST_AMO (XPC_ENGAGED_PARTITIONS_AMO + 1)
224 216
225
226/* 217/*
227 * The following structure describes the per partition specific variables. 218 * The following structure describes the per partition specific variables.
228 * 219 *
@@ -234,7 +225,7 @@ xpc_disallow_hb(partid_t partid, struct xpc_vars *vars)
234 * occupies half a cacheline. 225 * occupies half a cacheline.
235 */ 226 */
236struct xpc_vars_part { 227struct xpc_vars_part {
237 volatile u64 magic; 228 u64 magic;
238 229
239 u64 openclose_args_pa; /* physical address of open and close args */ 230 u64 openclose_args_pa; /* physical address of open and close args */
240 u64 GPs_pa; /* physical address of Get/Put values */ 231 u64 GPs_pa; /* physical address of Get/Put values */
@@ -257,20 +248,20 @@ struct xpc_vars_part {
257 * MAGIC2 indicates that this partition has pulled the remote partititions 248 * MAGIC2 indicates that this partition has pulled the remote partititions
258 * per partition variables that pertain to this partition. 249 * per partition variables that pertain to this partition.
259 */ 250 */
260#define XPC_VP_MAGIC1 0x0053524156435058L /* 'XPCVARS\0'L (little endian) */ 251#define XPC_VP_MAGIC1 0x0053524156435058L /* 'XPCVARS\0'L (little endian) */
261#define XPC_VP_MAGIC2 0x0073726176435058L /* 'XPCvars\0'L (little endian) */ 252#define XPC_VP_MAGIC2 0x0073726176435058L /* 'XPCvars\0'L (little endian) */
262
263 253
264/* the reserved page sizes and offsets */ 254/* the reserved page sizes and offsets */
265 255
266#define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page)) 256#define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page))
267#define XPC_RP_VARS_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_vars)) 257#define XPC_RP_VARS_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_vars))
268 258
269#define XPC_RP_PART_NASIDS(_rp) (u64 *) ((u8 *) _rp + XPC_RP_HEADER_SIZE) 259#define XPC_RP_PART_NASIDS(_rp) ((u64 *)((u8 *)(_rp) + XPC_RP_HEADER_SIZE))
270#define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + xp_nasid_mask_words) 260#define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + xp_nasid_mask_words)
271#define XPC_RP_VARS(_rp) ((struct xpc_vars *) XPC_RP_MACH_NASIDS(_rp) + xp_nasid_mask_words) 261#define XPC_RP_VARS(_rp) ((struct xpc_vars *)(XPC_RP_MACH_NASIDS(_rp) + \
272#define XPC_RP_VARS_PART(_rp) (struct xpc_vars_part *) ((u8 *) XPC_RP_VARS(rp) + XPC_RP_VARS_SIZE) 262 xp_nasid_mask_words))
273 263#define XPC_RP_VARS_PART(_rp) ((struct xpc_vars_part *) \
264 ((u8 *)XPC_RP_VARS(_rp) + XPC_RP_VARS_SIZE))
274 265
275/* 266/*
276 * Functions registered by add_timer() or called by kernel_thread() only 267 * Functions registered by add_timer() or called by kernel_thread() only
@@ -285,21 +276,17 @@ struct xpc_vars_part {
285#define XPC_UNPACK_ARG1(_args) (((u64) _args) & 0xffffffff) 276#define XPC_UNPACK_ARG1(_args) (((u64) _args) & 0xffffffff)
286#define XPC_UNPACK_ARG2(_args) ((((u64) _args) >> 32) & 0xffffffff) 277#define XPC_UNPACK_ARG2(_args) ((((u64) _args) >> 32) & 0xffffffff)
287 278
288
289
290/* 279/*
291 * Define a Get/Put value pair (pointers) used with a message queue. 280 * Define a Get/Put value pair (pointers) used with a message queue.
292 */ 281 */
293struct xpc_gp { 282struct xpc_gp {
294 volatile s64 get; /* Get value */ 283 s64 get; /* Get value */
295 volatile s64 put; /* Put value */ 284 s64 put; /* Put value */
296}; 285};
297 286
298#define XPC_GP_SIZE \ 287#define XPC_GP_SIZE \
299 L1_CACHE_ALIGN(sizeof(struct xpc_gp) * XPC_NCHANNELS) 288 L1_CACHE_ALIGN(sizeof(struct xpc_gp) * XPC_NCHANNELS)
300 289
301
302
303/* 290/*
304 * Define a structure that contains arguments associated with opening and 291 * Define a structure that contains arguments associated with opening and
305 * closing a channel. 292 * closing a channel.
@@ -315,20 +302,15 @@ struct xpc_openclose_args {
315#define XPC_OPENCLOSE_ARGS_SIZE \ 302#define XPC_OPENCLOSE_ARGS_SIZE \
316 L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * XPC_NCHANNELS) 303 L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * XPC_NCHANNELS)
317 304
318
319
320/* struct xpc_msg flags */ 305/* struct xpc_msg flags */
321 306
322#define XPC_M_DONE 0x01 /* msg has been received/consumed */ 307#define XPC_M_DONE 0x01 /* msg has been received/consumed */
323#define XPC_M_READY 0x02 /* msg is ready to be sent */ 308#define XPC_M_READY 0x02 /* msg is ready to be sent */
324#define XPC_M_INTERRUPT 0x04 /* send interrupt when msg consumed */ 309#define XPC_M_INTERRUPT 0x04 /* send interrupt when msg consumed */
325 310
326
327#define XPC_MSG_ADDRESS(_payload) \ 311#define XPC_MSG_ADDRESS(_payload) \
328 ((struct xpc_msg *)((u8 *)(_payload) - XPC_MSG_PAYLOAD_OFFSET)) 312 ((struct xpc_msg *)((u8 *)(_payload) - XPC_MSG_PAYLOAD_OFFSET))
329 313
330
331
332/* 314/*
333 * Defines notify entry. 315 * Defines notify entry.
334 * 316 *
@@ -336,19 +318,17 @@ struct xpc_openclose_args {
336 * and consumed by the intended recipient. 318 * and consumed by the intended recipient.
337 */ 319 */
338struct xpc_notify { 320struct xpc_notify {
339 volatile u8 type; /* type of notification */ 321 u8 type; /* type of notification */
340 322
341 /* the following two fields are only used if type == XPC_N_CALL */ 323 /* the following two fields are only used if type == XPC_N_CALL */
342 xpc_notify_func func; /* user's notify function */ 324 xpc_notify_func func; /* user's notify function */
343 void *key; /* pointer to user's key */ 325 void *key; /* pointer to user's key */
344}; 326};
345 327
346/* struct xpc_notify type of notification */ 328/* struct xpc_notify type of notification */
347 329
348#define XPC_N_CALL 0x01 /* notify function provided by user */ 330#define XPC_N_CALL 0x01 /* notify function provided by user */
349 331
350
351
352/* 332/*
353 * Define the structure that manages all the stuff required by a channel. In 333 * Define the structure that manages all the stuff required by a channel. In
354 * particular, they are used to manage the messages sent across the channel. 334 * particular, they are used to manage the messages sent across the channel.
@@ -428,48 +408,48 @@ struct xpc_notify {
428 * messages. 408 * messages.
429 */ 409 */
430struct xpc_channel { 410struct xpc_channel {
431 partid_t partid; /* ID of remote partition connected */ 411 partid_t partid; /* ID of remote partition connected */
432 spinlock_t lock; /* lock for updating this structure */ 412 spinlock_t lock; /* lock for updating this structure */
433 u32 flags; /* general flags */ 413 u32 flags; /* general flags */
434 414
435 enum xpc_retval reason; /* reason why channel is disconnect'g */ 415 enum xpc_retval reason; /* reason why channel is disconnect'g */
436 int reason_line; /* line# disconnect initiated from */ 416 int reason_line; /* line# disconnect initiated from */
437 417
438 u16 number; /* channel # */ 418 u16 number; /* channel # */
439 419
440 u16 msg_size; /* sizeof each msg entry */ 420 u16 msg_size; /* sizeof each msg entry */
441 u16 local_nentries; /* #of msg entries in local msg queue */ 421 u16 local_nentries; /* #of msg entries in local msg queue */
442 u16 remote_nentries; /* #of msg entries in remote msg queue*/ 422 u16 remote_nentries; /* #of msg entries in remote msg queue */
443 423
444 void *local_msgqueue_base; /* base address of kmalloc'd space */ 424 void *local_msgqueue_base; /* base address of kmalloc'd space */
445 struct xpc_msg *local_msgqueue; /* local message queue */ 425 struct xpc_msg *local_msgqueue; /* local message queue */
446 void *remote_msgqueue_base; /* base address of kmalloc'd space */ 426 void *remote_msgqueue_base; /* base address of kmalloc'd space */
447 struct xpc_msg *remote_msgqueue;/* cached copy of remote partition's */ 427 struct xpc_msg *remote_msgqueue; /* cached copy of remote partition's */
448 /* local message queue */ 428 /* local message queue */
449 u64 remote_msgqueue_pa; /* phys addr of remote partition's */ 429 u64 remote_msgqueue_pa; /* phys addr of remote partition's */
450 /* local message queue */ 430 /* local message queue */
451 431
452 atomic_t references; /* #of external references to queues */ 432 atomic_t references; /* #of external references to queues */
453 433
454 atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */ 434 atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */
455 wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */ 435 wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */
456 436
457 u8 delayed_IPI_flags; /* IPI flags received, but delayed */ 437 u8 delayed_IPI_flags; /* IPI flags received, but delayed */
458 /* action until channel disconnected */ 438 /* action until channel disconnected */
459 439
460 /* queue of msg senders who want to be notified when msg received */ 440 /* queue of msg senders who want to be notified when msg received */
461 441
462 atomic_t n_to_notify; /* #of msg senders to notify */ 442 atomic_t n_to_notify; /* #of msg senders to notify */
463 struct xpc_notify *notify_queue;/* notify queue for messages sent */ 443 struct xpc_notify *notify_queue; /* notify queue for messages sent */
464 444
465 xpc_channel_func func; /* user's channel function */ 445 xpc_channel_func func; /* user's channel function */
466 void *key; /* pointer to user's key */ 446 void *key; /* pointer to user's key */
467 447
468 struct mutex msg_to_pull_mutex; /* next msg to pull serialization */ 448 struct mutex msg_to_pull_mutex; /* next msg to pull serialization */
469 struct completion wdisconnect_wait; /* wait for channel disconnect */ 449 struct completion wdisconnect_wait; /* wait for channel disconnect */
470 450
471 struct xpc_openclose_args *local_openclose_args; /* args passed on */ 451 struct xpc_openclose_args *local_openclose_args; /* args passed on */
472 /* opening or closing of channel */ 452 /* opening or closing of channel */
473 453
474 /* various flavors of local and remote Get/Put values */ 454 /* various flavors of local and remote Get/Put values */
475 455
@@ -477,56 +457,48 @@ struct xpc_channel {
477 struct xpc_gp remote_GP; /* remote Get/Put values */ 457 struct xpc_gp remote_GP; /* remote Get/Put values */
478 struct xpc_gp w_local_GP; /* working local Get/Put values */ 458 struct xpc_gp w_local_GP; /* working local Get/Put values */
479 struct xpc_gp w_remote_GP; /* working remote Get/Put values */ 459 struct xpc_gp w_remote_GP; /* working remote Get/Put values */
480 s64 next_msg_to_pull; /* Put value of next msg to pull */ 460 s64 next_msg_to_pull; /* Put value of next msg to pull */
481 461
482 /* kthread management related fields */ 462 /* kthread management related fields */
483 463
484// >>> rethink having kthreads_assigned_limit and kthreads_idle_limit; perhaps
485// >>> allow the assigned limit be unbounded and let the idle limit be dynamic
486// >>> dependent on activity over the last interval of time
487 atomic_t kthreads_assigned; /* #of kthreads assigned to channel */ 464 atomic_t kthreads_assigned; /* #of kthreads assigned to channel */
488 u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */ 465 u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */
489 atomic_t kthreads_idle; /* #of kthreads idle waiting for work */ 466 atomic_t kthreads_idle; /* #of kthreads idle waiting for work */
490 u32 kthreads_idle_limit; /* limit on #of kthreads idle */ 467 u32 kthreads_idle_limit; /* limit on #of kthreads idle */
491 atomic_t kthreads_active; /* #of kthreads actively working */ 468 atomic_t kthreads_active; /* #of kthreads actively working */
492 // >>> following field is temporary
493 u32 kthreads_created; /* total #of kthreads created */
494 469
495 wait_queue_head_t idle_wq; /* idle kthread wait queue */ 470 wait_queue_head_t idle_wq; /* idle kthread wait queue */
496 471
497} ____cacheline_aligned; 472} ____cacheline_aligned;
498 473
499
500/* struct xpc_channel flags */ 474/* struct xpc_channel flags */
501 475
502#define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */ 476#define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */
503 477
504#define XPC_C_ROPENREPLY 0x00000002 /* remote open channel reply */ 478#define XPC_C_ROPENREPLY 0x00000002 /* remote open channel reply */
505#define XPC_C_OPENREPLY 0x00000004 /* local open channel reply */ 479#define XPC_C_OPENREPLY 0x00000004 /* local open channel reply */
506#define XPC_C_ROPENREQUEST 0x00000008 /* remote open channel request */ 480#define XPC_C_ROPENREQUEST 0x00000008 /* remote open channel request */
507#define XPC_C_OPENREQUEST 0x00000010 /* local open channel request */ 481#define XPC_C_OPENREQUEST 0x00000010 /* local open channel request */
508 482
509#define XPC_C_SETUP 0x00000020 /* channel's msgqueues are alloc'd */ 483#define XPC_C_SETUP 0x00000020 /* channel's msgqueues are alloc'd */
510#define XPC_C_CONNECTEDCALLOUT 0x00000040 /* connected callout initiated */ 484#define XPC_C_CONNECTEDCALLOUT 0x00000040 /* connected callout initiated */
511#define XPC_C_CONNECTEDCALLOUT_MADE \ 485#define XPC_C_CONNECTEDCALLOUT_MADE \
512 0x00000080 /* connected callout completed */ 486 0x00000080 /* connected callout completed */
513#define XPC_C_CONNECTED 0x00000100 /* local channel is connected */ 487#define XPC_C_CONNECTED 0x00000100 /* local channel is connected */
514#define XPC_C_CONNECTING 0x00000200 /* channel is being connected */ 488#define XPC_C_CONNECTING 0x00000200 /* channel is being connected */
515 489
516#define XPC_C_RCLOSEREPLY 0x00000400 /* remote close channel reply */ 490#define XPC_C_RCLOSEREPLY 0x00000400 /* remote close channel reply */
517#define XPC_C_CLOSEREPLY 0x00000800 /* local close channel reply */ 491#define XPC_C_CLOSEREPLY 0x00000800 /* local close channel reply */
518#define XPC_C_RCLOSEREQUEST 0x00001000 /* remote close channel request */ 492#define XPC_C_RCLOSEREQUEST 0x00001000 /* remote close channel request */
519#define XPC_C_CLOSEREQUEST 0x00002000 /* local close channel request */ 493#define XPC_C_CLOSEREQUEST 0x00002000 /* local close channel request */
520 494
521#define XPC_C_DISCONNECTED 0x00004000 /* channel is disconnected */ 495#define XPC_C_DISCONNECTED 0x00004000 /* channel is disconnected */
522#define XPC_C_DISCONNECTING 0x00008000 /* channel is being disconnected */ 496#define XPC_C_DISCONNECTING 0x00008000 /* channel is being disconnected */
523#define XPC_C_DISCONNECTINGCALLOUT \ 497#define XPC_C_DISCONNECTINGCALLOUT \
524 0x00010000 /* disconnecting callout initiated */ 498 0x00010000 /* disconnecting callout initiated */
525#define XPC_C_DISCONNECTINGCALLOUT_MADE \ 499#define XPC_C_DISCONNECTINGCALLOUT_MADE \
526 0x00020000 /* disconnecting callout completed */ 500 0x00020000 /* disconnecting callout completed */
527#define XPC_C_WDISCONNECT 0x00040000 /* waiting for channel disconnect */ 501#define XPC_C_WDISCONNECT 0x00040000 /* waiting for channel disconnect */
528
529
530 502
531/* 503/*
532 * Manages channels on a partition basis. There is one of these structures 504 * Manages channels on a partition basis. There is one of these structures
@@ -537,33 +509,31 @@ struct xpc_partition {
537 509
538 /* XPC HB infrastructure */ 510 /* XPC HB infrastructure */
539 511
540 u8 remote_rp_version; /* version# of partition's rsvd pg */ 512 u8 remote_rp_version; /* version# of partition's rsvd pg */
541 struct timespec remote_rp_stamp;/* time when rsvd pg was initialized */ 513 struct timespec remote_rp_stamp; /* time when rsvd pg was initialized */
542 u64 remote_rp_pa; /* phys addr of partition's rsvd pg */ 514 u64 remote_rp_pa; /* phys addr of partition's rsvd pg */
543 u64 remote_vars_pa; /* phys addr of partition's vars */ 515 u64 remote_vars_pa; /* phys addr of partition's vars */
544 u64 remote_vars_part_pa; /* phys addr of partition's vars part */ 516 u64 remote_vars_part_pa; /* phys addr of partition's vars part */
545 u64 last_heartbeat; /* HB at last read */ 517 u64 last_heartbeat; /* HB at last read */
546 u64 remote_amos_page_pa; /* phys addr of partition's amos page */ 518 u64 remote_amos_page_pa; /* phys addr of partition's amos page */
547 int remote_act_nasid; /* active part's act/deact nasid */ 519 int remote_act_nasid; /* active part's act/deact nasid */
548 int remote_act_phys_cpuid; /* active part's act/deact phys cpuid */ 520 int remote_act_phys_cpuid; /* active part's act/deact phys cpuid */
549 u32 act_IRQ_rcvd; /* IRQs since activation */ 521 u32 act_IRQ_rcvd; /* IRQs since activation */
550 spinlock_t act_lock; /* protect updating of act_state */ 522 spinlock_t act_lock; /* protect updating of act_state */
551 u8 act_state; /* from XPC HB viewpoint */ 523 u8 act_state; /* from XPC HB viewpoint */
552 u8 remote_vars_version; /* version# of partition's vars */ 524 u8 remote_vars_version; /* version# of partition's vars */
553 enum xpc_retval reason; /* reason partition is deactivating */ 525 enum xpc_retval reason; /* reason partition is deactivating */
554 int reason_line; /* line# deactivation initiated from */ 526 int reason_line; /* line# deactivation initiated from */
555 int reactivate_nasid; /* nasid in partition to reactivate */ 527 int reactivate_nasid; /* nasid in partition to reactivate */
556 528
557 unsigned long disengage_request_timeout; /* timeout in jiffies */ 529 unsigned long disengage_request_timeout; /* timeout in jiffies */
558 struct timer_list disengage_request_timer; 530 struct timer_list disengage_request_timer;
559 531
560
561 /* XPC infrastructure referencing and teardown control */ 532 /* XPC infrastructure referencing and teardown control */
562 533
563 volatile u8 setup_state; /* infrastructure setup state */ 534 u8 setup_state; /* infrastructure setup state */
564 wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */ 535 wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */
565 atomic_t references; /* #of references to infrastructure */ 536 atomic_t references; /* #of references to infrastructure */
566
567 537
568 /* 538 /*
569 * NONE OF THE PRECEDING FIELDS OF THIS STRUCTURE WILL BE CLEARED WHEN 539 * NONE OF THE PRECEDING FIELDS OF THIS STRUCTURE WILL BE CLEARED WHEN
@@ -572,53 +542,48 @@ struct xpc_partition {
572 * 'nchannels' FIELD MUST BE THE FIRST OF THE FIELDS TO BE CLEARED.) 542 * 'nchannels' FIELD MUST BE THE FIRST OF THE FIELDS TO BE CLEARED.)
573 */ 543 */
574 544
575 545 u8 nchannels; /* #of defined channels supported */
576 u8 nchannels; /* #of defined channels supported */ 546 atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */
577 atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */ 547 atomic_t nchannels_engaged; /* #of channels engaged with remote part */
578 atomic_t nchannels_engaged;/* #of channels engaged with remote part */ 548 struct xpc_channel *channels; /* array of channel structures */
579 struct xpc_channel *channels;/* array of channel structures */ 549
580 550 void *local_GPs_base; /* base address of kmalloc'd space */
581 void *local_GPs_base; /* base address of kmalloc'd space */ 551 struct xpc_gp *local_GPs; /* local Get/Put values */
582 struct xpc_gp *local_GPs; /* local Get/Put values */ 552 void *remote_GPs_base; /* base address of kmalloc'd space */
583 void *remote_GPs_base; /* base address of kmalloc'd space */ 553 struct xpc_gp *remote_GPs; /* copy of remote partition's local */
584 struct xpc_gp *remote_GPs;/* copy of remote partition's local Get/Put */ 554 /* Get/Put values */
585 /* values */ 555 u64 remote_GPs_pa; /* phys address of remote partition's local */
586 u64 remote_GPs_pa; /* phys address of remote partition's local */ 556 /* Get/Put values */
587 /* Get/Put values */
588
589 557
590 /* fields used to pass args when opening or closing a channel */ 558 /* fields used to pass args when opening or closing a channel */
591 559
592 void *local_openclose_args_base; /* base address of kmalloc'd space */ 560 void *local_openclose_args_base; /* base address of kmalloc'd space */
593 struct xpc_openclose_args *local_openclose_args; /* local's args */ 561 struct xpc_openclose_args *local_openclose_args; /* local's args */
594 void *remote_openclose_args_base; /* base address of kmalloc'd space */ 562 void *remote_openclose_args_base; /* base address of kmalloc'd space */
595 struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */ 563 struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
596 /* args */ 564 /* args */
597 u64 remote_openclose_args_pa; /* phys addr of remote's args */ 565 u64 remote_openclose_args_pa; /* phys addr of remote's args */
598
599 566
600 /* IPI sending, receiving and handling related fields */ 567 /* IPI sending, receiving and handling related fields */
601 568
602 int remote_IPI_nasid; /* nasid of where to send IPIs */ 569 int remote_IPI_nasid; /* nasid of where to send IPIs */
603 int remote_IPI_phys_cpuid; /* phys CPU ID of where to send IPIs */ 570 int remote_IPI_phys_cpuid; /* phys CPU ID of where to send IPIs */
604 AMO_t *remote_IPI_amo_va; /* address of remote IPI AMO_t structure */ 571 AMO_t *remote_IPI_amo_va; /* address of remote IPI AMO_t structure */
605
606 AMO_t *local_IPI_amo_va; /* address of IPI AMO_t structure */
607 u64 local_IPI_amo; /* IPI amo flags yet to be handled */
608 char IPI_owner[8]; /* IPI owner's name */
609 struct timer_list dropped_IPI_timer; /* dropped IPI timer */
610 572
611 spinlock_t IPI_lock; /* IPI handler lock */ 573 AMO_t *local_IPI_amo_va; /* address of IPI AMO_t structure */
574 u64 local_IPI_amo; /* IPI amo flags yet to be handled */
575 char IPI_owner[8]; /* IPI owner's name */
576 struct timer_list dropped_IPI_timer; /* dropped IPI timer */
612 577
578 spinlock_t IPI_lock; /* IPI handler lock */
613 579
614 /* channel manager related fields */ 580 /* channel manager related fields */
615 581
616 atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */ 582 atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */
617 wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */ 583 wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */
618 584
619} ____cacheline_aligned; 585} ____cacheline_aligned;
620 586
621
622/* struct xpc_partition act_state values (for XPC HB) */ 587/* struct xpc_partition act_state values (for XPC HB) */
623 588
624#define XPC_P_INACTIVE 0x00 /* partition is not active */ 589#define XPC_P_INACTIVE 0x00 /* partition is not active */
@@ -627,11 +592,9 @@ struct xpc_partition {
627#define XPC_P_ACTIVE 0x03 /* xpc_partition_up() was called */ 592#define XPC_P_ACTIVE 0x03 /* xpc_partition_up() was called */
628#define XPC_P_DEACTIVATING 0x04 /* partition deactivation initiated */ 593#define XPC_P_DEACTIVATING 0x04 /* partition deactivation initiated */
629 594
630
631#define XPC_DEACTIVATE_PARTITION(_p, _reason) \ 595#define XPC_DEACTIVATE_PARTITION(_p, _reason) \
632 xpc_deactivate_partition(__LINE__, (_p), (_reason)) 596 xpc_deactivate_partition(__LINE__, (_p), (_reason))
633 597
634
635/* struct xpc_partition setup_state values */ 598/* struct xpc_partition setup_state values */
636 599
637#define XPC_P_UNSET 0x00 /* infrastructure was never setup */ 600#define XPC_P_UNSET 0x00 /* infrastructure was never setup */
@@ -639,8 +602,6 @@ struct xpc_partition {
639#define XPC_P_WTEARDOWN 0x02 /* waiting to teardown infrastructure */ 602#define XPC_P_WTEARDOWN 0x02 /* waiting to teardown infrastructure */
640#define XPC_P_TORNDOWN 0x03 /* infrastructure is torndown */ 603#define XPC_P_TORNDOWN 0x03 /* infrastructure is torndown */
641 604
642
643
644/* 605/*
645 * struct xpc_partition IPI_timer #of seconds to wait before checking for 606 * struct xpc_partition IPI_timer #of seconds to wait before checking for
646 * dropped IPIs. These occur whenever an IPI amo write doesn't complete until 607 * dropped IPIs. These occur whenever an IPI amo write doesn't complete until
@@ -648,22 +609,17 @@ struct xpc_partition {
648 */ 609 */
649#define XPC_P_DROPPED_IPI_WAIT (0.25 * HZ) 610#define XPC_P_DROPPED_IPI_WAIT (0.25 * HZ)
650 611
651
652/* number of seconds to wait for other partitions to disengage */ 612/* number of seconds to wait for other partitions to disengage */
653#define XPC_DISENGAGE_REQUEST_DEFAULT_TIMELIMIT 90 613#define XPC_DISENGAGE_REQUEST_DEFAULT_TIMELIMIT 90
654 614
655/* interval in seconds to print 'waiting disengagement' messages */ 615/* interval in seconds to print 'waiting disengagement' messages */
656#define XPC_DISENGAGE_PRINTMSG_INTERVAL 10 616#define XPC_DISENGAGE_PRINTMSG_INTERVAL 10
657 617
658
659#define XPC_PARTID(_p) ((partid_t) ((_p) - &xpc_partitions[0])) 618#define XPC_PARTID(_p) ((partid_t) ((_p) - &xpc_partitions[0]))
660 619
661
662
663/* found in xp_main.c */ 620/* found in xp_main.c */
664extern struct xpc_registration xpc_registrations[]; 621extern struct xpc_registration xpc_registrations[];
665 622
666
667/* found in xpc_main.c */ 623/* found in xpc_main.c */
668extern struct device *xpc_part; 624extern struct device *xpc_part;
669extern struct device *xpc_chan; 625extern struct device *xpc_chan;
@@ -676,7 +632,6 @@ extern void xpc_activate_kthreads(struct xpc_channel *, int);
676extern void xpc_create_kthreads(struct xpc_channel *, int, int); 632extern void xpc_create_kthreads(struct xpc_channel *, int, int);
677extern void xpc_disconnect_wait(int); 633extern void xpc_disconnect_wait(int);
678 634
679
680/* found in xpc_partition.c */ 635/* found in xpc_partition.c */
681extern int xpc_exiting; 636extern int xpc_exiting;
682extern struct xpc_vars *xpc_vars; 637extern struct xpc_vars *xpc_vars;
@@ -696,10 +651,9 @@ extern void xpc_mark_partition_inactive(struct xpc_partition *);
696extern void xpc_discovery(void); 651extern void xpc_discovery(void);
697extern void xpc_check_remote_hb(void); 652extern void xpc_check_remote_hb(void);
698extern void xpc_deactivate_partition(const int, struct xpc_partition *, 653extern void xpc_deactivate_partition(const int, struct xpc_partition *,
699 enum xpc_retval); 654 enum xpc_retval);
700extern enum xpc_retval xpc_initiate_partid_to_nasids(partid_t, void *); 655extern enum xpc_retval xpc_initiate_partid_to_nasids(partid_t, void *);
701 656
702
703/* found in xpc_channel.c */ 657/* found in xpc_channel.c */
704extern void xpc_initiate_connect(int); 658extern void xpc_initiate_connect(int);
705extern void xpc_initiate_disconnect(int); 659extern void xpc_initiate_disconnect(int);
@@ -714,23 +668,18 @@ extern void xpc_process_channel_activity(struct xpc_partition *);
714extern void xpc_connected_callout(struct xpc_channel *); 668extern void xpc_connected_callout(struct xpc_channel *);
715extern void xpc_deliver_msg(struct xpc_channel *); 669extern void xpc_deliver_msg(struct xpc_channel *);
716extern void xpc_disconnect_channel(const int, struct xpc_channel *, 670extern void xpc_disconnect_channel(const int, struct xpc_channel *,
717 enum xpc_retval, unsigned long *); 671 enum xpc_retval, unsigned long *);
718extern void xpc_disconnect_callout(struct xpc_channel *, enum xpc_retval); 672extern void xpc_disconnect_callout(struct xpc_channel *, enum xpc_retval);
719extern void xpc_partition_going_down(struct xpc_partition *, enum xpc_retval); 673extern void xpc_partition_going_down(struct xpc_partition *, enum xpc_retval);
720extern void xpc_teardown_infrastructure(struct xpc_partition *); 674extern void xpc_teardown_infrastructure(struct xpc_partition *);
721 675
722
723
724static inline void 676static inline void
725xpc_wakeup_channel_mgr(struct xpc_partition *part) 677xpc_wakeup_channel_mgr(struct xpc_partition *part)
726{ 678{
727 if (atomic_inc_return(&part->channel_mgr_requests) == 1) { 679 if (atomic_inc_return(&part->channel_mgr_requests) == 1)
728 wake_up(&part->channel_mgr_wq); 680 wake_up(&part->channel_mgr_wq);
729 }
730} 681}
731 682
732
733
734/* 683/*
735 * These next two inlines are used to keep us from tearing down a channel's 684 * These next two inlines are used to keep us from tearing down a channel's
736 * msg queues while a thread may be referencing them. 685 * msg queues while a thread may be referencing them.
@@ -747,17 +696,13 @@ xpc_msgqueue_deref(struct xpc_channel *ch)
747 s32 refs = atomic_dec_return(&ch->references); 696 s32 refs = atomic_dec_return(&ch->references);
748 697
749 DBUG_ON(refs < 0); 698 DBUG_ON(refs < 0);
750 if (refs == 0) { 699 if (refs == 0)
751 xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]); 700 xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
752 }
753} 701}
754 702
755
756
757#define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \ 703#define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
758 xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs) 704 xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
759 705
760
761/* 706/*
762 * These two inlines are used to keep us from tearing down a partition's 707 * These two inlines are used to keep us from tearing down a partition's
763 * setup infrastructure while a thread may be referencing it. 708 * setup infrastructure while a thread may be referencing it.
@@ -767,11 +712,9 @@ xpc_part_deref(struct xpc_partition *part)
767{ 712{
768 s32 refs = atomic_dec_return(&part->references); 713 s32 refs = atomic_dec_return(&part->references);
769 714
770
771 DBUG_ON(refs < 0); 715 DBUG_ON(refs < 0);
772 if (refs == 0 && part->setup_state == XPC_P_WTEARDOWN) { 716 if (refs == 0 && part->setup_state == XPC_P_WTEARDOWN)
773 wake_up(&part->teardown_wq); 717 wake_up(&part->teardown_wq);
774 }
775} 718}
776 719
777static inline int 720static inline int
@@ -779,17 +722,14 @@ xpc_part_ref(struct xpc_partition *part)
779{ 722{
780 int setup; 723 int setup;
781 724
782
783 atomic_inc(&part->references); 725 atomic_inc(&part->references);
784 setup = (part->setup_state == XPC_P_SETUP); 726 setup = (part->setup_state == XPC_P_SETUP);
785 if (!setup) { 727 if (!setup)
786 xpc_part_deref(part); 728 xpc_part_deref(part);
787 } 729
788 return setup; 730 return setup;
789} 731}
790 732
791
792
793/* 733/*
794 * The following macro is to be used for the setting of the reason and 734 * The following macro is to be used for the setting of the reason and
795 * reason_line fields in both the struct xpc_channel and struct xpc_partition 735 * reason_line fields in both the struct xpc_channel and struct xpc_partition
@@ -801,8 +741,6 @@ xpc_part_ref(struct xpc_partition *part)
801 (_p)->reason_line = _line; \ 741 (_p)->reason_line = _line; \
802 } 742 }
803 743
804
805
806/* 744/*
807 * This next set of inlines are used to keep track of when a partition is 745 * This next set of inlines are used to keep track of when a partition is
808 * potentially engaged in accessing memory belonging to another partition. 746 * potentially engaged in accessing memory belonging to another partition.
@@ -812,23 +750,24 @@ static inline void
812xpc_mark_partition_engaged(struct xpc_partition *part) 750xpc_mark_partition_engaged(struct xpc_partition *part)
813{ 751{
814 unsigned long irq_flags; 752 unsigned long irq_flags;
815 AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa + 753 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
816 (XPC_ENGAGED_PARTITIONS_AMO * sizeof(AMO_t))); 754 (XPC_ENGAGED_PARTITIONS_AMO *
817 755 sizeof(AMO_t)));
818 756
819 local_irq_save(irq_flags); 757 local_irq_save(irq_flags);
820 758
821 /* set bit corresponding to our partid in remote partition's AMO */ 759 /* set bit corresponding to our partid in remote partition's AMO */
822 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR, 760 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR,
823 (1UL << sn_partition_id)); 761 (1UL << sn_partition_id));
824 /* 762 /*
825 * We must always use the nofault function regardless of whether we 763 * We must always use the nofault function regardless of whether we
826 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we 764 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
827 * didn't, we'd never know that the other partition is down and would 765 * didn't, we'd never know that the other partition is down and would
828 * keep sending IPIs and AMOs to it until the heartbeat times out. 766 * keep sending IPIs and AMOs to it until the heartbeat times out.
829 */ 767 */
830 (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo-> 768 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
831 variable), xp_nofault_PIOR_target)); 769 variable),
770 xp_nofault_PIOR_target));
832 771
833 local_irq_restore(irq_flags); 772 local_irq_restore(irq_flags);
834} 773}
@@ -837,23 +776,24 @@ static inline void
837xpc_mark_partition_disengaged(struct xpc_partition *part) 776xpc_mark_partition_disengaged(struct xpc_partition *part)
838{ 777{
839 unsigned long irq_flags; 778 unsigned long irq_flags;
840 AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa + 779 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
841 (XPC_ENGAGED_PARTITIONS_AMO * sizeof(AMO_t))); 780 (XPC_ENGAGED_PARTITIONS_AMO *
842 781 sizeof(AMO_t)));
843 782
844 local_irq_save(irq_flags); 783 local_irq_save(irq_flags);
845 784
846 /* clear bit corresponding to our partid in remote partition's AMO */ 785 /* clear bit corresponding to our partid in remote partition's AMO */
847 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND, 786 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
848 ~(1UL << sn_partition_id)); 787 ~(1UL << sn_partition_id));
849 /* 788 /*
850 * We must always use the nofault function regardless of whether we 789 * We must always use the nofault function regardless of whether we
851 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we 790 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
852 * didn't, we'd never know that the other partition is down and would 791 * didn't, we'd never know that the other partition is down and would
853 * keep sending IPIs and AMOs to it until the heartbeat times out. 792 * keep sending IPIs and AMOs to it until the heartbeat times out.
854 */ 793 */
855 (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo-> 794 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
856 variable), xp_nofault_PIOR_target)); 795 variable),
796 xp_nofault_PIOR_target));
857 797
858 local_irq_restore(irq_flags); 798 local_irq_restore(irq_flags);
859} 799}
@@ -862,23 +802,23 @@ static inline void
862xpc_request_partition_disengage(struct xpc_partition *part) 802xpc_request_partition_disengage(struct xpc_partition *part)
863{ 803{
864 unsigned long irq_flags; 804 unsigned long irq_flags;
865 AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa + 805 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
866 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t))); 806 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
867
868 807
869 local_irq_save(irq_flags); 808 local_irq_save(irq_flags);
870 809
871 /* set bit corresponding to our partid in remote partition's AMO */ 810 /* set bit corresponding to our partid in remote partition's AMO */
872 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR, 811 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR,
873 (1UL << sn_partition_id)); 812 (1UL << sn_partition_id));
874 /* 813 /*
875 * We must always use the nofault function regardless of whether we 814 * We must always use the nofault function regardless of whether we
876 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we 815 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
877 * didn't, we'd never know that the other partition is down and would 816 * didn't, we'd never know that the other partition is down and would
878 * keep sending IPIs and AMOs to it until the heartbeat times out. 817 * keep sending IPIs and AMOs to it until the heartbeat times out.
879 */ 818 */
880 (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo-> 819 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
881 variable), xp_nofault_PIOR_target)); 820 variable),
821 xp_nofault_PIOR_target));
882 822
883 local_irq_restore(irq_flags); 823 local_irq_restore(irq_flags);
884} 824}
@@ -887,23 +827,23 @@ static inline void
887xpc_cancel_partition_disengage_request(struct xpc_partition *part) 827xpc_cancel_partition_disengage_request(struct xpc_partition *part)
888{ 828{
889 unsigned long irq_flags; 829 unsigned long irq_flags;
890 AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa + 830 AMO_t *amo = (AMO_t *)__va(part->remote_amos_page_pa +
891 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t))); 831 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
892
893 832
894 local_irq_save(irq_flags); 833 local_irq_save(irq_flags);
895 834
896 /* clear bit corresponding to our partid in remote partition's AMO */ 835 /* clear bit corresponding to our partid in remote partition's AMO */
897 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND, 836 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
898 ~(1UL << sn_partition_id)); 837 ~(1UL << sn_partition_id));
899 /* 838 /*
900 * We must always use the nofault function regardless of whether we 839 * We must always use the nofault function regardless of whether we
901 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we 840 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
902 * didn't, we'd never know that the other partition is down and would 841 * didn't, we'd never know that the other partition is down and would
903 * keep sending IPIs and AMOs to it until the heartbeat times out. 842 * keep sending IPIs and AMOs to it until the heartbeat times out.
904 */ 843 */
905 (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo-> 844 (void)xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->
906 variable), xp_nofault_PIOR_target)); 845 variable),
846 xp_nofault_PIOR_target));
907 847
908 local_irq_restore(irq_flags); 848 local_irq_restore(irq_flags);
909} 849}
@@ -913,10 +853,9 @@ xpc_partition_engaged(u64 partid_mask)
913{ 853{
914 AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO; 854 AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
915 855
916
917 /* return our partition's AMO variable ANDed with partid_mask */ 856 /* return our partition's AMO variable ANDed with partid_mask */
918 return (FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_LOAD) & 857 return (FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) &
919 partid_mask); 858 partid_mask);
920} 859}
921 860
922static inline u64 861static inline u64
@@ -924,10 +863,9 @@ xpc_partition_disengage_requested(u64 partid_mask)
924{ 863{
925 AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO; 864 AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
926 865
927
928 /* return our partition's AMO variable ANDed with partid_mask */ 866 /* return our partition's AMO variable ANDed with partid_mask */
929 return (FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_LOAD) & 867 return (FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_LOAD) &
930 partid_mask); 868 partid_mask);
931} 869}
932 870
933static inline void 871static inline void
@@ -935,10 +873,9 @@ xpc_clear_partition_engaged(u64 partid_mask)
935{ 873{
936 AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO; 874 AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
937 875
938
939 /* clear bit(s) based on partid_mask in our partition's AMO */ 876 /* clear bit(s) based on partid_mask in our partition's AMO */
940 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND, 877 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
941 ~partid_mask); 878 ~partid_mask);
942} 879}
943 880
944static inline void 881static inline void
@@ -946,14 +883,11 @@ xpc_clear_partition_disengage_request(u64 partid_mask)
946{ 883{
947 AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO; 884 AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
948 885
949
950 /* clear bit(s) based on partid_mask in our partition's AMO */ 886 /* clear bit(s) based on partid_mask in our partition's AMO */
951 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND, 887 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_AND,
952 ~partid_mask); 888 ~partid_mask);
953} 889}
954 890
955
956
957/* 891/*
958 * The following set of macros and inlines are used for the sending and 892 * The following set of macros and inlines are used for the sending and
959 * receiving of IPIs (also known as IRQs). There are two flavors of IPIs, 893 * receiving of IPIs (also known as IRQs). There are two flavors of IPIs,
@@ -964,20 +898,18 @@ xpc_clear_partition_disengage_request(u64 partid_mask)
964static inline u64 898static inline u64
965xpc_IPI_receive(AMO_t *amo) 899xpc_IPI_receive(AMO_t *amo)
966{ 900{
967 return FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_CLEAR); 901 return FETCHOP_LOAD_OP(TO_AMO((u64)&amo->variable), FETCHOP_CLEAR);
968} 902}
969 903
970
971static inline enum xpc_retval 904static inline enum xpc_retval
972xpc_IPI_send(AMO_t *amo, u64 flag, int nasid, int phys_cpuid, int vector) 905xpc_IPI_send(AMO_t *amo, u64 flag, int nasid, int phys_cpuid, int vector)
973{ 906{
974 int ret = 0; 907 int ret = 0;
975 unsigned long irq_flags; 908 unsigned long irq_flags;
976 909
977
978 local_irq_save(irq_flags); 910 local_irq_save(irq_flags);
979 911
980 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR, flag); 912 FETCHOP_STORE_OP(TO_AMO((u64)&amo->variable), FETCHOP_OR, flag);
981 sn_send_IPI_phys(nasid, phys_cpuid, vector, 0); 913 sn_send_IPI_phys(nasid, phys_cpuid, vector, 0);
982 914
983 /* 915 /*
@@ -986,15 +918,14 @@ xpc_IPI_send(AMO_t *amo, u64 flag, int nasid, int phys_cpuid, int vector)
986 * didn't, we'd never know that the other partition is down and would 918 * didn't, we'd never know that the other partition is down and would
987 * keep sending IPIs and AMOs to it until the heartbeat times out. 919 * keep sending IPIs and AMOs to it until the heartbeat times out.
988 */ 920 */
989 ret = xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->variable), 921 ret = xp_nofault_PIOR((u64 *)GLOBAL_MMR_ADDR(NASID_GET(&amo->variable),
990 xp_nofault_PIOR_target)); 922 xp_nofault_PIOR_target));
991 923
992 local_irq_restore(irq_flags); 924 local_irq_restore(irq_flags);
993 925
994 return ((ret == 0) ? xpcSuccess : xpcPioReadError); 926 return ((ret == 0) ? xpcSuccess : xpcPioReadError);
995} 927}
996 928
997
998/* 929/*
999 * IPIs associated with SGI_XPC_ACTIVATE IRQ. 930 * IPIs associated with SGI_XPC_ACTIVATE IRQ.
1000 */ 931 */
@@ -1004,47 +935,47 @@ xpc_IPI_send(AMO_t *amo, u64 flag, int nasid, int phys_cpuid, int vector)
1004 */ 935 */
1005static inline void 936static inline void
1006xpc_activate_IRQ_send(u64 amos_page_pa, int from_nasid, int to_nasid, 937xpc_activate_IRQ_send(u64 amos_page_pa, int from_nasid, int to_nasid,
1007 int to_phys_cpuid) 938 int to_phys_cpuid)
1008{ 939{
1009 int w_index = XPC_NASID_W_INDEX(from_nasid); 940 int w_index = XPC_NASID_W_INDEX(from_nasid);
1010 int b_index = XPC_NASID_B_INDEX(from_nasid); 941 int b_index = XPC_NASID_B_INDEX(from_nasid);
1011 AMO_t *amos = (AMO_t *) __va(amos_page_pa + 942 AMO_t *amos = (AMO_t *)__va(amos_page_pa +
1012 (XPC_ACTIVATE_IRQ_AMOS * sizeof(AMO_t))); 943 (XPC_ACTIVATE_IRQ_AMOS * sizeof(AMO_t)));
1013 944
1014 945 (void)xpc_IPI_send(&amos[w_index], (1UL << b_index), to_nasid,
1015 (void) xpc_IPI_send(&amos[w_index], (1UL << b_index), to_nasid, 946 to_phys_cpuid, SGI_XPC_ACTIVATE);
1016 to_phys_cpuid, SGI_XPC_ACTIVATE);
1017} 947}
1018 948
1019static inline void 949static inline void
1020xpc_IPI_send_activate(struct xpc_vars *vars) 950xpc_IPI_send_activate(struct xpc_vars *vars)
1021{ 951{
1022 xpc_activate_IRQ_send(vars->amos_page_pa, cnodeid_to_nasid(0), 952 xpc_activate_IRQ_send(vars->amos_page_pa, cnodeid_to_nasid(0),
1023 vars->act_nasid, vars->act_phys_cpuid); 953 vars->act_nasid, vars->act_phys_cpuid);
1024} 954}
1025 955
1026static inline void 956static inline void
1027xpc_IPI_send_activated(struct xpc_partition *part) 957xpc_IPI_send_activated(struct xpc_partition *part)
1028{ 958{
1029 xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0), 959 xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
1030 part->remote_act_nasid, part->remote_act_phys_cpuid); 960 part->remote_act_nasid,
961 part->remote_act_phys_cpuid);
1031} 962}
1032 963
1033static inline void 964static inline void
1034xpc_IPI_send_reactivate(struct xpc_partition *part) 965xpc_IPI_send_reactivate(struct xpc_partition *part)
1035{ 966{
1036 xpc_activate_IRQ_send(xpc_vars->amos_page_pa, part->reactivate_nasid, 967 xpc_activate_IRQ_send(xpc_vars->amos_page_pa, part->reactivate_nasid,
1037 xpc_vars->act_nasid, xpc_vars->act_phys_cpuid); 968 xpc_vars->act_nasid, xpc_vars->act_phys_cpuid);
1038} 969}
1039 970
1040static inline void 971static inline void
1041xpc_IPI_send_disengage(struct xpc_partition *part) 972xpc_IPI_send_disengage(struct xpc_partition *part)
1042{ 973{
1043 xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0), 974 xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
1044 part->remote_act_nasid, part->remote_act_phys_cpuid); 975 part->remote_act_nasid,
976 part->remote_act_phys_cpuid);
1045} 977}
1046 978
1047
1048/* 979/*
1049 * IPIs associated with SGI_XPC_NOTIFY IRQ. 980 * IPIs associated with SGI_XPC_NOTIFY IRQ.
1050 */ 981 */
@@ -1058,33 +989,28 @@ xpc_IPI_send_disengage(struct xpc_partition *part)
1058 989
1059static inline void 990static inline void
1060xpc_notify_IRQ_send(struct xpc_channel *ch, u8 ipi_flag, char *ipi_flag_string, 991xpc_notify_IRQ_send(struct xpc_channel *ch, u8 ipi_flag, char *ipi_flag_string,
1061 unsigned long *irq_flags) 992 unsigned long *irq_flags)
1062{ 993{
1063 struct xpc_partition *part = &xpc_partitions[ch->partid]; 994 struct xpc_partition *part = &xpc_partitions[ch->partid];
1064 enum xpc_retval ret; 995 enum xpc_retval ret;
1065 996
1066
1067 if (likely(part->act_state != XPC_P_DEACTIVATING)) { 997 if (likely(part->act_state != XPC_P_DEACTIVATING)) {
1068 ret = xpc_IPI_send(part->remote_IPI_amo_va, 998 ret = xpc_IPI_send(part->remote_IPI_amo_va,
1069 (u64) ipi_flag << (ch->number * 8), 999 (u64)ipi_flag << (ch->number * 8),
1070 part->remote_IPI_nasid, 1000 part->remote_IPI_nasid,
1071 part->remote_IPI_phys_cpuid, 1001 part->remote_IPI_phys_cpuid, SGI_XPC_NOTIFY);
1072 SGI_XPC_NOTIFY);
1073 dev_dbg(xpc_chan, "%s sent to partid=%d, channel=%d, ret=%d\n", 1002 dev_dbg(xpc_chan, "%s sent to partid=%d, channel=%d, ret=%d\n",
1074 ipi_flag_string, ch->partid, ch->number, ret); 1003 ipi_flag_string, ch->partid, ch->number, ret);
1075 if (unlikely(ret != xpcSuccess)) { 1004 if (unlikely(ret != xpcSuccess)) {
1076 if (irq_flags != NULL) { 1005 if (irq_flags != NULL)
1077 spin_unlock_irqrestore(&ch->lock, *irq_flags); 1006 spin_unlock_irqrestore(&ch->lock, *irq_flags);
1078 }
1079 XPC_DEACTIVATE_PARTITION(part, ret); 1007 XPC_DEACTIVATE_PARTITION(part, ret);
1080 if (irq_flags != NULL) { 1008 if (irq_flags != NULL)
1081 spin_lock_irqsave(&ch->lock, *irq_flags); 1009 spin_lock_irqsave(&ch->lock, *irq_flags);
1082 }
1083 } 1010 }
1084 } 1011 }
1085} 1012}
1086 1013
1087
1088/* 1014/*
1089 * Make it look like the remote partition, which is associated with the 1015 * Make it look like the remote partition, which is associated with the
1090 * specified channel, sent us an IPI. This faked IPI will be handled 1016 * specified channel, sent us an IPI. This faked IPI will be handled
@@ -1095,18 +1021,16 @@ xpc_notify_IRQ_send(struct xpc_channel *ch, u8 ipi_flag, char *ipi_flag_string,
1095 1021
1096static inline void 1022static inline void
1097xpc_notify_IRQ_send_local(struct xpc_channel *ch, u8 ipi_flag, 1023xpc_notify_IRQ_send_local(struct xpc_channel *ch, u8 ipi_flag,
1098 char *ipi_flag_string) 1024 char *ipi_flag_string)
1099{ 1025{
1100 struct xpc_partition *part = &xpc_partitions[ch->partid]; 1026 struct xpc_partition *part = &xpc_partitions[ch->partid];
1101 1027
1102 1028 FETCHOP_STORE_OP(TO_AMO((u64)&part->local_IPI_amo_va->variable),
1103 FETCHOP_STORE_OP(TO_AMO((u64) &part->local_IPI_amo_va->variable), 1029 FETCHOP_OR, ((u64)ipi_flag << (ch->number * 8)));
1104 FETCHOP_OR, ((u64) ipi_flag << (ch->number * 8)));
1105 dev_dbg(xpc_chan, "%s sent local from partid=%d, channel=%d\n", 1030 dev_dbg(xpc_chan, "%s sent local from partid=%d, channel=%d\n",
1106 ipi_flag_string, ch->partid, ch->number); 1031 ipi_flag_string, ch->partid, ch->number);
1107} 1032}
1108 1033
1109
1110/* 1034/*
1111 * The sending and receiving of IPIs includes the setting of an AMO variable 1035 * The sending and receiving of IPIs includes the setting of an AMO variable
1112 * to indicate the reason the IPI was sent. The 64-bit variable is divided 1036 * to indicate the reason the IPI was sent. The 64-bit variable is divided
@@ -1121,21 +1045,18 @@ xpc_notify_IRQ_send_local(struct xpc_channel *ch, u8 ipi_flag,
1121#define XPC_IPI_OPENREPLY 0x08 1045#define XPC_IPI_OPENREPLY 0x08
1122#define XPC_IPI_MSGREQUEST 0x10 1046#define XPC_IPI_MSGREQUEST 0x10
1123 1047
1124
1125/* given an AMO variable and a channel#, get its associated IPI flags */ 1048/* given an AMO variable and a channel#, get its associated IPI flags */
1126#define XPC_GET_IPI_FLAGS(_amo, _c) ((u8) (((_amo) >> ((_c) * 8)) & 0xff)) 1049#define XPC_GET_IPI_FLAGS(_amo, _c) ((u8) (((_amo) >> ((_c) * 8)) & 0xff))
1127#define XPC_SET_IPI_FLAGS(_amo, _c, _f) (_amo) |= ((u64) (_f) << ((_c) * 8)) 1050#define XPC_SET_IPI_FLAGS(_amo, _c, _f) (_amo) |= ((u64) (_f) << ((_c) * 8))
1128 1051
1129#define XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(_amo) ((_amo) & __IA64_UL_CONST(0x0f0f0f0f0f0f0f0f)) 1052#define XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(_amo) ((_amo) & 0x0f0f0f0f0f0f0f0fUL)
1130#define XPC_ANY_MSG_IPI_FLAGS_SET(_amo) ((_amo) & __IA64_UL_CONST(0x1010101010101010)) 1053#define XPC_ANY_MSG_IPI_FLAGS_SET(_amo) ((_amo) & 0x1010101010101010UL)
1131
1132 1054
1133static inline void 1055static inline void
1134xpc_IPI_send_closerequest(struct xpc_channel *ch, unsigned long *irq_flags) 1056xpc_IPI_send_closerequest(struct xpc_channel *ch, unsigned long *irq_flags)
1135{ 1057{
1136 struct xpc_openclose_args *args = ch->local_openclose_args; 1058 struct xpc_openclose_args *args = ch->local_openclose_args;
1137 1059
1138
1139 args->reason = ch->reason; 1060 args->reason = ch->reason;
1140 1061
1141 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREQUEST, irq_flags); 1062 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREQUEST, irq_flags);
@@ -1152,7 +1073,6 @@ xpc_IPI_send_openrequest(struct xpc_channel *ch, unsigned long *irq_flags)
1152{ 1073{
1153 struct xpc_openclose_args *args = ch->local_openclose_args; 1074 struct xpc_openclose_args *args = ch->local_openclose_args;
1154 1075
1155
1156 args->msg_size = ch->msg_size; 1076 args->msg_size = ch->msg_size;
1157 args->local_nentries = ch->local_nentries; 1077 args->local_nentries = ch->local_nentries;
1158 1078
@@ -1164,7 +1084,6 @@ xpc_IPI_send_openreply(struct xpc_channel *ch, unsigned long *irq_flags)
1164{ 1084{
1165 struct xpc_openclose_args *args = ch->local_openclose_args; 1085 struct xpc_openclose_args *args = ch->local_openclose_args;
1166 1086
1167
1168 args->remote_nentries = ch->remote_nentries; 1087 args->remote_nentries = ch->remote_nentries;
1169 args->local_nentries = ch->local_nentries; 1088 args->local_nentries = ch->local_nentries;
1170 args->local_msgqueue_pa = __pa(ch->local_msgqueue); 1089 args->local_msgqueue_pa = __pa(ch->local_msgqueue);
@@ -1184,7 +1103,6 @@ xpc_IPI_send_local_msgrequest(struct xpc_channel *ch)
1184 XPC_NOTIFY_IRQ_SEND_LOCAL(ch, XPC_IPI_MSGREQUEST); 1103 XPC_NOTIFY_IRQ_SEND_LOCAL(ch, XPC_IPI_MSGREQUEST);
1185} 1104}
1186 1105
1187
1188/* 1106/*
1189 * Memory for XPC's AMO variables is allocated by the MSPEC driver. These 1107 * Memory for XPC's AMO variables is allocated by the MSPEC driver. These
1190 * pages are located in the lowest granule. The lowest granule uses 4k pages 1108 * pages are located in the lowest granule. The lowest granule uses 4k pages
@@ -1201,13 +1119,10 @@ xpc_IPI_init(int index)
1201{ 1119{
1202 AMO_t *amo = xpc_vars->amos_page + index; 1120 AMO_t *amo = xpc_vars->amos_page + index;
1203 1121
1204 1122 (void)xpc_IPI_receive(amo); /* clear AMO variable */
1205 (void) xpc_IPI_receive(amo); /* clear AMO variable */
1206 return amo; 1123 return amo;
1207} 1124}
1208 1125
1209
1210
1211static inline enum xpc_retval 1126static inline enum xpc_retval
1212xpc_map_bte_errors(bte_result_t error) 1127xpc_map_bte_errors(bte_result_t error)
1213{ 1128{
@@ -1220,22 +1135,31 @@ xpc_map_bte_errors(bte_result_t error)
1220 return xpcBteUnmappedError; 1135 return xpcBteUnmappedError;
1221 } 1136 }
1222 switch (error) { 1137 switch (error) {
1223 case BTE_SUCCESS: return xpcSuccess; 1138 case BTE_SUCCESS:
1224 case BTEFAIL_DIR: return xpcBteDirectoryError; 1139 return xpcSuccess;
1225 case BTEFAIL_POISON: return xpcBtePoisonError; 1140 case BTEFAIL_DIR:
1226 case BTEFAIL_WERR: return xpcBteWriteError; 1141 return xpcBteDirectoryError;
1227 case BTEFAIL_ACCESS: return xpcBteAccessError; 1142 case BTEFAIL_POISON:
1228 case BTEFAIL_PWERR: return xpcBtePWriteError; 1143 return xpcBtePoisonError;
1229 case BTEFAIL_PRERR: return xpcBtePReadError; 1144 case BTEFAIL_WERR:
1230 case BTEFAIL_TOUT: return xpcBteTimeOutError; 1145 return xpcBteWriteError;
1231 case BTEFAIL_XTERR: return xpcBteXtalkError; 1146 case BTEFAIL_ACCESS:
1232 case BTEFAIL_NOTAVAIL: return xpcBteNotAvailable; 1147 return xpcBteAccessError;
1233 default: return xpcBteUnmappedError; 1148 case BTEFAIL_PWERR:
1149 return xpcBtePWriteError;
1150 case BTEFAIL_PRERR:
1151 return xpcBtePReadError;
1152 case BTEFAIL_TOUT:
1153 return xpcBteTimeOutError;
1154 case BTEFAIL_XTERR:
1155 return xpcBteXtalkError;
1156 case BTEFAIL_NOTAVAIL:
1157 return xpcBteNotAvailable;
1158 default:
1159 return xpcBteUnmappedError;
1234 } 1160 }
1235} 1161}
1236 1162
1237
1238
1239/* 1163/*
1240 * Check to see if there is any channel activity to/from the specified 1164 * Check to see if there is any channel activity to/from the specified
1241 * partition. 1165 * partition.
@@ -1246,11 +1170,9 @@ xpc_check_for_channel_activity(struct xpc_partition *part)
1246 u64 IPI_amo; 1170 u64 IPI_amo;
1247 unsigned long irq_flags; 1171 unsigned long irq_flags;
1248 1172
1249
1250 IPI_amo = xpc_IPI_receive(part->local_IPI_amo_va); 1173 IPI_amo = xpc_IPI_receive(part->local_IPI_amo_va);
1251 if (IPI_amo == 0) { 1174 if (IPI_amo == 0)
1252 return; 1175 return;
1253 }
1254 1176
1255 spin_lock_irqsave(&part->IPI_lock, irq_flags); 1177 spin_lock_irqsave(&part->IPI_lock, irq_flags);
1256 part->local_IPI_amo |= IPI_amo; 1178 part->local_IPI_amo |= IPI_amo;
@@ -1262,6 +1184,4 @@ xpc_check_for_channel_activity(struct xpc_partition *part)
1262 xpc_wakeup_channel_mgr(part); 1184 xpc_wakeup_channel_mgr(part);
1263} 1185}
1264 1186
1265 1187#endif /* _DRIVERS_MISC_SGIXP_XPC_H */
1266#endif /* _ASM_IA64_SN_XPC_H */
1267
diff --git a/arch/ia64/sn/kernel/xpc_channel.c b/drivers/misc/sgi-xp/xpc_channel.c
index 44ccc0d789c9..bfcb9ea968e9 100644
--- a/arch/ia64/sn/kernel/xpc_channel.c
+++ b/drivers/misc/sgi-xp/xpc_channel.c
@@ -3,10 +3,9 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (c) 2004-2006 Silicon Graphics, Inc. All Rights Reserved. 6 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
7 */ 7 */
8 8
9
10/* 9/*
11 * Cross Partition Communication (XPC) channel support. 10 * Cross Partition Communication (XPC) channel support.
12 * 11 *
@@ -15,7 +14,6 @@
15 * 14 *
16 */ 15 */
17 16
18
19#include <linux/kernel.h> 17#include <linux/kernel.h>
20#include <linux/init.h> 18#include <linux/init.h>
21#include <linux/sched.h> 19#include <linux/sched.h>
@@ -25,8 +23,7 @@
25#include <linux/completion.h> 23#include <linux/completion.h>
26#include <asm/sn/bte.h> 24#include <asm/sn/bte.h>
27#include <asm/sn/sn_sal.h> 25#include <asm/sn/sn_sal.h>
28#include <asm/sn/xpc.h> 26#include "xpc.h"
29
30 27
31/* 28/*
32 * Guarantee that the kzalloc'd memory is cacheline aligned. 29 * Guarantee that the kzalloc'd memory is cacheline aligned.
@@ -36,22 +33,21 @@ xpc_kzalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
36{ 33{
37 /* see if kzalloc will give us cachline aligned memory by default */ 34 /* see if kzalloc will give us cachline aligned memory by default */
38 *base = kzalloc(size, flags); 35 *base = kzalloc(size, flags);
39 if (*base == NULL) { 36 if (*base == NULL)
40 return NULL; 37 return NULL;
41 } 38
42 if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) { 39 if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
43 return *base; 40 return *base;
44 } 41
45 kfree(*base); 42 kfree(*base);
46 43
47 /* nope, we'll have to do it ourselves */ 44 /* nope, we'll have to do it ourselves */
48 *base = kzalloc(size + L1_CACHE_BYTES, flags); 45 *base = kzalloc(size + L1_CACHE_BYTES, flags);
49 if (*base == NULL) { 46 if (*base == NULL)
50 return NULL; 47 return NULL;
51 }
52 return (void *) L1_CACHE_ALIGN((u64) *base);
53}
54 48
49 return (void *)L1_CACHE_ALIGN((u64)*base);
50}
55 51
56/* 52/*
57 * Set up the initial values for the XPartition Communication channels. 53 * Set up the initial values for the XPartition Communication channels.
@@ -62,7 +58,6 @@ xpc_initialize_channels(struct xpc_partition *part, partid_t partid)
62 int ch_number; 58 int ch_number;
63 struct xpc_channel *ch; 59 struct xpc_channel *ch;
64 60
65
66 for (ch_number = 0; ch_number < part->nchannels; ch_number++) { 61 for (ch_number = 0; ch_number < part->nchannels; ch_number++) {
67 ch = &part->channels[ch_number]; 62 ch = &part->channels[ch_number];
68 63
@@ -72,7 +67,7 @@ xpc_initialize_channels(struct xpc_partition *part, partid_t partid)
72 67
73 ch->local_GP = &part->local_GPs[ch_number]; 68 ch->local_GP = &part->local_GPs[ch_number];
74 ch->local_openclose_args = 69 ch->local_openclose_args =
75 &part->local_openclose_args[ch_number]; 70 &part->local_openclose_args[ch_number];
76 71
77 atomic_set(&ch->kthreads_assigned, 0); 72 atomic_set(&ch->kthreads_assigned, 0);
78 atomic_set(&ch->kthreads_idle, 0); 73 atomic_set(&ch->kthreads_idle, 0);
@@ -91,7 +86,6 @@ xpc_initialize_channels(struct xpc_partition *part, partid_t partid)
91 } 86 }
92} 87}
93 88
94
95/* 89/*
96 * Setup the infrastructure necessary to support XPartition Communication 90 * Setup the infrastructure necessary to support XPartition Communication
97 * between the specified remote partition and the local one. 91 * between the specified remote partition and the local one.
@@ -103,7 +97,6 @@ xpc_setup_infrastructure(struct xpc_partition *part)
103 struct timer_list *timer; 97 struct timer_list *timer;
104 partid_t partid = XPC_PARTID(part); 98 partid_t partid = XPC_PARTID(part);
105 99
106
107 /* 100 /*
108 * Zero out MOST of the entry for this partition. Only the fields 101 * Zero out MOST of the entry for this partition. Only the fields
109 * starting with `nchannels' will be zeroed. The preceding fields must 102 * starting with `nchannels' will be zeroed. The preceding fields must
@@ -111,14 +104,14 @@ xpc_setup_infrastructure(struct xpc_partition *part)
111 * referenced during this memset() operation. 104 * referenced during this memset() operation.
112 */ 105 */
113 memset(&part->nchannels, 0, sizeof(struct xpc_partition) - 106 memset(&part->nchannels, 0, sizeof(struct xpc_partition) -
114 offsetof(struct xpc_partition, nchannels)); 107 offsetof(struct xpc_partition, nchannels));
115 108
116 /* 109 /*
117 * Allocate all of the channel structures as a contiguous chunk of 110 * Allocate all of the channel structures as a contiguous chunk of
118 * memory. 111 * memory.
119 */ 112 */
120 part->channels = kzalloc(sizeof(struct xpc_channel) * XPC_NCHANNELS, 113 part->channels = kzalloc(sizeof(struct xpc_channel) * XPC_NCHANNELS,
121 GFP_KERNEL); 114 GFP_KERNEL);
122 if (part->channels == NULL) { 115 if (part->channels == NULL) {
123 dev_err(xpc_chan, "can't get memory for channels\n"); 116 dev_err(xpc_chan, "can't get memory for channels\n");
124 return xpcNoMemory; 117 return xpcNoMemory;
@@ -126,11 +119,11 @@ xpc_setup_infrastructure(struct xpc_partition *part)
126 119
127 part->nchannels = XPC_NCHANNELS; 120 part->nchannels = XPC_NCHANNELS;
128 121
129
130 /* allocate all the required GET/PUT values */ 122 /* allocate all the required GET/PUT values */
131 123
132 part->local_GPs = xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE, 124 part->local_GPs = xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE,
133 GFP_KERNEL, &part->local_GPs_base); 125 GFP_KERNEL,
126 &part->local_GPs_base);
134 if (part->local_GPs == NULL) { 127 if (part->local_GPs == NULL) {
135 kfree(part->channels); 128 kfree(part->channels);
136 part->channels = NULL; 129 part->channels = NULL;
@@ -140,7 +133,9 @@ xpc_setup_infrastructure(struct xpc_partition *part)
140 } 133 }
141 134
142 part->remote_GPs = xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE, 135 part->remote_GPs = xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE,
143 GFP_KERNEL, &part->remote_GPs_base); 136 GFP_KERNEL,
137 &part->
138 remote_GPs_base);
144 if (part->remote_GPs == NULL) { 139 if (part->remote_GPs == NULL) {
145 dev_err(xpc_chan, "can't get memory for remote get/put " 140 dev_err(xpc_chan, "can't get memory for remote get/put "
146 "values\n"); 141 "values\n");
@@ -151,12 +146,11 @@ xpc_setup_infrastructure(struct xpc_partition *part)
151 return xpcNoMemory; 146 return xpcNoMemory;
152 } 147 }
153 148
154
155 /* allocate all the required open and close args */ 149 /* allocate all the required open and close args */
156 150
157 part->local_openclose_args = xpc_kzalloc_cacheline_aligned( 151 part->local_openclose_args =
158 XPC_OPENCLOSE_ARGS_SIZE, GFP_KERNEL, 152 xpc_kzalloc_cacheline_aligned(XPC_OPENCLOSE_ARGS_SIZE, GFP_KERNEL,
159 &part->local_openclose_args_base); 153 &part->local_openclose_args_base);
160 if (part->local_openclose_args == NULL) { 154 if (part->local_openclose_args == NULL) {
161 dev_err(xpc_chan, "can't get memory for local connect args\n"); 155 dev_err(xpc_chan, "can't get memory for local connect args\n");
162 kfree(part->remote_GPs_base); 156 kfree(part->remote_GPs_base);
@@ -168,9 +162,9 @@ xpc_setup_infrastructure(struct xpc_partition *part)
168 return xpcNoMemory; 162 return xpcNoMemory;
169 } 163 }
170 164
171 part->remote_openclose_args = xpc_kzalloc_cacheline_aligned( 165 part->remote_openclose_args =
172 XPC_OPENCLOSE_ARGS_SIZE, GFP_KERNEL, 166 xpc_kzalloc_cacheline_aligned(XPC_OPENCLOSE_ARGS_SIZE, GFP_KERNEL,
173 &part->remote_openclose_args_base); 167 &part->remote_openclose_args_base);
174 if (part->remote_openclose_args == NULL) { 168 if (part->remote_openclose_args == NULL) {
175 dev_err(xpc_chan, "can't get memory for remote connect args\n"); 169 dev_err(xpc_chan, "can't get memory for remote connect args\n");
176 kfree(part->local_openclose_args_base); 170 kfree(part->local_openclose_args_base);
@@ -184,13 +178,11 @@ xpc_setup_infrastructure(struct xpc_partition *part)
184 return xpcNoMemory; 178 return xpcNoMemory;
185 } 179 }
186 180
187
188 xpc_initialize_channels(part, partid); 181 xpc_initialize_channels(part, partid);
189 182
190 atomic_set(&part->nchannels_active, 0); 183 atomic_set(&part->nchannels_active, 0);
191 atomic_set(&part->nchannels_engaged, 0); 184 atomic_set(&part->nchannels_engaged, 0);
192 185
193
194 /* local_IPI_amo were set to 0 by an earlier memset() */ 186 /* local_IPI_amo were set to 0 by an earlier memset() */
195 187
196 /* Initialize this partitions AMO_t structure */ 188 /* Initialize this partitions AMO_t structure */
@@ -203,7 +195,7 @@ xpc_setup_infrastructure(struct xpc_partition *part)
203 195
204 sprintf(part->IPI_owner, "xpc%02d", partid); 196 sprintf(part->IPI_owner, "xpc%02d", partid);
205 ret = request_irq(SGI_XPC_NOTIFY, xpc_notify_IRQ_handler, IRQF_SHARED, 197 ret = request_irq(SGI_XPC_NOTIFY, xpc_notify_IRQ_handler, IRQF_SHARED,
206 part->IPI_owner, (void *) (u64) partid); 198 part->IPI_owner, (void *)(u64)partid);
207 if (ret != 0) { 199 if (ret != 0) {
208 dev_err(xpc_chan, "can't register NOTIFY IRQ handler, " 200 dev_err(xpc_chan, "can't register NOTIFY IRQ handler, "
209 "errno=%d\n", -ret); 201 "errno=%d\n", -ret);
@@ -223,8 +215,8 @@ xpc_setup_infrastructure(struct xpc_partition *part)
223 /* Setup a timer to check for dropped IPIs */ 215 /* Setup a timer to check for dropped IPIs */
224 timer = &part->dropped_IPI_timer; 216 timer = &part->dropped_IPI_timer;
225 init_timer(timer); 217 init_timer(timer);
226 timer->function = (void (*)(unsigned long)) xpc_dropped_IPI_check; 218 timer->function = (void (*)(unsigned long))xpc_dropped_IPI_check;
227 timer->data = (unsigned long) part; 219 timer->data = (unsigned long)part;
228 timer->expires = jiffies + XPC_P_DROPPED_IPI_WAIT; 220 timer->expires = jiffies + XPC_P_DROPPED_IPI_WAIT;
229 add_timer(timer); 221 add_timer(timer);
230 222
@@ -234,7 +226,6 @@ xpc_setup_infrastructure(struct xpc_partition *part)
234 */ 226 */
235 part->setup_state = XPC_P_SETUP; 227 part->setup_state = XPC_P_SETUP;
236 228
237
238 /* 229 /*
239 * Setup the per partition specific variables required by the 230 * Setup the per partition specific variables required by the
240 * remote partition to establish channel connections with us. 231 * remote partition to establish channel connections with us.
@@ -244,7 +235,7 @@ xpc_setup_infrastructure(struct xpc_partition *part)
244 */ 235 */
245 xpc_vars_part[partid].GPs_pa = __pa(part->local_GPs); 236 xpc_vars_part[partid].GPs_pa = __pa(part->local_GPs);
246 xpc_vars_part[partid].openclose_args_pa = 237 xpc_vars_part[partid].openclose_args_pa =
247 __pa(part->local_openclose_args); 238 __pa(part->local_openclose_args);
248 xpc_vars_part[partid].IPI_amo_pa = __pa(part->local_IPI_amo_va); 239 xpc_vars_part[partid].IPI_amo_pa = __pa(part->local_IPI_amo_va);
249 cpuid = raw_smp_processor_id(); /* any CPU in this partition will do */ 240 cpuid = raw_smp_processor_id(); /* any CPU in this partition will do */
250 xpc_vars_part[partid].IPI_nasid = cpuid_to_nasid(cpuid); 241 xpc_vars_part[partid].IPI_nasid = cpuid_to_nasid(cpuid);
@@ -255,7 +246,6 @@ xpc_setup_infrastructure(struct xpc_partition *part)
255 return xpcSuccess; 246 return xpcSuccess;
256} 247}
257 248
258
259/* 249/*
260 * Create a wrapper that hides the underlying mechanism for pulling a cacheline 250 * Create a wrapper that hides the underlying mechanism for pulling a cacheline
261 * (or multiple cachelines) from a remote partition. 251 * (or multiple cachelines) from a remote partition.
@@ -266,24 +256,21 @@ xpc_setup_infrastructure(struct xpc_partition *part)
266 */ 256 */
267static enum xpc_retval 257static enum xpc_retval
268xpc_pull_remote_cachelines(struct xpc_partition *part, void *dst, 258xpc_pull_remote_cachelines(struct xpc_partition *part, void *dst,
269 const void *src, size_t cnt) 259 const void *src, size_t cnt)
270{ 260{
271 bte_result_t bte_ret; 261 bte_result_t bte_ret;
272 262
273 263 DBUG_ON((u64)src != L1_CACHE_ALIGN((u64)src));
274 DBUG_ON((u64) src != L1_CACHE_ALIGN((u64) src)); 264 DBUG_ON((u64)dst != L1_CACHE_ALIGN((u64)dst));
275 DBUG_ON((u64) dst != L1_CACHE_ALIGN((u64) dst));
276 DBUG_ON(cnt != L1_CACHE_ALIGN(cnt)); 265 DBUG_ON(cnt != L1_CACHE_ALIGN(cnt));
277 266
278 if (part->act_state == XPC_P_DEACTIVATING) { 267 if (part->act_state == XPC_P_DEACTIVATING)
279 return part->reason; 268 return part->reason;
280 }
281 269
282 bte_ret = xp_bte_copy((u64) src, (u64) dst, (u64) cnt, 270 bte_ret = xp_bte_copy((u64)src, (u64)dst, (u64)cnt,
283 (BTE_NORMAL | BTE_WACQUIRE), NULL); 271 (BTE_NORMAL | BTE_WACQUIRE), NULL);
284 if (bte_ret == BTE_SUCCESS) { 272 if (bte_ret == BTE_SUCCESS)
285 return xpcSuccess; 273 return xpcSuccess;
286 }
287 274
288 dev_dbg(xpc_chan, "xp_bte_copy() from partition %d failed, ret=%d\n", 275 dev_dbg(xpc_chan, "xp_bte_copy() from partition %d failed, ret=%d\n",
289 XPC_PARTID(part), bte_ret); 276 XPC_PARTID(part), bte_ret);
@@ -291,7 +278,6 @@ xpc_pull_remote_cachelines(struct xpc_partition *part, void *dst,
291 return xpc_map_bte_errors(bte_ret); 278 return xpc_map_bte_errors(bte_ret);
292} 279}
293 280
294
295/* 281/*
296 * Pull the remote per partition specific variables from the specified 282 * Pull the remote per partition specific variables from the specified
297 * partition. 283 * partition.
@@ -301,41 +287,40 @@ xpc_pull_remote_vars_part(struct xpc_partition *part)
301{ 287{
302 u8 buffer[L1_CACHE_BYTES * 2]; 288 u8 buffer[L1_CACHE_BYTES * 2];
303 struct xpc_vars_part *pulled_entry_cacheline = 289 struct xpc_vars_part *pulled_entry_cacheline =
304 (struct xpc_vars_part *) L1_CACHE_ALIGN((u64) buffer); 290 (struct xpc_vars_part *)L1_CACHE_ALIGN((u64)buffer);
305 struct xpc_vars_part *pulled_entry; 291 struct xpc_vars_part *pulled_entry;
306 u64 remote_entry_cacheline_pa, remote_entry_pa; 292 u64 remote_entry_cacheline_pa, remote_entry_pa;
307 partid_t partid = XPC_PARTID(part); 293 partid_t partid = XPC_PARTID(part);
308 enum xpc_retval ret; 294 enum xpc_retval ret;
309 295
310
311 /* pull the cacheline that contains the variables we're interested in */ 296 /* pull the cacheline that contains the variables we're interested in */
312 297
313 DBUG_ON(part->remote_vars_part_pa != 298 DBUG_ON(part->remote_vars_part_pa !=
314 L1_CACHE_ALIGN(part->remote_vars_part_pa)); 299 L1_CACHE_ALIGN(part->remote_vars_part_pa));
315 DBUG_ON(sizeof(struct xpc_vars_part) != L1_CACHE_BYTES / 2); 300 DBUG_ON(sizeof(struct xpc_vars_part) != L1_CACHE_BYTES / 2);
316 301
317 remote_entry_pa = part->remote_vars_part_pa + 302 remote_entry_pa = part->remote_vars_part_pa +
318 sn_partition_id * sizeof(struct xpc_vars_part); 303 sn_partition_id * sizeof(struct xpc_vars_part);
319 304
320 remote_entry_cacheline_pa = (remote_entry_pa & ~(L1_CACHE_BYTES - 1)); 305 remote_entry_cacheline_pa = (remote_entry_pa & ~(L1_CACHE_BYTES - 1));
321 306
322 pulled_entry = (struct xpc_vars_part *) ((u64) pulled_entry_cacheline + 307 pulled_entry = (struct xpc_vars_part *)((u64)pulled_entry_cacheline +
323 (remote_entry_pa & (L1_CACHE_BYTES - 1))); 308 (remote_entry_pa &
309 (L1_CACHE_BYTES - 1)));
324 310
325 ret = xpc_pull_remote_cachelines(part, pulled_entry_cacheline, 311 ret = xpc_pull_remote_cachelines(part, pulled_entry_cacheline,
326 (void *) remote_entry_cacheline_pa, 312 (void *)remote_entry_cacheline_pa,
327 L1_CACHE_BYTES); 313 L1_CACHE_BYTES);
328 if (ret != xpcSuccess) { 314 if (ret != xpcSuccess) {
329 dev_dbg(xpc_chan, "failed to pull XPC vars_part from " 315 dev_dbg(xpc_chan, "failed to pull XPC vars_part from "
330 "partition %d, ret=%d\n", partid, ret); 316 "partition %d, ret=%d\n", partid, ret);
331 return ret; 317 return ret;
332 } 318 }
333 319
334
335 /* see if they've been set up yet */ 320 /* see if they've been set up yet */
336 321
337 if (pulled_entry->magic != XPC_VP_MAGIC1 && 322 if (pulled_entry->magic != XPC_VP_MAGIC1 &&
338 pulled_entry->magic != XPC_VP_MAGIC2) { 323 pulled_entry->magic != XPC_VP_MAGIC2) {
339 324
340 if (pulled_entry->magic != 0) { 325 if (pulled_entry->magic != 0) {
341 dev_dbg(xpc_chan, "partition %d's XPC vars_part for " 326 dev_dbg(xpc_chan, "partition %d's XPC vars_part for "
@@ -353,8 +338,8 @@ xpc_pull_remote_vars_part(struct xpc_partition *part)
353 /* validate the variables */ 338 /* validate the variables */
354 339
355 if (pulled_entry->GPs_pa == 0 || 340 if (pulled_entry->GPs_pa == 0 ||
356 pulled_entry->openclose_args_pa == 0 || 341 pulled_entry->openclose_args_pa == 0 ||
357 pulled_entry->IPI_amo_pa == 0) { 342 pulled_entry->IPI_amo_pa == 0) {
358 343
359 dev_err(xpc_chan, "partition %d's XPC vars_part for " 344 dev_err(xpc_chan, "partition %d's XPC vars_part for "
360 "partition %d are not valid\n", partid, 345 "partition %d are not valid\n", partid,
@@ -366,29 +351,26 @@ xpc_pull_remote_vars_part(struct xpc_partition *part)
366 351
367 part->remote_GPs_pa = pulled_entry->GPs_pa; 352 part->remote_GPs_pa = pulled_entry->GPs_pa;
368 part->remote_openclose_args_pa = 353 part->remote_openclose_args_pa =
369 pulled_entry->openclose_args_pa; 354 pulled_entry->openclose_args_pa;
370 part->remote_IPI_amo_va = 355 part->remote_IPI_amo_va =
371 (AMO_t *) __va(pulled_entry->IPI_amo_pa); 356 (AMO_t *)__va(pulled_entry->IPI_amo_pa);
372 part->remote_IPI_nasid = pulled_entry->IPI_nasid; 357 part->remote_IPI_nasid = pulled_entry->IPI_nasid;
373 part->remote_IPI_phys_cpuid = pulled_entry->IPI_phys_cpuid; 358 part->remote_IPI_phys_cpuid = pulled_entry->IPI_phys_cpuid;
374 359
375 if (part->nchannels > pulled_entry->nchannels) { 360 if (part->nchannels > pulled_entry->nchannels)
376 part->nchannels = pulled_entry->nchannels; 361 part->nchannels = pulled_entry->nchannels;
377 }
378 362
379 /* let the other side know that we've pulled their variables */ 363 /* let the other side know that we've pulled their variables */
380 364
381 xpc_vars_part[partid].magic = XPC_VP_MAGIC2; 365 xpc_vars_part[partid].magic = XPC_VP_MAGIC2;
382 } 366 }
383 367
384 if (pulled_entry->magic == XPC_VP_MAGIC1) { 368 if (pulled_entry->magic == XPC_VP_MAGIC1)
385 return xpcRetry; 369 return xpcRetry;
386 }
387 370
388 return xpcSuccess; 371 return xpcSuccess;
389} 372}
390 373
391
392/* 374/*
393 * Get the IPI flags and pull the openclose args and/or remote GPs as needed. 375 * Get the IPI flags and pull the openclose args and/or remote GPs as needed.
394 */ 376 */
@@ -399,23 +381,23 @@ xpc_get_IPI_flags(struct xpc_partition *part)
399 u64 IPI_amo; 381 u64 IPI_amo;
400 enum xpc_retval ret; 382 enum xpc_retval ret;
401 383
402
403 /* 384 /*
404 * See if there are any IPI flags to be handled. 385 * See if there are any IPI flags to be handled.
405 */ 386 */
406 387
407 spin_lock_irqsave(&part->IPI_lock, irq_flags); 388 spin_lock_irqsave(&part->IPI_lock, irq_flags);
408 if ((IPI_amo = part->local_IPI_amo) != 0) { 389 IPI_amo = part->local_IPI_amo;
390 if (IPI_amo != 0)
409 part->local_IPI_amo = 0; 391 part->local_IPI_amo = 0;
410 }
411 spin_unlock_irqrestore(&part->IPI_lock, irq_flags);
412 392
393 spin_unlock_irqrestore(&part->IPI_lock, irq_flags);
413 394
414 if (XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(IPI_amo)) { 395 if (XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(IPI_amo)) {
415 ret = xpc_pull_remote_cachelines(part, 396 ret = xpc_pull_remote_cachelines(part,
416 part->remote_openclose_args, 397 part->remote_openclose_args,
417 (void *) part->remote_openclose_args_pa, 398 (void *)part->
418 XPC_OPENCLOSE_ARGS_SIZE); 399 remote_openclose_args_pa,
400 XPC_OPENCLOSE_ARGS_SIZE);
419 if (ret != xpcSuccess) { 401 if (ret != xpcSuccess) {
420 XPC_DEACTIVATE_PARTITION(part, ret); 402 XPC_DEACTIVATE_PARTITION(part, ret);
421 403
@@ -430,8 +412,8 @@ xpc_get_IPI_flags(struct xpc_partition *part)
430 412
431 if (XPC_ANY_MSG_IPI_FLAGS_SET(IPI_amo)) { 413 if (XPC_ANY_MSG_IPI_FLAGS_SET(IPI_amo)) {
432 ret = xpc_pull_remote_cachelines(part, part->remote_GPs, 414 ret = xpc_pull_remote_cachelines(part, part->remote_GPs,
433 (void *) part->remote_GPs_pa, 415 (void *)part->remote_GPs_pa,
434 XPC_GP_SIZE); 416 XPC_GP_SIZE);
435 if (ret != xpcSuccess) { 417 if (ret != xpcSuccess) {
436 XPC_DEACTIVATE_PARTITION(part, ret); 418 XPC_DEACTIVATE_PARTITION(part, ret);
437 419
@@ -446,7 +428,6 @@ xpc_get_IPI_flags(struct xpc_partition *part)
446 return IPI_amo; 428 return IPI_amo;
447} 429}
448 430
449
450/* 431/*
451 * Allocate the local message queue and the notify queue. 432 * Allocate the local message queue and the notify queue.
452 */ 433 */
@@ -457,20 +438,14 @@ xpc_allocate_local_msgqueue(struct xpc_channel *ch)
457 int nentries; 438 int nentries;
458 size_t nbytes; 439 size_t nbytes;
459 440
460
461 // >>> may want to check for ch->flags & XPC_C_DISCONNECTING between
462 // >>> iterations of the for-loop, bail if set?
463
464 // >>> should we impose a minimum #of entries? like 4 or 8?
465 for (nentries = ch->local_nentries; nentries > 0; nentries--) { 441 for (nentries = ch->local_nentries; nentries > 0; nentries--) {
466 442
467 nbytes = nentries * ch->msg_size; 443 nbytes = nentries * ch->msg_size;
468 ch->local_msgqueue = xpc_kzalloc_cacheline_aligned(nbytes, 444 ch->local_msgqueue = xpc_kzalloc_cacheline_aligned(nbytes,
469 GFP_KERNEL, 445 GFP_KERNEL,
470 &ch->local_msgqueue_base); 446 &ch->local_msgqueue_base);
471 if (ch->local_msgqueue == NULL) { 447 if (ch->local_msgqueue == NULL)
472 continue; 448 continue;
473 }
474 449
475 nbytes = nentries * sizeof(struct xpc_notify); 450 nbytes = nentries * sizeof(struct xpc_notify);
476 ch->notify_queue = kzalloc(nbytes, GFP_KERNEL); 451 ch->notify_queue = kzalloc(nbytes, GFP_KERNEL);
@@ -497,7 +472,6 @@ xpc_allocate_local_msgqueue(struct xpc_channel *ch)
497 return xpcNoMemory; 472 return xpcNoMemory;
498} 473}
499 474
500
501/* 475/*
502 * Allocate the cached remote message queue. 476 * Allocate the cached remote message queue.
503 */ 477 */
@@ -508,22 +482,16 @@ xpc_allocate_remote_msgqueue(struct xpc_channel *ch)
508 int nentries; 482 int nentries;
509 size_t nbytes; 483 size_t nbytes;
510 484
511
512 DBUG_ON(ch->remote_nentries <= 0); 485 DBUG_ON(ch->remote_nentries <= 0);
513 486
514 // >>> may want to check for ch->flags & XPC_C_DISCONNECTING between
515 // >>> iterations of the for-loop, bail if set?
516
517 // >>> should we impose a minimum #of entries? like 4 or 8?
518 for (nentries = ch->remote_nentries; nentries > 0; nentries--) { 487 for (nentries = ch->remote_nentries; nentries > 0; nentries--) {
519 488
520 nbytes = nentries * ch->msg_size; 489 nbytes = nentries * ch->msg_size;
521 ch->remote_msgqueue = xpc_kzalloc_cacheline_aligned(nbytes, 490 ch->remote_msgqueue = xpc_kzalloc_cacheline_aligned(nbytes,
522 GFP_KERNEL, 491 GFP_KERNEL,
523 &ch->remote_msgqueue_base); 492 &ch->remote_msgqueue_base);
524 if (ch->remote_msgqueue == NULL) { 493 if (ch->remote_msgqueue == NULL)
525 continue; 494 continue;
526 }
527 495
528 spin_lock_irqsave(&ch->lock, irq_flags); 496 spin_lock_irqsave(&ch->lock, irq_flags);
529 if (nentries < ch->remote_nentries) { 497 if (nentries < ch->remote_nentries) {
@@ -542,7 +510,6 @@ xpc_allocate_remote_msgqueue(struct xpc_channel *ch)
542 return xpcNoMemory; 510 return xpcNoMemory;
543} 511}
544 512
545
546/* 513/*
547 * Allocate message queues and other stuff associated with a channel. 514 * Allocate message queues and other stuff associated with a channel.
548 * 515 *
@@ -554,14 +521,14 @@ xpc_allocate_msgqueues(struct xpc_channel *ch)
554 unsigned long irq_flags; 521 unsigned long irq_flags;
555 enum xpc_retval ret; 522 enum xpc_retval ret;
556 523
557
558 DBUG_ON(ch->flags & XPC_C_SETUP); 524 DBUG_ON(ch->flags & XPC_C_SETUP);
559 525
560 if ((ret = xpc_allocate_local_msgqueue(ch)) != xpcSuccess) { 526 ret = xpc_allocate_local_msgqueue(ch);
527 if (ret != xpcSuccess)
561 return ret; 528 return ret;
562 }
563 529
564 if ((ret = xpc_allocate_remote_msgqueue(ch)) != xpcSuccess) { 530 ret = xpc_allocate_remote_msgqueue(ch);
531 if (ret != xpcSuccess) {
565 kfree(ch->local_msgqueue_base); 532 kfree(ch->local_msgqueue_base);
566 ch->local_msgqueue = NULL; 533 ch->local_msgqueue = NULL;
567 kfree(ch->notify_queue); 534 kfree(ch->notify_queue);
@@ -576,7 +543,6 @@ xpc_allocate_msgqueues(struct xpc_channel *ch)
576 return xpcSuccess; 543 return xpcSuccess;
577} 544}
578 545
579
580/* 546/*
581 * Process a connect message from a remote partition. 547 * Process a connect message from a remote partition.
582 * 548 *
@@ -588,11 +554,10 @@ xpc_process_connect(struct xpc_channel *ch, unsigned long *irq_flags)
588{ 554{
589 enum xpc_retval ret; 555 enum xpc_retval ret;
590 556
591
592 DBUG_ON(!spin_is_locked(&ch->lock)); 557 DBUG_ON(!spin_is_locked(&ch->lock));
593 558
594 if (!(ch->flags & XPC_C_OPENREQUEST) || 559 if (!(ch->flags & XPC_C_OPENREQUEST) ||
595 !(ch->flags & XPC_C_ROPENREQUEST)) { 560 !(ch->flags & XPC_C_ROPENREQUEST)) {
596 /* nothing more to do for now */ 561 /* nothing more to do for now */
597 return; 562 return;
598 } 563 }
@@ -603,12 +568,11 @@ xpc_process_connect(struct xpc_channel *ch, unsigned long *irq_flags)
603 ret = xpc_allocate_msgqueues(ch); 568 ret = xpc_allocate_msgqueues(ch);
604 spin_lock_irqsave(&ch->lock, *irq_flags); 569 spin_lock_irqsave(&ch->lock, *irq_flags);
605 570
606 if (ret != xpcSuccess) { 571 if (ret != xpcSuccess)
607 XPC_DISCONNECT_CHANNEL(ch, ret, irq_flags); 572 XPC_DISCONNECT_CHANNEL(ch, ret, irq_flags);
608 } 573
609 if (ch->flags & (XPC_C_CONNECTED | XPC_C_DISCONNECTING)) { 574 if (ch->flags & (XPC_C_CONNECTED | XPC_C_DISCONNECTING))
610 return; 575 return;
611 }
612 576
613 DBUG_ON(!(ch->flags & XPC_C_SETUP)); 577 DBUG_ON(!(ch->flags & XPC_C_SETUP));
614 DBUG_ON(ch->local_msgqueue == NULL); 578 DBUG_ON(ch->local_msgqueue == NULL);
@@ -620,23 +584,21 @@ xpc_process_connect(struct xpc_channel *ch, unsigned long *irq_flags)
620 xpc_IPI_send_openreply(ch, irq_flags); 584 xpc_IPI_send_openreply(ch, irq_flags);
621 } 585 }
622 586
623 if (!(ch->flags & XPC_C_ROPENREPLY)) { 587 if (!(ch->flags & XPC_C_ROPENREPLY))
624 return; 588 return;
625 }
626 589
627 DBUG_ON(ch->remote_msgqueue_pa == 0); 590 DBUG_ON(ch->remote_msgqueue_pa == 0);
628 591
629 ch->flags = (XPC_C_CONNECTED | XPC_C_SETUP); /* clear all else */ 592 ch->flags = (XPC_C_CONNECTED | XPC_C_SETUP); /* clear all else */
630 593
631 dev_info(xpc_chan, "channel %d to partition %d connected\n", 594 dev_info(xpc_chan, "channel %d to partition %d connected\n",
632 ch->number, ch->partid); 595 ch->number, ch->partid);
633 596
634 spin_unlock_irqrestore(&ch->lock, *irq_flags); 597 spin_unlock_irqrestore(&ch->lock, *irq_flags);
635 xpc_create_kthreads(ch, 1, 0); 598 xpc_create_kthreads(ch, 1, 0);
636 spin_lock_irqsave(&ch->lock, *irq_flags); 599 spin_lock_irqsave(&ch->lock, *irq_flags);
637} 600}
638 601
639
640/* 602/*
641 * Notify those who wanted to be notified upon delivery of their message. 603 * Notify those who wanted to be notified upon delivery of their message.
642 */ 604 */
@@ -647,7 +609,6 @@ xpc_notify_senders(struct xpc_channel *ch, enum xpc_retval reason, s64 put)
647 u8 notify_type; 609 u8 notify_type;
648 s64 get = ch->w_remote_GP.get - 1; 610 s64 get = ch->w_remote_GP.get - 1;
649 611
650
651 while (++get < put && atomic_read(&ch->n_to_notify) > 0) { 612 while (++get < put && atomic_read(&ch->n_to_notify) > 0) {
652 613
653 notify = &ch->notify_queue[get % ch->local_nentries]; 614 notify = &ch->notify_queue[get % ch->local_nentries];
@@ -660,8 +621,7 @@ xpc_notify_senders(struct xpc_channel *ch, enum xpc_retval reason, s64 put)
660 */ 621 */
661 notify_type = notify->type; 622 notify_type = notify->type;
662 if (notify_type == 0 || 623 if (notify_type == 0 ||
663 cmpxchg(&notify->type, notify_type, 0) != 624 cmpxchg(&notify->type, notify_type, 0) != notify_type) {
664 notify_type) {
665 continue; 625 continue;
666 } 626 }
667 627
@@ -672,20 +632,19 @@ xpc_notify_senders(struct xpc_channel *ch, enum xpc_retval reason, s64 put)
672 if (notify->func != NULL) { 632 if (notify->func != NULL) {
673 dev_dbg(xpc_chan, "notify->func() called, notify=0x%p, " 633 dev_dbg(xpc_chan, "notify->func() called, notify=0x%p, "
674 "msg_number=%ld, partid=%d, channel=%d\n", 634 "msg_number=%ld, partid=%d, channel=%d\n",
675 (void *) notify, get, ch->partid, ch->number); 635 (void *)notify, get, ch->partid, ch->number);
676 636
677 notify->func(reason, ch->partid, ch->number, 637 notify->func(reason, ch->partid, ch->number,
678 notify->key); 638 notify->key);
679 639
680 dev_dbg(xpc_chan, "notify->func() returned, " 640 dev_dbg(xpc_chan, "notify->func() returned, "
681 "notify=0x%p, msg_number=%ld, partid=%d, " 641 "notify=0x%p, msg_number=%ld, partid=%d, "
682 "channel=%d\n", (void *) notify, get, 642 "channel=%d\n", (void *)notify, get,
683 ch->partid, ch->number); 643 ch->partid, ch->number);
684 } 644 }
685 } 645 }
686} 646}
687 647
688
689/* 648/*
690 * Free up message queues and other stuff that were allocated for the specified 649 * Free up message queues and other stuff that were allocated for the specified
691 * channel. 650 * channel.
@@ -733,7 +692,6 @@ xpc_free_msgqueues(struct xpc_channel *ch)
733 } 692 }
734} 693}
735 694
736
737/* 695/*
738 * spin_lock_irqsave() is expected to be held on entry. 696 * spin_lock_irqsave() is expected to be held on entry.
739 */ 697 */
@@ -743,46 +701,41 @@ xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags)
743 struct xpc_partition *part = &xpc_partitions[ch->partid]; 701 struct xpc_partition *part = &xpc_partitions[ch->partid];
744 u32 channel_was_connected = (ch->flags & XPC_C_WASCONNECTED); 702 u32 channel_was_connected = (ch->flags & XPC_C_WASCONNECTED);
745 703
746
747 DBUG_ON(!spin_is_locked(&ch->lock)); 704 DBUG_ON(!spin_is_locked(&ch->lock));
748 705
749 if (!(ch->flags & XPC_C_DISCONNECTING)) { 706 if (!(ch->flags & XPC_C_DISCONNECTING))
750 return; 707 return;
751 }
752 708
753 DBUG_ON(!(ch->flags & XPC_C_CLOSEREQUEST)); 709 DBUG_ON(!(ch->flags & XPC_C_CLOSEREQUEST));
754 710
755 /* make sure all activity has settled down first */ 711 /* make sure all activity has settled down first */
756 712
757 if (atomic_read(&ch->kthreads_assigned) > 0 || 713 if (atomic_read(&ch->kthreads_assigned) > 0 ||
758 atomic_read(&ch->references) > 0) { 714 atomic_read(&ch->references) > 0) {
759 return; 715 return;
760 } 716 }
761 DBUG_ON((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) && 717 DBUG_ON((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
762 !(ch->flags & XPC_C_DISCONNECTINGCALLOUT_MADE)); 718 !(ch->flags & XPC_C_DISCONNECTINGCALLOUT_MADE));
763 719
764 if (part->act_state == XPC_P_DEACTIVATING) { 720 if (part->act_state == XPC_P_DEACTIVATING) {
765 /* can't proceed until the other side disengages from us */ 721 /* can't proceed until the other side disengages from us */
766 if (xpc_partition_engaged(1UL << ch->partid)) { 722 if (xpc_partition_engaged(1UL << ch->partid))
767 return; 723 return;
768 }
769 724
770 } else { 725 } else {
771 726
772 /* as long as the other side is up do the full protocol */ 727 /* as long as the other side is up do the full protocol */
773 728
774 if (!(ch->flags & XPC_C_RCLOSEREQUEST)) { 729 if (!(ch->flags & XPC_C_RCLOSEREQUEST))
775 return; 730 return;
776 }
777 731
778 if (!(ch->flags & XPC_C_CLOSEREPLY)) { 732 if (!(ch->flags & XPC_C_CLOSEREPLY)) {
779 ch->flags |= XPC_C_CLOSEREPLY; 733 ch->flags |= XPC_C_CLOSEREPLY;
780 xpc_IPI_send_closereply(ch, irq_flags); 734 xpc_IPI_send_closereply(ch, irq_flags);
781 } 735 }
782 736
783 if (!(ch->flags & XPC_C_RCLOSEREPLY)) { 737 if (!(ch->flags & XPC_C_RCLOSEREPLY))
784 return; 738 return;
785 }
786 } 739 }
787 740
788 /* wake those waiting for notify completion */ 741 /* wake those waiting for notify completion */
@@ -809,7 +762,7 @@ xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags)
809 762
810 if (channel_was_connected) { 763 if (channel_was_connected) {
811 dev_info(xpc_chan, "channel %d to partition %d disconnected, " 764 dev_info(xpc_chan, "channel %d to partition %d disconnected, "
812 "reason=%d\n", ch->number, ch->partid, ch->reason); 765 "reason=%d\n", ch->number, ch->partid, ch->reason);
813 } 766 }
814 767
815 if (ch->flags & XPC_C_WDISCONNECT) { 768 if (ch->flags & XPC_C_WDISCONNECT) {
@@ -820,35 +773,32 @@ xpc_process_disconnect(struct xpc_channel *ch, unsigned long *irq_flags)
820 /* time to take action on any delayed IPI flags */ 773 /* time to take action on any delayed IPI flags */
821 spin_lock(&part->IPI_lock); 774 spin_lock(&part->IPI_lock);
822 XPC_SET_IPI_FLAGS(part->local_IPI_amo, ch->number, 775 XPC_SET_IPI_FLAGS(part->local_IPI_amo, ch->number,
823 ch->delayed_IPI_flags); 776 ch->delayed_IPI_flags);
824 spin_unlock(&part->IPI_lock); 777 spin_unlock(&part->IPI_lock);
825 } 778 }
826 ch->delayed_IPI_flags = 0; 779 ch->delayed_IPI_flags = 0;
827 } 780 }
828} 781}
829 782
830
831/* 783/*
832 * Process a change in the channel's remote connection state. 784 * Process a change in the channel's remote connection state.
833 */ 785 */
834static void 786static void
835xpc_process_openclose_IPI(struct xpc_partition *part, int ch_number, 787xpc_process_openclose_IPI(struct xpc_partition *part, int ch_number,
836 u8 IPI_flags) 788 u8 IPI_flags)
837{ 789{
838 unsigned long irq_flags; 790 unsigned long irq_flags;
839 struct xpc_openclose_args *args = 791 struct xpc_openclose_args *args =
840 &part->remote_openclose_args[ch_number]; 792 &part->remote_openclose_args[ch_number];
841 struct xpc_channel *ch = &part->channels[ch_number]; 793 struct xpc_channel *ch = &part->channels[ch_number];
842 enum xpc_retval reason; 794 enum xpc_retval reason;
843 795
844
845
846 spin_lock_irqsave(&ch->lock, irq_flags); 796 spin_lock_irqsave(&ch->lock, irq_flags);
847 797
848again: 798again:
849 799
850 if ((ch->flags & XPC_C_DISCONNECTED) && 800 if ((ch->flags & XPC_C_DISCONNECTED) &&
851 (ch->flags & XPC_C_WDISCONNECT)) { 801 (ch->flags & XPC_C_WDISCONNECT)) {
852 /* 802 /*
853 * Delay processing IPI flags until thread waiting disconnect 803 * Delay processing IPI flags until thread waiting disconnect
854 * has had a chance to see that the channel is disconnected. 804 * has had a chance to see that the channel is disconnected.
@@ -858,7 +808,6 @@ again:
858 return; 808 return;
859 } 809 }
860 810
861
862 if (IPI_flags & XPC_IPI_CLOSEREQUEST) { 811 if (IPI_flags & XPC_IPI_CLOSEREQUEST) {
863 812
864 dev_dbg(xpc_chan, "XPC_IPI_CLOSEREQUEST (reason=%d) received " 813 dev_dbg(xpc_chan, "XPC_IPI_CLOSEREQUEST (reason=%d) received "
@@ -890,13 +839,14 @@ again:
890 if (ch->flags & XPC_C_DISCONNECTED) { 839 if (ch->flags & XPC_C_DISCONNECTED) {
891 if (!(IPI_flags & XPC_IPI_OPENREQUEST)) { 840 if (!(IPI_flags & XPC_IPI_OPENREQUEST)) {
892 if ((XPC_GET_IPI_FLAGS(part->local_IPI_amo, 841 if ((XPC_GET_IPI_FLAGS(part->local_IPI_amo,
893 ch_number) & XPC_IPI_OPENREQUEST)) { 842 ch_number) &
843 XPC_IPI_OPENREQUEST)) {
894 844
895 DBUG_ON(ch->delayed_IPI_flags != 0); 845 DBUG_ON(ch->delayed_IPI_flags != 0);
896 spin_lock(&part->IPI_lock); 846 spin_lock(&part->IPI_lock);
897 XPC_SET_IPI_FLAGS(part->local_IPI_amo, 847 XPC_SET_IPI_FLAGS(part->local_IPI_amo,
898 ch_number, 848 ch_number,
899 XPC_IPI_CLOSEREQUEST); 849 XPC_IPI_CLOSEREQUEST);
900 spin_unlock(&part->IPI_lock); 850 spin_unlock(&part->IPI_lock);
901 } 851 }
902 spin_unlock_irqrestore(&ch->lock, irq_flags); 852 spin_unlock_irqrestore(&ch->lock, irq_flags);
@@ -921,11 +871,10 @@ again:
921 871
922 if (!(ch->flags & XPC_C_DISCONNECTING)) { 872 if (!(ch->flags & XPC_C_DISCONNECTING)) {
923 reason = args->reason; 873 reason = args->reason;
924 if (reason <= xpcSuccess || reason > xpcUnknownReason) { 874 if (reason <= xpcSuccess || reason > xpcUnknownReason)
925 reason = xpcUnknownReason; 875 reason = xpcUnknownReason;
926 } else if (reason == xpcUnregistering) { 876 else if (reason == xpcUnregistering)
927 reason = xpcOtherUnregistering; 877 reason = xpcOtherUnregistering;
928 }
929 878
930 XPC_DISCONNECT_CHANNEL(ch, reason, &irq_flags); 879 XPC_DISCONNECT_CHANNEL(ch, reason, &irq_flags);
931 880
@@ -937,7 +886,6 @@ again:
937 xpc_process_disconnect(ch, &irq_flags); 886 xpc_process_disconnect(ch, &irq_flags);
938 } 887 }
939 888
940
941 if (IPI_flags & XPC_IPI_CLOSEREPLY) { 889 if (IPI_flags & XPC_IPI_CLOSEREPLY) {
942 890
943 dev_dbg(xpc_chan, "XPC_IPI_CLOSEREPLY received from partid=%d," 891 dev_dbg(xpc_chan, "XPC_IPI_CLOSEREPLY received from partid=%d,"
@@ -953,12 +901,13 @@ again:
953 901
954 if (!(ch->flags & XPC_C_RCLOSEREQUEST)) { 902 if (!(ch->flags & XPC_C_RCLOSEREQUEST)) {
955 if ((XPC_GET_IPI_FLAGS(part->local_IPI_amo, ch_number) 903 if ((XPC_GET_IPI_FLAGS(part->local_IPI_amo, ch_number)
956 & XPC_IPI_CLOSEREQUEST)) { 904 & XPC_IPI_CLOSEREQUEST)) {
957 905
958 DBUG_ON(ch->delayed_IPI_flags != 0); 906 DBUG_ON(ch->delayed_IPI_flags != 0);
959 spin_lock(&part->IPI_lock); 907 spin_lock(&part->IPI_lock);
960 XPC_SET_IPI_FLAGS(part->local_IPI_amo, 908 XPC_SET_IPI_FLAGS(part->local_IPI_amo,
961 ch_number, XPC_IPI_CLOSEREPLY); 909 ch_number,
910 XPC_IPI_CLOSEREPLY);
962 spin_unlock(&part->IPI_lock); 911 spin_unlock(&part->IPI_lock);
963 } 912 }
964 spin_unlock_irqrestore(&ch->lock, irq_flags); 913 spin_unlock_irqrestore(&ch->lock, irq_flags);
@@ -973,7 +922,6 @@ again:
973 } 922 }
974 } 923 }
975 924
976
977 if (IPI_flags & XPC_IPI_OPENREQUEST) { 925 if (IPI_flags & XPC_IPI_OPENREQUEST) {
978 926
979 dev_dbg(xpc_chan, "XPC_IPI_OPENREQUEST (msg_size=%d, " 927 dev_dbg(xpc_chan, "XPC_IPI_OPENREQUEST (msg_size=%d, "
@@ -982,7 +930,7 @@ again:
982 ch->partid, ch->number); 930 ch->partid, ch->number);
983 931
984 if (part->act_state == XPC_P_DEACTIVATING || 932 if (part->act_state == XPC_P_DEACTIVATING ||
985 (ch->flags & XPC_C_ROPENREQUEST)) { 933 (ch->flags & XPC_C_ROPENREQUEST)) {
986 spin_unlock_irqrestore(&ch->lock, irq_flags); 934 spin_unlock_irqrestore(&ch->lock, irq_flags);
987 return; 935 return;
988 } 936 }
@@ -993,9 +941,9 @@ again:
993 return; 941 return;
994 } 942 }
995 DBUG_ON(!(ch->flags & (XPC_C_DISCONNECTED | 943 DBUG_ON(!(ch->flags & (XPC_C_DISCONNECTED |
996 XPC_C_OPENREQUEST))); 944 XPC_C_OPENREQUEST)));
997 DBUG_ON(ch->flags & (XPC_C_ROPENREQUEST | XPC_C_ROPENREPLY | 945 DBUG_ON(ch->flags & (XPC_C_ROPENREQUEST | XPC_C_ROPENREPLY |
998 XPC_C_OPENREPLY | XPC_C_CONNECTED)); 946 XPC_C_OPENREPLY | XPC_C_CONNECTED));
999 947
1000 /* 948 /*
1001 * The meaningful OPENREQUEST connection state fields are: 949 * The meaningful OPENREQUEST connection state fields are:
@@ -1011,11 +959,10 @@ again:
1011 ch->flags |= (XPC_C_ROPENREQUEST | XPC_C_CONNECTING); 959 ch->flags |= (XPC_C_ROPENREQUEST | XPC_C_CONNECTING);
1012 ch->remote_nentries = args->local_nentries; 960 ch->remote_nentries = args->local_nentries;
1013 961
1014
1015 if (ch->flags & XPC_C_OPENREQUEST) { 962 if (ch->flags & XPC_C_OPENREQUEST) {
1016 if (args->msg_size != ch->msg_size) { 963 if (args->msg_size != ch->msg_size) {
1017 XPC_DISCONNECT_CHANNEL(ch, xpcUnequalMsgSizes, 964 XPC_DISCONNECT_CHANNEL(ch, xpcUnequalMsgSizes,
1018 &irq_flags); 965 &irq_flags);
1019 spin_unlock_irqrestore(&ch->lock, irq_flags); 966 spin_unlock_irqrestore(&ch->lock, irq_flags);
1020 return; 967 return;
1021 } 968 }
@@ -1031,7 +978,6 @@ again:
1031 xpc_process_connect(ch, &irq_flags); 978 xpc_process_connect(ch, &irq_flags);
1032 } 979 }
1033 980
1034
1035 if (IPI_flags & XPC_IPI_OPENREPLY) { 981 if (IPI_flags & XPC_IPI_OPENREPLY) {
1036 982
1037 dev_dbg(xpc_chan, "XPC_IPI_OPENREPLY (local_msgqueue_pa=0x%lx, " 983 dev_dbg(xpc_chan, "XPC_IPI_OPENREPLY (local_msgqueue_pa=0x%lx, "
@@ -1046,7 +992,7 @@ again:
1046 } 992 }
1047 if (!(ch->flags & XPC_C_OPENREQUEST)) { 993 if (!(ch->flags & XPC_C_OPENREQUEST)) {
1048 XPC_DISCONNECT_CHANNEL(ch, xpcOpenCloseError, 994 XPC_DISCONNECT_CHANNEL(ch, xpcOpenCloseError,
1049 &irq_flags); 995 &irq_flags);
1050 spin_unlock_irqrestore(&ch->lock, irq_flags); 996 spin_unlock_irqrestore(&ch->lock, irq_flags);
1051 return; 997 return;
1052 } 998 }
@@ -1057,7 +1003,7 @@ again:
1057 /* 1003 /*
1058 * The meaningful OPENREPLY connection state fields are: 1004 * The meaningful OPENREPLY connection state fields are:
1059 * local_msgqueue_pa = physical address of remote 1005 * local_msgqueue_pa = physical address of remote
1060 * partition's local_msgqueue 1006 * partition's local_msgqueue
1061 * local_nentries = remote partition's local_nentries 1007 * local_nentries = remote partition's local_nentries
1062 * remote_nentries = remote partition's remote_nentries 1008 * remote_nentries = remote partition's remote_nentries
1063 */ 1009 */
@@ -1093,7 +1039,6 @@ again:
1093 spin_unlock_irqrestore(&ch->lock, irq_flags); 1039 spin_unlock_irqrestore(&ch->lock, irq_flags);
1094} 1040}
1095 1041
1096
1097/* 1042/*
1098 * Attempt to establish a channel connection to a remote partition. 1043 * Attempt to establish a channel connection to a remote partition.
1099 */ 1044 */
@@ -1103,10 +1048,8 @@ xpc_connect_channel(struct xpc_channel *ch)
1103 unsigned long irq_flags; 1048 unsigned long irq_flags;
1104 struct xpc_registration *registration = &xpc_registrations[ch->number]; 1049 struct xpc_registration *registration = &xpc_registrations[ch->number];
1105 1050
1106 1051 if (mutex_trylock(&registration->mutex) == 0)
1107 if (mutex_trylock(&registration->mutex) == 0) {
1108 return xpcRetry; 1052 return xpcRetry;
1109 }
1110 1053
1111 if (!XPC_CHANNEL_REGISTERED(ch->number)) { 1054 if (!XPC_CHANNEL_REGISTERED(ch->number)) {
1112 mutex_unlock(&registration->mutex); 1055 mutex_unlock(&registration->mutex);
@@ -1124,7 +1067,6 @@ xpc_connect_channel(struct xpc_channel *ch)
1124 return ch->reason; 1067 return ch->reason;
1125 } 1068 }
1126 1069
1127
1128 /* add info from the channel connect registration to the channel */ 1070 /* add info from the channel connect registration to the channel */
1129 1071
1130 ch->kthreads_assigned_limit = registration->assigned_limit; 1072 ch->kthreads_assigned_limit = registration->assigned_limit;
@@ -1154,7 +1096,7 @@ xpc_connect_channel(struct xpc_channel *ch)
1154 */ 1096 */
1155 mutex_unlock(&registration->mutex); 1097 mutex_unlock(&registration->mutex);
1156 XPC_DISCONNECT_CHANNEL(ch, xpcUnequalMsgSizes, 1098 XPC_DISCONNECT_CHANNEL(ch, xpcUnequalMsgSizes,
1157 &irq_flags); 1099 &irq_flags);
1158 spin_unlock_irqrestore(&ch->lock, irq_flags); 1100 spin_unlock_irqrestore(&ch->lock, irq_flags);
1159 return xpcUnequalMsgSizes; 1101 return xpcUnequalMsgSizes;
1160 } 1102 }
@@ -1169,7 +1111,6 @@ xpc_connect_channel(struct xpc_channel *ch)
1169 1111
1170 mutex_unlock(&registration->mutex); 1112 mutex_unlock(&registration->mutex);
1171 1113
1172
1173 /* initiate the connection */ 1114 /* initiate the connection */
1174 1115
1175 ch->flags |= (XPC_C_OPENREQUEST | XPC_C_CONNECTING); 1116 ch->flags |= (XPC_C_OPENREQUEST | XPC_C_CONNECTING);
@@ -1182,7 +1123,6 @@ xpc_connect_channel(struct xpc_channel *ch)
1182 return xpcSuccess; 1123 return xpcSuccess;
1183} 1124}
1184 1125
1185
1186/* 1126/*
1187 * Clear some of the msg flags in the local message queue. 1127 * Clear some of the msg flags in the local message queue.
1188 */ 1128 */
@@ -1192,16 +1132,15 @@ xpc_clear_local_msgqueue_flags(struct xpc_channel *ch)
1192 struct xpc_msg *msg; 1132 struct xpc_msg *msg;
1193 s64 get; 1133 s64 get;
1194 1134
1195
1196 get = ch->w_remote_GP.get; 1135 get = ch->w_remote_GP.get;
1197 do { 1136 do {
1198 msg = (struct xpc_msg *) ((u64) ch->local_msgqueue + 1137 msg = (struct xpc_msg *)((u64)ch->local_msgqueue +
1199 (get % ch->local_nentries) * ch->msg_size); 1138 (get % ch->local_nentries) *
1139 ch->msg_size);
1200 msg->flags = 0; 1140 msg->flags = 0;
1201 } while (++get < (volatile s64) ch->remote_GP.get); 1141 } while (++get < ch->remote_GP.get);
1202} 1142}
1203 1143
1204
1205/* 1144/*
1206 * Clear some of the msg flags in the remote message queue. 1145 * Clear some of the msg flags in the remote message queue.
1207 */ 1146 */
@@ -1211,43 +1150,39 @@ xpc_clear_remote_msgqueue_flags(struct xpc_channel *ch)
1211 struct xpc_msg *msg; 1150 struct xpc_msg *msg;
1212 s64 put; 1151 s64 put;
1213 1152
1214
1215 put = ch->w_remote_GP.put; 1153 put = ch->w_remote_GP.put;
1216 do { 1154 do {
1217 msg = (struct xpc_msg *) ((u64) ch->remote_msgqueue + 1155 msg = (struct xpc_msg *)((u64)ch->remote_msgqueue +
1218 (put % ch->remote_nentries) * ch->msg_size); 1156 (put % ch->remote_nentries) *
1157 ch->msg_size);
1219 msg->flags = 0; 1158 msg->flags = 0;
1220 } while (++put < (volatile s64) ch->remote_GP.put); 1159 } while (++put < ch->remote_GP.put);
1221} 1160}
1222 1161
1223
1224static void 1162static void
1225xpc_process_msg_IPI(struct xpc_partition *part, int ch_number) 1163xpc_process_msg_IPI(struct xpc_partition *part, int ch_number)
1226{ 1164{
1227 struct xpc_channel *ch = &part->channels[ch_number]; 1165 struct xpc_channel *ch = &part->channels[ch_number];
1228 int nmsgs_sent; 1166 int nmsgs_sent;
1229 1167
1230
1231 ch->remote_GP = part->remote_GPs[ch_number]; 1168 ch->remote_GP = part->remote_GPs[ch_number];
1232 1169
1233
1234 /* See what, if anything, has changed for each connected channel */ 1170 /* See what, if anything, has changed for each connected channel */
1235 1171
1236 xpc_msgqueue_ref(ch); 1172 xpc_msgqueue_ref(ch);
1237 1173
1238 if (ch->w_remote_GP.get == ch->remote_GP.get && 1174 if (ch->w_remote_GP.get == ch->remote_GP.get &&
1239 ch->w_remote_GP.put == ch->remote_GP.put) { 1175 ch->w_remote_GP.put == ch->remote_GP.put) {
1240 /* nothing changed since GPs were last pulled */ 1176 /* nothing changed since GPs were last pulled */
1241 xpc_msgqueue_deref(ch); 1177 xpc_msgqueue_deref(ch);
1242 return; 1178 return;
1243 } 1179 }
1244 1180
1245 if (!(ch->flags & XPC_C_CONNECTED)){ 1181 if (!(ch->flags & XPC_C_CONNECTED)) {
1246 xpc_msgqueue_deref(ch); 1182 xpc_msgqueue_deref(ch);
1247 return; 1183 return;
1248 } 1184 }
1249 1185
1250
1251 /* 1186 /*
1252 * First check to see if messages recently sent by us have been 1187 * First check to see if messages recently sent by us have been
1253 * received by the other side. (The remote GET value will have 1188 * received by the other side. (The remote GET value will have
@@ -1269,7 +1204,7 @@ xpc_process_msg_IPI(struct xpc_partition *part, int ch_number)
1269 * received and delivered by the other side. 1204 * received and delivered by the other side.
1270 */ 1205 */
1271 xpc_notify_senders(ch, xpcMsgDelivered, 1206 xpc_notify_senders(ch, xpcMsgDelivered,
1272 ch->remote_GP.get); 1207 ch->remote_GP.get);
1273 } 1208 }
1274 1209
1275 /* 1210 /*
@@ -1288,12 +1223,10 @@ xpc_process_msg_IPI(struct xpc_partition *part, int ch_number)
1288 * If anyone was waiting for message queue entries to become 1223 * If anyone was waiting for message queue entries to become
1289 * available, wake them up. 1224 * available, wake them up.
1290 */ 1225 */
1291 if (atomic_read(&ch->n_on_msg_allocate_wq) > 0) { 1226 if (atomic_read(&ch->n_on_msg_allocate_wq) > 0)
1292 wake_up(&ch->msg_allocate_wq); 1227 wake_up(&ch->msg_allocate_wq);
1293 }
1294 } 1228 }
1295 1229
1296
1297 /* 1230 /*
1298 * Now check for newly sent messages by the other side. (The remote 1231 * Now check for newly sent messages by the other side. (The remote
1299 * PUT value will have changed since we last looked at it.) 1232 * PUT value will have changed since we last looked at it.)
@@ -1318,16 +1251,14 @@ xpc_process_msg_IPI(struct xpc_partition *part, int ch_number)
1318 "delivered=%d, partid=%d, channel=%d\n", 1251 "delivered=%d, partid=%d, channel=%d\n",
1319 nmsgs_sent, ch->partid, ch->number); 1252 nmsgs_sent, ch->partid, ch->number);
1320 1253
1321 if (ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) { 1254 if (ch->flags & XPC_C_CONNECTEDCALLOUT_MADE)
1322 xpc_activate_kthreads(ch, nmsgs_sent); 1255 xpc_activate_kthreads(ch, nmsgs_sent);
1323 }
1324 } 1256 }
1325 } 1257 }
1326 1258
1327 xpc_msgqueue_deref(ch); 1259 xpc_msgqueue_deref(ch);
1328} 1260}
1329 1261
1330
1331void 1262void
1332xpc_process_channel_activity(struct xpc_partition *part) 1263xpc_process_channel_activity(struct xpc_partition *part)
1333{ 1264{
@@ -1337,7 +1268,6 @@ xpc_process_channel_activity(struct xpc_partition *part)
1337 int ch_number; 1268 int ch_number;
1338 u32 ch_flags; 1269 u32 ch_flags;
1339 1270
1340
1341 IPI_amo = xpc_get_IPI_flags(part); 1271 IPI_amo = xpc_get_IPI_flags(part);
1342 1272
1343 /* 1273 /*
@@ -1350,7 +1280,6 @@ xpc_process_channel_activity(struct xpc_partition *part)
1350 for (ch_number = 0; ch_number < part->nchannels; ch_number++) { 1280 for (ch_number = 0; ch_number < part->nchannels; ch_number++) {
1351 ch = &part->channels[ch_number]; 1281 ch = &part->channels[ch_number];
1352 1282
1353
1354 /* 1283 /*
1355 * Process any open or close related IPI flags, and then deal 1284 * Process any open or close related IPI flags, and then deal
1356 * with connecting or disconnecting the channel as required. 1285 * with connecting or disconnecting the channel as required.
@@ -1358,9 +1287,8 @@ xpc_process_channel_activity(struct xpc_partition *part)
1358 1287
1359 IPI_flags = XPC_GET_IPI_FLAGS(IPI_amo, ch_number); 1288 IPI_flags = XPC_GET_IPI_FLAGS(IPI_amo, ch_number);
1360 1289
1361 if (XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(IPI_flags)) { 1290 if (XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(IPI_flags))
1362 xpc_process_openclose_IPI(part, ch_number, IPI_flags); 1291 xpc_process_openclose_IPI(part, ch_number, IPI_flags);
1363 }
1364 1292
1365 ch_flags = ch->flags; /* need an atomic snapshot of flags */ 1293 ch_flags = ch->flags; /* need an atomic snapshot of flags */
1366 1294
@@ -1371,14 +1299,13 @@ xpc_process_channel_activity(struct xpc_partition *part)
1371 continue; 1299 continue;
1372 } 1300 }
1373 1301
1374 if (part->act_state == XPC_P_DEACTIVATING) { 1302 if (part->act_state == XPC_P_DEACTIVATING)
1375 continue; 1303 continue;
1376 }
1377 1304
1378 if (!(ch_flags & XPC_C_CONNECTED)) { 1305 if (!(ch_flags & XPC_C_CONNECTED)) {
1379 if (!(ch_flags & XPC_C_OPENREQUEST)) { 1306 if (!(ch_flags & XPC_C_OPENREQUEST)) {
1380 DBUG_ON(ch_flags & XPC_C_SETUP); 1307 DBUG_ON(ch_flags & XPC_C_SETUP);
1381 (void) xpc_connect_channel(ch); 1308 (void)xpc_connect_channel(ch);
1382 } else { 1309 } else {
1383 spin_lock_irqsave(&ch->lock, irq_flags); 1310 spin_lock_irqsave(&ch->lock, irq_flags);
1384 xpc_process_connect(ch, &irq_flags); 1311 xpc_process_connect(ch, &irq_flags);
@@ -1387,20 +1314,17 @@ xpc_process_channel_activity(struct xpc_partition *part)
1387 continue; 1314 continue;
1388 } 1315 }
1389 1316
1390
1391 /* 1317 /*
1392 * Process any message related IPI flags, this may involve the 1318 * Process any message related IPI flags, this may involve the
1393 * activation of kthreads to deliver any pending messages sent 1319 * activation of kthreads to deliver any pending messages sent
1394 * from the other partition. 1320 * from the other partition.
1395 */ 1321 */
1396 1322
1397 if (XPC_ANY_MSG_IPI_FLAGS_SET(IPI_flags)) { 1323 if (XPC_ANY_MSG_IPI_FLAGS_SET(IPI_flags))
1398 xpc_process_msg_IPI(part, ch_number); 1324 xpc_process_msg_IPI(part, ch_number);
1399 }
1400 } 1325 }
1401} 1326}
1402 1327
1403
1404/* 1328/*
1405 * XPC's heartbeat code calls this function to inform XPC that a partition is 1329 * XPC's heartbeat code calls this function to inform XPC that a partition is
1406 * going down. XPC responds by tearing down the XPartition Communication 1330 * going down. XPC responds by tearing down the XPartition Communication
@@ -1417,7 +1341,6 @@ xpc_partition_going_down(struct xpc_partition *part, enum xpc_retval reason)
1417 int ch_number; 1341 int ch_number;
1418 struct xpc_channel *ch; 1342 struct xpc_channel *ch;
1419 1343
1420
1421 dev_dbg(xpc_chan, "deactivating partition %d, reason=%d\n", 1344 dev_dbg(xpc_chan, "deactivating partition %d, reason=%d\n",
1422 XPC_PARTID(part), reason); 1345 XPC_PARTID(part), reason);
1423 1346
@@ -1426,7 +1349,6 @@ xpc_partition_going_down(struct xpc_partition *part, enum xpc_retval reason)
1426 return; 1349 return;
1427 } 1350 }
1428 1351
1429
1430 /* disconnect channels associated with the partition going down */ 1352 /* disconnect channels associated with the partition going down */
1431 1353
1432 for (ch_number = 0; ch_number < part->nchannels; ch_number++) { 1354 for (ch_number = 0; ch_number < part->nchannels; ch_number++) {
@@ -1446,7 +1368,6 @@ xpc_partition_going_down(struct xpc_partition *part, enum xpc_retval reason)
1446 xpc_part_deref(part); 1368 xpc_part_deref(part);
1447} 1369}
1448 1370
1449
1450/* 1371/*
1451 * Teardown the infrastructure necessary to support XPartition Communication 1372 * Teardown the infrastructure necessary to support XPartition Communication
1452 * between the specified remote partition and the local one. 1373 * between the specified remote partition and the local one.
@@ -1456,7 +1377,6 @@ xpc_teardown_infrastructure(struct xpc_partition *part)
1456{ 1377{
1457 partid_t partid = XPC_PARTID(part); 1378 partid_t partid = XPC_PARTID(part);
1458 1379
1459
1460 /* 1380 /*
1461 * We start off by making this partition inaccessible to local 1381 * We start off by making this partition inaccessible to local
1462 * processes by marking it as no longer setup. Then we make it 1382 * processes by marking it as no longer setup. Then we make it
@@ -1473,9 +1393,7 @@ xpc_teardown_infrastructure(struct xpc_partition *part)
1473 1393
1474 xpc_vars_part[partid].magic = 0; 1394 xpc_vars_part[partid].magic = 0;
1475 1395
1476 1396 free_irq(SGI_XPC_NOTIFY, (void *)(u64)partid);
1477 free_irq(SGI_XPC_NOTIFY, (void *) (u64) partid);
1478
1479 1397
1480 /* 1398 /*
1481 * Before proceeding with the teardown we have to wait until all 1399 * Before proceeding with the teardown we have to wait until all
@@ -1483,7 +1401,6 @@ xpc_teardown_infrastructure(struct xpc_partition *part)
1483 */ 1401 */
1484 wait_event(part->teardown_wq, (atomic_read(&part->references) == 0)); 1402 wait_event(part->teardown_wq, (atomic_read(&part->references) == 0));
1485 1403
1486
1487 /* now we can begin tearing down the infrastructure */ 1404 /* now we can begin tearing down the infrastructure */
1488 1405
1489 part->setup_state = XPC_P_TORNDOWN; 1406 part->setup_state = XPC_P_TORNDOWN;
@@ -1504,7 +1421,6 @@ xpc_teardown_infrastructure(struct xpc_partition *part)
1504 part->local_IPI_amo_va = NULL; 1421 part->local_IPI_amo_va = NULL;
1505} 1422}
1506 1423
1507
1508/* 1424/*
1509 * Called by XP at the time of channel connection registration to cause 1425 * Called by XP at the time of channel connection registration to cause
1510 * XPC to establish connections to all currently active partitions. 1426 * XPC to establish connections to all currently active partitions.
@@ -1516,7 +1432,6 @@ xpc_initiate_connect(int ch_number)
1516 struct xpc_partition *part; 1432 struct xpc_partition *part;
1517 struct xpc_channel *ch; 1433 struct xpc_channel *ch;
1518 1434
1519
1520 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS); 1435 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS);
1521 1436
1522 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) { 1437 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
@@ -1535,7 +1450,6 @@ xpc_initiate_connect(int ch_number)
1535 } 1450 }
1536} 1451}
1537 1452
1538
1539void 1453void
1540xpc_connected_callout(struct xpc_channel *ch) 1454xpc_connected_callout(struct xpc_channel *ch)
1541{ 1455{
@@ -1546,14 +1460,13 @@ xpc_connected_callout(struct xpc_channel *ch)
1546 "partid=%d, channel=%d\n", ch->partid, ch->number); 1460 "partid=%d, channel=%d\n", ch->partid, ch->number);
1547 1461
1548 ch->func(xpcConnected, ch->partid, ch->number, 1462 ch->func(xpcConnected, ch->partid, ch->number,
1549 (void *) (u64) ch->local_nentries, ch->key); 1463 (void *)(u64)ch->local_nentries, ch->key);
1550 1464
1551 dev_dbg(xpc_chan, "ch->func() returned, reason=xpcConnected, " 1465 dev_dbg(xpc_chan, "ch->func() returned, reason=xpcConnected, "
1552 "partid=%d, channel=%d\n", ch->partid, ch->number); 1466 "partid=%d, channel=%d\n", ch->partid, ch->number);
1553 } 1467 }
1554} 1468}
1555 1469
1556
1557/* 1470/*
1558 * Called by XP at the time of channel connection unregistration to cause 1471 * Called by XP at the time of channel connection unregistration to cause
1559 * XPC to teardown all current connections for the specified channel. 1472 * XPC to teardown all current connections for the specified channel.
@@ -1575,7 +1488,6 @@ xpc_initiate_disconnect(int ch_number)
1575 struct xpc_partition *part; 1488 struct xpc_partition *part;
1576 struct xpc_channel *ch; 1489 struct xpc_channel *ch;
1577 1490
1578
1579 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS); 1491 DBUG_ON(ch_number < 0 || ch_number >= XPC_NCHANNELS);
1580 1492
1581 /* initiate the channel disconnect for every active partition */ 1493 /* initiate the channel disconnect for every active partition */
@@ -1592,7 +1504,7 @@ xpc_initiate_disconnect(int ch_number)
1592 ch->flags |= XPC_C_WDISCONNECT; 1504 ch->flags |= XPC_C_WDISCONNECT;
1593 1505
1594 XPC_DISCONNECT_CHANNEL(ch, xpcUnregistering, 1506 XPC_DISCONNECT_CHANNEL(ch, xpcUnregistering,
1595 &irq_flags); 1507 &irq_flags);
1596 } 1508 }
1597 1509
1598 spin_unlock_irqrestore(&ch->lock, irq_flags); 1510 spin_unlock_irqrestore(&ch->lock, irq_flags);
@@ -1605,7 +1517,6 @@ xpc_initiate_disconnect(int ch_number)
1605 xpc_disconnect_wait(ch_number); 1517 xpc_disconnect_wait(ch_number);
1606} 1518}
1607 1519
1608
1609/* 1520/*
1610 * To disconnect a channel, and reflect it back to all who may be waiting. 1521 * To disconnect a channel, and reflect it back to all who may be waiting.
1611 * 1522 *
@@ -1617,16 +1528,15 @@ xpc_initiate_disconnect(int ch_number)
1617 */ 1528 */
1618void 1529void
1619xpc_disconnect_channel(const int line, struct xpc_channel *ch, 1530xpc_disconnect_channel(const int line, struct xpc_channel *ch,
1620 enum xpc_retval reason, unsigned long *irq_flags) 1531 enum xpc_retval reason, unsigned long *irq_flags)
1621{ 1532{
1622 u32 channel_was_connected = (ch->flags & XPC_C_CONNECTED); 1533 u32 channel_was_connected = (ch->flags & XPC_C_CONNECTED);
1623 1534
1624
1625 DBUG_ON(!spin_is_locked(&ch->lock)); 1535 DBUG_ON(!spin_is_locked(&ch->lock));
1626 1536
1627 if (ch->flags & (XPC_C_DISCONNECTING | XPC_C_DISCONNECTED)) { 1537 if (ch->flags & (XPC_C_DISCONNECTING | XPC_C_DISCONNECTED))
1628 return; 1538 return;
1629 } 1539
1630 DBUG_ON(!(ch->flags & (XPC_C_CONNECTING | XPC_C_CONNECTED))); 1540 DBUG_ON(!(ch->flags & (XPC_C_CONNECTING | XPC_C_CONNECTED)));
1631 1541
1632 dev_dbg(xpc_chan, "reason=%d, line=%d, partid=%d, channel=%d\n", 1542 dev_dbg(xpc_chan, "reason=%d, line=%d, partid=%d, channel=%d\n",
@@ -1637,14 +1547,13 @@ xpc_disconnect_channel(const int line, struct xpc_channel *ch,
1637 ch->flags |= (XPC_C_CLOSEREQUEST | XPC_C_DISCONNECTING); 1547 ch->flags |= (XPC_C_CLOSEREQUEST | XPC_C_DISCONNECTING);
1638 /* some of these may not have been set */ 1548 /* some of these may not have been set */
1639 ch->flags &= ~(XPC_C_OPENREQUEST | XPC_C_OPENREPLY | 1549 ch->flags &= ~(XPC_C_OPENREQUEST | XPC_C_OPENREPLY |
1640 XPC_C_ROPENREQUEST | XPC_C_ROPENREPLY | 1550 XPC_C_ROPENREQUEST | XPC_C_ROPENREPLY |
1641 XPC_C_CONNECTING | XPC_C_CONNECTED); 1551 XPC_C_CONNECTING | XPC_C_CONNECTED);
1642 1552
1643 xpc_IPI_send_closerequest(ch, irq_flags); 1553 xpc_IPI_send_closerequest(ch, irq_flags);
1644 1554
1645 if (channel_was_connected) { 1555 if (channel_was_connected)
1646 ch->flags |= XPC_C_WASCONNECTED; 1556 ch->flags |= XPC_C_WASCONNECTED;
1647 }
1648 1557
1649 spin_unlock_irqrestore(&ch->lock, *irq_flags); 1558 spin_unlock_irqrestore(&ch->lock, *irq_flags);
1650 1559
@@ -1653,20 +1562,18 @@ xpc_disconnect_channel(const int line, struct xpc_channel *ch,
1653 wake_up_all(&ch->idle_wq); 1562 wake_up_all(&ch->idle_wq);
1654 1563
1655 } else if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) && 1564 } else if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
1656 !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) { 1565 !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) {
1657 /* start a kthread that will do the xpcDisconnecting callout */ 1566 /* start a kthread that will do the xpcDisconnecting callout */
1658 xpc_create_kthreads(ch, 1, 1); 1567 xpc_create_kthreads(ch, 1, 1);
1659 } 1568 }
1660 1569
1661 /* wake those waiting to allocate an entry from the local msg queue */ 1570 /* wake those waiting to allocate an entry from the local msg queue */
1662 if (atomic_read(&ch->n_on_msg_allocate_wq) > 0) { 1571 if (atomic_read(&ch->n_on_msg_allocate_wq) > 0)
1663 wake_up(&ch->msg_allocate_wq); 1572 wake_up(&ch->msg_allocate_wq);
1664 }
1665 1573
1666 spin_lock_irqsave(&ch->lock, *irq_flags); 1574 spin_lock_irqsave(&ch->lock, *irq_flags);
1667} 1575}
1668 1576
1669
1670void 1577void
1671xpc_disconnect_callout(struct xpc_channel *ch, enum xpc_retval reason) 1578xpc_disconnect_callout(struct xpc_channel *ch, enum xpc_retval reason)
1672{ 1579{
@@ -1687,7 +1594,6 @@ xpc_disconnect_callout(struct xpc_channel *ch, enum xpc_retval reason)
1687 } 1594 }
1688} 1595}
1689 1596
1690
1691/* 1597/*
1692 * Wait for a message entry to become available for the specified channel, 1598 * Wait for a message entry to become available for the specified channel,
1693 * but don't wait any longer than 1 jiffy. 1599 * but don't wait any longer than 1 jiffy.
@@ -1697,9 +1603,8 @@ xpc_allocate_msg_wait(struct xpc_channel *ch)
1697{ 1603{
1698 enum xpc_retval ret; 1604 enum xpc_retval ret;
1699 1605
1700
1701 if (ch->flags & XPC_C_DISCONNECTING) { 1606 if (ch->flags & XPC_C_DISCONNECTING) {
1702 DBUG_ON(ch->reason == xpcInterrupted); // >>> Is this true? 1607 DBUG_ON(ch->reason == xpcInterrupted);
1703 return ch->reason; 1608 return ch->reason;
1704 } 1609 }
1705 1610
@@ -1709,7 +1614,7 @@ xpc_allocate_msg_wait(struct xpc_channel *ch)
1709 1614
1710 if (ch->flags & XPC_C_DISCONNECTING) { 1615 if (ch->flags & XPC_C_DISCONNECTING) {
1711 ret = ch->reason; 1616 ret = ch->reason;
1712 DBUG_ON(ch->reason == xpcInterrupted); // >>> Is this true? 1617 DBUG_ON(ch->reason == xpcInterrupted);
1713 } else if (ret == 0) { 1618 } else if (ret == 0) {
1714 ret = xpcTimeout; 1619 ret = xpcTimeout;
1715 } else { 1620 } else {
@@ -1719,20 +1624,18 @@ xpc_allocate_msg_wait(struct xpc_channel *ch)
1719 return ret; 1624 return ret;
1720} 1625}
1721 1626
1722
1723/* 1627/*
1724 * Allocate an entry for a message from the message queue associated with the 1628 * Allocate an entry for a message from the message queue associated with the
1725 * specified channel. 1629 * specified channel.
1726 */ 1630 */
1727static enum xpc_retval 1631static enum xpc_retval
1728xpc_allocate_msg(struct xpc_channel *ch, u32 flags, 1632xpc_allocate_msg(struct xpc_channel *ch, u32 flags,
1729 struct xpc_msg **address_of_msg) 1633 struct xpc_msg **address_of_msg)
1730{ 1634{
1731 struct xpc_msg *msg; 1635 struct xpc_msg *msg;
1732 enum xpc_retval ret; 1636 enum xpc_retval ret;
1733 s64 put; 1637 s64 put;
1734 1638
1735
1736 /* this reference will be dropped in xpc_send_msg() */ 1639 /* this reference will be dropped in xpc_send_msg() */
1737 xpc_msgqueue_ref(ch); 1640 xpc_msgqueue_ref(ch);
1738 1641
@@ -1745,7 +1648,6 @@ xpc_allocate_msg(struct xpc_channel *ch, u32 flags,
1745 return xpcNotConnected; 1648 return xpcNotConnected;
1746 } 1649 }
1747 1650
1748
1749 /* 1651 /*
1750 * Get the next available message entry from the local message queue. 1652 * Get the next available message entry from the local message queue.
1751 * If none are available, we'll make sure that we grab the latest 1653 * If none are available, we'll make sure that we grab the latest
@@ -1755,25 +1657,23 @@ xpc_allocate_msg(struct xpc_channel *ch, u32 flags,
1755 1657
1756 while (1) { 1658 while (1) {
1757 1659
1758 put = (volatile s64) ch->w_local_GP.put; 1660 put = ch->w_local_GP.put;
1759 if (put - (volatile s64) ch->w_remote_GP.get < 1661 rmb(); /* guarantee that .put loads before .get */
1760 ch->local_nentries) { 1662 if (put - ch->w_remote_GP.get < ch->local_nentries) {
1761 1663
1762 /* There are available message entries. We need to try 1664 /* There are available message entries. We need to try
1763 * to secure one for ourselves. We'll do this by trying 1665 * to secure one for ourselves. We'll do this by trying
1764 * to increment w_local_GP.put as long as someone else 1666 * to increment w_local_GP.put as long as someone else
1765 * doesn't beat us to it. If they do, we'll have to 1667 * doesn't beat us to it. If they do, we'll have to
1766 * try again. 1668 * try again.
1767 */ 1669 */
1768 if (cmpxchg(&ch->w_local_GP.put, put, put + 1) == 1670 if (cmpxchg(&ch->w_local_GP.put, put, put + 1) == put) {
1769 put) {
1770 /* we got the entry referenced by put */ 1671 /* we got the entry referenced by put */
1771 break; 1672 break;
1772 } 1673 }
1773 continue; /* try again */ 1674 continue; /* try again */
1774 } 1675 }
1775 1676
1776
1777 /* 1677 /*
1778 * There aren't any available msg entries at this time. 1678 * There aren't any available msg entries at this time.
1779 * 1679 *
@@ -1783,9 +1683,8 @@ xpc_allocate_msg(struct xpc_channel *ch, u32 flags,
1783 * that will cause the IPI handler to fetch the latest 1683 * that will cause the IPI handler to fetch the latest
1784 * GP values as if an IPI was sent by the other side. 1684 * GP values as if an IPI was sent by the other side.
1785 */ 1685 */
1786 if (ret == xpcTimeout) { 1686 if (ret == xpcTimeout)
1787 xpc_IPI_send_local_msgrequest(ch); 1687 xpc_IPI_send_local_msgrequest(ch);
1788 }
1789 1688
1790 if (flags & XPC_NOWAIT) { 1689 if (flags & XPC_NOWAIT) {
1791 xpc_msgqueue_deref(ch); 1690 xpc_msgqueue_deref(ch);
@@ -1799,25 +1698,22 @@ xpc_allocate_msg(struct xpc_channel *ch, u32 flags,
1799 } 1698 }
1800 } 1699 }
1801 1700
1802
1803 /* get the message's address and initialize it */ 1701 /* get the message's address and initialize it */
1804 msg = (struct xpc_msg *) ((u64) ch->local_msgqueue + 1702 msg = (struct xpc_msg *)((u64)ch->local_msgqueue +
1805 (put % ch->local_nentries) * ch->msg_size); 1703 (put % ch->local_nentries) * ch->msg_size);
1806
1807 1704
1808 DBUG_ON(msg->flags != 0); 1705 DBUG_ON(msg->flags != 0);
1809 msg->number = put; 1706 msg->number = put;
1810 1707
1811 dev_dbg(xpc_chan, "w_local_GP.put changed to %ld; msg=0x%p, " 1708 dev_dbg(xpc_chan, "w_local_GP.put changed to %ld; msg=0x%p, "
1812 "msg_number=%ld, partid=%d, channel=%d\n", put + 1, 1709 "msg_number=%ld, partid=%d, channel=%d\n", put + 1,
1813 (void *) msg, msg->number, ch->partid, ch->number); 1710 (void *)msg, msg->number, ch->partid, ch->number);
1814 1711
1815 *address_of_msg = msg; 1712 *address_of_msg = msg;
1816 1713
1817 return xpcSuccess; 1714 return xpcSuccess;
1818} 1715}
1819 1716
1820
1821/* 1717/*
1822 * Allocate an entry for a message from the message queue associated with the 1718 * Allocate an entry for a message from the message queue associated with the
1823 * specified channel. NOTE that this routine can sleep waiting for a message 1719 * specified channel. NOTE that this routine can sleep waiting for a message
@@ -1838,7 +1734,6 @@ xpc_initiate_allocate(partid_t partid, int ch_number, u32 flags, void **payload)
1838 enum xpc_retval ret = xpcUnknownReason; 1734 enum xpc_retval ret = xpcUnknownReason;
1839 struct xpc_msg *msg = NULL; 1735 struct xpc_msg *msg = NULL;
1840 1736
1841
1842 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS); 1737 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
1843 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels); 1738 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels);
1844 1739
@@ -1848,15 +1743,13 @@ xpc_initiate_allocate(partid_t partid, int ch_number, u32 flags, void **payload)
1848 ret = xpc_allocate_msg(&part->channels[ch_number], flags, &msg); 1743 ret = xpc_allocate_msg(&part->channels[ch_number], flags, &msg);
1849 xpc_part_deref(part); 1744 xpc_part_deref(part);
1850 1745
1851 if (msg != NULL) { 1746 if (msg != NULL)
1852 *payload = &msg->payload; 1747 *payload = &msg->payload;
1853 }
1854 } 1748 }
1855 1749
1856 return ret; 1750 return ret;
1857} 1751}
1858 1752
1859
1860/* 1753/*
1861 * Now we actually send the messages that are ready to be sent by advancing 1754 * Now we actually send the messages that are ready to be sent by advancing
1862 * the local message queue's Put value and then send an IPI to the recipient 1755 * the local message queue's Put value and then send an IPI to the recipient
@@ -1869,20 +1762,18 @@ xpc_send_msgs(struct xpc_channel *ch, s64 initial_put)
1869 s64 put = initial_put + 1; 1762 s64 put = initial_put + 1;
1870 int send_IPI = 0; 1763 int send_IPI = 0;
1871 1764
1872
1873 while (1) { 1765 while (1) {
1874 1766
1875 while (1) { 1767 while (1) {
1876 if (put == (volatile s64) ch->w_local_GP.put) { 1768 if (put == ch->w_local_GP.put)
1877 break; 1769 break;
1878 }
1879 1770
1880 msg = (struct xpc_msg *) ((u64) ch->local_msgqueue + 1771 msg = (struct xpc_msg *)((u64)ch->local_msgqueue +
1881 (put % ch->local_nentries) * ch->msg_size); 1772 (put % ch->local_nentries) *
1773 ch->msg_size);
1882 1774
1883 if (!(msg->flags & XPC_M_READY)) { 1775 if (!(msg->flags & XPC_M_READY))
1884 break; 1776 break;
1885 }
1886 1777
1887 put++; 1778 put++;
1888 } 1779 }
@@ -1893,9 +1784,9 @@ xpc_send_msgs(struct xpc_channel *ch, s64 initial_put)
1893 } 1784 }
1894 1785
1895 if (cmpxchg_rel(&ch->local_GP->put, initial_put, put) != 1786 if (cmpxchg_rel(&ch->local_GP->put, initial_put, put) !=
1896 initial_put) { 1787 initial_put) {
1897 /* someone else beat us to it */ 1788 /* someone else beat us to it */
1898 DBUG_ON((volatile s64) ch->local_GP->put < initial_put); 1789 DBUG_ON(ch->local_GP->put < initial_put);
1899 break; 1790 break;
1900 } 1791 }
1901 1792
@@ -1914,12 +1805,10 @@ xpc_send_msgs(struct xpc_channel *ch, s64 initial_put)
1914 initial_put = put; 1805 initial_put = put;
1915 } 1806 }
1916 1807
1917 if (send_IPI) { 1808 if (send_IPI)
1918 xpc_IPI_send_msgrequest(ch); 1809 xpc_IPI_send_msgrequest(ch);
1919 }
1920} 1810}
1921 1811
1922
1923/* 1812/*
1924 * Common code that does the actual sending of the message by advancing the 1813 * Common code that does the actual sending of the message by advancing the
1925 * local message queue's Put value and sends an IPI to the partition the 1814 * local message queue's Put value and sends an IPI to the partition the
@@ -1927,16 +1816,15 @@ xpc_send_msgs(struct xpc_channel *ch, s64 initial_put)
1927 */ 1816 */
1928static enum xpc_retval 1817static enum xpc_retval
1929xpc_send_msg(struct xpc_channel *ch, struct xpc_msg *msg, u8 notify_type, 1818xpc_send_msg(struct xpc_channel *ch, struct xpc_msg *msg, u8 notify_type,
1930 xpc_notify_func func, void *key) 1819 xpc_notify_func func, void *key)
1931{ 1820{
1932 enum xpc_retval ret = xpcSuccess; 1821 enum xpc_retval ret = xpcSuccess;
1933 struct xpc_notify *notify = notify; 1822 struct xpc_notify *notify = notify;
1934 s64 put, msg_number = msg->number; 1823 s64 put, msg_number = msg->number;
1935 1824
1936
1937 DBUG_ON(notify_type == XPC_N_CALL && func == NULL); 1825 DBUG_ON(notify_type == XPC_N_CALL && func == NULL);
1938 DBUG_ON((((u64) msg - (u64) ch->local_msgqueue) / ch->msg_size) != 1826 DBUG_ON((((u64)msg - (u64)ch->local_msgqueue) / ch->msg_size) !=
1939 msg_number % ch->local_nentries); 1827 msg_number % ch->local_nentries);
1940 DBUG_ON(msg->flags & XPC_M_READY); 1828 DBUG_ON(msg->flags & XPC_M_READY);
1941 1829
1942 if (ch->flags & XPC_C_DISCONNECTING) { 1830 if (ch->flags & XPC_C_DISCONNECTING) {
@@ -1959,7 +1847,7 @@ xpc_send_msg(struct xpc_channel *ch, struct xpc_msg *msg, u8 notify_type,
1959 notify->key = key; 1847 notify->key = key;
1960 notify->type = notify_type; 1848 notify->type = notify_type;
1961 1849
1962 // >>> is a mb() needed here? 1850 /* >>> is a mb() needed here? */
1963 1851
1964 if (ch->flags & XPC_C_DISCONNECTING) { 1852 if (ch->flags & XPC_C_DISCONNECTING) {
1965 /* 1853 /*
@@ -1970,7 +1858,7 @@ xpc_send_msg(struct xpc_channel *ch, struct xpc_msg *msg, u8 notify_type,
1970 * the notify entry. 1858 * the notify entry.
1971 */ 1859 */
1972 if (cmpxchg(&notify->type, notify_type, 0) == 1860 if (cmpxchg(&notify->type, notify_type, 0) ==
1973 notify_type) { 1861 notify_type) {
1974 atomic_dec(&ch->n_to_notify); 1862 atomic_dec(&ch->n_to_notify);
1975 ret = ch->reason; 1863 ret = ch->reason;
1976 } 1864 }
@@ -1992,16 +1880,14 @@ xpc_send_msg(struct xpc_channel *ch, struct xpc_msg *msg, u8 notify_type,
1992 /* see if the message is next in line to be sent, if so send it */ 1880 /* see if the message is next in line to be sent, if so send it */
1993 1881
1994 put = ch->local_GP->put; 1882 put = ch->local_GP->put;
1995 if (put == msg_number) { 1883 if (put == msg_number)
1996 xpc_send_msgs(ch, put); 1884 xpc_send_msgs(ch, put);
1997 }
1998 1885
1999 /* drop the reference grabbed in xpc_allocate_msg() */ 1886 /* drop the reference grabbed in xpc_allocate_msg() */
2000 xpc_msgqueue_deref(ch); 1887 xpc_msgqueue_deref(ch);
2001 return ret; 1888 return ret;
2002} 1889}
2003 1890
2004
2005/* 1891/*
2006 * Send a message previously allocated using xpc_initiate_allocate() on the 1892 * Send a message previously allocated using xpc_initiate_allocate() on the
2007 * specified channel connected to the specified partition. 1893 * specified channel connected to the specified partition.
@@ -2029,8 +1915,7 @@ xpc_initiate_send(partid_t partid, int ch_number, void *payload)
2029 struct xpc_msg *msg = XPC_MSG_ADDRESS(payload); 1915 struct xpc_msg *msg = XPC_MSG_ADDRESS(payload);
2030 enum xpc_retval ret; 1916 enum xpc_retval ret;
2031 1917
2032 1918 dev_dbg(xpc_chan, "msg=0x%p, partid=%d, channel=%d\n", (void *)msg,
2033 dev_dbg(xpc_chan, "msg=0x%p, partid=%d, channel=%d\n", (void *) msg,
2034 partid, ch_number); 1919 partid, ch_number);
2035 1920
2036 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS); 1921 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
@@ -2042,7 +1927,6 @@ xpc_initiate_send(partid_t partid, int ch_number, void *payload)
2042 return ret; 1927 return ret;
2043} 1928}
2044 1929
2045
2046/* 1930/*
2047 * Send a message previously allocated using xpc_initiate_allocate on the 1931 * Send a message previously allocated using xpc_initiate_allocate on the
2048 * specified channel connected to the specified partition. 1932 * specified channel connected to the specified partition.
@@ -2075,14 +1959,13 @@ xpc_initiate_send(partid_t partid, int ch_number, void *payload)
2075 */ 1959 */
2076enum xpc_retval 1960enum xpc_retval
2077xpc_initiate_send_notify(partid_t partid, int ch_number, void *payload, 1961xpc_initiate_send_notify(partid_t partid, int ch_number, void *payload,
2078 xpc_notify_func func, void *key) 1962 xpc_notify_func func, void *key)
2079{ 1963{
2080 struct xpc_partition *part = &xpc_partitions[partid]; 1964 struct xpc_partition *part = &xpc_partitions[partid];
2081 struct xpc_msg *msg = XPC_MSG_ADDRESS(payload); 1965 struct xpc_msg *msg = XPC_MSG_ADDRESS(payload);
2082 enum xpc_retval ret; 1966 enum xpc_retval ret;
2083 1967
2084 1968 dev_dbg(xpc_chan, "msg=0x%p, partid=%d, channel=%d\n", (void *)msg,
2085 dev_dbg(xpc_chan, "msg=0x%p, partid=%d, channel=%d\n", (void *) msg,
2086 partid, ch_number); 1969 partid, ch_number);
2087 1970
2088 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS); 1971 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
@@ -2091,11 +1974,10 @@ xpc_initiate_send_notify(partid_t partid, int ch_number, void *payload,
2091 DBUG_ON(func == NULL); 1974 DBUG_ON(func == NULL);
2092 1975
2093 ret = xpc_send_msg(&part->channels[ch_number], msg, XPC_N_CALL, 1976 ret = xpc_send_msg(&part->channels[ch_number], msg, XPC_N_CALL,
2094 func, key); 1977 func, key);
2095 return ret; 1978 return ret;
2096} 1979}
2097 1980
2098
2099static struct xpc_msg * 1981static struct xpc_msg *
2100xpc_pull_remote_msg(struct xpc_channel *ch, s64 get) 1982xpc_pull_remote_msg(struct xpc_channel *ch, s64 get)
2101{ 1983{
@@ -2105,7 +1987,6 @@ xpc_pull_remote_msg(struct xpc_channel *ch, s64 get)
2105 u64 msg_offset; 1987 u64 msg_offset;
2106 enum xpc_retval ret; 1988 enum xpc_retval ret;
2107 1989
2108
2109 if (mutex_lock_interruptible(&ch->msg_to_pull_mutex) != 0) { 1990 if (mutex_lock_interruptible(&ch->msg_to_pull_mutex) != 0) {
2110 /* we were interrupted by a signal */ 1991 /* we were interrupted by a signal */
2111 return NULL; 1992 return NULL;
@@ -2117,23 +1998,21 @@ xpc_pull_remote_msg(struct xpc_channel *ch, s64 get)
2117 1998
2118 msg_index = ch->next_msg_to_pull % ch->remote_nentries; 1999 msg_index = ch->next_msg_to_pull % ch->remote_nentries;
2119 2000
2120 DBUG_ON(ch->next_msg_to_pull >= 2001 DBUG_ON(ch->next_msg_to_pull >= ch->w_remote_GP.put);
2121 (volatile s64) ch->w_remote_GP.put); 2002 nmsgs = ch->w_remote_GP.put - ch->next_msg_to_pull;
2122 nmsgs = (volatile s64) ch->w_remote_GP.put -
2123 ch->next_msg_to_pull;
2124 if (msg_index + nmsgs > ch->remote_nentries) { 2003 if (msg_index + nmsgs > ch->remote_nentries) {
2125 /* ignore the ones that wrap the msg queue for now */ 2004 /* ignore the ones that wrap the msg queue for now */
2126 nmsgs = ch->remote_nentries - msg_index; 2005 nmsgs = ch->remote_nentries - msg_index;
2127 } 2006 }
2128 2007
2129 msg_offset = msg_index * ch->msg_size; 2008 msg_offset = msg_index * ch->msg_size;
2130 msg = (struct xpc_msg *) ((u64) ch->remote_msgqueue + 2009 msg = (struct xpc_msg *)((u64)ch->remote_msgqueue + msg_offset);
2131 msg_offset); 2010 remote_msg = (struct xpc_msg *)(ch->remote_msgqueue_pa +
2132 remote_msg = (struct xpc_msg *) (ch->remote_msgqueue_pa + 2011 msg_offset);
2133 msg_offset);
2134 2012
2135 if ((ret = xpc_pull_remote_cachelines(part, msg, remote_msg, 2013 ret = xpc_pull_remote_cachelines(part, msg, remote_msg,
2136 nmsgs * ch->msg_size)) != xpcSuccess) { 2014 nmsgs * ch->msg_size);
2015 if (ret != xpcSuccess) {
2137 2016
2138 dev_dbg(xpc_chan, "failed to pull %d msgs starting with" 2017 dev_dbg(xpc_chan, "failed to pull %d msgs starting with"
2139 " msg %ld from partition %d, channel=%d, " 2018 " msg %ld from partition %d, channel=%d, "
@@ -2146,8 +2025,6 @@ xpc_pull_remote_msg(struct xpc_channel *ch, s64 get)
2146 return NULL; 2025 return NULL;
2147 } 2026 }
2148 2027
2149 mb(); /* >>> this may not be needed, we're not sure */
2150
2151 ch->next_msg_to_pull += nmsgs; 2028 ch->next_msg_to_pull += nmsgs;
2152 } 2029 }
2153 2030
@@ -2155,12 +2032,11 @@ xpc_pull_remote_msg(struct xpc_channel *ch, s64 get)
2155 2032
2156 /* return the message we were looking for */ 2033 /* return the message we were looking for */
2157 msg_offset = (get % ch->remote_nentries) * ch->msg_size; 2034 msg_offset = (get % ch->remote_nentries) * ch->msg_size;
2158 msg = (struct xpc_msg *) ((u64) ch->remote_msgqueue + msg_offset); 2035 msg = (struct xpc_msg *)((u64)ch->remote_msgqueue + msg_offset);
2159 2036
2160 return msg; 2037 return msg;
2161} 2038}
2162 2039
2163
2164/* 2040/*
2165 * Get a message to be delivered. 2041 * Get a message to be delivered.
2166 */ 2042 */
@@ -2170,23 +2046,21 @@ xpc_get_deliverable_msg(struct xpc_channel *ch)
2170 struct xpc_msg *msg = NULL; 2046 struct xpc_msg *msg = NULL;
2171 s64 get; 2047 s64 get;
2172 2048
2173
2174 do { 2049 do {
2175 if ((volatile u32) ch->flags & XPC_C_DISCONNECTING) { 2050 if (ch->flags & XPC_C_DISCONNECTING)
2176 break; 2051 break;
2177 }
2178 2052
2179 get = (volatile s64) ch->w_local_GP.get; 2053 get = ch->w_local_GP.get;
2180 if (get == (volatile s64) ch->w_remote_GP.put) { 2054 rmb(); /* guarantee that .get loads before .put */
2055 if (get == ch->w_remote_GP.put)
2181 break; 2056 break;
2182 }
2183 2057
2184 /* There are messages waiting to be pulled and delivered. 2058 /* There are messages waiting to be pulled and delivered.
2185 * We need to try to secure one for ourselves. We'll do this 2059 * We need to try to secure one for ourselves. We'll do this
2186 * by trying to increment w_local_GP.get and hope that no one 2060 * by trying to increment w_local_GP.get and hope that no one
2187 * else beats us to it. If they do, we'll we'll simply have 2061 * else beats us to it. If they do, we'll we'll simply have
2188 * to try again for the next one. 2062 * to try again for the next one.
2189 */ 2063 */
2190 2064
2191 if (cmpxchg(&ch->w_local_GP.get, get, get + 1) == get) { 2065 if (cmpxchg(&ch->w_local_GP.get, get, get + 1) == get) {
2192 /* we got the entry referenced by get */ 2066 /* we got the entry referenced by get */
@@ -2211,7 +2085,6 @@ xpc_get_deliverable_msg(struct xpc_channel *ch)
2211 return msg; 2085 return msg;
2212} 2086}
2213 2087
2214
2215/* 2088/*
2216 * Deliver a message to its intended recipient. 2089 * Deliver a message to its intended recipient.
2217 */ 2090 */
@@ -2220,8 +2093,8 @@ xpc_deliver_msg(struct xpc_channel *ch)
2220{ 2093{
2221 struct xpc_msg *msg; 2094 struct xpc_msg *msg;
2222 2095
2223 2096 msg = xpc_get_deliverable_msg(ch);
2224 if ((msg = xpc_get_deliverable_msg(ch)) != NULL) { 2097 if (msg != NULL) {
2225 2098
2226 /* 2099 /*
2227 * This ref is taken to protect the payload itself from being 2100 * This ref is taken to protect the payload itself from being
@@ -2235,16 +2108,16 @@ xpc_deliver_msg(struct xpc_channel *ch)
2235 if (ch->func != NULL) { 2108 if (ch->func != NULL) {
2236 dev_dbg(xpc_chan, "ch->func() called, msg=0x%p, " 2109 dev_dbg(xpc_chan, "ch->func() called, msg=0x%p, "
2237 "msg_number=%ld, partid=%d, channel=%d\n", 2110 "msg_number=%ld, partid=%d, channel=%d\n",
2238 (void *) msg, msg->number, ch->partid, 2111 (void *)msg, msg->number, ch->partid,
2239 ch->number); 2112 ch->number);
2240 2113
2241 /* deliver the message to its intended recipient */ 2114 /* deliver the message to its intended recipient */
2242 ch->func(xpcMsgReceived, ch->partid, ch->number, 2115 ch->func(xpcMsgReceived, ch->partid, ch->number,
2243 &msg->payload, ch->key); 2116 &msg->payload, ch->key);
2244 2117
2245 dev_dbg(xpc_chan, "ch->func() returned, msg=0x%p, " 2118 dev_dbg(xpc_chan, "ch->func() returned, msg=0x%p, "
2246 "msg_number=%ld, partid=%d, channel=%d\n", 2119 "msg_number=%ld, partid=%d, channel=%d\n",
2247 (void *) msg, msg->number, ch->partid, 2120 (void *)msg, msg->number, ch->partid,
2248 ch->number); 2121 ch->number);
2249 } 2122 }
2250 2123
@@ -2252,7 +2125,6 @@ xpc_deliver_msg(struct xpc_channel *ch)
2252 } 2125 }
2253} 2126}
2254 2127
2255
2256/* 2128/*
2257 * Now we actually acknowledge the messages that have been delivered and ack'd 2129 * Now we actually acknowledge the messages that have been delivered and ack'd
2258 * by advancing the cached remote message queue's Get value and if requested 2130 * by advancing the cached remote message queue's Get value and if requested
@@ -2265,20 +2137,18 @@ xpc_acknowledge_msgs(struct xpc_channel *ch, s64 initial_get, u8 msg_flags)
2265 s64 get = initial_get + 1; 2137 s64 get = initial_get + 1;
2266 int send_IPI = 0; 2138 int send_IPI = 0;
2267 2139
2268
2269 while (1) { 2140 while (1) {
2270 2141
2271 while (1) { 2142 while (1) {
2272 if (get == (volatile s64) ch->w_local_GP.get) { 2143 if (get == ch->w_local_GP.get)
2273 break; 2144 break;
2274 }
2275 2145
2276 msg = (struct xpc_msg *) ((u64) ch->remote_msgqueue + 2146 msg = (struct xpc_msg *)((u64)ch->remote_msgqueue +
2277 (get % ch->remote_nentries) * ch->msg_size); 2147 (get % ch->remote_nentries) *
2148 ch->msg_size);
2278 2149
2279 if (!(msg->flags & XPC_M_DONE)) { 2150 if (!(msg->flags & XPC_M_DONE))
2280 break; 2151 break;
2281 }
2282 2152
2283 msg_flags |= msg->flags; 2153 msg_flags |= msg->flags;
2284 get++; 2154 get++;
@@ -2290,10 +2160,9 @@ xpc_acknowledge_msgs(struct xpc_channel *ch, s64 initial_get, u8 msg_flags)
2290 } 2160 }
2291 2161
2292 if (cmpxchg_rel(&ch->local_GP->get, initial_get, get) != 2162 if (cmpxchg_rel(&ch->local_GP->get, initial_get, get) !=
2293 initial_get) { 2163 initial_get) {
2294 /* someone else beat us to it */ 2164 /* someone else beat us to it */
2295 DBUG_ON((volatile s64) ch->local_GP->get <= 2165 DBUG_ON(ch->local_GP->get <= initial_get);
2296 initial_get);
2297 break; 2166 break;
2298 } 2167 }
2299 2168
@@ -2312,12 +2181,10 @@ xpc_acknowledge_msgs(struct xpc_channel *ch, s64 initial_get, u8 msg_flags)
2312 initial_get = get; 2181 initial_get = get;
2313 } 2182 }
2314 2183
2315 if (send_IPI) { 2184 if (send_IPI)
2316 xpc_IPI_send_msgrequest(ch); 2185 xpc_IPI_send_msgrequest(ch);
2317 }
2318} 2186}
2319 2187
2320
2321/* 2188/*
2322 * Acknowledge receipt of a delivered message. 2189 * Acknowledge receipt of a delivered message.
2323 * 2190 *
@@ -2343,17 +2210,16 @@ xpc_initiate_received(partid_t partid, int ch_number, void *payload)
2343 struct xpc_msg *msg = XPC_MSG_ADDRESS(payload); 2210 struct xpc_msg *msg = XPC_MSG_ADDRESS(payload);
2344 s64 get, msg_number = msg->number; 2211 s64 get, msg_number = msg->number;
2345 2212
2346
2347 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS); 2213 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
2348 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels); 2214 DBUG_ON(ch_number < 0 || ch_number >= part->nchannels);
2349 2215
2350 ch = &part->channels[ch_number]; 2216 ch = &part->channels[ch_number];
2351 2217
2352 dev_dbg(xpc_chan, "msg=0x%p, msg_number=%ld, partid=%d, channel=%d\n", 2218 dev_dbg(xpc_chan, "msg=0x%p, msg_number=%ld, partid=%d, channel=%d\n",
2353 (void *) msg, msg_number, ch->partid, ch->number); 2219 (void *)msg, msg_number, ch->partid, ch->number);
2354 2220
2355 DBUG_ON((((u64) msg - (u64) ch->remote_msgqueue) / ch->msg_size) != 2221 DBUG_ON((((u64)msg - (u64)ch->remote_msgqueue) / ch->msg_size) !=
2356 msg_number % ch->remote_nentries); 2222 msg_number % ch->remote_nentries);
2357 DBUG_ON(msg->flags & XPC_M_DONE); 2223 DBUG_ON(msg->flags & XPC_M_DONE);
2358 2224
2359 msg->flags |= XPC_M_DONE; 2225 msg->flags |= XPC_M_DONE;
@@ -2369,11 +2235,9 @@ xpc_initiate_received(partid_t partid, int ch_number, void *payload)
2369 * been delivered. 2235 * been delivered.
2370 */ 2236 */
2371 get = ch->local_GP->get; 2237 get = ch->local_GP->get;
2372 if (get == msg_number) { 2238 if (get == msg_number)
2373 xpc_acknowledge_msgs(ch, get, msg->flags); 2239 xpc_acknowledge_msgs(ch, get, msg->flags);
2374 }
2375 2240
2376 /* the call to xpc_msgqueue_ref() was done by xpc_deliver_msg() */ 2241 /* the call to xpc_msgqueue_ref() was done by xpc_deliver_msg() */
2377 xpc_msgqueue_deref(ch); 2242 xpc_msgqueue_deref(ch);
2378} 2243}
2379
diff --git a/arch/ia64/sn/kernel/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
index 9e0b164da9c2..f673ba90eb0e 100644
--- a/arch/ia64/sn/kernel/xpc_main.c
+++ b/drivers/misc/sgi-xp/xpc_main.c
@@ -3,10 +3,9 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (c) 2004-2007 Silicon Graphics, Inc. All Rights Reserved. 6 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
7 */ 7 */
8 8
9
10/* 9/*
11 * Cross Partition Communication (XPC) support - standard version. 10 * Cross Partition Communication (XPC) support - standard version.
12 * 11 *
@@ -44,23 +43,20 @@
44 * 43 *
45 */ 44 */
46 45
47
48#include <linux/kernel.h> 46#include <linux/kernel.h>
49#include <linux/module.h> 47#include <linux/module.h>
50#include <linux/init.h> 48#include <linux/init.h>
51#include <linux/sched.h>
52#include <linux/syscalls.h>
53#include <linux/cache.h> 49#include <linux/cache.h>
54#include <linux/interrupt.h> 50#include <linux/interrupt.h>
55#include <linux/delay.h> 51#include <linux/delay.h>
56#include <linux/reboot.h> 52#include <linux/reboot.h>
57#include <linux/completion.h> 53#include <linux/completion.h>
58#include <linux/kdebug.h> 54#include <linux/kdebug.h>
55#include <linux/kthread.h>
56#include <linux/uaccess.h>
59#include <asm/sn/intr.h> 57#include <asm/sn/intr.h>
60#include <asm/sn/sn_sal.h> 58#include <asm/sn/sn_sal.h>
61#include <asm/uaccess.h> 59#include "xpc.h"
62#include <asm/sn/xpc.h>
63
64 60
65/* define two XPC debug device structures to be used with dev_dbg() et al */ 61/* define two XPC debug device structures to be used with dev_dbg() et al */
66 62
@@ -81,10 +77,8 @@ struct device xpc_chan_dbg_subname = {
81struct device *xpc_part = &xpc_part_dbg_subname; 77struct device *xpc_part = &xpc_part_dbg_subname;
82struct device *xpc_chan = &xpc_chan_dbg_subname; 78struct device *xpc_chan = &xpc_chan_dbg_subname;
83 79
84
85static int xpc_kdebug_ignore; 80static int xpc_kdebug_ignore;
86 81
87
88/* systune related variables for /proc/sys directories */ 82/* systune related variables for /proc/sys directories */
89 83
90static int xpc_hb_interval = XPC_HB_DEFAULT_INTERVAL; 84static int xpc_hb_interval = XPC_HB_DEFAULT_INTERVAL;
@@ -96,61 +90,56 @@ static int xpc_hb_check_min_interval = 10;
96static int xpc_hb_check_max_interval = 120; 90static int xpc_hb_check_max_interval = 120;
97 91
98int xpc_disengage_request_timelimit = XPC_DISENGAGE_REQUEST_DEFAULT_TIMELIMIT; 92int xpc_disengage_request_timelimit = XPC_DISENGAGE_REQUEST_DEFAULT_TIMELIMIT;
99static int xpc_disengage_request_min_timelimit = 0; 93static int xpc_disengage_request_min_timelimit; /* = 0 */
100static int xpc_disengage_request_max_timelimit = 120; 94static int xpc_disengage_request_max_timelimit = 120;
101 95
102static ctl_table xpc_sys_xpc_hb_dir[] = { 96static ctl_table xpc_sys_xpc_hb_dir[] = {
103 { 97 {
104 .ctl_name = CTL_UNNUMBERED, 98 .ctl_name = CTL_UNNUMBERED,
105 .procname = "hb_interval", 99 .procname = "hb_interval",
106 .data = &xpc_hb_interval, 100 .data = &xpc_hb_interval,
107 .maxlen = sizeof(int), 101 .maxlen = sizeof(int),
108 .mode = 0644, 102 .mode = 0644,
109 .proc_handler = &proc_dointvec_minmax, 103 .proc_handler = &proc_dointvec_minmax,
110 .strategy = &sysctl_intvec, 104 .strategy = &sysctl_intvec,
111 .extra1 = &xpc_hb_min_interval, 105 .extra1 = &xpc_hb_min_interval,
112 .extra2 = &xpc_hb_max_interval 106 .extra2 = &xpc_hb_max_interval},
113 },
114 { 107 {
115 .ctl_name = CTL_UNNUMBERED, 108 .ctl_name = CTL_UNNUMBERED,
116 .procname = "hb_check_interval", 109 .procname = "hb_check_interval",
117 .data = &xpc_hb_check_interval, 110 .data = &xpc_hb_check_interval,
118 .maxlen = sizeof(int), 111 .maxlen = sizeof(int),
119 .mode = 0644, 112 .mode = 0644,
120 .proc_handler = &proc_dointvec_minmax, 113 .proc_handler = &proc_dointvec_minmax,
121 .strategy = &sysctl_intvec, 114 .strategy = &sysctl_intvec,
122 .extra1 = &xpc_hb_check_min_interval, 115 .extra1 = &xpc_hb_check_min_interval,
123 .extra2 = &xpc_hb_check_max_interval 116 .extra2 = &xpc_hb_check_max_interval},
124 },
125 {} 117 {}
126}; 118};
127static ctl_table xpc_sys_xpc_dir[] = { 119static ctl_table xpc_sys_xpc_dir[] = {
128 { 120 {
129 .ctl_name = CTL_UNNUMBERED, 121 .ctl_name = CTL_UNNUMBERED,
130 .procname = "hb", 122 .procname = "hb",
131 .mode = 0555, 123 .mode = 0555,
132 .child = xpc_sys_xpc_hb_dir 124 .child = xpc_sys_xpc_hb_dir},
133 },
134 { 125 {
135 .ctl_name = CTL_UNNUMBERED, 126 .ctl_name = CTL_UNNUMBERED,
136 .procname = "disengage_request_timelimit", 127 .procname = "disengage_request_timelimit",
137 .data = &xpc_disengage_request_timelimit, 128 .data = &xpc_disengage_request_timelimit,
138 .maxlen = sizeof(int), 129 .maxlen = sizeof(int),
139 .mode = 0644, 130 .mode = 0644,
140 .proc_handler = &proc_dointvec_minmax, 131 .proc_handler = &proc_dointvec_minmax,
141 .strategy = &sysctl_intvec, 132 .strategy = &sysctl_intvec,
142 .extra1 = &xpc_disengage_request_min_timelimit, 133 .extra1 = &xpc_disengage_request_min_timelimit,
143 .extra2 = &xpc_disengage_request_max_timelimit 134 .extra2 = &xpc_disengage_request_max_timelimit},
144 },
145 {} 135 {}
146}; 136};
147static ctl_table xpc_sys_dir[] = { 137static ctl_table xpc_sys_dir[] = {
148 { 138 {
149 .ctl_name = CTL_UNNUMBERED, 139 .ctl_name = CTL_UNNUMBERED,
150 .procname = "xpc", 140 .procname = "xpc",
151 .mode = 0555, 141 .mode = 0555,
152 .child = xpc_sys_xpc_dir 142 .child = xpc_sys_xpc_dir},
153 },
154 {} 143 {}
155}; 144};
156static struct ctl_table_header *xpc_sysctl; 145static struct ctl_table_header *xpc_sysctl;
@@ -172,13 +161,10 @@ static DECLARE_COMPLETION(xpc_hb_checker_exited);
172/* notification that the xpc_discovery thread has exited */ 161/* notification that the xpc_discovery thread has exited */
173static DECLARE_COMPLETION(xpc_discovery_exited); 162static DECLARE_COMPLETION(xpc_discovery_exited);
174 163
175
176static struct timer_list xpc_hb_timer; 164static struct timer_list xpc_hb_timer;
177 165
178
179static void xpc_kthread_waitmsgs(struct xpc_partition *, struct xpc_channel *); 166static void xpc_kthread_waitmsgs(struct xpc_partition *, struct xpc_channel *);
180 167
181
182static int xpc_system_reboot(struct notifier_block *, unsigned long, void *); 168static int xpc_system_reboot(struct notifier_block *, unsigned long, void *);
183static struct notifier_block xpc_reboot_notifier = { 169static struct notifier_block xpc_reboot_notifier = {
184 .notifier_call = xpc_system_reboot, 170 .notifier_call = xpc_system_reboot,
@@ -189,25 +175,22 @@ static struct notifier_block xpc_die_notifier = {
189 .notifier_call = xpc_system_die, 175 .notifier_call = xpc_system_die,
190}; 176};
191 177
192
193/* 178/*
194 * Timer function to enforce the timelimit on the partition disengage request. 179 * Timer function to enforce the timelimit on the partition disengage request.
195 */ 180 */
196static void 181static void
197xpc_timeout_partition_disengage_request(unsigned long data) 182xpc_timeout_partition_disengage_request(unsigned long data)
198{ 183{
199 struct xpc_partition *part = (struct xpc_partition *) data; 184 struct xpc_partition *part = (struct xpc_partition *)data;
200
201 185
202 DBUG_ON(time_before(jiffies, part->disengage_request_timeout)); 186 DBUG_ON(time_before(jiffies, part->disengage_request_timeout));
203 187
204 (void) xpc_partition_disengaged(part); 188 (void)xpc_partition_disengaged(part);
205 189
206 DBUG_ON(part->disengage_request_timeout != 0); 190 DBUG_ON(part->disengage_request_timeout != 0);
207 DBUG_ON(xpc_partition_engaged(1UL << XPC_PARTID(part)) != 0); 191 DBUG_ON(xpc_partition_engaged(1UL << XPC_PARTID(part)) != 0);
208} 192}
209 193
210
211/* 194/*
212 * Notify the heartbeat check thread that an IRQ has been received. 195 * Notify the heartbeat check thread that an IRQ has been received.
213 */ 196 */
@@ -219,7 +202,6 @@ xpc_act_IRQ_handler(int irq, void *dev_id)
219 return IRQ_HANDLED; 202 return IRQ_HANDLED;
220} 203}
221 204
222
223/* 205/*
224 * Timer to produce the heartbeat. The timer structures function is 206 * Timer to produce the heartbeat. The timer structures function is
225 * already set when this is initially called. A tunable is used to 207 * already set when this is initially called. A tunable is used to
@@ -230,15 +212,13 @@ xpc_hb_beater(unsigned long dummy)
230{ 212{
231 xpc_vars->heartbeat++; 213 xpc_vars->heartbeat++;
232 214
233 if (time_after_eq(jiffies, xpc_hb_check_timeout)) { 215 if (time_after_eq(jiffies, xpc_hb_check_timeout))
234 wake_up_interruptible(&xpc_act_IRQ_wq); 216 wake_up_interruptible(&xpc_act_IRQ_wq);
235 }
236 217
237 xpc_hb_timer.expires = jiffies + (xpc_hb_interval * HZ); 218 xpc_hb_timer.expires = jiffies + (xpc_hb_interval * HZ);
238 add_timer(&xpc_hb_timer); 219 add_timer(&xpc_hb_timer);
239} 220}
240 221
241
242/* 222/*
243 * This thread is responsible for nearly all of the partition 223 * This thread is responsible for nearly all of the partition
244 * activation/deactivation. 224 * activation/deactivation.
@@ -248,27 +228,23 @@ xpc_hb_checker(void *ignore)
248{ 228{
249 int last_IRQ_count = 0; 229 int last_IRQ_count = 0;
250 int new_IRQ_count; 230 int new_IRQ_count;
251 int force_IRQ=0; 231 int force_IRQ = 0;
252
253 232
254 /* this thread was marked active by xpc_hb_init() */ 233 /* this thread was marked active by xpc_hb_init() */
255 234
256 daemonize(XPC_HB_CHECK_THREAD_NAME);
257
258 set_cpus_allowed(current, cpumask_of_cpu(XPC_HB_CHECK_CPU)); 235 set_cpus_allowed(current, cpumask_of_cpu(XPC_HB_CHECK_CPU));
259 236
260 /* set our heartbeating to other partitions into motion */ 237 /* set our heartbeating to other partitions into motion */
261 xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ); 238 xpc_hb_check_timeout = jiffies + (xpc_hb_check_interval * HZ);
262 xpc_hb_beater(0); 239 xpc_hb_beater(0);
263 240
264 while (!(volatile int) xpc_exiting) { 241 while (!xpc_exiting) {
265 242
266 dev_dbg(xpc_part, "woke up with %d ticks rem; %d IRQs have " 243 dev_dbg(xpc_part, "woke up with %d ticks rem; %d IRQs have "
267 "been received\n", 244 "been received\n",
268 (int) (xpc_hb_check_timeout - jiffies), 245 (int)(xpc_hb_check_timeout - jiffies),
269 atomic_read(&xpc_act_IRQ_rcvd) - last_IRQ_count); 246 atomic_read(&xpc_act_IRQ_rcvd) - last_IRQ_count);
270 247
271
272 /* checking of remote heartbeats is skewed by IRQ handling */ 248 /* checking of remote heartbeats is skewed by IRQ handling */
273 if (time_after_eq(jiffies, xpc_hb_check_timeout)) { 249 if (time_after_eq(jiffies, xpc_hb_check_timeout)) {
274 dev_dbg(xpc_part, "checking remote heartbeats\n"); 250 dev_dbg(xpc_part, "checking remote heartbeats\n");
@@ -282,7 +258,6 @@ xpc_hb_checker(void *ignore)
282 force_IRQ = 1; 258 force_IRQ = 1;
283 } 259 }
284 260
285
286 /* check for outstanding IRQs */ 261 /* check for outstanding IRQs */
287 new_IRQ_count = atomic_read(&xpc_act_IRQ_rcvd); 262 new_IRQ_count = atomic_read(&xpc_act_IRQ_rcvd);
288 if (last_IRQ_count < new_IRQ_count || force_IRQ != 0) { 263 if (last_IRQ_count < new_IRQ_count || force_IRQ != 0) {
@@ -294,30 +269,30 @@ xpc_hb_checker(void *ignore)
294 last_IRQ_count += xpc_identify_act_IRQ_sender(); 269 last_IRQ_count += xpc_identify_act_IRQ_sender();
295 if (last_IRQ_count < new_IRQ_count) { 270 if (last_IRQ_count < new_IRQ_count) {
296 /* retry once to help avoid missing AMO */ 271 /* retry once to help avoid missing AMO */
297 (void) xpc_identify_act_IRQ_sender(); 272 (void)xpc_identify_act_IRQ_sender();
298 } 273 }
299 last_IRQ_count = new_IRQ_count; 274 last_IRQ_count = new_IRQ_count;
300 275
301 xpc_hb_check_timeout = jiffies + 276 xpc_hb_check_timeout = jiffies +
302 (xpc_hb_check_interval * HZ); 277 (xpc_hb_check_interval * HZ);
303 } 278 }
304 279
305 /* wait for IRQ or timeout */ 280 /* wait for IRQ or timeout */
306 (void) wait_event_interruptible(xpc_act_IRQ_wq, 281 (void)wait_event_interruptible(xpc_act_IRQ_wq,
307 (last_IRQ_count < atomic_read(&xpc_act_IRQ_rcvd) || 282 (last_IRQ_count <
308 time_after_eq(jiffies, xpc_hb_check_timeout) || 283 atomic_read(&xpc_act_IRQ_rcvd)
309 (volatile int) xpc_exiting)); 284 || time_after_eq(jiffies,
285 xpc_hb_check_timeout) ||
286 xpc_exiting));
310 } 287 }
311 288
312 dev_dbg(xpc_part, "heartbeat checker is exiting\n"); 289 dev_dbg(xpc_part, "heartbeat checker is exiting\n");
313 290
314
315 /* mark this thread as having exited */ 291 /* mark this thread as having exited */
316 complete(&xpc_hb_checker_exited); 292 complete(&xpc_hb_checker_exited);
317 return 0; 293 return 0;
318} 294}
319 295
320
321/* 296/*
322 * This thread will attempt to discover other partitions to activate 297 * This thread will attempt to discover other partitions to activate
323 * based on info provided by SAL. This new thread is short lived and 298 * based on info provided by SAL. This new thread is short lived and
@@ -326,8 +301,6 @@ xpc_hb_checker(void *ignore)
326static int 301static int
327xpc_initiate_discovery(void *ignore) 302xpc_initiate_discovery(void *ignore)
328{ 303{
329 daemonize(XPC_DISCOVERY_THREAD_NAME);
330
331 xpc_discovery(); 304 xpc_discovery();
332 305
333 dev_dbg(xpc_part, "discovery thread is exiting\n"); 306 dev_dbg(xpc_part, "discovery thread is exiting\n");
@@ -337,7 +310,6 @@ xpc_initiate_discovery(void *ignore)
337 return 0; 310 return 0;
338} 311}
339 312
340
341/* 313/*
342 * Establish first contact with the remote partititon. This involves pulling 314 * Establish first contact with the remote partititon. This involves pulling
343 * the XPC per partition variables from the remote partition and waiting for 315 * the XPC per partition variables from the remote partition and waiting for
@@ -348,7 +320,6 @@ xpc_make_first_contact(struct xpc_partition *part)
348{ 320{
349 enum xpc_retval ret; 321 enum xpc_retval ret;
350 322
351
352 while ((ret = xpc_pull_remote_vars_part(part)) != xpcSuccess) { 323 while ((ret = xpc_pull_remote_vars_part(part)) != xpcSuccess) {
353 if (ret != xpcRetry) { 324 if (ret != xpcRetry) {
354 XPC_DEACTIVATE_PARTITION(part, ret); 325 XPC_DEACTIVATE_PARTITION(part, ret);
@@ -359,17 +330,15 @@ xpc_make_first_contact(struct xpc_partition *part)
359 "partition %d\n", XPC_PARTID(part)); 330 "partition %d\n", XPC_PARTID(part));
360 331
361 /* wait a 1/4 of a second or so */ 332 /* wait a 1/4 of a second or so */
362 (void) msleep_interruptible(250); 333 (void)msleep_interruptible(250);
363 334
364 if (part->act_state == XPC_P_DEACTIVATING) { 335 if (part->act_state == XPC_P_DEACTIVATING)
365 return part->reason; 336 return part->reason;
366 }
367 } 337 }
368 338
369 return xpc_mark_partition_active(part); 339 return xpc_mark_partition_active(part);
370} 340}
371 341
372
373/* 342/*
374 * The first kthread assigned to a newly activated partition is the one 343 * The first kthread assigned to a newly activated partition is the one
375 * created by XPC HB with which it calls xpc_partition_up(). XPC hangs on to 344 * created by XPC HB with which it calls xpc_partition_up(). XPC hangs on to
@@ -386,12 +355,11 @@ static void
386xpc_channel_mgr(struct xpc_partition *part) 355xpc_channel_mgr(struct xpc_partition *part)
387{ 356{
388 while (part->act_state != XPC_P_DEACTIVATING || 357 while (part->act_state != XPC_P_DEACTIVATING ||
389 atomic_read(&part->nchannels_active) > 0 || 358 atomic_read(&part->nchannels_active) > 0 ||
390 !xpc_partition_disengaged(part)) { 359 !xpc_partition_disengaged(part)) {
391 360
392 xpc_process_channel_activity(part); 361 xpc_process_channel_activity(part);
393 362
394
395 /* 363 /*
396 * Wait until we've been requested to activate kthreads or 364 * Wait until we've been requested to activate kthreads or
397 * all of the channel's message queues have been torn down or 365 * all of the channel's message queues have been torn down or
@@ -406,21 +374,16 @@ xpc_channel_mgr(struct xpc_partition *part)
406 * wake him up. 374 * wake him up.
407 */ 375 */
408 atomic_dec(&part->channel_mgr_requests); 376 atomic_dec(&part->channel_mgr_requests);
409 (void) wait_event_interruptible(part->channel_mgr_wq, 377 (void)wait_event_interruptible(part->channel_mgr_wq,
410 (atomic_read(&part->channel_mgr_requests) > 0 || 378 (atomic_read(&part->channel_mgr_requests) > 0 ||
411 (volatile u64) part->local_IPI_amo != 0 || 379 part->local_IPI_amo != 0 ||
412 ((volatile u8) part->act_state == 380 (part->act_state == XPC_P_DEACTIVATING &&
413 XPC_P_DEACTIVATING && 381 atomic_read(&part->nchannels_active) == 0 &&
414 atomic_read(&part->nchannels_active) == 0 && 382 xpc_partition_disengaged(part))));
415 xpc_partition_disengaged(part))));
416 atomic_set(&part->channel_mgr_requests, 1); 383 atomic_set(&part->channel_mgr_requests, 1);
417
418 // >>> Does it need to wakeup periodically as well? In case we
419 // >>> miscalculated the #of kthreads to wakeup or create?
420 } 384 }
421} 385}
422 386
423
424/* 387/*
425 * When XPC HB determines that a partition has come up, it will create a new 388 * When XPC HB determines that a partition has come up, it will create a new
426 * kthread and that kthread will call this function to attempt to set up the 389 * kthread and that kthread will call this function to attempt to set up the
@@ -443,9 +406,8 @@ xpc_partition_up(struct xpc_partition *part)
443 406
444 dev_dbg(xpc_chan, "activating partition %d\n", XPC_PARTID(part)); 407 dev_dbg(xpc_chan, "activating partition %d\n", XPC_PARTID(part));
445 408
446 if (xpc_setup_infrastructure(part) != xpcSuccess) { 409 if (xpc_setup_infrastructure(part) != xpcSuccess)
447 return; 410 return;
448 }
449 411
450 /* 412 /*
451 * The kthread that XPC HB called us with will become the 413 * The kthread that XPC HB called us with will become the
@@ -454,27 +416,22 @@ xpc_partition_up(struct xpc_partition *part)
454 * has been dismantled. 416 * has been dismantled.
455 */ 417 */
456 418
457 (void) xpc_part_ref(part); /* this will always succeed */ 419 (void)xpc_part_ref(part); /* this will always succeed */
458 420
459 if (xpc_make_first_contact(part) == xpcSuccess) { 421 if (xpc_make_first_contact(part) == xpcSuccess)
460 xpc_channel_mgr(part); 422 xpc_channel_mgr(part);
461 }
462 423
463 xpc_part_deref(part); 424 xpc_part_deref(part);
464 425
465 xpc_teardown_infrastructure(part); 426 xpc_teardown_infrastructure(part);
466} 427}
467 428
468
469static int 429static int
470xpc_activating(void *__partid) 430xpc_activating(void *__partid)
471{ 431{
472 partid_t partid = (u64) __partid; 432 partid_t partid = (u64)__partid;
473 struct xpc_partition *part = &xpc_partitions[partid]; 433 struct xpc_partition *part = &xpc_partitions[partid];
474 unsigned long irq_flags; 434 unsigned long irq_flags;
475 struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
476 int ret;
477
478 435
479 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS); 436 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
480 437
@@ -496,21 +453,6 @@ xpc_activating(void *__partid)
496 453
497 dev_dbg(xpc_part, "bringing partition %d up\n", partid); 454 dev_dbg(xpc_part, "bringing partition %d up\n", partid);
498 455
499 daemonize("xpc%02d", partid);
500
501 /*
502 * This thread needs to run at a realtime priority to prevent a
503 * significant performance degradation.
504 */
505 ret = sched_setscheduler(current, SCHED_FIFO, &param);
506 if (ret != 0) {
507 dev_warn(xpc_part, "unable to set pid %d to a realtime "
508 "priority, ret=%d\n", current->pid, ret);
509 }
510
511 /* allow this thread and its children to run on any CPU */
512 set_cpus_allowed(current, CPU_MASK_ALL);
513
514 /* 456 /*
515 * Register the remote partition's AMOs with SAL so it can handle 457 * Register the remote partition's AMOs with SAL so it can handle
516 * and cleanup errors within that address range should the remote 458 * and cleanup errors within that address range should the remote
@@ -522,9 +464,9 @@ xpc_activating(void *__partid)
522 * reloads and system reboots. 464 * reloads and system reboots.
523 */ 465 */
524 if (sn_register_xp_addr_region(part->remote_amos_page_pa, 466 if (sn_register_xp_addr_region(part->remote_amos_page_pa,
525 PAGE_SIZE, 1) < 0) { 467 PAGE_SIZE, 1) < 0) {
526 dev_warn(xpc_part, "xpc_partition_up(%d) failed to register " 468 dev_warn(xpc_part, "xpc_partition_up(%d) failed to register "
527 "xp_addr region\n", partid); 469 "xp_addr region\n", partid);
528 470
529 spin_lock_irqsave(&part->act_lock, irq_flags); 471 spin_lock_irqsave(&part->act_lock, irq_flags);
530 part->act_state = XPC_P_INACTIVE; 472 part->act_state = XPC_P_INACTIVE;
@@ -537,12 +479,11 @@ xpc_activating(void *__partid)
537 xpc_allow_hb(partid, xpc_vars); 479 xpc_allow_hb(partid, xpc_vars);
538 xpc_IPI_send_activated(part); 480 xpc_IPI_send_activated(part);
539 481
540
541 /* 482 /*
542 * xpc_partition_up() holds this thread and marks this partition as 483 * xpc_partition_up() holds this thread and marks this partition as
543 * XPC_P_ACTIVE by calling xpc_hb_mark_active(). 484 * XPC_P_ACTIVE by calling xpc_hb_mark_active().
544 */ 485 */
545 (void) xpc_partition_up(part); 486 (void)xpc_partition_up(part);
546 487
547 xpc_disallow_hb(partid, xpc_vars); 488 xpc_disallow_hb(partid, xpc_vars);
548 xpc_mark_partition_inactive(part); 489 xpc_mark_partition_inactive(part);
@@ -555,14 +496,12 @@ xpc_activating(void *__partid)
555 return 0; 496 return 0;
556} 497}
557 498
558
559void 499void
560xpc_activate_partition(struct xpc_partition *part) 500xpc_activate_partition(struct xpc_partition *part)
561{ 501{
562 partid_t partid = XPC_PARTID(part); 502 partid_t partid = XPC_PARTID(part);
563 unsigned long irq_flags; 503 unsigned long irq_flags;
564 pid_t pid; 504 struct task_struct *kthread;
565
566 505
567 spin_lock_irqsave(&part->act_lock, irq_flags); 506 spin_lock_irqsave(&part->act_lock, irq_flags);
568 507
@@ -573,9 +512,9 @@ xpc_activate_partition(struct xpc_partition *part)
573 512
574 spin_unlock_irqrestore(&part->act_lock, irq_flags); 513 spin_unlock_irqrestore(&part->act_lock, irq_flags);
575 514
576 pid = kernel_thread(xpc_activating, (void *) ((u64) partid), 0); 515 kthread = kthread_run(xpc_activating, (void *)((u64)partid), "xpc%02d",
577 516 partid);
578 if (unlikely(pid <= 0)) { 517 if (IS_ERR(kthread)) {
579 spin_lock_irqsave(&part->act_lock, irq_flags); 518 spin_lock_irqsave(&part->act_lock, irq_flags);
580 part->act_state = XPC_P_INACTIVE; 519 part->act_state = XPC_P_INACTIVE;
581 XPC_SET_REASON(part, xpcCloneKThreadFailed, __LINE__); 520 XPC_SET_REASON(part, xpcCloneKThreadFailed, __LINE__);
@@ -583,12 +522,11 @@ xpc_activate_partition(struct xpc_partition *part)
583 } 522 }
584} 523}
585 524
586
587/* 525/*
588 * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified 526 * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified
589 * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more 527 * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more
590 * than one partition, we use an AMO_t structure per partition to indicate 528 * than one partition, we use an AMO_t structure per partition to indicate
591 * whether a partition has sent an IPI or not. >>> If it has, then wake up the 529 * whether a partition has sent an IPI or not. If it has, then wake up the
592 * associated kthread to handle it. 530 * associated kthread to handle it.
593 * 531 *
594 * All SGI_XPC_NOTIFY IRQs received by XPC are the result of IPIs sent by XPC 532 * All SGI_XPC_NOTIFY IRQs received by XPC are the result of IPIs sent by XPC
@@ -603,10 +541,9 @@ xpc_activate_partition(struct xpc_partition *part)
603irqreturn_t 541irqreturn_t
604xpc_notify_IRQ_handler(int irq, void *dev_id) 542xpc_notify_IRQ_handler(int irq, void *dev_id)
605{ 543{
606 partid_t partid = (partid_t) (u64) dev_id; 544 partid_t partid = (partid_t) (u64)dev_id;
607 struct xpc_partition *part = &xpc_partitions[partid]; 545 struct xpc_partition *part = &xpc_partitions[partid];
608 546
609
610 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS); 547 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
611 548
612 if (xpc_part_ref(part)) { 549 if (xpc_part_ref(part)) {
@@ -617,7 +554,6 @@ xpc_notify_IRQ_handler(int irq, void *dev_id)
617 return IRQ_HANDLED; 554 return IRQ_HANDLED;
618} 555}
619 556
620
621/* 557/*
622 * Check to see if xpc_notify_IRQ_handler() dropped any IPIs on the floor 558 * Check to see if xpc_notify_IRQ_handler() dropped any IPIs on the floor
623 * because the write to their associated IPI amo completed after the IRQ/IPI 559 * because the write to their associated IPI amo completed after the IRQ/IPI
@@ -630,13 +566,12 @@ xpc_dropped_IPI_check(struct xpc_partition *part)
630 xpc_check_for_channel_activity(part); 566 xpc_check_for_channel_activity(part);
631 567
632 part->dropped_IPI_timer.expires = jiffies + 568 part->dropped_IPI_timer.expires = jiffies +
633 XPC_P_DROPPED_IPI_WAIT; 569 XPC_P_DROPPED_IPI_WAIT;
634 add_timer(&part->dropped_IPI_timer); 570 add_timer(&part->dropped_IPI_timer);
635 xpc_part_deref(part); 571 xpc_part_deref(part);
636 } 572 }
637} 573}
638 574
639
640void 575void
641xpc_activate_kthreads(struct xpc_channel *ch, int needed) 576xpc_activate_kthreads(struct xpc_channel *ch, int needed)
642{ 577{
@@ -644,7 +579,6 @@ xpc_activate_kthreads(struct xpc_channel *ch, int needed)
644 int assigned = atomic_read(&ch->kthreads_assigned); 579 int assigned = atomic_read(&ch->kthreads_assigned);
645 int wakeup; 580 int wakeup;
646 581
647
648 DBUG_ON(needed <= 0); 582 DBUG_ON(needed <= 0);
649 583
650 if (idle > 0) { 584 if (idle > 0) {
@@ -658,16 +592,13 @@ xpc_activate_kthreads(struct xpc_channel *ch, int needed)
658 wake_up_nr(&ch->idle_wq, wakeup); 592 wake_up_nr(&ch->idle_wq, wakeup);
659 } 593 }
660 594
661 if (needed <= 0) { 595 if (needed <= 0)
662 return; 596 return;
663 }
664 597
665 if (needed + assigned > ch->kthreads_assigned_limit) { 598 if (needed + assigned > ch->kthreads_assigned_limit) {
666 needed = ch->kthreads_assigned_limit - assigned; 599 needed = ch->kthreads_assigned_limit - assigned;
667 // >>>should never be less than 0 600 if (needed <= 0)
668 if (needed <= 0) {
669 return; 601 return;
670 }
671 } 602 }
672 603
673 dev_dbg(xpc_chan, "create %d new kthreads, partid=%d, channel=%d\n", 604 dev_dbg(xpc_chan, "create %d new kthreads, partid=%d, channel=%d\n",
@@ -676,7 +607,6 @@ xpc_activate_kthreads(struct xpc_channel *ch, int needed)
676 xpc_create_kthreads(ch, needed, 0); 607 xpc_create_kthreads(ch, needed, 0);
677} 608}
678 609
679
680/* 610/*
681 * This function is where XPC's kthreads wait for messages to deliver. 611 * This function is where XPC's kthreads wait for messages to deliver.
682 */ 612 */
@@ -686,15 +616,13 @@ xpc_kthread_waitmsgs(struct xpc_partition *part, struct xpc_channel *ch)
686 do { 616 do {
687 /* deliver messages to their intended recipients */ 617 /* deliver messages to their intended recipients */
688 618
689 while ((volatile s64) ch->w_local_GP.get < 619 while (ch->w_local_GP.get < ch->w_remote_GP.put &&
690 (volatile s64) ch->w_remote_GP.put && 620 !(ch->flags & XPC_C_DISCONNECTING)) {
691 !((volatile u32) ch->flags &
692 XPC_C_DISCONNECTING)) {
693 xpc_deliver_msg(ch); 621 xpc_deliver_msg(ch);
694 } 622 }
695 623
696 if (atomic_inc_return(&ch->kthreads_idle) > 624 if (atomic_inc_return(&ch->kthreads_idle) >
697 ch->kthreads_idle_limit) { 625 ch->kthreads_idle_limit) {
698 /* too many idle kthreads on this channel */ 626 /* too many idle kthreads on this channel */
699 atomic_dec(&ch->kthreads_idle); 627 atomic_dec(&ch->kthreads_idle);
700 break; 628 break;
@@ -703,20 +631,17 @@ xpc_kthread_waitmsgs(struct xpc_partition *part, struct xpc_channel *ch)
703 dev_dbg(xpc_chan, "idle kthread calling " 631 dev_dbg(xpc_chan, "idle kthread calling "
704 "wait_event_interruptible_exclusive()\n"); 632 "wait_event_interruptible_exclusive()\n");
705 633
706 (void) wait_event_interruptible_exclusive(ch->idle_wq, 634 (void)wait_event_interruptible_exclusive(ch->idle_wq,
707 ((volatile s64) ch->w_local_GP.get < 635 (ch->w_local_GP.get < ch->w_remote_GP.put ||
708 (volatile s64) ch->w_remote_GP.put || 636 (ch->flags & XPC_C_DISCONNECTING)));
709 ((volatile u32) ch->flags &
710 XPC_C_DISCONNECTING)));
711 637
712 atomic_dec(&ch->kthreads_idle); 638 atomic_dec(&ch->kthreads_idle);
713 639
714 } while (!((volatile u32) ch->flags & XPC_C_DISCONNECTING)); 640 } while (!(ch->flags & XPC_C_DISCONNECTING));
715} 641}
716 642
717
718static int 643static int
719xpc_daemonize_kthread(void *args) 644xpc_kthread_start(void *args)
720{ 645{
721 partid_t partid = XPC_UNPACK_ARG1(args); 646 partid_t partid = XPC_UNPACK_ARG1(args);
722 u16 ch_number = XPC_UNPACK_ARG2(args); 647 u16 ch_number = XPC_UNPACK_ARG2(args);
@@ -725,9 +650,6 @@ xpc_daemonize_kthread(void *args)
725 int n_needed; 650 int n_needed;
726 unsigned long irq_flags; 651 unsigned long irq_flags;
727 652
728
729 daemonize("xpc%02dc%d", partid, ch_number);
730
731 dev_dbg(xpc_chan, "kthread starting, partid=%d, channel=%d\n", 653 dev_dbg(xpc_chan, "kthread starting, partid=%d, channel=%d\n",
732 partid, ch_number); 654 partid, ch_number);
733 655
@@ -756,10 +678,9 @@ xpc_daemonize_kthread(void *args)
756 * need one less than total #of messages to deliver. 678 * need one less than total #of messages to deliver.
757 */ 679 */
758 n_needed = ch->w_remote_GP.put - ch->w_local_GP.get - 1; 680 n_needed = ch->w_remote_GP.put - ch->w_local_GP.get - 1;
759 if (n_needed > 0 && 681 if (n_needed > 0 && !(ch->flags & XPC_C_DISCONNECTING))
760 !(ch->flags & XPC_C_DISCONNECTING)) {
761 xpc_activate_kthreads(ch, n_needed); 682 xpc_activate_kthreads(ch, n_needed);
762 } 683
763 } else { 684 } else {
764 spin_unlock_irqrestore(&ch->lock, irq_flags); 685 spin_unlock_irqrestore(&ch->lock, irq_flags);
765 } 686 }
@@ -771,7 +692,7 @@ xpc_daemonize_kthread(void *args)
771 692
772 spin_lock_irqsave(&ch->lock, irq_flags); 693 spin_lock_irqsave(&ch->lock, irq_flags);
773 if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) && 694 if ((ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) &&
774 !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) { 695 !(ch->flags & XPC_C_DISCONNECTINGCALLOUT)) {
775 ch->flags |= XPC_C_DISCONNECTINGCALLOUT; 696 ch->flags |= XPC_C_DISCONNECTINGCALLOUT;
776 spin_unlock_irqrestore(&ch->lock, irq_flags); 697 spin_unlock_irqrestore(&ch->lock, irq_flags);
777 698
@@ -798,7 +719,6 @@ xpc_daemonize_kthread(void *args)
798 return 0; 719 return 0;
799} 720}
800 721
801
802/* 722/*
803 * For each partition that XPC has established communications with, there is 723 * For each partition that XPC has established communications with, there is
804 * a minimum of one kernel thread assigned to perform any operation that 724 * a minimum of one kernel thread assigned to perform any operation that
@@ -813,13 +733,12 @@ xpc_daemonize_kthread(void *args)
813 */ 733 */
814void 734void
815xpc_create_kthreads(struct xpc_channel *ch, int needed, 735xpc_create_kthreads(struct xpc_channel *ch, int needed,
816 int ignore_disconnecting) 736 int ignore_disconnecting)
817{ 737{
818 unsigned long irq_flags; 738 unsigned long irq_flags;
819 pid_t pid;
820 u64 args = XPC_PACK_ARGS(ch->partid, ch->number); 739 u64 args = XPC_PACK_ARGS(ch->partid, ch->number);
821 struct xpc_partition *part = &xpc_partitions[ch->partid]; 740 struct xpc_partition *part = &xpc_partitions[ch->partid];
822 741 struct task_struct *kthread;
823 742
824 while (needed-- > 0) { 743 while (needed-- > 0) {
825 744
@@ -832,7 +751,7 @@ xpc_create_kthreads(struct xpc_channel *ch, int needed,
832 if (!atomic_inc_not_zero(&ch->kthreads_assigned)) { 751 if (!atomic_inc_not_zero(&ch->kthreads_assigned)) {
833 /* kthreads assigned had gone to zero */ 752 /* kthreads assigned had gone to zero */
834 BUG_ON(!(ch->flags & 753 BUG_ON(!(ch->flags &
835 XPC_C_DISCONNECTINGCALLOUT_MADE)); 754 XPC_C_DISCONNECTINGCALLOUT_MADE));
836 break; 755 break;
837 } 756 }
838 757
@@ -843,11 +762,12 @@ xpc_create_kthreads(struct xpc_channel *ch, int needed,
843 if (atomic_inc_return(&part->nchannels_engaged) == 1) 762 if (atomic_inc_return(&part->nchannels_engaged) == 1)
844 xpc_mark_partition_engaged(part); 763 xpc_mark_partition_engaged(part);
845 } 764 }
846 (void) xpc_part_ref(part); 765 (void)xpc_part_ref(part);
847 xpc_msgqueue_ref(ch); 766 xpc_msgqueue_ref(ch);
848 767
849 pid = kernel_thread(xpc_daemonize_kthread, (void *) args, 0); 768 kthread = kthread_run(xpc_kthread_start, (void *)args,
850 if (pid < 0) { 769 "xpc%02dc%d", ch->partid, ch->number);
770 if (IS_ERR(kthread)) {
851 /* the fork failed */ 771 /* the fork failed */
852 772
853 /* 773 /*
@@ -857,7 +777,7 @@ xpc_create_kthreads(struct xpc_channel *ch, int needed,
857 * to this channel are blocked in the channel's 777 * to this channel are blocked in the channel's
858 * registerer, because the only thing that will unblock 778 * registerer, because the only thing that will unblock
859 * them is the xpcDisconnecting callout that this 779 * them is the xpcDisconnecting callout that this
860 * failed kernel_thread would have made. 780 * failed kthread_run() would have made.
861 */ 781 */
862 782
863 if (atomic_dec_return(&ch->kthreads_assigned) == 0 && 783 if (atomic_dec_return(&ch->kthreads_assigned) == 0 &&
@@ -869,7 +789,7 @@ xpc_create_kthreads(struct xpc_channel *ch, int needed,
869 xpc_part_deref(part); 789 xpc_part_deref(part);
870 790
871 if (atomic_read(&ch->kthreads_assigned) < 791 if (atomic_read(&ch->kthreads_assigned) <
872 ch->kthreads_idle_limit) { 792 ch->kthreads_idle_limit) {
873 /* 793 /*
874 * Flag this as an error only if we have an 794 * Flag this as an error only if we have an
875 * insufficient #of kthreads for the channel 795 * insufficient #of kthreads for the channel
@@ -877,17 +797,14 @@ xpc_create_kthreads(struct xpc_channel *ch, int needed,
877 */ 797 */
878 spin_lock_irqsave(&ch->lock, irq_flags); 798 spin_lock_irqsave(&ch->lock, irq_flags);
879 XPC_DISCONNECT_CHANNEL(ch, xpcLackOfResources, 799 XPC_DISCONNECT_CHANNEL(ch, xpcLackOfResources,
880 &irq_flags); 800 &irq_flags);
881 spin_unlock_irqrestore(&ch->lock, irq_flags); 801 spin_unlock_irqrestore(&ch->lock, irq_flags);
882 } 802 }
883 break; 803 break;
884 } 804 }
885
886 ch->kthreads_created++; // >>> temporary debug only!!!
887 } 805 }
888} 806}
889 807
890
891void 808void
892xpc_disconnect_wait(int ch_number) 809xpc_disconnect_wait(int ch_number)
893{ 810{
@@ -897,14 +814,12 @@ xpc_disconnect_wait(int ch_number)
897 struct xpc_channel *ch; 814 struct xpc_channel *ch;
898 int wakeup_channel_mgr; 815 int wakeup_channel_mgr;
899 816
900
901 /* now wait for all callouts to the caller's function to cease */ 817 /* now wait for all callouts to the caller's function to cease */
902 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) { 818 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
903 part = &xpc_partitions[partid]; 819 part = &xpc_partitions[partid];
904 820
905 if (!xpc_part_ref(part)) { 821 if (!xpc_part_ref(part))
906 continue; 822 continue;
907 }
908 823
909 ch = &part->channels[ch_number]; 824 ch = &part->channels[ch_number];
910 825
@@ -923,7 +838,8 @@ xpc_disconnect_wait(int ch_number)
923 if (part->act_state != XPC_P_DEACTIVATING) { 838 if (part->act_state != XPC_P_DEACTIVATING) {
924 spin_lock(&part->IPI_lock); 839 spin_lock(&part->IPI_lock);
925 XPC_SET_IPI_FLAGS(part->local_IPI_amo, 840 XPC_SET_IPI_FLAGS(part->local_IPI_amo,
926 ch->number, ch->delayed_IPI_flags); 841 ch->number,
842 ch->delayed_IPI_flags);
927 spin_unlock(&part->IPI_lock); 843 spin_unlock(&part->IPI_lock);
928 wakeup_channel_mgr = 1; 844 wakeup_channel_mgr = 1;
929 } 845 }
@@ -933,15 +849,13 @@ xpc_disconnect_wait(int ch_number)
933 ch->flags &= ~XPC_C_WDISCONNECT; 849 ch->flags &= ~XPC_C_WDISCONNECT;
934 spin_unlock_irqrestore(&ch->lock, irq_flags); 850 spin_unlock_irqrestore(&ch->lock, irq_flags);
935 851
936 if (wakeup_channel_mgr) { 852 if (wakeup_channel_mgr)
937 xpc_wakeup_channel_mgr(part); 853 xpc_wakeup_channel_mgr(part);
938 }
939 854
940 xpc_part_deref(part); 855 xpc_part_deref(part);
941 } 856 }
942} 857}
943 858
944
945static void 859static void
946xpc_do_exit(enum xpc_retval reason) 860xpc_do_exit(enum xpc_retval reason)
947{ 861{
@@ -950,7 +864,6 @@ xpc_do_exit(enum xpc_retval reason)
950 struct xpc_partition *part; 864 struct xpc_partition *part;
951 unsigned long printmsg_time, disengage_request_timeout = 0; 865 unsigned long printmsg_time, disengage_request_timeout = 0;
952 866
953
954 /* a 'rmmod XPC' and a 'reboot' cannot both end up here together */ 867 /* a 'rmmod XPC' and a 'reboot' cannot both end up here together */
955 DBUG_ON(xpc_exiting == 1); 868 DBUG_ON(xpc_exiting == 1);
956 869
@@ -971,10 +884,8 @@ xpc_do_exit(enum xpc_retval reason)
971 /* wait for the heartbeat checker thread to exit */ 884 /* wait for the heartbeat checker thread to exit */
972 wait_for_completion(&xpc_hb_checker_exited); 885 wait_for_completion(&xpc_hb_checker_exited);
973 886
974
975 /* sleep for a 1/3 of a second or so */ 887 /* sleep for a 1/3 of a second or so */
976 (void) msleep_interruptible(300); 888 (void)msleep_interruptible(300);
977
978 889
979 /* wait for all partitions to become inactive */ 890 /* wait for all partitions to become inactive */
980 891
@@ -988,7 +899,7 @@ xpc_do_exit(enum xpc_retval reason)
988 part = &xpc_partitions[partid]; 899 part = &xpc_partitions[partid];
989 900
990 if (xpc_partition_disengaged(part) && 901 if (xpc_partition_disengaged(part) &&
991 part->act_state == XPC_P_INACTIVE) { 902 part->act_state == XPC_P_INACTIVE) {
992 continue; 903 continue;
993 } 904 }
994 905
@@ -997,47 +908,46 @@ xpc_do_exit(enum xpc_retval reason)
997 XPC_DEACTIVATE_PARTITION(part, reason); 908 XPC_DEACTIVATE_PARTITION(part, reason);
998 909
999 if (part->disengage_request_timeout > 910 if (part->disengage_request_timeout >
1000 disengage_request_timeout) { 911 disengage_request_timeout) {
1001 disengage_request_timeout = 912 disengage_request_timeout =
1002 part->disengage_request_timeout; 913 part->disengage_request_timeout;
1003 } 914 }
1004 } 915 }
1005 916
1006 if (xpc_partition_engaged(-1UL)) { 917 if (xpc_partition_engaged(-1UL)) {
1007 if (time_after(jiffies, printmsg_time)) { 918 if (time_after(jiffies, printmsg_time)) {
1008 dev_info(xpc_part, "waiting for remote " 919 dev_info(xpc_part, "waiting for remote "
1009 "partitions to disengage, timeout in " 920 "partitions to disengage, timeout in "
1010 "%ld seconds\n", 921 "%ld seconds\n",
1011 (disengage_request_timeout - jiffies) 922 (disengage_request_timeout - jiffies)
1012 / HZ); 923 / HZ);
1013 printmsg_time = jiffies + 924 printmsg_time = jiffies +
1014 (XPC_DISENGAGE_PRINTMSG_INTERVAL * HZ); 925 (XPC_DISENGAGE_PRINTMSG_INTERVAL * HZ);
1015 printed_waiting_msg = 1; 926 printed_waiting_msg = 1;
1016 } 927 }
1017 928
1018 } else if (active_part_count > 0) { 929 } else if (active_part_count > 0) {
1019 if (printed_waiting_msg) { 930 if (printed_waiting_msg) {
1020 dev_info(xpc_part, "waiting for local partition" 931 dev_info(xpc_part, "waiting for local partition"
1021 " to disengage\n"); 932 " to disengage\n");
1022 printed_waiting_msg = 0; 933 printed_waiting_msg = 0;
1023 } 934 }
1024 935
1025 } else { 936 } else {
1026 if (!xpc_disengage_request_timedout) { 937 if (!xpc_disengage_request_timedout) {
1027 dev_info(xpc_part, "all partitions have " 938 dev_info(xpc_part, "all partitions have "
1028 "disengaged\n"); 939 "disengaged\n");
1029 } 940 }
1030 break; 941 break;
1031 } 942 }
1032 943
1033 /* sleep for a 1/3 of a second or so */ 944 /* sleep for a 1/3 of a second or so */
1034 (void) msleep_interruptible(300); 945 (void)msleep_interruptible(300);
1035 946
1036 } while (1); 947 } while (1);
1037 948
1038 DBUG_ON(xpc_partition_engaged(-1UL)); 949 DBUG_ON(xpc_partition_engaged(-1UL));
1039 950
1040
1041 /* indicate to others that our reserved page is uninitialized */ 951 /* indicate to others that our reserved page is uninitialized */
1042 xpc_rsvd_page->vars_pa = 0; 952 xpc_rsvd_page->vars_pa = 0;
1043 953
@@ -1047,27 +957,24 @@ xpc_do_exit(enum xpc_retval reason)
1047 957
1048 if (reason == xpcUnloading) { 958 if (reason == xpcUnloading) {
1049 /* take ourselves off of the reboot_notifier_list */ 959 /* take ourselves off of the reboot_notifier_list */
1050 (void) unregister_reboot_notifier(&xpc_reboot_notifier); 960 (void)unregister_reboot_notifier(&xpc_reboot_notifier);
1051 961
1052 /* take ourselves off of the die_notifier list */ 962 /* take ourselves off of the die_notifier list */
1053 (void) unregister_die_notifier(&xpc_die_notifier); 963 (void)unregister_die_notifier(&xpc_die_notifier);
1054 } 964 }
1055 965
1056 /* close down protections for IPI operations */ 966 /* close down protections for IPI operations */
1057 xpc_restrict_IPI_ops(); 967 xpc_restrict_IPI_ops();
1058 968
1059
1060 /* clear the interface to XPC's functions */ 969 /* clear the interface to XPC's functions */
1061 xpc_clear_interface(); 970 xpc_clear_interface();
1062 971
1063 if (xpc_sysctl) { 972 if (xpc_sysctl)
1064 unregister_sysctl_table(xpc_sysctl); 973 unregister_sysctl_table(xpc_sysctl);
1065 }
1066 974
1067 kfree(xpc_remote_copy_buffer_base); 975 kfree(xpc_remote_copy_buffer_base);
1068} 976}
1069 977
1070
1071/* 978/*
1072 * This function is called when the system is being rebooted. 979 * This function is called when the system is being rebooted.
1073 */ 980 */
@@ -1076,7 +983,6 @@ xpc_system_reboot(struct notifier_block *nb, unsigned long event, void *unused)
1076{ 983{
1077 enum xpc_retval reason; 984 enum xpc_retval reason;
1078 985
1079
1080 switch (event) { 986 switch (event) {
1081 case SYS_RESTART: 987 case SYS_RESTART:
1082 reason = xpcSystemReboot; 988 reason = xpcSystemReboot;
@@ -1095,7 +1001,6 @@ xpc_system_reboot(struct notifier_block *nb, unsigned long event, void *unused)
1095 return NOTIFY_DONE; 1001 return NOTIFY_DONE;
1096} 1002}
1097 1003
1098
1099/* 1004/*
1100 * Notify other partitions to disengage from all references to our memory. 1005 * Notify other partitions to disengage from all references to our memory.
1101 */ 1006 */
@@ -1107,17 +1012,16 @@ xpc_die_disengage(void)
1107 unsigned long engaged; 1012 unsigned long engaged;
1108 long time, printmsg_time, disengage_request_timeout; 1013 long time, printmsg_time, disengage_request_timeout;
1109 1014
1110
1111 /* keep xpc_hb_checker thread from doing anything (just in case) */ 1015 /* keep xpc_hb_checker thread from doing anything (just in case) */
1112 xpc_exiting = 1; 1016 xpc_exiting = 1;
1113 1017
1114 xpc_vars->heartbeating_to_mask = 0; /* indicate we're deactivated */ 1018 xpc_vars->heartbeating_to_mask = 0; /* indicate we're deactivated */
1115 1019
1116 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) { 1020 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
1117 part = &xpc_partitions[partid]; 1021 part = &xpc_partitions[partid];
1118 1022
1119 if (!XPC_SUPPORTS_DISENGAGE_REQUEST(part-> 1023 if (!XPC_SUPPORTS_DISENGAGE_REQUEST(part->
1120 remote_vars_version)) { 1024 remote_vars_version)) {
1121 1025
1122 /* just in case it was left set by an earlier XPC */ 1026 /* just in case it was left set by an earlier XPC */
1123 xpc_clear_partition_engaged(1UL << partid); 1027 xpc_clear_partition_engaged(1UL << partid);
@@ -1125,7 +1029,7 @@ xpc_die_disengage(void)
1125 } 1029 }
1126 1030
1127 if (xpc_partition_engaged(1UL << partid) || 1031 if (xpc_partition_engaged(1UL << partid) ||
1128 part->act_state != XPC_P_INACTIVE) { 1032 part->act_state != XPC_P_INACTIVE) {
1129 xpc_request_partition_disengage(part); 1033 xpc_request_partition_disengage(part);
1130 xpc_mark_partition_disengaged(part); 1034 xpc_mark_partition_disengaged(part);
1131 xpc_IPI_send_disengage(part); 1035 xpc_IPI_send_disengage(part);
@@ -1134,9 +1038,9 @@ xpc_die_disengage(void)
1134 1038
1135 time = rtc_time(); 1039 time = rtc_time();
1136 printmsg_time = time + 1040 printmsg_time = time +
1137 (XPC_DISENGAGE_PRINTMSG_INTERVAL * sn_rtc_cycles_per_second); 1041 (XPC_DISENGAGE_PRINTMSG_INTERVAL * sn_rtc_cycles_per_second);
1138 disengage_request_timeout = time + 1042 disengage_request_timeout = time +
1139 (xpc_disengage_request_timelimit * sn_rtc_cycles_per_second); 1043 (xpc_disengage_request_timelimit * sn_rtc_cycles_per_second);
1140 1044
1141 /* wait for all other partitions to disengage from us */ 1045 /* wait for all other partitions to disengage from us */
1142 1046
@@ -1152,8 +1056,8 @@ xpc_die_disengage(void)
1152 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) { 1056 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
1153 if (engaged & (1UL << partid)) { 1057 if (engaged & (1UL << partid)) {
1154 dev_info(xpc_part, "disengage from " 1058 dev_info(xpc_part, "disengage from "
1155 "remote partition %d timed " 1059 "remote partition %d timed "
1156 "out\n", partid); 1060 "out\n", partid);
1157 } 1061 }
1158 } 1062 }
1159 break; 1063 break;
@@ -1161,17 +1065,16 @@ xpc_die_disengage(void)
1161 1065
1162 if (time >= printmsg_time) { 1066 if (time >= printmsg_time) {
1163 dev_info(xpc_part, "waiting for remote partitions to " 1067 dev_info(xpc_part, "waiting for remote partitions to "
1164 "disengage, timeout in %ld seconds\n", 1068 "disengage, timeout in %ld seconds\n",
1165 (disengage_request_timeout - time) / 1069 (disengage_request_timeout - time) /
1166 sn_rtc_cycles_per_second); 1070 sn_rtc_cycles_per_second);
1167 printmsg_time = time + 1071 printmsg_time = time +
1168 (XPC_DISENGAGE_PRINTMSG_INTERVAL * 1072 (XPC_DISENGAGE_PRINTMSG_INTERVAL *
1169 sn_rtc_cycles_per_second); 1073 sn_rtc_cycles_per_second);
1170 } 1074 }
1171 } 1075 }
1172} 1076}
1173 1077
1174
1175/* 1078/*
1176 * This function is called when the system is being restarted or halted due 1079 * This function is called when the system is being restarted or halted due
1177 * to some sort of system failure. If this is the case we need to notify the 1080 * to some sort of system failure. If this is the case we need to notify the
@@ -1191,9 +1094,9 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
1191 1094
1192 case DIE_KDEBUG_ENTER: 1095 case DIE_KDEBUG_ENTER:
1193 /* Should lack of heartbeat be ignored by other partitions? */ 1096 /* Should lack of heartbeat be ignored by other partitions? */
1194 if (!xpc_kdebug_ignore) { 1097 if (!xpc_kdebug_ignore)
1195 break; 1098 break;
1196 } 1099
1197 /* fall through */ 1100 /* fall through */
1198 case DIE_MCA_MONARCH_ENTER: 1101 case DIE_MCA_MONARCH_ENTER:
1199 case DIE_INIT_MONARCH_ENTER: 1102 case DIE_INIT_MONARCH_ENTER:
@@ -1203,9 +1106,9 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
1203 1106
1204 case DIE_KDEBUG_LEAVE: 1107 case DIE_KDEBUG_LEAVE:
1205 /* Is lack of heartbeat being ignored by other partitions? */ 1108 /* Is lack of heartbeat being ignored by other partitions? */
1206 if (!xpc_kdebug_ignore) { 1109 if (!xpc_kdebug_ignore)
1207 break; 1110 break;
1208 } 1111
1209 /* fall through */ 1112 /* fall through */
1210 case DIE_MCA_MONARCH_LEAVE: 1113 case DIE_MCA_MONARCH_LEAVE:
1211 case DIE_INIT_MONARCH_LEAVE: 1114 case DIE_INIT_MONARCH_LEAVE:
@@ -1217,26 +1120,23 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *unused)
1217 return NOTIFY_DONE; 1120 return NOTIFY_DONE;
1218} 1121}
1219 1122
1220
1221int __init 1123int __init
1222xpc_init(void) 1124xpc_init(void)
1223{ 1125{
1224 int ret; 1126 int ret;
1225 partid_t partid; 1127 partid_t partid;
1226 struct xpc_partition *part; 1128 struct xpc_partition *part;
1227 pid_t pid; 1129 struct task_struct *kthread;
1228 size_t buf_size; 1130 size_t buf_size;
1229 1131
1230 1132 if (!ia64_platform_is("sn2"))
1231 if (!ia64_platform_is("sn2")) {
1232 return -ENODEV; 1133 return -ENODEV;
1233 }
1234
1235 1134
1236 buf_size = max(XPC_RP_VARS_SIZE, 1135 buf_size = max(XPC_RP_VARS_SIZE,
1237 XPC_RP_HEADER_SIZE + XP_NASID_MASK_BYTES); 1136 XPC_RP_HEADER_SIZE + XP_NASID_MASK_BYTES);
1238 xpc_remote_copy_buffer = xpc_kmalloc_cacheline_aligned(buf_size, 1137 xpc_remote_copy_buffer = xpc_kmalloc_cacheline_aligned(buf_size,
1239 GFP_KERNEL, &xpc_remote_copy_buffer_base); 1138 GFP_KERNEL,
1139 &xpc_remote_copy_buffer_base);
1240 if (xpc_remote_copy_buffer == NULL) 1140 if (xpc_remote_copy_buffer == NULL)
1241 return -ENOMEM; 1141 return -ENOMEM;
1242 1142
@@ -1256,7 +1156,7 @@ xpc_init(void)
1256 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) { 1156 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
1257 part = &xpc_partitions[partid]; 1157 part = &xpc_partitions[partid];
1258 1158
1259 DBUG_ON((u64) part != L1_CACHE_ALIGN((u64) part)); 1159 DBUG_ON((u64)part != L1_CACHE_ALIGN((u64)part));
1260 1160
1261 part->act_IRQ_rcvd = 0; 1161 part->act_IRQ_rcvd = 0;
1262 spin_lock_init(&part->act_lock); 1162 spin_lock_init(&part->act_lock);
@@ -1265,8 +1165,8 @@ xpc_init(void)
1265 1165
1266 init_timer(&part->disengage_request_timer); 1166 init_timer(&part->disengage_request_timer);
1267 part->disengage_request_timer.function = 1167 part->disengage_request_timer.function =
1268 xpc_timeout_partition_disengage_request; 1168 xpc_timeout_partition_disengage_request;
1269 part->disengage_request_timer.data = (unsigned long) part; 1169 part->disengage_request_timer.data = (unsigned long)part;
1270 1170
1271 part->setup_state = XPC_P_UNSET; 1171 part->setup_state = XPC_P_UNSET;
1272 init_waitqueue_head(&part->teardown_wq); 1172 init_waitqueue_head(&part->teardown_wq);
@@ -1292,16 +1192,15 @@ xpc_init(void)
1292 * but rather immediately process the interrupt. 1192 * but rather immediately process the interrupt.
1293 */ 1193 */
1294 ret = request_irq(SGI_XPC_ACTIVATE, xpc_act_IRQ_handler, 0, 1194 ret = request_irq(SGI_XPC_ACTIVATE, xpc_act_IRQ_handler, 0,
1295 "xpc hb", NULL); 1195 "xpc hb", NULL);
1296 if (ret != 0) { 1196 if (ret != 0) {
1297 dev_err(xpc_part, "can't register ACTIVATE IRQ handler, " 1197 dev_err(xpc_part, "can't register ACTIVATE IRQ handler, "
1298 "errno=%d\n", -ret); 1198 "errno=%d\n", -ret);
1299 1199
1300 xpc_restrict_IPI_ops(); 1200 xpc_restrict_IPI_ops();
1301 1201
1302 if (xpc_sysctl) { 1202 if (xpc_sysctl)
1303 unregister_sysctl_table(xpc_sysctl); 1203 unregister_sysctl_table(xpc_sysctl);
1304 }
1305 1204
1306 kfree(xpc_remote_copy_buffer_base); 1205 kfree(xpc_remote_copy_buffer_base);
1307 return -EBUSY; 1206 return -EBUSY;
@@ -1319,26 +1218,22 @@ xpc_init(void)
1319 free_irq(SGI_XPC_ACTIVATE, NULL); 1218 free_irq(SGI_XPC_ACTIVATE, NULL);
1320 xpc_restrict_IPI_ops(); 1219 xpc_restrict_IPI_ops();
1321 1220
1322 if (xpc_sysctl) { 1221 if (xpc_sysctl)
1323 unregister_sysctl_table(xpc_sysctl); 1222 unregister_sysctl_table(xpc_sysctl);
1324 }
1325 1223
1326 kfree(xpc_remote_copy_buffer_base); 1224 kfree(xpc_remote_copy_buffer_base);
1327 return -EBUSY; 1225 return -EBUSY;
1328 } 1226 }
1329 1227
1330
1331 /* add ourselves to the reboot_notifier_list */ 1228 /* add ourselves to the reboot_notifier_list */
1332 ret = register_reboot_notifier(&xpc_reboot_notifier); 1229 ret = register_reboot_notifier(&xpc_reboot_notifier);
1333 if (ret != 0) { 1230 if (ret != 0)
1334 dev_warn(xpc_part, "can't register reboot notifier\n"); 1231 dev_warn(xpc_part, "can't register reboot notifier\n");
1335 }
1336 1232
1337 /* add ourselves to the die_notifier list */ 1233 /* add ourselves to the die_notifier list */
1338 ret = register_die_notifier(&xpc_die_notifier); 1234 ret = register_die_notifier(&xpc_die_notifier);
1339 if (ret != 0) { 1235 if (ret != 0)
1340 dev_warn(xpc_part, "can't register die notifier\n"); 1236 dev_warn(xpc_part, "can't register die notifier\n");
1341 }
1342 1237
1343 init_timer(&xpc_hb_timer); 1238 init_timer(&xpc_hb_timer);
1344 xpc_hb_timer.function = xpc_hb_beater; 1239 xpc_hb_timer.function = xpc_hb_beater;
@@ -1347,39 +1242,38 @@ xpc_init(void)
1347 * The real work-horse behind xpc. This processes incoming 1242 * The real work-horse behind xpc. This processes incoming
1348 * interrupts and monitors remote heartbeats. 1243 * interrupts and monitors remote heartbeats.
1349 */ 1244 */
1350 pid = kernel_thread(xpc_hb_checker, NULL, 0); 1245 kthread = kthread_run(xpc_hb_checker, NULL, XPC_HB_CHECK_THREAD_NAME);
1351 if (pid < 0) { 1246 if (IS_ERR(kthread)) {
1352 dev_err(xpc_part, "failed while forking hb check thread\n"); 1247 dev_err(xpc_part, "failed while forking hb check thread\n");
1353 1248
1354 /* indicate to others that our reserved page is uninitialized */ 1249 /* indicate to others that our reserved page is uninitialized */
1355 xpc_rsvd_page->vars_pa = 0; 1250 xpc_rsvd_page->vars_pa = 0;
1356 1251
1357 /* take ourselves off of the reboot_notifier_list */ 1252 /* take ourselves off of the reboot_notifier_list */
1358 (void) unregister_reboot_notifier(&xpc_reboot_notifier); 1253 (void)unregister_reboot_notifier(&xpc_reboot_notifier);
1359 1254
1360 /* take ourselves off of the die_notifier list */ 1255 /* take ourselves off of the die_notifier list */
1361 (void) unregister_die_notifier(&xpc_die_notifier); 1256 (void)unregister_die_notifier(&xpc_die_notifier);
1362 1257
1363 del_timer_sync(&xpc_hb_timer); 1258 del_timer_sync(&xpc_hb_timer);
1364 free_irq(SGI_XPC_ACTIVATE, NULL); 1259 free_irq(SGI_XPC_ACTIVATE, NULL);
1365 xpc_restrict_IPI_ops(); 1260 xpc_restrict_IPI_ops();
1366 1261
1367 if (xpc_sysctl) { 1262 if (xpc_sysctl)
1368 unregister_sysctl_table(xpc_sysctl); 1263 unregister_sysctl_table(xpc_sysctl);
1369 }
1370 1264
1371 kfree(xpc_remote_copy_buffer_base); 1265 kfree(xpc_remote_copy_buffer_base);
1372 return -EBUSY; 1266 return -EBUSY;
1373 } 1267 }
1374 1268
1375
1376 /* 1269 /*
1377 * Startup a thread that will attempt to discover other partitions to 1270 * Startup a thread that will attempt to discover other partitions to
1378 * activate based on info provided by SAL. This new thread is short 1271 * activate based on info provided by SAL. This new thread is short
1379 * lived and will exit once discovery is complete. 1272 * lived and will exit once discovery is complete.
1380 */ 1273 */
1381 pid = kernel_thread(xpc_initiate_discovery, NULL, 0); 1274 kthread = kthread_run(xpc_initiate_discovery, NULL,
1382 if (pid < 0) { 1275 XPC_DISCOVERY_THREAD_NAME);
1276 if (IS_ERR(kthread)) {
1383 dev_err(xpc_part, "failed while forking discovery thread\n"); 1277 dev_err(xpc_part, "failed while forking discovery thread\n");
1384 1278
1385 /* mark this new thread as a non-starter */ 1279 /* mark this new thread as a non-starter */
@@ -1389,7 +1283,6 @@ xpc_init(void)
1389 return -EBUSY; 1283 return -EBUSY;
1390 } 1284 }
1391 1285
1392
1393 /* set the interface to point at XPC's functions */ 1286 /* set the interface to point at XPC's functions */
1394 xpc_set_interface(xpc_initiate_connect, xpc_initiate_disconnect, 1287 xpc_set_interface(xpc_initiate_connect, xpc_initiate_disconnect,
1395 xpc_initiate_allocate, xpc_initiate_send, 1288 xpc_initiate_allocate, xpc_initiate_send,
@@ -1398,16 +1291,16 @@ xpc_init(void)
1398 1291
1399 return 0; 1292 return 0;
1400} 1293}
1401module_init(xpc_init);
1402 1294
1295module_init(xpc_init);
1403 1296
1404void __exit 1297void __exit
1405xpc_exit(void) 1298xpc_exit(void)
1406{ 1299{
1407 xpc_do_exit(xpcUnloading); 1300 xpc_do_exit(xpcUnloading);
1408} 1301}
1409module_exit(xpc_exit);
1410 1302
1303module_exit(xpc_exit);
1411 1304
1412MODULE_AUTHOR("Silicon Graphics, Inc."); 1305MODULE_AUTHOR("Silicon Graphics, Inc.");
1413MODULE_DESCRIPTION("Cross Partition Communication (XPC) support"); 1306MODULE_DESCRIPTION("Cross Partition Communication (XPC) support");
@@ -1415,17 +1308,16 @@ MODULE_LICENSE("GPL");
1415 1308
1416module_param(xpc_hb_interval, int, 0); 1309module_param(xpc_hb_interval, int, 0);
1417MODULE_PARM_DESC(xpc_hb_interval, "Number of seconds between " 1310MODULE_PARM_DESC(xpc_hb_interval, "Number of seconds between "
1418 "heartbeat increments."); 1311 "heartbeat increments.");
1419 1312
1420module_param(xpc_hb_check_interval, int, 0); 1313module_param(xpc_hb_check_interval, int, 0);
1421MODULE_PARM_DESC(xpc_hb_check_interval, "Number of seconds between " 1314MODULE_PARM_DESC(xpc_hb_check_interval, "Number of seconds between "
1422 "heartbeat checks."); 1315 "heartbeat checks.");
1423 1316
1424module_param(xpc_disengage_request_timelimit, int, 0); 1317module_param(xpc_disengage_request_timelimit, int, 0);
1425MODULE_PARM_DESC(xpc_disengage_request_timelimit, "Number of seconds to wait " 1318MODULE_PARM_DESC(xpc_disengage_request_timelimit, "Number of seconds to wait "
1426 "for disengage request to complete."); 1319 "for disengage request to complete.");
1427 1320
1428module_param(xpc_kdebug_ignore, int, 0); 1321module_param(xpc_kdebug_ignore, int, 0);
1429MODULE_PARM_DESC(xpc_kdebug_ignore, "Should lack of heartbeat be ignored by " 1322MODULE_PARM_DESC(xpc_kdebug_ignore, "Should lack of heartbeat be ignored by "
1430 "other partitions when dropping into kdebug."); 1323 "other partitions when dropping into kdebug.");
1431
diff --git a/arch/ia64/sn/kernel/xpc_partition.c b/drivers/misc/sgi-xp/xpc_partition.c
index 9e97c2684832..27e200ec5826 100644
--- a/arch/ia64/sn/kernel/xpc_partition.c
+++ b/drivers/misc/sgi-xp/xpc_partition.c
@@ -3,10 +3,9 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (c) 2004-2006 Silicon Graphics, Inc. All Rights Reserved. 6 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
7 */ 7 */
8 8
9
10/* 9/*
11 * Cross Partition Communication (XPC) partition support. 10 * Cross Partition Communication (XPC) partition support.
12 * 11 *
@@ -16,7 +15,6 @@
16 * 15 *
17 */ 16 */
18 17
19
20#include <linux/kernel.h> 18#include <linux/kernel.h>
21#include <linux/sysctl.h> 19#include <linux/sysctl.h>
22#include <linux/cache.h> 20#include <linux/cache.h>
@@ -28,13 +26,11 @@
28#include <asm/sn/sn_sal.h> 26#include <asm/sn/sn_sal.h>
29#include <asm/sn/nodepda.h> 27#include <asm/sn/nodepda.h>
30#include <asm/sn/addrs.h> 28#include <asm/sn/addrs.h>
31#include <asm/sn/xpc.h> 29#include "xpc.h"
32
33 30
34/* XPC is exiting flag */ 31/* XPC is exiting flag */
35int xpc_exiting; 32int xpc_exiting;
36 33
37
38/* SH_IPI_ACCESS shub register value on startup */ 34/* SH_IPI_ACCESS shub register value on startup */
39static u64 xpc_sh1_IPI_access; 35static u64 xpc_sh1_IPI_access;
40static u64 xpc_sh2_IPI_access0; 36static u64 xpc_sh2_IPI_access0;
@@ -42,11 +38,9 @@ static u64 xpc_sh2_IPI_access1;
42static u64 xpc_sh2_IPI_access2; 38static u64 xpc_sh2_IPI_access2;
43static u64 xpc_sh2_IPI_access3; 39static u64 xpc_sh2_IPI_access3;
44 40
45
46/* original protection values for each node */ 41/* original protection values for each node */
47u64 xpc_prot_vec[MAX_NUMNODES]; 42u64 xpc_prot_vec[MAX_NUMNODES];
48 43
49
50/* this partition's reserved page pointers */ 44/* this partition's reserved page pointers */
51struct xpc_rsvd_page *xpc_rsvd_page; 45struct xpc_rsvd_page *xpc_rsvd_page;
52static u64 *xpc_part_nasids; 46static u64 *xpc_part_nasids;
@@ -57,7 +51,6 @@ struct xpc_vars_part *xpc_vars_part;
57static int xp_nasid_mask_bytes; /* actual size in bytes of nasid mask */ 51static int xp_nasid_mask_bytes; /* actual size in bytes of nasid mask */
58static int xp_nasid_mask_words; /* actual size in words of nasid mask */ 52static int xp_nasid_mask_words; /* actual size in words of nasid mask */
59 53
60
61/* 54/*
62 * For performance reasons, each entry of xpc_partitions[] is cacheline 55 * For performance reasons, each entry of xpc_partitions[] is cacheline
63 * aligned. And xpc_partitions[] is padded with an additional entry at the 56 * aligned. And xpc_partitions[] is padded with an additional entry at the
@@ -66,7 +59,6 @@ static int xp_nasid_mask_words; /* actual size in words of nasid mask */
66 */ 59 */
67struct xpc_partition xpc_partitions[XP_MAX_PARTITIONS + 1]; 60struct xpc_partition xpc_partitions[XP_MAX_PARTITIONS + 1];
68 61
69
70/* 62/*
71 * Generic buffer used to store a local copy of portions of a remote 63 * Generic buffer used to store a local copy of portions of a remote
72 * partition's reserved page (either its header and part_nasids mask, 64 * partition's reserved page (either its header and part_nasids mask,
@@ -75,7 +67,6 @@ struct xpc_partition xpc_partitions[XP_MAX_PARTITIONS + 1];
75char *xpc_remote_copy_buffer; 67char *xpc_remote_copy_buffer;
76void *xpc_remote_copy_buffer_base; 68void *xpc_remote_copy_buffer_base;
77 69
78
79/* 70/*
80 * Guarantee that the kmalloc'd memory is cacheline aligned. 71 * Guarantee that the kmalloc'd memory is cacheline aligned.
81 */ 72 */
@@ -84,22 +75,21 @@ xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
84{ 75{
85 /* see if kmalloc will give us cachline aligned memory by default */ 76 /* see if kmalloc will give us cachline aligned memory by default */
86 *base = kmalloc(size, flags); 77 *base = kmalloc(size, flags);
87 if (*base == NULL) { 78 if (*base == NULL)
88 return NULL; 79 return NULL;
89 } 80
90 if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) { 81 if ((u64)*base == L1_CACHE_ALIGN((u64)*base))
91 return *base; 82 return *base;
92 } 83
93 kfree(*base); 84 kfree(*base);
94 85
95 /* nope, we'll have to do it ourselves */ 86 /* nope, we'll have to do it ourselves */
96 *base = kmalloc(size + L1_CACHE_BYTES, flags); 87 *base = kmalloc(size + L1_CACHE_BYTES, flags);
97 if (*base == NULL) { 88 if (*base == NULL)
98 return NULL; 89 return NULL;
99 }
100 return (void *) L1_CACHE_ALIGN((u64) *base);
101}
102 90
91 return (void *)L1_CACHE_ALIGN((u64)*base);
92}
103 93
104/* 94/*
105 * Given a nasid, get the physical address of the partition's reserved page 95 * Given a nasid, get the physical address of the partition's reserved page
@@ -117,25 +107,24 @@ xpc_get_rsvd_page_pa(int nasid)
117 u64 buf_len = 0; 107 u64 buf_len = 0;
118 void *buf_base = NULL; 108 void *buf_base = NULL;
119 109
120
121 while (1) { 110 while (1) {
122 111
123 status = sn_partition_reserved_page_pa(buf, &cookie, &rp_pa, 112 status = sn_partition_reserved_page_pa(buf, &cookie, &rp_pa,
124 &len); 113 &len);
125 114
126 dev_dbg(xpc_part, "SAL returned with status=%li, cookie=" 115 dev_dbg(xpc_part, "SAL returned with status=%li, cookie="
127 "0x%016lx, address=0x%016lx, len=0x%016lx\n", 116 "0x%016lx, address=0x%016lx, len=0x%016lx\n",
128 status, cookie, rp_pa, len); 117 status, cookie, rp_pa, len);
129 118
130 if (status != SALRET_MORE_PASSES) { 119 if (status != SALRET_MORE_PASSES)
131 break; 120 break;
132 }
133 121
134 if (L1_CACHE_ALIGN(len) > buf_len) { 122 if (L1_CACHE_ALIGN(len) > buf_len) {
135 kfree(buf_base); 123 kfree(buf_base);
136 buf_len = L1_CACHE_ALIGN(len); 124 buf_len = L1_CACHE_ALIGN(len);
137 buf = (u64) xpc_kmalloc_cacheline_aligned(buf_len, 125 buf = (u64)xpc_kmalloc_cacheline_aligned(buf_len,
138 GFP_KERNEL, &buf_base); 126 GFP_KERNEL,
127 &buf_base);
139 if (buf_base == NULL) { 128 if (buf_base == NULL) {
140 dev_err(xpc_part, "unable to kmalloc " 129 dev_err(xpc_part, "unable to kmalloc "
141 "len=0x%016lx\n", buf_len); 130 "len=0x%016lx\n", buf_len);
@@ -145,7 +134,7 @@ xpc_get_rsvd_page_pa(int nasid)
145 } 134 }
146 135
147 bte_res = xp_bte_copy(rp_pa, buf, buf_len, 136 bte_res = xp_bte_copy(rp_pa, buf, buf_len,
148 (BTE_NOTIFY | BTE_WACQUIRE), NULL); 137 (BTE_NOTIFY | BTE_WACQUIRE), NULL);
149 if (bte_res != BTE_SUCCESS) { 138 if (bte_res != BTE_SUCCESS) {
150 dev_dbg(xpc_part, "xp_bte_copy failed %i\n", bte_res); 139 dev_dbg(xpc_part, "xp_bte_copy failed %i\n", bte_res);
151 status = SALRET_ERROR; 140 status = SALRET_ERROR;
@@ -155,14 +144,13 @@ xpc_get_rsvd_page_pa(int nasid)
155 144
156 kfree(buf_base); 145 kfree(buf_base);
157 146
158 if (status != SALRET_OK) { 147 if (status != SALRET_OK)
159 rp_pa = 0; 148 rp_pa = 0;
160 } 149
161 dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa); 150 dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa);
162 return rp_pa; 151 return rp_pa;
163} 152}
164 153
165
166/* 154/*
167 * Fill the partition reserved page with the information needed by 155 * Fill the partition reserved page with the information needed by
168 * other partitions to discover we are alive and establish initial 156 * other partitions to discover we are alive and establish initial
@@ -176,7 +164,6 @@ xpc_rsvd_page_init(void)
176 u64 rp_pa, nasid_array = 0; 164 u64 rp_pa, nasid_array = 0;
177 int i, ret; 165 int i, ret;
178 166
179
180 /* get the local reserved page's address */ 167 /* get the local reserved page's address */
181 168
182 preempt_disable(); 169 preempt_disable();
@@ -186,7 +173,7 @@ xpc_rsvd_page_init(void)
186 dev_err(xpc_part, "SAL failed to locate the reserved page\n"); 173 dev_err(xpc_part, "SAL failed to locate the reserved page\n");
187 return NULL; 174 return NULL;
188 } 175 }
189 rp = (struct xpc_rsvd_page *) __va(rp_pa); 176 rp = (struct xpc_rsvd_page *)__va(rp_pa);
190 177
191 if (rp->partid != sn_partition_id) { 178 if (rp->partid != sn_partition_id) {
192 dev_err(xpc_part, "the reserved page's partid of %d should be " 179 dev_err(xpc_part, "the reserved page's partid of %d should be "
@@ -222,8 +209,9 @@ xpc_rsvd_page_init(void)
222 * on subsequent loads of XPC. This AMO page is never freed, and its 209 * on subsequent loads of XPC. This AMO page is never freed, and its
223 * memory protections are never restricted. 210 * memory protections are never restricted.
224 */ 211 */
225 if ((amos_page = xpc_vars->amos_page) == NULL) { 212 amos_page = xpc_vars->amos_page;
226 amos_page = (AMO_t *) TO_AMO(uncached_alloc_page(0)); 213 if (amos_page == NULL) {
214 amos_page = (AMO_t *)TO_AMO(uncached_alloc_page(0));
227 if (amos_page == NULL) { 215 if (amos_page == NULL) {
228 dev_err(xpc_part, "can't allocate page of AMOs\n"); 216 dev_err(xpc_part, "can't allocate page of AMOs\n");
229 return NULL; 217 return NULL;
@@ -234,30 +222,31 @@ xpc_rsvd_page_init(void)
234 * when xpc_allow_IPI_ops() is called via xpc_hb_init(). 222 * when xpc_allow_IPI_ops() is called via xpc_hb_init().
235 */ 223 */
236 if (!enable_shub_wars_1_1()) { 224 if (!enable_shub_wars_1_1()) {
237 ret = sn_change_memprotect(ia64_tpa((u64) amos_page), 225 ret = sn_change_memprotect(ia64_tpa((u64)amos_page),
238 PAGE_SIZE, SN_MEMPROT_ACCESS_CLASS_1, 226 PAGE_SIZE,
239 &nasid_array); 227 SN_MEMPROT_ACCESS_CLASS_1,
228 &nasid_array);
240 if (ret != 0) { 229 if (ret != 0) {
241 dev_err(xpc_part, "can't change memory " 230 dev_err(xpc_part, "can't change memory "
242 "protections\n"); 231 "protections\n");
243 uncached_free_page(__IA64_UNCACHED_OFFSET | 232 uncached_free_page(__IA64_UNCACHED_OFFSET |
244 TO_PHYS((u64) amos_page)); 233 TO_PHYS((u64)amos_page));
245 return NULL; 234 return NULL;
246 } 235 }
247 } 236 }
248 } else if (!IS_AMO_ADDRESS((u64) amos_page)) { 237 } else if (!IS_AMO_ADDRESS((u64)amos_page)) {
249 /* 238 /*
250 * EFI's XPBOOT can also set amos_page in the reserved page, 239 * EFI's XPBOOT can also set amos_page in the reserved page,
251 * but it happens to leave it as an uncached physical address 240 * but it happens to leave it as an uncached physical address
252 * and we need it to be an uncached virtual, so we'll have to 241 * and we need it to be an uncached virtual, so we'll have to
253 * convert it. 242 * convert it.
254 */ 243 */
255 if (!IS_AMO_PHYS_ADDRESS((u64) amos_page)) { 244 if (!IS_AMO_PHYS_ADDRESS((u64)amos_page)) {
256 dev_err(xpc_part, "previously used amos_page address " 245 dev_err(xpc_part, "previously used amos_page address "
257 "is bad = 0x%p\n", (void *) amos_page); 246 "is bad = 0x%p\n", (void *)amos_page);
258 return NULL; 247 return NULL;
259 } 248 }
260 amos_page = (AMO_t *) TO_AMO((u64) amos_page); 249 amos_page = (AMO_t *)TO_AMO((u64)amos_page);
261 } 250 }
262 251
263 /* clear xpc_vars */ 252 /* clear xpc_vars */
@@ -267,22 +256,20 @@ xpc_rsvd_page_init(void)
267 xpc_vars->act_nasid = cpuid_to_nasid(0); 256 xpc_vars->act_nasid = cpuid_to_nasid(0);
268 xpc_vars->act_phys_cpuid = cpu_physical_id(0); 257 xpc_vars->act_phys_cpuid = cpu_physical_id(0);
269 xpc_vars->vars_part_pa = __pa(xpc_vars_part); 258 xpc_vars->vars_part_pa = __pa(xpc_vars_part);
270 xpc_vars->amos_page_pa = ia64_tpa((u64) amos_page); 259 xpc_vars->amos_page_pa = ia64_tpa((u64)amos_page);
271 xpc_vars->amos_page = amos_page; /* save for next load of XPC */ 260 xpc_vars->amos_page = amos_page; /* save for next load of XPC */
272
273 261
274 /* clear xpc_vars_part */ 262 /* clear xpc_vars_part */
275 memset((u64 *) xpc_vars_part, 0, sizeof(struct xpc_vars_part) * 263 memset((u64 *)xpc_vars_part, 0, sizeof(struct xpc_vars_part) *
276 XP_MAX_PARTITIONS); 264 XP_MAX_PARTITIONS);
277 265
278 /* initialize the activate IRQ related AMO variables */ 266 /* initialize the activate IRQ related AMO variables */
279 for (i = 0; i < xp_nasid_mask_words; i++) { 267 for (i = 0; i < xp_nasid_mask_words; i++)
280 (void) xpc_IPI_init(XPC_ACTIVATE_IRQ_AMOS + i); 268 (void)xpc_IPI_init(XPC_ACTIVATE_IRQ_AMOS + i);
281 }
282 269
283 /* initialize the engaged remote partitions related AMO variables */ 270 /* initialize the engaged remote partitions related AMO variables */
284 (void) xpc_IPI_init(XPC_ENGAGED_PARTITIONS_AMO); 271 (void)xpc_IPI_init(XPC_ENGAGED_PARTITIONS_AMO);
285 (void) xpc_IPI_init(XPC_DISENGAGE_REQUEST_AMO); 272 (void)xpc_IPI_init(XPC_DISENGAGE_REQUEST_AMO);
286 273
287 /* timestamp of when reserved page was setup by XPC */ 274 /* timestamp of when reserved page was setup by XPC */
288 rp->stamp = CURRENT_TIME; 275 rp->stamp = CURRENT_TIME;
@@ -296,7 +283,6 @@ xpc_rsvd_page_init(void)
296 return rp; 283 return rp;
297} 284}
298 285
299
300/* 286/*
301 * Change protections to allow IPI operations (and AMO operations on 287 * Change protections to allow IPI operations (and AMO operations on
302 * Shub 1.1 systems). 288 * Shub 1.1 systems).
@@ -307,39 +293,38 @@ xpc_allow_IPI_ops(void)
307 int node; 293 int node;
308 int nasid; 294 int nasid;
309 295
310 296 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
311 // >>> Change SH_IPI_ACCESS code to use SAL call once it is available.
312 297
313 if (is_shub2()) { 298 if (is_shub2()) {
314 xpc_sh2_IPI_access0 = 299 xpc_sh2_IPI_access0 =
315 (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS0)); 300 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS0));
316 xpc_sh2_IPI_access1 = 301 xpc_sh2_IPI_access1 =
317 (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS1)); 302 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS1));
318 xpc_sh2_IPI_access2 = 303 xpc_sh2_IPI_access2 =
319 (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS2)); 304 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS2));
320 xpc_sh2_IPI_access3 = 305 xpc_sh2_IPI_access3 =
321 (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH2_IPI_ACCESS3)); 306 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH2_IPI_ACCESS3));
322 307
323 for_each_online_node(node) { 308 for_each_online_node(node) {
324 nasid = cnodeid_to_nasid(node); 309 nasid = cnodeid_to_nasid(node);
325 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0), 310 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
326 -1UL); 311 -1UL);
327 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1), 312 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
328 -1UL); 313 -1UL);
329 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2), 314 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
330 -1UL); 315 -1UL);
331 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3), 316 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
332 -1UL); 317 -1UL);
333 } 318 }
334 319
335 } else { 320 } else {
336 xpc_sh1_IPI_access = 321 xpc_sh1_IPI_access =
337 (u64) HUB_L((u64 *) LOCAL_MMR_ADDR(SH1_IPI_ACCESS)); 322 (u64)HUB_L((u64 *)LOCAL_MMR_ADDR(SH1_IPI_ACCESS));
338 323
339 for_each_online_node(node) { 324 for_each_online_node(node) {
340 nasid = cnodeid_to_nasid(node); 325 nasid = cnodeid_to_nasid(node);
341 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS), 326 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
342 -1UL); 327 -1UL);
343 328
344 /* 329 /*
345 * Since the BIST collides with memory operations on 330 * Since the BIST collides with memory operations on
@@ -347,21 +332,23 @@ xpc_allow_IPI_ops(void)
347 */ 332 */
348 if (enable_shub_wars_1_1()) { 333 if (enable_shub_wars_1_1()) {
349 /* open up everything */ 334 /* open up everything */
350 xpc_prot_vec[node] = (u64) HUB_L((u64 *) 335 xpc_prot_vec[node] = (u64)HUB_L((u64 *)
351 GLOBAL_MMR_ADDR(nasid, 336 GLOBAL_MMR_ADDR
352 SH1_MD_DQLP_MMR_DIR_PRIVEC0)); 337 (nasid,
353 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, 338 SH1_MD_DQLP_MMR_DIR_PRIVEC0));
354 SH1_MD_DQLP_MMR_DIR_PRIVEC0), 339 HUB_S((u64 *)
355 -1UL); 340 GLOBAL_MMR_ADDR(nasid,
356 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, 341 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
357 SH1_MD_DQRP_MMR_DIR_PRIVEC0), 342 -1UL);
358 -1UL); 343 HUB_S((u64 *)
344 GLOBAL_MMR_ADDR(nasid,
345 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
346 -1UL);
359 } 347 }
360 } 348 }
361 } 349 }
362} 350}
363 351
364
365/* 352/*
366 * Restrict protections to disallow IPI operations (and AMO operations on 353 * Restrict protections to disallow IPI operations (and AMO operations on
367 * Shub 1.1 systems). 354 * Shub 1.1 systems).
@@ -372,43 +359,41 @@ xpc_restrict_IPI_ops(void)
372 int node; 359 int node;
373 int nasid; 360 int nasid;
374 361
375 362 /* >>> Change SH_IPI_ACCESS code to use SAL call once it is available */
376 // >>> Change SH_IPI_ACCESS code to use SAL call once it is available.
377 363
378 if (is_shub2()) { 364 if (is_shub2()) {
379 365
380 for_each_online_node(node) { 366 for_each_online_node(node) {
381 nasid = cnodeid_to_nasid(node); 367 nasid = cnodeid_to_nasid(node);
382 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0), 368 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS0),
383 xpc_sh2_IPI_access0); 369 xpc_sh2_IPI_access0);
384 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1), 370 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS1),
385 xpc_sh2_IPI_access1); 371 xpc_sh2_IPI_access1);
386 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2), 372 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS2),
387 xpc_sh2_IPI_access2); 373 xpc_sh2_IPI_access2);
388 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3), 374 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH2_IPI_ACCESS3),
389 xpc_sh2_IPI_access3); 375 xpc_sh2_IPI_access3);
390 } 376 }
391 377
392 } else { 378 } else {
393 379
394 for_each_online_node(node) { 380 for_each_online_node(node) {
395 nasid = cnodeid_to_nasid(node); 381 nasid = cnodeid_to_nasid(node);
396 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS), 382 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid, SH1_IPI_ACCESS),
397 xpc_sh1_IPI_access); 383 xpc_sh1_IPI_access);
398 384
399 if (enable_shub_wars_1_1()) { 385 if (enable_shub_wars_1_1()) {
400 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, 386 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
401 SH1_MD_DQLP_MMR_DIR_PRIVEC0), 387 SH1_MD_DQLP_MMR_DIR_PRIVEC0),
402 xpc_prot_vec[node]); 388 xpc_prot_vec[node]);
403 HUB_S((u64 *) GLOBAL_MMR_ADDR(nasid, 389 HUB_S((u64 *)GLOBAL_MMR_ADDR(nasid,
404 SH1_MD_DQRP_MMR_DIR_PRIVEC0), 390 SH1_MD_DQRP_MMR_DIR_PRIVEC0),
405 xpc_prot_vec[node]); 391 xpc_prot_vec[node]);
406 } 392 }
407 } 393 }
408 } 394 }
409} 395}
410 396
411
412/* 397/*
413 * At periodic intervals, scan through all active partitions and ensure 398 * At periodic intervals, scan through all active partitions and ensure
414 * their heartbeat is still active. If not, the partition is deactivated. 399 * their heartbeat is still active. If not, the partition is deactivated.
@@ -421,34 +406,31 @@ xpc_check_remote_hb(void)
421 partid_t partid; 406 partid_t partid;
422 bte_result_t bres; 407 bte_result_t bres;
423 408
424 409 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
425 remote_vars = (struct xpc_vars *) xpc_remote_copy_buffer;
426 410
427 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) { 411 for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
428 412
429 if (xpc_exiting) { 413 if (xpc_exiting)
430 break; 414 break;
431 }
432 415
433 if (partid == sn_partition_id) { 416 if (partid == sn_partition_id)
434 continue; 417 continue;
435 }
436 418
437 part = &xpc_partitions[partid]; 419 part = &xpc_partitions[partid];
438 420
439 if (part->act_state == XPC_P_INACTIVE || 421 if (part->act_state == XPC_P_INACTIVE ||
440 part->act_state == XPC_P_DEACTIVATING) { 422 part->act_state == XPC_P_DEACTIVATING) {
441 continue; 423 continue;
442 } 424 }
443 425
444 /* pull the remote_hb cache line */ 426 /* pull the remote_hb cache line */
445 bres = xp_bte_copy(part->remote_vars_pa, 427 bres = xp_bte_copy(part->remote_vars_pa,
446 (u64) remote_vars, 428 (u64)remote_vars,
447 XPC_RP_VARS_SIZE, 429 XPC_RP_VARS_SIZE,
448 (BTE_NOTIFY | BTE_WACQUIRE), NULL); 430 (BTE_NOTIFY | BTE_WACQUIRE), NULL);
449 if (bres != BTE_SUCCESS) { 431 if (bres != BTE_SUCCESS) {
450 XPC_DEACTIVATE_PARTITION(part, 432 XPC_DEACTIVATE_PARTITION(part,
451 xpc_map_bte_errors(bres)); 433 xpc_map_bte_errors(bres));
452 continue; 434 continue;
453 } 435 }
454 436
@@ -459,8 +441,8 @@ xpc_check_remote_hb(void)
459 remote_vars->heartbeating_to_mask); 441 remote_vars->heartbeating_to_mask);
460 442
461 if (((remote_vars->heartbeat == part->last_heartbeat) && 443 if (((remote_vars->heartbeat == part->last_heartbeat) &&
462 (remote_vars->heartbeat_offline == 0)) || 444 (remote_vars->heartbeat_offline == 0)) ||
463 !xpc_hb_allowed(sn_partition_id, remote_vars)) { 445 !xpc_hb_allowed(sn_partition_id, remote_vars)) {
464 446
465 XPC_DEACTIVATE_PARTITION(part, xpcNoHeartbeat); 447 XPC_DEACTIVATE_PARTITION(part, xpcNoHeartbeat);
466 continue; 448 continue;
@@ -470,7 +452,6 @@ xpc_check_remote_hb(void)
470 } 452 }
471} 453}
472 454
473
474/* 455/*
475 * Get a copy of a portion of the remote partition's rsvd page. 456 * Get a copy of a portion of the remote partition's rsvd page.
476 * 457 *
@@ -480,59 +461,48 @@ xpc_check_remote_hb(void)
480 */ 461 */
481static enum xpc_retval 462static enum xpc_retval
482xpc_get_remote_rp(int nasid, u64 *discovered_nasids, 463xpc_get_remote_rp(int nasid, u64 *discovered_nasids,
483 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa) 464 struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa)
484{ 465{
485 int bres, i; 466 int bres, i;
486 467
487
488 /* get the reserved page's physical address */ 468 /* get the reserved page's physical address */
489 469
490 *remote_rp_pa = xpc_get_rsvd_page_pa(nasid); 470 *remote_rp_pa = xpc_get_rsvd_page_pa(nasid);
491 if (*remote_rp_pa == 0) { 471 if (*remote_rp_pa == 0)
492 return xpcNoRsvdPageAddr; 472 return xpcNoRsvdPageAddr;
493 }
494
495 473
496 /* pull over the reserved page header and part_nasids mask */ 474 /* pull over the reserved page header and part_nasids mask */
497 bres = xp_bte_copy(*remote_rp_pa, (u64) remote_rp, 475 bres = xp_bte_copy(*remote_rp_pa, (u64)remote_rp,
498 XPC_RP_HEADER_SIZE + xp_nasid_mask_bytes, 476 XPC_RP_HEADER_SIZE + xp_nasid_mask_bytes,
499 (BTE_NOTIFY | BTE_WACQUIRE), NULL); 477 (BTE_NOTIFY | BTE_WACQUIRE), NULL);
500 if (bres != BTE_SUCCESS) { 478 if (bres != BTE_SUCCESS)
501 return xpc_map_bte_errors(bres); 479 return xpc_map_bte_errors(bres);
502 }
503
504 480
505 if (discovered_nasids != NULL) { 481 if (discovered_nasids != NULL) {
506 u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp); 482 u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp);
507 483
508 484 for (i = 0; i < xp_nasid_mask_words; i++)
509 for (i = 0; i < xp_nasid_mask_words; i++) {
510 discovered_nasids[i] |= remote_part_nasids[i]; 485 discovered_nasids[i] |= remote_part_nasids[i];
511 }
512 } 486 }
513 487
514
515 /* check that the partid is for another partition */ 488 /* check that the partid is for another partition */
516 489
517 if (remote_rp->partid < 1 || 490 if (remote_rp->partid < 1 ||
518 remote_rp->partid > (XP_MAX_PARTITIONS - 1)) { 491 remote_rp->partid > (XP_MAX_PARTITIONS - 1)) {
519 return xpcInvalidPartid; 492 return xpcInvalidPartid;
520 } 493 }
521 494
522 if (remote_rp->partid == sn_partition_id) { 495 if (remote_rp->partid == sn_partition_id)
523 return xpcLocalPartid; 496 return xpcLocalPartid;
524 }
525
526 497
527 if (XPC_VERSION_MAJOR(remote_rp->version) != 498 if (XPC_VERSION_MAJOR(remote_rp->version) !=
528 XPC_VERSION_MAJOR(XPC_RP_VERSION)) { 499 XPC_VERSION_MAJOR(XPC_RP_VERSION)) {
529 return xpcBadVersion; 500 return xpcBadVersion;
530 } 501 }
531 502
532 return xpcSuccess; 503 return xpcSuccess;
533} 504}
534 505
535
536/* 506/*
537 * Get a copy of the remote partition's XPC variables from the reserved page. 507 * Get a copy of the remote partition's XPC variables from the reserved page.
538 * 508 *
@@ -544,34 +514,30 @@ xpc_get_remote_vars(u64 remote_vars_pa, struct xpc_vars *remote_vars)
544{ 514{
545 int bres; 515 int bres;
546 516
547 517 if (remote_vars_pa == 0)
548 if (remote_vars_pa == 0) {
549 return xpcVarsNotSet; 518 return xpcVarsNotSet;
550 }
551 519
552 /* pull over the cross partition variables */ 520 /* pull over the cross partition variables */
553 bres = xp_bte_copy(remote_vars_pa, (u64) remote_vars, XPC_RP_VARS_SIZE, 521 bres = xp_bte_copy(remote_vars_pa, (u64)remote_vars, XPC_RP_VARS_SIZE,
554 (BTE_NOTIFY | BTE_WACQUIRE), NULL); 522 (BTE_NOTIFY | BTE_WACQUIRE), NULL);
555 if (bres != BTE_SUCCESS) { 523 if (bres != BTE_SUCCESS)
556 return xpc_map_bte_errors(bres); 524 return xpc_map_bte_errors(bres);
557 }
558 525
559 if (XPC_VERSION_MAJOR(remote_vars->version) != 526 if (XPC_VERSION_MAJOR(remote_vars->version) !=
560 XPC_VERSION_MAJOR(XPC_V_VERSION)) { 527 XPC_VERSION_MAJOR(XPC_V_VERSION)) {
561 return xpcBadVersion; 528 return xpcBadVersion;
562 } 529 }
563 530
564 return xpcSuccess; 531 return xpcSuccess;
565} 532}
566 533
567
568/* 534/*
569 * Update the remote partition's info. 535 * Update the remote partition's info.
570 */ 536 */
571static void 537static void
572xpc_update_partition_info(struct xpc_partition *part, u8 remote_rp_version, 538xpc_update_partition_info(struct xpc_partition *part, u8 remote_rp_version,
573 struct timespec *remote_rp_stamp, u64 remote_rp_pa, 539 struct timespec *remote_rp_stamp, u64 remote_rp_pa,
574 u64 remote_vars_pa, struct xpc_vars *remote_vars) 540 u64 remote_vars_pa, struct xpc_vars *remote_vars)
575{ 541{
576 part->remote_rp_version = remote_rp_version; 542 part->remote_rp_version = remote_rp_version;
577 dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n", 543 dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n",
@@ -613,7 +579,6 @@ xpc_update_partition_info(struct xpc_partition *part, u8 remote_rp_version,
613 part->remote_vars_version); 579 part->remote_vars_version);
614} 580}
615 581
616
617/* 582/*
618 * Prior code has determined the nasid which generated an IPI. Inspect 583 * Prior code has determined the nasid which generated an IPI. Inspect
619 * that nasid to determine if its partition needs to be activated or 584 * that nasid to determine if its partition needs to be activated or
@@ -643,54 +608,51 @@ xpc_identify_act_IRQ_req(int nasid)
643 struct xpc_partition *part; 608 struct xpc_partition *part;
644 enum xpc_retval ret; 609 enum xpc_retval ret;
645 610
646
647 /* pull over the reserved page structure */ 611 /* pull over the reserved page structure */
648 612
649 remote_rp = (struct xpc_rsvd_page *) xpc_remote_copy_buffer; 613 remote_rp = (struct xpc_rsvd_page *)xpc_remote_copy_buffer;
650 614
651 ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa); 615 ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa);
652 if (ret != xpcSuccess) { 616 if (ret != xpcSuccess) {
653 dev_warn(xpc_part, "unable to get reserved page from nasid %d, " 617 dev_warn(xpc_part, "unable to get reserved page from nasid %d, "
654 "which sent interrupt, reason=%d\n", nasid, ret); 618 "which sent interrupt, reason=%d\n", nasid, ret);
655 return; 619 return;
656 } 620 }
657 621
658 remote_vars_pa = remote_rp->vars_pa; 622 remote_vars_pa = remote_rp->vars_pa;
659 remote_rp_version = remote_rp->version; 623 remote_rp_version = remote_rp->version;
660 if (XPC_SUPPORTS_RP_STAMP(remote_rp_version)) { 624 if (XPC_SUPPORTS_RP_STAMP(remote_rp_version))
661 remote_rp_stamp = remote_rp->stamp; 625 remote_rp_stamp = remote_rp->stamp;
662 } 626
663 partid = remote_rp->partid; 627 partid = remote_rp->partid;
664 part = &xpc_partitions[partid]; 628 part = &xpc_partitions[partid];
665 629
666
667 /* pull over the cross partition variables */ 630 /* pull over the cross partition variables */
668 631
669 remote_vars = (struct xpc_vars *) xpc_remote_copy_buffer; 632 remote_vars = (struct xpc_vars *)xpc_remote_copy_buffer;
670 633
671 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars); 634 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
672 if (ret != xpcSuccess) { 635 if (ret != xpcSuccess) {
673 636
674 dev_warn(xpc_part, "unable to get XPC variables from nasid %d, " 637 dev_warn(xpc_part, "unable to get XPC variables from nasid %d, "
675 "which sent interrupt, reason=%d\n", nasid, ret); 638 "which sent interrupt, reason=%d\n", nasid, ret);
676 639
677 XPC_DEACTIVATE_PARTITION(part, ret); 640 XPC_DEACTIVATE_PARTITION(part, ret);
678 return; 641 return;
679 } 642 }
680 643
681
682 part->act_IRQ_rcvd++; 644 part->act_IRQ_rcvd++;
683 645
684 dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = " 646 dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = "
685 "%ld:0x%lx\n", (int) nasid, (int) partid, part->act_IRQ_rcvd, 647 "%ld:0x%lx\n", (int)nasid, (int)partid, part->act_IRQ_rcvd,
686 remote_vars->heartbeat, remote_vars->heartbeating_to_mask); 648 remote_vars->heartbeat, remote_vars->heartbeating_to_mask);
687 649
688 if (xpc_partition_disengaged(part) && 650 if (xpc_partition_disengaged(part) &&
689 part->act_state == XPC_P_INACTIVE) { 651 part->act_state == XPC_P_INACTIVE) {
690 652
691 xpc_update_partition_info(part, remote_rp_version, 653 xpc_update_partition_info(part, remote_rp_version,
692 &remote_rp_stamp, remote_rp_pa, 654 &remote_rp_stamp, remote_rp_pa,
693 remote_vars_pa, remote_vars); 655 remote_vars_pa, remote_vars);
694 656
695 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) { 657 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) {
696 if (xpc_partition_disengage_requested(1UL << partid)) { 658 if (xpc_partition_disengage_requested(1UL << partid)) {
@@ -714,16 +676,15 @@ xpc_identify_act_IRQ_req(int nasid)
714 676
715 if (!XPC_SUPPORTS_RP_STAMP(part->remote_rp_version)) { 677 if (!XPC_SUPPORTS_RP_STAMP(part->remote_rp_version)) {
716 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(part-> 678 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(part->
717 remote_vars_version)); 679 remote_vars_version));
718 680
719 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) { 681 if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) {
720 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars-> 682 DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
721 version)); 683 version));
722 /* see if the other side rebooted */ 684 /* see if the other side rebooted */
723 if (part->remote_amos_page_pa == 685 if (part->remote_amos_page_pa ==
724 remote_vars->amos_page_pa && 686 remote_vars->amos_page_pa &&
725 xpc_hb_allowed(sn_partition_id, 687 xpc_hb_allowed(sn_partition_id, remote_vars)) {
726 remote_vars)) {
727 /* doesn't look that way, so ignore the IPI */ 688 /* doesn't look that way, so ignore the IPI */
728 return; 689 return;
729 } 690 }
@@ -735,8 +696,8 @@ xpc_identify_act_IRQ_req(int nasid)
735 */ 696 */
736 697
737 xpc_update_partition_info(part, remote_rp_version, 698 xpc_update_partition_info(part, remote_rp_version,
738 &remote_rp_stamp, remote_rp_pa, 699 &remote_rp_stamp, remote_rp_pa,
739 remote_vars_pa, remote_vars); 700 remote_vars_pa, remote_vars);
740 part->reactivate_nasid = nasid; 701 part->reactivate_nasid = nasid;
741 XPC_DEACTIVATE_PARTITION(part, xpcReactivating); 702 XPC_DEACTIVATE_PARTITION(part, xpcReactivating);
742 return; 703 return;
@@ -756,15 +717,15 @@ xpc_identify_act_IRQ_req(int nasid)
756 xpc_clear_partition_disengage_request(1UL << partid); 717 xpc_clear_partition_disengage_request(1UL << partid);
757 718
758 xpc_update_partition_info(part, remote_rp_version, 719 xpc_update_partition_info(part, remote_rp_version,
759 &remote_rp_stamp, remote_rp_pa, 720 &remote_rp_stamp, remote_rp_pa,
760 remote_vars_pa, remote_vars); 721 remote_vars_pa, remote_vars);
761 reactivate = 1; 722 reactivate = 1;
762 723
763 } else { 724 } else {
764 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version)); 725 DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version));
765 726
766 stamp_diff = xpc_compare_stamps(&part->remote_rp_stamp, 727 stamp_diff = xpc_compare_stamps(&part->remote_rp_stamp,
767 &remote_rp_stamp); 728 &remote_rp_stamp);
768 if (stamp_diff != 0) { 729 if (stamp_diff != 0) {
769 DBUG_ON(stamp_diff >= 0); 730 DBUG_ON(stamp_diff >= 0);
770 731
@@ -775,17 +736,18 @@ xpc_identify_act_IRQ_req(int nasid)
775 736
776 DBUG_ON(xpc_partition_engaged(1UL << partid)); 737 DBUG_ON(xpc_partition_engaged(1UL << partid));
777 DBUG_ON(xpc_partition_disengage_requested(1UL << 738 DBUG_ON(xpc_partition_disengage_requested(1UL <<
778 partid)); 739 partid));
779 740
780 xpc_update_partition_info(part, remote_rp_version, 741 xpc_update_partition_info(part, remote_rp_version,
781 &remote_rp_stamp, remote_rp_pa, 742 &remote_rp_stamp,
782 remote_vars_pa, remote_vars); 743 remote_rp_pa, remote_vars_pa,
744 remote_vars);
783 reactivate = 1; 745 reactivate = 1;
784 } 746 }
785 } 747 }
786 748
787 if (part->disengage_request_timeout > 0 && 749 if (part->disengage_request_timeout > 0 &&
788 !xpc_partition_disengaged(part)) { 750 !xpc_partition_disengaged(part)) {
789 /* still waiting on other side to disengage from us */ 751 /* still waiting on other side to disengage from us */
790 return; 752 return;
791 } 753 }
@@ -795,12 +757,11 @@ xpc_identify_act_IRQ_req(int nasid)
795 XPC_DEACTIVATE_PARTITION(part, xpcReactivating); 757 XPC_DEACTIVATE_PARTITION(part, xpcReactivating);
796 758
797 } else if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version) && 759 } else if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version) &&
798 xpc_partition_disengage_requested(1UL << partid)) { 760 xpc_partition_disengage_requested(1UL << partid)) {
799 XPC_DEACTIVATE_PARTITION(part, xpcOtherGoingDown); 761 XPC_DEACTIVATE_PARTITION(part, xpcOtherGoingDown);
800 } 762 }
801} 763}
802 764
803
804/* 765/*
805 * Loop through the activation AMO variables and process any bits 766 * Loop through the activation AMO variables and process any bits
806 * which are set. Each bit indicates a nasid sending a partition 767 * which are set. Each bit indicates a nasid sending a partition
@@ -813,20 +774,17 @@ xpc_identify_act_IRQ_sender(void)
813{ 774{
814 int word, bit; 775 int word, bit;
815 u64 nasid_mask; 776 u64 nasid_mask;
816 u64 nasid; /* remote nasid */ 777 u64 nasid; /* remote nasid */
817 int n_IRQs_detected = 0; 778 int n_IRQs_detected = 0;
818 AMO_t *act_amos; 779 AMO_t *act_amos;
819 780
820
821 act_amos = xpc_vars->amos_page + XPC_ACTIVATE_IRQ_AMOS; 781 act_amos = xpc_vars->amos_page + XPC_ACTIVATE_IRQ_AMOS;
822 782
823
824 /* scan through act AMO variable looking for non-zero entries */ 783 /* scan through act AMO variable looking for non-zero entries */
825 for (word = 0; word < xp_nasid_mask_words; word++) { 784 for (word = 0; word < xp_nasid_mask_words; word++) {
826 785
827 if (xpc_exiting) { 786 if (xpc_exiting)
828 break; 787 break;
829 }
830 788
831 nasid_mask = xpc_IPI_receive(&act_amos[word]); 789 nasid_mask = xpc_IPI_receive(&act_amos[word]);
832 if (nasid_mask == 0) { 790 if (nasid_mask == 0) {
@@ -837,7 +795,6 @@ xpc_identify_act_IRQ_sender(void)
837 dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word, 795 dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word,
838 nasid_mask); 796 nasid_mask);
839 797
840
841 /* 798 /*
842 * If this nasid has been added to the machine since 799 * If this nasid has been added to the machine since
843 * our partition was reset, this will retain the 800 * our partition was reset, this will retain the
@@ -846,7 +803,6 @@ xpc_identify_act_IRQ_sender(void)
846 */ 803 */
847 xpc_mach_nasids[word] |= nasid_mask; 804 xpc_mach_nasids[word] |= nasid_mask;
848 805
849
850 /* locate the nasid(s) which sent interrupts */ 806 /* locate the nasid(s) which sent interrupts */
851 807
852 for (bit = 0; bit < (8 * sizeof(u64)); bit++) { 808 for (bit = 0; bit < (8 * sizeof(u64)); bit++) {
@@ -862,7 +818,6 @@ xpc_identify_act_IRQ_sender(void)
862 return n_IRQs_detected; 818 return n_IRQs_detected;
863} 819}
864 820
865
866/* 821/*
867 * See if the other side has responded to a partition disengage request 822 * See if the other side has responded to a partition disengage request
868 * from us. 823 * from us.
@@ -873,11 +828,11 @@ xpc_partition_disengaged(struct xpc_partition *part)
873 partid_t partid = XPC_PARTID(part); 828 partid_t partid = XPC_PARTID(part);
874 int disengaged; 829 int disengaged;
875 830
876
877 disengaged = (xpc_partition_engaged(1UL << partid) == 0); 831 disengaged = (xpc_partition_engaged(1UL << partid) == 0);
878 if (part->disengage_request_timeout) { 832 if (part->disengage_request_timeout) {
879 if (!disengaged) { 833 if (!disengaged) {
880 if (time_before(jiffies, part->disengage_request_timeout)) { 834 if (time_before(jiffies,
835 part->disengage_request_timeout)) {
881 /* timelimit hasn't been reached yet */ 836 /* timelimit hasn't been reached yet */
882 return 0; 837 return 0;
883 } 838 }
@@ -888,7 +843,7 @@ xpc_partition_disengaged(struct xpc_partition *part)
888 */ 843 */
889 844
890 dev_info(xpc_part, "disengage from remote partition %d " 845 dev_info(xpc_part, "disengage from remote partition %d "
891 "timed out\n", partid); 846 "timed out\n", partid);
892 xpc_disengage_request_timedout = 1; 847 xpc_disengage_request_timedout = 1;
893 xpc_clear_partition_engaged(1UL << partid); 848 xpc_clear_partition_engaged(1UL << partid);
894 disengaged = 1; 849 disengaged = 1;
@@ -898,23 +853,20 @@ xpc_partition_disengaged(struct xpc_partition *part)
898 /* cancel the timer function, provided it's not us */ 853 /* cancel the timer function, provided it's not us */
899 if (!in_interrupt()) { 854 if (!in_interrupt()) {
900 del_singleshot_timer_sync(&part-> 855 del_singleshot_timer_sync(&part->
901 disengage_request_timer); 856 disengage_request_timer);
902 } 857 }
903 858
904 DBUG_ON(part->act_state != XPC_P_DEACTIVATING && 859 DBUG_ON(part->act_state != XPC_P_DEACTIVATING &&
905 part->act_state != XPC_P_INACTIVE); 860 part->act_state != XPC_P_INACTIVE);
906 if (part->act_state != XPC_P_INACTIVE) { 861 if (part->act_state != XPC_P_INACTIVE)
907 xpc_wakeup_channel_mgr(part); 862 xpc_wakeup_channel_mgr(part);
908 }
909 863
910 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) { 864 if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version))
911 xpc_cancel_partition_disengage_request(part); 865 xpc_cancel_partition_disengage_request(part);
912 }
913 } 866 }
914 return disengaged; 867 return disengaged;
915} 868}
916 869
917
918/* 870/*
919 * Mark specified partition as active. 871 * Mark specified partition as active.
920 */ 872 */
@@ -924,7 +876,6 @@ xpc_mark_partition_active(struct xpc_partition *part)
924 unsigned long irq_flags; 876 unsigned long irq_flags;
925 enum xpc_retval ret; 877 enum xpc_retval ret;
926 878
927
928 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part)); 879 dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part));
929 880
930 spin_lock_irqsave(&part->act_lock, irq_flags); 881 spin_lock_irqsave(&part->act_lock, irq_flags);
@@ -940,17 +891,15 @@ xpc_mark_partition_active(struct xpc_partition *part)
940 return ret; 891 return ret;
941} 892}
942 893
943
944/* 894/*
945 * Notify XPC that the partition is down. 895 * Notify XPC that the partition is down.
946 */ 896 */
947void 897void
948xpc_deactivate_partition(const int line, struct xpc_partition *part, 898xpc_deactivate_partition(const int line, struct xpc_partition *part,
949 enum xpc_retval reason) 899 enum xpc_retval reason)
950{ 900{
951 unsigned long irq_flags; 901 unsigned long irq_flags;
952 902
953
954 spin_lock_irqsave(&part->act_lock, irq_flags); 903 spin_lock_irqsave(&part->act_lock, irq_flags);
955 904
956 if (part->act_state == XPC_P_INACTIVE) { 905 if (part->act_state == XPC_P_INACTIVE) {
@@ -964,7 +913,7 @@ xpc_deactivate_partition(const int line, struct xpc_partition *part,
964 } 913 }
965 if (part->act_state == XPC_P_DEACTIVATING) { 914 if (part->act_state == XPC_P_DEACTIVATING) {
966 if ((part->reason == xpcUnloading && reason != xpcUnloading) || 915 if ((part->reason == xpcUnloading && reason != xpcUnloading) ||
967 reason == xpcReactivating) { 916 reason == xpcReactivating) {
968 XPC_SET_REASON(part, reason, line); 917 XPC_SET_REASON(part, reason, line);
969 } 918 }
970 spin_unlock_irqrestore(&part->act_lock, irq_flags); 919 spin_unlock_irqrestore(&part->act_lock, irq_flags);
@@ -982,9 +931,9 @@ xpc_deactivate_partition(const int line, struct xpc_partition *part,
982 931
983 /* set a timelimit on the disengage request */ 932 /* set a timelimit on the disengage request */
984 part->disengage_request_timeout = jiffies + 933 part->disengage_request_timeout = jiffies +
985 (xpc_disengage_request_timelimit * HZ); 934 (xpc_disengage_request_timelimit * HZ);
986 part->disengage_request_timer.expires = 935 part->disengage_request_timer.expires =
987 part->disengage_request_timeout; 936 part->disengage_request_timeout;
988 add_timer(&part->disengage_request_timer); 937 add_timer(&part->disengage_request_timer);
989 } 938 }
990 939
@@ -994,7 +943,6 @@ xpc_deactivate_partition(const int line, struct xpc_partition *part,
994 xpc_partition_going_down(part, reason); 943 xpc_partition_going_down(part, reason);
995} 944}
996 945
997
998/* 946/*
999 * Mark specified partition as inactive. 947 * Mark specified partition as inactive.
1000 */ 948 */
@@ -1003,7 +951,6 @@ xpc_mark_partition_inactive(struct xpc_partition *part)
1003{ 951{
1004 unsigned long irq_flags; 952 unsigned long irq_flags;
1005 953
1006
1007 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n", 954 dev_dbg(xpc_part, "setting partition %d to INACTIVE\n",
1008 XPC_PARTID(part)); 955 XPC_PARTID(part));
1009 956
@@ -1013,7 +960,6 @@ xpc_mark_partition_inactive(struct xpc_partition *part)
1013 part->remote_rp_pa = 0; 960 part->remote_rp_pa = 0;
1014} 961}
1015 962
1016
1017/* 963/*
1018 * SAL has provided a partition and machine mask. The partition mask 964 * SAL has provided a partition and machine mask. The partition mask
1019 * contains a bit for each even nasid in our partition. The machine 965 * contains a bit for each even nasid in our partition. The machine
@@ -1041,24 +987,22 @@ xpc_discovery(void)
1041 u64 *discovered_nasids; 987 u64 *discovered_nasids;
1042 enum xpc_retval ret; 988 enum xpc_retval ret;
1043 989
1044
1045 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE + 990 remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE +
1046 xp_nasid_mask_bytes, 991 xp_nasid_mask_bytes,
1047 GFP_KERNEL, &remote_rp_base); 992 GFP_KERNEL, &remote_rp_base);
1048 if (remote_rp == NULL) { 993 if (remote_rp == NULL)
1049 return; 994 return;
1050 }
1051 remote_vars = (struct xpc_vars *) remote_rp;
1052 995
996 remote_vars = (struct xpc_vars *)remote_rp;
1053 997
1054 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words, 998 discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
1055 GFP_KERNEL); 999 GFP_KERNEL);
1056 if (discovered_nasids == NULL) { 1000 if (discovered_nasids == NULL) {
1057 kfree(remote_rp_base); 1001 kfree(remote_rp_base);
1058 return; 1002 return;
1059 } 1003 }
1060 1004
1061 rp = (struct xpc_rsvd_page *) xpc_rsvd_page; 1005 rp = (struct xpc_rsvd_page *)xpc_rsvd_page;
1062 1006
1063 /* 1007 /*
1064 * The term 'region' in this context refers to the minimum number of 1008 * The term 'region' in this context refers to the minimum number of
@@ -1081,23 +1025,19 @@ xpc_discovery(void)
1081 1025
1082 for (region = 0; region < max_regions; region++) { 1026 for (region = 0; region < max_regions; region++) {
1083 1027
1084 if ((volatile int) xpc_exiting) { 1028 if (xpc_exiting)
1085 break; 1029 break;
1086 }
1087 1030
1088 dev_dbg(xpc_part, "searching region %d\n", region); 1031 dev_dbg(xpc_part, "searching region %d\n", region);
1089 1032
1090 for (nasid = (region * region_size * 2); 1033 for (nasid = (region * region_size * 2);
1091 nasid < ((region + 1) * region_size * 2); 1034 nasid < ((region + 1) * region_size * 2); nasid += 2) {
1092 nasid += 2) {
1093 1035
1094 if ((volatile int) xpc_exiting) { 1036 if (xpc_exiting)
1095 break; 1037 break;
1096 }
1097 1038
1098 dev_dbg(xpc_part, "checking nasid %d\n", nasid); 1039 dev_dbg(xpc_part, "checking nasid %d\n", nasid);
1099 1040
1100
1101 if (XPC_NASID_IN_ARRAY(nasid, xpc_part_nasids)) { 1041 if (XPC_NASID_IN_ARRAY(nasid, xpc_part_nasids)) {
1102 dev_dbg(xpc_part, "PROM indicates Nasid %d is " 1042 dev_dbg(xpc_part, "PROM indicates Nasid %d is "
1103 "part of the local partition; skipping " 1043 "part of the local partition; skipping "
@@ -1119,19 +1059,18 @@ xpc_discovery(void)
1119 continue; 1059 continue;
1120 } 1060 }
1121 1061
1122
1123 /* pull over the reserved page structure */ 1062 /* pull over the reserved page structure */
1124 1063
1125 ret = xpc_get_remote_rp(nasid, discovered_nasids, 1064 ret = xpc_get_remote_rp(nasid, discovered_nasids,
1126 remote_rp, &remote_rp_pa); 1065 remote_rp, &remote_rp_pa);
1127 if (ret != xpcSuccess) { 1066 if (ret != xpcSuccess) {
1128 dev_dbg(xpc_part, "unable to get reserved page " 1067 dev_dbg(xpc_part, "unable to get reserved page "
1129 "from nasid %d, reason=%d\n", nasid, 1068 "from nasid %d, reason=%d\n", nasid,
1130 ret); 1069 ret);
1131 1070
1132 if (ret == xpcLocalPartid) { 1071 if (ret == xpcLocalPartid)
1133 break; 1072 break;
1134 } 1073
1135 continue; 1074 continue;
1136 } 1075 }
1137 1076
@@ -1140,7 +1079,6 @@ xpc_discovery(void)
1140 partid = remote_rp->partid; 1079 partid = remote_rp->partid;
1141 part = &xpc_partitions[partid]; 1080 part = &xpc_partitions[partid];
1142 1081
1143
1144 /* pull over the cross partition variables */ 1082 /* pull over the cross partition variables */
1145 1083
1146 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars); 1084 ret = xpc_get_remote_vars(remote_vars_pa, remote_vars);
@@ -1171,15 +1109,15 @@ xpc_discovery(void)
1171 * get the same page for remote_act_amos_pa after 1109 * get the same page for remote_act_amos_pa after
1172 * module reloads and system reboots. 1110 * module reloads and system reboots.
1173 */ 1111 */
1174 if (sn_register_xp_addr_region( 1112 if (sn_register_xp_addr_region
1175 remote_vars->amos_page_pa, 1113 (remote_vars->amos_page_pa, PAGE_SIZE, 1) < 0) {
1176 PAGE_SIZE, 1) < 0) { 1114 dev_dbg(xpc_part,
1177 dev_dbg(xpc_part, "partition %d failed to " 1115 "partition %d failed to "
1178 "register xp_addr region 0x%016lx\n", 1116 "register xp_addr region 0x%016lx\n",
1179 partid, remote_vars->amos_page_pa); 1117 partid, remote_vars->amos_page_pa);
1180 1118
1181 XPC_SET_REASON(part, xpcPhysAddrRegFailed, 1119 XPC_SET_REASON(part, xpcPhysAddrRegFailed,
1182 __LINE__); 1120 __LINE__);
1183 break; 1121 break;
1184 } 1122 }
1185 1123
@@ -1195,9 +1133,9 @@ xpc_discovery(void)
1195 remote_vars->act_phys_cpuid); 1133 remote_vars->act_phys_cpuid);
1196 1134
1197 if (XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars-> 1135 if (XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->
1198 version)) { 1136 version)) {
1199 part->remote_amos_page_pa = 1137 part->remote_amos_page_pa =
1200 remote_vars->amos_page_pa; 1138 remote_vars->amos_page_pa;
1201 xpc_mark_partition_disengaged(part); 1139 xpc_mark_partition_disengaged(part);
1202 xpc_cancel_partition_disengage_request(part); 1140 xpc_cancel_partition_disengage_request(part);
1203 } 1141 }
@@ -1209,7 +1147,6 @@ xpc_discovery(void)
1209 kfree(remote_rp_base); 1147 kfree(remote_rp_base);
1210} 1148}
1211 1149
1212
1213/* 1150/*
1214 * Given a partid, get the nasids owned by that partition from the 1151 * Given a partid, get the nasids owned by that partition from the
1215 * remote partition's reserved page. 1152 * remote partition's reserved page.
@@ -1221,19 +1158,17 @@ xpc_initiate_partid_to_nasids(partid_t partid, void *nasid_mask)
1221 u64 part_nasid_pa; 1158 u64 part_nasid_pa;
1222 int bte_res; 1159 int bte_res;
1223 1160
1224
1225 part = &xpc_partitions[partid]; 1161 part = &xpc_partitions[partid];
1226 if (part->remote_rp_pa == 0) { 1162 if (part->remote_rp_pa == 0)
1227 return xpcPartitionDown; 1163 return xpcPartitionDown;
1228 }
1229 1164
1230 memset(nasid_mask, 0, XP_NASID_MASK_BYTES); 1165 memset(nasid_mask, 0, XP_NASID_MASK_BYTES);
1231 1166
1232 part_nasid_pa = (u64) XPC_RP_PART_NASIDS(part->remote_rp_pa); 1167 part_nasid_pa = (u64)XPC_RP_PART_NASIDS(part->remote_rp_pa);
1233 1168
1234 bte_res = xp_bte_copy(part_nasid_pa, (u64) nasid_mask, 1169 bte_res = xp_bte_copy(part_nasid_pa, (u64)nasid_mask,
1235 xp_nasid_mask_bytes, (BTE_NOTIFY | BTE_WACQUIRE), NULL); 1170 xp_nasid_mask_bytes, (BTE_NOTIFY | BTE_WACQUIRE),
1171 NULL);
1236 1172
1237 return xpc_map_bte_errors(bte_res); 1173 return xpc_map_bte_errors(bte_res);
1238} 1174}
1239
diff --git a/arch/ia64/sn/kernel/xpnet.c b/drivers/misc/sgi-xp/xpnet.c
index a5df672d8392..a9543c65814d 100644
--- a/arch/ia64/sn/kernel/xpnet.c
+++ b/drivers/misc/sgi-xp/xpnet.c
@@ -3,10 +3,9 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (C) 1999,2001-2005 Silicon Graphics, Inc. All rights reserved. 6 * Copyright (C) 1999-2008 Silicon Graphics, Inc. All rights reserved.
7 */ 7 */
8 8
9
10/* 9/*
11 * Cross Partition Network Interface (XPNET) support 10 * Cross Partition Network Interface (XPNET) support
12 * 11 *
@@ -21,8 +20,8 @@
21 * 20 *
22 */ 21 */
23 22
24
25#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/types.h>
26#include <linux/kernel.h> 25#include <linux/kernel.h>
27#include <linux/init.h> 26#include <linux/init.h>
28#include <linux/ioport.h> 27#include <linux/ioport.h>
@@ -36,10 +35,8 @@
36#include <asm/sn/bte.h> 35#include <asm/sn/bte.h>
37#include <asm/sn/io.h> 36#include <asm/sn/io.h>
38#include <asm/sn/sn_sal.h> 37#include <asm/sn/sn_sal.h>
39#include <asm/types.h>
40#include <asm/atomic.h> 38#include <asm/atomic.h>
41#include <asm/sn/xp.h> 39#include "xp.h"
42
43 40
44/* 41/*
45 * The message payload transferred by XPC. 42 * The message payload transferred by XPC.
@@ -79,7 +76,6 @@ struct xpnet_message {
79#define XPNET_MSG_ALIGNED_SIZE (L1_CACHE_ALIGN(XPNET_MSG_SIZE)) 76#define XPNET_MSG_ALIGNED_SIZE (L1_CACHE_ALIGN(XPNET_MSG_SIZE))
80#define XPNET_MSG_NENTRIES (PAGE_SIZE / XPNET_MSG_ALIGNED_SIZE) 77#define XPNET_MSG_NENTRIES (PAGE_SIZE / XPNET_MSG_ALIGNED_SIZE)
81 78
82
83#define XPNET_MAX_KTHREADS (XPNET_MSG_NENTRIES + 1) 79#define XPNET_MAX_KTHREADS (XPNET_MSG_NENTRIES + 1)
84#define XPNET_MAX_IDLE_KTHREADS (XPNET_MSG_NENTRIES + 1) 80#define XPNET_MAX_IDLE_KTHREADS (XPNET_MSG_NENTRIES + 1)
85 81
@@ -91,9 +87,9 @@ struct xpnet_message {
91#define XPNET_VERSION_MAJOR(_v) ((_v) >> 4) 87#define XPNET_VERSION_MAJOR(_v) ((_v) >> 4)
92#define XPNET_VERSION_MINOR(_v) ((_v) & 0xf) 88#define XPNET_VERSION_MINOR(_v) ((_v) & 0xf)
93 89
94#define XPNET_VERSION _XPNET_VERSION(1,0) /* version 1.0 */ 90#define XPNET_VERSION _XPNET_VERSION(1, 0) /* version 1.0 */
95#define XPNET_VERSION_EMBED _XPNET_VERSION(1,1) /* version 1.1 */ 91#define XPNET_VERSION_EMBED _XPNET_VERSION(1, 1) /* version 1.1 */
96#define XPNET_MAGIC 0x88786984 /* "XNET" */ 92#define XPNET_MAGIC 0x88786984 /* "XNET" */
97 93
98#define XPNET_VALID_MSG(_m) \ 94#define XPNET_VALID_MSG(_m) \
99 ((XPNET_VERSION_MAJOR(_m->version) == XPNET_VERSION_MAJOR(XPNET_VERSION)) \ 95 ((XPNET_VERSION_MAJOR(_m->version) == XPNET_VERSION_MAJOR(XPNET_VERSION)) \
@@ -101,7 +97,6 @@ struct xpnet_message {
101 97
102#define XPNET_DEVICE_NAME "xp0" 98#define XPNET_DEVICE_NAME "xp0"
103 99
104
105/* 100/*
106 * When messages are queued with xpc_send_notify, a kmalloc'd buffer 101 * When messages are queued with xpc_send_notify, a kmalloc'd buffer
107 * of the following type is passed as a notification cookie. When the 102 * of the following type is passed as a notification cookie. When the
@@ -145,7 +140,6 @@ static DEFINE_SPINLOCK(xpnet_broadcast_lock);
145/* 32KB has been determined to be the ideal */ 140/* 32KB has been determined to be the ideal */
146#define XPNET_DEF_MTU (0x8000UL) 141#define XPNET_DEF_MTU (0x8000UL)
147 142
148
149/* 143/*
150 * The partition id is encapsulated in the MAC address. The following 144 * The partition id is encapsulated in the MAC address. The following
151 * define locates the octet the partid is in. 145 * define locates the octet the partid is in.
@@ -153,7 +147,6 @@ static DEFINE_SPINLOCK(xpnet_broadcast_lock);
153#define XPNET_PARTID_OCTET 1 147#define XPNET_PARTID_OCTET 1
154#define XPNET_LICENSE_OCTET 2 148#define XPNET_LICENSE_OCTET 2
155 149
156
157/* 150/*
158 * Define the XPNET debug device structure that is to be used with dev_dbg(), 151 * Define the XPNET debug device structure that is to be used with dev_dbg(),
159 * dev_err(), dev_warn(), and dev_info(). 152 * dev_err(), dev_warn(), and dev_info().
@@ -163,7 +156,7 @@ struct device_driver xpnet_dbg_name = {
163}; 156};
164 157
165struct device xpnet_dbg_subname = { 158struct device xpnet_dbg_subname = {
166 .bus_id = {0}, /* set to "" */ 159 .bus_id = {0}, /* set to "" */
167 .driver = &xpnet_dbg_name 160 .driver = &xpnet_dbg_name
168}; 161};
169 162
@@ -178,14 +171,13 @@ xpnet_receive(partid_t partid, int channel, struct xpnet_message *msg)
178 struct sk_buff *skb; 171 struct sk_buff *skb;
179 bte_result_t bret; 172 bte_result_t bret;
180 struct xpnet_dev_private *priv = 173 struct xpnet_dev_private *priv =
181 (struct xpnet_dev_private *) xpnet_device->priv; 174 (struct xpnet_dev_private *)xpnet_device->priv;
182
183 175
184 if (!XPNET_VALID_MSG(msg)) { 176 if (!XPNET_VALID_MSG(msg)) {
185 /* 177 /*
186 * Packet with a different XPC version. Ignore. 178 * Packet with a different XPC version. Ignore.
187 */ 179 */
188 xpc_received(partid, channel, (void *) msg); 180 xpc_received(partid, channel, (void *)msg);
189 181
190 priv->stats.rx_errors++; 182 priv->stats.rx_errors++;
191 183
@@ -194,14 +186,13 @@ xpnet_receive(partid_t partid, int channel, struct xpnet_message *msg)
194 dev_dbg(xpnet, "received 0x%lx, %d, %d, %d\n", msg->buf_pa, msg->size, 186 dev_dbg(xpnet, "received 0x%lx, %d, %d, %d\n", msg->buf_pa, msg->size,
195 msg->leadin_ignore, msg->tailout_ignore); 187 msg->leadin_ignore, msg->tailout_ignore);
196 188
197
198 /* reserve an extra cache line */ 189 /* reserve an extra cache line */
199 skb = dev_alloc_skb(msg->size + L1_CACHE_BYTES); 190 skb = dev_alloc_skb(msg->size + L1_CACHE_BYTES);
200 if (!skb) { 191 if (!skb) {
201 dev_err(xpnet, "failed on dev_alloc_skb(%d)\n", 192 dev_err(xpnet, "failed on dev_alloc_skb(%d)\n",
202 msg->size + L1_CACHE_BYTES); 193 msg->size + L1_CACHE_BYTES);
203 194
204 xpc_received(partid, channel, (void *) msg); 195 xpc_received(partid, channel, (void *)msg);
205 196
206 priv->stats.rx_errors++; 197 priv->stats.rx_errors++;
207 198
@@ -227,12 +218,13 @@ xpnet_receive(partid_t partid, int channel, struct xpnet_message *msg)
227 * Move the data over from the other side. 218 * Move the data over from the other side.
228 */ 219 */
229 if ((XPNET_VERSION_MINOR(msg->version) == 1) && 220 if ((XPNET_VERSION_MINOR(msg->version) == 1) &&
230 (msg->embedded_bytes != 0)) { 221 (msg->embedded_bytes != 0)) {
231 dev_dbg(xpnet, "copying embedded message. memcpy(0x%p, 0x%p, " 222 dev_dbg(xpnet, "copying embedded message. memcpy(0x%p, 0x%p, "
232 "%lu)\n", skb->data, &msg->data, 223 "%lu)\n", skb->data, &msg->data,
233 (size_t) msg->embedded_bytes); 224 (size_t)msg->embedded_bytes);
234 225
235 skb_copy_to_linear_data(skb, &msg->data, (size_t)msg->embedded_bytes); 226 skb_copy_to_linear_data(skb, &msg->data,
227 (size_t)msg->embedded_bytes);
236 } else { 228 } else {
237 dev_dbg(xpnet, "transferring buffer to the skb->data area;\n\t" 229 dev_dbg(xpnet, "transferring buffer to the skb->data area;\n\t"
238 "bte_copy(0x%p, 0x%p, %hu)\n", (void *)msg->buf_pa, 230 "bte_copy(0x%p, 0x%p, %hu)\n", (void *)msg->buf_pa,
@@ -244,16 +236,18 @@ xpnet_receive(partid_t partid, int channel, struct xpnet_message *msg)
244 msg->size, (BTE_NOTIFY | BTE_WACQUIRE), NULL); 236 msg->size, (BTE_NOTIFY | BTE_WACQUIRE), NULL);
245 237
246 if (bret != BTE_SUCCESS) { 238 if (bret != BTE_SUCCESS) {
247 // >>> Need better way of cleaning skb. Currently skb 239 /*
248 // >>> appears in_use and we can't just call 240 * >>> Need better way of cleaning skb. Currently skb
249 // >>> dev_kfree_skb. 241 * >>> appears in_use and we can't just call
242 * >>> dev_kfree_skb.
243 */
250 dev_err(xpnet, "bte_copy(0x%p, 0x%p, 0x%hx) returned " 244 dev_err(xpnet, "bte_copy(0x%p, 0x%p, 0x%hx) returned "
251 "error=0x%x\n", (void *)msg->buf_pa, 245 "error=0x%x\n", (void *)msg->buf_pa,
252 (void *)__pa((u64)skb->data & 246 (void *)__pa((u64)skb->data &
253 ~(L1_CACHE_BYTES - 1)), 247 ~(L1_CACHE_BYTES - 1)),
254 msg->size, bret); 248 msg->size, bret);
255 249
256 xpc_received(partid, channel, (void *) msg); 250 xpc_received(partid, channel, (void *)msg);
257 251
258 priv->stats.rx_errors++; 252 priv->stats.rx_errors++;
259 253
@@ -262,7 +256,7 @@ xpnet_receive(partid_t partid, int channel, struct xpnet_message *msg)
262 } 256 }
263 257
264 dev_dbg(xpnet, "<skb->head=0x%p skb->data=0x%p skb->tail=0x%p " 258 dev_dbg(xpnet, "<skb->head=0x%p skb->data=0x%p skb->tail=0x%p "
265 "skb->end=0x%p skb->len=%d\n", (void *) skb->head, 259 "skb->end=0x%p skb->len=%d\n", (void *)skb->head,
266 (void *)skb->data, skb_tail_pointer(skb), skb_end_pointer(skb), 260 (void *)skb->data, skb_tail_pointer(skb), skb_end_pointer(skb),
267 skb->len); 261 skb->len);
268 262
@@ -275,16 +269,14 @@ xpnet_receive(partid_t partid, int channel, struct xpnet_message *msg)
275 (void *)skb->head, (void *)skb->data, skb_tail_pointer(skb), 269 (void *)skb->head, (void *)skb->data, skb_tail_pointer(skb),
276 skb_end_pointer(skb), skb->len); 270 skb_end_pointer(skb), skb->len);
277 271
278
279 xpnet_device->last_rx = jiffies; 272 xpnet_device->last_rx = jiffies;
280 priv->stats.rx_packets++; 273 priv->stats.rx_packets++;
281 priv->stats.rx_bytes += skb->len + ETH_HLEN; 274 priv->stats.rx_bytes += skb->len + ETH_HLEN;
282 275
283 netif_rx_ni(skb); 276 netif_rx_ni(skb);
284 xpc_received(partid, channel, (void *) msg); 277 xpc_received(partid, channel, (void *)msg);
285} 278}
286 279
287
288/* 280/*
289 * This is the handler which XPC calls during any sort of change in 281 * This is the handler which XPC calls during any sort of change in
290 * state or message reception on a connection. 282 * state or message reception on a connection.
@@ -295,20 +287,19 @@ xpnet_connection_activity(enum xpc_retval reason, partid_t partid, int channel,
295{ 287{
296 long bp; 288 long bp;
297 289
298
299 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS); 290 DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);
300 DBUG_ON(channel != XPC_NET_CHANNEL); 291 DBUG_ON(channel != XPC_NET_CHANNEL);
301 292
302 switch(reason) { 293 switch (reason) {
303 case xpcMsgReceived: /* message received */ 294 case xpcMsgReceived: /* message received */
304 DBUG_ON(data == NULL); 295 DBUG_ON(data == NULL);
305 296
306 xpnet_receive(partid, channel, (struct xpnet_message *) data); 297 xpnet_receive(partid, channel, (struct xpnet_message *)data);
307 break; 298 break;
308 299
309 case xpcConnected: /* connection completed to a partition */ 300 case xpcConnected: /* connection completed to a partition */
310 spin_lock_bh(&xpnet_broadcast_lock); 301 spin_lock_bh(&xpnet_broadcast_lock);
311 xpnet_broadcast_partitions |= 1UL << (partid -1 ); 302 xpnet_broadcast_partitions |= 1UL << (partid - 1);
312 bp = xpnet_broadcast_partitions; 303 bp = xpnet_broadcast_partitions;
313 spin_unlock_bh(&xpnet_broadcast_lock); 304 spin_unlock_bh(&xpnet_broadcast_lock);
314 305
@@ -321,13 +312,12 @@ xpnet_connection_activity(enum xpc_retval reason, partid_t partid, int channel,
321 312
322 default: 313 default:
323 spin_lock_bh(&xpnet_broadcast_lock); 314 spin_lock_bh(&xpnet_broadcast_lock);
324 xpnet_broadcast_partitions &= ~(1UL << (partid -1 )); 315 xpnet_broadcast_partitions &= ~(1UL << (partid - 1));
325 bp = xpnet_broadcast_partitions; 316 bp = xpnet_broadcast_partitions;
326 spin_unlock_bh(&xpnet_broadcast_lock); 317 spin_unlock_bh(&xpnet_broadcast_lock);
327 318
328 if (bp == 0) { 319 if (bp == 0)
329 netif_carrier_off(xpnet_device); 320 netif_carrier_off(xpnet_device);
330 }
331 321
332 dev_dbg(xpnet, "%s disconnected from partition %d; " 322 dev_dbg(xpnet, "%s disconnected from partition %d; "
333 "xpnet_broadcast_partitions=0x%lx\n", 323 "xpnet_broadcast_partitions=0x%lx\n",
@@ -337,13 +327,11 @@ xpnet_connection_activity(enum xpc_retval reason, partid_t partid, int channel,
337 } 327 }
338} 328}
339 329
340
341static int 330static int
342xpnet_dev_open(struct net_device *dev) 331xpnet_dev_open(struct net_device *dev)
343{ 332{
344 enum xpc_retval ret; 333 enum xpc_retval ret;
345 334
346
347 dev_dbg(xpnet, "calling xpc_connect(%d, 0x%p, NULL, %ld, %ld, %ld, " 335 dev_dbg(xpnet, "calling xpc_connect(%d, 0x%p, NULL, %ld, %ld, %ld, "
348 "%ld)\n", XPC_NET_CHANNEL, xpnet_connection_activity, 336 "%ld)\n", XPC_NET_CHANNEL, xpnet_connection_activity,
349 XPNET_MSG_SIZE, XPNET_MSG_NENTRIES, XPNET_MAX_KTHREADS, 337 XPNET_MSG_SIZE, XPNET_MSG_NENTRIES, XPNET_MAX_KTHREADS,
@@ -364,7 +352,6 @@ xpnet_dev_open(struct net_device *dev)
364 return 0; 352 return 0;
365} 353}
366 354
367
368static int 355static int
369xpnet_dev_stop(struct net_device *dev) 356xpnet_dev_stop(struct net_device *dev)
370{ 357{
@@ -375,7 +362,6 @@ xpnet_dev_stop(struct net_device *dev)
375 return 0; 362 return 0;
376} 363}
377 364
378
379static int 365static int
380xpnet_dev_change_mtu(struct net_device *dev, int new_mtu) 366xpnet_dev_change_mtu(struct net_device *dev, int new_mtu)
381{ 367{
@@ -392,7 +378,6 @@ xpnet_dev_change_mtu(struct net_device *dev, int new_mtu)
392 return 0; 378 return 0;
393} 379}
394 380
395
396/* 381/*
397 * Required for the net_device structure. 382 * Required for the net_device structure.
398 */ 383 */
@@ -402,7 +387,6 @@ xpnet_dev_set_config(struct net_device *dev, struct ifmap *new_map)
402 return 0; 387 return 0;
403} 388}
404 389
405
406/* 390/*
407 * Return statistics to the caller. 391 * Return statistics to the caller.
408 */ 392 */
@@ -411,13 +395,11 @@ xpnet_dev_get_stats(struct net_device *dev)
411{ 395{
412 struct xpnet_dev_private *priv; 396 struct xpnet_dev_private *priv;
413 397
414 398 priv = (struct xpnet_dev_private *)dev->priv;
415 priv = (struct xpnet_dev_private *) dev->priv;
416 399
417 return &priv->stats; 400 return &priv->stats;
418} 401}
419 402
420
421/* 403/*
422 * Notification that the other end has received the message and 404 * Notification that the other end has received the message and
423 * DMA'd the skb information. At this point, they are done with 405 * DMA'd the skb information. At this point, they are done with
@@ -426,11 +408,9 @@ xpnet_dev_get_stats(struct net_device *dev)
426 */ 408 */
427static void 409static void
428xpnet_send_completed(enum xpc_retval reason, partid_t partid, int channel, 410xpnet_send_completed(enum xpc_retval reason, partid_t partid, int channel,
429 void *__qm) 411 void *__qm)
430{ 412{
431 struct xpnet_pending_msg *queued_msg = 413 struct xpnet_pending_msg *queued_msg = (struct xpnet_pending_msg *)__qm;
432 (struct xpnet_pending_msg *) __qm;
433
434 414
435 DBUG_ON(queued_msg == NULL); 415 DBUG_ON(queued_msg == NULL);
436 416
@@ -439,14 +419,13 @@ xpnet_send_completed(enum xpc_retval reason, partid_t partid, int channel,
439 419
440 if (atomic_dec_return(&queued_msg->use_count) == 0) { 420 if (atomic_dec_return(&queued_msg->use_count) == 0) {
441 dev_dbg(xpnet, "all acks for skb->head=-x%p\n", 421 dev_dbg(xpnet, "all acks for skb->head=-x%p\n",
442 (void *) queued_msg->skb->head); 422 (void *)queued_msg->skb->head);
443 423
444 dev_kfree_skb_any(queued_msg->skb); 424 dev_kfree_skb_any(queued_msg->skb);
445 kfree(queued_msg); 425 kfree(queued_msg);
446 } 426 }
447} 427}
448 428
449
450/* 429/*
451 * Network layer has formatted a packet (skb) and is ready to place it 430 * Network layer has formatted a packet (skb) and is ready to place it
452 * "on the wire". Prepare and send an xpnet_message to all partitions 431 * "on the wire". Prepare and send an xpnet_message to all partitions
@@ -469,16 +448,13 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
469 struct xpnet_dev_private *priv; 448 struct xpnet_dev_private *priv;
470 u16 embedded_bytes; 449 u16 embedded_bytes;
471 450
472 451 priv = (struct xpnet_dev_private *)dev->priv;
473 priv = (struct xpnet_dev_private *) dev->priv;
474
475 452
476 dev_dbg(xpnet, ">skb->head=0x%p skb->data=0x%p skb->tail=0x%p " 453 dev_dbg(xpnet, ">skb->head=0x%p skb->data=0x%p skb->tail=0x%p "
477 "skb->end=0x%p skb->len=%d\n", (void *) skb->head, 454 "skb->end=0x%p skb->len=%d\n", (void *)skb->head,
478 (void *)skb->data, skb_tail_pointer(skb), skb_end_pointer(skb), 455 (void *)skb->data, skb_tail_pointer(skb), skb_end_pointer(skb),
479 skb->len); 456 skb->len);
480 457
481
482 /* 458 /*
483 * The xpnet_pending_msg tracks how many outstanding 459 * The xpnet_pending_msg tracks how many outstanding
484 * xpc_send_notifies are relying on this skb. When none 460 * xpc_send_notifies are relying on this skb. When none
@@ -487,16 +463,15 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
487 queued_msg = kmalloc(sizeof(struct xpnet_pending_msg), GFP_ATOMIC); 463 queued_msg = kmalloc(sizeof(struct xpnet_pending_msg), GFP_ATOMIC);
488 if (queued_msg == NULL) { 464 if (queued_msg == NULL) {
489 dev_warn(xpnet, "failed to kmalloc %ld bytes; dropping " 465 dev_warn(xpnet, "failed to kmalloc %ld bytes; dropping "
490 "packet\n", sizeof(struct xpnet_pending_msg)); 466 "packet\n", sizeof(struct xpnet_pending_msg));
491 467
492 priv->stats.tx_errors++; 468 priv->stats.tx_errors++;
493 469
494 return -ENOMEM; 470 return -ENOMEM;
495 } 471 }
496 472
497
498 /* get the beginning of the first cacheline and end of last */ 473 /* get the beginning of the first cacheline and end of last */
499 start_addr = ((u64) skb->data & ~(L1_CACHE_BYTES - 1)); 474 start_addr = ((u64)skb->data & ~(L1_CACHE_BYTES - 1));
500 end_addr = L1_CACHE_ALIGN((u64)skb_tail_pointer(skb)); 475 end_addr = L1_CACHE_ALIGN((u64)skb_tail_pointer(skb));
501 476
502 /* calculate how many bytes to embed in the XPC message */ 477 /* calculate how many bytes to embed in the XPC message */
@@ -506,7 +481,6 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
506 embedded_bytes = skb->len; 481 embedded_bytes = skb->len;
507 } 482 }
508 483
509
510 /* 484 /*
511 * Since the send occurs asynchronously, we set the count to one 485 * Since the send occurs asynchronously, we set the count to one
512 * and begin sending. Any sends that happen to complete before 486 * and begin sending. Any sends that happen to complete before
@@ -517,14 +491,13 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
517 atomic_set(&queued_msg->use_count, 1); 491 atomic_set(&queued_msg->use_count, 1);
518 queued_msg->skb = skb; 492 queued_msg->skb = skb;
519 493
520
521 second_mac_octet = skb->data[XPNET_PARTID_OCTET]; 494 second_mac_octet = skb->data[XPNET_PARTID_OCTET];
522 if (second_mac_octet == 0xff) { 495 if (second_mac_octet == 0xff) {
523 /* we are being asked to broadcast to all partitions */ 496 /* we are being asked to broadcast to all partitions */
524 dp = xpnet_broadcast_partitions; 497 dp = xpnet_broadcast_partitions;
525 } else if (second_mac_octet != 0) { 498 } else if (second_mac_octet != 0) {
526 dp = xpnet_broadcast_partitions & 499 dp = xpnet_broadcast_partitions &
527 (1UL << (second_mac_octet - 1)); 500 (1UL << (second_mac_octet - 1));
528 } else { 501 } else {
529 /* 0 is an invalid partid. Ignore */ 502 /* 0 is an invalid partid. Ignore */
530 dp = 0; 503 dp = 0;
@@ -543,7 +516,6 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
543 for (dest_partid = 1; dp && dest_partid < XP_MAX_PARTITIONS; 516 for (dest_partid = 1; dp && dest_partid < XP_MAX_PARTITIONS;
544 dest_partid++) { 517 dest_partid++) {
545 518
546
547 if (!(dp & (1UL << (dest_partid - 1)))) { 519 if (!(dp & (1UL << (dest_partid - 1)))) {
548 /* not destined for this partition */ 520 /* not destined for this partition */
549 continue; 521 continue;
@@ -552,20 +524,18 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
552 /* remove this partition from the destinations mask */ 524 /* remove this partition from the destinations mask */
553 dp &= ~(1UL << (dest_partid - 1)); 525 dp &= ~(1UL << (dest_partid - 1));
554 526
555
556 /* found a partition to send to */ 527 /* found a partition to send to */
557 528
558 ret = xpc_allocate(dest_partid, XPC_NET_CHANNEL, 529 ret = xpc_allocate(dest_partid, XPC_NET_CHANNEL,
559 XPC_NOWAIT, (void **)&msg); 530 XPC_NOWAIT, (void **)&msg);
560 if (unlikely(ret != xpcSuccess)) { 531 if (unlikely(ret != xpcSuccess))
561 continue; 532 continue;
562 }
563 533
564 msg->embedded_bytes = embedded_bytes; 534 msg->embedded_bytes = embedded_bytes;
565 if (unlikely(embedded_bytes != 0)) { 535 if (unlikely(embedded_bytes != 0)) {
566 msg->version = XPNET_VERSION_EMBED; 536 msg->version = XPNET_VERSION_EMBED;
567 dev_dbg(xpnet, "calling memcpy(0x%p, 0x%p, 0x%lx)\n", 537 dev_dbg(xpnet, "calling memcpy(0x%p, 0x%p, 0x%lx)\n",
568 &msg->data, skb->data, (size_t) embedded_bytes); 538 &msg->data, skb->data, (size_t)embedded_bytes);
569 skb_copy_from_linear_data(skb, &msg->data, 539 skb_copy_from_linear_data(skb, &msg->data,
570 (size_t)embedded_bytes); 540 (size_t)embedded_bytes);
571 } else { 541 } else {
@@ -573,7 +543,7 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
573 } 543 }
574 msg->magic = XPNET_MAGIC; 544 msg->magic = XPNET_MAGIC;
575 msg->size = end_addr - start_addr; 545 msg->size = end_addr - start_addr;
576 msg->leadin_ignore = (u64) skb->data - start_addr; 546 msg->leadin_ignore = (u64)skb->data - start_addr;
577 msg->tailout_ignore = end_addr - (u64)skb_tail_pointer(skb); 547 msg->tailout_ignore = end_addr - (u64)skb_tail_pointer(skb);
578 msg->buf_pa = __pa(start_addr); 548 msg->buf_pa = __pa(start_addr);
579 549
@@ -583,7 +553,6 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
583 dest_partid, XPC_NET_CHANNEL, msg->buf_pa, msg->size, 553 dest_partid, XPC_NET_CHANNEL, msg->buf_pa, msg->size,
584 msg->leadin_ignore, msg->tailout_ignore); 554 msg->leadin_ignore, msg->tailout_ignore);
585 555
586
587 atomic_inc(&queued_msg->use_count); 556 atomic_inc(&queued_msg->use_count);
588 557
589 ret = xpc_send_notify(dest_partid, XPC_NET_CHANNEL, msg, 558 ret = xpc_send_notify(dest_partid, XPC_NET_CHANNEL, msg,
@@ -592,14 +561,12 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
592 atomic_dec(&queued_msg->use_count); 561 atomic_dec(&queued_msg->use_count);
593 continue; 562 continue;
594 } 563 }
595
596 } 564 }
597 565
598 if (atomic_dec_return(&queued_msg->use_count) == 0) { 566 if (atomic_dec_return(&queued_msg->use_count) == 0) {
599 dev_dbg(xpnet, "no partitions to receive packet destined for " 567 dev_dbg(xpnet, "no partitions to receive packet destined for "
600 "%d\n", dest_partid); 568 "%d\n", dest_partid);
601 569
602
603 dev_kfree_skb(skb); 570 dev_kfree_skb(skb);
604 kfree(queued_msg); 571 kfree(queued_msg);
605 } 572 }
@@ -610,23 +577,20 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
610 return 0; 577 return 0;
611} 578}
612 579
613
614/* 580/*
615 * Deal with transmit timeouts coming from the network layer. 581 * Deal with transmit timeouts coming from the network layer.
616 */ 582 */
617static void 583static void
618xpnet_dev_tx_timeout (struct net_device *dev) 584xpnet_dev_tx_timeout(struct net_device *dev)
619{ 585{
620 struct xpnet_dev_private *priv; 586 struct xpnet_dev_private *priv;
621 587
622 588 priv = (struct xpnet_dev_private *)dev->priv;
623 priv = (struct xpnet_dev_private *) dev->priv;
624 589
625 priv->stats.tx_errors++; 590 priv->stats.tx_errors++;
626 return; 591 return;
627} 592}
628 593
629
630static int __init 594static int __init
631xpnet_init(void) 595xpnet_init(void)
632{ 596{
@@ -634,10 +598,8 @@ xpnet_init(void)
634 u32 license_num; 598 u32 license_num;
635 int result = -ENOMEM; 599 int result = -ENOMEM;
636 600
637 601 if (!ia64_platform_is("sn2"))
638 if (!ia64_platform_is("sn2")) {
639 return -ENODEV; 602 return -ENODEV;
640 }
641 603
642 dev_info(xpnet, "registering network device %s\n", XPNET_DEVICE_NAME); 604 dev_info(xpnet, "registering network device %s\n", XPNET_DEVICE_NAME);
643 605
@@ -647,9 +609,8 @@ xpnet_init(void)
647 */ 609 */
648 xpnet_device = alloc_netdev(sizeof(struct xpnet_dev_private), 610 xpnet_device = alloc_netdev(sizeof(struct xpnet_dev_private),
649 XPNET_DEVICE_NAME, ether_setup); 611 XPNET_DEVICE_NAME, ether_setup);
650 if (xpnet_device == NULL) { 612 if (xpnet_device == NULL)
651 return -ENOMEM; 613 return -ENOMEM;
652 }
653 614
654 netif_carrier_off(xpnet_device); 615 netif_carrier_off(xpnet_device);
655 616
@@ -672,7 +633,7 @@ xpnet_init(void)
672 license_num = sn_partition_serial_number_val(); 633 license_num = sn_partition_serial_number_val();
673 for (i = 3; i >= 0; i--) { 634 for (i = 3; i >= 0; i--) {
674 xpnet_device->dev_addr[XPNET_LICENSE_OCTET + i] = 635 xpnet_device->dev_addr[XPNET_LICENSE_OCTET + i] =
675 license_num & 0xff; 636 license_num & 0xff;
676 license_num = license_num >> 8; 637 license_num = license_num >> 8;
677 } 638 }
678 639
@@ -690,29 +651,27 @@ xpnet_init(void)
690 xpnet_device->features = NETIF_F_NO_CSUM; 651 xpnet_device->features = NETIF_F_NO_CSUM;
691 652
692 result = register_netdev(xpnet_device); 653 result = register_netdev(xpnet_device);
693 if (result != 0) { 654 if (result != 0)
694 free_netdev(xpnet_device); 655 free_netdev(xpnet_device);
695 }
696 656
697 return result; 657 return result;
698} 658}
699module_init(xpnet_init);
700 659
660module_init(xpnet_init);
701 661
702static void __exit 662static void __exit
703xpnet_exit(void) 663xpnet_exit(void)
704{ 664{
705 dev_info(xpnet, "unregistering network device %s\n", 665 dev_info(xpnet, "unregistering network device %s\n",
706 xpnet_device[0].name); 666 xpnet_device[0].name);
707 667
708 unregister_netdev(xpnet_device); 668 unregister_netdev(xpnet_device);
709 669
710 free_netdev(xpnet_device); 670 free_netdev(xpnet_device);
711} 671}
712module_exit(xpnet_exit);
713 672
673module_exit(xpnet_exit);
714 674
715MODULE_AUTHOR("Silicon Graphics, Inc."); 675MODULE_AUTHOR("Silicon Graphics, Inc.");
716MODULE_DESCRIPTION("Cross Partition Network adapter (XPNET)"); 676MODULE_DESCRIPTION("Cross Partition Network adapter (XPNET)");
717MODULE_LICENSE("GPL"); 677MODULE_LICENSE("GPL");
718
diff --git a/drivers/net/hamradio/dmascc.c b/drivers/net/hamradio/dmascc.c
index e04bf9926441..0b94833e23f7 100644
--- a/drivers/net/hamradio/dmascc.c
+++ b/drivers/net/hamradio/dmascc.c
@@ -1083,15 +1083,12 @@ static void start_timer(struct scc_priv *priv, int t, int r15)
1083 if (t == 0) { 1083 if (t == 0) {
1084 tm_isr(priv); 1084 tm_isr(priv);
1085 } else if (t > 0) { 1085 } else if (t > 0) {
1086 save_flags(flags);
1087 cli();
1088 outb(t & 0xFF, priv->tmr_cnt); 1086 outb(t & 0xFF, priv->tmr_cnt);
1089 outb((t >> 8) & 0xFF, priv->tmr_cnt); 1087 outb((t >> 8) & 0xFF, priv->tmr_cnt);
1090 if (priv->type != TYPE_TWIN) { 1088 if (priv->type != TYPE_TWIN) {
1091 write_scc(priv, R15, r15 | CTSIE); 1089 write_scc(priv, R15, r15 | CTSIE);
1092 priv->rr0 |= CTS; 1090 priv->rr0 |= CTS;
1093 } 1091 }
1094 restore_flags(flags);
1095 } 1092 }
1096} 1093}
1097 1094
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 4dc5b4b7a561..d3207c0da895 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -123,7 +123,6 @@ struct ppp {
123 u32 minseq; /* MP: min of most recent seqnos */ 123 u32 minseq; /* MP: min of most recent seqnos */
124 struct sk_buff_head mrq; /* MP: receive reconstruction queue */ 124 struct sk_buff_head mrq; /* MP: receive reconstruction queue */
125#endif /* CONFIG_PPP_MULTILINK */ 125#endif /* CONFIG_PPP_MULTILINK */
126 struct net_device_stats stats; /* statistics */
127#ifdef CONFIG_PPP_FILTER 126#ifdef CONFIG_PPP_FILTER
128 struct sock_filter *pass_filter; /* filter for packets to pass */ 127 struct sock_filter *pass_filter; /* filter for packets to pass */
129 struct sock_filter *active_filter;/* filter for pkts to reset idle */ 128 struct sock_filter *active_filter;/* filter for pkts to reset idle */
@@ -914,18 +913,10 @@ ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
914 913
915 outf: 914 outf:
916 kfree_skb(skb); 915 kfree_skb(skb);
917 ++ppp->stats.tx_dropped; 916 ++ppp->dev->stats.tx_dropped;
918 return 0; 917 return 0;
919} 918}
920 919
921static struct net_device_stats *
922ppp_net_stats(struct net_device *dev)
923{
924 struct ppp *ppp = (struct ppp *) dev->priv;
925
926 return &ppp->stats;
927}
928
929static int 920static int
930ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 921ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
931{ 922{
@@ -1095,8 +1086,8 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
1095#endif /* CONFIG_PPP_FILTER */ 1086#endif /* CONFIG_PPP_FILTER */
1096 } 1087 }
1097 1088
1098 ++ppp->stats.tx_packets; 1089 ++ppp->dev->stats.tx_packets;
1099 ppp->stats.tx_bytes += skb->len - 2; 1090 ppp->dev->stats.tx_bytes += skb->len - 2;
1100 1091
1101 switch (proto) { 1092 switch (proto) {
1102 case PPP_IP: 1093 case PPP_IP:
@@ -1171,7 +1162,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
1171 drop: 1162 drop:
1172 if (skb) 1163 if (skb)
1173 kfree_skb(skb); 1164 kfree_skb(skb);
1174 ++ppp->stats.tx_errors; 1165 ++ppp->dev->stats.tx_errors;
1175} 1166}
1176 1167
1177/* 1168/*
@@ -1409,7 +1400,7 @@ static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
1409 spin_unlock_bh(&pch->downl); 1400 spin_unlock_bh(&pch->downl);
1410 if (ppp->debug & 1) 1401 if (ppp->debug & 1)
1411 printk(KERN_ERR "PPP: no memory (fragment)\n"); 1402 printk(KERN_ERR "PPP: no memory (fragment)\n");
1412 ++ppp->stats.tx_errors; 1403 ++ppp->dev->stats.tx_errors;
1413 ++ppp->nxseq; 1404 ++ppp->nxseq;
1414 return 1; /* abandon the frame */ 1405 return 1; /* abandon the frame */
1415} 1406}
@@ -1538,7 +1529,7 @@ ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1538 1529
1539 if (skb->len > 0) 1530 if (skb->len > 0)
1540 /* note: a 0-length skb is used as an error indication */ 1531 /* note: a 0-length skb is used as an error indication */
1541 ++ppp->stats.rx_length_errors; 1532 ++ppp->dev->stats.rx_length_errors;
1542 1533
1543 kfree_skb(skb); 1534 kfree_skb(skb);
1544 ppp_receive_error(ppp); 1535 ppp_receive_error(ppp);
@@ -1547,7 +1538,7 @@ ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1547static void 1538static void
1548ppp_receive_error(struct ppp *ppp) 1539ppp_receive_error(struct ppp *ppp)
1549{ 1540{
1550 ++ppp->stats.rx_errors; 1541 ++ppp->dev->stats.rx_errors;
1551 if (ppp->vj) 1542 if (ppp->vj)
1552 slhc_toss(ppp->vj); 1543 slhc_toss(ppp->vj);
1553} 1544}
@@ -1627,8 +1618,8 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
1627 break; 1618 break;
1628 } 1619 }
1629 1620
1630 ++ppp->stats.rx_packets; 1621 ++ppp->dev->stats.rx_packets;
1631 ppp->stats.rx_bytes += skb->len - 2; 1622 ppp->dev->stats.rx_bytes += skb->len - 2;
1632 1623
1633 npi = proto_to_npindex(proto); 1624 npi = proto_to_npindex(proto);
1634 if (npi < 0) { 1625 if (npi < 0) {
@@ -1806,7 +1797,7 @@ ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1806 */ 1797 */
1807 if (seq_before(seq, ppp->nextseq)) { 1798 if (seq_before(seq, ppp->nextseq)) {
1808 kfree_skb(skb); 1799 kfree_skb(skb);
1809 ++ppp->stats.rx_dropped; 1800 ++ppp->dev->stats.rx_dropped;
1810 ppp_receive_error(ppp); 1801 ppp_receive_error(ppp);
1811 return; 1802 return;
1812 } 1803 }
@@ -1928,7 +1919,7 @@ ppp_mp_reconstruct(struct ppp *ppp)
1928 /* Got a complete packet yet? */ 1919 /* Got a complete packet yet? */
1929 if (lost == 0 && (p->BEbits & E) && (head->BEbits & B)) { 1920 if (lost == 0 && (p->BEbits & E) && (head->BEbits & B)) {
1930 if (len > ppp->mrru + 2) { 1921 if (len > ppp->mrru + 2) {
1931 ++ppp->stats.rx_length_errors; 1922 ++ppp->dev->stats.rx_length_errors;
1932 printk(KERN_DEBUG "PPP: reconstructed packet" 1923 printk(KERN_DEBUG "PPP: reconstructed packet"
1933 " is too long (%d)\n", len); 1924 " is too long (%d)\n", len);
1934 } else if (p == head) { 1925 } else if (p == head) {
@@ -1937,7 +1928,7 @@ ppp_mp_reconstruct(struct ppp *ppp)
1937 skb = skb_get(p); 1928 skb = skb_get(p);
1938 break; 1929 break;
1939 } else if ((skb = dev_alloc_skb(len)) == NULL) { 1930 } else if ((skb = dev_alloc_skb(len)) == NULL) {
1940 ++ppp->stats.rx_missed_errors; 1931 ++ppp->dev->stats.rx_missed_errors;
1941 printk(KERN_DEBUG "PPP: no memory for " 1932 printk(KERN_DEBUG "PPP: no memory for "
1942 "reconstructed packet"); 1933 "reconstructed packet");
1943 } else { 1934 } else {
@@ -1966,7 +1957,7 @@ ppp_mp_reconstruct(struct ppp *ppp)
1966 if (ppp->debug & 1) 1957 if (ppp->debug & 1)
1967 printk(KERN_DEBUG " missed pkts %u..%u\n", 1958 printk(KERN_DEBUG " missed pkts %u..%u\n",
1968 ppp->nextseq, head->sequence-1); 1959 ppp->nextseq, head->sequence-1);
1969 ++ppp->stats.rx_dropped; 1960 ++ppp->dev->stats.rx_dropped;
1970 ppp_receive_error(ppp); 1961 ppp_receive_error(ppp);
1971 } 1962 }
1972 1963
@@ -2377,12 +2368,12 @@ ppp_get_stats(struct ppp *ppp, struct ppp_stats *st)
2377 struct slcompress *vj = ppp->vj; 2368 struct slcompress *vj = ppp->vj;
2378 2369
2379 memset(st, 0, sizeof(*st)); 2370 memset(st, 0, sizeof(*st));
2380 st->p.ppp_ipackets = ppp->stats.rx_packets; 2371 st->p.ppp_ipackets = ppp->dev->stats.rx_packets;
2381 st->p.ppp_ierrors = ppp->stats.rx_errors; 2372 st->p.ppp_ierrors = ppp->dev->stats.rx_errors;
2382 st->p.ppp_ibytes = ppp->stats.rx_bytes; 2373 st->p.ppp_ibytes = ppp->dev->stats.rx_bytes;
2383 st->p.ppp_opackets = ppp->stats.tx_packets; 2374 st->p.ppp_opackets = ppp->dev->stats.tx_packets;
2384 st->p.ppp_oerrors = ppp->stats.tx_errors; 2375 st->p.ppp_oerrors = ppp->dev->stats.tx_errors;
2385 st->p.ppp_obytes = ppp->stats.tx_bytes; 2376 st->p.ppp_obytes = ppp->dev->stats.tx_bytes;
2386 if (!vj) 2377 if (!vj)
2387 return; 2378 return;
2388 st->vj.vjs_packets = vj->sls_o_compressed + vj->sls_o_uncompressed; 2379 st->vj.vjs_packets = vj->sls_o_compressed + vj->sls_o_uncompressed;
@@ -2436,7 +2427,6 @@ ppp_create_interface(int unit, int *retp)
2436 dev->priv = ppp; 2427 dev->priv = ppp;
2437 2428
2438 dev->hard_start_xmit = ppp_start_xmit; 2429 dev->hard_start_xmit = ppp_start_xmit;
2439 dev->get_stats = ppp_net_stats;
2440 dev->do_ioctl = ppp_net_ioctl; 2430 dev->do_ioctl = ppp_net_ioctl;
2441 2431
2442 ret = -EEXIST; 2432 ret = -EEXIST;
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index d91856b19f6f..0ce07a339c7e 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -668,16 +668,23 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
668 break; 668 break;
669 669
670 case TUNSETLINK: 670 case TUNSETLINK:
671 {
672 int ret;
673
671 /* Only allow setting the type when the interface is down */ 674 /* Only allow setting the type when the interface is down */
675 rtnl_lock();
672 if (tun->dev->flags & IFF_UP) { 676 if (tun->dev->flags & IFF_UP) {
673 DBG(KERN_INFO "%s: Linktype set failed because interface is up\n", 677 DBG(KERN_INFO "%s: Linktype set failed because interface is up\n",
674 tun->dev->name); 678 tun->dev->name);
675 return -EBUSY; 679 ret = -EBUSY;
676 } else { 680 } else {
677 tun->dev->type = (int) arg; 681 tun->dev->type = (int) arg;
678 DBG(KERN_INFO "%s: linktype set to %d\n", tun->dev->name, tun->dev->type); 682 DBG(KERN_INFO "%s: linktype set to %d\n", tun->dev->name, tun->dev->type);
683 ret = 0;
679 } 684 }
680 break; 685 rtnl_unlock();
686 return ret;
687 }
681 688
682#ifdef TUN_DEBUG 689#ifdef TUN_DEBUG
683 case TUNSETDEBUG: 690 case TUNSETDEBUG:
@@ -734,7 +741,12 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
734 case SIOCADDMULTI: 741 case SIOCADDMULTI:
735 /** Add the specified group to the character device's multicast filter 742 /** Add the specified group to the character device's multicast filter
736 * list. */ 743 * list. */
744 rtnl_lock();
745 netif_tx_lock_bh(tun->dev);
737 add_multi(tun->chr_filter, ifr.ifr_hwaddr.sa_data); 746 add_multi(tun->chr_filter, ifr.ifr_hwaddr.sa_data);
747 netif_tx_unlock_bh(tun->dev);
748 rtnl_unlock();
749
738 DBG(KERN_DEBUG "%s: add multi: %s\n", 750 DBG(KERN_DEBUG "%s: add multi: %s\n",
739 tun->dev->name, print_mac(mac, ifr.ifr_hwaddr.sa_data)); 751 tun->dev->name, print_mac(mac, ifr.ifr_hwaddr.sa_data));
740 return 0; 752 return 0;
@@ -742,7 +754,12 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
742 case SIOCDELMULTI: 754 case SIOCDELMULTI:
743 /** Remove the specified group from the character device's multicast 755 /** Remove the specified group from the character device's multicast
744 * filter list. */ 756 * filter list. */
757 rtnl_lock();
758 netif_tx_lock_bh(tun->dev);
745 del_multi(tun->chr_filter, ifr.ifr_hwaddr.sa_data); 759 del_multi(tun->chr_filter, ifr.ifr_hwaddr.sa_data);
760 netif_tx_unlock_bh(tun->dev);
761 rtnl_unlock();
762
746 DBG(KERN_DEBUG "%s: del multi: %s\n", 763 DBG(KERN_DEBUG "%s: del multi: %s\n",
747 tun->dev->name, print_mac(mac, ifr.ifr_hwaddr.sa_data)); 764 tun->dev->name, print_mac(mac, ifr.ifr_hwaddr.sa_data));
748 return 0; 765 return 0;
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 70092191fc53..c2642bc1d49b 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -56,8 +56,7 @@ obj-$(CONFIG_RTL8187) += rtl8187.o
56 56
57obj-$(CONFIG_ADM8211) += adm8211.o 57obj-$(CONFIG_ADM8211) += adm8211.o
58 58
59obj-$(CONFIG_IWL3945) += iwlwifi/ 59obj-$(CONFIG_IWLCORE) += iwlwifi/
60obj-$(CONFIG_IWL4965) += iwlwifi/
61obj-$(CONFIG_RT2X00) += rt2x00/ 60obj-$(CONFIG_RT2X00) += rt2x00/
62 61
63obj-$(CONFIG_P54_COMMON) += p54/ 62obj-$(CONFIG_P54_COMMON) += p54/
diff --git a/drivers/net/wireless/ath5k/hw.c b/drivers/net/wireless/ath5k/hw.c
index 87e782291a01..5fb1ae6ad3e2 100644
--- a/drivers/net/wireless/ath5k/hw.c
+++ b/drivers/net/wireless/ath5k/hw.c
@@ -304,14 +304,20 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
304 ah->ah_radio = AR5K_RF2413; 304 ah->ah_radio = AR5K_RF2413;
305 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A; 305 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
306 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC2) { 306 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC2) {
307
308 ah->ah_radio = AR5K_RF5413; 307 ah->ah_radio = AR5K_RF5413;
308 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
309 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5133) {
309 310
310 if (ah->ah_mac_srev <= AR5K_SREV_VER_AR5424 && 311 /* AR5424 */
311 ah->ah_mac_srev >= AR5K_SREV_VER_AR2424) 312 if (srev >= AR5K_SREV_VER_AR5424) {
313 ah->ah_radio = AR5K_RF5413;
312 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424; 314 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424;
313 else 315 /* AR2424 */
316 } else {
317 ah->ah_radio = AR5K_RF2413; /* For testing */
314 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A; 318 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
319 }
320
315 /* 321 /*
316 * Register returns 0x4 for radio revision 322 * Register returns 0x4 for radio revision
317 * so ath5k_hw_radio_revision doesn't parse the value 323 * so ath5k_hw_radio_revision doesn't parse the value
diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c
index 21c886a9a1d9..6dcbb3c87e72 100644
--- a/drivers/net/wireless/b43/dma.c
+++ b/drivers/net/wireless/b43/dma.c
@@ -980,6 +980,42 @@ void b43_dma_free(struct b43_wldev *dev)
980 destroy_ring(dma, tx_ring_mcast); 980 destroy_ring(dma, tx_ring_mcast);
981} 981}
982 982
983static int b43_dma_set_mask(struct b43_wldev *dev, u64 mask)
984{
985 u64 orig_mask = mask;
986 bool fallback = 0;
987 int err;
988
989 /* Try to set the DMA mask. If it fails, try falling back to a
990 * lower mask, as we can always also support a lower one. */
991 while (1) {
992 err = ssb_dma_set_mask(dev->dev, mask);
993 if (!err)
994 break;
995 if (mask == DMA_64BIT_MASK) {
996 mask = DMA_32BIT_MASK;
997 fallback = 1;
998 continue;
999 }
1000 if (mask == DMA_32BIT_MASK) {
1001 mask = DMA_30BIT_MASK;
1002 fallback = 1;
1003 continue;
1004 }
1005 b43err(dev->wl, "The machine/kernel does not support "
1006 "the required %u-bit DMA mask\n",
1007 (unsigned int)dma_mask_to_engine_type(orig_mask));
1008 return -EOPNOTSUPP;
1009 }
1010 if (fallback) {
1011 b43info(dev->wl, "DMA mask fallback from %u-bit to %u-bit\n",
1012 (unsigned int)dma_mask_to_engine_type(orig_mask),
1013 (unsigned int)dma_mask_to_engine_type(mask));
1014 }
1015
1016 return 0;
1017}
1018
983int b43_dma_init(struct b43_wldev *dev) 1019int b43_dma_init(struct b43_wldev *dev)
984{ 1020{
985 struct b43_dma *dma = &dev->dma; 1021 struct b43_dma *dma = &dev->dma;
@@ -989,14 +1025,9 @@ int b43_dma_init(struct b43_wldev *dev)
989 1025
990 dmamask = supported_dma_mask(dev); 1026 dmamask = supported_dma_mask(dev);
991 type = dma_mask_to_engine_type(dmamask); 1027 type = dma_mask_to_engine_type(dmamask);
992 err = ssb_dma_set_mask(dev->dev, dmamask); 1028 err = b43_dma_set_mask(dev, dmamask);
993 if (err) { 1029 if (err)
994 b43err(dev->wl, "The machine/kernel does not support " 1030 return err;
995 "the required DMA mask (0x%08X%08X)\n",
996 (unsigned int)((dmamask & 0xFFFFFFFF00000000ULL) >> 32),
997 (unsigned int)(dmamask & 0x00000000FFFFFFFFULL));
998 return -EOPNOTSUPP;
999 }
1000 1031
1001 err = -ENOMEM; 1032 err = -ENOMEM;
1002 /* setup TX DMA channels. */ 1033 /* setup TX DMA channels. */
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 943cc851c504..4bf8a99099fe 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -84,6 +84,10 @@ int b43_modparam_qos = 1;
84module_param_named(qos, b43_modparam_qos, int, 0444); 84module_param_named(qos, b43_modparam_qos, int, 0444);
85MODULE_PARM_DESC(qos, "Enable QOS support (default on)"); 85MODULE_PARM_DESC(qos, "Enable QOS support (default on)");
86 86
87static int modparam_btcoex = 1;
88module_param_named(btcoex, modparam_btcoex, int, 0444);
89MODULE_PARM_DESC(btcoex, "Enable Bluetooth coexistance (default on)");
90
87 91
88static const struct ssb_device_id b43_ssb_tbl[] = { 92static const struct ssb_device_id b43_ssb_tbl[] = {
89 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 5), 93 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 5),
@@ -3706,8 +3710,10 @@ static void setup_struct_wldev_for_init(struct b43_wldev *dev)
3706static void b43_bluetooth_coext_enable(struct b43_wldev *dev) 3710static void b43_bluetooth_coext_enable(struct b43_wldev *dev)
3707{ 3711{
3708 struct ssb_sprom *sprom = &dev->dev->bus->sprom; 3712 struct ssb_sprom *sprom = &dev->dev->bus->sprom;
3709 u32 hf; 3713 u64 hf;
3710 3714
3715 if (!modparam_btcoex)
3716 return;
3711 if (!(sprom->boardflags_lo & B43_BFL_BTCOEXIST)) 3717 if (!(sprom->boardflags_lo & B43_BFL_BTCOEXIST))
3712 return; 3718 return;
3713 if (dev->phy.type != B43_PHYTYPE_B && !dev->phy.gmode) 3719 if (dev->phy.type != B43_PHYTYPE_B && !dev->phy.gmode)
@@ -3719,11 +3725,13 @@ static void b43_bluetooth_coext_enable(struct b43_wldev *dev)
3719 else 3725 else
3720 hf |= B43_HF_BTCOEX; 3726 hf |= B43_HF_BTCOEX;
3721 b43_hf_write(dev, hf); 3727 b43_hf_write(dev, hf);
3722 //TODO
3723} 3728}
3724 3729
3725static void b43_bluetooth_coext_disable(struct b43_wldev *dev) 3730static void b43_bluetooth_coext_disable(struct b43_wldev *dev)
3726{ //TODO 3731{
3732 if (!modparam_btcoex)
3733 return;
3734 //TODO
3727} 3735}
3728 3736
3729static void b43_imcfglo_timeouts_workaround(struct b43_wldev *dev) 3737static void b43_imcfglo_timeouts_workaround(struct b43_wldev *dev)
@@ -3852,7 +3860,8 @@ static int b43_wireless_core_init(struct b43_wldev *dev)
3852 struct ssb_sprom *sprom = &bus->sprom; 3860 struct ssb_sprom *sprom = &bus->sprom;
3853 struct b43_phy *phy = &dev->phy; 3861 struct b43_phy *phy = &dev->phy;
3854 int err; 3862 int err;
3855 u32 hf, tmp; 3863 u64 hf;
3864 u32 tmp;
3856 3865
3857 B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT); 3866 B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
3858 3867
@@ -4414,8 +4423,16 @@ static int b43_one_core_attach(struct ssb_device *dev, struct b43_wl *wl)
4414 return err; 4423 return err;
4415} 4424}
4416 4425
4426#define IS_PDEV(pdev, _vendor, _device, _subvendor, _subdevice) ( \
4427 (pdev->vendor == PCI_VENDOR_ID_##_vendor) && \
4428 (pdev->device == _device) && \
4429 (pdev->subsystem_vendor == PCI_VENDOR_ID_##_subvendor) && \
4430 (pdev->subsystem_device == _subdevice) )
4431
4417static void b43_sprom_fixup(struct ssb_bus *bus) 4432static void b43_sprom_fixup(struct ssb_bus *bus)
4418{ 4433{
4434 struct pci_dev *pdev;
4435
4419 /* boardflags workarounds */ 4436 /* boardflags workarounds */
4420 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_DELL && 4437 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_DELL &&
4421 bus->chip_id == 0x4301 && bus->boardinfo.rev == 0x74) 4438 bus->chip_id == 0x4301 && bus->boardinfo.rev == 0x74)
@@ -4423,6 +4440,13 @@ static void b43_sprom_fixup(struct ssb_bus *bus)
4423 if (bus->boardinfo.vendor == PCI_VENDOR_ID_APPLE && 4440 if (bus->boardinfo.vendor == PCI_VENDOR_ID_APPLE &&
4424 bus->boardinfo.type == 0x4E && bus->boardinfo.rev > 0x40) 4441 bus->boardinfo.type == 0x4E && bus->boardinfo.rev > 0x40)
4425 bus->sprom.boardflags_lo |= B43_BFL_PACTRL; 4442 bus->sprom.boardflags_lo |= B43_BFL_PACTRL;
4443 if (bus->bustype == SSB_BUSTYPE_PCI) {
4444 pdev = bus->host_pci;
4445 if (IS_PDEV(pdev, BROADCOM, 0x4318, ASUSTEK, 0x100F) ||
4446 IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0015) ||
4447 IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0013))
4448 bus->sprom.boardflags_lo &= ~B43_BFL_BTCOEXIST;
4449 }
4426} 4450}
4427 4451
4428static void b43_wireless_exit(struct ssb_device *dev, struct b43_wl *wl) 4452static void b43_wireless_exit(struct ssb_device *dev, struct b43_wl *wl)
diff --git a/drivers/net/wireless/b43/phy.c b/drivers/net/wireless/b43/phy.c
index 575c5436ebdf..de024dc03718 100644
--- a/drivers/net/wireless/b43/phy.c
+++ b/drivers/net/wireless/b43/phy.c
@@ -2043,7 +2043,7 @@ int b43_phy_init(struct b43_wldev *dev)
2043void b43_set_rx_antenna(struct b43_wldev *dev, int antenna) 2043void b43_set_rx_antenna(struct b43_wldev *dev, int antenna)
2044{ 2044{
2045 struct b43_phy *phy = &dev->phy; 2045 struct b43_phy *phy = &dev->phy;
2046 u32 hf; 2046 u64 hf;
2047 u16 tmp; 2047 u16 tmp;
2048 int autodiv = 0; 2048 int autodiv = 0;
2049 2049
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index f844b738d34e..c4e631d14bfe 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -49,7 +49,9 @@ config IWL4965_HT
49 49
50config IWL4965_LEDS 50config IWL4965_LEDS
51 bool "Enable LEDS features in iwl4965 driver" 51 bool "Enable LEDS features in iwl4965 driver"
52 depends on IWL4965 && MAC80211_LEDS && LEDS_CLASS 52 depends on IWL4965
53 select MAC80211_LEDS
54 select LEDS_CLASS
53 select IWLWIFI_LEDS 55 select IWLWIFI_LEDS
54 ---help--- 56 ---help---
55 This option enables LEDS for the iwlwifi drivers 57 This option enables LEDS for the iwlwifi drivers
@@ -134,7 +136,9 @@ config IWL3945_SPECTRUM_MEASUREMENT
134 136
135config IWL3945_LEDS 137config IWL3945_LEDS
136 bool "Enable LEDS features in iwl3945 driver" 138 bool "Enable LEDS features in iwl3945 driver"
137 depends on IWL3945 && MAC80211_LEDS && LEDS_CLASS 139 depends on IWL3945
140 select MAC80211_LEDS
141 select LEDS_CLASS
138 ---help--- 142 ---help---
139 This option enables LEDS for the iwl3945 driver. 143 This option enables LEDS for the iwl3945 driver.
140 144
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile
index 4f3e88b12e3a..ec6187b75c3b 100644
--- a/drivers/net/wireless/iwlwifi/Makefile
+++ b/drivers/net/wireless/iwlwifi/Makefile
@@ -1,4 +1,4 @@
1obj-$(CONFIG_IWLCORE) := iwlcore.o 1obj-$(CONFIG_IWLCORE) += iwlcore.o
2iwlcore-objs := iwl-core.o iwl-eeprom.o iwl-hcmd.o 2iwlcore-objs := iwl-core.o iwl-eeprom.o iwl-hcmd.o
3iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o 3iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o
4iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o 4iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 1a5678fe4224..a1a0b3c581f1 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -6907,7 +6907,6 @@ static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6907 6907
6908 if (priv->vif != vif) { 6908 if (priv->vif != vif) {
6909 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); 6909 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6910 mutex_unlock(&priv->mutex);
6911 return 0; 6910 return 0;
6912 } 6911 }
6913 6912
diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c
index d7e2358a213a..d0bbcaaeb94c 100644
--- a/drivers/net/wireless/iwlwifi/iwl4965-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl4965-base.c
@@ -6473,7 +6473,6 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
6473 6473
6474 if (priv->vif != vif) { 6474 if (priv->vif != vif) {
6475 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); 6475 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6476 mutex_unlock(&priv->mutex);
6477 return 0; 6476 return 0;
6478 } 6477 }
6479 6478
diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index e5b3c282009c..5b375b289036 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -1186,7 +1186,7 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
1186 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); 1186 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1187 devindex = r.u; 1187 devindex = r.u;
1188 /* Now get the key, return it */ 1188 /* Now get the key, return it */
1189 if ((index < 0) || (index > 3)) 1189 if (index == -1 || index > 3)
1190 /* no index provided, use the current one */ 1190 /* no index provided, use the current one */
1191 index = devindex; 1191 index = devindex;
1192 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r); 1192 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);
diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
index 977751f372ff..d0b1fb15c709 100644
--- a/drivers/net/wireless/rndis_wlan.c
+++ b/drivers/net/wireless/rndis_wlan.c
@@ -2402,7 +2402,6 @@ static int bcm4320_early_init(struct usbnet *dev)
2402 priv->param_power_output = modparam_power_output; 2402 priv->param_power_output = modparam_power_output;
2403 priv->param_roamtrigger = modparam_roamtrigger; 2403 priv->param_roamtrigger = modparam_roamtrigger;
2404 priv->param_roamdelta = modparam_roamdelta; 2404 priv->param_roamdelta = modparam_roamdelta;
2405 priv->param_workaround_interval = modparam_workaround_interval;
2406 2405
2407 priv->param_country[0] = toupper(priv->param_country[0]); 2406 priv->param_country[0] = toupper(priv->param_country[0]);
2408 priv->param_country[1] = toupper(priv->param_country[1]); 2407 priv->param_country[1] = toupper(priv->param_country[1]);
@@ -2425,8 +2424,10 @@ static int bcm4320_early_init(struct usbnet *dev)
2425 else if (priv->param_roamdelta > 2) 2424 else if (priv->param_roamdelta > 2)
2426 priv->param_roamdelta = 2; 2425 priv->param_roamdelta = 2;
2427 2426
2428 if (priv->param_workaround_interval < 0) 2427 if (modparam_workaround_interval < 0)
2429 priv->param_workaround_interval = 500; 2428 priv->param_workaround_interval = 500;
2429 else
2430 priv->param_workaround_interval = modparam_workaround_interval;
2430 2431
2431 rndis_set_config_parameter_str(dev, "Country", priv->param_country); 2432 rndis_set_config_parameter_str(dev, "Country", priv->param_country);
2432 rndis_set_config_parameter_str(dev, "FrameBursting", 2433 rndis_set_config_parameter_str(dev, "FrameBursting",
diff --git a/drivers/net/wireless/rt2x00/Kconfig b/drivers/net/wireless/rt2x00/Kconfig
index a1e3938cba9b..ab1029e79884 100644
--- a/drivers/net/wireless/rt2x00/Kconfig
+++ b/drivers/net/wireless/rt2x00/Kconfig
@@ -60,7 +60,8 @@ config RT2400PCI_RFKILL
60 60
61config RT2400PCI_LEDS 61config RT2400PCI_LEDS
62 bool "RT2400 leds support" 62 bool "RT2400 leds support"
63 depends on RT2400PCI && LEDS_CLASS 63 depends on RT2400PCI
64 select LEDS_CLASS
64 select RT2X00_LIB_LEDS 65 select RT2X00_LIB_LEDS
65 ---help--- 66 ---help---
66 This adds support for led triggers provided my mac80211. 67 This adds support for led triggers provided my mac80211.
@@ -86,7 +87,8 @@ config RT2500PCI_RFKILL
86 87
87config RT2500PCI_LEDS 88config RT2500PCI_LEDS
88 bool "RT2500 leds support" 89 bool "RT2500 leds support"
89 depends on RT2500PCI && LEDS_CLASS 90 depends on RT2500PCI
91 select LEDS_CLASS
90 select RT2X00_LIB_LEDS 92 select RT2X00_LIB_LEDS
91 ---help--- 93 ---help---
92 This adds support for led triggers provided my mac80211. 94 This adds support for led triggers provided my mac80211.
@@ -114,7 +116,8 @@ config RT61PCI_RFKILL
114 116
115config RT61PCI_LEDS 117config RT61PCI_LEDS
116 bool "RT61 leds support" 118 bool "RT61 leds support"
117 depends on RT61PCI && LEDS_CLASS 119 depends on RT61PCI
120 select LEDS_CLASS
118 select RT2X00_LIB_LEDS 121 select RT2X00_LIB_LEDS
119 ---help--- 122 ---help---
120 This adds support for led triggers provided my mac80211. 123 This adds support for led triggers provided my mac80211.
@@ -130,7 +133,8 @@ config RT2500USB
130 133
131config RT2500USB_LEDS 134config RT2500USB_LEDS
132 bool "RT2500 leds support" 135 bool "RT2500 leds support"
133 depends on RT2500USB && LEDS_CLASS 136 depends on RT2500USB
137 select LEDS_CLASS
134 select RT2X00_LIB_LEDS 138 select RT2X00_LIB_LEDS
135 ---help--- 139 ---help---
136 This adds support for led triggers provided my mac80211. 140 This adds support for led triggers provided my mac80211.
@@ -148,7 +152,8 @@ config RT73USB
148 152
149config RT73USB_LEDS 153config RT73USB_LEDS
150 bool "RT73 leds support" 154 bool "RT73 leds support"
151 depends on RT73USB && LEDS_CLASS 155 depends on RT73USB
156 select LEDS_CLASS
152 select RT2X00_LIB_LEDS 157 select RT2X00_LIB_LEDS
153 ---help--- 158 ---help---
154 This adds support for led triggers provided my mac80211. 159 This adds support for led triggers provided my mac80211.
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index f9b7bdd27829..8ddb918f5f57 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -416,13 +416,13 @@ static void pci_bus_size_cardbus(struct pci_bus *bus)
416 * Reserve some resources for CardBus. We reserve 416 * Reserve some resources for CardBus. We reserve
417 * a fixed amount of bus space for CardBus bridges. 417 * a fixed amount of bus space for CardBus bridges.
418 */ 418 */
419 b_res[0].start = pci_cardbus_io_size; 419 b_res[0].start = 0;
420 b_res[0].end = b_res[0].start + pci_cardbus_io_size - 1; 420 b_res[0].end = pci_cardbus_io_size - 1;
421 b_res[0].flags |= IORESOURCE_IO; 421 b_res[0].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
422 422
423 b_res[1].start = pci_cardbus_io_size; 423 b_res[1].start = 0;
424 b_res[1].end = b_res[1].start + pci_cardbus_io_size - 1; 424 b_res[1].end = pci_cardbus_io_size - 1;
425 b_res[1].flags |= IORESOURCE_IO; 425 b_res[1].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
426 426
427 /* 427 /*
428 * Check whether prefetchable memory is supported 428 * Check whether prefetchable memory is supported
@@ -441,17 +441,17 @@ static void pci_bus_size_cardbus(struct pci_bus *bus)
441 * twice the size. 441 * twice the size.
442 */ 442 */
443 if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) { 443 if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
444 b_res[2].start = pci_cardbus_mem_size; 444 b_res[2].start = 0;
445 b_res[2].end = b_res[2].start + pci_cardbus_mem_size - 1; 445 b_res[2].end = pci_cardbus_mem_size - 1;
446 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH; 446 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_SIZEALIGN;
447 447
448 b_res[3].start = pci_cardbus_mem_size; 448 b_res[3].start = 0;
449 b_res[3].end = b_res[3].start + pci_cardbus_mem_size - 1; 449 b_res[3].end = pci_cardbus_mem_size - 1;
450 b_res[3].flags |= IORESOURCE_MEM; 450 b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
451 } else { 451 } else {
452 b_res[3].start = pci_cardbus_mem_size * 2; 452 b_res[3].start = 0;
453 b_res[3].end = b_res[3].start + pci_cardbus_mem_size * 2 - 1; 453 b_res[3].end = pci_cardbus_mem_size * 2 - 1;
454 b_res[3].flags |= IORESOURCE_MEM; 454 b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
455 } 455 }
456} 456}
457 457
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index ed8c06904807..8d8852651fd2 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -200,7 +200,6 @@ config PCMCIA_AU1X00
200config PCMCIA_SA1100 200config PCMCIA_SA1100
201 tristate "SA1100 support" 201 tristate "SA1100 support"
202 depends on ARM && ARCH_SA1100 && PCMCIA 202 depends on ARM && ARCH_SA1100 && PCMCIA
203 depends on ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL || MACH_ARMCORE
204 help 203 help
205 Say Y here to include support for SA11x0-based PCMCIA or CF 204 Say Y here to include support for SA11x0-based PCMCIA or CF
206 sockets, found on HP iPAQs, Yopy, and other StrongARM(R)/ 205 sockets, found on HP iPAQs, Yopy, and other StrongARM(R)/
@@ -221,6 +220,7 @@ config PCMCIA_SA1111
221config PCMCIA_PXA2XX 220config PCMCIA_PXA2XX
222 tristate "PXA2xx support" 221 tristate "PXA2xx support"
223 depends on ARM && ARCH_PXA && PCMCIA 222 depends on ARM && ARCH_PXA && PCMCIA
223 depends on ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL || MACH_ARMCORE
224 help 224 help
225 Say Y here to include support for the PXA2xx PCMCIA controller 225 Say Y here to include support for the PXA2xx PCMCIA controller
226 226
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index 2dcd1960aca8..98cbc9f18eed 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -84,10 +84,12 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res,
84 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) && 84 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
85 i < PNP_MAX_IRQ) 85 i < PNP_MAX_IRQ)
86 i++; 86 i++;
87 if (i >= PNP_MAX_IRQ && !warned) { 87 if (i >= PNP_MAX_IRQ) {
88 printk(KERN_WARNING "pnpacpi: exceeded the max number of IRQ " 88 if (!warned) {
89 "resources: %d \n", PNP_MAX_IRQ); 89 printk(KERN_WARNING "pnpacpi: exceeded the max number"
90 warned = 1; 90 " of IRQ resources: %d\n", PNP_MAX_IRQ);
91 warned = 1;
92 }
91 return; 93 return;
92 } 94 }
93 /* 95 /*
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index cb2e40506379..3271379a36db 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -1015,6 +1015,7 @@ static struct uart_ops sunzilog_pops = {
1015 .verify_port = sunzilog_verify_port, 1015 .verify_port = sunzilog_verify_port,
1016}; 1016};
1017 1017
1018static int uart_chip_count;
1018static struct uart_sunzilog_port *sunzilog_port_table; 1019static struct uart_sunzilog_port *sunzilog_port_table;
1019static struct zilog_layout __iomem **sunzilog_chip_regs; 1020static struct zilog_layout __iomem **sunzilog_chip_regs;
1020 1021
@@ -1350,16 +1351,22 @@ static int zilog_irq = -1;
1350 1351
1351static int __devinit zs_probe(struct of_device *op, const struct of_device_id *match) 1352static int __devinit zs_probe(struct of_device *op, const struct of_device_id *match)
1352{ 1353{
1353 static int inst; 1354 static int kbm_inst, uart_inst;
1355 int inst;
1354 struct uart_sunzilog_port *up; 1356 struct uart_sunzilog_port *up;
1355 struct zilog_layout __iomem *rp; 1357 struct zilog_layout __iomem *rp;
1356 int keyboard_mouse; 1358 int keyboard_mouse = 0;
1357 int err; 1359 int err;
1358 1360
1359 keyboard_mouse = 0;
1360 if (of_find_property(op->node, "keyboard", NULL)) 1361 if (of_find_property(op->node, "keyboard", NULL))
1361 keyboard_mouse = 1; 1362 keyboard_mouse = 1;
1362 1363
1364 /* uarts must come before keyboards/mice */
1365 if (keyboard_mouse)
1366 inst = uart_chip_count + kbm_inst;
1367 else
1368 inst = uart_inst;
1369
1363 sunzilog_chip_regs[inst] = of_ioremap(&op->resource[0], 0, 1370 sunzilog_chip_regs[inst] = of_ioremap(&op->resource[0], 0,
1364 sizeof(struct zilog_layout), 1371 sizeof(struct zilog_layout),
1365 "zs"); 1372 "zs");
@@ -1427,6 +1434,7 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1427 rp, sizeof(struct zilog_layout)); 1434 rp, sizeof(struct zilog_layout));
1428 return err; 1435 return err;
1429 } 1436 }
1437 uart_inst++;
1430 } else { 1438 } else {
1431 printk(KERN_INFO "%s: Keyboard at MMIO 0x%llx (irq = %d) " 1439 printk(KERN_INFO "%s: Keyboard at MMIO 0x%llx (irq = %d) "
1432 "is a %s\n", 1440 "is a %s\n",
@@ -1438,12 +1446,11 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1438 op->dev.bus_id, 1446 op->dev.bus_id,
1439 (unsigned long long) up[1].port.mapbase, 1447 (unsigned long long) up[1].port.mapbase,
1440 op->irqs[0], sunzilog_type(&up[1].port)); 1448 op->irqs[0], sunzilog_type(&up[1].port));
1449 kbm_inst++;
1441 } 1450 }
1442 1451
1443 dev_set_drvdata(&op->dev, &up[0]); 1452 dev_set_drvdata(&op->dev, &up[0]);
1444 1453
1445 inst++;
1446
1447 return 0; 1454 return 0;
1448} 1455}
1449 1456
@@ -1491,28 +1498,25 @@ static struct of_platform_driver zs_driver = {
1491static int __init sunzilog_init(void) 1498static int __init sunzilog_init(void)
1492{ 1499{
1493 struct device_node *dp; 1500 struct device_node *dp;
1494 int err, uart_count; 1501 int err;
1495 int num_keybms; 1502 int num_keybms = 0;
1496 int num_sunzilog = 0; 1503 int num_sunzilog = 0;
1497 1504
1498 num_keybms = 0;
1499 for_each_node_by_name(dp, "zs") { 1505 for_each_node_by_name(dp, "zs") {
1500 num_sunzilog++; 1506 num_sunzilog++;
1501 if (of_find_property(dp, "keyboard", NULL)) 1507 if (of_find_property(dp, "keyboard", NULL))
1502 num_keybms++; 1508 num_keybms++;
1503 } 1509 }
1504 1510
1505 uart_count = 0;
1506 if (num_sunzilog) { 1511 if (num_sunzilog) {
1507 int uart_count;
1508
1509 err = sunzilog_alloc_tables(num_sunzilog); 1512 err = sunzilog_alloc_tables(num_sunzilog);
1510 if (err) 1513 if (err)
1511 goto out; 1514 goto out;
1512 1515
1513 uart_count = (num_sunzilog * 2) - (2 * num_keybms); 1516 uart_chip_count = num_sunzilog - num_keybms;
1514 1517
1515 err = sunserial_register_minors(&sunzilog_reg, uart_count); 1518 err = sunserial_register_minors(&sunzilog_reg,
1519 uart_chip_count * 2);
1516 if (err) 1520 if (err)
1517 goto out_free_tables; 1521 goto out_free_tables;
1518 } 1522 }
diff --git a/drivers/ssb/pci.c b/drivers/ssb/pci.c
index 904b1a8d0885..57c4ccfab1ee 100644
--- a/drivers/ssb/pci.c
+++ b/drivers/ssb/pci.c
@@ -484,6 +484,11 @@ static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out,
484 goto unsupported; 484 goto unsupported;
485 } 485 }
486 486
487 if (out->boardflags_lo == 0xFFFF)
488 out->boardflags_lo = 0; /* per specs */
489 if (out->boardflags_hi == 0xFFFF)
490 out->boardflags_hi = 0; /* per specs */
491
487 return 0; 492 return 0;
488unsupported: 493unsupported:
489 ssb_printk(KERN_WARNING PFX "Unsupported SPROM revision %d " 494 ssb_printk(KERN_WARNING PFX "Unsupported SPROM revision %d "
diff --git a/fs/Kconfig b/fs/Kconfig
index 028ae38ecc52..8b18a8758677 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -689,6 +689,7 @@ config ZISOFS
689 689
690config UDF_FS 690config UDF_FS
691 tristate "UDF file system support" 691 tristate "UDF file system support"
692 select CRC_ITU_T
692 help 693 help
693 This is the new file system used on some CD-ROMs and DVDs. Say Y if 694 This is the new file system used on some CD-ROMs and DVDs. Say Y if
694 you intend to mount DVD discs or CDRW's written in packet mode, or 695 you intend to mount DVD discs or CDRW's written in packet mode, or
diff --git a/fs/dcache.c b/fs/dcache.c
index 43455776711e..3ee588d5f585 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1746,12 +1746,21 @@ shouldnt_be_hashed:
1746 goto shouldnt_be_hashed; 1746 goto shouldnt_be_hashed;
1747} 1747}
1748 1748
1749static int prepend(char **buffer, int *buflen, const char *str,
1750 int namelen)
1751{
1752 *buflen -= namelen;
1753 if (*buflen < 0)
1754 return -ENAMETOOLONG;
1755 *buffer -= namelen;
1756 memcpy(*buffer, str, namelen);
1757 return 0;
1758}
1759
1749/** 1760/**
1750 * d_path - return the path of a dentry 1761 * d_path - return the path of a dentry
1751 * @dentry: dentry to report 1762 * @path: the dentry/vfsmount to report
1752 * @vfsmnt: vfsmnt to which the dentry belongs 1763 * @root: root vfsmnt/dentry (may be modified by this function)
1753 * @root: root dentry
1754 * @rootmnt: vfsmnt to which the root dentry belongs
1755 * @buffer: buffer to return value in 1764 * @buffer: buffer to return value in
1756 * @buflen: buffer length 1765 * @buflen: buffer length
1757 * 1766 *
@@ -1761,23 +1770,22 @@ shouldnt_be_hashed:
1761 * Returns the buffer or an error code if the path was too long. 1770 * Returns the buffer or an error code if the path was too long.
1762 * 1771 *
1763 * "buflen" should be positive. Caller holds the dcache_lock. 1772 * "buflen" should be positive. Caller holds the dcache_lock.
1773 *
1774 * If path is not reachable from the supplied root, then the value of
1775 * root is changed (without modifying refcounts).
1764 */ 1776 */
1765static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt, 1777char *__d_path(const struct path *path, struct path *root,
1766 struct path *root, char *buffer, int buflen) 1778 char *buffer, int buflen)
1767{ 1779{
1780 struct dentry *dentry = path->dentry;
1781 struct vfsmount *vfsmnt = path->mnt;
1768 char * end = buffer+buflen; 1782 char * end = buffer+buflen;
1769 char * retval; 1783 char * retval;
1770 int namelen; 1784
1771 1785 prepend(&end, &buflen, "\0", 1);
1772 *--end = '\0'; 1786 if (!IS_ROOT(dentry) && d_unhashed(dentry) &&
1773 buflen--; 1787 (prepend(&end, &buflen, " (deleted)", 10) != 0))
1774 if (!IS_ROOT(dentry) && d_unhashed(dentry)) {
1775 buflen -= 10;
1776 end -= 10;
1777 if (buflen < 0)
1778 goto Elong; 1788 goto Elong;
1779 memcpy(end, " (deleted)", 10);
1780 }
1781 1789
1782 if (buflen < 1) 1790 if (buflen < 1)
1783 goto Elong; 1791 goto Elong;
@@ -1804,13 +1812,10 @@ static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
1804 } 1812 }
1805 parent = dentry->d_parent; 1813 parent = dentry->d_parent;
1806 prefetch(parent); 1814 prefetch(parent);
1807 namelen = dentry->d_name.len; 1815 if ((prepend(&end, &buflen, dentry->d_name.name,
1808 buflen -= namelen + 1; 1816 dentry->d_name.len) != 0) ||
1809 if (buflen < 0) 1817 (prepend(&end, &buflen, "/", 1) != 0))
1810 goto Elong; 1818 goto Elong;
1811 end -= namelen;
1812 memcpy(end, dentry->d_name.name, namelen);
1813 *--end = '/';
1814 retval = end; 1819 retval = end;
1815 dentry = parent; 1820 dentry = parent;
1816 } 1821 }
@@ -1818,12 +1823,12 @@ static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
1818 return retval; 1823 return retval;
1819 1824
1820global_root: 1825global_root:
1821 namelen = dentry->d_name.len; 1826 retval += 1; /* hit the slash */
1822 buflen -= namelen; 1827 if (prepend(&retval, &buflen, dentry->d_name.name,
1823 if (buflen < 0) 1828 dentry->d_name.len) != 0)
1824 goto Elong; 1829 goto Elong;
1825 retval -= namelen-1; /* hit the slash */ 1830 root->mnt = vfsmnt;
1826 memcpy(retval, dentry->d_name.name, namelen); 1831 root->dentry = dentry;
1827 return retval; 1832 return retval;
1828Elong: 1833Elong:
1829 return ERR_PTR(-ENAMETOOLONG); 1834 return ERR_PTR(-ENAMETOOLONG);
@@ -1846,6 +1851,7 @@ char *d_path(struct path *path, char *buf, int buflen)
1846{ 1851{
1847 char *res; 1852 char *res;
1848 struct path root; 1853 struct path root;
1854 struct path tmp;
1849 1855
1850 /* 1856 /*
1851 * We have various synthetic filesystems that never get mounted. On 1857 * We have various synthetic filesystems that never get mounted. On
@@ -1859,10 +1865,11 @@ char *d_path(struct path *path, char *buf, int buflen)
1859 1865
1860 read_lock(&current->fs->lock); 1866 read_lock(&current->fs->lock);
1861 root = current->fs->root; 1867 root = current->fs->root;
1862 path_get(&current->fs->root); 1868 path_get(&root);
1863 read_unlock(&current->fs->lock); 1869 read_unlock(&current->fs->lock);
1864 spin_lock(&dcache_lock); 1870 spin_lock(&dcache_lock);
1865 res = __d_path(path->dentry, path->mnt, &root, buf, buflen); 1871 tmp = root;
1872 res = __d_path(path, &tmp, buf, buflen);
1866 spin_unlock(&dcache_lock); 1873 spin_unlock(&dcache_lock);
1867 path_put(&root); 1874 path_put(&root);
1868 return res; 1875 return res;
@@ -1890,6 +1897,48 @@ char *dynamic_dname(struct dentry *dentry, char *buffer, int buflen,
1890} 1897}
1891 1898
1892/* 1899/*
1900 * Write full pathname from the root of the filesystem into the buffer.
1901 */
1902char *dentry_path(struct dentry *dentry, char *buf, int buflen)
1903{
1904 char *end = buf + buflen;
1905 char *retval;
1906
1907 spin_lock(&dcache_lock);
1908 prepend(&end, &buflen, "\0", 1);
1909 if (!IS_ROOT(dentry) && d_unhashed(dentry) &&
1910 (prepend(&end, &buflen, "//deleted", 9) != 0))
1911 goto Elong;
1912 if (buflen < 1)
1913 goto Elong;
1914 /* Get '/' right */
1915 retval = end-1;
1916 *retval = '/';
1917
1918 for (;;) {
1919 struct dentry *parent;
1920 if (IS_ROOT(dentry))
1921 break;
1922
1923 parent = dentry->d_parent;
1924 prefetch(parent);
1925
1926 if ((prepend(&end, &buflen, dentry->d_name.name,
1927 dentry->d_name.len) != 0) ||
1928 (prepend(&end, &buflen, "/", 1) != 0))
1929 goto Elong;
1930
1931 retval = end;
1932 dentry = parent;
1933 }
1934 spin_unlock(&dcache_lock);
1935 return retval;
1936Elong:
1937 spin_unlock(&dcache_lock);
1938 return ERR_PTR(-ENAMETOOLONG);
1939}
1940
1941/*
1893 * NOTE! The user-level library version returns a 1942 * NOTE! The user-level library version returns a
1894 * character pointer. The kernel system call just 1943 * character pointer. The kernel system call just
1895 * returns the length of the buffer filled (which 1944 * returns the length of the buffer filled (which
@@ -1918,9 +1967,9 @@ asmlinkage long sys_getcwd(char __user *buf, unsigned long size)
1918 1967
1919 read_lock(&current->fs->lock); 1968 read_lock(&current->fs->lock);
1920 pwd = current->fs->pwd; 1969 pwd = current->fs->pwd;
1921 path_get(&current->fs->pwd); 1970 path_get(&pwd);
1922 root = current->fs->root; 1971 root = current->fs->root;
1923 path_get(&current->fs->root); 1972 path_get(&root);
1924 read_unlock(&current->fs->lock); 1973 read_unlock(&current->fs->lock);
1925 1974
1926 error = -ENOENT; 1975 error = -ENOENT;
@@ -1928,9 +1977,10 @@ asmlinkage long sys_getcwd(char __user *buf, unsigned long size)
1928 spin_lock(&dcache_lock); 1977 spin_lock(&dcache_lock);
1929 if (pwd.dentry->d_parent == pwd.dentry || !d_unhashed(pwd.dentry)) { 1978 if (pwd.dentry->d_parent == pwd.dentry || !d_unhashed(pwd.dentry)) {
1930 unsigned long len; 1979 unsigned long len;
1980 struct path tmp = root;
1931 char * cwd; 1981 char * cwd;
1932 1982
1933 cwd = __d_path(pwd.dentry, pwd.mnt, &root, page, PAGE_SIZE); 1983 cwd = __d_path(&pwd, &tmp, page, PAGE_SIZE);
1934 spin_unlock(&dcache_lock); 1984 spin_unlock(&dcache_lock);
1935 1985
1936 error = PTR_ERR(cwd); 1986 error = PTR_ERR(cwd);
diff --git a/fs/dlm/Makefile b/fs/dlm/Makefile
index d248e60951ba..ca1c9124c8ce 100644
--- a/fs/dlm/Makefile
+++ b/fs/dlm/Makefile
@@ -10,6 +10,7 @@ dlm-y := ast.o \
10 midcomms.o \ 10 midcomms.o \
11 netlink.o \ 11 netlink.o \
12 lowcomms.o \ 12 lowcomms.o \
13 plock.o \
13 rcom.o \ 14 rcom.o \
14 recover.o \ 15 recover.o \
15 recoverd.o \ 16 recoverd.o \
diff --git a/fs/dlm/config.c b/fs/dlm/config.c
index c3ad1dff3b25..eac23bd288b2 100644
--- a/fs/dlm/config.c
+++ b/fs/dlm/config.c
@@ -114,7 +114,7 @@ struct cluster_attribute {
114}; 114};
115 115
116static ssize_t cluster_set(struct cluster *cl, unsigned int *cl_field, 116static ssize_t cluster_set(struct cluster *cl, unsigned int *cl_field,
117 unsigned int *info_field, int check_zero, 117 int *info_field, int check_zero,
118 const char *buf, size_t len) 118 const char *buf, size_t len)
119{ 119{
120 unsigned int x; 120 unsigned int x;
@@ -284,6 +284,7 @@ struct node {
284 struct list_head list; /* space->members */ 284 struct list_head list; /* space->members */
285 int nodeid; 285 int nodeid;
286 int weight; 286 int weight;
287 int new;
287}; 288};
288 289
289static struct configfs_group_operations clusters_ops = { 290static struct configfs_group_operations clusters_ops = {
@@ -565,6 +566,7 @@ static struct config_item *make_node(struct config_group *g, const char *name)
565 config_item_init_type_name(&nd->item, name, &node_type); 566 config_item_init_type_name(&nd->item, name, &node_type);
566 nd->nodeid = -1; 567 nd->nodeid = -1;
567 nd->weight = 1; /* default weight of 1 if none is set */ 568 nd->weight = 1; /* default weight of 1 if none is set */
569 nd->new = 1; /* set to 0 once it's been read by dlm_nodeid_list() */
568 570
569 mutex_lock(&sp->members_lock); 571 mutex_lock(&sp->members_lock);
570 list_add(&nd->list, &sp->members); 572 list_add(&nd->list, &sp->members);
@@ -805,12 +807,13 @@ static void put_comm(struct comm *cm)
805} 807}
806 808
807/* caller must free mem */ 809/* caller must free mem */
808int dlm_nodeid_list(char *lsname, int **ids_out) 810int dlm_nodeid_list(char *lsname, int **ids_out, int *ids_count_out,
811 int **new_out, int *new_count_out)
809{ 812{
810 struct space *sp; 813 struct space *sp;
811 struct node *nd; 814 struct node *nd;
812 int i = 0, rv = 0; 815 int i = 0, rv = 0, ids_count = 0, new_count = 0;
813 int *ids; 816 int *ids, *new;
814 817
815 sp = get_space(lsname); 818 sp = get_space(lsname);
816 if (!sp) 819 if (!sp)
@@ -818,23 +821,50 @@ int dlm_nodeid_list(char *lsname, int **ids_out)
818 821
819 mutex_lock(&sp->members_lock); 822 mutex_lock(&sp->members_lock);
820 if (!sp->members_count) { 823 if (!sp->members_count) {
821 rv = 0; 824 rv = -EINVAL;
825 printk(KERN_ERR "dlm: zero members_count\n");
822 goto out; 826 goto out;
823 } 827 }
824 828
825 ids = kcalloc(sp->members_count, sizeof(int), GFP_KERNEL); 829 ids_count = sp->members_count;
830
831 ids = kcalloc(ids_count, sizeof(int), GFP_KERNEL);
826 if (!ids) { 832 if (!ids) {
827 rv = -ENOMEM; 833 rv = -ENOMEM;
828 goto out; 834 goto out;
829 } 835 }
830 836
831 rv = sp->members_count; 837 list_for_each_entry(nd, &sp->members, list) {
832 list_for_each_entry(nd, &sp->members, list)
833 ids[i++] = nd->nodeid; 838 ids[i++] = nd->nodeid;
839 if (nd->new)
840 new_count++;
841 }
842
843 if (ids_count != i)
844 printk(KERN_ERR "dlm: bad nodeid count %d %d\n", ids_count, i);
845
846 if (!new_count)
847 goto out_ids;
848
849 new = kcalloc(new_count, sizeof(int), GFP_KERNEL);
850 if (!new) {
851 kfree(ids);
852 rv = -ENOMEM;
853 goto out;
854 }
834 855
835 if (rv != i) 856 i = 0;
836 printk("bad nodeid count %d %d\n", rv, i); 857 list_for_each_entry(nd, &sp->members, list) {
858 if (nd->new) {
859 new[i++] = nd->nodeid;
860 nd->new = 0;
861 }
862 }
863 *new_count_out = new_count;
864 *new_out = new;
837 865
866 out_ids:
867 *ids_count_out = ids_count;
838 *ids_out = ids; 868 *ids_out = ids;
839 out: 869 out:
840 mutex_unlock(&sp->members_lock); 870 mutex_unlock(&sp->members_lock);
diff --git a/fs/dlm/config.h b/fs/dlm/config.h
index a3170fe22090..4f1d6fce58c5 100644
--- a/fs/dlm/config.h
+++ b/fs/dlm/config.h
@@ -35,7 +35,8 @@ extern struct dlm_config_info dlm_config;
35int dlm_config_init(void); 35int dlm_config_init(void);
36void dlm_config_exit(void); 36void dlm_config_exit(void);
37int dlm_node_weight(char *lsname, int nodeid); 37int dlm_node_weight(char *lsname, int nodeid);
38int dlm_nodeid_list(char *lsname, int **ids_out); 38int dlm_nodeid_list(char *lsname, int **ids_out, int *ids_count_out,
39 int **new_out, int *new_count_out);
39int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr); 40int dlm_nodeid_to_addr(int nodeid, struct sockaddr_storage *addr);
40int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid); 41int dlm_addr_to_nodeid(struct sockaddr_storage *addr, int *nodeid);
41int dlm_our_nodeid(void); 42int dlm_our_nodeid(void);
diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h
index 7a8824f475f2..5a7ac33b629c 100644
--- a/fs/dlm/dlm_internal.h
+++ b/fs/dlm/dlm_internal.h
@@ -42,8 +42,6 @@
42#include <linux/dlm.h> 42#include <linux/dlm.h>
43#include "config.h" 43#include "config.h"
44 44
45#define DLM_LOCKSPACE_LEN 64
46
47/* Size of the temp buffer midcomms allocates on the stack. 45/* Size of the temp buffer midcomms allocates on the stack.
48 We try to make this large enough so most messages fit. 46 We try to make this large enough so most messages fit.
49 FIXME: should sctp make this unnecessary? */ 47 FIXME: should sctp make this unnecessary? */
@@ -132,8 +130,10 @@ struct dlm_member {
132 130
133struct dlm_recover { 131struct dlm_recover {
134 struct list_head list; 132 struct list_head list;
135 int *nodeids; 133 int *nodeids; /* nodeids of all members */
136 int node_count; 134 int node_count;
135 int *new; /* nodeids of new members */
136 int new_count;
137 uint64_t seq; 137 uint64_t seq;
138}; 138};
139 139
@@ -579,6 +579,8 @@ static inline int dlm_no_directory(struct dlm_ls *ls)
579int dlm_netlink_init(void); 579int dlm_netlink_init(void);
580void dlm_netlink_exit(void); 580void dlm_netlink_exit(void);
581void dlm_timeout_warn(struct dlm_lkb *lkb); 581void dlm_timeout_warn(struct dlm_lkb *lkb);
582int dlm_plock_init(void);
583void dlm_plock_exit(void);
582 584
583#ifdef CONFIG_DLM_DEBUG 585#ifdef CONFIG_DLM_DEBUG
584int dlm_register_debugfs(void); 586int dlm_register_debugfs(void);
diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index 8f250ac8b928..2d3d1027ce2b 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -165,7 +165,7 @@ void dlm_print_lkb(struct dlm_lkb *lkb)
165 lkb->lkb_grmode, lkb->lkb_wait_type, lkb->lkb_ast_type); 165 lkb->lkb_grmode, lkb->lkb_wait_type, lkb->lkb_ast_type);
166} 166}
167 167
168void dlm_print_rsb(struct dlm_rsb *r) 168static void dlm_print_rsb(struct dlm_rsb *r)
169{ 169{
170 printk(KERN_ERR "rsb: nodeid %d flags %lx first %x rlc %d name %s\n", 170 printk(KERN_ERR "rsb: nodeid %d flags %lx first %x rlc %d name %s\n",
171 r->res_nodeid, r->res_flags, r->res_first_lkid, 171 r->res_nodeid, r->res_flags, r->res_first_lkid,
@@ -1956,8 +1956,7 @@ static void confirm_master(struct dlm_rsb *r, int error)
1956 list_del_init(&lkb->lkb_rsb_lookup); 1956 list_del_init(&lkb->lkb_rsb_lookup);
1957 r->res_first_lkid = lkb->lkb_id; 1957 r->res_first_lkid = lkb->lkb_id;
1958 _request_lock(r, lkb); 1958 _request_lock(r, lkb);
1959 } else 1959 }
1960 r->res_nodeid = -1;
1961 break; 1960 break;
1962 1961
1963 default: 1962 default:
diff --git a/fs/dlm/lock.h b/fs/dlm/lock.h
index 05d9c82e646b..88e93c80cc22 100644
--- a/fs/dlm/lock.h
+++ b/fs/dlm/lock.h
@@ -13,7 +13,6 @@
13#ifndef __LOCK_DOT_H__ 13#ifndef __LOCK_DOT_H__
14#define __LOCK_DOT_H__ 14#define __LOCK_DOT_H__
15 15
16void dlm_print_rsb(struct dlm_rsb *r);
17void dlm_dump_rsb(struct dlm_rsb *r); 16void dlm_dump_rsb(struct dlm_rsb *r);
18void dlm_print_lkb(struct dlm_lkb *lkb); 17void dlm_print_lkb(struct dlm_lkb *lkb);
19void dlm_receive_message_saved(struct dlm_ls *ls, struct dlm_message *ms); 18void dlm_receive_message_saved(struct dlm_ls *ls, struct dlm_message *ms);
diff --git a/fs/dlm/main.c b/fs/dlm/main.c
index 58487fb95a4c..b80e0aa3cfa5 100644
--- a/fs/dlm/main.c
+++ b/fs/dlm/main.c
@@ -46,10 +46,16 @@ static int __init init_dlm(void)
46 if (error) 46 if (error)
47 goto out_user; 47 goto out_user;
48 48
49 error = dlm_plock_init();
50 if (error)
51 goto out_netlink;
52
49 printk("DLM (built %s %s) installed\n", __DATE__, __TIME__); 53 printk("DLM (built %s %s) installed\n", __DATE__, __TIME__);
50 54
51 return 0; 55 return 0;
52 56
57 out_netlink:
58 dlm_netlink_exit();
53 out_user: 59 out_user:
54 dlm_user_exit(); 60 dlm_user_exit();
55 out_debug: 61 out_debug:
@@ -66,6 +72,7 @@ static int __init init_dlm(void)
66 72
67static void __exit exit_dlm(void) 73static void __exit exit_dlm(void)
68{ 74{
75 dlm_plock_exit();
69 dlm_netlink_exit(); 76 dlm_netlink_exit();
70 dlm_user_exit(); 77 dlm_user_exit();
71 dlm_config_exit(); 78 dlm_config_exit();
diff --git a/fs/dlm/member.c b/fs/dlm/member.c
index fa17f5a27883..26133f05ae3a 100644
--- a/fs/dlm/member.c
+++ b/fs/dlm/member.c
@@ -210,6 +210,23 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out)
210 } 210 }
211 } 211 }
212 212
213 /* Add an entry to ls_nodes_gone for members that were removed and
214 then added again, so that previous state for these nodes will be
215 cleared during recovery. */
216
217 for (i = 0; i < rv->new_count; i++) {
218 if (!dlm_is_member(ls, rv->new[i]))
219 continue;
220 log_debug(ls, "new nodeid %d is a re-added member", rv->new[i]);
221
222 memb = kzalloc(sizeof(struct dlm_member), GFP_KERNEL);
223 if (!memb)
224 return -ENOMEM;
225 memb->nodeid = rv->new[i];
226 list_add_tail(&memb->list, &ls->ls_nodes_gone);
227 neg++;
228 }
229
213 /* add new members to ls_nodes */ 230 /* add new members to ls_nodes */
214 231
215 for (i = 0; i < rv->node_count; i++) { 232 for (i = 0; i < rv->node_count; i++) {
@@ -314,15 +331,16 @@ int dlm_ls_stop(struct dlm_ls *ls)
314int dlm_ls_start(struct dlm_ls *ls) 331int dlm_ls_start(struct dlm_ls *ls)
315{ 332{
316 struct dlm_recover *rv = NULL, *rv_old; 333 struct dlm_recover *rv = NULL, *rv_old;
317 int *ids = NULL; 334 int *ids = NULL, *new = NULL;
318 int error, count; 335 int error, ids_count = 0, new_count = 0;
319 336
320 rv = kzalloc(sizeof(struct dlm_recover), GFP_KERNEL); 337 rv = kzalloc(sizeof(struct dlm_recover), GFP_KERNEL);
321 if (!rv) 338 if (!rv)
322 return -ENOMEM; 339 return -ENOMEM;
323 340
324 error = count = dlm_nodeid_list(ls->ls_name, &ids); 341 error = dlm_nodeid_list(ls->ls_name, &ids, &ids_count,
325 if (error <= 0) 342 &new, &new_count);
343 if (error < 0)
326 goto fail; 344 goto fail;
327 345
328 spin_lock(&ls->ls_recover_lock); 346 spin_lock(&ls->ls_recover_lock);
@@ -337,14 +355,19 @@ int dlm_ls_start(struct dlm_ls *ls)
337 } 355 }
338 356
339 rv->nodeids = ids; 357 rv->nodeids = ids;
340 rv->node_count = count; 358 rv->node_count = ids_count;
359 rv->new = new;
360 rv->new_count = new_count;
341 rv->seq = ++ls->ls_recover_seq; 361 rv->seq = ++ls->ls_recover_seq;
342 rv_old = ls->ls_recover_args; 362 rv_old = ls->ls_recover_args;
343 ls->ls_recover_args = rv; 363 ls->ls_recover_args = rv;
344 spin_unlock(&ls->ls_recover_lock); 364 spin_unlock(&ls->ls_recover_lock);
345 365
346 if (rv_old) { 366 if (rv_old) {
367 log_error(ls, "unused recovery %llx %d",
368 (unsigned long long)rv_old->seq, rv_old->node_count);
347 kfree(rv_old->nodeids); 369 kfree(rv_old->nodeids);
370 kfree(rv_old->new);
348 kfree(rv_old); 371 kfree(rv_old);
349 } 372 }
350 373
@@ -354,6 +377,7 @@ int dlm_ls_start(struct dlm_ls *ls)
354 fail: 377 fail:
355 kfree(rv); 378 kfree(rv);
356 kfree(ids); 379 kfree(ids);
380 kfree(new);
357 return error; 381 return error;
358} 382}
359 383
diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/dlm/plock.c
index 2ebd374b3143..d6d6e370f89c 100644
--- a/fs/gfs2/locking/dlm/plock.c
+++ b/fs/dlm/plock.c
@@ -1,17 +1,19 @@
1/* 1/*
2 * Copyright (C) 2005 Red Hat, Inc. All rights reserved. 2 * Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved.
3 * 3 *
4 * This copyrighted material is made available to anyone wishing to use, 4 * This copyrighted material is made available to anyone wishing to use,
5 * modify, copy, or redistribute it subject to the terms and conditions 5 * modify, copy, or redistribute it subject to the terms and conditions
6 * of the GNU General Public License version 2. 6 * of the GNU General Public License version 2.
7 */ 7 */
8 8
9#include <linux/fs.h>
9#include <linux/miscdevice.h> 10#include <linux/miscdevice.h>
10#include <linux/lock_dlm_plock.h>
11#include <linux/poll.h> 11#include <linux/poll.h>
12#include <linux/dlm.h>
13#include <linux/dlm_plock.h>
12 14
13#include "lock_dlm.h" 15#include "dlm_internal.h"
14 16#include "lockspace.h"
15 17
16static spinlock_t ops_lock; 18static spinlock_t ops_lock;
17static struct list_head send_list; 19static struct list_head send_list;
@@ -22,7 +24,7 @@ static wait_queue_head_t recv_wq;
22struct plock_op { 24struct plock_op {
23 struct list_head list; 25 struct list_head list;
24 int done; 26 int done;
25 struct gdlm_plock_info info; 27 struct dlm_plock_info info;
26}; 28};
27 29
28struct plock_xop { 30struct plock_xop {
@@ -34,22 +36,22 @@ struct plock_xop {
34}; 36};
35 37
36 38
37static inline void set_version(struct gdlm_plock_info *info) 39static inline void set_version(struct dlm_plock_info *info)
38{ 40{
39 info->version[0] = GDLM_PLOCK_VERSION_MAJOR; 41 info->version[0] = DLM_PLOCK_VERSION_MAJOR;
40 info->version[1] = GDLM_PLOCK_VERSION_MINOR; 42 info->version[1] = DLM_PLOCK_VERSION_MINOR;
41 info->version[2] = GDLM_PLOCK_VERSION_PATCH; 43 info->version[2] = DLM_PLOCK_VERSION_PATCH;
42} 44}
43 45
44static int check_version(struct gdlm_plock_info *info) 46static int check_version(struct dlm_plock_info *info)
45{ 47{
46 if ((GDLM_PLOCK_VERSION_MAJOR != info->version[0]) || 48 if ((DLM_PLOCK_VERSION_MAJOR != info->version[0]) ||
47 (GDLM_PLOCK_VERSION_MINOR < info->version[1])) { 49 (DLM_PLOCK_VERSION_MINOR < info->version[1])) {
48 log_error("plock device version mismatch: " 50 log_print("plock device version mismatch: "
49 "kernel (%u.%u.%u), user (%u.%u.%u)", 51 "kernel (%u.%u.%u), user (%u.%u.%u)",
50 GDLM_PLOCK_VERSION_MAJOR, 52 DLM_PLOCK_VERSION_MAJOR,
51 GDLM_PLOCK_VERSION_MINOR, 53 DLM_PLOCK_VERSION_MINOR,
52 GDLM_PLOCK_VERSION_PATCH, 54 DLM_PLOCK_VERSION_PATCH,
53 info->version[0], 55 info->version[0],
54 info->version[1], 56 info->version[1],
55 info->version[2]); 57 info->version[2]);
@@ -68,25 +70,31 @@ static void send_op(struct plock_op *op)
68 wake_up(&send_wq); 70 wake_up(&send_wq);
69} 71}
70 72
71int gdlm_plock(void *lockspace, struct lm_lockname *name, 73int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file,
72 struct file *file, int cmd, struct file_lock *fl) 74 int cmd, struct file_lock *fl)
73{ 75{
74 struct gdlm_ls *ls = lockspace; 76 struct dlm_ls *ls;
75 struct plock_op *op; 77 struct plock_op *op;
76 struct plock_xop *xop; 78 struct plock_xop *xop;
77 int rv; 79 int rv;
78 80
81 ls = dlm_find_lockspace_local(lockspace);
82 if (!ls)
83 return -EINVAL;
84
79 xop = kzalloc(sizeof(*xop), GFP_KERNEL); 85 xop = kzalloc(sizeof(*xop), GFP_KERNEL);
80 if (!xop) 86 if (!xop) {
81 return -ENOMEM; 87 rv = -ENOMEM;
88 goto out;
89 }
82 90
83 op = &xop->xop; 91 op = &xop->xop;
84 op->info.optype = GDLM_PLOCK_OP_LOCK; 92 op->info.optype = DLM_PLOCK_OP_LOCK;
85 op->info.pid = fl->fl_pid; 93 op->info.pid = fl->fl_pid;
86 op->info.ex = (fl->fl_type == F_WRLCK); 94 op->info.ex = (fl->fl_type == F_WRLCK);
87 op->info.wait = IS_SETLKW(cmd); 95 op->info.wait = IS_SETLKW(cmd);
88 op->info.fsid = ls->id; 96 op->info.fsid = ls->ls_global_id;
89 op->info.number = name->ln_number; 97 op->info.number = number;
90 op->info.start = fl->fl_start; 98 op->info.start = fl->fl_start;
91 op->info.end = fl->fl_end; 99 op->info.end = fl->fl_end;
92 if (fl->fl_lmops && fl->fl_lmops->fl_grant) { 100 if (fl->fl_lmops && fl->fl_lmops->fl_grant) {
@@ -107,12 +115,15 @@ int gdlm_plock(void *lockspace, struct lm_lockname *name,
107 115
108 if (xop->callback == NULL) 116 if (xop->callback == NULL)
109 wait_event(recv_wq, (op->done != 0)); 117 wait_event(recv_wq, (op->done != 0));
110 else 118 else {
111 return -EINPROGRESS; 119 rv = -EINPROGRESS;
120 goto out;
121 }
112 122
113 spin_lock(&ops_lock); 123 spin_lock(&ops_lock);
114 if (!list_empty(&op->list)) { 124 if (!list_empty(&op->list)) {
115 printk(KERN_INFO "plock op on list\n"); 125 log_error(ls, "dlm_posix_lock: op on list %llx",
126 (unsigned long long)number);
116 list_del(&op->list); 127 list_del(&op->list);
117 } 128 }
118 spin_unlock(&ops_lock); 129 spin_unlock(&ops_lock);
@@ -121,17 +132,19 @@ int gdlm_plock(void *lockspace, struct lm_lockname *name,
121 132
122 if (!rv) { 133 if (!rv) {
123 if (posix_lock_file_wait(file, fl) < 0) 134 if (posix_lock_file_wait(file, fl) < 0)
124 log_error("gdlm_plock: vfs lock error %x,%llx", 135 log_error(ls, "dlm_posix_lock: vfs lock error %llx",
125 name->ln_type, 136 (unsigned long long)number);
126 (unsigned long long)name->ln_number);
127 } 137 }
128 138
129 kfree(xop); 139 kfree(xop);
140out:
141 dlm_put_lockspace(ls);
130 return rv; 142 return rv;
131} 143}
144EXPORT_SYMBOL_GPL(dlm_posix_lock);
132 145
133/* Returns failure iff a succesful lock operation should be canceled */ 146/* Returns failure iff a succesful lock operation should be canceled */
134static int gdlm_plock_callback(struct plock_op *op) 147static int dlm_plock_callback(struct plock_op *op)
135{ 148{
136 struct file *file; 149 struct file *file;
137 struct file_lock *fl; 150 struct file_lock *fl;
@@ -142,7 +155,8 @@ static int gdlm_plock_callback(struct plock_op *op)
142 155
143 spin_lock(&ops_lock); 156 spin_lock(&ops_lock);
144 if (!list_empty(&op->list)) { 157 if (!list_empty(&op->list)) {
145 printk(KERN_INFO "plock op on list\n"); 158 log_print("dlm_plock_callback: op on list %llx",
159 (unsigned long long)op->info.number);
146 list_del(&op->list); 160 list_del(&op->list);
147 } 161 }
148 spin_unlock(&ops_lock); 162 spin_unlock(&ops_lock);
@@ -165,19 +179,19 @@ static int gdlm_plock_callback(struct plock_op *op)
165 * This can only happen in the case of kmalloc() failure. 179 * This can only happen in the case of kmalloc() failure.
166 * The filesystem's own lock is the authoritative lock, 180 * The filesystem's own lock is the authoritative lock,
167 * so a failure to get the lock locally is not a disaster. 181 * so a failure to get the lock locally is not a disaster.
168 * As long as GFS cannot reliably cancel locks (especially 182 * As long as the fs cannot reliably cancel locks (especially
169 * in a low-memory situation), we're better off ignoring 183 * in a low-memory situation), we're better off ignoring
170 * this failure than trying to recover. 184 * this failure than trying to recover.
171 */ 185 */
172 log_error("gdlm_plock: vfs lock error file %p fl %p", 186 log_print("dlm_plock_callback: vfs lock error %llx file %p fl %p",
173 file, fl); 187 (unsigned long long)op->info.number, file, fl);
174 } 188 }
175 189
176 rv = notify(flc, NULL, 0); 190 rv = notify(flc, NULL, 0);
177 if (rv) { 191 if (rv) {
178 /* XXX: We need to cancel the fs lock here: */ 192 /* XXX: We need to cancel the fs lock here: */
179 printk("gfs2 lock granted after lock request failed;" 193 log_print("dlm_plock_callback: lock granted after lock request "
180 " dangling lock!\n"); 194 "failed; dangling lock!\n");
181 goto out; 195 goto out;
182 } 196 }
183 197
@@ -186,25 +200,31 @@ out:
186 return rv; 200 return rv;
187} 201}
188 202
189int gdlm_punlock(void *lockspace, struct lm_lockname *name, 203int dlm_posix_unlock(dlm_lockspace_t *lockspace, u64 number, struct file *file,
190 struct file *file, struct file_lock *fl) 204 struct file_lock *fl)
191{ 205{
192 struct gdlm_ls *ls = lockspace; 206 struct dlm_ls *ls;
193 struct plock_op *op; 207 struct plock_op *op;
194 int rv; 208 int rv;
195 209
210 ls = dlm_find_lockspace_local(lockspace);
211 if (!ls)
212 return -EINVAL;
213
196 op = kzalloc(sizeof(*op), GFP_KERNEL); 214 op = kzalloc(sizeof(*op), GFP_KERNEL);
197 if (!op) 215 if (!op) {
198 return -ENOMEM; 216 rv = -ENOMEM;
217 goto out;
218 }
199 219
200 if (posix_lock_file_wait(file, fl) < 0) 220 if (posix_lock_file_wait(file, fl) < 0)
201 log_error("gdlm_punlock: vfs unlock error %x,%llx", 221 log_error(ls, "dlm_posix_unlock: vfs unlock error %llx",
202 name->ln_type, (unsigned long long)name->ln_number); 222 (unsigned long long)number);
203 223
204 op->info.optype = GDLM_PLOCK_OP_UNLOCK; 224 op->info.optype = DLM_PLOCK_OP_UNLOCK;
205 op->info.pid = fl->fl_pid; 225 op->info.pid = fl->fl_pid;
206 op->info.fsid = ls->id; 226 op->info.fsid = ls->ls_global_id;
207 op->info.number = name->ln_number; 227 op->info.number = number;
208 op->info.start = fl->fl_start; 228 op->info.start = fl->fl_start;
209 op->info.end = fl->fl_end; 229 op->info.end = fl->fl_end;
210 if (fl->fl_lmops && fl->fl_lmops->fl_grant) 230 if (fl->fl_lmops && fl->fl_lmops->fl_grant)
@@ -217,7 +237,8 @@ int gdlm_punlock(void *lockspace, struct lm_lockname *name,
217 237
218 spin_lock(&ops_lock); 238 spin_lock(&ops_lock);
219 if (!list_empty(&op->list)) { 239 if (!list_empty(&op->list)) {
220 printk(KERN_INFO "punlock op on list\n"); 240 log_error(ls, "dlm_posix_unlock: op on list %llx",
241 (unsigned long long)number);
221 list_del(&op->list); 242 list_del(&op->list);
222 } 243 }
223 spin_unlock(&ops_lock); 244 spin_unlock(&ops_lock);
@@ -228,25 +249,34 @@ int gdlm_punlock(void *lockspace, struct lm_lockname *name,
228 rv = 0; 249 rv = 0;
229 250
230 kfree(op); 251 kfree(op);
252out:
253 dlm_put_lockspace(ls);
231 return rv; 254 return rv;
232} 255}
256EXPORT_SYMBOL_GPL(dlm_posix_unlock);
233 257
234int gdlm_plock_get(void *lockspace, struct lm_lockname *name, 258int dlm_posix_get(dlm_lockspace_t *lockspace, u64 number, struct file *file,
235 struct file *file, struct file_lock *fl) 259 struct file_lock *fl)
236{ 260{
237 struct gdlm_ls *ls = lockspace; 261 struct dlm_ls *ls;
238 struct plock_op *op; 262 struct plock_op *op;
239 int rv; 263 int rv;
240 264
265 ls = dlm_find_lockspace_local(lockspace);
266 if (!ls)
267 return -EINVAL;
268
241 op = kzalloc(sizeof(*op), GFP_KERNEL); 269 op = kzalloc(sizeof(*op), GFP_KERNEL);
242 if (!op) 270 if (!op) {
243 return -ENOMEM; 271 rv = -ENOMEM;
272 goto out;
273 }
244 274
245 op->info.optype = GDLM_PLOCK_OP_GET; 275 op->info.optype = DLM_PLOCK_OP_GET;
246 op->info.pid = fl->fl_pid; 276 op->info.pid = fl->fl_pid;
247 op->info.ex = (fl->fl_type == F_WRLCK); 277 op->info.ex = (fl->fl_type == F_WRLCK);
248 op->info.fsid = ls->id; 278 op->info.fsid = ls->ls_global_id;
249 op->info.number = name->ln_number; 279 op->info.number = number;
250 op->info.start = fl->fl_start; 280 op->info.start = fl->fl_start;
251 op->info.end = fl->fl_end; 281 op->info.end = fl->fl_end;
252 if (fl->fl_lmops && fl->fl_lmops->fl_grant) 282 if (fl->fl_lmops && fl->fl_lmops->fl_grant)
@@ -259,7 +289,8 @@ int gdlm_plock_get(void *lockspace, struct lm_lockname *name,
259 289
260 spin_lock(&ops_lock); 290 spin_lock(&ops_lock);
261 if (!list_empty(&op->list)) { 291 if (!list_empty(&op->list)) {
262 printk(KERN_INFO "plock_get op on list\n"); 292 log_error(ls, "dlm_posix_get: op on list %llx",
293 (unsigned long long)number);
263 list_del(&op->list); 294 list_del(&op->list);
264 } 295 }
265 spin_unlock(&ops_lock); 296 spin_unlock(&ops_lock);
@@ -281,14 +312,17 @@ int gdlm_plock_get(void *lockspace, struct lm_lockname *name,
281 } 312 }
282 313
283 kfree(op); 314 kfree(op);
315out:
316 dlm_put_lockspace(ls);
284 return rv; 317 return rv;
285} 318}
319EXPORT_SYMBOL_GPL(dlm_posix_get);
286 320
287/* a read copies out one plock request from the send list */ 321/* a read copies out one plock request from the send list */
288static ssize_t dev_read(struct file *file, char __user *u, size_t count, 322static ssize_t dev_read(struct file *file, char __user *u, size_t count,
289 loff_t *ppos) 323 loff_t *ppos)
290{ 324{
291 struct gdlm_plock_info info; 325 struct dlm_plock_info info;
292 struct plock_op *op = NULL; 326 struct plock_op *op = NULL;
293 327
294 if (count < sizeof(info)) 328 if (count < sizeof(info))
@@ -315,7 +349,7 @@ static ssize_t dev_read(struct file *file, char __user *u, size_t count,
315static ssize_t dev_write(struct file *file, const char __user *u, size_t count, 349static ssize_t dev_write(struct file *file, const char __user *u, size_t count,
316 loff_t *ppos) 350 loff_t *ppos)
317{ 351{
318 struct gdlm_plock_info info; 352 struct dlm_plock_info info;
319 struct plock_op *op; 353 struct plock_op *op;
320 int found = 0; 354 int found = 0;
321 355
@@ -345,12 +379,12 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count,
345 struct plock_xop *xop; 379 struct plock_xop *xop;
346 xop = (struct plock_xop *)op; 380 xop = (struct plock_xop *)op;
347 if (xop->callback) 381 if (xop->callback)
348 count = gdlm_plock_callback(op); 382 count = dlm_plock_callback(op);
349 else 383 else
350 wake_up(&recv_wq); 384 wake_up(&recv_wq);
351 } else 385 } else
352 printk(KERN_INFO "gdlm dev_write no op %x %llx\n", info.fsid, 386 log_print("dev_write no op %x %llx", info.fsid,
353 (unsigned long long)info.number); 387 (unsigned long long)info.number);
354 return count; 388 return count;
355} 389}
356 390
@@ -377,11 +411,11 @@ static const struct file_operations dev_fops = {
377 411
378static struct miscdevice plock_dev_misc = { 412static struct miscdevice plock_dev_misc = {
379 .minor = MISC_DYNAMIC_MINOR, 413 .minor = MISC_DYNAMIC_MINOR,
380 .name = GDLM_PLOCK_MISC_NAME, 414 .name = DLM_PLOCK_MISC_NAME,
381 .fops = &dev_fops 415 .fops = &dev_fops
382}; 416};
383 417
384int gdlm_plock_init(void) 418int dlm_plock_init(void)
385{ 419{
386 int rv; 420 int rv;
387 421
@@ -393,14 +427,13 @@ int gdlm_plock_init(void)
393 427
394 rv = misc_register(&plock_dev_misc); 428 rv = misc_register(&plock_dev_misc);
395 if (rv) 429 if (rv)
396 printk(KERN_INFO "gdlm_plock_init: misc_register failed %d", 430 log_print("dlm_plock_init: misc_register failed %d", rv);
397 rv);
398 return rv; 431 return rv;
399} 432}
400 433
401void gdlm_plock_exit(void) 434void dlm_plock_exit(void)
402{ 435{
403 if (misc_deregister(&plock_dev_misc) < 0) 436 if (misc_deregister(&plock_dev_misc) < 0)
404 printk(KERN_INFO "gdlm_plock_exit: misc_deregister failed"); 437 log_print("dlm_plock_exit: misc_deregister failed");
405} 438}
406 439
diff --git a/fs/dlm/recoverd.c b/fs/dlm/recoverd.c
index 997f9531d594..fd677c8c3d3b 100644
--- a/fs/dlm/recoverd.c
+++ b/fs/dlm/recoverd.c
@@ -257,6 +257,7 @@ static void do_ls_recovery(struct dlm_ls *ls)
257 if (rv) { 257 if (rv) {
258 ls_recover(ls, rv); 258 ls_recover(ls, rv);
259 kfree(rv->nodeids); 259 kfree(rv->nodeids);
260 kfree(rv->new);
260 kfree(rv); 261 kfree(rv);
261 } 262 }
262} 263}
diff --git a/fs/gfs2/locking/dlm/Makefile b/fs/gfs2/locking/dlm/Makefile
index 89b93b6b45cf..2609bb6cd013 100644
--- a/fs/gfs2/locking/dlm/Makefile
+++ b/fs/gfs2/locking/dlm/Makefile
@@ -1,3 +1,3 @@
1obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o 1obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o
2lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o plock.o 2lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o
3 3
diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h
index 58fcf8c5bf39..a243cf69c54e 100644
--- a/fs/gfs2/locking/dlm/lock_dlm.h
+++ b/fs/gfs2/locking/dlm/lock_dlm.h
@@ -25,6 +25,7 @@
25#include <net/sock.h> 25#include <net/sock.h>
26 26
27#include <linux/dlm.h> 27#include <linux/dlm.h>
28#include <linux/dlm_plock.h>
28#include <linux/lm_interface.h> 29#include <linux/lm_interface.h>
29 30
30/* 31/*
@@ -173,17 +174,6 @@ void gdlm_cancel(void *);
173int gdlm_hold_lvb(void *, char **); 174int gdlm_hold_lvb(void *, char **);
174void gdlm_unhold_lvb(void *, char *); 175void gdlm_unhold_lvb(void *, char *);
175 176
176/* plock.c */
177
178int gdlm_plock_init(void);
179void gdlm_plock_exit(void);
180int gdlm_plock(void *, struct lm_lockname *, struct file *, int,
181 struct file_lock *);
182int gdlm_plock_get(void *, struct lm_lockname *, struct file *,
183 struct file_lock *);
184int gdlm_punlock(void *, struct lm_lockname *, struct file *,
185 struct file_lock *);
186
187/* mount.c */ 177/* mount.c */
188 178
189extern const struct lm_lockops gdlm_ops; 179extern const struct lm_lockops gdlm_ops;
diff --git a/fs/gfs2/locking/dlm/main.c b/fs/gfs2/locking/dlm/main.c
index 36a225850bd8..b9a03a7ff801 100644
--- a/fs/gfs2/locking/dlm/main.c
+++ b/fs/gfs2/locking/dlm/main.c
@@ -28,13 +28,6 @@ static int __init init_lock_dlm(void)
28 return error; 28 return error;
29 } 29 }
30 30
31 error = gdlm_plock_init();
32 if (error) {
33 gdlm_sysfs_exit();
34 gfs2_unregister_lockproto(&gdlm_ops);
35 return error;
36 }
37
38 printk(KERN_INFO 31 printk(KERN_INFO
39 "Lock_DLM (built %s %s) installed\n", __DATE__, __TIME__); 32 "Lock_DLM (built %s %s) installed\n", __DATE__, __TIME__);
40 return 0; 33 return 0;
@@ -42,7 +35,6 @@ static int __init init_lock_dlm(void)
42 35
43static void __exit exit_lock_dlm(void) 36static void __exit exit_lock_dlm(void)
44{ 37{
45 gdlm_plock_exit();
46 gdlm_sysfs_exit(); 38 gdlm_sysfs_exit();
47 gfs2_unregister_lockproto(&gdlm_ops); 39 gfs2_unregister_lockproto(&gdlm_ops);
48} 40}
diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c
index f2efff424224..470bdf650b50 100644
--- a/fs/gfs2/locking/dlm/mount.c
+++ b/fs/gfs2/locking/dlm/mount.c
@@ -236,6 +236,27 @@ static void gdlm_withdraw(void *lockspace)
236 gdlm_kobject_release(ls); 236 gdlm_kobject_release(ls);
237} 237}
238 238
239static int gdlm_plock(void *lockspace, struct lm_lockname *name,
240 struct file *file, int cmd, struct file_lock *fl)
241{
242 struct gdlm_ls *ls = lockspace;
243 return dlm_posix_lock(ls->dlm_lockspace, name->ln_number, file, cmd, fl);
244}
245
246static int gdlm_punlock(void *lockspace, struct lm_lockname *name,
247 struct file *file, struct file_lock *fl)
248{
249 struct gdlm_ls *ls = lockspace;
250 return dlm_posix_unlock(ls->dlm_lockspace, name->ln_number, file, fl);
251}
252
253static int gdlm_plock_get(void *lockspace, struct lm_lockname *name,
254 struct file *file, struct file_lock *fl)
255{
256 struct gdlm_ls *ls = lockspace;
257 return dlm_posix_get(ls->dlm_lockspace, name->ln_number, file, fl);
258}
259
239const struct lm_lockops gdlm_ops = { 260const struct lm_lockops gdlm_ops = {
240 .lm_proto_name = "lock_dlm", 261 .lm_proto_name = "lock_dlm",
241 .lm_mount = gdlm_mount, 262 .lm_mount = gdlm_mount,
diff --git a/fs/internal.h b/fs/internal.h
index 392e8ccd6fc4..80aa9a023372 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -43,3 +43,14 @@ extern void __init chrdev_init(void);
43 * namespace.c 43 * namespace.c
44 */ 44 */
45extern int copy_mount_options(const void __user *, unsigned long *); 45extern int copy_mount_options(const void __user *, unsigned long *);
46
47extern void free_vfsmnt(struct vfsmount *);
48extern struct vfsmount *alloc_vfsmnt(const char *);
49extern struct vfsmount *__lookup_mnt(struct vfsmount *, struct dentry *, int);
50extern void mnt_set_mountpoint(struct vfsmount *, struct dentry *,
51 struct vfsmount *);
52extern void release_mounts(struct list_head *);
53extern void umount_tree(struct vfsmount *, int, struct list_head *);
54extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int);
55
56extern void __init mnt_init(void);
diff --git a/fs/namespace.c b/fs/namespace.c
index 678f7ce060f2..0505fb61aa74 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -27,6 +27,7 @@
27#include <linux/mount.h> 27#include <linux/mount.h>
28#include <linux/ramfs.h> 28#include <linux/ramfs.h>
29#include <linux/log2.h> 29#include <linux/log2.h>
30#include <linux/idr.h>
30#include <asm/uaccess.h> 31#include <asm/uaccess.h>
31#include <asm/unistd.h> 32#include <asm/unistd.h>
32#include "pnode.h" 33#include "pnode.h"
@@ -39,6 +40,8 @@
39__cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock); 40__cacheline_aligned_in_smp DEFINE_SPINLOCK(vfsmount_lock);
40 41
41static int event; 42static int event;
43static DEFINE_IDA(mnt_id_ida);
44static DEFINE_IDA(mnt_group_ida);
42 45
43static struct list_head *mount_hashtable __read_mostly; 46static struct list_head *mount_hashtable __read_mostly;
44static struct kmem_cache *mnt_cache __read_mostly; 47static struct kmem_cache *mnt_cache __read_mostly;
@@ -58,10 +61,63 @@ static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
58 61
59#define MNT_WRITER_UNDERFLOW_LIMIT -(1<<16) 62#define MNT_WRITER_UNDERFLOW_LIMIT -(1<<16)
60 63
64/* allocation is serialized by namespace_sem */
65static int mnt_alloc_id(struct vfsmount *mnt)
66{
67 int res;
68
69retry:
70 ida_pre_get(&mnt_id_ida, GFP_KERNEL);
71 spin_lock(&vfsmount_lock);
72 res = ida_get_new(&mnt_id_ida, &mnt->mnt_id);
73 spin_unlock(&vfsmount_lock);
74 if (res == -EAGAIN)
75 goto retry;
76
77 return res;
78}
79
80static void mnt_free_id(struct vfsmount *mnt)
81{
82 spin_lock(&vfsmount_lock);
83 ida_remove(&mnt_id_ida, mnt->mnt_id);
84 spin_unlock(&vfsmount_lock);
85}
86
87/*
88 * Allocate a new peer group ID
89 *
90 * mnt_group_ida is protected by namespace_sem
91 */
92static int mnt_alloc_group_id(struct vfsmount *mnt)
93{
94 if (!ida_pre_get(&mnt_group_ida, GFP_KERNEL))
95 return -ENOMEM;
96
97 return ida_get_new_above(&mnt_group_ida, 1, &mnt->mnt_group_id);
98}
99
100/*
101 * Release a peer group ID
102 */
103void mnt_release_group_id(struct vfsmount *mnt)
104{
105 ida_remove(&mnt_group_ida, mnt->mnt_group_id);
106 mnt->mnt_group_id = 0;
107}
108
61struct vfsmount *alloc_vfsmnt(const char *name) 109struct vfsmount *alloc_vfsmnt(const char *name)
62{ 110{
63 struct vfsmount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL); 111 struct vfsmount *mnt = kmem_cache_zalloc(mnt_cache, GFP_KERNEL);
64 if (mnt) { 112 if (mnt) {
113 int err;
114
115 err = mnt_alloc_id(mnt);
116 if (err) {
117 kmem_cache_free(mnt_cache, mnt);
118 return NULL;
119 }
120
65 atomic_set(&mnt->mnt_count, 1); 121 atomic_set(&mnt->mnt_count, 1);
66 INIT_LIST_HEAD(&mnt->mnt_hash); 122 INIT_LIST_HEAD(&mnt->mnt_hash);
67 INIT_LIST_HEAD(&mnt->mnt_child); 123 INIT_LIST_HEAD(&mnt->mnt_child);
@@ -353,6 +409,7 @@ EXPORT_SYMBOL(simple_set_mnt);
353void free_vfsmnt(struct vfsmount *mnt) 409void free_vfsmnt(struct vfsmount *mnt)
354{ 410{
355 kfree(mnt->mnt_devname); 411 kfree(mnt->mnt_devname);
412 mnt_free_id(mnt);
356 kmem_cache_free(mnt_cache, mnt); 413 kmem_cache_free(mnt_cache, mnt);
357} 414}
358 415
@@ -499,6 +556,17 @@ static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
499 struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname); 556 struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname);
500 557
501 if (mnt) { 558 if (mnt) {
559 if (flag & (CL_SLAVE | CL_PRIVATE))
560 mnt->mnt_group_id = 0; /* not a peer of original */
561 else
562 mnt->mnt_group_id = old->mnt_group_id;
563
564 if ((flag & CL_MAKE_SHARED) && !mnt->mnt_group_id) {
565 int err = mnt_alloc_group_id(mnt);
566 if (err)
567 goto out_free;
568 }
569
502 mnt->mnt_flags = old->mnt_flags; 570 mnt->mnt_flags = old->mnt_flags;
503 atomic_inc(&sb->s_active); 571 atomic_inc(&sb->s_active);
504 mnt->mnt_sb = sb; 572 mnt->mnt_sb = sb;
@@ -528,6 +596,10 @@ static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
528 } 596 }
529 } 597 }
530 return mnt; 598 return mnt;
599
600 out_free:
601 free_vfsmnt(mnt);
602 return NULL;
531} 603}
532 604
533static inline void __mntput(struct vfsmount *mnt) 605static inline void __mntput(struct vfsmount *mnt)
@@ -652,20 +724,21 @@ void save_mount_options(struct super_block *sb, char *options)
652} 724}
653EXPORT_SYMBOL(save_mount_options); 725EXPORT_SYMBOL(save_mount_options);
654 726
727#ifdef CONFIG_PROC_FS
655/* iterator */ 728/* iterator */
656static void *m_start(struct seq_file *m, loff_t *pos) 729static void *m_start(struct seq_file *m, loff_t *pos)
657{ 730{
658 struct mnt_namespace *n = m->private; 731 struct proc_mounts *p = m->private;
659 732
660 down_read(&namespace_sem); 733 down_read(&namespace_sem);
661 return seq_list_start(&n->list, *pos); 734 return seq_list_start(&p->ns->list, *pos);
662} 735}
663 736
664static void *m_next(struct seq_file *m, void *v, loff_t *pos) 737static void *m_next(struct seq_file *m, void *v, loff_t *pos)
665{ 738{
666 struct mnt_namespace *n = m->private; 739 struct proc_mounts *p = m->private;
667 740
668 return seq_list_next(v, &n->list, pos); 741 return seq_list_next(v, &p->ns->list, pos);
669} 742}
670 743
671static void m_stop(struct seq_file *m, void *v) 744static void m_stop(struct seq_file *m, void *v)
@@ -673,20 +746,30 @@ static void m_stop(struct seq_file *m, void *v)
673 up_read(&namespace_sem); 746 up_read(&namespace_sem);
674} 747}
675 748
676static int show_vfsmnt(struct seq_file *m, void *v) 749struct proc_fs_info {
750 int flag;
751 const char *str;
752};
753
754static void show_sb_opts(struct seq_file *m, struct super_block *sb)
677{ 755{
678 struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list); 756 static const struct proc_fs_info fs_info[] = {
679 int err = 0;
680 static struct proc_fs_info {
681 int flag;
682 char *str;
683 } fs_info[] = {
684 { MS_SYNCHRONOUS, ",sync" }, 757 { MS_SYNCHRONOUS, ",sync" },
685 { MS_DIRSYNC, ",dirsync" }, 758 { MS_DIRSYNC, ",dirsync" },
686 { MS_MANDLOCK, ",mand" }, 759 { MS_MANDLOCK, ",mand" },
687 { 0, NULL } 760 { 0, NULL }
688 }; 761 };
689 static struct proc_fs_info mnt_info[] = { 762 const struct proc_fs_info *fs_infop;
763
764 for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
765 if (sb->s_flags & fs_infop->flag)
766 seq_puts(m, fs_infop->str);
767 }
768}
769
770static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt)
771{
772 static const struct proc_fs_info mnt_info[] = {
690 { MNT_NOSUID, ",nosuid" }, 773 { MNT_NOSUID, ",nosuid" },
691 { MNT_NODEV, ",nodev" }, 774 { MNT_NODEV, ",nodev" },
692 { MNT_NOEXEC, ",noexec" }, 775 { MNT_NOEXEC, ",noexec" },
@@ -695,40 +778,108 @@ static int show_vfsmnt(struct seq_file *m, void *v)
695 { MNT_RELATIME, ",relatime" }, 778 { MNT_RELATIME, ",relatime" },
696 { 0, NULL } 779 { 0, NULL }
697 }; 780 };
698 struct proc_fs_info *fs_infop; 781 const struct proc_fs_info *fs_infop;
782
783 for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
784 if (mnt->mnt_flags & fs_infop->flag)
785 seq_puts(m, fs_infop->str);
786 }
787}
788
789static void show_type(struct seq_file *m, struct super_block *sb)
790{
791 mangle(m, sb->s_type->name);
792 if (sb->s_subtype && sb->s_subtype[0]) {
793 seq_putc(m, '.');
794 mangle(m, sb->s_subtype);
795 }
796}
797
798static int show_vfsmnt(struct seq_file *m, void *v)
799{
800 struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
801 int err = 0;
699 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; 802 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
700 803
701 mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none"); 804 mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
702 seq_putc(m, ' '); 805 seq_putc(m, ' ');
703 seq_path(m, &mnt_path, " \t\n\\"); 806 seq_path(m, &mnt_path, " \t\n\\");
704 seq_putc(m, ' '); 807 seq_putc(m, ' ');
705 mangle(m, mnt->mnt_sb->s_type->name); 808 show_type(m, mnt->mnt_sb);
706 if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
707 seq_putc(m, '.');
708 mangle(m, mnt->mnt_sb->s_subtype);
709 }
710 seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw"); 809 seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
711 for (fs_infop = fs_info; fs_infop->flag; fs_infop++) { 810 show_sb_opts(m, mnt->mnt_sb);
712 if (mnt->mnt_sb->s_flags & fs_infop->flag) 811 show_mnt_opts(m, mnt);
713 seq_puts(m, fs_infop->str);
714 }
715 for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
716 if (mnt->mnt_flags & fs_infop->flag)
717 seq_puts(m, fs_infop->str);
718 }
719 if (mnt->mnt_sb->s_op->show_options) 812 if (mnt->mnt_sb->s_op->show_options)
720 err = mnt->mnt_sb->s_op->show_options(m, mnt); 813 err = mnt->mnt_sb->s_op->show_options(m, mnt);
721 seq_puts(m, " 0 0\n"); 814 seq_puts(m, " 0 0\n");
722 return err; 815 return err;
723} 816}
724 817
725struct seq_operations mounts_op = { 818const struct seq_operations mounts_op = {
726 .start = m_start, 819 .start = m_start,
727 .next = m_next, 820 .next = m_next,
728 .stop = m_stop, 821 .stop = m_stop,
729 .show = show_vfsmnt 822 .show = show_vfsmnt
730}; 823};
731 824
825static int show_mountinfo(struct seq_file *m, void *v)
826{
827 struct proc_mounts *p = m->private;
828 struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
829 struct super_block *sb = mnt->mnt_sb;
830 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
831 struct path root = p->root;
832 int err = 0;
833
834 seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
835 MAJOR(sb->s_dev), MINOR(sb->s_dev));
836 seq_dentry(m, mnt->mnt_root, " \t\n\\");
837 seq_putc(m, ' ');
838 seq_path_root(m, &mnt_path, &root, " \t\n\\");
839 if (root.mnt != p->root.mnt || root.dentry != p->root.dentry) {
840 /*
841 * Mountpoint is outside root, discard that one. Ugly,
842 * but less so than trying to do that in iterator in a
843 * race-free way (due to renames).
844 */
845 return SEQ_SKIP;
846 }
847 seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw");
848 show_mnt_opts(m, mnt);
849
850 /* Tagged fields ("foo:X" or "bar") */
851 if (IS_MNT_SHARED(mnt))
852 seq_printf(m, " shared:%i", mnt->mnt_group_id);
853 if (IS_MNT_SLAVE(mnt)) {
854 int master = mnt->mnt_master->mnt_group_id;
855 int dom = get_dominating_id(mnt, &p->root);
856 seq_printf(m, " master:%i", master);
857 if (dom && dom != master)
858 seq_printf(m, " propagate_from:%i", dom);
859 }
860 if (IS_MNT_UNBINDABLE(mnt))
861 seq_puts(m, " unbindable");
862
863 /* Filesystem specific data */
864 seq_puts(m, " - ");
865 show_type(m, sb);
866 seq_putc(m, ' ');
867 mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
868 seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw");
869 show_sb_opts(m, sb);
870 if (sb->s_op->show_options)
871 err = sb->s_op->show_options(m, mnt);
872 seq_putc(m, '\n');
873 return err;
874}
875
876const struct seq_operations mountinfo_op = {
877 .start = m_start,
878 .next = m_next,
879 .stop = m_stop,
880 .show = show_mountinfo,
881};
882
732static int show_vfsstat(struct seq_file *m, void *v) 883static int show_vfsstat(struct seq_file *m, void *v)
733{ 884{
734 struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list); 885 struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
@@ -749,7 +900,7 @@ static int show_vfsstat(struct seq_file *m, void *v)
749 900
750 /* file system type */ 901 /* file system type */
751 seq_puts(m, "with fstype "); 902 seq_puts(m, "with fstype ");
752 mangle(m, mnt->mnt_sb->s_type->name); 903 show_type(m, mnt->mnt_sb);
753 904
754 /* optional statistics */ 905 /* optional statistics */
755 if (mnt->mnt_sb->s_op->show_stats) { 906 if (mnt->mnt_sb->s_op->show_stats) {
@@ -761,12 +912,13 @@ static int show_vfsstat(struct seq_file *m, void *v)
761 return err; 912 return err;
762} 913}
763 914
764struct seq_operations mountstats_op = { 915const struct seq_operations mountstats_op = {
765 .start = m_start, 916 .start = m_start,
766 .next = m_next, 917 .next = m_next,
767 .stop = m_stop, 918 .stop = m_stop,
768 .show = show_vfsstat, 919 .show = show_vfsstat,
769}; 920};
921#endif /* CONFIG_PROC_FS */
770 922
771/** 923/**
772 * may_umount_tree - check if a mount tree is busy 924 * may_umount_tree - check if a mount tree is busy
@@ -1091,23 +1243,50 @@ Enomem:
1091struct vfsmount *collect_mounts(struct vfsmount *mnt, struct dentry *dentry) 1243struct vfsmount *collect_mounts(struct vfsmount *mnt, struct dentry *dentry)
1092{ 1244{
1093 struct vfsmount *tree; 1245 struct vfsmount *tree;
1094 down_read(&namespace_sem); 1246 down_write(&namespace_sem);
1095 tree = copy_tree(mnt, dentry, CL_COPY_ALL | CL_PRIVATE); 1247 tree = copy_tree(mnt, dentry, CL_COPY_ALL | CL_PRIVATE);
1096 up_read(&namespace_sem); 1248 up_write(&namespace_sem);
1097 return tree; 1249 return tree;
1098} 1250}
1099 1251
1100void drop_collected_mounts(struct vfsmount *mnt) 1252void drop_collected_mounts(struct vfsmount *mnt)
1101{ 1253{
1102 LIST_HEAD(umount_list); 1254 LIST_HEAD(umount_list);
1103 down_read(&namespace_sem); 1255 down_write(&namespace_sem);
1104 spin_lock(&vfsmount_lock); 1256 spin_lock(&vfsmount_lock);
1105 umount_tree(mnt, 0, &umount_list); 1257 umount_tree(mnt, 0, &umount_list);
1106 spin_unlock(&vfsmount_lock); 1258 spin_unlock(&vfsmount_lock);
1107 up_read(&namespace_sem); 1259 up_write(&namespace_sem);
1108 release_mounts(&umount_list); 1260 release_mounts(&umount_list);
1109} 1261}
1110 1262
1263static void cleanup_group_ids(struct vfsmount *mnt, struct vfsmount *end)
1264{
1265 struct vfsmount *p;
1266
1267 for (p = mnt; p != end; p = next_mnt(p, mnt)) {
1268 if (p->mnt_group_id && !IS_MNT_SHARED(p))
1269 mnt_release_group_id(p);
1270 }
1271}
1272
1273static int invent_group_ids(struct vfsmount *mnt, bool recurse)
1274{
1275 struct vfsmount *p;
1276
1277 for (p = mnt; p; p = recurse ? next_mnt(p, mnt) : NULL) {
1278 if (!p->mnt_group_id && !IS_MNT_SHARED(p)) {
1279 int err = mnt_alloc_group_id(p);
1280 if (err) {
1281 cleanup_group_ids(mnt, p);
1282 return err;
1283 }
1284 }
1285 }
1286
1287 return 0;
1288}
1289
1111/* 1290/*
1112 * @source_mnt : mount tree to be attached 1291 * @source_mnt : mount tree to be attached
1113 * @nd : place the mount tree @source_mnt is attached 1292 * @nd : place the mount tree @source_mnt is attached
@@ -1178,9 +1357,16 @@ static int attach_recursive_mnt(struct vfsmount *source_mnt,
1178 struct vfsmount *dest_mnt = path->mnt; 1357 struct vfsmount *dest_mnt = path->mnt;
1179 struct dentry *dest_dentry = path->dentry; 1358 struct dentry *dest_dentry = path->dentry;
1180 struct vfsmount *child, *p; 1359 struct vfsmount *child, *p;
1360 int err;
1181 1361
1182 if (propagate_mnt(dest_mnt, dest_dentry, source_mnt, &tree_list)) 1362 if (IS_MNT_SHARED(dest_mnt)) {
1183 return -EINVAL; 1363 err = invent_group_ids(source_mnt, true);
1364 if (err)
1365 goto out;
1366 }
1367 err = propagate_mnt(dest_mnt, dest_dentry, source_mnt, &tree_list);
1368 if (err)
1369 goto out_cleanup_ids;
1184 1370
1185 if (IS_MNT_SHARED(dest_mnt)) { 1371 if (IS_MNT_SHARED(dest_mnt)) {
1186 for (p = source_mnt; p; p = next_mnt(p, source_mnt)) 1372 for (p = source_mnt; p; p = next_mnt(p, source_mnt))
@@ -1203,34 +1389,40 @@ static int attach_recursive_mnt(struct vfsmount *source_mnt,
1203 } 1389 }
1204 spin_unlock(&vfsmount_lock); 1390 spin_unlock(&vfsmount_lock);
1205 return 0; 1391 return 0;
1392
1393 out_cleanup_ids:
1394 if (IS_MNT_SHARED(dest_mnt))
1395 cleanup_group_ids(source_mnt, NULL);
1396 out:
1397 return err;
1206} 1398}
1207 1399
1208static int graft_tree(struct vfsmount *mnt, struct nameidata *nd) 1400static int graft_tree(struct vfsmount *mnt, struct path *path)
1209{ 1401{
1210 int err; 1402 int err;
1211 if (mnt->mnt_sb->s_flags & MS_NOUSER) 1403 if (mnt->mnt_sb->s_flags & MS_NOUSER)
1212 return -EINVAL; 1404 return -EINVAL;
1213 1405
1214 if (S_ISDIR(nd->path.dentry->d_inode->i_mode) != 1406 if (S_ISDIR(path->dentry->d_inode->i_mode) !=
1215 S_ISDIR(mnt->mnt_root->d_inode->i_mode)) 1407 S_ISDIR(mnt->mnt_root->d_inode->i_mode))
1216 return -ENOTDIR; 1408 return -ENOTDIR;
1217 1409
1218 err = -ENOENT; 1410 err = -ENOENT;
1219 mutex_lock(&nd->path.dentry->d_inode->i_mutex); 1411 mutex_lock(&path->dentry->d_inode->i_mutex);
1220 if (IS_DEADDIR(nd->path.dentry->d_inode)) 1412 if (IS_DEADDIR(path->dentry->d_inode))
1221 goto out_unlock; 1413 goto out_unlock;
1222 1414
1223 err = security_sb_check_sb(mnt, nd); 1415 err = security_sb_check_sb(mnt, path);
1224 if (err) 1416 if (err)
1225 goto out_unlock; 1417 goto out_unlock;
1226 1418
1227 err = -ENOENT; 1419 err = -ENOENT;
1228 if (IS_ROOT(nd->path.dentry) || !d_unhashed(nd->path.dentry)) 1420 if (IS_ROOT(path->dentry) || !d_unhashed(path->dentry))
1229 err = attach_recursive_mnt(mnt, &nd->path, NULL); 1421 err = attach_recursive_mnt(mnt, path, NULL);
1230out_unlock: 1422out_unlock:
1231 mutex_unlock(&nd->path.dentry->d_inode->i_mutex); 1423 mutex_unlock(&path->dentry->d_inode->i_mutex);
1232 if (!err) 1424 if (!err)
1233 security_sb_post_addmount(mnt, nd); 1425 security_sb_post_addmount(mnt, path);
1234 return err; 1426 return err;
1235} 1427}
1236 1428
@@ -1243,6 +1435,7 @@ static noinline int do_change_type(struct nameidata *nd, int flag)
1243 struct vfsmount *m, *mnt = nd->path.mnt; 1435 struct vfsmount *m, *mnt = nd->path.mnt;
1244 int recurse = flag & MS_REC; 1436 int recurse = flag & MS_REC;
1245 int type = flag & ~MS_REC; 1437 int type = flag & ~MS_REC;
1438 int err = 0;
1246 1439
1247 if (!capable(CAP_SYS_ADMIN)) 1440 if (!capable(CAP_SYS_ADMIN))
1248 return -EPERM; 1441 return -EPERM;
@@ -1251,12 +1444,20 @@ static noinline int do_change_type(struct nameidata *nd, int flag)
1251 return -EINVAL; 1444 return -EINVAL;
1252 1445
1253 down_write(&namespace_sem); 1446 down_write(&namespace_sem);
1447 if (type == MS_SHARED) {
1448 err = invent_group_ids(mnt, recurse);
1449 if (err)
1450 goto out_unlock;
1451 }
1452
1254 spin_lock(&vfsmount_lock); 1453 spin_lock(&vfsmount_lock);
1255 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL)) 1454 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
1256 change_mnt_propagation(m, type); 1455 change_mnt_propagation(m, type);
1257 spin_unlock(&vfsmount_lock); 1456 spin_unlock(&vfsmount_lock);
1457
1458 out_unlock:
1258 up_write(&namespace_sem); 1459 up_write(&namespace_sem);
1259 return 0; 1460 return err;
1260} 1461}
1261 1462
1262/* 1463/*
@@ -1294,7 +1495,7 @@ static noinline int do_loopback(struct nameidata *nd, char *old_name,
1294 if (!mnt) 1495 if (!mnt)
1295 goto out; 1496 goto out;
1296 1497
1297 err = graft_tree(mnt, nd); 1498 err = graft_tree(mnt, &nd->path);
1298 if (err) { 1499 if (err) {
1299 LIST_HEAD(umount_list); 1500 LIST_HEAD(umount_list);
1300 spin_lock(&vfsmount_lock); 1501 spin_lock(&vfsmount_lock);
@@ -1501,7 +1702,7 @@ int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
1501 goto unlock; 1702 goto unlock;
1502 1703
1503 newmnt->mnt_flags = mnt_flags; 1704 newmnt->mnt_flags = mnt_flags;
1504 if ((err = graft_tree(newmnt, nd))) 1705 if ((err = graft_tree(newmnt, &nd->path)))
1505 goto unlock; 1706 goto unlock;
1506 1707
1507 if (fslist) /* add to the specified expiration list */ 1708 if (fslist) /* add to the specified expiration list */
@@ -1746,7 +1947,8 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
1746 if (retval) 1947 if (retval)
1747 return retval; 1948 return retval;
1748 1949
1749 retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page); 1950 retval = security_sb_mount(dev_name, &nd.path,
1951 type_page, flags, data_page);
1750 if (retval) 1952 if (retval)
1751 goto dput_out; 1953 goto dput_out;
1752 1954
@@ -1986,15 +2188,13 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
1986 const char __user * put_old) 2188 const char __user * put_old)
1987{ 2189{
1988 struct vfsmount *tmp; 2190 struct vfsmount *tmp;
1989 struct nameidata new_nd, old_nd, user_nd; 2191 struct nameidata new_nd, old_nd;
1990 struct path parent_path, root_parent; 2192 struct path parent_path, root_parent, root;
1991 int error; 2193 int error;
1992 2194
1993 if (!capable(CAP_SYS_ADMIN)) 2195 if (!capable(CAP_SYS_ADMIN))
1994 return -EPERM; 2196 return -EPERM;
1995 2197
1996 lock_kernel();
1997
1998 error = __user_walk(new_root, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, 2198 error = __user_walk(new_root, LOOKUP_FOLLOW | LOOKUP_DIRECTORY,
1999 &new_nd); 2199 &new_nd);
2000 if (error) 2200 if (error)
@@ -2007,14 +2207,14 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
2007 if (error) 2207 if (error)
2008 goto out1; 2208 goto out1;
2009 2209
2010 error = security_sb_pivotroot(&old_nd, &new_nd); 2210 error = security_sb_pivotroot(&old_nd.path, &new_nd.path);
2011 if (error) { 2211 if (error) {
2012 path_put(&old_nd.path); 2212 path_put(&old_nd.path);
2013 goto out1; 2213 goto out1;
2014 } 2214 }
2015 2215
2016 read_lock(&current->fs->lock); 2216 read_lock(&current->fs->lock);
2017 user_nd.path = current->fs->root; 2217 root = current->fs->root;
2018 path_get(&current->fs->root); 2218 path_get(&current->fs->root);
2019 read_unlock(&current->fs->lock); 2219 read_unlock(&current->fs->lock);
2020 down_write(&namespace_sem); 2220 down_write(&namespace_sem);
@@ -2022,9 +2222,9 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
2022 error = -EINVAL; 2222 error = -EINVAL;
2023 if (IS_MNT_SHARED(old_nd.path.mnt) || 2223 if (IS_MNT_SHARED(old_nd.path.mnt) ||
2024 IS_MNT_SHARED(new_nd.path.mnt->mnt_parent) || 2224 IS_MNT_SHARED(new_nd.path.mnt->mnt_parent) ||
2025 IS_MNT_SHARED(user_nd.path.mnt->mnt_parent)) 2225 IS_MNT_SHARED(root.mnt->mnt_parent))
2026 goto out2; 2226 goto out2;
2027 if (!check_mnt(user_nd.path.mnt)) 2227 if (!check_mnt(root.mnt))
2028 goto out2; 2228 goto out2;
2029 error = -ENOENT; 2229 error = -ENOENT;
2030 if (IS_DEADDIR(new_nd.path.dentry->d_inode)) 2230 if (IS_DEADDIR(new_nd.path.dentry->d_inode))
@@ -2034,13 +2234,13 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
2034 if (d_unhashed(old_nd.path.dentry) && !IS_ROOT(old_nd.path.dentry)) 2234 if (d_unhashed(old_nd.path.dentry) && !IS_ROOT(old_nd.path.dentry))
2035 goto out2; 2235 goto out2;
2036 error = -EBUSY; 2236 error = -EBUSY;
2037 if (new_nd.path.mnt == user_nd.path.mnt || 2237 if (new_nd.path.mnt == root.mnt ||
2038 old_nd.path.mnt == user_nd.path.mnt) 2238 old_nd.path.mnt == root.mnt)
2039 goto out2; /* loop, on the same file system */ 2239 goto out2; /* loop, on the same file system */
2040 error = -EINVAL; 2240 error = -EINVAL;
2041 if (user_nd.path.mnt->mnt_root != user_nd.path.dentry) 2241 if (root.mnt->mnt_root != root.dentry)
2042 goto out2; /* not a mountpoint */ 2242 goto out2; /* not a mountpoint */
2043 if (user_nd.path.mnt->mnt_parent == user_nd.path.mnt) 2243 if (root.mnt->mnt_parent == root.mnt)
2044 goto out2; /* not attached */ 2244 goto out2; /* not attached */
2045 if (new_nd.path.mnt->mnt_root != new_nd.path.dentry) 2245 if (new_nd.path.mnt->mnt_root != new_nd.path.dentry)
2046 goto out2; /* not a mountpoint */ 2246 goto out2; /* not a mountpoint */
@@ -2062,27 +2262,26 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
2062 } else if (!is_subdir(old_nd.path.dentry, new_nd.path.dentry)) 2262 } else if (!is_subdir(old_nd.path.dentry, new_nd.path.dentry))
2063 goto out3; 2263 goto out3;
2064 detach_mnt(new_nd.path.mnt, &parent_path); 2264 detach_mnt(new_nd.path.mnt, &parent_path);
2065 detach_mnt(user_nd.path.mnt, &root_parent); 2265 detach_mnt(root.mnt, &root_parent);
2066 /* mount old root on put_old */ 2266 /* mount old root on put_old */
2067 attach_mnt(user_nd.path.mnt, &old_nd.path); 2267 attach_mnt(root.mnt, &old_nd.path);
2068 /* mount new_root on / */ 2268 /* mount new_root on / */
2069 attach_mnt(new_nd.path.mnt, &root_parent); 2269 attach_mnt(new_nd.path.mnt, &root_parent);
2070 touch_mnt_namespace(current->nsproxy->mnt_ns); 2270 touch_mnt_namespace(current->nsproxy->mnt_ns);
2071 spin_unlock(&vfsmount_lock); 2271 spin_unlock(&vfsmount_lock);
2072 chroot_fs_refs(&user_nd.path, &new_nd.path); 2272 chroot_fs_refs(&root, &new_nd.path);
2073 security_sb_post_pivotroot(&user_nd, &new_nd); 2273 security_sb_post_pivotroot(&root, &new_nd.path);
2074 error = 0; 2274 error = 0;
2075 path_put(&root_parent); 2275 path_put(&root_parent);
2076 path_put(&parent_path); 2276 path_put(&parent_path);
2077out2: 2277out2:
2078 mutex_unlock(&old_nd.path.dentry->d_inode->i_mutex); 2278 mutex_unlock(&old_nd.path.dentry->d_inode->i_mutex);
2079 up_write(&namespace_sem); 2279 up_write(&namespace_sem);
2080 path_put(&user_nd.path); 2280 path_put(&root);
2081 path_put(&old_nd.path); 2281 path_put(&old_nd.path);
2082out1: 2282out1:
2083 path_put(&new_nd.path); 2283 path_put(&new_nd.path);
2084out0: 2284out0:
2085 unlock_kernel();
2086 return error; 2285 return error;
2087out3: 2286out3:
2088 spin_unlock(&vfsmount_lock); 2287 spin_unlock(&vfsmount_lock);
diff --git a/fs/pipe.c b/fs/pipe.c
index 8be381bbcb54..f73492b6817e 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -988,7 +988,10 @@ struct file *create_write_pipe(void)
988 return f; 988 return f;
989 989
990 err_dentry: 990 err_dentry:
991 free_pipe_info(inode);
991 dput(dentry); 992 dput(dentry);
993 return ERR_PTR(err);
994
992 err_inode: 995 err_inode:
993 free_pipe_info(inode); 996 free_pipe_info(inode);
994 iput(inode); 997 iput(inode);
diff --git a/fs/pnode.c b/fs/pnode.c
index 1d8f5447f3f7..8d5f392ec3d3 100644
--- a/fs/pnode.c
+++ b/fs/pnode.c
@@ -9,6 +9,7 @@
9#include <linux/mnt_namespace.h> 9#include <linux/mnt_namespace.h>
10#include <linux/mount.h> 10#include <linux/mount.h>
11#include <linux/fs.h> 11#include <linux/fs.h>
12#include "internal.h"
12#include "pnode.h" 13#include "pnode.h"
13 14
14/* return the next shared peer mount of @p */ 15/* return the next shared peer mount of @p */
@@ -27,6 +28,57 @@ static inline struct vfsmount *next_slave(struct vfsmount *p)
27 return list_entry(p->mnt_slave.next, struct vfsmount, mnt_slave); 28 return list_entry(p->mnt_slave.next, struct vfsmount, mnt_slave);
28} 29}
29 30
31/*
32 * Return true if path is reachable from root
33 *
34 * namespace_sem is held, and mnt is attached
35 */
36static bool is_path_reachable(struct vfsmount *mnt, struct dentry *dentry,
37 const struct path *root)
38{
39 while (mnt != root->mnt && mnt->mnt_parent != mnt) {
40 dentry = mnt->mnt_mountpoint;
41 mnt = mnt->mnt_parent;
42 }
43 return mnt == root->mnt && is_subdir(dentry, root->dentry);
44}
45
46static struct vfsmount *get_peer_under_root(struct vfsmount *mnt,
47 struct mnt_namespace *ns,
48 const struct path *root)
49{
50 struct vfsmount *m = mnt;
51
52 do {
53 /* Check the namespace first for optimization */
54 if (m->mnt_ns == ns && is_path_reachable(m, m->mnt_root, root))
55 return m;
56
57 m = next_peer(m);
58 } while (m != mnt);
59
60 return NULL;
61}
62
63/*
64 * Get ID of closest dominating peer group having a representative
65 * under the given root.
66 *
67 * Caller must hold namespace_sem
68 */
69int get_dominating_id(struct vfsmount *mnt, const struct path *root)
70{
71 struct vfsmount *m;
72
73 for (m = mnt->mnt_master; m != NULL; m = m->mnt_master) {
74 struct vfsmount *d = get_peer_under_root(m, mnt->mnt_ns, root);
75 if (d)
76 return d->mnt_group_id;
77 }
78
79 return 0;
80}
81
30static int do_make_slave(struct vfsmount *mnt) 82static int do_make_slave(struct vfsmount *mnt)
31{ 83{
32 struct vfsmount *peer_mnt = mnt, *master = mnt->mnt_master; 84 struct vfsmount *peer_mnt = mnt, *master = mnt->mnt_master;
@@ -45,7 +97,11 @@ static int do_make_slave(struct vfsmount *mnt)
45 if (peer_mnt == mnt) 97 if (peer_mnt == mnt)
46 peer_mnt = NULL; 98 peer_mnt = NULL;
47 } 99 }
100 if (IS_MNT_SHARED(mnt) && list_empty(&mnt->mnt_share))
101 mnt_release_group_id(mnt);
102
48 list_del_init(&mnt->mnt_share); 103 list_del_init(&mnt->mnt_share);
104 mnt->mnt_group_id = 0;
49 105
50 if (peer_mnt) 106 if (peer_mnt)
51 master = peer_mnt; 107 master = peer_mnt;
@@ -67,7 +123,6 @@ static int do_make_slave(struct vfsmount *mnt)
67 } 123 }
68 mnt->mnt_master = master; 124 mnt->mnt_master = master;
69 CLEAR_MNT_SHARED(mnt); 125 CLEAR_MNT_SHARED(mnt);
70 INIT_LIST_HEAD(&mnt->mnt_slave_list);
71 return 0; 126 return 0;
72} 127}
73 128
@@ -211,8 +266,7 @@ int propagate_mnt(struct vfsmount *dest_mnt, struct dentry *dest_dentry,
211out: 266out:
212 spin_lock(&vfsmount_lock); 267 spin_lock(&vfsmount_lock);
213 while (!list_empty(&tmp_list)) { 268 while (!list_empty(&tmp_list)) {
214 child = list_entry(tmp_list.next, struct vfsmount, mnt_hash); 269 child = list_first_entry(&tmp_list, struct vfsmount, mnt_hash);
215 list_del_init(&child->mnt_hash);
216 umount_tree(child, 0, &umount_list); 270 umount_tree(child, 0, &umount_list);
217 } 271 }
218 spin_unlock(&vfsmount_lock); 272 spin_unlock(&vfsmount_lock);
diff --git a/fs/pnode.h b/fs/pnode.h
index f249be2fee7a..958665d662af 100644
--- a/fs/pnode.h
+++ b/fs/pnode.h
@@ -35,4 +35,6 @@ int propagate_mnt(struct vfsmount *, struct dentry *, struct vfsmount *,
35 struct list_head *); 35 struct list_head *);
36int propagate_umount(struct list_head *); 36int propagate_umount(struct list_head *);
37int propagate_mount_busy(struct vfsmount *, int); 37int propagate_mount_busy(struct vfsmount *, int);
38void mnt_release_group_id(struct vfsmount *);
39int get_dominating_id(struct vfsmount *mnt, const struct path *root);
38#endif /* _LINUX_PNODE_H */ 40#endif /* _LINUX_PNODE_H */
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 81d7d145292a..c5e412a00b17 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -502,17 +502,14 @@ static const struct inode_operations proc_def_inode_operations = {
502 .setattr = proc_setattr, 502 .setattr = proc_setattr,
503}; 503};
504 504
505extern const struct seq_operations mounts_op; 505static int mounts_open_common(struct inode *inode, struct file *file,
506struct proc_mounts { 506 const struct seq_operations *op)
507 struct seq_file m;
508 int event;
509};
510
511static int mounts_open(struct inode *inode, struct file *file)
512{ 507{
513 struct task_struct *task = get_proc_task(inode); 508 struct task_struct *task = get_proc_task(inode);
514 struct nsproxy *nsp; 509 struct nsproxy *nsp;
515 struct mnt_namespace *ns = NULL; 510 struct mnt_namespace *ns = NULL;
511 struct fs_struct *fs = NULL;
512 struct path root;
516 struct proc_mounts *p; 513 struct proc_mounts *p;
517 int ret = -EINVAL; 514 int ret = -EINVAL;
518 515
@@ -525,40 +522,61 @@ static int mounts_open(struct inode *inode, struct file *file)
525 get_mnt_ns(ns); 522 get_mnt_ns(ns);
526 } 523 }
527 rcu_read_unlock(); 524 rcu_read_unlock();
528 525 if (ns)
526 fs = get_fs_struct(task);
529 put_task_struct(task); 527 put_task_struct(task);
530 } 528 }
531 529
532 if (ns) { 530 if (!ns)
533 ret = -ENOMEM; 531 goto err;
534 p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL); 532 if (!fs)
535 if (p) { 533 goto err_put_ns;
536 file->private_data = &p->m; 534
537 ret = seq_open(file, &mounts_op); 535 read_lock(&fs->lock);
538 if (!ret) { 536 root = fs->root;
539 p->m.private = ns; 537 path_get(&root);
540 p->event = ns->event; 538 read_unlock(&fs->lock);
541 return 0; 539 put_fs_struct(fs);
542 } 540
543 kfree(p); 541 ret = -ENOMEM;
544 } 542 p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
545 put_mnt_ns(ns); 543 if (!p)
546 } 544 goto err_put_path;
545
546 file->private_data = &p->m;
547 ret = seq_open(file, op);
548 if (ret)
549 goto err_free;
550
551 p->m.private = p;
552 p->ns = ns;
553 p->root = root;
554 p->event = ns->event;
555
556 return 0;
557
558 err_free:
559 kfree(p);
560 err_put_path:
561 path_put(&root);
562 err_put_ns:
563 put_mnt_ns(ns);
564 err:
547 return ret; 565 return ret;
548} 566}
549 567
550static int mounts_release(struct inode *inode, struct file *file) 568static int mounts_release(struct inode *inode, struct file *file)
551{ 569{
552 struct seq_file *m = file->private_data; 570 struct proc_mounts *p = file->private_data;
553 struct mnt_namespace *ns = m->private; 571 path_put(&p->root);
554 put_mnt_ns(ns); 572 put_mnt_ns(p->ns);
555 return seq_release(inode, file); 573 return seq_release(inode, file);
556} 574}
557 575
558static unsigned mounts_poll(struct file *file, poll_table *wait) 576static unsigned mounts_poll(struct file *file, poll_table *wait)
559{ 577{
560 struct proc_mounts *p = file->private_data; 578 struct proc_mounts *p = file->private_data;
561 struct mnt_namespace *ns = p->m.private; 579 struct mnt_namespace *ns = p->ns;
562 unsigned res = 0; 580 unsigned res = 0;
563 581
564 poll_wait(file, &ns->poll, wait); 582 poll_wait(file, &ns->poll, wait);
@@ -573,6 +591,11 @@ static unsigned mounts_poll(struct file *file, poll_table *wait)
573 return res; 591 return res;
574} 592}
575 593
594static int mounts_open(struct inode *inode, struct file *file)
595{
596 return mounts_open_common(inode, file, &mounts_op);
597}
598
576static const struct file_operations proc_mounts_operations = { 599static const struct file_operations proc_mounts_operations = {
577 .open = mounts_open, 600 .open = mounts_open,
578 .read = seq_read, 601 .read = seq_read,
@@ -581,38 +604,22 @@ static const struct file_operations proc_mounts_operations = {
581 .poll = mounts_poll, 604 .poll = mounts_poll,
582}; 605};
583 606
584extern const struct seq_operations mountstats_op; 607static int mountinfo_open(struct inode *inode, struct file *file)
585static int mountstats_open(struct inode *inode, struct file *file)
586{ 608{
587 int ret = seq_open(file, &mountstats_op); 609 return mounts_open_common(inode, file, &mountinfo_op);
588 610}
589 if (!ret) {
590 struct seq_file *m = file->private_data;
591 struct nsproxy *nsp;
592 struct mnt_namespace *mnt_ns = NULL;
593 struct task_struct *task = get_proc_task(inode);
594
595 if (task) {
596 rcu_read_lock();
597 nsp = task_nsproxy(task);
598 if (nsp) {
599 mnt_ns = nsp->mnt_ns;
600 if (mnt_ns)
601 get_mnt_ns(mnt_ns);
602 }
603 rcu_read_unlock();
604 611
605 put_task_struct(task); 612static const struct file_operations proc_mountinfo_operations = {
606 } 613 .open = mountinfo_open,
614 .read = seq_read,
615 .llseek = seq_lseek,
616 .release = mounts_release,
617 .poll = mounts_poll,
618};
607 619
608 if (mnt_ns) 620static int mountstats_open(struct inode *inode, struct file *file)
609 m->private = mnt_ns; 621{
610 else { 622 return mounts_open_common(inode, file, &mountstats_op);
611 seq_release(inode, file);
612 ret = -EINVAL;
613 }
614 }
615 return ret;
616} 623}
617 624
618static const struct file_operations proc_mountstats_operations = { 625static const struct file_operations proc_mountstats_operations = {
@@ -1626,7 +1633,6 @@ static int proc_readfd_common(struct file * filp, void * dirent,
1626 unsigned int fd, ino; 1633 unsigned int fd, ino;
1627 int retval; 1634 int retval;
1628 struct files_struct * files; 1635 struct files_struct * files;
1629 struct fdtable *fdt;
1630 1636
1631 retval = -ENOENT; 1637 retval = -ENOENT;
1632 if (!p) 1638 if (!p)
@@ -1649,9 +1655,8 @@ static int proc_readfd_common(struct file * filp, void * dirent,
1649 if (!files) 1655 if (!files)
1650 goto out; 1656 goto out;
1651 rcu_read_lock(); 1657 rcu_read_lock();
1652 fdt = files_fdtable(files);
1653 for (fd = filp->f_pos-2; 1658 for (fd = filp->f_pos-2;
1654 fd < fdt->max_fds; 1659 fd < files_fdtable(files)->max_fds;
1655 fd++, filp->f_pos++) { 1660 fd++, filp->f_pos++) {
1656 char name[PROC_NUMBUF]; 1661 char name[PROC_NUMBUF];
1657 int len; 1662 int len;
@@ -2311,6 +2316,7 @@ static const struct pid_entry tgid_base_stuff[] = {
2311 LNK("root", root), 2316 LNK("root", root),
2312 LNK("exe", exe), 2317 LNK("exe", exe),
2313 REG("mounts", S_IRUGO, mounts), 2318 REG("mounts", S_IRUGO, mounts),
2319 REG("mountinfo", S_IRUGO, mountinfo),
2314 REG("mountstats", S_IRUSR, mountstats), 2320 REG("mountstats", S_IRUSR, mountstats),
2315#ifdef CONFIG_PROC_PAGE_MONITOR 2321#ifdef CONFIG_PROC_PAGE_MONITOR
2316 REG("clear_refs", S_IWUSR, clear_refs), 2322 REG("clear_refs", S_IWUSR, clear_refs),
@@ -2643,6 +2649,7 @@ static const struct pid_entry tid_base_stuff[] = {
2643 LNK("root", root), 2649 LNK("root", root),
2644 LNK("exe", exe), 2650 LNK("exe", exe),
2645 REG("mounts", S_IRUGO, mounts), 2651 REG("mounts", S_IRUGO, mounts),
2652 REG("mountinfo", S_IRUGO, mountinfo),
2646#ifdef CONFIG_PROC_PAGE_MONITOR 2653#ifdef CONFIG_PROC_PAGE_MONITOR
2647 REG("clear_refs", S_IWUSR, clear_refs), 2654 REG("clear_refs", S_IWUSR, clear_refs),
2648 REG("smaps", S_IRUGO, smaps), 2655 REG("smaps", S_IRUGO, smaps),
diff --git a/fs/read_write.c b/fs/read_write.c
index 49a98718ecdf..f0d1240a5c69 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -33,7 +33,7 @@ EXPORT_SYMBOL(generic_ro_fops);
33 33
34loff_t generic_file_llseek(struct file *file, loff_t offset, int origin) 34loff_t generic_file_llseek(struct file *file, loff_t offset, int origin)
35{ 35{
36 long long retval; 36 loff_t retval;
37 struct inode *inode = file->f_mapping->host; 37 struct inode *inode = file->f_mapping->host;
38 38
39 mutex_lock(&inode->i_mutex); 39 mutex_lock(&inode->i_mutex);
@@ -60,7 +60,7 @@ EXPORT_SYMBOL(generic_file_llseek);
60 60
61loff_t remote_llseek(struct file *file, loff_t offset, int origin) 61loff_t remote_llseek(struct file *file, loff_t offset, int origin)
62{ 62{
63 long long retval; 63 loff_t retval;
64 64
65 lock_kernel(); 65 lock_kernel();
66 switch (origin) { 66 switch (origin) {
@@ -91,7 +91,7 @@ EXPORT_SYMBOL(no_llseek);
91 91
92loff_t default_llseek(struct file *file, loff_t offset, int origin) 92loff_t default_llseek(struct file *file, loff_t offset, int origin)
93{ 93{
94 long long retval; 94 loff_t retval;
95 95
96 lock_kernel(); 96 lock_kernel();
97 switch (origin) { 97 switch (origin) {
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 853770274f20..3f54dbd6c49b 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -25,6 +25,7 @@
25 * into the buffer. In case of error ->start() and ->next() return 25 * into the buffer. In case of error ->start() and ->next() return
26 * ERR_PTR(error). In the end of sequence they return %NULL. ->show() 26 * ERR_PTR(error). In the end of sequence they return %NULL. ->show()
27 * returns 0 in case of success and negative number in case of error. 27 * returns 0 in case of success and negative number in case of error.
28 * Returning SEQ_SKIP means "discard this element and move on".
28 */ 29 */
29int seq_open(struct file *file, const struct seq_operations *op) 30int seq_open(struct file *file, const struct seq_operations *op)
30{ 31{
@@ -114,8 +115,10 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
114 if (!p || IS_ERR(p)) 115 if (!p || IS_ERR(p))
115 break; 116 break;
116 err = m->op->show(m, p); 117 err = m->op->show(m, p);
117 if (err) 118 if (err < 0)
118 break; 119 break;
120 if (unlikely(err))
121 m->count = 0;
119 if (m->count < m->size) 122 if (m->count < m->size)
120 goto Fill; 123 goto Fill;
121 m->op->stop(m, p); 124 m->op->stop(m, p);
@@ -140,9 +143,10 @@ Fill:
140 break; 143 break;
141 } 144 }
142 err = m->op->show(m, p); 145 err = m->op->show(m, p);
143 if (err || m->count == m->size) { 146 if (m->count == m->size || err) {
144 m->count = offs; 147 m->count = offs;
145 break; 148 if (likely(err <= 0))
149 break;
146 } 150 }
147 pos = next; 151 pos = next;
148 } 152 }
@@ -199,8 +203,12 @@ static int traverse(struct seq_file *m, loff_t offset)
199 if (IS_ERR(p)) 203 if (IS_ERR(p))
200 break; 204 break;
201 error = m->op->show(m, p); 205 error = m->op->show(m, p);
202 if (error) 206 if (error < 0)
203 break; 207 break;
208 if (unlikely(error)) {
209 error = 0;
210 m->count = 0;
211 }
204 if (m->count == m->size) 212 if (m->count == m->size)
205 goto Eoverflow; 213 goto Eoverflow;
206 if (pos + m->count > offset) { 214 if (pos + m->count > offset) {
@@ -239,7 +247,7 @@ Eoverflow:
239loff_t seq_lseek(struct file *file, loff_t offset, int origin) 247loff_t seq_lseek(struct file *file, loff_t offset, int origin)
240{ 248{
241 struct seq_file *m = (struct seq_file *)file->private_data; 249 struct seq_file *m = (struct seq_file *)file->private_data;
242 long long retval = -EINVAL; 250 loff_t retval = -EINVAL;
243 251
244 mutex_lock(&m->lock); 252 mutex_lock(&m->lock);
245 m->version = file->f_version; 253 m->version = file->f_version;
@@ -342,28 +350,40 @@ int seq_printf(struct seq_file *m, const char *f, ...)
342} 350}
343EXPORT_SYMBOL(seq_printf); 351EXPORT_SYMBOL(seq_printf);
344 352
353static char *mangle_path(char *s, char *p, char *esc)
354{
355 while (s <= p) {
356 char c = *p++;
357 if (!c) {
358 return s;
359 } else if (!strchr(esc, c)) {
360 *s++ = c;
361 } else if (s + 4 > p) {
362 break;
363 } else {
364 *s++ = '\\';
365 *s++ = '0' + ((c & 0300) >> 6);
366 *s++ = '0' + ((c & 070) >> 3);
367 *s++ = '0' + (c & 07);
368 }
369 }
370 return NULL;
371}
372
373/*
374 * return the absolute path of 'dentry' residing in mount 'mnt'.
375 */
345int seq_path(struct seq_file *m, struct path *path, char *esc) 376int seq_path(struct seq_file *m, struct path *path, char *esc)
346{ 377{
347 if (m->count < m->size) { 378 if (m->count < m->size) {
348 char *s = m->buf + m->count; 379 char *s = m->buf + m->count;
349 char *p = d_path(path, s, m->size - m->count); 380 char *p = d_path(path, s, m->size - m->count);
350 if (!IS_ERR(p)) { 381 if (!IS_ERR(p)) {
351 while (s <= p) { 382 s = mangle_path(s, p, esc);
352 char c = *p++; 383 if (s) {
353 if (!c) { 384 p = m->buf + m->count;
354 p = m->buf + m->count; 385 m->count = s - m->buf;
355 m->count = s - m->buf; 386 return s - p;
356 return s - p;
357 } else if (!strchr(esc, c)) {
358 *s++ = c;
359 } else if (s + 4 > p) {
360 break;
361 } else {
362 *s++ = '\\';
363 *s++ = '0' + ((c & 0300) >> 6);
364 *s++ = '0' + ((c & 070) >> 3);
365 *s++ = '0' + (c & 07);
366 }
367 } 387 }
368 } 388 }
369 } 389 }
@@ -372,6 +392,57 @@ int seq_path(struct seq_file *m, struct path *path, char *esc)
372} 392}
373EXPORT_SYMBOL(seq_path); 393EXPORT_SYMBOL(seq_path);
374 394
395/*
396 * Same as seq_path, but relative to supplied root.
397 *
398 * root may be changed, see __d_path().
399 */
400int seq_path_root(struct seq_file *m, struct path *path, struct path *root,
401 char *esc)
402{
403 int err = -ENAMETOOLONG;
404 if (m->count < m->size) {
405 char *s = m->buf + m->count;
406 char *p;
407
408 spin_lock(&dcache_lock);
409 p = __d_path(path, root, s, m->size - m->count);
410 spin_unlock(&dcache_lock);
411 err = PTR_ERR(p);
412 if (!IS_ERR(p)) {
413 s = mangle_path(s, p, esc);
414 if (s) {
415 p = m->buf + m->count;
416 m->count = s - m->buf;
417 return 0;
418 }
419 }
420 }
421 m->count = m->size;
422 return err;
423}
424
425/*
426 * returns the path of the 'dentry' from the root of its filesystem.
427 */
428int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)
429{
430 if (m->count < m->size) {
431 char *s = m->buf + m->count;
432 char *p = dentry_path(dentry, s, m->size - m->count);
433 if (!IS_ERR(p)) {
434 s = mangle_path(s, p, esc);
435 if (s) {
436 p = m->buf + m->count;
437 m->count = s - m->buf;
438 return s - p;
439 }
440 }
441 }
442 m->count = m->size;
443 return -1;
444}
445
375static void *single_start(struct seq_file *p, loff_t *pos) 446static void *single_start(struct seq_file *p, loff_t *pos)
376{ 447{
377 return NULL + (*pos == 0); 448 return NULL + (*pos == 0);
diff --git a/fs/super.c b/fs/super.c
index 1f8f05ede437..4798350b2bc9 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -39,6 +39,7 @@
39#include <linux/mutex.h> 39#include <linux/mutex.h>
40#include <linux/file.h> 40#include <linux/file.h>
41#include <asm/uaccess.h> 41#include <asm/uaccess.h>
42#include "internal.h"
42 43
43 44
44LIST_HEAD(super_blocks); 45LIST_HEAD(super_blocks);
diff --git a/fs/udf/Makefile b/fs/udf/Makefile
index be845e7540ef..0d4503f7446d 100644
--- a/fs/udf/Makefile
+++ b/fs/udf/Makefile
@@ -6,4 +6,4 @@ obj-$(CONFIG_UDF_FS) += udf.o
6 6
7udf-objs := balloc.o dir.o file.o ialloc.o inode.o lowlevel.o namei.o \ 7udf-objs := balloc.o dir.o file.o ialloc.o inode.o lowlevel.o namei.o \
8 partition.o super.o truncate.o symlink.o fsync.o \ 8 partition.o super.o truncate.o symlink.o fsync.o \
9 crc.o directory.o misc.o udftime.o unicode.o 9 directory.o misc.o udftime.o unicode.o
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
index f855dcbbdfb8..1b809bd494bd 100644
--- a/fs/udf/balloc.c
+++ b/fs/udf/balloc.c
@@ -149,8 +149,7 @@ static bool udf_add_free_space(struct udf_sb_info *sbi,
149 return false; 149 return false;
150 150
151 lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; 151 lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
152 lvid->freeSpaceTable[partition] = cpu_to_le32(le32_to_cpu( 152 le32_add_cpu(&lvid->freeSpaceTable[partition], cnt);
153 lvid->freeSpaceTable[partition]) + cnt);
154 return true; 153 return true;
155} 154}
156 155
@@ -589,10 +588,8 @@ static void udf_table_free_blocks(struct super_block *sb,
589 sptr = oepos.bh->b_data + epos.offset; 588 sptr = oepos.bh->b_data + epos.offset;
590 aed = (struct allocExtDesc *) 589 aed = (struct allocExtDesc *)
591 oepos.bh->b_data; 590 oepos.bh->b_data;
592 aed->lengthAllocDescs = 591 le32_add_cpu(&aed->lengthAllocDescs,
593 cpu_to_le32(le32_to_cpu( 592 adsize);
594 aed->lengthAllocDescs) +
595 adsize);
596 } else { 593 } else {
597 sptr = iinfo->i_ext.i_data + 594 sptr = iinfo->i_ext.i_data +
598 epos.offset; 595 epos.offset;
@@ -645,9 +642,7 @@ static void udf_table_free_blocks(struct super_block *sb,
645 mark_inode_dirty(table); 642 mark_inode_dirty(table);
646 } else { 643 } else {
647 aed = (struct allocExtDesc *)epos.bh->b_data; 644 aed = (struct allocExtDesc *)epos.bh->b_data;
648 aed->lengthAllocDescs = 645 le32_add_cpu(&aed->lengthAllocDescs, adsize);
649 cpu_to_le32(le32_to_cpu(
650 aed->lengthAllocDescs) + adsize);
651 udf_update_tag(epos.bh->b_data, epos.offset); 646 udf_update_tag(epos.bh->b_data, epos.offset);
652 mark_buffer_dirty(epos.bh); 647 mark_buffer_dirty(epos.bh);
653 } 648 }
diff --git a/fs/udf/crc.c b/fs/udf/crc.c
deleted file mode 100644
index b1661296e786..000000000000
--- a/fs/udf/crc.c
+++ /dev/null
@@ -1,172 +0,0 @@
1/*
2 * crc.c
3 *
4 * PURPOSE
5 * Routines to generate, calculate, and test a 16-bit CRC.
6 *
7 * DESCRIPTION
8 * The CRC code was devised by Don P. Mitchell of AT&T Bell Laboratories
9 * and Ned W. Rhodes of Software Systems Group. It has been published in
10 * "Design and Validation of Computer Protocols", Prentice Hall,
11 * Englewood Cliffs, NJ, 1991, Chapter 3, ISBN 0-13-539925-4.
12 *
13 * Copyright is held by AT&T.
14 *
15 * AT&T gives permission for the free use of the CRC source code.
16 *
17 * COPYRIGHT
18 * This file is distributed under the terms of the GNU General Public
19 * License (GPL). Copies of the GPL can be obtained from:
20 * ftp://prep.ai.mit.edu/pub/gnu/GPL
21 * Each contributing author retains all rights to their own work.
22 */
23
24#include "udfdecl.h"
25
26static uint16_t crc_table[256] = {
27 0x0000U, 0x1021U, 0x2042U, 0x3063U, 0x4084U, 0x50a5U, 0x60c6U, 0x70e7U,
28 0x8108U, 0x9129U, 0xa14aU, 0xb16bU, 0xc18cU, 0xd1adU, 0xe1ceU, 0xf1efU,
29 0x1231U, 0x0210U, 0x3273U, 0x2252U, 0x52b5U, 0x4294U, 0x72f7U, 0x62d6U,
30 0x9339U, 0x8318U, 0xb37bU, 0xa35aU, 0xd3bdU, 0xc39cU, 0xf3ffU, 0xe3deU,
31 0x2462U, 0x3443U, 0x0420U, 0x1401U, 0x64e6U, 0x74c7U, 0x44a4U, 0x5485U,
32 0xa56aU, 0xb54bU, 0x8528U, 0x9509U, 0xe5eeU, 0xf5cfU, 0xc5acU, 0xd58dU,
33 0x3653U, 0x2672U, 0x1611U, 0x0630U, 0x76d7U, 0x66f6U, 0x5695U, 0x46b4U,
34 0xb75bU, 0xa77aU, 0x9719U, 0x8738U, 0xf7dfU, 0xe7feU, 0xd79dU, 0xc7bcU,
35 0x48c4U, 0x58e5U, 0x6886U, 0x78a7U, 0x0840U, 0x1861U, 0x2802U, 0x3823U,
36 0xc9ccU, 0xd9edU, 0xe98eU, 0xf9afU, 0x8948U, 0x9969U, 0xa90aU, 0xb92bU,
37 0x5af5U, 0x4ad4U, 0x7ab7U, 0x6a96U, 0x1a71U, 0x0a50U, 0x3a33U, 0x2a12U,
38 0xdbfdU, 0xcbdcU, 0xfbbfU, 0xeb9eU, 0x9b79U, 0x8b58U, 0xbb3bU, 0xab1aU,
39 0x6ca6U, 0x7c87U, 0x4ce4U, 0x5cc5U, 0x2c22U, 0x3c03U, 0x0c60U, 0x1c41U,
40 0xedaeU, 0xfd8fU, 0xcdecU, 0xddcdU, 0xad2aU, 0xbd0bU, 0x8d68U, 0x9d49U,
41 0x7e97U, 0x6eb6U, 0x5ed5U, 0x4ef4U, 0x3e13U, 0x2e32U, 0x1e51U, 0x0e70U,
42 0xff9fU, 0xefbeU, 0xdfddU, 0xcffcU, 0xbf1bU, 0xaf3aU, 0x9f59U, 0x8f78U,
43 0x9188U, 0x81a9U, 0xb1caU, 0xa1ebU, 0xd10cU, 0xc12dU, 0xf14eU, 0xe16fU,
44 0x1080U, 0x00a1U, 0x30c2U, 0x20e3U, 0x5004U, 0x4025U, 0x7046U, 0x6067U,
45 0x83b9U, 0x9398U, 0xa3fbU, 0xb3daU, 0xc33dU, 0xd31cU, 0xe37fU, 0xf35eU,
46 0x02b1U, 0x1290U, 0x22f3U, 0x32d2U, 0x4235U, 0x5214U, 0x6277U, 0x7256U,
47 0xb5eaU, 0xa5cbU, 0x95a8U, 0x8589U, 0xf56eU, 0xe54fU, 0xd52cU, 0xc50dU,
48 0x34e2U, 0x24c3U, 0x14a0U, 0x0481U, 0x7466U, 0x6447U, 0x5424U, 0x4405U,
49 0xa7dbU, 0xb7faU, 0x8799U, 0x97b8U, 0xe75fU, 0xf77eU, 0xc71dU, 0xd73cU,
50 0x26d3U, 0x36f2U, 0x0691U, 0x16b0U, 0x6657U, 0x7676U, 0x4615U, 0x5634U,
51 0xd94cU, 0xc96dU, 0xf90eU, 0xe92fU, 0x99c8U, 0x89e9U, 0xb98aU, 0xa9abU,
52 0x5844U, 0x4865U, 0x7806U, 0x6827U, 0x18c0U, 0x08e1U, 0x3882U, 0x28a3U,
53 0xcb7dU, 0xdb5cU, 0xeb3fU, 0xfb1eU, 0x8bf9U, 0x9bd8U, 0xabbbU, 0xbb9aU,
54 0x4a75U, 0x5a54U, 0x6a37U, 0x7a16U, 0x0af1U, 0x1ad0U, 0x2ab3U, 0x3a92U,
55 0xfd2eU, 0xed0fU, 0xdd6cU, 0xcd4dU, 0xbdaaU, 0xad8bU, 0x9de8U, 0x8dc9U,
56 0x7c26U, 0x6c07U, 0x5c64U, 0x4c45U, 0x3ca2U, 0x2c83U, 0x1ce0U, 0x0cc1U,
57 0xef1fU, 0xff3eU, 0xcf5dU, 0xdf7cU, 0xaf9bU, 0xbfbaU, 0x8fd9U, 0x9ff8U,
58 0x6e17U, 0x7e36U, 0x4e55U, 0x5e74U, 0x2e93U, 0x3eb2U, 0x0ed1U, 0x1ef0U
59};
60
61/*
62 * udf_crc
63 *
64 * PURPOSE
65 * Calculate a 16-bit CRC checksum using ITU-T V.41 polynomial.
66 *
67 * DESCRIPTION
68 * The OSTA-UDF(tm) 1.50 standard states that using CRCs is mandatory.
69 * The polynomial used is: x^16 + x^12 + x^15 + 1
70 *
71 * PRE-CONDITIONS
72 * data Pointer to the data block.
73 * size Size of the data block.
74 *
75 * POST-CONDITIONS
76 * <return> CRC of the data block.
77 *
78 * HISTORY
79 * July 21, 1997 - Andrew E. Mileski
80 * Adapted from OSTA-UDF(tm) 1.50 standard.
81 */
82uint16_t udf_crc(uint8_t *data, uint32_t size, uint16_t crc)
83{
84 while (size--)
85 crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8);
86
87 return crc;
88}
89
90/****************************************************************************/
91#if defined(TEST)
92
93/*
94 * PURPOSE
95 * Test udf_crc()
96 *
97 * HISTORY
98 * July 21, 1997 - Andrew E. Mileski
99 * Adapted from OSTA-UDF(tm) 1.50 standard.
100 */
101
102unsigned char bytes[] = { 0x70U, 0x6AU, 0x77U };
103
104int main(void)
105{
106 unsigned short x;
107
108 x = udf_crc(bytes, sizeof bytes);
109 printf("udf_crc: calculated = %4.4x, correct = %4.4x\n", x, 0x3299U);
110
111 return 0;
112}
113
114#endif /* defined(TEST) */
115
116/****************************************************************************/
117#if defined(GENERATE)
118
119/*
120 * PURPOSE
121 * Generate a table for fast 16-bit CRC calculations (any polynomial).
122 *
123 * DESCRIPTION
124 * The ITU-T V.41 polynomial is 010041.
125 *
126 * HISTORY
127 * July 21, 1997 - Andrew E. Mileski
128 * Adapted from OSTA-UDF(tm) 1.50 standard.
129 */
130
131#include <stdio.h>
132
133int main(int argc, char **argv)
134{
135 unsigned long crc, poly;
136 int n, i;
137
138 /* Get the polynomial */
139 sscanf(argv[1], "%lo", &poly);
140 if (poly & 0xffff0000U) {
141 fprintf(stderr, "polynomial is too large\en");
142 exit(1);
143 }
144
145 printf("/* CRC 0%o */\n", poly);
146
147 /* Create a table */
148 printf("static unsigned short crc_table[256] = {\n");
149 for (n = 0; n < 256; n++) {
150 if (n % 8 == 0)
151 printf("\t");
152 crc = n << 8;
153 for (i = 0; i < 8; i++) {
154 if (crc & 0x8000U)
155 crc = (crc << 1) ^ poly;
156 else
157 crc <<= 1;
158 crc &= 0xFFFFU;
159 }
160 if (n == 255)
161 printf("0x%04xU ", crc);
162 else
163 printf("0x%04xU, ", crc);
164 if (n % 8 == 7)
165 printf("\n");
166 }
167 printf("};\n");
168
169 return 0;
170}
171
172#endif /* defined(GENERATE) */
diff --git a/fs/udf/dir.c b/fs/udf/dir.c
index 8d8643ada199..62dc270c69d1 100644
--- a/fs/udf/dir.c
+++ b/fs/udf/dir.c
@@ -39,13 +39,13 @@
39static int do_udf_readdir(struct inode *dir, struct file *filp, 39static int do_udf_readdir(struct inode *dir, struct file *filp,
40 filldir_t filldir, void *dirent) 40 filldir_t filldir, void *dirent)
41{ 41{
42 struct udf_fileident_bh fibh; 42 struct udf_fileident_bh fibh = { .sbh = NULL, .ebh = NULL};
43 struct fileIdentDesc *fi = NULL; 43 struct fileIdentDesc *fi = NULL;
44 struct fileIdentDesc cfi; 44 struct fileIdentDesc cfi;
45 int block, iblock; 45 int block, iblock;
46 loff_t nf_pos = (filp->f_pos - 1) << 2; 46 loff_t nf_pos = (filp->f_pos - 1) << 2;
47 int flen; 47 int flen;
48 char fname[UDF_NAME_LEN]; 48 char *fname = NULL;
49 char *nameptr; 49 char *nameptr;
50 uint16_t liu; 50 uint16_t liu;
51 uint8_t lfi; 51 uint8_t lfi;
@@ -54,23 +54,32 @@ static int do_udf_readdir(struct inode *dir, struct file *filp,
54 kernel_lb_addr eloc; 54 kernel_lb_addr eloc;
55 uint32_t elen; 55 uint32_t elen;
56 sector_t offset; 56 sector_t offset;
57 int i, num; 57 int i, num, ret = 0;
58 unsigned int dt_type; 58 unsigned int dt_type;
59 struct extent_position epos = { NULL, 0, {0, 0} }; 59 struct extent_position epos = { NULL, 0, {0, 0} };
60 struct udf_inode_info *iinfo; 60 struct udf_inode_info *iinfo;
61 61
62 if (nf_pos >= size) 62 if (nf_pos >= size)
63 return 0; 63 goto out;
64
65 fname = kmalloc(UDF_NAME_LEN, GFP_NOFS);
66 if (!fname) {
67 ret = -ENOMEM;
68 goto out;
69 }
64 70
65 if (nf_pos == 0) 71 if (nf_pos == 0)
66 nf_pos = udf_ext0_offset(dir); 72 nf_pos = udf_ext0_offset(dir);
67 73
68 fibh.soffset = fibh.eoffset = nf_pos & (dir->i_sb->s_blocksize - 1); 74 fibh.soffset = fibh.eoffset = nf_pos & (dir->i_sb->s_blocksize - 1);
69 iinfo = UDF_I(dir); 75 iinfo = UDF_I(dir);
70 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { 76 if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
71 fibh.sbh = fibh.ebh = NULL; 77 if (inode_bmap(dir, nf_pos >> dir->i_sb->s_blocksize_bits,
72 } else if (inode_bmap(dir, nf_pos >> dir->i_sb->s_blocksize_bits, 78 &epos, &eloc, &elen, &offset)
73 &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) { 79 != (EXT_RECORDED_ALLOCATED >> 30)) {
80 ret = -ENOENT;
81 goto out;
82 }
74 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 83 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
75 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { 84 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
76 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) 85 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
@@ -83,8 +92,8 @@ static int do_udf_readdir(struct inode *dir, struct file *filp,
83 } 92 }
84 93
85 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) { 94 if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) {
86 brelse(epos.bh); 95 ret = -EIO;
87 return -EIO; 96 goto out;
88 } 97 }
89 98
90 if (!(offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) { 99 if (!(offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) {
@@ -105,9 +114,6 @@ static int do_udf_readdir(struct inode *dir, struct file *filp,
105 brelse(bha[i]); 114 brelse(bha[i]);
106 } 115 }
107 } 116 }
108 } else {
109 brelse(epos.bh);
110 return -ENOENT;
111 } 117 }
112 118
113 while (nf_pos < size) { 119 while (nf_pos < size) {
@@ -115,13 +121,8 @@ static int do_udf_readdir(struct inode *dir, struct file *filp,
115 121
116 fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc, 122 fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc,
117 &elen, &offset); 123 &elen, &offset);
118 if (!fi) { 124 if (!fi)
119 if (fibh.sbh != fibh.ebh) 125 goto out;
120 brelse(fibh.ebh);
121 brelse(fibh.sbh);
122 brelse(epos.bh);
123 return 0;
124 }
125 126
126 liu = le16_to_cpu(cfi.lengthOfImpUse); 127 liu = le16_to_cpu(cfi.lengthOfImpUse);
127 lfi = cfi.lengthFileIdent; 128 lfi = cfi.lengthFileIdent;
@@ -167,53 +168,23 @@ static int do_udf_readdir(struct inode *dir, struct file *filp,
167 dt_type = DT_UNKNOWN; 168 dt_type = DT_UNKNOWN;
168 } 169 }
169 170
170 if (flen) { 171 if (flen && filldir(dirent, fname, flen, filp->f_pos,
171 if (filldir(dirent, fname, flen, filp->f_pos, iblock, dt_type) < 0) { 172 iblock, dt_type) < 0)
172 if (fibh.sbh != fibh.ebh) 173 goto out;
173 brelse(fibh.ebh);
174 brelse(fibh.sbh);
175 brelse(epos.bh);
176 return 0;
177 }
178 }
179 } /* end while */ 174 } /* end while */
180 175
181 filp->f_pos = (nf_pos >> 2) + 1; 176 filp->f_pos = (nf_pos >> 2) + 1;
182 177
178out:
183 if (fibh.sbh != fibh.ebh) 179 if (fibh.sbh != fibh.ebh)
184 brelse(fibh.ebh); 180 brelse(fibh.ebh);
185 brelse(fibh.sbh); 181 brelse(fibh.sbh);
186 brelse(epos.bh); 182 brelse(epos.bh);
183 kfree(fname);
187 184
188 return 0; 185 return ret;
189} 186}
190 187
191/*
192 * udf_readdir
193 *
194 * PURPOSE
195 * Read a directory entry.
196 *
197 * DESCRIPTION
198 * Optional - sys_getdents() will return -ENOTDIR if this routine is not
199 * available.
200 *
201 * Refer to sys_getdents() in fs/readdir.c
202 * sys_getdents() -> .
203 *
204 * PRE-CONDITIONS
205 * filp Pointer to directory file.
206 * buf Pointer to directory entry buffer.
207 * filldir Pointer to filldir function.
208 *
209 * POST-CONDITIONS
210 * <return> >=0 on success.
211 *
212 * HISTORY
213 * July 1, 1997 - Andrew E. Mileski
214 * Written, tested, and released.
215 */
216
217static int udf_readdir(struct file *filp, void *dirent, filldir_t filldir) 188static int udf_readdir(struct file *filp, void *dirent, filldir_t filldir)
218{ 189{
219 struct inode *dir = filp->f_path.dentry->d_inode; 190 struct inode *dir = filp->f_path.dentry->d_inode;
diff --git a/fs/udf/ecma_167.h b/fs/udf/ecma_167.h
index 56387711589b..a0974df82b31 100644
--- a/fs/udf/ecma_167.h
+++ b/fs/udf/ecma_167.h
@@ -70,19 +70,6 @@ typedef struct {
70 uint8_t microseconds; 70 uint8_t microseconds;
71} __attribute__ ((packed)) timestamp; 71} __attribute__ ((packed)) timestamp;
72 72
73typedef struct {
74 uint16_t typeAndTimezone;
75 int16_t year;
76 uint8_t month;
77 uint8_t day;
78 uint8_t hour;
79 uint8_t minute;
80 uint8_t second;
81 uint8_t centiseconds;
82 uint8_t hundredsOfMicroseconds;
83 uint8_t microseconds;
84} __attribute__ ((packed)) kernel_timestamp;
85
86/* Type and Time Zone (ECMA 167r3 1/7.3.1) */ 73/* Type and Time Zone (ECMA 167r3 1/7.3.1) */
87#define TIMESTAMP_TYPE_MASK 0xF000 74#define TIMESTAMP_TYPE_MASK 0xF000
88#define TIMESTAMP_TYPE_CUT 0x0000 75#define TIMESTAMP_TYPE_CUT 0x0000
diff --git a/fs/udf/file.c b/fs/udf/file.c
index 97c71ae7c689..0ed6e146a0d9 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -27,7 +27,6 @@
27 27
28#include "udfdecl.h" 28#include "udfdecl.h"
29#include <linux/fs.h> 29#include <linux/fs.h>
30#include <linux/udf_fs.h>
31#include <asm/uaccess.h> 30#include <asm/uaccess.h>
32#include <linux/kernel.h> 31#include <linux/kernel.h>
33#include <linux/string.h> /* memset */ 32#include <linux/string.h> /* memset */
@@ -144,40 +143,6 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
144 return retval; 143 return retval;
145} 144}
146 145
147/*
148 * udf_ioctl
149 *
150 * PURPOSE
151 * Issue an ioctl.
152 *
153 * DESCRIPTION
154 * Optional - sys_ioctl() will return -ENOTTY if this routine is not
155 * available, and the ioctl cannot be handled without filesystem help.
156 *
157 * sys_ioctl() handles these ioctls that apply only to regular files:
158 * FIBMAP [requires udf_block_map()], FIGETBSZ, FIONREAD
159 * These ioctls are also handled by sys_ioctl():
160 * FIOCLEX, FIONCLEX, FIONBIO, FIOASYNC
161 * All other ioctls are passed to the filesystem.
162 *
163 * Refer to sys_ioctl() in fs/ioctl.c
164 * sys_ioctl() -> .
165 *
166 * PRE-CONDITIONS
167 * inode Pointer to inode that ioctl was issued on.
168 * filp Pointer to file that ioctl was issued on.
169 * cmd The ioctl command.
170 * arg The ioctl argument [can be interpreted as a
171 * user-space pointer if desired].
172 *
173 * POST-CONDITIONS
174 * <return> Success (>=0) or an error code (<=0) that
175 * sys_ioctl() will return.
176 *
177 * HISTORY
178 * July 1, 1997 - Andrew E. Mileski
179 * Written, tested, and released.
180 */
181int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, 146int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
182 unsigned long arg) 147 unsigned long arg)
183{ 148{
@@ -225,18 +190,6 @@ int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
225 return result; 190 return result;
226} 191}
227 192
228/*
229 * udf_release_file
230 *
231 * PURPOSE
232 * Called when all references to the file are closed
233 *
234 * DESCRIPTION
235 * Discard prealloced blocks
236 *
237 * HISTORY
238 *
239 */
240static int udf_release_file(struct inode *inode, struct file *filp) 193static int udf_release_file(struct inode *inode, struct file *filp)
241{ 194{
242 if (filp->f_mode & FMODE_WRITE) { 195 if (filp->f_mode & FMODE_WRITE) {
diff --git a/fs/udf/ialloc.c b/fs/udf/ialloc.c
index 84360315aca2..eb9cfa23dc3d 100644
--- a/fs/udf/ialloc.c
+++ b/fs/udf/ialloc.c
@@ -21,7 +21,6 @@
21#include "udfdecl.h" 21#include "udfdecl.h"
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/quotaops.h> 23#include <linux/quotaops.h>
24#include <linux/udf_fs.h>
25#include <linux/sched.h> 24#include <linux/sched.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
27 26
@@ -47,11 +46,9 @@ void udf_free_inode(struct inode *inode)
47 struct logicalVolIntegrityDescImpUse *lvidiu = 46 struct logicalVolIntegrityDescImpUse *lvidiu =
48 udf_sb_lvidiu(sbi); 47 udf_sb_lvidiu(sbi);
49 if (S_ISDIR(inode->i_mode)) 48 if (S_ISDIR(inode->i_mode))
50 lvidiu->numDirs = 49 le32_add_cpu(&lvidiu->numDirs, -1);
51 cpu_to_le32(le32_to_cpu(lvidiu->numDirs) - 1);
52 else 50 else
53 lvidiu->numFiles = 51 le32_add_cpu(&lvidiu->numFiles, -1);
54 cpu_to_le32(le32_to_cpu(lvidiu->numFiles) - 1);
55 52
56 mark_buffer_dirty(sbi->s_lvid_bh); 53 mark_buffer_dirty(sbi->s_lvid_bh);
57 } 54 }
@@ -105,11 +102,9 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
105 lvhd = (struct logicalVolHeaderDesc *) 102 lvhd = (struct logicalVolHeaderDesc *)
106 (lvid->logicalVolContentsUse); 103 (lvid->logicalVolContentsUse);
107 if (S_ISDIR(mode)) 104 if (S_ISDIR(mode))
108 lvidiu->numDirs = 105 le32_add_cpu(&lvidiu->numDirs, 1);
109 cpu_to_le32(le32_to_cpu(lvidiu->numDirs) + 1);
110 else 106 else
111 lvidiu->numFiles = 107 le32_add_cpu(&lvidiu->numFiles, 1);
112 cpu_to_le32(le32_to_cpu(lvidiu->numFiles) + 1);
113 iinfo->i_unique = uniqueID = le64_to_cpu(lvhd->uniqueID); 108 iinfo->i_unique = uniqueID = le64_to_cpu(lvhd->uniqueID);
114 if (!(++uniqueID & 0x00000000FFFFFFFFUL)) 109 if (!(++uniqueID & 0x00000000FFFFFFFFUL))
115 uniqueID += 16; 110 uniqueID += 16;
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 24cfa55d0fdc..6e74b117aaf0 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -37,6 +37,7 @@
37#include <linux/buffer_head.h> 37#include <linux/buffer_head.h>
38#include <linux/writeback.h> 38#include <linux/writeback.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/crc-itu-t.h>
40 41
41#include "udf_i.h" 42#include "udf_i.h"
42#include "udf_sb.h" 43#include "udf_sb.h"
@@ -66,22 +67,7 @@ static void udf_update_extents(struct inode *,
66 struct extent_position *); 67 struct extent_position *);
67static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int); 68static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
68 69
69/* 70
70 * udf_delete_inode
71 *
72 * PURPOSE
73 * Clean-up before the specified inode is destroyed.
74 *
75 * DESCRIPTION
76 * This routine is called when the kernel destroys an inode structure
77 * ie. when iput() finds i_count == 0.
78 *
79 * HISTORY
80 * July 1, 1997 - Andrew E. Mileski
81 * Written, tested, and released.
82 *
83 * Called at the last iput() if i_nlink is zero.
84 */
85void udf_delete_inode(struct inode *inode) 71void udf_delete_inode(struct inode *inode)
86{ 72{
87 truncate_inode_pages(&inode->i_data, 0); 73 truncate_inode_pages(&inode->i_data, 0);
@@ -323,9 +309,6 @@ static int udf_get_block(struct inode *inode, sector_t block,
323 309
324 lock_kernel(); 310 lock_kernel();
325 311
326 if (block < 0)
327 goto abort_negative;
328
329 iinfo = UDF_I(inode); 312 iinfo = UDF_I(inode);
330 if (block == iinfo->i_next_alloc_block + 1) { 313 if (block == iinfo->i_next_alloc_block + 1) {
331 iinfo->i_next_alloc_block++; 314 iinfo->i_next_alloc_block++;
@@ -347,10 +330,6 @@ static int udf_get_block(struct inode *inode, sector_t block,
347abort: 330abort:
348 unlock_kernel(); 331 unlock_kernel();
349 return err; 332 return err;
350
351abort_negative:
352 udf_warning(inode->i_sb, "udf_get_block", "block < 0");
353 goto abort;
354} 333}
355 334
356static struct buffer_head *udf_getblk(struct inode *inode, long block, 335static struct buffer_head *udf_getblk(struct inode *inode, long block,
@@ -1116,42 +1095,36 @@ static void __udf_read_inode(struct inode *inode)
1116 fe = (struct fileEntry *)bh->b_data; 1095 fe = (struct fileEntry *)bh->b_data;
1117 1096
1118 if (fe->icbTag.strategyType == cpu_to_le16(4096)) { 1097 if (fe->icbTag.strategyType == cpu_to_le16(4096)) {
1119 struct buffer_head *ibh = NULL, *nbh = NULL; 1098 struct buffer_head *ibh;
1120 struct indirectEntry *ie;
1121 1099
1122 ibh = udf_read_ptagged(inode->i_sb, iinfo->i_location, 1, 1100 ibh = udf_read_ptagged(inode->i_sb, iinfo->i_location, 1,
1123 &ident); 1101 &ident);
1124 if (ident == TAG_IDENT_IE) { 1102 if (ident == TAG_IDENT_IE && ibh) {
1125 if (ibh) { 1103 struct buffer_head *nbh = NULL;
1126 kernel_lb_addr loc; 1104 kernel_lb_addr loc;
1127 ie = (struct indirectEntry *)ibh->b_data; 1105 struct indirectEntry *ie;
1128 1106
1129 loc = lelb_to_cpu(ie->indirectICB.extLocation); 1107 ie = (struct indirectEntry *)ibh->b_data;
1130 1108 loc = lelb_to_cpu(ie->indirectICB.extLocation);
1131 if (ie->indirectICB.extLength && 1109
1132 (nbh = udf_read_ptagged(inode->i_sb, loc, 0, 1110 if (ie->indirectICB.extLength &&
1133 &ident))) { 1111 (nbh = udf_read_ptagged(inode->i_sb, loc, 0,
1134 if (ident == TAG_IDENT_FE || 1112 &ident))) {
1135 ident == TAG_IDENT_EFE) { 1113 if (ident == TAG_IDENT_FE ||
1136 memcpy(&iinfo->i_location, 1114 ident == TAG_IDENT_EFE) {
1137 &loc, 1115 memcpy(&iinfo->i_location,
1138 sizeof(kernel_lb_addr)); 1116 &loc,
1139 brelse(bh); 1117 sizeof(kernel_lb_addr));
1140 brelse(ibh); 1118 brelse(bh);
1141 brelse(nbh);
1142 __udf_read_inode(inode);
1143 return;
1144 } else {
1145 brelse(nbh);
1146 brelse(ibh);
1147 }
1148 } else {
1149 brelse(ibh); 1119 brelse(ibh);
1120 brelse(nbh);
1121 __udf_read_inode(inode);
1122 return;
1150 } 1123 }
1124 brelse(nbh);
1151 } 1125 }
1152 } else {
1153 brelse(ibh);
1154 } 1126 }
1127 brelse(ibh);
1155 } else if (fe->icbTag.strategyType != cpu_to_le16(4)) { 1128 } else if (fe->icbTag.strategyType != cpu_to_le16(4)) {
1156 printk(KERN_ERR "udf: unsupported strategy type: %d\n", 1129 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
1157 le16_to_cpu(fe->icbTag.strategyType)); 1130 le16_to_cpu(fe->icbTag.strategyType));
@@ -1168,8 +1141,6 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1168{ 1141{
1169 struct fileEntry *fe; 1142 struct fileEntry *fe;
1170 struct extendedFileEntry *efe; 1143 struct extendedFileEntry *efe;
1171 time_t convtime;
1172 long convtime_usec;
1173 int offset; 1144 int offset;
1174 struct udf_sb_info *sbi = UDF_SB(inode->i_sb); 1145 struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
1175 struct udf_inode_info *iinfo = UDF_I(inode); 1146 struct udf_inode_info *iinfo = UDF_I(inode);
@@ -1257,29 +1228,15 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1257 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) << 1228 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
1258 (inode->i_sb->s_blocksize_bits - 9); 1229 (inode->i_sb->s_blocksize_bits - 9);
1259 1230
1260 if (udf_stamp_to_time(&convtime, &convtime_usec, 1231 if (!udf_disk_stamp_to_time(&inode->i_atime, fe->accessTime))
1261 lets_to_cpu(fe->accessTime))) {
1262 inode->i_atime.tv_sec = convtime;
1263 inode->i_atime.tv_nsec = convtime_usec * 1000;
1264 } else {
1265 inode->i_atime = sbi->s_record_time; 1232 inode->i_atime = sbi->s_record_time;
1266 }
1267 1233
1268 if (udf_stamp_to_time(&convtime, &convtime_usec, 1234 if (!udf_disk_stamp_to_time(&inode->i_mtime,
1269 lets_to_cpu(fe->modificationTime))) { 1235 fe->modificationTime))
1270 inode->i_mtime.tv_sec = convtime;
1271 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1272 } else {
1273 inode->i_mtime = sbi->s_record_time; 1236 inode->i_mtime = sbi->s_record_time;
1274 }
1275 1237
1276 if (udf_stamp_to_time(&convtime, &convtime_usec, 1238 if (!udf_disk_stamp_to_time(&inode->i_ctime, fe->attrTime))
1277 lets_to_cpu(fe->attrTime))) {
1278 inode->i_ctime.tv_sec = convtime;
1279 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1280 } else {
1281 inode->i_ctime = sbi->s_record_time; 1239 inode->i_ctime = sbi->s_record_time;
1282 }
1283 1240
1284 iinfo->i_unique = le64_to_cpu(fe->uniqueID); 1241 iinfo->i_unique = le64_to_cpu(fe->uniqueID);
1285 iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr); 1242 iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
@@ -1289,37 +1246,18 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1289 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) << 1246 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
1290 (inode->i_sb->s_blocksize_bits - 9); 1247 (inode->i_sb->s_blocksize_bits - 9);
1291 1248
1292 if (udf_stamp_to_time(&convtime, &convtime_usec, 1249 if (!udf_disk_stamp_to_time(&inode->i_atime, efe->accessTime))
1293 lets_to_cpu(efe->accessTime))) {
1294 inode->i_atime.tv_sec = convtime;
1295 inode->i_atime.tv_nsec = convtime_usec * 1000;
1296 } else {
1297 inode->i_atime = sbi->s_record_time; 1250 inode->i_atime = sbi->s_record_time;
1298 }
1299 1251
1300 if (udf_stamp_to_time(&convtime, &convtime_usec, 1252 if (!udf_disk_stamp_to_time(&inode->i_mtime,
1301 lets_to_cpu(efe->modificationTime))) { 1253 efe->modificationTime))
1302 inode->i_mtime.tv_sec = convtime;
1303 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1304 } else {
1305 inode->i_mtime = sbi->s_record_time; 1254 inode->i_mtime = sbi->s_record_time;
1306 }
1307 1255
1308 if (udf_stamp_to_time(&convtime, &convtime_usec, 1256 if (!udf_disk_stamp_to_time(&iinfo->i_crtime, efe->createTime))
1309 lets_to_cpu(efe->createTime))) {
1310 iinfo->i_crtime.tv_sec = convtime;
1311 iinfo->i_crtime.tv_nsec = convtime_usec * 1000;
1312 } else {
1313 iinfo->i_crtime = sbi->s_record_time; 1257 iinfo->i_crtime = sbi->s_record_time;
1314 }
1315 1258
1316 if (udf_stamp_to_time(&convtime, &convtime_usec, 1259 if (!udf_disk_stamp_to_time(&inode->i_ctime, efe->attrTime))
1317 lets_to_cpu(efe->attrTime))) {
1318 inode->i_ctime.tv_sec = convtime;
1319 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1320 } else {
1321 inode->i_ctime = sbi->s_record_time; 1260 inode->i_ctime = sbi->s_record_time;
1322 }
1323 1261
1324 iinfo->i_unique = le64_to_cpu(efe->uniqueID); 1262 iinfo->i_unique = le64_to_cpu(efe->uniqueID);
1325 iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr); 1263 iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
@@ -1338,6 +1276,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1338 case ICBTAG_FILE_TYPE_REALTIME: 1276 case ICBTAG_FILE_TYPE_REALTIME:
1339 case ICBTAG_FILE_TYPE_REGULAR: 1277 case ICBTAG_FILE_TYPE_REGULAR:
1340 case ICBTAG_FILE_TYPE_UNDEF: 1278 case ICBTAG_FILE_TYPE_UNDEF:
1279 case ICBTAG_FILE_TYPE_VAT20:
1341 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 1280 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
1342 inode->i_data.a_ops = &udf_adinicb_aops; 1281 inode->i_data.a_ops = &udf_adinicb_aops;
1343 else 1282 else
@@ -1363,6 +1302,15 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1363 inode->i_op = &page_symlink_inode_operations; 1302 inode->i_op = &page_symlink_inode_operations;
1364 inode->i_mode = S_IFLNK | S_IRWXUGO; 1303 inode->i_mode = S_IFLNK | S_IRWXUGO;
1365 break; 1304 break;
1305 case ICBTAG_FILE_TYPE_MAIN:
1306 udf_debug("METADATA FILE-----\n");
1307 break;
1308 case ICBTAG_FILE_TYPE_MIRROR:
1309 udf_debug("METADATA MIRROR FILE-----\n");
1310 break;
1311 case ICBTAG_FILE_TYPE_BITMAP:
1312 udf_debug("METADATA BITMAP FILE-----\n");
1313 break;
1366 default: 1314 default:
1367 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown " 1315 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown "
1368 "file type=%d\n", inode->i_ino, 1316 "file type=%d\n", inode->i_ino,
@@ -1416,21 +1364,6 @@ static mode_t udf_convert_permissions(struct fileEntry *fe)
1416 return mode; 1364 return mode;
1417} 1365}
1418 1366
1419/*
1420 * udf_write_inode
1421 *
1422 * PURPOSE
1423 * Write out the specified inode.
1424 *
1425 * DESCRIPTION
1426 * This routine is called whenever an inode is synced.
1427 * Currently this routine is just a placeholder.
1428 *
1429 * HISTORY
1430 * July 1, 1997 - Andrew E. Mileski
1431 * Written, tested, and released.
1432 */
1433
1434int udf_write_inode(struct inode *inode, int sync) 1367int udf_write_inode(struct inode *inode, int sync)
1435{ 1368{
1436 int ret; 1369 int ret;
@@ -1455,7 +1388,6 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1455 uint32_t udfperms; 1388 uint32_t udfperms;
1456 uint16_t icbflags; 1389 uint16_t icbflags;
1457 uint16_t crclen; 1390 uint16_t crclen;
1458 kernel_timestamp cpu_time;
1459 int err = 0; 1391 int err = 0;
1460 struct udf_sb_info *sbi = UDF_SB(inode->i_sb); 1392 struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
1461 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; 1393 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
@@ -1488,9 +1420,9 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1488 iinfo->i_location. 1420 iinfo->i_location.
1489 logicalBlockNum); 1421 logicalBlockNum);
1490 use->descTag.descCRCLength = cpu_to_le16(crclen); 1422 use->descTag.descCRCLength = cpu_to_le16(crclen);
1491 use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + 1423 use->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)use +
1492 sizeof(tag), crclen, 1424 sizeof(tag),
1493 0)); 1425 crclen));
1494 use->descTag.tagChecksum = udf_tag_checksum(&use->descTag); 1426 use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
1495 1427
1496 mark_buffer_dirty(bh); 1428 mark_buffer_dirty(bh);
@@ -1558,12 +1490,9 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1558 (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >> 1490 (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
1559 (blocksize_bits - 9)); 1491 (blocksize_bits - 9));
1560 1492
1561 if (udf_time_to_stamp(&cpu_time, inode->i_atime)) 1493 udf_time_to_disk_stamp(&fe->accessTime, inode->i_atime);
1562 fe->accessTime = cpu_to_lets(cpu_time); 1494 udf_time_to_disk_stamp(&fe->modificationTime, inode->i_mtime);
1563 if (udf_time_to_stamp(&cpu_time, inode->i_mtime)) 1495 udf_time_to_disk_stamp(&fe->attrTime, inode->i_ctime);
1564 fe->modificationTime = cpu_to_lets(cpu_time);
1565 if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
1566 fe->attrTime = cpu_to_lets(cpu_time);
1567 memset(&(fe->impIdent), 0, sizeof(regid)); 1496 memset(&(fe->impIdent), 0, sizeof(regid));
1568 strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER); 1497 strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
1569 fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; 1498 fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
@@ -1598,14 +1527,10 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1598 iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec)) 1527 iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
1599 iinfo->i_crtime = inode->i_ctime; 1528 iinfo->i_crtime = inode->i_ctime;
1600 1529
1601 if (udf_time_to_stamp(&cpu_time, inode->i_atime)) 1530 udf_time_to_disk_stamp(&efe->accessTime, inode->i_atime);
1602 efe->accessTime = cpu_to_lets(cpu_time); 1531 udf_time_to_disk_stamp(&efe->modificationTime, inode->i_mtime);
1603 if (udf_time_to_stamp(&cpu_time, inode->i_mtime)) 1532 udf_time_to_disk_stamp(&efe->createTime, iinfo->i_crtime);
1604 efe->modificationTime = cpu_to_lets(cpu_time); 1533 udf_time_to_disk_stamp(&efe->attrTime, inode->i_ctime);
1605 if (udf_time_to_stamp(&cpu_time, iinfo->i_crtime))
1606 efe->createTime = cpu_to_lets(cpu_time);
1607 if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
1608 efe->attrTime = cpu_to_lets(cpu_time);
1609 1534
1610 memset(&(efe->impIdent), 0, sizeof(regid)); 1535 memset(&(efe->impIdent), 0, sizeof(regid));
1611 strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER); 1536 strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
@@ -1660,8 +1585,8 @@ static int udf_update_inode(struct inode *inode, int do_sync)
1660 crclen += iinfo->i_lenEAttr + iinfo->i_lenAlloc - 1585 crclen += iinfo->i_lenEAttr + iinfo->i_lenAlloc -
1661 sizeof(tag); 1586 sizeof(tag);
1662 fe->descTag.descCRCLength = cpu_to_le16(crclen); 1587 fe->descTag.descCRCLength = cpu_to_le16(crclen);
1663 fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), 1588 fe->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)fe + sizeof(tag),
1664 crclen, 0)); 1589 crclen));
1665 fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag); 1590 fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
1666 1591
1667 /* write the data blocks */ 1592 /* write the data blocks */
@@ -1778,9 +1703,7 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1778 1703
1779 if (epos->bh) { 1704 if (epos->bh) {
1780 aed = (struct allocExtDesc *)epos->bh->b_data; 1705 aed = (struct allocExtDesc *)epos->bh->b_data;
1781 aed->lengthAllocDescs = 1706 le32_add_cpu(&aed->lengthAllocDescs, adsize);
1782 cpu_to_le32(le32_to_cpu(
1783 aed->lengthAllocDescs) + adsize);
1784 } else { 1707 } else {
1785 iinfo->i_lenAlloc += adsize; 1708 iinfo->i_lenAlloc += adsize;
1786 mark_inode_dirty(inode); 1709 mark_inode_dirty(inode);
@@ -1830,9 +1753,7 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1830 mark_inode_dirty(inode); 1753 mark_inode_dirty(inode);
1831 } else { 1754 } else {
1832 aed = (struct allocExtDesc *)epos->bh->b_data; 1755 aed = (struct allocExtDesc *)epos->bh->b_data;
1833 aed->lengthAllocDescs = 1756 le32_add_cpu(&aed->lengthAllocDescs, adsize);
1834 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) +
1835 adsize);
1836 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || 1757 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
1837 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) 1758 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
1838 udf_update_tag(epos->bh->b_data, 1759 udf_update_tag(epos->bh->b_data,
@@ -2046,9 +1967,7 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2046 mark_inode_dirty(inode); 1967 mark_inode_dirty(inode);
2047 } else { 1968 } else {
2048 aed = (struct allocExtDesc *)oepos.bh->b_data; 1969 aed = (struct allocExtDesc *)oepos.bh->b_data;
2049 aed->lengthAllocDescs = 1970 le32_add_cpu(&aed->lengthAllocDescs, -(2 * adsize));
2050 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2051 (2 * adsize));
2052 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || 1971 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2053 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) 1972 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
2054 udf_update_tag(oepos.bh->b_data, 1973 udf_update_tag(oepos.bh->b_data,
@@ -2065,9 +1984,7 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2065 mark_inode_dirty(inode); 1984 mark_inode_dirty(inode);
2066 } else { 1985 } else {
2067 aed = (struct allocExtDesc *)oepos.bh->b_data; 1986 aed = (struct allocExtDesc *)oepos.bh->b_data;
2068 aed->lengthAllocDescs = 1987 le32_add_cpu(&aed->lengthAllocDescs, -adsize);
2069 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2070 adsize);
2071 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || 1988 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
2072 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) 1989 UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
2073 udf_update_tag(oepos.bh->b_data, 1990 udf_update_tag(oepos.bh->b_data,
@@ -2095,11 +2012,6 @@ int8_t inode_bmap(struct inode *inode, sector_t block,
2095 int8_t etype; 2012 int8_t etype;
2096 struct udf_inode_info *iinfo; 2013 struct udf_inode_info *iinfo;
2097 2014
2098 if (block < 0) {
2099 printk(KERN_ERR "udf: inode_bmap: block < 0\n");
2100 return -1;
2101 }
2102
2103 iinfo = UDF_I(inode); 2015 iinfo = UDF_I(inode);
2104 pos->offset = 0; 2016 pos->offset = 0;
2105 pos->block = iinfo->i_location; 2017 pos->block = iinfo->i_location;
diff --git a/fs/udf/lowlevel.c b/fs/udf/lowlevel.c
index 579bae71e67e..703843f30ffd 100644
--- a/fs/udf/lowlevel.c
+++ b/fs/udf/lowlevel.c
@@ -23,7 +23,6 @@
23#include <linux/cdrom.h> 23#include <linux/cdrom.h>
24#include <asm/uaccess.h> 24#include <asm/uaccess.h>
25 25
26#include <linux/udf_fs.h>
27#include "udf_sb.h" 26#include "udf_sb.h"
28 27
29unsigned int udf_get_last_session(struct super_block *sb) 28unsigned int udf_get_last_session(struct super_block *sb)
diff --git a/fs/udf/misc.c b/fs/udf/misc.c
index a1d6da0caf71..84bf0fd4a4f1 100644
--- a/fs/udf/misc.c
+++ b/fs/udf/misc.c
@@ -23,8 +23,8 @@
23 23
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/udf_fs.h>
27#include <linux/buffer_head.h> 26#include <linux/buffer_head.h>
27#include <linux/crc-itu-t.h>
28 28
29#include "udf_i.h" 29#include "udf_i.h"
30#include "udf_sb.h" 30#include "udf_sb.h"
@@ -136,8 +136,8 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
136 /* rewrite CRC + checksum of eahd */ 136 /* rewrite CRC + checksum of eahd */
137 crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag); 137 crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag);
138 eahd->descTag.descCRCLength = cpu_to_le16(crclen); 138 eahd->descTag.descCRCLength = cpu_to_le16(crclen);
139 eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + 139 eahd->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)eahd +
140 sizeof(tag), crclen, 0)); 140 sizeof(tag), crclen));
141 eahd->descTag.tagChecksum = udf_tag_checksum(&eahd->descTag); 141 eahd->descTag.tagChecksum = udf_tag_checksum(&eahd->descTag);
142 iinfo->i_lenEAttr += size; 142 iinfo->i_lenEAttr += size;
143 return (struct genericFormat *)&ea[offset]; 143 return (struct genericFormat *)&ea[offset];
@@ -204,16 +204,15 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
204{ 204{
205 tag *tag_p; 205 tag *tag_p;
206 struct buffer_head *bh = NULL; 206 struct buffer_head *bh = NULL;
207 struct udf_sb_info *sbi = UDF_SB(sb);
208 207
209 /* Read the block */ 208 /* Read the block */
210 if (block == 0xFFFFFFFF) 209 if (block == 0xFFFFFFFF)
211 return NULL; 210 return NULL;
212 211
213 bh = udf_tread(sb, block + sbi->s_session); 212 bh = udf_tread(sb, block);
214 if (!bh) { 213 if (!bh) {
215 udf_debug("block=%d, location=%d: read failed\n", 214 udf_debug("block=%d, location=%d: read failed\n",
216 block + sbi->s_session, location); 215 block, location);
217 return NULL; 216 return NULL;
218 } 217 }
219 218
@@ -223,8 +222,7 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
223 222
224 if (location != le32_to_cpu(tag_p->tagLocation)) { 223 if (location != le32_to_cpu(tag_p->tagLocation)) {
225 udf_debug("location mismatch block %u, tag %u != %u\n", 224 udf_debug("location mismatch block %u, tag %u != %u\n",
226 block + sbi->s_session, 225 block, le32_to_cpu(tag_p->tagLocation), location);
227 le32_to_cpu(tag_p->tagLocation), location);
228 goto error_out; 226 goto error_out;
229 } 227 }
230 228
@@ -244,13 +242,13 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
244 242
245 /* Verify the descriptor CRC */ 243 /* Verify the descriptor CRC */
246 if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize || 244 if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize ||
247 le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag), 245 le16_to_cpu(tag_p->descCRC) == crc_itu_t(0,
248 le16_to_cpu(tag_p->descCRCLength), 0)) 246 bh->b_data + sizeof(tag),
247 le16_to_cpu(tag_p->descCRCLength)))
249 return bh; 248 return bh;
250 249
251 udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", 250 udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", block,
252 block + sbi->s_session, le16_to_cpu(tag_p->descCRC), 251 le16_to_cpu(tag_p->descCRC), le16_to_cpu(tag_p->descCRCLength));
253 le16_to_cpu(tag_p->descCRCLength));
254 252
255error_out: 253error_out:
256 brelse(bh); 254 brelse(bh);
@@ -270,7 +268,7 @@ void udf_update_tag(char *data, int length)
270 length -= sizeof(tag); 268 length -= sizeof(tag);
271 269
272 tptr->descCRCLength = cpu_to_le16(length); 270 tptr->descCRCLength = cpu_to_le16(length);
273 tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0)); 271 tptr->descCRC = cpu_to_le16(crc_itu_t(0, data + sizeof(tag), length));
274 tptr->tagChecksum = udf_tag_checksum(tptr); 272 tptr->tagChecksum = udf_tag_checksum(tptr);
275} 273}
276 274
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 112a5fb0b27b..ba5537d4bc15 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -31,6 +31,7 @@
31#include <linux/smp_lock.h> 31#include <linux/smp_lock.h>
32#include <linux/buffer_head.h> 32#include <linux/buffer_head.h>
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/crc-itu-t.h>
34 35
35static inline int udf_match(int len1, const char *name1, int len2, 36static inline int udf_match(int len1, const char *name1, int len2,
36 const char *name2) 37 const char *name2)
@@ -97,25 +98,23 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
97 memset(fibh->ebh->b_data, 0x00, padlen + offset); 98 memset(fibh->ebh->b_data, 0x00, padlen + offset);
98 } 99 }
99 100
100 crc = udf_crc((uint8_t *)cfi + sizeof(tag), 101 crc = crc_itu_t(0, (uint8_t *)cfi + sizeof(tag),
101 sizeof(struct fileIdentDesc) - sizeof(tag), 0); 102 sizeof(struct fileIdentDesc) - sizeof(tag));
102 103
103 if (fibh->sbh == fibh->ebh) { 104 if (fibh->sbh == fibh->ebh) {
104 crc = udf_crc((uint8_t *)sfi->impUse, 105 crc = crc_itu_t(crc, (uint8_t *)sfi->impUse,
105 crclen + sizeof(tag) - 106 crclen + sizeof(tag) -
106 sizeof(struct fileIdentDesc), crc); 107 sizeof(struct fileIdentDesc));
107 } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) { 108 } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) {
108 crc = udf_crc(fibh->ebh->b_data + 109 crc = crc_itu_t(crc, fibh->ebh->b_data +
109 sizeof(struct fileIdentDesc) + 110 sizeof(struct fileIdentDesc) +
110 fibh->soffset, 111 fibh->soffset,
111 crclen + sizeof(tag) - 112 crclen + sizeof(tag) -
112 sizeof(struct fileIdentDesc), 113 sizeof(struct fileIdentDesc));
113 crc);
114 } else { 114 } else {
115 crc = udf_crc((uint8_t *)sfi->impUse, 115 crc = crc_itu_t(crc, (uint8_t *)sfi->impUse,
116 -fibh->soffset - sizeof(struct fileIdentDesc), 116 -fibh->soffset - sizeof(struct fileIdentDesc));
117 crc); 117 crc = crc_itu_t(crc, fibh->ebh->b_data, fibh->eoffset);
118 crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc);
119 } 118 }
120 119
121 cfi->descTag.descCRC = cpu_to_le16(crc); 120 cfi->descTag.descCRC = cpu_to_le16(crc);
@@ -149,7 +148,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
149 struct fileIdentDesc *fi = NULL; 148 struct fileIdentDesc *fi = NULL;
150 loff_t f_pos; 149 loff_t f_pos;
151 int block, flen; 150 int block, flen;
152 char fname[UDF_NAME_LEN]; 151 char *fname = NULL;
153 char *nameptr; 152 char *nameptr;
154 uint8_t lfi; 153 uint8_t lfi;
155 uint16_t liu; 154 uint16_t liu;
@@ -163,12 +162,12 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
163 size = udf_ext0_offset(dir) + dir->i_size; 162 size = udf_ext0_offset(dir) + dir->i_size;
164 f_pos = udf_ext0_offset(dir); 163 f_pos = udf_ext0_offset(dir);
165 164
165 fibh->sbh = fibh->ebh = NULL;
166 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1); 166 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
167 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 167 if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
168 fibh->sbh = fibh->ebh = NULL; 168 if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, &epos,
169 else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, 169 &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30))
170 &epos, &eloc, &elen, &offset) == 170 goto out_err;
171 (EXT_RECORDED_ALLOCATED >> 30)) {
172 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 171 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
173 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { 172 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
174 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) 173 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
@@ -179,25 +178,19 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
179 offset = 0; 178 offset = 0;
180 179
181 fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); 180 fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
182 if (!fibh->sbh) { 181 if (!fibh->sbh)
183 brelse(epos.bh); 182 goto out_err;
184 return NULL;
185 }
186 } else {
187 brelse(epos.bh);
188 return NULL;
189 } 183 }
190 184
185 fname = kmalloc(UDF_NAME_LEN, GFP_NOFS);
186 if (!fname)
187 goto out_err;
188
191 while (f_pos < size) { 189 while (f_pos < size) {
192 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, 190 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
193 &elen, &offset); 191 &elen, &offset);
194 if (!fi) { 192 if (!fi)
195 if (fibh->sbh != fibh->ebh) 193 goto out_err;
196 brelse(fibh->ebh);
197 brelse(fibh->sbh);
198 brelse(epos.bh);
199 return NULL;
200 }
201 194
202 liu = le16_to_cpu(cfi->lengthOfImpUse); 195 liu = le16_to_cpu(cfi->lengthOfImpUse);
203 lfi = cfi->lengthFileIdent; 196 lfi = cfi->lengthFileIdent;
@@ -237,53 +230,22 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
237 230
238 flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); 231 flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
239 if (flen && udf_match(flen, fname, dentry->d_name.len, 232 if (flen && udf_match(flen, fname, dentry->d_name.len,
240 dentry->d_name.name)) { 233 dentry->d_name.name))
241 brelse(epos.bh); 234 goto out_ok;
242 return fi;
243 }
244 } 235 }
245 236
237out_err:
238 fi = NULL;
246 if (fibh->sbh != fibh->ebh) 239 if (fibh->sbh != fibh->ebh)
247 brelse(fibh->ebh); 240 brelse(fibh->ebh);
248 brelse(fibh->sbh); 241 brelse(fibh->sbh);
242out_ok:
249 brelse(epos.bh); 243 brelse(epos.bh);
244 kfree(fname);
250 245
251 return NULL; 246 return fi;
252} 247}
253 248
254/*
255 * udf_lookup
256 *
257 * PURPOSE
258 * Look-up the inode for a given name.
259 *
260 * DESCRIPTION
261 * Required - lookup_dentry() will return -ENOTDIR if this routine is not
262 * available for a directory. The filesystem is useless if this routine is
263 * not available for at least the filesystem's root directory.
264 *
265 * This routine is passed an incomplete dentry - it must be completed by
266 * calling d_add(dentry, inode). If the name does not exist, then the
267 * specified inode must be set to null. An error should only be returned
268 * when the lookup fails for a reason other than the name not existing.
269 * Note that the directory inode semaphore is held during the call.
270 *
271 * Refer to lookup_dentry() in fs/namei.c
272 * lookup_dentry() -> lookup() -> real_lookup() -> .
273 *
274 * PRE-CONDITIONS
275 * dir Pointer to inode of parent directory.
276 * dentry Pointer to dentry to complete.
277 * nd Pointer to lookup nameidata
278 *
279 * POST-CONDITIONS
280 * <return> Zero on success.
281 *
282 * HISTORY
283 * July 1, 1997 - Andrew E. Mileski
284 * Written, tested, and released.
285 */
286
287static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, 249static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
288 struct nameidata *nd) 250 struct nameidata *nd)
289{ 251{
@@ -336,11 +298,9 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
336{ 298{
337 struct super_block *sb = dir->i_sb; 299 struct super_block *sb = dir->i_sb;
338 struct fileIdentDesc *fi = NULL; 300 struct fileIdentDesc *fi = NULL;
339 char name[UDF_NAME_LEN], fname[UDF_NAME_LEN]; 301 char *name = NULL;
340 int namelen; 302 int namelen;
341 loff_t f_pos; 303 loff_t f_pos;
342 int flen;
343 char *nameptr;
344 loff_t size = udf_ext0_offset(dir) + dir->i_size; 304 loff_t size = udf_ext0_offset(dir) + dir->i_size;
345 int nfidlen; 305 int nfidlen;
346 uint8_t lfi; 306 uint8_t lfi;
@@ -352,16 +312,23 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
352 struct extent_position epos = {}; 312 struct extent_position epos = {};
353 struct udf_inode_info *dinfo; 313 struct udf_inode_info *dinfo;
354 314
315 fibh->sbh = fibh->ebh = NULL;
316 name = kmalloc(UDF_NAME_LEN, GFP_NOFS);
317 if (!name) {
318 *err = -ENOMEM;
319 goto out_err;
320 }
321
355 if (dentry) { 322 if (dentry) {
356 if (!dentry->d_name.len) { 323 if (!dentry->d_name.len) {
357 *err = -EINVAL; 324 *err = -EINVAL;
358 return NULL; 325 goto out_err;
359 } 326 }
360 namelen = udf_put_filename(sb, dentry->d_name.name, name, 327 namelen = udf_put_filename(sb, dentry->d_name.name, name,
361 dentry->d_name.len); 328 dentry->d_name.len);
362 if (!namelen) { 329 if (!namelen) {
363 *err = -ENAMETOOLONG; 330 *err = -ENAMETOOLONG;
364 return NULL; 331 goto out_err;
365 } 332 }
366 } else { 333 } else {
367 namelen = 0; 334 namelen = 0;
@@ -373,11 +340,14 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
373 340
374 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1); 341 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
375 dinfo = UDF_I(dir); 342 dinfo = UDF_I(dir);
376 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 343 if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
377 fibh->sbh = fibh->ebh = NULL; 344 if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, &epos,
378 else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, 345 &eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30)) {
379 &epos, &eloc, &elen, &offset) == 346 block = udf_get_lb_pblock(dir->i_sb,
380 (EXT_RECORDED_ALLOCATED >> 30)) { 347 dinfo->i_location, 0);
348 fibh->soffset = fibh->eoffset = sb->s_blocksize;
349 goto add;
350 }
381 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 351 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
382 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) { 352 if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
383 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) 353 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
@@ -389,17 +359,11 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
389 359
390 fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block); 360 fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
391 if (!fibh->sbh) { 361 if (!fibh->sbh) {
392 brelse(epos.bh);
393 *err = -EIO; 362 *err = -EIO;
394 return NULL; 363 goto out_err;
395 } 364 }
396 365
397 block = dinfo->i_location.logicalBlockNum; 366 block = dinfo->i_location.logicalBlockNum;
398 } else {
399 block = udf_get_lb_pblock(dir->i_sb, dinfo->i_location, 0);
400 fibh->sbh = fibh->ebh = NULL;
401 fibh->soffset = fibh->eoffset = sb->s_blocksize;
402 goto add;
403 } 367 }
404 368
405 while (f_pos < size) { 369 while (f_pos < size) {
@@ -407,41 +371,16 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
407 &elen, &offset); 371 &elen, &offset);
408 372
409 if (!fi) { 373 if (!fi) {
410 if (fibh->sbh != fibh->ebh)
411 brelse(fibh->ebh);
412 brelse(fibh->sbh);
413 brelse(epos.bh);
414 *err = -EIO; 374 *err = -EIO;
415 return NULL; 375 goto out_err;
416 } 376 }
417 377
418 liu = le16_to_cpu(cfi->lengthOfImpUse); 378 liu = le16_to_cpu(cfi->lengthOfImpUse);
419 lfi = cfi->lengthFileIdent; 379 lfi = cfi->lengthFileIdent;
420 380
421 if (fibh->sbh == fibh->ebh)
422 nameptr = fi->fileIdent + liu;
423 else {
424 int poffset; /* Unpaded ending offset */
425
426 poffset = fibh->soffset + sizeof(struct fileIdentDesc) +
427 liu + lfi;
428
429 if (poffset >= lfi)
430 nameptr = (char *)(fibh->ebh->b_data +
431 poffset - lfi);
432 else {
433 nameptr = fname;
434 memcpy(nameptr, fi->fileIdent + liu,
435 lfi - poffset);
436 memcpy(nameptr + lfi - poffset,
437 fibh->ebh->b_data, poffset);
438 }
439 }
440
441 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { 381 if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
442 if (((sizeof(struct fileIdentDesc) + 382 if (((sizeof(struct fileIdentDesc) +
443 liu + lfi + 3) & ~3) == nfidlen) { 383 liu + lfi + 3) & ~3) == nfidlen) {
444 brelse(epos.bh);
445 cfi->descTag.tagSerialNum = cpu_to_le16(1); 384 cfi->descTag.tagSerialNum = cpu_to_le16(1);
446 cfi->fileVersionNum = cpu_to_le16(1); 385 cfi->fileVersionNum = cpu_to_le16(1);
447 cfi->fileCharacteristics = 0; 386 cfi->fileCharacteristics = 0;
@@ -449,27 +388,13 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
449 cfi->lengthOfImpUse = cpu_to_le16(0); 388 cfi->lengthOfImpUse = cpu_to_le16(0);
450 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, 389 if (!udf_write_fi(dir, cfi, fi, fibh, NULL,
451 name)) 390 name))
452 return fi; 391 goto out_ok;
453 else { 392 else {
454 *err = -EIO; 393 *err = -EIO;
455 return NULL; 394 goto out_err;
456 } 395 }
457 } 396 }
458 } 397 }
459
460 if (!lfi || !dentry)
461 continue;
462
463 flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
464 if (flen && udf_match(flen, fname, dentry->d_name.len,
465 dentry->d_name.name)) {
466 if (fibh->sbh != fibh->ebh)
467 brelse(fibh->ebh);
468 brelse(fibh->sbh);
469 brelse(epos.bh);
470 *err = -EEXIST;
471 return NULL;
472 }
473 } 398 }
474 399
475add: 400add:
@@ -496,7 +421,7 @@ add:
496 fibh->sbh = fibh->ebh = 421 fibh->sbh = fibh->ebh =
497 udf_expand_dir_adinicb(dir, &block, err); 422 udf_expand_dir_adinicb(dir, &block, err);
498 if (!fibh->sbh) 423 if (!fibh->sbh)
499 return NULL; 424 goto out_err;
500 epos.block = dinfo->i_location; 425 epos.block = dinfo->i_location;
501 epos.offset = udf_file_entry_alloc_offset(dir); 426 epos.offset = udf_file_entry_alloc_offset(dir);
502 /* Load extent udf_expand_dir_adinicb() has created */ 427 /* Load extent udf_expand_dir_adinicb() has created */
@@ -537,11 +462,8 @@ add:
537 dir->i_sb->s_blocksize_bits); 462 dir->i_sb->s_blocksize_bits);
538 fibh->ebh = udf_bread(dir, 463 fibh->ebh = udf_bread(dir,
539 f_pos >> dir->i_sb->s_blocksize_bits, 1, err); 464 f_pos >> dir->i_sb->s_blocksize_bits, 1, err);
540 if (!fibh->ebh) { 465 if (!fibh->ebh)
541 brelse(epos.bh); 466 goto out_err;
542 brelse(fibh->sbh);
543 return NULL;
544 }
545 467
546 if (!fibh->soffset) { 468 if (!fibh->soffset) {
547 if (udf_next_aext(dir, &epos, &eloc, &elen, 1) == 469 if (udf_next_aext(dir, &epos, &eloc, &elen, 1) ==
@@ -572,20 +494,25 @@ add:
572 cfi->lengthFileIdent = namelen; 494 cfi->lengthFileIdent = namelen;
573 cfi->lengthOfImpUse = cpu_to_le16(0); 495 cfi->lengthOfImpUse = cpu_to_le16(0);
574 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) { 496 if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) {
575 brelse(epos.bh);
576 dir->i_size += nfidlen; 497 dir->i_size += nfidlen;
577 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 498 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
578 dinfo->i_lenAlloc += nfidlen; 499 dinfo->i_lenAlloc += nfidlen;
579 mark_inode_dirty(dir); 500 mark_inode_dirty(dir);
580 return fi; 501 goto out_ok;
581 } else { 502 } else {
582 brelse(epos.bh);
583 if (fibh->sbh != fibh->ebh)
584 brelse(fibh->ebh);
585 brelse(fibh->sbh);
586 *err = -EIO; 503 *err = -EIO;
587 return NULL; 504 goto out_err;
588 } 505 }
506
507out_err:
508 fi = NULL;
509 if (fibh->sbh != fibh->ebh)
510 brelse(fibh->ebh);
511 brelse(fibh->sbh);
512out_ok:
513 brelse(epos.bh);
514 kfree(name);
515 return fi;
589} 516}
590 517
591static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi, 518static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi,
@@ -940,7 +867,7 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
940 char *ea; 867 char *ea;
941 int err; 868 int err;
942 int block; 869 int block;
943 char name[UDF_NAME_LEN]; 870 char *name = NULL;
944 int namelen; 871 int namelen;
945 struct buffer_head *bh; 872 struct buffer_head *bh;
946 struct udf_inode_info *iinfo; 873 struct udf_inode_info *iinfo;
@@ -950,6 +877,12 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
950 if (!inode) 877 if (!inode)
951 goto out; 878 goto out;
952 879
880 name = kmalloc(UDF_NAME_LEN, GFP_NOFS);
881 if (!name) {
882 err = -ENOMEM;
883 goto out_no_entry;
884 }
885
953 iinfo = UDF_I(inode); 886 iinfo = UDF_I(inode);
954 inode->i_mode = S_IFLNK | S_IRWXUGO; 887 inode->i_mode = S_IFLNK | S_IRWXUGO;
955 inode->i_data.a_ops = &udf_symlink_aops; 888 inode->i_data.a_ops = &udf_symlink_aops;
@@ -1089,6 +1022,7 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
1089 err = 0; 1022 err = 0;
1090 1023
1091out: 1024out:
1025 kfree(name);
1092 unlock_kernel(); 1026 unlock_kernel();
1093 return err; 1027 return err;
1094 1028
diff --git a/fs/udf/partition.c b/fs/udf/partition.c
index fc533345ab89..63610f026ae1 100644
--- a/fs/udf/partition.c
+++ b/fs/udf/partition.c
@@ -24,7 +24,6 @@
24 24
25#include <linux/fs.h> 25#include <linux/fs.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/udf_fs.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include <linux/buffer_head.h> 28#include <linux/buffer_head.h>
30 29
@@ -55,11 +54,10 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
55 struct udf_sb_info *sbi = UDF_SB(sb); 54 struct udf_sb_info *sbi = UDF_SB(sb);
56 struct udf_part_map *map; 55 struct udf_part_map *map;
57 struct udf_virtual_data *vdata; 56 struct udf_virtual_data *vdata;
58 struct udf_inode_info *iinfo; 57 struct udf_inode_info *iinfo = UDF_I(sbi->s_vat_inode);
59 58
60 map = &sbi->s_partmaps[partition]; 59 map = &sbi->s_partmaps[partition];
61 vdata = &map->s_type_specific.s_virtual; 60 vdata = &map->s_type_specific.s_virtual;
62 index = (sb->s_blocksize - vdata->s_start_offset) / sizeof(uint32_t);
63 61
64 if (block > vdata->s_num_entries) { 62 if (block > vdata->s_num_entries) {
65 udf_debug("Trying to access block beyond end of VAT " 63 udf_debug("Trying to access block beyond end of VAT "
@@ -67,6 +65,12 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
67 return 0xFFFFFFFF; 65 return 0xFFFFFFFF;
68 } 66 }
69 67
68 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
69 loc = le32_to_cpu(((__le32 *)(iinfo->i_ext.i_data +
70 vdata->s_start_offset))[block]);
71 goto translate;
72 }
73 index = (sb->s_blocksize - vdata->s_start_offset) / sizeof(uint32_t);
70 if (block >= index) { 74 if (block >= index) {
71 block -= index; 75 block -= index;
72 newblock = 1 + (block / (sb->s_blocksize / sizeof(uint32_t))); 76 newblock = 1 + (block / (sb->s_blocksize / sizeof(uint32_t)));
@@ -89,7 +93,7 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
89 93
90 brelse(bh); 94 brelse(bh);
91 95
92 iinfo = UDF_I(sbi->s_vat_inode); 96translate:
93 if (iinfo->i_location.partitionReferenceNum == partition) { 97 if (iinfo->i_location.partitionReferenceNum == partition) {
94 udf_debug("recursive call to udf_get_pblock!\n"); 98 udf_debug("recursive call to udf_get_pblock!\n");
95 return 0xFFFFFFFF; 99 return 0xFFFFFFFF;
@@ -263,3 +267,58 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
263 267
264 return 0; 268 return 0;
265} 269}
270
271static uint32_t udf_try_read_meta(struct inode *inode, uint32_t block,
272 uint16_t partition, uint32_t offset)
273{
274 struct super_block *sb = inode->i_sb;
275 struct udf_part_map *map;
276 kernel_lb_addr eloc;
277 uint32_t elen;
278 sector_t ext_offset;
279 struct extent_position epos = {};
280 uint32_t phyblock;
281
282 if (inode_bmap(inode, block, &epos, &eloc, &elen, &ext_offset) !=
283 (EXT_RECORDED_ALLOCATED >> 30))
284 phyblock = 0xFFFFFFFF;
285 else {
286 map = &UDF_SB(sb)->s_partmaps[partition];
287 /* map to sparable/physical partition desc */
288 phyblock = udf_get_pblock(sb, eloc.logicalBlockNum,
289 map->s_partition_num, ext_offset + offset);
290 }
291
292 brelse(epos.bh);
293 return phyblock;
294}
295
296uint32_t udf_get_pblock_meta25(struct super_block *sb, uint32_t block,
297 uint16_t partition, uint32_t offset)
298{
299 struct udf_sb_info *sbi = UDF_SB(sb);
300 struct udf_part_map *map;
301 struct udf_meta_data *mdata;
302 uint32_t retblk;
303 struct inode *inode;
304
305 udf_debug("READING from METADATA\n");
306
307 map = &sbi->s_partmaps[partition];
308 mdata = &map->s_type_specific.s_metadata;
309 inode = mdata->s_metadata_fe ? : mdata->s_mirror_fe;
310
311 /* We shouldn't mount such media... */
312 BUG_ON(!inode);
313 retblk = udf_try_read_meta(inode, block, partition, offset);
314 if (retblk == 0xFFFFFFFF) {
315 udf_warning(sb, __func__, "error reading from METADATA, "
316 "trying to read from MIRROR");
317 inode = mdata->s_mirror_fe;
318 if (!inode)
319 return 0xFFFFFFFF;
320 retblk = udf_try_read_meta(inode, block, partition, offset);
321 }
322
323 return retblk;
324}
diff --git a/fs/udf/super.c b/fs/udf/super.c
index f3ac4abfc946..b564fc140fe4 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -55,9 +55,10 @@
55#include <linux/errno.h> 55#include <linux/errno.h>
56#include <linux/mount.h> 56#include <linux/mount.h>
57#include <linux/seq_file.h> 57#include <linux/seq_file.h>
58#include <linux/bitmap.h>
59#include <linux/crc-itu-t.h>
58#include <asm/byteorder.h> 60#include <asm/byteorder.h>
59 61
60#include <linux/udf_fs.h>
61#include "udf_sb.h" 62#include "udf_sb.h"
62#include "udf_i.h" 63#include "udf_i.h"
63 64
@@ -84,22 +85,19 @@ static void udf_write_super(struct super_block *);
84static int udf_remount_fs(struct super_block *, int *, char *); 85static int udf_remount_fs(struct super_block *, int *, char *);
85static int udf_check_valid(struct super_block *, int, int); 86static int udf_check_valid(struct super_block *, int, int);
86static int udf_vrs(struct super_block *sb, int silent); 87static int udf_vrs(struct super_block *sb, int silent);
87static int udf_load_partition(struct super_block *, kernel_lb_addr *);
88static int udf_load_logicalvol(struct super_block *, struct buffer_head *,
89 kernel_lb_addr *);
90static void udf_load_logicalvolint(struct super_block *, kernel_extent_ad); 88static void udf_load_logicalvolint(struct super_block *, kernel_extent_ad);
91static void udf_find_anchor(struct super_block *); 89static void udf_find_anchor(struct super_block *);
92static int udf_find_fileset(struct super_block *, kernel_lb_addr *, 90static int udf_find_fileset(struct super_block *, kernel_lb_addr *,
93 kernel_lb_addr *); 91 kernel_lb_addr *);
94static void udf_load_pvoldesc(struct super_block *, struct buffer_head *);
95static void udf_load_fileset(struct super_block *, struct buffer_head *, 92static void udf_load_fileset(struct super_block *, struct buffer_head *,
96 kernel_lb_addr *); 93 kernel_lb_addr *);
97static int udf_load_partdesc(struct super_block *, struct buffer_head *);
98static void udf_open_lvid(struct super_block *); 94static void udf_open_lvid(struct super_block *);
99static void udf_close_lvid(struct super_block *); 95static void udf_close_lvid(struct super_block *);
100static unsigned int udf_count_free(struct super_block *); 96static unsigned int udf_count_free(struct super_block *);
101static int udf_statfs(struct dentry *, struct kstatfs *); 97static int udf_statfs(struct dentry *, struct kstatfs *);
102static int udf_show_options(struct seq_file *, struct vfsmount *); 98static int udf_show_options(struct seq_file *, struct vfsmount *);
99static void udf_error(struct super_block *sb, const char *function,
100 const char *fmt, ...);
103 101
104struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi) 102struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi)
105{ 103{
@@ -587,48 +585,10 @@ static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
587 return 0; 585 return 0;
588} 586}
589 587
590/*
591 * udf_set_blocksize
592 *
593 * PURPOSE
594 * Set the block size to be used in all transfers.
595 *
596 * DESCRIPTION
597 * To allow room for a DMA transfer, it is best to guess big when unsure.
598 * This routine picks 2048 bytes as the blocksize when guessing. This
599 * should be adequate until devices with larger block sizes become common.
600 *
601 * Note that the Linux kernel can currently only deal with blocksizes of
602 * 512, 1024, 2048, 4096, and 8192 bytes.
603 *
604 * PRE-CONDITIONS
605 * sb Pointer to _locked_ superblock.
606 *
607 * POST-CONDITIONS
608 * sb->s_blocksize Blocksize.
609 * sb->s_blocksize_bits log2 of blocksize.
610 * <return> 0 Blocksize is valid.
611 * <return> 1 Blocksize is invalid.
612 *
613 * HISTORY
614 * July 1, 1997 - Andrew E. Mileski
615 * Written, tested, and released.
616 */
617static int udf_set_blocksize(struct super_block *sb, int bsize)
618{
619 if (!sb_min_blocksize(sb, bsize)) {
620 udf_debug("Bad block size (%d)\n", bsize);
621 printk(KERN_ERR "udf: bad block size (%d)\n", bsize);
622 return 0;
623 }
624
625 return sb->s_blocksize;
626}
627
628static int udf_vrs(struct super_block *sb, int silent) 588static int udf_vrs(struct super_block *sb, int silent)
629{ 589{
630 struct volStructDesc *vsd = NULL; 590 struct volStructDesc *vsd = NULL;
631 int sector = 32768; 591 loff_t sector = 32768;
632 int sectorsize; 592 int sectorsize;
633 struct buffer_head *bh = NULL; 593 struct buffer_head *bh = NULL;
634 int iso9660 = 0; 594 int iso9660 = 0;
@@ -649,7 +609,8 @@ static int udf_vrs(struct super_block *sb, int silent)
649 sector += (sbi->s_session << sb->s_blocksize_bits); 609 sector += (sbi->s_session << sb->s_blocksize_bits);
650 610
651 udf_debug("Starting at sector %u (%ld byte sectors)\n", 611 udf_debug("Starting at sector %u (%ld byte sectors)\n",
652 (sector >> sb->s_blocksize_bits), sb->s_blocksize); 612 (unsigned int)(sector >> sb->s_blocksize_bits),
613 sb->s_blocksize);
653 /* Process the sequence (if applicable) */ 614 /* Process the sequence (if applicable) */
654 for (; !nsr02 && !nsr03; sector += sectorsize) { 615 for (; !nsr02 && !nsr03; sector += sectorsize) {
655 /* Read a block */ 616 /* Read a block */
@@ -719,162 +680,140 @@ static int udf_vrs(struct super_block *sb, int silent)
719} 680}
720 681
721/* 682/*
722 * udf_find_anchor 683 * Check whether there is an anchor block in the given block
723 *
724 * PURPOSE
725 * Find an anchor volume descriptor.
726 *
727 * PRE-CONDITIONS
728 * sb Pointer to _locked_ superblock.
729 * lastblock Last block on media.
730 *
731 * POST-CONDITIONS
732 * <return> 1 if not found, 0 if ok
733 *
734 * HISTORY
735 * July 1, 1997 - Andrew E. Mileski
736 * Written, tested, and released.
737 */ 684 */
738static void udf_find_anchor(struct super_block *sb) 685static int udf_check_anchor_block(struct super_block *sb, sector_t block,
686 bool varconv)
739{ 687{
740 int lastblock;
741 struct buffer_head *bh = NULL; 688 struct buffer_head *bh = NULL;
689 tag *t;
742 uint16_t ident; 690 uint16_t ident;
743 uint32_t location; 691 uint32_t location;
744 int i;
745 struct udf_sb_info *sbi;
746 692
747 sbi = UDF_SB(sb); 693 if (varconv) {
748 lastblock = sbi->s_last_block; 694 if (udf_fixed_to_variable(block) >=
695 sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits)
696 return 0;
697 bh = sb_bread(sb, udf_fixed_to_variable(block));
698 }
699 else
700 bh = sb_bread(sb, block);
749 701
750 if (lastblock) { 702 if (!bh)
751 int varlastblock = udf_variable_to_fixed(lastblock); 703 return 0;
752 int last[] = { lastblock, lastblock - 2,
753 lastblock - 150, lastblock - 152,
754 varlastblock, varlastblock - 2,
755 varlastblock - 150, varlastblock - 152 };
756
757 lastblock = 0;
758
759 /* Search for an anchor volume descriptor pointer */
760
761 /* according to spec, anchor is in either:
762 * block 256
763 * lastblock-256
764 * lastblock
765 * however, if the disc isn't closed, it could be 512 */
766
767 for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
768 ident = location = 0;
769 if (last[i] >= 0) {
770 bh = sb_bread(sb, last[i]);
771 if (bh) {
772 tag *t = (tag *)bh->b_data;
773 ident = le16_to_cpu(t->tagIdent);
774 location = le32_to_cpu(t->tagLocation);
775 brelse(bh);
776 }
777 }
778 704
779 if (ident == TAG_IDENT_AVDP) { 705 t = (tag *)bh->b_data;
780 if (location == last[i] - sbi->s_session) { 706 ident = le16_to_cpu(t->tagIdent);
781 lastblock = last[i] - sbi->s_session; 707 location = le32_to_cpu(t->tagLocation);
782 sbi->s_anchor[0] = lastblock; 708 brelse(bh);
783 sbi->s_anchor[1] = lastblock - 256; 709 if (ident != TAG_IDENT_AVDP)
784 } else if (location == 710 return 0;
785 udf_variable_to_fixed(last[i]) - 711 return location == block;
786 sbi->s_session) { 712}
787 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
788 lastblock =
789 udf_variable_to_fixed(last[i]) -
790 sbi->s_session;
791 sbi->s_anchor[0] = lastblock;
792 sbi->s_anchor[1] = lastblock - 256 -
793 sbi->s_session;
794 } else {
795 udf_debug("Anchor found at block %d, "
796 "location mismatch %d.\n",
797 last[i], location);
798 }
799 } else if (ident == TAG_IDENT_FE ||
800 ident == TAG_IDENT_EFE) {
801 lastblock = last[i];
802 sbi->s_anchor[3] = 512;
803 } else {
804 ident = location = 0;
805 if (last[i] >= 256) {
806 bh = sb_bread(sb, last[i] - 256);
807 if (bh) {
808 tag *t = (tag *)bh->b_data;
809 ident = le16_to_cpu(
810 t->tagIdent);
811 location = le32_to_cpu(
812 t->tagLocation);
813 brelse(bh);
814 }
815 }
816 713
817 if (ident == TAG_IDENT_AVDP && 714/* Search for an anchor volume descriptor pointer */
818 location == last[i] - 256 - 715static sector_t udf_scan_anchors(struct super_block *sb, bool varconv,
819 sbi->s_session) { 716 sector_t lastblock)
820 lastblock = last[i]; 717{
821 sbi->s_anchor[1] = last[i] - 256; 718 sector_t last[6];
822 } else { 719 int i;
823 ident = location = 0; 720 struct udf_sb_info *sbi = UDF_SB(sb);
824 if (last[i] >= 312 + sbi->s_session) {
825 bh = sb_bread(sb,
826 last[i] - 312 -
827 sbi->s_session);
828 if (bh) {
829 tag *t = (tag *)
830 bh->b_data;
831 ident = le16_to_cpu(
832 t->tagIdent);
833 location = le32_to_cpu(
834 t->tagLocation);
835 brelse(bh);
836 }
837 }
838 721
839 if (ident == TAG_IDENT_AVDP && 722 last[0] = lastblock;
840 location == udf_variable_to_fixed(last[i]) - 256) { 723 last[1] = last[0] - 1;
841 UDF_SET_FLAG(sb, 724 last[2] = last[0] + 1;
842 UDF_FLAG_VARCONV); 725 last[3] = last[0] - 2;
843 lastblock = udf_variable_to_fixed(last[i]); 726 last[4] = last[0] - 150;
844 sbi->s_anchor[1] = lastblock - 256; 727 last[5] = last[0] - 152;
845 } 728
846 } 729 /* according to spec, anchor is in either:
847 } 730 * block 256
731 * lastblock-256
732 * lastblock
733 * however, if the disc isn't closed, it could be 512 */
734
735 for (i = 0; i < ARRAY_SIZE(last); i++) {
736 if (last[i] < 0)
737 continue;
738 if (last[i] >= sb->s_bdev->bd_inode->i_size >>
739 sb->s_blocksize_bits)
740 continue;
741
742 if (udf_check_anchor_block(sb, last[i], varconv)) {
743 sbi->s_anchor[0] = last[i];
744 sbi->s_anchor[1] = last[i] - 256;
745 return last[i];
848 } 746 }
849 }
850 747
851 if (!lastblock) { 748 if (last[i] < 256)
852 /* We haven't found the lastblock. check 312 */ 749 continue;
853 bh = sb_bread(sb, 312 + sbi->s_session);
854 if (bh) {
855 tag *t = (tag *)bh->b_data;
856 ident = le16_to_cpu(t->tagIdent);
857 location = le32_to_cpu(t->tagLocation);
858 brelse(bh);
859 750
860 if (ident == TAG_IDENT_AVDP && location == 256) 751 if (udf_check_anchor_block(sb, last[i] - 256, varconv)) {
861 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); 752 sbi->s_anchor[1] = last[i] - 256;
753 return last[i];
862 } 754 }
863 } 755 }
864 756
757 if (udf_check_anchor_block(sb, sbi->s_session + 256, varconv)) {
758 sbi->s_anchor[0] = sbi->s_session + 256;
759 return last[0];
760 }
761 if (udf_check_anchor_block(sb, sbi->s_session + 512, varconv)) {
762 sbi->s_anchor[0] = sbi->s_session + 512;
763 return last[0];
764 }
765 return 0;
766}
767
768/*
769 * Find an anchor volume descriptor. The function expects sbi->s_lastblock to
770 * be the last block on the media.
771 *
772 * Return 1 if not found, 0 if ok
773 *
774 */
775static void udf_find_anchor(struct super_block *sb)
776{
777 sector_t lastblock;
778 struct buffer_head *bh = NULL;
779 uint16_t ident;
780 int i;
781 struct udf_sb_info *sbi = UDF_SB(sb);
782
783 lastblock = udf_scan_anchors(sb, 0, sbi->s_last_block);
784 if (lastblock)
785 goto check_anchor;
786
787 /* No anchor found? Try VARCONV conversion of block numbers */
788 /* Firstly, we try to not convert number of the last block */
789 lastblock = udf_scan_anchors(sb, 1,
790 udf_variable_to_fixed(sbi->s_last_block));
791 if (lastblock) {
792 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
793 goto check_anchor;
794 }
795
796 /* Secondly, we try with converted number of the last block */
797 lastblock = udf_scan_anchors(sb, 1, sbi->s_last_block);
798 if (lastblock)
799 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
800
801check_anchor:
802 /*
803 * Check located anchors and the anchor block supplied via
804 * mount options
805 */
865 for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) { 806 for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
866 if (sbi->s_anchor[i]) { 807 if (!sbi->s_anchor[i])
867 bh = udf_read_tagged(sb, sbi->s_anchor[i], 808 continue;
868 sbi->s_anchor[i], &ident); 809 bh = udf_read_tagged(sb, sbi->s_anchor[i],
869 if (!bh) 810 sbi->s_anchor[i], &ident);
811 if (!bh)
812 sbi->s_anchor[i] = 0;
813 else {
814 brelse(bh);
815 if (ident != TAG_IDENT_AVDP)
870 sbi->s_anchor[i] = 0; 816 sbi->s_anchor[i] = 0;
871 else {
872 brelse(bh);
873 if ((ident != TAG_IDENT_AVDP) &&
874 (i || (ident != TAG_IDENT_FE &&
875 ident != TAG_IDENT_EFE)))
876 sbi->s_anchor[i] = 0;
877 }
878 } 817 }
879 } 818 }
880 819
@@ -971,27 +910,30 @@ static int udf_find_fileset(struct super_block *sb,
971 return 1; 910 return 1;
972} 911}
973 912
974static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh) 913static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
975{ 914{
976 struct primaryVolDesc *pvoldesc; 915 struct primaryVolDesc *pvoldesc;
977 time_t recording;
978 long recording_usec;
979 struct ustr instr; 916 struct ustr instr;
980 struct ustr outstr; 917 struct ustr outstr;
918 struct buffer_head *bh;
919 uint16_t ident;
920
921 bh = udf_read_tagged(sb, block, block, &ident);
922 if (!bh)
923 return 1;
924 BUG_ON(ident != TAG_IDENT_PVD);
981 925
982 pvoldesc = (struct primaryVolDesc *)bh->b_data; 926 pvoldesc = (struct primaryVolDesc *)bh->b_data;
983 927
984 if (udf_stamp_to_time(&recording, &recording_usec, 928 if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
985 lets_to_cpu(pvoldesc->recordingDateAndTime))) { 929 pvoldesc->recordingDateAndTime)) {
986 kernel_timestamp ts; 930#ifdef UDFFS_DEBUG
987 ts = lets_to_cpu(pvoldesc->recordingDateAndTime); 931 timestamp *ts = &pvoldesc->recordingDateAndTime;
988 udf_debug("recording time %ld/%ld, %04u/%02u/%02u" 932 udf_debug("recording time %04u/%02u/%02u"
989 " %02u:%02u (%x)\n", 933 " %02u:%02u (%x)\n",
990 recording, recording_usec, 934 le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
991 ts.year, ts.month, ts.day, ts.hour, 935 ts->minute, le16_to_cpu(ts->typeAndTimezone));
992 ts.minute, ts.typeAndTimezone); 936#endif
993 UDF_SB(sb)->s_record_time.tv_sec = recording;
994 UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000;
995 } 937 }
996 938
997 if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) 939 if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32))
@@ -1005,6 +947,104 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
1005 if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) 947 if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128))
1006 if (udf_CS0toUTF8(&outstr, &instr)) 948 if (udf_CS0toUTF8(&outstr, &instr))
1007 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name); 949 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
950
951 brelse(bh);
952 return 0;
953}
954
955static int udf_load_metadata_files(struct super_block *sb, int partition)
956{
957 struct udf_sb_info *sbi = UDF_SB(sb);
958 struct udf_part_map *map;
959 struct udf_meta_data *mdata;
960 kernel_lb_addr addr;
961 int fe_error = 0;
962
963 map = &sbi->s_partmaps[partition];
964 mdata = &map->s_type_specific.s_metadata;
965
966 /* metadata address */
967 addr.logicalBlockNum = mdata->s_meta_file_loc;
968 addr.partitionReferenceNum = map->s_partition_num;
969
970 udf_debug("Metadata file location: block = %d part = %d\n",
971 addr.logicalBlockNum, addr.partitionReferenceNum);
972
973 mdata->s_metadata_fe = udf_iget(sb, addr);
974
975 if (mdata->s_metadata_fe == NULL) {
976 udf_warning(sb, __func__, "metadata inode efe not found, "
977 "will try mirror inode.");
978 fe_error = 1;
979 } else if (UDF_I(mdata->s_metadata_fe)->i_alloc_type !=
980 ICBTAG_FLAG_AD_SHORT) {
981 udf_warning(sb, __func__, "metadata inode efe does not have "
982 "short allocation descriptors!");
983 fe_error = 1;
984 iput(mdata->s_metadata_fe);
985 mdata->s_metadata_fe = NULL;
986 }
987
988 /* mirror file entry */
989 addr.logicalBlockNum = mdata->s_mirror_file_loc;
990 addr.partitionReferenceNum = map->s_partition_num;
991
992 udf_debug("Mirror metadata file location: block = %d part = %d\n",
993 addr.logicalBlockNum, addr.partitionReferenceNum);
994
995 mdata->s_mirror_fe = udf_iget(sb, addr);
996
997 if (mdata->s_mirror_fe == NULL) {
998 if (fe_error) {
999 udf_error(sb, __func__, "mirror inode efe not found "
1000 "and metadata inode is missing too, exiting...");
1001 goto error_exit;
1002 } else
1003 udf_warning(sb, __func__, "mirror inode efe not found,"
1004 " but metadata inode is OK");
1005 } else if (UDF_I(mdata->s_mirror_fe)->i_alloc_type !=
1006 ICBTAG_FLAG_AD_SHORT) {
1007 udf_warning(sb, __func__, "mirror inode efe does not have "
1008 "short allocation descriptors!");
1009 iput(mdata->s_mirror_fe);
1010 mdata->s_mirror_fe = NULL;
1011 if (fe_error)
1012 goto error_exit;
1013 }
1014
1015 /*
1016 * bitmap file entry
1017 * Note:
1018 * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
1019 */
1020 if (mdata->s_bitmap_file_loc != 0xFFFFFFFF) {
1021 addr.logicalBlockNum = mdata->s_bitmap_file_loc;
1022 addr.partitionReferenceNum = map->s_partition_num;
1023
1024 udf_debug("Bitmap file location: block = %d part = %d\n",
1025 addr.logicalBlockNum, addr.partitionReferenceNum);
1026
1027 mdata->s_bitmap_fe = udf_iget(sb, addr);
1028
1029 if (mdata->s_bitmap_fe == NULL) {
1030 if (sb->s_flags & MS_RDONLY)
1031 udf_warning(sb, __func__, "bitmap inode efe "
1032 "not found but it's ok since the disc"
1033 " is mounted read-only");
1034 else {
1035 udf_error(sb, __func__, "bitmap inode efe not "
1036 "found and attempted read-write mount");
1037 goto error_exit;
1038 }
1039 }
1040 }
1041
1042 udf_debug("udf_load_metadata_files Ok\n");
1043
1044 return 0;
1045
1046error_exit:
1047 return 1;
1008} 1048}
1009 1049
1010static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, 1050static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
@@ -1025,10 +1065,9 @@ static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
1025int udf_compute_nr_groups(struct super_block *sb, u32 partition) 1065int udf_compute_nr_groups(struct super_block *sb, u32 partition)
1026{ 1066{
1027 struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; 1067 struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
1028 return (map->s_partition_len + 1068 return DIV_ROUND_UP(map->s_partition_len +
1029 (sizeof(struct spaceBitmapDesc) << 3) + 1069 (sizeof(struct spaceBitmapDesc) << 3),
1030 (sb->s_blocksize * 8) - 1) / 1070 sb->s_blocksize * 8);
1031 (sb->s_blocksize * 8);
1032} 1071}
1033 1072
1034static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index) 1073static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
@@ -1059,134 +1098,241 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
1059 return bitmap; 1098 return bitmap;
1060} 1099}
1061 1100
1062static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) 1101static int udf_fill_partdesc_info(struct super_block *sb,
1102 struct partitionDesc *p, int p_index)
1103{
1104 struct udf_part_map *map;
1105 struct udf_sb_info *sbi = UDF_SB(sb);
1106 struct partitionHeaderDesc *phd;
1107
1108 map = &sbi->s_partmaps[p_index];
1109
1110 map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
1111 map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
1112
1113 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
1114 map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
1115 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
1116 map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
1117 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
1118 map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
1119 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
1120 map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
1121
1122 udf_debug("Partition (%d type %x) starts at physical %d, "
1123 "block length %d\n", p_index,
1124 map->s_partition_type, map->s_partition_root,
1125 map->s_partition_len);
1126
1127 if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) &&
1128 strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
1129 return 0;
1130
1131 phd = (struct partitionHeaderDesc *)p->partitionContentsUse;
1132 if (phd->unallocSpaceTable.extLength) {
1133 kernel_lb_addr loc = {
1134 .logicalBlockNum = le32_to_cpu(
1135 phd->unallocSpaceTable.extPosition),
1136 .partitionReferenceNum = p_index,
1137 };
1138
1139 map->s_uspace.s_table = udf_iget(sb, loc);
1140 if (!map->s_uspace.s_table) {
1141 udf_debug("cannot load unallocSpaceTable (part %d)\n",
1142 p_index);
1143 return 1;
1144 }
1145 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
1146 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
1147 p_index, map->s_uspace.s_table->i_ino);
1148 }
1149
1150 if (phd->unallocSpaceBitmap.extLength) {
1151 struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
1152 if (!bitmap)
1153 return 1;
1154 map->s_uspace.s_bitmap = bitmap;
1155 bitmap->s_extLength = le32_to_cpu(
1156 phd->unallocSpaceBitmap.extLength);
1157 bitmap->s_extPosition = le32_to_cpu(
1158 phd->unallocSpaceBitmap.extPosition);
1159 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
1160 udf_debug("unallocSpaceBitmap (part %d) @ %d\n", p_index,
1161 bitmap->s_extPosition);
1162 }
1163
1164 if (phd->partitionIntegrityTable.extLength)
1165 udf_debug("partitionIntegrityTable (part %d)\n", p_index);
1166
1167 if (phd->freedSpaceTable.extLength) {
1168 kernel_lb_addr loc = {
1169 .logicalBlockNum = le32_to_cpu(
1170 phd->freedSpaceTable.extPosition),
1171 .partitionReferenceNum = p_index,
1172 };
1173
1174 map->s_fspace.s_table = udf_iget(sb, loc);
1175 if (!map->s_fspace.s_table) {
1176 udf_debug("cannot load freedSpaceTable (part %d)\n",
1177 p_index);
1178 return 1;
1179 }
1180
1181 map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE;
1182 udf_debug("freedSpaceTable (part %d) @ %ld\n",
1183 p_index, map->s_fspace.s_table->i_ino);
1184 }
1185
1186 if (phd->freedSpaceBitmap.extLength) {
1187 struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
1188 if (!bitmap)
1189 return 1;
1190 map->s_fspace.s_bitmap = bitmap;
1191 bitmap->s_extLength = le32_to_cpu(
1192 phd->freedSpaceBitmap.extLength);
1193 bitmap->s_extPosition = le32_to_cpu(
1194 phd->freedSpaceBitmap.extPosition);
1195 map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
1196 udf_debug("freedSpaceBitmap (part %d) @ %d\n", p_index,
1197 bitmap->s_extPosition);
1198 }
1199 return 0;
1200}
1201
1202static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
1203{
1204 struct udf_sb_info *sbi = UDF_SB(sb);
1205 struct udf_part_map *map = &sbi->s_partmaps[p_index];
1206 kernel_lb_addr ino;
1207 struct buffer_head *bh = NULL;
1208 struct udf_inode_info *vati;
1209 uint32_t pos;
1210 struct virtualAllocationTable20 *vat20;
1211
1212 /* VAT file entry is in the last recorded block */
1213 ino.partitionReferenceNum = type1_index;
1214 ino.logicalBlockNum = sbi->s_last_block - map->s_partition_root;
1215 sbi->s_vat_inode = udf_iget(sb, ino);
1216 if (!sbi->s_vat_inode)
1217 return 1;
1218
1219 if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
1220 map->s_type_specific.s_virtual.s_start_offset = 0;
1221 map->s_type_specific.s_virtual.s_num_entries =
1222 (sbi->s_vat_inode->i_size - 36) >> 2;
1223 } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
1224 vati = UDF_I(sbi->s_vat_inode);
1225 if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
1226 pos = udf_block_map(sbi->s_vat_inode, 0);
1227 bh = sb_bread(sb, pos);
1228 if (!bh)
1229 return 1;
1230 vat20 = (struct virtualAllocationTable20 *)bh->b_data;
1231 } else {
1232 vat20 = (struct virtualAllocationTable20 *)
1233 vati->i_ext.i_data;
1234 }
1235
1236 map->s_type_specific.s_virtual.s_start_offset =
1237 le16_to_cpu(vat20->lengthHeader);
1238 map->s_type_specific.s_virtual.s_num_entries =
1239 (sbi->s_vat_inode->i_size -
1240 map->s_type_specific.s_virtual.
1241 s_start_offset) >> 2;
1242 brelse(bh);
1243 }
1244 return 0;
1245}
1246
1247static int udf_load_partdesc(struct super_block *sb, sector_t block)
1063{ 1248{
1249 struct buffer_head *bh;
1064 struct partitionDesc *p; 1250 struct partitionDesc *p;
1065 int i;
1066 struct udf_part_map *map; 1251 struct udf_part_map *map;
1067 struct udf_sb_info *sbi; 1252 struct udf_sb_info *sbi = UDF_SB(sb);
1253 int i, type1_idx;
1254 uint16_t partitionNumber;
1255 uint16_t ident;
1256 int ret = 0;
1257
1258 bh = udf_read_tagged(sb, block, block, &ident);
1259 if (!bh)
1260 return 1;
1261 if (ident != TAG_IDENT_PD)
1262 goto out_bh;
1068 1263
1069 p = (struct partitionDesc *)bh->b_data; 1264 p = (struct partitionDesc *)bh->b_data;
1070 sbi = UDF_SB(sb); 1265 partitionNumber = le16_to_cpu(p->partitionNumber);
1071 1266
1267 /* First scan for TYPE1, SPARABLE and METADATA partitions */
1072 for (i = 0; i < sbi->s_partitions; i++) { 1268 for (i = 0; i < sbi->s_partitions; i++) {
1073 map = &sbi->s_partmaps[i]; 1269 map = &sbi->s_partmaps[i];
1074 udf_debug("Searching map: (%d == %d)\n", 1270 udf_debug("Searching map: (%d == %d)\n",
1075 map->s_partition_num, 1271 map->s_partition_num, partitionNumber);
1076 le16_to_cpu(p->partitionNumber)); 1272 if (map->s_partition_num == partitionNumber &&
1077 if (map->s_partition_num == 1273 (map->s_partition_type == UDF_TYPE1_MAP15 ||
1078 le16_to_cpu(p->partitionNumber)) { 1274 map->s_partition_type == UDF_SPARABLE_MAP15))
1079 map->s_partition_len =
1080 le32_to_cpu(p->partitionLength); /* blocks */
1081 map->s_partition_root =
1082 le32_to_cpu(p->partitionStartingLocation);
1083 if (p->accessType ==
1084 cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
1085 map->s_partition_flags |=
1086 UDF_PART_FLAG_READ_ONLY;
1087 if (p->accessType ==
1088 cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
1089 map->s_partition_flags |=
1090 UDF_PART_FLAG_WRITE_ONCE;
1091 if (p->accessType ==
1092 cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
1093 map->s_partition_flags |=
1094 UDF_PART_FLAG_REWRITABLE;
1095 if (p->accessType ==
1096 cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
1097 map->s_partition_flags |=
1098 UDF_PART_FLAG_OVERWRITABLE;
1099
1100 if (!strcmp(p->partitionContents.ident,
1101 PD_PARTITION_CONTENTS_NSR02) ||
1102 !strcmp(p->partitionContents.ident,
1103 PD_PARTITION_CONTENTS_NSR03)) {
1104 struct partitionHeaderDesc *phd;
1105
1106 phd = (struct partitionHeaderDesc *)
1107 (p->partitionContentsUse);
1108 if (phd->unallocSpaceTable.extLength) {
1109 kernel_lb_addr loc = {
1110 .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
1111 .partitionReferenceNum = i,
1112 };
1113
1114 map->s_uspace.s_table =
1115 udf_iget(sb, loc);
1116 if (!map->s_uspace.s_table) {
1117 udf_debug("cannot load unallocSpaceTable (part %d)\n", i);
1118 return 1;
1119 }
1120 map->s_partition_flags |=
1121 UDF_PART_FLAG_UNALLOC_TABLE;
1122 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
1123 i, map->s_uspace.s_table->i_ino);
1124 }
1125 if (phd->unallocSpaceBitmap.extLength) {
1126 struct udf_bitmap *bitmap =
1127 udf_sb_alloc_bitmap(sb, i);
1128 map->s_uspace.s_bitmap = bitmap;
1129 if (bitmap != NULL) {
1130 bitmap->s_extLength =
1131 le32_to_cpu(phd->unallocSpaceBitmap.extLength);
1132 bitmap->s_extPosition =
1133 le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
1134 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
1135 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
1136 i, bitmap->s_extPosition);
1137 }
1138 }
1139 if (phd->partitionIntegrityTable.extLength)
1140 udf_debug("partitionIntegrityTable (part %d)\n", i);
1141 if (phd->freedSpaceTable.extLength) {
1142 kernel_lb_addr loc = {
1143 .logicalBlockNum = le32_to_cpu(phd->freedSpaceTable.extPosition),
1144 .partitionReferenceNum = i,
1145 };
1146
1147 map->s_fspace.s_table =
1148 udf_iget(sb, loc);
1149 if (!map->s_fspace.s_table) {
1150 udf_debug("cannot load freedSpaceTable (part %d)\n", i);
1151 return 1;
1152 }
1153 map->s_partition_flags |=
1154 UDF_PART_FLAG_FREED_TABLE;
1155 udf_debug("freedSpaceTable (part %d) @ %ld\n",
1156 i, map->s_fspace.s_table->i_ino);
1157 }
1158 if (phd->freedSpaceBitmap.extLength) {
1159 struct udf_bitmap *bitmap =
1160 udf_sb_alloc_bitmap(sb, i);
1161 map->s_fspace.s_bitmap = bitmap;
1162 if (bitmap != NULL) {
1163 bitmap->s_extLength =
1164 le32_to_cpu(phd->freedSpaceBitmap.extLength);
1165 bitmap->s_extPosition =
1166 le32_to_cpu(phd->freedSpaceBitmap.extPosition);
1167 map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
1168 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
1169 i, bitmap->s_extPosition);
1170 }
1171 }
1172 }
1173 break; 1275 break;
1174 }
1175 } 1276 }
1176 if (i == sbi->s_partitions) 1277
1278 if (i >= sbi->s_partitions) {
1177 udf_debug("Partition (%d) not found in partition map\n", 1279 udf_debug("Partition (%d) not found in partition map\n",
1178 le16_to_cpu(p->partitionNumber)); 1280 partitionNumber);
1179 else 1281 goto out_bh;
1180 udf_debug("Partition (%d:%d type %x) starts at physical %d, " 1282 }
1181 "block length %d\n", 1283
1182 le16_to_cpu(p->partitionNumber), i, 1284 ret = udf_fill_partdesc_info(sb, p, i);
1183 map->s_partition_type, 1285
1184 map->s_partition_root, 1286 /*
1185 map->s_partition_len); 1287 * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
1186 return 0; 1288 * PHYSICAL partitions are already set up
1289 */
1290 type1_idx = i;
1291 for (i = 0; i < sbi->s_partitions; i++) {
1292 map = &sbi->s_partmaps[i];
1293
1294 if (map->s_partition_num == partitionNumber &&
1295 (map->s_partition_type == UDF_VIRTUAL_MAP15 ||
1296 map->s_partition_type == UDF_VIRTUAL_MAP20 ||
1297 map->s_partition_type == UDF_METADATA_MAP25))
1298 break;
1299 }
1300
1301 if (i >= sbi->s_partitions)
1302 goto out_bh;
1303
1304 ret = udf_fill_partdesc_info(sb, p, i);
1305 if (ret)
1306 goto out_bh;
1307
1308 if (map->s_partition_type == UDF_METADATA_MAP25) {
1309 ret = udf_load_metadata_files(sb, i);
1310 if (ret) {
1311 printk(KERN_ERR "UDF-fs: error loading MetaData "
1312 "partition map %d\n", i);
1313 goto out_bh;
1314 }
1315 } else {
1316 ret = udf_load_vat(sb, i, type1_idx);
1317 if (ret)
1318 goto out_bh;
1319 /*
1320 * Mark filesystem read-only if we have a partition with
1321 * virtual map since we don't handle writing to it (we
1322 * overwrite blocks instead of relocating them).
1323 */
1324 sb->s_flags |= MS_RDONLY;
1325 printk(KERN_NOTICE "UDF-fs: Filesystem marked read-only "
1326 "because writing to pseudooverwrite partition is "
1327 "not implemented.\n");
1328 }
1329out_bh:
1330 /* In case loading failed, we handle cleanup in udf_fill_super */
1331 brelse(bh);
1332 return ret;
1187} 1333}
1188 1334
1189static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh, 1335static int udf_load_logicalvol(struct super_block *sb, sector_t block,
1190 kernel_lb_addr *fileset) 1336 kernel_lb_addr *fileset)
1191{ 1337{
1192 struct logicalVolDesc *lvd; 1338 struct logicalVolDesc *lvd;
@@ -1194,12 +1340,21 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
1194 uint8_t type; 1340 uint8_t type;
1195 struct udf_sb_info *sbi = UDF_SB(sb); 1341 struct udf_sb_info *sbi = UDF_SB(sb);
1196 struct genericPartitionMap *gpm; 1342 struct genericPartitionMap *gpm;
1343 uint16_t ident;
1344 struct buffer_head *bh;
1345 int ret = 0;
1197 1346
1347 bh = udf_read_tagged(sb, block, block, &ident);
1348 if (!bh)
1349 return 1;
1350 BUG_ON(ident != TAG_IDENT_LVD);
1198 lvd = (struct logicalVolDesc *)bh->b_data; 1351 lvd = (struct logicalVolDesc *)bh->b_data;
1199 1352
1200 i = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps)); 1353 i = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
1201 if (i != 0) 1354 if (i != 0) {
1202 return i; 1355 ret = i;
1356 goto out_bh;
1357 }
1203 1358
1204 for (i = 0, offset = 0; 1359 for (i = 0, offset = 0;
1205 i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength); 1360 i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength);
@@ -1223,12 +1378,12 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
1223 u16 suf = 1378 u16 suf =
1224 le16_to_cpu(((__le16 *)upm2->partIdent. 1379 le16_to_cpu(((__le16 *)upm2->partIdent.
1225 identSuffix)[0]); 1380 identSuffix)[0]);
1226 if (suf == 0x0150) { 1381 if (suf < 0x0200) {
1227 map->s_partition_type = 1382 map->s_partition_type =
1228 UDF_VIRTUAL_MAP15; 1383 UDF_VIRTUAL_MAP15;
1229 map->s_partition_func = 1384 map->s_partition_func =
1230 udf_get_pblock_virt15; 1385 udf_get_pblock_virt15;
1231 } else if (suf == 0x0200) { 1386 } else {
1232 map->s_partition_type = 1387 map->s_partition_type =
1233 UDF_VIRTUAL_MAP20; 1388 UDF_VIRTUAL_MAP20;
1234 map->s_partition_func = 1389 map->s_partition_func =
@@ -1238,7 +1393,6 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
1238 UDF_ID_SPARABLE, 1393 UDF_ID_SPARABLE,
1239 strlen(UDF_ID_SPARABLE))) { 1394 strlen(UDF_ID_SPARABLE))) {
1240 uint32_t loc; 1395 uint32_t loc;
1241 uint16_t ident;
1242 struct sparingTable *st; 1396 struct sparingTable *st;
1243 struct sparablePartitionMap *spm = 1397 struct sparablePartitionMap *spm =
1244 (struct sparablePartitionMap *)gpm; 1398 (struct sparablePartitionMap *)gpm;
@@ -1256,22 +1410,64 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
1256 map->s_type_specific.s_sparing. 1410 map->s_type_specific.s_sparing.
1257 s_spar_map[j] = bh2; 1411 s_spar_map[j] = bh2;
1258 1412
1259 if (bh2 != NULL) { 1413 if (bh2 == NULL)
1260 st = (struct sparingTable *) 1414 continue;
1261 bh2->b_data; 1415
1262 if (ident != 0 || strncmp( 1416 st = (struct sparingTable *)bh2->b_data;
1263 st->sparingIdent.ident, 1417 if (ident != 0 || strncmp(
1264 UDF_ID_SPARING, 1418 st->sparingIdent.ident,
1265 strlen(UDF_ID_SPARING))) { 1419 UDF_ID_SPARING,
1266 brelse(bh2); 1420 strlen(UDF_ID_SPARING))) {
1267 map->s_type_specific. 1421 brelse(bh2);
1268 s_sparing. 1422 map->s_type_specific.s_sparing.
1269 s_spar_map[j] = 1423 s_spar_map[j] = NULL;
1270 NULL;
1271 }
1272 } 1424 }
1273 } 1425 }
1274 map->s_partition_func = udf_get_pblock_spar15; 1426 map->s_partition_func = udf_get_pblock_spar15;
1427 } else if (!strncmp(upm2->partIdent.ident,
1428 UDF_ID_METADATA,
1429 strlen(UDF_ID_METADATA))) {
1430 struct udf_meta_data *mdata =
1431 &map->s_type_specific.s_metadata;
1432 struct metadataPartitionMap *mdm =
1433 (struct metadataPartitionMap *)
1434 &(lvd->partitionMaps[offset]);
1435 udf_debug("Parsing Logical vol part %d "
1436 "type %d id=%s\n", i, type,
1437 UDF_ID_METADATA);
1438
1439 map->s_partition_type = UDF_METADATA_MAP25;
1440 map->s_partition_func = udf_get_pblock_meta25;
1441
1442 mdata->s_meta_file_loc =
1443 le32_to_cpu(mdm->metadataFileLoc);
1444 mdata->s_mirror_file_loc =
1445 le32_to_cpu(mdm->metadataMirrorFileLoc);
1446 mdata->s_bitmap_file_loc =
1447 le32_to_cpu(mdm->metadataBitmapFileLoc);
1448 mdata->s_alloc_unit_size =
1449 le32_to_cpu(mdm->allocUnitSize);
1450 mdata->s_align_unit_size =
1451 le16_to_cpu(mdm->alignUnitSize);
1452 mdata->s_dup_md_flag =
1453 mdm->flags & 0x01;
1454
1455 udf_debug("Metadata Ident suffix=0x%x\n",
1456 (le16_to_cpu(
1457 ((__le16 *)
1458 mdm->partIdent.identSuffix)[0])));
1459 udf_debug("Metadata part num=%d\n",
1460 le16_to_cpu(mdm->partitionNum));
1461 udf_debug("Metadata part alloc unit size=%d\n",
1462 le32_to_cpu(mdm->allocUnitSize));
1463 udf_debug("Metadata file loc=%d\n",
1464 le32_to_cpu(mdm->metadataFileLoc));
1465 udf_debug("Mirror file loc=%d\n",
1466 le32_to_cpu(mdm->metadataMirrorFileLoc));
1467 udf_debug("Bitmap file loc=%d\n",
1468 le32_to_cpu(mdm->metadataBitmapFileLoc));
1469 udf_debug("Duplicate Flag: %d %d\n",
1470 mdata->s_dup_md_flag, mdm->flags);
1275 } else { 1471 } else {
1276 udf_debug("Unknown ident: %s\n", 1472 udf_debug("Unknown ident: %s\n",
1277 upm2->partIdent.ident); 1473 upm2->partIdent.ident);
@@ -1296,7 +1492,9 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
1296 if (lvd->integritySeqExt.extLength) 1492 if (lvd->integritySeqExt.extLength)
1297 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt)); 1493 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
1298 1494
1299 return 0; 1495out_bh:
1496 brelse(bh);
1497 return ret;
1300} 1498}
1301 1499
1302/* 1500/*
@@ -1345,7 +1543,7 @@ static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1345 * July 1, 1997 - Andrew E. Mileski 1543 * July 1, 1997 - Andrew E. Mileski
1346 * Written, tested, and released. 1544 * Written, tested, and released.
1347 */ 1545 */
1348static int udf_process_sequence(struct super_block *sb, long block, 1546static noinline int udf_process_sequence(struct super_block *sb, long block,
1349 long lastblock, kernel_lb_addr *fileset) 1547 long lastblock, kernel_lb_addr *fileset)
1350{ 1548{
1351 struct buffer_head *bh = NULL; 1549 struct buffer_head *bh = NULL;
@@ -1354,19 +1552,25 @@ static int udf_process_sequence(struct super_block *sb, long block,
1354 struct generic_desc *gd; 1552 struct generic_desc *gd;
1355 struct volDescPtr *vdp; 1553 struct volDescPtr *vdp;
1356 int done = 0; 1554 int done = 0;
1357 int i, j;
1358 uint32_t vdsn; 1555 uint32_t vdsn;
1359 uint16_t ident; 1556 uint16_t ident;
1360 long next_s = 0, next_e = 0; 1557 long next_s = 0, next_e = 0;
1361 1558
1362 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH); 1559 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1363 1560
1364 /* Read the main descriptor sequence */ 1561 /*
1562 * Read the main descriptor sequence and find which descriptors
1563 * are in it.
1564 */
1365 for (; (!done && block <= lastblock); block++) { 1565 for (; (!done && block <= lastblock); block++) {
1366 1566
1367 bh = udf_read_tagged(sb, block, block, &ident); 1567 bh = udf_read_tagged(sb, block, block, &ident);
1368 if (!bh) 1568 if (!bh) {
1369 break; 1569 printk(KERN_ERR "udf: Block %Lu of volume descriptor "
1570 "sequence is corrupted or we could not read "
1571 "it.\n", (unsigned long long)block);
1572 return 1;
1573 }
1370 1574
1371 /* Process each descriptor (ISO 13346 3/8.3-8.4) */ 1575 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1372 gd = (struct generic_desc *)bh->b_data; 1576 gd = (struct generic_desc *)bh->b_data;
@@ -1432,41 +1636,31 @@ static int udf_process_sequence(struct super_block *sb, long block,
1432 } 1636 }
1433 brelse(bh); 1637 brelse(bh);
1434 } 1638 }
1435 for (i = 0; i < VDS_POS_LENGTH; i++) { 1639 /*
1436 if (vds[i].block) { 1640 * Now read interesting descriptors again and process them
1437 bh = udf_read_tagged(sb, vds[i].block, vds[i].block, 1641 * in a suitable order
1438 &ident); 1642 */
1439 1643 if (!vds[VDS_POS_PRIMARY_VOL_DESC].block) {
1440 if (i == VDS_POS_PRIMARY_VOL_DESC) { 1644 printk(KERN_ERR "udf: Primary Volume Descriptor not found!\n");
1441 udf_load_pvoldesc(sb, bh); 1645 return 1;
1442 } else if (i == VDS_POS_LOGICAL_VOL_DESC) { 1646 }
1443 if (udf_load_logicalvol(sb, bh, fileset)) { 1647 if (udf_load_pvoldesc(sb, vds[VDS_POS_PRIMARY_VOL_DESC].block))
1444 brelse(bh); 1648 return 1;
1445 return 1; 1649
1446 } 1650 if (vds[VDS_POS_LOGICAL_VOL_DESC].block && udf_load_logicalvol(sb,
1447 } else if (i == VDS_POS_PARTITION_DESC) { 1651 vds[VDS_POS_LOGICAL_VOL_DESC].block, fileset))
1448 struct buffer_head *bh2 = NULL; 1652 return 1;
1449 if (udf_load_partdesc(sb, bh)) { 1653
1450 brelse(bh); 1654 if (vds[VDS_POS_PARTITION_DESC].block) {
1451 return 1; 1655 /*
1452 } 1656 * We rescan the whole descriptor sequence to find
1453 for (j = vds[i].block + 1; 1657 * partition descriptor blocks and process them.
1454 j < vds[VDS_POS_TERMINATING_DESC].block; 1658 */
1455 j++) { 1659 for (block = vds[VDS_POS_PARTITION_DESC].block;
1456 bh2 = udf_read_tagged(sb, j, j, &ident); 1660 block < vds[VDS_POS_TERMINATING_DESC].block;
1457 gd = (struct generic_desc *)bh2->b_data; 1661 block++)
1458 if (ident == TAG_IDENT_PD) 1662 if (udf_load_partdesc(sb, block))
1459 if (udf_load_partdesc(sb, 1663 return 1;
1460 bh2)) {
1461 brelse(bh);
1462 brelse(bh2);
1463 return 1;
1464 }
1465 brelse(bh2);
1466 }
1467 }
1468 brelse(bh);
1469 }
1470 } 1664 }
1471 1665
1472 return 0; 1666 return 0;
@@ -1478,6 +1672,7 @@ static int udf_process_sequence(struct super_block *sb, long block,
1478static int udf_check_valid(struct super_block *sb, int novrs, int silent) 1672static int udf_check_valid(struct super_block *sb, int novrs, int silent)
1479{ 1673{
1480 long block; 1674 long block;
1675 struct udf_sb_info *sbi = UDF_SB(sb);
1481 1676
1482 if (novrs) { 1677 if (novrs) {
1483 udf_debug("Validity check skipped because of novrs option\n"); 1678 udf_debug("Validity check skipped because of novrs option\n");
@@ -1485,27 +1680,22 @@ static int udf_check_valid(struct super_block *sb, int novrs, int silent)
1485 } 1680 }
1486 /* Check that it is NSR02 compliant */ 1681 /* Check that it is NSR02 compliant */
1487 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ 1682 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1488 else { 1683 block = udf_vrs(sb, silent);
1489 block = udf_vrs(sb, silent); 1684 if (block == -1)
1490 if (block == -1) { 1685 udf_debug("Failed to read byte 32768. Assuming open "
1491 struct udf_sb_info *sbi = UDF_SB(sb); 1686 "disc. Skipping validity check\n");
1492 udf_debug("Failed to read byte 32768. Assuming open " 1687 if (block && !sbi->s_last_block)
1493 "disc. Skipping validity check\n"); 1688 sbi->s_last_block = udf_get_last_block(sb);
1494 if (!sbi->s_last_block) 1689 return !block;
1495 sbi->s_last_block = udf_get_last_block(sb);
1496 return 0;
1497 } else
1498 return !block;
1499 }
1500} 1690}
1501 1691
1502static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset) 1692static int udf_load_sequence(struct super_block *sb, kernel_lb_addr *fileset)
1503{ 1693{
1504 struct anchorVolDescPtr *anchor; 1694 struct anchorVolDescPtr *anchor;
1505 uint16_t ident; 1695 uint16_t ident;
1506 struct buffer_head *bh; 1696 struct buffer_head *bh;
1507 long main_s, main_e, reserve_s, reserve_e; 1697 long main_s, main_e, reserve_s, reserve_e;
1508 int i, j; 1698 int i;
1509 struct udf_sb_info *sbi; 1699 struct udf_sb_info *sbi;
1510 1700
1511 if (!sb) 1701 if (!sb)
@@ -1515,6 +1705,7 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1515 for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) { 1705 for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
1516 if (!sbi->s_anchor[i]) 1706 if (!sbi->s_anchor[i])
1517 continue; 1707 continue;
1708
1518 bh = udf_read_tagged(sb, sbi->s_anchor[i], sbi->s_anchor[i], 1709 bh = udf_read_tagged(sb, sbi->s_anchor[i], sbi->s_anchor[i],
1519 &ident); 1710 &ident);
1520 if (!bh) 1711 if (!bh)
@@ -1553,76 +1744,6 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1553 } 1744 }
1554 udf_debug("Using anchor in block %d\n", sbi->s_anchor[i]); 1745 udf_debug("Using anchor in block %d\n", sbi->s_anchor[i]);
1555 1746
1556 for (i = 0; i < sbi->s_partitions; i++) {
1557 kernel_lb_addr uninitialized_var(ino);
1558 struct udf_part_map *map = &sbi->s_partmaps[i];
1559 switch (map->s_partition_type) {
1560 case UDF_VIRTUAL_MAP15:
1561 case UDF_VIRTUAL_MAP20:
1562 if (!sbi->s_last_block) {
1563 sbi->s_last_block = udf_get_last_block(sb);
1564 udf_find_anchor(sb);
1565 }
1566
1567 if (!sbi->s_last_block) {
1568 udf_debug("Unable to determine Lastblock (For "
1569 "Virtual Partition)\n");
1570 return 1;
1571 }
1572
1573 for (j = 0; j < sbi->s_partitions; j++) {
1574 struct udf_part_map *map2 = &sbi->s_partmaps[j];
1575 if (j != i &&
1576 map->s_volumeseqnum ==
1577 map2->s_volumeseqnum &&
1578 map->s_partition_num ==
1579 map2->s_partition_num) {
1580 ino.partitionReferenceNum = j;
1581 ino.logicalBlockNum =
1582 sbi->s_last_block -
1583 map2->s_partition_root;
1584 break;
1585 }
1586 }
1587
1588 if (j == sbi->s_partitions)
1589 return 1;
1590
1591 sbi->s_vat_inode = udf_iget(sb, ino);
1592 if (!sbi->s_vat_inode)
1593 return 1;
1594
1595 if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
1596 map->s_type_specific.s_virtual.s_start_offset =
1597 udf_ext0_offset(sbi->s_vat_inode);
1598 map->s_type_specific.s_virtual.s_num_entries =
1599 (sbi->s_vat_inode->i_size - 36) >> 2;
1600 } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
1601 uint32_t pos;
1602 struct virtualAllocationTable20 *vat20;
1603
1604 pos = udf_block_map(sbi->s_vat_inode, 0);
1605 bh = sb_bread(sb, pos);
1606 if (!bh)
1607 return 1;
1608 vat20 = (struct virtualAllocationTable20 *)
1609 bh->b_data +
1610 udf_ext0_offset(sbi->s_vat_inode);
1611 map->s_type_specific.s_virtual.s_start_offset =
1612 le16_to_cpu(vat20->lengthHeader) +
1613 udf_ext0_offset(sbi->s_vat_inode);
1614 map->s_type_specific.s_virtual.s_num_entries =
1615 (sbi->s_vat_inode->i_size -
1616 map->s_type_specific.s_virtual.
1617 s_start_offset) >> 2;
1618 brelse(bh);
1619 }
1620 map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
1621 map->s_partition_len =
1622 sbi->s_partmaps[ino.partitionReferenceNum].
1623 s_partition_len;
1624 }
1625 }
1626 return 0; 1747 return 0;
1627} 1748}
1628 1749
@@ -1630,65 +1751,61 @@ static void udf_open_lvid(struct super_block *sb)
1630{ 1751{
1631 struct udf_sb_info *sbi = UDF_SB(sb); 1752 struct udf_sb_info *sbi = UDF_SB(sb);
1632 struct buffer_head *bh = sbi->s_lvid_bh; 1753 struct buffer_head *bh = sbi->s_lvid_bh;
1633 if (bh) { 1754 struct logicalVolIntegrityDesc *lvid;
1634 kernel_timestamp cpu_time; 1755 struct logicalVolIntegrityDescImpUse *lvidiu;
1635 struct logicalVolIntegrityDesc *lvid = 1756 if (!bh)
1636 (struct logicalVolIntegrityDesc *)bh->b_data; 1757 return;
1637 struct logicalVolIntegrityDescImpUse *lvidiu =
1638 udf_sb_lvidiu(sbi);
1639 1758
1640 lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; 1759 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
1641 lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; 1760 lvidiu = udf_sb_lvidiu(sbi);
1642 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1643 lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
1644 lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
1645 1761
1646 lvid->descTag.descCRC = cpu_to_le16( 1762 lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1647 udf_crc((char *)lvid + sizeof(tag), 1763 lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1648 le16_to_cpu(lvid->descTag.descCRCLength), 1764 udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
1649 0)); 1765 CURRENT_TIME);
1766 lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
1650 1767
1651 lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag); 1768 lvid->descTag.descCRC = cpu_to_le16(
1652 mark_buffer_dirty(bh); 1769 crc_itu_t(0, (char *)lvid + sizeof(tag),
1653 } 1770 le16_to_cpu(lvid->descTag.descCRCLength)));
1771
1772 lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
1773 mark_buffer_dirty(bh);
1654} 1774}
1655 1775
1656static void udf_close_lvid(struct super_block *sb) 1776static void udf_close_lvid(struct super_block *sb)
1657{ 1777{
1658 kernel_timestamp cpu_time;
1659 struct udf_sb_info *sbi = UDF_SB(sb); 1778 struct udf_sb_info *sbi = UDF_SB(sb);
1660 struct buffer_head *bh = sbi->s_lvid_bh; 1779 struct buffer_head *bh = sbi->s_lvid_bh;
1661 struct logicalVolIntegrityDesc *lvid; 1780 struct logicalVolIntegrityDesc *lvid;
1781 struct logicalVolIntegrityDescImpUse *lvidiu;
1662 1782
1663 if (!bh) 1783 if (!bh)
1664 return; 1784 return;
1665 1785
1666 lvid = (struct logicalVolIntegrityDesc *)bh->b_data; 1786 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
1667 1787
1668 if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) { 1788 if (lvid->integrityType != LVID_INTEGRITY_TYPE_OPEN)
1669 struct logicalVolIntegrityDescImpUse *lvidiu = 1789 return;
1670 udf_sb_lvidiu(sbi); 1790
1671 lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; 1791 lvidiu = udf_sb_lvidiu(sbi);
1672 lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; 1792 lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1673 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) 1793 lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1674 lvid->recordingDateAndTime = cpu_to_lets(cpu_time); 1794 udf_time_to_disk_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
1675 if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev)) 1795 if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
1676 lvidiu->maxUDFWriteRev = 1796 lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
1677 cpu_to_le16(UDF_MAX_WRITE_VERSION); 1797 if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
1678 if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev)) 1798 lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
1679 lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev); 1799 if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
1680 if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev)) 1800 lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
1681 lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev); 1801 lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
1682 lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE); 1802
1683 1803 lvid->descTag.descCRC = cpu_to_le16(
1684 lvid->descTag.descCRC = cpu_to_le16( 1804 crc_itu_t(0, (char *)lvid + sizeof(tag),
1685 udf_crc((char *)lvid + sizeof(tag), 1805 le16_to_cpu(lvid->descTag.descCRCLength)));
1686 le16_to_cpu(lvid->descTag.descCRCLength), 1806
1687 0)); 1807 lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
1688 1808 mark_buffer_dirty(bh);
1689 lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
1690 mark_buffer_dirty(bh);
1691 }
1692} 1809}
1693 1810
1694static void udf_sb_free_bitmap(struct udf_bitmap *bitmap) 1811static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
@@ -1708,22 +1825,35 @@ static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
1708 vfree(bitmap); 1825 vfree(bitmap);
1709} 1826}
1710 1827
1711/* 1828static void udf_free_partition(struct udf_part_map *map)
1712 * udf_read_super 1829{
1713 * 1830 int i;
1714 * PURPOSE 1831 struct udf_meta_data *mdata;
1715 * Complete the specified super block. 1832
1716 * 1833 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
1717 * PRE-CONDITIONS 1834 iput(map->s_uspace.s_table);
1718 * sb Pointer to superblock to complete - never NULL. 1835 if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
1719 * sb->s_dev Device to read suberblock from. 1836 iput(map->s_fspace.s_table);
1720 * options Pointer to mount options. 1837 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
1721 * silent Silent flag. 1838 udf_sb_free_bitmap(map->s_uspace.s_bitmap);
1722 * 1839 if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
1723 * HISTORY 1840 udf_sb_free_bitmap(map->s_fspace.s_bitmap);
1724 * July 1, 1997 - Andrew E. Mileski 1841 if (map->s_partition_type == UDF_SPARABLE_MAP15)
1725 * Written, tested, and released. 1842 for (i = 0; i < 4; i++)
1726 */ 1843 brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
1844 else if (map->s_partition_type == UDF_METADATA_MAP25) {
1845 mdata = &map->s_type_specific.s_metadata;
1846 iput(mdata->s_metadata_fe);
1847 mdata->s_metadata_fe = NULL;
1848
1849 iput(mdata->s_mirror_fe);
1850 mdata->s_mirror_fe = NULL;
1851
1852 iput(mdata->s_bitmap_fe);
1853 mdata->s_bitmap_fe = NULL;
1854 }
1855}
1856
1727static int udf_fill_super(struct super_block *sb, void *options, int silent) 1857static int udf_fill_super(struct super_block *sb, void *options, int silent)
1728{ 1858{
1729 int i; 1859 int i;
@@ -1776,8 +1906,11 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1776 sbi->s_nls_map = uopt.nls_map; 1906 sbi->s_nls_map = uopt.nls_map;
1777 1907
1778 /* Set the block size for all transfers */ 1908 /* Set the block size for all transfers */
1779 if (!udf_set_blocksize(sb, uopt.blocksize)) 1909 if (!sb_min_blocksize(sb, uopt.blocksize)) {
1910 udf_debug("Bad block size (%d)\n", uopt.blocksize);
1911 printk(KERN_ERR "udf: bad block size (%d)\n", uopt.blocksize);
1780 goto error_out; 1912 goto error_out;
1913 }
1781 1914
1782 if (uopt.session == 0xFFFFFFFF) 1915 if (uopt.session == 0xFFFFFFFF)
1783 sbi->s_session = udf_get_last_session(sb); 1916 sbi->s_session = udf_get_last_session(sb);
@@ -1789,7 +1922,6 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1789 sbi->s_last_block = uopt.lastblock; 1922 sbi->s_last_block = uopt.lastblock;
1790 sbi->s_anchor[0] = sbi->s_anchor[1] = 0; 1923 sbi->s_anchor[0] = sbi->s_anchor[1] = 0;
1791 sbi->s_anchor[2] = uopt.anchor; 1924 sbi->s_anchor[2] = uopt.anchor;
1792 sbi->s_anchor[3] = 256;
1793 1925
1794 if (udf_check_valid(sb, uopt.novrs, silent)) { 1926 if (udf_check_valid(sb, uopt.novrs, silent)) {
1795 /* read volume recognition sequences */ 1927 /* read volume recognition sequences */
@@ -1806,7 +1938,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1806 sb->s_magic = UDF_SUPER_MAGIC; 1938 sb->s_magic = UDF_SUPER_MAGIC;
1807 sb->s_time_gran = 1000; 1939 sb->s_time_gran = 1000;
1808 1940
1809 if (udf_load_partition(sb, &fileset)) { 1941 if (udf_load_sequence(sb, &fileset)) {
1810 printk(KERN_WARNING "UDF-fs: No partition found (1)\n"); 1942 printk(KERN_WARNING "UDF-fs: No partition found (1)\n");
1811 goto error_out; 1943 goto error_out;
1812 } 1944 }
@@ -1856,12 +1988,12 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1856 } 1988 }
1857 1989
1858 if (!silent) { 1990 if (!silent) {
1859 kernel_timestamp ts; 1991 timestamp ts;
1860 udf_time_to_stamp(&ts, sbi->s_record_time); 1992 udf_time_to_disk_stamp(&ts, sbi->s_record_time);
1861 udf_info("UDF: Mounting volume '%s', " 1993 udf_info("UDF: Mounting volume '%s', "
1862 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n", 1994 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1863 sbi->s_volume_ident, ts.year, ts.month, ts.day, 1995 sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
1864 ts.hour, ts.minute, ts.typeAndTimezone); 1996 ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
1865 } 1997 }
1866 if (!(sb->s_flags & MS_RDONLY)) 1998 if (!(sb->s_flags & MS_RDONLY))
1867 udf_open_lvid(sb); 1999 udf_open_lvid(sb);
@@ -1890,21 +2022,9 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1890error_out: 2022error_out:
1891 if (sbi->s_vat_inode) 2023 if (sbi->s_vat_inode)
1892 iput(sbi->s_vat_inode); 2024 iput(sbi->s_vat_inode);
1893 if (sbi->s_partitions) { 2025 if (sbi->s_partitions)
1894 struct udf_part_map *map = &sbi->s_partmaps[sbi->s_partition]; 2026 for (i = 0; i < sbi->s_partitions; i++)
1895 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) 2027 udf_free_partition(&sbi->s_partmaps[i]);
1896 iput(map->s_uspace.s_table);
1897 if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
1898 iput(map->s_fspace.s_table);
1899 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
1900 udf_sb_free_bitmap(map->s_uspace.s_bitmap);
1901 if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
1902 udf_sb_free_bitmap(map->s_fspace.s_bitmap);
1903 if (map->s_partition_type == UDF_SPARABLE_MAP15)
1904 for (i = 0; i < 4; i++)
1905 brelse(map->s_type_specific.s_sparing.
1906 s_spar_map[i]);
1907 }
1908#ifdef CONFIG_UDF_NLS 2028#ifdef CONFIG_UDF_NLS
1909 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) 2029 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1910 unload_nls(sbi->s_nls_map); 2030 unload_nls(sbi->s_nls_map);
@@ -1920,8 +2040,8 @@ error_out:
1920 return -EINVAL; 2040 return -EINVAL;
1921} 2041}
1922 2042
1923void udf_error(struct super_block *sb, const char *function, 2043static void udf_error(struct super_block *sb, const char *function,
1924 const char *fmt, ...) 2044 const char *fmt, ...)
1925{ 2045{
1926 va_list args; 2046 va_list args;
1927 2047
@@ -1948,19 +2068,6 @@ void udf_warning(struct super_block *sb, const char *function,
1948 sb->s_id, function, error_buf); 2068 sb->s_id, function, error_buf);
1949} 2069}
1950 2070
1951/*
1952 * udf_put_super
1953 *
1954 * PURPOSE
1955 * Prepare for destruction of the superblock.
1956 *
1957 * DESCRIPTION
1958 * Called before the filesystem is unmounted.
1959 *
1960 * HISTORY
1961 * July 1, 1997 - Andrew E. Mileski
1962 * Written, tested, and released.
1963 */
1964static void udf_put_super(struct super_block *sb) 2071static void udf_put_super(struct super_block *sb)
1965{ 2072{
1966 int i; 2073 int i;
@@ -1969,21 +2076,9 @@ static void udf_put_super(struct super_block *sb)
1969 sbi = UDF_SB(sb); 2076 sbi = UDF_SB(sb);
1970 if (sbi->s_vat_inode) 2077 if (sbi->s_vat_inode)
1971 iput(sbi->s_vat_inode); 2078 iput(sbi->s_vat_inode);
1972 if (sbi->s_partitions) { 2079 if (sbi->s_partitions)
1973 struct udf_part_map *map = &sbi->s_partmaps[sbi->s_partition]; 2080 for (i = 0; i < sbi->s_partitions; i++)
1974 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) 2081 udf_free_partition(&sbi->s_partmaps[i]);
1975 iput(map->s_uspace.s_table);
1976 if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
1977 iput(map->s_fspace.s_table);
1978 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
1979 udf_sb_free_bitmap(map->s_uspace.s_bitmap);
1980 if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
1981 udf_sb_free_bitmap(map->s_fspace.s_bitmap);
1982 if (map->s_partition_type == UDF_SPARABLE_MAP15)
1983 for (i = 0; i < 4; i++)
1984 brelse(map->s_type_specific.s_sparing.
1985 s_spar_map[i]);
1986 }
1987#ifdef CONFIG_UDF_NLS 2082#ifdef CONFIG_UDF_NLS
1988 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) 2083 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1989 unload_nls(sbi->s_nls_map); 2084 unload_nls(sbi->s_nls_map);
@@ -1996,19 +2091,6 @@ static void udf_put_super(struct super_block *sb)
1996 sb->s_fs_info = NULL; 2091 sb->s_fs_info = NULL;
1997} 2092}
1998 2093
1999/*
2000 * udf_stat_fs
2001 *
2002 * PURPOSE
2003 * Return info about the filesystem.
2004 *
2005 * DESCRIPTION
2006 * Called by sys_statfs()
2007 *
2008 * HISTORY
2009 * July 1, 1997 - Andrew E. Mileski
2010 * Written, tested, and released.
2011 */
2012static int udf_statfs(struct dentry *dentry, struct kstatfs *buf) 2094static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
2013{ 2095{
2014 struct super_block *sb = dentry->d_sb; 2096 struct super_block *sb = dentry->d_sb;
@@ -2035,10 +2117,6 @@ static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
2035 return 0; 2117 return 0;
2036} 2118}
2037 2119
2038static unsigned char udf_bitmap_lookup[16] = {
2039 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
2040};
2041
2042static unsigned int udf_count_free_bitmap(struct super_block *sb, 2120static unsigned int udf_count_free_bitmap(struct super_block *sb,
2043 struct udf_bitmap *bitmap) 2121 struct udf_bitmap *bitmap)
2044{ 2122{
@@ -2048,7 +2126,6 @@ static unsigned int udf_count_free_bitmap(struct super_block *sb,
2048 int block = 0, newblock; 2126 int block = 0, newblock;
2049 kernel_lb_addr loc; 2127 kernel_lb_addr loc;
2050 uint32_t bytes; 2128 uint32_t bytes;
2051 uint8_t value;
2052 uint8_t *ptr; 2129 uint8_t *ptr;
2053 uint16_t ident; 2130 uint16_t ident;
2054 struct spaceBitmapDesc *bm; 2131 struct spaceBitmapDesc *bm;
@@ -2074,13 +2151,10 @@ static unsigned int udf_count_free_bitmap(struct super_block *sb,
2074 ptr = (uint8_t *)bh->b_data; 2151 ptr = (uint8_t *)bh->b_data;
2075 2152
2076 while (bytes > 0) { 2153 while (bytes > 0) {
2077 while ((bytes > 0) && (index < sb->s_blocksize)) { 2154 u32 cur_bytes = min_t(u32, bytes, sb->s_blocksize - index);
2078 value = ptr[index]; 2155 accum += bitmap_weight((const unsigned long *)(ptr + index),
2079 accum += udf_bitmap_lookup[value & 0x0f]; 2156 cur_bytes * 8);
2080 accum += udf_bitmap_lookup[value >> 4]; 2157 bytes -= cur_bytes;
2081 index++;
2082 bytes--;
2083 }
2084 if (bytes) { 2158 if (bytes) {
2085 brelse(bh); 2159 brelse(bh);
2086 newblock = udf_get_lb_pblock(sb, loc, ++block); 2160 newblock = udf_get_lb_pblock(sb, loc, ++block);
diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c
index 6ec99221e50c..c3265e1385d4 100644
--- a/fs/udf/symlink.c
+++ b/fs/udf/symlink.c
@@ -23,7 +23,6 @@
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/fs.h> 25#include <linux/fs.h>
26#include <linux/udf_fs.h>
27#include <linux/time.h> 26#include <linux/time.h>
28#include <linux/mm.h> 27#include <linux/mm.h>
29#include <linux/stat.h> 28#include <linux/stat.h>
diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c
index fe61be17cdab..65e19b4f9424 100644
--- a/fs/udf/truncate.c
+++ b/fs/udf/truncate.c
@@ -22,7 +22,6 @@
22#include "udfdecl.h" 22#include "udfdecl.h"
23#include <linux/fs.h> 23#include <linux/fs.h>
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/udf_fs.h>
26#include <linux/buffer_head.h> 25#include <linux/buffer_head.h>
27 26
28#include "udf_i.h" 27#include "udf_i.h"
@@ -180,6 +179,24 @@ void udf_discard_prealloc(struct inode *inode)
180 brelse(epos.bh); 179 brelse(epos.bh);
181} 180}
182 181
182static void udf_update_alloc_ext_desc(struct inode *inode,
183 struct extent_position *epos,
184 u32 lenalloc)
185{
186 struct super_block *sb = inode->i_sb;
187 struct udf_sb_info *sbi = UDF_SB(sb);
188
189 struct allocExtDesc *aed = (struct allocExtDesc *) (epos->bh->b_data);
190 int len = sizeof(struct allocExtDesc);
191
192 aed->lengthAllocDescs = cpu_to_le32(lenalloc);
193 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || sbi->s_udfrev >= 0x0201)
194 len += lenalloc;
195
196 udf_update_tag(epos->bh->b_data, len);
197 mark_buffer_dirty_inode(epos->bh, inode);
198}
199
183void udf_truncate_extents(struct inode *inode) 200void udf_truncate_extents(struct inode *inode)
184{ 201{
185 struct extent_position epos; 202 struct extent_position epos;
@@ -187,7 +204,6 @@ void udf_truncate_extents(struct inode *inode)
187 uint32_t elen, nelen = 0, indirect_ext_len = 0, lenalloc; 204 uint32_t elen, nelen = 0, indirect_ext_len = 0, lenalloc;
188 int8_t etype; 205 int8_t etype;
189 struct super_block *sb = inode->i_sb; 206 struct super_block *sb = inode->i_sb;
190 struct udf_sb_info *sbi = UDF_SB(sb);
191 sector_t first_block = inode->i_size >> sb->s_blocksize_bits, offset; 207 sector_t first_block = inode->i_size >> sb->s_blocksize_bits, offset;
192 loff_t byte_offset; 208 loff_t byte_offset;
193 int adsize; 209 int adsize;
@@ -224,35 +240,15 @@ void udf_truncate_extents(struct inode *inode)
224 if (indirect_ext_len) { 240 if (indirect_ext_len) {
225 /* We managed to free all extents in the 241 /* We managed to free all extents in the
226 * indirect extent - free it too */ 242 * indirect extent - free it too */
227 if (!epos.bh) 243 BUG_ON(!epos.bh);
228 BUG();
229 udf_free_blocks(sb, inode, epos.block, 244 udf_free_blocks(sb, inode, epos.block,
230 0, indirect_ext_len); 245 0, indirect_ext_len);
231 } else { 246 } else if (!epos.bh) {
232 if (!epos.bh) { 247 iinfo->i_lenAlloc = lenalloc;
233 iinfo->i_lenAlloc = 248 mark_inode_dirty(inode);
234 lenalloc; 249 } else
235 mark_inode_dirty(inode); 250 udf_update_alloc_ext_desc(inode,
236 } else { 251 &epos, lenalloc);
237 struct allocExtDesc *aed =
238 (struct allocExtDesc *)
239 (epos.bh->b_data);
240 int len =
241 sizeof(struct allocExtDesc);
242
243 aed->lengthAllocDescs =
244 cpu_to_le32(lenalloc);
245 if (!UDF_QUERY_FLAG(sb,
246 UDF_FLAG_STRICT) ||
247 sbi->s_udfrev >= 0x0201)
248 len += lenalloc;
249
250 udf_update_tag(epos.bh->b_data,
251 len);
252 mark_buffer_dirty_inode(
253 epos.bh, inode);
254 }
255 }
256 brelse(epos.bh); 252 brelse(epos.bh);
257 epos.offset = sizeof(struct allocExtDesc); 253 epos.offset = sizeof(struct allocExtDesc);
258 epos.block = eloc; 254 epos.block = eloc;
@@ -272,29 +268,14 @@ void udf_truncate_extents(struct inode *inode)
272 } 268 }
273 269
274 if (indirect_ext_len) { 270 if (indirect_ext_len) {
275 if (!epos.bh) 271 BUG_ON(!epos.bh);
276 BUG();
277 udf_free_blocks(sb, inode, epos.block, 0, 272 udf_free_blocks(sb, inode, epos.block, 0,
278 indirect_ext_len); 273 indirect_ext_len);
279 } else { 274 } else if (!epos.bh) {
280 if (!epos.bh) { 275 iinfo->i_lenAlloc = lenalloc;
281 iinfo->i_lenAlloc = lenalloc; 276 mark_inode_dirty(inode);
282 mark_inode_dirty(inode); 277 } else
283 } else { 278 udf_update_alloc_ext_desc(inode, &epos, lenalloc);
284 struct allocExtDesc *aed =
285 (struct allocExtDesc *)(epos.bh->b_data);
286 aed->lengthAllocDescs = cpu_to_le32(lenalloc);
287 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) ||
288 sbi->s_udfrev >= 0x0201)
289 udf_update_tag(epos.bh->b_data,
290 lenalloc +
291 sizeof(struct allocExtDesc));
292 else
293 udf_update_tag(epos.bh->b_data,
294 sizeof(struct allocExtDesc));
295 mark_buffer_dirty_inode(epos.bh, inode);
296 }
297 }
298 } else if (inode->i_size) { 279 } else if (inode->i_size) {
299 if (byte_offset) { 280 if (byte_offset) {
300 kernel_long_ad extent; 281 kernel_long_ad extent;
diff --git a/fs/udf/udf_i.h b/fs/udf/udf_i.h
index ccc52f16bf7d..4f86b1d98a5d 100644
--- a/fs/udf/udf_i.h
+++ b/fs/udf/udf_i.h
@@ -1,10 +1,32 @@
1#ifndef __LINUX_UDF_I_H 1#ifndef _UDF_I_H
2#define __LINUX_UDF_I_H 2#define _UDF_I_H
3
4struct udf_inode_info {
5 struct timespec i_crtime;
6 /* Physical address of inode */
7 kernel_lb_addr i_location;
8 __u64 i_unique;
9 __u32 i_lenEAttr;
10 __u32 i_lenAlloc;
11 __u64 i_lenExtents;
12 __u32 i_next_alloc_block;
13 __u32 i_next_alloc_goal;
14 unsigned i_alloc_type : 3;
15 unsigned i_efe : 1; /* extendedFileEntry */
16 unsigned i_use : 1; /* unallocSpaceEntry */
17 unsigned i_strat4096 : 1;
18 unsigned reserved : 26;
19 union {
20 short_ad *i_sad;
21 long_ad *i_lad;
22 __u8 *i_data;
23 } i_ext;
24 struct inode vfs_inode;
25};
3 26
4#include <linux/udf_fs_i.h>
5static inline struct udf_inode_info *UDF_I(struct inode *inode) 27static inline struct udf_inode_info *UDF_I(struct inode *inode)
6{ 28{
7 return list_entry(inode, struct udf_inode_info, vfs_inode); 29 return list_entry(inode, struct udf_inode_info, vfs_inode);
8} 30}
9 31
10#endif /* !defined(_LINUX_UDF_I_H) */ 32#endif /* _UDF_I_H) */
diff --git a/fs/udf/udf_sb.h b/fs/udf/udf_sb.h
index 737d1c604eea..1c1c514a9725 100644
--- a/fs/udf/udf_sb.h
+++ b/fs/udf/udf_sb.h
@@ -1,10 +1,12 @@
1#ifndef __LINUX_UDF_SB_H 1#ifndef __LINUX_UDF_SB_H
2#define __LINUX_UDF_SB_H 2#define __LINUX_UDF_SB_H
3 3
4#include <linux/mutex.h>
5
4/* Since UDF 2.01 is ISO 13346 based... */ 6/* Since UDF 2.01 is ISO 13346 based... */
5#define UDF_SUPER_MAGIC 0x15013346 7#define UDF_SUPER_MAGIC 0x15013346
6 8
7#define UDF_MAX_READ_VERSION 0x0201 9#define UDF_MAX_READ_VERSION 0x0250
8#define UDF_MAX_WRITE_VERSION 0x0201 10#define UDF_MAX_WRITE_VERSION 0x0201
9 11
10#define UDF_FLAG_USE_EXTENDED_FE 0 12#define UDF_FLAG_USE_EXTENDED_FE 0
@@ -38,6 +40,111 @@
38#define UDF_PART_FLAG_REWRITABLE 0x0040 40#define UDF_PART_FLAG_REWRITABLE 0x0040
39#define UDF_PART_FLAG_OVERWRITABLE 0x0080 41#define UDF_PART_FLAG_OVERWRITABLE 0x0080
40 42
43#define UDF_MAX_BLOCK_LOADED 8
44
45#define UDF_TYPE1_MAP15 0x1511U
46#define UDF_VIRTUAL_MAP15 0x1512U
47#define UDF_VIRTUAL_MAP20 0x2012U
48#define UDF_SPARABLE_MAP15 0x1522U
49#define UDF_METADATA_MAP25 0x2511U
50
51#pragma pack(1) /* XXX(hch): Why? This file just defines in-core structures */
52
53struct udf_meta_data {
54 __u32 s_meta_file_loc;
55 __u32 s_mirror_file_loc;
56 __u32 s_bitmap_file_loc;
57 __u32 s_alloc_unit_size;
58 __u16 s_align_unit_size;
59 __u8 s_dup_md_flag;
60 struct inode *s_metadata_fe;
61 struct inode *s_mirror_fe;
62 struct inode *s_bitmap_fe;
63};
64
65struct udf_sparing_data {
66 __u16 s_packet_len;
67 struct buffer_head *s_spar_map[4];
68};
69
70struct udf_virtual_data {
71 __u32 s_num_entries;
72 __u16 s_start_offset;
73};
74
75struct udf_bitmap {
76 __u32 s_extLength;
77 __u32 s_extPosition;
78 __u16 s_nr_groups;
79 struct buffer_head **s_block_bitmap;
80};
81
82struct udf_part_map {
83 union {
84 struct udf_bitmap *s_bitmap;
85 struct inode *s_table;
86 } s_uspace;
87 union {
88 struct udf_bitmap *s_bitmap;
89 struct inode *s_table;
90 } s_fspace;
91 __u32 s_partition_root;
92 __u32 s_partition_len;
93 __u16 s_partition_type;
94 __u16 s_partition_num;
95 union {
96 struct udf_sparing_data s_sparing;
97 struct udf_virtual_data s_virtual;
98 struct udf_meta_data s_metadata;
99 } s_type_specific;
100 __u32 (*s_partition_func)(struct super_block *, __u32, __u16, __u32);
101 __u16 s_volumeseqnum;
102 __u16 s_partition_flags;
103};
104
105#pragma pack()
106
107struct udf_sb_info {
108 struct udf_part_map *s_partmaps;
109 __u8 s_volume_ident[32];
110
111 /* Overall info */
112 __u16 s_partitions;
113 __u16 s_partition;
114
115 /* Sector headers */
116 __s32 s_session;
117 __u32 s_anchor[3];
118 __u32 s_last_block;
119
120 struct buffer_head *s_lvid_bh;
121
122 /* Default permissions */
123 mode_t s_umask;
124 gid_t s_gid;
125 uid_t s_uid;
126
127 /* Root Info */
128 struct timespec s_record_time;
129
130 /* Fileset Info */
131 __u16 s_serial_number;
132
133 /* highest UDF revision we have recorded to this media */
134 __u16 s_udfrev;
135
136 /* Miscellaneous flags */
137 __u32 s_flags;
138
139 /* Encoding info */
140 struct nls_table *s_nls_map;
141
142 /* VAT inode */
143 struct inode *s_vat_inode;
144
145 struct mutex s_alloc_mutex;
146};
147
41static inline struct udf_sb_info *UDF_SB(struct super_block *sb) 148static inline struct udf_sb_info *UDF_SB(struct super_block *sb)
42{ 149{
43 return sb->s_fs_info; 150 return sb->s_fs_info;
diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
index 681dc2b66cdb..f3f45d029277 100644
--- a/fs/udf/udfdecl.h
+++ b/fs/udf/udfdecl.h
@@ -1,17 +1,37 @@
1#ifndef __UDF_DECL_H 1#ifndef __UDF_DECL_H
2#define __UDF_DECL_H 2#define __UDF_DECL_H
3 3
4#include <linux/udf_fs.h>
5#include "ecma_167.h" 4#include "ecma_167.h"
6#include "osta_udf.h" 5#include "osta_udf.h"
7 6
8#include <linux/fs.h> 7#include <linux/fs.h>
9#include <linux/types.h> 8#include <linux/types.h>
10#include <linux/udf_fs_i.h>
11#include <linux/udf_fs_sb.h>
12#include <linux/buffer_head.h> 9#include <linux/buffer_head.h>
10#include <linux/udf_fs_i.h>
13 11
12#include "udf_sb.h"
14#include "udfend.h" 13#include "udfend.h"
14#include "udf_i.h"
15
16#define UDF_PREALLOCATE
17#define UDF_DEFAULT_PREALLOC_BLOCKS 8
18
19#define UDFFS_DEBUG
20
21#ifdef UDFFS_DEBUG
22#define udf_debug(f, a...) \
23do { \
24 printk(KERN_DEBUG "UDF-fs DEBUG %s:%d:%s: ", \
25 __FILE__, __LINE__, __func__); \
26 printk(f, ##a); \
27} while (0)
28#else
29#define udf_debug(f, a...) /**/
30#endif
31
32#define udf_info(f, a...) \
33 printk(KERN_INFO "UDF-fs INFO " f, ##a);
34
15 35
16#define udf_fixed_to_variable(x) ( ( ( (x) >> 5 ) * 39 ) + ( (x) & 0x0000001F ) ) 36#define udf_fixed_to_variable(x) ( ( ( (x) >> 5 ) * 39 ) + ( (x) & 0x0000001F ) )
17#define udf_variable_to_fixed(x) ( ( ( (x) / 39 ) << 5 ) + ( (x) % 39 ) ) 37#define udf_variable_to_fixed(x) ( ( ( (x) / 39 ) << 5 ) + ( (x) % 39 ) )
@@ -23,16 +43,24 @@
23#define UDF_NAME_LEN 256 43#define UDF_NAME_LEN 256
24#define UDF_PATH_LEN 1023 44#define UDF_PATH_LEN 1023
25 45
26#define udf_file_entry_alloc_offset(inode)\ 46static inline size_t udf_file_entry_alloc_offset(struct inode *inode)
27 (UDF_I(inode)->i_use ?\ 47{
28 sizeof(struct unallocSpaceEntry) :\ 48 struct udf_inode_info *iinfo = UDF_I(inode);
29 ((UDF_I(inode)->i_efe ?\ 49 if (iinfo->i_use)
30 sizeof(struct extendedFileEntry) :\ 50 return sizeof(struct unallocSpaceEntry);
31 sizeof(struct fileEntry)) + UDF_I(inode)->i_lenEAttr)) 51 else if (iinfo->i_efe)
32 52 return sizeof(struct extendedFileEntry) + iinfo->i_lenEAttr;
33#define udf_ext0_offset(inode)\ 53 else
34 (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB ?\ 54 return sizeof(struct fileEntry) + iinfo->i_lenEAttr;
35 udf_file_entry_alloc_offset(inode) : 0) 55}
56
57static inline size_t udf_ext0_offset(struct inode *inode)
58{
59 if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
60 return udf_file_entry_alloc_offset(inode);
61 else
62 return 0;
63}
36 64
37#define udf_get_lb_pblock(sb,loc,offset) udf_get_pblock((sb), (loc).logicalBlockNum, (loc).partitionReferenceNum, (offset)) 65#define udf_get_lb_pblock(sb,loc,offset) udf_get_pblock((sb), (loc).logicalBlockNum, (loc).partitionReferenceNum, (offset))
38 66
@@ -83,7 +111,6 @@ struct extent_position {
83}; 111};
84 112
85/* super.c */ 113/* super.c */
86extern void udf_error(struct super_block *, const char *, const char *, ...);
87extern void udf_warning(struct super_block *, const char *, const char *, ...); 114extern void udf_warning(struct super_block *, const char *, const char *, ...);
88 115
89/* namei.c */ 116/* namei.c */
@@ -150,6 +177,8 @@ extern uint32_t udf_get_pblock_virt20(struct super_block *, uint32_t, uint16_t,
150 uint32_t); 177 uint32_t);
151extern uint32_t udf_get_pblock_spar15(struct super_block *, uint32_t, uint16_t, 178extern uint32_t udf_get_pblock_spar15(struct super_block *, uint32_t, uint16_t,
152 uint32_t); 179 uint32_t);
180extern uint32_t udf_get_pblock_meta25(struct super_block *, uint32_t, uint16_t,
181 uint32_t);
153extern int udf_relocate_blocks(struct super_block *, long, long *); 182extern int udf_relocate_blocks(struct super_block *, long, long *);
154 183
155/* unicode.c */ 184/* unicode.c */
@@ -157,7 +186,7 @@ extern int udf_get_filename(struct super_block *, uint8_t *, uint8_t *, int);
157extern int udf_put_filename(struct super_block *, const uint8_t *, uint8_t *, 186extern int udf_put_filename(struct super_block *, const uint8_t *, uint8_t *,
158 int); 187 int);
159extern int udf_build_ustr(struct ustr *, dstring *, int); 188extern int udf_build_ustr(struct ustr *, dstring *, int);
160extern int udf_CS0toUTF8(struct ustr *, struct ustr *); 189extern int udf_CS0toUTF8(struct ustr *, const struct ustr *);
161 190
162/* ialloc.c */ 191/* ialloc.c */
163extern void udf_free_inode(struct inode *); 192extern void udf_free_inode(struct inode *);
@@ -191,11 +220,9 @@ extern struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize,
191extern long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int); 220extern long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int);
192extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int); 221extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
193 222
194/* crc.c */
195extern uint16_t udf_crc(uint8_t *, uint32_t, uint16_t);
196
197/* udftime.c */ 223/* udftime.c */
198extern time_t *udf_stamp_to_time(time_t *, long *, kernel_timestamp); 224extern struct timespec *udf_disk_stamp_to_time(struct timespec *dest,
199extern kernel_timestamp *udf_time_to_stamp(kernel_timestamp *, struct timespec); 225 timestamp src);
226extern timestamp *udf_time_to_disk_stamp(timestamp *dest, struct timespec src);
200 227
201#endif /* __UDF_DECL_H */ 228#endif /* __UDF_DECL_H */
diff --git a/fs/udf/udfend.h b/fs/udf/udfend.h
index c4bd1203f857..489f52fb428c 100644
--- a/fs/udf/udfend.h
+++ b/fs/udf/udfend.h
@@ -24,17 +24,6 @@ static inline lb_addr cpu_to_lelb(kernel_lb_addr in)
24 return out; 24 return out;
25} 25}
26 26
27static inline kernel_timestamp lets_to_cpu(timestamp in)
28{
29 kernel_timestamp out;
30
31 memcpy(&out, &in, sizeof(timestamp));
32 out.typeAndTimezone = le16_to_cpu(in.typeAndTimezone);
33 out.year = le16_to_cpu(in.year);
34
35 return out;
36}
37
38static inline short_ad lesa_to_cpu(short_ad in) 27static inline short_ad lesa_to_cpu(short_ad in)
39{ 28{
40 short_ad out; 29 short_ad out;
@@ -85,15 +74,4 @@ static inline kernel_extent_ad leea_to_cpu(extent_ad in)
85 return out; 74 return out;
86} 75}
87 76
88static inline timestamp cpu_to_lets(kernel_timestamp in)
89{
90 timestamp out;
91
92 memcpy(&out, &in, sizeof(timestamp));
93 out.typeAndTimezone = cpu_to_le16(in.typeAndTimezone);
94 out.year = cpu_to_le16(in.year);
95
96 return out;
97}
98
99#endif /* __UDF_ENDIAN_H */ 77#endif /* __UDF_ENDIAN_H */
diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c
index ce595732ba6f..5f811655c9b5 100644
--- a/fs/udf/udftime.c
+++ b/fs/udf/udftime.c
@@ -85,39 +85,38 @@ extern struct timezone sys_tz;
85#define SECS_PER_HOUR (60 * 60) 85#define SECS_PER_HOUR (60 * 60)
86#define SECS_PER_DAY (SECS_PER_HOUR * 24) 86#define SECS_PER_DAY (SECS_PER_HOUR * 24)
87 87
88time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src) 88struct timespec *udf_disk_stamp_to_time(struct timespec *dest, timestamp src)
89{ 89{
90 int yday; 90 int yday;
91 uint8_t type = src.typeAndTimezone >> 12; 91 u16 typeAndTimezone = le16_to_cpu(src.typeAndTimezone);
92 u16 year = le16_to_cpu(src.year);
93 uint8_t type = typeAndTimezone >> 12;
92 int16_t offset; 94 int16_t offset;
93 95
94 if (type == 1) { 96 if (type == 1) {
95 offset = src.typeAndTimezone << 4; 97 offset = typeAndTimezone << 4;
96 /* sign extent offset */ 98 /* sign extent offset */
97 offset = (offset >> 4); 99 offset = (offset >> 4);
98 if (offset == -2047) /* unspecified offset */ 100 if (offset == -2047) /* unspecified offset */
99 offset = 0; 101 offset = 0;
100 } else { 102 } else
101 offset = 0; 103 offset = 0;
102 }
103 104
104 if ((src.year < EPOCH_YEAR) || 105 if ((year < EPOCH_YEAR) ||
105 (src.year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) { 106 (year >= EPOCH_YEAR + MAX_YEAR_SECONDS)) {
106 *dest = -1;
107 *dest_usec = -1;
108 return NULL; 107 return NULL;
109 } 108 }
110 *dest = year_seconds[src.year - EPOCH_YEAR]; 109 dest->tv_sec = year_seconds[year - EPOCH_YEAR];
111 *dest -= offset * 60; 110 dest->tv_sec -= offset * 60;
112 111
113 yday = ((__mon_yday[__isleap(src.year)][src.month - 1]) + src.day - 1); 112 yday = ((__mon_yday[__isleap(year)][src.month - 1]) + src.day - 1);
114 *dest += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second; 113 dest->tv_sec += (((yday * 24) + src.hour) * 60 + src.minute) * 60 + src.second;
115 *dest_usec = src.centiseconds * 10000 + 114 dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
116 src.hundredsOfMicroseconds * 100 + src.microseconds; 115 src.hundredsOfMicroseconds * 100 + src.microseconds);
117 return dest; 116 return dest;
118} 117}
119 118
120kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts) 119timestamp *udf_time_to_disk_stamp(timestamp *dest, struct timespec ts)
121{ 120{
122 long int days, rem, y; 121 long int days, rem, y;
123 const unsigned short int *ip; 122 const unsigned short int *ip;
@@ -128,7 +127,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
128 if (!dest) 127 if (!dest)
129 return NULL; 128 return NULL;
130 129
131 dest->typeAndTimezone = 0x1000 | (offset & 0x0FFF); 130 dest->typeAndTimezone = cpu_to_le16(0x1000 | (offset & 0x0FFF));
132 131
133 ts.tv_sec += offset * 60; 132 ts.tv_sec += offset * 60;
134 days = ts.tv_sec / SECS_PER_DAY; 133 days = ts.tv_sec / SECS_PER_DAY;
@@ -151,7 +150,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
151 - LEAPS_THRU_END_OF(y - 1)); 150 - LEAPS_THRU_END_OF(y - 1));
152 y = yg; 151 y = yg;
153 } 152 }
154 dest->year = y; 153 dest->year = cpu_to_le16(y);
155 ip = __mon_yday[__isleap(y)]; 154 ip = __mon_yday[__isleap(y)];
156 for (y = 11; days < (long int)ip[y]; --y) 155 for (y = 11; days < (long int)ip[y]; --y)
157 continue; 156 continue;
diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c
index e533b11703bf..9fdf8c93c58e 100644
--- a/fs/udf/unicode.c
+++ b/fs/udf/unicode.c
@@ -23,7 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/string.h> /* for memset */ 24#include <linux/string.h> /* for memset */
25#include <linux/nls.h> 25#include <linux/nls.h>
26#include <linux/udf_fs.h> 26#include <linux/crc-itu-t.h>
27 27
28#include "udf_sb.h" 28#include "udf_sb.h"
29 29
@@ -49,14 +49,16 @@ int udf_build_ustr(struct ustr *dest, dstring *ptr, int size)
49{ 49{
50 int usesize; 50 int usesize;
51 51
52 if ((!dest) || (!ptr) || (!size)) 52 if (!dest || !ptr || !size)
53 return -1; 53 return -1;
54 BUG_ON(size < 2);
54 55
55 memset(dest, 0, sizeof(struct ustr)); 56 usesize = min_t(size_t, ptr[size - 1], sizeof(dest->u_name));
56 usesize = (size > UDF_NAME_LEN) ? UDF_NAME_LEN : size; 57 usesize = min(usesize, size - 2);
57 dest->u_cmpID = ptr[0]; 58 dest->u_cmpID = ptr[0];
58 dest->u_len = ptr[size - 1]; 59 dest->u_len = usesize;
59 memcpy(dest->u_name, ptr + 1, usesize - 1); 60 memcpy(dest->u_name, ptr + 1, usesize);
61 memset(dest->u_name + usesize, 0, sizeof(dest->u_name) - usesize);
60 62
61 return 0; 63 return 0;
62} 64}
@@ -83,9 +85,6 @@ static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize)
83 * PURPOSE 85 * PURPOSE
84 * Convert OSTA Compressed Unicode to the UTF-8 equivalent. 86 * Convert OSTA Compressed Unicode to the UTF-8 equivalent.
85 * 87 *
86 * DESCRIPTION
87 * This routine is only called by udf_filldir().
88 *
89 * PRE-CONDITIONS 88 * PRE-CONDITIONS
90 * utf Pointer to UTF-8 output buffer. 89 * utf Pointer to UTF-8 output buffer.
91 * ocu Pointer to OSTA Compressed Unicode input buffer 90 * ocu Pointer to OSTA Compressed Unicode input buffer
@@ -99,43 +98,39 @@ static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize)
99 * November 12, 1997 - Andrew E. Mileski 98 * November 12, 1997 - Andrew E. Mileski
100 * Written, tested, and released. 99 * Written, tested, and released.
101 */ 100 */
102int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i) 101int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i)
103{ 102{
104 uint8_t *ocu; 103 const uint8_t *ocu;
105 uint32_t c;
106 uint8_t cmp_id, ocu_len; 104 uint8_t cmp_id, ocu_len;
107 int i; 105 int i;
108 106
109 ocu = ocu_i->u_name;
110
111 ocu_len = ocu_i->u_len; 107 ocu_len = ocu_i->u_len;
112 cmp_id = ocu_i->u_cmpID;
113 utf_o->u_len = 0;
114
115 if (ocu_len == 0) { 108 if (ocu_len == 0) {
116 memset(utf_o, 0, sizeof(struct ustr)); 109 memset(utf_o, 0, sizeof(struct ustr));
117 utf_o->u_cmpID = 0;
118 utf_o->u_len = 0;
119 return 0; 110 return 0;
120 } 111 }
121 112
122 if ((cmp_id != 8) && (cmp_id != 16)) { 113 cmp_id = ocu_i->u_cmpID;
114 if (cmp_id != 8 && cmp_id != 16) {
115 memset(utf_o, 0, sizeof(struct ustr));
123 printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n", 116 printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n",
124 cmp_id, ocu_i->u_name); 117 cmp_id, ocu_i->u_name);
125 return 0; 118 return 0;
126 } 119 }
127 120
121 ocu = ocu_i->u_name;
122 utf_o->u_len = 0;
128 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) { 123 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) {
129 124
130 /* Expand OSTA compressed Unicode to Unicode */ 125 /* Expand OSTA compressed Unicode to Unicode */
131 c = ocu[i++]; 126 uint32_t c = ocu[i++];
132 if (cmp_id == 16) 127 if (cmp_id == 16)
133 c = (c << 8) | ocu[i++]; 128 c = (c << 8) | ocu[i++];
134 129
135 /* Compress Unicode to UTF-8 */ 130 /* Compress Unicode to UTF-8 */
136 if (c < 0x80U) { 131 if (c < 0x80U)
137 utf_o->u_name[utf_o->u_len++] = (uint8_t)c; 132 utf_o->u_name[utf_o->u_len++] = (uint8_t)c;
138 } else if (c < 0x800U) { 133 else if (c < 0x800U) {
139 utf_o->u_name[utf_o->u_len++] = 134 utf_o->u_name[utf_o->u_len++] =
140 (uint8_t)(0xc0 | (c >> 6)); 135 (uint8_t)(0xc0 | (c >> 6));
141 utf_o->u_name[utf_o->u_len++] = 136 utf_o->u_name[utf_o->u_len++] =
@@ -255,35 +250,32 @@ error_out:
255} 250}
256 251
257static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, 252static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o,
258 struct ustr *ocu_i) 253 const struct ustr *ocu_i)
259{ 254{
260 uint8_t *ocu; 255 const uint8_t *ocu;
261 uint32_t c;
262 uint8_t cmp_id, ocu_len; 256 uint8_t cmp_id, ocu_len;
263 int i; 257 int i;
264 258
265 ocu = ocu_i->u_name;
266 259
267 ocu_len = ocu_i->u_len; 260 ocu_len = ocu_i->u_len;
268 cmp_id = ocu_i->u_cmpID;
269 utf_o->u_len = 0;
270
271 if (ocu_len == 0) { 261 if (ocu_len == 0) {
272 memset(utf_o, 0, sizeof(struct ustr)); 262 memset(utf_o, 0, sizeof(struct ustr));
273 utf_o->u_cmpID = 0;
274 utf_o->u_len = 0;
275 return 0; 263 return 0;
276 } 264 }
277 265
278 if ((cmp_id != 8) && (cmp_id != 16)) { 266 cmp_id = ocu_i->u_cmpID;
267 if (cmp_id != 8 && cmp_id != 16) {
268 memset(utf_o, 0, sizeof(struct ustr));
279 printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n", 269 printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n",
280 cmp_id, ocu_i->u_name); 270 cmp_id, ocu_i->u_name);
281 return 0; 271 return 0;
282 } 272 }
283 273
274 ocu = ocu_i->u_name;
275 utf_o->u_len = 0;
284 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) { 276 for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) {
285 /* Expand OSTA compressed Unicode to Unicode */ 277 /* Expand OSTA compressed Unicode to Unicode */
286 c = ocu[i++]; 278 uint32_t c = ocu[i++];
287 if (cmp_id == 16) 279 if (cmp_id == 16)
288 c = (c << 8) | ocu[i++]; 280 c = (c << 8) | ocu[i++];
289 281
@@ -463,7 +455,7 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
463 } else if (newIndex > 250) 455 } else if (newIndex > 250)
464 newIndex = 250; 456 newIndex = 250;
465 newName[newIndex++] = CRC_MARK; 457 newName[newIndex++] = CRC_MARK;
466 valueCRC = udf_crc(fidName, fidNameLen, 0); 458 valueCRC = crc_itu_t(0, fidName, fidNameLen);
467 newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12]; 459 newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12];
468 newName[newIndex++] = hexChar[(valueCRC & 0x0f00) >> 8]; 460 newName[newIndex++] = hexChar[(valueCRC & 0x0f00) >> 8];
469 newName[newIndex++] = hexChar[(valueCRC & 0x00f0) >> 4]; 461 newName[newIndex++] = hexChar[(valueCRC & 0x00f0) >> 4];
diff --git a/fs/xattr.c b/fs/xattr.c
index f7062da505d4..89a942f07e1b 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -307,7 +307,6 @@ sys_fsetxattr(int fd, char __user *name, void __user *value,
307 error = setxattr(dentry, name, value, size, flags); 307 error = setxattr(dentry, name, value, size, flags);
308 mnt_drop_write(f->f_path.mnt); 308 mnt_drop_write(f->f_path.mnt);
309 } 309 }
310out_fput:
311 fput(f); 310 fput(f);
312 return error; 311 return error;
313} 312}
diff --git a/include/asm-ia64/mca.h b/include/asm-ia64/mca.h
index f1663aa94a52..18a4321349a3 100644
--- a/include/asm-ia64/mca.h
+++ b/include/asm-ia64/mca.h
@@ -157,6 +157,7 @@ extern void ia64_mca_printk(const char * fmt, ...)
157struct ia64_mca_notify_die { 157struct ia64_mca_notify_die {
158 struct ia64_sal_os_state *sos; 158 struct ia64_sal_os_state *sos;
159 int *monarch_cpu; 159 int *monarch_cpu;
160 int *data;
160}; 161};
161 162
162DECLARE_PER_CPU(u64, ia64_mca_pal_base); 163DECLARE_PER_CPU(u64, ia64_mca_pal_base);
diff --git a/include/asm-sh/i2c-sh7760.h b/include/asm-sh/i2c-sh7760.h
new file mode 100644
index 000000000000..24182116711f
--- /dev/null
+++ b/include/asm-sh/i2c-sh7760.h
@@ -0,0 +1,22 @@
1/*
2 * MMIO/IRQ and platform data for SH7760 I2C channels
3 */
4
5#ifndef _I2C_SH7760_H_
6#define _I2C_SH7760_H_
7
8#define SH7760_I2C_DEVNAME "sh7760-i2c"
9
10#define SH7760_I2C0_MMIO 0xFE140000
11#define SH7760_I2C0_MMIOEND 0xFE14003B
12#define SH7760_I2C0_IRQ 62
13
14#define SH7760_I2C1_MMIO 0xFE150000
15#define SH7760_I2C1_MMIOEND 0xFE15003B
16#define SH7760_I2C1_IRQ 63
17
18struct sh7760_i2c_platdata {
19 unsigned int speed_khz;
20};
21
22#endif
diff --git a/include/asm-sparc/device.h b/include/asm-sparc/device.h
index 680e51d87374..19790eb99cc6 100644
--- a/include/asm-sparc/device.h
+++ b/include/asm-sparc/device.h
@@ -16,6 +16,8 @@ struct dev_archdata {
16 16
17 struct device_node *prom_node; 17 struct device_node *prom_node;
18 struct of_device *op; 18 struct of_device *op;
19
20 int numa_node;
19}; 21};
20 22
21#endif /* _ASM_SPARC_DEVICE_H */ 23#endif /* _ASM_SPARC_DEVICE_H */
diff --git a/include/asm-sparc/prom.h b/include/asm-sparc/prom.h
index df5dc4422483..fd55522481cd 100644
--- a/include/asm-sparc/prom.h
+++ b/include/asm-sparc/prom.h
@@ -77,6 +77,11 @@ extern int of_getintprop_default(struct device_node *np,
77 const char *name, 77 const char *name,
78 int def); 78 int def);
79extern int of_find_in_proplist(const char *list, const char *match, int len); 79extern int of_find_in_proplist(const char *list, const char *match, int len);
80#ifdef CONFIG_NUMA
81extern int of_node_to_nid(struct device_node *dp);
82#else
83#define of_node_to_nid(dp) (-1)
84#endif
80 85
81extern void prom_build_devicetree(void); 86extern void prom_build_devicetree(void);
82 87
diff --git a/include/asm-sparc64/iommu.h b/include/asm-sparc64/iommu.h
index 46325ddee23b..d7b9afcba08b 100644
--- a/include/asm-sparc64/iommu.h
+++ b/include/asm-sparc64/iommu.h
@@ -56,6 +56,7 @@ struct strbuf {
56}; 56};
57 57
58extern int iommu_table_init(struct iommu *iommu, int tsbsize, 58extern int iommu_table_init(struct iommu *iommu, int tsbsize,
59 u32 dma_offset, u32 dma_addr_mask); 59 u32 dma_offset, u32 dma_addr_mask,
60 int numa_node);
60 61
61#endif /* !(_SPARC64_IOMMU_H) */ 62#endif /* !(_SPARC64_IOMMU_H) */
diff --git a/include/asm-sparc64/mmzone.h b/include/asm-sparc64/mmzone.h
new file mode 100644
index 000000000000..ebf5986c12ed
--- /dev/null
+++ b/include/asm-sparc64/mmzone.h
@@ -0,0 +1,17 @@
1#ifndef _SPARC64_MMZONE_H
2#define _SPARC64_MMZONE_H
3
4#ifdef CONFIG_NEED_MULTIPLE_NODES
5
6extern struct pglist_data *node_data[];
7
8#define NODE_DATA(nid) (node_data[nid])
9#define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
10#define node_end_pfn(nid) (NODE_DATA(nid)->node_end_pfn)
11
12extern int numa_cpu_lookup_table[];
13extern cpumask_t numa_cpumask_lookup_table[];
14
15#endif /* CONFIG_NEED_MULTIPLE_NODES */
16
17#endif /* _SPARC64_MMZONE_H */
diff --git a/include/asm-sparc64/numnodes.h b/include/asm-sparc64/numnodes.h
deleted file mode 100644
index 017e7e74f5e7..000000000000
--- a/include/asm-sparc64/numnodes.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef _SPARC64_NUMNODES_H
2#define _SPARC64_NUMNODES_H
3
4#define NODES_SHIFT 0
5
6#endif /* !(_SPARC64_NUMNODES_H) */
diff --git a/include/asm-sparc64/ptrace.h b/include/asm-sparc64/ptrace.h
index 6da197803efc..b4b951d570bb 100644
--- a/include/asm-sparc64/ptrace.h
+++ b/include/asm-sparc64/ptrace.h
@@ -8,6 +8,8 @@
8 * stack during a system call and basically all traps. 8 * stack during a system call and basically all traps.
9 */ 9 */
10 10
11#define PT_REGS_MAGIC 0x57ac6c00
12
11#ifndef __ASSEMBLY__ 13#ifndef __ASSEMBLY__
12 14
13struct pt_regs { 15struct pt_regs {
@@ -16,7 +18,19 @@ struct pt_regs {
16 unsigned long tpc; 18 unsigned long tpc;
17 unsigned long tnpc; 19 unsigned long tnpc;
18 unsigned int y; 20 unsigned int y;
19 unsigned int fprs; 21
22 /* We encode a magic number, PT_REGS_MAGIC, along
23 * with the %tt (trap type) register value at trap
24 * entry time. The magic number allows us to identify
25 * accurately a trap stack frame in the stack
26 * unwinder, and the %tt value allows us to test
27 * things like "in a system call" etc. for an arbitray
28 * process.
29 *
30 * The PT_REGS_MAGIC is choosen such that it can be
31 * loaded completely using just a sethi instruction.
32 */
33 unsigned int magic;
20}; 34};
21 35
22struct pt_regs32 { 36struct pt_regs32 {
@@ -147,7 +161,7 @@ extern void __show_regs(struct pt_regs *);
147#define PT_V9_TPC 0x88 161#define PT_V9_TPC 0x88
148#define PT_V9_TNPC 0x90 162#define PT_V9_TNPC 0x90
149#define PT_V9_Y 0x98 163#define PT_V9_Y 0x98
150#define PT_V9_FPRS 0x9c 164#define PT_V9_MAGIC 0x9c
151#define PT_TSTATE PT_V9_TSTATE 165#define PT_TSTATE PT_V9_TSTATE
152#define PT_TPC PT_V9_TPC 166#define PT_TPC PT_V9_TPC
153#define PT_TNPC PT_V9_TNPC 167#define PT_TNPC PT_V9_TNPC
diff --git a/include/asm-sparc64/sparsemem.h b/include/asm-sparc64/sparsemem.h
index 77bcd2bfa53c..b99d4e4b6d28 100644
--- a/include/asm-sparc64/sparsemem.h
+++ b/include/asm-sparc64/sparsemem.h
@@ -3,7 +3,7 @@
3 3
4#ifdef __KERNEL__ 4#ifdef __KERNEL__
5 5
6#define SECTION_SIZE_BITS 31 6#define SECTION_SIZE_BITS 30
7#define MAX_PHYSADDR_BITS 42 7#define MAX_PHYSADDR_BITS 42
8#define MAX_PHYSMEM_BITS 42 8#define MAX_PHYSMEM_BITS 42
9 9
diff --git a/include/asm-sparc64/topology.h b/include/asm-sparc64/topology.h
index c6b557034f68..001c04027c82 100644
--- a/include/asm-sparc64/topology.h
+++ b/include/asm-sparc64/topology.h
@@ -1,6 +1,77 @@
1#ifndef _ASM_SPARC64_TOPOLOGY_H 1#ifndef _ASM_SPARC64_TOPOLOGY_H
2#define _ASM_SPARC64_TOPOLOGY_H 2#define _ASM_SPARC64_TOPOLOGY_H
3 3
4#ifdef CONFIG_NUMA
5
6#include <asm/mmzone.h>
7
8static inline int cpu_to_node(int cpu)
9{
10 return numa_cpu_lookup_table[cpu];
11}
12
13#define parent_node(node) (node)
14
15static inline cpumask_t node_to_cpumask(int node)
16{
17 return numa_cpumask_lookup_table[node];
18}
19
20/* Returns a pointer to the cpumask of CPUs on Node 'node'. */
21#define node_to_cpumask_ptr(v, node) \
22 cpumask_t *v = &(numa_cpumask_lookup_table[node])
23
24#define node_to_cpumask_ptr_next(v, node) \
25 v = &(numa_cpumask_lookup_table[node])
26
27static inline int node_to_first_cpu(int node)
28{
29 cpumask_t tmp;
30 tmp = node_to_cpumask(node);
31 return first_cpu(tmp);
32}
33
34struct pci_bus;
35#ifdef CONFIG_PCI
36extern int pcibus_to_node(struct pci_bus *pbus);
37#else
38static inline int pcibus_to_node(struct pci_bus *pbus)
39{
40 return -1;
41}
42#endif
43
44#define pcibus_to_cpumask(bus) \
45 (pcibus_to_node(bus) == -1 ? \
46 CPU_MASK_ALL : \
47 node_to_cpumask(pcibus_to_node(bus)))
48
49#define SD_NODE_INIT (struct sched_domain) { \
50 .min_interval = 8, \
51 .max_interval = 32, \
52 .busy_factor = 32, \
53 .imbalance_pct = 125, \
54 .cache_nice_tries = 2, \
55 .busy_idx = 3, \
56 .idle_idx = 2, \
57 .newidle_idx = 0, \
58 .wake_idx = 1, \
59 .forkexec_idx = 1, \
60 .flags = SD_LOAD_BALANCE \
61 | SD_BALANCE_FORK \
62 | SD_BALANCE_EXEC \
63 | SD_SERIALIZE \
64 | SD_WAKE_BALANCE, \
65 .last_balance = jiffies, \
66 .balance_interval = 1, \
67}
68
69#else /* CONFIG_NUMA */
70
71#include <asm-generic/topology.h>
72
73#endif /* !(CONFIG_NUMA) */
74
4#ifdef CONFIG_SMP 75#ifdef CONFIG_SMP
5#define topology_physical_package_id(cpu) (cpu_data(cpu).proc_id) 76#define topology_physical_package_id(cpu) (cpu_data(cpu).proc_id)
6#define topology_core_id(cpu) (cpu_data(cpu).core_id) 77#define topology_core_id(cpu) (cpu_data(cpu).core_id)
@@ -10,8 +81,6 @@
10#define smt_capable() (sparc64_multi_core) 81#define smt_capable() (sparc64_multi_core)
11#endif /* CONFIG_SMP */ 82#endif /* CONFIG_SMP */
12 83
13#include <asm-generic/topology.h>
14
15#define cpu_coregroup_map(cpu) (cpu_core_map[cpu]) 84#define cpu_coregroup_map(cpu) (cpu_core_map[cpu])
16 85
17#endif /* _ASM_SPARC64_TOPOLOGY_H */ 86#endif /* _ASM_SPARC64_TOPOLOGY_H */
diff --git a/include/asm-sparc64/ttable.h b/include/asm-sparc64/ttable.h
index 7208a777750e..d3cc4eff39a6 100644
--- a/include/asm-sparc64/ttable.h
+++ b/include/asm-sparc64/ttable.h
@@ -28,7 +28,7 @@
28 call routine; \ 28 call routine; \
29 add %sp, PTREGS_OFF, %o0; \ 29 add %sp, PTREGS_OFF, %o0; \
30 ba,pt %xcc, rtrap; \ 30 ba,pt %xcc, rtrap; \
31 clr %l6; \ 31 nop; \
32 nop; 32 nop;
33 33
34#define TRAP_7INSNS(routine) \ 34#define TRAP_7INSNS(routine) \
@@ -38,7 +38,7 @@
38 call routine; \ 38 call routine; \
39 add %sp, PTREGS_OFF, %o0; \ 39 add %sp, PTREGS_OFF, %o0; \
40 ba,pt %xcc, rtrap; \ 40 ba,pt %xcc, rtrap; \
41 clr %l6; 41 nop;
42 42
43#define TRAP_SAVEFPU(routine) \ 43#define TRAP_SAVEFPU(routine) \
44 sethi %hi(109f), %g7; \ 44 sethi %hi(109f), %g7; \
@@ -47,7 +47,7 @@
47 call routine; \ 47 call routine; \
48 add %sp, PTREGS_OFF, %o0; \ 48 add %sp, PTREGS_OFF, %o0; \
49 ba,pt %xcc, rtrap; \ 49 ba,pt %xcc, rtrap; \
50 clr %l6; \ 50 nop; \
51 nop; 51 nop;
52 52
53#define TRAP_NOSAVE(routine) \ 53#define TRAP_NOSAVE(routine) \
@@ -67,7 +67,7 @@
67 call routine; \ 67 call routine; \
68 add %sp, PTREGS_OFF, %o0; \ 68 add %sp, PTREGS_OFF, %o0; \
69 ba,pt %xcc, rtrap; \ 69 ba,pt %xcc, rtrap; \
70 clr %l6; \ 70 nop; \
71 nop; 71 nop;
72 72
73#define TRAP_ARG(routine, arg) \ 73#define TRAP_ARG(routine, arg) \
@@ -78,7 +78,7 @@
78 call routine; \ 78 call routine; \
79 mov arg, %o1; \ 79 mov arg, %o1; \
80 ba,pt %xcc, rtrap; \ 80 ba,pt %xcc, rtrap; \
81 clr %l6; 81 nop;
82 82
83#define TRAPTL1_ARG(routine, arg) \ 83#define TRAPTL1_ARG(routine, arg) \
84 sethi %hi(109f), %g7; \ 84 sethi %hi(109f), %g7; \
@@ -88,7 +88,7 @@
88 call routine; \ 88 call routine; \
89 mov arg, %o1; \ 89 mov arg, %o1; \
90 ba,pt %xcc, rtrap; \ 90 ba,pt %xcc, rtrap; \
91 clr %l6; 91 nop;
92 92
93#define SYSCALL_TRAP(routine, systbl) \ 93#define SYSCALL_TRAP(routine, systbl) \
94 sethi %hi(109f), %g7; \ 94 sethi %hi(109f), %g7; \
@@ -166,7 +166,7 @@
166 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1; \ 166 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1; \
167 add %l1, 4, %l2; \ 167 add %l1, 4, %l2; \
168 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]; \ 168 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]; \
169 ba,pt %xcc, rtrap_clr_l6; \ 169 ba,pt %xcc, rtrap; \
170 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]; 170 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC];
171 171
172#ifdef CONFIG_KPROBES 172#ifdef CONFIG_KPROBES
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index b3d9ccde0c27..cbb5ccb27de3 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -100,7 +100,7 @@ header-y += ixjuser.h
100header-y += jffs2.h 100header-y += jffs2.h
101header-y += keyctl.h 101header-y += keyctl.h
102header-y += limits.h 102header-y += limits.h
103header-y += lock_dlm_plock.h 103header-y += dlm_plock.h
104header-y += magic.h 104header-y += magic.h
105header-y += major.h 105header-y += major.h
106header-y += matroxfb.h 106header-y += matroxfb.h
@@ -150,6 +150,7 @@ header-y += tiocl.h
150header-y += tipc.h 150header-y += tipc.h
151header-y += tipc_config.h 151header-y += tipc_config.h
152header-y += toshiba.h 152header-y += toshiba.h
153header-y += udf_fs_i.h
153header-y += ultrasound.h 154header-y += ultrasound.h
154header-y += un.h 155header-y += un.h
155header-y += utime.h 156header-y += utime.h
@@ -210,7 +211,9 @@ unifdef-y += hdlcdrv.h
210unifdef-y += hdlc.h 211unifdef-y += hdlc.h
211unifdef-y += hdreg.h 212unifdef-y += hdreg.h
212unifdef-y += hdsmart.h 213unifdef-y += hdsmart.h
214unifdef-y += hid.h
213unifdef-y += hiddev.h 215unifdef-y += hiddev.h
216unifdef-y += hidraw.h
214unifdef-y += hpet.h 217unifdef-y += hpet.h
215unifdef-y += i2c.h 218unifdef-y += i2c.h
216unifdef-y += i2c-dev.h 219unifdef-y += i2c-dev.h
@@ -334,7 +337,6 @@ unifdef-y += time.h
334unifdef-y += timex.h 337unifdef-y += timex.h
335unifdef-y += tty.h 338unifdef-y += tty.h
336unifdef-y += types.h 339unifdef-y += types.h
337unifdef-y += udf_fs_i.h
338unifdef-y += udp.h 340unifdef-y += udp.h
339unifdef-y += uinput.h 341unifdef-y += uinput.h
340unifdef-y += uio.h 342unifdef-y += uio.h
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 6bd646096fa6..cfb1627ac51c 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -301,7 +301,9 @@ extern int d_validate(struct dentry *, struct dentry *);
301 */ 301 */
302extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...); 302extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
303 303
304extern char *__d_path(const struct path *path, struct path *root, char *, int);
304extern char *d_path(struct path *, char *, int); 305extern char *d_path(struct path *, char *, int);
306extern char *dentry_path(struct dentry *, char *, int);
305 307
306/* Allocation counts.. */ 308/* Allocation counts.. */
307 309
@@ -359,7 +361,6 @@ static inline int d_mountpoint(struct dentry *dentry)
359} 361}
360 362
361extern struct vfsmount *lookup_mnt(struct vfsmount *, struct dentry *); 363extern struct vfsmount *lookup_mnt(struct vfsmount *, struct dentry *);
362extern struct vfsmount *__lookup_mnt(struct vfsmount *, struct dentry *, int);
363extern struct dentry *lookup_create(struct nameidata *nd, int is_dir); 364extern struct dentry *lookup_create(struct nameidata *nd, int is_dir);
364 365
365extern int sysctl_vfs_cache_pressure; 366extern int sysctl_vfs_cache_pressure;
diff --git a/include/linux/dlm.h b/include/linux/dlm.h
index c743fbc769db..203a025e30e5 100644
--- a/include/linux/dlm.h
+++ b/include/linux/dlm.h
@@ -21,10 +21,7 @@
21 21
22/* Lock levels and flags are here */ 22/* Lock levels and flags are here */
23#include <linux/dlmconstants.h> 23#include <linux/dlmconstants.h>
24 24#include <linux/types.h>
25
26#define DLM_RESNAME_MAXLEN 64
27
28 25
29typedef void dlm_lockspace_t; 26typedef void dlm_lockspace_t;
30 27
@@ -63,7 +60,7 @@ typedef void dlm_lockspace_t;
63 60
64struct dlm_lksb { 61struct dlm_lksb {
65 int sb_status; 62 int sb_status;
66 uint32_t sb_lkid; 63 __u32 sb_lkid;
67 char sb_flags; 64 char sb_flags;
68 char * sb_lvbptr; 65 char * sb_lvbptr;
69}; 66};
diff --git a/include/linux/dlm_device.h b/include/linux/dlm_device.h
index 9642277a152a..c6034508fed9 100644
--- a/include/linux/dlm_device.h
+++ b/include/linux/dlm_device.h
@@ -11,10 +11,16 @@
11******************************************************************************* 11*******************************************************************************
12******************************************************************************/ 12******************************************************************************/
13 13
14#ifndef _LINUX_DLM_DEVICE_H
15#define _LINUX_DLM_DEVICE_H
16
14/* This is the device interface for dlm, most users will use a library 17/* This is the device interface for dlm, most users will use a library
15 * interface. 18 * interface.
16 */ 19 */
17 20
21#include <linux/dlm.h>
22#include <linux/types.h>
23
18#define DLM_USER_LVB_LEN 32 24#define DLM_USER_LVB_LEN 32
19 25
20/* Version of the device interface */ 26/* Version of the device interface */
@@ -94,10 +100,9 @@ struct dlm_lock_result {
94#define DLM_USER_PURGE 6 100#define DLM_USER_PURGE 6
95#define DLM_USER_DEADLOCK 7 101#define DLM_USER_DEADLOCK 7
96 102
97/* Arbitrary length restriction */
98#define MAX_LS_NAME_LEN 64
99
100/* Lockspace flags */ 103/* Lockspace flags */
101#define DLM_USER_LSFLG_AUTOFREE 1 104#define DLM_USER_LSFLG_AUTOFREE 1
102#define DLM_USER_LSFLG_FORCEFREE 2 105#define DLM_USER_LSFLG_FORCEFREE 2
103 106
107#endif
108
diff --git a/include/linux/dlm_plock.h b/include/linux/dlm_plock.h
new file mode 100644
index 000000000000..18d5fdbceb74
--- /dev/null
+++ b/include/linux/dlm_plock.h
@@ -0,0 +1,50 @@
1/*
2 * Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved.
3 *
4 * This copyrighted material is made available to anyone wishing to use,
5 * modify, copy, or redistribute it subject to the terms and conditions
6 * of the GNU General Public License v.2.
7 */
8
9#ifndef __DLM_PLOCK_DOT_H__
10#define __DLM_PLOCK_DOT_H__
11
12#define DLM_PLOCK_MISC_NAME "dlm_plock"
13
14#define DLM_PLOCK_VERSION_MAJOR 1
15#define DLM_PLOCK_VERSION_MINOR 1
16#define DLM_PLOCK_VERSION_PATCH 0
17
18enum {
19 DLM_PLOCK_OP_LOCK = 1,
20 DLM_PLOCK_OP_UNLOCK,
21 DLM_PLOCK_OP_GET,
22};
23
24struct dlm_plock_info {
25 __u32 version[3];
26 __u8 optype;
27 __u8 ex;
28 __u8 wait;
29 __u8 pad;
30 __u32 pid;
31 __s32 nodeid;
32 __s32 rv;
33 __u32 fsid;
34 __u64 number;
35 __u64 start;
36 __u64 end;
37 __u64 owner;
38};
39
40#ifdef __KERNEL__
41int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file,
42 int cmd, struct file_lock *fl);
43int dlm_posix_unlock(dlm_lockspace_t *lockspace, u64 number, struct file *file,
44 struct file_lock *fl);
45int dlm_posix_get(dlm_lockspace_t *lockspace, u64 number, struct file *file,
46 struct file_lock *fl);
47#endif /* __KERNEL__ */
48
49#endif
50
diff --git a/include/linux/dlmconstants.h b/include/linux/dlmconstants.h
index fddb3d3ff321..47bf08dc7566 100644
--- a/include/linux/dlmconstants.h
+++ b/include/linux/dlmconstants.h
@@ -18,6 +18,10 @@
18 * Constants used by DLM interface. 18 * Constants used by DLM interface.
19 */ 19 */
20 20
21#define DLM_LOCKSPACE_LEN 64
22#define DLM_RESNAME_MAXLEN 64
23
24
21/* 25/*
22 * Lock Modes 26 * Lock Modes
23 */ 27 */
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 0c609e71c379..cc2be2cf7d41 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -305,7 +305,6 @@ struct vfsmount;
305 305
306extern void __init inode_init(void); 306extern void __init inode_init(void);
307extern void __init inode_init_early(void); 307extern void __init inode_init_early(void);
308extern void __init mnt_init(void);
309extern void __init files_init(unsigned long); 308extern void __init files_init(unsigned long);
310 309
311struct buffer_head; 310struct buffer_head;
@@ -1536,12 +1535,7 @@ extern struct vfsmount *kern_mount_data(struct file_system_type *, void *data);
1536#define kern_mount(type) kern_mount_data(type, NULL) 1535#define kern_mount(type) kern_mount_data(type, NULL)
1537extern int may_umount_tree(struct vfsmount *); 1536extern int may_umount_tree(struct vfsmount *);
1538extern int may_umount(struct vfsmount *); 1537extern int may_umount(struct vfsmount *);
1539extern void umount_tree(struct vfsmount *, int, struct list_head *);
1540extern void release_mounts(struct list_head *);
1541extern long do_mount(char *, char *, char *, unsigned long, void *); 1538extern long do_mount(char *, char *, char *, unsigned long, void *);
1542extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int);
1543extern void mnt_set_mountpoint(struct vfsmount *, struct dentry *,
1544 struct vfsmount *);
1545extern struct vfsmount *collect_mounts(struct vfsmount *, struct dentry *); 1539extern struct vfsmount *collect_mounts(struct vfsmount *, struct dentry *);
1546extern void drop_collected_mounts(struct vfsmount *); 1540extern void drop_collected_mounts(struct vfsmount *);
1547 1541
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 74ff57596eb1..d951ec411241 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -284,6 +284,7 @@ struct hid_item {
284#define HID_QUIRK_2WHEEL_MOUSE_HACK_B8 0x02000000 284#define HID_QUIRK_2WHEEL_MOUSE_HACK_B8 0x02000000
285#define HID_QUIRK_HWHEEL_WHEEL_INVERT 0x04000000 285#define HID_QUIRK_HWHEEL_WHEEL_INVERT 0x04000000
286#define HID_QUIRK_MICROSOFT_KEYS 0x08000000 286#define HID_QUIRK_MICROSOFT_KEYS 0x08000000
287#define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000
287 288
288/* 289/*
289 * Separate quirks for runtime report descriptor fixup 290 * Separate quirks for runtime report descriptor fixup
@@ -296,6 +297,8 @@ struct hid_item {
296#define HID_QUIRK_RDESC_MACBOOK_JIS 0x00000010 297#define HID_QUIRK_RDESC_MACBOOK_JIS 0x00000010
297#define HID_QUIRK_RDESC_BUTTON_CONSUMER 0x00000020 298#define HID_QUIRK_RDESC_BUTTON_CONSUMER 0x00000020
298#define HID_QUIRK_RDESC_SAMSUNG_REMOTE 0x00000040 299#define HID_QUIRK_RDESC_SAMSUNG_REMOTE 0x00000040
300#define HID_QUIRK_RDESC_MICROSOFT_RECV_1028 0x00000080
301#define HID_QUIRK_RDESC_SUNPLUS_WDESKTOP 0x00000100
299 302
300/* 303/*
301 * This is the global environment of the parser. This information is 304 * This is the global environment of the parser. This information is
@@ -320,7 +323,7 @@ struct hid_global {
320 * This is the local environment. It is persistent up the next main-item. 323 * This is the local environment. It is persistent up the next main-item.
321 */ 324 */
322 325
323#define HID_MAX_USAGES 8192 326#define HID_MAX_USAGES 12288
324#define HID_DEFAULT_NUM_COLLECTIONS 16 327#define HID_DEFAULT_NUM_COLLECTIONS 16
325 328
326struct hid_local { 329struct hid_local {
@@ -421,6 +424,7 @@ struct hid_control_fifo {
421#define HID_RESET_PENDING 4 424#define HID_RESET_PENDING 4
422#define HID_SUSPENDED 5 425#define HID_SUSPENDED 5
423#define HID_CLEAR_HALT 6 426#define HID_CLEAR_HALT 6
427#define HID_DISCONNECTED 7
424 428
425struct hid_input { 429struct hid_input {
426 struct list_head list; 430 struct list_head list;
@@ -452,8 +456,6 @@ struct hid_device { /* device report descriptor */
452 void *hidraw; 456 void *hidraw;
453 int minor; /* Hiddev minor number */ 457 int minor; /* Hiddev minor number */
454 458
455 wait_queue_head_t wait; /* For sleeping */
456
457 int open; /* is the device open by anyone? */ 459 int open; /* is the device open by anyone? */
458 char name[128]; /* Device name */ 460 char name[128]; /* Device name */
459 char phys[64]; /* Device physical location */ 461 char phys[64]; /* Device physical location */
@@ -530,14 +532,12 @@ int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int
530int hidinput_mapping_quirks(struct hid_usage *, struct input_dev *, unsigned long **, int *); 532int hidinput_mapping_quirks(struct hid_usage *, struct input_dev *, unsigned long **, int *);
531int hidinput_event_quirks(struct hid_device *, struct hid_field *, struct hid_usage *, __s32); 533int hidinput_event_quirks(struct hid_device *, struct hid_field *, struct hid_usage *, __s32);
532int hidinput_apple_event(struct hid_device *, struct input_dev *, struct hid_usage *, __s32); 534int hidinput_apple_event(struct hid_device *, struct input_dev *, struct hid_usage *, __s32);
533void hid_input_field(struct hid_device *hid, struct hid_field *field, __u8 *data, int interrupt);
534void hid_output_report(struct hid_report *report, __u8 *data); 535void hid_output_report(struct hid_report *report, __u8 *data);
535void hid_free_device(struct hid_device *device); 536void hid_free_device(struct hid_device *device);
536struct hid_device *hid_parse_report(__u8 *start, unsigned size); 537struct hid_device *hid_parse_report(__u8 *start, unsigned size);
537 538
538/* HID quirks API */ 539/* HID quirks API */
539u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct); 540u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct);
540int usbhid_modify_dquirk(const u16 idVendor, const u16 idProduct, const u32 quirks);
541int usbhid_quirks_init(char **quirks_param); 541int usbhid_quirks_init(char **quirks_param);
542void usbhid_quirks_exit(void); 542void usbhid_quirks_exit(void);
543void usbhid_fixup_report_descriptor(const u16, const u16, char *, unsigned, char **); 543void usbhid_fixup_report_descriptor(const u16, const u16, char *, unsigned, char **);
@@ -546,6 +546,7 @@ void usbhid_fixup_report_descriptor(const u16, const u16, char *, unsigned, char
546int hid_ff_init(struct hid_device *hid); 546int hid_ff_init(struct hid_device *hid);
547 547
548int hid_lgff_init(struct hid_device *hid); 548int hid_lgff_init(struct hid_device *hid);
549int hid_lg2ff_init(struct hid_device *hid);
549int hid_plff_init(struct hid_device *hid); 550int hid_plff_init(struct hid_device *hid);
550int hid_tmff_init(struct hid_device *hid); 551int hid_tmff_init(struct hid_device *hid);
551int hid_zpff_init(struct hid_device *hid); 552int hid_zpff_init(struct hid_device *hid);
@@ -566,7 +567,11 @@ static inline int hid_ff_init(struct hid_device *hid) { return -1; }
566#define dbg_hid_line(format, arg...) if (hid_debug) \ 567#define dbg_hid_line(format, arg...) if (hid_debug) \
567 printk(format, ## arg) 568 printk(format, ## arg)
568#else 569#else
569#define dbg_hid(format, arg...) do {} while (0) 570static inline int __attribute__((format(printf, 1, 2)))
571dbg_hid(const char *fmt, ...)
572{
573 return 0;
574}
570#define dbg_hid_line dbg_hid 575#define dbg_hid_line dbg_hid
571#endif 576#endif
572 577
diff --git a/include/linux/hidraw.h b/include/linux/hidraw.h
index 0536f299f7ff..dbb5c8c374f0 100644
--- a/include/linux/hidraw.h
+++ b/include/linux/hidraw.h
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/hid.h> 18#include <linux/hid.h>
19#include <linux/types.h>
19 20
20struct hidraw_report_descriptor { 21struct hidraw_report_descriptor {
21 __u32 size; 22 __u32 size;
diff --git a/include/linux/i2c-algo-pca.h b/include/linux/i2c-algo-pca.h
index fce47c051bb1..adcb3dc7ac26 100644
--- a/include/linux/i2c-algo-pca.h
+++ b/include/linux/i2c-algo-pca.h
@@ -1,14 +1,41 @@
1#ifndef _LINUX_I2C_ALGO_PCA_H 1#ifndef _LINUX_I2C_ALGO_PCA_H
2#define _LINUX_I2C_ALGO_PCA_H 2#define _LINUX_I2C_ALGO_PCA_H
3 3
4/* Clock speeds for the bus */
5#define I2C_PCA_CON_330kHz 0x00
6#define I2C_PCA_CON_288kHz 0x01
7#define I2C_PCA_CON_217kHz 0x02
8#define I2C_PCA_CON_146kHz 0x03
9#define I2C_PCA_CON_88kHz 0x04
10#define I2C_PCA_CON_59kHz 0x05
11#define I2C_PCA_CON_44kHz 0x06
12#define I2C_PCA_CON_36kHz 0x07
13
14/* PCA9564 registers */
15#define I2C_PCA_STA 0x00 /* STATUS Read Only */
16#define I2C_PCA_TO 0x00 /* TIMEOUT Write Only */
17#define I2C_PCA_DAT 0x01 /* DATA Read/Write */
18#define I2C_PCA_ADR 0x02 /* OWN ADR Read/Write */
19#define I2C_PCA_CON 0x03 /* CONTROL Read/Write */
20
21#define I2C_PCA_CON_AA 0x80 /* Assert Acknowledge */
22#define I2C_PCA_CON_ENSIO 0x40 /* Enable */
23#define I2C_PCA_CON_STA 0x20 /* Start */
24#define I2C_PCA_CON_STO 0x10 /* Stop */
25#define I2C_PCA_CON_SI 0x08 /* Serial Interrupt */
26#define I2C_PCA_CON_CR 0x07 /* Clock Rate (MASK) */
27
4struct i2c_algo_pca_data { 28struct i2c_algo_pca_data {
5 int (*get_own) (struct i2c_algo_pca_data *adap); /* Obtain own address */ 29 void *data; /* private low level data */
6 int (*get_clock) (struct i2c_algo_pca_data *adap); 30 void (*write_byte) (void *data, int reg, int val);
7 void (*write_byte) (struct i2c_algo_pca_data *adap, int reg, int val); 31 int (*read_byte) (void *data, int reg);
8 int (*read_byte) (struct i2c_algo_pca_data *adap, int reg); 32 int (*wait_for_completion) (void *data);
9 int (*wait_for_interrupt) (struct i2c_algo_pca_data *adap); 33 void (*reset_chip) (void *data);
34 /* i2c_clock values are defined in linux/i2c-algo-pca.h */
35 unsigned int i2c_clock;
10}; 36};
11 37
12int i2c_pca_add_bus(struct i2c_adapter *); 38int i2c_pca_add_bus(struct i2c_adapter *);
39int i2c_pca_add_numbered_bus(struct i2c_adapter *);
13 40
14#endif /* _LINUX_I2C_ALGO_PCA_H */ 41#endif /* _LINUX_I2C_ALGO_PCA_H */
diff --git a/include/linux/i2c-pca-platform.h b/include/linux/i2c-pca-platform.h
new file mode 100644
index 000000000000..3d191873f2d1
--- /dev/null
+++ b/include/linux/i2c-pca-platform.h
@@ -0,0 +1,12 @@
1#ifndef I2C_PCA9564_PLATFORM_H
2#define I2C_PCA9564_PLATFORM_H
3
4struct i2c_pca9564_pf_platform_data {
5 int gpio; /* pin to reset chip. driver will work when
6 * not supplied (negative value), but it
7 * cannot exit some error conditions then */
8 int i2c_clock_speed; /* values are defined in linux/i2c-algo-pca.h */
9 int timeout; /* timeout = this value * 10us */
10};
11
12#endif /* I2C_PCA9564_PLATFORM_H */
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index f27d11ab418b..529f301d9372 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -465,13 +465,19 @@ enum ieee80211_eid {
465 WLAN_EID_TS_DELAY = 43, 465 WLAN_EID_TS_DELAY = 43,
466 WLAN_EID_TCLAS_PROCESSING = 44, 466 WLAN_EID_TCLAS_PROCESSING = 44,
467 WLAN_EID_QOS_CAPA = 46, 467 WLAN_EID_QOS_CAPA = 46,
468 /* 802.11s */ 468 /* 802.11s
469 WLAN_EID_MESH_CONFIG = 36, /* Pending IEEE 802.11 ANA approval */ 469 *
470 WLAN_EID_MESH_ID = 37, /* Pending IEEE 802.11 ANA approval */ 470 * All mesh EID numbers are pending IEEE 802.11 ANA approval.
471 WLAN_EID_PEER_LINK = 40, /* Pending IEEE 802.11 ANA approval */ 471 * The numbers have been incremented from those suggested in
472 WLAN_EID_PREQ = 53, /* Pending IEEE 802.11 ANA approval */ 472 * 802.11s/D2.0 so that MESH_CONFIG does not conflict with
473 WLAN_EID_PREP = 54, /* Pending IEEE 802.11 ANA approval */ 473 * EXT_SUPP_RATES.
474 WLAN_EID_PERR = 55, /* Pending IEEE 802.11 ANA approval */ 474 */
475 WLAN_EID_MESH_CONFIG = 51,
476 WLAN_EID_MESH_ID = 52,
477 WLAN_EID_PEER_LINK = 55,
478 WLAN_EID_PREQ = 68,
479 WLAN_EID_PREP = 69,
480 WLAN_EID_PERR = 70,
475 /* 802.11h */ 481 /* 802.11h */
476 WLAN_EID_PWR_CONSTRAINT = 32, 482 WLAN_EID_PWR_CONSTRAINT = 32,
477 WLAN_EID_PWR_CAPABILITY = 33, 483 WLAN_EID_PWR_CAPABILITY = 33,
diff --git a/include/linux/lock_dlm_plock.h b/include/linux/lock_dlm_plock.h
deleted file mode 100644
index fc3415113973..000000000000
--- a/include/linux/lock_dlm_plock.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * Copyright (C) 2005 Red Hat, Inc. All rights reserved.
3 *
4 * This copyrighted material is made available to anyone wishing to use,
5 * modify, copy, or redistribute it subject to the terms and conditions
6 * of the GNU General Public License v.2.
7 */
8
9#ifndef __LOCK_DLM_PLOCK_DOT_H__
10#define __LOCK_DLM_PLOCK_DOT_H__
11
12#define GDLM_PLOCK_MISC_NAME "lock_dlm_plock"
13
14#define GDLM_PLOCK_VERSION_MAJOR 1
15#define GDLM_PLOCK_VERSION_MINOR 1
16#define GDLM_PLOCK_VERSION_PATCH 0
17
18enum {
19 GDLM_PLOCK_OP_LOCK = 1,
20 GDLM_PLOCK_OP_UNLOCK,
21 GDLM_PLOCK_OP_GET,
22};
23
24struct gdlm_plock_info {
25 __u32 version[3];
26 __u8 optype;
27 __u8 ex;
28 __u8 wait;
29 __u8 pad;
30 __u32 pid;
31 __s32 nodeid;
32 __s32 rv;
33 __u32 fsid;
34 __u64 number;
35 __u64 start;
36 __u64 end;
37 __u64 owner;
38};
39
40#endif
41
diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
index 8eed44f8ca73..830bbcd449d6 100644
--- a/include/linux/mnt_namespace.h
+++ b/include/linux/mnt_namespace.h
@@ -5,6 +5,7 @@
5#include <linux/mount.h> 5#include <linux/mount.h>
6#include <linux/sched.h> 6#include <linux/sched.h>
7#include <linux/nsproxy.h> 7#include <linux/nsproxy.h>
8#include <linux/seq_file.h>
8 9
9struct mnt_namespace { 10struct mnt_namespace {
10 atomic_t count; 11 atomic_t count;
@@ -14,6 +15,13 @@ struct mnt_namespace {
14 int event; 15 int event;
15}; 16};
16 17
18struct proc_mounts {
19 struct seq_file m; /* must be the first element */
20 struct mnt_namespace *ns;
21 struct path root;
22 int event;
23};
24
17extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *, 25extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
18 struct fs_struct *); 26 struct fs_struct *);
19extern void __put_mnt_ns(struct mnt_namespace *ns); 27extern void __put_mnt_ns(struct mnt_namespace *ns);
@@ -37,5 +45,9 @@ static inline void get_mnt_ns(struct mnt_namespace *ns)
37 atomic_inc(&ns->count); 45 atomic_inc(&ns->count);
38} 46}
39 47
48extern const struct seq_operations mounts_op;
49extern const struct seq_operations mountinfo_op;
50extern const struct seq_operations mountstats_op;
51
40#endif 52#endif
41#endif 53#endif
diff --git a/include/linux/mount.h b/include/linux/mount.h
index d6600e3f7e45..b4836d58f428 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -56,6 +56,8 @@ struct vfsmount {
56 struct list_head mnt_slave; /* slave list entry */ 56 struct list_head mnt_slave; /* slave list entry */
57 struct vfsmount *mnt_master; /* slave is on master->mnt_slave_list */ 57 struct vfsmount *mnt_master; /* slave is on master->mnt_slave_list */
58 struct mnt_namespace *mnt_ns; /* containing namespace */ 58 struct mnt_namespace *mnt_ns; /* containing namespace */
59 int mnt_id; /* mount identifier */
60 int mnt_group_id; /* peer group identifier */
59 /* 61 /*
60 * We put mnt_count & mnt_expiry_mark at the end of struct vfsmount 62 * We put mnt_count & mnt_expiry_mark at the end of struct vfsmount
61 * to let these frequently modified fields in a separate cache line 63 * to let these frequently modified fields in a separate cache line
@@ -94,8 +96,6 @@ static inline void mntput(struct vfsmount *mnt)
94 } 96 }
95} 97}
96 98
97extern void free_vfsmnt(struct vfsmount *mnt);
98extern struct vfsmount *alloc_vfsmnt(const char *name);
99extern struct vfsmount *do_kern_mount(const char *fstype, int flags, 99extern struct vfsmount *do_kern_mount(const char *fstype, int flags,
100 const char *name, void *data); 100 const char *name, void *data);
101 101
diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index b9e174079002..44c81c744538 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -740,13 +740,13 @@ extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
740extern void rtnl_lock(void); 740extern void rtnl_lock(void);
741extern void rtnl_unlock(void); 741extern void rtnl_unlock(void);
742extern int rtnl_trylock(void); 742extern int rtnl_trylock(void);
743extern int rtnl_is_locked(void);
743 744
744extern void rtnetlink_init(void); 745extern void rtnetlink_init(void);
745extern void __rtnl_unlock(void); 746extern void __rtnl_unlock(void);
746 747
747#define ASSERT_RTNL() do { \ 748#define ASSERT_RTNL() do { \
748 if (unlikely(rtnl_trylock())) { \ 749 if (unlikely(!rtnl_is_locked())) { \
749 rtnl_unlock(); \
750 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \ 750 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
751 __FILE__, __LINE__); \ 751 __FILE__, __LINE__); \
752 dump_stack(); \ 752 dump_stack(); \
diff --git a/include/linux/security.h b/include/linux/security.h
index fea1f4aa4dd5..53a34539382a 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -230,7 +230,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
230 * loopback/bind mount (@flags & MS_BIND), @dev_name identifies the 230 * loopback/bind mount (@flags & MS_BIND), @dev_name identifies the
231 * pathname of the object being mounted. 231 * pathname of the object being mounted.
232 * @dev_name contains the name for object being mounted. 232 * @dev_name contains the name for object being mounted.
233 * @nd contains the nameidata structure for mount point object. 233 * @path contains the path for mount point object.
234 * @type contains the filesystem type. 234 * @type contains the filesystem type.
235 * @flags contains the mount flags. 235 * @flags contains the mount flags.
236 * @data contains the filesystem-specific data. 236 * @data contains the filesystem-specific data.
@@ -249,7 +249,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
249 * Check permission before the device with superblock @mnt->sb is mounted 249 * Check permission before the device with superblock @mnt->sb is mounted
250 * on the mount point named by @nd. 250 * on the mount point named by @nd.
251 * @mnt contains the vfsmount for device being mounted. 251 * @mnt contains the vfsmount for device being mounted.
252 * @nd contains the nameidata object for the mount point. 252 * @path contains the path for the mount point.
253 * Return 0 if permission is granted. 253 * Return 0 if permission is granted.
254 * @sb_umount: 254 * @sb_umount:
255 * Check permission before the @mnt file system is unmounted. 255 * Check permission before the @mnt file system is unmounted.
@@ -278,16 +278,16 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
278 * This hook is called any time a mount is successfully grafetd to 278 * This hook is called any time a mount is successfully grafetd to
279 * the tree. 279 * the tree.
280 * @mnt contains the mounted filesystem. 280 * @mnt contains the mounted filesystem.
281 * @mountpoint_nd contains the nameidata structure for the mount point. 281 * @mountpoint contains the path for the mount point.
282 * @sb_pivotroot: 282 * @sb_pivotroot:
283 * Check permission before pivoting the root filesystem. 283 * Check permission before pivoting the root filesystem.
284 * @old_nd contains the nameidata structure for the new location of the current root (put_old). 284 * @old_path contains the path for the new location of the current root (put_old).
285 * @new_nd contains the nameidata structure for the new root (new_root). 285 * @new_path contains the path for the new root (new_root).
286 * Return 0 if permission is granted. 286 * Return 0 if permission is granted.
287 * @sb_post_pivotroot: 287 * @sb_post_pivotroot:
288 * Update module state after a successful pivot. 288 * Update module state after a successful pivot.
289 * @old_nd contains the nameidata structure for the old root. 289 * @old_path contains the path for the old root.
290 * @new_nd contains the nameidata structure for the new root. 290 * @new_path contains the path for the new root.
291 * @sb_get_mnt_opts: 291 * @sb_get_mnt_opts:
292 * Get the security relevant mount options used for a superblock 292 * Get the security relevant mount options used for a superblock
293 * @sb the superblock to get security mount options from 293 * @sb the superblock to get security mount options from
@@ -1315,20 +1315,20 @@ struct security_operations {
1315 int (*sb_copy_data)(char *orig, char *copy); 1315 int (*sb_copy_data)(char *orig, char *copy);
1316 int (*sb_kern_mount) (struct super_block *sb, void *data); 1316 int (*sb_kern_mount) (struct super_block *sb, void *data);
1317 int (*sb_statfs) (struct dentry *dentry); 1317 int (*sb_statfs) (struct dentry *dentry);
1318 int (*sb_mount) (char *dev_name, struct nameidata * nd, 1318 int (*sb_mount) (char *dev_name, struct path *path,
1319 char *type, unsigned long flags, void *data); 1319 char *type, unsigned long flags, void *data);
1320 int (*sb_check_sb) (struct vfsmount * mnt, struct nameidata * nd); 1320 int (*sb_check_sb) (struct vfsmount * mnt, struct path *path);
1321 int (*sb_umount) (struct vfsmount * mnt, int flags); 1321 int (*sb_umount) (struct vfsmount * mnt, int flags);
1322 void (*sb_umount_close) (struct vfsmount * mnt); 1322 void (*sb_umount_close) (struct vfsmount * mnt);
1323 void (*sb_umount_busy) (struct vfsmount * mnt); 1323 void (*sb_umount_busy) (struct vfsmount * mnt);
1324 void (*sb_post_remount) (struct vfsmount * mnt, 1324 void (*sb_post_remount) (struct vfsmount * mnt,
1325 unsigned long flags, void *data); 1325 unsigned long flags, void *data);
1326 void (*sb_post_addmount) (struct vfsmount * mnt, 1326 void (*sb_post_addmount) (struct vfsmount * mnt,
1327 struct nameidata * mountpoint_nd); 1327 struct path *mountpoint);
1328 int (*sb_pivotroot) (struct nameidata * old_nd, 1328 int (*sb_pivotroot) (struct path *old_path,
1329 struct nameidata * new_nd); 1329 struct path *new_path);
1330 void (*sb_post_pivotroot) (struct nameidata * old_nd, 1330 void (*sb_post_pivotroot) (struct path *old_path,
1331 struct nameidata * new_nd); 1331 struct path *new_path);
1332 int (*sb_get_mnt_opts) (const struct super_block *sb, 1332 int (*sb_get_mnt_opts) (const struct super_block *sb,
1333 struct security_mnt_opts *opts); 1333 struct security_mnt_opts *opts);
1334 int (*sb_set_mnt_opts) (struct super_block *sb, 1334 int (*sb_set_mnt_opts) (struct super_block *sb,
@@ -1593,16 +1593,16 @@ void security_sb_free(struct super_block *sb);
1593int security_sb_copy_data(char *orig, char *copy); 1593int security_sb_copy_data(char *orig, char *copy);
1594int security_sb_kern_mount(struct super_block *sb, void *data); 1594int security_sb_kern_mount(struct super_block *sb, void *data);
1595int security_sb_statfs(struct dentry *dentry); 1595int security_sb_statfs(struct dentry *dentry);
1596int security_sb_mount(char *dev_name, struct nameidata *nd, 1596int security_sb_mount(char *dev_name, struct path *path,
1597 char *type, unsigned long flags, void *data); 1597 char *type, unsigned long flags, void *data);
1598int security_sb_check_sb(struct vfsmount *mnt, struct nameidata *nd); 1598int security_sb_check_sb(struct vfsmount *mnt, struct path *path);
1599int security_sb_umount(struct vfsmount *mnt, int flags); 1599int security_sb_umount(struct vfsmount *mnt, int flags);
1600void security_sb_umount_close(struct vfsmount *mnt); 1600void security_sb_umount_close(struct vfsmount *mnt);
1601void security_sb_umount_busy(struct vfsmount *mnt); 1601void security_sb_umount_busy(struct vfsmount *mnt);
1602void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *data); 1602void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *data);
1603void security_sb_post_addmount(struct vfsmount *mnt, struct nameidata *mountpoint_nd); 1603void security_sb_post_addmount(struct vfsmount *mnt, struct path *mountpoint);
1604int security_sb_pivotroot(struct nameidata *old_nd, struct nameidata *new_nd); 1604int security_sb_pivotroot(struct path *old_path, struct path *new_path);
1605void security_sb_post_pivotroot(struct nameidata *old_nd, struct nameidata *new_nd); 1605void security_sb_post_pivotroot(struct path *old_path, struct path *new_path);
1606int security_sb_get_mnt_opts(const struct super_block *sb, 1606int security_sb_get_mnt_opts(const struct super_block *sb,
1607 struct security_mnt_opts *opts); 1607 struct security_mnt_opts *opts);
1608int security_sb_set_mnt_opts(struct super_block *sb, struct security_mnt_opts *opts); 1608int security_sb_set_mnt_opts(struct super_block *sb, struct security_mnt_opts *opts);
@@ -1872,7 +1872,7 @@ static inline int security_sb_statfs (struct dentry *dentry)
1872 return 0; 1872 return 0;
1873} 1873}
1874 1874
1875static inline int security_sb_mount (char *dev_name, struct nameidata *nd, 1875static inline int security_sb_mount (char *dev_name, struct path *path,
1876 char *type, unsigned long flags, 1876 char *type, unsigned long flags,
1877 void *data) 1877 void *data)
1878{ 1878{
@@ -1880,7 +1880,7 @@ static inline int security_sb_mount (char *dev_name, struct nameidata *nd,
1880} 1880}
1881 1881
1882static inline int security_sb_check_sb (struct vfsmount *mnt, 1882static inline int security_sb_check_sb (struct vfsmount *mnt,
1883 struct nameidata *nd) 1883 struct path *path)
1884{ 1884{
1885 return 0; 1885 return 0;
1886} 1886}
@@ -1901,17 +1901,17 @@ static inline void security_sb_post_remount (struct vfsmount *mnt,
1901{ } 1901{ }
1902 1902
1903static inline void security_sb_post_addmount (struct vfsmount *mnt, 1903static inline void security_sb_post_addmount (struct vfsmount *mnt,
1904 struct nameidata *mountpoint_nd) 1904 struct path *mountpoint)
1905{ } 1905{ }
1906 1906
1907static inline int security_sb_pivotroot (struct nameidata *old_nd, 1907static inline int security_sb_pivotroot (struct path *old_path,
1908 struct nameidata *new_nd) 1908 struct path *new_path)
1909{ 1909{
1910 return 0; 1910 return 0;
1911} 1911}
1912 1912
1913static inline void security_sb_post_pivotroot (struct nameidata *old_nd, 1913static inline void security_sb_post_pivotroot (struct path *old_path,
1914 struct nameidata *new_nd) 1914 struct path *new_path)
1915{ } 1915{ }
1916static inline int security_sb_get_mnt_opts(const struct super_block *sb, 1916static inline int security_sb_get_mnt_opts(const struct super_block *sb,
1917 struct security_mnt_opts *opts) 1917 struct security_mnt_opts *opts)
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 1da1e6208a0a..5b5369c3c209 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -10,6 +10,7 @@ struct seq_operations;
10struct file; 10struct file;
11struct path; 11struct path;
12struct inode; 12struct inode;
13struct dentry;
13 14
14struct seq_file { 15struct seq_file {
15 char *buf; 16 char *buf;
@@ -30,6 +31,8 @@ struct seq_operations {
30 int (*show) (struct seq_file *m, void *v); 31 int (*show) (struct seq_file *m, void *v);
31}; 32};
32 33
34#define SEQ_SKIP 1
35
33int seq_open(struct file *, const struct seq_operations *); 36int seq_open(struct file *, const struct seq_operations *);
34ssize_t seq_read(struct file *, char __user *, size_t, loff_t *); 37ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
35loff_t seq_lseek(struct file *, loff_t, int); 38loff_t seq_lseek(struct file *, loff_t, int);
@@ -42,6 +45,9 @@ int seq_printf(struct seq_file *, const char *, ...)
42 __attribute__ ((format (printf,2,3))); 45 __attribute__ ((format (printf,2,3)));
43 46
44int seq_path(struct seq_file *, struct path *, char *); 47int seq_path(struct seq_file *, struct path *, char *);
48int seq_dentry(struct seq_file *, struct dentry *, char *);
49int seq_path_root(struct seq_file *m, struct path *path, struct path *root,
50 char *esc);
45 51
46int single_open(struct file *, int (*)(struct seq_file *, void *), void *); 52int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
47int single_release(struct inode *, struct file *); 53int single_release(struct inode *, struct file *);
diff --git a/include/linux/udf_fs.h b/include/linux/udf_fs.h
deleted file mode 100644
index aa88654eb76b..000000000000
--- a/include/linux/udf_fs.h
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 * udf_fs.h
3 *
4 * PURPOSE
5 * Included by fs/filesystems.c
6 *
7 * DESCRIPTION
8 * OSTA-UDF(tm) = Optical Storage Technology Association
9 * Universal Disk Format.
10 *
11 * This code is based on version 2.50 of the UDF specification,
12 * and revision 3 of the ECMA 167 standard [equivalent to ISO 13346].
13 * http://www.osta.org/ * http://www.ecma.ch/
14 * http://www.iso.org/
15 *
16 * COPYRIGHT
17 * This file is distributed under the terms of the GNU General Public
18 * License (GPL). Copies of the GPL can be obtained from:
19 * ftp://prep.ai.mit.edu/pub/gnu/GPL
20 * Each contributing author retains all rights to their own work.
21 *
22 * (C) 1999-2004 Ben Fennema
23 * (C) 1999-2000 Stelias Computing Inc
24 *
25 * HISTORY
26 *
27 */
28
29#ifndef _UDF_FS_H
30#define _UDF_FS_H 1
31
32#define UDF_PREALLOCATE
33#define UDF_DEFAULT_PREALLOC_BLOCKS 8
34
35#undef UDFFS_DEBUG
36
37#ifdef UDFFS_DEBUG
38#define udf_debug(f, a...) \
39 do { \
40 printk (KERN_DEBUG "UDF-fs DEBUG %s:%d:%s: ", \
41 __FILE__, __LINE__, __FUNCTION__); \
42 printk (f, ##a); \
43 } while (0)
44#else
45#define udf_debug(f, a...) /**/
46#endif
47
48#define udf_info(f, a...) \
49 printk (KERN_INFO "UDF-fs INFO " f, ##a);
50
51#endif /* _UDF_FS_H */
diff --git a/include/linux/udf_fs_i.h b/include/linux/udf_fs_i.h
index ffaf05679ffb..3536965913b0 100644
--- a/include/linux/udf_fs_i.h
+++ b/include/linux/udf_fs_i.h
@@ -9,41 +9,10 @@
9 * ftp://prep.ai.mit.edu/pub/gnu/GPL 9 * ftp://prep.ai.mit.edu/pub/gnu/GPL
10 * Each contributing author retains all rights to their own work. 10 * Each contributing author retains all rights to their own work.
11 */ 11 */
12
13#ifndef _UDF_FS_I_H 12#ifndef _UDF_FS_I_H
14#define _UDF_FS_I_H 1 13#define _UDF_FS_I_H 1
15 14
16#ifdef __KERNEL__
17
18struct udf_inode_info
19{
20 struct timespec i_crtime;
21 /* Physical address of inode */
22 kernel_lb_addr i_location;
23 __u64 i_unique;
24 __u32 i_lenEAttr;
25 __u32 i_lenAlloc;
26 __u64 i_lenExtents;
27 __u32 i_next_alloc_block;
28 __u32 i_next_alloc_goal;
29 unsigned i_alloc_type : 3;
30 unsigned i_efe : 1;
31 unsigned i_use : 1;
32 unsigned i_strat4096 : 1;
33 unsigned reserved : 26;
34 union
35 {
36 short_ad *i_sad;
37 long_ad *i_lad;
38 __u8 *i_data;
39 } i_ext;
40 struct inode vfs_inode;
41};
42
43#endif
44
45/* exported IOCTLs, we have 'l', 0x40-0x7f */ 15/* exported IOCTLs, we have 'l', 0x40-0x7f */
46
47#define UDF_GETEASIZE _IOR('l', 0x40, int) 16#define UDF_GETEASIZE _IOR('l', 0x40, int)
48#define UDF_GETEABLOCK _IOR('l', 0x41, void *) 17#define UDF_GETEABLOCK _IOR('l', 0x41, void *)
49#define UDF_GETVOLIDENT _IOR('l', 0x42, void *) 18#define UDF_GETVOLIDENT _IOR('l', 0x42, void *)
diff --git a/include/linux/udf_fs_sb.h b/include/linux/udf_fs_sb.h
deleted file mode 100644
index 9bc47352b6b4..000000000000
--- a/include/linux/udf_fs_sb.h
+++ /dev/null
@@ -1,117 +0,0 @@
1/*
2 * udf_fs_sb.h
3 *
4 * This include file is for the Linux kernel/module.
5 *
6 * COPYRIGHT
7 * This file is distributed under the terms of the GNU General Public
8 * License (GPL). Copies of the GPL can be obtained from:
9 * ftp://prep.ai.mit.edu/pub/gnu/GPL
10 * Each contributing author retains all rights to their own work.
11 */
12
13#ifndef _UDF_FS_SB_H
14#define _UDF_FS_SB_H 1
15
16#include <linux/mutex.h>
17
18#pragma pack(1)
19
20#define UDF_MAX_BLOCK_LOADED 8
21
22#define UDF_TYPE1_MAP15 0x1511U
23#define UDF_VIRTUAL_MAP15 0x1512U
24#define UDF_VIRTUAL_MAP20 0x2012U
25#define UDF_SPARABLE_MAP15 0x1522U
26
27struct udf_sparing_data
28{
29 __u16 s_packet_len;
30 struct buffer_head *s_spar_map[4];
31};
32
33struct udf_virtual_data
34{
35 __u32 s_num_entries;
36 __u16 s_start_offset;
37};
38
39struct udf_bitmap
40{
41 __u32 s_extLength;
42 __u32 s_extPosition;
43 __u16 s_nr_groups;
44 struct buffer_head **s_block_bitmap;
45};
46
47struct udf_part_map
48{
49 union
50 {
51 struct udf_bitmap *s_bitmap;
52 struct inode *s_table;
53 } s_uspace;
54 union
55 {
56 struct udf_bitmap *s_bitmap;
57 struct inode *s_table;
58 } s_fspace;
59 __u32 s_partition_root;
60 __u32 s_partition_len;
61 __u16 s_partition_type;
62 __u16 s_partition_num;
63 union
64 {
65 struct udf_sparing_data s_sparing;
66 struct udf_virtual_data s_virtual;
67 } s_type_specific;
68 __u32 (*s_partition_func)(struct super_block *, __u32, __u16, __u32);
69 __u16 s_volumeseqnum;
70 __u16 s_partition_flags;
71};
72
73#pragma pack()
74
75struct udf_sb_info
76{
77 struct udf_part_map *s_partmaps;
78 __u8 s_volume_ident[32];
79
80 /* Overall info */
81 __u16 s_partitions;
82 __u16 s_partition;
83
84 /* Sector headers */
85 __s32 s_session;
86 __u32 s_anchor[4];
87 __u32 s_last_block;
88
89 struct buffer_head *s_lvid_bh;
90
91 /* Default permissions */
92 mode_t s_umask;
93 gid_t s_gid;
94 uid_t s_uid;
95
96 /* Root Info */
97 struct timespec s_record_time;
98
99 /* Fileset Info */
100 __u16 s_serial_number;
101
102 /* highest UDF revision we have recorded to this media */
103 __u16 s_udfrev;
104
105 /* Miscellaneous flags */
106 __u32 s_flags;
107
108 /* Encoding info */
109 struct nls_table *s_nls_map;
110
111 /* VAT inode */
112 struct inode *s_vat_inode;
113
114 struct mutex s_alloc_mutex;
115};
116
117#endif /* _UDF_FS_SB_H */
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index b56b6a10fe5e..baa9f372cfd1 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -436,6 +436,9 @@ struct xfrm_tmpl
436/* May skip this transfomration if no SA is found */ 436/* May skip this transfomration if no SA is found */
437 __u8 optional; 437 __u8 optional;
438 438
439/* Skip aalgos/ealgos/calgos checks. */
440 __u8 allalgs;
441
439/* Bit mask of algos allowed for acquisition */ 442/* Bit mask of algos allowed for acquisition */
440 __u32 aalgos; 443 __u32 aalgos;
441 __u32 ealgos; 444 __u32 ealgos;
diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
index 01480581f825..049edc5e6461 100644
--- a/include/sound/ac97_codec.h
+++ b/include/sound/ac97_codec.h
@@ -397,6 +397,7 @@
397#define AC97_HAS_NO_TONE (1<<16) /* no Tone volume */ 397#define AC97_HAS_NO_TONE (1<<16) /* no Tone volume */
398#define AC97_HAS_NO_STD_PCM (1<<17) /* no standard AC97 PCM volume and mute */ 398#define AC97_HAS_NO_STD_PCM (1<<17) /* no standard AC97 PCM volume and mute */
399#define AC97_HAS_NO_AUX (1<<18) /* no standard AC97 AUX volume and mute */ 399#define AC97_HAS_NO_AUX (1<<18) /* no standard AC97 AUX volume and mute */
400#define AC97_HAS_8CH (1<<19) /* supports 8-channel output */
400 401
401/* rates indexes */ 402/* rates indexes */
402#define AC97_RATES_FRONT_DAC 0 403#define AC97_RATES_FRONT_DAC 0
diff --git a/include/sound/ak4114.h b/include/sound/ak4114.h
index 4e80d3fe7381..d293d36a66b8 100644
--- a/include/sound/ak4114.h
+++ b/include/sound/ak4114.h
@@ -182,6 +182,7 @@ struct ak4114 {
182 unsigned char rcs0; 182 unsigned char rcs0;
183 unsigned char rcs1; 183 unsigned char rcs1;
184 struct delayed_work work; 184 struct delayed_work work;
185 unsigned int check_flags;
185 void *change_callback_private; 186 void *change_callback_private;
186 void (*change_callback)(struct ak4114 *ak4114, unsigned char c0, unsigned char c1); 187 void (*change_callback)(struct ak4114 *ak4114, unsigned char c0, unsigned char c1);
187}; 188};
diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
index 6153b91cdc3e..891cf1aea8b1 100644
--- a/include/sound/ak4xxx-adda.h
+++ b/include/sound/ak4xxx-adda.h
@@ -68,7 +68,7 @@ struct snd_akm4xxx {
68 enum { 68 enum {
69 SND_AK4524, SND_AK4528, SND_AK4529, 69 SND_AK4524, SND_AK4528, SND_AK4529,
70 SND_AK4355, SND_AK4358, SND_AK4381, 70 SND_AK4355, SND_AK4358, SND_AK4381,
71 SND_AK5365, NON_AKM 71 SND_AK5365
72 } type; 72 } type;
73 73
74 /* (array) information of combined codecs */ 74 /* (array) information of combined codecs */
diff --git a/include/sound/asoundef.h b/include/sound/asoundef.h
index 024ce62f7d16..a6e0facf8a37 100644
--- a/include/sound/asoundef.h
+++ b/include/sound/asoundef.h
@@ -112,6 +112,14 @@
112#define IEC958_AES3_CON_CLOCK_1000PPM (0<<4) /* 1000 ppm */ 112#define IEC958_AES3_CON_CLOCK_1000PPM (0<<4) /* 1000 ppm */
113#define IEC958_AES3_CON_CLOCK_50PPM (1<<4) /* 50 ppm */ 113#define IEC958_AES3_CON_CLOCK_50PPM (1<<4) /* 50 ppm */
114#define IEC958_AES3_CON_CLOCK_VARIABLE (2<<4) /* variable pitch */ 114#define IEC958_AES3_CON_CLOCK_VARIABLE (2<<4) /* variable pitch */
115#define IEC958_AES4_CON_MAX_WORDLEN_24 (1<<0) /* 0 = 20-bit, 1 = 24-bit */
116#define IEC958_AES4_CON_WORDLEN (7<<1) /* mask - sample word length */
117#define IEC958_AES4_CON_WORDLEN_NOTID (0<<1) /* not indicated */
118#define IEC958_AES4_CON_WORDLEN_20_16 (1<<1) /* 20-bit or 16-bit */
119#define IEC958_AES4_CON_WORDLEN_22_18 (2<<1) /* 22-bit or 18-bit */
120#define IEC958_AES4_CON_WORDLEN_23_19 (4<<1) /* 23-bit or 19-bit */
121#define IEC958_AES4_CON_WORDLEN_24_20 (5<<1) /* 24-bit or 20-bit */
122#define IEC958_AES4_CON_WORDLEN_21_17 (6<<1) /* 21-bit or 17-bit */
115 123
116/***************************************************************************** 124/*****************************************************************************
117 * * 125 * *
diff --git a/include/sound/control.h b/include/sound/control.h
index e79baa63912f..3dc1291f52db 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -169,4 +169,11 @@ int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
169int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol, 169int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
170 struct snd_ctl_elem_info *uinfo); 170 struct snd_ctl_elem_info *uinfo);
171 171
172/*
173 * virtual master control
174 */
175struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
176 const unsigned int *tlv);
177int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave);
178
172#endif /* __SOUND_CONTROL_H */ 179#endif /* __SOUND_CONTROL_H */
diff --git a/include/sound/core.h b/include/sound/core.h
index 4fc0235ad784..695ee53488a3 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -277,8 +277,8 @@ int snd_minor_info_done(void);
277int snd_minor_info_oss_init(void); 277int snd_minor_info_oss_init(void);
278int snd_minor_info_oss_done(void); 278int snd_minor_info_oss_done(void);
279#else 279#else
280#define snd_minor_info_oss_init() /*NOP*/ 280static inline int snd_minor_info_oss_init(void) { return 0; }
281#define snd_minor_info_oss_done() /*NOP*/ 281static inline int snd_minor_info_oss_done(void) { return 0; }
282#endif 282#endif
283 283
284/* memory.c */ 284/* memory.c */
@@ -310,7 +310,7 @@ int snd_card_file_add(struct snd_card *card, struct file *file);
310int snd_card_file_remove(struct snd_card *card, struct file *file); 310int snd_card_file_remove(struct snd_card *card, struct file *file);
311 311
312#ifndef snd_card_set_dev 312#ifndef snd_card_set_dev
313#define snd_card_set_dev(card,devptr) ((card)->dev = (devptr)) 313#define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
314#endif 314#endif
315 315
316/* device.c */ 316/* device.c */
@@ -373,7 +373,7 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
373 * snd_printd - debug printk 373 * snd_printd - debug printk
374 * @fmt: format string 374 * @fmt: format string
375 * 375 *
376 * Compiled only when Works like snd_printk() for debugging purpose. 376 * Works like snd_printk() for debugging purposes.
377 * Ignored when CONFIG_SND_DEBUG is not set. 377 * Ignored when CONFIG_SND_DEBUG is not set.
378 */ 378 */
379#define snd_printd(fmt, args...) \ 379#define snd_printd(fmt, args...) \
@@ -417,7 +417,7 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
417 * snd_printdd - debug printk 417 * snd_printdd - debug printk
418 * @format: format string 418 * @format: format string
419 * 419 *
420 * Compiled only when Works like snd_printk() for debugging purpose. 420 * Works like snd_printk() for debugging purposes.
421 * Ignored when CONFIG_SND_DEBUG_DETECT is not set. 421 * Ignored when CONFIG_SND_DEBUG_DETECT is not set.
422 */ 422 */
423#define snd_printdd(format, args...) snd_printk(format, ##args) 423#define snd_printdd(format, args...) snd_printk(format, ##args)
diff --git a/include/sound/mpu401.h b/include/sound/mpu401.h
index d45218b44dfe..68b634b75068 100644
--- a/include/sound/mpu401.h
+++ b/include/sound/mpu401.h
@@ -103,6 +103,21 @@ struct snd_mpu401 {
103#define MPU401D(mpu) (mpu)->port 103#define MPU401D(mpu) (mpu)->port
104 104
105/* 105/*
106 * control register bits
107 */
108/* read MPU401C() */
109#define MPU401_RX_EMPTY 0x80
110#define MPU401_TX_FULL 0x40
111
112/* write MPU401C() */
113#define MPU401_RESET 0xff
114#define MPU401_ENTER_UART 0x3f
115
116/* read MPU401D() */
117#define MPU401_ACK 0xfe
118
119
120/*
106 121
107 */ 122 */
108 123
diff --git a/include/sound/version.h b/include/sound/version.h
index fac66c49445a..ed6fb2eb1eac 100644
--- a/include/sound/version.h
+++ b/include/sound/version.h
@@ -1,3 +1,3 @@
1/* include/version.h. Generated by alsa/ksync script. */ 1/* include/version.h. Generated by alsa/ksync script. */
2#define CONFIG_SND_VERSION "1.0.16rc2" 2#define CONFIG_SND_VERSION "1.0.16"
3#define CONFIG_SND_DATE " (Thu Jan 31 16:40:16 2008 UTC)" 3#define CONFIG_SND_DATE ""
diff --git a/kernel/exit.c b/kernel/exit.c
index 073005b1cfb2..cece89f80ab4 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -521,7 +521,7 @@ void reset_files_struct(struct task_struct *tsk, struct files_struct *files)
521} 521}
522EXPORT_SYMBOL(reset_files_struct); 522EXPORT_SYMBOL(reset_files_struct);
523 523
524static void __exit_files(struct task_struct *tsk) 524void exit_files(struct task_struct *tsk)
525{ 525{
526 struct files_struct * files = tsk->files; 526 struct files_struct * files = tsk->files;
527 527
@@ -533,12 +533,7 @@ static void __exit_files(struct task_struct *tsk)
533 } 533 }
534} 534}
535 535
536void exit_files(struct task_struct *tsk) 536void put_fs_struct(struct fs_struct *fs)
537{
538 __exit_files(tsk);
539}
540
541static void __put_fs_struct(struct fs_struct *fs)
542{ 537{
543 /* No need to hold fs->lock if we are killing it */ 538 /* No need to hold fs->lock if we are killing it */
544 if (atomic_dec_and_test(&fs->count)) { 539 if (atomic_dec_and_test(&fs->count)) {
@@ -550,12 +545,7 @@ static void __put_fs_struct(struct fs_struct *fs)
550 } 545 }
551} 546}
552 547
553void put_fs_struct(struct fs_struct *fs) 548void exit_fs(struct task_struct *tsk)
554{
555 __put_fs_struct(fs);
556}
557
558static void __exit_fs(struct task_struct *tsk)
559{ 549{
560 struct fs_struct * fs = tsk->fs; 550 struct fs_struct * fs = tsk->fs;
561 551
@@ -563,15 +553,10 @@ static void __exit_fs(struct task_struct *tsk)
563 task_lock(tsk); 553 task_lock(tsk);
564 tsk->fs = NULL; 554 tsk->fs = NULL;
565 task_unlock(tsk); 555 task_unlock(tsk);
566 __put_fs_struct(fs); 556 put_fs_struct(fs);
567 } 557 }
568} 558}
569 559
570void exit_fs(struct task_struct *tsk)
571{
572 __exit_fs(tsk);
573}
574
575EXPORT_SYMBOL_GPL(exit_fs); 560EXPORT_SYMBOL_GPL(exit_fs);
576 561
577/* 562/*
@@ -967,8 +952,8 @@ NORET_TYPE void do_exit(long code)
967 if (group_dead) 952 if (group_dead)
968 acct_process(); 953 acct_process();
969 exit_sem(tsk); 954 exit_sem(tsk);
970 __exit_files(tsk); 955 exit_files(tsk);
971 __exit_fs(tsk); 956 exit_fs(tsk);
972 check_stack_usage(); 957 check_stack_usage();
973 exit_thread(); 958 exit_thread();
974 cgroup_exit(tsk, 1); 959 cgroup_exit(tsk, 1);
diff --git a/kernel/sched.c b/kernel/sched.c
index 57ba7ea9b744..0014b03adaca 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -7035,6 +7035,7 @@ static int find_next_best_node(int node, nodemask_t *used_nodes)
7035/** 7035/**
7036 * sched_domain_node_span - get a cpumask for a node's sched_domain 7036 * sched_domain_node_span - get a cpumask for a node's sched_domain
7037 * @node: node whose cpumask we're constructing 7037 * @node: node whose cpumask we're constructing
7038 * @span: resulting cpumask
7038 * 7039 *
7039 * Given a node, construct a good cpumask for its sched_domain to span. It 7040 * Given a node, construct a good cpumask for its sched_domain to span. It
7040 * should be one that prevents unnecessary balancing, but also spreads tasks 7041 * should be one that prevents unnecessary balancing, but also spreads tasks
diff --git a/kernel/time.c b/kernel/time.c
index a5ec013b6c80..35d373a98782 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -379,6 +379,7 @@ void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec)
379 ts->tv_sec = sec; 379 ts->tv_sec = sec;
380 ts->tv_nsec = nsec; 380 ts->tv_nsec = nsec;
381} 381}
382EXPORT_SYMBOL(set_normalized_timespec);
382 383
383/** 384/**
384 * ns_to_timespec - Convert nanoseconds to timespec 385 * ns_to_timespec - Convert nanoseconds to timespec
diff --git a/lib/lmb.c b/lib/lmb.c
index 896e2832099e..207147ab25e4 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -346,7 +346,7 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
346 if (j < 0) { 346 if (j < 0) {
347 /* this area isn't reserved, take it */ 347 /* this area isn't reserved, take it */
348 if (lmb_add_region(&lmb.reserved, base, 348 if (lmb_add_region(&lmb.reserved, base,
349 size) < 0) 349 lmb_align_up(size, align)) < 0)
350 return 0; 350 return 0;
351 return base; 351 return base;
352 } 352 }
diff --git a/mm/slub.c b/mm/slub.c
index 7f8aaa291a4e..39592b5ce68a 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -521,7 +521,7 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)
521static void object_err(struct kmem_cache *s, struct page *page, 521static void object_err(struct kmem_cache *s, struct page *page,
522 u8 *object, char *reason) 522 u8 *object, char *reason)
523{ 523{
524 slab_bug(s, reason); 524 slab_bug(s, "%s", reason);
525 print_trailer(s, page, object); 525 print_trailer(s, page, object);
526} 526}
527 527
@@ -533,7 +533,7 @@ static void slab_err(struct kmem_cache *s, struct page *page, char *fmt, ...)
533 va_start(args, fmt); 533 va_start(args, fmt);
534 vsnprintf(buf, sizeof(buf), fmt, args); 534 vsnprintf(buf, sizeof(buf), fmt, args);
535 va_end(args); 535 va_end(args);
536 slab_bug(s, fmt); 536 slab_bug(s, "%s", buf);
537 print_page_info(page); 537 print_page_info(page);
538 dump_stack(); 538 dump_stack();
539} 539}
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 7635d3f72723..4e7b847347f7 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -87,6 +87,7 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
87 return ret; 87 return ret;
88} 88}
89 89
90NETDEVICE_SHOW(dev_id, fmt_hex);
90NETDEVICE_SHOW(addr_len, fmt_dec); 91NETDEVICE_SHOW(addr_len, fmt_dec);
91NETDEVICE_SHOW(iflink, fmt_dec); 92NETDEVICE_SHOW(iflink, fmt_dec);
92NETDEVICE_SHOW(ifindex, fmt_dec); 93NETDEVICE_SHOW(ifindex, fmt_dec);
@@ -210,6 +211,7 @@ static ssize_t store_tx_queue_len(struct device *dev,
210 211
211static struct device_attribute net_class_attributes[] = { 212static struct device_attribute net_class_attributes[] = {
212 __ATTR(addr_len, S_IRUGO, show_addr_len, NULL), 213 __ATTR(addr_len, S_IRUGO, show_addr_len, NULL),
214 __ATTR(dev_id, S_IRUGO, show_dev_id, NULL),
213 __ATTR(iflink, S_IRUGO, show_iflink, NULL), 215 __ATTR(iflink, S_IRUGO, show_iflink, NULL),
214 __ATTR(ifindex, S_IRUGO, show_ifindex, NULL), 216 __ATTR(ifindex, S_IRUGO, show_ifindex, NULL),
215 __ATTR(features, S_IRUGO, show_features, NULL), 217 __ATTR(features, S_IRUGO, show_features, NULL),
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index bc39e417694a..cf857c4dc7b1 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -82,6 +82,11 @@ int rtnl_trylock(void)
82 return mutex_trylock(&rtnl_mutex); 82 return mutex_trylock(&rtnl_mutex);
83} 83}
84 84
85int rtnl_is_locked(void)
86{
87 return mutex_is_locked(&rtnl_mutex);
88}
89
85static struct rtnl_link *rtnl_msg_handlers[NPROTO]; 90static struct rtnl_link *rtnl_msg_handlers[NPROTO];
86 91
87static inline int rtm_msgindex(int msgtype) 92static inline int rtm_msgindex(int msgtype)
@@ -1402,6 +1407,7 @@ EXPORT_SYMBOL(rtnetlink_put_metrics);
1402EXPORT_SYMBOL(rtnl_lock); 1407EXPORT_SYMBOL(rtnl_lock);
1403EXPORT_SYMBOL(rtnl_trylock); 1408EXPORT_SYMBOL(rtnl_trylock);
1404EXPORT_SYMBOL(rtnl_unlock); 1409EXPORT_SYMBOL(rtnl_unlock);
1410EXPORT_SYMBOL(rtnl_is_locked);
1405EXPORT_SYMBOL(rtnl_unicast); 1411EXPORT_SYMBOL(rtnl_unicast);
1406EXPORT_SYMBOL(rtnl_notify); 1412EXPORT_SYMBOL(rtnl_notify);
1407EXPORT_SYMBOL(rtnl_set_sk_err); 1413EXPORT_SYMBOL(rtnl_set_sk_err);
diff --git a/net/dccp/probe.c b/net/dccp/probe.c
index 7053bb827bc8..6e1df62bd7c9 100644
--- a/net/dccp/probe.c
+++ b/net/dccp/probe.c
@@ -46,29 +46,24 @@ struct {
46 struct kfifo *fifo; 46 struct kfifo *fifo;
47 spinlock_t lock; 47 spinlock_t lock;
48 wait_queue_head_t wait; 48 wait_queue_head_t wait;
49 struct timeval tstart; 49 struct timespec tstart;
50} dccpw; 50} dccpw;
51 51
52static void printl(const char *fmt, ...) 52static void printl(const char *fmt, ...)
53{ 53{
54 va_list args; 54 va_list args;
55 int len; 55 int len;
56 struct timeval now; 56 struct timespec now;
57 char tbuf[256]; 57 char tbuf[256];
58 58
59 va_start(args, fmt); 59 va_start(args, fmt);
60 do_gettimeofday(&now); 60 getnstimeofday(&now);
61 61
62 now.tv_sec -= dccpw.tstart.tv_sec; 62 now = timespec_sub(now, dccpw.tstart);
63 now.tv_usec -= dccpw.tstart.tv_usec;
64 if (now.tv_usec < 0) {
65 --now.tv_sec;
66 now.tv_usec += 1000000;
67 }
68 63
69 len = sprintf(tbuf, "%lu.%06lu ", 64 len = sprintf(tbuf, "%lu.%06lu ",
70 (unsigned long) now.tv_sec, 65 (unsigned long) now.tv_sec,
71 (unsigned long) now.tv_usec); 66 (unsigned long) now.tv_nsec / NSEC_PER_USEC);
72 len += vscnprintf(tbuf+len, sizeof(tbuf)-len, fmt, args); 67 len += vscnprintf(tbuf+len, sizeof(tbuf)-len, fmt, args);
73 va_end(args); 68 va_end(args);
74 69
@@ -119,7 +114,7 @@ static struct jprobe dccp_send_probe = {
119static int dccpprobe_open(struct inode *inode, struct file *file) 114static int dccpprobe_open(struct inode *inode, struct file *file)
120{ 115{
121 kfifo_reset(dccpw.fifo); 116 kfifo_reset(dccpw.fifo);
122 do_gettimeofday(&dccpw.tstart); 117 getnstimeofday(&dccpw.tstart);
123 return 0; 118 return 0;
124} 119}
125 120
diff --git a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c
index 02088deb0461..2e2fc3376ac9 100644
--- a/net/ipv4/fib_hash.c
+++ b/net/ipv4/fib_hash.c
@@ -1003,7 +1003,7 @@ static unsigned fib_flag_trans(int type, __be32 mask, struct fib_info *fi)
1003static int fib_seq_show(struct seq_file *seq, void *v) 1003static int fib_seq_show(struct seq_file *seq, void *v)
1004{ 1004{
1005 struct fib_iter_state *iter; 1005 struct fib_iter_state *iter;
1006 char bf[128]; 1006 int len;
1007 __be32 prefix, mask; 1007 __be32 prefix, mask;
1008 unsigned flags; 1008 unsigned flags;
1009 struct fib_node *f; 1009 struct fib_node *f;
@@ -1025,18 +1025,19 @@ static int fib_seq_show(struct seq_file *seq, void *v)
1025 mask = FZ_MASK(iter->zone); 1025 mask = FZ_MASK(iter->zone);
1026 flags = fib_flag_trans(fa->fa_type, mask, fi); 1026 flags = fib_flag_trans(fa->fa_type, mask, fi);
1027 if (fi) 1027 if (fi)
1028 snprintf(bf, sizeof(bf), 1028 seq_printf(seq,
1029 "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u", 1029 "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
1030 fi->fib_dev ? fi->fib_dev->name : "*", prefix, 1030 fi->fib_dev ? fi->fib_dev->name : "*", prefix,
1031 fi->fib_nh->nh_gw, flags, 0, 0, fi->fib_priority, 1031 fi->fib_nh->nh_gw, flags, 0, 0, fi->fib_priority,
1032 mask, (fi->fib_advmss ? fi->fib_advmss + 40 : 0), 1032 mask, (fi->fib_advmss ? fi->fib_advmss + 40 : 0),
1033 fi->fib_window, 1033 fi->fib_window,
1034 fi->fib_rtt >> 3); 1034 fi->fib_rtt >> 3, &len);
1035 else 1035 else
1036 snprintf(bf, sizeof(bf), 1036 seq_printf(seq,
1037 "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u", 1037 "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
1038 prefix, 0, flags, 0, 0, 0, mask, 0, 0, 0); 1038 prefix, 0, flags, 0, 0, 0, mask, 0, 0, 0, &len);
1039 seq_printf(seq, "%-127s\n", bf); 1039
1040 seq_printf(seq, "%*s\n", 127 - len, "");
1040out: 1041out:
1041 return 0; 1042 return 0;
1042} 1043}
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index ea294fffb9ce..4b02d14e7ab9 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -2602,15 +2602,16 @@ static int fib_route_seq_show(struct seq_file *seq, void *v)
2602 list_for_each_entry_rcu(fa, &li->falh, fa_list) { 2602 list_for_each_entry_rcu(fa, &li->falh, fa_list) {
2603 const struct fib_info *fi = fa->fa_info; 2603 const struct fib_info *fi = fa->fa_info;
2604 unsigned flags = fib_flag_trans(fa->fa_type, mask, fi); 2604 unsigned flags = fib_flag_trans(fa->fa_type, mask, fi);
2605 char bf[128]; 2605 int len;
2606 2606
2607 if (fa->fa_type == RTN_BROADCAST 2607 if (fa->fa_type == RTN_BROADCAST
2608 || fa->fa_type == RTN_MULTICAST) 2608 || fa->fa_type == RTN_MULTICAST)
2609 continue; 2609 continue;
2610 2610
2611 if (fi) 2611 if (fi)
2612 snprintf(bf, sizeof(bf), 2612 seq_printf(seq,
2613 "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u", 2613 "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
2614 "%d\t%08X\t%d\t%u\t%u%n",
2614 fi->fib_dev ? fi->fib_dev->name : "*", 2615 fi->fib_dev ? fi->fib_dev->name : "*",
2615 prefix, 2616 prefix,
2616 fi->fib_nh->nh_gw, flags, 0, 0, 2617 fi->fib_nh->nh_gw, flags, 0, 0,
@@ -2619,14 +2620,15 @@ static int fib_route_seq_show(struct seq_file *seq, void *v)
2619 (fi->fib_advmss ? 2620 (fi->fib_advmss ?
2620 fi->fib_advmss + 40 : 0), 2621 fi->fib_advmss + 40 : 0),
2621 fi->fib_window, 2622 fi->fib_window,
2622 fi->fib_rtt >> 3); 2623 fi->fib_rtt >> 3, &len);
2623 else 2624 else
2624 snprintf(bf, sizeof(bf), 2625 seq_printf(seq,
2625 "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u", 2626 "*\t%08X\t%08X\t%04X\t%d\t%u\t"
2627 "%d\t%08X\t%d\t%u\t%u%n",
2626 prefix, 0, flags, 0, 0, 0, 2628 prefix, 0, flags, 0, 0, 0,
2627 mask, 0, 0, 0); 2629 mask, 0, 0, 0, &len);
2628 2630
2629 seq_printf(seq, "%-127s\n", bf); 2631 seq_printf(seq, "%*s\n", 127 - len, "");
2630 } 2632 }
2631 } 2633 }
2632 2634
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index f064031f2031..c67d00e8c600 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -847,7 +847,7 @@ static void icmp_echo(struct sk_buff *skb)
847 */ 847 */
848static void icmp_timestamp(struct sk_buff *skb) 848static void icmp_timestamp(struct sk_buff *skb)
849{ 849{
850 struct timeval tv; 850 struct timespec tv;
851 struct icmp_bxm icmp_param; 851 struct icmp_bxm icmp_param;
852 /* 852 /*
853 * Too short. 853 * Too short.
@@ -858,9 +858,9 @@ static void icmp_timestamp(struct sk_buff *skb)
858 /* 858 /*
859 * Fill in the current time as ms since midnight UT: 859 * Fill in the current time as ms since midnight UT:
860 */ 860 */
861 do_gettimeofday(&tv); 861 getnstimeofday(&tv);
862 icmp_param.data.times[1] = htonl((tv.tv_sec % 86400) * 1000 + 862 icmp_param.data.times[1] = htonl((tv.tv_sec % 86400) * MSEC_PER_SEC +
863 tv.tv_usec / 1000); 863 tv.tv_nsec / NSEC_PER_MSEC);
864 icmp_param.data.times[2] = icmp_param.data.times[1]; 864 icmp_param.data.times[2] = icmp_param.data.times[1];
865 if (skb_copy_bits(skb, 0, &icmp_param.data.times[0], 4)) 865 if (skb_copy_bits(skb, 0, &icmp_param.data.times[0], 4))
866 BUG(); 866 BUG();
@@ -1144,7 +1144,7 @@ static void __net_exit icmp_sk_exit(struct net *net)
1144 net->ipv4.icmp_sk = NULL; 1144 net->ipv4.icmp_sk = NULL;
1145} 1145}
1146 1146
1147int __net_init icmp_sk_init(struct net *net) 1147static int __net_init icmp_sk_init(struct net *net)
1148{ 1148{
1149 int i, err; 1149 int i, err;
1150 1150
diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c
index d107543d3f81..33126ad2cfdc 100644
--- a/net/ipv4/ip_options.c
+++ b/net/ipv4/ip_options.c
@@ -55,10 +55,10 @@ void ip_options_build(struct sk_buff * skb, struct ip_options * opt,
55 if (opt->ts_needaddr) 55 if (opt->ts_needaddr)
56 ip_rt_get_source(iph+opt->ts+iph[opt->ts+2]-9, rt); 56 ip_rt_get_source(iph+opt->ts+iph[opt->ts+2]-9, rt);
57 if (opt->ts_needtime) { 57 if (opt->ts_needtime) {
58 struct timeval tv; 58 struct timespec tv;
59 __be32 midtime; 59 __be32 midtime;
60 do_gettimeofday(&tv); 60 getnstimeofday(&tv);
61 midtime = htonl((tv.tv_sec % 86400) * 1000 + tv.tv_usec / 1000); 61 midtime = htonl((tv.tv_sec % 86400) * MSEC_PER_SEC + tv.tv_nsec / NSEC_PER_MSEC);
62 memcpy(iph+opt->ts+iph[opt->ts+2]-5, &midtime, 4); 62 memcpy(iph+opt->ts+iph[opt->ts+2]-5, &midtime, 4);
63 } 63 }
64 return; 64 return;
@@ -406,10 +406,10 @@ int ip_options_compile(struct net *net,
406 break; 406 break;
407 } 407 }
408 if (timeptr) { 408 if (timeptr) {
409 struct timeval tv; 409 struct timespec tv;
410 __be32 midtime; 410 __be32 midtime;
411 do_gettimeofday(&tv); 411 getnstimeofday(&tv);
412 midtime = htonl((tv.tv_sec % 86400) * 1000 + tv.tv_usec / 1000); 412 midtime = htonl((tv.tv_sec % 86400) * MSEC_PER_SEC + tv.tv_nsec / NSEC_PER_MSEC);
413 memcpy(timeptr, &midtime, sizeof(__be32)); 413 memcpy(timeptr, &midtime, sizeof(__be32));
414 opt->is_changed = 1; 414 opt->is_changed = 1;
415 } 415 }
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 780e9484c825..ce25a13f3430 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -367,10 +367,10 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
367 "HHUptod\tSpecDst"); 367 "HHUptod\tSpecDst");
368 else { 368 else {
369 struct rtable *r = v; 369 struct rtable *r = v;
370 char temp[256]; 370 int len;
371 371
372 sprintf(temp, "%s\t%08lX\t%08lX\t%8X\t%d\t%u\t%d\t" 372 seq_printf(seq, "%s\t%08lX\t%08lX\t%8X\t%d\t%u\t%d\t"
373 "%08lX\t%d\t%u\t%u\t%02X\t%d\t%1d\t%08X", 373 "%08lX\t%d\t%u\t%u\t%02X\t%d\t%1d\t%08X%n",
374 r->u.dst.dev ? r->u.dst.dev->name : "*", 374 r->u.dst.dev ? r->u.dst.dev->name : "*",
375 (unsigned long)r->rt_dst, (unsigned long)r->rt_gateway, 375 (unsigned long)r->rt_dst, (unsigned long)r->rt_gateway,
376 r->rt_flags, atomic_read(&r->u.dst.__refcnt), 376 r->rt_flags, atomic_read(&r->u.dst.__refcnt),
@@ -384,8 +384,9 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
384 r->u.dst.hh ? atomic_read(&r->u.dst.hh->hh_refcnt) : -1, 384 r->u.dst.hh ? atomic_read(&r->u.dst.hh->hh_refcnt) : -1,
385 r->u.dst.hh ? (r->u.dst.hh->hh_output == 385 r->u.dst.hh ? (r->u.dst.hh->hh_output ==
386 dev_queue_xmit) : 0, 386 dev_queue_xmit) : 0,
387 r->rt_spec_dst); 387 r->rt_spec_dst, &len);
388 seq_printf(seq, "%-127s\n", temp); 388
389 seq_printf(seq, "%*s\n", 127 - len, "");
389 } 390 }
390 return 0; 391 return 0;
391} 392}
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 58ac838bf460..f88653138621 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1722,7 +1722,7 @@ static int tcp_close_state(struct sock *sk)
1722 1722
1723/* 1723/*
1724 * Shutdown the sending side of a connection. Much like close except 1724 * Shutdown the sending side of a connection. Much like close except
1725 * that we don't receive shut down or set_sock_flag(sk, SOCK_DEAD). 1725 * that we don't receive shut down or sock_set_flag(sk, SOCK_DEAD).
1726 */ 1726 */
1727 1727
1728void tcp_shutdown(struct sock *sk, int how) 1728void tcp_shutdown(struct sock *sk, int how)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index cdc051bfdb4d..ac9b8482f702 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -2298,7 +2298,7 @@ static inline int tcp_packet_delayed(struct tcp_sock *tp)
2298{ 2298{
2299 return !tp->retrans_stamp || 2299 return !tp->retrans_stamp ||
2300 (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && 2300 (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr &&
2301 (__s32)(tp->rx_opt.rcv_tsecr - tp->retrans_stamp) < 0); 2301 before(tp->rx_opt.rcv_tsecr, tp->retrans_stamp));
2302} 2302}
2303 2303
2304/* Undo procedures. */ 2304/* Undo procedures. */
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 776615180b93..0e9bc120707d 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2255,13 +2255,13 @@ void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo)
2255} 2255}
2256 2256
2257static void get_openreq4(struct sock *sk, struct request_sock *req, 2257static void get_openreq4(struct sock *sk, struct request_sock *req,
2258 char *tmpbuf, int i, int uid) 2258 struct seq_file *f, int i, int uid, int *len)
2259{ 2259{
2260 const struct inet_request_sock *ireq = inet_rsk(req); 2260 const struct inet_request_sock *ireq = inet_rsk(req);
2261 int ttd = req->expires - jiffies; 2261 int ttd = req->expires - jiffies;
2262 2262
2263 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 2263 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
2264 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p", 2264 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
2265 i, 2265 i,
2266 ireq->loc_addr, 2266 ireq->loc_addr,
2267 ntohs(inet_sk(sk)->sport), 2267 ntohs(inet_sk(sk)->sport),
@@ -2276,10 +2276,11 @@ static void get_openreq4(struct sock *sk, struct request_sock *req,
2276 0, /* non standard timer */ 2276 0, /* non standard timer */
2277 0, /* open_requests have no inode */ 2277 0, /* open_requests have no inode */
2278 atomic_read(&sk->sk_refcnt), 2278 atomic_read(&sk->sk_refcnt),
2279 req); 2279 req,
2280 len);
2280} 2281}
2281 2282
2282static void get_tcp4_sock(struct sock *sk, char *tmpbuf, int i) 2283static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
2283{ 2284{
2284 int timer_active; 2285 int timer_active;
2285 unsigned long timer_expires; 2286 unsigned long timer_expires;
@@ -2305,8 +2306,8 @@ static void get_tcp4_sock(struct sock *sk, char *tmpbuf, int i)
2305 timer_expires = jiffies; 2306 timer_expires = jiffies;
2306 } 2307 }
2307 2308
2308 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX " 2309 seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
2309 "%08X %5d %8d %lu %d %p %u %u %u %u %d", 2310 "%08X %5d %8d %lu %d %p %u %u %u %u %d%n",
2310 i, src, srcp, dest, destp, sk->sk_state, 2311 i, src, srcp, dest, destp, sk->sk_state,
2311 tp->write_seq - tp->snd_una, 2312 tp->write_seq - tp->snd_una,
2312 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog : 2313 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
@@ -2322,11 +2323,12 @@ static void get_tcp4_sock(struct sock *sk, char *tmpbuf, int i)
2322 icsk->icsk_ack.ato, 2323 icsk->icsk_ack.ato,
2323 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, 2324 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
2324 tp->snd_cwnd, 2325 tp->snd_cwnd,
2325 tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh); 2326 tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh,
2327 len);
2326} 2328}
2327 2329
2328static void get_timewait4_sock(struct inet_timewait_sock *tw, 2330static void get_timewait4_sock(struct inet_timewait_sock *tw,
2329 char *tmpbuf, int i) 2331 struct seq_file *f, int i, int *len)
2330{ 2332{
2331 __be32 dest, src; 2333 __be32 dest, src;
2332 __u16 destp, srcp; 2334 __u16 destp, srcp;
@@ -2340,11 +2342,11 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
2340 destp = ntohs(tw->tw_dport); 2342 destp = ntohs(tw->tw_dport);
2341 srcp = ntohs(tw->tw_sport); 2343 srcp = ntohs(tw->tw_sport);
2342 2344
2343 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 2345 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
2344 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p", 2346 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
2345 i, src, srcp, dest, destp, tw->tw_substate, 0, 0, 2347 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
2346 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0, 2348 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
2347 atomic_read(&tw->tw_refcnt), tw); 2349 atomic_read(&tw->tw_refcnt), tw, len);
2348} 2350}
2349 2351
2350#define TMPSZ 150 2352#define TMPSZ 150
@@ -2352,7 +2354,7 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
2352static int tcp4_seq_show(struct seq_file *seq, void *v) 2354static int tcp4_seq_show(struct seq_file *seq, void *v)
2353{ 2355{
2354 struct tcp_iter_state* st; 2356 struct tcp_iter_state* st;
2355 char tmpbuf[TMPSZ + 1]; 2357 int len;
2356 2358
2357 if (v == SEQ_START_TOKEN) { 2359 if (v == SEQ_START_TOKEN) {
2358 seq_printf(seq, "%-*s\n", TMPSZ - 1, 2360 seq_printf(seq, "%-*s\n", TMPSZ - 1,
@@ -2366,16 +2368,16 @@ static int tcp4_seq_show(struct seq_file *seq, void *v)
2366 switch (st->state) { 2368 switch (st->state) {
2367 case TCP_SEQ_STATE_LISTENING: 2369 case TCP_SEQ_STATE_LISTENING:
2368 case TCP_SEQ_STATE_ESTABLISHED: 2370 case TCP_SEQ_STATE_ESTABLISHED:
2369 get_tcp4_sock(v, tmpbuf, st->num); 2371 get_tcp4_sock(v, seq, st->num, &len);
2370 break; 2372 break;
2371 case TCP_SEQ_STATE_OPENREQ: 2373 case TCP_SEQ_STATE_OPENREQ:
2372 get_openreq4(st->syn_wait_sk, v, tmpbuf, st->num, st->uid); 2374 get_openreq4(st->syn_wait_sk, v, seq, st->num, st->uid, &len);
2373 break; 2375 break;
2374 case TCP_SEQ_STATE_TIME_WAIT: 2376 case TCP_SEQ_STATE_TIME_WAIT:
2375 get_timewait4_sock(v, tmpbuf, st->num); 2377 get_timewait4_sock(v, seq, st->num, &len);
2376 break; 2378 break;
2377 } 2379 }
2378 seq_printf(seq, "%-*s\n", TMPSZ - 1, tmpbuf); 2380 seq_printf(seq, "%*s\n", TMPSZ - 1 - len, "");
2379out: 2381out:
2380 return 0; 2382 return 0;
2381} 2383}
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index b053ac795275..1f535e315188 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1619,7 +1619,8 @@ void udp_proc_unregister(struct net *net, struct udp_seq_afinfo *afinfo)
1619} 1619}
1620 1620
1621/* ------------------------------------------------------------------------ */ 1621/* ------------------------------------------------------------------------ */
1622static void udp4_format_sock(struct sock *sp, char *tmpbuf, int bucket) 1622static void udp4_format_sock(struct sock *sp, struct seq_file *f,
1623 int bucket, int *len)
1623{ 1624{
1624 struct inet_sock *inet = inet_sk(sp); 1625 struct inet_sock *inet = inet_sk(sp);
1625 __be32 dest = inet->daddr; 1626 __be32 dest = inet->daddr;
@@ -1627,13 +1628,13 @@ static void udp4_format_sock(struct sock *sp, char *tmpbuf, int bucket)
1627 __u16 destp = ntohs(inet->dport); 1628 __u16 destp = ntohs(inet->dport);
1628 __u16 srcp = ntohs(inet->sport); 1629 __u16 srcp = ntohs(inet->sport);
1629 1630
1630 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 1631 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
1631 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p", 1632 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p%n",
1632 bucket, src, srcp, dest, destp, sp->sk_state, 1633 bucket, src, srcp, dest, destp, sp->sk_state,
1633 atomic_read(&sp->sk_wmem_alloc), 1634 atomic_read(&sp->sk_wmem_alloc),
1634 atomic_read(&sp->sk_rmem_alloc), 1635 atomic_read(&sp->sk_rmem_alloc),
1635 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp), 1636 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
1636 atomic_read(&sp->sk_refcnt), sp); 1637 atomic_read(&sp->sk_refcnt), sp, len);
1637} 1638}
1638 1639
1639int udp4_seq_show(struct seq_file *seq, void *v) 1640int udp4_seq_show(struct seq_file *seq, void *v)
@@ -1644,11 +1645,11 @@ int udp4_seq_show(struct seq_file *seq, void *v)
1644 "rx_queue tr tm->when retrnsmt uid timeout " 1645 "rx_queue tr tm->when retrnsmt uid timeout "
1645 "inode"); 1646 "inode");
1646 else { 1647 else {
1647 char tmpbuf[129];
1648 struct udp_iter_state *state = seq->private; 1648 struct udp_iter_state *state = seq->private;
1649 int len;
1649 1650
1650 udp4_format_sock(v, tmpbuf, state->bucket); 1651 udp4_format_sock(v, seq, state->bucket, &len);
1651 seq_printf(seq, "%-127s\n", tmpbuf); 1652 seq_printf(seq, "%*s\n", 127 - len ,"");
1652 } 1653 }
1653 return 0; 1654 return 0;
1654} 1655}
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 8a0fd4007bdb..e591e09e5e4e 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -4338,12 +4338,6 @@ int unregister_inet6addr_notifier(struct notifier_block *nb)
4338 4338
4339EXPORT_SYMBOL(unregister_inet6addr_notifier); 4339EXPORT_SYMBOL(unregister_inet6addr_notifier);
4340 4340
4341
4342static int addrconf_net_init(struct net *net)
4343{
4344 return 0;
4345}
4346
4347static void addrconf_net_exit(struct net *net) 4341static void addrconf_net_exit(struct net *net)
4348{ 4342{
4349 struct net_device *dev; 4343 struct net_device *dev;
@@ -4360,7 +4354,6 @@ static void addrconf_net_exit(struct net *net)
4360} 4354}
4361 4355
4362static struct pernet_operations addrconf_net_ops = { 4356static struct pernet_operations addrconf_net_ops = {
4363 .init = addrconf_net_init,
4364 .exit = addrconf_net_exit, 4357 .exit = addrconf_net_exit,
4365}; 4358};
4366 4359
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 50f3f8f8a59b..1ee4fa17c129 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -1543,7 +1543,7 @@ out_timer:
1543static void fib6_net_exit(struct net *net) 1543static void fib6_net_exit(struct net *net)
1544{ 1544{
1545 rt6_ifdown(net, NULL); 1545 rt6_ifdown(net, NULL);
1546 del_timer(net->ipv6.ip6_fib_timer); 1546 del_timer_sync(net->ipv6.ip6_fib_timer);
1547 kfree(net->ipv6.ip6_fib_timer); 1547 kfree(net->ipv6.ip6_fib_timer);
1548#ifdef CONFIG_IPV6_MULTIPLE_TABLES 1548#ifdef CONFIG_IPV6_MULTIPLE_TABLES
1549 kfree(net->ipv6.fib6_local_tbl); 1549 kfree(net->ipv6.fib6_local_tbl);
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 210a079cfc6f..a493ad9b8914 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -150,7 +150,7 @@ static struct rt6_info ip6_null_entry_template = {
150static int ip6_pkt_prohibit(struct sk_buff *skb); 150static int ip6_pkt_prohibit(struct sk_buff *skb);
151static int ip6_pkt_prohibit_out(struct sk_buff *skb); 151static int ip6_pkt_prohibit_out(struct sk_buff *skb);
152 152
153struct rt6_info ip6_prohibit_entry_template = { 153static struct rt6_info ip6_prohibit_entry_template = {
154 .u = { 154 .u = {
155 .dst = { 155 .dst = {
156 .__refcnt = ATOMIC_INIT(1), 156 .__refcnt = ATOMIC_INIT(1),
@@ -2614,9 +2614,8 @@ struct ctl_table *ipv6_route_sysctl_init(struct net *net)
2614 2614
2615static int ip6_route_net_init(struct net *net) 2615static int ip6_route_net_init(struct net *net)
2616{ 2616{
2617 int ret = 0; 2617 int ret = -ENOMEM;
2618 2618
2619 ret = -ENOMEM;
2620 net->ipv6.ip6_dst_ops = kmemdup(&ip6_dst_ops_template, 2619 net->ipv6.ip6_dst_ops = kmemdup(&ip6_dst_ops_template,
2621 sizeof(*net->ipv6.ip6_dst_ops), 2620 sizeof(*net->ipv6.ip6_dst_ops),
2622 GFP_KERNEL); 2621 GFP_KERNEL);
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 1fb0fe42a72e..81a8e5297ad1 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -1907,7 +1907,7 @@ parse_ipsecrequest(struct xfrm_policy *xp, struct sadb_x_ipsecrequest *rq)
1907 t->encap_family = xp->family; 1907 t->encap_family = xp->family;
1908 1908
1909 /* No way to set this via kame pfkey */ 1909 /* No way to set this via kame pfkey */
1910 t->aalgos = t->ealgos = t->calgos = ~0; 1910 t->allalgs = 1;
1911 xp->xfrm_nr++; 1911 xp->xfrm_nr++;
1912 return 0; 1912 return 0;
1913} 1913}
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 6b75cb6c6300..a5e5c31c23ab 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -2248,10 +2248,13 @@ static void ieee80211_rx_bss_put(struct net_device *dev,
2248 struct ieee80211_sta_bss *bss) 2248 struct ieee80211_sta_bss *bss)
2249{ 2249{
2250 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2250 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2251 if (!atomic_dec_and_test(&bss->users)) 2251
2252 local_bh_disable();
2253 if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) {
2254 local_bh_enable();
2252 return; 2255 return;
2256 }
2253 2257
2254 spin_lock_bh(&local->sta_bss_lock);
2255 __ieee80211_rx_bss_hash_del(dev, bss); 2258 __ieee80211_rx_bss_hash_del(dev, bss);
2256 list_del(&bss->list); 2259 list_del(&bss->list);
2257 spin_unlock_bh(&local->sta_bss_lock); 2260 spin_unlock_bh(&local->sta_bss_lock);
@@ -2709,7 +2712,26 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
2709 bss->wmm_ie_len = elems.wmm_param_len + 2; 2712 bss->wmm_ie_len = elems.wmm_param_len + 2;
2710 } else 2713 } else
2711 bss->wmm_ie_len = 0; 2714 bss->wmm_ie_len = 0;
2712 } else if (!elems.wmm_param && bss->wmm_ie) { 2715 } else if (elems.wmm_info &&
2716 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_info_len ||
2717 memcmp(bss->wmm_ie, elems.wmm_info, elems.wmm_info_len))) {
2718 /* As for certain AP's Fifth bit is not set in WMM IE in
2719 * beacon frames.So while parsing the beacon frame the
2720 * wmm_info structure is used instead of wmm_param.
2721 * wmm_info structure was never used to set bss->wmm_ie.
2722 * This code fixes this problem by copying the WME
2723 * information from wmm_info to bss->wmm_ie and enabling
2724 * n-band association.
2725 */
2726 kfree(bss->wmm_ie);
2727 bss->wmm_ie = kmalloc(elems.wmm_info_len + 2, GFP_ATOMIC);
2728 if (bss->wmm_ie) {
2729 memcpy(bss->wmm_ie, elems.wmm_info - 2,
2730 elems.wmm_info_len + 2);
2731 bss->wmm_ie_len = elems.wmm_info_len + 2;
2732 } else
2733 bss->wmm_ie_len = 0;
2734 } else if (!elems.wmm_param && !elems.wmm_info && bss->wmm_ie) {
2713 kfree(bss->wmm_ie); 2735 kfree(bss->wmm_ie);
2714 bss->wmm_ie = NULL; 2736 bss->wmm_ie = NULL;
2715 bss->wmm_ie_len = 0; 2737 bss->wmm_ie_len = 0;
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 52e4554fdde7..02f436a86061 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -2170,7 +2170,7 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2170 struct ieee80211_supported_band *sband; 2170 struct ieee80211_supported_band *sband;
2171 2171
2172 if (status->band < 0 || 2172 if (status->band < 0 ||
2173 status->band > IEEE80211_NUM_BANDS) { 2173 status->band >= IEEE80211_NUM_BANDS) {
2174 WARN_ON(1); 2174 WARN_ON(1);
2175 return; 2175 return;
2176 } 2176 }
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 4e94e4026e78..64faa3dc488f 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -709,7 +709,7 @@ void ieee80211_requeue(struct ieee80211_local *local, int queue)
709 struct ieee80211_sched_data *q = qdisc_priv(root_qd); 709 struct ieee80211_sched_data *q = qdisc_priv(root_qd);
710 struct Qdisc *qdisc = q->queues[queue]; 710 struct Qdisc *qdisc = q->queues[queue];
711 struct sk_buff *skb = NULL; 711 struct sk_buff *skb = NULL;
712 u32 len = qdisc->q.qlen; 712 u32 len;
713 713
714 if (!qdisc || !qdisc->dequeue) 714 if (!qdisc || !qdisc->dequeue)
715 return; 715 return;
diff --git a/net/rose/rose_route.c b/net/rose/rose_route.c
index fb9359fb2358..5053a53ba24f 100644
--- a/net/rose/rose_route.c
+++ b/net/rose/rose_route.c
@@ -857,7 +857,6 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
857 src_addr = (rose_address *)(skb->data + 9); 857 src_addr = (rose_address *)(skb->data + 9);
858 dest_addr = (rose_address *)(skb->data + 4); 858 dest_addr = (rose_address *)(skb->data + 4);
859 859
860 spin_lock_bh(&rose_node_list_lock);
861 spin_lock_bh(&rose_neigh_list_lock); 860 spin_lock_bh(&rose_neigh_list_lock);
862 spin_lock_bh(&rose_route_list_lock); 861 spin_lock_bh(&rose_route_list_lock);
863 862
@@ -1060,7 +1059,6 @@ int rose_route_frame(struct sk_buff *skb, ax25_cb *ax25)
1060out: 1059out:
1061 spin_unlock_bh(&rose_route_list_lock); 1060 spin_unlock_bh(&rose_route_list_lock);
1062 spin_unlock_bh(&rose_neigh_list_lock); 1061 spin_unlock_bh(&rose_neigh_list_lock);
1063 spin_unlock_bh(&rose_node_list_lock);
1064 1062
1065 return res; 1063 return res;
1066} 1064}
diff --git a/net/sctp/objcnt.c b/net/sctp/objcnt.c
index cfeb07ea1b04..f73ec0ea93ba 100644
--- a/net/sctp/objcnt.c
+++ b/net/sctp/objcnt.c
@@ -83,13 +83,12 @@ static sctp_dbg_objcnt_entry_t sctp_dbg_objcnt[] = {
83 */ 83 */
84static int sctp_objcnt_seq_show(struct seq_file *seq, void *v) 84static int sctp_objcnt_seq_show(struct seq_file *seq, void *v)
85{ 85{
86 int i; 86 int i, len;
87 char temp[128];
88 87
89 i = (int)*(loff_t *)v; 88 i = (int)*(loff_t *)v;
90 sprintf(temp, "%s: %d", sctp_dbg_objcnt[i].label, 89 seq_printf(seq, "%s: %d%n", sctp_dbg_objcnt[i].label,
91 atomic_read(sctp_dbg_objcnt[i].counter)); 90 atomic_read(sctp_dbg_objcnt[i].counter), &len);
92 seq_printf(seq, "%-127s\n", temp); 91 seq_printf(seq, "%*s\n", 127 - len, "");
93 return 0; 92 return 0;
94} 93}
95 94
diff --git a/net/socket.c b/net/socket.c
index 9b5c917f8a6b..66c4a8cf6db9 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2327,9 +2327,6 @@ int kernel_sock_shutdown(struct socket *sock, enum sock_shutdown_cmd how)
2327 return sock->ops->shutdown(sock, how); 2327 return sock->ops->shutdown(sock, how);
2328} 2328}
2329 2329
2330/* ABI emulation layers need these two */
2331EXPORT_SYMBOL(move_addr_to_kernel);
2332EXPORT_SYMBOL(move_addr_to_user);
2333EXPORT_SYMBOL(sock_create); 2330EXPORT_SYMBOL(sock_create);
2334EXPORT_SYMBOL(sock_create_kern); 2331EXPORT_SYMBOL(sock_create_kern);
2335EXPORT_SYMBOL(sock_create_lite); 2332EXPORT_SYMBOL(sock_create_lite);
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 1454afcc06c4..e18cd3628db4 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2197,7 +2197,11 @@ static void __exit af_unix_exit(void)
2197 unregister_pernet_subsys(&unix_net_ops); 2197 unregister_pernet_subsys(&unix_net_ops);
2198} 2198}
2199 2199
2200module_init(af_unix_init); 2200/* Earlier than device_initcall() so that other drivers invoking
2201 request_module() don't end up in a loop when modprobe tries
2202 to use a UNIX socket. But later than subsys_initcall() because
2203 we depend on stuff initialised there */
2204fs_initcall(af_unix_init);
2201module_exit(af_unix_exit); 2205module_exit(af_unix_exit);
2202 2206
2203MODULE_LICENSE("GPL"); 2207MODULE_LICENSE("GPL");
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index ab4d0e598a2c..e0c0390613c0 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1819,7 +1819,7 @@ xfrm_state_ok(struct xfrm_tmpl *tmpl, struct xfrm_state *x,
1819 (x->id.spi == tmpl->id.spi || !tmpl->id.spi) && 1819 (x->id.spi == tmpl->id.spi || !tmpl->id.spi) &&
1820 (x->props.reqid == tmpl->reqid || !tmpl->reqid) && 1820 (x->props.reqid == tmpl->reqid || !tmpl->reqid) &&
1821 x->props.mode == tmpl->mode && 1821 x->props.mode == tmpl->mode &&
1822 ((tmpl->aalgos & (1<<x->props.aalgo)) || 1822 (tmpl->allalgs || (tmpl->aalgos & (1<<x->props.aalgo)) ||
1823 !(xfrm_id_proto_match(tmpl->id.proto, IPSEC_PROTO_ANY))) && 1823 !(xfrm_id_proto_match(tmpl->id.proto, IPSEC_PROTO_ANY))) &&
1824 !(x->props.mode != XFRM_MODE_TRANSPORT && 1824 !(x->props.mode != XFRM_MODE_TRANSPORT &&
1825 xfrm_state_addr_cmp(tmpl, x, family)); 1825 xfrm_state_addr_cmp(tmpl, x, family));
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 1810f5645bb5..22a30ae582a2 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -981,6 +981,8 @@ static void copy_templates(struct xfrm_policy *xp, struct xfrm_user_tmpl *ut,
981 t->aalgos = ut->aalgos; 981 t->aalgos = ut->aalgos;
982 t->ealgos = ut->ealgos; 982 t->ealgos = ut->ealgos;
983 t->calgos = ut->calgos; 983 t->calgos = ut->calgos;
984 /* If all masks are ~0, then we allow all algorithms. */
985 t->allalgs = !~(t->aalgos & t->ealgos & t->calgos);
984 t->encap_family = ut->family; 986 t->encap_family = ut->family;
985 } 987 }
986} 988}
diff --git a/security/dummy.c b/security/dummy.c
index 98d5f969cdc8..b0232bbf427b 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -196,13 +196,13 @@ static int dummy_sb_statfs (struct dentry *dentry)
196 return 0; 196 return 0;
197} 197}
198 198
199static int dummy_sb_mount (char *dev_name, struct nameidata *nd, char *type, 199static int dummy_sb_mount (char *dev_name, struct path *path, char *type,
200 unsigned long flags, void *data) 200 unsigned long flags, void *data)
201{ 201{
202 return 0; 202 return 0;
203} 203}
204 204
205static int dummy_sb_check_sb (struct vfsmount *mnt, struct nameidata *nd) 205static int dummy_sb_check_sb (struct vfsmount *mnt, struct path *path)
206{ 206{
207 return 0; 207 return 0;
208} 208}
@@ -229,17 +229,17 @@ static void dummy_sb_post_remount (struct vfsmount *mnt, unsigned long flags,
229} 229}
230 230
231 231
232static void dummy_sb_post_addmount (struct vfsmount *mnt, struct nameidata *nd) 232static void dummy_sb_post_addmount (struct vfsmount *mnt, struct path *path)
233{ 233{
234 return; 234 return;
235} 235}
236 236
237static int dummy_sb_pivotroot (struct nameidata *old_nd, struct nameidata *new_nd) 237static int dummy_sb_pivotroot (struct path *old_path, struct path *new_path)
238{ 238{
239 return 0; 239 return 0;
240} 240}
241 241
242static void dummy_sb_post_pivotroot (struct nameidata *old_nd, struct nameidata *new_nd) 242static void dummy_sb_post_pivotroot (struct path *old_path, struct path *new_path)
243{ 243{
244 return; 244 return;
245} 245}
diff --git a/security/security.c b/security/security.c
index 2e250c7028eb..8a285c7b9962 100644
--- a/security/security.c
+++ b/security/security.c
@@ -296,15 +296,15 @@ int security_sb_statfs(struct dentry *dentry)
296 return security_ops->sb_statfs(dentry); 296 return security_ops->sb_statfs(dentry);
297} 297}
298 298
299int security_sb_mount(char *dev_name, struct nameidata *nd, 299int security_sb_mount(char *dev_name, struct path *path,
300 char *type, unsigned long flags, void *data) 300 char *type, unsigned long flags, void *data)
301{ 301{
302 return security_ops->sb_mount(dev_name, nd, type, flags, data); 302 return security_ops->sb_mount(dev_name, path, type, flags, data);
303} 303}
304 304
305int security_sb_check_sb(struct vfsmount *mnt, struct nameidata *nd) 305int security_sb_check_sb(struct vfsmount *mnt, struct path *path)
306{ 306{
307 return security_ops->sb_check_sb(mnt, nd); 307 return security_ops->sb_check_sb(mnt, path);
308} 308}
309 309
310int security_sb_umount(struct vfsmount *mnt, int flags) 310int security_sb_umount(struct vfsmount *mnt, int flags)
@@ -327,19 +327,19 @@ void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *d
327 security_ops->sb_post_remount(mnt, flags, data); 327 security_ops->sb_post_remount(mnt, flags, data);
328} 328}
329 329
330void security_sb_post_addmount(struct vfsmount *mnt, struct nameidata *mountpoint_nd) 330void security_sb_post_addmount(struct vfsmount *mnt, struct path *mountpoint)
331{ 331{
332 security_ops->sb_post_addmount(mnt, mountpoint_nd); 332 security_ops->sb_post_addmount(mnt, mountpoint);
333} 333}
334 334
335int security_sb_pivotroot(struct nameidata *old_nd, struct nameidata *new_nd) 335int security_sb_pivotroot(struct path *old_path, struct path *new_path)
336{ 336{
337 return security_ops->sb_pivotroot(old_nd, new_nd); 337 return security_ops->sb_pivotroot(old_path, new_path);
338} 338}
339 339
340void security_sb_post_pivotroot(struct nameidata *old_nd, struct nameidata *new_nd) 340void security_sb_post_pivotroot(struct path *old_path, struct path *new_path)
341{ 341{
342 security_ops->sb_post_pivotroot(old_nd, new_nd); 342 security_ops->sb_post_pivotroot(old_path, new_path);
343} 343}
344 344
345int security_sb_get_mnt_opts(const struct super_block *sb, 345int security_sb_get_mnt_opts(const struct super_block *sb,
diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 1d69f6649bff..95a8ef4a5073 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -312,6 +312,7 @@ static inline int avc_reclaim_node(void)
312 if (!spin_trylock_irqsave(&avc_cache.slots_lock[hvalue], flags)) 312 if (!spin_trylock_irqsave(&avc_cache.slots_lock[hvalue], flags))
313 continue; 313 continue;
314 314
315 rcu_read_lock();
315 list_for_each_entry(node, &avc_cache.slots[hvalue], list) { 316 list_for_each_entry(node, &avc_cache.slots[hvalue], list) {
316 if (atomic_dec_and_test(&node->ae.used)) { 317 if (atomic_dec_and_test(&node->ae.used)) {
317 /* Recently Unused */ 318 /* Recently Unused */
@@ -319,11 +320,13 @@ static inline int avc_reclaim_node(void)
319 avc_cache_stats_incr(reclaims); 320 avc_cache_stats_incr(reclaims);
320 ecx++; 321 ecx++;
321 if (ecx >= AVC_CACHE_RECLAIM) { 322 if (ecx >= AVC_CACHE_RECLAIM) {
323 rcu_read_unlock();
322 spin_unlock_irqrestore(&avc_cache.slots_lock[hvalue], flags); 324 spin_unlock_irqrestore(&avc_cache.slots_lock[hvalue], flags);
323 goto out; 325 goto out;
324 } 326 }
325 } 327 }
326 } 328 }
329 rcu_read_unlock();
327 spin_unlock_irqrestore(&avc_cache.slots_lock[hvalue], flags); 330 spin_unlock_irqrestore(&avc_cache.slots_lock[hvalue], flags);
328 } 331 }
329out: 332out:
@@ -821,8 +824,14 @@ int avc_ss_reset(u32 seqno)
821 824
822 for (i = 0; i < AVC_CACHE_SLOTS; i++) { 825 for (i = 0; i < AVC_CACHE_SLOTS; i++) {
823 spin_lock_irqsave(&avc_cache.slots_lock[i], flag); 826 spin_lock_irqsave(&avc_cache.slots_lock[i], flag);
827 /*
828 * With preemptable RCU, the outer spinlock does not
829 * prevent RCU grace periods from ending.
830 */
831 rcu_read_lock();
824 list_for_each_entry(node, &avc_cache.slots[i], list) 832 list_for_each_entry(node, &avc_cache.slots[i], list)
825 avc_node_delete(node); 833 avc_node_delete(node);
834 rcu_read_unlock();
826 spin_unlock_irqrestore(&avc_cache.slots_lock[i], flag); 835 spin_unlock_irqrestore(&avc_cache.slots_lock[i], flag);
827 } 836 }
828 837
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 1bf2543ea942..308e2cf17d75 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -755,9 +755,18 @@ static void selinux_sb_clone_mnt_opts(const struct super_block *oldsb,
755 int set_context = (oldsbsec->flags & CONTEXT_MNT); 755 int set_context = (oldsbsec->flags & CONTEXT_MNT);
756 int set_rootcontext = (oldsbsec->flags & ROOTCONTEXT_MNT); 756 int set_rootcontext = (oldsbsec->flags & ROOTCONTEXT_MNT);
757 757
758 /* we can't error, we can't save the info, this shouldn't get called 758 /*
759 * this early in the boot process. */ 759 * if the parent was able to be mounted it clearly had no special lsm
760 BUG_ON(!ss_initialized); 760 * mount options. thus we can safely put this sb on the list and deal
761 * with it later
762 */
763 if (!ss_initialized) {
764 spin_lock(&sb_security_lock);
765 if (list_empty(&newsbsec->list))
766 list_add(&newsbsec->list, &superblock_security_head);
767 spin_unlock(&sb_security_lock);
768 return;
769 }
761 770
762 /* how can we clone if the old one wasn't set up?? */ 771 /* how can we clone if the old one wasn't set up?? */
763 BUG_ON(!oldsbsec->initialized); 772 BUG_ON(!oldsbsec->initialized);
@@ -2392,22 +2401,22 @@ static int selinux_sb_statfs(struct dentry *dentry)
2392} 2401}
2393 2402
2394static int selinux_mount(char *dev_name, 2403static int selinux_mount(char *dev_name,
2395 struct nameidata *nd, 2404 struct path *path,
2396 char *type, 2405 char *type,
2397 unsigned long flags, 2406 unsigned long flags,
2398 void *data) 2407 void *data)
2399{ 2408{
2400 int rc; 2409 int rc;
2401 2410
2402 rc = secondary_ops->sb_mount(dev_name, nd, type, flags, data); 2411 rc = secondary_ops->sb_mount(dev_name, path, type, flags, data);
2403 if (rc) 2412 if (rc)
2404 return rc; 2413 return rc;
2405 2414
2406 if (flags & MS_REMOUNT) 2415 if (flags & MS_REMOUNT)
2407 return superblock_has_perm(current, nd->path.mnt->mnt_sb, 2416 return superblock_has_perm(current, path->mnt->mnt_sb,
2408 FILESYSTEM__REMOUNT, NULL); 2417 FILESYSTEM__REMOUNT, NULL);
2409 else 2418 else
2410 return dentry_has_perm(current, nd->path.mnt, nd->path.dentry, 2419 return dentry_has_perm(current, path->mnt, path->dentry,
2411 FILE__MOUNTON); 2420 FILE__MOUNTON);
2412} 2421}
2413 2422
diff --git a/security/selinux/netif.c b/security/selinux/netif.c
index c658b84c3196..b4e14bc0bf32 100644
--- a/security/selinux/netif.c
+++ b/security/selinux/netif.c
@@ -239,11 +239,13 @@ static void sel_netif_kill(int ifindex)
239{ 239{
240 struct sel_netif *netif; 240 struct sel_netif *netif;
241 241
242 rcu_read_lock();
242 spin_lock_bh(&sel_netif_lock); 243 spin_lock_bh(&sel_netif_lock);
243 netif = sel_netif_find(ifindex); 244 netif = sel_netif_find(ifindex);
244 if (netif) 245 if (netif)
245 sel_netif_destroy(netif); 246 sel_netif_destroy(netif);
246 spin_unlock_bh(&sel_netif_lock); 247 spin_unlock_bh(&sel_netif_lock);
248 rcu_read_unlock();
247} 249}
248 250
249/** 251/**
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 93f5b0ce662a..4215971434e6 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -315,10 +315,10 @@ static int smack_sb_statfs(struct dentry *dentry)
315 * Returns 0 if current can write the floor of the filesystem 315 * Returns 0 if current can write the floor of the filesystem
316 * being mounted on, an error code otherwise. 316 * being mounted on, an error code otherwise.
317 */ 317 */
318static int smack_sb_mount(char *dev_name, struct nameidata *nd, 318static int smack_sb_mount(char *dev_name, struct path *path,
319 char *type, unsigned long flags, void *data) 319 char *type, unsigned long flags, void *data)
320{ 320{
321 struct superblock_smack *sbp = nd->path.mnt->mnt_sb->s_security; 321 struct superblock_smack *sbp = path->mnt->mnt_sb->s_security;
322 322
323 return smk_curacc(sbp->smk_floor, MAY_WRITE); 323 return smk_curacc(sbp->smk_floor, MAY_WRITE);
324} 324}
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index 8704e2825b10..5b3274b465eb 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -72,7 +72,7 @@ static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg
72 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 && 72 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 &&
73 !((GSR | gsr_bits) & GSR_SDONE)) { 73 !((GSR | gsr_bits) & GSR_SDONE)) {
74 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n", 74 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n",
75 __FUNCTION__, reg, GSR | gsr_bits); 75 __func__, reg, GSR | gsr_bits);
76 val = -1; 76 val = -1;
77 goto out; 77 goto out;
78 } 78 }
@@ -104,7 +104,7 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigne
104 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 && 104 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 &&
105 !((GSR | gsr_bits) & GSR_CDONE)) 105 !((GSR | gsr_bits) & GSR_CDONE))
106 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n", 106 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n",
107 __FUNCTION__, reg, GSR | gsr_bits); 107 __func__, reg, GSR | gsr_bits);
108 108
109 mutex_unlock(&car_mutex); 109 mutex_unlock(&car_mutex);
110} 110}
@@ -112,6 +112,16 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigne
112static void pxa2xx_ac97_reset(struct snd_ac97 *ac97) 112static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
113{ 113{
114 /* First, try cold reset */ 114 /* First, try cold reset */
115#ifdef CONFIG_PXA3xx
116 int timeout;
117
118 /* Hold CLKBPB for 100us */
119 GCR = 0;
120 GCR = GCR_CLKBPB;
121 udelay(100);
122 GCR = 0;
123#endif
124
115 GCR &= GCR_COLD_RST; /* clear everything but nCRST */ 125 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
116 GCR &= ~GCR_COLD_RST; /* then assert nCRST */ 126 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
117 127
@@ -123,6 +133,14 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
123 clk_disable(ac97conf_clk); 133 clk_disable(ac97conf_clk);
124 GCR = GCR_COLD_RST; 134 GCR = GCR_COLD_RST;
125 udelay(50); 135 udelay(50);
136#elif defined(CONFIG_PXA3xx)
137 timeout = 1000;
138 /* Can't use interrupts on PXA3xx */
139 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
140
141 GCR = GCR_WARM_RST | GCR_COLD_RST;
142 while (!(GSR & (GSR_PCR | GSR_SCR)) && timeout--)
143 mdelay(10);
126#else 144#else
127 GCR = GCR_COLD_RST; 145 GCR = GCR_COLD_RST;
128 GCR |= GCR_CDONE_IE|GCR_SDONE_IE; 146 GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
@@ -131,7 +149,7 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
131 149
132 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) { 150 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) {
133 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n", 151 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
134 __FUNCTION__, gsr_bits); 152 __func__, gsr_bits);
135 153
136 /* let's try warm reset */ 154 /* let's try warm reset */
137 gsr_bits = 0; 155 gsr_bits = 0;
@@ -143,6 +161,12 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
143 GCR |= GCR_WARM_RST; 161 GCR |= GCR_WARM_RST;
144 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 162 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
145 udelay(500); 163 udelay(500);
164#elif defined(CONFIG_PXA3xx)
165 timeout = 100;
166 /* Can't use interrupts */
167 GCR |= GCR_WARM_RST;
168 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
169 mdelay(1);
146#else 170#else
147 GCR |= GCR_WARM_RST|GCR_PRIRDY_IEN|GCR_SECRDY_IEN; 171 GCR |= GCR_WARM_RST|GCR_PRIRDY_IEN|GCR_SECRDY_IEN;
148 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1); 172 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
@@ -150,7 +174,7 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
150 174
151 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) 175 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
152 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n", 176 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
153 __FUNCTION__, gsr_bits); 177 __func__, gsr_bits);
154 } 178 }
155 179
156 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 180 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
@@ -424,6 +448,7 @@ static struct platform_driver pxa2xx_ac97_driver = {
424 .resume = pxa2xx_ac97_resume, 448 .resume = pxa2xx_ac97_resume,
425 .driver = { 449 .driver = {
426 .name = "pxa2xx-ac97", 450 .name = "pxa2xx-ac97",
451 .owner = THIS_MODULE,
427 }, 452 },
428}; 453};
429 454
@@ -443,3 +468,4 @@ module_exit(pxa2xx_ac97_exit);
443MODULE_AUTHOR("Nicolas Pitre"); 468MODULE_AUTHOR("Nicolas Pitre");
444MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip"); 469MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
445MODULE_LICENSE("GPL"); 470MODULE_LICENSE("GPL");
471MODULE_ALIAS("platform:pxa2xx-ac97");
diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index 829ca38b595e..a8d71c6c8e75 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -181,3 +181,7 @@ config SND_PCM_XRUN_DEBUG
181 It is usually not required, but if you have trouble with 181 It is usually not required, but if you have trouble with
182 sound clicking when system is loaded, it may help to determine 182 sound clicking when system is loaded, it may help to determine
183 the process or driver which causes the scheduling gaps. 183 the process or driver which causes the scheduling gaps.
184
185config SND_VMASTER
186 bool
187 depends on SND
diff --git a/sound/core/Makefile b/sound/core/Makefile
index 267039a97bd5..da8e685eef9c 100644
--- a/sound/core/Makefile
+++ b/sound/core/Makefile
@@ -6,6 +6,7 @@
6snd-y := sound.o init.o memory.o info.o control.o misc.o device.o 6snd-y := sound.o init.o memory.o info.o control.o misc.o device.o
7snd-$(CONFIG_ISA_DMA_API) += isadma.o 7snd-$(CONFIG_ISA_DMA_API) += isadma.o
8snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o 8snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o
9snd-$(CONFIG_SND_VMASTER) += vmaster.o
9 10
10snd-pcm-objs := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \ 11snd-pcm-objs := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \
11 pcm_memory.o 12 pcm_memory.o
diff --git a/sound/core/init.c b/sound/core/init.c
index e3338d6071ef..ac0573416130 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -254,7 +254,7 @@ static int snd_disconnect_release(struct inode *inode, struct file *file)
254 if (likely(df)) 254 if (likely(df))
255 return df->disconnected_f_op->release(inode, file); 255 return df->disconnected_f_op->release(inode, file);
256 256
257 panic("%s(%p, %p) failed!", __FUNCTION__, inode, file); 257 panic("%s(%p, %p) failed!", __func__, inode, file);
258} 258}
259 259
260static unsigned int snd_disconnect_poll(struct file * file, poll_table * wait) 260static unsigned int snd_disconnect_poll(struct file * file, poll_table * wait)
@@ -311,6 +311,9 @@ int snd_card_disconnect(struct snd_card *card)
311 struct file *file; 311 struct file *file;
312 int err; 312 int err;
313 313
314 if (!card)
315 return -EINVAL;
316
314 spin_lock(&card->files_lock); 317 spin_lock(&card->files_lock);
315 if (card->shutdown) { 318 if (card->shutdown) {
316 spin_unlock(&card->files_lock); 319 spin_unlock(&card->files_lock);
@@ -322,6 +325,7 @@ int snd_card_disconnect(struct snd_card *card)
322 /* phase 1: disable fops (user space) operations for ALSA API */ 325 /* phase 1: disable fops (user space) operations for ALSA API */
323 mutex_lock(&snd_card_mutex); 326 mutex_lock(&snd_card_mutex);
324 snd_cards[card->number] = NULL; 327 snd_cards[card->number] = NULL;
328 snd_cards_lock &= ~(1 << card->number);
325 mutex_unlock(&snd_card_mutex); 329 mutex_unlock(&snd_card_mutex);
326 330
327 /* phase 2: replace file->f_op with special dummy operations */ 331 /* phase 2: replace file->f_op with special dummy operations */
@@ -360,6 +364,15 @@ int snd_card_disconnect(struct snd_card *card)
360 snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number); 364 snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number);
361 365
362 snd_info_card_disconnect(card); 366 snd_info_card_disconnect(card);
367#ifndef CONFIG_SYSFS_DEPRECATED
368 if (card->card_dev) {
369 device_unregister(card->card_dev);
370 card->card_dev = NULL;
371 }
372#endif
373#ifdef CONFIG_PM
374 wake_up(&card->power_sleep);
375#endif
363 return 0; 376 return 0;
364} 377}
365 378
@@ -401,33 +414,14 @@ static int snd_card_do_free(struct snd_card *card)
401 snd_printk(KERN_WARNING "unable to free card info\n"); 414 snd_printk(KERN_WARNING "unable to free card info\n");
402 /* Not fatal error */ 415 /* Not fatal error */
403 } 416 }
404#ifndef CONFIG_SYSFS_DEPRECATED
405 if (card->card_dev)
406 device_unregister(card->card_dev);
407#endif
408 kfree(card); 417 kfree(card);
409 return 0; 418 return 0;
410} 419}
411 420
412static int snd_card_free_prepare(struct snd_card *card)
413{
414 if (card == NULL)
415 return -EINVAL;
416 (void) snd_card_disconnect(card);
417 mutex_lock(&snd_card_mutex);
418 snd_cards[card->number] = NULL;
419 snd_cards_lock &= ~(1 << card->number);
420 mutex_unlock(&snd_card_mutex);
421#ifdef CONFIG_PM
422 wake_up(&card->power_sleep);
423#endif
424 return 0;
425}
426
427int snd_card_free_when_closed(struct snd_card *card) 421int snd_card_free_when_closed(struct snd_card *card)
428{ 422{
429 int free_now = 0; 423 int free_now = 0;
430 int ret = snd_card_free_prepare(card); 424 int ret = snd_card_disconnect(card);
431 if (ret) 425 if (ret)
432 return ret; 426 return ret;
433 427
@@ -447,7 +441,7 @@ EXPORT_SYMBOL(snd_card_free_when_closed);
447 441
448int snd_card_free(struct snd_card *card) 442int snd_card_free(struct snd_card *card)
449{ 443{
450 int ret = snd_card_free_prepare(card); 444 int ret = snd_card_disconnect(card);
451 if (ret) 445 if (ret)
452 return ret; 446 return ret;
453 447
diff --git a/sound/core/misc.c b/sound/core/misc.c
index 102d1c36cf26..38524f615d94 100644
--- a/sound/core/misc.c
+++ b/sound/core/misc.c
@@ -39,7 +39,7 @@ void snd_verbose_printk(const char *file, int line, const char *format, ...)
39{ 39{
40 va_list args; 40 va_list args;
41 41
42 if (format[0] == '<' && format[1] >= '0' && format[1] <= '9' && format[2] == '>') { 42 if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') {
43 char tmp[] = "<0>"; 43 char tmp[] = "<0>";
44 tmp[1] = format[1]; 44 tmp[1] = format[1];
45 printk("%sALSA %s:%d: ", tmp, file, line); 45 printk("%sALSA %s:%d: ", tmp, file, line);
@@ -60,7 +60,7 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
60{ 60{
61 va_list args; 61 va_list args;
62 62
63 if (format[0] == '<' && format[1] >= '0' && format[1] <= '9' && format[2] == '>') { 63 if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') {
64 char tmp[] = "<0>"; 64 char tmp[] = "<0>";
65 tmp[1] = format[1]; 65 tmp[1] = format[1];
66 printk("%sALSA %s:%d: ", tmp, file, line); 66 printk("%sALSA %s:%d: ", tmp, file, line);
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index 75daed298a15..581aa2c60e65 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1257,6 +1257,8 @@ static void snd_mixer_oss_build(struct snd_mixer_oss *mixer)
1257 { SOUND_MIXER_DIGITAL3, "Digital", 2 }, 1257 { SOUND_MIXER_DIGITAL3, "Digital", 2 },
1258 { SOUND_MIXER_PHONEIN, "Phone", 0 }, 1258 { SOUND_MIXER_PHONEIN, "Phone", 0 },
1259 { SOUND_MIXER_PHONEOUT, "Master Mono", 0 }, 1259 { SOUND_MIXER_PHONEOUT, "Master Mono", 0 },
1260 { SOUND_MIXER_PHONEOUT, "Speaker", 0 }, /*fallback*/
1261 { SOUND_MIXER_PHONEOUT, "Mono", 0 }, /*fallback*/
1260 { SOUND_MIXER_PHONEOUT, "Phone", 0 }, /* fallback */ 1262 { SOUND_MIXER_PHONEOUT, "Phone", 0 }, /* fallback */
1261 { SOUND_MIXER_VIDEO, "Video", 0 }, 1263 { SOUND_MIXER_VIDEO, "Video", 0 },
1262 { SOUND_MIXER_RADIO, "Radio", 0 }, 1264 { SOUND_MIXER_RADIO, "Radio", 0 },
diff --git a/sound/core/seq/oss/seq_oss_synth.c b/sound/core/seq/oss/seq_oss_synth.c
index ab570a0a6183..558dadbf45f1 100644
--- a/sound/core/seq/oss/seq_oss_synth.c
+++ b/sound/core/seq/oss/seq_oss_synth.c
@@ -245,8 +245,13 @@ snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp)
245 info->nr_voices = rec->nr_voices; 245 info->nr_voices = rec->nr_voices;
246 if (info->nr_voices > 0) { 246 if (info->nr_voices > 0) {
247 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL); 247 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL);
248 if (!info->ch) 248 if (!info->ch) {
249 BUG(); 249 snd_printk(KERN_ERR "Cannot malloc\n");
250 rec->oper.close(&info->arg);
251 module_put(rec->oper.owner);
252 snd_use_lock_free(&rec->use_lock);
253 continue;
254 }
250 reset_channels(info); 255 reset_channels(info);
251 } 256 }
252 debug_printk(("synth %d assigned\n", i)); 257 debug_printk(("synth %d assigned\n", i));
diff --git a/sound/pci/hda/vmaster.c b/sound/core/vmaster.c
index 2da49d20a1fc..4cc57f902e2c 100644
--- a/sound/pci/hda/vmaster.c
+++ b/sound/core/vmaster.c
@@ -12,6 +12,7 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <sound/core.h> 13#include <sound/core.h>
14#include <sound/control.h> 14#include <sound/control.h>
15#include <sound/tlv.h>
15 16
16/* 17/*
17 * a subset of information returned via ctl info callback 18 * a subset of information returned via ctl info callback
@@ -34,6 +35,7 @@ struct link_master {
34 struct list_head slaves; 35 struct list_head slaves;
35 struct link_ctl_info info; 36 struct link_ctl_info info;
36 int val; /* the master value */ 37 int val; /* the master value */
38 unsigned int tlv[4];
37}; 39};
38 40
39/* 41/*
@@ -253,6 +255,8 @@ int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave)
253 return 0; 255 return 0;
254} 256}
255 257
258EXPORT_SYMBOL(snd_ctl_add_slave);
259
256/* 260/*
257 * ctl callbacks for master controls 261 * ctl callbacks for master controls
258 */ 262 */
@@ -355,10 +359,13 @@ struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
355 kctl->private_free = master_free; 359 kctl->private_free = master_free;
356 360
357 /* additional (constant) TLV read */ 361 /* additional (constant) TLV read */
358 if (tlv) { 362 if (tlv && tlv[0] == SNDRV_CTL_TLVT_DB_SCALE) {
359 /* FIXME: this assumes that the max volume is 0 dB */
360 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; 363 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
361 kctl->tlv.p = tlv; 364 memcpy(master->tlv, tlv, sizeof(master->tlv));
365 kctl->tlv.p = master->tlv;
362 } 366 }
367
363 return kctl; 368 return kctl;
364} 369}
370
371EXPORT_SYMBOL(snd_ctl_make_virtual_master);
diff --git a/sound/drivers/Kconfig b/sound/drivers/Kconfig
index 75d4fe09fdf3..fe85af1c5693 100644
--- a/sound/drivers/Kconfig
+++ b/sound/drivers/Kconfig
@@ -4,6 +4,24 @@ menu "Generic devices"
4 depends on SND!=n 4 depends on SND!=n
5 5
6 6
7config SND_PCSP
8 tristate "Internal PC speaker support"
9 depends on X86_PC && HIGH_RES_TIMERS
10 depends on INPUT
11 help
12 If you don't have a sound card in your computer, you can include a
13 driver for the PC speaker which allows it to act like a primitive
14 sound card.
15 This driver also replaces the pcspkr driver for beeps.
16
17 You can compile this as a module which will be called snd-pcsp.
18
19 You don't need this driver if you only want your pc-speaker to beep.
20 You don't need this driver if you have a tablet piezo beeper
21 in your PC instead of the real speaker.
22
23 It should not hurt to say Y or M here in all other cases.
24
7config SND_MPU401_UART 25config SND_MPU401_UART
8 tristate 26 tristate
9 select SND_RAWMIDI 27 select SND_RAWMIDI
diff --git a/sound/drivers/Makefile b/sound/drivers/Makefile
index 8e5530006e1f..d4a07f9ff2c7 100644
--- a/sound/drivers/Makefile
+++ b/sound/drivers/Makefile
@@ -20,4 +20,4 @@ obj-$(CONFIG_SND_MTS64) += snd-mts64.o
20obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o 20obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o
21obj-$(CONFIG_SND_ML403_AC97CR) += snd-ml403-ac97cr.o 21obj-$(CONFIG_SND_ML403_AC97CR) += snd-ml403-ac97cr.o
22 22
23obj-$(CONFIG_SND) += opl3/ opl4/ mpu401/ vx/ 23obj-$(CONFIG_SND) += opl3/ opl4/ mpu401/ vx/ pcsp/
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index a240eaeb5c62..4e4c69e6cb4c 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -181,10 +181,10 @@ struct snd_dummy_pcm {
181 struct snd_dummy *dummy; 181 struct snd_dummy *dummy;
182 spinlock_t lock; 182 spinlock_t lock;
183 struct timer_list timer; 183 struct timer_list timer;
184 unsigned int pcm_size; 184 unsigned int pcm_buffer_size;
185 unsigned int pcm_count; 185 unsigned int pcm_period_size;
186 unsigned int pcm_bps; /* bytes per second */ 186 unsigned int pcm_bps; /* bytes per second */
187 unsigned int pcm_jiffie; /* bytes per one jiffie */ 187 unsigned int pcm_hz; /* HZ */
188 unsigned int pcm_irq_pos; /* IRQ position */ 188 unsigned int pcm_irq_pos; /* IRQ position */
189 unsigned int pcm_buf_pos; /* position in buffer */ 189 unsigned int pcm_buf_pos; /* position in buffer */
190 struct snd_pcm_substream *substream; 190 struct snd_pcm_substream *substream;
@@ -230,19 +230,24 @@ static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
230{ 230{
231 struct snd_pcm_runtime *runtime = substream->runtime; 231 struct snd_pcm_runtime *runtime = substream->runtime;
232 struct snd_dummy_pcm *dpcm = runtime->private_data; 232 struct snd_dummy_pcm *dpcm = runtime->private_data;
233 unsigned int bps; 233 int bps;
234
235 bps = snd_pcm_format_width(runtime->format) * runtime->rate *
236 runtime->channels / 8;
234 237
235 bps = runtime->rate * runtime->channels;
236 bps *= snd_pcm_format_width(runtime->format);
237 bps /= 8;
238 if (bps <= 0) 238 if (bps <= 0)
239 return -EINVAL; 239 return -EINVAL;
240
240 dpcm->pcm_bps = bps; 241 dpcm->pcm_bps = bps;
241 dpcm->pcm_jiffie = bps / HZ; 242 dpcm->pcm_hz = HZ;
242 dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream); 243 dpcm->pcm_buffer_size = snd_pcm_lib_buffer_bytes(substream);
243 dpcm->pcm_count = snd_pcm_lib_period_bytes(substream); 244 dpcm->pcm_period_size = snd_pcm_lib_period_bytes(substream);
244 dpcm->pcm_irq_pos = 0; 245 dpcm->pcm_irq_pos = 0;
245 dpcm->pcm_buf_pos = 0; 246 dpcm->pcm_buf_pos = 0;
247
248 snd_pcm_format_set_silence(runtime->format, runtime->dma_area,
249 bytes_to_samples(runtime, runtime->dma_bytes));
250
246 return 0; 251 return 0;
247} 252}
248 253
@@ -254,11 +259,11 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data)
254 spin_lock_irqsave(&dpcm->lock, flags); 259 spin_lock_irqsave(&dpcm->lock, flags);
255 dpcm->timer.expires = 1 + jiffies; 260 dpcm->timer.expires = 1 + jiffies;
256 add_timer(&dpcm->timer); 261 add_timer(&dpcm->timer);
257 dpcm->pcm_irq_pos += dpcm->pcm_jiffie; 262 dpcm->pcm_irq_pos += dpcm->pcm_bps;
258 dpcm->pcm_buf_pos += dpcm->pcm_jiffie; 263 dpcm->pcm_buf_pos += dpcm->pcm_bps;
259 dpcm->pcm_buf_pos %= dpcm->pcm_size; 264 dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size * dpcm->pcm_hz;
260 if (dpcm->pcm_irq_pos >= dpcm->pcm_count) { 265 if (dpcm->pcm_irq_pos >= dpcm->pcm_period_size * dpcm->pcm_hz) {
261 dpcm->pcm_irq_pos %= dpcm->pcm_count; 266 dpcm->pcm_irq_pos %= dpcm->pcm_period_size * dpcm->pcm_hz;
262 spin_unlock_irqrestore(&dpcm->lock, flags); 267 spin_unlock_irqrestore(&dpcm->lock, flags);
263 snd_pcm_period_elapsed(dpcm->substream); 268 snd_pcm_period_elapsed(dpcm->substream);
264 } else 269 } else
@@ -270,7 +275,7 @@ static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *su
270 struct snd_pcm_runtime *runtime = substream->runtime; 275 struct snd_pcm_runtime *runtime = substream->runtime;
271 struct snd_dummy_pcm *dpcm = runtime->private_data; 276 struct snd_dummy_pcm *dpcm = runtime->private_data;
272 277
273 return bytes_to_frames(runtime, dpcm->pcm_buf_pos); 278 return bytes_to_frames(runtime, dpcm->pcm_buf_pos / dpcm->pcm_hz);
274} 279}
275 280
276static struct snd_pcm_hardware snd_card_dummy_playback = 281static struct snd_pcm_hardware snd_card_dummy_playback =
diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c
index 05a871aa7b81..ecdbeb6d3603 100644
--- a/sound/drivers/ml403-ac97cr.c
+++ b/sound/drivers/ml403-ac97cr.c
@@ -1191,8 +1191,6 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
1191 return err; 1191 return err;
1192 } 1192 }
1193 1193
1194 snd_card_set_dev(card, &pfdev->dev);
1195
1196 *rml403_ac97cr = ml403_ac97cr; 1194 *rml403_ac97cr = ml403_ac97cr;
1197 return 0; 1195 return 0;
1198} 1196}
@@ -1330,11 +1328,15 @@ static int snd_ml403_ac97cr_remove(struct platform_device *pfdev)
1330 return 0; 1328 return 0;
1331} 1329}
1332 1330
1331/* work with hotplug and coldplug */
1332MODULE_ALIAS("platform:" SND_ML403_AC97CR_DRIVER);
1333
1333static struct platform_driver snd_ml403_ac97cr_driver = { 1334static struct platform_driver snd_ml403_ac97cr_driver = {
1334 .probe = snd_ml403_ac97cr_probe, 1335 .probe = snd_ml403_ac97cr_probe,
1335 .remove = snd_ml403_ac97cr_remove, 1336 .remove = snd_ml403_ac97cr_remove,
1336 .driver = { 1337 .driver = {
1337 .name = SND_ML403_AC97CR_DRIVER, 1338 .name = SND_ML403_AC97CR_DRIVER,
1339 .owner = THIS_MODULE,
1338 }, 1340 },
1339}; 1341};
1340 1342
diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
index 5993864acbd3..18cca2457d44 100644
--- a/sound/drivers/mpu401/mpu401_uart.c
+++ b/sound/drivers/mpu401/mpu401_uart.c
@@ -49,12 +49,10 @@ static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu);
49 49
50 */ 50 */
51 51
52#define snd_mpu401_input_avail(mpu) (!(mpu->read(mpu, MPU401C(mpu)) & 0x80)) 52#define snd_mpu401_input_avail(mpu) \
53#define snd_mpu401_output_ready(mpu) (!(mpu->read(mpu, MPU401C(mpu)) & 0x40)) 53 (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_RX_EMPTY))
54 54#define snd_mpu401_output_ready(mpu) \
55#define MPU401_RESET 0xff 55 (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_TX_FULL))
56#define MPU401_ENTER_UART 0x3f
57#define MPU401_ACK 0xfe
58 56
59/* Build in lowlevel io */ 57/* Build in lowlevel io */
60static void mpu401_write_port(struct snd_mpu401 *mpu, unsigned char data, 58static void mpu401_write_port(struct snd_mpu401 *mpu, unsigned char data,
@@ -425,16 +423,17 @@ static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu)
425static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu) 423static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu)
426{ 424{
427 unsigned char byte; 425 unsigned char byte;
428 int max = 256, timeout; 426 int max = 256;
429 427
430 do { 428 do {
431 if (snd_rawmidi_transmit_peek(mpu->substream_output, 429 if (snd_rawmidi_transmit_peek(mpu->substream_output,
432 &byte, 1) == 1) { 430 &byte, 1) == 1) {
433 for (timeout = 100; timeout > 0; timeout--) { 431 /*
434 if (snd_mpu401_output_ready(mpu)) 432 * Try twice because there is hardware that insists on
435 break; 433 * setting the output busy bit after each write.
436 } 434 */
437 if (timeout == 0) 435 if (!snd_mpu401_output_ready(mpu) &&
436 !snd_mpu401_output_ready(mpu))
438 break; /* Tx FIFO full - try again later */ 437 break; /* Tx FIFO full - try again later */
439 mpu->write(mpu, byte, MPU401D(mpu)); 438 mpu->write(mpu, byte, MPU401D(mpu));
440 snd_rawmidi_transmit_ack(mpu->substream_output, 1); 439 snd_rawmidi_transmit_ack(mpu->substream_output, 1);
diff --git a/sound/drivers/pcsp/Makefile b/sound/drivers/pcsp/Makefile
new file mode 100644
index 000000000000..b19555b440da
--- /dev/null
+++ b/sound/drivers/pcsp/Makefile
@@ -0,0 +1,2 @@
1snd-pcsp-objs := pcsp.o pcsp_lib.o pcsp_mixer.o pcsp_input.o
2obj-$(CONFIG_SND_PCSP) += snd-pcsp.o
diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
new file mode 100644
index 000000000000..59203511e77d
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp.c
@@ -0,0 +1,235 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 1997-2001 David Woodhouse
5 * Copyright (C) 2001-2008 Stas Sergeev
6 */
7
8#include <linux/init.h>
9#include <linux/moduleparam.h>
10#include <linux/platform_device.h>
11#include <sound/core.h>
12#include <sound/initval.h>
13#include <sound/pcm.h>
14#include <linux/input.h>
15#include <linux/delay.h>
16#include <asm/bitops.h>
17#include "pcsp_input.h"
18#include "pcsp.h"
19
20MODULE_AUTHOR("Stas Sergeev <stsp@users.sourceforge.net>");
21MODULE_DESCRIPTION("PC-Speaker driver");
22MODULE_LICENSE("GPL");
23MODULE_SUPPORTED_DEVICE("{{PC-Speaker, pcsp}}");
24MODULE_ALIAS("platform:pcspkr");
25
26static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
27static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
28static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
29
30module_param(index, int, 0444);
31MODULE_PARM_DESC(index, "Index value for pcsp soundcard.");
32module_param(id, charp, 0444);
33MODULE_PARM_DESC(id, "ID string for pcsp soundcard.");
34module_param(enable, bool, 0444);
35MODULE_PARM_DESC(enable, "Enable PC-Speaker sound.");
36
37struct snd_pcsp pcsp_chip;
38
39static int __devinit snd_pcsp_create(struct snd_card *card)
40{
41 static struct snd_device_ops ops = { };
42 struct timespec tp;
43 int err;
44 int div, min_div, order;
45
46 hrtimer_get_res(CLOCK_MONOTONIC, &tp);
47 if (tp.tv_sec || tp.tv_nsec > PCSP_MAX_PERIOD_NS) {
48 printk(KERN_ERR "PCSP: Timer resolution is not sufficient "
49 "(%linS)\n", tp.tv_nsec);
50 printk(KERN_ERR "PCSP: Make sure you have HPET and ACPI "
51 "enabled.\n");
52 return -EIO;
53 }
54
55 if (loops_per_jiffy >= PCSP_MIN_LPJ && tp.tv_nsec <= PCSP_MIN_PERIOD_NS)
56 min_div = MIN_DIV;
57 else
58 min_div = MAX_DIV;
59#if PCSP_DEBUG
60 printk("PCSP: lpj=%li, min_div=%i, res=%li\n",
61 loops_per_jiffy, min_div, tp.tv_nsec);
62#endif
63
64 div = MAX_DIV / min_div;
65 order = fls(div) - 1;
66
67 pcsp_chip.max_treble = min(order, PCSP_MAX_TREBLE);
68 pcsp_chip.treble = min(pcsp_chip.max_treble, PCSP_DEFAULT_TREBLE);
69 pcsp_chip.playback_ptr = 0;
70 pcsp_chip.period_ptr = 0;
71 atomic_set(&pcsp_chip.timer_active, 0);
72 pcsp_chip.enable = 1;
73 pcsp_chip.pcspkr = 1;
74
75 spin_lock_init(&pcsp_chip.substream_lock);
76
77 pcsp_chip.card = card;
78 pcsp_chip.port = 0x61;
79 pcsp_chip.irq = -1;
80 pcsp_chip.dma = -1;
81
82 /* Register device */
83 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, &pcsp_chip, &ops);
84 if (err < 0)
85 return err;
86
87 return 0;
88}
89
90static int __devinit snd_card_pcsp_probe(int devnum, struct device *dev)
91{
92 struct snd_card *card;
93 int err;
94
95 if (devnum != 0)
96 return -EINVAL;
97
98 hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
99 pcsp_chip.timer.cb_mode = HRTIMER_CB_IRQSAFE;
100 pcsp_chip.timer.function = pcsp_do_timer;
101
102 card = snd_card_new(index, id, THIS_MODULE, 0);
103 if (!card)
104 return -ENOMEM;
105
106 err = snd_pcsp_create(card);
107 if (err < 0) {
108 snd_card_free(card);
109 return err;
110 }
111 err = snd_pcsp_new_pcm(&pcsp_chip);
112 if (err < 0) {
113 snd_card_free(card);
114 return err;
115 }
116 err = snd_pcsp_new_mixer(&pcsp_chip);
117 if (err < 0) {
118 snd_card_free(card);
119 return err;
120 }
121
122 snd_card_set_dev(pcsp_chip.card, dev);
123
124 strcpy(card->driver, "PC-Speaker");
125 strcpy(card->shortname, "pcsp");
126 sprintf(card->longname, "Internal PC-Speaker at port 0x%x",
127 pcsp_chip.port);
128
129 err = snd_card_register(card);
130 if (err < 0) {
131 snd_card_free(card);
132 return err;
133 }
134
135 return 0;
136}
137
138static int __devinit alsa_card_pcsp_init(struct device *dev)
139{
140 int err;
141
142 err = snd_card_pcsp_probe(0, dev);
143 if (err) {
144 printk(KERN_ERR "PC-Speaker initialization failed.\n");
145 return err;
146 }
147
148#ifdef CONFIG_DEBUG_PAGEALLOC
149 /* Well, CONFIG_DEBUG_PAGEALLOC makes the sound horrible. Lets alert */
150 printk(KERN_WARNING "PCSP: CONFIG_DEBUG_PAGEALLOC is enabled, "
151 "which may make the sound noisy.\n");
152#endif
153
154 return 0;
155}
156
157static void __devexit alsa_card_pcsp_exit(struct snd_pcsp *chip)
158{
159 snd_card_free(chip->card);
160}
161
162static int __devinit pcsp_probe(struct platform_device *dev)
163{
164 int err;
165
166 err = pcspkr_input_init(&pcsp_chip.input_dev, &dev->dev);
167 if (err < 0)
168 return err;
169
170 err = alsa_card_pcsp_init(&dev->dev);
171 if (err < 0) {
172 pcspkr_input_remove(pcsp_chip.input_dev);
173 return err;
174 }
175
176 platform_set_drvdata(dev, &pcsp_chip);
177 return 0;
178}
179
180static int __devexit pcsp_remove(struct platform_device *dev)
181{
182 struct snd_pcsp *chip = platform_get_drvdata(dev);
183 alsa_card_pcsp_exit(chip);
184 pcspkr_input_remove(chip->input_dev);
185 platform_set_drvdata(dev, NULL);
186 return 0;
187}
188
189static void pcsp_stop_beep(struct snd_pcsp *chip)
190{
191 spin_lock_irq(&chip->substream_lock);
192 if (!chip->playback_substream)
193 pcspkr_stop_sound();
194 spin_unlock_irq(&chip->substream_lock);
195}
196
197static int pcsp_suspend(struct platform_device *dev, pm_message_t state)
198{
199 struct snd_pcsp *chip = platform_get_drvdata(dev);
200 pcsp_stop_beep(chip);
201 snd_pcm_suspend_all(chip->pcm);
202 return 0;
203}
204
205static void pcsp_shutdown(struct platform_device *dev)
206{
207 struct snd_pcsp *chip = platform_get_drvdata(dev);
208 pcsp_stop_beep(chip);
209}
210
211static struct platform_driver pcsp_platform_driver = {
212 .driver = {
213 .name = "pcspkr",
214 .owner = THIS_MODULE,
215 },
216 .probe = pcsp_probe,
217 .remove = __devexit_p(pcsp_remove),
218 .suspend = pcsp_suspend,
219 .shutdown = pcsp_shutdown,
220};
221
222static int __init pcsp_init(void)
223{
224 if (!enable)
225 return -ENODEV;
226 return platform_driver_register(&pcsp_platform_driver);
227}
228
229static void __exit pcsp_exit(void)
230{
231 platform_driver_unregister(&pcsp_platform_driver);
232}
233
234module_init(pcsp_init);
235module_exit(pcsp_exit);
diff --git a/sound/drivers/pcsp/pcsp.h b/sound/drivers/pcsp/pcsp.h
new file mode 100644
index 000000000000..f07cc1ee1fe7
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp.h
@@ -0,0 +1,82 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 1993-1997 Michael Beck
5 * Copyright (C) 1997-2001 David Woodhouse
6 * Copyright (C) 2001-2008 Stas Sergeev
7 */
8
9#ifndef __PCSP_H__
10#define __PCSP_H__
11
12#include <linux/hrtimer.h>
13#if defined(CONFIG_MIPS) || defined(CONFIG_X86)
14/* Use the global PIT lock ! */
15#include <asm/i8253.h>
16#else
17#include <asm/8253pit.h>
18static DEFINE_SPINLOCK(i8253_lock);
19#endif
20
21#define PCSP_SOUND_VERSION 0x400 /* read 4.00 */
22#define PCSP_DEBUG 0
23
24/* default timer freq for PC-Speaker: 18643 Hz */
25#define DIV_18KHZ 64
26#define MAX_DIV DIV_18KHZ
27#define CUR_DIV() (MAX_DIV >> chip->treble)
28#define PCSP_MAX_TREBLE 1
29
30/* unfortunately, with hrtimers 37KHz does not work very well :( */
31#define PCSP_DEFAULT_TREBLE 0
32#define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE)
33
34/* wild guess */
35#define PCSP_MIN_LPJ 1000000
36#define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1)
37#define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV)
38#define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble))
39#define PCSP_RATE() (PIT_TICK_RATE / CUR_DIV())
40#define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE
41#define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE
42#define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1)
43#define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1)
44#define PCSP_CALC_NS(div) ({ \
45 u64 __val = 1000000000ULL * (div); \
46 do_div(__val, PIT_TICK_RATE); \
47 __val; \
48})
49#define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV())
50
51#define PCSP_MAX_PERIOD_SIZE (64*1024)
52#define PCSP_MAX_PERIODS 512
53#define PCSP_BUFFER_SIZE (128*1024)
54
55struct snd_pcsp {
56 struct snd_card *card;
57 struct snd_pcm *pcm;
58 struct input_dev *input_dev;
59 struct hrtimer timer;
60 unsigned short port, irq, dma;
61 spinlock_t substream_lock;
62 struct snd_pcm_substream *playback_substream;
63 size_t playback_ptr;
64 size_t period_ptr;
65 atomic_t timer_active;
66 int thalf;
67 u64 ns_rem;
68 unsigned char val61;
69 int enable;
70 int max_treble;
71 int treble;
72 int pcspkr;
73};
74
75extern struct snd_pcsp pcsp_chip;
76
77extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle);
78
79extern int snd_pcsp_new_pcm(struct snd_pcsp *chip);
80extern int snd_pcsp_new_mixer(struct snd_pcsp *chip);
81
82#endif
diff --git a/sound/drivers/pcsp/pcsp_input.c b/sound/drivers/pcsp/pcsp_input.c
new file mode 100644
index 000000000000..cd9b83e7f7d1
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_input.c
@@ -0,0 +1,116 @@
1/*
2 * PC Speaker beeper driver for Linux
3 *
4 * Copyright (c) 2002 Vojtech Pavlik
5 * Copyright (c) 1992 Orest Zborowski
6 *
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation
13 */
14
15#include <linux/init.h>
16#include <linux/input.h>
17#include <asm/io.h>
18#include "pcsp.h"
19
20static void pcspkr_do_sound(unsigned int count)
21{
22 unsigned long flags;
23
24 spin_lock_irqsave(&i8253_lock, flags);
25
26 if (count) {
27 /* enable counter 2 */
28 outb_p(inb_p(0x61) | 3, 0x61);
29 /* set command for counter 2, 2 byte write */
30 outb_p(0xB6, 0x43);
31 /* select desired HZ */
32 outb_p(count & 0xff, 0x42);
33 outb((count >> 8) & 0xff, 0x42);
34 } else {
35 /* disable counter 2 */
36 outb(inb_p(0x61) & 0xFC, 0x61);
37 }
38
39 spin_unlock_irqrestore(&i8253_lock, flags);
40}
41
42void pcspkr_stop_sound(void)
43{
44 pcspkr_do_sound(0);
45}
46
47static int pcspkr_input_event(struct input_dev *dev, unsigned int type,
48 unsigned int code, int value)
49{
50 unsigned int count = 0;
51
52 if (atomic_read(&pcsp_chip.timer_active) || !pcsp_chip.pcspkr)
53 return 0;
54
55 switch (type) {
56 case EV_SND:
57 switch (code) {
58 case SND_BELL:
59 if (value)
60 value = 1000;
61 case SND_TONE:
62 break;
63 default:
64 return -1;
65 }
66 break;
67
68 default:
69 return -1;
70 }
71
72 if (value > 20 && value < 32767)
73 count = PIT_TICK_RATE / value;
74
75 pcspkr_do_sound(count);
76
77 return 0;
78}
79
80int __devinit pcspkr_input_init(struct input_dev **rdev, struct device *dev)
81{
82 int err;
83
84 struct input_dev *input_dev = input_allocate_device();
85 if (!input_dev)
86 return -ENOMEM;
87
88 input_dev->name = "PC Speaker";
89 input_dev->phys = "isa0061/input0";
90 input_dev->id.bustype = BUS_ISA;
91 input_dev->id.vendor = 0x001f;
92 input_dev->id.product = 0x0001;
93 input_dev->id.version = 0x0100;
94 input_dev->dev.parent = dev;
95
96 input_dev->evbit[0] = BIT(EV_SND);
97 input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
98 input_dev->event = pcspkr_input_event;
99
100 err = input_register_device(input_dev);
101 if (err) {
102 input_free_device(input_dev);
103 return err;
104 }
105
106 *rdev = input_dev;
107 return 0;
108}
109
110int pcspkr_input_remove(struct input_dev *dev)
111{
112 pcspkr_stop_sound();
113 input_unregister_device(dev); /* this also does kfree() */
114
115 return 0;
116}
diff --git a/sound/drivers/pcsp/pcsp_input.h b/sound/drivers/pcsp/pcsp_input.h
new file mode 100644
index 000000000000..e66738c78333
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_input.h
@@ -0,0 +1,14 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 2001-2008 Stas Sergeev
5 */
6
7#ifndef __PCSP_INPUT_H__
8#define __PCSP_INPUT_H__
9
10int __devinit pcspkr_input_init(struct input_dev **rdev, struct device *dev);
11int pcspkr_input_remove(struct input_dev *dev);
12void pcspkr_stop_sound(void);
13
14#endif
diff --git a/sound/drivers/pcsp/pcsp_lib.c b/sound/drivers/pcsp/pcsp_lib.c
new file mode 100644
index 000000000000..ac6238e93513
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_lib.c
@@ -0,0 +1,338 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 1993-1997 Michael Beck
5 * Copyright (C) 1997-2001 David Woodhouse
6 * Copyright (C) 2001-2008 Stas Sergeev
7 */
8
9#include <linux/module.h>
10#include <linux/moduleparam.h>
11#include <sound/pcm.h>
12#include <linux/interrupt.h>
13#include <asm/io.h>
14#include "pcsp.h"
15
16static int nforce_wa;
17module_param(nforce_wa, bool, 0444);
18MODULE_PARM_DESC(nforce_wa, "Apply NForce chipset workaround "
19 "(expect bad sound)");
20
21static void pcsp_start_timer(unsigned long dummy)
22{
23 hrtimer_start(&pcsp_chip.timer, ktime_set(0, 0), HRTIMER_MODE_REL);
24}
25
26/*
27 * We need the hrtimer_start as a tasklet to avoid
28 * the nasty locking problem. :(
29 * The problem:
30 * - The timer handler is called with the cpu_base->lock
31 * already held by hrtimer code.
32 * - snd_pcm_period_elapsed() takes the
33 * substream->self_group.lock.
34 * So far so good.
35 * But the snd_pcsp_trigger() is called with the
36 * substream->self_group.lock held, and it calls
37 * hrtimer_start(), which takes the cpu_base->lock.
38 * You see the problem. We have the code pathes
39 * which take two locks in a reverse order. This
40 * can deadlock and the lock validator complains.
41 * The only solution I could find was to move the
42 * hrtimer_start() into a tasklet. -stsp
43 */
44static DECLARE_TASKLET(pcsp_start_timer_tasklet, pcsp_start_timer, 0);
45
46enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle)
47{
48 unsigned long flags;
49 unsigned char timer_cnt, val;
50 int periods_elapsed;
51 u64 ns;
52 size_t period_bytes, buffer_bytes;
53 struct snd_pcm_substream *substream;
54 struct snd_pcm_runtime *runtime;
55 struct snd_pcsp *chip = container_of(handle, struct snd_pcsp, timer);
56
57 if (chip->thalf) {
58 outb(chip->val61, 0x61);
59 chip->thalf = 0;
60 if (!atomic_read(&chip->timer_active))
61 return HRTIMER_NORESTART;
62 hrtimer_forward(&chip->timer, chip->timer.expires,
63 ktime_set(0, chip->ns_rem));
64 return HRTIMER_RESTART;
65 }
66
67 /* hrtimer calls us from both hardirq and softirq contexts,
68 * so irqsave :( */
69 spin_lock_irqsave(&chip->substream_lock, flags);
70 /* Takashi Iwai says regarding this extra lock:
71
72 If the irq handler handles some data on the DMA buffer, it should
73 do snd_pcm_stream_lock().
74 That protects basically against all races among PCM callbacks, yes.
75 However, there are two remaining issues:
76 1. The substream pointer you try to lock isn't protected _before_
77 this lock yet.
78 2. snd_pcm_period_elapsed() itself acquires the lock.
79 The requirement of another lock is because of 1. When you get
80 chip->playback_substream, it's not protected.
81 Keeping this lock while snd_pcm_period_elapsed() assures the substream
82 is still protected (at least, not released). And the other status is
83 handled properly inside snd_pcm_stream_lock() in
84 snd_pcm_period_elapsed().
85
86 */
87 if (!chip->playback_substream)
88 goto exit_nr_unlock1;
89 substream = chip->playback_substream;
90 snd_pcm_stream_lock(substream);
91 if (!atomic_read(&chip->timer_active))
92 goto exit_nr_unlock2;
93
94 runtime = substream->runtime;
95 /* assume it is u8 mono */
96 val = runtime->dma_area[chip->playback_ptr];
97 timer_cnt = val * CUR_DIV() / 256;
98
99 if (timer_cnt && chip->enable) {
100 spin_lock(&i8253_lock);
101 if (!nforce_wa) {
102 outb_p(chip->val61, 0x61);
103 outb_p(timer_cnt, 0x42);
104 outb(chip->val61 ^ 1, 0x61);
105 } else {
106 outb(chip->val61 ^ 2, 0x61);
107 chip->thalf = 1;
108 }
109 spin_unlock(&i8253_lock);
110 }
111
112 period_bytes = snd_pcm_lib_period_bytes(substream);
113 buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
114 chip->playback_ptr += PCSP_INDEX_INC();
115 periods_elapsed = chip->playback_ptr - chip->period_ptr;
116 if (periods_elapsed < 0) {
117 printk(KERN_WARNING "PCSP: playback_ptr inconsistent "
118 "(%zi %zi %zi)\n",
119 chip->playback_ptr, period_bytes, buffer_bytes);
120 periods_elapsed += buffer_bytes;
121 }
122 periods_elapsed /= period_bytes;
123 /* wrap the pointer _before_ calling snd_pcm_period_elapsed(),
124 * or ALSA will BUG on us. */
125 chip->playback_ptr %= buffer_bytes;
126
127 snd_pcm_stream_unlock(substream);
128
129 if (periods_elapsed) {
130 snd_pcm_period_elapsed(substream);
131 chip->period_ptr += periods_elapsed * period_bytes;
132 chip->period_ptr %= buffer_bytes;
133 }
134
135 spin_unlock_irqrestore(&chip->substream_lock, flags);
136
137 if (!atomic_read(&chip->timer_active))
138 return HRTIMER_NORESTART;
139
140 chip->ns_rem = PCSP_PERIOD_NS();
141 ns = (chip->thalf ? PCSP_CALC_NS(timer_cnt) : chip->ns_rem);
142 chip->ns_rem -= ns;
143 hrtimer_forward(&chip->timer, chip->timer.expires, ktime_set(0, ns));
144 return HRTIMER_RESTART;
145
146exit_nr_unlock2:
147 snd_pcm_stream_unlock(substream);
148exit_nr_unlock1:
149 spin_unlock_irqrestore(&chip->substream_lock, flags);
150 return HRTIMER_NORESTART;
151}
152
153static void pcsp_start_playing(struct snd_pcsp *chip)
154{
155#if PCSP_DEBUG
156 printk(KERN_INFO "PCSP: start_playing called\n");
157#endif
158 if (atomic_read(&chip->timer_active)) {
159 printk(KERN_ERR "PCSP: Timer already active\n");
160 return;
161 }
162
163 spin_lock(&i8253_lock);
164 chip->val61 = inb(0x61) | 0x03;
165 outb_p(0x92, 0x43); /* binary, mode 1, LSB only, ch 2 */
166 spin_unlock(&i8253_lock);
167 atomic_set(&chip->timer_active, 1);
168 chip->thalf = 0;
169
170 tasklet_schedule(&pcsp_start_timer_tasklet);
171}
172
173static void pcsp_stop_playing(struct snd_pcsp *chip)
174{
175#if PCSP_DEBUG
176 printk(KERN_INFO "PCSP: stop_playing called\n");
177#endif
178 if (!atomic_read(&chip->timer_active))
179 return;
180
181 atomic_set(&chip->timer_active, 0);
182 spin_lock(&i8253_lock);
183 /* restore the timer */
184 outb_p(0xb6, 0x43); /* binary, mode 3, LSB/MSB, ch 2 */
185 outb(chip->val61 & 0xFC, 0x61);
186 spin_unlock(&i8253_lock);
187}
188
189static int snd_pcsp_playback_close(struct snd_pcm_substream *substream)
190{
191 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
192#if PCSP_DEBUG
193 printk(KERN_INFO "PCSP: close called\n");
194#endif
195 if (atomic_read(&chip->timer_active)) {
196 printk(KERN_ERR "PCSP: timer still active\n");
197 pcsp_stop_playing(chip);
198 }
199 spin_lock_irq(&chip->substream_lock);
200 chip->playback_substream = NULL;
201 spin_unlock_irq(&chip->substream_lock);
202 return 0;
203}
204
205static int snd_pcsp_playback_hw_params(struct snd_pcm_substream *substream,
206 struct snd_pcm_hw_params *hw_params)
207{
208 int err;
209 err = snd_pcm_lib_malloc_pages(substream,
210 params_buffer_bytes(hw_params));
211 if (err < 0)
212 return err;
213 return 0;
214}
215
216static int snd_pcsp_playback_hw_free(struct snd_pcm_substream *substream)
217{
218#if PCSP_DEBUG
219 printk(KERN_INFO "PCSP: hw_free called\n");
220#endif
221 return snd_pcm_lib_free_pages(substream);
222}
223
224static int snd_pcsp_playback_prepare(struct snd_pcm_substream *substream)
225{
226 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
227#if PCSP_DEBUG
228 printk(KERN_INFO "PCSP: prepare called, "
229 "size=%zi psize=%zi f=%zi f1=%i\n",
230 snd_pcm_lib_buffer_bytes(substream),
231 snd_pcm_lib_period_bytes(substream),
232 snd_pcm_lib_buffer_bytes(substream) /
233 snd_pcm_lib_period_bytes(substream),
234 substream->runtime->periods);
235#endif
236 chip->playback_ptr = 0;
237 chip->period_ptr = 0;
238 return 0;
239}
240
241static int snd_pcsp_trigger(struct snd_pcm_substream *substream, int cmd)
242{
243 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
244#if PCSP_DEBUG
245 printk(KERN_INFO "PCSP: trigger called\n");
246#endif
247 switch (cmd) {
248 case SNDRV_PCM_TRIGGER_START:
249 case SNDRV_PCM_TRIGGER_RESUME:
250 pcsp_start_playing(chip);
251 break;
252 case SNDRV_PCM_TRIGGER_STOP:
253 case SNDRV_PCM_TRIGGER_SUSPEND:
254 pcsp_stop_playing(chip);
255 break;
256 default:
257 return -EINVAL;
258 }
259 return 0;
260}
261
262static snd_pcm_uframes_t snd_pcsp_playback_pointer(struct snd_pcm_substream
263 *substream)
264{
265 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
266 return bytes_to_frames(substream->runtime, chip->playback_ptr);
267}
268
269static struct snd_pcm_hardware snd_pcsp_playback = {
270 .info = (SNDRV_PCM_INFO_INTERLEAVED |
271 SNDRV_PCM_INFO_HALF_DUPLEX |
272 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
273 .formats = SNDRV_PCM_FMTBIT_U8,
274 .rates = SNDRV_PCM_RATE_KNOT,
275 .rate_min = PCSP_DEFAULT_SRATE,
276 .rate_max = PCSP_DEFAULT_SRATE,
277 .channels_min = 1,
278 .channels_max = 1,
279 .buffer_bytes_max = PCSP_BUFFER_SIZE,
280 .period_bytes_min = 64,
281 .period_bytes_max = PCSP_MAX_PERIOD_SIZE,
282 .periods_min = 2,
283 .periods_max = PCSP_MAX_PERIODS,
284 .fifo_size = 0,
285};
286
287static int snd_pcsp_playback_open(struct snd_pcm_substream *substream)
288{
289 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
290 struct snd_pcm_runtime *runtime = substream->runtime;
291#if PCSP_DEBUG
292 printk(KERN_INFO "PCSP: open called\n");
293#endif
294 if (atomic_read(&chip->timer_active)) {
295 printk(KERN_ERR "PCSP: still active!!\n");
296 return -EBUSY;
297 }
298 runtime->hw = snd_pcsp_playback;
299 spin_lock_irq(&chip->substream_lock);
300 chip->playback_substream = substream;
301 spin_unlock_irq(&chip->substream_lock);
302 return 0;
303}
304
305static struct snd_pcm_ops snd_pcsp_playback_ops = {
306 .open = snd_pcsp_playback_open,
307 .close = snd_pcsp_playback_close,
308 .ioctl = snd_pcm_lib_ioctl,
309 .hw_params = snd_pcsp_playback_hw_params,
310 .hw_free = snd_pcsp_playback_hw_free,
311 .prepare = snd_pcsp_playback_prepare,
312 .trigger = snd_pcsp_trigger,
313 .pointer = snd_pcsp_playback_pointer,
314};
315
316int __devinit snd_pcsp_new_pcm(struct snd_pcsp *chip)
317{
318 int err;
319
320 err = snd_pcm_new(chip->card, "pcspeaker", 0, 1, 0, &chip->pcm);
321 if (err < 0)
322 return err;
323
324 snd_pcm_set_ops(chip->pcm, SNDRV_PCM_STREAM_PLAYBACK,
325 &snd_pcsp_playback_ops);
326
327 chip->pcm->private_data = chip;
328 chip->pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
329 strcpy(chip->pcm->name, "pcsp");
330
331 snd_pcm_lib_preallocate_pages_for_all(chip->pcm,
332 SNDRV_DMA_TYPE_CONTINUOUS,
333 snd_dma_continuous_data
334 (GFP_KERNEL), PCSP_BUFFER_SIZE,
335 PCSP_BUFFER_SIZE);
336
337 return 0;
338}
diff --git a/sound/drivers/pcsp/pcsp_mixer.c b/sound/drivers/pcsp/pcsp_mixer.c
new file mode 100644
index 000000000000..64a695fef74e
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_mixer.c
@@ -0,0 +1,143 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Mixer implementation.
5 * Copyright (C) 2001-2008 Stas Sergeev
6 */
7
8#include <sound/core.h>
9#include <sound/control.h>
10#include "pcsp.h"
11
12
13static int pcsp_enable_info(struct snd_kcontrol *kcontrol,
14 struct snd_ctl_elem_info *uinfo)
15{
16 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
17 uinfo->count = 1;
18 uinfo->value.integer.min = 0;
19 uinfo->value.integer.max = 1;
20 return 0;
21}
22
23static int pcsp_enable_get(struct snd_kcontrol *kcontrol,
24 struct snd_ctl_elem_value *ucontrol)
25{
26 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
27 ucontrol->value.integer.value[0] = chip->enable;
28 return 0;
29}
30
31static int pcsp_enable_put(struct snd_kcontrol *kcontrol,
32 struct snd_ctl_elem_value *ucontrol)
33{
34 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
35 int changed = 0;
36 int enab = ucontrol->value.integer.value[0];
37 if (enab != chip->enable) {
38 chip->enable = enab;
39 changed = 1;
40 }
41 return changed;
42}
43
44static int pcsp_treble_info(struct snd_kcontrol *kcontrol,
45 struct snd_ctl_elem_info *uinfo)
46{
47 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
48 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
49 uinfo->count = 1;
50 uinfo->value.enumerated.items = chip->max_treble + 1;
51 if (uinfo->value.enumerated.item > chip->max_treble)
52 uinfo->value.enumerated.item = chip->max_treble;
53 sprintf(uinfo->value.enumerated.name, "%d", PCSP_RATE());
54 return 0;
55}
56
57static int pcsp_treble_get(struct snd_kcontrol *kcontrol,
58 struct snd_ctl_elem_value *ucontrol)
59{
60 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
61 ucontrol->value.enumerated.item[0] = chip->treble;
62 return 0;
63}
64
65static int pcsp_treble_put(struct snd_kcontrol *kcontrol,
66 struct snd_ctl_elem_value *ucontrol)
67{
68 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
69 int changed = 0;
70 int treble = ucontrol->value.enumerated.item[0];
71 if (treble != chip->treble) {
72 chip->treble = treble;
73#if PCSP_DEBUG
74 printk(KERN_INFO "PCSP: rate set to %i\n", PCSP_RATE());
75#endif
76 changed = 1;
77 }
78 return changed;
79}
80
81static int pcsp_pcspkr_info(struct snd_kcontrol *kcontrol,
82 struct snd_ctl_elem_info *uinfo)
83{
84 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
85 uinfo->count = 1;
86 uinfo->value.integer.min = 0;
87 uinfo->value.integer.max = 1;
88 return 0;
89}
90
91static int pcsp_pcspkr_get(struct snd_kcontrol *kcontrol,
92 struct snd_ctl_elem_value *ucontrol)
93{
94 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
95 ucontrol->value.integer.value[0] = chip->pcspkr;
96 return 0;
97}
98
99static int pcsp_pcspkr_put(struct snd_kcontrol *kcontrol,
100 struct snd_ctl_elem_value *ucontrol)
101{
102 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
103 int changed = 0;
104 int spkr = ucontrol->value.integer.value[0];
105 if (spkr != chip->pcspkr) {
106 chip->pcspkr = spkr;
107 changed = 1;
108 }
109 return changed;
110}
111
112#define PCSP_MIXER_CONTROL(ctl_type, ctl_name) \
113{ \
114 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
115 .name = ctl_name, \
116 .info = pcsp_##ctl_type##_info, \
117 .get = pcsp_##ctl_type##_get, \
118 .put = pcsp_##ctl_type##_put, \
119}
120
121static struct snd_kcontrol_new __devinitdata snd_pcsp_controls[] = {
122 PCSP_MIXER_CONTROL(enable, "Master Playback Switch"),
123 PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"),
124 PCSP_MIXER_CONTROL(pcspkr, "PC Speaker Playback Switch"),
125};
126
127int __devinit snd_pcsp_new_mixer(struct snd_pcsp *chip)
128{
129 struct snd_card *card = chip->card;
130 int i, err;
131
132 for (i = 0; i < ARRAY_SIZE(snd_pcsp_controls); i++) {
133 err = snd_ctl_add(card,
134 snd_ctl_new1(snd_pcsp_controls + i,
135 chip));
136 if (err < 0)
137 return err;
138 }
139
140 strcpy(card->mixername, "PC-Speaker");
141
142 return 0;
143}
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c
index 15061bd72776..d20d893b3b60 100644
--- a/sound/i2c/other/ak4114.c
+++ b/sound/i2c/other/ak4114.c
@@ -27,6 +27,7 @@
27#include <sound/pcm.h> 27#include <sound/pcm.h>
28#include <sound/ak4114.h> 28#include <sound/ak4114.h>
29#include <sound/asoundef.h> 29#include <sound/asoundef.h>
30#include <sound/info.h>
30 31
31MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 32MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
32MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei"); 33MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei");
@@ -446,6 +447,26 @@ static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = {
446} 447}
447}; 448};
448 449
450
451static void snd_ak4114_proc_regs_read(struct snd_info_entry *entry,
452 struct snd_info_buffer *buffer)
453{
454 struct ak4114 *ak4114 = entry->private_data;
455 int reg, val;
456 /* all ak4114 registers 0x00 - 0x1f */
457 for (reg = 0; reg < 0x20; reg++) {
458 val = reg_read(ak4114, reg);
459 snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
460 }
461}
462
463static void snd_ak4114_proc_init(struct ak4114 *ak4114)
464{
465 struct snd_info_entry *entry;
466 if (!snd_card_proc_new(ak4114->card, "ak4114", &entry))
467 snd_info_set_text_ops(entry, ak4114, snd_ak4114_proc_regs_read);
468}
469
449int snd_ak4114_build(struct ak4114 *ak4114, 470int snd_ak4114_build(struct ak4114 *ak4114,
450 struct snd_pcm_substream *ply_substream, 471 struct snd_pcm_substream *ply_substream,
451 struct snd_pcm_substream *cap_substream) 472 struct snd_pcm_substream *cap_substream)
@@ -478,6 +499,7 @@ int snd_ak4114_build(struct ak4114 *ak4114,
478 return err; 499 return err;
479 ak4114->kctls[idx] = kctl; 500 ak4114->kctls[idx] = kctl;
480 } 501 }
502 snd_ak4114_proc_init(ak4114);
481 /* trigger workq */ 503 /* trigger workq */
482 schedule_delayed_work(&ak4114->work, HZ / 10); 504 schedule_delayed_work(&ak4114->work, HZ / 10);
483 return 0; 505 return 0;
@@ -590,7 +612,7 @@ static void ak4114_stats(struct work_struct *work)
590 struct ak4114 *chip = container_of(work, struct ak4114, work.work); 612 struct ak4114 *chip = container_of(work, struct ak4114, work.work);
591 613
592 if (!chip->init) 614 if (!chip->init)
593 snd_ak4114_check_rate_and_errors(chip, 0); 615 snd_ak4114_check_rate_and_errors(chip, chip->check_flags);
594 616
595 schedule_delayed_work(&chip->work, HZ / 10); 617 schedule_delayed_work(&chip->work, HZ / 10);
596} 618}
diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c
index 35fbbf2cb9fa..288926d2e205 100644
--- a/sound/i2c/other/ak4xxx-adda.c
+++ b/sound/i2c/other/ak4xxx-adda.c
@@ -70,7 +70,8 @@ static void ak4524_reset(struct snd_akm4xxx *ak, int state)
70} 70}
71 71
72/* reset procedure for AK4355 and AK4358 */ 72/* reset procedure for AK4355 and AK4358 */
73static void ak4355_reset(struct snd_akm4xxx *ak, int state) 73static void ak435X_reset(struct snd_akm4xxx *ak, int state,
74 unsigned char total_regs)
74{ 75{
75 unsigned char reg; 76 unsigned char reg;
76 77
@@ -78,7 +79,7 @@ static void ak4355_reset(struct snd_akm4xxx *ak, int state)
78 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */ 79 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
79 return; 80 return;
80 } 81 }
81 for (reg = 0x00; reg < 0x0b; reg++) 82 for (reg = 0x00; reg < total_regs; reg++)
82 if (reg != 0x01) 83 if (reg != 0x01)
83 snd_akm4xxx_write(ak, 0, reg, 84 snd_akm4xxx_write(ak, 0, reg,
84 snd_akm4xxx_get(ak, 0, reg)); 85 snd_akm4xxx_get(ak, 0, reg));
@@ -118,8 +119,10 @@ void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state)
118 /* FIXME: needed for ak4529? */ 119 /* FIXME: needed for ak4529? */
119 break; 120 break;
120 case SND_AK4355: 121 case SND_AK4355:
122 ak435X_reset(ak, state, 0x0b);
123 break;
121 case SND_AK4358: 124 case SND_AK4358:
122 ak4355_reset(ak, state); 125 ak435X_reset(ak, state, 0x10);
123 break; 126 break;
124 case SND_AK4381: 127 case SND_AK4381:
125 ak4381_reset(ak, state); 128 ak4381_reset(ak, state);
@@ -292,11 +295,6 @@ void snd_akm4xxx_init(struct snd_akm4xxx *ak)
292 case SND_AK5365: 295 case SND_AK5365:
293 /* FIXME: any init sequence? */ 296 /* FIXME: any init sequence? */
294 return; 297 return;
295 case NON_AKM:
296 /* fake value for non-akm codecs using akm infrastructure
297 * (e.g. of ice1724) - certainly FIXME
298 */
299 return;
300 default: 298 default:
301 snd_BUG(); 299 snd_BUG();
302 return; 300 return;
@@ -374,6 +372,8 @@ static int put_ak_reg(struct snd_kcontrol *kcontrol, int addr,
374 nval = mask - nval; 372 nval = mask - nval;
375 if (AK_GET_NEEDSMSB(kcontrol->private_value)) 373 if (AK_GET_NEEDSMSB(kcontrol->private_value))
376 nval |= 0x80; 374 nval |= 0x80;
375 /* printk(KERN_DEBUG "DEBUG - AK writing reg: chip %x addr %x,
376 nval %x\n", chip, addr, nval); */
377 snd_akm4xxx_write(ak, chip, addr, nval); 377 snd_akm4xxx_write(ak, chip, addr, nval);
378 return 1; 378 return 1;
379} 379}
diff --git a/sound/isa/sb/sb16_csp.c b/sound/isa/sb/sb16_csp.c
index bed29ca22239..f3fd7b4f4668 100644
--- a/sound/isa/sb/sb16_csp.c
+++ b/sound/isa/sb/sb16_csp.c
@@ -331,7 +331,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
331 return -EFAULT; 331 return -EFAULT;
332 if ((file_h.name != RIFF_HEADER) || 332 if ((file_h.name != RIFF_HEADER) ||
333 (le32_to_cpu(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) { 333 (le32_to_cpu(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) {
334 snd_printd("%s: Invalid RIFF header\n", __FUNCTION__); 334 snd_printd("%s: Invalid RIFF header\n", __func__);
335 return -EINVAL; 335 return -EINVAL;
336 } 336 }
337 data_ptr += sizeof(file_h); 337 data_ptr += sizeof(file_h);
@@ -340,7 +340,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
340 if (copy_from_user(&item_type, data_ptr, sizeof(item_type))) 340 if (copy_from_user(&item_type, data_ptr, sizeof(item_type)))
341 return -EFAULT; 341 return -EFAULT;
342 if (item_type != CSP__HEADER) { 342 if (item_type != CSP__HEADER) {
343 snd_printd("%s: Invalid RIFF file type\n", __FUNCTION__); 343 snd_printd("%s: Invalid RIFF file type\n", __func__);
344 return -EINVAL; 344 return -EINVAL;
345 } 345 }
346 data_ptr += sizeof (item_type); 346 data_ptr += sizeof (item_type);
@@ -395,7 +395,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
395 return -EFAULT; 395 return -EFAULT;
396 396
397 if (code_h.name != MAIN_HEADER) { 397 if (code_h.name != MAIN_HEADER) {
398 snd_printd("%s: Missing 'main' microcode\n", __FUNCTION__); 398 snd_printd("%s: Missing 'main' microcode\n", __func__);
399 return -EINVAL; 399 return -EINVAL;
400 } 400 }
401 data_ptr += sizeof(code_h); 401 data_ptr += sizeof(code_h);
@@ -439,7 +439,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
439 p->acc_format = p->acc_width = p->acc_rates = 0; 439 p->acc_format = p->acc_width = p->acc_rates = 0;
440 p->mode = 0; 440 p->mode = 0;
441 snd_printd("%s: Unsupported CSP codec type: 0x%04x\n", 441 snd_printd("%s: Unsupported CSP codec type: 0x%04x\n",
442 __FUNCTION__, 442 __func__,
443 le16_to_cpu(funcdesc_h.VOC_type)); 443 le16_to_cpu(funcdesc_h.VOC_type));
444 return -EINVAL; 444 return -EINVAL;
445 } 445 }
@@ -458,7 +458,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
458 return 0; 458 return 0;
459 } 459 }
460 } 460 }
461 snd_printd("%s: Function #%d not found\n", __FUNCTION__, info.func_req); 461 snd_printd("%s: Function #%d not found\n", __func__, info.func_req);
462 return -EINVAL; 462 return -EINVAL;
463} 463}
464 464
@@ -612,7 +612,7 @@ static int get_version(struct snd_sb *chip)
612static int snd_sb_csp_check_version(struct snd_sb_csp * p) 612static int snd_sb_csp_check_version(struct snd_sb_csp * p)
613{ 613{
614 if (p->version < 0x10 || p->version > 0x1f) { 614 if (p->version < 0x10 || p->version > 0x1f) {
615 snd_printd("%s: Invalid CSP version: 0x%x\n", __FUNCTION__, p->version); 615 snd_printd("%s: Invalid CSP version: 0x%x\n", __func__, p->version);
616 return 1; 616 return 1;
617 } 617 }
618 return 0; 618 return 0;
@@ -631,7 +631,7 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int
631 spin_lock_irqsave(&p->chip->reg_lock, flags); 631 spin_lock_irqsave(&p->chip->reg_lock, flags);
632 snd_sbdsp_command(p->chip, 0x01); /* CSP download command */ 632 snd_sbdsp_command(p->chip, 0x01); /* CSP download command */
633 if (snd_sbdsp_get_byte(p->chip)) { 633 if (snd_sbdsp_get_byte(p->chip)) {
634 snd_printd("%s: Download command failed\n", __FUNCTION__); 634 snd_printd("%s: Download command failed\n", __func__);
635 goto __fail; 635 goto __fail;
636 } 636 }
637 /* Send CSP low byte (size - 1) */ 637 /* Send CSP low byte (size - 1) */
@@ -658,7 +658,7 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int
658 udelay (10); 658 udelay (10);
659 } 659 }
660 if (status != 0x55) { 660 if (status != 0x55) {
661 snd_printd("%s: Microcode initialization failed\n", __FUNCTION__); 661 snd_printd("%s: Microcode initialization failed\n", __func__);
662 goto __fail; 662 goto __fail;
663 } 663 }
664 } else { 664 } else {
@@ -824,19 +824,19 @@ static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channel
824 unsigned long flags; 824 unsigned long flags;
825 825
826 if (!(p->running & (SNDRV_SB_CSP_ST_LOADED | SNDRV_SB_CSP_ST_AUTO))) { 826 if (!(p->running & (SNDRV_SB_CSP_ST_LOADED | SNDRV_SB_CSP_ST_AUTO))) {
827 snd_printd("%s: Microcode not loaded\n", __FUNCTION__); 827 snd_printd("%s: Microcode not loaded\n", __func__);
828 return -ENXIO; 828 return -ENXIO;
829 } 829 }
830 if (p->running & SNDRV_SB_CSP_ST_RUNNING) { 830 if (p->running & SNDRV_SB_CSP_ST_RUNNING) {
831 snd_printd("%s: CSP already running\n", __FUNCTION__); 831 snd_printd("%s: CSP already running\n", __func__);
832 return -EBUSY; 832 return -EBUSY;
833 } 833 }
834 if (!(sample_width & p->acc_width)) { 834 if (!(sample_width & p->acc_width)) {
835 snd_printd("%s: Unsupported PCM sample width\n", __FUNCTION__); 835 snd_printd("%s: Unsupported PCM sample width\n", __func__);
836 return -EINVAL; 836 return -EINVAL;
837 } 837 }
838 if (!(channels & p->acc_channels)) { 838 if (!(channels & p->acc_channels)) {
839 snd_printd("%s: Invalid number of channels\n", __FUNCTION__); 839 snd_printd("%s: Invalid number of channels\n", __func__);
840 return -EINVAL; 840 return -EINVAL;
841 } 841 }
842 842
@@ -858,11 +858,11 @@ static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channel
858 s_type |= 0x22; /* 00dX 00dX (d = 1 if 8 bit samples) */ 858 s_type |= 0x22; /* 00dX 00dX (d = 1 if 8 bit samples) */
859 859
860 if (set_codec_parameter(p->chip, 0x81, s_type)) { 860 if (set_codec_parameter(p->chip, 0x81, s_type)) {
861 snd_printd("%s: Set sample type command failed\n", __FUNCTION__); 861 snd_printd("%s: Set sample type command failed\n", __func__);
862 goto __fail; 862 goto __fail;
863 } 863 }
864 if (set_codec_parameter(p->chip, 0x80, 0x00)) { 864 if (set_codec_parameter(p->chip, 0x80, 0x00)) {
865 snd_printd("%s: Codec start command failed\n", __FUNCTION__); 865 snd_printd("%s: Codec start command failed\n", __func__);
866 goto __fail; 866 goto __fail;
867 } 867 }
868 p->run_width = sample_width; 868 p->run_width = sample_width;
diff --git a/sound/isa/sb/sb_common.c b/sound/isa/sb/sb_common.c
index d63c1af550de..b432d9ae874b 100644
--- a/sound/isa/sb/sb_common.c
+++ b/sound/isa/sb/sb_common.c
@@ -51,7 +51,7 @@ int snd_sbdsp_command(struct snd_sb *chip, unsigned char val)
51 outb(val, SBP(chip, COMMAND)); 51 outb(val, SBP(chip, COMMAND));
52 return 1; 52 return 1;
53 } 53 }
54 snd_printd("%s [0x%lx]: timeout (0x%x)\n", __FUNCTION__, chip->port, val); 54 snd_printd("%s [0x%lx]: timeout (0x%x)\n", __func__, chip->port, val);
55 return 0; 55 return 0;
56} 56}
57 57
@@ -68,7 +68,7 @@ int snd_sbdsp_get_byte(struct snd_sb *chip)
68 return val; 68 return val;
69 } 69 }
70 } 70 }
71 snd_printd("%s [0x%lx]: timeout\n", __FUNCTION__, chip->port); 71 snd_printd("%s [0x%lx]: timeout\n", __func__, chip->port);
72 return -ENODEV; 72 return -ENODEV;
73} 73}
74 74
@@ -87,7 +87,7 @@ int snd_sbdsp_reset(struct snd_sb *chip)
87 else 87 else
88 break; 88 break;
89 } 89 }
90 snd_printdd("%s [0x%lx] failed...\n", __FUNCTION__, chip->port); 90 snd_printdd("%s [0x%lx] failed...\n", __func__, chip->port);
91 return -ENODEV; 91 return -ENODEV;
92} 92}
93 93
diff --git a/sound/oss/dmabuf.c b/sound/oss/dmabuf.c
index eaf69971bf92..1e90d769b62e 100644
--- a/sound/oss/dmabuf.c
+++ b/sound/oss/dmabuf.c
@@ -795,9 +795,9 @@ static int find_output_space(int dev, char **buf, int *size)
795#ifdef BE_CONSERVATIVE 795#ifdef BE_CONSERVATIVE
796 active_offs = dmap->byte_counter + dmap->qhead * dmap->fragment_size; 796 active_offs = dmap->byte_counter + dmap->qhead * dmap->fragment_size;
797#else 797#else
798 active_offs = DMAbuf_get_buffer_pointer(dev, dmap, DMODE_OUTPUT); 798 active_offs = max(DMAbuf_get_buffer_pointer(dev, dmap, DMODE_OUTPUT), 0);
799 /* Check for pointer wrapping situation */ 799 /* Check for pointer wrapping situation */
800 if (active_offs < 0 || active_offs >= dmap->bytes_in_use) 800 if (active_offs >= dmap->bytes_in_use)
801 active_offs = 0; 801 active_offs = 0;
802 active_offs += dmap->byte_counter; 802 active_offs += dmap->byte_counter;
803#endif 803#endif
diff --git a/sound/oss/trident.c b/sound/oss/trident.c
index d6af9065d1c0..f43f91ef86c7 100644
--- a/sound/oss/trident.c
+++ b/sound/oss/trident.c
@@ -3076,8 +3076,7 @@ ali_ac97_get(struct trident_card *card, int secondary, u8 reg)
3076 u16 wcontrol; 3076 u16 wcontrol;
3077 unsigned long flags; 3077 unsigned long flags;
3078 3078
3079 if (!card) 3079 BUG_ON(!card);
3080 BUG();
3081 3080
3082 address = ALI_AC97_READ; 3081 address = ALI_AC97_READ;
3083 if (card->revision == ALI_5451_V02) { 3082 if (card->revision == ALI_5451_V02) {
@@ -3148,8 +3147,7 @@ ali_ac97_set(struct trident_card *card, int secondary, u8 reg, u16 val)
3148 3147
3149 data = ((u32) val) << 16; 3148 data = ((u32) val) << 16;
3150 3149
3151 if (!card) 3150 BUG_ON(!card);
3152 BUG();
3153 3151
3154 address = ALI_AC97_WRITE; 3152 address = ALI_AC97_WRITE;
3155 mask = ALI_AC97_WRITE_ACTION | ALI_AC97_AUDIO_BUSY; 3153 mask = ALI_AC97_WRITE_ACTION | ALI_AC97_AUDIO_BUSY;
@@ -3213,8 +3211,7 @@ ali_ac97_read(struct ac97_codec *codec, u8 reg)
3213 struct trident_card *card = NULL; 3211 struct trident_card *card = NULL;
3214 3212
3215 /* Added by Matt Wu */ 3213 /* Added by Matt Wu */
3216 if (!codec) 3214 BUG_ON(!codec);
3217 BUG();
3218 3215
3219 card = (struct trident_card *) codec->private_data; 3216 card = (struct trident_card *) codec->private_data;
3220 3217
@@ -3240,8 +3237,7 @@ ali_ac97_write(struct ac97_codec *codec, u8 reg, u16 val)
3240 struct trident_card *card; 3237 struct trident_card *card;
3241 3238
3242 /* Added by Matt Wu */ 3239 /* Added by Matt Wu */
3243 if (!codec) 3240 BUG_ON(!codec);
3244 BUG();
3245 3241
3246 card = (struct trident_card *) codec->private_data; 3242 card = (struct trident_card *) codec->private_data;
3247 3243
diff --git a/sound/oss/trident.h b/sound/oss/trident.h
index 4713b49fc91d..ff30a1d7c2f1 100644
--- a/sound/oss/trident.h
+++ b/sound/oss/trident.h
@@ -322,7 +322,7 @@ enum miscint_bits {
322#define VALIDATE_MAGIC(FOO,MAG) \ 322#define VALIDATE_MAGIC(FOO,MAG) \
323({ \ 323({ \
324 if (!(FOO) || (FOO)->magic != MAG) { \ 324 if (!(FOO) || (FOO)->magic != MAG) { \
325 printk(invalid_magic,__FUNCTION__); \ 325 printk(invalid_magic,__func__); \
326 return -ENXIO; \ 326 return -ENXIO; \
327 } \ 327 } \
328}) 328})
diff --git a/sound/oss/vwsnd.c b/sound/oss/vwsnd.c
index d25249a932bf..2c5aaa58046d 100644
--- a/sound/oss/vwsnd.c
+++ b/sound/oss/vwsnd.c
@@ -194,11 +194,11 @@ static void dbgassert(const char *fcn, int line, const char *expr)
194 * DBGRV - debug print function return when verbose 194 * DBGRV - debug print function return when verbose
195 */ 195 */
196 196
197#define ASSERT(e) ((e) ? (void) 0 : dbgassert(__FUNCTION__, __LINE__, #e)) 197#define ASSERT(e) ((e) ? (void) 0 : dbgassert(__func__, __LINE__, #e))
198#define DBGDO(x) x 198#define DBGDO(x) x
199#define DBGX(fmt, args...) (in_interrupt() ? 0 : printk(KERN_ERR fmt, ##args)) 199#define DBGX(fmt, args...) (in_interrupt() ? 0 : printk(KERN_ERR fmt, ##args))
200#define DBGP(fmt, args...) (DBGX("%s: " fmt, __FUNCTION__ , ##args)) 200#define DBGP(fmt, args...) (DBGX("%s: " fmt, __func__ , ##args))
201#define DBGE(fmt, args...) (DBGX("%s" fmt, __FUNCTION__ , ##args)) 201#define DBGE(fmt, args...) (DBGX("%s" fmt, __func__ , ##args))
202#define DBGC(rtn) (DBGP("calling %s\n", rtn)) 202#define DBGC(rtn) (DBGP("calling %s\n", rtn))
203#define DBGR() (DBGP("returning\n")) 203#define DBGR() (DBGP("returning\n"))
204#define DBGXV(fmt, args...) (shut_up ? 0 : DBGX(fmt, ##args)) 204#define DBGXV(fmt, args...) (shut_up ? 0 : DBGX(fmt, ##args))
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 812085d521f1..581debf37dcb 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -122,6 +122,21 @@ config SND_AU8830
122 To compile this driver as a module, choose M here: the module 122 To compile this driver as a module, choose M here: the module
123 will be called snd-au8830. 123 will be called snd-au8830.
124 124
125config SND_AW2
126 tristate "Emagic Audiowerk 2"
127 depends on SND
128 help
129 Say Y here to include support for Emagic Audiowerk 2 soundcards.
130
131 Supported features: Analog and SPDIF output. Analog or SPDIF input.
132 Note: Switch between analog and digital input does not always work.
133 It can produce continuous noise. The workaround is to switch again
134 (and again) between digital and analog input until it works.
135
136 To compile this driver as a module, choose M here: the module
137 will be called snd-aw2.
138
139
125config SND_AZT3328 140config SND_AZT3328
126 tristate "Aztech AZF3328 / PCI168 (EXPERIMENTAL)" 141 tristate "Aztech AZF3328 / PCI168 (EXPERIMENTAL)"
127 depends on SND && EXPERIMENTAL 142 depends on SND && EXPERIMENTAL
@@ -162,6 +177,7 @@ config SND_CA0106
162 depends on SND 177 depends on SND
163 select SND_AC97_CODEC 178 select SND_AC97_CODEC
164 select SND_RAWMIDI 179 select SND_RAWMIDI
180 select SND_VMASTER
165 help 181 help
166 Say Y here to include support for the Sound Blaster Audigy LS 182 Say Y here to include support for the Sound Blaster Audigy LS
167 and Live 24bit. 183 and Live 24bit.
@@ -517,6 +533,7 @@ config SND_HDA_INTEL
517 tristate "Intel HD Audio" 533 tristate "Intel HD Audio"
518 depends on SND 534 depends on SND
519 select SND_PCM 535 select SND_PCM
536 select SND_VMASTER
520 help 537 help
521 Say Y here to include support for Intel "High Definition 538 Say Y here to include support for Intel "High Definition
522 Audio" (Azalia) motherboard devices. 539 Audio" (Azalia) motherboard devices.
@@ -680,6 +697,7 @@ config SND_ICE1724
680 depends on SND 697 depends on SND
681 select SND_MPU401_UART 698 select SND_MPU401_UART
682 select SND_AC97_CODEC 699 select SND_AC97_CODEC
700 select SND_VMASTER
683 help 701 help
684 Say Y here to include support for soundcards based on 702 Say Y here to include support for soundcards based on
685 ICE/VT1724/1720 (Envy24HT/PT) chips. 703 ICE/VT1724/1720 (Envy24HT/PT) chips.
@@ -896,12 +914,12 @@ config SND_VIA82XX_MODEM
896 will be called snd-via82xx-modem. 914 will be called snd-via82xx-modem.
897 915
898config SND_VIRTUOSO 916config SND_VIRTUOSO
899 tristate "Asus Virtuoso 200 (Xonar)" 917 tristate "Asus Virtuoso 100/200 (Xonar)"
900 depends on SND 918 depends on SND
901 select SND_OXYGEN_LIB 919 select SND_OXYGEN_LIB
902 help 920 help
903 Say Y here to include support for sound cards based on the 921 Say Y here to include support for sound cards based on the
904 Asus AV200 chip, i.e., Xonar D2 and Xonar D2X. 922 Asus AV100/AV200 chips, i.e., Xonar D2, DX and D2X.
905 923
906 To compile this driver as a module, choose M here: the module 924 To compile this driver as a module, choose M here: the module
907 will be called snd-virtuoso. 925 will be called snd-virtuoso.
diff --git a/sound/pci/Makefile b/sound/pci/Makefile
index 2d42fd28f4e7..85ef14bc8056 100644
--- a/sound/pci/Makefile
+++ b/sound/pci/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_SND) += \
58 ac97/ \ 58 ac97/ \
59 ali5451/ \ 59 ali5451/ \
60 au88x0/ \ 60 au88x0/ \
61 aw2/ \
61 ca0106/ \ 62 ca0106/ \
62 cs46xx/ \ 63 cs46xx/ \
63 cs5535audio/ \ 64 cs5535audio/ \
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 50c637e55ffa..39198e505b12 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -114,10 +114,9 @@ static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd
114 114
115static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 115static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
116{ 116{
117 static const char *texts[] = { "2ch", "4ch", "6ch" }; 117 static const char *texts[] = { "2ch", "4ch", "6ch", "8ch" };
118 if (kcontrol->private_value) 118 return ac97_enum_text_info(kcontrol, uinfo, texts,
119 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */ 119 kcontrol->private_value);
120 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
121} 120}
122 121
123static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 122static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -133,13 +132,8 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
133 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 132 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
134 unsigned char mode = ucontrol->value.enumerated.item[0]; 133 unsigned char mode = ucontrol->value.enumerated.item[0];
135 134
136 if (kcontrol->private_value) { 135 if (mode >= kcontrol->private_value)
137 if (mode >= 2) 136 return -EINVAL;
138 return -EINVAL;
139 } else {
140 if (mode >= 3)
141 return -EINVAL;
142 }
143 137
144 if (mode != ac97->channel_mode) { 138 if (mode != ac97->channel_mode) {
145 ac97->channel_mode = mode; 139 ac97->channel_mode = mode;
@@ -158,6 +152,7 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
158 .get = ac97_surround_jack_mode_get, \ 152 .get = ac97_surround_jack_mode_get, \
159 .put = ac97_surround_jack_mode_put, \ 153 .put = ac97_surround_jack_mode_put, \
160 } 154 }
155/* 6ch */
161#define AC97_CHANNEL_MODE_CTL \ 156#define AC97_CHANNEL_MODE_CTL \
162 { \ 157 { \
163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -165,7 +160,9 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
165 .info = ac97_channel_mode_info, \ 160 .info = ac97_channel_mode_info, \
166 .get = ac97_channel_mode_get, \ 161 .get = ac97_channel_mode_get, \
167 .put = ac97_channel_mode_put, \ 162 .put = ac97_channel_mode_put, \
163 .private_value = 3, \
168 } 164 }
165/* 4ch */
169#define AC97_CHANNEL_MODE_4CH_CTL \ 166#define AC97_CHANNEL_MODE_4CH_CTL \
170 { \ 167 { \
171 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 168 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -173,7 +170,17 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
173 .info = ac97_channel_mode_info, \ 170 .info = ac97_channel_mode_info, \
174 .get = ac97_channel_mode_get, \ 171 .get = ac97_channel_mode_get, \
175 .put = ac97_channel_mode_put, \ 172 .put = ac97_channel_mode_put, \
176 .private_value = 1, \ 173 .private_value = 2, \
174 }
175/* 8ch */
176#define AC97_CHANNEL_MODE_8CH_CTL \
177 { \
178 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
179 .name = "Channel Mode", \
180 .info = ac97_channel_mode_info, \
181 .get = ac97_channel_mode_get, \
182 .put = ac97_channel_mode_put, \
183 .private_value = 4, \
177 } 184 }
178 185
179static inline int is_surround_on(struct snd_ac97 *ac97) 186static inline int is_surround_on(struct snd_ac97 *ac97)
@@ -210,6 +217,10 @@ static inline int is_shared_micin(struct snd_ac97 *ac97)
210 return !ac97->indep_surround && !is_clfe_on(ac97); 217 return !ac97->indep_surround && !is_clfe_on(ac97);
211} 218}
212 219
220static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
221{
222 return is_surround_on(ac97);
223}
213 224
214/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */ 225/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
215/* Modified for YMF743 by Keita Maehara <maehara@debian.org> */ 226/* Modified for YMF743 by Keita Maehara <maehara@debian.org> */
@@ -2816,10 +2827,12 @@ static int patch_alc655(struct snd_ac97 * ac97)
2816 2827
2817#define AC97_ALC850_JACK_SELECT 0x76 2828#define AC97_ALC850_JACK_SELECT 0x76
2818#define AC97_ALC850_MISC1 0x7a 2829#define AC97_ALC850_MISC1 0x7a
2830#define AC97_ALC850_MULTICH 0x6a
2819 2831
2820static void alc850_update_jacks(struct snd_ac97 *ac97) 2832static void alc850_update_jacks(struct snd_ac97 *ac97)
2821{ 2833{
2822 int shared; 2834 int shared;
2835 int aux_is_back_surround;
2823 2836
2824 /* shared Line-In / Surround Out */ 2837 /* shared Line-In / Surround Out */
2825 shared = is_shared_surrout(ac97); 2838 shared = is_shared_surrout(ac97);
@@ -2837,13 +2850,18 @@ static void alc850_update_jacks(struct snd_ac97 *ac97)
2837 /* MIC-IN = 1, CENTER-LFE = 5 */ 2850 /* MIC-IN = 1, CENTER-LFE = 5 */
2838 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, 2851 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2839 shared ? (5<<4) : (1<<4)); 2852 shared ? (5<<4) : (1<<4));
2853
2854 aux_is_back_surround = alc850_is_aux_back_surround(ac97);
2855 /* Aux is Back Surround */
2856 snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10,
2857 aux_is_back_surround ? (1<<10) : (0<<10));
2840} 2858}
2841 2859
2842static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = { 2860static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
2843 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 2861 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2844 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1), 2862 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
2845 AC97_SURROUND_JACK_MODE_CTL, 2863 AC97_SURROUND_JACK_MODE_CTL,
2846 AC97_CHANNEL_MODE_CTL, 2864 AC97_CHANNEL_MODE_8CH_CTL,
2847}; 2865};
2848 2866
2849static int patch_alc850_specific(struct snd_ac97 *ac97) 2867static int patch_alc850_specific(struct snd_ac97 *ac97)
@@ -2869,6 +2887,7 @@ static int patch_alc850(struct snd_ac97 *ac97)
2869 ac97->build_ops = &patch_alc850_ops; 2887 ac97->build_ops = &patch_alc850_ops;
2870 2888
2871 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ 2889 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2890 ac97->flags |= AC97_HAS_8CH;
2872 2891
2873 /* assume only page 0 for writing cache */ 2892 /* assume only page 0 for writing cache */
2874 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 2893 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
@@ -2878,6 +2897,7 @@ static int patch_alc850(struct snd_ac97 *ac97)
2878 spdif-in monitor off, spdif-in PCM off 2897 spdif-in monitor off, spdif-in PCM off
2879 center on mic off, surround on line-in off 2898 center on mic off, surround on line-in off
2880 duplicate front off 2899 duplicate front off
2900 NB default bit 10=0 = Aux is Capture, not Back Surround
2881 */ 2901 */
2882 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 2902 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2883 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off 2903 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
diff --git a/sound/pci/ac97/ac97_pcm.c b/sound/pci/ac97/ac97_pcm.c
index 3674f35c4a79..48cbda9378c5 100644
--- a/sound/pci/ac97/ac97_pcm.c
+++ b/sound/pci/ac97/ac97_pcm.c
@@ -574,7 +574,6 @@ int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,
574 r = rate > 48000; 574 r = rate > 48000;
575 bus = pcm->bus; 575 bus = pcm->bus;
576 if (cfg == AC97_PCM_CFG_SPDIF) { 576 if (cfg == AC97_PCM_CFG_SPDIF) {
577 int err;
578 for (cidx = 0; cidx < 4; cidx++) 577 for (cidx = 0; cidx < 4; cidx++)
579 if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) { 578 if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) {
580 err = set_spdif_rate(bus->codec[cidx], rate); 579 err = set_spdif_rate(bus->codec[cidx], rate);
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index a66d5150bb7a..39ec55b57b1e 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -264,10 +264,10 @@ snd_ad1889_ac97_ready(struct snd_ad1889 *chip)
264 mdelay(1); 264 mdelay(1);
265 if (!retry) { 265 if (!retry) {
266 snd_printk(KERN_ERR PFX "[%s] Link is not ready.\n", 266 snd_printk(KERN_ERR PFX "[%s] Link is not ready.\n",
267 __FUNCTION__); 267 __func__);
268 return -EIO; 268 return -EIO;
269 } 269 }
270 ad1889_debug("[%s] ready after %d ms\n", __FUNCTION__, 400 - retry); 270 ad1889_debug("[%s] ready after %d ms\n", __func__, 400 - retry);
271 271
272 return 0; 272 return 0;
273} 273}
@@ -854,8 +854,6 @@ snd_ad1889_free(struct snd_ad1889 *chip)
854 854
855 spin_unlock_irq(&chip->lock); 855 spin_unlock_irq(&chip->lock);
856 856
857 synchronize_irq(chip->irq);
858
859 if (chip->irq >= 0) 857 if (chip->irq >= 0)
860 free_irq(chip->irq, chip); 858 free_irq(chip->irq, chip);
861 859
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index 6a905ed9cbd6..1a0fd65ec280 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -1809,26 +1809,26 @@ static int snd_ali5451_spdif_get(struct snd_kcontrol *kcontrol,
1809 struct snd_ctl_elem_value *ucontrol) 1809 struct snd_ctl_elem_value *ucontrol)
1810{ 1810{
1811 struct snd_ali *codec = kcontrol->private_data; 1811 struct snd_ali *codec = kcontrol->private_data;
1812 unsigned int enable; 1812 unsigned int spdif_enable;
1813 1813
1814 enable = ucontrol->value.integer.value[0] ? 1 : 0; 1814 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0;
1815 1815
1816 spin_lock_irq(&codec->reg_lock); 1816 spin_lock_irq(&codec->reg_lock);
1817 switch (kcontrol->private_value) { 1817 switch (kcontrol->private_value) {
1818 case 0: 1818 case 0:
1819 enable = (codec->spdif_mask & 0x02) ? 1 : 0; 1819 spdif_enable = (codec->spdif_mask & 0x02) ? 1 : 0;
1820 break; 1820 break;
1821 case 1: 1821 case 1:
1822 enable = ((codec->spdif_mask & 0x02) && 1822 spdif_enable = ((codec->spdif_mask & 0x02) &&
1823 (codec->spdif_mask & 0x04)) ? 1 : 0; 1823 (codec->spdif_mask & 0x04)) ? 1 : 0;
1824 break; 1824 break;
1825 case 2: 1825 case 2:
1826 enable = (codec->spdif_mask & 0x01) ? 1 : 0; 1826 spdif_enable = (codec->spdif_mask & 0x01) ? 1 : 0;
1827 break; 1827 break;
1828 default: 1828 default:
1829 break; 1829 break;
1830 } 1830 }
1831 ucontrol->value.integer.value[0] = enable; 1831 ucontrol->value.integer.value[0] = spdif_enable;
1832 spin_unlock_irq(&codec->reg_lock); 1832 spin_unlock_irq(&codec->reg_lock);
1833 return 0; 1833 return 0;
1834} 1834}
@@ -1837,17 +1837,17 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,
1837 struct snd_ctl_elem_value *ucontrol) 1837 struct snd_ctl_elem_value *ucontrol)
1838{ 1838{
1839 struct snd_ali *codec = kcontrol->private_data; 1839 struct snd_ali *codec = kcontrol->private_data;
1840 unsigned int change = 0, enable = 0; 1840 unsigned int change = 0, spdif_enable = 0;
1841 1841
1842 enable = ucontrol->value.integer.value[0] ? 1 : 0; 1842 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0;
1843 1843
1844 spin_lock_irq(&codec->reg_lock); 1844 spin_lock_irq(&codec->reg_lock);
1845 switch (kcontrol->private_value) { 1845 switch (kcontrol->private_value) {
1846 case 0: 1846 case 0:
1847 change = (codec->spdif_mask & 0x02) ? 1 : 0; 1847 change = (codec->spdif_mask & 0x02) ? 1 : 0;
1848 change = change ^ enable; 1848 change = change ^ spdif_enable;
1849 if (change) { 1849 if (change) {
1850 if (enable) { 1850 if (spdif_enable) {
1851 codec->spdif_mask |= 0x02; 1851 codec->spdif_mask |= 0x02;
1852 snd_ali_enable_spdif_out(codec); 1852 snd_ali_enable_spdif_out(codec);
1853 } else { 1853 } else {
@@ -1859,9 +1859,9 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,
1859 break; 1859 break;
1860 case 1: 1860 case 1:
1861 change = (codec->spdif_mask & 0x04) ? 1 : 0; 1861 change = (codec->spdif_mask & 0x04) ? 1 : 0;
1862 change = change ^ enable; 1862 change = change ^ spdif_enable;
1863 if (change && (codec->spdif_mask & 0x02)) { 1863 if (change && (codec->spdif_mask & 0x02)) {
1864 if (enable) { 1864 if (spdif_enable) {
1865 codec->spdif_mask |= 0x04; 1865 codec->spdif_mask |= 0x04;
1866 snd_ali_enable_spdif_chnout(codec); 1866 snd_ali_enable_spdif_chnout(codec);
1867 } else { 1867 } else {
@@ -1872,9 +1872,9 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,
1872 break; 1872 break;
1873 case 2: 1873 case 2:
1874 change = (codec->spdif_mask & 0x01) ? 1 : 0; 1874 change = (codec->spdif_mask & 0x01) ? 1 : 0;
1875 change = change ^ enable; 1875 change = change ^ spdif_enable;
1876 if (change) { 1876 if (change) {
1877 if (enable) { 1877 if (spdif_enable) {
1878 codec->spdif_mask |= 0x01; 1878 codec->spdif_mask |= 0x01;
1879 snd_ali_enable_spdif_in(codec); 1879 snd_ali_enable_spdif_in(codec);
1880 } else { 1880 } else {
@@ -2047,10 +2047,8 @@ static int snd_ali_free(struct snd_ali * codec)
2047{ 2047{
2048 if (codec->hw_initialized) 2048 if (codec->hw_initialized)
2049 snd_ali_disable_address_interrupt(codec); 2049 snd_ali_disable_address_interrupt(codec);
2050 if (codec->irq >= 0) { 2050 if (codec->irq >= 0)
2051 synchronize_irq(codec->irq);
2052 free_irq(codec->irq, codec); 2051 free_irq(codec->irq, codec);
2053 }
2054 if (codec->port) 2052 if (codec->port)
2055 pci_release_regions(codec->pci); 2053 pci_release_regions(codec->pci);
2056 pci_disable_device(codec->pci); 2054 pci_disable_device(codec->pci);
diff --git a/sound/pci/als300.c b/sound/pci/als300.c
index 0e990a735821..8df6824b51cd 100644
--- a/sound/pci/als300.c
+++ b/sound/pci/als300.c
@@ -92,8 +92,8 @@
92 92
93#if DEBUG_CALLS 93#if DEBUG_CALLS
94#define snd_als300_dbgcalls(format, args...) printk(format, ##args) 94#define snd_als300_dbgcalls(format, args...) printk(format, ##args)
95#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__) 95#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__)
96#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__) 96#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__)
97#else 97#else
98#define snd_als300_dbgcalls(format, args...) 98#define snd_als300_dbgcalls(format, args...)
99#define snd_als300_dbgcallenter() 99#define snd_als300_dbgcallenter()
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index 4594186b83ee..457228fb22aa 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -1553,7 +1553,7 @@ static int snd_atiixp_free(struct atiixp *chip)
1553 if (chip->irq < 0) 1553 if (chip->irq < 0)
1554 goto __hw_end; 1554 goto __hw_end;
1555 snd_atiixp_chip_stop(chip); 1555 snd_atiixp_chip_stop(chip);
1556 synchronize_irq(chip->irq); 1556
1557 __hw_end: 1557 __hw_end:
1558 if (chip->irq >= 0) 1558 if (chip->irq >= 0)
1559 free_irq(chip->irq, chip); 1559 free_irq(chip->irq, chip);
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index a67a869180d4..d457a32a7939 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -1197,7 +1197,7 @@ static int snd_atiixp_free(struct atiixp_modem *chip)
1197 if (chip->irq < 0) 1197 if (chip->irq < 0)
1198 goto __hw_end; 1198 goto __hw_end;
1199 snd_atiixp_chip_stop(chip); 1199 snd_atiixp_chip_stop(chip);
1200 synchronize_irq(chip->irq); 1200
1201 __hw_end: 1201 __hw_end:
1202 if (chip->irq >= 0) 1202 if (chip->irq >= 0)
1203 free_irq(chip->irq, chip); 1203 free_irq(chip->irq, chip);
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c
index 26819e2f5761..68368e490074 100644
--- a/sound/pci/au88x0/au88x0.c
+++ b/sound/pci/au88x0/au88x0.c
@@ -126,7 +126,6 @@ static int snd_vortex_dev_free(struct snd_device *device)
126 vortex_gameport_unregister(vortex); 126 vortex_gameport_unregister(vortex);
127 vortex_core_shutdown(vortex); 127 vortex_core_shutdown(vortex);
128 // Take down PCI interface. 128 // Take down PCI interface.
129 synchronize_irq(vortex->irq);
130 free_irq(vortex->irq, vortex); 129 free_irq(vortex->irq, vortex);
131 iounmap(vortex->mmio); 130 iounmap(vortex->mmio);
132 pci_release_regions(vortex->pci_dev); 131 pci_release_regions(vortex->pci_dev);
@@ -220,7 +219,6 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
220 return 0; 219 return 0;
221 220
222 alloc_out: 221 alloc_out:
223 synchronize_irq(chip->irq);
224 free_irq(chip->irq, chip); 222 free_irq(chip->irq, chip);
225 irq_out: 223 irq_out:
226 vortex_core_shutdown(chip); 224 vortex_core_shutdown(chip);
diff --git a/sound/pci/au88x0/au88x0_pcm.c b/sound/pci/au88x0/au88x0_pcm.c
index 526c6c5ecf7b..f9a58b4a30eb 100644
--- a/sound/pci/au88x0/au88x0_pcm.c
+++ b/sound/pci/au88x0/au88x0_pcm.c
@@ -498,14 +498,14 @@ static struct snd_kcontrol_new snd_vortex_mixer_spdif[] __devinitdata = {
498}; 498};
499 499
500/* create a pcm device */ 500/* create a pcm device */
501static int __devinit snd_vortex_new_pcm(vortex_t * chip, int idx, int nr) 501static int __devinit snd_vortex_new_pcm(vortex_t *chip, int idx, int nr)
502{ 502{
503 struct snd_pcm *pcm; 503 struct snd_pcm *pcm;
504 struct snd_kcontrol *kctl; 504 struct snd_kcontrol *kctl;
505 int i; 505 int i;
506 int err, nr_capt; 506 int err, nr_capt;
507 507
508 if ((chip == 0) || (idx < 0) || (idx >= VORTEX_PCM_LAST)) 508 if (!chip || idx < 0 || idx >= VORTEX_PCM_LAST)
509 return -ENODEV; 509 return -ENODEV;
510 510
511 /* idx indicates which kind of PCM device. ADB, SPDIF, I2S and A3D share the 511 /* idx indicates which kind of PCM device. ADB, SPDIF, I2S and A3D share the
@@ -514,9 +514,9 @@ static int __devinit snd_vortex_new_pcm(vortex_t * chip, int idx, int nr)
514 nr_capt = nr; 514 nr_capt = nr;
515 else 515 else
516 nr_capt = 0; 516 nr_capt = 0;
517 if ((err = 517 err = snd_pcm_new(chip->card, vortex_pcm_prettyname[idx], idx, nr,
518 snd_pcm_new(chip->card, vortex_pcm_prettyname[idx], idx, nr, 518 nr_capt, &pcm);
519 nr_capt, &pcm)) < 0) 519 if (err < 0)
520 return err; 520 return err;
521 strcpy(pcm->name, vortex_pcm_name[idx]); 521 strcpy(pcm->name, vortex_pcm_name[idx]);
522 chip->pcm[idx] = pcm; 522 chip->pcm[idx] = pcm;
diff --git a/sound/pci/aw2/Makefile b/sound/pci/aw2/Makefile
new file mode 100644
index 000000000000..842335d3b735
--- /dev/null
+++ b/sound/pci/aw2/Makefile
@@ -0,0 +1,3 @@
1snd-aw2-objs := aw2-alsa.o aw2-saa7146.o
2
3obj-$(CONFIG_SND_AW2) += snd-aw2.o
diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c
new file mode 100644
index 000000000000..56f87cd33c19
--- /dev/null
+++ b/sound/pci/aw2/aw2-alsa.c
@@ -0,0 +1,794 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23#include <linux/init.h>
24#include <linux/pci.h>
25#include <linux/dma-mapping.h>
26#include <linux/slab.h>
27#include <linux/interrupt.h>
28#include <linux/delay.h>
29#include <asm/io.h>
30#include <sound/core.h>
31#include <sound/initval.h>
32#include <sound/pcm.h>
33#include <sound/pcm_params.h>
34#include <sound/control.h>
35
36#include "saa7146.h"
37#include "aw2-saa7146.h"
38
39MODULE_AUTHOR("Cedric Bregardis <cedric.bregardis@free.fr>, "
40 "Jean-Christian Hassler <jhassler@free.fr>");
41MODULE_DESCRIPTION("Emagic Audiowerk 2 sound driver");
42MODULE_LICENSE("GPL");
43
44/*********************************
45 * DEFINES
46 ********************************/
47#define PCI_VENDOR_ID_SAA7146 0x1131
48#define PCI_DEVICE_ID_SAA7146 0x7146
49
50#define CTL_ROUTE_ANALOG 0
51#define CTL_ROUTE_DIGITAL 1
52
53/*********************************
54 * TYPEDEFS
55 ********************************/
56 /* hardware definition */
57static struct snd_pcm_hardware snd_aw2_playback_hw = {
58 .info = (SNDRV_PCM_INFO_MMAP |
59 SNDRV_PCM_INFO_INTERLEAVED |
60 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID),
61 .formats = SNDRV_PCM_FMTBIT_S16_LE,
62 .rates = SNDRV_PCM_RATE_44100,
63 .rate_min = 44100,
64 .rate_max = 44100,
65 .channels_min = 2,
66 .channels_max = 4,
67 .buffer_bytes_max = 32768,
68 .period_bytes_min = 4096,
69 .period_bytes_max = 32768,
70 .periods_min = 1,
71 .periods_max = 1024,
72};
73
74static struct snd_pcm_hardware snd_aw2_capture_hw = {
75 .info = (SNDRV_PCM_INFO_MMAP |
76 SNDRV_PCM_INFO_INTERLEAVED |
77 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID),
78 .formats = SNDRV_PCM_FMTBIT_S16_LE,
79 .rates = SNDRV_PCM_RATE_44100,
80 .rate_min = 44100,
81 .rate_max = 44100,
82 .channels_min = 2,
83 .channels_max = 2,
84 .buffer_bytes_max = 32768,
85 .period_bytes_min = 4096,
86 .period_bytes_max = 32768,
87 .periods_min = 1,
88 .periods_max = 1024,
89};
90
91struct aw2_pcm_device {
92 struct snd_pcm *pcm;
93 unsigned int stream_number;
94 struct aw2 *chip;
95};
96
97struct aw2 {
98 struct snd_aw2_saa7146 saa7146;
99
100 struct pci_dev *pci;
101 int irq;
102 spinlock_t reg_lock;
103 struct mutex mtx;
104
105 unsigned long iobase_phys;
106 void __iomem *iobase_virt;
107
108 struct snd_card *card;
109
110 struct aw2_pcm_device device_playback[NB_STREAM_PLAYBACK];
111 struct aw2_pcm_device device_capture[NB_STREAM_CAPTURE];
112};
113
114/*********************************
115 * FUNCTION DECLARATIONS
116 ********************************/
117static int __init alsa_card_aw2_init(void);
118static void __exit alsa_card_aw2_exit(void);
119static int snd_aw2_dev_free(struct snd_device *device);
120static int __devinit snd_aw2_create(struct snd_card *card,
121 struct pci_dev *pci, struct aw2 **rchip);
122static int __devinit snd_aw2_probe(struct pci_dev *pci,
123 const struct pci_device_id *pci_id);
124static void __devexit snd_aw2_remove(struct pci_dev *pci);
125static int snd_aw2_pcm_playback_open(struct snd_pcm_substream *substream);
126static int snd_aw2_pcm_playback_close(struct snd_pcm_substream *substream);
127static int snd_aw2_pcm_capture_open(struct snd_pcm_substream *substream);
128static int snd_aw2_pcm_capture_close(struct snd_pcm_substream *substream);
129static int snd_aw2_pcm_hw_params(struct snd_pcm_substream *substream,
130 struct snd_pcm_hw_params *hw_params);
131static int snd_aw2_pcm_hw_free(struct snd_pcm_substream *substream);
132static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream *substream);
133static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream);
134static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream *substream,
135 int cmd);
136static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream *substream,
137 int cmd);
138static snd_pcm_uframes_t snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
139 *substream);
140static snd_pcm_uframes_t snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
141 *substream);
142static int __devinit snd_aw2_new_pcm(struct aw2 *chip);
143
144static int snd_aw2_control_switch_capture_info(struct snd_kcontrol *kcontrol,
145 struct snd_ctl_elem_info *uinfo);
146static int snd_aw2_control_switch_capture_get(struct snd_kcontrol *kcontrol,
147 struct snd_ctl_elem_value
148 *ucontrol);
149static int snd_aw2_control_switch_capture_put(struct snd_kcontrol *kcontrol,
150 struct snd_ctl_elem_value
151 *ucontrol);
152
153/*********************************
154 * VARIABLES
155 ********************************/
156static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
157static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
158static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
159
160module_param_array(index, int, NULL, 0444);
161MODULE_PARM_DESC(index, "Index value for Audiowerk2 soundcard.");
162module_param_array(id, charp, NULL, 0444);
163MODULE_PARM_DESC(id, "ID string for the Audiowerk2 soundcard.");
164module_param_array(enable, bool, NULL, 0444);
165MODULE_PARM_DESC(enable, "Enable Audiowerk2 soundcard.");
166
167static struct pci_device_id snd_aw2_ids[] = {
168 {PCI_VENDOR_ID_SAA7146, PCI_DEVICE_ID_SAA7146, PCI_ANY_ID, PCI_ANY_ID,
169 0, 0, 0},
170 {0}
171};
172
173MODULE_DEVICE_TABLE(pci, snd_aw2_ids);
174
175/* pci_driver definition */
176static struct pci_driver driver = {
177 .name = "Emagic Audiowerk 2",
178 .id_table = snd_aw2_ids,
179 .probe = snd_aw2_probe,
180 .remove = __devexit_p(snd_aw2_remove),
181};
182
183/* operators for playback PCM alsa interface */
184static struct snd_pcm_ops snd_aw2_playback_ops = {
185 .open = snd_aw2_pcm_playback_open,
186 .close = snd_aw2_pcm_playback_close,
187 .ioctl = snd_pcm_lib_ioctl,
188 .hw_params = snd_aw2_pcm_hw_params,
189 .hw_free = snd_aw2_pcm_hw_free,
190 .prepare = snd_aw2_pcm_prepare_playback,
191 .trigger = snd_aw2_pcm_trigger_playback,
192 .pointer = snd_aw2_pcm_pointer_playback,
193};
194
195/* operators for capture PCM alsa interface */
196static struct snd_pcm_ops snd_aw2_capture_ops = {
197 .open = snd_aw2_pcm_capture_open,
198 .close = snd_aw2_pcm_capture_close,
199 .ioctl = snd_pcm_lib_ioctl,
200 .hw_params = snd_aw2_pcm_hw_params,
201 .hw_free = snd_aw2_pcm_hw_free,
202 .prepare = snd_aw2_pcm_prepare_capture,
203 .trigger = snd_aw2_pcm_trigger_capture,
204 .pointer = snd_aw2_pcm_pointer_capture,
205};
206
207static struct snd_kcontrol_new aw2_control __devinitdata = {
208 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
209 .name = "PCM Capture Route",
210 .index = 0,
211 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
212 .private_value = 0xffff,
213 .info = snd_aw2_control_switch_capture_info,
214 .get = snd_aw2_control_switch_capture_get,
215 .put = snd_aw2_control_switch_capture_put
216};
217
218/*********************************
219 * FUNCTION IMPLEMENTATIONS
220 ********************************/
221
222/* initialization of the module */
223static int __init alsa_card_aw2_init(void)
224{
225 snd_printdd(KERN_DEBUG "aw2: Load aw2 module\n");
226 return pci_register_driver(&driver);
227}
228
229/* clean up the module */
230static void __exit alsa_card_aw2_exit(void)
231{
232 snd_printdd(KERN_DEBUG "aw2: Unload aw2 module\n");
233 pci_unregister_driver(&driver);
234}
235
236module_init(alsa_card_aw2_init);
237module_exit(alsa_card_aw2_exit);
238
239/* component-destructor */
240static int snd_aw2_dev_free(struct snd_device *device)
241{
242 struct aw2 *chip = device->device_data;
243
244 /* Free hardware */
245 snd_aw2_saa7146_free(&chip->saa7146);
246
247 /* release the irq */
248 if (chip->irq >= 0)
249 free_irq(chip->irq, (void *)chip);
250 /* release the i/o ports & memory */
251 if (chip->iobase_virt)
252 iounmap(chip->iobase_virt);
253
254 pci_release_regions(chip->pci);
255 /* disable the PCI entry */
256 pci_disable_device(chip->pci);
257 /* release the data */
258 kfree(chip);
259
260 return 0;
261}
262
263/* chip-specific constructor */
264static int __devinit snd_aw2_create(struct snd_card *card,
265 struct pci_dev *pci, struct aw2 **rchip)
266{
267 struct aw2 *chip;
268 int err;
269 static struct snd_device_ops ops = {
270 .dev_free = snd_aw2_dev_free,
271 };
272
273 *rchip = NULL;
274
275 /* initialize the PCI entry */
276 err = pci_enable_device(pci);
277 if (err < 0)
278 return err;
279 pci_set_master(pci);
280
281 /* check PCI availability (32bit DMA) */
282 if ((pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0) ||
283 (pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0)) {
284 printk(KERN_ERR "aw2: Impossible to set 32bit mask DMA\n");
285 pci_disable_device(pci);
286 return -ENXIO;
287 }
288 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
289 if (chip == NULL) {
290 pci_disable_device(pci);
291 return -ENOMEM;
292 }
293
294 /* initialize the stuff */
295 chip->card = card;
296 chip->pci = pci;
297 chip->irq = -1;
298
299 /* (1) PCI resource allocation */
300 err = pci_request_regions(pci, "Audiowerk2");
301 if (err < 0) {
302 pci_disable_device(pci);
303 kfree(chip);
304 return err;
305 }
306 chip->iobase_phys = pci_resource_start(pci, 0);
307 chip->iobase_virt =
308 ioremap_nocache(chip->iobase_phys,
309 pci_resource_len(pci, 0));
310
311 if (chip->iobase_virt == NULL) {
312 printk(KERN_ERR "aw2: unable to remap memory region");
313 pci_release_regions(pci);
314 pci_disable_device(pci);
315 kfree(chip);
316 return -ENOMEM;
317 }
318
319
320 if (request_irq(pci->irq, snd_aw2_saa7146_interrupt,
321 IRQF_SHARED, "Audiowerk2", chip)) {
322 printk(KERN_ERR "aw2: Cannot grab irq %d\n", pci->irq);
323
324 iounmap(chip->iobase_virt);
325 pci_release_regions(chip->pci);
326 pci_disable_device(chip->pci);
327 kfree(chip);
328 return -EBUSY;
329 }
330 chip->irq = pci->irq;
331
332 /* (2) initialization of the chip hardware */
333 snd_aw2_saa7146_setup(&chip->saa7146, chip->iobase_virt);
334 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
335 if (err < 0) {
336 free_irq(chip->irq, (void *)chip);
337 iounmap(chip->iobase_virt);
338 pci_release_regions(chip->pci);
339 pci_disable_device(chip->pci);
340 kfree(chip);
341 return err;
342 }
343
344 snd_card_set_dev(card, &pci->dev);
345 *rchip = chip;
346
347 printk(KERN_INFO
348 "Audiowerk 2 sound card (saa7146 chipset) detected and "
349 "managed\n");
350 return 0;
351}
352
353/* constructor */
354static int __devinit snd_aw2_probe(struct pci_dev *pci,
355 const struct pci_device_id *pci_id)
356{
357 static int dev;
358 struct snd_card *card;
359 struct aw2 *chip;
360 int err;
361
362 /* (1) Continue if device is not enabled, else inc dev */
363 if (dev >= SNDRV_CARDS)
364 return -ENODEV;
365 if (!enable[dev]) {
366 dev++;
367 return -ENOENT;
368 }
369
370 /* (2) Create card instance */
371 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
372 if (card == NULL)
373 return -ENOMEM;
374
375 /* (3) Create main component */
376 err = snd_aw2_create(card, pci, &chip);
377 if (err < 0) {
378 snd_card_free(card);
379 return err;
380 }
381
382 /* initialize mutex */
383 mutex_init(&chip->mtx);
384 /* init spinlock */
385 spin_lock_init(&chip->reg_lock);
386 /* (4) Define driver ID and name string */
387 strcpy(card->driver, "aw2");
388 strcpy(card->shortname, "Audiowerk2");
389
390 sprintf(card->longname, "%s with SAA7146 irq %i",
391 card->shortname, chip->irq);
392
393 /* (5) Create other components */
394 snd_aw2_new_pcm(chip);
395
396 /* (6) Register card instance */
397 err = snd_card_register(card);
398 if (err < 0) {
399 snd_card_free(card);
400 return err;
401 }
402
403 /* (7) Set PCI driver data */
404 pci_set_drvdata(pci, card);
405
406 dev++;
407 return 0;
408}
409
410/* destructor */
411static void __devexit snd_aw2_remove(struct pci_dev *pci)
412{
413 snd_card_free(pci_get_drvdata(pci));
414 pci_set_drvdata(pci, NULL);
415}
416
417/* open callback */
418static int snd_aw2_pcm_playback_open(struct snd_pcm_substream *substream)
419{
420 struct snd_pcm_runtime *runtime = substream->runtime;
421
422 snd_printdd(KERN_DEBUG "aw2: Playback_open \n");
423 runtime->hw = snd_aw2_playback_hw;
424 return 0;
425}
426
427/* close callback */
428static int snd_aw2_pcm_playback_close(struct snd_pcm_substream *substream)
429{
430 return 0;
431
432}
433
434static int snd_aw2_pcm_capture_open(struct snd_pcm_substream *substream)
435{
436 struct snd_pcm_runtime *runtime = substream->runtime;
437
438 snd_printdd(KERN_DEBUG "aw2: Capture_open \n");
439 runtime->hw = snd_aw2_capture_hw;
440 return 0;
441}
442
443/* close callback */
444static int snd_aw2_pcm_capture_close(struct snd_pcm_substream *substream)
445{
446 /* TODO: something to do ? */
447 return 0;
448}
449
450 /* hw_params callback */
451static int snd_aw2_pcm_hw_params(struct snd_pcm_substream *substream,
452 struct snd_pcm_hw_params *hw_params)
453{
454 return snd_pcm_lib_malloc_pages(substream,
455 params_buffer_bytes(hw_params));
456}
457
458/* hw_free callback */
459static int snd_aw2_pcm_hw_free(struct snd_pcm_substream *substream)
460{
461 return snd_pcm_lib_free_pages(substream);
462}
463
464/* prepare callback for playback */
465static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream *substream)
466{
467 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
468 struct aw2 *chip = pcm_device->chip;
469 struct snd_pcm_runtime *runtime = substream->runtime;
470 unsigned long period_size, buffer_size;
471
472 mutex_lock(&chip->mtx);
473
474 period_size = snd_pcm_lib_period_bytes(substream);
475 buffer_size = snd_pcm_lib_buffer_bytes(substream);
476
477 snd_aw2_saa7146_pcm_init_playback(&chip->saa7146,
478 pcm_device->stream_number,
479 runtime->dma_addr, period_size,
480 buffer_size);
481
482 /* Define Interrupt callback */
483 snd_aw2_saa7146_define_it_playback_callback(pcm_device->stream_number,
484 (snd_aw2_saa7146_it_cb)
485 snd_pcm_period_elapsed,
486 (void *)substream);
487
488 mutex_unlock(&chip->mtx);
489
490 return 0;
491}
492
493/* prepare callback for capture */
494static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream)
495{
496 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
497 struct aw2 *chip = pcm_device->chip;
498 struct snd_pcm_runtime *runtime = substream->runtime;
499 unsigned long period_size, buffer_size;
500
501 mutex_lock(&chip->mtx);
502
503 period_size = snd_pcm_lib_period_bytes(substream);
504 buffer_size = snd_pcm_lib_buffer_bytes(substream);
505
506 snd_aw2_saa7146_pcm_init_capture(&chip->saa7146,
507 pcm_device->stream_number,
508 runtime->dma_addr, period_size,
509 buffer_size);
510
511 /* Define Interrupt callback */
512 snd_aw2_saa7146_define_it_capture_callback(pcm_device->stream_number,
513 (snd_aw2_saa7146_it_cb)
514 snd_pcm_period_elapsed,
515 (void *)substream);
516
517 mutex_unlock(&chip->mtx);
518
519 return 0;
520}
521
522/* playback trigger callback */
523static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream *substream,
524 int cmd)
525{
526 int status = 0;
527 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
528 struct aw2 *chip = pcm_device->chip;
529 spin_lock(&chip->reg_lock);
530 switch (cmd) {
531 case SNDRV_PCM_TRIGGER_START:
532 snd_aw2_saa7146_pcm_trigger_start_playback(&chip->saa7146,
533 pcm_device->
534 stream_number);
535 break;
536 case SNDRV_PCM_TRIGGER_STOP:
537 snd_aw2_saa7146_pcm_trigger_stop_playback(&chip->saa7146,
538 pcm_device->
539 stream_number);
540 break;
541 default:
542 status = -EINVAL;
543 }
544 spin_unlock(&chip->reg_lock);
545 return status;
546}
547
548/* capture trigger callback */
549static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream *substream,
550 int cmd)
551{
552 int status = 0;
553 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
554 struct aw2 *chip = pcm_device->chip;
555 spin_lock(&chip->reg_lock);
556 switch (cmd) {
557 case SNDRV_PCM_TRIGGER_START:
558 snd_aw2_saa7146_pcm_trigger_start_capture(&chip->saa7146,
559 pcm_device->
560 stream_number);
561 break;
562 case SNDRV_PCM_TRIGGER_STOP:
563 snd_aw2_saa7146_pcm_trigger_stop_capture(&chip->saa7146,
564 pcm_device->
565 stream_number);
566 break;
567 default:
568 status = -EINVAL;
569 }
570 spin_unlock(&chip->reg_lock);
571 return status;
572}
573
574/* playback pointer callback */
575static snd_pcm_uframes_t snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
576 *substream)
577{
578 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
579 struct aw2 *chip = pcm_device->chip;
580 unsigned int current_ptr;
581
582 /* get the current hardware pointer */
583 struct snd_pcm_runtime *runtime = substream->runtime;
584 current_ptr =
585 snd_aw2_saa7146_get_hw_ptr_playback(&chip->saa7146,
586 pcm_device->stream_number,
587 runtime->dma_area,
588 runtime->buffer_size);
589
590 return bytes_to_frames(substream->runtime, current_ptr);
591}
592
593/* capture pointer callback */
594static snd_pcm_uframes_t snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
595 *substream)
596{
597 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
598 struct aw2 *chip = pcm_device->chip;
599 unsigned int current_ptr;
600
601 /* get the current hardware pointer */
602 struct snd_pcm_runtime *runtime = substream->runtime;
603 current_ptr =
604 snd_aw2_saa7146_get_hw_ptr_capture(&chip->saa7146,
605 pcm_device->stream_number,
606 runtime->dma_area,
607 runtime->buffer_size);
608
609 return bytes_to_frames(substream->runtime, current_ptr);
610}
611
612/* create a pcm device */
613static int __devinit snd_aw2_new_pcm(struct aw2 *chip)
614{
615 struct snd_pcm *pcm_playback_ana;
616 struct snd_pcm *pcm_playback_num;
617 struct snd_pcm *pcm_capture;
618 struct aw2_pcm_device *pcm_device;
619 int err = 0;
620
621 /* Create new Alsa PCM device */
622
623 err = snd_pcm_new(chip->card, "Audiowerk2 analog playback", 0, 1, 0,
624 &pcm_playback_ana);
625 if (err < 0) {
626 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err);
627 return err;
628 }
629
630 /* Creation ok */
631 pcm_device = &chip->device_playback[NUM_STREAM_PLAYBACK_ANA];
632
633 /* Set PCM device name */
634 strcpy(pcm_playback_ana->name, "Analog playback");
635 /* Associate private data to PCM device */
636 pcm_playback_ana->private_data = pcm_device;
637 /* set operators of PCM device */
638 snd_pcm_set_ops(pcm_playback_ana, SNDRV_PCM_STREAM_PLAYBACK,
639 &snd_aw2_playback_ops);
640 /* store PCM device */
641 pcm_device->pcm = pcm_playback_ana;
642 /* give base chip pointer to our internal pcm device
643 structure */
644 pcm_device->chip = chip;
645 /* Give stream number to PCM device */
646 pcm_device->stream_number = NUM_STREAM_PLAYBACK_ANA;
647
648 /* pre-allocation of buffers */
649 /* Preallocate continuous pages. */
650 err = snd_pcm_lib_preallocate_pages_for_all(pcm_playback_ana,
651 SNDRV_DMA_TYPE_DEV,
652 snd_dma_pci_data
653 (chip->pci),
654 64 * 1024, 64 * 1024);
655 if (err)
656 printk(KERN_ERR "aw2: snd_pcm_lib_preallocate_pages_for_all "
657 "error (0x%X)\n", err);
658
659 err = snd_pcm_new(chip->card, "Audiowerk2 digital playback", 1, 1, 0,
660 &pcm_playback_num);
661
662 if (err < 0) {
663 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err);
664 return err;
665 }
666 /* Creation ok */
667 pcm_device = &chip->device_playback[NUM_STREAM_PLAYBACK_DIG];
668
669 /* Set PCM device name */
670 strcpy(pcm_playback_num->name, "Digital playback");
671 /* Associate private data to PCM device */
672 pcm_playback_num->private_data = pcm_device;
673 /* set operators of PCM device */
674 snd_pcm_set_ops(pcm_playback_num, SNDRV_PCM_STREAM_PLAYBACK,
675 &snd_aw2_playback_ops);
676 /* store PCM device */
677 pcm_device->pcm = pcm_playback_num;
678 /* give base chip pointer to our internal pcm device
679 structure */
680 pcm_device->chip = chip;
681 /* Give stream number to PCM device */
682 pcm_device->stream_number = NUM_STREAM_PLAYBACK_DIG;
683
684 /* pre-allocation of buffers */
685 /* Preallocate continuous pages. */
686 err = snd_pcm_lib_preallocate_pages_for_all(pcm_playback_num,
687 SNDRV_DMA_TYPE_DEV,
688 snd_dma_pci_data
689 (chip->pci),
690 64 * 1024, 64 * 1024);
691 if (err)
692 printk(KERN_ERR
693 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
694 "(0x%X)\n", err);
695
696
697
698 err = snd_pcm_new(chip->card, "Audiowerk2 capture", 2, 0, 1,
699 &pcm_capture);
700
701 if (err < 0) {
702 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err);
703 return err;
704 }
705
706 /* Creation ok */
707 pcm_device = &chip->device_capture[NUM_STREAM_CAPTURE_ANA];
708
709 /* Set PCM device name */
710 strcpy(pcm_capture->name, "Capture");
711 /* Associate private data to PCM device */
712 pcm_capture->private_data = pcm_device;
713 /* set operators of PCM device */
714 snd_pcm_set_ops(pcm_capture, SNDRV_PCM_STREAM_CAPTURE,
715 &snd_aw2_capture_ops);
716 /* store PCM device */
717 pcm_device->pcm = pcm_capture;
718 /* give base chip pointer to our internal pcm device
719 structure */
720 pcm_device->chip = chip;
721 /* Give stream number to PCM device */
722 pcm_device->stream_number = NUM_STREAM_CAPTURE_ANA;
723
724 /* pre-allocation of buffers */
725 /* Preallocate continuous pages. */
726 err = snd_pcm_lib_preallocate_pages_for_all(pcm_capture,
727 SNDRV_DMA_TYPE_DEV,
728 snd_dma_pci_data
729 (chip->pci),
730 64 * 1024, 64 * 1024);
731 if (err)
732 printk(KERN_ERR
733 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
734 "(0x%X)\n", err);
735
736
737 /* Create control */
738 err = snd_ctl_add(chip->card, snd_ctl_new1(&aw2_control, chip));
739 if (err < 0) {
740 printk(KERN_ERR "aw2: snd_ctl_add error (0x%X)\n", err);
741 return err;
742 }
743
744 return 0;
745}
746
747static int snd_aw2_control_switch_capture_info(struct snd_kcontrol *kcontrol,
748 struct snd_ctl_elem_info *uinfo)
749{
750 static char *texts[2] = {
751 "Analog", "Digital"
752 };
753 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
754 uinfo->count = 1;
755 uinfo->value.enumerated.items = 2;
756 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) {
757 uinfo->value.enumerated.item =
758 uinfo->value.enumerated.items - 1;
759 }
760 strcpy(uinfo->value.enumerated.name,
761 texts[uinfo->value.enumerated.item]);
762 return 0;
763}
764
765static int snd_aw2_control_switch_capture_get(struct snd_kcontrol *kcontrol,
766 struct snd_ctl_elem_value
767 *ucontrol)
768{
769 struct aw2 *chip = snd_kcontrol_chip(kcontrol);
770 if (snd_aw2_saa7146_is_using_digital_input(&chip->saa7146))
771 ucontrol->value.enumerated.item[0] = CTL_ROUTE_DIGITAL;
772 else
773 ucontrol->value.enumerated.item[0] = CTL_ROUTE_ANALOG;
774 return 0;
775}
776
777static int snd_aw2_control_switch_capture_put(struct snd_kcontrol *kcontrol,
778 struct snd_ctl_elem_value
779 *ucontrol)
780{
781 struct aw2 *chip = snd_kcontrol_chip(kcontrol);
782 int changed = 0;
783 int is_disgital =
784 snd_aw2_saa7146_is_using_digital_input(&chip->saa7146);
785
786 if (((ucontrol->value.integer.value[0] == CTL_ROUTE_DIGITAL)
787 && !is_disgital)
788 || ((ucontrol->value.integer.value[0] == CTL_ROUTE_ANALOG)
789 && is_disgital)) {
790 snd_aw2_saa7146_use_digital_input(&chip->saa7146, !is_disgital);
791 changed = 1;
792 }
793 return changed;
794}
diff --git a/sound/pci/aw2/aw2-saa7146.c b/sound/pci/aw2/aw2-saa7146.c
new file mode 100644
index 000000000000..6a3891ab69dd
--- /dev/null
+++ b/sound/pci/aw2/aw2-saa7146.c
@@ -0,0 +1,465 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23
24#define AW2_SAA7146_M
25
26#include <linux/init.h>
27#include <linux/pci.h>
28#include <linux/slab.h>
29#include <linux/interrupt.h>
30#include <linux/delay.h>
31#include <asm/system.h>
32#include <asm/io.h>
33#include <sound/core.h>
34#include <sound/initval.h>
35#include <sound/pcm.h>
36#include <sound/pcm_params.h>
37
38#include "saa7146.h"
39#include "aw2-saa7146.h"
40
41#include "aw2-tsl.c"
42
43#define WRITEREG(value, addr) writel((value), chip->base_addr + (addr))
44#define READREG(addr) readl(chip->base_addr + (addr))
45
46static struct snd_aw2_saa7146_cb_param
47 arr_substream_it_playback_cb[NB_STREAM_PLAYBACK];
48static struct snd_aw2_saa7146_cb_param
49 arr_substream_it_capture_cb[NB_STREAM_CAPTURE];
50
51static int snd_aw2_saa7146_get_limit(int size);
52
53/* chip-specific destructor */
54int snd_aw2_saa7146_free(struct snd_aw2_saa7146 *chip)
55{
56 /* disable all irqs */
57 WRITEREG(0, IER);
58
59 /* reset saa7146 */
60 WRITEREG((MRST_N << 16), MC1);
61
62 /* Unset base addr */
63 chip->base_addr = NULL;
64
65 return 0;
66}
67
68void snd_aw2_saa7146_setup(struct snd_aw2_saa7146 *chip,
69 void __iomem *pci_base_addr)
70{
71 /* set PCI burst/threshold
72
73 Burst length definition
74 VALUE BURST LENGTH
75 000 1 Dword
76 001 2 Dwords
77 010 4 Dwords
78 011 8 Dwords
79 100 16 Dwords
80 101 32 Dwords
81 110 64 Dwords
82 111 128 Dwords
83
84 Threshold definition
85 VALUE WRITE MODE READ MODE
86 00 1 Dword of valid data 1 empty Dword
87 01 4 Dwords of valid data 4 empty Dwords
88 10 8 Dwords of valid data 8 empty Dwords
89 11 16 Dwords of valid data 16 empty Dwords */
90
91 unsigned int acon2;
92 unsigned int acon1 = 0;
93 int i;
94
95 /* Set base addr */
96 chip->base_addr = pci_base_addr;
97
98 /* disable all irqs */
99 WRITEREG(0, IER);
100
101 /* reset saa7146 */
102 WRITEREG((MRST_N << 16), MC1);
103
104 /* enable audio interface */
105#ifdef __BIG_ENDIAN
106 acon1 |= A1_SWAP;
107 acon1 |= A2_SWAP;
108#endif
109 /* WS0_CTRL, WS0_SYNC: input TSL1, I2S */
110
111 /* At initialization WS1 and WS2 are disbaled (configured as input */
112 acon1 |= 0 * WS1_CTRL;
113 acon1 |= 0 * WS2_CTRL;
114
115 /* WS4 is not used. So it must not restart A2.
116 This is why it is configured as output (force to low) */
117 acon1 |= 3 * WS4_CTRL;
118
119 /* WS3_CTRL, WS3_SYNC: output TSL2, I2S */
120 acon1 |= 2 * WS3_CTRL;
121
122 /* A1 and A2 are active and asynchronous */
123 acon1 |= 3 * AUDIO_MODE;
124 WRITEREG(acon1, ACON1);
125
126 /* The following comes from original windows driver.
127 It is needed to have a correct behavior of input and output
128 simultenously, but I don't know why ! */
129 WRITEREG(3 * (BurstA1_in) + 3 * (ThreshA1_in) +
130 3 * (BurstA1_out) + 3 * (ThreshA1_out) +
131 3 * (BurstA2_out) + 3 * (ThreshA2_out), PCI_BT_A);
132
133 /* enable audio port pins */
134 WRITEREG((EAP << 16) | EAP, MC1);
135
136 /* enable I2C */
137 WRITEREG((EI2C << 16) | EI2C, MC1);
138 /* enable interrupts */
139 WRITEREG(A1_out | A2_out | A1_in | IIC_S | IIC_E, IER);
140
141 /* audio configuration */
142 acon2 = A2_CLKSRC | BCLK1_OEN;
143 WRITEREG(acon2, ACON2);
144
145 /* By default use analog input */
146 snd_aw2_saa7146_use_digital_input(chip, 0);
147
148 /* TSL setup */
149 for (i = 0; i < 8; ++i) {
150 WRITEREG(tsl1[i], TSL1 + (i * 4));
151 WRITEREG(tsl2[i], TSL2 + (i * 4));
152 }
153
154}
155
156void snd_aw2_saa7146_pcm_init_playback(struct snd_aw2_saa7146 *chip,
157 int stream_number,
158 unsigned long dma_addr,
159 unsigned long period_size,
160 unsigned long buffer_size)
161{
162 unsigned long dw_page, dw_limit;
163
164 /* Configure DMA for substream
165 Configuration informations: ALSA has allocated continuous memory
166 pages. So we don't need to use MMU of saa7146.
167 */
168
169 /* No MMU -> nothing to do with PageA1, we only configure the limit of
170 PageAx_out register */
171 /* Disable MMU */
172 dw_page = (0L << 11);
173
174 /* Configure Limit for DMA access.
175 The limit register defines an address limit, which generates
176 an interrupt if passed by the actual PCI address pointer.
177 '0001' means an interrupt will be generated if the lower
178 6 bits (64 bytes) of the PCI address are zero. '0010'
179 defines a limit of 128 bytes, '0011' one of 256 bytes, and
180 so on up to 1 Mbyte defined by '1111'. This interrupt range
181 can be calculated as follows:
182 Range = 2^(5 + Limit) bytes.
183 */
184 dw_limit = snd_aw2_saa7146_get_limit(period_size);
185 dw_page |= (dw_limit << 4);
186
187 if (stream_number == 0) {
188 WRITEREG(dw_page, PageA2_out);
189
190 /* Base address for DMA transfert. */
191 /* This address has been reserved by ALSA. */
192 /* This is a physical address */
193 WRITEREG(dma_addr, BaseA2_out);
194
195 /* Define upper limit for DMA access */
196 WRITEREG(dma_addr + buffer_size, ProtA2_out);
197
198 } else if (stream_number == 1) {
199 WRITEREG(dw_page, PageA1_out);
200
201 /* Base address for DMA transfert. */
202 /* This address has been reserved by ALSA. */
203 /* This is a physical address */
204 WRITEREG(dma_addr, BaseA1_out);
205
206 /* Define upper limit for DMA access */
207 WRITEREG(dma_addr + buffer_size, ProtA1_out);
208 } else {
209 printk(KERN_ERR
210 "aw2: snd_aw2_saa7146_pcm_init_playback: "
211 "Substream number is not 0 or 1 -> not managed\n");
212 }
213}
214
215void snd_aw2_saa7146_pcm_init_capture(struct snd_aw2_saa7146 *chip,
216 int stream_number, unsigned long dma_addr,
217 unsigned long period_size,
218 unsigned long buffer_size)
219{
220 unsigned long dw_page, dw_limit;
221
222 /* Configure DMA for substream
223 Configuration informations: ALSA has allocated continuous memory
224 pages. So we don't need to use MMU of saa7146.
225 */
226
227 /* No MMU -> nothing to do with PageA1, we only configure the limit of
228 PageAx_out register */
229 /* Disable MMU */
230 dw_page = (0L << 11);
231
232 /* Configure Limit for DMA access.
233 The limit register defines an address limit, which generates
234 an interrupt if passed by the actual PCI address pointer.
235 '0001' means an interrupt will be generated if the lower
236 6 bits (64 bytes) of the PCI address are zero. '0010'
237 defines a limit of 128 bytes, '0011' one of 256 bytes, and
238 so on up to 1 Mbyte defined by '1111'. This interrupt range
239 can be calculated as follows:
240 Range = 2^(5 + Limit) bytes.
241 */
242 dw_limit = snd_aw2_saa7146_get_limit(period_size);
243 dw_page |= (dw_limit << 4);
244
245 if (stream_number == 0) {
246 WRITEREG(dw_page, PageA1_in);
247
248 /* Base address for DMA transfert. */
249 /* This address has been reserved by ALSA. */
250 /* This is a physical address */
251 WRITEREG(dma_addr, BaseA1_in);
252
253 /* Define upper limit for DMA access */
254 WRITEREG(dma_addr + buffer_size, ProtA1_in);
255 } else {
256 printk(KERN_ERR
257 "aw2: snd_aw2_saa7146_pcm_init_capture: "
258 "Substream number is not 0 -> not managed\n");
259 }
260}
261
262void snd_aw2_saa7146_define_it_playback_callback(unsigned int stream_number,
263 snd_aw2_saa7146_it_cb
264 p_it_callback,
265 void *p_callback_param)
266{
267 if (stream_number < NB_STREAM_PLAYBACK) {
268 arr_substream_it_playback_cb[stream_number].p_it_callback =
269 (snd_aw2_saa7146_it_cb) p_it_callback;
270 arr_substream_it_playback_cb[stream_number].p_callback_param =
271 (void *)p_callback_param;
272 }
273}
274
275void snd_aw2_saa7146_define_it_capture_callback(unsigned int stream_number,
276 snd_aw2_saa7146_it_cb
277 p_it_callback,
278 void *p_callback_param)
279{
280 if (stream_number < NB_STREAM_CAPTURE) {
281 arr_substream_it_capture_cb[stream_number].p_it_callback =
282 (snd_aw2_saa7146_it_cb) p_it_callback;
283 arr_substream_it_capture_cb[stream_number].p_callback_param =
284 (void *)p_callback_param;
285 }
286}
287
288void snd_aw2_saa7146_pcm_trigger_start_playback(struct snd_aw2_saa7146 *chip,
289 int stream_number)
290{
291 unsigned int acon1 = 0;
292 /* In aw8 driver, dma transfert is always active. It is
293 started and stopped in a larger "space" */
294 acon1 = READREG(ACON1);
295 if (stream_number == 0) {
296 WRITEREG((TR_E_A2_OUT << 16) | TR_E_A2_OUT, MC1);
297
298 /* WS2_CTRL, WS2_SYNC: output TSL2, I2S */
299 acon1 |= 2 * WS2_CTRL;
300 WRITEREG(acon1, ACON1);
301
302 } else if (stream_number == 1) {
303 WRITEREG((TR_E_A1_OUT << 16) | TR_E_A1_OUT, MC1);
304
305 /* WS1_CTRL, WS1_SYNC: output TSL1, I2S */
306 acon1 |= 1 * WS1_CTRL;
307 WRITEREG(acon1, ACON1);
308 }
309}
310
311void snd_aw2_saa7146_pcm_trigger_stop_playback(struct snd_aw2_saa7146 *chip,
312 int stream_number)
313{
314 unsigned int acon1 = 0;
315 acon1 = READREG(ACON1);
316 if (stream_number == 0) {
317 /* WS2_CTRL, WS2_SYNC: output TSL2, I2S */
318 acon1 &= ~(3 * WS2_CTRL);
319 WRITEREG(acon1, ACON1);
320
321 WRITEREG((TR_E_A2_OUT << 16), MC1);
322 } else if (stream_number == 1) {
323 /* WS1_CTRL, WS1_SYNC: output TSL1, I2S */
324 acon1 &= ~(3 * WS1_CTRL);
325 WRITEREG(acon1, ACON1);
326
327 WRITEREG((TR_E_A1_OUT << 16), MC1);
328 }
329}
330
331void snd_aw2_saa7146_pcm_trigger_start_capture(struct snd_aw2_saa7146 *chip,
332 int stream_number)
333{
334 /* In aw8 driver, dma transfert is always active. It is
335 started and stopped in a larger "space" */
336 if (stream_number == 0)
337 WRITEREG((TR_E_A1_IN << 16) | TR_E_A1_IN, MC1);
338}
339
340void snd_aw2_saa7146_pcm_trigger_stop_capture(struct snd_aw2_saa7146 *chip,
341 int stream_number)
342{
343 if (stream_number == 0)
344 WRITEREG((TR_E_A1_IN << 16), MC1);
345}
346
347irqreturn_t snd_aw2_saa7146_interrupt(int irq, void *dev_id)
348{
349 unsigned int isr;
350 unsigned int iicsta;
351 struct snd_aw2_saa7146 *chip = dev_id;
352
353 isr = READREG(ISR);
354 if (!isr)
355 return IRQ_NONE;
356
357 WRITEREG(isr, ISR);
358
359 if (isr & (IIC_S | IIC_E)) {
360 iicsta = READREG(IICSTA);
361 WRITEREG(0x100, IICSTA);
362 }
363
364 if (isr & A1_out) {
365 if (arr_substream_it_playback_cb[1].p_it_callback != NULL) {
366 arr_substream_it_playback_cb[1].
367 p_it_callback(arr_substream_it_playback_cb[1].
368 p_callback_param);
369 }
370 }
371 if (isr & A2_out) {
372 if (arr_substream_it_playback_cb[0].p_it_callback != NULL) {
373 arr_substream_it_playback_cb[0].
374 p_it_callback(arr_substream_it_playback_cb[0].
375 p_callback_param);
376 }
377
378 }
379 if (isr & A1_in) {
380 if (arr_substream_it_capture_cb[0].p_it_callback != NULL) {
381 arr_substream_it_capture_cb[0].
382 p_it_callback(arr_substream_it_capture_cb[0].
383 p_callback_param);
384 }
385 }
386 return IRQ_HANDLED;
387}
388
389unsigned int snd_aw2_saa7146_get_hw_ptr_playback(struct snd_aw2_saa7146 *chip,
390 int stream_number,
391 unsigned char *start_addr,
392 unsigned int buffer_size)
393{
394 long pci_adp = 0;
395 size_t ptr = 0;
396
397 if (stream_number == 0) {
398 pci_adp = READREG(PCI_ADP3);
399 ptr = pci_adp - (long)start_addr;
400
401 if (ptr == buffer_size)
402 ptr = 0;
403 }
404 if (stream_number == 1) {
405 pci_adp = READREG(PCI_ADP1);
406 ptr = pci_adp - (size_t) start_addr;
407
408 if (ptr == buffer_size)
409 ptr = 0;
410 }
411 return ptr;
412}
413
414unsigned int snd_aw2_saa7146_get_hw_ptr_capture(struct snd_aw2_saa7146 *chip,
415 int stream_number,
416 unsigned char *start_addr,
417 unsigned int buffer_size)
418{
419 size_t pci_adp = 0;
420 size_t ptr = 0;
421 if (stream_number == 0) {
422 pci_adp = READREG(PCI_ADP2);
423 ptr = pci_adp - (size_t) start_addr;
424
425 if (ptr == buffer_size)
426 ptr = 0;
427 }
428 return ptr;
429}
430
431void snd_aw2_saa7146_use_digital_input(struct snd_aw2_saa7146 *chip,
432 int use_digital)
433{
434 /* FIXME: switch between analog and digital input does not always work.
435 It can produce a kind of white noise. It seams that received data
436 are inverted sometime (endian inversion). Why ? I don't know, maybe
437 a problem of synchronization... However for the time being I have
438 not found the problem. Workaround: switch again (and again) between
439 digital and analog input until it works. */
440 if (use_digital)
441 WRITEREG(0x40, GPIO_CTRL);
442 else
443 WRITEREG(0x50, GPIO_CTRL);
444}
445
446int snd_aw2_saa7146_is_using_digital_input(struct snd_aw2_saa7146 *chip)
447{
448 unsigned int reg_val = READREG(GPIO_CTRL);
449 if ((reg_val & 0xFF) == 0x40)
450 return 1;
451 else
452 return 0;
453}
454
455
456static int snd_aw2_saa7146_get_limit(int size)
457{
458 int limitsize = 32;
459 int limit = 0;
460 while (limitsize < size) {
461 limitsize *= 2;
462 limit++;
463 }
464 return limit;
465}
diff --git a/sound/pci/aw2/aw2-saa7146.h b/sound/pci/aw2/aw2-saa7146.h
new file mode 100644
index 000000000000..5b35e358937f
--- /dev/null
+++ b/sound/pci/aw2/aw2-saa7146.h
@@ -0,0 +1,105 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23
24#ifndef AW2_SAA7146_H
25#define AW2_SAA7146_H
26
27#define NB_STREAM_PLAYBACK 2
28#define NB_STREAM_CAPTURE 1
29
30#define NUM_STREAM_PLAYBACK_ANA 0
31#define NUM_STREAM_PLAYBACK_DIG 1
32
33#define NUM_STREAM_CAPTURE_ANA 0
34
35typedef void (*snd_aw2_saa7146_it_cb) (void *);
36
37struct snd_aw2_saa7146_cb_param {
38 snd_aw2_saa7146_it_cb p_it_callback;
39 void *p_callback_param;
40};
41
42/* definition of the chip-specific record */
43
44struct snd_aw2_saa7146 {
45 void __iomem *base_addr;
46};
47
48extern void snd_aw2_saa7146_setup(struct snd_aw2_saa7146 *chip,
49 void __iomem *pci_base_addr);
50extern int snd_aw2_saa7146_free(struct snd_aw2_saa7146 *chip);
51
52extern void snd_aw2_saa7146_pcm_init_playback(struct snd_aw2_saa7146 *chip,
53 int stream_number,
54 unsigned long dma_addr,
55 unsigned long period_size,
56 unsigned long buffer_size);
57extern void snd_aw2_saa7146_pcm_init_capture(struct snd_aw2_saa7146 *chip,
58 int stream_number,
59 unsigned long dma_addr,
60 unsigned long period_size,
61 unsigned long buffer_size);
62extern void snd_aw2_saa7146_define_it_playback_callback(unsigned int
63 stream_number,
64 snd_aw2_saa7146_it_cb
65 p_it_callback,
66 void *p_callback_param);
67extern void snd_aw2_saa7146_define_it_capture_callback(unsigned int
68 stream_number,
69 snd_aw2_saa7146_it_cb
70 p_it_callback,
71 void *p_callback_param);
72extern void snd_aw2_saa7146_pcm_trigger_start_capture(struct snd_aw2_saa7146
73 *chip, int stream_number);
74extern void snd_aw2_saa7146_pcm_trigger_stop_capture(struct snd_aw2_saa7146
75 *chip, int stream_number);
76
77extern void snd_aw2_saa7146_pcm_trigger_start_playback(struct snd_aw2_saa7146
78 *chip,
79 int stream_number);
80extern void snd_aw2_saa7146_pcm_trigger_stop_playback(struct snd_aw2_saa7146
81 *chip, int stream_number);
82
83extern irqreturn_t snd_aw2_saa7146_interrupt(int irq, void *dev_id);
84extern unsigned int snd_aw2_saa7146_get_hw_ptr_playback(struct snd_aw2_saa7146
85 *chip,
86 int stream_number,
87 unsigned char
88 *start_addr,
89 unsigned int
90 buffer_size);
91extern unsigned int snd_aw2_saa7146_get_hw_ptr_capture(struct snd_aw2_saa7146
92 *chip,
93 int stream_number,
94 unsigned char
95 *start_addr,
96 unsigned int
97 buffer_size);
98
99extern void snd_aw2_saa7146_use_digital_input(struct snd_aw2_saa7146 *chip,
100 int use_digital);
101
102extern int snd_aw2_saa7146_is_using_digital_input(struct snd_aw2_saa7146
103 *chip);
104
105#endif
diff --git a/sound/pci/aw2/aw2-tsl.c b/sound/pci/aw2/aw2-tsl.c
new file mode 100644
index 000000000000..459b0311ea31
--- /dev/null
+++ b/sound/pci/aw2/aw2-tsl.c
@@ -0,0 +1,110 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 * Copyright 1998 Emagic Soft- und Hardware GmbH
6 * Copyright 2002 Martijn Sipkema
7 *
8 * This file is part of the Audiowerk2 ALSA driver
9 *
10 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.
13 *
14 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 * USA.
23 *
24 *****************************************************************************/
25
26#define TSL_WS0 (1UL << 31)
27#define TSL_WS1 (1UL << 30)
28#define TSL_WS2 (1UL << 29)
29#define TSL_WS3 (1UL << 28)
30#define TSL_WS4 (1UL << 27)
31#define TSL_DIS_A1 (1UL << 24)
32#define TSL_SDW_A1 (1UL << 23)
33#define TSL_SIB_A1 (1UL << 22)
34#define TSL_SF_A1 (1UL << 21)
35#define TSL_LF_A1 (1UL << 20)
36#define TSL_BSEL_A1 (1UL << 17)
37#define TSL_DOD_A1 (1UL << 15)
38#define TSL_LOW_A1 (1UL << 14)
39#define TSL_DIS_A2 (1UL << 11)
40#define TSL_SDW_A2 (1UL << 10)
41#define TSL_SIB_A2 (1UL << 9)
42#define TSL_SF_A2 (1UL << 8)
43#define TSL_LF_A2 (1UL << 7)
44#define TSL_BSEL_A2 (1UL << 4)
45#define TSL_DOD_A2 (1UL << 2)
46#define TSL_LOW_A2 (1UL << 1)
47#define TSL_EOS (1UL << 0)
48
49 /* Audiowerk8 hardware setup: */
50 /* WS0, SD4, TSL1 - Analog/ digital in */
51 /* WS1, SD0, TSL1 - Analog out #1, digital out */
52 /* WS2, SD2, TSL1 - Analog out #2 */
53 /* WS3, SD1, TSL2 - Analog out #3 */
54 /* WS4, SD3, TSL2 - Analog out #4 */
55
56 /* Audiowerk8 timing: */
57 /* Timeslot: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ... */
58
59 /* A1_INPUT: */
60 /* SD4: <_ADC-L_>-------<_ADC-R_>-------< */
61 /* WS0: _______________/---------------\_ */
62
63 /* A1_OUTPUT: */
64 /* SD0: <_1-L___>-------<_1-R___>-------< */
65 /* WS1: _______________/---------------\_ */
66 /* SD2: >-------<_2-L___>-------<_2-R___> */
67 /* WS2: -------\_______________/--------- */
68
69 /* A2_OUTPUT: */
70 /* SD1: <_3-L___>-------<_3-R___>-------< */
71 /* WS3: _______________/---------------\_ */
72 /* SD3: >-------<_4-L___>-------<_4-R___> */
73 /* WS4: -------\_______________/--------- */
74
75static int tsl1[8] = {
76 1 * TSL_SDW_A1 | 3 * TSL_BSEL_A1 |
77 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_LF_A1,
78
79 1 * TSL_SDW_A1 | 2 * TSL_BSEL_A1 |
80 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1,
81
82 0 * TSL_SDW_A1 | 3 * TSL_BSEL_A1 |
83 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1,
84
85 0 * TSL_SDW_A1 | 2 * TSL_BSEL_A1 |
86 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1,
87
88 1 * TSL_SDW_A1 | 1 * TSL_BSEL_A1 |
89 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0,
90
91 1 * TSL_SDW_A1 | 0 * TSL_BSEL_A1 |
92 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0,
93
94 0 * TSL_SDW_A1 | 1 * TSL_BSEL_A1 |
95 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0,
96
97 0 * TSL_SDW_A1 | 0 * TSL_BSEL_A1 | 0 * TSL_DIS_A1 |
98 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0 | TSL_SF_A1 | TSL_EOS,
99};
100
101static int tsl2[8] = {
102 0 * TSL_SDW_A2 | 3 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_LF_A2,
103 0 * TSL_SDW_A2 | 2 * TSL_BSEL_A2 | 2 * TSL_DOD_A2,
104 0 * TSL_SDW_A2 | 3 * TSL_BSEL_A2 | 2 * TSL_DOD_A2,
105 0 * TSL_SDW_A2 | 2 * TSL_BSEL_A2 | 2 * TSL_DOD_A2,
106 0 * TSL_SDW_A2 | 1 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2,
107 0 * TSL_SDW_A2 | 0 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2,
108 0 * TSL_SDW_A2 | 1 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2,
109 0 * TSL_SDW_A2 | 0 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2 | TSL_EOS
110};
diff --git a/sound/pci/aw2/saa7146.h b/sound/pci/aw2/saa7146.h
new file mode 100644
index 000000000000..ce0ab5f9ee9c
--- /dev/null
+++ b/sound/pci/aw2/saa7146.h
@@ -0,0 +1,168 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23
24/* SAA7146 registers */
25#define PCI_BT_A 0x4C
26#define IICTFR 0x8C
27#define IICSTA 0x90
28#define BaseA1_in 0x94
29#define ProtA1_in 0x98
30#define PageA1_in 0x9C
31#define BaseA1_out 0xA0
32#define ProtA1_out 0xA4
33#define PageA1_out 0xA8
34#define BaseA2_in 0xAC
35#define ProtA2_in 0xB0
36#define PageA2_in 0xB4
37#define BaseA2_out 0xB8
38#define ProtA2_out 0xBC
39#define PageA2_out 0xC0
40#define IER 0xDC
41#define GPIO_CTRL 0xE0
42#define ACON1 0xF4
43#define ACON2 0xF8
44#define MC1 0xFC
45#define MC2 0x100
46#define ISR 0x10C
47#define PSR 0x110
48#define SSR 0x114
49#define PCI_ADP1 0x12C
50#define PCI_ADP2 0x130
51#define PCI_ADP3 0x134
52#define PCI_ADP4 0x138
53#define LEVEL_REP 0x140
54#define FB_BUFFER1 0x144
55#define FB_BUFFER2 0x148
56#define TSL1 0x180
57#define TSL2 0x1C0
58
59#define ME (1UL << 11)
60#define LIMIT (1UL << 4)
61#define PV (1UL << 3)
62
63/* PSR/ISR/IER */
64#define PPEF (1UL << 31)
65#define PABO (1UL << 30)
66#define IIC_S (1UL << 17)
67#define IIC_E (1UL << 16)
68#define A2_in (1UL << 15)
69#define A2_out (1UL << 14)
70#define A1_in (1UL << 13)
71#define A1_out (1UL << 12)
72#define AFOU (1UL << 11)
73#define PIN3 (1UL << 6)
74#define PIN2 (1UL << 5)
75#define PIN1 (1UL << 4)
76#define PIN0 (1UL << 3)
77#define ECS (1UL << 2)
78#define EC3S (1UL << 1)
79#define EC0S (1UL << 0)
80
81/* SSR */
82#define PRQ (1UL << 31)
83#define PMA (1UL << 30)
84#define IIC_EA (1UL << 21)
85#define IIC_EW (1UL << 20)
86#define IIC_ER (1UL << 19)
87#define IIC_EL (1UL << 18)
88#define IIC_EF (1UL << 17)
89#define AF2_in (1UL << 10)
90#define AF2_out (1UL << 9)
91#define AF1_in (1UL << 8)
92#define AF1_out (1UL << 7)
93#define EC5S (1UL << 3)
94#define EC4S (1UL << 2)
95#define EC2S (1UL << 1)
96#define EC1S (1UL << 0)
97
98/* PCI_BT_A */
99#define BurstA1_in (1UL << 26)
100#define ThreshA1_in (1UL << 24)
101#define BurstA1_out (1UL << 18)
102#define ThreshA1_out (1UL << 16)
103#define BurstA2_in (1UL << 10)
104#define ThreshA2_in (1UL << 8)
105#define BurstA2_out (1UL << 2)
106#define ThreshA2_out (1UL << 0)
107
108/* MC1 */
109#define MRST_N (1UL << 15)
110#define EAP (1UL << 9)
111#define EI2C (1UL << 8)
112#define TR_E_A2_OUT (1UL << 3)
113#define TR_E_A2_IN (1UL << 2)
114#define TR_E_A1_OUT (1UL << 1)
115#define TR_E_A1_IN (1UL << 0)
116
117/* MC2 */
118#define UPLD_IIC (1UL << 0)
119
120/* ACON1 */
121#define AUDIO_MODE (1UL << 29)
122#define MAXLEVEL (1UL << 22)
123#define A1_SWAP (1UL << 21)
124#define A2_SWAP (1UL << 20)
125#define WS0_CTRL (1UL << 18)
126#define WS0_SYNC (1UL << 16)
127#define WS1_CTRL (1UL << 14)
128#define WS1_SYNC (1UL << 12)
129#define WS2_CTRL (1UL << 10)
130#define WS2_SYNC (1UL << 8)
131#define WS3_CTRL (1UL << 6)
132#define WS3_SYNC (1UL << 4)
133#define WS4_CTRL (1UL << 2)
134#define WS4_SYNC (1UL << 0)
135
136/* ACON2 */
137#define A1_CLKSRC (1UL << 27)
138#define A2_CLKSRC (1UL << 22)
139#define INVERT_BCLK1 (1UL << 21)
140#define INVERT_BCLK2 (1UL << 20)
141#define BCLK1_OEN (1UL << 19)
142#define BCLK2_OEN (1UL << 18)
143
144/* IICSTA */
145#define IICCC (1UL << 8)
146#define ABORT (1UL << 7)
147#define SPERR (1UL << 6)
148#define APERR (1UL << 5)
149#define DTERR (1UL << 4)
150#define DRERR (1UL << 3)
151#define AL (1UL << 2)
152#define ERR (1UL << 1)
153#define BUSY (1UL << 0)
154
155/* IICTFR */
156#define BYTE2 (1UL << 24)
157#define BYTE1 (1UL << 16)
158#define BYTE0 (1UL << 8)
159#define ATRR2 (1UL << 6)
160#define ATRR1 (1UL << 4)
161#define ATRR0 (1UL << 2)
162#define ERR (1UL << 1)
163#define BUSY (1UL << 0)
164
165#define START 3
166#define CONT 2
167#define STOP 1
168#define NOP 0
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 4e71a55120a0..5f63af6b88a2 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -157,8 +157,8 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
157 157
158#if DEBUG_CALLS 158#if DEBUG_CALLS
159#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args) 159#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
160#define snd_azf3328_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__) 160#define snd_azf3328_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__)
161#define snd_azf3328_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__) 161#define snd_azf3328_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__)
162#else 162#else
163#define snd_azf3328_dbgcalls(format, args...) 163#define snd_azf3328_dbgcalls(format, args...)
164#define snd_azf3328_dbgcallenter() 164#define snd_azf3328_dbgcallenter()
@@ -1514,7 +1514,8 @@ snd_azf3328_free(struct snd_azf3328 *chip)
1514 /* well, at least we know how to disable the timer IRQ */ 1514 /* well, at least we know how to disable the timer IRQ */
1515 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00); 1515 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00);
1516 1516
1517 synchronize_irq(chip->irq); 1517 if (chip->irq >= 0)
1518 synchronize_irq(chip->irq);
1518__end_hw: 1519__end_hw:
1519 snd_azf3328_free_joystick(chip); 1520 snd_azf3328_free_joystick(chip);
1520 if (chip->irq >= 0) 1521 if (chip->irq >= 0)
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 176e0f0e8058..ecbe79b67e43 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -435,22 +435,22 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
435static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb) 435static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb)
436{ 436{
437 unsigned long flags; 437 unsigned long flags;
438 unsigned int enable; 438 unsigned int intr_enable;
439 439
440 spin_lock_irqsave(&emu->emu_lock, flags); 440 spin_lock_irqsave(&emu->emu_lock, flags);
441 enable = inl(emu->port + INTE) | intrenb; 441 intr_enable = inl(emu->port + INTE) | intrenb;
442 outl(enable, emu->port + INTE); 442 outl(intr_enable, emu->port + INTE);
443 spin_unlock_irqrestore(&emu->emu_lock, flags); 443 spin_unlock_irqrestore(&emu->emu_lock, flags);
444} 444}
445 445
446static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb) 446static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb)
447{ 447{
448 unsigned long flags; 448 unsigned long flags;
449 unsigned int enable; 449 unsigned int intr_enable;
450 450
451 spin_lock_irqsave(&emu->emu_lock, flags); 451 spin_lock_irqsave(&emu->emu_lock, flags);
452 enable = inl(emu->port + INTE) & ~intrenb; 452 intr_enable = inl(emu->port + INTE) & ~intrenb;
453 outl(enable, emu->port + INTE); 453 outl(intr_enable, emu->port + INTE);
454 spin_unlock_irqrestore(&emu->emu_lock, flags); 454 spin_unlock_irqrestore(&emu->emu_lock, flags);
455} 455}
456 456
@@ -1114,6 +1114,8 @@ static int snd_ca0106_free(struct snd_ca0106 *chip)
1114 * So we can fix: snd-malloc: Memory leak? pages not freed = 8 1114 * So we can fix: snd-malloc: Memory leak? pages not freed = 8
1115 */ 1115 */
1116 } 1116 }
1117 if (chip->irq >= 0)
1118 free_irq(chip->irq, chip);
1117 // release the data 1119 // release the data
1118#if 1 1120#if 1
1119 if (chip->buffer.area) 1121 if (chip->buffer.area)
@@ -1123,9 +1125,6 @@ static int snd_ca0106_free(struct snd_ca0106 *chip)
1123 // release the i/o port 1125 // release the i/o port
1124 release_and_free_resource(chip->res_port); 1126 release_and_free_resource(chip->res_port);
1125 1127
1126 // release the irq
1127 if (chip->irq >= 0)
1128 free_irq(chip->irq, chip);
1129 pci_disable_device(chip->pci); 1128 pci_disable_device(chip->pci);
1130 kfree(chip); 1129 kfree(chip);
1131 return 0; 1130 return 0;
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index af736869d9b1..3025ed1b6e1e 100644
--- a/sound/pci/ca0106/ca0106_mixer.c
+++ b/sound/pci/ca0106/ca0106_mixer.c
@@ -650,19 +650,55 @@ static int __devinit rename_ctl(struct snd_card *card, const char *src, const ch
650 650
651#define ADD_CTLS(emu, ctls) \ 651#define ADD_CTLS(emu, ctls) \
652 do { \ 652 do { \
653 int i, err; \ 653 int i, _err; \
654 for (i = 0; i < ARRAY_SIZE(ctls); i++) { \ 654 for (i = 0; i < ARRAY_SIZE(ctls); i++) { \
655 err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \ 655 _err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \
656 if (err < 0) \ 656 if (_err < 0) \
657 return err; \ 657 return _err; \
658 } \ 658 } \
659 } while (0) 659 } while (0)
660 660
661static __devinitdata
662DECLARE_TLV_DB_SCALE(snd_ca0106_master_db_scale, -6375, 50, 1);
663
664static char *slave_vols[] __devinitdata = {
665 "Analog Front Playback Volume",
666 "Analog Rear Playback Volume",
667 "Analog Center/LFE Playback Volume",
668 "Analog Side Playback Volume",
669 "IEC958 Front Playback Volume",
670 "IEC958 Rear Playback Volume",
671 "IEC958 Center/LFE Playback Volume",
672 "IEC958 Unknown Playback Volume",
673 "CAPTURE feedback Playback Volume",
674 NULL
675};
676
677static char *slave_sws[] __devinitdata = {
678 "Analog Front Playback Switch",
679 "Analog Rear Playback Switch",
680 "Analog Center/LFE Playback Switch",
681 "Analog Side Playback Switch",
682 "IEC958 Playback Switch",
683 NULL
684};
685
686static void __devinit add_slaves(struct snd_card *card,
687 struct snd_kcontrol *master, char **list)
688{
689 for (; *list; list++) {
690 struct snd_kcontrol *slave = ctl_find(card, *list);
691 if (slave)
692 snd_ctl_add_slave(master, slave);
693 }
694}
695
661int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu) 696int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
662{ 697{
663 int err; 698 int err;
664 struct snd_card *card = emu->card; 699 struct snd_card *card = emu->card;
665 char **c; 700 char **c;
701 struct snd_kcontrol *vmaster;
666 static char *ca0106_remove_ctls[] = { 702 static char *ca0106_remove_ctls[] = {
667 "Master Mono Playback Switch", 703 "Master Mono Playback Switch",
668 "Master Mono Playback Volume", 704 "Master Mono Playback Volume",
@@ -719,6 +755,21 @@ int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
719 } 755 }
720 if (emu->details->spi_dac == 1) 756 if (emu->details->spi_dac == 1)
721 ADD_CTLS(emu, snd_ca0106_volume_spi_dac_ctls); 757 ADD_CTLS(emu, snd_ca0106_volume_spi_dac_ctls);
758
759 /* Create virtual master controls */
760 vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
761 snd_ca0106_master_db_scale);
762 if (!vmaster)
763 return -ENOMEM;
764 add_slaves(card, vmaster, slave_vols);
765
766 if (emu->details->spi_dac == 1) {
767 vmaster = snd_ctl_make_virtual_master("Master Playback Switch",
768 NULL);
769 if (!vmaster)
770 return -ENOMEM;
771 add_slaves(card, vmaster, slave_sws);
772 }
722 return 0; 773 return 0;
723} 774}
724 775
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 135f30860753..9971b5b7735b 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2744,12 +2744,13 @@ static int __devinit snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_devic
2744 } 2744 }
2745 2745
2746 for (idx = 0; idx < CM_SAVED_MIXERS; idx++) { 2746 for (idx = 0; idx < CM_SAVED_MIXERS; idx++) {
2747 struct snd_ctl_elem_id id; 2747 struct snd_ctl_elem_id elem_id;
2748 struct snd_kcontrol *ctl; 2748 struct snd_kcontrol *ctl;
2749 memset(&id, 0, sizeof(id)); 2749 memset(&elem_id, 0, sizeof(elem_id));
2750 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2750 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2751 strcpy(id.name, cm_saved_mixer[idx].name); 2751 strcpy(elem_id.name, cm_saved_mixer[idx].name);
2752 if ((ctl = snd_ctl_find_id(cm->card, &id)) != NULL) 2752 ctl = snd_ctl_find_id(cm->card, &elem_id);
2753 if (ctl)
2753 cm->mixer_res_ctl[idx] = ctl; 2754 cm->mixer_res_ctl[idx] = ctl;
2754 } 2755 }
2755 2756
@@ -2932,8 +2933,6 @@ static int snd_cmipci_free(struct cmipci *cm)
2932 /* reset mixer */ 2933 /* reset mixer */
2933 snd_cmipci_mixer_write(cm, 0, 0); 2934 snd_cmipci_mixer_write(cm, 0, 0);
2934 2935
2935 synchronize_irq(cm->irq);
2936
2937 free_irq(cm->irq, cm); 2936 free_irq(cm->irq, cm);
2938 } 2937 }
2939 2938
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index 87ddffcd9d89..e214e567dec8 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -2772,6 +2772,9 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
2772 if (chip->irq >= 0) 2772 if (chip->irq >= 0)
2773 free_irq(chip->irq, chip); 2773 free_irq(chip->irq, chip);
2774 2774
2775 if (chip->active_ctrl)
2776 chip->active_ctrl(chip, -chip->amplifier);
2777
2775 for (idx = 0; idx < 5; idx++) { 2778 for (idx = 0; idx < 5; idx++) {
2776 struct snd_cs46xx_region *region = &chip->region.idx[idx]; 2779 struct snd_cs46xx_region *region = &chip->region.idx[idx];
2777 if (region->remap_addr) 2780 if (region->remap_addr)
@@ -2779,9 +2782,6 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
2779 release_and_free_resource(region->resource); 2782 release_and_free_resource(region->resource);
2780 } 2783 }
2781 2784
2782 if (chip->active_ctrl)
2783 chip->active_ctrl(chip, -chip->amplifier);
2784
2785#ifdef CONFIG_SND_CS46XX_NEW_DSP 2785#ifdef CONFIG_SND_CS46XX_NEW_DSP
2786 if (chip->dsp_spos_instance) { 2786 if (chip->dsp_spos_instance) {
2787 cs46xx_dsp_spos_destroy(chip); 2787 cs46xx_dsp_spos_destroy(chip);
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 90ec090792ba..e16dc92e82fb 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -1852,15 +1852,16 @@ static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1852static int snd_echo_free(struct echoaudio *chip) 1852static int snd_echo_free(struct echoaudio *chip)
1853{ 1853{
1854 DE_INIT(("Stop DSP...\n")); 1854 DE_INIT(("Stop DSP...\n"));
1855 if (chip->comm_page) { 1855 if (chip->comm_page)
1856 rest_in_peace(chip); 1856 rest_in_peace(chip);
1857 snd_dma_free_pages(&chip->commpage_dma_buf);
1858 }
1859 DE_INIT(("Stopped.\n")); 1857 DE_INIT(("Stopped.\n"));
1860 1858
1861 if (chip->irq >= 0) 1859 if (chip->irq >= 0)
1862 free_irq(chip->irq, chip); 1860 free_irq(chip->irq, chip);
1863 1861
1862 if (chip->comm_page)
1863 snd_dma_free_pages(&chip->commpage_dma_buf);
1864
1864 if (chip->dsp_registers) 1865 if (chip->dsp_registers)
1865 iounmap(chip->dsp_registers); 1866 iounmap(chip->dsp_registers);
1866 1867
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 9a9b977d3cf1..abde5b901884 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -1249,11 +1249,6 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1249 if (emu->port) { /* avoid access to already used hardware */ 1249 if (emu->port) { /* avoid access to already used hardware */
1250 snd_emu10k1_fx8010_tram_setup(emu, 0); 1250 snd_emu10k1_fx8010_tram_setup(emu, 0);
1251 snd_emu10k1_done(emu); 1251 snd_emu10k1_done(emu);
1252 /* remove reserved page */
1253 if (emu->reserved_page) {
1254 snd_emu10k1_synth_free(emu, (struct snd_util_memblk *)emu->reserved_page);
1255 emu->reserved_page = NULL;
1256 }
1257 snd_emu10k1_free_efx(emu); 1252 snd_emu10k1_free_efx(emu);
1258 } 1253 }
1259 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010) { 1254 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010) {
@@ -1262,6 +1257,14 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1262 } 1257 }
1263 if (emu->emu1010.firmware_thread) 1258 if (emu->emu1010.firmware_thread)
1264 kthread_stop(emu->emu1010.firmware_thread); 1259 kthread_stop(emu->emu1010.firmware_thread);
1260 if (emu->irq >= 0)
1261 free_irq(emu->irq, emu);
1262 /* remove reserved page */
1263 if (emu->reserved_page) {
1264 snd_emu10k1_synth_free(emu,
1265 (struct snd_util_memblk *)emu->reserved_page);
1266 emu->reserved_page = NULL;
1267 }
1265 if (emu->memhdr) 1268 if (emu->memhdr)
1266 snd_util_memhdr_free(emu->memhdr); 1269 snd_util_memhdr_free(emu->memhdr);
1267 if (emu->silent_page.area) 1270 if (emu->silent_page.area)
@@ -1273,8 +1276,6 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1273#ifdef CONFIG_PM 1276#ifdef CONFIG_PM
1274 free_pm_buffer(emu); 1277 free_pm_buffer(emu);
1275#endif 1278#endif
1276 if (emu->irq >= 0)
1277 free_irq(emu->irq, emu);
1278 if (emu->port) 1279 if (emu->port)
1279 pci_release_regions(emu->pci); 1280 pci_release_regions(emu->pci);
1280 if (emu->card_capabilities->ca0151_chip) /* P16V */ 1281 if (emu->card_capabilities->ca0151_chip) /* P16V */
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 5512abd98bd9..491a4a50f869 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -327,22 +327,22 @@ static void snd_emu10k1x_ptr_write(struct emu10k1x *emu,
327static void snd_emu10k1x_intr_enable(struct emu10k1x *emu, unsigned int intrenb) 327static void snd_emu10k1x_intr_enable(struct emu10k1x *emu, unsigned int intrenb)
328{ 328{
329 unsigned long flags; 329 unsigned long flags;
330 unsigned int enable; 330 unsigned int intr_enable;
331 331
332 spin_lock_irqsave(&emu->emu_lock, flags); 332 spin_lock_irqsave(&emu->emu_lock, flags);
333 enable = inl(emu->port + INTE) | intrenb; 333 intr_enable = inl(emu->port + INTE) | intrenb;
334 outl(enable, emu->port + INTE); 334 outl(intr_enable, emu->port + INTE);
335 spin_unlock_irqrestore(&emu->emu_lock, flags); 335 spin_unlock_irqrestore(&emu->emu_lock, flags);
336} 336}
337 337
338static void snd_emu10k1x_intr_disable(struct emu10k1x *emu, unsigned int intrenb) 338static void snd_emu10k1x_intr_disable(struct emu10k1x *emu, unsigned int intrenb)
339{ 339{
340 unsigned long flags; 340 unsigned long flags;
341 unsigned int enable; 341 unsigned int intr_enable;
342 342
343 spin_lock_irqsave(&emu->emu_lock, flags); 343 spin_lock_irqsave(&emu->emu_lock, flags);
344 enable = inl(emu->port + INTE) & ~intrenb; 344 intr_enable = inl(emu->port + INTE) & ~intrenb;
345 outl(enable, emu->port + INTE); 345 outl(intr_enable, emu->port + INTE);
346 spin_unlock_irqrestore(&emu->emu_lock, flags); 346 spin_unlock_irqrestore(&emu->emu_lock, flags);
347} 347}
348 348
@@ -754,13 +754,13 @@ static int snd_emu10k1x_free(struct emu10k1x *chip)
754 // disable audio 754 // disable audio
755 outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); 755 outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
756 756
757 // release the i/o port 757 /* release the irq */
758 release_and_free_resource(chip->res_port);
759
760 // release the irq
761 if (chip->irq >= 0) 758 if (chip->irq >= 0)
762 free_irq(chip->irq, chip); 759 free_irq(chip->irq, chip);
763 760
761 // release the i/o port
762 release_and_free_resource(chip->res_port);
763
764 // release the DMA 764 // release the DMA
765 if (chip->dma_buffer.area) { 765 if (chip->dma_buffer.area) {
766 snd_dma_free_pages(&chip->dma_buffer); 766 snd_dma_free_pages(&chip->dma_buffer);
@@ -795,9 +795,9 @@ static irqreturn_t snd_emu10k1x_interrupt(int irq, void *dev_id)
795 795
796 // capture interrupt 796 // capture interrupt
797 if (status & (IPR_CAP_0_LOOP | IPR_CAP_0_HALF_LOOP)) { 797 if (status & (IPR_CAP_0_LOOP | IPR_CAP_0_HALF_LOOP)) {
798 struct emu10k1x_voice *pvoice = &chip->capture_voice; 798 struct emu10k1x_voice *cap_voice = &chip->capture_voice;
799 if (pvoice->use) 799 if (cap_voice->use)
800 snd_emu10k1x_pcm_interrupt(chip, pvoice); 800 snd_emu10k1x_pcm_interrupt(chip, cap_voice);
801 else 801 else
802 snd_emu10k1x_intr_disable(chip, 802 snd_emu10k1x_intr_disable(chip,
803 INTE_CAP_0_LOOP | 803 INTE_CAP_0_LOOP |
diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c
index f3caa3f890c6..216f9748aff5 100644
--- a/sound/pci/emu10k1/emuproc.c
+++ b/sound/pci/emu10k1/emuproc.c
@@ -412,7 +412,7 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,
412 struct snd_info_buffer *buffer) 412 struct snd_info_buffer *buffer)
413{ 413{
414 struct snd_emu10k1 *emu = entry->private_data; 414 struct snd_emu10k1 *emu = entry->private_data;
415 int value; 415 u32 value;
416 unsigned long flags; 416 unsigned long flags;
417 int i; 417 int i;
418 snd_iprintf(buffer, "EMU1010 Registers:\n\n"); 418 snd_iprintf(buffer, "EMU1010 Registers:\n\n");
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index 72d85a5ae6a0..fbf1124f7c79 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -1635,20 +1635,20 @@ static int __devinit snd_ensoniq_1371_mixer(struct ensoniq *ensoniq,
1635 if (has_spdif > 0 || 1635 if (has_spdif > 0 ||
1636 (!has_spdif && es1371_quirk_lookup(ensoniq, es1371_spdif_present))) { 1636 (!has_spdif && es1371_quirk_lookup(ensoniq, es1371_spdif_present))) {
1637 struct snd_kcontrol *kctl; 1637 struct snd_kcontrol *kctl;
1638 int i, index = 0; 1638 int i, is_spdif = 0;
1639 1639
1640 ensoniq->spdif_default = ensoniq->spdif_stream = 1640 ensoniq->spdif_default = ensoniq->spdif_stream =
1641 SNDRV_PCM_DEFAULT_CON_SPDIF; 1641 SNDRV_PCM_DEFAULT_CON_SPDIF;
1642 outl(ensoniq->spdif_default, ES_REG(ensoniq, CHANNEL_STATUS)); 1642 outl(ensoniq->spdif_default, ES_REG(ensoniq, CHANNEL_STATUS));
1643 1643
1644 if (ensoniq->u.es1371.ac97->ext_id & AC97_EI_SPDIF) 1644 if (ensoniq->u.es1371.ac97->ext_id & AC97_EI_SPDIF)
1645 index++; 1645 is_spdif++;
1646 1646
1647 for (i = 0; i < ARRAY_SIZE(snd_es1371_mixer_spdif); i++) { 1647 for (i = 0; i < ARRAY_SIZE(snd_es1371_mixer_spdif); i++) {
1648 kctl = snd_ctl_new1(&snd_es1371_mixer_spdif[i], ensoniq); 1648 kctl = snd_ctl_new1(&snd_es1371_mixer_spdif[i], ensoniq);
1649 if (!kctl) 1649 if (!kctl)
1650 return -ENOMEM; 1650 return -ENOMEM;
1651 kctl->id.index = index; 1651 kctl->id.index = is_spdif;
1652 err = snd_ctl_add(card, kctl); 1652 err = snd_ctl_add(card, kctl);
1653 if (err < 0) 1653 if (err < 0)
1654 return err; 1654 return err;
@@ -1910,7 +1910,8 @@ static int snd_ensoniq_free(struct ensoniq *ensoniq)
1910 outl(0, ES_REG(ensoniq, CONTROL)); /* switch everything off */ 1910 outl(0, ES_REG(ensoniq, CONTROL)); /* switch everything off */
1911 outl(0, ES_REG(ensoniq, SERIAL)); /* clear serial interface */ 1911 outl(0, ES_REG(ensoniq, SERIAL)); /* clear serial interface */
1912#endif 1912#endif
1913 synchronize_irq(ensoniq->irq); 1913 if (ensoniq->irq >= 0)
1914 synchronize_irq(ensoniq->irq);
1914 pci_set_power_state(ensoniq->pci, 3); 1915 pci_set_power_state(ensoniq->pci, 3);
1915 __hw_end: 1916 __hw_end:
1916#ifdef CHIP1370 1917#ifdef CHIP1370
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 1a314fa99c45..84fac1fbf103 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1488,7 +1488,6 @@ static int es1938_suspend(struct pci_dev *pci, pm_message_t state)
1488 1488
1489 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */ 1489 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */
1490 if (chip->irq >= 0) { 1490 if (chip->irq >= 0) {
1491 synchronize_irq(chip->irq);
1492 free_irq(chip->irq, chip); 1491 free_irq(chip->irq, chip);
1493 chip->irq = -1; 1492 chip->irq = -1;
1494 } 1493 }
@@ -1578,10 +1577,8 @@ static int snd_es1938_free(struct es1938 *chip)
1578 1577
1579 snd_es1938_free_gameport(chip); 1578 snd_es1938_free_gameport(chip);
1580 1579
1581 if (chip->irq >= 0) { 1580 if (chip->irq >= 0)
1582 synchronize_irq(chip->irq);
1583 free_irq(chip->irq, chip); 1581 free_irq(chip->irq, chip);
1584 }
1585 pci_release_regions(chip->pci); 1582 pci_release_regions(chip->pci);
1586 pci_disable_device(chip->pci); 1583 pci_disable_device(chip->pci);
1587 kfree(chip); 1584 kfree(chip);
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 7d911a18c082..1bf298d214b9 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -1827,6 +1827,22 @@ snd_es1968_pcm(struct es1968 *chip, int device)
1827 1827
1828 return 0; 1828 return 0;
1829} 1829}
1830/*
1831 * suppress jitter on some maestros when playing stereo
1832 */
1833static void snd_es1968_suppress_jitter(struct es1968 *chip, struct esschan *es)
1834{
1835 unsigned int cp1;
1836 unsigned int cp2;
1837 unsigned int diff;
1838
1839 cp1 = __apu_get_register(chip, 0, 5);
1840 cp2 = __apu_get_register(chip, 1, 5);
1841 diff = (cp1 > cp2 ? cp1 - cp2 : cp2 - cp1);
1842
1843 if (diff > 1)
1844 __maestro_write(chip, IDR0_DATA_PORT, cp1);
1845}
1830 1846
1831/* 1847/*
1832 * update pointer 1848 * update pointer
@@ -1948,8 +1964,11 @@ static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id)
1948 struct esschan *es; 1964 struct esschan *es;
1949 spin_lock(&chip->substream_lock); 1965 spin_lock(&chip->substream_lock);
1950 list_for_each_entry(es, &chip->substream_list, list) { 1966 list_for_each_entry(es, &chip->substream_list, list) {
1951 if (es->running) 1967 if (es->running) {
1952 snd_es1968_update_pcm(chip, es); 1968 snd_es1968_update_pcm(chip, es);
1969 if (es->fmt & ESS_FMT_STEREO)
1970 snd_es1968_suppress_jitter(chip, es);
1971 }
1953 } 1972 }
1954 spin_unlock(&chip->substream_lock); 1973 spin_unlock(&chip->substream_lock);
1955 if (chip->in_measurement) { 1974 if (chip->in_measurement) {
@@ -1972,7 +1991,7 @@ snd_es1968_mixer(struct es1968 *chip)
1972{ 1991{
1973 struct snd_ac97_bus *pbus; 1992 struct snd_ac97_bus *pbus;
1974 struct snd_ac97_template ac97; 1993 struct snd_ac97_template ac97;
1975 struct snd_ctl_elem_id id; 1994 struct snd_ctl_elem_id elem_id;
1976 int err; 1995 int err;
1977 static struct snd_ac97_bus_ops ops = { 1996 static struct snd_ac97_bus_ops ops = {
1978 .write = snd_es1968_ac97_write, 1997 .write = snd_es1968_ac97_write,
@@ -1989,14 +2008,14 @@ snd_es1968_mixer(struct es1968 *chip)
1989 return err; 2008 return err;
1990 2009
1991 /* attach master switch / volumes for h/w volume control */ 2010 /* attach master switch / volumes for h/w volume control */
1992 memset(&id, 0, sizeof(id)); 2011 memset(&elem_id, 0, sizeof(elem_id));
1993 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2012 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1994 strcpy(id.name, "Master Playback Switch"); 2013 strcpy(elem_id.name, "Master Playback Switch");
1995 chip->master_switch = snd_ctl_find_id(chip->card, &id); 2014 chip->master_switch = snd_ctl_find_id(chip->card, &elem_id);
1996 memset(&id, 0, sizeof(id)); 2015 memset(&elem_id, 0, sizeof(elem_id));
1997 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2016 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1998 strcpy(id.name, "Master Playback Volume"); 2017 strcpy(elem_id.name, "Master Playback Volume");
1999 chip->master_volume = snd_ctl_find_id(chip->card, &id); 2018 chip->master_volume = snd_ctl_find_id(chip->card, &elem_id);
2000 2019
2001 return 0; 2020 return 0;
2002} 2021}
@@ -2456,7 +2475,8 @@ static inline void snd_es1968_free_gameport(struct es1968 *chip) { }
2456static int snd_es1968_free(struct es1968 *chip) 2475static int snd_es1968_free(struct es1968 *chip)
2457{ 2476{
2458 if (chip->io_port) { 2477 if (chip->io_port) {
2459 synchronize_irq(chip->irq); 2478 if (chip->irq >= 0)
2479 synchronize_irq(chip->irq);
2460 outw(1, chip->io_port + 0x04); /* clear WP interrupts */ 2480 outw(1, chip->io_port + 0x04); /* clear WP interrupts */
2461 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */ 2481 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */
2462 } 2482 }
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index 4c300e6149fc..c129f9e2072c 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -1285,7 +1285,6 @@ static int wait_for_codec(struct fm801 *chip, unsigned int codec_id,
1285 1285
1286static int snd_fm801_chip_init(struct fm801 *chip, int resume) 1286static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1287{ 1287{
1288 int id;
1289 unsigned short cmdw; 1288 unsigned short cmdw;
1290 1289
1291 if (chip->tea575x_tuner & 0x0010) 1290 if (chip->tea575x_tuner & 0x0010)
@@ -1310,13 +1309,14 @@ static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1310 } else { 1309 } else {
1311 /* my card has the secondary codec */ 1310 /* my card has the secondary codec */
1312 /* at address #3, so the loop is inverted */ 1311 /* at address #3, so the loop is inverted */
1313 for (id = 3; id > 0; id--) { 1312 int i;
1314 if (! wait_for_codec(chip, id, AC97_VENDOR_ID1, 1313 for (i = 3; i > 0; i--) {
1314 if (!wait_for_codec(chip, i, AC97_VENDOR_ID1,
1315 msecs_to_jiffies(50))) { 1315 msecs_to_jiffies(50))) {
1316 cmdw = inw(FM801_REG(chip, AC97_DATA)); 1316 cmdw = inw(FM801_REG(chip, AC97_DATA));
1317 if (cmdw != 0xffff && cmdw != 0) { 1317 if (cmdw != 0xffff && cmdw != 0) {
1318 chip->secondary = 1; 1318 chip->secondary = 1;
1319 chip->secondary_addr = id; 1319 chip->secondary_addr = i;
1320 break; 1320 break;
1321 } 1321 }
1322 } 1322 }
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 9e0d8a1268aa..ab0c726d648e 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -2,7 +2,7 @@ snd-hda-intel-y := hda_intel.o
2# since snd-hda-intel is the only driver using hda-codec, 2# since snd-hda-intel is the only driver using hda-codec,
3# merge it into a single module although it was originally 3# merge it into a single module although it was originally
4# designed to be individual modules 4# designed to be individual modules
5snd-hda-intel-y += hda_codec.o vmaster.o 5snd-hda-intel-y += hda_codec.o
6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o 6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o
7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
8snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o 8snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 37c413923db8..a6be6e3e8716 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -31,6 +31,7 @@
31#include <sound/initval.h> 31#include <sound/initval.h>
32#include "hda_local.h" 32#include "hda_local.h"
33#include <sound/hda_hwdep.h> 33#include <sound/hda_hwdep.h>
34#include "hda_patch.h" /* codec presets */
34 35
35#ifdef CONFIG_SND_HDA_POWER_SAVE 36#ifdef CONFIG_SND_HDA_POWER_SAVE
36/* define this option here to hide as static */ 37/* define this option here to hide as static */
@@ -51,21 +52,50 @@ struct hda_vendor_id {
51 52
52/* codec vendor labels */ 53/* codec vendor labels */
53static struct hda_vendor_id hda_vendor_ids[] = { 54static struct hda_vendor_id hda_vendor_ids[] = {
54 { 0x10ec, "Realtek" }, 55 { 0x1002, "ATI" },
55 { 0x1057, "Motorola" }, 56 { 0x1057, "Motorola" },
57 { 0x1095, "Silicon Image" },
58 { 0x10ec, "Realtek" },
56 { 0x1106, "VIA" }, 59 { 0x1106, "VIA" },
57 { 0x111d, "IDT" }, 60 { 0x111d, "IDT" },
61 { 0x11c1, "LSI" },
58 { 0x11d4, "Analog Devices" }, 62 { 0x11d4, "Analog Devices" },
59 { 0x13f6, "C-Media" }, 63 { 0x13f6, "C-Media" },
60 { 0x14f1, "Conexant" }, 64 { 0x14f1, "Conexant" },
65 { 0x17e8, "Chrontel" },
66 { 0x1854, "LG" },
61 { 0x434d, "C-Media" }, 67 { 0x434d, "C-Media" },
62 { 0x8384, "SigmaTel" }, 68 { 0x8384, "SigmaTel" },
63 {} /* terminator */ 69 {} /* terminator */
64}; 70};
65 71
66/* codec presets */ 72static const struct hda_codec_preset *hda_preset_tables[] = {
67#include "hda_patch.h" 73#ifdef CONFIG_SND_HDA_CODEC_REALTEK
68 74 snd_hda_preset_realtek,
75#endif
76#ifdef CONFIG_SND_HDA_CODEC_CMEDIA
77 snd_hda_preset_cmedia,
78#endif
79#ifdef CONFIG_SND_HDA_CODEC_ANALOG
80 snd_hda_preset_analog,
81#endif
82#ifdef CONFIG_SND_HDA_CODEC_SIGMATEL
83 snd_hda_preset_sigmatel,
84#endif
85#ifdef CONFIG_SND_HDA_CODEC_SI3054
86 snd_hda_preset_si3054,
87#endif
88#ifdef CONFIG_SND_HDA_CODEC_ATIHDMI
89 snd_hda_preset_atihdmi,
90#endif
91#ifdef CONFIG_SND_HDA_CODEC_CONEXANT
92 snd_hda_preset_conexant,
93#endif
94#ifdef CONFIG_SND_HDA_CODEC_VIA
95 snd_hda_preset_via,
96#endif
97 NULL
98};
69 99
70#ifdef CONFIG_SND_HDA_POWER_SAVE 100#ifdef CONFIG_SND_HDA_POWER_SAVE
71static void hda_power_work(struct work_struct *work); 101static void hda_power_work(struct work_struct *work);
@@ -690,6 +720,19 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
690 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format); 720 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
691} 721}
692 722
723void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
724{
725 if (!nid)
726 return;
727
728 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid);
729 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
730#if 0 /* keep the format */
731 msleep(1);
732 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
733#endif
734}
735
693/* 736/*
694 * amp access functions 737 * amp access functions
695 */ 738 */
@@ -1037,16 +1080,24 @@ void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1037} 1080}
1038 1081
1039/* find a mixer control element with the given name */ 1082/* find a mixer control element with the given name */
1040struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, 1083static struct snd_kcontrol *
1041 const char *name) 1084_snd_hda_find_mixer_ctl(struct hda_codec *codec,
1085 const char *name, int idx)
1042{ 1086{
1043 struct snd_ctl_elem_id id; 1087 struct snd_ctl_elem_id id;
1044 memset(&id, 0, sizeof(id)); 1088 memset(&id, 0, sizeof(id));
1045 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1089 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1090 id.index = idx;
1046 strcpy(id.name, name); 1091 strcpy(id.name, name);
1047 return snd_ctl_find_id(codec->bus->card, &id); 1092 return snd_ctl_find_id(codec->bus->card, &id);
1048} 1093}
1049 1094
1095struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1096 const char *name)
1097{
1098 return _snd_hda_find_mixer_ctl(codec, name, 0);
1099}
1100
1050/* create a virtual master control and add slaves */ 1101/* create a virtual master control and add slaves */
1051int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1102int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1052 unsigned int *tlv, const char **slaves) 1103 unsigned int *tlv, const char **slaves)
@@ -1481,6 +1532,8 @@ static struct snd_kcontrol_new dig_mixes[] = {
1481 { } /* end */ 1532 { } /* end */
1482}; 1533};
1483 1534
1535#define SPDIF_MAX_IDX 4 /* 4 instances should be enough to probe */
1536
1484/** 1537/**
1485 * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls 1538 * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls
1486 * @codec: the HDA codec 1539 * @codec: the HDA codec
@@ -1496,9 +1549,20 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1496 int err; 1549 int err;
1497 struct snd_kcontrol *kctl; 1550 struct snd_kcontrol *kctl;
1498 struct snd_kcontrol_new *dig_mix; 1551 struct snd_kcontrol_new *dig_mix;
1552 int idx;
1499 1553
1554 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
1555 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch",
1556 idx))
1557 break;
1558 }
1559 if (idx >= SPDIF_MAX_IDX) {
1560 printk(KERN_ERR "hda_codec: too many IEC958 outputs\n");
1561 return -EBUSY;
1562 }
1500 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { 1563 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
1501 kctl = snd_ctl_new1(dig_mix, codec); 1564 kctl = snd_ctl_new1(dig_mix, codec);
1565 kctl->id.index = idx;
1502 kctl->private_value = nid; 1566 kctl->private_value = nid;
1503 err = snd_ctl_add(codec->bus->card, kctl); 1567 err = snd_ctl_add(codec->bus->card, kctl);
1504 if (err < 0) 1568 if (err < 0)
@@ -1512,6 +1576,43 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1512} 1576}
1513 1577
1514/* 1578/*
1579 * SPDIF sharing with analog output
1580 */
1581static int spdif_share_sw_get(struct snd_kcontrol *kcontrol,
1582 struct snd_ctl_elem_value *ucontrol)
1583{
1584 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
1585 ucontrol->value.integer.value[0] = mout->share_spdif;
1586 return 0;
1587}
1588
1589static int spdif_share_sw_put(struct snd_kcontrol *kcontrol,
1590 struct snd_ctl_elem_value *ucontrol)
1591{
1592 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
1593 mout->share_spdif = !!ucontrol->value.integer.value[0];
1594 return 0;
1595}
1596
1597static struct snd_kcontrol_new spdif_share_sw = {
1598 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1599 .name = "IEC958 Default PCM Playback Switch",
1600 .info = snd_ctl_boolean_mono_info,
1601 .get = spdif_share_sw_get,
1602 .put = spdif_share_sw_put,
1603};
1604
1605int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
1606 struct hda_multi_out *mout)
1607{
1608 if (!mout->dig_out_nid)
1609 return 0;
1610 /* ATTENTION: here mout is passed as private_data, instead of codec */
1611 return snd_ctl_add(codec->bus->card,
1612 snd_ctl_new1(&spdif_share_sw, mout));
1613}
1614
1615/*
1515 * SPDIF input 1616 * SPDIF input
1516 */ 1617 */
1517 1618
@@ -1595,7 +1696,17 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1595 int err; 1696 int err;
1596 struct snd_kcontrol *kctl; 1697 struct snd_kcontrol *kctl;
1597 struct snd_kcontrol_new *dig_mix; 1698 struct snd_kcontrol_new *dig_mix;
1699 int idx;
1598 1700
1701 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
1702 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Capture Switch",
1703 idx))
1704 break;
1705 }
1706 if (idx >= SPDIF_MAX_IDX) {
1707 printk(KERN_ERR "hda_codec: too many IEC958 inputs\n");
1708 return -EBUSY;
1709 }
1599 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { 1710 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
1600 kctl = snd_ctl_new1(dig_mix, codec); 1711 kctl = snd_ctl_new1(dig_mix, codec);
1601 kctl->private_value = nid; 1712 kctl->private_value = nid;
@@ -2106,7 +2217,7 @@ static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
2106 struct hda_codec *codec, 2217 struct hda_codec *codec,
2107 struct snd_pcm_substream *substream) 2218 struct snd_pcm_substream *substream)
2108{ 2219{
2109 snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0); 2220 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2110 return 0; 2221 return 0;
2111} 2222}
2112 2223
@@ -2491,7 +2602,7 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
2491 mutex_lock(&codec->spdif_mutex); 2602 mutex_lock(&codec->spdif_mutex);
2492 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP) 2603 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP)
2493 /* already opened as analog dup; reset it once */ 2604 /* already opened as analog dup; reset it once */
2494 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 0, 0, 0); 2605 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2495 mout->dig_out_used = HDA_DIG_EXCLUSIVE; 2606 mout->dig_out_used = HDA_DIG_EXCLUSIVE;
2496 mutex_unlock(&codec->spdif_mutex); 2607 mutex_unlock(&codec->spdif_mutex);
2497 return 0; 2608 return 0;
@@ -2526,9 +2637,36 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec,
2526 */ 2637 */
2527int snd_hda_multi_out_analog_open(struct hda_codec *codec, 2638int snd_hda_multi_out_analog_open(struct hda_codec *codec,
2528 struct hda_multi_out *mout, 2639 struct hda_multi_out *mout,
2529 struct snd_pcm_substream *substream) 2640 struct snd_pcm_substream *substream,
2530{ 2641 struct hda_pcm_stream *hinfo)
2531 substream->runtime->hw.channels_max = mout->max_channels; 2642{
2643 struct snd_pcm_runtime *runtime = substream->runtime;
2644 runtime->hw.channels_max = mout->max_channels;
2645 if (mout->dig_out_nid) {
2646 if (!mout->analog_rates) {
2647 mout->analog_rates = hinfo->rates;
2648 mout->analog_formats = hinfo->formats;
2649 mout->analog_maxbps = hinfo->maxbps;
2650 } else {
2651 runtime->hw.rates = mout->analog_rates;
2652 runtime->hw.formats = mout->analog_formats;
2653 hinfo->maxbps = mout->analog_maxbps;
2654 }
2655 if (!mout->spdif_rates) {
2656 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
2657 &mout->spdif_rates,
2658 &mout->spdif_formats,
2659 &mout->spdif_maxbps);
2660 }
2661 mutex_lock(&codec->spdif_mutex);
2662 if (mout->share_spdif) {
2663 runtime->hw.rates &= mout->spdif_rates;
2664 runtime->hw.formats &= mout->spdif_formats;
2665 if (mout->spdif_maxbps < hinfo->maxbps)
2666 hinfo->maxbps = mout->spdif_maxbps;
2667 }
2668 mutex_unlock(&codec->spdif_mutex);
2669 }
2532 return snd_pcm_hw_constraint_step(substream->runtime, 0, 2670 return snd_pcm_hw_constraint_step(substream->runtime, 0,
2533 SNDRV_PCM_HW_PARAM_CHANNELS, 2); 2671 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
2534} 2672}
@@ -2548,7 +2686,8 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2548 int i; 2686 int i;
2549 2687
2550 mutex_lock(&codec->spdif_mutex); 2688 mutex_lock(&codec->spdif_mutex);
2551 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { 2689 if (mout->dig_out_nid && mout->share_spdif &&
2690 mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
2552 if (chs == 2 && 2691 if (chs == 2 &&
2553 snd_hda_is_supported_format(codec, mout->dig_out_nid, 2692 snd_hda_is_supported_format(codec, mout->dig_out_nid,
2554 format) && 2693 format) &&
@@ -2558,8 +2697,7 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2558 stream_tag, format); 2697 stream_tag, format);
2559 } else { 2698 } else {
2560 mout->dig_out_used = 0; 2699 mout->dig_out_used = 0;
2561 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 2700 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2562 0, 0, 0);
2563 } 2701 }
2564 } 2702 }
2565 mutex_unlock(&codec->spdif_mutex); 2703 mutex_unlock(&codec->spdif_mutex);
@@ -2601,17 +2739,16 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
2601 int i; 2739 int i;
2602 2740
2603 for (i = 0; i < mout->num_dacs; i++) 2741 for (i = 0; i < mout->num_dacs; i++)
2604 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); 2742 snd_hda_codec_cleanup_stream(codec, nids[i]);
2605 if (mout->hp_nid) 2743 if (mout->hp_nid)
2606 snd_hda_codec_setup_stream(codec, mout->hp_nid, 0, 0, 0); 2744 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
2607 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) 2745 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
2608 if (mout->extra_out_nid[i]) 2746 if (mout->extra_out_nid[i])
2609 snd_hda_codec_setup_stream(codec, 2747 snd_hda_codec_cleanup_stream(codec,
2610 mout->extra_out_nid[i], 2748 mout->extra_out_nid[i]);
2611 0, 0, 0);
2612 mutex_lock(&codec->spdif_mutex); 2749 mutex_lock(&codec->spdif_mutex);
2613 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) { 2750 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
2614 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 0, 0, 0); 2751 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2615 mout->dig_out_used = 0; 2752 mout->dig_out_used = 0;
2616 } 2753 }
2617 mutex_unlock(&codec->spdif_mutex); 2754 mutex_unlock(&codec->spdif_mutex);
@@ -2790,6 +2927,30 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
2790 } 2927 }
2791 } 2928 }
2792 2929
2930 /* FIX-UP:
2931 * If no line-out is defined but multiple HPs are found,
2932 * some of them might be the real line-outs.
2933 */
2934 if (!cfg->line_outs && cfg->hp_outs > 1) {
2935 int i = 0;
2936 while (i < cfg->hp_outs) {
2937 /* The real HPs should have the sequence 0x0f */
2938 if ((sequences_hp[i] & 0x0f) == 0x0f) {
2939 i++;
2940 continue;
2941 }
2942 /* Move it to the line-out table */
2943 cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
2944 sequences_line_out[cfg->line_outs] = sequences_hp[i];
2945 cfg->line_outs++;
2946 cfg->hp_outs--;
2947 memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
2948 sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
2949 memmove(sequences_hp + i - 1, sequences_hp + i,
2950 sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
2951 }
2952 }
2953
2793 /* sort by sequence */ 2954 /* sort by sequence */
2794 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out, 2955 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
2795 cfg->line_outs); 2956 cfg->line_outs);
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index f14871151be9..dcd390b2bbaa 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -590,11 +590,21 @@ struct hda_pcm_stream {
590 struct hda_pcm_ops ops; 590 struct hda_pcm_ops ops;
591}; 591};
592 592
593/* PCM types */
594enum {
595 HDA_PCM_TYPE_AUDIO,
596 HDA_PCM_TYPE_SPDIF,
597 HDA_PCM_TYPE_HDMI,
598 HDA_PCM_TYPE_MODEM,
599 HDA_PCM_NTYPES
600};
601
593/* for PCM creation */ 602/* for PCM creation */
594struct hda_pcm { 603struct hda_pcm {
595 char *name; 604 char *name;
596 struct hda_pcm_stream stream[2]; 605 struct hda_pcm_stream stream[2];
597 unsigned int is_modem; /* modem codec? */ 606 unsigned int pcm_type; /* HDA_PCM_TYPE_XXX */
607 int device; /* assigned device number */
598}; 608};
599 609
600/* codec information */ 610/* codec information */
@@ -712,6 +722,7 @@ int snd_hda_build_pcms(struct hda_bus *bus);
712void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, 722void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
713 u32 stream_tag, 723 u32 stream_tag,
714 int channel_id, int format); 724 int channel_id, int format);
725void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid);
715unsigned int snd_hda_calc_stream_format(unsigned int rate, 726unsigned int snd_hda_calc_stream_format(unsigned int rate,
716 unsigned int channels, 727 unsigned int channels,
717 unsigned int format, 728 unsigned int format,
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index f9de7c467c25..59e4389c94a4 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -1007,8 +1007,8 @@ static int generic_pcm2_cleanup(struct hda_pcm_stream *hinfo,
1007{ 1007{
1008 struct hda_gspec *spec = codec->spec; 1008 struct hda_gspec *spec = codec->spec;
1009 1009
1010 snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0); 1010 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1011 snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid, 0, 0, 0); 1011 snd_hda_codec_cleanup_stream(codec, spec->dac_node[1]->nid);
1012 return 0; 1012 return 0;
1013} 1013}
1014 1014
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 4be36c84b36c..b3a618eb42cd 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -39,6 +39,7 @@
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/kernel.h> 40#include <linux/kernel.h>
41#include <linux/module.h> 41#include <linux/module.h>
42#include <linux/dma-mapping.h>
42#include <linux/moduleparam.h> 43#include <linux/moduleparam.h>
43#include <linux/init.h> 44#include <linux/init.h>
44#include <linux/slab.h> 45#include <linux/slab.h>
@@ -185,35 +186,28 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
185 186
186/* max number of SDs */ 187/* max number of SDs */
187/* ICH, ATI and VIA have 4 playback and 4 capture */ 188/* ICH, ATI and VIA have 4 playback and 4 capture */
188#define ICH6_CAPTURE_INDEX 0
189#define ICH6_NUM_CAPTURE 4 189#define ICH6_NUM_CAPTURE 4
190#define ICH6_PLAYBACK_INDEX 4
191#define ICH6_NUM_PLAYBACK 4 190#define ICH6_NUM_PLAYBACK 4
192 191
193/* ULI has 6 playback and 5 capture */ 192/* ULI has 6 playback and 5 capture */
194#define ULI_CAPTURE_INDEX 0
195#define ULI_NUM_CAPTURE 5 193#define ULI_NUM_CAPTURE 5
196#define ULI_PLAYBACK_INDEX 5
197#define ULI_NUM_PLAYBACK 6 194#define ULI_NUM_PLAYBACK 6
198 195
199/* ATI HDMI has 1 playback and 0 capture */ 196/* ATI HDMI has 1 playback and 0 capture */
200#define ATIHDMI_CAPTURE_INDEX 0
201#define ATIHDMI_NUM_CAPTURE 0 197#define ATIHDMI_NUM_CAPTURE 0
202#define ATIHDMI_PLAYBACK_INDEX 0
203#define ATIHDMI_NUM_PLAYBACK 1 198#define ATIHDMI_NUM_PLAYBACK 1
204 199
205/* this number is statically defined for simplicity */ 200/* this number is statically defined for simplicity */
206#define MAX_AZX_DEV 16 201#define MAX_AZX_DEV 16
207 202
208/* max number of fragments - we may use more if allocating more pages for BDL */ 203/* max number of fragments - we may use more if allocating more pages for BDL */
209#define BDL_SIZE PAGE_ALIGN(8192) 204#define BDL_SIZE 4096
210#define AZX_MAX_FRAG (BDL_SIZE / (MAX_AZX_DEV * 16)) 205#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
206#define AZX_MAX_FRAG 32
211/* max buffer size - no h/w limit, you can increase as you like */ 207/* max buffer size - no h/w limit, you can increase as you like */
212#define AZX_MAX_BUF_SIZE (1024*1024*1024) 208#define AZX_MAX_BUF_SIZE (1024*1024*1024)
213/* max number of PCM devics per card */ 209/* max number of PCM devics per card */
214#define AZX_MAX_AUDIO_PCMS 6 210#define AZX_MAX_PCMS 8
215#define AZX_MAX_MODEM_PCMS 2
216#define AZX_MAX_PCMS (AZX_MAX_AUDIO_PCMS + AZX_MAX_MODEM_PCMS)
217 211
218/* RIRB int mask: overrun[2], response[0] */ 212/* RIRB int mask: overrun[2], response[0] */
219#define RIRB_INT_RESPONSE 0x01 213#define RIRB_INT_RESPONSE 0x01
@@ -227,6 +221,9 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
227/* SD_CTL bits */ 221/* SD_CTL bits */
228#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */ 222#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
229#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */ 223#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
224#define SD_CTL_STRIPE (3 << 16) /* stripe control */
225#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
226#define SD_CTL_DIR (1 << 19) /* bi-directional stream */
230#define SD_CTL_STREAM_TAG_MASK (0xf << 20) 227#define SD_CTL_STREAM_TAG_MASK (0xf << 20)
231#define SD_CTL_STREAM_TAG_SHIFT 20 228#define SD_CTL_STREAM_TAG_SHIFT 20
232 229
@@ -284,12 +281,10 @@ enum {
284 */ 281 */
285 282
286struct azx_dev { 283struct azx_dev {
287 u32 *bdl; /* virtual address of the BDL */ 284 struct snd_dma_buffer bdl; /* BDL buffer */
288 dma_addr_t bdl_addr; /* physical address of the BDL */
289 u32 *posbuf; /* position buffer pointer */ 285 u32 *posbuf; /* position buffer pointer */
290 286
291 unsigned int bufsize; /* size of the play buffer in bytes */ 287 unsigned int bufsize; /* size of the play buffer in bytes */
292 unsigned int fragsize; /* size of each period in bytes */
293 unsigned int frags; /* number for period in the play buffer */ 288 unsigned int frags; /* number for period in the play buffer */
294 unsigned int fifo_size; /* FIFO size */ 289 unsigned int fifo_size; /* FIFO size */
295 290
@@ -350,7 +345,6 @@ struct azx {
350 struct azx_dev *azx_dev; 345 struct azx_dev *azx_dev;
351 346
352 /* PCM */ 347 /* PCM */
353 unsigned int pcm_devs;
354 struct snd_pcm *pcm[AZX_MAX_PCMS]; 348 struct snd_pcm *pcm[AZX_MAX_PCMS];
355 349
356 /* HD codec */ 350 /* HD codec */
@@ -361,8 +355,7 @@ struct azx {
361 struct azx_rb corb; 355 struct azx_rb corb;
362 struct azx_rb rirb; 356 struct azx_rb rirb;
363 357
364 /* BDL, CORB/RIRB and position buffers */ 358 /* CORB/RIRB and position buffers */
365 struct snd_dma_buffer bdl;
366 struct snd_dma_buffer rb; 359 struct snd_dma_buffer rb;
367 struct snd_dma_buffer posbuf; 360 struct snd_dma_buffer posbuf;
368 361
@@ -546,8 +539,9 @@ static void azx_update_rirb(struct azx *chip)
546 if (res_ex & ICH6_RIRB_EX_UNSOL_EV) 539 if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
547 snd_hda_queue_unsol_event(chip->bus, res, res_ex); 540 snd_hda_queue_unsol_event(chip->bus, res, res_ex);
548 else if (chip->rirb.cmds) { 541 else if (chip->rirb.cmds) {
549 chip->rirb.cmds--;
550 chip->rirb.res = res; 542 chip->rirb.res = res;
543 smp_wmb();
544 chip->rirb.cmds--;
551 } 545 }
552 } 546 }
553} 547}
@@ -566,8 +560,10 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec)
566 azx_update_rirb(chip); 560 azx_update_rirb(chip);
567 spin_unlock_irq(&chip->reg_lock); 561 spin_unlock_irq(&chip->reg_lock);
568 } 562 }
569 if (!chip->rirb.cmds) 563 if (!chip->rirb.cmds) {
564 smp_rmb();
570 return chip->rirb.res; /* the last value */ 565 return chip->rirb.res; /* the last value */
566 }
571 if (time_after(jiffies, timeout)) 567 if (time_after(jiffies, timeout))
572 break; 568 break;
573 if (codec->bus->needs_damn_long_delay) 569 if (codec->bus->needs_damn_long_delay)
@@ -965,30 +961,57 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
965/* 961/*
966 * set up BDL entries 962 * set up BDL entries
967 */ 963 */
968static void azx_setup_periods(struct azx_dev *azx_dev) 964static int azx_setup_periods(struct snd_pcm_substream *substream,
965 struct azx_dev *azx_dev)
969{ 966{
970 u32 *bdl = azx_dev->bdl; 967 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
971 dma_addr_t dma_addr = azx_dev->substream->runtime->dma_addr; 968 u32 *bdl;
972 int idx; 969 int i, ofs, periods, period_bytes;
973 970
974 /* reset BDL address */ 971 /* reset BDL address */
975 azx_sd_writel(azx_dev, SD_BDLPL, 0); 972 azx_sd_writel(azx_dev, SD_BDLPL, 0);
976 azx_sd_writel(azx_dev, SD_BDLPU, 0); 973 azx_sd_writel(azx_dev, SD_BDLPU, 0);
977 974
975 period_bytes = snd_pcm_lib_period_bytes(substream);
976 periods = azx_dev->bufsize / period_bytes;
977
978 /* program the initial BDL entries */ 978 /* program the initial BDL entries */
979 for (idx = 0; idx < azx_dev->frags; idx++) { 979 bdl = (u32 *)azx_dev->bdl.area;
980 unsigned int off = idx << 2; /* 4 dword step */ 980 ofs = 0;
981 dma_addr_t addr = dma_addr + idx * azx_dev->fragsize; 981 azx_dev->frags = 0;
982 /* program the address field of the BDL entry */ 982 for (i = 0; i < periods; i++) {
983 bdl[off] = cpu_to_le32((u32)addr); 983 int size, rest;
984 bdl[off+1] = cpu_to_le32(upper_32bit(addr)); 984 if (i >= AZX_MAX_BDL_ENTRIES) {
985 985 snd_printk(KERN_ERR "Too many BDL entries: "
986 /* program the size field of the BDL entry */ 986 "buffer=%d, period=%d\n",
987 bdl[off+2] = cpu_to_le32(azx_dev->fragsize); 987 azx_dev->bufsize, period_bytes);
988 988 /* reset */
989 /* program the IOC to enable interrupt when buffer completes */ 989 azx_sd_writel(azx_dev, SD_BDLPL, 0);
990 bdl[off+3] = cpu_to_le32(0x01); 990 azx_sd_writel(azx_dev, SD_BDLPU, 0);
991 return -EINVAL;
992 }
993 rest = period_bytes;
994 do {
995 dma_addr_t addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs);
996 /* program the address field of the BDL entry */
997 bdl[0] = cpu_to_le32((u32)addr);
998 bdl[1] = cpu_to_le32(upper_32bit(addr));
999 /* program the size field of the BDL entry */
1000 size = PAGE_SIZE - (ofs % PAGE_SIZE);
1001 if (rest < size)
1002 size = rest;
1003 bdl[2] = cpu_to_le32(size);
1004 /* program the IOC to enable interrupt
1005 * only when the whole fragment is processed
1006 */
1007 rest -= size;
1008 bdl[3] = rest ? 0 : cpu_to_le32(0x01);
1009 bdl += 4;
1010 azx_dev->frags++;
1011 ofs += size;
1012 } while (rest > 0);
991 } 1013 }
1014 return 0;
992} 1015}
993 1016
994/* 1017/*
@@ -1037,14 +1060,17 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1037 1060
1038 /* program the BDL address */ 1061 /* program the BDL address */
1039 /* lower BDL address */ 1062 /* lower BDL address */
1040 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl_addr); 1063 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
1041 /* upper BDL address */ 1064 /* upper BDL address */
1042 azx_sd_writel(azx_dev, SD_BDLPU, upper_32bit(azx_dev->bdl_addr)); 1065 azx_sd_writel(azx_dev, SD_BDLPU, upper_32bit(azx_dev->bdl.addr));
1043 1066
1044 /* enable the position buffer */ 1067 /* enable the position buffer */
1045 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE)) 1068 if (chip->position_fix == POS_FIX_POSBUF ||
1046 azx_writel(chip, DPLBASE, 1069 chip->position_fix == POS_FIX_AUTO) {
1047 (u32)chip->posbuf.addr |ICH6_DPLBASE_ENABLE); 1070 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
1071 azx_writel(chip, DPLBASE,
1072 (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
1073 }
1048 1074
1049 /* set the interrupt enable bits in the descriptor control register */ 1075 /* set the interrupt enable bits in the descriptor control register */
1050 azx_sd_writel(azx_dev, SD_CTL, 1076 azx_sd_writel(azx_dev, SD_CTL,
@@ -1157,7 +1183,8 @@ static struct snd_pcm_hardware azx_pcm_hw = {
1157 SNDRV_PCM_INFO_MMAP_VALID | 1183 SNDRV_PCM_INFO_MMAP_VALID |
1158 /* No full-resume yet implemented */ 1184 /* No full-resume yet implemented */
1159 /* SNDRV_PCM_INFO_RESUME |*/ 1185 /* SNDRV_PCM_INFO_RESUME |*/
1160 SNDRV_PCM_INFO_PAUSE), 1186 SNDRV_PCM_INFO_PAUSE |
1187 SNDRV_PCM_INFO_SYNC_START),
1161 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1188 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1162 .rates = SNDRV_PCM_RATE_48000, 1189 .rates = SNDRV_PCM_RATE_48000,
1163 .rate_min = 48000, 1190 .rate_min = 48000,
@@ -1219,6 +1246,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1219 spin_unlock_irqrestore(&chip->reg_lock, flags); 1246 spin_unlock_irqrestore(&chip->reg_lock, flags);
1220 1247
1221 runtime->private_data = azx_dev; 1248 runtime->private_data = azx_dev;
1249 snd_pcm_set_sync(substream);
1222 mutex_unlock(&chip->open_mutex); 1250 mutex_unlock(&chip->open_mutex);
1223 return 0; 1251 return 0;
1224} 1252}
@@ -1275,8 +1303,6 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1275 struct snd_pcm_runtime *runtime = substream->runtime; 1303 struct snd_pcm_runtime *runtime = substream->runtime;
1276 1304
1277 azx_dev->bufsize = snd_pcm_lib_buffer_bytes(substream); 1305 azx_dev->bufsize = snd_pcm_lib_buffer_bytes(substream);
1278 azx_dev->fragsize = snd_pcm_lib_period_bytes(substream);
1279 azx_dev->frags = azx_dev->bufsize / azx_dev->fragsize;
1280 azx_dev->format_val = snd_hda_calc_stream_format(runtime->rate, 1306 azx_dev->format_val = snd_hda_calc_stream_format(runtime->rate,
1281 runtime->channels, 1307 runtime->channels,
1282 runtime->format, 1308 runtime->format,
@@ -1288,10 +1314,10 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1288 return -EINVAL; 1314 return -EINVAL;
1289 } 1315 }
1290 1316
1291 snd_printdd("azx_pcm_prepare: bufsize=0x%x, fragsize=0x%x, " 1317 snd_printdd("azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
1292 "format=0x%x\n", 1318 azx_dev->bufsize, azx_dev->format_val);
1293 azx_dev->bufsize, azx_dev->fragsize, azx_dev->format_val); 1319 if (azx_setup_periods(substream, azx_dev) < 0)
1294 azx_setup_periods(azx_dev); 1320 return -EINVAL;
1295 azx_setup_controller(chip, azx_dev); 1321 azx_setup_controller(chip, azx_dev);
1296 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1322 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1297 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1; 1323 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
@@ -1305,37 +1331,94 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1305static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 1331static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1306{ 1332{
1307 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 1333 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1308 struct azx_dev *azx_dev = get_azx_dev(substream);
1309 struct azx *chip = apcm->chip; 1334 struct azx *chip = apcm->chip;
1310 int err = 0; 1335 struct azx_dev *azx_dev;
1336 struct snd_pcm_substream *s;
1337 int start, nsync = 0, sbits = 0;
1338 int nwait, timeout;
1311 1339
1312 spin_lock(&chip->reg_lock);
1313 switch (cmd) { 1340 switch (cmd) {
1314 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1341 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1315 case SNDRV_PCM_TRIGGER_RESUME: 1342 case SNDRV_PCM_TRIGGER_RESUME:
1316 case SNDRV_PCM_TRIGGER_START: 1343 case SNDRV_PCM_TRIGGER_START:
1317 azx_stream_start(chip, azx_dev); 1344 start = 1;
1318 azx_dev->running = 1;
1319 break; 1345 break;
1320 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1346 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1321 case SNDRV_PCM_TRIGGER_SUSPEND: 1347 case SNDRV_PCM_TRIGGER_SUSPEND:
1322 case SNDRV_PCM_TRIGGER_STOP: 1348 case SNDRV_PCM_TRIGGER_STOP:
1323 azx_stream_stop(chip, azx_dev); 1349 start = 0;
1324 azx_dev->running = 0;
1325 break; 1350 break;
1326 default: 1351 default:
1327 err = -EINVAL; 1352 return -EINVAL;
1353 }
1354
1355 snd_pcm_group_for_each_entry(s, substream) {
1356 if (s->pcm->card != substream->pcm->card)
1357 continue;
1358 azx_dev = get_azx_dev(s);
1359 sbits |= 1 << azx_dev->index;
1360 nsync++;
1361 snd_pcm_trigger_done(s, substream);
1362 }
1363
1364 spin_lock(&chip->reg_lock);
1365 if (nsync > 1) {
1366 /* first, set SYNC bits of corresponding streams */
1367 azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits);
1368 }
1369 snd_pcm_group_for_each_entry(s, substream) {
1370 if (s->pcm->card != substream->pcm->card)
1371 continue;
1372 azx_dev = get_azx_dev(s);
1373 if (start)
1374 azx_stream_start(chip, azx_dev);
1375 else
1376 azx_stream_stop(chip, azx_dev);
1377 azx_dev->running = start;
1328 } 1378 }
1329 spin_unlock(&chip->reg_lock); 1379 spin_unlock(&chip->reg_lock);
1330 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH || 1380 if (start) {
1331 cmd == SNDRV_PCM_TRIGGER_SUSPEND || 1381 if (nsync == 1)
1332 cmd == SNDRV_PCM_TRIGGER_STOP) { 1382 return 0;
1333 int timeout = 5000; 1383 /* wait until all FIFOs get ready */
1334 while ((azx_sd_readb(azx_dev, SD_CTL) & SD_CTL_DMA_START) && 1384 for (timeout = 5000; timeout; timeout--) {
1335 --timeout) 1385 nwait = 0;
1336 ; 1386 snd_pcm_group_for_each_entry(s, substream) {
1387 if (s->pcm->card != substream->pcm->card)
1388 continue;
1389 azx_dev = get_azx_dev(s);
1390 if (!(azx_sd_readb(azx_dev, SD_STS) &
1391 SD_STS_FIFO_READY))
1392 nwait++;
1393 }
1394 if (!nwait)
1395 break;
1396 cpu_relax();
1397 }
1398 } else {
1399 /* wait until all RUN bits are cleared */
1400 for (timeout = 5000; timeout; timeout--) {
1401 nwait = 0;
1402 snd_pcm_group_for_each_entry(s, substream) {
1403 if (s->pcm->card != substream->pcm->card)
1404 continue;
1405 azx_dev = get_azx_dev(s);
1406 if (azx_sd_readb(azx_dev, SD_CTL) &
1407 SD_CTL_DMA_START)
1408 nwait++;
1409 }
1410 if (!nwait)
1411 break;
1412 cpu_relax();
1413 }
1337 } 1414 }
1338 return err; 1415 if (nsync > 1) {
1416 spin_lock(&chip->reg_lock);
1417 /* reset SYNC bits */
1418 azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits);
1419 spin_unlock(&chip->reg_lock);
1420 }
1421 return 0;
1339} 1422}
1340 1423
1341static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) 1424static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
@@ -1378,6 +1461,7 @@ static struct snd_pcm_ops azx_pcm_ops = {
1378 .prepare = azx_pcm_prepare, 1461 .prepare = azx_pcm_prepare,
1379 .trigger = azx_pcm_trigger, 1462 .trigger = azx_pcm_trigger,
1380 .pointer = azx_pcm_pointer, 1463 .pointer = azx_pcm_pointer,
1464 .page = snd_pcm_sgbuf_ops_page,
1381}; 1465};
1382 1466
1383static void azx_pcm_free(struct snd_pcm *pcm) 1467static void azx_pcm_free(struct snd_pcm *pcm)
@@ -1386,7 +1470,7 @@ static void azx_pcm_free(struct snd_pcm *pcm)
1386} 1470}
1387 1471
1388static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec, 1472static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1389 struct hda_pcm *cpcm, int pcm_dev) 1473 struct hda_pcm *cpcm)
1390{ 1474{
1391 int err; 1475 int err;
1392 struct snd_pcm *pcm; 1476 struct snd_pcm *pcm;
@@ -1400,7 +1484,7 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1400 1484
1401 snd_assert(cpcm->name, return -EINVAL); 1485 snd_assert(cpcm->name, return -EINVAL);
1402 1486
1403 err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, 1487 err = snd_pcm_new(chip->card, cpcm->name, cpcm->device,
1404 cpcm->stream[0].substreams, 1488 cpcm->stream[0].substreams,
1405 cpcm->stream[1].substreams, 1489 cpcm->stream[1].substreams,
1406 &pcm); 1490 &pcm);
@@ -1420,62 +1504,70 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1420 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &azx_pcm_ops); 1504 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &azx_pcm_ops);
1421 if (cpcm->stream[1].substreams) 1505 if (cpcm->stream[1].substreams)
1422 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops); 1506 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops);
1423 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 1507 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1424 snd_dma_pci_data(chip->pci), 1508 snd_dma_pci_data(chip->pci),
1425 1024 * 64, 1024 * 1024); 1509 1024 * 64, 1024 * 1024);
1426 chip->pcm[pcm_dev] = pcm; 1510 chip->pcm[cpcm->device] = pcm;
1427 if (chip->pcm_devs < pcm_dev + 1)
1428 chip->pcm_devs = pcm_dev + 1;
1429
1430 return 0; 1511 return 0;
1431} 1512}
1432 1513
1433static int __devinit azx_pcm_create(struct azx *chip) 1514static int __devinit azx_pcm_create(struct azx *chip)
1434{ 1515{
1516 static const char *dev_name[HDA_PCM_NTYPES] = {
1517 "Audio", "SPDIF", "HDMI", "Modem"
1518 };
1519 /* starting device index for each PCM type */
1520 static int dev_idx[HDA_PCM_NTYPES] = {
1521 [HDA_PCM_TYPE_AUDIO] = 0,
1522 [HDA_PCM_TYPE_SPDIF] = 1,
1523 [HDA_PCM_TYPE_HDMI] = 3,
1524 [HDA_PCM_TYPE_MODEM] = 6
1525 };
1526 /* normal audio device indices; not linear to keep compatibility */
1527 static int audio_idx[4] = { 0, 2, 4, 5 };
1435 struct hda_codec *codec; 1528 struct hda_codec *codec;
1436 int c, err; 1529 int c, err;
1437 int pcm_dev; 1530 int num_devs[HDA_PCM_NTYPES];
1438 1531
1439 err = snd_hda_build_pcms(chip->bus); 1532 err = snd_hda_build_pcms(chip->bus);
1440 if (err < 0) 1533 if (err < 0)
1441 return err; 1534 return err;
1442 1535
1443 /* create audio PCMs */ 1536 /* create audio PCMs */
1444 pcm_dev = 0; 1537 memset(num_devs, 0, sizeof(num_devs));
1445 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1446 for (c = 0; c < codec->num_pcms; c++) {
1447 if (codec->pcm_info[c].is_modem)
1448 continue; /* create later */
1449 if (pcm_dev >= AZX_MAX_AUDIO_PCMS) {
1450 snd_printk(KERN_ERR SFX
1451 "Too many audio PCMs\n");
1452 return -EINVAL;
1453 }
1454 err = create_codec_pcm(chip, codec,
1455 &codec->pcm_info[c], pcm_dev);
1456 if (err < 0)
1457 return err;
1458 pcm_dev++;
1459 }
1460 }
1461
1462 /* create modem PCMs */
1463 pcm_dev = AZX_MAX_AUDIO_PCMS;
1464 list_for_each_entry(codec, &chip->bus->codec_list, list) { 1538 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1465 for (c = 0; c < codec->num_pcms; c++) { 1539 for (c = 0; c < codec->num_pcms; c++) {
1466 if (!codec->pcm_info[c].is_modem) 1540 struct hda_pcm *cpcm = &codec->pcm_info[c];
1467 continue; /* already created */ 1541 int type = cpcm->pcm_type;
1468 if (pcm_dev >= AZX_MAX_PCMS) { 1542 switch (type) {
1469 snd_printk(KERN_ERR SFX 1543 case HDA_PCM_TYPE_AUDIO:
1470 "Too many modem PCMs\n"); 1544 if (num_devs[type] >= ARRAY_SIZE(audio_idx)) {
1471 return -EINVAL; 1545 snd_printk(KERN_WARNING
1546 "Too many audio devices\n");
1547 continue;
1548 }
1549 cpcm->device = audio_idx[num_devs[type]];
1550 break;
1551 case HDA_PCM_TYPE_SPDIF:
1552 case HDA_PCM_TYPE_HDMI:
1553 case HDA_PCM_TYPE_MODEM:
1554 if (num_devs[type]) {
1555 snd_printk(KERN_WARNING
1556 "%s already defined\n",
1557 dev_name[type]);
1558 continue;
1559 }
1560 cpcm->device = dev_idx[type];
1561 break;
1562 default:
1563 snd_printk(KERN_WARNING
1564 "Invalid PCM type %d\n", type);
1565 continue;
1472 } 1566 }
1473 err = create_codec_pcm(chip, codec, 1567 num_devs[type]++;
1474 &codec->pcm_info[c], pcm_dev); 1568 err = create_codec_pcm(chip, codec, cpcm);
1475 if (err < 0) 1569 if (err < 0)
1476 return err; 1570 return err;
1477 chip->pcm[pcm_dev]->dev_class = SNDRV_PCM_CLASS_MODEM;
1478 pcm_dev++;
1479 } 1571 }
1480 } 1572 }
1481 return 0; 1573 return 0;
@@ -1502,10 +1594,7 @@ static int __devinit azx_init_stream(struct azx *chip)
1502 * and initialize 1594 * and initialize
1503 */ 1595 */
1504 for (i = 0; i < chip->num_streams; i++) { 1596 for (i = 0; i < chip->num_streams; i++) {
1505 unsigned int off = sizeof(u32) * (i * AZX_MAX_FRAG * 4);
1506 struct azx_dev *azx_dev = &chip->azx_dev[i]; 1597 struct azx_dev *azx_dev = &chip->azx_dev[i];
1507 azx_dev->bdl = (u32 *)(chip->bdl.area + off);
1508 azx_dev->bdl_addr = chip->bdl.addr + off;
1509 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8); 1598 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
1510 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ 1599 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
1511 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); 1600 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
@@ -1587,13 +1676,12 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state)
1587 int i; 1676 int i;
1588 1677
1589 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 1678 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1590 for (i = 0; i < chip->pcm_devs; i++) 1679 for (i = 0; i < AZX_MAX_PCMS; i++)
1591 snd_pcm_suspend_all(chip->pcm[i]); 1680 snd_pcm_suspend_all(chip->pcm[i]);
1592 if (chip->initialized) 1681 if (chip->initialized)
1593 snd_hda_suspend(chip->bus, state); 1682 snd_hda_suspend(chip->bus, state);
1594 azx_stop_chip(chip); 1683 azx_stop_chip(chip);
1595 if (chip->irq >= 0) { 1684 if (chip->irq >= 0) {
1596 synchronize_irq(chip->irq);
1597 free_irq(chip->irq, chip); 1685 free_irq(chip->irq, chip);
1598 chip->irq = -1; 1686 chip->irq = -1;
1599 } 1687 }
@@ -1641,24 +1729,26 @@ static int azx_resume(struct pci_dev *pci)
1641 */ 1729 */
1642static int azx_free(struct azx *chip) 1730static int azx_free(struct azx *chip)
1643{ 1731{
1732 int i;
1733
1644 if (chip->initialized) { 1734 if (chip->initialized) {
1645 int i;
1646 for (i = 0; i < chip->num_streams; i++) 1735 for (i = 0; i < chip->num_streams; i++)
1647 azx_stream_stop(chip, &chip->azx_dev[i]); 1736 azx_stream_stop(chip, &chip->azx_dev[i]);
1648 azx_stop_chip(chip); 1737 azx_stop_chip(chip);
1649 } 1738 }
1650 1739
1651 if (chip->irq >= 0) { 1740 if (chip->irq >= 0)
1652 synchronize_irq(chip->irq);
1653 free_irq(chip->irq, (void*)chip); 1741 free_irq(chip->irq, (void*)chip);
1654 }
1655 if (chip->msi) 1742 if (chip->msi)
1656 pci_disable_msi(chip->pci); 1743 pci_disable_msi(chip->pci);
1657 if (chip->remap_addr) 1744 if (chip->remap_addr)
1658 iounmap(chip->remap_addr); 1745 iounmap(chip->remap_addr);
1659 1746
1660 if (chip->bdl.area) 1747 if (chip->azx_dev) {
1661 snd_dma_free_pages(&chip->bdl); 1748 for (i = 0; i < chip->num_streams; i++)
1749 if (chip->azx_dev[i].bdl.area)
1750 snd_dma_free_pages(&chip->azx_dev[i].bdl);
1751 }
1662 if (chip->rb.area) 1752 if (chip->rb.area)
1663 snd_dma_free_pages(&chip->rb); 1753 snd_dma_free_pages(&chip->rb);
1664 if (chip->posbuf.area) 1754 if (chip->posbuf.area)
@@ -1682,6 +1772,7 @@ static int azx_dev_free(struct snd_device *device)
1682static struct snd_pci_quirk position_fix_list[] __devinitdata = { 1772static struct snd_pci_quirk position_fix_list[] __devinitdata = {
1683 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_NONE), 1773 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_NONE),
1684 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_NONE), 1774 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_NONE),
1775 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_NONE),
1685 {} 1776 {}
1686}; 1777};
1687 1778
@@ -1740,7 +1831,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
1740 struct azx **rchip) 1831 struct azx **rchip)
1741{ 1832{
1742 struct azx *chip; 1833 struct azx *chip;
1743 int err; 1834 int i, err;
1744 unsigned short gcap; 1835 unsigned short gcap;
1745 static struct snd_device_ops ops = { 1836 static struct snd_device_ops ops = {
1746 .dev_free = azx_dev_free, 1837 .dev_free = azx_dev_free,
@@ -1812,38 +1903,35 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
1812 gcap = azx_readw(chip, GCAP); 1903 gcap = azx_readw(chip, GCAP);
1813 snd_printdd("chipset global capabilities = 0x%x\n", gcap); 1904 snd_printdd("chipset global capabilities = 0x%x\n", gcap);
1814 1905
1815 if (gcap) { 1906 /* allow 64bit DMA address if supported by H/W */
1816 /* read number of streams from GCAP register instead of using 1907 if ((gcap & 0x01) && !pci_set_dma_mask(pci, DMA_64BIT_MASK))
1817 * hardcoded value 1908 pci_set_consistent_dma_mask(pci, DMA_64BIT_MASK);
1818 */ 1909
1819 chip->playback_streams = (gcap & (0xF << 12)) >> 12; 1910 /* read number of streams from GCAP register instead of using
1820 chip->capture_streams = (gcap & (0xF << 8)) >> 8; 1911 * hardcoded value
1821 chip->playback_index_offset = chip->capture_streams; 1912 */
1822 chip->capture_index_offset = 0; 1913 chip->capture_streams = (gcap >> 8) & 0x0f;
1823 } else { 1914 chip->playback_streams = (gcap >> 12) & 0x0f;
1915 if (!chip->playback_streams && !chip->capture_streams) {
1824 /* gcap didn't give any info, switching to old method */ 1916 /* gcap didn't give any info, switching to old method */
1825 1917
1826 switch (chip->driver_type) { 1918 switch (chip->driver_type) {
1827 case AZX_DRIVER_ULI: 1919 case AZX_DRIVER_ULI:
1828 chip->playback_streams = ULI_NUM_PLAYBACK; 1920 chip->playback_streams = ULI_NUM_PLAYBACK;
1829 chip->capture_streams = ULI_NUM_CAPTURE; 1921 chip->capture_streams = ULI_NUM_CAPTURE;
1830 chip->playback_index_offset = ULI_PLAYBACK_INDEX;
1831 chip->capture_index_offset = ULI_CAPTURE_INDEX;
1832 break; 1922 break;
1833 case AZX_DRIVER_ATIHDMI: 1923 case AZX_DRIVER_ATIHDMI:
1834 chip->playback_streams = ATIHDMI_NUM_PLAYBACK; 1924 chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
1835 chip->capture_streams = ATIHDMI_NUM_CAPTURE; 1925 chip->capture_streams = ATIHDMI_NUM_CAPTURE;
1836 chip->playback_index_offset = ATIHDMI_PLAYBACK_INDEX;
1837 chip->capture_index_offset = ATIHDMI_CAPTURE_INDEX;
1838 break; 1926 break;
1839 default: 1927 default:
1840 chip->playback_streams = ICH6_NUM_PLAYBACK; 1928 chip->playback_streams = ICH6_NUM_PLAYBACK;
1841 chip->capture_streams = ICH6_NUM_CAPTURE; 1929 chip->capture_streams = ICH6_NUM_CAPTURE;
1842 chip->playback_index_offset = ICH6_PLAYBACK_INDEX;
1843 chip->capture_index_offset = ICH6_CAPTURE_INDEX;
1844 break; 1930 break;
1845 } 1931 }
1846 } 1932 }
1933 chip->capture_index_offset = 0;
1934 chip->playback_index_offset = chip->capture_streams;
1847 chip->num_streams = chip->playback_streams + chip->capture_streams; 1935 chip->num_streams = chip->playback_streams + chip->capture_streams;
1848 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), 1936 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
1849 GFP_KERNEL); 1937 GFP_KERNEL);
@@ -1852,13 +1940,15 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
1852 goto errout; 1940 goto errout;
1853 } 1941 }
1854 1942
1855 /* allocate memory for the BDL for each stream */ 1943 for (i = 0; i < chip->num_streams; i++) {
1856 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 1944 /* allocate memory for the BDL for each stream */
1857 snd_dma_pci_data(chip->pci), 1945 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
1858 BDL_SIZE, &chip->bdl); 1946 snd_dma_pci_data(chip->pci),
1859 if (err < 0) { 1947 BDL_SIZE, &chip->azx_dev[i].bdl);
1860 snd_printk(KERN_ERR SFX "cannot allocate BDL\n"); 1948 if (err < 0) {
1861 goto errout; 1949 snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
1950 goto errout;
1951 }
1862 } 1952 }
1863 /* allocate memory for the position buffer */ 1953 /* allocate memory for the position buffer */
1864 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 1954 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
@@ -1994,48 +2084,63 @@ static void __devexit azx_remove(struct pci_dev *pci)
1994 2084
1995/* PCI IDs */ 2085/* PCI IDs */
1996static struct pci_device_id azx_ids[] = { 2086static struct pci_device_id azx_ids[] = {
1997 { 0x8086, 0x2668, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH6 */ 2087 /* ICH 6..10 */
1998 { 0x8086, 0x27d8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH7 */ 2088 { PCI_DEVICE(0x8086, 0x2668), .driver_data = AZX_DRIVER_ICH },
1999 { 0x8086, 0x269a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ESB2 */ 2089 { PCI_DEVICE(0x8086, 0x27d8), .driver_data = AZX_DRIVER_ICH },
2000 { 0x8086, 0x284b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH8 */ 2090 { PCI_DEVICE(0x8086, 0x269a), .driver_data = AZX_DRIVER_ICH },
2001 { 0x8086, 0x293e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH9 */ 2091 { PCI_DEVICE(0x8086, 0x284b), .driver_data = AZX_DRIVER_ICH },
2002 { 0x8086, 0x293f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH9 */ 2092 { PCI_DEVICE(0x8086, 0x293e), .driver_data = AZX_DRIVER_ICH },
2003 { 0x8086, 0x3a3e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH10 */ 2093 { PCI_DEVICE(0x8086, 0x293f), .driver_data = AZX_DRIVER_ICH },
2004 { 0x8086, 0x3a6e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH10 */ 2094 { PCI_DEVICE(0x8086, 0x3a3e), .driver_data = AZX_DRIVER_ICH },
2005 { 0x8086, 0x811b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SCH }, /* SCH*/ 2095 { PCI_DEVICE(0x8086, 0x3a6e), .driver_data = AZX_DRIVER_ICH },
2006 { 0x1002, 0x437b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATI }, /* ATI SB450 */ 2096 /* SCH */
2007 { 0x1002, 0x4383, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATI }, /* ATI SB600 */ 2097 { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH },
2008 { 0x1002, 0x793b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS600 HDMI */ 2098 /* ATI SB 450/600 */
2009 { 0x1002, 0x7919, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS690 HDMI */ 2099 { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI },
2010 { 0x1002, 0x960f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS780 HDMI */ 2100 { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI },
2011 { 0x1002, 0xaa00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI R600 HDMI */ 2101 /* ATI HDMI */
2012 { 0x1002, 0xaa08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV630 HDMI */ 2102 { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI },
2013 { 0x1002, 0xaa10, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV610 HDMI */ 2103 { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI },
2014 { 0x1002, 0xaa18, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV670 HDMI */ 2104 { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI },
2015 { 0x1002, 0xaa20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV635 HDMI */ 2105 { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI },
2016 { 0x1002, 0xaa28, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV620 HDMI */ 2106 { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI },
2017 { 0x1002, 0xaa30, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV770 HDMI */ 2107 { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI },
2018 { 0x1106, 0x3288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_VIA }, /* VIA VT8251/VT8237A */ 2108 { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI },
2019 { 0x1039, 0x7502, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SIS }, /* SIS966 */ 2109 { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI },
2020 { 0x10b9, 0x5461, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ULI }, /* ULI M5461 */ 2110 { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI },
2021 { 0x10de, 0x026c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP51 */ 2111 { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI },
2022 { 0x10de, 0x0371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP55 */ 2112 { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI },
2023 { 0x10de, 0x03e4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP61 */ 2113 { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI },
2024 { 0x10de, 0x03f0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP61 */ 2114 { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI },
2025 { 0x10de, 0x044a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP65 */ 2115 /* VIA VT8251/VT8237A */
2026 { 0x10de, 0x044b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP65 */ 2116 { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
2027 { 0x10de, 0x055c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP67 */ 2117 /* SIS966 */
2028 { 0x10de, 0x055d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP67 */ 2118 { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
2029 { 0x10de, 0x07fc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP73 */ 2119 /* ULI M5461 */
2030 { 0x10de, 0x07fd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP73 */ 2120 { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
2031 { 0x10de, 0x0774, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2121 /* NVIDIA MCP */
2032 { 0x10de, 0x0775, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2122 { PCI_DEVICE(0x10de, 0x026c), .driver_data = AZX_DRIVER_NVIDIA },
2033 { 0x10de, 0x0776, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2123 { PCI_DEVICE(0x10de, 0x0371), .driver_data = AZX_DRIVER_NVIDIA },
2034 { 0x10de, 0x0777, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2124 { PCI_DEVICE(0x10de, 0x03e4), .driver_data = AZX_DRIVER_NVIDIA },
2035 { 0x10de, 0x0ac0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2125 { PCI_DEVICE(0x10de, 0x03f0), .driver_data = AZX_DRIVER_NVIDIA },
2036 { 0x10de, 0x0ac1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2126 { PCI_DEVICE(0x10de, 0x044a), .driver_data = AZX_DRIVER_NVIDIA },
2037 { 0x10de, 0x0ac2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2127 { PCI_DEVICE(0x10de, 0x044b), .driver_data = AZX_DRIVER_NVIDIA },
2038 { 0x10de, 0x0ac3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2128 { PCI_DEVICE(0x10de, 0x055c), .driver_data = AZX_DRIVER_NVIDIA },
2129 { PCI_DEVICE(0x10de, 0x055d), .driver_data = AZX_DRIVER_NVIDIA },
2130 { PCI_DEVICE(0x10de, 0x0774), .driver_data = AZX_DRIVER_NVIDIA },
2131 { PCI_DEVICE(0x10de, 0x0775), .driver_data = AZX_DRIVER_NVIDIA },
2132 { PCI_DEVICE(0x10de, 0x0776), .driver_data = AZX_DRIVER_NVIDIA },
2133 { PCI_DEVICE(0x10de, 0x0777), .driver_data = AZX_DRIVER_NVIDIA },
2134 { PCI_DEVICE(0x10de, 0x07fc), .driver_data = AZX_DRIVER_NVIDIA },
2135 { PCI_DEVICE(0x10de, 0x07fd), .driver_data = AZX_DRIVER_NVIDIA },
2136 { PCI_DEVICE(0x10de, 0x0ac0), .driver_data = AZX_DRIVER_NVIDIA },
2137 { PCI_DEVICE(0x10de, 0x0ac1), .driver_data = AZX_DRIVER_NVIDIA },
2138 { PCI_DEVICE(0x10de, 0x0ac2), .driver_data = AZX_DRIVER_NVIDIA },
2139 { PCI_DEVICE(0x10de, 0x0ac3), .driver_data = AZX_DRIVER_NVIDIA },
2140 { PCI_DEVICE(0x10de, 0x0bd4), .driver_data = AZX_DRIVER_NVIDIA },
2141 { PCI_DEVICE(0x10de, 0x0bd5), .driver_data = AZX_DRIVER_NVIDIA },
2142 { PCI_DEVICE(0x10de, 0x0bd6), .driver_data = AZX_DRIVER_NVIDIA },
2143 { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA },
2039 { 0, } 2144 { 0, }
2040}; 2145};
2041MODULE_DEVICE_TABLE(pci, azx_ids); 2146MODULE_DEVICE_TABLE(pci, azx_ids);
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index ad0014ab71f9..5c9e578f7f2d 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -228,8 +228,18 @@ struct hda_multi_out {
228 int max_channels; /* currently supported analog channels */ 228 int max_channels; /* currently supported analog channels */
229 int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */ 229 int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */
230 int no_share_stream; /* don't share a stream with multiple pins */ 230 int no_share_stream; /* don't share a stream with multiple pins */
231 int share_spdif; /* share SPDIF pin */
232 /* PCM information for both analog and SPDIF DACs */
233 unsigned int analog_rates;
234 unsigned int analog_maxbps;
235 u64 analog_formats;
236 unsigned int spdif_rates;
237 unsigned int spdif_maxbps;
238 u64 spdif_formats;
231}; 239};
232 240
241int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
242 struct hda_multi_out *mout);
233int snd_hda_multi_out_dig_open(struct hda_codec *codec, 243int snd_hda_multi_out_dig_open(struct hda_codec *codec,
234 struct hda_multi_out *mout); 244 struct hda_multi_out *mout);
235int snd_hda_multi_out_dig_close(struct hda_codec *codec, 245int snd_hda_multi_out_dig_close(struct hda_codec *codec,
@@ -241,7 +251,8 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
241 struct snd_pcm_substream *substream); 251 struct snd_pcm_substream *substream);
242int snd_hda_multi_out_analog_open(struct hda_codec *codec, 252int snd_hda_multi_out_analog_open(struct hda_codec *codec,
243 struct hda_multi_out *mout, 253 struct hda_multi_out *mout,
244 struct snd_pcm_substream *substream); 254 struct snd_pcm_substream *substream,
255 struct hda_pcm_stream *hinfo);
245int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, 256int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
246 struct hda_multi_out *mout, 257 struct hda_multi_out *mout,
247 unsigned int stream_tag, 258 unsigned int stream_tag,
@@ -407,11 +418,4 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
407 hda_nid_t nid); 418 hda_nid_t nid);
408#endif /* CONFIG_SND_HDA_POWER_SAVE */ 419#endif /* CONFIG_SND_HDA_POWER_SAVE */
409 420
410/*
411 * virtual master control
412 */
413struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
414 const unsigned int *tlv);
415int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave);
416
417#endif /* __SOUND_HDA_LOCAL_H */ 421#endif /* __SOUND_HDA_LOCAL_H */
diff --git a/sound/pci/hda/hda_patch.h b/sound/pci/hda/hda_patch.h
index f5c23bb16d7e..2fdf2358dbc2 100644
--- a/sound/pci/hda/hda_patch.h
+++ b/sound/pci/hda/hda_patch.h
@@ -18,31 +18,3 @@ extern struct hda_codec_preset snd_hda_preset_atihdmi[];
18extern struct hda_codec_preset snd_hda_preset_conexant[]; 18extern struct hda_codec_preset snd_hda_preset_conexant[];
19/* VIA codecs */ 19/* VIA codecs */
20extern struct hda_codec_preset snd_hda_preset_via[]; 20extern struct hda_codec_preset snd_hda_preset_via[];
21
22static const struct hda_codec_preset *hda_preset_tables[] = {
23#ifdef CONFIG_SND_HDA_CODEC_REALTEK
24 snd_hda_preset_realtek,
25#endif
26#ifdef CONFIG_SND_HDA_CODEC_CMEDIA
27 snd_hda_preset_cmedia,
28#endif
29#ifdef CONFIG_SND_HDA_CODEC_ANALOG
30 snd_hda_preset_analog,
31#endif
32#ifdef CONFIG_SND_HDA_CODEC_SIGMATEL
33 snd_hda_preset_sigmatel,
34#endif
35#ifdef CONFIG_SND_HDA_CODEC_SI3054
36 snd_hda_preset_si3054,
37#endif
38#ifdef CONFIG_SND_HDA_CODEC_ATIHDMI
39 snd_hda_preset_atihdmi,
40#endif
41#ifdef CONFIG_SND_HDA_CODEC_CONEXANT
42 snd_hda_preset_conexant,
43#endif
44#ifdef CONFIG_SND_HDA_CODEC_VIA
45 snd_hda_preset_via,
46#endif
47 NULL
48};
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index c8649282c2cf..e0a605adde42 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -28,6 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31#include "hda_patch.h"
31 32
32struct ad198x_spec { 33struct ad198x_spec {
33 struct snd_kcontrol_new *mixers[5]; 34 struct snd_kcontrol_new *mixers[5];
@@ -80,7 +81,6 @@ struct ad198x_spec {
80#endif 81#endif
81 /* for virtual master */ 82 /* for virtual master */
82 hda_nid_t vmaster_nid; 83 hda_nid_t vmaster_nid;
83 u32 vmaster_tlv[4];
84 const char **slave_vols; 84 const char **slave_vols;
85 const char **slave_sws; 85 const char **slave_sws;
86}; 86};
@@ -171,6 +171,11 @@ static int ad198x_build_controls(struct hda_codec *codec)
171 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 171 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
172 if (err < 0) 172 if (err < 0)
173 return err; 173 return err;
174 err = snd_hda_create_spdif_share_sw(codec,
175 &spec->multiout);
176 if (err < 0)
177 return err;
178 spec->multiout.share_spdif = 1;
174 } 179 }
175 if (spec->dig_in_nid) { 180 if (spec->dig_in_nid) {
176 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 181 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -180,10 +185,11 @@ static int ad198x_build_controls(struct hda_codec *codec)
180 185
181 /* if we have no master control, let's create it */ 186 /* if we have no master control, let's create it */
182 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 187 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
188 unsigned int vmaster_tlv[4];
183 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 189 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
184 HDA_OUTPUT, spec->vmaster_tlv); 190 HDA_OUTPUT, vmaster_tlv);
185 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 191 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
186 spec->vmaster_tlv, 192 vmaster_tlv,
187 (spec->slave_vols ? 193 (spec->slave_vols ?
188 spec->slave_vols : ad_slave_vols)); 194 spec->slave_vols : ad_slave_vols));
189 if (err < 0) 195 if (err < 0)
@@ -217,7 +223,8 @@ static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
217 struct snd_pcm_substream *substream) 223 struct snd_pcm_substream *substream)
218{ 224{
219 struct ad198x_spec *spec = codec->spec; 225 struct ad198x_spec *spec = codec->spec;
220 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 226 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
227 hinfo);
221} 228}
222 229
223static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 230static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -289,8 +296,7 @@ static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
289 struct snd_pcm_substream *substream) 296 struct snd_pcm_substream *substream)
290{ 297{
291 struct ad198x_spec *spec = codec->spec; 298 struct ad198x_spec *spec = codec->spec;
292 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 299 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
293 0, 0, 0);
294 return 0; 300 return 0;
295} 301}
296 302
@@ -359,6 +365,7 @@ static int ad198x_build_pcms(struct hda_codec *codec)
359 info++; 365 info++;
360 codec->num_pcms++; 366 codec->num_pcms++;
361 info->name = "AD198x Digital"; 367 info->name = "AD198x Digital";
368 info->pcm_type = HDA_PCM_TYPE_SPDIF;
362 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback; 369 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
363 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 370 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
364 if (spec->dig_in_nid) { 371 if (spec->dig_in_nid) {
@@ -611,13 +618,19 @@ static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
611 }, 618 },
612}; 619};
613 620
621static struct hda_input_mux ad1986a_automic_capture_source = {
622 .num_items = 2,
623 .items = {
624 { "Mic", 0x0 },
625 { "Mix", 0x5 },
626 },
627};
628
614static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = { 629static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
615 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol), 630 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
616 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw), 631 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
617 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT), 632 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
618 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), 633 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
619 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
620 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
621 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 634 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
622 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), 635 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
623 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT), 636 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
@@ -641,6 +654,33 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
641 { } /* end */ 654 { } /* end */
642}; 655};
643 656
657/* re-connect the mic boost input according to the jack sensing */
658static void ad1986a_automic(struct hda_codec *codec)
659{
660 unsigned int present;
661 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0);
662 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
663 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
664 (present & AC_PINSENSE_PRESENCE) ? 0 : 2);
665}
666
667#define AD1986A_MIC_EVENT 0x36
668
669static void ad1986a_automic_unsol_event(struct hda_codec *codec,
670 unsigned int res)
671{
672 if ((res >> 26) != AD1986A_MIC_EVENT)
673 return;
674 ad1986a_automic(codec);
675}
676
677static int ad1986a_automic_init(struct hda_codec *codec)
678{
679 ad198x_init(codec);
680 ad1986a_automic(codec);
681 return 0;
682}
683
644/* laptop-automute - 2ch only */ 684/* laptop-automute - 2ch only */
645 685
646static void ad1986a_update_hp(struct hda_codec *codec) 686static void ad1986a_update_hp(struct hda_codec *codec)
@@ -844,6 +884,15 @@ static struct hda_verb ad1986a_eapd_init_verbs[] = {
844 {} 884 {}
845}; 885};
846 886
887static struct hda_verb ad1986a_automic_verbs[] = {
888 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
889 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
890 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
891 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
892 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
893 {}
894};
895
847/* Ultra initialization */ 896/* Ultra initialization */
848static struct hda_verb ad1986a_ultra_init[] = { 897static struct hda_verb ad1986a_ultra_init[] = {
849 /* eapd initialization */ 898 /* eapd initialization */
@@ -986,14 +1035,17 @@ static int patch_ad1986a(struct hda_codec *codec)
986 break; 1035 break;
987 case AD1986A_LAPTOP_EAPD: 1036 case AD1986A_LAPTOP_EAPD:
988 spec->mixers[0] = ad1986a_laptop_eapd_mixers; 1037 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
989 spec->num_init_verbs = 2; 1038 spec->num_init_verbs = 3;
990 spec->init_verbs[1] = ad1986a_eapd_init_verbs; 1039 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1040 spec->init_verbs[2] = ad1986a_automic_verbs;
991 spec->multiout.max_channels = 2; 1041 spec->multiout.max_channels = 2;
992 spec->multiout.num_dacs = 1; 1042 spec->multiout.num_dacs = 1;
993 spec->multiout.dac_nids = ad1986a_laptop_dac_nids; 1043 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
994 if (!is_jack_available(codec, 0x25)) 1044 if (!is_jack_available(codec, 0x25))
995 spec->multiout.dig_out_nid = 0; 1045 spec->multiout.dig_out_nid = 0;
996 spec->input_mux = &ad1986a_laptop_eapd_capture_source; 1046 spec->input_mux = &ad1986a_automic_capture_source;
1047 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1048 codec->patch_ops.init = ad1986a_automic_init;
997 break; 1049 break;
998 case AD1986A_LAPTOP_AUTOMUTE: 1050 case AD1986A_LAPTOP_AUTOMUTE:
999 spec->mixers[0] = ad1986a_laptop_automute_mixers; 1051 spec->mixers[0] = ad1986a_laptop_automute_mixers;
@@ -1365,7 +1417,10 @@ static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1365 1417
1366 if (! ad198x_eapd_put(kcontrol, ucontrol)) 1418 if (! ad198x_eapd_put(kcontrol, ucontrol))
1367 return 0; 1419 return 0;
1368 1420 /* change speaker pin appropriately */
1421 snd_hda_codec_write(codec, 0x05, 0,
1422 AC_VERB_SET_PIN_WIDGET_CONTROL,
1423 spec->cur_eapd ? PIN_OUT : 0);
1369 /* toggle HP mute appropriately */ 1424 /* toggle HP mute appropriately */
1370 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0, 1425 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1371 HDA_AMP_MUTE, 1426 HDA_AMP_MUTE,
@@ -2087,6 +2142,10 @@ static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2087 { } /* end */ 2142 { } /* end */
2088}; 2143};
2089 2144
2145static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2146 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2147 { } /* end */
2148};
2090 2149
2091/* 2150/*
2092 * initialization verbs 2151 * initialization verbs
@@ -2187,6 +2246,13 @@ static struct hda_verb ad1988_spdif_init_verbs[] = {
2187 { } 2246 { }
2188}; 2247};
2189 2248
2249/* AD1989 has no ADC -> SPDIF route */
2250static struct hda_verb ad1989_spdif_init_verbs[] = {
2251 /* SPDIF out pin */
2252 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2253 { }
2254};
2255
2190/* 2256/*
2191 * verbs for 3stack (+dig) 2257 * verbs for 3stack (+dig)
2192 */ 2258 */
@@ -2894,10 +2960,19 @@ static int patch_ad1988(struct hda_codec *codec)
2894 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers; 2960 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2895 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs; 2961 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2896 if (spec->multiout.dig_out_nid) { 2962 if (spec->multiout.dig_out_nid) {
2897 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers; 2963 if (codec->vendor_id >= 0x11d4989a) {
2898 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs; 2964 spec->mixers[spec->num_mixers++] =
2965 ad1989_spdif_out_mixers;
2966 spec->init_verbs[spec->num_init_verbs++] =
2967 ad1989_spdif_init_verbs;
2968 } else {
2969 spec->mixers[spec->num_mixers++] =
2970 ad1988_spdif_out_mixers;
2971 spec->init_verbs[spec->num_init_verbs++] =
2972 ad1988_spdif_init_verbs;
2973 }
2899 } 2974 }
2900 if (spec->dig_in_nid) 2975 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
2901 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers; 2976 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2902 2977
2903 codec->patch_ops = ad198x_patch_ops; 2978 codec->patch_ops = ad198x_patch_ops;
@@ -3133,11 +3208,12 @@ static int patch_ad1884(struct hda_codec *codec)
3133 * Lenovo Thinkpad T61/X61 3208 * Lenovo Thinkpad T61/X61
3134 */ 3209 */
3135static struct hda_input_mux ad1984_thinkpad_capture_source = { 3210static struct hda_input_mux ad1984_thinkpad_capture_source = {
3136 .num_items = 3, 3211 .num_items = 4,
3137 .items = { 3212 .items = {
3138 { "Mic", 0x0 }, 3213 { "Mic", 0x0 },
3139 { "Internal Mic", 0x1 }, 3214 { "Internal Mic", 0x1 },
3140 { "Mix", 0x3 }, 3215 { "Mix", 0x3 },
3216 { "Docking-Station", 0x4 },
3141 }, 3217 },
3142}; 3218};
3143 3219
@@ -3268,8 +3344,7 @@ static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3268 struct hda_codec *codec, 3344 struct hda_codec *codec,
3269 struct snd_pcm_substream *substream) 3345 struct snd_pcm_substream *substream)
3270{ 3346{
3271 snd_hda_codec_setup_stream(codec, 0x05 + substream->number, 3347 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
3272 0, 0, 0);
3273 return 0; 3348 return 0;
3274} 3349}
3275 3350
@@ -3356,6 +3431,472 @@ static int patch_ad1984(struct hda_codec *codec)
3356 3431
3357 3432
3358/* 3433/*
3434 * AD1883 / AD1884A / AD1984A / AD1984B
3435 *
3436 * port-B (0x14) - front mic-in
3437 * port-E (0x1c) - rear mic-in
3438 * port-F (0x16) - CD / ext out
3439 * port-C (0x15) - rear line-in
3440 * port-D (0x12) - rear line-out
3441 * port-A (0x11) - front hp-out
3442 *
3443 * AD1984A = AD1884A + digital-mic
3444 * AD1883 = equivalent with AD1984A
3445 * AD1984B = AD1984A + extra SPDIF-out
3446 *
3447 * FIXME:
3448 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3449 */
3450
3451static hda_nid_t ad1884a_dac_nids[1] = {
3452 0x03,
3453};
3454
3455#define ad1884a_adc_nids ad1884_adc_nids
3456#define ad1884a_capsrc_nids ad1884_capsrc_nids
3457
3458#define AD1884A_SPDIF_OUT 0x02
3459
3460static struct hda_input_mux ad1884a_capture_source = {
3461 .num_items = 5,
3462 .items = {
3463 { "Front Mic", 0x0 },
3464 { "Mic", 0x4 },
3465 { "Line", 0x1 },
3466 { "CD", 0x2 },
3467 { "Mix", 0x3 },
3468 },
3469};
3470
3471static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3472 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3473 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3474 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3475 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3476 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3477 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3478 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3479 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3480 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3481 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3482 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3483 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3484 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3485 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3486 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3487 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3488 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3489 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3490 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3491 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3492 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3493 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3494 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3495 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3496 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3497 {
3498 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3499 /* The multiple "Capture Source" controls confuse alsamixer
3500 * So call somewhat different..
3501 */
3502 /* .name = "Capture Source", */
3503 .name = "Input Source",
3504 .count = 2,
3505 .info = ad198x_mux_enum_info,
3506 .get = ad198x_mux_enum_get,
3507 .put = ad198x_mux_enum_put,
3508 },
3509 /* SPDIF controls */
3510 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3511 {
3512 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3513 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3514 /* identical with ad1983 */
3515 .info = ad1983_spdif_route_info,
3516 .get = ad1983_spdif_route_get,
3517 .put = ad1983_spdif_route_put,
3518 },
3519 { } /* end */
3520};
3521
3522/*
3523 * initialization verbs
3524 */
3525static struct hda_verb ad1884a_init_verbs[] = {
3526 /* DACs; unmute as default */
3527 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3528 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3529 /* Port-A (HP) mixer - route only from analog mixer */
3530 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3531 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3532 /* Port-A pin */
3533 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3534 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3535 /* Port-D (Line-out) mixer - route only from analog mixer */
3536 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3537 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3538 /* Port-D pin */
3539 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3540 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3541 /* Mono-out mixer - route only from analog mixer */
3542 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3543 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3544 /* Mono-out pin */
3545 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3546 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3547 /* Port-B (front mic) pin */
3548 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3549 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3550 /* Port-C (rear line-in) pin */
3551 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3552 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3553 /* Port-E (rear mic) pin */
3554 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3555 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3556 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3557 /* Port-F (CD) pin */
3558 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3559 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3560 /* Analog mixer; mute as default */
3561 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3562 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3563 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3564 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3565 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3566 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3567 /* Analog Mix output amp */
3568 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3569 /* capture sources */
3570 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3571 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3572 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3573 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3574 /* SPDIF output amp */
3575 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3576 { } /* end */
3577};
3578
3579#ifdef CONFIG_SND_HDA_POWER_SAVE
3580static struct hda_amp_list ad1884a_loopbacks[] = {
3581 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3582 { 0x20, HDA_INPUT, 1 }, /* Mic */
3583 { 0x20, HDA_INPUT, 2 }, /* CD */
3584 { 0x20, HDA_INPUT, 4 }, /* Docking */
3585 { } /* end */
3586};
3587#endif
3588
3589/*
3590 * Laptop model
3591 *
3592 * Port A: Headphone jack
3593 * Port B: MIC jack
3594 * Port C: Internal MIC
3595 * Port D: Dock Line Out (if enabled)
3596 * Port E: Dock Line In (if enabled)
3597 * Port F: Internal speakers
3598 */
3599
3600static struct hda_input_mux ad1884a_laptop_capture_source = {
3601 .num_items = 4,
3602 .items = {
3603 { "Mic", 0x0 }, /* port-B */
3604 { "Internal Mic", 0x1 }, /* port-C */
3605 { "Dock Mic", 0x4 }, /* port-E */
3606 { "Mix", 0x3 },
3607 },
3608};
3609
3610static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3611 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3612 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3613 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3614 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3615 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3616 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3617 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3618 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3619 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3620 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3621 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3622 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3623 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3624 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3625 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3626 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3627 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3628 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3629 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3630 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3631 {
3632 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3633 /* The multiple "Capture Source" controls confuse alsamixer
3634 * So call somewhat different..
3635 */
3636 /* .name = "Capture Source", */
3637 .name = "Input Source",
3638 .count = 2,
3639 .info = ad198x_mux_enum_info,
3640 .get = ad198x_mux_enum_get,
3641 .put = ad198x_mux_enum_put,
3642 },
3643 { } /* end */
3644};
3645
3646static struct hda_input_mux ad1884a_mobile_capture_source = {
3647 .num_items = 2,
3648 .items = {
3649 { "Mic", 0x1 }, /* port-C */
3650 { "Mix", 0x3 },
3651 },
3652};
3653
3654static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3655 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3656 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3657 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3658 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3659 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3660 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3661 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3662 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3663 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3664 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3665 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3666 {
3667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3668 .name = "Capture Source",
3669 .info = ad198x_mux_enum_info,
3670 .get = ad198x_mux_enum_get,
3671 .put = ad198x_mux_enum_put,
3672 },
3673 { } /* end */
3674};
3675
3676/* mute internal speaker if HP is plugged */
3677static void ad1884a_hp_automute(struct hda_codec *codec)
3678{
3679 unsigned int present;
3680
3681 present = snd_hda_codec_read(codec, 0x11, 0,
3682 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3683 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3684 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3685 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3686 present ? 0x00 : 0x02);
3687}
3688
3689#define AD1884A_HP_EVENT 0x37
3690
3691/* unsolicited event for HP jack sensing */
3692static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3693{
3694 if ((res >> 26) != AD1884A_HP_EVENT)
3695 return;
3696 ad1884a_hp_automute(codec);
3697}
3698
3699/* initialize jack-sensing, too */
3700static int ad1884a_hp_init(struct hda_codec *codec)
3701{
3702 ad198x_init(codec);
3703 ad1884a_hp_automute(codec);
3704 return 0;
3705}
3706
3707/* additional verbs for laptop model */
3708static struct hda_verb ad1884a_laptop_verbs[] = {
3709 /* Port-A (HP) pin - always unmuted */
3710 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3711 /* Port-F (int speaker) mixer - route only from analog mixer */
3712 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3713 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3714 /* Port-F pin */
3715 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3716 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3717 /* analog mix */
3718 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3719 /* unsolicited event for pin-sense */
3720 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3721 { } /* end */
3722};
3723
3724/*
3725 * Thinkpad X300
3726 * 0x11 - HP
3727 * 0x12 - speaker
3728 * 0x14 - mic-in
3729 * 0x17 - built-in mic
3730 */
3731
3732static struct hda_verb ad1984a_thinkpad_verbs[] = {
3733 /* HP unmute */
3734 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3735 /* analog mix */
3736 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3737 /* turn on EAPD */
3738 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3739 /* unsolicited event for pin-sense */
3740 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3741 /* internal mic - dmic */
3742 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3743 /* set magic COEFs for dmic */
3744 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3745 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
3746 { } /* end */
3747};
3748
3749static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3750 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3751 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3752 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3753 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3754 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3755 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3756 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3757 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3758 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3759 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3760 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3761 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3762 {
3763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3764 .name = "Capture Source",
3765 .info = ad198x_mux_enum_info,
3766 .get = ad198x_mux_enum_get,
3767 .put = ad198x_mux_enum_put,
3768 },
3769 { } /* end */
3770};
3771
3772static struct hda_input_mux ad1984a_thinkpad_capture_source = {
3773 .num_items = 3,
3774 .items = {
3775 { "Mic", 0x0 },
3776 { "Internal Mic", 0x5 },
3777 { "Mix", 0x3 },
3778 },
3779};
3780
3781/* mute internal speaker if HP is plugged */
3782static void ad1984a_thinkpad_automute(struct hda_codec *codec)
3783{
3784 unsigned int present;
3785
3786 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0)
3787 & AC_PINSENSE_PRESENCE;
3788 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
3789 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3790}
3791
3792/* unsolicited event for HP jack sensing */
3793static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
3794 unsigned int res)
3795{
3796 if ((res >> 26) != AD1884A_HP_EVENT)
3797 return;
3798 ad1984a_thinkpad_automute(codec);
3799}
3800
3801/* initialize jack-sensing, too */
3802static int ad1984a_thinkpad_init(struct hda_codec *codec)
3803{
3804 ad198x_init(codec);
3805 ad1984a_thinkpad_automute(codec);
3806 return 0;
3807}
3808
3809/*
3810 */
3811
3812enum {
3813 AD1884A_DESKTOP,
3814 AD1884A_LAPTOP,
3815 AD1884A_MOBILE,
3816 AD1884A_THINKPAD,
3817 AD1884A_MODELS
3818};
3819
3820static const char *ad1884a_models[AD1884A_MODELS] = {
3821 [AD1884A_DESKTOP] = "desktop",
3822 [AD1884A_LAPTOP] = "laptop",
3823 [AD1884A_MOBILE] = "mobile",
3824 [AD1884A_THINKPAD] = "thinkpad",
3825};
3826
3827static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3828 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
3829 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
3830 {}
3831};
3832
3833static int patch_ad1884a(struct hda_codec *codec)
3834{
3835 struct ad198x_spec *spec;
3836 int board_config;
3837
3838 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3839 if (spec == NULL)
3840 return -ENOMEM;
3841
3842 mutex_init(&spec->amp_mutex);
3843 codec->spec = spec;
3844
3845 spec->multiout.max_channels = 2;
3846 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
3847 spec->multiout.dac_nids = ad1884a_dac_nids;
3848 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
3849 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
3850 spec->adc_nids = ad1884a_adc_nids;
3851 spec->capsrc_nids = ad1884a_capsrc_nids;
3852 spec->input_mux = &ad1884a_capture_source;
3853 spec->num_mixers = 1;
3854 spec->mixers[0] = ad1884a_base_mixers;
3855 spec->num_init_verbs = 1;
3856 spec->init_verbs[0] = ad1884a_init_verbs;
3857 spec->spdif_route = 0;
3858#ifdef CONFIG_SND_HDA_POWER_SAVE
3859 spec->loopback.amplist = ad1884a_loopbacks;
3860#endif
3861 codec->patch_ops = ad198x_patch_ops;
3862
3863 /* override some parameters */
3864 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
3865 ad1884a_models,
3866 ad1884a_cfg_tbl);
3867 switch (board_config) {
3868 case AD1884A_LAPTOP:
3869 spec->mixers[0] = ad1884a_laptop_mixers;
3870 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3871 spec->multiout.dig_out_nid = 0;
3872 spec->input_mux = &ad1884a_laptop_capture_source;
3873 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3874 codec->patch_ops.init = ad1884a_hp_init;
3875 break;
3876 case AD1884A_MOBILE:
3877 spec->mixers[0] = ad1884a_mobile_mixers;
3878 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3879 spec->multiout.dig_out_nid = 0;
3880 spec->input_mux = &ad1884a_mobile_capture_source;
3881 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3882 codec->patch_ops.init = ad1884a_hp_init;
3883 break;
3884 case AD1884A_THINKPAD:
3885 spec->mixers[0] = ad1984a_thinkpad_mixers;
3886 spec->init_verbs[spec->num_init_verbs++] =
3887 ad1984a_thinkpad_verbs;
3888 spec->multiout.dig_out_nid = 0;
3889 spec->input_mux = &ad1984a_thinkpad_capture_source;
3890 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
3891 codec->patch_ops.init = ad1984a_thinkpad_init;
3892 break;
3893 }
3894
3895 return 0;
3896}
3897
3898
3899/*
3359 * AD1882 3900 * AD1882
3360 * 3901 *
3361 * port-A - front hp-out 3902 * port-A - front hp-out
@@ -3654,13 +4195,19 @@ static int patch_ad1882(struct hda_codec *codec)
3654 * patch entries 4195 * patch entries
3655 */ 4196 */
3656struct hda_codec_preset snd_hda_preset_analog[] = { 4197struct hda_codec_preset snd_hda_preset_analog[] = {
4198 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
3657 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 }, 4199 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
4200 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
3658 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 }, 4201 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
4202 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4203 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
3659 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 }, 4204 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
3660 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 }, 4205 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
3661 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 }, 4206 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
3662 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a }, 4207 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
3663 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 }, 4208 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
3664 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 }, 4209 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
4210 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4211 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
3665 {} /* terminator */ 4212 {} /* terminator */
3666}; 4213};
diff --git a/sound/pci/hda/patch_atihdmi.c b/sound/pci/hda/patch_atihdmi.c
index 9a8bb4ce3f8d..12272508b112 100644
--- a/sound/pci/hda/patch_atihdmi.c
+++ b/sound/pci/hda/patch_atihdmi.c
@@ -27,6 +27,7 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include "hda_codec.h" 28#include "hda_codec.h"
29#include "hda_local.h" 29#include "hda_local.h"
30#include "hda_patch.h"
30 31
31struct atihdmi_spec { 32struct atihdmi_spec {
32 struct hda_multi_out multiout; 33 struct hda_multi_out multiout;
@@ -58,6 +59,10 @@ static int atihdmi_build_controls(struct hda_codec *codec)
58static int atihdmi_init(struct hda_codec *codec) 59static int atihdmi_init(struct hda_codec *codec)
59{ 60{
60 snd_hda_sequence_write(codec, atihdmi_basic_init); 61 snd_hda_sequence_write(codec, atihdmi_basic_init);
62 /* SI codec requires to unmute the pin */
63 if (get_wcaps(codec, 0x03) & AC_WCAP_OUT_AMP)
64 snd_hda_codec_write(codec, 0x03, 0, AC_VERB_SET_AMP_GAIN_MUTE,
65 AMP_OUT_UNMUTE);
61 return 0; 66 return 0;
62} 67}
63 68
@@ -112,6 +117,7 @@ static int atihdmi_build_pcms(struct hda_codec *codec)
112 codec->pcm_info = info; 117 codec->pcm_info = info;
113 118
114 info->name = "ATI HDMI"; 119 info->name = "ATI HDMI";
120 info->pcm_type = HDA_PCM_TYPE_HDMI;
115 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback; 121 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
116 122
117 return 0; 123 return 0;
@@ -158,5 +164,7 @@ struct hda_codec_preset snd_hda_preset_atihdmi[] = {
158 { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, 164 { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
159 { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi }, 165 { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi },
160 { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi }, 166 { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi },
167 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_atihdmi },
168 { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi },
161 {} /* terminator */ 169 {} /* terminator */
162}; 170};
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index 3d6097ba1d68..c73ce074a6ea 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -28,6 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31#include "hda_patch.h"
31#define NUM_PINS 11 32#define NUM_PINS 11
32 33
33 34
@@ -329,6 +330,11 @@ static int cmi9880_build_controls(struct hda_codec *codec)
329 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 330 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
330 if (err < 0) 331 if (err < 0)
331 return err; 332 return err;
333 err = snd_hda_create_spdif_share_sw(codec,
334 &spec->multiout);
335 if (err < 0)
336 return err;
337 spec->multiout.share_spdif = 1;
332 } 338 }
333 if (spec->dig_in_nid) { 339 if (spec->dig_in_nid) {
334 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 340 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -432,7 +438,8 @@ static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo,
432 struct snd_pcm_substream *substream) 438 struct snd_pcm_substream *substream)
433{ 439{
434 struct cmi_spec *spec = codec->spec; 440 struct cmi_spec *spec = codec->spec;
435 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 441 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
442 hinfo);
436} 443}
437 444
438static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 445static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -506,7 +513,7 @@ static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
506{ 513{
507 struct cmi_spec *spec = codec->spec; 514 struct cmi_spec *spec = codec->spec;
508 515
509 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); 516 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
510 return 0; 517 return 0;
511} 518}
512 519
@@ -571,6 +578,7 @@ static int cmi9880_build_pcms(struct hda_codec *codec)
571 codec->num_pcms++; 578 codec->num_pcms++;
572 info++; 579 info++;
573 info->name = "CMI9880 Digital"; 580 info->name = "CMI9880 Digital";
581 info->pcm_type = HDA_PCM_TYPE_SPDIF;
574 if (spec->multiout.dig_out_nid) { 582 if (spec->multiout.dig_out_nid) {
575 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback; 583 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
576 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 584 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
@@ -603,6 +611,7 @@ static const char *cmi9880_models[CMI_MODELS] = {
603 611
604static struct snd_pci_quirk cmi9880_cfg_tbl[] = { 612static struct snd_pci_quirk cmi9880_cfg_tbl[] = {
605 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", CMI_FULL_DIG), 613 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", CMI_FULL_DIG),
614 SND_PCI_QUIRK(0x1854, 0x0032, "LG", CMI_FULL_DIG),
606 {} /* terminator */ 615 {} /* terminator */
607}; 616};
608 617
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 7206b30cbf94..36fd85260035 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -27,6 +27,7 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include "hda_codec.h" 28#include "hda_codec.h"
29#include "hda_local.h" 29#include "hda_local.h"
30#include "hda_patch.h"
30 31
31#define CXT_PIN_DIR_IN 0x00 32#define CXT_PIN_DIR_IN 0x00
32#define CXT_PIN_DIR_OUT 0x01 33#define CXT_PIN_DIR_OUT 0x01
@@ -98,7 +99,8 @@ static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
98 struct snd_pcm_substream *substream) 99 struct snd_pcm_substream *substream)
99{ 100{
100 struct conexant_spec *spec = codec->spec; 101 struct conexant_spec *spec = codec->spec;
101 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 102 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
103 hinfo);
102} 104}
103 105
104static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 106static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -172,8 +174,7 @@ static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
172 struct snd_pcm_substream *substream) 174 struct snd_pcm_substream *substream)
173{ 175{
174 struct conexant_spec *spec = codec->spec; 176 struct conexant_spec *spec = codec->spec;
175 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 177 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
176 0, 0, 0);
177 return 0; 178 return 0;
178} 179}
179 180
@@ -241,7 +242,7 @@ static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
241 struct snd_pcm_substream *substream) 242 struct snd_pcm_substream *substream)
242{ 243{
243 struct conexant_spec *spec = codec->spec; 244 struct conexant_spec *spec = codec->spec;
244 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0); 245 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
245 spec->cur_adc = 0; 246 spec->cur_adc = 0;
246 return 0; 247 return 0;
247} 248}
@@ -284,6 +285,7 @@ static int conexant_build_pcms(struct hda_codec *codec)
284 info++; 285 info++;
285 codec->num_pcms++; 286 codec->num_pcms++;
286 info->name = "Conexant Digital"; 287 info->name = "Conexant Digital";
288 info->pcm_type = HDA_PCM_TYPE_SPDIF;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 289 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
288 conexant_pcm_digital_playback; 290 conexant_pcm_digital_playback;
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 291 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
@@ -371,6 +373,11 @@ static int conexant_build_controls(struct hda_codec *codec)
371 spec->multiout.dig_out_nid); 373 spec->multiout.dig_out_nid);
372 if (err < 0) 374 if (err < 0)
373 return err; 375 return err;
376 err = snd_hda_create_spdif_share_sw(codec,
377 &spec->multiout);
378 if (err < 0)
379 return err;
380 spec->multiout.share_spdif = 1;
374 } 381 }
375 if (spec->dig_in_nid) { 382 if (spec->dig_in_nid) {
376 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 383 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
@@ -511,6 +518,14 @@ static struct hda_input_mux cxt5045_capture_source_benq = {
511 } 518 }
512}; 519};
513 520
521static struct hda_input_mux cxt5045_capture_source_hp530 = {
522 .num_items = 2,
523 .items = {
524 { "ExtMic", 0x1 },
525 { "IntMic", 0x2 },
526 }
527};
528
514/* turn on/off EAPD (+ mute HP) as a master switch */ 529/* turn on/off EAPD (+ mute HP) as a master switch */
515static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 530static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
516 struct snd_ctl_elem_value *ucontrol) 531 struct snd_ctl_elem_value *ucontrol)
@@ -639,6 +654,37 @@ static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
639 {} 654 {}
640}; 655};
641 656
657static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
658 {
659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
660 .name = "Capture Source",
661 .info = conexant_mux_enum_info,
662 .get = conexant_mux_enum_get,
663 .put = conexant_mux_enum_put
664 },
665 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
666 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
667 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
668 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
669 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
670 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
671 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
672 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
673 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
674 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
675 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
676 {
677 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
678 .name = "Master Playback Switch",
679 .info = cxt_eapd_info,
680 .get = cxt_eapd_get,
681 .put = cxt5045_hp_master_sw_put,
682 .private_value = 0x10,
683 },
684
685 {}
686};
687
642static struct hda_verb cxt5045_init_verbs[] = { 688static struct hda_verb cxt5045_init_verbs[] = {
643 /* Line in, Mic */ 689 /* Line in, Mic */
644 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 690 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
@@ -833,6 +879,7 @@ enum {
833 CXT5045_LAPTOP_MICSENSE, 879 CXT5045_LAPTOP_MICSENSE,
834 CXT5045_LAPTOP_HPMICSENSE, 880 CXT5045_LAPTOP_HPMICSENSE,
835 CXT5045_BENQ, 881 CXT5045_BENQ,
882 CXT5045_LAPTOP_HP530,
836#ifdef CONFIG_SND_DEBUG 883#ifdef CONFIG_SND_DEBUG
837 CXT5045_TEST, 884 CXT5045_TEST,
838#endif 885#endif
@@ -844,6 +891,7 @@ static const char *cxt5045_models[CXT5045_MODELS] = {
844 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 891 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
845 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 892 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
846 [CXT5045_BENQ] = "benq", 893 [CXT5045_BENQ] = "benq",
894 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
847#ifdef CONFIG_SND_DEBUG 895#ifdef CONFIG_SND_DEBUG
848 [CXT5045_TEST] = "test", 896 [CXT5045_TEST] = "test",
849#endif 897#endif
@@ -857,7 +905,7 @@ static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
857 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE), 905 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
858 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE), 906 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
859 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE), 907 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
860 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE), 908 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
861 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE), 909 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
862 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 910 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
863 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 911 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
@@ -941,6 +989,14 @@ static int patch_cxt5045(struct hda_codec *codec)
941 spec->num_mixers = 2; 989 spec->num_mixers = 2;
942 codec->patch_ops.init = cxt5045_init; 990 codec->patch_ops.init = cxt5045_init;
943 break; 991 break;
992 case CXT5045_LAPTOP_HP530:
993 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
994 spec->input_mux = &cxt5045_capture_source_hp530;
995 spec->num_init_verbs = 2;
996 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
997 spec->mixers[0] = cxt5045_mixers_hp530;
998 codec->patch_ops.init = cxt5045_init;
999 break;
944#ifdef CONFIG_SND_DEBUG 1000#ifdef CONFIG_SND_DEBUG
945 case CXT5045_TEST: 1001 case CXT5045_TEST:
946 spec->input_mux = &cxt5045_test_capture_source; 1002 spec->input_mux = &cxt5045_test_capture_source;
@@ -1537,7 +1593,7 @@ static void cxt5051_portc_automic(struct hda_codec *codec)
1537 new_adc = spec->adc_nids[spec->cur_adc_idx]; 1593 new_adc = spec->adc_nids[spec->cur_adc_idx];
1538 if (spec->cur_adc && spec->cur_adc != new_adc) { 1594 if (spec->cur_adc && spec->cur_adc != new_adc) {
1539 /* stream is running, let's swap the current ADC */ 1595 /* stream is running, let's swap the current ADC */
1540 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0); 1596 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1541 spec->cur_adc = new_adc; 1597 spec->cur_adc = new_adc;
1542 snd_hda_codec_setup_stream(codec, new_adc, 1598 snd_hda_codec_setup_stream(codec, new_adc,
1543 spec->cur_adc_stream_tag, 0, 1599 spec->cur_adc_stream_tag, 0,
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 33282f9c01c7..cdda64b02f46 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -30,6 +30,7 @@
30#include <sound/core.h> 30#include <sound/core.h>
31#include "hda_codec.h" 31#include "hda_codec.h"
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_patch.h"
33 34
34#define ALC880_FRONT_EVENT 0x01 35#define ALC880_FRONT_EVENT 0x01
35#define ALC880_DCVOL_EVENT 0x02 36#define ALC880_DCVOL_EVENT 0x02
@@ -97,16 +98,19 @@ enum {
97 ALC262_SONY_ASSAMD, 98 ALC262_SONY_ASSAMD,
98 ALC262_BENQ_T31, 99 ALC262_BENQ_T31,
99 ALC262_ULTRA, 100 ALC262_ULTRA,
101 ALC262_LENOVO_3000,
100 ALC262_AUTO, 102 ALC262_AUTO,
101 ALC262_MODEL_LAST /* last tag */ 103 ALC262_MODEL_LAST /* last tag */
102}; 104};
103 105
104/* ALC268 models */ 106/* ALC268 models */
105enum { 107enum {
108 ALC267_QUANTA_IL1,
106 ALC268_3ST, 109 ALC268_3ST,
107 ALC268_TOSHIBA, 110 ALC268_TOSHIBA,
108 ALC268_ACER, 111 ALC268_ACER,
109 ALC268_DELL, 112 ALC268_DELL,
113 ALC268_ZEPTO,
110#ifdef CONFIG_SND_DEBUG 114#ifdef CONFIG_SND_DEBUG
111 ALC268_TEST, 115 ALC268_TEST,
112#endif 116#endif
@@ -195,10 +199,11 @@ enum {
195 ALC883_LENOVO_NB0763, 199 ALC883_LENOVO_NB0763,
196 ALC888_LENOVO_MS7195_DIG, 200 ALC888_LENOVO_MS7195_DIG,
197 ALC883_HAIER_W66, 201 ALC883_HAIER_W66,
198 ALC888_6ST_HP,
199 ALC888_3ST_HP, 202 ALC888_3ST_HP,
200 ALC888_6ST_DELL, 203 ALC888_6ST_DELL,
201 ALC883_MITAC, 204 ALC883_MITAC,
205 ALC883_CLEVO_M720,
206 ALC883_FUJITSU_PI2515,
202 ALC883_AUTO, 207 ALC883_AUTO,
203 ALC883_MODEL_LAST, 208 ALC883_MODEL_LAST,
204}; 209};
@@ -237,6 +242,7 @@ struct alc_spec {
237 /* capture */ 242 /* capture */
238 unsigned int num_adc_nids; 243 unsigned int num_adc_nids;
239 hda_nid_t *adc_nids; 244 hda_nid_t *adc_nids;
245 hda_nid_t *capsrc_nids;
240 hda_nid_t dig_in_nid; /* digital-in NID; optional */ 246 hda_nid_t dig_in_nid; /* digital-in NID; optional */
241 247
242 /* capture source */ 248 /* capture source */
@@ -270,7 +276,6 @@ struct alc_spec {
270 276
271 /* for virtual master */ 277 /* for virtual master */
272 hda_nid_t vmaster_nid; 278 hda_nid_t vmaster_nid;
273 u32 vmaster_tlv[4];
274#ifdef CONFIG_SND_HDA_POWER_SAVE 279#ifdef CONFIG_SND_HDA_POWER_SAVE
275 struct hda_loopback_check loopback; 280 struct hda_loopback_check loopback;
276#endif 281#endif
@@ -290,6 +295,7 @@ struct alc_config_preset {
290 hda_nid_t hp_nid; /* optional */ 295 hda_nid_t hp_nid; /* optional */
291 unsigned int num_adc_nids; 296 unsigned int num_adc_nids;
292 hda_nid_t *adc_nids; 297 hda_nid_t *adc_nids;
298 hda_nid_t *capsrc_nids;
293 hda_nid_t dig_in_nid; 299 hda_nid_t dig_in_nid;
294 unsigned int num_channel_mode; 300 unsigned int num_channel_mode;
295 const struct hda_channel_mode *channel_mode; 301 const struct hda_channel_mode *channel_mode;
@@ -336,9 +342,10 @@ static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
336 struct alc_spec *spec = codec->spec; 342 struct alc_spec *spec = codec->spec;
337 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 343 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
338 unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; 344 unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
345 hda_nid_t nid = spec->capsrc_nids ?
346 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
339 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol, 347 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
340 spec->adc_nids[adc_idx], 348 nid, &spec->cur_mux[adc_idx]);
341 &spec->cur_mux[adc_idx]);
342} 349}
343 350
344 351
@@ -707,6 +714,7 @@ static void setup_preset(struct alc_spec *spec,
707 714
708 spec->num_adc_nids = preset->num_adc_nids; 715 spec->num_adc_nids = preset->num_adc_nids;
709 spec->adc_nids = preset->adc_nids; 716 spec->adc_nids = preset->adc_nids;
717 spec->capsrc_nids = preset->capsrc_nids;
710 spec->dig_in_nid = preset->dig_in_nid; 718 spec->dig_in_nid = preset->dig_in_nid;
711 719
712 spec->unsol_event = preset->unsol_event; 720 spec->unsol_event = preset->unsol_event;
@@ -741,7 +749,6 @@ static struct hda_verb alc_gpio3_init_verbs[] = {
741static void alc_sku_automute(struct hda_codec *codec) 749static void alc_sku_automute(struct hda_codec *codec)
742{ 750{
743 struct alc_spec *spec = codec->spec; 751 struct alc_spec *spec = codec->spec;
744 unsigned int mute;
745 unsigned int present; 752 unsigned int present;
746 unsigned int hp_nid = spec->autocfg.hp_pins[0]; 753 unsigned int hp_nid = spec->autocfg.hp_pins[0];
747 unsigned int sp_nid = spec->autocfg.speaker_pins[0]; 754 unsigned int sp_nid = spec->autocfg.speaker_pins[0];
@@ -751,16 +758,8 @@ static void alc_sku_automute(struct hda_codec *codec)
751 present = snd_hda_codec_read(codec, hp_nid, 0, 758 present = snd_hda_codec_read(codec, hp_nid, 0,
752 AC_VERB_GET_PIN_SENSE, 0); 759 AC_VERB_GET_PIN_SENSE, 0);
753 spec->jack_present = (present & 0x80000000) != 0; 760 spec->jack_present = (present & 0x80000000) != 0;
754 if (spec->jack_present) { 761 snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
755 /* mute internal speaker */ 762 spec->jack_present ? 0 : PIN_OUT);
756 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
757 HDA_AMP_MUTE, HDA_AMP_MUTE);
758 } else {
759 /* unmute internal speaker if necessary */
760 mute = snd_hda_codec_amp_read(codec, hp_nid, 0, HDA_OUTPUT, 0);
761 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
762 HDA_AMP_MUTE, mute);
763 }
764} 763}
765 764
766/* unsolicited event for HP jack sensing */ 765/* unsolicited event for HP jack sensing */
@@ -1319,11 +1318,19 @@ static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1319 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT), 1318 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1320 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 1319 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1321 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 1320 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1322 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 1321 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1323 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 1322 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1324 { } /* end */ 1323 { } /* end */
1325}; 1324};
1326 1325
1326static struct hda_input_mux alc880_f1734_capture_source = {
1327 .num_items = 2,
1328 .items = {
1329 { "Mic", 0x1 },
1330 { "CD", 0x4 },
1331 },
1332};
1333
1327 1334
1328/* 1335/*
1329 * ALC880 ASUS model 1336 * ALC880 ASUS model
@@ -1516,6 +1523,11 @@ static int alc_build_controls(struct hda_codec *codec)
1516 spec->multiout.dig_out_nid); 1523 spec->multiout.dig_out_nid);
1517 if (err < 0) 1524 if (err < 0)
1518 return err; 1525 return err;
1526 err = snd_hda_create_spdif_share_sw(codec,
1527 &spec->multiout);
1528 if (err < 0)
1529 return err;
1530 spec->multiout.share_spdif = 1;
1519 } 1531 }
1520 if (spec->dig_in_nid) { 1532 if (spec->dig_in_nid) {
1521 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 1533 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -1525,10 +1537,11 @@ static int alc_build_controls(struct hda_codec *codec)
1525 1537
1526 /* if we have no master control, let's create it */ 1538 /* if we have no master control, let's create it */
1527 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 1539 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1540 unsigned int vmaster_tlv[4];
1528 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 1541 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1529 HDA_OUTPUT, spec->vmaster_tlv); 1542 HDA_OUTPUT, vmaster_tlv);
1530 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 1543 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1531 spec->vmaster_tlv, alc_slave_vols); 1544 vmaster_tlv, alc_slave_vols);
1532 if (err < 0) 1545 if (err < 0)
1533 return err; 1546 return err;
1534 } 1547 }
@@ -1882,7 +1895,7 @@ static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1882 present = snd_hda_codec_read(codec, 0x14, 0, 1895 present = snd_hda_codec_read(codec, 0x14, 0,
1883 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1896 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1884 bits = present ? HDA_AMP_MUTE : 0; 1897 bits = present ? HDA_AMP_MUTE : 0;
1885 snd_hda_codec_amp_stereo(codec, 0x15, HDA_INPUT, 0, HDA_AMP_MUTE, bits); 1898 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1886} 1899}
1887 1900
1888static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec) 1901static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
@@ -1915,6 +1928,7 @@ static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1915 * HP = 0x14, speaker-out = 0x15, mic = 0x18 1928 * HP = 0x14, speaker-out = 0x15, mic = 0x18
1916 */ 1929 */
1917static struct hda_verb alc880_pin_f1734_init_verbs[] = { 1930static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1931 {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
1918 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, 1932 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1919 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, 1933 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1920 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, 1934 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
@@ -1927,7 +1941,7 @@ static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1927 1941
1928 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1942 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1929 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 1943 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1930 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1944 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
1931 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 1945 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1932 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1946 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1933 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1947 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -1935,6 +1949,9 @@ static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1935 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1949 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1936 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1950 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1937 1951
1952 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
1953 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
1954
1938 { } 1955 { }
1939}; 1956};
1940 1957
@@ -2318,7 +2335,8 @@ static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2318 struct snd_pcm_substream *substream) 2335 struct snd_pcm_substream *substream)
2319{ 2336{
2320 struct alc_spec *spec = codec->spec; 2337 struct alc_spec *spec = codec->spec;
2321 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 2338 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2339 hinfo);
2322} 2340}
2323 2341
2324static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2342static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -2392,8 +2410,8 @@ static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2392{ 2410{
2393 struct alc_spec *spec = codec->spec; 2411 struct alc_spec *spec = codec->spec;
2394 2412
2395 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], 2413 snd_hda_codec_cleanup_stream(codec,
2396 0, 0, 0); 2414 spec->adc_nids[substream->number + 1]);
2397 return 0; 2415 return 0;
2398} 2416}
2399 2417
@@ -2498,6 +2516,7 @@ static int alc_build_pcms(struct hda_codec *codec)
2498 codec->num_pcms = 2; 2516 codec->num_pcms = 2;
2499 info = spec->pcm_rec + 1; 2517 info = spec->pcm_rec + 1;
2500 info->name = spec->stream_name_digital; 2518 info->name = spec->stream_name_digital;
2519 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2501 if (spec->multiout.dig_out_nid && 2520 if (spec->multiout.dig_out_nid &&
2502 spec->stream_digital_playback) { 2521 spec->stream_digital_playback) {
2503 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback); 2522 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
@@ -2560,6 +2579,7 @@ static void alc_free(struct hda_codec *codec)
2560 kfree(spec->kctl_alloc); 2579 kfree(spec->kctl_alloc);
2561 } 2580 }
2562 kfree(spec); 2581 kfree(spec);
2582 codec->spec = NULL; /* to be sure */
2563} 2583}
2564 2584
2565/* 2585/*
@@ -3057,7 +3077,9 @@ static struct alc_config_preset alc880_presets[] = {
3057 .hp_nid = 0x02, 3077 .hp_nid = 0x02,
3058 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes), 3078 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3059 .channel_mode = alc880_2_jack_modes, 3079 .channel_mode = alc880_2_jack_modes,
3060 .input_mux = &alc880_capture_source, 3080 .input_mux = &alc880_f1734_capture_source,
3081 .unsol_event = alc880_uniwill_p53_unsol_event,
3082 .init_hook = alc880_uniwill_p53_hp_automute,
3061 }, 3083 },
3062 [ALC880_ASUS] = { 3084 [ALC880_ASUS] = {
3063 .mixers = { alc880_asus_mixer }, 3085 .mixers = { alc880_asus_mixer },
@@ -3467,15 +3489,21 @@ static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3467 return 0; 3489 return 0;
3468} 3490}
3469 3491
3470static void alc880_auto_set_output_and_unmute(struct hda_codec *codec, 3492static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3471 hda_nid_t nid, int pin_type, 3493 unsigned int pin_type)
3472 int dac_idx)
3473{ 3494{
3474 /* set as output */
3475 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 3495 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3476 pin_type); 3496 pin_type);
3497 /* unmute pin */
3477 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 3498 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3478 AMP_OUT_UNMUTE); 3499 AMP_OUT_UNMUTE);
3500}
3501
3502static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3503 hda_nid_t nid, int pin_type,
3504 int dac_idx)
3505{
3506 alc_set_pin_output(codec, nid, pin_type);
3479 /* need the manual connection? */ 3507 /* need the manual connection? */
3480 if (alc880_is_multi_pin(nid)) { 3508 if (alc880_is_multi_pin(nid)) {
3481 struct alc_spec *spec = codec->spec; 3509 struct alc_spec *spec = codec->spec;
@@ -3597,9 +3625,12 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
3597/* additional initialization for auto-configuration model */ 3625/* additional initialization for auto-configuration model */
3598static void alc880_auto_init(struct hda_codec *codec) 3626static void alc880_auto_init(struct hda_codec *codec)
3599{ 3627{
3628 struct alc_spec *spec = codec->spec;
3600 alc880_auto_init_multi_out(codec); 3629 alc880_auto_init_multi_out(codec);
3601 alc880_auto_init_extra_out(codec); 3630 alc880_auto_init_extra_out(codec);
3602 alc880_auto_init_analog_input(codec); 3631 alc880_auto_init_analog_input(codec);
3632 if (spec->unsol_event)
3633 alc_sku_automute(codec);
3603} 3634}
3604 3635
3605/* 3636/*
@@ -4795,11 +4826,7 @@ static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4795 hda_nid_t nid, int pin_type, 4826 hda_nid_t nid, int pin_type,
4796 int sel_idx) 4827 int sel_idx)
4797{ 4828{
4798 /* set as output */ 4829 alc_set_pin_output(codec, nid, pin_type);
4799 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4800 pin_type);
4801 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4802 AMP_OUT_UNMUTE);
4803 /* need the manual connection? */ 4830 /* need the manual connection? */
4804 if (nid >= 0x12) { 4831 if (nid >= 0x12) {
4805 int idx = nid - 0x12; 4832 int idx = nid - 0x12;
@@ -4929,7 +4956,7 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
4929 /* check whether NID 0x04 is valid */ 4956 /* check whether NID 0x04 is valid */
4930 wcap = get_wcaps(codec, 0x04); 4957 wcap = get_wcaps(codec, 0x04);
4931 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */ 4958 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4932 if (wcap != AC_WID_AUD_IN) { 4959 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
4933 spec->adc_nids = alc260_adc_nids_alt; 4960 spec->adc_nids = alc260_adc_nids_alt;
4934 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt); 4961 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4935 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer; 4962 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
@@ -4946,8 +4973,11 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
4946/* additional initialization for auto-configuration model */ 4973/* additional initialization for auto-configuration model */
4947static void alc260_auto_init(struct hda_codec *codec) 4974static void alc260_auto_init(struct hda_codec *codec)
4948{ 4975{
4976 struct alc_spec *spec = codec->spec;
4949 alc260_auto_init_multi_out(codec); 4977 alc260_auto_init_multi_out(codec);
4950 alc260_auto_init_analog_input(codec); 4978 alc260_auto_init_analog_input(codec);
4979 if (spec->unsol_event)
4980 alc_sku_automute(codec);
4951} 4981}
4952 4982
4953#ifdef CONFIG_SND_HDA_POWER_SAVE 4983#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -5204,6 +5234,9 @@ static hda_nid_t alc882_dac_nids[4] = {
5204#define alc882_adc_nids alc880_adc_nids 5234#define alc882_adc_nids alc880_adc_nids
5205#define alc882_adc_nids_alt alc880_adc_nids_alt 5235#define alc882_adc_nids_alt alc880_adc_nids_alt
5206 5236
5237static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5238static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5239
5207/* input MUX */ 5240/* input MUX */
5208/* FIXME: should be a matrix-type input source selection */ 5241/* FIXME: should be a matrix-type input source selection */
5209 5242
@@ -5226,15 +5259,11 @@ static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5226 struct alc_spec *spec = codec->spec; 5259 struct alc_spec *spec = codec->spec;
5227 const struct hda_input_mux *imux = spec->input_mux; 5260 const struct hda_input_mux *imux = spec->input_mux;
5228 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 5261 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5229 static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 }; 5262 hda_nid_t nid = spec->capsrc_nids ?
5230 hda_nid_t nid; 5263 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5231 unsigned int *cur_val = &spec->cur_mux[adc_idx]; 5264 unsigned int *cur_val = &spec->cur_mux[adc_idx];
5232 unsigned int i, idx; 5265 unsigned int i, idx;
5233 5266
5234 if (spec->num_adc_nids < 3)
5235 nid = capture_mixers[adc_idx + 1];
5236 else
5237 nid = capture_mixers[adc_idx];
5238 idx = ucontrol->value.enumerated.item[0]; 5267 idx = ucontrol->value.enumerated.item[0];
5239 if (idx >= imux->num_items) 5268 if (idx >= imux->num_items)
5240 idx = imux->num_items - 1; 5269 idx = imux->num_items - 1;
@@ -6111,6 +6140,7 @@ static struct alc_config_preset alc882_presets[] = {
6111 .dig_out_nid = ALC882_DIGOUT_NID, 6140 .dig_out_nid = ALC882_DIGOUT_NID,
6112 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids), 6141 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6113 .adc_nids = alc882_adc_nids, 6142 .adc_nids = alc882_adc_nids,
6143 .capsrc_nids = alc882_capsrc_nids,
6114 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes), 6144 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6115 .channel_mode = alc882_3ST_6ch_modes, 6145 .channel_mode = alc882_3ST_6ch_modes,
6116 .need_dac_fix = 1, 6146 .need_dac_fix = 1,
@@ -6127,6 +6157,7 @@ static struct alc_config_preset alc882_presets[] = {
6127 .dig_out_nid = ALC882_DIGOUT_NID, 6157 .dig_out_nid = ALC882_DIGOUT_NID,
6128 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids), 6158 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6129 .adc_nids = alc882_adc_nids, 6159 .adc_nids = alc882_adc_nids,
6160 .capsrc_nids = alc882_capsrc_nids,
6130 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes), 6161 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6131 .channel_mode = alc882_3ST_6ch_modes, 6162 .channel_mode = alc882_3ST_6ch_modes,
6132 .need_dac_fix = 1, 6163 .need_dac_fix = 1,
@@ -6182,15 +6213,11 @@ static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6182 struct alc_spec *spec = codec->spec; 6213 struct alc_spec *spec = codec->spec;
6183 int idx; 6214 int idx;
6184 6215
6216 alc_set_pin_output(codec, nid, pin_type);
6185 if (spec->multiout.dac_nids[dac_idx] == 0x25) 6217 if (spec->multiout.dac_nids[dac_idx] == 0x25)
6186 idx = 4; 6218 idx = 4;
6187 else 6219 else
6188 idx = spec->multiout.dac_nids[dac_idx] - 2; 6220 idx = spec->multiout.dac_nids[dac_idx] - 2;
6189
6190 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
6191 pin_type);
6192 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
6193 AMP_OUT_UNMUTE);
6194 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx); 6221 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6195 6222
6196} 6223}
@@ -6219,6 +6246,9 @@ static void alc882_auto_init_hp_out(struct hda_codec *codec)
6219 if (pin) /* connect to front */ 6246 if (pin) /* connect to front */
6220 /* use dac 0 */ 6247 /* use dac 0 */
6221 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 6248 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6249 pin = spec->autocfg.speaker_pins[0];
6250 if (pin)
6251 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6222} 6252}
6223 6253
6224#define alc882_is_input_pin(nid) alc880_is_input_pin(nid) 6254#define alc882_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -6231,16 +6261,21 @@ static void alc882_auto_init_analog_input(struct hda_codec *codec)
6231 6261
6232 for (i = 0; i < AUTO_PIN_LAST; i++) { 6262 for (i = 0; i < AUTO_PIN_LAST; i++) {
6233 hda_nid_t nid = spec->autocfg.input_pins[i]; 6263 hda_nid_t nid = spec->autocfg.input_pins[i];
6234 if (alc882_is_input_pin(nid)) { 6264 unsigned int vref;
6235 snd_hda_codec_write(codec, nid, 0, 6265 if (!nid)
6236 AC_VERB_SET_PIN_WIDGET_CONTROL, 6266 continue;
6237 i <= AUTO_PIN_FRONT_MIC ? 6267 vref = PIN_IN;
6238 PIN_VREF80 : PIN_IN); 6268 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6239 if (nid != ALC882_PIN_CD_NID) 6269 if (snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP) &
6240 snd_hda_codec_write(codec, nid, 0, 6270 AC_PINCAP_VREF_80)
6241 AC_VERB_SET_AMP_GAIN_MUTE, 6271 vref = PIN_VREF80;
6242 AMP_OUT_MUTE);
6243 } 6272 }
6273 snd_hda_codec_write(codec, nid, 0,
6274 AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6275 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6276 snd_hda_codec_write(codec, nid, 0,
6277 AC_VERB_SET_AMP_GAIN_MUTE,
6278 AMP_OUT_MUTE);
6244 } 6279 }
6245} 6280}
6246 6281
@@ -6294,11 +6329,16 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
6294/* additional initialization for auto-configuration model */ 6329/* additional initialization for auto-configuration model */
6295static void alc882_auto_init(struct hda_codec *codec) 6330static void alc882_auto_init(struct hda_codec *codec)
6296{ 6331{
6332 struct alc_spec *spec = codec->spec;
6297 alc882_auto_init_multi_out(codec); 6333 alc882_auto_init_multi_out(codec);
6298 alc882_auto_init_hp_out(codec); 6334 alc882_auto_init_hp_out(codec);
6299 alc882_auto_init_analog_input(codec); 6335 alc882_auto_init_analog_input(codec);
6336 if (spec->unsol_event)
6337 alc_sku_automute(codec);
6300} 6338}
6301 6339
6340static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6341
6302static int patch_alc882(struct hda_codec *codec) 6342static int patch_alc882(struct hda_codec *codec)
6303{ 6343{
6304 struct alc_spec *spec; 6344 struct alc_spec *spec;
@@ -6328,6 +6368,11 @@ static int patch_alc882(struct hda_codec *codec)
6328 board_config = ALC885_MBP3; 6368 board_config = ALC885_MBP3;
6329 break; 6369 break;
6330 default: 6370 default:
6371 /* ALC889A is handled better as ALC888-compatible */
6372 if (codec->revision_id == 0x100103) {
6373 alc_free(codec);
6374 return patch_alc883(codec);
6375 }
6331 printk(KERN_INFO "hda_codec: Unknown model for ALC882, " 6376 printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6332 "trying auto-probe from BIOS...\n"); 6377 "trying auto-probe from BIOS...\n");
6333 board_config = ALC882_AUTO; 6378 board_config = ALC882_AUTO;
@@ -6372,12 +6417,14 @@ static int patch_alc882(struct hda_codec *codec)
6372 if (wcap != AC_WID_AUD_IN) { 6417 if (wcap != AC_WID_AUD_IN) {
6373 spec->adc_nids = alc882_adc_nids_alt; 6418 spec->adc_nids = alc882_adc_nids_alt;
6374 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt); 6419 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6420 spec->capsrc_nids = alc882_capsrc_nids_alt;
6375 spec->mixers[spec->num_mixers] = 6421 spec->mixers[spec->num_mixers] =
6376 alc882_capture_alt_mixer; 6422 alc882_capture_alt_mixer;
6377 spec->num_mixers++; 6423 spec->num_mixers++;
6378 } else { 6424 } else {
6379 spec->adc_nids = alc882_adc_nids; 6425 spec->adc_nids = alc882_adc_nids;
6380 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids); 6426 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6427 spec->capsrc_nids = alc882_capsrc_nids;
6381 spec->mixers[spec->num_mixers] = alc882_capture_mixer; 6428 spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6382 spec->num_mixers++; 6429 spec->num_mixers++;
6383 } 6430 }
@@ -6412,7 +6459,7 @@ static int patch_alc882(struct hda_codec *codec)
6412 6459
6413static hda_nid_t alc883_dac_nids[4] = { 6460static hda_nid_t alc883_dac_nids[4] = {
6414 /* front, rear, clfe, rear_surr */ 6461 /* front, rear, clfe, rear_surr */
6415 0x02, 0x04, 0x03, 0x05 6462 0x02, 0x03, 0x04, 0x05
6416}; 6463};
6417 6464
6418static hda_nid_t alc883_adc_nids[2] = { 6465static hda_nid_t alc883_adc_nids[2] = {
@@ -6420,6 +6467,8 @@ static hda_nid_t alc883_adc_nids[2] = {
6420 0x08, 0x09, 6467 0x08, 0x09,
6421}; 6468};
6422 6469
6470static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6471
6423/* input MUX */ 6472/* input MUX */
6424/* FIXME: should be a matrix-type input source selection */ 6473/* FIXME: should be a matrix-type input source selection */
6425 6474
@@ -6451,35 +6500,18 @@ static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6451 }, 6500 },
6452}; 6501};
6453 6502
6503static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6504 .num_items = 2,
6505 .items = {
6506 { "Mic", 0x0 },
6507 { "Int Mic", 0x1 },
6508 },
6509};
6510
6454#define alc883_mux_enum_info alc_mux_enum_info 6511#define alc883_mux_enum_info alc_mux_enum_info
6455#define alc883_mux_enum_get alc_mux_enum_get 6512#define alc883_mux_enum_get alc_mux_enum_get
6456 6513/* ALC883 has the ALC882-type input selection */
6457static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol, 6514#define alc883_mux_enum_put alc882_mux_enum_put
6458 struct snd_ctl_elem_value *ucontrol)
6459{
6460 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6461 struct alc_spec *spec = codec->spec;
6462 const struct hda_input_mux *imux = spec->input_mux;
6463 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
6464 static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
6465 hda_nid_t nid = capture_mixers[adc_idx];
6466 unsigned int *cur_val = &spec->cur_mux[adc_idx];
6467 unsigned int i, idx;
6468
6469 idx = ucontrol->value.enumerated.item[0];
6470 if (idx >= imux->num_items)
6471 idx = imux->num_items - 1;
6472 if (*cur_val == idx)
6473 return 0;
6474 for (i = 0; i < imux->num_items; i++) {
6475 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
6476 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
6477 imux->items[i].index,
6478 HDA_AMP_MUTE, v);
6479 }
6480 *cur_val = idx;
6481 return 1;
6482}
6483 6515
6484/* 6516/*
6485 * 2ch mode 6517 * 2ch mode
@@ -6638,6 +6670,60 @@ static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6638 { } /* end */ 6670 { } /* end */
6639}; 6671};
6640 6672
6673static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
6674 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6675 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6676 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6677 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6678 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6679 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6680 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6681 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6682 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6683 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6684 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6685 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6686 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6687 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6688 {
6689 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6690 /* .name = "Capture Source", */
6691 .name = "Input Source",
6692 .count = 2,
6693 .info = alc883_mux_enum_info,
6694 .get = alc883_mux_enum_get,
6695 .put = alc883_mux_enum_put,
6696 },
6697 { } /* end */
6698};
6699
6700static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
6701 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6702 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6703 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6704 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6705 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6706 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6707 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6708 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6709 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6710 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6711 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6712 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6713 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6714 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6715 {
6716 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6717 /* .name = "Capture Source", */
6718 .name = "Input Source",
6719 .count = 2,
6720 .info = alc883_mux_enum_info,
6721 .get = alc883_mux_enum_get,
6722 .put = alc883_mux_enum_put,
6723 },
6724 { } /* end */
6725};
6726
6641static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = { 6727static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6642 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 6728 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6643 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 6729 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -6787,6 +6873,9 @@ static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6787 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 6873 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6788 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 6874 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6789 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 6875 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6876 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6877 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6878 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6790 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 6879 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6791 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 6880 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6792 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT), 6881 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
@@ -6878,124 +6967,6 @@ static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6878 { } /* end */ 6967 { } /* end */
6879}; 6968};
6880 6969
6881static struct snd_kcontrol_new alc888_6st_hp_mixer[] = {
6882 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6883 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6884 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6885 HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6886 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6887 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6888 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6889 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6890 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6891 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6892 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6893 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6894 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6895 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6896 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6897 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6898 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6899 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6900 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6901 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6902 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6903 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6904 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6905 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6906 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6907 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6908 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6909 {
6910 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6911 /* .name = "Capture Source", */
6912 .name = "Input Source",
6913 .count = 2,
6914 .info = alc883_mux_enum_info,
6915 .get = alc883_mux_enum_get,
6916 .put = alc883_mux_enum_put,
6917 },
6918 { } /* end */
6919};
6920
6921static struct snd_kcontrol_new alc888_3st_hp_mixer[] = {
6922 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6923 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6924 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6925 HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6926 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6927 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6928 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6929 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6930 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6931 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6932 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6933 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6934 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6935 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6936 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6937 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6938 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6939 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6940 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6941 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6942 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6943 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6944 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6945 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6946 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6947 {
6948 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6949 /* .name = "Capture Source", */
6950 .name = "Input Source",
6951 .count = 2,
6952 .info = alc883_mux_enum_info,
6953 .get = alc883_mux_enum_get,
6954 .put = alc883_mux_enum_put,
6955 },
6956 { } /* end */
6957};
6958
6959static struct snd_kcontrol_new alc888_6st_dell_mixer[] = {
6960 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6961 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6962 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6963 HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6964 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6965 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6966 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6967 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6968 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6969 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6970 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6971 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6972 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6973 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6974 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6975 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6976 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6977 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6978 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6979 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6980 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6981 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6982 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6983 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6984 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6985 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6986 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6987 {
6988 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6989 /* .name = "Capture Source", */
6990 .name = "Input Source",
6991 .count = 2,
6992 .info = alc883_mux_enum_info,
6993 .get = alc883_mux_enum_get,
6994 .put = alc883_mux_enum_put,
6995 },
6996 { } /* end */
6997};
6998
6999static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = { 6970static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7000 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 6971 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7001 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 6972 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -7171,6 +7142,35 @@ static struct hda_verb alc883_mitac_verbs[] = {
7171 { } /* end */ 7142 { } /* end */
7172}; 7143};
7173 7144
7145static struct hda_verb alc883_clevo_m720_verbs[] = {
7146 /* HP */
7147 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7148 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7149 /* Int speaker */
7150 {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7151 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7152
7153 /* enable unsolicited event */
7154 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7155 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7156
7157 { } /* end */
7158};
7159
7160static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7161 /* HP */
7162 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7163 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7164 /* Subwoofer */
7165 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7166 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7167
7168 /* enable unsolicited event */
7169 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7170
7171 { } /* end */
7172};
7173
7174static struct hda_verb alc883_tagra_verbs[] = { 7174static struct hda_verb alc883_tagra_verbs[] = {
7175 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7175 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7176 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 7176 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
@@ -7227,26 +7227,14 @@ static struct hda_verb alc883_haier_w66_verbs[] = {
7227 { } /* end */ 7227 { } /* end */
7228}; 7228};
7229 7229
7230static struct hda_verb alc888_6st_hp_verbs[] = {
7231 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7232 {0x15, AC_VERB_SET_CONNECT_SEL, 0x02}, /* Rear : output 2 (0x0e) */
7233 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* CLFE : output 1 (0x0d) */
7234 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03}, /* Side : output 3 (0x0f) */
7235 { }
7236};
7237
7238static struct hda_verb alc888_3st_hp_verbs[] = { 7230static struct hda_verb alc888_3st_hp_verbs[] = {
7239 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */ 7231 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7240 {0x18, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Rear : output 1 (0x0d) */ 7232 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Rear : output 1 (0x0d) */
7241 {0x16, AC_VERB_SET_CONNECT_SEL, 0x02}, /* CLFE : output 2 (0x0e) */ 7233 {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* CLFE : output 2 (0x0e) */
7242 { } 7234 { }
7243}; 7235};
7244 7236
7245static struct hda_verb alc888_6st_dell_verbs[] = { 7237static struct hda_verb alc888_6st_dell_verbs[] = {
7246 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7247 {0x15, AC_VERB_SET_CONNECT_SEL, 0x02}, /* Rear : output 1 (0x0e) */
7248 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* CLFE : output 2 (0x0d) */
7249 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03}, /* Side : output 3 (0x0f) */
7250 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 7238 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7251 { } 7239 { }
7252}; 7240};
@@ -7354,6 +7342,68 @@ static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7354 alc883_tagra_automute(codec); 7342 alc883_tagra_automute(codec);
7355} 7343}
7356 7344
7345/* toggle speaker-output according to the hp-jack state */
7346static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7347{
7348 unsigned int present;
7349 unsigned char bits;
7350
7351 present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7352 & AC_PINSENSE_PRESENCE;
7353 bits = present ? HDA_AMP_MUTE : 0;
7354 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7355 HDA_AMP_MUTE, bits);
7356}
7357
7358static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7359{
7360 unsigned int present;
7361
7362 present = snd_hda_codec_read(codec, 0x18, 0,
7363 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7364 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7365 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7366}
7367
7368static void alc883_clevo_m720_automute(struct hda_codec *codec)
7369{
7370 alc883_clevo_m720_hp_automute(codec);
7371 alc883_clevo_m720_mic_automute(codec);
7372}
7373
7374static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7375 unsigned int res)
7376{
7377 switch (res >> 26) {
7378 case ALC880_HP_EVENT:
7379 alc883_clevo_m720_hp_automute(codec);
7380 break;
7381 case ALC880_MIC_EVENT:
7382 alc883_clevo_m720_mic_automute(codec);
7383 break;
7384 }
7385}
7386
7387/* toggle speaker-output according to the hp-jack state */
7388static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7389{
7390 unsigned int present;
7391 unsigned char bits;
7392
7393 present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7394 & AC_PINSENSE_PRESENCE;
7395 bits = present ? HDA_AMP_MUTE : 0;
7396 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7397 HDA_AMP_MUTE, bits);
7398}
7399
7400static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7401 unsigned int res)
7402{
7403 if ((res >> 26) == ALC880_HP_EVENT)
7404 alc883_2ch_fujitsu_pi2515_automute(codec);
7405}
7406
7357static void alc883_haier_w66_automute(struct hda_codec *codec) 7407static void alc883_haier_w66_automute(struct hda_codec *codec)
7358{ 7408{
7359 unsigned int present; 7409 unsigned int present;
@@ -7587,10 +7637,11 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
7587 [ALC883_LENOVO_NB0763] = "lenovo-nb0763", 7637 [ALC883_LENOVO_NB0763] = "lenovo-nb0763",
7588 [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig", 7638 [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7589 [ALC883_HAIER_W66] = "haier-w66", 7639 [ALC883_HAIER_W66] = "haier-w66",
7590 [ALC888_6ST_HP] = "6stack-hp",
7591 [ALC888_3ST_HP] = "3stack-hp", 7640 [ALC888_3ST_HP] = "3stack-hp",
7592 [ALC888_6ST_DELL] = "6stack-dell", 7641 [ALC888_6ST_DELL] = "6stack-dell",
7593 [ALC883_MITAC] = "mitac", 7642 [ALC883_MITAC] = "mitac",
7643 [ALC883_CLEVO_M720] = "clevo-m720",
7644 [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
7594 [ALC883_AUTO] = "auto", 7645 [ALC883_AUTO] = "auto",
7595}; 7646};
7596 7647
@@ -7604,7 +7655,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7604 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG), 7655 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7605 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP), 7656 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7606 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP), 7657 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7607 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_6ST_HP), 7658 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
7608 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG), 7659 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7609 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG), 7660 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7610 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC), 7661 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
@@ -7614,7 +7665,9 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7614 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG), 7665 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7615 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG), 7666 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7616 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG), 7667 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7668 SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
7617 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG), 7669 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7670 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
7618 SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG), 7671 SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7619 SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG), 7672 SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7620 SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG), 7673 SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
@@ -7627,13 +7680,17 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7627 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG), 7680 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7628 SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG), 7681 SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7629 SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG), 7682 SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7683 SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
7630 SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG), 7684 SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7631 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG), 7685 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7632 SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG), 7686 SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7633 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG), 7687 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7688 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
7689 SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
7634 SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD), 7690 SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7635 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch), 7691 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7636 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION), 7692 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7693 SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
7637 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch), 7694 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7638 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763), 7695 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7639 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763), 7696 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
@@ -7652,8 +7709,6 @@ static struct alc_config_preset alc883_presets[] = {
7652 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7709 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7653 .dac_nids = alc883_dac_nids, 7710 .dac_nids = alc883_dac_nids,
7654 .dig_out_nid = ALC883_DIGOUT_NID, 7711 .dig_out_nid = ALC883_DIGOUT_NID,
7655 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7656 .adc_nids = alc883_adc_nids,
7657 .dig_in_nid = ALC883_DIGIN_NID, 7712 .dig_in_nid = ALC883_DIGIN_NID,
7658 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7713 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7659 .channel_mode = alc883_3ST_2ch_modes, 7714 .channel_mode = alc883_3ST_2ch_modes,
@@ -7665,8 +7720,6 @@ static struct alc_config_preset alc883_presets[] = {
7665 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7720 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7666 .dac_nids = alc883_dac_nids, 7721 .dac_nids = alc883_dac_nids,
7667 .dig_out_nid = ALC883_DIGOUT_NID, 7722 .dig_out_nid = ALC883_DIGOUT_NID,
7668 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7669 .adc_nids = alc883_adc_nids,
7670 .dig_in_nid = ALC883_DIGIN_NID, 7723 .dig_in_nid = ALC883_DIGIN_NID,
7671 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7724 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7672 .channel_mode = alc883_3ST_6ch_modes, 7725 .channel_mode = alc883_3ST_6ch_modes,
@@ -7678,8 +7731,6 @@ static struct alc_config_preset alc883_presets[] = {
7678 .init_verbs = { alc883_init_verbs }, 7731 .init_verbs = { alc883_init_verbs },
7679 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7732 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7680 .dac_nids = alc883_dac_nids, 7733 .dac_nids = alc883_dac_nids,
7681 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7682 .adc_nids = alc883_adc_nids,
7683 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7734 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7684 .channel_mode = alc883_3ST_6ch_modes, 7735 .channel_mode = alc883_3ST_6ch_modes,
7685 .need_dac_fix = 1, 7736 .need_dac_fix = 1,
@@ -7691,8 +7742,6 @@ static struct alc_config_preset alc883_presets[] = {
7691 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7742 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7692 .dac_nids = alc883_dac_nids, 7743 .dac_nids = alc883_dac_nids,
7693 .dig_out_nid = ALC883_DIGOUT_NID, 7744 .dig_out_nid = ALC883_DIGOUT_NID,
7694 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7695 .adc_nids = alc883_adc_nids,
7696 .dig_in_nid = ALC883_DIGIN_NID, 7745 .dig_in_nid = ALC883_DIGIN_NID,
7697 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 7746 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7698 .channel_mode = alc883_sixstack_modes, 7747 .channel_mode = alc883_sixstack_modes,
@@ -7704,8 +7753,6 @@ static struct alc_config_preset alc883_presets[] = {
7704 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7753 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7705 .dac_nids = alc883_dac_nids, 7754 .dac_nids = alc883_dac_nids,
7706 .dig_out_nid = ALC883_DIGOUT_NID, 7755 .dig_out_nid = ALC883_DIGOUT_NID,
7707 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7708 .adc_nids = alc883_adc_nids,
7709 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7756 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7710 .channel_mode = alc883_3ST_6ch_modes, 7757 .channel_mode = alc883_3ST_6ch_modes,
7711 .need_dac_fix = 1, 7758 .need_dac_fix = 1,
@@ -7719,8 +7766,6 @@ static struct alc_config_preset alc883_presets[] = {
7719 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7766 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7720 .dac_nids = alc883_dac_nids, 7767 .dac_nids = alc883_dac_nids,
7721 .dig_out_nid = ALC883_DIGOUT_NID, 7768 .dig_out_nid = ALC883_DIGOUT_NID,
7722 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7723 .adc_nids = alc883_adc_nids,
7724 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7769 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7725 .channel_mode = alc883_3ST_2ch_modes, 7770 .channel_mode = alc883_3ST_2ch_modes,
7726 .input_mux = &alc883_capture_source, 7771 .input_mux = &alc883_capture_source,
@@ -7737,8 +7782,6 @@ static struct alc_config_preset alc883_presets[] = {
7737 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs }, 7782 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7738 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7783 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7739 .dac_nids = alc883_dac_nids, 7784 .dac_nids = alc883_dac_nids,
7740 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7741 .adc_nids = alc883_adc_nids,
7742 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7785 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7743 .channel_mode = alc883_3ST_2ch_modes, 7786 .channel_mode = alc883_3ST_2ch_modes,
7744 .input_mux = &alc883_capture_source, 7787 .input_mux = &alc883_capture_source,
@@ -7749,8 +7792,6 @@ static struct alc_config_preset alc883_presets[] = {
7749 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7792 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7750 .dac_nids = alc883_dac_nids, 7793 .dac_nids = alc883_dac_nids,
7751 .dig_out_nid = ALC883_DIGOUT_NID, 7794 .dig_out_nid = ALC883_DIGOUT_NID,
7752 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7753 .adc_nids = alc883_adc_nids,
7754 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7795 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7755 .channel_mode = alc883_3ST_2ch_modes, 7796 .channel_mode = alc883_3ST_2ch_modes,
7756 .input_mux = &alc883_capture_source, 7797 .input_mux = &alc883_capture_source,
@@ -7764,8 +7805,6 @@ static struct alc_config_preset alc883_presets[] = {
7764 alc883_medion_eapd_verbs }, 7805 alc883_medion_eapd_verbs },
7765 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7806 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7766 .dac_nids = alc883_dac_nids, 7807 .dac_nids = alc883_dac_nids,
7767 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7768 .adc_nids = alc883_adc_nids,
7769 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 7808 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7770 .channel_mode = alc883_sixstack_modes, 7809 .channel_mode = alc883_sixstack_modes,
7771 .input_mux = &alc883_capture_source, 7810 .input_mux = &alc883_capture_source,
@@ -7776,8 +7815,6 @@ static struct alc_config_preset alc883_presets[] = {
7776 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7815 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7777 .dac_nids = alc883_dac_nids, 7816 .dac_nids = alc883_dac_nids,
7778 .dig_out_nid = ALC883_DIGOUT_NID, 7817 .dig_out_nid = ALC883_DIGOUT_NID,
7779 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7780 .adc_nids = alc883_adc_nids,
7781 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7818 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7782 .channel_mode = alc883_3ST_2ch_modes, 7819 .channel_mode = alc883_3ST_2ch_modes,
7783 .input_mux = &alc883_capture_source, 7820 .input_mux = &alc883_capture_source,
@@ -7789,19 +7826,27 @@ static struct alc_config_preset alc883_presets[] = {
7789 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs }, 7826 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7790 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7827 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7791 .dac_nids = alc883_dac_nids, 7828 .dac_nids = alc883_dac_nids,
7792 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7793 .adc_nids = alc883_adc_nids,
7794 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7829 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7795 .channel_mode = alc883_3ST_2ch_modes, 7830 .channel_mode = alc883_3ST_2ch_modes,
7796 .input_mux = &alc883_capture_source, 7831 .input_mux = &alc883_capture_source,
7797 }, 7832 },
7833 [ALC883_CLEVO_M720] = {
7834 .mixers = { alc883_clevo_m720_mixer },
7835 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
7836 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7837 .dac_nids = alc883_dac_nids,
7838 .dig_out_nid = ALC883_DIGOUT_NID,
7839 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7840 .channel_mode = alc883_3ST_2ch_modes,
7841 .input_mux = &alc883_capture_source,
7842 .unsol_event = alc883_clevo_m720_unsol_event,
7843 .init_hook = alc883_clevo_m720_automute,
7844 },
7798 [ALC883_LENOVO_101E_2ch] = { 7845 [ALC883_LENOVO_101E_2ch] = {
7799 .mixers = { alc883_lenovo_101e_2ch_mixer}, 7846 .mixers = { alc883_lenovo_101e_2ch_mixer},
7800 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs}, 7847 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7801 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7848 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7802 .dac_nids = alc883_dac_nids, 7849 .dac_nids = alc883_dac_nids,
7803 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7804 .adc_nids = alc883_adc_nids,
7805 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7850 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7806 .channel_mode = alc883_3ST_2ch_modes, 7851 .channel_mode = alc883_3ST_2ch_modes,
7807 .input_mux = &alc883_lenovo_101e_capture_source, 7852 .input_mux = &alc883_lenovo_101e_capture_source,
@@ -7813,8 +7858,6 @@ static struct alc_config_preset alc883_presets[] = {
7813 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs}, 7858 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7814 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7859 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7815 .dac_nids = alc883_dac_nids, 7860 .dac_nids = alc883_dac_nids,
7816 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7817 .adc_nids = alc883_adc_nids,
7818 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7861 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7819 .channel_mode = alc883_3ST_2ch_modes, 7862 .channel_mode = alc883_3ST_2ch_modes,
7820 .need_dac_fix = 1, 7863 .need_dac_fix = 1,
@@ -7828,8 +7871,6 @@ static struct alc_config_preset alc883_presets[] = {
7828 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7871 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7829 .dac_nids = alc883_dac_nids, 7872 .dac_nids = alc883_dac_nids,
7830 .dig_out_nid = ALC883_DIGOUT_NID, 7873 .dig_out_nid = ALC883_DIGOUT_NID,
7831 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7832 .adc_nids = alc883_adc_nids,
7833 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7874 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7834 .channel_mode = alc883_3ST_6ch_modes, 7875 .channel_mode = alc883_3ST_6ch_modes,
7835 .need_dac_fix = 1, 7876 .need_dac_fix = 1,
@@ -7843,47 +7884,28 @@ static struct alc_config_preset alc883_presets[] = {
7843 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7884 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7844 .dac_nids = alc883_dac_nids, 7885 .dac_nids = alc883_dac_nids,
7845 .dig_out_nid = ALC883_DIGOUT_NID, 7886 .dig_out_nid = ALC883_DIGOUT_NID,
7846 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7847 .adc_nids = alc883_adc_nids,
7848 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7887 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7849 .channel_mode = alc883_3ST_2ch_modes, 7888 .channel_mode = alc883_3ST_2ch_modes,
7850 .input_mux = &alc883_capture_source, 7889 .input_mux = &alc883_capture_source,
7851 .unsol_event = alc883_haier_w66_unsol_event, 7890 .unsol_event = alc883_haier_w66_unsol_event,
7852 .init_hook = alc883_haier_w66_automute, 7891 .init_hook = alc883_haier_w66_automute,
7853 },
7854 [ALC888_6ST_HP] = {
7855 .mixers = { alc888_6st_hp_mixer, alc883_chmode_mixer },
7856 .init_verbs = { alc883_init_verbs, alc888_6st_hp_verbs },
7857 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7858 .dac_nids = alc883_dac_nids,
7859 .dig_out_nid = ALC883_DIGOUT_NID,
7860 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7861 .adc_nids = alc883_adc_nids,
7862 .dig_in_nid = ALC883_DIGIN_NID,
7863 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7864 .channel_mode = alc883_sixstack_modes,
7865 .input_mux = &alc883_capture_source,
7866 }, 7892 },
7867 [ALC888_3ST_HP] = { 7893 [ALC888_3ST_HP] = {
7868 .mixers = { alc888_3st_hp_mixer, alc883_chmode_mixer }, 7894 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7869 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs }, 7895 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7870 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7896 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7871 .dac_nids = alc883_dac_nids, 7897 .dac_nids = alc883_dac_nids,
7872 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7873 .adc_nids = alc883_adc_nids,
7874 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes), 7898 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7875 .channel_mode = alc888_3st_hp_modes, 7899 .channel_mode = alc888_3st_hp_modes,
7876 .need_dac_fix = 1, 7900 .need_dac_fix = 1,
7877 .input_mux = &alc883_capture_source, 7901 .input_mux = &alc883_capture_source,
7878 }, 7902 },
7879 [ALC888_6ST_DELL] = { 7903 [ALC888_6ST_DELL] = {
7880 .mixers = { alc888_6st_dell_mixer, alc883_chmode_mixer }, 7904 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7881 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs }, 7905 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
7882 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7906 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7883 .dac_nids = alc883_dac_nids, 7907 .dac_nids = alc883_dac_nids,
7884 .dig_out_nid = ALC883_DIGOUT_NID, 7908 .dig_out_nid = ALC883_DIGOUT_NID,
7885 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7886 .adc_nids = alc883_adc_nids,
7887 .dig_in_nid = ALC883_DIGIN_NID, 7909 .dig_in_nid = ALC883_DIGIN_NID,
7888 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 7910 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7889 .channel_mode = alc883_sixstack_modes, 7911 .channel_mode = alc883_sixstack_modes,
@@ -7896,14 +7918,25 @@ static struct alc_config_preset alc883_presets[] = {
7896 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs }, 7918 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
7897 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7919 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7898 .dac_nids = alc883_dac_nids, 7920 .dac_nids = alc883_dac_nids,
7899 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7900 .adc_nids = alc883_adc_nids,
7901 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7921 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7902 .channel_mode = alc883_3ST_2ch_modes, 7922 .channel_mode = alc883_3ST_2ch_modes,
7903 .input_mux = &alc883_capture_source, 7923 .input_mux = &alc883_capture_source,
7904 .unsol_event = alc883_mitac_unsol_event, 7924 .unsol_event = alc883_mitac_unsol_event,
7905 .init_hook = alc883_mitac_automute, 7925 .init_hook = alc883_mitac_automute,
7906 }, 7926 },
7927 [ALC883_FUJITSU_PI2515] = {
7928 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
7929 .init_verbs = { alc883_init_verbs,
7930 alc883_2ch_fujitsu_pi2515_verbs},
7931 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7932 .dac_nids = alc883_dac_nids,
7933 .dig_out_nid = ALC883_DIGOUT_NID,
7934 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7935 .channel_mode = alc883_3ST_2ch_modes,
7936 .input_mux = &alc883_fujitsu_pi2515_capture_source,
7937 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
7938 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
7939 },
7907}; 7940};
7908 7941
7909 7942
@@ -7918,15 +7951,11 @@ static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
7918 struct alc_spec *spec = codec->spec; 7951 struct alc_spec *spec = codec->spec;
7919 int idx; 7952 int idx;
7920 7953
7954 alc_set_pin_output(codec, nid, pin_type);
7921 if (spec->multiout.dac_nids[dac_idx] == 0x25) 7955 if (spec->multiout.dac_nids[dac_idx] == 0x25)
7922 idx = 4; 7956 idx = 4;
7923 else 7957 else
7924 idx = spec->multiout.dac_nids[dac_idx] - 2; 7958 idx = spec->multiout.dac_nids[dac_idx] - 2;
7925
7926 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7927 pin_type);
7928 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7929 AMP_OUT_UNMUTE);
7930 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx); 7959 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7931 7960
7932} 7961}
@@ -7955,6 +7984,9 @@ static void alc883_auto_init_hp_out(struct hda_codec *codec)
7955 if (pin) /* connect to front */ 7984 if (pin) /* connect to front */
7956 /* use dac 0 */ 7985 /* use dac 0 */
7957 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 7986 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7987 pin = spec->autocfg.speaker_pins[0];
7988 if (pin)
7989 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7958} 7990}
7959 7991
7960#define alc883_is_input_pin(nid) alc880_is_input_pin(nid) 7992#define alc883_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -8006,9 +8038,12 @@ static int alc883_parse_auto_config(struct hda_codec *codec)
8006/* additional initialization for auto-configuration model */ 8038/* additional initialization for auto-configuration model */
8007static void alc883_auto_init(struct hda_codec *codec) 8039static void alc883_auto_init(struct hda_codec *codec)
8008{ 8040{
8041 struct alc_spec *spec = codec->spec;
8009 alc883_auto_init_multi_out(codec); 8042 alc883_auto_init_multi_out(codec);
8010 alc883_auto_init_hp_out(codec); 8043 alc883_auto_init_hp_out(codec);
8011 alc883_auto_init_analog_input(codec); 8044 alc883_auto_init_analog_input(codec);
8045 if (spec->unsol_event)
8046 alc_sku_automute(codec);
8012} 8047}
8013 8048
8014static int patch_alc883(struct hda_codec *codec) 8049static int patch_alc883(struct hda_codec *codec)
@@ -8057,10 +8092,9 @@ static int patch_alc883(struct hda_codec *codec)
8057 spec->stream_digital_playback = &alc883_pcm_digital_playback; 8092 spec->stream_digital_playback = &alc883_pcm_digital_playback;
8058 spec->stream_digital_capture = &alc883_pcm_digital_capture; 8093 spec->stream_digital_capture = &alc883_pcm_digital_capture;
8059 8094
8060 if (!spec->adc_nids && spec->input_mux) { 8095 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8061 spec->adc_nids = alc883_adc_nids; 8096 spec->adc_nids = alc883_adc_nids;
8062 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids); 8097 spec->capsrc_nids = alc883_capsrc_nids;
8063 }
8064 8098
8065 spec->vmaster_nid = 0x0c; 8099 spec->vmaster_nid = 0x0c;
8066 8100
@@ -8085,6 +8119,8 @@ static int patch_alc883(struct hda_codec *codec)
8085#define alc262_dac_nids alc260_dac_nids 8119#define alc262_dac_nids alc260_dac_nids
8086#define alc262_adc_nids alc882_adc_nids 8120#define alc262_adc_nids alc882_adc_nids
8087#define alc262_adc_nids_alt alc882_adc_nids_alt 8121#define alc262_adc_nids_alt alc882_adc_nids_alt
8122#define alc262_capsrc_nids alc882_capsrc_nids
8123#define alc262_capsrc_nids_alt alc882_capsrc_nids_alt
8088 8124
8089#define alc262_modes alc260_modes 8125#define alc262_modes alc260_modes
8090#define alc262_capture_source alc882_capture_source 8126#define alc262_capture_source alc882_capture_source
@@ -8585,7 +8621,8 @@ static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8585 8621
8586/* 8622/*
8587 * fujitsu model 8623 * fujitsu model
8588 * 0x14 = headphone/spdif-out, 0x15 = internal speaker 8624 * 0x14 = headphone/spdif-out, 0x15 = internal speaker,
8625 * 0x1b = port replicator headphone out
8589 */ 8626 */
8590 8627
8591#define ALC_HP_EVENT 0x37 8628#define ALC_HP_EVENT 0x37
@@ -8593,6 +8630,14 @@ static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8593static struct hda_verb alc262_fujitsu_unsol_verbs[] = { 8630static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8594 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT}, 8631 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8595 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 8632 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8633 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8634 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8635 {}
8636};
8637
8638static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
8639 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8640 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8596 {} 8641 {}
8597}; 8642};
8598 8643
@@ -8633,12 +8678,16 @@ static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
8633 unsigned int mute; 8678 unsigned int mute;
8634 8679
8635 if (force || !spec->sense_updated) { 8680 if (force || !spec->sense_updated) {
8636 unsigned int present; 8681 unsigned int present_int_hp, present_dock_hp;
8637 /* need to execute and sync at first */ 8682 /* need to execute and sync at first */
8638 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0); 8683 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
8639 present = snd_hda_codec_read(codec, 0x14, 0, 8684 present_int_hp = snd_hda_codec_read(codec, 0x14, 0,
8640 AC_VERB_GET_PIN_SENSE, 0); 8685 AC_VERB_GET_PIN_SENSE, 0);
8641 spec->jack_present = (present & 0x80000000) != 0; 8686 snd_hda_codec_read(codec, 0x1B, 0, AC_VERB_SET_PIN_SENSE, 0);
8687 present_dock_hp = snd_hda_codec_read(codec, 0x1b, 0,
8688 AC_VERB_GET_PIN_SENSE, 0);
8689 spec->jack_present = (present_int_hp & 0x80000000) != 0;
8690 spec->jack_present |= (present_dock_hp & 0x80000000) != 0;
8642 spec->sense_updated = 1; 8691 spec->sense_updated = 1;
8643 } 8692 }
8644 if (spec->jack_present) { 8693 if (spec->jack_present) {
@@ -8672,6 +8721,46 @@ static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
8672 }, 8721 },
8673}; 8722};
8674 8723
8724/* mute/unmute internal speaker according to the hp jack and mute state */
8725static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
8726{
8727 struct alc_spec *spec = codec->spec;
8728 unsigned int mute;
8729
8730 if (force || !spec->sense_updated) {
8731 unsigned int present_int_hp;
8732 /* need to execute and sync at first */
8733 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8734 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
8735 AC_VERB_GET_PIN_SENSE, 0);
8736 spec->jack_present = (present_int_hp & 0x80000000) != 0;
8737 spec->sense_updated = 1;
8738 }
8739 if (spec->jack_present) {
8740 /* mute internal speaker */
8741 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8742 HDA_AMP_MUTE, HDA_AMP_MUTE);
8743 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8744 HDA_AMP_MUTE, HDA_AMP_MUTE);
8745 } else {
8746 /* unmute internal speaker if necessary */
8747 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8748 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8749 HDA_AMP_MUTE, mute);
8750 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8751 HDA_AMP_MUTE, mute);
8752 }
8753}
8754
8755/* unsolicited event for HP jack sensing */
8756static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
8757 unsigned int res)
8758{
8759 if ((res >> 26) != ALC_HP_EVENT)
8760 return;
8761 alc262_lenovo_3000_automute(codec, 1);
8762}
8763
8675/* bind hp and internal speaker mute (with plug check) */ 8764/* bind hp and internal speaker mute (with plug check) */
8676static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol, 8765static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8677 struct snd_ctl_elem_value *ucontrol) 8766 struct snd_ctl_elem_value *ucontrol)
@@ -8680,12 +8769,13 @@ static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8680 long *valp = ucontrol->value.integer.value; 8769 long *valp = ucontrol->value.integer.value;
8681 int change; 8770 int change;
8682 8771
8683 change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0, 8772 change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8684 HDA_AMP_MUTE, 8773 HDA_AMP_MUTE,
8685 valp[0] ? 0 : HDA_AMP_MUTE); 8774 valp ? 0 : HDA_AMP_MUTE);
8686 change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0, 8775 change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8687 HDA_AMP_MUTE, 8776 HDA_AMP_MUTE,
8688 valp[1] ? 0 : HDA_AMP_MUTE); 8777 valp ? 0 : HDA_AMP_MUTE);
8778
8689 if (change) 8779 if (change)
8690 alc262_fujitsu_automute(codec, 0); 8780 alc262_fujitsu_automute(codec, 0);
8691 return change; 8781 return change;
@@ -8703,6 +8793,46 @@ static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
8703 }, 8793 },
8704 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 8794 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8705 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 8795 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8796 HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
8797 HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
8798 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8799 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8800 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8801 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8802 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8803 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8804 { } /* end */
8805};
8806
8807/* bind hp and internal speaker mute (with plug check) */
8808static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
8809 struct snd_ctl_elem_value *ucontrol)
8810{
8811 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8812 long *valp = ucontrol->value.integer.value;
8813 int change;
8814
8815 change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8816 HDA_AMP_MUTE,
8817 valp ? 0 : HDA_AMP_MUTE);
8818
8819 if (change)
8820 alc262_lenovo_3000_automute(codec, 0);
8821 return change;
8822}
8823
8824static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
8825 HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8826 {
8827 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8828 .name = "Master Playback Switch",
8829 .info = snd_hda_mixer_amp_switch_info,
8830 .get = snd_hda_mixer_amp_switch_get,
8831 .put = alc262_lenovo_3000_master_sw_put,
8832 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
8833 },
8834 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8835 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8706 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8836 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8707 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8837 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8708 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8838 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
@@ -8730,59 +8860,72 @@ static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
8730 8860
8731/* Samsung Q1 Ultra Vista model setup */ 8861/* Samsung Q1 Ultra Vista model setup */
8732static struct snd_kcontrol_new alc262_ultra_mixer[] = { 8862static struct snd_kcontrol_new alc262_ultra_mixer[] = {
8733 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 8863 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8734 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT), 8864 HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
8735 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8736 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 8865 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8737 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 8866 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8738 HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT), 8867 HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8868 HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
8739 { } /* end */ 8869 { } /* end */
8740}; 8870};
8741 8871
8742static struct hda_verb alc262_ultra_verbs[] = { 8872static struct hda_verb alc262_ultra_verbs[] = {
8743 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, 8873 /* output mixer */
8874 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8875 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8876 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8877 /* speaker */
8878 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8880 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8881 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8882 /* HP */
8744 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 8883 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8745 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 8884 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8746 /* Mic is on Node 0x19 */ 8885 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8747 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24}, 8886 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8748 {0x22, AC_VERB_SET_CONNECT_SEL, 0x01}, 8887 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8749 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, 8888 /* internal mic */
8750 {0x23, AC_VERB_SET_CONNECT_SEL, 0x01}, 8889 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8751 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, 8890 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8752 {0x24, AC_VERB_SET_CONNECT_SEL, 0x01}, 8891 /* ADC, choose mic */
8753 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, 8892 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8893 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8894 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8895 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8896 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8897 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8898 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8899 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8900 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8901 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
8754 {} 8902 {}
8755}; 8903};
8756 8904
8757static struct hda_input_mux alc262_ultra_capture_source = {
8758 .num_items = 1,
8759 .items = {
8760 { "Mic", 0x1 },
8761 },
8762};
8763
8764/* mute/unmute internal speaker according to the hp jack and mute state */ 8905/* mute/unmute internal speaker according to the hp jack and mute state */
8765static void alc262_ultra_automute(struct hda_codec *codec) 8906static void alc262_ultra_automute(struct hda_codec *codec)
8766{ 8907{
8767 struct alc_spec *spec = codec->spec; 8908 struct alc_spec *spec = codec->spec;
8768 unsigned int mute; 8909 unsigned int mute;
8769 unsigned int present;
8770 8910
8771 /* need to execute and sync at first */ 8911 mute = 0;
8772 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0); 8912 /* auto-mute only when HP is used as HP */
8773 present = snd_hda_codec_read(codec, 0x15, 0, 8913 if (!spec->cur_mux[0]) {
8774 AC_VERB_GET_PIN_SENSE, 0); 8914 unsigned int present;
8775 spec->jack_present = (present & 0x80000000) != 0; 8915 /* need to execute and sync at first */
8776 if (spec->jack_present) { 8916 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8777 /* mute internal speaker */ 8917 present = snd_hda_codec_read(codec, 0x15, 0,
8778 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8918 AC_VERB_GET_PIN_SENSE, 0);
8779 HDA_AMP_MUTE, HDA_AMP_MUTE); 8919 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8780 } else { 8920 if (spec->jack_present)
8781 /* unmute internal speaker if necessary */ 8921 mute = HDA_AMP_MUTE;
8782 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8783 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8784 HDA_AMP_MUTE, mute);
8785 } 8922 }
8923 /* mute/unmute internal speaker */
8924 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8925 HDA_AMP_MUTE, mute);
8926 /* mute/unmute HP */
8927 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8928 HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
8786} 8929}
8787 8930
8788/* unsolicited event for HP jack sensing */ 8931/* unsolicited event for HP jack sensing */
@@ -8794,6 +8937,45 @@ static void alc262_ultra_unsol_event(struct hda_codec *codec,
8794 alc262_ultra_automute(codec); 8937 alc262_ultra_automute(codec);
8795} 8938}
8796 8939
8940static struct hda_input_mux alc262_ultra_capture_source = {
8941 .num_items = 2,
8942 .items = {
8943 { "Mic", 0x1 },
8944 { "Headphone", 0x7 },
8945 },
8946};
8947
8948static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
8949 struct snd_ctl_elem_value *ucontrol)
8950{
8951 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8952 struct alc_spec *spec = codec->spec;
8953 int ret;
8954
8955 ret = alc882_mux_enum_put(kcontrol, ucontrol);
8956 if (!ret)
8957 return 0;
8958 /* reprogram the HP pin as mic or HP according to the input source */
8959 snd_hda_codec_write_cache(codec, 0x15, 0,
8960 AC_VERB_SET_PIN_WIDGET_CONTROL,
8961 spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
8962 alc262_ultra_automute(codec); /* mute/unmute HP */
8963 return ret;
8964}
8965
8966static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
8967 HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
8968 HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
8969 {
8970 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8971 .name = "Capture Source",
8972 .info = alc882_mux_enum_info,
8973 .get = alc882_mux_enum_get,
8974 .put = alc262_ultra_mux_enum_put,
8975 },
8976 { } /* end */
8977};
8978
8797/* add playback controls from the parsed DAC table */ 8979/* add playback controls from the parsed DAC table */
8798static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec, 8980static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
8799 const struct auto_pin_cfg *cfg) 8981 const struct auto_pin_cfg *cfg)
@@ -9185,9 +9367,12 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
9185/* init callback for auto-configuration model -- overriding the default init */ 9367/* init callback for auto-configuration model -- overriding the default init */
9186static void alc262_auto_init(struct hda_codec *codec) 9368static void alc262_auto_init(struct hda_codec *codec)
9187{ 9369{
9370 struct alc_spec *spec = codec->spec;
9188 alc262_auto_init_multi_out(codec); 9371 alc262_auto_init_multi_out(codec);
9189 alc262_auto_init_hp_out(codec); 9372 alc262_auto_init_hp_out(codec);
9190 alc262_auto_init_analog_input(codec); 9373 alc262_auto_init_analog_input(codec);
9374 if (spec->unsol_event)
9375 alc_sku_automute(codec);
9191} 9376}
9192 9377
9193/* 9378/*
@@ -9206,6 +9391,7 @@ static const char *alc262_models[ALC262_MODEL_LAST] = {
9206 [ALC262_BENQ_T31] = "benq-t31", 9391 [ALC262_BENQ_T31] = "benq-t31",
9207 [ALC262_SONY_ASSAMD] = "sony-assamd", 9392 [ALC262_SONY_ASSAMD] = "sony-assamd",
9208 [ALC262_ULTRA] = "ultra", 9393 [ALC262_ULTRA] = "ultra",
9394 [ALC262_LENOVO_3000] = "lenovo-3000",
9209 [ALC262_AUTO] = "auto", 9395 [ALC262_AUTO] = "auto",
9210}; 9396};
9211 9397
@@ -9241,6 +9427,8 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
9241 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU), 9427 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9242 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU), 9428 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9243 SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA), 9429 SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9430 SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9431 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
9244 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8), 9432 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9245 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31), 9433 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9246 SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1), 9434 SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
@@ -9390,18 +9578,32 @@ static struct alc_config_preset alc262_presets[] = {
9390 .init_hook = alc262_hippo_automute, 9578 .init_hook = alc262_hippo_automute,
9391 }, 9579 },
9392 [ALC262_ULTRA] = { 9580 [ALC262_ULTRA] = {
9393 .mixers = { alc262_ultra_mixer }, 9581 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9394 .init_verbs = { alc262_init_verbs, alc262_ultra_verbs }, 9582 .init_verbs = { alc262_ultra_verbs },
9395 .num_dacs = ARRAY_SIZE(alc262_dac_nids), 9583 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9396 .dac_nids = alc262_dac_nids, 9584 .dac_nids = alc262_dac_nids,
9397 .hp_nid = 0x03,
9398 .dig_out_nid = ALC262_DIGOUT_NID,
9399 .num_channel_mode = ARRAY_SIZE(alc262_modes), 9585 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9400 .channel_mode = alc262_modes, 9586 .channel_mode = alc262_modes,
9401 .input_mux = &alc262_ultra_capture_source, 9587 .input_mux = &alc262_ultra_capture_source,
9588 .adc_nids = alc262_adc_nids, /* ADC0 */
9589 .capsrc_nids = alc262_capsrc_nids,
9590 .num_adc_nids = 1, /* single ADC */
9402 .unsol_event = alc262_ultra_unsol_event, 9591 .unsol_event = alc262_ultra_unsol_event,
9403 .init_hook = alc262_ultra_automute, 9592 .init_hook = alc262_ultra_automute,
9404 }, 9593 },
9594 [ALC262_LENOVO_3000] = {
9595 .mixers = { alc262_lenovo_3000_mixer },
9596 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9597 alc262_lenovo_3000_unsol_verbs },
9598 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9599 .dac_nids = alc262_dac_nids,
9600 .hp_nid = 0x03,
9601 .dig_out_nid = ALC262_DIGOUT_NID,
9602 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9603 .channel_mode = alc262_modes,
9604 .input_mux = &alc262_fujitsu_capture_source,
9605 .unsol_event = alc262_lenovo_3000_unsol_event,
9606 },
9405}; 9607};
9406 9608
9407static int patch_alc262(struct hda_codec *codec) 9609static int patch_alc262(struct hda_codec *codec)
@@ -9472,12 +9674,14 @@ static int patch_alc262(struct hda_codec *codec)
9472 if (wcap != AC_WID_AUD_IN) { 9674 if (wcap != AC_WID_AUD_IN) {
9473 spec->adc_nids = alc262_adc_nids_alt; 9675 spec->adc_nids = alc262_adc_nids_alt;
9474 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt); 9676 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
9677 spec->capsrc_nids = alc262_capsrc_nids_alt;
9475 spec->mixers[spec->num_mixers] = 9678 spec->mixers[spec->num_mixers] =
9476 alc262_capture_alt_mixer; 9679 alc262_capture_alt_mixer;
9477 spec->num_mixers++; 9680 spec->num_mixers++;
9478 } else { 9681 } else {
9479 spec->adc_nids = alc262_adc_nids; 9682 spec->adc_nids = alc262_adc_nids;
9480 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids); 9683 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
9684 spec->capsrc_nids = alc262_capsrc_nids;
9481 spec->mixers[spec->num_mixers] = alc262_capture_mixer; 9685 spec->mixers[spec->num_mixers] = alc262_capture_mixer;
9482 spec->num_mixers++; 9686 spec->num_mixers++;
9483 } 9687 }
@@ -9517,6 +9721,8 @@ static hda_nid_t alc268_adc_nids_alt[1] = {
9517 0x08 9721 0x08
9518}; 9722};
9519 9723
9724static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
9725
9520static struct snd_kcontrol_new alc268_base_mixer[] = { 9726static struct snd_kcontrol_new alc268_base_mixer[] = {
9521 /* output mixer control */ 9727 /* output mixer control */
9522 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT), 9728 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
@@ -9529,6 +9735,22 @@ static struct snd_kcontrol_new alc268_base_mixer[] = {
9529 { } 9735 { }
9530}; 9736};
9531 9737
9738/* bind Beep switches of both NID 0x0f and 0x10 */
9739static struct hda_bind_ctls alc268_bind_beep_sw = {
9740 .ops = &snd_hda_bind_sw,
9741 .values = {
9742 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
9743 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
9744 0
9745 },
9746};
9747
9748static struct snd_kcontrol_new alc268_beep_mixer[] = {
9749 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
9750 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
9751 { }
9752};
9753
9532static struct hda_verb alc268_eapd_verbs[] = { 9754static struct hda_verb alc268_eapd_verbs[] = {
9533 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, 9755 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9534 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2}, 9756 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
@@ -9613,8 +9835,12 @@ static struct snd_kcontrol_new alc268_acer_mixer[] = {
9613}; 9835};
9614 9836
9615static struct hda_verb alc268_acer_verbs[] = { 9837static struct hda_verb alc268_acer_verbs[] = {
9838 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
9839 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9616 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 9840 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9617 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9841 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9842 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9843 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9618 9844
9619 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 9845 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9620 { } 9846 { }
@@ -9685,6 +9911,64 @@ static void alc268_dell_unsol_event(struct hda_codec *codec,
9685 9911
9686#define alc268_dell_init_hook alc268_dell_automute 9912#define alc268_dell_init_hook alc268_dell_automute
9687 9913
9914static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
9915 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9916 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9917 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9918 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9919 HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9920 HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
9921 HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
9922 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9923 { }
9924};
9925
9926static struct hda_verb alc267_quanta_il1_verbs[] = {
9927 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9928 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
9929 { }
9930};
9931
9932static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
9933{
9934 unsigned int present;
9935
9936 present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
9937 & AC_PINSENSE_PRESENCE;
9938 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
9939 present ? 0 : PIN_OUT);
9940}
9941
9942static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
9943{
9944 unsigned int present;
9945
9946 present = snd_hda_codec_read(codec, 0x18, 0,
9947 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9948 snd_hda_codec_write(codec, 0x23, 0,
9949 AC_VERB_SET_CONNECT_SEL,
9950 present ? 0x00 : 0x01);
9951}
9952
9953static void alc267_quanta_il1_automute(struct hda_codec *codec)
9954{
9955 alc267_quanta_il1_hp_automute(codec);
9956 alc267_quanta_il1_mic_automute(codec);
9957}
9958
9959static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
9960 unsigned int res)
9961{
9962 switch (res >> 26) {
9963 case ALC880_HP_EVENT:
9964 alc267_quanta_il1_hp_automute(codec);
9965 break;
9966 case ALC880_MIC_EVENT:
9967 alc267_quanta_il1_mic_automute(codec);
9968 break;
9969 }
9970}
9971
9688/* 9972/*
9689 * generic initialization of ADC, input mixers and output mixers 9973 * generic initialization of ADC, input mixers and output mixers
9690 */ 9974 */
@@ -9725,7 +10009,11 @@ static struct hda_verb alc268_base_init_verbs[] = {
9725 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10009 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9726 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10010 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9727 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10011 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9728 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, 10012
10013 /* set PCBEEP vol = 0, mute connections */
10014 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10015 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10016 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9729 10017
9730 /* Unmute Selector 23h,24h and set the default input to mic-in */ 10018 /* Unmute Selector 23h,24h and set the default input to mic-in */
9731 10019
@@ -9764,29 +10052,17 @@ static struct hda_verb alc268_volume_init_verbs[] = {
9764 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10052 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9765 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10053 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9766 10054
9767 /* set PCBEEP vol = 0 */ 10055 /* set PCBEEP vol = 0, mute connections */
9768 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))}, 10056 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10057 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10058 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9769 10059
9770 { } 10060 { }
9771}; 10061};
9772 10062
9773#define alc268_mux_enum_info alc_mux_enum_info 10063#define alc268_mux_enum_info alc_mux_enum_info
9774#define alc268_mux_enum_get alc_mux_enum_get 10064#define alc268_mux_enum_get alc_mux_enum_get
9775 10065#define alc268_mux_enum_put alc_mux_enum_put
9776static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
9777 struct snd_ctl_elem_value *ucontrol)
9778{
9779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9780 struct alc_spec *spec = codec->spec;
9781
9782 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
9783 static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
9784 hda_nid_t nid = capture_mixers[adc_idx];
9785
9786 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
9787 nid,
9788 &spec->cur_mux[adc_idx]);
9789}
9790 10066
9791static struct snd_kcontrol_new alc268_capture_alt_mixer[] = { 10067static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
9792 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT), 10068 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
@@ -9836,13 +10112,17 @@ static struct hda_input_mux alc268_capture_source = {
9836 }, 10112 },
9837}; 10113};
9838 10114
10115static struct hda_input_mux alc268_acer_capture_source = {
10116 .num_items = 3,
10117 .items = {
10118 { "Mic", 0x0 },
10119 { "Internal Mic", 0x6 },
10120 { "Line", 0x2 },
10121 },
10122};
10123
9839#ifdef CONFIG_SND_DEBUG 10124#ifdef CONFIG_SND_DEBUG
9840static struct snd_kcontrol_new alc268_test_mixer[] = { 10125static struct snd_kcontrol_new alc268_test_mixer[] = {
9841 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9842 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9843 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9844 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9845
9846 /* Volume widgets */ 10126 /* Volume widgets */
9847 HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT), 10127 HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9848 HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT), 10128 HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
@@ -9981,6 +10261,10 @@ static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
9981 case 0x1c: 10261 case 0x1c:
9982 idx1 = 3; /* CD */ 10262 idx1 = 3; /* CD */
9983 break; 10263 break;
10264 case 0x12:
10265 case 0x13:
10266 idx1 = 6; /* digital mics */
10267 break;
9984 default: 10268 default:
9985 continue; 10269 continue;
9986 } 10270 }
@@ -10073,6 +10357,9 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
10073 if (spec->kctl_alloc) 10357 if (spec->kctl_alloc)
10074 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 10358 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10075 10359
10360 if (spec->autocfg.speaker_pins[0] != 0x1d)
10361 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10362
10076 spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs; 10363 spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10077 spec->num_mux_defs = 1; 10364 spec->num_mux_defs = 1;
10078 spec->input_mux = &spec->private_imux; 10365 spec->input_mux = &spec->private_imux;
@@ -10091,20 +10378,25 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
10091/* init callback for auto-configuration model -- overriding the default init */ 10378/* init callback for auto-configuration model -- overriding the default init */
10092static void alc268_auto_init(struct hda_codec *codec) 10379static void alc268_auto_init(struct hda_codec *codec)
10093{ 10380{
10381 struct alc_spec *spec = codec->spec;
10094 alc268_auto_init_multi_out(codec); 10382 alc268_auto_init_multi_out(codec);
10095 alc268_auto_init_hp_out(codec); 10383 alc268_auto_init_hp_out(codec);
10096 alc268_auto_init_mono_speaker_out(codec); 10384 alc268_auto_init_mono_speaker_out(codec);
10097 alc268_auto_init_analog_input(codec); 10385 alc268_auto_init_analog_input(codec);
10386 if (spec->unsol_event)
10387 alc_sku_automute(codec);
10098} 10388}
10099 10389
10100/* 10390/*
10101 * configuration and preset 10391 * configuration and preset
10102 */ 10392 */
10103static const char *alc268_models[ALC268_MODEL_LAST] = { 10393static const char *alc268_models[ALC268_MODEL_LAST] = {
10394 [ALC267_QUANTA_IL1] = "quanta-il1",
10104 [ALC268_3ST] = "3stack", 10395 [ALC268_3ST] = "3stack",
10105 [ALC268_TOSHIBA] = "toshiba", 10396 [ALC268_TOSHIBA] = "toshiba",
10106 [ALC268_ACER] = "acer", 10397 [ALC268_ACER] = "acer",
10107 [ALC268_DELL] = "dell", 10398 [ALC268_DELL] = "dell",
10399 [ALC268_ZEPTO] = "zepto",
10108#ifdef CONFIG_SND_DEBUG 10400#ifdef CONFIG_SND_DEBUG
10109 [ALC268_TEST] = "test", 10401 [ALC268_TEST] = "test",
10110#endif 10402#endif
@@ -10112,6 +10404,7 @@ static const char *alc268_models[ALC268_MODEL_LAST] = {
10112}; 10404};
10113 10405
10114static struct snd_pci_quirk alc268_cfg_tbl[] = { 10406static struct snd_pci_quirk alc268_cfg_tbl[] = {
10407 SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
10115 SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER), 10408 SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10116 SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER), 10409 SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10117 SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER), 10410 SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
@@ -10122,17 +10415,36 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
10122 SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA), 10415 SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10123 SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA), 10416 SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10124 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER), 10417 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10418 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
10419 SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10125 {} 10420 {}
10126}; 10421};
10127 10422
10128static struct alc_config_preset alc268_presets[] = { 10423static struct alc_config_preset alc268_presets[] = {
10424 [ALC267_QUANTA_IL1] = {
10425 .mixers = { alc267_quanta_il1_mixer },
10426 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10427 alc267_quanta_il1_verbs },
10428 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10429 .dac_nids = alc268_dac_nids,
10430 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10431 .adc_nids = alc268_adc_nids_alt,
10432 .hp_nid = 0x03,
10433 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10434 .channel_mode = alc268_modes,
10435 .input_mux = &alc268_capture_source,
10436 .unsol_event = alc267_quanta_il1_unsol_event,
10437 .init_hook = alc267_quanta_il1_automute,
10438 },
10129 [ALC268_3ST] = { 10439 [ALC268_3ST] = {
10130 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer }, 10440 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10441 alc268_beep_mixer },
10131 .init_verbs = { alc268_base_init_verbs }, 10442 .init_verbs = { alc268_base_init_verbs },
10132 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10443 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10133 .dac_nids = alc268_dac_nids, 10444 .dac_nids = alc268_dac_nids,
10134 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10445 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10135 .adc_nids = alc268_adc_nids_alt, 10446 .adc_nids = alc268_adc_nids_alt,
10447 .capsrc_nids = alc268_capsrc_nids,
10136 .hp_nid = 0x03, 10448 .hp_nid = 0x03,
10137 .dig_out_nid = ALC268_DIGOUT_NID, 10449 .dig_out_nid = ALC268_DIGOUT_NID,
10138 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10450 .num_channel_mode = ARRAY_SIZE(alc268_modes),
@@ -10140,13 +10452,15 @@ static struct alc_config_preset alc268_presets[] = {
10140 .input_mux = &alc268_capture_source, 10452 .input_mux = &alc268_capture_source,
10141 }, 10453 },
10142 [ALC268_TOSHIBA] = { 10454 [ALC268_TOSHIBA] = {
10143 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer }, 10455 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10456 alc268_beep_mixer },
10144 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 10457 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10145 alc268_toshiba_verbs }, 10458 alc268_toshiba_verbs },
10146 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10459 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10147 .dac_nids = alc268_dac_nids, 10460 .dac_nids = alc268_dac_nids,
10148 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10461 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10149 .adc_nids = alc268_adc_nids_alt, 10462 .adc_nids = alc268_adc_nids_alt,
10463 .capsrc_nids = alc268_capsrc_nids,
10150 .hp_nid = 0x03, 10464 .hp_nid = 0x03,
10151 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10465 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10152 .channel_mode = alc268_modes, 10466 .channel_mode = alc268_modes,
@@ -10155,22 +10469,24 @@ static struct alc_config_preset alc268_presets[] = {
10155 .init_hook = alc268_toshiba_automute, 10469 .init_hook = alc268_toshiba_automute,
10156 }, 10470 },
10157 [ALC268_ACER] = { 10471 [ALC268_ACER] = {
10158 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer }, 10472 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10473 alc268_beep_mixer },
10159 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 10474 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10160 alc268_acer_verbs }, 10475 alc268_acer_verbs },
10161 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10476 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10162 .dac_nids = alc268_dac_nids, 10477 .dac_nids = alc268_dac_nids,
10163 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10478 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10164 .adc_nids = alc268_adc_nids_alt, 10479 .adc_nids = alc268_adc_nids_alt,
10480 .capsrc_nids = alc268_capsrc_nids,
10165 .hp_nid = 0x02, 10481 .hp_nid = 0x02,
10166 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10482 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10167 .channel_mode = alc268_modes, 10483 .channel_mode = alc268_modes,
10168 .input_mux = &alc268_capture_source, 10484 .input_mux = &alc268_acer_capture_source,
10169 .unsol_event = alc268_acer_unsol_event, 10485 .unsol_event = alc268_acer_unsol_event,
10170 .init_hook = alc268_acer_init_hook, 10486 .init_hook = alc268_acer_init_hook,
10171 }, 10487 },
10172 [ALC268_DELL] = { 10488 [ALC268_DELL] = {
10173 .mixers = { alc268_dell_mixer }, 10489 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10174 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 10490 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10175 alc268_dell_verbs }, 10491 alc268_dell_verbs },
10176 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10492 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -10182,6 +10498,24 @@ static struct alc_config_preset alc268_presets[] = {
10182 .init_hook = alc268_dell_init_hook, 10498 .init_hook = alc268_dell_init_hook,
10183 .input_mux = &alc268_capture_source, 10499 .input_mux = &alc268_capture_source,
10184 }, 10500 },
10501 [ALC268_ZEPTO] = {
10502 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10503 alc268_beep_mixer },
10504 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10505 alc268_toshiba_verbs },
10506 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10507 .dac_nids = alc268_dac_nids,
10508 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10509 .adc_nids = alc268_adc_nids_alt,
10510 .capsrc_nids = alc268_capsrc_nids,
10511 .hp_nid = 0x03,
10512 .dig_out_nid = ALC268_DIGOUT_NID,
10513 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10514 .channel_mode = alc268_modes,
10515 .input_mux = &alc268_capture_source,
10516 .unsol_event = alc268_toshiba_unsol_event,
10517 .init_hook = alc268_toshiba_automute
10518 },
10185#ifdef CONFIG_SND_DEBUG 10519#ifdef CONFIG_SND_DEBUG
10186 [ALC268_TEST] = { 10520 [ALC268_TEST] = {
10187 .mixers = { alc268_test_mixer, alc268_capture_mixer }, 10521 .mixers = { alc268_test_mixer, alc268_capture_mixer },
@@ -10191,6 +10525,7 @@ static struct alc_config_preset alc268_presets[] = {
10191 .dac_nids = alc268_dac_nids, 10525 .dac_nids = alc268_dac_nids,
10192 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10526 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10193 .adc_nids = alc268_adc_nids_alt, 10527 .adc_nids = alc268_adc_nids_alt,
10528 .capsrc_nids = alc268_capsrc_nids,
10194 .hp_nid = 0x03, 10529 .hp_nid = 0x03,
10195 .dig_out_nid = ALC268_DIGOUT_NID, 10530 .dig_out_nid = ALC268_DIGOUT_NID,
10196 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10531 .num_channel_mode = ARRAY_SIZE(alc268_modes),
@@ -10247,13 +10582,22 @@ static int patch_alc268(struct hda_codec *codec)
10247 spec->stream_name_digital = "ALC268 Digital"; 10582 spec->stream_name_digital = "ALC268 Digital";
10248 spec->stream_digital_playback = &alc268_pcm_digital_playback; 10583 spec->stream_digital_playback = &alc268_pcm_digital_playback;
10249 10584
10585 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
10586 /* override the amp caps for beep generator */
10587 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
10588 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
10589 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
10590 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
10591 (0 << AC_AMPCAP_MUTE_SHIFT));
10592
10250 if (!spec->adc_nids && spec->input_mux) { 10593 if (!spec->adc_nids && spec->input_mux) {
10251 /* check whether NID 0x07 is valid */ 10594 /* check whether NID 0x07 is valid */
10252 unsigned int wcap = get_wcaps(codec, 0x07); 10595 unsigned int wcap = get_wcaps(codec, 0x07);
10596 int i;
10253 10597
10254 /* get type */ 10598 /* get type */
10255 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 10599 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10256 if (wcap != AC_WID_AUD_IN) { 10600 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
10257 spec->adc_nids = alc268_adc_nids_alt; 10601 spec->adc_nids = alc268_adc_nids_alt;
10258 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt); 10602 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
10259 spec->mixers[spec->num_mixers] = 10603 spec->mixers[spec->num_mixers] =
@@ -10266,6 +10610,12 @@ static int patch_alc268(struct hda_codec *codec)
10266 alc268_capture_mixer; 10610 alc268_capture_mixer;
10267 spec->num_mixers++; 10611 spec->num_mixers++;
10268 } 10612 }
10613 spec->capsrc_nids = alc268_capsrc_nids;
10614 /* set default input source */
10615 for (i = 0; i < spec->num_adc_nids; i++)
10616 snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
10617 0, AC_VERB_SET_CONNECT_SEL,
10618 spec->input_mux->items[0].index);
10269 } 10619 }
10270 10620
10271 spec->vmaster_nid = 0x02; 10621 spec->vmaster_nid = 0x02;
@@ -10539,9 +10889,12 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
10539/* init callback for auto-configuration model -- overriding the default init */ 10889/* init callback for auto-configuration model -- overriding the default init */
10540static void alc269_auto_init(struct hda_codec *codec) 10890static void alc269_auto_init(struct hda_codec *codec)
10541{ 10891{
10892 struct alc_spec *spec = codec->spec;
10542 alc269_auto_init_multi_out(codec); 10893 alc269_auto_init_multi_out(codec);
10543 alc269_auto_init_hp_out(codec); 10894 alc269_auto_init_hp_out(codec);
10544 alc269_auto_init_analog_input(codec); 10895 alc269_auto_init_analog_input(codec);
10896 if (spec->unsol_event)
10897 alc_sku_automute(codec);
10545} 10898}
10546 10899
10547/* 10900/*
@@ -11463,13 +11816,7 @@ static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
11463 hda_nid_t nid, 11816 hda_nid_t nid,
11464 int pin_type, int dac_idx) 11817 int pin_type, int dac_idx)
11465{ 11818{
11466 /* set as output */ 11819 alc_set_pin_output(codec, nid, pin_type);
11467
11468 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11469 pin_type);
11470 snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11471 AMP_OUT_UNMUTE);
11472
11473} 11820}
11474 11821
11475static void alc861_auto_init_multi_out(struct hda_codec *codec) 11822static void alc861_auto_init_multi_out(struct hda_codec *codec)
@@ -11496,6 +11843,9 @@ static void alc861_auto_init_hp_out(struct hda_codec *codec)
11496 if (pin) /* connect to front */ 11843 if (pin) /* connect to front */
11497 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP, 11844 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
11498 spec->multiout.dac_nids[0]); 11845 spec->multiout.dac_nids[0]);
11846 pin = spec->autocfg.speaker_pins[0];
11847 if (pin)
11848 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
11499} 11849}
11500 11850
11501static void alc861_auto_init_analog_input(struct hda_codec *codec) 11851static void alc861_auto_init_analog_input(struct hda_codec *codec)
@@ -11568,9 +11918,12 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
11568/* additional initialization for auto-configuration model */ 11918/* additional initialization for auto-configuration model */
11569static void alc861_auto_init(struct hda_codec *codec) 11919static void alc861_auto_init(struct hda_codec *codec)
11570{ 11920{
11921 struct alc_spec *spec = codec->spec;
11571 alc861_auto_init_multi_out(codec); 11922 alc861_auto_init_multi_out(codec);
11572 alc861_auto_init_hp_out(codec); 11923 alc861_auto_init_hp_out(codec);
11573 alc861_auto_init_analog_input(codec); 11924 alc861_auto_init_analog_input(codec);
11925 if (spec->unsol_event)
11926 alc_sku_automute(codec);
11574} 11927}
11575 11928
11576#ifdef CONFIG_SND_HDA_POWER_SAVE 11929#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -11822,6 +12175,8 @@ static hda_nid_t alc861vd_adc_nids[1] = {
11822 0x09, 12175 0x09,
11823}; 12176};
11824 12177
12178static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12179
11825/* input MUX */ 12180/* input MUX */
11826/* FIXME: should be a matrix-type input source selection */ 12181/* FIXME: should be a matrix-type input source selection */
11827static struct hda_input_mux alc861vd_capture_source = { 12182static struct hda_input_mux alc861vd_capture_source = {
@@ -11835,11 +12190,10 @@ static struct hda_input_mux alc861vd_capture_source = {
11835}; 12190};
11836 12191
11837static struct hda_input_mux alc861vd_dallas_capture_source = { 12192static struct hda_input_mux alc861vd_dallas_capture_source = {
11838 .num_items = 3, 12193 .num_items = 2,
11839 .items = { 12194 .items = {
11840 { "Front Mic", 0x0 }, 12195 { "Ext Mic", 0x0 },
11841 { "ATAPI Mic", 0x1 }, 12196 { "Int Mic", 0x1 },
11842 { "Line In", 0x5 },
11843 }, 12197 },
11844}; 12198};
11845 12199
@@ -11853,33 +12207,8 @@ static struct hda_input_mux alc861vd_hp_capture_source = {
11853 12207
11854#define alc861vd_mux_enum_info alc_mux_enum_info 12208#define alc861vd_mux_enum_info alc_mux_enum_info
11855#define alc861vd_mux_enum_get alc_mux_enum_get 12209#define alc861vd_mux_enum_get alc_mux_enum_get
11856 12210/* ALC861VD has the ALC882-type input selection (but has only one ADC) */
11857static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol, 12211#define alc861vd_mux_enum_put alc882_mux_enum_put
11858 struct snd_ctl_elem_value *ucontrol)
11859{
11860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11861 struct alc_spec *spec = codec->spec;
11862 const struct hda_input_mux *imux = spec->input_mux;
11863 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
11864 static hda_nid_t capture_mixers[1] = { 0x22 };
11865 hda_nid_t nid = capture_mixers[adc_idx];
11866 unsigned int *cur_val = &spec->cur_mux[adc_idx];
11867 unsigned int i, idx;
11868
11869 idx = ucontrol->value.enumerated.item[0];
11870 if (idx >= imux->num_items)
11871 idx = imux->num_items - 1;
11872 if (*cur_val == idx)
11873 return 0;
11874 for (i = 0; i < imux->num_items; i++) {
11875 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
11876 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
11877 imux->items[i].index,
11878 HDA_AMP_MUTE, v);
11879 }
11880 *cur_val = idx;
11881 return 1;
11882}
11883 12212
11884/* 12213/*
11885 * 2ch mode 12214 * 2ch mode
@@ -12034,20 +12363,22 @@ static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
12034 { } /* end */ 12363 { } /* end */
12035}; 12364};
12036 12365
12037/* Pin assignment: Front=0x14, HP = 0x15, 12366/* Pin assignment: Speaker=0x14, HP = 0x15,
12038 * Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d 12367 * Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
12039 */ 12368 */
12040static struct snd_kcontrol_new alc861vd_dallas_mixer[] = { 12369static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
12041 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT), 12370 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12042 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 12371 HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
12043 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT), 12372 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12044 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT), 12373 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12045 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 12374 HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12046 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 12375 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12047 HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 12376 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12048 HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 12377 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12049 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT), 12378 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12050 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT), 12379 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12380 HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
12381 HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
12051 { } /* end */ 12382 { } /* end */
12052}; 12383};
12053 12384
@@ -12348,6 +12679,7 @@ static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
12348 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/ 12679 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
12349 SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS), 12680 SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
12350 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO), 12681 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
12682 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
12351 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG), 12683 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
12352 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO), 12684 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
12353 SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO), 12685 SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
@@ -12362,8 +12694,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12362 alc861vd_3stack_init_verbs }, 12694 alc861vd_3stack_init_verbs },
12363 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids), 12695 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12364 .dac_nids = alc660vd_dac_nids, 12696 .dac_nids = alc660vd_dac_nids,
12365 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12366 .adc_nids = alc861vd_adc_nids,
12367 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12697 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12368 .channel_mode = alc861vd_3stack_2ch_modes, 12698 .channel_mode = alc861vd_3stack_2ch_modes,
12369 .input_mux = &alc861vd_capture_source, 12699 .input_mux = &alc861vd_capture_source,
@@ -12375,8 +12705,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12375 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids), 12705 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12376 .dac_nids = alc660vd_dac_nids, 12706 .dac_nids = alc660vd_dac_nids,
12377 .dig_out_nid = ALC861VD_DIGOUT_NID, 12707 .dig_out_nid = ALC861VD_DIGOUT_NID,
12378 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12379 .adc_nids = alc861vd_adc_nids,
12380 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12708 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12381 .channel_mode = alc861vd_3stack_2ch_modes, 12709 .channel_mode = alc861vd_3stack_2ch_modes,
12382 .input_mux = &alc861vd_capture_source, 12710 .input_mux = &alc861vd_capture_source,
@@ -12421,8 +12749,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12421 alc861vd_lenovo_unsol_verbs }, 12749 alc861vd_lenovo_unsol_verbs },
12422 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids), 12750 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12423 .dac_nids = alc660vd_dac_nids, 12751 .dac_nids = alc660vd_dac_nids,
12424 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12425 .adc_nids = alc861vd_adc_nids,
12426 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12752 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12427 .channel_mode = alc861vd_3stack_2ch_modes, 12753 .channel_mode = alc861vd_3stack_2ch_modes,
12428 .input_mux = &alc861vd_capture_source, 12754 .input_mux = &alc861vd_capture_source,
@@ -12434,8 +12760,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12434 .init_verbs = { alc861vd_dallas_verbs }, 12760 .init_verbs = { alc861vd_dallas_verbs },
12435 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids), 12761 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12436 .dac_nids = alc861vd_dac_nids, 12762 .dac_nids = alc861vd_dac_nids,
12437 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12438 .adc_nids = alc861vd_adc_nids,
12439 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12763 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12440 .channel_mode = alc861vd_3stack_2ch_modes, 12764 .channel_mode = alc861vd_3stack_2ch_modes,
12441 .input_mux = &alc861vd_dallas_capture_source, 12765 .input_mux = &alc861vd_dallas_capture_source,
@@ -12447,9 +12771,7 @@ static struct alc_config_preset alc861vd_presets[] = {
12447 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs }, 12771 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
12448 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids), 12772 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12449 .dac_nids = alc861vd_dac_nids, 12773 .dac_nids = alc861vd_dac_nids,
12450 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12451 .dig_out_nid = ALC861VD_DIGOUT_NID, 12774 .dig_out_nid = ALC861VD_DIGOUT_NID,
12452 .adc_nids = alc861vd_adc_nids,
12453 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12775 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12454 .channel_mode = alc861vd_3stack_2ch_modes, 12776 .channel_mode = alc861vd_3stack_2ch_modes,
12455 .input_mux = &alc861vd_hp_capture_source, 12777 .input_mux = &alc861vd_hp_capture_source,
@@ -12464,11 +12786,7 @@ static struct alc_config_preset alc861vd_presets[] = {
12464static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec, 12786static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
12465 hda_nid_t nid, int pin_type, int dac_idx) 12787 hda_nid_t nid, int pin_type, int dac_idx)
12466{ 12788{
12467 /* set as output */ 12789 alc_set_pin_output(codec, nid, pin_type);
12468 snd_hda_codec_write(codec, nid, 0,
12469 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
12470 snd_hda_codec_write(codec, nid, 0,
12471 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
12472} 12790}
12473 12791
12474static void alc861vd_auto_init_multi_out(struct hda_codec *codec) 12792static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
@@ -12495,6 +12813,9 @@ static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
12495 pin = spec->autocfg.hp_pins[0]; 12813 pin = spec->autocfg.hp_pins[0];
12496 if (pin) /* connect to front and use dac 0 */ 12814 if (pin) /* connect to front and use dac 0 */
12497 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 12815 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12816 pin = spec->autocfg.speaker_pins[0];
12817 if (pin)
12818 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12498} 12819}
12499 12820
12500#define alc861vd_is_input_pin(nid) alc880_is_input_pin(nid) 12821#define alc861vd_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -12698,9 +13019,12 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
12698/* additional initialization for auto-configuration model */ 13019/* additional initialization for auto-configuration model */
12699static void alc861vd_auto_init(struct hda_codec *codec) 13020static void alc861vd_auto_init(struct hda_codec *codec)
12700{ 13021{
13022 struct alc_spec *spec = codec->spec;
12701 alc861vd_auto_init_multi_out(codec); 13023 alc861vd_auto_init_multi_out(codec);
12702 alc861vd_auto_init_hp_out(codec); 13024 alc861vd_auto_init_hp_out(codec);
12703 alc861vd_auto_init_analog_input(codec); 13025 alc861vd_auto_init_analog_input(codec);
13026 if (spec->unsol_event)
13027 alc_sku_automute(codec);
12704} 13028}
12705 13029
12706static int patch_alc861vd(struct hda_codec *codec) 13030static int patch_alc861vd(struct hda_codec *codec)
@@ -12751,6 +13075,7 @@ static int patch_alc861vd(struct hda_codec *codec)
12751 13075
12752 spec->adc_nids = alc861vd_adc_nids; 13076 spec->adc_nids = alc861vd_adc_nids;
12753 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids); 13077 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
13078 spec->capsrc_nids = alc861vd_capsrc_nids;
12754 13079
12755 spec->mixers[spec->num_mixers] = alc861vd_capture_mixer; 13080 spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
12756 spec->num_mixers++; 13081 spec->num_mixers++;
@@ -12792,9 +13117,11 @@ static hda_nid_t alc662_adc_nids[1] = {
12792 /* ADC1-2 */ 13117 /* ADC1-2 */
12793 0x09, 13118 0x09,
12794}; 13119};
13120
13121static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13122
12795/* input MUX */ 13123/* input MUX */
12796/* FIXME: should be a matrix-type input source selection */ 13124/* FIXME: should be a matrix-type input source selection */
12797
12798static struct hda_input_mux alc662_capture_source = { 13125static struct hda_input_mux alc662_capture_source = {
12799 .num_items = 4, 13126 .num_items = 4,
12800 .items = { 13127 .items = {
@@ -12823,33 +13150,8 @@ static struct hda_input_mux alc662_eeepc_capture_source = {
12823 13150
12824#define alc662_mux_enum_info alc_mux_enum_info 13151#define alc662_mux_enum_info alc_mux_enum_info
12825#define alc662_mux_enum_get alc_mux_enum_get 13152#define alc662_mux_enum_get alc_mux_enum_get
13153#define alc662_mux_enum_put alc882_mux_enum_put
12826 13154
12827static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
12828 struct snd_ctl_elem_value *ucontrol)
12829{
12830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
12831 struct alc_spec *spec = codec->spec;
12832 const struct hda_input_mux *imux = spec->input_mux;
12833 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
12834 static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
12835 hda_nid_t nid = capture_mixers[adc_idx];
12836 unsigned int *cur_val = &spec->cur_mux[adc_idx];
12837 unsigned int i, idx;
12838
12839 idx = ucontrol->value.enumerated.item[0];
12840 if (idx >= imux->num_items)
12841 idx = imux->num_items - 1;
12842 if (*cur_val == idx)
12843 return 0;
12844 for (i = 0; i < imux->num_items; i++) {
12845 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
12846 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
12847 imux->items[i].index,
12848 HDA_AMP_MUTE, v);
12849 }
12850 *cur_val = idx;
12851 return 1;
12852}
12853/* 13155/*
12854 * 2ch mode 13156 * 2ch mode
12855 */ 13157 */
@@ -12918,13 +13220,13 @@ static struct hda_channel_mode alc662_5stack_modes[2] = {
12918static struct snd_kcontrol_new alc662_base_mixer[] = { 13220static struct snd_kcontrol_new alc662_base_mixer[] = {
12919 /* output mixer control */ 13221 /* output mixer control */
12920 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT), 13222 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12921 HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT), 13223 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
12922 HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT), 13224 HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12923 HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT), 13225 HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
12924 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT), 13226 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12925 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT), 13227 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12926 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT), 13228 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
12927 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT), 13229 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
12928 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 13230 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12929 13231
12930 /*Input mixer control */ 13232 /*Input mixer control */
@@ -12941,7 +13243,7 @@ static struct snd_kcontrol_new alc662_base_mixer[] = {
12941 13243
12942static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = { 13244static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
12943 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT), 13245 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12944 HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT), 13246 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
12945 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 13247 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12946 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 13248 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12947 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 13249 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
@@ -12958,13 +13260,13 @@ static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
12958 13260
12959static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = { 13261static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
12960 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT), 13262 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12961 HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT), 13263 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
12962 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT), 13264 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12963 HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT), 13265 HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
12964 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT), 13266 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12965 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT), 13267 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12966 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT), 13268 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
12967 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT), 13269 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
12968 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 13270 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12969 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 13271 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12970 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 13272 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
@@ -13313,6 +13615,7 @@ static const char *alc662_models[ALC662_MODEL_LAST] = {
13313}; 13615};
13314 13616
13315static struct snd_pci_quirk alc662_cfg_tbl[] = { 13617static struct snd_pci_quirk alc662_cfg_tbl[] = {
13618 SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
13316 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701), 13619 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
13317 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20), 13620 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
13318 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E), 13621 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
@@ -13326,8 +13629,6 @@ static struct alc_config_preset alc662_presets[] = {
13326 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13629 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13327 .dac_nids = alc662_dac_nids, 13630 .dac_nids = alc662_dac_nids,
13328 .dig_out_nid = ALC662_DIGOUT_NID, 13631 .dig_out_nid = ALC662_DIGOUT_NID,
13329 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13330 .adc_nids = alc662_adc_nids,
13331 .dig_in_nid = ALC662_DIGIN_NID, 13632 .dig_in_nid = ALC662_DIGIN_NID,
13332 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 13633 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13333 .channel_mode = alc662_3ST_2ch_modes, 13634 .channel_mode = alc662_3ST_2ch_modes,
@@ -13340,8 +13641,6 @@ static struct alc_config_preset alc662_presets[] = {
13340 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13641 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13341 .dac_nids = alc662_dac_nids, 13642 .dac_nids = alc662_dac_nids,
13342 .dig_out_nid = ALC662_DIGOUT_NID, 13643 .dig_out_nid = ALC662_DIGOUT_NID,
13343 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13344 .adc_nids = alc662_adc_nids,
13345 .dig_in_nid = ALC662_DIGIN_NID, 13644 .dig_in_nid = ALC662_DIGIN_NID,
13346 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes), 13645 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13347 .channel_mode = alc662_3ST_6ch_modes, 13646 .channel_mode = alc662_3ST_6ch_modes,
@@ -13354,8 +13653,6 @@ static struct alc_config_preset alc662_presets[] = {
13354 .init_verbs = { alc662_init_verbs }, 13653 .init_verbs = { alc662_init_verbs },
13355 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13654 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13356 .dac_nids = alc662_dac_nids, 13655 .dac_nids = alc662_dac_nids,
13357 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13358 .adc_nids = alc662_adc_nids,
13359 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes), 13656 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13360 .channel_mode = alc662_3ST_6ch_modes, 13657 .channel_mode = alc662_3ST_6ch_modes,
13361 .need_dac_fix = 1, 13658 .need_dac_fix = 1,
@@ -13368,8 +13665,6 @@ static struct alc_config_preset alc662_presets[] = {
13368 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13665 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13369 .dac_nids = alc662_dac_nids, 13666 .dac_nids = alc662_dac_nids,
13370 .dig_out_nid = ALC662_DIGOUT_NID, 13667 .dig_out_nid = ALC662_DIGOUT_NID,
13371 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13372 .adc_nids = alc662_adc_nids,
13373 .dig_in_nid = ALC662_DIGIN_NID, 13668 .dig_in_nid = ALC662_DIGIN_NID,
13374 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes), 13669 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
13375 .channel_mode = alc662_5stack_modes, 13670 .channel_mode = alc662_5stack_modes,
@@ -13380,8 +13675,6 @@ static struct alc_config_preset alc662_presets[] = {
13380 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs }, 13675 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
13381 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13676 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13382 .dac_nids = alc662_dac_nids, 13677 .dac_nids = alc662_dac_nids,
13383 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13384 .adc_nids = alc662_adc_nids,
13385 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 13678 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13386 .channel_mode = alc662_3ST_2ch_modes, 13679 .channel_mode = alc662_3ST_2ch_modes,
13387 .input_mux = &alc662_lenovo_101e_capture_source, 13680 .input_mux = &alc662_lenovo_101e_capture_source,
@@ -13394,8 +13687,6 @@ static struct alc_config_preset alc662_presets[] = {
13394 alc662_eeepc_sue_init_verbs }, 13687 alc662_eeepc_sue_init_verbs },
13395 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13688 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13396 .dac_nids = alc662_dac_nids, 13689 .dac_nids = alc662_dac_nids,
13397 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
13398 .adc_nids = alc662_adc_nids,
13399 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 13690 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13400 .channel_mode = alc662_3ST_2ch_modes, 13691 .channel_mode = alc662_3ST_2ch_modes,
13401 .input_mux = &alc662_eeepc_capture_source, 13692 .input_mux = &alc662_eeepc_capture_source,
@@ -13409,8 +13700,6 @@ static struct alc_config_preset alc662_presets[] = {
13409 alc662_eeepc_ep20_sue_init_verbs }, 13700 alc662_eeepc_ep20_sue_init_verbs },
13410 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13701 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13411 .dac_nids = alc662_dac_nids, 13702 .dac_nids = alc662_dac_nids,
13412 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13413 .adc_nids = alc662_adc_nids,
13414 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes), 13703 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13415 .channel_mode = alc662_3ST_6ch_modes, 13704 .channel_mode = alc662_3ST_6ch_modes,
13416 .input_mux = &alc662_lenovo_101e_capture_source, 13705 .input_mux = &alc662_lenovo_101e_capture_source,
@@ -13556,11 +13845,7 @@ static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
13556 hda_nid_t nid, int pin_type, 13845 hda_nid_t nid, int pin_type,
13557 int dac_idx) 13846 int dac_idx)
13558{ 13847{
13559 /* set as output */ 13848 alc_set_pin_output(codec, nid, pin_type);
13560 snd_hda_codec_write(codec, nid, 0,
13561 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
13562 snd_hda_codec_write(codec, nid, 0,
13563 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
13564 /* need the manual connection? */ 13849 /* need the manual connection? */
13565 if (alc880_is_multi_pin(nid)) { 13850 if (alc880_is_multi_pin(nid)) {
13566 struct alc_spec *spec = codec->spec; 13851 struct alc_spec *spec = codec->spec;
@@ -13595,6 +13880,9 @@ static void alc662_auto_init_hp_out(struct hda_codec *codec)
13595 if (pin) /* connect to front */ 13880 if (pin) /* connect to front */
13596 /* use dac 0 */ 13881 /* use dac 0 */
13597 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 13882 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13883 pin = spec->autocfg.speaker_pins[0];
13884 if (pin)
13885 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13598} 13886}
13599 13887
13600#define alc662_is_input_pin(nid) alc880_is_input_pin(nid) 13888#define alc662_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -13672,9 +13960,12 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
13672/* additional initialization for auto-configuration model */ 13960/* additional initialization for auto-configuration model */
13673static void alc662_auto_init(struct hda_codec *codec) 13961static void alc662_auto_init(struct hda_codec *codec)
13674{ 13962{
13963 struct alc_spec *spec = codec->spec;
13675 alc662_auto_init_multi_out(codec); 13964 alc662_auto_init_multi_out(codec);
13676 alc662_auto_init_hp_out(codec); 13965 alc662_auto_init_hp_out(codec);
13677 alc662_auto_init_analog_input(codec); 13966 alc662_auto_init_analog_input(codec);
13967 if (spec->unsol_event)
13968 alc_sku_automute(codec);
13678} 13969}
13679 13970
13680static int patch_alc662(struct hda_codec *codec) 13971static int patch_alc662(struct hda_codec *codec)
@@ -13722,10 +14013,9 @@ static int patch_alc662(struct hda_codec *codec)
13722 spec->stream_digital_playback = &alc662_pcm_digital_playback; 14013 spec->stream_digital_playback = &alc662_pcm_digital_playback;
13723 spec->stream_digital_capture = &alc662_pcm_digital_capture; 14014 spec->stream_digital_capture = &alc662_pcm_digital_capture;
13724 14015
13725 if (!spec->adc_nids && spec->input_mux) { 14016 spec->adc_nids = alc662_adc_nids;
13726 spec->adc_nids = alc662_adc_nids; 14017 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
13727 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids); 14018 spec->capsrc_nids = alc662_capsrc_nids;
13728 }
13729 14019
13730 spec->vmaster_nid = 0x02; 14020 spec->vmaster_nid = 0x02;
13731 14021
@@ -13761,6 +14051,8 @@ struct hda_codec_preset snd_hda_preset_realtek[] = {
13761 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, 14051 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
13762 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, 14052 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
13763 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 }, 14053 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
14054 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
14055 .patch = patch_alc882 }, /* should be patch_alc883() in future */
13764 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, 14056 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
13765 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 }, 14057 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
13766 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 }, 14058 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c
index d22f5a6b850f..9332b63e406c 100644
--- a/sound/pci/hda/patch_si3054.c
+++ b/sound/pci/hda/patch_si3054.c
@@ -28,7 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31 31#include "hda_patch.h"
32 32
33/* si3054 verbs */ 33/* si3054 verbs */
34#define SI3054_VERB_READ_NODE 0x900 34#define SI3054_VERB_READ_NODE 0x900
@@ -206,7 +206,7 @@ static int si3054_build_pcms(struct hda_codec *codec)
206 info->name = "Si3054 Modem"; 206 info->name = "Si3054 Modem";
207 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm; 207 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm;
208 info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm; 208 info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm;
209 info->is_modem = 1; 209 info->pcm_type = HDA_PCM_TYPE_MODEM;
210 return 0; 210 return 0;
211} 211}
212 212
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index caf48edaa921..b3a15d616873 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -32,6 +32,7 @@
32#include <sound/asoundef.h> 32#include <sound/asoundef.h>
33#include "hda_codec.h" 33#include "hda_codec.h"
34#include "hda_local.h" 34#include "hda_local.h"
35#include "hda_patch.h"
35 36
36#define NUM_CONTROL_ALLOC 32 37#define NUM_CONTROL_ALLOC 32
37#define STAC_PWR_EVENT 0x20 38#define STAC_PWR_EVENT 0x20
@@ -39,6 +40,7 @@
39 40
40enum { 41enum {
41 STAC_REF, 42 STAC_REF,
43 STAC_9200_OQO,
42 STAC_9200_DELL_D21, 44 STAC_9200_DELL_D21,
43 STAC_9200_DELL_D22, 45 STAC_9200_DELL_D22,
44 STAC_9200_DELL_D23, 46 STAC_9200_DELL_D23,
@@ -50,6 +52,7 @@ enum {
50 STAC_9200_DELL_M26, 52 STAC_9200_DELL_M26,
51 STAC_9200_DELL_M27, 53 STAC_9200_DELL_M27,
52 STAC_9200_GATEWAY, 54 STAC_9200_GATEWAY,
55 STAC_9200_PANASONIC,
53 STAC_9200_MODELS 56 STAC_9200_MODELS
54}; 57};
55 58
@@ -63,11 +66,14 @@ enum {
63 66
64enum { 67enum {
65 STAC_92HD73XX_REF, 68 STAC_92HD73XX_REF,
69 STAC_DELL_M6,
66 STAC_92HD73XX_MODELS 70 STAC_92HD73XX_MODELS
67}; 71};
68 72
69enum { 73enum {
70 STAC_92HD71BXX_REF, 74 STAC_92HD71BXX_REF,
75 STAC_DELL_M4_1,
76 STAC_DELL_M4_2,
71 STAC_92HD71BXX_MODELS 77 STAC_92HD71BXX_MODELS
72}; 78};
73 79
@@ -123,6 +129,7 @@ struct sigmatel_spec {
123 unsigned int hp_detect: 1; 129 unsigned int hp_detect: 1;
124 130
125 /* gpio lines */ 131 /* gpio lines */
132 unsigned int eapd_mask;
126 unsigned int gpio_mask; 133 unsigned int gpio_mask;
127 unsigned int gpio_dir; 134 unsigned int gpio_dir;
128 unsigned int gpio_data; 135 unsigned int gpio_data;
@@ -135,6 +142,7 @@ struct sigmatel_spec {
135 /* power management */ 142 /* power management */
136 unsigned int num_pwrs; 143 unsigned int num_pwrs;
137 hda_nid_t *pwr_nids; 144 hda_nid_t *pwr_nids;
145 hda_nid_t *dac_list;
138 146
139 /* playback */ 147 /* playback */
140 struct hda_input_mux *mono_mux; 148 struct hda_input_mux *mono_mux;
@@ -173,6 +181,7 @@ struct sigmatel_spec {
173 /* i/o switches */ 181 /* i/o switches */
174 unsigned int io_switch[2]; 182 unsigned int io_switch[2];
175 unsigned int clfe_swap; 183 unsigned int clfe_swap;
184 unsigned int hp_switch;
176 unsigned int aloopback; 185 unsigned int aloopback;
177 186
178 struct hda_pcm pcm_rec[2]; /* PCM information */ 187 struct hda_pcm pcm_rec[2]; /* PCM information */
@@ -184,9 +193,6 @@ struct sigmatel_spec {
184 struct hda_input_mux private_dimux; 193 struct hda_input_mux private_dimux;
185 struct hda_input_mux private_imux; 194 struct hda_input_mux private_imux;
186 struct hda_input_mux private_mono_mux; 195 struct hda_input_mux private_mono_mux;
187
188 /* virtual master */
189 unsigned int vmaster_tlv[4];
190}; 196};
191 197
192static hda_nid_t stac9200_adc_nids[1] = { 198static hda_nid_t stac9200_adc_nids[1] = {
@@ -244,7 +250,7 @@ static hda_nid_t stac92hd71bxx_dmux_nids[1] = {
244 0x1c, 250 0x1c,
245}; 251};
246 252
247static hda_nid_t stac92hd71bxx_dac_nids[2] = { 253static hda_nid_t stac92hd71bxx_dac_nids[1] = {
248 0x10, /*0x11, */ 254 0x10, /*0x11, */
249}; 255};
250 256
@@ -290,6 +296,10 @@ static hda_nid_t stac927x_mux_nids[3] = {
290 0x15, 0x16, 0x17 296 0x15, 0x16, 0x17
291}; 297};
292 298
299static hda_nid_t stac927x_dac_nids[6] = {
300 0x02, 0x03, 0x04, 0x05, 0x06, 0
301};
302
293static hda_nid_t stac927x_dmux_nids[1] = { 303static hda_nid_t stac927x_dmux_nids[1] = {
294 0x1b, 304 0x1b,
295}; 305};
@@ -331,10 +341,10 @@ static hda_nid_t stac922x_pin_nids[10] = {
331 0x0f, 0x10, 0x11, 0x15, 0x1b, 341 0x0f, 0x10, 0x11, 0x15, 0x1b,
332}; 342};
333 343
334static hda_nid_t stac92hd73xx_pin_nids[12] = { 344static hda_nid_t stac92hd73xx_pin_nids[13] = {
335 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 345 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
336 0x0f, 0x10, 0x11, 0x12, 0x13, 346 0x0f, 0x10, 0x11, 0x12, 0x13,
337 0x14, 0x22 347 0x14, 0x1e, 0x22
338}; 348};
339 349
340static hda_nid_t stac92hd71bxx_pin_nids[10] = { 350static hda_nid_t stac92hd71bxx_pin_nids[10] = {
@@ -527,6 +537,43 @@ static struct hda_verb stac92hd73xx_6ch_core_init[] = {
527 {} 537 {}
528}; 538};
529 539
540static struct hda_verb dell_eq_core_init[] = {
541 /* set master volume to max value without distortion
542 * and direct control */
543 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
544 /* setup audio connections */
545 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
546 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
547 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
548 /* setup adcs to point to mixer */
549 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
550 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
551 /* setup import muxs */
552 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
553 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
554 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
555 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
556 {}
557};
558
559static struct hda_verb dell_m6_core_init[] = {
560 /* set master volume and direct control */
561 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
562 /* setup audio connections */
563 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
564 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
565 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
566 /* setup adcs to point to mixer */
567 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
568 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
569 /* setup import muxs */
570 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
571 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
572 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
573 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
574 {}
575};
576
530static struct hda_verb stac92hd73xx_8ch_core_init[] = { 577static struct hda_verb stac92hd73xx_8ch_core_init[] = {
531 /* set master volume and direct control */ 578 /* set master volume and direct control */
532 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 579 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
@@ -910,6 +957,11 @@ static int stac92xx_build_controls(struct hda_codec *codec)
910 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 957 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
911 if (err < 0) 958 if (err < 0)
912 return err; 959 return err;
960 err = snd_hda_create_spdif_share_sw(codec,
961 &spec->multiout);
962 if (err < 0)
963 return err;
964 spec->multiout.share_spdif = 1;
913 } 965 }
914 if (spec->dig_in_nid) { 966 if (spec->dig_in_nid) {
915 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 967 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -919,10 +971,11 @@ static int stac92xx_build_controls(struct hda_codec *codec)
919 971
920 /* if we have no master control, let's create it */ 972 /* if we have no master control, let's create it */
921 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 973 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
974 unsigned int vmaster_tlv[4];
922 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0], 975 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
923 HDA_OUTPUT, spec->vmaster_tlv); 976 HDA_OUTPUT, vmaster_tlv);
924 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 977 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
925 spec->vmaster_tlv, slave_vols); 978 vmaster_tlv, slave_vols);
926 if (err < 0) 979 if (err < 0)
927 return err; 980 return err;
928 } 981 }
@@ -1052,9 +1105,15 @@ static unsigned int dell9200_m27_pin_configs[8] = {
1052 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc, 1105 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1053}; 1106};
1054 1107
1108static unsigned int oqo9200_pin_configs[8] = {
1109 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1110 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1111};
1112
1055 1113
1056static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = { 1114static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1057 [STAC_REF] = ref9200_pin_configs, 1115 [STAC_REF] = ref9200_pin_configs,
1116 [STAC_9200_OQO] = oqo9200_pin_configs,
1058 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs, 1117 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1059 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs, 1118 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1060 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs, 1119 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
@@ -1065,10 +1124,12 @@ static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1065 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs, 1124 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1066 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs, 1125 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1067 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs, 1126 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1127 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1068}; 1128};
1069 1129
1070static const char *stac9200_models[STAC_9200_MODELS] = { 1130static const char *stac9200_models[STAC_9200_MODELS] = {
1071 [STAC_REF] = "ref", 1131 [STAC_REF] = "ref",
1132 [STAC_9200_OQO] = "oqo",
1072 [STAC_9200_DELL_D21] = "dell-d21", 1133 [STAC_9200_DELL_D21] = "dell-d21",
1073 [STAC_9200_DELL_D22] = "dell-d22", 1134 [STAC_9200_DELL_D22] = "dell-d22",
1074 [STAC_9200_DELL_D23] = "dell-d23", 1135 [STAC_9200_DELL_D23] = "dell-d23",
@@ -1080,6 +1141,7 @@ static const char *stac9200_models[STAC_9200_MODELS] = {
1080 [STAC_9200_DELL_M26] = "dell-m26", 1141 [STAC_9200_DELL_M26] = "dell-m26",
1081 [STAC_9200_DELL_M27] = "dell-m27", 1142 [STAC_9200_DELL_M27] = "dell-m27",
1082 [STAC_9200_GATEWAY] = "gateway", 1143 [STAC_9200_GATEWAY] = "gateway",
1144 [STAC_9200_PANASONIC] = "panasonic",
1083}; 1145};
1084 1146
1085static struct snd_pci_quirk stac9200_cfg_tbl[] = { 1147static struct snd_pci_quirk stac9200_cfg_tbl[] = {
@@ -1146,13 +1208,15 @@ static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1146 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6, 1208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1147 "unknown Dell", STAC_9200_DELL_M26), 1209 "unknown Dell", STAC_9200_DELL_M26),
1148 /* Panasonic */ 1210 /* Panasonic */
1149 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF), 1211 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1150 /* Gateway machines needs EAPD to be set on resume */ 1212 /* Gateway machines needs EAPD to be set on resume */
1151 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY), 1213 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1152 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", 1214 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1153 STAC_9200_GATEWAY), 1215 STAC_9200_GATEWAY),
1154 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", 1216 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1155 STAC_9200_GATEWAY), 1217 STAC_9200_GATEWAY),
1218 /* OQO Mobile */
1219 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1156 {} /* terminator */ 1220 {} /* terminator */
1157}; 1221};
1158 1222
@@ -1202,24 +1266,48 @@ static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1202 {} /* terminator */ 1266 {} /* terminator */
1203}; 1267};
1204 1268
1205static unsigned int ref92hd73xx_pin_configs[12] = { 1269static unsigned int ref92hd73xx_pin_configs[13] = {
1206 0x02214030, 0x02a19040, 0x01a19020, 0x02214030, 1270 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1207 0x0181302e, 0x01014010, 0x01014020, 0x01014030, 1271 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1208 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050, 1272 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1273 0x01452050,
1274};
1275
1276static unsigned int dell_m6_pin_configs[13] = {
1277 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1278 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1279 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1280 0x4f0000f0,
1209}; 1281};
1210 1282
1211static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = { 1283static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1212 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs, 1284 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1285 [STAC_DELL_M6] = dell_m6_pin_configs,
1213}; 1286};
1214 1287
1215static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = { 1288static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1216 [STAC_92HD73XX_REF] = "ref", 1289 [STAC_92HD73XX_REF] = "ref",
1290 [STAC_DELL_M6] = "dell-m6",
1217}; 1291};
1218 1292
1219static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = { 1293static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1220 /* SigmaTel reference board */ 1294 /* SigmaTel reference board */
1221 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1295 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1222 "DFI LanParty", STAC_92HD73XX_REF), 1296 "DFI LanParty", STAC_92HD73XX_REF),
1297 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1298 "unknown Dell", STAC_DELL_M6),
1299 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1300 "unknown Dell", STAC_DELL_M6),
1301 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1302 "unknown Dell", STAC_DELL_M6),
1303 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1304 "unknown Dell", STAC_DELL_M6),
1305 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1306 "unknown Dell", STAC_DELL_M6),
1307 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1308 "unknown Dell", STAC_DELL_M6),
1309 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1310 "unknown Dell", STAC_DELL_M6),
1223 {} /* terminator */ 1311 {} /* terminator */
1224}; 1312};
1225 1313
@@ -1229,18 +1317,56 @@ static unsigned int ref92hd71bxx_pin_configs[10] = {
1229 0x90a000f0, 0x01452050, 1317 0x90a000f0, 0x01452050,
1230}; 1318};
1231 1319
1320static unsigned int dell_m4_1_pin_configs[13] = {
1321 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1322 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1323 0x40f000f0, 0x4f0000f0,
1324};
1325
1326static unsigned int dell_m4_2_pin_configs[13] = {
1327 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1328 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1329 0x40f000f0, 0x044413b0,
1330};
1331
1232static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = { 1332static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1233 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs, 1333 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1334 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1335 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1234}; 1336};
1235 1337
1236static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = { 1338static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1237 [STAC_92HD71BXX_REF] = "ref", 1339 [STAC_92HD71BXX_REF] = "ref",
1340 [STAC_DELL_M4_1] = "dell-m4-1",
1341 [STAC_DELL_M4_2] = "dell-m4-2",
1238}; 1342};
1239 1343
1240static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = { 1344static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1241 /* SigmaTel reference board */ 1345 /* SigmaTel reference board */
1242 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1346 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1243 "DFI LanParty", STAC_92HD71BXX_REF), 1347 "DFI LanParty", STAC_92HD71BXX_REF),
1348 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1349 "unknown Dell", STAC_DELL_M4_1),
1350 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1351 "unknown Dell", STAC_DELL_M4_1),
1352 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1353 "unknown Dell", STAC_DELL_M4_1),
1354 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1355 "unknown Dell", STAC_DELL_M4_1),
1356 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1357 "unknown Dell", STAC_DELL_M4_1),
1358 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1359 "unknown Dell", STAC_DELL_M4_1),
1360 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1361 "unknown Dell", STAC_DELL_M4_1),
1362 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1363 "unknown Dell", STAC_DELL_M4_2),
1364 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1365 "unknown Dell", STAC_DELL_M4_2),
1366 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1367 "unknown Dell", STAC_DELL_M4_2),
1368 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1369 "unknown Dell", STAC_DELL_M4_2),
1244 {} /* terminator */ 1370 {} /* terminator */
1245}; 1371};
1246 1372
@@ -1733,7 +1859,8 @@ static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1733 struct snd_pcm_substream *substream) 1859 struct snd_pcm_substream *substream)
1734{ 1860{
1735 struct sigmatel_spec *spec = codec->spec; 1861 struct sigmatel_spec *spec = codec->spec;
1736 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 1862 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1863 hinfo);
1737} 1864}
1738 1865
1739static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 1866static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -1807,7 +1934,7 @@ static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1807{ 1934{
1808 struct sigmatel_spec *spec = codec->spec; 1935 struct sigmatel_spec *spec = codec->spec;
1809 1936
1810 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); 1937 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1811 return 0; 1938 return 0;
1812} 1939}
1813 1940
@@ -1889,6 +2016,7 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
1889 codec->num_pcms++; 2016 codec->num_pcms++;
1890 info++; 2017 info++;
1891 info->name = "STAC92xx Digital"; 2018 info->name = "STAC92xx Digital";
2019 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1892 if (spec->multiout.dig_out_nid) { 2020 if (spec->multiout.dig_out_nid) {
1893 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback; 2021 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1894 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 2022 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
@@ -1925,6 +2053,34 @@ static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int
1925 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); 2053 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1926} 2054}
1927 2055
2056#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2057
2058static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2059 struct snd_ctl_elem_value *ucontrol)
2060{
2061 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2062 struct sigmatel_spec *spec = codec->spec;
2063
2064 ucontrol->value.integer.value[0] = spec->hp_switch;
2065 return 0;
2066}
2067
2068static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2069 struct snd_ctl_elem_value *ucontrol)
2070{
2071 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2072 struct sigmatel_spec *spec = codec->spec;
2073
2074 spec->hp_switch = ucontrol->value.integer.value[0];
2075
2076 /* check to be sure that the ports are upto date with
2077 * switch changes
2078 */
2079 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2080
2081 return 1;
2082}
2083
1928#define stac92xx_io_switch_info snd_ctl_boolean_mono_info 2084#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
1929 2085
1930static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2086static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1996,6 +2152,15 @@ static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1996 return 1; 2152 return 1;
1997} 2153}
1998 2154
2155#define STAC_CODEC_HP_SWITCH(xname) \
2156 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2157 .name = xname, \
2158 .index = 0, \
2159 .info = stac92xx_hp_switch_info, \
2160 .get = stac92xx_hp_switch_get, \
2161 .put = stac92xx_hp_switch_put, \
2162 }
2163
1999#define STAC_CODEC_IO_SWITCH(xname, xpval) \ 2164#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2000 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 2165 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2001 .name = xname, \ 2166 .name = xname, \
@@ -2020,6 +2185,7 @@ enum {
2020 STAC_CTL_WIDGET_VOL, 2185 STAC_CTL_WIDGET_VOL,
2021 STAC_CTL_WIDGET_MUTE, 2186 STAC_CTL_WIDGET_MUTE,
2022 STAC_CTL_WIDGET_MONO_MUX, 2187 STAC_CTL_WIDGET_MONO_MUX,
2188 STAC_CTL_WIDGET_HP_SWITCH,
2023 STAC_CTL_WIDGET_IO_SWITCH, 2189 STAC_CTL_WIDGET_IO_SWITCH,
2024 STAC_CTL_WIDGET_CLFE_SWITCH 2190 STAC_CTL_WIDGET_CLFE_SWITCH
2025}; 2191};
@@ -2028,6 +2194,7 @@ static struct snd_kcontrol_new stac92xx_control_templates[] = {
2028 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 2194 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2029 HDA_CODEC_MUTE(NULL, 0, 0, 0), 2195 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2030 STAC_MONO_MUX, 2196 STAC_MONO_MUX,
2197 STAC_CODEC_HP_SWITCH(NULL),
2031 STAC_CODEC_IO_SWITCH(NULL, 0), 2198 STAC_CODEC_IO_SWITCH(NULL, 0),
2032 STAC_CODEC_CLFE_SWITCH(NULL, 0), 2199 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2033}; 2200};
@@ -2222,6 +2389,29 @@ static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_
2222 return 0; 2389 return 0;
2223} 2390}
2224 2391
2392static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2393{
2394 if (!spec->multiout.hp_nid)
2395 spec->multiout.hp_nid = nid;
2396 else if (spec->multiout.num_dacs > 4) {
2397 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2398 return 1;
2399 } else {
2400 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2401 spec->multiout.num_dacs++;
2402 }
2403 return 0;
2404}
2405
2406static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2407{
2408 if (is_in_dac_nids(spec, nid))
2409 return 1;
2410 if (spec->multiout.hp_nid == nid)
2411 return 1;
2412 return 0;
2413}
2414
2225/* add playback controls from the parsed DAC table */ 2415/* add playback controls from the parsed DAC table */
2226static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec, 2416static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2227 const struct auto_pin_cfg *cfg) 2417 const struct auto_pin_cfg *cfg)
@@ -2236,7 +2426,7 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2236 unsigned int wid_caps, pincap; 2426 unsigned int wid_caps, pincap;
2237 2427
2238 2428
2239 for (i = 0; i < cfg->line_outs; i++) { 2429 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
2240 if (!spec->multiout.dac_nids[i]) 2430 if (!spec->multiout.dac_nids[i])
2241 continue; 2431 continue;
2242 2432
@@ -2269,6 +2459,14 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2269 } 2459 }
2270 } 2460 }
2271 2461
2462 if (cfg->hp_outs > 1) {
2463 err = stac92xx_add_control(spec,
2464 STAC_CTL_WIDGET_HP_SWITCH,
2465 "Headphone as Line Out Switch", 0);
2466 if (err < 0)
2467 return err;
2468 }
2469
2272 if (spec->line_switch) { 2470 if (spec->line_switch) {
2273 nid = cfg->input_pins[AUTO_PIN_LINE]; 2471 nid = cfg->input_pins[AUTO_PIN_LINE];
2274 pincap = snd_hda_param_read(codec, nid, 2472 pincap = snd_hda_param_read(codec, nid,
@@ -2284,10 +2482,11 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2284 2482
2285 if (spec->mic_switch) { 2483 if (spec->mic_switch) {
2286 unsigned int def_conf; 2484 unsigned int def_conf;
2287 nid = cfg->input_pins[AUTO_PIN_MIC]; 2485 unsigned int mic_pin = AUTO_PIN_MIC;
2486again:
2487 nid = cfg->input_pins[mic_pin];
2288 def_conf = snd_hda_codec_read(codec, nid, 0, 2488 def_conf = snd_hda_codec_read(codec, nid, 0,
2289 AC_VERB_GET_CONFIG_DEFAULT, 0); 2489 AC_VERB_GET_CONFIG_DEFAULT, 0);
2290
2291 /* some laptops have an internal analog microphone 2490 /* some laptops have an internal analog microphone
2292 * which can't be used as a output */ 2491 * which can't be used as a output */
2293 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) { 2492 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
@@ -2297,38 +2496,22 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2297 err = stac92xx_add_control(spec, 2496 err = stac92xx_add_control(spec,
2298 STAC_CTL_WIDGET_IO_SWITCH, 2497 STAC_CTL_WIDGET_IO_SWITCH,
2299 "Mic as Output Switch", (nid << 8) | 1); 2498 "Mic as Output Switch", (nid << 8) | 1);
2499 nid = snd_hda_codec_read(codec, nid, 0,
2500 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2501 if (!check_in_dac_nids(spec, nid))
2502 add_spec_dacs(spec, nid);
2300 if (err < 0) 2503 if (err < 0)
2301 return err; 2504 return err;
2302 } 2505 }
2506 } else if (mic_pin == AUTO_PIN_MIC) {
2507 mic_pin = AUTO_PIN_FRONT_MIC;
2508 goto again;
2303 } 2509 }
2304 } 2510 }
2305 2511
2306 return 0; 2512 return 0;
2307} 2513}
2308 2514
2309static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2310{
2311 if (is_in_dac_nids(spec, nid))
2312 return 1;
2313 if (spec->multiout.hp_nid == nid)
2314 return 1;
2315 return 0;
2316}
2317
2318static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2319{
2320 if (!spec->multiout.hp_nid)
2321 spec->multiout.hp_nid = nid;
2322 else if (spec->multiout.num_dacs > 4) {
2323 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2324 return 1;
2325 } else {
2326 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2327 spec->multiout.num_dacs++;
2328 }
2329 return 0;
2330}
2331
2332/* add playback controls for Speaker and HP outputs */ 2515/* add playback controls for Speaker and HP outputs */
2333static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, 2516static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2334 struct auto_pin_cfg *cfg) 2517 struct auto_pin_cfg *cfg)
@@ -2378,12 +2561,8 @@ static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2378 return err; 2561 return err;
2379 } 2562 }
2380 if (spec->multiout.hp_nid) { 2563 if (spec->multiout.hp_nid) {
2381 const char *pfx; 2564 err = create_controls(spec, "Headphone",
2382 if (old_num_dacs == spec->multiout.num_dacs) 2565 spec->multiout.hp_nid, 3);
2383 pfx = "Master";
2384 else
2385 pfx = "Headphone";
2386 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
2387 if (err < 0) 2566 if (err < 0)
2388 return err; 2567 return err;
2389 } 2568 }
@@ -2745,7 +2924,7 @@ static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2745 */ 2924 */
2746 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) { 2925 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2747 hda_nid_t pin = spec->autocfg.speaker_pins[i]; 2926 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2748 unsigned long wcaps = get_wcaps(codec, pin); 2927 unsigned int wcaps = get_wcaps(codec, pin);
2749 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP); 2928 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2750 if (wcaps == AC_WCAP_OUT_AMP) 2929 if (wcaps == AC_WCAP_OUT_AMP)
2751 /* found a mono speaker with an amp, must be lfe */ 2930 /* found a mono speaker with an amp, must be lfe */
@@ -2756,12 +2935,12 @@ static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2756 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) { 2935 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2757 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) { 2936 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2758 hda_nid_t pin = spec->autocfg.line_out_pins[i]; 2937 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2759 unsigned long cfg; 2938 unsigned int defcfg;
2760 cfg = snd_hda_codec_read(codec, pin, 0, 2939 defcfg = snd_hda_codec_read(codec, pin, 0,
2761 AC_VERB_GET_CONFIG_DEFAULT, 2940 AC_VERB_GET_CONFIG_DEFAULT,
2762 0x00); 2941 0x00);
2763 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) { 2942 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
2764 unsigned long wcaps = get_wcaps(codec, pin); 2943 unsigned int wcaps = get_wcaps(codec, pin);
2765 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP); 2944 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2766 if (wcaps == AC_WCAP_OUT_AMP) 2945 if (wcaps == AC_WCAP_OUT_AMP)
2767 /* found a mono speaker with an amp, 2946 /* found a mono speaker with an amp,
@@ -2866,6 +3045,19 @@ static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
2866 return 0; /* nid is not a HP-Out */ 3045 return 0; /* nid is not a HP-Out */
2867}; 3046};
2868 3047
3048static void stac92xx_power_down(struct hda_codec *codec)
3049{
3050 struct sigmatel_spec *spec = codec->spec;
3051
3052 /* power down inactive DACs */
3053 hda_nid_t *dac;
3054 for (dac = spec->dac_list; *dac; dac++)
3055 if (!is_in_dac_nids(spec, *dac) &&
3056 spec->multiout.hp_nid != *dac)
3057 snd_hda_codec_write_cache(codec, *dac, 0,
3058 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3059}
3060
2869static int stac92xx_init(struct hda_codec *codec) 3061static int stac92xx_init(struct hda_codec *codec)
2870{ 3062{
2871 struct sigmatel_spec *spec = codec->spec; 3063 struct sigmatel_spec *spec = codec->spec;
@@ -2909,16 +3101,21 @@ static int stac92xx_init(struct hda_codec *codec)
2909 ? STAC_HP_EVENT : STAC_PWR_EVENT; 3101 ? STAC_HP_EVENT : STAC_PWR_EVENT;
2910 int pinctl = snd_hda_codec_read(codec, spec->pwr_nids[i], 3102 int pinctl = snd_hda_codec_read(codec, spec->pwr_nids[i],
2911 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 3103 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3104 int def_conf = snd_hda_codec_read(codec, spec->pwr_nids[i],
3105 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
2912 /* outputs are only ports capable of power management 3106 /* outputs are only ports capable of power management
2913 * any attempts on powering down a input port cause the 3107 * any attempts on powering down a input port cause the
2914 * referenced VREF to act quirky. 3108 * referenced VREF to act quirky.
2915 */ 3109 */
2916 if (pinctl & AC_PINCTL_IN_EN) 3110 if (pinctl & AC_PINCTL_IN_EN)
2917 continue; 3111 continue;
3112 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED)
3113 continue;
2918 enable_pin_detect(codec, spec->pwr_nids[i], event | i); 3114 enable_pin_detect(codec, spec->pwr_nids[i], event | i);
2919 codec->patch_ops.unsol_event(codec, (event | i) << 26); 3115 codec->patch_ops.unsol_event(codec, (event | i) << 26);
2920 } 3116 }
2921 3117 if (spec->dac_list)
3118 stac92xx_power_down(codec);
2922 if (cfg->dig_out_pin) 3119 if (cfg->dig_out_pin)
2923 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin, 3120 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2924 AC_PINCTL_OUT_EN); 3121 AC_PINCTL_OUT_EN);
@@ -3014,6 +3211,7 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
3014{ 3211{
3015 struct sigmatel_spec *spec = codec->spec; 3212 struct sigmatel_spec *spec = codec->spec;
3016 struct auto_pin_cfg *cfg = &spec->autocfg; 3213 struct auto_pin_cfg *cfg = &spec->autocfg;
3214 int nid = cfg->hp_pins[cfg->hp_outs - 1];
3017 int i, presence; 3215 int i, presence;
3018 3216
3019 presence = 0; 3217 presence = 0;
@@ -3024,26 +3222,42 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
3024 for (i = 0; i < cfg->hp_outs; i++) { 3222 for (i = 0; i < cfg->hp_outs; i++) {
3025 if (presence) 3223 if (presence)
3026 break; 3224 break;
3225 if (spec->hp_switch && cfg->hp_pins[i] == nid)
3226 break;
3027 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]); 3227 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
3028 } 3228 }
3029 3229
3030 if (presence) { 3230 if (presence) {
3031 /* disable lineouts, enable hp */ 3231 /* disable lineouts, enable hp */
3232 if (spec->hp_switch)
3233 stac92xx_reset_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3032 for (i = 0; i < cfg->line_outs; i++) 3234 for (i = 0; i < cfg->line_outs; i++)
3033 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i], 3235 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
3034 AC_PINCTL_OUT_EN); 3236 AC_PINCTL_OUT_EN);
3035 for (i = 0; i < cfg->speaker_outs; i++) 3237 for (i = 0; i < cfg->speaker_outs; i++)
3036 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i], 3238 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
3037 AC_PINCTL_OUT_EN); 3239 AC_PINCTL_OUT_EN);
3240 if (spec->eapd_mask)
3241 stac_gpio_set(codec, spec->gpio_mask,
3242 spec->gpio_dir, spec->gpio_data &
3243 ~spec->eapd_mask);
3038 } else { 3244 } else {
3039 /* enable lineouts, disable hp */ 3245 /* enable lineouts, disable hp */
3246 if (spec->hp_switch)
3247 stac92xx_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3040 for (i = 0; i < cfg->line_outs; i++) 3248 for (i = 0; i < cfg->line_outs; i++)
3041 stac92xx_set_pinctl(codec, cfg->line_out_pins[i], 3249 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
3042 AC_PINCTL_OUT_EN); 3250 AC_PINCTL_OUT_EN);
3043 for (i = 0; i < cfg->speaker_outs; i++) 3251 for (i = 0; i < cfg->speaker_outs; i++)
3044 stac92xx_set_pinctl(codec, cfg->speaker_pins[i], 3252 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
3045 AC_PINCTL_OUT_EN); 3253 AC_PINCTL_OUT_EN);
3254 if (spec->eapd_mask)
3255 stac_gpio_set(codec, spec->gpio_mask,
3256 spec->gpio_dir, spec->gpio_data |
3257 spec->eapd_mask);
3046 } 3258 }
3259 if (!spec->hp_switch && cfg->hp_outs > 1 && presence)
3260 stac92xx_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3047} 3261}
3048 3262
3049static void stac92xx_pin_sense(struct hda_codec *codec, int idx) 3263static void stac92xx_pin_sense(struct hda_codec *codec, int idx)
@@ -3091,6 +3305,9 @@ static int stac92xx_resume(struct hda_codec *codec)
3091 spec->gpio_dir, spec->gpio_data); 3305 spec->gpio_dir, spec->gpio_data);
3092 snd_hda_codec_resume_amp(codec); 3306 snd_hda_codec_resume_amp(codec);
3093 snd_hda_codec_resume_cache(codec); 3307 snd_hda_codec_resume_cache(codec);
3308 /* power down inactive DACs */
3309 if (spec->dac_list)
3310 stac92xx_power_down(codec);
3094 /* invoke unsolicited event to reset the HP state */ 3311 /* invoke unsolicited event to reset the HP state */
3095 if (spec->hp_detect) 3312 if (spec->hp_detect)
3096 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); 3313 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
@@ -3147,12 +3364,18 @@ static int patch_stac9200(struct hda_codec *codec)
3147 spec->num_adcs = 1; 3364 spec->num_adcs = 1;
3148 spec->num_pwrs = 0; 3365 spec->num_pwrs = 0;
3149 3366
3150 if (spec->board_config == STAC_9200_GATEWAY) 3367 if (spec->board_config == STAC_9200_GATEWAY ||
3368 spec->board_config == STAC_9200_OQO)
3151 spec->init = stac9200_eapd_init; 3369 spec->init = stac9200_eapd_init;
3152 else 3370 else
3153 spec->init = stac9200_core_init; 3371 spec->init = stac9200_core_init;
3154 spec->mixer = stac9200_mixer; 3372 spec->mixer = stac9200_mixer;
3155 3373
3374 if (spec->board_config == STAC_9200_PANASONIC) {
3375 spec->gpio_mask = spec->gpio_dir = 0x09;
3376 spec->gpio_data = 0x00;
3377 }
3378
3156 err = stac9200_parse_auto_config(codec); 3379 err = stac9200_parse_auto_config(codec);
3157 if (err < 0) { 3380 if (err < 0) {
3158 stac92xx_free(codec); 3381 stac92xx_free(codec);
@@ -3293,6 +3516,7 @@ again:
3293 3516
3294 switch (spec->multiout.num_dacs) { 3517 switch (spec->multiout.num_dacs) {
3295 case 0x3: /* 6 Channel */ 3518 case 0x3: /* 6 Channel */
3519 spec->multiout.hp_nid = 0x17;
3296 spec->mixer = stac92hd73xx_6ch_mixer; 3520 spec->mixer = stac92hd73xx_6ch_mixer;
3297 spec->init = stac92hd73xx_6ch_core_init; 3521 spec->init = stac92hd73xx_6ch_core_init;
3298 break; 3522 break;
@@ -3318,13 +3542,42 @@ again:
3318 3542
3319 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids); 3543 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
3320 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids); 3544 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
3321 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
3322 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids); 3545 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
3323 spec->dinput_mux = &stac92hd73xx_dmux; 3546 spec->dinput_mux = &stac92hd73xx_dmux;
3324 /* GPIO0 High = Enable EAPD */ 3547 /* GPIO0 High = Enable EAPD */
3325 spec->gpio_mask = spec->gpio_dir = 0x1; 3548 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
3326 spec->gpio_data = 0x01; 3549 spec->gpio_data = 0x01;
3327 3550
3551 switch (spec->board_config) {
3552 case STAC_DELL_M6:
3553 spec->init = dell_eq_core_init;
3554 switch (codec->subsystem_id) {
3555 case 0x1028025e: /* Analog Mics */
3556 case 0x1028025f:
3557 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
3558 spec->num_dmics = 0;
3559 break;
3560 case 0x10280271: /* Digital Mics */
3561 case 0x10280272:
3562 spec->init = dell_m6_core_init;
3563 /* fall-through */
3564 case 0x10280254:
3565 case 0x10280255:
3566 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
3567 spec->num_dmics = 1;
3568 break;
3569 case 0x10280256: /* Both */
3570 case 0x10280057:
3571 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
3572 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
3573 spec->num_dmics = 1;
3574 break;
3575 }
3576 break;
3577 default:
3578 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
3579 }
3580
3328 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids); 3581 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
3329 spec->pwr_nids = stac92hd73xx_pwr_nids; 3582 spec->pwr_nids = stac92hd73xx_pwr_nids;
3330 3583
@@ -3398,7 +3651,10 @@ again:
3398 spec->aloopback_shift = 0; 3651 spec->aloopback_shift = 0;
3399 3652
3400 /* GPIO0 High = EAPD */ 3653 /* GPIO0 High = EAPD */
3401 spec->gpio_mask = spec->gpio_dir = spec->gpio_data = 0x1; 3654 spec->gpio_mask = 0x01;
3655 spec->gpio_dir = 0x01;
3656 spec->gpio_mask = 0x01;
3657 spec->gpio_data = 0x01;
3402 3658
3403 spec->mux_nids = stac92hd71bxx_mux_nids; 3659 spec->mux_nids = stac92hd71bxx_mux_nids;
3404 spec->adc_nids = stac92hd71bxx_adc_nids; 3660 spec->adc_nids = stac92hd71bxx_adc_nids;
@@ -3413,7 +3669,7 @@ again:
3413 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids); 3669 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
3414 spec->pwr_nids = stac92hd71bxx_pwr_nids; 3670 spec->pwr_nids = stac92hd71bxx_pwr_nids;
3415 3671
3416 spec->multiout.num_dacs = 2; 3672 spec->multiout.num_dacs = 1;
3417 spec->multiout.hp_nid = 0x11; 3673 spec->multiout.hp_nid = 0x11;
3418 spec->multiout.dac_nids = stac92hd71bxx_dac_nids; 3674 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
3419 3675
@@ -3577,13 +3833,14 @@ static int patch_stac927x(struct hda_codec *codec)
3577 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids); 3833 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
3578 spec->mux_nids = stac927x_mux_nids; 3834 spec->mux_nids = stac927x_mux_nids;
3579 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids); 3835 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
3836 spec->dac_list = stac927x_dac_nids;
3580 spec->multiout.dac_nids = spec->dac_nids; 3837 spec->multiout.dac_nids = spec->dac_nids;
3581 3838
3582 switch (spec->board_config) { 3839 switch (spec->board_config) {
3583 case STAC_D965_3ST: 3840 case STAC_D965_3ST:
3584 case STAC_D965_5ST: 3841 case STAC_D965_5ST:
3585 /* GPIO0 High = Enable EAPD */ 3842 /* GPIO0 High = Enable EAPD */
3586 spec->gpio_mask = spec->gpio_dir = 0x01; 3843 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
3587 spec->gpio_data = 0x01; 3844 spec->gpio_data = 0x01;
3588 spec->num_dmics = 0; 3845 spec->num_dmics = 0;
3589 3846
@@ -3591,14 +3848,23 @@ static int patch_stac927x(struct hda_codec *codec)
3591 spec->mixer = stac927x_mixer; 3848 spec->mixer = stac927x_mixer;
3592 break; 3849 break;
3593 case STAC_DELL_BIOS: 3850 case STAC_DELL_BIOS:
3851 switch (codec->subsystem_id) {
3852 case 0x10280209:
3853 case 0x1028022e:
3854 /* correct the device field to SPDIF out */
3855 stac92xx_set_config_reg(codec, 0x21, 0x01442070);
3856 break;
3857 };
3858 /* configure the analog microphone on some laptops */
3859 stac92xx_set_config_reg(codec, 0x0c, 0x90a79130);
3594 /* correct the front output jack as a hp out */ 3860 /* correct the front output jack as a hp out */
3595 stac92xx_set_config_reg(codec, 0x0f, 0x02270110); 3861 stac92xx_set_config_reg(codec, 0x0f, 0x0227011f);
3596 /* correct the front input jack as a mic */ 3862 /* correct the front input jack as a mic */
3597 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130); 3863 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130);
3598 /* fallthru */ 3864 /* fallthru */
3599 case STAC_DELL_3ST: 3865 case STAC_DELL_3ST:
3600 /* GPIO2 High = Enable EAPD */ 3866 /* GPIO2 High = Enable EAPD */
3601 spec->gpio_mask = spec->gpio_dir = 0x04; 3867 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
3602 spec->gpio_data = 0x04; 3868 spec->gpio_data = 0x04;
3603 spec->dmic_nids = stac927x_dmic_nids; 3869 spec->dmic_nids = stac927x_dmic_nids;
3604 spec->num_dmics = STAC927X_NUM_DMICS; 3870 spec->num_dmics = STAC927X_NUM_DMICS;
@@ -3610,7 +3876,7 @@ static int patch_stac927x(struct hda_codec *codec)
3610 break; 3876 break;
3611 default: 3877 default:
3612 /* GPIO0 High = Enable EAPD */ 3878 /* GPIO0 High = Enable EAPD */
3613 spec->gpio_mask = spec->gpio_dir = 0x1; 3879 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
3614 spec->gpio_data = 0x01; 3880 spec->gpio_data = 0x01;
3615 spec->num_dmics = 0; 3881 spec->num_dmics = 0;
3616 3882
@@ -3714,6 +3980,7 @@ static int patch_stac9205(struct hda_codec *codec)
3714 (AC_USRSP_EN | STAC_HP_EVENT)); 3980 (AC_USRSP_EN | STAC_HP_EVENT));
3715 3981
3716 spec->gpio_dir = 0x0b; 3982 spec->gpio_dir = 0x0b;
3983 spec->eapd_mask = 0x01;
3717 spec->gpio_mask = 0x1b; 3984 spec->gpio_mask = 0x1b;
3718 spec->gpio_mute = 0x10; 3985 spec->gpio_mute = 0x10;
3719 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute, 3986 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
@@ -3723,7 +3990,7 @@ static int patch_stac9205(struct hda_codec *codec)
3723 break; 3990 break;
3724 default: 3991 default:
3725 /* GPIO0 High = EAPD */ 3992 /* GPIO0 High = EAPD */
3726 spec->gpio_mask = spec->gpio_dir = 0x1; 3993 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
3727 spec->gpio_data = 0x01; 3994 spec->gpio_data = 0x01;
3728 break; 3995 break;
3729 } 3996 }
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 4e5dd4cf36f5..52b1d81a26f7 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -39,7 +39,7 @@
39#include <sound/core.h> 39#include <sound/core.h>
40#include "hda_codec.h" 40#include "hda_codec.h"
41#include "hda_local.h" 41#include "hda_local.h"
42 42#include "hda_patch.h"
43 43
44/* amp values */ 44/* amp values */
45#define AMP_VAL_IDX_SHIFT 19 45#define AMP_VAL_IDX_SHIFT 19
@@ -357,7 +357,8 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
357 struct snd_pcm_substream *substream) 357 struct snd_pcm_substream *substream)
358{ 358{
359 struct via_spec *spec = codec->spec; 359 struct via_spec *spec = codec->spec;
360 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 360 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
361 hinfo);
361} 362}
362 363
363static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 364static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -430,8 +431,7 @@ static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
430 struct snd_pcm_substream *substream) 431 struct snd_pcm_substream *substream)
431{ 432{
432 struct via_spec *spec = codec->spec; 433 struct via_spec *spec = codec->spec;
433 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 434 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
434 0, 0, 0);
435 return 0; 435 return 0;
436} 436}
437 437
@@ -493,6 +493,11 @@ static int via_build_controls(struct hda_codec *codec)
493 spec->multiout.dig_out_nid); 493 spec->multiout.dig_out_nid);
494 if (err < 0) 494 if (err < 0)
495 return err; 495 return err;
496 err = snd_hda_create_spdif_share_sw(codec,
497 &spec->multiout);
498 if (err < 0)
499 return err;
500 spec->multiout.share_spdif = 1;
496 } 501 }
497 if (spec->dig_in_nid) { 502 if (spec->dig_in_nid) {
498 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 503 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -523,6 +528,7 @@ static int via_build_pcms(struct hda_codec *codec)
523 codec->num_pcms++; 528 codec->num_pcms++;
524 info++; 529 info++;
525 info->name = spec->stream_name_digital; 530 info->name = spec->stream_name_digital;
531 info->pcm_type = HDA_PCM_TYPE_SPDIF;
526 if (spec->multiout.dig_out_nid) { 532 if (spec->multiout.dig_out_nid) {
527 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 533 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
528 *(spec->stream_digital_playback); 534 *(spec->stream_digital_playback);
diff --git a/sound/pci/ice1712/delta.c b/sound/pci/ice1712/delta.c
index efd180b40e56..0ed96c178059 100644
--- a/sound/pci/ice1712/delta.c
+++ b/sound/pci/ice1712/delta.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * ALSA driver for ICEnsemble ICE1712 (Envy24) 2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
3 * 3 *
4 * Lowlevel functions for M-Audio Delta 1010, 44, 66, Dio2496, Audiophile 4 * Lowlevel functions for M-Audio Delta 1010, 1010E, 44, 66, 66E, Dio2496,
5 * Digigram VX442 5 * Audiophile, Digigram VX442
6 * 6 *
7 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz> 7 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
8 * 8 *
@@ -86,6 +86,7 @@ static unsigned char ap_cs8427_codec_select(struct snd_ice1712 *ice)
86 unsigned char tmp; 86 unsigned char tmp;
87 tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA); 87 tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
88 switch (ice->eeprom.subvendor) { 88 switch (ice->eeprom.subvendor) {
89 case ICE1712_SUBDEVICE_DELTA1010E:
89 case ICE1712_SUBDEVICE_DELTA1010LT: 90 case ICE1712_SUBDEVICE_DELTA1010LT:
90 tmp &= ~ICE1712_DELTA_1010LT_CS; 91 tmp &= ~ICE1712_DELTA_1010LT_CS;
91 tmp |= ICE1712_DELTA_1010LT_CCLK | ICE1712_DELTA_1010LT_CS_CS8427; 92 tmp |= ICE1712_DELTA_1010LT_CCLK | ICE1712_DELTA_1010LT_CS_CS8427;
@@ -109,6 +110,7 @@ static unsigned char ap_cs8427_codec_select(struct snd_ice1712 *ice)
109static void ap_cs8427_codec_deassert(struct snd_ice1712 *ice, unsigned char tmp) 110static void ap_cs8427_codec_deassert(struct snd_ice1712 *ice, unsigned char tmp)
110{ 111{
111 switch (ice->eeprom.subvendor) { 112 switch (ice->eeprom.subvendor) {
113 case ICE1712_SUBDEVICE_DELTA1010E:
112 case ICE1712_SUBDEVICE_DELTA1010LT: 114 case ICE1712_SUBDEVICE_DELTA1010LT:
113 tmp &= ~ICE1712_DELTA_1010LT_CS; 115 tmp &= ~ICE1712_DELTA_1010LT_CS;
114 tmp |= ICE1712_DELTA_1010LT_CS_NONE; 116 tmp |= ICE1712_DELTA_1010LT_CS_NONE;
@@ -534,6 +536,14 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
534 int err; 536 int err;
535 struct snd_akm4xxx *ak; 537 struct snd_akm4xxx *ak;
536 538
539 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA1010 &&
540 ice->eeprom.gpiodir == 0x7b)
541 ice->eeprom.subvendor = ICE1712_SUBDEVICE_DELTA1010E;
542
543 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA66 &&
544 ice->eeprom.gpiodir == 0xfb)
545 ice->eeprom.subvendor = ICE1712_SUBDEVICE_DELTA66E;
546
537 /* determine I2C, DACs and ADCs */ 547 /* determine I2C, DACs and ADCs */
538 switch (ice->eeprom.subvendor) { 548 switch (ice->eeprom.subvendor) {
539 case ICE1712_SUBDEVICE_AUDIOPHILE: 549 case ICE1712_SUBDEVICE_AUDIOPHILE:
@@ -550,6 +560,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
550 ice->num_total_adcs = ice->omni ? 8 : 4; 560 ice->num_total_adcs = ice->omni ? 8 : 4;
551 break; 561 break;
552 case ICE1712_SUBDEVICE_DELTA1010: 562 case ICE1712_SUBDEVICE_DELTA1010:
563 case ICE1712_SUBDEVICE_DELTA1010E:
553 case ICE1712_SUBDEVICE_DELTA1010LT: 564 case ICE1712_SUBDEVICE_DELTA1010LT:
554 case ICE1712_SUBDEVICE_MEDIASTATION: 565 case ICE1712_SUBDEVICE_MEDIASTATION:
555 ice->num_total_dacs = 8; 566 ice->num_total_dacs = 8;
@@ -559,6 +570,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
559 ice->num_total_dacs = 4; /* two AK4324 codecs */ 570 ice->num_total_dacs = 4; /* two AK4324 codecs */
560 break; 571 break;
561 case ICE1712_SUBDEVICE_VX442: 572 case ICE1712_SUBDEVICE_VX442:
573 case ICE1712_SUBDEVICE_DELTA66E: /* omni not suported yet */
562 ice->num_total_dacs = 4; 574 ice->num_total_dacs = 4;
563 ice->num_total_adcs = 4; 575 ice->num_total_adcs = 4;
564 break; 576 break;
@@ -568,8 +580,10 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
568 switch (ice->eeprom.subvendor) { 580 switch (ice->eeprom.subvendor) {
569 case ICE1712_SUBDEVICE_AUDIOPHILE: 581 case ICE1712_SUBDEVICE_AUDIOPHILE:
570 case ICE1712_SUBDEVICE_DELTA410: 582 case ICE1712_SUBDEVICE_DELTA410:
583 case ICE1712_SUBDEVICE_DELTA1010E:
571 case ICE1712_SUBDEVICE_DELTA1010LT: 584 case ICE1712_SUBDEVICE_DELTA1010LT:
572 case ICE1712_SUBDEVICE_VX442: 585 case ICE1712_SUBDEVICE_VX442:
586 case ICE1712_SUBDEVICE_DELTA66E:
573 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { 587 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
574 snd_printk(KERN_ERR "unable to create I2C bus\n"); 588 snd_printk(KERN_ERR "unable to create I2C bus\n");
575 return err; 589 return err;
@@ -601,6 +615,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
601 /* no analog? */ 615 /* no analog? */
602 switch (ice->eeprom.subvendor) { 616 switch (ice->eeprom.subvendor) {
603 case ICE1712_SUBDEVICE_DELTA1010: 617 case ICE1712_SUBDEVICE_DELTA1010:
618 case ICE1712_SUBDEVICE_DELTA1010E:
604 case ICE1712_SUBDEVICE_DELTADIO2496: 619 case ICE1712_SUBDEVICE_DELTADIO2496:
605 case ICE1712_SUBDEVICE_MEDIASTATION: 620 case ICE1712_SUBDEVICE_MEDIASTATION:
606 return 0; 621 return 0;
@@ -627,6 +642,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
627 err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice); 642 err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
628 break; 643 break;
629 case ICE1712_SUBDEVICE_VX442: 644 case ICE1712_SUBDEVICE_VX442:
645 case ICE1712_SUBDEVICE_DELTA66E:
630 err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice); 646 err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice);
631 break; 647 break;
632 default: 648 default:
@@ -674,6 +690,7 @@ static int __devinit snd_ice1712_delta_add_controls(struct snd_ice1712 *ice)
674 if (err < 0) 690 if (err < 0)
675 return err; 691 return err;
676 break; 692 break;
693 case ICE1712_SUBDEVICE_DELTA1010E:
677 case ICE1712_SUBDEVICE_DELTA1010LT: 694 case ICE1712_SUBDEVICE_DELTA1010LT:
678 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice)); 695 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice));
679 if (err < 0) 696 if (err < 0)
@@ -716,6 +733,7 @@ static int __devinit snd_ice1712_delta_add_controls(struct snd_ice1712 *ice)
716 case ICE1712_SUBDEVICE_DELTA44: 733 case ICE1712_SUBDEVICE_DELTA44:
717 case ICE1712_SUBDEVICE_DELTA66: 734 case ICE1712_SUBDEVICE_DELTA66:
718 case ICE1712_SUBDEVICE_VX442: 735 case ICE1712_SUBDEVICE_VX442:
736 case ICE1712_SUBDEVICE_DELTA66E:
719 err = snd_ice1712_akm4xxx_build_controls(ice); 737 err = snd_ice1712_akm4xxx_build_controls(ice);
720 if (err < 0) 738 if (err < 0)
721 return err; 739 return err;
diff --git a/sound/pci/ice1712/delta.h b/sound/pci/ice1712/delta.h
index 26ea05a32f56..ea7116c304c0 100644
--- a/sound/pci/ice1712/delta.h
+++ b/sound/pci/ice1712/delta.h
@@ -36,8 +36,10 @@
36 "{Lionstracs,Mediastation}," 36 "{Lionstracs,Mediastation},"
37 37
38#define ICE1712_SUBDEVICE_DELTA1010 0x121430d6 38#define ICE1712_SUBDEVICE_DELTA1010 0x121430d6
39#define ICE1712_SUBDEVICE_DELTA1010E 0xff1430d6
39#define ICE1712_SUBDEVICE_DELTADIO2496 0x121431d6 40#define ICE1712_SUBDEVICE_DELTADIO2496 0x121431d6
40#define ICE1712_SUBDEVICE_DELTA66 0x121432d6 41#define ICE1712_SUBDEVICE_DELTA66 0x121432d6
42#define ICE1712_SUBDEVICE_DELTA66E 0xff1432d6
41#define ICE1712_SUBDEVICE_DELTA44 0x121433d6 43#define ICE1712_SUBDEVICE_DELTA44 0x121433d6
42#define ICE1712_SUBDEVICE_AUDIOPHILE 0x121434d6 44#define ICE1712_SUBDEVICE_AUDIOPHILE 0x121434d6
43#define ICE1712_SUBDEVICE_DELTA410 0x121438d6 45#define ICE1712_SUBDEVICE_DELTA410 0x121438d6
diff --git a/sound/pci/ice1712/ews.c b/sound/pci/ice1712/ews.c
index 064760d2a027..013fc4f04822 100644
--- a/sound/pci/ice1712/ews.c
+++ b/sound/pci/ice1712/ews.c
@@ -238,6 +238,7 @@ static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned
238 case ICE1712_SUBDEVICE_EWS88MT: 238 case ICE1712_SUBDEVICE_EWS88MT:
239 case ICE1712_SUBDEVICE_EWS88MT_NEW: 239 case ICE1712_SUBDEVICE_EWS88MT_NEW:
240 case ICE1712_SUBDEVICE_PHASE88: 240 case ICE1712_SUBDEVICE_PHASE88:
241 case ICE1712_SUBDEVICE_TS88:
241 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1) 242 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1)
242 != 1) 243 != 1)
243 goto _error; 244 goto _error;
@@ -433,6 +434,7 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
433 case ICE1712_SUBDEVICE_EWS88MT: 434 case ICE1712_SUBDEVICE_EWS88MT:
434 case ICE1712_SUBDEVICE_EWS88MT_NEW: 435 case ICE1712_SUBDEVICE_EWS88MT_NEW:
435 case ICE1712_SUBDEVICE_PHASE88: 436 case ICE1712_SUBDEVICE_PHASE88:
437 case ICE1712_SUBDEVICE_TS88:
436 ice->num_total_dacs = 8; 438 ice->num_total_dacs = 8;
437 ice->num_total_adcs = 8; 439 ice->num_total_adcs = 8;
438 break; 440 break;
@@ -475,6 +477,8 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
475 case ICE1712_SUBDEVICE_EWS88MT: 477 case ICE1712_SUBDEVICE_EWS88MT:
476 case ICE1712_SUBDEVICE_EWS88MT_NEW: 478 case ICE1712_SUBDEVICE_EWS88MT_NEW:
477 case ICE1712_SUBDEVICE_PHASE88: 479 case ICE1712_SUBDEVICE_PHASE88:
480 case ICE1712_SUBDEVICE_TS88:
481
478 err = snd_i2c_device_create(ice->i2c, "CS8404", 482 err = snd_i2c_device_create(ice->i2c, "CS8404",
479 ICE1712_EWS88MT_CS8404_ADDR, 483 ICE1712_EWS88MT_CS8404_ADDR,
480 &spec->i2cdevs[EWS_I2C_CS8404]); 484 &spec->i2cdevs[EWS_I2C_CS8404]);
@@ -518,6 +522,7 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
518 case ICE1712_SUBDEVICE_EWS88MT: 522 case ICE1712_SUBDEVICE_EWS88MT:
519 case ICE1712_SUBDEVICE_EWS88MT_NEW: 523 case ICE1712_SUBDEVICE_EWS88MT_NEW:
520 case ICE1712_SUBDEVICE_PHASE88: 524 case ICE1712_SUBDEVICE_PHASE88:
525 case ICE1712_SUBDEVICE_TS88:
521 case ICE1712_SUBDEVICE_EWS88D: 526 case ICE1712_SUBDEVICE_EWS88D:
522 /* set up CS8404 */ 527 /* set up CS8404 */
523 ice->spdif.ops.open = ews88_open_spdif; 528 ice->spdif.ops.open = ews88_open_spdif;
@@ -547,6 +552,7 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
547 case ICE1712_SUBDEVICE_EWS88MT: 552 case ICE1712_SUBDEVICE_EWS88MT:
548 case ICE1712_SUBDEVICE_EWS88MT_NEW: 553 case ICE1712_SUBDEVICE_EWS88MT_NEW:
549 case ICE1712_SUBDEVICE_PHASE88: 554 case ICE1712_SUBDEVICE_PHASE88:
555 case ICE1712_SUBDEVICE_TS88:
550 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice); 556 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
551 break; 557 break;
552 case ICE1712_SUBDEVICE_EWX2496: 558 case ICE1712_SUBDEVICE_EWX2496:
@@ -973,6 +979,7 @@ static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
973 case ICE1712_SUBDEVICE_EWS88MT: 979 case ICE1712_SUBDEVICE_EWS88MT:
974 case ICE1712_SUBDEVICE_EWS88MT_NEW: 980 case ICE1712_SUBDEVICE_EWS88MT_NEW:
975 case ICE1712_SUBDEVICE_PHASE88: 981 case ICE1712_SUBDEVICE_PHASE88:
982 case ICE1712_SUBDEVICE_TS88:
976 case ICE1712_SUBDEVICE_DMX6FIRE: 983 case ICE1712_SUBDEVICE_DMX6FIRE:
977 err = snd_ice1712_akm4xxx_build_controls(ice); 984 err = snd_ice1712_akm4xxx_build_controls(ice);
978 if (err < 0) 985 if (err < 0)
@@ -992,6 +999,7 @@ static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
992 case ICE1712_SUBDEVICE_EWS88MT: 999 case ICE1712_SUBDEVICE_EWS88MT:
993 case ICE1712_SUBDEVICE_EWS88MT_NEW: 1000 case ICE1712_SUBDEVICE_EWS88MT_NEW:
994 case ICE1712_SUBDEVICE_PHASE88: 1001 case ICE1712_SUBDEVICE_PHASE88:
1002 case ICE1712_SUBDEVICE_TS88:
995 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice)); 1003 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
996 if (err < 0) 1004 if (err < 0)
997 return err; 1005 return err;
@@ -1049,6 +1057,13 @@ struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = {
1049 .build_controls = snd_ice1712_ews_add_controls, 1057 .build_controls = snd_ice1712_ews_add_controls,
1050 }, 1058 },
1051 { 1059 {
1060 .subvendor = ICE1712_SUBDEVICE_TS88,
1061 .name = "terrasoniq TS88",
1062 .model = "phase88",
1063 .chip_init = snd_ice1712_ews_init,
1064 .build_controls = snd_ice1712_ews_add_controls,
1065 },
1066 {
1052 .subvendor = ICE1712_SUBDEVICE_EWS88D, 1067 .subvendor = ICE1712_SUBDEVICE_EWS88D,
1053 .name = "TerraTec EWS88D", 1068 .name = "TerraTec EWS88D",
1054 .model = "ews88d", 1069 .model = "ews88d",
diff --git a/sound/pci/ice1712/ews.h b/sound/pci/ice1712/ews.h
index e4ed1b475b08..1c443718af03 100644
--- a/sound/pci/ice1712/ews.h
+++ b/sound/pci/ice1712/ews.h
@@ -30,7 +30,8 @@
30 "{TerraTec,EWS 88MT},"\ 30 "{TerraTec,EWS 88MT},"\
31 "{TerraTec,EWS 88D},"\ 31 "{TerraTec,EWS 88D},"\
32 "{TerraTec,DMX 6Fire},"\ 32 "{TerraTec,DMX 6Fire},"\
33 "{TerraTec,Phase 88}," 33 "{TerraTec,Phase 88}," \
34 "{terrasoniq,TS 88},"
34 35
35#define ICE1712_SUBDEVICE_EWX2496 0x3b153011 36#define ICE1712_SUBDEVICE_EWX2496 0x3b153011
36#define ICE1712_SUBDEVICE_EWS88MT 0x3b151511 37#define ICE1712_SUBDEVICE_EWS88MT 0x3b151511
@@ -38,6 +39,7 @@
38#define ICE1712_SUBDEVICE_EWS88D 0x3b152b11 39#define ICE1712_SUBDEVICE_EWS88D 0x3b152b11
39#define ICE1712_SUBDEVICE_DMX6FIRE 0x3b153811 40#define ICE1712_SUBDEVICE_DMX6FIRE 0x3b153811
40#define ICE1712_SUBDEVICE_PHASE88 0x3b155111 41#define ICE1712_SUBDEVICE_PHASE88 0x3b155111
42#define ICE1712_SUBDEVICE_TS88 0x3b157c11
41 43
42/* entry point */ 44/* entry point */
43extern struct snd_ice1712_card_info snd_ice1712_ews_cards[]; 45extern struct snd_ice1712_card_info snd_ice1712_ews_cards[];
diff --git a/sound/pci/ice1712/hoontech.c b/sound/pci/ice1712/hoontech.c
index cf5c7c0898fd..6914189073a4 100644
--- a/sound/pci/ice1712/hoontech.c
+++ b/sound/pci/ice1712/hoontech.c
@@ -208,6 +208,19 @@ static int __devinit snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
208 /* ICE1712_STDSP24_MUTE | 208 /* ICE1712_STDSP24_MUTE |
209 ICE1712_STDSP24_INSEL | 209 ICE1712_STDSP24_INSEL |
210 ICE1712_STDSP24_DAREAR; */ 210 ICE1712_STDSP24_DAREAR; */
211 /* These boxconfigs have caused problems in the past.
212 * The code is not optimal, but should now enable a working config to
213 * be achieved.
214 * ** MIDI IN can only be configured on one box **
215 * ICE1712_STDSP24_BOX_MIDI1 needs to be set for that box.
216 * Tests on a ADAC2000 box suggest the box config flags do not
217 * work as would be expected, and the inputs are crossed.
218 * Setting ICE1712_STDSP24_BOX_MIDI1 and ICE1712_STDSP24_BOX_MIDI2
219 * on the same box connects MIDI-In to both 401 uarts; both outputs
220 * are then active on all boxes.
221 * The default config here sets up everything on the first box.
222 * Alan Horstmann 5.2.2008
223 */
211 spec->boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 | 224 spec->boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 |
212 ICE1712_STDSP24_BOX_CHN2 | 225 ICE1712_STDSP24_BOX_CHN2 |
213 ICE1712_STDSP24_BOX_CHN3 | 226 ICE1712_STDSP24_BOX_CHN3 |
@@ -223,14 +236,14 @@ static int __devinit snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
223 (spec->config & ICE1712_STDSP24_MUTE) ? 1 : 0); 236 (spec->config & ICE1712_STDSP24_MUTE) ? 1 : 0);
224 snd_ice1712_stdsp24_insel(ice, 237 snd_ice1712_stdsp24_insel(ice,
225 (spec->config & ICE1712_STDSP24_INSEL) ? 1 : 0); 238 (spec->config & ICE1712_STDSP24_INSEL) ? 1 : 0);
226 for (box = 0; box < 1; box++) { 239 for (box = 0; box < 4; box++) {
227 if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2) 240 if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2)
228 snd_ice1712_stdsp24_midi2(ice, 1); 241 snd_ice1712_stdsp24_midi2(ice, 1);
229 for (chn = 0; chn < 4; chn++) 242 for (chn = 0; chn < 4; chn++)
230 snd_ice1712_stdsp24_box_channel(ice, box, chn, 243 snd_ice1712_stdsp24_box_channel(ice, box, chn,
231 (spec->boxconfig[box] & (1 << chn)) ? 1 : 0); 244 (spec->boxconfig[box] & (1 << chn)) ? 1 : 0);
232 snd_ice1712_stdsp24_box_midi(ice, box, 245 if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1)
233 (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1) ? 1 : 0); 246 snd_ice1712_stdsp24_box_midi(ice, box, 1);
234 } 247 }
235 248
236 return 0; 249 return 0;
@@ -322,6 +335,8 @@ struct snd_ice1712_card_info snd_ice1712_hoontech_cards[] __devinitdata = {
322 .name = "Hoontech SoundTrack Audio DSP24", 335 .name = "Hoontech SoundTrack Audio DSP24",
323 .model = "dsp24", 336 .model = "dsp24",
324 .chip_init = snd_ice1712_hoontech_init, 337 .chip_init = snd_ice1712_hoontech_init,
338 .mpu401_1_name = "MIDI-1 Hoontech/STA DSP24",
339 .mpu401_2_name = "MIDI-2 Hoontech/STA DSP24",
325 }, 340 },
326 { 341 {
327 .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */ 342 .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index df292af67381..29d449d73c98 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -1297,11 +1297,14 @@ static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
1297static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1297static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1298{ 1298{
1299 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1299 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1300 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1300 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1301 kcontrol->private_value;
1301 1302
1302 spin_lock_irq(&ice->reg_lock); 1303 spin_lock_irq(&ice->reg_lock);
1303 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1); 1304 ucontrol->value.integer.value[0] =
1304 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1); 1305 !((ice->pro_volumes[priv_idx] >> 15) & 1);
1306 ucontrol->value.integer.value[1] =
1307 !((ice->pro_volumes[priv_idx] >> 31) & 1);
1305 spin_unlock_irq(&ice->reg_lock); 1308 spin_unlock_irq(&ice->reg_lock);
1306 return 0; 1309 return 0;
1307} 1310}
@@ -1309,16 +1312,17 @@ static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struc
1309static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1312static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1310{ 1313{
1311 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1314 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1312 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1315 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1316 kcontrol->private_value;
1313 unsigned int nval, change; 1317 unsigned int nval, change;
1314 1318
1315 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) | 1319 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1316 (ucontrol->value.integer.value[1] ? 0 : 0x80000000); 1320 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1317 spin_lock_irq(&ice->reg_lock); 1321 spin_lock_irq(&ice->reg_lock);
1318 nval |= ice->pro_volumes[index] & ~0x80008000; 1322 nval |= ice->pro_volumes[priv_idx] & ~0x80008000;
1319 change = nval != ice->pro_volumes[index]; 1323 change = nval != ice->pro_volumes[priv_idx];
1320 ice->pro_volumes[index] = nval; 1324 ice->pro_volumes[priv_idx] = nval;
1321 snd_ice1712_update_volume(ice, index); 1325 snd_ice1712_update_volume(ice, priv_idx);
1322 spin_unlock_irq(&ice->reg_lock); 1326 spin_unlock_irq(&ice->reg_lock);
1323 return change; 1327 return change;
1324} 1328}
@@ -1335,11 +1339,14 @@ static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, stru
1335static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1339static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1336{ 1340{
1337 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1341 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1338 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1342 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1343 kcontrol->private_value;
1339 1344
1340 spin_lock_irq(&ice->reg_lock); 1345 spin_lock_irq(&ice->reg_lock);
1341 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127; 1346 ucontrol->value.integer.value[0] =
1342 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127; 1347 (ice->pro_volumes[priv_idx] >> 0) & 127;
1348 ucontrol->value.integer.value[1] =
1349 (ice->pro_volumes[priv_idx] >> 16) & 127;
1343 spin_unlock_irq(&ice->reg_lock); 1350 spin_unlock_irq(&ice->reg_lock);
1344 return 0; 1351 return 0;
1345} 1352}
@@ -1347,16 +1354,17 @@ static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struc
1347static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1354static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1348{ 1355{
1349 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1356 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1350 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1357 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1358 kcontrol->private_value;
1351 unsigned int nval, change; 1359 unsigned int nval, change;
1352 1360
1353 nval = (ucontrol->value.integer.value[0] & 127) | 1361 nval = (ucontrol->value.integer.value[0] & 127) |
1354 ((ucontrol->value.integer.value[1] & 127) << 16); 1362 ((ucontrol->value.integer.value[1] & 127) << 16);
1355 spin_lock_irq(&ice->reg_lock); 1363 spin_lock_irq(&ice->reg_lock);
1356 nval |= ice->pro_volumes[index] & ~0x007f007f; 1364 nval |= ice->pro_volumes[priv_idx] & ~0x007f007f;
1357 change = nval != ice->pro_volumes[index]; 1365 change = nval != ice->pro_volumes[priv_idx];
1358 ice->pro_volumes[index] = nval; 1366 ice->pro_volumes[priv_idx] = nval;
1359 snd_ice1712_update_volume(ice, index); 1367 snd_ice1712_update_volume(ice, priv_idx);
1360 spin_unlock_irq(&ice->reg_lock); 1368 spin_unlock_irq(&ice->reg_lock);
1361 return change; 1369 return change;
1362} 1370}
@@ -2482,10 +2490,9 @@ static int snd_ice1712_free(struct snd_ice1712 *ice)
2482 outb(0xff, ICEREG(ice, IRQMASK)); 2490 outb(0xff, ICEREG(ice, IRQMASK));
2483 /* --- */ 2491 /* --- */
2484 __hw_end: 2492 __hw_end:
2485 if (ice->irq >= 0) { 2493 if (ice->irq >= 0)
2486 synchronize_irq(ice->irq);
2487 free_irq(ice->irq, ice); 2494 free_irq(ice->irq, ice);
2488 } 2495
2489 if (ice->port) 2496 if (ice->port)
2490 pci_release_regions(ice->pci); 2497 pci_release_regions(ice->pci);
2491 snd_ice1712_akm4xxx_free(ice); 2498 snd_ice1712_akm4xxx_free(ice);
diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
index 303cffe08bd8..3208901c740e 100644
--- a/sound/pci/ice1712/ice1712.h
+++ b/sound/pci/ice1712/ice1712.h
@@ -367,6 +367,15 @@ struct snd_ice1712 {
367 367
368 /* other board-specific data */ 368 /* other board-specific data */
369 void *spec; 369 void *spec;
370
371 /* VT172x specific */
372 int pro_rate_default;
373 int (*is_spdif_master)(struct snd_ice1712 *ice);
374 unsigned int (*get_rate)(struct snd_ice1712 *ice);
375 void (*set_rate)(struct snd_ice1712 *ice, unsigned int rate);
376 unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate);
377 void (*set_spdif_clock)(struct snd_ice1712 *ice);
378
370}; 379};
371 380
372 381
@@ -429,10 +438,14 @@ int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
429static inline void snd_ice1712_gpio_write_bits(struct snd_ice1712 *ice, 438static inline void snd_ice1712_gpio_write_bits(struct snd_ice1712 *ice,
430 unsigned int mask, unsigned int bits) 439 unsigned int mask, unsigned int bits)
431{ 440{
441 unsigned val;
442
432 ice->gpio.direction |= mask; 443 ice->gpio.direction |= mask;
433 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction); 444 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
434 snd_ice1712_gpio_set_mask(ice, ~mask); 445 val = snd_ice1712_gpio_read(ice);
435 snd_ice1712_gpio_write(ice, mask & bits); 446 val &= ~mask;
447 val |= mask & bits;
448 snd_ice1712_gpio_write(ice, val);
436} 449}
437 450
438static inline int snd_ice1712_gpio_read_bits(struct snd_ice1712 *ice, 451static inline int snd_ice1712_gpio_read_bits(struct snd_ice1712 *ice,
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index f533850ec6e7..4490422fb930 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -106,15 +106,19 @@ static unsigned int PRO_RATE_DEFAULT = 44100;
106 * Basic I/O 106 * Basic I/O
107 */ 107 */
108 108
109/*
110 * default rates, default clock routines
111 */
112
109/* check whether the clock mode is spdif-in */ 113/* check whether the clock mode is spdif-in */
110static inline int is_spdif_master(struct snd_ice1712 *ice) 114static inline int stdclock_is_spdif_master(struct snd_ice1712 *ice)
111{ 115{
112 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0; 116 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
113} 117}
114 118
115static inline int is_pro_rate_locked(struct snd_ice1712 *ice) 119static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
116{ 120{
117 return is_spdif_master(ice) || PRO_RATE_LOCKED; 121 return ice->is_spdif_master(ice) || PRO_RATE_LOCKED;
118} 122}
119 123
120/* 124/*
@@ -219,6 +223,32 @@ static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
219} 223}
220 224
221/* 225/*
226 * MPU401 accessor
227 */
228static unsigned char snd_vt1724_mpu401_read(struct snd_mpu401 *mpu,
229 unsigned long addr)
230{
231 /* fix status bits to the standard position */
232 /* only RX_EMPTY and TX_FULL are checked */
233 if (addr == MPU401C(mpu))
234 return (inb(addr) & 0x0c) << 4;
235 else
236 return inb(addr);
237}
238
239static void snd_vt1724_mpu401_write(struct snd_mpu401 *mpu,
240 unsigned char data, unsigned long addr)
241{
242 if (addr == MPU401C(mpu)) {
243 if (data == MPU401_ENTER_UART)
244 outb(0x01, addr);
245 /* what else? */
246 } else
247 outb(data, addr);
248}
249
250
251/*
222 * Interrupt handler 252 * Interrupt handler
223 */ 253 */
224 254
@@ -226,24 +256,53 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
226{ 256{
227 struct snd_ice1712 *ice = dev_id; 257 struct snd_ice1712 *ice = dev_id;
228 unsigned char status; 258 unsigned char status;
259 unsigned char status_mask =
260 VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX | VT1724_IRQ_MTPCM;
229 int handled = 0; 261 int handled = 0;
262#ifdef CONFIG_SND_DEBUG
263 int timeout = 0;
264#endif
230 265
231 while (1) { 266 while (1) {
232 status = inb(ICEREG1724(ice, IRQSTAT)); 267 status = inb(ICEREG1724(ice, IRQSTAT));
268 status &= status_mask;
233 if (status == 0) 269 if (status == 0)
234 break; 270 break;
235 271#ifdef CONFIG_SND_DEBUG
272 if (++timeout > 10) {
273 printk(KERN_ERR
274 "ice1724: Too long irq loop, status = 0x%x\n",
275 status);
276 break;
277 }
278#endif
236 handled = 1; 279 handled = 1;
237 /* these should probably be separated at some point, 280 if (status & VT1724_IRQ_MPU_TX) {
238 * but as we don't currently have MPU support on the board 281 if (ice->rmidi[0])
239 * I will leave it 282 snd_mpu401_uart_interrupt_tx(irq,
240 */ 283 ice->rmidi[0]->private_data);
241 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) { 284 else /* disable TX to be sure */
285 outb(inb(ICEREG1724(ice, IRQMASK)) |
286 VT1724_IRQ_MPU_TX,
287 ICEREG1724(ice, IRQMASK));
288 /* Due to mysterical reasons, MPU_TX is always
289 * generated (and can't be cleared) when a PCM
290 * playback is going. So let's ignore at the
291 * next loop.
292 */
293 status_mask &= ~VT1724_IRQ_MPU_TX;
294 }
295 if (status & VT1724_IRQ_MPU_RX) {
242 if (ice->rmidi[0]) 296 if (ice->rmidi[0])
243 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data); 297 snd_mpu401_uart_interrupt(irq,
244 outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT)); 298 ice->rmidi[0]->private_data);
245 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX); 299 else /* disable RX to be sure */
300 outb(inb(ICEREG1724(ice, IRQMASK)) |
301 VT1724_IRQ_MPU_RX,
302 ICEREG1724(ice, IRQMASK));
246 } 303 }
304 /* ack MPU irq */
305 outb(status, ICEREG1724(ice, IRQSTAT));
247 if (status & VT1724_IRQ_MTPCM) { 306 if (status & VT1724_IRQ_MTPCM) {
248 /* 307 /*
249 * Multi-track PCM 308 * Multi-track PCM
@@ -391,51 +450,61 @@ static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
391#define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\ 450#define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
392 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE) 451 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
393 452
394static int get_max_rate(struct snd_ice1712 *ice) 453static const unsigned int stdclock_rate_list[16] = {
454 48000, 24000, 12000, 9600, 32000, 16000, 8000, 96000, 44100,
455 22050, 11025, 88200, 176400, 0, 192000, 64000
456};
457
458static unsigned int stdclock_get_rate(struct snd_ice1712 *ice)
395{ 459{
460 unsigned int rate;
461 rate = stdclock_rate_list[inb(ICEMT1724(ice, RATE)) & 15];
462 return rate;
463}
464
465static void stdclock_set_rate(struct snd_ice1712 *ice, unsigned int rate)
466{
467 int i;
468 for (i = 0; i < ARRAY_SIZE(stdclock_rate_list); i++) {
469 if (stdclock_rate_list[i] == rate) {
470 outb(i, ICEMT1724(ice, RATE));
471 return;
472 }
473 }
474}
475
476static unsigned char stdclock_set_mclk(struct snd_ice1712 *ice,
477 unsigned int rate)
478{
479 unsigned char val, old;
480 /* check MT02 */
396 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { 481 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
397 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720) 482 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
398 return 192000; 483 if (rate > 96000)
484 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
399 else 485 else
400 return 96000; 486 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
401 } else 487 if (val != old) {
402 return 48000; 488 outb(val, ICEMT1724(ice, I2S_FORMAT));
489 /* master clock changed */
490 return 1;
491 }
492 }
493 /* no change in master clock */
494 return 0;
403} 495}
404 496
405static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, 497static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
406 int force) 498 int force)
407{ 499{
408 unsigned long flags; 500 unsigned long flags;
409 unsigned char val, old; 501 unsigned char mclk_change;
410 unsigned int i, mclk_change; 502 unsigned int i, old_rate;
411 503
412 if (rate > get_max_rate(ice)) 504 if (rate > ice->hw_rates->list[ice->hw_rates->count - 1])
413 return; 505 return;
414
415 switch (rate) {
416 case 8000: val = 6; break;
417 case 9600: val = 3; break;
418 case 11025: val = 10; break;
419 case 12000: val = 2; break;
420 case 16000: val = 5; break;
421 case 22050: val = 9; break;
422 case 24000: val = 1; break;
423 case 32000: val = 4; break;
424 case 44100: val = 8; break;
425 case 48000: val = 0; break;
426 case 64000: val = 15; break;
427 case 88200: val = 11; break;
428 case 96000: val = 7; break;
429 case 176400: val = 12; break;
430 case 192000: val = 14; break;
431 default:
432 snd_BUG();
433 val = 0;
434 break;
435 }
436
437 spin_lock_irqsave(&ice->reg_lock, flags); 506 spin_lock_irqsave(&ice->reg_lock, flags);
438 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) || 507 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
439 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) { 508 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
440 /* running? we cannot change the rate now... */ 509 /* running? we cannot change the rate now... */
441 spin_unlock_irqrestore(&ice->reg_lock, flags); 510 spin_unlock_irqrestore(&ice->reg_lock, flags);
@@ -446,9 +515,9 @@ static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
446 return; 515 return;
447 } 516 }
448 517
449 old = inb(ICEMT1724(ice, RATE)); 518 old_rate = ice->get_rate(ice);
450 if (force || old != val) 519 if (force || (old_rate != rate))
451 outb(val, ICEMT1724(ice, RATE)); 520 ice->set_rate(ice, rate);
452 else if (rate == ice->cur_rate) { 521 else if (rate == ice->cur_rate) {
453 spin_unlock_irqrestore(&ice->reg_lock, flags); 522 spin_unlock_irqrestore(&ice->reg_lock, flags);
454 return; 523 return;
@@ -456,19 +525,9 @@ static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
456 525
457 ice->cur_rate = rate; 526 ice->cur_rate = rate;
458 527
459 /* check MT02 */ 528 /* setting master clock */
460 mclk_change = 0; 529 mclk_change = ice->set_mclk(ice, rate);
461 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { 530
462 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
463 if (rate > 96000)
464 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
465 else
466 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
467 if (val != old) {
468 outb(val, ICEMT1724(ice, I2S_FORMAT));
469 mclk_change = 1;
470 }
471 }
472 spin_unlock_irqrestore(&ice->reg_lock, flags); 531 spin_unlock_irqrestore(&ice->reg_lock, flags);
473 532
474 if (mclk_change && ice->gpio.i2s_mclk_changed) 533 if (mclk_change && ice->gpio.i2s_mclk_changed)
@@ -727,43 +786,32 @@ static const struct snd_pcm_hardware snd_vt1724_2ch_stereo =
727/* 786/*
728 * set rate constraints 787 * set rate constraints
729 */ 788 */
730static int set_rate_constraints(struct snd_ice1712 *ice, 789static void set_std_hw_rates(struct snd_ice1712 *ice)
731 struct snd_pcm_substream *substream)
732{ 790{
733 struct snd_pcm_runtime *runtime = substream->runtime;
734 if (ice->hw_rates) {
735 /* hardware specific */
736 runtime->hw.rate_min = ice->hw_rates->list[0];
737 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
738 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
739 return snd_pcm_hw_constraint_list(runtime, 0,
740 SNDRV_PCM_HW_PARAM_RATE,
741 ice->hw_rates);
742 }
743 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { 791 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
744 /* I2S */ 792 /* I2S */
745 /* VT1720 doesn't support more than 96kHz */ 793 /* VT1720 doesn't support more than 96kHz */
746 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720) 794 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
747 return snd_pcm_hw_constraint_list(runtime, 0, 795 ice->hw_rates = &hw_constraints_rates_192;
748 SNDRV_PCM_HW_PARAM_RATE, 796 else
749 &hw_constraints_rates_192); 797 ice->hw_rates = &hw_constraints_rates_96;
750 else { 798 } else {
751 runtime->hw.rates = SNDRV_PCM_RATE_KNOT |
752 SNDRV_PCM_RATE_8000_96000;
753 runtime->hw.rate_max = 96000;
754 return snd_pcm_hw_constraint_list(runtime, 0,
755 SNDRV_PCM_HW_PARAM_RATE,
756 &hw_constraints_rates_96);
757 }
758 } else if (ice->ac97) {
759 /* ACLINK */ 799 /* ACLINK */
760 runtime->hw.rate_max = 48000; 800 ice->hw_rates = &hw_constraints_rates_48;
761 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
762 return snd_pcm_hw_constraint_list(runtime, 0,
763 SNDRV_PCM_HW_PARAM_RATE,
764 &hw_constraints_rates_48);
765 } 801 }
766 return 0; 802}
803
804static int set_rate_constraints(struct snd_ice1712 *ice,
805 struct snd_pcm_substream *substream)
806{
807 struct snd_pcm_runtime *runtime = substream->runtime;
808
809 runtime->hw.rate_min = ice->hw_rates->list[0];
810 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
811 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
812 return snd_pcm_hw_constraint_list(runtime, 0,
813 SNDRV_PCM_HW_PARAM_RATE,
814 ice->hw_rates);
767} 815}
768 816
769/* multi-channel playback needs alignment 8x32bit regardless of the channels 817/* multi-channel playback needs alignment 8x32bit regardless of the channels
@@ -824,7 +872,7 @@ static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
824 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 872 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
825 873
826 if (PRO_RATE_RESET) 874 if (PRO_RATE_RESET)
827 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 875 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
828 ice->playback_pro_substream = NULL; 876 ice->playback_pro_substream = NULL;
829 877
830 return 0; 878 return 0;
@@ -835,7 +883,7 @@ static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
835 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 883 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
836 884
837 if (PRO_RATE_RESET) 885 if (PRO_RATE_RESET)
838 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 886 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
839 ice->capture_pro_substream = NULL; 887 ice->capture_pro_substream = NULL;
840 return 0; 888 return 0;
841} 889}
@@ -970,6 +1018,8 @@ static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
970 VT1724_BUFFER_ALIGN); 1018 VT1724_BUFFER_ALIGN);
971 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1019 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
972 VT1724_BUFFER_ALIGN); 1020 VT1724_BUFFER_ALIGN);
1021 if (ice->spdif.ops.open)
1022 ice->spdif.ops.open(ice, substream);
973 return 0; 1023 return 0;
974} 1024}
975 1025
@@ -978,8 +1028,10 @@ static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
978 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 1028 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
979 1029
980 if (PRO_RATE_RESET) 1030 if (PRO_RATE_RESET)
981 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 1031 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
982 ice->playback_con_substream = NULL; 1032 ice->playback_con_substream = NULL;
1033 if (ice->spdif.ops.close)
1034 ice->spdif.ops.close(ice, substream);
983 1035
984 return 0; 1036 return 0;
985} 1037}
@@ -1002,6 +1054,8 @@ static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
1002 VT1724_BUFFER_ALIGN); 1054 VT1724_BUFFER_ALIGN);
1003 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1055 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1004 VT1724_BUFFER_ALIGN); 1056 VT1724_BUFFER_ALIGN);
1057 if (ice->spdif.ops.open)
1058 ice->spdif.ops.open(ice, substream);
1005 return 0; 1059 return 0;
1006} 1060}
1007 1061
@@ -1010,8 +1064,10 @@ static int snd_vt1724_capture_spdif_close(struct snd_pcm_substream *substream)
1010 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 1064 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1011 1065
1012 if (PRO_RATE_RESET) 1066 if (PRO_RATE_RESET)
1013 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 1067 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
1014 ice->capture_con_substream = NULL; 1068 ice->capture_con_substream = NULL;
1069 if (ice->spdif.ops.close)
1070 ice->spdif.ops.close(ice, substream);
1015 1071
1016 return 0; 1072 return 0;
1017} 1073}
@@ -1154,7 +1210,7 @@ static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
1154 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 1210 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1155 1211
1156 if (PRO_RATE_RESET) 1212 if (PRO_RATE_RESET)
1157 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 1213 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
1158 ice->playback_con_substream_ds[substream->number] = NULL; 1214 ice->playback_con_substream_ds[substream->number] = NULL;
1159 ice->pcm_reserved[substream->number] = NULL; 1215 ice->pcm_reserved[substream->number] = NULL;
1160 1216
@@ -1572,50 +1628,18 @@ int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1572static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol, 1628static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1573 struct snd_ctl_elem_info *uinfo) 1629 struct snd_ctl_elem_info *uinfo)
1574{ 1630{
1575 static const char * const texts_1724[] = {
1576 "8000", /* 0: 6 */
1577 "9600", /* 1: 3 */
1578 "11025", /* 2: 10 */
1579 "12000", /* 3: 2 */
1580 "16000", /* 4: 5 */
1581 "22050", /* 5: 9 */
1582 "24000", /* 6: 1 */
1583 "32000", /* 7: 4 */
1584 "44100", /* 8: 8 */
1585 "48000", /* 9: 0 */
1586 "64000", /* 10: 15 */
1587 "88200", /* 11: 11 */
1588 "96000", /* 12: 7 */
1589 "176400", /* 13: 12 */
1590 "192000", /* 14: 14 */
1591 "IEC958 Input", /* 15: -- */
1592 };
1593 static const char * const texts_1720[] = {
1594 "8000", /* 0: 6 */
1595 "9600", /* 1: 3 */
1596 "11025", /* 2: 10 */
1597 "12000", /* 3: 2 */
1598 "16000", /* 4: 5 */
1599 "22050", /* 5: 9 */
1600 "24000", /* 6: 1 */
1601 "32000", /* 7: 4 */
1602 "44100", /* 8: 8 */
1603 "48000", /* 9: 0 */
1604 "64000", /* 10: 15 */
1605 "88200", /* 11: 11 */
1606 "96000", /* 12: 7 */
1607 "IEC958 Input", /* 13: -- */
1608 };
1609 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1631 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1610 1632
1611 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1633 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1612 uinfo->count = 1; 1634 uinfo->count = 1;
1613 uinfo->value.enumerated.items = ice->vt1720 ? 14 : 16; 1635 uinfo->value.enumerated.items = ice->hw_rates->count + 1;
1614 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 1636 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1615 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1637 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1616 strcpy(uinfo->value.enumerated.name, 1638 if (uinfo->value.enumerated.item == uinfo->value.enumerated.items - 1)
1617 ice->vt1720 ? texts_1720[uinfo->value.enumerated.item] : 1639 strcpy(uinfo->value.enumerated.name, "IEC958 Input");
1618 texts_1724[uinfo->value.enumerated.item]); 1640 else
1641 sprintf(uinfo->value.enumerated.name, "%d",
1642 ice->hw_rates->list[uinfo->value.enumerated.item]);
1619 return 0; 1643 return 0;
1620} 1644}
1621 1645
@@ -1623,68 +1647,79 @@ static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1623 struct snd_ctl_elem_value *ucontrol) 1647 struct snd_ctl_elem_value *ucontrol)
1624{ 1648{
1625 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1649 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1626 static const unsigned char xlate[16] = { 1650 unsigned int i, rate;
1627 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1628 };
1629 unsigned char val;
1630 1651
1631 spin_lock_irq(&ice->reg_lock); 1652 spin_lock_irq(&ice->reg_lock);
1632 if (is_spdif_master(ice)) { 1653 if (ice->is_spdif_master(ice)) {
1633 ucontrol->value.enumerated.item[0] = ice->vt1720 ? 13 : 15; 1654 ucontrol->value.enumerated.item[0] = ice->hw_rates->count;
1634 } else { 1655 } else {
1635 val = xlate[inb(ICEMT1724(ice, RATE)) & 15]; 1656 rate = ice->get_rate(ice);
1636 if (val == 255) { 1657 ucontrol->value.enumerated.item[0] = 0;
1637 snd_BUG(); 1658 for (i = 0; i < ice->hw_rates->count; i++) {
1638 val = 0; 1659 if (ice->hw_rates->list[i] == rate) {
1660 ucontrol->value.enumerated.item[0] = i;
1661 break;
1662 }
1639 } 1663 }
1640 ucontrol->value.enumerated.item[0] = val;
1641 } 1664 }
1642 spin_unlock_irq(&ice->reg_lock); 1665 spin_unlock_irq(&ice->reg_lock);
1643 return 0; 1666 return 0;
1644} 1667}
1645 1668
1669/* setting clock to external - SPDIF */
1670static void stdclock_set_spdif_clock(struct snd_ice1712 *ice)
1671{
1672 unsigned char oval;
1673 unsigned char i2s_oval;
1674 oval = inb(ICEMT1724(ice, RATE));
1675 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1676 /* setting 256fs */
1677 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
1678 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT));
1679}
1680
1646static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol, 1681static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1647 struct snd_ctl_elem_value *ucontrol) 1682 struct snd_ctl_elem_value *ucontrol)
1648{ 1683{
1649 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1684 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1650 unsigned char oval; 1685 unsigned int old_rate, new_rate;
1651 int rate; 1686 unsigned int item = ucontrol->value.enumerated.item[0];
1652 int change = 0; 1687 unsigned int spdif = ice->hw_rates->count;
1653 int spdif = ice->vt1720 ? 13 : 15; 1688
1689 if (item > spdif)
1690 return -EINVAL;
1654 1691
1655 spin_lock_irq(&ice->reg_lock); 1692 spin_lock_irq(&ice->reg_lock);
1656 oval = inb(ICEMT1724(ice, RATE)); 1693 if (ice->is_spdif_master(ice))
1657 if (ucontrol->value.enumerated.item[0] == spdif) { 1694 old_rate = 0;
1658 unsigned char i2s_oval; 1695 else
1659 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE)); 1696 old_rate = ice->get_rate(ice);
1660 /* setting 256fs */ 1697 if (item == spdif) {
1661 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT)); 1698 /* switching to external clock via SPDIF */
1662 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, 1699 ice->set_spdif_clock(ice);
1663 ICEMT1724(ice, I2S_FORMAT)); 1700 new_rate = 0;
1664 } else { 1701 } else {
1665 rate = rates[ucontrol->value.integer.value[0] % 15]; 1702 /* internal on-card clock */
1666 if (rate <= get_max_rate(ice)) { 1703 new_rate = ice->hw_rates->list[item];
1667 PRO_RATE_DEFAULT = rate; 1704 ice->pro_rate_default = new_rate;
1668 spin_unlock_irq(&ice->reg_lock); 1705 spin_unlock_irq(&ice->reg_lock);
1669 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1); 1706 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1);
1670 spin_lock_irq(&ice->reg_lock); 1707 spin_lock_irq(&ice->reg_lock);
1671 }
1672 } 1708 }
1673 change = inb(ICEMT1724(ice, RATE)) != oval;
1674 spin_unlock_irq(&ice->reg_lock); 1709 spin_unlock_irq(&ice->reg_lock);
1675 1710
1676 if ((oval & VT1724_SPDIF_MASTER) != 1711 /* the first reset to the SPDIF master mode? */
1677 (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) { 1712 if (old_rate != new_rate && !new_rate) {
1678 /* notify akm chips as well */ 1713 /* notify akm chips as well */
1679 if (is_spdif_master(ice)) { 1714 unsigned int i;
1680 unsigned int i; 1715 if (ice->gpio.set_pro_rate)
1681 for (i = 0; i < ice->akm_codecs; i++) { 1716 ice->gpio.set_pro_rate(ice, 0);
1682 if (ice->akm[i].ops.set_rate_val) 1717 for (i = 0; i < ice->akm_codecs; i++) {
1683 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0); 1718 if (ice->akm[i].ops.set_rate_val)
1684 } 1719 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1685 } 1720 }
1686 } 1721 }
1687 return change; 1722 return old_rate != new_rate;
1688} 1723}
1689 1724
1690static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = { 1725static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
@@ -2065,12 +2100,16 @@ static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
2065 2100
2066 2101
2067 2102
2068static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice) 2103static void __devinit snd_vt1724_chip_reset(struct snd_ice1712 *ice)
2069{ 2104{
2070 outb(VT1724_RESET , ICEREG1724(ice, CONTROL)); 2105 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
2071 udelay(200); 2106 msleep(10);
2072 outb(0, ICEREG1724(ice, CONTROL)); 2107 outb(0, ICEREG1724(ice, CONTROL));
2073 udelay(200); 2108 msleep(10);
2109}
2110
2111static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
2112{
2074 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG)); 2113 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
2075 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG)); 2114 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
2076 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES)); 2115 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
@@ -2169,10 +2208,8 @@ static int snd_vt1724_free(struct snd_ice1712 *ice)
2169 outb(0xff, ICEREG1724(ice, IRQMASK)); 2208 outb(0xff, ICEREG1724(ice, IRQMASK));
2170 /* --- */ 2209 /* --- */
2171 __hw_end: 2210 __hw_end:
2172 if (ice->irq >= 0) { 2211 if (ice->irq >= 0)
2173 synchronize_irq(ice->irq);
2174 free_irq(ice->irq, ice); 2212 free_irq(ice->irq, ice);
2175 }
2176 pci_release_regions(ice->pci); 2213 pci_release_regions(ice->pci);
2177 snd_ice1712_akm4xxx_free(ice); 2214 snd_ice1712_akm4xxx_free(ice);
2178 pci_disable_device(ice->pci); 2215 pci_disable_device(ice->pci);
@@ -2243,6 +2280,7 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2243 2280
2244 ice->irq = pci->irq; 2281 ice->irq = pci->irq;
2245 2282
2283 snd_vt1724_chip_reset(ice);
2246 if (snd_vt1724_read_eeprom(ice, modelname) < 0) { 2284 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2247 snd_vt1724_free(ice); 2285 snd_vt1724_free(ice);
2248 return -EIO; 2286 return -EIO;
@@ -2253,10 +2291,7 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2253 } 2291 }
2254 2292
2255 /* unmask used interrupts */ 2293 /* unmask used interrupts */
2256 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401)) 2294 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2257 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2258 else
2259 mask = 0;
2260 outb(mask, ICEREG1724(ice, IRQMASK)); 2295 outb(mask, ICEREG1724(ice, IRQMASK));
2261 /* don't handle FIFO overrun/underruns (just yet), 2296 /* don't handle FIFO overrun/underruns (just yet),
2262 * since they cause machine lockups 2297 * since they cause machine lockups
@@ -2335,6 +2370,19 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2335 * was called so in ice1712 driver, and vt1724 driver is derived from 2370 * was called so in ice1712 driver, and vt1724 driver is derived from
2336 * ice1712 driver. 2371 * ice1712 driver.
2337 */ 2372 */
2373 ice->pro_rate_default = PRO_RATE_DEFAULT;
2374 if (!ice->is_spdif_master)
2375 ice->is_spdif_master = stdclock_is_spdif_master;
2376 if (!ice->get_rate)
2377 ice->get_rate = stdclock_get_rate;
2378 if (!ice->set_rate)
2379 ice->set_rate = stdclock_set_rate;
2380 if (!ice->set_mclk)
2381 ice->set_mclk = stdclock_set_mclk;
2382 if (!ice->set_spdif_clock)
2383 ice->set_spdif_clock = stdclock_set_spdif_clock;
2384 if (!ice->hw_rates)
2385 set_std_hw_rates(ice);
2338 2386
2339 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) { 2387 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2340 snd_card_free(card); 2388 snd_card_free(card);
@@ -2377,14 +2425,29 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2377 2425
2378 if (! c->no_mpu401) { 2426 if (! c->no_mpu401) {
2379 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) { 2427 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2428 struct snd_mpu401 *mpu;
2380 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712, 2429 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2381 ICEREG1724(ice, MPU_CTRL), 2430 ICEREG1724(ice, MPU_CTRL),
2382 MPU401_INFO_INTEGRATED, 2431 (MPU401_INFO_INTEGRATED |
2432 MPU401_INFO_TX_IRQ),
2383 ice->irq, 0, 2433 ice->irq, 0,
2384 &ice->rmidi[0])) < 0) { 2434 &ice->rmidi[0])) < 0) {
2385 snd_card_free(card); 2435 snd_card_free(card);
2386 return err; 2436 return err;
2387 } 2437 }
2438 mpu = ice->rmidi[0]->private_data;
2439 mpu->read = snd_vt1724_mpu401_read;
2440 mpu->write = snd_vt1724_mpu401_write;
2441 /* unmask MPU RX/TX irqs */
2442 outb(inb(ICEREG1724(ice, IRQMASK)) &
2443 ~(VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX),
2444 ICEREG1724(ice, IRQMASK));
2445#if 0 /* for testing */
2446 /* set watermarks */
2447 outb(VT1724_MPU_RX_FIFO | 0x1,
2448 ICEREG1724(ice, MPU_FIFO_WM));
2449 outb(0x1, ICEREG1724(ice, MPU_FIFO_WM));
2450#endif
2388 } 2451 }
2389 } 2452 }
2390 2453
diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c
index e8038c0ceb72..b4e0c16852a6 100644
--- a/sound/pci/ice1712/juli.c
+++ b/sound/pci/ice1712/juli.c
@@ -4,6 +4,8 @@
4 * Lowlevel functions for ESI Juli@ cards 4 * Lowlevel functions for ESI Juli@ cards
5 * 5 *
6 * Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz> 6 * Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz>
7 * 2008 Pavel Hofman <dustin@seznam.cz>
8 *
7 * 9 *
8 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
@@ -27,11 +29,11 @@
27#include <linux/init.h> 29#include <linux/init.h>
28#include <linux/slab.h> 30#include <linux/slab.h>
29#include <sound/core.h> 31#include <sound/core.h>
32#include <sound/tlv.h>
30 33
31#include "ice1712.h" 34#include "ice1712.h"
32#include "envy24ht.h" 35#include "envy24ht.h"
33#include "juli.h" 36#include "juli.h"
34
35struct juli_spec { 37struct juli_spec {
36 struct ak4114 *ak4114; 38 struct ak4114 *ak4114;
37 unsigned int analog: 1; 39 unsigned int analog: 1;
@@ -44,6 +46,32 @@ struct juli_spec {
44#define AK4358_ADDR 0x22 /* DAC */ 46#define AK4358_ADDR 0x22 /* DAC */
45 47
46/* 48/*
49 * Juli does not use the standard ICE1724 clock scheme. Juli's ice1724 chip is
50 * supplied by external clock provided by Xilinx array and MK73-1 PLL frequency
51 * multiplier. Actual frequency is set by ice1724 GPIOs hooked to the Xilinx.
52 *
53 * The clock circuitry is supplied by the two ice1724 crystals. This
54 * arrangement allows to generate independent clock signal for AK4114's input
55 * rate detection circuit. As a result, Juli, unlike most other
56 * ice1724+ak4114-based cards, detects spdif input rate correctly.
57 * This fact is applied in the driver, allowing to modify PCM stream rate
58 * parameter according to the actual input rate.
59 *
60 * Juli uses the remaining three stereo-channels of its DAC to optionally
61 * monitor analog input, digital input, and digital output. The corresponding
62 * I2S signals are routed by Xilinx, controlled by GPIOs.
63 *
64 * The master mute is implemented using output muting transistors (GPIO) in
65 * combination with smuting the DAC.
66 *
67 * The card itself has no HW master volume control, implemented using the
68 * vmaster control.
69 *
70 * TODO:
71 * researching and fixing the input monitors
72 */
73
74/*
47 * GPIO pins 75 * GPIO pins
48 */ 76 */
49#define GPIO_FREQ_MASK (3<<0) 77#define GPIO_FREQ_MASK (3<<0)
@@ -55,17 +83,82 @@ struct juli_spec {
55#define GPIO_MULTI_2X (1<<2) 83#define GPIO_MULTI_2X (1<<2)
56#define GPIO_MULTI_1X (2<<2) /* also external */ 84#define GPIO_MULTI_1X (2<<2) /* also external */
57#define GPIO_MULTI_HALF (3<<2) 85#define GPIO_MULTI_HALF (3<<2)
58#define GPIO_INTERNAL_CLOCK (1<<4) 86#define GPIO_INTERNAL_CLOCK (1<<4) /* 0 = external, 1 = internal */
87#define GPIO_CLOCK_MASK (1<<4)
59#define GPIO_ANALOG_PRESENT (1<<5) /* RO only: 0 = present */ 88#define GPIO_ANALOG_PRESENT (1<<5) /* RO only: 0 = present */
60#define GPIO_RXMCLK_SEL (1<<7) /* must be 0 */ 89#define GPIO_RXMCLK_SEL (1<<7) /* must be 0 */
61#define GPIO_AK5385A_CKS0 (1<<8) 90#define GPIO_AK5385A_CKS0 (1<<8)
62#define GPIO_AK5385A_DFS0 (1<<9) /* swapped with DFS1 according doc? */ 91#define GPIO_AK5385A_DFS1 (1<<9)
63#define GPIO_AK5385A_DFS1 (1<<10) 92#define GPIO_AK5385A_DFS0 (1<<10)
64#define GPIO_DIGOUT_MONITOR (1<<11) /* 1 = active */ 93#define GPIO_DIGOUT_MONITOR (1<<11) /* 1 = active */
65#define GPIO_DIGIN_MONITOR (1<<12) /* 1 = active */ 94#define GPIO_DIGIN_MONITOR (1<<12) /* 1 = active */
66#define GPIO_ANAIN_MONITOR (1<<13) /* 1 = active */ 95#define GPIO_ANAIN_MONITOR (1<<13) /* 1 = active */
67#define GPIO_AK5385A_MCLK (1<<14) /* must be 0 */ 96#define GPIO_AK5385A_CKS1 (1<<14) /* must be 0 */
68#define GPIO_MUTE_CONTROL (1<<15) /* 0 = off, 1 = on */ 97#define GPIO_MUTE_CONTROL (1<<15) /* output mute, 1 = muted */
98
99#define GPIO_RATE_MASK (GPIO_FREQ_MASK | GPIO_MULTI_MASK | \
100 GPIO_CLOCK_MASK)
101#define GPIO_AK5385A_MASK (GPIO_AK5385A_CKS0 | GPIO_AK5385A_DFS0 | \
102 GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS1)
103
104#define JULI_PCM_RATE (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
105 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
106 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
107 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \
108 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000)
109
110#define GPIO_RATE_16000 (GPIO_FREQ_32KHZ | GPIO_MULTI_HALF | \
111 GPIO_INTERNAL_CLOCK)
112#define GPIO_RATE_22050 (GPIO_FREQ_44KHZ | GPIO_MULTI_HALF | \
113 GPIO_INTERNAL_CLOCK)
114#define GPIO_RATE_24000 (GPIO_FREQ_48KHZ | GPIO_MULTI_HALF | \
115 GPIO_INTERNAL_CLOCK)
116#define GPIO_RATE_32000 (GPIO_FREQ_32KHZ | GPIO_MULTI_1X | \
117 GPIO_INTERNAL_CLOCK)
118#define GPIO_RATE_44100 (GPIO_FREQ_44KHZ | GPIO_MULTI_1X | \
119 GPIO_INTERNAL_CLOCK)
120#define GPIO_RATE_48000 (GPIO_FREQ_48KHZ | GPIO_MULTI_1X | \
121 GPIO_INTERNAL_CLOCK)
122#define GPIO_RATE_64000 (GPIO_FREQ_32KHZ | GPIO_MULTI_2X | \
123 GPIO_INTERNAL_CLOCK)
124#define GPIO_RATE_88200 (GPIO_FREQ_44KHZ | GPIO_MULTI_2X | \
125 GPIO_INTERNAL_CLOCK)
126#define GPIO_RATE_96000 (GPIO_FREQ_48KHZ | GPIO_MULTI_2X | \
127 GPIO_INTERNAL_CLOCK)
128#define GPIO_RATE_176400 (GPIO_FREQ_44KHZ | GPIO_MULTI_4X | \
129 GPIO_INTERNAL_CLOCK)
130#define GPIO_RATE_192000 (GPIO_FREQ_48KHZ | GPIO_MULTI_4X | \
131 GPIO_INTERNAL_CLOCK)
132
133/*
134 * Initial setup of the conversion array GPIO <-> rate
135 */
136static unsigned int juli_rates[] = {
137 16000, 22050, 24000, 32000,
138 44100, 48000, 64000, 88200,
139 96000, 176400, 192000,
140};
141
142static unsigned int gpio_vals[] = {
143 GPIO_RATE_16000, GPIO_RATE_22050, GPIO_RATE_24000, GPIO_RATE_32000,
144 GPIO_RATE_44100, GPIO_RATE_48000, GPIO_RATE_64000, GPIO_RATE_88200,
145 GPIO_RATE_96000, GPIO_RATE_176400, GPIO_RATE_192000,
146};
147
148static struct snd_pcm_hw_constraint_list juli_rates_info = {
149 .count = ARRAY_SIZE(juli_rates),
150 .list = juli_rates,
151 .mask = 0,
152};
153
154static int get_gpio_val(int rate)
155{
156 int i;
157 for (i = 0; i < ARRAY_SIZE(juli_rates); i++)
158 if (juli_rates[i] == rate)
159 return gpio_vals[i];
160 return 0;
161}
69 162
70static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val) 163static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val)
71{ 164{
@@ -78,6 +171,27 @@ static unsigned char juli_ak4114_read(void *private_data, unsigned char reg)
78} 171}
79 172
80/* 173/*
174 * If SPDIF capture and slaved to SPDIF-IN, setting runtime rate
175 * to the external rate
176 */
177static void juli_spdif_in_open(struct snd_ice1712 *ice,
178 struct snd_pcm_substream *substream)
179{
180 struct juli_spec *spec = ice->spec;
181 struct snd_pcm_runtime *runtime = substream->runtime;
182 int rate;
183
184 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
185 !ice->is_spdif_master(ice))
186 return;
187 rate = snd_ak4114_external_rate(spec->ak4114);
188 if (rate >= runtime->hw.rate_min && rate <= runtime->hw.rate_max) {
189 runtime->hw.rate_min = rate;
190 runtime->hw.rate_max = rate;
191 }
192}
193
194/*
81 * AK4358 section 195 * AK4358 section
82 */ 196 */
83 197
@@ -99,57 +213,285 @@ static void juli_akm_write(struct snd_akm4xxx *ak, int chip,
99} 213}
100 214
101/* 215/*
102 * change the rate of envy24HT, AK4358 216 * change the rate of envy24HT, AK4358, AK5385
103 */ 217 */
104static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) 218static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
105{ 219{
106 unsigned char old, tmp, dfs; 220 unsigned char old, tmp, ak4358_dfs;
221 unsigned int ak5385_pins, old_gpio, new_gpio;
222 struct snd_ice1712 *ice = ak->private_data[0];
223 struct juli_spec *spec = ice->spec;
107 224
108 if (rate == 0) /* no hint - S/PDIF input is master, simply return */ 225 if (rate == 0) /* no hint - S/PDIF input is master or the new spdif
226 input rate undetected, simply return */
109 return; 227 return;
110 228
111 /* adjust DFS on codecs */ 229 /* adjust DFS on codecs */
112 if (rate > 96000) 230 if (rate > 96000) {
113 dfs = 2; 231 ak4358_dfs = 2;
114 else if (rate > 48000) 232 ak5385_pins = GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS0;
115 dfs = 1; 233 } else if (rate > 48000) {
116 else 234 ak4358_dfs = 1;
117 dfs = 0; 235 ak5385_pins = GPIO_AK5385A_DFS0;
118 236 } else {
237 ak4358_dfs = 0;
238 ak5385_pins = 0;
239 }
240 /* AK5385 first, since it requires cold reset affecting both codecs */
241 old_gpio = ice->gpio.get_data(ice);
242 new_gpio = (old_gpio & ~GPIO_AK5385A_MASK) | ak5385_pins;
243 /* printk(KERN_DEBUG "JULI - ak5385 set_rate_val: new gpio 0x%x\n",
244 new_gpio); */
245 ice->gpio.set_data(ice, new_gpio);
246
247 /* cold reset */
248 old = inb(ICEMT1724(ice, AC97_CMD));
249 outb(old | VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD));
250 udelay(1);
251 outb(old & ~VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD));
252
253 /* AK4358 */
254 /* set new value, reset DFS */
119 tmp = snd_akm4xxx_get(ak, 0, 2); 255 tmp = snd_akm4xxx_get(ak, 0, 2);
120 old = (tmp >> 4) & 0x03;
121 if (old == dfs)
122 return;
123 /* reset DFS */
124 snd_akm4xxx_reset(ak, 1); 256 snd_akm4xxx_reset(ak, 1);
125 tmp = snd_akm4xxx_get(ak, 0, 2); 257 tmp = snd_akm4xxx_get(ak, 0, 2);
126 tmp &= ~(0x03 << 4); 258 tmp &= ~(0x03 << 4);
127 tmp |= dfs << 4; 259 tmp |= ak4358_dfs << 4;
128 snd_akm4xxx_set(ak, 0, 2, tmp); 260 snd_akm4xxx_set(ak, 0, 2, tmp);
129 snd_akm4xxx_reset(ak, 0); 261 snd_akm4xxx_reset(ak, 0);
262
263 /* reinit ak4114 */
264 snd_ak4114_reinit(spec->ak4114);
130} 265}
131 266
267#define AK_DAC(xname, xch) { .name = xname, .num_channels = xch }
268#define PCM_VOLUME "PCM Playback Volume"
269#define MONITOR_AN_IN_VOLUME "Monitor Analog In Volume"
270#define MONITOR_DIG_IN_VOLUME "Monitor Digital In Volume"
271#define MONITOR_DIG_OUT_VOLUME "Monitor Digital Out Volume"
272
273static const struct snd_akm4xxx_dac_channel juli_dac[] = {
274 AK_DAC(PCM_VOLUME, 2),
275 AK_DAC(MONITOR_AN_IN_VOLUME, 2),
276 AK_DAC(MONITOR_DIG_OUT_VOLUME, 2),
277 AK_DAC(MONITOR_DIG_IN_VOLUME, 2),
278};
279
280
132static struct snd_akm4xxx akm_juli_dac __devinitdata = { 281static struct snd_akm4xxx akm_juli_dac __devinitdata = {
133 .type = SND_AK4358, 282 .type = SND_AK4358,
134 .num_dacs = 2, 283 .num_dacs = 8, /* DAC1 - analog out
284 DAC2 - analog in monitor
285 DAC3 - digital out monitor
286 DAC4 - digital in monitor
287 */
135 .ops = { 288 .ops = {
136 .lock = juli_akm_lock, 289 .lock = juli_akm_lock,
137 .unlock = juli_akm_unlock, 290 .unlock = juli_akm_unlock,
138 .write = juli_akm_write, 291 .write = juli_akm_write,
139 .set_rate_val = juli_akm_set_rate_val 292 .set_rate_val = juli_akm_set_rate_val
293 },
294 .dac_info = juli_dac,
295};
296
297#define juli_mute_info snd_ctl_boolean_mono_info
298
299static int juli_mute_get(struct snd_kcontrol *kcontrol,
300 struct snd_ctl_elem_value *ucontrol)
301{
302 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
303 unsigned int val;
304 val = ice->gpio.get_data(ice) & (unsigned int) kcontrol->private_value;
305 if (kcontrol->private_value == GPIO_MUTE_CONTROL)
306 /* val 0 = signal on */
307 ucontrol->value.integer.value[0] = (val) ? 0 : 1;
308 else
309 /* val 1 = signal on */
310 ucontrol->value.integer.value[0] = (val) ? 1 : 0;
311 return 0;
312}
313
314static int juli_mute_put(struct snd_kcontrol *kcontrol,
315 struct snd_ctl_elem_value *ucontrol)
316{
317 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
318 unsigned int old_gpio, new_gpio;
319 old_gpio = ice->gpio.get_data(ice);
320 if (ucontrol->value.integer.value[0]) {
321 /* unmute */
322 if (kcontrol->private_value == GPIO_MUTE_CONTROL) {
323 /* 0 = signal on */
324 new_gpio = old_gpio & ~GPIO_MUTE_CONTROL;
325 /* un-smuting DAC */
326 snd_akm4xxx_write(ice->akm, 0, 0x01, 0x01);
327 } else
328 /* 1 = signal on */
329 new_gpio = old_gpio |
330 (unsigned int) kcontrol->private_value;
331 } else {
332 /* mute */
333 if (kcontrol->private_value == GPIO_MUTE_CONTROL) {
334 /* 1 = signal off */
335 new_gpio = old_gpio | GPIO_MUTE_CONTROL;
336 /* smuting DAC */
337 snd_akm4xxx_write(ice->akm, 0, 0x01, 0x03);
338 } else
339 /* 0 = signal off */
340 new_gpio = old_gpio &
341 ~((unsigned int) kcontrol->private_value);
342 }
343 /* printk("JULI - mute/unmute: control_value: 0x%x, old_gpio: 0x%x, \
344 new_gpio 0x%x\n",
345 (unsigned int)ucontrol->value.integer.value[0], old_gpio,
346 new_gpio); */
347 if (old_gpio != new_gpio) {
348 ice->gpio.set_data(ice, new_gpio);
349 return 1;
350 }
351 /* no change */
352 return 0;
353}
354
355static struct snd_kcontrol_new juli_mute_controls[] __devinitdata = {
356 {
357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
358 .name = "Master Playback Switch",
359 .info = juli_mute_info,
360 .get = juli_mute_get,
361 .put = juli_mute_put,
362 .private_value = GPIO_MUTE_CONTROL,
363 },
364 /* Although the following functionality respects the succint NDA'd
365 * documentation from the card manufacturer, and the same way of
366 * operation is coded in OSS Juli driver, only Digital Out monitor
367 * seems to work. Surprisingly, Analog input monitor outputs Digital
368 * output data. The two are independent, as enabling both doubles
369 * volume of the monitor sound.
370 *
371 * Checking traces on the board suggests the functionality described
372 * by the manufacturer is correct - I2S from ADC and AK4114
373 * go to ICE as well as to Xilinx, I2S inputs of DAC2,3,4 (the monitor
374 * inputs) are fed from Xilinx.
375 *
376 * I even checked traces on board and coded a support in driver for
377 * an alternative possiblity - the unused I2S ICE output channels
378 * switched to HW-IN/SPDIF-IN and providing the monitoring signal to
379 * the DAC - to no avail. The I2S outputs seem to be unconnected.
380 *
381 * The windows driver supports the monitoring correctly.
382 */
383 {
384 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
385 .name = "Monitor Analog In Switch",
386 .info = juli_mute_info,
387 .get = juli_mute_get,
388 .put = juli_mute_put,
389 .private_value = GPIO_ANAIN_MONITOR,
390 },
391 {
392 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
393 .name = "Monitor Digital Out Switch",
394 .info = juli_mute_info,
395 .get = juli_mute_get,
396 .put = juli_mute_put,
397 .private_value = GPIO_DIGOUT_MONITOR,
398 },
399 {
400 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
401 .name = "Monitor Digital In Switch",
402 .info = juli_mute_info,
403 .get = juli_mute_get,
404 .put = juli_mute_put,
405 .private_value = GPIO_DIGIN_MONITOR,
406 },
407};
408
409
410static void ak4358_proc_regs_read(struct snd_info_entry *entry,
411 struct snd_info_buffer *buffer)
412{
413 struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
414 int reg, val;
415 for (reg = 0; reg <= 0xf; reg++) {
416 val = snd_akm4xxx_get(ice->akm, 0, reg);
417 snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
140 } 418 }
419}
420
421static void ak4358_proc_init(struct snd_ice1712 *ice)
422{
423 struct snd_info_entry *entry;
424 if (!snd_card_proc_new(ice->card, "ak4358_codec", &entry))
425 snd_info_set_text_ops(entry, ice, ak4358_proc_regs_read);
426}
427
428static char *slave_vols[] __devinitdata = {
429 PCM_VOLUME,
430 MONITOR_AN_IN_VOLUME,
431 MONITOR_DIG_IN_VOLUME,
432 MONITOR_DIG_OUT_VOLUME,
433 NULL
141}; 434};
142 435
436static __devinitdata
437DECLARE_TLV_DB_SCALE(juli_master_db_scale, -6350, 50, 1);
438
439static struct snd_kcontrol __devinit *ctl_find(struct snd_card *card,
440 const char *name)
441{
442 struct snd_ctl_elem_id sid;
443 memset(&sid, 0, sizeof(sid));
444 /* FIXME: strcpy is bad. */
445 strcpy(sid.name, name);
446 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
447 return snd_ctl_find_id(card, &sid);
448}
449
450static void __devinit add_slaves(struct snd_card *card,
451 struct snd_kcontrol *master, char **list)
452{
453 for (; *list; list++) {
454 struct snd_kcontrol *slave = ctl_find(card, *list);
455 /* printk(KERN_DEBUG "add_slaves - %s\n", *list); */
456 if (slave) {
457 /* printk(KERN_DEBUG "slave %s found\n", *list); */
458 snd_ctl_add_slave(master, slave);
459 }
460 }
461}
462
143static int __devinit juli_add_controls(struct snd_ice1712 *ice) 463static int __devinit juli_add_controls(struct snd_ice1712 *ice)
144{ 464{
145 struct juli_spec *spec = ice->spec; 465 struct juli_spec *spec = ice->spec;
146 int err; 466 int err;
467 unsigned int i;
468 struct snd_kcontrol *vmaster;
469
147 err = snd_ice1712_akm4xxx_build_controls(ice); 470 err = snd_ice1712_akm4xxx_build_controls(ice);
148 if (err < 0) 471 if (err < 0)
149 return err; 472 return err;
473
474 for (i = 0; i < ARRAY_SIZE(juli_mute_controls); i++) {
475 err = snd_ctl_add(ice->card,
476 snd_ctl_new1(&juli_mute_controls[i], ice));
477 if (err < 0)
478 return err;
479 }
480 /* Create virtual master control */
481 vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
482 juli_master_db_scale);
483 if (!vmaster)
484 return -ENOMEM;
485 add_slaves(ice->card, vmaster, slave_vols);
486 err = snd_ctl_add(ice->card, vmaster);
487 if (err < 0)
488 return err;
489
150 /* only capture SPDIF over AK4114 */ 490 /* only capture SPDIF over AK4114 */
151 err = snd_ak4114_build(spec->ak4114, NULL, 491 err = snd_ak4114_build(spec->ak4114, NULL,
152 ice->pcm_pro->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 492 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
493
494 ak4358_proc_init(ice);
153 if (err < 0) 495 if (err < 0)
154 return err; 496 return err;
155 return 0; 497 return 0;
@@ -158,6 +500,74 @@ static int __devinit juli_add_controls(struct snd_ice1712 *ice)
158/* 500/*
159 * initialize the chip 501 * initialize the chip
160 */ 502 */
503
504static inline int juli_is_spdif_master(struct snd_ice1712 *ice)
505{
506 return (ice->gpio.get_data(ice) & GPIO_INTERNAL_CLOCK) ? 0 : 1;
507}
508
509static unsigned int juli_get_rate(struct snd_ice1712 *ice)
510{
511 int i;
512 unsigned char result;
513
514 result = ice->gpio.get_data(ice) & GPIO_RATE_MASK;
515 for (i = 0; i < ARRAY_SIZE(gpio_vals); i++)
516 if (gpio_vals[i] == result)
517 return juli_rates[i];
518 return 0;
519}
520
521/* setting new rate */
522static void juli_set_rate(struct snd_ice1712 *ice, unsigned int rate)
523{
524 unsigned int old, new;
525 unsigned char val;
526
527 old = ice->gpio.get_data(ice);
528 new = (old & ~GPIO_RATE_MASK) | get_gpio_val(rate);
529 /* printk(KERN_DEBUG "JULI - set_rate: old %x, new %x\n",
530 old & GPIO_RATE_MASK,
531 new & GPIO_RATE_MASK); */
532
533 ice->gpio.set_data(ice, new);
534 /* switching to external clock - supplied by external circuits */
535 val = inb(ICEMT1724(ice, RATE));
536 outb(val | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
537}
538
539static inline unsigned char juli_set_mclk(struct snd_ice1712 *ice,
540 unsigned int rate)
541{
542 /* no change in master clock */
543 return 0;
544}
545
546/* setting clock to external - SPDIF */
547static void juli_set_spdif_clock(struct snd_ice1712 *ice)
548{
549 unsigned int old;
550 old = ice->gpio.get_data(ice);
551 /* external clock (= 0), multiply 1x, 48kHz */
552 ice->gpio.set_data(ice, (old & ~GPIO_RATE_MASK) | GPIO_MULTI_1X |
553 GPIO_FREQ_48KHZ);
554}
555
556/* Called when ak4114 detects change in the input SPDIF stream */
557static void juli_ak4114_change(struct ak4114 *ak4114, unsigned char c0,
558 unsigned char c1)
559{
560 struct snd_ice1712 *ice = ak4114->change_callback_private;
561 int rate;
562 if (ice->is_spdif_master(ice) && c1) {
563 /* only for SPDIF master mode, rate was changed */
564 rate = snd_ak4114_external_rate(ak4114);
565 /* printk(KERN_DEBUG "ak4114 - input rate changed to %d\n",
566 rate); */
567 juli_akm_set_rate_val(ice->akm, rate);
568 }
569}
570
161static int __devinit juli_init(struct snd_ice1712 *ice) 571static int __devinit juli_init(struct snd_ice1712 *ice)
162{ 572{
163 static const unsigned char ak4114_init_vals[] = { 573 static const unsigned char ak4114_init_vals[] = {
@@ -187,6 +597,11 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
187 ice, &spec->ak4114); 597 ice, &spec->ak4114);
188 if (err < 0) 598 if (err < 0)
189 return err; 599 return err;
600 /* callback for codecs rate setting */
601 spec->ak4114->change_callback = juli_ak4114_change;
602 spec->ak4114->change_callback_private = ice;
603 /* AK4114 in Juli can detect external rate correctly */
604 spec->ak4114->check_flags = 0;
190 605
191#if 0 606#if 0
192 /* it seems that the analog doughter board detection does not work 607 /* it seems that the analog doughter board detection does not work
@@ -210,6 +625,15 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
210 return err; 625 return err;
211 } 626 }
212 627
628 /* juli is clocked by Xilinx array */
629 ice->hw_rates = &juli_rates_info;
630 ice->is_spdif_master = juli_is_spdif_master;
631 ice->get_rate = juli_get_rate;
632 ice->set_rate = juli_set_rate;
633 ice->set_mclk = juli_set_mclk;
634 ice->set_spdif_clock = juli_set_spdif_clock;
635
636 ice->spdif.ops.open = juli_spdif_in_open;
213 return 0; 637 return 0;
214} 638}
215 639
@@ -220,18 +644,20 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
220 */ 644 */
221 645
222static unsigned char juli_eeprom[] __devinitdata = { 646static unsigned char juli_eeprom[] __devinitdata = {
223 [ICE_EEP2_SYSCONF] = 0x20, /* clock 512, mpu401, 1xADC, 1xDACs */ 647 [ICE_EEP2_SYSCONF] = 0x2b, /* clock 512, mpu401, 1xADC, 1xDACs,
648 SPDIF in */
224 [ICE_EEP2_ACLINK] = 0x80, /* I2S */ 649 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
225 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */ 650 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */
226 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ 651 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
227 [ICE_EEP2_GPIO_DIR] = 0x9f, 652 [ICE_EEP2_GPIO_DIR] = 0x9f, /* 5, 6:inputs; 7, 4-0 outputs*/
228 [ICE_EEP2_GPIO_DIR1] = 0xff, 653 [ICE_EEP2_GPIO_DIR1] = 0xff,
229 [ICE_EEP2_GPIO_DIR2] = 0x7f, 654 [ICE_EEP2_GPIO_DIR2] = 0x7f,
230 [ICE_EEP2_GPIO_MASK] = 0x9f, 655 [ICE_EEP2_GPIO_MASK] = 0x60, /* 5, 6: locked; 7, 4-0 writable */
231 [ICE_EEP2_GPIO_MASK1] = 0xff, 656 [ICE_EEP2_GPIO_MASK1] = 0x00, /* 0-7 writable */
232 [ICE_EEP2_GPIO_MASK2] = 0x7f, 657 [ICE_EEP2_GPIO_MASK2] = 0x7f,
233 [ICE_EEP2_GPIO_STATE] = 0x16, /* internal clock, multiple 1x, 48kHz */ 658 [ICE_EEP2_GPIO_STATE] = GPIO_FREQ_48KHZ | GPIO_MULTI_1X |
234 [ICE_EEP2_GPIO_STATE1] = 0x80, /* mute */ 659 GPIO_INTERNAL_CLOCK, /* internal clock, multiple 1x, 48kHz*/
660 [ICE_EEP2_GPIO_STATE1] = 0x00, /* unmuted */
235 [ICE_EEP2_GPIO_STATE2] = 0x00, 661 [ICE_EEP2_GPIO_STATE2] = 0x00,
236}; 662};
237 663
diff --git a/sound/pci/ice1712/pontis.c b/sound/pci/ice1712/pontis.c
index 4945c81e8a96..203cdc1bf8da 100644
--- a/sound/pci/ice1712/pontis.c
+++ b/sound/pci/ice1712/pontis.c
@@ -246,7 +246,7 @@ static int wm_adc_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
246 wm_put(ice, WM_ADC_MUX, nval); 246 wm_put(ice, WM_ADC_MUX, nval);
247 } 247 }
248 mutex_unlock(&ice->gpio_mutex); 248 mutex_unlock(&ice->gpio_mutex);
249 return 0; 249 return change;
250} 250}
251 251
252/* 252/*
@@ -450,7 +450,7 @@ static int cs_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
450 change = 1; 450 change = 1;
451 } 451 }
452 mutex_unlock(&ice->gpio_mutex); 452 mutex_unlock(&ice->gpio_mutex);
453 return 0; 453 return change;
454} 454}
455 455
456 456
diff --git a/sound/pci/ice1712/prodigy192.c b/sound/pci/ice1712/prodigy192.c
index 48cf40a8f32a..48d3679292a7 100644
--- a/sound/pci/ice1712/prodigy192.c
+++ b/sound/pci/ice1712/prodigy192.c
@@ -319,12 +319,11 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
319/* 319/*
320 * Handler for setting correct codec rate - called when rate change is detected 320 * Handler for setting correct codec rate - called when rate change is detected
321 */ 321 */
322static void stac9460_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) 322static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
323{ 323{
324 unsigned char old, new; 324 unsigned char old, new;
325 int idx; 325 int idx;
326 unsigned char changed[7]; 326 unsigned char changed[7];
327 struct snd_ice1712 *ice = ak->private_data[0];
328 struct prodigy192_spec *spec = ice->spec; 327 struct prodigy192_spec *spec = ice->spec;
329 328
330 if (rate == 0) /* no hint - S/PDIF input is master, simply return */ 329 if (rate == 0) /* no hint - S/PDIF input is master, simply return */
@@ -357,16 +356,6 @@ static void stac9460_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
357 mutex_unlock(&spec->mute_mutex); 356 mutex_unlock(&spec->mute_mutex);
358} 357}
359 358
360/* using akm infrastructure for setting rate of the codec */
361static struct snd_akm4xxx akmlike_stac9460 __devinitdata = {
362 .type = NON_AKM, /* special value */
363 .num_adcs = 6, /* not used in any way, just for completeness */
364 .num_dacs = 2,
365 .ops = {
366 .set_rate_val = stac9460_set_rate_val
367 }
368};
369
370 359
371static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0); 360static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
372static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0); 361static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
@@ -642,12 +631,19 @@ static int prodigy192_ak4114_init(struct snd_ice1712 *ice)
642 0x41, 0x02, 0x2c, 0x00, 0x00 631 0x41, 0x02, 0x2c, 0x00, 0x00
643 }; 632 };
644 struct prodigy192_spec *spec = ice->spec; 633 struct prodigy192_spec *spec = ice->spec;
634 int err;
645 635
646 return snd_ak4114_create(ice->card, 636 err = snd_ak4114_create(ice->card,
647 prodigy192_ak4114_read, 637 prodigy192_ak4114_read,
648 prodigy192_ak4114_write, 638 prodigy192_ak4114_write,
649 ak4114_init_vals, ak4114_init_txcsb, 639 ak4114_init_vals, ak4114_init_txcsb,
650 ice, &spec->ak4114); 640 ice, &spec->ak4114);
641 if (err < 0)
642 return err;
643 /* AK4114 in Prodigy192 cannot detect external rate correctly.
644 * No reason to stop capture stream due to incorrect checks */
645 spec->ak4114->check_flags = AK4114_CHECK_NO_RATE;
646 return 0;
651} 647}
652 648
653static void stac9460_proc_regs_read(struct snd_info_entry *entry, 649static void stac9460_proc_regs_read(struct snd_info_entry *entry,
@@ -743,7 +739,6 @@ static int __devinit prodigy192_init(struct snd_ice1712 *ice)
743 }; 739 };
744 const unsigned short *p; 740 const unsigned short *p;
745 int err = 0; 741 int err = 0;
746 struct snd_akm4xxx *ak;
747 struct prodigy192_spec *spec; 742 struct prodigy192_spec *spec;
748 743
749 /* prodigy 192 */ 744 /* prodigy 192 */
@@ -761,15 +756,7 @@ static int __devinit prodigy192_init(struct snd_ice1712 *ice)
761 p = stac_inits_prodigy; 756 p = stac_inits_prodigy;
762 for (; *p != (unsigned short)-1; p += 2) 757 for (; *p != (unsigned short)-1; p += 2)
763 stac9460_put(ice, p[0], p[1]); 758 stac9460_put(ice, p[0], p[1]);
764 /* reusing the akm codecs infrastructure, 759 ice->gpio.set_pro_rate = stac9460_set_rate_val;
765 * for setting rate on stac9460 */
766 ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
767 if (!ak)
768 return -ENOMEM;
769 ice->akm_codecs = 1;
770 err = snd_ice1712_akm4xxx_init(ak, &akmlike_stac9460, NULL, ice);
771 if (err < 0)
772 return err;
773 760
774 /* MI/ODI/O add on card with AK4114 */ 761 /* MI/ODI/O add on card with AK4114 */
775 if (prodigy192_miodio_exists(ice)) { 762 if (prodigy192_miodio_exists(ice)) {
@@ -825,10 +812,6 @@ struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] __devinitdata = {
825 .build_controls = prodigy192_add_controls, 812 .build_controls = prodigy192_add_controls,
826 .eeprom_size = sizeof(prodigy71_eeprom), 813 .eeprom_size = sizeof(prodigy71_eeprom),
827 .eeprom_data = prodigy71_eeprom, 814 .eeprom_data = prodigy71_eeprom,
828 /* the current MPU401 code loops infinitely
829 * when opening midi device
830 */
831 .no_mpu401 = 1,
832 }, 815 },
833 { } /* terminator */ 816 { } /* terminator */
834}; 817};
diff --git a/sound/pci/ice1712/revo.c b/sound/pci/ice1712/revo.c
index 301bf929acd9..4d2631434dc8 100644
--- a/sound/pci/ice1712/revo.c
+++ b/sound/pci/ice1712/revo.c
@@ -322,17 +322,23 @@ static struct snd_pt2258 ptc_revo51_volume;
322static void ap192_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) 322static void ap192_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
323{ 323{
324 struct snd_ice1712 *ice = ak->private_data[0]; 324 struct snd_ice1712 *ice = ak->private_data[0];
325 int dfs;
325 326
326 revo_set_rate_val(ak, rate); 327 revo_set_rate_val(ak, rate);
327 328
328#if 1 /* FIXME: do we need this procedure? */ 329 /* reset CKS */
329 /* reset DFS pin of AK5385A for ADC, too */ 330 snd_ice1712_gpio_write_bits(ice, 1 << 8, rate > 96000 ? 1 << 8 : 0);
330 /* DFS0 (pin 18) -- GPIO10 pin 77 */ 331 /* reset DFS pins of AK5385A for ADC, too */
331 snd_ice1712_save_gpio_status(ice); 332 if (rate > 96000)
332 snd_ice1712_gpio_write_bits(ice, 1 << 10, 333 dfs = 2;
333 rate > 48000 ? (1 << 10) : 0); 334 else if (rate > 48000)
334 snd_ice1712_restore_gpio_status(ice); 335 dfs = 1;
335#endif 336 else
337 dfs = 0;
338 snd_ice1712_gpio_write_bits(ice, 3 << 9, dfs << 9);
339 /* reset ADC */
340 snd_ice1712_gpio_write_bits(ice, 1 << 11, 0);
341 snd_ice1712_gpio_write_bits(ice, 1 << 11, 1 << 11);
336} 342}
337 343
338static const struct snd_akm4xxx_dac_channel ap192_dac[] = { 344static const struct snd_akm4xxx_dac_channel ap192_dac[] = {
@@ -353,28 +359,20 @@ static struct snd_ak4xxx_private akm_ap192_priv __devinitdata = {
353 .cif = 0, 359 .cif = 0,
354 .data_mask = VT1724_REVO_CDOUT, 360 .data_mask = VT1724_REVO_CDOUT,
355 .clk_mask = VT1724_REVO_CCLK, 361 .clk_mask = VT1724_REVO_CCLK,
356 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS3, 362 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
357 .cs_addr = VT1724_REVO_CS3, 363 .cs_addr = VT1724_REVO_CS1,
358 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS3, 364 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
359 .add_flags = VT1724_REVO_CCLK, /* high at init */ 365 .add_flags = VT1724_REVO_CCLK, /* high at init */
360 .mask_flags = 0, 366 .mask_flags = 0,
361}; 367};
362 368
363#if 0
364/* FIXME: ak4114 makes the sound much lower due to some confliction,
365 * so let's disable it right now...
366 */
367#define BUILD_AK4114_AP192
368#endif
369
370#ifdef BUILD_AK4114_AP192
371/* AK4114 support on Audiophile 192 */ 369/* AK4114 support on Audiophile 192 */
372/* CDTO (pin 32) -- GPIO2 pin 52 370/* CDTO (pin 32) -- GPIO2 pin 52
373 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358) 371 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358)
374 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358) 372 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358)
375 * CSN (pin 35) -- GPIO7 pin 59 373 * CSN (pin 35) -- GPIO7 pin 59
376 */ 374 */
377#define AK4114_ADDR 0x00 375#define AK4114_ADDR 0x02
378 376
379static void write_data(struct snd_ice1712 *ice, unsigned int gpio, 377static void write_data(struct snd_ice1712 *ice, unsigned int gpio,
380 unsigned int data, int idx) 378 unsigned int data, int idx)
@@ -428,7 +426,7 @@ static unsigned int ap192_4wire_start(struct snd_ice1712 *ice)
428 tmp = snd_ice1712_gpio_read(ice); 426 tmp = snd_ice1712_gpio_read(ice);
429 tmp |= VT1724_REVO_CCLK; /* high at init */ 427 tmp |= VT1724_REVO_CCLK; /* high at init */
430 tmp |= VT1724_REVO_CS0; 428 tmp |= VT1724_REVO_CS0;
431 tmp &= ~VT1724_REVO_CS3; 429 tmp &= ~VT1724_REVO_CS1;
432 snd_ice1712_gpio_write(ice, tmp); 430 snd_ice1712_gpio_write(ice, tmp);
433 udelay(1); 431 udelay(1);
434 return tmp; 432 return tmp;
@@ -436,7 +434,7 @@ static unsigned int ap192_4wire_start(struct snd_ice1712 *ice)
436 434
437static void ap192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp) 435static void ap192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp)
438{ 436{
439 tmp |= VT1724_REVO_CS3; 437 tmp |= VT1724_REVO_CS1;
440 tmp |= VT1724_REVO_CS0; 438 tmp |= VT1724_REVO_CS0;
441 snd_ice1712_gpio_write(ice, tmp); 439 snd_ice1712_gpio_write(ice, tmp);
442 udelay(1); 440 udelay(1);
@@ -485,13 +483,17 @@ static int __devinit ap192_ak4114_init(struct snd_ice1712 *ice)
485 struct ak4114 *ak; 483 struct ak4114 *ak;
486 int err; 484 int err;
487 485
488 return snd_ak4114_create(ice->card, 486 err = snd_ak4114_create(ice->card,
489 ap192_ak4114_read, 487 ap192_ak4114_read,
490 ap192_ak4114_write, 488 ap192_ak4114_write,
491 ak4114_init_vals, ak4114_init_txcsb, 489 ak4114_init_vals, ak4114_init_txcsb,
492 ice, &ak); 490 ice, &ak);
491 /* AK4114 in Revo cannot detect external rate correctly.
492 * No reason to stop capture stream due to incorrect checks */
493 ak->check_flags = AK4114_CHECK_NO_RATE;
494
495 return 0; /* error ignored; it's no fatal error */
493} 496}
494#endif /* BUILD_AK4114_AP192 */
495 497
496static int __devinit revo_init(struct snd_ice1712 *ice) 498static int __devinit revo_init(struct snd_ice1712 *ice)
497{ 499{
@@ -557,6 +559,9 @@ static int __devinit revo_init(struct snd_ice1712 *ice)
557 if (err < 0) 559 if (err < 0)
558 return err; 560 return err;
559 561
562 /* unmute all codecs */
563 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE,
564 VT1724_REVO_MUTE);
560 break; 565 break;
561 } 566 }
562 567
@@ -588,11 +593,9 @@ static int __devinit revo_add_controls(struct snd_ice1712 *ice)
588 err = snd_ice1712_akm4xxx_build_controls(ice); 593 err = snd_ice1712_akm4xxx_build_controls(ice);
589 if (err < 0) 594 if (err < 0)
590 return err; 595 return err;
591#ifdef BUILD_AK4114_AP192
592 err = ap192_ak4114_init(ice); 596 err = ap192_ak4114_init(ice);
593 if (err < 0) 597 if (err < 0)
594 return err; 598 return err;
595#endif
596 break; 599 break;
597 } 600 }
598 return 0; 601 return 0;
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index c52abd0bf22e..048d99e25ab0 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -155,7 +155,8 @@ DEFINE_REGSET(SP, 0x60); /* SPDIF out */
155#define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */ 155#define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */
156#define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */ 156#define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */
157#define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */ 157#define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */
158#define ICH_PCM_246_MASK 0x00300000 /* 6 channels (not all chips) */ 158#define ICH_PCM_246_MASK 0x00300000 /* chan mask (not all chips) */
159#define ICH_PCM_8 0x00300000 /* 8 channels (not all chips) */
159#define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */ 160#define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */
160#define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */ 161#define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */
161#define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */ 162#define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */
@@ -382,6 +383,7 @@ struct intel8x0 {
382 383
383 unsigned multi4: 1, 384 unsigned multi4: 1,
384 multi6: 1, 385 multi6: 1,
386 multi8 :1,
385 dra: 1, 387 dra: 1,
386 smp20bit: 1; 388 smp20bit: 1;
387 unsigned in_ac97_init: 1, 389 unsigned in_ac97_init: 1,
@@ -997,6 +999,8 @@ static void snd_intel8x0_setup_pcm_out(struct intel8x0 *chip,
997 cnt |= ICH_PCM_4; 999 cnt |= ICH_PCM_4;
998 else if (runtime->channels == 6) 1000 else if (runtime->channels == 6)
999 cnt |= ICH_PCM_6; 1001 cnt |= ICH_PCM_6;
1002 else if (runtime->channels == 8)
1003 cnt |= ICH_PCM_8;
1000 if (chip->device_type == DEVICE_NFORCE) { 1004 if (chip->device_type == DEVICE_NFORCE) {
1001 /* reset to 2ch once to keep the 6 channel data in alignment, 1005 /* reset to 2ch once to keep the 6 channel data in alignment,
1002 * to start from Front Left always 1006 * to start from Front Left always
@@ -1106,6 +1110,16 @@ static struct snd_pcm_hw_constraint_list hw_constraints_channels6 = {
1106 .mask = 0, 1110 .mask = 0,
1107}; 1111};
1108 1112
1113static unsigned int channels8[] = {
1114 2, 4, 6, 8,
1115};
1116
1117static struct snd_pcm_hw_constraint_list hw_constraints_channels8 = {
1118 .count = ARRAY_SIZE(channels8),
1119 .list = channels8,
1120 .mask = 0,
1121};
1122
1109static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev) 1123static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev)
1110{ 1124{
1111 struct intel8x0 *chip = snd_pcm_substream_chip(substream); 1125 struct intel8x0 *chip = snd_pcm_substream_chip(substream);
@@ -1136,7 +1150,12 @@ static int snd_intel8x0_playback_open(struct snd_pcm_substream *substream)
1136 if (err < 0) 1150 if (err < 0)
1137 return err; 1151 return err;
1138 1152
1139 if (chip->multi6) { 1153 if (chip->multi8) {
1154 runtime->hw.channels_max = 8;
1155 snd_pcm_hw_constraint_list(runtime, 0,
1156 SNDRV_PCM_HW_PARAM_CHANNELS,
1157 &hw_constraints_channels8);
1158 } else if (chip->multi6) {
1140 runtime->hw.channels_max = 6; 1159 runtime->hw.channels_max = 6;
1141 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 1160 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
1142 &hw_constraints_channels6); 1161 &hw_constraints_channels6);
@@ -2203,8 +2222,11 @@ static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
2203 } 2222 }
2204 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) { 2223 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
2205 chip->multi4 = 1; 2224 chip->multi4 = 1;
2206 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE)) 2225 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE)) {
2207 chip->multi6 = 1; 2226 chip->multi6 = 1;
2227 if (chip->ac97[0]->flags & AC97_HAS_8CH)
2228 chip->multi8 = 1;
2229 }
2208 } 2230 }
2209 if (pbus->pcms[0].r[1].rslots[0]) { 2231 if (pbus->pcms[0].r[1].rslots[0]) {
2210 chip->dra = 1; 2232 chip->dra = 1;
@@ -2446,7 +2468,7 @@ static int snd_intel8x0_free(struct intel8x0 *chip)
2446 pci_write_config_dword(chip->pci, 0x4c, val); 2468 pci_write_config_dword(chip->pci, 0x4c, val);
2447 } 2469 }
2448 /* --- */ 2470 /* --- */
2449 synchronize_irq(chip->irq); 2471
2450 __hw_end: 2472 __hw_end:
2451 if (chip->irq >= 0) 2473 if (chip->irq >= 0)
2452 free_irq(chip->irq, chip); 2474 free_irq(chip->irq, chip);
@@ -2495,7 +2517,6 @@ static int intel8x0_suspend(struct pci_dev *pci, pm_message_t state)
2495 chip->sdm_saved = igetbyte(chip, ICHREG(SDM)); 2517 chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
2496 2518
2497 if (chip->irq >= 0) { 2519 if (chip->irq >= 0) {
2498 synchronize_irq(chip->irq);
2499 free_irq(chip->irq, chip); 2520 free_irq(chip->irq, chip);
2500 chip->irq = -1; 2521 chip->irq = -1;
2501 } 2522 }
@@ -2648,7 +2669,7 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2648 t = stop_time.tv_sec - start_time.tv_sec; 2669 t = stop_time.tv_sec - start_time.tv_sec;
2649 t *= 1000000; 2670 t *= 1000000;
2650 t += stop_time.tv_usec - start_time.tv_usec; 2671 t += stop_time.tv_usec - start_time.tv_usec;
2651 printk(KERN_INFO "%s: measured %lu usecs\n", __FUNCTION__, t); 2672 printk(KERN_INFO "%s: measured %lu usecs\n", __func__, t);
2652 if (t == 0) { 2673 if (t == 0) {
2653 snd_printk(KERN_ERR "?? calculation error..\n"); 2674 snd_printk(KERN_ERR "?? calculation error..\n");
2654 return; 2675 return;
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index cadda8d6b70f..faf674e671ac 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -985,17 +985,15 @@ static int snd_intel8x0_free(struct intel8x0m *chip)
985 /* reset channels */ 985 /* reset channels */
986 for (i = 0; i < chip->bdbars_count; i++) 986 for (i = 0; i < chip->bdbars_count; i++)
987 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS); 987 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
988 /* --- */ 988 __hw_end:
989 synchronize_irq(chip->irq); 989 if (chip->irq >= 0)
990 __hw_end: 990 free_irq(chip->irq, chip);
991 if (chip->bdbars.area) 991 if (chip->bdbars.area)
992 snd_dma_free_pages(&chip->bdbars); 992 snd_dma_free_pages(&chip->bdbars);
993 if (chip->addr) 993 if (chip->addr)
994 pci_iounmap(chip->pci, chip->addr); 994 pci_iounmap(chip->pci, chip->addr);
995 if (chip->bmaddr) 995 if (chip->bmaddr)
996 pci_iounmap(chip->pci, chip->bmaddr); 996 pci_iounmap(chip->pci, chip->bmaddr);
997 if (chip->irq >= 0)
998 free_irq(chip->irq, chip);
999 pci_release_regions(chip->pci); 997 pci_release_regions(chip->pci);
1000 pci_disable_device(chip->pci); 998 pci_disable_device(chip->pci);
1001 kfree(chip); 999 kfree(chip);
@@ -1017,7 +1015,6 @@ static int intel8x0m_suspend(struct pci_dev *pci, pm_message_t state)
1017 snd_pcm_suspend_all(chip->pcm[i]); 1015 snd_pcm_suspend_all(chip->pcm[i]);
1018 snd_ac97_suspend(chip->ac97); 1016 snd_ac97_suspend(chip->ac97);
1019 if (chip->irq >= 0) { 1017 if (chip->irq >= 0) {
1020 synchronize_irq(chip->irq);
1021 free_irq(chip->irq, chip); 1018 free_irq(chip->irq, chip);
1022 chip->irq = -1; 1019 chip->irq = -1;
1023 } 1020 }
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 10c713d9ac49..f4c85b52bde3 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -2102,7 +2102,6 @@ snd_korg1212_free(struct snd_korg1212 *korg1212)
2102 snd_korg1212_TurnOffIdleMonitor(korg1212); 2102 snd_korg1212_TurnOffIdleMonitor(korg1212);
2103 2103
2104 if (korg1212->irq >= 0) { 2104 if (korg1212->irq >= 0) {
2105 synchronize_irq(korg1212->irq);
2106 snd_korg1212_DisableCardInterrupts(korg1212); 2105 snd_korg1212_DisableCardInterrupts(korg1212);
2107 free_irq(korg1212->irq, korg1212); 2106 free_irq(korg1212->irq, korg1212);
2108 korg1212->irq = -1; 2107 korg1212->irq = -1;
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 04fa0a68416c..a536c59fbea1 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -2068,7 +2068,7 @@ static int __devinit snd_m3_mixer(struct snd_m3 *chip)
2068{ 2068{
2069 struct snd_ac97_bus *pbus; 2069 struct snd_ac97_bus *pbus;
2070 struct snd_ac97_template ac97; 2070 struct snd_ac97_template ac97;
2071 struct snd_ctl_elem_id id; 2071 struct snd_ctl_elem_id elem_id;
2072 int err; 2072 int err;
2073 static struct snd_ac97_bus_ops ops = { 2073 static struct snd_ac97_bus_ops ops = {
2074 .write = snd_m3_ac97_write, 2074 .write = snd_m3_ac97_write,
@@ -2088,14 +2088,14 @@ static int __devinit snd_m3_mixer(struct snd_m3 *chip)
2088 schedule_timeout_uninterruptible(msecs_to_jiffies(100)); 2088 schedule_timeout_uninterruptible(msecs_to_jiffies(100));
2089 snd_ac97_write(chip->ac97, AC97_PCM, 0); 2089 snd_ac97_write(chip->ac97, AC97_PCM, 0);
2090 2090
2091 memset(&id, 0, sizeof(id)); 2091 memset(&elem_id, 0, sizeof(elem_id));
2092 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2092 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2093 strcpy(id.name, "Master Playback Switch"); 2093 strcpy(elem_id.name, "Master Playback Switch");
2094 chip->master_switch = snd_ctl_find_id(chip->card, &id); 2094 chip->master_switch = snd_ctl_find_id(chip->card, &elem_id);
2095 memset(&id, 0, sizeof(id)); 2095 memset(&elem_id, 0, sizeof(elem_id));
2096 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2096 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2097 strcpy(id.name, "Master Playback Volume"); 2097 strcpy(elem_id.name, "Master Playback Volume");
2098 chip->master_volume = snd_ctl_find_id(chip->card, &id); 2098 chip->master_volume = snd_ctl_find_id(chip->card, &elem_id);
2099 2099
2100 return 0; 2100 return 0;
2101} 2101}
@@ -2542,10 +2542,8 @@ static int snd_m3_free(struct snd_m3 *chip)
2542 vfree(chip->suspend_mem); 2542 vfree(chip->suspend_mem);
2543#endif 2543#endif
2544 2544
2545 if (chip->irq >= 0) { 2545 if (chip->irq >= 0)
2546 synchronize_irq(chip->irq);
2547 free_irq(chip->irq, chip); 2546 free_irq(chip->irq, chip);
2548 }
2549 2547
2550 if (chip->iobase) 2548 if (chip->iobase)
2551 pci_release_regions(chip->pci); 2549 pci_release_regions(chip->pci);
@@ -2569,7 +2567,7 @@ static int m3_suspend(struct pci_dev *pci, pm_message_t state)
2569{ 2567{
2570 struct snd_card *card = pci_get_drvdata(pci); 2568 struct snd_card *card = pci_get_drvdata(pci);
2571 struct snd_m3 *chip = card->private_data; 2569 struct snd_m3 *chip = card->private_data;
2572 int i, index; 2570 int i, dsp_index;
2573 2571
2574 if (chip->suspend_mem == NULL) 2572 if (chip->suspend_mem == NULL)
2575 return 0; 2573 return 0;
@@ -2583,12 +2581,12 @@ static int m3_suspend(struct pci_dev *pci, pm_message_t state)
2583 snd_m3_assp_halt(chip); 2581 snd_m3_assp_halt(chip);
2584 2582
2585 /* save dsp image */ 2583 /* save dsp image */
2586 index = 0; 2584 dsp_index = 0;
2587 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++) 2585 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++)
2588 chip->suspend_mem[index++] = 2586 chip->suspend_mem[dsp_index++] =
2589 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_CODE, i); 2587 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_CODE, i);
2590 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++) 2588 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
2591 chip->suspend_mem[index++] = 2589 chip->suspend_mem[dsp_index++] =
2592 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, i); 2590 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, i);
2593 2591
2594 pci_disable_device(pci); 2592 pci_disable_device(pci);
@@ -2601,7 +2599,7 @@ static int m3_resume(struct pci_dev *pci)
2601{ 2599{
2602 struct snd_card *card = pci_get_drvdata(pci); 2600 struct snd_card *card = pci_get_drvdata(pci);
2603 struct snd_m3 *chip = card->private_data; 2601 struct snd_m3 *chip = card->private_data;
2604 int i, index; 2602 int i, dsp_index;
2605 2603
2606 if (chip->suspend_mem == NULL) 2604 if (chip->suspend_mem == NULL)
2607 return 0; 2605 return 0;
@@ -2625,13 +2623,13 @@ static int m3_resume(struct pci_dev *pci)
2625 snd_m3_ac97_reset(chip); 2623 snd_m3_ac97_reset(chip);
2626 2624
2627 /* restore dsp image */ 2625 /* restore dsp image */
2628 index = 0; 2626 dsp_index = 0;
2629 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++) 2627 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++)
2630 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE, i, 2628 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE, i,
2631 chip->suspend_mem[index++]); 2629 chip->suspend_mem[dsp_index++]);
2632 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++) 2630 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
2633 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, i, 2631 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, i,
2634 chip->suspend_mem[index++]); 2632 chip->suspend_mem[dsp_index++]);
2635 2633
2636 /* tell the dma engine to restart itself */ 2634 /* tell the dma engine to restart itself */
2637 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, 2635 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 7ac654e381da..7efb838d18a6 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -1439,7 +1439,7 @@ static int snd_nm256_free(struct nm256 *chip)
1439 snd_nm256_capture_stop(chip); 1439 snd_nm256_capture_stop(chip);
1440 1440
1441 if (chip->irq >= 0) 1441 if (chip->irq >= 0)
1442 synchronize_irq(chip->irq); 1442 free_irq(chip->irq, chip);
1443 1443
1444 if (chip->cport) 1444 if (chip->cport)
1445 iounmap(chip->cport); 1445 iounmap(chip->cport);
@@ -1447,8 +1447,6 @@ static int snd_nm256_free(struct nm256 *chip)
1447 iounmap(chip->buffer); 1447 iounmap(chip->buffer);
1448 release_and_free_resource(chip->res_cport); 1448 release_and_free_resource(chip->res_cport);
1449 release_and_free_resource(chip->res_buffer); 1449 release_and_free_resource(chip->res_buffer);
1450 if (chip->irq >= 0)
1451 free_irq(chip->irq, chip);
1452 1450
1453 pci_disable_device(chip->pci); 1451 pci_disable_device(chip->pci);
1454 kfree(chip->ac97_regs); 1452 kfree(chip->ac97_regs);
diff --git a/sound/pci/oxygen/cs4362a.h b/sound/pci/oxygen/cs4362a.h
new file mode 100644
index 000000000000..6a4fedf5e1ec
--- /dev/null
+++ b/sound/pci/oxygen/cs4362a.h
@@ -0,0 +1,69 @@
1/* register 01h */
2#define CS4362A_PDN 0x01
3#define CS4362A_DAC1_DIS 0x02
4#define CS4362A_DAC2_DIS 0x04
5#define CS4362A_DAC3_DIS 0x08
6#define CS4362A_MCLKDIV 0x20
7#define CS4362A_FREEZE 0x40
8#define CS4362A_CPEN 0x80
9/* register 02h */
10#define CS4362A_DIF_MASK 0x70
11#define CS4362A_DIF_LJUST 0x00
12#define CS4362A_DIF_I2S 0x10
13#define CS4362A_DIF_RJUST_16 0x20
14#define CS4362A_DIF_RJUST_24 0x30
15#define CS4362A_DIF_RJUST_20 0x40
16#define CS4362A_DIF_RJUST_18 0x50
17/* register 03h */
18#define CS4362A_MUTEC_MASK 0x03
19#define CS4362A_MUTEC_6 0x00
20#define CS4362A_MUTEC_1 0x01
21#define CS4362A_MUTEC_3 0x03
22#define CS4362A_AMUTE 0x04
23#define CS4362A_MUTEC_POL 0x08
24#define CS4362A_RMP_UP 0x10
25#define CS4362A_SNGLVOL 0x20
26#define CS4362A_ZERO_CROSS 0x40
27#define CS4362A_SOFT_RAMP 0x80
28/* register 04h */
29#define CS4362A_RMP_DN 0x01
30#define CS4362A_DEM_MASK 0x06
31#define CS4362A_DEM_NONE 0x00
32#define CS4362A_DEM_44100 0x02
33#define CS4362A_DEM_48000 0x04
34#define CS4362A_DEM_32000 0x06
35#define CS4362A_FILT_SEL 0x10
36/* register 05h */
37#define CS4362A_INV_A1 0x01
38#define CS4362A_INV_B1 0x02
39#define CS4362A_INV_A2 0x04
40#define CS4362A_INV_B2 0x08
41#define CS4362A_INV_A3 0x10
42#define CS4362A_INV_B3 0x20
43/* register 06h */
44#define CS4362A_FM_MASK 0x03
45#define CS4362A_FM_SINGLE 0x00
46#define CS4362A_FM_DOUBLE 0x01
47#define CS4362A_FM_QUAD 0x02
48#define CS4362A_FM_DSD 0x03
49#define CS4362A_ATAPI_MASK 0x7c
50#define CS4362A_ATAPI_B_MUTE 0x00
51#define CS4362A_ATAPI_B_R 0x04
52#define CS4362A_ATAPI_B_L 0x08
53#define CS4362A_ATAPI_B_LR 0x0c
54#define CS4362A_ATAPI_A_MUTE 0x00
55#define CS4362A_ATAPI_A_R 0x10
56#define CS4362A_ATAPI_A_L 0x20
57#define CS4362A_ATAPI_A_LR 0x30
58#define CS4362A_ATAPI_MIX_LR_VOL 0x40
59#define CS4362A_A_EQ_B 0x80
60/* register 07h */
61#define CS4362A_VOL_MASK 0x7f
62#define CS4362A_MUTE 0x80
63/* register 08h: like 07h */
64/* registers 09h..0Bh: like 06h..08h */
65/* registers 0Ch..0Eh: like 06h..08h */
66/* register 12h */
67#define CS4362A_REV_MASK 0x07
68#define CS4362A_PART_MASK 0xf8
69#define CS4362A_PART_CS4362A 0x50
diff --git a/sound/pci/oxygen/cs4398.h b/sound/pci/oxygen/cs4398.h
new file mode 100644
index 000000000000..5faf5efc8826
--- /dev/null
+++ b/sound/pci/oxygen/cs4398.h
@@ -0,0 +1,69 @@
1/* register 1 */
2#define CS4398_REV_MASK 0x07
3#define CS4398_PART_MASK 0xf8
4#define CS4398_PART_CS4398 0x70
5/* register 2 */
6#define CS4398_FM_MASK 0x03
7#define CS4398_FM_SINGLE 0x00
8#define CS4398_FM_DOUBLE 0x01
9#define CS4398_FM_QUAD 0x02
10#define CS4398_FM_DSD 0x03
11#define CS4398_DEM_MASK 0x0c
12#define CS4398_DEM_NONE 0x00
13#define CS4398_DEM_44100 0x04
14#define CS4398_DEM_48000 0x08
15#define CS4398_DEM_32000 0x0c
16#define CS4398_DIF_MASK 0x70
17#define CS4398_DIF_LJUST 0x00
18#define CS4398_DIF_I2S 0x10
19#define CS4398_DIF_RJUST_16 0x20
20#define CS4398_DIF_RJUST_24 0x30
21#define CS4398_DIF_RJUST_20 0x40
22#define CS4398_DIF_RJUST_18 0x50
23#define CS4398_DSD_SRC 0x80
24/* register 3 */
25#define CS4398_ATAPI_MASK 0x1f
26#define CS4398_ATAPI_B_MUTE 0x00
27#define CS4398_ATAPI_B_R 0x01
28#define CS4398_ATAPI_B_L 0x02
29#define CS4398_ATAPI_B_LR 0x03
30#define CS4398_ATAPI_A_MUTE 0x00
31#define CS4398_ATAPI_A_R 0x04
32#define CS4398_ATAPI_A_L 0x08
33#define CS4398_ATAPI_A_LR 0x0c
34#define CS4398_ATAPI_MIX_LR_VOL 0x10
35#define CS4398_INVERT_B 0x20
36#define CS4398_INVERT_A 0x40
37#define CS4398_VOL_B_EQ_A 0x80
38/* register 4 */
39#define CS4398_MUTEP_MASK 0x03
40#define CS4398_MUTEP_AUTO 0x00
41#define CS4398_MUTEP_LOW 0x02
42#define CS4398_MUTEP_HIGH 0x03
43#define CS4398_MUTE_B 0x08
44#define CS4398_MUTE_A 0x10
45#define CS4398_MUTEC_A_EQ_B 0x20
46#define CS4398_DAMUTE 0x40
47#define CS4398_PAMUTE 0x80
48/* register 5 */
49#define CS4398_VOL_A_MASK 0xff
50/* register 6 */
51#define CS4398_VOL_B_MASK 0xff
52/* register 7 */
53#define CS4398_DIR_DSD 0x01
54#define CS4398_FILT_SEL 0x04
55#define CS4398_RMP_DN 0x10
56#define CS4398_RMP_UP 0x20
57#define CS4398_ZERO_CROSS 0x40
58#define CS4398_SOFT_RAMP 0x80
59/* register 8 */
60#define CS4398_MCLKDIV3 0x08
61#define CS4398_MCLKDIV2 0x10
62#define CS4398_FREEZE 0x20
63#define CS4398_CPEN 0x40
64#define CS4398_PDN 0x80
65/* register 9 */
66#define CS4398_DSD_PM_EN 0x01
67#define CS4398_DSD_PM_MODE 0x02
68#define CS4398_INVALID_DSD 0x04
69#define CS4398_STATIC_DSD 0x08
diff --git a/sound/pci/oxygen/hifier.c b/sound/pci/oxygen/hifier.c
index 666f69a3312e..090dd4354a28 100644
--- a/sound/pci/oxygen/hifier.c
+++ b/sound/pci/oxygen/hifier.c
@@ -66,12 +66,12 @@ static void hifier_init(struct oxygen *chip)
66{ 66{
67 struct hifier_data *data = chip->model_data; 67 struct hifier_data *data = chip->model_data;
68 68
69 data->ak4396_ctl2 = AK4396_DEM_OFF | AK4396_DFS_NORMAL; 69 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
70 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 70 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
71 ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2); 71 ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2);
72 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM); 72 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
73 ak4396_write(chip, AK4396_LCH_ATT, 0xff); 73 ak4396_write(chip, AK4396_LCH_ATT, 0);
74 ak4396_write(chip, AK4396_RCH_ATT, 0xff); 74 ak4396_write(chip, AK4396_RCH_ATT, 0);
75 75
76 snd_component_add(chip->card, "AK4396"); 76 snd_component_add(chip->card, "AK4396");
77 snd_component_add(chip->card, "CS5340"); 77 snd_component_add(chip->card, "CS5340");
@@ -127,22 +127,8 @@ static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
127 127
128static int hifier_control_filter(struct snd_kcontrol_new *template) 128static int hifier_control_filter(struct snd_kcontrol_new *template)
129{ 129{
130 if (!strcmp(template->name, "Master Playback Volume")) { 130 if (!strcmp(template->name, "Stereo Upmixing"))
131 template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
132 template->tlv.p = ak4396_db_scale;
133 } else if (!strcmp(template->name, "Stereo Upmixing")) {
134 return 1; /* stereo only - we don't need upmixing */ 131 return 1; /* stereo only - we don't need upmixing */
135 } else if (!strcmp(template->name,
136 SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK)) ||
137 !strcmp(template->name,
138 SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT))) {
139 return 1; /* no digital input */
140 }
141 return 0;
142}
143
144static int hifier_mixer_init(struct oxygen *chip)
145{
146 return 0; 132 return 0;
147} 133}
148 134
@@ -153,18 +139,20 @@ static const struct oxygen_model model_hifier = {
153 .owner = THIS_MODULE, 139 .owner = THIS_MODULE,
154 .init = hifier_init, 140 .init = hifier_init,
155 .control_filter = hifier_control_filter, 141 .control_filter = hifier_control_filter,
156 .mixer_init = hifier_mixer_init,
157 .cleanup = hifier_cleanup, 142 .cleanup = hifier_cleanup,
158 .set_dac_params = set_ak4396_params, 143 .set_dac_params = set_ak4396_params,
159 .set_adc_params = set_cs5340_params, 144 .set_adc_params = set_cs5340_params,
160 .update_dac_volume = update_ak4396_volume, 145 .update_dac_volume = update_ak4396_volume,
161 .update_dac_mute = update_ak4396_mute, 146 .update_dac_mute = update_ak4396_mute,
147 .dac_tlv = ak4396_db_scale,
162 .model_data_size = sizeof(struct hifier_data), 148 .model_data_size = sizeof(struct hifier_data),
149 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
150 PLAYBACK_1_TO_SPDIF |
151 CAPTURE_0_FROM_I2S_1,
163 .dac_channels = 2, 152 .dac_channels = 2,
164 .used_channels = OXYGEN_CHANNEL_A | 153 .dac_volume_min = 0,
165 OXYGEN_CHANNEL_SPDIF | 154 .dac_volume_max = 255,
166 OXYGEN_CHANNEL_MULTICH, 155 .function_flags = OXYGEN_FUNCTION_SPI,
167 .function_flags = 0,
168 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 156 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
169 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 157 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
170}; 158};
@@ -181,7 +169,7 @@ static int __devinit hifier_probe(struct pci_dev *pci,
181 ++dev; 169 ++dev;
182 return -ENOENT; 170 return -ENOENT;
183 } 171 }
184 err = oxygen_pci_probe(pci, index[dev], id[dev], 0, &model_hifier); 172 err = oxygen_pci_probe(pci, index[dev], id[dev], &model_hifier);
185 if (err >= 0) 173 if (err >= 0)
186 ++dev; 174 ++dev;
187 return err; 175 return err;
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index 9a9941bb0460..63f185c1ed1e 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -39,7 +39,7 @@
39#include <sound/tlv.h> 39#include <sound/tlv.h>
40#include "oxygen.h" 40#include "oxygen.h"
41#include "ak4396.h" 41#include "ak4396.h"
42#include "cm9780.h" 42#include "wm8785.h"
43 43
44MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 44MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
45MODULE_DESCRIPTION("C-Media CMI8788 driver"); 45MODULE_DESCRIPTION("C-Media CMI8788 driver");
@@ -78,49 +78,6 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids);
78#define GPIO_AK5385_DFS_DOUBLE 0x0001 78#define GPIO_AK5385_DFS_DOUBLE 0x0001
79#define GPIO_AK5385_DFS_QUAD 0x0002 79#define GPIO_AK5385_DFS_QUAD 0x0002
80 80
81#define GPIO_LINE_MUTE CM9780_GPO0
82
83#define WM8785_R0 0
84#define WM8785_R1 1
85#define WM8785_R2 2
86#define WM8785_R7 7
87
88/* R0 */
89#define WM8785_MCR_MASK 0x007
90#define WM8785_MCR_SLAVE 0x000
91#define WM8785_MCR_MASTER_128 0x001
92#define WM8785_MCR_MASTER_192 0x002
93#define WM8785_MCR_MASTER_256 0x003
94#define WM8785_MCR_MASTER_384 0x004
95#define WM8785_MCR_MASTER_512 0x005
96#define WM8785_MCR_MASTER_768 0x006
97#define WM8785_OSR_MASK 0x018
98#define WM8785_OSR_SINGLE 0x000
99#define WM8785_OSR_DOUBLE 0x008
100#define WM8785_OSR_QUAD 0x010
101#define WM8785_FORMAT_MASK 0x060
102#define WM8785_FORMAT_RJUST 0x000
103#define WM8785_FORMAT_LJUST 0x020
104#define WM8785_FORMAT_I2S 0x040
105#define WM8785_FORMAT_DSP 0x060
106/* R1 */
107#define WM8785_WL_MASK 0x003
108#define WM8785_WL_16 0x000
109#define WM8785_WL_20 0x001
110#define WM8785_WL_24 0x002
111#define WM8785_WL_32 0x003
112#define WM8785_LRP 0x004
113#define WM8785_BCLKINV 0x008
114#define WM8785_LRSWAP 0x010
115#define WM8785_DEVNO_MASK 0x0e0
116/* R2 */
117#define WM8785_HPFR 0x001
118#define WM8785_HPFL 0x002
119#define WM8785_SDODIS 0x004
120#define WM8785_PWRDNR 0x008
121#define WM8785_PWRDNL 0x010
122#define WM8785_TDM_MASK 0x1c0
123
124struct generic_data { 81struct generic_data {
125 u8 ak4396_ctl2; 82 u8 ak4396_ctl2;
126}; 83};
@@ -155,7 +112,7 @@ static void ak4396_init(struct oxygen *chip)
155 struct generic_data *data = chip->model_data; 112 struct generic_data *data = chip->model_data;
156 unsigned int i; 113 unsigned int i;
157 114
158 data->ak4396_ctl2 = AK4396_DEM_OFF | AK4396_DFS_NORMAL; 115 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
159 for (i = 0; i < 4; ++i) { 116 for (i = 0; i < 4; ++i) {
160 ak4396_write(chip, i, 117 ak4396_write(chip, i,
161 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 118 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
@@ -163,8 +120,8 @@ static void ak4396_init(struct oxygen *chip)
163 AK4396_CONTROL_2, data->ak4396_ctl2); 120 AK4396_CONTROL_2, data->ak4396_ctl2);
164 ak4396_write(chip, i, 121 ak4396_write(chip, i,
165 AK4396_CONTROL_3, AK4396_PCM); 122 AK4396_CONTROL_3, AK4396_PCM);
166 ak4396_write(chip, i, AK4396_LCH_ATT, 0xff); 123 ak4396_write(chip, i, AK4396_LCH_ATT, 0);
167 ak4396_write(chip, i, AK4396_RCH_ATT, 0xff); 124 ak4396_write(chip, i, AK4396_RCH_ATT, 0);
168 } 125 }
169 snd_component_add(chip->card, "AK4396"); 126 snd_component_add(chip->card, "AK4396");
170} 127}
@@ -185,23 +142,16 @@ static void wm8785_init(struct oxygen *chip)
185 snd_component_add(chip->card, "WM8785"); 142 snd_component_add(chip->card, "WM8785");
186} 143}
187 144
188static void cmi9780_init(struct oxygen *chip)
189{
190 oxygen_ac97_clear_bits(chip, 0, CM9780_GPIO_STATUS, GPIO_LINE_MUTE);
191}
192
193static void generic_init(struct oxygen *chip) 145static void generic_init(struct oxygen *chip)
194{ 146{
195 ak4396_init(chip); 147 ak4396_init(chip);
196 wm8785_init(chip); 148 wm8785_init(chip);
197 cmi9780_init(chip);
198} 149}
199 150
200static void meridian_init(struct oxygen *chip) 151static void meridian_init(struct oxygen *chip)
201{ 152{
202 ak4396_init(chip); 153 ak4396_init(chip);
203 ak5385_init(chip); 154 ak5385_init(chip);
204 cmi9780_init(chip);
205} 155}
206 156
207static void generic_cleanup(struct oxygen *chip) 157static void generic_cleanup(struct oxygen *chip)
@@ -297,59 +247,32 @@ static void set_ak5385_params(struct oxygen *chip,
297 value, GPIO_AK5385_DFS_MASK); 247 value, GPIO_AK5385_DFS_MASK);
298} 248}
299 249
300static void cmi9780_switch_hook(struct oxygen *chip, unsigned int codec,
301 unsigned int reg, int mute)
302{
303 if (codec != 0)
304 return;
305 switch (reg) {
306 case AC97_LINE:
307 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
308 mute ? GPIO_LINE_MUTE : 0,
309 GPIO_LINE_MUTE);
310 break;
311 case AC97_MIC:
312 case AC97_CD:
313 case AC97_AUX:
314 if (!mute)
315 oxygen_ac97_set_bits(chip, 0, CM9780_GPIO_STATUS,
316 GPIO_LINE_MUTE);
317 break;
318 }
319}
320
321static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 250static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
322 251
323static int ak4396_control_filter(struct snd_kcontrol_new *template)
324{
325 if (!strcmp(template->name, "Master Playback Volume")) {
326 template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
327 template->tlv.p = ak4396_db_scale;
328 }
329 return 0;
330}
331
332static const struct oxygen_model model_generic = { 252static const struct oxygen_model model_generic = {
333 .shortname = "C-Media CMI8788", 253 .shortname = "C-Media CMI8788",
334 .longname = "C-Media Oxygen HD Audio", 254 .longname = "C-Media Oxygen HD Audio",
335 .chip = "CMI8788", 255 .chip = "CMI8788",
336 .owner = THIS_MODULE, 256 .owner = THIS_MODULE,
337 .init = generic_init, 257 .init = generic_init,
338 .control_filter = ak4396_control_filter,
339 .cleanup = generic_cleanup, 258 .cleanup = generic_cleanup,
340 .set_dac_params = set_ak4396_params, 259 .set_dac_params = set_ak4396_params,
341 .set_adc_params = set_wm8785_params, 260 .set_adc_params = set_wm8785_params,
342 .update_dac_volume = update_ak4396_volume, 261 .update_dac_volume = update_ak4396_volume,
343 .update_dac_mute = update_ak4396_mute, 262 .update_dac_mute = update_ak4396_mute,
344 .ac97_switch_hook = cmi9780_switch_hook, 263 .dac_tlv = ak4396_db_scale,
345 .model_data_size = sizeof(struct generic_data), 264 .model_data_size = sizeof(struct generic_data),
265 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
266 PLAYBACK_1_TO_SPDIF |
267 PLAYBACK_2_TO_AC97_1 |
268 CAPTURE_0_FROM_I2S_1 |
269 CAPTURE_1_FROM_SPDIF |
270 CAPTURE_2_FROM_AC97_1,
346 .dac_channels = 8, 271 .dac_channels = 8,
347 .used_channels = OXYGEN_CHANNEL_A | 272 .dac_volume_min = 0,
348 OXYGEN_CHANNEL_C | 273 .dac_volume_max = 255,
349 OXYGEN_CHANNEL_SPDIF | 274 .function_flags = OXYGEN_FUNCTION_SPI |
350 OXYGEN_CHANNEL_MULTICH | 275 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
351 OXYGEN_CHANNEL_AC97,
352 .function_flags = OXYGEN_FUNCTION_ENABLE_SPI_4_5,
353 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 276 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
354 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 277 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
355}; 278};
@@ -359,21 +282,25 @@ static const struct oxygen_model model_meridian = {
359 .chip = "CMI8788", 282 .chip = "CMI8788",
360 .owner = THIS_MODULE, 283 .owner = THIS_MODULE,
361 .init = meridian_init, 284 .init = meridian_init,
362 .control_filter = ak4396_control_filter,
363 .cleanup = generic_cleanup, 285 .cleanup = generic_cleanup,
364 .set_dac_params = set_ak4396_params, 286 .set_dac_params = set_ak4396_params,
365 .set_adc_params = set_ak5385_params, 287 .set_adc_params = set_ak5385_params,
366 .update_dac_volume = update_ak4396_volume, 288 .update_dac_volume = update_ak4396_volume,
367 .update_dac_mute = update_ak4396_mute, 289 .update_dac_mute = update_ak4396_mute,
368 .ac97_switch_hook = cmi9780_switch_hook, 290 .dac_tlv = ak4396_db_scale,
369 .model_data_size = sizeof(struct generic_data), 291 .model_data_size = sizeof(struct generic_data),
292 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
293 PLAYBACK_1_TO_SPDIF |
294 PLAYBACK_2_TO_AC97_1 |
295 CAPTURE_0_FROM_I2S_2 |
296 CAPTURE_1_FROM_SPDIF |
297 CAPTURE_2_FROM_AC97_1,
370 .dac_channels = 8, 298 .dac_channels = 8,
371 .used_channels = OXYGEN_CHANNEL_B | 299 .dac_volume_min = 0,
372 OXYGEN_CHANNEL_C | 300 .dac_volume_max = 255,
373 OXYGEN_CHANNEL_SPDIF | 301 .misc_flags = OXYGEN_MISC_MIDI,
374 OXYGEN_CHANNEL_MULTICH | 302 .function_flags = OXYGEN_FUNCTION_SPI |
375 OXYGEN_CHANNEL_AC97, 303 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
376 .function_flags = OXYGEN_FUNCTION_ENABLE_SPI_4_5,
377 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 304 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
378 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 305 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
379}; 306};
@@ -392,7 +319,7 @@ static int __devinit generic_oxygen_probe(struct pci_dev *pci,
392 return -ENOENT; 319 return -ENOENT;
393 } 320 }
394 is_meridian = pci_id->driver_data; 321 is_meridian = pci_id->driver_data;
395 err = oxygen_pci_probe(pci, index[dev], id[dev], is_meridian, 322 err = oxygen_pci_probe(pci, index[dev], id[dev],
396 is_meridian ? &model_meridian : &model_generic); 323 is_meridian ? &model_meridian : &model_generic);
397 if (err >= 0) 324 if (err >= 0)
398 ++dev; 325 ++dev;
diff --git a/sound/pci/oxygen/oxygen.h b/sound/pci/oxygen/oxygen.h
index ad50fb8b206b..a71c6e059260 100644
--- a/sound/pci/oxygen/oxygen.h
+++ b/sound/pci/oxygen/oxygen.h
@@ -16,6 +16,16 @@
16#define PCM_AC97 5 16#define PCM_AC97 5
17#define PCM_COUNT 6 17#define PCM_COUNT 6
18 18
19/* model-specific configuration of outputs/inputs */
20#define PLAYBACK_0_TO_I2S 0x001
21#define PLAYBACK_1_TO_SPDIF 0x004
22#define PLAYBACK_2_TO_AC97_1 0x008
23#define CAPTURE_0_FROM_I2S_1 0x010
24#define CAPTURE_0_FROM_I2S_2 0x020
25#define CAPTURE_1_FROM_SPDIF 0x080
26#define CAPTURE_2_FROM_I2S_2 0x100
27#define CAPTURE_2_FROM_AC97_1 0x200
28
19enum { 29enum {
20 CONTROL_SPDIF_PCM, 30 CONTROL_SPDIF_PCM,
21 CONTROL_SPDIF_INPUT_BITS, 31 CONTROL_SPDIF_INPUT_BITS,
@@ -87,12 +97,16 @@ struct oxygen_model {
87 struct snd_pcm_hw_params *params); 97 struct snd_pcm_hw_params *params);
88 void (*update_dac_volume)(struct oxygen *chip); 98 void (*update_dac_volume)(struct oxygen *chip);
89 void (*update_dac_mute)(struct oxygen *chip); 99 void (*update_dac_mute)(struct oxygen *chip);
90 void (*ac97_switch_hook)(struct oxygen *chip, unsigned int codec,
91 unsigned int reg, int mute);
92 void (*gpio_changed)(struct oxygen *chip); 100 void (*gpio_changed)(struct oxygen *chip);
101 void (*ac97_switch)(struct oxygen *chip,
102 unsigned int reg, unsigned int mute);
103 const unsigned int *dac_tlv;
93 size_t model_data_size; 104 size_t model_data_size;
105 unsigned int pcm_dev_cfg;
94 u8 dac_channels; 106 u8 dac_channels;
95 u8 used_channels; 107 u8 dac_volume_min;
108 u8 dac_volume_max;
109 u8 misc_flags;
96 u8 function_flags; 110 u8 function_flags;
97 u16 dac_i2s_format; 111 u16 dac_i2s_format;
98 u16 adc_i2s_format; 112 u16 adc_i2s_format;
@@ -100,7 +114,7 @@ struct oxygen_model {
100 114
101/* oxygen_lib.c */ 115/* oxygen_lib.c */
102 116
103int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, int midi, 117int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
104 const struct oxygen_model *model); 118 const struct oxygen_model *model);
105void oxygen_pci_remove(struct pci_dev *pci); 119void oxygen_pci_remove(struct pci_dev *pci);
106 120
@@ -137,6 +151,7 @@ void oxygen_write_ac97_masked(struct oxygen *chip, unsigned int codec,
137 unsigned int index, u16 data, u16 mask); 151 unsigned int index, u16 data, u16 mask);
138 152
139void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data); 153void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data);
154void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data);
140 155
141static inline void oxygen_set_bits8(struct oxygen *chip, 156static inline void oxygen_set_bits8(struct oxygen *chip,
142 unsigned int reg, u8 value) 157 unsigned int reg, u8 value)
diff --git a/sound/pci/oxygen/oxygen_io.c b/sound/pci/oxygen/oxygen_io.c
index 74e23ef9c946..5569606ee87f 100644
--- a/sound/pci/oxygen/oxygen_io.c
+++ b/sound/pci/oxygen/oxygen_io.c
@@ -190,12 +190,31 @@ void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data)
190 --count; 190 --count;
191 } 191 }
192 192
193 spin_lock_irq(&chip->reg_lock);
194 oxygen_write8(chip, OXYGEN_SPI_DATA1, data); 193 oxygen_write8(chip, OXYGEN_SPI_DATA1, data);
195 oxygen_write8(chip, OXYGEN_SPI_DATA2, data >> 8); 194 oxygen_write8(chip, OXYGEN_SPI_DATA2, data >> 8);
196 if (control & OXYGEN_SPI_DATA_LENGTH_3) 195 if (control & OXYGEN_SPI_DATA_LENGTH_3)
197 oxygen_write8(chip, OXYGEN_SPI_DATA3, data >> 16); 196 oxygen_write8(chip, OXYGEN_SPI_DATA3, data >> 16);
198 oxygen_write8(chip, OXYGEN_SPI_CONTROL, control); 197 oxygen_write8(chip, OXYGEN_SPI_CONTROL, control);
199 spin_unlock_irq(&chip->reg_lock);
200} 198}
201EXPORT_SYMBOL(oxygen_write_spi); 199EXPORT_SYMBOL(oxygen_write_spi);
200
201void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data)
202{
203 unsigned long timeout;
204
205 /* should not need more than about 300 us */
206 timeout = jiffies + msecs_to_jiffies(1);
207 do {
208 if (!(oxygen_read16(chip, OXYGEN_2WIRE_BUS_STATUS)
209 & OXYGEN_2WIRE_BUSY))
210 break;
211 udelay(1);
212 cond_resched();
213 } while (time_after_eq(timeout, jiffies));
214
215 oxygen_write8(chip, OXYGEN_2WIRE_MAP, map);
216 oxygen_write8(chip, OXYGEN_2WIRE_DATA, data);
217 oxygen_write8(chip, OXYGEN_2WIRE_CONTROL,
218 device | OXYGEN_2WIRE_DIR_WRITE);
219}
220EXPORT_SYMBOL(oxygen_write_i2c);
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 78c21155218e..897697d43506 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -221,7 +221,8 @@ static void oxygen_init(struct oxygen *chip)
221 221
222 chip->dac_routing = 1; 222 chip->dac_routing = 1;
223 for (i = 0; i < 8; ++i) 223 for (i = 0; i < 8; ++i)
224 chip->dac_volume[i] = 0xff; 224 chip->dac_volume[i] = chip->model->dac_volume_min;
225 chip->dac_mute = 1;
225 chip->spdif_playback_enable = 1; 226 chip->spdif_playback_enable = 1;
226 chip->spdif_bits = OXYGEN_SPDIF_C | OXYGEN_SPDIF_ORIGINAL | 227 chip->spdif_bits = OXYGEN_SPDIF_C | OXYGEN_SPDIF_ORIGINAL |
227 (IEC958_AES1_CON_PCM_CODER << OXYGEN_SPDIF_CATEGORY_SHIFT); 228 (IEC958_AES1_CON_PCM_CODER << OXYGEN_SPDIF_CATEGORY_SHIFT);
@@ -240,12 +241,12 @@ static void oxygen_init(struct oxygen *chip)
240 chip->has_ac97_0 = (i & OXYGEN_AC97_CODEC_0) != 0; 241 chip->has_ac97_0 = (i & OXYGEN_AC97_CODEC_0) != 0;
241 chip->has_ac97_1 = (i & OXYGEN_AC97_CODEC_1) != 0; 242 chip->has_ac97_1 = (i & OXYGEN_AC97_CODEC_1) != 0;
242 243
243 oxygen_set_bits8(chip, OXYGEN_FUNCTION,
244 OXYGEN_FUNCTION_RESET_CODEC |
245 chip->model->function_flags);
246 oxygen_write8_masked(chip, OXYGEN_FUNCTION, 244 oxygen_write8_masked(chip, OXYGEN_FUNCTION,
247 OXYGEN_FUNCTION_SPI, 245 OXYGEN_FUNCTION_RESET_CODEC |
248 OXYGEN_FUNCTION_2WIRE_SPI_MASK); 246 chip->model->function_flags,
247 OXYGEN_FUNCTION_RESET_CODEC |
248 OXYGEN_FUNCTION_2WIRE_SPI_MASK |
249 OXYGEN_FUNCTION_ENABLE_SPI_4_5);
249 oxygen_write8(chip, OXYGEN_DMA_STATUS, 0); 250 oxygen_write8(chip, OXYGEN_DMA_STATUS, 0);
250 oxygen_write8(chip, OXYGEN_DMA_PAUSE, 0); 251 oxygen_write8(chip, OXYGEN_DMA_PAUSE, 0);
251 oxygen_write8(chip, OXYGEN_PLAY_CHANNELS, 252 oxygen_write8(chip, OXYGEN_PLAY_CHANNELS,
@@ -253,11 +254,13 @@ static void oxygen_init(struct oxygen *chip)
253 OXYGEN_DMA_A_BURST_8 | 254 OXYGEN_DMA_A_BURST_8 |
254 OXYGEN_DMA_MULTICH_BURST_8); 255 OXYGEN_DMA_MULTICH_BURST_8);
255 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0); 256 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0);
256 oxygen_write8_masked(chip, OXYGEN_MISC, 0, 257 oxygen_write8_masked(chip, OXYGEN_MISC,
258 chip->model->misc_flags,
257 OXYGEN_MISC_WRITE_PCI_SUBID | 259 OXYGEN_MISC_WRITE_PCI_SUBID |
258 OXYGEN_MISC_REC_C_FROM_SPDIF | 260 OXYGEN_MISC_REC_C_FROM_SPDIF |
259 OXYGEN_MISC_REC_B_FROM_AC97 | 261 OXYGEN_MISC_REC_B_FROM_AC97 |
260 OXYGEN_MISC_REC_A_FROM_MULTICH); 262 OXYGEN_MISC_REC_A_FROM_MULTICH |
263 OXYGEN_MISC_MIDI);
261 oxygen_write8(chip, OXYGEN_REC_FORMAT, 264 oxygen_write8(chip, OXYGEN_REC_FORMAT,
262 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_A_SHIFT) | 265 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_A_SHIFT) |
263 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_B_SHIFT) | 266 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_B_SHIFT) |
@@ -267,35 +270,49 @@ static void oxygen_init(struct oxygen *chip)
267 (OXYGEN_FORMAT_16 << OXYGEN_MULTICH_FORMAT_SHIFT)); 270 (OXYGEN_FORMAT_16 << OXYGEN_MULTICH_FORMAT_SHIFT));
268 oxygen_write8(chip, OXYGEN_REC_CHANNELS, OXYGEN_REC_CHANNELS_2_2_2); 271 oxygen_write8(chip, OXYGEN_REC_CHANNELS, OXYGEN_REC_CHANNELS_2_2_2);
269 oxygen_write16(chip, OXYGEN_I2S_MULTICH_FORMAT, 272 oxygen_write16(chip, OXYGEN_I2S_MULTICH_FORMAT,
270 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST | 273 OXYGEN_RATE_48000 | chip->model->dac_i2s_format |
271 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 | 274 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
272 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
273 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
274 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST |
275 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
276 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
277 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
278 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST |
279 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
280 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 275 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
276 if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1)
277 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
278 OXYGEN_RATE_48000 | chip->model->adc_i2s_format |
279 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
280 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
281 else
282 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
283 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK);
284 if (chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_2 |
285 CAPTURE_2_FROM_I2S_2))
286 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
287 OXYGEN_RATE_48000 | chip->model->adc_i2s_format |
288 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
289 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
290 else
291 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
292 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK);
281 oxygen_write16(chip, OXYGEN_I2S_C_FORMAT, 293 oxygen_write16(chip, OXYGEN_I2S_C_FORMAT,
282 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST | 294 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK);
283 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 | 295 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
284 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 296 OXYGEN_SPDIF_OUT_ENABLE |
285 oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL, 297 OXYGEN_SPDIF_LOOPBACK);
286 OXYGEN_SPDIF_SENSE_MASK | 298 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF)
287 OXYGEN_SPDIF_LOCK_MASK | 299 oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL,
288 OXYGEN_SPDIF_RATE_MASK | 300 OXYGEN_SPDIF_SENSE_MASK |
289 OXYGEN_SPDIF_LOCK_PAR | 301 OXYGEN_SPDIF_LOCK_MASK |
290 OXYGEN_SPDIF_IN_CLOCK_96, 302 OXYGEN_SPDIF_RATE_MASK |
291 OXYGEN_SPDIF_OUT_ENABLE | 303 OXYGEN_SPDIF_LOCK_PAR |
292 OXYGEN_SPDIF_LOOPBACK | 304 OXYGEN_SPDIF_IN_CLOCK_96,
293 OXYGEN_SPDIF_SENSE_MASK | 305 OXYGEN_SPDIF_SENSE_MASK |
294 OXYGEN_SPDIF_LOCK_MASK | 306 OXYGEN_SPDIF_LOCK_MASK |
295 OXYGEN_SPDIF_RATE_MASK | 307 OXYGEN_SPDIF_RATE_MASK |
296 OXYGEN_SPDIF_SENSE_PAR | 308 OXYGEN_SPDIF_SENSE_PAR |
297 OXYGEN_SPDIF_LOCK_PAR | 309 OXYGEN_SPDIF_LOCK_PAR |
298 OXYGEN_SPDIF_IN_CLOCK_MASK); 310 OXYGEN_SPDIF_IN_CLOCK_MASK);
311 else
312 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
313 OXYGEN_SPDIF_SENSE_MASK |
314 OXYGEN_SPDIF_LOCK_MASK |
315 OXYGEN_SPDIF_RATE_MASK);
299 oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, chip->spdif_bits); 316 oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, chip->spdif_bits);
300 oxygen_clear_bits8(chip, OXYGEN_MPU401_CONTROL, OXYGEN_MPU401_LOOPBACK); 317 oxygen_clear_bits8(chip, OXYGEN_MPU401_CONTROL, OXYGEN_MPU401_LOOPBACK);
301 oxygen_write8(chip, OXYGEN_GPI_INTERRUPT_MASK, 0); 318 oxygen_write8(chip, OXYGEN_GPI_INTERRUPT_MASK, 0);
@@ -318,9 +335,12 @@ static void oxygen_init(struct oxygen *chip)
318 (2 << OXYGEN_A_MONITOR_ROUTE_2_SHIFT) | 335 (2 << OXYGEN_A_MONITOR_ROUTE_2_SHIFT) |
319 (3 << OXYGEN_A_MONITOR_ROUTE_3_SHIFT)); 336 (3 << OXYGEN_A_MONITOR_ROUTE_3_SHIFT));
320 337
321 oxygen_write8(chip, OXYGEN_AC97_INTERRUPT_MASK, 338 if (chip->has_ac97_0 | chip->has_ac97_1)
322 OXYGEN_AC97_INT_READ_DONE | 339 oxygen_write8(chip, OXYGEN_AC97_INTERRUPT_MASK,
323 OXYGEN_AC97_INT_WRITE_DONE); 340 OXYGEN_AC97_INT_READ_DONE |
341 OXYGEN_AC97_INT_WRITE_DONE);
342 else
343 oxygen_write8(chip, OXYGEN_AC97_INTERRUPT_MASK, 0);
324 oxygen_write32(chip, OXYGEN_AC97_OUT_CONFIG, 0); 344 oxygen_write32(chip, OXYGEN_AC97_OUT_CONFIG, 0);
325 oxygen_write32(chip, OXYGEN_AC97_IN_CONFIG, 0); 345 oxygen_write32(chip, OXYGEN_AC97_IN_CONFIG, 0);
326 if (!(chip->has_ac97_0 | chip->has_ac97_1)) 346 if (!(chip->has_ac97_0 | chip->has_ac97_1))
@@ -351,6 +371,8 @@ static void oxygen_init(struct oxygen *chip)
351 oxygen_write_ac97(chip, 0, AC97_REC_GAIN, 0x8000); 371 oxygen_write_ac97(chip, 0, AC97_REC_GAIN, 0x8000);
352 oxygen_write_ac97(chip, 0, AC97_CENTER_LFE_MASTER, 0x8080); 372 oxygen_write_ac97(chip, 0, AC97_CENTER_LFE_MASTER, 0x8080);
353 oxygen_write_ac97(chip, 0, AC97_SURROUND_MASTER, 0x8080); 373 oxygen_write_ac97(chip, 0, AC97_SURROUND_MASTER, 0x8080);
374 oxygen_ac97_clear_bits(chip, 0, CM9780_GPIO_STATUS,
375 CM9780_GPO0);
354 /* power down unused ADCs and DACs */ 376 /* power down unused ADCs and DACs */
355 oxygen_ac97_set_bits(chip, 0, AC97_POWERDOWN, 377 oxygen_ac97_set_bits(chip, 0, AC97_POWERDOWN,
356 AC97_PD_PR0 | AC97_PD_PR1); 378 AC97_PD_PR0 | AC97_PD_PR1);
@@ -388,10 +410,8 @@ static void oxygen_card_free(struct snd_card *card)
388 oxygen_write16(chip, OXYGEN_DMA_STATUS, 0); 410 oxygen_write16(chip, OXYGEN_DMA_STATUS, 0);
389 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0); 411 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0);
390 spin_unlock_irq(&chip->reg_lock); 412 spin_unlock_irq(&chip->reg_lock);
391 if (chip->irq >= 0) { 413 if (chip->irq >= 0)
392 free_irq(chip->irq, chip); 414 free_irq(chip->irq, chip);
393 synchronize_irq(chip->irq);
394 }
395 flush_scheduled_work(); 415 flush_scheduled_work();
396 chip->model->cleanup(chip); 416 chip->model->cleanup(chip);
397 mutex_destroy(&chip->mutex); 417 mutex_destroy(&chip->mutex);
@@ -400,7 +420,7 @@ static void oxygen_card_free(struct snd_card *card)
400} 420}
401 421
402int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, 422int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
403 int midi, const struct oxygen_model *model) 423 const struct oxygen_model *model)
404{ 424{
405 struct snd_card *card; 425 struct snd_card *card;
406 struct oxygen *chip; 426 struct oxygen *chip;
@@ -472,9 +492,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
472 if (err < 0) 492 if (err < 0)
473 goto err_card; 493 goto err_card;
474 494
475 oxygen_write8_masked(chip, OXYGEN_MISC, 495 if (model->misc_flags & OXYGEN_MISC_MIDI) {
476 midi ? OXYGEN_MISC_MIDI : 0, OXYGEN_MISC_MIDI);
477 if (midi) {
478 err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, 496 err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
479 chip->addr + OXYGEN_MPU401, 497 chip->addr + OXYGEN_MPU401,
480 MPU401_INFO_INTEGRATED, 0, 0, 498 MPU401_INFO_INTEGRATED, 0, 0,
@@ -486,7 +504,10 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
486 oxygen_proc_init(chip); 504 oxygen_proc_init(chip);
487 505
488 spin_lock_irq(&chip->reg_lock); 506 spin_lock_irq(&chip->reg_lock);
489 chip->interrupt_mask |= OXYGEN_INT_SPDIF_IN_DETECT | OXYGEN_INT_AC97; 507 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF)
508 chip->interrupt_mask |= OXYGEN_INT_SPDIF_IN_DETECT;
509 if (chip->has_ac97_0 | chip->has_ac97_1)
510 chip->interrupt_mask |= OXYGEN_INT_AC97;
490 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask); 511 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask);
491 spin_unlock_irq(&chip->reg_lock); 512 spin_unlock_irq(&chip->reg_lock);
492 513
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index a8e4623415d9..cc0cddadd589 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -32,8 +32,8 @@ static int dac_volume_info(struct snd_kcontrol *ctl,
32 32
33 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 33 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
34 info->count = chip->model->dac_channels; 34 info->count = chip->model->dac_channels;
35 info->value.integer.min = 0; 35 info->value.integer.min = chip->model->dac_volume_min;
36 info->value.integer.max = 0xff; 36 info->value.integer.max = chip->model->dac_volume_max;
37 return 0; 37 return 0;
38} 38}
39 39
@@ -446,6 +446,50 @@ static int spdif_loopback_put(struct snd_kcontrol *ctl,
446 return changed; 446 return changed;
447} 447}
448 448
449static int monitor_volume_info(struct snd_kcontrol *ctl,
450 struct snd_ctl_elem_info *info)
451{
452 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
453 info->count = 1;
454 info->value.integer.min = 0;
455 info->value.integer.max = 1;
456 return 0;
457}
458
459static int monitor_get(struct snd_kcontrol *ctl,
460 struct snd_ctl_elem_value *value)
461{
462 struct oxygen *chip = ctl->private_data;
463 u8 bit = ctl->private_value;
464 int invert = ctl->private_value & (1 << 8);
465
466 value->value.integer.value[0] =
467 !!invert ^ !!(oxygen_read8(chip, OXYGEN_ADC_MONITOR) & bit);
468 return 0;
469}
470
471static int monitor_put(struct snd_kcontrol *ctl,
472 struct snd_ctl_elem_value *value)
473{
474 struct oxygen *chip = ctl->private_data;
475 u8 bit = ctl->private_value;
476 int invert = ctl->private_value & (1 << 8);
477 u8 oldreg, newreg;
478 int changed;
479
480 spin_lock_irq(&chip->reg_lock);
481 oldreg = oxygen_read8(chip, OXYGEN_ADC_MONITOR);
482 if ((!!value->value.integer.value[0] ^ !!invert) != 0)
483 newreg = oldreg | bit;
484 else
485 newreg = oldreg & ~bit;
486 changed = newreg != oldreg;
487 if (changed)
488 oxygen_write8(chip, OXYGEN_ADC_MONITOR, newreg);
489 spin_unlock_irq(&chip->reg_lock);
490 return changed;
491}
492
449static int ac97_switch_get(struct snd_kcontrol *ctl, 493static int ac97_switch_get(struct snd_kcontrol *ctl,
450 struct snd_ctl_elem_value *value) 494 struct snd_ctl_elem_value *value)
451{ 495{
@@ -466,6 +510,21 @@ static int ac97_switch_get(struct snd_kcontrol *ctl,
466 return 0; 510 return 0;
467} 511}
468 512
513static void mute_ac97_ctl(struct oxygen *chip, unsigned int control)
514{
515 unsigned int priv_idx = chip->controls[control]->private_value & 0xff;
516 u16 value;
517
518 value = oxygen_read_ac97(chip, 0, priv_idx);
519 if (!(value & 0x8000)) {
520 oxygen_write_ac97(chip, 0, priv_idx, value | 0x8000);
521 if (chip->model->ac97_switch)
522 chip->model->ac97_switch(chip, priv_idx, 0x8000);
523 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
524 &chip->controls[control]->id);
525 }
526}
527
469static int ac97_switch_put(struct snd_kcontrol *ctl, 528static int ac97_switch_put(struct snd_kcontrol *ctl,
470 struct snd_ctl_elem_value *value) 529 struct snd_ctl_elem_value *value)
471{ 530{
@@ -487,9 +546,24 @@ static int ac97_switch_put(struct snd_kcontrol *ctl,
487 change = newreg != oldreg; 546 change = newreg != oldreg;
488 if (change) { 547 if (change) {
489 oxygen_write_ac97(chip, codec, index, newreg); 548 oxygen_write_ac97(chip, codec, index, newreg);
490 if (bitnr == 15 && chip->model->ac97_switch_hook) 549 if (codec == 0 && chip->model->ac97_switch)
491 chip->model->ac97_switch_hook(chip, codec, index, 550 chip->model->ac97_switch(chip, index, newreg & 0x8000);
492 newreg & 0x8000); 551 if (index == AC97_LINE) {
552 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
553 newreg & 0x8000 ?
554 CM9780_GPO0 : 0, CM9780_GPO0);
555 if (!(newreg & 0x8000)) {
556 mute_ac97_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH);
557 mute_ac97_ctl(chip, CONTROL_CD_CAPTURE_SWITCH);
558 mute_ac97_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH);
559 }
560 } else if ((index == AC97_MIC || index == AC97_CD ||
561 index == AC97_VIDEO || index == AC97_AUX) &&
562 bitnr == 15 && !(newreg & 0x8000)) {
563 mute_ac97_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH);
564 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
565 CM9780_GPO0, CM9780_GPO0);
566 }
493 } 567 }
494 mutex_unlock(&chip->mutex); 568 mutex_unlock(&chip->mutex);
495 return change; 569 return change;
@@ -608,6 +682,7 @@ static int ac97_fp_rec_volume_put(struct snd_kcontrol *ctl,
608 .private_value = ((codec) << 24) | (index), \ 682 .private_value = ((codec) << 24) | (index), \
609 } 683 }
610 684
685static DECLARE_TLV_DB_SCALE(monitor_db_scale, -1000, 1000, 0);
611static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0); 686static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0);
612static DECLARE_TLV_DB_SCALE(ac97_rec_db_scale, 0, 150, 0); 687static DECLARE_TLV_DB_SCALE(ac97_rec_db_scale, 0, 150, 0);
613 688
@@ -667,6 +742,9 @@ static const struct snd_kcontrol_new controls[] = {
667 .get = spdif_pcm_get, 742 .get = spdif_pcm_get,
668 .put = spdif_pcm_put, 743 .put = spdif_pcm_put,
669 }, 744 },
745};
746
747static const struct snd_kcontrol_new spdif_input_controls[] = {
670 { 748 {
671 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 749 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
672 .device = 1, 750 .device = 1,
@@ -692,11 +770,118 @@ static const struct snd_kcontrol_new controls[] = {
692 }, 770 },
693}; 771};
694 772
773static const struct {
774 unsigned int pcm_dev;
775 struct snd_kcontrol_new controls[2];
776} monitor_controls[] = {
777 {
778 .pcm_dev = CAPTURE_0_FROM_I2S_1,
779 .controls = {
780 {
781 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
782 .name = "Analog Input Monitor Switch",
783 .info = snd_ctl_boolean_mono_info,
784 .get = monitor_get,
785 .put = monitor_put,
786 .private_value = OXYGEN_ADC_MONITOR_A,
787 },
788 {
789 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
790 .name = "Analog Input Monitor Volume",
791 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
792 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
793 .info = monitor_volume_info,
794 .get = monitor_get,
795 .put = monitor_put,
796 .private_value = OXYGEN_ADC_MONITOR_A_HALF_VOL
797 | (1 << 8),
798 .tlv = { .p = monitor_db_scale, },
799 },
800 },
801 },
802 {
803 .pcm_dev = CAPTURE_0_FROM_I2S_2,
804 .controls = {
805 {
806 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
807 .name = "Analog Input Monitor Switch",
808 .info = snd_ctl_boolean_mono_info,
809 .get = monitor_get,
810 .put = monitor_put,
811 .private_value = OXYGEN_ADC_MONITOR_B,
812 },
813 {
814 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
815 .name = "Analog Input Monitor Volume",
816 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
817 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
818 .info = monitor_volume_info,
819 .get = monitor_get,
820 .put = monitor_put,
821 .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL
822 | (1 << 8),
823 .tlv = { .p = monitor_db_scale, },
824 },
825 },
826 },
827 {
828 .pcm_dev = CAPTURE_2_FROM_I2S_2,
829 .controls = {
830 {
831 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
832 .name = "Analog Input Monitor Switch",
833 .index = 1,
834 .info = snd_ctl_boolean_mono_info,
835 .get = monitor_get,
836 .put = monitor_put,
837 .private_value = OXYGEN_ADC_MONITOR_B,
838 },
839 {
840 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
841 .name = "Analog Input Monitor Volume",
842 .index = 1,
843 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
844 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
845 .info = monitor_volume_info,
846 .get = monitor_get,
847 .put = monitor_put,
848 .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL
849 | (1 << 8),
850 .tlv = { .p = monitor_db_scale, },
851 },
852 },
853 },
854 {
855 .pcm_dev = CAPTURE_1_FROM_SPDIF,
856 .controls = {
857 {
858 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
859 .name = "Digital Input Monitor Switch",
860 .info = snd_ctl_boolean_mono_info,
861 .get = monitor_get,
862 .put = monitor_put,
863 .private_value = OXYGEN_ADC_MONITOR_C,
864 },
865 {
866 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
867 .name = "Digital Input Monitor Volume",
868 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
869 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
870 .info = monitor_volume_info,
871 .get = monitor_get,
872 .put = monitor_put,
873 .private_value = OXYGEN_ADC_MONITOR_C_HALF_VOL
874 | (1 << 8),
875 .tlv = { .p = monitor_db_scale, },
876 },
877 },
878 },
879};
880
695static const struct snd_kcontrol_new ac97_controls[] = { 881static const struct snd_kcontrol_new ac97_controls[] = {
696 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC), 882 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC),
697 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1), 883 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1),
698 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0), 884 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0),
699 AC97_VOLUME("Line Capture Volume", 0, AC97_LINE),
700 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1), 885 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1),
701 AC97_VOLUME("CD Capture Volume", 0, AC97_CD), 886 AC97_VOLUME("CD Capture Volume", 0, AC97_CD),
702 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1), 887 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1),
@@ -756,6 +941,11 @@ static int add_controls(struct oxygen *chip,
756 return err; 941 return err;
757 if (err == 1) 942 if (err == 1)
758 continue; 943 continue;
944 if (!strcmp(template.name, "Master Playback Volume") &&
945 chip->model->dac_tlv) {
946 template.tlv.p = chip->model->dac_tlv;
947 template.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
948 }
759 ctl = snd_ctl_new1(&template, chip); 949 ctl = snd_ctl_new1(&template, chip);
760 if (!ctl) 950 if (!ctl)
761 return -ENOMEM; 951 return -ENOMEM;
@@ -773,11 +963,26 @@ static int add_controls(struct oxygen *chip,
773 963
774int oxygen_mixer_init(struct oxygen *chip) 964int oxygen_mixer_init(struct oxygen *chip)
775{ 965{
966 unsigned int i;
776 int err; 967 int err;
777 968
778 err = add_controls(chip, controls, ARRAY_SIZE(controls)); 969 err = add_controls(chip, controls, ARRAY_SIZE(controls));
779 if (err < 0) 970 if (err < 0)
780 return err; 971 return err;
972 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF) {
973 err = add_controls(chip, spdif_input_controls,
974 ARRAY_SIZE(spdif_input_controls));
975 if (err < 0)
976 return err;
977 }
978 for (i = 0; i < ARRAY_SIZE(monitor_controls); ++i) {
979 if (!(chip->model->pcm_dev_cfg & monitor_controls[i].pcm_dev))
980 continue;
981 err = add_controls(chip, monitor_controls[i].controls,
982 ARRAY_SIZE(monitor_controls[i].controls));
983 if (err < 0)
984 return err;
985 }
781 if (chip->has_ac97_0) { 986 if (chip->has_ac97_0) {
782 err = add_controls(chip, ac97_controls, 987 err = add_controls(chip, ac97_controls,
783 ARRAY_SIZE(ac97_controls)); 988 ARRAY_SIZE(ac97_controls));
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index b70046aca657..b17c405e069d 100644
--- a/sound/pci/oxygen/oxygen_pcm.c
+++ b/sound/pci/oxygen/oxygen_pcm.c
@@ -119,7 +119,7 @@ static int oxygen_open(struct snd_pcm_substream *substream,
119 119
120 runtime->private_data = (void *)(uintptr_t)channel; 120 runtime->private_data = (void *)(uintptr_t)channel;
121 if (channel == PCM_B && chip->has_ac97_1 && 121 if (channel == PCM_B && chip->has_ac97_1 &&
122 (chip->model->used_channels & OXYGEN_CHANNEL_AC97)) 122 (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1))
123 runtime->hw = oxygen_ac97_hardware; 123 runtime->hw = oxygen_ac97_hardware;
124 else 124 else
125 runtime->hw = *oxygen_hardware[channel]; 125 runtime->hw = *oxygen_hardware[channel];
@@ -365,7 +365,7 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
365 return err; 365 return err;
366 366
367 is_ac97 = chip->has_ac97_1 && 367 is_ac97 = chip->has_ac97_1 &&
368 (chip->model->used_channels & OXYGEN_CHANNEL_AC97); 368 (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1);
369 369
370 spin_lock_irq(&chip->reg_lock); 370 spin_lock_irq(&chip->reg_lock);
371 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT, 371 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT,
@@ -640,34 +640,39 @@ int oxygen_pcm_init(struct oxygen *chip)
640 int outs, ins; 640 int outs, ins;
641 int err; 641 int err;
642 642
643 outs = 1; /* OXYGEN_CHANNEL_MULTICH is always used */ 643 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_0_TO_I2S);
644 ins = !!(chip->model->used_channels & (OXYGEN_CHANNEL_A | 644 ins = !!(chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_1 |
645 OXYGEN_CHANNEL_B)); 645 CAPTURE_0_FROM_I2S_2));
646 err = snd_pcm_new(chip->card, "Analog", 0, outs, ins, &pcm); 646 if (outs | ins) {
647 if (err < 0) 647 err = snd_pcm_new(chip->card, "Analog", 0, outs, ins, &pcm);
648 return err; 648 if (err < 0)
649 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &oxygen_multich_ops); 649 return err;
650 if (chip->model->used_channels & OXYGEN_CHANNEL_A) 650 if (outs)
651 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 651 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
652 &oxygen_rec_a_ops); 652 &oxygen_multich_ops);
653 else if (chip->model->used_channels & OXYGEN_CHANNEL_B) 653 if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1)
654 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 654 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
655 &oxygen_rec_b_ops); 655 &oxygen_rec_a_ops);
656 pcm->private_data = chip; 656 else if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_2)
657 pcm->private_free = oxygen_pcm_free; 657 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
658 strcpy(pcm->name, "Analog"); 658 &oxygen_rec_b_ops);
659 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream, 659 pcm->private_data = chip;
660 SNDRV_DMA_TYPE_DEV, 660 pcm->private_free = oxygen_pcm_free;
661 snd_dma_pci_data(chip->pci), 661 strcpy(pcm->name, "Analog");
662 512 * 1024, 2048 * 1024); 662 if (outs)
663 if (ins) 663 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
664 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, 664 SNDRV_DMA_TYPE_DEV,
665 SNDRV_DMA_TYPE_DEV, 665 snd_dma_pci_data(chip->pci),
666 snd_dma_pci_data(chip->pci), 666 512 * 1024, 2048 * 1024);
667 128 * 1024, 256 * 1024); 667 if (ins)
668 668 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
669 outs = !!(chip->model->used_channels & OXYGEN_CHANNEL_SPDIF); 669 SNDRV_DMA_TYPE_DEV,
670 ins = !!(chip->model->used_channels & OXYGEN_CHANNEL_C); 670 snd_dma_pci_data(chip->pci),
671 128 * 1024, 256 * 1024);
672 }
673
674 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_1_TO_SPDIF);
675 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF);
671 if (outs | ins) { 676 if (outs | ins) {
672 err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm); 677 err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm);
673 if (err < 0) 678 if (err < 0)
@@ -686,12 +691,13 @@ int oxygen_pcm_init(struct oxygen *chip)
686 128 * 1024, 256 * 1024); 691 128 * 1024, 256 * 1024);
687 } 692 }
688 693
689 outs = chip->has_ac97_1 && 694 if (chip->has_ac97_1) {
690 (chip->model->used_channels & OXYGEN_CHANNEL_AC97); 695 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_2_TO_AC97_1);
691 ins = outs || 696 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1);
692 (chip->model->used_channels & (OXYGEN_CHANNEL_A | 697 } else {
693 OXYGEN_CHANNEL_B)) 698 outs = 0;
694 == (OXYGEN_CHANNEL_A | OXYGEN_CHANNEL_B); 699 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_I2S_2);
700 }
695 if (outs | ins) { 701 if (outs | ins) {
696 err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2", 702 err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2",
697 2, outs, ins, &pcm); 703 2, outs, ins, &pcm);
diff --git a/sound/pci/oxygen/pcm1796.h b/sound/pci/oxygen/pcm1796.h
new file mode 100644
index 000000000000..698bf46c710c
--- /dev/null
+++ b/sound/pci/oxygen/pcm1796.h
@@ -0,0 +1,58 @@
1#ifndef PCM1796_H_INCLUDED
2#define PCM1796_H_INCLUDED
3
4/* register 16 */
5#define PCM1796_ATL_MASK 0xff
6/* register 17 */
7#define PCM1796_ATR_MASK 0xff
8/* register 18 */
9#define PCM1796_MUTE 0x01
10#define PCM1796_DME 0x02
11#define PCM1796_DMF_MASK 0x0c
12#define PCM1796_DMF_DISABLED 0x00
13#define PCM1796_DMF_48 0x04
14#define PCM1796_DMF_441 0x08
15#define PCM1796_DMF_32 0x0c
16#define PCM1796_FMT_MASK 0x70
17#define PCM1796_FMT_16_RJUST 0x00
18#define PCM1796_FMT_20_RJUST 0x10
19#define PCM1796_FMT_24_RJUST 0x20
20#define PCM1796_FMT_24_LJUST 0x30
21#define PCM1796_FMT_16_I2S 0x40
22#define PCM1796_FMT_24_I2S 0x50
23#define PCM1796_ATLD 0x80
24/* register 19 */
25#define PCM1796_INZD 0x01
26#define PCM1796_FLT_MASK 0x02
27#define PCM1796_FLT_SHARP 0x00
28#define PCM1796_FLT_SLOW 0x02
29#define PCM1796_DFMS 0x04
30#define PCM1796_OPE 0x10
31#define PCM1796_ATS_MASK 0x60
32#define PCM1796_ATS_1 0x00
33#define PCM1796_ATS_2 0x20
34#define PCM1796_ATS_4 0x40
35#define PCM1796_ATS_8 0x60
36#define PCM1796_REV 0x80
37/* register 20 */
38#define PCM1796_OS_MASK 0x03
39#define PCM1796_OS_64 0x00
40#define PCM1796_OS_32 0x01
41#define PCM1796_OS_128 0x02
42#define PCM1796_CHSL_MASK 0x04
43#define PCM1796_CHSL_LEFT 0x00
44#define PCM1796_CHSL_RIGHT 0x04
45#define PCM1796_MONO 0x08
46#define PCM1796_DFTH 0x10
47#define PCM1796_DSD 0x20
48#define PCM1796_SRST 0x40
49/* register 21 */
50#define PCM1796_PCMZ 0x01
51#define PCM1796_DZ_MASK 0x06
52/* register 22 */
53#define PCM1796_ZFGL 0x01
54#define PCM1796_ZFGR 0x02
55/* register 23 */
56#define PCM1796_ID_MASK 0x1f
57
58#endif
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index d163397b85cc..7f84fa5deca2 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -18,6 +18,9 @@
18 */ 18 */
19 19
20/* 20/*
21 * Xonar D2/D2X
22 * ------------
23 *
21 * CMI8788: 24 * CMI8788:
22 * 25 *
23 * SPI 0 -> 1st PCM1796 (front) 26 * SPI 0 -> 1st PCM1796 (front)
@@ -30,10 +33,33 @@
30 * GPIO 5 <- external power present (D2X only) 33 * GPIO 5 <- external power present (D2X only)
31 * GPIO 7 -> ALT 34 * GPIO 7 -> ALT
32 * GPIO 8 -> enable output to speakers 35 * GPIO 8 -> enable output to speakers
36 */
37
38/*
39 * Xonar DX
40 * --------
41 *
42 * CMI8788:
43 *
44 * I²C <-> CS4398 (front)
45 * <-> CS4362A (surround, center/LFE, back)
46 *
47 * GPI 0 <- external power present
33 * 48 *
34 * CM9780: 49 * GPIO 0 -> enable output to speakers
50 * GPIO 1 -> enable front panel I/O
51 * GPIO 2 -> M0 of CS5361
52 * GPIO 3 -> M1 of CS5361
53 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
35 * 54 *
36 * GPIO 0 -> enable AC'97 bypass (line in -> ADC) 55 * CS4398:
56 *
57 * AD0 <- 1
58 * AD1 <- 1
59 *
60 * CS4362A:
61 *
62 * AD0 <- 0
37 */ 63 */
38 64
39#include <linux/pci.h> 65#include <linux/pci.h>
@@ -47,11 +73,14 @@
47#include <sound/tlv.h> 73#include <sound/tlv.h>
48#include "oxygen.h" 74#include "oxygen.h"
49#include "cm9780.h" 75#include "cm9780.h"
76#include "pcm1796.h"
77#include "cs4398.h"
78#include "cs4362a.h"
50 79
51MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 80MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
52MODULE_DESCRIPTION("Asus AV200 driver"); 81MODULE_DESCRIPTION("Asus AVx00 driver");
53MODULE_LICENSE("GPL"); 82MODULE_LICENSE("GPL");
54MODULE_SUPPORTED_DEVICE("{{Asus,AV200}}"); 83MODULE_SUPPORTED_DEVICE("{{Asus,AV100},{Asus,AV200}}");
55 84
56static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 85static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
57static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 86static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
@@ -64,80 +93,44 @@ MODULE_PARM_DESC(id, "ID string");
64module_param_array(enable, bool, NULL, 0444); 93module_param_array(enable, bool, NULL, 0444);
65MODULE_PARM_DESC(enable, "enable card"); 94MODULE_PARM_DESC(enable, "enable card");
66 95
96enum {
97 MODEL_D2,
98 MODEL_D2X,
99 MODEL_DX,
100};
101
67static struct pci_device_id xonar_ids[] __devinitdata = { 102static struct pci_device_id xonar_ids[] __devinitdata = {
68 { OXYGEN_PCI_SUBID(0x1043, 0x8269) }, /* Asus Xonar D2 */ 103 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 },
69 { OXYGEN_PCI_SUBID(0x1043, 0x82b7) }, /* Asus Xonar D2X */ 104 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX },
105 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X },
70 { } 106 { }
71}; 107};
72MODULE_DEVICE_TABLE(pci, xonar_ids); 108MODULE_DEVICE_TABLE(pci, xonar_ids);
73 109
74 110
75#define GPIO_CS5381_M_MASK 0x000c 111#define GPIO_CS53x1_M_MASK 0x000c
76#define GPIO_CS5381_M_SINGLE 0x0000 112#define GPIO_CS53x1_M_SINGLE 0x0000
77#define GPIO_CS5381_M_DOUBLE 0x0004 113#define GPIO_CS53x1_M_DOUBLE 0x0004
78#define GPIO_CS5381_M_QUAD 0x0008 114#define GPIO_CS53x1_M_QUAD 0x0008
79#define GPIO_EXT_POWER 0x0020 115
80#define GPIO_ALT 0x0080 116#define GPIO_D2X_EXT_POWER 0x0020
81#define GPIO_OUTPUT_ENABLE 0x0100 117#define GPIO_D2_ALT 0x0080
82 118#define GPIO_D2_OUTPUT_ENABLE 0x0100
83#define GPIO_LINE_MUTE CM9780_GPO0 119
84 120#define GPI_DX_EXT_POWER 0x01
85/* register 16 */ 121#define GPIO_DX_OUTPUT_ENABLE 0x0001
86#define PCM1796_ATL_MASK 0xff 122#define GPIO_DX_FRONT_PANEL 0x0002
87/* register 17 */ 123#define GPIO_DX_INPUT_ROUTE 0x0100
88#define PCM1796_ATR_MASK 0xff 124
89/* register 18 */ 125#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
90#define PCM1796_MUTE 0x01 126#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
91#define PCM1796_DME 0x02
92#define PCM1796_DMF_MASK 0x0c
93#define PCM1796_DMF_DISABLED 0x00
94#define PCM1796_DMF_48 0x04
95#define PCM1796_DMF_441 0x08
96#define PCM1796_DMF_32 0x0c
97#define PCM1796_FMT_MASK 0x70
98#define PCM1796_FMT_16_RJUST 0x00
99#define PCM1796_FMT_20_RJUST 0x10
100#define PCM1796_FMT_24_RJUST 0x20
101#define PCM1796_FMT_24_LJUST 0x30
102#define PCM1796_FMT_16_I2S 0x40
103#define PCM1796_FMT_24_I2S 0x50
104#define PCM1796_ATLD 0x80
105/* register 19 */
106#define PCM1796_INZD 0x01
107#define PCM1796_FLT_MASK 0x02
108#define PCM1796_FLT_SHARP 0x00
109#define PCM1796_FLT_SLOW 0x02
110#define PCM1796_DFMS 0x04
111#define PCM1796_OPE 0x10
112#define PCM1796_ATS_MASK 0x60
113#define PCM1796_ATS_1 0x00
114#define PCM1796_ATS_2 0x20
115#define PCM1796_ATS_4 0x40
116#define PCM1796_ATS_8 0x60
117#define PCM1796_REV 0x80
118/* register 20 */
119#define PCM1796_OS_MASK 0x03
120#define PCM1796_OS_64 0x00
121#define PCM1796_OS_32 0x01
122#define PCM1796_OS_128 0x02
123#define PCM1796_CHSL_MASK 0x04
124#define PCM1796_CHSL_LEFT 0x00
125#define PCM1796_CHSL_RIGHT 0x04
126#define PCM1796_MONO 0x08
127#define PCM1796_DFTH 0x10
128#define PCM1796_DSD 0x20
129#define PCM1796_SRST 0x40
130/* register 21 */
131#define PCM1796_PCMZ 0x01
132#define PCM1796_DZ_MASK 0x06
133/* register 22 */
134#define PCM1796_ZFGL 0x01
135#define PCM1796_ZFGR 0x02
136/* register 23 */
137#define PCM1796_ID_MASK 0x1f
138 127
139struct xonar_data { 128struct xonar_data {
140 u8 is_d2x; 129 unsigned int anti_pop_delay;
130 u16 output_enable_bit;
131 u8 ext_power_reg;
132 u8 ext_power_int_reg;
133 u8 ext_power_bit;
141 u8 has_power; 134 u8 has_power;
142}; 135};
143 136
@@ -156,62 +149,157 @@ static void pcm1796_write(struct oxygen *chip, unsigned int codec,
156 (reg << 8) | value); 149 (reg << 8) | value);
157} 150}
158 151
159static void xonar_init(struct oxygen *chip) 152static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
153{
154 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
155}
156
157static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
158{
159 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
160}
161
162static void xonar_common_init(struct oxygen *chip)
163{
164 struct xonar_data *data = chip->model_data;
165
166 if (data->ext_power_reg) {
167 oxygen_set_bits8(chip, data->ext_power_int_reg,
168 data->ext_power_bit);
169 chip->interrupt_mask |= OXYGEN_INT_GPIO;
170 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
171 & data->ext_power_bit);
172 }
173 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CS53x1_M_MASK);
174 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
175 GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
176 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
177 msleep(data->anti_pop_delay);
178 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, data->output_enable_bit);
179 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
180}
181
182static void xonar_d2_init(struct oxygen *chip)
160{ 183{
161 struct xonar_data *data = chip->model_data; 184 struct xonar_data *data = chip->model_data;
162 unsigned int i; 185 unsigned int i;
163 186
164 data->is_d2x = chip->pci->subsystem_device == 0x82b7; 187 data->anti_pop_delay = 300;
188 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
165 189
166 for (i = 0; i < 4; ++i) { 190 for (i = 0; i < 4; ++i) {
167 pcm1796_write(chip, i, 18, PCM1796_FMT_24_LJUST | PCM1796_ATLD); 191 pcm1796_write(chip, i, 18, PCM1796_MUTE | PCM1796_DMF_DISABLED |
192 PCM1796_FMT_24_LJUST | PCM1796_ATLD);
168 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1); 193 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
169 pcm1796_write(chip, i, 20, PCM1796_OS_64); 194 pcm1796_write(chip, i, 20, PCM1796_OS_64);
170 pcm1796_write(chip, i, 21, 0); 195 pcm1796_write(chip, i, 21, 0);
171 pcm1796_write(chip, i, 16, 0xff); /* set ATL/ATR after ATLD */ 196 pcm1796_write(chip, i, 16, 0x0f); /* set ATL/ATR after ATLD */
172 pcm1796_write(chip, i, 17, 0xff); 197 pcm1796_write(chip, i, 17, 0x0f);
173 } 198 }
174 199
175 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, 200 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
176 GPIO_CS5381_M_MASK | GPIO_ALT); 201 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
177 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, 202
178 GPIO_CS5381_M_SINGLE, 203 xonar_common_init(chip);
179 GPIO_CS5381_M_MASK | GPIO_ALT);
180 if (data->is_d2x) {
181 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
182 GPIO_EXT_POWER);
183 oxygen_set_bits16(chip, OXYGEN_GPIO_INTERRUPT_MASK,
184 GPIO_EXT_POWER);
185 chip->interrupt_mask |= OXYGEN_INT_GPIO;
186 data->has_power = !!(oxygen_read16(chip, OXYGEN_GPIO_DATA)
187 & GPIO_EXT_POWER);
188 }
189 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
190 oxygen_ac97_clear_bits(chip, 0, CM9780_GPIO_STATUS, GPIO_LINE_MUTE);
191 msleep(300);
192 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_OUTPUT_ENABLE);
193 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, GPIO_OUTPUT_ENABLE);
194 204
195 snd_component_add(chip->card, "PCM1796"); 205 snd_component_add(chip->card, "PCM1796");
196 snd_component_add(chip->card, "CS5381"); 206 snd_component_add(chip->card, "CS5381");
197} 207}
198 208
209static void xonar_d2x_init(struct oxygen *chip)
210{
211 struct xonar_data *data = chip->model_data;
212
213 data->ext_power_reg = OXYGEN_GPIO_DATA;
214 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
215 data->ext_power_bit = GPIO_D2X_EXT_POWER;
216 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
217 xonar_d2_init(chip);
218}
219
220static void xonar_dx_init(struct oxygen *chip)
221{
222 struct xonar_data *data = chip->model_data;
223
224 data->anti_pop_delay = 800;
225 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
226 data->ext_power_reg = OXYGEN_GPI_DATA;
227 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
228 data->ext_power_bit = GPI_DX_EXT_POWER;
229
230 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
231 OXYGEN_2WIRE_LENGTH_8 |
232 OXYGEN_2WIRE_INTERRUPT_MASK |
233 OXYGEN_2WIRE_SPEED_FAST);
234
235 /* set CPEN (control port mode) and power down */
236 cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN);
237 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
238 /* configure */
239 cs4398_write(chip, 2, CS4398_FM_SINGLE |
240 CS4398_DEM_NONE | CS4398_DIF_LJUST);
241 cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L);
242 cs4398_write(chip, 4, CS4398_MUTEP_LOW | CS4398_PAMUTE);
243 cs4398_write(chip, 5, 0xfe);
244 cs4398_write(chip, 6, 0xfe);
245 cs4398_write(chip, 7, CS4398_RMP_DN | CS4398_RMP_UP |
246 CS4398_ZERO_CROSS | CS4398_SOFT_RAMP);
247 cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST);
248 cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE |
249 CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP);
250 cs4362a_write(chip, 0x04, CS4362A_RMP_DN | CS4362A_DEM_NONE);
251 cs4362a_write(chip, 0x05, 0);
252 cs4362a_write(chip, 0x06, CS4362A_FM_SINGLE |
253 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
254 cs4362a_write(chip, 0x07, 0x7f | CS4362A_MUTE);
255 cs4362a_write(chip, 0x08, 0x7f | CS4362A_MUTE);
256 cs4362a_write(chip, 0x09, CS4362A_FM_SINGLE |
257 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
258 cs4362a_write(chip, 0x0a, 0x7f | CS4362A_MUTE);
259 cs4362a_write(chip, 0x0b, 0x7f | CS4362A_MUTE);
260 cs4362a_write(chip, 0x0c, CS4362A_FM_SINGLE |
261 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
262 cs4362a_write(chip, 0x0d, 0x7f | CS4362A_MUTE);
263 cs4362a_write(chip, 0x0e, 0x7f | CS4362A_MUTE);
264 /* clear power down */
265 cs4398_write(chip, 8, CS4398_CPEN);
266 cs4362a_write(chip, 0x01, CS4362A_CPEN);
267
268 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
269 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
270 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
271 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
272
273 xonar_common_init(chip);
274
275 snd_component_add(chip->card, "CS4398");
276 snd_component_add(chip->card, "CS4362A");
277 snd_component_add(chip->card, "CS5361");
278}
279
199static void xonar_cleanup(struct oxygen *chip) 280static void xonar_cleanup(struct oxygen *chip)
200{ 281{
201 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_OUTPUT_ENABLE); 282 struct xonar_data *data = chip->model_data;
283
284 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
285}
286
287static void xonar_dx_cleanup(struct oxygen *chip)
288{
289 xonar_cleanup(chip);
290 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
291 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
202} 292}
203 293
204static void set_pcm1796_params(struct oxygen *chip, 294static void set_pcm1796_params(struct oxygen *chip,
205 struct snd_pcm_hw_params *params) 295 struct snd_pcm_hw_params *params)
206{ 296{
207#if 0
208 unsigned int i; 297 unsigned int i;
209 u8 value; 298 u8 value;
210 299
211 value = params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64; 300 value = params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
212 for (i = 0; i < 4; ++i) 301 for (i = 0; i < 4; ++i)
213 pcm1796_write(chip, i, 20, value); 302 pcm1796_write(chip, i, 20, value);
214#endif
215} 303}
216 304
217static void update_pcm1796_volume(struct oxygen *chip) 305static void update_pcm1796_volume(struct oxygen *chip)
@@ -236,19 +324,73 @@ static void update_pcm1796_mute(struct oxygen *chip)
236 pcm1796_write(chip, i, 18, value); 324 pcm1796_write(chip, i, 18, value);
237} 325}
238 326
239static void set_cs5381_params(struct oxygen *chip, 327static void set_cs53x1_params(struct oxygen *chip,
240 struct snd_pcm_hw_params *params) 328 struct snd_pcm_hw_params *params)
241{ 329{
242 unsigned int value; 330 unsigned int value;
243 331
244 if (params_rate(params) <= 54000) 332 if (params_rate(params) <= 54000)
245 value = GPIO_CS5381_M_SINGLE; 333 value = GPIO_CS53x1_M_SINGLE;
246 else if (params_rate(params) <= 108000) 334 else if (params_rate(params) <= 108000)
247 value = GPIO_CS5381_M_DOUBLE; 335 value = GPIO_CS53x1_M_DOUBLE;
248 else 336 else
249 value = GPIO_CS5381_M_QUAD; 337 value = GPIO_CS53x1_M_QUAD;
250 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, 338 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
251 value, GPIO_CS5381_M_MASK); 339 value, GPIO_CS53x1_M_MASK);
340}
341
342static void set_cs43xx_params(struct oxygen *chip,
343 struct snd_pcm_hw_params *params)
344{
345 u8 fm_cs4398, fm_cs4362a;
346
347 fm_cs4398 = CS4398_DEM_NONE | CS4398_DIF_LJUST;
348 fm_cs4362a = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
349 if (params_rate(params) <= 50000) {
350 fm_cs4398 |= CS4398_FM_SINGLE;
351 fm_cs4362a |= CS4362A_FM_SINGLE;
352 } else if (params_rate(params) <= 100000) {
353 fm_cs4398 |= CS4398_FM_DOUBLE;
354 fm_cs4362a |= CS4362A_FM_DOUBLE;
355 } else {
356 fm_cs4398 |= CS4398_FM_QUAD;
357 fm_cs4362a |= CS4362A_FM_QUAD;
358 }
359 cs4398_write(chip, 2, fm_cs4398);
360 cs4362a_write(chip, 0x06, fm_cs4362a);
361 cs4362a_write(chip, 0x09, fm_cs4362a);
362 cs4362a_write(chip, 0x0c, fm_cs4362a);
363}
364
365static void update_cs4362a_volumes(struct oxygen *chip)
366{
367 u8 mute;
368
369 mute = chip->dac_mute ? CS4362A_MUTE : 0;
370 cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute);
371 cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute);
372 cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute);
373 cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute);
374 cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute);
375 cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute);
376}
377
378static void update_cs43xx_volume(struct oxygen *chip)
379{
380 cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2);
381 cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2);
382 update_cs4362a_volumes(chip);
383}
384
385static void update_cs43xx_mute(struct oxygen *chip)
386{
387 u8 reg;
388
389 reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
390 if (chip->dac_mute)
391 reg |= CS4398_MUTE_B | CS4398_MUTE_A;
392 cs4398_write(chip, 4, reg);
393 update_cs4362a_volumes(chip);
252} 394}
253 395
254static void xonar_gpio_changed(struct oxygen *chip) 396static void xonar_gpio_changed(struct oxygen *chip)
@@ -256,10 +398,8 @@ static void xonar_gpio_changed(struct oxygen *chip)
256 struct xonar_data *data = chip->model_data; 398 struct xonar_data *data = chip->model_data;
257 u8 has_power; 399 u8 has_power;
258 400
259 if (!data->is_d2x) 401 has_power = !!(oxygen_read8(chip, data->ext_power_reg)
260 return; 402 & data->ext_power_bit);
261 has_power = !!(oxygen_read16(chip, OXYGEN_GPIO_DATA)
262 & GPIO_EXT_POWER);
263 if (has_power != data->has_power) { 403 if (has_power != data->has_power) {
264 data->has_power = has_power; 404 data->has_power = has_power;
265 if (has_power) { 405 if (has_power) {
@@ -272,66 +412,13 @@ static void xonar_gpio_changed(struct oxygen *chip)
272 } 412 }
273} 413}
274 414
275static void mute_ac97_ctl(struct oxygen *chip, unsigned int control)
276{
277 unsigned int index = chip->controls[control]->private_value & 0xff;
278 u16 value;
279
280 value = oxygen_read_ac97(chip, 0, index);
281 if (!(value & 0x8000)) {
282 oxygen_write_ac97(chip, 0, index, value | 0x8000);
283 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
284 &chip->controls[control]->id);
285 }
286}
287
288static void xonar_ac97_switch_hook(struct oxygen *chip, unsigned int codec,
289 unsigned int reg, int mute)
290{
291 if (codec != 0)
292 return;
293 /* line-in is exclusive */
294 switch (reg) {
295 case AC97_LINE:
296 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
297 mute ? GPIO_LINE_MUTE : 0,
298 GPIO_LINE_MUTE);
299 if (!mute) {
300 mute_ac97_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH);
301 mute_ac97_ctl(chip, CONTROL_CD_CAPTURE_SWITCH);
302 mute_ac97_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH);
303 }
304 break;
305 case AC97_MIC:
306 case AC97_CD:
307 case AC97_VIDEO:
308 case AC97_AUX:
309 if (!mute) {
310 oxygen_ac97_set_bits(chip, 0, CM9780_GPIO_STATUS,
311 GPIO_LINE_MUTE);
312 mute_ac97_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH);
313 }
314 break;
315 }
316}
317
318static int pcm1796_volume_info(struct snd_kcontrol *ctl,
319 struct snd_ctl_elem_info *info)
320{
321 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
322 info->count = 8;
323 info->value.integer.min = 0x0f;
324 info->value.integer.max = 0xff;
325 return 0;
326}
327
328static int alt_switch_get(struct snd_kcontrol *ctl, 415static int alt_switch_get(struct snd_kcontrol *ctl,
329 struct snd_ctl_elem_value *value) 416 struct snd_ctl_elem_value *value)
330{ 417{
331 struct oxygen *chip = ctl->private_data; 418 struct oxygen *chip = ctl->private_data;
332 419
333 value->value.integer.value[0] = 420 value->value.integer.value[0] =
334 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_ALT); 421 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_D2_ALT);
335 return 0; 422 return 0;
336} 423}
337 424
@@ -345,9 +432,9 @@ static int alt_switch_put(struct snd_kcontrol *ctl,
345 spin_lock_irq(&chip->reg_lock); 432 spin_lock_irq(&chip->reg_lock);
346 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA); 433 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
347 if (value->value.integer.value[0]) 434 if (value->value.integer.value[0])
348 new_bits = old_bits | GPIO_ALT; 435 new_bits = old_bits | GPIO_D2_ALT;
349 else 436 else
350 new_bits = old_bits & ~GPIO_ALT; 437 new_bits = old_bits & ~GPIO_D2_ALT;
351 changed = new_bits != old_bits; 438 changed = new_bits != old_bits;
352 if (changed) 439 if (changed)
353 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits); 440 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
@@ -363,20 +450,68 @@ static const struct snd_kcontrol_new alt_switch = {
363 .put = alt_switch_put, 450 .put = alt_switch_put,
364}; 451};
365 452
453static int front_panel_get(struct snd_kcontrol *ctl,
454 struct snd_ctl_elem_value *value)
455{
456 struct oxygen *chip = ctl->private_data;
457
458 value->value.integer.value[0] =
459 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DX_FRONT_PANEL);
460 return 0;
461}
462
463static int front_panel_put(struct snd_kcontrol *ctl,
464 struct snd_ctl_elem_value *value)
465{
466 struct oxygen *chip = ctl->private_data;
467 u16 old_reg, new_reg;
468
469 spin_lock_irq(&chip->reg_lock);
470 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
471 if (value->value.integer.value[0])
472 new_reg = old_reg | GPIO_DX_FRONT_PANEL;
473 else
474 new_reg = old_reg & ~GPIO_DX_FRONT_PANEL;
475 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
476 spin_unlock_irq(&chip->reg_lock);
477 return old_reg != new_reg;
478}
479
480static const struct snd_kcontrol_new front_panel_switch = {
481 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
482 .name = "Front Panel Switch",
483 .info = snd_ctl_boolean_mono_info,
484 .get = front_panel_get,
485 .put = front_panel_put,
486};
487
488static void xonar_dx_ac97_switch(struct oxygen *chip,
489 unsigned int reg, unsigned int mute)
490{
491 if (reg == AC97_LINE) {
492 spin_lock_irq(&chip->reg_lock);
493 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
494 mute ? GPIO_DX_INPUT_ROUTE : 0,
495 GPIO_DX_INPUT_ROUTE);
496 spin_unlock_irq(&chip->reg_lock);
497 }
498}
499
366static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -12000, 50, 0); 500static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -12000, 50, 0);
501static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -12700, 100, 0);
367 502
368static int xonar_control_filter(struct snd_kcontrol_new *template) 503static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
369{ 504{
370 if (!strcmp(template->name, "Master Playback Volume")) { 505 if (!strncmp(template->name, "CD Capture ", 11))
371 template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
372 template->info = pcm1796_volume_info,
373 template->tlv.p = pcm1796_db_scale;
374 } else if (!strncmp(template->name, "CD Capture ", 11)) {
375 /* CD in is actually connected to the video in pin */ 506 /* CD in is actually connected to the video in pin */
376 template->private_value ^= AC97_CD ^ AC97_VIDEO; 507 template->private_value ^= AC97_CD ^ AC97_VIDEO;
377 } else if (!strcmp(template->name, "Line Capture Volume")) { 508 return 0;
378 return 1; /* line-in bypasses the AC'97 mixer */ 509}
379 } 510
511static int xonar_dx_control_filter(struct snd_kcontrol_new *template)
512{
513 if (!strncmp(template->name, "CD Capture ", 11))
514 return 1; /* no CD input */
380 return 0; 515 return 0;
381} 516}
382 517
@@ -385,30 +520,96 @@ static int xonar_mixer_init(struct oxygen *chip)
385 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); 520 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
386} 521}
387 522
388static const struct oxygen_model model_xonar = { 523static int xonar_dx_mixer_init(struct oxygen *chip)
389 .shortname = "Asus AV200", 524{
390 .longname = "Asus Virtuoso 200", 525 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
391 .chip = "AV200", 526}
392 .owner = THIS_MODULE, 527
393 .init = xonar_init, 528static const struct oxygen_model xonar_models[] = {
394 .control_filter = xonar_control_filter, 529 [MODEL_D2] = {
395 .mixer_init = xonar_mixer_init, 530 .shortname = "Xonar D2",
396 .cleanup = xonar_cleanup, 531 .longname = "Asus Virtuoso 200",
397 .set_dac_params = set_pcm1796_params, 532 .chip = "AV200",
398 .set_adc_params = set_cs5381_params, 533 .owner = THIS_MODULE,
399 .update_dac_volume = update_pcm1796_volume, 534 .init = xonar_d2_init,
400 .update_dac_mute = update_pcm1796_mute, 535 .control_filter = xonar_d2_control_filter,
401 .ac97_switch_hook = xonar_ac97_switch_hook, 536 .mixer_init = xonar_mixer_init,
402 .gpio_changed = xonar_gpio_changed, 537 .cleanup = xonar_cleanup,
403 .model_data_size = sizeof(struct xonar_data), 538 .set_dac_params = set_pcm1796_params,
404 .dac_channels = 8, 539 .set_adc_params = set_cs53x1_params,
405 .used_channels = OXYGEN_CHANNEL_B | 540 .update_dac_volume = update_pcm1796_volume,
406 OXYGEN_CHANNEL_C | 541 .update_dac_mute = update_pcm1796_mute,
407 OXYGEN_CHANNEL_SPDIF | 542 .dac_tlv = pcm1796_db_scale,
408 OXYGEN_CHANNEL_MULTICH, 543 .model_data_size = sizeof(struct xonar_data),
409 .function_flags = OXYGEN_FUNCTION_ENABLE_SPI_4_5, 544 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
410 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 545 PLAYBACK_1_TO_SPDIF |
411 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 546 CAPTURE_0_FROM_I2S_2 |
547 CAPTURE_1_FROM_SPDIF,
548 .dac_channels = 8,
549 .dac_volume_min = 0x0f,
550 .dac_volume_max = 0xff,
551 .misc_flags = OXYGEN_MISC_MIDI,
552 .function_flags = OXYGEN_FUNCTION_SPI |
553 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
554 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
555 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
556 },
557 [MODEL_D2X] = {
558 .shortname = "Xonar D2X",
559 .longname = "Asus Virtuoso 200",
560 .chip = "AV200",
561 .owner = THIS_MODULE,
562 .init = xonar_d2x_init,
563 .control_filter = xonar_d2_control_filter,
564 .mixer_init = xonar_mixer_init,
565 .cleanup = xonar_cleanup,
566 .set_dac_params = set_pcm1796_params,
567 .set_adc_params = set_cs53x1_params,
568 .update_dac_volume = update_pcm1796_volume,
569 .update_dac_mute = update_pcm1796_mute,
570 .gpio_changed = xonar_gpio_changed,
571 .dac_tlv = pcm1796_db_scale,
572 .model_data_size = sizeof(struct xonar_data),
573 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
574 PLAYBACK_1_TO_SPDIF |
575 CAPTURE_0_FROM_I2S_2 |
576 CAPTURE_1_FROM_SPDIF,
577 .dac_channels = 8,
578 .dac_volume_min = 0x0f,
579 .dac_volume_max = 0xff,
580 .misc_flags = OXYGEN_MISC_MIDI,
581 .function_flags = OXYGEN_FUNCTION_SPI |
582 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
583 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
584 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
585 },
586 [MODEL_DX] = {
587 .shortname = "Xonar DX",
588 .longname = "Asus Virtuoso 100",
589 .chip = "AV200",
590 .owner = THIS_MODULE,
591 .init = xonar_dx_init,
592 .control_filter = xonar_dx_control_filter,
593 .mixer_init = xonar_dx_mixer_init,
594 .cleanup = xonar_dx_cleanup,
595 .set_dac_params = set_cs43xx_params,
596 .set_adc_params = set_cs53x1_params,
597 .update_dac_volume = update_cs43xx_volume,
598 .update_dac_mute = update_cs43xx_mute,
599 .gpio_changed = xonar_gpio_changed,
600 .ac97_switch = xonar_dx_ac97_switch,
601 .dac_tlv = cs4362a_db_scale,
602 .model_data_size = sizeof(struct xonar_data),
603 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
604 PLAYBACK_1_TO_SPDIF |
605 CAPTURE_0_FROM_I2S_2,
606 .dac_channels = 8,
607 .dac_volume_min = 0,
608 .dac_volume_max = 127,
609 .function_flags = OXYGEN_FUNCTION_2WIRE,
610 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
611 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
612 },
412}; 613};
413 614
414static int __devinit xonar_probe(struct pci_dev *pci, 615static int __devinit xonar_probe(struct pci_dev *pci,
@@ -423,7 +624,8 @@ static int __devinit xonar_probe(struct pci_dev *pci,
423 ++dev; 624 ++dev;
424 return -ENOENT; 625 return -ENOENT;
425 } 626 }
426 err = oxygen_pci_probe(pci, index[dev], id[dev], 1, &model_xonar); 627 err = oxygen_pci_probe(pci, index[dev], id[dev],
628 &xonar_models[pci_id->driver_data]);
427 if (err >= 0) 629 if (err >= 0)
428 ++dev; 630 ++dev;
429 return err; 631 return err;
diff --git a/sound/pci/oxygen/wm8785.h b/sound/pci/oxygen/wm8785.h
new file mode 100644
index 000000000000..8c23e315ae66
--- /dev/null
+++ b/sound/pci/oxygen/wm8785.h
@@ -0,0 +1,45 @@
1#ifndef WM8785_H_INCLUDED
2#define WM8785_H_INCLUDED
3
4#define WM8785_R0 0
5#define WM8785_R1 1
6#define WM8785_R2 2
7#define WM8785_R7 7
8
9/* R0 */
10#define WM8785_MCR_MASK 0x007
11#define WM8785_MCR_SLAVE 0x000
12#define WM8785_MCR_MASTER_128 0x001
13#define WM8785_MCR_MASTER_192 0x002
14#define WM8785_MCR_MASTER_256 0x003
15#define WM8785_MCR_MASTER_384 0x004
16#define WM8785_MCR_MASTER_512 0x005
17#define WM8785_MCR_MASTER_768 0x006
18#define WM8785_OSR_MASK 0x018
19#define WM8785_OSR_SINGLE 0x000
20#define WM8785_OSR_DOUBLE 0x008
21#define WM8785_OSR_QUAD 0x010
22#define WM8785_FORMAT_MASK 0x060
23#define WM8785_FORMAT_RJUST 0x000
24#define WM8785_FORMAT_LJUST 0x020
25#define WM8785_FORMAT_I2S 0x040
26#define WM8785_FORMAT_DSP 0x060
27/* R1 */
28#define WM8785_WL_MASK 0x003
29#define WM8785_WL_16 0x000
30#define WM8785_WL_20 0x001
31#define WM8785_WL_24 0x002
32#define WM8785_WL_32 0x003
33#define WM8785_LRP 0x004
34#define WM8785_BCLKINV 0x008
35#define WM8785_LRSWAP 0x010
36#define WM8785_DEVNO_MASK 0x0e0
37/* R2 */
38#define WM8785_HPFR 0x001
39#define WM8785_HPFL 0x002
40#define WM8785_SDODIS 0x004
41#define WM8785_PWRDNR 0x008
42#define WM8785_PWRDNL 0x010
43#define WM8785_TDM_MASK 0x1c0
44
45#endif
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index 9d5bb76229a8..7fdcdc8c6b64 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -458,7 +458,7 @@ static int pcxhr_update_r_buffer(struct pcxhr_stream *stream)
458 458
459 snd_printdd("pcxhr_update_r_buffer(pcm%c%d) : addr(%p) bytes(%zx) subs(%d)\n", 459 snd_printdd("pcxhr_update_r_buffer(pcm%c%d) : addr(%p) bytes(%zx) subs(%d)\n",
460 is_capture ? 'c' : 'p', 460 is_capture ? 'c' : 'p',
461 chip->chip_idx, (void*)subs->runtime->dma_addr, 461 chip->chip_idx, (void *)(long)subs->runtime->dma_addr,
462 subs->runtime->dma_bytes, subs->number); 462 subs->runtime->dma_bytes, subs->number);
463 463
464 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS); 464 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS);
@@ -626,7 +626,7 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
626#ifdef CONFIG_SND_DEBUG_DETECT 626#ifdef CONFIG_SND_DEBUG_DETECT
627 do_gettimeofday(&my_tv2); 627 do_gettimeofday(&my_tv2);
628 snd_printdd("***TRIGGER TASKLET*** TIME = %ld (err = %x)\n", 628 snd_printdd("***TRIGGER TASKLET*** TIME = %ld (err = %x)\n",
629 my_tv2.tv_usec - my_tv1.tv_usec, err); 629 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
630#endif 630#endif
631} 631}
632 632
@@ -846,7 +846,6 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
846 struct pcxhr_mgr *mgr = chip->mgr; 846 struct pcxhr_mgr *mgr = chip->mgr;
847 struct snd_pcm_runtime *runtime = subs->runtime; 847 struct snd_pcm_runtime *runtime = subs->runtime;
848 struct pcxhr_stream *stream; 848 struct pcxhr_stream *stream;
849 int is_capture;
850 849
851 mutex_lock(&mgr->setup_mutex); 850 mutex_lock(&mgr->setup_mutex);
852 851
@@ -856,12 +855,10 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
856 if( subs->stream == SNDRV_PCM_STREAM_PLAYBACK ) { 855 if( subs->stream == SNDRV_PCM_STREAM_PLAYBACK ) {
857 snd_printdd("pcxhr_open playback chip%d subs%d\n", 856 snd_printdd("pcxhr_open playback chip%d subs%d\n",
858 chip->chip_idx, subs->number); 857 chip->chip_idx, subs->number);
859 is_capture = 0;
860 stream = &chip->playback_stream[subs->number]; 858 stream = &chip->playback_stream[subs->number];
861 } else { 859 } else {
862 snd_printdd("pcxhr_open capture chip%d subs%d\n", 860 snd_printdd("pcxhr_open capture chip%d subs%d\n",
863 chip->chip_idx, subs->number); 861 chip->chip_idx, subs->number);
864 is_capture = 1;
865 if (mgr->mono_capture) 862 if (mgr->mono_capture)
866 runtime->hw.channels_max = 1; 863 runtime->hw.channels_max = 1;
867 else 864 else
diff --git a/sound/pci/pcxhr/pcxhr_core.c b/sound/pci/pcxhr/pcxhr_core.c
index c4e415d07380..78aa81feaa4a 100644
--- a/sound/pci/pcxhr/pcxhr_core.c
+++ b/sound/pci/pcxhr/pcxhr_core.c
@@ -897,7 +897,7 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask, int capture_m
897#ifdef CONFIG_SND_DEBUG_DETECT 897#ifdef CONFIG_SND_DEBUG_DETECT
898 do_gettimeofday(&my_tv2); 898 do_gettimeofday(&my_tv2);
899 snd_printdd("***SET PIPE STATE*** TIME = %ld (err = %x)\n", 899 snd_printdd("***SET PIPE STATE*** TIME = %ld (err = %x)\n",
900 my_tv2.tv_usec - my_tv1.tv_usec, err); 900 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
901#endif 901#endif
902 return 0; 902 return 0;
903} 903}
@@ -1005,30 +1005,37 @@ void pcxhr_msg_tasklet(unsigned long arg)
1005 int nb_stream = (prmh->stat[i] >> (2*FIELD_SIZE)) & MASK_FIRST_FIELD; 1005 int nb_stream = (prmh->stat[i] >> (2*FIELD_SIZE)) & MASK_FIRST_FIELD;
1006 int pipe = prmh->stat[i] & MASK_FIRST_FIELD; 1006 int pipe = prmh->stat[i] & MASK_FIRST_FIELD;
1007 int is_capture = prmh->stat[i] & 0x400000; 1007 int is_capture = prmh->stat[i] & 0x400000;
1008 u32 err; 1008 u32 err2;
1009 1009
1010 if (prmh->stat[i] & 0x800000) { /* if BIT_END */ 1010 if (prmh->stat[i] & 0x800000) { /* if BIT_END */
1011 snd_printdd("TASKLET : End%sPipe %d\n", 1011 snd_printdd("TASKLET : End%sPipe %d\n",
1012 is_capture ? "Record" : "Play", pipe); 1012 is_capture ? "Record" : "Play", pipe);
1013 } 1013 }
1014 i++; 1014 i++;
1015 err = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1]; 1015 err2 = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1];
1016 if (err) 1016 if (err2)
1017 pcxhr_handle_async_err(mgr, err, PCXHR_ERR_PIPE, 1017 pcxhr_handle_async_err(mgr, err2,
1018 PCXHR_ERR_PIPE,
1018 pipe, is_capture); 1019 pipe, is_capture);
1019 i += 2; 1020 i += 2;
1020 for (j = 0; j < nb_stream; j++) { 1021 for (j = 0; j < nb_stream; j++) {
1021 err = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1]; 1022 err2 = prmh->stat[i] ?
1022 if (err) 1023 prmh->stat[i] : prmh->stat[i+1];
1023 pcxhr_handle_async_err(mgr, err, PCXHR_ERR_STREAM, 1024 if (err2)
1024 pipe, is_capture); 1025 pcxhr_handle_async_err(mgr, err2,
1026 PCXHR_ERR_STREAM,
1027 pipe,
1028 is_capture);
1025 i += 2; 1029 i += 2;
1026 } 1030 }
1027 for (j = 0; j < nb_audio; j++) { 1031 for (j = 0; j < nb_audio; j++) {
1028 err = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1]; 1032 err2 = prmh->stat[i] ?
1029 if (err) 1033 prmh->stat[i] : prmh->stat[i+1];
1030 pcxhr_handle_async_err(mgr, err, PCXHR_ERR_AUDIO, 1034 if (err2)
1031 pipe, is_capture); 1035 pcxhr_handle_async_err(mgr, err2,
1036 PCXHR_ERR_AUDIO,
1037 pipe,
1038 is_capture);
1032 i += 2; 1039 i += 2;
1033 } 1040 }
1034 } 1041 }
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index 9408b1eeec40..979f7da641ce 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -1630,14 +1630,14 @@ static int snd_riptide_playback_open(struct snd_pcm_substream *substream)
1630 struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1630 struct snd_riptide *chip = snd_pcm_substream_chip(substream);
1631 struct snd_pcm_runtime *runtime = substream->runtime; 1631 struct snd_pcm_runtime *runtime = substream->runtime;
1632 struct pcmhw *data; 1632 struct pcmhw *data;
1633 int index = substream->number; 1633 int sub_num = substream->number;
1634 1634
1635 chip->playback_substream[index] = substream; 1635 chip->playback_substream[sub_num] = substream;
1636 runtime->hw = snd_riptide_playback; 1636 runtime->hw = snd_riptide_playback;
1637 data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL); 1637 data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL);
1638 data->paths = lbus_play_paths[index]; 1638 data->paths = lbus_play_paths[sub_num];
1639 data->id = play_ids[index]; 1639 data->id = play_ids[sub_num];
1640 data->source = play_sources[index]; 1640 data->source = play_sources[sub_num];
1641 data->intdec[0] = 0xff; 1641 data->intdec[0] = 0xff;
1642 data->intdec[1] = 0xff; 1642 data->intdec[1] = 0xff;
1643 data->state = ST_STOP; 1643 data->state = ST_STOP;
@@ -1670,10 +1670,10 @@ static int snd_riptide_playback_close(struct snd_pcm_substream *substream)
1670{ 1670{
1671 struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1671 struct snd_riptide *chip = snd_pcm_substream_chip(substream);
1672 struct pcmhw *data = get_pcmhwdev(substream); 1672 struct pcmhw *data = get_pcmhwdev(substream);
1673 int index = substream->number; 1673 int sub_num = substream->number;
1674 1674
1675 substream->runtime->private_data = NULL; 1675 substream->runtime->private_data = NULL;
1676 chip->playback_substream[index] = NULL; 1676 chip->playback_substream[sub_num] = NULL;
1677 kfree(data); 1677 kfree(data);
1678 return 0; 1678 return 0;
1679} 1679}
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index df184aabce84..e7ef3a1a25a8 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -1350,7 +1350,8 @@ static int __devinit snd_rme32_create(struct rme32 * rme32)
1350 return err; 1350 return err;
1351 rme32->port = pci_resource_start(rme32->pci, 0); 1351 rme32->port = pci_resource_start(rme32->pci, 0);
1352 1352
1353 if ((rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE)) == 0) { 1353 rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE);
1354 if (!rme32->iobase) {
1354 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", 1355 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n",
1355 rme32->port, rme32->port + RME32_IO_SIZE - 1); 1356 rme32->port, rme32->port + RME32_IO_SIZE - 1);
1356 return -ENOMEM; 1357 return -ENOMEM;
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index fb0a4ee8bc02..3fdd488d0975 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -1559,7 +1559,8 @@ snd_rme96_create(struct rme96 *rme96)
1559 return err; 1559 return err;
1560 rme96->port = pci_resource_start(rme96->pci, 0); 1560 rme96->port = pci_resource_start(rme96->pci, 0);
1561 1561
1562 if ((rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE)) == 0) { 1562 rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE);
1563 if (!rme96->iobase) {
1563 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1); 1564 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1);
1564 return -ENOMEM; 1565 return -ENOMEM;
1565 } 1566 }
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 1be84f22d0de..4d6fbb36ab8a 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -318,6 +318,10 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
318#define HDSP_midi1IRQPending (1<<31) 318#define HDSP_midi1IRQPending (1<<31)
319 319
320#define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2) 320#define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
321#define HDSP_spdifFrequencyMask_9632 (HDSP_spdifFrequency0|\
322 HDSP_spdifFrequency1|\
323 HDSP_spdifFrequency2|\
324 HDSP_spdifFrequency3)
321 325
322#define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0) 326#define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
323#define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1) 327#define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
@@ -328,7 +332,9 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
328#define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1) 332#define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
329 333
330/* This is for H9632 cards */ 334/* This is for H9632 cards */
331#define HDSP_spdifFrequency128KHz HDSP_spdifFrequencyMask 335#define HDSP_spdifFrequency128KHz (HDSP_spdifFrequency0|\
336 HDSP_spdifFrequency1|\
337 HDSP_spdifFrequency2)
332#define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3 338#define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
333#define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0) 339#define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
334 340
@@ -885,28 +891,15 @@ static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
885 return ret; 891 return ret;
886} 892}
887 893
888static int hdsp_external_sample_rate (struct hdsp *hdsp)
889{
890 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
891 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
892
893 switch (rate_bits) {
894 case HDSP_systemFrequency32: return 32000;
895 case HDSP_systemFrequency44_1: return 44100;
896 case HDSP_systemFrequency48: return 48000;
897 case HDSP_systemFrequency64: return 64000;
898 case HDSP_systemFrequency88_2: return 88200;
899 case HDSP_systemFrequency96: return 96000;
900 default:
901 return 0;
902 }
903}
904
905static int hdsp_spdif_sample_rate(struct hdsp *hdsp) 894static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
906{ 895{
907 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister); 896 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
908 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask); 897 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
909 898
899 /* For the 9632, the mask is different */
900 if (hdsp->io_type == H9632)
901 rate_bits = (status & HDSP_spdifFrequencyMask_9632);
902
910 if (status & HDSP_SPDIFErrorFlag) 903 if (status & HDSP_SPDIFErrorFlag)
911 return 0; 904 return 0;
912 905
@@ -933,6 +926,31 @@ static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
933 return 0; 926 return 0;
934} 927}
935 928
929static int hdsp_external_sample_rate(struct hdsp *hdsp)
930{
931 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
932 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
933
934 /* For the 9632 card, there seems to be no bit for indicating external
935 * sample rate greater than 96kHz. The card reports the corresponding
936 * single speed. So the best means seems to get spdif rate when
937 * autosync reference is spdif */
938 if (hdsp->io_type == H9632 &&
939 hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF)
940 return hdsp_spdif_sample_rate(hdsp);
941
942 switch (rate_bits) {
943 case HDSP_systemFrequency32: return 32000;
944 case HDSP_systemFrequency44_1: return 44100;
945 case HDSP_systemFrequency48: return 48000;
946 case HDSP_systemFrequency64: return 64000;
947 case HDSP_systemFrequency88_2: return 88200;
948 case HDSP_systemFrequency96: return 96000;
949 default:
950 return 0;
951 }
952}
953
936static void hdsp_compute_period_size(struct hdsp *hdsp) 954static void hdsp_compute_period_size(struct hdsp *hdsp)
937{ 955{
938 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8)); 956 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 9a19ae6a64d9..ab423bc82342 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -540,7 +540,8 @@ static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf,
540 540
541static inline int HDSPM_bit2freq(int n) 541static inline int HDSPM_bit2freq(int n)
542{ 542{
543 static int bit2freq_tab[] = { 0, 32000, 44100, 48000, 64000, 88200, 543 static const int bit2freq_tab[] = {
544 0, 32000, 44100, 48000, 64000, 88200,
544 96000, 128000, 176400, 192000 }; 545 96000, 128000, 176400, 192000 };
545 if (n < 1 || n > 9) 546 if (n < 1 || n > 9)
546 return 0; 547 return 0;
@@ -582,7 +583,7 @@ static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan,
582 return hdspm->mixer->ch[chan].pb[pb]; 583 return hdspm->mixer->ch[chan].pb[pb];
583} 584}
584 585
585static inline int hdspm_write_in_gain(struct hdspm * hdspm, unsigned int chan, 586static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan,
586 unsigned int in, unsigned short data) 587 unsigned int in, unsigned short data)
587{ 588{
588 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) 589 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
@@ -595,7 +596,7 @@ static inline int hdspm_write_in_gain(struct hdspm * hdspm, unsigned int chan,
595 return 0; 596 return 0;
596} 597}
597 598
598static inline int hdspm_write_pb_gain(struct hdspm * hdspm, unsigned int chan, 599static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan,
599 unsigned int pb, unsigned short data) 600 unsigned int pb, unsigned short data)
600{ 601{
601 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) 602 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
@@ -621,7 +622,7 @@ static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v)
621} 622}
622 623
623/* check if same process is writing and reading */ 624/* check if same process is writing and reading */
624static inline int snd_hdspm_use_is_exclusive(struct hdspm * hdspm) 625static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm)
625{ 626{
626 unsigned long flags; 627 unsigned long flags;
627 int ret = 1; 628 int ret = 1;
@@ -636,7 +637,7 @@ static inline int snd_hdspm_use_is_exclusive(struct hdspm * hdspm)
636} 637}
637 638
638/* check for external sample rate */ 639/* check for external sample rate */
639static inline int hdspm_external_sample_rate(struct hdspm * hdspm) 640static int hdspm_external_sample_rate(struct hdspm *hdspm)
640{ 641{
641 if (hdspm->is_aes32) { 642 if (hdspm->is_aes32) {
642 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2); 643 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
@@ -787,7 +788,7 @@ static inline void hdspm_stop_audio(struct hdspm * s)
787} 788}
788 789
789/* should I silence all or only opened ones ? doit all for first even is 4MB*/ 790/* should I silence all or only opened ones ? doit all for first even is 4MB*/
790static inline void hdspm_silence_playback(struct hdspm * hdspm) 791static void hdspm_silence_playback(struct hdspm *hdspm)
791{ 792{
792 int i; 793 int i;
793 int n = hdspm->period_bytes; 794 int n = hdspm->period_bytes;
@@ -1028,9 +1029,9 @@ static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id,
1028{ 1029{
1029 /* the hardware already does the relevant bit-mask with 0xff */ 1030 /* the hardware already does the relevant bit-mask with 0xff */
1030 if (id) 1031 if (id)
1031 return hdspm_write(hdspm, HDSPM_midiDataOut1, val); 1032 hdspm_write(hdspm, HDSPM_midiDataOut1, val);
1032 else 1033 else
1033 return hdspm_write(hdspm, HDSPM_midiDataOut0, val); 1034 hdspm_write(hdspm, HDSPM_midiDataOut0, val);
1034} 1035}
1035 1036
1036static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id) 1037static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id)
@@ -1057,7 +1058,7 @@ static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id)
1057 return 0; 1058 return 0;
1058} 1059}
1059 1060
1060static inline void snd_hdspm_flush_midi_input (struct hdspm *hdspm, int id) 1061static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id)
1061{ 1062{
1062 while (snd_hdspm_midi_input_available (hdspm, id)) 1063 while (snd_hdspm_midi_input_available (hdspm, id))
1063 snd_hdspm_midi_read_byte (hdspm, id); 1064 snd_hdspm_midi_read_byte (hdspm, id);
diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c
index 742f1180c39e..df2007e3be7c 100644
--- a/sound/pci/sis7019.c
+++ b/sound/pci/sis7019.c
@@ -1194,7 +1194,6 @@ static int sis_suspend(struct pci_dev *pci, pm_message_t state)
1194 /* snd_pcm_suspend_all() stopped all channels, so we're quiescent. 1194 /* snd_pcm_suspend_all() stopped all channels, so we're quiescent.
1195 */ 1195 */
1196 if (sis->irq >= 0) { 1196 if (sis->irq >= 0) {
1197 synchronize_irq(sis->irq);
1198 free_irq(sis->irq, sis); 1197 free_irq(sis->irq, sis);
1199 sis->irq = -1; 1198 sis->irq = -1;
1200 } 1199 }
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index 71138ff9b310..bbcee2c09ae4 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -3676,6 +3676,8 @@ static int snd_trident_free(struct snd_trident *trident)
3676 else if (trident->device == TRIDENT_DEVICE_ID_SI7018) { 3676 else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
3677 outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); 3677 outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
3678 } 3678 }
3679 if (trident->irq >= 0)
3680 free_irq(trident->irq, trident);
3679 if (trident->tlb.buffer.area) { 3681 if (trident->tlb.buffer.area) {
3680 outl(0, TRID_REG(trident, NX_TLBC)); 3682 outl(0, TRID_REG(trident, NX_TLBC));
3681 if (trident->tlb.memhdr) 3683 if (trident->tlb.memhdr)
@@ -3685,8 +3687,6 @@ static int snd_trident_free(struct snd_trident *trident)
3685 vfree(trident->tlb.shadow_entries); 3687 vfree(trident->tlb.shadow_entries);
3686 snd_dma_free_pages(&trident->tlb.buffer); 3688 snd_dma_free_pages(&trident->tlb.buffer);
3687 } 3689 }
3688 if (trident->irq >= 0)
3689 free_irq(trident->irq, trident);
3690 pci_release_regions(trident->pci); 3690 pci_release_regions(trident->pci);
3691 pci_disable_device(trident->pci); 3691 pci_disable_device(trident->pci);
3692 kfree(trident); 3692 kfree(trident);
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index a756be661f9a..b585cc3e4c47 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -2236,7 +2236,7 @@ static int snd_via82xx_free(struct via82xx *chip)
2236 /* disable interrupts */ 2236 /* disable interrupts */
2237 for (i = 0; i < chip->num_devs; i++) 2237 for (i = 0; i < chip->num_devs; i++)
2238 snd_via82xx_channel_reset(chip, &chip->devs[i]); 2238 snd_via82xx_channel_reset(chip, &chip->devs[i]);
2239 synchronize_irq(chip->irq); 2239
2240 if (chip->irq >= 0) 2240 if (chip->irq >= 0)
2241 free_irq(chip->irq, chip); 2241 free_irq(chip->irq, chip);
2242 __end_hw: 2242 __end_hw:
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index f5df1c79bee1..31f64ee39882 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -1075,7 +1075,7 @@ static int snd_via82xx_free(struct via82xx_modem *chip)
1075 /* disable interrupts */ 1075 /* disable interrupts */
1076 for (i = 0; i < chip->num_devs; i++) 1076 for (i = 0; i < chip->num_devs; i++)
1077 snd_via82xx_channel_reset(chip, &chip->devs[i]); 1077 snd_via82xx_channel_reset(chip, &chip->devs[i]);
1078 synchronize_irq(chip->irq); 1078
1079 __end_hw: 1079 __end_hw:
1080 if (chip->irq >= 0) 1080 if (chip->irq >= 0)
1081 free_irq(chip->irq, chip); 1081 free_irq(chip->irq, chip);
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 42c1eb7d35f5..29b3056c5109 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -2249,6 +2249,8 @@ static int snd_ymfpci_free(struct snd_ymfpci *chip)
2249#ifdef CONFIG_PM 2249#ifdef CONFIG_PM
2250 vfree(chip->saved_regs); 2250 vfree(chip->saved_regs);
2251#endif 2251#endif
2252 if (chip->irq >= 0)
2253 free_irq(chip->irq, chip);
2252 release_and_free_resource(chip->mpu_res); 2254 release_and_free_resource(chip->mpu_res);
2253 release_and_free_resource(chip->fm_res); 2255 release_and_free_resource(chip->fm_res);
2254 snd_ymfpci_free_gameport(chip); 2256 snd_ymfpci_free_gameport(chip);
@@ -2257,8 +2259,6 @@ static int snd_ymfpci_free(struct snd_ymfpci *chip)
2257 if (chip->work_ptr.area) 2259 if (chip->work_ptr.area)
2258 snd_dma_free_pages(&chip->work_ptr); 2260 snd_dma_free_pages(&chip->work_ptr);
2259 2261
2260 if (chip->irq >= 0)
2261 free_irq(chip->irq, chip);
2262 release_and_free_resource(chip->res_reg_area); 2262 release_and_free_resource(chip->res_reg_area);
2263 2263
2264 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl); 2264 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl);
diff --git a/sound/ppc/awacs.c b/sound/ppc/awacs.c
index 8441e780df00..566a6d0daf4a 100644
--- a/sound/ppc/awacs.c
+++ b/sound/ppc/awacs.c
@@ -141,7 +141,7 @@ static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol,
141 uinfo->value.integer.max = 15; 141 uinfo->value.integer.max = 15;
142 return 0; 142 return 0;
143} 143}
144 144
145static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol, 145static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol,
146 struct snd_ctl_elem_value *ucontrol) 146 struct snd_ctl_elem_value *ucontrol)
147{ 147{
@@ -267,7 +267,8 @@ static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol,
267static void awacs_set_cuda(int reg, int val) 267static void awacs_set_cuda(int reg, int val)
268{ 268{
269 struct adb_request req; 269 struct adb_request req;
270 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a, reg, val); 270 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a,
271 reg, val);
271 while (! req.complete) 272 while (! req.complete)
272 cuda_poll(); 273 cuda_poll();
273} 274}
@@ -289,11 +290,11 @@ static void awacs_amp_set_tone(struct awacs_amp *amp, int bass, int treble)
289/* 290/*
290 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo 291 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo
291 */ 292 */
292static int awacs_amp_set_vol(struct awacs_amp *amp, int index, int lvol, int rvol, 293static int awacs_amp_set_vol(struct awacs_amp *amp, int index,
293 int do_check) 294 int lvol, int rvol, int do_check)
294{ 295{
295 if (do_check && amp->amp_vol[index][0] == lvol && 296 if (do_check && amp->amp_vol[index][0] == lvol &&
296 amp->amp_vol[index][1] == rvol) 297 amp->amp_vol[index][1] == rvol)
297 return 0; 298 return 0;
298 awacs_set_cuda(3 + index, lvol); 299 awacs_set_cuda(3 + index, lvol);
299 awacs_set_cuda(5 + index, rvol); 300 awacs_set_cuda(5 + index, rvol);
@@ -337,7 +338,7 @@ static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol,
337 uinfo->value.integer.max = 31; 338 uinfo->value.integer.max = 31;
338 return 0; 339 return 0;
339} 340}
340 341
341static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol, 342static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol,
342 struct snd_ctl_elem_value *ucontrol) 343 struct snd_ctl_elem_value *ucontrol)
343{ 344{
@@ -361,8 +362,10 @@ static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol *kcontrol,
361 snd_assert(amp, return -EINVAL); 362 snd_assert(amp, return -EINVAL);
362 snd_assert(index >= 0 && index <= 1, return -EINVAL); 363 snd_assert(index >= 0 && index <= 1, return -EINVAL);
363 364
364 vol[0] = (31 - (ucontrol->value.integer.value[0] & 31)) | (amp->amp_vol[index][0] & 32); 365 vol[0] = (31 - (ucontrol->value.integer.value[0] & 31))
365 vol[1] = (31 - (ucontrol->value.integer.value[1] & 31)) | (amp->amp_vol[index][1] & 32); 366 | (amp->amp_vol[index][0] & 32);
367 vol[1] = (31 - (ucontrol->value.integer.value[1] & 31))
368 | (amp->amp_vol[index][1] & 32);
366 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); 369 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
367} 370}
368 371
@@ -374,8 +377,10 @@ static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol,
374 struct awacs_amp *amp = chip->mixer_data; 377 struct awacs_amp *amp = chip->mixer_data;
375 snd_assert(amp, return -EINVAL); 378 snd_assert(amp, return -EINVAL);
376 snd_assert(index >= 0 && index <= 1, return -EINVAL); 379 snd_assert(index >= 0 && index <= 1, return -EINVAL);
377 ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32) ? 0 : 1; 380 ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32)
378 ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32) ? 0 : 1; 381 ? 0 : 1;
382 ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32)
383 ? 0 : 1;
379 return 0; 384 return 0;
380} 385}
381 386
@@ -389,8 +394,10 @@ static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol,
389 snd_assert(amp, return -EINVAL); 394 snd_assert(amp, return -EINVAL);
390 snd_assert(index >= 0 && index <= 1, return -EINVAL); 395 snd_assert(index >= 0 && index <= 1, return -EINVAL);
391 396
392 vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32) | (amp->amp_vol[index][0] & 31); 397 vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32)
393 vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32) | (amp->amp_vol[index][1] & 31); 398 | (amp->amp_vol[index][0] & 31);
399 vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32)
400 | (amp->amp_vol[index][1] & 31);
394 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); 401 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
395} 402}
396 403
@@ -403,7 +410,7 @@ static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol,
403 uinfo->value.integer.max = 14; 410 uinfo->value.integer.max = 14;
404 return 0; 411 return 0;
405} 412}
406 413
407static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol, 414static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol,
408 struct snd_ctl_elem_value *ucontrol) 415 struct snd_ctl_elem_value *ucontrol)
409{ 416{
@@ -445,7 +452,7 @@ static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol,
445 uinfo->value.integer.max = 99; 452 uinfo->value.integer.max = 99;
446 return 0; 453 return 0;
447} 454}
448 455
449static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol, 456static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol,
450 struct snd_ctl_elem_value *ucontrol) 457 struct snd_ctl_elem_value *ucontrol)
451{ 458{
@@ -544,7 +551,7 @@ static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol,
544 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 551 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
545 uinfo->count = 1; 552 uinfo->count = 1;
546 uinfo->value.integer.min = 0; 553 uinfo->value.integer.min = 0;
547 uinfo->value.integer.max = 2; 554 uinfo->value.integer.max = 3;
548 return 0; 555 return 0;
549} 556}
550 557
@@ -552,16 +559,14 @@ static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_value *ucontrol) 559 struct snd_ctl_elem_value *ucontrol)
553{ 560{
554 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 561 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
555 int val; 562 int val = 0;
556 unsigned long flags; 563 unsigned long flags;
557 564
558 spin_lock_irqsave(&chip->reg_lock, flags); 565 spin_lock_irqsave(&chip->reg_lock, flags);
559 if (chip->awacs_reg[6] & MASK_MIC_BOOST) 566 if (chip->awacs_reg[6] & MASK_MIC_BOOST)
560 val = 2; 567 val |= 2;
561 else if (chip->awacs_reg[0] & MASK_GAINLINE) 568 if (chip->awacs_reg[0] & MASK_GAINLINE)
562 val = 1; 569 val |= 1;
563 else
564 val = 0;
565 spin_unlock_irqrestore(&chip->reg_lock, flags); 570 spin_unlock_irqrestore(&chip->reg_lock, flags);
566 ucontrol->value.integer.value[0] = val; 571 ucontrol->value.integer.value[0] = val;
567 return 0; 572 return 0;
@@ -578,11 +583,10 @@ static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
578 spin_lock_irqsave(&chip->reg_lock, flags); 583 spin_lock_irqsave(&chip->reg_lock, flags);
579 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE; 584 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
580 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST; 585 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
581 if (ucontrol->value.integer.value[0] > 0) { 586 if (ucontrol->value.integer.value[0] & 1)
582 val0 |= MASK_GAINLINE; 587 val0 |= MASK_GAINLINE;
583 if (ucontrol->value.integer.value[0] > 1) 588 if (ucontrol->value.integer.value[0] & 2)
584 val6 |= MASK_MIC_BOOST; 589 val6 |= MASK_MIC_BOOST;
585 }
586 if (val0 != chip->awacs_reg[0]) { 590 if (val0 != chip->awacs_reg[0]) {
587 snd_pmac_awacs_write_reg(chip, 0, val0); 591 snd_pmac_awacs_write_reg(chip, 0, val0);
588 changed = 1; 592 changed = 1;
@@ -599,9 +603,32 @@ static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
599 * lists of mixer elements 603 * lists of mixer elements
600 */ 604 */
601static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = { 605static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = {
602 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
603 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0), 606 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
604 AWACS_VOLUME("Capture Volume", 0, 4, 0), 607 AWACS_VOLUME("Master Capture Volume", 0, 4, 0),
608/* AWACS_SWITCH("Unknown Playback Switch", 6, SHIFT_PAROUT0, 0), */
609};
610
611static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __initdata = {
612 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
613 AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
614 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
615 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0),
616};
617
618static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = {
619 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
620 AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
621 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
622};
623
624static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __initdata = {
625 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
626 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
627 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
628};
629
630static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = {
631 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
605 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), 632 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
606}; 633};
607 634
@@ -621,35 +648,61 @@ static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = {
621static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata = 648static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata =
622AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1); 649AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
623 650
651static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata =
652AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);
653
624static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = { 654static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = {
625 AWACS_SWITCH("Mic Boost", 0, SHIFT_GAINLINE, 0), 655 AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
626}; 656};
627 657
628static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = { 658static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = {
629 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 659 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
630 .name = "Mic Boost", 660 .name = "Mic Boost Capture Volume",
631 .info = snd_pmac_screamer_mic_boost_info, 661 .info = snd_pmac_screamer_mic_boost_info,
632 .get = snd_pmac_screamer_mic_boost_get, 662 .get = snd_pmac_screamer_mic_boost_get,
633 .put = snd_pmac_screamer_mic_boost_put, 663 .put = snd_pmac_screamer_mic_boost_put,
634 }, 664 },
635}; 665};
636 666
667static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __initdata =
668{
669 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
670};
671
672static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __initdata =
673{
674 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
675 AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
676};
677
678static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __initdata =
679{
680 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
681 AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
682};
683
637static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = { 684static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = {
638 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1), 685 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
639}; 686};
687
640static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata = 688static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata =
641AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1); 689AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
642 690
691static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac __initdata =
692AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
693
643 694
644/* 695/*
645 * add new mixer elements to the card 696 * add new mixer elements to the card
646 */ 697 */
647static int build_mixers(struct snd_pmac *chip, int nums, struct snd_kcontrol_new *mixers) 698static int build_mixers(struct snd_pmac *chip, int nums,
699 struct snd_kcontrol_new *mixers)
648{ 700{
649 int i, err; 701 int i, err;
650 702
651 for (i = 0; i < nums; i++) { 703 for (i = 0; i < nums; i++) {
652 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip))) < 0) 704 err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip));
705 if (err < 0)
653 return err; 706 return err;
654 } 707 }
655 return 0; 708 return 0;
@@ -699,8 +752,10 @@ static void snd_pmac_awacs_resume(struct snd_pmac *chip)
699#ifdef PMAC_AMP_AVAIL 752#ifdef PMAC_AMP_AVAIL
700 if (chip->mixer_data) { 753 if (chip->mixer_data) {
701 struct awacs_amp *amp = chip->mixer_data; 754 struct awacs_amp *amp = chip->mixer_data;
702 awacs_amp_set_vol(amp, 0, amp->amp_vol[0][0], amp->amp_vol[0][1], 0); 755 awacs_amp_set_vol(amp, 0,
703 awacs_amp_set_vol(amp, 1, amp->amp_vol[1][0], amp->amp_vol[1][1], 0); 756 amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
757 awacs_amp_set_vol(amp, 1,
758 amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
704 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]); 759 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
705 awacs_amp_set_master(amp, amp->amp_master); 760 awacs_amp_set_master(amp, amp->amp_master);
706 } 761 }
@@ -708,6 +763,14 @@ static void snd_pmac_awacs_resume(struct snd_pmac *chip)
708} 763}
709#endif /* CONFIG_PM */ 764#endif /* CONFIG_PM */
710 765
766#define IS_PM7500 (machine_is_compatible("AAPL,7500"))
767#define IS_BEIGE (machine_is_compatible("AAPL,Gossamer"))
768#define IS_IMAC (machine_is_compatible("PowerMac2,1") \
769 || machine_is_compatible("PowerMac2,2") \
770 || machine_is_compatible("PowerMac4,1"))
771
772static int imac;
773
711#ifdef PMAC_SUPPORT_AUTOMUTE 774#ifdef PMAC_SUPPORT_AUTOMUTE
712/* 775/*
713 * auto-mute stuffs 776 * auto-mute stuffs
@@ -750,9 +813,16 @@ static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
750 } else 813 } else
751#endif 814#endif
752 { 815 {
753 int reg = chip->awacs_reg[1] | (MASK_HDMUTE|MASK_SPKMUTE); 816 int reg = chip->awacs_reg[1]
817 | (MASK_HDMUTE | MASK_SPKMUTE);
818 if (imac) {
819 reg &= ~MASK_SPKMUTE;
820 reg &= ~MASK_PAROUT1;
821 }
754 if (snd_pmac_awacs_detect_headphone(chip)) 822 if (snd_pmac_awacs_detect_headphone(chip))
755 reg &= ~MASK_HDMUTE; 823 reg &= ~MASK_HDMUTE;
824 else if (imac)
825 reg |= MASK_PAROUT1;
756 else 826 else
757 reg &= ~MASK_SPKMUTE; 827 reg &= ~MASK_SPKMUTE;
758 if (do_notify && reg == chip->awacs_reg[1]) 828 if (do_notify && reg == chip->awacs_reg[1])
@@ -778,8 +848,11 @@ static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
778int __init 848int __init
779snd_pmac_awacs_init(struct snd_pmac *chip) 849snd_pmac_awacs_init(struct snd_pmac *chip)
780{ 850{
851 int pm7500 = IS_PM7500;
852 int beige = IS_BEIGE;
781 int err, vol; 853 int err, vol;
782 854
855 imac = IS_IMAC;
783 /* looks like MASK_GAINLINE triggers something, so we set here 856 /* looks like MASK_GAINLINE triggers something, so we set here
784 * as start-up 857 * as start-up
785 */ 858 */
@@ -787,7 +860,7 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
787 chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE; 860 chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
788 /* FIXME: Only machines with external SRS module need MASK_PAROUT */ 861 /* FIXME: Only machines with external SRS module need MASK_PAROUT */
789 if (chip->has_iic || chip->device_id == 0x5 || 862 if (chip->has_iic || chip->device_id == 0x5 ||
790 /*chip->_device_id == 0x8 || */ 863 /* chip->_device_id == 0x8 || */
791 chip->device_id == 0xb) 864 chip->device_id == 0xb)
792 chip->awacs_reg[1] |= MASK_PAROUT; 865 chip->awacs_reg[1] |= MASK_PAROUT;
793 /* get default volume from nvram */ 866 /* get default volume from nvram */
@@ -798,8 +871,10 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
798 chip->awacs_reg[2] = vol; 871 chip->awacs_reg[2] = vol;
799 chip->awacs_reg[4] = vol; 872 chip->awacs_reg[4] = vol;
800 if (chip->model == PMAC_SCREAMER) { 873 if (chip->model == PMAC_SCREAMER) {
801 chip->awacs_reg[5] = vol; /* FIXME: screamer has loopthru vol control */ 874 /* FIXME: screamer has loopthru vol control */
802 chip->awacs_reg[6] = MASK_MIC_BOOST; /* FIXME: maybe should be vol << 3 for PCMCIA speaker */ 875 chip->awacs_reg[5] = vol;
876 /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
877 chip->awacs_reg[6] = MASK_MIC_BOOST;
803 chip->awacs_reg[7] = 0; 878 chip->awacs_reg[7] = 0;
804 } 879 }
805 880
@@ -815,7 +890,8 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
815 return -ENOMEM; 890 return -ENOMEM;
816 chip->mixer_data = amp; 891 chip->mixer_data = amp;
817 chip->mixer_free = awacs_amp_free; 892 chip->mixer_free = awacs_amp_free;
818 awacs_amp_set_vol(amp, 0, 63, 63, 0); /* mute and zero vol */ 893 /* mute and zero vol */
894 awacs_amp_set_vol(amp, 0, 63, 63, 0);
819 awacs_amp_set_vol(amp, 1, 63, 63, 0); 895 awacs_amp_set_vol(amp, 1, 63, 63, 0);
820 awacs_amp_set_tone(amp, 7, 7); /* 0 dB */ 896 awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
821 awacs_amp_set_master(amp, 79); /* 0 dB */ 897 awacs_amp_set_master(amp, 79); /* 0 dB */
@@ -826,20 +902,25 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
826 /* set headphone-jack detection bit */ 902 /* set headphone-jack detection bit */
827 switch (chip->model) { 903 switch (chip->model) {
828 case PMAC_AWACS: 904 case PMAC_AWACS:
829 chip->hp_stat_mask = 0x04; 905 chip->hp_stat_mask = pm7500 ? MASK_HDPCONN
906 : MASK_LOCONN;
830 break; 907 break;
831 case PMAC_SCREAMER: 908 case PMAC_SCREAMER:
832 switch (chip->device_id) { 909 switch (chip->device_id) {
833 case 0x08: 910 case 0x08:
834 /* 1 = side jack, 2 = front jack */ 911 case 0x0B:
835 chip->hp_stat_mask = 0x03; 912 chip->hp_stat_mask = imac
913 ? MASK_LOCONN_IMAC |
914 MASK_HDPLCONN_IMAC |
915 MASK_HDPRCONN_IMAC
916 : MASK_HDPCONN;
836 break; 917 break;
837 case 0x00: 918 case 0x00:
838 case 0x05: 919 case 0x05:
839 chip->hp_stat_mask = 0x04; 920 chip->hp_stat_mask = MASK_LOCONN;
840 break; 921 break;
841 default: 922 default:
842 chip->hp_stat_mask = 0x08; 923 chip->hp_stat_mask = MASK_HDPCONN;
843 break; 924 break;
844 } 925 }
845 break; 926 break;
@@ -854,19 +935,43 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
854 */ 935 */
855 strcpy(chip->card->mixername, "PowerMac AWACS"); 936 strcpy(chip->card->mixername, "PowerMac AWACS");
856 937
857 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers), 938 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
858 snd_pmac_awacs_mixers)) < 0) 939 snd_pmac_awacs_mixers);
940 if (err < 0)
859 return err; 941 return err;
860 if (chip->model == PMAC_SCREAMER) 942 if (beige)
943 ;
944 else if (chip->model == PMAC_SCREAMER)
861 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2), 945 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
862 snd_pmac_screamer_mixers2); 946 snd_pmac_screamer_mixers2);
863 else 947 else if (!pm7500)
864 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2), 948 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
865 snd_pmac_awacs_mixers2); 949 snd_pmac_awacs_mixers2);
866 if (err < 0) 950 if (err < 0)
867 return err; 951 return err;
868 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_master_sw, chip); 952 if (pm7500)
869 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) 953 err = build_mixers(chip,
954 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
955 snd_pmac_awacs_mixers_pmac7500);
956 else if (beige)
957 err = build_mixers(chip,
958 ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
959 snd_pmac_screamer_mixers_beige);
960 else if (imac)
961 err = build_mixers(chip,
962 ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
963 snd_pmac_screamer_mixers_imac);
964 else
965 err = build_mixers(chip,
966 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac),
967 snd_pmac_awacs_mixers_pmac);
968 if (err < 0)
969 return err;
970 chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac)
971 ? &snd_pmac_awacs_master_sw_imac
972 : &snd_pmac_awacs_master_sw, chip);
973 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
974 if (err < 0)
870 return err; 975 return err;
871#ifdef PMAC_AMP_AVAIL 976#ifdef PMAC_AMP_AVAIL
872 if (chip->mixer_data) { 977 if (chip->mixer_data) {
@@ -876,37 +981,58 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
876 * screamer registers. 981 * screamer registers.
877 * in this case, it seems the route C is not used. 982 * in this case, it seems the route C is not used.
878 */ 983 */
879 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol), 984 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
880 snd_pmac_awacs_amp_vol)) < 0) 985 snd_pmac_awacs_amp_vol);
986 if (err < 0)
881 return err; 987 return err;
882 /* overwrite */ 988 /* overwrite */
883 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw, chip); 989 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw,
884 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) 990 chip);
991 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
992 if (err < 0)
885 return err; 993 return err;
886 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw, chip); 994 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw,
887 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) 995 chip);
996 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
997 if (err < 0)
888 return err; 998 return err;
889 } else 999 } else
890#endif /* PMAC_AMP_AVAIL */ 1000#endif /* PMAC_AMP_AVAIL */
891 { 1001 {
892 /* route A = headphone, route C = speaker */ 1002 /* route A = headphone, route C = speaker */
893 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol), 1003 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol),
894 snd_pmac_awacs_speaker_vol)) < 0) 1004 snd_pmac_awacs_speaker_vol);
1005 if (err < 0)
895 return err; 1006 return err;
896 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_speaker_sw, chip); 1007 chip->speaker_sw_ctl = snd_ctl_new1(imac
897 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) 1008 ? &snd_pmac_awacs_speaker_sw_imac
1009 : &snd_pmac_awacs_speaker_sw, chip);
1010 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
1011 if (err < 0)
898 return err; 1012 return err;
899 } 1013 }
900 1014
901 if (chip->model == PMAC_SCREAMER) { 1015 if (beige)
902 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mic_boost), 1016 err = build_mixers(chip,
903 snd_pmac_screamer_mic_boost)) < 0) 1017 ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
904 return err; 1018 snd_pmac_screamer_mic_boost_beige);
905 } else { 1019 else if (imac)
906 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost), 1020 err = build_mixers(chip,
907 snd_pmac_awacs_mic_boost)) < 0) 1021 ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
908 return err; 1022 snd_pmac_screamer_mic_boost_imac);
909 } 1023 else if (chip->model == PMAC_SCREAMER)
1024 err = build_mixers(chip,
1025 ARRAY_SIZE(snd_pmac_screamer_mic_boost),
1026 snd_pmac_screamer_mic_boost);
1027 else if (pm7500)
1028 err = build_mixers(chip,
1029 ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
1030 snd_pmac_awacs_mic_boost_pmac7500);
1031 else
1032 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
1033 snd_pmac_awacs_mic_boost);
1034 if (err < 0)
1035 return err;
910 1036
911 /* 1037 /*
912 * set lowlevel callbacks 1038 * set lowlevel callbacks
@@ -917,7 +1043,8 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
917 chip->resume = snd_pmac_awacs_resume; 1043 chip->resume = snd_pmac_awacs_resume;
918#endif 1044#endif
919#ifdef PMAC_SUPPORT_AUTOMUTE 1045#ifdef PMAC_SUPPORT_AUTOMUTE
920 if ((err = snd_pmac_add_automute(chip)) < 0) 1046 err = snd_pmac_add_automute(chip);
1047 if (err < 0)
921 return err; 1048 return err;
922 chip->detect_headphone = snd_pmac_awacs_detect_headphone; 1049 chip->detect_headphone = snd_pmac_awacs_detect_headphone;
923 chip->update_automute = snd_pmac_awacs_update_automute; 1050 chip->update_automute = snd_pmac_awacs_update_automute;
diff --git a/sound/ppc/awacs.h b/sound/ppc/awacs.h
index 1b2cc44eda57..c33e6a531cf7 100644
--- a/sound/ppc/awacs.h
+++ b/sound/ppc/awacs.h
@@ -116,6 +116,11 @@ struct awacs_regs {
116#define MASK_HDMUTE MASK_AMUTE 116#define MASK_HDMUTE MASK_AMUTE
117#define SHIFT_HDMUTE 9 117#define SHIFT_HDMUTE 9
118#define MASK_PAROUT (0x3 << 10) /* Parallel Out (???) */ 118#define MASK_PAROUT (0x3 << 10) /* Parallel Out (???) */
119#define MASK_PAROUT0 (0x1 << 10) /* Parallel Out (???) */
120#define MASK_PAROUT1 (0x1 << 11) /* Parallel Out (enable speaker) */
121#define SHIFT_PAROUT 10
122#define SHIFT_PAROUT0 10
123#define SHIFT_PAROUT1 11
119 124
120#define SAMPLERATE_48000 (0x0 << 3) /* 48 or 44.1 kHz */ 125#define SAMPLERATE_48000 (0x0 << 3) /* 48 or 44.1 kHz */
121#define SAMPLERATE_32000 (0x1 << 3) /* 32 or 29.4 kHz */ 126#define SAMPLERATE_32000 (0x1 << 3) /* 32 or 29.4 kHz */
@@ -139,7 +144,7 @@ struct awacs_regs {
139#define VOLLEFT(x) (((~(x)) << 6) & MASK_OUTVOLLEFT) 144#define VOLLEFT(x) (((~(x)) << 6) & MASK_OUTVOLLEFT)
140 145
141/* address 6 */ 146/* address 6 */
142#define MASK_MIC_BOOST (0x4) /* screamer mic boost */ 147#define MASK_MIC_BOOST (0x4) /* screamer mic boost */
143#define SHIFT_MIC_BOOST 2 148#define SHIFT_MIC_BOOST 2
144 149
145/* Audio Codec Status Reg Bit Masks */ 150/* Audio Codec Status Reg Bit Masks */
@@ -152,8 +157,15 @@ struct awacs_regs {
152#define MASK_REVISION (0xf << 12) /* Revision Number */ 157#define MASK_REVISION (0xf << 12) /* Revision Number */
153#define MASK_MFGID (0xf << 8) /* Mfg. ID */ 158#define MASK_MFGID (0xf << 8) /* Mfg. ID */
154#define MASK_CODSTATRES (0xf << 4) /* bits 4 - 7 reserved */ 159#define MASK_CODSTATRES (0xf << 4) /* bits 4 - 7 reserved */
155#define MASK_INPPORT (0xf) /* Input Port */ 160#define MASK_INSENSE (0xf) /* port sense bits: */
156#define MASK_HDPCONN 8 /* headphone plugged in */ 161#define MASK_HDPCONN 8 /* headphone plugged in */
162#define MASK_LOCONN 4 /* line-out plugged in */
163#define MASK_LICONN 2 /* line-in plugged in */
164#define MASK_MICCONN 1 /* microphone plugged in */
165#define MASK_LICONN_IMAC 8 /* line-in plugged in */
166#define MASK_HDPRCONN_IMAC 4 /* headphone right plugged in */
167#define MASK_HDPLCONN_IMAC 2 /* headphone left plugged in */
168#define MASK_LOCONN_IMAC 1 /* line-out plugged in */
157 169
158/* Clipping Count Reg Bit Masks */ 170/* Clipping Count Reg Bit Masks */
159/* -------- ----- --- --- ----- */ 171/* -------- ----- --- --- ----- */
@@ -163,7 +175,8 @@ struct awacs_regs {
163/* DBDMA ChannelStatus Bit Masks */ 175/* DBDMA ChannelStatus Bit Masks */
164/* ----- ------------- --- ----- */ 176/* ----- ------------- --- ----- */
165#define MASK_CSERR (0x1 << 7) /* Error */ 177#define MASK_CSERR (0x1 << 7) /* Error */
166#define MASK_EOI (0x1 << 6) /* End of Input -- only for Input Channel */ 178#define MASK_EOI (0x1 << 6) /* End of Input --
179 only for Input Channel */
167#define MASK_CSUNUSED (0x1f << 1) /* bits 1-5 not used */ 180#define MASK_CSUNUSED (0x1f << 1) /* bits 1-5 not used */
168#define MASK_WAIT (0x1) /* Wait */ 181#define MASK_WAIT (0x1) /* Wait */
169 182
diff --git a/sound/ppc/burgundy.c b/sound/ppc/burgundy.c
index 1a545ac0de04..f860d39af36b 100644
--- a/sound/ppc/burgundy.c
+++ b/sound/ppc/burgundy.c
@@ -102,7 +102,8 @@ snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr)
102} 102}
103 103
104static void 104static void
105snd_pmac_burgundy_wcb(struct snd_pmac *chip, unsigned int addr, unsigned int val) 105snd_pmac_burgundy_wcb(struct snd_pmac *chip, unsigned int addr,
106 unsigned int val)
106{ 107{
107 out_le32(&chip->awacs->codec_ctrl, addr + 0x300000 + (val & 0xff)); 108 out_le32(&chip->awacs->codec_ctrl, addr + 0x300000 + (val & 0xff));
108 snd_pmac_burgundy_busy_wait(chip); 109 snd_pmac_burgundy_busy_wait(chip);
@@ -126,8 +127,11 @@ snd_pmac_burgundy_rcb(struct snd_pmac *chip, unsigned int addr)
126 return val; 127 return val;
127} 128}
128 129
130#define BASE2ADDR(base) ((base) << 12)
131#define ADDR2BASE(addr) ((addr) >> 12)
132
129/* 133/*
130 * Burgundy volume: 0 - 100, stereo 134 * Burgundy volume: 0 - 100, stereo, word reg
131 */ 135 */
132static void 136static void
133snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address, 137snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address,
@@ -168,13 +172,6 @@ snd_pmac_burgundy_read_volume(struct snd_pmac *chip, unsigned int address,
168 volume[1] = 0; 172 volume[1] = 0;
169} 173}
170 174
171
172/*
173 */
174
175#define BASE2ADDR(base) ((base) << 12)
176#define ADDR2BASE(addr) ((addr) >> 12)
177
178static int snd_pmac_burgundy_info_volume(struct snd_kcontrol *kcontrol, 175static int snd_pmac_burgundy_info_volume(struct snd_kcontrol *kcontrol,
179 struct snd_ctl_elem_info *uinfo) 176 struct snd_ctl_elem_info *uinfo)
180{ 177{
@@ -191,8 +188,8 @@ static int snd_pmac_burgundy_get_volume(struct snd_kcontrol *kcontrol,
191 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 188 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
192 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 189 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
193 int shift = (kcontrol->private_value >> 8) & 0xff; 190 int shift = (kcontrol->private_value >> 8) & 0xff;
194 snd_pmac_burgundy_read_volume(chip, addr, ucontrol->value.integer.value, 191 snd_pmac_burgundy_read_volume(chip, addr,
195 shift); 192 ucontrol->value.integer.value, shift);
196 return 0; 193 return 0;
197} 194}
198 195
@@ -204,24 +201,163 @@ static int snd_pmac_burgundy_put_volume(struct snd_kcontrol *kcontrol,
204 int shift = (kcontrol->private_value >> 8) & 0xff; 201 int shift = (kcontrol->private_value >> 8) & 0xff;
205 long nvoices[2]; 202 long nvoices[2];
206 203
207 snd_pmac_burgundy_write_volume(chip, addr, ucontrol->value.integer.value, 204 snd_pmac_burgundy_write_volume(chip, addr,
208 shift); 205 ucontrol->value.integer.value, shift);
209 snd_pmac_burgundy_read_volume(chip, addr, nvoices, shift); 206 snd_pmac_burgundy_read_volume(chip, addr, nvoices, shift);
210 return (nvoices[0] != ucontrol->value.integer.value[0] || 207 return (nvoices[0] != ucontrol->value.integer.value[0] ||
211 nvoices[1] != ucontrol->value.integer.value[1]); 208 nvoices[1] != ucontrol->value.integer.value[1]);
212} 209}
213 210
214#define BURGUNDY_VOLUME(xname, xindex, addr, shift) \ 211#define BURGUNDY_VOLUME_W(xname, xindex, addr, shift) \
215{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 212{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
216 .info = snd_pmac_burgundy_info_volume,\ 213 .info = snd_pmac_burgundy_info_volume,\
217 .get = snd_pmac_burgundy_get_volume,\ 214 .get = snd_pmac_burgundy_get_volume,\
218 .put = snd_pmac_burgundy_put_volume,\ 215 .put = snd_pmac_burgundy_put_volume,\
219 .private_value = ((ADDR2BASE(addr) & 0xff) | ((shift) << 8)) } 216 .private_value = ((ADDR2BASE(addr) & 0xff) | ((shift) << 8)) }
220 217
221/* lineout/speaker */ 218/*
219 * Burgundy volume: 0 - 100, stereo, 2-byte reg
220 */
221static void
222snd_pmac_burgundy_write_volume_2b(struct snd_pmac *chip, unsigned int address,
223 long *volume, int off)
224{
225 int lvolume, rvolume;
222 226
223static int snd_pmac_burgundy_info_switch_out(struct snd_kcontrol *kcontrol, 227 off |= off << 2;
224 struct snd_ctl_elem_info *uinfo) 228 lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0;
229 rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0;
230
231 snd_pmac_burgundy_wcb(chip, address + off, lvolume);
232 snd_pmac_burgundy_wcb(chip, address + off + 0x500, rvolume);
233}
234
235static void
236snd_pmac_burgundy_read_volume_2b(struct snd_pmac *chip, unsigned int address,
237 long *volume, int off)
238{
239 volume[0] = snd_pmac_burgundy_rcb(chip, address + off);
240 if (volume[0] >= BURGUNDY_VOLUME_OFFSET)
241 volume[0] -= BURGUNDY_VOLUME_OFFSET;
242 else
243 volume[0] = 0;
244 volume[1] = snd_pmac_burgundy_rcb(chip, address + off + 0x100);
245 if (volume[1] >= BURGUNDY_VOLUME_OFFSET)
246 volume[1] -= BURGUNDY_VOLUME_OFFSET;
247 else
248 volume[1] = 0;
249}
250
251static int snd_pmac_burgundy_info_volume_2b(struct snd_kcontrol *kcontrol,
252 struct snd_ctl_elem_info *uinfo)
253{
254 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
255 uinfo->count = 2;
256 uinfo->value.integer.min = 0;
257 uinfo->value.integer.max = 100;
258 return 0;
259}
260
261static int snd_pmac_burgundy_get_volume_2b(struct snd_kcontrol *kcontrol,
262 struct snd_ctl_elem_value *ucontrol)
263{
264 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
265 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
266 int off = kcontrol->private_value & 0x300;
267 snd_pmac_burgundy_read_volume_2b(chip, addr,
268 ucontrol->value.integer.value, off);
269 return 0;
270}
271
272static int snd_pmac_burgundy_put_volume_2b(struct snd_kcontrol *kcontrol,
273 struct snd_ctl_elem_value *ucontrol)
274{
275 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
276 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
277 int off = kcontrol->private_value & 0x300;
278 long nvoices[2];
279
280 snd_pmac_burgundy_write_volume_2b(chip, addr,
281 ucontrol->value.integer.value, off);
282 snd_pmac_burgundy_read_volume_2b(chip, addr, nvoices, off);
283 return (nvoices[0] != ucontrol->value.integer.value[0] ||
284 nvoices[1] != ucontrol->value.integer.value[1]);
285}
286
287#define BURGUNDY_VOLUME_2B(xname, xindex, addr, off) \
288{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
289 .info = snd_pmac_burgundy_info_volume_2b,\
290 .get = snd_pmac_burgundy_get_volume_2b,\
291 .put = snd_pmac_burgundy_put_volume_2b,\
292 .private_value = ((ADDR2BASE(addr) & 0xff) | ((off) << 8)) }
293
294/*
295 * Burgundy gain/attenuation: 0 - 15, mono/stereo, byte reg
296 */
297static int snd_pmac_burgundy_info_gain(struct snd_kcontrol *kcontrol,
298 struct snd_ctl_elem_info *uinfo)
299{
300 int stereo = (kcontrol->private_value >> 24) & 1;
301 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
302 uinfo->count = stereo + 1;
303 uinfo->value.integer.min = 0;
304 uinfo->value.integer.max = 15;
305 return 0;
306}
307
308static int snd_pmac_burgundy_get_gain(struct snd_kcontrol *kcontrol,
309 struct snd_ctl_elem_value *ucontrol)
310{
311 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
312 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
313 int stereo = (kcontrol->private_value >> 24) & 1;
314 int atten = (kcontrol->private_value >> 25) & 1;
315 int oval;
316
317 oval = snd_pmac_burgundy_rcb(chip, addr);
318 if (atten)
319 oval = ~oval & 0xff;
320 ucontrol->value.integer.value[0] = oval & 0xf;
321 if (stereo)
322 ucontrol->value.integer.value[1] = (oval >> 4) & 0xf;
323 return 0;
324}
325
326static int snd_pmac_burgundy_put_gain(struct snd_kcontrol *kcontrol,
327 struct snd_ctl_elem_value *ucontrol)
328{
329 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
330 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
331 int stereo = (kcontrol->private_value >> 24) & 1;
332 int atten = (kcontrol->private_value >> 25) & 1;
333 int oval, val;
334
335 oval = snd_pmac_burgundy_rcb(chip, addr);
336 if (atten)
337 oval = ~oval & 0xff;
338 val = ucontrol->value.integer.value[0];
339 if (stereo)
340 val |= ucontrol->value.integer.value[1] << 4;
341 else
342 val |= ucontrol->value.integer.value[0] << 4;
343 if (atten)
344 val = ~val & 0xff;
345 snd_pmac_burgundy_wcb(chip, addr, val);
346 return val != oval;
347}
348
349#define BURGUNDY_VOLUME_B(xname, xindex, addr, stereo, atten) \
350{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
351 .info = snd_pmac_burgundy_info_gain,\
352 .get = snd_pmac_burgundy_get_gain,\
353 .put = snd_pmac_burgundy_put_gain,\
354 .private_value = (ADDR2BASE(addr) | ((stereo) << 24) | ((atten) << 25)) }
355
356/*
357 * Burgundy switch: 0/1, mono/stereo, word reg
358 */
359static int snd_pmac_burgundy_info_switch_w(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_info *uinfo)
225{ 361{
226 int stereo = (kcontrol->private_value >> 24) & 1; 362 int stereo = (kcontrol->private_value >> 24) & 1;
227 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 363 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
@@ -231,111 +367,207 @@ static int snd_pmac_burgundy_info_switch_out(struct snd_kcontrol *kcontrol,
231 return 0; 367 return 0;
232} 368}
233 369
234static int snd_pmac_burgundy_get_switch_out(struct snd_kcontrol *kcontrol, 370static int snd_pmac_burgundy_get_switch_w(struct snd_kcontrol *kcontrol,
235 struct snd_ctl_elem_value *ucontrol) 371 struct snd_ctl_elem_value *ucontrol)
236{ 372{
237 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 373 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
238 int lmask = kcontrol->private_value & 0xff; 374 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
239 int rmask = (kcontrol->private_value >> 8) & 0xff; 375 int lmask = 1 << (kcontrol->private_value & 0xff);
376 int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff);
240 int stereo = (kcontrol->private_value >> 24) & 1; 377 int stereo = (kcontrol->private_value >> 24) & 1;
241 int val = snd_pmac_burgundy_rcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES); 378 int val = snd_pmac_burgundy_rcw(chip, addr);
242 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0; 379 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0;
243 if (stereo) 380 if (stereo)
244 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0; 381 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
245 return 0; 382 return 0;
246} 383}
247 384
248static int snd_pmac_burgundy_put_switch_out(struct snd_kcontrol *kcontrol, 385static int snd_pmac_burgundy_put_switch_w(struct snd_kcontrol *kcontrol,
249 struct snd_ctl_elem_value *ucontrol) 386 struct snd_ctl_elem_value *ucontrol)
250{ 387{
251 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 388 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
252 int lmask = kcontrol->private_value & 0xff; 389 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
253 int rmask = (kcontrol->private_value >> 8) & 0xff; 390 int lmask = 1 << (kcontrol->private_value & 0xff);
391 int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff);
254 int stereo = (kcontrol->private_value >> 24) & 1; 392 int stereo = (kcontrol->private_value >> 24) & 1;
255 int val, oval; 393 int val, oval;
256 oval = snd_pmac_burgundy_rcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES); 394 oval = snd_pmac_burgundy_rcw(chip, addr);
257 val = oval & ~(lmask | rmask); 395 val = oval & ~(lmask | (stereo ? rmask : 0));
258 if (ucontrol->value.integer.value[0]) 396 if (ucontrol->value.integer.value[0])
259 val |= lmask; 397 val |= lmask;
260 if (stereo && ucontrol->value.integer.value[1]) 398 if (stereo && ucontrol->value.integer.value[1])
261 val |= rmask; 399 val |= rmask;
262 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, val); 400 snd_pmac_burgundy_wcw(chip, addr, val);
263 return val != oval; 401 return val != oval;
264} 402}
265 403
266#define BURGUNDY_OUTPUT_SWITCH(xname, xindex, lmask, rmask, stereo) \ 404#define BURGUNDY_SWITCH_W(xname, xindex, addr, lbit, rbit, stereo) \
267{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 405{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
268 .info = snd_pmac_burgundy_info_switch_out,\ 406 .info = snd_pmac_burgundy_info_switch_w,\
269 .get = snd_pmac_burgundy_get_switch_out,\ 407 .get = snd_pmac_burgundy_get_switch_w,\
270 .put = snd_pmac_burgundy_put_switch_out,\ 408 .put = snd_pmac_burgundy_put_switch_w,\
271 .private_value = ((lmask) | ((rmask) << 8) | ((stereo) << 24)) } 409 .private_value = ((lbit) | ((rbit) << 8)\
272 410 | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
273/* line/speaker output volume */ 411
274static int snd_pmac_burgundy_info_volume_out(struct snd_kcontrol *kcontrol, 412/*
275 struct snd_ctl_elem_info *uinfo) 413 * Burgundy switch: 0/1, mono/stereo, byte reg, bit mask
414 */
415static int snd_pmac_burgundy_info_switch_b(struct snd_kcontrol *kcontrol,
416 struct snd_ctl_elem_info *uinfo)
276{ 417{
277 int stereo = (kcontrol->private_value >> 24) & 1; 418 int stereo = (kcontrol->private_value >> 24) & 1;
278 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 419 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
279 uinfo->count = stereo + 1; 420 uinfo->count = stereo + 1;
280 uinfo->value.integer.min = 0; 421 uinfo->value.integer.min = 0;
281 uinfo->value.integer.max = 15; 422 uinfo->value.integer.max = 1;
282 return 0; 423 return 0;
283} 424}
284 425
285static int snd_pmac_burgundy_get_volume_out(struct snd_kcontrol *kcontrol, 426static int snd_pmac_burgundy_get_switch_b(struct snd_kcontrol *kcontrol,
286 struct snd_ctl_elem_value *ucontrol) 427 struct snd_ctl_elem_value *ucontrol)
287{ 428{
288 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 429 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
289 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 430 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
431 int lmask = kcontrol->private_value & 0xff;
432 int rmask = (kcontrol->private_value >> 8) & 0xff;
290 int stereo = (kcontrol->private_value >> 24) & 1; 433 int stereo = (kcontrol->private_value >> 24) & 1;
291 int oval; 434 int val = snd_pmac_burgundy_rcb(chip, addr);
292 435 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0;
293 oval = ~snd_pmac_burgundy_rcb(chip, addr) & 0xff;
294 ucontrol->value.integer.value[0] = oval & 0xf;
295 if (stereo) 436 if (stereo)
296 ucontrol->value.integer.value[1] = (oval >> 4) & 0xf; 437 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
297 return 0; 438 return 0;
298} 439}
299 440
300static int snd_pmac_burgundy_put_volume_out(struct snd_kcontrol *kcontrol, 441static int snd_pmac_burgundy_put_switch_b(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_value *ucontrol) 442 struct snd_ctl_elem_value *ucontrol)
302{ 443{
303 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 444 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
304 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 445 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
446 int lmask = kcontrol->private_value & 0xff;
447 int rmask = (kcontrol->private_value >> 8) & 0xff;
305 int stereo = (kcontrol->private_value >> 24) & 1; 448 int stereo = (kcontrol->private_value >> 24) & 1;
306 unsigned int oval, val; 449 int val, oval;
307 450 oval = snd_pmac_burgundy_rcb(chip, addr);
308 oval = ~snd_pmac_burgundy_rcb(chip, addr) & 0xff; 451 val = oval & ~(lmask | rmask);
309 val = ucontrol->value.integer.value[0] & 15; 452 if (ucontrol->value.integer.value[0])
310 if (stereo) 453 val |= lmask;
311 val |= (ucontrol->value.integer.value[1] & 15) << 4; 454 if (stereo && ucontrol->value.integer.value[1])
312 else 455 val |= rmask;
313 val |= val << 4;
314 val = ~val & 0xff;
315 snd_pmac_burgundy_wcb(chip, addr, val); 456 snd_pmac_burgundy_wcb(chip, addr, val);
316 return val != oval; 457 return val != oval;
317} 458}
318 459
319#define BURGUNDY_OUTPUT_VOLUME(xname, xindex, addr, stereo) \ 460#define BURGUNDY_SWITCH_B(xname, xindex, addr, lmask, rmask, stereo) \
320{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 461{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
321 .info = snd_pmac_burgundy_info_volume_out,\ 462 .info = snd_pmac_burgundy_info_switch_b,\
322 .get = snd_pmac_burgundy_get_volume_out,\ 463 .get = snd_pmac_burgundy_get_switch_b,\
323 .put = snd_pmac_burgundy_put_volume_out,\ 464 .put = snd_pmac_burgundy_put_switch_b,\
324 .private_value = (ADDR2BASE(addr) | ((stereo) << 24)) } 465 .private_value = ((lmask) | ((rmask) << 8)\
466 | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
325 467
468/*
469 * Burgundy mixers
470 */
326static struct snd_kcontrol_new snd_pmac_burgundy_mixers[] __initdata = { 471static struct snd_kcontrol_new snd_pmac_burgundy_mixers[] __initdata = {
327 BURGUNDY_VOLUME("Master Playback Volume", 0, MASK_ADDR_BURGUNDY_MASTER_VOLUME, 8), 472 BURGUNDY_VOLUME_W("Master Playback Volume", 0,
328 BURGUNDY_VOLUME("Line Playback Volume", 0, MASK_ADDR_BURGUNDY_VOLLINE, 16), 473 MASK_ADDR_BURGUNDY_MASTER_VOLUME, 8),
329 BURGUNDY_VOLUME("CD Playback Volume", 0, MASK_ADDR_BURGUNDY_VOLCD, 16), 474 BURGUNDY_VOLUME_W("CD Capture Volume", 0,
330 BURGUNDY_VOLUME("Mic Playback Volume", 0, MASK_ADDR_BURGUNDY_VOLMIC, 16), 475 MASK_ADDR_BURGUNDY_VOLCD, 16),
331 BURGUNDY_OUTPUT_VOLUME("PC Speaker Playback Volume", 0, MASK_ADDR_BURGUNDY_ATTENHP, 0), 476 BURGUNDY_VOLUME_2B("Input Capture Volume", 0,
332 /*BURGUNDY_OUTPUT_VOLUME("PCM Playback Volume", 0, MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1),*/ 477 MASK_ADDR_BURGUNDY_VOLMIX01, 2),
333 BURGUNDY_OUTPUT_VOLUME("Headphone Playback Volume", 0, MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1), 478 BURGUNDY_VOLUME_2B("Mixer Playback Volume", 0,
334}; 479 MASK_ADDR_BURGUNDY_VOLMIX23, 0),
335static struct snd_kcontrol_new snd_pmac_burgundy_master_sw __initdata = 480 BURGUNDY_VOLUME_B("CD Gain Capture Volume", 0,
336BURGUNDY_OUTPUT_SWITCH("Headphone Playback Switch", 0, BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1); 481 MASK_ADDR_BURGUNDY_GAINCD, 1, 0),
337static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw __initdata = 482 BURGUNDY_SWITCH_W("Master Capture Switch", 0,
338BURGUNDY_OUTPUT_SWITCH("PC Speaker Playback Switch", 0, BURGUNDY_OUTPUT_INTERN, 0, 0); 483 MASK_ADDR_BURGUNDY_OUTPUTENABLES, 24, 0, 0),
484 BURGUNDY_SWITCH_W("CD Capture Switch", 0,
485 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 0, 16, 1),
486 BURGUNDY_SWITCH_W("CD Playback Switch", 0,
487 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 0, 16, 1),
488/* BURGUNDY_SWITCH_W("Loop Capture Switch", 0,
489 * MASK_ADDR_BURGUNDY_CAPTURESELECTS, 8, 24, 1),
490 * BURGUNDY_SWITCH_B("Mixer out Capture Switch", 0,
491 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x02, 0, 0),
492 * BURGUNDY_SWITCH_B("Mixer Capture Switch", 0,
493 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x01, 0, 0),
494 * BURGUNDY_SWITCH_B("PCM out Capture Switch", 0,
495 * MASK_ADDR_BURGUNDY_HOSTIFEH, 0x02, 0, 0),
496 */ BURGUNDY_SWITCH_B("PCM Capture Switch", 0,
497 MASK_ADDR_BURGUNDY_HOSTIFEH, 0x01, 0, 0)
498};
499static struct snd_kcontrol_new snd_pmac_burgundy_mixers_imac[] __initdata = {
500 BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
501 MASK_ADDR_BURGUNDY_VOLLINE, 16),
502 BURGUNDY_VOLUME_W("Mic Capture Volume", 0,
503 MASK_ADDR_BURGUNDY_VOLMIC, 16),
504 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
505 MASK_ADDR_BURGUNDY_GAINLINE, 1, 0),
506 BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0,
507 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
508 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0,
509 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
510 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
511 MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1, 1),
512 BURGUNDY_VOLUME_B("Headphone Playback Volume", 0,
513 MASK_ADDR_BURGUNDY_ATTENHP, 1, 1),
514 BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
515 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 1, 17, 1),
516 BURGUNDY_SWITCH_W("Mic Capture Switch", 0,
517 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1),
518 BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
519 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 1, 17, 1),
520 BURGUNDY_SWITCH_W("Mic Playback Switch", 0,
521 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1),
522 BURGUNDY_SWITCH_B("Mic Boost Capture Switch", 0,
523 MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1)
524};
525static struct snd_kcontrol_new snd_pmac_burgundy_mixers_pmac[] __initdata = {
526 BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
527 MASK_ADDR_BURGUNDY_VOLMIC, 16),
528 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
529 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
530 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0,
531 MASK_ADDR_BURGUNDY_ATTENMONO, 0, 1),
532 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
533 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
534 BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
535 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1),
536 BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
537 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1),
538/* BURGUNDY_SWITCH_B("Line in Boost Capture Switch", 0,
539 * MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1) */
540};
541static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_imac __initdata =
542BURGUNDY_SWITCH_B("Master Playback Switch", 0,
543 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
544 BURGUNDY_OUTPUT_LEFT | BURGUNDY_LINEOUT_LEFT | BURGUNDY_HP_LEFT,
545 BURGUNDY_OUTPUT_RIGHT | BURGUNDY_LINEOUT_RIGHT | BURGUNDY_HP_RIGHT, 1);
546static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_pmac __initdata =
547BURGUNDY_SWITCH_B("Master Playback Switch", 0,
548 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
549 BURGUNDY_OUTPUT_INTERN
550 | BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
551static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac __initdata =
552BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0,
553 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
554 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
555static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac __initdata =
556BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0,
557 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
558 BURGUNDY_OUTPUT_INTERN, 0, 0);
559static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac __initdata =
560BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
561 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
562 BURGUNDY_LINEOUT_LEFT, BURGUNDY_LINEOUT_RIGHT, 1);
563static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_pmac __initdata =
564BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
565 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
566 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
567static struct snd_kcontrol_new snd_pmac_burgundy_hp_sw_imac __initdata =
568BURGUNDY_SWITCH_B("Headphone Playback Switch", 0,
569 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
570 BURGUNDY_HP_LEFT, BURGUNDY_HP_RIGHT, 1);
339 571
340 572
341#ifdef PMAC_SUPPORT_AUTOMUTE 573#ifdef PMAC_SUPPORT_AUTOMUTE
@@ -350,16 +582,26 @@ static int snd_pmac_burgundy_detect_headphone(struct snd_pmac *chip)
350static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_notify) 582static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_notify)
351{ 583{
352 if (chip->auto_mute) { 584 if (chip->auto_mute) {
585 int imac = machine_is_compatible("iMac");
353 int reg, oreg; 586 int reg, oreg;
354 reg = oreg = snd_pmac_burgundy_rcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES); 587 reg = oreg = snd_pmac_burgundy_rcb(chip,
355 reg &= ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT | BURGUNDY_OUTPUT_INTERN); 588 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES);
589 reg &= imac ? ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT
590 | BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT)
591 : ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT
592 | BURGUNDY_OUTPUT_INTERN);
356 if (snd_pmac_burgundy_detect_headphone(chip)) 593 if (snd_pmac_burgundy_detect_headphone(chip))
357 reg |= BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT; 594 reg |= imac ? (BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT)
595 : (BURGUNDY_OUTPUT_LEFT
596 | BURGUNDY_OUTPUT_RIGHT);
358 else 597 else
359 reg |= BURGUNDY_OUTPUT_INTERN; 598 reg |= imac ? (BURGUNDY_OUTPUT_LEFT
599 | BURGUNDY_OUTPUT_RIGHT)
600 : (BURGUNDY_OUTPUT_INTERN);
360 if (do_notify && reg == oreg) 601 if (do_notify && reg == oreg)
361 return; 602 return;
362 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, reg); 603 snd_pmac_burgundy_wcb(chip,
604 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, reg);
363 if (do_notify) { 605 if (do_notify) {
364 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 606 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
365 &chip->master_sw_ctl->id); 607 &chip->master_sw_ctl->id);
@@ -378,6 +620,7 @@ static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_noti
378 */ 620 */
379int __init snd_pmac_burgundy_init(struct snd_pmac *chip) 621int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
380{ 622{
623 int imac = machine_is_compatible("iMac");
381 int i, err; 624 int i, err;
382 625
383 /* Checks to see the chip is alive and kicking */ 626 /* Checks to see the chip is alive and kicking */
@@ -386,7 +629,7 @@ int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
386 return 1; 629 return 1;
387 } 630 }
388 631
389 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_OUTPUTENABLES, 632 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_OUTPUTENABLES,
390 DEF_BURGUNDY_OUTPUTENABLES); 633 DEF_BURGUNDY_OUTPUTENABLES);
391 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 634 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
392 DEF_BURGUNDY_MORE_OUTPUTENABLES); 635 DEF_BURGUNDY_MORE_OUTPUTENABLES);
@@ -396,7 +639,8 @@ int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
396 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL21, 639 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL21,
397 DEF_BURGUNDY_INPSEL21); 640 DEF_BURGUNDY_INPSEL21);
398 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL3, 641 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL3,
399 DEF_BURGUNDY_INPSEL3); 642 imac ? DEF_BURGUNDY_INPSEL3_IMAC
643 : DEF_BURGUNDY_INPSEL3_PMAC);
400 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINCD, 644 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINCD,
401 DEF_BURGUNDY_GAINCD); 645 DEF_BURGUNDY_GAINCD);
402 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINLINE, 646 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINLINE,
@@ -422,27 +666,62 @@ int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
422 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLMIC, 666 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLMIC,
423 DEF_BURGUNDY_VOLMIC); 667 DEF_BURGUNDY_VOLMIC);
424 668
425 if (chip->hp_stat_mask == 0) 669 if (chip->hp_stat_mask == 0) {
426 /* set headphone-jack detection bit */ 670 /* set headphone-jack detection bit */
427 chip->hp_stat_mask = 0x04; 671 if (imac)
428 672 chip->hp_stat_mask = BURGUNDY_HPDETECT_IMAC_UPPER
673 | BURGUNDY_HPDETECT_IMAC_LOWER
674 | BURGUNDY_HPDETECT_IMAC_SIDE;
675 else
676 chip->hp_stat_mask = BURGUNDY_HPDETECT_PMAC_BACK;
677 }
429 /* 678 /*
430 * build burgundy mixers 679 * build burgundy mixers
431 */ 680 */
432 strcpy(chip->card->mixername, "PowerMac Burgundy"); 681 strcpy(chip->card->mixername, "PowerMac Burgundy");
433 682
434 for (i = 0; i < ARRAY_SIZE(snd_pmac_burgundy_mixers); i++) { 683 for (i = 0; i < ARRAY_SIZE(snd_pmac_burgundy_mixers); i++) {
435 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_pmac_burgundy_mixers[i], chip))) < 0) 684 err = snd_ctl_add(chip->card,
685 snd_ctl_new1(&snd_pmac_burgundy_mixers[i], chip));
686 if (err < 0)
687 return err;
688 }
689 for (i = 0; i < (imac ? ARRAY_SIZE(snd_pmac_burgundy_mixers_imac)
690 : ARRAY_SIZE(snd_pmac_burgundy_mixers_pmac)); i++) {
691 err = snd_ctl_add(chip->card,
692 snd_ctl_new1(imac ? &snd_pmac_burgundy_mixers_imac[i]
693 : &snd_pmac_burgundy_mixers_pmac[i], chip));
694 if (err < 0)
436 return err; 695 return err;
437 } 696 }
438 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_burgundy_master_sw, chip); 697 chip->master_sw_ctl = snd_ctl_new1(imac
439 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) 698 ? &snd_pmac_burgundy_master_sw_imac
699 : &snd_pmac_burgundy_master_sw_pmac, chip);
700 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
701 if (err < 0)
702 return err;
703 chip->master_sw_ctl = snd_ctl_new1(imac
704 ? &snd_pmac_burgundy_line_sw_imac
705 : &snd_pmac_burgundy_line_sw_pmac, chip);
706 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
707 if (err < 0)
440 return err; 708 return err;
441 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_burgundy_speaker_sw, chip); 709 if (imac) {
442 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) 710 chip->master_sw_ctl = snd_ctl_new1(
711 &snd_pmac_burgundy_hp_sw_imac, chip);
712 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
713 if (err < 0)
714 return err;
715 }
716 chip->speaker_sw_ctl = snd_ctl_new1(imac
717 ? &snd_pmac_burgundy_speaker_sw_imac
718 : &snd_pmac_burgundy_speaker_sw_pmac, chip);
719 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
720 if (err < 0)
443 return err; 721 return err;
444#ifdef PMAC_SUPPORT_AUTOMUTE 722#ifdef PMAC_SUPPORT_AUTOMUTE
445 if ((err = snd_pmac_add_automute(chip)) < 0) 723 err = snd_pmac_add_automute(chip);
724 if (err < 0)
446 return err; 725 return err;
447 726
448 chip->detect_headphone = snd_pmac_burgundy_detect_headphone; 727 chip->detect_headphone = snd_pmac_burgundy_detect_headphone;
diff --git a/sound/ppc/burgundy.h b/sound/ppc/burgundy.h
index ebb457a8342c..7a7f9cf3d299 100644
--- a/sound/ppc/burgundy.h
+++ b/sound/ppc/burgundy.h
@@ -22,6 +22,7 @@
22#ifndef __BURGUNDY_H 22#ifndef __BURGUNDY_H
23#define __BURGUNDY_H 23#define __BURGUNDY_H
24 24
25#define MASK_ADDR_BURGUNDY_INPBOOST (0x10 << 12)
25#define MASK_ADDR_BURGUNDY_INPSEL21 (0x11 << 12) 26#define MASK_ADDR_BURGUNDY_INPSEL21 (0x11 << 12)
26#define MASK_ADDR_BURGUNDY_INPSEL3 (0x12 << 12) 27#define MASK_ADDR_BURGUNDY_INPSEL3 (0x12 << 12)
27 28
@@ -35,7 +36,10 @@
35#define MASK_ADDR_BURGUNDY_VOLCH3 (0x22 << 12) 36#define MASK_ADDR_BURGUNDY_VOLCH3 (0x22 << 12)
36#define MASK_ADDR_BURGUNDY_VOLCH4 (0x23 << 12) 37#define MASK_ADDR_BURGUNDY_VOLCH4 (0x23 << 12)
37 38
39#define MASK_ADDR_BURGUNDY_CAPTURESELECTS (0x2A << 12)
38#define MASK_ADDR_BURGUNDY_OUTPUTSELECTS (0x2B << 12) 40#define MASK_ADDR_BURGUNDY_OUTPUTSELECTS (0x2B << 12)
41#define MASK_ADDR_BURGUNDY_VOLMIX01 (0x2D << 12)
42#define MASK_ADDR_BURGUNDY_VOLMIX23 (0x2E << 12)
39#define MASK_ADDR_BURGUNDY_OUTPUTENABLES (0x2F << 12) 43#define MASK_ADDR_BURGUNDY_OUTPUTENABLES (0x2F << 12)
40 44
41#define MASK_ADDR_BURGUNDY_MASTER_VOLUME (0x30 << 12) 45#define MASK_ADDR_BURGUNDY_MASTER_VOLUME (0x30 << 12)
@@ -45,6 +49,10 @@
45#define MASK_ADDR_BURGUNDY_ATTENSPEAKER (0x62 << 12) 49#define MASK_ADDR_BURGUNDY_ATTENSPEAKER (0x62 << 12)
46#define MASK_ADDR_BURGUNDY_ATTENLINEOUT (0x63 << 12) 50#define MASK_ADDR_BURGUNDY_ATTENLINEOUT (0x63 << 12)
47#define MASK_ADDR_BURGUNDY_ATTENHP (0x64 << 12) 51#define MASK_ADDR_BURGUNDY_ATTENHP (0x64 << 12)
52#define MASK_ADDR_BURGUNDY_ATTENMONO (0x65 << 12)
53
54#define MASK_ADDR_BURGUNDY_HOSTIFAD (0x78 << 12)
55#define MASK_ADDR_BURGUNDY_HOSTIFEH (0x79 << 12)
48 56
49#define MASK_ADDR_BURGUNDY_VOLCD (MASK_ADDR_BURGUNDY_VOLCH1) 57#define MASK_ADDR_BURGUNDY_VOLCD (MASK_ADDR_BURGUNDY_VOLCH1)
50#define MASK_ADDR_BURGUNDY_VOLLINE (MASK_ADDR_BURGUNDY_VOLCH2) 58#define MASK_ADDR_BURGUNDY_VOLLINE (MASK_ADDR_BURGUNDY_VOLCH2)
@@ -59,21 +67,22 @@
59 67
60/* These are all default values for the burgundy */ 68/* These are all default values for the burgundy */
61#define DEF_BURGUNDY_INPSEL21 (0xAA) 69#define DEF_BURGUNDY_INPSEL21 (0xAA)
62#define DEF_BURGUNDY_INPSEL3 (0x0A) 70#define DEF_BURGUNDY_INPSEL3_IMAC (0x0A)
71#define DEF_BURGUNDY_INPSEL3_PMAC (0x05)
63 72
64#define DEF_BURGUNDY_GAINCD (0x33) 73#define DEF_BURGUNDY_GAINCD (0x33)
65#define DEF_BURGUNDY_GAINLINE (0x44) 74#define DEF_BURGUNDY_GAINLINE (0x44)
66#define DEF_BURGUNDY_GAINMIC (0x44) 75#define DEF_BURGUNDY_GAINMIC (0x44)
67#define DEF_BURGUNDY_GAINMODEM (0x06) 76#define DEF_BURGUNDY_GAINMODEM (0x06)
68 77
69/* Remember: lowest volume here is 0x9b */ 78/* Remember: lowest volume here is 0x9B (155) */
70#define DEF_BURGUNDY_VOLCD (0xCCCCCCCC) 79#define DEF_BURGUNDY_VOLCD (0xCCCCCCCC)
71#define DEF_BURGUNDY_VOLLINE (0x00000000) 80#define DEF_BURGUNDY_VOLLINE (0x00000000)
72#define DEF_BURGUNDY_VOLMIC (0x00000000) 81#define DEF_BURGUNDY_VOLMIC (0x00000000)
73#define DEF_BURGUNDY_VOLMODEM (0xCCCCCCCC) 82#define DEF_BURGUNDY_VOLMODEM (0xCCCCCCCC)
74 83
75#define DEF_BURGUNDY_OUTPUTSELECTS (0x010f010f) 84#define DEF_BURGUNDY_OUTPUTSELECTS (0x010F010F)
76#define DEF_BURGUNDY_OUTPUTENABLES (0x0A) 85#define DEF_BURGUNDY_OUTPUTENABLES (0x0100000A)
77 86
78/* #define DEF_BURGUNDY_MASTER_VOLUME (0xFFFFFFFF) */ /* too loud */ 87/* #define DEF_BURGUNDY_MASTER_VOLUME (0xFFFFFFFF) */ /* too loud */
79#define DEF_BURGUNDY_MASTER_VOLUME (0xDDDDDDDD) 88#define DEF_BURGUNDY_MASTER_VOLUME (0xDDDDDDDD)
@@ -84,12 +93,22 @@
84#define DEF_BURGUNDY_ATTENLINEOUT (0xCC) 93#define DEF_BURGUNDY_ATTENLINEOUT (0xCC)
85#define DEF_BURGUNDY_ATTENHP (0xCC) 94#define DEF_BURGUNDY_ATTENHP (0xCC)
86 95
87/* OUTPUTENABLES bits */ 96/* MORE_OUTPUTENABLES bits */
88#define BURGUNDY_OUTPUT_LEFT 0x02 97#define BURGUNDY_OUTPUT_LEFT 0x02
89#define BURGUNDY_OUTPUT_RIGHT 0x04 98#define BURGUNDY_OUTPUT_RIGHT 0x04
99#define BURGUNDY_LINEOUT_LEFT 0x08
100#define BURGUNDY_LINEOUT_RIGHT 0x10
101#define BURGUNDY_HP_LEFT 0x20
102#define BURGUNDY_HP_RIGHT 0x40
90#define BURGUNDY_OUTPUT_INTERN 0x80 103#define BURGUNDY_OUTPUT_INTERN 0x80
91 104
92/* volume offset */ 105/* Headphone detection bits */
106#define BURGUNDY_HPDETECT_PMAC_BACK 0x04
107#define BURGUNDY_HPDETECT_IMAC_SIDE 0x04
108#define BURGUNDY_HPDETECT_IMAC_UPPER 0x08
109#define BURGUNDY_HPDETECT_IMAC_LOWER 0x01
110
111/* Volume offset */
93#define BURGUNDY_VOLUME_OFFSET 155 112#define BURGUNDY_VOLUME_OFFSET 155
94 113
95#endif /* __BURGUNDY_H */ 114#endif /* __BURGUNDY_H */
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 613a565e04de..a38c0c790d2b 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -214,7 +214,7 @@ static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec,
214 int rate_index; 214 int rate_index;
215 long offset; 215 long offset;
216 struct pmac_stream *astr; 216 struct pmac_stream *astr;
217 217
218 rec->dma_size = snd_pcm_lib_buffer_bytes(subs); 218 rec->dma_size = snd_pcm_lib_buffer_bytes(subs);
219 rec->period_size = snd_pcm_lib_period_bytes(subs); 219 rec->period_size = snd_pcm_lib_period_bytes(subs);
220 rec->nperiods = rec->dma_size / rec->period_size; 220 rec->nperiods = rec->dma_size / rec->period_size;
@@ -643,7 +643,7 @@ static int snd_pmac_pcm_close(struct snd_pmac *chip, struct pmac_stream *rec,
643 /* reset constraints */ 643 /* reset constraints */
644 astr->cur_freqs = chip->freqs_ok; 644 astr->cur_freqs = chip->freqs_ok;
645 astr->cur_formats = chip->formats_ok; 645 astr->cur_formats = chip->formats_ok;
646 646
647 return 0; 647 return 0;
648} 648}
649 649
@@ -1300,9 +1300,9 @@ int __init snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return)
1300 1300
1301 snd_pmac_sound_feature(chip, 1); 1301 snd_pmac_sound_feature(chip, 1);
1302 1302
1303 /* reset */ 1303 /* reset & enable interrupts */
1304 if (chip->model == PMAC_AWACS) 1304 if (chip->model <= PMAC_BURGUNDY)
1305 out_le32(&chip->awacs->control, 0x11); 1305 out_le32(&chip->awacs->control, chip->control_mask);
1306 1306
1307 /* Powerbooks have odd ways of enabling inputs such as 1307 /* Powerbooks have odd ways of enabling inputs such as
1308 an expansion-bay CD or sound from an internal modem 1308 an expansion-bay CD or sound from an internal modem
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index 276585215160..a3b51df2bea1 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -29,6 +29,7 @@ source "sound/soc/pxa/Kconfig"
29source "sound/soc/s3c24xx/Kconfig" 29source "sound/soc/s3c24xx/Kconfig"
30source "sound/soc/sh/Kconfig" 30source "sound/soc/sh/Kconfig"
31source "sound/soc/fsl/Kconfig" 31source "sound/soc/fsl/Kconfig"
32source "sound/soc/davinci/Kconfig"
32 33
33# Supported codecs 34# Supported codecs
34source "sound/soc/codecs/Kconfig" 35source "sound/soc/codecs/Kconfig"
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 4869c9ae7a03..e489dbdde458 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -1,4 +1,4 @@
1snd-soc-core-objs := soc-core.o soc-dapm.o 1snd-soc-core-objs := soc-core.o soc-dapm.o
2 2
3obj-$(CONFIG_SND_SOC) += snd-soc-core.o 3obj-$(CONFIG_SND_SOC) += snd-soc-core.o
4obj-$(CONFIG_SND_SOC) += codecs/ at91/ pxa/ s3c24xx/ sh/ fsl/ 4obj-$(CONFIG_SND_SOC) += codecs/ at91/ pxa/ s3c24xx/ sh/ fsl/ davinci/
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 898a7d363284..3903ab7dfa4a 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -18,6 +18,10 @@ config SND_SOC_WM9712
18 tristate 18 tristate
19 depends on SND_SOC 19 depends on SND_SOC
20 20
21config SND_SOC_WM9713
22 tristate
23 depends on SND_SOC
24
21# Cirrus Logic CS4270 Codec 25# Cirrus Logic CS4270 Codec
22config SND_SOC_CS4270 26config SND_SOC_CS4270
23 tristate 27 tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index c6e5338c2666..4e1314c9d3ec 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -3,6 +3,7 @@ snd-soc-wm8731-objs := wm8731.o
3snd-soc-wm8750-objs := wm8750.o 3snd-soc-wm8750-objs := wm8750.o
4snd-soc-wm8753-objs := wm8753.o 4snd-soc-wm8753-objs := wm8753.o
5snd-soc-wm9712-objs := wm9712.o 5snd-soc-wm9712-objs := wm9712.o
6snd-soc-wm9713-objs := wm9713.o
6snd-soc-cs4270-objs := cs4270.o 7snd-soc-cs4270-objs := cs4270.o
7snd-soc-tlv320aic3x-objs := tlv320aic3x.o 8snd-soc-tlv320aic3x-objs := tlv320aic3x.o
8 9
@@ -11,5 +12,6 @@ obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o
11obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o 12obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o
12obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o 13obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o
13obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o 14obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o
15obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o
14obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 16obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
15obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o 17obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
index 242130cf1abd..2a1ffe396908 100644
--- a/sound/soc/codecs/ac97.c
+++ b/sound/soc/codecs/ac97.c
@@ -40,7 +40,8 @@ static int ac97_prepare(struct snd_pcm_substream *substream)
40} 40}
41 41
42#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 42#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
43 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) 43 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
44 SNDRV_PCM_RATE_48000)
44 45
45struct snd_soc_codec_dai ac97_dai = { 46struct snd_soc_codec_dai ac97_dai = {
46 .name = "AC97 HiFi", 47 .name = "AC97 HiFi",
@@ -86,7 +87,7 @@ static int ac97_soc_probe(struct platform_device *pdev)
86 printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION); 87 printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION);
87 88
88 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 89 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
89 if (socdev->codec == NULL) 90 if (!socdev->codec)
90 return -ENOMEM; 91 return -ENOMEM;
91 codec = socdev->codec; 92 codec = socdev->codec;
92 mutex_init(&codec->mutex); 93 mutex_init(&codec->mutex);
@@ -102,17 +103,17 @@ static int ac97_soc_probe(struct platform_device *pdev)
102 103
103 /* register pcms */ 104 /* register pcms */
104 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 105 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
105 if(ret < 0) 106 if (ret < 0)
106 goto err; 107 goto err;
107 108
108 /* add codec as bus device for standard ac97 */ 109 /* add codec as bus device for standard ac97 */
109 ret = snd_ac97_bus(codec->card, 0, &soc_ac97_ops, NULL, &ac97_bus); 110 ret = snd_ac97_bus(codec->card, 0, &soc_ac97_ops, NULL, &ac97_bus);
110 if(ret < 0) 111 if (ret < 0)
111 goto bus_err; 112 goto bus_err;
112 113
113 memset(&ac97_template, 0, sizeof(struct snd_ac97_template)); 114 memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
114 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97); 115 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97);
115 if(ret < 0) 116 if (ret < 0)
116 goto bus_err; 117 goto bus_err;
117 118
118 ret = snd_soc_register_card(socdev); 119 ret = snd_soc_register_card(socdev);
@@ -135,7 +136,7 @@ static int ac97_soc_remove(struct platform_device *pdev)
135 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 136 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
136 struct snd_soc_codec *codec = socdev->codec; 137 struct snd_soc_codec *codec = socdev->codec;
137 138
138 if(codec == NULL) 139 if (!codec)
139 return 0; 140 return 0;
140 141
141 snd_soc_free_pcms(socdev); 142 snd_soc_free_pcms(socdev);
@@ -145,11 +146,10 @@ static int ac97_soc_remove(struct platform_device *pdev)
145 return 0; 146 return 0;
146} 147}
147 148
148struct snd_soc_codec_device soc_codec_dev_ac97= { 149struct snd_soc_codec_device soc_codec_dev_ac97 = {
149 .probe = ac97_soc_probe, 150 .probe = ac97_soc_probe,
150 .remove = ac97_soc_remove, 151 .remove = ac97_soc_remove,
151}; 152};
152
153EXPORT_SYMBOL_GPL(soc_codec_dev_ac97); 153EXPORT_SYMBOL_GPL(soc_codec_dev_ac97);
154 154
155MODULE_DESCRIPTION("Soc Generic AC97 driver"); 155MODULE_DESCRIPTION("Soc Generic AC97 driver");
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index bf2ab72d49bf..e73fcfd9f5cd 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -372,7 +372,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
372 struct snd_soc_device *socdev = rtd->socdev; 372 struct snd_soc_device *socdev = rtd->socdev;
373 struct snd_soc_codec *codec = socdev->codec; 373 struct snd_soc_codec *codec = socdev->codec;
374 struct cs4270_private *cs4270 = codec->private_data; 374 struct cs4270_private *cs4270 = codec->private_data;
375 unsigned int ret = 0; 375 int ret;
376 unsigned int i; 376 unsigned int i;
377 unsigned int rate; 377 unsigned int rate;
378 unsigned int ratio; 378 unsigned int ratio;
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 889a897d41ac..630684f4a0bc 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -660,33 +660,53 @@ struct aic3x_rate_divs {
660/* AIC3X codec mclk clock divider coefficients */ 660/* AIC3X codec mclk clock divider coefficients */
661static const struct aic3x_rate_divs aic3x_divs[] = { 661static const struct aic3x_rate_divs aic3x_divs[] = {
662 /* 8k */ 662 /* 8k */
663 {12000000, 8000, 48000, 0xa, 16, 3840},
664 {19200000, 8000, 48000, 0xa, 10, 2400},
663 {22579200, 8000, 48000, 0xa, 8, 7075}, 665 {22579200, 8000, 48000, 0xa, 8, 7075},
664 {33868800, 8000, 48000, 0xa, 5, 8049}, 666 {33868800, 8000, 48000, 0xa, 5, 8049},
665 /* 11.025k */ 667 /* 11.025k */
668 {12000000, 11025, 44100, 0x6, 15, 528},
669 {19200000, 11025, 44100, 0x6, 9, 4080},
666 {22579200, 11025, 44100, 0x6, 8, 0}, 670 {22579200, 11025, 44100, 0x6, 8, 0},
667 {33868800, 11025, 44100, 0x6, 5, 3333}, 671 {33868800, 11025, 44100, 0x6, 5, 3333},
668 /* 16k */ 672 /* 16k */
673 {12000000, 16000, 48000, 0x4, 16, 3840},
674 {19200000, 16000, 48000, 0x4, 10, 2400},
669 {22579200, 16000, 48000, 0x4, 8, 7075}, 675 {22579200, 16000, 48000, 0x4, 8, 7075},
670 {33868800, 16000, 48000, 0x4, 5, 8049}, 676 {33868800, 16000, 48000, 0x4, 5, 8049},
671 /* 22.05k */ 677 /* 22.05k */
678 {12000000, 22050, 44100, 0x2, 15, 528},
679 {19200000, 22050, 44100, 0x2, 9, 4080},
672 {22579200, 22050, 44100, 0x2, 8, 0}, 680 {22579200, 22050, 44100, 0x2, 8, 0},
673 {33868800, 22050, 44100, 0x2, 5, 3333}, 681 {33868800, 22050, 44100, 0x2, 5, 3333},
674 /* 32k */ 682 /* 32k */
683 {12000000, 32000, 48000, 0x1, 16, 3840},
684 {19200000, 32000, 48000, 0x1, 10, 2400},
675 {22579200, 32000, 48000, 0x1, 8, 7075}, 685 {22579200, 32000, 48000, 0x1, 8, 7075},
676 {33868800, 32000, 48000, 0x1, 5, 8049}, 686 {33868800, 32000, 48000, 0x1, 5, 8049},
677 /* 44.1k */ 687 /* 44.1k */
688 {12000000, 44100, 44100, 0x0, 15, 528},
689 {19200000, 44100, 44100, 0x0, 9, 4080},
678 {22579200, 44100, 44100, 0x0, 8, 0}, 690 {22579200, 44100, 44100, 0x0, 8, 0},
679 {33868800, 44100, 44100, 0x0, 5, 3333}, 691 {33868800, 44100, 44100, 0x0, 5, 3333},
680 /* 48k */ 692 /* 48k */
693 {12000000, 48000, 48000, 0x0, 16, 3840},
694 {19200000, 48000, 48000, 0x0, 10, 2400},
681 {22579200, 48000, 48000, 0x0, 8, 7075}, 695 {22579200, 48000, 48000, 0x0, 8, 7075},
682 {33868800, 48000, 48000, 0x0, 5, 8049}, 696 {33868800, 48000, 48000, 0x0, 5, 8049},
683 /* 64k */ 697 /* 64k */
698 {12000000, 64000, 96000, 0x1, 16, 3840},
699 {19200000, 64000, 96000, 0x1, 10, 2400},
684 {22579200, 64000, 96000, 0x1, 8, 7075}, 700 {22579200, 64000, 96000, 0x1, 8, 7075},
685 {33868800, 64000, 96000, 0x1, 5, 8049}, 701 {33868800, 64000, 96000, 0x1, 5, 8049},
686 /* 88.2k */ 702 /* 88.2k */
703 {12000000, 88200, 88200, 0x0, 15, 528},
704 {19200000, 88200, 88200, 0x0, 9, 4080},
687 {22579200, 88200, 88200, 0x0, 8, 0}, 705 {22579200, 88200, 88200, 0x0, 8, 0},
688 {33868800, 88200, 88200, 0x0, 5, 3333}, 706 {33868800, 88200, 88200, 0x0, 5, 3333},
689 /* 96k */ 707 /* 96k */
708 {12000000, 96000, 96000, 0x0, 16, 3840},
709 {19200000, 96000, 96000, 0x0, 10, 2400},
690 {22579200, 96000, 96000, 0x0, 8, 7075}, 710 {22579200, 96000, 96000, 0x0, 8, 7075},
691 {33868800, 96000, 96000, 0x0, 5, 8049}, 711 {33868800, 96000, 96000, 0x0, 5, 8049},
692}; 712};
@@ -807,6 +827,8 @@ static int aic3x_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
807 struct aic3x_priv *aic3x = codec->private_data; 827 struct aic3x_priv *aic3x = codec->private_data;
808 828
809 switch (freq) { 829 switch (freq) {
830 case 12000000:
831 case 19200000:
810 case 22579200: 832 case 22579200:
811 case 33868800: 833 case 33868800:
812 aic3x->sysclk = freq; 834 aic3x->sysclk = freq;
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index 9c33fe874928..0cf9265fca8f 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -110,7 +110,7 @@ static int wm8731_write(struct snd_soc_codec *codec, unsigned int reg,
110 data[0] = (reg << 1) | ((value >> 8) & 0x0001); 110 data[0] = (reg << 1) | ((value >> 8) & 0x0001);
111 data[1] = value & 0x00ff; 111 data[1] = value & 0x00ff;
112 112
113 wm8731_write_reg_cache (codec, reg, value); 113 wm8731_write_reg_cache(codec, reg, value);
114 if (codec->hw_write(codec->control_data, data, 2) == 2) 114 if (codec->hw_write(codec->control_data, data, 2) == 2)
115 return 0; 115 return 0;
116 else 116 else
@@ -154,8 +154,10 @@ static int wm8731_add_controls(struct snd_soc_codec *codec)
154 int err, i; 154 int err, i;
155 155
156 for (i = 0; i < ARRAY_SIZE(wm8731_snd_controls); i++) { 156 for (i = 0; i < ARRAY_SIZE(wm8731_snd_controls); i++) {
157 if ((err = snd_ctl_add(codec->card, 157 err = snd_ctl_add(codec->card,
158 snd_soc_cnew(&wm8731_snd_controls[i],codec, NULL))) < 0) 158 snd_soc_cnew(&wm8731_snd_controls[i],
159 codec, NULL));
160 if (err < 0)
159 return err; 161 return err;
160 } 162 }
161 163
@@ -221,15 +223,13 @@ static int wm8731_add_widgets(struct snd_soc_codec *codec)
221{ 223{
222 int i; 224 int i;
223 225
224 for(i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) { 226 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
225 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]); 227 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
226 }
227 228
228 /* set up audio path interconnects */ 229 /* set up audio path interconnects */
229 for(i = 0; intercon[i][0] != NULL; i++) { 230 for (i = 0; intercon[i][0] != NULL; i++)
230 snd_soc_dapm_connect_input(codec, intercon[i][0], 231 snd_soc_dapm_connect_input(codec, intercon[i][0],
231 intercon[i][1], intercon[i][2]); 232 intercon[i][1], intercon[i][2]);
232 }
233 233
234 snd_soc_dapm_new_widgets(codec); 234 snd_soc_dapm_new_widgets(codec);
235 return 0; 235 return 0;
@@ -589,7 +589,7 @@ pcm_err:
589 589
590static struct snd_soc_device *wm8731_socdev; 590static struct snd_soc_device *wm8731_socdev;
591 591
592#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 592#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
593 593
594/* 594/*
595 * WM8731 2 wire address is determined by GPIO5 595 * WM8731 2 wire address is determined by GPIO5
@@ -651,7 +651,7 @@ err:
651 651
652static int wm8731_i2c_detach(struct i2c_client *client) 652static int wm8731_i2c_detach(struct i2c_client *client)
653{ 653{
654 struct snd_soc_codec* codec = i2c_get_clientdata(client); 654 struct snd_soc_codec *codec = i2c_get_clientdata(client);
655 i2c_detach_client(client); 655 i2c_detach_client(client);
656 kfree(codec->reg_cache); 656 kfree(codec->reg_cache);
657 kfree(client); 657 kfree(client);
@@ -709,7 +709,7 @@ static int wm8731_probe(struct platform_device *pdev)
709 INIT_LIST_HEAD(&codec->dapm_paths); 709 INIT_LIST_HEAD(&codec->dapm_paths);
710 710
711 wm8731_socdev = socdev; 711 wm8731_socdev = socdev;
712#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 712#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
713 if (setup->i2c_address) { 713 if (setup->i2c_address) {
714 normal_i2c[0] = setup->i2c_address; 714 normal_i2c[0] = setup->i2c_address;
715 codec->hw_write = (hw_write_t)i2c_master_send; 715 codec->hw_write = (hw_write_t)i2c_master_send;
@@ -734,7 +734,7 @@ static int wm8731_remove(struct platform_device *pdev)
734 734
735 snd_soc_free_pcms(socdev); 735 snd_soc_free_pcms(socdev);
736 snd_soc_dapm_free(socdev); 736 snd_soc_dapm_free(socdev);
737#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 737#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
738 i2c_del_driver(&wm8731_i2c_driver); 738 i2c_del_driver(&wm8731_i2c_driver);
739#endif 739#endif
740 kfree(codec->private_data); 740 kfree(codec->private_data);
@@ -749,7 +749,6 @@ struct snd_soc_codec_device soc_codec_dev_wm8731 = {
749 .suspend = wm8731_suspend, 749 .suspend = wm8731_suspend,
750 .resume = wm8731_resume, 750 .resume = wm8731_resume,
751}; 751};
752
753EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); 752EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731);
754 753
755MODULE_DESCRIPTION("ASoC WM8731 driver"); 754MODULE_DESCRIPTION("ASoC WM8731 driver");
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index 77a857b997a2..16cd5d4d5ad9 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -110,7 +110,7 @@ static int wm8750_write(struct snd_soc_codec *codec, unsigned int reg,
110 data[0] = (reg << 1) | ((value >> 8) & 0x0001); 110 data[0] = (reg << 1) | ((value >> 8) & 0x0001);
111 data[1] = value & 0x00ff; 111 data[1] = value & 0x00ff;
112 112
113 wm8750_write_reg_cache (codec, reg, value); 113 wm8750_write_reg_cache(codec, reg, value);
114 if (codec->hw_write(codec->control_data, data, 2) == 2) 114 if (codec->hw_write(codec->control_data, data, 2) == 2)
115 return 0; 115 return 0;
116 else 116 else
@@ -257,7 +257,8 @@ static int wm8750_add_controls(struct snd_soc_codec *codec)
257 257
258 for (i = 0; i < ARRAY_SIZE(wm8750_snd_controls); i++) { 258 for (i = 0; i < ARRAY_SIZE(wm8750_snd_controls); i++) {
259 err = snd_ctl_add(codec->card, 259 err = snd_ctl_add(codec->card,
260 snd_soc_cnew(&wm8750_snd_controls[i],codec, NULL)); 260 snd_soc_cnew(&wm8750_snd_controls[i],
261 codec, NULL));
261 if (err < 0) 262 if (err < 0)
262 return err; 263 return err;
263 } 264 }
@@ -478,15 +479,13 @@ static int wm8750_add_widgets(struct snd_soc_codec *codec)
478{ 479{
479 int i; 480 int i;
480 481
481 for(i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++) { 482 for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++)
482 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]); 483 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
483 }
484 484
485 /* set up audio path audio_mapnects */ 485 /* set up audio path audio_mapnects */
486 for(i = 0; audio_map[i][0] != NULL; i++) { 486 for (i = 0; audio_map[i][0] != NULL; i++)
487 snd_soc_dapm_connect_input(codec, audio_map[i][0], 487 snd_soc_dapm_connect_input(codec, audio_map[i][0],
488 audio_map[i][1], audio_map[i][2]); 488 audio_map[i][1], audio_map[i][2]);
489 }
490 489
491 snd_soc_dapm_new_widgets(codec); 490 snd_soc_dapm_new_widgets(codec);
492 return 0; 491 return 0;
@@ -714,8 +713,8 @@ static int wm8750_dapm_event(struct snd_soc_codec *codec, int event)
714} 713}
715 714
716#define WM8750_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 715#define WM8750_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
717 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 716 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
718 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) 717 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
719 718
720#define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 719#define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
721 SNDRV_PCM_FMTBIT_S24_LE) 720 SNDRV_PCM_FMTBIT_S24_LE)
@@ -784,7 +783,8 @@ static int wm8750_resume(struct platform_device *pdev)
784 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) { 783 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) {
785 wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2); 784 wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2);
786 codec->dapm_state = SNDRV_CTL_POWER_D0; 785 codec->dapm_state = SNDRV_CTL_POWER_D0;
787 schedule_delayed_work(&codec->delayed_work, msecs_to_jiffies(1000)); 786 schedule_delayed_work(&codec->delayed_work,
787 msecs_to_jiffies(1000));
788 } 788 }
789 789
790 return 0; 790 return 0;
@@ -864,7 +864,7 @@ pcm_err:
864 around */ 864 around */
865static struct snd_soc_device *wm8750_socdev; 865static struct snd_soc_device *wm8750_socdev;
866 866
867#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 867#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
868 868
869/* 869/*
870 * WM8731 2 wire address is determined by GPIO5 870 * WM8731 2 wire address is determined by GPIO5
@@ -979,8 +979,8 @@ static int wm8750_probe(struct platform_device *pdev)
979 INIT_LIST_HEAD(&codec->dapm_paths); 979 INIT_LIST_HEAD(&codec->dapm_paths);
980 wm8750_socdev = socdev; 980 wm8750_socdev = socdev;
981 INIT_DELAYED_WORK(&codec->delayed_work, wm8750_work); 981 INIT_DELAYED_WORK(&codec->delayed_work, wm8750_work);
982 982
983#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 983#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
984 if (setup->i2c_address) { 984 if (setup->i2c_address) {
985 normal_i2c[0] = setup->i2c_address; 985 normal_i2c[0] = setup->i2c_address;
986 codec->hw_write = (hw_write_t)i2c_master_send; 986 codec->hw_write = (hw_write_t)i2c_master_send;
@@ -1025,7 +1025,7 @@ static int wm8750_remove(struct platform_device *pdev)
1025 run_delayed_work(&codec->delayed_work); 1025 run_delayed_work(&codec->delayed_work);
1026 snd_soc_free_pcms(socdev); 1026 snd_soc_free_pcms(socdev);
1027 snd_soc_dapm_free(socdev); 1027 snd_soc_dapm_free(socdev);
1028#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 1028#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1029 i2c_del_driver(&wm8750_i2c_driver); 1029 i2c_del_driver(&wm8750_i2c_driver);
1030#endif 1030#endif
1031 kfree(codec->private_data); 1031 kfree(codec->private_data);
@@ -1040,7 +1040,6 @@ struct snd_soc_codec_device soc_codec_dev_wm8750 = {
1040 .suspend = wm8750_suspend, 1040 .suspend = wm8750_suspend,
1041 .resume = wm8750_resume, 1041 .resume = wm8750_resume,
1042}; 1042};
1043
1044EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750); 1043EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750);
1045 1044
1046MODULE_DESCRIPTION("ASoC WM8750 driver"); 1045MODULE_DESCRIPTION("ASoC WM8750 driver");
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index ddd9c71b3fde..76a5c7b05dfb 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -198,6 +198,7 @@ static const char *wm8753_mic_sel[] = {"Mic 1", "Mic 2", "Mic 3"};
198static const char *wm8753_dai_mode[] = {"DAI 0", "DAI 1", "DAI 2", "DAI 3"}; 198static const char *wm8753_dai_mode[] = {"DAI 0", "DAI 1", "DAI 2", "DAI 3"};
199static const char *wm8753_dat_sel[] = {"Stereo", "Left ADC", "Right ADC", 199static const char *wm8753_dat_sel[] = {"Stereo", "Left ADC", "Right ADC",
200 "Channel Swap"}; 200 "Channel Swap"};
201static const char *wm8753_rout2_phase[] = {"Non Inverted", "Inverted"};
201 202
202static const struct soc_enum wm8753_enum[] = { 203static const struct soc_enum wm8753_enum[] = {
203SOC_ENUM_SINGLE(WM8753_BASS, 7, 2, wm8753_base), 204SOC_ENUM_SINGLE(WM8753_BASS, 7, 2, wm8753_base),
@@ -228,6 +229,7 @@ SOC_ENUM_SINGLE(WM8753_ADC, 4, 2, wm8753_adc_filter),
228SOC_ENUM_SINGLE(WM8753_MICBIAS, 6, 3, wm8753_mic_sel), 229SOC_ENUM_SINGLE(WM8753_MICBIAS, 6, 3, wm8753_mic_sel),
229SOC_ENUM_SINGLE(WM8753_IOCTL, 2, 4, wm8753_dai_mode), 230SOC_ENUM_SINGLE(WM8753_IOCTL, 2, 4, wm8753_dai_mode),
230SOC_ENUM_SINGLE(WM8753_ADC, 7, 4, wm8753_dat_sel), 231SOC_ENUM_SINGLE(WM8753_ADC, 7, 4, wm8753_dat_sel),
232SOC_ENUM_SINGLE(WM8753_OUTCTL, 2, 2, wm8753_rout2_phase),
231}; 233};
232 234
233 235
@@ -279,7 +281,7 @@ SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8753_LOUT2V, WM8753_ROUT2V, 7, 1, 0
279 281
280SOC_SINGLE("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1), 282SOC_SINGLE("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1),
281SOC_SINGLE("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1), 283SOC_SINGLE("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1),
282SOC_SINGLE("Mono Voice Playback Volume", WM8753_MOUTM2, 4, 7, 1), 284SOC_SINGLE("Mono Voice Playback Volume", WM8753_MOUTM2, 0, 7, 1),
283SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV, 7, 1, 0), 285SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV, 7, 1, 0),
284 286
285SOC_ENUM("Bass Boost", wm8753_enum[0]), 287SOC_ENUM("Bass Boost", wm8753_enum[0]),
@@ -330,6 +332,7 @@ SOC_SINGLE("Mic1 Capture Volume", WM8753_INCTL1, 5, 3, 0),
330SOC_ENUM_EXT("DAI Mode", wm8753_enum[26], wm8753_get_dai, wm8753_set_dai), 332SOC_ENUM_EXT("DAI Mode", wm8753_enum[26], wm8753_get_dai, wm8753_set_dai),
331 333
332SOC_ENUM("ADC Data Select", wm8753_enum[27]), 334SOC_ENUM("ADC Data Select", wm8753_enum[27]),
335SOC_ENUM("ROUT2 Phase", wm8753_enum[28]),
333}; 336};
334 337
335/* add non dapm controls */ 338/* add non dapm controls */
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index 524f7450804f..d2d79e182a45 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -581,22 +581,14 @@ static int wm9712_dapm_event(struct snd_soc_codec *codec, int event)
581 581
582 switch (event) { 582 switch (event) {
583 case SNDRV_CTL_POWER_D0: /* full On */ 583 case SNDRV_CTL_POWER_D0: /* full On */
584 /* liam - maybe enable thermal shutdown */
585 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xdfff;
586 ac97_write(codec, AC97_EXTENDED_MID, reg);
587 break;
588 case SNDRV_CTL_POWER_D1: /* partial On */ 584 case SNDRV_CTL_POWER_D1: /* partial On */
589 case SNDRV_CTL_POWER_D2: /* partial On */ 585 case SNDRV_CTL_POWER_D2: /* partial On */
590 break; 586 break;
591 case SNDRV_CTL_POWER_D3hot: /* Off, with power */ 587 case SNDRV_CTL_POWER_D3hot: /* Off, with power */
592 /* enable master bias and vmid */
593 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xbbff;
594 ac97_write(codec, AC97_EXTENDED_MID, reg);
595 ac97_write(codec, AC97_POWERDOWN, 0x0000); 588 ac97_write(codec, AC97_POWERDOWN, 0x0000);
596 break; 589 break;
597 case SNDRV_CTL_POWER_D3cold: /* Off, without power */ 590 case SNDRV_CTL_POWER_D3cold: /* Off, without power */
598 /* disable everything including AC link */ 591 /* disable everything including AC link */
599 ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
600 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); 592 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
601 ac97_write(codec, AC97_POWERDOWN, 0xffff); 593 ac97_write(codec, AC97_POWERDOWN, 0xffff);
602 break; 594 break;
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
new file mode 100644
index 000000000000..1f241161445c
--- /dev/null
+++ b/sound/soc/codecs/wm9713.c
@@ -0,0 +1,1300 @@
1/*
2 * wm9713.c -- ALSA Soc WM9713 codec support
3 *
4 * Copyright 2006 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * Revision history
14 * 4th Feb 2006 Initial version.
15 *
16 * Features:-
17 *
18 * o Support for AC97 Codec, Voice DAC and Aux DAC
19 * o Support for DAPM
20 */
21
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/device.h>
25#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/ac97_codec.h>
28#include <sound/initval.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
32
33#include "wm9713.h"
34
35#define WM9713_VERSION "0.15"
36
37struct wm9713_priv {
38 u32 pll_in; /* PLL input frequency */
39 u32 pll_out; /* PLL output frequency */
40};
41
42static unsigned int ac97_read(struct snd_soc_codec *codec,
43 unsigned int reg);
44static int ac97_write(struct snd_soc_codec *codec,
45 unsigned int reg, unsigned int val);
46
47/*
48 * WM9713 register cache
49 * Reg 0x3c bit 15 is used by touch driver.
50 */
51static const u16 wm9713_reg[] = {
52 0x6174, 0x8080, 0x8080, 0x8080,
53 0xc880, 0xe808, 0xe808, 0x0808,
54 0x00da, 0x8000, 0xd600, 0xaaa0,
55 0xaaa0, 0xaaa0, 0x0000, 0x0000,
56 0x0f0f, 0x0040, 0x0000, 0x7f00,
57 0x0405, 0x0410, 0xbb80, 0xbb80,
58 0x0000, 0xbb80, 0x0000, 0x4523,
59 0x0000, 0x2000, 0x7eff, 0xffff,
60 0x0000, 0x0000, 0x0080, 0x0000,
61 0x0000, 0x0000, 0xfffe, 0xffff,
62 0x0000, 0x0000, 0x0000, 0xfffe,
63 0x4000, 0x0000, 0x0000, 0x0000,
64 0xb032, 0x3e00, 0x0000, 0x0000,
65 0x0000, 0x0000, 0x0000, 0x0000,
66 0x0000, 0x0000, 0x0000, 0x0006,
67 0x0001, 0x0000, 0x574d, 0x4c13,
68 0x0000, 0x0000, 0x0000
69};
70
71/* virtual HP mixers regs */
72#define HPL_MIXER 0x80
73#define HPR_MIXER 0x82
74#define MICB_MUX 0x82
75
76static const char *wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
77static const char *wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
78static const char *wm9713_rec_src[] =
79 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker",
80 "Mono Out", "Zh"};
81static const char *wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
82static const char *wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
83static const char *wm9713_mono_pga[] = {"Vmid", "Zh", "Mono", "Inv",
84 "Mono Vmid", "Inv Vmid"};
85static const char *wm9713_spk_pga[] =
86 {"Vmid", "Zh", "Headphone", "Speaker", "Inv", "Headphone Vmid",
87 "Speaker Vmid", "Inv Vmid"};
88static const char *wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone",
89 "Headphone Vmid"};
90static const char *wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "Inv 1 Vmid"};
91static const char *wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "Inv 2 Vmid"};
92static const char *wm9713_dac_inv[] =
93 {"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone",
94 "Headphone Mono", "NC", "Vmid"};
95static const char *wm9713_bass[] = {"Linear Control", "Adaptive Boost"};
96static const char *wm9713_ng_type[] = {"Constant Gain", "Mute"};
97static const char *wm9713_mic_select[] = {"Mic 1", "Mic 2 A", "Mic 2 B"};
98static const char *wm9713_micb_select[] = {"MPB", "MPA"};
99
100static const struct soc_enum wm9713_enum[] = {
101SOC_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), /* record mic mixer 0 */
102SOC_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), /* record mux hp 1 */
103SOC_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), /* record mux mono 2 */
104SOC_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src), /* record mux left 3 */
105SOC_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src), /* record mux right 4*/
106SOC_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), /* record step size 5 */
107SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), /* alc source select 6*/
108SOC_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), /* mono input select 7 */
109SOC_ENUM_SINGLE(AC97_REC_GAIN, 11, 8, wm9713_spk_pga), /* speaker left input select 8 */
110SOC_ENUM_SINGLE(AC97_REC_GAIN, 8, 8, wm9713_spk_pga), /* speaker right input select 9 */
111SOC_ENUM_SINGLE(AC97_REC_GAIN, 6, 3, wm9713_hp_pga), /* headphone left input 10 */
112SOC_ENUM_SINGLE(AC97_REC_GAIN, 4, 3, wm9713_hp_pga), /* headphone right input 11 */
113SOC_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), /* out 3 source 12 */
114SOC_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), /* out 4 source 13 */
115SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 13, 8, wm9713_dac_inv), /* dac invert 1 14 */
116SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 10, 8, wm9713_dac_inv), /* dac invert 2 15 */
117SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */
118SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */
119SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */
120SOC_ENUM_SINGLE(MICB_MUX, 0, 2, wm9713_micb_select), /* mic selection 19 */
121};
122
123static const struct snd_kcontrol_new wm9713_snd_ac97_controls[] = {
124SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1),
125SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER, 15, 7, 1, 1),
126SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
127SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 7, 1, 1),
128SOC_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
129SOC_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
130SOC_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
131SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
132
133SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
134SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
135
136SOC_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
137SOC_ENUM("Capture Volume Steps", wm9713_enum[5]),
138SOC_DOUBLE("Capture Volume", AC97_CD, 8, 0, 31, 0),
139SOC_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
140
141SOC_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
142SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
143SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
144
145SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
146SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
147SOC_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
148SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
149SOC_ENUM("ALC Function", wm9713_enum[6]),
150SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
151SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
152SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
153SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
154SOC_ENUM("ALC NG Type", wm9713_enum[17]),
155SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
156
157SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER, 14, 6, 1, 0),
158SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
159
160SOC_SINGLE("Out4 Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
161SOC_SINGLE("Out4 Playback ZC Switch", AC97_MASTER_MONO, 14, 1, 0),
162SOC_SINGLE("Out4 Playback Volume", AC97_MASTER_MONO, 8, 63, 1),
163
164SOC_SINGLE("Out3 Playback Switch", AC97_MASTER_MONO, 7, 1, 1),
165SOC_SINGLE("Out3 Playback ZC Switch", AC97_MASTER_MONO, 6, 1, 0),
166SOC_SINGLE("Out3 Playback Volume", AC97_MASTER_MONO, 0, 63, 1),
167
168SOC_SINGLE("Mono Capture Volume", AC97_MASTER_TONE, 8, 31, 1),
169SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1),
170SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
171SOC_SINGLE("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1),
172
173SOC_SINGLE("PC Beep Playback Headphone Volume", AC97_AUX, 12, 7, 1),
174SOC_SINGLE("PC Beep Playback Speaker Volume", AC97_AUX, 8, 7, 1),
175SOC_SINGLE("PC Beep Playback Mono Volume", AC97_AUX, 4, 7, 1),
176
177SOC_SINGLE("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1),
178SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1),
179SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM, 4, 7, 1),
180
181SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL, 12, 7, 1),
182SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL, 8, 7, 1),
183SOC_SINGLE("Aux Playback Mono Volume", AC97_REC_SEL, 4, 7, 1),
184
185SOC_ENUM("Bass Control", wm9713_enum[16]),
186SOC_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
187SOC_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
188SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
189SOC_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
190SOC_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
191
192SOC_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
193SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
194SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
195};
196
197/* add non dapm controls */
198static int wm9713_add_controls(struct snd_soc_codec *codec)
199{
200 int err, i;
201
202 for (i = 0; i < ARRAY_SIZE(wm9713_snd_ac97_controls); i++) {
203 err = snd_ctl_add(codec->card,
204 snd_soc_cnew(&wm9713_snd_ac97_controls[i],
205 codec, NULL));
206 if (err < 0)
207 return err;
208 }
209 return 0;
210}
211
212/* We have to create a fake left and right HP mixers because
213 * the codec only has a single control that is shared by both channels.
214 * This makes it impossible to determine the audio path using the current
215 * register map, thus we add a new (virtual) register to help determine the
216 * audio route within the device.
217 */
218static int mixer_event(struct snd_soc_dapm_widget *w,
219 struct snd_kcontrol *kcontrol, int event)
220{
221 u16 l, r, beep, tone, phone, rec, pcm, aux;
222
223 l = ac97_read(w->codec, HPL_MIXER);
224 r = ac97_read(w->codec, HPR_MIXER);
225 beep = ac97_read(w->codec, AC97_PC_BEEP);
226 tone = ac97_read(w->codec, AC97_MASTER_TONE);
227 phone = ac97_read(w->codec, AC97_PHONE);
228 rec = ac97_read(w->codec, AC97_REC_SEL);
229 pcm = ac97_read(w->codec, AC97_PCM);
230 aux = ac97_read(w->codec, AC97_AUX);
231
232 if (event & SND_SOC_DAPM_PRE_REG)
233 return 0;
234 if ((l & 0x1) || (r & 0x1))
235 ac97_write(w->codec, AC97_PC_BEEP, beep & 0x7fff);
236 else
237 ac97_write(w->codec, AC97_PC_BEEP, beep | 0x8000);
238
239 if ((l & 0x2) || (r & 0x2))
240 ac97_write(w->codec, AC97_MASTER_TONE, tone & 0x7fff);
241 else
242 ac97_write(w->codec, AC97_MASTER_TONE, tone | 0x8000);
243
244 if ((l & 0x4) || (r & 0x4))
245 ac97_write(w->codec, AC97_PHONE, phone & 0x7fff);
246 else
247 ac97_write(w->codec, AC97_PHONE, phone | 0x8000);
248
249 if ((l & 0x8) || (r & 0x8))
250 ac97_write(w->codec, AC97_REC_SEL, rec & 0x7fff);
251 else
252 ac97_write(w->codec, AC97_REC_SEL, rec | 0x8000);
253
254 if ((l & 0x10) || (r & 0x10))
255 ac97_write(w->codec, AC97_PCM, pcm & 0x7fff);
256 else
257 ac97_write(w->codec, AC97_PCM, pcm | 0x8000);
258
259 if ((l & 0x20) || (r & 0x20))
260 ac97_write(w->codec, AC97_AUX, aux & 0x7fff);
261 else
262 ac97_write(w->codec, AC97_AUX, aux | 0x8000);
263
264 return 0;
265}
266
267/* Left Headphone Mixers */
268static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = {
269SOC_DAPM_SINGLE("PC Beep Playback Switch", HPL_MIXER, 5, 1, 0),
270SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER, 4, 1, 0),
271SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 3, 1, 0),
272SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 2, 1, 0),
273SOC_DAPM_SINGLE("MonoIn Playback Switch", HPL_MIXER, 1, 1, 0),
274SOC_DAPM_SINGLE("Bypass Playback Switch", HPL_MIXER, 0, 1, 0),
275};
276
277/* Right Headphone Mixers */
278static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = {
279SOC_DAPM_SINGLE("PC Beep Playback Switch", HPR_MIXER, 5, 1, 0),
280SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER, 4, 1, 0),
281SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 3, 1, 0),
282SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 2, 1, 0),
283SOC_DAPM_SINGLE("MonoIn Playback Switch", HPR_MIXER, 1, 1, 0),
284SOC_DAPM_SINGLE("Bypass Playback Switch", HPR_MIXER, 0, 1, 0),
285};
286
287/* headphone capture mux */
288static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls =
289SOC_DAPM_ENUM("Route", wm9713_enum[1]);
290
291/* headphone mic mux */
292static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls =
293SOC_DAPM_ENUM("Route", wm9713_enum[0]);
294
295/* Speaker Mixer */
296static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = {
297SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 11, 1, 1),
298SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1),
299SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1),
300SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1),
301SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 14, 1, 1),
302SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1),
303};
304
305/* Mono Mixer */
306static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = {
307SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 7, 1, 1),
308SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1),
309SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1),
310SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1),
311SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 13, 1, 1),
312SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 13, 1, 1),
313SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE, 7, 1, 1),
314SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE, 6, 1, 1),
315};
316
317/* mono mic mux */
318static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls =
319SOC_DAPM_ENUM("Route", wm9713_enum[2]);
320
321/* mono output mux */
322static const struct snd_kcontrol_new wm9713_mono_mux_controls =
323SOC_DAPM_ENUM("Route", wm9713_enum[7]);
324
325/* speaker left output mux */
326static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls =
327SOC_DAPM_ENUM("Route", wm9713_enum[8]);
328
329/* speaker right output mux */
330static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls =
331SOC_DAPM_ENUM("Route", wm9713_enum[9]);
332
333/* headphone left output mux */
334static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls =
335SOC_DAPM_ENUM("Route", wm9713_enum[10]);
336
337/* headphone right output mux */
338static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls =
339SOC_DAPM_ENUM("Route", wm9713_enum[11]);
340
341/* Out3 mux */
342static const struct snd_kcontrol_new wm9713_out3_mux_controls =
343SOC_DAPM_ENUM("Route", wm9713_enum[12]);
344
345/* Out4 mux */
346static const struct snd_kcontrol_new wm9713_out4_mux_controls =
347SOC_DAPM_ENUM("Route", wm9713_enum[13]);
348
349/* DAC inv mux 1 */
350static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls =
351SOC_DAPM_ENUM("Route", wm9713_enum[14]);
352
353/* DAC inv mux 2 */
354static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls =
355SOC_DAPM_ENUM("Route", wm9713_enum[15]);
356
357/* Capture source left */
358static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls =
359SOC_DAPM_ENUM("Route", wm9713_enum[3]);
360
361/* Capture source right */
362static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls =
363SOC_DAPM_ENUM("Route", wm9713_enum[4]);
364
365/* mic source */
366static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls =
367SOC_DAPM_ENUM("Route", wm9713_enum[18]);
368
369/* mic source B virtual control */
370static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls =
371SOC_DAPM_ENUM("Route", wm9713_enum[19]);
372
373static const struct snd_soc_dapm_widget wm9713_dapm_widgets[] = {
374SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM, 0, 0,
375 &wm9713_hp_rec_mux_controls),
376SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM, 0, 0,
377 &wm9713_hp_mic_mux_controls),
378SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM, 0, 0,
379 &wm9713_mono_mic_mux_controls),
380SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM, 0, 0,
381 &wm9713_mono_mux_controls),
382SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM, 0, 0,
383 &wm9713_hp_spkl_mux_controls),
384SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM, 0, 0,
385 &wm9713_hp_spkr_mux_controls),
386SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM, 0, 0,
387 &wm9713_hpl_out_mux_controls),
388SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM, 0, 0,
389 &wm9713_hpr_out_mux_controls),
390SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM, 0, 0,
391 &wm9713_out3_mux_controls),
392SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM, 0, 0,
393 &wm9713_out4_mux_controls),
394SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM, 0, 0,
395 &wm9713_dac_inv1_mux_controls),
396SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM, 0, 0,
397 &wm9713_dac_inv2_mux_controls),
398SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0,
399 &wm9713_rec_srcl_mux_controls),
400SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0,
401 &wm9713_rec_srcr_mux_controls),
402SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM, 0, 0,
403 &wm9713_mic_sel_mux_controls),
404SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0,
405 &wm9713_micb_sel_mux_controls),
406SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_EXTENDED_MID, 3, 1,
407 &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls),
408 mixer_event, SND_SOC_DAPM_POST_REG),
409SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_EXTENDED_MID, 2, 1,
410 &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls),
411 mixer_event, SND_SOC_DAPM_POST_REG),
412SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1,
413 &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)),
414SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1,
415 &wm9713_speaker_mixer_controls[0],
416 ARRAY_SIZE(wm9713_speaker_mixer_controls)),
417SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID, 7, 1),
418SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID, 6, 1),
419SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
420SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
421SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
422SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
423SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1),
424SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1),
425SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", AC97_EXTENDED_MID, 5, 1),
426SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", AC97_EXTENDED_MID, 4, 1),
427SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS, 10, 1, NULL, 0),
428SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS, 9, 1, NULL, 0),
429SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS, 8, 1, NULL, 0),
430SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS, 7, 1, NULL, 0),
431SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS, 11, 1, NULL, 0),
432SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS, 12, 1, NULL, 0),
433SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS, 13, 1, NULL, 0),
434SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS, 6, 1, NULL, 0),
435SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS, 5, 1, NULL, 0),
436SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS, 4, 1, NULL, 0),
437SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS, 3, 1, NULL, 0),
438SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS, 2, 1, NULL, 0),
439SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS, 1, 1, NULL, 0),
440SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS, 0, 1, NULL, 0),
441SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS, 14, 1),
442SND_SOC_DAPM_OUTPUT("MONO"),
443SND_SOC_DAPM_OUTPUT("HPL"),
444SND_SOC_DAPM_OUTPUT("HPR"),
445SND_SOC_DAPM_OUTPUT("SPKL"),
446SND_SOC_DAPM_OUTPUT("SPKR"),
447SND_SOC_DAPM_OUTPUT("OUT3"),
448SND_SOC_DAPM_OUTPUT("OUT4"),
449SND_SOC_DAPM_INPUT("LINEL"),
450SND_SOC_DAPM_INPUT("LINER"),
451SND_SOC_DAPM_INPUT("MONOIN"),
452SND_SOC_DAPM_INPUT("PCBEEP"),
453SND_SOC_DAPM_INPUT("MIC1"),
454SND_SOC_DAPM_INPUT("MIC2A"),
455SND_SOC_DAPM_INPUT("MIC2B"),
456SND_SOC_DAPM_VMID("VMID"),
457};
458
459static const char *audio_map[][3] = {
460 /* left HP mixer */
461 {"Left HP Mixer", "PC Beep Playback Switch", "PCBEEP"},
462 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"},
463 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
464 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"},
465 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"},
466 {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"},
467 {"Left HP Mixer", NULL, "Capture Headphone Mux"},
468
469 /* right HP mixer */
470 {"Right HP Mixer", "PC Beep Playback Switch", "PCBEEP"},
471 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"},
472 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
473 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"},
474 {"Right HP Mixer", "PCM Playback Switch", "Right DAC"},
475 {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"},
476 {"Right HP Mixer", NULL, "Capture Headphone Mux"},
477
478 /* virtual mixer - mixes left & right channels for spk and mono */
479 {"AC97 Mixer", NULL, "Left DAC"},
480 {"AC97 Mixer", NULL, "Right DAC"},
481 {"Line Mixer", NULL, "Right Line In"},
482 {"Line Mixer", NULL, "Left Line In"},
483 {"HP Mixer", NULL, "Left HP Mixer"},
484 {"HP Mixer", NULL, "Right HP Mixer"},
485 {"Capture Mixer", NULL, "Left Capture Source"},
486 {"Capture Mixer", NULL, "Right Capture Source"},
487
488 /* speaker mixer */
489 {"Speaker Mixer", "PC Beep Playback Switch", "PCBEEP"},
490 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"},
491 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
492 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"},
493 {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"},
494 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"},
495
496 /* mono mixer */
497 {"Mono Mixer", "PC Beep Playback Switch", "PCBEEP"},
498 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
499 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"},
500 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"},
501 {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"},
502 {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"},
503 {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"},
504 {"Mono Mixer", NULL, "Capture Mono Mux"},
505
506 /* DAC inv mux 1 */
507 {"DAC Inv Mux 1", "Mono", "Mono Mixer"},
508 {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"},
509 {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"},
510 {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"},
511 {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"},
512
513 /* DAC inv mux 2 */
514 {"DAC Inv Mux 2", "Mono", "Mono Mixer"},
515 {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"},
516 {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"},
517 {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"},
518 {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"},
519
520 /* headphone left mux */
521 {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"},
522
523 /* headphone right mux */
524 {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"},
525
526 /* speaker left mux */
527 {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"},
528 {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"},
529 {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"},
530
531 /* speaker right mux */
532 {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"},
533 {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"},
534 {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"},
535
536 /* mono mux */
537 {"Mono Out Mux", "Mono", "Mono Mixer"},
538 {"Mono Out Mux", "Inv", "DAC Inv Mux 1"},
539
540 /* out 3 mux */
541 {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"},
542
543 /* out 4 mux */
544 {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"},
545
546 /* output pga */
547 {"HPL", NULL, "Left Headphone"},
548 {"Left Headphone", NULL, "Left Headphone Out Mux"},
549 {"HPR", NULL, "Right Headphone"},
550 {"Right Headphone", NULL, "Right Headphone Out Mux"},
551 {"OUT3", NULL, "Out 3"},
552 {"Out 3", NULL, "Out 3 Mux"},
553 {"OUT4", NULL, "Out 4"},
554 {"Out 4", NULL, "Out 4 Mux"},
555 {"SPKL", NULL, "Left Speaker"},
556 {"Left Speaker", NULL, "Left Speaker Out Mux"},
557 {"SPKR", NULL, "Right Speaker"},
558 {"Right Speaker", NULL, "Right Speaker Out Mux"},
559 {"MONO", NULL, "Mono Out"},
560 {"Mono Out", NULL, "Mono Out Mux"},
561
562 /* input pga */
563 {"Left Line In", NULL, "LINEL"},
564 {"Right Line In", NULL, "LINER"},
565 {"Mono In", NULL, "MONOIN"},
566 {"Mic A PGA", NULL, "Mic A Pre Amp"},
567 {"Mic B PGA", NULL, "Mic B Pre Amp"},
568
569 /* left capture select */
570 {"Left Capture Source", "Mic 1", "Mic A Pre Amp"},
571 {"Left Capture Source", "Mic 2", "Mic B Pre Amp"},
572 {"Left Capture Source", "Line", "LINEL"},
573 {"Left Capture Source", "Mono In", "MONOIN"},
574 {"Left Capture Source", "Headphone", "Left HP Mixer"},
575 {"Left Capture Source", "Speaker", "Speaker Mixer"},
576 {"Left Capture Source", "Mono Out", "Mono Mixer"},
577
578 /* right capture select */
579 {"Right Capture Source", "Mic 1", "Mic A Pre Amp"},
580 {"Right Capture Source", "Mic 2", "Mic B Pre Amp"},
581 {"Right Capture Source", "Line", "LINER"},
582 {"Right Capture Source", "Mono In", "MONOIN"},
583 {"Right Capture Source", "Headphone", "Right HP Mixer"},
584 {"Right Capture Source", "Speaker", "Speaker Mixer"},
585 {"Right Capture Source", "Mono Out", "Mono Mixer"},
586
587 /* left ADC */
588 {"Left ADC", NULL, "Left Capture Source"},
589
590 /* right ADC */
591 {"Right ADC", NULL, "Right Capture Source"},
592
593 /* mic */
594 {"Mic A Pre Amp", NULL, "Mic A Source"},
595 {"Mic A Source", "Mic 1", "MIC1"},
596 {"Mic A Source", "Mic 2 A", "MIC2A"},
597 {"Mic A Source", "Mic 2 B", "Mic B Source"},
598 {"Mic B Pre Amp", "MPB", "Mic B Source"},
599 {"Mic B Source", NULL, "MIC2B"},
600
601 /* headphone capture */
602 {"Capture Headphone Mux", "Stereo", "Capture Mixer"},
603 {"Capture Headphone Mux", "Left", "Left Capture Source"},
604 {"Capture Headphone Mux", "Right", "Right Capture Source"},
605
606 /* mono capture */
607 {"Capture Mono Mux", "Stereo", "Capture Mixer"},
608 {"Capture Mono Mux", "Left", "Left Capture Source"},
609 {"Capture Mono Mux", "Right", "Right Capture Source"},
610
611 {NULL, NULL, NULL},
612};
613
614static int wm9713_add_widgets(struct snd_soc_codec *codec)
615{
616 int i;
617
618 for (i = 0; i < ARRAY_SIZE(wm9713_dapm_widgets); i++)
619 snd_soc_dapm_new_control(codec, &wm9713_dapm_widgets[i]);
620
621 /* set up audio path audio_mapnects */
622 for (i = 0; audio_map[i][0] != NULL; i++)
623 snd_soc_dapm_connect_input(codec, audio_map[i][0],
624 audio_map[i][1], audio_map[i][2]);
625
626 snd_soc_dapm_new_widgets(codec);
627 return 0;
628}
629
630static unsigned int ac97_read(struct snd_soc_codec *codec,
631 unsigned int reg)
632{
633 u16 *cache = codec->reg_cache;
634
635 if (reg == AC97_RESET || reg == AC97_GPIO_STATUS ||
636 reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 ||
637 reg == AC97_CD)
638 return soc_ac97_ops.read(codec->ac97, reg);
639 else {
640 reg = reg >> 1;
641
642 if (reg > (ARRAY_SIZE(wm9713_reg)))
643 return -EIO;
644
645 return cache[reg];
646 }
647}
648
649static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
650 unsigned int val)
651{
652 u16 *cache = codec->reg_cache;
653 if (reg < 0x7c)
654 soc_ac97_ops.write(codec->ac97, reg, val);
655 reg = reg >> 1;
656 if (reg <= (ARRAY_SIZE(wm9713_reg)))
657 cache[reg] = val;
658
659 return 0;
660}
661
662/* PLL divisors */
663struct _pll_div {
664 u32 divsel:1;
665 u32 divctl:1;
666 u32 lf:1;
667 u32 n:4;
668 u32 k:24;
669};
670
671/* The size in bits of the PLL divide multiplied by 10
672 * to allow rounding later */
673#define FIXED_PLL_SIZE ((1 << 22) * 10)
674
675static void pll_factors(struct _pll_div *pll_div, unsigned int source)
676{
677 u64 Kpart;
678 unsigned int K, Ndiv, Nmod, target;
679
680 /* The the PLL output is always 98.304MHz. */
681 target = 98304000;
682
683 /* If the input frequency is over 14.4MHz then scale it down. */
684 if (source > 14400000) {
685 source >>= 1;
686 pll_div->divsel = 1;
687
688 if (source > 14400000) {
689 source >>= 1;
690 pll_div->divctl = 1;
691 } else
692 pll_div->divctl = 0;
693
694 } else {
695 pll_div->divsel = 0;
696 pll_div->divctl = 0;
697 }
698
699 /* Low frequency sources require an additional divide in the
700 * loop.
701 */
702 if (source < 8192000) {
703 pll_div->lf = 1;
704 target >>= 2;
705 } else
706 pll_div->lf = 0;
707
708 Ndiv = target / source;
709 if ((Ndiv < 5) || (Ndiv > 12))
710 printk(KERN_WARNING
711 "WM9713 PLL N value %d out of recommended range!\n",
712 Ndiv);
713
714 pll_div->n = Ndiv;
715 Nmod = target % source;
716 Kpart = FIXED_PLL_SIZE * (long long)Nmod;
717
718 do_div(Kpart, source);
719
720 K = Kpart & 0xFFFFFFFF;
721
722 /* Check if we need to round */
723 if ((K % 10) >= 5)
724 K += 5;
725
726 /* Move down to proper range now rounding is done */
727 K /= 10;
728
729 pll_div->k = K;
730}
731
732/**
733 * Please note that changing the PLL input frequency may require
734 * resynchronisation with the AC97 controller.
735 */
736static int wm9713_set_pll(struct snd_soc_codec *codec,
737 int pll_id, unsigned int freq_in, unsigned int freq_out)
738{
739 struct wm9713_priv *wm9713 = codec->private_data;
740 u16 reg, reg2;
741 struct _pll_div pll_div;
742
743 /* turn PLL off ? */
744 if (freq_in == 0 || freq_out == 0) {
745 /* disable PLL power and select ext source */
746 reg = ac97_read(codec, AC97_HANDSET_RATE);
747 ac97_write(codec, AC97_HANDSET_RATE, reg | 0x0080);
748 reg = ac97_read(codec, AC97_EXTENDED_MID);
749 ac97_write(codec, AC97_EXTENDED_MID, reg | 0x0200);
750 wm9713->pll_out = 0;
751 return 0;
752 }
753
754 pll_factors(&pll_div, freq_in);
755
756 if (pll_div.k == 0) {
757 reg = (pll_div.n << 12) | (pll_div.lf << 11) |
758 (pll_div.divsel << 9) | (pll_div.divctl << 8);
759 ac97_write(codec, AC97_LINE1_LEVEL, reg);
760 } else {
761 /* write the fractional k to the reg 0x46 pages */
762 reg2 = (pll_div.n << 12) | (pll_div.lf << 11) | (1 << 10) |
763 (pll_div.divsel << 9) | (pll_div.divctl << 8);
764
765 /* K [21:20] */
766 reg = reg2 | (0x5 << 4) | (pll_div.k >> 20);
767 ac97_write(codec, AC97_LINE1_LEVEL, reg);
768
769 /* K [19:16] */
770 reg = reg2 | (0x4 << 4) | ((pll_div.k >> 16) & 0xf);
771 ac97_write(codec, AC97_LINE1_LEVEL, reg);
772
773 /* K [15:12] */
774 reg = reg2 | (0x3 << 4) | ((pll_div.k >> 12) & 0xf);
775 ac97_write(codec, AC97_LINE1_LEVEL, reg);
776
777 /* K [11:8] */
778 reg = reg2 | (0x2 << 4) | ((pll_div.k >> 8) & 0xf);
779 ac97_write(codec, AC97_LINE1_LEVEL, reg);
780
781 /* K [7:4] */
782 reg = reg2 | (0x1 << 4) | ((pll_div.k >> 4) & 0xf);
783 ac97_write(codec, AC97_LINE1_LEVEL, reg);
784
785 reg = reg2 | (0x0 << 4) | (pll_div.k & 0xf); /* K [3:0] */
786 ac97_write(codec, AC97_LINE1_LEVEL, reg);
787 }
788
789 /* turn PLL on and select as source */
790 reg = ac97_read(codec, AC97_EXTENDED_MID);
791 ac97_write(codec, AC97_EXTENDED_MID, reg & 0xfdff);
792 reg = ac97_read(codec, AC97_HANDSET_RATE);
793 ac97_write(codec, AC97_HANDSET_RATE, reg & 0xff7f);
794 wm9713->pll_out = freq_out;
795 wm9713->pll_in = freq_in;
796
797 /* wait 10ms AC97 link frames for the link to stabilise */
798 schedule_timeout_interruptible(msecs_to_jiffies(10));
799 return 0;
800}
801
802static int wm9713_set_dai_pll(struct snd_soc_codec_dai *codec_dai,
803 int pll_id, unsigned int freq_in, unsigned int freq_out)
804{
805 struct snd_soc_codec *codec = codec_dai->codec;
806 return wm9713_set_pll(codec, pll_id, freq_in, freq_out);
807}
808
809/*
810 * Tristate the PCM DAI lines, tristate can be disabled by calling
811 * wm9713_set_dai_fmt()
812 */
813static int wm9713_set_dai_tristate(struct snd_soc_codec_dai *codec_dai,
814 int tristate)
815{
816 struct snd_soc_codec *codec = codec_dai->codec;
817 u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0x9fff;
818
819 if (tristate)
820 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
821
822 return 0;
823}
824
825/*
826 * Configure WM9713 clock dividers.
827 * Voice DAC needs 256 FS
828 */
829static int wm9713_set_dai_clkdiv(struct snd_soc_codec_dai *codec_dai,
830 int div_id, int div)
831{
832 struct snd_soc_codec *codec = codec_dai->codec;
833 u16 reg;
834
835 switch (div_id) {
836 case WM9713_PCMCLK_DIV:
837 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xf0ff;
838 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
839 break;
840 case WM9713_CLKA_MULT:
841 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffd;
842 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
843 break;
844 case WM9713_CLKB_MULT:
845 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffb;
846 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
847 break;
848 case WM9713_HIFI_DIV:
849 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0x8fff;
850 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
851 break;
852 case WM9713_PCMBCLK_DIV:
853 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xf1ff;
854 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg | div);
855 break;
856 case WM9713_PCMCLK_PLL_DIV:
857 reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80;
858 ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x60 | div);
859 break;
860 case WM9713_HIFI_PLL_DIV:
861 reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80;
862 ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x70 | div);
863 break;
864 default:
865 return -EINVAL;
866 }
867
868 return 0;
869}
870
871static int wm9713_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
872 unsigned int fmt)
873{
874 struct snd_soc_codec *codec = codec_dai->codec;
875 u16 gpio = ac97_read(codec, AC97_GPIO_CFG) & 0xffc5;
876 u16 reg = 0x8000;
877
878 /* clock masters */
879 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
880 case SND_SOC_DAIFMT_CBM_CFM:
881 reg |= 0x4000;
882 gpio |= 0x0010;
883 break;
884 case SND_SOC_DAIFMT_CBM_CFS:
885 reg |= 0x6000;
886 gpio |= 0x0018;
887 break;
888 case SND_SOC_DAIFMT_CBS_CFS:
889 reg |= 0x0200;
890 gpio |= 0x001a;
891 break;
892 case SND_SOC_DAIFMT_CBS_CFM:
893 gpio |= 0x0012;
894 break;
895 }
896
897 /* clock inversion */
898 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
899 case SND_SOC_DAIFMT_IB_IF:
900 reg |= 0x00c0;
901 break;
902 case SND_SOC_DAIFMT_IB_NF:
903 reg |= 0x0080;
904 break;
905 case SND_SOC_DAIFMT_NB_IF:
906 reg |= 0x0040;
907 break;
908 }
909
910 /* DAI format */
911 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
912 case SND_SOC_DAIFMT_I2S:
913 reg |= 0x0002;
914 break;
915 case SND_SOC_DAIFMT_RIGHT_J:
916 break;
917 case SND_SOC_DAIFMT_LEFT_J:
918 reg |= 0x0001;
919 break;
920 case SND_SOC_DAIFMT_DSP_A:
921 reg |= 0x0003;
922 break;
923 case SND_SOC_DAIFMT_DSP_B:
924 reg |= 0x0043;
925 break;
926 }
927
928 ac97_write(codec, AC97_GPIO_CFG, gpio);
929 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
930 return 0;
931}
932
933static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream,
934 struct snd_pcm_hw_params *params)
935{
936 struct snd_soc_pcm_runtime *rtd = substream->private_data;
937 struct snd_soc_device *socdev = rtd->socdev;
938 struct snd_soc_codec *codec = socdev->codec;
939 u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xfff3;
940
941 switch (params_format(params)) {
942 case SNDRV_PCM_FORMAT_S16_LE:
943 break;
944 case SNDRV_PCM_FORMAT_S20_3LE:
945 reg |= 0x0004;
946 break;
947 case SNDRV_PCM_FORMAT_S24_LE:
948 reg |= 0x0008;
949 break;
950 case SNDRV_PCM_FORMAT_S32_LE:
951 reg |= 0x000c;
952 break;
953 }
954
955 /* enable PCM interface in master mode */
956 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
957 return 0;
958}
959
960static void wm9713_voiceshutdown(struct snd_pcm_substream *substream)
961{
962 struct snd_soc_pcm_runtime *rtd = substream->private_data;
963 struct snd_soc_device *socdev = rtd->socdev;
964 struct snd_soc_codec *codec = socdev->codec;
965 u16 status;
966
967 /* Gracefully shut down the voice interface. */
968 status = ac97_read(codec, AC97_EXTENDED_STATUS) | 0x1000;
969 ac97_write(codec, AC97_HANDSET_RATE, 0x0280);
970 schedule_timeout_interruptible(msecs_to_jiffies(1));
971 ac97_write(codec, AC97_HANDSET_RATE, 0x0F80);
972 ac97_write(codec, AC97_EXTENDED_MID, status);
973}
974
975static int ac97_hifi_prepare(struct snd_pcm_substream *substream)
976{
977 struct snd_pcm_runtime *runtime = substream->runtime;
978 struct snd_soc_pcm_runtime *rtd = substream->private_data;
979 struct snd_soc_device *socdev = rtd->socdev;
980 struct snd_soc_codec *codec = socdev->codec;
981 int reg;
982 u16 vra;
983
984 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
985 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
986
987 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
988 reg = AC97_PCM_FRONT_DAC_RATE;
989 else
990 reg = AC97_PCM_LR_ADC_RATE;
991
992 return ac97_write(codec, reg, runtime->rate);
993}
994
995static int ac97_aux_prepare(struct snd_pcm_substream *substream)
996{
997 struct snd_pcm_runtime *runtime = substream->runtime;
998 struct snd_soc_pcm_runtime *rtd = substream->private_data;
999 struct snd_soc_device *socdev = rtd->socdev;
1000 struct snd_soc_codec *codec = socdev->codec;
1001 u16 vra, xsle;
1002
1003 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
1004 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
1005 xsle = ac97_read(codec, AC97_PCI_SID);
1006 ac97_write(codec, AC97_PCI_SID, xsle | 0x8000);
1007
1008 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
1009 return -ENODEV;
1010
1011 return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate);
1012}
1013
1014#define WM9713_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
1015 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
1016 SNDRV_PCM_RATE_48000)
1017
1018#define WM9713_PCM_FORMATS \
1019 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
1020 SNDRV_PCM_FORMAT_S24_LE)
1021
1022struct snd_soc_codec_dai wm9713_dai[] = {
1023{
1024 .name = "AC97 HiFi",
1025 .type = SND_SOC_DAI_AC97_BUS,
1026 .playback = {
1027 .stream_name = "HiFi Playback",
1028 .channels_min = 1,
1029 .channels_max = 2,
1030 .rates = WM9713_RATES,
1031 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1032 .capture = {
1033 .stream_name = "HiFi Capture",
1034 .channels_min = 1,
1035 .channels_max = 2,
1036 .rates = WM9713_RATES,
1037 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1038 .ops = {
1039 .prepare = ac97_hifi_prepare,},
1040 .dai_ops = {
1041 .set_clkdiv = wm9713_set_dai_clkdiv,
1042 .set_pll = wm9713_set_dai_pll,},
1043 },
1044 {
1045 .name = "AC97 Aux",
1046 .playback = {
1047 .stream_name = "Aux Playback",
1048 .channels_min = 1,
1049 .channels_max = 1,
1050 .rates = WM9713_RATES,
1051 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1052 .ops = {
1053 .prepare = ac97_aux_prepare,},
1054 .dai_ops = {
1055 .set_clkdiv = wm9713_set_dai_clkdiv,
1056 .set_pll = wm9713_set_dai_pll,},
1057 },
1058 {
1059 .name = "WM9713 Voice",
1060 .playback = {
1061 .stream_name = "Voice Playback",
1062 .channels_min = 1,
1063 .channels_max = 1,
1064 .rates = WM9713_RATES,
1065 .formats = WM9713_PCM_FORMATS,},
1066 .capture = {
1067 .stream_name = "Voice Capture",
1068 .channels_min = 1,
1069 .channels_max = 2,
1070 .rates = WM9713_RATES,
1071 .formats = WM9713_PCM_FORMATS,},
1072 .ops = {
1073 .hw_params = wm9713_pcm_hw_params,
1074 .shutdown = wm9713_voiceshutdown,},
1075 .dai_ops = {
1076 .set_clkdiv = wm9713_set_dai_clkdiv,
1077 .set_pll = wm9713_set_dai_pll,
1078 .set_fmt = wm9713_set_dai_fmt,
1079 .set_tristate = wm9713_set_dai_tristate,
1080 },
1081 },
1082};
1083EXPORT_SYMBOL_GPL(wm9713_dai);
1084
1085int wm9713_reset(struct snd_soc_codec *codec, int try_warm)
1086{
1087 if (try_warm && soc_ac97_ops.warm_reset) {
1088 soc_ac97_ops.warm_reset(codec->ac97);
1089 if (!(ac97_read(codec, 0) & 0x8000))
1090 return 1;
1091 }
1092
1093 soc_ac97_ops.reset(codec->ac97);
1094 if (ac97_read(codec, 0) & 0x8000)
1095 return -EIO;
1096 return 0;
1097}
1098EXPORT_SYMBOL_GPL(wm9713_reset);
1099
1100static int wm9713_dapm_event(struct snd_soc_codec *codec, int event)
1101{
1102 u16 reg;
1103
1104 switch (event) {
1105 case SNDRV_CTL_POWER_D0: /* full On */
1106 /* enable thermal shutdown */
1107 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x1bff;
1108 ac97_write(codec, AC97_EXTENDED_MID, reg);
1109 break;
1110 case SNDRV_CTL_POWER_D1: /* partial On */
1111 case SNDRV_CTL_POWER_D2: /* partial On */
1112 break;
1113 case SNDRV_CTL_POWER_D3hot: /* Off, with power */
1114 /* enable master bias and vmid */
1115 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x3bff;
1116 ac97_write(codec, AC97_EXTENDED_MID, reg);
1117 ac97_write(codec, AC97_POWERDOWN, 0x0000);
1118 break;
1119 case SNDRV_CTL_POWER_D3cold: /* Off, without power */
1120 /* disable everything including AC link */
1121 ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
1122 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
1123 ac97_write(codec, AC97_POWERDOWN, 0xffff);
1124 break;
1125 }
1126 codec->dapm_state = event;
1127 return 0;
1128}
1129
1130static int wm9713_soc_suspend(struct platform_device *pdev,
1131 pm_message_t state)
1132{
1133 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1134 struct snd_soc_codec *codec = socdev->codec;
1135 u16 reg;
1136
1137 /* Disable everything except touchpanel - that will be handled
1138 * by the touch driver and left disabled if touch is not in
1139 * use. */
1140 reg = ac97_read(codec, AC97_EXTENDED_MID);
1141 ac97_write(codec, AC97_EXTENDED_MID, reg | 0x7fff);
1142 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
1143 ac97_write(codec, AC97_POWERDOWN, 0x6f00);
1144 ac97_write(codec, AC97_POWERDOWN, 0xffff);
1145
1146 return 0;
1147}
1148
1149static int wm9713_soc_resume(struct platform_device *pdev)
1150{
1151 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1152 struct snd_soc_codec *codec = socdev->codec;
1153 struct wm9713_priv *wm9713 = codec->private_data;
1154 int i, ret;
1155 u16 *cache = codec->reg_cache;
1156
1157 ret = wm9713_reset(codec, 1);
1158 if (ret < 0) {
1159 printk(KERN_ERR "could not reset AC97 codec\n");
1160 return ret;
1161 }
1162
1163 wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
1164
1165 /* do we need to re-start the PLL ? */
1166 if (wm9713->pll_out)
1167 wm9713_set_pll(codec, 0, wm9713->pll_in, wm9713->pll_out);
1168
1169 /* only synchronise the codec if warm reset failed */
1170 if (ret == 0) {
1171 for (i = 2; i < ARRAY_SIZE(wm9713_reg) << 1; i += 2) {
1172 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_MID ||
1173 i == AC97_EXTENDED_MSTATUS || i > 0x66)
1174 continue;
1175 soc_ac97_ops.write(codec->ac97, i, cache[i>>1]);
1176 }
1177 }
1178
1179 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0)
1180 wm9713_dapm_event(codec, SNDRV_CTL_POWER_D0);
1181
1182 return ret;
1183}
1184
1185static int wm9713_soc_probe(struct platform_device *pdev)
1186{
1187 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1188 struct snd_soc_codec *codec;
1189 int ret = 0, reg;
1190
1191 printk(KERN_INFO "WM9713/WM9714 SoC Audio Codec %s\n", WM9713_VERSION);
1192
1193 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
1194 if (socdev->codec == NULL)
1195 return -ENOMEM;
1196 codec = socdev->codec;
1197 mutex_init(&codec->mutex);
1198
1199 codec->reg_cache = kmemdup(wm9713_reg, sizeof(wm9713_reg), GFP_KERNEL);
1200 if (codec->reg_cache == NULL) {
1201 ret = -ENOMEM;
1202 goto cache_err;
1203 }
1204 codec->reg_cache_size = sizeof(wm9713_reg);
1205 codec->reg_cache_step = 2;
1206
1207 codec->private_data = kzalloc(sizeof(struct wm9713_priv), GFP_KERNEL);
1208 if (codec->private_data == NULL) {
1209 ret = -ENOMEM;
1210 goto priv_err;
1211 }
1212
1213 codec->name = "WM9713";
1214 codec->owner = THIS_MODULE;
1215 codec->dai = wm9713_dai;
1216 codec->num_dai = ARRAY_SIZE(wm9713_dai);
1217 codec->write = ac97_write;
1218 codec->read = ac97_read;
1219 codec->dapm_event = wm9713_dapm_event;
1220 INIT_LIST_HEAD(&codec->dapm_widgets);
1221 INIT_LIST_HEAD(&codec->dapm_paths);
1222
1223 ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0);
1224 if (ret < 0)
1225 goto codec_err;
1226
1227 /* register pcms */
1228 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
1229 if (ret < 0)
1230 goto pcm_err;
1231
1232 /* do a cold reset for the controller and then try
1233 * a warm reset followed by an optional cold reset for codec */
1234 wm9713_reset(codec, 0);
1235 ret = wm9713_reset(codec, 1);
1236 if (ret < 0) {
1237 printk(KERN_ERR "AC97 link error\n");
1238 goto reset_err;
1239 }
1240
1241 wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
1242
1243 /* unmute the adc - move to kcontrol */
1244 reg = ac97_read(codec, AC97_CD) & 0x7fff;
1245 ac97_write(codec, AC97_CD, reg);
1246
1247 wm9713_add_controls(codec);
1248 wm9713_add_widgets(codec);
1249 ret = snd_soc_register_card(socdev);
1250 if (ret < 0)
1251 goto reset_err;
1252 return 0;
1253
1254reset_err:
1255 snd_soc_free_pcms(socdev);
1256
1257pcm_err:
1258 snd_soc_free_ac97_codec(codec);
1259
1260codec_err:
1261 kfree(codec->private_data);
1262
1263priv_err:
1264 kfree(codec->reg_cache);
1265
1266cache_err:
1267 kfree(socdev->codec);
1268 socdev->codec = NULL;
1269 return ret;
1270}
1271
1272static int wm9713_soc_remove(struct platform_device *pdev)
1273{
1274 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1275 struct snd_soc_codec *codec = socdev->codec;
1276
1277 if (codec == NULL)
1278 return 0;
1279
1280 snd_soc_dapm_free(socdev);
1281 snd_soc_free_pcms(socdev);
1282 snd_soc_free_ac97_codec(codec);
1283 kfree(codec->private_data);
1284 kfree(codec->reg_cache);
1285 kfree(codec->dai);
1286 kfree(codec);
1287 return 0;
1288}
1289
1290struct snd_soc_codec_device soc_codec_dev_wm9713 = {
1291 .probe = wm9713_soc_probe,
1292 .remove = wm9713_soc_remove,
1293 .suspend = wm9713_soc_suspend,
1294 .resume = wm9713_soc_resume,
1295};
1296EXPORT_SYMBOL_GPL(soc_codec_dev_wm9713);
1297
1298MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver");
1299MODULE_AUTHOR("Liam Girdwood");
1300MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm9713.h b/sound/soc/codecs/wm9713.h
new file mode 100644
index 000000000000..d357b6c8134b
--- /dev/null
+++ b/sound/soc/codecs/wm9713.h
@@ -0,0 +1,53 @@
1/*
2 * wm9713.h -- WM9713 Soc Audio driver
3 */
4
5#ifndef _WM9713_H
6#define _WM9713_H
7
8/* clock inputs */
9#define WM9713_CLKA_PIN 0
10#define WM9713_CLKB_PIN 1
11
12/* clock divider ID's */
13#define WM9713_PCMCLK_DIV 0
14#define WM9713_CLKA_MULT 1
15#define WM9713_CLKB_MULT 2
16#define WM9713_HIFI_DIV 3
17#define WM9713_PCMBCLK_DIV 4
18#define WM9713_PCMCLK_PLL_DIV 5
19#define WM9713_HIFI_PLL_DIV 6
20
21/* Calculate the appropriate bit mask for the external PCM clock divider */
22#define WM9713_PCMDIV(x) ((x - 1) << 8)
23
24/* Calculate the appropriate bit mask for the external HiFi clock divider */
25#define WM9713_HIFIDIV(x) ((x - 1) << 12)
26
27/* MCLK clock mulitipliers */
28#define WM9713_CLKA_X1 (0 << 1)
29#define WM9713_CLKA_X2 (1 << 1)
30#define WM9713_CLKB_X1 (0 << 2)
31#define WM9713_CLKB_X2 (1 << 2)
32
33/* MCLK clock MUX */
34#define WM9713_CLK_MUX_A (0 << 0)
35#define WM9713_CLK_MUX_B (1 << 0)
36
37/* Voice DAI BCLK divider */
38#define WM9713_PCMBCLK_DIV_1 (0 << 9)
39#define WM9713_PCMBCLK_DIV_2 (1 << 9)
40#define WM9713_PCMBCLK_DIV_4 (2 << 9)
41#define WM9713_PCMBCLK_DIV_8 (3 << 9)
42#define WM9713_PCMBCLK_DIV_16 (4 << 9)
43
44#define WM9713_DAI_AC97_HIFI 0
45#define WM9713_DAI_AC97_AUX 1
46#define WM9713_DAI_PCM_VOICE 2
47
48extern struct snd_soc_codec_device soc_codec_dev_wm9713;
49extern struct snd_soc_codec_dai wm9713_dai[3];
50
51int wm9713_reset(struct snd_soc_codec *codec, int try_warm);
52
53#endif
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig
new file mode 100644
index 000000000000..20680c551aab
--- /dev/null
+++ b/sound/soc/davinci/Kconfig
@@ -0,0 +1,19 @@
1config SND_DAVINCI_SOC
2 tristate "SoC Audio for the TI DAVINCI chip"
3 depends on ARCH_DAVINCI && SND_SOC
4 help
5 Say Y or M if you want to add support for codecs attached to
6 the DAVINCI AC97 or I2S interface. You will also need
7 to select the audio interfaces to support below.
8
9config SND_DAVINCI_SOC_I2S
10 tristate
11
12config SND_DAVINCI_SOC_EVM
13 tristate "SoC Audio support for DaVinci EVM"
14 depends on SND_DAVINCI_SOC && MACH_DAVINCI_EVM
15 select SND_DAVINCI_SOC_I2S
16 select SND_SOC_TLV320AIC3X
17 help
18 Say Y if you want to add support for SoC audio on TI
19 DaVinci EVM platform.
diff --git a/sound/soc/davinci/Makefile b/sound/soc/davinci/Makefile
new file mode 100644
index 000000000000..ca772e5b4637
--- /dev/null
+++ b/sound/soc/davinci/Makefile
@@ -0,0 +1,11 @@
1# DAVINCI Platform Support
2snd-soc-davinci-objs := davinci-pcm.o
3snd-soc-davinci-i2s-objs := davinci-i2s.o
4
5obj-$(CONFIG_SND_DAVINCI_SOC) += snd-soc-davinci.o
6obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o
7
8# DAVINCI Machine Support
9snd-soc-evm-objs := davinci-evm.o
10
11obj-$(CONFIG_SND_DAVINCI_SOC_EVM) += snd-soc-evm.o
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
new file mode 100644
index 000000000000..fcd165240333
--- /dev/null
+++ b/sound/soc/davinci/davinci-evm.c
@@ -0,0 +1,208 @@
1/*
2 * ASoC driver for TI DAVINCI EVM platform
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/timer.h>
15#include <linux/interrupt.h>
16#include <linux/platform_device.h>
17#include <sound/core.h>
18#include <sound/pcm.h>
19#include <sound/soc.h>
20#include <sound/soc-dapm.h>
21
22#include <asm/mach-types.h>
23#include <asm/dma.h>
24#include <asm/arch/hardware.h>
25
26#include "../codecs/tlv320aic3x.h"
27#include "davinci-pcm.h"
28#include "davinci-i2s.h"
29
30#define EVM_CODEC_CLOCK 22579200
31
32static int evm_hw_params(struct snd_pcm_substream *substream,
33 struct snd_pcm_hw_params *params)
34{
35 struct snd_soc_pcm_runtime *rtd = substream->private_data;
36 struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
37 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
38 int ret = 0;
39
40 /* set codec DAI configuration */
41 ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
42 SND_SOC_DAIFMT_CBM_CFM);
43 if (ret < 0)
44 return ret;
45
46 /* set cpu DAI configuration */
47 ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
48 SND_SOC_DAIFMT_IB_NF);
49 if (ret < 0)
50 return ret;
51
52 /* set the codec system clock */
53 ret = codec_dai->dai_ops.set_sysclk(codec_dai, 0, EVM_CODEC_CLOCK,
54 SND_SOC_CLOCK_OUT);
55 if (ret < 0)
56 return ret;
57
58 return 0;
59}
60
61static struct snd_soc_ops evm_ops = {
62 .hw_params = evm_hw_params,
63};
64
65/* davinci-evm machine dapm widgets */
66static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
67 SND_SOC_DAPM_HP("Headphone Jack", NULL),
68 SND_SOC_DAPM_LINE("Line Out", NULL),
69 SND_SOC_DAPM_MIC("Mic Jack", NULL),
70 SND_SOC_DAPM_LINE("Line In", NULL),
71};
72
73/* davinci-evm machine audio_mapnections to the codec pins */
74static const char *audio_map[][3] = {
75 /* Headphone connected to HPLOUT, HPROUT */
76 {"Headphone Jack", NULL, "HPLOUT"},
77 {"Headphone Jack", NULL, "HPROUT"},
78
79 /* Line Out connected to LLOUT, RLOUT */
80 {"Line Out", NULL, "LLOUT"},
81 {"Line Out", NULL, "RLOUT"},
82
83 /* Mic connected to (MIC3L | MIC3R) */
84 {"MIC3L", NULL, "Mic Bias 2V"},
85 {"MIC3R", NULL, "Mic Bias 2V"},
86 {"Mic Bias 2V", NULL, "Mic Jack"},
87
88 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
89 {"LINE1L", NULL, "Line In"},
90 {"LINE2L", NULL, "Line In"},
91 {"LINE1R", NULL, "Line In"},
92 {"LINE2R", NULL, "Line In"},
93
94 {NULL, NULL, NULL},
95};
96
97/* Logic for a aic3x as connected on a davinci-evm */
98static int evm_aic3x_init(struct snd_soc_codec *codec)
99{
100 int i;
101
102 /* Add davinci-evm specific widgets */
103 for (i = 0; i < ARRAY_SIZE(aic3x_dapm_widgets); i++)
104 snd_soc_dapm_new_control(codec, &aic3x_dapm_widgets[i]);
105
106 /* Set up davinci-evm specific audio path audio_map */
107 for (i = 0; audio_map[i][0] != NULL; i++)
108 snd_soc_dapm_connect_input(codec, audio_map[i][0],
109 audio_map[i][1], audio_map[i][2]);
110
111 /* not connected */
112 snd_soc_dapm_set_endpoint(codec, "MONO_LOUT", 0);
113 snd_soc_dapm_set_endpoint(codec, "HPLCOM", 0);
114 snd_soc_dapm_set_endpoint(codec, "HPRCOM", 0);
115
116 /* always connected */
117 snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
118 snd_soc_dapm_set_endpoint(codec, "Line Out", 1);
119 snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
120 snd_soc_dapm_set_endpoint(codec, "Line In", 1);
121
122 snd_soc_dapm_sync_endpoints(codec);
123
124 return 0;
125}
126
127/* davinci-evm digital audio interface glue - connects codec <--> CPU */
128static struct snd_soc_dai_link evm_dai = {
129 .name = "TLV320AIC3X",
130 .stream_name = "AIC3X",
131 .cpu_dai = &davinci_i2s_dai,
132 .codec_dai = &aic3x_dai,
133 .init = evm_aic3x_init,
134 .ops = &evm_ops,
135};
136
137/* davinci-evm audio machine driver */
138static struct snd_soc_machine snd_soc_machine_evm = {
139 .name = "DaVinci EVM",
140 .dai_link = &evm_dai,
141 .num_links = 1,
142};
143
144/* evm audio private data */
145static struct aic3x_setup_data evm_aic3x_setup = {
146 .i2c_address = 0x1b,
147};
148
149/* evm audio subsystem */
150static struct snd_soc_device evm_snd_devdata = {
151 .machine = &snd_soc_machine_evm,
152 .platform = &davinci_soc_platform,
153 .codec_dev = &soc_codec_dev_aic3x,
154 .codec_data = &evm_aic3x_setup,
155};
156
157static struct resource evm_snd_resources[] = {
158 {
159 .start = DAVINCI_MCBSP_BASE,
160 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
161 .flags = IORESOURCE_MEM,
162 },
163};
164
165static struct evm_snd_platform_data evm_snd_data = {
166 .tx_dma_ch = DM644X_DMACH_MCBSP_TX,
167 .rx_dma_ch = DM644X_DMACH_MCBSP_RX,
168};
169
170static struct platform_device *evm_snd_device;
171
172static int __init evm_init(void)
173{
174 int ret;
175
176 evm_snd_device = platform_device_alloc("soc-audio", 0);
177 if (!evm_snd_device)
178 return -ENOMEM;
179
180 platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
181 evm_snd_devdata.dev = &evm_snd_device->dev;
182 evm_snd_device->dev.platform_data = &evm_snd_data;
183
184 ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
185 ARRAY_SIZE(evm_snd_resources));
186 if (ret) {
187 platform_device_put(evm_snd_device);
188 return ret;
189 }
190
191 ret = platform_device_add(evm_snd_device);
192 if (ret)
193 platform_device_put(evm_snd_device);
194
195 return ret;
196}
197
198static void __exit evm_exit(void)
199{
200 platform_device_unregister(evm_snd_device);
201}
202
203module_init(evm_init);
204module_exit(evm_exit);
205
206MODULE_AUTHOR("Vladimir Barinov");
207MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
208MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
new file mode 100644
index 000000000000..c421774b33ee
--- /dev/null
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -0,0 +1,407 @@
1/*
2 * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/device.h>
15#include <linux/delay.h>
16#include <linux/io.h>
17#include <linux/clk.h>
18
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/pcm_params.h>
22#include <sound/initval.h>
23#include <sound/soc.h>
24
25#include "davinci-pcm.h"
26
27#define DAVINCI_MCBSP_DRR_REG 0x00
28#define DAVINCI_MCBSP_DXR_REG 0x04
29#define DAVINCI_MCBSP_SPCR_REG 0x08
30#define DAVINCI_MCBSP_RCR_REG 0x0c
31#define DAVINCI_MCBSP_XCR_REG 0x10
32#define DAVINCI_MCBSP_SRGR_REG 0x14
33#define DAVINCI_MCBSP_PCR_REG 0x24
34
35#define DAVINCI_MCBSP_SPCR_RRST (1 << 0)
36#define DAVINCI_MCBSP_SPCR_RINTM(v) ((v) << 4)
37#define DAVINCI_MCBSP_SPCR_XRST (1 << 16)
38#define DAVINCI_MCBSP_SPCR_XINTM(v) ((v) << 20)
39#define DAVINCI_MCBSP_SPCR_GRST (1 << 22)
40#define DAVINCI_MCBSP_SPCR_FRST (1 << 23)
41#define DAVINCI_MCBSP_SPCR_FREE (1 << 25)
42
43#define DAVINCI_MCBSP_RCR_RWDLEN1(v) ((v) << 5)
44#define DAVINCI_MCBSP_RCR_RFRLEN1(v) ((v) << 8)
45#define DAVINCI_MCBSP_RCR_RDATDLY(v) ((v) << 16)
46#define DAVINCI_MCBSP_RCR_RWDLEN2(v) ((v) << 21)
47
48#define DAVINCI_MCBSP_XCR_XWDLEN1(v) ((v) << 5)
49#define DAVINCI_MCBSP_XCR_XFRLEN1(v) ((v) << 8)
50#define DAVINCI_MCBSP_XCR_XDATDLY(v) ((v) << 16)
51#define DAVINCI_MCBSP_XCR_XFIG (1 << 18)
52#define DAVINCI_MCBSP_XCR_XWDLEN2(v) ((v) << 21)
53
54#define DAVINCI_MCBSP_SRGR_FWID(v) ((v) << 8)
55#define DAVINCI_MCBSP_SRGR_FPER(v) ((v) << 16)
56#define DAVINCI_MCBSP_SRGR_FSGM (1 << 28)
57
58#define DAVINCI_MCBSP_PCR_CLKRP (1 << 0)
59#define DAVINCI_MCBSP_PCR_CLKXP (1 << 1)
60#define DAVINCI_MCBSP_PCR_FSRP (1 << 2)
61#define DAVINCI_MCBSP_PCR_FSXP (1 << 3)
62#define DAVINCI_MCBSP_PCR_CLKRM (1 << 8)
63#define DAVINCI_MCBSP_PCR_CLKXM (1 << 9)
64#define DAVINCI_MCBSP_PCR_FSRM (1 << 10)
65#define DAVINCI_MCBSP_PCR_FSXM (1 << 11)
66
67#define MOD_REG_BIT(val, mask, set) do { \
68 if (set) { \
69 val |= mask; \
70 } else { \
71 val &= ~mask; \
72 } \
73} while (0)
74
75enum {
76 DAVINCI_MCBSP_WORD_8 = 0,
77 DAVINCI_MCBSP_WORD_12,
78 DAVINCI_MCBSP_WORD_16,
79 DAVINCI_MCBSP_WORD_20,
80 DAVINCI_MCBSP_WORD_24,
81 DAVINCI_MCBSP_WORD_32,
82};
83
84static struct davinci_pcm_dma_params davinci_i2s_pcm_out = {
85 .name = "I2S PCM Stereo out",
86};
87
88static struct davinci_pcm_dma_params davinci_i2s_pcm_in = {
89 .name = "I2S PCM Stereo in",
90};
91
92struct davinci_mcbsp_dev {
93 void __iomem *base;
94 struct clk *clk;
95 struct davinci_pcm_dma_params *dma_params[2];
96};
97
98static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev,
99 int reg, u32 val)
100{
101 __raw_writel(val, dev->base + reg);
102}
103
104static inline u32 davinci_mcbsp_read_reg(struct davinci_mcbsp_dev *dev, int reg)
105{
106 return __raw_readl(dev->base + reg);
107}
108
109static void davinci_mcbsp_start(struct snd_pcm_substream *substream)
110{
111 struct snd_soc_pcm_runtime *rtd = substream->private_data;
112 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
113 u32 w;
114
115 /* Start the sample generator and enable transmitter/receiver */
116 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
117 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_GRST, 1);
118 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
119 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 1);
120 else
121 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_RRST, 1);
122 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w);
123
124 /* Start frame sync */
125 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
126 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_FRST, 1);
127 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w);
128}
129
130static void davinci_mcbsp_stop(struct snd_pcm_substream *substream)
131{
132 struct snd_soc_pcm_runtime *rtd = substream->private_data;
133 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
134 u32 w;
135
136 /* Reset transmitter/receiver and sample rate/frame sync generators */
137 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
138 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_GRST |
139 DAVINCI_MCBSP_SPCR_FRST, 0);
140 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
141 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 0);
142 else
143 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_RRST, 0);
144 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w);
145}
146
147static int davinci_i2s_startup(struct snd_pcm_substream *substream)
148{
149 struct snd_soc_pcm_runtime *rtd = substream->private_data;
150 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
151 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
152
153 cpu_dai->dma_data = dev->dma_params[substream->stream];
154
155 return 0;
156}
157
158static int davinci_i2s_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
159 unsigned int fmt)
160{
161 struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
162 u32 w;
163
164 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
165 case SND_SOC_DAIFMT_CBS_CFS:
166 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG,
167 DAVINCI_MCBSP_PCR_FSXM |
168 DAVINCI_MCBSP_PCR_FSRM |
169 DAVINCI_MCBSP_PCR_CLKXM |
170 DAVINCI_MCBSP_PCR_CLKRM);
171 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG,
172 DAVINCI_MCBSP_SRGR_FSGM);
173 break;
174 case SND_SOC_DAIFMT_CBM_CFM:
175 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, 0);
176 break;
177 default:
178 return -EINVAL;
179 }
180
181 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
182 case SND_SOC_DAIFMT_IB_NF:
183 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG);
184 MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_CLKXP |
185 DAVINCI_MCBSP_PCR_CLKRP, 1);
186 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w);
187 break;
188 case SND_SOC_DAIFMT_NB_IF:
189 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG);
190 MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_FSXP |
191 DAVINCI_MCBSP_PCR_FSRP, 1);
192 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w);
193 break;
194 case SND_SOC_DAIFMT_IB_IF:
195 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG);
196 MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_CLKXP |
197 DAVINCI_MCBSP_PCR_CLKRP |
198 DAVINCI_MCBSP_PCR_FSXP |
199 DAVINCI_MCBSP_PCR_FSRP, 1);
200 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w);
201 break;
202 case SND_SOC_DAIFMT_NB_NF:
203 break;
204 default:
205 return -EINVAL;
206 }
207
208 return 0;
209}
210
211static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
212 struct snd_pcm_hw_params *params)
213{
214 struct snd_soc_pcm_runtime *rtd = substream->private_data;
215 struct davinci_pcm_dma_params *dma_params = rtd->dai->cpu_dai->dma_data;
216 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
217 struct snd_interval *i = NULL;
218 int mcbsp_word_length;
219 u32 w;
220
221 /* general line settings */
222 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG,
223 DAVINCI_MCBSP_SPCR_RINTM(3) |
224 DAVINCI_MCBSP_SPCR_XINTM(3) |
225 DAVINCI_MCBSP_SPCR_FREE);
226 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG,
227 DAVINCI_MCBSP_RCR_RFRLEN1(1) |
228 DAVINCI_MCBSP_RCR_RDATDLY(1));
229 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG,
230 DAVINCI_MCBSP_XCR_XFRLEN1(1) |
231 DAVINCI_MCBSP_XCR_XDATDLY(1) |
232 DAVINCI_MCBSP_XCR_XFIG);
233
234 i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS);
235 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SRGR_REG);
236 MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FWID(snd_interval_value(i) - 1), 1);
237 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w);
238
239 i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_FRAME_BITS);
240 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SRGR_REG);
241 MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FPER(snd_interval_value(i) - 1), 1);
242 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w);
243
244 /* Determine xfer data type */
245 switch (params_format(params)) {
246 case SNDRV_PCM_FORMAT_S8:
247 dma_params->data_type = 1;
248 mcbsp_word_length = DAVINCI_MCBSP_WORD_8;
249 break;
250 case SNDRV_PCM_FORMAT_S16_LE:
251 dma_params->data_type = 2;
252 mcbsp_word_length = DAVINCI_MCBSP_WORD_16;
253 break;
254 case SNDRV_PCM_FORMAT_S32_LE:
255 dma_params->data_type = 4;
256 mcbsp_word_length = DAVINCI_MCBSP_WORD_32;
257 break;
258 default:
259 printk(KERN_WARNING "davinci-i2s: unsupported PCM format");
260 return -EINVAL;
261 }
262
263 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_RCR_REG);
264 MOD_REG_BIT(w, DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) |
265 DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length), 1);
266 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG, w);
267
268 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_XCR_REG);
269 MOD_REG_BIT(w, DAVINCI_MCBSP_XCR_XWDLEN1(mcbsp_word_length) |
270 DAVINCI_MCBSP_XCR_XWDLEN2(mcbsp_word_length), 1);
271 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG, w);
272
273 return 0;
274}
275
276static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
277{
278 int ret = 0;
279
280 switch (cmd) {
281 case SNDRV_PCM_TRIGGER_START:
282 case SNDRV_PCM_TRIGGER_RESUME:
283 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
284 davinci_mcbsp_start(substream);
285 break;
286 case SNDRV_PCM_TRIGGER_STOP:
287 case SNDRV_PCM_TRIGGER_SUSPEND:
288 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
289 davinci_mcbsp_stop(substream);
290 break;
291 default:
292 ret = -EINVAL;
293 }
294
295 return ret;
296}
297
298static int davinci_i2s_probe(struct platform_device *pdev)
299{
300 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
301 struct snd_soc_machine *machine = socdev->machine;
302 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai;
303 struct davinci_mcbsp_dev *dev;
304 struct resource *mem, *ioarea;
305 struct evm_snd_platform_data *pdata;
306 int ret;
307
308 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
309 if (!mem) {
310 dev_err(&pdev->dev, "no mem resource?\n");
311 return -ENODEV;
312 }
313
314 ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1,
315 pdev->name);
316 if (!ioarea) {
317 dev_err(&pdev->dev, "McBSP region already claimed\n");
318 return -EBUSY;
319 }
320
321 dev = kzalloc(sizeof(struct davinci_mcbsp_dev), GFP_KERNEL);
322 if (!dev) {
323 ret = -ENOMEM;
324 goto err_release_region;
325 }
326
327 cpu_dai->private_data = dev;
328
329 dev->clk = clk_get(&pdev->dev, "McBSPCLK");
330 if (IS_ERR(dev->clk)) {
331 ret = -ENODEV;
332 goto err_free_mem;
333 }
334 clk_enable(dev->clk);
335
336 dev->base = (void __iomem *)IO_ADDRESS(mem->start);
337 pdata = pdev->dev.platform_data;
338
339 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK] = &davinci_i2s_pcm_out;
340 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]->channel = pdata->tx_dma_ch;
341 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]->dma_addr =
342 (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DXR_REG);
343
344 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE] = &davinci_i2s_pcm_in;
345 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]->channel = pdata->rx_dma_ch;
346 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]->dma_addr =
347 (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DRR_REG);
348
349 return 0;
350
351err_free_mem:
352 kfree(dev);
353err_release_region:
354 release_mem_region(mem->start, (mem->end - mem->start) + 1);
355
356 return ret;
357}
358
359static void davinci_i2s_remove(struct platform_device *pdev)
360{
361 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
362 struct snd_soc_machine *machine = socdev->machine;
363 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai;
364 struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
365 struct resource *mem;
366
367 clk_disable(dev->clk);
368 clk_put(dev->clk);
369 dev->clk = NULL;
370
371 kfree(dev);
372
373 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
374 release_mem_region(mem->start, (mem->end - mem->start) + 1);
375}
376
377#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000
378
379struct snd_soc_cpu_dai davinci_i2s_dai = {
380 .name = "davinci-i2s",
381 .id = 0,
382 .type = SND_SOC_DAI_I2S,
383 .probe = davinci_i2s_probe,
384 .remove = davinci_i2s_remove,
385 .playback = {
386 .channels_min = 2,
387 .channels_max = 2,
388 .rates = DAVINCI_I2S_RATES,
389 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
390 .capture = {
391 .channels_min = 2,
392 .channels_max = 2,
393 .rates = DAVINCI_I2S_RATES,
394 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
395 .ops = {
396 .startup = davinci_i2s_startup,
397 .trigger = davinci_i2s_trigger,
398 .hw_params = davinci_i2s_hw_params,},
399 .dai_ops = {
400 .set_fmt = davinci_i2s_set_dai_fmt,
401 },
402};
403EXPORT_SYMBOL_GPL(davinci_i2s_dai);
404
405MODULE_AUTHOR("Vladimir Barinov");
406MODULE_DESCRIPTION("TI DAVINCI I2S (McBSP) SoC Interface");
407MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-i2s.h b/sound/soc/davinci/davinci-i2s.h
new file mode 100644
index 000000000000..9592d17db320
--- /dev/null
+++ b/sound/soc/davinci/davinci-i2s.h
@@ -0,0 +1,17 @@
1/*
2 * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _DAVINCI_I2S_H
13#define _DAVINCI_I2S_H
14
15extern struct snd_soc_cpu_dai davinci_i2s_dai;
16
17#endif
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
new file mode 100644
index 000000000000..6a76927c9971
--- /dev/null
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -0,0 +1,389 @@
1/*
2 * ALSA PCM interface for the TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/platform_device.h>
15#include <linux/slab.h>
16#include <linux/dma-mapping.h>
17
18#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/pcm_params.h>
21#include <sound/soc.h>
22
23#include <asm/dma.h>
24
25#include "davinci-pcm.h"
26
27#define DAVINCI_PCM_DEBUG 0
28#if DAVINCI_PCM_DEBUG
29#define DPRINTK(x...) printk(KERN_DEBUG x)
30#else
31#define DPRINTK(x...)
32#endif
33
34static struct snd_pcm_hardware davinci_pcm_hardware = {
35 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
36 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
37 SNDRV_PCM_INFO_PAUSE),
38 .formats = (SNDRV_PCM_FMTBIT_S16_LE),
39 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
40 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
41 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
42 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
43 SNDRV_PCM_RATE_KNOT),
44 .rate_min = 8000,
45 .rate_max = 96000,
46 .channels_min = 2,
47 .channels_max = 2,
48 .buffer_bytes_max = 128 * 1024,
49 .period_bytes_min = 32,
50 .period_bytes_max = 8 * 1024,
51 .periods_min = 16,
52 .periods_max = 255,
53 .fifo_size = 0,
54};
55
56struct davinci_runtime_data {
57 spinlock_t lock;
58 int period; /* current DMA period */
59 int master_lch; /* Master DMA channel */
60 int slave_lch; /* Slave DMA channel */
61 struct davinci_pcm_dma_params *params; /* DMA params */
62};
63
64static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
65{
66 struct davinci_runtime_data *prtd = substream->runtime->private_data;
67 struct snd_pcm_runtime *runtime = substream->runtime;
68 int lch = prtd->slave_lch;
69 unsigned int period_size;
70 unsigned int dma_offset;
71 dma_addr_t dma_pos;
72 dma_addr_t src, dst;
73 unsigned short src_bidx, dst_bidx;
74 unsigned int data_type;
75 unsigned int count;
76
77 period_size = snd_pcm_lib_period_bytes(substream);
78 dma_offset = prtd->period * period_size;
79 dma_pos = runtime->dma_addr + dma_offset;
80
81 DPRINTK("audio_set_dma_params_play channel = %d dma_ptr = %x "
82 "period_size=%x\n", lch, dma_pos, period_size);
83
84 data_type = prtd->params->data_type;
85 count = period_size / data_type;
86
87 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
88 src = dma_pos;
89 dst = prtd->params->dma_addr;
90 src_bidx = data_type;
91 dst_bidx = 0;
92 } else {
93 src = prtd->params->dma_addr;
94 dst = dma_pos;
95 src_bidx = 0;
96 dst_bidx = data_type;
97 }
98
99 davinci_set_dma_src_params(lch, src, INCR, W8BIT);
100 davinci_set_dma_dest_params(lch, dst, INCR, W8BIT);
101 davinci_set_dma_src_index(lch, src_bidx, 0);
102 davinci_set_dma_dest_index(lch, dst_bidx, 0);
103 davinci_set_dma_transfer_params(lch, data_type, count, 1, 0, ASYNC);
104
105 prtd->period++;
106 if (unlikely(prtd->period >= runtime->periods))
107 prtd->period = 0;
108}
109
110static void davinci_pcm_dma_irq(int lch, u16 ch_status, void *data)
111{
112 struct snd_pcm_substream *substream = data;
113 struct davinci_runtime_data *prtd = substream->runtime->private_data;
114
115 DPRINTK("lch=%d, status=0x%x\n", lch, ch_status);
116
117 if (unlikely(ch_status != DMA_COMPLETE))
118 return;
119
120 if (snd_pcm_running(substream)) {
121 snd_pcm_period_elapsed(substream);
122
123 spin_lock(&prtd->lock);
124 davinci_pcm_enqueue_dma(substream);
125 spin_unlock(&prtd->lock);
126 }
127}
128
129static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
130{
131 struct davinci_runtime_data *prtd = substream->runtime->private_data;
132 struct snd_soc_pcm_runtime *rtd = substream->private_data;
133 struct davinci_pcm_dma_params *dma_data = rtd->dai->cpu_dai->dma_data;
134 int tcc = TCC_ANY;
135 int ret;
136
137 if (!dma_data)
138 return -ENODEV;
139
140 prtd->params = dma_data;
141
142 /* Request master DMA channel */
143 ret = davinci_request_dma(prtd->params->channel, prtd->params->name,
144 davinci_pcm_dma_irq, substream,
145 &prtd->master_lch, &tcc, EVENTQ_0);
146 if (ret)
147 return ret;
148
149 /* Request slave DMA channel */
150 ret = davinci_request_dma(PARAM_ANY, "Link",
151 NULL, NULL, &prtd->slave_lch, &tcc, EVENTQ_0);
152 if (ret) {
153 davinci_free_dma(prtd->master_lch);
154 return ret;
155 }
156
157 /* Link slave DMA channel in loopback */
158 davinci_dma_link_lch(prtd->slave_lch, prtd->slave_lch);
159
160 return 0;
161}
162
163static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
164{
165 struct davinci_runtime_data *prtd = substream->runtime->private_data;
166 int ret = 0;
167
168 spin_lock(&prtd->lock);
169
170 switch (cmd) {
171 case SNDRV_PCM_TRIGGER_START:
172 case SNDRV_PCM_TRIGGER_RESUME:
173 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
174 davinci_start_dma(prtd->master_lch);
175 break;
176 case SNDRV_PCM_TRIGGER_STOP:
177 case SNDRV_PCM_TRIGGER_SUSPEND:
178 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
179 davinci_stop_dma(prtd->master_lch);
180 break;
181 default:
182 ret = -EINVAL;
183 break;
184 }
185
186 spin_unlock(&prtd->lock);
187
188 return ret;
189}
190
191static int davinci_pcm_prepare(struct snd_pcm_substream *substream)
192{
193 struct davinci_runtime_data *prtd = substream->runtime->private_data;
194 struct paramentry_descriptor temp;
195
196 prtd->period = 0;
197 davinci_pcm_enqueue_dma(substream);
198
199 /* Get slave channel dma params for master channel startup */
200 davinci_get_dma_params(prtd->slave_lch, &temp);
201 davinci_set_dma_params(prtd->master_lch, &temp);
202
203 return 0;
204}
205
206static snd_pcm_uframes_t
207davinci_pcm_pointer(struct snd_pcm_substream *substream)
208{
209 struct snd_pcm_runtime *runtime = substream->runtime;
210 struct davinci_runtime_data *prtd = runtime->private_data;
211 unsigned int offset;
212 dma_addr_t count;
213 dma_addr_t src, dst;
214
215 spin_lock(&prtd->lock);
216
217 davinci_dma_getposition(prtd->master_lch, &src, &dst);
218 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
219 count = src - runtime->dma_addr;
220 else
221 count = dst - runtime->dma_addr;;
222
223 spin_unlock(&prtd->lock);
224
225 offset = bytes_to_frames(runtime, count);
226 if (offset >= runtime->buffer_size)
227 offset = 0;
228
229 return offset;
230}
231
232static int davinci_pcm_open(struct snd_pcm_substream *substream)
233{
234 struct snd_pcm_runtime *runtime = substream->runtime;
235 struct davinci_runtime_data *prtd;
236 int ret = 0;
237
238 snd_soc_set_runtime_hwparams(substream, &davinci_pcm_hardware);
239
240 prtd = kzalloc(sizeof(struct davinci_runtime_data), GFP_KERNEL);
241 if (prtd == NULL)
242 return -ENOMEM;
243
244 spin_lock_init(&prtd->lock);
245
246 runtime->private_data = prtd;
247
248 ret = davinci_pcm_dma_request(substream);
249 if (ret) {
250 printk(KERN_ERR "davinci_pcm: Failed to get dma channels\n");
251 kfree(prtd);
252 }
253
254 return ret;
255}
256
257static int davinci_pcm_close(struct snd_pcm_substream *substream)
258{
259 struct snd_pcm_runtime *runtime = substream->runtime;
260 struct davinci_runtime_data *prtd = runtime->private_data;
261
262 davinci_dma_unlink_lch(prtd->slave_lch, prtd->slave_lch);
263
264 davinci_free_dma(prtd->slave_lch);
265 davinci_free_dma(prtd->master_lch);
266
267 kfree(prtd);
268
269 return 0;
270}
271
272static int davinci_pcm_hw_params(struct snd_pcm_substream *substream,
273 struct snd_pcm_hw_params *hw_params)
274{
275 return snd_pcm_lib_malloc_pages(substream,
276 params_buffer_bytes(hw_params));
277}
278
279static int davinci_pcm_hw_free(struct snd_pcm_substream *substream)
280{
281 return snd_pcm_lib_free_pages(substream);
282}
283
284static int davinci_pcm_mmap(struct snd_pcm_substream *substream,
285 struct vm_area_struct *vma)
286{
287 struct snd_pcm_runtime *runtime = substream->runtime;
288
289 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
290 runtime->dma_area,
291 runtime->dma_addr,
292 runtime->dma_bytes);
293}
294
295struct snd_pcm_ops davinci_pcm_ops = {
296 .open = davinci_pcm_open,
297 .close = davinci_pcm_close,
298 .ioctl = snd_pcm_lib_ioctl,
299 .hw_params = davinci_pcm_hw_params,
300 .hw_free = davinci_pcm_hw_free,
301 .prepare = davinci_pcm_prepare,
302 .trigger = davinci_pcm_trigger,
303 .pointer = davinci_pcm_pointer,
304 .mmap = davinci_pcm_mmap,
305};
306
307static int davinci_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
308{
309 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
310 struct snd_dma_buffer *buf = &substream->dma_buffer;
311 size_t size = davinci_pcm_hardware.buffer_bytes_max;
312
313 buf->dev.type = SNDRV_DMA_TYPE_DEV;
314 buf->dev.dev = pcm->card->dev;
315 buf->private_data = NULL;
316 buf->area = dma_alloc_writecombine(pcm->card->dev, size,
317 &buf->addr, GFP_KERNEL);
318
319 DPRINTK("preallocate_dma_buffer: area=%p, addr=%p, size=%d\n",
320 (void *) buf->area, (void *) buf->addr, size);
321
322 if (!buf->area)
323 return -ENOMEM;
324
325 buf->bytes = size;
326 return 0;
327}
328
329static void davinci_pcm_free(struct snd_pcm *pcm)
330{
331 struct snd_pcm_substream *substream;
332 struct snd_dma_buffer *buf;
333 int stream;
334
335 for (stream = 0; stream < 2; stream++) {
336 substream = pcm->streams[stream].substream;
337 if (!substream)
338 continue;
339
340 buf = &substream->dma_buffer;
341 if (!buf->area)
342 continue;
343
344 dma_free_writecombine(pcm->card->dev, buf->bytes,
345 buf->area, buf->addr);
346 buf->area = NULL;
347 }
348}
349
350static u64 davinci_pcm_dmamask = 0xffffffff;
351
352static int davinci_pcm_new(struct snd_card *card,
353 struct snd_soc_codec_dai *dai, struct snd_pcm *pcm)
354{
355 int ret;
356
357 if (!card->dev->dma_mask)
358 card->dev->dma_mask = &davinci_pcm_dmamask;
359 if (!card->dev->coherent_dma_mask)
360 card->dev->coherent_dma_mask = 0xffffffff;
361
362 if (dai->playback.channels_min) {
363 ret = davinci_pcm_preallocate_dma_buffer(pcm,
364 SNDRV_PCM_STREAM_PLAYBACK);
365 if (ret)
366 return ret;
367 }
368
369 if (dai->capture.channels_min) {
370 ret = davinci_pcm_preallocate_dma_buffer(pcm,
371 SNDRV_PCM_STREAM_CAPTURE);
372 if (ret)
373 return ret;
374 }
375
376 return 0;
377}
378
379struct snd_soc_platform davinci_soc_platform = {
380 .name = "davinci-audio",
381 .pcm_ops = &davinci_pcm_ops,
382 .pcm_new = davinci_pcm_new,
383 .pcm_free = davinci_pcm_free,
384};
385EXPORT_SYMBOL_GPL(davinci_soc_platform);
386
387MODULE_AUTHOR("Vladimir Barinov");
388MODULE_DESCRIPTION("TI DAVINCI PCM DMA module");
389MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-pcm.h b/sound/soc/davinci/davinci-pcm.h
new file mode 100644
index 000000000000..8d6a45e75a6e
--- /dev/null
+++ b/sound/soc/davinci/davinci-pcm.h
@@ -0,0 +1,29 @@
1/*
2 * ALSA PCM interface for the TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _DAVINCI_PCM_H
13#define _DAVINCI_PCM_H
14
15struct davinci_pcm_dma_params {
16 char *name; /* stream identifier */
17 int channel; /* sync dma channel ID */
18 dma_addr_t dma_addr; /* device physical address for DMA */
19 unsigned int data_type; /* xfer data type */
20};
21
22struct evm_snd_platform_data {
23 int tx_dma_ch;
24 int rx_dma_ch;
25};
26
27extern struct snd_soc_platform davinci_soc_platform;
28
29#endif
diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index 652514fc8142..78de7168d2ba 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -20,7 +20,6 @@
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22 22
23#include <sound/driver.h>
24#include <sound/core.h> 23#include <sound/core.h>
25#include <sound/pcm.h> 24#include <sound/pcm.h>
26#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 145ad13d52d1..b2a11b0d2e4c 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -15,7 +15,6 @@
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17 17
18#include <sound/driver.h>
19#include <sound/core.h> 18#include <sound/core.h>
20#include <sound/pcm.h> 19#include <sound/pcm.h>
21#include <sound/pcm_params.h> 20#include <sound/pcm_params.h>
diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c
index 1a70a6ac98ce..7f32a1167572 100644
--- a/sound/soc/pxa/corgi.c
+++ b/sound/soc/pxa/corgi.c
@@ -297,21 +297,19 @@ static int corgi_wm8731_init(struct snd_soc_codec *codec)
297 /* Add corgi specific controls */ 297 /* Add corgi specific controls */
298 for (i = 0; i < ARRAY_SIZE(wm8731_corgi_controls); i++) { 298 for (i = 0; i < ARRAY_SIZE(wm8731_corgi_controls); i++) {
299 err = snd_ctl_add(codec->card, 299 err = snd_ctl_add(codec->card,
300 snd_soc_cnew(&wm8731_corgi_controls[i],codec, NULL)); 300 snd_soc_cnew(&wm8731_corgi_controls[i], codec, NULL));
301 if (err < 0) 301 if (err < 0)
302 return err; 302 return err;
303 } 303 }
304 304
305 /* Add corgi specific widgets */ 305 /* Add corgi specific widgets */
306 for(i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) { 306 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
307 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]); 307 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
308 }
309 308
310 /* Set up corgi specific audio path audio_map */ 309 /* Set up corgi specific audio path audio_map */
311 for(i = 0; audio_map[i][0] != NULL; i++) { 310 for (i = 0; audio_map[i][0] != NULL; i++)
312 snd_soc_dapm_connect_input(codec, audio_map[i][0], 311 snd_soc_dapm_connect_input(codec, audio_map[i][0],
313 audio_map[i][1], audio_map[i][2]); 312 audio_map[i][1], audio_map[i][2]);
314 }
315 313
316 snd_soc_dapm_sync_endpoints(codec); 314 snd_soc_dapm_sync_endpoints(codec);
317 return 0; 315 return 0;
@@ -353,7 +351,8 @@ static int __init corgi_init(void)
353{ 351{
354 int ret; 352 int ret;
355 353
356 if (!(machine_is_corgi() || machine_is_shepherd() || machine_is_husky())) 354 if (!(machine_is_corgi() || machine_is_shepherd() ||
355 machine_is_husky()))
357 return -ENODEV; 356 return -ENODEV;
358 357
359 corgi_snd_device = platform_device_alloc("soc-audio", -1); 358 corgi_snd_device = platform_device_alloc("soc-audio", -1);
diff --git a/sound/soc/pxa/poodle.c b/sound/soc/pxa/poodle.c
index 4fbf8bba9627..7e830b218943 100644
--- a/sound/soc/pxa/poodle.c
+++ b/sound/soc/pxa/poodle.c
@@ -257,21 +257,19 @@ static int poodle_wm8731_init(struct snd_soc_codec *codec)
257 /* Add poodle specific controls */ 257 /* Add poodle specific controls */
258 for (i = 0; i < ARRAY_SIZE(wm8731_poodle_controls); i++) { 258 for (i = 0; i < ARRAY_SIZE(wm8731_poodle_controls); i++) {
259 err = snd_ctl_add(codec->card, 259 err = snd_ctl_add(codec->card,
260 snd_soc_cnew(&wm8731_poodle_controls[i],codec, NULL)); 260 snd_soc_cnew(&wm8731_poodle_controls[i], codec, NULL));
261 if (err < 0) 261 if (err < 0)
262 return err; 262 return err;
263 } 263 }
264 264
265 /* Add poodle specific widgets */ 265 /* Add poodle specific widgets */
266 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) { 266 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
267 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]); 267 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
268 }
269 268
270 /* Set up poodle specific audio path audio_map */ 269 /* Set up poodle specific audio path audio_map */
271 for (i = 0; audio_map[i][0] != NULL; i++) { 270 for (i = 0; audio_map[i][0] != NULL; i++)
272 snd_soc_dapm_connect_input(codec, audio_map[i][0], 271 snd_soc_dapm_connect_input(codec, audio_map[i][0],
273 audio_map[i][1], audio_map[i][2]); 272 audio_map[i][1], audio_map[i][2]);
274 }
275 273
276 snd_soc_dapm_sync_endpoints(codec); 274 snd_soc_dapm_sync_endpoints(codec);
277 return 0; 275 return 0;
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
index e17379998802..97ec2d90547c 100644
--- a/sound/soc/pxa/pxa2xx-ac97.c
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -61,7 +61,7 @@ static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97,
61 mutex_lock(&car_mutex); 61 mutex_lock(&car_mutex);
62 62
63 /* set up primary or secondary codec/modem space */ 63 /* set up primary or secondary codec/modem space */
64#ifdef CONFIG_PXA27x 64#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
65 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE; 65 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
66#else 66#else
67 if (reg == AC97_GPIO_STATUS) 67 if (reg == AC97_GPIO_STATUS)
@@ -87,7 +87,7 @@ static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97,
87 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1); 87 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1);
88 if (!((GSR | gsr_bits) & GSR_SDONE)) { 88 if (!((GSR | gsr_bits) & GSR_SDONE)) {
89 printk(KERN_ERR "%s: read error (ac97_reg=%x GSR=%#lx)\n", 89 printk(KERN_ERR "%s: read error (ac97_reg=%x GSR=%#lx)\n",
90 __FUNCTION__, reg, GSR | gsr_bits); 90 __func__, reg, GSR | gsr_bits);
91 val = -1; 91 val = -1;
92 goto out; 92 goto out;
93 } 93 }
@@ -111,7 +111,7 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
111 mutex_lock(&car_mutex); 111 mutex_lock(&car_mutex);
112 112
113 /* set up primary or secondary codec/modem space */ 113 /* set up primary or secondary codec/modem space */
114#ifdef CONFIG_PXA27x 114#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
115 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE; 115 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
116#else 116#else
117 if (reg == AC97_GPIO_STATUS) 117 if (reg == AC97_GPIO_STATUS)
@@ -127,13 +127,16 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
127 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1); 127 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1);
128 if (!((GSR | gsr_bits) & GSR_CDONE)) 128 if (!((GSR | gsr_bits) & GSR_CDONE))
129 printk(KERN_ERR "%s: write error (ac97_reg=%x GSR=%#lx)\n", 129 printk(KERN_ERR "%s: write error (ac97_reg=%x GSR=%#lx)\n",
130 __FUNCTION__, reg, GSR | gsr_bits); 130 __func__, reg, GSR | gsr_bits);
131 131
132 mutex_unlock(&car_mutex); 132 mutex_unlock(&car_mutex);
133} 133}
134 134
135static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97) 135static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
136{ 136{
137#ifdef CONFIG_PXA3xx
138 int timeout = 100;
139#endif
137 gsr_bits = 0; 140 gsr_bits = 0;
138 141
139#ifdef CONFIG_PXA27x 142#ifdef CONFIG_PXA27x
@@ -144,6 +147,11 @@ static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
144 GCR |= GCR_WARM_RST; 147 GCR |= GCR_WARM_RST;
145 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 148 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
146 udelay(500); 149 udelay(500);
150#elif defined(CONFIG_PXA3xx)
151 /* Can't use interrupts */
152 GCR |= GCR_WARM_RST;
153 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
154 mdelay(1);
147#else 155#else
148 GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN; 156 GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN;
149 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1); 157 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
@@ -151,7 +159,7 @@ static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
151 159
152 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) 160 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
153 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n", 161 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
154 __FUNCTION__, gsr_bits); 162 __func__, gsr_bits);
155 163
156 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 164 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
157 GCR |= GCR_SDONE_IE|GCR_CDONE_IE; 165 GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
@@ -159,6 +167,16 @@ static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
159 167
160static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97) 168static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
161{ 169{
170#ifdef CONFIG_PXA3xx
171 int timeout = 1000;
172
173 /* Hold CLKBPB for 100us */
174 GCR = 0;
175 GCR = GCR_CLKBPB;
176 udelay(100);
177 GCR = 0;
178#endif
179
162 GCR &= GCR_COLD_RST; /* clear everything but nCRST */ 180 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
163 GCR &= ~GCR_COLD_RST; /* then assert nCRST */ 181 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
164 182
@@ -170,6 +188,13 @@ static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
170 clk_disable(ac97conf_clk); 188 clk_disable(ac97conf_clk);
171 GCR = GCR_COLD_RST; 189 GCR = GCR_COLD_RST;
172 udelay(50); 190 udelay(50);
191#elif defined(CONFIG_PXA3xx)
192 /* Can't use interrupts on PXA3xx */
193 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
194
195 GCR = GCR_WARM_RST | GCR_COLD_RST;
196 while (!(GSR & (GSR_PCR | GSR_SCR)) && timeout--)
197 mdelay(10);
173#else 198#else
174 GCR = GCR_COLD_RST; 199 GCR = GCR_COLD_RST;
175 GCR |= GCR_CDONE_IE|GCR_SDONE_IE; 200 GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
@@ -178,7 +203,7 @@ static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
178 203
179 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) 204 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
180 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n", 205 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
181 __FUNCTION__, gsr_bits); 206 __func__, gsr_bits);
182 207
183 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 208 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
184 GCR |= GCR_SDONE_IE|GCR_CDONE_IE; 209 GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
diff --git a/sound/soc/pxa/pxa2xx-pcm.c b/sound/soc/pxa/pxa2xx-pcm.c
index daeaa4c8b876..01ad7bf716b7 100644
--- a/sound/soc/pxa/pxa2xx-pcm.c
+++ b/sound/soc/pxa/pxa2xx-pcm.c
@@ -64,8 +64,8 @@ static void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id)
64 if (dcsr & DCSR_ENDINTR) { 64 if (dcsr & DCSR_ENDINTR) {
65 snd_pcm_period_elapsed(substream); 65 snd_pcm_period_elapsed(substream);
66 } else { 66 } else {
67 printk( KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n", 67 printk(KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
68 prtd->params->name, dma_ch, dcsr ); 68 prtd->params->name, dma_ch, dcsr);
69 } 69 }
70} 70}
71 71
@@ -84,8 +84,8 @@ static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
84 84
85 /* return if this is a bufferless transfer e.g. 85 /* return if this is a bufferless transfer e.g.
86 * codec <--> BT codec or GSM modem -- lg FIXME */ 86 * codec <--> BT codec or GSM modem -- lg FIXME */
87 if (!dma) 87 if (!dma)
88 return 0; 88 return 0;
89 89
90 /* this may get called several times by oss emulation 90 /* this may get called several times by oss emulation
91 * with different params */ 91 * with different params */
@@ -363,7 +363,6 @@ struct snd_soc_platform pxa2xx_soc_platform = {
363 .pcm_new = pxa2xx_pcm_new, 363 .pcm_new = pxa2xx_pcm_new,
364 .pcm_free = pxa2xx_pcm_free_dma_buffers, 364 .pcm_free = pxa2xx_pcm_free_dma_buffers,
365}; 365};
366
367EXPORT_SYMBOL_GPL(pxa2xx_soc_platform); 366EXPORT_SYMBOL_GPL(pxa2xx_soc_platform);
368 367
369MODULE_AUTHOR("Nicolas Pitre"); 368MODULE_AUTHOR("Nicolas Pitre");
diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c
index ecca39033fcc..d8b8372db00e 100644
--- a/sound/soc/pxa/spitz.c
+++ b/sound/soc/pxa/spitz.c
@@ -313,15 +313,13 @@ static int spitz_wm8750_init(struct snd_soc_codec *codec)
313 } 313 }
314 314
315 /* Add spitz specific widgets */ 315 /* Add spitz specific widgets */
316 for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++) { 316 for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++)
317 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]); 317 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
318 }
319 318
320 /* Set up spitz specific audio path audio_map */ 319 /* Set up spitz specific audio path audio_map */
321 for (i = 0; audio_map[i][0] != NULL; i++) { 320 for (i = 0; audio_map[i][0] != NULL; i++)
322 snd_soc_dapm_connect_input(codec, audio_map[i][0], 321 snd_soc_dapm_connect_input(codec, audio_map[i][0],
323 audio_map[i][1], audio_map[i][2]); 322 audio_map[i][1], audio_map[i][2]);
324 }
325 323
326 snd_soc_dapm_sync_endpoints(codec); 324 snd_soc_dapm_sync_endpoints(codec);
327 return 0; 325 return 0;
diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c
index 6ee115ceb011..962cc20b1af5 100644
--- a/sound/soc/s3c24xx/neo1973_wm8753.c
+++ b/sound/soc/s3c24xx/neo1973_wm8753.c
@@ -659,6 +659,7 @@ static int __init neo1973_init(void)
659 659
660static void __exit neo1973_exit(void) 660static void __exit neo1973_exit(void)
661{ 661{
662 i2c_del_driver(&lm4857_i2c_driver);
662 platform_device_unregister(neo1973_snd_device); 663 platform_device_unregister(neo1973_snd_device);
663} 664}
664 665
diff --git a/sound/soc/s3c24xx/s3c24xx-i2s.c b/sound/soc/s3c24xx/s3c24xx-i2s.c
index 0a3c630951be..4ebcd6a8bf28 100644
--- a/sound/soc/s3c24xx/s3c24xx-i2s.c
+++ b/sound/soc/s3c24xx/s3c24xx-i2s.c
@@ -25,6 +25,7 @@
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/clk.h> 26#include <linux/clk.h>
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/io.h>
28#include <sound/core.h> 29#include <sound/core.h>
29#include <sound/pcm.h> 30#include <sound/pcm.h>
30#include <sound/pcm_params.h> 31#include <sound/pcm_params.h>
@@ -32,7 +33,6 @@
32#include <sound/soc.h> 33#include <sound/soc.h>
33 34
34#include <asm/hardware.h> 35#include <asm/hardware.h>
35#include <asm/io.h>
36#include <asm/arch/regs-gpio.h> 36#include <asm/arch/regs-gpio.h>
37#include <asm/arch/regs-clock.h> 37#include <asm/arch/regs-clock.h>
38#include <asm/arch/audio.h> 38#include <asm/arch/audio.h>
@@ -46,7 +46,7 @@
46 46
47#define S3C24XX_I2S_DEBUG 0 47#define S3C24XX_I2S_DEBUG 0
48#if S3C24XX_I2S_DEBUG 48#if S3C24XX_I2S_DEBUG
49#define DBG(x...) printk(KERN_DEBUG x) 49#define DBG(x...) printk(KERN_DEBUG "s3c24xx-i2s: " x)
50#else 50#else
51#define DBG(x...) 51#define DBG(x...)
52#endif 52#endif
@@ -89,7 +89,7 @@ static void s3c24xx_snd_txctrl(int on)
89 u32 iiscon; 89 u32 iiscon;
90 u32 iismod; 90 u32 iismod;
91 91
92 DBG("Entered %s\n", __FUNCTION__); 92 DBG("Entered %s\n", __func__);
93 93
94 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 94 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
95 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 95 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -134,7 +134,7 @@ static void s3c24xx_snd_rxctrl(int on)
134 u32 iiscon; 134 u32 iiscon;
135 u32 iismod; 135 u32 iismod;
136 136
137 DBG("Entered %s\n", __FUNCTION__); 137 DBG("Entered %s\n", __func__);
138 138
139 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 139 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
140 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 140 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -159,10 +159,10 @@ static void s3c24xx_snd_rxctrl(int on)
159 * DMA engine will simply freeze randomly. 159 * DMA engine will simply freeze randomly.
160 */ 160 */
161 161
162 iisfcon &= ~S3C2410_IISFCON_RXENABLE; 162 iisfcon &= ~S3C2410_IISFCON_RXENABLE;
163 iisfcon &= ~S3C2410_IISFCON_RXDMA; 163 iisfcon &= ~S3C2410_IISFCON_RXDMA;
164 iiscon |= S3C2410_IISCON_RXIDLE; 164 iiscon |= S3C2410_IISCON_RXIDLE;
165 iiscon &= ~S3C2410_IISCON_RXDMAEN; 165 iiscon &= ~S3C2410_IISCON_RXDMAEN;
166 iismod &= ~S3C2410_IISMOD_RXMODE; 166 iismod &= ~S3C2410_IISMOD_RXMODE;
167 167
168 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); 168 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
@@ -182,7 +182,7 @@ static int s3c24xx_snd_lrsync(void)
182 u32 iiscon; 182 u32 iiscon;
183 unsigned long timeout = jiffies + msecs_to_jiffies(5); 183 unsigned long timeout = jiffies + msecs_to_jiffies(5);
184 184
185 DBG("Entered %s\n", __FUNCTION__); 185 DBG("Entered %s\n", __func__);
186 186
187 while (1) { 187 while (1) {
188 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 188 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -201,7 +201,7 @@ static int s3c24xx_snd_lrsync(void)
201 */ 201 */
202static inline int s3c24xx_snd_is_clkmaster(void) 202static inline int s3c24xx_snd_is_clkmaster(void)
203{ 203{
204 DBG("Entered %s\n", __FUNCTION__); 204 DBG("Entered %s\n", __func__);
205 205
206 return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1; 206 return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1;
207} 207}
@@ -214,7 +214,7 @@ static int s3c24xx_i2s_set_fmt(struct snd_soc_cpu_dai *cpu_dai,
214{ 214{
215 u32 iismod; 215 u32 iismod;
216 216
217 DBG("Entered %s\n", __FUNCTION__); 217 DBG("Entered %s\n", __func__);
218 218
219 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 219 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
220 DBG("hw_params r: IISMOD: %lx \n", iismod); 220 DBG("hw_params r: IISMOD: %lx \n", iismod);
@@ -250,7 +250,7 @@ static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream,
250 struct snd_soc_pcm_runtime *rtd = substream->private_data; 250 struct snd_soc_pcm_runtime *rtd = substream->private_data;
251 u32 iismod; 251 u32 iismod;
252 252
253 DBG("Entered %s\n", __FUNCTION__); 253 DBG("Entered %s\n", __func__);
254 254
255 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 255 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
256 rtd->dai->cpu_dai->dma_data = &s3c24xx_i2s_pcm_stereo_out; 256 rtd->dai->cpu_dai->dma_data = &s3c24xx_i2s_pcm_stereo_out;
@@ -278,7 +278,7 @@ static int s3c24xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
278{ 278{
279 int ret = 0; 279 int ret = 0;
280 280
281 DBG("Entered %s\n", __FUNCTION__); 281 DBG("Entered %s\n", __func__);
282 282
283 switch (cmd) { 283 switch (cmd) {
284 case SNDRV_PCM_TRIGGER_START: 284 case SNDRV_PCM_TRIGGER_START:
@@ -320,7 +320,7 @@ static int s3c24xx_i2s_set_sysclk(struct snd_soc_cpu_dai *cpu_dai,
320{ 320{
321 u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 321 u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
322 322
323 DBG("Entered %s\n", __FUNCTION__); 323 DBG("Entered %s\n", __func__);
324 324
325 iismod &= ~S3C2440_IISMOD_MPLL; 325 iismod &= ~S3C2440_IISMOD_MPLL;
326 326
@@ -346,7 +346,7 @@ static int s3c24xx_i2s_set_clkdiv(struct snd_soc_cpu_dai *cpu_dai,
346{ 346{
347 u32 reg; 347 u32 reg;
348 348
349 DBG("Entered %s\n", __FUNCTION__); 349 DBG("Entered %s\n", __func__);
350 350
351 switch (div_id) { 351 switch (div_id) {
352 case S3C24XX_DIV_BCLK: 352 case S3C24XX_DIV_BCLK:
@@ -381,13 +381,13 @@ EXPORT_SYMBOL_GPL(s3c24xx_i2s_get_clockrate);
381 381
382static int s3c24xx_i2s_probe(struct platform_device *pdev) 382static int s3c24xx_i2s_probe(struct platform_device *pdev)
383{ 383{
384 DBG("Entered %s\n", __FUNCTION__); 384 DBG("Entered %s\n", __func__);
385 385
386 s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100); 386 s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100);
387 if (s3c24xx_i2s.regs == NULL) 387 if (s3c24xx_i2s.regs == NULL)
388 return -ENXIO; 388 return -ENXIO;
389 389
390 s3c24xx_i2s.iis_clk=clk_get(&pdev->dev, "iis"); 390 s3c24xx_i2s.iis_clk = clk_get(&pdev->dev, "iis");
391 if (s3c24xx_i2s.iis_clk == NULL) { 391 if (s3c24xx_i2s.iis_clk == NULL) {
392 DBG("failed to get iis_clock\n"); 392 DBG("failed to get iis_clock\n");
393 iounmap(s3c24xx_i2s.regs); 393 iounmap(s3c24xx_i2s.regs);
@@ -411,9 +411,11 @@ static int s3c24xx_i2s_probe(struct platform_device *pdev)
411} 411}
412 412
413#ifdef CONFIG_PM 413#ifdef CONFIG_PM
414int s3c24xx_i2s_suspend(struct platform_device *pdev, 414static int s3c24xx_i2s_suspend(struct platform_device *pdev,
415 struct snd_soc_cpu_dai *cpu_dai) 415 struct snd_soc_cpu_dai *cpu_dai)
416{ 416{
417 DBG("Entered %s\n", __func__);
418
417 s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 419 s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
418 s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 420 s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
419 s3c24xx_i2s.iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 421 s3c24xx_i2s.iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
@@ -424,9 +426,10 @@ int s3c24xx_i2s_suspend(struct platform_device *pdev,
424 return 0; 426 return 0;
425} 427}
426 428
427int s3c24xx_i2s_resume(struct platform_device *pdev, 429static int s3c24xx_i2s_resume(struct platform_device *pdev,
428 struct snd_soc_cpu_dai *cpu_dai) 430 struct snd_soc_cpu_dai *cpu_dai)
429{ 431{
432 DBG("Entered %s\n", __func__);
430 clk_enable(s3c24xx_i2s.iis_clk); 433 clk_enable(s3c24xx_i2s.iis_clk);
431 434
432 writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); 435 writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
diff --git a/sound/soc/s3c24xx/s3c24xx-pcm.c b/sound/soc/s3c24xx/s3c24xx-pcm.c
index 29a6c82f873a..49580fb481d5 100644
--- a/sound/soc/s3c24xx/s3c24xx-pcm.c
+++ b/sound/soc/s3c24xx/s3c24xx-pcm.c
@@ -39,7 +39,7 @@
39 39
40#define S3C24XX_PCM_DEBUG 0 40#define S3C24XX_PCM_DEBUG 0
41#if S3C24XX_PCM_DEBUG 41#if S3C24XX_PCM_DEBUG
42#define DBG(x...) printk(KERN_DEBUG x) 42#define DBG(x...) printk(KERN_DEBUG "s3c24xx-pcm: " x)
43#else 43#else
44#define DBG(x...) 44#define DBG(x...)
45#endif 45#endif
@@ -88,7 +88,7 @@ static void s3c24xx_pcm_enqueue(struct snd_pcm_substream *substream)
88 dma_addr_t pos = prtd->dma_pos; 88 dma_addr_t pos = prtd->dma_pos;
89 int ret; 89 int ret;
90 90
91 DBG("Entered %s\n", __FUNCTION__); 91 DBG("Entered %s\n", __func__);
92 92
93 while (prtd->dma_loaded < prtd->dma_limit) { 93 while (prtd->dma_loaded < prtd->dma_limit) {
94 unsigned long len = prtd->dma_period; 94 unsigned long len = prtd->dma_period;
@@ -98,7 +98,7 @@ static void s3c24xx_pcm_enqueue(struct snd_pcm_substream *substream)
98 if ((pos + len) > prtd->dma_end) { 98 if ((pos + len) > prtd->dma_end) {
99 len = prtd->dma_end - pos; 99 len = prtd->dma_end - pos;
100 DBG(KERN_DEBUG "%s: corrected dma len %ld\n", 100 DBG(KERN_DEBUG "%s: corrected dma len %ld\n",
101 __FUNCTION__, len); 101 __func__, len);
102 } 102 }
103 103
104 ret = s3c2410_dma_enqueue(prtd->params->channel, 104 ret = s3c2410_dma_enqueue(prtd->params->channel,
@@ -123,7 +123,7 @@ static void s3c24xx_audio_buffdone(struct s3c2410_dma_chan *channel,
123 struct snd_pcm_substream *substream = dev_id; 123 struct snd_pcm_substream *substream = dev_id;
124 struct s3c24xx_runtime_data *prtd; 124 struct s3c24xx_runtime_data *prtd;
125 125
126 DBG("Entered %s\n", __FUNCTION__); 126 DBG("Entered %s\n", __func__);
127 127
128 if (result == S3C2410_RES_ABORT || result == S3C2410_RES_ERR) 128 if (result == S3C2410_RES_ABORT || result == S3C2410_RES_ERR)
129 return; 129 return;
@@ -152,7 +152,7 @@ static int s3c24xx_pcm_hw_params(struct snd_pcm_substream *substream,
152 unsigned long totbytes = params_buffer_bytes(params); 152 unsigned long totbytes = params_buffer_bytes(params);
153 int ret=0; 153 int ret=0;
154 154
155 DBG("Entered %s\n", __FUNCTION__); 155 DBG("Entered %s\n", __func__);
156 156
157 /* return if this is a bufferless transfer e.g. 157 /* return if this is a bufferless transfer e.g.
158 * codec <--> BT codec or GSM modem -- lg FIXME */ 158 * codec <--> BT codec or GSM modem -- lg FIXME */
@@ -200,7 +200,7 @@ static int s3c24xx_pcm_hw_free(struct snd_pcm_substream *substream)
200{ 200{
201 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 201 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
202 202
203 DBG("Entered %s\n", __FUNCTION__); 203 DBG("Entered %s\n", __func__);
204 204
205 /* TODO - do we need to ensure DMA flushed */ 205 /* TODO - do we need to ensure DMA flushed */
206 snd_pcm_set_runtime_buffer(substream, NULL); 206 snd_pcm_set_runtime_buffer(substream, NULL);
@@ -218,7 +218,7 @@ static int s3c24xx_pcm_prepare(struct snd_pcm_substream *substream)
218 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 218 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
219 int ret = 0; 219 int ret = 0;
220 220
221 DBG("Entered %s\n", __FUNCTION__); 221 DBG("Entered %s\n", __func__);
222 222
223 /* return if this is a bufferless transfer e.g. 223 /* return if this is a bufferless transfer e.g.
224 * codec <--> BT codec or GSM modem -- lg FIXME */ 224 * codec <--> BT codec or GSM modem -- lg FIXME */
@@ -263,7 +263,7 @@ static int s3c24xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
263 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 263 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
264 int ret = 0; 264 int ret = 0;
265 265
266 DBG("Entered %s\n", __FUNCTION__); 266 DBG("Entered %s\n", __func__);
267 267
268 spin_lock(&prtd->lock); 268 spin_lock(&prtd->lock);
269 269
@@ -301,7 +301,7 @@ static snd_pcm_uframes_t
301 unsigned long res; 301 unsigned long res;
302 dma_addr_t src, dst; 302 dma_addr_t src, dst;
303 303
304 DBG("Entered %s\n", __FUNCTION__); 304 DBG("Entered %s\n", __func__);
305 305
306 spin_lock(&prtd->lock); 306 spin_lock(&prtd->lock);
307 s3c2410_dma_getposition(prtd->params->channel, &src, &dst); 307 s3c2410_dma_getposition(prtd->params->channel, &src, &dst);
@@ -334,7 +334,7 @@ static int s3c24xx_pcm_open(struct snd_pcm_substream *substream)
334 struct snd_pcm_runtime *runtime = substream->runtime; 334 struct snd_pcm_runtime *runtime = substream->runtime;
335 struct s3c24xx_runtime_data *prtd; 335 struct s3c24xx_runtime_data *prtd;
336 336
337 DBG("Entered %s\n", __FUNCTION__); 337 DBG("Entered %s\n", __func__);
338 338
339 snd_soc_set_runtime_hwparams(substream, &s3c24xx_pcm_hardware); 339 snd_soc_set_runtime_hwparams(substream, &s3c24xx_pcm_hardware);
340 340
@@ -353,7 +353,7 @@ static int s3c24xx_pcm_close(struct snd_pcm_substream *substream)
353 struct snd_pcm_runtime *runtime = substream->runtime; 353 struct snd_pcm_runtime *runtime = substream->runtime;
354 struct s3c24xx_runtime_data *prtd = runtime->private_data; 354 struct s3c24xx_runtime_data *prtd = runtime->private_data;
355 355
356 DBG("Entered %s\n", __FUNCTION__); 356 DBG("Entered %s\n", __func__);
357 357
358 if (prtd) 358 if (prtd)
359 kfree(prtd); 359 kfree(prtd);
@@ -368,7 +368,7 @@ static int s3c24xx_pcm_mmap(struct snd_pcm_substream *substream,
368{ 368{
369 struct snd_pcm_runtime *runtime = substream->runtime; 369 struct snd_pcm_runtime *runtime = substream->runtime;
370 370
371 DBG("Entered %s\n", __FUNCTION__); 371 DBG("Entered %s\n", __func__);
372 372
373 return dma_mmap_writecombine(substream->pcm->card->dev, vma, 373 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
374 runtime->dma_area, 374 runtime->dma_area,
@@ -394,7 +394,7 @@ static int s3c24xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
394 struct snd_dma_buffer *buf = &substream->dma_buffer; 394 struct snd_dma_buffer *buf = &substream->dma_buffer;
395 size_t size = s3c24xx_pcm_hardware.buffer_bytes_max; 395 size_t size = s3c24xx_pcm_hardware.buffer_bytes_max;
396 396
397 DBG("Entered %s\n", __FUNCTION__); 397 DBG("Entered %s\n", __func__);
398 398
399 buf->dev.type = SNDRV_DMA_TYPE_DEV; 399 buf->dev.type = SNDRV_DMA_TYPE_DEV;
400 buf->dev.dev = pcm->card->dev; 400 buf->dev.dev = pcm->card->dev;
@@ -413,7 +413,7 @@ static void s3c24xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
413 struct snd_dma_buffer *buf; 413 struct snd_dma_buffer *buf;
414 int stream; 414 int stream;
415 415
416 DBG("Entered %s\n", __FUNCTION__); 416 DBG("Entered %s\n", __func__);
417 417
418 for (stream = 0; stream < 2; stream++) { 418 for (stream = 0; stream < 2; stream++) {
419 substream = pcm->streams[stream].substream; 419 substream = pcm->streams[stream].substream;
@@ -437,7 +437,7 @@ static int s3c24xx_pcm_new(struct snd_card *card,
437{ 437{
438 int ret = 0; 438 int ret = 0;
439 439
440 DBG("Entered %s\n", __FUNCTION__); 440 DBG("Entered %s\n", __func__);
441 441
442 if (!card->dev->dma_mask) 442 if (!card->dev->dma_mask)
443 card->dev->dma_mask = &s3c24xx_pcm_dmamask; 443 card->dev->dma_mask = &s3c24xx_pcm_dmamask;
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig
index f03220d23e73..4c1e013381c9 100644
--- a/sound/soc/sh/Kconfig
+++ b/sound/soc/sh/Kconfig
@@ -1,4 +1,5 @@
1menu "SoC Audio support for SuperH" 1menu "SoC Audio support for SuperH"
2 depends on SUPERH
2 3
3config SND_SOC_PCM_SH7760 4config SND_SOC_PCM_SH7760
4 tristate "SoC Audio support for Renesas SH7760" 5 tristate "SoC Audio support for Renesas SH7760"
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 9eb5479787c1..e148db940cfc 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -839,6 +839,7 @@ static int soc_remove(struct platform_device *pdev)
839static struct platform_driver soc_driver = { 839static struct platform_driver soc_driver = {
840 .driver = { 840 .driver = {
841 .name = "soc-audio", 841 .name = "soc-audio",
842 .owner = THIS_MODULE,
842 }, 843 },
843 .probe = soc_probe, 844 .probe = soc_probe,
844 .remove = soc_remove, 845 .remove = soc_remove,
@@ -1601,3 +1602,4 @@ module_exit(snd_soc_exit);
1601MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); 1602MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
1602MODULE_DESCRIPTION("ALSA SoC Core"); 1603MODULE_DESCRIPTION("ALSA SoC Core");
1603MODULE_LICENSE("GPL"); 1604MODULE_LICENSE("GPL");
1605MODULE_ALIAS("platform:soc-audio");
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 620d7ea3c15f..af3326c63504 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -226,7 +226,7 @@ static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
226 snd_soc_write(codec, widget->reg, new); 226 snd_soc_write(codec, widget->reg, new);
227 pop_wait(POP_TIME); 227 pop_wait(POP_TIME);
228 } 228 }
229 dbg("reg old %x new %x change %d\n", old, new, change); 229 dbg("reg %x old %x new %x change %d\n", widget->reg, old, new, change);
230 return change; 230 return change;
231} 231}
232 232
@@ -1288,7 +1288,7 @@ int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
1288 mutex_unlock(&codec->mutex); 1288 mutex_unlock(&codec->mutex);
1289 1289
1290 dapm_power_widgets(codec, event); 1290 dapm_power_widgets(codec, event);
1291 dump_dapm(codec, __FUNCTION__); 1291 dump_dapm(codec, __func__);
1292 return 0; 1292 return 0;
1293} 1293}
1294EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event); 1294EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
@@ -1334,10 +1334,11 @@ int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec,
1334 list_for_each_entry(w, &codec->dapm_widgets, list) { 1334 list_for_each_entry(w, &codec->dapm_widgets, list) {
1335 if (!strcmp(w->name, endpoint)) { 1335 if (!strcmp(w->name, endpoint)) {
1336 w->connected = status; 1336 w->connected = status;
1337 return 0;
1337 } 1338 }
1338 } 1339 }
1339 1340
1340 return 0; 1341 return -ENODEV;
1341} 1342}
1342EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint); 1343EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint);
1343 1344
diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
index 89d6e9c35140..09802e8a6fb8 100644
--- a/sound/spi/at73c213.c
+++ b/sound/spi/at73c213.c
@@ -118,7 +118,7 @@ static struct snd_pcm_hardware snd_at73c213_playback_hw = {
118 .rates = SNDRV_PCM_RATE_CONTINUOUS, 118 .rates = SNDRV_PCM_RATE_CONTINUOUS,
119 .rate_min = 8000, /* Replaced by chip->bitrate later. */ 119 .rate_min = 8000, /* Replaced by chip->bitrate later. */
120 .rate_max = 50000, /* Replaced by chip->bitrate later. */ 120 .rate_max = 50000, /* Replaced by chip->bitrate later. */
121 .channels_min = 2, 121 .channels_min = 1,
122 .channels_max = 2, 122 .channels_max = 2,
123 .buffer_bytes_max = 64 * 1024 - 1, 123 .buffer_bytes_max = 64 * 1024 - 1,
124 .period_bytes_min = 512, 124 .period_bytes_min = 512,
@@ -133,7 +133,8 @@ static struct snd_pcm_hardware snd_at73c213_playback_hw = {
133static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip) 133static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip)
134{ 134{
135 unsigned long ssc_rate = clk_get_rate(chip->ssc->clk); 135 unsigned long ssc_rate = clk_get_rate(chip->ssc->clk);
136 unsigned long dac_rate_new, ssc_div, status; 136 unsigned long dac_rate_new, ssc_div;
137 int status;
137 unsigned long ssc_div_max, ssc_div_min; 138 unsigned long ssc_div_max, ssc_div_min;
138 int max_tries; 139 int max_tries;
139 140
@@ -209,7 +210,13 @@ static int snd_at73c213_pcm_open(struct snd_pcm_substream *substream)
209{ 210{
210 struct snd_at73c213 *chip = snd_pcm_substream_chip(substream); 211 struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
211 struct snd_pcm_runtime *runtime = substream->runtime; 212 struct snd_pcm_runtime *runtime = substream->runtime;
213 int err;
212 214
215 /* ensure buffer_size is a multiple of period_size */
216 err = snd_pcm_hw_constraint_integer(runtime,
217 SNDRV_PCM_HW_PARAM_PERIODS);
218 if (err < 0)
219 return err;
213 snd_at73c213_playback_hw.rate_min = chip->bitrate; 220 snd_at73c213_playback_hw.rate_min = chip->bitrate;
214 snd_at73c213_playback_hw.rate_max = chip->bitrate; 221 snd_at73c213_playback_hw.rate_max = chip->bitrate;
215 runtime->hw = snd_at73c213_playback_hw; 222 runtime->hw = snd_at73c213_playback_hw;
@@ -228,6 +235,14 @@ static int snd_at73c213_pcm_close(struct snd_pcm_substream *substream)
228static int snd_at73c213_pcm_hw_params(struct snd_pcm_substream *substream, 235static int snd_at73c213_pcm_hw_params(struct snd_pcm_substream *substream,
229 struct snd_pcm_hw_params *hw_params) 236 struct snd_pcm_hw_params *hw_params)
230{ 237{
238 struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
239 int channels = params_channels(hw_params);
240 int val;
241
242 val = ssc_readl(chip->ssc->regs, TFMR);
243 val = SSC_BFINS(TFMR_DATNB, channels - 1, val);
244 ssc_writel(chip->ssc->regs, TFMR, val);
245
231 return snd_pcm_lib_malloc_pages(substream, 246 return snd_pcm_lib_malloc_pages(substream,
232 params_buffer_bytes(hw_params)); 247 params_buffer_bytes(hw_params));
233} 248}
@@ -249,10 +264,12 @@ static int snd_at73c213_pcm_prepare(struct snd_pcm_substream *substream)
249 264
250 ssc_writel(chip->ssc->regs, PDC_TPR, 265 ssc_writel(chip->ssc->regs, PDC_TPR,
251 (long)runtime->dma_addr); 266 (long)runtime->dma_addr);
252 ssc_writel(chip->ssc->regs, PDC_TCR, runtime->period_size * 2); 267 ssc_writel(chip->ssc->regs, PDC_TCR,
268 runtime->period_size * runtime->channels);
253 ssc_writel(chip->ssc->regs, PDC_TNPR, 269 ssc_writel(chip->ssc->regs, PDC_TNPR,
254 (long)runtime->dma_addr + block_size); 270 (long)runtime->dma_addr + block_size);
255 ssc_writel(chip->ssc->regs, PDC_TNCR, runtime->period_size * 2); 271 ssc_writel(chip->ssc->regs, PDC_TNCR,
272 runtime->period_size * runtime->channels);
256 273
257 return 0; 274 return 0;
258} 275}
@@ -314,15 +331,6 @@ static struct snd_pcm_ops at73c213_playback_ops = {
314 .pointer = snd_at73c213_pcm_pointer, 331 .pointer = snd_at73c213_pcm_pointer,
315}; 332};
316 333
317static void snd_at73c213_pcm_free(struct snd_pcm *pcm)
318{
319 struct snd_at73c213 *chip = snd_pcm_chip(pcm);
320 if (chip->pcm) {
321 snd_pcm_lib_preallocate_free_for_all(chip->pcm);
322 chip->pcm = NULL;
323 }
324}
325
326static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device) 334static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device)
327{ 335{
328 struct snd_pcm *pcm; 336 struct snd_pcm *pcm;
@@ -334,7 +342,6 @@ static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device)
334 goto out; 342 goto out;
335 343
336 pcm->private_data = chip; 344 pcm->private_data = chip;
337 pcm->private_free = snd_at73c213_pcm_free;
338 pcm->info_flags = SNDRV_PCM_INFO_BLOCK_TRANSFER; 345 pcm->info_flags = SNDRV_PCM_INFO_BLOCK_TRANSFER;
339 strcpy(pcm->name, "at73c213"); 346 strcpy(pcm->name, "at73c213");
340 chip->pcm = pcm; 347 chip->pcm = pcm;
@@ -375,7 +382,8 @@ static irqreturn_t snd_at73c213_interrupt(int irq, void *dev_id)
375 382
376 ssc_writel(chip->ssc->regs, PDC_TNPR, 383 ssc_writel(chip->ssc->regs, PDC_TNPR,
377 (long)runtime->dma_addr + offset); 384 (long)runtime->dma_addr + offset);
378 ssc_writel(chip->ssc->regs, PDC_TNCR, runtime->period_size * 2); 385 ssc_writel(chip->ssc->regs, PDC_TNCR,
386 runtime->period_size * runtime->channels);
379 retval = IRQ_HANDLED; 387 retval = IRQ_HANDLED;
380 } 388 }
381 389
@@ -737,7 +745,7 @@ cleanup:
737/* 745/*
738 * Device functions 746 * Device functions
739 */ 747 */
740static int snd_at73c213_ssc_init(struct snd_at73c213 *chip) 748static int __devinit snd_at73c213_ssc_init(struct snd_at73c213 *chip)
741{ 749{
742 /* 750 /*
743 * Continuous clock output. 751 * Continuous clock output.
@@ -767,7 +775,7 @@ static int snd_at73c213_ssc_init(struct snd_at73c213 *chip)
767 return 0; 775 return 0;
768} 776}
769 777
770static int snd_at73c213_chip_init(struct snd_at73c213 *chip) 778static int __devinit snd_at73c213_chip_init(struct snd_at73c213 *chip)
771{ 779{
772 int retval; 780 int retval;
773 unsigned char dac_ctrl = 0; 781 unsigned char dac_ctrl = 0;
@@ -933,7 +941,7 @@ out:
933 return retval; 941 return retval;
934} 942}
935 943
936static int snd_at73c213_probe(struct spi_device *spi) 944static int __devinit snd_at73c213_probe(struct spi_device *spi)
937{ 945{
938 struct snd_card *card; 946 struct snd_card *card;
939 struct snd_at73c213 *chip; 947 struct snd_at73c213 *chip;
diff --git a/sound/usb/caiaq/caiaq-audio.c b/sound/usb/caiaq/caiaq-audio.c
index 9cc4cd8283f9..24970a5c888f 100644
--- a/sound/usb/caiaq/caiaq-audio.c
+++ b/sound/usb/caiaq/caiaq-audio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006,2007 Daniel Mack, Karsten Wiese 2 * Copyright (c) 2006-2008 Daniel Mack, Karsten Wiese
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
@@ -39,7 +39,8 @@
39#define BYTES_PER_SAMPLE 3 39#define BYTES_PER_SAMPLE 3
40#define BYTES_PER_SAMPLE_USB 4 40#define BYTES_PER_SAMPLE_USB 4
41#define MAX_BUFFER_SIZE (128*1024) 41#define MAX_BUFFER_SIZE (128*1024)
42 42#define MAX_ENDPOINT_SIZE 512
43
43#define ENDPOINT_CAPTURE 2 44#define ENDPOINT_CAPTURE 2
44#define ENDPOINT_PLAYBACK 6 45#define ENDPOINT_PLAYBACK 6
45 46
@@ -77,10 +78,15 @@ static void
77deactivate_substream(struct snd_usb_caiaqdev *dev, 78deactivate_substream(struct snd_usb_caiaqdev *dev,
78 struct snd_pcm_substream *sub) 79 struct snd_pcm_substream *sub)
79{ 80{
81 unsigned long flags;
82 spin_lock_irqsave(&dev->spinlock, flags);
83
80 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 84 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
81 dev->sub_playback[sub->number] = NULL; 85 dev->sub_playback[sub->number] = NULL;
82 else 86 else
83 dev->sub_capture[sub->number] = NULL; 87 dev->sub_capture[sub->number] = NULL;
88
89 spin_unlock_irqrestore(&dev->spinlock, flags);
84} 90}
85 91
86static int 92static int
@@ -97,13 +103,13 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
97{ 103{
98 int i, ret; 104 int i, ret;
99 105
100 debug("stream_start(%p)\n", dev); 106 debug("%s(%p)\n", __func__, dev);
101 spin_lock_irq(&dev->spinlock); 107
102 if (dev->streaming) { 108 if (dev->streaming)
103 spin_unlock_irq(&dev->spinlock);
104 return -EINVAL; 109 return -EINVAL;
105 }
106 110
111 memset(dev->sub_playback, 0, sizeof(dev->sub_playback));
112 memset(dev->sub_capture, 0, sizeof(dev->sub_capture));
107 dev->input_panic = 0; 113 dev->input_panic = 0;
108 dev->output_panic = 0; 114 dev->output_panic = 0;
109 dev->first_packet = 1; 115 dev->first_packet = 1;
@@ -112,37 +118,35 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
112 for (i = 0; i < N_URBS; i++) { 118 for (i = 0; i < N_URBS; i++) {
113 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC); 119 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC);
114 if (ret) { 120 if (ret) {
115 log("unable to trigger initial read #%d! (ret = %d)\n", 121 log("unable to trigger read #%d! (ret %d)\n", i, ret);
116 i, ret);
117 dev->streaming = 0; 122 dev->streaming = 0;
118 spin_unlock_irq(&dev->spinlock);
119 return -EPIPE; 123 return -EPIPE;
120 } 124 }
121 } 125 }
122 126
123 spin_unlock_irq(&dev->spinlock);
124 return 0; 127 return 0;
125} 128}
126 129
127static void stream_stop(struct snd_usb_caiaqdev *dev) 130static void stream_stop(struct snd_usb_caiaqdev *dev)
128{ 131{
129 int i; 132 int i;
130 133
131 debug("stream_stop(%p)\n", dev); 134 debug("%s(%p)\n", __func__, dev);
132 if (!dev->streaming) 135 if (!dev->streaming)
133 return; 136 return;
134 137
135 dev->streaming = 0; 138 dev->streaming = 0;
139
136 for (i = 0; i < N_URBS; i++) { 140 for (i = 0; i < N_URBS; i++) {
137 usb_unlink_urb(dev->data_urbs_in[i]); 141 usb_kill_urb(dev->data_urbs_in[i]);
138 usb_unlink_urb(dev->data_urbs_out[i]); 142 usb_kill_urb(dev->data_urbs_out[i]);
139 } 143 }
140} 144}
141 145
142static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream) 146static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream)
143{ 147{
144 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 148 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
145 debug("snd_usb_caiaq_substream_open(%p)\n", substream); 149 debug("%s(%p)\n", __func__, substream);
146 substream->runtime->hw = dev->pcm_info; 150 substream->runtime->hw = dev->pcm_info;
147 snd_pcm_limit_hw_rates(substream->runtime); 151 snd_pcm_limit_hw_rates(substream->runtime);
148 return 0; 152 return 0;
@@ -152,7 +156,7 @@ static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
152{ 156{
153 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 157 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
154 158
155 debug("snd_usb_caiaq_substream_close(%p)\n", substream); 159 debug("%s(%p)\n", __func__, substream);
156 if (all_substreams_zero(dev->sub_playback) && 160 if (all_substreams_zero(dev->sub_playback) &&
157 all_substreams_zero(dev->sub_capture)) { 161 all_substreams_zero(dev->sub_capture)) {
158 /* when the last client has stopped streaming, 162 /* when the last client has stopped streaming,
@@ -160,24 +164,22 @@ static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
160 stream_stop(dev); 164 stream_stop(dev);
161 dev->pcm_info.rates = dev->samplerates; 165 dev->pcm_info.rates = dev->samplerates;
162 } 166 }
163 167
164 return 0; 168 return 0;
165} 169}
166 170
167static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub, 171static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub,
168 struct snd_pcm_hw_params *hw_params) 172 struct snd_pcm_hw_params *hw_params)
169{ 173{
170 debug("snd_usb_caiaq_pcm_hw_params(%p)\n", sub); 174 debug("%s(%p)\n", __func__, sub);
171 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params)); 175 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params));
172} 176}
173 177
174static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub) 178static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub)
175{ 179{
176 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 180 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub);
177 debug("snd_usb_caiaq_pcm_hw_free(%p)\n", sub); 181 debug("%s(%p)\n", __func__, sub);
178 spin_lock_irq(&dev->spinlock);
179 deactivate_substream(dev, sub); 182 deactivate_substream(dev, sub);
180 spin_unlock_irq(&dev->spinlock);
181 return snd_pcm_lib_free_pages(sub); 183 return snd_pcm_lib_free_pages(sub);
182} 184}
183 185
@@ -196,12 +198,12 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
196 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 198 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
197 struct snd_pcm_runtime *runtime = substream->runtime; 199 struct snd_pcm_runtime *runtime = substream->runtime;
198 200
199 debug("snd_usb_caiaq_pcm_prepare(%p)\n", substream); 201 debug("%s(%p)\n", __func__, substream);
200 202
201 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 203 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
202 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1; 204 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1;
203 else 205 else
204 dev->audio_in_buf_pos[index] = 0; 206 dev->audio_in_buf_pos[index] = BYTES_PER_SAMPLE;
205 207
206 if (dev->streaming) 208 if (dev->streaming)
207 return 0; 209 return 0;
@@ -220,7 +222,10 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
220 222
221 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE) 223 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
222 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams; 224 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams;
223 225
226 if (bpp > MAX_ENDPOINT_SIZE)
227 bpp = MAX_ENDPOINT_SIZE;
228
224 ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate, 229 ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate,
225 runtime->sample_bits, bpp); 230 runtime->sample_bits, bpp);
226 if (ret) 231 if (ret)
@@ -247,15 +252,11 @@ static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd)
247 switch (cmd) { 252 switch (cmd) {
248 case SNDRV_PCM_TRIGGER_START: 253 case SNDRV_PCM_TRIGGER_START:
249 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 254 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
250 spin_lock(&dev->spinlock);
251 activate_substream(dev, sub); 255 activate_substream(dev, sub);
252 spin_unlock(&dev->spinlock);
253 break; 256 break;
254 case SNDRV_PCM_TRIGGER_STOP: 257 case SNDRV_PCM_TRIGGER_STOP:
255 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 258 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
256 spin_lock(&dev->spinlock);
257 deactivate_substream(dev, sub); 259 deactivate_substream(dev, sub);
258 spin_unlock(&dev->spinlock);
259 break; 260 break;
260 default: 261 default:
261 return -EINVAL; 262 return -EINVAL;
@@ -328,8 +329,6 @@ static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev,
328 if (all_substreams_zero(dev->sub_capture)) 329 if (all_substreams_zero(dev->sub_capture))
329 return; 330 return;
330 331
331 spin_lock(&dev->spinlock);
332
333 for (i = 0; i < iso->actual_length;) { 332 for (i = 0; i < iso->actual_length;) {
334 for (stream = 0; stream < dev->n_streams; stream++, i++) { 333 for (stream = 0; stream < dev->n_streams; stream++, i++) {
335 sub = dev->sub_capture[stream]; 334 sub = dev->sub_capture[stream];
@@ -345,8 +344,6 @@ static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev,
345 } 344 }
346 } 345 }
347 } 346 }
348
349 spin_unlock(&dev->spinlock);
350} 347}
351 348
352static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev, 349static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
@@ -358,8 +355,6 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
358 struct snd_pcm_substream *sub; 355 struct snd_pcm_substream *sub;
359 int stream, i; 356 int stream, i;
360 357
361 spin_lock(&dev->spinlock);
362
363 for (i = 0; i < iso->actual_length;) { 358 for (i = 0; i < iso->actual_length;) {
364 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) { 359 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) {
365 for (stream = 0; 360 for (stream = 0;
@@ -393,8 +388,6 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
393 } 388 }
394 } 389 }
395 } 390 }
396
397 spin_unlock(&dev->spinlock);
398} 391}
399 392
400static void read_in_urb(struct snd_usb_caiaqdev *dev, 393static void read_in_urb(struct snd_usb_caiaqdev *dev,
@@ -418,8 +411,6 @@ static void read_in_urb(struct snd_usb_caiaqdev *dev,
418 dev->input_panic ? "(input)" : "", 411 dev->input_panic ? "(input)" : "",
419 dev->output_panic ? "(output)" : ""); 412 dev->output_panic ? "(output)" : "");
420 } 413 }
421
422 check_for_elapsed_periods(dev, dev->sub_capture);
423} 414}
424 415
425static void fill_out_urb(struct snd_usb_caiaqdev *dev, 416static void fill_out_urb(struct snd_usb_caiaqdev *dev,
@@ -429,8 +420,6 @@ static void fill_out_urb(struct snd_usb_caiaqdev *dev,
429 unsigned char *usb_buf = urb->transfer_buffer + iso->offset; 420 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
430 struct snd_pcm_substream *sub; 421 struct snd_pcm_substream *sub;
431 int stream, i; 422 int stream, i;
432
433 spin_lock(&dev->spinlock);
434 423
435 for (i = 0; i < iso->length;) { 424 for (i = 0; i < iso->length;) {
436 for (stream = 0; stream < dev->n_streams; stream++, i++) { 425 for (stream = 0; stream < dev->n_streams; stream++, i++) {
@@ -456,9 +445,6 @@ static void fill_out_urb(struct snd_usb_caiaqdev *dev,
456 for (stream = 0; stream < dev->n_streams; stream++, i++) 445 for (stream = 0; stream < dev->n_streams; stream++, i++)
457 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i); 446 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i);
458 } 447 }
459
460 spin_unlock(&dev->spinlock);
461 check_for_elapsed_periods(dev, dev->sub_playback);
462} 448}
463 449
464static void read_completed(struct urb *urb) 450static void read_completed(struct urb *urb)
@@ -472,6 +458,7 @@ static void read_completed(struct urb *urb)
472 return; 458 return;
473 459
474 dev = info->dev; 460 dev = info->dev;
461
475 if (!dev->streaming) 462 if (!dev->streaming)
476 return; 463 return;
477 464
@@ -489,8 +476,12 @@ static void read_completed(struct urb *urb)
489 out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame; 476 out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame;
490 477
491 if (len > 0) { 478 if (len > 0) {
479 spin_lock(&dev->spinlock);
492 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]); 480 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]);
493 read_in_urb(dev, urb, &urb->iso_frame_desc[frame]); 481 read_in_urb(dev, urb, &urb->iso_frame_desc[frame]);
482 spin_unlock(&dev->spinlock);
483 check_for_elapsed_periods(dev, dev->sub_playback);
484 check_for_elapsed_periods(dev, dev->sub_capture);
494 send_it = 1; 485 send_it = 1;
495 } 486 }
496 487
@@ -696,7 +687,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
696 687
697void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev) 688void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev)
698{ 689{
699 debug("snd_usb_caiaq_audio_free (%p)\n", dev); 690 debug("%s(%p)\n", __func__, dev);
700 stream_stop(dev); 691 stream_stop(dev);
701 free_urbs(dev->data_urbs_in); 692 free_urbs(dev->data_urbs_in);
702 free_urbs(dev->data_urbs_out); 693 free_urbs(dev->data_urbs_out);
diff --git a/sound/usb/caiaq/caiaq-device.c b/sound/usb/caiaq/caiaq-device.c
index 7c44a2c7f963..e97d8b2ac16a 100644
--- a/sound/usb/caiaq/caiaq-device.c
+++ b/sound/usb/caiaq/caiaq-device.c
@@ -42,7 +42,7 @@
42#endif 42#endif
43 43
44MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 44MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
45MODULE_DESCRIPTION("caiaq USB audio, version 1.3.2"); 45MODULE_DESCRIPTION("caiaq USB audio, version 1.3.6");
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 47MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
48 "{Native Instruments, RigKontrol3}," 48 "{Native Instruments, RigKontrol3},"
@@ -456,7 +456,7 @@ static void snd_disconnect(struct usb_interface *intf)
456 struct snd_usb_caiaqdev *dev; 456 struct snd_usb_caiaqdev *dev;
457 struct snd_card *card = dev_get_drvdata(&intf->dev); 457 struct snd_card *card = dev_get_drvdata(&intf->dev);
458 458
459 debug("snd_disconnect(%p)\n", intf); 459 debug("%s(%p)\n", __func__, intf);
460 460
461 if (!card) 461 if (!card)
462 return; 462 return;
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index f48838a078cb..410be4aff1ba 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -64,9 +64,10 @@ MODULE_SUPPORTED_DEVICE("{{Generic,USB Audio}}");
64 64
65static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 65static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
66static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 66static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
67static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 67static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
68static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; /* Vendor ID for this card */ 68/* Vendor/product IDs for this card */
69static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; /* Product ID for this card */ 69static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
70static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
70static int nrpacks = 8; /* max. number of packets per urb */ 71static int nrpacks = 8; /* max. number of packets per urb */
71static int async_unlink = 1; 72static int async_unlink = 1;
72static int device_setup[SNDRV_CARDS]; /* device parameter for this card*/ 73static int device_setup[SNDRV_CARDS]; /* device parameter for this card*/
@@ -687,7 +688,7 @@ static void snd_complete_urb(struct urb *urb)
687 int err = 0; 688 int err = 0;
688 689
689 if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) || 690 if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) ||
690 ! subs->running || /* can be stopped during retire callback */ 691 !subs->running || /* can be stopped during retire callback */
691 (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 || 692 (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 ||
692 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 693 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
693 clear_bit(ctx->index, &subs->active_mask); 694 clear_bit(ctx->index, &subs->active_mask);
@@ -710,7 +711,7 @@ static void snd_complete_sync_urb(struct urb *urb)
710 int err = 0; 711 int err = 0;
711 712
712 if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) || 713 if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) ||
713 ! subs->running || /* can be stopped during retire callback */ 714 !subs->running || /* can be stopped during retire callback */
714 (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 || 715 (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 ||
715 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 716 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
716 clear_bit(ctx->index + 16, &subs->active_mask); 717 clear_bit(ctx->index + 16, &subs->active_mask);
@@ -740,7 +741,7 @@ static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t s
740 vfree(runtime->dma_area); 741 vfree(runtime->dma_area);
741 } 742 }
742 runtime->dma_area = vmalloc(size); 743 runtime->dma_area = vmalloc(size);
743 if (! runtime->dma_area) 744 if (!runtime->dma_area)
744 return -ENOMEM; 745 return -ENOMEM;
745 runtime->dma_bytes = size; 746 runtime->dma_bytes = size;
746 return 0; 747 return 0;
@@ -772,12 +773,12 @@ static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sl
772 773
773 async = !can_sleep && async_unlink; 774 async = !can_sleep && async_unlink;
774 775
775 if (! async && in_interrupt()) 776 if (!async && in_interrupt())
776 return 0; 777 return 0;
777 778
778 for (i = 0; i < subs->nurbs; i++) { 779 for (i = 0; i < subs->nurbs; i++) {
779 if (test_bit(i, &subs->active_mask)) { 780 if (test_bit(i, &subs->active_mask)) {
780 if (! test_and_set_bit(i, &subs->unlink_mask)) { 781 if (!test_and_set_bit(i, &subs->unlink_mask)) {
781 struct urb *u = subs->dataurb[i].urb; 782 struct urb *u = subs->dataurb[i].urb;
782 if (async) 783 if (async)
783 usb_unlink_urb(u); 784 usb_unlink_urb(u);
@@ -789,7 +790,7 @@ static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sl
789 if (subs->syncpipe) { 790 if (subs->syncpipe) {
790 for (i = 0; i < SYNC_URBS; i++) { 791 for (i = 0; i < SYNC_URBS; i++) {
791 if (test_bit(i+16, &subs->active_mask)) { 792 if (test_bit(i+16, &subs->active_mask)) {
792 if (! test_and_set_bit(i+16, &subs->unlink_mask)) { 793 if (!test_and_set_bit(i+16, &subs->unlink_mask)) {
793 struct urb *u = subs->syncurb[i].urb; 794 struct urb *u = subs->syncurb[i].urb;
794 if (async) 795 if (async)
795 usb_unlink_urb(u); 796 usb_unlink_urb(u);
@@ -1137,12 +1138,12 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1137 if (subs->fmt_type == USB_FORMAT_TYPE_II) 1138 if (subs->fmt_type == USB_FORMAT_TYPE_II)
1138 u->packets++; /* for transfer delimiter */ 1139 u->packets++; /* for transfer delimiter */
1139 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); 1140 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
1140 if (! u->urb) 1141 if (!u->urb)
1141 goto out_of_memory; 1142 goto out_of_memory;
1142 u->urb->transfer_buffer = 1143 u->urb->transfer_buffer =
1143 usb_buffer_alloc(subs->dev, u->buffer_size, GFP_KERNEL, 1144 usb_buffer_alloc(subs->dev, u->buffer_size, GFP_KERNEL,
1144 &u->urb->transfer_dma); 1145 &u->urb->transfer_dma);
1145 if (! u->urb->transfer_buffer) 1146 if (!u->urb->transfer_buffer)
1146 goto out_of_memory; 1147 goto out_of_memory;
1147 u->urb->pipe = subs->datapipe; 1148 u->urb->pipe = subs->datapipe;
1148 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 1149 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
@@ -1155,7 +1156,7 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1155 /* allocate and initialize sync urbs */ 1156 /* allocate and initialize sync urbs */
1156 subs->syncbuf = usb_buffer_alloc(subs->dev, SYNC_URBS * 4, 1157 subs->syncbuf = usb_buffer_alloc(subs->dev, SYNC_URBS * 4,
1157 GFP_KERNEL, &subs->sync_dma); 1158 GFP_KERNEL, &subs->sync_dma);
1158 if (! subs->syncbuf) 1159 if (!subs->syncbuf)
1159 goto out_of_memory; 1160 goto out_of_memory;
1160 for (i = 0; i < SYNC_URBS; i++) { 1161 for (i = 0; i < SYNC_URBS; i++) {
1161 struct snd_urb_ctx *u = &subs->syncurb[i]; 1162 struct snd_urb_ctx *u = &subs->syncurb[i];
@@ -1163,7 +1164,7 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1163 u->subs = subs; 1164 u->subs = subs;
1164 u->packets = 1; 1165 u->packets = 1;
1165 u->urb = usb_alloc_urb(1, GFP_KERNEL); 1166 u->urb = usb_alloc_urb(1, GFP_KERNEL);
1166 if (! u->urb) 1167 if (!u->urb)
1167 goto out_of_memory; 1168 goto out_of_memory;
1168 u->urb->transfer_buffer = subs->syncbuf + i * 4; 1169 u->urb->transfer_buffer = subs->syncbuf + i * 4;
1169 u->urb->transfer_dma = subs->sync_dma + i * 4; 1170 u->urb->transfer_dma = subs->sync_dma + i * 4;
@@ -1427,8 +1428,8 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
1427 subs->cur_audiofmt = fmt; 1428 subs->cur_audiofmt = fmt;
1428 1429
1429#if 0 1430#if 0
1430 printk("setting done: format = %d, rate = %d, channels = %d\n", 1431 printk("setting done: format = %d, rate = %d..%d, channels = %d\n",
1431 fmt->format, fmt->rate, fmt->channels); 1432 fmt->format, fmt->rate_min, fmt->rate_max, fmt->channels);
1432 printk(" datapipe = 0x%0x, syncpipe = 0x%0x\n", 1433 printk(" datapipe = 0x%0x, syncpipe = 0x%0x\n",
1433 subs->datapipe, subs->syncpipe); 1434 subs->datapipe, subs->syncpipe);
1434#endif 1435#endif
@@ -1463,7 +1464,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
1463 rate = params_rate(hw_params); 1464 rate = params_rate(hw_params);
1464 channels = params_channels(hw_params); 1465 channels = params_channels(hw_params);
1465 fmt = find_format(subs, format, rate, channels); 1466 fmt = find_format(subs, format, rate, channels);
1466 if (! fmt) { 1467 if (!fmt) {
1467 snd_printd(KERN_DEBUG "cannot set format: format = 0x%x, rate = %d, channels = %d\n", 1468 snd_printd(KERN_DEBUG "cannot set format: format = 0x%x, rate = %d, channels = %d\n",
1468 format, rate, channels); 1469 format, rate, channels);
1469 return -EINVAL; 1470 return -EINVAL;
@@ -1584,7 +1585,7 @@ static int hw_check_valid_format(struct snd_pcm_hw_params *params, struct audiof
1584 struct snd_mask *fmts = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 1585 struct snd_mask *fmts = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
1585 1586
1586 /* check the format */ 1587 /* check the format */
1587 if (! snd_mask_test(fmts, fp->format)) { 1588 if (!snd_mask_test(fmts, fp->format)) {
1588 hwc_debug(" > check: no supported format %d\n", fp->format); 1589 hwc_debug(" > check: no supported format %d\n", fp->format);
1589 return 0; 1590 return 0;
1590 } 1591 }
@@ -1620,7 +1621,7 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params,
1620 list_for_each(p, &subs->fmt_list) { 1621 list_for_each(p, &subs->fmt_list) {
1621 struct audioformat *fp; 1622 struct audioformat *fp;
1622 fp = list_entry(p, struct audioformat, list); 1623 fp = list_entry(p, struct audioformat, list);
1623 if (! hw_check_valid_format(params, fp)) 1624 if (!hw_check_valid_format(params, fp))
1624 continue; 1625 continue;
1625 if (changed++) { 1626 if (changed++) {
1626 if (rmin > fp->rate_min) 1627 if (rmin > fp->rate_min)
@@ -1633,7 +1634,7 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params,
1633 } 1634 }
1634 } 1635 }
1635 1636
1636 if (! changed) { 1637 if (!changed) {
1637 hwc_debug(" --> get empty\n"); 1638 hwc_debug(" --> get empty\n");
1638 it->empty = 1; 1639 it->empty = 1;
1639 return -EINVAL; 1640 return -EINVAL;
@@ -1674,7 +1675,7 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params,
1674 list_for_each(p, &subs->fmt_list) { 1675 list_for_each(p, &subs->fmt_list) {
1675 struct audioformat *fp; 1676 struct audioformat *fp;
1676 fp = list_entry(p, struct audioformat, list); 1677 fp = list_entry(p, struct audioformat, list);
1677 if (! hw_check_valid_format(params, fp)) 1678 if (!hw_check_valid_format(params, fp))
1678 continue; 1679 continue;
1679 if (changed++) { 1680 if (changed++) {
1680 if (rmin > fp->channels) 1681 if (rmin > fp->channels)
@@ -1687,7 +1688,7 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params,
1687 } 1688 }
1688 } 1689 }
1689 1690
1690 if (! changed) { 1691 if (!changed) {
1691 hwc_debug(" --> get empty\n"); 1692 hwc_debug(" --> get empty\n");
1692 it->empty = 1; 1693 it->empty = 1;
1693 return -EINVAL; 1694 return -EINVAL;
@@ -1727,7 +1728,7 @@ static int hw_rule_format(struct snd_pcm_hw_params *params,
1727 list_for_each(p, &subs->fmt_list) { 1728 list_for_each(p, &subs->fmt_list) {
1728 struct audioformat *fp; 1729 struct audioformat *fp;
1729 fp = list_entry(p, struct audioformat, list); 1730 fp = list_entry(p, struct audioformat, list);
1730 if (! hw_check_valid_format(params, fp)) 1731 if (!hw_check_valid_format(params, fp))
1731 continue; 1732 continue;
1732 fbits |= (1ULL << fp->format); 1733 fbits |= (1ULL << fp->format);
1733 } 1734 }
@@ -1736,7 +1737,7 @@ static int hw_rule_format(struct snd_pcm_hw_params *params,
1736 oldbits[1] = fmt->bits[1]; 1737 oldbits[1] = fmt->bits[1];
1737 fmt->bits[0] &= (u32)fbits; 1738 fmt->bits[0] &= (u32)fbits;
1738 fmt->bits[1] &= (u32)(fbits >> 32); 1739 fmt->bits[1] &= (u32)(fbits >> 32);
1739 if (! fmt->bits[0] && ! fmt->bits[1]) { 1740 if (!fmt->bits[0] && !fmt->bits[1]) {
1740 hwc_debug(" --> get empty\n"); 1741 hwc_debug(" --> get empty\n");
1741 return -EINVAL; 1742 return -EINVAL;
1742 } 1743 }
@@ -1762,8 +1763,10 @@ static int check_hw_params_convention(struct snd_usb_substream *subs)
1762 1763
1763 channels = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL); 1764 channels = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL);
1764 rates = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL); 1765 rates = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL);
1765 if (!channels || !rates) 1766 if (!channels || !rates) {
1767 err = -ENOMEM;
1766 goto __out; 1768 goto __out;
1769 }
1767 1770
1768 list_for_each(p, &subs->fmt_list) { 1771 list_for_each(p, &subs->fmt_list) {
1769 struct audioformat *f; 1772 struct audioformat *f;
@@ -1916,7 +1919,10 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
1916 1000 * MIN_PACKS_URB, 1919 1000 * MIN_PACKS_URB,
1917 /*(nrpacks * MAX_URBS) * 1000*/ UINT_MAX); 1920 /*(nrpacks * MAX_URBS) * 1000*/ UINT_MAX);
1918 1921
1919 if (check_hw_params_convention(subs)) { 1922 err = check_hw_params_convention(subs);
1923 if (err < 0)
1924 return err;
1925 else if (err) {
1920 hwc_debug("setting extra hw constraints...\n"); 1926 hwc_debug("setting extra hw constraints...\n");
1921 if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 1927 if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1922 hw_rule_rate, subs, 1928 hw_rule_rate, subs,
@@ -2222,7 +2228,7 @@ static void proc_pcm_format_add(struct snd_usb_stream *stream)
2222 struct snd_card *card = stream->chip->card; 2228 struct snd_card *card = stream->chip->card;
2223 2229
2224 sprintf(name, "stream%d", stream->pcm_index); 2230 sprintf(name, "stream%d", stream->pcm_index);
2225 if (! snd_card_proc_new(card, name, &entry)) 2231 if (!snd_card_proc_new(card, name, &entry))
2226 snd_info_set_text_ops(entry, stream, proc_pcm_format_read); 2232 snd_info_set_text_ops(entry, stream, proc_pcm_format_read);
2227} 2233}
2228 2234
@@ -2278,7 +2284,7 @@ static void free_substream(struct snd_usb_substream *subs)
2278{ 2284{
2279 struct list_head *p, *n; 2285 struct list_head *p, *n;
2280 2286
2281 if (! subs->num_formats) 2287 if (!subs->num_formats)
2282 return; /* not initialized */ 2288 return; /* not initialized */
2283 list_for_each_safe(p, n, &subs->fmt_list) { 2289 list_for_each_safe(p, n, &subs->fmt_list) {
2284 struct audioformat *fp = list_entry(p, struct audioformat, list); 2290 struct audioformat *fp = list_entry(p, struct audioformat, list);
@@ -2328,7 +2334,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct aud
2328 if (as->fmt_type != fp->fmt_type) 2334 if (as->fmt_type != fp->fmt_type)
2329 continue; 2335 continue;
2330 subs = &as->substream[stream]; 2336 subs = &as->substream[stream];
2331 if (! subs->endpoint) 2337 if (!subs->endpoint)
2332 continue; 2338 continue;
2333 if (subs->endpoint == fp->endpoint) { 2339 if (subs->endpoint == fp->endpoint) {
2334 list_add_tail(&fp->list, &subs->fmt_list); 2340 list_add_tail(&fp->list, &subs->fmt_list);
@@ -2354,7 +2360,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct aud
2354 2360
2355 /* create a new pcm */ 2361 /* create a new pcm */
2356 as = kzalloc(sizeof(*as), GFP_KERNEL); 2362 as = kzalloc(sizeof(*as), GFP_KERNEL);
2357 if (! as) 2363 if (!as)
2358 return -ENOMEM; 2364 return -ENOMEM;
2359 as->pcm_index = chip->pcm_devs; 2365 as->pcm_index = chip->pcm_devs;
2360 as->chip = chip; 2366 as->chip = chip;
@@ -2463,11 +2469,12 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor
2463 } 2469 }
2464 break; 2470 break;
2465 case USB_AUDIO_FORMAT_PCM8: 2471 case USB_AUDIO_FORMAT_PCM8:
2466 /* Dallas DS4201 workaround */ 2472 pcm_format = SNDRV_PCM_FORMAT_U8;
2473
2474 /* Dallas DS4201 workaround: it advertises U8 format, but really
2475 supports S8. */
2467 if (chip->usb_id == USB_ID(0x04fa, 0x4201)) 2476 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
2468 pcm_format = SNDRV_PCM_FORMAT_S8; 2477 pcm_format = SNDRV_PCM_FORMAT_S8;
2469 else
2470 pcm_format = SNDRV_PCM_FORMAT_U8;
2471 break; 2478 break;
2472 case USB_AUDIO_FORMAT_IEEE_FLOAT: 2479 case USB_AUDIO_FORMAT_IEEE_FLOAT:
2473 pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE; 2480 pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE;
@@ -2671,12 +2678,23 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2671 int format; 2678 int format;
2672 struct audioformat *fp; 2679 struct audioformat *fp;
2673 unsigned char *fmt, *csep; 2680 unsigned char *fmt, *csep;
2681 int num;
2674 2682
2675 dev = chip->dev; 2683 dev = chip->dev;
2676 2684
2677 /* parse the interface's altsettings */ 2685 /* parse the interface's altsettings */
2678 iface = usb_ifnum_to_if(dev, iface_no); 2686 iface = usb_ifnum_to_if(dev, iface_no);
2679 for (i = 0; i < iface->num_altsetting; i++) { 2687
2688 num = iface->num_altsetting;
2689
2690 /*
2691 * Dallas DS4201 workaround: It presents 5 altsettings, but the last
2692 * one misses syncpipe, and does not produce any sound.
2693 */
2694 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
2695 num = 4;
2696
2697 for (i = 0; i < num; i++) {
2680 alts = &iface->altsetting[i]; 2698 alts = &iface->altsetting[i];
2681 altsd = get_iface_desc(alts); 2699 altsd = get_iface_desc(alts);
2682 /* skip invalid one */ 2700 /* skip invalid one */
@@ -3375,14 +3393,14 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip,
3375static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 3393static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3376{ 3394{
3377 struct snd_usb_audio *chip = entry->private_data; 3395 struct snd_usb_audio *chip = entry->private_data;
3378 if (! chip->shutdown) 3396 if (!chip->shutdown)
3379 snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum); 3397 snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum);
3380} 3398}
3381 3399
3382static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 3400static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3383{ 3401{
3384 struct snd_usb_audio *chip = entry->private_data; 3402 struct snd_usb_audio *chip = entry->private_data;
3385 if (! chip->shutdown) 3403 if (!chip->shutdown)
3386 snd_iprintf(buffer, "%04x:%04x\n", 3404 snd_iprintf(buffer, "%04x:%04x\n",
3387 USB_ID_VENDOR(chip->usb_id), 3405 USB_ID_VENDOR(chip->usb_id),
3388 USB_ID_PRODUCT(chip->usb_id)); 3406 USB_ID_PRODUCT(chip->usb_id));
@@ -3391,9 +3409,9 @@ static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_
3391static void snd_usb_audio_create_proc(struct snd_usb_audio *chip) 3409static void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
3392{ 3410{
3393 struct snd_info_entry *entry; 3411 struct snd_info_entry *entry;
3394 if (! snd_card_proc_new(chip->card, "usbbus", &entry)) 3412 if (!snd_card_proc_new(chip->card, "usbbus", &entry))
3395 snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read); 3413 snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read);
3396 if (! snd_card_proc_new(chip->card, "usbid", &entry)) 3414 if (!snd_card_proc_new(chip->card, "usbid", &entry))
3397 snd_info_set_text_ops(entry, chip, proc_audio_usbid_read); 3415 snd_info_set_text_ops(entry, chip, proc_audio_usbid_read);
3398} 3416}
3399 3417
@@ -3406,7 +3424,6 @@ static void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
3406 3424
3407static int snd_usb_audio_free(struct snd_usb_audio *chip) 3425static int snd_usb_audio_free(struct snd_usb_audio *chip)
3408{ 3426{
3409 usb_chip[chip->index] = NULL;
3410 kfree(chip); 3427 kfree(chip);
3411 return 0; 3428 return 0;
3412} 3429}
@@ -3600,8 +3617,8 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3600 snd_card_set_dev(chip->card, &intf->dev); 3617 snd_card_set_dev(chip->card, &intf->dev);
3601 break; 3618 break;
3602 } 3619 }
3603 if (! chip) { 3620 if (!chip) {
3604 snd_printk(KERN_ERR "no available usb audio device\n"); 3621 printk(KERN_ERR "no available usb audio device\n");
3605 goto __error; 3622 goto __error;
3606 } 3623 }
3607 } 3624 }
@@ -3671,6 +3688,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr)
3671 list_for_each(p, &chip->mixer_list) { 3688 list_for_each(p, &chip->mixer_list) {
3672 snd_usb_mixer_disconnect(p); 3689 snd_usb_mixer_disconnect(p);
3673 } 3690 }
3691 usb_chip[chip->index] = NULL;
3674 mutex_unlock(&register_mutex); 3692 mutex_unlock(&register_mutex);
3675 snd_card_free_when_closed(card); 3693 snd_card_free_when_closed(card);
3676 } else { 3694 } else {
diff --git a/sound/usb/usbquirks.h b/sound/usb/usbquirks.h
index 938dff5f9cef..82a8d14c26af 100644
--- a/sound/usb/usbquirks.h
+++ b/sound/usb/usbquirks.h
@@ -39,6 +39,30 @@
39 .idProduct = prod, \ 39 .idProduct = prod, \
40 .bInterfaceClass = USB_CLASS_VENDOR_SPEC 40 .bInterfaceClass = USB_CLASS_VENDOR_SPEC
41 41
42/* Creative/E-Mu devices */
43{
44 USB_DEVICE(0x041e, 0x3010),
45 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
46 .vendor_name = "Creative Labs",
47 .product_name = "Sound Blaster MP3+",
48 .ifnum = QUIRK_NO_INTERFACE
49 }
50},
51{
52 /* E-Mu 0202 USB */
53 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
54 .idVendor = 0x041e,
55 .idProduct = 0x3f02,
56 .bInterfaceClass = USB_CLASS_AUDIO,
57},
58{
59 /* E-Mu 0404 USB */
60 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
61 .idVendor = 0x041e,
62 .idProduct = 0x3f04,
63 .bInterfaceClass = USB_CLASS_AUDIO,
64},
65
42/* 66/*
43 * Logitech QuickCam: bDeviceClass is vendor-specific, so generic interface 67 * Logitech QuickCam: bDeviceClass is vendor-specific, so generic interface
44 * class matches do not take effect without an explicit ID match. 68 * class matches do not take effect without an explicit ID match.
@@ -97,19 +121,7 @@
97 .bInterfaceClass = USB_CLASS_AUDIO, 121 .bInterfaceClass = USB_CLASS_AUDIO,
98 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL 122 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL
99}, 123},
100/* E-Mu devices */ 124
101{
102 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
103 .idVendor = 0x041e,
104 .idProduct = 0x3f02,
105 .bInterfaceClass = USB_CLASS_AUDIO,
106},
107{
108 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
109 .idVendor = 0x041e,
110 .idProduct = 0x3f04,
111 .bInterfaceClass = USB_CLASS_AUDIO,
112},
113/* 125/*
114 * Yamaha devices 126 * Yamaha devices
115 */ 127 */
@@ -1165,19 +1177,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1165 } 1177 }
1166 } 1178 }
1167}, 1179},
1168{
1169 USB_DEVICE(0x582, 0x00a6),
1170 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1171 .vendor_name = "Roland",
1172 .product_name = "Juno-G",
1173 .ifnum = 0,
1174 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1175 .data = & (const struct snd_usb_midi_endpoint_info) {
1176 .out_cables = 0x0001,
1177 .in_cables = 0x0001
1178 }
1179 }
1180},
1181{ /* 1180{ /*
1182 * This quirk is for the "Advanced" modes of the Edirol UA-25. 1181 * This quirk is for the "Advanced" modes of the Edirol UA-25.
1183 * If the switch is not in an advanced setting, the UA-25 has 1182 * If the switch is not in an advanced setting, the UA-25 has
@@ -1336,6 +1335,19 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1336}, 1335},
1337 /* TODO: add Edirol MD-P1 support */ 1336 /* TODO: add Edirol MD-P1 support */
1338{ 1337{
1338 USB_DEVICE(0x582, 0x00a6),
1339 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1340 .vendor_name = "Roland",
1341 .product_name = "Juno-G",
1342 .ifnum = 0,
1343 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1344 .data = & (const struct snd_usb_midi_endpoint_info) {
1345 .out_cables = 0x0001,
1346 .in_cables = 0x0001
1347 }
1348 }
1349},
1350{
1339 /* Roland SH-201 */ 1351 /* Roland SH-201 */
1340 USB_DEVICE(0x0582, 0x00ad), 1352 USB_DEVICE(0x0582, 0x00ad),
1341 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 1353 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
@@ -1719,17 +1731,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1719 } 1731 }
1720}, 1732},
1721 1733
1722{
1723 /* Creative Sound Blaster MP3+ */
1724 USB_DEVICE(0x041e, 0x3010),
1725 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1726 .vendor_name = "Creative Labs",
1727 .product_name = "Sound Blaster MP3+",
1728 .ifnum = QUIRK_NO_INTERFACE
1729 }
1730
1731},
1732
1733/* Emagic devices */ 1734/* Emagic devices */
1734{ 1735{
1735 USB_DEVICE(0x086a, 0x0001), 1736 USB_DEVICE(0x086a, 0x0001),