Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Renesas R-Car DVC support |
| 3 | * |
| 4 | * Copyright (C) 2014 Renesas Solutions Corp. |
| 5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | #include "rsnd.h" |
| 12 | |
| 13 | #define RSND_DVC_NAME_SIZE 16 |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 14 | |
| 15 | #define DVC_NAME "dvc" |
| 16 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 17 | struct rsnd_dvc { |
| 18 | struct rsnd_dvc_platform_info *info; /* rcar_snd.h */ |
| 19 | struct rsnd_mod mod; |
Kuninori Morimoto | 170a249 | 2014-11-27 08:06:14 +0000 | [diff] [blame] | 20 | struct rsnd_kctrl_cfg_m volume; |
| 21 | struct rsnd_kctrl_cfg_m mute; |
| 22 | struct rsnd_kctrl_cfg_s ren; /* Ramp Enable */ |
| 23 | struct rsnd_kctrl_cfg_s rup; /* Ramp Rate Up */ |
| 24 | struct rsnd_kctrl_cfg_s rdown; /* Ramp Rate Down */ |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 25 | }; |
| 26 | |
Kuninori Morimoto | 4f35fab | 2015-07-15 07:11:02 +0000 | [diff] [blame] | 27 | #define rsnd_dvc_nr(priv) ((priv)->dvc_nr) |
Kuninori Morimoto | 93b986e | 2015-02-20 10:30:41 +0000 | [diff] [blame] | 28 | #define rsnd_dvc_of_node(priv) \ |
| 29 | of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,dvc") |
| 30 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 31 | #define rsnd_mod_to_dvc(_mod) \ |
| 32 | container_of((_mod), struct rsnd_dvc, mod) |
| 33 | |
| 34 | #define for_each_rsnd_dvc(pos, priv, i) \ |
| 35 | for ((i) = 0; \ |
| 36 | ((i) < rsnd_dvc_nr(priv)) && \ |
| 37 | ((pos) = (struct rsnd_dvc *)(priv)->dvc + i); \ |
| 38 | i++) |
| 39 | |
Krzysztof Kozlowski | 2f4b1e6 | 2015-03-24 11:47:43 +0100 | [diff] [blame] | 40 | static const char * const dvc_ramp_rate[] = { |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 41 | "128 dB/1 step", /* 00000 */ |
| 42 | "64 dB/1 step", /* 00001 */ |
| 43 | "32 dB/1 step", /* 00010 */ |
| 44 | "16 dB/1 step", /* 00011 */ |
| 45 | "8 dB/1 step", /* 00100 */ |
| 46 | "4 dB/1 step", /* 00101 */ |
| 47 | "2 dB/1 step", /* 00110 */ |
| 48 | "1 dB/1 step", /* 00111 */ |
| 49 | "0.5 dB/1 step", /* 01000 */ |
| 50 | "0.25 dB/1 step", /* 01001 */ |
| 51 | "0.125 dB/1 step", /* 01010 */ |
| 52 | "0.125 dB/2 steps", /* 01011 */ |
| 53 | "0.125 dB/4 steps", /* 01100 */ |
| 54 | "0.125 dB/8 steps", /* 01101 */ |
| 55 | "0.125 dB/16 steps", /* 01110 */ |
| 56 | "0.125 dB/32 steps", /* 01111 */ |
| 57 | "0.125 dB/64 steps", /* 10000 */ |
| 58 | "0.125 dB/128 steps", /* 10001 */ |
| 59 | "0.125 dB/256 steps", /* 10010 */ |
| 60 | "0.125 dB/512 steps", /* 10011 */ |
| 61 | "0.125 dB/1024 steps", /* 10100 */ |
| 62 | "0.125 dB/2048 steps", /* 10101 */ |
| 63 | "0.125 dB/4096 steps", /* 10110 */ |
| 64 | "0.125 dB/8192 steps", /* 10111 */ |
| 65 | }; |
| 66 | |
Kuninori Morimoto | 636e4ba | 2015-07-15 07:12:00 +0000 | [diff] [blame^] | 67 | static void rsnd_dvc_soft_reset(struct rsnd_mod *mod) |
| 68 | { |
| 69 | rsnd_mod_write(mod, DVC_SWRSR, 0); |
| 70 | rsnd_mod_write(mod, DVC_SWRSR, 1); |
| 71 | } |
| 72 | |
Kuninori Morimoto | b65a7cc | 2015-06-15 06:27:28 +0000 | [diff] [blame] | 73 | static void rsnd_dvc_volume_update(struct rsnd_dai_stream *io, |
| 74 | struct rsnd_mod *mod) |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 75 | { |
| 76 | struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod); |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 77 | u32 val[RSND_DVC_CHANNELS]; |
Kuninori Morimoto | 1c5d1c9 | 2014-11-04 20:26:53 -0800 | [diff] [blame] | 78 | u32 dvucr = 0; |
Kuninori Morimoto | cd2b657 | 2014-08-01 03:10:55 -0700 | [diff] [blame] | 79 | u32 mute = 0; |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 80 | int i; |
| 81 | |
Kuninori Morimoto | ec14af9 | 2014-11-04 20:27:46 -0800 | [diff] [blame] | 82 | for (i = 0; i < dvc->mute.cfg.size; i++) |
| 83 | mute |= (!!dvc->mute.cfg.val[i]) << i; |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 84 | |
Kuninori Morimoto | 140bab8 | 2014-11-04 20:27:18 -0800 | [diff] [blame] | 85 | /* Disable DVC Register access */ |
| 86 | rsnd_mod_write(mod, DVC_DVUER, 0); |
| 87 | |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 88 | /* Enable Ramp */ |
| 89 | if (dvc->ren.val) { |
| 90 | dvucr |= 0x10; |
| 91 | |
| 92 | /* Digital Volume Max */ |
| 93 | for (i = 0; i < RSND_DVC_CHANNELS; i++) |
| 94 | val[i] = dvc->volume.cfg.max; |
| 95 | |
| 96 | rsnd_mod_write(mod, DVC_VRCTR, 0xff); |
| 97 | rsnd_mod_write(mod, DVC_VRPDR, dvc->rup.val << 8 | |
| 98 | dvc->rdown.val); |
| 99 | /* |
| 100 | * FIXME !! |
| 101 | * use scale-downed Digital Volume |
| 102 | * as Volume Ramp |
| 103 | * 7F FFFF -> 3FF |
| 104 | */ |
| 105 | rsnd_mod_write(mod, DVC_VRDBR, |
| 106 | 0x3ff - (dvc->volume.val[0] >> 13)); |
| 107 | |
| 108 | } else { |
| 109 | for (i = 0; i < RSND_DVC_CHANNELS; i++) |
| 110 | val[i] = dvc->volume.val[i]; |
| 111 | } |
| 112 | |
Kuninori Morimoto | 1c5d1c9 | 2014-11-04 20:26:53 -0800 | [diff] [blame] | 113 | /* Enable Digital Volume */ |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 114 | dvucr |= 0x100; |
| 115 | rsnd_mod_write(mod, DVC_VOL0R, val[0]); |
| 116 | rsnd_mod_write(mod, DVC_VOL1R, val[1]); |
Kuninori Morimoto | cd2b657 | 2014-08-01 03:10:55 -0700 | [diff] [blame] | 117 | |
Kuninori Morimoto | 1c5d1c9 | 2014-11-04 20:26:53 -0800 | [diff] [blame] | 118 | /* Enable Mute */ |
| 119 | if (mute) { |
| 120 | dvucr |= 0x1; |
| 121 | rsnd_mod_write(mod, DVC_ZCMCR, mute); |
| 122 | } |
| 123 | |
| 124 | rsnd_mod_write(mod, DVC_DVUCR, dvucr); |
Kuninori Morimoto | 140bab8 | 2014-11-04 20:27:18 -0800 | [diff] [blame] | 125 | |
| 126 | /* Enable DVC Register access */ |
| 127 | rsnd_mod_write(mod, DVC_DVUER, 1); |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Kuninori Morimoto | d1f83d6 | 2015-02-02 04:53:53 +0000 | [diff] [blame] | 130 | static int rsnd_dvc_remove_gen2(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 131 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | d1f83d6 | 2015-02-02 04:53:53 +0000 | [diff] [blame] | 132 | struct rsnd_priv *priv) |
| 133 | { |
| 134 | struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod); |
| 135 | |
| 136 | rsnd_kctrl_remove(dvc->volume); |
| 137 | rsnd_kctrl_remove(dvc->mute); |
| 138 | rsnd_kctrl_remove(dvc->ren); |
| 139 | rsnd_kctrl_remove(dvc->rup); |
| 140 | rsnd_kctrl_remove(dvc->rdown); |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 145 | static int rsnd_dvc_init(struct rsnd_mod *dvc_mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 146 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 147 | struct rsnd_priv *priv) |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 148 | { |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 149 | struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); |
| 150 | struct device *dev = rsnd_priv_to_dev(priv); |
| 151 | int dvc_id = rsnd_mod_id(dvc_mod); |
| 152 | int src_id = rsnd_mod_id(src_mod); |
| 153 | u32 route[] = { |
| 154 | [0] = 0x30000, |
| 155 | [1] = 0x30001, |
| 156 | [2] = 0x40000, |
| 157 | [3] = 0x10000, |
| 158 | [4] = 0x20000, |
| 159 | [5] = 0x40100 |
| 160 | }; |
| 161 | |
| 162 | if (src_id >= ARRAY_SIZE(route)) { |
| 163 | dev_err(dev, "DVC%d isn't connected to SRC%d\n", dvc_id, src_id); |
| 164 | return -EINVAL; |
| 165 | } |
| 166 | |
Kuninori Morimoto | 8564295 | 2015-01-15 08:03:22 +0000 | [diff] [blame] | 167 | rsnd_mod_hw_start(dvc_mod); |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 168 | |
Kuninori Morimoto | 636e4ba | 2015-07-15 07:12:00 +0000 | [diff] [blame^] | 169 | rsnd_dvc_soft_reset(dvc_mod); |
| 170 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 171 | /* |
| 172 | * fixme |
| 173 | * it doesn't support CTU/MIX |
| 174 | */ |
| 175 | rsnd_mod_write(dvc_mod, CMD_ROUTE_SLCT, route[src_id]); |
| 176 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 177 | rsnd_mod_write(dvc_mod, DVC_DVUIR, 1); |
| 178 | |
Kuninori Morimoto | 4e2639f | 2015-06-15 06:26:08 +0000 | [diff] [blame] | 179 | rsnd_mod_write(dvc_mod, DVC_ADINR, rsnd_get_adinr(dvc_mod, io)); |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 180 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 181 | /* ch0/ch1 Volume */ |
Kuninori Morimoto | b65a7cc | 2015-06-15 06:27:28 +0000 | [diff] [blame] | 182 | rsnd_dvc_volume_update(io, dvc_mod); |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 183 | |
| 184 | rsnd_mod_write(dvc_mod, DVC_DVUIR, 0); |
| 185 | |
Kuninori Morimoto | f708d94 | 2015-01-15 08:07:19 +0000 | [diff] [blame] | 186 | rsnd_adg_set_cmd_timsel_gen2(dvc_mod, io); |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static int rsnd_dvc_quit(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 192 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 193 | struct rsnd_priv *priv) |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 194 | { |
Kuninori Morimoto | 8564295 | 2015-01-15 08:03:22 +0000 | [diff] [blame] | 195 | rsnd_mod_hw_stop(mod); |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static int rsnd_dvc_start(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 201 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 202 | struct rsnd_priv *priv) |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 203 | { |
| 204 | rsnd_mod_write(mod, CMD_CTRL, 0x10); |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static int rsnd_dvc_stop(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 210 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | 690602f | 2015-01-15 08:07:47 +0000 | [diff] [blame] | 211 | struct rsnd_priv *priv) |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 212 | { |
| 213 | rsnd_mod_write(mod, CMD_CTRL, 0); |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 218 | static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, |
Kuninori Morimoto | 2c0fac1 | 2015-06-15 06:25:20 +0000 | [diff] [blame] | 219 | struct rsnd_dai_stream *io, |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 220 | struct snd_soc_pcm_runtime *rtd) |
| 221 | { |
Kuninori Morimoto | 486b09c | 2014-08-01 03:10:47 -0700 | [diff] [blame] | 222 | struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod); |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 223 | int is_play = rsnd_io_is_play(io); |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 224 | int ret; |
| 225 | |
Kuninori Morimoto | 486b09c | 2014-08-01 03:10:47 -0700 | [diff] [blame] | 226 | /* Volume */ |
Kuninori Morimoto | b65a7cc | 2015-06-15 06:27:28 +0000 | [diff] [blame] | 227 | ret = rsnd_kctrl_new_m(mod, io, rtd, |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 228 | is_play ? |
Kuninori Morimoto | 486b09c | 2014-08-01 03:10:47 -0700 | [diff] [blame] | 229 | "DVC Out Playback Volume" : "DVC In Capture Volume", |
Kuninori Morimoto | 170a249 | 2014-11-27 08:06:14 +0000 | [diff] [blame] | 230 | rsnd_dvc_volume_update, |
Kuninori Morimoto | ec14af9 | 2014-11-04 20:27:46 -0800 | [diff] [blame] | 231 | &dvc->volume, 0x00800000 - 1); |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 232 | if (ret < 0) |
| 233 | return ret; |
| 234 | |
Kuninori Morimoto | cd2b657 | 2014-08-01 03:10:55 -0700 | [diff] [blame] | 235 | /* Mute */ |
Kuninori Morimoto | b65a7cc | 2015-06-15 06:27:28 +0000 | [diff] [blame] | 236 | ret = rsnd_kctrl_new_m(mod, io, rtd, |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 237 | is_play ? |
Kuninori Morimoto | cd2b657 | 2014-08-01 03:10:55 -0700 | [diff] [blame] | 238 | "DVC Out Mute Switch" : "DVC In Mute Switch", |
Kuninori Morimoto | 170a249 | 2014-11-27 08:06:14 +0000 | [diff] [blame] | 239 | rsnd_dvc_volume_update, |
Kuninori Morimoto | ec14af9 | 2014-11-04 20:27:46 -0800 | [diff] [blame] | 240 | &dvc->mute, 1); |
Kuninori Morimoto | cd2b657 | 2014-08-01 03:10:55 -0700 | [diff] [blame] | 241 | if (ret < 0) |
| 242 | return ret; |
| 243 | |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 244 | /* Ramp */ |
Kuninori Morimoto | b65a7cc | 2015-06-15 06:27:28 +0000 | [diff] [blame] | 245 | ret = rsnd_kctrl_new_s(mod, io, rtd, |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 246 | is_play ? |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 247 | "DVC Out Ramp Switch" : "DVC In Ramp Switch", |
Kuninori Morimoto | 170a249 | 2014-11-27 08:06:14 +0000 | [diff] [blame] | 248 | rsnd_dvc_volume_update, |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 249 | &dvc->ren, 1); |
| 250 | if (ret < 0) |
| 251 | return ret; |
| 252 | |
Kuninori Morimoto | b65a7cc | 2015-06-15 06:27:28 +0000 | [diff] [blame] | 253 | ret = rsnd_kctrl_new_e(mod, io, rtd, |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 254 | is_play ? |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 255 | "DVC Out Ramp Up Rate" : "DVC In Ramp Up Rate", |
| 256 | &dvc->rup, |
Kuninori Morimoto | 170a249 | 2014-11-27 08:06:14 +0000 | [diff] [blame] | 257 | rsnd_dvc_volume_update, |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 258 | dvc_ramp_rate, ARRAY_SIZE(dvc_ramp_rate)); |
| 259 | if (ret < 0) |
| 260 | return ret; |
| 261 | |
Kuninori Morimoto | b65a7cc | 2015-06-15 06:27:28 +0000 | [diff] [blame] | 262 | ret = rsnd_kctrl_new_e(mod, io, rtd, |
Kuninori Morimoto | 985a4f6 | 2015-01-15 08:06:49 +0000 | [diff] [blame] | 263 | is_play ? |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 264 | "DVC Out Ramp Down Rate" : "DVC In Ramp Down Rate", |
| 265 | &dvc->rdown, |
Kuninori Morimoto | 170a249 | 2014-11-27 08:06:14 +0000 | [diff] [blame] | 266 | rsnd_dvc_volume_update, |
Kuninori Morimoto | 3539cac | 2014-11-09 19:52:06 -0800 | [diff] [blame] | 267 | dvc_ramp_rate, ARRAY_SIZE(dvc_ramp_rate)); |
| 268 | |
| 269 | if (ret < 0) |
| 270 | return ret; |
| 271 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 272 | return 0; |
| 273 | } |
| 274 | |
Kuninori Morimoto | 9b99e9a | 2015-06-15 06:26:25 +0000 | [diff] [blame] | 275 | static struct dma_chan *rsnd_dvc_dma_req(struct rsnd_dai_stream *io, |
| 276 | struct rsnd_mod *mod) |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 277 | { |
| 278 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
| 279 | |
| 280 | return rsnd_dma_request_channel(rsnd_dvc_of_node(priv), |
| 281 | mod, "tx"); |
| 282 | } |
| 283 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 284 | static struct rsnd_mod_ops rsnd_dvc_ops = { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 285 | .name = DVC_NAME, |
Kuninori Morimoto | 72adc61 | 2015-02-20 10:31:23 +0000 | [diff] [blame] | 286 | .dma_req = rsnd_dvc_dma_req, |
Kuninori Morimoto | d1f83d6 | 2015-02-02 04:53:53 +0000 | [diff] [blame] | 287 | .remove = rsnd_dvc_remove_gen2, |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 288 | .init = rsnd_dvc_init, |
| 289 | .quit = rsnd_dvc_quit, |
| 290 | .start = rsnd_dvc_start, |
| 291 | .stop = rsnd_dvc_stop, |
| 292 | .pcm_new = rsnd_dvc_pcm_new, |
| 293 | }; |
| 294 | |
| 295 | struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id) |
| 296 | { |
| 297 | if (WARN_ON(id < 0 || id >= rsnd_dvc_nr(priv))) |
| 298 | id = 0; |
| 299 | |
| 300 | return &((struct rsnd_dvc *)(priv->dvc) + id)->mod; |
| 301 | } |
| 302 | |
Kuninori Morimoto | 34cb612 | 2014-06-22 17:59:28 -0700 | [diff] [blame] | 303 | static void rsnd_of_parse_dvc(struct platform_device *pdev, |
| 304 | const struct rsnd_of_data *of_data, |
| 305 | struct rsnd_priv *priv) |
| 306 | { |
| 307 | struct device_node *node; |
| 308 | struct rsnd_dvc_platform_info *dvc_info; |
| 309 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
| 310 | struct device *dev = &pdev->dev; |
| 311 | int nr; |
| 312 | |
| 313 | if (!of_data) |
| 314 | return; |
| 315 | |
| 316 | node = of_get_child_by_name(dev->of_node, "rcar_sound,dvc"); |
| 317 | if (!node) |
| 318 | return; |
| 319 | |
| 320 | nr = of_get_child_count(node); |
| 321 | if (!nr) |
| 322 | goto rsnd_of_parse_dvc_end; |
| 323 | |
| 324 | dvc_info = devm_kzalloc(dev, |
| 325 | sizeof(struct rsnd_dvc_platform_info) * nr, |
| 326 | GFP_KERNEL); |
| 327 | if (!dvc_info) { |
| 328 | dev_err(dev, "dvc info allocation error\n"); |
| 329 | goto rsnd_of_parse_dvc_end; |
| 330 | } |
| 331 | |
| 332 | info->dvc_info = dvc_info; |
| 333 | info->dvc_info_nr = nr; |
| 334 | |
| 335 | rsnd_of_parse_dvc_end: |
| 336 | of_node_put(node); |
| 337 | } |
| 338 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 339 | int rsnd_dvc_probe(struct platform_device *pdev, |
| 340 | const struct rsnd_of_data *of_data, |
| 341 | struct rsnd_priv *priv) |
| 342 | { |
| 343 | struct rcar_snd_info *info = rsnd_priv_to_info(priv); |
| 344 | struct device *dev = rsnd_priv_to_dev(priv); |
| 345 | struct rsnd_dvc *dvc; |
| 346 | struct clk *clk; |
| 347 | char name[RSND_DVC_NAME_SIZE]; |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 348 | int i, nr, ret; |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 349 | |
Kuninori Morimoto | 34cb612 | 2014-06-22 17:59:28 -0700 | [diff] [blame] | 350 | rsnd_of_parse_dvc(pdev, of_data, priv); |
| 351 | |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 352 | nr = info->dvc_info_nr; |
| 353 | if (!nr) |
| 354 | return 0; |
| 355 | |
| 356 | /* This driver doesn't support Gen1 at this point */ |
| 357 | if (rsnd_is_gen1(priv)) { |
| 358 | dev_warn(dev, "CMD is not supported on Gen1\n"); |
| 359 | return -EINVAL; |
| 360 | } |
| 361 | |
| 362 | dvc = devm_kzalloc(dev, sizeof(*dvc) * nr, GFP_KERNEL); |
Kuninori Morimoto | 6abcae3 | 2015-07-15 07:09:07 +0000 | [diff] [blame] | 363 | if (!dvc) |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 364 | return -ENOMEM; |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 365 | |
| 366 | priv->dvc_nr = nr; |
| 367 | priv->dvc = dvc; |
| 368 | |
| 369 | for_each_rsnd_dvc(dvc, priv, i) { |
Kuninori Morimoto | 8aefda5 | 2014-05-22 23:25:43 -0700 | [diff] [blame] | 370 | snprintf(name, RSND_DVC_NAME_SIZE, "%s.%d", |
| 371 | DVC_NAME, i); |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 372 | |
| 373 | clk = devm_clk_get(dev, name); |
| 374 | if (IS_ERR(clk)) |
| 375 | return PTR_ERR(clk); |
| 376 | |
| 377 | dvc->info = &info->dvc_info[i]; |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 378 | |
Kuninori Morimoto | 2099bc8 | 2015-06-15 06:24:54 +0000 | [diff] [blame] | 379 | ret = rsnd_mod_init(priv, &dvc->mod, &rsnd_dvc_ops, |
Kuninori Morimoto | 8564295 | 2015-01-15 08:03:22 +0000 | [diff] [blame] | 380 | clk, RSND_MOD_DVC, i); |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 381 | if (ret) |
| 382 | return ret; |
Kuninori Morimoto | bff58ea | 2014-05-08 17:44:49 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | return 0; |
| 386 | } |
Kuninori Morimoto | 2f78dd7 | 2015-03-26 04:02:09 +0000 | [diff] [blame] | 387 | |
| 388 | void rsnd_dvc_remove(struct platform_device *pdev, |
| 389 | struct rsnd_priv *priv) |
| 390 | { |
| 391 | struct rsnd_dvc *dvc; |
| 392 | int i; |
| 393 | |
| 394 | for_each_rsnd_dvc(dvc, priv, i) { |
| 395 | rsnd_mod_quit(&dvc->mod); |
| 396 | } |
| 397 | } |