blob: b267fe8db3fca7ce355d5b46fefacfe3e0f7171f [file] [log] [blame]
Thomas Gleixner97fb5e82019-05-29 07:17:58 -07001// SPDX-License-Identifier: GPL-2.0-only
Kenneth Westfield80beab82015-03-03 16:21:54 -08002/*
3 * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved.
4 *
Kenneth Westfield80beab82015-03-03 16:21:54 -08005 * lpass-cpu.c -- ALSA SoC CPU DAI driver for QTi LPASS
6 */
7
8#include <linux/clk.h>
Kenneth Westfield80beab82015-03-03 16:21:54 -08009#include <linux/kernel.h>
Kenneth Westfield80beab82015-03-03 16:21:54 -080010#include <linux/module.h>
11#include <linux/of.h>
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +010012#include <linux/of_device.h>
Kenneth Westfield80beab82015-03-03 16:21:54 -080013#include <linux/platform_device.h>
14#include <sound/pcm.h>
15#include <sound/pcm_params.h>
16#include <linux/regmap.h>
17#include <sound/soc.h>
18#include <sound/soc-dai.h>
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +010019#include "lpass-lpaif-reg.h"
Kenneth Westfield80beab82015-03-03 16:21:54 -080020#include "lpass.h"
21
Stephan Gerhold4ff028f62020-04-25 20:46:57 +020022#define LPASS_CPU_MAX_MI2S_LINES 4
23#define LPASS_CPU_I2S_SD0_MASK BIT(0)
24#define LPASS_CPU_I2S_SD1_MASK BIT(1)
25#define LPASS_CPU_I2S_SD2_MASK BIT(2)
26#define LPASS_CPU_I2S_SD3_MASK BIT(3)
27#define LPASS_CPU_I2S_SD0_1_MASK GENMASK(1, 0)
28#define LPASS_CPU_I2S_SD2_3_MASK GENMASK(3, 2)
29#define LPASS_CPU_I2S_SD0_1_2_MASK GENMASK(2, 0)
30#define LPASS_CPU_I2S_SD0_1_2_3_MASK GENMASK(3, 0)
31
Rohit kumarb5022a32020-08-14 16:23:01 +053032static int lpass_cpu_init_i2sctl_bitfields(struct device *dev,
33 struct lpaif_i2sctl *i2sctl, struct regmap *map)
34{
35 struct lpass_data *drvdata = dev_get_drvdata(dev);
36 struct lpass_variant *v = drvdata->variant;
37
38 i2sctl->loopback = devm_regmap_field_alloc(dev, map, v->loopback);
39 i2sctl->spken = devm_regmap_field_alloc(dev, map, v->spken);
40 i2sctl->spkmode = devm_regmap_field_alloc(dev, map, v->spkmode);
41 i2sctl->spkmono = devm_regmap_field_alloc(dev, map, v->spkmono);
42 i2sctl->micen = devm_regmap_field_alloc(dev, map, v->micen);
43 i2sctl->micmode = devm_regmap_field_alloc(dev, map, v->micmode);
44 i2sctl->micmono = devm_regmap_field_alloc(dev, map, v->micmono);
45 i2sctl->wssrc = devm_regmap_field_alloc(dev, map, v->wssrc);
46 i2sctl->bitwidth = devm_regmap_field_alloc(dev, map, v->bitwidth);
47
48 if (IS_ERR(i2sctl->loopback) || IS_ERR(i2sctl->spken) ||
49 IS_ERR(i2sctl->spkmode) || IS_ERR(i2sctl->spkmono) ||
50 IS_ERR(i2sctl->micen) || IS_ERR(i2sctl->micmode) ||
51 IS_ERR(i2sctl->micmono) || IS_ERR(i2sctl->wssrc) ||
52 IS_ERR(i2sctl->bitwidth))
53 return -EINVAL;
54
55 return 0;
56}
57
Kenneth Westfield80beab82015-03-03 16:21:54 -080058static int lpass_cpu_daiops_set_sysclk(struct snd_soc_dai *dai, int clk_id,
59 unsigned int freq, int dir)
60{
61 struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
62 int ret;
63
Srinivas Kandagatla9a127cf2015-05-21 22:52:49 +010064 ret = clk_set_rate(drvdata->mi2s_osr_clk[dai->driver->id], freq);
Kenneth Westfield80beab82015-03-03 16:21:54 -080065 if (ret)
Bjorn Anderssonb6e643a2017-01-30 13:03:37 -080066 dev_err(dai->dev, "error setting mi2s osrclk to %u: %d\n",
67 freq, ret);
Kenneth Westfield80beab82015-03-03 16:21:54 -080068
69 return ret;
70}
71
72static int lpass_cpu_daiops_startup(struct snd_pcm_substream *substream,
73 struct snd_soc_dai *dai)
74{
75 struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
76 int ret;
77
Bjorn Andersson46dccc32017-01-30 13:03:36 -080078 ret = clk_prepare_enable(drvdata->mi2s_osr_clk[dai->driver->id]);
79 if (ret) {
Bjorn Anderssonb6e643a2017-01-30 13:03:37 -080080 dev_err(dai->dev, "error in enabling mi2s osr clk: %d\n", ret);
Bjorn Andersson46dccc32017-01-30 13:03:36 -080081 return ret;
Kenneth Westfield80beab82015-03-03 16:21:54 -080082 }
V Sujith Kumar Reddy6ec6c362020-10-19 14:36:03 +053083 ret = clk_prepare(drvdata->mi2s_bit_clk[dai->driver->id]);
84 if (ret) {
85 dev_err(dai->dev, "error in enabling mi2s bit clk: %d\n", ret);
86 clk_disable_unprepare(drvdata->mi2s_osr_clk[dai->driver->id]);
87 return ret;
88 }
Kenneth Westfield80beab82015-03-03 16:21:54 -080089 return 0;
90}
91
92static void lpass_cpu_daiops_shutdown(struct snd_pcm_substream *substream,
93 struct snd_soc_dai *dai)
94{
95 struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
96
Bjorn Andersson46dccc32017-01-30 13:03:36 -080097 clk_disable_unprepare(drvdata->mi2s_osr_clk[dai->driver->id]);
V Sujith Kumar Reddy6ec6c362020-10-19 14:36:03 +053098 clk_unprepare(drvdata->mi2s_bit_clk[dai->driver->id]);
Kenneth Westfield80beab82015-03-03 16:21:54 -080099}
100
101static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream,
102 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
103{
104 struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
Rohit kumarb5022a32020-08-14 16:23:01 +0530105 struct lpaif_i2sctl *i2sctl = drvdata->i2sctl;
106 unsigned int id = dai->driver->id;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800107 snd_pcm_format_t format = params_format(params);
108 unsigned int channels = params_channels(params);
109 unsigned int rate = params_rate(params);
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200110 unsigned int mode;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800111 unsigned int regval;
112 int bitwidth, ret;
113
114 bitwidth = snd_pcm_format_width(format);
115 if (bitwidth < 0) {
Bjorn Anderssonb6e643a2017-01-30 13:03:37 -0800116 dev_err(dai->dev, "invalid bit width given: %d\n", bitwidth);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800117 return bitwidth;
118 }
119
Rohit kumarb5022a32020-08-14 16:23:01 +0530120 ret = regmap_fields_write(i2sctl->loopback, id,
121 LPAIF_I2SCTL_LOOPBACK_DISABLE);
122 if (ret) {
123 dev_err(dai->dev, "error updating loopback field: %d\n", ret);
124 return ret;
125 }
126
127 ret = regmap_fields_write(i2sctl->wssrc, id,
128 LPAIF_I2SCTL_WSSRC_INTERNAL);
129 if (ret) {
130 dev_err(dai->dev, "error updating wssrc field: %d\n", ret);
131 return ret;
132 }
Kenneth Westfield80beab82015-03-03 16:21:54 -0800133
134 switch (bitwidth) {
135 case 16:
Rohit kumarb5022a32020-08-14 16:23:01 +0530136 regval = LPAIF_I2SCTL_BITWIDTH_16;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800137 break;
138 case 24:
Rohit kumarb5022a32020-08-14 16:23:01 +0530139 regval = LPAIF_I2SCTL_BITWIDTH_24;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800140 break;
141 case 32:
Rohit kumarb5022a32020-08-14 16:23:01 +0530142 regval = LPAIF_I2SCTL_BITWIDTH_32;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800143 break;
144 default:
Bjorn Anderssonb6e643a2017-01-30 13:03:37 -0800145 dev_err(dai->dev, "invalid bitwidth given: %d\n", bitwidth);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800146 return -EINVAL;
147 }
148
Rohit kumarb5022a32020-08-14 16:23:01 +0530149 ret = regmap_fields_write(i2sctl->bitwidth, id, regval);
150 if (ret) {
151 dev_err(dai->dev, "error updating bitwidth field: %d\n", ret);
152 return ret;
153 }
154
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200155 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Rohit kumarb5022a32020-08-14 16:23:01 +0530156 mode = drvdata->mi2s_playback_sd_mode[id];
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200157 else
Rohit kumarb5022a32020-08-14 16:23:01 +0530158 mode = drvdata->mi2s_capture_sd_mode[id];
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200159
160 if (!mode) {
161 dev_err(dai->dev, "no line is assigned\n");
162 return -EINVAL;
163 }
164
165 switch (channels) {
166 case 1:
167 case 2:
168 switch (mode) {
169 case LPAIF_I2SCTL_MODE_QUAD01:
170 case LPAIF_I2SCTL_MODE_6CH:
171 case LPAIF_I2SCTL_MODE_8CH:
172 mode = LPAIF_I2SCTL_MODE_SD0;
173 break;
174 case LPAIF_I2SCTL_MODE_QUAD23:
175 mode = LPAIF_I2SCTL_MODE_SD2;
176 break;
177 }
178
179 break;
180 case 4:
181 if (mode < LPAIF_I2SCTL_MODE_QUAD01) {
182 dev_err(dai->dev, "cannot configure 4 channels with mode %d\n",
183 mode);
184 return -EINVAL;
185 }
186
187 switch (mode) {
188 case LPAIF_I2SCTL_MODE_6CH:
189 case LPAIF_I2SCTL_MODE_8CH:
190 mode = LPAIF_I2SCTL_MODE_QUAD01;
191 break;
192 }
193 break;
194 case 6:
195 if (mode < LPAIF_I2SCTL_MODE_6CH) {
196 dev_err(dai->dev, "cannot configure 6 channels with mode %d\n",
197 mode);
198 return -EINVAL;
199 }
200
201 switch (mode) {
202 case LPAIF_I2SCTL_MODE_8CH:
203 mode = LPAIF_I2SCTL_MODE_6CH;
204 break;
205 }
206 break;
207 case 8:
208 if (mode < LPAIF_I2SCTL_MODE_8CH) {
209 dev_err(dai->dev, "cannot configure 8 channels with mode %d\n",
210 mode);
211 return -EINVAL;
212 }
213 break;
214 default:
215 dev_err(dai->dev, "invalid channels given: %u\n", channels);
216 return -EINVAL;
217 }
218
Srinivas Kandagatlafb5d1152016-02-11 12:18:33 +0000219 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Rohit kumarb5022a32020-08-14 16:23:01 +0530220 ret = regmap_fields_write(i2sctl->spkmode, id,
221 LPAIF_I2SCTL_SPKMODE(mode));
222 if (ret) {
223 dev_err(dai->dev, "error writing to i2sctl spkr mode: %d\n",
224 ret);
225 return ret;
226 }
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200227 if (channels >= 2)
Rohit kumarb5022a32020-08-14 16:23:01 +0530228 ret = regmap_fields_write(i2sctl->spkmono, id,
229 LPAIF_I2SCTL_SPKMONO_STEREO);
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200230 else
Rohit kumarb5022a32020-08-14 16:23:01 +0530231 ret = regmap_fields_write(i2sctl->spkmono, id,
232 LPAIF_I2SCTL_SPKMONO_MONO);
Srinivas Kandagatlafb5d1152016-02-11 12:18:33 +0000233 } else {
Rohit kumarb5022a32020-08-14 16:23:01 +0530234 ret = regmap_fields_write(i2sctl->micmode, id,
235 LPAIF_I2SCTL_MICMODE(mode));
236 if (ret) {
237 dev_err(dai->dev, "error writing to i2sctl mic mode: %d\n",
238 ret);
239 return ret;
240 }
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200241 if (channels >= 2)
Rohit kumarb5022a32020-08-14 16:23:01 +0530242 ret = regmap_fields_write(i2sctl->micmono, id,
243 LPAIF_I2SCTL_MICMONO_STEREO);
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200244 else
Rohit kumarb5022a32020-08-14 16:23:01 +0530245 ret = regmap_fields_write(i2sctl->micmono, id,
246 LPAIF_I2SCTL_MICMONO_MONO);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800247 }
248
Kenneth Westfield80beab82015-03-03 16:21:54 -0800249 if (ret) {
Rohit kumarb5022a32020-08-14 16:23:01 +0530250 dev_err(dai->dev, "error writing to i2sctl channels mode: %d\n",
251 ret);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800252 return ret;
253 }
254
Rohit kumarb5022a32020-08-14 16:23:01 +0530255 ret = clk_set_rate(drvdata->mi2s_bit_clk[id],
Srinivas Kandagatla9a127cf2015-05-21 22:52:49 +0100256 rate * bitwidth * 2);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800257 if (ret) {
Bjorn Anderssonb6e643a2017-01-30 13:03:37 -0800258 dev_err(dai->dev, "error setting mi2s bitclk to %u: %d\n",
259 rate * bitwidth * 2, ret);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800260 return ret;
261 }
262
263 return 0;
264}
265
Kenneth Westfield80beab82015-03-03 16:21:54 -0800266static int lpass_cpu_daiops_trigger(struct snd_pcm_substream *substream,
267 int cmd, struct snd_soc_dai *dai)
268{
269 struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
Rohit kumarb5022a32020-08-14 16:23:01 +0530270 struct lpaif_i2sctl *i2sctl = drvdata->i2sctl;
271 unsigned int id = dai->driver->id;
Takashi Iwai96f05be2015-04-13 14:23:29 +0200272 int ret = -EINVAL;
Srinivasa Rao Mandadapub18249682020-11-23 21:47:53 +0530273 unsigned int val = 0;
274
275 ret = regmap_read(drvdata->lpaif_map,
276 LPAIF_I2SCTL_REG(drvdata->variant, dai->driver->id), &val);
277 if (ret) {
278 dev_err(dai->dev, "error reading from i2sctl reg: %d\n", ret);
279 return ret;
280 }
281 if (val == LPAIF_I2SCTL_RESET_STATE) {
282 dev_err(dai->dev, "error in i2sctl register state\n");
283 return -ENOTRECOVERABLE;
284 }
Kenneth Westfield80beab82015-03-03 16:21:54 -0800285
286 switch (cmd) {
287 case SNDRV_PCM_TRIGGER_START:
288 case SNDRV_PCM_TRIGGER_RESUME:
289 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Srinivas Kandagatlafb5d1152016-02-11 12:18:33 +0000290 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Rohit kumarb5022a32020-08-14 16:23:01 +0530291 ret = regmap_fields_write(i2sctl->spken, id,
292 LPAIF_I2SCTL_SPKEN_ENABLE);
Srinivas Kandagatlafb5d1152016-02-11 12:18:33 +0000293 } else {
Rohit kumarb5022a32020-08-14 16:23:01 +0530294 ret = regmap_fields_write(i2sctl->micen, id,
295 LPAIF_I2SCTL_MICEN_ENABLE);
Srinivas Kandagatlafb5d1152016-02-11 12:18:33 +0000296 }
Kenneth Westfield80beab82015-03-03 16:21:54 -0800297 if (ret)
Bjorn Anderssonb6e643a2017-01-30 13:03:37 -0800298 dev_err(dai->dev, "error writing to i2sctl reg: %d\n",
299 ret);
V Sujith Kumar Reddy7e6799d2020-09-18 22:24:33 +0530300
Srinivasa Rao Mandadapub18249682020-11-23 21:47:53 +0530301 if (drvdata->bit_clk_state[id] == LPAIF_BIT_CLK_DISABLE) {
302 ret = clk_enable(drvdata->mi2s_bit_clk[id]);
303 if (ret) {
304 dev_err(dai->dev, "error in enabling mi2s bit clk: %d\n", ret);
305 clk_disable(drvdata->mi2s_osr_clk[id]);
306 return ret;
307 }
308 drvdata->bit_clk_state[id] = LPAIF_BIT_CLK_ENABLE;
V Sujith Kumar Reddy7e6799d2020-09-18 22:24:33 +0530309 }
310
Kenneth Westfield80beab82015-03-03 16:21:54 -0800311 break;
312 case SNDRV_PCM_TRIGGER_STOP:
313 case SNDRV_PCM_TRIGGER_SUSPEND:
314 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Srinivas Kandagatlafb5d1152016-02-11 12:18:33 +0000315 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Rohit kumarb5022a32020-08-14 16:23:01 +0530316 ret = regmap_fields_write(i2sctl->spken, id,
317 LPAIF_I2SCTL_SPKEN_DISABLE);
Srinivas Kandagatlafb5d1152016-02-11 12:18:33 +0000318 } else {
Rohit kumarb5022a32020-08-14 16:23:01 +0530319 ret = regmap_fields_write(i2sctl->micen, id,
320 LPAIF_I2SCTL_MICEN_DISABLE);
Srinivas Kandagatlafb5d1152016-02-11 12:18:33 +0000321 }
Kenneth Westfield80beab82015-03-03 16:21:54 -0800322 if (ret)
Bjorn Anderssonb6e643a2017-01-30 13:03:37 -0800323 dev_err(dai->dev, "error writing to i2sctl reg: %d\n",
324 ret);
Srinivasa Rao Mandadapub18249682020-11-23 21:47:53 +0530325 if (drvdata->bit_clk_state[id] == LPAIF_BIT_CLK_ENABLE) {
326 clk_disable(drvdata->mi2s_bit_clk[dai->driver->id]);
327 drvdata->bit_clk_state[id] = LPAIF_BIT_CLK_DISABLE;
328 }
Kenneth Westfield80beab82015-03-03 16:21:54 -0800329 break;
330 }
331
332 return ret;
333}
334
Axel Lin618718d2015-08-28 10:53:31 +0800335const struct snd_soc_dai_ops asoc_qcom_lpass_cpu_dai_ops = {
Kenneth Westfield80beab82015-03-03 16:21:54 -0800336 .set_sysclk = lpass_cpu_daiops_set_sysclk,
337 .startup = lpass_cpu_daiops_startup,
338 .shutdown = lpass_cpu_daiops_shutdown,
339 .hw_params = lpass_cpu_daiops_hw_params,
Kenneth Westfield80beab82015-03-03 16:21:54 -0800340 .trigger = lpass_cpu_daiops_trigger,
341};
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100342EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_dai_ops);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800343
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100344int asoc_qcom_lpass_cpu_dai_probe(struct snd_soc_dai *dai)
Kenneth Westfield80beab82015-03-03 16:21:54 -0800345{
346 struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
347 int ret;
348
349 /* ensure audio hardware is disabled */
350 ret = regmap_write(drvdata->lpaif_map,
Srinivas Kandagatla0ae9fd32015-05-16 13:32:25 +0100351 LPAIF_I2SCTL_REG(drvdata->variant, dai->driver->id), 0);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800352 if (ret)
Bjorn Anderssonb6e643a2017-01-30 13:03:37 -0800353 dev_err(dai->dev, "error writing to i2sctl reg: %d\n", ret);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800354
355 return ret;
356}
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100357EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_dai_probe);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800358
359static const struct snd_soc_component_driver lpass_cpu_comp_driver = {
360 .name = "lpass-cpu",
361};
362
363static bool lpass_cpu_regmap_writeable(struct device *dev, unsigned int reg)
364{
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100365 struct lpass_data *drvdata = dev_get_drvdata(dev);
366 struct lpass_variant *v = drvdata->variant;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800367 int i;
368
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100369 for (i = 0; i < v->i2s_ports; ++i)
370 if (reg == LPAIF_I2SCTL_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800371 return true;
372
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100373 for (i = 0; i < v->irq_ports; ++i) {
374 if (reg == LPAIF_IRQEN_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800375 return true;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100376 if (reg == LPAIF_IRQCLEAR_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800377 return true;
378 }
379
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100380 for (i = 0; i < v->rdma_channels; ++i) {
381 if (reg == LPAIF_RDMACTL_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800382 return true;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100383 if (reg == LPAIF_RDMABASE_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800384 return true;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100385 if (reg == LPAIF_RDMABUFF_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800386 return true;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100387 if (reg == LPAIF_RDMAPER_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800388 return true;
389 }
390
Srinivas Kandagatladad80612016-02-11 12:18:27 +0000391 for (i = 0; i < v->wrdma_channels; ++i) {
392 if (reg == LPAIF_WRDMACTL_REG(v, i + v->wrdma_channel_start))
393 return true;
394 if (reg == LPAIF_WRDMABASE_REG(v, i + v->wrdma_channel_start))
395 return true;
396 if (reg == LPAIF_WRDMABUFF_REG(v, i + v->wrdma_channel_start))
397 return true;
398 if (reg == LPAIF_WRDMAPER_REG(v, i + v->wrdma_channel_start))
399 return true;
400 }
401
Kenneth Westfield80beab82015-03-03 16:21:54 -0800402 return false;
403}
404
405static bool lpass_cpu_regmap_readable(struct device *dev, unsigned int reg)
406{
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100407 struct lpass_data *drvdata = dev_get_drvdata(dev);
408 struct lpass_variant *v = drvdata->variant;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800409 int i;
410
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100411 for (i = 0; i < v->i2s_ports; ++i)
412 if (reg == LPAIF_I2SCTL_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800413 return true;
414
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100415 for (i = 0; i < v->irq_ports; ++i) {
416 if (reg == LPAIF_IRQEN_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800417 return true;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100418 if (reg == LPAIF_IRQSTAT_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800419 return true;
420 }
421
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100422 for (i = 0; i < v->rdma_channels; ++i) {
423 if (reg == LPAIF_RDMACTL_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800424 return true;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100425 if (reg == LPAIF_RDMABASE_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800426 return true;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100427 if (reg == LPAIF_RDMABUFF_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800428 return true;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100429 if (reg == LPAIF_RDMACURR_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800430 return true;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100431 if (reg == LPAIF_RDMAPER_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800432 return true;
433 }
434
Srinivas Kandagatladad80612016-02-11 12:18:27 +0000435 for (i = 0; i < v->wrdma_channels; ++i) {
436 if (reg == LPAIF_WRDMACTL_REG(v, i + v->wrdma_channel_start))
437 return true;
438 if (reg == LPAIF_WRDMABASE_REG(v, i + v->wrdma_channel_start))
439 return true;
440 if (reg == LPAIF_WRDMABUFF_REG(v, i + v->wrdma_channel_start))
441 return true;
442 if (reg == LPAIF_WRDMACURR_REG(v, i + v->wrdma_channel_start))
443 return true;
444 if (reg == LPAIF_WRDMAPER_REG(v, i + v->wrdma_channel_start))
445 return true;
446 }
447
Kenneth Westfield80beab82015-03-03 16:21:54 -0800448 return false;
449}
450
451static bool lpass_cpu_regmap_volatile(struct device *dev, unsigned int reg)
452{
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100453 struct lpass_data *drvdata = dev_get_drvdata(dev);
454 struct lpass_variant *v = drvdata->variant;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800455 int i;
456
Srinivasa Rao Mandadapub18249682020-11-23 21:47:53 +0530457 for (i = 0; i < v->i2s_ports; ++i)
458 if (reg == LPAIF_I2SCTL_REG(v, i))
459 return true;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100460 for (i = 0; i < v->irq_ports; ++i)
461 if (reg == LPAIF_IRQSTAT_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800462 return true;
463
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100464 for (i = 0; i < v->rdma_channels; ++i)
Srinivasa Rao Mandadapub18249682020-11-23 21:47:53 +0530465 if (reg == LPAIF_RDMACURR_REG(v, i) || reg == LPAIF_RDMACTL_REG(v, i))
Kenneth Westfield80beab82015-03-03 16:21:54 -0800466 return true;
467
Srinivas Kandagatladad80612016-02-11 12:18:27 +0000468 for (i = 0; i < v->wrdma_channels; ++i)
Srinivasa Rao Mandadapub18249682020-11-23 21:47:53 +0530469 if (reg == LPAIF_WRDMACURR_REG(v, i + v->wrdma_channel_start) ||
470 reg == LPAIF_WRDMACTL_REG(v, i + v->wrdma_channel_start))
Srinivas Kandagatladad80612016-02-11 12:18:27 +0000471 return true;
472
Kenneth Westfield80beab82015-03-03 16:21:54 -0800473 return false;
474}
475
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100476static struct regmap_config lpass_cpu_regmap_config = {
Stephen Boyd03b49bf2021-01-14 19:43:25 -0800477 .name = "lpass_cpu",
Kenneth Westfield80beab82015-03-03 16:21:54 -0800478 .reg_bits = 32,
479 .reg_stride = 4,
480 .val_bits = 32,
Kenneth Westfield80beab82015-03-03 16:21:54 -0800481 .writeable_reg = lpass_cpu_regmap_writeable,
482 .readable_reg = lpass_cpu_regmap_readable,
483 .volatile_reg = lpass_cpu_regmap_volatile,
484 .cache_type = REGCACHE_FLAT,
485};
486
V Sujith Kumar Reddy7cb37b72020-10-08 10:47:01 +0530487static int lpass_hdmi_init_bitfields(struct device *dev, struct regmap *map)
488{
489 struct lpass_data *drvdata = dev_get_drvdata(dev);
490 struct lpass_variant *v = drvdata->variant;
491 unsigned int i;
492 struct lpass_hdmi_tx_ctl *tx_ctl;
493 struct regmap_field *legacy_en;
494 struct lpass_vbit_ctrl *vbit_ctl;
495 struct regmap_field *tx_parity;
496 struct lpass_dp_metadata_ctl *meta_ctl;
497 struct lpass_sstream_ctl *sstream_ctl;
498 struct regmap_field *ch_msb;
499 struct regmap_field *ch_lsb;
500 struct lpass_hdmitx_dmactl *tx_dmactl;
501 int rval;
502
503 tx_ctl = devm_kzalloc(dev, sizeof(*tx_ctl), GFP_KERNEL);
504 if (!tx_ctl)
505 return -ENOMEM;
506
507 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->soft_reset, tx_ctl->soft_reset);
508 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->force_reset, tx_ctl->force_reset);
509 drvdata->tx_ctl = tx_ctl;
510
511 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->legacy_en, legacy_en);
512 drvdata->hdmitx_legacy_en = legacy_en;
513
514 vbit_ctl = devm_kzalloc(dev, sizeof(*vbit_ctl), GFP_KERNEL);
515 if (!vbit_ctl)
516 return -ENOMEM;
517
518 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->replace_vbit, vbit_ctl->replace_vbit);
519 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->vbit_stream, vbit_ctl->vbit_stream);
520 drvdata->vbit_ctl = vbit_ctl;
521
522
523 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->calc_en, tx_parity);
524 drvdata->hdmitx_parity_calc_en = tx_parity;
525
526 meta_ctl = devm_kzalloc(dev, sizeof(*meta_ctl), GFP_KERNEL);
527 if (!meta_ctl)
528 return -ENOMEM;
529
530 rval = devm_regmap_field_bulk_alloc(dev, map, &meta_ctl->mute, &v->mute, 7);
531 if (rval)
532 return rval;
533 drvdata->meta_ctl = meta_ctl;
534
535 sstream_ctl = devm_kzalloc(dev, sizeof(*sstream_ctl), GFP_KERNEL);
536 if (!sstream_ctl)
537 return -ENOMEM;
538
539 rval = devm_regmap_field_bulk_alloc(dev, map, &sstream_ctl->sstream_en, &v->sstream_en, 9);
540 if (rval)
541 return rval;
542
543 drvdata->sstream_ctl = sstream_ctl;
544
545 for (i = 0; i < LPASS_MAX_HDMI_DMA_CHANNELS; i++) {
546 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->msb_bits, ch_msb);
547 drvdata->hdmitx_ch_msb[i] = ch_msb;
548
549 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->lsb_bits, ch_lsb);
550 drvdata->hdmitx_ch_lsb[i] = ch_lsb;
551
552 tx_dmactl = devm_kzalloc(dev, sizeof(*tx_dmactl), GFP_KERNEL);
553 if (!tx_dmactl)
554 return -ENOMEM;
555
556 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->use_hw_chs, tx_dmactl->use_hw_chs);
557 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->use_hw_usr, tx_dmactl->use_hw_usr);
558 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->hw_chs_sel, tx_dmactl->hw_chs_sel);
559 QCOM_REGMAP_FIELD_ALLOC(dev, map, v->hw_usr_sel, tx_dmactl->hw_usr_sel);
560 drvdata->hdmi_tx_dmactl[i] = tx_dmactl;
561 }
562 return 0;
563}
564
565static bool lpass_hdmi_regmap_writeable(struct device *dev, unsigned int reg)
566{
567 struct lpass_data *drvdata = dev_get_drvdata(dev);
568 struct lpass_variant *v = drvdata->variant;
569 int i;
570
571 if (reg == LPASS_HDMI_TX_CTL_ADDR(v))
572 return true;
573 if (reg == LPASS_HDMI_TX_LEGACY_ADDR(v))
574 return true;
575 if (reg == LPASS_HDMI_TX_VBIT_CTL_ADDR(v))
576 return true;
577 if (reg == LPASS_HDMI_TX_PARITY_ADDR(v))
578 return true;
579 if (reg == LPASS_HDMI_TX_DP_ADDR(v))
580 return true;
581 if (reg == LPASS_HDMI_TX_SSTREAM_ADDR(v))
582 return true;
583 if (reg == LPASS_HDMITX_APP_IRQEN_REG(v))
584 return true;
585 if (reg == LPASS_HDMITX_APP_IRQCLEAR_REG(v))
586 return true;
587
588 for (i = 0; i < v->hdmi_rdma_channels; i++) {
589 if (reg == LPASS_HDMI_TX_CH_LSB_ADDR(v, i))
590 return true;
591 if (reg == LPASS_HDMI_TX_CH_MSB_ADDR(v, i))
592 return true;
593 if (reg == LPASS_HDMI_TX_DMA_ADDR(v, i))
594 return true;
595 }
596
597 for (i = 0; i < v->rdma_channels; ++i) {
598 if (reg == LPAIF_HDMI_RDMACTL_REG(v, i))
599 return true;
600 if (reg == LPAIF_HDMI_RDMABASE_REG(v, i))
601 return true;
602 if (reg == LPAIF_HDMI_RDMABUFF_REG(v, i))
603 return true;
604 if (reg == LPAIF_HDMI_RDMAPER_REG(v, i))
605 return true;
606 }
607 return false;
608}
609
610static bool lpass_hdmi_regmap_readable(struct device *dev, unsigned int reg)
611{
612 struct lpass_data *drvdata = dev_get_drvdata(dev);
613 struct lpass_variant *v = drvdata->variant;
614 int i;
615
616 if (reg == LPASS_HDMI_TX_CTL_ADDR(v))
617 return true;
618 if (reg == LPASS_HDMI_TX_LEGACY_ADDR(v))
619 return true;
620 if (reg == LPASS_HDMI_TX_VBIT_CTL_ADDR(v))
621 return true;
622
623 for (i = 0; i < v->hdmi_rdma_channels; i++) {
624 if (reg == LPASS_HDMI_TX_CH_LSB_ADDR(v, i))
625 return true;
626 if (reg == LPASS_HDMI_TX_CH_MSB_ADDR(v, i))
627 return true;
628 if (reg == LPASS_HDMI_TX_DMA_ADDR(v, i))
629 return true;
630 }
631
632 if (reg == LPASS_HDMI_TX_PARITY_ADDR(v))
633 return true;
634 if (reg == LPASS_HDMI_TX_DP_ADDR(v))
635 return true;
636 if (reg == LPASS_HDMI_TX_SSTREAM_ADDR(v))
637 return true;
638 if (reg == LPASS_HDMITX_APP_IRQEN_REG(v))
639 return true;
640 if (reg == LPASS_HDMITX_APP_IRQSTAT_REG(v))
641 return true;
642
643 for (i = 0; i < v->rdma_channels; ++i) {
644 if (reg == LPAIF_HDMI_RDMACTL_REG(v, i))
645 return true;
646 if (reg == LPAIF_HDMI_RDMABASE_REG(v, i))
647 return true;
648 if (reg == LPAIF_HDMI_RDMABUFF_REG(v, i))
649 return true;
650 if (reg == LPAIF_HDMI_RDMAPER_REG(v, i))
651 return true;
652 if (reg == LPAIF_HDMI_RDMACURR_REG(v, i))
653 return true;
654 }
655
656 return false;
657}
658
659static bool lpass_hdmi_regmap_volatile(struct device *dev, unsigned int reg)
660{
661 struct lpass_data *drvdata = dev_get_drvdata(dev);
662 struct lpass_variant *v = drvdata->variant;
663 int i;
664
665 if (reg == LPASS_HDMITX_APP_IRQSTAT_REG(v))
666 return true;
667 if (reg == LPASS_HDMI_TX_LEGACY_ADDR(v))
668 return true;
669
670 for (i = 0; i < v->rdma_channels; ++i) {
671 if (reg == LPAIF_HDMI_RDMACURR_REG(v, i))
672 return true;
673 }
674 return false;
675}
676
Srinivas Kandagatla20f64a12020-11-05 11:41:00 +0000677static struct regmap_config lpass_hdmi_regmap_config = {
Stephen Boyd03b49bf2021-01-14 19:43:25 -0800678 .name = "lpass_hdmi",
V Sujith Kumar Reddy7cb37b72020-10-08 10:47:01 +0530679 .reg_bits = 32,
680 .reg_stride = 4,
681 .val_bits = 32,
682 .writeable_reg = lpass_hdmi_regmap_writeable,
683 .readable_reg = lpass_hdmi_regmap_readable,
684 .volatile_reg = lpass_hdmi_regmap_volatile,
685 .cache_type = REGCACHE_FLAT,
686};
687
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200688static unsigned int of_lpass_cpu_parse_sd_lines(struct device *dev,
689 struct device_node *node,
690 const char *name)
691{
692 unsigned int lines[LPASS_CPU_MAX_MI2S_LINES];
693 unsigned int sd_line_mask = 0;
694 int num_lines, i;
695
696 num_lines = of_property_read_variable_u32_array(node, name, lines, 0,
697 LPASS_CPU_MAX_MI2S_LINES);
698 if (num_lines < 0)
699 return LPAIF_I2SCTL_MODE_NONE;
700
701 for (i = 0; i < num_lines; i++)
702 sd_line_mask |= BIT(lines[i]);
703
704 switch (sd_line_mask) {
705 case LPASS_CPU_I2S_SD0_MASK:
706 return LPAIF_I2SCTL_MODE_SD0;
707 case LPASS_CPU_I2S_SD1_MASK:
708 return LPAIF_I2SCTL_MODE_SD1;
709 case LPASS_CPU_I2S_SD2_MASK:
710 return LPAIF_I2SCTL_MODE_SD2;
711 case LPASS_CPU_I2S_SD3_MASK:
712 return LPAIF_I2SCTL_MODE_SD3;
713 case LPASS_CPU_I2S_SD0_1_MASK:
714 return LPAIF_I2SCTL_MODE_QUAD01;
715 case LPASS_CPU_I2S_SD2_3_MASK:
716 return LPAIF_I2SCTL_MODE_QUAD23;
717 case LPASS_CPU_I2S_SD0_1_2_MASK:
718 return LPAIF_I2SCTL_MODE_6CH;
719 case LPASS_CPU_I2S_SD0_1_2_3_MASK:
720 return LPAIF_I2SCTL_MODE_8CH;
721 default:
722 dev_err(dev, "Unsupported SD line mask: %#x\n", sd_line_mask);
723 return LPAIF_I2SCTL_MODE_NONE;
724 }
725}
726
727static void of_lpass_cpu_parse_dai_data(struct device *dev,
728 struct lpass_data *data)
729{
730 struct device_node *node;
731 int ret, id;
732
733 /* Allow all channels by default for backwards compatibility */
734 for (id = 0; id < data->variant->num_dai; id++) {
735 data->mi2s_playback_sd_mode[id] = LPAIF_I2SCTL_MODE_8CH;
736 data->mi2s_capture_sd_mode[id] = LPAIF_I2SCTL_MODE_8CH;
737 }
738
739 for_each_child_of_node(dev->of_node, node) {
740 ret = of_property_read_u32(node, "reg", &id);
741 if (ret || id < 0 || id >= data->variant->num_dai) {
742 dev_err(dev, "valid dai id not found: %d\n", ret);
743 continue;
744 }
V Sujith Kumar Reddy7cb37b72020-10-08 10:47:01 +0530745 if (id == LPASS_DP_RX) {
746 data->hdmi_port_enable = 1;
V Sujith Kumar Reddy7cb37b72020-10-08 10:47:01 +0530747 } else {
748 data->mi2s_playback_sd_mode[id] =
749 of_lpass_cpu_parse_sd_lines(dev, node,
750 "qcom,playback-sd-lines");
751 data->mi2s_capture_sd_mode[id] =
752 of_lpass_cpu_parse_sd_lines(dev, node,
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200753 "qcom,capture-sd-lines");
V Sujith Kumar Reddy7cb37b72020-10-08 10:47:01 +0530754 }
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200755 }
756}
757
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100758int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev)
Kenneth Westfield80beab82015-03-03 16:21:54 -0800759{
760 struct lpass_data *drvdata;
Kenneth Westfield8ebe1482015-03-13 00:54:17 -0700761 struct device_node *dsp_of_node;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800762 struct resource *res;
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100763 struct lpass_variant *variant;
764 struct device *dev = &pdev->dev;
765 const struct of_device_id *match;
Srinivas Kandagatla9a127cf2015-05-21 22:52:49 +0100766 int ret, i, dai_id;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800767
Kenneth Westfield8ebe1482015-03-13 00:54:17 -0700768 dsp_of_node = of_parse_phandle(pdev->dev.of_node, "qcom,adsp", 0);
769 if (dsp_of_node) {
Tang Bin952c0e22020-05-04 14:59:47 +0800770 dev_err(dev, "DSP exists and holds audio resources\n");
Kenneth Westfield8ebe1482015-03-13 00:54:17 -0700771 return -EBUSY;
772 }
773
Tang Bin952c0e22020-05-04 14:59:47 +0800774 drvdata = devm_kzalloc(dev, sizeof(struct lpass_data), GFP_KERNEL);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800775 if (!drvdata)
776 return -ENOMEM;
777 platform_set_drvdata(pdev, drvdata);
778
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100779 match = of_match_device(dev->driver->of_match_table, dev);
780 if (!match || !match->data)
781 return -EINVAL;
782
783 drvdata->variant = (struct lpass_variant *)match->data;
784 variant = drvdata->variant;
785
Stephan Gerhold4ff028f62020-04-25 20:46:57 +0200786 of_lpass_cpu_parse_dai_data(dev, drvdata);
787
V Sujith Kumar Reddy4049a3b2020-10-08 10:46:59 +0530788 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpass-lpaif");
Kenneth Westfield80beab82015-03-03 16:21:54 -0800789
Tang Bin952c0e22020-05-04 14:59:47 +0800790 drvdata->lpaif = devm_ioremap_resource(dev, res);
Stephen Boyde697df62021-01-14 19:43:26 -0800791 if (IS_ERR(drvdata->lpaif)) {
Tang Bin952c0e22020-05-04 14:59:47 +0800792 dev_err(dev, "error mapping reg resource: %ld\n",
Stephen Boyde697df62021-01-14 19:43:26 -0800793 PTR_ERR(drvdata->lpaif));
794 return PTR_ERR(drvdata->lpaif);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800795 }
796
Srinivas Kandagatladad80612016-02-11 12:18:27 +0000797 lpass_cpu_regmap_config.max_register = LPAIF_WRDMAPER_REG(variant,
798 variant->wrdma_channels +
799 variant->wrdma_channel_start);
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100800
Tang Bin952c0e22020-05-04 14:59:47 +0800801 drvdata->lpaif_map = devm_regmap_init_mmio(dev, drvdata->lpaif,
Kenneth Westfield80beab82015-03-03 16:21:54 -0800802 &lpass_cpu_regmap_config);
803 if (IS_ERR(drvdata->lpaif_map)) {
Tang Bin952c0e22020-05-04 14:59:47 +0800804 dev_err(dev, "error initializing regmap: %ld\n",
Bjorn Anderssonb6e643a2017-01-30 13:03:37 -0800805 PTR_ERR(drvdata->lpaif_map));
Kenneth Westfield80beab82015-03-03 16:21:54 -0800806 return PTR_ERR(drvdata->lpaif_map);
807 }
808
V Sujith Kumar Reddy7cb37b72020-10-08 10:47:01 +0530809 if (drvdata->hdmi_port_enable) {
810 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpass-hdmiif");
811
812 drvdata->hdmiif = devm_ioremap_resource(dev, res);
Stephen Boyde697df62021-01-14 19:43:26 -0800813 if (IS_ERR(drvdata->hdmiif)) {
V Sujith Kumar Reddy7cb37b72020-10-08 10:47:01 +0530814 dev_err(dev, "error mapping reg resource: %ld\n",
Stephen Boyde697df62021-01-14 19:43:26 -0800815 PTR_ERR(drvdata->hdmiif));
816 return PTR_ERR(drvdata->hdmiif);
V Sujith Kumar Reddy7cb37b72020-10-08 10:47:01 +0530817 }
818
819 lpass_hdmi_regmap_config.max_register = LPAIF_HDMI_RDMAPER_REG(variant,
820 variant->hdmi_rdma_channels);
821 drvdata->hdmiif_map = devm_regmap_init_mmio(dev, drvdata->hdmiif,
822 &lpass_hdmi_regmap_config);
823 if (IS_ERR(drvdata->hdmiif_map)) {
824 dev_err(dev, "error initializing regmap: %ld\n",
825 PTR_ERR(drvdata->hdmiif_map));
826 return PTR_ERR(drvdata->hdmiif_map);
827 }
828 }
829
Rohit kumara5035672020-08-14 16:22:58 +0530830 if (variant->init) {
831 ret = variant->init(pdev);
832 if (ret) {
833 dev_err(dev, "error initializing variant: %d\n", ret);
834 return ret;
835 }
836 }
Kenneth Westfield80beab82015-03-03 16:21:54 -0800837
Srinivas Kandagatla9a127cf2015-05-21 22:52:49 +0100838 for (i = 0; i < variant->num_dai; i++) {
839 dai_id = variant->dai_driver[i].id;
V Sujith Kumar Reddy7cb37b72020-10-08 10:47:01 +0530840 if (dai_id == LPASS_DP_RX)
841 continue;
842
Tang Bin952c0e22020-05-04 14:59:47 +0800843 drvdata->mi2s_osr_clk[dai_id] = devm_clk_get(dev,
Linus Walleij97c52eb2017-04-05 10:34:10 +0200844 variant->dai_osr_clk_names[i]);
Srinivas Kandagatla9a127cf2015-05-21 22:52:49 +0100845 if (IS_ERR(drvdata->mi2s_osr_clk[dai_id])) {
Tang Bin952c0e22020-05-04 14:59:47 +0800846 dev_warn(dev,
Linus Walleij97c52eb2017-04-05 10:34:10 +0200847 "%s() error getting optional %s: %ld\n",
848 __func__,
849 variant->dai_osr_clk_names[i],
Srinivas Kandagatla9a127cf2015-05-21 22:52:49 +0100850 PTR_ERR(drvdata->mi2s_osr_clk[dai_id]));
Bjorn Andersson46dccc32017-01-30 13:03:36 -0800851
852 drvdata->mi2s_osr_clk[dai_id] = NULL;
Srinivas Kandagatla9a127cf2015-05-21 22:52:49 +0100853 }
854
Tang Bin952c0e22020-05-04 14:59:47 +0800855 drvdata->mi2s_bit_clk[dai_id] = devm_clk_get(dev,
Linus Walleij97c52eb2017-04-05 10:34:10 +0200856 variant->dai_bit_clk_names[i]);
Srinivas Kandagatla9a127cf2015-05-21 22:52:49 +0100857 if (IS_ERR(drvdata->mi2s_bit_clk[dai_id])) {
Tang Bin952c0e22020-05-04 14:59:47 +0800858 dev_err(dev,
Linus Walleij97c52eb2017-04-05 10:34:10 +0200859 "error getting %s: %ld\n",
860 variant->dai_bit_clk_names[i],
Julia Lawall89857292015-09-17 10:47:33 +0200861 PTR_ERR(drvdata->mi2s_bit_clk[dai_id]));
Srinivas Kandagatla9a127cf2015-05-21 22:52:49 +0100862 return PTR_ERR(drvdata->mi2s_bit_clk[dai_id]);
863 }
Srinivasa Rao Mandadapub18249682020-11-23 21:47:53 +0530864 drvdata->bit_clk_state[dai_id] = LPAIF_BIT_CLK_DISABLE;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800865 }
866
Rohit kumarb5022a32020-08-14 16:23:01 +0530867 /* Allocation for i2sctl regmap fields */
868 drvdata->i2sctl = devm_kzalloc(&pdev->dev, sizeof(struct lpaif_i2sctl),
869 GFP_KERNEL);
870
871 /* Initialize bitfields for dai I2SCTL register */
872 ret = lpass_cpu_init_i2sctl_bitfields(dev, drvdata->i2sctl,
873 drvdata->lpaif_map);
874 if (ret) {
875 dev_err(dev, "error init i2sctl field: %d\n", ret);
876 return ret;
877 }
878
V Sujith Kumar Reddy7cb37b72020-10-08 10:47:01 +0530879 if (drvdata->hdmi_port_enable) {
880 ret = lpass_hdmi_init_bitfields(dev, drvdata->hdmiif_map);
881 if (ret) {
882 dev_err(dev, "%s error hdmi init failed\n", __func__);
883 return ret;
884 }
885 }
Tang Bin952c0e22020-05-04 14:59:47 +0800886 ret = devm_snd_soc_register_component(dev,
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100887 &lpass_cpu_comp_driver,
888 variant->dai_driver,
889 variant->num_dai);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800890 if (ret) {
Tang Bin952c0e22020-05-04 14:59:47 +0800891 dev_err(dev, "error registering cpu driver: %d\n", ret);
Rohit kumara5035672020-08-14 16:22:58 +0530892 goto err;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800893 }
894
895 ret = asoc_qcom_lpass_platform_register(pdev);
896 if (ret) {
Tang Bin952c0e22020-05-04 14:59:47 +0800897 dev_err(dev, "error registering platform driver: %d\n", ret);
Rohit kumara5035672020-08-14 16:22:58 +0530898 goto err;
Kenneth Westfield80beab82015-03-03 16:21:54 -0800899 }
900
Rohit kumara5035672020-08-14 16:22:58 +0530901err:
Kenneth Westfield80beab82015-03-03 16:21:54 -0800902 return ret;
903}
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100904EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_platform_probe);
Kenneth Westfield80beab82015-03-03 16:21:54 -0800905
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100906int asoc_qcom_lpass_cpu_platform_remove(struct platform_device *pdev)
Kenneth Westfield80beab82015-03-03 16:21:54 -0800907{
908 struct lpass_data *drvdata = platform_get_drvdata(pdev);
909
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100910 if (drvdata->variant->exit)
911 drvdata->variant->exit(pdev);
912
Kenneth Westfield80beab82015-03-03 16:21:54 -0800913
914 return 0;
915}
Srinivas Kandagatla9bae4882015-05-16 13:32:17 +0100916EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_platform_remove);
Srinivas Kandagatla94201792016-10-31 11:25:45 +0000917
V Sujith Kumar Reddy60a97382020-11-14 00:08:22 +0530918void asoc_qcom_lpass_cpu_platform_shutdown(struct platform_device *pdev)
919{
920 struct lpass_data *drvdata = platform_get_drvdata(pdev);
921
922 if (drvdata->variant->exit)
923 drvdata->variant->exit(pdev);
924
925}
926EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_platform_shutdown);
927
Srinivas Kandagatla94201792016-10-31 11:25:45 +0000928MODULE_DESCRIPTION("QTi LPASS CPU Driver");
929MODULE_LICENSE("GPL v2");