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 | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 77 | int irq; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 78 | unsigned int usrcnt; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 81 | /* flags */ |
| 82 | #define RSND_SSI_CLK_PIN_SHARE (1 << 0) |
| 83 | #define RSND_SSI_NO_BUSIF (1 << 1) /* SSI+DMA without BUSIF */ |
| 84 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 85 | #define for_each_rsnd_ssi(pos, priv, i) \ |
| 86 | for (i = 0; \ |
| 87 | (i < rsnd_ssi_nr(priv)) && \ |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 88 | ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \ |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 89 | i++) |
| 90 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 91 | #define rsnd_ssi_get(priv, id) ((struct rsnd_ssi *)(priv->ssi) + id) |
Kuninori Morimoto | 232c00b | 2015-10-26 08:38:26 +0000 | [diff] [blame] | 92 | #define rsnd_ssi_to_dma(mod) ((ssi)->dma) |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 93 | #define rsnd_ssi_nr(priv) ((priv)->ssi_nr) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 94 | #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] | 95 | #define rsnd_ssi_mode_flags(p) ((p)->flags) |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 96 | #define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io)) |
Kuninori Morimoto | c308abe | 2016-02-09 07:04:09 +0000 | [diff] [blame] | 97 | #define rsnd_ssi_is_multi_slave(mod, io) \ |
| 98 | (rsnd_ssi_multi_slaves(io) & (1 << rsnd_mod_id(mod))) |
Kuninori Morimoto | fd9adcf | 2016-02-18 08:19:12 +0000 | [diff] [blame] | 99 | #define rsnd_ssi_is_run_mods(mod, io) \ |
| 100 | (rsnd_ssi_run_mods(io) & (1 << rsnd_mod_id(mod))) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 101 | |
Kuninori Morimoto | b415b4d | 2015-10-22 03:15:46 +0000 | [diff] [blame] | 102 | int rsnd_ssi_use_busif(struct rsnd_dai_stream *io) |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 103 | { |
Kuninori Morimoto | b415b4d | 2015-10-22 03:15:46 +0000 | [diff] [blame] | 104 | struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 105 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 106 | int use_busif = 0; |
| 107 | |
Kuninori Morimoto | 7b466fc | 2014-11-27 08:05:54 +0000 | [diff] [blame] | 108 | if (!rsnd_ssi_is_dma_mode(mod)) |
| 109 | return 0; |
| 110 | |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 111 | if (!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_NO_BUSIF)) |
| 112 | use_busif = 1; |
| 113 | if (rsnd_io_to_mod_src(io)) |
| 114 | use_busif = 1; |
| 115 | |
| 116 | return use_busif; |
| 117 | } |
| 118 | |
Kuninori Morimoto | e10369d | 2015-10-26 08:42:09 +0000 | [diff] [blame] | 119 | static void rsnd_ssi_status_clear(struct rsnd_mod *mod) |
| 120 | { |
| 121 | rsnd_mod_write(mod, SSISR, 0); |
| 122 | } |
| 123 | |
| 124 | static u32 rsnd_ssi_status_get(struct rsnd_mod *mod) |
| 125 | { |
| 126 | return rsnd_mod_read(mod, SSISR); |
| 127 | } |
| 128 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 129 | static void rsnd_ssi_status_check(struct rsnd_mod *mod, |
| 130 | u32 bit) |
| 131 | { |
| 132 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 133 | struct device *dev = rsnd_priv_to_dev(priv); |
| 134 | u32 status; |
| 135 | int i; |
| 136 | |
| 137 | for (i = 0; i < 1024; i++) { |
Kuninori Morimoto | e10369d | 2015-10-26 08:42:09 +0000 | [diff] [blame] | 138 | status = rsnd_ssi_status_get(mod); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 139 | if (status & bit) |
| 140 | return; |
| 141 | |
| 142 | udelay(50); |
| 143 | } |
| 144 | |
Kuninori Morimoto | 1120dbf | 2016-02-18 08:14:09 +0000 | [diff] [blame] | 145 | dev_warn(dev, "%s[%d] status check failed\n", |
| 146 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Kuninori Morimoto | 4f5c634 | 2016-02-18 08:18:54 +0000 | [diff] [blame] | 149 | static u32 rsnd_ssi_multi_slaves(struct rsnd_dai_stream *io) |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 150 | { |
| 151 | struct rsnd_mod *mod; |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 152 | enum rsnd_mod_type types[] = { |
| 153 | RSND_MOD_SSIM1, |
| 154 | RSND_MOD_SSIM2, |
| 155 | RSND_MOD_SSIM3, |
| 156 | }; |
| 157 | int i, mask; |
| 158 | |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 159 | mask = 0; |
| 160 | for (i = 0; i < ARRAY_SIZE(types); i++) { |
| 161 | mod = rsnd_io_to_mod(io, types[i]); |
| 162 | if (!mod) |
| 163 | continue; |
| 164 | |
| 165 | mask |= 1 << rsnd_mod_id(mod); |
| 166 | } |
| 167 | |
| 168 | return mask; |
| 169 | } |
| 170 | |
Kuninori Morimoto | fd9adcf | 2016-02-18 08:19:12 +0000 | [diff] [blame] | 171 | static u32 rsnd_ssi_run_mods(struct rsnd_dai_stream *io) |
| 172 | { |
| 173 | struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io); |
| 174 | struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io); |
Kuninori Morimoto | 019433d | 2017-11-01 07:16:58 +0000 | [diff] [blame] | 175 | u32 mods; |
Kuninori Morimoto | fd9adcf | 2016-02-18 08:19:12 +0000 | [diff] [blame] | 176 | |
Kuninori Morimoto | 019433d | 2017-11-01 07:16:58 +0000 | [diff] [blame] | 177 | mods = rsnd_ssi_multi_slaves_runtime(io) | |
| 178 | 1 << rsnd_mod_id(ssi_mod); |
| 179 | |
| 180 | if (ssi_parent_mod) |
| 181 | mods |= 1 << rsnd_mod_id(ssi_parent_mod); |
| 182 | |
| 183 | return mods; |
Kuninori Morimoto | fd9adcf | 2016-02-18 08:19:12 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Kuninori Morimoto | 4f5c634 | 2016-02-18 08:18:54 +0000 | [diff] [blame] | 186 | u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io) |
| 187 | { |
Kuninori Morimoto | eed76bb | 2016-02-25 05:54:58 +0000 | [diff] [blame] | 188 | if (rsnd_runtime_is_ssi_multi(io)) |
| 189 | return rsnd_ssi_multi_slaves(io); |
Kuninori Morimoto | 4f5c634 | 2016-02-18 08:18:54 +0000 | [diff] [blame] | 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
Kuninori Morimoto | 26d34b1 | 2016-02-18 08:14:37 +0000 | [diff] [blame] | 194 | static int rsnd_ssi_master_clk_start(struct rsnd_mod *mod, |
Kuninori Morimoto | adcf7d5 | 2013-12-19 19:28:39 -0800 | [diff] [blame] | 195 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 196 | { |
Kuninori Morimoto | 1b13d118 | 2015-01-15 08:08:34 +0000 | [diff] [blame] | 197 | struct rsnd_priv *priv = rsnd_io_to_priv(io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 198 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 199 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
Kuninori Morimoto | 26d34b1 | 2016-02-18 08:14:37 +0000 | [diff] [blame] | 200 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 201 | struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io); |
Kuninori Morimoto | eed76bb | 2016-02-25 05:54:58 +0000 | [diff] [blame] | 202 | int chan = rsnd_runtime_channel_for_ssi(io); |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 203 | int j, ret; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 204 | int ssi_clk_mul_table[] = { |
| 205 | 1, 2, 4, 8, 16, 6, 12, |
| 206 | }; |
| 207 | unsigned int main_rate; |
Kuninori Morimoto | cbf1494 | 2016-03-07 05:08:33 +0000 | [diff] [blame] | 208 | unsigned int rate = rsnd_io_is_play(io) ? |
| 209 | rsnd_src_get_out_rate(priv, io) : |
| 210 | rsnd_src_get_in_rate(priv, io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 211 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 212 | if (!rsnd_rdai_is_clk_master(rdai)) |
| 213 | return 0; |
| 214 | |
| 215 | if (ssi_parent_mod && !rsnd_ssi_is_parent(mod, io)) |
| 216 | return 0; |
| 217 | |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 218 | if (rsnd_ssi_is_multi_slave(mod, io)) |
| 219 | return 0; |
| 220 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 221 | if (ssi->usrcnt > 1) { |
| 222 | if (ssi->rate != rate) { |
| 223 | dev_err(dev, "SSI parent/child should use same rate\n"); |
| 224 | return -EINVAL; |
| 225 | } |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 230 | /* |
| 231 | * Find best clock, and try to start ADG |
| 232 | */ |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 233 | for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) { |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 234 | |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 235 | /* |
Kuninori Morimoto | 28fdd86 | 2017-03-22 04:02:43 +0000 | [diff] [blame] | 236 | * It will set SSIWSR.CONT here, but SSICR.CKDV = 000 |
| 237 | * with it is not allowed. (SSIWSR.WS_MODE with |
| 238 | * SSICR.CKDV = 000 is not allowed either). |
| 239 | * Skip it. See SSICR.CKDV |
| 240 | */ |
| 241 | if (j == 0) |
| 242 | continue; |
| 243 | |
| 244 | /* |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 245 | * this driver is assuming that |
Kuninori Morimoto | eed76bb | 2016-02-25 05:54:58 +0000 | [diff] [blame] | 246 | * system word is 32bit x chan |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 247 | * see rsnd_ssi_init() |
| 248 | */ |
Kuninori Morimoto | eed76bb | 2016-02-25 05:54:58 +0000 | [diff] [blame] | 249 | main_rate = rate * 32 * chan * ssi_clk_mul_table[j]; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 250 | |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 251 | ret = rsnd_adg_ssi_clk_try_start(mod, main_rate); |
| 252 | if (0 == ret) { |
| 253 | ssi->cr_clk = FORCE | SWL_32 | |
| 254 | SCKD | SWSD | CKDV(j); |
Kuninori Morimoto | 08bada2 | 2015-11-30 08:53:04 +0000 | [diff] [blame] | 255 | ssi->wsr = CONT; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 256 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 257 | ssi->rate = rate; |
| 258 | |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 259 | dev_dbg(dev, "%s[%d] outputs %u Hz\n", |
| 260 | rsnd_mod_name(mod), |
| 261 | rsnd_mod_id(mod), rate); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 262 | |
Kuninori Morimoto | eae6fff | 2015-09-10 07:03:48 +0000 | [diff] [blame] | 263 | return 0; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | dev_err(dev, "unsupported clock rate\n"); |
| 268 | return -EIO; |
| 269 | } |
| 270 | |
Kuninori Morimoto | 26d34b1 | 2016-02-18 08:14:37 +0000 | [diff] [blame] | 271 | static void rsnd_ssi_master_clk_stop(struct rsnd_mod *mod, |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 272 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 273 | { |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 274 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
Kuninori Morimoto | 26d34b1 | 2016-02-18 08:14:37 +0000 | [diff] [blame] | 275 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 276 | struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 277 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 278 | if (!rsnd_rdai_is_clk_master(rdai)) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 279 | return; |
| 280 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 281 | if (ssi_parent_mod && !rsnd_ssi_is_parent(mod, io)) |
| 282 | return; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 283 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 284 | if (ssi->usrcnt > 1) |
| 285 | return; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 286 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 287 | ssi->cr_clk = 0; |
| 288 | ssi->rate = 0; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 289 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 290 | rsnd_adg_ssi_clk_stop(mod); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Kuninori Morimoto | 0dc6bf7 | 2016-02-18 08:17:18 +0000 | [diff] [blame] | 293 | static void rsnd_ssi_config_init(struct rsnd_mod *mod, |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 294 | struct rsnd_dai_stream *io) |
| 295 | { |
| 296 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
| 297 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
Kuninori Morimoto | 26d34b1 | 2016-02-18 08:14:37 +0000 | [diff] [blame] | 298 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 299 | u32 cr_own; |
| 300 | u32 cr_mode; |
Kuninori Morimoto | 186fadc | 2015-11-30 08:54:03 +0000 | [diff] [blame] | 301 | u32 wsr; |
Kuninori Morimoto | f98ed11 | 2015-12-02 07:34:28 +0000 | [diff] [blame] | 302 | int is_tdm; |
| 303 | |
Kuninori Morimoto | eed76bb | 2016-02-25 05:54:58 +0000 | [diff] [blame] | 304 | is_tdm = rsnd_runtime_is_ssi_tdm(io); |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 305 | |
| 306 | /* |
| 307 | * always use 32bit system word. |
| 308 | * see also rsnd_ssi_master_clk_enable() |
| 309 | */ |
| 310 | cr_own = FORCE | SWL_32 | PDTA; |
| 311 | |
| 312 | if (rdai->bit_clk_inv) |
| 313 | cr_own |= SCKP; |
Kuninori Morimoto | f98ed11 | 2015-12-02 07:34:28 +0000 | [diff] [blame] | 314 | if (rdai->frm_clk_inv ^ is_tdm) |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 315 | cr_own |= SWSP; |
| 316 | if (rdai->data_alignment) |
| 317 | cr_own |= SDTA; |
| 318 | if (rdai->sys_delay) |
| 319 | cr_own |= DEL; |
| 320 | if (rsnd_io_is_play(io)) |
| 321 | cr_own |= TRMD; |
| 322 | |
| 323 | switch (runtime->sample_bits) { |
| 324 | case 16: |
| 325 | cr_own |= DWL_16; |
| 326 | break; |
| 327 | case 32: |
| 328 | cr_own |= DWL_24; |
| 329 | break; |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Kuninori Morimoto | 26d34b1 | 2016-02-18 08:14:37 +0000 | [diff] [blame] | 332 | if (rsnd_ssi_is_dma_mode(mod)) { |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 333 | cr_mode = UIEN | OIEN | /* over/under run */ |
| 334 | DMEN; /* DMA : enable DMA */ |
| 335 | } else { |
| 336 | cr_mode = DIEN; /* PIO : enable Data interrupt */ |
| 337 | } |
| 338 | |
Kuninori Morimoto | 186fadc | 2015-11-30 08:54:03 +0000 | [diff] [blame] | 339 | /* |
| 340 | * TDM Extend Mode |
| 341 | * see |
| 342 | * rsnd_ssiu_init_gen2() |
| 343 | */ |
| 344 | wsr = ssi->wsr; |
Kuninori Morimoto | f98ed11 | 2015-12-02 07:34:28 +0000 | [diff] [blame] | 345 | if (is_tdm) { |
Kuninori Morimoto | 186fadc | 2015-11-30 08:54:03 +0000 | [diff] [blame] | 346 | wsr |= WS_MODE; |
| 347 | cr_own |= CHNL_8; |
| 348 | } |
| 349 | |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 350 | ssi->cr_own = cr_own; |
| 351 | ssi->cr_mode = cr_mode; |
Kuninori Morimoto | 186fadc | 2015-11-30 08:54:03 +0000 | [diff] [blame] | 352 | ssi->wsr = wsr; |
Kuninori Morimoto | 0dc6bf7 | 2016-02-18 08:17:18 +0000 | [diff] [blame] | 353 | } |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 354 | |
Kuninori Morimoto | 0dc6bf7 | 2016-02-18 08:17:18 +0000 | [diff] [blame] | 355 | static void rsnd_ssi_register_setup(struct rsnd_mod *mod) |
| 356 | { |
| 357 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
| 358 | |
| 359 | rsnd_mod_write(mod, SSIWSR, ssi->wsr); |
| 360 | rsnd_mod_write(mod, SSICR, ssi->cr_own | |
| 361 | ssi->cr_clk | |
| 362 | ssi->cr_mode); /* without EN */ |
Kuninori Morimoto | 840ada3 | 2015-11-30 08:52:38 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 365 | /* |
| 366 | * SSI mod common functions |
| 367 | */ |
| 368 | static int rsnd_ssi_init(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 369 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 370 | struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 371 | { |
| 372 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 373 | int ret; |
| 374 | |
Kuninori Morimoto | fd9adcf | 2016-02-18 08:19:12 +0000 | [diff] [blame] | 375 | if (!rsnd_ssi_is_run_mods(mod, io)) |
| 376 | return 0; |
| 377 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 378 | ssi->usrcnt++; |
| 379 | |
| 380 | rsnd_mod_power_on(mod); |
| 381 | |
Kuninori Morimoto | 26d34b1 | 2016-02-18 08:14:37 +0000 | [diff] [blame] | 382 | ret = rsnd_ssi_master_clk_start(mod, io); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 383 | if (ret < 0) |
| 384 | return ret; |
| 385 | |
Kuninori Morimoto | 0dc6bf7 | 2016-02-18 08:17:18 +0000 | [diff] [blame] | 386 | if (!rsnd_ssi_is_parent(mod, io)) |
| 387 | rsnd_ssi_config_init(mod, io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 388 | |
Kuninori Morimoto | 0dc6bf7 | 2016-02-18 08:17:18 +0000 | [diff] [blame] | 389 | rsnd_ssi_register_setup(mod); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 390 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 391 | /* clear error status */ |
| 392 | rsnd_ssi_status_clear(mod); |
| 393 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static int rsnd_ssi_quit(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 398 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 399 | struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 400 | { |
| 401 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 402 | struct device *dev = rsnd_priv_to_dev(priv); |
| 403 | |
Kuninori Morimoto | fd9adcf | 2016-02-18 08:19:12 +0000 | [diff] [blame] | 404 | if (!rsnd_ssi_is_run_mods(mod, io)) |
| 405 | return 0; |
| 406 | |
Andrzej Hajda | e5d9cfc | 2015-12-24 08:02:39 +0100 | [diff] [blame] | 407 | if (!ssi->usrcnt) { |
| 408 | dev_err(dev, "%s[%d] usrcnt error\n", |
| 409 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
| 410 | return -EIO; |
| 411 | } |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 412 | |
Kuninori Morimoto | b5b442a | 2016-01-26 04:56:57 +0000 | [diff] [blame] | 413 | if (!rsnd_ssi_is_parent(mod, io)) |
Andrzej Hajda | e5d9cfc | 2015-12-24 08:02:39 +0100 | [diff] [blame] | 414 | ssi->cr_own = 0; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 415 | |
Kuninori Morimoto | 26d34b1 | 2016-02-18 08:14:37 +0000 | [diff] [blame] | 416 | rsnd_ssi_master_clk_stop(mod, io); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 417 | |
| 418 | rsnd_mod_power_off(mod); |
| 419 | |
| 420 | ssi->usrcnt--; |
| 421 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 425 | static int rsnd_ssi_hw_params(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 426 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 427 | struct snd_pcm_substream *substream, |
| 428 | struct snd_pcm_hw_params *params) |
| 429 | { |
| 430 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 431 | int chan = params_channels(params); |
| 432 | |
| 433 | /* |
| 434 | * Already working. |
| 435 | * It will happen if SSI has parent/child connection. |
| 436 | */ |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 437 | if (ssi->usrcnt > 1) { |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 438 | /* |
| 439 | * it is error if child <-> parent SSI uses |
| 440 | * different channels. |
| 441 | */ |
| 442 | if (ssi->chan != chan) |
| 443 | return -EIO; |
| 444 | } |
| 445 | |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 446 | ssi->chan = chan; |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 451 | static int rsnd_ssi_start(struct rsnd_mod *mod, |
| 452 | struct rsnd_dai_stream *io, |
| 453 | struct rsnd_priv *priv) |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 454 | { |
Kuninori Morimoto | fd9adcf | 2016-02-18 08:19:12 +0000 | [diff] [blame] | 455 | if (!rsnd_ssi_is_run_mods(mod, io)) |
| 456 | return 0; |
| 457 | |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 458 | /* |
| 459 | * EN will be set via SSIU :: SSI_CONTROL |
| 460 | * if Multi channel mode |
| 461 | */ |
Kuninori Morimoto | 4f5c634 | 2016-02-18 08:18:54 +0000 | [diff] [blame] | 462 | if (rsnd_ssi_multi_slaves_runtime(io)) |
Kuninori Morimoto | 0dc6bf7 | 2016-02-18 08:17:18 +0000 | [diff] [blame] | 463 | return 0; |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 464 | |
Kuninori Morimoto | 0dc6bf7 | 2016-02-18 08:17:18 +0000 | [diff] [blame] | 465 | rsnd_mod_bset(mod, SSICR, EN, EN); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 470 | static int rsnd_ssi_stop(struct rsnd_mod *mod, |
| 471 | struct rsnd_dai_stream *io, |
| 472 | struct rsnd_priv *priv) |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 473 | { |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 474 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 475 | u32 cr; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 476 | |
Kuninori Morimoto | fd9adcf | 2016-02-18 08:19:12 +0000 | [diff] [blame] | 477 | if (!rsnd_ssi_is_run_mods(mod, io)) |
| 478 | return 0; |
| 479 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 480 | /* |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 481 | * don't stop if not last user |
| 482 | * see also |
| 483 | * rsnd_ssi_start |
| 484 | * rsnd_ssi_interrupt |
| 485 | */ |
| 486 | if (ssi->usrcnt > 1) |
| 487 | return 0; |
| 488 | |
| 489 | /* |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 490 | * disable all IRQ, |
| 491 | * and, wait all data was sent |
| 492 | */ |
| 493 | cr = ssi->cr_own | |
| 494 | ssi->cr_clk; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 495 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 496 | rsnd_mod_write(mod, SSICR, cr | EN); |
| 497 | rsnd_ssi_status_check(mod, DIRQ); |
| 498 | |
| 499 | /* |
| 500 | * disable SSI, |
| 501 | * and, wait idle state |
| 502 | */ |
| 503 | rsnd_mod_write(mod, SSICR, cr); /* disabled all */ |
| 504 | rsnd_ssi_status_check(mod, IIRQ); |
Kuninori Morimoto | c17dba8 | 2014-11-27 08:05:09 +0000 | [diff] [blame] | 505 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 506 | return 0; |
| 507 | } |
| 508 | |
Kuninori Morimoto | 615fb6c | 2016-02-18 08:18:16 +0000 | [diff] [blame] | 509 | static int rsnd_ssi_irq(struct rsnd_mod *mod, |
| 510 | struct rsnd_dai_stream *io, |
| 511 | struct rsnd_priv *priv, |
| 512 | int enable) |
| 513 | { |
| 514 | u32 val = 0; |
| 515 | |
| 516 | if (rsnd_is_gen1(priv)) |
| 517 | return 0; |
| 518 | |
| 519 | if (rsnd_ssi_is_parent(mod, io)) |
| 520 | return 0; |
| 521 | |
Kuninori Morimoto | fd9adcf | 2016-02-18 08:19:12 +0000 | [diff] [blame] | 522 | if (!rsnd_ssi_is_run_mods(mod, io)) |
| 523 | return 0; |
| 524 | |
Kuninori Morimoto | 615fb6c | 2016-02-18 08:18:16 +0000 | [diff] [blame] | 525 | if (enable) |
| 526 | val = rsnd_ssi_is_dma_mode(mod) ? 0x0e000000 : 0x0f000000; |
| 527 | |
| 528 | rsnd_mod_write(mod, SSI_INT_ENABLE, val); |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
Kuninori Morimoto | bfc0cfe | 2015-06-15 06:26:56 +0000 | [diff] [blame] | 533 | static void __rsnd_ssi_interrupt(struct rsnd_mod *mod, |
| 534 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 535 | { |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 536 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 765ae7c | 2015-01-15 08:09:13 +0000 | [diff] [blame] | 537 | int is_dma = rsnd_ssi_is_dma_mode(mod); |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 538 | u32 status; |
Kuninori Morimoto | 75defee | 2015-06-15 06:21:15 +0000 | [diff] [blame] | 539 | bool elapsed = false; |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 540 | bool stop = false; |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 541 | |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 542 | spin_lock(&priv->lock); |
| 543 | |
| 544 | /* ignore all cases if not working */ |
Kuninori Morimoto | d5bbe7d | 2015-06-15 06:27:47 +0000 | [diff] [blame] | 545 | if (!rsnd_io_is_working(io)) |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 546 | goto rsnd_ssi_interrupt_out; |
| 547 | |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 548 | status = rsnd_ssi_status_get(mod); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 549 | |
| 550 | /* PIO only */ |
Kuninori Morimoto | 765ae7c | 2015-01-15 08:09:13 +0000 | [diff] [blame] | 551 | if (!is_dma && (status & DIRQ)) { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 552 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 553 | u32 *buf = (u32 *)(runtime->dma_area + |
| 554 | rsnd_dai_pointer_offset(io, 0)); |
| 555 | |
| 556 | /* |
| 557 | * 8/16/32 data can be assesse to TDR/RDR register |
| 558 | * directly as 32bit data |
| 559 | * see rsnd_ssi_init() |
| 560 | */ |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 561 | if (rsnd_io_is_play(io)) |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 562 | rsnd_mod_write(mod, SSITDR, *buf); |
| 563 | else |
| 564 | *buf = rsnd_mod_read(mod, SSIRDR); |
| 565 | |
Kuninori Morimoto | 75defee | 2015-06-15 06:21:15 +0000 | [diff] [blame] | 566 | elapsed = rsnd_dai_pointer_update(io, sizeof(*buf)); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Kuninori Morimoto | 12927a8 | 2015-06-15 06:20:54 +0000 | [diff] [blame] | 569 | /* DMA only */ |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 570 | if (is_dma && (status & (UIRQ | OIRQ))) |
| 571 | stop = true; |
Kuninori Morimoto | 69e32a5 | 2015-10-26 08:41:36 +0000 | [diff] [blame] | 572 | |
Kuninori Morimoto | 5342dff | 2015-11-26 11:13:40 +0000 | [diff] [blame] | 573 | rsnd_ssi_status_clear(mod); |
Kuninori Morimoto | 02299d9 | 2015-05-21 03:50:23 +0000 | [diff] [blame] | 574 | rsnd_ssi_interrupt_out: |
| 575 | spin_unlock(&priv->lock); |
| 576 | |
Kuninori Morimoto | 75defee | 2015-06-15 06:21:15 +0000 | [diff] [blame] | 577 | if (elapsed) |
| 578 | rsnd_dai_period_elapsed(io); |
Kuninori Morimoto | 6a25c8d | 2016-01-26 04:56:14 +0000 | [diff] [blame] | 579 | |
| 580 | if (stop) |
| 581 | snd_pcm_stop_xrun(io->substream); |
| 582 | |
Kuninori Morimoto | bfc0cfe | 2015-06-15 06:26:56 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) |
| 586 | { |
| 587 | struct rsnd_mod *mod = data; |
| 588 | |
| 589 | rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt); |
Kuninori Morimoto | 75defee | 2015-06-15 06:21:15 +0000 | [diff] [blame] | 590 | |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 591 | return IRQ_HANDLED; |
| 592 | } |
| 593 | |
Kuninori Morimoto | 6cfad78 | 2014-11-27 08:08:10 +0000 | [diff] [blame] | 594 | /* |
| 595 | * SSI PIO |
| 596 | */ |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 597 | static void rsnd_ssi_parent_attach(struct rsnd_mod *mod, |
Kuninori Morimoto | 098bd89 | 2016-02-18 08:17:52 +0000 | [diff] [blame] | 598 | struct rsnd_dai_stream *io) |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 599 | { |
Kuninori Morimoto | 098bd89 | 2016-02-18 08:17:52 +0000 | [diff] [blame] | 600 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
| 601 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 602 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 603 | if (!__rsnd_ssi_is_pin_sharing(mod)) |
| 604 | return; |
| 605 | |
Kuninori Morimoto | 098bd89 | 2016-02-18 08:17:52 +0000 | [diff] [blame] | 606 | if (!rsnd_rdai_is_clk_master(rdai)) |
| 607 | return; |
| 608 | |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 609 | switch (rsnd_mod_id(mod)) { |
| 610 | case 1: |
| 611 | case 2: |
| 612 | rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP); |
| 613 | break; |
| 614 | case 4: |
| 615 | rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP); |
| 616 | break; |
| 617 | case 8: |
| 618 | rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP); |
| 619 | break; |
| 620 | } |
| 621 | } |
| 622 | |
Kuninori Morimoto | 098bd89 | 2016-02-18 08:17:52 +0000 | [diff] [blame] | 623 | static int rsnd_ssi_pcm_new(struct rsnd_mod *mod, |
| 624 | struct rsnd_dai_stream *io, |
| 625 | struct snd_soc_pcm_runtime *rtd) |
| 626 | { |
| 627 | /* |
| 628 | * rsnd_rdai_is_clk_master() will be enabled after set_fmt, |
| 629 | * and, pcm_new will be called after it. |
| 630 | * This function reuse pcm_new at this point. |
| 631 | */ |
| 632 | rsnd_ssi_parent_attach(mod, io); |
| 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | |
Kuninori Morimoto | c7f69ab | 2015-10-26 08:43:41 +0000 | [diff] [blame] | 637 | static int rsnd_ssi_common_probe(struct rsnd_mod *mod, |
| 638 | struct rsnd_dai_stream *io, |
| 639 | struct rsnd_priv *priv) |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 640 | { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 641 | struct device *dev = rsnd_priv_to_dev(priv); |
| 642 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 643 | int ret; |
| 644 | |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 645 | /* |
| 646 | * SSIP/SSIU/IRQ are not needed on |
| 647 | * SSI Multi slaves |
| 648 | */ |
| 649 | if (rsnd_ssi_is_multi_slave(mod, io)) |
| 650 | return 0; |
| 651 | |
Kuninori Morimoto | 098bd89 | 2016-02-18 08:17:52 +0000 | [diff] [blame] | 652 | /* |
| 653 | * It can't judge ssi parent at this point |
| 654 | * see rsnd_ssi_pcm_new() |
| 655 | */ |
Kuninori Morimoto | e7d850d | 2015-10-26 08:43:57 +0000 | [diff] [blame] | 656 | |
Kuninori Morimoto | c7f69ab | 2015-10-26 08:43:41 +0000 | [diff] [blame] | 657 | ret = rsnd_ssiu_attach(io, mod); |
| 658 | if (ret < 0) |
| 659 | return ret; |
| 660 | |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 661 | ret = devm_request_irq(dev, ssi->irq, |
Kuninori Morimoto | 6cfad78 | 2014-11-27 08:08:10 +0000 | [diff] [blame] | 662 | rsnd_ssi_interrupt, |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 663 | IRQF_SHARED, |
Kuninori Morimoto | bfc0cfe | 2015-06-15 06:26:56 +0000 | [diff] [blame] | 664 | dev_name(dev), mod); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 665 | |
| 666 | return ret; |
| 667 | } |
| 668 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 669 | static struct rsnd_mod_ops rsnd_ssi_pio_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 670 | .name = SSI_NAME, |
Kuninori Morimoto | c7f69ab | 2015-10-26 08:43:41 +0000 | [diff] [blame] | 671 | .probe = rsnd_ssi_common_probe, |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 672 | .init = rsnd_ssi_init, |
| 673 | .quit = rsnd_ssi_quit, |
Kuninori Morimoto | 4922985 | 2014-11-27 08:07:17 +0000 | [diff] [blame] | 674 | .start = rsnd_ssi_start, |
| 675 | .stop = rsnd_ssi_stop, |
Kuninori Morimoto | b5b442a | 2016-01-26 04:56:57 +0000 | [diff] [blame] | 676 | .irq = rsnd_ssi_irq, |
Kuninori Morimoto | 098bd89 | 2016-02-18 08:17:52 +0000 | [diff] [blame] | 677 | .pcm_new = rsnd_ssi_pcm_new, |
Kuninori Morimoto | 919567d | 2015-04-10 08:50:30 +0000 | [diff] [blame] | 678 | .hw_params = rsnd_ssi_hw_params, |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 679 | }; |
| 680 | |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 681 | static int rsnd_ssi_dma_probe(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 682 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 683 | struct rsnd_priv *priv) |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 684 | { |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 685 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 686 | int dma_id = 0; /* not needed */ |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 687 | int ret; |
| 688 | |
Kuninori Morimoto | b4c83b1 | 2015-12-17 03:00:10 +0000 | [diff] [blame] | 689 | /* |
| 690 | * SSIP/SSIU/IRQ/DMA are not needed on |
| 691 | * SSI Multi slaves |
| 692 | */ |
| 693 | if (rsnd_ssi_is_multi_slave(mod, io)) |
| 694 | return 0; |
| 695 | |
Kuninori Morimoto | c7f69ab | 2015-10-26 08:43:41 +0000 | [diff] [blame] | 696 | ret = rsnd_ssi_common_probe(mod, io, priv); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 697 | if (ret) |
Kuninori Morimoto | b543b52 | 2015-03-26 04:02:32 +0000 | [diff] [blame] | 698 | return ret; |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 699 | |
Kuninori Morimoto | 355cb84fb | 2016-01-21 01:58:33 +0000 | [diff] [blame] | 700 | /* SSI probe might be called many times in MUX multi path */ |
| 701 | ret = rsnd_dma_attach(io, mod, &ssi->dma, dma_id); |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 702 | |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 703 | return ret; |
| 704 | } |
| 705 | |
| 706 | static int rsnd_ssi_dma_remove(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 707 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 708 | struct rsnd_priv *priv) |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 709 | { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 710 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | 1cb145c | 2017-08-09 02:16:20 +0000 | [diff] [blame] | 711 | struct rsnd_mod *pure_ssi_mod = rsnd_io_to_mod_ssi(io); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 712 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 02534f2 | 2015-11-10 05:11:35 +0000 | [diff] [blame] | 713 | int irq = ssi->irq; |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 714 | |
Kuninori Morimoto | 1cb145c | 2017-08-09 02:16:20 +0000 | [diff] [blame] | 715 | /* Do nothing if non SSI (= SSI parent, multi SSI) mod */ |
| 716 | if (pure_ssi_mod != mod) |
Kuninori Morimoto | 24978c2 | 2017-05-16 01:48:24 +0000 | [diff] [blame] | 717 | return 0; |
| 718 | |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 719 | /* PIO will request IRQ again */ |
Kuninori Morimoto | b05ce4c | 2015-10-22 03:13:44 +0000 | [diff] [blame] | 720 | devm_free_irq(dev, irq, mod); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 721 | |
Kuninori Morimoto | 97463e1 | 2014-11-27 08:02:43 +0000 | [diff] [blame] | 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | static int rsnd_ssi_fallback(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 726 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 727 | struct rsnd_priv *priv) |
Kuninori Morimoto | 97463e1 | 2014-11-27 08:02:43 +0000 | [diff] [blame] | 728 | { |
Kuninori Morimoto | d3a7682 | 2014-11-09 20:00:58 -0800 | [diff] [blame] | 729 | struct device *dev = rsnd_priv_to_dev(priv); |
| 730 | |
Kuninori Morimoto | d3a7682 | 2014-11-09 20:00:58 -0800 | [diff] [blame] | 731 | /* |
| 732 | * fallback to PIO |
| 733 | * |
| 734 | * SSI .probe might be called again. |
| 735 | * see |
| 736 | * rsnd_rdai_continuance_probe() |
| 737 | */ |
| 738 | mod->ops = &rsnd_ssi_pio_ops; |
| 739 | |
| 740 | dev_info(dev, "%s[%d] fallback to PIO mode\n", |
| 741 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
| 742 | |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 743 | return 0; |
| 744 | } |
| 745 | |
Kuninori Morimoto | 9b99e9a | 2015-06-15 06:26:25 +0000 | [diff] [blame] | 746 | static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io, |
| 747 | struct rsnd_mod *mod) |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 748 | { |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 749 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 750 | int is_play = rsnd_io_is_play(io); |
| 751 | char *name; |
| 752 | |
Kuninori Morimoto | b415b4d | 2015-10-22 03:15:46 +0000 | [diff] [blame] | 753 | if (rsnd_ssi_use_busif(io)) |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 754 | name = is_play ? "rxu" : "txu"; |
| 755 | else |
| 756 | name = is_play ? "rx" : "tx"; |
| 757 | |
| 758 | return rsnd_dma_request_channel(rsnd_ssi_of_node(priv), |
| 759 | mod, name); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 762 | static struct rsnd_mod_ops rsnd_ssi_dma_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 763 | .name = SSI_NAME, |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 764 | .dma_req = rsnd_ssi_dma_req, |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 765 | .probe = rsnd_ssi_dma_probe, |
| 766 | .remove = rsnd_ssi_dma_remove, |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 767 | .init = rsnd_ssi_init, |
| 768 | .quit = rsnd_ssi_quit, |
Kuninori Morimoto | 497deba | 2015-10-26 08:43:01 +0000 | [diff] [blame] | 769 | .start = rsnd_ssi_start, |
| 770 | .stop = rsnd_ssi_stop, |
Kuninori Morimoto | c8e969a | 2016-02-18 08:16:43 +0000 | [diff] [blame] | 771 | .irq = rsnd_ssi_irq, |
Kuninori Morimoto | 098bd89 | 2016-02-18 08:17:52 +0000 | [diff] [blame] | 772 | .pcm_new = rsnd_ssi_pcm_new, |
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; |
Julia Lawall | 5193029 | 2016-08-05 10:56:51 +0200 | [diff] [blame] | 950 | if (of_property_read_bool(np, "pio-transfer")) |
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 | } |