Thomas Gleixner | 97fb5e8 | 2019-05-29 07:17:58 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved. |
| 4 | * |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 5 | * lpass-cpu.c -- ALSA SoC CPU DAI driver for QTi LPASS |
| 6 | */ |
| 7 | |
| 8 | #include <linux/clk.h> |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 9 | #include <linux/kernel.h> |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/of.h> |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 12 | #include <linux/of_device.h> |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 13 | #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 Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 19 | #include "lpass-lpaif-reg.h" |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 20 | #include "lpass.h" |
| 21 | |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 22 | #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 | |
Srinivasa Rao Mandadapu | c223f41 | 2021-06-09 19:00:39 +0530 | [diff] [blame] | 32 | /* |
| 33 | * Channel maps for Quad channel playbacks on MI2S Secondary |
| 34 | */ |
| 35 | static struct snd_pcm_chmap_elem lpass_quad_chmaps[] = { |
| 36 | { .channels = 4, |
| 37 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_RL, |
| 38 | SNDRV_CHMAP_FR, SNDRV_CHMAP_RR } }, |
| 39 | { } |
| 40 | }; |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 41 | static int lpass_cpu_init_i2sctl_bitfields(struct device *dev, |
| 42 | struct lpaif_i2sctl *i2sctl, struct regmap *map) |
| 43 | { |
| 44 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 45 | struct lpass_variant *v = drvdata->variant; |
| 46 | |
| 47 | i2sctl->loopback = devm_regmap_field_alloc(dev, map, v->loopback); |
| 48 | i2sctl->spken = devm_regmap_field_alloc(dev, map, v->spken); |
| 49 | i2sctl->spkmode = devm_regmap_field_alloc(dev, map, v->spkmode); |
| 50 | i2sctl->spkmono = devm_regmap_field_alloc(dev, map, v->spkmono); |
| 51 | i2sctl->micen = devm_regmap_field_alloc(dev, map, v->micen); |
| 52 | i2sctl->micmode = devm_regmap_field_alloc(dev, map, v->micmode); |
| 53 | i2sctl->micmono = devm_regmap_field_alloc(dev, map, v->micmono); |
| 54 | i2sctl->wssrc = devm_regmap_field_alloc(dev, map, v->wssrc); |
| 55 | i2sctl->bitwidth = devm_regmap_field_alloc(dev, map, v->bitwidth); |
| 56 | |
| 57 | if (IS_ERR(i2sctl->loopback) || IS_ERR(i2sctl->spken) || |
| 58 | IS_ERR(i2sctl->spkmode) || IS_ERR(i2sctl->spkmono) || |
| 59 | IS_ERR(i2sctl->micen) || IS_ERR(i2sctl->micmode) || |
| 60 | IS_ERR(i2sctl->micmono) || IS_ERR(i2sctl->wssrc) || |
| 61 | IS_ERR(i2sctl->bitwidth)) |
| 62 | return -EINVAL; |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 67 | static int lpass_cpu_daiops_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 68 | unsigned int freq, int dir) |
| 69 | { |
| 70 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
| 71 | int ret; |
| 72 | |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 73 | ret = clk_set_rate(drvdata->mi2s_osr_clk[dai->driver->id], freq); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 74 | if (ret) |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 75 | dev_err(dai->dev, "error setting mi2s osrclk to %u: %d\n", |
| 76 | freq, ret); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 77 | |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | static int lpass_cpu_daiops_startup(struct snd_pcm_substream *substream, |
| 82 | struct snd_soc_dai *dai) |
| 83 | { |
| 84 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
| 85 | int ret; |
| 86 | |
Bjorn Andersson | 46dccc3 | 2017-01-30 13:03:36 -0800 | [diff] [blame] | 87 | ret = clk_prepare_enable(drvdata->mi2s_osr_clk[dai->driver->id]); |
| 88 | if (ret) { |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 89 | dev_err(dai->dev, "error in enabling mi2s osr clk: %d\n", ret); |
Bjorn Andersson | 46dccc3 | 2017-01-30 13:03:36 -0800 | [diff] [blame] | 90 | return ret; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 91 | } |
V Sujith Kumar Reddy | 6ec6c36 | 2020-10-19 14:36:03 +0530 | [diff] [blame] | 92 | ret = clk_prepare(drvdata->mi2s_bit_clk[dai->driver->id]); |
| 93 | if (ret) { |
| 94 | dev_err(dai->dev, "error in enabling mi2s bit clk: %d\n", ret); |
| 95 | clk_disable_unprepare(drvdata->mi2s_osr_clk[dai->driver->id]); |
| 96 | return ret; |
| 97 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static void lpass_cpu_daiops_shutdown(struct snd_pcm_substream *substream, |
| 102 | struct snd_soc_dai *dai) |
| 103 | { |
| 104 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
Srinivasa Rao Mandadapu | c8a4556 | 2021-06-04 23:45:45 +0800 | [diff] [blame] | 105 | struct lpaif_i2sctl *i2sctl = drvdata->i2sctl; |
| 106 | unsigned int id = dai->driver->id; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 107 | |
Bjorn Andersson | 46dccc3 | 2017-01-30 13:03:36 -0800 | [diff] [blame] | 108 | clk_disable_unprepare(drvdata->mi2s_osr_clk[dai->driver->id]); |
Srinivasa Rao Mandadapu | c8a4556 | 2021-06-04 23:45:45 +0800 | [diff] [blame] | 109 | /* |
| 110 | * Ensure LRCLK is disabled even in device node validation. |
| 111 | * Will not impact if disabled in lpass_cpu_daiops_trigger() |
| 112 | * suspend. |
| 113 | */ |
| 114 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 115 | regmap_fields_write(i2sctl->spken, id, LPAIF_I2SCTL_SPKEN_DISABLE); |
| 116 | else |
| 117 | regmap_fields_write(i2sctl->micen, id, LPAIF_I2SCTL_MICEN_DISABLE); |
| 118 | |
| 119 | /* |
| 120 | * BCLK may not be enabled if lpass_cpu_daiops_prepare is called before |
| 121 | * lpass_cpu_daiops_shutdown. It's paired with the clk_enable in |
| 122 | * lpass_cpu_daiops_prepare. |
| 123 | */ |
| 124 | if (drvdata->mi2s_was_prepared[dai->driver->id]) { |
| 125 | drvdata->mi2s_was_prepared[dai->driver->id] = false; |
| 126 | clk_disable(drvdata->mi2s_bit_clk[dai->driver->id]); |
| 127 | } |
| 128 | |
V Sujith Kumar Reddy | 6ec6c36 | 2020-10-19 14:36:03 +0530 | [diff] [blame] | 129 | clk_unprepare(drvdata->mi2s_bit_clk[dai->driver->id]); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream, |
| 133 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
| 134 | { |
| 135 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 136 | struct lpaif_i2sctl *i2sctl = drvdata->i2sctl; |
| 137 | unsigned int id = dai->driver->id; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 138 | snd_pcm_format_t format = params_format(params); |
| 139 | unsigned int channels = params_channels(params); |
| 140 | unsigned int rate = params_rate(params); |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 141 | unsigned int mode; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 142 | unsigned int regval; |
| 143 | int bitwidth, ret; |
| 144 | |
| 145 | bitwidth = snd_pcm_format_width(format); |
| 146 | if (bitwidth < 0) { |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 147 | dev_err(dai->dev, "invalid bit width given: %d\n", bitwidth); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 148 | return bitwidth; |
| 149 | } |
| 150 | |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 151 | ret = regmap_fields_write(i2sctl->loopback, id, |
| 152 | LPAIF_I2SCTL_LOOPBACK_DISABLE); |
| 153 | if (ret) { |
| 154 | dev_err(dai->dev, "error updating loopback field: %d\n", ret); |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | ret = regmap_fields_write(i2sctl->wssrc, id, |
| 159 | LPAIF_I2SCTL_WSSRC_INTERNAL); |
| 160 | if (ret) { |
| 161 | dev_err(dai->dev, "error updating wssrc field: %d\n", ret); |
| 162 | return ret; |
| 163 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 164 | |
| 165 | switch (bitwidth) { |
| 166 | case 16: |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 167 | regval = LPAIF_I2SCTL_BITWIDTH_16; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 168 | break; |
| 169 | case 24: |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 170 | regval = LPAIF_I2SCTL_BITWIDTH_24; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 171 | break; |
| 172 | case 32: |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 173 | regval = LPAIF_I2SCTL_BITWIDTH_32; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 174 | break; |
| 175 | default: |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 176 | dev_err(dai->dev, "invalid bitwidth given: %d\n", bitwidth); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 177 | return -EINVAL; |
| 178 | } |
| 179 | |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 180 | ret = regmap_fields_write(i2sctl->bitwidth, id, regval); |
| 181 | if (ret) { |
| 182 | dev_err(dai->dev, "error updating bitwidth field: %d\n", ret); |
| 183 | return ret; |
| 184 | } |
| 185 | |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 186 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 187 | mode = drvdata->mi2s_playback_sd_mode[id]; |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 188 | else |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 189 | mode = drvdata->mi2s_capture_sd_mode[id]; |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 190 | |
| 191 | if (!mode) { |
| 192 | dev_err(dai->dev, "no line is assigned\n"); |
| 193 | return -EINVAL; |
| 194 | } |
| 195 | |
| 196 | switch (channels) { |
| 197 | case 1: |
| 198 | case 2: |
| 199 | switch (mode) { |
| 200 | case LPAIF_I2SCTL_MODE_QUAD01: |
| 201 | case LPAIF_I2SCTL_MODE_6CH: |
| 202 | case LPAIF_I2SCTL_MODE_8CH: |
| 203 | mode = LPAIF_I2SCTL_MODE_SD0; |
| 204 | break; |
| 205 | case LPAIF_I2SCTL_MODE_QUAD23: |
| 206 | mode = LPAIF_I2SCTL_MODE_SD2; |
| 207 | break; |
| 208 | } |
| 209 | |
| 210 | break; |
| 211 | case 4: |
| 212 | if (mode < LPAIF_I2SCTL_MODE_QUAD01) { |
| 213 | dev_err(dai->dev, "cannot configure 4 channels with mode %d\n", |
| 214 | mode); |
| 215 | return -EINVAL; |
| 216 | } |
| 217 | |
| 218 | switch (mode) { |
| 219 | case LPAIF_I2SCTL_MODE_6CH: |
| 220 | case LPAIF_I2SCTL_MODE_8CH: |
| 221 | mode = LPAIF_I2SCTL_MODE_QUAD01; |
| 222 | break; |
| 223 | } |
| 224 | break; |
| 225 | case 6: |
| 226 | if (mode < LPAIF_I2SCTL_MODE_6CH) { |
| 227 | dev_err(dai->dev, "cannot configure 6 channels with mode %d\n", |
| 228 | mode); |
| 229 | return -EINVAL; |
| 230 | } |
| 231 | |
| 232 | switch (mode) { |
| 233 | case LPAIF_I2SCTL_MODE_8CH: |
| 234 | mode = LPAIF_I2SCTL_MODE_6CH; |
| 235 | break; |
| 236 | } |
| 237 | break; |
| 238 | case 8: |
| 239 | if (mode < LPAIF_I2SCTL_MODE_8CH) { |
| 240 | dev_err(dai->dev, "cannot configure 8 channels with mode %d\n", |
| 241 | mode); |
| 242 | return -EINVAL; |
| 243 | } |
| 244 | break; |
| 245 | default: |
| 246 | dev_err(dai->dev, "invalid channels given: %u\n", channels); |
| 247 | return -EINVAL; |
| 248 | } |
| 249 | |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 250 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 251 | ret = regmap_fields_write(i2sctl->spkmode, id, |
| 252 | LPAIF_I2SCTL_SPKMODE(mode)); |
| 253 | if (ret) { |
| 254 | dev_err(dai->dev, "error writing to i2sctl spkr mode: %d\n", |
| 255 | ret); |
| 256 | return ret; |
| 257 | } |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 258 | if (channels >= 2) |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 259 | ret = regmap_fields_write(i2sctl->spkmono, id, |
| 260 | LPAIF_I2SCTL_SPKMONO_STEREO); |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 261 | else |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 262 | ret = regmap_fields_write(i2sctl->spkmono, id, |
| 263 | LPAIF_I2SCTL_SPKMONO_MONO); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 264 | } else { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 265 | ret = regmap_fields_write(i2sctl->micmode, id, |
| 266 | LPAIF_I2SCTL_MICMODE(mode)); |
| 267 | if (ret) { |
| 268 | dev_err(dai->dev, "error writing to i2sctl mic mode: %d\n", |
| 269 | ret); |
| 270 | return ret; |
| 271 | } |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 272 | if (channels >= 2) |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 273 | ret = regmap_fields_write(i2sctl->micmono, id, |
| 274 | LPAIF_I2SCTL_MICMONO_STEREO); |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 275 | else |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 276 | ret = regmap_fields_write(i2sctl->micmono, id, |
| 277 | LPAIF_I2SCTL_MICMONO_MONO); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 280 | if (ret) { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 281 | dev_err(dai->dev, "error writing to i2sctl channels mode: %d\n", |
| 282 | ret); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 283 | return ret; |
| 284 | } |
| 285 | |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 286 | ret = clk_set_rate(drvdata->mi2s_bit_clk[id], |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 287 | rate * bitwidth * 2); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 288 | if (ret) { |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 289 | dev_err(dai->dev, "error setting mi2s bitclk to %u: %d\n", |
| 290 | rate * bitwidth * 2, ret); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 291 | return ret; |
| 292 | } |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 297 | static int lpass_cpu_daiops_trigger(struct snd_pcm_substream *substream, |
| 298 | int cmd, struct snd_soc_dai *dai) |
| 299 | { |
| 300 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 301 | struct lpaif_i2sctl *i2sctl = drvdata->i2sctl; |
| 302 | unsigned int id = dai->driver->id; |
Takashi Iwai | 96f05be | 2015-04-13 14:23:29 +0200 | [diff] [blame] | 303 | int ret = -EINVAL; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 304 | |
| 305 | switch (cmd) { |
| 306 | case SNDRV_PCM_TRIGGER_START: |
| 307 | case SNDRV_PCM_TRIGGER_RESUME: |
| 308 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Srinivasa Rao Mandadapu | c8a4556 | 2021-06-04 23:45:45 +0800 | [diff] [blame] | 309 | /* |
| 310 | * Ensure lpass BCLK/LRCLK is enabled during |
| 311 | * device resume as lpass_cpu_daiops_prepare() is not called |
| 312 | * after the device resumes. We don't check mi2s_was_prepared before |
| 313 | * enable/disable BCLK in trigger events because: |
| 314 | * 1. These trigger events are paired, so the BCLK |
| 315 | * enable_count is balanced. |
| 316 | * 2. the BCLK can be shared (ex: headset and headset mic), |
| 317 | * we need to increase the enable_count so that we don't |
| 318 | * turn off the shared BCLK while other devices are using |
| 319 | * it. |
| 320 | */ |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 321 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 322 | ret = regmap_fields_write(i2sctl->spken, id, |
| 323 | LPAIF_I2SCTL_SPKEN_ENABLE); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 324 | } else { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 325 | ret = regmap_fields_write(i2sctl->micen, id, |
| 326 | LPAIF_I2SCTL_MICEN_ENABLE); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 327 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 328 | if (ret) |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 329 | dev_err(dai->dev, "error writing to i2sctl reg: %d\n", |
| 330 | ret); |
V Sujith Kumar Reddy | 7e6799d | 2020-09-18 22:24:33 +0530 | [diff] [blame] | 331 | |
Srinivasa Rao Mandadapu | 6c28377 | 2021-01-27 20:48:24 +0530 | [diff] [blame] | 332 | ret = clk_enable(drvdata->mi2s_bit_clk[id]); |
| 333 | if (ret) { |
| 334 | dev_err(dai->dev, "error in enabling mi2s bit clk: %d\n", ret); |
| 335 | clk_disable(drvdata->mi2s_osr_clk[id]); |
| 336 | return ret; |
V Sujith Kumar Reddy | 7e6799d | 2020-09-18 22:24:33 +0530 | [diff] [blame] | 337 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 338 | break; |
| 339 | case SNDRV_PCM_TRIGGER_STOP: |
| 340 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 341 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Srinivasa Rao Mandadapu | c8a4556 | 2021-06-04 23:45:45 +0800 | [diff] [blame] | 342 | /* |
| 343 | * To ensure lpass BCLK/LRCLK is disabled during |
| 344 | * device suspend. |
| 345 | */ |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 346 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 347 | ret = regmap_fields_write(i2sctl->spken, id, |
| 348 | LPAIF_I2SCTL_SPKEN_DISABLE); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 349 | } else { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 350 | ret = regmap_fields_write(i2sctl->micen, id, |
| 351 | LPAIF_I2SCTL_MICEN_DISABLE); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 352 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 353 | if (ret) |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 354 | dev_err(dai->dev, "error writing to i2sctl reg: %d\n", |
| 355 | ret); |
Srinivasa Rao Mandadapu | 6c28377 | 2021-01-27 20:48:24 +0530 | [diff] [blame] | 356 | |
| 357 | clk_disable(drvdata->mi2s_bit_clk[dai->driver->id]); |
| 358 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | |
| 362 | return ret; |
| 363 | } |
| 364 | |
Srinivasa Rao Mandadapu | c8a4556 | 2021-06-04 23:45:45 +0800 | [diff] [blame] | 365 | static int lpass_cpu_daiops_prepare(struct snd_pcm_substream *substream, |
| 366 | struct snd_soc_dai *dai) |
| 367 | { |
| 368 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
| 369 | struct lpaif_i2sctl *i2sctl = drvdata->i2sctl; |
| 370 | unsigned int id = dai->driver->id; |
| 371 | int ret; |
| 372 | |
| 373 | /* |
| 374 | * Ensure lpass BCLK/LRCLK is enabled bit before playback/capture |
| 375 | * data flow starts. This allows other codec to have some delay before |
| 376 | * the data flow. |
| 377 | * (ex: to drop start up pop noise before capture starts). |
| 378 | */ |
| 379 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 380 | ret = regmap_fields_write(i2sctl->spken, id, LPAIF_I2SCTL_SPKEN_ENABLE); |
| 381 | else |
| 382 | ret = regmap_fields_write(i2sctl->micen, id, LPAIF_I2SCTL_MICEN_ENABLE); |
| 383 | |
| 384 | if (ret) { |
| 385 | dev_err(dai->dev, "error writing to i2sctl reg: %d\n", ret); |
| 386 | return ret; |
| 387 | } |
| 388 | |
| 389 | /* |
| 390 | * Check mi2s_was_prepared before enabling BCLK as lpass_cpu_daiops_prepare can |
| 391 | * be called multiple times. It's paired with the clk_disable in |
| 392 | * lpass_cpu_daiops_shutdown. |
| 393 | */ |
| 394 | if (!drvdata->mi2s_was_prepared[dai->driver->id]) { |
| 395 | ret = clk_enable(drvdata->mi2s_bit_clk[id]); |
| 396 | if (ret) { |
| 397 | dev_err(dai->dev, "error in enabling mi2s bit clk: %d\n", ret); |
| 398 | return ret; |
| 399 | } |
| 400 | drvdata->mi2s_was_prepared[dai->driver->id] = true; |
| 401 | } |
| 402 | return 0; |
| 403 | } |
| 404 | |
Axel Lin | 618718d | 2015-08-28 10:53:31 +0800 | [diff] [blame] | 405 | const struct snd_soc_dai_ops asoc_qcom_lpass_cpu_dai_ops = { |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 406 | .set_sysclk = lpass_cpu_daiops_set_sysclk, |
| 407 | .startup = lpass_cpu_daiops_startup, |
| 408 | .shutdown = lpass_cpu_daiops_shutdown, |
| 409 | .hw_params = lpass_cpu_daiops_hw_params, |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 410 | .trigger = lpass_cpu_daiops_trigger, |
Srinivasa Rao Mandadapu | c8a4556 | 2021-06-04 23:45:45 +0800 | [diff] [blame] | 411 | .prepare = lpass_cpu_daiops_prepare, |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 412 | }; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 413 | EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_dai_ops); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 414 | |
Srinivasa Rao Mandadapu | c223f41 | 2021-06-09 19:00:39 +0530 | [diff] [blame] | 415 | int lpass_cpu_pcm_new(struct snd_soc_pcm_runtime *rtd, |
| 416 | struct snd_soc_dai *dai) |
| 417 | { |
| 418 | int ret; |
| 419 | struct snd_soc_dai_driver *drv = dai->driver; |
| 420 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
| 421 | |
| 422 | if (drvdata->mi2s_playback_sd_mode[dai->id] == LPAIF_I2SCTL_MODE_QUAD01) { |
| 423 | ret = snd_pcm_add_chmap_ctls(rtd->pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 424 | lpass_quad_chmaps, drv->playback.channels_max, 0, |
| 425 | NULL); |
| 426 | if (ret < 0) |
| 427 | return ret; |
| 428 | } |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | EXPORT_SYMBOL_GPL(lpass_cpu_pcm_new); |
| 433 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 434 | int asoc_qcom_lpass_cpu_dai_probe(struct snd_soc_dai *dai) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 435 | { |
| 436 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
| 437 | int ret; |
| 438 | |
| 439 | /* ensure audio hardware is disabled */ |
| 440 | ret = regmap_write(drvdata->lpaif_map, |
Srinivas Kandagatla | 0ae9fd3 | 2015-05-16 13:32:25 +0100 | [diff] [blame] | 441 | LPAIF_I2SCTL_REG(drvdata->variant, dai->driver->id), 0); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 442 | if (ret) |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 443 | dev_err(dai->dev, "error writing to i2sctl reg: %d\n", ret); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 444 | |
| 445 | return ret; |
| 446 | } |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 447 | EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_dai_probe); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 448 | |
Srinivas Kandagatla | cd3484f | 2021-01-19 17:15:27 +0000 | [diff] [blame] | 449 | static int asoc_qcom_of_xlate_dai_name(struct snd_soc_component *component, |
Krzysztof Kozlowski | 933f98b | 2021-02-21 16:30:24 +0100 | [diff] [blame] | 450 | const struct of_phandle_args *args, |
Srinivas Kandagatla | cd3484f | 2021-01-19 17:15:27 +0000 | [diff] [blame] | 451 | const char **dai_name) |
| 452 | { |
| 453 | struct lpass_data *drvdata = snd_soc_component_get_drvdata(component); |
| 454 | struct lpass_variant *variant = drvdata->variant; |
| 455 | int id = args->args[0]; |
| 456 | int ret = -EINVAL; |
| 457 | int i; |
| 458 | |
| 459 | for (i = 0; i < variant->num_dai; i++) { |
| 460 | if (variant->dai_driver[i].id == id) { |
| 461 | *dai_name = variant->dai_driver[i].name; |
| 462 | ret = 0; |
| 463 | break; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | return ret; |
| 468 | } |
| 469 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 470 | static const struct snd_soc_component_driver lpass_cpu_comp_driver = { |
| 471 | .name = "lpass-cpu", |
Srinivas Kandagatla | cd3484f | 2021-01-19 17:15:27 +0000 | [diff] [blame] | 472 | .of_xlate_dai_name = asoc_qcom_of_xlate_dai_name, |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 473 | }; |
| 474 | |
| 475 | static bool lpass_cpu_regmap_writeable(struct device *dev, unsigned int reg) |
| 476 | { |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 477 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 478 | struct lpass_variant *v = drvdata->variant; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 479 | int i; |
| 480 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 481 | for (i = 0; i < v->i2s_ports; ++i) |
| 482 | if (reg == LPAIF_I2SCTL_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 483 | return true; |
| 484 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 485 | for (i = 0; i < v->irq_ports; ++i) { |
| 486 | if (reg == LPAIF_IRQEN_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 487 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 488 | if (reg == LPAIF_IRQCLEAR_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 489 | return true; |
| 490 | } |
| 491 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 492 | for (i = 0; i < v->rdma_channels; ++i) { |
| 493 | if (reg == LPAIF_RDMACTL_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 494 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 495 | if (reg == LPAIF_RDMABASE_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 496 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 497 | if (reg == LPAIF_RDMABUFF_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 498 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 499 | if (reg == LPAIF_RDMAPER_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 500 | return true; |
| 501 | } |
| 502 | |
Srinivas Kandagatla | dad8061 | 2016-02-11 12:18:27 +0000 | [diff] [blame] | 503 | for (i = 0; i < v->wrdma_channels; ++i) { |
| 504 | if (reg == LPAIF_WRDMACTL_REG(v, i + v->wrdma_channel_start)) |
| 505 | return true; |
| 506 | if (reg == LPAIF_WRDMABASE_REG(v, i + v->wrdma_channel_start)) |
| 507 | return true; |
| 508 | if (reg == LPAIF_WRDMABUFF_REG(v, i + v->wrdma_channel_start)) |
| 509 | return true; |
| 510 | if (reg == LPAIF_WRDMAPER_REG(v, i + v->wrdma_channel_start)) |
| 511 | return true; |
| 512 | } |
| 513 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 514 | return false; |
| 515 | } |
| 516 | |
| 517 | static bool lpass_cpu_regmap_readable(struct device *dev, unsigned int reg) |
| 518 | { |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 519 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 520 | struct lpass_variant *v = drvdata->variant; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 521 | int i; |
| 522 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 523 | for (i = 0; i < v->i2s_ports; ++i) |
| 524 | if (reg == LPAIF_I2SCTL_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 525 | return true; |
| 526 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 527 | for (i = 0; i < v->irq_ports; ++i) { |
Srinivas Kandagatla | 6a7f5bd | 2021-06-24 10:21:53 +0100 | [diff] [blame] | 528 | if (reg == LPAIF_IRQCLEAR_REG(v, i)) |
| 529 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 530 | if (reg == LPAIF_IRQEN_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 531 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 532 | if (reg == LPAIF_IRQSTAT_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 533 | return true; |
| 534 | } |
| 535 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 536 | for (i = 0; i < v->rdma_channels; ++i) { |
| 537 | if (reg == LPAIF_RDMACTL_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 538 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 539 | if (reg == LPAIF_RDMABASE_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 540 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 541 | if (reg == LPAIF_RDMABUFF_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 542 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 543 | if (reg == LPAIF_RDMACURR_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 544 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 545 | if (reg == LPAIF_RDMAPER_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 546 | return true; |
| 547 | } |
| 548 | |
Srinivas Kandagatla | dad8061 | 2016-02-11 12:18:27 +0000 | [diff] [blame] | 549 | for (i = 0; i < v->wrdma_channels; ++i) { |
| 550 | if (reg == LPAIF_WRDMACTL_REG(v, i + v->wrdma_channel_start)) |
| 551 | return true; |
| 552 | if (reg == LPAIF_WRDMABASE_REG(v, i + v->wrdma_channel_start)) |
| 553 | return true; |
| 554 | if (reg == LPAIF_WRDMABUFF_REG(v, i + v->wrdma_channel_start)) |
| 555 | return true; |
| 556 | if (reg == LPAIF_WRDMACURR_REG(v, i + v->wrdma_channel_start)) |
| 557 | return true; |
| 558 | if (reg == LPAIF_WRDMAPER_REG(v, i + v->wrdma_channel_start)) |
| 559 | return true; |
| 560 | } |
| 561 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 562 | return false; |
| 563 | } |
| 564 | |
| 565 | static bool lpass_cpu_regmap_volatile(struct device *dev, unsigned int reg) |
| 566 | { |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 567 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 568 | struct lpass_variant *v = drvdata->variant; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 569 | int i; |
| 570 | |
Srinivas Kandagatla | 6a7f5bd | 2021-06-24 10:21:53 +0100 | [diff] [blame] | 571 | for (i = 0; i < v->irq_ports; ++i) { |
| 572 | if (reg == LPAIF_IRQCLEAR_REG(v, i)) |
| 573 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 574 | if (reg == LPAIF_IRQSTAT_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 575 | return true; |
Srinivas Kandagatla | 6a7f5bd | 2021-06-24 10:21:53 +0100 | [diff] [blame] | 576 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 577 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 578 | for (i = 0; i < v->rdma_channels; ++i) |
Srinivasa Rao Mandadapu | 315fbe4c | 2020-12-17 13:38:33 +0530 | [diff] [blame] | 579 | if (reg == LPAIF_RDMACURR_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 580 | return true; |
| 581 | |
Srinivas Kandagatla | dad8061 | 2016-02-11 12:18:27 +0000 | [diff] [blame] | 582 | for (i = 0; i < v->wrdma_channels; ++i) |
Srinivasa Rao Mandadapu | 315fbe4c | 2020-12-17 13:38:33 +0530 | [diff] [blame] | 583 | if (reg == LPAIF_WRDMACURR_REG(v, i + v->wrdma_channel_start)) |
Srinivas Kandagatla | dad8061 | 2016-02-11 12:18:27 +0000 | [diff] [blame] | 584 | return true; |
| 585 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 586 | return false; |
| 587 | } |
| 588 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 589 | static struct regmap_config lpass_cpu_regmap_config = { |
Stephen Boyd | 03b49bf | 2021-01-14 19:43:25 -0800 | [diff] [blame] | 590 | .name = "lpass_cpu", |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 591 | .reg_bits = 32, |
| 592 | .reg_stride = 4, |
| 593 | .val_bits = 32, |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 594 | .writeable_reg = lpass_cpu_regmap_writeable, |
| 595 | .readable_reg = lpass_cpu_regmap_readable, |
| 596 | .volatile_reg = lpass_cpu_regmap_volatile, |
| 597 | .cache_type = REGCACHE_FLAT, |
| 598 | }; |
| 599 | |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 600 | static int lpass_hdmi_init_bitfields(struct device *dev, struct regmap *map) |
| 601 | { |
| 602 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 603 | struct lpass_variant *v = drvdata->variant; |
| 604 | unsigned int i; |
| 605 | struct lpass_hdmi_tx_ctl *tx_ctl; |
| 606 | struct regmap_field *legacy_en; |
| 607 | struct lpass_vbit_ctrl *vbit_ctl; |
| 608 | struct regmap_field *tx_parity; |
| 609 | struct lpass_dp_metadata_ctl *meta_ctl; |
| 610 | struct lpass_sstream_ctl *sstream_ctl; |
| 611 | struct regmap_field *ch_msb; |
| 612 | struct regmap_field *ch_lsb; |
| 613 | struct lpass_hdmitx_dmactl *tx_dmactl; |
| 614 | int rval; |
| 615 | |
| 616 | tx_ctl = devm_kzalloc(dev, sizeof(*tx_ctl), GFP_KERNEL); |
| 617 | if (!tx_ctl) |
| 618 | return -ENOMEM; |
| 619 | |
| 620 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->soft_reset, tx_ctl->soft_reset); |
| 621 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->force_reset, tx_ctl->force_reset); |
| 622 | drvdata->tx_ctl = tx_ctl; |
| 623 | |
| 624 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->legacy_en, legacy_en); |
| 625 | drvdata->hdmitx_legacy_en = legacy_en; |
| 626 | |
| 627 | vbit_ctl = devm_kzalloc(dev, sizeof(*vbit_ctl), GFP_KERNEL); |
| 628 | if (!vbit_ctl) |
| 629 | return -ENOMEM; |
| 630 | |
| 631 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->replace_vbit, vbit_ctl->replace_vbit); |
| 632 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->vbit_stream, vbit_ctl->vbit_stream); |
| 633 | drvdata->vbit_ctl = vbit_ctl; |
| 634 | |
| 635 | |
| 636 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->calc_en, tx_parity); |
| 637 | drvdata->hdmitx_parity_calc_en = tx_parity; |
| 638 | |
| 639 | meta_ctl = devm_kzalloc(dev, sizeof(*meta_ctl), GFP_KERNEL); |
| 640 | if (!meta_ctl) |
| 641 | return -ENOMEM; |
| 642 | |
| 643 | rval = devm_regmap_field_bulk_alloc(dev, map, &meta_ctl->mute, &v->mute, 7); |
| 644 | if (rval) |
| 645 | return rval; |
| 646 | drvdata->meta_ctl = meta_ctl; |
| 647 | |
| 648 | sstream_ctl = devm_kzalloc(dev, sizeof(*sstream_ctl), GFP_KERNEL); |
| 649 | if (!sstream_ctl) |
| 650 | return -ENOMEM; |
| 651 | |
| 652 | rval = devm_regmap_field_bulk_alloc(dev, map, &sstream_ctl->sstream_en, &v->sstream_en, 9); |
| 653 | if (rval) |
| 654 | return rval; |
| 655 | |
| 656 | drvdata->sstream_ctl = sstream_ctl; |
| 657 | |
| 658 | for (i = 0; i < LPASS_MAX_HDMI_DMA_CHANNELS; i++) { |
| 659 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->msb_bits, ch_msb); |
| 660 | drvdata->hdmitx_ch_msb[i] = ch_msb; |
| 661 | |
| 662 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->lsb_bits, ch_lsb); |
| 663 | drvdata->hdmitx_ch_lsb[i] = ch_lsb; |
| 664 | |
| 665 | tx_dmactl = devm_kzalloc(dev, sizeof(*tx_dmactl), GFP_KERNEL); |
| 666 | if (!tx_dmactl) |
| 667 | return -ENOMEM; |
| 668 | |
| 669 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->use_hw_chs, tx_dmactl->use_hw_chs); |
| 670 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->use_hw_usr, tx_dmactl->use_hw_usr); |
| 671 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->hw_chs_sel, tx_dmactl->hw_chs_sel); |
| 672 | QCOM_REGMAP_FIELD_ALLOC(dev, map, v->hw_usr_sel, tx_dmactl->hw_usr_sel); |
| 673 | drvdata->hdmi_tx_dmactl[i] = tx_dmactl; |
| 674 | } |
| 675 | return 0; |
| 676 | } |
| 677 | |
| 678 | static bool lpass_hdmi_regmap_writeable(struct device *dev, unsigned int reg) |
| 679 | { |
| 680 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 681 | struct lpass_variant *v = drvdata->variant; |
| 682 | int i; |
| 683 | |
| 684 | if (reg == LPASS_HDMI_TX_CTL_ADDR(v)) |
| 685 | return true; |
| 686 | if (reg == LPASS_HDMI_TX_LEGACY_ADDR(v)) |
| 687 | return true; |
| 688 | if (reg == LPASS_HDMI_TX_VBIT_CTL_ADDR(v)) |
| 689 | return true; |
| 690 | if (reg == LPASS_HDMI_TX_PARITY_ADDR(v)) |
| 691 | return true; |
| 692 | if (reg == LPASS_HDMI_TX_DP_ADDR(v)) |
| 693 | return true; |
| 694 | if (reg == LPASS_HDMI_TX_SSTREAM_ADDR(v)) |
| 695 | return true; |
| 696 | if (reg == LPASS_HDMITX_APP_IRQEN_REG(v)) |
| 697 | return true; |
| 698 | if (reg == LPASS_HDMITX_APP_IRQCLEAR_REG(v)) |
| 699 | return true; |
| 700 | |
| 701 | for (i = 0; i < v->hdmi_rdma_channels; i++) { |
| 702 | if (reg == LPASS_HDMI_TX_CH_LSB_ADDR(v, i)) |
| 703 | return true; |
| 704 | if (reg == LPASS_HDMI_TX_CH_MSB_ADDR(v, i)) |
| 705 | return true; |
| 706 | if (reg == LPASS_HDMI_TX_DMA_ADDR(v, i)) |
| 707 | return true; |
| 708 | } |
| 709 | |
Srinivasa Rao Mandadapu | e681b1a | 2021-02-02 11:57:27 +0530 | [diff] [blame] | 710 | for (i = 0; i < v->hdmi_rdma_channels; ++i) { |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 711 | if (reg == LPAIF_HDMI_RDMACTL_REG(v, i)) |
| 712 | return true; |
| 713 | if (reg == LPAIF_HDMI_RDMABASE_REG(v, i)) |
| 714 | return true; |
| 715 | if (reg == LPAIF_HDMI_RDMABUFF_REG(v, i)) |
| 716 | return true; |
| 717 | if (reg == LPAIF_HDMI_RDMAPER_REG(v, i)) |
| 718 | return true; |
| 719 | } |
| 720 | return false; |
| 721 | } |
| 722 | |
| 723 | static bool lpass_hdmi_regmap_readable(struct device *dev, unsigned int reg) |
| 724 | { |
| 725 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 726 | struct lpass_variant *v = drvdata->variant; |
| 727 | int i; |
| 728 | |
| 729 | if (reg == LPASS_HDMI_TX_CTL_ADDR(v)) |
| 730 | return true; |
| 731 | if (reg == LPASS_HDMI_TX_LEGACY_ADDR(v)) |
| 732 | return true; |
| 733 | if (reg == LPASS_HDMI_TX_VBIT_CTL_ADDR(v)) |
| 734 | return true; |
| 735 | |
| 736 | for (i = 0; i < v->hdmi_rdma_channels; i++) { |
| 737 | if (reg == LPASS_HDMI_TX_CH_LSB_ADDR(v, i)) |
| 738 | return true; |
| 739 | if (reg == LPASS_HDMI_TX_CH_MSB_ADDR(v, i)) |
| 740 | return true; |
| 741 | if (reg == LPASS_HDMI_TX_DMA_ADDR(v, i)) |
| 742 | return true; |
| 743 | } |
| 744 | |
| 745 | if (reg == LPASS_HDMI_TX_PARITY_ADDR(v)) |
| 746 | return true; |
| 747 | if (reg == LPASS_HDMI_TX_DP_ADDR(v)) |
| 748 | return true; |
| 749 | if (reg == LPASS_HDMI_TX_SSTREAM_ADDR(v)) |
| 750 | return true; |
| 751 | if (reg == LPASS_HDMITX_APP_IRQEN_REG(v)) |
| 752 | return true; |
| 753 | if (reg == LPASS_HDMITX_APP_IRQSTAT_REG(v)) |
| 754 | return true; |
| 755 | |
Srinivasa Rao Mandadapu | e681b1a | 2021-02-02 11:57:27 +0530 | [diff] [blame] | 756 | for (i = 0; i < v->hdmi_rdma_channels; ++i) { |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 757 | if (reg == LPAIF_HDMI_RDMACTL_REG(v, i)) |
| 758 | return true; |
| 759 | if (reg == LPAIF_HDMI_RDMABASE_REG(v, i)) |
| 760 | return true; |
| 761 | if (reg == LPAIF_HDMI_RDMABUFF_REG(v, i)) |
| 762 | return true; |
| 763 | if (reg == LPAIF_HDMI_RDMAPER_REG(v, i)) |
| 764 | return true; |
| 765 | if (reg == LPAIF_HDMI_RDMACURR_REG(v, i)) |
| 766 | return true; |
| 767 | } |
| 768 | |
| 769 | return false; |
| 770 | } |
| 771 | |
| 772 | static bool lpass_hdmi_regmap_volatile(struct device *dev, unsigned int reg) |
| 773 | { |
| 774 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 775 | struct lpass_variant *v = drvdata->variant; |
| 776 | int i; |
| 777 | |
| 778 | if (reg == LPASS_HDMITX_APP_IRQSTAT_REG(v)) |
| 779 | return true; |
| 780 | if (reg == LPASS_HDMI_TX_LEGACY_ADDR(v)) |
| 781 | return true; |
| 782 | |
Srinivasa Rao Mandadapu | e681b1a | 2021-02-02 11:57:27 +0530 | [diff] [blame] | 783 | for (i = 0; i < v->hdmi_rdma_channels; ++i) { |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 784 | if (reg == LPAIF_HDMI_RDMACURR_REG(v, i)) |
| 785 | return true; |
| 786 | } |
| 787 | return false; |
| 788 | } |
| 789 | |
Srinivas Kandagatla | 20f64a1 | 2020-11-05 11:41:00 +0000 | [diff] [blame] | 790 | static struct regmap_config lpass_hdmi_regmap_config = { |
Stephen Boyd | 03b49bf | 2021-01-14 19:43:25 -0800 | [diff] [blame] | 791 | .name = "lpass_hdmi", |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 792 | .reg_bits = 32, |
| 793 | .reg_stride = 4, |
| 794 | .val_bits = 32, |
| 795 | .writeable_reg = lpass_hdmi_regmap_writeable, |
| 796 | .readable_reg = lpass_hdmi_regmap_readable, |
| 797 | .volatile_reg = lpass_hdmi_regmap_volatile, |
| 798 | .cache_type = REGCACHE_FLAT, |
| 799 | }; |
| 800 | |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 801 | static unsigned int of_lpass_cpu_parse_sd_lines(struct device *dev, |
| 802 | struct device_node *node, |
| 803 | const char *name) |
| 804 | { |
| 805 | unsigned int lines[LPASS_CPU_MAX_MI2S_LINES]; |
| 806 | unsigned int sd_line_mask = 0; |
| 807 | int num_lines, i; |
| 808 | |
| 809 | num_lines = of_property_read_variable_u32_array(node, name, lines, 0, |
| 810 | LPASS_CPU_MAX_MI2S_LINES); |
| 811 | if (num_lines < 0) |
| 812 | return LPAIF_I2SCTL_MODE_NONE; |
| 813 | |
| 814 | for (i = 0; i < num_lines; i++) |
| 815 | sd_line_mask |= BIT(lines[i]); |
| 816 | |
| 817 | switch (sd_line_mask) { |
| 818 | case LPASS_CPU_I2S_SD0_MASK: |
| 819 | return LPAIF_I2SCTL_MODE_SD0; |
| 820 | case LPASS_CPU_I2S_SD1_MASK: |
| 821 | return LPAIF_I2SCTL_MODE_SD1; |
| 822 | case LPASS_CPU_I2S_SD2_MASK: |
| 823 | return LPAIF_I2SCTL_MODE_SD2; |
| 824 | case LPASS_CPU_I2S_SD3_MASK: |
| 825 | return LPAIF_I2SCTL_MODE_SD3; |
| 826 | case LPASS_CPU_I2S_SD0_1_MASK: |
| 827 | return LPAIF_I2SCTL_MODE_QUAD01; |
| 828 | case LPASS_CPU_I2S_SD2_3_MASK: |
| 829 | return LPAIF_I2SCTL_MODE_QUAD23; |
| 830 | case LPASS_CPU_I2S_SD0_1_2_MASK: |
| 831 | return LPAIF_I2SCTL_MODE_6CH; |
| 832 | case LPASS_CPU_I2S_SD0_1_2_3_MASK: |
| 833 | return LPAIF_I2SCTL_MODE_8CH; |
| 834 | default: |
| 835 | dev_err(dev, "Unsupported SD line mask: %#x\n", sd_line_mask); |
| 836 | return LPAIF_I2SCTL_MODE_NONE; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | static void of_lpass_cpu_parse_dai_data(struct device *dev, |
| 841 | struct lpass_data *data) |
| 842 | { |
| 843 | struct device_node *node; |
| 844 | int ret, id; |
| 845 | |
| 846 | /* Allow all channels by default for backwards compatibility */ |
| 847 | for (id = 0; id < data->variant->num_dai; id++) { |
| 848 | data->mi2s_playback_sd_mode[id] = LPAIF_I2SCTL_MODE_8CH; |
| 849 | data->mi2s_capture_sd_mode[id] = LPAIF_I2SCTL_MODE_8CH; |
| 850 | } |
| 851 | |
| 852 | for_each_child_of_node(dev->of_node, node) { |
| 853 | ret = of_property_read_u32(node, "reg", &id); |
Srinivasa Rao Mandadapu | 9922f50 | 2021-03-11 21:15:57 +0530 | [diff] [blame] | 854 | if (ret || id < 0) { |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 855 | dev_err(dev, "valid dai id not found: %d\n", ret); |
| 856 | continue; |
| 857 | } |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 858 | if (id == LPASS_DP_RX) { |
| 859 | data->hdmi_port_enable = 1; |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 860 | } else { |
| 861 | data->mi2s_playback_sd_mode[id] = |
| 862 | of_lpass_cpu_parse_sd_lines(dev, node, |
| 863 | "qcom,playback-sd-lines"); |
| 864 | data->mi2s_capture_sd_mode[id] = |
| 865 | of_lpass_cpu_parse_sd_lines(dev, node, |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 866 | "qcom,capture-sd-lines"); |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 867 | } |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 871 | int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 872 | { |
| 873 | struct lpass_data *drvdata; |
Kenneth Westfield | 8ebe148 | 2015-03-13 00:54:17 -0700 | [diff] [blame] | 874 | struct device_node *dsp_of_node; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 875 | struct lpass_variant *variant; |
| 876 | struct device *dev = &pdev->dev; |
| 877 | const struct of_device_id *match; |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 878 | int ret, i, dai_id; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 879 | |
Kenneth Westfield | 8ebe148 | 2015-03-13 00:54:17 -0700 | [diff] [blame] | 880 | dsp_of_node = of_parse_phandle(pdev->dev.of_node, "qcom,adsp", 0); |
| 881 | if (dsp_of_node) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 882 | dev_err(dev, "DSP exists and holds audio resources\n"); |
Kenneth Westfield | 8ebe148 | 2015-03-13 00:54:17 -0700 | [diff] [blame] | 883 | return -EBUSY; |
| 884 | } |
| 885 | |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 886 | drvdata = devm_kzalloc(dev, sizeof(struct lpass_data), GFP_KERNEL); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 887 | if (!drvdata) |
| 888 | return -ENOMEM; |
| 889 | platform_set_drvdata(pdev, drvdata); |
| 890 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 891 | match = of_match_device(dev->driver->of_match_table, dev); |
| 892 | if (!match || !match->data) |
| 893 | return -EINVAL; |
| 894 | |
| 895 | drvdata->variant = (struct lpass_variant *)match->data; |
| 896 | variant = drvdata->variant; |
| 897 | |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 898 | of_lpass_cpu_parse_dai_data(dev, drvdata); |
| 899 | |
Yang Yingliang | 77b7bae | 2021-06-15 22:07:11 +0800 | [diff] [blame] | 900 | drvdata->lpaif = devm_platform_ioremap_resource_byname(pdev, "lpass-lpaif"); |
Stephen Boyd | 4e15f50 | 2021-01-14 19:43:27 -0800 | [diff] [blame] | 901 | if (IS_ERR(drvdata->lpaif)) |
Stephen Boyd | e697df6 | 2021-01-14 19:43:26 -0800 | [diff] [blame] | 902 | return PTR_ERR(drvdata->lpaif); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 903 | |
Srinivas Kandagatla | dad8061 | 2016-02-11 12:18:27 +0000 | [diff] [blame] | 904 | lpass_cpu_regmap_config.max_register = LPAIF_WRDMAPER_REG(variant, |
| 905 | variant->wrdma_channels + |
| 906 | variant->wrdma_channel_start); |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 907 | |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 908 | drvdata->lpaif_map = devm_regmap_init_mmio(dev, drvdata->lpaif, |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 909 | &lpass_cpu_regmap_config); |
| 910 | if (IS_ERR(drvdata->lpaif_map)) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 911 | dev_err(dev, "error initializing regmap: %ld\n", |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 912 | PTR_ERR(drvdata->lpaif_map)); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 913 | return PTR_ERR(drvdata->lpaif_map); |
| 914 | } |
| 915 | |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 916 | if (drvdata->hdmi_port_enable) { |
Yang Yingliang | 77b7bae | 2021-06-15 22:07:11 +0800 | [diff] [blame] | 917 | drvdata->hdmiif = devm_platform_ioremap_resource_byname(pdev, "lpass-hdmiif"); |
Stephen Boyd | 4e15f50 | 2021-01-14 19:43:27 -0800 | [diff] [blame] | 918 | if (IS_ERR(drvdata->hdmiif)) |
Stephen Boyd | e697df6 | 2021-01-14 19:43:26 -0800 | [diff] [blame] | 919 | return PTR_ERR(drvdata->hdmiif); |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 920 | |
| 921 | lpass_hdmi_regmap_config.max_register = LPAIF_HDMI_RDMAPER_REG(variant, |
Srinivasa Rao Mandadapu | e681b1a | 2021-02-02 11:57:27 +0530 | [diff] [blame] | 922 | variant->hdmi_rdma_channels - 1); |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 923 | drvdata->hdmiif_map = devm_regmap_init_mmio(dev, drvdata->hdmiif, |
| 924 | &lpass_hdmi_regmap_config); |
| 925 | if (IS_ERR(drvdata->hdmiif_map)) { |
| 926 | dev_err(dev, "error initializing regmap: %ld\n", |
| 927 | PTR_ERR(drvdata->hdmiif_map)); |
| 928 | return PTR_ERR(drvdata->hdmiif_map); |
| 929 | } |
| 930 | } |
| 931 | |
Rohit kumar | a503567 | 2020-08-14 16:22:58 +0530 | [diff] [blame] | 932 | if (variant->init) { |
| 933 | ret = variant->init(pdev); |
| 934 | if (ret) { |
| 935 | dev_err(dev, "error initializing variant: %d\n", ret); |
| 936 | return ret; |
| 937 | } |
| 938 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 939 | |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 940 | for (i = 0; i < variant->num_dai; i++) { |
| 941 | dai_id = variant->dai_driver[i].id; |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 942 | if (dai_id == LPASS_DP_RX) |
| 943 | continue; |
| 944 | |
Stephen Boyd | af27025 | 2021-05-19 18:48:07 -0700 | [diff] [blame] | 945 | drvdata->mi2s_osr_clk[dai_id] = devm_clk_get_optional(dev, |
Linus Walleij | 97c52eb | 2017-04-05 10:34:10 +0200 | [diff] [blame] | 946 | variant->dai_osr_clk_names[i]); |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 947 | drvdata->mi2s_bit_clk[dai_id] = devm_clk_get(dev, |
Linus Walleij | 97c52eb | 2017-04-05 10:34:10 +0200 | [diff] [blame] | 948 | variant->dai_bit_clk_names[i]); |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 949 | if (IS_ERR(drvdata->mi2s_bit_clk[dai_id])) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 950 | dev_err(dev, |
Linus Walleij | 97c52eb | 2017-04-05 10:34:10 +0200 | [diff] [blame] | 951 | "error getting %s: %ld\n", |
| 952 | variant->dai_bit_clk_names[i], |
Julia Lawall | 8985729 | 2015-09-17 10:47:33 +0200 | [diff] [blame] | 953 | PTR_ERR(drvdata->mi2s_bit_clk[dai_id])); |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 954 | return PTR_ERR(drvdata->mi2s_bit_clk[dai_id]); |
| 955 | } |
Srinivasa Rao Mandadapu | c223f41 | 2021-06-09 19:00:39 +0530 | [diff] [blame] | 956 | if (drvdata->mi2s_playback_sd_mode[dai_id] == |
| 957 | LPAIF_I2SCTL_MODE_QUAD01) { |
| 958 | variant->dai_driver[dai_id].playback.channels_min = 4; |
| 959 | variant->dai_driver[dai_id].playback.channels_max = 4; |
| 960 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 961 | } |
| 962 | |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 963 | /* Allocation for i2sctl regmap fields */ |
| 964 | drvdata->i2sctl = devm_kzalloc(&pdev->dev, sizeof(struct lpaif_i2sctl), |
| 965 | GFP_KERNEL); |
| 966 | |
| 967 | /* Initialize bitfields for dai I2SCTL register */ |
| 968 | ret = lpass_cpu_init_i2sctl_bitfields(dev, drvdata->i2sctl, |
| 969 | drvdata->lpaif_map); |
| 970 | if (ret) { |
| 971 | dev_err(dev, "error init i2sctl field: %d\n", ret); |
| 972 | return ret; |
| 973 | } |
| 974 | |
V Sujith Kumar Reddy | 7cb37b7 | 2020-10-08 10:47:01 +0530 | [diff] [blame] | 975 | if (drvdata->hdmi_port_enable) { |
| 976 | ret = lpass_hdmi_init_bitfields(dev, drvdata->hdmiif_map); |
| 977 | if (ret) { |
| 978 | dev_err(dev, "%s error hdmi init failed\n", __func__); |
| 979 | return ret; |
| 980 | } |
| 981 | } |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 982 | ret = devm_snd_soc_register_component(dev, |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 983 | &lpass_cpu_comp_driver, |
| 984 | variant->dai_driver, |
| 985 | variant->num_dai); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 986 | if (ret) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 987 | dev_err(dev, "error registering cpu driver: %d\n", ret); |
Rohit kumar | a503567 | 2020-08-14 16:22:58 +0530 | [diff] [blame] | 988 | goto err; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | ret = asoc_qcom_lpass_platform_register(pdev); |
| 992 | if (ret) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 993 | dev_err(dev, "error registering platform driver: %d\n", ret); |
Rohit kumar | a503567 | 2020-08-14 16:22:58 +0530 | [diff] [blame] | 994 | goto err; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 995 | } |
| 996 | |
Rohit kumar | a503567 | 2020-08-14 16:22:58 +0530 | [diff] [blame] | 997 | err: |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 998 | return ret; |
| 999 | } |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 1000 | EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_platform_probe); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 1001 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 1002 | int asoc_qcom_lpass_cpu_platform_remove(struct platform_device *pdev) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 1003 | { |
| 1004 | struct lpass_data *drvdata = platform_get_drvdata(pdev); |
| 1005 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 1006 | if (drvdata->variant->exit) |
| 1007 | drvdata->variant->exit(pdev); |
| 1008 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 1009 | |
| 1010 | return 0; |
| 1011 | } |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 1012 | EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_platform_remove); |
Srinivas Kandagatla | 9420179 | 2016-10-31 11:25:45 +0000 | [diff] [blame] | 1013 | |
V Sujith Kumar Reddy | 60a9738 | 2020-11-14 00:08:22 +0530 | [diff] [blame] | 1014 | void asoc_qcom_lpass_cpu_platform_shutdown(struct platform_device *pdev) |
| 1015 | { |
| 1016 | struct lpass_data *drvdata = platform_get_drvdata(pdev); |
| 1017 | |
| 1018 | if (drvdata->variant->exit) |
| 1019 | drvdata->variant->exit(pdev); |
| 1020 | |
| 1021 | } |
| 1022 | EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_platform_shutdown); |
| 1023 | |
Srinivas Kandagatla | 9420179 | 2016-10-31 11:25:45 +0000 | [diff] [blame] | 1024 | MODULE_DESCRIPTION("QTi LPASS CPU Driver"); |
| 1025 | MODULE_LICENSE("GPL v2"); |