Path: blob/master/sound/hda/codecs/side-codecs/cirrus_scodec.c
26481 views
// SPDX-License-Identifier: GPL-2.0-only1//2// Common code for Cirrus side-codecs.3//4// Copyright (C) 2021, 2023 Cirrus Logic, Inc. and5// Cirrus Logic International Semiconductor Ltd.67#include <linux/dev_printk.h>8#include <linux/gpio/consumer.h>9#include <linux/module.h>1011#include "cirrus_scodec.h"1213int cirrus_scodec_get_speaker_id(struct device *dev, int amp_index,14int num_amps, int fixed_gpio_id)15{16struct gpio_desc *speaker_id_desc;17int speaker_id = -ENOENT;1819if (fixed_gpio_id >= 0) {20dev_dbg(dev, "Found Fixed Speaker ID GPIO (index = %d)\n", fixed_gpio_id);21speaker_id_desc = gpiod_get_index(dev, NULL, fixed_gpio_id, GPIOD_IN);22if (IS_ERR(speaker_id_desc)) {23speaker_id = PTR_ERR(speaker_id_desc);24return speaker_id;25}26speaker_id = gpiod_get_value_cansleep(speaker_id_desc);27gpiod_put(speaker_id_desc);28} else {29int base_index;30int gpios_per_amp;31int count;32int tmp;33int i;3435count = gpiod_count(dev, "spk-id");36if (count > 0) {37speaker_id = 0;38gpios_per_amp = count / num_amps;39base_index = gpios_per_amp * amp_index;4041if (count % num_amps)42return -EINVAL;4344dev_dbg(dev, "Found %d Speaker ID GPIOs per Amp\n", gpios_per_amp);4546for (i = 0; i < gpios_per_amp; i++) {47speaker_id_desc = gpiod_get_index(dev, "spk-id", i + base_index,48GPIOD_IN);49if (IS_ERR(speaker_id_desc)) {50speaker_id = PTR_ERR(speaker_id_desc);51break;52}53tmp = gpiod_get_value_cansleep(speaker_id_desc);54gpiod_put(speaker_id_desc);55if (tmp < 0) {56speaker_id = tmp;57break;58}59speaker_id |= tmp << i;60}61}62}6364dev_dbg(dev, "Speaker ID = %d\n", speaker_id);6566return speaker_id;67}68EXPORT_SYMBOL_NS_GPL(cirrus_scodec_get_speaker_id, "SND_HDA_CIRRUS_SCODEC");6970MODULE_DESCRIPTION("HDA Cirrus side-codec library");71MODULE_AUTHOR("Richard Fitzgerald <[email protected]>");72MODULE_LICENSE("GPL");737475