summaryrefslogtreecommitdiff
path: root/sound/hda/codecs/side-codecs/cirrus_scodec.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2025-07-09 18:04:09 +0200
committerTakashi Iwai <tiwai@suse.de>2025-07-11 09:55:37 +0200
commit6014e9021b28e634935c776c0271b5cbcabdc5d6 (patch)
tree36026b2b3cc9a3baa525e1c6ba7f84bc4b1d3d46 /sound/hda/codecs/side-codecs/cirrus_scodec.c
parent2d9223d2d64cb5216859ced6cc33fb3b04e5f98f (diff)
ALSA: hda: Move codec drivers into sound/hda/codecs directory
Now move the all remaining codec drivers from sound/pci/hda to sound/hda/codecs subdirectory. Some drivers are put under the further vendor subdirectory, and the vendor helper code (*_helper.c) are put under helpers subdirectory. Also the sub-codec drivers are moved under a different subdirectory, sound/hda/codecs/sub-codecs, for distinguishing from the main HD-audio codec drivers. The prefix patch_ and hda_ as well as the suffix _helper are dropped from file names as they are mostly superfluous. No functional changes but just file path shuffling. Reviewed-by: Richard Fitzgerald <rf@opensource.cirrus.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250709160434.1859-7-tiwai@suse.de
Diffstat (limited to 'sound/hda/codecs/side-codecs/cirrus_scodec.c')
-rw-r--r--sound/hda/codecs/side-codecs/cirrus_scodec.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/sound/hda/codecs/side-codecs/cirrus_scodec.c b/sound/hda/codecs/side-codecs/cirrus_scodec.c
new file mode 100644
index 000000000000..3c670207ba30
--- /dev/null
+++ b/sound/hda/codecs/side-codecs/cirrus_scodec.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Common code for Cirrus side-codecs.
+//
+// Copyright (C) 2021, 2023 Cirrus Logic, Inc. and
+// Cirrus Logic International Semiconductor Ltd.
+
+#include <linux/dev_printk.h>
+#include <linux/gpio/consumer.h>
+#include <linux/module.h>
+
+#include "cirrus_scodec.h"
+
+int cirrus_scodec_get_speaker_id(struct device *dev, int amp_index,
+ int num_amps, int fixed_gpio_id)
+{
+ struct gpio_desc *speaker_id_desc;
+ int speaker_id = -ENOENT;
+
+ if (fixed_gpio_id >= 0) {
+ dev_dbg(dev, "Found Fixed Speaker ID GPIO (index = %d)\n", fixed_gpio_id);
+ speaker_id_desc = gpiod_get_index(dev, NULL, fixed_gpio_id, GPIOD_IN);
+ if (IS_ERR(speaker_id_desc)) {
+ speaker_id = PTR_ERR(speaker_id_desc);
+ return speaker_id;
+ }
+ speaker_id = gpiod_get_value_cansleep(speaker_id_desc);
+ gpiod_put(speaker_id_desc);
+ } else {
+ int base_index;
+ int gpios_per_amp;
+ int count;
+ int tmp;
+ int i;
+
+ count = gpiod_count(dev, "spk-id");
+ if (count > 0) {
+ speaker_id = 0;
+ gpios_per_amp = count / num_amps;
+ base_index = gpios_per_amp * amp_index;
+
+ if (count % num_amps)
+ return -EINVAL;
+
+ dev_dbg(dev, "Found %d Speaker ID GPIOs per Amp\n", gpios_per_amp);
+
+ for (i = 0; i < gpios_per_amp; i++) {
+ speaker_id_desc = gpiod_get_index(dev, "spk-id", i + base_index,
+ GPIOD_IN);
+ if (IS_ERR(speaker_id_desc)) {
+ speaker_id = PTR_ERR(speaker_id_desc);
+ break;
+ }
+ tmp = gpiod_get_value_cansleep(speaker_id_desc);
+ gpiod_put(speaker_id_desc);
+ if (tmp < 0) {
+ speaker_id = tmp;
+ break;
+ }
+ speaker_id |= tmp << i;
+ }
+ }
+ }
+
+ dev_dbg(dev, "Speaker ID = %d\n", speaker_id);
+
+ return speaker_id;
+}
+EXPORT_SYMBOL_NS_GPL(cirrus_scodec_get_speaker_id, "SND_HDA_CIRRUS_SCODEC");
+
+MODULE_DESCRIPTION("HDA Cirrus side-codec library");
+MODULE_AUTHOR("Richard Fitzgerald <rf@opensource.cirrus.com>");
+MODULE_LICENSE("GPL");