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>
16 #include <asm/arch-rockchip/periph.h>
17 #include <dm/pinctrl.h>
19 static int rockchip_sound_setup(struct udevice *dev)
21 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
22 struct i2s_uc_priv *i2c_priv = dev_get_uclass_priv(uc_priv->i2s);
25 if (uc_priv->setup_done)
27 ret = audio_codec_set_params(uc_priv->codec, i2c_priv->id,
28 i2c_priv->samplingrate,
29 i2c_priv->samplingrate * i2c_priv->rfs,
30 i2c_priv->bitspersample,
34 uc_priv->setup_done = true;
39 static int rockchip_sound_play(struct udevice *dev, void *data, uint data_size)
41 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
43 return i2s_tx_data(uc_priv->i2s, data, data_size);
46 static int rockchip_sound_probe(struct udevice *dev)
48 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
49 struct ofnode_phandle_args args;
50 struct udevice *pinctrl;
55 node = ofnode_find_subnode(dev_ofnode(dev), "cpu");
56 if (!ofnode_valid(node)) {
57 log_debug("Failed to find /cpu subnode\n");
60 ret = ofnode_parse_phandle_with_args(node, "sound-dai",
61 "#sound-dai-cells", 0, 0, &args);
63 log_debug("Cannot find i2s phandle: %d\n", ret);
66 ret = uclass_get_device_by_ofnode(UCLASS_I2S, args.node, &uc_priv->i2s);
68 log_debug("Cannot find i2s: %d\n", ret);
72 node = ofnode_find_subnode(dev_ofnode(dev), "codec");
73 if (!ofnode_valid(node)) {
74 log_debug("Failed to find /codec subnode\n");
77 ret = ofnode_parse_phandle_with_args(node, "sound-dai",
78 "#sound-dai-cells", 0, 0, &args);
80 log_debug("Cannot find codec phandle: %d\n", ret);
83 ret = uclass_get_device_by_ofnode(UCLASS_AUDIO_CODEC, args.node,
86 log_debug("Cannot find audio codec: %d\n", ret);
89 ret = clk_get_by_index(uc_priv->i2s, 1, &clk);
91 log_debug("Cannot find clock: %d\n", ret);
94 ret = clk_set_rate(&clk, 12288000);
96 log_debug("Cannot find clock: %d\n", ret);
99 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl);
101 debug("%s: Cannot find pinctrl device\n", __func__);
104 ret = pinctrl_request(pinctrl, PERIPH_ID_I2S, 0);
106 debug("%s: Cannot select I2C pinctrl\n", __func__);
110 log_debug("Probed sound '%s' with codec '%s' and i2s '%s'\n", dev->name,
111 uc_priv->codec->name, uc_priv->i2s->name);
116 static const struct sound_ops rockchip_sound_ops = {
117 .setup = rockchip_sound_setup,
118 .play = rockchip_sound_play,
121 static const struct udevice_id rockchip_sound_ids[] = {
122 { .compatible = "rockchip,audio-max98090-jerry" },
126 U_BOOT_DRIVER(rockchip_sound) = {
127 .name = "rockchip_sound",
129 .of_match = rockchip_sound_ids,
130 .probe = rockchip_sound_probe,
131 .ops = &rockchip_sound_ops,