cmd_sound.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics
  3. * Rajeshwari Shinde <rajeshwari.s@samsung.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <fdtdec.h>
  26. #include <sound.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /* Initilaise sound subsystem */
  29. static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  30. {
  31. int ret;
  32. ret = sound_init(gd->fdt_blob);
  33. if (ret) {
  34. printf("Initialise Audio driver failed\n");
  35. return CMD_RET_FAILURE;
  36. }
  37. return 0;
  38. }
  39. /* play sound from buffer */
  40. static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  41. {
  42. int ret = 0;
  43. int msec = 1000;
  44. int freq = 400;
  45. if (argc > 1)
  46. msec = simple_strtoul(argv[1], NULL, 10);
  47. if (argc > 2)
  48. freq = simple_strtoul(argv[2], NULL, 10);
  49. ret = sound_play(msec, freq);
  50. if (ret) {
  51. printf("play failed");
  52. return CMD_RET_FAILURE;
  53. }
  54. return 0;
  55. }
  56. static cmd_tbl_t cmd_sound_sub[] = {
  57. U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
  58. U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""),
  59. };
  60. /* process sound command */
  61. static int do_sound(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  62. {
  63. cmd_tbl_t *c;
  64. if (argc < 1)
  65. return CMD_RET_USAGE;
  66. /* Strip off leading 'sound' command argument */
  67. argc--;
  68. argv++;
  69. c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub));
  70. if (c)
  71. return c->cmd(cmdtp, flag, argc, argv);
  72. else
  73. return CMD_RET_USAGE;
  74. }
  75. U_BOOT_CMD(
  76. sound, 4, 1, do_sound,
  77. "sound sub-system",
  78. "init - initialise the sound driver\n"
  79. "sound play [len] [freq] - play a sound for len ms at freq hz\n"
  80. );