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