2018-06-12 12:58:38 +07: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 09:08:53 +07: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 11:36:35 +07:00
|
|
|
#include "rsnd.h"
|
|
|
|
|
2014-05-23 13:25:43 +07:00
|
|
|
#define SRC_NAME "src"
|
|
|
|
|
2015-01-08 08:52:36 +07:00
|
|
|
/* SCU_SYSTEM_STATUS0/1 */
|
|
|
|
#define OUF_SRC(id) ((1 << (id + 16)) | (1 << id))
|
|
|
|
|
2014-03-04 11:51:21 +07:00
|
|
|
struct rsnd_src {
|
2013-07-22 11:36:35 +07:00
|
|
|
struct rsnd_mod mod;
|
2015-10-26 15:42:25 +07:00
|
|
|
struct rsnd_mod *dma;
|
2015-04-01 11:15:16 +07:00
|
|
|
struct rsnd_kctrl_cfg_s sen; /* sync convert enable */
|
|
|
|
struct rsnd_kctrl_cfg_s sync; /* sync convert */
|
2015-11-10 12:11:55 +07:00
|
|
|
int irq;
|
2013-07-22 11:36:35 +07:00
|
|
|
};
|
|
|
|
|
2014-03-04 11:51:21 +07:00
|
|
|
#define RSND_SRC_NAME_SIZE 16
|
2013-07-29 08:59:12 +07:00
|
|
|
|
2015-11-10 12:11:55 +07:00
|
|
|
#define rsnd_src_get(priv, id) ((struct rsnd_src *)(priv->src) + id)
|
2015-07-15 14:11:21 +07:00
|
|
|
#define rsnd_src_nr(priv) ((priv)->src_nr)
|
2016-03-07 12:07:57 +07:00
|
|
|
#define rsnd_src_sync_is_enabled(mod) (rsnd_mod_to_src(mod)->sen.val)
|
2015-02-20 17:30:22 +07:00
|
|
|
|
2014-03-04 11:51:21 +07:00
|
|
|
#define rsnd_mod_to_src(_mod) \
|
|
|
|
container_of((_mod), struct rsnd_src, mod)
|
2014-01-24 09:40:47 +07:00
|
|
|
|
2014-03-04 11:51:21 +07:00
|
|
|
#define for_each_rsnd_src(pos, priv, i) \
|
2014-01-24 09:40:47 +07:00
|
|
|
for ((i) = 0; \
|
2014-03-04 11:51:21 +07:00
|
|
|
((i) < rsnd_src_nr(priv)) && \
|
|
|
|
((pos) = (struct rsnd_src *)(priv)->src + i); \
|
2014-01-24 09:40:47 +07:00
|
|
|
i++)
|
|
|
|
|
|
|
|
|
2013-12-20 10:28:51 +07:00
|
|
|
/*
|
|
|
|
* image of SRC (Sampling Rate Converter)
|
|
|
|
*
|
|
|
|
* 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
|
|
|
|
* 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
|
|
|
|
* 44.1kHz <-> +-----+ +-----+ +-------+
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
*/
|
2013-07-29 08:59:12 +07:00
|
|
|
|
2015-11-30 15:50:32 +07:00
|
|
|
static void rsnd_src_activation(struct rsnd_mod *mod)
|
2015-07-15 14:12:18 +07:00
|
|
|
{
|
|
|
|
rsnd_mod_write(mod, SRC_SWRSR, 0);
|
|
|
|
rsnd_mod_write(mod, SRC_SWRSR, 1);
|
|
|
|
}
|
|
|
|
|
2015-11-30 15:51:35 +07: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 13:26:25 +07: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 17:31:23 +07: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 13:27:13 +07:00
|
|
|
static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io,
|
2016-03-07 12:07:29 +07:00
|
|
|
struct rsnd_mod *mod)
|
2015-04-01 11:15:16 +07:00
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
2016-03-07 12:07:29 +07:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
2015-04-01 11:15:16 +07:00
|
|
|
u32 convert_rate;
|
|
|
|
|
|
|
|
if (!runtime)
|
|
|
|
return 0;
|
|
|
|
|
2016-03-07 12:07:57 +07:00
|
|
|
if (!rsnd_src_sync_is_enabled(mod))
|
2018-11-06 12:20:10 +07:00
|
|
|
return rsnd_io_converted_rate(io);
|
2015-04-01 11:15:16 +07:00
|
|
|
|
|
|
|
convert_rate = src->sync.val;
|
|
|
|
|
|
|
|
if (!convert_rate)
|
2018-11-06 12:20:10 +07:00
|
|
|
convert_rate = rsnd_io_converted_rate(io);
|
2015-04-01 11:15:16 +07:00
|
|
|
|
|
|
|
if (!convert_rate)
|
|
|
|
convert_rate = runtime->rate;
|
|
|
|
|
|
|
|
return convert_rate;
|
|
|
|
}
|
|
|
|
|
2016-03-07 12:08:33 +07:00
|
|
|
unsigned int rsnd_src_get_rate(struct rsnd_priv *priv,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
int is_in)
|
2014-01-24 09:41:36 +07:00
|
|
|
{
|
2014-03-24 11:23:42 +07:00
|
|
|
struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
|
2016-03-07 12:08:33 +07:00
|
|
|
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
|
2014-03-24 11:23:42 +07:00
|
|
|
unsigned int rate = 0;
|
2016-03-07 12:08:33 +07: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 09:41:36 +07:00
|
|
|
|
2016-03-07 12:07:29 +07: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 09:41:36 +07:00
|
|
|
|
|
|
|
if (!rate)
|
|
|
|
rate = runtime->rate;
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
2019-03-07 13:15:54 +07:00
|
|
|
static const u32 bsdsr_table_pattern1[] = {
|
2018-12-25 12:05:28 +07:00
|
|
|
0x01800000, /* 6 - 1/6 */
|
|
|
|
0x01000000, /* 6 - 1/4 */
|
|
|
|
0x00c00000, /* 6 - 1/3 */
|
|
|
|
0x00800000, /* 6 - 1/2 */
|
|
|
|
0x00600000, /* 6 - 2/3 */
|
|
|
|
0x00400000, /* 6 - 1 */
|
|
|
|
};
|
|
|
|
|
2019-03-07 13:15:54 +07:00
|
|
|
static const u32 bsdsr_table_pattern2[] = {
|
2018-12-25 12:05:28 +07:00
|
|
|
0x02400000, /* 6 - 1/6 */
|
|
|
|
0x01800000, /* 6 - 1/4 */
|
|
|
|
0x01200000, /* 6 - 1/3 */
|
|
|
|
0x00c00000, /* 6 - 1/2 */
|
|
|
|
0x00900000, /* 6 - 2/3 */
|
|
|
|
0x00600000, /* 6 - 1 */
|
|
|
|
};
|
|
|
|
|
2019-03-07 13:15:54 +07:00
|
|
|
static const u32 bsisr_table[] = {
|
2018-12-25 12:05:28 +07:00
|
|
|
0x00100060, /* 6 - 1/6 */
|
|
|
|
0x00100040, /* 6 - 1/4 */
|
|
|
|
0x00100030, /* 6 - 1/3 */
|
|
|
|
0x00100020, /* 6 - 1/2 */
|
|
|
|
0x00100020, /* 6 - 2/3 */
|
|
|
|
0x00100020, /* 6 - 1 */
|
|
|
|
};
|
|
|
|
|
2019-03-07 13:15:54 +07:00
|
|
|
static const u32 chan288888[] = {
|
2018-12-25 12:05:28 +07:00
|
|
|
0x00000006, /* 1 to 2 */
|
|
|
|
0x000001fe, /* 1 to 8 */
|
|
|
|
0x000001fe, /* 1 to 8 */
|
|
|
|
0x000001fe, /* 1 to 8 */
|
|
|
|
0x000001fe, /* 1 to 8 */
|
|
|
|
0x000001fe, /* 1 to 8 */
|
|
|
|
};
|
|
|
|
|
2019-03-07 13:15:54 +07:00
|
|
|
static const u32 chan244888[] = {
|
2018-12-25 12:05:28 +07:00
|
|
|
0x00000006, /* 1 to 2 */
|
|
|
|
0x0000001e, /* 1 to 4 */
|
|
|
|
0x0000001e, /* 1 to 4 */
|
|
|
|
0x000001fe, /* 1 to 8 */
|
|
|
|
0x000001fe, /* 1 to 8 */
|
|
|
|
0x000001fe, /* 1 to 8 */
|
|
|
|
};
|
|
|
|
|
2019-03-07 13:15:54 +07:00
|
|
|
static const u32 chan222222[] = {
|
2018-12-25 12:05:28 +07:00
|
|
|
0x00000006, /* 1 to 2 */
|
|
|
|
0x00000006, /* 1 to 2 */
|
|
|
|
0x00000006, /* 1 to 2 */
|
|
|
|
0x00000006, /* 1 to 2 */
|
|
|
|
0x00000006, /* 1 to 2 */
|
|
|
|
0x00000006, /* 1 to 2 */
|
|
|
|
};
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_mod *mod)
|
2014-01-24 09:41:36 +07:00
|
|
|
{
|
2015-11-10 12:10:48 +07: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 08:51:41 +07:00
|
|
|
int is_play = rsnd_io_is_play(io);
|
2016-10-27 08:05:21 +07:00
|
|
|
int use_src = 0;
|
2016-03-07 12:09:14 +07:00
|
|
|
u32 fin, fout;
|
2015-11-10 12:10:48 +07:00
|
|
|
u32 ifscr, fsrate, adinr;
|
|
|
|
u32 cr, route;
|
2017-05-16 08:51:41 +07:00
|
|
|
u32 i_busif, o_busif, tmp;
|
2018-12-25 12:05:28 +07:00
|
|
|
const u32 *bsdsr_table;
|
|
|
|
const u32 *chptn;
|
2015-11-10 12:10:48 +07:00
|
|
|
uint ratio;
|
2018-12-25 12:05:28 +07:00
|
|
|
int chan;
|
|
|
|
int idx;
|
2014-01-24 09:41:36 +07:00
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
if (!runtime)
|
|
|
|
return;
|
2015-04-01 11:15:16 +07:00
|
|
|
|
2016-03-07 12:09:14 +07:00
|
|
|
fin = rsnd_src_get_in_rate(priv, io);
|
|
|
|
fout = rsnd_src_get_out_rate(priv, io);
|
|
|
|
|
2018-12-25 12:05:28 +07:00
|
|
|
chan = rsnd_runtime_channel_original(io);
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
/* 6 - 1/6 are very enough ratio for SRC_BSDSR */
|
2016-03-07 12:09:14 +07:00
|
|
|
if (fin == fout)
|
2015-11-10 12:10:48 +07:00
|
|
|
ratio = 0;
|
2016-03-07 12:09:14 +07:00
|
|
|
else if (fin > fout)
|
|
|
|
ratio = 100 * fin / fout;
|
2015-11-10 12:10:48 +07:00
|
|
|
else
|
2016-03-07 12:09:14 +07:00
|
|
|
ratio = 100 * fout / fin;
|
2014-01-24 09:41:36 +07:00
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
if (ratio > 600) {
|
|
|
|
dev_err(dev, "FSO/FSI ratio error\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-01-24 09:41:36 +07:00
|
|
|
|
2016-10-27 08:05:21 +07:00
|
|
|
use_src = (fin != fout) | rsnd_src_sync_is_enabled(mod);
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
/*
|
2017-08-21 14:03:01 +07:00
|
|
|
* SRC_ADINR
|
2015-11-10 12:10:48 +07:00
|
|
|
*/
|
2018-12-25 12:05:28 +07:00
|
|
|
adinr = rsnd_get_adinr_bit(mod, io) | chan;
|
2014-01-24 09:41:36 +07:00
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
/*
|
2017-08-21 14:03:01 +07:00
|
|
|
* SRC_IFSCR / SRC_IFSVR
|
2015-11-10 12:10:48 +07:00
|
|
|
*/
|
|
|
|
ifscr = 0;
|
|
|
|
fsrate = 0;
|
2016-10-27 08:05:21 +07:00
|
|
|
if (use_src) {
|
2016-07-25 08:52:43 +07:00
|
|
|
u64 n;
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
ifscr = 1;
|
2016-07-25 08:52:43 +07:00
|
|
|
n = (u64)0x0400000 * fin;
|
|
|
|
do_div(n, fout);
|
|
|
|
fsrate = n;
|
2015-11-10 12:10:48 +07:00
|
|
|
}
|
2015-01-08 08:52:36 +07:00
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
/*
|
2017-08-21 14:03:01 +07:00
|
|
|
* SRC_SRCCR / SRC_ROUTE_MODE0
|
2015-11-10 12:10:48 +07:00
|
|
|
*/
|
|
|
|
cr = 0x00011110;
|
|
|
|
route = 0x0;
|
2016-10-27 08:05:21 +07:00
|
|
|
if (use_src) {
|
2015-11-10 12:10:48 +07:00
|
|
|
route = 0x1;
|
2015-03-26 11:02:51 +07:00
|
|
|
|
2016-03-07 12:07:57 +07:00
|
|
|
if (rsnd_src_sync_is_enabled(mod)) {
|
2015-11-10 12:10:48 +07:00
|
|
|
cr |= 0x1;
|
|
|
|
route |= rsnd_io_is_play(io) ?
|
|
|
|
(0x1 << 24) : (0x1 << 25);
|
|
|
|
}
|
|
|
|
}
|
2015-04-01 11:15:16 +07:00
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
/*
|
|
|
|
* SRC_BSDSR / SRC_BSISR
|
2018-12-25 12:05:28 +07:00
|
|
|
*
|
|
|
|
* see
|
|
|
|
* Combination of Register Setting Related to
|
|
|
|
* FSO/FSI Ratio and Channel, Latency
|
2015-11-10 12:10:48 +07:00
|
|
|
*/
|
|
|
|
switch (rsnd_mod_id(mod)) {
|
2018-12-25 12:05:28 +07:00
|
|
|
case 0:
|
|
|
|
chptn = chan288888;
|
|
|
|
bsdsr_table = bsdsr_table_pattern1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
chptn = chan244888;
|
|
|
|
bsdsr_table = bsdsr_table_pattern1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 9:
|
|
|
|
chptn = chan222222;
|
|
|
|
bsdsr_table = bsdsr_table_pattern1;
|
|
|
|
break;
|
2015-11-10 12:10:48 +07:00
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
case 8:
|
2018-12-25 12:05:28 +07:00
|
|
|
chptn = chan222222;
|
|
|
|
bsdsr_table = bsdsr_table_pattern2;
|
2015-11-10 12:10:48 +07:00
|
|
|
break;
|
|
|
|
default:
|
2018-12-25 12:05:28 +07:00
|
|
|
goto convert_rate_err;
|
2015-11-10 12:10:48 +07:00
|
|
|
}
|
2014-01-24 09:41:36 +07:00
|
|
|
|
2018-12-25 12:05:28 +07:00
|
|
|
/*
|
|
|
|
* E3 need to overwrite
|
|
|
|
*/
|
2019-03-07 13:15:53 +07:00
|
|
|
if (rsnd_is_e3(priv))
|
2018-12-25 12:05:28 +07:00
|
|
|
switch (rsnd_mod_id(mod)) {
|
|
|
|
case 0:
|
|
|
|
case 4:
|
|
|
|
chptn = chan222222;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (idx = 0; idx < ARRAY_SIZE(chan222222); idx++)
|
|
|
|
if (chptn[idx] & (1 << chan))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (chan > 8 ||
|
|
|
|
idx >= ARRAY_SIZE(chan222222))
|
|
|
|
goto convert_rate_err;
|
|
|
|
|
2017-05-16 08:51:41 +07: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 15:13:45 +07:00
|
|
|
rsnd_mod_write(mod, SRC_ROUTE_MODE0, route);
|
|
|
|
|
2015-11-10 12:10:48 +07: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);
|
2018-12-25 12:05:28 +07:00
|
|
|
rsnd_mod_write(mod, SRC_BSDSR, bsdsr_table[idx]);
|
|
|
|
rsnd_mod_write(mod, SRC_BSISR, bsisr_table[idx]);
|
2015-11-10 12:10:48 +07:00
|
|
|
rsnd_mod_write(mod, SRC_SRCIR, 0); /* cancel initialize */
|
2014-01-24 09:41:36 +07:00
|
|
|
|
2017-05-16 08:51:41 +07:00
|
|
|
rsnd_mod_write(mod, SRC_I_BUSIF_MODE, i_busif);
|
|
|
|
rsnd_mod_write(mod, SRC_O_BUSIF_MODE, o_busif);
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
|
2014-01-24 09:41:36 +07:00
|
|
|
|
2016-03-07 12:09:14 +07:00
|
|
|
rsnd_adg_set_src_timesel_gen2(mod, io, fin, fout);
|
2018-12-25 12:05:28 +07:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
convert_rate_err:
|
|
|
|
dev_err(dev, "unknown BSDSR/BSDIR settings\n");
|
2014-01-24 09:41:36 +07:00
|
|
|
}
|
|
|
|
|
2016-01-26 11:56:57 +07:00
|
|
|
static int rsnd_src_irq(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv,
|
|
|
|
int enable)
|
2015-01-08 08:52:36 +07:00
|
|
|
{
|
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
u32 sys_int_val, int_val, sys_int_mask;
|
2015-11-10 12:11:55 +07:00
|
|
|
int irq = src->irq;
|
2015-01-08 08:52:36 +07: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 12:10:48 +07:00
|
|
|
* rsnd_src_probe_()
|
2015-01-08 08:52:36 +07:00
|
|
|
*/
|
|
|
|
if ((irq <= 0) || !enable) {
|
|
|
|
sys_int_val = 0;
|
|
|
|
int_val = 0;
|
|
|
|
}
|
|
|
|
|
2015-07-15 14:10:22 +07:00
|
|
|
/*
|
|
|
|
* WORKAROUND
|
|
|
|
*
|
2016-03-07 12:07:57 +07:00
|
|
|
* ignore over flow error when rsnd_src_sync_is_enabled()
|
2015-07-15 14:10:22 +07:00
|
|
|
*/
|
2016-03-07 12:07:57 +07:00
|
|
|
if (rsnd_src_sync_is_enabled(mod))
|
2015-07-15 14:10:22 +07:00
|
|
|
sys_int_val = sys_int_val & 0xffff;
|
|
|
|
|
2015-01-08 08:52:36 +07: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 11:56:57 +07:00
|
|
|
|
|
|
|
return 0;
|
2015-01-08 08:52:36 +07:00
|
|
|
}
|
|
|
|
|
2015-11-26 18:11:03 +07:00
|
|
|
static void rsnd_src_status_clear(struct rsnd_mod *mod)
|
2015-01-08 08:52:36 +07:00
|
|
|
{
|
|
|
|
u32 val = OUF_SRC(rsnd_mod_id(mod));
|
|
|
|
|
2016-10-26 11:28:42 +07:00
|
|
|
rsnd_mod_write(mod, SCU_SYS_STATUS0, val);
|
|
|
|
rsnd_mod_write(mod, SCU_SYS_STATUS1, val);
|
2015-01-08 08:52:36 +07:00
|
|
|
}
|
|
|
|
|
2016-01-26 11:56:14 +07:00
|
|
|
static bool rsnd_src_error_occurred(struct rsnd_mod *mod)
|
2015-01-08 08:52:36 +07:00
|
|
|
{
|
2018-02-13 09:08:53 +07:00
|
|
|
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
2015-07-15 14:10:22 +07:00
|
|
|
u32 val0, val1;
|
2018-02-13 09:08:53 +07:00
|
|
|
u32 status0, status1;
|
2015-01-08 08:52:36 +07:00
|
|
|
bool ret = false;
|
|
|
|
|
2015-07-15 14:10:22 +07:00
|
|
|
val0 = val1 = OUF_SRC(rsnd_mod_id(mod));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WORKAROUND
|
|
|
|
*
|
2016-03-07 12:07:57 +07:00
|
|
|
* ignore over flow error when rsnd_src_sync_is_enabled()
|
2015-07-15 14:10:22 +07:00
|
|
|
*/
|
2016-03-07 12:07:57 +07:00
|
|
|
if (rsnd_src_sync_is_enabled(mod))
|
2015-07-15 14:10:22 +07:00
|
|
|
val0 = val0 & 0xffff;
|
|
|
|
|
2018-02-13 09:08:53 +07:00
|
|
|
status0 = rsnd_mod_read(mod, SCU_SYS_STATUS0);
|
|
|
|
status1 = rsnd_mod_read(mod, SCU_SYS_STATUS1);
|
|
|
|
if ((status0 & val0) || (status1 & val1)) {
|
ASoC: rsnd: rsnd_mod_name() handles both name and ID
Current rsnd driver is using "%s[%d]" for mod name and ID,
but, this ID portion might confusable.
For example currently, CTU ID is 0 to 7, but using 00 to 13
(= 00, 01, 02, 03, 10, 11, 12, 13) is very best matching to datasheet.
In the future, we will support BUSIFn, but it will be more complicated
numbering. To avoid future confusable code, this patch modify
rsnd_mod_name() to return understandable name.
To avoid using pointless memory, it uses static char and snprintf,
thus, rsnd_mod_name() user should use it immediately, and shouldn't keep
its pointer.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2018-10-30 14:47:50 +07:00
|
|
|
rsnd_dbg_irq_status(dev, "%s err status : 0x%08x, 0x%08x\n",
|
|
|
|
rsnd_mod_name(mod), status0, status1);
|
2018-02-13 09:08:53 +07:00
|
|
|
|
2015-01-08 08:52:36 +07:00
|
|
|
ret = true;
|
2018-02-13 09:08:53 +07:00
|
|
|
}
|
2015-01-08 08:52:36 +07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
static int rsnd_src_start(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2015-01-08 08:52:36 +07:00
|
|
|
{
|
2015-07-15 14:10:22 +07:00
|
|
|
u32 val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WORKAROUND
|
|
|
|
*
|
|
|
|
* Enable SRC output if you want to use sync convert together with DVC
|
|
|
|
*/
|
2016-03-07 12:07:57 +07:00
|
|
|
val = (rsnd_io_to_mod_dvc(io) && !rsnd_src_sync_is_enabled(mod)) ?
|
2015-07-15 14:10:22 +07:00
|
|
|
0x01 : 0x11;
|
2015-01-08 08:52:36 +07:00
|
|
|
|
|
|
|
rsnd_mod_write(mod, SRC_CTRL, val);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
static int rsnd_src_stop(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2015-01-08 08:52:36 +07:00
|
|
|
{
|
2016-01-21 09:00:13 +07:00
|
|
|
rsnd_mod_write(mod, SRC_CTRL, 0);
|
2015-01-08 08:52:36 +07:00
|
|
|
|
2015-11-10 12:10:48 +07: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 08:52:36 +07:00
|
|
|
|
2017-02-02 12:01:05 +07:00
|
|
|
/* reset sync convert_rate */
|
|
|
|
src->sync.val = 0;
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
rsnd_mod_power_on(mod);
|
|
|
|
|
2015-11-30 15:50:32 +07:00
|
|
|
rsnd_src_activation(mod);
|
2015-11-10 12:10:48 +07:00
|
|
|
|
|
|
|
rsnd_src_set_convert_rate(io, mod);
|
|
|
|
|
2015-11-26 18:11:03 +07:00
|
|
|
rsnd_src_status_clear(mod);
|
2015-11-10 12:10:48 +07:00
|
|
|
|
|
|
|
return 0;
|
2015-01-08 08:52:36 +07:00
|
|
|
}
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
static int rsnd_src_quit(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2015-10-26 15:40:59 +07:00
|
|
|
{
|
2015-11-10 12:10:48 +07:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
|
|
|
|
2015-11-30 15:51:35 +07:00
|
|
|
rsnd_src_halt(mod);
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
rsnd_mod_power_off(mod);
|
|
|
|
|
|
|
|
/* reset sync convert_rate */
|
|
|
|
src->sync.val = 0;
|
|
|
|
|
|
|
|
return 0;
|
2015-10-26 15:40:59 +07:00
|
|
|
}
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
static void __rsnd_src_interrupt(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io)
|
2015-01-08 08:52:36 +07:00
|
|
|
{
|
2015-05-21 10:50:23 +07:00
|
|
|
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
|
2016-01-26 11:56:14 +07:00
|
|
|
bool stop = false;
|
2015-05-21 10:50:23 +07:00
|
|
|
|
|
|
|
spin_lock(&priv->lock);
|
2015-01-08 08:52:36 +07:00
|
|
|
|
2015-05-21 10:50:23 +07:00
|
|
|
/* ignore all cases if not working */
|
2015-06-15 13:27:47 +07:00
|
|
|
if (!rsnd_io_is_working(io))
|
2015-11-10 12:10:48 +07:00
|
|
|
goto rsnd_src_interrupt_out;
|
2015-01-08 08:52:36 +07:00
|
|
|
|
2016-01-26 11:56:14 +07:00
|
|
|
if (rsnd_src_error_occurred(mod))
|
|
|
|
stop = true;
|
2015-06-15 13:27:13 +07:00
|
|
|
|
2015-11-26 18:11:03 +07:00
|
|
|
rsnd_src_status_clear(mod);
|
2015-11-10 12:10:48 +07:00
|
|
|
rsnd_src_interrupt_out:
|
2015-11-26 18:11:03 +07:00
|
|
|
|
2015-05-21 10:50:23 +07:00
|
|
|
spin_unlock(&priv->lock);
|
2016-01-26 11:56:14 +07:00
|
|
|
|
|
|
|
if (stop)
|
|
|
|
snd_pcm_stop_xrun(io->substream);
|
2015-06-15 13:27:13 +07:00
|
|
|
}
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
static irqreturn_t rsnd_src_interrupt(int irq, void *data)
|
2015-06-15 13:27:13 +07:00
|
|
|
{
|
|
|
|
struct rsnd_mod *mod = data;
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
rsnd_mod_interrupt(mod, __rsnd_src_interrupt);
|
2015-01-08 08:52:36 +07:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
static int rsnd_src_probe_(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
2014-03-04 11:50:41 +07:00
|
|
|
{
|
2014-03-04 11:51:21 +07:00
|
|
|
struct rsnd_src *src = rsnd_mod_to_src(mod);
|
2014-03-04 11:50:41 +07:00
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
2015-11-10 12:11:55 +07:00
|
|
|
int irq = src->irq;
|
2014-03-04 11:50:41 +07:00
|
|
|
int ret;
|
|
|
|
|
2015-01-08 08:52:36 +07:00
|
|
|
if (irq > 0) {
|
|
|
|
/*
|
|
|
|
* IRQ is not supported on non-DT
|
|
|
|
* see
|
2016-01-26 11:56:57 +07:00
|
|
|
* rsnd_src_irq()
|
2015-01-08 08:52:36 +07:00
|
|
|
*/
|
|
|
|
ret = devm_request_irq(dev, irq,
|
2015-11-10 12:10:48 +07:00
|
|
|
rsnd_src_interrupt,
|
2015-01-08 08:52:36 +07:00
|
|
|
IRQF_SHARED,
|
|
|
|
dev_name(dev), mod);
|
|
|
|
if (ret)
|
2015-03-26 11:02:32 +07:00
|
|
|
return ret;
|
2015-01-08 08:52:36 +07:00
|
|
|
}
|
|
|
|
|
2016-10-25 07:36:13 +07:00
|
|
|
ret = rsnd_dma_attach(io, mod, &src->dma);
|
2014-05-23 13:25:43 +07:00
|
|
|
|
2014-03-04 11:50:41 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
static int rsnd_src_pcm_new(struct rsnd_mod *mod,
|
2015-06-15 13:25:20 +07:00
|
|
|
struct rsnd_dai_stream *io,
|
2015-04-01 11:15:16 +07: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 14:39:17 +07:00
|
|
|
/*
|
2016-03-07 12:06:17 +07:00
|
|
|
* It can't use SRC Synchronous convert
|
|
|
|
* when Capture if it uses CMD
|
2015-11-10 14:39:17 +07:00
|
|
|
*/
|
2016-03-07 12:06:17 +07:00
|
|
|
if (rsnd_io_to_mod_cmd(io) && !rsnd_io_is_play(io))
|
2015-11-10 14:39:17 +07:00
|
|
|
return 0;
|
|
|
|
|
2015-04-01 11:15:16 +07:00
|
|
|
/*
|
|
|
|
* enable sync convert
|
|
|
|
*/
|
2015-06-15 13:27:28 +07:00
|
|
|
ret = rsnd_kctrl_new_s(mod, io, rtd,
|
2015-04-01 11:15:16 +07:00
|
|
|
rsnd_io_is_play(io) ?
|
|
|
|
"SRC Out Rate Switch" :
|
|
|
|
"SRC In Rate Switch",
|
2017-06-07 07:11:48 +07:00
|
|
|
rsnd_kctrl_accept_anytime,
|
2015-11-10 12:10:48 +07:00
|
|
|
rsnd_src_set_convert_rate,
|
2015-04-01 11:15:16 +07:00
|
|
|
&src->sen, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2015-06-15 13:27:28 +07:00
|
|
|
ret = rsnd_kctrl_new_s(mod, io, rtd,
|
2015-04-01 11:15:16 +07:00
|
|
|
rsnd_io_is_play(io) ?
|
|
|
|
"SRC Out Rate" :
|
|
|
|
"SRC In Rate",
|
2017-06-07 07:11:48 +07:00
|
|
|
rsnd_kctrl_accept_runtime,
|
2015-11-10 12:10:48 +07:00
|
|
|
rsnd_src_set_convert_rate,
|
2015-04-01 11:15:16 +07:00
|
|
|
&src->sync, 192000);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-10 12:10:48 +07:00
|
|
|
static struct rsnd_mod_ops rsnd_src_ops = {
|
2018-10-30 14:46:05 +07: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,
|
|
|
|
.pcm_new = rsnd_src_pcm_new,
|
|
|
|
.get_status = rsnd_mod_get_status,
|
2014-01-24 09:42:00 +07:00
|
|
|
};
|
|
|
|
|
2014-03-04 11:51:21 +07:00
|
|
|
struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
|
2013-07-22 11:36:35 +07:00
|
|
|
{
|
2014-03-04 11:51:21 +07:00
|
|
|
if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
|
2013-11-06 00:40:05 +07:00
|
|
|
id = 0;
|
2013-07-22 11:36:35 +07:00
|
|
|
|
2015-11-10 12:11:55 +07:00
|
|
|
return rsnd_mod_get(rsnd_src_get(priv, id));
|
2014-03-18 09:29:55 +07:00
|
|
|
}
|
|
|
|
|
2015-11-10 12:14:12 +07:00
|
|
|
int rsnd_src_probe(struct rsnd_priv *priv)
|
2013-07-22 11:36:35 +07:00
|
|
|
{
|
2015-11-10 12:11:55 +07:00
|
|
|
struct device_node *node;
|
|
|
|
struct device_node *np;
|
2013-07-22 11:36:35 +07:00
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
2014-03-04 11:51:21 +07:00
|
|
|
struct rsnd_src *src;
|
2013-12-20 10:28:51 +07:00
|
|
|
struct clk *clk;
|
2014-03-04 11:51:21 +07:00
|
|
|
char name[RSND_SRC_NAME_SIZE];
|
2015-03-26 11:02:09 +07:00
|
|
|
int i, nr, ret;
|
2013-07-22 11:36:35 +07:00
|
|
|
|
2015-11-10 12:09:52 +07:00
|
|
|
/* This driver doesn't support Gen1 at this point */
|
|
|
|
if (rsnd_is_gen1(priv))
|
|
|
|
return 0;
|
2014-05-23 13:25:37 +07:00
|
|
|
|
2015-11-10 12:11:55 +07:00
|
|
|
node = rsnd_src_of_node(priv);
|
|
|
|
if (!node)
|
|
|
|
return 0; /* not used is not error */
|
2014-03-18 09:29:55 +07:00
|
|
|
|
2015-11-10 12:11:55 +07:00
|
|
|
nr = of_get_child_count(node);
|
|
|
|
if (!nr) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2014-03-04 11:50:00 +07: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 04:07:58 +07:00
|
|
|
src = devm_kcalloc(dev, nr, sizeof(*src), GFP_KERNEL);
|
2015-11-10 12:11:55 +07:00
|
|
|
if (!src) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2013-07-22 11:36:35 +07:00
|
|
|
|
2014-03-04 11:51:21 +07:00
|
|
|
priv->src_nr = nr;
|
|
|
|
priv->src = src;
|
2013-07-22 11:36:35 +07:00
|
|
|
|
2015-11-10 12:11:55 +07:00
|
|
|
i = 0;
|
|
|
|
for_each_child_of_node(node, np) {
|
2016-05-12 05:36:40 +07:00
|
|
|
if (!of_device_is_available(np))
|
|
|
|
goto skip;
|
|
|
|
|
2015-11-10 12:11:55 +07:00
|
|
|
src = rsnd_src_get(priv, i);
|
|
|
|
|
2014-05-23 13:25:43 +07:00
|
|
|
snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
|
|
|
|
SRC_NAME, i);
|
2013-12-20 10:28:51 +07:00
|
|
|
|
2015-11-10 12:11:55 +07:00
|
|
|
src->irq = irq_of_parse_and_map(np, 0);
|
|
|
|
if (!src->irq) {
|
|
|
|
ret = -EINVAL;
|
2017-07-15 14:19:07 +07:00
|
|
|
of_node_put(np);
|
2015-11-10 12:11:55 +07:00
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2013-12-20 10:28:51 +07:00
|
|
|
|
2015-11-10 12:11:55 +07:00
|
|
|
clk = devm_clk_get(dev, name);
|
|
|
|
if (IS_ERR(clk)) {
|
|
|
|
ret = PTR_ERR(clk);
|
2017-07-15 14:19:07 +07:00
|
|
|
of_node_put(np);
|
2015-11-10 12:11:55 +07:00
|
|
|
goto rsnd_src_probe_done;
|
|
|
|
}
|
2013-07-22 11:36:35 +07:00
|
|
|
|
2015-11-10 12:09:52 +07:00
|
|
|
ret = rsnd_mod_init(priv, rsnd_mod_get(src),
|
2018-10-30 14:46:05 +07:00
|
|
|
&rsnd_src_ops, clk, RSND_MOD_SRC, i);
|
2017-07-15 14:19:07 +07:00
|
|
|
if (ret) {
|
|
|
|
of_node_put(np);
|
2015-11-10 12:11:55 +07:00
|
|
|
goto rsnd_src_probe_done;
|
2017-07-15 14:19:07 +07:00
|
|
|
}
|
2015-11-10 12:11:55 +07:00
|
|
|
|
2016-05-12 05:36:40 +07:00
|
|
|
skip:
|
2015-11-10 12:11:55 +07:00
|
|
|
i++;
|
2013-07-29 08:59:12 +07:00
|
|
|
}
|
2013-07-22 11:36:35 +07:00
|
|
|
|
2015-11-10 12:11:55 +07:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
rsnd_src_probe_done:
|
|
|
|
of_node_put(node);
|
|
|
|
|
|
|
|
return ret;
|
2013-07-22 11:36:35 +07:00
|
|
|
}
|
2015-03-26 11:02:09 +07:00
|
|
|
|
2015-11-10 12:14:12 +07:00
|
|
|
void rsnd_src_remove(struct rsnd_priv *priv)
|
2015-03-26 11:02:09 +07:00
|
|
|
{
|
|
|
|
struct rsnd_src *src;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_rsnd_src(src, priv, i) {
|
2015-09-10 14:02:21 +07:00
|
|
|
rsnd_mod_quit(rsnd_mod_get(src));
|
2015-03-26 11:02:09 +07:00
|
|
|
}
|
|
|
|
}
|