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