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