From patchwork Tue Nov 21 12:28:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 1866712 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZNw81Vplz1ySV for ; Tue, 21 Nov 2023 23:28:54 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1r5Prx-0004pg-8k; Tue, 21 Nov 2023 12:28:45 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1r5Prt-0004ow-11 for kernel-team@lists.ubuntu.com; Tue, 21 Nov 2023 12:28:41 +0000 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 876B13F0B1 for ; Tue, 21 Nov 2023 12:28:40 +0000 (UTC) Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3b2ef9a0756so6421294b6e.2 for ; Tue, 21 Nov 2023 04:28:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700569719; x=1701174519; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cm9ljLgjZ4zok/xm3HH4X9+9VWySk88Z6684+vEEnHk=; b=NHfouH1wWDrthGhYUCCzkqvTyIp00AL/z3jJWqkeqgcZLYuuBEUcGpP/Qc6sDSc5jR X1IXJgGWEdc6sY+YKCuvjH8vEcZpP+d7rTMBQTewysHLec5Wm1oTvT5A4bK6WXTNhAXM Gpx7uiBXZ0qH/9Mt/vJ6UjU1cePsDkDjG3WERtaSr3sjzkjhlYwTR+ecb9b7Zut62tVk D97iVDmV0gzsY8Om58OK+fcOMMCqWlsEK+AuwaAnp1JMEeSEAACKI43V+k0zcjoaETCA E70n7ev34LxffzC+yT2QEiDEQpc83XtBsgSZnWvHSE14VaNGnB0e0f1kMwu/pXBuWp59 VnLg== X-Gm-Message-State: AOJu0YzpTuFqQ0XTOx3YqW/j8Q0/zctXSbvwhBqihYjwH4RFIpb51BpG Q8iYqgxYorFBzsBIdbU4fRB36vsxWVXuSsck7X+FeRNAJD4ThkPfo+8GXaLePjjGAnIYcgy326I 3ZFhUX3FoiDbcTsc5+wlC0BrRd3cV8IIZ9hQFAeKho86hZxIUhA== X-Received: by 2002:a05:6808:14cd:b0:3af:e67d:8295 with SMTP id f13-20020a05680814cd00b003afe67d8295mr15013471oiw.40.1700569718988; Tue, 21 Nov 2023 04:28:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHpTLbP6h2uIvS3fIarLpDhdZWM05nsRn7Wrp0ljFAy8FmkKMX/DV+b/8hS0j+//YrRKzwyfQ== X-Received: by 2002:a05:6808:14cd:b0:3af:e67d:8295 with SMTP id f13-20020a05680814cd00b003afe67d8295mr15013447oiw.40.1700569718413; Tue, 21 Nov 2023 04:28:38 -0800 (PST) Received: from localhost.localdomain (114-36-219-155.dynamic-ip.hinet.net. [114.36.219.155]) by smtp.gmail.com with ESMTPSA id o12-20020a056a00214c00b006c34015a8f2sm8006096pfk.146.2023.11.21.04.28.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 04:28:38 -0800 (PST) From: Chris Chiu To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/6][SRU][M] ALSA: hda: cs35l41: Support systems with missing _DSD properties Date: Tue, 21 Nov 2023 20:28:28 +0800 Message-Id: <20231121122833.11493-2-chris.chiu@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231121122833.11493-1-chris.chiu@canonical.com> References: <20231121122833.11493-1-chris.chiu@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Stefan Binding BugLink: https://bugs.launchpad.net/bugs/2039151 Some systems using CS35L41 with HDA were released without some required _DSD properties in ACPI. To support these special cases, add an api to configure the correct properties for systems with this issue. This initial commit moves the no _DSD support for Lenovo Legion Laptops (CLSA0100, CLSA0101) into a new framework which can be extended to support additional laptops in the future. Signed-off-by: Stefan Binding Link: https://lore.kernel.org/r/20230815161033.3519-1-sbinding@opensource.cirrus.com Signed-off-by: Takashi Iwai (cherry picked from commit ef4ba63f12b03532378395a8611f2f6e22ece67b) Signed-off-by: Chris Chiu --- sound/pci/hda/Makefile | 2 +- sound/pci/hda/cs35l41_hda.c | 65 ++++++------------------- sound/pci/hda/cs35l41_hda.h | 1 + sound/pci/hda/cs35l41_hda_property.c | 73 ++++++++++++++++++++++++++++ sound/pci/hda/cs35l41_hda_property.h | 18 +++++++ 5 files changed, 108 insertions(+), 51 deletions(-) create mode 100644 sound/pci/hda/cs35l41_hda_property.c create mode 100644 sound/pci/hda/cs35l41_hda_property.h diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile index 00d306104484..3b259239c48a 100644 --- a/sound/pci/hda/Makefile +++ b/sound/pci/hda/Makefile @@ -28,7 +28,7 @@ snd-hda-codec-via-objs := patch_via.o snd-hda-codec-hdmi-objs := patch_hdmi.o hda_eld.o # side codecs -snd-hda-scodec-cs35l41-objs := cs35l41_hda.o +snd-hda-scodec-cs35l41-objs := cs35l41_hda.o cs35l41_hda_property.o snd-hda-scodec-cs35l41-i2c-objs := cs35l41_hda_i2c.o snd-hda-scodec-cs35l41-spi-objs := cs35l41_hda_spi.o snd-hda-cs-dsp-ctls-objs := hda_cs_dsp_ctl.o diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c index 98feb5ccd586..6eea7ebc7848 100644 --- a/sound/pci/hda/cs35l41_hda.c +++ b/sound/pci/hda/cs35l41_hda.c @@ -19,6 +19,7 @@ #include "hda_component.h" #include "cs35l41_hda.h" #include "hda_cs_dsp_ctl.h" +#include "cs35l41_hda_property.h" #define CS35L41_FIRMWARE_ROOT "cirrus/" #define CS35L41_PART "cs35l41" @@ -1308,8 +1309,7 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41) return cs35l41_hda_channel_map(cs35l41->dev, 0, NULL, 1, &hw_cfg->spk_pos); } -static int cs35l41_get_speaker_id(struct device *dev, int amp_index, - int num_amps, int fixed_gpio_id) +int cs35l41_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 = -ENODEV; @@ -1363,49 +1363,6 @@ static int cs35l41_get_speaker_id(struct device *dev, int amp_index, return speaker_id; } -/* - * Device CLSA010(0/1) doesn't have _DSD so a gpiod_get by the label reset won't work. - * And devices created by serial-multi-instantiate don't have their device struct - * pointing to the correct fwnode, so acpi_dev must be used here. - * And devm functions expect that the device requesting the resource has the correct - * fwnode. - */ -static int cs35l41_no_acpi_dsd(struct cs35l41_hda *cs35l41, struct device *physdev, int id, - const char *hid) -{ - struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; - - /* check I2C address to assign the index */ - cs35l41->index = id == 0x40 ? 0 : 1; - cs35l41->channel_index = 0; - cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH); - cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 2); - hw_cfg->spk_pos = cs35l41->index; - hw_cfg->gpio2.func = CS35L41_INTERRUPT; - hw_cfg->gpio2.valid = true; - hw_cfg->valid = true; - - if (strncmp(hid, "CLSA0100", 8) == 0) { - hw_cfg->bst_type = CS35L41_EXT_BOOST_NO_VSPK_SWITCH; - } else if (strncmp(hid, "CLSA0101", 8) == 0) { - hw_cfg->bst_type = CS35L41_EXT_BOOST; - hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH; - hw_cfg->gpio1.valid = true; - } else { - /* - * Note: CLSA010(0/1) are special cases which use a slightly different design. - * All other HIDs e.g. CSC3551 require valid ACPI _DSD properties to be supported. - */ - dev_err(cs35l41->dev, "Error: ACPI _DSD Properties are missing for HID %s.\n", hid); - hw_cfg->valid = false; - hw_cfg->gpio1.valid = false; - hw_cfg->gpio2.valid = false; - return -EINVAL; - } - - return 0; -} - static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, int id) { struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; @@ -1431,12 +1388,17 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i sub = NULL; cs35l41->acpi_subsystem_id = sub; + ret = cs35l41_add_dsd_properties(cs35l41, physdev, id, hid); + if (!ret) { + dev_info(cs35l41->dev, "Using extra _DSD properties, bypassing _DSD in ACPI\n"); + goto put_physdev; + } + property = "cirrus,dev-index"; ret = device_property_count_u32(physdev, property); - if (ret <= 0) { - ret = cs35l41_no_acpi_dsd(cs35l41, physdev, id, hid); - goto err_put_physdev; - } + if (ret <= 0) + goto err; + if (ret > ARRAY_SIZE(values)) { ret = -EINVAL; goto err; @@ -1526,7 +1488,10 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i err: dev_err(cs35l41->dev, "Failed property %s: %d\n", property, ret); -err_put_physdev: + hw_cfg->valid = false; + hw_cfg->gpio1.valid = false; + hw_cfg->gpio2.valid = false; +put_physdev: put_device(physdev); return ret; diff --git a/sound/pci/hda/cs35l41_hda.h b/sound/pci/hda/cs35l41_hda.h index bdb35f3be68a..b93bf762976e 100644 --- a/sound/pci/hda/cs35l41_hda.h +++ b/sound/pci/hda/cs35l41_hda.h @@ -83,5 +83,6 @@ extern const struct dev_pm_ops cs35l41_hda_pm_ops; int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int irq, struct regmap *regmap); void cs35l41_hda_remove(struct device *dev); +int cs35l41_get_speaker_id(struct device *dev, int amp_index, int num_amps, int fixed_gpio_id); #endif /*__CS35L41_HDA_H__*/ diff --git a/sound/pci/hda/cs35l41_hda_property.c b/sound/pci/hda/cs35l41_hda_property.c new file mode 100644 index 000000000000..673f23257a09 --- /dev/null +++ b/sound/pci/hda/cs35l41_hda_property.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// CS35L41 ALSA HDA Property driver +// +// Copyright 2023 Cirrus Logic, Inc. +// +// Author: Stefan Binding + +#include +#include +#include "cs35l41_hda_property.h" + +/* + * Device CLSA010(0/1) doesn't have _DSD so a gpiod_get by the label reset won't work. + * And devices created by serial-multi-instantiate don't have their device struct + * pointing to the correct fwnode, so acpi_dev must be used here. + * And devm functions expect that the device requesting the resource has the correct + * fwnode. + */ +static int lenovo_legion_no_acpi(struct cs35l41_hda *cs35l41, struct device *physdev, int id, + const char *hid) +{ + struct cs35l41_hw_cfg *hw_cfg = &cs35l41->hw_cfg; + + /* check I2C address to assign the index */ + cs35l41->index = id == 0x40 ? 0 : 1; + cs35l41->channel_index = 0; + cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH); + cs35l41->speaker_id = cs35l41_get_speaker_id(physdev, 0, 0, 2); + hw_cfg->spk_pos = cs35l41->index; + hw_cfg->gpio2.func = CS35L41_INTERRUPT; + hw_cfg->gpio2.valid = true; + hw_cfg->valid = true; + + if (strcmp(hid, "CLSA0100") == 0) { + hw_cfg->bst_type = CS35L41_EXT_BOOST_NO_VSPK_SWITCH; + } else if (strcmp(hid, "CLSA0101") == 0) { + hw_cfg->bst_type = CS35L41_EXT_BOOST; + hw_cfg->gpio1.func = CS35l41_VSPK_SWITCH; + hw_cfg->gpio1.valid = true; + } + + return 0; +} + +struct cs35l41_prop_model { + const char *hid; + const char *ssid; + int (*add_prop)(struct cs35l41_hda *cs35l41, struct device *physdev, int id, + const char *hid); +}; + +const struct cs35l41_prop_model cs35l41_prop_model_table[] = { + { "CLSA0100", NULL, lenovo_legion_no_acpi }, + { "CLSA0101", NULL, lenovo_legion_no_acpi }, + {} +}; + +int cs35l41_add_dsd_properties(struct cs35l41_hda *cs35l41, struct device *physdev, int id, + const char *hid) +{ + const struct cs35l41_prop_model *model; + + for (model = cs35l41_prop_model_table; model->hid > 0; model++) { + if (!strcmp(model->hid, hid) && + (!model->ssid || + (cs35l41->acpi_subsystem_id && + !strcmp(model->ssid, cs35l41->acpi_subsystem_id)))) + return model->add_prop(cs35l41, physdev, id, hid); + } + + return -ENOENT; +} diff --git a/sound/pci/hda/cs35l41_hda_property.h b/sound/pci/hda/cs35l41_hda_property.h new file mode 100644 index 000000000000..fd834042e2fd --- /dev/null +++ b/sound/pci/hda/cs35l41_hda_property.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * CS35L41 ALSA HDA Property driver + * + * Copyright 2023 Cirrus Logic, Inc. + * + * Author: Stefan Binding + */ + +#ifndef CS35L41_HDA_PROP_H +#define CS35L41_HDA_PROP_H + +#include +#include "cs35l41_hda.h" + +int cs35l41_add_dsd_properties(struct cs35l41_hda *cs35l41, struct device *physdev, int id, + const char *hid); +#endif /* CS35L41_HDA_PROP_H */ From patchwork Tue Nov 21 12:28:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 1866715 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZNwJ6zG9z1yRV for ; Tue, 21 Nov 2023 23:29:04 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1r5Ps8-0004vB-SN; Tue, 21 Nov 2023 12:28:57 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1r5Prt-0004p7-UL for kernel-team@lists.ubuntu.com; Tue, 21 Nov 2023 12:28:42 +0000 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id B95D43F11F for ; Tue, 21 Nov 2023 12:28:41 +0000 (UTC) Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-6cbb6ff734dso1599074b3a.0 for ; Tue, 21 Nov 2023 04:28:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700569720; x=1701174520; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y8ms6BjJ52UG2qHU1VjKTVMXQs6AzGTlTS86xtXmOas=; b=wjKGU1Go0n1uUj5RTYBK9PGYrQahcZU7vYoXQJ/6cjrxyIOBOozme879mW28oRS+5I a+xSI8XPCdojHfOutSX7+FsX/IEkaDzr85c+TY6YkoLGpn4LIzZGQ3k0Qw6jTbGysgRC S/SGrLDG3yn7X8UO4xgnzqGT0kYDUbkOS1SqBmrkwbrdt2S66Zri4RnpveN5gM3AGmFO bzOFoSSDIKz2/cqk59x7jbSOfwNzeFnEIGhwinmAJcf8UAzjdqkcSnQzvha71+XPCE+4 +eOXdu50M22RYgPCHiDEuCuIYYxbZsUIvGd8lZKT2/jILMpFzHndg5xYYLwhISSvpQmK cBJw== X-Gm-Message-State: AOJu0YxtDS5SRg+I5iO3KgSBpjyonnlV716cdAwIpQf1V+FEIOoPvvZw jJSSPkmR7k1k3YJGvCOKlD01LGKs0vg51dBvF2gPJIadR9LeGTVLIgiZDsKar3uyJdEJDJh+YM+ EYVUaAqdRuZ5+nKIVMI7OZ5xdmQJk74v1mxuV+3r2+P3msWiFYQ== X-Received: by 2002:a05:6a20:5483:b0:187:fa62:bb2d with SMTP id i3-20020a056a20548300b00187fa62bb2dmr8917101pzk.36.1700569720194; Tue, 21 Nov 2023 04:28:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6gTtbtUpVKXcMIarysCUJMxl5UY7Gok4paZFNs67Gy4LSZwRcZWVc6yNuBFTXk9QKtS0TqA== X-Received: by 2002:a05:6a20:5483:b0:187:fa62:bb2d with SMTP id i3-20020a056a20548300b00187fa62bb2dmr8917087pzk.36.1700569719778; Tue, 21 Nov 2023 04:28:39 -0800 (PST) Received: from localhost.localdomain (114-36-219-155.dynamic-ip.hinet.net. [114.36.219.155]) by smtp.gmail.com with ESMTPSA id o12-20020a056a00214c00b006c34015a8f2sm8006096pfk.146.2023.11.21.04.28.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 04:28:39 -0800 (PST) From: Chris Chiu To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/6][SRU][M] ALSA: hda: cs35l41: Fix the loop check in cs35l41_add_dsd_properties Date: Tue, 21 Nov 2023 20:28:29 +0800 Message-Id: <20231121122833.11493-3-chris.chiu@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231121122833.11493-1-chris.chiu@canonical.com> References: <20231121122833.11493-1-chris.chiu@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Takashi Iwai BugLink: https://bugs.launchpad.net/bugs/2039151 model->hid is a pointer, and should be rather NULL-checked in the loop of cs35l41_prop_model_table. Fixes: ef4ba63f12b0 ("ALSA: hda: cs35l41: Support systems with missing _DSD properties") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202308160506.8lCEeFDG-lkp@intel.com/ Link: https://lore.kernel.org/r/20230816063525.23009-1-tiwai@suse.de Signed-off-by: Takashi Iwai (cherry picked from commit 409896794380c1dc0d596bbb9255e583a94d9a00) Signed-off-by: Chris Chiu --- sound/pci/hda/cs35l41_hda_property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/pci/hda/cs35l41_hda_property.c b/sound/pci/hda/cs35l41_hda_property.c index 673f23257a09..48dcc3f1ef88 100644 --- a/sound/pci/hda/cs35l41_hda_property.c +++ b/sound/pci/hda/cs35l41_hda_property.c @@ -61,7 +61,7 @@ int cs35l41_add_dsd_properties(struct cs35l41_hda *cs35l41, struct device *physd { const struct cs35l41_prop_model *model; - for (model = cs35l41_prop_model_table; model->hid > 0; model++) { + for (model = cs35l41_prop_model_table; model->hid; model++) { if (!strcmp(model->hid, hid) && (!model->ssid || (cs35l41->acpi_subsystem_id && From patchwork Tue Nov 21 12:28:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 1866716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZNwQ6rMdz1yRV for ; Tue, 21 Nov 2023 23:29:10 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1r5PsE-00050h-BN; Tue, 21 Nov 2023 12:29:02 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1r5Prv-0004pL-VC for kernel-team@lists.ubuntu.com; Tue, 21 Nov 2023 12:28:44 +0000 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 57C6A3F0B1 for ; Tue, 21 Nov 2023 12:28:43 +0000 (UTC) Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-6c334d2fd40so8014337b3a.2 for ; Tue, 21 Nov 2023 04:28:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700569722; x=1701174522; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zzAxEJohxSdHBurTi9gGpmeRluERPXqc5Yvi/xFP9ao=; b=oifAHqcyh0iQKPGABjE8gARjrOXqVRvaGmfI34+3BVUNYLjJvMudLvvkZg9J6WQK+D ikXuJz1kqcDN+b0ML3Y2H57QgJRY5O0t4vDAh/CbgwpWDa3oh14EWzLZeqpg31Ulwakn H1zsa8YHT0swlndT7Y9U8bEb70k8Ti49EjTLuGjUQPs6J1+fBFGD5wu6rPXf/AUMs5Kb 6c2Wcf44W/yCULUBu/SRiBTlii9krFCSbw+9ead6jJFcmydwf/x3sa8tK9URzWjAVnpz GVwA3FUdvMEdXt6rKk3UHXQ9NITSGXGJFGsm73gEefiuECIO5fNueDFnfqZNGmDoTB5j iZpA== X-Gm-Message-State: AOJu0YyS+g1tjFt5+fO9rM1rRy1roieSYTaH1V2dvd/SJJ2clSn8wlzs FiCtOaci7uSVzxifj1HDoFoWOoa9e+PxcmidwYpr/5hyLH2DuFyn9Q1M8xNCqChZ8JLsX2CaTxT tYULspVRNCJny5pU59L0CWk0DKidsqG4xoWkxdVDBHWH4E1cT8Q== X-Received: by 2002:a05:6a00:1399:b0:6cb:6cac:71d7 with SMTP id t25-20020a056a00139900b006cb6cac71d7mr11080015pfg.31.1700569721596; Tue, 21 Nov 2023 04:28:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzgynFADLu1+0JS6T5Aai7MI0UYcGJrCWFZmXuElZM/uDJjmMrPejYwe9ssN0jg7dR5+52Qw== X-Received: by 2002:a05:6a00:1399:b0:6cb:6cac:71d7 with SMTP id t25-20020a056a00139900b006cb6cac71d7mr11079994pfg.31.1700569721223; Tue, 21 Nov 2023 04:28:41 -0800 (PST) Received: from localhost.localdomain (114-36-219-155.dynamic-ip.hinet.net. [114.36.219.155]) by smtp.gmail.com with ESMTPSA id o12-20020a056a00214c00b006c34015a8f2sm8006096pfk.146.2023.11.21.04.28.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 04:28:40 -0800 (PST) From: Chris Chiu To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/6][SRU][M] ALSA: hda: cs35l41: Add notification support into component binding Date: Tue, 21 Nov 2023 20:28:30 +0800 Message-Id: <20231121122833.11493-4-chris.chiu@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231121122833.11493-1-chris.chiu@canonical.com> References: <20231121122833.11493-1-chris.chiu@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Stefan Binding BugLink: https://bugs.launchpad.net/bugs/2039151 Some systems support a notification from ACPI, which can be used for different things. Only one handler can be registered for the acpi notification, but all amps need to receive that notification, we can register a single handler inside the component master, so that it can then notify through the component framework. This is required to support mute notifications from ACPI. Signed-off-by: Stefan Binding Link: https://lore.kernel.org/r/20230921162849.1988124-2-sbinding@opensource.cirrus.com Signed-off-by: Takashi Iwai (cherry picked from commit 502629a75566b5cb409c118125d38102e5edc8f6) Signed-off-by: Chris Chiu --- sound/pci/hda/hda_component.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sound/pci/hda/hda_component.h b/sound/pci/hda/hda_component.h index f170aec967c1..bbd6f0ed16c1 100644 --- a/sound/pci/hda/hda_component.h +++ b/sound/pci/hda/hda_component.h @@ -6,6 +6,7 @@ * Cirrus Logic International Semiconductor Ltd. */ +#include #include #define HDA_MAX_COMPONENTS 4 @@ -15,6 +16,9 @@ struct hda_component { struct device *dev; char name[HDA_MAX_NAME_SIZE]; struct hda_codec *codec; + struct acpi_device *adev; + bool acpi_notifications_supported; + void (*acpi_notify)(acpi_handle handle, u32 event, struct device *dev); void (*pre_playback_hook)(struct device *dev, int action); void (*playback_hook)(struct device *dev, int action); void (*post_playback_hook)(struct device *dev, int action); From patchwork Tue Nov 21 12:28:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 1866714 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZNwB52ccz1ySW for ; Tue, 21 Nov 2023 23:28:57 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1r5Ps1-0004qf-NW; Tue, 21 Nov 2023 12:28:49 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1r5Prw-0004pS-Td for kernel-team@lists.ubuntu.com; Tue, 21 Nov 2023 12:28:45 +0000 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 7957C3F6E7 for ; Tue, 21 Nov 2023 12:28:44 +0000 (UTC) Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-6b5cac99d3dso8450859b3a.2 for ; Tue, 21 Nov 2023 04:28:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700569723; x=1701174523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ehUWyNwkoisKjOWc8HvnmMeIOJEcjUE/6JpZXs6f4Ek=; b=mLPxTMjOB3vvcnXtDkK/0HD1Vl5BdBCWHNSMwaapc81VgHqmuSpNxFnf5k9NigN5sN u6RxklZlJW3NLhliMPxGniQTEOJBoroD/TokuCLBDdS0uuDG4I2LJwkNCFayI2ESyjQH 2toq1/+4x6xmJizcRNlQKgqbGbHFiOCoAtj5zxxKz1vwwbf0nCkqYbWS+aM9dE5PboNw lyQ+QGA2U7JciG/nNJdhWmC5WoMVvXZ1zDm8O5Woj5ynGXONmw/ck1vCAvum3B9kkAbW gTaPSYJf+RjM+U+h652G4e8AZj6Ya3NyWUsPULkrxNAqaJcfuuUPZLQkhlM0nsTyNcQP qw3Q== X-Gm-Message-State: AOJu0YwfAB6ncErQzBP3OZ36/ZjPRluU3jwDJIeOK23FL4Po8/15Ctoc 1Y2vFSMbcpOWjDao67DkGxrqnLa4zScxGpVoQsy5pflM17GI2ktoujeIPS3z7z+4Z5xk21pZyuk Wp1/babIUe04DSkEEls9tuABWdT1KR1LKv6pjd3lh4kPrc6UGxg== X-Received: by 2002:a05:6a00:3a09:b0:6cb:a1a7:ebcb with SMTP id fj9-20020a056a003a0900b006cba1a7ebcbmr6945085pfb.24.1700569722850; Tue, 21 Nov 2023 04:28:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/a6YC+zzNO5SqFk0UkfN/LTaIyoyec1/c4r8sj7KdX7Q0CyuTkNjrsDIeH50VZ7Hb//+22Q== X-Received: by 2002:a05:6a00:3a09:b0:6cb:a1a7:ebcb with SMTP id fj9-20020a056a003a0900b006cba1a7ebcbmr6945062pfb.24.1700569722425; Tue, 21 Nov 2023 04:28:42 -0800 (PST) Received: from localhost.localdomain (114-36-219-155.dynamic-ip.hinet.net. [114.36.219.155]) by smtp.gmail.com with ESMTPSA id o12-20020a056a00214c00b006c34015a8f2sm8006096pfk.146.2023.11.21.04.28.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 04:28:42 -0800 (PST) From: Chris Chiu To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/6][SRU][M] ALSA: hda/realtek: Support ACPI Notification framework via component binding Date: Tue, 21 Nov 2023 20:28:31 +0800 Message-Id: <20231121122833.11493-5-chris.chiu@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231121122833.11493-1-chris.chiu@canonical.com> References: <20231121122833.11493-1-chris.chiu@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Stefan Binding BugLink: https://bugs.launchpad.net/bugs/2039151 For systems which have support for ACPI notifications, add a mechanism to register a handler for ACPI notifications and then call the acpi_notify api on the bound components. Registering a handler in the Realtek HDA driver, allows a single handler to be registered, which then calls into all the components, rather than attempting to register the same handler multiple times, once for each component. Signed-off-by: Stefan Binding Link: https://lore.kernel.org/r/20230921162849.1988124-3-sbinding@opensource.cirrus.com Signed-off-by: Takashi Iwai (cherry picked from commit 7ce669334c55c50ecc2909c42275a3eec0039799) Signed-off-by: Chris Chiu --- sound/pci/hda/patch_realtek.c | 83 ++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index c79d25ca8d16..d93deb78e3f5 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -10,6 +10,7 @@ * Jonathan Woithe */ +#include #include #include #include @@ -6688,12 +6689,91 @@ static void alc287_fixup_legion_15imhg05_speakers(struct hda_codec *codec, } } +#ifdef CONFIG_ACPI +static void comp_acpi_device_notify(acpi_handle handle, u32 event, void *data) +{ + struct hda_codec *cdc = data; + struct alc_spec *spec = cdc->spec; + int i; + + codec_info(cdc, "ACPI Notification %d\n", event); + + for (i = 0; i < HDA_MAX_COMPONENTS; i++) { + if (spec->comps[i].dev && spec->comps[i].acpi_notify) + spec->comps[i].acpi_notify(acpi_device_handle(spec->comps[i].adev), event, + spec->comps[i].dev); + } +} + +static int comp_bind_acpi(struct device *dev) +{ + struct hda_codec *cdc = dev_to_hda_codec(dev); + struct alc_spec *spec = cdc->spec; + bool support_notifications = false; + struct acpi_device *adev; + int ret; + int i; + + adev = spec->comps[0].adev; + if (!acpi_device_handle(adev)) + return 0; + + for (i = 0; i < HDA_MAX_COMPONENTS; i++) + support_notifications = support_notifications || + spec->comps[i].acpi_notifications_supported; + + if (support_notifications) { + ret = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, + comp_acpi_device_notify, cdc); + if (ret < 0) { + codec_warn(cdc, "Failed to install notify handler: %d\n", ret); + return 0; + } + + codec_dbg(cdc, "Notify handler installed\n"); + } + + return 0; +} + +static void comp_unbind_acpi(struct device *dev) +{ + struct hda_codec *cdc = dev_to_hda_codec(dev); + struct alc_spec *spec = cdc->spec; + struct acpi_device *adev; + int ret; + + adev = spec->comps[0].adev; + if (!acpi_device_handle(adev)) + return; + + ret = acpi_remove_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, + comp_acpi_device_notify); + if (ret < 0) + codec_warn(cdc, "Failed to uninstall notify handler: %d\n", ret); +} +#else +static int comp_bind_acpi(struct device *dev) +{ + return 0; +} + +static void comp_unbind_acpi(struct device *dev) +{ +} +#endif + static int comp_bind(struct device *dev) { struct hda_codec *cdc = dev_to_hda_codec(dev); struct alc_spec *spec = cdc->spec; + int ret; + + ret = component_bind_all(dev, spec->comps); + if (ret) + return ret; - return component_bind_all(dev, spec->comps); + return comp_bind_acpi(dev); } static void comp_unbind(struct device *dev) @@ -6701,6 +6781,7 @@ static void comp_unbind(struct device *dev) struct hda_codec *cdc = dev_to_hda_codec(dev); struct alc_spec *spec = cdc->spec; + comp_unbind_acpi(dev); component_unbind_all(dev, spec->comps); } From patchwork Tue Nov 21 12:28:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 1866717 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZNwZ47BHz1yRV for ; Tue, 21 Nov 2023 23:29:18 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1r5PsK-00055R-A7; Tue, 21 Nov 2023 12:29:08 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1r5Pry-0004q4-8y for kernel-team@lists.ubuntu.com; Tue, 21 Nov 2023 12:28:46 +0000 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C7B043F204 for ; Tue, 21 Nov 2023 12:28:45 +0000 (UTC) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-5be3799791fso7762255a12.3 for ; Tue, 21 Nov 2023 04:28:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700569724; x=1701174524; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1gLDqUjOLk1H80wIH6RtxIlgIJAv/grlM4o1rlNDXqs=; b=uxXkqKx1GyQ8d5UhAtqQKk8SL2J3cobsniTsxa/pAmilPCOyMjk1okzxTy7VhZDTnq r82fP8IezsKROm6Q+63ztr9VtSbFtXbBlYkcBsPWUIpTTcPHE0J1RbQ+gybbQT5fb4Li HF2vaSTVkSM3y8Ab4uDym003/jQmNMzKh8+OIeXDrVUAVMko3NyBueBCBN0bM8QeBfMd SyleDx+gxFmWA1D+BL7Gc5hRy+YkFG9es4CSyQ3K5YSxpGXDxDxtBMmgIBt10R1D2TS6 eRyVhsdYWr+XHK+vKgYoZ4sMcP/aXyVU0iwpNdYVrusd0Eg7cZ4Dy+ywNCWADCyN9+WS HHOQ== X-Gm-Message-State: AOJu0YwuaKDD/dGUgNSk1I6IfY4c7CPLbW8+JN4lFIjDqSzhE2lZ/g4m 3vrvVvTV81d2xzeFWEh0K6tIQNcT4GUyadKgFkj6Aj3M0yGblqZSxUNOscbhfinkCvoQk8JiEWY IxNnD3sSivrEWamigndEcG33WgnagXbpoCR7yd6hDkdUtBC6Ixw== X-Received: by 2002:a05:6a21:340a:b0:189:c0d9:ccfe with SMTP id yn10-20020a056a21340a00b00189c0d9ccfemr13780503pzb.50.1700569724105; Tue, 21 Nov 2023 04:28:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPlp3i//0XcudD3CiETIGAnf6Pl+vzpc77UDkgOnXyJwtIRh+sHY/hXlww5tsKX+rNlUgQ4A== X-Received: by 2002:a05:6a21:340a:b0:189:c0d9:ccfe with SMTP id yn10-20020a056a21340a00b00189c0d9ccfemr13780486pzb.50.1700569723595; Tue, 21 Nov 2023 04:28:43 -0800 (PST) Received: from localhost.localdomain (114-36-219-155.dynamic-ip.hinet.net. [114.36.219.155]) by smtp.gmail.com with ESMTPSA id o12-20020a056a00214c00b006c34015a8f2sm8006096pfk.146.2023.11.21.04.28.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 04:28:43 -0800 (PST) From: Chris Chiu To: kernel-team@lists.ubuntu.com Subject: [PATCH 5/6][SRU][M] ALSA: hda: cs35l41: Support mute notifications for CS35L41 HDA Date: Tue, 21 Nov 2023 20:28:32 +0800 Message-Id: <20231121122833.11493-6-chris.chiu@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231121122833.11493-1-chris.chiu@canonical.com> References: <20231121122833.11493-1-chris.chiu@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Stefan Binding BugLink: https://bugs.launchpad.net/bugs/2039151 Some laptops require a hardware based mute system, where when a hotkey is pressed, it forces the amp to be muted. For CS35L41, when the hotkey is pressed, an acpi notification is sent to the CS35L41 Device Node. The driver needs to handle this notification and call a _DSM function to retrieve the mute state. Since the amp is only muted during playback, the driver will only mute or unmute if playback is occurring, otherwise it will save the mute state for when playback starts. This uses the ACPI Notification mechanism, where a handler has been registered in the component master, which notifies each amp through the component binding. Signed-off-by: Stefan Binding Link: https://lore.kernel.org/r/20230921162849.1988124-4-sbinding@opensource.cirrus.com Signed-off-by: Takashi Iwai (cherry picked from commit 447106e92a0c86c332d40710436f38f64c322cd6) Signed-off-by: Chris Chiu --- sound/pci/hda/cs35l41_hda.c | 104 +++++++++++++++++++++++++++++++----- sound/pci/hda/cs35l41_hda.h | 3 ++ 2 files changed, 94 insertions(+), 13 deletions(-) diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c index 6eea7ebc7848..55c32896125b 100644 --- a/sound/pci/hda/cs35l41_hda.c +++ b/sound/pci/hda/cs35l41_hda.c @@ -33,6 +33,9 @@ #define CAL_AMBIENT_DSP_CTL_NAME "CAL_AMBIENT" #define CAL_DSP_CTL_TYPE 5 #define CAL_DSP_CTL_ALG 205 +#define CS35L41_UUID "50d90cdc-3de4-4f18-b528-c7fe3b71f40d" +#define CS35L41_DSM_GET_MUTE 5 +#define CS35L41_NOTIFY_EVENT 0x91 static bool firmware_autostart = 1; module_param(firmware_autostart, bool, 0444); @@ -520,6 +523,31 @@ static void cs35l41_hda_play_start(struct device *dev) } +static void cs35l41_mute(struct device *dev, bool mute) +{ + struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); + struct regmap *reg = cs35l41->regmap; + + dev_dbg(dev, "Mute(%d:%d) Playback Started: %d\n", mute, cs35l41->mute_override, + cs35l41->playback_started); + + if (cs35l41->playback_started) { + if (mute || cs35l41->mute_override) { + dev_dbg(dev, "Muting\n"); + regmap_multi_reg_write(reg, cs35l41_hda_mute, ARRAY_SIZE(cs35l41_hda_mute)); + } else { + dev_dbg(dev, "Unmuting\n"); + if (cs35l41->firmware_running) { + regmap_multi_reg_write(reg, cs35l41_hda_unmute_dsp, + ARRAY_SIZE(cs35l41_hda_unmute_dsp)); + } else { + regmap_multi_reg_write(reg, cs35l41_hda_unmute, + ARRAY_SIZE(cs35l41_hda_unmute)); + } + } + } +} + static void cs35l41_hda_play_done(struct device *dev) { struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); @@ -529,13 +557,7 @@ static void cs35l41_hda_play_done(struct device *dev) cs35l41_global_enable(dev, reg, cs35l41->hw_cfg.bst_type, 1, NULL, cs35l41->firmware_running); - if (cs35l41->firmware_running) { - regmap_multi_reg_write(reg, cs35l41_hda_unmute_dsp, - ARRAY_SIZE(cs35l41_hda_unmute_dsp)); - } else { - regmap_multi_reg_write(reg, cs35l41_hda_unmute, - ARRAY_SIZE(cs35l41_hda_unmute)); - } + cs35l41_mute(dev, false); } static void cs35l41_hda_pause_start(struct device *dev) @@ -545,7 +567,7 @@ static void cs35l41_hda_pause_start(struct device *dev) dev_dbg(dev, "Pause (Start)\n"); - regmap_multi_reg_write(reg, cs35l41_hda_mute, ARRAY_SIZE(cs35l41_hda_mute)); + cs35l41_mute(dev, true); cs35l41_global_enable(dev, reg, cs35l41->hw_cfg.bst_type, 0, NULL, cs35l41->firmware_running); } @@ -1073,6 +1095,53 @@ static int cs35l41_create_controls(struct cs35l41_hda *cs35l41) return 0; } +static bool cs35l41_dsm_supported(acpi_handle handle, unsigned int commands) +{ + guid_t guid; + + guid_parse(CS35L41_UUID, &guid); + + return acpi_check_dsm(handle, &guid, 0, BIT(commands)); +} + +static int cs35l41_get_acpi_mute_state(struct cs35l41_hda *cs35l41, acpi_handle handle) +{ + guid_t guid; + union acpi_object *ret; + int mute = -ENODEV; + + guid_parse(CS35L41_UUID, &guid); + + if (cs35l41_dsm_supported(handle, CS35L41_DSM_GET_MUTE)) { + ret = acpi_evaluate_dsm(handle, &guid, 0, CS35L41_DSM_GET_MUTE, NULL); + mute = *ret->buffer.pointer; + dev_dbg(cs35l41->dev, "CS35L41_DSM_GET_MUTE: %d\n", mute); + } + + dev_dbg(cs35l41->dev, "%s: %d\n", __func__, mute); + + return mute; +} + +static void cs35l41_acpi_device_notify(acpi_handle handle, u32 event, struct device *dev) +{ + struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); + int mute; + + if (event != CS35L41_NOTIFY_EVENT) + return; + + mute = cs35l41_get_acpi_mute_state(cs35l41, handle); + if (mute < 0) { + dev_warn(cs35l41->dev, "Unable to retrieve mute state: %d\n", mute); + return; + } + + dev_dbg(cs35l41->dev, "Requesting mute value: %d\n", mute); + cs35l41->mute_override = (mute > 0); + cs35l41_mute(cs35l41->dev, cs35l41->mute_override); +} + static int cs35l41_hda_bind(struct device *dev, struct device *master, void *master_data) { struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev); @@ -1114,6 +1183,14 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas comps->playback_hook = cs35l41_hda_playback_hook; comps->pre_playback_hook = cs35l41_hda_pre_playback_hook; comps->post_playback_hook = cs35l41_hda_post_playback_hook; + comps->acpi_notify = cs35l41_acpi_device_notify; + comps->adev = cs35l41->dacpi; + + comps->acpi_notifications_supported = cs35l41_dsm_supported(acpi_device_handle(comps->adev), + CS35L41_DSM_GET_MUTE); + + cs35l41->mute_override = cs35l41_get_acpi_mute_state(cs35l41, + acpi_device_handle(cs35l41->dacpi)) > 0; mutex_unlock(&cs35l41->fw_mutex); @@ -1380,8 +1457,8 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i return -ENODEV; } + cs35l41->dacpi = adev; physdev = get_device(acpi_get_first_physical_node(adev)); - acpi_dev_put(adev); sub = acpi_get_subsystem_id(ACPI_HANDLE(physdev)); if (IS_ERR(sub)) @@ -1491,6 +1568,7 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i hw_cfg->valid = false; hw_cfg->gpio1.valid = false; hw_cfg->gpio2.valid = false; + acpi_dev_put(cs35l41->dacpi); put_physdev: put_device(physdev); @@ -1594,10 +1672,7 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i if (ret) goto err; - ret = regmap_multi_reg_write(cs35l41->regmap, cs35l41_hda_mute, - ARRAY_SIZE(cs35l41_hda_mute)); - if (ret) - goto err; + cs35l41_mute(cs35l41->dev, true); INIT_WORK(&cs35l41->fw_load_work, cs35l41_fw_load_work); mutex_init(&cs35l41->fw_mutex); @@ -1634,6 +1709,7 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i if (cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type)) gpiod_set_value_cansleep(cs35l41->reset_gpio, 0); gpiod_put(cs35l41->reset_gpio); + acpi_dev_put(cs35l41->dacpi); kfree(cs35l41->acpi_subsystem_id); return ret; @@ -1652,6 +1728,8 @@ void cs35l41_hda_remove(struct device *dev) component_del(cs35l41->dev, &cs35l41_hda_comp_ops); + acpi_dev_put(cs35l41->dacpi); + pm_runtime_put_noidle(cs35l41->dev); if (cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type)) diff --git a/sound/pci/hda/cs35l41_hda.h b/sound/pci/hda/cs35l41_hda.h index b93bf762976e..ce3f2bb6ffd0 100644 --- a/sound/pci/hda/cs35l41_hda.h +++ b/sound/pci/hda/cs35l41_hda.h @@ -10,6 +10,7 @@ #ifndef __CS35L41_HDA_H__ #define __CS35L41_HDA_H__ +#include #include #include #include @@ -70,6 +71,8 @@ struct cs35l41_hda { bool halo_initialized; bool playback_started; struct cs_dsp cs_dsp; + struct acpi_device *dacpi; + bool mute_override; }; enum halo_state { From patchwork Tue Nov 21 12:28:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 1866718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZNwh3GT9z1yRV for ; Tue, 21 Nov 2023 23:29:24 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1r5PsS-0005D4-VI; Tue, 21 Nov 2023 12:29:17 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1r5Prz-0004qd-6w for kernel-team@lists.ubuntu.com; Tue, 21 Nov 2023 12:28:48 +0000 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id DB4303F6E7 for ; Tue, 21 Nov 2023 12:28:46 +0000 (UTC) Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-6c0362a50bbso7376798b3a.2 for ; Tue, 21 Nov 2023 04:28:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700569725; x=1701174525; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=er4RVSTbLBukgfq1PtOO5y5RgGqsA0Kf88Fcnp0W8Ts=; b=Feu5zQZhelQ0CBlyQacsEy6StcJywPAMOKNYmOHO6x3kzMf5l0Mb0NCwu1dk2kZhGC j1Q5Jq9LEX5Ffd3AepnxMll4V/pqe3AYjAsSA0qXBWQHM/5pMFFV/MeaNRHn8gEh3Hs+ c+69O/odEhOZHPQkipkv/xqulkEPmUQ3//o6W+4FwoXdwj2+j4UXG0PZ3p2hmDl8p/6O 6OE5bh60gdg7sCQ4irWd1QMQxJ8DHNFBWeMOD30gkqShDkwv9NIYOVVlUT59nYZl+h0k LxtkPloPDZLdK/TZz3xpyl1ZBOOnllU2R71XnC5DRlW2dyt3udoIY8KrTZWXy8rxw47D krfQ== X-Gm-Message-State: AOJu0YzsXl5/qwgnBOp5JHEhfuN0n4BRwYTSU65UtlMZuEbdYv/6Vq+z rIOM14xTP/g9IrFRZpOKixhTwjGA6RgEd9oLyruInGqPihJ3VbvvFNRAsGc3sGRHSlwU/prn71F RW0NDAemSfDeNew9yLN4BT496OZkdtIlPPkmSqrlSgdLTpVUWlQ== X-Received: by 2002:a05:6a00:887:b0:6be:287d:46d6 with SMTP id q7-20020a056a00088700b006be287d46d6mr9693747pfj.33.1700569725167; Tue, 21 Nov 2023 04:28:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFejgsaD4AyVhEZx5F7Zyln8naKRU7KlsucCCttDzjrk3DB62fJtcIfrUNrzpu9+ycsuNtZFA== X-Received: by 2002:a05:6a00:887:b0:6be:287d:46d6 with SMTP id q7-20020a056a00088700b006be287d46d6mr9693724pfj.33.1700569724757; Tue, 21 Nov 2023 04:28:44 -0800 (PST) Received: from localhost.localdomain (114-36-219-155.dynamic-ip.hinet.net. [114.36.219.155]) by smtp.gmail.com with ESMTPSA id o12-20020a056a00214c00b006c34015a8f2sm8006096pfk.146.2023.11.21.04.28.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 04:28:44 -0800 (PST) From: Chris Chiu To: kernel-team@lists.ubuntu.com Subject: [PATCH 6/6][SRU][M] ALSA: hda: cs35l41: Add read-only ALSA control for forced mute Date: Tue, 21 Nov 2023 20:28:33 +0800 Message-Id: <20231121122833.11493-7-chris.chiu@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231121122833.11493-1-chris.chiu@canonical.com> References: <20231121122833.11493-1-chris.chiu@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Stefan Binding BugLink: https://bugs.launchpad.net/bugs/2039151 When the CS35L41 amp is requested to mute using the ACPI notification mechanism, userspace is not notified that the amp is muted. To allow userspace to know about the mute, add an ALSA control which tracks the forced mute override. This control does not track the overall mute state of the amp, since the amp is only unmuted during playback anyway, instead it tracks the mute override request from the ACPI notification. Signed-off-by: Stefan Binding Link: https://lore.kernel.org/r/20230921162849.1988124-5-sbinding@opensource.cirrus.com Signed-off-by: Takashi Iwai (cherry picked from commit 4c870513fbb02b842408b840cf68ea8fe09ed82e) Signed-off-by: Chris Chiu --- sound/pci/hda/cs35l41_hda.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c index 55c32896125b..d13c45b5748b 100644 --- a/sound/pci/hda/cs35l41_hda.c +++ b/sound/pci/hda/cs35l41_hda.c @@ -972,6 +972,15 @@ static int cs35l41_fw_load_ctl_get(struct snd_kcontrol *kcontrol, return 0; } +static int cs35l41_mute_override_ctl_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct cs35l41_hda *cs35l41 = snd_kcontrol_chip(kcontrol); + + ucontrol->value.integer.value[0] = cs35l41->mute_override; + return 0; +} + static void cs35l41_fw_load_work(struct work_struct *work) { struct cs35l41_hda *cs35l41 = container_of(work, struct cs35l41_hda, fw_load_work); @@ -1055,6 +1064,7 @@ static int cs35l41_create_controls(struct cs35l41_hda *cs35l41) { char fw_type_ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; char fw_load_ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; + char mute_override_ctl_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; struct snd_kcontrol_new fw_type_ctl = { .name = fw_type_ctl_name, .iface = SNDRV_CTL_ELEM_IFACE_CARD, @@ -1069,12 +1079,21 @@ static int cs35l41_create_controls(struct cs35l41_hda *cs35l41) .get = cs35l41_fw_load_ctl_get, .put = cs35l41_fw_load_ctl_put, }; + struct snd_kcontrol_new mute_override_ctl = { + .name = mute_override_ctl_name, + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .info = snd_ctl_boolean_mono_info, + .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, + .get = cs35l41_mute_override_ctl_get, + }; int ret; scnprintf(fw_type_ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s DSP1 Firmware Type", cs35l41->amp_name); scnprintf(fw_load_ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s DSP1 Firmware Load", cs35l41->amp_name); + scnprintf(mute_override_ctl_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s Forced Mute Status", + cs35l41->amp_name); ret = snd_ctl_add(cs35l41->codec->card, snd_ctl_new1(&fw_type_ctl, cs35l41)); if (ret) { @@ -1092,6 +1111,15 @@ static int cs35l41_create_controls(struct cs35l41_hda *cs35l41) dev_dbg(cs35l41->dev, "Added Control %s\n", fw_load_ctl.name); + ret = snd_ctl_add(cs35l41->codec->card, snd_ctl_new1(&mute_override_ctl, cs35l41)); + if (ret) { + dev_err(cs35l41->dev, "Failed to add KControl %s = %d\n", mute_override_ctl.name, + ret); + return ret; + } + + dev_dbg(cs35l41->dev, "Added Control %s\n", mute_override_ctl.name); + return 0; }