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