Kuninori Morimoto | 1e0edd4 | 2018-06-12 05:58:38 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // Renesas R-Car SRC support |
| 4 | // |
| 5 | // Copyright (C) 2013 Renesas Solutions Corp. |
| 6 | // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
Kuninori Morimoto | 2b62786 | 2018-02-13 02:08:53 +0000 | [diff] [blame] | 7 | |
| 8 | /* |
| 9 | * you can enable below define if you don't need |
| 10 | * SSI interrupt status debug message when debugging |
| 11 | * see rsnd_dbg_irq_status() |
| 12 | * |
| 13 | * #define RSND_DEBUG_NO_IRQ_STATUS 1 |
| 14 | */ |
| 15 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 16 | #include "rsnd.h" |
| 17 | |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 18 | #define SRC_NAME "src" |
| 19 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 20 | /* SCU_SYSTEM_STATUS0/1 */ |
| 21 | #define OUF_SRC(id) ((1 << (id + 16)) | (1 << id)) |
| 22 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 23 | struct rsnd_src { |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 24 | struct rsnd_mod mod; |
Kuninori Morimoto | 940e947 | 2015-10-26 08:42:25 +0000 | [diff] [blame] | 25 | struct rsnd_mod *dma; |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 26 | struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ |
| 27 | struct rsnd_kctrl_cfg_s sync; /* sync convert */ |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 28 | u32 convert_rate; /* sampling rate convert */ |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 29 | int irq; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 32 | #define RSND_SRC_NAME_SIZE 16 |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 33 | |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 34 | #define rsnd_src_get(priv, id) ((struct rsnd_src *)(priv->src) + id) |
Kuninori Morimoto | da599fd | 2015-07-15 07:11:21 +0000 | [diff] [blame] | 35 | #define rsnd_src_nr(priv) ((priv)->src_nr) |
Kuninori Morimoto | ab2049f | 2016-03-07 05:07:57 +0000 | [diff] [blame] | 36 | #define rsnd_src_sync_is_enabled(mod) (rsnd_mod_to_src(mod)->sen.val) |
Kuninori Morimoto | 82e76ed | 2015-02-20 10:30:22 +0000 | [diff] [blame] | 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 | 98efeea | 2015-11-30 08:50:32 +0000 | [diff] [blame] | 58 | static void rsnd_src_activation(struct rsnd_mod *mod) |
Kuninori Morimoto | 379febf | 2015-07-15 07:12:18 +0000 | [diff] [blame] | 59 | { |
| 60 | rsnd_mod_write(mod, SRC_SWRSR, 0); |
| 61 | rsnd_mod_write(mod, SRC_SWRSR, 1); |
| 62 | } |
| 63 | |
Kuninori Morimoto | 475a361 | 2015-11-30 08:51:35 +0000 | [diff] [blame] | 64 | static void rsnd_src_halt(struct rsnd_mod *mod) |
| 65 | { |
| 66 | rsnd_mod_write(mod, SRC_SRCIR, 1); |
| 67 | rsnd_mod_write(mod, SRC_SWRSR, 0); |
| 68 | } |
| 69 | |
Kuninori Morimoto | 9b99e9a | 2015-06-15 06:26:25 +0000 | [diff] [blame] | 70 | static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io, |
| 71 | struct rsnd_mod *mod) |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 72 | { |
| 73 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 74 | int is_play = rsnd_io_is_play(io); |
| 75 | |
| 76 | return rsnd_dma_request_channel(rsnd_src_of_node(priv), |
| 77 | mod, |
| 78 | is_play ? "rx" : "tx"); |
| 79 | } |
| 80 | |
Kuninori Morimoto | 88c61cf | 2015-06-15 06:27:13 +0000 | [diff] [blame] | 81 | static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io, |
Kuninori Morimoto | 1a9be9e | 2016-03-07 05:07:29 +0000 | [diff] [blame] | 82 | struct rsnd_mod *mod) |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 83 | { |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 84 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | 1a9be9e | 2016-03-07 05:07:29 +0000 | [diff] [blame] | 85 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 86 | u32 convert_rate; |
| 87 | |
| 88 | if (!runtime) |
| 89 | return 0; |
| 90 | |
Kuninori Morimoto | ab2049f | 2016-03-07 05:07:57 +0000 | [diff] [blame] | 91 | if (!rsnd_src_sync_is_enabled(mod)) |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 92 | return src->convert_rate; |
| 93 | |
| 94 | convert_rate = src->sync.val; |
| 95 | |
| 96 | if (!convert_rate) |
| 97 | convert_rate = src->convert_rate; |
| 98 | |
| 99 | if (!convert_rate) |
| 100 | convert_rate = runtime->rate; |
| 101 | |
| 102 | return convert_rate; |
| 103 | } |
| 104 | |
Kuninori Morimoto | cbf1494 | 2016-03-07 05:08:33 +0000 | [diff] [blame] | 105 | unsigned int rsnd_src_get_rate(struct rsnd_priv *priv, |
| 106 | struct rsnd_dai_stream *io, |
| 107 | int is_in) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 108 | { |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 109 | struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); |
Kuninori Morimoto | cbf1494 | 2016-03-07 05:08:33 +0000 | [diff] [blame] | 110 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 111 | unsigned int rate = 0; |
Kuninori Morimoto | cbf1494 | 2016-03-07 05:08:33 +0000 | [diff] [blame] | 112 | int is_play = rsnd_io_is_play(io); |
| 113 | |
| 114 | /* |
Kuninori Morimoto | cbf1494 | 2016-03-07 05:08:33 +0000 | [diff] [blame] | 115 | * Playback |
| 116 | * runtime_rate -> [SRC] -> convert_rate |
| 117 | * |
| 118 | * Capture |
| 119 | * convert_rate -> [SRC] -> runtime_rate |
| 120 | */ |
| 121 | |
| 122 | if (is_play == is_in) |
| 123 | return runtime->rate; |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 124 | |
Kuninori Morimoto | 1a9be9e | 2016-03-07 05:07:29 +0000 | [diff] [blame] | 125 | /* |
| 126 | * return convert rate if SRC is used, |
| 127 | * otherwise, return runtime->rate as usual |
| 128 | */ |
| 129 | if (src_mod) |
| 130 | rate = rsnd_src_convert_rate(io, src_mod); |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 131 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 132 | if (!rate) |
| 133 | rate = runtime->rate; |
| 134 | |
| 135 | return rate; |
| 136 | } |
| 137 | |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 138 | static int rsnd_src_hw_params(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac19 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 139 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 140 | struct snd_pcm_substream *substream, |
| 141 | struct snd_pcm_hw_params *fe_params) |
| 142 | { |
| 143 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 144 | struct snd_soc_pcm_runtime *fe = substream->private_data; |
| 145 | |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 146 | /* |
| 147 | * SRC assumes that it is used under DPCM if user want to use |
| 148 | * sampling rate convert. Then, SRC should be FE. |
| 149 | * And then, this function will be called *after* BE settings. |
| 150 | * this means, each BE already has fixuped hw_params. |
| 151 | * see |
| 152 | * dpcm_fe_dai_hw_params() |
| 153 | * dpcm_be_dai_hw_params() |
| 154 | */ |
Kuninori Morimoto | fc99d23 | 2017-04-06 07:24:36 +0000 | [diff] [blame] | 155 | src->convert_rate = 0; |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 156 | if (fe->dai_link->dynamic) { |
| 157 | int stream = substream->stream; |
| 158 | struct snd_soc_dpcm *dpcm; |
| 159 | struct snd_pcm_hw_params *be_params; |
| 160 | |
Kuninori Morimoto | 8d6258a | 2018-09-18 01:31:09 +0000 | [diff] [blame] | 161 | for_each_dpcm_be(fe, stream, dpcm) { |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 162 | be_params = &dpcm->hw_params; |
| 163 | |
| 164 | if (params_rate(fe_params) != params_rate(be_params)) |
| 165 | src->convert_rate = params_rate(be_params); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 172 | static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io, |
| 173 | struct rsnd_mod *mod) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 174 | { |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 175 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 176 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 177 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | 90431eb | 2017-05-16 01:51:41 +0000 | [diff] [blame] | 178 | int is_play = rsnd_io_is_play(io); |
Kuninori Morimoto | 67923f7 | 2016-10-27 01:05:21 +0000 | [diff] [blame] | 179 | int use_src = 0; |
Kuninori Morimoto | 0102eed | 2016-03-07 05:09:14 +0000 | [diff] [blame] | 180 | u32 fin, fout; |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 181 | u32 ifscr, fsrate, adinr; |
| 182 | u32 cr, route; |
| 183 | u32 bsdsr, bsisr; |
Kuninori Morimoto | 90431eb | 2017-05-16 01:51:41 +0000 | [diff] [blame] | 184 | u32 i_busif, o_busif, tmp; |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 185 | uint ratio; |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 186 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 187 | if (!runtime) |
| 188 | return; |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 189 | |
Kuninori Morimoto | 0102eed | 2016-03-07 05:09:14 +0000 | [diff] [blame] | 190 | fin = rsnd_src_get_in_rate(priv, io); |
| 191 | fout = rsnd_src_get_out_rate(priv, io); |
| 192 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 193 | /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ |
Kuninori Morimoto | 0102eed | 2016-03-07 05:09:14 +0000 | [diff] [blame] | 194 | if (fin == fout) |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 195 | ratio = 0; |
Kuninori Morimoto | 0102eed | 2016-03-07 05:09:14 +0000 | [diff] [blame] | 196 | else if (fin > fout) |
| 197 | ratio = 100 * fin / fout; |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 198 | else |
Kuninori Morimoto | 0102eed | 2016-03-07 05:09:14 +0000 | [diff] [blame] | 199 | ratio = 100 * fout / fin; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 200 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 201 | if (ratio > 600) { |
| 202 | dev_err(dev, "FSO/FSI ratio error\n"); |
| 203 | return; |
| 204 | } |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 205 | |
Kuninori Morimoto | 67923f7 | 2016-10-27 01:05:21 +0000 | [diff] [blame] | 206 | use_src = (fin != fout) | rsnd_src_sync_is_enabled(mod); |
| 207 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 208 | /* |
Kuninori Morimoto | b65cb7a | 2017-08-21 07:03:01 +0000 | [diff] [blame] | 209 | * SRC_ADINR |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 210 | */ |
Kuninori Morimoto | c45f726 | 2015-11-30 08:49:33 +0000 | [diff] [blame] | 211 | adinr = rsnd_get_adinr_bit(mod, io) | |
Kuninori Morimoto | eed76bb | 2016-02-25 05:54:58 +0000 | [diff] [blame] | 212 | rsnd_runtime_channel_original(io); |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 213 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 214 | /* |
Kuninori Morimoto | b65cb7a | 2017-08-21 07:03:01 +0000 | [diff] [blame] | 215 | * SRC_IFSCR / SRC_IFSVR |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 216 | */ |
| 217 | ifscr = 0; |
| 218 | fsrate = 0; |
Kuninori Morimoto | 67923f7 | 2016-10-27 01:05:21 +0000 | [diff] [blame] | 219 | if (use_src) { |
Hiroyuki Yokoyama | 93ca33c | 2016-07-25 01:52:43 +0000 | [diff] [blame] | 220 | u64 n; |
| 221 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 222 | ifscr = 1; |
Hiroyuki Yokoyama | 93ca33c | 2016-07-25 01:52:43 +0000 | [diff] [blame] | 223 | n = (u64)0x0400000 * fin; |
| 224 | do_div(n, fout); |
| 225 | fsrate = n; |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* |
Kuninori Morimoto | b65cb7a | 2017-08-21 07:03:01 +0000 | [diff] [blame] | 229 | * SRC_SRCCR / SRC_ROUTE_MODE0 |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 230 | */ |
| 231 | cr = 0x00011110; |
| 232 | route = 0x0; |
Kuninori Morimoto | 67923f7 | 2016-10-27 01:05:21 +0000 | [diff] [blame] | 233 | if (use_src) { |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 234 | route = 0x1; |
| 235 | |
Kuninori Morimoto | ab2049f | 2016-03-07 05:07:57 +0000 | [diff] [blame] | 236 | if (rsnd_src_sync_is_enabled(mod)) { |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 237 | cr |= 0x1; |
| 238 | route |= rsnd_io_is_play(io) ? |
| 239 | (0x1 << 24) : (0x1 << 25); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * SRC_BSDSR / SRC_BSISR |
| 245 | */ |
| 246 | switch (rsnd_mod_id(mod)) { |
| 247 | case 5: |
| 248 | case 6: |
| 249 | case 7: |
| 250 | case 8: |
| 251 | bsdsr = 0x02400000; /* 6 - 1/6 */ |
| 252 | bsisr = 0x00100060; /* 6 - 1/6 */ |
| 253 | break; |
| 254 | default: |
| 255 | bsdsr = 0x01800000; /* 6 - 1/6 */ |
| 256 | bsisr = 0x00100060 ;/* 6 - 1/6 */ |
| 257 | break; |
| 258 | } |
| 259 | |
Kuninori Morimoto | 90431eb | 2017-05-16 01:51:41 +0000 | [diff] [blame] | 260 | /* BUSIF_MODE */ |
| 261 | tmp = rsnd_get_busif_shift(io, mod); |
| 262 | i_busif = ( is_play ? tmp : 0) | 1; |
| 263 | o_busif = (!is_play ? tmp : 0) | 1; |
| 264 | |
Kuninori Morimoto | 0fbab95 | 2016-02-18 08:13:45 +0000 | [diff] [blame] | 265 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, route); |
| 266 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 267 | rsnd_mod_write(mod, SRC_SRCIR, 1); /* initialize */ |
| 268 | rsnd_mod_write(mod, SRC_ADINR, adinr); |
| 269 | rsnd_mod_write(mod, SRC_IFSCR, ifscr); |
| 270 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); |
| 271 | rsnd_mod_write(mod, SRC_SRCCR, cr); |
| 272 | rsnd_mod_write(mod, SRC_BSDSR, bsdsr); |
| 273 | rsnd_mod_write(mod, SRC_BSISR, bsisr); |
| 274 | rsnd_mod_write(mod, SRC_SRCIR, 0); /* cancel initialize */ |
| 275 | |
Kuninori Morimoto | 90431eb | 2017-05-16 01:51:41 +0000 | [diff] [blame] | 276 | rsnd_mod_write(mod, SRC_I_BUSIF_MODE, i_busif); |
| 277 | rsnd_mod_write(mod, SRC_O_BUSIF_MODE, o_busif); |
| 278 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 279 | rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io)); |
| 280 | |
Kuninori Morimoto | 0102eed | 2016-03-07 05:09:14 +0000 | [diff] [blame] | 281 | rsnd_adg_set_src_timesel_gen2(mod, io, fin, fout); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Kuninori Morimoto | b5b442a | 2016-01-26 04:56:57 +0000 | [diff] [blame] | 284 | static int rsnd_src_irq(struct rsnd_mod *mod, |
| 285 | struct rsnd_dai_stream *io, |
| 286 | struct rsnd_priv *priv, |
| 287 | int enable) |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 288 | { |
| 289 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 290 | u32 sys_int_val, int_val, sys_int_mask; |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 291 | int irq = src->irq; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 292 | int id = rsnd_mod_id(mod); |
| 293 | |
| 294 | sys_int_val = |
| 295 | sys_int_mask = OUF_SRC(id); |
| 296 | int_val = 0x3300; |
| 297 | |
| 298 | /* |
| 299 | * IRQ is not supported on non-DT |
| 300 | * see |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 301 | * rsnd_src_probe_() |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 302 | */ |
| 303 | if ((irq <= 0) || !enable) { |
| 304 | sys_int_val = 0; |
| 305 | int_val = 0; |
| 306 | } |
| 307 | |
Kuninori Morimoto | 1a1bf58 | 2015-07-15 07:10:22 +0000 | [diff] [blame] | 308 | /* |
| 309 | * WORKAROUND |
| 310 | * |
Kuninori Morimoto | ab2049f | 2016-03-07 05:07:57 +0000 | [diff] [blame] | 311 | * ignore over flow error when rsnd_src_sync_is_enabled() |
Kuninori Morimoto | 1a1bf58 | 2015-07-15 07:10:22 +0000 | [diff] [blame] | 312 | */ |
Kuninori Morimoto | ab2049f | 2016-03-07 05:07:57 +0000 | [diff] [blame] | 313 | if (rsnd_src_sync_is_enabled(mod)) |
Kuninori Morimoto | 1a1bf58 | 2015-07-15 07:10:22 +0000 | [diff] [blame] | 314 | sys_int_val = sys_int_val & 0xffff; |
| 315 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 316 | rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val); |
| 317 | rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val); |
| 318 | rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val); |
Kuninori Morimoto | b5b442a | 2016-01-26 04:56:57 +0000 | [diff] [blame] | 319 | |
| 320 | return 0; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Kuninori Morimoto | 8cc225f | 2015-11-26 11:11:03 +0000 | [diff] [blame] | 323 | static void rsnd_src_status_clear(struct rsnd_mod *mod) |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 324 | { |
| 325 | u32 val = OUF_SRC(rsnd_mod_id(mod)); |
| 326 | |
Kuninori Morimoto | 42b197e | 2016-10-26 04:28:42 +0000 | [diff] [blame] | 327 | rsnd_mod_write(mod, SCU_SYS_STATUS0, val); |
| 328 | rsnd_mod_write(mod, SCU_SYS_STATUS1, val); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 331 | static bool rsnd_src_error_occurred(struct rsnd_mod *mod) |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 332 | { |
Kuninori Morimoto | 2b62786 | 2018-02-13 02:08:53 +0000 | [diff] [blame] | 333 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 334 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 1a1bf58 | 2015-07-15 07:10:22 +0000 | [diff] [blame] | 335 | u32 val0, val1; |
Kuninori Morimoto | 2b62786 | 2018-02-13 02:08:53 +0000 | [diff] [blame] | 336 | u32 status0, status1; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 337 | bool ret = false; |
| 338 | |
Kuninori Morimoto | 1a1bf58 | 2015-07-15 07:10:22 +0000 | [diff] [blame] | 339 | val0 = val1 = OUF_SRC(rsnd_mod_id(mod)); |
| 340 | |
| 341 | /* |
| 342 | * WORKAROUND |
| 343 | * |
Kuninori Morimoto | ab2049f | 2016-03-07 05:07:57 +0000 | [diff] [blame] | 344 | * ignore over flow error when rsnd_src_sync_is_enabled() |
Kuninori Morimoto | 1a1bf58 | 2015-07-15 07:10:22 +0000 | [diff] [blame] | 345 | */ |
Kuninori Morimoto | ab2049f | 2016-03-07 05:07:57 +0000 | [diff] [blame] | 346 | if (rsnd_src_sync_is_enabled(mod)) |
Kuninori Morimoto | 1a1bf58 | 2015-07-15 07:10:22 +0000 | [diff] [blame] | 347 | val0 = val0 & 0xffff; |
| 348 | |
Kuninori Morimoto | 2b62786 | 2018-02-13 02:08:53 +0000 | [diff] [blame] | 349 | status0 = rsnd_mod_read(mod, SCU_SYS_STATUS0); |
| 350 | status1 = rsnd_mod_read(mod, SCU_SYS_STATUS1); |
| 351 | if ((status0 & val0) || (status1 & val1)) { |
| 352 | rsnd_dbg_irq_status(dev, "%s[%d] err status : 0x%08x, 0x%08x\n", |
| 353 | rsnd_mod_name(mod), rsnd_mod_id(mod), |
| 354 | status0, status1); |
| 355 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 356 | ret = true; |
Kuninori Morimoto | 2b62786 | 2018-02-13 02:08:53 +0000 | [diff] [blame] | 357 | } |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 358 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 359 | return ret; |
| 360 | } |
| 361 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 362 | static int rsnd_src_start(struct rsnd_mod *mod, |
| 363 | struct rsnd_dai_stream *io, |
| 364 | struct rsnd_priv *priv) |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 365 | { |
Kuninori Morimoto | 1a1bf58 | 2015-07-15 07:10:22 +0000 | [diff] [blame] | 366 | u32 val; |
| 367 | |
| 368 | /* |
| 369 | * WORKAROUND |
| 370 | * |
| 371 | * Enable SRC output if you want to use sync convert together with DVC |
| 372 | */ |
Kuninori Morimoto | ab2049f | 2016-03-07 05:07:57 +0000 | [diff] [blame] | 373 | val = (rsnd_io_to_mod_dvc(io) && !rsnd_src_sync_is_enabled(mod)) ? |
Kuninori Morimoto | 1a1bf58 | 2015-07-15 07:10:22 +0000 | [diff] [blame] | 374 | 0x01 : 0x11; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 375 | |
| 376 | rsnd_mod_write(mod, SRC_CTRL, val); |
| 377 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 378 | return 0; |
| 379 | } |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 380 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 381 | static int rsnd_src_stop(struct rsnd_mod *mod, |
| 382 | struct rsnd_dai_stream *io, |
| 383 | struct rsnd_priv *priv) |
| 384 | { |
Kuninori Morimoto | 31739a6 | 2016-01-21 02:00:13 +0000 | [diff] [blame] | 385 | rsnd_mod_write(mod, SRC_CTRL, 0); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 390 | static int rsnd_src_init(struct rsnd_mod *mod, |
| 391 | struct rsnd_dai_stream *io, |
| 392 | struct rsnd_priv *priv) |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 393 | { |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 394 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 395 | |
Kuninori Morimoto | ef30da1c5 | 2017-02-02 05:01:05 +0000 | [diff] [blame] | 396 | /* reset sync convert_rate */ |
| 397 | src->sync.val = 0; |
| 398 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 399 | rsnd_mod_power_on(mod); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 400 | |
Kuninori Morimoto | 98efeea | 2015-11-30 08:50:32 +0000 | [diff] [blame] | 401 | rsnd_src_activation(mod); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 402 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 403 | rsnd_src_set_convert_rate(io, mod); |
| 404 | |
Kuninori Morimoto | 8cc225f | 2015-11-26 11:11:03 +0000 | [diff] [blame] | 405 | rsnd_src_status_clear(mod); |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 406 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 407 | return 0; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 410 | static int rsnd_src_quit(struct rsnd_mod *mod, |
| 411 | struct rsnd_dai_stream *io, |
| 412 | struct rsnd_priv *priv) |
Kuninori Morimoto | b761bf2 | 2015-10-26 08:40:59 +0000 | [diff] [blame] | 413 | { |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 414 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 415 | |
Kuninori Morimoto | 475a361 | 2015-11-30 08:51:35 +0000 | [diff] [blame] | 416 | rsnd_src_halt(mod); |
| 417 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 418 | rsnd_mod_power_off(mod); |
| 419 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 420 | /* reset sync convert_rate */ |
| 421 | src->sync.val = 0; |
| 422 | |
| 423 | return 0; |
Kuninori Morimoto | b761bf2 | 2015-10-26 08:40:59 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 426 | static void __rsnd_src_interrupt(struct rsnd_mod *mod, |
| 427 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 428 | { |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 429 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 430 | bool stop = false; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 431 | |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 432 | spin_lock(&priv->lock); |
| 433 | |
| 434 | /* ignore all cases if not working */ |
Kuninori Morimoto | d5bbe7d | 2015-06-15 06:27:47 +0000 | [diff] [blame] | 435 | if (!rsnd_io_is_working(io)) |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 436 | goto rsnd_src_interrupt_out; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 437 | |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 438 | if (rsnd_src_error_occurred(mod)) |
| 439 | stop = true; |
Kuninori Morimoto | 88c61cf | 2015-06-15 06:27:13 +0000 | [diff] [blame] | 440 | |
Kuninori Morimoto | 8cc225f | 2015-11-26 11:11:03 +0000 | [diff] [blame] | 441 | rsnd_src_status_clear(mod); |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 442 | rsnd_src_interrupt_out: |
Kuninori Morimoto | 8cc225f | 2015-11-26 11:11:03 +0000 | [diff] [blame] | 443 | |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 444 | spin_unlock(&priv->lock); |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 445 | |
| 446 | if (stop) |
| 447 | snd_pcm_stop_xrun(io->substream); |
Kuninori Morimoto | 88c61cf | 2015-06-15 06:27:13 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 450 | static irqreturn_t rsnd_src_interrupt(int irq, void *data) |
Kuninori Morimoto | 88c61cf | 2015-06-15 06:27:13 +0000 | [diff] [blame] | 451 | { |
| 452 | struct rsnd_mod *mod = data; |
| 453 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 454 | rsnd_mod_interrupt(mod, __rsnd_src_interrupt); |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 455 | |
| 456 | return IRQ_HANDLED; |
| 457 | } |
| 458 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 459 | static int rsnd_src_probe_(struct rsnd_mod *mod, |
| 460 | struct rsnd_dai_stream *io, |
| 461 | struct rsnd_priv *priv) |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 462 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 463 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 464 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 465 | int irq = src->irq; |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 466 | int ret; |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 467 | |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 468 | if (irq > 0) { |
| 469 | /* |
| 470 | * IRQ is not supported on non-DT |
| 471 | * see |
Kuninori Morimoto | b5b442a | 2016-01-26 04:56:57 +0000 | [diff] [blame] | 472 | * rsnd_src_irq() |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 473 | */ |
| 474 | ret = devm_request_irq(dev, irq, |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 475 | rsnd_src_interrupt, |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 476 | IRQF_SHARED, |
| 477 | dev_name(dev), mod); |
| 478 | if (ret) |
Kuninori Morimoto | b543b52 | 2015-03-26 04:02:32 +0000 | [diff] [blame] | 479 | return ret; |
Kuninori Morimoto | cfcefe0 | 2015-01-08 01:52:36 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Kuninori Morimoto | b99305d | 2016-10-25 00:36:13 +0000 | [diff] [blame] | 482 | ret = rsnd_dma_attach(io, mod, &src->dma); |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 483 | |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 484 | return ret; |
| 485 | } |
| 486 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 487 | static int rsnd_src_pcm_new(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac19 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 488 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 489 | struct snd_soc_pcm_runtime *rtd) |
| 490 | { |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 491 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 492 | int ret; |
| 493 | |
| 494 | /* |
| 495 | * enable SRC sync convert if possible |
| 496 | */ |
| 497 | |
| 498 | /* |
Kuninori Morimoto | 61a219f | 2016-03-07 05:06:17 +0000 | [diff] [blame] | 499 | * It can't use SRC Synchronous convert |
| 500 | * when Capture if it uses CMD |
Kuninori Morimoto | 7115cb9 | 2015-11-10 07:39:17 +0000 | [diff] [blame] | 501 | */ |
Kuninori Morimoto | 61a219f | 2016-03-07 05:06:17 +0000 | [diff] [blame] | 502 | if (rsnd_io_to_mod_cmd(io) && !rsnd_io_is_play(io)) |
Kuninori Morimoto | 7115cb9 | 2015-11-10 07:39:17 +0000 | [diff] [blame] | 503 | return 0; |
| 504 | |
| 505 | /* |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 506 | * enable sync convert |
| 507 | */ |
Kuninori Morimoto | b65a7cc | 2015-06-15 06:27:28 +0000 | [diff] [blame] | 508 | ret = rsnd_kctrl_new_s(mod, io, rtd, |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 509 | rsnd_io_is_play(io) ? |
| 510 | "SRC Out Rate Switch" : |
| 511 | "SRC In Rate Switch", |
Kuninori Morimoto | f0b04d8 | 2017-06-07 00:11:48 +0000 | [diff] [blame] | 512 | rsnd_kctrl_accept_anytime, |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 513 | rsnd_src_set_convert_rate, |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 514 | &src->sen, 1); |
| 515 | if (ret < 0) |
| 516 | return ret; |
| 517 | |
Kuninori Morimoto | b65a7cc | 2015-06-15 06:27:28 +0000 | [diff] [blame] | 518 | ret = rsnd_kctrl_new_s(mod, io, rtd, |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 519 | rsnd_io_is_play(io) ? |
| 520 | "SRC Out Rate" : |
| 521 | "SRC In Rate", |
Kuninori Morimoto | f0b04d8 | 2017-06-07 00:11:48 +0000 | [diff] [blame] | 522 | rsnd_kctrl_accept_runtime, |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 523 | rsnd_src_set_convert_rate, |
Kuninori Morimoto | 43cb695 | 2015-04-01 04:15:16 +0000 | [diff] [blame] | 524 | &src->sync, 192000); |
| 525 | |
| 526 | return ret; |
| 527 | } |
| 528 | |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 529 | static struct rsnd_mod_ops rsnd_src_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 530 | .name = SRC_NAME, |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 531 | .dma_req = rsnd_src_dma_req, |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 532 | .probe = rsnd_src_probe_, |
| 533 | .init = rsnd_src_init, |
| 534 | .quit = rsnd_src_quit, |
| 535 | .start = rsnd_src_start, |
| 536 | .stop = rsnd_src_stop, |
Kuninori Morimoto | b5b442a | 2016-01-26 04:56:57 +0000 | [diff] [blame] | 537 | .irq = rsnd_src_irq, |
Kuninori Morimoto | 3b7843f | 2015-03-26 04:02:51 +0000 | [diff] [blame] | 538 | .hw_params = rsnd_src_hw_params, |
Kuninori Morimoto | 75916f6 | 2015-11-10 05:10:48 +0000 | [diff] [blame] | 539 | .pcm_new = rsnd_src_pcm_new, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 540 | }; |
| 541 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 542 | 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] | 543 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 544 | if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) |
Takashi Iwai | 8b14719 | 2013-11-05 18:40:05 +0100 | [diff] [blame] | 545 | id = 0; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 546 | |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 547 | return rsnd_mod_get(rsnd_src_get(priv, id)); |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Kuninori Morimoto | 2ea6b07 | 2015-11-10 05:14:12 +0000 | [diff] [blame] | 550 | int rsnd_src_probe(struct rsnd_priv *priv) |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 551 | { |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 552 | struct device_node *node; |
| 553 | struct device_node *np; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 554 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 555 | struct rsnd_src *src; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 556 | struct clk *clk; |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 557 | char name[RSND_SRC_NAME_SIZE]; |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 558 | int i, nr, ret; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 559 | |
Kuninori Morimoto | e8e7b7b | 2015-11-10 05:09:52 +0000 | [diff] [blame] | 560 | /* This driver doesn't support Gen1 at this point */ |
| 561 | if (rsnd_is_gen1(priv)) |
| 562 | return 0; |
Kuninori Morimoto | 033e7ed | 2014-05-22 23:25:37 -0700 | [diff] [blame] | 563 | |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 564 | node = rsnd_src_of_node(priv); |
| 565 | if (!node) |
| 566 | return 0; /* not used is not error */ |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 567 | |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 568 | nr = of_get_child_count(node); |
| 569 | if (!nr) { |
| 570 | ret = -EINVAL; |
| 571 | goto rsnd_src_probe_done; |
| 572 | } |
Kuninori Morimoto | 389933d | 2014-03-03 20:50:00 -0800 | [diff] [blame] | 573 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 574 | src = devm_kcalloc(dev, nr, sizeof(*src), GFP_KERNEL); |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 575 | if (!src) { |
| 576 | ret = -ENOMEM; |
| 577 | goto rsnd_src_probe_done; |
| 578 | } |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 579 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 580 | priv->src_nr = nr; |
| 581 | priv->src = src; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 582 | |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 583 | i = 0; |
| 584 | for_each_child_of_node(node, np) { |
Sergei Shtylyov | de19651 | 2016-05-12 01:36:40 +0300 | [diff] [blame] | 585 | if (!of_device_is_available(np)) |
| 586 | goto skip; |
| 587 | |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 588 | src = rsnd_src_get(priv, i); |
| 589 | |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 590 | snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d", |
| 591 | SRC_NAME, i); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 592 | |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 593 | src->irq = irq_of_parse_and_map(np, 0); |
| 594 | if (!src->irq) { |
| 595 | ret = -EINVAL; |
Julia Lawall | 53ba2aa | 2017-07-15 09:19:07 +0200 | [diff] [blame] | 596 | of_node_put(np); |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 597 | goto rsnd_src_probe_done; |
| 598 | } |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 599 | |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 600 | clk = devm_clk_get(dev, name); |
| 601 | if (IS_ERR(clk)) { |
| 602 | ret = PTR_ERR(clk); |
Julia Lawall | 53ba2aa | 2017-07-15 09:19:07 +0200 | [diff] [blame] | 603 | of_node_put(np); |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 604 | goto rsnd_src_probe_done; |
| 605 | } |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 606 | |
Kuninori Morimoto | e8e7b7b | 2015-11-10 05:09:52 +0000 | [diff] [blame] | 607 | ret = rsnd_mod_init(priv, rsnd_mod_get(src), |
Kuninori Morimoto | 5ba17b42 | 2016-01-21 01:58:07 +0000 | [diff] [blame] | 608 | &rsnd_src_ops, clk, rsnd_mod_get_status, |
| 609 | RSND_MOD_SRC, i); |
Julia Lawall | 53ba2aa | 2017-07-15 09:19:07 +0200 | [diff] [blame] | 610 | if (ret) { |
| 611 | of_node_put(np); |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 612 | goto rsnd_src_probe_done; |
Julia Lawall | 53ba2aa | 2017-07-15 09:19:07 +0200 | [diff] [blame] | 613 | } |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 614 | |
Sergei Shtylyov | de19651 | 2016-05-12 01:36:40 +0300 | [diff] [blame] | 615 | skip: |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 616 | i++; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 617 | } |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 618 | |
Kuninori Morimoto | adf6a68 | 2015-11-10 05:11:55 +0000 | [diff] [blame] | 619 | ret = 0; |
| 620 | |
| 621 | rsnd_src_probe_done: |
| 622 | of_node_put(node); |
| 623 | |
| 624 | return ret; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 625 | } |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 626 | |
Kuninori Morimoto | 2ea6b07 | 2015-11-10 05:14:12 +0000 | [diff] [blame] | 627 | void rsnd_src_remove(struct rsnd_priv *priv) |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 628 | { |
| 629 | struct rsnd_src *src; |
| 630 | int i; |
| 631 | |
| 632 | for_each_rsnd_src(src, priv, i) { |
Kuninori Morimoto | b76e218 | 2015-09-10 07:02:21 +0000 | [diff] [blame] | 633 | rsnd_mod_quit(rsnd_mod_get(src)); |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 634 | } |
| 635 | } |