Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6: ALSA: ASoC: fix SNDCTL_DSP_SYNC support in Freescale 8610 sound drivers
···327327 * fsl_dma_open: open a new substream.328328 *329329 * Each substream has its own DMA buffer.330330+ *331331+ * ALSA divides the DMA buffer into N periods. We create NUM_DMA_LINKS link332332+ * descriptors that ping-pong from one period to the next. For example, if333333+ * there are six periods and two link descriptors, this is how they look334334+ * before playback starts:335335+ *336336+ * The last link descriptor337337+ * ____________ points back to the first338338+ * | |339339+ * V |340340+ * ___ ___ |341341+ * | |->| |->|342342+ * |___| |___|343343+ * | |344344+ * | |345345+ * V V346346+ * _________________________________________347347+ * | | | | | | | The DMA buffer is348348+ * | | | | | | | divided into 6 parts349349+ * |______|______|______|______|______|______|350350+ *351351+ * and here's how they look after the first period is finished playing:352352+ *353353+ * ____________354354+ * | |355355+ * V |356356+ * ___ ___ |357357+ * | |->| |->|358358+ * |___| |___|359359+ * | |360360+ * |______________361361+ * | |362362+ * V V363363+ * _________________________________________364364+ * | | | | | | |365365+ * | | | | | | |366366+ * |______|______|______|______|______|______|367367+ *368368+ * The first link descriptor now points to the third period. The DMA369369+ * controller is currently playing the second period. When it finishes, it370370+ * will jump back to the first descriptor and play the third period.371371+ *372372+ * There are four reasons we do this:373373+ *374374+ * 1. The only way to get the DMA controller to automatically restart the375375+ * transfer when it gets to the end of the buffer is to use chaining376376+ * mode. Basic direct mode doesn't offer that feature.377377+ * 2. We need to receive an interrupt at the end of every period. The DMA378378+ * controller can generate an interrupt at the end of every link transfer379379+ * (aka segment). Making each period into a DMA segment will give us the380380+ * interrupts we need.381381+ * 3. By creating only two link descriptors, regardless of the number of382382+ * periods, we do not need to reallocate the link descriptors if the383383+ * number of periods changes.384384+ * 4. All of the audio data is still stored in a single, contiguous DMA385385+ * buffer, which is what ALSA expects. We're just dividing it into386386+ * contiguous parts, and creating a link descriptor for each one.330387 */331388static int fsl_dma_open(struct snd_pcm_substream *substream)332389{333390 struct snd_pcm_runtime *runtime = substream->runtime;334391 struct fsl_dma_private *dma_private;392392+ struct ccsr_dma_channel __iomem *dma_channel;335393 dma_addr_t ld_buf_phys;394394+ u64 temp_link; /* Pointer to next link descriptor */395395+ u32 mr;336396 unsigned int channel;337397 int ret = 0;398398+ unsigned int i;338399339400 /*340401 * Reject any DMA buffer whose size is not a multiple of the period···456395 snd_soc_set_runtime_hwparams(substream, &fsl_dma_hardware);457396 runtime->private_data = dma_private;458397459459- return 0;460460-}398398+ /* Program the fixed DMA controller parameters */461399462462-/**463463- * fsl_dma_hw_params: allocate the DMA buffer and the DMA link descriptors.464464- *465465- * ALSA divides the DMA buffer into N periods. We create NUM_DMA_LINKS link466466- * descriptors that ping-pong from one period to the next. For example, if467467- * there are six periods and two link descriptors, this is how they look468468- * before playback starts:469469- *470470- * The last link descriptor471471- * ____________ points back to the first472472- * | |473473- * V |474474- * ___ ___ |475475- * | |->| |->|476476- * |___| |___|477477- * | |478478- * | |479479- * V V480480- * _________________________________________481481- * | | | | | | | The DMA buffer is482482- * | | | | | | | divided into 6 parts483483- * |______|______|______|______|______|______|484484- *485485- * and here's how they look after the first period is finished playing:486486- *487487- * ____________488488- * | |489489- * V |490490- * ___ ___ |491491- * | |->| |->|492492- * |___| |___|493493- * | |494494- * |______________495495- * | |496496- * V V497497- * _________________________________________498498- * | | | | | | |499499- * | | | | | | |500500- * |______|______|______|______|______|______|501501- *502502- * The first link descriptor now points to the third period. The DMA503503- * controller is currently playing the second period. When it finishes, it504504- * will jump back to the first descriptor and play the third period.505505- *506506- * There are four reasons we do this:507507- *508508- * 1. The only way to get the DMA controller to automatically restart the509509- * transfer when it gets to the end of the buffer is to use chaining510510- * mode. Basic direct mode doesn't offer that feature.511511- * 2. We need to receive an interrupt at the end of every period. The DMA512512- * controller can generate an interrupt at the end of every link transfer513513- * (aka segment). Making each period into a DMA segment will give us the514514- * interrupts we need.515515- * 3. By creating only two link descriptors, regardless of the number of516516- * periods, we do not need to reallocate the link descriptors if the517517- * number of periods changes.518518- * 4. All of the audio data is still stored in a single, contiguous DMA519519- * buffer, which is what ALSA expects. We're just dividing it into520520- * contiguous parts, and creating a link descriptor for each one.521521- *522522- * Note that due to a quirk of the SSI's STX register, the target address523523- * for the DMA operations depends on the sample size. So we don't program524524- * the dest_addr (for playback -- source_addr for capture) fields in the525525- * link descriptors here. We do that in fsl_dma_prepare()526526- */527527-static int fsl_dma_hw_params(struct snd_pcm_substream *substream,528528- struct snd_pcm_hw_params *hw_params)529529-{530530- struct snd_pcm_runtime *runtime = substream->runtime;531531- struct fsl_dma_private *dma_private = runtime->private_data;532532- struct ccsr_dma_channel __iomem *dma_channel = dma_private->dma_channel;400400+ dma_channel = dma_private->dma_channel;533401534534- dma_addr_t temp_addr; /* Pointer to next period */535535- u64 temp_link; /* Pointer to next link descriptor */536536- u32 mr; /* Temporary variable for MR register */537537-538538- unsigned int i;539539-540540- /* Get all the parameters we need */541541- size_t buffer_size = params_buffer_bytes(hw_params);542542- size_t period_size = params_period_bytes(hw_params);543543-544544- /* Initialize our DMA tracking variables */545545- dma_private->period_size = period_size;546546- dma_private->num_periods = params_periods(hw_params);547547- dma_private->dma_buf_end = dma_private->dma_buf_phys + buffer_size;548548- dma_private->dma_buf_next = dma_private->dma_buf_phys +549549- (NUM_DMA_LINKS * period_size);550550- if (dma_private->dma_buf_next >= dma_private->dma_buf_end)551551- dma_private->dma_buf_next = dma_private->dma_buf_phys;552552-553553- /*554554- * Initialize each link descriptor.555555- *556556- * The actual address in STX0 (destination for playback, source for557557- * capture) is based on the sample size, but we don't know the sample558558- * size in this function, so we'll have to adjust that later. See559559- * comments in fsl_dma_prepare().560560- *561561- * The DMA controller does not have a cache, so the CPU does not562562- * need to tell it to flush its cache. However, the DMA563563- * controller does need to tell the CPU to flush its cache.564564- * That's what the SNOOP bit does.565565- *566566- * Also, even though the DMA controller supports 36-bit addressing, for567567- * simplicity we currently support only 32-bit addresses for the audio568568- * buffer itself.569569- */570570- temp_addr = substream->dma_buffer.addr;571402 temp_link = dma_private->ld_buf_phys +572403 sizeof(struct fsl_dma_link_descriptor);573404574405 for (i = 0; i < NUM_DMA_LINKS; i++) {575406 struct fsl_dma_link_descriptor *link = &dma_private->link[i];576407577577- link->count = cpu_to_be32(period_size);578408 link->source_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP);579409 link->dest_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP);580410 link->next = cpu_to_be64(temp_link);581411582582- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)583583- link->source_addr = cpu_to_be32(temp_addr);584584- else585585- link->dest_addr = cpu_to_be32(temp_addr);586586-587587- temp_addr += period_size;588412 temp_link += sizeof(struct fsl_dma_link_descriptor);589413 }590414 /* The last link descriptor points to the first */···495549 * We want External Master Start and External Master Pause enabled,496550 * because the SSI is controlling the DMA controller. We want the DMA497551 * controller to be set up in advance, and then we signal only the SSI498498- * to start transfering.552552+ * to start transferring.499553 *500554 * We want End-Of-Segment Interrupts enabled, because this will generate501555 * an interrupt at the end of each segment (each link descriptor···515569 CCSR_DMA_MR_DAHE : CCSR_DMA_MR_SAHE;516570517571 out_be32(&dma_channel->mr, mr);572572+573573+ return 0;574574+}575575+576576+/**577577+ * fsl_dma_hw_params: continue initializing the DMA links578578+ *579579+ * This function obtains hardware parameters about the opened stream and580580+ * programs the DMA controller accordingly.581581+ *582582+ * Note that due to a quirk of the SSI's STX register, the target address583583+ * for the DMA operations depends on the sample size. So we don't program584584+ * the dest_addr (for playback -- source_addr for capture) fields in the585585+ * link descriptors here. We do that in fsl_dma_prepare()586586+ */587587+static int fsl_dma_hw_params(struct snd_pcm_substream *substream,588588+ struct snd_pcm_hw_params *hw_params)589589+{590590+ struct snd_pcm_runtime *runtime = substream->runtime;591591+ struct fsl_dma_private *dma_private = runtime->private_data;592592+593593+ dma_addr_t temp_addr; /* Pointer to next period */594594+595595+ unsigned int i;596596+597597+ /* Get all the parameters we need */598598+ size_t buffer_size = params_buffer_bytes(hw_params);599599+ size_t period_size = params_period_bytes(hw_params);600600+601601+ /* Initialize our DMA tracking variables */602602+ dma_private->period_size = period_size;603603+ dma_private->num_periods = params_periods(hw_params);604604+ dma_private->dma_buf_end = dma_private->dma_buf_phys + buffer_size;605605+ dma_private->dma_buf_next = dma_private->dma_buf_phys +606606+ (NUM_DMA_LINKS * period_size);607607+ if (dma_private->dma_buf_next >= dma_private->dma_buf_end)608608+ dma_private->dma_buf_next = dma_private->dma_buf_phys;609609+610610+ /*611611+ * The actual address in STX0 (destination for playback, source for612612+ * capture) is based on the sample size, but we don't know the sample613613+ * size in this function, so we'll have to adjust that later. See614614+ * comments in fsl_dma_prepare().615615+ *616616+ * The DMA controller does not have a cache, so the CPU does not617617+ * need to tell it to flush its cache. However, the DMA618618+ * controller does need to tell the CPU to flush its cache.619619+ * That's what the SNOOP bit does.620620+ *621621+ * Also, even though the DMA controller supports 36-bit addressing, for622622+ * simplicity we currently support only 32-bit addresses for the audio623623+ * buffer itself.624624+ */625625+ temp_addr = substream->dma_buffer.addr;626626+627627+ for (i = 0; i < NUM_DMA_LINKS; i++) {628628+ struct fsl_dma_link_descriptor *link = &dma_private->link[i];629629+630630+ link->count = cpu_to_be32(period_size);631631+632632+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)633633+ link->source_addr = cpu_to_be32(temp_addr);634634+ else635635+ link->dest_addr = cpu_to_be32(temp_addr);636636+637637+ temp_addr += period_size;638638+ }518639519640 return 0;520641}