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