]> Git Repo - J-u-boot.git/blame - cmd/sound.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[J-u-boot.git] / cmd / sound.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
c0c88533
RS
2/*
3 * Copyright (C) 2012 Samsung Electronics
4 * Rajeshwari Shinde <[email protected]>
c0c88533
RS
5 */
6
d678a59d 7#include <common.h>
c0c88533 8#include <command.h>
d4901898 9#include <dm.h>
c0c88533
RS
10#include <fdtdec.h>
11#include <sound.h>
401d1c4f 12#include <asm/global_data.h>
c0c88533
RS
13
14DECLARE_GLOBAL_DATA_PTR;
15
16/* Initilaise sound subsystem */
09140113
SG
17static int do_init(struct cmd_tbl *cmdtp, int flag, int argc,
18 char *const argv[])
c0c88533 19{
d4901898 20 struct udevice *dev;
c0c88533
RS
21 int ret;
22
d4901898
SG
23 ret = uclass_first_device_err(UCLASS_SOUND, &dev);
24 if (!ret)
25 ret = sound_setup(dev);
c0c88533 26 if (ret) {
d4901898 27 printf("Initialise Audio driver failed (ret=%d)\n", ret);
c0c88533
RS
28 return CMD_RET_FAILURE;
29 }
30
31 return 0;
32}
33
34/* play sound from buffer */
09140113
SG
35static int do_play(struct cmd_tbl *cmdtp, int flag, int argc,
36 char *const argv[])
c0c88533 37{
d4901898 38 struct udevice *dev;
c0c88533
RS
39 int ret = 0;
40 int msec = 1000;
41 int freq = 400;
ea58b9a4 42 bool first = true;
c0c88533 43
d4901898 44 ret = uclass_first_device_err(UCLASS_SOUND, &dev);
ea58b9a4
HS
45 if (ret)
46 goto err;
47 --argc;
48 ++argv;
49 while (argc || first) {
50 first = false;
532952f6 51 if (argc) {
ea58b9a4
HS
52 msec = dectoul(argv[0], NULL);
53 --argc;
54 ++argv;
55 }
532952f6 56 if (argc) {
ea58b9a4
HS
57 freq = dectoul(argv[0], NULL);
58 --argc;
59 ++argv;
60 }
d4901898 61 ret = sound_beep(dev, msec, freq);
ea58b9a4
HS
62 if (ret)
63 goto err;
c0c88533 64 }
c0c88533 65 return 0;
ea58b9a4
HS
66
67err:
68 printf("Sound device failed to play (err=%d)\n", ret);
69 return CMD_RET_FAILURE;
c0c88533
RS
70}
71
09140113 72static struct cmd_tbl cmd_sound_sub[] = {
c0c88533 73 U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
ea58b9a4 74 U_BOOT_CMD_MKENT(play, INT_MAX, 1, do_play, "", ""),
c0c88533
RS
75};
76
77/* process sound command */
09140113
SG
78static int do_sound(struct cmd_tbl *cmdtp, int flag, int argc,
79 char *const argv[])
c0c88533 80{
09140113 81 struct cmd_tbl *c;
c0c88533
RS
82
83 if (argc < 1)
84 return CMD_RET_USAGE;
85
86 /* Strip off leading 'sound' command argument */
87 argc--;
88 argv++;
89
90 c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub));
91
92 if (c)
93 return c->cmd(cmdtp, flag, argc, argv);
94 else
95 return CMD_RET_USAGE;
96}
97
98U_BOOT_CMD(
ea58b9a4 99 sound, INT_MAX, 1, do_sound,
c0c88533
RS
100 "sound sub-system",
101 "init - initialise the sound driver\n"
ea58b9a4
HS
102 "sound play [[[-q|-s] len [freq]] ...] - play sounds\n"
103 " len - duration in ms\n"
104 " freq - frequency in Hz\n"
c0c88533 105);
This page took 0.414236 seconds and 4 git commands to generate.