blob: 473f8d8f9771a89ee84fc4755fbbda102c91adb6 [file] [log] [blame]
Simon Glass5b6e44e2019-02-16 20:25:06 -07001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Sound for broadwell
4 *
5 * Copyright 2019 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#define LOG_CATEGORY UCLASS_SOUND
10
Simon Glass5b6e44e2019-02-16 20:25:06 -070011#include <audio_codec.h>
12#include <dm.h>
13#include <i2s.h>
14#include <sound.h>
15
16static int broadwell_sound_probe(struct udevice *dev)
17{
18 return sound_find_codec_i2s(dev);
19}
20
21static int broadwell_sound_setup(struct udevice *dev)
22{
23 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
24 struct i2s_uc_priv *i2c_priv = dev_get_uclass_priv(uc_priv->i2s);
25 int ret;
26
27 if (uc_priv->setup_done)
28 return -EALREADY;
29 ret = audio_codec_set_params(uc_priv->codec, i2c_priv->id,
30 i2c_priv->samplingrate,
31 i2c_priv->samplingrate * i2c_priv->rfs,
32 i2c_priv->bitspersample,
33 i2c_priv->channels);
34 if (ret)
35 return ret;
36 uc_priv->setup_done = true;
37
38 return 0;
39}
40
41static int broadwell_sound_play(struct udevice *dev, void *data, uint data_size)
42{
43 struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
44
45 return i2s_tx_data(uc_priv->i2s, data, data_size);
46}
47
48static const struct sound_ops broadwell_sound_ops = {
49 .setup = broadwell_sound_setup,
50 .play = broadwell_sound_play,
51};
52
53static const struct udevice_id broadwell_sound_ids[] = {
54 { .compatible = "google,samus-sound" },
55 { }
56};
57
58U_BOOT_DRIVER(broadwell_sound_drv) = {
59 .name = "broadwell_sound",
60 .id = UCLASS_SOUND,
61 .of_match = broadwell_sound_ids,
62 .probe = broadwell_sound_probe,
63 .ops = &broadwell_sound_ops,
64};