2018-06-12 12:58:38 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//
|
|
|
|
// ctu.c
|
|
|
|
//
|
|
|
|
// Copyright (c) 2015 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
|
|
|
|
|
2015-07-15 14:17:17 +07:00
|
|
|
#include "rsnd.h"
|
|
|
|
|
|
|
|
#define CTU_NAME_SIZE 16
|
|
|
|
#define CTU_NAME "ctu"
|
|
|
|
|
2016-02-25 12:55:23 +07:00
|
|
|
/*
|
|
|
|
* User needs to setup CTU by amixer, and its settings are
|
|
|
|
* based on below registers
|
|
|
|
*
|
|
|
|
* CTUn_CPMDR : amixser set "CTU Pass"
|
|
|
|
* CTUn_SV0xR : amixser set "CTU SV0"
|
|
|
|
* CTUn_SV1xR : amixser set "CTU SV1"
|
|
|
|
* CTUn_SV2xR : amixser set "CTU SV2"
|
|
|
|
* CTUn_SV3xR : amixser set "CTU SV3"
|
|
|
|
*
|
|
|
|
* [CTU Pass]
|
|
|
|
* 0000: default
|
|
|
|
* 0001: Connect input data of channel 0
|
|
|
|
* 0010: Connect input data of channel 1
|
|
|
|
* 0011: Connect input data of channel 2
|
|
|
|
* 0100: Connect input data of channel 3
|
|
|
|
* 0101: Connect input data of channel 4
|
|
|
|
* 0110: Connect input data of channel 5
|
|
|
|
* 0111: Connect input data of channel 6
|
|
|
|
* 1000: Connect input data of channel 7
|
|
|
|
* 1001: Connect calculated data by scale values of matrix row 0
|
|
|
|
* 1010: Connect calculated data by scale values of matrix row 1
|
|
|
|
* 1011: Connect calculated data by scale values of matrix row 2
|
|
|
|
* 1100: Connect calculated data by scale values of matrix row 3
|
|
|
|
*
|
|
|
|
* [CTU SVx]
|
|
|
|
* [Output0] = [SV00, SV01, SV02, SV03, SV04, SV05, SV06, SV07]
|
|
|
|
* [Output1] = [SV10, SV11, SV12, SV13, SV14, SV15, SV16, SV17]
|
|
|
|
* [Output2] = [SV20, SV21, SV22, SV23, SV24, SV25, SV26, SV27]
|
|
|
|
* [Output3] = [SV30, SV31, SV32, SV33, SV34, SV35, SV36, SV37]
|
|
|
|
* [Output4] = [ 0, 0, 0, 0, 0, 0, 0, 0 ]
|
|
|
|
* [Output5] = [ 0, 0, 0, 0, 0, 0, 0, 0 ]
|
|
|
|
* [Output6] = [ 0, 0, 0, 0, 0, 0, 0, 0 ]
|
|
|
|
* [Output7] = [ 0, 0, 0, 0, 0, 0, 0, 0 ]
|
|
|
|
*
|
|
|
|
* [SVxx]
|
|
|
|
* Plus Minus
|
|
|
|
* value time dB value time dB
|
|
|
|
* -----------------------------------------------------------------------
|
|
|
|
* H'7F_FFFF 2 6 H'80_0000 2 6
|
|
|
|
* ...
|
|
|
|
* H'40_0000 1 0 H'C0_0000 1 0
|
|
|
|
* ...
|
|
|
|
* H'00_0001 2.38 x 10^-7 -132
|
|
|
|
* H'00_0000 0 Mute H'FF_FFFF 2.38 x 10^-7 -132
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Ex) Input ch -> Output ch
|
|
|
|
* 1ch -> 0ch
|
|
|
|
* 0ch -> 1ch
|
|
|
|
*
|
|
|
|
* amixer set "CTU Reset" on
|
|
|
|
* amixer set "CTU Pass" 9,10
|
|
|
|
* amixer set "CTU SV0" 0,4194304
|
|
|
|
* amixer set "CTU SV1" 4194304,0
|
|
|
|
* or
|
|
|
|
* amixer set "CTU Reset" on
|
|
|
|
* amixer set "CTU Pass" 2,1
|
|
|
|
*/
|
|
|
|
|
2015-07-15 14:17:17 +07:00
|
|
|
struct rsnd_ctu {
|
|
|
|
struct rsnd_mod mod;
|
2016-02-25 12:55:23 +07:00
|
|
|
struct rsnd_kctrl_cfg_m pass;
|
2018-12-12 14:03:58 +07:00
|
|
|
struct rsnd_kctrl_cfg_m sv[4];
|
2016-02-25 12:55:23 +07:00
|
|
|
struct rsnd_kctrl_cfg_s reset;
|
2016-02-25 12:53:00 +07:00
|
|
|
int channels;
|
2017-10-02 06:48:46 +07:00
|
|
|
u32 flags;
|
2015-07-15 14:17:17 +07:00
|
|
|
};
|
|
|
|
|
2017-10-02 06:48:46 +07:00
|
|
|
#define KCTRL_INITIALIZED (1 << 0)
|
|
|
|
|
2015-07-15 14:17:17 +07:00
|
|
|
#define rsnd_ctu_nr(priv) ((priv)->ctu_nr)
|
|
|
|
#define for_each_rsnd_ctu(pos, priv, i) \
|
|
|
|
for ((i) = 0; \
|
|
|
|
((i) < rsnd_ctu_nr(priv)) && \
|
|
|
|
((pos) = (struct rsnd_ctu *)(priv)->ctu + i); \
|
|
|
|
i++)
|
|
|
|
|
2016-02-25 12:53:00 +07:00
|
|
|
#define rsnd_mod_to_ctu(_mod) \
|
|
|
|
container_of((_mod), struct rsnd_ctu, mod)
|
|
|
|
|
2015-11-10 12:12:13 +07:00
|
|
|
#define rsnd_ctu_get(priv, id) ((struct rsnd_ctu *)(priv->ctu) + id)
|
2016-01-21 08:58:53 +07:00
|
|
|
|
|
|
|
static void rsnd_ctu_activation(struct rsnd_mod *mod)
|
|
|
|
{
|
|
|
|
rsnd_mod_write(mod, CTU_SWRSR, 0);
|
|
|
|
rsnd_mod_write(mod, CTU_SWRSR, 1);
|
|
|
|
}
|
|
|
|
|
2016-01-21 08:59:12 +07:00
|
|
|
static void rsnd_ctu_halt(struct rsnd_mod *mod)
|
|
|
|
{
|
|
|
|
rsnd_mod_write(mod, CTU_CTUIR, 1);
|
|
|
|
rsnd_mod_write(mod, CTU_SWRSR, 0);
|
|
|
|
}
|
|
|
|
|
2015-10-26 15:43:21 +07:00
|
|
|
static int rsnd_ctu_probe_(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
|
|
|
{
|
2019-06-18 12:19:53 +07:00
|
|
|
return rsnd_cmd_attach(io, rsnd_mod_id(mod));
|
2015-10-26 15:43:21 +07:00
|
|
|
}
|
|
|
|
|
2016-01-21 08:59:33 +07:00
|
|
|
static void rsnd_ctu_value_init(struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_mod *mod)
|
|
|
|
{
|
2016-02-25 12:55:23 +07:00
|
|
|
struct rsnd_ctu *ctu = rsnd_mod_to_ctu(mod);
|
|
|
|
u32 cpmdr = 0;
|
|
|
|
u32 scmdr = 0;
|
2018-12-12 14:03:58 +07:00
|
|
|
int i, j;
|
2016-02-25 12:55:23 +07:00
|
|
|
|
|
|
|
for (i = 0; i < RSND_MAX_CHANNELS; i++) {
|
2017-10-11 11:42:34 +07:00
|
|
|
u32 val = rsnd_kctrl_valm(ctu->pass, i);
|
2016-02-25 12:55:23 +07:00
|
|
|
|
|
|
|
cpmdr |= val << (28 - (i * 4));
|
|
|
|
|
|
|
|
if ((val > 0x8) && (scmdr < (val - 0x8)))
|
|
|
|
scmdr = val - 0x8;
|
|
|
|
}
|
|
|
|
|
2016-01-21 08:59:33 +07:00
|
|
|
rsnd_mod_write(mod, CTU_CTUIR, 1);
|
|
|
|
|
2016-02-25 12:54:58 +07:00
|
|
|
rsnd_mod_write(mod, CTU_ADINR, rsnd_runtime_channel_original(io));
|
2016-01-21 08:59:33 +07:00
|
|
|
|
2016-02-25 12:55:23 +07:00
|
|
|
rsnd_mod_write(mod, CTU_CPMDR, cpmdr);
|
|
|
|
|
|
|
|
rsnd_mod_write(mod, CTU_SCMDR, scmdr);
|
|
|
|
|
2018-12-12 14:03:58 +07:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
|
|
|
|
if (i >= scmdr)
|
|
|
|
break;
|
|
|
|
|
|
|
|
for (j = 0; j < RSND_MAX_CHANNELS; j++)
|
|
|
|
rsnd_mod_write(mod, CTU_SVxxR(i, j), rsnd_kctrl_valm(ctu->sv[i], j));
|
2016-02-25 12:55:23 +07:00
|
|
|
}
|
2016-01-21 08:59:33 +07:00
|
|
|
|
|
|
|
rsnd_mod_write(mod, CTU_CTUIR, 0);
|
|
|
|
}
|
|
|
|
|
2016-02-25 12:55:23 +07:00
|
|
|
static void rsnd_ctu_value_reset(struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_mod *mod)
|
|
|
|
{
|
|
|
|
struct rsnd_ctu *ctu = rsnd_mod_to_ctu(mod);
|
|
|
|
int i;
|
|
|
|
|
2017-10-11 11:42:34 +07:00
|
|
|
if (!rsnd_kctrl_vals(ctu->reset))
|
2016-02-25 12:55:23 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < RSND_MAX_CHANNELS; i++) {
|
2017-10-11 11:42:34 +07:00
|
|
|
rsnd_kctrl_valm(ctu->pass, i) = 0;
|
2018-12-12 14:03:58 +07:00
|
|
|
rsnd_kctrl_valm(ctu->sv[0], i) = 0;
|
|
|
|
rsnd_kctrl_valm(ctu->sv[1], i) = 0;
|
|
|
|
rsnd_kctrl_valm(ctu->sv[2], i) = 0;
|
|
|
|
rsnd_kctrl_valm(ctu->sv[3], i) = 0;
|
2016-02-25 12:55:23 +07:00
|
|
|
}
|
2017-10-11 11:42:34 +07:00
|
|
|
rsnd_kctrl_vals(ctu->reset) = 0;
|
2016-02-25 12:55:23 +07:00
|
|
|
}
|
|
|
|
|
2015-07-15 14:17:17 +07:00
|
|
|
static int rsnd_ctu_init(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
|
|
|
{
|
2015-10-22 10:15:04 +07:00
|
|
|
rsnd_mod_power_on(mod);
|
2015-07-15 14:17:17 +07:00
|
|
|
|
2016-01-21 08:58:53 +07:00
|
|
|
rsnd_ctu_activation(mod);
|
|
|
|
|
2016-01-21 08:59:33 +07:00
|
|
|
rsnd_ctu_value_init(io, mod);
|
2015-07-15 14:17:17 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rsnd_ctu_quit(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct rsnd_priv *priv)
|
|
|
|
{
|
2016-01-21 08:59:12 +07:00
|
|
|
rsnd_ctu_halt(mod);
|
|
|
|
|
2015-10-22 10:15:04 +07:00
|
|
|
rsnd_mod_power_off(mod);
|
2015-07-15 14:17:17 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-25 12:55:23 +07:00
|
|
|
static int rsnd_ctu_pcm_new(struct rsnd_mod *mod,
|
|
|
|
struct rsnd_dai_stream *io,
|
|
|
|
struct snd_soc_pcm_runtime *rtd)
|
|
|
|
{
|
|
|
|
struct rsnd_ctu *ctu = rsnd_mod_to_ctu(mod);
|
|
|
|
int ret;
|
|
|
|
|
2017-10-02 06:48:46 +07:00
|
|
|
if (rsnd_flags_has(ctu, KCTRL_INITIALIZED))
|
|
|
|
return 0;
|
|
|
|
|
2016-02-25 12:55:23 +07:00
|
|
|
/* CTU Pass */
|
|
|
|
ret = rsnd_kctrl_new_m(mod, io, rtd, "CTU Pass",
|
2017-06-07 07:11:48 +07:00
|
|
|
rsnd_kctrl_accept_anytime,
|
2016-02-25 12:55:23 +07:00
|
|
|
NULL,
|
|
|
|
&ctu->pass, RSND_MAX_CHANNELS,
|
|
|
|
0xC);
|
|
|
|
|
|
|
|
/* ROW0 */
|
|
|
|
ret = rsnd_kctrl_new_m(mod, io, rtd, "CTU SV0",
|
2017-06-07 07:11:48 +07:00
|
|
|
rsnd_kctrl_accept_anytime,
|
2016-02-25 12:55:23 +07:00
|
|
|
NULL,
|
2018-12-12 14:03:58 +07:00
|
|
|
&ctu->sv[0], RSND_MAX_CHANNELS,
|
2016-02-25 12:55:23 +07:00
|
|
|
0x00FFFFFF);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ROW1 */
|
|
|
|
ret = rsnd_kctrl_new_m(mod, io, rtd, "CTU SV1",
|
2017-06-07 07:11:48 +07:00
|
|
|
rsnd_kctrl_accept_anytime,
|
2016-02-25 12:55:23 +07:00
|
|
|
NULL,
|
2018-12-12 14:03:58 +07:00
|
|
|
&ctu->sv[1], RSND_MAX_CHANNELS,
|
2016-02-25 12:55:23 +07:00
|
|
|
0x00FFFFFF);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ROW2 */
|
|
|
|
ret = rsnd_kctrl_new_m(mod, io, rtd, "CTU SV2",
|
2017-06-07 07:11:48 +07:00
|
|
|
rsnd_kctrl_accept_anytime,
|
2016-02-25 12:55:23 +07:00
|
|
|
NULL,
|
2018-12-12 14:03:58 +07:00
|
|
|
&ctu->sv[2], RSND_MAX_CHANNELS,
|
2016-02-25 12:55:23 +07:00
|
|
|
0x00FFFFFF);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ROW3 */
|
|
|
|
ret = rsnd_kctrl_new_m(mod, io, rtd, "CTU SV3",
|
2017-06-07 07:11:48 +07:00
|
|
|
rsnd_kctrl_accept_anytime,
|
2016-02-25 12:55:23 +07:00
|
|
|
NULL,
|
2018-12-12 14:03:58 +07:00
|
|
|
&ctu->sv[3], RSND_MAX_CHANNELS,
|
2016-02-25 12:55:23 +07:00
|
|
|
0x00FFFFFF);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Reset */
|
|
|
|
ret = rsnd_kctrl_new_s(mod, io, rtd, "CTU Reset",
|
2017-06-07 07:11:48 +07:00
|
|
|
rsnd_kctrl_accept_anytime,
|
2016-02-25 12:55:23 +07:00
|
|
|
rsnd_ctu_value_reset,
|
|
|
|
&ctu->reset, 1);
|
|
|
|
|
2017-10-02 06:48:46 +07:00
|
|
|
rsnd_flags_set(ctu, KCTRL_INITIALIZED);
|
|
|
|
|
2016-02-25 12:55:23 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-30 14:47:18 +07:00
|
|
|
static int rsnd_ctu_id(struct rsnd_mod *mod)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* ctu00: -> 0, ctu01: -> 0, ctu02: -> 0, ctu03: -> 0
|
|
|
|
* ctu10: -> 1, ctu11: -> 1, ctu12: -> 1, ctu13: -> 1
|
|
|
|
*/
|
|
|
|
return mod->id / 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rsnd_ctu_id_sub(struct rsnd_mod *mod)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* ctu00: -> 0, ctu01: -> 1, ctu02: -> 2, ctu03: -> 3
|
|
|
|
* ctu10: -> 0, ctu11: -> 1, ctu12: -> 2, ctu13: -> 3
|
|
|
|
*/
|
|
|
|
return mod->id % 4;
|
|
|
|
}
|
|
|
|
|
2015-07-15 14:17:17 +07:00
|
|
|
static struct rsnd_mod_ops rsnd_ctu_ops = {
|
|
|
|
.name = CTU_NAME,
|
2015-10-26 15:43:21 +07:00
|
|
|
.probe = rsnd_ctu_probe_,
|
2015-07-15 14:17:17 +07:00
|
|
|
.init = rsnd_ctu_init,
|
|
|
|
.quit = rsnd_ctu_quit,
|
2016-02-25 12:55:23 +07:00
|
|
|
.pcm_new = rsnd_ctu_pcm_new,
|
2018-10-30 14:46:05 +07:00
|
|
|
.get_status = rsnd_mod_get_status,
|
2018-10-30 14:47:18 +07:00
|
|
|
.id = rsnd_ctu_id,
|
|
|
|
.id_sub = rsnd_ctu_id_sub,
|
2018-12-04 15:00:47 +07:00
|
|
|
.id_cmd = rsnd_mod_id_raw,
|
2015-07-15 14:17:17 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id)
|
|
|
|
{
|
|
|
|
if (WARN_ON(id < 0 || id >= rsnd_ctu_nr(priv)))
|
|
|
|
id = 0;
|
|
|
|
|
2015-11-10 12:12:13 +07:00
|
|
|
return rsnd_mod_get(rsnd_ctu_get(priv, id));
|
2015-07-15 14:17:17 +07:00
|
|
|
}
|
|
|
|
|
2015-11-10 12:14:12 +07:00
|
|
|
int rsnd_ctu_probe(struct rsnd_priv *priv)
|
2015-07-15 14:17:17 +07:00
|
|
|
{
|
2015-11-10 12:12:13 +07:00
|
|
|
struct device_node *node;
|
|
|
|
struct device_node *np;
|
2015-07-15 14:17:17 +07:00
|
|
|
struct device *dev = rsnd_priv_to_dev(priv);
|
|
|
|
struct rsnd_ctu *ctu;
|
|
|
|
struct clk *clk;
|
|
|
|
char name[CTU_NAME_SIZE];
|
|
|
|
int i, nr, ret;
|
|
|
|
|
|
|
|
/* This driver doesn't support Gen1 at this point */
|
2015-10-15 10:25:28 +07:00
|
|
|
if (rsnd_is_gen1(priv))
|
|
|
|
return 0;
|
2015-07-15 14:17:17 +07:00
|
|
|
|
2015-11-10 12:12:13 +07:00
|
|
|
node = rsnd_ctu_of_node(priv);
|
|
|
|
if (!node)
|
|
|
|
return 0; /* not used is not error */
|
2015-07-15 14:17:17 +07:00
|
|
|
|
2015-11-10 12:12:13 +07:00
|
|
|
nr = of_get_child_count(node);
|
|
|
|
if (!nr) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto rsnd_ctu_probe_done;
|
|
|
|
}
|
2015-07-15 14:17:17 +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
|
|
|
ctu = devm_kcalloc(dev, nr, sizeof(*ctu), GFP_KERNEL);
|
2015-11-10 12:12:13 +07:00
|
|
|
if (!ctu) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto rsnd_ctu_probe_done;
|
|
|
|
}
|
2015-07-15 14:17:17 +07:00
|
|
|
|
|
|
|
priv->ctu_nr = nr;
|
|
|
|
priv->ctu = ctu;
|
|
|
|
|
2015-11-10 12:12:13 +07:00
|
|
|
i = 0;
|
2015-12-14 19:04:54 +07:00
|
|
|
ret = 0;
|
2015-11-10 12:12:13 +07:00
|
|
|
for_each_child_of_node(node, np) {
|
|
|
|
ctu = rsnd_ctu_get(priv, i);
|
|
|
|
|
2015-07-15 14:17:17 +07:00
|
|
|
/*
|
|
|
|
* CTU00, CTU01, CTU02, CTU03 => CTU0
|
|
|
|
* CTU10, CTU11, CTU12, CTU13 => CTU1
|
|
|
|
*/
|
|
|
|
snprintf(name, CTU_NAME_SIZE, "%s.%d",
|
|
|
|
CTU_NAME, i / 4);
|
|
|
|
|
|
|
|
clk = devm_clk_get(dev, name);
|
2015-11-10 12:12:13 +07:00
|
|
|
if (IS_ERR(clk)) {
|
|
|
|
ret = PTR_ERR(clk);
|
2017-07-15 14:19:07 +07:00
|
|
|
of_node_put(np);
|
2015-11-10 12:12:13 +07:00
|
|
|
goto rsnd_ctu_probe_done;
|
|
|
|
}
|
2015-07-15 14:17:17 +07:00
|
|
|
|
2015-09-10 14:02:21 +07:00
|
|
|
ret = rsnd_mod_init(priv, rsnd_mod_get(ctu), &rsnd_ctu_ops,
|
2018-10-30 14:46:05 +07:00
|
|
|
clk, RSND_MOD_CTU, i);
|
2017-07-15 14:19:07 +07:00
|
|
|
if (ret) {
|
|
|
|
of_node_put(np);
|
2015-11-10 12:12:13 +07:00
|
|
|
goto rsnd_ctu_probe_done;
|
2017-07-15 14:19:07 +07:00
|
|
|
}
|
2015-11-10 12:12:13 +07:00
|
|
|
|
|
|
|
i++;
|
2015-07-15 14:17:17 +07:00
|
|
|
}
|
|
|
|
|
2015-11-10 12:12:13 +07:00
|
|
|
|
|
|
|
rsnd_ctu_probe_done:
|
|
|
|
of_node_put(node);
|
|
|
|
|
|
|
|
return ret;
|
2015-07-15 14:17:17 +07:00
|
|
|
}
|
|
|
|
|
2015-11-10 12:14:12 +07:00
|
|
|
void rsnd_ctu_remove(struct rsnd_priv *priv)
|
2015-07-15 14:17:17 +07:00
|
|
|
{
|
|
|
|
struct rsnd_ctu *ctu;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_rsnd_ctu(ctu, priv, i) {
|
2015-09-10 14:02:21 +07:00
|
|
|
rsnd_mod_quit(rsnd_mod_get(ctu));
|
2015-07-15 14:17:17 +07:00
|
|
|
}
|
|
|
|
}
|