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