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