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
···327 * fsl_dma_open: open a new substream.328 *329 * Each substream has its own DMA buffer.000000000000000000000000000000000000000000000000000000000330 */331static int fsl_dma_open(struct snd_pcm_substream *substream)332{333 struct snd_pcm_runtime *runtime = substream->runtime;334 struct fsl_dma_private *dma_private;0335 dma_addr_t ld_buf_phys;00336 unsigned int channel;337 int ret = 0;0338339 /*340 * Reject any DMA buffer whose size is not a multiple of the period···456 snd_soc_set_runtime_hwparams(substream, &fsl_dma_hardware);457 runtime->private_data = dma_private;458459- return 0;460-}461462-/**463- * fsl_dma_hw_params: allocate the DMA buffer and the DMA link descriptors.464- *465- * ALSA divides the DMA buffer into N periods. We create NUM_DMA_LINKS link466- * descriptors that ping-pong from one period to the next. For example, if467- * there are six periods and two link descriptors, this is how they look468- * before playback starts:469- *470- * The last link descriptor471- * ____________ points back to the first472- * | |473- * V |474- * ___ ___ |475- * | |->| |->|476- * |___| |___|477- * | |478- * | |479- * V V480- * _________________________________________481- * | | | | | | | The DMA buffer is482- * | | | | | | | divided into 6 parts483- * |______|______|______|______|______|______|484- *485- * and here's how they look after the first period is finished playing:486- *487- * ____________488- * | |489- * V |490- * ___ ___ |491- * | |->| |->|492- * |___| |___|493- * | |494- * |______________495- * | |496- * V V497- * _________________________________________498- * | | | | | | |499- * | | | | | | |500- * |______|______|______|______|______|______|501- *502- * The first link descriptor now points to the third period. The DMA503- * controller is currently playing the second period. When it finishes, it504- * will jump back to the first descriptor and play the third period.505- *506- * There are four reasons we do this:507- *508- * 1. The only way to get the DMA controller to automatically restart the509- * transfer when it gets to the end of the buffer is to use chaining510- * mode. Basic direct mode doesn't offer that feature.511- * 2. We need to receive an interrupt at the end of every period. The DMA512- * controller can generate an interrupt at the end of every link transfer513- * (aka segment). Making each period into a DMA segment will give us the514- * interrupts we need.515- * 3. By creating only two link descriptors, regardless of the number of516- * periods, we do not need to reallocate the link descriptors if the517- * number of periods changes.518- * 4. All of the audio data is still stored in a single, contiguous DMA519- * buffer, which is what ALSA expects. We're just dividing it into520- * contiguous parts, and creating a link descriptor for each one.521- *522- * Note that due to a quirk of the SSI's STX register, the target address523- * for the DMA operations depends on the sample size. So we don't program524- * the dest_addr (for playback -- source_addr for capture) fields in the525- * link descriptors here. We do that in fsl_dma_prepare()526- */527-static int fsl_dma_hw_params(struct snd_pcm_substream *substream,528- struct snd_pcm_hw_params *hw_params)529-{530- struct snd_pcm_runtime *runtime = substream->runtime;531- struct fsl_dma_private *dma_private = runtime->private_data;532- struct ccsr_dma_channel __iomem *dma_channel = dma_private->dma_channel;533534- dma_addr_t temp_addr; /* Pointer to next period */535- u64 temp_link; /* Pointer to next link descriptor */536- u32 mr; /* Temporary variable for MR register */537-538- unsigned int i;539-540- /* Get all the parameters we need */541- size_t buffer_size = params_buffer_bytes(hw_params);542- size_t period_size = params_period_bytes(hw_params);543-544- /* Initialize our DMA tracking variables */545- dma_private->period_size = period_size;546- dma_private->num_periods = params_periods(hw_params);547- dma_private->dma_buf_end = dma_private->dma_buf_phys + buffer_size;548- dma_private->dma_buf_next = dma_private->dma_buf_phys +549- (NUM_DMA_LINKS * period_size);550- if (dma_private->dma_buf_next >= dma_private->dma_buf_end)551- dma_private->dma_buf_next = dma_private->dma_buf_phys;552-553- /*554- * Initialize each link descriptor.555- *556- * The actual address in STX0 (destination for playback, source for557- * capture) is based on the sample size, but we don't know the sample558- * size in this function, so we'll have to adjust that later. See559- * comments in fsl_dma_prepare().560- *561- * The DMA controller does not have a cache, so the CPU does not562- * need to tell it to flush its cache. However, the DMA563- * controller does need to tell the CPU to flush its cache.564- * That's what the SNOOP bit does.565- *566- * Also, even though the DMA controller supports 36-bit addressing, for567- * simplicity we currently support only 32-bit addresses for the audio568- * buffer itself.569- */570- temp_addr = substream->dma_buffer.addr;571 temp_link = dma_private->ld_buf_phys +572 sizeof(struct fsl_dma_link_descriptor);573574 for (i = 0; i < NUM_DMA_LINKS; i++) {575 struct fsl_dma_link_descriptor *link = &dma_private->link[i];576577- link->count = cpu_to_be32(period_size);578 link->source_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP);579 link->dest_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP);580 link->next = cpu_to_be64(temp_link);581582- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)583- link->source_addr = cpu_to_be32(temp_addr);584- else585- link->dest_addr = cpu_to_be32(temp_addr);586-587- temp_addr += period_size;588 temp_link += sizeof(struct fsl_dma_link_descriptor);589 }590 /* The last link descriptor points to the first */···495 * We want External Master Start and External Master Pause enabled,496 * because the SSI is controlling the DMA controller. We want the DMA497 * controller to be set up in advance, and then we signal only the SSI498- * to start transfering.499 *500 * We want End-Of-Segment Interrupts enabled, because this will generate501 * an interrupt at the end of each segment (each link descriptor···515 CCSR_DMA_MR_DAHE : CCSR_DMA_MR_SAHE;516517 out_be32(&dma_channel->mr, mr);0000000000000000000000000000000000000000000000000000000000000000000518519 return 0;520}
···327 * fsl_dma_open: open a new substream.328 *329 * Each substream has its own DMA buffer.330+ *331+ * ALSA divides the DMA buffer into N periods. We create NUM_DMA_LINKS link332+ * descriptors that ping-pong from one period to the next. For example, if333+ * there are six periods and two link descriptors, this is how they look334+ * before playback starts:335+ *336+ * The last link descriptor337+ * ____________ points back to the first338+ * | |339+ * V |340+ * ___ ___ |341+ * | |->| |->|342+ * |___| |___|343+ * | |344+ * | |345+ * V V346+ * _________________________________________347+ * | | | | | | | The DMA buffer is348+ * | | | | | | | divided into 6 parts349+ * |______|______|______|______|______|______|350+ *351+ * and here's how they look after the first period is finished playing:352+ *353+ * ____________354+ * | |355+ * V |356+ * ___ ___ |357+ * | |->| |->|358+ * |___| |___|359+ * | |360+ * |______________361+ * | |362+ * V V363+ * _________________________________________364+ * | | | | | | |365+ * | | | | | | |366+ * |______|______|______|______|______|______|367+ *368+ * The first link descriptor now points to the third period. The DMA369+ * controller is currently playing the second period. When it finishes, it370+ * will jump back to the first descriptor and play the third period.371+ *372+ * There are four reasons we do this:373+ *374+ * 1. The only way to get the DMA controller to automatically restart the375+ * transfer when it gets to the end of the buffer is to use chaining376+ * mode. Basic direct mode doesn't offer that feature.377+ * 2. We need to receive an interrupt at the end of every period. The DMA378+ * controller can generate an interrupt at the end of every link transfer379+ * (aka segment). Making each period into a DMA segment will give us the380+ * interrupts we need.381+ * 3. By creating only two link descriptors, regardless of the number of382+ * periods, we do not need to reallocate the link descriptors if the383+ * number of periods changes.384+ * 4. All of the audio data is still stored in a single, contiguous DMA385+ * buffer, which is what ALSA expects. We're just dividing it into386+ * contiguous parts, and creating a link descriptor for each one.387 */388static int fsl_dma_open(struct snd_pcm_substream *substream)389{390 struct snd_pcm_runtime *runtime = substream->runtime;391 struct fsl_dma_private *dma_private;392+ struct ccsr_dma_channel __iomem *dma_channel;393 dma_addr_t ld_buf_phys;394+ u64 temp_link; /* Pointer to next link descriptor */395+ u32 mr;396 unsigned int channel;397 int ret = 0;398+ unsigned int i;399400 /*401 * Reject any DMA buffer whose size is not a multiple of the period···395 snd_soc_set_runtime_hwparams(substream, &fsl_dma_hardware);396 runtime->private_data = dma_private;397398+ /* Program the fixed DMA controller parameters */0399400+ dma_channel = dma_private->dma_channel;00000000000000000000000000000000000000000000000000000000000000000000004010000000000000000000000000000000000000402 temp_link = dma_private->ld_buf_phys +403 sizeof(struct fsl_dma_link_descriptor);404405 for (i = 0; i < NUM_DMA_LINKS; i++) {406 struct fsl_dma_link_descriptor *link = &dma_private->link[i];4070408 link->source_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP);409 link->dest_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP);410 link->next = cpu_to_be64(temp_link);411000000412 temp_link += sizeof(struct fsl_dma_link_descriptor);413 }414 /* The last link descriptor points to the first */···549 * We want External Master Start and External Master Pause enabled,550 * because the SSI is controlling the DMA controller. We want the DMA551 * controller to be set up in advance, and then we signal only the SSI552+ * to start transferring.553 *554 * We want End-Of-Segment Interrupts enabled, because this will generate555 * an interrupt at the end of each segment (each link descriptor···569 CCSR_DMA_MR_DAHE : CCSR_DMA_MR_SAHE;570571 out_be32(&dma_channel->mr, mr);572+573+ return 0;574+}575+576+/**577+ * fsl_dma_hw_params: continue initializing the DMA links578+ *579+ * This function obtains hardware parameters about the opened stream and580+ * programs the DMA controller accordingly.581+ *582+ * Note that due to a quirk of the SSI's STX register, the target address583+ * for the DMA operations depends on the sample size. So we don't program584+ * the dest_addr (for playback -- source_addr for capture) fields in the585+ * link descriptors here. We do that in fsl_dma_prepare()586+ */587+static int fsl_dma_hw_params(struct snd_pcm_substream *substream,588+ struct snd_pcm_hw_params *hw_params)589+{590+ struct snd_pcm_runtime *runtime = substream->runtime;591+ struct fsl_dma_private *dma_private = runtime->private_data;592+593+ dma_addr_t temp_addr; /* Pointer to next period */594+595+ unsigned int i;596+597+ /* Get all the parameters we need */598+ size_t buffer_size = params_buffer_bytes(hw_params);599+ size_t period_size = params_period_bytes(hw_params);600+601+ /* Initialize our DMA tracking variables */602+ dma_private->period_size = period_size;603+ dma_private->num_periods = params_periods(hw_params);604+ dma_private->dma_buf_end = dma_private->dma_buf_phys + buffer_size;605+ dma_private->dma_buf_next = dma_private->dma_buf_phys +606+ (NUM_DMA_LINKS * period_size);607+ if (dma_private->dma_buf_next >= dma_private->dma_buf_end)608+ dma_private->dma_buf_next = dma_private->dma_buf_phys;609+610+ /*611+ * The actual address in STX0 (destination for playback, source for612+ * capture) is based on the sample size, but we don't know the sample613+ * size in this function, so we'll have to adjust that later. See614+ * comments in fsl_dma_prepare().615+ *616+ * The DMA controller does not have a cache, so the CPU does not617+ * need to tell it to flush its cache. However, the DMA618+ * controller does need to tell the CPU to flush its cache.619+ * That's what the SNOOP bit does.620+ *621+ * Also, even though the DMA controller supports 36-bit addressing, for622+ * simplicity we currently support only 32-bit addresses for the audio623+ * buffer itself.624+ */625+ temp_addr = substream->dma_buffer.addr;626+627+ for (i = 0; i < NUM_DMA_LINKS; i++) {628+ struct fsl_dma_link_descriptor *link = &dma_private->link[i];629+630+ link->count = cpu_to_be32(period_size);631+632+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)633+ link->source_addr = cpu_to_be32(temp_addr);634+ else635+ link->dest_addr = cpu_to_be32(temp_addr);636+637+ temp_addr += period_size;638+ }639640 return 0;641}