aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/aoa/codecs/onyx.c76
-rw-r--r--sound/aoa/codecs/tas.c66
-rw-r--r--sound/arm/aaci.c2
-rw-r--r--sound/arm/pxa2xx-ac97-lib.c4
-rw-r--r--sound/core/control.c35
-rw-r--r--sound/core/jack.c3
-rw-r--r--sound/core/pcm_compat.c11
-rw-r--r--sound/core/pcm_lib.c54
-rw-r--r--sound/core/pcm_native.c93
-rw-r--r--sound/core/seq/seq_compat.c9
-rw-r--r--sound/core/timer.c11
-rw-r--r--sound/isa/msnd/msnd.c6
-rw-r--r--sound/isa/sb/sb16_csp.c19
-rw-r--r--sound/isa/wavefront/wavefront_fx.c14
-rw-r--r--sound/isa/wavefront/wavefront_synth.c11
-rw-r--r--sound/pci/ac97/ac97_codec.c2
-rw-r--r--sound/pci/bt87x.c6
-rw-r--r--sound/pci/emu10k1/emufx.c41
-rw-r--r--sound/pci/hda/hda_codec.c14
-rw-r--r--sound/pci/hda/hda_intel.c39
-rw-r--r--sound/pci/hda/patch_analog.c53
-rw-r--r--sound/pci/hda/patch_conexant.c21
-rw-r--r--sound/pci/hda/patch_realtek.c112
-rw-r--r--sound/pci/hda/patch_sigmatel.c44
-rw-r--r--sound/pci/intel8x0.c105
-rw-r--r--sound/pci/korg1212/korg1212.c6
-rw-r--r--sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c3
-rw-r--r--sound/ppc/keywest.c82
-rw-r--r--sound/soc/au1x/dbdma2.c2
-rw-r--r--sound/soc/codecs/Makefile1
-rw-r--r--sound/soc/codecs/twl4030.c8
-rw-r--r--sound/soc/codecs/wm8350.c2
-rw-r--r--sound/soc/codecs/wm8580.c16
-rw-r--r--sound/soc/codecs/wm8990.c40
-rw-r--r--sound/soc/codecs/wm9705.c2
-rw-r--r--sound/soc/davinci/Kconfig7
-rw-r--r--sound/soc/davinci/davinci-evm.c63
-rw-r--r--sound/soc/davinci/davinci-i2s.c26
-rw-r--r--sound/soc/davinci/davinci-pcm.c71
-rw-r--r--sound/soc/fsl/mpc5200_psc_i2s.c3
-rw-r--r--sound/soc/omap/n810.c4
-rw-r--r--sound/soc/omap/omap-mcbsp.c12
-rw-r--r--sound/soc/omap/omap-mcbsp.h3
-rw-r--r--sound/soc/omap/omap-pcm.c5
-rw-r--r--sound/soc/omap/omap-pcm.h3
-rw-r--r--sound/soc/omap/osk5912.c4
-rw-r--r--sound/soc/pxa/magician.c2
-rw-r--r--sound/soc/pxa/palm27x.c27
-rw-r--r--sound/soc/pxa/pxa-ssp.c37
-rw-r--r--sound/soc/s3c24xx/Kconfig6
-rw-r--r--sound/soc/s3c24xx/jive_wm8750.c12
-rw-r--r--sound/soc/s3c24xx/s3c-i2s-v2.c21
-rw-r--r--sound/soc/s3c24xx/s3c2412-i2s.c2
-rw-r--r--sound/soc/sh/dma-sh7760.c3
-rw-r--r--sound/soc/soc-core.c3
-rw-r--r--sound/sparc/dbri.c3
-rw-r--r--sound/usb/caiaq/Makefile4
-rw-r--r--sound/usb/caiaq/audio.c (renamed from sound/usb/caiaq/caiaq-audio.c)24
-rw-r--r--sound/usb/caiaq/audio.h (renamed from sound/usb/caiaq/caiaq-audio.h)0
-rw-r--r--sound/usb/caiaq/control.c (renamed from sound/usb/caiaq/caiaq-control.c)10
-rw-r--r--sound/usb/caiaq/control.h (renamed from sound/usb/caiaq/caiaq-control.h)0
-rw-r--r--sound/usb/caiaq/device.c (renamed from sound/usb/caiaq/caiaq-device.c)25
-rw-r--r--sound/usb/caiaq/device.h (renamed from sound/usb/caiaq/caiaq-device.h)0
-rw-r--r--sound/usb/caiaq/input.c (renamed from sound/usb/caiaq/caiaq-input.c)11
-rw-r--r--sound/usb/caiaq/input.h (renamed from sound/usb/caiaq/caiaq-input.h)0
-rw-r--r--sound/usb/caiaq/midi.c (renamed from sound/usb/caiaq/caiaq-midi.c)13
-rw-r--r--sound/usb/caiaq/midi.h (renamed from sound/usb/caiaq/caiaq-midi.h)0
-rw-r--r--sound/usb/usx2y/us122l.c22
-rw-r--r--sound/usb/usx2y/usX2Yhwdep.c13
-rw-r--r--sound/usb/usx2y/usb_stream.c67
-rw-r--r--sound/usb/usx2y/usbusx2yaudio.c3
71 files changed, 958 insertions, 564 deletions
diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
index 15500b9d2da0..84bb07d39a7f 100644
--- a/sound/aoa/codecs/onyx.c
+++ b/sound/aoa/codecs/onyx.c
@@ -47,7 +47,7 @@ MODULE_DESCRIPTION("pcm3052 (onyx) codec driver for snd-aoa");
47struct onyx { 47struct onyx {
48 /* cache registers 65 to 80, they are write-only! */ 48 /* cache registers 65 to 80, they are write-only! */
49 u8 cache[16]; 49 u8 cache[16];
50 struct i2c_client i2c; 50 struct i2c_client *i2c;
51 struct aoa_codec codec; 51 struct aoa_codec codec;
52 u32 initialised:1, 52 u32 initialised:1,
53 spdif_locked:1, 53 spdif_locked:1,
@@ -72,7 +72,7 @@ static int onyx_read_register(struct onyx *onyx, u8 reg, u8 *value)
72 *value = onyx->cache[reg-FIRSTREGISTER]; 72 *value = onyx->cache[reg-FIRSTREGISTER];
73 return 0; 73 return 0;
74 } 74 }
75 v = i2c_smbus_read_byte_data(&onyx->i2c, reg); 75 v = i2c_smbus_read_byte_data(onyx->i2c, reg);
76 if (v < 0) 76 if (v < 0)
77 return -1; 77 return -1;
78 *value = (u8)v; 78 *value = (u8)v;
@@ -84,7 +84,7 @@ static int onyx_write_register(struct onyx *onyx, u8 reg, u8 value)
84{ 84{
85 int result; 85 int result;
86 86
87 result = i2c_smbus_write_byte_data(&onyx->i2c, reg, value); 87 result = i2c_smbus_write_byte_data(onyx->i2c, reg, value);
88 if (!result) 88 if (!result)
89 onyx->cache[reg-FIRSTREGISTER] = value; 89 onyx->cache[reg-FIRSTREGISTER] = value;
90 return result; 90 return result;
@@ -996,12 +996,45 @@ static void onyx_exit_codec(struct aoa_codec *codec)
996 onyx->codec.soundbus_dev->detach_codec(onyx->codec.soundbus_dev, onyx); 996 onyx->codec.soundbus_dev->detach_codec(onyx->codec.soundbus_dev, onyx);
997} 997}
998 998
999static struct i2c_driver onyx_driver;
1000
1001static int onyx_create(struct i2c_adapter *adapter, 999static int onyx_create(struct i2c_adapter *adapter,
1002 struct device_node *node, 1000 struct device_node *node,
1003 int addr) 1001 int addr)
1004{ 1002{
1003 struct i2c_board_info info;
1004 struct i2c_client *client;
1005
1006 memset(&info, 0, sizeof(struct i2c_board_info));
1007 strlcpy(info.type, "aoa_codec_onyx", I2C_NAME_SIZE);
1008 info.addr = addr;
1009 info.platform_data = node;
1010 client = i2c_new_device(adapter, &info);
1011 if (!client)
1012 return -ENODEV;
1013
1014 /*
1015 * We know the driver is already loaded, so the device should be
1016 * already bound. If not it means binding failed, which suggests
1017 * the device doesn't really exist and should be deleted.
1018 * Ideally this would be replaced by better checks _before_
1019 * instantiating the device.
1020 */
1021 if (!client->driver) {
1022 i2c_unregister_device(client);
1023 return -ENODEV;
1024 }
1025
1026 /*
1027 * Let i2c-core delete that device on driver removal.
1028 * This is safe because i2c-core holds the core_lock mutex for us.
1029 */
1030 list_add_tail(&client->detected, &client->driver->clients);
1031 return 0;
1032}
1033
1034static int onyx_i2c_probe(struct i2c_client *client,
1035 const struct i2c_device_id *id)
1036{
1037 struct device_node *node = client->dev.platform_data;
1005 struct onyx *onyx; 1038 struct onyx *onyx;
1006 u8 dummy; 1039 u8 dummy;
1007 1040
@@ -1011,20 +1044,12 @@ static int onyx_create(struct i2c_adapter *adapter,
1011 return -ENOMEM; 1044 return -ENOMEM;
1012 1045
1013 mutex_init(&onyx->mutex); 1046 mutex_init(&onyx->mutex);
1014 onyx->i2c.driver = &onyx_driver; 1047 onyx->i2c = client;
1015 onyx->i2c.adapter = adapter; 1048 i2c_set_clientdata(client, onyx);
1016 onyx->i2c.addr = addr & 0x7f;
1017 strlcpy(onyx->i2c.name, "onyx audio codec", I2C_NAME_SIZE);
1018
1019 if (i2c_attach_client(&onyx->i2c)) {
1020 printk(KERN_ERR PFX "failed to attach to i2c\n");
1021 goto fail;
1022 }
1023 1049
1024 /* we try to read from register ONYX_REG_CONTROL 1050 /* we try to read from register ONYX_REG_CONTROL
1025 * to check if the codec is present */ 1051 * to check if the codec is present */
1026 if (onyx_read_register(onyx, ONYX_REG_CONTROL, &dummy) != 0) { 1052 if (onyx_read_register(onyx, ONYX_REG_CONTROL, &dummy) != 0) {
1027 i2c_detach_client(&onyx->i2c);
1028 printk(KERN_ERR PFX "failed to read control register\n"); 1053 printk(KERN_ERR PFX "failed to read control register\n");
1029 goto fail; 1054 goto fail;
1030 } 1055 }
@@ -1036,14 +1061,14 @@ static int onyx_create(struct i2c_adapter *adapter,
1036 onyx->codec.node = of_node_get(node); 1061 onyx->codec.node = of_node_get(node);
1037 1062
1038 if (aoa_codec_register(&onyx->codec)) { 1063 if (aoa_codec_register(&onyx->codec)) {
1039 i2c_detach_client(&onyx->i2c);
1040 goto fail; 1064 goto fail;
1041 } 1065 }
1042 printk(KERN_DEBUG PFX "created and attached onyx instance\n"); 1066 printk(KERN_DEBUG PFX "created and attached onyx instance\n");
1043 return 0; 1067 return 0;
1044 fail: 1068 fail:
1069 i2c_set_clientdata(client, NULL);
1045 kfree(onyx); 1070 kfree(onyx);
1046 return -EINVAL; 1071 return -ENODEV;
1047} 1072}
1048 1073
1049static int onyx_i2c_attach(struct i2c_adapter *adapter) 1074static int onyx_i2c_attach(struct i2c_adapter *adapter)
@@ -1080,28 +1105,33 @@ static int onyx_i2c_attach(struct i2c_adapter *adapter)
1080 return onyx_create(adapter, NULL, 0x47); 1105 return onyx_create(adapter, NULL, 0x47);
1081} 1106}
1082 1107
1083static int onyx_i2c_detach(struct i2c_client *client) 1108static int onyx_i2c_remove(struct i2c_client *client)
1084{ 1109{
1085 struct onyx *onyx = container_of(client, struct onyx, i2c); 1110 struct onyx *onyx = i2c_get_clientdata(client);
1086 int err;
1087 1111
1088 if ((err = i2c_detach_client(client)))
1089 return err;
1090 aoa_codec_unregister(&onyx->codec); 1112 aoa_codec_unregister(&onyx->codec);
1091 of_node_put(onyx->codec.node); 1113 of_node_put(onyx->codec.node);
1092 if (onyx->codec_info) 1114 if (onyx->codec_info)
1093 kfree(onyx->codec_info); 1115 kfree(onyx->codec_info);
1116 i2c_set_clientdata(client, onyx);
1094 kfree(onyx); 1117 kfree(onyx);
1095 return 0; 1118 return 0;
1096} 1119}
1097 1120
1121static const struct i2c_device_id onyx_i2c_id[] = {
1122 { "aoa_codec_onyx", 0 },
1123 { }
1124};
1125
1098static struct i2c_driver onyx_driver = { 1126static struct i2c_driver onyx_driver = {
1099 .driver = { 1127 .driver = {
1100 .name = "aoa_codec_onyx", 1128 .name = "aoa_codec_onyx",
1101 .owner = THIS_MODULE, 1129 .owner = THIS_MODULE,
1102 }, 1130 },
1103 .attach_adapter = onyx_i2c_attach, 1131 .attach_adapter = onyx_i2c_attach,
1104 .detach_client = onyx_i2c_detach, 1132 .probe = onyx_i2c_probe,
1133 .remove = onyx_i2c_remove,
1134 .id_table = onyx_i2c_id,
1105}; 1135};
1106 1136
1107static int __init onyx_init(void) 1137static int __init onyx_init(void)
diff --git a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c
index 008e0f85097d..f0ebc971c686 100644
--- a/sound/aoa/codecs/tas.c
+++ b/sound/aoa/codecs/tas.c
@@ -82,7 +82,7 @@ MODULE_DESCRIPTION("tas codec driver for snd-aoa");
82 82
83struct tas { 83struct tas {
84 struct aoa_codec codec; 84 struct aoa_codec codec;
85 struct i2c_client i2c; 85 struct i2c_client *i2c;
86 u32 mute_l:1, mute_r:1 , 86 u32 mute_l:1, mute_r:1 ,
87 controls_created:1 , 87 controls_created:1 ,
88 drc_enabled:1, 88 drc_enabled:1,
@@ -108,9 +108,9 @@ static struct tas *codec_to_tas(struct aoa_codec *codec)
108static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data) 108static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data)
109{ 109{
110 if (len == 1) 110 if (len == 1)
111 return i2c_smbus_write_byte_data(&tas->i2c, reg, *data); 111 return i2c_smbus_write_byte_data(tas->i2c, reg, *data);
112 else 112 else
113 return i2c_smbus_write_i2c_block_data(&tas->i2c, reg, len, data); 113 return i2c_smbus_write_i2c_block_data(tas->i2c, reg, len, data);
114} 114}
115 115
116static void tas3004_set_drc(struct tas *tas) 116static void tas3004_set_drc(struct tas *tas)
@@ -882,12 +882,34 @@ static void tas_exit_codec(struct aoa_codec *codec)
882} 882}
883 883
884 884
885static struct i2c_driver tas_driver;
886
887static int tas_create(struct i2c_adapter *adapter, 885static int tas_create(struct i2c_adapter *adapter,
888 struct device_node *node, 886 struct device_node *node,
889 int addr) 887 int addr)
890{ 888{
889 struct i2c_board_info info;
890 struct i2c_client *client;
891
892 memset(&info, 0, sizeof(struct i2c_board_info));
893 strlcpy(info.type, "aoa_codec_tas", I2C_NAME_SIZE);
894 info.addr = addr;
895 info.platform_data = node;
896
897 client = i2c_new_device(adapter, &info);
898 if (!client)
899 return -ENODEV;
900
901 /*
902 * Let i2c-core delete that device on driver removal.
903 * This is safe because i2c-core holds the core_lock mutex for us.
904 */
905 list_add_tail(&client->detected, &client->driver->clients);
906 return 0;
907}
908
909static int tas_i2c_probe(struct i2c_client *client,
910 const struct i2c_device_id *id)
911{
912 struct device_node *node = client->dev.platform_data;
891 struct tas *tas; 913 struct tas *tas;
892 914
893 tas = kzalloc(sizeof(struct tas), GFP_KERNEL); 915 tas = kzalloc(sizeof(struct tas), GFP_KERNEL);
@@ -896,17 +918,11 @@ static int tas_create(struct i2c_adapter *adapter,
896 return -ENOMEM; 918 return -ENOMEM;
897 919
898 mutex_init(&tas->mtx); 920 mutex_init(&tas->mtx);
899 tas->i2c.driver = &tas_driver; 921 tas->i2c = client;
900 tas->i2c.adapter = adapter; 922 i2c_set_clientdata(client, tas);
901 tas->i2c.addr = addr; 923
902 /* seems that half is a saner default */ 924 /* seems that half is a saner default */
903 tas->drc_range = TAS3004_DRC_MAX / 2; 925 tas->drc_range = TAS3004_DRC_MAX / 2;
904 strlcpy(tas->i2c.name, "tas audio codec", I2C_NAME_SIZE);
905
906 if (i2c_attach_client(&tas->i2c)) {
907 printk(KERN_ERR PFX "failed to attach to i2c\n");
908 goto fail;
909 }
910 926
911 strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN); 927 strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN);
912 tas->codec.owner = THIS_MODULE; 928 tas->codec.owner = THIS_MODULE;
@@ -915,14 +931,12 @@ static int tas_create(struct i2c_adapter *adapter,
915 tas->codec.node = of_node_get(node); 931 tas->codec.node = of_node_get(node);
916 932
917 if (aoa_codec_register(&tas->codec)) { 933 if (aoa_codec_register(&tas->codec)) {
918 goto detach; 934 goto fail;
919 } 935 }
920 printk(KERN_DEBUG 936 printk(KERN_DEBUG
921 "snd-aoa-codec-tas: tas found, addr 0x%02x on %s\n", 937 "snd-aoa-codec-tas: tas found, addr 0x%02x on %s\n",
922 addr, node->full_name); 938 (unsigned int)client->addr, node->full_name);
923 return 0; 939 return 0;
924 detach:
925 i2c_detach_client(&tas->i2c);
926 fail: 940 fail:
927 mutex_destroy(&tas->mtx); 941 mutex_destroy(&tas->mtx);
928 kfree(tas); 942 kfree(tas);
@@ -970,14 +984,11 @@ static int tas_i2c_attach(struct i2c_adapter *adapter)
970 return -ENODEV; 984 return -ENODEV;
971} 985}
972 986
973static int tas_i2c_detach(struct i2c_client *client) 987static int tas_i2c_remove(struct i2c_client *client)
974{ 988{
975 struct tas *tas = container_of(client, struct tas, i2c); 989 struct tas *tas = i2c_get_clientdata(client);
976 int err;
977 u8 tmp = TAS_ACR_ANALOG_PDOWN; 990 u8 tmp = TAS_ACR_ANALOG_PDOWN;
978 991
979 if ((err = i2c_detach_client(client)))
980 return err;
981 aoa_codec_unregister(&tas->codec); 992 aoa_codec_unregister(&tas->codec);
982 of_node_put(tas->codec.node); 993 of_node_put(tas->codec.node);
983 994
@@ -989,13 +1000,20 @@ static int tas_i2c_detach(struct i2c_client *client)
989 return 0; 1000 return 0;
990} 1001}
991 1002
1003static const struct i2c_device_id tas_i2c_id[] = {
1004 { "aoa_codec_tas", 0 },
1005 { }
1006};
1007
992static struct i2c_driver tas_driver = { 1008static struct i2c_driver tas_driver = {
993 .driver = { 1009 .driver = {
994 .name = "aoa_codec_tas", 1010 .name = "aoa_codec_tas",
995 .owner = THIS_MODULE, 1011 .owner = THIS_MODULE,
996 }, 1012 },
997 .attach_adapter = tas_i2c_attach, 1013 .attach_adapter = tas_i2c_attach,
998 .detach_client = tas_i2c_detach, 1014 .probe = tas_i2c_probe,
1015 .remove = tas_i2c_remove,
1016 .id_table = tas_i2c_id,
999}; 1017};
1000 1018
1001static int __init tas_init(void) 1019static int __init tas_init(void)
diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c
index 7fbd68fab944..5c48e36038f2 100644
--- a/sound/arm/aaci.c
+++ b/sound/arm/aaci.c
@@ -1074,7 +1074,7 @@ static unsigned int __devinit aaci_size_fifo(struct aaci *aaci)
1074 return i; 1074 return i;
1075} 1075}
1076 1076
1077static int __devinit aaci_probe(struct amba_device *dev, void *id) 1077static int __devinit aaci_probe(struct amba_device *dev, struct amba_id *id)
1078{ 1078{
1079 struct aaci *aaci; 1079 struct aaci *aaci;
1080 int ret, i; 1080 int ret, i;
diff --git a/sound/arm/pxa2xx-ac97-lib.c b/sound/arm/pxa2xx-ac97-lib.c
index 0afd1a8226fb..6fdca97186e7 100644
--- a/sound/arm/pxa2xx-ac97-lib.c
+++ b/sound/arm/pxa2xx-ac97-lib.c
@@ -65,7 +65,7 @@ static void set_resetgpio_mode(int resetgpio_action)
65 switch (resetgpio_action) { 65 switch (resetgpio_action) {
66 case RESETGPIO_NORMAL_ALTFUNC: 66 case RESETGPIO_NORMAL_ALTFUNC:
67 if (reset_gpio == 113) 67 if (reset_gpio == 113)
68 mode = 113 | GPIO_OUT | GPIO_DFLT_LOW; 68 mode = 113 | GPIO_ALT_FN_2_OUT;
69 if (reset_gpio == 95) 69 if (reset_gpio == 95)
70 mode = 95 | GPIO_ALT_FN_1_OUT; 70 mode = 95 | GPIO_ALT_FN_1_OUT;
71 break; 71 break;
@@ -364,7 +364,7 @@ EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_resume);
364int __devinit pxa2xx_ac97_hw_probe(struct platform_device *dev) 364int __devinit pxa2xx_ac97_hw_probe(struct platform_device *dev)
365{ 365{
366 int ret; 366 int ret;
367 struct pxa2xx_ac97_platform_data *pdata = dev->dev.platform_data; 367 pxa2xx_audio_ops_t *pdata = dev->dev.platform_data;
368 368
369 if (pdata) { 369 if (pdata) {
370 switch (pdata->reset_gpio) { 370 switch (pdata->reset_gpio) {
diff --git a/sound/core/control.c b/sound/core/control.c
index 4b20fa2b7e6d..17b8d47a5cd0 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -723,14 +723,11 @@ static int snd_ctl_elem_read_user(struct snd_card *card,
723{ 723{
724 struct snd_ctl_elem_value *control; 724 struct snd_ctl_elem_value *control;
725 int result; 725 int result;
726 726
727 control = kmalloc(sizeof(*control), GFP_KERNEL); 727 control = memdup_user(_control, sizeof(*control));
728 if (control == NULL) 728 if (IS_ERR(control))
729 return -ENOMEM; 729 return PTR_ERR(control);
730 if (copy_from_user(control, _control, sizeof(*control))) { 730
731 kfree(control);
732 return -EFAULT;
733 }
734 snd_power_lock(card); 731 snd_power_lock(card);
735 result = snd_power_wait(card, SNDRV_CTL_POWER_D0); 732 result = snd_power_wait(card, SNDRV_CTL_POWER_D0);
736 if (result >= 0) 733 if (result >= 0)
@@ -784,13 +781,10 @@ static int snd_ctl_elem_write_user(struct snd_ctl_file *file,
784 struct snd_card *card; 781 struct snd_card *card;
785 int result; 782 int result;
786 783
787 control = kmalloc(sizeof(*control), GFP_KERNEL); 784 control = memdup_user(_control, sizeof(*control));
788 if (control == NULL) 785 if (IS_ERR(control))
789 return -ENOMEM; 786 return PTR_ERR(control);
790 if (copy_from_user(control, _control, sizeof(*control))) { 787
791 kfree(control);
792 return -EFAULT;
793 }
794 card = file->card; 788 card = file->card;
795 snd_power_lock(card); 789 snd_power_lock(card);
796 result = snd_power_wait(card, SNDRV_CTL_POWER_D0); 790 result = snd_power_wait(card, SNDRV_CTL_POWER_D0);
@@ -916,13 +910,10 @@ static int snd_ctl_elem_user_tlv(struct snd_kcontrol *kcontrol,
916 if (op_flag > 0) { 910 if (op_flag > 0) {
917 if (size > 1024 * 128) /* sane value */ 911 if (size > 1024 * 128) /* sane value */
918 return -EINVAL; 912 return -EINVAL;
919 new_data = kmalloc(size, GFP_KERNEL); 913
920 if (new_data == NULL) 914 new_data = memdup_user(tlv, size);
921 return -ENOMEM; 915 if (IS_ERR(new_data))
922 if (copy_from_user(new_data, tlv, size)) { 916 return PTR_ERR(new_data);
923 kfree(new_data);
924 return -EFAULT;
925 }
926 change = ue->tlv_data_size != size; 917 change = ue->tlv_data_size != size;
927 if (!change) 918 if (!change)
928 change = memcmp(ue->tlv_data, new_data, size); 919 change = memcmp(ue->tlv_data, new_data, size);
diff --git a/sound/core/jack.c b/sound/core/jack.c
index c8254c667c62..d54d1a05fe65 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -35,6 +35,9 @@ static int snd_jack_dev_free(struct snd_device *device)
35{ 35{
36 struct snd_jack *jack = device->device_data; 36 struct snd_jack *jack = device->device_data;
37 37
38 if (jack->private_free)
39 jack->private_free(jack);
40
38 /* If the input device is registered with the input subsystem 41 /* If the input device is registered with the input subsystem
39 * then we need to use a different deallocator. */ 42 * then we need to use a different deallocator. */
40 if (jack->registered) 43 if (jack->registered)
diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
index 36d7a5998234..08bfed594a83 100644
--- a/sound/core/pcm_compat.c
+++ b/sound/core/pcm_compat.c
@@ -232,14 +232,11 @@ static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream,
232 if (! (runtime = substream->runtime)) 232 if (! (runtime = substream->runtime))
233 return -ENOTTY; 233 return -ENOTTY;
234 234
235 data = kmalloc(sizeof(*data), GFP_KERNEL);
236 if (data == NULL)
237 return -ENOMEM;
238 /* only fifo_size is different, so just copy all */ 235 /* only fifo_size is different, so just copy all */
239 if (copy_from_user(data, data32, sizeof(*data32))) { 236 data = memdup_user(data32, sizeof(*data32));
240 err = -EFAULT; 237 if (IS_ERR(data))
241 goto error; 238 return PTR_ERR(data);
242 } 239
243 if (refine) 240 if (refine)
244 err = snd_pcm_hw_refine(substream, data); 241 err = snd_pcm_hw_refine(substream, data);
245 else 242 else
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index fbb2e391591e..a2a792c18c40 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -209,9 +209,11 @@ static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
209{ 209{
210 struct snd_pcm_runtime *runtime = substream->runtime; 210 struct snd_pcm_runtime *runtime = substream->runtime;
211 snd_pcm_uframes_t pos; 211 snd_pcm_uframes_t pos;
212 snd_pcm_uframes_t new_hw_ptr, hw_ptr_interrupt, hw_base; 212 snd_pcm_uframes_t old_hw_ptr, new_hw_ptr, hw_ptr_interrupt, hw_base;
213 snd_pcm_sframes_t delta; 213 snd_pcm_sframes_t hdelta, delta;
214 unsigned long jdelta;
214 215
216 old_hw_ptr = runtime->status->hw_ptr;
215 pos = snd_pcm_update_hw_ptr_pos(substream, runtime); 217 pos = snd_pcm_update_hw_ptr_pos(substream, runtime);
216 if (pos == SNDRV_PCM_POS_XRUN) { 218 if (pos == SNDRV_PCM_POS_XRUN) {
217 xrun(substream); 219 xrun(substream);
@@ -247,7 +249,37 @@ static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
247 new_hw_ptr = hw_base + pos; 249 new_hw_ptr = hw_base + pos;
248 } 250 }
249 } 251 }
250 if (delta > runtime->period_size) { 252 /* Skip the jiffies check for hardwares with BATCH flag.
253 * Such hardware usually just increases the position at each IRQ,
254 * thus it can't give any strange position.
255 */
256 if (runtime->hw.info & SNDRV_PCM_INFO_BATCH)
257 goto no_jiffies_check;
258 hdelta = new_hw_ptr - old_hw_ptr;
259 jdelta = jiffies - runtime->hw_ptr_jiffies;
260 if (((hdelta * HZ) / runtime->rate) > jdelta + HZ/100) {
261 delta = jdelta /
262 (((runtime->period_size * HZ) / runtime->rate)
263 + HZ/100);
264 hw_ptr_error(substream,
265 "hw_ptr skipping! [Q] "
266 "(pos=%ld, delta=%ld, period=%ld, "
267 "jdelta=%lu/%lu/%lu)\n",
268 (long)pos, (long)hdelta,
269 (long)runtime->period_size, jdelta,
270 ((hdelta * HZ) / runtime->rate), delta);
271 hw_ptr_interrupt = runtime->hw_ptr_interrupt +
272 runtime->period_size * delta;
273 if (hw_ptr_interrupt >= runtime->boundary)
274 hw_ptr_interrupt -= runtime->boundary;
275 /* rebase to interrupt position */
276 hw_base = new_hw_ptr = hw_ptr_interrupt;
277 /* align hw_base to buffer_size */
278 hw_base -= hw_base % runtime->buffer_size;
279 delta = 0;
280 }
281 no_jiffies_check:
282 if (delta > runtime->period_size + runtime->period_size / 2) {
251 hw_ptr_error(substream, 283 hw_ptr_error(substream,
252 "Lost interrupts? " 284 "Lost interrupts? "
253 "(stream=%i, delta=%ld, intr_ptr=%ld)\n", 285 "(stream=%i, delta=%ld, intr_ptr=%ld)\n",
@@ -263,6 +295,7 @@ static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
263 295
264 runtime->hw_ptr_base = hw_base; 296 runtime->hw_ptr_base = hw_base;
265 runtime->status->hw_ptr = new_hw_ptr; 297 runtime->status->hw_ptr = new_hw_ptr;
298 runtime->hw_ptr_jiffies = jiffies;
266 runtime->hw_ptr_interrupt = hw_ptr_interrupt; 299 runtime->hw_ptr_interrupt = hw_ptr_interrupt;
267 300
268 return snd_pcm_update_hw_ptr_post(substream, runtime); 301 return snd_pcm_update_hw_ptr_post(substream, runtime);
@@ -275,6 +308,7 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream)
275 snd_pcm_uframes_t pos; 308 snd_pcm_uframes_t pos;
276 snd_pcm_uframes_t old_hw_ptr, new_hw_ptr, hw_base; 309 snd_pcm_uframes_t old_hw_ptr, new_hw_ptr, hw_base;
277 snd_pcm_sframes_t delta; 310 snd_pcm_sframes_t delta;
311 unsigned long jdelta;
278 312
279 old_hw_ptr = runtime->status->hw_ptr; 313 old_hw_ptr = runtime->status->hw_ptr;
280 pos = snd_pcm_update_hw_ptr_pos(substream, runtime); 314 pos = snd_pcm_update_hw_ptr_pos(substream, runtime);
@@ -286,14 +320,15 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream)
286 new_hw_ptr = hw_base + pos; 320 new_hw_ptr = hw_base + pos;
287 321
288 delta = new_hw_ptr - old_hw_ptr; 322 delta = new_hw_ptr - old_hw_ptr;
323 jdelta = jiffies - runtime->hw_ptr_jiffies;
289 if (delta < 0) { 324 if (delta < 0) {
290 delta += runtime->buffer_size; 325 delta += runtime->buffer_size;
291 if (delta < 0) { 326 if (delta < 0) {
292 hw_ptr_error(substream, 327 hw_ptr_error(substream,
293 "Unexpected hw_pointer value [2] " 328 "Unexpected hw_pointer value [2] "
294 "(stream=%i, pos=%ld, old_ptr=%ld)\n", 329 "(stream=%i, pos=%ld, old_ptr=%ld, jdelta=%li)\n",
295 substream->stream, (long)pos, 330 substream->stream, (long)pos,
296 (long)old_hw_ptr); 331 (long)old_hw_ptr, jdelta);
297 return 0; 332 return 0;
298 } 333 }
299 hw_base += runtime->buffer_size; 334 hw_base += runtime->buffer_size;
@@ -301,12 +336,13 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream)
301 hw_base = 0; 336 hw_base = 0;
302 new_hw_ptr = hw_base + pos; 337 new_hw_ptr = hw_base + pos;
303 } 338 }
304 if (delta > runtime->period_size && runtime->periods > 1) { 339 if (((delta * HZ) / runtime->rate) > jdelta + HZ/100) {
305 hw_ptr_error(substream, 340 hw_ptr_error(substream,
306 "hw_ptr skipping! " 341 "hw_ptr skipping! "
307 "(pos=%ld, delta=%ld, period=%ld)\n", 342 "(pos=%ld, delta=%ld, period=%ld, jdelta=%lu/%lu)\n",
308 (long)pos, (long)delta, 343 (long)pos, (long)delta,
309 (long)runtime->period_size); 344 (long)runtime->period_size, jdelta,
345 ((delta * HZ) / runtime->rate));
310 return 0; 346 return 0;
311 } 347 }
312 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && 348 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
@@ -315,6 +351,7 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream)
315 351
316 runtime->hw_ptr_base = hw_base; 352 runtime->hw_ptr_base = hw_base;
317 runtime->status->hw_ptr = new_hw_ptr; 353 runtime->status->hw_ptr = new_hw_ptr;
354 runtime->hw_ptr_jiffies = jiffies;
318 355
319 return snd_pcm_update_hw_ptr_post(substream, runtime); 356 return snd_pcm_update_hw_ptr_post(substream, runtime);
320} 357}
@@ -1441,6 +1478,7 @@ static int snd_pcm_lib_ioctl_reset(struct snd_pcm_substream *substream,
1441 runtime->status->hw_ptr %= runtime->buffer_size; 1478 runtime->status->hw_ptr %= runtime->buffer_size;
1442 else 1479 else
1443 runtime->status->hw_ptr = 0; 1480 runtime->status->hw_ptr = 0;
1481 runtime->hw_ptr_jiffies = jiffies;
1444 snd_pcm_stream_unlock_irqrestore(substream, flags); 1482 snd_pcm_stream_unlock_irqrestore(substream, flags);
1445 return 0; 1483 return 0;
1446} 1484}
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index a151fb01ba82..fc6f98e257df 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -327,21 +327,16 @@ static int snd_pcm_hw_refine_user(struct snd_pcm_substream *substream,
327 struct snd_pcm_hw_params *params; 327 struct snd_pcm_hw_params *params;
328 int err; 328 int err;
329 329
330 params = kmalloc(sizeof(*params), GFP_KERNEL); 330 params = memdup_user(_params, sizeof(*params));
331 if (!params) { 331 if (IS_ERR(params))
332 err = -ENOMEM; 332 return PTR_ERR(params);
333 goto out; 333
334 }
335 if (copy_from_user(params, _params, sizeof(*params))) {
336 err = -EFAULT;
337 goto out;
338 }
339 err = snd_pcm_hw_refine(substream, params); 334 err = snd_pcm_hw_refine(substream, params);
340 if (copy_to_user(_params, params, sizeof(*params))) { 335 if (copy_to_user(_params, params, sizeof(*params))) {
341 if (!err) 336 if (!err)
342 err = -EFAULT; 337 err = -EFAULT;
343 } 338 }
344out: 339
345 kfree(params); 340 kfree(params);
346 return err; 341 return err;
347} 342}
@@ -465,21 +460,16 @@ static int snd_pcm_hw_params_user(struct snd_pcm_substream *substream,
465 struct snd_pcm_hw_params *params; 460 struct snd_pcm_hw_params *params;
466 int err; 461 int err;
467 462
468 params = kmalloc(sizeof(*params), GFP_KERNEL); 463 params = memdup_user(_params, sizeof(*params));
469 if (!params) { 464 if (IS_ERR(params))
470 err = -ENOMEM; 465 return PTR_ERR(params);
471 goto out; 466
472 }
473 if (copy_from_user(params, _params, sizeof(*params))) {
474 err = -EFAULT;
475 goto out;
476 }
477 err = snd_pcm_hw_params(substream, params); 467 err = snd_pcm_hw_params(substream, params);
478 if (copy_to_user(_params, params, sizeof(*params))) { 468 if (copy_to_user(_params, params, sizeof(*params))) {
479 if (!err) 469 if (!err)
480 err = -EFAULT; 470 err = -EFAULT;
481 } 471 }
482out: 472
483 kfree(params); 473 kfree(params);
484 return err; 474 return err;
485} 475}
@@ -2593,13 +2583,11 @@ static int snd_pcm_playback_ioctl1(struct file *file,
2593 return -EFAULT; 2583 return -EFAULT;
2594 if (copy_from_user(&xfern, _xfern, sizeof(xfern))) 2584 if (copy_from_user(&xfern, _xfern, sizeof(xfern)))
2595 return -EFAULT; 2585 return -EFAULT;
2596 bufs = kmalloc(sizeof(void *) * runtime->channels, GFP_KERNEL); 2586
2597 if (bufs == NULL) 2587 bufs = memdup_user(xfern.bufs,
2598 return -ENOMEM; 2588 sizeof(void *) * runtime->channels);
2599 if (copy_from_user(bufs, xfern.bufs, sizeof(void *) * runtime->channels)) { 2589 if (IS_ERR(bufs))
2600 kfree(bufs); 2590 return PTR_ERR(bufs);
2601 return -EFAULT;
2602 }
2603 result = snd_pcm_lib_writev(substream, bufs, xfern.frames); 2591 result = snd_pcm_lib_writev(substream, bufs, xfern.frames);
2604 kfree(bufs); 2592 kfree(bufs);
2605 __put_user(result, &_xfern->result); 2593 __put_user(result, &_xfern->result);
@@ -2675,13 +2663,11 @@ static int snd_pcm_capture_ioctl1(struct file *file,
2675 return -EFAULT; 2663 return -EFAULT;
2676 if (copy_from_user(&xfern, _xfern, sizeof(xfern))) 2664 if (copy_from_user(&xfern, _xfern, sizeof(xfern)))
2677 return -EFAULT; 2665 return -EFAULT;
2678 bufs = kmalloc(sizeof(void *) * runtime->channels, GFP_KERNEL); 2666
2679 if (bufs == NULL) 2667 bufs = memdup_user(xfern.bufs,
2680 return -ENOMEM; 2668 sizeof(void *) * runtime->channels);
2681 if (copy_from_user(bufs, xfern.bufs, sizeof(void *) * runtime->channels)) { 2669 if (IS_ERR(bufs))
2682 kfree(bufs); 2670 return PTR_ERR(bufs);
2683 return -EFAULT;
2684 }
2685 result = snd_pcm_lib_readv(substream, bufs, xfern.frames); 2671 result = snd_pcm_lib_readv(substream, bufs, xfern.frames);
2686 kfree(bufs); 2672 kfree(bufs);
2687 __put_user(result, &_xfern->result); 2673 __put_user(result, &_xfern->result);
@@ -3312,18 +3298,12 @@ static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream,
3312 int err; 3298 int err;
3313 3299
3314 params = kmalloc(sizeof(*params), GFP_KERNEL); 3300 params = kmalloc(sizeof(*params), GFP_KERNEL);
3315 if (!params) { 3301 if (!params)
3316 err = -ENOMEM; 3302 return -ENOMEM;
3317 goto out;
3318 }
3319 oparams = kmalloc(sizeof(*oparams), GFP_KERNEL);
3320 if (!oparams) {
3321 err = -ENOMEM;
3322 goto out;
3323 }
3324 3303
3325 if (copy_from_user(oparams, _oparams, sizeof(*oparams))) { 3304 oparams = memdup_user(_oparams, sizeof(*oparams));
3326 err = -EFAULT; 3305 if (IS_ERR(oparams)) {
3306 err = PTR_ERR(oparams);
3327 goto out; 3307 goto out;
3328 } 3308 }
3329 snd_pcm_hw_convert_from_old_params(params, oparams); 3309 snd_pcm_hw_convert_from_old_params(params, oparams);
@@ -3333,9 +3313,10 @@ static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream,
3333 if (!err) 3313 if (!err)
3334 err = -EFAULT; 3314 err = -EFAULT;
3335 } 3315 }
3316
3317 kfree(oparams);
3336out: 3318out:
3337 kfree(params); 3319 kfree(params);
3338 kfree(oparams);
3339 return err; 3320 return err;
3340} 3321}
3341 3322
@@ -3347,17 +3328,12 @@ static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream,
3347 int err; 3328 int err;
3348 3329
3349 params = kmalloc(sizeof(*params), GFP_KERNEL); 3330 params = kmalloc(sizeof(*params), GFP_KERNEL);
3350 if (!params) { 3331 if (!params)
3351 err = -ENOMEM; 3332 return -ENOMEM;
3352 goto out; 3333
3353 } 3334 oparams = memdup_user(_oparams, sizeof(*oparams));
3354 oparams = kmalloc(sizeof(*oparams), GFP_KERNEL); 3335 if (IS_ERR(oparams)) {
3355 if (!oparams) { 3336 err = PTR_ERR(oparams);
3356 err = -ENOMEM;
3357 goto out;
3358 }
3359 if (copy_from_user(oparams, _oparams, sizeof(*oparams))) {
3360 err = -EFAULT;
3361 goto out; 3337 goto out;
3362 } 3338 }
3363 snd_pcm_hw_convert_from_old_params(params, oparams); 3339 snd_pcm_hw_convert_from_old_params(params, oparams);
@@ -3367,9 +3343,10 @@ static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream,
3367 if (!err) 3343 if (!err)
3368 err = -EFAULT; 3344 err = -EFAULT;
3369 } 3345 }
3346
3347 kfree(oparams);
3370out: 3348out:
3371 kfree(params); 3349 kfree(params);
3372 kfree(oparams);
3373 return err; 3350 return err;
3374} 3351}
3375#endif /* CONFIG_SND_SUPPORT_OLD_API */ 3352#endif /* CONFIG_SND_SUPPORT_OLD_API */
diff --git a/sound/core/seq/seq_compat.c b/sound/core/seq/seq_compat.c
index 38693f47c262..c956fe462569 100644
--- a/sound/core/seq/seq_compat.c
+++ b/sound/core/seq/seq_compat.c
@@ -48,12 +48,11 @@ static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsigned
48 struct snd_seq_port_info *data; 48 struct snd_seq_port_info *data;
49 mm_segment_t fs; 49 mm_segment_t fs;
50 50
51 data = kmalloc(sizeof(*data), GFP_KERNEL); 51 data = memdup_user(data32, sizeof(*data32));
52 if (! data) 52 if (IS_ERR(data))
53 return -ENOMEM; 53 return PTR_ERR(data);
54 54
55 if (copy_from_user(data, data32, sizeof(*data32)) || 55 if (get_user(data->flags, &data32->flags) ||
56 get_user(data->flags, &data32->flags) ||
57 get_user(data->time_queue, &data32->time_queue)) 56 get_user(data->time_queue, &data32->time_queue))
58 goto error; 57 goto error;
59 data->kernel = NULL; 58 data->kernel = NULL;
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 3f0050d0b71e..8f8b17ac074d 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -1395,13 +1395,10 @@ static int snd_timer_user_ginfo(struct file *file,
1395 struct list_head *p; 1395 struct list_head *p;
1396 int err = 0; 1396 int err = 0;
1397 1397
1398 ginfo = kmalloc(sizeof(*ginfo), GFP_KERNEL); 1398 ginfo = memdup_user(_ginfo, sizeof(*ginfo));
1399 if (! ginfo) 1399 if (IS_ERR(ginfo))
1400 return -ENOMEM; 1400 return PTR_ERR(ginfo);
1401 if (copy_from_user(ginfo, _ginfo, sizeof(*ginfo))) { 1401
1402 kfree(ginfo);
1403 return -EFAULT;
1404 }
1405 tid = ginfo->tid; 1402 tid = ginfo->tid;
1406 memset(ginfo, 0, sizeof(*ginfo)); 1403 memset(ginfo, 0, sizeof(*ginfo));
1407 ginfo->tid = tid; 1404 ginfo->tid = tid;
diff --git a/sound/isa/msnd/msnd.c b/sound/isa/msnd/msnd.c
index 906454413ed2..3a1526ae1729 100644
--- a/sound/isa/msnd/msnd.c
+++ b/sound/isa/msnd/msnd.c
@@ -438,7 +438,8 @@ static void snd_msnd_capture_reset_queue(struct snd_msnd *chip,
438static struct snd_pcm_hardware snd_msnd_playback = { 438static struct snd_pcm_hardware snd_msnd_playback = {
439 .info = SNDRV_PCM_INFO_MMAP | 439 .info = SNDRV_PCM_INFO_MMAP |
440 SNDRV_PCM_INFO_INTERLEAVED | 440 SNDRV_PCM_INFO_INTERLEAVED |
441 SNDRV_PCM_INFO_MMAP_VALID, 441 SNDRV_PCM_INFO_MMAP_VALID |
442 SNDRV_PCM_INFO_BATCH,
442 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 443 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
443 .rates = SNDRV_PCM_RATE_8000_48000, 444 .rates = SNDRV_PCM_RATE_8000_48000,
444 .rate_min = 8000, 445 .rate_min = 8000,
@@ -456,7 +457,8 @@ static struct snd_pcm_hardware snd_msnd_playback = {
456static struct snd_pcm_hardware snd_msnd_capture = { 457static struct snd_pcm_hardware snd_msnd_capture = {
457 .info = SNDRV_PCM_INFO_MMAP | 458 .info = SNDRV_PCM_INFO_MMAP |
458 SNDRV_PCM_INFO_INTERLEAVED | 459 SNDRV_PCM_INFO_INTERLEAVED |
459 SNDRV_PCM_INFO_MMAP_VALID, 460 SNDRV_PCM_INFO_MMAP_VALID |
461 SNDRV_PCM_INFO_BATCH,
460 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 462 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
461 .rates = SNDRV_PCM_RATE_8000_48000, 463 .rates = SNDRV_PCM_RATE_8000_48000,
462 .rate_min = 8000, 464 .rate_min = 8000,
diff --git a/sound/isa/sb/sb16_csp.c b/sound/isa/sb/sb16_csp.c
index 49037d074c71..bdc8dde4e4a2 100644
--- a/sound/isa/sb/sb16_csp.c
+++ b/sound/isa/sb/sb16_csp.c
@@ -684,15 +684,16 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int
684 684
685static int snd_sb_csp_load_user(struct snd_sb_csp * p, const unsigned char __user *buf, int size, int load_flags) 685static int snd_sb_csp_load_user(struct snd_sb_csp * p, const unsigned char __user *buf, int size, int load_flags)
686{ 686{
687 int err = -ENOMEM; 687 int err;
688 unsigned char *kbuf = kmalloc(size, GFP_KERNEL); 688 unsigned char *kbuf;
689 if (kbuf) { 689
690 if (copy_from_user(kbuf, buf, size)) 690 kbuf = memdup_user(buf, size);
691 err = -EFAULT; 691 if (IS_ERR(kbuf))
692 else 692 return PTR_ERR(kbuf);
693 err = snd_sb_csp_load(p, kbuf, size, load_flags); 693
694 kfree(kbuf); 694 err = snd_sb_csp_load(p, kbuf, size, load_flags);
695 } 695
696 kfree(kbuf);
696 return err; 697 return err;
697} 698}
698 699
diff --git a/sound/isa/wavefront/wavefront_fx.c b/sound/isa/wavefront/wavefront_fx.c
index a4345fc07561..2bb1cee09255 100644
--- a/sound/isa/wavefront/wavefront_fx.c
+++ b/sound/isa/wavefront/wavefront_fx.c
@@ -202,15 +202,11 @@ snd_wavefront_fx_ioctl (struct snd_hwdep *sdev, struct file *file,
202 "> 512 bytes to FX\n"); 202 "> 512 bytes to FX\n");
203 return -EIO; 203 return -EIO;
204 } 204 }
205 page_data = kmalloc(r.data[2] * sizeof(short), GFP_KERNEL); 205 page_data = memdup_user((unsigned char __user *)
206 if (!page_data) 206 r.data[3],
207 return -ENOMEM; 207 r.data[2] * sizeof(short));
208 if (copy_from_user (page_data, 208 if (IS_ERR(page_data))
209 (unsigned char __user *) r.data[3], 209 return PTR_ERR(page_data);
210 r.data[2] * sizeof(short))) {
211 kfree(page_data);
212 return -EFAULT;
213 }
214 pd = page_data; 210 pd = page_data;
215 } 211 }
216 212
diff --git a/sound/isa/wavefront/wavefront_synth.c b/sound/isa/wavefront/wavefront_synth.c
index beb312cca75b..5d4ff48c4345 100644
--- a/sound/isa/wavefront/wavefront_synth.c
+++ b/sound/isa/wavefront/wavefront_synth.c
@@ -1664,12 +1664,11 @@ snd_wavefront_synth_ioctl (struct snd_hwdep *hw, struct file *file,
1664 break; 1664 break;
1665 1665
1666 case WFCTL_WFCMD: 1666 case WFCTL_WFCMD:
1667 wc = kmalloc(sizeof(*wc), GFP_KERNEL); 1667 wc = memdup_user(argp, sizeof(*wc));
1668 if (! wc) 1668 if (IS_ERR(wc))
1669 return -ENOMEM; 1669 return PTR_ERR(wc);
1670 if (copy_from_user (wc, argp, sizeof (*wc))) 1670
1671 err = -EFAULT; 1671 if (wavefront_synth_control (acard, wc) < 0)
1672 else if (wavefront_synth_control (acard, wc) < 0)
1673 err = -EIO; 1672 err = -EIO;
1674 else if (copy_to_user (argp, wc, sizeof (*wc))) 1673 else if (copy_to_user (argp, wc, sizeof (*wc)))
1675 err = -EFAULT; 1674 err = -EFAULT;
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 97ee127ac33d..78288dbfc17a 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -2122,7 +2122,7 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
2122 } 2122 }
2123 /* nothing should be in powerdown mode */ 2123 /* nothing should be in powerdown mode */
2124 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0); 2124 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0);
2125 end_time = jiffies + msecs_to_jiffies(100); 2125 end_time = jiffies + msecs_to_jiffies(120);
2126 do { 2126 do {
2127 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f) 2127 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f)
2128 goto __ready_ok; 2128 goto __ready_ok;
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c
index a299340519df..ce3f2e90f4d7 100644
--- a/sound/pci/bt87x.c
+++ b/sound/pci/bt87x.c
@@ -349,7 +349,8 @@ static struct snd_pcm_hardware snd_bt87x_digital_hw = {
349 .info = SNDRV_PCM_INFO_MMAP | 349 .info = SNDRV_PCM_INFO_MMAP |
350 SNDRV_PCM_INFO_INTERLEAVED | 350 SNDRV_PCM_INFO_INTERLEAVED |
351 SNDRV_PCM_INFO_BLOCK_TRANSFER | 351 SNDRV_PCM_INFO_BLOCK_TRANSFER |
352 SNDRV_PCM_INFO_MMAP_VALID, 352 SNDRV_PCM_INFO_MMAP_VALID |
353 SNDRV_PCM_INFO_BATCH,
353 .formats = SNDRV_PCM_FMTBIT_S16_LE, 354 .formats = SNDRV_PCM_FMTBIT_S16_LE,
354 .rates = 0, /* set at runtime */ 355 .rates = 0, /* set at runtime */
355 .channels_min = 2, 356 .channels_min = 2,
@@ -365,7 +366,8 @@ static struct snd_pcm_hardware snd_bt87x_analog_hw = {
365 .info = SNDRV_PCM_INFO_MMAP | 366 .info = SNDRV_PCM_INFO_MMAP |
366 SNDRV_PCM_INFO_INTERLEAVED | 367 SNDRV_PCM_INFO_INTERLEAVED |
367 SNDRV_PCM_INFO_BLOCK_TRANSFER | 368 SNDRV_PCM_INFO_BLOCK_TRANSFER |
368 SNDRV_PCM_INFO_MMAP_VALID, 369 SNDRV_PCM_INFO_MMAP_VALID |
370 SNDRV_PCM_INFO_BATCH,
369 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8, 371 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8,
370 .rates = SNDRV_PCM_RATE_KNOT, 372 .rates = SNDRV_PCM_RATE_KNOT,
371 .rate_min = ANALOG_CLOCK / CLOCK_DIV_MAX, 373 .rate_min = ANALOG_CLOCK / CLOCK_DIV_MAX,
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 191e1cd9997d..4b302d86f5f2 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -2493,24 +2493,17 @@ static int snd_emu10k1_fx8010_ioctl(struct snd_hwdep * hw, struct file *file, un
2493 case SNDRV_EMU10K1_IOCTL_CODE_POKE: 2493 case SNDRV_EMU10K1_IOCTL_CODE_POKE:
2494 if (!capable(CAP_SYS_ADMIN)) 2494 if (!capable(CAP_SYS_ADMIN))
2495 return -EPERM; 2495 return -EPERM;
2496 icode = kmalloc(sizeof(*icode), GFP_KERNEL); 2496
2497 if (icode == NULL) 2497 icode = memdup_user(argp, sizeof(*icode));
2498 return -ENOMEM; 2498 if (IS_ERR(icode))
2499 if (copy_from_user(icode, argp, sizeof(*icode))) { 2499 return PTR_ERR(icode);
2500 kfree(icode);
2501 return -EFAULT;
2502 }
2503 res = snd_emu10k1_icode_poke(emu, icode); 2500 res = snd_emu10k1_icode_poke(emu, icode);
2504 kfree(icode); 2501 kfree(icode);
2505 return res; 2502 return res;
2506 case SNDRV_EMU10K1_IOCTL_CODE_PEEK: 2503 case SNDRV_EMU10K1_IOCTL_CODE_PEEK:
2507 icode = kmalloc(sizeof(*icode), GFP_KERNEL); 2504 icode = memdup_user(argp, sizeof(*icode));
2508 if (icode == NULL) 2505 if (IS_ERR(icode))
2509 return -ENOMEM; 2506 return PTR_ERR(icode);
2510 if (copy_from_user(icode, argp, sizeof(*icode))) {
2511 kfree(icode);
2512 return -EFAULT;
2513 }
2514 res = snd_emu10k1_icode_peek(emu, icode); 2507 res = snd_emu10k1_icode_peek(emu, icode);
2515 if (res == 0 && copy_to_user(argp, icode, sizeof(*icode))) { 2508 if (res == 0 && copy_to_user(argp, icode, sizeof(*icode))) {
2516 kfree(icode); 2509 kfree(icode);
@@ -2519,24 +2512,16 @@ static int snd_emu10k1_fx8010_ioctl(struct snd_hwdep * hw, struct file *file, un
2519 kfree(icode); 2512 kfree(icode);
2520 return res; 2513 return res;
2521 case SNDRV_EMU10K1_IOCTL_PCM_POKE: 2514 case SNDRV_EMU10K1_IOCTL_PCM_POKE:
2522 ipcm = kmalloc(sizeof(*ipcm), GFP_KERNEL); 2515 ipcm = memdup_user(argp, sizeof(*ipcm));
2523 if (ipcm == NULL) 2516 if (IS_ERR(ipcm))
2524 return -ENOMEM; 2517 return PTR_ERR(ipcm);
2525 if (copy_from_user(ipcm, argp, sizeof(*ipcm))) {
2526 kfree(ipcm);
2527 return -EFAULT;
2528 }
2529 res = snd_emu10k1_ipcm_poke(emu, ipcm); 2518 res = snd_emu10k1_ipcm_poke(emu, ipcm);
2530 kfree(ipcm); 2519 kfree(ipcm);
2531 return res; 2520 return res;
2532 case SNDRV_EMU10K1_IOCTL_PCM_PEEK: 2521 case SNDRV_EMU10K1_IOCTL_PCM_PEEK:
2533 ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL); 2522 ipcm = memdup_user(argp, sizeof(*ipcm));
2534 if (ipcm == NULL) 2523 if (IS_ERR(ipcm))
2535 return -ENOMEM; 2524 return PTR_ERR(ipcm);
2536 if (copy_from_user(ipcm, argp, sizeof(*ipcm))) {
2537 kfree(ipcm);
2538 return -EFAULT;
2539 }
2540 res = snd_emu10k1_ipcm_peek(emu, ipcm); 2525 res = snd_emu10k1_ipcm_peek(emu, ipcm);
2541 if (res == 0 && copy_to_user(argp, ipcm, sizeof(*ipcm))) { 2526 if (res == 0 && copy_to_user(argp, ipcm, sizeof(*ipcm))) {
2542 kfree(ipcm); 2527 kfree(ipcm);
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index a4e5e5952115..8820faf6c9d8 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -642,19 +642,21 @@ static int get_codec_name(struct hda_codec *codec)
642 */ 642 */
643static void /*__devinit*/ setup_fg_nodes(struct hda_codec *codec) 643static void /*__devinit*/ setup_fg_nodes(struct hda_codec *codec)
644{ 644{
645 int i, total_nodes; 645 int i, total_nodes, function_id;
646 hda_nid_t nid; 646 hda_nid_t nid;
647 647
648 total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid); 648 total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
649 for (i = 0; i < total_nodes; i++, nid++) { 649 for (i = 0; i < total_nodes; i++, nid++) {
650 codec->function_id = snd_hda_param_read(codec, nid, 650 function_id = snd_hda_param_read(codec, nid,
651 AC_PAR_FUNCTION_TYPE) & 0xff; 651 AC_PAR_FUNCTION_TYPE) & 0xff;
652 switch (codec->function_id) { 652 switch (function_id) {
653 case AC_GRP_AUDIO_FUNCTION: 653 case AC_GRP_AUDIO_FUNCTION:
654 codec->afg = nid; 654 codec->afg = nid;
655 codec->function_id = function_id;
655 break; 656 break;
656 case AC_GRP_MODEM_FUNCTION: 657 case AC_GRP_MODEM_FUNCTION:
657 codec->mfg = nid; 658 codec->mfg = nid;
659 codec->function_id = function_id;
658 break; 660 break;
659 default: 661 default:
660 break; 662 break;
@@ -2250,7 +2252,11 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
2250 err = bus->ops.command(bus, res); 2252 err = bus->ops.command(bus, res);
2251 if (!err) { 2253 if (!err) {
2252 struct hda_cache_head *c; 2254 struct hda_cache_head *c;
2253 u32 key = build_cmd_cache_key(nid, verb); 2255 u32 key;
2256 /* parm may contain the verb stuff for get/set amp */
2257 verb = verb | (parm >> 8);
2258 parm &= 0xff;
2259 key = build_cmd_cache_key(nid, verb);
2254 c = get_alloc_hash(&codec->cmd_cache, key); 2260 c = get_alloc_hash(&codec->cmd_cache, key);
2255 if (c) 2261 if (c)
2256 c->val = parm; 2262 c->val = parm;
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 7ba8db5d4c42..21e99cfa8c49 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -312,6 +312,8 @@ struct azx_dev {
312 unsigned int period_bytes; /* size of the period in bytes */ 312 unsigned int period_bytes; /* size of the period in bytes */
313 unsigned int frags; /* number for period in the play buffer */ 313 unsigned int frags; /* number for period in the play buffer */
314 unsigned int fifo_size; /* FIFO size */ 314 unsigned int fifo_size; /* FIFO size */
315 unsigned long start_jiffies; /* start + minimum jiffies */
316 unsigned long min_jiffies; /* minimum jiffies before position is valid */
315 317
316 void __iomem *sd_addr; /* stream descriptor pointer */ 318 void __iomem *sd_addr; /* stream descriptor pointer */
317 319
@@ -330,7 +332,7 @@ struct azx_dev {
330 unsigned int opened :1; 332 unsigned int opened :1;
331 unsigned int running :1; 333 unsigned int running :1;
332 unsigned int irq_pending :1; 334 unsigned int irq_pending :1;
333 unsigned int irq_ignore :1; 335 unsigned int start_flag: 1; /* stream full start flag */
334 /* 336 /*
335 * For VIA: 337 * For VIA:
336 * A flag to ensure DMA position is 0 338 * A flag to ensure DMA position is 0
@@ -975,7 +977,7 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
975 struct azx *chip = dev_id; 977 struct azx *chip = dev_id;
976 struct azx_dev *azx_dev; 978 struct azx_dev *azx_dev;
977 u32 status; 979 u32 status;
978 int i; 980 int i, ok;
979 981
980 spin_lock(&chip->reg_lock); 982 spin_lock(&chip->reg_lock);
981 983
@@ -991,18 +993,14 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
991 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); 993 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
992 if (!azx_dev->substream || !azx_dev->running) 994 if (!azx_dev->substream || !azx_dev->running)
993 continue; 995 continue;
994 /* ignore the first dummy IRQ (due to pos_adj) */
995 if (azx_dev->irq_ignore) {
996 azx_dev->irq_ignore = 0;
997 continue;
998 }
999 /* check whether this IRQ is really acceptable */ 996 /* check whether this IRQ is really acceptable */
1000 if (azx_position_ok(chip, azx_dev)) { 997 ok = azx_position_ok(chip, azx_dev);
998 if (ok == 1) {
1001 azx_dev->irq_pending = 0; 999 azx_dev->irq_pending = 0;
1002 spin_unlock(&chip->reg_lock); 1000 spin_unlock(&chip->reg_lock);
1003 snd_pcm_period_elapsed(azx_dev->substream); 1001 snd_pcm_period_elapsed(azx_dev->substream);
1004 spin_lock(&chip->reg_lock); 1002 spin_lock(&chip->reg_lock);
1005 } else if (chip->bus && chip->bus->workq) { 1003 } else if (ok == 0 && chip->bus && chip->bus->workq) {
1006 /* bogus IRQ, process it later */ 1004 /* bogus IRQ, process it later */
1007 azx_dev->irq_pending = 1; 1005 azx_dev->irq_pending = 1;
1008 queue_work(chip->bus->workq, 1006 queue_work(chip->bus->workq,
@@ -1088,7 +1086,6 @@ static int azx_setup_periods(struct azx *chip,
1088 bdl = (u32 *)azx_dev->bdl.area; 1086 bdl = (u32 *)azx_dev->bdl.area;
1089 ofs = 0; 1087 ofs = 0;
1090 azx_dev->frags = 0; 1088 azx_dev->frags = 0;
1091 azx_dev->irq_ignore = 0;
1092 pos_adj = bdl_pos_adj[chip->dev_index]; 1089 pos_adj = bdl_pos_adj[chip->dev_index];
1093 if (pos_adj > 0) { 1090 if (pos_adj > 0) {
1094 struct snd_pcm_runtime *runtime = substream->runtime; 1091 struct snd_pcm_runtime *runtime = substream->runtime;
@@ -1109,7 +1106,6 @@ static int azx_setup_periods(struct azx *chip,
1109 &bdl, ofs, pos_adj, 1); 1106 &bdl, ofs, pos_adj, 1);
1110 if (ofs < 0) 1107 if (ofs < 0)
1111 goto error; 1108 goto error;
1112 azx_dev->irq_ignore = 1;
1113 } 1109 }
1114 } else 1110 } else
1115 pos_adj = 0; 1111 pos_adj = 0;
@@ -1155,6 +1151,9 @@ static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
1155 while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) && 1151 while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
1156 --timeout) 1152 --timeout)
1157 ; 1153 ;
1154
1155 /* reset first position - may not be synced with hw at this time */
1156 *azx_dev->posbuf = 0;
1158} 1157}
1159 1158
1160/* 1159/*
@@ -1409,7 +1408,6 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1409 snd_pcm_set_sync(substream); 1408 snd_pcm_set_sync(substream);
1410 mutex_unlock(&chip->open_mutex); 1409 mutex_unlock(&chip->open_mutex);
1411 1410
1412 azx_stream_reset(chip, azx_dev);
1413 return 0; 1411 return 0;
1414} 1412}
1415 1413
@@ -1474,6 +1472,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1474 unsigned int bufsize, period_bytes, format_val; 1472 unsigned int bufsize, period_bytes, format_val;
1475 int err; 1473 int err;
1476 1474
1475 azx_stream_reset(chip, azx_dev);
1477 format_val = snd_hda_calc_stream_format(runtime->rate, 1476 format_val = snd_hda_calc_stream_format(runtime->rate,
1478 runtime->channels, 1477 runtime->channels,
1479 runtime->format, 1478 runtime->format,
@@ -1502,6 +1501,8 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1502 return err; 1501 return err;
1503 } 1502 }
1504 1503
1504 azx_dev->min_jiffies = (runtime->period_size * HZ) /
1505 (runtime->rate * 2);
1505 azx_setup_controller(chip, azx_dev); 1506 azx_setup_controller(chip, azx_dev);
1506 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1507 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1507 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1; 1508 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
@@ -1518,13 +1519,14 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1518 struct azx *chip = apcm->chip; 1519 struct azx *chip = apcm->chip;
1519 struct azx_dev *azx_dev; 1520 struct azx_dev *azx_dev;
1520 struct snd_pcm_substream *s; 1521 struct snd_pcm_substream *s;
1521 int start, nsync = 0, sbits = 0; 1522 int rstart = 0, start, nsync = 0, sbits = 0;
1522 int nwait, timeout; 1523 int nwait, timeout;
1523 1524
1524 switch (cmd) { 1525 switch (cmd) {
1526 case SNDRV_PCM_TRIGGER_START:
1527 rstart = 1;
1525 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1528 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1526 case SNDRV_PCM_TRIGGER_RESUME: 1529 case SNDRV_PCM_TRIGGER_RESUME:
1527 case SNDRV_PCM_TRIGGER_START:
1528 start = 1; 1530 start = 1;
1529 break; 1531 break;
1530 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1532 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
@@ -1554,6 +1556,10 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1554 if (s->pcm->card != substream->pcm->card) 1556 if (s->pcm->card != substream->pcm->card)
1555 continue; 1557 continue;
1556 azx_dev = get_azx_dev(s); 1558 azx_dev = get_azx_dev(s);
1559 if (rstart) {
1560 azx_dev->start_flag = 1;
1561 azx_dev->start_jiffies = jiffies + azx_dev->min_jiffies;
1562 }
1557 if (start) 1563 if (start)
1558 azx_stream_start(chip, azx_dev); 1564 azx_stream_start(chip, azx_dev);
1559 else 1565 else
@@ -1703,6 +1709,11 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
1703{ 1709{
1704 unsigned int pos; 1710 unsigned int pos;
1705 1711
1712 if (azx_dev->start_flag &&
1713 time_before_eq(jiffies, azx_dev->start_jiffies))
1714 return -1; /* bogus (too early) interrupt */
1715 azx_dev->start_flag = 0;
1716
1706 pos = azx_get_position(chip, azx_dev); 1717 pos = azx_get_position(chip, azx_dev);
1707 if (chip->position_fix == POS_FIX_AUTO) { 1718 if (chip->position_fix == POS_FIX_AUTO) {
1708 if (!pos) { 1719 if (!pos) {
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 38ad3f7b040f..84cc49ca9148 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -3817,6 +3817,49 @@ static struct hda_verb ad1884a_laptop_verbs[] = {
3817 { } /* end */ 3817 { } /* end */
3818}; 3818};
3819 3819
3820static struct hda_verb ad1884a_mobile_verbs[] = {
3821 /* DACs; unmute as default */
3822 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3823 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3824 /* Port-A (HP) mixer - route only from analog mixer */
3825 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3826 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3827 /* Port-A pin */
3828 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3829 /* Port-A (HP) pin - always unmuted */
3830 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3831 /* Port-B (mic jack) pin */
3832 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3833 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3834 /* Port-C (int mic) pin */
3835 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3836 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
3837 /* Port-F (int speaker) mixer - route only from analog mixer */
3838 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3839 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3840 /* Port-F pin */
3841 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3842 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3843 /* Analog mixer; mute as default */
3844 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3845 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3846 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3847 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3848 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3849 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3850 /* Analog Mix output amp */
3851 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3852 /* capture sources */
3853 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
3854 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3855 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3856 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3857 /* unsolicited event for pin-sense */
3858 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3859 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
3860 { } /* end */
3861};
3862
3820/* 3863/*
3821 * Thinkpad X300 3864 * Thinkpad X300
3822 * 0x11 - HP 3865 * 0x11 - HP
@@ -3977,10 +4020,18 @@ static int patch_ad1884a(struct hda_codec *codec)
3977 spec->input_mux = &ad1884a_laptop_capture_source; 4020 spec->input_mux = &ad1884a_laptop_capture_source;
3978 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event; 4021 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3979 codec->patch_ops.init = ad1884a_hp_init; 4022 codec->patch_ops.init = ad1884a_hp_init;
4023 /* set the upper-limit for mixer amp to 0dB for avoiding the
4024 * possible damage by overloading
4025 */
4026 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4027 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4028 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4029 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4030 (1 << AC_AMPCAP_MUTE_SHIFT));
3980 break; 4031 break;
3981 case AD1884A_MOBILE: 4032 case AD1884A_MOBILE:
3982 spec->mixers[0] = ad1884a_mobile_mixers; 4033 spec->mixers[0] = ad1884a_mobile_mixers;
3983 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs; 4034 spec->init_verbs[0] = ad1884a_mobile_verbs;
3984 spec->multiout.dig_out_nid = 0; 4035 spec->multiout.dig_out_nid = 0;
3985 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event; 4036 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3986 codec->patch_ops.init = ad1884a_hp_init; 4037 codec->patch_ops.init = ad1884a_hp_init;
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 1f2ad76ca94b..56ce19e68cb5 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -350,12 +350,20 @@ static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
350} 350}
351 351
352#ifdef CONFIG_SND_JACK 352#ifdef CONFIG_SND_JACK
353static void conexant_free_jack_priv(struct snd_jack *jack)
354{
355 struct conexant_jack *jacks = jack->private_data;
356 jacks->nid = 0;
357 jacks->jack = NULL;
358}
359
353static int conexant_add_jack(struct hda_codec *codec, 360static int conexant_add_jack(struct hda_codec *codec,
354 hda_nid_t nid, int type) 361 hda_nid_t nid, int type)
355{ 362{
356 struct conexant_spec *spec; 363 struct conexant_spec *spec;
357 struct conexant_jack *jack; 364 struct conexant_jack *jack;
358 const char *name; 365 const char *name;
366 int err;
359 367
360 spec = codec->spec; 368 spec = codec->spec;
361 snd_array_init(&spec->jacks, sizeof(*jack), 32); 369 snd_array_init(&spec->jacks, sizeof(*jack), 32);
@@ -368,7 +376,12 @@ static int conexant_add_jack(struct hda_codec *codec,
368 jack->nid = nid; 376 jack->nid = nid;
369 jack->type = type; 377 jack->type = type;
370 378
371 return snd_jack_new(codec->bus->card, name, type, &jack->jack); 379 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
380 if (err < 0)
381 return err;
382 jack->jack->private_data = jack;
383 jack->jack->private_free = conexant_free_jack_priv;
384 return 0;
372} 385}
373 386
374static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 387static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
@@ -455,8 +468,10 @@ static void conexant_free(struct hda_codec *codec)
455 if (spec->jacks.list) { 468 if (spec->jacks.list) {
456 struct conexant_jack *jacks = spec->jacks.list; 469 struct conexant_jack *jacks = spec->jacks.list;
457 int i; 470 int i;
458 for (i = 0; i < spec->jacks.used; i++) 471 for (i = 0; i < spec->jacks.used; i++, jacks++) {
459 snd_device_free(codec->bus->card, &jacks[i].jack); 472 if (jacks->jack)
473 snd_device_free(codec->bus->card, jacks->jack);
474 }
460 snd_array_free(&spec->jacks); 475 snd_array_free(&spec->jacks);
461 } 476 }
462#endif 477#endif
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index f35e58a2d921..bcbb736f94f0 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -188,6 +188,8 @@ enum {
188 ALC663_ASUS_MODE4, 188 ALC663_ASUS_MODE4,
189 ALC663_ASUS_MODE5, 189 ALC663_ASUS_MODE5,
190 ALC663_ASUS_MODE6, 190 ALC663_ASUS_MODE6,
191 ALC272_DELL,
192 ALC272_DELL_ZM1,
191 ALC662_AUTO, 193 ALC662_AUTO,
192 ALC662_MODEL_LAST, 194 ALC662_MODEL_LAST,
193}; 195};
@@ -8742,10 +8744,9 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
8742 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD), 8744 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
8743 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch), 8745 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8744 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION), 8746 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8745 SND_PCI_QUIRK(0x1734, 0x1107, "FSC AMILO Xi2550", 8747 SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
8746 ALC883_FUJITSU_PI2515), 8748 ALC883_FUJITSU_PI2515),
8747 SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515), 8749 SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
8748 SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8749 ALC888_FUJITSU_XA3530), 8750 ALC888_FUJITSU_XA3530),
8750 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch), 8751 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8751 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763), 8752 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
@@ -12057,6 +12058,7 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
12057 SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL), 12058 SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12058 SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL), 12059 SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
12059 SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA), 12060 SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
12061 SND_PCI_QUIRK(0x103c, 0x30f1, "HP TX25xx series", ALC268_TOSHIBA),
12060 SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST), 12062 SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12061 SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA), 12063 SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
12062 SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA), 12064 SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
@@ -12977,10 +12979,17 @@ static struct snd_pci_quirk alc269_cfg_tbl[] = {
12977 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1), 12979 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12978 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A", 12980 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12979 ALC269_ASUS_EEEPC_P703), 12981 ALC269_ASUS_EEEPC_P703),
12982 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
12983 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
12984 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
12985 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
12986 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
12987 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
12980 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901", 12988 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12981 ALC269_ASUS_EEEPC_P901), 12989 ALC269_ASUS_EEEPC_P901),
12982 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101", 12990 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12983 ALC269_ASUS_EEEPC_P901), 12991 ALC269_ASUS_EEEPC_P901),
12992 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
12984 SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU), 12993 SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12985 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK), 12994 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12986 {} 12995 {}
@@ -15211,12 +15220,23 @@ static hda_nid_t alc662_dac_nids[4] = {
15211 0x02, 0x03, 0x04 15220 0x02, 0x03, 0x04
15212}; 15221};
15213 15222
15223static hda_nid_t alc272_dac_nids[2] = {
15224 0x02, 0x03
15225};
15226
15214static hda_nid_t alc662_adc_nids[1] = { 15227static hda_nid_t alc662_adc_nids[1] = {
15215 /* ADC1-2 */ 15228 /* ADC1-2 */
15216 0x09, 15229 0x09,
15217}; 15230};
15218 15231
15232static hda_nid_t alc272_adc_nids[1] = {
15233 /* ADC1-2 */
15234 0x08,
15235};
15236
15219static hda_nid_t alc662_capsrc_nids[1] = { 0x22 }; 15237static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
15238static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15239
15220 15240
15221/* input MUX */ 15241/* input MUX */
15222/* FIXME: should be a matrix-type input source selection */ 15242/* FIXME: should be a matrix-type input source selection */
@@ -15642,14 +15662,7 @@ static struct hda_verb alc662_init_verbs[] = {
15642 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */ 15662 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15643 /* Input mixer */ 15663 /* Input mixer */
15644 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 15664 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15645 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15646 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15647 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15648
15649 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 15665 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15650 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15651 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15652 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15653 15666
15654 /* always trun on EAPD */ 15667 /* always trun on EAPD */
15655 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, 15668 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
@@ -15844,12 +15857,48 @@ static struct hda_verb alc662_ecs_init_verbs[] = {
15844 {} 15857 {}
15845}; 15858};
15846 15859
15860static struct hda_verb alc272_dell_zm1_init_verbs[] = {
15861 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15862 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15863 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15864 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15865 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15866 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15867 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
15868 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15869 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15870 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15871 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15872 {}
15873};
15874
15875static struct hda_verb alc272_dell_init_verbs[] = {
15876 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15877 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15878 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15879 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15880 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15881 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15882 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
15883 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15884 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15885 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15886 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15887 {}
15888};
15889
15847static struct snd_kcontrol_new alc662_auto_capture_mixer[] = { 15890static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15848 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT), 15891 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15849 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT), 15892 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15850 { } /* end */ 15893 { } /* end */
15851}; 15894};
15852 15895
15896static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
15897 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
15898 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
15899 { } /* end */
15900};
15901
15853static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec) 15902static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15854{ 15903{
15855 unsigned int present; 15904 unsigned int present;
@@ -16361,6 +16410,8 @@ static const char *alc662_models[ALC662_MODEL_LAST] = {
16361 16410
16362static struct snd_pci_quirk alc662_cfg_tbl[] = { 16411static struct snd_pci_quirk alc662_cfg_tbl[] = {
16363 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS), 16412 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16413 SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16414 SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16364 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1), 16415 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16365 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3), 16416 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16366 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3), 16417 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
@@ -16373,26 +16424,36 @@ static struct snd_pci_quirk alc662_cfg_tbl[] = {
16373 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6), 16424 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16374 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6), 16425 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16375 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2), 16426 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16427 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16428 SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16429 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16376 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2), 16430 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16377 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5), 16431 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16378 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6), 16432 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16379 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2), 16433 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16434 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16380 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2), 16435 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16381 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2), 16436 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16382 SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA), 16437 SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16383 /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/ 16438 /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16384 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3), 16439 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16385 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3), 16440 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16441 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16442 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16443 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16386 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1), 16444 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16387 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2), 16445 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16388 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2), 16446 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16447 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16389 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1), 16448 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16390 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3), 16449 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16450 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16391 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1), 16451 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16392 SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V), 16452 SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16393 /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/ 16453 /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16394 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1), 16454 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16395 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2), 16455 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16456 SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16396 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1), 16457 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16397 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4), 16458 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16398 SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG), 16459 SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
@@ -16404,6 +16465,7 @@ static struct snd_pci_quirk alc662_cfg_tbl[] = {
16404 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L", 16465 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16405 ALC662_3ST_6ch_DIG), 16466 ALC662_3ST_6ch_DIG),
16406 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG), 16467 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16468 SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16407 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E), 16469 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16408 SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0", 16470 SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16409 ALC662_3ST_6ch_DIG), 16471 ALC662_3ST_6ch_DIG),
@@ -16641,6 +16703,36 @@ static struct alc_config_preset alc662_presets[] = {
16641 .unsol_event = alc663_mode6_unsol_event, 16703 .unsol_event = alc663_mode6_unsol_event,
16642 .init_hook = alc663_mode6_inithook, 16704 .init_hook = alc663_mode6_inithook,
16643 }, 16705 },
16706 [ALC272_DELL] = {
16707 .mixers = { alc663_m51va_mixer },
16708 .cap_mixer = alc272_auto_capture_mixer,
16709 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
16710 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
16711 .dac_nids = alc662_dac_nids,
16712 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16713 .adc_nids = alc272_adc_nids,
16714 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
16715 .capsrc_nids = alc272_capsrc_nids,
16716 .channel_mode = alc662_3ST_2ch_modes,
16717 .input_mux = &alc663_m51va_capture_source,
16718 .unsol_event = alc663_m51va_unsol_event,
16719 .init_hook = alc663_m51va_inithook,
16720 },
16721 [ALC272_DELL_ZM1] = {
16722 .mixers = { alc663_m51va_mixer },
16723 .cap_mixer = alc662_auto_capture_mixer,
16724 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
16725 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
16726 .dac_nids = alc662_dac_nids,
16727 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16728 .adc_nids = alc662_adc_nids,
16729 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
16730 .capsrc_nids = alc662_capsrc_nids,
16731 .channel_mode = alc662_3ST_2ch_modes,
16732 .input_mux = &alc663_m51va_capture_source,
16733 .unsol_event = alc663_m51va_unsol_event,
16734 .init_hook = alc663_m51va_inithook,
16735 },
16644}; 16736};
16645 16737
16646 16738
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 61996a2f45df..03b3646018a1 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -3076,6 +3076,11 @@ static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3076 unsigned int wid_caps; 3076 unsigned int wid_caps;
3077 3077
3078 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) { 3078 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3079 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3080 wid_caps = get_wcaps(codec, pins[i]);
3081 if (wid_caps & AC_WCAP_UNSOL_CAP)
3082 spec->hp_detect = 1;
3083 }
3079 nid = dac_nids[i]; 3084 nid = dac_nids[i];
3080 if (!nid) 3085 if (!nid)
3081 continue; 3086 continue;
@@ -3119,11 +3124,6 @@ static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3119 err = create_controls_idx(codec, name, idx, nid, 3); 3124 err = create_controls_idx(codec, name, idx, nid, 3);
3120 if (err < 0) 3125 if (err < 0)
3121 return err; 3126 return err;
3122 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3123 wid_caps = get_wcaps(codec, pins[i]);
3124 if (wid_caps & AC_WCAP_UNSOL_CAP)
3125 spec->hp_detect = 1;
3126 }
3127 } 3127 }
3128 } 3128 }
3129 return 0; 3129 return 0;
@@ -3851,6 +3851,15 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
3851 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */ 3851 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
3852} 3852}
3853 3853
3854#ifdef CONFIG_SND_JACK
3855static void stac92xx_free_jack_priv(struct snd_jack *jack)
3856{
3857 struct sigmatel_jack *jacks = jack->private_data;
3858 jacks->nid = 0;
3859 jacks->jack = NULL;
3860}
3861#endif
3862
3854static int stac92xx_add_jack(struct hda_codec *codec, 3863static int stac92xx_add_jack(struct hda_codec *codec,
3855 hda_nid_t nid, int type) 3864 hda_nid_t nid, int type)
3856{ 3865{
@@ -3860,6 +3869,7 @@ static int stac92xx_add_jack(struct hda_codec *codec,
3860 int def_conf = snd_hda_codec_get_pincfg(codec, nid); 3869 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
3861 int connectivity = get_defcfg_connect(def_conf); 3870 int connectivity = get_defcfg_connect(def_conf);
3862 char name[32]; 3871 char name[32];
3872 int err;
3863 3873
3864 if (connectivity && connectivity != AC_JACK_PORT_FIXED) 3874 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3865 return 0; 3875 return 0;
@@ -3876,10 +3886,15 @@ static int stac92xx_add_jack(struct hda_codec *codec,
3876 snd_hda_get_jack_connectivity(def_conf), 3886 snd_hda_get_jack_connectivity(def_conf),
3877 snd_hda_get_jack_location(def_conf)); 3887 snd_hda_get_jack_location(def_conf));
3878 3888
3879 return snd_jack_new(codec->bus->card, name, type, &jack->jack); 3889 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
3880#else 3890 if (err < 0) {
3881 return 0; 3891 jack->nid = 0;
3892 return err;
3893 }
3894 jack->jack->private_data = jack;
3895 jack->jack->private_free = stac92xx_free_jack_priv;
3882#endif 3896#endif
3897 return 0;
3883} 3898}
3884 3899
3885static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid, 3900static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
@@ -4064,7 +4079,12 @@ static int stac92xx_init(struct hda_codec *codec)
4064 pinctl = snd_hda_codec_read(codec, nid, 0, 4079 pinctl = snd_hda_codec_read(codec, nid, 0,
4065 AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 4080 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4066 /* if PINCTL already set then skip */ 4081 /* if PINCTL already set then skip */
4067 if (!(pinctl & AC_PINCTL_IN_EN)) { 4082 /* Also, if both INPUT and OUTPUT are set,
4083 * it must be a BIOS bug; need to override, too
4084 */
4085 if (!(pinctl & AC_PINCTL_IN_EN) ||
4086 (pinctl & AC_PINCTL_OUT_EN)) {
4087 pinctl &= ~AC_PINCTL_OUT_EN;
4068 pinctl |= AC_PINCTL_IN_EN; 4088 pinctl |= AC_PINCTL_IN_EN;
4069 stac92xx_auto_set_pinctl(codec, nid, 4089 stac92xx_auto_set_pinctl(codec, nid,
4070 pinctl); 4090 pinctl);
@@ -4138,8 +4158,10 @@ static void stac92xx_free_jacks(struct hda_codec *codec)
4138 if (!codec->bus->shutdown && spec->jacks.list) { 4158 if (!codec->bus->shutdown && spec->jacks.list) {
4139 struct sigmatel_jack *jacks = spec->jacks.list; 4159 struct sigmatel_jack *jacks = spec->jacks.list;
4140 int i; 4160 int i;
4141 for (i = 0; i < spec->jacks.used; i++) 4161 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4142 snd_device_free(codec->bus->card, &jacks[i].jack); 4162 if (jacks->jack)
4163 snd_device_free(codec->bus->card, jacks->jack);
4164 }
4143 } 4165 }
4144 snd_array_free(&spec->jacks); 4166 snd_array_free(&spec->jacks);
4145#endif 4167#endif
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 57648810eaf1..173bebf9f51d 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -355,6 +355,9 @@ struct ichdev {
355 unsigned int fragsize1; 355 unsigned int fragsize1;
356 unsigned int position; 356 unsigned int position;
357 unsigned int pos_shift; 357 unsigned int pos_shift;
358 unsigned int last_pos;
359 unsigned long last_pos_jiffies;
360 unsigned int jiffy_to_bytes;
358 int frags; 361 int frags;
359 int lvi; 362 int lvi;
360 int lvi_frag; 363 int lvi_frag;
@@ -838,7 +841,10 @@ static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd
838 ichdev->suspended = 0; 841 ichdev->suspended = 0;
839 /* fallthru */ 842 /* fallthru */
840 case SNDRV_PCM_TRIGGER_START: 843 case SNDRV_PCM_TRIGGER_START:
844 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
841 val = ICH_IOCE | ICH_STARTBM; 845 val = ICH_IOCE | ICH_STARTBM;
846 ichdev->last_pos = ichdev->position;
847 ichdev->last_pos_jiffies = jiffies;
842 break; 848 break;
843 case SNDRV_PCM_TRIGGER_SUSPEND: 849 case SNDRV_PCM_TRIGGER_SUSPEND:
844 ichdev->suspended = 1; 850 ichdev->suspended = 1;
@@ -849,9 +855,6 @@ static int snd_intel8x0_pcm_trigger(struct snd_pcm_substream *substream, int cmd
849 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 855 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
850 val = ICH_IOCE; 856 val = ICH_IOCE;
851 break; 857 break;
852 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
853 val = ICH_IOCE | ICH_STARTBM;
854 break;
855 default: 858 default:
856 return -EINVAL; 859 return -EINVAL;
857 } 860 }
@@ -1045,6 +1048,7 @@ static int snd_intel8x0_pcm_prepare(struct snd_pcm_substream *substream)
1045 ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1; 1048 ichdev->pos_shift = (runtime->sample_bits > 16) ? 2 : 1;
1046 } 1049 }
1047 snd_intel8x0_setup_periods(chip, ichdev); 1050 snd_intel8x0_setup_periods(chip, ichdev);
1051 ichdev->jiffy_to_bytes = (runtime->rate * 4 * ichdev->pos_shift) / HZ;
1048 return 0; 1052 return 0;
1049} 1053}
1050 1054
@@ -1053,7 +1057,7 @@ static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *subs
1053 struct intel8x0 *chip = snd_pcm_substream_chip(substream); 1057 struct intel8x0 *chip = snd_pcm_substream_chip(substream);
1054 struct ichdev *ichdev = get_ichdev(substream); 1058 struct ichdev *ichdev = get_ichdev(substream);
1055 size_t ptr1, ptr; 1059 size_t ptr1, ptr;
1056 int civ, timeout = 100; 1060 int civ, timeout = 10;
1057 unsigned int position; 1061 unsigned int position;
1058 1062
1059 spin_lock(&chip->reg_lock); 1063 spin_lock(&chip->reg_lock);
@@ -1069,9 +1073,19 @@ static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *subs
1069 ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb)) 1073 ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
1070 break; 1074 break;
1071 } while (timeout--); 1075 } while (timeout--);
1072 ptr1 <<= ichdev->pos_shift; 1076 if (ptr1 != 0) {
1073 ptr = ichdev->fragsize1 - ptr1; 1077 ptr1 <<= ichdev->pos_shift;
1074 ptr += position; 1078 ptr = ichdev->fragsize1 - ptr1;
1079 ptr += position;
1080 ichdev->last_pos = ptr;
1081 ichdev->last_pos_jiffies = jiffies;
1082 } else {
1083 ptr1 = jiffies - ichdev->last_pos_jiffies;
1084 if (ptr1)
1085 ptr1 -= 1;
1086 ptr = ichdev->last_pos + ptr1 * ichdev->jiffy_to_bytes;
1087 ptr %= ichdev->size;
1088 }
1075 spin_unlock(&chip->reg_lock); 1089 spin_unlock(&chip->reg_lock);
1076 if (ptr >= ichdev->size) 1090 if (ptr >= ichdev->size)
1077 return 0; 1091 return 0;
@@ -1840,6 +1854,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
1840 }, 1854 },
1841 { 1855 {
1842 .subvendor = 0x1028, 1856 .subvendor = 0x1028,
1857 .subdevice = 0x016a,
1858 .name = "Dell Inspiron 8600", /* STAC9750/51 */
1859 .type = AC97_TUNE_HP_ONLY
1860 },
1861 {
1862 .subvendor = 0x1028,
1843 .subdevice = 0x0186, 1863 .subdevice = 0x0186,
1844 .name = "Dell Latitude D810", /* cf. Malone #41015 */ 1864 .name = "Dell Latitude D810", /* cf. Malone #41015 */
1845 .type = AC97_TUNE_HP_MUTE_LED 1865 .type = AC97_TUNE_HP_MUTE_LED
@@ -1882,12 +1902,6 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
1882 }, 1902 },
1883 { 1903 {
1884 .subvendor = 0x103c, 1904 .subvendor = 0x103c,
1885 .subdevice = 0x0934,
1886 .name = "HP nx8220",
1887 .type = AC97_TUNE_MUTE_LED
1888 },
1889 {
1890 .subvendor = 0x103c,
1891 .subdevice = 0x129d, 1905 .subdevice = 0x129d,
1892 .name = "HP xw8000", 1906 .name = "HP xw8000",
1893 .type = AC97_TUNE_HP_ONLY 1907 .type = AC97_TUNE_HP_ONLY
@@ -2661,12 +2675,14 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2661 struct snd_pcm_substream *subs; 2675 struct snd_pcm_substream *subs;
2662 struct ichdev *ichdev; 2676 struct ichdev *ichdev;
2663 unsigned long port; 2677 unsigned long port;
2664 unsigned long pos, t; 2678 unsigned long pos, pos1, t;
2665 struct timeval start_time, stop_time; 2679 int civ, timeout = 1000, attempt = 1;
2680 struct timespec start_time, stop_time;
2666 2681
2667 if (chip->ac97_bus->clock != 48000) 2682 if (chip->ac97_bus->clock != 48000)
2668 return; /* specified in module option */ 2683 return; /* specified in module option */
2669 2684
2685 __again:
2670 subs = chip->pcm[0]->streams[0].substream; 2686 subs = chip->pcm[0]->streams[0].substream;
2671 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) { 2687 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
2672 snd_printk(KERN_WARNING "no playback buffer allocated - aborting measure ac97 clock\n"); 2688 snd_printk(KERN_WARNING "no playback buffer allocated - aborting measure ac97 clock\n");
@@ -2674,7 +2690,7 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2674 } 2690 }
2675 ichdev = &chip->ichd[ICHD_PCMOUT]; 2691 ichdev = &chip->ichd[ICHD_PCMOUT];
2676 ichdev->physbuf = subs->dma_buffer.addr; 2692 ichdev->physbuf = subs->dma_buffer.addr;
2677 ichdev->size = chip->ichd[ICHD_PCMOUT].fragsize = INTEL8X0_TESTBUF_SIZE; 2693 ichdev->size = ichdev->fragsize = INTEL8X0_TESTBUF_SIZE;
2678 ichdev->substream = NULL; /* don't process interrupts */ 2694 ichdev->substream = NULL; /* don't process interrupts */
2679 2695
2680 /* set rate */ 2696 /* set rate */
@@ -2693,16 +2709,31 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2693 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE); 2709 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_IOCE);
2694 iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot); 2710 iputdword(chip, ICHREG(ALI_DMACR), 1 << ichdev->ali_slot);
2695 } 2711 }
2696 do_gettimeofday(&start_time); 2712 do_posix_clock_monotonic_gettime(&start_time);
2697 spin_unlock_irq(&chip->reg_lock); 2713 spin_unlock_irq(&chip->reg_lock);
2698 msleep(50); 2714 msleep(50);
2699 spin_lock_irq(&chip->reg_lock); 2715 spin_lock_irq(&chip->reg_lock);
2700 /* check the position */ 2716 /* check the position */
2701 pos = ichdev->fragsize1; 2717 do {
2702 pos -= igetword(chip, ichdev->reg_offset + ichdev->roff_picb) << ichdev->pos_shift; 2718 civ = igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV);
2703 pos += ichdev->position; 2719 pos1 = igetword(chip, ichdev->reg_offset + ichdev->roff_picb);
2720 if (pos1 == 0) {
2721 udelay(10);
2722 continue;
2723 }
2724 if (civ == igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV) &&
2725 pos1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
2726 break;
2727 } while (timeout--);
2728 if (pos1 == 0) { /* oops, this value is not reliable */
2729 pos = 0;
2730 } else {
2731 pos = ichdev->fragsize1;
2732 pos -= pos1 << ichdev->pos_shift;
2733 pos += ichdev->position;
2734 }
2704 chip->in_measurement = 0; 2735 chip->in_measurement = 0;
2705 do_gettimeofday(&stop_time); 2736 do_posix_clock_monotonic_gettime(&stop_time);
2706 /* stop */ 2737 /* stop */
2707 if (chip->device_type == DEVICE_ALI) { 2738 if (chip->device_type == DEVICE_ALI) {
2708 iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 16)); 2739 iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 16));
@@ -2717,22 +2748,42 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2717 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS); 2748 iputbyte(chip, port + ICH_REG_OFF_CR, ICH_RESETREGS);
2718 spin_unlock_irq(&chip->reg_lock); 2749 spin_unlock_irq(&chip->reg_lock);
2719 2750
2751 if (pos == 0) {
2752 snd_printk(KERN_ERR "intel8x0: measure - unreliable DMA position..\n");
2753 __retry:
2754 if (attempt < 3) {
2755 msleep(300);
2756 attempt++;
2757 goto __again;
2758 }
2759 goto __end;
2760 }
2761
2762 pos /= 4;
2720 t = stop_time.tv_sec - start_time.tv_sec; 2763 t = stop_time.tv_sec - start_time.tv_sec;
2721 t *= 1000000; 2764 t *= 1000000;
2722 t += stop_time.tv_usec - start_time.tv_usec; 2765 t += (stop_time.tv_nsec - start_time.tv_nsec) / 1000;
2723 printk(KERN_INFO "%s: measured %lu usecs\n", __func__, t); 2766 printk(KERN_INFO "%s: measured %lu usecs (%lu samples)\n", __func__, t, pos);
2724 if (t == 0) { 2767 if (t == 0) {
2725 snd_printk(KERN_ERR "?? calculation error..\n"); 2768 snd_printk(KERN_ERR "intel8x0: ?? calculation error..\n");
2726 return; 2769 goto __retry;
2727 } 2770 }
2728 pos = (pos / 4) * 1000; 2771 pos *= 1000;
2729 pos = (pos / t) * 1000 + ((pos % t) * 1000) / t; 2772 pos = (pos / t) * 1000 + ((pos % t) * 1000) / t;
2730 if (pos < 40000 || pos >= 60000) 2773 if (pos < 40000 || pos >= 60000) {
2731 /* abnormal value. hw problem? */ 2774 /* abnormal value. hw problem? */
2732 printk(KERN_INFO "intel8x0: measured clock %ld rejected\n", pos); 2775 printk(KERN_INFO "intel8x0: measured clock %ld rejected\n", pos);
2776 goto __retry;
2777 } else if (pos > 40500 && pos < 41500)
2778 /* first exception - 41000Hz reference clock */
2779 chip->ac97_bus->clock = 41000;
2780 else if (pos > 43600 && pos < 44600)
2781 /* second exception - 44100HZ reference clock */
2782 chip->ac97_bus->clock = 44100;
2733 else if (pos < 47500 || pos > 48500) 2783 else if (pos < 47500 || pos > 48500)
2734 /* not 48000Hz, tuning the clock.. */ 2784 /* not 48000Hz, tuning the clock.. */
2735 chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos; 2785 chip->ac97_bus->clock = (chip->ac97_bus->clock * 48000) / pos;
2786 __end:
2736 printk(KERN_INFO "intel8x0: clocking to %d\n", chip->ac97_bus->clock); 2787 printk(KERN_INFO "intel8x0: clocking to %d\n", chip->ac97_bus->clock);
2737 snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0); 2788 snd_ac97_update_power(chip->ac97[0], AC97_PCM_FRONT_DAC_RATE, 0);
2738} 2789}
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 8b79969034be..7cc38a11e997 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -1238,7 +1238,8 @@ static struct snd_pcm_hardware snd_korg1212_playback_info =
1238{ 1238{
1239 .info = (SNDRV_PCM_INFO_MMAP | 1239 .info = (SNDRV_PCM_INFO_MMAP |
1240 SNDRV_PCM_INFO_MMAP_VALID | 1240 SNDRV_PCM_INFO_MMAP_VALID |
1241 SNDRV_PCM_INFO_INTERLEAVED), 1241 SNDRV_PCM_INFO_INTERLEAVED |
1242 SNDRV_PCM_INFO_BATCH),
1242 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1243 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1243 .rates = (SNDRV_PCM_RATE_44100 | 1244 .rates = (SNDRV_PCM_RATE_44100 |
1244 SNDRV_PCM_RATE_48000), 1245 SNDRV_PCM_RATE_48000),
@@ -1258,7 +1259,8 @@ static struct snd_pcm_hardware snd_korg1212_capture_info =
1258{ 1259{
1259 .info = (SNDRV_PCM_INFO_MMAP | 1260 .info = (SNDRV_PCM_INFO_MMAP |
1260 SNDRV_PCM_INFO_MMAP_VALID | 1261 SNDRV_PCM_INFO_MMAP_VALID |
1261 SNDRV_PCM_INFO_INTERLEAVED), 1262 SNDRV_PCM_INFO_INTERLEAVED |
1263 SNDRV_PCM_INFO_BATCH),
1262 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1264 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1263 .rates = (SNDRV_PCM_RATE_44100 | 1265 .rates = (SNDRV_PCM_RATE_44100 |
1264 SNDRV_PCM_RATE_48000), 1266 SNDRV_PCM_RATE_48000),
diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c b/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c
index 01066c95580e..d057e6489643 100644
--- a/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c
+++ b/sound/pcmcia/pdaudiocf/pdaudiocf_pcm.c
@@ -240,7 +240,8 @@ static int pdacf_pcm_prepare(struct snd_pcm_substream *subs)
240static struct snd_pcm_hardware pdacf_pcm_capture_hw = { 240static struct snd_pcm_hardware pdacf_pcm_capture_hw = {
241 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 241 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
242 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME | 242 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
243 SNDRV_PCM_INFO_MMAP_VALID), 243 SNDRV_PCM_INFO_MMAP_VALID |
244 SNDRV_PCM_INFO_BATCH),
244 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | 245 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
245 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | 246 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE |
246 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, 247 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c
index 6ff99ed77516..a5afb2682e7f 100644
--- a/sound/ppc/keywest.c
+++ b/sound/ppc/keywest.c
@@ -33,26 +33,25 @@
33static struct pmac_keywest *keywest_ctx; 33static struct pmac_keywest *keywest_ctx;
34 34
35 35
36static int keywest_attach_adapter(struct i2c_adapter *adapter);
37static int keywest_detach_client(struct i2c_client *client);
38
39struct i2c_driver keywest_driver = {
40 .driver = {
41 .name = "PMac Keywest Audio",
42 },
43 .attach_adapter = &keywest_attach_adapter,
44 .detach_client = &keywest_detach_client,
45};
46
47
48#ifndef i2c_device_name 36#ifndef i2c_device_name
49#define i2c_device_name(x) ((x)->name) 37#define i2c_device_name(x) ((x)->name)
50#endif 38#endif
51 39
40static int keywest_probe(struct i2c_client *client,
41 const struct i2c_device_id *id)
42{
43 i2c_set_clientdata(client, keywest_ctx);
44 return 0;
45}
46
47/*
48 * This is kind of a hack, best would be to turn powermac to fixed i2c
49 * bus numbers and declare the sound device as part of platform
50 * initialization
51 */
52static int keywest_attach_adapter(struct i2c_adapter *adapter) 52static int keywest_attach_adapter(struct i2c_adapter *adapter)
53{ 53{
54 int err; 54 struct i2c_board_info info;
55 struct i2c_client *new_client;
56 55
57 if (! keywest_ctx) 56 if (! keywest_ctx)
58 return -EINVAL; 57 return -EINVAL;
@@ -60,46 +59,47 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
60 if (strncmp(i2c_device_name(adapter), "mac-io", 6)) 59 if (strncmp(i2c_device_name(adapter), "mac-io", 6))
61 return 0; /* ignored */ 60 return 0; /* ignored */
62 61
63 new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 62 memset(&info, 0, sizeof(struct i2c_board_info));
64 if (! new_client) 63 strlcpy(info.type, "keywest", I2C_NAME_SIZE);
65 return -ENOMEM; 64 info.addr = keywest_ctx->addr;
66 65 keywest_ctx->client = i2c_new_device(adapter, &info);
67 new_client->addr = keywest_ctx->addr;
68 i2c_set_clientdata(new_client, keywest_ctx);
69 new_client->adapter = adapter;
70 new_client->driver = &keywest_driver;
71 new_client->flags = 0;
72
73 strcpy(i2c_device_name(new_client), keywest_ctx->name);
74 keywest_ctx->client = new_client;
75 66
76 /* Tell the i2c layer a new client has arrived */ 67 /*
77 if (i2c_attach_client(new_client)) { 68 * Let i2c-core delete that device on driver removal.
78 snd_printk(KERN_ERR "tumbler: cannot attach i2c client\n"); 69 * This is safe because i2c-core holds the core_lock mutex for us.
79 err = -ENODEV; 70 */
80 goto __err; 71 list_add_tail(&keywest_ctx->client->detected,
81 } 72 &keywest_ctx->client->driver->clients);
82
83 return 0; 73 return 0;
84
85 __err:
86 kfree(new_client);
87 keywest_ctx->client = NULL;
88 return err;
89} 74}
90 75
91static int keywest_detach_client(struct i2c_client *client) 76static int keywest_remove(struct i2c_client *client)
92{ 77{
78 i2c_set_clientdata(client, NULL);
93 if (! keywest_ctx) 79 if (! keywest_ctx)
94 return 0; 80 return 0;
95 if (client == keywest_ctx->client) 81 if (client == keywest_ctx->client)
96 keywest_ctx->client = NULL; 82 keywest_ctx->client = NULL;
97 83
98 i2c_detach_client(client);
99 kfree(client);
100 return 0; 84 return 0;
101} 85}
102 86
87
88static const struct i2c_device_id keywest_i2c_id[] = {
89 { "keywest", 0 },
90 { }
91};
92
93struct i2c_driver keywest_driver = {
94 .driver = {
95 .name = "PMac Keywest Audio",
96 },
97 .attach_adapter = keywest_attach_adapter,
98 .probe = keywest_probe,
99 .remove = keywest_remove,
100 .id_table = keywest_i2c_id,
101};
102
103/* exported */ 103/* exported */
104void snd_pmac_keywest_cleanup(struct pmac_keywest *i2c) 104void snd_pmac_keywest_cleanup(struct pmac_keywest *i2c)
105{ 105{
diff --git a/sound/soc/au1x/dbdma2.c b/sound/soc/au1x/dbdma2.c
index 30490a259148..594c6c5b7838 100644
--- a/sound/soc/au1x/dbdma2.c
+++ b/sound/soc/au1x/dbdma2.c
@@ -82,7 +82,7 @@ static struct au1xpsc_audio_dmadata *au1xpsc_audio_pcmdma[2];
82/* PCM hardware DMA capabilities - platform specific */ 82/* PCM hardware DMA capabilities - platform specific */
83static const struct snd_pcm_hardware au1xpsc_pcm_hardware = { 83static const struct snd_pcm_hardware au1xpsc_pcm_hardware = {
84 .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | 84 .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
85 SNDRV_PCM_INFO_INTERLEAVED, 85 SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BATCH,
86 .formats = AU1XPSC_PCM_FMTS, 86 .formats = AU1XPSC_PCM_FMTS,
87 .period_bytes_min = AU1XPSC_PERIOD_MIN_BYTES, 87 .period_bytes_min = AU1XPSC_PERIOD_MIN_BYTES,
88 .period_bytes_max = 4096 * 1024 - 1, 88 .period_bytes_max = 4096 * 1024 - 1,
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 030d2454725f..f2653803ede8 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -56,7 +56,6 @@ obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o
56obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o 56obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o
57obj-$(CONFIG_SND_SOC_WM8971) += snd-soc-wm8971.o 57obj-$(CONFIG_SND_SOC_WM8971) += snd-soc-wm8971.o
58obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o 58obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o
59obj-$(CONFIG_SND_SOC_WM8991) += snd-soc-wm8991.o
60obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o 59obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o
61obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o 60obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o
62obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o 61obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 921b205de28a..df7c8c281d2f 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -836,6 +836,12 @@ static DECLARE_TLV_DB_SCALE(analog_tlv, -2400, 200, 0);
836static DECLARE_TLV_DB_SCALE(output_tvl, -1200, 600, 1); 836static DECLARE_TLV_DB_SCALE(output_tvl, -1200, 600, 1);
837 837
838/* 838/*
839 * Gain control for earpiece amplifier
840 * 0 dB to 12 dB in 6 dB steps (mute instead of -6)
841 */
842static DECLARE_TLV_DB_SCALE(output_ear_tvl, -600, 600, 1);
843
844/*
839 * Capture gain after the ADCs 845 * Capture gain after the ADCs
840 * from 0 dB to 31 dB in 1 dB steps 846 * from 0 dB to 31 dB in 1 dB steps
841 */ 847 */
@@ -900,7 +906,7 @@ static const struct snd_kcontrol_new twl4030_snd_controls[] = {
900 4, 3, 0, output_tvl), 906 4, 3, 0, output_tvl),
901 907
902 SOC_SINGLE_TLV_TWL4030("Earpiece Playback Volume", 908 SOC_SINGLE_TLV_TWL4030("Earpiece Playback Volume",
903 TWL4030_REG_EAR_CTL, 4, 3, 0, output_tvl), 909 TWL4030_REG_EAR_CTL, 4, 3, 0, output_ear_tvl),
904 910
905 /* Common capture gain controls */ 911 /* Common capture gain controls */
906 SOC_DOUBLE_R_TLV("TX1 Digital Capture Volume", 912 SOC_DOUBLE_R_TLV("TX1 Digital Capture Volume",
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index 3b1d0993bed9..0275321ff8ab 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -968,7 +968,7 @@ static int wm8350_pcm_trigger(struct snd_pcm_substream *substream,
968 * required for LRC in master mode. The DACs or ADCs need a 968 * required for LRC in master mode. The DACs or ADCs need a
969 * valid audio path i.e. pin -> ADC or DAC -> pin before 969 * valid audio path i.e. pin -> ADC or DAC -> pin before
970 * the LRC will be enabled in master mode. */ 970 * the LRC will be enabled in master mode. */
971 if (!master && cmd != SNDRV_PCM_TRIGGER_START) 971 if (!master || cmd != SNDRV_PCM_TRIGGER_START)
972 return 0; 972 return 0;
973 973
974 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { 974 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index 442ea6f160fc..9f6be3d31ac0 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -268,9 +268,11 @@ static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1);
268static int wm8580_out_vu(struct snd_kcontrol *kcontrol, 268static int wm8580_out_vu(struct snd_kcontrol *kcontrol,
269 struct snd_ctl_elem_value *ucontrol) 269 struct snd_ctl_elem_value *ucontrol)
270{ 270{
271 struct soc_mixer_control *mc =
272 (struct soc_mixer_control *)kcontrol->private_value;
271 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 273 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
272 int reg = kcontrol->private_value & 0xff; 274 unsigned int reg = mc->reg;
273 int reg2 = (kcontrol->private_value >> 24) & 0xff; 275 unsigned int reg2 = mc->rreg;
274 int ret; 276 int ret;
275 u16 val; 277 u16 val;
276 278
@@ -292,15 +294,17 @@ static int wm8580_out_vu(struct snd_kcontrol *kcontrol,
292 return 0; 294 return 0;
293} 295}
294 296
295#define SOC_WM8580_OUT_DOUBLE_R_TLV(xname, reg_left, reg_right, shift, max, invert, tlv_array) \ 297#define SOC_WM8580_OUT_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, \
298 xinvert, tlv_array) \
296{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ 299{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
297 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ 300 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
298 SNDRV_CTL_ELEM_ACCESS_READWRITE, \ 301 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
299 .tlv.p = (tlv_array), \ 302 .tlv.p = (tlv_array), \
300 .info = snd_soc_info_volsw_2r, \ 303 .info = snd_soc_info_volsw_2r, \
301 .get = snd_soc_get_volsw_2r, .put = wm8580_out_vu, \ 304 .get = snd_soc_get_volsw_2r, .put = wm8580_out_vu, \
302 .private_value = (reg_left) | ((shift) << 8) | \ 305 .private_value = (unsigned long)&(struct soc_mixer_control) \
303 ((max) << 12) | ((invert) << 20) | ((reg_right) << 24) } 306 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
307 .max = xmax, .invert = xinvert} }
304 308
305static const struct snd_kcontrol_new wm8580_snd_controls[] = { 309static const struct snd_kcontrol_new wm8580_snd_controls[] = {
306SOC_WM8580_OUT_DOUBLE_R_TLV("DAC1 Playback Volume", 310SOC_WM8580_OUT_DOUBLE_R_TLV("DAC1 Playback Volume",
@@ -522,7 +526,7 @@ static int wm8580_set_dai_pll(struct snd_soc_dai *codec_dai,
522 reg = wm8580_read(codec, WM8580_PLLA4 + offset); 526 reg = wm8580_read(codec, WM8580_PLLA4 + offset);
523 reg &= ~0x3f; 527 reg &= ~0x3f;
524 reg |= pll_div.prescale | pll_div.postscale << 1 | 528 reg |= pll_div.prescale | pll_div.postscale << 1 |
525 pll_div.freqmode << 4; 529 pll_div.freqmode << 3;
526 530
527 wm8580_write(codec, WM8580_PLLA4 + offset, reg); 531 wm8580_write(codec, WM8580_PLLA4 + offset, reg);
528 532
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index c518c3e5aa3f..40cd274eb1ef 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -729,7 +729,7 @@ SND_SOC_DAPM_MIXER_E("INMIXL", WM8990_INTDRIVBITS, WM8990_INMIXL_PWR_BIT, 0,
729 inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 729 inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
730 730
731/* AINLMUX */ 731/* AINLMUX */
732SND_SOC_DAPM_MUX_E("AILNMUX", WM8990_INTDRIVBITS, WM8990_AINLMUX_PWR_BIT, 0, 732SND_SOC_DAPM_MUX_E("AINLMUX", WM8990_INTDRIVBITS, WM8990_AINLMUX_PWR_BIT, 0,
733 &wm8990_dapm_ainlmux_controls, inmixer_event, 733 &wm8990_dapm_ainlmux_controls, inmixer_event,
734 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 734 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
735 735
@@ -740,7 +740,7 @@ SND_SOC_DAPM_MIXER_E("INMIXR", WM8990_INTDRIVBITS, WM8990_INMIXR_PWR_BIT, 0,
740 inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 740 inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
741 741
742/* AINRMUX */ 742/* AINRMUX */
743SND_SOC_DAPM_MUX_E("AIRNMUX", WM8990_INTDRIVBITS, WM8990_AINRMUX_PWR_BIT, 0, 743SND_SOC_DAPM_MUX_E("AINRMUX", WM8990_INTDRIVBITS, WM8990_AINRMUX_PWR_BIT, 0,
744 &wm8990_dapm_ainrmux_controls, inmixer_event, 744 &wm8990_dapm_ainrmux_controls, inmixer_event,
745 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 745 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
746 746
@@ -848,40 +848,40 @@ static const struct snd_soc_dapm_route audio_map[] = {
848 {"LIN12 PGA", "LIN2 Switch", "LIN2"}, 848 {"LIN12 PGA", "LIN2 Switch", "LIN2"},
849 /* LIN34 PGA */ 849 /* LIN34 PGA */
850 {"LIN34 PGA", "LIN3 Switch", "LIN3"}, 850 {"LIN34 PGA", "LIN3 Switch", "LIN3"},
851 {"LIN34 PGA", "LIN4 Switch", "LIN4"}, 851 {"LIN34 PGA", "LIN4 Switch", "LIN4/RXN"},
852 /* INMIXL */ 852 /* INMIXL */
853 {"INMIXL", "Record Left Volume", "LOMIX"}, 853 {"INMIXL", "Record Left Volume", "LOMIX"},
854 {"INMIXL", "LIN2 Volume", "LIN2"}, 854 {"INMIXL", "LIN2 Volume", "LIN2"},
855 {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"}, 855 {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"},
856 {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"}, 856 {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"},
857 /* AILNMUX */ 857 /* AINLMUX */
858 {"AILNMUX", "INMIXL Mix", "INMIXL"}, 858 {"AINLMUX", "INMIXL Mix", "INMIXL"},
859 {"AILNMUX", "DIFFINL Mix", "LIN12PGA"}, 859 {"AINLMUX", "DIFFINL Mix", "LIN12 PGA"},
860 {"AILNMUX", "DIFFINL Mix", "LIN34PGA"}, 860 {"AINLMUX", "DIFFINL Mix", "LIN34 PGA"},
861 {"AILNMUX", "RXVOICE Mix", "LIN4/RXN"}, 861 {"AINLMUX", "RXVOICE Mix", "LIN4/RXN"},
862 {"AILNMUX", "RXVOICE Mix", "RIN4/RXP"}, 862 {"AINLMUX", "RXVOICE Mix", "RIN4/RXP"},
863 /* ADC */ 863 /* ADC */
864 {"Left ADC", NULL, "AILNMUX"}, 864 {"Left ADC", NULL, "AINLMUX"},
865 865
866 /* RIN12 PGA */ 866 /* RIN12 PGA */
867 {"RIN12 PGA", "RIN1 Switch", "RIN1"}, 867 {"RIN12 PGA", "RIN1 Switch", "RIN1"},
868 {"RIN12 PGA", "RIN2 Switch", "RIN2"}, 868 {"RIN12 PGA", "RIN2 Switch", "RIN2"},
869 /* RIN34 PGA */ 869 /* RIN34 PGA */
870 {"RIN34 PGA", "RIN3 Switch", "RIN3"}, 870 {"RIN34 PGA", "RIN3 Switch", "RIN3"},
871 {"RIN34 PGA", "RIN4 Switch", "RIN4"}, 871 {"RIN34 PGA", "RIN4 Switch", "RIN4/RXP"},
872 /* INMIXL */ 872 /* INMIXL */
873 {"INMIXR", "Record Right Volume", "ROMIX"}, 873 {"INMIXR", "Record Right Volume", "ROMIX"},
874 {"INMIXR", "RIN2 Volume", "RIN2"}, 874 {"INMIXR", "RIN2 Volume", "RIN2"},
875 {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"}, 875 {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"},
876 {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"}, 876 {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"},
877 /* AIRNMUX */ 877 /* AINRMUX */
878 {"AIRNMUX", "INMIXR Mix", "INMIXR"}, 878 {"AINRMUX", "INMIXR Mix", "INMIXR"},
879 {"AIRNMUX", "DIFFINR Mix", "RIN12PGA"}, 879 {"AINRMUX", "DIFFINR Mix", "RIN12 PGA"},
880 {"AIRNMUX", "DIFFINR Mix", "RIN34PGA"}, 880 {"AINRMUX", "DIFFINR Mix", "RIN34 PGA"},
881 {"AIRNMUX", "RXVOICE Mix", "RIN4/RXN"}, 881 {"AINRMUX", "RXVOICE Mix", "LIN4/RXN"},
882 {"AIRNMUX", "RXVOICE Mix", "RIN4/RXP"}, 882 {"AINRMUX", "RXVOICE Mix", "RIN4/RXP"},
883 /* ADC */ 883 /* ADC */
884 {"Right ADC", NULL, "AIRNMUX"}, 884 {"Right ADC", NULL, "AINRMUX"},
885 885
886 /* LOMIX */ 886 /* LOMIX */
887 {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"}, 887 {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"},
@@ -922,7 +922,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
922 {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"}, 922 {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"},
923 923
924 /* OUT3MIX */ 924 /* OUT3MIX */
925 {"OUT3MIX", "OUT3MIX LIN4/RXP Bypass Switch", "LIN4/RXP"}, 925 {"OUT3MIX", "OUT3MIX LIN4/RXP Bypass Switch", "LIN4/RXN"},
926 {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"}, 926 {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"},
927 927
928 /* OUT4MIX */ 928 /* OUT4MIX */
@@ -949,7 +949,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
949 /* Output Pins */ 949 /* Output Pins */
950 {"LON", NULL, "LONMIX"}, 950 {"LON", NULL, "LONMIX"},
951 {"LOP", NULL, "LOPMIX"}, 951 {"LOP", NULL, "LOPMIX"},
952 {"OUT", NULL, "OUT3MIX"}, 952 {"OUT3", NULL, "OUT3MIX"},
953 {"LOUT", NULL, "LOUT PGA"}, 953 {"LOUT", NULL, "LOUT PGA"},
954 {"SPKN", NULL, "SPKMIX"}, 954 {"SPKN", NULL, "SPKMIX"},
955 {"ROUT", NULL, "ROUT PGA"}, 955 {"ROUT", NULL, "ROUT PGA"},
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c
index 6e23a81dba78..c2d1a7a18fa3 100644
--- a/sound/soc/codecs/wm9705.c
+++ b/sound/soc/codecs/wm9705.c
@@ -318,7 +318,7 @@ static int wm9705_reset(struct snd_soc_codec *codec)
318} 318}
319 319
320#ifdef CONFIG_PM 320#ifdef CONFIG_PM
321static int wm9705_soc_suspend(struct platform_device *pdev) 321static int wm9705_soc_suspend(struct platform_device *pdev, pm_message_t msg)
322{ 322{
323 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 323 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
324 struct snd_soc_codec *codec = socdev->card->codec; 324 struct snd_soc_codec *codec = socdev->card->codec;
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig
index bd7392c9657e..411a710be660 100644
--- a/sound/soc/davinci/Kconfig
+++ b/sound/soc/davinci/Kconfig
@@ -10,13 +10,14 @@ config SND_DAVINCI_SOC_I2S
10 tristate 10 tristate
11 11
12config SND_DAVINCI_SOC_EVM 12config SND_DAVINCI_SOC_EVM
13 tristate "SoC Audio support for DaVinci EVM" 13 tristate "SoC Audio support for DaVinci DM6446 or DM355 EVM"
14 depends on SND_DAVINCI_SOC && MACH_DAVINCI_EVM 14 depends on SND_DAVINCI_SOC
15 depends on MACH_DAVINCI_EVM || MACH_DAVINCI_DM355_EVM
15 select SND_DAVINCI_SOC_I2S 16 select SND_DAVINCI_SOC_I2S
16 select SND_SOC_TLV320AIC3X 17 select SND_SOC_TLV320AIC3X
17 help 18 help
18 Say Y if you want to add support for SoC audio on TI 19 Say Y if you want to add support for SoC audio on TI
19 DaVinci EVM platform. 20 DaVinci DM6446 or DM355 EVM platforms.
20 21
21config SND_DAVINCI_SOC_SFFSDR 22config SND_DAVINCI_SOC_SFFSDR
22 tristate "SoC Audio support for SFFSDR" 23 tristate "SoC Audio support for SFFSDR"
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index 9b90b347007c..58fd1cbedd88 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -20,7 +20,11 @@
20#include <sound/soc-dapm.h> 20#include <sound/soc-dapm.h>
21 21
22#include <asm/dma.h> 22#include <asm/dma.h>
23#include <mach/hardware.h> 23#include <asm/mach-types.h>
24
25#include <mach/asp.h>
26#include <mach/edma.h>
27#include <mach/mux.h>
24 28
25#include "../codecs/tlv320aic3x.h" 29#include "../codecs/tlv320aic3x.h"
26#include "davinci-pcm.h" 30#include "davinci-pcm.h"
@@ -150,7 +154,7 @@ static struct snd_soc_card snd_soc_card_evm = {
150 154
151/* evm audio private data */ 155/* evm audio private data */
152static struct aic3x_setup_data evm_aic3x_setup = { 156static struct aic3x_setup_data evm_aic3x_setup = {
153 .i2c_bus = 0, 157 .i2c_bus = 1,
154 .i2c_address = 0x1b, 158 .i2c_address = 0x1b,
155}; 159};
156 160
@@ -161,36 +165,73 @@ static struct snd_soc_device evm_snd_devdata = {
161 .codec_data = &evm_aic3x_setup, 165 .codec_data = &evm_aic3x_setup,
162}; 166};
163 167
168/* DM6446 EVM uses ASP0; line-out is a pair of RCA jacks */
164static struct resource evm_snd_resources[] = { 169static struct resource evm_snd_resources[] = {
165 { 170 {
166 .start = DAVINCI_MCBSP_BASE, 171 .start = DAVINCI_ASP0_BASE,
167 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1, 172 .end = DAVINCI_ASP0_BASE + SZ_8K - 1,
168 .flags = IORESOURCE_MEM, 173 .flags = IORESOURCE_MEM,
169 }, 174 },
170}; 175};
171 176
172static struct evm_snd_platform_data evm_snd_data = { 177static struct evm_snd_platform_data evm_snd_data = {
173 .tx_dma_ch = DM644X_DMACH_MCBSP_TX, 178 .tx_dma_ch = DAVINCI_DMA_ASP0_TX,
174 .rx_dma_ch = DM644X_DMACH_MCBSP_RX, 179 .rx_dma_ch = DAVINCI_DMA_ASP0_RX,
180};
181
182/* DM335 EVM uses ASP1; line-out is a stereo mini-jack */
183static struct resource dm335evm_snd_resources[] = {
184 {
185 .start = DAVINCI_ASP1_BASE,
186 .end = DAVINCI_ASP1_BASE + SZ_8K - 1,
187 .flags = IORESOURCE_MEM,
188 },
189};
190
191static struct evm_snd_platform_data dm335evm_snd_data = {
192 .tx_dma_ch = DAVINCI_DMA_ASP1_TX,
193 .rx_dma_ch = DAVINCI_DMA_ASP1_RX,
175}; 194};
176 195
177static struct platform_device *evm_snd_device; 196static struct platform_device *evm_snd_device;
178 197
179static int __init evm_init(void) 198static int __init evm_init(void)
180{ 199{
200 struct resource *resources;
201 unsigned num_resources;
202 struct evm_snd_platform_data *data;
203 int index;
181 int ret; 204 int ret;
182 205
183 evm_snd_device = platform_device_alloc("soc-audio", 0); 206 if (machine_is_davinci_evm()) {
207 davinci_cfg_reg(DM644X_MCBSP);
208
209 resources = evm_snd_resources;
210 num_resources = ARRAY_SIZE(evm_snd_resources);
211 data = &evm_snd_data;
212 index = 0;
213 } else if (machine_is_davinci_dm355_evm()) {
214 /* we don't use ASP1 IRQs, or we'd need to mux them ... */
215 davinci_cfg_reg(DM355_EVT8_ASP1_TX);
216 davinci_cfg_reg(DM355_EVT9_ASP1_RX);
217
218 resources = dm335evm_snd_resources;
219 num_resources = ARRAY_SIZE(dm335evm_snd_resources);
220 data = &dm335evm_snd_data;
221 index = 1;
222 } else
223 return -EINVAL;
224
225 evm_snd_device = platform_device_alloc("soc-audio", index);
184 if (!evm_snd_device) 226 if (!evm_snd_device)
185 return -ENOMEM; 227 return -ENOMEM;
186 228
187 platform_set_drvdata(evm_snd_device, &evm_snd_devdata); 229 platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
188 evm_snd_devdata.dev = &evm_snd_device->dev; 230 evm_snd_devdata.dev = &evm_snd_device->dev;
189 platform_device_add_data(evm_snd_device, &evm_snd_data, 231 platform_device_add_data(evm_snd_device, data, sizeof(*data));
190 sizeof(evm_snd_data));
191 232
192 ret = platform_device_add_resources(evm_snd_device, evm_snd_resources, 233 ret = platform_device_add_resources(evm_snd_device, resources,
193 ARRAY_SIZE(evm_snd_resources)); 234 num_resources);
194 if (ret) { 235 if (ret) {
195 platform_device_put(evm_snd_device); 236 platform_device_put(evm_snd_device);
196 return ret; 237 return ret;
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
index ffdb9439d3d8..b1ea52fc83c7 100644
--- a/sound/soc/davinci/davinci-i2s.c
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -24,6 +24,26 @@
24 24
25#include "davinci-pcm.h" 25#include "davinci-pcm.h"
26 26
27
28/*
29 * NOTE: terminology here is confusing.
30 *
31 * - This driver supports the "Audio Serial Port" (ASP),
32 * found on dm6446, dm355, and other DaVinci chips.
33 *
34 * - But it labels it a "Multi-channel Buffered Serial Port"
35 * (McBSP) as on older chips like the dm642 ... which was
36 * backward-compatible, possibly explaining that confusion.
37 *
38 * - OMAP chips have a controller called McBSP, which is
39 * incompatible with the DaVinci flavor of McBSP.
40 *
41 * - Newer DaVinci chips have a controller called McASP,
42 * incompatible with ASP and with either McBSP.
43 *
44 * In short: this uses ASP to implement I2S, not McBSP.
45 * And it won't be the only DaVinci implemention of I2S.
46 */
27#define DAVINCI_MCBSP_DRR_REG 0x00 47#define DAVINCI_MCBSP_DRR_REG 0x00
28#define DAVINCI_MCBSP_DXR_REG 0x04 48#define DAVINCI_MCBSP_DXR_REG 0x04
29#define DAVINCI_MCBSP_SPCR_REG 0x08 49#define DAVINCI_MCBSP_SPCR_REG 0x08
@@ -421,7 +441,7 @@ static int davinci_i2s_probe(struct platform_device *pdev,
421{ 441{
422 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 442 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
423 struct snd_soc_card *card = socdev->card; 443 struct snd_soc_card *card = socdev->card;
424 struct snd_soc_dai *cpu_dai = card->dai_link[pdev->id].cpu_dai; 444 struct snd_soc_dai *cpu_dai = card->dai_link->cpu_dai;
425 struct davinci_mcbsp_dev *dev; 445 struct davinci_mcbsp_dev *dev;
426 struct resource *mem, *ioarea; 446 struct resource *mem, *ioarea;
427 struct evm_snd_platform_data *pdata; 447 struct evm_snd_platform_data *pdata;
@@ -448,7 +468,7 @@ static int davinci_i2s_probe(struct platform_device *pdev,
448 468
449 cpu_dai->private_data = dev; 469 cpu_dai->private_data = dev;
450 470
451 dev->clk = clk_get(&pdev->dev, "McBSPCLK"); 471 dev->clk = clk_get(&pdev->dev, NULL);
452 if (IS_ERR(dev->clk)) { 472 if (IS_ERR(dev->clk)) {
453 ret = -ENODEV; 473 ret = -ENODEV;
454 goto err_free_mem; 474 goto err_free_mem;
@@ -483,7 +503,7 @@ static void davinci_i2s_remove(struct platform_device *pdev,
483{ 503{
484 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 504 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
485 struct snd_soc_card *card = socdev->card; 505 struct snd_soc_card *card = socdev->card;
486 struct snd_soc_dai *cpu_dai = card->dai_link[pdev->id].cpu_dai; 506 struct snd_soc_dai *cpu_dai = card->dai_link->cpu_dai;
487 struct davinci_mcbsp_dev *dev = cpu_dai->private_data; 507 struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
488 struct resource *mem; 508 struct resource *mem;
489 509
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
index 7af3b5b3a53d..a05996588489 100644
--- a/sound/soc/davinci/davinci-pcm.c
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -22,6 +22,7 @@
22#include <sound/soc.h> 22#include <sound/soc.h>
23 23
24#include <asm/dma.h> 24#include <asm/dma.h>
25#include <mach/edma.h>
25 26
26#include "davinci-pcm.h" 27#include "davinci-pcm.h"
27 28
@@ -51,7 +52,7 @@ struct davinci_runtime_data {
51 spinlock_t lock; 52 spinlock_t lock;
52 int period; /* current DMA period */ 53 int period; /* current DMA period */
53 int master_lch; /* Master DMA channel */ 54 int master_lch; /* Master DMA channel */
54 int slave_lch; /* Slave DMA channel */ 55 int slave_lch; /* linked parameter RAM reload slot */
55 struct davinci_pcm_dma_params *params; /* DMA params */ 56 struct davinci_pcm_dma_params *params; /* DMA params */
56}; 57};
57 58
@@ -90,18 +91,18 @@ static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
90 dst_bidx = data_type; 91 dst_bidx = data_type;
91 } 92 }
92 93
93 davinci_set_dma_src_params(lch, src, INCR, W8BIT); 94 edma_set_src(lch, src, INCR, W8BIT);
94 davinci_set_dma_dest_params(lch, dst, INCR, W8BIT); 95 edma_set_dest(lch, dst, INCR, W8BIT);
95 davinci_set_dma_src_index(lch, src_bidx, 0); 96 edma_set_src_index(lch, src_bidx, 0);
96 davinci_set_dma_dest_index(lch, dst_bidx, 0); 97 edma_set_dest_index(lch, dst_bidx, 0);
97 davinci_set_dma_transfer_params(lch, data_type, count, 1, 0, ASYNC); 98 edma_set_transfer_params(lch, data_type, count, 1, 0, ASYNC);
98 99
99 prtd->period++; 100 prtd->period++;
100 if (unlikely(prtd->period >= runtime->periods)) 101 if (unlikely(prtd->period >= runtime->periods))
101 prtd->period = 0; 102 prtd->period = 0;
102} 103}
103 104
104static void davinci_pcm_dma_irq(int lch, u16 ch_status, void *data) 105static void davinci_pcm_dma_irq(unsigned lch, u16 ch_status, void *data)
105{ 106{
106 struct snd_pcm_substream *substream = data; 107 struct snd_pcm_substream *substream = data;
107 struct davinci_runtime_data *prtd = substream->runtime->private_data; 108 struct davinci_runtime_data *prtd = substream->runtime->private_data;
@@ -125,7 +126,7 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
125 struct davinci_runtime_data *prtd = substream->runtime->private_data; 126 struct davinci_runtime_data *prtd = substream->runtime->private_data;
126 struct snd_soc_pcm_runtime *rtd = substream->private_data; 127 struct snd_soc_pcm_runtime *rtd = substream->private_data;
127 struct davinci_pcm_dma_params *dma_data = rtd->dai->cpu_dai->dma_data; 128 struct davinci_pcm_dma_params *dma_data = rtd->dai->cpu_dai->dma_data;
128 int tcc = TCC_ANY; 129 struct edmacc_param p_ram;
129 int ret; 130 int ret;
130 131
131 if (!dma_data) 132 if (!dma_data)
@@ -134,22 +135,34 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
134 prtd->params = dma_data; 135 prtd->params = dma_data;
135 136
136 /* Request master DMA channel */ 137 /* Request master DMA channel */
137 ret = davinci_request_dma(prtd->params->channel, prtd->params->name, 138 ret = edma_alloc_channel(prtd->params->channel,
138 davinci_pcm_dma_irq, substream, 139 davinci_pcm_dma_irq, substream,
139 &prtd->master_lch, &tcc, EVENTQ_0); 140 EVENTQ_0);
140 if (ret) 141 if (ret < 0)
141 return ret; 142 return ret;
143 prtd->master_lch = ret;
142 144
143 /* Request slave DMA channel */ 145 /* Request parameter RAM reload slot */
144 ret = davinci_request_dma(PARAM_ANY, "Link", 146 ret = edma_alloc_slot(EDMA_SLOT_ANY);
145 NULL, NULL, &prtd->slave_lch, &tcc, EVENTQ_0); 147 if (ret < 0) {
146 if (ret) { 148 edma_free_channel(prtd->master_lch);
147 davinci_free_dma(prtd->master_lch);
148 return ret; 149 return ret;
149 } 150 }
150 151 prtd->slave_lch = ret;
151 /* Link slave DMA channel in loopback */ 152
152 davinci_dma_link_lch(prtd->slave_lch, prtd->slave_lch); 153 /* Issue transfer completion IRQ when the channel completes a
154 * transfer, then always reload from the same slot (by a kind
155 * of loopback link). The completion IRQ handler will update
156 * the reload slot with a new buffer.
157 *
158 * REVISIT save p_ram here after setting up everything except
159 * the buffer and its length (ccnt) ... use it as a template
160 * so davinci_pcm_enqueue_dma() takes less time in IRQ.
161 */
162 edma_read_slot(prtd->slave_lch, &p_ram);
163 p_ram.opt |= TCINTEN | EDMA_TCC(prtd->master_lch);
164 p_ram.link_bcntrld = prtd->slave_lch << 5;
165 edma_write_slot(prtd->slave_lch, &p_ram);
153 166
154 return 0; 167 return 0;
155} 168}
@@ -165,12 +178,12 @@ static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
165 case SNDRV_PCM_TRIGGER_START: 178 case SNDRV_PCM_TRIGGER_START:
166 case SNDRV_PCM_TRIGGER_RESUME: 179 case SNDRV_PCM_TRIGGER_RESUME:
167 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 180 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
168 davinci_start_dma(prtd->master_lch); 181 edma_start(prtd->master_lch);
169 break; 182 break;
170 case SNDRV_PCM_TRIGGER_STOP: 183 case SNDRV_PCM_TRIGGER_STOP:
171 case SNDRV_PCM_TRIGGER_SUSPEND: 184 case SNDRV_PCM_TRIGGER_SUSPEND:
172 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 185 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
173 davinci_stop_dma(prtd->master_lch); 186 edma_stop(prtd->master_lch);
174 break; 187 break;
175 default: 188 default:
176 ret = -EINVAL; 189 ret = -EINVAL;
@@ -185,14 +198,14 @@ static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
185static int davinci_pcm_prepare(struct snd_pcm_substream *substream) 198static int davinci_pcm_prepare(struct snd_pcm_substream *substream)
186{ 199{
187 struct davinci_runtime_data *prtd = substream->runtime->private_data; 200 struct davinci_runtime_data *prtd = substream->runtime->private_data;
188 struct paramentry_descriptor temp; 201 struct edmacc_param temp;
189 202
190 prtd->period = 0; 203 prtd->period = 0;
191 davinci_pcm_enqueue_dma(substream); 204 davinci_pcm_enqueue_dma(substream);
192 205
193 /* Get slave channel dma params for master channel startup */ 206 /* Copy self-linked parameter RAM entry into master channel */
194 davinci_get_dma_params(prtd->slave_lch, &temp); 207 edma_read_slot(prtd->slave_lch, &temp);
195 davinci_set_dma_params(prtd->master_lch, &temp); 208 edma_write_slot(prtd->master_lch, &temp);
196 209
197 return 0; 210 return 0;
198} 211}
@@ -208,7 +221,7 @@ davinci_pcm_pointer(struct snd_pcm_substream *substream)
208 221
209 spin_lock(&prtd->lock); 222 spin_lock(&prtd->lock);
210 223
211 davinci_dma_getposition(prtd->master_lch, &src, &dst); 224 edma_get_position(prtd->master_lch, &src, &dst);
212 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 225 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
213 count = src - runtime->dma_addr; 226 count = src - runtime->dma_addr;
214 else 227 else
@@ -253,10 +266,10 @@ static int davinci_pcm_close(struct snd_pcm_substream *substream)
253 struct snd_pcm_runtime *runtime = substream->runtime; 266 struct snd_pcm_runtime *runtime = substream->runtime;
254 struct davinci_runtime_data *prtd = runtime->private_data; 267 struct davinci_runtime_data *prtd = runtime->private_data;
255 268
256 davinci_dma_unlink_lch(prtd->slave_lch, prtd->slave_lch); 269 edma_unlink(prtd->slave_lch);
257 270
258 davinci_free_dma(prtd->slave_lch); 271 edma_free_slot(prtd->slave_lch);
259 davinci_free_dma(prtd->master_lch); 272 edma_free_channel(prtd->master_lch);
260 273
261 kfree(prtd); 274 kfree(prtd);
262 275
diff --git a/sound/soc/fsl/mpc5200_psc_i2s.c b/sound/soc/fsl/mpc5200_psc_i2s.c
index 3aa729df27b5..1111c710118a 100644
--- a/sound/soc/fsl/mpc5200_psc_i2s.c
+++ b/sound/soc/fsl/mpc5200_psc_i2s.c
@@ -504,7 +504,8 @@ static struct snd_soc_dai psc_i2s_dai_template = {
504 504
505static const struct snd_pcm_hardware psc_i2s_pcm_hardware = { 505static const struct snd_pcm_hardware psc_i2s_pcm_hardware = {
506 .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | 506 .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
507 SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER, 507 SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
508 SNDRV_PCM_INFO_BATCH,
508 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE | 509 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE |
509 SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE, 510 SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE,
510 .rate_min = 8000, 511 .rate_min = 8000,
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c
index a6d1178ce128..91ef17992de5 100644
--- a/sound/soc/omap/n810.c
+++ b/sound/soc/omap/n810.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (C) 2008 Nokia Corporation
5 * 5 *
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com> 6 * Contact: Jarkko Nikula <jhnikula@gmail.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License 9 * modify it under the terms of the GNU General Public License
@@ -417,6 +417,6 @@ static void __exit n810_soc_exit(void)
417module_init(n810_soc_init); 417module_init(n810_soc_init);
418module_exit(n810_soc_exit); 418module_exit(n810_soc_exit);
419 419
420MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@nokia.com>"); 420MODULE_AUTHOR("Jarkko Nikula <jhnikula@gmail.com>");
421MODULE_DESCRIPTION("ALSA SoC Nokia N810"); 421MODULE_DESCRIPTION("ALSA SoC Nokia N810");
422MODULE_LICENSE("GPL"); 422MODULE_LICENSE("GPL");
diff --git a/sound/soc/omap/omap-mcbsp.c b/sound/soc/omap/omap-mcbsp.c
index 9c09b94f0cf8..912614283848 100644
--- a/sound/soc/omap/omap-mcbsp.c
+++ b/sound/soc/omap/omap-mcbsp.c
@@ -3,7 +3,8 @@
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (C) 2008 Nokia Corporation
5 * 5 *
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com> 6 * Contact: Jarkko Nikula <jhnikula@gmail.com>
7 * Peter Ujfalusi <peter.ujfalusi@nokia.com>
7 * 8 *
8 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License 10 * modify it under the terms of the GNU General Public License
@@ -283,7 +284,7 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
283 break; 284 break;
284 case SND_SOC_DAIFMT_DSP_B: 285 case SND_SOC_DAIFMT_DSP_B:
285 regs->srgr2 |= FPER(wlen * channels - 1); 286 regs->srgr2 |= FPER(wlen * channels - 1);
286 regs->srgr1 |= FWID(wlen * channels - 2); 287 regs->srgr1 |= FWID(0);
287 break; 288 break;
288 } 289 }
289 290
@@ -302,6 +303,7 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
302{ 303{
303 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data); 304 struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
304 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs; 305 struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
306 unsigned int temp_fmt = fmt;
305 307
306 if (mcbsp_data->configured) 308 if (mcbsp_data->configured)
307 return 0; 309 return 0;
@@ -328,6 +330,8 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
328 /* 0-bit data delay */ 330 /* 0-bit data delay */
329 regs->rcr2 |= RDATDLY(0); 331 regs->rcr2 |= RDATDLY(0);
330 regs->xcr2 |= XDATDLY(0); 332 regs->xcr2 |= XDATDLY(0);
333 /* Invert FS polarity configuration */
334 temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
331 break; 335 break;
332 default: 336 default:
333 /* Unsupported data format */ 337 /* Unsupported data format */
@@ -351,7 +355,7 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
351 } 355 }
352 356
353 /* Set bit clock (CLKX/CLKR) and FS polarities */ 357 /* Set bit clock (CLKX/CLKR) and FS polarities */
354 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 358 switch (temp_fmt & SND_SOC_DAIFMT_INV_MASK) {
355 case SND_SOC_DAIFMT_NB_NF: 359 case SND_SOC_DAIFMT_NB_NF:
356 /* 360 /*
357 * Normal BCLK + FS. 361 * Normal BCLK + FS.
@@ -529,6 +533,6 @@ static void __exit snd_omap_mcbsp_exit(void)
529} 533}
530module_exit(snd_omap_mcbsp_exit); 534module_exit(snd_omap_mcbsp_exit);
531 535
532MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@nokia.com>"); 536MODULE_AUTHOR("Jarkko Nikula <jhnikula@gmail.com>");
533MODULE_DESCRIPTION("OMAP I2S SoC Interface"); 537MODULE_DESCRIPTION("OMAP I2S SoC Interface");
534MODULE_LICENSE("GPL"); 538MODULE_LICENSE("GPL");
diff --git a/sound/soc/omap/omap-mcbsp.h b/sound/soc/omap/omap-mcbsp.h
index df7ad13ba73d..c8147aace813 100644
--- a/sound/soc/omap/omap-mcbsp.h
+++ b/sound/soc/omap/omap-mcbsp.h
@@ -3,7 +3,8 @@
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (C) 2008 Nokia Corporation
5 * 5 *
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com> 6 * Contact: Jarkko Nikula <jhnikula@gmail.com>
7 * Peter Ujfalusi <peter.ujfalusi@nokia.com>
7 * 8 *
8 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License 10 * modify it under the terms of the GNU General Public License
diff --git a/sound/soc/omap/omap-pcm.c b/sound/soc/omap/omap-pcm.c
index 1bdbb0427183..07cf7f46b584 100644
--- a/sound/soc/omap/omap-pcm.c
+++ b/sound/soc/omap/omap-pcm.c
@@ -3,7 +3,8 @@
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (C) 2008 Nokia Corporation
5 * 5 *
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com> 6 * Contact: Jarkko Nikula <jhnikula@gmail.com>
7 * Peter Ujfalusi <peter.ujfalusi@nokia.com>
7 * 8 *
8 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License 10 * modify it under the terms of the GNU General Public License
@@ -367,6 +368,6 @@ static void __exit omap_soc_platform_exit(void)
367} 368}
368module_exit(omap_soc_platform_exit); 369module_exit(omap_soc_platform_exit);
369 370
370MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@nokia.com>"); 371MODULE_AUTHOR("Jarkko Nikula <jhnikula@gmail.com>");
371MODULE_DESCRIPTION("OMAP PCM DMA module"); 372MODULE_DESCRIPTION("OMAP PCM DMA module");
372MODULE_LICENSE("GPL"); 373MODULE_LICENSE("GPL");
diff --git a/sound/soc/omap/omap-pcm.h b/sound/soc/omap/omap-pcm.h
index e4369bdfd77d..8d9d26916b05 100644
--- a/sound/soc/omap/omap-pcm.h
+++ b/sound/soc/omap/omap-pcm.h
@@ -3,7 +3,8 @@
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (C) 2008 Nokia Corporation
5 * 5 *
6 * Contact: Jarkko Nikula <jarkko.nikula@nokia.com> 6 * Contact: Jarkko Nikula <jhnikula@gmail.com>
7 * Peter Ujfalusi <peter.ujfalusi@nokia.com>
7 * 8 *
8 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License 10 * modify it under the terms of the GNU General Public License
diff --git a/sound/soc/omap/osk5912.c b/sound/soc/omap/osk5912.c
index a952a4eb3361..a4e149b7f0eb 100644
--- a/sound/soc/omap/osk5912.c
+++ b/sound/soc/omap/osk5912.c
@@ -62,7 +62,7 @@ static int osk_hw_params(struct snd_pcm_substream *substream,
62 /* Set codec DAI configuration */ 62 /* Set codec DAI configuration */
63 err = snd_soc_dai_set_fmt(codec_dai, 63 err = snd_soc_dai_set_fmt(codec_dai,
64 SND_SOC_DAIFMT_DSP_B | 64 SND_SOC_DAIFMT_DSP_B |
65 SND_SOC_DAIFMT_NB_IF | 65 SND_SOC_DAIFMT_NB_NF |
66 SND_SOC_DAIFMT_CBM_CFM); 66 SND_SOC_DAIFMT_CBM_CFM);
67 if (err < 0) { 67 if (err < 0) {
68 printk(KERN_ERR "can't set codec DAI configuration\n"); 68 printk(KERN_ERR "can't set codec DAI configuration\n");
@@ -72,7 +72,7 @@ static int osk_hw_params(struct snd_pcm_substream *substream,
72 /* Set cpu DAI configuration */ 72 /* Set cpu DAI configuration */
73 err = snd_soc_dai_set_fmt(cpu_dai, 73 err = snd_soc_dai_set_fmt(cpu_dai,
74 SND_SOC_DAIFMT_DSP_B | 74 SND_SOC_DAIFMT_DSP_B |
75 SND_SOC_DAIFMT_NB_IF | 75 SND_SOC_DAIFMT_NB_NF |
76 SND_SOC_DAIFMT_CBM_CFM); 76 SND_SOC_DAIFMT_CBM_CFM);
77 if (err < 0) { 77 if (err < 0) {
78 printk(KERN_ERR "can't set cpu DAI configuration\n"); 78 printk(KERN_ERR "can't set cpu DAI configuration\n");
diff --git a/sound/soc/pxa/magician.c b/sound/soc/pxa/magician.c
index f7c4544f7859..0625c342a1c9 100644
--- a/sound/soc/pxa/magician.c
+++ b/sound/soc/pxa/magician.c
@@ -27,8 +27,6 @@
27#include <sound/soc.h> 27#include <sound/soc.h>
28#include <sound/soc-dapm.h> 28#include <sound/soc-dapm.h>
29 29
30#include <mach/pxa-regs.h>
31#include <mach/hardware.h>
32#include <mach/magician.h> 30#include <mach/magician.h>
33#include <asm/mach-types.h> 31#include <asm/mach-types.h>
34#include "../codecs/uda1380.h" 32#include "../codecs/uda1380.h"
diff --git a/sound/soc/pxa/palm27x.c b/sound/soc/pxa/palm27x.c
index 48a73f64500b..44fcc4e01e08 100644
--- a/sound/soc/pxa/palm27x.c
+++ b/sound/soc/pxa/palm27x.c
@@ -200,7 +200,7 @@ static struct snd_soc_device palm27x_snd_devdata = {
200 200
201static struct platform_device *palm27x_snd_device; 201static struct platform_device *palm27x_snd_device;
202 202
203static int __init palm27x_asoc_init(void) 203static int palm27x_asoc_probe(struct platform_device *pdev)
204{ 204{
205 int ret; 205 int ret;
206 206
@@ -208,6 +208,10 @@ static int __init palm27x_asoc_init(void)
208 machine_is_palmld())) 208 machine_is_palmld()))
209 return -ENODEV; 209 return -ENODEV;
210 210
211 if (pdev->dev.platform_data)
212 palm27x_ep_gpio = ((struct palm27x_asoc_info *)
213 (pdev->dev.platform_data))->jack_gpio;
214
211 ret = gpio_request(palm27x_ep_gpio, "Headphone Jack"); 215 ret = gpio_request(palm27x_ep_gpio, "Headphone Jack");
212 if (ret) 216 if (ret)
213 return ret; 217 return ret;
@@ -245,16 +249,31 @@ err_alloc:
245 return ret; 249 return ret;
246} 250}
247 251
248static void __exit palm27x_asoc_exit(void) 252static int __devexit palm27x_asoc_remove(struct platform_device *pdev)
249{ 253{
250 free_irq(gpio_to_irq(palm27x_ep_gpio), NULL); 254 free_irq(gpio_to_irq(palm27x_ep_gpio), NULL);
251 gpio_free(palm27x_ep_gpio); 255 gpio_free(palm27x_ep_gpio);
252 platform_device_unregister(palm27x_snd_device); 256 platform_device_unregister(palm27x_snd_device);
257 return 0;
253} 258}
254 259
255void __init palm27x_asoc_set_pdata(struct palm27x_asoc_info *data) 260static struct platform_driver palm27x_wm9712_driver = {
261 .probe = palm27x_asoc_probe,
262 .remove = __devexit_p(palm27x_asoc_remove),
263 .driver = {
264 .name = "palm27x-asoc",
265 .owner = THIS_MODULE,
266 },
267};
268
269static int __init palm27x_asoc_init(void)
270{
271 return platform_driver_register(&palm27x_wm9712_driver);
272}
273
274static void __exit palm27x_asoc_exit(void)
256{ 275{
257 palm27x_ep_gpio = data->jack_gpio; 276 platform_driver_unregister(&palm27x_wm9712_driver);
258} 277}
259 278
260module_init(palm27x_asoc_init); 279module_init(palm27x_asoc_init);
diff --git a/sound/soc/pxa/pxa-ssp.c b/sound/soc/pxa/pxa-ssp.c
index 308a657928d2..286be31545df 100644
--- a/sound/soc/pxa/pxa-ssp.c
+++ b/sound/soc/pxa/pxa-ssp.c
@@ -280,12 +280,33 @@ static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
280 * ssp_set_clkdiv - set SSP clock divider 280 * ssp_set_clkdiv - set SSP clock divider
281 * @div: serial clock rate divider 281 * @div: serial clock rate divider
282 */ 282 */
283static void ssp_set_scr(struct ssp_dev *dev, u32 div) 283static void ssp_set_scr(struct ssp_device *ssp, u32 div)
284{ 284{
285 struct ssp_device *ssp = dev->ssp; 285 u32 sscr0 = ssp_read_reg(ssp, SSCR0);
286 u32 sscr0 = ssp_read_reg(dev->ssp, SSCR0) & ~SSCR0_SCR; 286
287 if (cpu_is_pxa25x() && ssp->type == PXA25x_SSP) {
288 sscr0 &= ~0x0000ff00;
289 sscr0 |= ((div - 2)/2) << 8; /* 2..512 */
290 } else {
291 sscr0 &= ~0x000fff00;
292 sscr0 |= (div - 1) << 8; /* 1..4096 */
293 }
294 ssp_write_reg(ssp, SSCR0, sscr0);
295}
296
297/**
298 * ssp_get_clkdiv - get SSP clock divider
299 */
300static u32 ssp_get_scr(struct ssp_device *ssp)
301{
302 u32 sscr0 = ssp_read_reg(ssp, SSCR0);
303 u32 div;
287 304
288 ssp_write_reg(ssp, SSCR0, (sscr0 | SSCR0_SerClkDiv(div))); 305 if (cpu_is_pxa25x() && ssp->type == PXA25x_SSP)
306 div = ((sscr0 >> 8) & 0xff) * 2 + 2;
307 else
308 div = ((sscr0 >> 8) & 0xfff) + 1;
309 return div;
289} 310}
290 311
291/* 312/*
@@ -326,7 +347,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
326 break; 347 break;
327 case PXA_SSP_CLK_AUDIO: 348 case PXA_SSP_CLK_AUDIO:
328 priv->sysclk = 0; 349 priv->sysclk = 0;
329 ssp_set_scr(&priv->dev, 1); 350 ssp_set_scr(ssp, 1);
330 sscr0 |= SSCR0_ACS; 351 sscr0 |= SSCR0_ACS;
331 break; 352 break;
332 default: 353 default:
@@ -387,7 +408,7 @@ static int pxa_ssp_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
387 ssp_write_reg(ssp, SSACD, val); 408 ssp_write_reg(ssp, SSACD, val);
388 break; 409 break;
389 case PXA_SSP_DIV_SCR: 410 case PXA_SSP_DIV_SCR:
390 ssp_set_scr(&priv->dev, div); 411 ssp_set_scr(ssp, div);
391 break; 412 break;
392 default: 413 default:
393 return -ENODEV; 414 return -ENODEV;
@@ -674,8 +695,7 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
674 case SND_SOC_DAIFMT_I2S: 695 case SND_SOC_DAIFMT_I2S:
675 sspsp = ssp_read_reg(ssp, SSPSP); 696 sspsp = ssp_read_reg(ssp, SSPSP);
676 697
677 if (((sscr0 & SSCR0_SCR) == SSCR0_SerClkDiv(4)) && 698 if ((ssp_get_scr(ssp) == 4) && (width == 16)) {
678 (width == 16)) {
679 /* This is a special case where the bitclk is 64fs 699 /* This is a special case where the bitclk is 64fs
680 * and we're not dealing with 2*32 bits of audio 700 * and we're not dealing with 2*32 bits of audio
681 * samples. 701 * samples.
@@ -806,6 +826,7 @@ static int pxa_ssp_probe(struct platform_device *pdev,
806 goto err_priv; 826 goto err_priv;
807 } 827 }
808 828
829 priv->dai_fmt = (unsigned int) -1;
809 dai->private_data = priv; 830 dai->private_data = priv;
810 831
811 return 0; 832 return 0;
diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig
index 2f3a21eee051..df494d1e346f 100644
--- a/sound/soc/s3c24xx/Kconfig
+++ b/sound/soc/s3c24xx/Kconfig
@@ -1,10 +1,10 @@
1config SND_S3C24XX_SOC 1config SND_S3C24XX_SOC
2 tristate "SoC Audio for the Samsung S3CXXXX chips" 2 tristate "SoC Audio for the Samsung S3CXXXX chips"
3 depends on ARCH_S3C2410 || ARCH_S3C64XX 3 depends on ARCH_S3C2410
4 help 4 help
5 Say Y or M if you want to add support for codecs attached to 5 Say Y or M if you want to add support for codecs attached to
6 the S3C24XX and S3C64XX AC97, I2S or SSP interface. You will 6 the S3C24XX AC97 or I2S interfaces. You will also need to
7 also need to select the audio interfaces to support below. 7 select the audio interfaces to support below.
8 8
9config SND_S3C24XX_SOC_I2S 9config SND_S3C24XX_SOC_I2S
10 tristate 10 tristate
diff --git a/sound/soc/s3c24xx/jive_wm8750.c b/sound/soc/s3c24xx/jive_wm8750.c
index 32063790d95b..93e6c87b7399 100644
--- a/sound/soc/s3c24xx/jive_wm8750.c
+++ b/sound/soc/s3c24xx/jive_wm8750.c
@@ -69,8 +69,8 @@ static int jive_hw_params(struct snd_pcm_substream *substream,
69 break; 69 break;
70 } 70 }
71 71
72 s3c_i2sv2_calc_rate(&div, NULL, params_rate(params), 72 s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
73 s3c2412_get_iisclk()); 73 s3c2412_get_iisclk());
74 74
75 /* set codec DAI configuration */ 75 /* set codec DAI configuration */
76 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | 76 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
@@ -145,8 +145,9 @@ static struct snd_soc_dai_link jive_dai = {
145}; 145};
146 146
147/* jive audio machine driver */ 147/* jive audio machine driver */
148static struct snd_soc_machine snd_soc_machine_jive = { 148static struct snd_soc_card snd_soc_machine_jive = {
149 .name = "Jive", 149 .name = "Jive",
150 .platform = &s3c24xx_soc_platform,
150 .dai_link = &jive_dai, 151 .dai_link = &jive_dai,
151 .num_links = 1, 152 .num_links = 1,
152}; 153};
@@ -157,9 +158,8 @@ static struct wm8750_setup_data jive_wm8750_setup = {
157 158
158/* jive audio subsystem */ 159/* jive audio subsystem */
159static struct snd_soc_device jive_snd_devdata = { 160static struct snd_soc_device jive_snd_devdata = {
160 .machine = &snd_soc_machine_jive, 161 .card = &snd_soc_machine_jive,
161 .platform = &s3c24xx_soc_platform, 162 .codec_dev = &soc_codec_dev_wm8750,
162 .codec_dev = &soc_codec_dev_wm8750_spi,
163 .codec_data = &jive_wm8750_setup, 163 .codec_data = &jive_wm8750_setup,
164}; 164};
165 165
diff --git a/sound/soc/s3c24xx/s3c-i2s-v2.c b/sound/soc/s3c24xx/s3c-i2s-v2.c
index 295a4c910262..ab680aac3fcb 100644
--- a/sound/soc/s3c24xx/s3c-i2s-v2.c
+++ b/sound/soc/s3c24xx/s3c-i2s-v2.c
@@ -473,9 +473,9 @@ static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
473/* default table of all avaialable root fs divisors */ 473/* default table of all avaialable root fs divisors */
474static unsigned int iis_fs_tab[] = { 256, 512, 384, 768 }; 474static unsigned int iis_fs_tab[] = { 256, 512, 384, 768 };
475 475
476int s3c2412_iis_calc_rate(struct s3c_i2sv2_rate_calc *info, 476int s3c_i2sv2_iis_calc_rate(struct s3c_i2sv2_rate_calc *info,
477 unsigned int *fstab, 477 unsigned int *fstab,
478 unsigned int rate, struct clk *clk) 478 unsigned int rate, struct clk *clk)
479{ 479{
480 unsigned long clkrate = clk_get_rate(clk); 480 unsigned long clkrate = clk_get_rate(clk);
481 unsigned int div; 481 unsigned int div;
@@ -531,7 +531,7 @@ int s3c2412_iis_calc_rate(struct s3c_i2sv2_rate_calc *info,
531 531
532 return 0; 532 return 0;
533} 533}
534EXPORT_SYMBOL_GPL(s3c2412_iis_calc_rate); 534EXPORT_SYMBOL_GPL(s3c_i2sv2_iis_calc_rate);
535 535
536int s3c_i2sv2_probe(struct platform_device *pdev, 536int s3c_i2sv2_probe(struct platform_device *pdev,
537 struct snd_soc_dai *dai, 537 struct snd_soc_dai *dai,
@@ -624,15 +624,18 @@ static int s3c2412_i2s_resume(struct snd_soc_dai *dai)
624 624
625int s3c_i2sv2_register_dai(struct snd_soc_dai *dai) 625int s3c_i2sv2_register_dai(struct snd_soc_dai *dai)
626{ 626{
627 dai->ops.trigger = s3c2412_i2s_trigger; 627 struct snd_soc_dai_ops *ops = dai->ops;
628 dai->ops.hw_params = s3c2412_i2s_hw_params; 628
629 dai->ops.set_fmt = s3c2412_i2s_set_fmt; 629 ops->trigger = s3c2412_i2s_trigger;
630 dai->ops.set_clkdiv = s3c2412_i2s_set_clkdiv; 630 ops->hw_params = s3c2412_i2s_hw_params;
631 ops->set_fmt = s3c2412_i2s_set_fmt;
632 ops->set_clkdiv = s3c2412_i2s_set_clkdiv;
631 633
632 dai->suspend = s3c2412_i2s_suspend; 634 dai->suspend = s3c2412_i2s_suspend;
633 dai->resume = s3c2412_i2s_resume; 635 dai->resume = s3c2412_i2s_resume;
634 636
635 return snd_soc_register_dai(dai); 637 return snd_soc_register_dai(dai);
636} 638}
637
638EXPORT_SYMBOL_GPL(s3c_i2sv2_register_dai); 639EXPORT_SYMBOL_GPL(s3c_i2sv2_register_dai);
640
641MODULE_LICENSE("GPL");
diff --git a/sound/soc/s3c24xx/s3c2412-i2s.c b/sound/soc/s3c24xx/s3c2412-i2s.c
index 1ca3cdaa8213..b7e0b3f0bfc8 100644
--- a/sound/soc/s3c24xx/s3c2412-i2s.c
+++ b/sound/soc/s3c24xx/s3c2412-i2s.c
@@ -33,8 +33,8 @@
33 33
34#include <plat/regs-s3c2412-iis.h> 34#include <plat/regs-s3c2412-iis.h>
35 35
36#include <plat/regs-gpio.h>
37#include <plat/audio.h> 36#include <plat/audio.h>
37#include <mach/regs-gpio.h>
38#include <mach/dma.h> 38#include <mach/dma.h>
39 39
40#include "s3c24xx-pcm.h" 40#include "s3c24xx-pcm.h"
diff --git a/sound/soc/sh/dma-sh7760.c b/sound/soc/sh/dma-sh7760.c
index 0dad3a0bb920..baddb1242c71 100644
--- a/sound/soc/sh/dma-sh7760.c
+++ b/sound/soc/sh/dma-sh7760.c
@@ -103,7 +103,8 @@ static struct snd_pcm_hardware camelot_pcm_hardware = {
103 .info = (SNDRV_PCM_INFO_MMAP | 103 .info = (SNDRV_PCM_INFO_MMAP |
104 SNDRV_PCM_INFO_INTERLEAVED | 104 SNDRV_PCM_INFO_INTERLEAVED |
105 SNDRV_PCM_INFO_BLOCK_TRANSFER | 105 SNDRV_PCM_INFO_BLOCK_TRANSFER |
106 SNDRV_PCM_INFO_MMAP_VALID), 106 SNDRV_PCM_INFO_MMAP_VALID |
107 SNDRV_PCM_INFO_BATCH),
107 .formats = DMABRG_FMTS, 108 .formats = DMABRG_FMTS,
108 .rates = DMABRG_RATES, 109 .rates = DMABRG_RATES,
109 .rate_min = 8000, 110 .rate_min = 8000,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 99712f652d0d..1cd149b9ce69 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -954,6 +954,9 @@ static int soc_remove(struct platform_device *pdev)
954 struct snd_soc_platform *platform = card->platform; 954 struct snd_soc_platform *platform = card->platform;
955 struct snd_soc_codec_device *codec_dev = socdev->codec_dev; 955 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
956 956
957 if (!card->instantiated)
958 return 0;
959
957 run_delayed_work(&card->delayed_work); 960 run_delayed_work(&card->delayed_work);
958 961
959 if (platform->remove) 962 if (platform->remove)
diff --git a/sound/sparc/dbri.c b/sound/sparc/dbri.c
index af95ff1e126c..1d2e51b3f918 100644
--- a/sound/sparc/dbri.c
+++ b/sound/sparc/dbri.c
@@ -1975,7 +1975,8 @@ static struct snd_pcm_hardware snd_dbri_pcm_hw = {
1975 .info = SNDRV_PCM_INFO_MMAP | 1975 .info = SNDRV_PCM_INFO_MMAP |
1976 SNDRV_PCM_INFO_INTERLEAVED | 1976 SNDRV_PCM_INFO_INTERLEAVED |
1977 SNDRV_PCM_INFO_BLOCK_TRANSFER | 1977 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1978 SNDRV_PCM_INFO_MMAP_VALID, 1978 SNDRV_PCM_INFO_MMAP_VALID |
1979 SNDRV_PCM_INFO_BATCH,
1979 .formats = SNDRV_PCM_FMTBIT_MU_LAW | 1980 .formats = SNDRV_PCM_FMTBIT_MU_LAW |
1980 SNDRV_PCM_FMTBIT_A_LAW | 1981 SNDRV_PCM_FMTBIT_A_LAW |
1981 SNDRV_PCM_FMTBIT_U8 | 1982 SNDRV_PCM_FMTBIT_U8 |
diff --git a/sound/usb/caiaq/Makefile b/sound/usb/caiaq/Makefile
index 23dadd5a11cd..388999653aaa 100644
--- a/sound/usb/caiaq/Makefile
+++ b/sound/usb/caiaq/Makefile
@@ -1,4 +1,4 @@
1snd-usb-caiaq-y := caiaq-device.o caiaq-audio.o caiaq-midi.o caiaq-control.o 1snd-usb-caiaq-y := device.o audio.o midi.o control.o
2snd-usb-caiaq-$(CONFIG_SND_USB_CAIAQ_INPUT) += caiaq-input.o 2snd-usb-caiaq-$(CONFIG_SND_USB_CAIAQ_INPUT) += input.o
3 3
4obj-$(CONFIG_SND_USB_CAIAQ) += snd-usb-caiaq.o 4obj-$(CONFIG_SND_USB_CAIAQ) += snd-usb-caiaq.o
diff --git a/sound/usb/caiaq/caiaq-audio.c b/sound/usb/caiaq/audio.c
index 08d51e0c9fea..b13ce767ac72 100644
--- a/sound/usb/caiaq/caiaq-audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -16,20 +16,14 @@
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/ 17*/
18 18
19#include <linux/spinlock.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/moduleparam.h>
22#include <linux/interrupt.h>
23#include <linux/usb.h> 21#include <linux/usb.h>
24#include <linux/spinlock.h>
25#include <sound/core.h> 22#include <sound/core.h>
26#include <sound/initval.h>
27#include <sound/pcm.h> 23#include <sound/pcm.h>
28#include <sound/rawmidi.h>
29#include <linux/input.h>
30 24
31#include "caiaq-device.h" 25#include "device.h"
32#include "caiaq-audio.h" 26#include "audio.h"
33 27
34#define N_URBS 32 28#define N_URBS 32
35#define CLOCK_DRIFT_TOLERANCE 5 29#define CLOCK_DRIFT_TOLERANCE 5
@@ -201,11 +195,14 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
201 195
202 debug("%s(%p)\n", __func__, substream); 196 debug("%s(%p)\n", __func__, substream);
203 197
204 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 198 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
199 dev->period_out_count[index] = BYTES_PER_SAMPLE + 1;
205 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1; 200 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1;
206 else 201 } else {
202 dev->period_in_count[index] = BYTES_PER_SAMPLE;
207 dev->audio_in_buf_pos[index] = BYTES_PER_SAMPLE; 203 dev->audio_in_buf_pos[index] = BYTES_PER_SAMPLE;
208 204 }
205
209 if (dev->streaming) 206 if (dev->streaming)
210 return 0; 207 return 0;
211 208
@@ -306,8 +303,7 @@ static void check_for_elapsed_periods(struct snd_usb_caiaqdev *dev,
306 if (!sub) 303 if (!sub)
307 continue; 304 continue;
308 305
309 pb = frames_to_bytes(sub->runtime, 306 pb = snd_pcm_lib_period_bytes(sub);
310 sub->runtime->period_size);
311 cnt = (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ? 307 cnt = (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
312 &dev->period_out_count[stream] : 308 &dev->period_out_count[stream] :
313 &dev->period_in_count[stream]; 309 &dev->period_in_count[stream];
diff --git a/sound/usb/caiaq/caiaq-audio.h b/sound/usb/caiaq/audio.h
index 8ab1f8d9529e..8ab1f8d9529e 100644
--- a/sound/usb/caiaq/caiaq-audio.h
+++ b/sound/usb/caiaq/audio.h
diff --git a/sound/usb/caiaq/caiaq-control.c b/sound/usb/caiaq/control.c
index e92c2bbf4fe9..537102ba6b9d 100644
--- a/sound/usb/caiaq/caiaq-control.c
+++ b/sound/usb/caiaq/control.c
@@ -18,17 +18,13 @@
18 */ 18 */
19 19
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/interrupt.h>
22#include <linux/usb.h> 21#include <linux/usb.h>
22#include <sound/control.h>
23#include <sound/core.h> 23#include <sound/core.h>
24#include <sound/initval.h>
25#include <sound/pcm.h> 24#include <sound/pcm.h>
26#include <sound/rawmidi.h>
27#include <sound/control.h>
28#include <linux/input.h>
29 25
30#include "caiaq-device.h" 26#include "device.h"
31#include "caiaq-control.h" 27#include "control.h"
32 28
33#define CNT_INTVAL 0x10000 29#define CNT_INTVAL 0x10000
34 30
diff --git a/sound/usb/caiaq/caiaq-control.h b/sound/usb/caiaq/control.h
index 2e7ab1aa4fb3..2e7ab1aa4fb3 100644
--- a/sound/usb/caiaq/caiaq-control.h
+++ b/sound/usb/caiaq/control.h
diff --git a/sound/usb/caiaq/caiaq-device.c b/sound/usb/caiaq/device.c
index cf573a982fdc..515de1cd2a3e 100644
--- a/sound/usb/caiaq/caiaq-device.c
+++ b/sound/usb/caiaq/device.c
@@ -19,30 +19,23 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20*/ 20*/
21 21
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/moduleparam.h> 22#include <linux/moduleparam.h>
25#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/input.h>
28#include <linux/spinlock.h>
29#include <sound/core.h>
30#include <sound/initval.h> 27#include <sound/initval.h>
28#include <sound/core.h>
31#include <sound/pcm.h> 29#include <sound/pcm.h>
32#include <sound/rawmidi.h>
33#include <sound/control.h>
34
35#include "caiaq-device.h"
36#include "caiaq-audio.h"
37#include "caiaq-midi.h"
38#include "caiaq-control.h"
39 30
40#ifdef CONFIG_SND_USB_CAIAQ_INPUT 31#include "device.h"
41#include "caiaq-input.h" 32#include "audio.h"
42#endif 33#include "midi.h"
34#include "control.h"
35#include "input.h"
43 36
44MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 37MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
45MODULE_DESCRIPTION("caiaq USB audio, version 1.3.13"); 38MODULE_DESCRIPTION("caiaq USB audio, version 1.3.14");
46MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
47MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 40MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
48 "{Native Instruments, RigKontrol3}," 41 "{Native Instruments, RigKontrol3},"
diff --git a/sound/usb/caiaq/caiaq-device.h b/sound/usb/caiaq/device.h
index 4cce1ad7493d..4cce1ad7493d 100644
--- a/sound/usb/caiaq/caiaq-device.h
+++ b/sound/usb/caiaq/device.h
diff --git a/sound/usb/caiaq/caiaq-input.c b/sound/usb/caiaq/input.c
index f743847a5e5a..a48d309bd94c 100644
--- a/sound/usb/caiaq/caiaq-input.c
+++ b/sound/usb/caiaq/input.c
@@ -17,17 +17,12 @@
17*/ 17*/
18 18
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/moduleparam.h>
22#include <linux/input.h>
23#include <linux/usb.h> 20#include <linux/usb.h>
24#include <linux/usb/input.h> 21#include <linux/usb/input.h>
25#include <linux/spinlock.h>
26#include <sound/core.h>
27#include <sound/rawmidi.h>
28#include <sound/pcm.h> 22#include <sound/pcm.h>
29#include "caiaq-device.h" 23
30#include "caiaq-input.h" 24#include "device.h"
25#include "input.h"
31 26
32static unsigned short keycode_ak1[] = { KEY_C, KEY_B, KEY_A }; 27static unsigned short keycode_ak1[] = { KEY_C, KEY_B, KEY_A };
33static unsigned short keycode_rk2[] = { KEY_1, KEY_2, KEY_3, KEY_4, 28static unsigned short keycode_rk2[] = { KEY_1, KEY_2, KEY_3, KEY_4,
diff --git a/sound/usb/caiaq/caiaq-input.h b/sound/usb/caiaq/input.h
index ced535577864..ced535577864 100644
--- a/sound/usb/caiaq/caiaq-input.h
+++ b/sound/usb/caiaq/input.h
diff --git a/sound/usb/caiaq/caiaq-midi.c b/sound/usb/caiaq/midi.c
index f19fd360c936..8fa8cd88d763 100644
--- a/sound/usb/caiaq/caiaq-midi.c
+++ b/sound/usb/caiaq/midi.c
@@ -16,20 +16,13 @@
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/ 17*/
18 18
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/moduleparam.h>
22#include <linux/interrupt.h>
23#include <linux/usb.h> 19#include <linux/usb.h>
24#include <linux/input.h>
25#include <linux/spinlock.h>
26#include <sound/core.h>
27#include <sound/rawmidi.h> 20#include <sound/rawmidi.h>
21#include <sound/core.h>
28#include <sound/pcm.h> 22#include <sound/pcm.h>
29 23
30#include "caiaq-device.h" 24#include "device.h"
31#include "caiaq-midi.h" 25#include "midi.h"
32
33 26
34static int snd_usb_caiaq_midi_input_open(struct snd_rawmidi_substream *substream) 27static int snd_usb_caiaq_midi_input_open(struct snd_rawmidi_substream *substream)
35{ 28{
diff --git a/sound/usb/caiaq/caiaq-midi.h b/sound/usb/caiaq/midi.h
index 9d16db027fc3..9d16db027fc3 100644
--- a/sound/usb/caiaq/caiaq-midi.h
+++ b/sound/usb/caiaq/midi.h
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index 98276aafefe6..a5aae9d67f31 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -349,14 +349,10 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
349 if (cmd != SNDRV_USB_STREAM_IOCTL_SET_PARAMS) 349 if (cmd != SNDRV_USB_STREAM_IOCTL_SET_PARAMS)
350 return -ENOTTY; 350 return -ENOTTY;
351 351
352 cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); 352 cfg = memdup_user((void *)arg, sizeof(*cfg));
353 if (!cfg) 353 if (IS_ERR(cfg))
354 return -ENOMEM; 354 return PTR_ERR(cfg);
355 355
356 if (copy_from_user(cfg, (void *)arg, sizeof(*cfg))) {
357 err = -EFAULT;
358 goto free;
359 }
360 if (cfg->version != USB_STREAM_INTERFACE_VERSION) { 356 if (cfg->version != USB_STREAM_INTERFACE_VERSION) {
361 err = -ENXIO; 357 err = -ENXIO;
362 goto free; 358 goto free;
@@ -478,6 +474,14 @@ static bool us122l_create_card(struct snd_card *card)
478 return true; 474 return true;
479} 475}
480 476
477static void snd_us122l_free(struct snd_card *card)
478{
479 struct us122l *us122l = US122L(card);
480 int index = us122l->chip.index;
481 if (index >= 0 && index < SNDRV_CARDS)
482 snd_us122l_card_used[index] = 0;
483}
484
481static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp) 485static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
482{ 486{
483 int dev; 487 int dev;
@@ -494,7 +498,7 @@ static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
494 if (err < 0) 498 if (err < 0)
495 return err; 499 return err;
496 snd_us122l_card_used[US122L(card)->chip.index = dev] = 1; 500 snd_us122l_card_used[US122L(card)->chip.index = dev] = 1;
497 501 card->private_free = snd_us122l_free;
498 US122L(card)->chip.dev = device; 502 US122L(card)->chip.dev = device;
499 US122L(card)->chip.card = card; 503 US122L(card)->chip.card = card;
500 mutex_init(&US122L(card)->mutex); 504 mutex_init(&US122L(card)->mutex);
@@ -588,7 +592,7 @@ static void snd_us122l_disconnect(struct usb_interface *intf)
588 } 592 }
589 593
590 usb_put_intf(intf); 594 usb_put_intf(intf);
591 usb_put_dev(US122L(card)->chip.dev); 595 usb_put_dev(us122l->chip.dev);
592 596
593 while (atomic_read(&us122l->mmap_count)) 597 while (atomic_read(&us122l->mmap_count))
594 msleep(500); 598 msleep(500);
diff --git a/sound/usb/usx2y/usX2Yhwdep.c b/sound/usb/usx2y/usX2Yhwdep.c
index 4af8740db717..f3d8f71265dd 100644
--- a/sound/usb/usx2y/usX2Yhwdep.c
+++ b/sound/usb/usx2y/usX2Yhwdep.c
@@ -203,13 +203,12 @@ static int snd_usX2Y_hwdep_dsp_load(struct snd_hwdep *hw,
203 203
204 if (access_ok(VERIFY_READ, dsp->image, dsp->length)) { 204 if (access_ok(VERIFY_READ, dsp->image, dsp->length)) {
205 struct usb_device* dev = priv->chip.dev; 205 struct usb_device* dev = priv->chip.dev;
206 char *buf = kmalloc(dsp->length, GFP_KERNEL); 206 char *buf;
207 if (!buf) 207
208 return -ENOMEM; 208 buf = memdup_user(dsp->image, dsp->length);
209 if (copy_from_user(buf, dsp->image, dsp->length)) { 209 if (IS_ERR(buf))
210 kfree(buf); 210 return PTR_ERR(buf);
211 return -EFAULT; 211
212 }
213 err = usb_set_interface(dev, 0, 1); 212 err = usb_set_interface(dev, 0, 1);
214 if (err) 213 if (err)
215 snd_printk(KERN_ERR "usb_set_interface error \n"); 214 snd_printk(KERN_ERR "usb_set_interface error \n");
diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c
index 24393dafcb6e..12ae0340adc0 100644
--- a/sound/usb/usx2y/usb_stream.c
+++ b/sound/usb/usx2y/usb_stream.c
@@ -33,32 +33,26 @@ static unsigned usb_stream_next_packet_size(struct usb_stream_kernel *sk)
33static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb) 33static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb)
34{ 34{
35 struct usb_stream *s = sk->s; 35 struct usb_stream *s = sk->s;
36 unsigned l = 0; 36 int pack, lb = 0;
37 int pack; 37
38 38 for (pack = 0; pack < sk->n_o_ps; pack++) {
39 urb->iso_frame_desc[0].offset = 0; 39 int l = usb_stream_next_packet_size(sk);
40 urb->iso_frame_desc[0].length = usb_stream_next_packet_size(sk); 40 if (s->idle_outsize + lb + l > s->period_size)
41 sk->out_phase = sk->out_phase_peeked;
42 urb->transfer_buffer_length = urb->iso_frame_desc[0].length;
43
44 for (pack = 1; pack < sk->n_o_ps; pack++) {
45 l = usb_stream_next_packet_size(sk);
46 if (s->idle_outsize + urb->transfer_buffer_length + l >
47 s->period_size)
48 goto check; 41 goto check;
49 42
50 sk->out_phase = sk->out_phase_peeked; 43 sk->out_phase = sk->out_phase_peeked;
51 urb->iso_frame_desc[pack].offset = urb->transfer_buffer_length; 44 urb->iso_frame_desc[pack].offset = lb;
52 urb->iso_frame_desc[pack].length = l; 45 urb->iso_frame_desc[pack].length = l;
53 urb->transfer_buffer_length += l; 46 lb += l;
54 } 47 }
55 snd_printdd(KERN_DEBUG "%i\n", urb->transfer_buffer_length); 48 snd_printdd(KERN_DEBUG "%i\n", lb);
56 49
57check: 50check:
58 urb->number_of_packets = pack; 51 urb->number_of_packets = pack;
59 s->idle_outsize += urb->transfer_buffer_length - s->period_size; 52 urb->transfer_buffer_length = lb;
53 s->idle_outsize += lb - s->period_size;
60 snd_printdd(KERN_DEBUG "idle=%i ul=%i ps=%i\n", s->idle_outsize, 54 snd_printdd(KERN_DEBUG "idle=%i ul=%i ps=%i\n", s->idle_outsize,
61 urb->transfer_buffer_length, s->period_size); 55 lb, s->period_size);
62} 56}
63 57
64static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize, 58static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
@@ -282,21 +276,20 @@ static int usb_stream_prepare_playback(struct usb_stream_kernel *sk,
282 struct usb_stream *s = sk->s; 276 struct usb_stream *s = sk->s;
283 struct urb *io; 277 struct urb *io;
284 struct usb_iso_packet_descriptor *id, *od; 278 struct usb_iso_packet_descriptor *id, *od;
285 int p, l = 0; 279 int p = 0, lb = 0, l = 0;
286 280
287 io = sk->idle_outurb; 281 io = sk->idle_outurb;
288 od = io->iso_frame_desc; 282 od = io->iso_frame_desc;
289 io->transfer_buffer_length = 0;
290 283
291 for (p = 0; s->sync_packet < 0; ++p, ++s->sync_packet) { 284 for (; s->sync_packet < 0; ++p, ++s->sync_packet) {
292 struct urb *ii = sk->completed_inurb; 285 struct urb *ii = sk->completed_inurb;
293 id = ii->iso_frame_desc + 286 id = ii->iso_frame_desc +
294 ii->number_of_packets + s->sync_packet; 287 ii->number_of_packets + s->sync_packet;
295 l = id->actual_length; 288 l = id->actual_length;
296 289
297 od[p].length = l; 290 od[p].length = l;
298 od[p].offset = io->transfer_buffer_length; 291 od[p].offset = lb;
299 io->transfer_buffer_length += l; 292 lb += l;
300 } 293 }
301 294
302 for (; 295 for (;
@@ -304,38 +297,38 @@ static int usb_stream_prepare_playback(struct usb_stream_kernel *sk,
304 ++p, ++s->sync_packet) { 297 ++p, ++s->sync_packet) {
305 l = inurb->iso_frame_desc[s->sync_packet].actual_length; 298 l = inurb->iso_frame_desc[s->sync_packet].actual_length;
306 299
307 if (s->idle_outsize + io->transfer_buffer_length + l > 300 if (s->idle_outsize + lb + l > s->period_size)
308 s->period_size)
309 goto check_ok; 301 goto check_ok;
310 302
311 od[p].length = l; 303 od[p].length = l;
312 od[p].offset = io->transfer_buffer_length; 304 od[p].offset = lb;
313 io->transfer_buffer_length += l; 305 lb += l;
314 } 306 }
315 307
316check_ok: 308check_ok:
317 s->sync_packet -= inurb->number_of_packets; 309 s->sync_packet -= inurb->number_of_packets;
318 if (s->sync_packet < -2 || s->sync_packet > 0) { 310 if (unlikely(s->sync_packet < -2 || s->sync_packet > 0)) {
319 snd_printk(KERN_WARNING "invalid sync_packet = %i;" 311 snd_printk(KERN_WARNING "invalid sync_packet = %i;"
320 " p=%i nop=%i %i %x %x %x > %x\n", 312 " p=%i nop=%i %i %x %x %x > %x\n",
321 s->sync_packet, p, inurb->number_of_packets, 313 s->sync_packet, p, inurb->number_of_packets,
322 s->idle_outsize + io->transfer_buffer_length + l, 314 s->idle_outsize + lb + l,
323 s->idle_outsize, io->transfer_buffer_length, l, 315 s->idle_outsize, lb, l,
324 s->period_size); 316 s->period_size);
325 return -1; 317 return -1;
326 } 318 }
327 if (io->transfer_buffer_length % s->cfg.frame_size) { 319 if (unlikely(lb % s->cfg.frame_size)) {
328 snd_printk(KERN_WARNING"invalid outsize = %i\n", 320 snd_printk(KERN_WARNING"invalid outsize = %i\n",
329 io->transfer_buffer_length); 321 lb);
330 return -1; 322 return -1;
331 } 323 }
332 s->idle_outsize += io->transfer_buffer_length - s->period_size; 324 s->idle_outsize += lb - s->period_size;
333 io->number_of_packets = p; 325 io->number_of_packets = p;
334 if (s->idle_outsize > 0) { 326 io->transfer_buffer_length = lb;
335 snd_printk(KERN_WARNING "idle=%i\n", s->idle_outsize); 327 if (s->idle_outsize <= 0)
336 return -1; 328 return 0;
337 } 329
338 return 0; 330 snd_printk(KERN_WARNING "idle=%i\n", s->idle_outsize);
331 return -1;
339} 332}
340 333
341static void prepare_inurb(int number_of_packets, struct urb *iu) 334static void prepare_inurb(int number_of_packets, struct urb *iu)
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index 9a608fa85155..dd1ab6177840 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -870,7 +870,8 @@ static struct snd_pcm_hardware snd_usX2Y_2c =
870{ 870{
871 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 871 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
872 SNDRV_PCM_INFO_BLOCK_TRANSFER | 872 SNDRV_PCM_INFO_BLOCK_TRANSFER |
873 SNDRV_PCM_INFO_MMAP_VALID), 873 SNDRV_PCM_INFO_MMAP_VALID |
874 SNDRV_PCM_INFO_BATCH),
874 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE, 875 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE,
875 .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, 876 .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
876 .rate_min = 44100, 877 .rate_min = 44100,