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