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 | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 13 | struct rsnd_src { |
| 14 | struct rsnd_src_platform_info *info; /* rcar_snd.h */ |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 15 | struct rsnd_mod mod; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 16 | struct clk *clk; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 17 | }; |
| 18 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 19 | #define RSND_SRC_NAME_SIZE 16 |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 20 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 21 | #define rsnd_src_convert_rate(p) ((p)->info->convert_rate) |
| 22 | #define rsnd_mod_to_src(_mod) \ |
| 23 | container_of((_mod), struct rsnd_src, mod) |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 24 | #define rsnd_src_dma_available(src) \ |
| 25 | rsnd_dma_available(rsnd_mod_to_dma(&(src)->mod)) |
Kuninori Morimoto | 39cf3c4 | 2014-01-23 18:40:47 -0800 | [diff] [blame] | 26 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 27 | #define for_each_rsnd_src(pos, priv, i) \ |
Kuninori Morimoto | 39cf3c4 | 2014-01-23 18:40:47 -0800 | [diff] [blame] | 28 | for ((i) = 0; \ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 29 | ((i) < rsnd_src_nr(priv)) && \ |
| 30 | ((pos) = (struct rsnd_src *)(priv)->src + i); \ |
Kuninori Morimoto | 39cf3c4 | 2014-01-23 18:40:47 -0800 | [diff] [blame] | 31 | i++) |
| 32 | |
| 33 | |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 34 | /* |
| 35 | * image of SRC (Sampling Rate Converter) |
| 36 | * |
| 37 | * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+ |
| 38 | * 48kHz <-> | SRC | <------> | SSI | <-----> | codec | |
| 39 | * 44.1kHz <-> +-----+ +-----+ +-------+ |
| 40 | * ... |
| 41 | * |
| 42 | */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 43 | |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 44 | /* |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 45 | * src.c is caring... |
Kuninori Morimoto | c926b74 | 2014-01-23 18:40:41 -0800 | [diff] [blame] | 46 | * |
| 47 | * Gen1 |
| 48 | * |
| 49 | * [mem] -> [SRU] -> [SSI] |
| 50 | * |--------| |
| 51 | * |
| 52 | * Gen2 |
| 53 | * |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 54 | * [mem] -> [SRC] -> [SSIU] -> [SSI] |
Kuninori Morimoto | c926b74 | 2014-01-23 18:40:41 -0800 | [diff] [blame] | 55 | * |-----------------| |
| 56 | */ |
| 57 | |
| 58 | /* |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 59 | * How to use SRC bypass mode for debugging |
| 60 | * |
| 61 | * SRC has bypass mode, and it is useful for debugging. |
| 62 | * In Gen2 case, |
| 63 | * SRCm_MODE controls whether SRC is used or not |
| 64 | * SSI_MODE0 controls whether SSIU which receives SRC data |
| 65 | * is used or not. |
| 66 | * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC, |
| 67 | * but SRC bypass mode needs SSI_MODE0 only. |
| 68 | * |
| 69 | * This driver request |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 70 | * struct rsnd_src_platform_info { |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 71 | * u32 convert_rate; |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 72 | * int dma_id; |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 73 | * } |
| 74 | * |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 75 | * rsnd_src_convert_rate() indicates |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 76 | * above convert_rate, and it controls |
| 77 | * whether SRC is used or not. |
| 78 | * |
| 79 | * ex) doesn't use SRC |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 80 | * static struct rsnd_dai_platform_info rsnd_dai = { |
| 81 | * .playback = { .ssi = &rsnd_ssi[0], }, |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 82 | * }; |
| 83 | * |
| 84 | * ex) uses SRC |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 85 | * static struct rsnd_src_platform_info rsnd_src[] = { |
| 86 | * RSND_SCU(48000, 0), |
| 87 | * ... |
| 88 | * }; |
| 89 | * static struct rsnd_dai_platform_info rsnd_dai = { |
| 90 | * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] }, |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 91 | * }; |
| 92 | * |
| 93 | * ex) uses SRC bypass mode |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 94 | * static struct rsnd_src_platform_info rsnd_src[] = { |
| 95 | * RSND_SCU(0, 0), |
| 96 | * ... |
| 97 | * }; |
| 98 | * static struct rsnd_dai_platform_info rsnd_dai = { |
| 99 | * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] }, |
Kuninori Morimoto | 41c6221 | 2014-01-23 18:39:56 -0800 | [diff] [blame] | 100 | * }; |
| 101 | * |
| 102 | */ |
| 103 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 104 | /* |
| 105 | * Gen1/Gen2 common functions |
| 106 | */ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 107 | int rsnd_src_ssi_mode_init(struct rsnd_mod *ssi_mod, |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 108 | struct rsnd_dai *rdai, |
| 109 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 110 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 111 | struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 112 | int ssi_id = rsnd_mod_id(ssi_mod); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 113 | |
| 114 | /* |
| 115 | * SSI_MODE0 |
| 116 | */ |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 117 | rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id), |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 118 | src_mod ? 0 : (1 << ssi_id)); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * SSI_MODE1 |
| 122 | */ |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 123 | if (rsnd_ssi_is_pin_sharing(ssi_mod)) { |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 124 | int shift = -1; |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 125 | switch (ssi_id) { |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 126 | case 1: |
| 127 | shift = 0; |
| 128 | break; |
| 129 | case 2: |
| 130 | shift = 2; |
| 131 | break; |
| 132 | case 4: |
| 133 | shift = 16; |
| 134 | break; |
| 135 | } |
| 136 | |
| 137 | if (shift >= 0) |
Kuninori Morimoto | 221bf52 | 2014-03-03 20:50:24 -0800 | [diff] [blame] | 138 | rsnd_mod_bset(ssi_mod, SSI_MODE1, |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 139 | 0x3 << shift, |
| 140 | rsnd_dai_is_clk_master(rdai) ? |
| 141 | 0x2 << shift : 0x1 << shift); |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 147 | int rsnd_src_enable_ssi_irq(struct rsnd_mod *ssi_mod, |
Kuninori Morimoto | b8cc41e | 2014-03-03 20:50:08 -0800 | [diff] [blame] | 148 | struct rsnd_dai *rdai, |
| 149 | struct rsnd_dai_stream *io) |
| 150 | { |
| 151 | struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); |
| 152 | |
| 153 | /* enable PIO interrupt if Gen2 */ |
| 154 | if (rsnd_is_gen2(priv)) |
| 155 | rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000); |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 160 | unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, |
Kuninori Morimoto | 374e542 | 2014-03-02 23:43:03 -0800 | [diff] [blame] | 161 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 162 | struct snd_pcm_runtime *runtime) |
| 163 | { |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 164 | struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 165 | struct rsnd_src *src; |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 166 | unsigned int rate = 0; |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 167 | |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 168 | if (src_mod) { |
| 169 | src = rsnd_mod_to_src(src_mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 170 | |
Kuninori Morimoto | b1eac43 | 2014-03-23 21:23:42 -0700 | [diff] [blame] | 171 | /* |
| 172 | * return convert rate if SRC is used, |
| 173 | * otherwise, return runtime->rate as usual |
| 174 | */ |
| 175 | rate = rsnd_src_convert_rate(src); |
| 176 | } |
| 177 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 178 | if (!rate) |
| 179 | rate = runtime->rate; |
| 180 | |
| 181 | return rate; |
| 182 | } |
| 183 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 184 | static int rsnd_src_set_convert_rate(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 185 | struct rsnd_dai *rdai, |
| 186 | struct rsnd_dai_stream *io) |
| 187 | { |
| 188 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 189 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 190 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 191 | u32 fsrate = 0; |
| 192 | |
| 193 | if (convert_rate) |
| 194 | fsrate = 0x0400000 / convert_rate * runtime->rate; |
| 195 | |
| 196 | /* set/clear soft reset */ |
| 197 | rsnd_mod_write(mod, SRC_SWRSR, 0); |
| 198 | rsnd_mod_write(mod, SRC_SWRSR, 1); |
| 199 | |
| 200 | /* |
| 201 | * Initialize the operation of the SRC internal circuits |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 202 | * see rsnd_src_start() |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 203 | */ |
| 204 | rsnd_mod_write(mod, SRC_SRCIR, 1); |
| 205 | |
| 206 | /* Set channel number and output bit length */ |
Kuninori Morimoto | d7bdbc5 | 2014-05-08 17:44:14 -0700 | [diff] [blame^] | 207 | rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod)); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 208 | |
| 209 | /* Enable the initial value of IFS */ |
| 210 | if (fsrate) { |
| 211 | rsnd_mod_write(mod, SRC_IFSCR, 1); |
| 212 | |
| 213 | /* Set initial value of IFS */ |
| 214 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); |
| 215 | } |
| 216 | |
| 217 | /* use DMA transfer */ |
| 218 | rsnd_mod_write(mod, SRC_BUSIF_MODE, 1); |
| 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 223 | static int rsnd_src_init(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 224 | struct rsnd_dai *rdai, |
| 225 | struct rsnd_dai_stream *io) |
| 226 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 227 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 228 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 229 | clk_enable(src->clk); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 230 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 231 | return 0; |
| 232 | } |
| 233 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 234 | static int rsnd_src_quit(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 235 | struct rsnd_dai *rdai, |
| 236 | struct rsnd_dai_stream *io) |
| 237 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 238 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 239 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 240 | clk_disable(src->clk); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 245 | static int rsnd_src_start(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 246 | struct rsnd_dai *rdai, |
| 247 | struct rsnd_dai_stream *io) |
| 248 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 249 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 250 | |
| 251 | /* |
| 252 | * Cancel the initialization and operate the SRC function |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 253 | * see rsnd_src_set_convert_rate() |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 254 | */ |
| 255 | rsnd_mod_write(mod, SRC_SRCIR, 0); |
| 256 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 257 | if (rsnd_src_convert_rate(src)) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 258 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1); |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 264 | static int rsnd_src_stop(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 265 | struct rsnd_dai *rdai, |
| 266 | struct rsnd_dai_stream *io) |
| 267 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 268 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 269 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 270 | if (rsnd_src_convert_rate(src)) |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 271 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0); |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 276 | static struct rsnd_mod_ops rsnd_src_non_ops = { |
| 277 | .name = "src (non)", |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 278 | }; |
| 279 | |
| 280 | /* |
| 281 | * Gen1 functions |
| 282 | */ |
| 283 | static int rsnd_src_set_route_gen1(struct rsnd_mod *mod, |
| 284 | struct rsnd_dai *rdai, |
| 285 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 286 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 287 | struct src_route_config { |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 288 | u32 mask; |
| 289 | int shift; |
| 290 | } routes[] = { |
| 291 | { 0xF, 0, }, /* 0 */ |
| 292 | { 0xF, 4, }, /* 1 */ |
| 293 | { 0xF, 8, }, /* 2 */ |
| 294 | { 0x7, 12, }, /* 3 */ |
| 295 | { 0x7, 16, }, /* 4 */ |
| 296 | { 0x7, 20, }, /* 5 */ |
| 297 | { 0x7, 24, }, /* 6 */ |
| 298 | { 0x3, 28, }, /* 7 */ |
| 299 | { 0x3, 30, }, /* 8 */ |
| 300 | }; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 301 | u32 mask; |
| 302 | u32 val; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 303 | int id; |
| 304 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 305 | id = rsnd_mod_id(mod); |
Dan Carpenter | b5f3d7a | 2013-11-08 12:46:10 +0300 | [diff] [blame] | 306 | if (id < 0 || id >= ARRAY_SIZE(routes)) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 307 | return -EIO; |
| 308 | |
| 309 | /* |
| 310 | * SRC_ROUTE_SELECT |
| 311 | */ |
| 312 | val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2; |
| 313 | val = val << routes[id].shift; |
| 314 | mask = routes[id].mask << routes[id].shift; |
| 315 | |
| 316 | rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val); |
| 317 | |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 318 | return 0; |
| 319 | } |
| 320 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 321 | static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 322 | struct rsnd_dai *rdai, |
| 323 | struct rsnd_dai_stream *io) |
| 324 | { |
| 325 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 326 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 327 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 328 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 329 | u32 mask; |
| 330 | u32 val; |
| 331 | int shift; |
| 332 | int id = rsnd_mod_id(mod); |
| 333 | int ret; |
| 334 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 335 | /* |
| 336 | * SRC_TIMING_SELECT |
| 337 | */ |
| 338 | shift = (id % 4) * 8; |
| 339 | mask = 0x1F << shift; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 340 | |
| 341 | /* |
| 342 | * ADG is used as source clock if SRC was used, |
| 343 | * then, SSI WS is used as destination clock. |
| 344 | * SSI WS is used as source clock if SRC is not used |
| 345 | * (when playback, source/destination become reverse when capture) |
| 346 | */ |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 347 | ret = 0; |
| 348 | if (convert_rate) { |
| 349 | /* use ADG */ |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 350 | val = 0; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 351 | ret = rsnd_adg_set_convert_clk_gen1(priv, mod, |
| 352 | runtime->rate, |
| 353 | convert_rate); |
| 354 | } else if (8 == id) { |
| 355 | /* use SSI WS, but SRU8 is special */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 356 | val = id << shift; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 357 | } else { |
| 358 | /* use SSI WS */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 359 | val = (id + 1) << shift; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | if (ret < 0) |
| 363 | return ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 364 | |
| 365 | switch (id / 4) { |
| 366 | case 0: |
| 367 | rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val); |
| 368 | break; |
| 369 | case 1: |
| 370 | rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val); |
| 371 | break; |
| 372 | case 2: |
| 373 | rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val); |
| 374 | break; |
| 375 | } |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 380 | static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 381 | struct rsnd_dai *rdai, |
| 382 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 383 | { |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 384 | int ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 385 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 386 | ret = rsnd_src_set_convert_rate(mod, rdai, io); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 387 | if (ret < 0) |
| 388 | return ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 389 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 390 | /* Select SRC mode (fixed value) */ |
| 391 | rsnd_mod_write(mod, SRC_SRCCR, 0x00010110); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 392 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 393 | /* Set the restriction value of the FS ratio (98%) */ |
| 394 | rsnd_mod_write(mod, SRC_MNFSR, |
| 395 | rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 396 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 397 | /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 398 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 402 | static int rsnd_src_init_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 403 | struct rsnd_dai *rdai, |
| 404 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 405 | { |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 406 | int ret; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 407 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 408 | ret = rsnd_src_init(mod, rdai, io); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 409 | if (ret < 0) |
| 410 | return ret; |
| 411 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 412 | ret = rsnd_src_set_route_gen1(mod, rdai, io); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 413 | if (ret < 0) |
| 414 | return ret; |
| 415 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 416 | ret = rsnd_src_set_convert_rate_gen1(mod, rdai, io); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 417 | if (ret < 0) |
| 418 | return ret; |
| 419 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 420 | ret = rsnd_src_set_convert_timing_gen1(mod, rdai, io); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 421 | if (ret < 0) |
| 422 | return ret; |
| 423 | |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 424 | return 0; |
| 425 | } |
| 426 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 427 | static int rsnd_src_start_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 428 | struct rsnd_dai *rdai, |
| 429 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 430 | { |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 431 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 432 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 433 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id)); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 434 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 435 | return rsnd_src_start(mod, rdai, io); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 438 | static int rsnd_src_stop_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 439 | struct rsnd_dai *rdai, |
| 440 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 441 | { |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 442 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 443 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 444 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 445 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 446 | return rsnd_src_stop(mod, rdai, io); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 447 | } |
| 448 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 449 | static struct rsnd_mod_ops rsnd_src_gen1_ops = { |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 450 | .name = "sru (gen1)", |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 451 | .init = rsnd_src_init_gen1, |
| 452 | .quit = rsnd_src_quit, |
| 453 | .start = rsnd_src_start_gen1, |
| 454 | .stop = rsnd_src_stop_gen1, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 455 | }; |
| 456 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 457 | /* |
| 458 | * Gen2 functions |
| 459 | */ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 460 | static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 461 | struct rsnd_dai *rdai, |
| 462 | struct rsnd_dai_stream *io) |
| 463 | { |
| 464 | int ret; |
| 465 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 466 | ret = rsnd_src_set_convert_rate(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 467 | if (ret < 0) |
| 468 | return ret; |
| 469 | |
Kuninori Morimoto | d7bdbc5 | 2014-05-08 17:44:14 -0700 | [diff] [blame^] | 470 | rsnd_mod_write(mod, SSI_BUSIF_ADINR, rsnd_get_adinr(mod)); |
| 471 | rsnd_mod_write(mod, SSI_BUSIF_MODE, 1); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 472 | |
| 473 | rsnd_mod_write(mod, SRC_SRCCR, 0x00011110); |
| 474 | |
| 475 | rsnd_mod_write(mod, SRC_BSDSR, 0x01800000); |
| 476 | rsnd_mod_write(mod, SRC_BSISR, 0x00100060); |
| 477 | |
| 478 | return 0; |
| 479 | } |
| 480 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 481 | static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 482 | struct rsnd_dai *rdai, |
| 483 | struct rsnd_dai_stream *io) |
| 484 | { |
| 485 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 486 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 487 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 488 | int ret; |
| 489 | |
| 490 | if (convert_rate) |
| 491 | ret = rsnd_adg_set_convert_clk_gen2(mod, rdai, io, |
| 492 | runtime->rate, |
| 493 | convert_rate); |
| 494 | else |
| 495 | ret = rsnd_adg_set_convert_timing_gen2(mod, rdai, io); |
| 496 | |
| 497 | return ret; |
| 498 | } |
| 499 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 500 | static int rsnd_src_probe_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 501 | struct rsnd_dai *rdai, |
| 502 | struct rsnd_dai_stream *io) |
| 503 | { |
| 504 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 505 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 506 | struct device *dev = rsnd_priv_to_dev(priv); |
| 507 | int ret; |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 508 | |
| 509 | ret = rsnd_dma_init(priv, |
| 510 | rsnd_mod_to_dma(mod), |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 511 | rsnd_info_is_playback(priv, src), |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 512 | src->info->dma_id); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 513 | if (ret < 0) |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 514 | dev_err(dev, "SRC DMA failed\n"); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 515 | |
| 516 | return ret; |
| 517 | } |
| 518 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 519 | static int rsnd_src_remove_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 520 | struct rsnd_dai *rdai, |
| 521 | struct rsnd_dai_stream *io) |
| 522 | { |
| 523 | rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod)); |
| 524 | |
| 525 | return 0; |
| 526 | } |
| 527 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 528 | static int rsnd_src_init_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 529 | struct rsnd_dai *rdai, |
| 530 | struct rsnd_dai_stream *io) |
| 531 | { |
| 532 | int ret; |
| 533 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 534 | ret = rsnd_src_init(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 535 | if (ret < 0) |
| 536 | return ret; |
| 537 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 538 | ret = rsnd_src_set_convert_rate_gen2(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 539 | if (ret < 0) |
| 540 | return ret; |
| 541 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 542 | ret = rsnd_src_set_convert_timing_gen2(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 543 | if (ret < 0) |
| 544 | return ret; |
| 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 549 | static int rsnd_src_start_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 550 | struct rsnd_dai *rdai, |
| 551 | struct rsnd_dai_stream *io) |
| 552 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 553 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 554 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 555 | rsnd_dma_start(rsnd_mod_to_dma(&src->mod)); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 556 | |
| 557 | rsnd_mod_write(mod, SSI_CTRL, 0x1); |
| 558 | rsnd_mod_write(mod, SRC_CTRL, 0x11); |
| 559 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 560 | return rsnd_src_start(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 561 | } |
| 562 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 563 | static int rsnd_src_stop_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 564 | struct rsnd_dai *rdai, |
| 565 | struct rsnd_dai_stream *io) |
| 566 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 567 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 568 | |
| 569 | rsnd_mod_write(mod, SSI_CTRL, 0); |
| 570 | rsnd_mod_write(mod, SRC_CTRL, 0); |
| 571 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 572 | rsnd_dma_stop(rsnd_mod_to_dma(&src->mod)); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 573 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 574 | return rsnd_src_stop(mod, rdai, io); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 575 | } |
| 576 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 577 | static struct rsnd_mod_ops rsnd_src_gen2_ops = { |
| 578 | .name = "src (gen2)", |
| 579 | .probe = rsnd_src_probe_gen2, |
| 580 | .remove = rsnd_src_remove_gen2, |
| 581 | .init = rsnd_src_init_gen2, |
| 582 | .quit = rsnd_src_quit, |
| 583 | .start = rsnd_src_start_gen2, |
| 584 | .stop = rsnd_src_stop_gen2, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 585 | }; |
| 586 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 587 | 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] | 588 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 589 | if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) |
Takashi Iwai | 8b14719 | 2013-11-05 18:40:05 +0100 | [diff] [blame] | 590 | id = 0; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 591 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 592 | return &((struct rsnd_src *)(priv->src) + id)->mod; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 595 | static void rsnd_of_parse_src(struct platform_device *pdev, |
| 596 | const struct rsnd_of_data *of_data, |
| 597 | struct rsnd_priv *priv) |
| 598 | { |
| 599 | struct device_node *src_node; |
| 600 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
| 601 | struct rsnd_src_platform_info *src_info; |
| 602 | struct device *dev = &pdev->dev; |
| 603 | int nr; |
| 604 | |
| 605 | if (!of_data) |
| 606 | return; |
| 607 | |
| 608 | src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src"); |
| 609 | if (!src_node) |
| 610 | return; |
| 611 | |
| 612 | nr = of_get_child_count(src_node); |
| 613 | if (!nr) |
| 614 | return; |
| 615 | |
| 616 | src_info = devm_kzalloc(dev, |
| 617 | sizeof(struct rsnd_src_platform_info) * nr, |
| 618 | GFP_KERNEL); |
| 619 | if (!src_info) { |
| 620 | dev_err(dev, "src info allocation error\n"); |
| 621 | return; |
| 622 | } |
| 623 | |
| 624 | info->src_info = src_info; |
| 625 | info->src_info_nr = nr; |
| 626 | } |
| 627 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 628 | int rsnd_src_probe(struct platform_device *pdev, |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 629 | const struct rsnd_of_data *of_data, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 630 | struct rsnd_priv *priv) |
| 631 | { |
Kuninori Morimoto | 5da39cf | 2014-02-24 22:15:00 -0800 | [diff] [blame] | 632 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 633 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 634 | struct rsnd_src *src; |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 635 | struct rsnd_mod_ops *ops; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 636 | struct clk *clk; |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 637 | char name[RSND_SRC_NAME_SIZE]; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 638 | int i, nr; |
| 639 | |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 640 | rsnd_of_parse_src(pdev, of_data, priv); |
| 641 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 642 | /* |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 643 | * init SRC |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 644 | */ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 645 | nr = info->src_info_nr; |
Kuninori Morimoto | 389933d | 2014-03-03 20:50:00 -0800 | [diff] [blame] | 646 | if (!nr) |
| 647 | return 0; |
| 648 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 649 | src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); |
| 650 | if (!src) { |
| 651 | dev_err(dev, "SRC allocate failed\n"); |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 652 | return -ENOMEM; |
| 653 | } |
| 654 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 655 | priv->src_nr = nr; |
| 656 | priv->src = src; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 657 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 658 | for_each_rsnd_src(src, priv, i) { |
| 659 | snprintf(name, RSND_SRC_NAME_SIZE, "src.%d", i); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 660 | |
| 661 | clk = devm_clk_get(dev, name); |
| 662 | if (IS_ERR(clk)) |
| 663 | return PTR_ERR(clk); |
| 664 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 665 | src->info = &info->src_info[i]; |
| 666 | src->clk = clk; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 667 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 668 | ops = &rsnd_src_non_ops; |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 669 | if (rsnd_is_gen1(priv)) |
| 670 | ops = &rsnd_src_gen1_ops; |
| 671 | if (rsnd_is_gen2(priv)) |
| 672 | ops = &rsnd_src_gen2_ops; |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 673 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 674 | rsnd_mod_init(priv, &src->mod, ops, RSND_MOD_SRC, i); |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 675 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 676 | dev_dbg(dev, "SRC%d probed\n", i); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 677 | } |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 678 | |
| 679 | return 0; |
| 680 | } |