Skip to content

Commit 03c5c35

Browse files
simontrimmertiwai
authored andcommitted
ALSA: hda/realtek: Add support for new HP G12 laptops
Some of these laptop models have quirk IDs that are identical but have different amplifier parts fitted, this difference is described in the ACPI information. The solution introduced for this product family can derive the required component binding information from ACPI instead of hardcoding it, supports the new variants of the CS35L56 being used and has generalized naming that makes it applicable to other ALC+amp combinations. Signed-off-by: Simon Trimmer <simont@opensource.cirrus.com> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Link: https://patch.msgid.link/20240802152215.20831-4-rf@opensource.cirrus.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 9219b17 commit 03c5c35

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

sound/pci/hda/patch_realtek.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111
*/
1212

1313
#include <linux/acpi.h>
14+
#include <linux/cleanup.h>
1415
#include <linux/init.h>
1516
#include <linux/delay.h>
1617
#include <linux/slab.h>
1718
#include <linux/pci.h>
1819
#include <linux/dmi.h>
1920
#include <linux/module.h>
21+
#include <linux/i2c.h>
2022
#include <linux/input.h>
2123
#include <linux/leds.h>
2224
#include <linux/ctype.h>
25+
#include <linux/spi/spi.h>
2326
#include <sound/core.h>
2427
#include <sound/jack.h>
2528
#include <sound/hda_codec.h>
@@ -6856,6 +6859,86 @@ static void comp_generic_fixup(struct hda_codec *cdc, int action, const char *bu
68566859
}
68576860
}
68586861

