sound.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2012 Samsung Electronics
  4. * Rajeshwari Shinde <rajeshwari.s@samsung.com>
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <dm.h>
  9. #include <fdtdec.h>
  10. #include <sound.h>
  11. #include <asm/global_data.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. /* Initilaise sound subsystem */
  14. static int do_init(struct cmd_tbl *cmdtp, int flag, int argc,
  15. char *const argv[])
  16. {
  17. struct udevice *dev;
  18. int ret;
  19. ret = uclass_first_device_err(UCLASS_SOUND, &dev);
  20. if (!ret)
  21. ret = sound_setup(dev);
  22. if (ret) {
  23. printf("Initialise Audio driver failed (ret=%d)\n", ret);
  24. return CMD_RET_FAILURE;
  25. }
  26. return 0;
  27. }
  28. /* play sound from buffer */
  29. static int do_play(struct cmd_tbl *cmdtp, int flag, int argc,
  30. char *const argv[])
  31. {
  32. struct udevice *dev;
  33. int ret = 0;
  34. int msec = 1000;
  35. int freq = 400;
  36. if (argc > 1)
  37. msec = dectoul(argv[1], NULL);
  38. if (argc > 2)
  39. freq = dectoul(argv[2], NULL);
  40. ret = uclass_first_device_err(UCLASS_SOUND, &dev);
  41. if (!ret)
  42. ret = sound_beep(dev, msec, freq);
  43. if (ret) {
  44. printf("Sound device failed to play (err=%d)\n", ret);
  45. return CMD_RET_FAILURE;
  46. }
  47. return 0;
  48. }
  49. static struct cmd_tbl cmd_sound_sub[] = {
  50. U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
  51. U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""),
  52. };
  53. /* process sound command */
  54. static int do_sound(struct cmd_tbl *cmdtp, int flag, int argc,
  55. char *const argv[])
  56. {
  57. struct cmd_tbl *c;
  58. if (argc < 1)
  59. return CMD_RET_USAGE;
  60. /* Strip off leading 'sound' command argument */
  61. argc--;
  62. argv++;
  63. c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub));
  64. if (c)
  65. return c->cmd(cmdtp, flag, argc, argv);
  66. else
  67. return CMD_RET_USAGE;
  68. }
  69. U_BOOT_CMD(
  70. sound, 4, 1, do_sound,
  71. "sound sub-system",
  72. "init - initialise the sound driver\n"
  73. "sound play [len] [freq] - play a sound for len ms at freq hz\n"
  74. );