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 | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 271 | static struct rsnd_mod_ops rsnd_src_non_ops = { |
| 272 | .name = "src (non)", |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | /* |
| 276 | * Gen1 functions |
| 277 | */ |
| 278 | static int rsnd_src_set_route_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 279 | struct rsnd_dai *rdai) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 280 | { |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 281 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 282 | struct src_route_config { |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 283 | u32 mask; |
| 284 | int shift; |
| 285 | } routes[] = { |
| 286 | { 0xF, 0, }, /* 0 */ |
| 287 | { 0xF, 4, }, /* 1 */ |
| 288 | { 0xF, 8, }, /* 2 */ |
| 289 | { 0x7, 12, }, /* 3 */ |
| 290 | { 0x7, 16, }, /* 4 */ |
| 291 | { 0x7, 20, }, /* 5 */ |
| 292 | { 0x7, 24, }, /* 6 */ |
| 293 | { 0x3, 28, }, /* 7 */ |
| 294 | { 0x3, 30, }, /* 8 */ |
| 295 | }; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 296 | u32 mask; |
| 297 | u32 val; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 298 | int id; |
| 299 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 300 | id = rsnd_mod_id(mod); |
Dan Carpenter | b5f3d7a | 2013-11-08 12:46:10 +0300 | [diff] [blame] | 301 | if (id < 0 || id >= ARRAY_SIZE(routes)) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 302 | return -EIO; |
| 303 | |
| 304 | /* |
| 305 | * SRC_ROUTE_SELECT |
| 306 | */ |
| 307 | val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2; |
| 308 | val = val << routes[id].shift; |
| 309 | mask = routes[id].mask << routes[id].shift; |
| 310 | |
| 311 | rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val); |
| 312 | |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 316 | static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 317 | struct rsnd_dai *rdai) |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 318 | { |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 319 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 320 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 321 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 322 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 323 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 324 | u32 mask; |
| 325 | u32 val; |
| 326 | int shift; |
| 327 | int id = rsnd_mod_id(mod); |
| 328 | int ret; |
| 329 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 330 | /* |
| 331 | * SRC_TIMING_SELECT |
| 332 | */ |
| 333 | shift = (id % 4) * 8; |
| 334 | mask = 0x1F << shift; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 335 | |
| 336 | /* |
| 337 | * ADG is used as source clock if SRC was used, |
| 338 | * then, SSI WS is used as destination clock. |
| 339 | * SSI WS is used as source clock if SRC is not used |
| 340 | * (when playback, source/destination become reverse when capture) |
| 341 | */ |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 342 | ret = 0; |
| 343 | if (convert_rate) { |
| 344 | /* use ADG */ |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 345 | val = 0; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 346 | ret = rsnd_adg_set_convert_clk_gen1(priv, mod, |
| 347 | runtime->rate, |
| 348 | convert_rate); |
| 349 | } else if (8 == id) { |
| 350 | /* use SSI WS, but SRU8 is special */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 351 | val = id << shift; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 352 | } else { |
| 353 | /* use SSI WS */ |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 354 | val = (id + 1) << shift; |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | if (ret < 0) |
| 358 | return ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 359 | |
| 360 | switch (id / 4) { |
| 361 | case 0: |
| 362 | rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val); |
| 363 | break; |
| 364 | case 1: |
| 365 | rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val); |
| 366 | break; |
| 367 | case 2: |
| 368 | rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val); |
| 369 | break; |
| 370 | } |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 375 | static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 376 | struct rsnd_dai *rdai) |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 377 | { |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 378 | int ret; |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 379 | |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 380 | ret = rsnd_src_set_convert_rate(mod, rdai); |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 381 | if (ret < 0) |
| 382 | return ret; |
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 | /* Select SRC mode (fixed value) */ |
| 385 | rsnd_mod_write(mod, SRC_SRCCR, 0x00010110); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 386 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 387 | /* Set the restriction value of the FS ratio (98%) */ |
| 388 | rsnd_mod_write(mod, SRC_MNFSR, |
| 389 | rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 390 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 391 | /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */ |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 392 | |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 393 | return 0; |
| 394 | } |
| 395 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 396 | static int rsnd_src_init_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 397 | struct rsnd_dai *rdai) |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 398 | { |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 399 | int ret; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 400 | |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 401 | ret = rsnd_src_init(mod, rdai); |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [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_route_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_rate_gen1(mod, rdai); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 410 | if (ret < 0) |
| 411 | return ret; |
| 412 | |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 413 | ret = rsnd_src_set_convert_timing_gen1(mod, rdai); |
Kuninori Morimoto | 28dc4b6 | 2014-01-23 18:41:10 -0800 | [diff] [blame] | 414 | if (ret < 0) |
| 415 | return ret; |
| 416 | |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 417 | return 0; |
| 418 | } |
| 419 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 420 | static int rsnd_src_start_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 421 | struct rsnd_dai *rdai) |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 422 | { |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 423 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 424 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 425 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id)); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 426 | |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 427 | return rsnd_src_start(mod, rdai); |
Kuninori Morimoto | a204d90 | 2014-01-23 18:38:33 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 430 | static int rsnd_src_stop_gen1(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 431 | struct rsnd_dai *rdai) |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 432 | { |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 433 | int id = rsnd_mod_id(mod); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 434 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 435 | rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0); |
Kuninori Morimoto | e7ce74e | 2014-01-23 18:38:50 -0800 | [diff] [blame] | 436 | |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 437 | return rsnd_src_stop(mod, rdai); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 440 | static struct rsnd_mod_ops rsnd_src_gen1_ops = { |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 441 | .name = "sru (gen1)", |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 442 | .init = rsnd_src_init_gen1, |
| 443 | .quit = rsnd_src_quit, |
| 444 | .start = rsnd_src_start_gen1, |
| 445 | .stop = rsnd_src_stop_gen1, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 446 | }; |
| 447 | |
Kuninori Morimoto | 1b7b08ef | 2014-01-23 18:41:36 -0800 | [diff] [blame] | 448 | /* |
| 449 | * Gen2 functions |
| 450 | */ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 451 | static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 452 | struct rsnd_dai *rdai) |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 453 | { |
| 454 | int ret; |
| 455 | |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 456 | ret = rsnd_src_set_convert_rate(mod, rdai); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 457 | if (ret < 0) |
| 458 | return ret; |
| 459 | |
Kuninori Morimoto | d7bdbc5 | 2014-05-08 17:44:14 -0700 | [diff] [blame] | 460 | rsnd_mod_write(mod, SSI_BUSIF_ADINR, rsnd_get_adinr(mod)); |
| 461 | rsnd_mod_write(mod, SSI_BUSIF_MODE, 1); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 462 | |
| 463 | rsnd_mod_write(mod, SRC_SRCCR, 0x00011110); |
| 464 | |
| 465 | rsnd_mod_write(mod, SRC_BSDSR, 0x01800000); |
| 466 | rsnd_mod_write(mod, SRC_BSISR, 0x00100060); |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 471 | static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 472 | struct rsnd_dai *rdai) |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 473 | { |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 474 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 475 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 476 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
| 477 | u32 convert_rate = rsnd_src_convert_rate(src); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 478 | int ret; |
| 479 | |
| 480 | if (convert_rate) |
| 481 | ret = rsnd_adg_set_convert_clk_gen2(mod, rdai, io, |
| 482 | runtime->rate, |
| 483 | convert_rate); |
| 484 | else |
| 485 | ret = rsnd_adg_set_convert_timing_gen2(mod, rdai, io); |
| 486 | |
| 487 | return ret; |
| 488 | } |
| 489 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 490 | static int rsnd_src_probe_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 491 | struct rsnd_dai *rdai) |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 492 | { |
| 493 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 494 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 495 | struct device *dev = rsnd_priv_to_dev(priv); |
| 496 | int ret; |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 497 | |
| 498 | ret = rsnd_dma_init(priv, |
| 499 | rsnd_mod_to_dma(mod), |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 500 | rsnd_info_is_playback(priv, src), |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 501 | src->info->dma_id); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 502 | if (ret < 0) |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 503 | dev_err(dev, "SRC DMA failed\n"); |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 504 | |
| 505 | return ret; |
| 506 | } |
| 507 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 508 | static int rsnd_src_remove_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 509 | struct rsnd_dai *rdai) |
Kuninori Morimoto | 76c6fb5 | 2014-03-03 20:50:41 -0800 | [diff] [blame] | 510 | { |
| 511 | rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod)); |
| 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 516 | static int rsnd_src_init_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 517 | struct rsnd_dai *rdai) |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 518 | { |
| 519 | int ret; |
| 520 | |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 521 | ret = rsnd_src_init(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_rate_gen2(mod, rdai); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 526 | if (ret < 0) |
| 527 | return ret; |
| 528 | |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 529 | ret = rsnd_src_set_convert_timing_gen2(mod, rdai); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 530 | if (ret < 0) |
| 531 | return ret; |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 536 | static int rsnd_src_start_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 537 | struct rsnd_dai *rdai) |
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 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 540 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 541 | rsnd_dma_start(rsnd_mod_to_dma(&src->mod)); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 542 | |
| 543 | rsnd_mod_write(mod, SSI_CTRL, 0x1); |
| 544 | rsnd_mod_write(mod, SRC_CTRL, 0x11); |
| 545 | |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 546 | return rsnd_src_start(mod, rdai); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 549 | static int rsnd_src_stop_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 550 | struct rsnd_dai *rdai) |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 551 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 552 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 553 | |
| 554 | rsnd_mod_write(mod, SSI_CTRL, 0); |
| 555 | rsnd_mod_write(mod, SRC_CTRL, 0); |
| 556 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 557 | rsnd_dma_stop(rsnd_mod_to_dma(&src->mod)); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 558 | |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame^] | 559 | return rsnd_src_stop(mod, rdai); |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 562 | static struct rsnd_mod_ops rsnd_src_gen2_ops = { |
| 563 | .name = "src (gen2)", |
| 564 | .probe = rsnd_src_probe_gen2, |
| 565 | .remove = rsnd_src_remove_gen2, |
| 566 | .init = rsnd_src_init_gen2, |
| 567 | .quit = rsnd_src_quit, |
| 568 | .start = rsnd_src_start_gen2, |
| 569 | .stop = rsnd_src_stop_gen2, |
Kuninori Morimoto | 629509c | 2014-01-23 18:42:00 -0800 | [diff] [blame] | 570 | }; |
| 571 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 572 | 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] | 573 | { |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 574 | if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) |
Takashi Iwai | 8b14719 | 2013-11-05 18:40:05 +0100 | [diff] [blame] | 575 | id = 0; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 576 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 577 | return &((struct rsnd_src *)(priv->src) + id)->mod; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 580 | static void rsnd_of_parse_src(struct platform_device *pdev, |
| 581 | const struct rsnd_of_data *of_data, |
| 582 | struct rsnd_priv *priv) |
| 583 | { |
| 584 | struct device_node *src_node; |
| 585 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
| 586 | struct rsnd_src_platform_info *src_info; |
| 587 | struct device *dev = &pdev->dev; |
| 588 | int nr; |
| 589 | |
| 590 | if (!of_data) |
| 591 | return; |
| 592 | |
| 593 | src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src"); |
| 594 | if (!src_node) |
| 595 | return; |
| 596 | |
| 597 | nr = of_get_child_count(src_node); |
| 598 | if (!nr) |
| 599 | return; |
| 600 | |
| 601 | src_info = devm_kzalloc(dev, |
| 602 | sizeof(struct rsnd_src_platform_info) * nr, |
| 603 | GFP_KERNEL); |
| 604 | if (!src_info) { |
| 605 | dev_err(dev, "src info allocation error\n"); |
| 606 | return; |
| 607 | } |
| 608 | |
| 609 | info->src_info = src_info; |
| 610 | info->src_info_nr = nr; |
| 611 | } |
| 612 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 613 | int rsnd_src_probe(struct platform_device *pdev, |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 614 | const struct rsnd_of_data *of_data, |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 615 | struct rsnd_priv *priv) |
| 616 | { |
Kuninori Morimoto | 5da39cf | 2014-02-24 22:15:00 -0800 | [diff] [blame] | 617 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 618 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 619 | struct rsnd_src *src; |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 620 | struct rsnd_mod_ops *ops; |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 621 | struct clk *clk; |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 622 | char name[RSND_SRC_NAME_SIZE]; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 623 | int i, nr; |
| 624 | |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 625 | rsnd_of_parse_src(pdev, of_data, priv); |
| 626 | |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 627 | /* |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 628 | * init SRC |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 629 | */ |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 630 | nr = info->src_info_nr; |
Kuninori Morimoto | 389933d | 2014-03-03 20:50:00 -0800 | [diff] [blame] | 631 | if (!nr) |
| 632 | return 0; |
| 633 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 634 | src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); |
| 635 | if (!src) { |
| 636 | dev_err(dev, "SRC allocate failed\n"); |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 637 | return -ENOMEM; |
| 638 | } |
| 639 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 640 | priv->src_nr = nr; |
| 641 | priv->src = src; |
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 | for_each_rsnd_src(src, priv, i) { |
| 644 | snprintf(name, RSND_SRC_NAME_SIZE, "src.%d", i); |
Kuninori Morimoto | ef74940 | 2013-12-19 19:28:51 -0800 | [diff] [blame] | 645 | |
| 646 | clk = devm_clk_get(dev, name); |
| 647 | if (IS_ERR(clk)) |
| 648 | return PTR_ERR(clk); |
| 649 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 650 | src->info = &info->src_info[i]; |
| 651 | src->clk = clk; |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 652 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 653 | ops = &rsnd_src_non_ops; |
Kuninori Morimoto | 29e69fd | 2014-05-08 01:59:26 -0700 | [diff] [blame] | 654 | if (rsnd_is_gen1(priv)) |
| 655 | ops = &rsnd_src_gen1_ops; |
| 656 | if (rsnd_is_gen2(priv)) |
| 657 | ops = &rsnd_src_gen2_ops; |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 658 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 659 | rsnd_mod_init(priv, &src->mod, ops, RSND_MOD_SRC, i); |
Kuninori Morimoto | 013f38f | 2014-01-23 18:38:26 -0800 | [diff] [blame] | 660 | |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 661 | dev_dbg(dev, "SRC%d probed\n", i); |
Kuninori Morimoto | 374a5281 | 2013-07-28 18:59:12 -0700 | [diff] [blame] | 662 | } |
Kuninori Morimoto | 07539c1 | 2013-07-21 21:36:35 -0700 | [diff] [blame] | 663 | |
| 664 | return 0; |
| 665 | } |