xref: /openbmc/u-boot/cmd/sound.c (revision 87a62bce)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2012 Samsung Electronics
4  * Rajeshwari Shinde <rajeshwari.s@samsung.com>
5  */
6 
7 #include <common.h>
8 #include <command.h>
9 #include <fdtdec.h>
10 #include <sound.h>
11 
12 DECLARE_GLOBAL_DATA_PTR;
13 
14 /* Initilaise sound subsystem */
15 static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
16 {
17 	int ret;
18 
19 	ret = sound_init(gd->fdt_blob);
20 	if (ret) {
21 		printf("Initialise Audio driver failed\n");
22 		return CMD_RET_FAILURE;
23 	}
24 
25 	return 0;
26 }
27 
28 /* play sound from buffer */
29 static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
30 {
31 	int ret = 0;
32 	int msec = 1000;
33 	int freq = 400;
34 
35 	if (argc > 1)
36 		msec = simple_strtoul(argv[1], NULL, 10);
37 	if (argc > 2)
38 		freq = simple_strtoul(argv[2], NULL, 10);
39 
40 	ret = sound_play(msec, freq);
41 	if (ret) {
42 		printf("play failed");
43 		return CMD_RET_FAILURE;
44 	}
45 
46 	return 0;
47 }
48 
49 static cmd_tbl_t 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 
54 /* process sound command */
55 static int do_sound(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
56 {
57 	cmd_tbl_t *c;
58 
59 	if (argc < 1)
60 		return CMD_RET_USAGE;
61 
62 	/* Strip off leading 'sound' command argument */
63 	argc--;
64 	argv++;
65 
66 	c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub));
67 
68 	if (c)
69 		return c->cmd(cmdtp, flag, argc, argv);
70 	else
71 		return CMD_RET_USAGE;
72 }
73 
74 U_BOOT_CMD(
75 	sound, 4, 1, do_sound,
76 	"sound sub-system",
77 	"init - initialise the sound driver\n"
78 	"sound play [len] [freq] - play a sound for len ms at freq hz\n"
79 );
80