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 | |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 32 | static 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 Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 58 | static 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 Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 64 | ret = clk_set_rate(drvdata->mi2s_osr_clk[dai->driver->id], freq); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 65 | if (ret) |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 66 | dev_err(dai->dev, "error setting mi2s osrclk to %u: %d\n", |
| 67 | freq, ret); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 68 | |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | static 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 Andersson | 46dccc3 | 2017-01-30 13:03:36 -0800 | [diff] [blame] | 78 | ret = clk_prepare_enable(drvdata->mi2s_osr_clk[dai->driver->id]); |
| 79 | if (ret) { |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 80 | 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] | 81 | return ret; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 82 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static void lpass_cpu_daiops_shutdown(struct snd_pcm_substream *substream, |
| 87 | struct snd_soc_dai *dai) |
| 88 | { |
| 89 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
| 90 | |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 91 | clk_disable_unprepare(drvdata->mi2s_bit_clk[dai->driver->id]); |
Srinivas Kandagatla | 3e53ac8 | 2015-05-21 22:52:57 +0100 | [diff] [blame] | 92 | |
Bjorn Andersson | 46dccc3 | 2017-01-30 13:03:36 -0800 | [diff] [blame] | 93 | clk_disable_unprepare(drvdata->mi2s_osr_clk[dai->driver->id]); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream, |
| 97 | struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
| 98 | { |
| 99 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 100 | struct lpaif_i2sctl *i2sctl = drvdata->i2sctl; |
| 101 | unsigned int id = dai->driver->id; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 102 | snd_pcm_format_t format = params_format(params); |
| 103 | unsigned int channels = params_channels(params); |
| 104 | unsigned int rate = params_rate(params); |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 105 | unsigned int mode; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 106 | unsigned int regval; |
| 107 | int bitwidth, ret; |
| 108 | |
| 109 | bitwidth = snd_pcm_format_width(format); |
| 110 | if (bitwidth < 0) { |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 111 | dev_err(dai->dev, "invalid bit width given: %d\n", bitwidth); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 112 | return bitwidth; |
| 113 | } |
| 114 | |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 115 | ret = regmap_fields_write(i2sctl->loopback, id, |
| 116 | LPAIF_I2SCTL_LOOPBACK_DISABLE); |
| 117 | if (ret) { |
| 118 | dev_err(dai->dev, "error updating loopback field: %d\n", ret); |
| 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | ret = regmap_fields_write(i2sctl->wssrc, id, |
| 123 | LPAIF_I2SCTL_WSSRC_INTERNAL); |
| 124 | if (ret) { |
| 125 | dev_err(dai->dev, "error updating wssrc field: %d\n", ret); |
| 126 | return ret; |
| 127 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 128 | |
| 129 | switch (bitwidth) { |
| 130 | case 16: |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 131 | regval = LPAIF_I2SCTL_BITWIDTH_16; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 132 | break; |
| 133 | case 24: |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 134 | regval = LPAIF_I2SCTL_BITWIDTH_24; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 135 | break; |
| 136 | case 32: |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 137 | regval = LPAIF_I2SCTL_BITWIDTH_32; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 138 | break; |
| 139 | default: |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 140 | dev_err(dai->dev, "invalid bitwidth given: %d\n", bitwidth); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 141 | return -EINVAL; |
| 142 | } |
| 143 | |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 144 | ret = regmap_fields_write(i2sctl->bitwidth, id, regval); |
| 145 | if (ret) { |
| 146 | dev_err(dai->dev, "error updating bitwidth field: %d\n", ret); |
| 147 | return ret; |
| 148 | } |
| 149 | |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 150 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 151 | mode = drvdata->mi2s_playback_sd_mode[id]; |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 152 | else |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 153 | mode = drvdata->mi2s_capture_sd_mode[id]; |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 154 | |
| 155 | if (!mode) { |
| 156 | dev_err(dai->dev, "no line is assigned\n"); |
| 157 | return -EINVAL; |
| 158 | } |
| 159 | |
| 160 | switch (channels) { |
| 161 | case 1: |
| 162 | case 2: |
| 163 | switch (mode) { |
| 164 | case LPAIF_I2SCTL_MODE_QUAD01: |
| 165 | case LPAIF_I2SCTL_MODE_6CH: |
| 166 | case LPAIF_I2SCTL_MODE_8CH: |
| 167 | mode = LPAIF_I2SCTL_MODE_SD0; |
| 168 | break; |
| 169 | case LPAIF_I2SCTL_MODE_QUAD23: |
| 170 | mode = LPAIF_I2SCTL_MODE_SD2; |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | break; |
| 175 | case 4: |
| 176 | if (mode < LPAIF_I2SCTL_MODE_QUAD01) { |
| 177 | dev_err(dai->dev, "cannot configure 4 channels with mode %d\n", |
| 178 | mode); |
| 179 | return -EINVAL; |
| 180 | } |
| 181 | |
| 182 | switch (mode) { |
| 183 | case LPAIF_I2SCTL_MODE_6CH: |
| 184 | case LPAIF_I2SCTL_MODE_8CH: |
| 185 | mode = LPAIF_I2SCTL_MODE_QUAD01; |
| 186 | break; |
| 187 | } |
| 188 | break; |
| 189 | case 6: |
| 190 | if (mode < LPAIF_I2SCTL_MODE_6CH) { |
| 191 | dev_err(dai->dev, "cannot configure 6 channels with mode %d\n", |
| 192 | mode); |
| 193 | return -EINVAL; |
| 194 | } |
| 195 | |
| 196 | switch (mode) { |
| 197 | case LPAIF_I2SCTL_MODE_8CH: |
| 198 | mode = LPAIF_I2SCTL_MODE_6CH; |
| 199 | break; |
| 200 | } |
| 201 | break; |
| 202 | case 8: |
| 203 | if (mode < LPAIF_I2SCTL_MODE_8CH) { |
| 204 | dev_err(dai->dev, "cannot configure 8 channels with mode %d\n", |
| 205 | mode); |
| 206 | return -EINVAL; |
| 207 | } |
| 208 | break; |
| 209 | default: |
| 210 | dev_err(dai->dev, "invalid channels given: %u\n", channels); |
| 211 | return -EINVAL; |
| 212 | } |
| 213 | |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 214 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 215 | ret = regmap_fields_write(i2sctl->spkmode, id, |
| 216 | LPAIF_I2SCTL_SPKMODE(mode)); |
| 217 | if (ret) { |
| 218 | dev_err(dai->dev, "error writing to i2sctl spkr mode: %d\n", |
| 219 | ret); |
| 220 | return ret; |
| 221 | } |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 222 | if (channels >= 2) |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 223 | ret = regmap_fields_write(i2sctl->spkmono, id, |
| 224 | LPAIF_I2SCTL_SPKMONO_STEREO); |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 225 | else |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 226 | ret = regmap_fields_write(i2sctl->spkmono, id, |
| 227 | LPAIF_I2SCTL_SPKMONO_MONO); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 228 | } else { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 229 | ret = regmap_fields_write(i2sctl->micmode, id, |
| 230 | LPAIF_I2SCTL_MICMODE(mode)); |
| 231 | if (ret) { |
| 232 | dev_err(dai->dev, "error writing to i2sctl mic mode: %d\n", |
| 233 | ret); |
| 234 | return ret; |
| 235 | } |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 236 | if (channels >= 2) |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 237 | ret = regmap_fields_write(i2sctl->micmono, id, |
| 238 | LPAIF_I2SCTL_MICMONO_STEREO); |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 239 | else |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 240 | ret = regmap_fields_write(i2sctl->micmono, id, |
| 241 | LPAIF_I2SCTL_MICMONO_MONO); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 244 | if (ret) { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 245 | dev_err(dai->dev, "error writing to i2sctl channels mode: %d\n", |
| 246 | ret); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 247 | return ret; |
| 248 | } |
| 249 | |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 250 | ret = clk_set_rate(drvdata->mi2s_bit_clk[id], |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 251 | rate * bitwidth * 2); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 252 | if (ret) { |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 253 | dev_err(dai->dev, "error setting mi2s bitclk to %u: %d\n", |
| 254 | rate * bitwidth * 2, ret); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 255 | return ret; |
| 256 | } |
| 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 261 | static int lpass_cpu_daiops_prepare(struct snd_pcm_substream *substream, |
| 262 | struct snd_soc_dai *dai) |
| 263 | { |
| 264 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 265 | struct lpaif_i2sctl *i2sctl = drvdata->i2sctl; |
| 266 | unsigned int id = dai->driver->id; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 267 | int ret; |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 268 | |
| 269 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 270 | ret = regmap_fields_write(i2sctl->spken, id, |
| 271 | LPAIF_I2SCTL_SPKEN_ENABLE); |
| 272 | } else { |
| 273 | ret = regmap_fields_write(i2sctl->micen, id, |
| 274 | LPAIF_I2SCTL_MICEN_ENABLE); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 275 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 276 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 277 | if (ret) |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 278 | dev_err(dai->dev, "error writing to i2sctl enable: %d\n", ret); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 279 | |
| 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | static int lpass_cpu_daiops_trigger(struct snd_pcm_substream *substream, |
| 284 | int cmd, struct snd_soc_dai *dai) |
| 285 | { |
| 286 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 287 | struct lpaif_i2sctl *i2sctl = drvdata->i2sctl; |
| 288 | unsigned int id = dai->driver->id; |
Takashi Iwai | 96f05be | 2015-04-13 14:23:29 +0200 | [diff] [blame] | 289 | int ret = -EINVAL; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 290 | |
| 291 | switch (cmd) { |
| 292 | case SNDRV_PCM_TRIGGER_START: |
| 293 | case SNDRV_PCM_TRIGGER_RESUME: |
| 294 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 295 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 296 | ret = regmap_fields_write(i2sctl->spken, id, |
| 297 | LPAIF_I2SCTL_SPKEN_ENABLE); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 298 | } else { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 299 | ret = regmap_fields_write(i2sctl->micen, id, |
| 300 | LPAIF_I2SCTL_MICEN_ENABLE); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 301 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 302 | if (ret) |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 303 | dev_err(dai->dev, "error writing to i2sctl reg: %d\n", |
| 304 | ret); |
V Sujith Kumar Reddy | 7e6799d | 2020-09-18 22:24:33 +0530 | [diff] [blame^] | 305 | |
| 306 | ret = clk_prepare_enable(drvdata->mi2s_bit_clk[id]); |
| 307 | if (ret) { |
| 308 | dev_err(dai->dev, "error in enabling mi2s bit clk: %d\n", ret); |
| 309 | clk_disable_unprepare(drvdata->mi2s_osr_clk[id]); |
| 310 | return ret; |
| 311 | } |
| 312 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 313 | break; |
| 314 | case SNDRV_PCM_TRIGGER_STOP: |
| 315 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 316 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 317 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 318 | ret = regmap_fields_write(i2sctl->spken, id, |
| 319 | LPAIF_I2SCTL_SPKEN_DISABLE); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 320 | } else { |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 321 | ret = regmap_fields_write(i2sctl->micen, id, |
| 322 | LPAIF_I2SCTL_MICEN_DISABLE); |
Srinivas Kandagatla | fb5d115 | 2016-02-11 12:18:33 +0000 | [diff] [blame] | 323 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 324 | if (ret) |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 325 | dev_err(dai->dev, "error writing to i2sctl reg: %d\n", |
| 326 | ret); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 327 | break; |
| 328 | } |
| 329 | |
| 330 | return ret; |
| 331 | } |
| 332 | |
Axel Lin | 618718d | 2015-08-28 10:53:31 +0800 | [diff] [blame] | 333 | const struct snd_soc_dai_ops asoc_qcom_lpass_cpu_dai_ops = { |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 334 | .set_sysclk = lpass_cpu_daiops_set_sysclk, |
| 335 | .startup = lpass_cpu_daiops_startup, |
| 336 | .shutdown = lpass_cpu_daiops_shutdown, |
| 337 | .hw_params = lpass_cpu_daiops_hw_params, |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 338 | .prepare = lpass_cpu_daiops_prepare, |
| 339 | .trigger = lpass_cpu_daiops_trigger, |
| 340 | }; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 341 | EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_dai_ops); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 342 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 343 | int asoc_qcom_lpass_cpu_dai_probe(struct snd_soc_dai *dai) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 344 | { |
| 345 | struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai); |
| 346 | int ret; |
| 347 | |
| 348 | /* ensure audio hardware is disabled */ |
| 349 | ret = regmap_write(drvdata->lpaif_map, |
Srinivas Kandagatla | 0ae9fd3 | 2015-05-16 13:32:25 +0100 | [diff] [blame] | 350 | LPAIF_I2SCTL_REG(drvdata->variant, dai->driver->id), 0); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 351 | if (ret) |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 352 | dev_err(dai->dev, "error writing to i2sctl reg: %d\n", ret); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 353 | |
| 354 | return ret; |
| 355 | } |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 356 | EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_dai_probe); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 357 | |
| 358 | static const struct snd_soc_component_driver lpass_cpu_comp_driver = { |
| 359 | .name = "lpass-cpu", |
| 360 | }; |
| 361 | |
| 362 | static bool lpass_cpu_regmap_writeable(struct device *dev, unsigned int reg) |
| 363 | { |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 364 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 365 | struct lpass_variant *v = drvdata->variant; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 366 | int i; |
| 367 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 368 | for (i = 0; i < v->i2s_ports; ++i) |
| 369 | if (reg == LPAIF_I2SCTL_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 370 | return true; |
| 371 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 372 | for (i = 0; i < v->irq_ports; ++i) { |
| 373 | if (reg == LPAIF_IRQEN_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 374 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 375 | if (reg == LPAIF_IRQCLEAR_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 376 | return true; |
| 377 | } |
| 378 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 379 | for (i = 0; i < v->rdma_channels; ++i) { |
| 380 | if (reg == LPAIF_RDMACTL_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 381 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 382 | if (reg == LPAIF_RDMABASE_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 383 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 384 | if (reg == LPAIF_RDMABUFF_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 385 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 386 | if (reg == LPAIF_RDMAPER_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 387 | return true; |
| 388 | } |
| 389 | |
Srinivas Kandagatla | dad8061 | 2016-02-11 12:18:27 +0000 | [diff] [blame] | 390 | for (i = 0; i < v->wrdma_channels; ++i) { |
| 391 | if (reg == LPAIF_WRDMACTL_REG(v, i + v->wrdma_channel_start)) |
| 392 | return true; |
| 393 | if (reg == LPAIF_WRDMABASE_REG(v, i + v->wrdma_channel_start)) |
| 394 | return true; |
| 395 | if (reg == LPAIF_WRDMABUFF_REG(v, i + v->wrdma_channel_start)) |
| 396 | return true; |
| 397 | if (reg == LPAIF_WRDMAPER_REG(v, i + v->wrdma_channel_start)) |
| 398 | return true; |
| 399 | } |
| 400 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 401 | return false; |
| 402 | } |
| 403 | |
| 404 | static bool lpass_cpu_regmap_readable(struct device *dev, unsigned int reg) |
| 405 | { |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 406 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 407 | struct lpass_variant *v = drvdata->variant; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 408 | int i; |
| 409 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 410 | for (i = 0; i < v->i2s_ports; ++i) |
| 411 | if (reg == LPAIF_I2SCTL_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 412 | return true; |
| 413 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 414 | for (i = 0; i < v->irq_ports; ++i) { |
| 415 | if (reg == LPAIF_IRQEN_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 416 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 417 | if (reg == LPAIF_IRQSTAT_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 418 | return true; |
| 419 | } |
| 420 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 421 | for (i = 0; i < v->rdma_channels; ++i) { |
| 422 | if (reg == LPAIF_RDMACTL_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 423 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 424 | if (reg == LPAIF_RDMABASE_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 425 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 426 | if (reg == LPAIF_RDMABUFF_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 427 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 428 | if (reg == LPAIF_RDMACURR_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 429 | return true; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 430 | if (reg == LPAIF_RDMAPER_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 431 | return true; |
| 432 | } |
| 433 | |
Srinivas Kandagatla | dad8061 | 2016-02-11 12:18:27 +0000 | [diff] [blame] | 434 | for (i = 0; i < v->wrdma_channels; ++i) { |
| 435 | if (reg == LPAIF_WRDMACTL_REG(v, i + v->wrdma_channel_start)) |
| 436 | return true; |
| 437 | if (reg == LPAIF_WRDMABASE_REG(v, i + v->wrdma_channel_start)) |
| 438 | return true; |
| 439 | if (reg == LPAIF_WRDMABUFF_REG(v, i + v->wrdma_channel_start)) |
| 440 | return true; |
| 441 | if (reg == LPAIF_WRDMACURR_REG(v, i + v->wrdma_channel_start)) |
| 442 | return true; |
| 443 | if (reg == LPAIF_WRDMAPER_REG(v, i + v->wrdma_channel_start)) |
| 444 | return true; |
| 445 | } |
| 446 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 447 | return false; |
| 448 | } |
| 449 | |
| 450 | static bool lpass_cpu_regmap_volatile(struct device *dev, unsigned int reg) |
| 451 | { |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 452 | struct lpass_data *drvdata = dev_get_drvdata(dev); |
| 453 | struct lpass_variant *v = drvdata->variant; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 454 | int i; |
| 455 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 456 | for (i = 0; i < v->irq_ports; ++i) |
| 457 | if (reg == LPAIF_IRQSTAT_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 458 | return true; |
| 459 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 460 | for (i = 0; i < v->rdma_channels; ++i) |
| 461 | if (reg == LPAIF_RDMACURR_REG(v, i)) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 462 | return true; |
| 463 | |
Srinivas Kandagatla | dad8061 | 2016-02-11 12:18:27 +0000 | [diff] [blame] | 464 | for (i = 0; i < v->wrdma_channels; ++i) |
| 465 | if (reg == LPAIF_WRDMACURR_REG(v, i + v->wrdma_channel_start)) |
| 466 | return true; |
| 467 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 468 | return false; |
| 469 | } |
| 470 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 471 | static struct regmap_config lpass_cpu_regmap_config = { |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 472 | .reg_bits = 32, |
| 473 | .reg_stride = 4, |
| 474 | .val_bits = 32, |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 475 | .writeable_reg = lpass_cpu_regmap_writeable, |
| 476 | .readable_reg = lpass_cpu_regmap_readable, |
| 477 | .volatile_reg = lpass_cpu_regmap_volatile, |
| 478 | .cache_type = REGCACHE_FLAT, |
| 479 | }; |
| 480 | |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 481 | static unsigned int of_lpass_cpu_parse_sd_lines(struct device *dev, |
| 482 | struct device_node *node, |
| 483 | const char *name) |
| 484 | { |
| 485 | unsigned int lines[LPASS_CPU_MAX_MI2S_LINES]; |
| 486 | unsigned int sd_line_mask = 0; |
| 487 | int num_lines, i; |
| 488 | |
| 489 | num_lines = of_property_read_variable_u32_array(node, name, lines, 0, |
| 490 | LPASS_CPU_MAX_MI2S_LINES); |
| 491 | if (num_lines < 0) |
| 492 | return LPAIF_I2SCTL_MODE_NONE; |
| 493 | |
| 494 | for (i = 0; i < num_lines; i++) |
| 495 | sd_line_mask |= BIT(lines[i]); |
| 496 | |
| 497 | switch (sd_line_mask) { |
| 498 | case LPASS_CPU_I2S_SD0_MASK: |
| 499 | return LPAIF_I2SCTL_MODE_SD0; |
| 500 | case LPASS_CPU_I2S_SD1_MASK: |
| 501 | return LPAIF_I2SCTL_MODE_SD1; |
| 502 | case LPASS_CPU_I2S_SD2_MASK: |
| 503 | return LPAIF_I2SCTL_MODE_SD2; |
| 504 | case LPASS_CPU_I2S_SD3_MASK: |
| 505 | return LPAIF_I2SCTL_MODE_SD3; |
| 506 | case LPASS_CPU_I2S_SD0_1_MASK: |
| 507 | return LPAIF_I2SCTL_MODE_QUAD01; |
| 508 | case LPASS_CPU_I2S_SD2_3_MASK: |
| 509 | return LPAIF_I2SCTL_MODE_QUAD23; |
| 510 | case LPASS_CPU_I2S_SD0_1_2_MASK: |
| 511 | return LPAIF_I2SCTL_MODE_6CH; |
| 512 | case LPASS_CPU_I2S_SD0_1_2_3_MASK: |
| 513 | return LPAIF_I2SCTL_MODE_8CH; |
| 514 | default: |
| 515 | dev_err(dev, "Unsupported SD line mask: %#x\n", sd_line_mask); |
| 516 | return LPAIF_I2SCTL_MODE_NONE; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | static void of_lpass_cpu_parse_dai_data(struct device *dev, |
| 521 | struct lpass_data *data) |
| 522 | { |
| 523 | struct device_node *node; |
| 524 | int ret, id; |
| 525 | |
| 526 | /* Allow all channels by default for backwards compatibility */ |
| 527 | for (id = 0; id < data->variant->num_dai; id++) { |
| 528 | data->mi2s_playback_sd_mode[id] = LPAIF_I2SCTL_MODE_8CH; |
| 529 | data->mi2s_capture_sd_mode[id] = LPAIF_I2SCTL_MODE_8CH; |
| 530 | } |
| 531 | |
| 532 | for_each_child_of_node(dev->of_node, node) { |
| 533 | ret = of_property_read_u32(node, "reg", &id); |
| 534 | if (ret || id < 0 || id >= data->variant->num_dai) { |
| 535 | dev_err(dev, "valid dai id not found: %d\n", ret); |
| 536 | continue; |
| 537 | } |
| 538 | |
| 539 | data->mi2s_playback_sd_mode[id] = |
| 540 | of_lpass_cpu_parse_sd_lines(dev, node, |
| 541 | "qcom,playback-sd-lines"); |
| 542 | data->mi2s_capture_sd_mode[id] = |
| 543 | of_lpass_cpu_parse_sd_lines(dev, node, |
| 544 | "qcom,capture-sd-lines"); |
| 545 | } |
| 546 | } |
| 547 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 548 | int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 549 | { |
| 550 | struct lpass_data *drvdata; |
Kenneth Westfield | 8ebe148 | 2015-03-13 00:54:17 -0700 | [diff] [blame] | 551 | struct device_node *dsp_of_node; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 552 | struct resource *res; |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 553 | struct lpass_variant *variant; |
| 554 | struct device *dev = &pdev->dev; |
| 555 | const struct of_device_id *match; |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 556 | int ret, i, dai_id; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 557 | |
Kenneth Westfield | 8ebe148 | 2015-03-13 00:54:17 -0700 | [diff] [blame] | 558 | dsp_of_node = of_parse_phandle(pdev->dev.of_node, "qcom,adsp", 0); |
| 559 | if (dsp_of_node) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 560 | dev_err(dev, "DSP exists and holds audio resources\n"); |
Kenneth Westfield | 8ebe148 | 2015-03-13 00:54:17 -0700 | [diff] [blame] | 561 | return -EBUSY; |
| 562 | } |
| 563 | |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 564 | drvdata = devm_kzalloc(dev, sizeof(struct lpass_data), GFP_KERNEL); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 565 | if (!drvdata) |
| 566 | return -ENOMEM; |
| 567 | platform_set_drvdata(pdev, drvdata); |
| 568 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 569 | match = of_match_device(dev->driver->of_match_table, dev); |
| 570 | if (!match || !match->data) |
| 571 | return -EINVAL; |
| 572 | |
| 573 | drvdata->variant = (struct lpass_variant *)match->data; |
| 574 | variant = drvdata->variant; |
| 575 | |
Stephan Gerhold | 4ff028f6 | 2020-04-25 20:46:57 +0200 | [diff] [blame] | 576 | of_lpass_cpu_parse_dai_data(dev, drvdata); |
| 577 | |
Rohit kumar | 93dbbd6 | 2020-08-14 16:23:06 +0530 | [diff] [blame] | 578 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 579 | |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 580 | drvdata->lpaif = devm_ioremap_resource(dev, res); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 581 | if (IS_ERR((void const __force *)drvdata->lpaif)) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 582 | dev_err(dev, "error mapping reg resource: %ld\n", |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 583 | PTR_ERR((void const __force *)drvdata->lpaif)); |
| 584 | return PTR_ERR((void const __force *)drvdata->lpaif); |
| 585 | } |
| 586 | |
Srinivas Kandagatla | dad8061 | 2016-02-11 12:18:27 +0000 | [diff] [blame] | 587 | lpass_cpu_regmap_config.max_register = LPAIF_WRDMAPER_REG(variant, |
| 588 | variant->wrdma_channels + |
| 589 | variant->wrdma_channel_start); |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 590 | |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 591 | drvdata->lpaif_map = devm_regmap_init_mmio(dev, drvdata->lpaif, |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 592 | &lpass_cpu_regmap_config); |
| 593 | if (IS_ERR(drvdata->lpaif_map)) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 594 | dev_err(dev, "error initializing regmap: %ld\n", |
Bjorn Andersson | b6e643a | 2017-01-30 13:03:37 -0800 | [diff] [blame] | 595 | PTR_ERR(drvdata->lpaif_map)); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 596 | return PTR_ERR(drvdata->lpaif_map); |
| 597 | } |
| 598 | |
Rohit kumar | a503567 | 2020-08-14 16:22:58 +0530 | [diff] [blame] | 599 | if (variant->init) { |
| 600 | ret = variant->init(pdev); |
| 601 | if (ret) { |
| 602 | dev_err(dev, "error initializing variant: %d\n", ret); |
| 603 | return ret; |
| 604 | } |
| 605 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 606 | |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 607 | for (i = 0; i < variant->num_dai; i++) { |
| 608 | dai_id = variant->dai_driver[i].id; |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 609 | drvdata->mi2s_osr_clk[dai_id] = devm_clk_get(dev, |
Linus Walleij | 97c52eb | 2017-04-05 10:34:10 +0200 | [diff] [blame] | 610 | variant->dai_osr_clk_names[i]); |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 611 | if (IS_ERR(drvdata->mi2s_osr_clk[dai_id])) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 612 | dev_warn(dev, |
Linus Walleij | 97c52eb | 2017-04-05 10:34:10 +0200 | [diff] [blame] | 613 | "%s() error getting optional %s: %ld\n", |
| 614 | __func__, |
| 615 | variant->dai_osr_clk_names[i], |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 616 | PTR_ERR(drvdata->mi2s_osr_clk[dai_id])); |
Bjorn Andersson | 46dccc3 | 2017-01-30 13:03:36 -0800 | [diff] [blame] | 617 | |
| 618 | drvdata->mi2s_osr_clk[dai_id] = NULL; |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 619 | } |
| 620 | |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 621 | drvdata->mi2s_bit_clk[dai_id] = devm_clk_get(dev, |
Linus Walleij | 97c52eb | 2017-04-05 10:34:10 +0200 | [diff] [blame] | 622 | variant->dai_bit_clk_names[i]); |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 623 | if (IS_ERR(drvdata->mi2s_bit_clk[dai_id])) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 624 | dev_err(dev, |
Linus Walleij | 97c52eb | 2017-04-05 10:34:10 +0200 | [diff] [blame] | 625 | "error getting %s: %ld\n", |
| 626 | variant->dai_bit_clk_names[i], |
Julia Lawall | 8985729 | 2015-09-17 10:47:33 +0200 | [diff] [blame] | 627 | PTR_ERR(drvdata->mi2s_bit_clk[dai_id])); |
Srinivas Kandagatla | 9a127cf | 2015-05-21 22:52:49 +0100 | [diff] [blame] | 628 | return PTR_ERR(drvdata->mi2s_bit_clk[dai_id]); |
| 629 | } |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 630 | } |
| 631 | |
Rohit kumar | b5022a3 | 2020-08-14 16:23:01 +0530 | [diff] [blame] | 632 | /* Allocation for i2sctl regmap fields */ |
| 633 | drvdata->i2sctl = devm_kzalloc(&pdev->dev, sizeof(struct lpaif_i2sctl), |
| 634 | GFP_KERNEL); |
| 635 | |
| 636 | /* Initialize bitfields for dai I2SCTL register */ |
| 637 | ret = lpass_cpu_init_i2sctl_bitfields(dev, drvdata->i2sctl, |
| 638 | drvdata->lpaif_map); |
| 639 | if (ret) { |
| 640 | dev_err(dev, "error init i2sctl field: %d\n", ret); |
| 641 | return ret; |
| 642 | } |
| 643 | |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 644 | ret = devm_snd_soc_register_component(dev, |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 645 | &lpass_cpu_comp_driver, |
| 646 | variant->dai_driver, |
| 647 | variant->num_dai); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 648 | if (ret) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 649 | dev_err(dev, "error registering cpu driver: %d\n", ret); |
Rohit kumar | a503567 | 2020-08-14 16:22:58 +0530 | [diff] [blame] | 650 | goto err; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | ret = asoc_qcom_lpass_platform_register(pdev); |
| 654 | if (ret) { |
Tang Bin | 952c0e2 | 2020-05-04 14:59:47 +0800 | [diff] [blame] | 655 | dev_err(dev, "error registering platform driver: %d\n", ret); |
Rohit kumar | a503567 | 2020-08-14 16:22:58 +0530 | [diff] [blame] | 656 | goto err; |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 657 | } |
| 658 | |
Rohit kumar | a503567 | 2020-08-14 16:22:58 +0530 | [diff] [blame] | 659 | err: |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 660 | return ret; |
| 661 | } |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 662 | EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_platform_probe); |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 663 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 664 | int asoc_qcom_lpass_cpu_platform_remove(struct platform_device *pdev) |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 665 | { |
| 666 | struct lpass_data *drvdata = platform_get_drvdata(pdev); |
| 667 | |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 668 | if (drvdata->variant->exit) |
| 669 | drvdata->variant->exit(pdev); |
| 670 | |
Kenneth Westfield | 80beab8 | 2015-03-03 16:21:54 -0800 | [diff] [blame] | 671 | |
| 672 | return 0; |
| 673 | } |
Srinivas Kandagatla | 9bae488 | 2015-05-16 13:32:17 +0100 | [diff] [blame] | 674 | EXPORT_SYMBOL_GPL(asoc_qcom_lpass_cpu_platform_remove); |
Srinivas Kandagatla | 9420179 | 2016-10-31 11:25:45 +0000 | [diff] [blame] | 675 | |
| 676 | MODULE_DESCRIPTION("QTi LPASS CPU Driver"); |
| 677 | MODULE_LICENSE("GPL v2"); |