ASoC: soc-card: Add storage for PCI SSID
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Tue, 12 Sep 2023 16:32:04 +0000 (17:32 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 28 Nov 2023 17:06:58 +0000 (17:06 +0000)
[ Upstream commit 47f56e38a199bd45514b8e0142399cba4feeaf1a ]

Add members to struct snd_soc_card to store the PCI subsystem ID (SSID)
of the soundcard.

The PCI specification provides two registers to store a vendor-specific
SSID that can be read by drivers to uniquely identify a particular
"soundcard". This is defined in the PCI specification to distinguish
products that use the same silicon (and therefore have the same silicon
ID) so that product-specific differences can be applied.

PCI only defines 0xFFFF as an invalid value. 0x0000 is not defined as
invalid. So the usual pattern of zero-filling the struct and then
assuming a zero value unset will not work. A flag is included to
indicate when the SSID information has been filled in.

Unlike DMI information, which has a free-format entirely up to the vendor,
the PCI SSID has a strictly defined format and a registry of vendor IDs.

It is usual in Windows drivers that the SSID is used as the sole identifier
of the specific end-product and the Windows driver contains tables mapping
that to information about the hardware setup, rather than using ACPI
properties.

This SSID is important information for ASoC components that need to apply
hardware-specific configuration on PCI-based systems.

As the SSID is a generic part of the PCI specification and is treated as
identifying the "soundcard", it is reasonable to include this information
in struct snd_soc_card, instead of components inventing their own custom
ways to pass this information around.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20230912163207.3498161-2-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/sound/soc-card.h
include/sound/soc.h

index 9d31a5c0db33c2ff36a18b8629430c218884e889..40d3023cf0d16aaaf9ed6e8bd351493c27264cdf 100644 (file)
@@ -44,6 +44,43 @@ int snd_soc_card_add_dai_link(struct snd_soc_card *card,
 void snd_soc_card_remove_dai_link(struct snd_soc_card *card,
                                  struct snd_soc_dai_link *dai_link);
 
+#ifdef CONFIG_PCI
+static inline void snd_soc_card_set_pci_ssid(struct snd_soc_card *card,
+                                            unsigned short vendor,
+                                            unsigned short device)
+{
+       card->pci_subsystem_vendor = vendor;
+       card->pci_subsystem_device = device;
+       card->pci_subsystem_set = true;
+}
+
+static inline int snd_soc_card_get_pci_ssid(struct snd_soc_card *card,
+                                           unsigned short *vendor,
+                                           unsigned short *device)
+{
+       if (!card->pci_subsystem_set)
+               return -ENOENT;
+
+       *vendor = card->pci_subsystem_vendor;
+       *device = card->pci_subsystem_device;
+
+       return 0;
+}
+#else /* !CONFIG_PCI */
+static inline void snd_soc_card_set_pci_ssid(struct snd_soc_card *card,
+                                            unsigned short vendor,
+                                            unsigned short device)
+{
+}
+
+static inline int snd_soc_card_get_pci_ssid(struct snd_soc_card *card,
+                                           unsigned short *vendor,
+                                           unsigned short *device)
+{
+       return -ENOENT;
+}
+#endif /* CONFIG_PCI */
+
 /* device driver data */
 static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
                                            void *data)
index 37bbfc8b45cb28b9033c823a1db64565e320d4c1..108617cea9c6765b416748674bcc04b917332dec 100644 (file)
@@ -911,6 +911,17 @@ struct snd_soc_card {
 #ifdef CONFIG_DMI
        char dmi_longname[80];
 #endif /* CONFIG_DMI */
+
+#ifdef CONFIG_PCI
+       /*
+        * PCI does not define 0 as invalid, so pci_subsystem_set indicates
+        * whether a value has been written to these fields.
+        */
+       unsigned short pci_subsystem_vendor;
+       unsigned short pci_subsystem_device;
+       bool pci_subsystem_set;
+#endif /* CONFIG_PCI */
+
        char topology_shortname[32];
 
        struct device *dev;