18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci// 38c2ecf20Sopenharmony_ci// Renesas R-Car Gen1 SRU/SSI support 48c2ecf20Sopenharmony_ci// 58c2ecf20Sopenharmony_ci// Copyright (C) 2013 Renesas Solutions Corp. 68c2ecf20Sopenharmony_ci// Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* 98c2ecf20Sopenharmony_ci * #define DEBUG 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * you can also add below in 128c2ecf20Sopenharmony_ci * ${LINUX}/drivers/base/regmap/regmap.c 138c2ecf20Sopenharmony_ci * for regmap debug 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * #define LOG_DEVICE "xxxx.rcar_sound" 168c2ecf20Sopenharmony_ci */ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include "rsnd.h" 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct rsnd_gen { 218c2ecf20Sopenharmony_ci struct rsnd_gen_ops *ops; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci /* RSND_BASE_MAX base */ 248c2ecf20Sopenharmony_ci void __iomem *base[RSND_BASE_MAX]; 258c2ecf20Sopenharmony_ci phys_addr_t res[RSND_BASE_MAX]; 268c2ecf20Sopenharmony_ci struct regmap *regmap[RSND_BASE_MAX]; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci /* RSND_REG_MAX base */ 298c2ecf20Sopenharmony_ci struct regmap_field *regs[REG_MAX]; 308c2ecf20Sopenharmony_ci const char *reg_name[REG_MAX]; 318c2ecf20Sopenharmony_ci}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define rsnd_priv_to_gen(p) ((struct rsnd_gen *)(p)->gen) 348c2ecf20Sopenharmony_ci#define rsnd_reg_name(gen, id) ((gen)->reg_name[id]) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistruct rsnd_regmap_field_conf { 378c2ecf20Sopenharmony_ci int idx; 388c2ecf20Sopenharmony_ci unsigned int reg_offset; 398c2ecf20Sopenharmony_ci unsigned int id_offset; 408c2ecf20Sopenharmony_ci const char *reg_name; 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define RSND_REG_SET(id, offset, _id_offset, n) \ 448c2ecf20Sopenharmony_ci{ \ 458c2ecf20Sopenharmony_ci .idx = id, \ 468c2ecf20Sopenharmony_ci .reg_offset = offset, \ 478c2ecf20Sopenharmony_ci .id_offset = _id_offset, \ 488c2ecf20Sopenharmony_ci .reg_name = n, \ 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci/* single address mapping */ 518c2ecf20Sopenharmony_ci#define RSND_GEN_S_REG(id, offset) \ 528c2ecf20Sopenharmony_ci RSND_REG_SET(id, offset, 0, #id) 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci/* multi address mapping */ 558c2ecf20Sopenharmony_ci#define RSND_GEN_M_REG(id, offset, _id_offset) \ 568c2ecf20Sopenharmony_ci RSND_REG_SET(id, offset, _id_offset, #id) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* 598c2ecf20Sopenharmony_ci * basic function 608c2ecf20Sopenharmony_ci */ 618c2ecf20Sopenharmony_cistatic int rsnd_is_accessible_reg(struct rsnd_priv *priv, 628c2ecf20Sopenharmony_ci struct rsnd_gen *gen, enum rsnd_reg reg) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci if (!gen->regs[reg]) { 658c2ecf20Sopenharmony_ci struct device *dev = rsnd_priv_to_dev(priv); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci dev_err(dev, "unsupported register access %x\n", reg); 688c2ecf20Sopenharmony_ci return 0; 698c2ecf20Sopenharmony_ci } 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci return 1; 728c2ecf20Sopenharmony_ci} 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic int rsnd_mod_id_cmd(struct rsnd_mod *mod) 758c2ecf20Sopenharmony_ci{ 768c2ecf20Sopenharmony_ci if (mod->ops->id_cmd) 778c2ecf20Sopenharmony_ci return mod->ops->id_cmd(mod); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci return rsnd_mod_id(mod); 808c2ecf20Sopenharmony_ci} 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ciu32 rsnd_mod_read(struct rsnd_mod *mod, enum rsnd_reg reg) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 858c2ecf20Sopenharmony_ci struct device *dev = rsnd_priv_to_dev(priv); 868c2ecf20Sopenharmony_ci struct rsnd_gen *gen = rsnd_priv_to_gen(priv); 878c2ecf20Sopenharmony_ci u32 val; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci if (!rsnd_is_accessible_reg(priv, gen, reg)) 908c2ecf20Sopenharmony_ci return 0; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci regmap_fields_read(gen->regs[reg], rsnd_mod_id_cmd(mod), &val); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci dev_dbg(dev, "r %s - %-18s (%4d) : %08x\n", 958c2ecf20Sopenharmony_ci rsnd_mod_name(mod), 968c2ecf20Sopenharmony_ci rsnd_reg_name(gen, reg), reg, val); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci return val; 998c2ecf20Sopenharmony_ci} 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_civoid rsnd_mod_write(struct rsnd_mod *mod, 1028c2ecf20Sopenharmony_ci enum rsnd_reg reg, u32 data) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 1058c2ecf20Sopenharmony_ci struct device *dev = rsnd_priv_to_dev(priv); 1068c2ecf20Sopenharmony_ci struct rsnd_gen *gen = rsnd_priv_to_gen(priv); 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci if (!rsnd_is_accessible_reg(priv, gen, reg)) 1098c2ecf20Sopenharmony_ci return; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci regmap_fields_force_write(gen->regs[reg], rsnd_mod_id_cmd(mod), data); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci dev_dbg(dev, "w %s - %-18s (%4d) : %08x\n", 1148c2ecf20Sopenharmony_ci rsnd_mod_name(mod), 1158c2ecf20Sopenharmony_ci rsnd_reg_name(gen, reg), reg, data); 1168c2ecf20Sopenharmony_ci} 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_civoid rsnd_mod_bset(struct rsnd_mod *mod, 1198c2ecf20Sopenharmony_ci enum rsnd_reg reg, u32 mask, u32 data) 1208c2ecf20Sopenharmony_ci{ 1218c2ecf20Sopenharmony_ci struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 1228c2ecf20Sopenharmony_ci struct device *dev = rsnd_priv_to_dev(priv); 1238c2ecf20Sopenharmony_ci struct rsnd_gen *gen = rsnd_priv_to_gen(priv); 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci if (!rsnd_is_accessible_reg(priv, gen, reg)) 1268c2ecf20Sopenharmony_ci return; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci regmap_fields_force_update_bits(gen->regs[reg], 1298c2ecf20Sopenharmony_ci rsnd_mod_id_cmd(mod), mask, data); 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci dev_dbg(dev, "b %s - %-18s (%4d) : %08x/%08x\n", 1328c2ecf20Sopenharmony_ci rsnd_mod_name(mod), 1338c2ecf20Sopenharmony_ci rsnd_reg_name(gen, reg), reg, data, mask); 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci} 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ciphys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id) 1388c2ecf20Sopenharmony_ci{ 1398c2ecf20Sopenharmony_ci struct rsnd_gen *gen = rsnd_priv_to_gen(priv); 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci return gen->res[reg_id]; 1428c2ecf20Sopenharmony_ci} 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci#define rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf) \ 1458c2ecf20Sopenharmony_ci _rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf, ARRAY_SIZE(conf)) 1468c2ecf20Sopenharmony_cistatic int _rsnd_gen_regmap_init(struct rsnd_priv *priv, 1478c2ecf20Sopenharmony_ci int id_size, 1488c2ecf20Sopenharmony_ci int reg_id, 1498c2ecf20Sopenharmony_ci const char *name, 1508c2ecf20Sopenharmony_ci const struct rsnd_regmap_field_conf *conf, 1518c2ecf20Sopenharmony_ci int conf_size) 1528c2ecf20Sopenharmony_ci{ 1538c2ecf20Sopenharmony_ci struct platform_device *pdev = rsnd_priv_to_pdev(priv); 1548c2ecf20Sopenharmony_ci struct rsnd_gen *gen = rsnd_priv_to_gen(priv); 1558c2ecf20Sopenharmony_ci struct device *dev = rsnd_priv_to_dev(priv); 1568c2ecf20Sopenharmony_ci struct resource *res; 1578c2ecf20Sopenharmony_ci struct regmap_config regc; 1588c2ecf20Sopenharmony_ci struct regmap_field *regs; 1598c2ecf20Sopenharmony_ci struct regmap *regmap; 1608c2ecf20Sopenharmony_ci struct reg_field regf; 1618c2ecf20Sopenharmony_ci void __iomem *base; 1628c2ecf20Sopenharmony_ci int i; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci memset(®c, 0, sizeof(regc)); 1658c2ecf20Sopenharmony_ci regc.reg_bits = 32; 1668c2ecf20Sopenharmony_ci regc.val_bits = 32; 1678c2ecf20Sopenharmony_ci regc.reg_stride = 4; 1688c2ecf20Sopenharmony_ci regc.name = name; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); 1718c2ecf20Sopenharmony_ci if (!res) 1728c2ecf20Sopenharmony_ci res = platform_get_resource(pdev, IORESOURCE_MEM, reg_id); 1738c2ecf20Sopenharmony_ci if (!res) 1748c2ecf20Sopenharmony_ci return -ENODEV; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci base = devm_ioremap_resource(dev, res); 1778c2ecf20Sopenharmony_ci if (IS_ERR(base)) 1788c2ecf20Sopenharmony_ci return PTR_ERR(base); 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci regmap = devm_regmap_init_mmio(dev, base, ®c); 1818c2ecf20Sopenharmony_ci if (IS_ERR(regmap)) 1828c2ecf20Sopenharmony_ci return PTR_ERR(regmap); 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci /* RSND_BASE_MAX base */ 1858c2ecf20Sopenharmony_ci gen->base[reg_id] = base; 1868c2ecf20Sopenharmony_ci gen->regmap[reg_id] = regmap; 1878c2ecf20Sopenharmony_ci gen->res[reg_id] = res->start; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci for (i = 0; i < conf_size; i++) { 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci regf.reg = conf[i].reg_offset; 1928c2ecf20Sopenharmony_ci regf.id_offset = conf[i].id_offset; 1938c2ecf20Sopenharmony_ci regf.lsb = 0; 1948c2ecf20Sopenharmony_ci regf.msb = 31; 1958c2ecf20Sopenharmony_ci regf.id_size = id_size; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci regs = devm_regmap_field_alloc(dev, regmap, regf); 1988c2ecf20Sopenharmony_ci if (IS_ERR(regs)) 1998c2ecf20Sopenharmony_ci return PTR_ERR(regs); 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci /* RSND_REG_MAX base */ 2028c2ecf20Sopenharmony_ci gen->regs[conf[i].idx] = regs; 2038c2ecf20Sopenharmony_ci gen->reg_name[conf[i].idx] = conf[i].reg_name; 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci return 0; 2078c2ecf20Sopenharmony_ci} 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci/* 2108c2ecf20Sopenharmony_ci * Gen2 2118c2ecf20Sopenharmony_ci */ 2128c2ecf20Sopenharmony_cistatic int rsnd_gen2_probe(struct rsnd_priv *priv) 2138c2ecf20Sopenharmony_ci{ 2148c2ecf20Sopenharmony_ci static const struct rsnd_regmap_field_conf conf_ssiu[] = { 2158c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_MODE0, 0x800), 2168c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_MODE1, 0x804), 2178c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_MODE2, 0x808), 2188c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_CONTROL, 0x810), 2198c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_STATUS0, 0x840), 2208c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_STATUS1, 0x844), 2218c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_STATUS2, 0x848), 2228c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_STATUS3, 0x84c), 2238c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_STATUS4, 0x880), 2248c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_STATUS5, 0x884), 2258c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_STATUS6, 0x888), 2268c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_STATUS7, 0x88c), 2278c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_INT_ENABLE0, 0x850), 2288c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_INT_ENABLE1, 0x854), 2298c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_INT_ENABLE2, 0x858), 2308c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_INT_ENABLE3, 0x85c), 2318c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_INT_ENABLE4, 0x890), 2328c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_INT_ENABLE5, 0x894), 2338c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_INT_ENABLE6, 0x898), 2348c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI_SYS_INT_ENABLE7, 0x89c), 2358c2ecf20Sopenharmony_ci RSND_GEN_S_REG(HDMI0_SEL, 0x9e0), 2368c2ecf20Sopenharmony_ci RSND_GEN_S_REG(HDMI1_SEL, 0x9e4), 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci /* FIXME: it needs SSI_MODE2/3 in the future */ 2398c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF0_MODE, 0x0, 0x80), 2408c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF0_ADINR, 0x4, 0x80), 2418c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF0_DALIGN, 0x8, 0x80), 2428c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF1_MODE, 0x20, 0x80), 2438c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF1_ADINR, 0x24, 0x80), 2448c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF1_DALIGN, 0x28, 0x80), 2458c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF2_MODE, 0x40, 0x80), 2468c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF2_ADINR, 0x44, 0x80), 2478c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF2_DALIGN, 0x48, 0x80), 2488c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF3_MODE, 0x60, 0x80), 2498c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF3_ADINR, 0x64, 0x80), 2508c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF3_DALIGN, 0x68, 0x80), 2518c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF4_MODE, 0x500, 0x80), 2528c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF4_ADINR, 0x504, 0x80), 2538c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF4_DALIGN, 0x508, 0x80), 2548c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF5_MODE, 0x520, 0x80), 2558c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF5_ADINR, 0x524, 0x80), 2568c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF5_DALIGN, 0x528, 0x80), 2578c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF6_MODE, 0x540, 0x80), 2588c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF6_ADINR, 0x544, 0x80), 2598c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF6_DALIGN, 0x548, 0x80), 2608c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF7_MODE, 0x560, 0x80), 2618c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF7_ADINR, 0x564, 0x80), 2628c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_BUSIF7_DALIGN, 0x568, 0x80), 2638c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_MODE, 0xc, 0x80), 2648c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_CTRL, 0x10, 0x80), 2658c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSI_INT_ENABLE, 0x18, 0x80), 2668c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF0_MODE, 0x48c), 2678c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF0_ADINR, 0x484), 2688c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF0_DALIGN, 0x488), 2698c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF1_MODE, 0x4a0), 2708c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF1_ADINR, 0x4a4), 2718c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF1_DALIGN, 0x4a8), 2728c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF2_MODE, 0x4c0), 2738c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF2_ADINR, 0x4c4), 2748c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF2_DALIGN, 0x4c8), 2758c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF3_MODE, 0x4e0), 2768c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF3_ADINR, 0x4e4), 2778c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF3_DALIGN, 0x4e8), 2788c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF4_MODE, 0xd80), 2798c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF4_ADINR, 0xd84), 2808c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF4_DALIGN, 0xd88), 2818c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF5_MODE, 0xda0), 2828c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF5_ADINR, 0xda4), 2838c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF5_DALIGN, 0xda8), 2848c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF6_MODE, 0xdc0), 2858c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF6_ADINR, 0xdc4), 2868c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF6_DALIGN, 0xdc8), 2878c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF7_MODE, 0xde0), 2888c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF7_ADINR, 0xde4), 2898c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SSI9_BUSIF7_DALIGN, 0xde8), 2908c2ecf20Sopenharmony_ci }; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci static const struct rsnd_regmap_field_conf conf_scu[] = { 2938c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_I_BUSIF_MODE,0x0, 0x20), 2948c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_O_BUSIF_MODE,0x4, 0x20), 2958c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_BUSIF_DALIGN,0x8, 0x20), 2968c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_ROUTE_MODE0, 0xc, 0x20), 2978c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_CTRL, 0x10, 0x20), 2988c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_INT_ENABLE0, 0x18, 0x20), 2998c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CMD_BUSIF_MODE, 0x184, 0x20), 3008c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CMD_BUSIF_DALIGN,0x188, 0x20), 3018c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CMD_ROUTE_SLCT, 0x18c, 0x20), 3028c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CMD_CTRL, 0x190, 0x20), 3038c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SCU_SYS_STATUS0, 0x1c8), 3048c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SCU_SYS_INT_EN0, 0x1cc), 3058c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SCU_SYS_STATUS1, 0x1d0), 3068c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SCU_SYS_INT_EN1, 0x1d4), 3078c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_SWRSR, 0x200, 0x40), 3088c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_SRCIR, 0x204, 0x40), 3098c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_ADINR, 0x214, 0x40), 3108c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_IFSCR, 0x21c, 0x40), 3118c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_IFSVR, 0x220, 0x40), 3128c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_SRCCR, 0x224, 0x40), 3138c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_BSDSR, 0x22c, 0x40), 3148c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SRC_BSISR, 0x238, 0x40), 3158c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SWRSR, 0x500, 0x100), 3168c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_CTUIR, 0x504, 0x100), 3178c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_ADINR, 0x508, 0x100), 3188c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_CPMDR, 0x510, 0x100), 3198c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SCMDR, 0x514, 0x100), 3208c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV00R, 0x518, 0x100), 3218c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV01R, 0x51c, 0x100), 3228c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV02R, 0x520, 0x100), 3238c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV03R, 0x524, 0x100), 3248c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV04R, 0x528, 0x100), 3258c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV05R, 0x52c, 0x100), 3268c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV06R, 0x530, 0x100), 3278c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV07R, 0x534, 0x100), 3288c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV10R, 0x538, 0x100), 3298c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV11R, 0x53c, 0x100), 3308c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV12R, 0x540, 0x100), 3318c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV13R, 0x544, 0x100), 3328c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV14R, 0x548, 0x100), 3338c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV15R, 0x54c, 0x100), 3348c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV16R, 0x550, 0x100), 3358c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV17R, 0x554, 0x100), 3368c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV20R, 0x558, 0x100), 3378c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV21R, 0x55c, 0x100), 3388c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV22R, 0x560, 0x100), 3398c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV23R, 0x564, 0x100), 3408c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV24R, 0x568, 0x100), 3418c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV25R, 0x56c, 0x100), 3428c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV26R, 0x570, 0x100), 3438c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV27R, 0x574, 0x100), 3448c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV30R, 0x578, 0x100), 3458c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV31R, 0x57c, 0x100), 3468c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV32R, 0x580, 0x100), 3478c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV33R, 0x584, 0x100), 3488c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV34R, 0x588, 0x100), 3498c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV35R, 0x58c, 0x100), 3508c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV36R, 0x590, 0x100), 3518c2ecf20Sopenharmony_ci RSND_GEN_M_REG(CTU_SV37R, 0x594, 0x100), 3528c2ecf20Sopenharmony_ci RSND_GEN_M_REG(MIX_SWRSR, 0xd00, 0x40), 3538c2ecf20Sopenharmony_ci RSND_GEN_M_REG(MIX_MIXIR, 0xd04, 0x40), 3548c2ecf20Sopenharmony_ci RSND_GEN_M_REG(MIX_ADINR, 0xd08, 0x40), 3558c2ecf20Sopenharmony_ci RSND_GEN_M_REG(MIX_MIXMR, 0xd10, 0x40), 3568c2ecf20Sopenharmony_ci RSND_GEN_M_REG(MIX_MVPDR, 0xd14, 0x40), 3578c2ecf20Sopenharmony_ci RSND_GEN_M_REG(MIX_MDBAR, 0xd18, 0x40), 3588c2ecf20Sopenharmony_ci RSND_GEN_M_REG(MIX_MDBBR, 0xd1c, 0x40), 3598c2ecf20Sopenharmony_ci RSND_GEN_M_REG(MIX_MDBCR, 0xd20, 0x40), 3608c2ecf20Sopenharmony_ci RSND_GEN_M_REG(MIX_MDBDR, 0xd24, 0x40), 3618c2ecf20Sopenharmony_ci RSND_GEN_M_REG(MIX_MDBER, 0xd28, 0x40), 3628c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_SWRSR, 0xe00, 0x100), 3638c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_DVUIR, 0xe04, 0x100), 3648c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_ADINR, 0xe08, 0x100), 3658c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_DVUCR, 0xe10, 0x100), 3668c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_ZCMCR, 0xe14, 0x100), 3678c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VRCTR, 0xe18, 0x100), 3688c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VRPDR, 0xe1c, 0x100), 3698c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VRDBR, 0xe20, 0x100), 3708c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VOL0R, 0xe28, 0x100), 3718c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VOL1R, 0xe2c, 0x100), 3728c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VOL2R, 0xe30, 0x100), 3738c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VOL3R, 0xe34, 0x100), 3748c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VOL4R, 0xe38, 0x100), 3758c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VOL5R, 0xe3c, 0x100), 3768c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VOL6R, 0xe40, 0x100), 3778c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_VOL7R, 0xe44, 0x100), 3788c2ecf20Sopenharmony_ci RSND_GEN_M_REG(DVC_DVUER, 0xe48, 0x100), 3798c2ecf20Sopenharmony_ci }; 3808c2ecf20Sopenharmony_ci static const struct rsnd_regmap_field_conf conf_adg[] = { 3818c2ecf20Sopenharmony_ci RSND_GEN_S_REG(BRRA, 0x00), 3828c2ecf20Sopenharmony_ci RSND_GEN_S_REG(BRRB, 0x04), 3838c2ecf20Sopenharmony_ci RSND_GEN_S_REG(BRGCKR, 0x08), 3848c2ecf20Sopenharmony_ci RSND_GEN_S_REG(AUDIO_CLK_SEL0, 0x0c), 3858c2ecf20Sopenharmony_ci RSND_GEN_S_REG(AUDIO_CLK_SEL1, 0x10), 3868c2ecf20Sopenharmony_ci RSND_GEN_S_REG(AUDIO_CLK_SEL2, 0x14), 3878c2ecf20Sopenharmony_ci RSND_GEN_S_REG(DIV_EN, 0x30), 3888c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SRCIN_TIMSEL0, 0x34), 3898c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SRCIN_TIMSEL1, 0x38), 3908c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SRCIN_TIMSEL2, 0x3c), 3918c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SRCIN_TIMSEL3, 0x40), 3928c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SRCIN_TIMSEL4, 0x44), 3938c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SRCOUT_TIMSEL0, 0x48), 3948c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SRCOUT_TIMSEL1, 0x4c), 3958c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SRCOUT_TIMSEL2, 0x50), 3968c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SRCOUT_TIMSEL3, 0x54), 3978c2ecf20Sopenharmony_ci RSND_GEN_S_REG(SRCOUT_TIMSEL4, 0x58), 3988c2ecf20Sopenharmony_ci RSND_GEN_S_REG(CMDOUT_TIMSEL, 0x5c), 3998c2ecf20Sopenharmony_ci }; 4008c2ecf20Sopenharmony_ci static const struct rsnd_regmap_field_conf conf_ssi[] = { 4018c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSICR, 0x00, 0x40), 4028c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSISR, 0x04, 0x40), 4038c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSITDR, 0x08, 0x40), 4048c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSIRDR, 0x0c, 0x40), 4058c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSIWSR, 0x20, 0x40), 4068c2ecf20Sopenharmony_ci }; 4078c2ecf20Sopenharmony_ci int ret_ssiu; 4088c2ecf20Sopenharmony_ci int ret_scu; 4098c2ecf20Sopenharmony_ci int ret_adg; 4108c2ecf20Sopenharmony_ci int ret_ssi; 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci ret_ssiu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSIU, "ssiu", conf_ssiu); 4138c2ecf20Sopenharmony_ci ret_scu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SCU, "scu", conf_scu); 4148c2ecf20Sopenharmony_ci ret_adg = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_ADG, "adg", conf_adg); 4158c2ecf20Sopenharmony_ci ret_ssi = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSI, "ssi", conf_ssi); 4168c2ecf20Sopenharmony_ci if (ret_ssiu < 0 || 4178c2ecf20Sopenharmony_ci ret_scu < 0 || 4188c2ecf20Sopenharmony_ci ret_adg < 0 || 4198c2ecf20Sopenharmony_ci ret_ssi < 0) 4208c2ecf20Sopenharmony_ci return ret_ssiu | ret_scu | ret_adg | ret_ssi; 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci return 0; 4238c2ecf20Sopenharmony_ci} 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci/* 4268c2ecf20Sopenharmony_ci * Gen1 4278c2ecf20Sopenharmony_ci */ 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_cistatic int rsnd_gen1_probe(struct rsnd_priv *priv) 4308c2ecf20Sopenharmony_ci{ 4318c2ecf20Sopenharmony_ci static const struct rsnd_regmap_field_conf conf_adg[] = { 4328c2ecf20Sopenharmony_ci RSND_GEN_S_REG(BRRA, 0x00), 4338c2ecf20Sopenharmony_ci RSND_GEN_S_REG(BRRB, 0x04), 4348c2ecf20Sopenharmony_ci RSND_GEN_S_REG(BRGCKR, 0x08), 4358c2ecf20Sopenharmony_ci RSND_GEN_S_REG(AUDIO_CLK_SEL0, 0x0c), 4368c2ecf20Sopenharmony_ci RSND_GEN_S_REG(AUDIO_CLK_SEL1, 0x10), 4378c2ecf20Sopenharmony_ci }; 4388c2ecf20Sopenharmony_ci static const struct rsnd_regmap_field_conf conf_ssi[] = { 4398c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSICR, 0x00, 0x40), 4408c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSISR, 0x04, 0x40), 4418c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSITDR, 0x08, 0x40), 4428c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSIRDR, 0x0c, 0x40), 4438c2ecf20Sopenharmony_ci RSND_GEN_M_REG(SSIWSR, 0x20, 0x40), 4448c2ecf20Sopenharmony_ci }; 4458c2ecf20Sopenharmony_ci int ret_adg; 4468c2ecf20Sopenharmony_ci int ret_ssi; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci ret_adg = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_ADG, "adg", conf_adg); 4498c2ecf20Sopenharmony_ci ret_ssi = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_SSI, "ssi", conf_ssi); 4508c2ecf20Sopenharmony_ci if (ret_adg < 0 || 4518c2ecf20Sopenharmony_ci ret_ssi < 0) 4528c2ecf20Sopenharmony_ci return ret_adg | ret_ssi; 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci return 0; 4558c2ecf20Sopenharmony_ci} 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci/* 4588c2ecf20Sopenharmony_ci * Gen 4598c2ecf20Sopenharmony_ci */ 4608c2ecf20Sopenharmony_ciint rsnd_gen_probe(struct rsnd_priv *priv) 4618c2ecf20Sopenharmony_ci{ 4628c2ecf20Sopenharmony_ci struct device *dev = rsnd_priv_to_dev(priv); 4638c2ecf20Sopenharmony_ci struct rsnd_gen *gen; 4648c2ecf20Sopenharmony_ci int ret; 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci gen = devm_kzalloc(dev, sizeof(*gen), GFP_KERNEL); 4678c2ecf20Sopenharmony_ci if (!gen) 4688c2ecf20Sopenharmony_ci return -ENOMEM; 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_ci priv->gen = gen; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci ret = -ENODEV; 4738c2ecf20Sopenharmony_ci if (rsnd_is_gen1(priv)) 4748c2ecf20Sopenharmony_ci ret = rsnd_gen1_probe(priv); 4758c2ecf20Sopenharmony_ci else if (rsnd_is_gen2(priv) || 4768c2ecf20Sopenharmony_ci rsnd_is_gen3(priv)) 4778c2ecf20Sopenharmony_ci ret = rsnd_gen2_probe(priv); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci if (ret < 0) 4808c2ecf20Sopenharmony_ci dev_err(dev, "unknown generation R-Car sound device\n"); 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci return ret; 4838c2ecf20Sopenharmony_ci} 484