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