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_I2S
10 #include <audio_codec.h>
16 #include "tegra_i2s_priv.h"
18 static int tegra_sound_setup(struct udevice *dev)
20 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
21 struct i2s_uc_priv *i2c_priv = dev_get_uclass_priv(uc_priv->i2s);
24 if (uc_priv->setup_done)
26 ret = audio_codec_set_params(uc_priv->codec, i2c_priv->id,
27 i2c_priv->samplingrate,
28 i2c_priv->samplingrate * i2c_priv->rfs,
29 i2c_priv->bitspersample,
33 uc_priv->setup_done = true;
38 static int tegra_sound_play(struct udevice *dev, void *data, uint data_size)
40 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
42 return i2s_tx_data(uc_priv->i2s, data, data_size);
45 static int tegra_sound_probe(struct udevice *dev)
47 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
48 struct gpio_desc en_gpio;
52 ret = gpio_request_by_name(dev, "codec-enable-gpio", 0, &en_gpio,
53 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
55 ret = uclass_get_device_by_phandle(UCLASS_AUDIO_CODEC, dev,
59 log_debug("Failed to probe audio codec\n");
62 ret = uclass_get_device_by_phandle(UCLASS_I2S, dev,
63 "nvidia,i2s-controller",
66 log_debug("Cannot find i2s: %d\n", ret);
70 /* Set up the audio hub, telling it the currect i2s to use */
71 ahub = dev_get_parent(uc_priv->i2s);
72 ret = misc_ioctl(ahub, AHUB_MISCOP_SET_I2S, &uc_priv->i2s);
74 log_debug("Cannot set i2c: %d\n", ret);
78 log_debug("Probed sound '%s' with codec '%s' and i2s '%s'\n", dev->name,
79 uc_priv->codec->name, uc_priv->i2s->name);
84 static const struct sound_ops tegra_sound_ops = {
85 .setup = tegra_sound_setup,
86 .play = tegra_sound_play,
89 static const struct udevice_id tegra_sound_ids[] = {
90 { .compatible = "nvidia,tegra-audio-max98090-nyan-big" },
94 U_BOOT_DRIVER(tegra_sound) = {
95 .name = "tegra_sound",
97 .of_match = tegra_sound_ids,
98 .probe = tegra_sound_probe,
99 .ops = &tegra_sound_ops,