broadwell_sound.c 1.5 KB

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