xref: /openbmc/linux/sound/soc/sh/rcar/gen.c (revision c0ea089d)
11e0edd4dSKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
21e0edd4dSKuninori Morimoto //
31e0edd4dSKuninori Morimoto // Renesas R-Car Gen1 SRU/SSI support
41e0edd4dSKuninori Morimoto //
51e0edd4dSKuninori Morimoto // Copyright (C) 2013 Renesas Solutions Corp.
61e0edd4dSKuninori Morimoto // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7ace0eb1eSKuninori Morimoto 
8ace0eb1eSKuninori Morimoto /*
9ace0eb1eSKuninori Morimoto  * #define DEBUG
10ace0eb1eSKuninori Morimoto  *
11ace0eb1eSKuninori Morimoto  * you can also add below in
12ace0eb1eSKuninori Morimoto  * ${LINUX}/drivers/base/regmap/regmap.c
13ace0eb1eSKuninori Morimoto  * for regmap debug
14ace0eb1eSKuninori Morimoto  *
15ace0eb1eSKuninori Morimoto  * #define LOG_DEVICE "xxxx.rcar_sound"
16ace0eb1eSKuninori Morimoto  */
17ace0eb1eSKuninori Morimoto 
183337744aSKuninori Morimoto #include "rsnd.h"
193337744aSKuninori Morimoto 
203337744aSKuninori Morimoto struct rsnd_gen {
213337744aSKuninori Morimoto 	struct rsnd_gen_ops *ops;
2255e5b6fdSKuninori Morimoto 
239993c16dSKuninori Morimoto 	/* RSND_BASE_MAX base */
249993c16dSKuninori Morimoto 	void __iomem *base[RSND_BASE_MAX];
259993c16dSKuninori Morimoto 	phys_addr_t res[RSND_BASE_MAX];
26b8c63786SKuninori Morimoto 	struct regmap *regmap[RSND_BASE_MAX];
279993c16dSKuninori Morimoto 
289993c16dSKuninori Morimoto 	/* RSND_REG_MAX base */
2955e5b6fdSKuninori Morimoto 	struct regmap_field *regs[RSND_REG_MAX];
300719ecf7SKuninori Morimoto 	const char *reg_name[RSND_REG_MAX];
313337744aSKuninori Morimoto };
323337744aSKuninori Morimoto 
333337744aSKuninori Morimoto #define rsnd_priv_to_gen(p)	((struct rsnd_gen *)(p)->gen)
340719ecf7SKuninori Morimoto #define rsnd_reg_name(gen, id)	((gen)->reg_name[id])
353337744aSKuninori Morimoto 
36b8c63786SKuninori Morimoto struct rsnd_regmap_field_conf {
37b8c63786SKuninori Morimoto 	int idx;
38b8c63786SKuninori Morimoto 	unsigned int reg_offset;
39b8c63786SKuninori Morimoto 	unsigned int id_offset;
400719ecf7SKuninori Morimoto 	const char *reg_name;
41b8c63786SKuninori Morimoto };
42b8c63786SKuninori Morimoto 
430719ecf7SKuninori Morimoto #define RSND_REG_SET(id, offset, _id_offset, n)	\
44b8c63786SKuninori Morimoto {						\
45b8c63786SKuninori Morimoto 	.idx = id,				\
46b8c63786SKuninori Morimoto 	.reg_offset = offset,			\
4755e5b6fdSKuninori Morimoto 	.id_offset = _id_offset,		\
480719ecf7SKuninori Morimoto 	.reg_name = n,				\
4955e5b6fdSKuninori Morimoto }
50b8c63786SKuninori Morimoto /* single address mapping */
51b8c63786SKuninori Morimoto #define RSND_GEN_S_REG(id, offset)	\
520719ecf7SKuninori Morimoto 	RSND_REG_SET(RSND_REG_##id, offset, 0, #id)
53b8c63786SKuninori Morimoto 
54b8c63786SKuninori Morimoto /* multi address mapping */
55b8c63786SKuninori Morimoto #define RSND_GEN_M_REG(id, offset, _id_offset)	\
560719ecf7SKuninori Morimoto 	RSND_REG_SET(RSND_REG_##id, offset, _id_offset, #id)
5755e5b6fdSKuninori Morimoto 
5855e5b6fdSKuninori Morimoto /*
5955e5b6fdSKuninori Morimoto  *		basic function
6055e5b6fdSKuninori Morimoto  */
6142ee5d22SKuninori Morimoto static int rsnd_is_accessible_reg(struct rsnd_priv *priv,
6242ee5d22SKuninori Morimoto 				  struct rsnd_gen *gen, enum rsnd_reg reg)
6342ee5d22SKuninori Morimoto {
6442ee5d22SKuninori Morimoto 	if (!gen->regs[reg]) {
6542ee5d22SKuninori Morimoto 		struct device *dev = rsnd_priv_to_dev(priv);
6642ee5d22SKuninori Morimoto 
6742ee5d22SKuninori Morimoto 		dev_err(dev, "unsupported register access %x\n", reg);
6842ee5d22SKuninori Morimoto 		return 0;
6942ee5d22SKuninori Morimoto 	}
7042ee5d22SKuninori Morimoto 
7142ee5d22SKuninori Morimoto 	return 1;
7242ee5d22SKuninori Morimoto }
7342ee5d22SKuninori Morimoto 
7455e5b6fdSKuninori Morimoto u32 rsnd_read(struct rsnd_priv *priv,
7555e5b6fdSKuninori Morimoto 	      struct rsnd_mod *mod, enum rsnd_reg reg)
7655e5b6fdSKuninori Morimoto {
77b8c63786SKuninori Morimoto 	struct device *dev = rsnd_priv_to_dev(priv);
7855e5b6fdSKuninori Morimoto 	struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
7955e5b6fdSKuninori Morimoto 	u32 val;
8055e5b6fdSKuninori Morimoto 
8142ee5d22SKuninori Morimoto 	if (!rsnd_is_accessible_reg(priv, gen, reg))
8242ee5d22SKuninori Morimoto 		return 0;
8342ee5d22SKuninori Morimoto 
84c9b9638fSKuninori Morimoto 	regmap_fields_read(gen->regs[reg], rsnd_mod_id(mod), &val);
85c9b9638fSKuninori Morimoto 
86c0ea089dSKuninori Morimoto 	dev_dbg(dev, "r %s - %-18s (%4d) : %08x\n",
87c0ea089dSKuninori Morimoto 		rsnd_mod_name(mod),
880719ecf7SKuninori Morimoto 		rsnd_reg_name(gen, reg), reg, val);
8955e5b6fdSKuninori Morimoto 
9055e5b6fdSKuninori Morimoto 	return val;
9155e5b6fdSKuninori Morimoto }
9255e5b6fdSKuninori Morimoto 
9355e5b6fdSKuninori Morimoto void rsnd_write(struct rsnd_priv *priv,
9455e5b6fdSKuninori Morimoto 		struct rsnd_mod *mod,
9555e5b6fdSKuninori Morimoto 		enum rsnd_reg reg, u32 data)
9655e5b6fdSKuninori Morimoto {
97b8c63786SKuninori Morimoto 	struct device *dev = rsnd_priv_to_dev(priv);
9855e5b6fdSKuninori Morimoto 	struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
9955e5b6fdSKuninori Morimoto 
10042ee5d22SKuninori Morimoto 	if (!rsnd_is_accessible_reg(priv, gen, reg))
10142ee5d22SKuninori Morimoto 		return;
10242ee5d22SKuninori Morimoto 
1037b47ab47SKuninori Morimoto 	regmap_fields_force_write(gen->regs[reg], rsnd_mod_id(mod), data);
1040719ecf7SKuninori Morimoto 
105c0ea089dSKuninori Morimoto 	dev_dbg(dev, "w %s - %-18s (%4d) : %08x\n",
106c0ea089dSKuninori Morimoto 		rsnd_mod_name(mod),
1070719ecf7SKuninori Morimoto 		rsnd_reg_name(gen, reg), reg, data);
1087b47ab47SKuninori Morimoto }
1097b47ab47SKuninori Morimoto 
11055e5b6fdSKuninori Morimoto void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod,
11155e5b6fdSKuninori Morimoto 	       enum rsnd_reg reg, u32 mask, u32 data)
11255e5b6fdSKuninori Morimoto {
1134f8f86aaSKuninori Morimoto 	struct device *dev = rsnd_priv_to_dev(priv);
11455e5b6fdSKuninori Morimoto 	struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
11555e5b6fdSKuninori Morimoto 
11642ee5d22SKuninori Morimoto 	if (!rsnd_is_accessible_reg(priv, gen, reg))
11742ee5d22SKuninori Morimoto 		return;
11842ee5d22SKuninori Morimoto 
119b3fc95adSKuninori Morimoto 	regmap_fields_force_update_bits(gen->regs[reg],
120b3fc95adSKuninori Morimoto 					rsnd_mod_id(mod), mask, data);
1210719ecf7SKuninori Morimoto 
122c0ea089dSKuninori Morimoto 	dev_dbg(dev, "b %s - %-18s (%4d) : %08x/%08x\n",
123c0ea089dSKuninori Morimoto 		rsnd_mod_name(mod),
1240719ecf7SKuninori Morimoto 		rsnd_reg_name(gen, reg), reg, data, mask);
1250719ecf7SKuninori Morimoto 
12655e5b6fdSKuninori Morimoto }
12755e5b6fdSKuninori Morimoto 
128c5212b45SKuninori Morimoto phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id)
129c5212b45SKuninori Morimoto {
130c5212b45SKuninori Morimoto 	struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
131c5212b45SKuninori Morimoto 
132c5212b45SKuninori Morimoto 	return	gen->res[reg_id];
133c5212b45SKuninori Morimoto }
134c5212b45SKuninori Morimoto 
1357277911cSKuninori Morimoto #define rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf)		\
1367277911cSKuninori Morimoto 	_rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf, ARRAY_SIZE(conf))
137b8c63786SKuninori Morimoto static int _rsnd_gen_regmap_init(struct rsnd_priv *priv,
138b8c63786SKuninori Morimoto 				 int id_size,
139b8c63786SKuninori Morimoto 				 int reg_id,
1407277911cSKuninori Morimoto 				 const char *name,
1410719ecf7SKuninori Morimoto 				 const struct rsnd_regmap_field_conf *conf,
142b8c63786SKuninori Morimoto 				 int conf_size)
143c1e6cc5eSKuninori Morimoto {
144b8c63786SKuninori Morimoto 	struct platform_device *pdev = rsnd_priv_to_pdev(priv);
145b8c63786SKuninori Morimoto 	struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
146c1e6cc5eSKuninori Morimoto 	struct device *dev = rsnd_priv_to_dev(priv);
147b8c63786SKuninori Morimoto 	struct resource *res;
148c1e6cc5eSKuninori Morimoto 	struct regmap_config regc;
149b8c63786SKuninori Morimoto 	struct regmap_field *regs;
150b8c63786SKuninori Morimoto 	struct regmap *regmap;
151b8c63786SKuninori Morimoto 	struct reg_field regf;
152b8c63786SKuninori Morimoto 	void __iomem *base;
153b8c63786SKuninori Morimoto 	int i;
154c1e6cc5eSKuninori Morimoto 
155c1e6cc5eSKuninori Morimoto 	memset(&regc, 0, sizeof(regc));
156c1e6cc5eSKuninori Morimoto 	regc.reg_bits = 32;
157c1e6cc5eSKuninori Morimoto 	regc.val_bits = 32;
158b8c63786SKuninori Morimoto 	regc.reg_stride = 4;
159530b7b4aSKuninori Morimoto 	regc.name = name;
160c1e6cc5eSKuninori Morimoto 
1617277911cSKuninori Morimoto 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
1627277911cSKuninori Morimoto 	if (!res)
163b8c63786SKuninori Morimoto 		res = platform_get_resource(pdev, IORESOURCE_MEM, reg_id);
164b8c63786SKuninori Morimoto 	if (!res)
165b8c63786SKuninori Morimoto 		return -ENODEV;
166c1e6cc5eSKuninori Morimoto 
167b8c63786SKuninori Morimoto 	base = devm_ioremap_resource(dev, res);
168b8c63786SKuninori Morimoto 	if (IS_ERR(base))
169b8c63786SKuninori Morimoto 		return PTR_ERR(base);
17042ee5d22SKuninori Morimoto 
171b8c63786SKuninori Morimoto 	regmap = devm_regmap_init_mmio(dev, base, &regc);
172b8c63786SKuninori Morimoto 	if (IS_ERR(regmap))
173b8c63786SKuninori Morimoto 		return PTR_ERR(regmap);
174c1e6cc5eSKuninori Morimoto 
1759993c16dSKuninori Morimoto 	/* RSND_BASE_MAX base */
176b8c63786SKuninori Morimoto 	gen->base[reg_id] = base;
177b8c63786SKuninori Morimoto 	gen->regmap[reg_id] = regmap;
178c5212b45SKuninori Morimoto 	gen->res[reg_id] = res->start;
179b8c63786SKuninori Morimoto 
180b8c63786SKuninori Morimoto 	for (i = 0; i < conf_size; i++) {
181b8c63786SKuninori Morimoto 
182b8c63786SKuninori Morimoto 		regf.reg	= conf[i].reg_offset;
183b8c63786SKuninori Morimoto 		regf.id_offset	= conf[i].id_offset;
184b8c63786SKuninori Morimoto 		regf.lsb	= 0;
185b8c63786SKuninori Morimoto 		regf.msb	= 31;
186b8c63786SKuninori Morimoto 		regf.id_size	= id_size;
187b8c63786SKuninori Morimoto 
188b8c63786SKuninori Morimoto 		regs = devm_regmap_field_alloc(dev, regmap, regf);
189b8c63786SKuninori Morimoto 		if (IS_ERR(regs))
190b8c63786SKuninori Morimoto 			return PTR_ERR(regs);
191b8c63786SKuninori Morimoto 
1929993c16dSKuninori Morimoto 		/* RSND_REG_MAX base */
193b8c63786SKuninori Morimoto 		gen->regs[conf[i].idx] = regs;
1940719ecf7SKuninori Morimoto 		gen->reg_name[conf[i].idx] = conf[i].reg_name;
195c1e6cc5eSKuninori Morimoto 	}
196c1e6cc5eSKuninori Morimoto 
197c1e6cc5eSKuninori Morimoto 	return 0;
198c1e6cc5eSKuninori Morimoto }
1993337744aSKuninori Morimoto 
200994a9df1SKuninori Morimoto /*
201994a9df1SKuninori Morimoto  *		Gen2
202994a9df1SKuninori Morimoto  */
2032ea6b074SKuninori Morimoto static int rsnd_gen2_probe(struct rsnd_priv *priv)
204507d466cSKuninori Morimoto {
205cc9bdcf2SArnd Bergmann 	static const struct rsnd_regmap_field_conf conf_ssiu[] = {
206b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SSI_MODE0,	0x800),
207b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SSI_MODE1,	0x804),
208b4c83b17SKuninori Morimoto 		RSND_GEN_S_REG(SSI_MODE2,	0x808),
209b4c83b17SKuninori Morimoto 		RSND_GEN_S_REG(SSI_CONTROL,	0x810),
210814efe3eSKuninori Morimoto 		RSND_GEN_S_REG(SSI_SYS_STATUS0,	0x840),
211814efe3eSKuninori Morimoto 		RSND_GEN_S_REG(SSI_SYS_STATUS1,	0x844),
212814efe3eSKuninori Morimoto 		RSND_GEN_S_REG(SSI_SYS_STATUS2,	0x848),
213814efe3eSKuninori Morimoto 		RSND_GEN_S_REG(SSI_SYS_STATUS3,	0x84c),
214814efe3eSKuninori Morimoto 		RSND_GEN_S_REG(SSI_SYS_STATUS4,	0x880),
215814efe3eSKuninori Morimoto 		RSND_GEN_S_REG(SSI_SYS_STATUS5,	0x884),
216814efe3eSKuninori Morimoto 		RSND_GEN_S_REG(SSI_SYS_STATUS6,	0x888),
217814efe3eSKuninori Morimoto 		RSND_GEN_S_REG(SSI_SYS_STATUS7,	0x88c),
2187fa72ccaSKuninori Morimoto 		RSND_GEN_S_REG(HDMI0_SEL,	0x9e0),
2197fa72ccaSKuninori Morimoto 		RSND_GEN_S_REG(HDMI1_SEL,	0x9e4),
220b4c83b17SKuninori Morimoto 
221b8c63786SKuninori Morimoto 		/* FIXME: it needs SSI_MODE2/3 in the future */
2228c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF0_MODE,		0x0,	0x80),
2238c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF0_ADINR,	0x4,	0x80),
2248c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF0_DALIGN,	0x8,	0x80),
2258c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF1_MODE,		0x20,	0x80),
2268c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF1_ADINR,	0x24,	0x80),
2278c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF1_DALIGN,	0x28,	0x80),
2288c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF2_MODE,		0x40,	0x80),
2298c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF2_ADINR,	0x44,	0x80),
2308c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF2_DALIGN,	0x48,	0x80),
2318c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF3_MODE,		0x60,	0x80),
2328c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF3_ADINR,	0x64,	0x80),
2338c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF3_DALIGN,	0x68,	0x80),
2348c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF4_MODE,		0x500,	0x80),
2358c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF4_ADINR,	0x504,	0x80),
2368c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF4_DALIGN,	0x508,	0x80),
2378c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF5_MODE,		0x520,	0x80),
2388c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF5_ADINR,	0x524,	0x80),
2398c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF5_DALIGN,	0x528,	0x80),
2408c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF6_MODE,		0x540,	0x80),
2418c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF6_ADINR,	0x544,	0x80),
2428c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF6_DALIGN,	0x548,	0x80),
2438c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF7_MODE,		0x560,	0x80),
2448c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF7_ADINR,	0x564,	0x80),
2458c9d7503SJiada Wang 		RSND_GEN_M_REG(SSI_BUSIF7_DALIGN,	0x568,	0x80),
246186fadc1SKuninori Morimoto 		RSND_GEN_M_REG(SSI_MODE,		0xc,	0x80),
247b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSI_CTRL,		0x10,	0x80),
248efa991dcSKuninori Morimoto 		RSND_GEN_M_REG(SSI_INT_ENABLE,		0x18,	0x80),
249b8c63786SKuninori Morimoto 	};
250bf4e8d7cSKuninori Morimoto 
251cc9bdcf2SArnd Bergmann 	static const struct rsnd_regmap_field_conf conf_scu[] = {
252bf4e8d7cSKuninori Morimoto 		RSND_GEN_M_REG(SRC_I_BUSIF_MODE,0x0,	0x20),
253bf4e8d7cSKuninori Morimoto 		RSND_GEN_M_REG(SRC_O_BUSIF_MODE,0x4,	0x20),
2544689032bSKuninori Morimoto 		RSND_GEN_M_REG(SRC_BUSIF_DALIGN,0x8,	0x20),
255b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SRC_ROUTE_MODE0,	0xc,	0x20),
256b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SRC_CTRL,	0x10,	0x20),
257cfcefe01SKuninori Morimoto 		RSND_GEN_M_REG(SRC_INT_ENABLE0,	0x18,	0x20),
25890431eb4SKuninori Morimoto 		RSND_GEN_M_REG(CMD_BUSIF_MODE,	0x184,	0x20),
259a504b1eeSKuninori Morimoto 		RSND_GEN_M_REG(CMD_BUSIF_DALIGN,0x188,	0x20),
260b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(CMD_ROUTE_SLCT,	0x18c,	0x20),
261b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(CMD_CTRL,	0x190,	0x20),
262cfcefe01SKuninori Morimoto 		RSND_GEN_S_REG(SCU_SYS_STATUS0,	0x1c8),
263cfcefe01SKuninori Morimoto 		RSND_GEN_S_REG(SCU_SYS_INT_EN0,	0x1cc),
264cfcefe01SKuninori Morimoto 		RSND_GEN_S_REG(SCU_SYS_STATUS1,	0x1d0),
265021c5d94SKuninori Morimoto 		RSND_GEN_S_REG(SCU_SYS_INT_EN1,	0x1d4),
266b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SRC_SWRSR,	0x200,	0x40),
267b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SRC_SRCIR,	0x204,	0x40),
268b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SRC_ADINR,	0x214,	0x40),
269b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SRC_IFSCR,	0x21c,	0x40),
270b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SRC_IFSVR,	0x220,	0x40),
271b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SRC_SRCCR,	0x224,	0x40),
272b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SRC_BSDSR,	0x22c,	0x40),
273b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SRC_BSISR,	0x238,	0x40),
274bd9a603fSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SWRSR,	0x500,	0x100),
2759269e3c3SKuninori Morimoto 		RSND_GEN_M_REG(CTU_CTUIR,	0x504,	0x100),
2769269e3c3SKuninori Morimoto 		RSND_GEN_M_REG(CTU_ADINR,	0x508,	0x100),
277dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_CPMDR,	0x510,	0x100),
278dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SCMDR,	0x514,	0x100),
279dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV00R,	0x518,	0x100),
280dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV01R,	0x51c,	0x100),
281dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV02R,	0x520,	0x100),
282dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV03R,	0x524,	0x100),
283dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV04R,	0x528,	0x100),
284dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV05R,	0x52c,	0x100),
285dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV06R,	0x530,	0x100),
286dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV07R,	0x534,	0x100),
287dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV10R,	0x538,	0x100),
288dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV11R,	0x53c,	0x100),
289dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV12R,	0x540,	0x100),
290dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV13R,	0x544,	0x100),
291dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV14R,	0x548,	0x100),
292dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV15R,	0x54c,	0x100),
293dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV16R,	0x550,	0x100),
294dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV17R,	0x554,	0x100),
295dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV20R,	0x558,	0x100),
296dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV21R,	0x55c,	0x100),
297dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV22R,	0x560,	0x100),
298dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV23R,	0x564,	0x100),
299dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV24R,	0x568,	0x100),
300dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV25R,	0x56c,	0x100),
301dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV26R,	0x570,	0x100),
302dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV27R,	0x574,	0x100),
303dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV30R,	0x578,	0x100),
304dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV31R,	0x57c,	0x100),
305dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV32R,	0x580,	0x100),
306dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV33R,	0x584,	0x100),
307dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV34R,	0x588,	0x100),
308dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV35R,	0x58c,	0x100),
309dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV36R,	0x590,	0x100),
310dc037afdSKuninori Morimoto 		RSND_GEN_M_REG(CTU_SV37R,	0x594,	0x100),
31170fb1052SKuninori Morimoto 		RSND_GEN_M_REG(MIX_SWRSR,	0xd00,	0x40),
31270fb1052SKuninori Morimoto 		RSND_GEN_M_REG(MIX_MIXIR,	0xd04,	0x40),
31370fb1052SKuninori Morimoto 		RSND_GEN_M_REG(MIX_ADINR,	0xd08,	0x40),
31470fb1052SKuninori Morimoto 		RSND_GEN_M_REG(MIX_MIXMR,	0xd10,	0x40),
31570fb1052SKuninori Morimoto 		RSND_GEN_M_REG(MIX_MVPDR,	0xd14,	0x40),
31670fb1052SKuninori Morimoto 		RSND_GEN_M_REG(MIX_MDBAR,	0xd18,	0x40),
31770fb1052SKuninori Morimoto 		RSND_GEN_M_REG(MIX_MDBBR,	0xd1c,	0x40),
31870fb1052SKuninori Morimoto 		RSND_GEN_M_REG(MIX_MDBCR,	0xd20,	0x40),
31970fb1052SKuninori Morimoto 		RSND_GEN_M_REG(MIX_MDBDR,	0xd24,	0x40),
32070fb1052SKuninori Morimoto 		RSND_GEN_M_REG(MIX_MDBER,	0xd28,	0x40),
321b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(DVC_SWRSR,	0xe00,	0x100),
322b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(DVC_DVUIR,	0xe04,	0x100),
323b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(DVC_ADINR,	0xe08,	0x100),
324b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(DVC_DVUCR,	0xe10,	0x100),
325b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(DVC_ZCMCR,	0xe14,	0x100),
3263539cacfSKuninori Morimoto 		RSND_GEN_M_REG(DVC_VRCTR,	0xe18,	0x100),
3273539cacfSKuninori Morimoto 		RSND_GEN_M_REG(DVC_VRPDR,	0xe1c,	0x100),
3283539cacfSKuninori Morimoto 		RSND_GEN_M_REG(DVC_VRDBR,	0xe20,	0x100),
329b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(DVC_VOL0R,	0xe28,	0x100),
330b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(DVC_VOL1R,	0xe2c,	0x100),
33142ab9a79SKuninori Morimoto 		RSND_GEN_M_REG(DVC_VOL2R,	0xe30,	0x100),
33242ab9a79SKuninori Morimoto 		RSND_GEN_M_REG(DVC_VOL3R,	0xe34,	0x100),
33342ab9a79SKuninori Morimoto 		RSND_GEN_M_REG(DVC_VOL4R,	0xe38,	0x100),
33442ab9a79SKuninori Morimoto 		RSND_GEN_M_REG(DVC_VOL5R,	0xe3c,	0x100),
33542ab9a79SKuninori Morimoto 		RSND_GEN_M_REG(DVC_VOL6R,	0xe40,	0x100),
33642ab9a79SKuninori Morimoto 		RSND_GEN_M_REG(DVC_VOL7R,	0xe44,	0x100),
337b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(DVC_DVUER,	0xe48,	0x100),
338b8c63786SKuninori Morimoto 	};
339cc9bdcf2SArnd Bergmann 	static const struct rsnd_regmap_field_conf conf_adg[] = {
340b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(BRRA,		0x00),
341b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(BRRB,		0x04),
3423e58690bSKuninori Morimoto 		RSND_GEN_S_REG(BRGCKR,		0x08),
343b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(AUDIO_CLK_SEL0,	0x0c),
344b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(AUDIO_CLK_SEL1,	0x10),
345b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(AUDIO_CLK_SEL2,	0x14),
346b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(DIV_EN,		0x30),
347b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SRCIN_TIMSEL0,	0x34),
348b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SRCIN_TIMSEL1,	0x38),
349b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SRCIN_TIMSEL2,	0x3c),
350b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SRCIN_TIMSEL3,	0x40),
351b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SRCIN_TIMSEL4,	0x44),
352b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SRCOUT_TIMSEL0,	0x48),
353b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SRCOUT_TIMSEL1,	0x4c),
354b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SRCOUT_TIMSEL2,	0x50),
355b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SRCOUT_TIMSEL3,	0x54),
356b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(SRCOUT_TIMSEL4,	0x58),
357b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(CMDOUT_TIMSEL,	0x5c),
358b8c63786SKuninori Morimoto 	};
359cc9bdcf2SArnd Bergmann 	static const struct rsnd_regmap_field_conf conf_ssi[] = {
360b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSICR,		0x00,	0x40),
361b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSISR,		0x04,	0x40),
362b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSITDR,		0x08,	0x40),
363b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSIRDR,		0x0c,	0x40),
364b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSIWSR,		0x20,	0x40),
365b8c63786SKuninori Morimoto 	};
366b8c63786SKuninori Morimoto 	int ret_ssiu;
367b8c63786SKuninori Morimoto 	int ret_scu;
368b8c63786SKuninori Morimoto 	int ret_adg;
369b8c63786SKuninori Morimoto 	int ret_ssi;
370507d466cSKuninori Morimoto 
3717277911cSKuninori Morimoto 	ret_ssiu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSIU, "ssiu", conf_ssiu);
3727277911cSKuninori Morimoto 	ret_scu  = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SCU,  "scu",  conf_scu);
3737277911cSKuninori Morimoto 	ret_adg  = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_ADG,  "adg",  conf_adg);
3747277911cSKuninori Morimoto 	ret_ssi  = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSI,  "ssi",  conf_ssi);
375b8c63786SKuninori Morimoto 	if (ret_ssiu < 0 ||
376b8c63786SKuninori Morimoto 	    ret_scu  < 0 ||
377b8c63786SKuninori Morimoto 	    ret_adg  < 0 ||
378b8c63786SKuninori Morimoto 	    ret_ssi  < 0)
379b8c63786SKuninori Morimoto 		return ret_ssiu | ret_scu | ret_adg | ret_ssi;
380507d466cSKuninori Morimoto 
381507d466cSKuninori Morimoto 	return 0;
382507d466cSKuninori Morimoto }
383507d466cSKuninori Morimoto 
384994a9df1SKuninori Morimoto /*
385994a9df1SKuninori Morimoto  *		Gen1
386994a9df1SKuninori Morimoto  */
387994a9df1SKuninori Morimoto 
3882ea6b074SKuninori Morimoto static int rsnd_gen1_probe(struct rsnd_priv *priv)
3893337744aSKuninori Morimoto {
390cc9bdcf2SArnd Bergmann 	static const struct rsnd_regmap_field_conf conf_adg[] = {
391b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(BRRA,		0x00),
392b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(BRRB,		0x04),
3933e58690bSKuninori Morimoto 		RSND_GEN_S_REG(BRGCKR,		0x08),
394b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(AUDIO_CLK_SEL0,	0x0c),
395b8c63786SKuninori Morimoto 		RSND_GEN_S_REG(AUDIO_CLK_SEL1,	0x10),
396b8c63786SKuninori Morimoto 	};
397cc9bdcf2SArnd Bergmann 	static const struct rsnd_regmap_field_conf conf_ssi[] = {
398b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSICR,		0x00,	0x40),
399b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSISR,		0x04,	0x40),
400b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSITDR,		0x08,	0x40),
401b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSIRDR,		0x0c,	0x40),
402b8c63786SKuninori Morimoto 		RSND_GEN_M_REG(SSIWSR,		0x20,	0x40),
403b8c63786SKuninori Morimoto 	};
404b8c63786SKuninori Morimoto 	int ret_adg;
405b8c63786SKuninori Morimoto 	int ret_ssi;
40607539c1dSKuninori Morimoto 
4077277911cSKuninori Morimoto 	ret_adg  = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_ADG, "adg", conf_adg);
4087277911cSKuninori Morimoto 	ret_ssi  = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_SSI, "ssi", conf_ssi);
409e8e7b7bdSKuninori Morimoto 	if (ret_adg  < 0 ||
410b8c63786SKuninori Morimoto 	    ret_ssi  < 0)
411e8e7b7bdSKuninori Morimoto 		return ret_adg | ret_ssi;
41207539c1dSKuninori Morimoto 
4133337744aSKuninori Morimoto 	return 0;
4143337744aSKuninori Morimoto }
4153337744aSKuninori Morimoto 
4163337744aSKuninori Morimoto /*
4173337744aSKuninori Morimoto  *		Gen
4183337744aSKuninori Morimoto  */
4192ea6b074SKuninori Morimoto int rsnd_gen_probe(struct rsnd_priv *priv)
4203337744aSKuninori Morimoto {
4213337744aSKuninori Morimoto 	struct device *dev = rsnd_priv_to_dev(priv);
4223337744aSKuninori Morimoto 	struct rsnd_gen *gen;
423531eaf49SKuninori Morimoto 	int ret;
4243337744aSKuninori Morimoto 
4253337744aSKuninori Morimoto 	gen = devm_kzalloc(dev, sizeof(*gen), GFP_KERNEL);
4260d7820d0SMarkus Elfring 	if (!gen)
4273337744aSKuninori Morimoto 		return -ENOMEM;
4283337744aSKuninori Morimoto 
429531eaf49SKuninori Morimoto 	priv->gen = gen;
430072188b6SKuninori Morimoto 
431507d466cSKuninori Morimoto 	ret = -ENODEV;
432507d466cSKuninori Morimoto 	if (rsnd_is_gen1(priv))
4332ea6b074SKuninori Morimoto 		ret = rsnd_gen1_probe(priv);
434d188e140SKuninori Morimoto 	else if (rsnd_is_gen2(priv) ||
435d188e140SKuninori Morimoto 		 rsnd_is_gen3(priv))
4362ea6b074SKuninori Morimoto 		ret = rsnd_gen2_probe(priv);
437507d466cSKuninori Morimoto 
438507d466cSKuninori Morimoto 	if (ret < 0)
439072188b6SKuninori Morimoto 		dev_err(dev, "unknown generation R-Car sound device\n");
440072188b6SKuninori Morimoto 
441531eaf49SKuninori Morimoto 	return ret;
4423337744aSKuninori Morimoto }
443