1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013 Google, Inc
7 #include <audio_codec.h>
10 #include <asm/sound.h>
13 struct sandbox_codec_priv {
21 struct sandbox_i2s_priv {
22 int sum; /* Use to sum the provided audio data */
25 int sound_play(uint32_t msec, uint32_t frequency)
27 sandbox_sdl_sound_start(frequency);
29 sandbox_sdl_sound_stop();
34 int sound_init(const void *blob)
36 return sandbox_sdl_sound_init();
39 void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep,
40 int *mclk_freqp, int *bits_per_samplep,
43 struct sandbox_codec_priv *priv = dev_get_priv(dev);
45 *interfacep = priv->interface;
47 *mclk_freqp = priv->mclk_freq;
48 *bits_per_samplep = priv->bits_per_sample;
49 *channelsp = priv->channels;
52 int sandbox_get_i2s_sum(struct udevice *dev)
54 struct sandbox_i2s_priv *priv = dev_get_priv(dev);
59 static int sandbox_codec_set_params(struct udevice *dev, int interface,
60 int rate, int mclk_freq,
61 int bits_per_sample, uint channels)
63 struct sandbox_codec_priv *priv = dev_get_priv(dev);
65 priv->interface = interface;
67 priv->mclk_freq = mclk_freq;
68 priv->bits_per_sample = bits_per_sample;
69 priv->channels = channels;
74 static int sandbox_i2s_tx_data(struct udevice *dev, void *data,
77 struct sandbox_i2s_priv *priv = dev_get_priv(dev);
80 for (i = 0; i < data_size; i++)
81 priv->sum += ((uint8_t *)data)[i];
86 static int sandbox_i2s_probe(struct udevice *dev)
88 struct i2s_uc_priv *uc_priv = dev_get_uclass_priv(dev);
90 /* Use hard-coded values here */
93 uc_priv->audio_pll_clk = 192000000;
94 uc_priv->samplingrate = 48000;
95 uc_priv->bitspersample = 16;
96 uc_priv->channels = 2;
102 static const struct audio_codec_ops sandbox_codec_ops = {
103 .set_params = sandbox_codec_set_params,
106 static const struct udevice_id sandbox_codec_ids[] = {
107 { .compatible = "sandbox,audio-codec" },
111 U_BOOT_DRIVER(sandbox_codec) = {
112 .name = "sandbox_codec",
113 .id = UCLASS_AUDIO_CODEC,
114 .of_match = sandbox_codec_ids,
115 .ops = &sandbox_codec_ops,
116 .priv_auto_alloc_size = sizeof(struct sandbox_codec_priv),
119 static const struct i2s_ops sandbox_i2s_ops = {
120 .tx_data = sandbox_i2s_tx_data,
123 static const struct udevice_id sandbox_i2s_ids[] = {
124 { .compatible = "sandbox,i2s" },
128 U_BOOT_DRIVER(sandbox_i2s) = {
129 .name = "sandbox_i2s",
131 .of_match = sandbox_i2s_ids,
132 .ops = &sandbox_i2s_ops,
133 .probe = sandbox_i2s_probe,
134 .priv_auto_alloc_size = sizeof(struct sandbox_i2s_priv),