Skip to contentSkip to conversation

MFD/ASoC: Add support for Intel Bay Trail boards with WM5102 codec

PATCH Superseded Hans de Goede 4 participants 15 messages Jan 17, 2021 – Jan 20, 2021

Subsystems (5)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover MFD/ASoC: Add support for Intel Bay Trail boards with WM5102 codec

Hi All,

Here is v3 of my series to add support for Intel Bay Trail based devices which use a WM5102 codec for audio output/input. New in v3 is that the compile error when CONFIG_ACPI is unset should be gone. Everything else is the same as in v2, see the cover-letter of v2 below:

This was developed and tested on a Lenovo Yoga Tablet 1051L.

The biggest difference from v1 is that, based on all the discussions about the jack-detect stuff, I've decided to split this into 2 series. One series adding the basic support for this setup, which is this series.

And a second series which reworks the extcon driver into an arizona-jackdet library and then modifies the codec drivers to use that directly, replacing the old separate extcon child-device and extcon-driver.

The are 2 reasons for the split:

1. With the new jack-det rework, the series really address 2 separate (but related) enhancements.

2. I expect this series to be ready for merging, while the jack-det stuff likely will need a couple more revisions.

Other then the split there are some minor changes addressing various review comments, see the individual patch changelogs.

The MFD and ASoC parts can be merged independent from each-other (both must be merged to get working sound on these boards, but that is only a runtime dependency and a part missing won't have any bad side-effects). Or the entire series could be merged through the MFD tree if people prefer that.

Regards,

Hans

#1 lore raw

PATCH v3 1/5 mfd: arizona: Add MODULE_SOFTDEP("pre: arizona_ldo1")

The (shared) probing code of the arizona-i2c and arizona-spi modules takes the following steps during init:

1. Call mfd_add_devices() for a set of early child-devices, this includes the arizona_ldo1 device which provides one of the core-regulators.

2. Bulk enable the core-regulators.

3. Read the device id.

4. Call mfd_add_devices() for the other child-devices.

This sequence depends on 1. leading to not only the child-device being created, but also the driver for the child-device binding to it and registering its regulator.

This requires the arizona_ldo1 driver to be loaded before the shared probing code runs. Add a softdep for this to both modules to ensure that this requirement is met.

Note this mirrors the existing MODULE_SOFTDEP("pre: wm8994_regulator") in the wm8994 code, which has a similar init sequence.

---
 drivers/mfd/arizona-i2c.c | 1 +
 drivers/mfd/arizona-spi.c | 1 +
 2 files changed, 2 insertions(+)
drivers/mfd/arizona-i2c.c +1 -0
index 4b58e3ad6eb6..2a4a3a164d0a 100644
@@ -115,6 +115,7 @@ static struct i2c_driver arizona_i2c_driver = {
 
 module_i2c_driver(arizona_i2c_driver);
 
+MODULE_SOFTDEP("pre: arizona_ldo1");
 MODULE_DESCRIPTION("Arizona I2C bus interface");
 MODULE_AUTHOR("Mark Brown <[email protected]>");
 MODULE_LICENSE("GPL");
drivers/mfd/arizona-spi.c +1 -0
index 2633e147b76c..704f214d2614 100644
@@ -110,6 +110,7 @@ static struct spi_driver arizona_spi_driver = {
 
 module_spi_driver(arizona_spi_driver);
 
+MODULE_SOFTDEP("pre: arizona_ldo1");
 MODULE_DESCRIPTION("Arizona SPI bus interface");
 MODULE_AUTHOR("Mark Brown <[email protected]>");
 MODULE_LICENSE("GPL");
Signature · 1 line
2.28.0
#2 lore raw

PATCH v3 2/5 mfd: arizona: Replace arizona_of_get_type() with device_get_match_data()

In reply to Hans de Goede

Replace the custom arizona_of_get_type() function with the generic device_get_match_data() helper. Besides being a nice cleanup this also makes it easier to add support for binding to ACPI enumerated devices.

While at it also fix a possible NULL pointer deref of the id argument to the probe functions (this could happen on e.g. manual driver binding through sysfs).

---
Changes in v2:
- New patch in v2 of this patchset

---
 drivers/mfd/arizona-core.c | 11 -----------
 drivers/mfd/arizona-i2c.c  | 10 ++++++----
 drivers/mfd/arizona-spi.c  | 10 ++++++----
 drivers/mfd/arizona.h      |  9 ---------
 4 files changed, 12 insertions(+), 28 deletions(-)
drivers/mfd/arizona-core.c +0 -11
index 000cb82023e3..75f1bc671d59 100644
@@ -797,17 +797,6 @@ const struct dev_pm_ops arizona_pm_ops = {
 EXPORT_SYMBOL_GPL(arizona_pm_ops);
 
 #ifdef CONFIG_OF
-unsigned long arizona_of_get_type(struct device *dev)
-{
-	const struct of_device_id *id = of_match_device(arizona_of_match, dev);
-
-	if (id)
-		return (unsigned long)id->data;
-	else
-		return 0;
-}
-EXPORT_SYMBOL_GPL(arizona_of_get_type);
-
 static int arizona_of_get_core_pdata(struct arizona *arizona)
 {
 	struct arizona_pdata *pdata = &arizona->pdata;
drivers/mfd/arizona-i2c.c +6 -4
index 2a4a3a164d0a..5e83b730c4ce 100644
@@ -23,14 +23,16 @@
 static int arizona_i2c_probe(struct i2c_client *i2c,
 			     const struct i2c_device_id *id)
 {
+	const void *match_data;
 	struct arizona *arizona;
 	const struct regmap_config *regmap_config = NULL;
-	unsigned long type;
+	unsigned long type = 0;
 	int ret;
 
-	if (i2c->dev.of_node)
-		type = arizona_of_get_type(&i2c->dev);
-	else
+	match_data = device_get_match_data(&i2c->dev);
+	if (match_data)
+		type = (unsigned long)match_data;
+	else if (id)
 		type = id->driver_data;
 
 	switch (type) {
drivers/mfd/arizona-spi.c +6 -4
index 704f214d2614..798b88295c77 100644
@@ -23,14 +23,16 @@
 static int arizona_spi_probe(struct spi_device *spi)
 {
 	const struct spi_device_id *id = spi_get_device_id(spi);
+	const void *match_data;
 	struct arizona *arizona;
 	const struct regmap_config *regmap_config = NULL;
-	unsigned long type;
+	unsigned long type = 0;
 	int ret;
 
-	if (spi->dev.of_node)
-		type = arizona_of_get_type(&spi->dev);
-	else
+	match_data = device_get_match_data(&spi->dev);
+	if (match_data)
+		type = (unsigned long)match_data;
+	else if (id)
 		type = id->driver_data;
 
 	switch (type) {
drivers/mfd/arizona.h +0 -9
index 995efc6d7f32..801cbbcd71cb 100644
@@ -50,13 +50,4 @@ int arizona_dev_exit(struct arizona *arizona);
 int arizona_irq_init(struct arizona *arizona);
 int arizona_irq_exit(struct arizona *arizona);
 
-#ifdef CONFIG_OF
-unsigned long arizona_of_get_type(struct device *dev);
-#else
-static inline unsigned long arizona_of_get_type(struct device *dev)
-{
-	return 0;
-}
-#endif
-
 #endif
Signature · 1 line
2.28.0
Reviewed-by on v3 2/5
#3 lore raw

Re: [PATCH v3 2/5] mfd: arizona: Replace arizona_of_get_type() with device_get_match_data()

Quoted 9 lines · Hans de Goede

Replace the custom arizona_of_get_type() function with the generic device_get_match_data() helper. Besides being a nice cleanup this also makes it easier to add support for binding to ACPI enumerated devices.

While at it also fix a possible NULL pointer deref of the id argument to the probe functions (this could happen on e.g. manual driver binding through sysfs).

Quoted 105 lines

---
Changes in v2:
- New patch in v2 of this patchset

---
 drivers/mfd/arizona-core.c | 11 -----------
 drivers/mfd/arizona-i2c.c  | 10 ++++++----
 drivers/mfd/arizona-spi.c  | 10 ++++++----
 drivers/mfd/arizona.h      |  9 ---------
 4 files changed, 12 insertions(+), 28 deletions(-)
drivers/mfd/arizona-core.c +0 -11
index 000cb82023e3..75f1bc671d59 100644
@@ -797,17 +797,6 @@ const struct dev_pm_ops arizona_pm_ops = {
 EXPORT_SYMBOL_GPL(arizona_pm_ops);
 
 #ifdef CONFIG_OF
-unsigned long arizona_of_get_type(struct device *dev)
-{
-       const struct of_device_id *id = of_match_device(arizona_of_match, dev);
-
-       if (id)
-               return (unsigned long)id->data;
-       else
-               return 0;
-}
-EXPORT_SYMBOL_GPL(arizona_of_get_type);
-
 static int arizona_of_get_core_pdata(struct arizona *arizona)
 {
        struct arizona_pdata *pdata = &arizona->pdata;
drivers/mfd/arizona-i2c.c +6 -4
index 2a4a3a164d0a..5e83b730c4ce 100644
@@ -23,14 +23,16 @@
 static int arizona_i2c_probe(struct i2c_client *i2c,
                             const struct i2c_device_id *id)
 {
+       const void *match_data;
        struct arizona *arizona;
        const struct regmap_config *regmap_config = NULL;
-       unsigned long type;
+       unsigned long type = 0;
        int ret;
 
-       if (i2c->dev.of_node)
-               type = arizona_of_get_type(&i2c->dev);
-       else
+       match_data = device_get_match_data(&i2c->dev);
+       if (match_data)
+               type = (unsigned long)match_data;
+       else if (id)
                type = id->driver_data;
 
        switch (type) {
drivers/mfd/arizona-spi.c +6 -4
index 704f214d2614..798b88295c77 100644
@@ -23,14 +23,16 @@
 static int arizona_spi_probe(struct spi_device *spi)
 {
        const struct spi_device_id *id = spi_get_device_id(spi);
+       const void *match_data;
        struct arizona *arizona;
        const struct regmap_config *regmap_config = NULL;
-       unsigned long type;
+       unsigned long type = 0;
        int ret;
 
-       if (spi->dev.of_node)
-               type = arizona_of_get_type(&spi->dev);
-       else
+       match_data = device_get_match_data(&spi->dev);
+       if (match_data)
+               type = (unsigned long)match_data;
+       else if (id)
                type = id->driver_data;
 
        switch (type) {
drivers/mfd/arizona.h +0 -10
index 995efc6d7f32..801cbbcd71cb 100644
@@ -50,13 +50,4 @@ int arizona_dev_exit(struct arizona *arizona);
 int arizona_irq_init(struct arizona *arizona);
 int arizona_irq_exit(struct arizona *arizona);
 
-#ifdef CONFIG_OF
-unsigned long arizona_of_get_type(struct device *dev);
-#else
-static inline unsigned long arizona_of_get_type(struct device *dev)
-{
-       return 0;
-}
-#endif
-
 #endif
--

2.28.0

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Acked-by on v3 2/5
#4 lore raw

Re: [PATCH v3 2/5] mfd: arizona: Replace arizona_of_get_type() with device_get_match_data()

In reply to Hans de Goede
Quoted 5 lines · Hans de Goede

Replace the custom arizona_of_get_type() function with the generic device_get_match_data() helper. Besides being a nice cleanup this also makes it easier to add support for binding to ACPI enumerated devices.

Quoted 7 lines

While at it also fix a possible NULL pointer deref of the id argument to the probe functions (this could happen on e.g. manual driver binding through sysfs).

---

Thanks,
Charles

#5 lore raw

PATCH v3 3/5 mfd: arizona: Add support for ACPI enumeration of WM5102 connected over SPI

In reply to Hans de Goede

The Intel Bay Trail (x86/ACPI) based Lenovo Yoga Tablet 2 series use a WM5102 codec connected over SPI.

Add support for ACPI enumeration to arizona-spi so that arizona-spi can bind to the codec on these tablets.

This is loosely based on an earlier attempt (for Android-x86) at this by Christian Hartmann, combined with insights in things like the speaker GPIO from the android-x86 android port for the Lenovo Yoga Tablet 2 1051F/L [1].

[1] https://github.com/Kitsune2222/Android_Yoga_Tablet_2-1051F_Kernel

---
Changes in v3:
- Fix compilation error when CONFIG_ACPI is not set

Changes in v2:
- Minor coding style tweaks
- Use memcpy instead of for loop to copy gpiod_lookup-s
- Log a warning when the ACPI "CLKE" call fails
- Drop addition of acpi_device_get_match_data() call, as the code was moved over to use the generic device_get_match_data() helper in a (new in v2) preparation patch

---
 drivers/mfd/arizona-spi.c | 121 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)
drivers/mfd/arizona-spi.c +121 -0
index 798b88295c77..c652b733b2cb 100644
@@ -7,7 +7,10 @@
  * Author: Mark Brown <[email protected]>
  */
 
+#include <linux/acpi.h>
 #include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio/machine.h>
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
@@ -15,11 +18,122 @@
 #include <linux/slab.h>
 #include <linux/spi/spi.h>
 #include <linux/of.h>
+#include <uapi/linux/input-event-codes.h>
 
 #include <linux/mfd/arizona/core.h>
 
 #include "arizona.h"
 
+#ifdef CONFIG_ACPI
+const struct acpi_gpio_params reset_gpios = { 1, 0, false };
+const struct acpi_gpio_params ldoena_gpios = { 2, 0, false };
+
+static const struct acpi_gpio_mapping arizona_acpi_gpios[] = {
+	{ "reset-gpios", &reset_gpios, 1, },
+	{ "wlf,ldoena-gpios", &ldoena_gpios, 1 },
+	{ }
+};
+
+/*
+ * The ACPI resources for the device only describe external GPIO-s. They do
+ * not provide mappings for the GPIO-s coming from the Arizona codec itself.
+ */
+static const struct gpiod_lookup arizona_soc_gpios[] = {
+	{ "arizona", 2, "wlf,spkvdd-ena", 0, GPIO_ACTIVE_HIGH },
+	{ "arizona", 4, "wlf,micd-pol", 0, GPIO_ACTIVE_LOW },
+};
+
+/*
+ * The AOSP 3.5 mm Headset: Accessory Specification gives the following values:
+ * Function A Play/Pause:           0 ohm
+ * Function D Voice assistant:    135 ohm
+ * Function B Volume Up           240 ohm
+ * Function C Volume Down         470 ohm
+ * Minimum Mic DC resistance     1000 ohm
+ * Minimum Ear speaker impedance   16 ohm
+ * Note the first max value below must be less then the min. speaker impedance,
+ * to allow CTIA/OMTP detection to work. The other max values are the closest
+ * value from extcon-arizona.c:arizona_micd_levels halfway 2 button resistances.
+ */
+static const struct arizona_micd_range arizona_micd_aosp_ranges[] = {
+	{ .max =  11, .key = KEY_PLAYPAUSE },
+	{ .max = 186, .key = KEY_VOICECOMMAND },
+	{ .max = 348, .key = KEY_VOLUMEUP },
+	{ .max = 752, .key = KEY_VOLUMEDOWN },
+};
+
+static void arizona_spi_acpi_remove_lookup(void *lookup)
+{
+	gpiod_remove_lookup_table(lookup);
+}
+
+static int arizona_spi_acpi_probe(struct arizona *arizona)
+{
+	struct gpiod_lookup_table *lookup;
+	acpi_status status;
+	int ret;
+
+	/* Add mappings for the 2 ACPI declared GPIOs used for reset and ldo-ena */
+	devm_acpi_dev_add_driver_gpios(arizona->dev, arizona_acpi_gpios);
+
+	/* Add lookups for the SoCs own GPIOs used for micdet-polarity and spkVDD-enable */
+	lookup = devm_kzalloc(arizona->dev,
+			      struct_size(lookup, table, ARRAY_SIZE(arizona_soc_gpios) + 1),
+			      GFP_KERNEL);
+	if (!lookup)
+		return -ENOMEM;
+
+	lookup->dev_id = dev_name(arizona->dev);
+	memcpy(lookup->table, arizona_soc_gpios, sizeof(arizona_soc_gpios));
+
+	gpiod_add_lookup_table(lookup);
+	ret = devm_add_action_or_reset(arizona->dev, arizona_spi_acpi_remove_lookup, lookup);
+	if (ret)
+		return ret;
+
+	/* Enable 32KHz clock from SoC to codec for jack-detect */
+	status = acpi_evaluate_object(ACPI_HANDLE(arizona->dev), "CLKE", NULL, NULL);
+	if (ACPI_FAILURE(status))
+		dev_warn(arizona->dev, "Failed to enable 32KHz clk ACPI error %d\n", status);
+
+	/*
+	 * Some DSDTs wrongly declare the IRQ trigger-type as IRQF_TRIGGER_FALLING
+	 * The IRQ line will stay low when a new IRQ event happens between reading
+	 * the IRQ status flags and acknowledging them. When the IRQ line stays
+	 * low like this the IRQ will never trigger again when its type is set
+	 * to IRQF_TRIGGER_FALLING. Correct the IRQ trigger-type to fix this.
+	 */
+	arizona->pdata.irq_flags = IRQF_TRIGGER_LOW;
+
+	/* Wait 200 ms after jack insertion */
+	arizona->pdata.micd_detect_debounce = 200;
+
+	/* Use standard AOSP values for headset-button mappings */
+	arizona->pdata.micd_ranges = arizona_micd_aosp_ranges;
+	arizona->pdata.num_micd_ranges = ARRAY_SIZE(arizona_micd_aosp_ranges);
+
+	return 0;
+}
+
+static const struct acpi_device_id arizona_acpi_match[] = {
+	{
+		.id = "WM510204",
+		.driver_data = WM5102,
+	},
+	{
+		.id = "WM510205",
+		.driver_data = WM5102,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, arizona_acpi_match);
+#else
+static int arizona_spi_acpi_probe(struct arizona *arizona)
+{
+	return -ENODEV;
+}
+#endif
+
 static int arizona_spi_probe(struct spi_device *spi)
 {
 	const struct spi_device_id *id = spi_get_device_id(spi);
@@ -77,6 +191,12 @@ static int arizona_spi_probe(struct spi_device *spi)
 	arizona->dev = &spi->dev;
 	arizona->irq = spi->irq;
 
+	if (has_acpi_companion(&spi->dev)) {
+		ret = arizona_spi_acpi_probe(arizona);
+		if (ret)
+			return ret;
+	}
+
 	return arizona_dev_init(arizona);
 }
 
@@ -104,6 +224,7 @@ static struct spi_driver arizona_spi_driver = {
 		.name	= "arizona",
 		.pm	= &arizona_pm_ops,
 		.of_match_table	= of_match_ptr(arizona_of_match),
+		.acpi_match_table = ACPI_PTR(arizona_acpi_match),
 	},
 	.probe		= arizona_spi_probe,
 	.remove		= arizona_spi_remove,
Signature · 1 line
2.28.0
maintainer
#6 lore raw

Re: [PATCH v3 3/5] mfd: arizona: Add support for ACPI enumeration of WM5102 connected over SPI

drivers/mfd/arizona-spi.c line 106

Quoted 8 lines · Hans de Goede
drivers/mfd/arizona-spi.c +8 -0
+	/*
+	 * Some DSDTs wrongly declare the IRQ trigger-type as IRQF_TRIGGER_FALLING
+	 * The IRQ line will stay low when a new IRQ event happens between reading
+	 * the IRQ status flags and acknowledging them. When the IRQ line stays
+	 * low like this the IRQ will never trigger again when its type is set
+	 * to IRQF_TRIGGER_FALLING. Correct the IRQ trigger-type to fix this.
+	 */
+	arizona->pdata.irq_flags = IRQF_TRIGGER_LOW;

Are you sure that all the relevant interrupt controllers support active low interrupts? There were issues on some systems with missing support for active low interrupts (see the bodge in wm8994-irq.c to work around them) - it's entirely likely that there are DSDTs that are just plain buggy here but if someone's copying and pasting it smells like there may be some systems that actually need an edge triggered interrupt that they're getting it from.

Quoted 57 lines
drivers/mfd/arizona-spi.c +37 -0
+
+	/* Wait 200 ms after jack insertion */
+	arizona->pdata.micd_detect_debounce = 200;
+
+	/* Use standard AOSP values for headset-button mappings */
+	arizona->pdata.micd_ranges = arizona_micd_aosp_ranges;
+	arizona->pdata.num_micd_ranges = ARRAY_SIZE(arizona_micd_aosp_ranges);
+
+	return 0;
+}
+
+static const struct acpi_device_id arizona_acpi_match[] = {
+	{
+		.id = "WM510204",
+		.driver_data = WM5102,
+	},
+	{
+		.id = "WM510205",
+		.driver_data = WM5102,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, arizona_acpi_match);
+#else
+static int arizona_spi_acpi_probe(struct arizona *arizona)
+{
+	return -ENODEV;
+}
+#endif
+
 static int arizona_spi_probe(struct spi_device *spi)
 {
 	const struct spi_device_id *id = spi_get_device_id(spi);
@@ -77,6 +191,12 @@ static int arizona_spi_probe(struct spi_device *spi)
 	arizona->dev = &spi->dev;
 	arizona->irq = spi->irq;
 
+	if (has_acpi_companion(&spi->dev)) {
+		ret = arizona_spi_acpi_probe(arizona);
+		if (ret)
+			return ret;
+	}
+
 	return arizona_dev_init(arizona);
 }
 
@@ -104,6 +224,7 @@ static struct spi_driver arizona_spi_driver = {
 		.name	= "arizona",
 		.pm	= &arizona_pm_ops,
 		.of_match_table	= of_match_ptr(arizona_of_match),
+		.acpi_match_table = ACPI_PTR(arizona_acpi_match),
 	},
 	.probe		= arizona_spi_probe,
 	.remove		= arizona_spi_remove,
Signature · 1 line
2.28.0
#7 lore raw

Re: [PATCH v3 3/5] mfd: arizona: Add support for ACPI enumeration of WM5102 connected over SPI

Hi,

Quoted 18 lines · Mark Brown

drivers/mfd/arizona-spi.c line 106

Quoted 8 lines · Hans de Goede
drivers/mfd/arizona-spi.c +8 -0
+	/*
+	 * Some DSDTs wrongly declare the IRQ trigger-type as IRQF_TRIGGER_FALLING
+	 * The IRQ line will stay low when a new IRQ event happens between reading
+	 * the IRQ status flags and acknowledging them. When the IRQ line stays
+	 * low like this the IRQ will never trigger again when its type is set
+	 * to IRQF_TRIGGER_FALLING. Correct the IRQ trigger-type to fix this.
+	 */
+	arizona->pdata.irq_flags = IRQF_TRIGGER_LOW;

Are you sure that all the relevant interrupt controllers support active low interrupts? There were issues on some systems with missing support for active low interrupts (see the bodge in wm8994-irq.c to work around them) - it's entirely likely that there are DSDTs that are just plain buggy here but if someone's copying and pasting it smells like there may be some systems that actually need an edge triggered interrupt that they're getting it from.

I'm only aware of one series of devices / models which actually use the combination of ACPI enumeration and the WM5102 codec, and that is the Lenovo Yoga Tablet 2 series (in 8, 10 and 13 inch versions shipping with both Windows and Android). These all use a Bay Trail SoC which is capable of using active low interrupts.

More in general I'm not aware of any (recent-ish) x86 GPIO controllers not being able to do active low interrupts. In theory we could hit this code path on ARM devices using ACPI enumeration, but I don't think it is likely we will see a combination of ARM + ACPI enumeration + WM5102 + GPIO controller not capable of active-low interrupts.

This overriding of the flags definitely is necessary on the Lenovo devices in question. I could add a
"if (dmi_name_in_vendors("LENOVO"))" guard around it, but that seems unnecessary.

Regards,

Hans

Quoted 58 lines
Quoted 58 lines
drivers/mfd/arizona-spi.c +37 -0
+
+	/* Wait 200 ms after jack insertion */
+	arizona->pdata.micd_detect_debounce = 200;
+
+	/* Use standard AOSP values for headset-button mappings */
+	arizona->pdata.micd_ranges = arizona_micd_aosp_ranges;
+	arizona->pdata.num_micd_ranges = ARRAY_SIZE(arizona_micd_aosp_ranges);
+
+	return 0;
+}
+
+static const struct acpi_device_id arizona_acpi_match[] = {
+	{
+		.id = "WM510204",
+		.driver_data = WM5102,
+	},
+	{
+		.id = "WM510205",
+		.driver_data = WM5102,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, arizona_acpi_match);
+#else
+static int arizona_spi_acpi_probe(struct arizona *arizona)
+{
+	return -ENODEV;
+}
+#endif
+
 static int arizona_spi_probe(struct spi_device *spi)
 {
 	const struct spi_device_id *id = spi_get_device_id(spi);
@@ -77,6 +191,12 @@ static int arizona_spi_probe(struct spi_device *spi)
 	arizona->dev = &spi->dev;
 	arizona->irq = spi->irq;
 
+	if (has_acpi_companion(&spi->dev)) {
+		ret = arizona_spi_acpi_probe(arizona);
+		if (ret)
+			return ret;
+	}
+
 	return arizona_dev_init(arizona);
 }
 
@@ -104,6 +224,7 @@ static struct spi_driver arizona_spi_driver = {
 		.name	= "arizona",
 		.pm	= &arizona_pm_ops,
 		.of_match_table	= of_match_ptr(arizona_of_match),
+		.acpi_match_table = ACPI_PTR(arizona_acpi_match),
 	},
 	.probe		= arizona_spi_probe,
 	.remove		= arizona_spi_remove,
Signature · 1 line
2.28.0
maintainer
#8 lore raw

Re: [PATCH v3 3/5] mfd: arizona: Add support for ACPI enumeration of WM5102 connected over SPI

Quoted 5 lines · Hans de Goede

More in general I'm not aware of any (recent-ish) x86 GPIO controllers not being able to do active low interrupts. In theory we could hit this code path on ARM devices using ACPI enumeration, but I don't think it is likely we will see a combination of ARM + ACPI enumeration + WM5102 + GPIO controller not capable of active-low interrupts.

I've not seen this issue on any ARM based systems.

Quoted 4 lines

This overriding of the flags definitely is necessary on the Lenovo devices in question. I could add a
"if (dmi_name_in_vendors("LENOVO"))" guard around it, but that seems unnecessary.

Possibly just an update to the comment to make it clear that some firmwares might legitimately set the flag?

#9 lore raw

Re: [PATCH v3 3/5] mfd: arizona: Add support for ACPI enumeration of WM5102 connected over SPI

Hi,

Quoted 10 lines · Mark Brown
Quoted 5 lines · Hans de Goede

More in general I'm not aware of any (recent-ish) x86 GPIO controllers not being able to do active low interrupts. In theory we could hit this code path on ARM devices using ACPI enumeration, but I don't think it is likely we will see a combination of ARM + ACPI enumeration + WM5102 + GPIO controller not capable of active-low interrupts.

I've not seen this issue on any ARM based systems.

Quoted 7 lines
Quoted 4 lines

This overriding of the flags definitely is necessary on the Lenovo devices in question. I could add a
"if (dmi_name_in_vendors("LENOVO"))" guard around it, but that seems unnecessary.

Possibly just an update to the comment to make it clear that some firmwares might legitimately set the flag

That seems sensible, I will wait a bit to so if you (or someone) has any more review remarks to this series and then send out a v4 with the comment updated.

Regards,

Hans

#10 lore raw

Re: [PATCH v3 3/5] mfd: arizona: Add support for ACPI enumeration of WM5102 connected over SPI

In reply to Mark Brown

Hi,

Quoted 10 lines · Mark Brown
Quoted 5 lines · Hans de Goede

More in general I'm not aware of any (recent-ish) x86 GPIO controllers not being able to do active low interrupts. In theory we could hit this code path on ARM devices using ACPI enumeration, but I don't think it is likely we will see a combination of ARM + ACPI enumeration + WM5102 + GPIO controller not capable of active-low interrupts.

I've not seen this issue on any ARM based systems.

Quoted 7 lines
Quoted 4 lines

This overriding of the flags definitely is necessary on the Lenovo devices in question. I could add a
"if (dmi_name_in_vendors("LENOVO"))" guard around it, but that seems unnecessary.

Possibly just an update to the comment to make it clear that some firmwares might legitimately set the flag?

Ok, I've extended the comment above the override of the irq-flags with the following paragraph for v4 of this patch-set:

* Note theoretically it is possible that some boards are not capable
* of handling active low level interrupts. In that case setting the
* flag to IRQF_TRIGGER_FALLING would not be a bug (and we would need
* to work around this) but sofar all known usages of IRQF_TRIGGER_FALLING
* are a bug in the boards DSDT.

Regards,

Hans

#11 lore raw

Re: [PATCH v3 3/5] mfd: arizona: Add support for ACPI enumeration of WM5102 connected over SPI

Quoted 19 lines · Hans de Goede
Quoted 10 lines · Mark Brown
Quoted 5 lines · Hans de Goede

More in general I'm not aware of any (recent-ish) x86 GPIO controllers not being able to do active low interrupts. In theory we could hit this code path on ARM devices using ACPI enumeration, but I don't think it is likely we will see a combination of ARM + ACPI enumeration + WM5102 + GPIO controller not capable of active-low interrupts.

I've not seen this issue on any ARM based systems.

Quoted 7 lines
Quoted 4 lines

This overriding of the flags definitely is necessary on the Lenovo devices in question. I could add a
"if (dmi_name_in_vendors("LENOVO"))" guard around it, but that seems unnecessary.

Possibly just an update to the comment to make it clear that some firmwares might legitimately set the flag?

Quoted 7 lines

Ok, I've extended the comment above the override of the irq-flags with the following paragraph for v4 of this patch-set:

* Note theoretically it is possible that some boards are not capable
* of handling active low level interrupts. In that case setting the
* flag to IRQF_TRIGGER_FALLING would not be a bug (and we would need
* to work around this) but sofar all known usages of IRQF_TRIGGER_FALLING

so far

Quoted 1 line

* are a bug in the boards DSDT.

board's

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#12 lore raw

Re: [PATCH v3 3/5] mfd: arizona: Add support for ACPI enumeration of WM5102 connected over SPI

Hi,

Quoted 28 lines · Andy Shevchenko
Quoted 19 lines · Hans de Goede
Quoted 10 lines · Mark Brown
Quoted 5 lines · Hans de Goede

More in general I'm not aware of any (recent-ish) x86 GPIO controllers not being able to do active low interrupts. In theory we could hit this code path on ARM devices using ACPI enumeration, but I don't think it is likely we will see a combination of ARM + ACPI enumeration + WM5102 + GPIO controller not capable of active-low interrupts.

I've not seen this issue on any ARM based systems.

Quoted 7 lines
Quoted 4 lines

This overriding of the flags definitely is necessary on the Lenovo devices in question. I could add a
"if (dmi_name_in_vendors("LENOVO"))" guard around it, but that seems unnecessary.

Possibly just an update to the comment to make it clear that some firmwares might legitimately set the flag?

Quoted 7 lines

Ok, I've extended the comment above the override of the irq-flags with the following paragraph for v4 of this patch-set:

* Note theoretically it is possible that some boards are not capable
* of handling active low level interrupts. In that case setting the
* flag to IRQF_TRIGGER_FALLING would not be a bug (and we would need
* to work around this) but sofar all known usages of IRQF_TRIGGER_FALLING

Quoted 6 lines

so far

Quoted 1 line

* are a bug in the boards DSDT.

board's

Thank you for the quick review, I've fixed both spelling errors for the upcoming v4.

Regards,

Hans

#13 lore raw

PATCH v3 4/5 ASoC: Intel: Add DMI quirk table to soc_intel_is_byt_cr()

In reply to Hans de Goede

Some Bay Trail systems:
1. Use a non CR version of the Bay Trail SoC
2. Contain at least 6 interrupt resources so that the platform_get_resource(pdev, IORESOURCE_IRQ, 5) check to workaround non CR systems which list their IPC IRQ at index 0 despite being non CR does not work
3. Despite 1. and 2. still have their IPC IRQ at index 0 rather then 5

Add a DMI quirk table to check for the few known models with this issue, so that the right IPC IRQ index is used on these systems.

---
 sound/soc/intel/common/soc-intel-quirks.h | 25 +++++++++++++++++++++++
 1 file changed, 25 insertions(+)
sound/soc/intel/common/soc-intel-quirks.h +25 -0
index b07df3059926..a93987ab7f4d 100644
@@ -11,6 +11,7 @@
 
 #if IS_ENABLED(CONFIG_X86)
 
+#include <linux/dmi.h>
 #include <asm/cpu_device_id.h>
 #include <asm/intel-family.h>
 #include <asm/iosf_mbi.h>
@@ -38,12 +39,36 @@ SOC_INTEL_IS_CPU(cml, KABYLAKE_L);
 
 static inline bool soc_intel_is_byt_cr(struct platform_device *pdev)
 {
+	/*
+	 * List of systems which:
+	 * 1. Use a non CR version of the Bay Trail SoC
+	 * 2. Contain at least 6 interrupt resources so that the
+	 *    platform_get_resource(pdev, IORESOURCE_IRQ, 5) check below
+	 *    succeeds
+	 * 3. Despite 1. and 2. still have their IPC IRQ at index 0 rather then 5
+	 *
+	 * This needs to be here so that it can be shared between the SST and
+	 * SOF drivers. We rely on the compiler to optimize this out in files
+	 * where soc_intel_is_byt_cr is not used.
+	 */
+	static const struct dmi_system_id force_bytcr_table[] = {
+		{	/* Lenovo Yoga Tablet 2 series */
+			.matches = {
+				DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+				DMI_MATCH(DMI_PRODUCT_FAMILY, "YOGATablet2"),
+			},
+		},
+		{}
+	};
 	struct device *dev = &pdev->dev;
 	int status = 0;
 
 	if (!soc_intel_is_byt())
 		return false;
 
+	if (dmi_check_system(force_bytcr_table))
+		return true;
+
 	if (iosf_mbi_available()) {
 		u32 bios_status;
 
Signature · 1 line
2.28.0
#14 lore raw

PATCH v3 5/5 ASoC: Intel: bytcr_wm5102: Add machine driver for BYT/WM5102

In reply to Hans de Goede

From: Pierre-Louis Bossart <[email protected]>

Add a new ASoc Machine driver for Intel Baytrail platforms with a Wolfson Microelectronics WM5102 codec.

This is based on a past contributions [1] from Paulo Sergio Travaglia <[email protected]> based on the Levono kernel [2] combined with insights in things like the speaker GPIO from the android-x86 android port for the Lenovo Yoga Tablet 2 1051F/L [3].

[1] https://patchwork.kernel.org/project/alsa-devel/patch/[email protected]/
[2] https://github.com/lenovo-yt2-dev/android_kernel_lenovo_baytrail/blob/cm-12.1/sound/soc/intel/board/byt_bl_wm5102.c
[3] https://github.com/Kitsune2222/Android_Yoga_Tablet_2-1051F_Kernel

The original machine driver from the Android ports was a crude modified copy of bytcr_rt5640.c adjusted to work with the WM5102 codec. This version has been extensively reworked to:

1. Remove all rt5640 related quirk handling. to the best of my knowledge this setup is only used on the Lenovo Yoga Tablet 2 series (8, 10 and 13 inch models) which all use the same setup. So there is no need to deal with all the variations with which we need to deal on rt5640 boards.

2. Rework clock handling, properly turn off the FLL and the platform-clock when they are no longer necessary and don't reconfigure the FLL unnecessarily when it is already running. This fixes a number of:
"Timed out waiting for lock" warnings being logged.

3. Add the GPIO controlled Speaker-VDD regulator as a DAPM_SUPPLY

This only adds the machine driver and ACPI hooks, the BYT-CR detection quirk which these devices need will be added in a separate patch.

---
Changes in v2:
- Drop unnecessary configuring of OPCLK
- Fix error-msg when setting the SYSCLK fails

---
 sound/soc/intel/boards/Kconfig                |  12 +
 sound/soc/intel/boards/Makefile               |   2 +
 sound/soc/intel/boards/bytcr_wm5102.c         | 465 ++++++++++++++++++
 .../intel/common/soc-acpi-intel-byt-match.c   |  16 +
 4 files changed, 495 insertions(+)
 create mode 100644 sound/soc/intel/boards/bytcr_wm5102.c
sound/soc/intel/boards/Kconfig +12 -0
index b58b9b60d37e..d1d28129a32b 100644
@@ -111,6 +111,18 @@ config SND_SOC_INTEL_BYTCR_RT5651_MACH
 	  Say Y or m if you have such a device. This is a recommended option.
 	  If unsure select "N".
 
+config SND_SOC_INTEL_BYTCR_WM5102_MACH
+	tristate "Baytrail and Baytrail-CR with WM5102 codec"
+	depends on MFD_ARIZONA && MFD_WM5102 && SPI_MASTER && ACPI
+	depends on X86_INTEL_LPSS || COMPILE_TEST
+	select SND_SOC_ACPI
+	select SND_SOC_WM5102
+	help
+	  This adds support for ASoC machine driver for Intel(R) Baytrail and Baytrail-CR
+	  platforms with WM5102 audio codec.
+	  Say Y if you have such a device.
+	  If unsure select "N".
+
 config SND_SOC_INTEL_CHT_BSW_RT5672_MACH
 	tristate "Cherrytrail & Braswell with RT5672 codec"
 	depends on I2C && ACPI
sound/soc/intel/boards/Makefile +2 -0
index 5f03e484b215..616c5fbab7d5 100644
@@ -10,6 +10,7 @@ snd-soc-sst-sof-wm8804-objs := sof_wm8804.o
 snd-soc-sst-glk-rt5682_max98357a-objs := glk_rt5682_max98357a.o hda_dsp_common.o
 snd-soc-sst-bytcr-rt5640-objs := bytcr_rt5640.o
 snd-soc-sst-bytcr-rt5651-objs := bytcr_rt5651.o
+snd-soc-sst-bytcr-wm5102-objs := bytcr_wm5102.o
 snd-soc-sst-cht-bsw-rt5672-objs := cht_bsw_rt5672.o
 snd-soc-sst-cht-bsw-rt5645-objs := cht_bsw_rt5645.o
 snd-soc-sst-cht-bsw-max98090_ti-objs := cht_bsw_max98090_ti.o
@@ -51,6 +52,7 @@ obj-$(CONFIG_SND_SOC_INTEL_BDW_RT5650_MACH) += snd-soc-sst-bdw-rt5650-mach.o
 obj-$(CONFIG_SND_SOC_INTEL_BDW_RT5677_MACH) += snd-soc-sst-bdw-rt5677-mach.o
 obj-$(CONFIG_SND_SOC_INTEL_BYTCR_RT5640_MACH) += snd-soc-sst-bytcr-rt5640.o
 obj-$(CONFIG_SND_SOC_INTEL_BYTCR_RT5651_MACH) += snd-soc-sst-bytcr-rt5651.o
+obj-$(CONFIG_SND_SOC_INTEL_BYTCR_WM5102_MACH) += snd-soc-sst-bytcr-wm5102.o
 obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_RT5672_MACH) += snd-soc-sst-cht-bsw-rt5672.o
 obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_RT5645_MACH) += snd-soc-sst-cht-bsw-rt5645.o
 obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_MAX98090_TI_MACH) += snd-soc-sst-cht-bsw-max98090_ti.o
sound/soc/intel/boards/bytcr_wm5102.c new file +465 -0

465 lines not on this page · raw message

sound/soc/intel/common/soc-acpi-intel-byt-match.c +16 -0
index c348607b49a5..ec7932549655 100644
@@ -154,6 +154,22 @@ struct snd_soc_acpi_mach  snd_soc_acpi_intel_baytrail_machines[] = {
 		.sof_fw_filename = "sof-byt.ri",
 		.sof_tplg_filename = "sof-byt-rt5651.tplg",
 	},
+	{
+		.id = "WM510204",
+		.drv_name = "bytcr_wm5102",
+		.fw_filename = "intel/fw_sst_0f28.bin",
+		.board = "bytcr_wm5102",
+		.sof_fw_filename = "sof-byt.ri",
+		.sof_tplg_filename = "sof-byt-wm5102.tplg",
+	},
+	{
+		.id = "WM510205",
+		.drv_name = "bytcr_wm5102",
+		.fw_filename = "intel/fw_sst_0f28.bin",
+		.board = "bytcr_wm5102",
+		.sof_fw_filename = "sof-byt.ri",
+		.sof_tplg_filename = "sof-byt-wm5102.tplg",
+	},
 	{
 		.id = "DLGS7212",
 		.drv_name = "bytcht_da7213",
Signature · 1 line
2.28.0