blob: d1cbc14f8df0f146021be166f95b4d8b1bba5bb0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shinde805adac2012-10-25 19:49:24 +00002/*
3 * Copyright (C) 2012 Samsung Electronics
4 * Rajeshwari Shinde <rajeshwari.s@samsung.com>
Rajeshwari Shinde805adac2012-10-25 19:49:24 +00005 */
6
7#include <common.h>
8#include <command.h>
9#include <fdtdec.h>
10#include <sound.h>
11
12DECLARE_GLOBAL_DATA_PTR;
13
14/* Initilaise sound subsystem */
15static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
16{
17 int ret;
18
Rajeshwari Shindeb973a292012-12-26 20:03:19 +000019 ret = sound_init(gd->fdt_blob);
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000020 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 */
29static 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
49static 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 */
55static 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
74U_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);