| .. | .. |
|---|
| 1 | | -/* |
|---|
| 2 | | - * rk3328_codec.c -- rk3328 ALSA Soc Audio driver |
|---|
| 3 | | - * |
|---|
| 4 | | - * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd All rights reserved. |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 7 | | - * under the terms and conditions of the GNU General Public License, |
|---|
| 8 | | - * version 2, as published by the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
|---|
| 11 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 12 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 13 | | - * more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License |
|---|
| 16 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | | - * |
|---|
| 18 | | - */ |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | +// |
|---|
| 3 | +// rk3328 ALSA SoC Audio driver |
|---|
| 4 | +// |
|---|
| 5 | +// Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd All rights reserved. |
|---|
| 19 | 6 | |
|---|
| 20 | | -#include <linux/module.h> |
|---|
| 21 | | -#include <linux/device.h> |
|---|
| 22 | | -#include <linux/delay.h> |
|---|
| 23 | | -#include <linux/of.h> |
|---|
| 24 | 7 | #include <linux/clk.h> |
|---|
| 25 | | -#include <linux/mfd/syscon.h> |
|---|
| 8 | +#include <linux/delay.h> |
|---|
| 9 | +#include <linux/device.h> |
|---|
| 10 | +#include <linux/gpio/consumer.h> |
|---|
| 11 | +#include <linux/module.h> |
|---|
| 12 | +#include <linux/of.h> |
|---|
| 26 | 13 | #include <linux/platform_device.h> |
|---|
| 27 | 14 | #include <linux/pm_runtime.h> |
|---|
| 28 | 15 | #include <linux/regmap.h> |
|---|
| 29 | | -#include <sound/pcm_params.h> |
|---|
| 16 | +#include <linux/mfd/syscon.h> |
|---|
| 30 | 17 | #include <sound/dmaengine_pcm.h> |
|---|
| 18 | +#include <sound/pcm_params.h> |
|---|
| 31 | 19 | #include "rk3328_codec.h" |
|---|
| 32 | 20 | |
|---|
| 33 | 21 | /* |
|---|
| .. | .. |
|---|
| 44 | 32 | |
|---|
| 45 | 33 | struct rk3328_codec_priv { |
|---|
| 46 | 34 | struct regmap *regmap; |
|---|
| 47 | | - struct regmap *grf; |
|---|
| 35 | + struct gpio_desc *mute; |
|---|
| 48 | 36 | struct clk *mclk; |
|---|
| 49 | 37 | struct clk *pclk; |
|---|
| 50 | 38 | unsigned int sclk; |
|---|
| .. | .. |
|---|
| 66 | 54 | { HPOUT_POP_CTRL, 0x11 }, |
|---|
| 67 | 55 | }; |
|---|
| 68 | 56 | |
|---|
| 69 | | -static int rk3328_codec_reset(struct snd_soc_component *component) |
|---|
| 57 | +static int rk3328_codec_reset(struct rk3328_codec_priv *rk3328) |
|---|
| 70 | 58 | { |
|---|
| 71 | | - struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(component); |
|---|
| 72 | | - |
|---|
| 73 | | - regmap_write(rk3328->regmap, CODEC_RESET, 0); |
|---|
| 59 | + regmap_write(rk3328->regmap, CODEC_RESET, 0x00); |
|---|
| 74 | 60 | mdelay(10); |
|---|
| 75 | 61 | regmap_write(rk3328->regmap, CODEC_RESET, 0x03); |
|---|
| 76 | 62 | |
|---|
| 77 | 63 | return 0; |
|---|
| 78 | 64 | } |
|---|
| 79 | 65 | |
|---|
| 80 | | -static int rk3328_set_dai_fmt(struct snd_soc_dai *dai, |
|---|
| 81 | | - unsigned int fmt) |
|---|
| 66 | +static int rk3328_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
|---|
| 82 | 67 | { |
|---|
| 83 | | - struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(dai->component); |
|---|
| 84 | | - unsigned int val = 0; |
|---|
| 68 | + struct rk3328_codec_priv *rk3328 = |
|---|
| 69 | + snd_soc_component_get_drvdata(dai->component); |
|---|
| 70 | + unsigned int val; |
|---|
| 85 | 71 | |
|---|
| 86 | 72 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
|---|
| 87 | 73 | case SND_SOC_DAIFMT_CBS_CFS: |
|---|
| 88 | | - val |= PIN_DIRECTION_IN | DAC_I2S_MODE_SLAVE; |
|---|
| 74 | + val = PIN_DIRECTION_IN | DAC_I2S_MODE_SLAVE; |
|---|
| 89 | 75 | break; |
|---|
| 90 | 76 | case SND_SOC_DAIFMT_CBM_CFM: |
|---|
| 91 | | - val |= PIN_DIRECTION_OUT | DAC_I2S_MODE_MASTER; |
|---|
| 77 | + val = PIN_DIRECTION_OUT | DAC_I2S_MODE_MASTER; |
|---|
| 92 | 78 | break; |
|---|
| 93 | 79 | default: |
|---|
| 94 | 80 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 97 | 83 | regmap_update_bits(rk3328->regmap, DAC_INIT_CTRL1, |
|---|
| 98 | 84 | PIN_DIRECTION_MASK | DAC_I2S_MODE_MASK, val); |
|---|
| 99 | 85 | |
|---|
| 100 | | - val = 0; |
|---|
| 101 | 86 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
|---|
| 102 | 87 | case SND_SOC_DAIFMT_DSP_A: |
|---|
| 103 | 88 | case SND_SOC_DAIFMT_DSP_B: |
|---|
| 104 | | - val |= DAC_MODE_PCM; |
|---|
| 89 | + val = DAC_MODE_PCM; |
|---|
| 105 | 90 | break; |
|---|
| 106 | 91 | case SND_SOC_DAIFMT_I2S: |
|---|
| 107 | | - val |= DAC_MODE_I2S; |
|---|
| 92 | + val = DAC_MODE_I2S; |
|---|
| 108 | 93 | break; |
|---|
| 109 | 94 | case SND_SOC_DAIFMT_RIGHT_J: |
|---|
| 110 | | - val |= DAC_MODE_RJM; |
|---|
| 95 | + val = DAC_MODE_RJM; |
|---|
| 111 | 96 | break; |
|---|
| 112 | 97 | case SND_SOC_DAIFMT_LEFT_J: |
|---|
| 113 | | - val |= DAC_MODE_LJM; |
|---|
| 98 | + val = DAC_MODE_LJM; |
|---|
| 114 | 99 | break; |
|---|
| 115 | 100 | default: |
|---|
| 116 | 101 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 118 | 103 | |
|---|
| 119 | 104 | regmap_update_bits(rk3328->regmap, DAC_INIT_CTRL2, |
|---|
| 120 | 105 | DAC_MODE_MASK, val); |
|---|
| 106 | + |
|---|
| 121 | 107 | return 0; |
|---|
| 122 | 108 | } |
|---|
| 123 | 109 | |
|---|
| 124 | | -static void rk3328_analog_output(struct rk3328_codec_priv *rk3328, int mute) |
|---|
| 110 | +static int rk3328_mute_stream(struct snd_soc_dai *dai, int mute, int direction) |
|---|
| 125 | 111 | { |
|---|
| 126 | | - regmap_write(rk3328->grf, RK3328_GRF_SOC_CON10, |
|---|
| 127 | | - (BIT(1) << 16) | (mute << 1)); |
|---|
| 128 | | -} |
|---|
| 129 | | - |
|---|
| 130 | | -static int rk3328_digital_mute(struct snd_soc_dai *dai, int mute) |
|---|
| 131 | | -{ |
|---|
| 132 | | - struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(dai->component); |
|---|
| 133 | | - unsigned int val = 0; |
|---|
| 112 | + struct rk3328_codec_priv *rk3328 = |
|---|
| 113 | + snd_soc_component_get_drvdata(dai->component); |
|---|
| 114 | + unsigned int val; |
|---|
| 134 | 115 | |
|---|
| 135 | 116 | if (mute) |
|---|
| 136 | 117 | val = HPOUTL_MUTE | HPOUTR_MUTE; |
|---|
| .. | .. |
|---|
| 139 | 120 | |
|---|
| 140 | 121 | regmap_update_bits(rk3328->regmap, HPOUT_CTRL, |
|---|
| 141 | 122 | HPOUTL_MUTE_MASK | HPOUTR_MUTE_MASK, val); |
|---|
| 123 | + |
|---|
| 142 | 124 | return 0; |
|---|
| 143 | 125 | } |
|---|
| 144 | 126 | |
|---|
| 145 | | -static int rk3328_codec_power_on(struct snd_soc_component *component, int wait_ms) |
|---|
| 127 | +static int rk3328_codec_power_on(struct rk3328_codec_priv *rk3328, int wait_ms) |
|---|
| 146 | 128 | { |
|---|
| 147 | | - struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(component); |
|---|
| 148 | | - |
|---|
| 149 | 129 | regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, |
|---|
| 150 | 130 | DAC_CHARGE_XCHARGE_MASK, DAC_CHARGE_PRECHARGE); |
|---|
| 151 | 131 | mdelay(10); |
|---|
| 152 | 132 | regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, |
|---|
| 153 | 133 | DAC_CHARGE_CURRENT_ALL_MASK, |
|---|
| 154 | 134 | DAC_CHARGE_CURRENT_ALL_ON); |
|---|
| 155 | | - |
|---|
| 156 | 135 | mdelay(wait_ms); |
|---|
| 157 | 136 | |
|---|
| 158 | 137 | return 0; |
|---|
| 159 | 138 | } |
|---|
| 160 | 139 | |
|---|
| 161 | | -static int rk3328_codec_power_off(struct snd_soc_component *component, int wait_ms) |
|---|
| 140 | +static int rk3328_codec_power_off(struct rk3328_codec_priv *rk3328, int wait_ms) |
|---|
| 162 | 141 | { |
|---|
| 163 | | - struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(component); |
|---|
| 164 | | - |
|---|
| 165 | 142 | regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, |
|---|
| 166 | 143 | DAC_CHARGE_XCHARGE_MASK, DAC_CHARGE_DISCHARGE); |
|---|
| 167 | 144 | mdelay(10); |
|---|
| 168 | 145 | regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, |
|---|
| 169 | 146 | DAC_CHARGE_CURRENT_ALL_MASK, |
|---|
| 170 | 147 | DAC_CHARGE_CURRENT_ALL_ON); |
|---|
| 171 | | - |
|---|
| 172 | 148 | mdelay(wait_ms); |
|---|
| 173 | 149 | |
|---|
| 174 | 150 | return 0; |
|---|
| 175 | 151 | } |
|---|
| 176 | 152 | |
|---|
| 177 | | -static struct rk3328_reg_msk_val playback_open_list[] = { |
|---|
| 153 | +static const struct rk3328_reg_msk_val playback_open_list[] = { |
|---|
| 178 | 154 | { DAC_PWR_CTRL, DAC_PWR_MASK, DAC_PWR_ON }, |
|---|
| 179 | 155 | { DAC_PWR_CTRL, DACL_PATH_REFV_MASK | DACR_PATH_REFV_MASK, |
|---|
| 180 | 156 | DACL_PATH_REFV_ON | DACR_PATH_REFV_ON }, |
|---|
| 181 | | - { DAC_PWR_CTRL, HPOUTL_ZERO_CROSSING_ON | HPOUTR_ZERO_CROSSING_ON, |
|---|
| 157 | + { DAC_PWR_CTRL, HPOUTL_ZERO_CROSSING_MASK | HPOUTR_ZERO_CROSSING_MASK, |
|---|
| 182 | 158 | HPOUTL_ZERO_CROSSING_ON | HPOUTR_ZERO_CROSSING_ON }, |
|---|
| 183 | 159 | { HPOUT_POP_CTRL, HPOUTR_POP_MASK | HPOUTL_POP_MASK, |
|---|
| 184 | 160 | HPOUTR_POP_WORK | HPOUTL_POP_WORK }, |
|---|
| .. | .. |
|---|
| 203 | 179 | HPOUTL_UNMUTE | HPOUTR_UNMUTE }, |
|---|
| 204 | 180 | }; |
|---|
| 205 | 181 | |
|---|
| 206 | | -#define PLAYBACK_OPEN_LIST_LEN ARRAY_SIZE(playback_open_list) |
|---|
| 207 | | - |
|---|
| 208 | | -static int rk3328_codec_open_playback(struct snd_soc_component *component) |
|---|
| 182 | +static int rk3328_codec_open_playback(struct rk3328_codec_priv *rk3328) |
|---|
| 209 | 183 | { |
|---|
| 210 | | - struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(component); |
|---|
| 211 | | - int i = 0; |
|---|
| 184 | + int i; |
|---|
| 212 | 185 | |
|---|
| 213 | 186 | regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, |
|---|
| 214 | 187 | DAC_CHARGE_CURRENT_ALL_MASK, |
|---|
| 215 | 188 | DAC_CHARGE_CURRENT_I); |
|---|
| 216 | 189 | |
|---|
| 217 | | - for (i = 0; i < PLAYBACK_OPEN_LIST_LEN; i++) { |
|---|
| 190 | + for (i = 0; i < ARRAY_SIZE(playback_open_list); i++) { |
|---|
| 218 | 191 | regmap_update_bits(rk3328->regmap, |
|---|
| 219 | 192 | playback_open_list[i].reg, |
|---|
| 220 | 193 | playback_open_list[i].msk, |
|---|
| .. | .. |
|---|
| 223 | 196 | } |
|---|
| 224 | 197 | |
|---|
| 225 | 198 | msleep(rk3328->spk_depop_time); |
|---|
| 226 | | - rk3328_analog_output(rk3328, 1); |
|---|
| 199 | + gpiod_set_value(rk3328->mute, 0); |
|---|
| 227 | 200 | |
|---|
| 228 | 201 | regmap_update_bits(rk3328->regmap, HPOUTL_GAIN_CTRL, |
|---|
| 229 | 202 | HPOUTL_GAIN_MASK, OUT_VOLUME); |
|---|
| 230 | 203 | regmap_update_bits(rk3328->regmap, HPOUTR_GAIN_CTRL, |
|---|
| 231 | 204 | HPOUTR_GAIN_MASK, OUT_VOLUME); |
|---|
| 205 | + |
|---|
| 232 | 206 | return 0; |
|---|
| 233 | 207 | } |
|---|
| 234 | 208 | |
|---|
| 235 | | -static struct rk3328_reg_msk_val playback_close_list[] = { |
|---|
| 209 | +static const struct rk3328_reg_msk_val playback_close_list[] = { |
|---|
| 236 | 210 | { HPMIX_CTRL, HPMIXL_INIT2_MASK | HPMIXR_INIT2_MASK, |
|---|
| 237 | 211 | HPMIXL_INIT2_DIS | HPMIXR_INIT2_DIS }, |
|---|
| 238 | 212 | { DAC_SELECT, DACL_SELECT_MASK | DACR_SELECT_MASK, |
|---|
| .. | .. |
|---|
| 259 | 233 | DACL_INIT_OFF | DACR_INIT_OFF }, |
|---|
| 260 | 234 | }; |
|---|
| 261 | 235 | |
|---|
| 262 | | -#define PLAYBACK_CLOSE_LIST_LEN ARRAY_SIZE(playback_close_list) |
|---|
| 263 | | - |
|---|
| 264 | | -static int rk3328_codec_close_playback(struct snd_soc_component *component) |
|---|
| 236 | +static int rk3328_codec_close_playback(struct rk3328_codec_priv *rk3328) |
|---|
| 265 | 237 | { |
|---|
| 266 | | - struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(component); |
|---|
| 267 | | - int i = 0; |
|---|
| 238 | + size_t i; |
|---|
| 268 | 239 | |
|---|
| 269 | | - rk3328_analog_output(rk3328, 0); |
|---|
| 240 | + gpiod_set_value(rk3328->mute, 1); |
|---|
| 270 | 241 | |
|---|
| 271 | 242 | regmap_update_bits(rk3328->regmap, HPOUTL_GAIN_CTRL, |
|---|
| 272 | 243 | HPOUTL_GAIN_MASK, 0); |
|---|
| 273 | 244 | regmap_update_bits(rk3328->regmap, HPOUTR_GAIN_CTRL, |
|---|
| 274 | 245 | HPOUTR_GAIN_MASK, 0); |
|---|
| 275 | 246 | |
|---|
| 276 | | - for (i = 0; i < PLAYBACK_CLOSE_LIST_LEN; i++) { |
|---|
| 247 | + for (i = 0; i < ARRAY_SIZE(playback_close_list); i++) { |
|---|
| 277 | 248 | regmap_update_bits(rk3328->regmap, |
|---|
| 278 | 249 | playback_close_list[i].reg, |
|---|
| 279 | 250 | playback_close_list[i].msk, |
|---|
| .. | .. |
|---|
| 281 | 252 | mdelay(1); |
|---|
| 282 | 253 | } |
|---|
| 283 | 254 | |
|---|
| 255 | + /* Workaround for silence when changed Fs 48 -> 44.1kHz */ |
|---|
| 256 | + rk3328_codec_reset(rk3328); |
|---|
| 257 | + |
|---|
| 284 | 258 | regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, |
|---|
| 285 | 259 | DAC_CHARGE_CURRENT_ALL_MASK, |
|---|
| 286 | | - DAC_CHARGE_CURRENT_I); |
|---|
| 260 | + DAC_CHARGE_CURRENT_ALL_ON); |
|---|
| 261 | + |
|---|
| 287 | 262 | return 0; |
|---|
| 288 | 263 | } |
|---|
| 289 | 264 | |
|---|
| .. | .. |
|---|
| 291 | 266 | struct snd_pcm_hw_params *params, |
|---|
| 292 | 267 | struct snd_soc_dai *dai) |
|---|
| 293 | 268 | { |
|---|
| 294 | | - struct rk3328_codec_priv *rk3328 = snd_soc_component_get_drvdata(dai->component); |
|---|
| 269 | + struct rk3328_codec_priv *rk3328 = |
|---|
| 270 | + snd_soc_component_get_drvdata(dai->component); |
|---|
| 295 | 271 | unsigned int val = 0; |
|---|
| 296 | 272 | |
|---|
| 297 | 273 | switch (params_format(params)) { |
|---|
| 298 | 274 | case SNDRV_PCM_FORMAT_S16_LE: |
|---|
| 299 | | - val |= DAC_VDL_16BITS; |
|---|
| 275 | + val = DAC_VDL_16BITS; |
|---|
| 300 | 276 | break; |
|---|
| 301 | 277 | case SNDRV_PCM_FORMAT_S20_3LE: |
|---|
| 302 | | - val |= DAC_VDL_20BITS; |
|---|
| 278 | + val = DAC_VDL_20BITS; |
|---|
| 303 | 279 | break; |
|---|
| 304 | 280 | case SNDRV_PCM_FORMAT_S24_LE: |
|---|
| 305 | | - val |= DAC_VDL_24BITS; |
|---|
| 281 | + val = DAC_VDL_24BITS; |
|---|
| 306 | 282 | break; |
|---|
| 307 | 283 | case SNDRV_PCM_FORMAT_S32_LE: |
|---|
| 308 | | - val |= DAC_VDL_32BITS; |
|---|
| 284 | + val = DAC_VDL_32BITS; |
|---|
| 309 | 285 | break; |
|---|
| 310 | 286 | default: |
|---|
| 311 | 287 | return -EINVAL; |
|---|
| 312 | 288 | } |
|---|
| 313 | | - |
|---|
| 314 | 289 | regmap_update_bits(rk3328->regmap, DAC_INIT_CTRL2, DAC_VDL_MASK, val); |
|---|
| 290 | + |
|---|
| 315 | 291 | val = DAC_WL_32BITS | DAC_RST_DIS; |
|---|
| 316 | 292 | regmap_update_bits(rk3328->regmap, DAC_INIT_CTRL3, |
|---|
| 317 | 293 | DAC_WL_MASK | DAC_RST_MASK, val); |
|---|
| .. | .. |
|---|
| 322 | 298 | static int rk3328_pcm_startup(struct snd_pcm_substream *substream, |
|---|
| 323 | 299 | struct snd_soc_dai *dai) |
|---|
| 324 | 300 | { |
|---|
| 325 | | - return rk3328_codec_open_playback(dai->component); |
|---|
| 301 | + struct rk3328_codec_priv *rk3328 = |
|---|
| 302 | + snd_soc_component_get_drvdata(dai->component); |
|---|
| 303 | + |
|---|
| 304 | + return rk3328_codec_open_playback(rk3328); |
|---|
| 326 | 305 | } |
|---|
| 327 | 306 | |
|---|
| 328 | 307 | static void rk3328_pcm_shutdown(struct snd_pcm_substream *substream, |
|---|
| 329 | 308 | struct snd_soc_dai *dai) |
|---|
| 330 | 309 | { |
|---|
| 331 | | - rk3328_codec_close_playback(dai->component); |
|---|
| 310 | + struct rk3328_codec_priv *rk3328 = |
|---|
| 311 | + snd_soc_component_get_drvdata(dai->component); |
|---|
| 312 | + |
|---|
| 313 | + rk3328_codec_close_playback(rk3328); |
|---|
| 332 | 314 | } |
|---|
| 333 | 315 | |
|---|
| 334 | 316 | static const struct snd_soc_dai_ops rk3328_dai_ops = { |
|---|
| 335 | 317 | .hw_params = rk3328_hw_params, |
|---|
| 336 | 318 | .set_fmt = rk3328_set_dai_fmt, |
|---|
| 337 | | - .digital_mute = rk3328_digital_mute, |
|---|
| 319 | + .mute_stream = rk3328_mute_stream, |
|---|
| 338 | 320 | .startup = rk3328_pcm_startup, |
|---|
| 339 | 321 | .shutdown = rk3328_pcm_shutdown, |
|---|
| 322 | + .no_capture_mute = 1, |
|---|
| 340 | 323 | }; |
|---|
| 341 | 324 | |
|---|
| 342 | 325 | static struct snd_soc_dai_driver rk3328_dai[] = { |
|---|
| .. | .. |
|---|
| 369 | 352 | |
|---|
| 370 | 353 | static int rk3328_codec_probe(struct snd_soc_component *component) |
|---|
| 371 | 354 | { |
|---|
| 372 | | - rk3328_codec_reset(component); |
|---|
| 373 | | - rk3328_codec_power_on(component, 0); |
|---|
| 355 | + struct rk3328_codec_priv *rk3328 = |
|---|
| 356 | + snd_soc_component_get_drvdata(component); |
|---|
| 357 | + |
|---|
| 358 | + rk3328_codec_reset(rk3328); |
|---|
| 359 | + rk3328_codec_power_on(rk3328, 0); |
|---|
| 374 | 360 | |
|---|
| 375 | 361 | return 0; |
|---|
| 376 | 362 | } |
|---|
| 377 | 363 | |
|---|
| 378 | 364 | static void rk3328_codec_remove(struct snd_soc_component *component) |
|---|
| 379 | 365 | { |
|---|
| 380 | | - rk3328_codec_close_playback(component); |
|---|
| 381 | | - rk3328_codec_power_off(component, 0); |
|---|
| 366 | + struct rk3328_codec_priv *rk3328 = |
|---|
| 367 | + snd_soc_component_get_drvdata(component); |
|---|
| 368 | + |
|---|
| 369 | + rk3328_codec_close_playback(rk3328); |
|---|
| 370 | + rk3328_codec_power_off(rk3328, 0); |
|---|
| 382 | 371 | } |
|---|
| 383 | 372 | |
|---|
| 384 | | -static const struct snd_soc_component_driver soc_codec_dev_rk3328 = { |
|---|
| 373 | +static const struct snd_soc_component_driver soc_codec_rk3328 = { |
|---|
| 385 | 374 | .probe = rk3328_codec_probe, |
|---|
| 386 | 375 | .remove = rk3328_codec_remove, |
|---|
| 387 | 376 | }; |
|---|
| .. | .. |
|---|
| 431 | 420 | .cache_type = REGCACHE_FLAT, |
|---|
| 432 | 421 | }; |
|---|
| 433 | 422 | |
|---|
| 434 | | -#ifdef CONFIG_OF |
|---|
| 435 | | -static const struct of_device_id rk3328codec_of_match[] = { |
|---|
| 436 | | - { .compatible = "rockchip,rk3328-codec", }, |
|---|
| 437 | | - {}, |
|---|
| 438 | | -}; |
|---|
| 439 | | -MODULE_DEVICE_TABLE(of, rk3328codec_of_match); |
|---|
| 440 | | -#endif |
|---|
| 441 | | - |
|---|
| 442 | 423 | static int rk3328_platform_probe(struct platform_device *pdev) |
|---|
| 443 | 424 | { |
|---|
| 444 | 425 | struct device_node *rk3328_np = pdev->dev.of_node; |
|---|
| 445 | 426 | struct rk3328_codec_priv *rk3328; |
|---|
| 446 | | - struct resource *res; |
|---|
| 447 | 427 | struct regmap *grf; |
|---|
| 448 | 428 | void __iomem *base; |
|---|
| 449 | 429 | int ret = 0; |
|---|
| .. | .. |
|---|
| 458 | 438 | dev_err(&pdev->dev, "missing 'rockchip,grf'\n"); |
|---|
| 459 | 439 | return PTR_ERR(grf); |
|---|
| 460 | 440 | } |
|---|
| 461 | | - rk3328->grf = grf; |
|---|
| 462 | 441 | /* enable i2s_acodec_en */ |
|---|
| 463 | 442 | regmap_write(grf, RK3328_GRF_SOC_CON2, |
|---|
| 464 | 443 | (BIT(14) << 16 | BIT(14))); |
|---|
| .. | .. |
|---|
| 467 | 446 | &rk3328->spk_depop_time); |
|---|
| 468 | 447 | if (ret < 0) { |
|---|
| 469 | 448 | dev_info(&pdev->dev, "spk_depop_time use default value.\n"); |
|---|
| 470 | | - rk3328->spk_depop_time = 100; |
|---|
| 449 | + rk3328->spk_depop_time = 200; |
|---|
| 471 | 450 | } |
|---|
| 472 | 451 | |
|---|
| 473 | | - rk3328_analog_output(rk3328, 0); |
|---|
| 452 | + rk3328->mute = gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_HIGH); |
|---|
| 453 | + if (IS_ERR(rk3328->mute)) |
|---|
| 454 | + return PTR_ERR(rk3328->mute); |
|---|
| 455 | + /* |
|---|
| 456 | + * Rock64 is the only supported platform to have widely relied on |
|---|
| 457 | + * this; if we do happen to come across an old DTB, just leave the |
|---|
| 458 | + * external mute forced off. |
|---|
| 459 | + */ |
|---|
| 460 | + if (!rk3328->mute && of_machine_is_compatible("pine64,rock64")) { |
|---|
| 461 | + dev_warn(&pdev->dev, "assuming implicit control of GPIO_MUTE; update devicetree if possible\n"); |
|---|
| 462 | + regmap_write(grf, RK3328_GRF_SOC_CON10, BIT(17) | BIT(1)); |
|---|
| 463 | + } |
|---|
| 474 | 464 | |
|---|
| 475 | 465 | rk3328->mclk = devm_clk_get(&pdev->dev, "mclk"); |
|---|
| 476 | 466 | if (IS_ERR(rk3328->mclk)) |
|---|
| .. | .. |
|---|
| 484 | 474 | rk3328->pclk = devm_clk_get(&pdev->dev, "pclk"); |
|---|
| 485 | 475 | if (IS_ERR(rk3328->pclk)) { |
|---|
| 486 | 476 | dev_err(&pdev->dev, "can't get acodec pclk\n"); |
|---|
| 487 | | - return PTR_ERR(rk3328->pclk); |
|---|
| 477 | + ret = PTR_ERR(rk3328->pclk); |
|---|
| 478 | + goto err_unprepare_mclk; |
|---|
| 488 | 479 | } |
|---|
| 489 | 480 | |
|---|
| 490 | 481 | ret = clk_prepare_enable(rk3328->pclk); |
|---|
| 491 | 482 | if (ret < 0) { |
|---|
| 492 | 483 | dev_err(&pdev->dev, "failed to enable acodec pclk\n"); |
|---|
| 493 | | - return ret; |
|---|
| 484 | + goto err_unprepare_mclk; |
|---|
| 494 | 485 | } |
|---|
| 495 | 486 | |
|---|
| 496 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 497 | | - base = devm_ioremap_resource(&pdev->dev, res); |
|---|
| 498 | | - if (IS_ERR(base)) |
|---|
| 499 | | - return PTR_ERR(base); |
|---|
| 487 | + base = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 488 | + if (IS_ERR(base)) { |
|---|
| 489 | + ret = PTR_ERR(base); |
|---|
| 490 | + goto err_unprepare_pclk; |
|---|
| 491 | + } |
|---|
| 500 | 492 | |
|---|
| 501 | 493 | rk3328->regmap = devm_regmap_init_mmio(&pdev->dev, base, |
|---|
| 502 | 494 | &rk3328_codec_regmap_config); |
|---|
| 503 | | - if (IS_ERR(rk3328->regmap)) |
|---|
| 504 | | - return PTR_ERR(rk3328->regmap); |
|---|
| 495 | + if (IS_ERR(rk3328->regmap)) { |
|---|
| 496 | + ret = PTR_ERR(rk3328->regmap); |
|---|
| 497 | + goto err_unprepare_pclk; |
|---|
| 498 | + } |
|---|
| 505 | 499 | |
|---|
| 506 | 500 | platform_set_drvdata(pdev, rk3328); |
|---|
| 507 | 501 | |
|---|
| 508 | | - return devm_snd_soc_register_component(&pdev->dev, &soc_codec_dev_rk3328, |
|---|
| 509 | | - rk3328_dai, ARRAY_SIZE(rk3328_dai)); |
|---|
| 502 | + ret = devm_snd_soc_register_component(&pdev->dev, &soc_codec_rk3328, |
|---|
| 503 | + rk3328_dai, |
|---|
| 504 | + ARRAY_SIZE(rk3328_dai)); |
|---|
| 505 | + if (ret) |
|---|
| 506 | + goto err_unprepare_pclk; |
|---|
| 507 | + |
|---|
| 508 | + return 0; |
|---|
| 509 | + |
|---|
| 510 | +err_unprepare_pclk: |
|---|
| 511 | + clk_disable_unprepare(rk3328->pclk); |
|---|
| 512 | + |
|---|
| 513 | +err_unprepare_mclk: |
|---|
| 514 | + clk_disable_unprepare(rk3328->mclk); |
|---|
| 515 | + return ret; |
|---|
| 510 | 516 | } |
|---|
| 517 | + |
|---|
| 518 | +static const struct of_device_id rk3328_codec_of_match[] = { |
|---|
| 519 | + { .compatible = "rockchip,rk3328-codec", }, |
|---|
| 520 | + {}, |
|---|
| 521 | +}; |
|---|
| 522 | +MODULE_DEVICE_TABLE(of, rk3328_codec_of_match); |
|---|
| 511 | 523 | |
|---|
| 512 | 524 | static struct platform_driver rk3328_codec_driver = { |
|---|
| 513 | 525 | .driver = { |
|---|
| 514 | 526 | .name = "rk3328-codec", |
|---|
| 515 | | - .of_match_table = of_match_ptr(rk3328codec_of_match), |
|---|
| 527 | + .of_match_table = of_match_ptr(rk3328_codec_of_match), |
|---|
| 516 | 528 | }, |
|---|
| 517 | 529 | .probe = rk3328_platform_probe, |
|---|
| 518 | 530 | }; |
|---|