1 // 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 
11 #include <common.h>
12 #include <audio_codec.h>
13 #include <dm.h>
14 #include <i2s.h>
15 #include <sound.h>
16 
17 static int broadwell_sound_probe(struct udevice *dev)
18 {
19 	return sound_find_codec_i2s(dev);
20 }
21 
22 static int broadwell_sound_setup(struct udevice *dev)
23 {
24 	struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
25 	struct i2s_uc_priv *i2c_priv = dev_get_uclass_priv(uc_priv->i2s);
26 	int ret;
27 
28 	if (uc_priv->setup_done)
29 		return -EALREADY;
30 	ret = audio_codec_set_params(uc_priv->codec, i2c_priv->id,
31 				     i2c_priv->samplingrate,
32 				     i2c_priv->samplingrate * i2c_priv->rfs,
33 				     i2c_priv->bitspersample,
34 				     i2c_priv->channels);
35 	if (ret)
36 		return ret;
37 	uc_priv->setup_done = true;
38 
39 	return 0;
40 }
41 
42 static int broadwell_sound_play(struct udevice *dev, void *data, uint data_size)
43 {
44 	struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
45 
46 	return i2s_tx_data(uc_priv->i2s, data, data_size);
47 }
48 
49 static const struct sound_ops broadwell_sound_ops = {
50 	.setup		= broadwell_sound_setup,
51 	.play		= broadwell_sound_play,
52 };
53 
54 static const struct udevice_id broadwell_sound_ids[] = {
55 	{ .compatible = "google,samus-sound" },
56 	{ }
57 };
58 
59 U_BOOT_DRIVER(broadwell_sound_drv) = {
60 	.name		= "broadwell_sound",
61 	.id		= UCLASS_SOUND,
62 	.of_match	= broadwell_sound_ids,
63 	.probe		= broadwell_sound_probe,
64 	.ops		= &broadwell_sound_ops,
65 };
66