2018-06-12 08:58:38 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//
|
|
|
|
// Renesas R-Car CMD support
|
|
|
|
//
|
|
|
|
// Copyright (C) 2015 Renesas Solutions Corp.
|
|
|
|
// Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
|
|
|
|
|
2015-10-26 11:43:21 +03:00
|
|
|
#include "rsnd.h"
|
|
|
|
|
|
|
|
struct rsnd_cmd {
|
|
|
|
struct rsnd_mod mod;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CMD_NAME "cmd"
|
|
|
|
|
|
|
|
#define rsnd_cmd_nr(priv) ((priv)->cmd_nr)
|
|
|
|
#define for_each_rsnd_cmd(pos, priv, i) \
|
|
|
|
for ((i) = 0; \
|
|
|
|
((i) < rsnd_cmd_nr(priv)) && \
|
|
|
|
((pos) = (struct rsnd_cmd *)(priv)->cmd + i); \
|
|
|
|
i++)
|
|
|
|
|
|
|
|
static int rsnd_cmd_init(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
|
|
|
{
|
|
|
|
struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
|
|
|
|
struct rsnd_mod *mix = rsnd_io_to_mod_mix(io);
|
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
|
|
|
u32 data;
|
2017-06-30 12:50:59 +03:00
|
|
|
static const u32 path[] = {
|
2017-03-01 06:51:00 +03:00
|
|
|
[1] = 1 << 0,
|
|
|
|
[5] = 1 << 8,
|
|
|
|
[6] = 1 << 12,
|
|
|
|
[9] = 1 << 15,
|
|
|
|
};
|
2015-10-26 11:43:21 +03:00
|
|
|
|
|
|
|
if (!mix && !dvc)
|
|
|
|
return 0;
|
|
|
|
|
2017-03-01 06:51:00 +03:00
|
|
|
if (ARRAY_SIZE(path) < rsnd_mod_id(mod) + 1)
|
|
|
|
return -ENXIO;
|
|
|
|
|
2015-10-26 11:43:21 +03:00
|
|
|
if (mix) {
|
|
|
|
struct rsnd_dai *rdai;
|
2016-01-21 04:57:37 +03:00
|
|
|
struct rsnd_mod *src;
|
2016-01-21 04:57:17 +03:00
|
|
|
struct rsnd_dai_stream *tio;
|
2015-10-26 11:43:21 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* it is assuming that integrater is well understanding about
|
|
|
|
* data path. Here doesn't check impossible connection,
|
|
|
|
* like src2 + src5
|
|
|
|
*/
|
|
|
|
data = 0;
|
|
|
|
for_each_rsnd_dai(rdai, priv, i) {
|
2016-01-21 04:57:17 +03:00
|
|
|
tio = &rdai->playback;
|
2016-01-21 04:57:37 +03:00
|
|
|
src = rsnd_io_to_mod_src(tio);
|
2016-01-21 04:57:17 +03:00
|
|
|
if (mix == rsnd_io_to_mod_mix(tio))
|
2015-10-26 11:43:21 +03:00
|
|
|
data |= path[rsnd_mod_id(src)];
|
|
|
|
|
2016-01-21 04:57:17 +03:00
|
|
|
tio = &rdai->capture;
|
2016-01-21 04:57:37 +03:00
|
|
|
src = rsnd_io_to_mod_src(tio);
|
2016-01-21 04:57:17 +03:00
|
|
|
if (mix == rsnd_io_to_mod_mix(tio))
|
2015-10-26 11:43:21 +03:00
|
|
|
data |= path[rsnd_mod_id(src)];
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2016-01-21 04:57:37 +03:00
|
|
|
struct rsnd_mod *src = rsnd_io_to_mod_src(io);
|
|
|
|
|
2017-06-30 12:50:59 +03:00
|
|
|
static const u8 cmd_case[] = {
|
2017-03-01 06:51:00 +03:00
|
|
|
[0] = 0x3,
|
|
|
|
[1] = 0x3,
|
|
|
|
[2] = 0x4,
|
|
|
|
[3] = 0x1,
|
|
|
|
[4] = 0x2,
|
|
|
|
[5] = 0x4,
|
|
|
|
[6] = 0x1,
|
|
|
|
[9] = 0x2,
|
2015-10-26 11:43:21 +03:00
|
|
|
};
|
|
|
|
|
2017-05-17 09:50:32 +03:00
|
|
|
if (unlikely(!src))
|
|
|
|
return -EIO;
|
|
|
|
|
2017-03-01 06:51:00 +03:00
|
|
|
data = path[rsnd_mod_id(src)] |
|
|
|
|
cmd_case[rsnd_mod_id(src)] << 16;
|
2015-10-26 11:43:21 +03:00
|
|
|
}
|
|
|
|
|
2018-07-05 05:20:04 +03:00
|
|
|
dev_dbg(dev, "ctu/mix path = 0x%08x\n", data);
|
2015-10-26 11:43:21 +03:00
|
|
|
|
|
|
|
rsnd_mod_write(mod, CMD_ROUTE_SLCT, data);
|
2017-05-16 04:51:41 +03:00
|
|
|
rsnd_mod_write(mod, CMD_BUSIF_MODE, rsnd_get_busif_shift(io, mod) | 1);
|
2015-12-08 08:38:23 +03:00
|
|
|
rsnd_mod_write(mod, CMD_BUSIF_DALIGN, rsnd_get_dalign(mod, io));
|
2015-10-26 11:43:21 +03:00
|
|
|
|
2015-11-04 11:43:33 +03:00
|
|
|
rsnd_adg_set_cmd_timsel_gen2(mod, io);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rsnd_cmd_start(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
|
|
|
{
|
2015-10-26 11:43:21 +03:00
|
|
|
rsnd_mod_write(mod, CMD_CTRL, 0x10);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-04 11:43:33 +03:00
|
|
|
static int rsnd_cmd_stop(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
|
|
|
{
|
|
|
|
rsnd_mod_write(mod, CMD_CTRL, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-26 11:43:21 +03:00
|
|
|
static struct rsnd_mod_ops rsnd_cmd_ops = {
|
2018-10-30 10:46:05 +03:00
|
|
|
.name = CMD_NAME,
|
|
|
|
.init = rsnd_cmd_init,
|
|
|
|
.start = rsnd_cmd_start,
|
|
|
|
.stop = rsnd_cmd_stop,
|
|
|
|
.get_status = rsnd_mod_get_status,
|
2015-10-26 11:43:21 +03:00
|
|
|
};
|
|
|
|
|
2018-04-06 08:41:43 +03:00
|
|
|
static struct rsnd_mod *rsnd_cmd_mod_get(struct rsnd_priv *priv, int id)
|
|
|
|
{
|
|
|
|
if (WARN_ON(id < 0 || id >= rsnd_cmd_nr(priv)))
|
|
|
|
id = 0;
|
|
|
|
|
|
|
|
return rsnd_mod_get((struct rsnd_cmd *)(priv->cmd) + id);
|
|
|
|
}
|
2015-10-26 11:43:21 +03:00
|
|
|
int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id)
|
|
|
|
{
|
|
|
|
struct rsnd_priv *priv = rsnd_io_to_priv(io);
|
|
|
|
struct rsnd_mod *mod = rsnd_cmd_mod_get(priv, id);
|
|
|
|
|
|
|
|
return rsnd_dai_connect(mod, io, mod->type);
|
|
|
|
}
|
|
|
|
|
2015-11-10 08:14:12 +03:00
|
|
|
int rsnd_cmd_probe(struct rsnd_priv *priv)
|
2015-10-26 11:43:21 +03:00
|
|
|
{
|
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
|
|
|
struct rsnd_cmd *cmd;
|
|
|
|
int i, nr, ret;
|
|
|
|
|
|
|
|
/* This driver doesn't support Gen1 at this point */
|
|
|
|
if (rsnd_is_gen1(priv))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* same number as DVC */
|
|
|
|
nr = priv->dvc_nr;
|
|
|
|
if (!nr)
|
|
|
|
return 0;
|
|
|
|
|
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 00:07:58 +03:00
|
|
|
cmd = devm_kcalloc(dev, nr, sizeof(*cmd), GFP_KERNEL);
|
2015-10-26 11:43:21 +03:00
|
|
|
if (!cmd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
priv->cmd_nr = nr;
|
|
|
|
priv->cmd = cmd;
|
|
|
|
|
|
|
|
for_each_rsnd_cmd(cmd, priv, i) {
|
|
|
|
ret = rsnd_mod_init(priv, rsnd_mod_get(cmd),
|
2016-01-21 04:58:07 +03:00
|
|
|
&rsnd_cmd_ops, NULL,
|
2018-10-30 10:46:05 +03:00
|
|
|
RSND_MOD_CMD, i);
|
2015-10-26 11:43:21 +03:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-10 08:14:12 +03:00
|
|
|
void rsnd_cmd_remove(struct rsnd_priv *priv)
|
2015-10-26 11:43:21 +03:00
|
|
|
{
|
|
|
|
struct rsnd_cmd *cmd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_rsnd_cmd(cmd, priv, i) {
|
|
|
|
rsnd_mod_quit(rsnd_mod_get(cmd));
|
|
|
|
}
|
|
|
|
}
|