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