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