1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2018 Google, LLC
4 * Written by Simon Glass <sjg@chromium.org>
7 #define LOG_CATEGORY UCLASS_SOUND
10 #include <audio_codec.h>
17 #include <asm/arch-rockchip/periph.h>
18 #include <dm/pinctrl.h>
20 static int rockchip_sound_setup(struct udevice *dev)
22 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
23 struct i2s_uc_priv *i2c_priv = dev_get_uclass_priv(uc_priv->i2s);
26 if (uc_priv->setup_done)
28 ret = audio_codec_set_params(uc_priv->codec, i2c_priv->id,
29 i2c_priv->samplingrate,
30 i2c_priv->samplingrate * i2c_priv->rfs,
31 i2c_priv->bitspersample,
35 uc_priv->setup_done = true;
40 static int rockchip_sound_play(struct udevice *dev, void *data, uint data_size)
42 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
44 return i2s_tx_data(uc_priv->i2s, data, data_size);
47 static int rockchip_sound_probe(struct udevice *dev)
49 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
50 struct ofnode_phandle_args args;
51 struct udevice *pinctrl;
56 node = ofnode_find_subnode(dev_ofnode(dev), "cpu");
57 if (!ofnode_valid(node)) {
58 log_debug("Failed to find /cpu subnode\n");
61 ret = ofnode_parse_phandle_with_args(node, "sound-dai",
62 "#sound-dai-cells", 0, 0, &args);
64 log_debug("Cannot find i2s phandle: %d\n", ret);
67 ret = uclass_get_device_by_ofnode(UCLASS_I2S, args.node, &uc_priv->i2s);
69 log_debug("Cannot find i2s: %d\n", ret);
73 node = ofnode_find_subnode(dev_ofnode(dev), "codec");
74 if (!ofnode_valid(node)) {
75 log_debug("Failed to find /codec subnode\n");
78 ret = ofnode_parse_phandle_with_args(node, "sound-dai",
79 "#sound-dai-cells", 0, 0, &args);
81 log_debug("Cannot find codec phandle: %d\n", ret);
84 ret = uclass_get_device_by_ofnode(UCLASS_AUDIO_CODEC, args.node,
87 log_debug("Cannot find audio codec: %d\n", ret);
90 ret = clk_get_by_index(uc_priv->i2s, 1, &clk);
92 log_debug("Cannot find clock: %d\n", ret);
95 ret = clk_set_rate(&clk, 12288000);
97 log_debug("Cannot find clock: %d\n", ret);
100 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
102 debug("%s: Cannot find pinctrl device\n", __func__);
105 ret = pinctrl_request(pinctrl, PERIPH_ID_I2S, 0);
107 debug("%s: Cannot select I2C pinctrl\n", __func__);
111 log_debug("Probed sound '%s' with codec '%s' and i2s '%s'\n", dev->name,
112 uc_priv->codec->name, uc_priv->i2s->name);
117 static const struct sound_ops rockchip_sound_ops = {
118 .setup = rockchip_sound_setup,
119 .play = rockchip_sound_play,
122 static const struct udevice_id rockchip_sound_ids[] = {
123 { .compatible = "rockchip,audio-max98090-jerry" },
127 U_BOOT_DRIVER(rockchip_sound) = {
128 .name = "rockchip_sound",
130 .of_match = rockchip_sound_ids,
131 .probe = rockchip_sound_probe,
132 .ops = &rockchip_sound_ops,