blob: f5dd8bcf261fa37a9736b4b08bf88ef27dca16cd [file] [log] [blame]
Rajeshwari Shindec0c88532012-10-25 19:49:24 +00001/*
2 * Copyright (C) 2012 Samsung Electronics
3 * Rajeshwari Shinde <rajeshwari.s@samsung.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shindec0c88532012-10-25 19:49:24 +00006 */
7
8#include <common.h>
9#include <command.h>
10#include <fdtdec.h>
11#include <sound.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
15/* Initilaise sound subsystem */
16static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
17{
18 int ret;
19
Rajeshwari Shinde2b8a0532012-12-26 20:03:19 +000020 ret = sound_init(gd->fdt_blob);
Rajeshwari Shindec0c88532012-10-25 19:49:24 +000021 if (ret) {
22 printf("Initialise Audio driver failed\n");
23 return CMD_RET_FAILURE;
24 }
25
26 return 0;
27}
28
29/* play sound from buffer */
30static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
31{
32 int ret = 0;
33 int msec = 1000;
34 int freq = 400;
35
36 if (argc > 1)
37 msec = simple_strtoul(argv[1], NULL, 10);
38 if (argc > 2)
39 freq = simple_strtoul(argv[2], NULL, 10);
40
41 ret = sound_play(msec, freq);
42 if (ret) {
43 printf("play failed");
44 return CMD_RET_FAILURE;
45 }
46
47 return 0;
48}
49
50static cmd_tbl_t cmd_sound_sub[] = {
51 U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
52 U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""),
53};
54
55/* process sound command */
56static int do_sound(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
57{
58 cmd_tbl_t *c;
59
60 if (argc < 1)
61 return CMD_RET_USAGE;
62
63 /* Strip off leading 'sound' command argument */
64 argc--;
65 argv++;
66
67 c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub));
68
69 if (c)
70 return c->cmd(cmdtp, flag, argc, argv);
71 else
72 return CMD_RET_USAGE;
73}
74
75U_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);