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> |
| 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; |
| 41 | |
| 42 | if (argc > 1) |
| 43 | msec = simple_strtoul(argv[1], NULL, 10); |
| 44 | if (argc > 2) |
| 45 | freq = simple_strtoul(argv[2], NULL, 10); |
| 46 | |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 47 | ret = uclass_first_device_err(UCLASS_SOUND, &dev); |
| 48 | if (!ret) |
| 49 | ret = sound_beep(dev, msec, freq); |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 50 | if (ret) { |
Simon Glass | d490189 | 2018-12-10 10:37:36 -0700 | [diff] [blame] | 51 | printf("Sound device failed to play (err=%d)\n", ret); |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 52 | return CMD_RET_FAILURE; |
| 53 | } |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 58 | static struct cmd_tbl cmd_sound_sub[] = { |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 59 | U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""), |
| 60 | U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""), |
| 61 | }; |
| 62 | |
| 63 | /* process sound command */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 64 | static int do_sound(struct cmd_tbl *cmdtp, int flag, int argc, |
| 65 | char *const argv[]) |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 66 | { |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 67 | struct cmd_tbl *c; |
Rajeshwari Shinde | c0c8853 | 2012-10-25 19:49:24 +0000 | [diff] [blame] | 68 | |
| 69 | if (argc < 1) |
| 70 | return CMD_RET_USAGE; |
| 71 | |
| 72 | /* Strip off leading 'sound' command argument */ |
| 73 | argc--; |
| 74 | argv++; |
| 75 | |
| 76 | c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub)); |
| 77 | |
| 78 | if (c) |
| 79 | return c->cmd(cmdtp, flag, argc, argv); |
| 80 | else |
| 81 | return CMD_RET_USAGE; |
| 82 | } |
| 83 | |
| 84 | U_BOOT_CMD( |
| 85 | sound, 4, 1, do_sound, |
| 86 | "sound sub-system", |
| 87 | "init - initialise the sound driver\n" |
| 88 | "sound play [len] [freq] - play a sound for len ms at freq hz\n" |
| 89 | ); |