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 | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 113 | /* |
| 114 | * Gen1/Gen2 common functions |
| 115 | */ |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 116 | static int rsnd_scu_ssi_mode_init(struct rsnd_mod *mod, |
| 117 | struct rsnd_dai *rdai, |
| 118 | struct rsnd_dai_stream *io) |
| 119 | { |
| 120 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 96c7c0d | 2014-01-23 18:40:54 -0800 | [diff] [blame] | 121 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 122 | int id = rsnd_mod_id(mod); |
| 123 | |
| 124 | /* |
| 125 | * SSI_MODE0 |
| 126 | */ |
| 127 | rsnd_mod_bset(mod, SSI_MODE0, (1 << id), |
Kuninori Morimoto | 96c7c0d | 2014-01-23 18:40:54 -0800 | [diff] [blame] | 128 | rsnd_scu_hpbif_is_enable(scu) ? 0 : (1 << id)); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * SSI_MODE1 |
| 132 | */ |
| 133 | if (rsnd_ssi_is_pin_sharing(rsnd_ssi_mod_get(priv, id))) { |
| 134 | int shift = -1; |
| 135 | switch (id) { |
| 136 | case 1: |
| 137 | shift = 0; |
| 138 | break; |
| 139 | case 2: |
| 140 | shift = 2; |
| 141 | break; |
| 142 | case 4: |
| 143 | shift = 16; |
| 144 | break; |
| 145 | } |
| 146 | |
| 147 | if (shift >= 0) |
| 148 | rsnd_mod_bset(mod, SSI_MODE1, |
| 149 | 0x3 << shift, |
| 150 | rsnd_dai_is_clk_master(rdai) ? |
| 151 | 0x2 << shift : 0x1 << shift); |
| 152 | } |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 157 | unsigned int rsnd_scu_get_ssi_rate(struct rsnd_priv *priv, |
| 158 | struct rsnd_mod *ssi_mod, |
| 159 | struct snd_pcm_runtime *runtime) |
| 160 | { |
| 161 | struct rsnd_scu *scu; |
| 162 | unsigned int rate; |
| 163 | |
| 164 | /* this function is assuming SSI id = SCU id here */ |
| 165 | scu = rsnd_mod_to_scu(rsnd_scu_mod_get(priv, rsnd_mod_id(ssi_mod))); |
| 166 | |
| 167 | /* |
| 168 | * return convert rate if SRC is used, |
| 169 | * otherwise, return runtime->rate as usual |
| 170 | */ |
| 171 | rate = rsnd_scu_convert_rate(scu); |
| 172 | if (!rate) |
| 173 | rate = runtime->rate; |
| 174 | |
| 175 | return rate; |
| 176 | } |
| 177 | |
| 178 | static int rsnd_scu_set_convert_rate(struct rsnd_mod *mod, |
| 179 | struct rsnd_dai *rdai, |
| 180 | struct rsnd_dai_stream *io) |
| 181 | { |
| 182 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 183 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
| 184 | u32 convert_rate = rsnd_scu_convert_rate(scu); |
| 185 | u32 adinr = runtime->channels; |
| 186 | u32 fsrate = 0; |
| 187 | |
| 188 | if (convert_rate) |
| 189 | fsrate = 0x0400000 / convert_rate * runtime->rate; |
| 190 | |
| 191 | /* set/clear soft reset */ |
| 192 | rsnd_mod_write(mod, SRC_SWRSR, 0); |
| 193 | rsnd_mod_write(mod, SRC_SWRSR, 1); |
| 194 | |
| 195 | /* |
| 196 | * Initialize the operation of the SRC internal circuits |
| 197 | * see rsnd_scu_start() |
| 198 | */ |
| 199 | rsnd_mod_write(mod, SRC_SRCIR, 1); |
| 200 | |
| 201 | /* Set channel number and output bit length */ |
| 202 | switch (runtime->sample_bits) { |
| 203 | case 16: |
| 204 | adinr |= OTBL_16; |
| 205 | break; |
| 206 | case 32: |
| 207 | adinr |= OTBL_24; |
| 208 | break; |
| 209 | default: |
| 210 | return -EIO; |
| 211 | } |
| 212 | rsnd_mod_write(mod, SRC_ADINR, adinr); |
| 213 | |
| 214 | /* Enable the initial value of IFS */ |
| 215 | if (fsrate) { |
| 216 | rsnd_mod_write(mod, SRC_IFSCR, 1); |
| 217 | |
| 218 | /* Set initial value of IFS */ |
| 219 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); |
| 220 | } |
| 221 | |
| 222 | /* use DMA transfer */ |
| 223 | rsnd_mod_write(mod, SRC_BUSIF_MODE, 1); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | static int rsnd_scu_init(struct rsnd_mod *mod, |
| 229 | struct rsnd_dai *rdai, |
| 230 | struct rsnd_dai_stream *io) |
| 231 | { |
| 232 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
| 233 | int ret; |
| 234 | |
| 235 | clk_enable(scu->clk); |
| 236 | |
| 237 | ret = rsnd_scu_ssi_mode_init(mod, rdai, io); |
| 238 | if (ret < 0) |
| 239 | return ret; |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | static int rsnd_scu_quit(struct rsnd_mod *mod, |
| 245 | struct rsnd_dai *rdai, |
| 246 | struct rsnd_dai_stream *io) |
| 247 | { |
| 248 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
| 249 | |
| 250 | clk_disable(scu->clk); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | static int rsnd_scu_start(struct rsnd_mod *mod, |
| 256 | struct rsnd_dai *rdai, |
| 257 | struct rsnd_dai_stream *io) |
| 258 | { |
| 259 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
| 260 | |
| 261 | /* |
| 262 | * Cancel the initialization and operate the SRC function |
| 263 | * see rsnd_scu_set_convert_rate() |
| 264 | */ |
| 265 | rsnd_mod_write(mod, SRC_SRCIR, 0); |
| 266 | |
| 267 | if (rsnd_scu_convert_rate(scu)) |
| 268 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | |
| 274 | static int rsnd_scu_stop(struct rsnd_mod *mod, |
| 275 | struct rsnd_dai *rdai, |
| 276 | struct rsnd_dai_stream *io) |
| 277 | { |
| 278 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
| 279 | |
| 280 | if (rsnd_scu_convert_rate(scu)) |
| 281 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0); |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | static struct rsnd_mod_ops rsnd_scu_non_ops = { |
| 287 | .name = "scu (non)", |
| 288 | }; |
| 289 | |
| 290 | /* |
| 291 | * Gen1 functions |
| 292 | */ |
| 293 | static int rsnd_src_set_route_gen1(struct rsnd_mod *mod, |
| 294 | struct rsnd_dai *rdai, |
| 295 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 296 | { |
| 297 | struct scu_route_config { |
| 298 | u32 mask; |
| 299 | int shift; |
| 300 | } routes[] = { |
| 301 | { 0xF, 0, }, /* 0 */ |
| 302 | { 0xF, 4, }, /* 1 */ |
| 303 | { 0xF, 8, }, /* 2 */ |
| 304 | { 0x7, 12, }, /* 3 */ |
| 305 | { 0x7, 16, }, /* 4 */ |
| 306 | { 0x7, 20, }, /* 5 */ |
| 307 | { 0x7, 24, }, /* 6 */ |
| 308 | { 0x3, 28, }, /* 7 */ |
| 309 | { 0x3, 30, }, /* 8 */ |
| 310 | }; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 311 | u32 mask; |
| 312 | u32 val; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 313 | int id; |
| 314 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 315 | id = rsnd_mod_id(mod); |
Dan Carpenter | b5f3d7a | 2013-11-08 12:46:10 +0300 | [diff] [blame] | 316 | if (id < 0 || id >= ARRAY_SIZE(routes)) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 317 | return -EIO; |
| 318 | |
| 319 | /* |
| 320 | * SRC_ROUTE_SELECT |
| 321 | */ |
| 322 | val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2; |
| 323 | val = val << routes[id].shift; |
| 324 | mask = routes[id].mask << routes[id].shift; |
| 325 | |
| 326 | rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val); |
| 327 | |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static int rsnd_scu_set_convert_timing_gen1(struct rsnd_mod *mod, |
| 332 | struct rsnd_dai *rdai, |
| 333 | struct rsnd_dai_stream *io) |
| 334 | { |
| 335 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 336 | struct rsnd_scu *scu = rsnd_mod_to_scu(mod); |
| 337 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 338 | u32 convert_rate = rsnd_scu_convert_rate(scu); |
| 339 | u32 mask; |
| 340 | u32 val; |
| 341 | int shift; |
| 342 | int id = rsnd_mod_id(mod); |
| 343 | int ret; |
| 344 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 345 | /* |
| 346 | * SRC_TIMING_SELECT |
| 347 | */ |
| 348 | shift = (id % 4) * 8; |
| 349 | mask = 0x1F << shift; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 350 | |
| 351 | /* |
| 352 | * ADG is used as source clock if SRC was used, |
| 353 | * then, SSI WS is used as destination clock. |
| 354 | * SSI WS is used as source clock if SRC is not used |
| 355 | * (when playback, source/destination become reverse when capture) |
| 356 | */ |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 357 | ret = 0; |
| 358 | if (convert_rate) { |
| 359 | /* use ADG */ |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 360 | val = 0; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 361 | ret = rsnd_adg_set_convert_clk_gen1(priv, mod, |
| 362 | runtime->rate, |
| 363 | convert_rate); |
| 364 | } else if (8 == id) { |
| 365 | /* use SSI WS, but SRU8 is special */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 366 | val = id << shift; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 367 | } else { |
| 368 | /* use SSI WS */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 369 | val = (id + 1) << shift; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | if (ret < 0) |
| 373 | return ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 374 | |
| 375 | switch (id / 4) { |
| 376 | case 0: |
| 377 | rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val); |
| 378 | break; |
| 379 | case 1: |
| 380 | rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val); |
| 381 | break; |
| 382 | case 2: |
| 383 | rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val); |
| 384 | break; |
| 385 | } |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 390 | static int rsnd_scu_set_convert_rate_gen1(struct rsnd_mod *mod, |
| 391 | struct rsnd_dai *rdai, |
| 392 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 393 | { |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 394 | int ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 395 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 396 | ret = rsnd_scu_set_convert_rate(mod, rdai, io); |
| 397 | if (ret < 0) |
| 398 | return ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 399 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 400 | /* Select SRC mode (fixed value) */ |
| 401 | rsnd_mod_write(mod, SRC_SRCCR, 0x00010110); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 402 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 403 | /* Set the restriction value of the FS ratio (98%) */ |
| 404 | rsnd_mod_write(mod, SRC_MNFSR, |
| 405 | rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 406 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 407 | /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 408 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 409 | return 0; |
| 410 | } |
| 411 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 412 | static int rsnd_scu_init_gen1(struct rsnd_mod *mod, |
| 413 | struct rsnd_dai *rdai, |
| 414 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 415 | { |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 416 | int ret; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 417 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 418 | ret = rsnd_scu_init(mod, rdai, io); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 419 | if (ret < 0) |
| 420 | return ret; |
| 421 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 422 | ret = rsnd_src_set_route_gen1(mod, rdai, io); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 423 | if (ret < 0) |
| 424 | return ret; |
| 425 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 426 | ret = rsnd_scu_set_convert_rate_gen1(mod, rdai, io); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 427 | if (ret < 0) |
| 428 | return ret; |
| 429 | |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 430 | ret = rsnd_scu_set_convert_timing_gen1(mod, rdai, io); |
| 431 | if (ret < 0) |
| 432 | return ret; |
| 433 | |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 434 | return 0; |
| 435 | } |
| 436 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 437 | static int rsnd_scu_start_gen1(struct rsnd_mod *mod, |
| 438 | struct rsnd_dai *rdai, |
| 439 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 440 | { |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 441 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 442 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 443 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id)); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 444 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 445 | return rsnd_scu_start(mod, rdai, io); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 448 | static int rsnd_scu_stop_gen1(struct rsnd_mod *mod, |
| 449 | struct rsnd_dai *rdai, |
| 450 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 451 | { |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 452 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 453 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 454 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 455 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 456 | return rsnd_scu_stop(mod, rdai, io); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 457 | } |
| 458 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 459 | static struct rsnd_mod_ops rsnd_scu_gen1_ops = { |
| 460 | .name = "sru (gen1)", |
| 461 | .init = rsnd_scu_init_gen1, |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 462 | .quit = rsnd_scu_quit, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 463 | .start = rsnd_scu_start_gen1, |
| 464 | .stop = rsnd_scu_stop_gen1, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 465 | }; |
| 466 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 467 | static struct rsnd_mod_ops rsnd_scu_non_gen1_ops = { |
| 468 | .name = "non-sru (gen1)", |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 469 | .init = rsnd_scu_ssi_mode_init, |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 470 | }; |
| 471 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 472 | /* |
| 473 | * Gen2 functions |
| 474 | */ |
| 475 | static int rsnd_scu_start_non_gen2(struct rsnd_mod *mod, |
| 476 | struct rsnd_dai *rdai, |
| 477 | struct rsnd_dai_stream *io) |
| 478 | { |
| 479 | /* enable PIO interrupt */ |
| 480 | rsnd_mod_write(mod, INT_ENABLE, 0x0f000000); |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | static struct rsnd_mod_ops rsnd_scu_non_gen2_ops = { |
| 486 | .name = "non-scu (gen2)", |
| 487 | .init = rsnd_scu_ssi_mode_init, |
| 488 | .start = rsnd_scu_start_non_gen2, |
| 489 | }; |
| 490 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 491 | struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id) |
| 492 | { |
Takashi Iwai | 8b14719 | 2013-11-05 18:40:05 +0100 | [diff] [blame] | 493 | if (WARN_ON(id < 0 || id >= rsnd_scu_nr(priv))) |
| 494 | id = 0; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 495 | |
| 496 | return &((struct rsnd_scu *)(priv->scu) + id)->mod; |
| 497 | } |
| 498 | |
| 499 | int rsnd_scu_probe(struct platform_device *pdev, |
| 500 | struct rcar_snd_info *info, |
| 501 | struct rsnd_priv *priv) |
| 502 | { |
| 503 | struct device *dev = rsnd_priv_to_dev(priv); |
| 504 | struct rsnd_scu *scu; |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 505 | struct rsnd_mod_ops *ops; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 506 | struct clk *clk; |
| 507 | char name[RSND_SCU_NAME_SIZE]; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 508 | int i, nr; |
| 509 | |
| 510 | /* |
| 511 | * init SCU |
| 512 | */ |
| 513 | nr = info->scu_info_nr; |
| 514 | scu = devm_kzalloc(dev, sizeof(*scu) * nr, GFP_KERNEL); |
| 515 | if (!scu) { |
| 516 | dev_err(dev, "SCU allocate failed\n"); |
| 517 | return -ENOMEM; |
| 518 | } |
| 519 | |
| 520 | priv->scu_nr = nr; |
| 521 | priv->scu = scu; |
| 522 | |
| 523 | for_each_rsnd_scu(scu, priv, i) { |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 524 | snprintf(name, RSND_SCU_NAME_SIZE, "scu.%d", i); |
| 525 | |
| 526 | clk = devm_clk_get(dev, name); |
| 527 | if (IS_ERR(clk)) |
| 528 | return PTR_ERR(clk); |
| 529 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 530 | scu->info = &info->scu_info[i]; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 531 | scu->clk = clk; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 532 | |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 533 | ops = &rsnd_scu_non_ops; |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 534 | if (rsnd_scu_hpbif_is_enable(scu)) { |
| 535 | if (rsnd_is_gen1(priv)) |
| 536 | ops = &rsnd_scu_gen1_ops; |
| 537 | } else { |
| 538 | if (rsnd_is_gen1(priv)) |
| 539 | ops = &rsnd_scu_non_gen1_ops; |
| 540 | if (rsnd_is_gen2(priv)) |
| 541 | ops = &rsnd_scu_non_gen2_ops; |
| 542 | } |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 543 | |
| 544 | rsnd_mod_init(priv, &scu->mod, ops, i); |
| 545 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 546 | dev_dbg(dev, "SCU%d probed\n", i); |
| 547 | } |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 548 | dev_dbg(dev, "scu probed\n"); |
| 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | void rsnd_scu_remove(struct platform_device *pdev, |
| 554 | struct rsnd_priv *priv) |
| 555 | { |
| 556 | } |