Lines Matching +full:rk3328 +full:- +full:grf +full:- +full:gpio
1 // SPDX-License-Identifier: GPL-2.0
3 // rk3328 ALSA SoC Audio driver
10 #include <linux/gpio/consumer.h>
22 * 0: -39dB
56 static int rk3328_codec_reset(struct rk3328_codec_priv *rk3328) in rk3328_codec_reset() argument
58 regmap_write(rk3328->regmap, CODEC_RESET, 0x00); in rk3328_codec_reset()
60 regmap_write(rk3328->regmap, CODEC_RESET, 0x03); in rk3328_codec_reset()
67 struct rk3328_codec_priv *rk3328 = in rk3328_set_dai_fmt() local
68 snd_soc_component_get_drvdata(dai->component); in rk3328_set_dai_fmt()
79 return -EINVAL; in rk3328_set_dai_fmt()
82 regmap_update_bits(rk3328->regmap, DAC_INIT_CTRL1, in rk3328_set_dai_fmt()
100 return -EINVAL; in rk3328_set_dai_fmt()
103 regmap_update_bits(rk3328->regmap, DAC_INIT_CTRL2, in rk3328_set_dai_fmt()
111 struct rk3328_codec_priv *rk3328 = in rk3328_mute_stream() local
112 snd_soc_component_get_drvdata(dai->component); in rk3328_mute_stream()
120 regmap_update_bits(rk3328->regmap, HPOUT_CTRL, in rk3328_mute_stream()
126 static int rk3328_codec_power_on(struct rk3328_codec_priv *rk3328, int wait_ms) in rk3328_codec_power_on() argument
128 regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, in rk3328_codec_power_on()
131 regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, in rk3328_codec_power_on()
139 static int rk3328_codec_power_off(struct rk3328_codec_priv *rk3328, int wait_ms) in rk3328_codec_power_off() argument
141 regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, in rk3328_codec_power_off()
144 regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, in rk3328_codec_power_off()
181 static int rk3328_codec_open_playback(struct rk3328_codec_priv *rk3328) in rk3328_codec_open_playback() argument
185 regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, in rk3328_codec_open_playback()
190 regmap_update_bits(rk3328->regmap, in rk3328_codec_open_playback()
197 msleep(rk3328->spk_depop_time); in rk3328_codec_open_playback()
198 gpiod_set_value(rk3328->mute, 0); in rk3328_codec_open_playback()
200 regmap_update_bits(rk3328->regmap, HPOUTL_GAIN_CTRL, in rk3328_codec_open_playback()
202 regmap_update_bits(rk3328->regmap, HPOUTR_GAIN_CTRL, in rk3328_codec_open_playback()
235 static int rk3328_codec_close_playback(struct rk3328_codec_priv *rk3328) in rk3328_codec_close_playback() argument
239 gpiod_set_value(rk3328->mute, 1); in rk3328_codec_close_playback()
241 regmap_update_bits(rk3328->regmap, HPOUTL_GAIN_CTRL, in rk3328_codec_close_playback()
243 regmap_update_bits(rk3328->regmap, HPOUTR_GAIN_CTRL, in rk3328_codec_close_playback()
247 regmap_update_bits(rk3328->regmap, in rk3328_codec_close_playback()
254 /* Workaround for silence when changed Fs 48 -> 44.1kHz */ in rk3328_codec_close_playback()
255 rk3328_codec_reset(rk3328); in rk3328_codec_close_playback()
257 regmap_update_bits(rk3328->regmap, DAC_PRECHARGE_CTRL, in rk3328_codec_close_playback()
268 struct rk3328_codec_priv *rk3328 = in rk3328_hw_params() local
269 snd_soc_component_get_drvdata(dai->component); in rk3328_hw_params()
286 return -EINVAL; in rk3328_hw_params()
288 regmap_update_bits(rk3328->regmap, DAC_INIT_CTRL2, DAC_VDL_MASK, val); in rk3328_hw_params()
291 regmap_update_bits(rk3328->regmap, DAC_INIT_CTRL3, in rk3328_hw_params()
300 struct rk3328_codec_priv *rk3328 = in rk3328_pcm_startup() local
301 snd_soc_component_get_drvdata(dai->component); in rk3328_pcm_startup()
303 return rk3328_codec_open_playback(rk3328); in rk3328_pcm_startup()
309 struct rk3328_codec_priv *rk3328 = in rk3328_pcm_shutdown() local
310 snd_soc_component_get_drvdata(dai->component); in rk3328_pcm_shutdown()
312 rk3328_codec_close_playback(rk3328); in rk3328_pcm_shutdown()
326 .name = "rk3328-hifi",
354 struct rk3328_codec_priv *rk3328 = in rk3328_codec_probe() local
357 rk3328_codec_reset(rk3328); in rk3328_codec_probe()
358 rk3328_codec_power_on(rk3328, 0); in rk3328_codec_probe()
365 struct rk3328_codec_priv *rk3328 = in rk3328_codec_remove() local
368 rk3328_codec_close_playback(rk3328); in rk3328_codec_remove()
369 rk3328_codec_power_off(rk3328, 0); in rk3328_codec_remove()
424 struct device_node *rk3328_np = pdev->dev.of_node; in rk3328_platform_probe()
425 struct rk3328_codec_priv *rk3328; in rk3328_platform_probe() local
426 struct regmap *grf; in rk3328_platform_probe() local
430 rk3328 = devm_kzalloc(&pdev->dev, sizeof(*rk3328), GFP_KERNEL); in rk3328_platform_probe()
431 if (!rk3328) in rk3328_platform_probe()
432 return -ENOMEM; in rk3328_platform_probe()
434 grf = syscon_regmap_lookup_by_phandle(rk3328_np, in rk3328_platform_probe()
435 "rockchip,grf"); in rk3328_platform_probe()
436 if (IS_ERR(grf)) { in rk3328_platform_probe()
437 dev_err(&pdev->dev, "missing 'rockchip,grf'\n"); in rk3328_platform_probe()
438 return PTR_ERR(grf); in rk3328_platform_probe()
441 regmap_write(grf, RK3328_GRF_SOC_CON2, in rk3328_platform_probe()
444 ret = of_property_read_u32(rk3328_np, "spk-depop-time-ms", in rk3328_platform_probe()
445 &rk3328->spk_depop_time); in rk3328_platform_probe()
447 dev_info(&pdev->dev, "spk_depop_time use default value.\n"); in rk3328_platform_probe()
448 rk3328->spk_depop_time = 200; in rk3328_platform_probe()
451 rk3328->mute = gpiod_get_optional(&pdev->dev, "mute", GPIOD_OUT_HIGH); in rk3328_platform_probe()
452 if (IS_ERR(rk3328->mute)) in rk3328_platform_probe()
453 return PTR_ERR(rk3328->mute); in rk3328_platform_probe()
459 if (!rk3328->mute && of_machine_is_compatible("pine64,rock64")) { in rk3328_platform_probe()
460 dev_warn(&pdev->dev, "assuming implicit control of GPIO_MUTE; update devicetree if possible\n"); in rk3328_platform_probe()
461 regmap_write(grf, RK3328_GRF_SOC_CON10, BIT(17) | BIT(1)); in rk3328_platform_probe()
464 rk3328->mclk = devm_clk_get(&pdev->dev, "mclk"); in rk3328_platform_probe()
465 if (IS_ERR(rk3328->mclk)) in rk3328_platform_probe()
466 return PTR_ERR(rk3328->mclk); in rk3328_platform_probe()
468 ret = clk_prepare_enable(rk3328->mclk); in rk3328_platform_probe()
471 clk_set_rate(rk3328->mclk, INITIAL_FREQ); in rk3328_platform_probe()
473 rk3328->pclk = devm_clk_get(&pdev->dev, "pclk"); in rk3328_platform_probe()
474 if (IS_ERR(rk3328->pclk)) { in rk3328_platform_probe()
475 dev_err(&pdev->dev, "can't get acodec pclk\n"); in rk3328_platform_probe()
476 ret = PTR_ERR(rk3328->pclk); in rk3328_platform_probe()
480 ret = clk_prepare_enable(rk3328->pclk); in rk3328_platform_probe()
482 dev_err(&pdev->dev, "failed to enable acodec pclk\n"); in rk3328_platform_probe()
492 rk3328->regmap = devm_regmap_init_mmio(&pdev->dev, base, in rk3328_platform_probe()
494 if (IS_ERR(rk3328->regmap)) { in rk3328_platform_probe()
495 ret = PTR_ERR(rk3328->regmap); in rk3328_platform_probe()
499 platform_set_drvdata(pdev, rk3328); in rk3328_platform_probe()
501 ret = devm_snd_soc_register_component(&pdev->dev, &soc_codec_rk3328, in rk3328_platform_probe()
510 clk_disable_unprepare(rk3328->pclk); in rk3328_platform_probe()
513 clk_disable_unprepare(rk3328->mclk); in rk3328_platform_probe()
518 { .compatible = "rockchip,rk3328-codec", },
525 .name = "rk3328-codec",
532 MODULE_AUTHOR("Sugar Zhang <sugar.zhang@rock-chips.com>");
533 MODULE_DESCRIPTION("ASoC rk3328 codec driver");