Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-2.6.35' of git://git.kernel.org/pub/scm/linux/kernel/git/lrg/asoc-2.6 into topic/asoc

+277 -54
+39 -42
sound/soc/codecs/tlv320aic3x.c
··· 38 38 #include <linux/delay.h> 39 39 #include <linux/pm.h> 40 40 #include <linux/i2c.h> 41 + #include <linux/regulator/consumer.h> 41 42 #include <linux/platform_device.h> 42 43 #include <sound/core.h> 43 44 #include <sound/pcm.h> ··· 50 49 51 50 #include "tlv320aic3x.h" 52 51 53 - #define AIC3X_VERSION "0.2" 52 + #define AIC3X_NUM_SUPPLIES 4 53 + static const char *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = { 54 + "IOVDD", /* I/O Voltage */ 55 + "DVDD", /* Digital Core Voltage */ 56 + "AVDD", /* Analog DAC Voltage */ 57 + "DRVDD", /* ADC Analog and Output Driver Voltage */ 58 + }; 54 59 55 60 /* codec private data */ 56 61 struct aic3x_priv { 57 62 struct snd_soc_codec codec; 63 + struct regulator_bulk_data supplies[AIC3X_NUM_SUPPLIES]; 58 64 unsigned int sysclk; 59 65 int master; 60 66 }; ··· 1007 999 1008 1000 switch (level) { 1009 1001 case SND_SOC_BIAS_ON: 1010 - /* all power is driven by DAPM system */ 1002 + break; 1003 + case SND_SOC_BIAS_PREPARE: 1011 1004 if (aic3x->master) { 1012 1005 /* enable pll */ 1013 1006 reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG); ··· 1016 1007 reg | PLL_ENABLE); 1017 1008 } 1018 1009 break; 1019 - case SND_SOC_BIAS_PREPARE: 1020 - break; 1021 1010 case SND_SOC_BIAS_STANDBY: 1022 - /* 1023 - * all power is driven by DAPM system, 1024 - * so output power is safe if bypass was set 1025 - */ 1026 - if (aic3x->master) { 1027 - /* disable pll */ 1028 - reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG); 1029 - aic3x_write(codec, AIC3X_PLL_PROGA_REG, 1030 - reg & ~PLL_ENABLE); 1031 - } 1032 - break; 1011 + /* fall through and disable pll */ 1033 1012 case SND_SOC_BIAS_OFF: 1034 - /* force all power off */ 1035 - reg = aic3x_read_reg_cache(codec, LINE1L_2_LADC_CTRL); 1036 - aic3x_write(codec, LINE1L_2_LADC_CTRL, reg & ~LADC_PWR_ON); 1037 - reg = aic3x_read_reg_cache(codec, LINE1R_2_RADC_CTRL); 1038 - aic3x_write(codec, LINE1R_2_RADC_CTRL, reg & ~RADC_PWR_ON); 1039 - 1040 - reg = aic3x_read_reg_cache(codec, DAC_PWR); 1041 - aic3x_write(codec, DAC_PWR, reg & ~(LDAC_PWR_ON | RDAC_PWR_ON)); 1042 - 1043 - reg = aic3x_read_reg_cache(codec, HPLOUT_CTRL); 1044 - aic3x_write(codec, HPLOUT_CTRL, reg & ~HPLOUT_PWR_ON); 1045 - reg = aic3x_read_reg_cache(codec, HPROUT_CTRL); 1046 - aic3x_write(codec, HPROUT_CTRL, reg & ~HPROUT_PWR_ON); 1047 - 1048 - reg = aic3x_read_reg_cache(codec, HPLCOM_CTRL); 1049 - aic3x_write(codec, HPLCOM_CTRL, reg & ~HPLCOM_PWR_ON); 1050 - reg = aic3x_read_reg_cache(codec, HPRCOM_CTRL); 1051 - aic3x_write(codec, HPRCOM_CTRL, reg & ~HPRCOM_PWR_ON); 1052 - 1053 - reg = aic3x_read_reg_cache(codec, MONOLOPM_CTRL); 1054 - aic3x_write(codec, MONOLOPM_CTRL, reg & ~MONOLOPM_PWR_ON); 1055 - 1056 - reg = aic3x_read_reg_cache(codec, LLOPM_CTRL); 1057 - aic3x_write(codec, LLOPM_CTRL, reg & ~LLOPM_PWR_ON); 1058 - reg = aic3x_read_reg_cache(codec, RLOPM_CTRL); 1059 - aic3x_write(codec, RLOPM_CTRL, reg & ~RLOPM_PWR_ON); 1060 - 1061 1013 if (aic3x->master) { 1062 1014 /* disable pll */ 1063 1015 reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG); ··· 1278 1308 snd_soc_unregister_dai(&aic3x_dai); 1279 1309 snd_soc_unregister_codec(&aic3x->codec); 1280 1310 1311 + regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies), aic3x->supplies); 1312 + regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies); 1313 + 1281 1314 kfree(aic3x); 1282 1315 aic3x_codec = NULL; 1283 1316 ··· 1302 1329 { 1303 1330 struct snd_soc_codec *codec; 1304 1331 struct aic3x_priv *aic3x; 1332 + int ret, i; 1305 1333 1306 1334 aic3x = kzalloc(sizeof(struct aic3x_priv), GFP_KERNEL); 1307 1335 if (aic3x == NULL) { ··· 1318 1344 1319 1345 i2c_set_clientdata(i2c, aic3x); 1320 1346 1347 + for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) 1348 + aic3x->supplies[i].supply = aic3x_supply_names[i]; 1349 + 1350 + ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(aic3x->supplies), 1351 + aic3x->supplies); 1352 + if (ret != 0) { 1353 + dev_err(codec->dev, "Failed to request supplies: %d\n", ret); 1354 + goto err_get; 1355 + } 1356 + 1357 + ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies), 1358 + aic3x->supplies); 1359 + if (ret != 0) { 1360 + dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); 1361 + goto err_enable; 1362 + } 1363 + 1321 1364 return aic3x_register(codec); 1365 + 1366 + err_enable: 1367 + regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies); 1368 + err_get: 1369 + kfree(aic3x); 1370 + return ret; 1322 1371 } 1323 1372 1324 1373 static int aic3x_i2c_remove(struct i2c_client *client)
+238 -12
sound/soc/codecs/tlv320dac33.c
··· 50 50 51 51 #define LATENCY_TIME_MS 20 52 52 53 + #define MODE7_LTHR 10 54 + #define MODE7_UTHR (DAC33_BUFFER_SIZE_SAMPLES - 10) 55 + 56 + #define BURST_BASEFREQ_HZ 49152000 57 + 58 + #define SAMPLES_TO_US(rate, samples) \ 59 + (1000000000 / ((rate * 1000) / samples)) 60 + 61 + #define US_TO_SAMPLES(rate, us) \ 62 + (rate / (1000000 / us)) 63 + 64 + 53 65 static struct snd_soc_codec *tlv320dac33_codec; 54 66 55 67 enum dac33_state { ··· 104 92 enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */ 105 93 unsigned int nsample; /* burst read amount from host */ 106 94 u8 burst_bclkdiv; /* BCLK divider value in burst mode */ 95 + unsigned int burst_rate; /* Interface speed in Burst modes */ 107 96 108 97 int keep_bclk; /* Keep the BCLK continuously running 109 98 * in FIFO modes */ 99 + spinlock_t lock; 100 + unsigned long long t_stamp1; /* Time stamp for FIFO modes to */ 101 + unsigned long long t_stamp2; /* calculate the FIFO caused delay */ 102 + 103 + unsigned int mode1_us_burst; /* Time to burst read n number of 104 + * samples */ 105 + unsigned int mode7_us_to_lthr; /* Time to reach lthr from uthr */ 106 + 110 107 enum dac33_state state; 111 108 }; 112 109 ··· 405 384 return 0; 406 385 407 386 if (ucontrol->value.integer.value[0] < dac33->nsample_min || 408 - ucontrol->value.integer.value[0] > dac33->nsample_max) 387 + ucontrol->value.integer.value[0] > dac33->nsample_max) { 409 388 ret = -EINVAL; 410 - else 389 + } else { 411 390 dac33->nsample = ucontrol->value.integer.value[0]; 391 + /* Re calculate the burst time */ 392 + dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, 393 + dac33->nsample); 394 + } 412 395 413 396 return ret; 414 397 } ··· 582 557 switch (dac33->fifo_mode) { 583 558 case DAC33_FIFO_MODE1: 584 559 dac33_write16(codec, DAC33_NSAMPLE_MSB, 585 - DAC33_THRREG(dac33->nsample)); 560 + DAC33_THRREG(dac33->nsample + dac33->alarm_threshold)); 561 + 562 + /* Take the timestamps */ 563 + spin_lock_irq(&dac33->lock); 564 + dac33->t_stamp2 = ktime_to_us(ktime_get()); 565 + dac33->t_stamp1 = dac33->t_stamp2; 566 + spin_unlock_irq(&dac33->lock); 567 + 586 568 dac33_write16(codec, DAC33_PREFILL_MSB, 587 569 DAC33_THRREG(dac33->alarm_threshold)); 570 + /* Enable Alarm Threshold IRQ with a delay */ 571 + udelay(SAMPLES_TO_US(dac33->burst_rate, 572 + dac33->alarm_threshold)); 573 + dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MAT); 588 574 break; 589 575 case DAC33_FIFO_MODE7: 576 + /* Take the timestamp */ 577 + spin_lock_irq(&dac33->lock); 578 + dac33->t_stamp1 = ktime_to_us(ktime_get()); 579 + /* Move back the timestamp with drain time */ 580 + dac33->t_stamp1 -= dac33->mode7_us_to_lthr; 581 + spin_unlock_irq(&dac33->lock); 582 + 590 583 dac33_write16(codec, DAC33_PREFILL_MSB, 591 - DAC33_THRREG(10)); 584 + DAC33_THRREG(MODE7_LTHR)); 585 + 586 + /* Enable Upper Threshold IRQ */ 587 + dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT); 592 588 break; 593 589 default: 594 590 dev_warn(codec->dev, "Unhandled FIFO mode: %d\n", ··· 626 580 627 581 switch (dac33->fifo_mode) { 628 582 case DAC33_FIFO_MODE1: 583 + /* Take the timestamp */ 584 + spin_lock_irq(&dac33->lock); 585 + dac33->t_stamp2 = ktime_to_us(ktime_get()); 586 + spin_unlock_irq(&dac33->lock); 587 + 629 588 dac33_write16(codec, DAC33_NSAMPLE_MSB, 630 589 DAC33_THRREG(dac33->nsample)); 631 590 break; ··· 683 632 struct snd_soc_codec *codec = dev; 684 633 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 685 634 686 - queue_work(dac33->dac33_wq, &dac33->work); 635 + spin_lock(&dac33->lock); 636 + dac33->t_stamp1 = ktime_to_us(ktime_get()); 637 + spin_unlock(&dac33->lock); 638 + 639 + /* Do not schedule the workqueue in Mode7 */ 640 + if (dac33->fifo_mode != DAC33_FIFO_MODE7) 641 + queue_work(dac33->dac33_wq, &dac33->work); 687 642 688 643 return IRQ_HANDLED; 689 644 } ··· 839 782 case DAC33_FIFO_MODE1: 840 783 dac33_write(codec, DAC33_FIFO_IRQ_MODE_B, 841 784 DAC33_ATM(DAC33_FIFO_IRQ_MODE_LEVEL)); 842 - dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MAT); 843 785 break; 844 786 case DAC33_FIFO_MODE7: 845 - /* Disable all interrupts */ 846 - dac33_write(codec, DAC33_FIFO_IRQ_MASK, 0); 787 + dac33_write(codec, DAC33_FIFO_IRQ_MODE_A, 788 + DAC33_UTM(DAC33_FIFO_IRQ_MODE_LEVEL)); 847 789 break; 848 790 default: 849 791 /* in FIFO bypass mode, the interrupts are not used */ ··· 920 864 * Configure the threshold levels, and leave 10 sample space 921 865 * at the bottom, and also at the top of the FIFO 922 866 */ 923 - dac33_write16(codec, DAC33_UTHR_MSB, 924 - DAC33_THRREG(DAC33_BUFFER_SIZE_SAMPLES - 10)); 925 - dac33_write16(codec, DAC33_LTHR_MSB, 926 - DAC33_THRREG(10)); 867 + dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(MODE7_UTHR)); 868 + dac33_write16(codec, DAC33_LTHR_MSB, DAC33_THRREG(MODE7_LTHR)); 927 869 break; 928 870 default: 929 871 break; ··· 939 885 struct snd_soc_codec *codec = socdev->card->codec; 940 886 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 941 887 unsigned int nsample_limit; 888 + 889 + /* In bypass mode we don't need to calculate */ 890 + if (!dac33->fifo_mode) 891 + return; 942 892 943 893 /* Number of samples (16bit, stereo) in one period */ 944 894 dac33->nsample_min = snd_pcm_lib_period_bytes(substream) / 4; ··· 977 919 978 920 if (dac33->nsample > dac33->nsample_max) 979 921 dac33->nsample = dac33->nsample_max; 922 + 923 + switch (dac33->fifo_mode) { 924 + case DAC33_FIFO_MODE1: 925 + dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate, 926 + dac33->nsample); 927 + dac33->t_stamp1 = 0; 928 + dac33->t_stamp2 = 0; 929 + break; 930 + case DAC33_FIFO_MODE7: 931 + dac33->mode7_us_to_lthr = 932 + SAMPLES_TO_US(substream->runtime->rate, 933 + MODE7_UTHR - MODE7_LTHR + 1); 934 + dac33->t_stamp1 = 0; 935 + break; 936 + default: 937 + break; 938 + } 939 + 980 940 } 981 941 982 942 static int dac33_pcm_prepare(struct snd_pcm_substream *substream, ··· 1037 961 } 1038 962 1039 963 return ret; 964 + } 965 + 966 + static snd_pcm_sframes_t dac33_dai_delay( 967 + struct snd_pcm_substream *substream, 968 + struct snd_soc_dai *dai) 969 + { 970 + struct snd_soc_pcm_runtime *rtd = substream->private_data; 971 + struct snd_soc_device *socdev = rtd->socdev; 972 + struct snd_soc_codec *codec = socdev->card->codec; 973 + struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec); 974 + unsigned long long t0, t1, t_now; 975 + unsigned int time_delta; 976 + int samples_out, samples_in, samples; 977 + snd_pcm_sframes_t delay = 0; 978 + 979 + switch (dac33->fifo_mode) { 980 + case DAC33_FIFO_BYPASS: 981 + break; 982 + case DAC33_FIFO_MODE1: 983 + spin_lock(&dac33->lock); 984 + t0 = dac33->t_stamp1; 985 + t1 = dac33->t_stamp2; 986 + spin_unlock(&dac33->lock); 987 + t_now = ktime_to_us(ktime_get()); 988 + 989 + /* We have not started to fill the FIFO yet, delay is 0 */ 990 + if (!t1) 991 + goto out; 992 + 993 + if (t0 > t1) { 994 + /* 995 + * Phase 1: 996 + * After Alarm threshold, and before nSample write 997 + */ 998 + time_delta = t_now - t0; 999 + samples_out = time_delta ? US_TO_SAMPLES( 1000 + substream->runtime->rate, 1001 + time_delta) : 0; 1002 + 1003 + if (likely(dac33->alarm_threshold > samples_out)) 1004 + delay = dac33->alarm_threshold - samples_out; 1005 + else 1006 + delay = 0; 1007 + } else if ((t_now - t1) <= dac33->mode1_us_burst) { 1008 + /* 1009 + * Phase 2: 1010 + * After nSample write (during burst operation) 1011 + */ 1012 + time_delta = t_now - t0; 1013 + samples_out = time_delta ? US_TO_SAMPLES( 1014 + substream->runtime->rate, 1015 + time_delta) : 0; 1016 + 1017 + time_delta = t_now - t1; 1018 + samples_in = time_delta ? US_TO_SAMPLES( 1019 + dac33->burst_rate, 1020 + time_delta) : 0; 1021 + 1022 + samples = dac33->alarm_threshold; 1023 + samples += (samples_in - samples_out); 1024 + 1025 + if (likely(samples > 0)) 1026 + delay = samples; 1027 + else 1028 + delay = 0; 1029 + } else { 1030 + /* 1031 + * Phase 3: 1032 + * After burst operation, before next alarm threshold 1033 + */ 1034 + time_delta = t_now - t0; 1035 + samples_out = time_delta ? US_TO_SAMPLES( 1036 + substream->runtime->rate, 1037 + time_delta) : 0; 1038 + 1039 + samples_in = dac33->nsample; 1040 + samples = dac33->alarm_threshold; 1041 + samples += (samples_in - samples_out); 1042 + 1043 + if (likely(samples > 0)) 1044 + delay = samples > DAC33_BUFFER_SIZE_SAMPLES ? 1045 + DAC33_BUFFER_SIZE_SAMPLES : samples; 1046 + else 1047 + delay = 0; 1048 + } 1049 + break; 1050 + case DAC33_FIFO_MODE7: 1051 + spin_lock(&dac33->lock); 1052 + t0 = dac33->t_stamp1; 1053 + spin_unlock(&dac33->lock); 1054 + t_now = ktime_to_us(ktime_get()); 1055 + 1056 + /* We have not started to fill the FIFO yet, delay is 0 */ 1057 + if (!t0) 1058 + goto out; 1059 + 1060 + if (t_now <= t0) { 1061 + /* 1062 + * Either the timestamps are messed or equal. Report 1063 + * maximum delay 1064 + */ 1065 + delay = MODE7_UTHR; 1066 + goto out; 1067 + } 1068 + 1069 + time_delta = t_now - t0; 1070 + if (time_delta <= dac33->mode7_us_to_lthr) { 1071 + /* 1072 + * Phase 1: 1073 + * After burst (draining phase) 1074 + */ 1075 + samples_out = US_TO_SAMPLES( 1076 + substream->runtime->rate, 1077 + time_delta); 1078 + 1079 + if (likely(MODE7_UTHR > samples_out)) 1080 + delay = MODE7_UTHR - samples_out; 1081 + else 1082 + delay = 0; 1083 + } else { 1084 + /* 1085 + * Phase 2: 1086 + * During burst operation 1087 + */ 1088 + time_delta = time_delta - dac33->mode7_us_to_lthr; 1089 + 1090 + samples_out = US_TO_SAMPLES( 1091 + substream->runtime->rate, 1092 + time_delta); 1093 + samples_in = US_TO_SAMPLES( 1094 + dac33->burst_rate, 1095 + time_delta); 1096 + delay = MODE7_LTHR + samples_in - samples_out; 1097 + 1098 + if (unlikely(delay > MODE7_UTHR)) 1099 + delay = MODE7_UTHR; 1100 + } 1101 + break; 1102 + default: 1103 + dev_warn(codec->dev, "Unhandled FIFO mode: %d\n", 1104 + dac33->fifo_mode); 1105 + break; 1106 + } 1107 + out: 1108 + return delay; 1040 1109 } 1041 1110 1042 1111 static int dac33_set_dai_sysclk(struct snd_soc_dai *codec_dai, ··· 1395 1174 .hw_params = dac33_hw_params, 1396 1175 .prepare = dac33_pcm_prepare, 1397 1176 .trigger = dac33_pcm_trigger, 1177 + .delay = dac33_dai_delay, 1398 1178 .set_sysclk = dac33_set_dai_sysclk, 1399 1179 .set_fmt = dac33_set_dai_fmt, 1400 1180 }; ··· 1436 1214 1437 1215 mutex_init(&codec->mutex); 1438 1216 mutex_init(&dac33->mutex); 1217 + spin_lock_init(&dac33->lock); 1439 1218 INIT_LIST_HEAD(&codec->dapm_widgets); 1440 1219 INIT_LIST_HEAD(&codec->dapm_paths); 1441 1220 ··· 1461 1238 1462 1239 dac33->power_gpio = pdata->power_gpio; 1463 1240 dac33->burst_bclkdiv = pdata->burst_bclkdiv; 1241 + /* Pre calculate the burst rate */ 1242 + dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32; 1464 1243 dac33->keep_bclk = pdata->keep_bclk; 1465 1244 dac33->irq = client->irq; 1466 1245 dac33->nsample = NSAMPLE_MAX; 1246 + dac33->nsample_max = NSAMPLE_MAX; 1467 1247 /* Disable FIFO use by default */ 1468 1248 dac33->fifo_mode = DAC33_FIFO_BYPASS; 1469 1249