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 | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 15 | /* SRCx_STATUS */ |
| 16 | #define OUF_SRCO ((1 << 12) | (1 << 13)) |
| 17 | #define OUF_SRCI ((1 << 9) | (1 << 8)) |
| 18 | |
| 19 | /* SCU_SYSTEM_STATUS0/1 */ |
| 20 | #define OUF_SRC(id) ((1 << (id + 16)) | (1 << id)) |
| 21 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 22 | struct rsnd_src { |
| 23 | struct rsnd_src_platform_info *info; /* rcar_snd.h */ |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 24 | struct rsnd_mod mod; |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 25 | struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ |
| 26 | struct rsnd_kctrl_cfg_s sync; /* sync convert */ |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 27 | u32 convert_rate; /* sampling rate convert */ |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 28 | int err; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 31 | #define RSND_SRC_NAME_SIZE 16 |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 32 | |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 33 | #define rsnd_enable_sync_convert(src) ((src)->sen.val) |
Kuninori Morimoto | 82e76ed | 2015-02-20 10:30:22 +0000 | [diff] [blame] | 34 | #define rsnd_src_of_node(priv) \ |
| 35 | of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src") |
| 36 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 37 | #define rsnd_mod_to_src(_mod) \ |
| 38 | container_of((_mod), struct rsnd_src, mod) |
Kuninori Morimoto | 39cf3c4 | 2014-01-23 18:40:47 -0800 | [diff] [blame] | 39 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 40 | #define for_each_rsnd_src(pos, priv, i) \ |
Kuninori Morimoto | 39cf3c4 | 2014-01-23 18:40:47 -0800 | [diff] [blame] | 41 | for ((i) = 0; \ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 42 | ((i) < rsnd_src_nr(priv)) && \ |
| 43 | ((pos) = (struct rsnd_src *)(priv)->src + i); \ |
Kuninori Morimoto | 39cf3c4 | 2014-01-23 18:40:47 -0800 | [diff] [blame] | 44 | i++) |
| 45 | |
| 46 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 47 | /* |
| 48 | * image of SRC (Sampling Rate Converter) |
| 49 | * |
| 50 | * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+ |
| 51 | * 48kHz <-> | SRC | <------> | SSI | <-----> | codec | |
| 52 | * 44.1kHz <-> +-----+ +-----+ +-------+ |
| 53 | * ... |
| 54 | * |
| 55 | */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 56 | |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 57 | /* |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 58 | * src.c is caring... |
Kuninori Morimoto | c926b74 | 2014-01-23 18:40:41 -0800 | [diff] [blame] | 59 | * |
| 60 | * Gen1 |
| 61 | * |
| 62 | * [mem] -> [SRU] -> [SSI] |
| 63 | * |--------| |
| 64 | * |
| 65 | * Gen2 |
| 66 | * |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 67 | * [mem] -> [SRC] -> [SSIU] -> [SSI] |
Kuninori Morimoto | c926b74 | 2014-01-23 18:40:41 -0800 | [diff] [blame] | 68 | * |-----------------| |
| 69 | */ |
| 70 | |
| 71 | /* |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 72 | * How to use SRC bypass mode for debugging |
| 73 | * |
| 74 | * SRC has bypass mode, and it is useful for debugging. |
| 75 | * In Gen2 case, |
| 76 | * SRCm_MODE controls whether SRC is used or not |
| 77 | * SSI_MODE0 controls whether SSIU which receives SRC data |
| 78 | * is used or not. |
| 79 | * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC, |
| 80 | * but SRC bypass mode needs SSI_MODE0 only. |
| 81 | * |
| 82 | * This driver request |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 83 | * struct rsnd_src_platform_info { |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 84 | * u32 convert_rate; |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 85 | * int dma_id; |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 86 | * } |
| 87 | * |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 88 | * rsnd_src_convert_rate() indicates |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 89 | * above convert_rate, and it controls |
| 90 | * whether SRC is used or not. |
| 91 | * |
| 92 | * ex) doesn't use SRC |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 93 | * static struct rsnd_dai_platform_info rsnd_dai = { |
| 94 | * .playback = { .ssi = &rsnd_ssi[0], }, |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 95 | * }; |
| 96 | * |
| 97 | * ex) uses SRC |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 98 | * static struct rsnd_src_platform_info rsnd_src[] = { |
| 99 | * RSND_SCU(48000, 0), |
| 100 | * ... |
| 101 | * }; |
| 102 | * static struct rsnd_dai_platform_info rsnd_dai = { |
| 103 | * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] }, |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 104 | * }; |
| 105 | * |
| 106 | * ex) uses SRC bypass mode |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 107 | * static struct rsnd_src_platform_info rsnd_src[] = { |
| 108 | * RSND_SCU(0, 0), |
| 109 | * ... |
| 110 | * }; |
| 111 | * static struct rsnd_dai_platform_info rsnd_dai = { |
| 112 | * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] }, |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 113 | * }; |
| 114 | * |
| 115 | */ |
| 116 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 117 | /* |
| 118 | * Gen1/Gen2 common functions |
| 119 | */ |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 120 | static struct dma_chan *rsnd_src_dma_req(struct rsnd_mod *mod) |
| 121 | { |
| 122 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 123 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
| 124 | int is_play = rsnd_io_is_play(io); |
| 125 | |
| 126 | return rsnd_dma_request_channel(rsnd_src_of_node(priv), |
| 127 | mod, |
| 128 | is_play ? "rx" : "tx"); |
| 129 | } |
| 130 | |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 131 | int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 132 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 133 | int use_busif) |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 134 | { |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 135 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
Kuninori Morimoto | 1cc7195 | 2014-07-30 23:52:26 -0700 | [diff] [blame] | 136 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 137 | int ssi_id = rsnd_mod_id(ssi_mod); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 138 | |
| 139 | /* |
| 140 | * SSI_MODE0 |
| 141 | */ |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 142 | rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id), |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 143 | !use_busif << ssi_id); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * SSI_MODE1 |
| 147 | */ |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 148 | if (rsnd_ssi_is_pin_sharing(ssi_mod)) { |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 149 | int shift = -1; |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 150 | switch (ssi_id) { |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 151 | case 1: |
| 152 | shift = 0; |
| 153 | break; |
| 154 | case 2: |
| 155 | shift = 2; |
| 156 | break; |
| 157 | case 4: |
| 158 | shift = 16; |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | if (shift >= 0) |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 163 | rsnd_mod_bset(ssi_mod, SSI_MODE1, |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 164 | 0x3 << shift, |
Kuninori Morimoto | 3ed6448 | 2015-01-15 08:04:51 +0000 | [diff] [blame] | 165 | rsnd_rdai_is_clk_master(rdai) ? |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 166 | 0x2 << shift : 0x1 << shift); |
| 167 | } |
| 168 | |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 169 | /* |
| 170 | * DMA settings for SSIU |
| 171 | */ |
| 172 | if (use_busif) { |
Kuninori Morimoto | 1cc7195 | 2014-07-30 23:52:26 -0700 | [diff] [blame] | 173 | u32 val = 0x76543210; |
| 174 | u32 mask = ~0; |
| 175 | |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 176 | rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR, |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 177 | rsnd_get_adinr(ssi_mod, io)); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 178 | rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1); |
| 179 | rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1); |
Kuninori Morimoto | 1cc7195 | 2014-07-30 23:52:26 -0700 | [diff] [blame] | 180 | |
| 181 | mask <<= runtime->channels * 4; |
| 182 | val = val & mask; |
| 183 | |
| 184 | switch (runtime->sample_bits) { |
| 185 | case 16: |
| 186 | val |= 0x67452301 & ~mask; |
| 187 | break; |
| 188 | case 32: |
| 189 | val |= 0x76543210 & ~mask; |
| 190 | break; |
| 191 | } |
| 192 | rsnd_mod_write(ssi_mod, BUSIF_DALIGN, val); |
| 193 | |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 199 | int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod, |
| 200 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 201 | { |
| 202 | /* |
| 203 | * DMA settings for SSIU |
| 204 | */ |
Kuninori Morimoto | 660cdce | 2014-11-27 08:03:39 +0000 | [diff] [blame] | 205 | rsnd_mod_write(ssi_mod, SSI_CTRL, 0); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 206 | |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 210 | int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod) |
Kuninori Morimoto | b8cc41e | 2014-03-03 20:50:08 -0800 | [diff] [blame] | 211 | { |
| 212 | struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); |
| 213 | |
Kuninori Morimoto | c17dba8 | 2014-11-27 08:05:09 +0000 | [diff] [blame] | 214 | if (rsnd_is_gen1(priv)) |
| 215 | return 0; |
| 216 | |
| 217 | /* enable SSI interrupt if Gen2 */ |
| 218 | if (rsnd_ssi_is_dma_mode(ssi_mod)) |
| 219 | rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0e000000); |
| 220 | else |
Kuninori Morimoto | b8cc41e | 2014-03-03 20:50:08 -0800 | [diff] [blame] | 221 | rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000); |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 226 | int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod) |
Kuninori Morimoto | c17dba8 | 2014-11-27 08:05:09 +0000 | [diff] [blame] | 227 | { |
| 228 | struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); |
| 229 | |
| 230 | if (rsnd_is_gen1(priv)) |
| 231 | return 0; |
| 232 | |
| 233 | /* disable SSI interrupt if Gen2 */ |
| 234 | rsnd_mod_write(ssi_mod, INT_ENABLE, 0x00000000); |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 239 | static u32 rsnd_src_convert_rate(struct rsnd_src *src) |
| 240 | { |
| 241 | struct rsnd_mod *mod = &src->mod; |
| 242 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
| 243 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 244 | u32 convert_rate; |
| 245 | |
| 246 | if (!runtime) |
| 247 | return 0; |
| 248 | |
| 249 | if (!rsnd_enable_sync_convert(src)) |
| 250 | return src->convert_rate; |
| 251 | |
| 252 | convert_rate = src->sync.val; |
| 253 | |
| 254 | if (!convert_rate) |
| 255 | convert_rate = src->convert_rate; |
| 256 | |
| 257 | if (!convert_rate) |
| 258 | convert_rate = runtime->rate; |
| 259 | |
| 260 | return convert_rate; |
| 261 | } |
| 262 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 263 | unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 264 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 265 | struct snd_pcm_runtime *runtime) |
| 266 | { |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 267 | struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 268 | struct rsnd_src *src; |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 269 | unsigned int rate = 0; |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 270 | |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 271 | if (src_mod) { |
| 272 | src = rsnd_mod_to_src(src_mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 273 | |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 274 | /* |
| 275 | * return convert rate if SRC is used, |
| 276 | * otherwise, return runtime->rate as usual |
| 277 | */ |
| 278 | rate = rsnd_src_convert_rate(src); |
| 279 | } |
| 280 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 281 | if (!rate) |
| 282 | rate = runtime->rate; |
| 283 | |
| 284 | return rate; |
| 285 | } |
| 286 | |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 287 | static int rsnd_src_set_convert_rate(struct rsnd_mod *mod, |
| 288 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 289 | { |
| 290 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 291 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 292 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 293 | u32 fsrate = 0; |
| 294 | |
| 295 | if (convert_rate) |
| 296 | fsrate = 0x0400000 / convert_rate * runtime->rate; |
| 297 | |
| 298 | /* set/clear soft reset */ |
| 299 | rsnd_mod_write(mod, SRC_SWRSR, 0); |
| 300 | rsnd_mod_write(mod, SRC_SWRSR, 1); |
| 301 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 302 | /* Set channel number and output bit length */ |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 303 | rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod, io)); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 304 | |
| 305 | /* Enable the initial value of IFS */ |
| 306 | if (fsrate) { |
| 307 | rsnd_mod_write(mod, SRC_IFSCR, 1); |
| 308 | |
| 309 | /* Set initial value of IFS */ |
| 310 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); |
| 311 | } |
| 312 | |
| 313 | /* use DMA transfer */ |
| 314 | rsnd_mod_write(mod, SRC_BUSIF_MODE, 1); |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 319 | static int rsnd_src_hw_params(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 320 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 321 | struct snd_pcm_substream *substream, |
| 322 | struct snd_pcm_hw_params *fe_params) |
| 323 | { |
| 324 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 325 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 326 | |
| 327 | /* default value (mainly for non-DT) */ |
| 328 | src->convert_rate = src->info->convert_rate; |
| 329 | |
| 330 | /* |
| 331 | * SRC assumes that it is used under DPCM if user want to use |
| 332 | * sampling rate convert. Then, SRC should be FE. |
| 333 | * And then, this function will be called *after* BE settings. |
| 334 | * this means, each BE already has fixuped hw_params. |
| 335 | * see |
| 336 | * dpcm_fe_dai_hw_params() |
| 337 | * dpcm_be_dai_hw_params() |
| 338 | */ |
| 339 | if (fe->dai_link->dynamic) { |
| 340 | int stream = substream->stream; |
| 341 | struct snd_soc_dpcm *dpcm; |
| 342 | struct snd_pcm_hw_params *be_params; |
| 343 | |
| 344 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { |
| 345 | be_params = &dpcm->hw_params; |
| 346 | |
| 347 | if (params_rate(fe_params) != params_rate(be_params)) |
| 348 | src->convert_rate = params_rate(be_params); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | static int rsnd_src_init(struct rsnd_mod *mod, |
| 356 | struct rsnd_priv *priv) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 357 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 358 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 359 | |
Kuninori Morimoto | 8564295 | 2015-01-15 08:03:22 +0000 | [diff] [blame] | 360 | rsnd_mod_hw_start(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 361 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 362 | src->err = 0; |
| 363 | |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 364 | /* reset sync convert_rate */ |
| 365 | src->sync.val = 0; |
| 366 | |
Kuninori Morimoto | 603cefa | 2014-11-27 08:06:43 +0000 | [diff] [blame] | 367 | /* |
| 368 | * Initialize the operation of the SRC internal circuits |
| 369 | * see rsnd_src_start() |
| 370 | */ |
| 371 | rsnd_mod_write(mod, SRC_SRCIR, 1); |
| 372 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 376 | static int rsnd_src_quit(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 377 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 378 | struct rsnd_priv *priv) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 379 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 380 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 381 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 382 | |
Kuninori Morimoto | 8564295 | 2015-01-15 08:03:22 +0000 | [diff] [blame] | 383 | rsnd_mod_hw_stop(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 384 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 385 | if (src->err) |
Kuninori Morimoto | 337b0b4 | 2015-01-15 08:08:57 +0000 | [diff] [blame] | 386 | dev_warn(dev, "%s[%d] under/over flow err = %d\n", |
| 387 | rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 388 | |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 389 | src->convert_rate = 0; |
| 390 | |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 391 | /* reset sync convert_rate */ |
| 392 | src->sync.val = 0; |
| 393 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 394 | return 0; |
| 395 | } |
| 396 | |
Kuninori Morimoto | f0ef0cb | 2014-11-27 08:07:28 +0000 | [diff] [blame] | 397 | static int rsnd_src_start(struct rsnd_mod *mod) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 398 | { |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 399 | /* |
| 400 | * Cancel the initialization and operate the SRC function |
Kuninori Morimoto | 603cefa | 2014-11-27 08:06:43 +0000 | [diff] [blame] | 401 | * see rsnd_src_init() |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 402 | */ |
| 403 | rsnd_mod_write(mod, SRC_SRCIR, 0); |
| 404 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 405 | return 0; |
| 406 | } |
| 407 | |
Kuninori Morimoto | f0ef0cb | 2014-11-27 08:07:28 +0000 | [diff] [blame] | 408 | static int rsnd_src_stop(struct rsnd_mod *mod) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 409 | { |
Kuninori Morimoto | 933cc8c | 2014-11-27 08:07:07 +0000 | [diff] [blame] | 410 | /* nothing to do */ |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 411 | return 0; |
| 412 | } |
| 413 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 414 | /* |
| 415 | * Gen1 functions |
| 416 | */ |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 417 | static int rsnd_src_set_route_gen1(struct rsnd_mod *mod) |
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 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 420 | struct src_route_config { |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 421 | u32 mask; |
| 422 | int shift; |
| 423 | } routes[] = { |
| 424 | { 0xF, 0, }, /* 0 */ |
| 425 | { 0xF, 4, }, /* 1 */ |
| 426 | { 0xF, 8, }, /* 2 */ |
| 427 | { 0x7, 12, }, /* 3 */ |
| 428 | { 0x7, 16, }, /* 4 */ |
| 429 | { 0x7, 20, }, /* 5 */ |
| 430 | { 0x7, 24, }, /* 6 */ |
| 431 | { 0x3, 28, }, /* 7 */ |
| 432 | { 0x3, 30, }, /* 8 */ |
| 433 | }; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 434 | u32 mask; |
| 435 | u32 val; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 436 | int id; |
| 437 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 438 | id = rsnd_mod_id(mod); |
Dan Carpenter | b5f3d7a | 2013-11-08 12:46:10 +0300 | [diff] [blame] | 439 | if (id < 0 || id >= ARRAY_SIZE(routes)) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 440 | return -EIO; |
| 441 | |
| 442 | /* |
| 443 | * SRC_ROUTE_SELECT |
| 444 | */ |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 445 | val = rsnd_io_is_play(io) ? 0x1 : 0x2; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 446 | val = val << routes[id].shift; |
| 447 | mask = routes[id].mask << routes[id].shift; |
| 448 | |
| 449 | rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val); |
| 450 | |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 451 | return 0; |
| 452 | } |
| 453 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 454 | static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod) |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 455 | { |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame] | 456 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 457 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 458 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 459 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 460 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 461 | u32 mask; |
| 462 | u32 val; |
| 463 | int shift; |
| 464 | int id = rsnd_mod_id(mod); |
| 465 | int ret; |
| 466 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 467 | /* |
| 468 | * SRC_TIMING_SELECT |
| 469 | */ |
| 470 | shift = (id % 4) * 8; |
| 471 | mask = 0x1F << shift; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 472 | |
| 473 | /* |
| 474 | * ADG is used as source clock if SRC was used, |
| 475 | * then, SSI WS is used as destination clock. |
| 476 | * SSI WS is used as source clock if SRC is not used |
| 477 | * (when playback, source/destination become reverse when capture) |
| 478 | */ |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 479 | ret = 0; |
| 480 | if (convert_rate) { |
| 481 | /* use ADG */ |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 482 | val = 0; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 483 | ret = rsnd_adg_set_convert_clk_gen1(priv, mod, |
| 484 | runtime->rate, |
| 485 | convert_rate); |
| 486 | } else if (8 == id) { |
| 487 | /* use SSI WS, but SRU8 is special */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 488 | val = id << shift; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 489 | } else { |
| 490 | /* use SSI WS */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 491 | val = (id + 1) << shift; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | if (ret < 0) |
| 495 | return ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 496 | |
| 497 | switch (id / 4) { |
| 498 | case 0: |
| 499 | rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val); |
| 500 | break; |
| 501 | case 1: |
| 502 | rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val); |
| 503 | break; |
| 504 | case 2: |
| 505 | rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val); |
| 506 | break; |
| 507 | } |
| 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 512 | static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod, |
| 513 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 514 | { |
Kuninori Morimoto | 933cc8c | 2014-11-27 08:07:07 +0000 | [diff] [blame] | 515 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 516 | int ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 517 | |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 518 | ret = rsnd_src_set_convert_rate(mod, io); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 519 | if (ret < 0) |
| 520 | return ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 521 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 522 | /* Select SRC mode (fixed value) */ |
| 523 | rsnd_mod_write(mod, SRC_SRCCR, 0x00010110); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 524 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 525 | /* Set the restriction value of the FS ratio (98%) */ |
| 526 | rsnd_mod_write(mod, SRC_MNFSR, |
| 527 | rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 528 | |
Kuninori Morimoto | 933cc8c | 2014-11-27 08:07:07 +0000 | [diff] [blame] | 529 | /* Gen1/Gen2 are not compatible */ |
| 530 | if (rsnd_src_convert_rate(src)) |
| 531 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); |
| 532 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 533 | /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 534 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 535 | return 0; |
| 536 | } |
| 537 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 538 | static int rsnd_src_init_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 539 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 540 | struct rsnd_priv *priv) |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 541 | { |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 542 | int ret; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 543 | |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 544 | ret = rsnd_src_init(mod, priv); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 545 | if (ret < 0) |
| 546 | return ret; |
| 547 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 548 | ret = rsnd_src_set_route_gen1(mod); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 549 | if (ret < 0) |
| 550 | return ret; |
| 551 | |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 552 | ret = rsnd_src_set_convert_rate_gen1(mod, io); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 553 | if (ret < 0) |
| 554 | return ret; |
| 555 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 556 | ret = rsnd_src_set_convert_timing_gen1(mod); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 557 | if (ret < 0) |
| 558 | return ret; |
| 559 | |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 560 | return 0; |
| 561 | } |
| 562 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 563 | static int rsnd_src_start_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 564 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 565 | struct rsnd_priv *priv) |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 566 | { |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 567 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 568 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 569 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id)); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 570 | |
Kuninori Morimoto | f0ef0cb | 2014-11-27 08:07:28 +0000 | [diff] [blame] | 571 | return rsnd_src_start(mod); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 572 | } |
| 573 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 574 | static int rsnd_src_stop_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 575 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 576 | struct rsnd_priv *priv) |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 577 | { |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 578 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 579 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 580 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 581 | |
Kuninori Morimoto | f0ef0cb | 2014-11-27 08:07:28 +0000 | [diff] [blame] | 582 | return rsnd_src_stop(mod); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 583 | } |
| 584 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 585 | static struct rsnd_mod_ops rsnd_src_gen1_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 586 | .name = SRC_NAME, |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 587 | .dma_req = rsnd_src_dma_req, |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 588 | .init = rsnd_src_init_gen1, |
| 589 | .quit = rsnd_src_quit, |
| 590 | .start = rsnd_src_start_gen1, |
| 591 | .stop = rsnd_src_stop_gen1, |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 592 | .hw_params = rsnd_src_hw_params, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 593 | }; |
| 594 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 595 | /* |
| 596 | * Gen2 functions |
| 597 | */ |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 598 | #define rsnd_src_irq_enable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 1) |
| 599 | #define rsnd_src_irq_disable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 0) |
| 600 | static void rsnd_src_irq_ctrol_gen2(struct rsnd_mod *mod, int enable) |
| 601 | { |
| 602 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 603 | u32 sys_int_val, int_val, sys_int_mask; |
| 604 | int irq = src->info->irq; |
| 605 | int id = rsnd_mod_id(mod); |
| 606 | |
| 607 | sys_int_val = |
| 608 | sys_int_mask = OUF_SRC(id); |
| 609 | int_val = 0x3300; |
| 610 | |
| 611 | /* |
| 612 | * IRQ is not supported on non-DT |
| 613 | * see |
| 614 | * rsnd_src_probe_gen2() |
| 615 | */ |
| 616 | if ((irq <= 0) || !enable) { |
| 617 | sys_int_val = 0; |
| 618 | int_val = 0; |
| 619 | } |
| 620 | |
| 621 | rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val); |
| 622 | rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val); |
| 623 | rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val); |
| 624 | } |
| 625 | |
| 626 | static void rsnd_src_error_clear_gen2(struct rsnd_mod *mod) |
| 627 | { |
| 628 | u32 val = OUF_SRC(rsnd_mod_id(mod)); |
| 629 | |
| 630 | rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val); |
| 631 | rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val); |
| 632 | } |
| 633 | |
| 634 | static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod) |
| 635 | { |
| 636 | u32 val = OUF_SRC(rsnd_mod_id(mod)); |
| 637 | bool ret = false; |
| 638 | |
| 639 | if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val) || |
| 640 | (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val)) { |
| 641 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 642 | |
| 643 | src->err++; |
| 644 | ret = true; |
| 645 | } |
| 646 | |
| 647 | /* clear error static */ |
| 648 | rsnd_src_error_clear_gen2(mod); |
| 649 | |
| 650 | return ret; |
| 651 | } |
| 652 | |
| 653 | static int _rsnd_src_start_gen2(struct rsnd_mod *mod) |
| 654 | { |
| 655 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
| 656 | u32 val = rsnd_io_to_mod_dvc(io) ? 0x01 : 0x11; |
| 657 | |
| 658 | rsnd_mod_write(mod, SRC_CTRL, val); |
| 659 | |
| 660 | rsnd_src_error_clear_gen2(mod); |
| 661 | |
| 662 | rsnd_src_start(mod); |
| 663 | |
| 664 | rsnd_src_irq_enable_gen2(mod); |
| 665 | |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | static int _rsnd_src_stop_gen2(struct rsnd_mod *mod) |
| 670 | { |
| 671 | rsnd_src_irq_disable_gen2(mod); |
| 672 | |
| 673 | rsnd_mod_write(mod, SRC_CTRL, 0); |
| 674 | |
| 675 | rsnd_src_error_record_gen2(mod); |
| 676 | |
| 677 | return rsnd_src_stop(mod); |
| 678 | } |
| 679 | |
| 680 | static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data) |
| 681 | { |
| 682 | struct rsnd_mod *mod = data; |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 683 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 684 | |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 685 | spin_lock(&priv->lock); |
| 686 | |
| 687 | /* ignore all cases if not working */ |
| 688 | if (!rsnd_mod_is_working(mod)) |
| 689 | goto rsnd_src_interrupt_gen2_out; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 690 | |
| 691 | if (rsnd_src_error_record_gen2(mod)) { |
| 692 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 639b231 | 2015-03-19 04:14:04 +0000 | [diff] [blame] | 693 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 694 | struct device *dev = rsnd_priv_to_dev(priv); |
| 695 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 696 | dev_dbg(dev, "%s[%d] restart\n", |
| 697 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
Kuninori Morimoto | 639b231 | 2015-03-19 04:14:04 +0000 | [diff] [blame] | 698 | |
| 699 | _rsnd_src_stop_gen2(mod); |
| 700 | if (src->err < 1024) |
| 701 | _rsnd_src_start_gen2(mod); |
| 702 | else |
| 703 | dev_warn(dev, "no more SRC restart\n"); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 704 | } |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 705 | rsnd_src_interrupt_gen2_out: |
| 706 | spin_unlock(&priv->lock); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 707 | |
| 708 | return IRQ_HANDLED; |
| 709 | } |
| 710 | |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 711 | static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod, |
| 712 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 713 | { |
Kuninori Morimoto | 054cd7f | 2014-07-30 23:52:04 -0700 | [diff] [blame] | 714 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 715 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 054cd7f | 2014-07-30 23:52:04 -0700 | [diff] [blame] | 716 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 717 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | b167a57 | 2014-11-27 08:06:34 +0000 | [diff] [blame] | 718 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 719 | u32 cr, route; |
Kuninori Morimoto | 054cd7f | 2014-07-30 23:52:04 -0700 | [diff] [blame] | 720 | uint ratio; |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 721 | int ret; |
| 722 | |
Kuninori Morimoto | 054cd7f | 2014-07-30 23:52:04 -0700 | [diff] [blame] | 723 | /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ |
Kuninori Morimoto | b167a57 | 2014-11-27 08:06:34 +0000 | [diff] [blame] | 724 | if (!convert_rate) |
Kuninori Morimoto | 054cd7f | 2014-07-30 23:52:04 -0700 | [diff] [blame] | 725 | ratio = 0; |
Kuninori Morimoto | b167a57 | 2014-11-27 08:06:34 +0000 | [diff] [blame] | 726 | else if (convert_rate > runtime->rate) |
| 727 | ratio = 100 * convert_rate / runtime->rate; |
Kuninori Morimoto | 054cd7f | 2014-07-30 23:52:04 -0700 | [diff] [blame] | 728 | else |
Kuninori Morimoto | b167a57 | 2014-11-27 08:06:34 +0000 | [diff] [blame] | 729 | ratio = 100 * runtime->rate / convert_rate; |
Kuninori Morimoto | 054cd7f | 2014-07-30 23:52:04 -0700 | [diff] [blame] | 730 | |
| 731 | if (ratio > 600) { |
| 732 | dev_err(dev, "FSO/FSI ratio error\n"); |
| 733 | return -EINVAL; |
| 734 | } |
| 735 | |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 736 | ret = rsnd_src_set_convert_rate(mod, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 737 | if (ret < 0) |
| 738 | return ret; |
| 739 | |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 740 | cr = 0x00011110; |
| 741 | route = 0x0; |
Kuninori Morimoto | 933cc8c | 2014-11-27 08:07:07 +0000 | [diff] [blame] | 742 | if (convert_rate) { |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 743 | route = 0x1; |
| 744 | |
| 745 | if (rsnd_enable_sync_convert(src)) { |
| 746 | cr |= 0x1; |
| 747 | route |= rsnd_io_is_play(io) ? |
| 748 | (0x1 << 24) : (0x1 << 25); |
| 749 | } |
Kuninori Morimoto | 933cc8c | 2014-11-27 08:07:07 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 752 | rsnd_mod_write(mod, SRC_SRCCR, cr); |
| 753 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, route); |
| 754 | |
Kuninori Morimoto | 054cd7f | 2014-07-30 23:52:04 -0700 | [diff] [blame] | 755 | switch (rsnd_mod_id(mod)) { |
| 756 | case 5: |
| 757 | case 6: |
| 758 | case 7: |
| 759 | case 8: |
| 760 | rsnd_mod_write(mod, SRC_BSDSR, 0x02400000); |
| 761 | break; |
| 762 | default: |
| 763 | rsnd_mod_write(mod, SRC_BSDSR, 0x01800000); |
| 764 | break; |
| 765 | } |
| 766 | |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 767 | rsnd_mod_write(mod, SRC_BSISR, 0x00100060); |
| 768 | |
| 769 | return 0; |
| 770 | } |
| 771 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 772 | static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod) |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 773 | { |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame] | 774 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 775 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 776 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 777 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 778 | int ret; |
| 779 | |
| 780 | if (convert_rate) |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 781 | ret = rsnd_adg_set_convert_clk_gen2(mod, io, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 782 | runtime->rate, |
| 783 | convert_rate); |
| 784 | else |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 785 | ret = rsnd_adg_set_convert_timing_gen2(mod, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 786 | |
| 787 | return ret; |
| 788 | } |
| 789 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 790 | static int rsnd_src_probe_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 791 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 792 | struct rsnd_priv *priv) |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 793 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 794 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 795 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 796 | int irq = src->info->irq; |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 797 | int ret; |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 798 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 799 | if (irq > 0) { |
| 800 | /* |
| 801 | * IRQ is not supported on non-DT |
| 802 | * see |
| 803 | * rsnd_src_irq_enable_gen2() |
| 804 | */ |
| 805 | ret = devm_request_irq(dev, irq, |
| 806 | rsnd_src_interrupt_gen2, |
| 807 | IRQF_SHARED, |
| 808 | dev_name(dev), mod); |
| 809 | if (ret) |
Kuninori Morimoto | b543b52 | 2015-03-26 04:02:32 +0000 | [diff] [blame] | 810 | return ret; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 813 | ret = rsnd_dma_init(priv, |
| 814 | rsnd_mod_to_dma(mod), |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 815 | src->info->dma_id); |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 816 | |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 817 | return ret; |
| 818 | } |
| 819 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 820 | static int rsnd_src_remove_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 821 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 822 | struct rsnd_priv *priv) |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 823 | { |
Kuninori Morimoto | 8a2ff42 | 2015-02-20 10:24:06 +0000 | [diff] [blame] | 824 | rsnd_dma_quit(rsnd_mod_to_dma(mod)); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 829 | static int rsnd_src_init_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 830 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 831 | struct rsnd_priv *priv) |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 832 | { |
| 833 | int ret; |
| 834 | |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 835 | ret = rsnd_src_init(mod, priv); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 836 | if (ret < 0) |
| 837 | return ret; |
| 838 | |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame^] | 839 | ret = rsnd_src_set_convert_rate_gen2(mod, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 840 | if (ret < 0) |
| 841 | return ret; |
| 842 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 843 | ret = rsnd_src_set_convert_timing_gen2(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 844 | if (ret < 0) |
| 845 | return ret; |
| 846 | |
| 847 | return 0; |
| 848 | } |
| 849 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 850 | static int rsnd_src_start_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 851 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 852 | struct rsnd_priv *priv) |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 853 | { |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 854 | rsnd_dma_start(rsnd_mod_to_dma(mod)); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 855 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 856 | return _rsnd_src_start_gen2(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 857 | } |
| 858 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 859 | static int rsnd_src_stop_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 860 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 861 | struct rsnd_priv *priv) |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 862 | { |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 863 | int ret; |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 864 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 865 | ret = _rsnd_src_stop_gen2(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 866 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 867 | rsnd_dma_stop(rsnd_mod_to_dma(mod)); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 868 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 869 | return ret; |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 870 | } |
| 871 | |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 872 | static void rsnd_src_reconvert_update(struct rsnd_mod *mod) |
| 873 | { |
| 874 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
| 875 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 876 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 877 | u32 convert_rate = rsnd_src_convert_rate(src); |
| 878 | u32 fsrate; |
| 879 | |
| 880 | if (!runtime) |
| 881 | return; |
| 882 | |
| 883 | if (!convert_rate) |
| 884 | convert_rate = runtime->rate; |
| 885 | |
| 886 | fsrate = 0x0400000 / convert_rate * runtime->rate; |
| 887 | |
| 888 | /* update IFS */ |
| 889 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); |
| 890 | } |
| 891 | |
| 892 | static int rsnd_src_pcm_new(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 893 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 894 | struct snd_soc_pcm_runtime *rtd) |
| 895 | { |
| 896 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 897 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
| 898 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 899 | int ret; |
| 900 | |
| 901 | /* |
| 902 | * enable SRC sync convert if possible |
| 903 | */ |
| 904 | |
| 905 | /* |
| 906 | * Gen1 is not supported |
| 907 | */ |
| 908 | if (rsnd_is_gen1(priv)) |
| 909 | return 0; |
| 910 | |
| 911 | /* |
| 912 | * SRC sync convert needs clock master |
| 913 | */ |
| 914 | if (!rsnd_rdai_is_clk_master(rdai)) |
| 915 | return 0; |
| 916 | |
| 917 | /* |
| 918 | * We can't use SRC sync convert |
| 919 | * if it has DVC |
| 920 | */ |
| 921 | if (rsnd_io_to_mod_dvc(io)) |
| 922 | return 0; |
| 923 | |
| 924 | /* |
| 925 | * enable sync convert |
| 926 | */ |
| 927 | ret = rsnd_kctrl_new_s(mod, rtd, |
| 928 | rsnd_io_is_play(io) ? |
| 929 | "SRC Out Rate Switch" : |
| 930 | "SRC In Rate Switch", |
| 931 | rsnd_src_reconvert_update, |
| 932 | &src->sen, 1); |
| 933 | if (ret < 0) |
| 934 | return ret; |
| 935 | |
| 936 | ret = rsnd_kctrl_new_s(mod, rtd, |
| 937 | rsnd_io_is_play(io) ? |
| 938 | "SRC Out Rate" : |
| 939 | "SRC In Rate", |
| 940 | rsnd_src_reconvert_update, |
| 941 | &src->sync, 192000); |
| 942 | |
| 943 | return ret; |
| 944 | } |
| 945 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 946 | static struct rsnd_mod_ops rsnd_src_gen2_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 947 | .name = SRC_NAME, |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 948 | .dma_req = rsnd_src_dma_req, |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 949 | .probe = rsnd_src_probe_gen2, |
| 950 | .remove = rsnd_src_remove_gen2, |
| 951 | .init = rsnd_src_init_gen2, |
| 952 | .quit = rsnd_src_quit, |
| 953 | .start = rsnd_src_start_gen2, |
| 954 | .stop = rsnd_src_stop_gen2, |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 955 | .hw_params = rsnd_src_hw_params, |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 956 | .pcm_new = rsnd_src_pcm_new, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 957 | }; |
| 958 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 959 | 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] | 960 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 961 | if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) |
Takashi Iwai | 8b14719 | 2013-11-05 18:40:05 +0100 | [diff] [blame] | 962 | id = 0; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 963 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 964 | return &((struct rsnd_src *)(priv->src) + id)->mod; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 967 | static void rsnd_of_parse_src(struct platform_device *pdev, |
| 968 | const struct rsnd_of_data *of_data, |
| 969 | struct rsnd_priv *priv) |
| 970 | { |
| 971 | struct device_node *src_node; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 972 | struct device_node *np; |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 973 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
| 974 | struct rsnd_src_platform_info *src_info; |
| 975 | struct device *dev = &pdev->dev; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 976 | int nr, i; |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 977 | |
| 978 | if (!of_data) |
| 979 | return; |
| 980 | |
Kuninori Morimoto | 82e76ed | 2015-02-20 10:30:22 +0000 | [diff] [blame] | 981 | src_node = rsnd_src_of_node(priv); |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 982 | if (!src_node) |
| 983 | return; |
| 984 | |
| 985 | nr = of_get_child_count(src_node); |
| 986 | if (!nr) |
Kuninori Morimoto | f451e48 | 2014-05-22 23:24:59 -0700 | [diff] [blame] | 987 | goto rsnd_of_parse_src_end; |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 988 | |
| 989 | src_info = devm_kzalloc(dev, |
| 990 | sizeof(struct rsnd_src_platform_info) * nr, |
| 991 | GFP_KERNEL); |
| 992 | if (!src_info) { |
| 993 | dev_err(dev, "src info allocation error\n"); |
Kuninori Morimoto | f451e48 | 2014-05-22 23:24:59 -0700 | [diff] [blame] | 994 | goto rsnd_of_parse_src_end; |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | info->src_info = src_info; |
| 998 | info->src_info_nr = nr; |
Kuninori Morimoto | f451e48 | 2014-05-22 23:24:59 -0700 | [diff] [blame] | 999 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 1000 | i = 0; |
| 1001 | for_each_child_of_node(src_node, np) { |
| 1002 | src_info[i].irq = irq_of_parse_and_map(np, 0); |
| 1003 | |
| 1004 | i++; |
| 1005 | } |
| 1006 | |
Kuninori Morimoto | f451e48 | 2014-05-22 23:24:59 -0700 | [diff] [blame] | 1007 | rsnd_of_parse_src_end: |
| 1008 | of_node_put(src_node); |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 1011 | int rsnd_src_probe(struct platform_device *pdev, |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 1012 | const struct rsnd_of_data *of_data, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1013 | struct rsnd_priv *priv) |
| 1014 | { |
Kuninori Morimoto | 5da39cf | 2014-02-24 22:15:00 -0800 | [diff] [blame] | 1015 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1016 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 1017 | struct rsnd_src *src; |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 1018 | struct rsnd_mod_ops *ops; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 1019 | struct clk *clk; |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 1020 | char name[RSND_SRC_NAME_SIZE]; |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 1021 | int i, nr, ret; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1022 | |
Kuninori Morimoto | 033e7ed | 2014-05-22 23:25:37 -0700 | [diff] [blame] | 1023 | ops = NULL; |
| 1024 | if (rsnd_is_gen1(priv)) |
| 1025 | ops = &rsnd_src_gen1_ops; |
| 1026 | if (rsnd_is_gen2(priv)) |
| 1027 | ops = &rsnd_src_gen2_ops; |
| 1028 | if (!ops) { |
| 1029 | dev_err(dev, "unknown Generation\n"); |
| 1030 | return -EIO; |
| 1031 | } |
| 1032 | |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 1033 | rsnd_of_parse_src(pdev, of_data, priv); |
| 1034 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1035 | /* |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 1036 | * init SRC |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1037 | */ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 1038 | nr = info->src_info_nr; |
Kuninori Morimoto | 389933d | 2014-03-03 20:50:00 -0800 | [diff] [blame] | 1039 | if (!nr) |
| 1040 | return 0; |
| 1041 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 1042 | src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); |
| 1043 | if (!src) { |
| 1044 | dev_err(dev, "SRC allocate failed\n"); |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1045 | return -ENOMEM; |
| 1046 | } |
| 1047 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 1048 | priv->src_nr = nr; |
| 1049 | priv->src = src; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1050 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 1051 | for_each_rsnd_src(src, priv, i) { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 1052 | snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d", |
| 1053 | SRC_NAME, i); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 1054 | |
| 1055 | clk = devm_clk_get(dev, name); |
| 1056 | if (IS_ERR(clk)) |
| 1057 | return PTR_ERR(clk); |
| 1058 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 1059 | src->info = &info->src_info[i]; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1060 | |
Kuninori Morimoto | 2099bc8 | 2015-06-15 06:24:54 +0000 | [diff] [blame] | 1061 | ret = rsnd_mod_init(priv, &src->mod, ops, clk, RSND_MOD_SRC, i); |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 1062 | if (ret) |
| 1063 | return ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 1064 | } |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 1065 | |
| 1066 | return 0; |
| 1067 | } |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 1068 | |
| 1069 | void rsnd_src_remove(struct platform_device *pdev, |
| 1070 | struct rsnd_priv *priv) |
| 1071 | { |
| 1072 | struct rsnd_src *src; |
| 1073 | int i; |
| 1074 | |
| 1075 | for_each_rsnd_src(src, priv, i) { |
| 1076 | rsnd_mod_quit(&src->mod); |
| 1077 | } |
| 1078 | } |