aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-12-09 10:22:07 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-12-09 10:22:07 -0500
commit1bd202e4c7745459aca6616cd127b2d2bbd29901 (patch)
tree94ab16eaf7ee76c4d495780df8d72c8e765a61cd /sound/soc
parent57769541b4bb696bf69c3350ca09187e04ebe7d4 (diff)
parent1b3bc060fb008ddd75fe60c876c24784a517c10c (diff)
Merge remote-tracking branch 'asoc/topic/davinci' into asoc-next
Diffstat (limited to 'sound/soc')
-rw-r--r--sound/soc/davinci/davinci-evm.c5
-rw-r--r--sound/soc/davinci/davinci-mcasp.c152
-rw-r--r--sound/soc/davinci/davinci-mcasp.h15
-rw-r--r--sound/soc/davinci/davinci-pcm.c53
-rw-r--r--sound/soc/davinci/davinci-pcm.h2
5 files changed, 141 insertions, 86 deletions
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index 6fac5af13298..d55e6477bff0 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -71,6 +71,11 @@ static int evm_hw_params(struct snd_pcm_substream *substream,
71 if (ret < 0) 71 if (ret < 0)
72 return ret; 72 return ret;
73 73
74 /* set the CPU system clock */
75 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, sysclk, SND_SOC_CLOCK_OUT);
76 if (ret < 0)
77 return ret;
78
74 return 0; 79 return 0;
75} 80}
76 81
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 714e51e5be5b..55e2bf652bef 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -199,6 +199,7 @@
199#define ACLKXE BIT(5) 199#define ACLKXE BIT(5)
200#define TX_ASYNC BIT(6) 200#define TX_ASYNC BIT(6)
201#define ACLKXPOL BIT(7) 201#define ACLKXPOL BIT(7)
202#define ACLKXDIV_MASK 0x1f
202 203
203/* 204/*
204 * DAVINCI_MCASP_ACLKRCTL_REG Receive Clock Control Register Bits 205 * DAVINCI_MCASP_ACLKRCTL_REG Receive Clock Control Register Bits
@@ -207,6 +208,7 @@
207#define ACLKRE BIT(5) 208#define ACLKRE BIT(5)
208#define RX_ASYNC BIT(6) 209#define RX_ASYNC BIT(6)
209#define ACLKRPOL BIT(7) 210#define ACLKRPOL BIT(7)
211#define ACLKRDIV_MASK 0x1f
210 212
211/* 213/*
212 * DAVINCI_MCASP_AHCLKXCTL_REG - High Frequency Transmit Clock Control 214 * DAVINCI_MCASP_AHCLKXCTL_REG - High Frequency Transmit Clock Control
@@ -215,6 +217,7 @@
215#define AHCLKXDIV(val) (val) 217#define AHCLKXDIV(val) (val)
216#define AHCLKXPOL BIT(14) 218#define AHCLKXPOL BIT(14)
217#define AHCLKXE BIT(15) 219#define AHCLKXE BIT(15)
220#define AHCLKXDIV_MASK 0xfff
218 221
219/* 222/*
220 * DAVINCI_MCASP_AHCLKRCTL_REG - High Frequency Receive Clock Control 223 * DAVINCI_MCASP_AHCLKRCTL_REG - High Frequency Receive Clock Control
@@ -223,6 +226,7 @@
223#define AHCLKRDIV(val) (val) 226#define AHCLKRDIV(val) (val)
224#define AHCLKRPOL BIT(14) 227#define AHCLKRPOL BIT(14)
225#define AHCLKRE BIT(15) 228#define AHCLKRE BIT(15)
229#define AHCLKRDIV_MASK 0xfff
226 230
227/* 231/*
228 * DAVINCI_MCASP_XRSRCTL_BASE_REG - Serializer Control Register Bits 232 * DAVINCI_MCASP_XRSRCTL_BASE_REG - Serializer Control Register Bits
@@ -473,6 +477,23 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
473 struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(cpu_dai); 477 struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(cpu_dai);
474 void __iomem *base = dev->base; 478 void __iomem *base = dev->base;
475 479
480 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
481 case SND_SOC_DAIFMT_DSP_B:
482 case SND_SOC_DAIFMT_AC97:
483 mcasp_clr_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
484 mcasp_clr_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
485 break;
486 default:
487 /* configure a full-word SYNC pulse (LRCLK) */
488 mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
489 mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
490
491 /* make 1st data bit occur one ACLK cycle after the frame sync */
492 mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, FSXDLY(1));
493 mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, FSRDLY(1));
494 break;
495 }
496
476 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 497 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
477 case SND_SOC_DAIFMT_CBS_CFS: 498 case SND_SOC_DAIFMT_CBS_CFS:
478 /* codec is clock and frame slave */ 499 /* codec is clock and frame slave */
@@ -482,8 +503,7 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
482 mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); 503 mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
483 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); 504 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
484 505
485 mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, 506 mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, ACLKX | AFSX);
486 ACLKX | AHCLKX | AFSX);
487 break; 507 break;
488 case SND_SOC_DAIFMT_CBM_CFS: 508 case SND_SOC_DAIFMT_CBM_CFS:
489 /* codec is clock master and frame slave */ 509 /* codec is clock master and frame slave */
@@ -554,59 +574,75 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
554 return 0; 574 return 0;
555} 575}
556 576
557static int davinci_config_channel_size(struct davinci_audio_dev *dev, 577static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div)
558 int channel_size)
559{ 578{
560 u32 fmt = 0; 579 struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(dai);
561 u32 mask, rotate;
562
563 switch (channel_size) {
564 case DAVINCI_AUDIO_WORD_8:
565 fmt = 0x03;
566 rotate = 6;
567 mask = 0x000000ff;
568 break;
569 580
570 case DAVINCI_AUDIO_WORD_12: 581 switch (div_id) {
571 fmt = 0x05; 582 case 0: /* MCLK divider */
572 rotate = 5; 583 mcasp_mod_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG,
573 mask = 0x00000fff; 584 AHCLKXDIV(div - 1), AHCLKXDIV_MASK);
585 mcasp_mod_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG,
586 AHCLKRDIV(div - 1), AHCLKRDIV_MASK);
574 break; 587 break;
575 588
576 case DAVINCI_AUDIO_WORD_16: 589 case 1: /* BCLK divider */
577 fmt = 0x07; 590 mcasp_mod_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG,
578 rotate = 4; 591 ACLKXDIV(div - 1), ACLKXDIV_MASK);
579 mask = 0x0000ffff; 592 mcasp_mod_bits(dev->base + DAVINCI_MCASP_ACLKRCTL_REG,
593 ACLKRDIV(div - 1), ACLKRDIV_MASK);
580 break; 594 break;
581 595
582 case DAVINCI_AUDIO_WORD_20: 596 case 2: /* BCLK/LRCLK ratio */
583 fmt = 0x09; 597 dev->bclk_lrclk_ratio = div;
584 rotate = 3;
585 mask = 0x000fffff;
586 break; 598 break;
587 599
588 case DAVINCI_AUDIO_WORD_24: 600 default:
589 fmt = 0x0B; 601 return -EINVAL;
590 rotate = 2; 602 }
591 mask = 0x00ffffff;
592 break;
593 603
594 case DAVINCI_AUDIO_WORD_28: 604 return 0;
595 fmt = 0x0D; 605}
596 rotate = 1;
597 mask = 0x0fffffff;
598 break;
599 606
600 case DAVINCI_AUDIO_WORD_32: 607static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id,
601 fmt = 0x0F; 608 unsigned int freq, int dir)
602 rotate = 0; 609{
603 mask = 0xffffffff; 610 struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(dai);
604 break;
605 611
606 default: 612 if (dir == SND_SOC_CLOCK_OUT) {
607 return -EINVAL; 613 mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
614 mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
615 mcasp_set_bits(dev->base + DAVINCI_MCASP_PDIR_REG, AHCLKX);
616 } else {
617 mcasp_clr_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
618 mcasp_clr_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
619 mcasp_clr_bits(dev->base + DAVINCI_MCASP_PDIR_REG, AHCLKX);
608 } 620 }
609 621
622 return 0;
623}
624
625static int davinci_config_channel_size(struct davinci_audio_dev *dev,
626 int word_length)
627{
628 u32 fmt;
629 u32 rotate = (32 - word_length) / 4;
630 u32 mask = (1ULL << word_length) - 1;
631
632 /*
633 * if s BCLK-to-LRCLK ratio has been configured via the set_clkdiv()
634 * callback, take it into account here. That allows us to for example
635 * send 32 bits per channel to the codec, while only 16 of them carry
636 * audio payload.
637 * The clock ratio is given for a full period of data (both left and
638 * right channels), so it has to be divided by 2.
639 */
640 if (dev->bclk_lrclk_ratio)
641 word_length = dev->bclk_lrclk_ratio / 2;
642
643 /* mapping of the XSSZ bit-field as described in the datasheet */
644 fmt = (word_length >> 1) - 1;
645
610 mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, 646 mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMT_REG,
611 RXSSZ(fmt), RXSSZ(0x0F)); 647 RXSSZ(fmt), RXSSZ(0x0F));
612 mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, 648 mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMT_REG,
@@ -709,8 +745,6 @@ static void davinci_hw_param(struct davinci_audio_dev *dev, int stream)
709 if (stream == SNDRV_PCM_STREAM_PLAYBACK) { 745 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
710 /* bit stream is MSB first with no delay */ 746 /* bit stream is MSB first with no delay */
711 /* DSP_B mode */ 747 /* DSP_B mode */
712 mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG,
713 AHCLKXE);
714 mcasp_set_reg(dev->base + DAVINCI_MCASP_TXTDM_REG, mask); 748 mcasp_set_reg(dev->base + DAVINCI_MCASP_TXTDM_REG, mask);
715 mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, TXORD); 749 mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, TXORD);
716 750
@@ -720,14 +754,10 @@ static void davinci_hw_param(struct davinci_audio_dev *dev, int stream)
720 else 754 else
721 printk(KERN_ERR "playback tdm slot %d not supported\n", 755 printk(KERN_ERR "playback tdm slot %d not supported\n",
722 dev->tdm_slots); 756 dev->tdm_slots);
723
724 mcasp_clr_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
725 } else { 757 } else {
726 /* bit stream is MSB first with no delay */ 758 /* bit stream is MSB first with no delay */
727 /* DSP_B mode */ 759 /* DSP_B mode */
728 mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, RXORD); 760 mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, RXORD);
729 mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG,
730 AHCLKRE);
731 mcasp_set_reg(dev->base + DAVINCI_MCASP_RXTDM_REG, mask); 761 mcasp_set_reg(dev->base + DAVINCI_MCASP_RXTDM_REG, mask);
732 762
733 if ((dev->tdm_slots >= 2) && (dev->tdm_slots <= 32)) 763 if ((dev->tdm_slots >= 2) && (dev->tdm_slots <= 32))
@@ -736,8 +766,6 @@ static void davinci_hw_param(struct davinci_audio_dev *dev, int stream)
736 else 766 else
737 printk(KERN_ERR "capture tdm slot %d not supported\n", 767 printk(KERN_ERR "capture tdm slot %d not supported\n",
738 dev->tdm_slots); 768 dev->tdm_slots);
739
740 mcasp_clr_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
741 } 769 }
742} 770}
743 771
@@ -800,19 +828,27 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
800 case SNDRV_PCM_FORMAT_U8: 828 case SNDRV_PCM_FORMAT_U8:
801 case SNDRV_PCM_FORMAT_S8: 829 case SNDRV_PCM_FORMAT_S8:
802 dma_params->data_type = 1; 830 dma_params->data_type = 1;
803 word_length = DAVINCI_AUDIO_WORD_8; 831 word_length = 8;
804 break; 832 break;
805 833
806 case SNDRV_PCM_FORMAT_U16_LE: 834 case SNDRV_PCM_FORMAT_U16_LE:
807 case SNDRV_PCM_FORMAT_S16_LE: 835 case SNDRV_PCM_FORMAT_S16_LE:
808 dma_params->data_type = 2; 836 dma_params->data_type = 2;
809 word_length = DAVINCI_AUDIO_WORD_16; 837 word_length = 16;
838 break;
839
840 case SNDRV_PCM_FORMAT_U24_3LE:
841 case SNDRV_PCM_FORMAT_S24_3LE:
842 dma_params->data_type = 3;
843 word_length = 24;
810 break; 844 break;
811 845
846 case SNDRV_PCM_FORMAT_U24_LE:
847 case SNDRV_PCM_FORMAT_S24_LE:
812 case SNDRV_PCM_FORMAT_U32_LE: 848 case SNDRV_PCM_FORMAT_U32_LE:
813 case SNDRV_PCM_FORMAT_S32_LE: 849 case SNDRV_PCM_FORMAT_S32_LE:
814 dma_params->data_type = 4; 850 dma_params->data_type = 4;
815 word_length = DAVINCI_AUDIO_WORD_32; 851 word_length = 32;
816 break; 852 break;
817 853
818 default: 854 default:
@@ -880,13 +916,18 @@ static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
880 .trigger = davinci_mcasp_trigger, 916 .trigger = davinci_mcasp_trigger,
881 .hw_params = davinci_mcasp_hw_params, 917 .hw_params = davinci_mcasp_hw_params,
882 .set_fmt = davinci_mcasp_set_dai_fmt, 918 .set_fmt = davinci_mcasp_set_dai_fmt,
883 919 .set_clkdiv = davinci_mcasp_set_clkdiv,
920 .set_sysclk = davinci_mcasp_set_sysclk,
884}; 921};
885 922
886#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \ 923#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \
887 SNDRV_PCM_FMTBIT_U8 | \ 924 SNDRV_PCM_FMTBIT_U8 | \
888 SNDRV_PCM_FMTBIT_S16_LE | \ 925 SNDRV_PCM_FMTBIT_S16_LE | \
889 SNDRV_PCM_FMTBIT_U16_LE | \ 926 SNDRV_PCM_FMTBIT_U16_LE | \
927 SNDRV_PCM_FMTBIT_S24_LE | \
928 SNDRV_PCM_FMTBIT_U24_LE | \
929 SNDRV_PCM_FMTBIT_S24_3LE | \
930 SNDRV_PCM_FMTBIT_U24_3LE | \
890 SNDRV_PCM_FMTBIT_S32_LE | \ 931 SNDRV_PCM_FMTBIT_S32_LE | \
891 SNDRV_PCM_FMTBIT_U32_LE) 932 SNDRV_PCM_FMTBIT_U32_LE)
892 933
@@ -1089,7 +1130,6 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1089 dev->tdm_slots = pdata->tdm_slots; 1130 dev->tdm_slots = pdata->tdm_slots;
1090 dev->num_serializer = pdata->num_serializer; 1131 dev->num_serializer = pdata->num_serializer;
1091 dev->serial_dir = pdata->serial_dir; 1132 dev->serial_dir = pdata->serial_dir;
1092 dev->codec_fmt = pdata->codec_fmt;
1093 dev->version = pdata->version; 1133 dev->version = pdata->version;
1094 dev->txnumevt = pdata->txnumevt; 1134 dev->txnumevt = pdata->txnumevt;
1095 dev->rxnumevt = pdata->rxnumevt; 1135 dev->rxnumevt = pdata->rxnumevt;
@@ -1098,6 +1138,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1098 dma_data = &dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]; 1138 dma_data = &dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
1099 dma_data->asp_chan_q = pdata->asp_chan_q; 1139 dma_data->asp_chan_q = pdata->asp_chan_q;
1100 dma_data->ram_chan_q = pdata->ram_chan_q; 1140 dma_data->ram_chan_q = pdata->ram_chan_q;
1141 dma_data->sram_pool = pdata->sram_pool;
1101 dma_data->sram_size = pdata->sram_size_playback; 1142 dma_data->sram_size = pdata->sram_size_playback;
1102 dma_data->dma_addr = (dma_addr_t) (pdata->tx_dma_offset + 1143 dma_data->dma_addr = (dma_addr_t) (pdata->tx_dma_offset +
1103 mem->start); 1144 mem->start);
@@ -1115,6 +1156,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1115 dma_data = &dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]; 1156 dma_data = &dev->dma_params[SNDRV_PCM_STREAM_CAPTURE];
1116 dma_data->asp_chan_q = pdata->asp_chan_q; 1157 dma_data->asp_chan_q = pdata->asp_chan_q;
1117 dma_data->ram_chan_q = pdata->ram_chan_q; 1158 dma_data->ram_chan_q = pdata->ram_chan_q;
1159 dma_data->sram_pool = pdata->sram_pool;
1118 dma_data->sram_size = pdata->sram_size_capture; 1160 dma_data->sram_size = pdata->sram_size_capture;
1119 dma_data->dma_addr = (dma_addr_t)(pdata->rx_dma_offset + 1161 dma_data->dma_addr = (dma_addr_t)(pdata->rx_dma_offset +
1120 mem->start); 1162 mem->start);
diff --git a/sound/soc/davinci/davinci-mcasp.h b/sound/soc/davinci/davinci-mcasp.h
index 0de9ed6ce038..0edd3b5a37fd 100644
--- a/sound/soc/davinci/davinci-mcasp.h
+++ b/sound/soc/davinci/davinci-mcasp.h
@@ -23,26 +23,14 @@
23 23
24#include "davinci-pcm.h" 24#include "davinci-pcm.h"
25 25
26#define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_96000 26#define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_192000
27#define DAVINCI_MCASP_I2S_DAI 0 27#define DAVINCI_MCASP_I2S_DAI 0
28#define DAVINCI_MCASP_DIT_DAI 1 28#define DAVINCI_MCASP_DIT_DAI 1
29 29
30enum {
31 DAVINCI_AUDIO_WORD_8 = 0,
32 DAVINCI_AUDIO_WORD_12,
33 DAVINCI_AUDIO_WORD_16,
34 DAVINCI_AUDIO_WORD_20,
35 DAVINCI_AUDIO_WORD_24,
36 DAVINCI_AUDIO_WORD_32,
37 DAVINCI_AUDIO_WORD_28, /* This is only valid for McASP */
38};
39
40struct davinci_audio_dev { 30struct davinci_audio_dev {
41 struct davinci_pcm_dma_params dma_params[2]; 31 struct davinci_pcm_dma_params dma_params[2];
42 void __iomem *base; 32 void __iomem *base;
43 int sample_rate;
44 struct device *dev; 33 struct device *dev;
45 unsigned int codec_fmt;
46 34
47 /* McASP specific data */ 35 /* McASP specific data */
48 int tdm_slots; 36 int tdm_slots;
@@ -50,6 +38,7 @@ struct davinci_audio_dev {
50 u8 num_serializer; 38 u8 num_serializer;
51 u8 *serial_dir; 39 u8 *serial_dir;
52 u8 version; 40 u8 version;
41 u8 bclk_lrclk_ratio;
53 42
54 /* McASP FIFO related */ 43 /* McASP FIFO related */
55 u8 txnumevt; 44 u8 txnumevt;
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
index 93ea3bf567e1..afab81f844ae 100644
--- a/sound/soc/davinci/davinci-pcm.c
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -16,6 +16,7 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/genalloc.h>
19 20
20#include <sound/core.h> 21#include <sound/core.h>
21#include <sound/pcm.h> 22#include <sound/pcm.h>
@@ -23,7 +24,6 @@
23#include <sound/soc.h> 24#include <sound/soc.h>
24 25
25#include <asm/dma.h> 26#include <asm/dma.h>
26#include <mach/sram.h>
27 27
28#include "davinci-pcm.h" 28#include "davinci-pcm.h"
29 29
@@ -67,13 +67,9 @@ static struct snd_pcm_hardware pcm_hardware_playback = {
67 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME| 67 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME|
68 SNDRV_PCM_INFO_BATCH), 68 SNDRV_PCM_INFO_BATCH),
69 .formats = DAVINCI_PCM_FMTBITS, 69 .formats = DAVINCI_PCM_FMTBITS,
70 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | 70 .rates = SNDRV_PCM_RATE_8000_192000 | SNDRV_PCM_RATE_KNOT,
71 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
72 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
73 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
74 SNDRV_PCM_RATE_KNOT),
75 .rate_min = 8000, 71 .rate_min = 8000,
76 .rate_max = 96000, 72 .rate_max = 192000,
77 .channels_min = 2, 73 .channels_min = 2,
78 .channels_max = 384, 74 .channels_max = 384,
79 .buffer_bytes_max = 128 * 1024, 75 .buffer_bytes_max = 128 * 1024,
@@ -90,13 +86,9 @@ static struct snd_pcm_hardware pcm_hardware_capture = {
90 SNDRV_PCM_INFO_PAUSE | 86 SNDRV_PCM_INFO_PAUSE |
91 SNDRV_PCM_INFO_BATCH), 87 SNDRV_PCM_INFO_BATCH),
92 .formats = DAVINCI_PCM_FMTBITS, 88 .formats = DAVINCI_PCM_FMTBITS,
93 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | 89 .rates = SNDRV_PCM_RATE_8000_192000 | SNDRV_PCM_RATE_KNOT,
94 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
95 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
96 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
97 SNDRV_PCM_RATE_KNOT),
98 .rate_min = 8000, 90 .rate_min = 8000,
99 .rate_max = 96000, 91 .rate_max = 192000,
100 .channels_min = 2, 92 .channels_min = 2,
101 .channels_max = 384, 93 .channels_max = 384,
102 .buffer_bytes_max = 128 * 1024, 94 .buffer_bytes_max = 128 * 1024,
@@ -259,7 +251,9 @@ static void davinci_pcm_dma_irq(unsigned link, u16 ch_status, void *data)
259 } 251 }
260} 252}
261 253
262static int allocate_sram(struct snd_pcm_substream *substream, unsigned size, 254#ifdef CONFIG_GENERIC_ALLOCATOR
255static int allocate_sram(struct snd_pcm_substream *substream,
256 struct gen_pool *sram_pool, unsigned size,
263 struct snd_pcm_hardware *ppcm) 257 struct snd_pcm_hardware *ppcm)
264{ 258{
265 struct snd_dma_buffer *buf = &substream->dma_buffer; 259 struct snd_dma_buffer *buf = &substream->dma_buffer;
@@ -271,9 +265,10 @@ static int allocate_sram(struct snd_pcm_substream *substream, unsigned size,
271 return 0; 265 return 0;
272 266
273 ppcm->period_bytes_max = size; 267 ppcm->period_bytes_max = size;
274 iram_virt = sram_alloc(size, &iram_phys); 268 iram_virt = (void *)gen_pool_alloc(sram_pool, size);
275 if (!iram_virt) 269 if (!iram_virt)
276 goto exit1; 270 goto exit1;
271 iram_phys = gen_pool_virt_to_phys(sram_pool, (unsigned)iram_virt);
277 iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL); 272 iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL);
278 if (!iram_dma) 273 if (!iram_dma)
279 goto exit2; 274 goto exit2;
@@ -285,11 +280,33 @@ static int allocate_sram(struct snd_pcm_substream *substream, unsigned size,
285 return 0; 280 return 0;
286exit2: 281exit2:
287 if (iram_virt) 282 if (iram_virt)
288 sram_free(iram_virt, size); 283 gen_pool_free(sram_pool, (unsigned)iram_virt, size);
289exit1: 284exit1:
290 return -ENOMEM; 285 return -ENOMEM;
291} 286}
292 287
288static void davinci_free_sram(struct snd_pcm_substream *substream,
289 struct snd_dma_buffer *iram_dma)
290{
291 struct davinci_runtime_data *prtd = substream->runtime->private_data;
292 struct gen_pool *sram_pool = prtd->params->sram_pool;
293
294 gen_pool_free(sram_pool, (unsigned) iram_dma->area, iram_dma->bytes);
295}
296#else
297static int allocate_sram(struct snd_pcm_substream *substream,
298 struct gen_pool *sram_pool, unsigned size,
299 struct snd_pcm_hardware *ppcm)
300{
301 return 0;
302}
303
304static void davinci_free_sram(struct snd_pcm_substream *substream,
305 struct snd_dma_buffer *iram_dma)
306{
307}
308#endif
309
293/* 310/*
294 * Only used with ping/pong. 311 * Only used with ping/pong.
295 * This is called after runtime->dma_addr, period_bytes and data_type are valid 312 * This is called after runtime->dma_addr, period_bytes and data_type are valid
@@ -676,7 +693,7 @@ static int davinci_pcm_open(struct snd_pcm_substream *substream)
676 693
677 ppcm = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? 694 ppcm = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
678 &pcm_hardware_playback : &pcm_hardware_capture; 695 &pcm_hardware_playback : &pcm_hardware_capture;
679 allocate_sram(substream, params->sram_size, ppcm); 696 allocate_sram(substream, params->sram_pool, params->sram_size, ppcm);
680 snd_soc_set_runtime_hwparams(substream, ppcm); 697 snd_soc_set_runtime_hwparams(substream, ppcm);
681 /* ensure that buffer size is a multiple of period size */ 698 /* ensure that buffer size is a multiple of period size */
682 ret = snd_pcm_hw_constraint_integer(runtime, 699 ret = snd_pcm_hw_constraint_integer(runtime,
@@ -819,7 +836,7 @@ static void davinci_pcm_free(struct snd_pcm *pcm)
819 buf->area = NULL; 836 buf->area = NULL;
820 iram_dma = buf->private_data; 837 iram_dma = buf->private_data;
821 if (iram_dma) { 838 if (iram_dma) {
822 sram_free(iram_dma->area, iram_dma->bytes); 839 davinci_free_sram(substream, iram_dma);
823 kfree(iram_dma); 840 kfree(iram_dma);
824 } 841 }
825 } 842 }
diff --git a/sound/soc/davinci/davinci-pcm.h b/sound/soc/davinci/davinci-pcm.h
index fc4d01cdd8c9..b6ef7039dd09 100644
--- a/sound/soc/davinci/davinci-pcm.h
+++ b/sound/soc/davinci/davinci-pcm.h
@@ -12,6 +12,7 @@
12#ifndef _DAVINCI_PCM_H 12#ifndef _DAVINCI_PCM_H
13#define _DAVINCI_PCM_H 13#define _DAVINCI_PCM_H
14 14
15#include <linux/genalloc.h>
15#include <linux/platform_data/davinci_asp.h> 16#include <linux/platform_data/davinci_asp.h>
16#include <mach/edma.h> 17#include <mach/edma.h>
17 18
@@ -20,6 +21,7 @@ struct davinci_pcm_dma_params {
20 unsigned short acnt; 21 unsigned short acnt;
21 dma_addr_t dma_addr; /* device physical address for DMA */ 22 dma_addr_t dma_addr; /* device physical address for DMA */
22 unsigned sram_size; 23 unsigned sram_size;
24 struct gen_pool *sram_pool; /* SRAM gen_pool for ping pong */
23 enum dma_event_q asp_chan_q; /* event queue number for ASP channel */ 25 enum dma_event_q asp_chan_q; /* event queue number for ASP channel */
24 enum dma_event_q ram_chan_q; /* event queue number for RAM channel */ 26 enum dma_event_q ram_chan_q; /* event queue number for RAM channel */
25 unsigned char data_type; /* xfer data type */ 27 unsigned char data_type; /* xfer data type */