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