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