2018-06-12 13:58:38 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//
|
|
|
|
// Renesas R-Car SRC support
|
|
|
|
//
|
|
|
|
// Copyright (C) 2013 Renesas Solutions Corp.
|
|
|
|
// Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
|
2018-02-13 10:08:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* you can enable below define if you don't need
|
|
|
|
* SSI interrupt status debug message when debugging
|
|
|
|
* see rsnd_dbg_irq_status()
|
|
|
|
*
|
|
|
|
* #define RSND_DEBUG_NO_IRQ_STATUS 1
|
|
|
|
*/
|
|
|
|
|
2013-07-22 12:36:35 +08:00
|
|
|
#include "rsnd.h"
|
|
|
|
|
2014-05-23 14:25:43 +08:00
|
|
|
#define SRC_NAME "src"
|
|
|
|
|
2015-01-08 09:52:36 +08:00
|
|
|
/* SCU_SYSTEM_STATUS0/1 */
|
|
|
|
#define OUF_SRC(id) ((1 << (id + 16)) | (1 << id))
|
|
|
|
|
2014-03-04 12:51:21 +08:00
|
|
|
struct rsnd_src {
|
2013-07-22 12:36:35 +08:00
|
|
|
struct rsnd_mod mod;
|
2015-10-26 16:42:25 +08:00
|
|
|
struct rsnd_mod *dma;
|
2015-04-01 12:15:16 +08:00
|
|
|
struct rsnd_kctrl_cfg_s sen; /* sync convert enable */
|
|
|
|
struct rsnd_kctrl_cfg_s sync; /* sync convert */
|
2015-03-26 12:02:51 +08:00
|
|
|
u32 convert_rate; /* sampling rate convert */
|
2015-11-10 13:11:55 +08:00
|
|
|
int irq;
|
2013-07-22 12:36:35 +08:00
|
|
|
};
|
|
|
|
|
2014-03-04 12:51:21 +08:00
|
|
|
#define RSND_SRC_NAME_SIZE 16
|
2013-07-29 09:59:12 +08:00
|
|
|
|
2015-11-10 13:11:55 +08:00
|
|
|
#define rsnd_src_get(priv, id) ((struct rsnd_src *)(priv->src) + id)
|
2015-07-15 15:11:21 +08:00
|
|
|
#define rsnd_src_nr(priv) ((priv)->src_nr)
|
2016-03-07 13:07:57 +08:00
|
|
|
#define rsnd_src_sync_is_enabled(mod) (rsnd_mod_to_src(mod)->sen.val)
|
2015-02-20 18:30:22 +08:00
|
|
|
|
2014-03-04 12:51:21 +08:00
|
|
|
#define rsnd_mod_to_src(_mod) \
|
|
|
|
container_of((_mod), struct rsnd_src, mod)
|
2014-01-24 10:40:47 +08:00
|
|
|
|
2014-03-04 12:51:21 +08:00
|
|
|
#define for_each_rsnd_src(pos, priv, i) \
|
2014-01-24 10:40:47 +08:00
|
|
|
for ((i) = 0; \
|
2014-03-04 12:51:21 +08:00
|
|
|
((i) < rsnd_src_nr(priv)) && \
|
|
|
|
((pos) = (struct rsnd_src *)(priv)->src + i); \
|
2014-01-24 10:40:47 +08:00
|
|
|
i++)
|
|
|
|
|
|
|
|
|
2013-12-20 11:28:51 +08:00
|
|
|
/*
|
|
|
|
* image of SRC (Sampling Rate Converter)
|
|
|
|
*
|
|
|
|
* 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
|
|
|
|
* 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
|
|
|
|
* 44.1kHz <-> +-----+ +-----+ +-------+
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
*/
|
2013-07-29 09:59:12 +08:00
|
|
|
|
2015-11-30 16:50:32 +08:00
|
|
|
static void rsnd_src_activation(struct rsnd_mod *mod)
|
2015-07-15 15:12:18 +08:00
|
|
|
{
|
|
|
|
rsnd_mod_write(mod, SRC_SWRSR, 0);
|
|
|
|
rsnd_mod_write(mod, SRC_SWRSR, 1);
|
|
|
|
}
|
|
|
|
|
2015-11-30 16:51:35 +08:00
|
|
|
static void rsnd_src_halt(struct rsnd_mod *mod)
|
|
|
|
{
|
|
|
|
rsnd_mod_write(mod, SRC_SRCIR, 1);
|
|
|
|
rsnd_mod_write(mod, SRC_SWRSR, 0);
|
|
|
|
}
|
|
|
|
|
2015-06-15 14:26:25 +08: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 18:31:23 +08: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 14:27:13 +08:00
|
|
|
static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io,
|
2016-03-07 13:07:29 +08:00
|
|
|
struct rsnd_mod *mod)
|
2015-04-01 12:15:16 +08:00
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
2016-03-07 13:07:29 +08:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
2015-04-01 12:15:16 +08:00
|
|
|
u32 convert_rate;
|
|
|
|
|
|
|
|
if (!runtime)
|
|
|
|
return 0;
|
|
|
|
|
2016-03-07 13:07:57 +08:00
|
|
|
if (!rsnd_src_sync_is_enabled(mod))
|
2015-04-01 12:15:16 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-03-07 13:08:33 +08:00
|
|
|
unsigned int rsnd_src_get_rate(struct rsnd_priv *priv,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
int is_in)
|
2014-01-24 10:41:36 +08:00
|
|
|
{
|
2014-03-24 12:23:42 +08:00
|
|
|
struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
|
2016-03-07 13:08:33 +08:00
|
|
|
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
2014-03-24 12:23:42 +08:00
|
|
|
unsigned int rate = 0;
|
2016-03-07 13:08:33 +08:00
|
|
|
int is_play = rsnd_io_is_play(io);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Playback
|
|
|
|
* runtime_rate -> [SRC] -> convert_rate
|
|
|
|
*
|
|
|
|
* Capture
|
|
|
|
* convert_rate -> [SRC] -> runtime_rate
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (is_play == is_in)
|
|
|
|
return runtime->rate;
|
2014-01-24 10:41:36 +08:00
|
|
|
|
2016-03-07 13:07:29 +08:00
|
|
|
/*
|
|
|
|
* return convert rate if SRC is used,
|
|
|
|
* otherwise, return runtime->rate as usual
|
|
|
|
*/
|
|
|
|
if (src_mod)
|
|
|
|
rate = rsnd_src_convert_rate(io, src_mod);
|
2014-01-24 10:41:36 +08:00
|
|
|
|
|
|
|
if (!rate)
|
|
|
|
rate = runtime->rate;
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
2015-03-26 12:02:51 +08:00
|
|
|
static int rsnd_src_hw_params(struct rsnd_mod *mod,
|
2015-06-15 14:25:20 +08:00
|
|
|
struct rsnd_dai_stream *io,
|
2015-03-26 12:02:51 +08: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()
|
|
|
|
*/
|
2017-04-06 15:24:36 +08:00
|
|
|
src->convert_rate = 0;
|
2015-03-26 12:02:51 +08:00
|
|
|
if (fe->dai_link->dynamic) {
|
|
|
|
int stream = substream->stream;
|
|
|
|
struct snd_soc_dpcm *dpcm;
|
|
|
|
struct snd_pcm_hw_params *be_params;
|
|
|
|
|
2018-09-18 09:31:09 +08:00
|
|
|
for_each_dpcm_be(fe, stream, dpcm) {
|
2015-03-26 12:02:51 +08:00
|
|
|
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 13:10:48 +08:00
|
|
|
static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_mod *mod)
|
2014-01-24 10:41:36 +08:00
|
|
|
{
|
2015-11-10 13:10:48 +08: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);
|
2017-05-16 09:51:41 +08:00
|
|
|
int is_play = rsnd_io_is_play(io);
|
2016-10-27 09:05:21 +08:00
|
|
|
int use_src = 0;
|
2016-03-07 13:09:14 +08:00
|
|
|
u32 fin, fout;
|
2015-11-10 13:10:48 +08:00
|
|
|
u32 ifscr, fsrate, adinr;
|
|
|
|
u32 cr, route;
|
|
|
|
u32 bsdsr, bsisr;
|
2017-05-16 09:51:41 +08:00
|
|
|
u32 i_busif, o_busif, tmp;
|
2015-11-10 13:10:48 +08:00
|
|
|
uint ratio;
|
2014-01-24 10:41:36 +08:00
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
if (!runtime)
|
|
|
|
return;
|
2015-04-01 12:15:16 +08:00
|
|
|
|
2016-03-07 13:09:14 +08:00
|
|
|
fin = rsnd_src_get_in_rate(priv, io);
|
|
|
|
fout = rsnd_src_get_out_rate(priv, io);
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
/* 6 - 1/6 are very enough ratio for SRC_BSDSR */
|
2016-03-07 13:09:14 +08:00
|
|
|
if (fin == fout)
|
2015-11-10 13:10:48 +08:00
|
|
|
ratio = 0;
|
2016-03-07 13:09:14 +08:00
|
|
|
else if (fin > fout)
|
|
|
|
ratio = 100 * fin / fout;
|
2015-11-10 13:10:48 +08:00
|
|
|
else
|
2016-03-07 13:09:14 +08:00
|
|
|
ratio = 100 * fout / fin;
|
2014-01-24 10:41:36 +08:00
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
if (ratio > 600) {
|
|
|
|
dev_err(dev, "FSO/FSI ratio error\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-01-24 10:41:36 +08:00
|
|
|
|
2016-10-27 09:05:21 +08:00
|
|
|
use_src = (fin != fout) | rsnd_src_sync_is_enabled(mod);
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
/*
|
2017-08-21 15:03:01 +08:00
|
|
|
* SRC_ADINR
|
2015-11-10 13:10:48 +08:00
|
|
|
*/
|
2015-11-30 16:49:33 +08:00
|
|
|
adinr = rsnd_get_adinr_bit(mod, io) |
|
2016-02-25 13:54:58 +08:00
|
|
|
rsnd_runtime_channel_original(io);
|
2014-01-24 10:41:36 +08:00
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
/*
|
2017-08-21 15:03:01 +08:00
|
|
|
* SRC_IFSCR / SRC_IFSVR
|
2015-11-10 13:10:48 +08:00
|
|
|
*/
|
|
|
|
ifscr = 0;
|
|
|
|
fsrate = 0;
|
2016-10-27 09:05:21 +08:00
|
|
|
if (use_src) {
|
2016-07-25 09:52:43 +08:00
|
|
|
u64 n;
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
ifscr = 1;
|
2016-07-25 09:52:43 +08:00
|
|
|
n = (u64)0x0400000 * fin;
|
|
|
|
do_div(n, fout);
|
|
|
|
fsrate = n;
|
2015-11-10 13:10:48 +08:00
|
|
|
}
|
2015-01-08 09:52:36 +08:00
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
/*
|
2017-08-21 15:03:01 +08:00
|
|
|
* SRC_SRCCR / SRC_ROUTE_MODE0
|
2015-11-10 13:10:48 +08:00
|
|
|
*/
|
|
|
|
cr = 0x00011110;
|
|
|
|
route = 0x0;
|
2016-10-27 09:05:21 +08:00
|
|
|
if (use_src) {
|
2015-11-10 13:10:48 +08:00
|
|
|
route = 0x1;
|
2015-03-26 12:02:51 +08:00
|
|
|
|
2016-03-07 13:07:57 +08:00
|
|
|
if (rsnd_src_sync_is_enabled(mod)) {
|
2015-11-10 13:10:48 +08:00
|
|
|
cr |= 0x1;
|
|
|
|
route |= rsnd_io_is_play(io) ?
|
|
|
|
(0x1 << 24) : (0x1 << 25);
|
|
|
|
}
|
|
|
|
}
|
2015-04-01 12:15:16 +08:00
|
|
|
|
2015-11-10 13:10:48 +08: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 10:41:36 +08:00
|
|
|
|
2017-05-16 09:51:41 +08:00
|
|
|
/* BUSIF_MODE */
|
|
|
|
tmp = rsnd_get_busif_shift(io, mod);
|
|
|
|
i_busif = ( is_play ? tmp : 0) | 1;
|
|
|
|
o_busif = (!is_play ? tmp : 0) | 1;
|
|
|
|
|
2016-02-18 16:13:45 +08:00
|
|
|
rsnd_mod_write(mod, SRC_ROUTE_MODE0, route);
|
|
|
|
|
2015-11-10 13:10:48 +08: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 10:41:36 +08:00
|
|
|
|
2017-05-16 09:51:41 +08:00
|
|
|
rsnd_mod_write(mod, SRC_I_BUSIF_MODE, i_busif);
|
|
|
|
rsnd_mod_write(mod, SRC_O_BUSIF_MODE, o_busif);
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
|
2014-01-24 10:41:36 +08:00
|
|
|
|
2016-03-07 13:09:14 +08:00
|
|
|
rsnd_adg_set_src_timesel_gen2(mod, io, fin, fout);
|
2014-01-24 10:41:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-26 12:56:57 +08:00
|
|
|
static int rsnd_src_irq(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv,
|
|
|
|
int enable)
|
2015-01-08 09:52:36 +08:00
|
|
|
{
|
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
u32 sys_int_val, int_val, sys_int_mask;
|
2015-11-10 13:11:55 +08:00
|
|
|
int irq = src->irq;
|
2015-01-08 09:52:36 +08: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 13:10:48 +08:00
|
|
|
* rsnd_src_probe_()
|
2015-01-08 09:52:36 +08:00
|
|
|
*/
|
|
|
|
if ((irq <= 0) || !enable) {
|
|
|
|
sys_int_val = 0;
|
|
|
|
int_val = 0;
|
|
|
|
}
|
|
|
|
|
2015-07-15 15:10:22 +08:00
|
|
|
/*
|
|
|
|
* WORKAROUND
|
|
|
|
*
|
2016-03-07 13:07:57 +08:00
|
|
|
* ignore over flow error when rsnd_src_sync_is_enabled()
|
2015-07-15 15:10:22 +08:00
|
|
|
*/
|
2016-03-07 13:07:57 +08:00
|
|
|
if (rsnd_src_sync_is_enabled(mod))
|
2015-07-15 15:10:22 +08:00
|
|
|
sys_int_val = sys_int_val & 0xffff;
|
|
|
|
|
2015-01-08 09:52:36 +08: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);
|
2016-01-26 12:56:57 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-01-08 09:52:36 +08:00
|
|
|
}
|
|
|
|
|
2015-11-26 19:11:03 +08:00
|
|
|
static void rsnd_src_status_clear(struct rsnd_mod *mod)
|
2015-01-08 09:52:36 +08:00
|
|
|
{
|
|
|
|
u32 val = OUF_SRC(rsnd_mod_id(mod));
|
|
|
|
|
2016-10-26 12:28:42 +08:00
|
|
|
rsnd_mod_write(mod, SCU_SYS_STATUS0, val);
|
|
|
|
rsnd_mod_write(mod, SCU_SYS_STATUS1, val);
|
2015-01-08 09:52:36 +08:00
|
|
|
}
|
|
|
|
|
2016-01-26 12:56:14 +08:00
|
|
|
static bool rsnd_src_error_occurred(struct rsnd_mod *mod)
|
2015-01-08 09:52:36 +08:00
|
|
|
{
|
2018-02-13 10:08:53 +08:00
|
|
|
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
2015-07-15 15:10:22 +08:00
|
|
|
u32 val0, val1;
|
2018-02-13 10:08:53 +08:00
|
|
|
u32 status0, status1;
|
2015-01-08 09:52:36 +08:00
|
|
|
bool ret = false;
|
|
|
|
|
2015-07-15 15:10:22 +08:00
|
|
|
val0 = val1 = OUF_SRC(rsnd_mod_id(mod));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WORKAROUND
|
|
|
|
*
|
2016-03-07 13:07:57 +08:00
|
|
|
* ignore over flow error when rsnd_src_sync_is_enabled()
|
2015-07-15 15:10:22 +08:00
|
|
|
*/
|
2016-03-07 13:07:57 +08:00
|
|
|
if (rsnd_src_sync_is_enabled(mod))
|
2015-07-15 15:10:22 +08:00
|
|
|
val0 = val0 & 0xffff;
|
|
|
|
|
2018-02-13 10:08:53 +08:00
|
|
|
status0 = rsnd_mod_read(mod, SCU_SYS_STATUS0);
|
|
|
|
status1 = rsnd_mod_read(mod, SCU_SYS_STATUS1);
|
|
|
|
if ((status0 & val0) || (status1 & val1)) {
|
|
|
|
rsnd_dbg_irq_status(dev, "%s[%d] err status : 0x%08x, 0x%08x\n",
|
|
|
|
rsnd_mod_name(mod), rsnd_mod_id(mod),
|
|
|
|
status0, status1);
|
|
|
|
|
2015-01-08 09:52:36 +08:00
|
|
|
ret = true;
|
2018-02-13 10:08:53 +08:00
|
|
|
}
|
2015-01-08 09:52:36 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
static int rsnd_src_start(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2015-01-08 09:52:36 +08:00
|
|
|
{
|
2015-07-15 15:10:22 +08:00
|
|
|
u32 val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WORKAROUND
|
|
|
|
*
|
|
|
|
* Enable SRC output if you want to use sync convert together with DVC
|
|
|
|
*/
|
2016-03-07 13:07:57 +08:00
|
|
|
val = (rsnd_io_to_mod_dvc(io) && !rsnd_src_sync_is_enabled(mod)) ?
|
2015-07-15 15:10:22 +08:00
|
|
|
0x01 : 0x11;
|
2015-01-08 09:52:36 +08:00
|
|
|
|
|
|
|
rsnd_mod_write(mod, SRC_CTRL, val);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
static int rsnd_src_stop(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2015-01-08 09:52:36 +08:00
|
|
|
{
|
2016-01-21 10:00:13 +08:00
|
|
|
rsnd_mod_write(mod, SRC_CTRL, 0);
|
2015-01-08 09:52:36 +08:00
|
|
|
|
2015-11-10 13:10:48 +08: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 09:52:36 +08:00
|
|
|
|
2017-02-02 13:01:05 +08:00
|
|
|
/* reset sync convert_rate */
|
|
|
|
src->sync.val = 0;
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
rsnd_mod_power_on(mod);
|
|
|
|
|
2015-11-30 16:50:32 +08:00
|
|
|
rsnd_src_activation(mod);
|
2015-11-10 13:10:48 +08:00
|
|
|
|
|
|
|
rsnd_src_set_convert_rate(io, mod);
|
|
|
|
|
2015-11-26 19:11:03 +08:00
|
|
|
rsnd_src_status_clear(mod);
|
2015-11-10 13:10:48 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-01-08 09:52:36 +08:00
|
|
|
}
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
static int rsnd_src_quit(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2015-10-26 16:40:59 +08:00
|
|
|
{
|
2015-11-10 13:10:48 +08:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
|
2015-11-30 16:51:35 +08:00
|
|
|
rsnd_src_halt(mod);
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
rsnd_mod_power_off(mod);
|
|
|
|
|
|
|
|
/* reset sync convert_rate */
|
|
|
|
src->sync.val = 0;
|
|
|
|
|
|
|
|
return 0;
|
2015-10-26 16:40:59 +08:00
|
|
|
}
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
static void __rsnd_src_interrupt(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io)
|
2015-01-08 09:52:36 +08:00
|
|
|
{
|
2015-05-21 11:50:23 +08:00
|
|
|
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
2016-01-26 12:56:14 +08:00
|
|
|
bool stop = false;
|
2015-05-21 11:50:23 +08:00
|
|
|
|
|
|
|
spin_lock(&priv->lock);
|
2015-01-08 09:52:36 +08:00
|
|
|
|
2015-05-21 11:50:23 +08:00
|
|
|
/* ignore all cases if not working */
|
2015-06-15 14:27:47 +08:00
|
|
|
if (!rsnd_io_is_working(io))
|
2015-11-10 13:10:48 +08:00
|
|
|
goto rsnd_src_interrupt_out;
|
2015-01-08 09:52:36 +08:00
|
|
|
|
2016-01-26 12:56:14 +08:00
|
|
|
if (rsnd_src_error_occurred(mod))
|
|
|
|
stop = true;
|
2015-06-15 14:27:13 +08:00
|
|
|
|
2015-11-26 19:11:03 +08:00
|
|
|
rsnd_src_status_clear(mod);
|
2015-11-10 13:10:48 +08:00
|
|
|
rsnd_src_interrupt_out:
|
2015-11-26 19:11:03 +08:00
|
|
|
|
2015-05-21 11:50:23 +08:00
|
|
|
spin_unlock(&priv->lock);
|
2016-01-26 12:56:14 +08:00
|
|
|
|
|
|
|
if (stop)
|
|
|
|
snd_pcm_stop_xrun(io->substream);
|
2015-06-15 14:27:13 +08:00
|
|
|
}
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
static irqreturn_t rsnd_src_interrupt(int irq, void *data)
|
2015-06-15 14:27:13 +08:00
|
|
|
{
|
|
|
|
struct rsnd_mod *mod = data;
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
rsnd_mod_interrupt(mod, __rsnd_src_interrupt);
|
2015-01-08 09:52:36 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
static int rsnd_src_probe_(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2014-03-04 12:50:41 +08:00
|
|
|
{
|
2014-03-04 12:51:21 +08:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
2014-03-04 12:50:41 +08:00
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
2015-11-10 13:11:55 +08:00
|
|
|
int irq = src->irq;
|
2014-03-04 12:50:41 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-01-08 09:52:36 +08:00
|
|
|
if (irq > 0) {
|
|
|
|
/*
|
|
|
|
* IRQ is not supported on non-DT
|
|
|
|
* see
|
2016-01-26 12:56:57 +08:00
|
|
|
* rsnd_src_irq()
|
2015-01-08 09:52:36 +08:00
|
|
|
*/
|
|
|
|
ret = devm_request_irq(dev, irq,
|
2015-11-10 13:10:48 +08:00
|
|
|
rsnd_src_interrupt,
|
2015-01-08 09:52:36 +08:00
|
|
|
IRQF_SHARED,
|
|
|
|
dev_name(dev), mod);
|
|
|
|
if (ret)
|
2015-03-26 12:02:32 +08:00
|
|
|
return ret;
|
2015-01-08 09:52:36 +08:00
|
|
|
}
|
|
|
|
|
2016-10-25 08:36:13 +08:00
|
|
|
ret = rsnd_dma_attach(io, mod, &src->dma);
|
2014-05-23 14:25:43 +08:00
|
|
|
|
2014-03-04 12:50:41 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
static int rsnd_src_pcm_new(struct rsnd_mod *mod,
|
2015-06-15 14:25:20 +08:00
|
|
|
struct rsnd_dai_stream *io,
|
2015-04-01 12:15:16 +08:00
|
|
|
struct snd_soc_pcm_runtime *rtd)
|
|
|
|
{
|
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* enable SRC sync convert if possible
|
|
|
|
*/
|
|
|
|
|
2015-11-10 15:39:17 +08:00
|
|
|
/*
|
2016-03-07 13:06:17 +08:00
|
|
|
* It can't use SRC Synchronous convert
|
|
|
|
* when Capture if it uses CMD
|
2015-11-10 15:39:17 +08:00
|
|
|
*/
|
2016-03-07 13:06:17 +08:00
|
|
|
if (rsnd_io_to_mod_cmd(io) && !rsnd_io_is_play(io))
|
2015-11-10 15:39:17 +08:00
|
|
|
return 0;
|
|
|
|
|
2015-04-01 12:15:16 +08:00
|
|
|
/*
|
|
|
|
* enable sync convert
|
|
|
|
*/
|
2015-06-15 14:27:28 +08:00
|
|
|
ret = rsnd_kctrl_new_s(mod, io, rtd,
|
2015-04-01 12:15:16 +08:00
|
|
|
rsnd_io_is_play(io) ?
|
|
|
|
"SRC Out Rate Switch" :
|
|
|
|
"SRC In Rate Switch",
|
2017-06-07 08:11:48 +08:00
|
|
|
rsnd_kctrl_accept_anytime,
|
2015-11-10 13:10:48 +08:00
|
|
|
rsnd_src_set_convert_rate,
|
2015-04-01 12:15:16 +08:00
|
|
|
&src->sen, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2015-06-15 14:27:28 +08:00
|
|
|
ret = rsnd_kctrl_new_s(mod, io, rtd,
|
2015-04-01 12:15:16 +08:00
|
|
|
rsnd_io_is_play(io) ?
|
|
|
|
"SRC Out Rate" :
|
|
|
|
"SRC In Rate",
|
2017-06-07 08:11:48 +08:00
|
|
|
rsnd_kctrl_accept_runtime,
|
2015-11-10 13:10:48 +08:00
|
|
|
rsnd_src_set_convert_rate,
|
2015-04-01 12:15:16 +08:00
|
|
|
&src->sync, 192000);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-10 13:10:48 +08:00
|
|
|
static struct rsnd_mod_ops rsnd_src_ops = {
|
2018-10-30 15:46:05 +08:00
|
|
|
.name = SRC_NAME,
|
|
|
|
.dma_req = rsnd_src_dma_req,
|
|
|
|
.probe = rsnd_src_probe_,
|
|
|
|
.init = rsnd_src_init,
|
|
|
|
.quit = rsnd_src_quit,
|
|
|
|
.start = rsnd_src_start,
|
|
|
|
.stop = rsnd_src_stop,
|
|
|
|
.irq = rsnd_src_irq,
|
|
|
|
.hw_params = rsnd_src_hw_params,
|
|
|
|
.pcm_new = rsnd_src_pcm_new,
|
|
|
|
.get_status = rsnd_mod_get_status,
|
2014-01-24 10:42:00 +08:00
|
|
|
};
|
|
|
|
|
2014-03-04 12:51:21 +08:00
|
|
|
struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
|
2013-07-22 12:36:35 +08:00
|
|
|
{
|
2014-03-04 12:51:21 +08:00
|
|
|
if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
|
2013-11-06 01:40:05 +08:00
|
|
|
id = 0;
|
2013-07-22 12:36:35 +08:00
|
|
|
|
2015-11-10 13:11:55 +08:00
|
|
|
return rsnd_mod_get(rsnd_src_get(priv, id));
|
2014-03-18 10:29:55 +08:00
|
|
|
}
|
|
|
|
|
2015-11-10 13:14:12 +08:00
|
|
|
int rsnd_src_probe(struct rsnd_priv *priv)
|
2013-07-22 12:36:35 +08:00
|
|
|
{
|
2015-11-10 13:11:55 +08:00
|
|
|
struct device_node *node;
|
|
|
|
struct device_node *np;
|
2013-07-22 12:36:35 +08:00
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
2014-03-04 12:51:21 +08:00
|
|
|
struct rsnd_src *src;
|
2013-12-20 11:28:51 +08:00
|
|
|
struct clk *clk;
|
2014-03-04 12:51:21 +08:00
|
|
|
char name[RSND_SRC_NAME_SIZE];
|
2015-03-26 12:02:09 +08:00
|
|
|
int i, nr, ret;
|
2013-07-22 12:36:35 +08:00
|
|
|
|
2015-11-10 13:09:52 +08:00
|
|
|
/* This driver doesn't support Gen1 at this point */
|
|
|
|
if (rsnd_is_gen1(priv))
|
|
|
|
return 0;
|
2014-05-23 14:25:37 +08:00
|
|
|
|
2015-11-10 13:11:55 +08:00
|
|
|
node = rsnd_src_of_node(priv);
|
|
|
|
if (!node)
|
|
|
|
return 0; /* not used is not error */
|
2014-03-18 10:29:55 +08:00
|
|
|
|
2015-11-10 13:11:55 +08:00
|
|
|
nr = of_get_child_count(node);
|
|
|
|
if (!nr) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2014-03-04 12:50:00 +08:00
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:07:58 +08:00
|
|
|
src = devm_kcalloc(dev, nr, sizeof(*src), GFP_KERNEL);
|
2015-11-10 13:11:55 +08:00
|
|
|
if (!src) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2013-07-22 12:36:35 +08:00
|
|
|
|
2014-03-04 12:51:21 +08:00
|
|
|
priv->src_nr = nr;
|
|
|
|
priv->src = src;
|
2013-07-22 12:36:35 +08:00
|
|
|
|
2015-11-10 13:11:55 +08:00
|
|
|
i = 0;
|
|
|
|
for_each_child_of_node(node, np) {
|
2016-05-12 06:36:40 +08:00
|
|
|
if (!of_device_is_available(np))
|
|
|
|
goto skip;
|
|
|
|
|
2015-11-10 13:11:55 +08:00
|
|
|
src = rsnd_src_get(priv, i);
|
|
|
|
|
2014-05-23 14:25:43 +08:00
|
|
|
snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
|
|
|
|
SRC_NAME, i);
|
2013-12-20 11:28:51 +08:00
|
|
|
|
2015-11-10 13:11:55 +08:00
|
|
|
src->irq = irq_of_parse_and_map(np, 0);
|
|
|
|
if (!src->irq) {
|
|
|
|
ret = -EINVAL;
|
2017-07-15 15:19:07 +08:00
|
|
|
of_node_put(np);
|
2015-11-10 13:11:55 +08:00
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2013-12-20 11:28:51 +08:00
|
|
|
|
2015-11-10 13:11:55 +08:00
|
|
|
clk = devm_clk_get(dev, name);
|
|
|
|
if (IS_ERR(clk)) {
|
|
|
|
ret = PTR_ERR(clk);
|
2017-07-15 15:19:07 +08:00
|
|
|
of_node_put(np);
|
2015-11-10 13:11:55 +08:00
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2013-07-22 12:36:35 +08:00
|
|
|
|
2015-11-10 13:09:52 +08:00
|
|
|
ret = rsnd_mod_init(priv, rsnd_mod_get(src),
|
2018-10-30 15:46:05 +08:00
|
|
|
&rsnd_src_ops, clk, RSND_MOD_SRC, i);
|
2017-07-15 15:19:07 +08:00
|
|
|
if (ret) {
|
|
|
|
of_node_put(np);
|
2015-11-10 13:11:55 +08:00
|
|
|
goto rsnd_src_probe_done;
|
2017-07-15 15:19:07 +08:00
|
|
|
}
|
2015-11-10 13:11:55 +08:00
|
|
|
|
2016-05-12 06:36:40 +08:00
|
|
|
skip:
|
2015-11-10 13:11:55 +08:00
|
|
|
i++;
|
2013-07-29 09:59:12 +08:00
|
|
|
}
|
2013-07-22 12:36:35 +08:00
|
|
|
|
2015-11-10 13:11:55 +08:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
rsnd_src_probe_done:
|
|
|
|
of_node_put(node);
|
|
|
|
|
|
|
|
return ret;
|
2013-07-22 12:36:35 +08:00
|
|
|
}
|
2015-03-26 12:02:09 +08:00
|
|
|
|
2015-11-10 13:14:12 +08:00
|
|
|
void rsnd_src_remove(struct rsnd_priv *priv)
|
2015-03-26 12:02:09 +08:00
|
|
|
{
|
|
|
|
struct rsnd_src *src;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_rsnd_src(src, priv, i) {
|
2015-09-10 15:02:21 +08:00
|
|
|
rsnd_mod_quit(rsnd_mod_get(src));
|
2015-03-26 12:02:09 +08:00
|
|
|
}
|
|
|
|
}
|