]>
Commit | Line | Data |
---|---|---|
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 | ||
7 | #include <common.h> | |
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 | |
14 | DECLARE_GLOBAL_DATA_PTR; | |
15 | ||
16 | /* Initilaise sound subsystem */ | |
09140113 SG |
17 | static 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 |
35 | static 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; | |
42 | ||
43 | if (argc > 1) | |
0b1284eb | 44 | msec = dectoul(argv[1], NULL); |
c0c88533 | 45 | if (argc > 2) |
0b1284eb | 46 | freq = dectoul(argv[2], NULL); |
c0c88533 | 47 | |
d4901898 SG |
48 | ret = uclass_first_device_err(UCLASS_SOUND, &dev); |
49 | if (!ret) | |
50 | ret = sound_beep(dev, msec, freq); | |
c0c88533 | 51 | if (ret) { |
d4901898 | 52 | printf("Sound device failed to play (err=%d)\n", ret); |
c0c88533 RS |
53 | return CMD_RET_FAILURE; |
54 | } | |
55 | ||
56 | return 0; | |
57 | } | |
58 | ||
09140113 | 59 | static struct cmd_tbl cmd_sound_sub[] = { |
c0c88533 RS |
60 | 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 */ | |
09140113 SG |
65 | static int do_sound(struct cmd_tbl *cmdtp, int flag, int argc, |
66 | char *const argv[]) | |
c0c88533 | 67 | { |
09140113 | 68 | struct cmd_tbl *c; |
c0c88533 RS |
69 | |
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 | ||
85 | U_BOOT_CMD( | |
86 | sound, 4, 1, do_sound, | |
87 | "sound sub-system", | |
88 | "init - initialise the sound driver\n" | |
ff414fcc | 89 | "sound play [len [freq]] - play a sound for len ms at freq Hz\n" |
c0c88533 | 90 | ); |