Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Renesas R-Car CMD support |
| 3 | * |
| 4 | * Copyright (C) 2015 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 | struct rsnd_cmd { |
| 14 | struct rsnd_mod mod; |
| 15 | }; |
| 16 | |
| 17 | #define CMD_NAME "cmd" |
| 18 | |
| 19 | #define rsnd_cmd_nr(priv) ((priv)->cmd_nr) |
| 20 | #define for_each_rsnd_cmd(pos, priv, i) \ |
| 21 | for ((i) = 0; \ |
| 22 | ((i) < rsnd_cmd_nr(priv)) && \ |
| 23 | ((pos) = (struct rsnd_cmd *)(priv)->cmd + i); \ |
| 24 | i++) |
| 25 | |
| 26 | static int rsnd_cmd_init(struct rsnd_mod *mod, |
| 27 | struct rsnd_dai_stream *io, |
| 28 | struct rsnd_priv *priv) |
| 29 | { |
| 30 | struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io); |
| 31 | struct rsnd_mod *mix = rsnd_io_to_mod_mix(io); |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 32 | struct device *dev = rsnd_priv_to_dev(priv); |
| 33 | u32 data; |
Hiroyuki Yokoyama | a1c2ff5 | 2017-03-01 03:51:00 +0000 | [diff] [blame] | 34 | u32 path[] = { |
| 35 | [1] = 1 << 0, |
| 36 | [5] = 1 << 8, |
| 37 | [6] = 1 << 12, |
| 38 | [9] = 1 << 15, |
| 39 | }; |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 40 | |
| 41 | if (!mix && !dvc) |
| 42 | return 0; |
| 43 | |
Hiroyuki Yokoyama | a1c2ff5 | 2017-03-01 03:51:00 +0000 | [diff] [blame] | 44 | if (ARRAY_SIZE(path) < rsnd_mod_id(mod) + 1) |
| 45 | return -ENXIO; |
| 46 | |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 47 | if (mix) { |
| 48 | struct rsnd_dai *rdai; |
Kuninori Morimoto | 72154e5 | 2016-01-21 01:57:37 +0000 | [diff] [blame] | 49 | struct rsnd_mod *src; |
Kuninori Morimoto | 654a12b | 2016-01-21 01:57:17 +0000 | [diff] [blame] | 50 | struct rsnd_dai_stream *tio; |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 51 | int i; |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * it is assuming that integrater is well understanding about |
| 55 | * data path. Here doesn't check impossible connection, |
| 56 | * like src2 + src5 |
| 57 | */ |
| 58 | data = 0; |
| 59 | for_each_rsnd_dai(rdai, priv, i) { |
Kuninori Morimoto | 654a12b | 2016-01-21 01:57:17 +0000 | [diff] [blame] | 60 | tio = &rdai->playback; |
Kuninori Morimoto | 72154e5 | 2016-01-21 01:57:37 +0000 | [diff] [blame] | 61 | src = rsnd_io_to_mod_src(tio); |
Kuninori Morimoto | 654a12b | 2016-01-21 01:57:17 +0000 | [diff] [blame] | 62 | if (mix == rsnd_io_to_mod_mix(tio)) |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 63 | data |= path[rsnd_mod_id(src)]; |
| 64 | |
Kuninori Morimoto | 654a12b | 2016-01-21 01:57:17 +0000 | [diff] [blame] | 65 | tio = &rdai->capture; |
Kuninori Morimoto | 72154e5 | 2016-01-21 01:57:37 +0000 | [diff] [blame] | 66 | src = rsnd_io_to_mod_src(tio); |
Kuninori Morimoto | 654a12b | 2016-01-21 01:57:17 +0000 | [diff] [blame] | 67 | if (mix == rsnd_io_to_mod_mix(tio)) |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 68 | data |= path[rsnd_mod_id(src)]; |
| 69 | } |
| 70 | |
| 71 | } else { |
Kuninori Morimoto | 72154e5 | 2016-01-21 01:57:37 +0000 | [diff] [blame] | 72 | struct rsnd_mod *src = rsnd_io_to_mod_src(io); |
| 73 | |
Hiroyuki Yokoyama | a1c2ff5 | 2017-03-01 03:51:00 +0000 | [diff] [blame] | 74 | u8 cmd_case[] = { |
| 75 | [0] = 0x3, |
| 76 | [1] = 0x3, |
| 77 | [2] = 0x4, |
| 78 | [3] = 0x1, |
| 79 | [4] = 0x2, |
| 80 | [5] = 0x4, |
| 81 | [6] = 0x1, |
| 82 | [9] = 0x2, |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
Hiroyuki Yokoyama | a1c2ff5 | 2017-03-01 03:51:00 +0000 | [diff] [blame] | 85 | data = path[rsnd_mod_id(src)] | |
| 86 | cmd_case[rsnd_mod_id(src)] << 16; |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | dev_dbg(dev, "ctu/mix path = 0x%08x", data); |
| 90 | |
| 91 | rsnd_mod_write(mod, CMD_ROUTE_SLCT, data); |
Kuninori Morimoto | a504b1e | 2015-12-08 05:38:23 +0000 | [diff] [blame] | 92 | rsnd_mod_write(mod, CMD_BUSIF_DALIGN, rsnd_get_dalign(mod, io)); |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 93 | |
Kuninori Morimoto | dcc5a7b | 2015-11-04 08:43:33 +0000 | [diff] [blame] | 94 | rsnd_adg_set_cmd_timsel_gen2(mod, io); |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static int rsnd_cmd_start(struct rsnd_mod *mod, |
| 100 | struct rsnd_dai_stream *io, |
| 101 | struct rsnd_priv *priv) |
| 102 | { |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 103 | rsnd_mod_write(mod, CMD_CTRL, 0x10); |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
Kuninori Morimoto | dcc5a7b | 2015-11-04 08:43:33 +0000 | [diff] [blame] | 108 | static int rsnd_cmd_stop(struct rsnd_mod *mod, |
| 109 | struct rsnd_dai_stream *io, |
| 110 | struct rsnd_priv *priv) |
| 111 | { |
| 112 | rsnd_mod_write(mod, CMD_CTRL, 0); |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 117 | static struct rsnd_mod_ops rsnd_cmd_ops = { |
| 118 | .name = CMD_NAME, |
| 119 | .init = rsnd_cmd_init, |
Kuninori Morimoto | dcc5a7b | 2015-11-04 08:43:33 +0000 | [diff] [blame] | 120 | .start = rsnd_cmd_start, |
| 121 | .stop = rsnd_cmd_stop, |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id) |
| 125 | { |
| 126 | struct rsnd_priv *priv = rsnd_io_to_priv(io); |
| 127 | struct rsnd_mod *mod = rsnd_cmd_mod_get(priv, id); |
| 128 | |
| 129 | return rsnd_dai_connect(mod, io, mod->type); |
| 130 | } |
| 131 | |
| 132 | struct rsnd_mod *rsnd_cmd_mod_get(struct rsnd_priv *priv, int id) |
| 133 | { |
| 134 | if (WARN_ON(id < 0 || id >= rsnd_cmd_nr(priv))) |
| 135 | id = 0; |
| 136 | |
| 137 | return rsnd_mod_get((struct rsnd_cmd *)(priv->cmd) + id); |
| 138 | } |
| 139 | |
Kuninori Morimoto | 2ea6b07 | 2015-11-10 05:14:12 +0000 | [diff] [blame] | 140 | int rsnd_cmd_probe(struct rsnd_priv *priv) |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 141 | { |
| 142 | struct device *dev = rsnd_priv_to_dev(priv); |
| 143 | struct rsnd_cmd *cmd; |
| 144 | int i, nr, ret; |
| 145 | |
| 146 | /* This driver doesn't support Gen1 at this point */ |
| 147 | if (rsnd_is_gen1(priv)) |
| 148 | return 0; |
| 149 | |
| 150 | /* same number as DVC */ |
| 151 | nr = priv->dvc_nr; |
| 152 | if (!nr) |
| 153 | return 0; |
| 154 | |
| 155 | cmd = devm_kzalloc(dev, sizeof(*cmd) * nr, GFP_KERNEL); |
| 156 | if (!cmd) |
| 157 | return -ENOMEM; |
| 158 | |
| 159 | priv->cmd_nr = nr; |
| 160 | priv->cmd = cmd; |
| 161 | |
| 162 | for_each_rsnd_cmd(cmd, priv, i) { |
| 163 | ret = rsnd_mod_init(priv, rsnd_mod_get(cmd), |
Kuninori Morimoto | 5ba17b42 | 2016-01-21 01:58:07 +0000 | [diff] [blame] | 164 | &rsnd_cmd_ops, NULL, |
| 165 | rsnd_mod_get_status, RSND_MOD_CMD, i); |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 166 | if (ret) |
| 167 | return ret; |
| 168 | } |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
Kuninori Morimoto | 2ea6b07 | 2015-11-10 05:14:12 +0000 | [diff] [blame] | 173 | void rsnd_cmd_remove(struct rsnd_priv *priv) |
Kuninori Morimoto | 1b2ca0a | 2015-10-26 08:43:21 +0000 | [diff] [blame] | 174 | { |
| 175 | struct rsnd_cmd *cmd; |
| 176 | int i; |
| 177 | |
| 178 | for_each_rsnd_cmd(cmd, priv, i) { |
| 179 | rsnd_mod_quit(rsnd_mod_get(cmd)); |
| 180 | } |
| 181 | } |