-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ALSA: hda: cs35l56: Add support for speaker id
Add handling of the "spk-id-gpios" _DSD property. If present, the value indicated by the GPIOs is appended to the subsystem-id part of the firmware name to load the appropriate tunings for that speaker. Some manufacturers use multiple sources of speakers, which need different tunings for best performance. On these models the type of speaker fitted is indicated by the values of one or more GPIOs. The number formed by the GPIOs identifies the tuning required. The speaker ID is only used in combination with a _SUB identifier because the value is only meaningful if the exact model is known. The code to get the speaker ID value has been implemented as a new library so that the cs35l41_hda driver can be switched in future to share common code. This library can be extended for other common functionality shared by Cirrus Logic amp drivers. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Link: https://lore.kernel.org/r/20230918095129.440-2-rf@opensource.cirrus.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
- Loading branch information
Richard Fitzgerald
authored and
Takashi Iwai
committed
Sep 18, 2023
1 parent
6e74378
commit 6f03b44
Showing
6 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 | ||
* | ||
* Copyright (C) 2023 Cirrus Logic, Inc. and | ||
* Cirrus Logic International Semiconductor Ltd. | ||
*/ | ||
|
||
#ifndef CIRRUS_SCODEC_H | ||
#define CIRRUS_SCODEC_H | ||
|
||
int cirrus_scodec_get_speaker_id(struct device *dev, int amp_index, | ||
int num_amps, int fixed_gpio_id); | ||
|
||
#endif /* CIRRUS_SCODEC_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters