blob: 20ac3f758e3442353974d8f97acb476a8776e604 [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>
Simon Glass76072ac2018-12-10 10:37:36 -07009#include <dm.h>
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000010#include <fdtdec.h>
11#include <sound.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000013
14DECLARE_GLOBAL_DATA_PTR;
15
16/* Initilaise sound subsystem */
Simon Glassed38aef2020-05-10 11:40:03 -060017static int do_init(struct cmd_tbl *cmdtp, int flag, int argc,
18 char *const argv[])
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000019{
Simon Glass76072ac2018-12-10 10:37:36 -070020 struct udevice *dev;
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000021 int ret;
22
Simon Glass76072ac2018-12-10 10:37:36 -070023 ret = uclass_first_device_err(UCLASS_SOUND, &dev);
24 if (!ret)
25 ret = sound_setup(dev);
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000026 if (ret) {
Simon Glass76072ac2018-12-10 10:37:36 -070027 printf("Initialise Audio driver failed (ret=%d)\n", ret);
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000028 return CMD_RET_FAILURE;
29 }
30
31 return 0;
32}
33
34/* play sound from buffer */
Simon Glassed38aef2020-05-10 11:40:03 -060035static int do_play(struct cmd_tbl *cmdtp, int flag, int argc,
36 char *const argv[])
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000037{
Simon Glass76072ac2018-12-10 10:37:36 -070038 struct udevice *dev;
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000039 int ret = 0;
40 int msec = 1000;
41 int freq = 400;
42
43 if (argc > 1)
Simon Glassff9b9032021-07-24 09:03:30 -060044 msec = dectoul(argv[1], NULL);
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000045 if (argc > 2)
Simon Glassff9b9032021-07-24 09:03:30 -060046 freq = dectoul(argv[2], NULL);
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000047
Simon Glass76072ac2018-12-10 10:37:36 -070048 ret = uclass_first_device_err(UCLASS_SOUND, &dev);
49 if (!ret)
50 ret = sound_beep(dev, msec, freq);
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000051 if (ret) {
Simon Glass76072ac2018-12-10 10:37:36 -070052 printf("Sound device failed to play (err=%d)\n", ret);
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000053 return CMD_RET_FAILURE;
54 }
55
56 return 0;
57}
58
Simon Glassed38aef2020-05-10 11:40:03 -060059static struct cmd_tbl cmd_sound_sub[] = {
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000060 U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
61 U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""),
62};
63
64/* process sound command */
Simon Glassed38aef2020-05-10 11:40:03 -060065static int do_sound(struct cmd_tbl *cmdtp, int flag, int argc,
66 char *const argv[])
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000067{
Simon Glassed38aef2020-05-10 11:40:03 -060068 struct cmd_tbl *c;
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000069
70 if (argc < 1)
71 return CMD_RET_USAGE;
72
73 /* Strip off leading 'sound' command argument */
74 argc--;
75 argv++;
76
77 c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub));
78
79 if (c)
80 return c->cmd(cmdtp, flag, argc, argv);
81 else
82 return CMD_RET_USAGE;
83}
84
85U_BOOT_CMD(
86 sound, 4, 1, do_sound,
87 "sound sub-system",
88 "init - initialise the sound driver\n"
Heinrich Schuchardtb250c942022-12-04 16:33:07 +010089 "sound play [len [freq]] - play a sound for len ms at freq Hz\n"
Rajeshwari Shinde805adac2012-10-25 19:49:24 +000090);