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