2019-05-27 09:55:05 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-10-03 18:57:50 +04:00
|
|
|
/*
|
|
|
|
* atmel_ssc_dai.c -- ALSA SoC ATMEL SSC Audio Layer Platform driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 SAN People
|
|
|
|
* Copyright (C) 2008 Atmel
|
|
|
|
*
|
|
|
|
* Author: Sedji Gaouaou <sedji.gaouaou@atmel.com>
|
|
|
|
* ATMEL CORP.
|
|
|
|
*
|
|
|
|
* Based on at91-ssc.c by
|
|
|
|
* Frank Mandarino <fmandarino@endrelia.com>
|
|
|
|
* Based on pxa2xx Platform drivers by
|
2009-02-03 01:23:22 +03:00
|
|
|
* Liam Girdwood <lrg@slimlogic.co.uk>
|
2008-10-03 18:57:50 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/atmel_pdc.h>
|
|
|
|
|
|
|
|
#include <linux/atmel-ssc.h>
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
|
|
|
|
#include "atmel-pcm.h"
|
|
|
|
#include "atmel_ssc_dai.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define NUM_SSC_DEVICES 3
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SSC PDC registers required by the PCM DMA engine.
|
|
|
|
*/
|
|
|
|
static struct atmel_pdc_regs pdc_tx_reg = {
|
|
|
|
.xpr = ATMEL_PDC_TPR,
|
|
|
|
.xcr = ATMEL_PDC_TCR,
|
|
|
|
.xnpr = ATMEL_PDC_TNPR,
|
|
|
|
.xncr = ATMEL_PDC_TNCR,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct atmel_pdc_regs pdc_rx_reg = {
|
|
|
|
.xpr = ATMEL_PDC_RPR,
|
|
|
|
.xcr = ATMEL_PDC_RCR,
|
|
|
|
.xnpr = ATMEL_PDC_RNPR,
|
|
|
|
.xncr = ATMEL_PDC_RNCR,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SSC & PDC status bits for transmit and receive.
|
|
|
|
*/
|
|
|
|
static struct atmel_ssc_mask ssc_tx_mask = {
|
|
|
|
.ssc_enable = SSC_BIT(CR_TXEN),
|
|
|
|
.ssc_disable = SSC_BIT(CR_TXDIS),
|
|
|
|
.ssc_endx = SSC_BIT(SR_ENDTX),
|
|
|
|
.ssc_endbuf = SSC_BIT(SR_TXBUFE),
|
2013-07-03 12:37:57 +04:00
|
|
|
.ssc_error = SSC_BIT(SR_OVRUN),
|
2008-10-03 18:57:50 +04:00
|
|
|
.pdc_enable = ATMEL_PDC_TXTEN,
|
|
|
|
.pdc_disable = ATMEL_PDC_TXTDIS,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct atmel_ssc_mask ssc_rx_mask = {
|
|
|
|
.ssc_enable = SSC_BIT(CR_RXEN),
|
|
|
|
.ssc_disable = SSC_BIT(CR_RXDIS),
|
|
|
|
.ssc_endx = SSC_BIT(SR_ENDRX),
|
|
|
|
.ssc_endbuf = SSC_BIT(SR_RXBUFF),
|
2013-07-03 12:37:57 +04:00
|
|
|
.ssc_error = SSC_BIT(SR_OVRUN),
|
2008-10-03 18:57:50 +04:00
|
|
|
.pdc_enable = ATMEL_PDC_RXTEN,
|
|
|
|
.pdc_disable = ATMEL_PDC_RXTDIS,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DMA parameters.
|
|
|
|
*/
|
|
|
|
static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = {
|
|
|
|
{{
|
|
|
|
.name = "SSC0 PCM out",
|
|
|
|
.pdc = &pdc_tx_reg,
|
|
|
|
.mask = &ssc_tx_mask,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "SSC0 PCM in",
|
|
|
|
.pdc = &pdc_rx_reg,
|
|
|
|
.mask = &ssc_rx_mask,
|
|
|
|
} },
|
|
|
|
{{
|
|
|
|
.name = "SSC1 PCM out",
|
|
|
|
.pdc = &pdc_tx_reg,
|
|
|
|
.mask = &ssc_tx_mask,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "SSC1 PCM in",
|
|
|
|
.pdc = &pdc_rx_reg,
|
|
|
|
.mask = &ssc_rx_mask,
|
|
|
|
} },
|
|
|
|
{{
|
|
|
|
.name = "SSC2 PCM out",
|
|
|
|
.pdc = &pdc_tx_reg,
|
|
|
|
.mask = &ssc_tx_mask,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "SSC2 PCM in",
|
|
|
|
.pdc = &pdc_rx_reg,
|
|
|
|
.mask = &ssc_rx_mask,
|
|
|
|
} },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES] = {
|
|
|
|
{
|
|
|
|
.name = "ssc0",
|
|
|
|
.dir_mask = SSC_DIR_MASK_UNUSED,
|
|
|
|
.initialized = 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "ssc1",
|
|
|
|
.dir_mask = SSC_DIR_MASK_UNUSED,
|
|
|
|
.initialized = 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "ssc2",
|
|
|
|
.dir_mask = SSC_DIR_MASK_UNUSED,
|
|
|
|
.initialized = 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SSC interrupt handler. Passes PDC interrupts to the DMA
|
|
|
|
* interrupt handler in the PCM driver.
|
|
|
|
*/
|
|
|
|
static irqreturn_t atmel_ssc_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct atmel_ssc_info *ssc_p = dev_id;
|
|
|
|
struct atmel_pcm_dma_params *dma_params;
|
|
|
|
u32 ssc_sr;
|
|
|
|
u32 ssc_substream_mask;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ssc_sr = (unsigned long)ssc_readl(ssc_p->ssc->regs, SR)
|
|
|
|
& (unsigned long)ssc_readl(ssc_p->ssc->regs, IMR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through the substreams attached to this SSC. If
|
|
|
|
* a DMA-related interrupt occurred on that substream, call
|
|
|
|
* the DMA interrupt handler function, if one has been
|
|
|
|
* registered in the dma_params structure by the PCM driver.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ssc_p->dma_params); i++) {
|
|
|
|
dma_params = ssc_p->dma_params[i];
|
|
|
|
|
|
|
|
if ((dma_params != NULL) &&
|
|
|
|
(dma_params->dma_intr_handler != NULL)) {
|
|
|
|
ssc_substream_mask = (dma_params->mask->ssc_endx |
|
|
|
|
dma_params->mask->ssc_endbuf);
|
|
|
|
if (ssc_sr & ssc_substream_mask) {
|
|
|
|
dma_params->dma_intr_handler(ssc_sr,
|
|
|
|
dma_params->
|
|
|
|
substream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2015-02-09 18:08:25 +03:00
|
|
|
/*
|
|
|
|
* When the bit clock is input, limit the maximum rate according to the
|
|
|
|
* Serial Clock Ratio Considerations section from the SSC documentation:
|
|
|
|
*
|
|
|
|
* The Transmitter and the Receiver can be programmed to operate
|
|
|
|
* with the clock signals provided on either the TK or RK pins.
|
|
|
|
* This allows the SSC to support many slave-mode data transfers.
|
|
|
|
* In this case, the maximum clock speed allowed on the RK pin is:
|
|
|
|
* - Peripheral clock divided by 2 if Receiver Frame Synchro is input
|
|
|
|
* - Peripheral clock divided by 3 if Receiver Frame Synchro is output
|
|
|
|
* In addition, the maximum clock speed allowed on the TK pin is:
|
|
|
|
* - Peripheral clock divided by 6 if Transmit Frame Synchro is input
|
|
|
|
* - Peripheral clock divided by 2 if Transmit Frame Synchro is output
|
|
|
|
*
|
|
|
|
* When the bit clock is output, limit the rate according to the
|
|
|
|
* SSC divider restrictions.
|
|
|
|
*/
|
|
|
|
static int atmel_ssc_hw_rule_rate(struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_pcm_hw_rule *rule)
|
|
|
|
{
|
|
|
|
struct atmel_ssc_info *ssc_p = rule->private;
|
|
|
|
struct ssc_device *ssc = ssc_p->ssc;
|
|
|
|
struct snd_interval *i = hw_param_interval(params, rule->var);
|
|
|
|
struct snd_interval t;
|
|
|
|
struct snd_ratnum r = {
|
|
|
|
.den_min = 1,
|
|
|
|
.den_max = 4095,
|
|
|
|
.den_step = 1,
|
|
|
|
};
|
|
|
|
unsigned int num = 0, den = 0;
|
|
|
|
int frame_size;
|
|
|
|
int mck_div = 2;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
frame_size = snd_soc_params_to_frame_size(params);
|
|
|
|
if (frame_size < 0)
|
|
|
|
return frame_size;
|
|
|
|
|
|
|
|
switch (ssc_p->daifmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFS:
|
|
|
|
if ((ssc_p->dir_mask & SSC_DIR_MASK_CAPTURE)
|
|
|
|
&& ssc->clk_from_rk_pin)
|
|
|
|
/* Receiver Frame Synchro (i.e. capture)
|
|
|
|
* is output (format is _CFS) and the RK pin
|
|
|
|
* is used for input (format is _CBM_).
|
|
|
|
*/
|
|
|
|
mck_div = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
|
|
|
if ((ssc_p->dir_mask & SSC_DIR_MASK_PLAYBACK)
|
|
|
|
&& !ssc->clk_from_rk_pin)
|
|
|
|
/* Transmit Frame Synchro (i.e. playback)
|
|
|
|
* is input (format is _CFM) and the TK pin
|
|
|
|
* is used for input (format _CBM_ but not
|
|
|
|
* using the RK pin).
|
|
|
|
*/
|
|
|
|
mck_div = 6;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ssc_p->daifmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
|
|
|
r.num = ssc_p->mck_rate / mck_div / frame_size;
|
|
|
|
|
|
|
|
ret = snd_interval_ratnum(i, 1, &r, &num, &den);
|
|
|
|
if (ret >= 0 && den && rule->var == SNDRV_PCM_HW_PARAM_RATE) {
|
|
|
|
params->rate_num = num;
|
|
|
|
params->rate_den = den;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFS:
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
|
|
|
t.min = 8000;
|
|
|
|
t.max = ssc_p->mck_rate / mck_div / frame_size;
|
|
|
|
t.openmin = t.openmax = 0;
|
|
|
|
t.integer = 0;
|
|
|
|
ret = snd_interval_refine(i, &t);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*\
|
|
|
|
* DAI functions
|
|
|
|
\*-------------------------------------------------------------------------*/
|
|
|
|
/*
|
|
|
|
* Startup. Only that one substream allowed in each direction.
|
|
|
|
*/
|
2008-11-19 01:11:38 +03:00
|
|
|
static int atmel_ssc_startup(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
2008-10-03 18:57:50 +04:00
|
|
|
{
|
2016-03-02 14:15:25 +03:00
|
|
|
struct platform_device *pdev = to_platform_device(dai->dev);
|
|
|
|
struct atmel_ssc_info *ssc_p = &ssc_info[pdev->id];
|
2013-07-03 12:37:56 +04:00
|
|
|
struct atmel_pcm_dma_params *dma_params;
|
|
|
|
int dir, dir_mask;
|
2015-02-09 18:08:25 +03:00
|
|
|
int ret;
|
2008-10-03 18:57:50 +04:00
|
|
|
|
2015-08-03 20:49:29 +03:00
|
|
|
pr_debug("atmel_ssc_startup: SSC_SR=0x%x\n",
|
2008-10-03 18:57:50 +04:00
|
|
|
ssc_readl(ssc_p->ssc->regs, SR));
|
|
|
|
|
2015-01-30 12:38:43 +03:00
|
|
|
/* Enable PMC peripheral clock for this SSC */
|
|
|
|
pr_debug("atmel_ssc_dai: Starting clock\n");
|
|
|
|
clk_enable(ssc_p->ssc->clk);
|
2015-02-09 18:08:25 +03:00
|
|
|
ssc_p->mck_rate = clk_get_rate(ssc_p->ssc->clk);
|
2015-01-30 12:38:43 +03:00
|
|
|
|
2016-08-15 19:59:25 +03:00
|
|
|
/* Reset the SSC unless initialized to keep it in a clean state */
|
|
|
|
if (!ssc_p->initialized)
|
|
|
|
ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST));
|
2015-01-30 12:38:43 +03:00
|
|
|
|
2013-07-03 12:37:56 +04:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
|
|
|
dir = 0;
|
2008-10-03 18:57:50 +04:00
|
|
|
dir_mask = SSC_DIR_MASK_PLAYBACK;
|
2013-07-03 12:37:56 +04:00
|
|
|
} else {
|
|
|
|
dir = 1;
|
2008-10-03 18:57:50 +04:00
|
|
|
dir_mask = SSC_DIR_MASK_CAPTURE;
|
2013-07-03 12:37:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-09 18:08:25 +03:00
|
|
|
ret = snd_pcm_hw_rule_add(substream->runtime, 0,
|
|
|
|
SNDRV_PCM_HW_PARAM_RATE,
|
|
|
|
atmel_ssc_hw_rule_rate,
|
|
|
|
ssc_p,
|
|
|
|
SNDRV_PCM_HW_PARAM_FRAME_BITS,
|
|
|
|
SNDRV_PCM_HW_PARAM_CHANNELS, -1);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dai->dev, "Failed to specify rate rule: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-07-05 12:46:29 +03:00
|
|
|
dma_params = &ssc_dma_params[pdev->id][dir];
|
2013-07-03 12:37:56 +04:00
|
|
|
dma_params->ssc = ssc_p->ssc;
|
|
|
|
dma_params->substream = substream;
|
|
|
|
|
|
|
|
ssc_p->dma_params[dir] = dma_params;
|
|
|
|
|
|
|
|
snd_soc_dai_set_dma_data(dai, substream, dma_params);
|
2008-10-03 18:57:50 +04:00
|
|
|
|
2019-09-18 13:03:44 +03:00
|
|
|
if (ssc_p->dir_mask & dir_mask)
|
2008-10-03 18:57:50 +04:00
|
|
|
return -EBUSY;
|
2019-09-18 13:03:44 +03:00
|
|
|
|
2008-10-03 18:57:50 +04:00
|
|
|
ssc_p->dir_mask |= dir_mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shutdown. Clear DMA parameters and shutdown the SSC if there
|
|
|
|
* are no other substreams open.
|
|
|
|
*/
|
2008-11-19 01:11:38 +03:00
|
|
|
static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
2008-10-03 18:57:50 +04:00
|
|
|
{
|
2016-03-02 14:15:25 +03:00
|
|
|
struct platform_device *pdev = to_platform_device(dai->dev);
|
|
|
|
struct atmel_ssc_info *ssc_p = &ssc_info[pdev->id];
|
2008-10-03 18:57:50 +04:00
|
|
|
struct atmel_pcm_dma_params *dma_params;
|
|
|
|
int dir, dir_mask;
|
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
dir = 0;
|
|
|
|
else
|
|
|
|
dir = 1;
|
|
|
|
|
|
|
|
dma_params = ssc_p->dma_params[dir];
|
|
|
|
|
|
|
|
if (dma_params != NULL) {
|
|
|
|
dma_params->ssc = NULL;
|
|
|
|
dma_params->substream = NULL;
|
|
|
|
ssc_p->dma_params[dir] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dir_mask = 1 << dir;
|
|
|
|
|
|
|
|
ssc_p->dir_mask &= ~dir_mask;
|
|
|
|
if (!ssc_p->dir_mask) {
|
|
|
|
if (ssc_p->initialized) {
|
|
|
|
free_irq(ssc_p->ssc->irq, ssc_p);
|
|
|
|
ssc_p->initialized = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the SSC */
|
|
|
|
ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST));
|
|
|
|
/* Clear the SSC dividers */
|
|
|
|
ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0;
|
2016-11-15 21:38:13 +03:00
|
|
|
ssc_p->forced_divider = 0;
|
2008-10-03 18:57:50 +04:00
|
|
|
}
|
2015-01-30 12:38:43 +03:00
|
|
|
|
|
|
|
/* Shutdown the SSC clock. */
|
|
|
|
pr_debug("atmel_ssc_dai: Stopping clock\n");
|
|
|
|
clk_disable(ssc_p->ssc->clk);
|
2008-10-03 18:57:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record the DAI format for use in hw_params().
|
|
|
|
*/
|
|
|
|
static int atmel_ssc_set_dai_fmt(struct snd_soc_dai *cpu_dai,
|
|
|
|
unsigned int fmt)
|
|
|
|
{
|
2016-03-02 14:15:25 +03:00
|
|
|
struct platform_device *pdev = to_platform_device(cpu_dai->dev);
|
|
|
|
struct atmel_ssc_info *ssc_p = &ssc_info[pdev->id];
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
ssc_p->daifmt = fmt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record SSC clock dividers for use in hw_params().
|
|
|
|
*/
|
|
|
|
static int atmel_ssc_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
|
|
|
|
int div_id, int div)
|
|
|
|
{
|
2016-03-02 14:15:25 +03:00
|
|
|
struct platform_device *pdev = to_platform_device(cpu_dai->dev);
|
|
|
|
struct atmel_ssc_info *ssc_p = &ssc_info[pdev->id];
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
switch (div_id) {
|
|
|
|
case ATMEL_SSC_CMR_DIV:
|
|
|
|
/*
|
|
|
|
* The same master clock divider is used for both
|
|
|
|
* transmit and receive, so if a value has already
|
|
|
|
* been set, it must match this value.
|
|
|
|
*/
|
ASoC: atmel_ssc_dai: Match the CMR divider only in full duplex.
The CMR divider register is shared by playback and capture. The SSC driver
therefore tries to enforce rules so that the needed register content do
not conflict during simultaneous playback/capture. However, the
implementation also prevents changing the register content in
half-duplex scenarios, which is needed when using the OSS API.
Thus, only lock the divider if there is a stream in the other direction.
Fixes the below program to not fail with the atmel ssc dai in master mode.
int
main(void)
{
int fd;
int format;
int channels;
int speed;
if ((fd = open("/dev/dsp", O_WRONLY, 0)) == -1) {
perror("open");
return 1;
}
format = AFMT_S16_LE;
if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) == -1) {
perror("SNDCTL_DSP_SETFMT");
return 1;
}
channels = 2;
if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
perror("SNDCTL_DSP_CHANNELS");
return 1;
}
speed = 22025;
if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) == -1) {
perror("SNDCTL_DSP_SPEED");
return 1;
}
return 0;
}
Signed-off-by: Peter Rosin <peda@axentia.se>
Acked-by: Bo Shen <voice.shen@atmel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2014-10-24 23:25:59 +04:00
|
|
|
if (ssc_p->dir_mask !=
|
|
|
|
(SSC_DIR_MASK_PLAYBACK | SSC_DIR_MASK_CAPTURE))
|
|
|
|
ssc_p->cmr_div = div;
|
|
|
|
else if (ssc_p->cmr_div == 0)
|
2008-10-03 18:57:50 +04:00
|
|
|
ssc_p->cmr_div = div;
|
|
|
|
else
|
|
|
|
if (div != ssc_p->cmr_div)
|
|
|
|
return -EBUSY;
|
2016-11-15 21:38:13 +03:00
|
|
|
ssc_p->forced_divider |= BIT(ATMEL_SSC_CMR_DIV);
|
2008-10-03 18:57:50 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ATMEL_SSC_TCMR_PERIOD:
|
|
|
|
ssc_p->tcmr_period = div;
|
2016-11-15 21:38:13 +03:00
|
|
|
ssc_p->forced_divider |= BIT(ATMEL_SSC_TCMR_PERIOD);
|
2008-10-03 18:57:50 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ATMEL_SSC_RCMR_PERIOD:
|
|
|
|
ssc_p->rcmr_period = div;
|
2016-11-15 21:38:13 +03:00
|
|
|
ssc_p->forced_divider |= BIT(ATMEL_SSC_RCMR_PERIOD);
|
2008-10-03 18:57:50 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-15 21:38:13 +03:00
|
|
|
/* Is the cpu-dai master of the frame clock? */
|
|
|
|
static int atmel_ssc_cfs(struct atmel_ssc_info *ssc_p)
|
|
|
|
{
|
|
|
|
switch (ssc_p->daifmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFS:
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the cpu-dai master of the bit clock? */
|
|
|
|
static int atmel_ssc_cbs(struct atmel_ssc_info *ssc_p)
|
|
|
|
{
|
|
|
|
switch (ssc_p->daifmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFM:
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-03 18:57:50 +04:00
|
|
|
/*
|
|
|
|
* Configure the SSC.
|
|
|
|
*/
|
|
|
|
static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
|
2008-11-19 01:11:38 +03:00
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_soc_dai *dai)
|
2008-10-03 18:57:50 +04:00
|
|
|
{
|
2016-03-02 14:15:25 +03:00
|
|
|
struct platform_device *pdev = to_platform_device(dai->dev);
|
|
|
|
int id = pdev->id;
|
2008-10-03 18:57:50 +04:00
|
|
|
struct atmel_ssc_info *ssc_p = &ssc_info[id];
|
2014-02-10 10:09:45 +04:00
|
|
|
struct ssc_device *ssc = ssc_p->ssc;
|
2008-10-03 18:57:50 +04:00
|
|
|
struct atmel_pcm_dma_params *dma_params;
|
|
|
|
int dir, channels, bits;
|
|
|
|
u32 tfmr, rfmr, tcmr, rcmr;
|
|
|
|
int ret;
|
2019-08-24 23:26:53 +03:00
|
|
|
int fslen, fslen_ext, fs_osync, fs_edge;
|
2016-11-15 21:38:13 +03:00
|
|
|
u32 cmr_div;
|
|
|
|
u32 tcmr_period;
|
|
|
|
u32 rcmr_period;
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Currently, there is only one set of dma params for
|
|
|
|
* each direction. If more are added, this code will
|
|
|
|
* have to be changed to select the proper set.
|
|
|
|
*/
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
dir = 0;
|
|
|
|
else
|
|
|
|
dir = 1;
|
|
|
|
|
2016-11-15 21:38:13 +03:00
|
|
|
/*
|
|
|
|
* If the cpu dai should provide BCLK, but noone has provided the
|
|
|
|
* divider needed for that to work, fall back to something sensible.
|
|
|
|
*/
|
|
|
|
cmr_div = ssc_p->cmr_div;
|
|
|
|
if (!(ssc_p->forced_divider & BIT(ATMEL_SSC_CMR_DIV)) &&
|
|
|
|
atmel_ssc_cbs(ssc_p)) {
|
|
|
|
int bclk_rate = snd_soc_params_to_bclk(params);
|
|
|
|
|
|
|
|
if (bclk_rate < 0) {
|
|
|
|
dev_err(dai->dev, "unable to calculate cmr_div: %d\n",
|
|
|
|
bclk_rate);
|
|
|
|
return bclk_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmr_div = DIV_ROUND_CLOSEST(ssc_p->mck_rate, 2 * bclk_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the cpu dai should provide LRCLK, but noone has provided the
|
|
|
|
* dividers needed for that to work, fall back to something sensible.
|
|
|
|
*/
|
|
|
|
tcmr_period = ssc_p->tcmr_period;
|
|
|
|
rcmr_period = ssc_p->rcmr_period;
|
|
|
|
if (atmel_ssc_cfs(ssc_p)) {
|
|
|
|
int frame_size = snd_soc_params_to_frame_size(params);
|
|
|
|
|
|
|
|
if (frame_size < 0) {
|
|
|
|
dev_err(dai->dev,
|
|
|
|
"unable to calculate tx/rx cmr_period: %d\n",
|
|
|
|
frame_size);
|
|
|
|
return frame_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ssc_p->forced_divider & BIT(ATMEL_SSC_TCMR_PERIOD)))
|
|
|
|
tcmr_period = frame_size / 2 - 1;
|
|
|
|
if (!(ssc_p->forced_divider & BIT(ATMEL_SSC_RCMR_PERIOD)))
|
|
|
|
rcmr_period = frame_size / 2 - 1;
|
|
|
|
}
|
|
|
|
|
2013-07-03 12:37:56 +04:00
|
|
|
dma_params = ssc_p->dma_params[dir];
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
channels = params_channels(params);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine sample size in bits and the PDC increment.
|
|
|
|
*/
|
|
|
|
switch (params_format(params)) {
|
|
|
|
case SNDRV_PCM_FORMAT_S8:
|
|
|
|
bits = 8;
|
|
|
|
dma_params->pdc_xfer_size = 1;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_S16_LE:
|
|
|
|
bits = 16;
|
|
|
|
dma_params->pdc_xfer_size = 2;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_S24_LE:
|
|
|
|
bits = 24;
|
|
|
|
dma_params->pdc_xfer_size = 4;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_S32_LE:
|
|
|
|
bits = 32;
|
|
|
|
dma_params->pdc_xfer_size = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_WARNING "atmel_ssc_dai: unsupported PCM format");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute SSC register settings.
|
|
|
|
*/
|
|
|
|
|
2019-08-24 23:26:53 +03:00
|
|
|
fslen_ext = (bits - 1) / 16;
|
|
|
|
fslen = (bits - 1) % 16;
|
|
|
|
|
|
|
|
switch (ssc_p->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
|
2019-08-24 23:26:54 +03:00
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
fs_osync = SSC_FSOS_POSITIVE;
|
|
|
|
fs_edge = SSC_START_RISING_RF;
|
|
|
|
|
|
|
|
rcmr = SSC_BF(RCMR_STTDLY, 0);
|
|
|
|
tcmr = SSC_BF(TCMR_STTDLY, 0);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2019-08-24 23:26:53 +03:00
|
|
|
case SND_SOC_DAIFMT_I2S:
|
|
|
|
fs_osync = SSC_FSOS_NEGATIVE;
|
|
|
|
fs_edge = SSC_START_FALLING_RF;
|
|
|
|
|
|
|
|
rcmr = SSC_BF(RCMR_STTDLY, 1);
|
|
|
|
tcmr = SSC_BF(TCMR_STTDLY, 1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_SOC_DAIFMT_DSP_A:
|
2008-10-03 18:57:50 +04:00
|
|
|
/*
|
2019-08-24 23:26:53 +03:00
|
|
|
* DSP/PCM Mode A format
|
2008-10-03 18:57:50 +04:00
|
|
|
*
|
2019-08-24 23:26:53 +03:00
|
|
|
* Data is transferred on first BCLK after LRC pulse rising
|
|
|
|
* edge.If stereo, the right channel data is contiguous with
|
|
|
|
* the left channel data.
|
2008-10-03 18:57:50 +04:00
|
|
|
*/
|
2019-08-24 23:26:53 +03:00
|
|
|
fs_osync = SSC_FSOS_POSITIVE;
|
|
|
|
fs_edge = SSC_START_RISING_RF;
|
|
|
|
fslen = fslen_ext = 0;
|
2014-06-11 14:14:40 +04:00
|
|
|
|
2019-08-24 23:26:53 +03:00
|
|
|
rcmr = SSC_BF(RCMR_STTDLY, 1);
|
|
|
|
tcmr = SSC_BF(TCMR_STTDLY, 1);
|
2014-06-11 14:14:40 +04:00
|
|
|
|
2008-10-03 18:57:50 +04:00
|
|
|
break;
|
|
|
|
|
2019-08-24 23:26:53 +03:00
|
|
|
default:
|
|
|
|
printk(KERN_WARNING "atmel_ssc_dai: unsupported DAI format 0x%x\n",
|
|
|
|
ssc_p->daifmt);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2008-10-03 18:57:50 +04:00
|
|
|
|
2019-08-24 23:26:53 +03:00
|
|
|
if (!atmel_ssc_cfs(ssc_p)) {
|
|
|
|
fslen = fslen_ext = 0;
|
|
|
|
rcmr_period = tcmr_period = 0;
|
|
|
|
fs_osync = SSC_FSOS_NONE;
|
|
|
|
}
|
2015-01-29 13:16:29 +03:00
|
|
|
|
2019-08-24 23:26:53 +03:00
|
|
|
rcmr |= SSC_BF(RCMR_START, fs_edge);
|
|
|
|
tcmr |= SSC_BF(TCMR_START, fs_edge);
|
2008-10-03 18:57:50 +04:00
|
|
|
|
2019-08-24 23:26:53 +03:00
|
|
|
if (atmel_ssc_cbs(ssc_p)) {
|
2008-10-03 18:57:50 +04:00
|
|
|
/*
|
2019-08-24 23:26:53 +03:00
|
|
|
* SSC provides BCLK
|
2008-10-03 18:57:50 +04:00
|
|
|
*
|
|
|
|
* The SSC transmit and receive clocks are generated from the
|
|
|
|
* MCK divider, and the BCLK signal is output
|
|
|
|
* on the SSC TK line.
|
|
|
|
*/
|
2019-08-24 23:26:53 +03:00
|
|
|
rcmr |= SSC_BF(RCMR_CKS, SSC_CKS_DIV)
|
|
|
|
| SSC_BF(RCMR_CKO, SSC_CKO_NONE);
|
2008-10-03 18:57:50 +04:00
|
|
|
|
2019-08-24 23:26:53 +03:00
|
|
|
tcmr |= SSC_BF(TCMR_CKS, SSC_CKS_DIV)
|
|
|
|
| SSC_BF(TCMR_CKO, SSC_CKO_CONTINUOUS);
|
|
|
|
} else {
|
|
|
|
rcmr |= SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ?
|
|
|
|
SSC_CKS_PIN : SSC_CKS_CLOCK)
|
|
|
|
| SSC_BF(RCMR_CKO, SSC_CKO_NONE);
|
2013-02-20 20:31:35 +04:00
|
|
|
|
2019-08-24 23:26:53 +03:00
|
|
|
tcmr |= SSC_BF(TCMR_CKS, ssc->clk_from_rk_pin ?
|
|
|
|
SSC_CKS_CLOCK : SSC_CKS_PIN)
|
|
|
|
| SSC_BF(TCMR_CKO, SSC_CKO_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
rcmr |= SSC_BF(RCMR_PERIOD, rcmr_period)
|
|
|
|
| SSC_BF(RCMR_CKI, SSC_CKI_RISING);
|
|
|
|
|
|
|
|
tcmr |= SSC_BF(TCMR_PERIOD, tcmr_period)
|
|
|
|
| SSC_BF(TCMR_CKI, SSC_CKI_FALLING);
|
|
|
|
|
|
|
|
rfmr = SSC_BF(RFMR_FSLEN_EXT, fslen_ext)
|
|
|
|
| SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
|
|
|
|
| SSC_BF(RFMR_FSOS, fs_osync)
|
|
|
|
| SSC_BF(RFMR_FSLEN, fslen)
|
|
|
|
| SSC_BF(RFMR_DATNB, (channels - 1))
|
|
|
|
| SSC_BIT(RFMR_MSBF)
|
|
|
|
| SSC_BF(RFMR_LOOP, 0)
|
|
|
|
| SSC_BF(RFMR_DATLEN, (bits - 1));
|
|
|
|
|
|
|
|
tfmr = SSC_BF(TFMR_FSLEN_EXT, fslen_ext)
|
|
|
|
| SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
|
|
|
|
| SSC_BF(TFMR_FSDEN, 0)
|
|
|
|
| SSC_BF(TFMR_FSOS, fs_osync)
|
|
|
|
| SSC_BF(TFMR_FSLEN, fslen)
|
|
|
|
| SSC_BF(TFMR_DATNB, (channels - 1))
|
|
|
|
| SSC_BIT(TFMR_MSBF)
|
|
|
|
| SSC_BF(TFMR_DATDEF, 0)
|
|
|
|
| SSC_BF(TFMR_DATLEN, (bits - 1));
|
|
|
|
|
|
|
|
if (fslen_ext && !ssc->pdata->has_fslen_ext) {
|
|
|
|
dev_err(dai->dev, "sample size %d is too large for SSC device\n",
|
|
|
|
bits);
|
2008-10-03 18:57:50 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2019-08-24 23:26:53 +03:00
|
|
|
|
2008-10-03 18:57:50 +04:00
|
|
|
pr_debug("atmel_ssc_hw_params: "
|
|
|
|
"RCMR=%08x RFMR=%08x TCMR=%08x TFMR=%08x\n",
|
|
|
|
rcmr, rfmr, tcmr, tfmr);
|
|
|
|
|
|
|
|
if (!ssc_p->initialized) {
|
2015-01-30 12:38:44 +03:00
|
|
|
if (!ssc_p->ssc->pdata->use_dma) {
|
|
|
|
ssc_writel(ssc_p->ssc->regs, PDC_RPR, 0);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, PDC_RCR, 0);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, PDC_RNPR, 0);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, PDC_RNCR, 0);
|
|
|
|
|
|
|
|
ssc_writel(ssc_p->ssc->regs, PDC_TPR, 0);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, PDC_TCR, 0);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, PDC_TNPR, 0);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, PDC_TNCR, 0);
|
|
|
|
}
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
ret = request_irq(ssc_p->ssc->irq, atmel_ssc_interrupt, 0,
|
|
|
|
ssc_p->name, ssc_p);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"atmel_ssc_dai: request_irq failure\n");
|
2018-03-30 18:44:20 +03:00
|
|
|
pr_debug("Atmel_ssc_dai: Stopping clock\n");
|
2008-10-03 18:57:50 +04:00
|
|
|
clk_disable(ssc_p->ssc->clk);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssc_p->initialized = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set SSC clock mode register */
|
2016-11-15 21:38:13 +03:00
|
|
|
ssc_writel(ssc_p->ssc->regs, CMR, cmr_div);
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
/* set receive clock mode and format */
|
|
|
|
ssc_writel(ssc_p->ssc->regs, RCMR, rcmr);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, RFMR, rfmr);
|
|
|
|
|
|
|
|
/* set transmit clock mode and format */
|
|
|
|
ssc_writel(ssc_p->ssc->regs, TCMR, tcmr);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, TFMR, tfmr);
|
|
|
|
|
|
|
|
pr_debug("atmel_ssc_dai,hw_params: SSC initialized\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-19 01:11:38 +03:00
|
|
|
static int atmel_ssc_prepare(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
2008-10-03 18:57:50 +04:00
|
|
|
{
|
2016-03-02 14:15:25 +03:00
|
|
|
struct platform_device *pdev = to_platform_device(dai->dev);
|
|
|
|
struct atmel_ssc_info *ssc_p = &ssc_info[pdev->id];
|
2008-10-03 18:57:50 +04:00
|
|
|
struct atmel_pcm_dma_params *dma_params;
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
dir = 0;
|
|
|
|
else
|
|
|
|
dir = 1;
|
|
|
|
|
|
|
|
dma_params = ssc_p->dma_params[dir];
|
|
|
|
|
2013-12-04 06:37:03 +04:00
|
|
|
ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_disable);
|
2013-09-04 11:27:46 +04:00
|
|
|
ssc_writel(ssc_p->ssc->regs, IDR, dma_params->mask->ssc_error);
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
pr_debug("%s enabled SSC_SR=0x%08x\n",
|
|
|
|
dir ? "receive" : "transmit",
|
|
|
|
ssc_readl(ssc_p->ssc->regs, SR));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-04 06:37:03 +04:00
|
|
|
static int atmel_ssc_trigger(struct snd_pcm_substream *substream,
|
|
|
|
int cmd, struct snd_soc_dai *dai)
|
|
|
|
{
|
2016-03-02 14:15:25 +03:00
|
|
|
struct platform_device *pdev = to_platform_device(dai->dev);
|
|
|
|
struct atmel_ssc_info *ssc_p = &ssc_info[pdev->id];
|
2013-12-04 06:37:03 +04:00
|
|
|
struct atmel_pcm_dma_params *dma_params;
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
dir = 0;
|
|
|
|
else
|
|
|
|
dir = 1;
|
|
|
|
|
|
|
|
dma_params = ssc_p->dma_params[dir];
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_enable);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_disable);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
2020-01-20 04:03:36 +03:00
|
|
|
static int atmel_ssc_suspend(struct snd_soc_component *component)
|
2008-10-03 18:57:50 +04:00
|
|
|
{
|
|
|
|
struct atmel_ssc_info *ssc_p;
|
2020-01-20 04:03:36 +03:00
|
|
|
struct platform_device *pdev = to_platform_device(component->dev);
|
2008-10-03 18:57:50 +04:00
|
|
|
|
2020-01-20 04:03:36 +03:00
|
|
|
if (!component->active)
|
2008-10-03 18:57:50 +04:00
|
|
|
return 0;
|
|
|
|
|
2016-03-02 14:15:25 +03:00
|
|
|
ssc_p = &ssc_info[pdev->id];
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
/* Save the status register before disabling transmit and receive */
|
|
|
|
ssc_p->ssc_state.ssc_sr = ssc_readl(ssc_p->ssc->regs, SR);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_TXDIS) | SSC_BIT(CR_RXDIS));
|
|
|
|
|
|
|
|
/* Save the current interrupt mask, then disable unmasked interrupts */
|
|
|
|
ssc_p->ssc_state.ssc_imr = ssc_readl(ssc_p->ssc->regs, IMR);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, IDR, ssc_p->ssc_state.ssc_imr);
|
|
|
|
|
|
|
|
ssc_p->ssc_state.ssc_cmr = ssc_readl(ssc_p->ssc->regs, CMR);
|
|
|
|
ssc_p->ssc_state.ssc_rcmr = ssc_readl(ssc_p->ssc->regs, RCMR);
|
|
|
|
ssc_p->ssc_state.ssc_rfmr = ssc_readl(ssc_p->ssc->regs, RFMR);
|
|
|
|
ssc_p->ssc_state.ssc_tcmr = ssc_readl(ssc_p->ssc->regs, TCMR);
|
|
|
|
ssc_p->ssc_state.ssc_tfmr = ssc_readl(ssc_p->ssc->regs, TFMR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-20 04:03:36 +03:00
|
|
|
static int atmel_ssc_resume(struct snd_soc_component *component)
|
2008-10-03 18:57:50 +04:00
|
|
|
{
|
|
|
|
struct atmel_ssc_info *ssc_p;
|
2020-01-20 04:03:36 +03:00
|
|
|
struct platform_device *pdev = to_platform_device(component->dev);
|
2008-10-03 18:57:50 +04:00
|
|
|
u32 cr;
|
|
|
|
|
2020-01-20 04:03:36 +03:00
|
|
|
if (!component->active)
|
2008-10-03 18:57:50 +04:00
|
|
|
return 0;
|
|
|
|
|
2016-03-02 14:15:25 +03:00
|
|
|
ssc_p = &ssc_info[pdev->id];
|
2008-10-03 18:57:50 +04:00
|
|
|
|
|
|
|
/* restore SSC register settings */
|
|
|
|
ssc_writel(ssc_p->ssc->regs, TFMR, ssc_p->ssc_state.ssc_tfmr);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, TCMR, ssc_p->ssc_state.ssc_tcmr);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, RFMR, ssc_p->ssc_state.ssc_rfmr);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, RCMR, ssc_p->ssc_state.ssc_rcmr);
|
|
|
|
ssc_writel(ssc_p->ssc->regs, CMR, ssc_p->ssc_state.ssc_cmr);
|
|
|
|
|
|
|
|
/* re-enable interrupts */
|
|
|
|
ssc_writel(ssc_p->ssc->regs, IER, ssc_p->ssc_state.ssc_imr);
|
|
|
|
|
2011-03-31 05:57:33 +04:00
|
|
|
/* Re-enable receive and transmit as appropriate */
|
2008-10-03 18:57:50 +04:00
|
|
|
cr = 0;
|
|
|
|
cr |=
|
|
|
|
(ssc_p->ssc_state.ssc_sr & SSC_BIT(SR_RXEN)) ? SSC_BIT(CR_RXEN) : 0;
|
|
|
|
cr |=
|
|
|
|
(ssc_p->ssc_state.ssc_sr & SSC_BIT(SR_TXEN)) ? SSC_BIT(CR_TXEN) : 0;
|
|
|
|
ssc_writel(ssc_p->ssc->regs, CR, cr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else /* CONFIG_PM */
|
|
|
|
# define atmel_ssc_suspend NULL
|
|
|
|
# define atmel_ssc_resume NULL
|
|
|
|
#endif /* CONFIG_PM */
|
|
|
|
|
|
|
|
#define ATMEL_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
|
|
|
|
SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
|
|
|
|
|
2011-11-23 14:40:40 +04:00
|
|
|
static const struct snd_soc_dai_ops atmel_ssc_dai_ops = {
|
2009-03-03 04:41:00 +03:00
|
|
|
.startup = atmel_ssc_startup,
|
|
|
|
.shutdown = atmel_ssc_shutdown,
|
|
|
|
.prepare = atmel_ssc_prepare,
|
2013-12-04 06:37:03 +04:00
|
|
|
.trigger = atmel_ssc_trigger,
|
2009-03-03 04:41:00 +03:00
|
|
|
.hw_params = atmel_ssc_hw_params,
|
|
|
|
.set_fmt = atmel_ssc_set_dai_fmt,
|
|
|
|
.set_clkdiv = atmel_ssc_set_dai_clkdiv,
|
|
|
|
};
|
|
|
|
|
2012-11-14 14:09:09 +04:00
|
|
|
static struct snd_soc_dai_driver atmel_ssc_dai = {
|
2008-10-03 18:57:50 +04:00
|
|
|
.playback = {
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2015-02-09 18:08:25 +03:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
|
|
|
.rate_min = 8000,
|
|
|
|
.rate_max = 384000,
|
2008-10-03 18:57:50 +04:00
|
|
|
.formats = ATMEL_SSC_FORMATS,},
|
|
|
|
.capture = {
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2015-02-09 18:08:25 +03:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
|
|
|
.rate_min = 8000,
|
|
|
|
.rate_max = 384000,
|
2008-10-03 18:57:50 +04:00
|
|
|
.formats = ATMEL_SSC_FORMATS,},
|
2009-03-03 04:41:00 +03:00
|
|
|
.ops = &atmel_ssc_dai_ops,
|
2008-10-03 18:57:50 +04:00
|
|
|
};
|
|
|
|
|
2013-03-21 14:28:24 +04:00
|
|
|
static const struct snd_soc_component_driver atmel_ssc_component = {
|
|
|
|
.name = "atmel-ssc",
|
2020-01-20 04:03:36 +03:00
|
|
|
.suspend = atmel_ssc_suspend,
|
|
|
|
.resume = atmel_ssc_resume,
|
2013-03-21 14:28:24 +04:00
|
|
|
};
|
|
|
|
|
2012-11-14 14:09:09 +04:00
|
|
|
static int asoc_ssc_init(struct device *dev)
|
2010-03-17 23:15:21 +03:00
|
|
|
{
|
2018-04-19 17:06:31 +03:00
|
|
|
struct ssc_device *ssc = dev_get_drvdata(dev);
|
2012-11-14 14:09:09 +04:00
|
|
|
int ret;
|
|
|
|
|
2018-09-07 04:00:15 +03:00
|
|
|
ret = devm_snd_soc_register_component(dev, &atmel_ssc_component,
|
2013-03-21 14:28:24 +04:00
|
|
|
&atmel_ssc_dai, 1);
|
2012-11-14 14:09:09 +04:00
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "Could not register DAI: %d\n", ret);
|
2018-09-07 04:00:15 +03:00
|
|
|
return ret;
|
2012-11-14 14:09:09 +04:00
|
|
|
}
|
|
|
|
|
2012-11-28 07:46:13 +04:00
|
|
|
if (ssc->pdata->use_dma)
|
|
|
|
ret = atmel_pcm_dma_platform_register(dev);
|
|
|
|
else
|
|
|
|
ret = atmel_pcm_pdc_platform_register(dev);
|
|
|
|
|
2012-11-14 14:09:09 +04:00
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "Could not register PCM: %d\n", ret);
|
2018-09-07 04:00:15 +03:00
|
|
|
return ret;
|
2013-10-09 02:55:45 +04:00
|
|
|
}
|
2010-03-17 23:15:21 +03:00
|
|
|
|
|
|
|
return 0;
|
2012-11-14 14:09:09 +04:00
|
|
|
}
|
2010-03-17 23:15:21 +03:00
|
|
|
|
2010-08-18 19:29:37 +04:00
|
|
|
/**
|
|
|
|
* atmel_ssc_set_audio - Allocate the specified SSC for audio use.
|
|
|
|
*/
|
|
|
|
int atmel_ssc_set_audio(int ssc_id)
|
|
|
|
{
|
|
|
|
struct ssc_device *ssc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* If we can grab the SSC briefly to parent the DAI device off it */
|
|
|
|
ssc = ssc_request(ssc_id);
|
2012-11-14 14:09:09 +04:00
|
|
|
if (IS_ERR(ssc)) {
|
|
|
|
pr_err("Unable to parent ASoC SSC DAI on SSC: %ld\n",
|
2010-08-18 19:29:37 +04:00
|
|
|
PTR_ERR(ssc));
|
2012-11-14 14:09:09 +04:00
|
|
|
return PTR_ERR(ssc);
|
|
|
|
} else {
|
|
|
|
ssc_info[ssc_id].ssc = ssc;
|
2011-06-02 01:59:10 +04:00
|
|
|
}
|
2010-08-18 19:29:37 +04:00
|
|
|
|
2012-11-14 14:09:09 +04:00
|
|
|
ret = asoc_ssc_init(&ssc->pdev->dev);
|
2010-08-18 19:29:37 +04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(atmel_ssc_set_audio);
|
|
|
|
|
2012-11-14 14:09:09 +04:00
|
|
|
void atmel_ssc_put_audio(int ssc_id)
|
|
|
|
{
|
|
|
|
struct ssc_device *ssc = ssc_info[ssc_id].ssc;
|
|
|
|
|
2013-01-31 07:53:39 +04:00
|
|
|
ssc_free(ssc);
|
2012-11-14 14:09:09 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(atmel_ssc_put_audio);
|
2008-12-03 22:26:35 +03:00
|
|
|
|
2008-10-03 18:57:50 +04:00
|
|
|
/* Module information */
|
|
|
|
MODULE_AUTHOR("Sedji Gaouaou, sedji.gaouaou@atmel.com, www.atmel.com");
|
|
|
|
MODULE_DESCRIPTION("ATMEL SSC ASoC Interface");
|
|
|
|
MODULE_LICENSE("GPL");
|