Blame view

cmd/sound.c 1.77 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
c0c88533f   Rajeshwari Shinde   Sound: Add comman...
2
3
4
  /*
   * Copyright (C) 2012 Samsung Electronics
   * Rajeshwari Shinde <rajeshwari.s@samsung.com>
c0c88533f   Rajeshwari Shinde   Sound: Add comman...
5
6
7
8
   */
  
  #include <common.h>
  #include <command.h>
d49018986   Simon Glass   dm: sound: Create...
9
  #include <dm.h>
c0c88533f   Rajeshwari Shinde   Sound: Add comman...
10
11
12
13
14
15
16
17
  #include <fdtdec.h>
  #include <sound.h>
  
  DECLARE_GLOBAL_DATA_PTR;
  
  /* Initilaise sound subsystem */
  static int do_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  {
d49018986   Simon Glass   dm: sound: Create...
18
  	struct udevice *dev;
c0c88533f   Rajeshwari Shinde   Sound: Add comman...
19
  	int ret;
d49018986   Simon Glass   dm: sound: Create...
20
21
22
  	ret = uclass_first_device_err(UCLASS_SOUND, &dev);
  	if (!ret)
  		ret = sound_setup(dev);
c0c88533f   Rajeshwari Shinde   Sound: Add comman...
23
  	if (ret) {
d49018986   Simon Glass   dm: sound: Create...
24
25
  		printf("Initialise Audio driver failed (ret=%d)
  ", ret);
c0c88533f   Rajeshwari Shinde   Sound: Add comman...
26
27
28
29
30
31
32
33
34
  		return CMD_RET_FAILURE;
  	}
  
  	return 0;
  }
  
  /* play sound from buffer */
  static int do_play(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  {
d49018986   Simon Glass   dm: sound: Create...
35
  	struct udevice *dev;
c0c88533f   Rajeshwari Shinde   Sound: Add comman...
36
37
38
39
40
41
42
43
  	int ret = 0;
  	int msec = 1000;
  	int freq = 400;
  
  	if (argc > 1)
  		msec = simple_strtoul(argv[1], NULL, 10);
  	if (argc > 2)
  		freq = simple_strtoul(argv[2], NULL, 10);
d49018986   Simon Glass   dm: sound: Create...
44
45
46
  	ret = uclass_first_device_err(UCLASS_SOUND, &dev);
  	if (!ret)
  		ret = sound_beep(dev, msec, freq);
c0c88533f   Rajeshwari Shinde   Sound: Add comman...
47
  	if (ret) {
d49018986   Simon Glass   dm: sound: Create...
48
49
  		printf("Sound device failed to play (err=%d)
  ", ret);
c0c88533f   Rajeshwari Shinde   Sound: Add comman...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  		return CMD_RET_FAILURE;
  	}
  
  	return 0;
  }
  
  static cmd_tbl_t cmd_sound_sub[] = {
  	U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""),
  	U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""),
  };
  
  /* process sound command */
  static int do_sound(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  {
  	cmd_tbl_t *c;
  
  	if (argc < 1)
  		return CMD_RET_USAGE;
  
  	/* Strip off leading 'sound' command argument */
  	argc--;
  	argv++;
  
  	c = find_cmd_tbl(argv[0], &cmd_sound_sub[0], ARRAY_SIZE(cmd_sound_sub));
  
  	if (c)
  		return c->cmd(cmdtp, flag, argc, argv);
  	else
  		return CMD_RET_USAGE;
  }
  
  U_BOOT_CMD(
  	sound, 4, 1, do_sound,
  	"sound sub-system",
  	"init - initialise the sound driver
  "
  	"sound play [len] [freq] - play a sound for len ms at freq hz
  "
  );