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