Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Renesas R-Car SSIU/SSI support |
| 3 | * |
| 4 | * Copyright (C) 2013 Renesas Solutions Corp. |
| 5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * Based on fsi.c |
| 8 | * Kuninori Morimoto <morimoto.kuninori@renesas.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | #include <linux/delay.h> |
| 15 | #include "rsnd.h" |
| 16 | #define RSND_SSI_NAME_SIZE 16 |
| 17 | |
| 18 | /* |
| 19 | * SSICR |
| 20 | */ |
| 21 | #define FORCE (1 << 31) /* Fixed */ |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 22 | #define DMEN (1 << 28) /* DMA Enable */ |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 23 | #define UIEN (1 << 27) /* Underflow Interrupt Enable */ |
| 24 | #define OIEN (1 << 26) /* Overflow Interrupt Enable */ |
| 25 | #define IIEN (1 << 25) /* Idle Mode Interrupt Enable */ |
| 26 | #define DIEN (1 << 24) /* Data Interrupt Enable */ |
Kuninori Morimoto | 186fadc | 2015-11-30 08:54:03 +0000 | [diff] [blame] | 27 | #define CHNL_4 (1 << 22) /* Channels */ |
| 28 | #define CHNL_6 (2 << 22) /* Channels */ |
| 29 | #define CHNL_8 (3 << 22) /* Channels */ |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 30 | #define DWL_8 (0 << 19) /* Data Word Length */ |
| 31 | #define DWL_16 (1 << 19) /* Data Word Length */ |
| 32 | #define DWL_18 (2 << 19) /* Data Word Length */ |
| 33 | #define DWL_20 (3 << 19) /* Data Word Length */ |
| 34 | #define DWL_22 (4 << 19) /* Data Word Length */ |
| 35 | #define DWL_24 (5 << 19) /* Data Word Length */ |
| 36 | #define DWL_32 (6 << 19) /* Data Word Length */ |
| 37 | |
| 38 | #define SWL_32 (3 << 16) /* R/W System Word Length */ |
| 39 | #define SCKD (1 << 15) /* Serial Bit Clock Direction */ |
| 40 | #define SWSD (1 << 14) /* Serial WS Direction */ |
| 41 | #define SCKP (1 << 13) /* Serial Bit Clock Polarity */ |
| 42 | #define SWSP (1 << 12) /* Serial WS Polarity */ |
| 43 | #define SDTA (1 << 10) /* Serial Data Alignment */ |
Kuninori Morimoto | f46a93b | 2015-11-17 08:28:11 +0000 | [diff] [blame] | 44 | #define PDTA (1 << 9) /* Parallel Data Alignment */ |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 45 | #define DEL (1 << 8) /* Serial Data Delay */ |
| 46 | #define CKDV(v) (v << 4) /* Serial Clock Division Ratio */ |
| 47 | #define TRMD (1 << 1) /* Transmit/Receive Mode Select */ |
| 48 | #define EN (1 << 0) /* SSI Module Enable */ |
| 49 | |
| 50 | /* |
| 51 | * SSISR |
| 52 | */ |
| 53 | #define UIRQ (1 << 27) /* Underflow Error Interrupt Status */ |
| 54 | #define OIRQ (1 << 26) /* Overflow Error Interrupt Status */ |
| 55 | #define IIRQ (1 << 25) /* Idle Mode Interrupt Status */ |
| 56 | #define DIRQ (1 << 24) /* Data Interrupt Status Flag */ |
| 57 | |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 58 | /* |
| 59 | * SSIWSR |
| 60 | */ |
| 61 | #define CONT (1 << 8) /* WS Continue Function */ |
Kuninori Morimoto | 186fadc | 2015-11-30 08:54:03 +0000 | [diff] [blame] | 62 | #define WS_MODE (1 << 0) /* WS Mode */ |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 63 | |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 64 | #define SSI_NAME "ssi" |
| 65 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 66 | struct rsnd_ssi { |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 67 | struct rsnd_mod mod; |
Kuninori Morimoto | 940e947 | 2015-10-26 08:42:25 +0000 | [diff] [blame] | 68 | struct rsnd_mod *dma; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 69 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 70 | u32 flags; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 71 | u32 cr_own; |
| 72 | u32 cr_clk; |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 73 | u32 cr_mode; |
Kuninori Morimoto | 08bada2 | 2015-11-30 08:53:04 +0000 | [diff] [blame] | 74 | u32 wsr; |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 75 | int chan; |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 76 | int rate; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 77 | int err; |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 78 | int irq; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 79 | unsigned int usrcnt; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 82 | /* flags */ |
| 83 | #define RSND_SSI_CLK_PIN_SHARE (1 << 0) |
| 84 | #define RSND_SSI_NO_BUSIF (1 << 1) /* SSI+DMA without BUSIF */ |
| 85 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 86 | #define for_each_rsnd_ssi(pos, priv, i) \ |
| 87 | for (i = 0; \ |
| 88 | (i < rsnd_ssi_nr(priv)) && \ |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 89 | ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \ |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 90 | i++) |
| 91 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 92 | #define rsnd_ssi_get(priv, id) ((struct rsnd_ssi *)(priv->ssi) + id) |
Kuninori Morimoto | 232c00b | 2015-10-26 08:38:26 +0000 | [diff] [blame] | 93 | #define rsnd_ssi_to_dma(mod) ((ssi)->dma) |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 94 | #define rsnd_ssi_nr(priv) ((priv)->ssi_nr) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 95 | #define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod) |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 96 | #define rsnd_ssi_mode_flags(p) ((p)->flags) |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 97 | #define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io)) |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 98 | #define rsnd_ssi_is_multi_slave(ssi, io) ((mod) != rsnd_io_to_mod_ssi(io)) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 99 | |
Kuninori Morimoto | b415b4d | 2015-10-22 03:15:46 +0000 | [diff] [blame] | 100 | int rsnd_ssi_use_busif(struct rsnd_dai_stream *io) |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 101 | { |
Kuninori Morimoto | b415b4d | 2015-10-22 03:15:46 +0000 | [diff] [blame] | 102 | struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 103 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 104 | int use_busif = 0; |
| 105 | |
Kuninori Morimoto | 7b466fc | 2014-11-27 08:05:54 +0000 | [diff] [blame] | 106 | if (!rsnd_ssi_is_dma_mode(mod)) |
| 107 | return 0; |
| 108 | |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 109 | if (!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_NO_BUSIF)) |
| 110 | use_busif = 1; |
| 111 | if (rsnd_io_to_mod_src(io)) |
| 112 | use_busif = 1; |
| 113 | |
| 114 | return use_busif; |
| 115 | } |
| 116 | |
Kuninori Morimoto | e10369d | 2015-10-26 08:42:09 +0000 | [diff] [blame] | 117 | static void rsnd_ssi_status_clear(struct rsnd_mod *mod) |
| 118 | { |
| 119 | rsnd_mod_write(mod, SSISR, 0); |
| 120 | } |
| 121 | |
| 122 | static u32 rsnd_ssi_status_get(struct rsnd_mod *mod) |
| 123 | { |
| 124 | return rsnd_mod_read(mod, SSISR); |
| 125 | } |
| 126 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 127 | static void rsnd_ssi_status_check(struct rsnd_mod *mod, |
| 128 | u32 bit) |
| 129 | { |
| 130 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 131 | struct device *dev = rsnd_priv_to_dev(priv); |
| 132 | u32 status; |
| 133 | int i; |
| 134 | |
| 135 | for (i = 0; i < 1024; i++) { |
Kuninori Morimoto | e10369d | 2015-10-26 08:42:09 +0000 | [diff] [blame] | 136 | status = rsnd_ssi_status_get(mod); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 137 | if (status & bit) |
| 138 | return; |
| 139 | |
| 140 | udelay(50); |
| 141 | } |
| 142 | |
| 143 | dev_warn(dev, "status check failed\n"); |
| 144 | } |
| 145 | |
Kuninori Morimoto | 37447b4 | 2015-10-26 08:40:41 +0000 | [diff] [blame] | 146 | static int rsnd_ssi_irq_enable(struct rsnd_mod *ssi_mod) |
| 147 | { |
| 148 | struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); |
| 149 | |
| 150 | if (rsnd_is_gen1(priv)) |
| 151 | return 0; |
| 152 | |
| 153 | /* enable SSI interrupt if Gen2 */ |
| 154 | rsnd_mod_write(ssi_mod, SSI_INT_ENABLE, |
| 155 | rsnd_ssi_is_dma_mode(ssi_mod) ? |
| 156 | 0x0e000000 : 0x0f000000); |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | static int rsnd_ssi_irq_disable(struct rsnd_mod *ssi_mod) |
| 162 | { |
| 163 | struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); |
| 164 | |
| 165 | if (rsnd_is_gen1(priv)) |
| 166 | return 0; |
| 167 | |
| 168 | /* disable SSI interrupt if Gen2 */ |
| 169 | rsnd_mod_write(ssi_mod, SSI_INT_ENABLE, 0x00000000); |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 174 | u32 rsnd_ssi_multi_slaves(struct rsnd_dai_stream *io) |
| 175 | { |
| 176 | struct rsnd_mod *mod; |
| 177 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 178 | struct rsnd_priv *priv = rsnd_io_to_priv(io); |
| 179 | struct device *dev = rsnd_priv_to_dev(priv); |
| 180 | enum rsnd_mod_type types[] = { |
| 181 | RSND_MOD_SSIM1, |
| 182 | RSND_MOD_SSIM2, |
| 183 | RSND_MOD_SSIM3, |
| 184 | }; |
| 185 | int i, mask; |
| 186 | |
| 187 | switch (runtime->channels) { |
| 188 | case 2: /* Multi channel is not needed for Stereo */ |
| 189 | return 0; |
| 190 | case 6: |
| 191 | break; |
| 192 | default: |
| 193 | dev_err(dev, "unsupported channel\n"); |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | mask = 0; |
| 198 | for (i = 0; i < ARRAY_SIZE(types); i++) { |
| 199 | mod = rsnd_io_to_mod(io, types[i]); |
| 200 | if (!mod) |
| 201 | continue; |
| 202 | |
| 203 | mask |= 1 << rsnd_mod_id(mod); |
| 204 | } |
| 205 | |
| 206 | return mask; |
| 207 | } |
| 208 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 209 | static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi, |
Kuninori Morimoto | adcf7d5 | 2013-12-19 19:28:39 -0800 | [diff] [blame] | 210 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 211 | { |
Kuninori Morimoto | 1b13d118 | 2015-01-15 08:08:34 +0000 | [diff] [blame] | 212 | struct rsnd_priv *priv = rsnd_io_to_priv(io); |
Kuninori Morimoto | adcf7d5 | 2013-12-19 19:28:39 -0800 | [diff] [blame] | 213 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 214 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 215 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
Kuninori Morimoto | b76e218 | 2015-09-10 07:02:21 +0000 | [diff] [blame] | 216 | struct rsnd_mod *mod = rsnd_mod_get(ssi); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 217 | struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io); |
Kuninori Morimoto | c140284 | 2015-12-17 02:57:27 +0000 | [diff] [blame] | 218 | int slots = rsnd_get_slot_width(io); |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 219 | int j, ret; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 220 | int ssi_clk_mul_table[] = { |
| 221 | 1, 2, 4, 8, 16, 6, 12, |
| 222 | }; |
| 223 | unsigned int main_rate; |
Kuninori Morimoto | ba9c949 | 2014-03-03 20:51:21 -0800 | [diff] [blame] | 224 | unsigned int rate = rsnd_src_get_ssi_rate(priv, io, runtime); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 225 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 226 | if (!rsnd_rdai_is_clk_master(rdai)) |
| 227 | return 0; |
| 228 | |
| 229 | if (ssi_parent_mod && !rsnd_ssi_is_parent(mod, io)) |
| 230 | return 0; |
| 231 | |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 232 | if (rsnd_ssi_is_multi_slave(mod, io)) |
| 233 | return 0; |
| 234 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 235 | if (ssi->usrcnt > 1) { |
| 236 | if (ssi->rate != rate) { |
| 237 | dev_err(dev, "SSI parent/child should use same rate\n"); |
| 238 | return -EINVAL; |
| 239 | } |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 244 | /* |
| 245 | * Find best clock, and try to start ADG |
| 246 | */ |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 247 | for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) { |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 248 | |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 249 | /* |
| 250 | * this driver is assuming that |
Kuninori Morimoto | 8ec85e7 | 2015-11-30 08:53:27 +0000 | [diff] [blame] | 251 | * system word is 32bit x slots |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 252 | * see rsnd_ssi_init() |
| 253 | */ |
Kuninori Morimoto | 8ec85e7 | 2015-11-30 08:53:27 +0000 | [diff] [blame] | 254 | main_rate = rate * 32 * slots * ssi_clk_mul_table[j]; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 255 | |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 256 | ret = rsnd_adg_ssi_clk_try_start(mod, main_rate); |
| 257 | if (0 == ret) { |
| 258 | ssi->cr_clk = FORCE | SWL_32 | |
| 259 | SCKD | SWSD | CKDV(j); |
Kuninori Morimoto | 08bada2 | 2015-11-30 08:53:04 +0000 | [diff] [blame] | 260 | ssi->wsr = CONT; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 261 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 262 | ssi->rate = rate; |
| 263 | |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 264 | dev_dbg(dev, "%s[%d] outputs %u Hz\n", |
| 265 | rsnd_mod_name(mod), |
| 266 | rsnd_mod_id(mod), rate); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 267 | |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 268 | return 0; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
| 272 | dev_err(dev, "unsupported clock rate\n"); |
| 273 | return -EIO; |
| 274 | } |
| 275 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 276 | static void rsnd_ssi_master_clk_stop(struct rsnd_ssi *ssi, |
| 277 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 278 | { |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 279 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
Kuninori Morimoto | b76e218 | 2015-09-10 07:02:21 +0000 | [diff] [blame] | 280 | struct rsnd_mod *mod = rsnd_mod_get(ssi); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 281 | struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 282 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 283 | if (!rsnd_rdai_is_clk_master(rdai)) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 284 | return; |
| 285 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 286 | if (ssi_parent_mod && !rsnd_ssi_is_parent(mod, io)) |
| 287 | return; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 288 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 289 | if (ssi->usrcnt > 1) |
| 290 | return; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 291 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 292 | ssi->cr_clk = 0; |
| 293 | ssi->rate = 0; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 294 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 295 | rsnd_adg_ssi_clk_stop(mod); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 298 | static int rsnd_ssi_config_init(struct rsnd_ssi *ssi, |
| 299 | struct rsnd_dai_stream *io) |
| 300 | { |
| 301 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
| 302 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 303 | u32 cr_own; |
| 304 | u32 cr_mode; |
Kuninori Morimoto | 186fadc | 2015-11-30 08:54:03 +0000 | [diff] [blame] | 305 | u32 wsr; |
Kuninori Morimoto | f98ed11 | 2015-12-02 07:34:28 +0000 | [diff] [blame] | 306 | int is_tdm; |
| 307 | |
Kuninori Morimoto | c140284 | 2015-12-17 02:57:27 +0000 | [diff] [blame] | 308 | is_tdm = (rsnd_get_slot_width(io) >= 6) ? 1 : 0; |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 309 | |
| 310 | /* |
| 311 | * always use 32bit system word. |
| 312 | * see also rsnd_ssi_master_clk_enable() |
| 313 | */ |
| 314 | cr_own = FORCE | SWL_32 | PDTA; |
| 315 | |
| 316 | if (rdai->bit_clk_inv) |
| 317 | cr_own |= SCKP; |
Kuninori Morimoto | f98ed11 | 2015-12-02 07:34:28 +0000 | [diff] [blame] | 318 | if (rdai->frm_clk_inv ^ is_tdm) |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 319 | cr_own |= SWSP; |
| 320 | if (rdai->data_alignment) |
| 321 | cr_own |= SDTA; |
| 322 | if (rdai->sys_delay) |
| 323 | cr_own |= DEL; |
| 324 | if (rsnd_io_is_play(io)) |
| 325 | cr_own |= TRMD; |
| 326 | |
| 327 | switch (runtime->sample_bits) { |
| 328 | case 16: |
| 329 | cr_own |= DWL_16; |
| 330 | break; |
| 331 | case 32: |
| 332 | cr_own |= DWL_24; |
| 333 | break; |
| 334 | default: |
| 335 | return -EINVAL; |
| 336 | } |
| 337 | |
| 338 | if (rsnd_ssi_is_dma_mode(rsnd_mod_get(ssi))) { |
| 339 | cr_mode = UIEN | OIEN | /* over/under run */ |
| 340 | DMEN; /* DMA : enable DMA */ |
| 341 | } else { |
| 342 | cr_mode = DIEN; /* PIO : enable Data interrupt */ |
| 343 | } |
| 344 | |
Kuninori Morimoto | 186fadc | 2015-11-30 08:54:03 +0000 | [diff] [blame] | 345 | /* |
| 346 | * TDM Extend Mode |
| 347 | * see |
| 348 | * rsnd_ssiu_init_gen2() |
| 349 | */ |
| 350 | wsr = ssi->wsr; |
Kuninori Morimoto | f98ed11 | 2015-12-02 07:34:28 +0000 | [diff] [blame] | 351 | if (is_tdm) { |
Kuninori Morimoto | 186fadc | 2015-11-30 08:54:03 +0000 | [diff] [blame] | 352 | wsr |= WS_MODE; |
| 353 | cr_own |= CHNL_8; |
| 354 | } |
| 355 | |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 356 | ssi->cr_own = cr_own; |
| 357 | ssi->cr_mode = cr_mode; |
Kuninori Morimoto | 186fadc | 2015-11-30 08:54:03 +0000 | [diff] [blame] | 358 | ssi->wsr = wsr; |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 363 | /* |
| 364 | * SSI mod common functions |
| 365 | */ |
| 366 | static int rsnd_ssi_init(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 367 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 368 | struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 369 | { |
| 370 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 371 | int ret; |
| 372 | |
| 373 | ssi->usrcnt++; |
| 374 | |
| 375 | rsnd_mod_power_on(mod); |
| 376 | |
| 377 | ret = rsnd_ssi_master_clk_start(ssi, io); |
| 378 | if (ret < 0) |
| 379 | return ret; |
| 380 | |
| 381 | if (rsnd_ssi_is_parent(mod, io)) |
| 382 | return 0; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 383 | |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 384 | ret = rsnd_ssi_config_init(ssi, io); |
| 385 | if (ret < 0) |
| 386 | return ret; |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 387 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 388 | ssi->err = -1; /* ignore 1st error */ |
| 389 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 390 | /* clear error status */ |
| 391 | rsnd_ssi_status_clear(mod); |
| 392 | |
| 393 | rsnd_ssi_irq_enable(mod); |
| 394 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | static int rsnd_ssi_quit(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 399 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 400 | struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 401 | { |
| 402 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 403 | struct device *dev = rsnd_priv_to_dev(priv); |
| 404 | |
Andrzej Hajda | e5d9cfc | 2015-12-24 08:02:39 +0100 | [diff] [blame] | 405 | if (!ssi->usrcnt) { |
| 406 | dev_err(dev, "%s[%d] usrcnt error\n", |
| 407 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
| 408 | return -EIO; |
| 409 | } |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 410 | |
Andrzej Hajda | e5d9cfc | 2015-12-24 08:02:39 +0100 | [diff] [blame] | 411 | if (!rsnd_ssi_is_parent(mod, io)) { |
| 412 | if (ssi->err > 0) |
| 413 | dev_warn(dev, "%s[%d] under/over flow err = %d\n", |
| 414 | rsnd_mod_name(mod), rsnd_mod_id(mod), |
| 415 | ssi->err); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 416 | |
Andrzej Hajda | e5d9cfc | 2015-12-24 08:02:39 +0100 | [diff] [blame] | 417 | ssi->cr_own = 0; |
| 418 | ssi->err = 0; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 419 | |
Andrzej Hajda | e5d9cfc | 2015-12-24 08:02:39 +0100 | [diff] [blame] | 420 | rsnd_ssi_irq_disable(mod); |
| 421 | } |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 422 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 423 | rsnd_ssi_master_clk_stop(ssi, io); |
| 424 | |
| 425 | rsnd_mod_power_off(mod); |
| 426 | |
| 427 | ssi->usrcnt--; |
| 428 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 429 | return 0; |
| 430 | } |
| 431 | |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 432 | static int rsnd_ssi_hw_params(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 433 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 434 | struct snd_pcm_substream *substream, |
| 435 | struct snd_pcm_hw_params *params) |
| 436 | { |
| 437 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 438 | int chan = params_channels(params); |
| 439 | |
| 440 | /* |
| 441 | * Already working. |
| 442 | * It will happen if SSI has parent/child connection. |
| 443 | */ |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 444 | if (ssi->usrcnt > 1) { |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 445 | /* |
| 446 | * it is error if child <-> parent SSI uses |
| 447 | * different channels. |
| 448 | */ |
| 449 | if (ssi->chan != chan) |
| 450 | return -EIO; |
| 451 | } |
| 452 | |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 453 | ssi->chan = chan; |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
Kuninori Morimoto | e10369d | 2015-10-26 08:42:09 +0000 | [diff] [blame] | 458 | static u32 rsnd_ssi_record_error(struct rsnd_ssi *ssi) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 459 | { |
Kuninori Morimoto | b76e218 | 2015-09-10 07:02:21 +0000 | [diff] [blame] | 460 | struct rsnd_mod *mod = rsnd_mod_get(ssi); |
Kuninori Morimoto | e10369d | 2015-10-26 08:42:09 +0000 | [diff] [blame] | 461 | u32 status = rsnd_ssi_status_get(mod); |
Kuninori Morimoto | b76e218 | 2015-09-10 07:02:21 +0000 | [diff] [blame] | 462 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 463 | /* under/over flow error */ |
Kuninori Morimoto | 5342dff | 2015-11-26 11:13:40 +0000 | [diff] [blame] | 464 | if (status & (UIRQ | OIRQ)) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 465 | ssi->err++; |
| 466 | |
Kuninori Morimoto | e10369d | 2015-10-26 08:42:09 +0000 | [diff] [blame] | 467 | return status; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 470 | static int __rsnd_ssi_start(struct rsnd_mod *mod, |
| 471 | struct rsnd_dai_stream *io, |
| 472 | struct rsnd_priv *priv) |
| 473 | { |
| 474 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
| 475 | u32 cr; |
| 476 | |
| 477 | cr = ssi->cr_own | |
| 478 | ssi->cr_clk | |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 479 | ssi->cr_mode; |
| 480 | |
| 481 | /* |
| 482 | * EN will be set via SSIU :: SSI_CONTROL |
| 483 | * if Multi channel mode |
| 484 | */ |
| 485 | if (!rsnd_ssi_multi_slaves(io)) |
| 486 | cr |= EN; |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 487 | |
| 488 | rsnd_mod_write(mod, SSICR, cr); |
Kuninori Morimoto | 08bada2 | 2015-11-30 08:53:04 +0000 | [diff] [blame] | 489 | rsnd_mod_write(mod, SSIWSR, ssi->wsr); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
Kuninori Morimoto | 4922985 | 2014-11-27 08:07:17 +0000 | [diff] [blame] | 494 | static int rsnd_ssi_start(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 495 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 496 | struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 497 | { |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 498 | /* |
| 499 | * no limit to start |
| 500 | * see also |
| 501 | * rsnd_ssi_stop |
| 502 | * rsnd_ssi_interrupt |
| 503 | */ |
| 504 | return __rsnd_ssi_start(mod, io, priv); |
| 505 | } |
| 506 | |
| 507 | static int __rsnd_ssi_stop(struct rsnd_mod *mod, |
| 508 | struct rsnd_dai_stream *io, |
| 509 | struct rsnd_priv *priv) |
| 510 | { |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 511 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 512 | u32 cr; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 513 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 514 | /* |
| 515 | * disable all IRQ, |
| 516 | * and, wait all data was sent |
| 517 | */ |
| 518 | cr = ssi->cr_own | |
| 519 | ssi->cr_clk; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 520 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 521 | rsnd_mod_write(mod, SSICR, cr | EN); |
| 522 | rsnd_ssi_status_check(mod, DIRQ); |
| 523 | |
| 524 | /* |
| 525 | * disable SSI, |
| 526 | * and, wait idle state |
| 527 | */ |
| 528 | rsnd_mod_write(mod, SSICR, cr); /* disabled all */ |
| 529 | rsnd_ssi_status_check(mod, IIRQ); |
Kuninori Morimoto | c17dba8 | 2014-11-27 08:05:09 +0000 | [diff] [blame] | 530 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 531 | return 0; |
| 532 | } |
| 533 | |
Kuninori Morimoto | 4922985 | 2014-11-27 08:07:17 +0000 | [diff] [blame] | 534 | static int rsnd_ssi_stop(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 535 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 536 | struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 537 | { |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 538 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
| 539 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 540 | /* |
| 541 | * don't stop if not last user |
| 542 | * see also |
| 543 | * rsnd_ssi_start |
| 544 | * rsnd_ssi_interrupt |
| 545 | */ |
| 546 | if (ssi->usrcnt > 1) |
| 547 | return 0; |
Kuninori Morimoto | c17dba8 | 2014-11-27 08:05:09 +0000 | [diff] [blame] | 548 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 549 | return __rsnd_ssi_stop(mod, io, priv); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Kuninori Morimoto | bfc0cfe | 2015-06-15 06:26:56 +0000 | [diff] [blame] | 552 | static void __rsnd_ssi_interrupt(struct rsnd_mod *mod, |
| 553 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 554 | { |
Kuninori Morimoto | bfc0cfe | 2015-06-15 06:26:56 +0000 | [diff] [blame] | 555 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 556 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 69e32a5 | 2015-10-26 08:41:36 +0000 | [diff] [blame] | 557 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 765ae7c | 2015-01-15 08:09:13 +0000 | [diff] [blame] | 558 | int is_dma = rsnd_ssi_is_dma_mode(mod); |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 559 | u32 status; |
Kuninori Morimoto | 75defee | 2015-06-15 06:21:15 +0000 | [diff] [blame] | 560 | bool elapsed = false; |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 561 | |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 562 | spin_lock(&priv->lock); |
| 563 | |
| 564 | /* ignore all cases if not working */ |
Kuninori Morimoto | d5bbe7d | 2015-06-15 06:27:47 +0000 | [diff] [blame] | 565 | if (!rsnd_io_is_working(io)) |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 566 | goto rsnd_ssi_interrupt_out; |
| 567 | |
Kuninori Morimoto | e10369d | 2015-10-26 08:42:09 +0000 | [diff] [blame] | 568 | status = rsnd_ssi_record_error(ssi); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 569 | |
| 570 | /* PIO only */ |
Kuninori Morimoto | 765ae7c | 2015-01-15 08:09:13 +0000 | [diff] [blame] | 571 | if (!is_dma && (status & DIRQ)) { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 572 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 573 | u32 *buf = (u32 *)(runtime->dma_area + |
| 574 | rsnd_dai_pointer_offset(io, 0)); |
| 575 | |
| 576 | /* |
| 577 | * 8/16/32 data can be assesse to TDR/RDR register |
| 578 | * directly as 32bit data |
| 579 | * see rsnd_ssi_init() |
| 580 | */ |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 581 | if (rsnd_io_is_play(io)) |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 582 | rsnd_mod_write(mod, SSITDR, *buf); |
| 583 | else |
| 584 | *buf = rsnd_mod_read(mod, SSIRDR); |
| 585 | |
Kuninori Morimoto | 75defee | 2015-06-15 06:21:15 +0000 | [diff] [blame] | 586 | elapsed = rsnd_dai_pointer_update(io, sizeof(*buf)); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Kuninori Morimoto | 12927a8 | 2015-06-15 06:20:54 +0000 | [diff] [blame] | 589 | /* DMA only */ |
| 590 | if (is_dma && (status & (UIRQ | OIRQ))) { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 591 | /* |
| 592 | * restart SSI |
| 593 | */ |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 594 | dev_dbg(dev, "%s[%d] restart\n", |
| 595 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
Kuninori Morimoto | 044930b | 2015-03-19 04:13:47 +0000 | [diff] [blame] | 596 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 597 | __rsnd_ssi_stop(mod, io, priv); |
| 598 | __rsnd_ssi_start(mod, io, priv); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Kuninori Morimoto | 69e32a5 | 2015-10-26 08:41:36 +0000 | [diff] [blame] | 601 | if (ssi->err > 1024) { |
| 602 | rsnd_ssi_irq_disable(mod); |
| 603 | |
| 604 | dev_warn(dev, "no more %s[%d] restart\n", |
| 605 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
| 606 | } |
| 607 | |
Kuninori Morimoto | 5342dff | 2015-11-26 11:13:40 +0000 | [diff] [blame] | 608 | rsnd_ssi_status_clear(mod); |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 609 | rsnd_ssi_interrupt_out: |
| 610 | spin_unlock(&priv->lock); |
| 611 | |
Kuninori Morimoto | 75defee | 2015-06-15 06:21:15 +0000 | [diff] [blame] | 612 | if (elapsed) |
| 613 | rsnd_dai_period_elapsed(io); |
Kuninori Morimoto | bfc0cfe | 2015-06-15 06:26:56 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) |
| 617 | { |
| 618 | struct rsnd_mod *mod = data; |
| 619 | |
| 620 | rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt); |
Kuninori Morimoto | 75defee | 2015-06-15 06:21:15 +0000 | [diff] [blame] | 621 | |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 622 | return IRQ_HANDLED; |
| 623 | } |
| 624 | |
Kuninori Morimoto | 6cfad78 | 2014-11-27 08:08:10 +0000 | [diff] [blame] | 625 | /* |
| 626 | * SSI PIO |
| 627 | */ |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 628 | static void rsnd_ssi_parent_attach(struct rsnd_mod *mod, |
| 629 | struct rsnd_dai_stream *io, |
| 630 | struct rsnd_priv *priv) |
| 631 | { |
| 632 | if (!__rsnd_ssi_is_pin_sharing(mod)) |
| 633 | return; |
| 634 | |
| 635 | switch (rsnd_mod_id(mod)) { |
| 636 | case 1: |
| 637 | case 2: |
| 638 | rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP); |
| 639 | break; |
| 640 | case 4: |
| 641 | rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP); |
| 642 | break; |
| 643 | case 8: |
| 644 | rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP); |
| 645 | break; |
| 646 | } |
| 647 | } |
| 648 | |
Kuninori Morimoto | c7f69ab | 2015-10-26 08:43:41 +0000 | [diff] [blame] | 649 | static int rsnd_ssi_common_probe(struct rsnd_mod *mod, |
| 650 | struct rsnd_dai_stream *io, |
| 651 | struct rsnd_priv *priv) |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 652 | { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 653 | struct device *dev = rsnd_priv_to_dev(priv); |
| 654 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 655 | int ret; |
| 656 | |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 657 | /* |
| 658 | * SSIP/SSIU/IRQ are not needed on |
| 659 | * SSI Multi slaves |
| 660 | */ |
| 661 | if (rsnd_ssi_is_multi_slave(mod, io)) |
| 662 | return 0; |
| 663 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 664 | rsnd_ssi_parent_attach(mod, io, priv); |
| 665 | |
Kuninori Morimoto | c7f69ab | 2015-10-26 08:43:41 +0000 | [diff] [blame] | 666 | ret = rsnd_ssiu_attach(io, mod); |
| 667 | if (ret < 0) |
| 668 | return ret; |
| 669 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 670 | ret = devm_request_irq(dev, ssi->irq, |
Kuninori Morimoto | 6cfad78 | 2014-11-27 08:08:10 +0000 | [diff] [blame] | 671 | rsnd_ssi_interrupt, |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 672 | IRQF_SHARED, |
Kuninori Morimoto | bfc0cfe | 2015-06-15 06:26:56 +0000 | [diff] [blame] | 673 | dev_name(dev), mod); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 674 | |
| 675 | return ret; |
| 676 | } |
| 677 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 678 | static struct rsnd_mod_ops rsnd_ssi_pio_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 679 | .name = SSI_NAME, |
Kuninori Morimoto | c7f69ab | 2015-10-26 08:43:41 +0000 | [diff] [blame] | 680 | .probe = rsnd_ssi_common_probe, |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 681 | .init = rsnd_ssi_init, |
| 682 | .quit = rsnd_ssi_quit, |
Kuninori Morimoto | 4922985 | 2014-11-27 08:07:17 +0000 | [diff] [blame] | 683 | .start = rsnd_ssi_start, |
| 684 | .stop = rsnd_ssi_stop, |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 685 | .hw_params = rsnd_ssi_hw_params, |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 686 | }; |
| 687 | |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 688 | static int rsnd_ssi_dma_probe(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 689 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 690 | struct rsnd_priv *priv) |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 691 | { |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 692 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 693 | int dma_id = 0; /* not needed */ |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 694 | int ret; |
| 695 | |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 696 | /* |
| 697 | * SSIP/SSIU/IRQ/DMA are not needed on |
| 698 | * SSI Multi slaves |
| 699 | */ |
| 700 | if (rsnd_ssi_is_multi_slave(mod, io)) |
| 701 | return 0; |
| 702 | |
Kuninori Morimoto | c7f69ab | 2015-10-26 08:43:41 +0000 | [diff] [blame] | 703 | ret = rsnd_ssi_common_probe(mod, io, priv); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 704 | if (ret) |
Kuninori Morimoto | b543b52 | 2015-03-26 04:02:32 +0000 | [diff] [blame] | 705 | return ret; |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 706 | |
Kuninori Morimoto | 355cb84fb | 2016-01-21 01:58:33 +0000 | [diff] [blame] | 707 | /* SSI probe might be called many times in MUX multi path */ |
| 708 | ret = rsnd_dma_attach(io, mod, &ssi->dma, dma_id); |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 709 | |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 710 | return ret; |
| 711 | } |
| 712 | |
| 713 | static int rsnd_ssi_dma_remove(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 714 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 715 | struct rsnd_priv *priv) |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 716 | { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 717 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
| 718 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 719 | int irq = ssi->irq; |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 720 | |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 721 | /* PIO will request IRQ again */ |
Kuninori Morimoto | b05ce4c | 2015-10-22 03:13:44 +0000 | [diff] [blame] | 722 | devm_free_irq(dev, irq, mod); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 723 | |
Kuninori Morimoto | 97463e1 | 2014-11-27 08:02:43 +0000 | [diff] [blame] | 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | static int rsnd_ssi_fallback(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 728 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 729 | struct rsnd_priv *priv) |
Kuninori Morimoto | 97463e1 | 2014-11-27 08:02:43 +0000 | [diff] [blame] | 730 | { |
Kuninori Morimoto | d3a7682 | 2014-11-09 20:00:58 -0800 | [diff] [blame] | 731 | struct device *dev = rsnd_priv_to_dev(priv); |
| 732 | |
Kuninori Morimoto | d3a7682 | 2014-11-09 20:00:58 -0800 | [diff] [blame] | 733 | /* |
| 734 | * fallback to PIO |
| 735 | * |
| 736 | * SSI .probe might be called again. |
| 737 | * see |
| 738 | * rsnd_rdai_continuance_probe() |
| 739 | */ |
| 740 | mod->ops = &rsnd_ssi_pio_ops; |
| 741 | |
| 742 | dev_info(dev, "%s[%d] fallback to PIO mode\n", |
| 743 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
| 744 | |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 745 | return 0; |
| 746 | } |
| 747 | |
Kuninori Morimoto | 9b99e9a | 2015-06-15 06:26:25 +0000 | [diff] [blame] | 748 | static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io, |
| 749 | struct rsnd_mod *mod) |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 750 | { |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 751 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 752 | int is_play = rsnd_io_is_play(io); |
| 753 | char *name; |
| 754 | |
Kuninori Morimoto | b415b4d | 2015-10-22 03:15:46 +0000 | [diff] [blame] | 755 | if (rsnd_ssi_use_busif(io)) |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 756 | name = is_play ? "rxu" : "txu"; |
| 757 | else |
| 758 | name = is_play ? "rx" : "tx"; |
| 759 | |
| 760 | return rsnd_dma_request_channel(rsnd_ssi_of_node(priv), |
| 761 | mod, name); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 764 | static struct rsnd_mod_ops rsnd_ssi_dma_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 765 | .name = SSI_NAME, |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 766 | .dma_req = rsnd_ssi_dma_req, |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 767 | .probe = rsnd_ssi_dma_probe, |
| 768 | .remove = rsnd_ssi_dma_remove, |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 769 | .init = rsnd_ssi_init, |
| 770 | .quit = rsnd_ssi_quit, |
Kuninori Morimoto | 497deba | 2015-10-26 08:43:01 +0000 | [diff] [blame] | 771 | .start = rsnd_ssi_start, |
| 772 | .stop = rsnd_ssi_stop, |
Kuninori Morimoto | 97463e1 | 2014-11-27 08:02:43 +0000 | [diff] [blame] | 773 | .fallback = rsnd_ssi_fallback, |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 774 | .hw_params = rsnd_ssi_hw_params, |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 775 | }; |
| 776 | |
Kuninori Morimoto | 0579541 | 2014-11-27 08:05:01 +0000 | [diff] [blame] | 777 | int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod) |
| 778 | { |
| 779 | return mod->ops == &rsnd_ssi_dma_ops; |
| 780 | } |
| 781 | |
| 782 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 783 | /* |
| 784 | * Non SSI |
| 785 | */ |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 786 | static struct rsnd_mod_ops rsnd_ssi_non_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 787 | .name = SSI_NAME, |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 788 | }; |
| 789 | |
| 790 | /* |
| 791 | * ssi mod function |
| 792 | */ |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 793 | static void rsnd_ssi_connect(struct rsnd_mod *mod, |
| 794 | struct rsnd_dai_stream *io) |
| 795 | { |
| 796 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
| 797 | enum rsnd_mod_type types[] = { |
| 798 | RSND_MOD_SSI, |
| 799 | RSND_MOD_SSIM1, |
| 800 | RSND_MOD_SSIM2, |
| 801 | RSND_MOD_SSIM3, |
| 802 | }; |
| 803 | enum rsnd_mod_type type; |
| 804 | int i; |
| 805 | |
| 806 | /* try SSI -> SSIM1 -> SSIM2 -> SSIM3 */ |
| 807 | for (i = 0; i < ARRAY_SIZE(types); i++) { |
| 808 | type = types[i]; |
| 809 | if (!rsnd_io_to_mod(io, type)) { |
| 810 | rsnd_dai_connect(mod, io, type); |
| 811 | rsnd_set_slot(rdai, 2 * (i + 1), (i + 1)); |
| 812 | return; |
| 813 | } |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | void rsnd_parse_connect_ssi(struct rsnd_dai *rdai, |
| 818 | struct device_node *playback, |
| 819 | struct device_node *capture) |
| 820 | { |
| 821 | struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai); |
| 822 | struct device_node *node; |
| 823 | struct device_node *np; |
| 824 | struct rsnd_mod *mod; |
| 825 | int i; |
| 826 | |
| 827 | node = rsnd_ssi_of_node(priv); |
| 828 | if (!node) |
| 829 | return; |
| 830 | |
| 831 | i = 0; |
| 832 | for_each_child_of_node(node, np) { |
| 833 | mod = rsnd_ssi_mod_get(priv, i); |
| 834 | if (np == playback) |
| 835 | rsnd_ssi_connect(mod, &rdai->playback); |
| 836 | if (np == capture) |
| 837 | rsnd_ssi_connect(mod, &rdai->capture); |
| 838 | i++; |
| 839 | } |
| 840 | |
| 841 | of_node_put(node); |
| 842 | } |
| 843 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 844 | struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id) |
| 845 | { |
Takashi Iwai | 8b14719 | 2013-11-05 18:40:05 +0100 | [diff] [blame] | 846 | if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv))) |
| 847 | id = 0; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 848 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 849 | return rsnd_mod_get(rsnd_ssi_get(priv, id)); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Kuninori Morimoto | b415b4d | 2015-10-22 03:15:46 +0000 | [diff] [blame] | 852 | int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod) |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 853 | { |
| 854 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
| 855 | |
| 856 | return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE); |
| 857 | } |
| 858 | |
Kuninori Morimoto | 5ba17b42 | 2016-01-21 01:58:07 +0000 | [diff] [blame] | 859 | static u32 *rsnd_ssi_get_status(struct rsnd_dai_stream *io, |
| 860 | struct rsnd_mod *mod, |
| 861 | enum rsnd_mod_type type) |
| 862 | { |
| 863 | /* |
| 864 | * SSIP (= SSI parent) needs to be special, otherwise, |
| 865 | * 2nd SSI might doesn't start. see also rsnd_mod_call() |
| 866 | * |
| 867 | * We can't include parent SSI status on SSI, because we don't know |
| 868 | * how many SSI requests parent SSI. Thus, it is localed on "io" now. |
| 869 | * ex) trouble case |
| 870 | * Playback: SSI0 |
| 871 | * Capture : SSI1 (needs SSI0) |
| 872 | * |
| 873 | * 1) start Capture -> SSI0/SSI1 are started. |
| 874 | * 2) start Playback -> SSI0 doesn't work, because it is already |
| 875 | * marked as "started" on 1) |
| 876 | * |
| 877 | * OTOH, using each mod's status is good for MUX case. |
| 878 | * It doesn't need to start in 2nd start |
| 879 | * ex) |
| 880 | * IO-0: SRC0 -> CTU1 -+-> MUX -> DVC -> SSIU -> SSI0 |
| 881 | * | |
| 882 | * IO-1: SRC1 -> CTU2 -+ |
| 883 | * |
| 884 | * 1) start IO-0 -> start SSI0 |
| 885 | * 2) start IO-1 -> SSI0 doesn't need to start, because it is |
| 886 | * already started on 1) |
| 887 | */ |
| 888 | if (type == RSND_MOD_SSIP) |
| 889 | return &io->parent_ssi_status; |
| 890 | |
| 891 | return rsnd_mod_get_status(io, mod, type); |
| 892 | } |
| 893 | |
Kuninori Morimoto | 2ea6b07 | 2015-11-10 05:14:12 +0000 | [diff] [blame] | 894 | int rsnd_ssi_probe(struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 895 | { |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 896 | struct device_node *node; |
| 897 | struct device_node *np; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 898 | struct device *dev = rsnd_priv_to_dev(priv); |
| 899 | struct rsnd_mod_ops *ops; |
| 900 | struct clk *clk; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 901 | struct rsnd_ssi *ssi; |
| 902 | char name[RSND_SSI_NAME_SIZE]; |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 903 | int i, nr, ret; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 904 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 905 | node = rsnd_ssi_of_node(priv); |
| 906 | if (!node) |
| 907 | return -EINVAL; |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 908 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 909 | nr = of_get_child_count(node); |
| 910 | if (!nr) { |
| 911 | ret = -EINVAL; |
| 912 | goto rsnd_ssi_probe_done; |
| 913 | } |
| 914 | |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 915 | ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL); |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 916 | if (!ssi) { |
| 917 | ret = -ENOMEM; |
| 918 | goto rsnd_ssi_probe_done; |
| 919 | } |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 920 | |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 921 | priv->ssi = ssi; |
| 922 | priv->ssi_nr = nr; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 923 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 924 | i = 0; |
| 925 | for_each_child_of_node(node, np) { |
| 926 | ssi = rsnd_ssi_get(priv, i); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 927 | |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 928 | snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d", |
| 929 | SSI_NAME, i); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 930 | |
Kuninori Morimoto | 60dbb4f | 2013-12-03 22:09:33 -0800 | [diff] [blame] | 931 | clk = devm_clk_get(dev, name); |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 932 | if (IS_ERR(clk)) { |
| 933 | ret = PTR_ERR(clk); |
| 934 | goto rsnd_ssi_probe_done; |
| 935 | } |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 936 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 937 | if (of_get_property(np, "shared-pin", NULL)) |
| 938 | ssi->flags |= RSND_SSI_CLK_PIN_SHARE; |
| 939 | |
| 940 | if (of_get_property(np, "no-busif", NULL)) |
| 941 | ssi->flags |= RSND_SSI_NO_BUSIF; |
| 942 | |
| 943 | ssi->irq = irq_of_parse_and_map(np, 0); |
| 944 | if (!ssi->irq) { |
| 945 | ret = -EINVAL; |
| 946 | goto rsnd_ssi_probe_done; |
| 947 | } |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 948 | |
| 949 | ops = &rsnd_ssi_non_ops; |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 950 | if (of_get_property(np, "pio-transfer", NULL)) |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 951 | ops = &rsnd_ssi_pio_ops; |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 952 | else |
| 953 | ops = &rsnd_ssi_dma_ops; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 954 | |
Kuninori Morimoto | b76e218 | 2015-09-10 07:02:21 +0000 | [diff] [blame] | 955 | ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk, |
Kuninori Morimoto | 5ba17b42 | 2016-01-21 01:58:07 +0000 | [diff] [blame] | 956 | rsnd_ssi_get_status, RSND_MOD_SSI, i); |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 957 | if (ret) |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 958 | goto rsnd_ssi_probe_done; |
| 959 | |
| 960 | i++; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 963 | ret = 0; |
| 964 | |
| 965 | rsnd_ssi_probe_done: |
| 966 | of_node_put(node); |
| 967 | |
| 968 | return ret; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 969 | } |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 970 | |
Kuninori Morimoto | 2ea6b07 | 2015-11-10 05:14:12 +0000 | [diff] [blame] | 971 | void rsnd_ssi_remove(struct rsnd_priv *priv) |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 972 | { |
| 973 | struct rsnd_ssi *ssi; |
| 974 | int i; |
| 975 | |
| 976 | for_each_rsnd_ssi(ssi, priv, i) { |
Kuninori Morimoto | b76e218 | 2015-09-10 07:02:21 +0000 | [diff] [blame] | 977 | rsnd_mod_quit(rsnd_mod_get(ssi)); |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 978 | } |
| 979 | } |