Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Renesas R-Car Gen1 SRU/SSI support |
| 3 | * |
| 4 | * Copyright (C) 2013 Renesas Solutions Corp. |
| 5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
Kuninori Morimoto | ace0eb1 | 2014-10-21 18:13:46 -0700 | [diff] [blame] | 11 | |
| 12 | /* |
| 13 | * #define DEBUG |
| 14 | * |
| 15 | * you can also add below in |
| 16 | * ${LINUX}/drivers/base/regmap/regmap.c |
| 17 | * for regmap debug |
| 18 | * |
| 19 | * #define LOG_DEVICE "xxxx.rcar_sound" |
| 20 | */ |
| 21 | |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 22 | #include "rsnd.h" |
| 23 | |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 24 | struct rsnd_gen { |
| 25 | void __iomem *base[RSND_BASE_MAX]; |
| 26 | |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 27 | struct rsnd_gen_ops *ops; |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 28 | |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 29 | struct regmap *regmap[RSND_BASE_MAX]; |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 30 | struct regmap_field *regs[RSND_REG_MAX]; |
Kuninori Morimoto | c5212b4 | 2015-02-20 10:25:27 +0000 | [diff] [blame] | 31 | phys_addr_t res[RSND_REG_MAX]; |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | #define rsnd_priv_to_gen(p) ((struct rsnd_gen *)(p)->gen) |
| 35 | |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 36 | struct rsnd_regmap_field_conf { |
| 37 | int idx; |
| 38 | unsigned int reg_offset; |
| 39 | unsigned int id_offset; |
| 40 | }; |
| 41 | |
| 42 | #define RSND_REG_SET(id, offset, _id_offset) \ |
| 43 | { \ |
| 44 | .idx = id, \ |
| 45 | .reg_offset = offset, \ |
| 46 | .id_offset = _id_offset, \ |
| 47 | } |
| 48 | /* single address mapping */ |
| 49 | #define RSND_GEN_S_REG(id, offset) \ |
| 50 | RSND_REG_SET(RSND_REG_##id, offset, 0) |
| 51 | |
| 52 | /* multi address mapping */ |
| 53 | #define RSND_GEN_M_REG(id, offset, _id_offset) \ |
| 54 | RSND_REG_SET(RSND_REG_##id, offset, _id_offset) |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * basic function |
| 58 | */ |
Kuninori Morimoto | 42ee5d2 | 2013-11-28 18:43:13 -0800 | [diff] [blame] | 59 | static int rsnd_is_accessible_reg(struct rsnd_priv *priv, |
| 60 | struct rsnd_gen *gen, enum rsnd_reg reg) |
| 61 | { |
| 62 | if (!gen->regs[reg]) { |
| 63 | struct device *dev = rsnd_priv_to_dev(priv); |
| 64 | |
| 65 | dev_err(dev, "unsupported register access %x\n", reg); |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | return 1; |
| 70 | } |
| 71 | |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 72 | u32 rsnd_read(struct rsnd_priv *priv, |
| 73 | struct rsnd_mod *mod, enum rsnd_reg reg) |
| 74 | { |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 75 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 76 | struct rsnd_gen *gen = rsnd_priv_to_gen(priv); |
| 77 | u32 val; |
| 78 | |
Kuninori Morimoto | 42ee5d2 | 2013-11-28 18:43:13 -0800 | [diff] [blame] | 79 | if (!rsnd_is_accessible_reg(priv, gen, reg)) |
| 80 | return 0; |
| 81 | |
Kuninori Morimoto | 30cc4fa | 2014-11-09 20:00:30 -0800 | [diff] [blame] | 82 | dev_dbg(dev, "r %s[%d] - %4d : %08x\n", |
Kuninori Morimoto | ace0eb1 | 2014-10-21 18:13:46 -0700 | [diff] [blame] | 83 | rsnd_mod_name(mod), rsnd_mod_id(mod), reg, val); |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 84 | |
Kuninori Morimoto | ace0eb1 | 2014-10-21 18:13:46 -0700 | [diff] [blame] | 85 | regmap_fields_read(gen->regs[reg], rsnd_mod_id(mod), &val); |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 86 | |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 87 | return val; |
| 88 | } |
| 89 | |
| 90 | void rsnd_write(struct rsnd_priv *priv, |
| 91 | struct rsnd_mod *mod, |
| 92 | enum rsnd_reg reg, u32 data) |
| 93 | { |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 94 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 95 | struct rsnd_gen *gen = rsnd_priv_to_gen(priv); |
| 96 | |
Kuninori Morimoto | 42ee5d2 | 2013-11-28 18:43:13 -0800 | [diff] [blame] | 97 | if (!rsnd_is_accessible_reg(priv, gen, reg)) |
| 98 | return; |
| 99 | |
Kuninori Morimoto | 30cc4fa | 2014-11-09 20:00:30 -0800 | [diff] [blame] | 100 | dev_dbg(dev, "w %s[%d] - %4d : %08x\n", |
Kuninori Morimoto | ace0eb1 | 2014-10-21 18:13:46 -0700 | [diff] [blame] | 101 | rsnd_mod_name(mod), rsnd_mod_id(mod), reg, data); |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 102 | |
Kuninori Morimoto | ace0eb1 | 2014-10-21 18:13:46 -0700 | [diff] [blame] | 103 | regmap_fields_write(gen->regs[reg], rsnd_mod_id(mod), data); |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, |
| 107 | enum rsnd_reg reg, u32 mask, u32 data) |
| 108 | { |
Kuninori Morimoto | 4f8f86a | 2014-07-30 23:52:50 -0700 | [diff] [blame] | 109 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 110 | struct rsnd_gen *gen = rsnd_priv_to_gen(priv); |
| 111 | |
Kuninori Morimoto | 42ee5d2 | 2013-11-28 18:43:13 -0800 | [diff] [blame] | 112 | if (!rsnd_is_accessible_reg(priv, gen, reg)) |
| 113 | return; |
| 114 | |
Kuninori Morimoto | 30cc4fa | 2014-11-09 20:00:30 -0800 | [diff] [blame] | 115 | dev_dbg(dev, "b %s[%d] - %4d : %08x/%08x\n", |
Kuninori Morimoto | ace0eb1 | 2014-10-21 18:13:46 -0700 | [diff] [blame] | 116 | rsnd_mod_name(mod), rsnd_mod_id(mod), reg, data, mask); |
| 117 | |
Kuninori Morimoto | 55e5b6f | 2013-09-23 23:12:27 -0700 | [diff] [blame] | 118 | regmap_fields_update_bits(gen->regs[reg], rsnd_mod_id(mod), |
| 119 | mask, data); |
| 120 | } |
| 121 | |
Kuninori Morimoto | c5212b4 | 2015-02-20 10:25:27 +0000 | [diff] [blame] | 122 | phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id) |
| 123 | { |
| 124 | struct rsnd_gen *gen = rsnd_priv_to_gen(priv); |
| 125 | |
| 126 | return gen->res[reg_id]; |
| 127 | } |
| 128 | |
Kuninori Morimoto | 7277911 | 2015-02-20 10:24:52 +0000 | [diff] [blame] | 129 | #define rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf) \ |
| 130 | _rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf, ARRAY_SIZE(conf)) |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 131 | static int _rsnd_gen_regmap_init(struct rsnd_priv *priv, |
| 132 | int id_size, |
| 133 | int reg_id, |
Kuninori Morimoto | 7277911 | 2015-02-20 10:24:52 +0000 | [diff] [blame] | 134 | const char *name, |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 135 | struct rsnd_regmap_field_conf *conf, |
| 136 | int conf_size) |
Kuninori Morimoto | c1e6cc5 | 2013-11-28 18:43:01 -0800 | [diff] [blame] | 137 | { |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 138 | struct platform_device *pdev = rsnd_priv_to_pdev(priv); |
| 139 | struct rsnd_gen *gen = rsnd_priv_to_gen(priv); |
Kuninori Morimoto | c1e6cc5 | 2013-11-28 18:43:01 -0800 | [diff] [blame] | 140 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 141 | struct resource *res; |
Kuninori Morimoto | c1e6cc5 | 2013-11-28 18:43:01 -0800 | [diff] [blame] | 142 | struct regmap_config regc; |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 143 | struct regmap_field *regs; |
| 144 | struct regmap *regmap; |
| 145 | struct reg_field regf; |
| 146 | void __iomem *base; |
| 147 | int i; |
Kuninori Morimoto | c1e6cc5 | 2013-11-28 18:43:01 -0800 | [diff] [blame] | 148 | |
| 149 | memset(®c, 0, sizeof(regc)); |
| 150 | regc.reg_bits = 32; |
| 151 | regc.val_bits = 32; |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 152 | regc.reg_stride = 4; |
Kuninori Morimoto | 530b7b4 | 2015-03-10 01:25:36 +0000 | [diff] [blame] | 153 | regc.name = name; |
Kuninori Morimoto | c1e6cc5 | 2013-11-28 18:43:01 -0800 | [diff] [blame] | 154 | |
Kuninori Morimoto | 7277911 | 2015-02-20 10:24:52 +0000 | [diff] [blame] | 155 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); |
| 156 | if (!res) |
| 157 | res = platform_get_resource(pdev, IORESOURCE_MEM, reg_id); |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 158 | if (!res) |
| 159 | return -ENODEV; |
Kuninori Morimoto | c1e6cc5 | 2013-11-28 18:43:01 -0800 | [diff] [blame] | 160 | |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 161 | base = devm_ioremap_resource(dev, res); |
| 162 | if (IS_ERR(base)) |
| 163 | return PTR_ERR(base); |
Kuninori Morimoto | 42ee5d2 | 2013-11-28 18:43:13 -0800 | [diff] [blame] | 164 | |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 165 | regmap = devm_regmap_init_mmio(dev, base, ®c); |
| 166 | if (IS_ERR(regmap)) |
| 167 | return PTR_ERR(regmap); |
Kuninori Morimoto | c1e6cc5 | 2013-11-28 18:43:01 -0800 | [diff] [blame] | 168 | |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 169 | gen->base[reg_id] = base; |
| 170 | gen->regmap[reg_id] = regmap; |
Kuninori Morimoto | c5212b4 | 2015-02-20 10:25:27 +0000 | [diff] [blame] | 171 | gen->res[reg_id] = res->start; |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 172 | |
| 173 | for (i = 0; i < conf_size; i++) { |
| 174 | |
| 175 | regf.reg = conf[i].reg_offset; |
| 176 | regf.id_offset = conf[i].id_offset; |
| 177 | regf.lsb = 0; |
| 178 | regf.msb = 31; |
| 179 | regf.id_size = id_size; |
| 180 | |
| 181 | regs = devm_regmap_field_alloc(dev, regmap, regf); |
| 182 | if (IS_ERR(regs)) |
| 183 | return PTR_ERR(regs); |
| 184 | |
| 185 | gen->regs[conf[i].idx] = regs; |
Kuninori Morimoto | c1e6cc5 | 2013-11-28 18:43:01 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | return 0; |
| 189 | } |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 190 | |
Kuninori Morimoto | 994a9df | 2013-11-28 18:43:23 -0800 | [diff] [blame] | 191 | /* |
| 192 | * Gen2 |
Kuninori Morimoto | 994a9df | 2013-11-28 18:43:23 -0800 | [diff] [blame] | 193 | */ |
Kuninori Morimoto | 507d466 | 2013-11-28 18:43:45 -0800 | [diff] [blame] | 194 | static int rsnd_gen2_probe(struct platform_device *pdev, |
Kuninori Morimoto | 507d466 | 2013-11-28 18:43:45 -0800 | [diff] [blame] | 195 | struct rsnd_priv *priv) |
| 196 | { |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 197 | struct rsnd_regmap_field_conf conf_ssiu[] = { |
| 198 | RSND_GEN_S_REG(SSI_MODE0, 0x800), |
| 199 | RSND_GEN_S_REG(SSI_MODE1, 0x804), |
| 200 | /* FIXME: it needs SSI_MODE2/3 in the future */ |
| 201 | RSND_GEN_M_REG(SSI_BUSIF_MODE, 0x0, 0x80), |
| 202 | RSND_GEN_M_REG(SSI_BUSIF_ADINR, 0x4, 0x80), |
Kuninori Morimoto | 1cc7195 | 2014-07-30 23:52:26 -0700 | [diff] [blame] | 203 | RSND_GEN_M_REG(BUSIF_DALIGN, 0x8, 0x80), |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 204 | RSND_GEN_M_REG(SSI_CTRL, 0x10, 0x80), |
| 205 | RSND_GEN_M_REG(INT_ENABLE, 0x18, 0x80), |
| 206 | }; |
| 207 | struct rsnd_regmap_field_conf conf_scu[] = { |
| 208 | RSND_GEN_M_REG(SRC_BUSIF_MODE, 0x0, 0x20), |
| 209 | RSND_GEN_M_REG(SRC_ROUTE_MODE0, 0xc, 0x20), |
| 210 | RSND_GEN_M_REG(SRC_CTRL, 0x10, 0x20), |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 211 | RSND_GEN_M_REG(SRC_INT_ENABLE0, 0x18, 0x20), |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 212 | RSND_GEN_M_REG(CMD_ROUTE_SLCT, 0x18c, 0x20), |
| 213 | RSND_GEN_M_REG(CMD_CTRL, 0x190, 0x20), |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 214 | RSND_GEN_S_REG(SCU_SYS_STATUS0, 0x1c8), |
| 215 | RSND_GEN_S_REG(SCU_SYS_INT_EN0, 0x1cc), |
| 216 | RSND_GEN_S_REG(SCU_SYS_STATUS1, 0x1d0), |
| 217 | RSND_GEN_S_REG(SCU_SYS_INT_EN1, 0x1c4), |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 218 | RSND_GEN_M_REG(SRC_SWRSR, 0x200, 0x40), |
| 219 | RSND_GEN_M_REG(SRC_SRCIR, 0x204, 0x40), |
| 220 | RSND_GEN_M_REG(SRC_ADINR, 0x214, 0x40), |
| 221 | RSND_GEN_M_REG(SRC_IFSCR, 0x21c, 0x40), |
| 222 | RSND_GEN_M_REG(SRC_IFSVR, 0x220, 0x40), |
| 223 | RSND_GEN_M_REG(SRC_SRCCR, 0x224, 0x40), |
| 224 | RSND_GEN_M_REG(SRC_BSDSR, 0x22c, 0x40), |
| 225 | RSND_GEN_M_REG(SRC_BSISR, 0x238, 0x40), |
| 226 | RSND_GEN_M_REG(DVC_SWRSR, 0xe00, 0x100), |
| 227 | RSND_GEN_M_REG(DVC_DVUIR, 0xe04, 0x100), |
| 228 | RSND_GEN_M_REG(DVC_ADINR, 0xe08, 0x100), |
| 229 | RSND_GEN_M_REG(DVC_DVUCR, 0xe10, 0x100), |
| 230 | RSND_GEN_M_REG(DVC_ZCMCR, 0xe14, 0x100), |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 231 | RSND_GEN_M_REG(DVC_VRCTR, 0xe18, 0x100), |
| 232 | RSND_GEN_M_REG(DVC_VRPDR, 0xe1c, 0x100), |
| 233 | RSND_GEN_M_REG(DVC_VRDBR, 0xe20, 0x100), |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 234 | RSND_GEN_M_REG(DVC_VOL0R, 0xe28, 0x100), |
| 235 | RSND_GEN_M_REG(DVC_VOL1R, 0xe2c, 0x100), |
| 236 | RSND_GEN_M_REG(DVC_DVUER, 0xe48, 0x100), |
| 237 | }; |
| 238 | struct rsnd_regmap_field_conf conf_adg[] = { |
| 239 | RSND_GEN_S_REG(BRRA, 0x00), |
| 240 | RSND_GEN_S_REG(BRRB, 0x04), |
| 241 | RSND_GEN_S_REG(SSICKR, 0x08), |
| 242 | RSND_GEN_S_REG(AUDIO_CLK_SEL0, 0x0c), |
| 243 | RSND_GEN_S_REG(AUDIO_CLK_SEL1, 0x10), |
| 244 | RSND_GEN_S_REG(AUDIO_CLK_SEL2, 0x14), |
| 245 | RSND_GEN_S_REG(DIV_EN, 0x30), |
| 246 | RSND_GEN_S_REG(SRCIN_TIMSEL0, 0x34), |
| 247 | RSND_GEN_S_REG(SRCIN_TIMSEL1, 0x38), |
| 248 | RSND_GEN_S_REG(SRCIN_TIMSEL2, 0x3c), |
| 249 | RSND_GEN_S_REG(SRCIN_TIMSEL3, 0x40), |
| 250 | RSND_GEN_S_REG(SRCIN_TIMSEL4, 0x44), |
| 251 | RSND_GEN_S_REG(SRCOUT_TIMSEL0, 0x48), |
| 252 | RSND_GEN_S_REG(SRCOUT_TIMSEL1, 0x4c), |
| 253 | RSND_GEN_S_REG(SRCOUT_TIMSEL2, 0x50), |
| 254 | RSND_GEN_S_REG(SRCOUT_TIMSEL3, 0x54), |
| 255 | RSND_GEN_S_REG(SRCOUT_TIMSEL4, 0x58), |
| 256 | RSND_GEN_S_REG(CMDOUT_TIMSEL, 0x5c), |
| 257 | }; |
| 258 | struct rsnd_regmap_field_conf conf_ssi[] = { |
| 259 | RSND_GEN_M_REG(SSICR, 0x00, 0x40), |
| 260 | RSND_GEN_M_REG(SSISR, 0x04, 0x40), |
| 261 | RSND_GEN_M_REG(SSITDR, 0x08, 0x40), |
| 262 | RSND_GEN_M_REG(SSIRDR, 0x0c, 0x40), |
| 263 | RSND_GEN_M_REG(SSIWSR, 0x20, 0x40), |
| 264 | }; |
| 265 | int ret_ssiu; |
| 266 | int ret_scu; |
| 267 | int ret_adg; |
| 268 | int ret_ssi; |
Kuninori Morimoto | 507d466 | 2013-11-28 18:43:45 -0800 | [diff] [blame] | 269 | |
Kuninori Morimoto | 7277911 | 2015-02-20 10:24:52 +0000 | [diff] [blame] | 270 | ret_ssiu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSIU, "ssiu", conf_ssiu); |
| 271 | ret_scu = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SCU, "scu", conf_scu); |
| 272 | ret_adg = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_ADG, "adg", conf_adg); |
| 273 | ret_ssi = rsnd_gen_regmap_init(priv, 10, RSND_GEN2_SSI, "ssi", conf_ssi); |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 274 | if (ret_ssiu < 0 || |
| 275 | ret_scu < 0 || |
| 276 | ret_adg < 0 || |
| 277 | ret_ssi < 0) |
| 278 | return ret_ssiu | ret_scu | ret_adg | ret_ssi; |
Kuninori Morimoto | 507d466 | 2013-11-28 18:43:45 -0800 | [diff] [blame] | 279 | |
Kuninori Morimoto | 507d466 | 2013-11-28 18:43:45 -0800 | [diff] [blame] | 280 | return 0; |
| 281 | } |
| 282 | |
Kuninori Morimoto | 994a9df | 2013-11-28 18:43:23 -0800 | [diff] [blame] | 283 | /* |
| 284 | * Gen1 |
| 285 | */ |
| 286 | |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 287 | static int rsnd_gen1_probe(struct platform_device *pdev, |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 288 | struct rsnd_priv *priv) |
| 289 | { |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 290 | struct rsnd_regmap_field_conf conf_sru[] = { |
| 291 | RSND_GEN_S_REG(SRC_ROUTE_SEL, 0x00), |
| 292 | RSND_GEN_S_REG(SRC_TMG_SEL0, 0x08), |
| 293 | RSND_GEN_S_REG(SRC_TMG_SEL1, 0x0c), |
| 294 | RSND_GEN_S_REG(SRC_TMG_SEL2, 0x10), |
| 295 | RSND_GEN_S_REG(SRC_ROUTE_CTRL, 0xc0), |
| 296 | RSND_GEN_S_REG(SSI_MODE0, 0xD0), |
| 297 | RSND_GEN_S_REG(SSI_MODE1, 0xD4), |
| 298 | RSND_GEN_M_REG(SRC_BUSIF_MODE, 0x20, 0x4), |
| 299 | RSND_GEN_M_REG(SRC_ROUTE_MODE0, 0x50, 0x8), |
| 300 | RSND_GEN_M_REG(SRC_SWRSR, 0x200, 0x40), |
| 301 | RSND_GEN_M_REG(SRC_SRCIR, 0x204, 0x40), |
| 302 | RSND_GEN_M_REG(SRC_ADINR, 0x214, 0x40), |
| 303 | RSND_GEN_M_REG(SRC_IFSCR, 0x21c, 0x40), |
| 304 | RSND_GEN_M_REG(SRC_IFSVR, 0x220, 0x40), |
| 305 | RSND_GEN_M_REG(SRC_SRCCR, 0x224, 0x40), |
| 306 | RSND_GEN_M_REG(SRC_MNFSR, 0x228, 0x40), |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 307 | /* |
| 308 | * ADD US |
| 309 | * |
| 310 | * SRC_STATUS |
| 311 | * SRC_INT_EN |
| 312 | * SCU_SYS_STATUS0 |
| 313 | * SCU_SYS_STATUS1 |
| 314 | * SCU_SYS_INT_EN0 |
| 315 | * SCU_SYS_INT_EN1 |
| 316 | */ |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 317 | }; |
| 318 | struct rsnd_regmap_field_conf conf_adg[] = { |
| 319 | RSND_GEN_S_REG(BRRA, 0x00), |
| 320 | RSND_GEN_S_REG(BRRB, 0x04), |
| 321 | RSND_GEN_S_REG(SSICKR, 0x08), |
| 322 | RSND_GEN_S_REG(AUDIO_CLK_SEL0, 0x0c), |
| 323 | RSND_GEN_S_REG(AUDIO_CLK_SEL1, 0x10), |
| 324 | RSND_GEN_S_REG(AUDIO_CLK_SEL3, 0x18), |
| 325 | RSND_GEN_S_REG(AUDIO_CLK_SEL4, 0x1c), |
| 326 | RSND_GEN_S_REG(AUDIO_CLK_SEL5, 0x20), |
| 327 | }; |
| 328 | struct rsnd_regmap_field_conf conf_ssi[] = { |
| 329 | RSND_GEN_M_REG(SSICR, 0x00, 0x40), |
| 330 | RSND_GEN_M_REG(SSISR, 0x04, 0x40), |
| 331 | RSND_GEN_M_REG(SSITDR, 0x08, 0x40), |
| 332 | RSND_GEN_M_REG(SSIRDR, 0x0c, 0x40), |
| 333 | RSND_GEN_M_REG(SSIWSR, 0x20, 0x40), |
| 334 | }; |
| 335 | int ret_sru; |
| 336 | int ret_adg; |
| 337 | int ret_ssi; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 338 | |
Kuninori Morimoto | 7277911 | 2015-02-20 10:24:52 +0000 | [diff] [blame] | 339 | ret_sru = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_SRU, "sru", conf_sru); |
| 340 | ret_adg = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_ADG, "adg", conf_adg); |
| 341 | ret_ssi = rsnd_gen_regmap_init(priv, 9, RSND_GEN1_SSI, "ssi", conf_ssi); |
Kuninori Morimoto | b8c6378 | 2014-07-29 00:37:31 -0700 | [diff] [blame] | 342 | if (ret_sru < 0 || |
| 343 | ret_adg < 0 || |
| 344 | ret_ssi < 0) |
| 345 | return ret_sru | ret_adg | ret_ssi; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 346 | |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 347 | return 0; |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 350 | /* |
| 351 | * Gen |
| 352 | */ |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 353 | static void rsnd_of_parse_gen(struct platform_device *pdev, |
| 354 | const struct rsnd_of_data *of_data, |
| 355 | struct rsnd_priv *priv) |
| 356 | { |
| 357 | struct rcar_snd_info *info = priv->info; |
| 358 | |
| 359 | if (!of_data) |
| 360 | return; |
| 361 | |
| 362 | info->flags = of_data->flags; |
| 363 | } |
| 364 | |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 365 | int rsnd_gen_probe(struct platform_device *pdev, |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 366 | const struct rsnd_of_data *of_data, |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 367 | struct rsnd_priv *priv) |
| 368 | { |
| 369 | struct device *dev = rsnd_priv_to_dev(priv); |
| 370 | struct rsnd_gen *gen; |
Kuninori Morimoto | 531eaf4 | 2013-11-28 18:43:34 -0800 | [diff] [blame] | 371 | int ret; |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 372 | |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 373 | rsnd_of_parse_gen(pdev, of_data, priv); |
| 374 | |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 375 | gen = devm_kzalloc(dev, sizeof(*gen), GFP_KERNEL); |
| 376 | if (!gen) { |
| 377 | dev_err(dev, "GEN allocate failed\n"); |
| 378 | return -ENOMEM; |
| 379 | } |
| 380 | |
Kuninori Morimoto | 531eaf4 | 2013-11-28 18:43:34 -0800 | [diff] [blame] | 381 | priv->gen = gen; |
Kuninori Morimoto | 072188b | 2013-09-01 20:31:16 -0700 | [diff] [blame] | 382 | |
Kuninori Morimoto | 507d466 | 2013-11-28 18:43:45 -0800 | [diff] [blame] | 383 | ret = -ENODEV; |
| 384 | if (rsnd_is_gen1(priv)) |
Kuninori Morimoto | 5da39cf | 2014-02-24 22:15:00 -0800 | [diff] [blame] | 385 | ret = rsnd_gen1_probe(pdev, priv); |
Kuninori Morimoto | 507d466 | 2013-11-28 18:43:45 -0800 | [diff] [blame] | 386 | else if (rsnd_is_gen2(priv)) |
Kuninori Morimoto | 5da39cf | 2014-02-24 22:15:00 -0800 | [diff] [blame] | 387 | ret = rsnd_gen2_probe(pdev, priv); |
Kuninori Morimoto | 507d466 | 2013-11-28 18:43:45 -0800 | [diff] [blame] | 388 | |
| 389 | if (ret < 0) |
Kuninori Morimoto | 072188b | 2013-09-01 20:31:16 -0700 | [diff] [blame] | 390 | dev_err(dev, "unknown generation R-Car sound device\n"); |
Kuninori Morimoto | 072188b | 2013-09-01 20:31:16 -0700 | [diff] [blame] | 391 | |
Kuninori Morimoto | 531eaf4 | 2013-11-28 18:43:34 -0800 | [diff] [blame] | 392 | return ret; |
Kuninori Morimoto | 3337744 | 2013-07-21 21:36:21 -0700 | [diff] [blame] | 393 | } |