Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Samsung Electronics |
| 4 | * Rajeshwari Shinde <rajeshwari.s@samsung.com> |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 8 | #include <dm.h> |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 9 | #include <fdtdec.h> |
| 10 | #include <sound.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
| 15 | /* Initilaise sound subsystem */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 16 | static int do_init(struct cmd_tbl *cmdtp, int flag, int argc, |
| 17 | char *const argv[]) |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 18 | { |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 19 | struct udevice *dev; |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 20 | int ret; |
| 21 | |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 22 | ret = uclass_first_device_err(UCLASS_SOUND, &dev); |
| 23 | if (!ret) |
| 24 | ret = sound_setup(dev); |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 25 | if (ret) { |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 26 | printf("Initialise Audio driver failed (ret=%d)\n", ret); |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 27 | return CMD_RET_FAILURE; |
| 28 | } |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | /* play sound from buffer */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 34 | static int do_play(struct cmd_tbl *cmdtp, int flag, int argc, |
| 35 | char *const argv[]) |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 36 | { |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 37 | struct udevice *dev; |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 38 | int ret = 0; |
| 39 | int msec = 1000; |
| 40 | int freq = 400; |
Heinrich Schuchardt | ea58b9a | 2022-12-15 16:50:39 -0800 | [diff] [blame] | 41 | bool first = true; |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 42 | |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 43 | ret = uclass_first_device_err(UCLASS_SOUND, &dev); |
Heinrich Schuchardt | ea58b9a | 2022-12-15 16:50:39 -0800 | [diff] [blame] | 44 | if (ret) |
| 45 | goto err; |
| 46 | --argc; |
| 47 | ++argv; |
| 48 | while (argc || first) { |
| 49 | first = false; |
Heinrich Schuchardt | 532952f | 2022-12-31 00:49:10 +0100 | [diff] [blame] | 50 | if (argc) { |
Heinrich Schuchardt | ea58b9a | 2022-12-15 16:50:39 -0800 | [diff] [blame] | 51 | msec = dectoul(argv[0], NULL); |
| 52 | --argc; |
| 53 | ++argv; |
| 54 | } |
Heinrich Schuchardt | 532952f | 2022-12-31 00:49:10 +0100 | [diff] [blame] | 55 | if (argc) { |
Heinrich Schuchardt | ea58b9a | 2022-12-15 16:50:39 -0800 | [diff] [blame] | 56 | freq = dectoul(argv[0], NULL); |
| 57 | --argc; |
| 58 | ++argv; |
| 59 | } |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 60 | ret = sound_beep(dev, msec, freq); |
Heinrich Schuchardt | ea58b9a | 2022-12-15 16:50:39 -0800 | [diff] [blame] | 61 | if (ret) |
| 62 | goto err; |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 63 | } |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 64 | return 0; |
Heinrich Schuchardt | ea58b9a | 2022-12-15 16:50:39 -0800 | [diff] [blame] | 65 | |
| 66 | err: |
| 67 | printf("Sound device failed to play (err=%d)\n", ret); |
| 68 | return CMD_RET_FAILURE; |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 71 | static struct cmd_tbl cmd_sound_sub[] = { |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 72 | U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""), |
Heinrich Schuchardt | ea58b9a | 2022-12-15 16:50:39 -0800 | [diff] [blame] | 73 | U_BOOT_CMD_MKENT(play, INT_MAX, 1, do_play, "", ""), |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | /* process sound command */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 77 | static int do_sound(struct cmd_tbl *cmdtp, int flag, int argc, |
| 78 | char *const argv[]) |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 79 | { |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 80 | struct cmd_tbl *c; |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 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 | |
| 97 | U_BOOT_CMD( |
Heinrich Schuchardt | ea58b9a | 2022-12-15 16:50:39 -0800 | [diff] [blame] | 98 | sound, INT_MAX, 1, do_sound, |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 99 | "sound sub-system", |
| 100 | "init - initialise the sound driver\n" |
Quentin Schulz | ca6a992 | 2024-06-10 18:11:44 +0200 | [diff] [blame] | 101 | "sound play [len [freq [len [freq ...]]]] - play sounds\n" |
Heinrich Schuchardt | ea58b9a | 2022-12-15 16:50:39 -0800 | [diff] [blame] | 102 | " len - duration in ms\n" |
| 103 | " freq - frequency in Hz\n" |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 104 | ); |