blob: 77f51529259e4646c42a1bce0c1a3867de7f6d74 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shindec0c88532012-10-25 19:49:24 +00002/*
3 * Copyright (C) 2012 Samsung Electronics
4 * Rajeshwari Shinde <rajeshwari.s@samsung.com>
Rajeshwari Shindec0c88532012-10-25 19:49:24 +00005 */
6
7#include <common.h>
8#include <command.h>
Simon Glassd4901892018-12-10 10:37:36 -07009#include <dm.h>
Rajeshwari Shindec0c88532012-10-25 19:49:24 +000010#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{
Simon Glassd4901892018-12-10 10:37:36 -070018#ifdef CONFIG_DM_SOUND
19 struct udevice *dev;
20#endif
Rajeshwari Shindec0c88532012-10-25 19:49:24 +000021 int ret;
22
Simon Glassd4901892018-12-10 10:37:36 -070023#ifdef CONFIG_DM_SOUND
24 ret = uclass_first_device_err(UCLASS_SOUND, &dev);
25 if (!ret)
26 ret = sound_setup(dev);
27#else
Rajeshwari Shinde2b8a0532012-12-26 20:03:19 +000028 ret = sound_init(gd->fdt_blob);
Simon Glassd4901892018-12-10 10:37:36 -070029#endif
Rajeshwari Shindec0c88532012-10-25 19:49:24 +000030 if (ret) {
Simon Glassd4901892018-12-10 10:37:36 -070031 printf("Initialise Audio driver failed (ret=%d)\n", ret);
Rajeshwari Shindec0c88532012-10-25 19:49:24 +000032 return CMD_RET_FAILURE;
33 }
34
35 return 0;
36}
37
38/* play sound from buffer */
39static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
40{
Simon Glassd4901892018-12-10 10:37:36 -070041#ifdef CONFIG_DM_SOUND
42 struct udevice *dev;
43#endif
Rajeshwari Shindec0c88532012-10-25 19:49:24 +000044 int ret = 0;
45 int msec = 1000;
46 int freq = 400;
47
48 if (argc > 1)
49 msec = simple_strtoul(argv[1], NULL, 10);
50 if (argc > 2)
51 freq = simple_strtoul(argv[2], NULL, 10);
52
Simon Glassd4901892018-12-10 10:37:36 -070053#ifdef CONFIG_DM_SOUND
54 ret = uclass_first_device_err(UCLASS_SOUND, &dev);
55 if (!ret)
56 ret = sound_beep(dev, msec, freq);
57#else
Rajeshwari Shindec0c88532012-10-25 19:49:24 +000058 ret = sound_play(msec, freq);
Simon Glassd4901892018-12-10 10:37:36 -070059#endif
Rajeshwari Shindec0c88532012-10-25 19:49:24 +000060 if (ret) {
Simon Glassd4901892018-12-10 10:37:36 -070061 printf("Sound device failed to play (err=%d)\n", ret);
Rajeshwari Shindec0c88532012-10-25 19:49:24 +000062 return CMD_RET_FAILURE;
63 }
64
65 return 0;
66}
67
68static cmd_tbl_t cmd_sound_sub[] = {
69 U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
70 U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""),
71};
72
73/* process sound command */
74static int do_sound(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
75{
76 cmd_tbl_t *c;
77
78 if (argc < 1)
79 return CMD_RET_USAGE;
80
81 /* Strip off leading 'sound' command argument */
82 argc--;
83 argv++;
84
85 c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub));
86
87 if (c)
88 return c->cmd(cmdtp, flag, argc, argv);
89 else
90 return CMD_RET_USAGE;
91}
92
93U_BOOT_CMD(
94 sound, 4, 1, do_sound,
95 "sound sub-system",
96 "init - initialise the sound driver\n"
97 "sound play [len] [freq] - play a sound for len ms at freq hz\n"
98);