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