On Sun, 24 Jan 2021, Anton Yakovlev wrote:

Enumerate all available jacks and create ALSA controls.

At the moment jacks have a simple implementation and can only be used
to receive notifications about a plugged in/out device.

Signed-off-by: Anton Yakovlev <[email protected]>
---
sound/virtio/Makefile      |   1 +
sound/virtio/virtio_card.c |  18 +++
sound/virtio/virtio_card.h |  12 ++
sound/virtio/virtio_jack.c | 255 +++++++++++++++++++++++++++++++++++++
4 files changed, 286 insertions(+)
create mode 100644 sound/virtio/virtio_jack.c

[snip]

diff --git a/sound/virtio/virtio_jack.c b/sound/virtio/virtio_jack.c
new file mode 100644
index 000000000000..83593c59f6bf
--- /dev/null
+++ b/sound/virtio/virtio_jack.c
@@ -0,0 +1,255 @@

[snip]

+/**
+ * virtsnd_jack_parse_cfg() - Parse the jack configuration.
+ * @snd: VirtIO sound device.
+ *
+ * This function is called during initial device initialization.
+ *
+ * Context: Any context that permits to sleep.
+ * Return: 0 on success, -errno on failure.
+ */
+int virtsnd_jack_parse_cfg(struct virtio_snd *snd)
+{
+       struct virtio_device *vdev = snd->vdev;
+       struct virtio_snd_jack_info *info;
+       unsigned int i;
+       int rc;
+
+       virtio_cread(vdev, struct virtio_snd_config, jacks, &snd->njacks);
+       if (!snd->njacks)
+               return 0;
+
+       snd->jacks = devm_kcalloc(&vdev->dev, snd->njacks, sizeof(*snd->jacks),
+                                 GFP_KERNEL);
+       if (!snd->jacks)
+               return -ENOMEM;
+
+       info = devm_kcalloc(&vdev->dev, snd->njacks, sizeof(*info), GFP_KERNEL);

just kcalloc()

+       if (!info)
+               return -ENOMEM;
+
+       rc = virtsnd_ctl_query_info(snd, VIRTIO_SND_R_JACK_INFO, 0, snd->njacks,
+                                   sizeof(*info), info);
+       if (rc)
+               return rc;
+
+       for (i = 0; i < snd->njacks; ++i) {
+               struct virtio_jack *jack = &snd->jacks[i];
+               struct virtio_pcm *pcm;
+
+               jack->nid = le32_to_cpu(info[i].hdr.hda_fn_nid);
+               jack->features = le32_to_cpu(info[i].features);
+               jack->defconf = le32_to_cpu(info[i].hda_reg_defconf);
+               jack->caps = le32_to_cpu(info[i].hda_reg_caps);
+               jack->connected = info[i].connected;
+
+               pcm = virtsnd_pcm_find_or_create(snd, jack->nid);
+               if (IS_ERR(pcm))
+                       return PTR_ERR(pcm);
+       }
+
+       devm_kfree(&vdev->dev, info);
+
+       return 0;
+}

Thanks
Guennadi

Reply via email to