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