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