tegra_sound.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2018 Google, LLC
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #define LOG_CATEGORY UCLASS_I2S
  7. #include <common.h>
  8. #include <audio_codec.h>
  9. #include <dm.h>
  10. #include <i2s.h>
  11. #include <log.h>
  12. #include <misc.h>
  13. #include <sound.h>
  14. #include <asm/gpio.h>
  15. #include "tegra_i2s_priv.h"
  16. static int tegra_sound_setup(struct udevice *dev)
  17. {
  18. struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
  19. struct i2s_uc_priv *i2c_priv = dev_get_uclass_priv(uc_priv->i2s);
  20. int ret;
  21. if (uc_priv->setup_done)
  22. return -EALREADY;
  23. ret = audio_codec_set_params(uc_priv->codec, i2c_priv->id,
  24. i2c_priv->samplingrate,
  25. i2c_priv->samplingrate * i2c_priv->rfs,
  26. i2c_priv->bitspersample,
  27. i2c_priv->channels);
  28. if (ret)
  29. return ret;
  30. uc_priv->setup_done = true;
  31. return 0;
  32. }
  33. static int tegra_sound_play(struct udevice *dev, void *data, uint data_size)
  34. {
  35. struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
  36. return i2s_tx_data(uc_priv->i2s, data, data_size);
  37. }
  38. static int tegra_sound_probe(struct udevice *dev)
  39. {
  40. struct sound_uc_priv *uc_priv = dev_get_uclass_priv(dev);
  41. struct gpio_desc en_gpio;
  42. struct udevice *ahub;
  43. int ret;
  44. ret = gpio_request_by_name(dev, "codec-enable-gpio", 0, &en_gpio,
  45. GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
  46. ret = uclass_get_device_by_phandle(UCLASS_AUDIO_CODEC, dev,
  47. "nvidia,audio-codec",
  48. &uc_priv->codec);
  49. if (ret) {
  50. log_debug("Failed to probe audio codec\n");
  51. return ret;
  52. }
  53. ret = uclass_get_device_by_phandle(UCLASS_I2S, dev,
  54. "nvidia,i2s-controller",
  55. &uc_priv->i2s);
  56. if (ret) {
  57. log_debug("Cannot find i2s: %d\n", ret);
  58. return ret;
  59. }
  60. /* Set up the audio hub, telling it the currect i2s to use */
  61. ahub = dev_get_parent(uc_priv->i2s);
  62. ret = misc_ioctl(ahub, AHUB_MISCOP_SET_I2S, &uc_priv->i2s);
  63. if (ret) {
  64. log_debug("Cannot set i2c: %d\n", ret);
  65. return ret;
  66. }
  67. log_debug("Probed sound '%s' with codec '%s' and i2s '%s'\n", dev->name,
  68. uc_priv->codec->name, uc_priv->i2s->name);
  69. return 0;
  70. }
  71. static const struct sound_ops tegra_sound_ops = {
  72. .setup = tegra_sound_setup,
  73. .play = tegra_sound_play,
  74. };
  75. static const struct udevice_id tegra_sound_ids[] = {
  76. { .compatible = "nvidia,tegra-audio-max98090-nyan-big" },
  77. { }
  78. };
  79. U_BOOT_DRIVER(tegra_sound) = {
  80. .name = "tegra_sound",
  81. .id = UCLASS_SOUND,
  82. .of_match = tegra_sound_ids,
  83. .probe = tegra_sound_probe,
  84. .ops = &tegra_sound_ops,
  85. };