mixer: Add get_card_name() API d-lollipop-release master
authorMisael Lopez Cruz <misael.lopez@ti.com>
Thu, 2 May 2013 23:11:17 +0000 (18:11 -0500)
committerVishal Mahaveer <vishalm@ti.com>
Wed, 12 Nov 2014 23:51:42 +0000 (17:51 -0600)
Add mixer_get_card_name() so that clients can retrieve card's
name based on its id.

Change-Id: Ic29e5e8c8098c578aadb8e104c4cd48e0871afeb
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
include/tinyalsa/asoundlib.h
mixer.c

index 75e5cda3e9a25e3ad9ab1baa4f45f3263060e42b..4b6e4ecaf8fbbf64273794fbac91fe0e407a7095 100644 (file)
@@ -147,6 +147,12 @@ enum mixer_ctl_type {
     MIXER_CTL_TYPE_MAX,
 };
 
+#ifdef OMAP_ENHANCEMENT
+#define MAX_CARD_COUNT 32
+
+int mixer_get_card_name(int card, char *str, size_t strlen);
+#endif
+
 /* Open and close a stream */
 struct pcm *pcm_open(unsigned int card, unsigned int device,
                      unsigned int flags, struct pcm_config *config);
diff --git a/mixer.c b/mixer.c
index 4568cca2bfed71746b551b397f2a12e09207b894..8a0add01c2823b856751c2f9c8016382f776eefa 100644 (file)
--- a/mixer.c
+++ b/mixer.c
@@ -495,3 +495,35 @@ int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string)
     return -EINVAL;
 }
 
+#ifdef OMAP_ENHANCEMENT
+int mixer_get_card_name(int card, char *str, size_t strlen)
+{
+    struct snd_ctl_card_info info;
+    char fn[256];
+    int fd;
+    int ret;
+
+    if (card > MAX_CARD_COUNT)
+        return -EINVAL;
+
+    if (!str)
+        return -EINVAL;
+
+    snprintf(fn, sizeof(fn), "/dev/snd/controlC%u", card);
+    fd = open(fn, O_RDWR);
+    if (fd < 0)
+        return -ENODEV;
+
+    ret = ioctl(fd, SNDRV_CTL_IOCTL_CARD_INFO, &info);
+    if (ret < 0) {
+        close(fd);
+        return ret;
+    }
+
+    strncpy(str, (char *)info.id, strlen);
+
+    close(fd);
+
+    return 0;
+}
+#endif