2013-07-22 04:36:35 +00:00
|
|
|
/*
|
2014-03-04 04:51:21 +00:00
|
|
|
* Renesas R-Car SRC support
|
2013-07-22 04:36:35 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Renesas Solutions Corp.
|
|
|
|
* Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include "rsnd.h"
|
|
|
|
|
2014-05-23 06:25:43 +00:00
|
|
|
#define SRC_NAME "src"
|
|
|
|
|
2015-01-08 01:52:36 +00:00
|
|
|
/* SRCx_STATUS */
|
|
|
|
#define OUF_SRCO ((1 << 12) | (1 << 13))
|
|
|
|
#define OUF_SRCI ((1 << 9) | (1 << 8))
|
|
|
|
|
|
|
|
/* SCU_SYSTEM_STATUS0/1 */
|
|
|
|
#define OUF_SRC(id) ((1 << (id + 16)) | (1 << id))
|
|
|
|
|
2014-03-04 04:51:21 +00:00
|
|
|
struct rsnd_src {
|
2013-07-22 04:36:35 +00:00
|
|
|
struct rsnd_mod mod;
|
2015-10-26 08:42:25 +00:00
|
|
|
struct rsnd_mod *dma;
|
2015-04-01 04:15:16 +00:00
|
|
|
struct rsnd_kctrl_cfg_s sen; /* sync convert enable */
|
|
|
|
struct rsnd_kctrl_cfg_s sync; /* sync convert */
|
2015-03-26 04:02:51 +00:00
|
|
|
u32 convert_rate; /* sampling rate convert */
|
2015-01-08 01:52:36 +00:00
|
|
|
int err;
|
2015-11-10 05:11:55 +00:00
|
|
|
int irq;
|
2013-07-22 04:36:35 +00:00
|
|
|
};
|
|
|
|
|
2014-03-04 04:51:21 +00:00
|
|
|
#define RSND_SRC_NAME_SIZE 16
|
2013-07-29 01:59:12 +00:00
|
|
|
|
2015-11-10 05:11:55 +00:00
|
|
|
#define rsnd_src_get(priv, id) ((struct rsnd_src *)(priv->src) + id)
|
2015-10-26 08:38:26 +00:00
|
|
|
#define rsnd_src_to_dma(src) ((src)->dma)
|
2015-07-15 07:11:21 +00:00
|
|
|
#define rsnd_src_nr(priv) ((priv)->src_nr)
|
2015-04-01 04:15:16 +00:00
|
|
|
#define rsnd_enable_sync_convert(src) ((src)->sen.val)
|
2015-02-20 10:30:22 +00:00
|
|
|
|
2014-03-04 04:51:21 +00:00
|
|
|
#define rsnd_mod_to_src(_mod) \
|
|
|
|
container_of((_mod), struct rsnd_src, mod)
|
2014-01-24 02:40:47 +00:00
|
|
|
|
2014-03-04 04:51:21 +00:00
|
|
|
#define for_each_rsnd_src(pos, priv, i) \
|
2014-01-24 02:40:47 +00:00
|
|
|
for ((i) = 0; \
|
2014-03-04 04:51:21 +00:00
|
|
|
((i) < rsnd_src_nr(priv)) && \
|
|
|
|
((pos) = (struct rsnd_src *)(priv)->src + i); \
|
2014-01-24 02:40:47 +00:00
|
|
|
i++)
|
|
|
|
|
|
|
|
|
2013-12-20 03:28:51 +00:00
|
|
|
/*
|
|
|
|
* image of SRC (Sampling Rate Converter)
|
|
|
|
*
|
|
|
|
* 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
|
|
|
|
* 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
|
|
|
|
* 44.1kHz <-> +-----+ +-----+ +-------+
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
*/
|
2013-07-29 01:59:12 +00:00
|
|
|
|
2014-01-24 02:40:41 +00:00
|
|
|
/*
|
2014-03-04 04:51:21 +00:00
|
|
|
* src.c is caring...
|
2014-01-24 02:40:41 +00:00
|
|
|
*
|
|
|
|
* Gen1
|
|
|
|
*
|
|
|
|
* [mem] -> [SRU] -> [SSI]
|
|
|
|
* |--------|
|
|
|
|
*
|
|
|
|
* Gen2
|
|
|
|
*
|
2014-03-04 04:51:21 +00:00
|
|
|
* [mem] -> [SRC] -> [SSIU] -> [SSI]
|
2014-01-24 02:40:41 +00:00
|
|
|
* |-----------------|
|
|
|
|
*/
|
|
|
|
|
2015-07-15 07:12:18 +00:00
|
|
|
static void rsnd_src_soft_reset(struct rsnd_mod *mod)
|
|
|
|
{
|
|
|
|
rsnd_mod_write(mod, SRC_SWRSR, 0);
|
|
|
|
rsnd_mod_write(mod, SRC_SWRSR, 1);
|
|
|
|
}
|
|
|
|
|
2015-06-15 06:26:25 +00:00
|
|
|
static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_mod *mod)
|
ASoC: rsnd: 1st DMAC dma-names cares subnode
Renesas R-Car sound (= rsnd) needs 2 DMAC which are called as
Audio DMAC (= 1st DMAC) and Audio DMAC peri peri (2nd DMAC).
And rsnd had assumed that 1st / 2nd DMACs are implemented as DMAEngine.
But, in result of DMA ML discussion, 2nd DMAC was concluded that it is
not a general purpose DMAC (2nd DMAC is for Device to Device inside
sound system). Additionally, current DMAEngine can't support Device to
Device, and we don't have correct DT bindings for it at this point.
So the easiest solution for it is that move it from DMAEngine to rsnd
driver.
dma-names on DT was implemented as no difference between 1st / 2nd
DMAC's, since rsnd had assumed that both DMACs are implemented as
DMAEngine. That style was "src_dst". But now, 2nd DMAC was implemented
as non DMAEngine, and it doesn't need dma-names anymore. So, this
dma-names rule is no longer needed.
And additionally, dma-names was assumed that it has all
(= SSI/SSIU/SRC/DVC) nodes under sound node.
In upstream code, no SoC/platform is supporting DMA for rsnd driver yet.
This means there is no compatible issue if this patch changes
dma-names's rule of DT.
This patch assumes dma-names for 1st DMAC are tx/rx base, and listed
in each SSI/SRC/DVC subnode
ex)
rcar_sound,dvc {
dvc0: dvc@0 {
dmas = <&audma0 0xbc>;
dma-names = "tx";
};
...
rcar_sound,src {
src0: src@0 {
...
dmas = <&audma0 0x85>, <&audma1 0x9a>;
dma-names = "rx", "tx";
};
...
rcar_sound,ssi {
ssi0: ssi@0 {
...
dmas = <&audma0 0x01>, <&audma1 0x02>, <&audma0 0x15>, <&audma1 0x16>;
dma-names = "rx", "tx", "rxu", "txu";
};
...
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-02-20 10:31:23 +00:00
|
|
|
{
|
|
|
|
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
|
|
|
int is_play = rsnd_io_is_play(io);
|
|
|
|
|
|
|
|
return rsnd_dma_request_channel(rsnd_src_of_node(priv),
|
|
|
|
mod,
|
|
|
|
is_play ? "rx" : "tx");
|
|
|
|
}
|
|
|
|
|
2015-06-15 06:27:13 +00:00
|
|
|
static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_src *src)
|
2015-04-01 04:15:16 +00:00
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
|
|
|
u32 convert_rate;
|
|
|
|
|
|
|
|
if (!runtime)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!rsnd_enable_sync_convert(src))
|
|
|
|
return src->convert_rate;
|
|
|
|
|
|
|
|
convert_rate = src->sync.val;
|
|
|
|
|
|
|
|
if (!convert_rate)
|
|
|
|
convert_rate = src->convert_rate;
|
|
|
|
|
|
|
|
if (!convert_rate)
|
|
|
|
convert_rate = runtime->rate;
|
|
|
|
|
|
|
|
return convert_rate;
|
|
|
|
}
|
|
|
|
|
2014-03-04 04:51:21 +00:00
|
|
|
unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
|
2014-03-03 07:43:03 +00:00
|
|
|
struct rsnd_dai_stream *io,
|
2014-01-24 02:41:36 +00:00
|
|
|
struct snd_pcm_runtime *runtime)
|
|
|
|
{
|
2014-03-24 04:23:42 +00:00
|
|
|
struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
|
2014-03-04 04:51:21 +00:00
|
|
|
struct rsnd_src *src;
|
2014-03-24 04:23:42 +00:00
|
|
|
unsigned int rate = 0;
|
2014-01-24 02:41:36 +00:00
|
|
|
|
2014-03-24 04:23:42 +00:00
|
|
|
if (src_mod) {
|
|
|
|
src = rsnd_mod_to_src(src_mod);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return convert rate if SRC is used,
|
|
|
|
* otherwise, return runtime->rate as usual
|
|
|
|
*/
|
2015-06-15 06:27:13 +00:00
|
|
|
rate = rsnd_src_convert_rate(io, src);
|
2014-03-24 04:23:42 +00:00
|
|
|
}
|
2014-01-24 02:41:36 +00:00
|
|
|
|
|
|
|
if (!rate)
|
|
|
|
rate = runtime->rate;
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
2015-03-26 04:02:51 +00:00
|
|
|
static int rsnd_src_hw_params(struct rsnd_mod *mod,
|
2015-06-15 06:25:20 +00:00
|
|
|
struct rsnd_dai_stream *io,
|
2015-03-26 04:02:51 +00:00
|
|
|
struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *fe_params)
|
|
|
|
{
|
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
struct snd_soc_pcm_runtime *fe = substream->private_data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SRC assumes that it is used under DPCM if user want to use
|
|
|
|
* sampling rate convert. Then, SRC should be FE.
|
|
|
|
* And then, this function will be called *after* BE settings.
|
|
|
|
* this means, each BE already has fixuped hw_params.
|
|
|
|
* see
|
|
|
|
* dpcm_fe_dai_hw_params()
|
|
|
|
* dpcm_be_dai_hw_params()
|
|
|
|
*/
|
|
|
|
if (fe->dai_link->dynamic) {
|
|
|
|
int stream = substream->stream;
|
|
|
|
struct snd_soc_dpcm *dpcm;
|
|
|
|
struct snd_pcm_hw_params *be_params;
|
|
|
|
|
|
|
|
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
|
|
|
|
be_params = &dpcm->hw_params;
|
|
|
|
|
|
|
|
if (params_rate(fe_params) != params_rate(be_params))
|
|
|
|
src->convert_rate = params_rate(be_params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_mod *mod)
|
2014-01-24 02:41:36 +00:00
|
|
|
{
|
2015-11-10 05:10:48 +00:00
|
|
|
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
|
|
|
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
2014-03-04 04:51:21 +00:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
2015-11-10 05:10:48 +00:00
|
|
|
u32 convert_rate = rsnd_src_convert_rate(io, src);
|
|
|
|
u32 ifscr, fsrate, adinr;
|
|
|
|
u32 cr, route;
|
|
|
|
u32 bsdsr, bsisr;
|
|
|
|
uint ratio;
|
2014-01-24 02:41:36 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
if (!runtime)
|
|
|
|
return;
|
2015-04-01 04:15:16 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
/* 6 - 1/6 are very enough ratio for SRC_BSDSR */
|
|
|
|
if (!convert_rate)
|
|
|
|
ratio = 0;
|
|
|
|
else if (convert_rate > runtime->rate)
|
|
|
|
ratio = 100 * convert_rate / runtime->rate;
|
|
|
|
else
|
|
|
|
ratio = 100 * runtime->rate / convert_rate;
|
2014-01-24 02:41:36 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
if (ratio > 600) {
|
|
|
|
dev_err(dev, "FSO/FSI ratio error\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-01-24 02:41:36 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
/*
|
|
|
|
* SRC_ADINR
|
|
|
|
*/
|
|
|
|
adinr = rsnd_get_adinr_bit(mod, io);
|
2014-01-24 02:41:36 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
/*
|
|
|
|
* SRC_IFSCR / SRC_IFSVR
|
|
|
|
*/
|
|
|
|
ifscr = 0;
|
|
|
|
fsrate = 0;
|
|
|
|
if (convert_rate) {
|
|
|
|
ifscr = 1;
|
|
|
|
fsrate = 0x0400000 / convert_rate * runtime->rate;
|
|
|
|
}
|
2015-01-08 01:52:36 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
/*
|
|
|
|
* SRC_SRCCR / SRC_ROUTE_MODE0
|
|
|
|
*/
|
|
|
|
cr = 0x00011110;
|
|
|
|
route = 0x0;
|
|
|
|
if (convert_rate) {
|
|
|
|
route = 0x1;
|
2015-03-26 04:02:51 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
if (rsnd_enable_sync_convert(src)) {
|
|
|
|
cr |= 0x1;
|
|
|
|
route |= rsnd_io_is_play(io) ?
|
|
|
|
(0x1 << 24) : (0x1 << 25);
|
|
|
|
}
|
|
|
|
}
|
2015-04-01 04:15:16 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
/*
|
|
|
|
* SRC_BSDSR / SRC_BSISR
|
|
|
|
*/
|
|
|
|
switch (rsnd_mod_id(mod)) {
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
case 8:
|
|
|
|
bsdsr = 0x02400000; /* 6 - 1/6 */
|
|
|
|
bsisr = 0x00100060; /* 6 - 1/6 */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bsdsr = 0x01800000; /* 6 - 1/6 */
|
|
|
|
bsisr = 0x00100060 ;/* 6 - 1/6 */
|
|
|
|
break;
|
|
|
|
}
|
2014-01-24 02:41:36 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_mod_write(mod, SRC_SRCIR, 1); /* initialize */
|
|
|
|
rsnd_mod_write(mod, SRC_ADINR, adinr);
|
|
|
|
rsnd_mod_write(mod, SRC_IFSCR, ifscr);
|
|
|
|
rsnd_mod_write(mod, SRC_IFSVR, fsrate);
|
|
|
|
rsnd_mod_write(mod, SRC_SRCCR, cr);
|
|
|
|
rsnd_mod_write(mod, SRC_BSDSR, bsdsr);
|
|
|
|
rsnd_mod_write(mod, SRC_BSISR, bsisr);
|
|
|
|
rsnd_mod_write(mod, SRC_SRCIR, 0); /* cancel initialize */
|
2014-01-24 02:41:36 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_mod_write(mod, SRC_ROUTE_MODE0, route);
|
|
|
|
rsnd_mod_write(mod, SRC_BUSIF_MODE, 1);
|
|
|
|
rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
|
2014-01-24 02:41:36 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
if (convert_rate)
|
|
|
|
rsnd_adg_set_convert_clk_gen2(mod, io,
|
|
|
|
runtime->rate,
|
|
|
|
convert_rate);
|
|
|
|
else
|
|
|
|
rsnd_adg_set_convert_timing_gen2(mod, io);
|
2014-01-24 02:41:36 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
#define rsnd_src_irq_enable(mod) rsnd_src_irq_ctrol(mod, 1)
|
|
|
|
#define rsnd_src_irq_disable(mod) rsnd_src_irq_ctrol(mod, 0)
|
|
|
|
static void rsnd_src_irq_ctrol(struct rsnd_mod *mod, int enable)
|
2015-01-08 01:52:36 +00:00
|
|
|
{
|
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
u32 sys_int_val, int_val, sys_int_mask;
|
2015-11-10 05:11:55 +00:00
|
|
|
int irq = src->irq;
|
2015-01-08 01:52:36 +00:00
|
|
|
int id = rsnd_mod_id(mod);
|
|
|
|
|
|
|
|
sys_int_val =
|
|
|
|
sys_int_mask = OUF_SRC(id);
|
|
|
|
int_val = 0x3300;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IRQ is not supported on non-DT
|
|
|
|
* see
|
2015-11-10 05:10:48 +00:00
|
|
|
* rsnd_src_probe_()
|
2015-01-08 01:52:36 +00:00
|
|
|
*/
|
|
|
|
if ((irq <= 0) || !enable) {
|
|
|
|
sys_int_val = 0;
|
|
|
|
int_val = 0;
|
|
|
|
}
|
|
|
|
|
2015-07-15 07:10:22 +00:00
|
|
|
/*
|
|
|
|
* WORKAROUND
|
|
|
|
*
|
|
|
|
* ignore over flow error when rsnd_enable_sync_convert()
|
|
|
|
*/
|
|
|
|
if (rsnd_enable_sync_convert(src))
|
|
|
|
sys_int_val = sys_int_val & 0xffff;
|
|
|
|
|
2015-01-08 01:52:36 +00:00
|
|
|
rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val);
|
|
|
|
rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val);
|
|
|
|
rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val);
|
|
|
|
}
|
|
|
|
|
2015-11-26 11:11:03 +00:00
|
|
|
static void rsnd_src_status_clear(struct rsnd_mod *mod)
|
2015-01-08 01:52:36 +00:00
|
|
|
{
|
|
|
|
u32 val = OUF_SRC(rsnd_mod_id(mod));
|
|
|
|
|
|
|
|
rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val);
|
|
|
|
rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val);
|
|
|
|
}
|
|
|
|
|
2015-11-26 11:11:03 +00:00
|
|
|
static bool rsnd_src_record_error(struct rsnd_mod *mod)
|
2015-01-08 01:52:36 +00:00
|
|
|
{
|
2015-07-15 07:10:22 +00:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
u32 val0, val1;
|
2015-01-08 01:52:36 +00:00
|
|
|
bool ret = false;
|
|
|
|
|
2015-07-15 07:10:22 +00:00
|
|
|
val0 = val1 = OUF_SRC(rsnd_mod_id(mod));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WORKAROUND
|
|
|
|
*
|
|
|
|
* ignore over flow error when rsnd_enable_sync_convert()
|
|
|
|
*/
|
|
|
|
if (rsnd_enable_sync_convert(src))
|
|
|
|
val0 = val0 & 0xffff;
|
|
|
|
|
|
|
|
if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val0) ||
|
|
|
|
(rsnd_mod_read(mod, SCU_SYS_STATUS1) & val1)) {
|
2015-01-08 01:52:36 +00:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
|
|
|
|
src->err++;
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
static int rsnd_src_start(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2015-01-08 01:52:36 +00:00
|
|
|
{
|
2015-07-15 07:10:22 +00:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WORKAROUND
|
|
|
|
*
|
|
|
|
* Enable SRC output if you want to use sync convert together with DVC
|
|
|
|
*/
|
|
|
|
val = (rsnd_io_to_mod_dvc(io) && !rsnd_enable_sync_convert(src)) ?
|
|
|
|
0x01 : 0x11;
|
2015-01-08 01:52:36 +00:00
|
|
|
|
|
|
|
rsnd_mod_write(mod, SRC_CTRL, val);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
static int rsnd_src_stop(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2015-01-08 01:52:36 +00:00
|
|
|
{
|
2015-10-26 08:40:59 +00:00
|
|
|
/*
|
|
|
|
* stop SRC output only
|
2015-11-10 05:10:48 +00:00
|
|
|
* see rsnd_src_quit
|
2015-10-26 08:40:59 +00:00
|
|
|
*/
|
|
|
|
rsnd_mod_write(mod, SRC_CTRL, 0x01);
|
2015-01-08 01:52:36 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rsnd_src_init(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
|
|
|
{
|
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
2015-01-08 01:52:36 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_mod_power_on(mod);
|
|
|
|
|
|
|
|
rsnd_src_soft_reset(mod);
|
|
|
|
|
|
|
|
rsnd_src_set_convert_rate(io, mod);
|
|
|
|
|
2015-11-26 11:11:03 +00:00
|
|
|
rsnd_src_status_clear(mod);
|
2015-11-10 05:10:48 +00:00
|
|
|
|
|
|
|
rsnd_src_irq_enable(mod);
|
|
|
|
|
|
|
|
src->err = 0;
|
|
|
|
|
|
|
|
/* reset sync convert_rate */
|
|
|
|
src->sync.val = 0;
|
|
|
|
|
|
|
|
return 0;
|
2015-01-08 01:52:36 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
static int rsnd_src_quit(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2015-10-26 08:40:59 +00:00
|
|
|
{
|
2015-11-10 05:10:48 +00:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
|
|
|
|
|
|
|
rsnd_src_irq_disable(mod);
|
|
|
|
|
2015-10-26 08:40:59 +00:00
|
|
|
/* stop both out/in */
|
|
|
|
rsnd_mod_write(mod, SRC_CTRL, 0);
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_mod_power_off(mod);
|
|
|
|
|
|
|
|
if (src->err)
|
|
|
|
dev_warn(dev, "%s[%d] under/over flow err = %d\n",
|
|
|
|
rsnd_mod_name(mod), rsnd_mod_id(mod), src->err);
|
|
|
|
|
|
|
|
src->convert_rate = 0;
|
|
|
|
|
|
|
|
/* reset sync convert_rate */
|
|
|
|
src->sync.val = 0;
|
|
|
|
|
|
|
|
return 0;
|
2015-10-26 08:40:59 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
static void __rsnd_src_interrupt(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io)
|
2015-01-08 01:52:36 +00:00
|
|
|
{
|
2015-05-21 03:50:23 +00:00
|
|
|
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
2015-10-26 08:41:36 +00:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
2015-05-21 03:50:23 +00:00
|
|
|
|
|
|
|
spin_lock(&priv->lock);
|
2015-01-08 01:52:36 +00:00
|
|
|
|
2015-05-21 03:50:23 +00:00
|
|
|
/* ignore all cases if not working */
|
2015-06-15 06:27:47 +00:00
|
|
|
if (!rsnd_io_is_working(io))
|
2015-11-10 05:10:48 +00:00
|
|
|
goto rsnd_src_interrupt_out;
|
2015-01-08 01:52:36 +00:00
|
|
|
|
2015-11-26 11:11:03 +00:00
|
|
|
if (rsnd_src_record_error(mod)) {
|
2015-01-08 01:52:36 +00:00
|
|
|
|
|
|
|
dev_dbg(dev, "%s[%d] restart\n",
|
|
|
|
rsnd_mod_name(mod), rsnd_mod_id(mod));
|
2015-03-19 04:14:04 +00:00
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_src_stop(mod, io, priv);
|
|
|
|
rsnd_src_start(mod, io, priv);
|
2015-10-26 08:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (src->err > 1024) {
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_src_irq_disable(mod);
|
2015-10-26 08:41:36 +00:00
|
|
|
|
|
|
|
dev_warn(dev, "no more %s[%d] restart\n",
|
|
|
|
rsnd_mod_name(mod), rsnd_mod_id(mod));
|
2015-01-08 01:52:36 +00:00
|
|
|
}
|
2015-06-15 06:27:13 +00:00
|
|
|
|
2015-11-26 11:11:03 +00:00
|
|
|
rsnd_src_status_clear(mod);
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_src_interrupt_out:
|
2015-11-26 11:11:03 +00:00
|
|
|
|
2015-05-21 03:50:23 +00:00
|
|
|
spin_unlock(&priv->lock);
|
2015-06-15 06:27:13 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
static irqreturn_t rsnd_src_interrupt(int irq, void *data)
|
2015-06-15 06:27:13 +00:00
|
|
|
{
|
|
|
|
struct rsnd_mod *mod = data;
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_mod_interrupt(mod, __rsnd_src_interrupt);
|
2015-01-08 01:52:36 +00:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
static int rsnd_src_probe_(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2014-03-04 04:50:41 +00:00
|
|
|
{
|
2014-03-04 04:51:21 +00:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
2014-03-04 04:50:41 +00:00
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
2015-11-10 05:11:55 +00:00
|
|
|
int irq = src->irq;
|
2014-03-04 04:50:41 +00:00
|
|
|
int ret;
|
|
|
|
|
2015-01-08 01:52:36 +00:00
|
|
|
if (irq > 0) {
|
|
|
|
/*
|
|
|
|
* IRQ is not supported on non-DT
|
|
|
|
* see
|
2015-11-10 05:10:48 +00:00
|
|
|
* rsnd_src_irq_enable()
|
2015-01-08 01:52:36 +00:00
|
|
|
*/
|
|
|
|
ret = devm_request_irq(dev, irq,
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_src_interrupt,
|
2015-01-08 01:52:36 +00:00
|
|
|
IRQF_SHARED,
|
|
|
|
dev_name(dev), mod);
|
|
|
|
if (ret)
|
2015-03-26 04:02:32 +00:00
|
|
|
return ret;
|
2015-01-08 01:52:36 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 05:11:55 +00:00
|
|
|
src->dma = rsnd_dma_attach(io, mod, 0);
|
2015-10-26 08:38:26 +00:00
|
|
|
if (IS_ERR(src->dma))
|
|
|
|
return PTR_ERR(src->dma);
|
2014-05-23 06:25:43 +00:00
|
|
|
|
2014-03-04 04:50:41 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
static int rsnd_src_pcm_new(struct rsnd_mod *mod,
|
2015-06-15 06:25:20 +00:00
|
|
|
struct rsnd_dai_stream *io,
|
2015-04-01 04:15:16 +00:00
|
|
|
struct snd_soc_pcm_runtime *rtd)
|
|
|
|
{
|
|
|
|
struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
|
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* enable SRC sync convert if possible
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SRC sync convert needs clock master
|
|
|
|
*/
|
|
|
|
if (!rsnd_rdai_is_clk_master(rdai))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* enable sync convert
|
|
|
|
*/
|
2015-06-15 06:27:28 +00:00
|
|
|
ret = rsnd_kctrl_new_s(mod, io, rtd,
|
2015-04-01 04:15:16 +00:00
|
|
|
rsnd_io_is_play(io) ?
|
|
|
|
"SRC Out Rate Switch" :
|
|
|
|
"SRC In Rate Switch",
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_src_set_convert_rate,
|
2015-04-01 04:15:16 +00:00
|
|
|
&src->sen, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2015-06-15 06:27:28 +00:00
|
|
|
ret = rsnd_kctrl_new_s(mod, io, rtd,
|
2015-04-01 04:15:16 +00:00
|
|
|
rsnd_io_is_play(io) ?
|
|
|
|
"SRC Out Rate" :
|
|
|
|
"SRC In Rate",
|
2015-11-10 05:10:48 +00:00
|
|
|
rsnd_src_set_convert_rate,
|
2015-04-01 04:15:16 +00:00
|
|
|
&src->sync, 192000);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-10 05:10:48 +00:00
|
|
|
static struct rsnd_mod_ops rsnd_src_ops = {
|
2014-05-23 06:25:43 +00:00
|
|
|
.name = SRC_NAME,
|
ASoC: rsnd: 1st DMAC dma-names cares subnode
Renesas R-Car sound (= rsnd) needs 2 DMAC which are called as
Audio DMAC (= 1st DMAC) and Audio DMAC peri peri (2nd DMAC).
And rsnd had assumed that 1st / 2nd DMACs are implemented as DMAEngine.
But, in result of DMA ML discussion, 2nd DMAC was concluded that it is
not a general purpose DMAC (2nd DMAC is for Device to Device inside
sound system). Additionally, current DMAEngine can't support Device to
Device, and we don't have correct DT bindings for it at this point.
So the easiest solution for it is that move it from DMAEngine to rsnd
driver.
dma-names on DT was implemented as no difference between 1st / 2nd
DMAC's, since rsnd had assumed that both DMACs are implemented as
DMAEngine. That style was "src_dst". But now, 2nd DMAC was implemented
as non DMAEngine, and it doesn't need dma-names anymore. So, this
dma-names rule is no longer needed.
And additionally, dma-names was assumed that it has all
(= SSI/SSIU/SRC/DVC) nodes under sound node.
In upstream code, no SoC/platform is supporting DMA for rsnd driver yet.
This means there is no compatible issue if this patch changes
dma-names's rule of DT.
This patch assumes dma-names for 1st DMAC are tx/rx base, and listed
in each SSI/SRC/DVC subnode
ex)
rcar_sound,dvc {
dvc0: dvc@0 {
dmas = <&audma0 0xbc>;
dma-names = "tx";
};
...
rcar_sound,src {
src0: src@0 {
...
dmas = <&audma0 0x85>, <&audma1 0x9a>;
dma-names = "rx", "tx";
};
...
rcar_sound,ssi {
ssi0: ssi@0 {
...
dmas = <&audma0 0x01>, <&audma1 0x02>, <&audma0 0x15>, <&audma1 0x16>;
dma-names = "rx", "tx", "rxu", "txu";
};
...
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-02-20 10:31:23 +00:00
|
|
|
.dma_req = rsnd_src_dma_req,
|
2015-11-10 05:10:48 +00:00
|
|
|
.probe = rsnd_src_probe_,
|
|
|
|
.init = rsnd_src_init,
|
|
|
|
.quit = rsnd_src_quit,
|
|
|
|
.start = rsnd_src_start,
|
|
|
|
.stop = rsnd_src_stop,
|
2015-03-26 04:02:51 +00:00
|
|
|
.hw_params = rsnd_src_hw_params,
|
2015-11-10 05:10:48 +00:00
|
|
|
.pcm_new = rsnd_src_pcm_new,
|
2014-01-24 02:42:00 +00:00
|
|
|
};
|
|
|
|
|
2014-03-04 04:51:21 +00:00
|
|
|
struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
|
2013-07-22 04:36:35 +00:00
|
|
|
{
|
2014-03-04 04:51:21 +00:00
|
|
|
if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
|
2013-11-05 17:40:05 +00:00
|
|
|
id = 0;
|
2013-07-22 04:36:35 +00:00
|
|
|
|
2015-11-10 05:11:55 +00:00
|
|
|
return rsnd_mod_get(rsnd_src_get(priv, id));
|
2014-03-18 02:29:55 +00:00
|
|
|
}
|
|
|
|
|
2015-11-10 05:14:12 +00:00
|
|
|
int rsnd_src_probe(struct rsnd_priv *priv)
|
2013-07-22 04:36:35 +00:00
|
|
|
{
|
2015-11-10 05:11:55 +00:00
|
|
|
struct device_node *node;
|
|
|
|
struct device_node *np;
|
2013-07-22 04:36:35 +00:00
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
2014-03-04 04:51:21 +00:00
|
|
|
struct rsnd_src *src;
|
2013-12-20 03:28:51 +00:00
|
|
|
struct clk *clk;
|
2014-03-04 04:51:21 +00:00
|
|
|
char name[RSND_SRC_NAME_SIZE];
|
2015-03-26 04:02:09 +00:00
|
|
|
int i, nr, ret;
|
2013-07-22 04:36:35 +00:00
|
|
|
|
2015-11-10 05:09:52 +00:00
|
|
|
/* This driver doesn't support Gen1 at this point */
|
|
|
|
if (rsnd_is_gen1(priv))
|
|
|
|
return 0;
|
2014-05-23 06:25:37 +00:00
|
|
|
|
2015-11-10 05:11:55 +00:00
|
|
|
node = rsnd_src_of_node(priv);
|
|
|
|
if (!node)
|
|
|
|
return 0; /* not used is not error */
|
2014-03-18 02:29:55 +00:00
|
|
|
|
2015-11-10 05:11:55 +00:00
|
|
|
nr = of_get_child_count(node);
|
|
|
|
if (!nr) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2014-03-04 04:50:00 +00:00
|
|
|
|
2014-03-04 04:51:21 +00:00
|
|
|
src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL);
|
2015-11-10 05:11:55 +00:00
|
|
|
if (!src) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2013-07-22 04:36:35 +00:00
|
|
|
|
2014-03-04 04:51:21 +00:00
|
|
|
priv->src_nr = nr;
|
|
|
|
priv->src = src;
|
2013-07-22 04:36:35 +00:00
|
|
|
|
2015-11-10 05:11:55 +00:00
|
|
|
i = 0;
|
|
|
|
for_each_child_of_node(node, np) {
|
|
|
|
src = rsnd_src_get(priv, i);
|
|
|
|
|
2014-05-23 06:25:43 +00:00
|
|
|
snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
|
|
|
|
SRC_NAME, i);
|
2013-12-20 03:28:51 +00:00
|
|
|
|
2015-11-10 05:11:55 +00:00
|
|
|
src->irq = irq_of_parse_and_map(np, 0);
|
|
|
|
if (!src->irq) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2013-12-20 03:28:51 +00:00
|
|
|
|
2015-11-10 05:11:55 +00:00
|
|
|
clk = devm_clk_get(dev, name);
|
|
|
|
if (IS_ERR(clk)) {
|
|
|
|
ret = PTR_ERR(clk);
|
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2013-07-22 04:36:35 +00:00
|
|
|
|
2015-11-10 05:09:52 +00:00
|
|
|
ret = rsnd_mod_init(priv, rsnd_mod_get(src),
|
2015-11-10 05:10:48 +00:00
|
|
|
&rsnd_src_ops, clk, RSND_MOD_SRC, i);
|
2015-03-26 04:02:09 +00:00
|
|
|
if (ret)
|
2015-11-10 05:11:55 +00:00
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
|
|
|
|
i++;
|
2013-07-29 01:59:12 +00:00
|
|
|
}
|
2013-07-22 04:36:35 +00:00
|
|
|
|
2015-11-10 05:11:55 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
rsnd_src_probe_done:
|
|
|
|
of_node_put(node);
|
|
|
|
|
|
|
|
return ret;
|
2013-07-22 04:36:35 +00:00
|
|
|
}
|
2015-03-26 04:02:09 +00:00
|
|
|
|
2015-11-10 05:14:12 +00:00
|
|
|
void rsnd_src_remove(struct rsnd_priv *priv)
|
2015-03-26 04:02:09 +00:00
|
|
|
{
|
|
|
|
struct rsnd_src *src;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_rsnd_src(src, priv, i) {
|
2015-09-10 07:02:21 +00:00
|
|
|
rsnd_mod_quit(rsnd_mod_get(src));
|
2015-03-26 04:02:09 +00:00
|
|
|
}
|
|
|
|
}
|