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 | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 69 | int err; |
| 70 | unsigned int usrcnt; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 73 | #define for_each_rsnd_ssi(pos, priv, i) \ |
| 74 | for (i = 0; \ |
| 75 | (i < rsnd_ssi_nr(priv)) && \ |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 76 | ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \ |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 77 | i++) |
| 78 | |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 79 | #define rsnd_ssi_nr(priv) ((priv)->ssi_nr) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 80 | #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] | 81 | #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] | 82 | #define rsnd_ssi_pio_available(ssi) ((ssi)->info->irq > 0) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 83 | #define rsnd_ssi_clk_from_parent(ssi) ((ssi)->parent) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 84 | #define rsnd_ssi_mode_flags(p) ((p)->info->flags) |
Kuninori Morimoto | 4b4dab8 | 2013-07-28 18:58:29 -0700 | [diff] [blame] | 85 | #define rsnd_ssi_dai_id(ssi) ((ssi)->info->dai_id) |
Kuninori Morimoto | 04e627b | 2015-02-20 10:30:02 +0000 | [diff] [blame] | 86 | #define rsnd_ssi_of_node(priv) \ |
| 87 | 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] | 88 | |
Kuninori Morimoto | e879a9d | 2015-02-20 10:29:41 +0000 | [diff] [blame] | 89 | int rsnd_ssi_use_busif(struct rsnd_mod *mod) |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 90 | { |
| 91 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
| 92 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
| 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 | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 192 | if (rsnd_ssi_clk_from_parent(ssi)) |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 193 | rsnd_ssi_hw_start(ssi->parent, io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 194 | else |
Kuninori Morimoto | adcf7d5 | 2013-12-19 19:28:39 -0800 | [diff] [blame] | 195 | rsnd_ssi_master_clk_start(ssi, io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
Kuninori Morimoto | 0579541 | 2014-11-27 08:05:01 +0000 | [diff] [blame] | 199 | cr_mode = rsnd_ssi_is_dma_mode(&ssi->mod) ? |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 200 | DMEN : /* DMA : enable DMA */ |
| 201 | DIEN; /* PIO : enable Data interrupt */ |
Kuninori Morimoto | 0579541 | 2014-11-27 08:05:01 +0000 | [diff] [blame] | 202 | |
| 203 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 204 | cr = ssi->cr_own | |
| 205 | ssi->cr_clk | |
Kuninori Morimoto | 0579541 | 2014-11-27 08:05:01 +0000 | [diff] [blame] | 206 | cr_mode | |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 207 | UIEN | OIEN | EN; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 208 | |
| 209 | rsnd_mod_write(&ssi->mod, SSICR, cr); |
| 210 | |
Kuninori Morimoto | d1b6405 | 2014-11-27 08:05:34 +0000 | [diff] [blame] | 211 | /* enable WS continue */ |
Kuninori Morimoto | 3ed6448 | 2015-01-15 08:04:51 +0000 | [diff] [blame] | 212 | if (rsnd_rdai_is_clk_master(rdai)) |
Kuninori Morimoto | d1b6405 | 2014-11-27 08:05:34 +0000 | [diff] [blame] | 213 | rsnd_mod_write(&ssi->mod, SSIWSR, CONT); |
| 214 | |
Kuninori Morimoto | 3ba84f4 | 2014-11-27 08:05:44 +0000 | [diff] [blame] | 215 | /* clear error status */ |
| 216 | rsnd_mod_write(&ssi->mod, SSISR, 0); |
| 217 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 218 | ssi->usrcnt++; |
| 219 | |
Kuninori Morimoto | 30cc4fa | 2014-11-09 20:00:30 -0800 | [diff] [blame] | 220 | dev_dbg(dev, "%s[%d] hw started\n", |
| 221 | rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod)); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 224 | static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 225 | { |
| 226 | struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod); |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 227 | struct rsnd_dai_stream *io = rsnd_mod_to_io(&ssi->mod); |
| 228 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 229 | struct device *dev = rsnd_priv_to_dev(priv); |
| 230 | u32 cr; |
| 231 | |
| 232 | if (0 == ssi->usrcnt) /* stop might be called without start */ |
| 233 | return; |
| 234 | |
| 235 | ssi->usrcnt--; |
| 236 | |
| 237 | if (0 == ssi->usrcnt) { |
| 238 | /* |
| 239 | * disable all IRQ, |
| 240 | * and, wait all data was sent |
| 241 | */ |
| 242 | cr = ssi->cr_own | |
| 243 | ssi->cr_clk; |
| 244 | |
| 245 | rsnd_mod_write(&ssi->mod, SSICR, cr | EN); |
| 246 | rsnd_ssi_status_check(&ssi->mod, DIRQ); |
| 247 | |
| 248 | /* |
| 249 | * disable SSI, |
| 250 | * and, wait idle state |
| 251 | */ |
| 252 | rsnd_mod_write(&ssi->mod, SSICR, cr); /* disabled all */ |
| 253 | rsnd_ssi_status_check(&ssi->mod, IIRQ); |
| 254 | |
Kuninori Morimoto | 3ed6448 | 2015-01-15 08:04:51 +0000 | [diff] [blame] | 255 | if (rsnd_rdai_is_clk_master(rdai)) { |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 256 | if (rsnd_ssi_clk_from_parent(ssi)) |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 257 | rsnd_ssi_hw_stop(ssi->parent); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 258 | else |
| 259 | rsnd_ssi_master_clk_stop(ssi); |
| 260 | } |
| 261 | |
Kuninori Morimoto | 8564295 | 2015-01-15 08:03:22 +0000 | [diff] [blame] | 262 | rsnd_mod_hw_stop(&ssi->mod); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Kuninori Morimoto | 30cc4fa | 2014-11-09 20:00:30 -0800 | [diff] [blame] | 265 | dev_dbg(dev, "%s[%d] hw stopped\n", |
| 266 | rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod)); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /* |
| 270 | * SSI mod common functions |
| 271 | */ |
| 272 | static int rsnd_ssi_init(struct rsnd_mod *mod, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 273 | struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 274 | { |
| 275 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame] | 276 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 277 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 278 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 279 | u32 cr; |
| 280 | |
| 281 | cr = FORCE; |
| 282 | |
| 283 | /* |
| 284 | * always use 32bit system word for easy clock calculation. |
| 285 | * see also rsnd_ssi_master_clk_enable() |
| 286 | */ |
| 287 | cr |= SWL_32; |
| 288 | |
| 289 | /* |
| 290 | * init clock settings for SSICR |
| 291 | */ |
| 292 | switch (runtime->sample_bits) { |
| 293 | case 16: |
| 294 | cr |= DWL_16; |
| 295 | break; |
| 296 | case 32: |
| 297 | cr |= DWL_24; |
| 298 | break; |
| 299 | default: |
| 300 | return -EIO; |
| 301 | } |
| 302 | |
| 303 | if (rdai->bit_clk_inv) |
| 304 | cr |= SCKP; |
| 305 | if (rdai->frm_clk_inv) |
| 306 | cr |= SWSP; |
| 307 | if (rdai->data_alignment) |
| 308 | cr |= SDTA; |
| 309 | if (rdai->sys_delay) |
| 310 | cr |= DEL; |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 311 | if (rsnd_io_is_play(io)) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 312 | cr |= TRMD; |
| 313 | |
| 314 | /* |
| 315 | * set ssi parameter |
| 316 | */ |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 317 | ssi->cr_own = cr; |
| 318 | ssi->err = -1; /* ignore 1st error */ |
| 319 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static int rsnd_ssi_quit(struct rsnd_mod *mod, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 324 | struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 325 | { |
| 326 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 327 | struct device *dev = rsnd_priv_to_dev(priv); |
| 328 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 329 | if (ssi->err > 0) |
Kuninori Morimoto | 337b0b4 | 2015-01-15 08:08:57 +0000 | [diff] [blame] | 330 | dev_warn(dev, "%s[%d] under/over flow err = %d\n", |
| 331 | rsnd_mod_name(mod), rsnd_mod_id(mod), ssi->err); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 332 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 333 | ssi->cr_own = 0; |
| 334 | ssi->err = 0; |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status) |
| 340 | { |
| 341 | /* under/over flow error */ |
| 342 | if (status & (UIRQ | OIRQ)) { |
| 343 | ssi->err++; |
| 344 | |
| 345 | /* clear error status */ |
| 346 | rsnd_mod_write(&ssi->mod, SSISR, 0); |
| 347 | } |
| 348 | } |
| 349 | |
Kuninori Morimoto | 4922985 | 2014-11-27 08:07:17 +0000 | [diff] [blame] | 350 | static int rsnd_ssi_start(struct rsnd_mod *mod, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 351 | struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 352 | { |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 353 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | b42fccf | 2014-05-08 17:44:29 -0700 | [diff] [blame] | 354 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 355 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 356 | rsnd_src_ssiu_start(mod, rsnd_ssi_use_busif(mod)); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 357 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 358 | rsnd_ssi_hw_start(ssi, io); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 359 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 360 | rsnd_src_ssi_irq_enable(mod); |
Kuninori Morimoto | c17dba8 | 2014-11-27 08:05:09 +0000 | [diff] [blame] | 361 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 362 | return 0; |
| 363 | } |
| 364 | |
Kuninori Morimoto | 4922985 | 2014-11-27 08:07:17 +0000 | [diff] [blame] | 365 | static int rsnd_ssi_stop(struct rsnd_mod *mod, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 366 | struct rsnd_priv *priv) |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 367 | { |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 368 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
| 369 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 370 | rsnd_src_ssi_irq_disable(mod); |
Kuninori Morimoto | c17dba8 | 2014-11-27 08:05:09 +0000 | [diff] [blame] | 371 | |
Kuninori Morimoto | 7b466fc | 2014-11-27 08:05:54 +0000 | [diff] [blame] | 372 | rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR)); |
| 373 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 374 | rsnd_ssi_hw_stop(ssi); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 375 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 376 | rsnd_src_ssiu_stop(mod); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 377 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 378 | return 0; |
| 379 | } |
| 380 | |
Kuninori Morimoto | 6cfad78 | 2014-11-27 08:08:10 +0000 | [diff] [blame] | 381 | static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 382 | { |
| 383 | struct rsnd_ssi *ssi = data; |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 384 | struct rsnd_mod *mod = &ssi->mod; |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 385 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 386 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
Kuninori Morimoto | 765ae7c | 2015-01-15 08:09:13 +0000 | [diff] [blame] | 387 | int is_dma = rsnd_ssi_is_dma_mode(mod); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 388 | u32 status = rsnd_mod_read(mod, SSISR); |
| 389 | |
| 390 | if (!io) |
| 391 | return IRQ_NONE; |
| 392 | |
| 393 | /* PIO only */ |
Kuninori Morimoto | 765ae7c | 2015-01-15 08:09:13 +0000 | [diff] [blame] | 394 | if (!is_dma && (status & DIRQ)) { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 395 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
| 396 | u32 *buf = (u32 *)(runtime->dma_area + |
| 397 | rsnd_dai_pointer_offset(io, 0)); |
| 398 | |
| 399 | /* |
| 400 | * 8/16/32 data can be assesse to TDR/RDR register |
| 401 | * directly as 32bit data |
| 402 | * see rsnd_ssi_init() |
| 403 | */ |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 404 | if (rsnd_io_is_play(io)) |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 405 | rsnd_mod_write(mod, SSITDR, *buf); |
| 406 | else |
| 407 | *buf = rsnd_mod_read(mod, SSIRDR); |
| 408 | |
| 409 | rsnd_dai_pointer_update(io, sizeof(*buf)); |
| 410 | } |
| 411 | |
| 412 | /* PIO / DMA */ |
| 413 | if (status & (UIRQ | OIRQ)) { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 414 | struct device *dev = rsnd_priv_to_dev(priv); |
| 415 | |
| 416 | /* |
| 417 | * restart SSI |
| 418 | */ |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 419 | dev_dbg(dev, "%s[%d] restart\n", |
| 420 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
Kuninori Morimoto | 044930b | 2015-03-19 04:13:47 +0000 | [diff] [blame] | 421 | |
| 422 | rsnd_ssi_stop(mod, priv); |
| 423 | if (ssi->err < 1024) |
| 424 | rsnd_ssi_start(mod, priv); |
| 425 | else |
| 426 | dev_warn(dev, "no more SSI restart\n"); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | rsnd_ssi_record_error(ssi, status); |
| 430 | |
| 431 | return IRQ_HANDLED; |
| 432 | } |
| 433 | |
Kuninori Morimoto | 6cfad78 | 2014-11-27 08:08:10 +0000 | [diff] [blame] | 434 | /* |
| 435 | * SSI PIO |
| 436 | */ |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 437 | static int rsnd_ssi_pio_probe(struct rsnd_mod *mod, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 438 | struct rsnd_priv *priv) |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 439 | { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 440 | struct device *dev = rsnd_priv_to_dev(priv); |
| 441 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 442 | int ret; |
| 443 | |
Kuninori Morimoto | 6cfad78 | 2014-11-27 08:08:10 +0000 | [diff] [blame] | 444 | ret = devm_request_irq(dev, ssi->info->irq, |
| 445 | rsnd_ssi_interrupt, |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 446 | IRQF_SHARED, |
| 447 | dev_name(dev), ssi); |
| 448 | if (ret) |
| 449 | dev_err(dev, "%s[%d] (PIO) request interrupt failed\n", |
| 450 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
| 451 | else |
| 452 | dev_dbg(dev, "%s[%d] (PIO) is probed\n", |
| 453 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
| 454 | |
| 455 | return ret; |
| 456 | } |
| 457 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 458 | static struct rsnd_mod_ops rsnd_ssi_pio_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 459 | .name = SSI_NAME, |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 460 | .probe = rsnd_ssi_pio_probe, |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 461 | .init = rsnd_ssi_init, |
| 462 | .quit = rsnd_ssi_quit, |
Kuninori Morimoto | 4922985 | 2014-11-27 08:07:17 +0000 | [diff] [blame] | 463 | .start = rsnd_ssi_start, |
| 464 | .stop = rsnd_ssi_stop, |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 465 | }; |
| 466 | |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 467 | static int rsnd_ssi_dma_probe(struct rsnd_mod *mod, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 468 | struct rsnd_priv *priv) |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 469 | { |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 470 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 471 | struct device *dev = rsnd_priv_to_dev(priv); |
| 472 | int dma_id = ssi->info->dma_id; |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 473 | int ret; |
| 474 | |
Kuninori Morimoto | 6cfad78 | 2014-11-27 08:08:10 +0000 | [diff] [blame] | 475 | ret = devm_request_irq(dev, ssi->info->irq, |
| 476 | rsnd_ssi_interrupt, |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 477 | IRQF_SHARED, |
| 478 | dev_name(dev), ssi); |
| 479 | if (ret) |
| 480 | goto rsnd_ssi_dma_probe_fail; |
| 481 | |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 482 | ret = rsnd_dma_init( |
| 483 | priv, rsnd_mod_to_dma(mod), |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 484 | dma_id); |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 485 | if (ret) |
| 486 | goto rsnd_ssi_dma_probe_fail; |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 487 | |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 488 | dev_dbg(dev, "%s[%d] (DMA) is probed\n", |
| 489 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
| 490 | |
| 491 | return ret; |
| 492 | |
| 493 | rsnd_ssi_dma_probe_fail: |
| 494 | dev_err(dev, "%s[%d] (DMA) is failed\n", |
| 495 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 496 | |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 497 | return ret; |
| 498 | } |
| 499 | |
| 500 | static int rsnd_ssi_dma_remove(struct rsnd_mod *mod, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 501 | struct rsnd_priv *priv) |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 502 | { |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 503 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
| 504 | struct device *dev = rsnd_priv_to_dev(priv); |
Kuninori Morimoto | 6cfad78 | 2014-11-27 08:08:10 +0000 | [diff] [blame] | 505 | int irq = ssi->info->irq; |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 506 | |
Kuninori Morimoto | 8a2ff42 | 2015-02-20 10:24:06 +0000 | [diff] [blame] | 507 | rsnd_dma_quit(rsnd_mod_to_dma(mod)); |
Kuninori Morimoto | 97463e1 | 2014-11-27 08:02:43 +0000 | [diff] [blame] | 508 | |
Kuninori Morimoto | 4e7d606 | 2014-11-27 08:07:47 +0000 | [diff] [blame] | 509 | /* PIO will request IRQ again */ |
| 510 | devm_free_irq(dev, irq, ssi); |
| 511 | |
Kuninori Morimoto | 97463e1 | 2014-11-27 08:02:43 +0000 | [diff] [blame] | 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | static int rsnd_ssi_fallback(struct rsnd_mod *mod, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 516 | struct rsnd_priv *priv) |
Kuninori Morimoto | 97463e1 | 2014-11-27 08:02:43 +0000 | [diff] [blame] | 517 | { |
Kuninori Morimoto | d3a7682 | 2014-11-09 20:00:58 -0800 | [diff] [blame] | 518 | struct device *dev = rsnd_priv_to_dev(priv); |
| 519 | |
Kuninori Morimoto | d3a7682 | 2014-11-09 20:00:58 -0800 | [diff] [blame] | 520 | /* |
| 521 | * fallback to PIO |
| 522 | * |
| 523 | * SSI .probe might be called again. |
| 524 | * see |
| 525 | * rsnd_rdai_continuance_probe() |
| 526 | */ |
| 527 | mod->ops = &rsnd_ssi_pio_ops; |
| 528 | |
| 529 | dev_info(dev, "%s[%d] fallback to PIO mode\n", |
| 530 | rsnd_mod_name(mod), rsnd_mod_id(mod)); |
| 531 | |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 532 | return 0; |
| 533 | } |
| 534 | |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 535 | static int rsnd_ssi_dma_start(struct rsnd_mod *mod, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 536 | struct rsnd_priv *priv) |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 537 | { |
Kuninori Morimoto | 4922985 | 2014-11-27 08:07:17 +0000 | [diff] [blame] | 538 | struct rsnd_dma *dma = rsnd_mod_to_dma(mod); |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 539 | |
Kuninori Morimoto | 7b466fc | 2014-11-27 08:05:54 +0000 | [diff] [blame] | 540 | rsnd_dma_start(dma); |
| 541 | |
Kuninori Morimoto | 1ceeab2 | 2015-01-15 08:09:26 +0000 | [diff] [blame] | 542 | rsnd_ssi_start(mod, priv); |
| 543 | |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | static int rsnd_ssi_dma_stop(struct rsnd_mod *mod, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 548 | struct rsnd_priv *priv) |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 549 | { |
Kuninori Morimoto | 4922985 | 2014-11-27 08:07:17 +0000 | [diff] [blame] | 550 | struct rsnd_dma *dma = rsnd_mod_to_dma(mod); |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 551 | |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 552 | rsnd_ssi_stop(mod, priv); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 553 | |
Kuninori Morimoto | 1ceeab2 | 2015-01-15 08:09:26 +0000 | [diff] [blame] | 554 | rsnd_dma_stop(dma); |
| 555 | |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 556 | return 0; |
| 557 | } |
| 558 | |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 559 | static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_mod *mod) |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 560 | { |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 561 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 562 | struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); |
| 563 | int is_play = rsnd_io_is_play(io); |
| 564 | char *name; |
| 565 | |
| 566 | if (rsnd_ssi_use_busif(mod)) |
| 567 | name = is_play ? "rxu" : "txu"; |
| 568 | else |
| 569 | name = is_play ? "rx" : "tx"; |
| 570 | |
| 571 | return rsnd_dma_request_channel(rsnd_ssi_of_node(priv), |
| 572 | mod, name); |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 575 | static struct rsnd_mod_ops rsnd_ssi_dma_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 576 | .name = SSI_NAME, |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 577 | .dma_req = rsnd_ssi_dma_req, |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 578 | .probe = rsnd_ssi_dma_probe, |
| 579 | .remove = rsnd_ssi_dma_remove, |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 580 | .init = rsnd_ssi_init, |
| 581 | .quit = rsnd_ssi_quit, |
| 582 | .start = rsnd_ssi_dma_start, |
| 583 | .stop = rsnd_ssi_dma_stop, |
Kuninori Morimoto | 97463e1 | 2014-11-27 08:02:43 +0000 | [diff] [blame] | 584 | .fallback = rsnd_ssi_fallback, |
Kuninori Morimoto | 849fc82 | 2013-07-28 18:59:02 -0700 | [diff] [blame] | 585 | }; |
| 586 | |
Kuninori Morimoto | 0579541 | 2014-11-27 08:05:01 +0000 | [diff] [blame] | 587 | int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod) |
| 588 | { |
| 589 | return mod->ops == &rsnd_ssi_dma_ops; |
| 590 | } |
| 591 | |
| 592 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 593 | /* |
| 594 | * Non SSI |
| 595 | */ |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 596 | static struct rsnd_mod_ops rsnd_ssi_non_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 597 | .name = SSI_NAME, |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 598 | }; |
| 599 | |
| 600 | /* |
| 601 | * ssi mod function |
| 602 | */ |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 603 | struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id) |
| 604 | { |
Takashi Iwai | 8b14719 | 2013-11-05 18:40:05 +0100 | [diff] [blame] | 605 | if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv))) |
| 606 | id = 0; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 607 | |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 608 | return &((struct rsnd_ssi *)(priv->ssi) + id)->mod; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 611 | int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod) |
| 612 | { |
| 613 | struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); |
| 614 | |
| 615 | return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE); |
| 616 | } |
| 617 | |
| 618 | static void rsnd_ssi_parent_clk_setup(struct rsnd_priv *priv, struct rsnd_ssi *ssi) |
| 619 | { |
| 620 | if (!rsnd_ssi_is_pin_sharing(&ssi->mod)) |
| 621 | return; |
| 622 | |
| 623 | switch (rsnd_mod_id(&ssi->mod)) { |
| 624 | case 1: |
| 625 | case 2: |
| 626 | ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 0)); |
| 627 | break; |
| 628 | case 4: |
| 629 | ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 3)); |
| 630 | break; |
| 631 | case 8: |
| 632 | ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 7)); |
| 633 | break; |
| 634 | } |
| 635 | } |
| 636 | |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 637 | |
| 638 | static void rsnd_of_parse_ssi(struct platform_device *pdev, |
| 639 | const struct rsnd_of_data *of_data, |
| 640 | struct rsnd_priv *priv) |
| 641 | { |
| 642 | struct device_node *node; |
| 643 | struct device_node *np; |
| 644 | struct rsnd_ssi_platform_info *ssi_info; |
| 645 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
| 646 | struct device *dev = &pdev->dev; |
| 647 | int nr, i; |
| 648 | |
| 649 | if (!of_data) |
| 650 | return; |
| 651 | |
Kuninori Morimoto | 04e627b | 2015-02-20 10:30:02 +0000 | [diff] [blame] | 652 | node = rsnd_ssi_of_node(priv); |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 653 | if (!node) |
| 654 | return; |
| 655 | |
| 656 | nr = of_get_child_count(node); |
| 657 | if (!nr) |
Kuninori Morimoto | f451e48 | 2014-05-22 23:24:59 -0700 | [diff] [blame] | 658 | goto rsnd_of_parse_ssi_end; |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 659 | |
| 660 | ssi_info = devm_kzalloc(dev, |
| 661 | sizeof(struct rsnd_ssi_platform_info) * nr, |
| 662 | GFP_KERNEL); |
| 663 | if (!ssi_info) { |
| 664 | dev_err(dev, "ssi info allocation error\n"); |
Kuninori Morimoto | f451e48 | 2014-05-22 23:24:59 -0700 | [diff] [blame] | 665 | goto rsnd_of_parse_ssi_end; |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | info->ssi_info = ssi_info; |
| 669 | info->ssi_info_nr = nr; |
| 670 | |
| 671 | i = -1; |
| 672 | for_each_child_of_node(node, np) { |
| 673 | i++; |
| 674 | |
| 675 | ssi_info = info->ssi_info + i; |
| 676 | |
| 677 | /* |
| 678 | * pin settings |
| 679 | */ |
| 680 | if (of_get_property(np, "shared-pin", NULL)) |
| 681 | ssi_info->flags |= RSND_SSI_CLK_PIN_SHARE; |
| 682 | |
| 683 | /* |
| 684 | * irq |
| 685 | */ |
Kuninori Morimoto | 6cfad78 | 2014-11-27 08:08:10 +0000 | [diff] [blame] | 686 | ssi_info->irq = irq_of_parse_and_map(np, 0); |
Kuninori Morimoto | 199e7688 | 2014-05-22 23:25:49 -0700 | [diff] [blame] | 687 | |
| 688 | /* |
| 689 | * DMA |
| 690 | */ |
| 691 | ssi_info->dma_id = of_get_property(np, "pio-transfer", NULL) ? |
| 692 | 0 : 1; |
Kuninori Morimoto | d9288d0 | 2014-06-22 17:56:23 -0700 | [diff] [blame] | 693 | |
| 694 | if (of_get_property(np, "no-busif", NULL)) |
| 695 | ssi_info->flags |= RSND_SSI_NO_BUSIF; |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 696 | } |
Kuninori Morimoto | f451e48 | 2014-05-22 23:24:59 -0700 | [diff] [blame] | 697 | |
| 698 | rsnd_of_parse_ssi_end: |
| 699 | of_node_put(node); |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 702 | int rsnd_ssi_probe(struct platform_device *pdev, |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 703 | const struct rsnd_of_data *of_data, |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 704 | struct rsnd_priv *priv) |
| 705 | { |
Kuninori Morimoto | 5da39cf | 2014-02-24 22:15:00 -0800 | [diff] [blame] | 706 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 707 | struct rsnd_ssi_platform_info *pinfo; |
| 708 | struct device *dev = rsnd_priv_to_dev(priv); |
| 709 | struct rsnd_mod_ops *ops; |
| 710 | struct clk *clk; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 711 | struct rsnd_ssi *ssi; |
| 712 | char name[RSND_SSI_NAME_SIZE]; |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 713 | int i, nr, ret; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 714 | |
Kuninori Morimoto | 90e8e50 | 2014-03-17 19:29:55 -0700 | [diff] [blame] | 715 | rsnd_of_parse_ssi(pdev, of_data, priv); |
| 716 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 717 | /* |
| 718 | * init SSI |
| 719 | */ |
| 720 | nr = info->ssi_info_nr; |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 721 | ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL); |
| 722 | if (!ssi) { |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 723 | dev_err(dev, "SSI allocate failed\n"); |
| 724 | return -ENOMEM; |
| 725 | } |
| 726 | |
Kuninori Morimoto | dd27d80 | 2014-01-23 18:39:40 -0800 | [diff] [blame] | 727 | priv->ssi = ssi; |
| 728 | priv->ssi_nr = nr; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 729 | |
| 730 | for_each_rsnd_ssi(ssi, priv, i) { |
| 731 | pinfo = &info->ssi_info[i]; |
| 732 | |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 733 | snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d", |
| 734 | SSI_NAME, i); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 735 | |
Kuninori Morimoto | 60dbb4f | 2013-12-03 22:09:33 -0800 | [diff] [blame] | 736 | clk = devm_clk_get(dev, name); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 737 | if (IS_ERR(clk)) |
| 738 | return PTR_ERR(clk); |
| 739 | |
| 740 | ssi->info = pinfo; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 741 | |
| 742 | ops = &rsnd_ssi_non_ops; |
Kuninori Morimoto | ff8f30e | 2014-03-03 20:50:49 -0800 | [diff] [blame] | 743 | if (pinfo->dma_id > 0) |
| 744 | ops = &rsnd_ssi_dma_ops; |
| 745 | else if (rsnd_ssi_pio_available(ssi)) |
| 746 | ops = &rsnd_ssi_pio_ops; |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 747 | |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 748 | ret = rsnd_mod_init(&ssi->mod, ops, clk, RSND_MOD_SSI, i); |
| 749 | if (ret) |
| 750 | return ret; |
Kuninori Morimoto | 7b5ce97 | 2014-01-23 18:39:32 -0800 | [diff] [blame] | 751 | |
| 752 | rsnd_ssi_parent_clk_setup(priv, ssi); |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Kuninori Morimoto | ae5c322 | 2013-07-21 21:36:57 -0700 | [diff] [blame] | 755 | return 0; |
| 756 | } |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 757 | |
| 758 | void rsnd_ssi_remove(struct platform_device *pdev, |
| 759 | struct rsnd_priv *priv) |
| 760 | { |
| 761 | struct rsnd_ssi *ssi; |
| 762 | int i; |
| 763 | |
| 764 | for_each_rsnd_ssi(ssi, priv, i) { |
| 765 | rsnd_mod_quit(&ssi->mod); |
| 766 | } |
| 767 | } |