6862+
static void cs35lxx_autodet_fixup(struct hda_codec *cdc,
6863+
const struct hda_fixup *fix,
6864+
int action)
6865+
{
6866+
struct device *dev = hda_codec_dev(cdc);
6867+
struct acpi_device *adev;
6868+
struct fwnode_handle *fwnode __free(fwnode_handle) = NULL;
6869+
const char *bus = NULL;
6870+
static const struct {
6871+
const char *hid;
6872+
const char *name;
6873+
} acpi_ids[] = {{ "CSC3554", "cs35l54-hda" },
6874+
{ "CSC3556", "cs35l56-hda" },
6875+
{ "CSC3557", "cs35l57-hda" }};
6876+
char *match;
6877+
int i, count = 0, count_devindex = 0;
6878+
6879+
switch (action) {
6880+
case HDA_FIXUP_ACT_PRE_PROBE:
6881+
for (i = 0; i < ARRAY_SIZE(acpi_ids); ++i) {
6882+
adev = acpi_dev_get_first_match_dev(acpi_ids[i].hid, NULL, -1);
6883+
if (adev)
6884+
break;
6885+
}
6886+
if (!adev) {
6887+
dev_err(dev, "Failed to find ACPI entry for a Cirrus Amp\n");
6888+
return;
6889+
}
6890+
6891+
count = i2c_acpi_client_count(adev);
6892+
if (count > 0) {
6893+
bus = "i2c";
6894+
} else {
6895+
count = acpi_spi_count_resources(adev);
6896+
if (count > 0)
6897+
bus = "spi";
6898+
}
6899+
6900+
fwnode = fwnode_handle_get(acpi_fwnode_handle(adev));
6901+
acpi_dev_put(adev);
6902+
6903+
if (!bus) {
6904+
dev_err(dev, "Did not find any buses for %s\n", acpi_ids[i].hid);
6905+
return;
6906+
}
6907+
6908+
if (!fwnode) {
6909+
dev_err(dev, "Could not get fwnode for %s\n", acpi_ids[i].hid);
6910+
return;
6911+
}
6912+
6913+
/*
6914+
* When available the cirrus,dev-index property is an accurate
6915+
* count of the amps in a system and is used in preference to
6916+
* the count of bus devices that can contain additional address
6917+
* alias entries.
6918+
*/
6919+
count_devindex = fwnode_property_count_u32(fwnode, "cirrus,dev-index");
6920+
if (count_devindex > 0)
6921+
count = count_devindex;
6922+
6923+
match = devm_kasprintf(dev, GFP_KERNEL, "-%%s:00-%s.%%d", acpi_ids[i].name);
6924+
if (!match)
6925+
return;
6926+
dev_info(dev, "Found %d %s on %s (%s)\n", count, acpi_ids[i].hid, bus, match);
6927+
comp_generic_fixup(cdc, action, bus, acpi_ids[i].hid, match, count);
6928+
6929+
break;
6930+
case HDA_FIXUP_ACT_FREE:
6931+
/*
6932+
* Pass the action on to comp_generic_fixup() so that
6933+
* hda_component_manager functions can be called in just once
6934+
* place. In this context the bus, hid, match_str or count
6935+
* values do not need to be calculated.
6936+
*/
6937+
comp_generic_fixup(cdc, action, NULL, NULL, NULL, 0);
6938+
break;
6939+
}
6940+
}
6941+
68596942
static void cs35l41_fixup_i2c_two(struct hda_codec *cdc, const struct hda_fixup *fix, int action)
68606943
{
68616944
comp_generic_fixup(cdc, action, "i2c", "CSC3551", "-%s:00-cs35l41-hda.%d", 2);
@@ -7528,6 +7611,7 @@ enum {
75287611
ALC256_FIXUP_CHROME_BOOK,
75297612
ALC287_FIXUP_LENOVO_14ARP8_LEGION_IAH7,
75307613
ALC287_FIXUP_LENOVO_SSID_17AA3820,
7614+
ALCXXX_FIXUP_CS35LXX,
75317615
};
75327616

75337617
/* A special fixup for Lenovo C940 and Yoga Duet 7;
@@ -9857,6 +9941,10 @@ static const struct hda_fixup alc269_fixups[] = {
98579941
.type = HDA_FIXUP_FUNC,
98589942
.v.func = alc287_fixup_lenovo_ssid_17aa3820,
98599943
},
9944+
[ALCXXX_FIXUP_CS35LXX] = {
9945+
.type = HDA_FIXUP_FUNC,
9946+
.v.func = cs35lxx_autodet_fixup,
9947+
},
98609948
};
98619949

98629950
static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -10271,6 +10359,17 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
1027110359
SND_PCI_QUIRK(0x103c, 0x8cdf, "HP SnowWhite", ALC287_FIXUP_CS35L41_I2C_2_HP_GPIO_LED),
1027210360
SND_PCI_QUIRK(0x103c, 0x8ce0, "HP SnowWhite", ALC287_FIXUP_CS35L41_I2C_2_HP_GPIO_LED),
1027310361
SND_PCI_QUIRK(0x103c, 0x8cf5, "HP ZBook Studio 16", ALC245_FIXUP_CS35L41_SPI_4_HP_GPIO_LED),
10362+
SND_PCI_QUIRK(0x103c, 0x8d01, "HP ZBook Power 14 G12", ALCXXX_FIXUP_CS35LXX),
10363+
SND_PCI_QUIRK(0x103c, 0x8d08, "HP EliteBook 1045 14 G12", ALCXXX_FIXUP_CS35LXX),
10364+
SND_PCI_QUIRK(0x103c, 0x8d85, "HP EliteBook 1040 14 G12", ALCXXX_FIXUP_CS35LXX),
10365+
SND_PCI_QUIRK(0x103c, 0x8d86, "HP Elite x360 1040 14 G12", ALCXXX_FIXUP_CS35LXX),
10366+
SND_PCI_QUIRK(0x103c, 0x8d8c, "HP EliteBook 830 13 G12", ALCXXX_FIXUP_CS35LXX),
10367+
SND_PCI_QUIRK(0x103c, 0x8d8d, "HP Elite x360 830 13 G12", ALCXXX_FIXUP_CS35LXX),
10368+
SND_PCI_QUIRK(0x103c, 0x8d8e, "HP EliteBook 840 14 G12", ALCXXX_FIXUP_CS35LXX),
10369+
SND_PCI_QUIRK(0x103c, 0x8d8f, "HP EliteBook 840 14 G12", ALCXXX_FIXUP_CS35LXX),
10370+
SND_PCI_QUIRK(0x103c, 0x8d90, "HP EliteBook 860 16 G12", ALCXXX_FIXUP_CS35LXX),
10371+
SND_PCI_QUIRK(0x103c, 0x8d91, "HP ZBook Firefly 14 G12", ALCXXX_FIXUP_CS35LXX),
10372+
SND_PCI_QUIRK(0x103c, 0x8d92, "HP ZBook Firefly 16 G12", ALCXXX_FIXUP_CS35LXX),
1027410373
SND_PCI_QUIRK(0x1043, 0x103e, "ASUS X540SA", ALC256_FIXUP_ASUS_MIC),
1027510374
SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300),
1027610375
SND_PCI_QUIRK(0x1043, 0x106d, "Asus K53BE", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),

0 commit comments

Comments
 (0)