Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Renesas R-Car SCU 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 | */ |
| 11 | #include "rsnd.h" |
| 12 | |
| 13 | struct rsnd_scu { |
| 14 | struct rsnd_scu_platform_info *info; /* rcar_snd.h */ |
| 15 | struct rsnd_mod mod; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 16 | struct clk *clk; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 17 | }; |
| 18 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 19 | #define rsnd_scu_mode_flags(p) ((p)->info->flags) |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 20 | #define rsnd_scu_convert_rate(p) ((p)->info->convert_rate) |
| 21 | |
| 22 | #define RSND_SCU_NAME_SIZE 16 |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * ADINR |
| 26 | */ |
| 27 | #define OTBL_24 (0 << 16) |
| 28 | #define OTBL_22 (2 << 16) |
| 29 | #define OTBL_20 (4 << 16) |
| 30 | #define OTBL_18 (6 << 16) |
| 31 | #define OTBL_16 (8 << 16) |
| 32 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 33 | /* |
| 34 | * image of SRC (Sampling Rate Converter) |
| 35 | * |
| 36 | * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+ |
| 37 | * 48kHz <-> | SRC | <------> | SSI | <-----> | codec | |
| 38 | * 44.1kHz <-> +-----+ +-----+ +-------+ |
| 39 | * ... |
| 40 | * |
| 41 | */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 42 | |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 43 | /* |
Kuninori Morimoto | c926b74 | 2014-01-23 18:40:41 -0800 | [diff] [blame^] | 44 | * scu.c is caring... |
| 45 | * |
| 46 | * Gen1 |
| 47 | * |
| 48 | * [mem] -> [SRU] -> [SSI] |
| 49 | * |--------| |
| 50 | * |
| 51 | * Gen2 |
| 52 | * |
| 53 | * [mem] -> [SCU] -> [SSIU] -> [SSI] |
| 54 | * |-----------------| |
| 55 | */ |
| 56 | |
| 57 | /* |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 58 | * How to use SRC bypass mode for debugging |
| 59 | * |
| 60 | * SRC has bypass mode, and it is useful for debugging. |
| 61 | * In Gen2 case, |
| 62 | * SRCm_MODE controls whether SRC is used or not |
| 63 | * SSI_MODE0 controls whether SSIU which receives SRC data |
| 64 | * is used or not. |
| 65 | * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC, |
| 66 | * but SRC bypass mode needs SSI_MODE0 only. |
| 67 | * |
| 68 | * This driver request |
| 69 | * struct rsnd_scu_platform_info { |
| 70 | * u32 flags; |
| 71 | * u32 convert_rate; |
| 72 | * } |
| 73 | * |
| 74 | * rsnd_scu_hpbif_is_enable() will be true |
| 75 | * if flags had RSND_SCU_USE_HPBIF, |
| 76 | * and it controls whether SSIU is used or not. |
| 77 | * |
| 78 | * rsnd_scu_convert_rate() indicates |
| 79 | * above convert_rate, and it controls |
| 80 | * whether SRC is used or not. |
| 81 | * |
| 82 | * ex) doesn't use SRC |
| 83 | * struct rsnd_scu_platform_info info = { |
| 84 | * .flags = 0, |
| 85 | * .convert_rate = 0, |
| 86 | * }; |
| 87 | * |
| 88 | * ex) uses SRC |
| 89 | * struct rsnd_scu_platform_info info = { |
| 90 | * .flags = RSND_SCU_USE_HPBIF, |
| 91 | * .convert_rate = 48000, |
| 92 | * }; |
| 93 | * |
| 94 | * ex) uses SRC bypass mode |
| 95 | * struct rsnd_scu_platform_info info = { |
| 96 | * .flags = RSND_SCU_USE_HPBIF, |
| 97 | * .convert_rate = 0, |
| 98 | * }; |
| 99 | * |
| 100 | */ |
| 101 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 102 | #define rsnd_mod_to_scu(_mod) \ |
| 103 | container_of((_mod), struct rsnd_scu, mod) |
| 104 | |
| 105 | #define for_each_rsnd_scu(pos, priv, i) \ |
| 106 | for ((i) = 0; \ |
| 107 | ((i) < rsnd_scu_nr(priv)) && \ |
| 108 | ((pos) = (struct rsnd_scu *)(priv)->scu + i); \ |
| 109 | i++) |
| 110 | |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 111 | static int rsnd_scu_ssi_mode_init(struct rsnd_mod *mod, |
| 112 | struct rsnd_dai *rdai, |
| 113 | struct rsnd_dai_stream *io) |
| 114 | { |
| 115 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 116 | int id = rsnd_mod_id(mod); |
| 117 | |
| 118 | /* |
| 119 | * SSI_MODE0 |
| 120 | */ |
| 121 | rsnd_mod_bset(mod, SSI_MODE0, (1 << id), |
| 122 | rsnd_scu_hpbif_is_enable(mod) ? 0 : (1 << id)); |
| 123 | |
| 124 | /* |
| 125 | * SSI_MODE1 |
| 126 | */ |
| 127 | if (rsnd_ssi_is_pin_sharing(rsnd_ssi_mod_get(priv, id))) { |
| 128 | int shift = -1; |
| 129 | switch (id) { |
| 130 | case 1: |
| 131 | shift = 0; |
| 132 | break; |
| 133 | case 2: |
| 134 | shift = 2; |
| 135 | break; |
| 136 | case 4: |
| 137 | shift = 16; |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | if (shift >= 0) |
| 142 | rsnd_mod_bset(mod, SSI_MODE1, |
| 143 | 0x3 << shift, |
| 144 | rsnd_dai_is_clk_master(rdai) ? |
| 145 | 0x2 << shift : 0x1 << shift); |
| 146 | } |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
Kuninori Morimoto | 2582718c | 2013-12-19 19:27:37 -0800 | [diff] [blame] | 151 | /* Gen1 only */ |
Kuninori Morimoto | 47718dc | 2014-01-23 18:38:42 -0800 | [diff] [blame] | 152 | static int rsnd_src_set_route_if_gen1( |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 153 | struct rsnd_mod *mod, |
| 154 | struct rsnd_dai *rdai, |
| 155 | struct rsnd_dai_stream *io) |
| 156 | { |
| 157 | struct scu_route_config { |
| 158 | u32 mask; |
| 159 | int shift; |
| 160 | } routes[] = { |
| 161 | { 0xF, 0, }, /* 0 */ |
| 162 | { 0xF, 4, }, /* 1 */ |
| 163 | { 0xF, 8, }, /* 2 */ |
| 164 | { 0x7, 12, }, /* 3 */ |
| 165 | { 0x7, 16, }, /* 4 */ |
| 166 | { 0x7, 20, }, /* 5 */ |
| 167 | { 0x7, 24, }, /* 6 */ |
| 168 | { 0x3, 28, }, /* 7 */ |
| 169 | { 0x3, 30, }, /* 8 */ |
| 170 | }; |
Kuninori Morimoto | 47718dc | 2014-01-23 18:38:42 -0800 | [diff] [blame] | 171 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 172 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 173 | u32 mask; |
| 174 | u32 val; |
| 175 | int shift; |
| 176 | int id; |
| 177 | |
| 178 | /* |
| 179 | * Gen1 only |
| 180 | */ |
| 181 | if (!rsnd_is_gen1(priv)) |
| 182 | return 0; |
| 183 | |
| 184 | id = rsnd_mod_id(mod); |
Dan Carpenter | b5f3d7a | 2013-11-08 12:46:10 +0300 | [diff] [blame] | 185 | if (id < 0 || id >= ARRAY_SIZE(routes)) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 186 | return -EIO; |
| 187 | |
| 188 | /* |
| 189 | * SRC_ROUTE_SELECT |
| 190 | */ |
| 191 | val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2; |
| 192 | val = val << routes[id].shift; |
| 193 | mask = routes[id].mask << routes[id].shift; |
| 194 | |
| 195 | rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val); |
| 196 | |
| 197 | /* |
| 198 | * SRC_TIMING_SELECT |
| 199 | */ |
| 200 | shift = (id % 4) * 8; |
| 201 | mask = 0x1F << shift; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * ADG is used as source clock if SRC was used, |
| 205 | * then, SSI WS is used as destination clock. |
| 206 | * SSI WS is used as source clock if SRC is not used |
| 207 | * (when playback, source/destination become reverse when capture) |
| 208 | */ |
| 209 | if (rsnd_scu_convert_rate(scu)) /* use ADG */ |
| 210 | val = 0; |
| 211 | else if (8 == id) /* use SSI WS, but SRU8 is special */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 212 | val = id << shift; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 213 | else /* use SSI WS */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 214 | val = (id + 1) << shift; |
| 215 | |
| 216 | switch (id / 4) { |
| 217 | case 0: |
| 218 | rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val); |
| 219 | break; |
| 220 | case 1: |
| 221 | rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val); |
| 222 | break; |
| 223 | case 2: |
| 224 | rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val); |
| 225 | break; |
| 226 | } |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 231 | unsigned int rsnd_scu_get_ssi_rate(struct rsnd_priv *priv, |
| 232 | struct rsnd_mod *ssi_mod, |
| 233 | struct snd_pcm_runtime *runtime) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 234 | { |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 235 | struct rsnd_scu *scu; |
| 236 | unsigned int rate; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 237 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 238 | /* this function is assuming SSI id = SCU id here */ |
| 239 | scu = rsnd_mod_to_scu(rsnd_scu_mod_get(priv, rsnd_mod_id(ssi_mod))); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 240 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 241 | /* |
| 242 | * return convert rate if SRC is used, |
| 243 | * otherwise, return runtime->rate as usual |
| 244 | */ |
| 245 | rate = rsnd_scu_convert_rate(scu); |
| 246 | if (!rate) |
| 247 | rate = runtime->rate; |
| 248 | |
| 249 | return rate; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Kuninori Morimoto | f80e1c9 | 2014-01-23 18:39:48 -0800 | [diff] [blame] | 252 | static int rsnd_scu_set_convert_rate(struct rsnd_mod *mod, |
| 253 | struct rsnd_dai *rdai, |
| 254 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 255 | { |
Kuninori Morimoto | 47718dc | 2014-01-23 18:38:42 -0800 | [diff] [blame] | 256 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 257 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 258 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
| 259 | u32 convert_rate = rsnd_scu_convert_rate(scu); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 260 | u32 adinr = runtime->channels; |
| 261 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 262 | /* set/clear soft reset */ |
| 263 | rsnd_mod_write(mod, SRC_SWRSR, 0); |
| 264 | rsnd_mod_write(mod, SRC_SWRSR, 1); |
| 265 | |
| 266 | /* Initialize the operation of the SRC internal circuits */ |
| 267 | rsnd_mod_write(mod, SRC_SRCIR, 1); |
| 268 | |
| 269 | /* Set channel number and output bit length */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 270 | switch (runtime->sample_bits) { |
| 271 | case 16: |
| 272 | adinr |= OTBL_16; |
| 273 | break; |
| 274 | case 32: |
| 275 | adinr |= OTBL_24; |
| 276 | break; |
| 277 | default: |
| 278 | return -EIO; |
| 279 | } |
Kuninori Morimoto | 690ef81 | 2013-12-19 19:27:03 -0800 | [diff] [blame] | 280 | rsnd_mod_write(mod, SRC_ADINR, adinr); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 281 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 282 | if (convert_rate) { |
| 283 | u32 fsrate = 0x0400000 / convert_rate * runtime->rate; |
| 284 | int ret; |
| 285 | |
| 286 | /* Enable the initial value of IFS */ |
| 287 | rsnd_mod_write(mod, SRC_IFSCR, 1); |
| 288 | |
| 289 | /* Set initial value of IFS */ |
| 290 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); |
| 291 | |
| 292 | /* Select SRC mode (fixed value) */ |
| 293 | rsnd_mod_write(mod, SRC_SRCCR, 0x00010110); |
| 294 | |
| 295 | /* Set the restriction value of the FS ratio (98%) */ |
| 296 | rsnd_mod_write(mod, SRC_MNFSR, fsrate / 100 * 98); |
| 297 | |
| 298 | if (rsnd_is_gen1(priv)) { |
| 299 | /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ |
| 300 | } |
| 301 | |
| 302 | /* set convert clock */ |
| 303 | ret = rsnd_adg_set_convert_clk(priv, mod, |
| 304 | runtime->rate, |
| 305 | convert_rate); |
| 306 | if (ret < 0) |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | /* Cancel the initialization and operate the SRC function */ |
| 311 | rsnd_mod_write(mod, SRC_SRCIR, 0); |
| 312 | |
| 313 | /* use DMA transfer */ |
Kuninori Morimoto | 0290d2a | 2014-01-23 18:37:39 -0800 | [diff] [blame] | 314 | rsnd_mod_write(mod, SRC_BUSIF_MODE, 1); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 315 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
Kuninori Morimoto | cdcfcac | 2013-10-17 22:50:59 -0700 | [diff] [blame] | 319 | bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod) |
| 320 | { |
| 321 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
| 322 | u32 flags = rsnd_scu_mode_flags(scu); |
| 323 | |
| 324 | return !!(flags & RSND_SCU_USE_HPBIF); |
| 325 | } |
| 326 | |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 327 | static int rsnd_scu_init(struct rsnd_mod *mod, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 328 | struct rsnd_dai *rdai, |
| 329 | struct rsnd_dai_stream *io) |
| 330 | { |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 331 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 332 | int ret; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 333 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 334 | clk_enable(scu->clk); |
| 335 | |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 336 | ret = rsnd_scu_ssi_mode_init(mod, rdai, io); |
| 337 | if (ret < 0) |
| 338 | return ret; |
| 339 | |
Kuninori Morimoto | 47718dc | 2014-01-23 18:38:42 -0800 | [diff] [blame] | 340 | ret = rsnd_src_set_route_if_gen1(mod, rdai, io); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 341 | if (ret < 0) |
| 342 | return ret; |
| 343 | |
Kuninori Morimoto | f80e1c9 | 2014-01-23 18:39:48 -0800 | [diff] [blame] | 344 | ret = rsnd_scu_set_convert_rate(mod, rdai, io); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 345 | if (ret < 0) |
| 346 | return ret; |
| 347 | |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | static int rsnd_scu_quit(struct rsnd_mod *mod, |
| 352 | struct rsnd_dai *rdai, |
| 353 | struct rsnd_dai_stream *io) |
| 354 | { |
| 355 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
| 356 | |
| 357 | clk_disable(scu->clk); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 358 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 359 | return 0; |
| 360 | } |
| 361 | |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 362 | static int rsnd_scu_start(struct rsnd_mod *mod, |
| 363 | struct rsnd_dai *rdai, |
| 364 | struct rsnd_dai_stream *io) |
| 365 | { |
| 366 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 367 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 368 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 369 | |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 370 | if (rsnd_is_gen1(priv)) |
| 371 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id)); |
| 372 | |
| 373 | if (rsnd_scu_convert_rate(scu)) |
| 374 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); |
| 375 | |
| 376 | return 0; |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 377 | } |
| 378 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 379 | static int rsnd_scu_stop(struct rsnd_mod *mod, |
| 380 | struct rsnd_dai *rdai, |
| 381 | struct rsnd_dai_stream *io) |
| 382 | { |
| 383 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 384 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 385 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 386 | |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 387 | if (rsnd_is_gen1(priv)) |
| 388 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0); |
| 389 | |
| 390 | if (rsnd_scu_convert_rate(scu)) |
| 391 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 392 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 393 | return 0; |
| 394 | } |
| 395 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 396 | static struct rsnd_mod_ops rsnd_scu_ops = { |
| 397 | .name = "scu", |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 398 | .init = rsnd_scu_init, |
| 399 | .quit = rsnd_scu_quit, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 400 | .start = rsnd_scu_start, |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 401 | .stop = rsnd_scu_stop, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 402 | }; |
| 403 | |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 404 | static struct rsnd_mod_ops rsnd_scu_non_ops = { |
| 405 | .name = "scu (non)", |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 406 | .init = rsnd_scu_ssi_mode_init, |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 407 | }; |
| 408 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 409 | struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id) |
| 410 | { |
Takashi Iwai | 8b14719 | 2013-11-05 18:40:05 +0100 | [diff] [blame] | 411 | if (WARN_ON(id < 0 || id >= rsnd_scu_nr(priv))) |
| 412 | id = 0; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 413 | |
| 414 | return &((struct rsnd_scu *)(priv->scu) + id)->mod; |
| 415 | } |
| 416 | |
| 417 | int rsnd_scu_probe(struct platform_device *pdev, |
| 418 | struct rcar_snd_info *info, |
| 419 | struct rsnd_priv *priv) |
| 420 | { |
| 421 | struct device *dev = rsnd_priv_to_dev(priv); |
| 422 | struct rsnd_scu *scu; |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 423 | struct rsnd_mod_ops *ops; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 424 | struct clk *clk; |
| 425 | char name[RSND_SCU_NAME_SIZE]; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 426 | int i, nr; |
| 427 | |
| 428 | /* |
| 429 | * init SCU |
| 430 | */ |
| 431 | nr = info->scu_info_nr; |
| 432 | scu = devm_kzalloc(dev, sizeof(*scu) * nr, GFP_KERNEL); |
| 433 | if (!scu) { |
| 434 | dev_err(dev, "SCU allocate failed\n"); |
| 435 | return -ENOMEM; |
| 436 | } |
| 437 | |
| 438 | priv->scu_nr = nr; |
| 439 | priv->scu = scu; |
| 440 | |
| 441 | for_each_rsnd_scu(scu, priv, i) { |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 442 | snprintf(name, RSND_SCU_NAME_SIZE, "scu.%d", i); |
| 443 | |
| 444 | clk = devm_clk_get(dev, name); |
| 445 | if (IS_ERR(clk)) |
| 446 | return PTR_ERR(clk); |
| 447 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 448 | scu->info = &info->scu_info[i]; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 449 | scu->clk = clk; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 450 | |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 451 | ops = &rsnd_scu_non_ops; |
| 452 | if (rsnd_scu_hpbif_is_enable(&scu->mod)) |
| 453 | ops = &rsnd_scu_ops; |
| 454 | |
| 455 | rsnd_mod_init(priv, &scu->mod, ops, i); |
| 456 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 457 | dev_dbg(dev, "SCU%d probed\n", i); |
| 458 | } |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 459 | dev_dbg(dev, "scu probed\n"); |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | void rsnd_scu_remove(struct platform_device *pdev, |
| 465 | struct rsnd_priv *priv) |
| 466 | { |
| 467 | } |