Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1 | /* |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 2 | * Renesas R-Car SRC support |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 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 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 13 | struct rsnd_src { |
| 14 | struct rsnd_src_platform_info *info; /* rcar_snd.h */ |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 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 | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 19 | #define RSND_SRC_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 | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 30 | #define rsnd_src_mode_flags(p) ((p)->info->flags) |
| 31 | #define rsnd_src_convert_rate(p) ((p)->info->convert_rate) |
| 32 | #define rsnd_mod_to_src(_mod) \ |
| 33 | container_of((_mod), struct rsnd_src, mod) |
| 34 | #define rsnd_src_hpbif_is_enable(src) \ |
| 35 | (rsnd_src_mode_flags(src) & RSND_SCU_USE_HPBIF) |
| 36 | #define rsnd_src_dma_available(src) \ |
| 37 | rsnd_dma_available(rsnd_mod_to_dma(&(src)->mod)) |
Kuninori Morimoto | 39cf3c4 | 2014-01-23 18:40:47 -0800 | [diff] [blame] | 38 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 39 | #define for_each_rsnd_src(pos, priv, i) \ |
Kuninori Morimoto | 39cf3c4 | 2014-01-23 18:40:47 -0800 | [diff] [blame] | 40 | for ((i) = 0; \ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 41 | ((i) < rsnd_src_nr(priv)) && \ |
| 42 | ((pos) = (struct rsnd_src *)(priv)->src + i); \ |
Kuninori Morimoto | 39cf3c4 | 2014-01-23 18:40:47 -0800 | [diff] [blame] | 43 | i++) |
| 44 | |
| 45 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 46 | /* |
| 47 | * image of SRC (Sampling Rate Converter) |
| 48 | * |
| 49 | * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+ |
| 50 | * 48kHz <-> | SRC | <------> | SSI | <-----> | codec | |
| 51 | * 44.1kHz <-> +-----+ +-----+ +-------+ |
| 52 | * ... |
| 53 | * |
| 54 | */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 55 | |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 56 | /* |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 57 | * src.c is caring... |
Kuninori Morimoto | c926b74 | 2014-01-23 18:40:41 -0800 | [diff] [blame] | 58 | * |
| 59 | * Gen1 |
| 60 | * |
| 61 | * [mem] -> [SRU] -> [SSI] |
| 62 | * |--------| |
| 63 | * |
| 64 | * Gen2 |
| 65 | * |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 66 | * [mem] -> [SRC] -> [SSIU] -> [SSI] |
Kuninori Morimoto | c926b74 | 2014-01-23 18:40:41 -0800 | [diff] [blame] | 67 | * |-----------------| |
| 68 | */ |
| 69 | |
| 70 | /* |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 71 | * How to use SRC bypass mode for debugging |
| 72 | * |
| 73 | * SRC has bypass mode, and it is useful for debugging. |
| 74 | * In Gen2 case, |
| 75 | * SRCm_MODE controls whether SRC is used or not |
| 76 | * SSI_MODE0 controls whether SSIU which receives SRC data |
| 77 | * is used or not. |
| 78 | * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC, |
| 79 | * but SRC bypass mode needs SSI_MODE0 only. |
| 80 | * |
| 81 | * This driver request |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 82 | * struct rsnd_src_platform_info { |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 83 | * u32 flags; |
| 84 | * u32 convert_rate; |
| 85 | * } |
| 86 | * |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 87 | * rsnd_src_hpbif_is_enable() will be true |
| 88 | * if flags had RSND_SRC_USE_HPBIF, |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 89 | * and it controls whether SSIU is used or not. |
| 90 | * |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 91 | * rsnd_src_convert_rate() indicates |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 92 | * above convert_rate, and it controls |
| 93 | * whether SRC is used or not. |
| 94 | * |
| 95 | * ex) doesn't use SRC |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 96 | * struct rsnd_src_platform_info info = { |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 97 | * .flags = 0, |
| 98 | * .convert_rate = 0, |
| 99 | * }; |
| 100 | * |
| 101 | * ex) uses SRC |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 102 | * struct rsnd_src_platform_info info = { |
| 103 | * .flags = RSND_SRC_USE_HPBIF, |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 104 | * .convert_rate = 48000, |
| 105 | * }; |
| 106 | * |
| 107 | * ex) uses SRC bypass mode |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 108 | * struct rsnd_src_platform_info info = { |
| 109 | * .flags = RSND_SRC_USE_HPBIF, |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 110 | * .convert_rate = 0, |
| 111 | * }; |
| 112 | * |
| 113 | */ |
| 114 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 115 | /* |
| 116 | * Gen1/Gen2 common functions |
| 117 | */ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 118 | int rsnd_src_ssi_mode_init(struct rsnd_mod *ssi_mod, |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 119 | struct rsnd_dai *rdai, |
| 120 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 121 | { |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 122 | struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 123 | struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 124 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 125 | int ssi_id = rsnd_mod_id(ssi_mod); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 126 | int has_src = 0; |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * SSI_MODE0 |
| 130 | */ |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 131 | if (info->dai_info) { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 132 | has_src = !!src_mod; |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 133 | } else { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 134 | struct rsnd_src *src = rsnd_mod_to_src(src_mod); |
| 135 | has_src = rsnd_src_hpbif_is_enable(src); |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id), |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 139 | has_src ? 0 : (1 << ssi_id)); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * SSI_MODE1 |
| 143 | */ |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 144 | if (rsnd_ssi_is_pin_sharing(ssi_mod)) { |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 145 | int shift = -1; |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 146 | switch (ssi_id) { |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 147 | case 1: |
| 148 | shift = 0; |
| 149 | break; |
| 150 | case 2: |
| 151 | shift = 2; |
| 152 | break; |
| 153 | case 4: |
| 154 | shift = 16; |
| 155 | break; |
| 156 | } |
| 157 | |
| 158 | if (shift >= 0) |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 159 | rsnd_mod_bset(ssi_mod, SSI_MODE1, |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 160 | 0x3 << shift, |
| 161 | rsnd_dai_is_clk_master(rdai) ? |
| 162 | 0x2 << shift : 0x1 << shift); |
| 163 | } |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 168 | int rsnd_src_enable_ssi_irq(struct rsnd_mod *ssi_mod, |
Kuninori Morimoto | b8cc41e | 2014-03-03 20:50:08 -0800 | [diff] [blame] | 169 | struct rsnd_dai *rdai, |
| 170 | struct rsnd_dai_stream *io) |
| 171 | { |
| 172 | struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); |
| 173 | |
| 174 | /* enable PIO interrupt if Gen2 */ |
| 175 | if (rsnd_is_gen2(priv)) |
| 176 | rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000); |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 181 | unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 182 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 183 | struct snd_pcm_runtime *runtime) |
| 184 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 185 | struct rsnd_src *src; |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 186 | unsigned int rate; |
| 187 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 188 | src = rsnd_mod_to_src(rsnd_io_to_mod_src(io)); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * return convert rate if SRC is used, |
| 192 | * otherwise, return runtime->rate as usual |
| 193 | */ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 194 | rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 195 | if (!rate) |
| 196 | rate = runtime->rate; |
| 197 | |
| 198 | return rate; |
| 199 | } |
| 200 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 201 | static int rsnd_src_set_convert_rate(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 202 | struct rsnd_dai *rdai, |
| 203 | struct rsnd_dai_stream *io) |
| 204 | { |
| 205 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 206 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 207 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 208 | u32 adinr = runtime->channels; |
| 209 | u32 fsrate = 0; |
| 210 | |
| 211 | if (convert_rate) |
| 212 | fsrate = 0x0400000 / convert_rate * runtime->rate; |
| 213 | |
| 214 | /* set/clear soft reset */ |
| 215 | rsnd_mod_write(mod, SRC_SWRSR, 0); |
| 216 | rsnd_mod_write(mod, SRC_SWRSR, 1); |
| 217 | |
| 218 | /* |
| 219 | * Initialize the operation of the SRC internal circuits |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 220 | * see rsnd_src_start() |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 221 | */ |
| 222 | rsnd_mod_write(mod, SRC_SRCIR, 1); |
| 223 | |
| 224 | /* Set channel number and output bit length */ |
| 225 | switch (runtime->sample_bits) { |
| 226 | case 16: |
| 227 | adinr |= OTBL_16; |
| 228 | break; |
| 229 | case 32: |
| 230 | adinr |= OTBL_24; |
| 231 | break; |
| 232 | default: |
| 233 | return -EIO; |
| 234 | } |
| 235 | rsnd_mod_write(mod, SRC_ADINR, adinr); |
| 236 | |
| 237 | /* Enable the initial value of IFS */ |
| 238 | if (fsrate) { |
| 239 | rsnd_mod_write(mod, SRC_IFSCR, 1); |
| 240 | |
| 241 | /* Set initial value of IFS */ |
| 242 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); |
| 243 | } |
| 244 | |
| 245 | /* use DMA transfer */ |
| 246 | rsnd_mod_write(mod, SRC_BUSIF_MODE, 1); |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 251 | static int rsnd_src_init(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 252 | struct rsnd_dai *rdai, |
| 253 | struct rsnd_dai_stream *io) |
| 254 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 255 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 256 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 257 | clk_enable(src->clk); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 258 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 262 | static int rsnd_src_quit(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 263 | struct rsnd_dai *rdai, |
| 264 | struct rsnd_dai_stream *io) |
| 265 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 266 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 267 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 268 | clk_disable(src->clk); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 273 | static int rsnd_src_start(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 274 | struct rsnd_dai *rdai, |
| 275 | struct rsnd_dai_stream *io) |
| 276 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 277 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 278 | |
| 279 | /* |
| 280 | * Cancel the initialization and operate the SRC function |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 281 | * see rsnd_src_set_convert_rate() |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 282 | */ |
| 283 | rsnd_mod_write(mod, SRC_SRCIR, 0); |
| 284 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 285 | if (rsnd_src_convert_rate(src)) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 286 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 292 | static int rsnd_src_stop(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 293 | struct rsnd_dai *rdai, |
| 294 | struct rsnd_dai_stream *io) |
| 295 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 296 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 297 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 298 | if (rsnd_src_convert_rate(src)) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 299 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0); |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 304 | static struct rsnd_mod_ops rsnd_src_non_ops = { |
| 305 | .name = "src (non)", |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 306 | }; |
| 307 | |
| 308 | /* |
| 309 | * Gen1 functions |
| 310 | */ |
| 311 | static int rsnd_src_set_route_gen1(struct rsnd_mod *mod, |
| 312 | struct rsnd_dai *rdai, |
| 313 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 314 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 315 | struct src_route_config { |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 316 | u32 mask; |
| 317 | int shift; |
| 318 | } routes[] = { |
| 319 | { 0xF, 0, }, /* 0 */ |
| 320 | { 0xF, 4, }, /* 1 */ |
| 321 | { 0xF, 8, }, /* 2 */ |
| 322 | { 0x7, 12, }, /* 3 */ |
| 323 | { 0x7, 16, }, /* 4 */ |
| 324 | { 0x7, 20, }, /* 5 */ |
| 325 | { 0x7, 24, }, /* 6 */ |
| 326 | { 0x3, 28, }, /* 7 */ |
| 327 | { 0x3, 30, }, /* 8 */ |
| 328 | }; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 329 | u32 mask; |
| 330 | u32 val; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 331 | int id; |
| 332 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 333 | id = rsnd_mod_id(mod); |
Dan Carpenter | b5f3d7a | 2013-11-08 12:46:10 +0300 | [diff] [blame] | 334 | if (id < 0 || id >= ARRAY_SIZE(routes)) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 335 | return -EIO; |
| 336 | |
| 337 | /* |
| 338 | * SRC_ROUTE_SELECT |
| 339 | */ |
| 340 | val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2; |
| 341 | val = val << routes[id].shift; |
| 342 | mask = routes[id].mask << routes[id].shift; |
| 343 | |
| 344 | rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val); |
| 345 | |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 346 | return 0; |
| 347 | } |
| 348 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 349 | static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 350 | struct rsnd_dai *rdai, |
| 351 | struct rsnd_dai_stream *io) |
| 352 | { |
| 353 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 354 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 355 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 356 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 357 | u32 mask; |
| 358 | u32 val; |
| 359 | int shift; |
| 360 | int id = rsnd_mod_id(mod); |
| 361 | int ret; |
| 362 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 363 | /* |
| 364 | * SRC_TIMING_SELECT |
| 365 | */ |
| 366 | shift = (id % 4) * 8; |
| 367 | mask = 0x1F << shift; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 368 | |
| 369 | /* |
| 370 | * ADG is used as source clock if SRC was used, |
| 371 | * then, SSI WS is used as destination clock. |
| 372 | * SSI WS is used as source clock if SRC is not used |
| 373 | * (when playback, source/destination become reverse when capture) |
| 374 | */ |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 375 | ret = 0; |
| 376 | if (convert_rate) { |
| 377 | /* use ADG */ |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 378 | val = 0; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 379 | ret = rsnd_adg_set_convert_clk_gen1(priv, mod, |
| 380 | runtime->rate, |
| 381 | convert_rate); |
| 382 | } else if (8 == id) { |
| 383 | /* use SSI WS, but SRU8 is special */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 384 | val = id << shift; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 385 | } else { |
| 386 | /* use SSI WS */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 387 | val = (id + 1) << shift; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | if (ret < 0) |
| 391 | return ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 392 | |
| 393 | switch (id / 4) { |
| 394 | case 0: |
| 395 | rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val); |
| 396 | break; |
| 397 | case 1: |
| 398 | rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val); |
| 399 | break; |
| 400 | case 2: |
| 401 | rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val); |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 408 | static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 409 | struct rsnd_dai *rdai, |
| 410 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 411 | { |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 412 | int ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 413 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 414 | ret = rsnd_src_set_convert_rate(mod, rdai, io); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 415 | if (ret < 0) |
| 416 | return ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 417 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 418 | /* Select SRC mode (fixed value) */ |
| 419 | rsnd_mod_write(mod, SRC_SRCCR, 0x00010110); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 420 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 421 | /* Set the restriction value of the FS ratio (98%) */ |
| 422 | rsnd_mod_write(mod, SRC_MNFSR, |
| 423 | rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 424 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 425 | /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 426 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 427 | return 0; |
| 428 | } |
| 429 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 430 | static int rsnd_src_init_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 431 | struct rsnd_dai *rdai, |
| 432 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 433 | { |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 434 | int ret; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 435 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 436 | ret = rsnd_src_init(mod, rdai, io); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 437 | if (ret < 0) |
| 438 | return ret; |
| 439 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 440 | ret = rsnd_src_set_route_gen1(mod, rdai, io); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 441 | if (ret < 0) |
| 442 | return ret; |
| 443 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 444 | ret = rsnd_src_set_convert_rate_gen1(mod, rdai, io); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 445 | if (ret < 0) |
| 446 | return ret; |
| 447 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 448 | ret = rsnd_src_set_convert_timing_gen1(mod, rdai, io); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 449 | if (ret < 0) |
| 450 | return ret; |
| 451 | |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 452 | return 0; |
| 453 | } |
| 454 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 455 | static int rsnd_src_start_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 456 | struct rsnd_dai *rdai, |
| 457 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 458 | { |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 459 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 460 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 461 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id)); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 462 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 463 | return rsnd_src_start(mod, rdai, io); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 466 | static int rsnd_src_stop_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 467 | struct rsnd_dai *rdai, |
| 468 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 469 | { |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 470 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 471 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 472 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 473 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 474 | return rsnd_src_stop(mod, rdai, io); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 475 | } |
| 476 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 477 | static struct rsnd_mod_ops rsnd_src_gen1_ops = { |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 478 | .name = "sru (gen1)", |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 479 | .init = rsnd_src_init_gen1, |
| 480 | .quit = rsnd_src_quit, |
| 481 | .start = rsnd_src_start_gen1, |
| 482 | .stop = rsnd_src_stop_gen1, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 483 | }; |
| 484 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 485 | /* |
| 486 | * Gen2 functions |
| 487 | */ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 488 | static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 489 | struct rsnd_dai *rdai, |
| 490 | struct rsnd_dai_stream *io) |
| 491 | { |
| 492 | int ret; |
| 493 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 494 | ret = rsnd_src_set_convert_rate(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 495 | if (ret < 0) |
| 496 | return ret; |
| 497 | |
| 498 | rsnd_mod_write(mod, SSI_BUSIF_ADINR, rsnd_mod_read(mod, SRC_ADINR)); |
| 499 | rsnd_mod_write(mod, SSI_BUSIF_MODE, rsnd_mod_read(mod, SRC_BUSIF_MODE)); |
| 500 | |
| 501 | rsnd_mod_write(mod, SRC_SRCCR, 0x00011110); |
| 502 | |
| 503 | rsnd_mod_write(mod, SRC_BSDSR, 0x01800000); |
| 504 | rsnd_mod_write(mod, SRC_BSISR, 0x00100060); |
| 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 509 | static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 510 | struct rsnd_dai *rdai, |
| 511 | struct rsnd_dai_stream *io) |
| 512 | { |
| 513 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 514 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 515 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 516 | int ret; |
| 517 | |
| 518 | if (convert_rate) |
| 519 | ret = rsnd_adg_set_convert_clk_gen2(mod, rdai, io, |
| 520 | runtime->rate, |
| 521 | convert_rate); |
| 522 | else |
| 523 | ret = rsnd_adg_set_convert_timing_gen2(mod, rdai, io); |
| 524 | |
| 525 | return ret; |
| 526 | } |
| 527 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 528 | static int rsnd_src_probe_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 529 | struct rsnd_dai *rdai, |
| 530 | struct rsnd_dai_stream *io) |
| 531 | { |
| 532 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 533 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 534 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 535 | struct rsnd_mod *ssi = rsnd_ssi_mod_get(priv, rsnd_mod_id(mod)); |
| 536 | struct device *dev = rsnd_priv_to_dev(priv); |
| 537 | int ret; |
| 538 | int is_play; |
| 539 | |
| 540 | if (info->dai_info) |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 541 | is_play = rsnd_info_is_playback(priv, src); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 542 | else |
| 543 | is_play = rsnd_ssi_is_play(ssi); |
| 544 | |
| 545 | ret = rsnd_dma_init(priv, |
| 546 | rsnd_mod_to_dma(mod), |
| 547 | is_play, |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 548 | src->info->dma_id); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 549 | if (ret < 0) |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 550 | dev_err(dev, "SRC DMA failed\n"); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 551 | |
| 552 | return ret; |
| 553 | } |
| 554 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 555 | static int rsnd_src_remove_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 556 | struct rsnd_dai *rdai, |
| 557 | struct rsnd_dai_stream *io) |
| 558 | { |
| 559 | rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod)); |
| 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 564 | static int rsnd_src_init_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 565 | struct rsnd_dai *rdai, |
| 566 | struct rsnd_dai_stream *io) |
| 567 | { |
| 568 | int ret; |
| 569 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 570 | ret = rsnd_src_init(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 571 | if (ret < 0) |
| 572 | return ret; |
| 573 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 574 | ret = rsnd_src_set_convert_rate_gen2(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 575 | if (ret < 0) |
| 576 | return ret; |
| 577 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 578 | ret = rsnd_src_set_convert_timing_gen2(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 579 | if (ret < 0) |
| 580 | return ret; |
| 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 585 | static int rsnd_src_start_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 586 | struct rsnd_dai *rdai, |
| 587 | struct rsnd_dai_stream *io) |
| 588 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 589 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 590 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 591 | rsnd_dma_start(rsnd_mod_to_dma(&src->mod)); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 592 | |
| 593 | rsnd_mod_write(mod, SSI_CTRL, 0x1); |
| 594 | rsnd_mod_write(mod, SRC_CTRL, 0x11); |
| 595 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 596 | return rsnd_src_start(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 599 | static int rsnd_src_stop_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 600 | struct rsnd_dai *rdai, |
| 601 | struct rsnd_dai_stream *io) |
| 602 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 603 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 604 | |
| 605 | rsnd_mod_write(mod, SSI_CTRL, 0); |
| 606 | rsnd_mod_write(mod, SRC_CTRL, 0); |
| 607 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 608 | rsnd_dma_stop(rsnd_mod_to_dma(&src->mod)); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 609 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 610 | return rsnd_src_stop(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 611 | } |
| 612 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 613 | static struct rsnd_mod_ops rsnd_src_gen2_ops = { |
| 614 | .name = "src (gen2)", |
| 615 | .probe = rsnd_src_probe_gen2, |
| 616 | .remove = rsnd_src_remove_gen2, |
| 617 | .init = rsnd_src_init_gen2, |
| 618 | .quit = rsnd_src_quit, |
| 619 | .start = rsnd_src_start_gen2, |
| 620 | .stop = rsnd_src_stop_gen2, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 621 | }; |
| 622 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 623 | struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 624 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 625 | if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) |
Takashi Iwai | 8b14719 | 2013-11-05 18:40:05 +0100 | [diff] [blame] | 626 | id = 0; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 627 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 628 | return &((struct rsnd_src *)(priv->src) + id)->mod; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 631 | int rsnd_src_probe(struct platform_device *pdev, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 632 | struct rsnd_priv *priv) |
| 633 | { |
Kuninori Morimoto | 5da39cf | 2014-02-24 22:15:00 -0800 | [diff] [blame] | 634 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 635 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 636 | struct rsnd_src *src; |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 637 | struct rsnd_mod_ops *ops; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 638 | struct clk *clk; |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 639 | char name[RSND_SRC_NAME_SIZE]; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 640 | int i, nr; |
| 641 | |
| 642 | /* |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 643 | * init SRC |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 644 | */ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 645 | nr = info->src_info_nr; |
Kuninori Morimoto | 389933d | 2014-03-03 20:50:00 -0800 | [diff] [blame] | 646 | if (!nr) |
| 647 | return 0; |
| 648 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 649 | src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); |
| 650 | if (!src) { |
| 651 | dev_err(dev, "SRC allocate failed\n"); |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 652 | return -ENOMEM; |
| 653 | } |
| 654 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 655 | priv->src_nr = nr; |
| 656 | priv->src = src; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 657 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 658 | for_each_rsnd_src(src, priv, i) { |
| 659 | snprintf(name, RSND_SRC_NAME_SIZE, "src.%d", i); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 660 | |
| 661 | clk = devm_clk_get(dev, name); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 662 | if (IS_ERR(clk)) { |
| 663 | snprintf(name, RSND_SRC_NAME_SIZE, "scu.%d", i); |
| 664 | clk = devm_clk_get(dev, name); |
| 665 | } |
| 666 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 667 | if (IS_ERR(clk)) |
| 668 | return PTR_ERR(clk); |
| 669 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 670 | src->info = &info->src_info[i]; |
| 671 | src->clk = clk; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 672 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 673 | ops = &rsnd_src_non_ops; |
| 674 | if (rsnd_src_hpbif_is_enable(src)) { |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 675 | if (rsnd_is_gen1(priv)) |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 676 | ops = &rsnd_src_gen1_ops; |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 677 | if (rsnd_is_gen2(priv)) |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 678 | ops = &rsnd_src_gen2_ops; |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 679 | } |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 680 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 681 | rsnd_mod_init(priv, &src->mod, ops, RSND_MOD_SRC, i); |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 682 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame^] | 683 | dev_dbg(dev, "SRC%d probed\n", i); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 684 | } |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 685 | |
| 686 | return 0; |
| 687 | } |