linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90
@ 2023-10-14 20:53 Hans de Goede
  2023-10-14 20:53 ` [PATCH 1/4] spi: Export acpi_spi_find_controller_by_adev() Hans de Goede
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Hans de Goede @ 2023-10-14 20:53 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ilpo Järvinen, Andy Shevchenko, Mark Brown
  Cc: Hans de Goede, linux-acpi, platform-driver-x86, linux-spi

Hi All,

Here is a patch series to fix audio on the Lenovo YT3-X90 x86 Android
tablet.

This series takes care of instantiating the SPI device for the codec,
to make things fully work there also are some sound/soc/intel/boards
changes necessary which I'm still working on.

The reason to post this initial series now is to get at least
the first patch merged before the next merge window so that
the rest of the series can easily be merged after the next
merge window without needing coordination between subsystem trees.

Mark can you please pickup patch 1/4 for the 6.7 merge-windows?
then I can queue up patches 3+4 for the 6.8 merge-window once
6.7-rc1 is released.

Regards,

Hans


Hans de Goede (4):
  spi: Export acpi_spi_find_controller_by_adev()
  ACPI: scan: Add LNXVIDEO HID to ignore_serial_bus_ids[]
  platform/x86: x86-android-tablets: Add support for SPI device
    instantiation
  platform/x86: x86-android-tablets: Add audio codec info for Lenovo
    Yoga Tab 3 Pro YT3-X90F

 drivers/acpi/scan.c                           |  1 +
 .../platform/x86/x86-android-tablets/core.c   | 62 ++++++++++++
 .../platform/x86/x86-android-tablets/lenovo.c | 99 +++++++++++++++++++
 .../x86-android-tablets/x86-android-tablets.h |  9 ++
 drivers/spi/spi.c                             |  5 +-
 include/linux/spi/spi.h                       |  1 +
 6 files changed, 174 insertions(+), 3 deletions(-)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/4] spi: Export acpi_spi_find_controller_by_adev()
  2023-10-14 20:53 [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90 Hans de Goede
@ 2023-10-14 20:53 ` Hans de Goede
  2023-10-14 20:53 ` [PATCH 2/4] ACPI: scan: Add LNXVIDEO HID to ignore_serial_bus_ids[] Hans de Goede
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2023-10-14 20:53 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ilpo Järvinen, Andy Shevchenko, Mark Brown
  Cc: Hans de Goede, linux-acpi, platform-driver-x86, linux-spi

Export acpi_spi_find_controller_by_adev() so that ACPI glue code which
wants to dynamically create a spi_device using acpi_spi_device_alloc() or
spi_new_device() on a controller, to which the code does not already have
a reference, can find the controller.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/spi/spi.c       | 5 ++---
 include/linux/spi/spi.h | 1 +
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 8d6304cb061e..ac6d9b15b2fa 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -2527,8 +2527,6 @@ static void acpi_spi_parse_apple_properties(struct acpi_device *dev,
 		lookup->mode |= SPI_CPHA;
 }
 
-static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev);
-
 static int acpi_spi_add_resource(struct acpi_resource *ares, void *data)
 {
 	struct acpi_spi_lookup *lookup = data;
@@ -4523,7 +4521,7 @@ static int spi_acpi_controller_match(struct device *dev, const void *data)
 	return ACPI_COMPANION(dev->parent) == data;
 }
 
-static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
+struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
 {
 	struct device *dev;
 
@@ -4537,6 +4535,7 @@ static struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_devic
 
 	return container_of(dev, struct spi_controller, dev);
 }
+EXPORT_SYMBOL_GPL(acpi_spi_find_controller_by_adev);
 
 static struct spi_device *acpi_spi_find_device_by_adev(struct acpi_device *adev)
 {
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 7f8b478fdeb3..da05488cade8 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -867,6 +867,7 @@ extern int devm_spi_register_controller(struct device *dev,
 extern void spi_unregister_controller(struct spi_controller *ctlr);
 
 #if IS_ENABLED(CONFIG_ACPI)
+extern struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev);
 extern struct spi_device *acpi_spi_device_alloc(struct spi_controller *ctlr,
 						struct acpi_device *adev,
 						int index);
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/4] ACPI: scan: Add LNXVIDEO HID to ignore_serial_bus_ids[]
  2023-10-14 20:53 [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90 Hans de Goede
  2023-10-14 20:53 ` [PATCH 1/4] spi: Export acpi_spi_find_controller_by_adev() Hans de Goede
@ 2023-10-14 20:53 ` Hans de Goede
  2023-10-18 11:01   ` Rafael J. Wysocki
  2023-10-14 20:53 ` [PATCH 3/4] platform/x86: x86-android-tablets: Add support for SPI device instantiation Hans de Goede
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Hans de Goede @ 2023-10-14 20:53 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ilpo Järvinen, Andy Shevchenko, Mark Brown
  Cc: Hans de Goede, linux-acpi, platform-driver-x86, linux-spi

The I2C-core already has filtering to skip i2c_client instantiation for
LNXVIDEO acpi_device-s with I2cSerialBus resources, since LNXVIDEO devices
are not i2c_client-s and are handled by the acpi_video driver.

This filtering was added to i2c-core-acpi.c in commit 3a4991a9864c ("i2c:
acpi: Do not create i2c-clients for LNXVIDEO ACPI devices").

Now a similar problem has shown up where the SPI-core is instantiating
an unwanted SPI-device for a SpiSerialBus resource under a LNXVIDEO
acpi_device. On a Lenovo Yoga Tab 3 YT3-X90F this unwanted SPI-device
instanstantiation causes the SPI-device instanstantiation for the WM5102
audio codec to fail with:

[   21.988441] pxa2xx-spi 8086228E:00: chipselect 0 already in use

Instead of duplicating the I2C-core filtering in the SPI-core code, push
the filtering of SerialBus resources under LNXVIDEO acpi_device-s up into
the ACPI-core by adding the LNXVIDEO HID to ignore_serial_bus_ids[].

Note the filtering in the I2C-core i2c_acpi_do_lookup() function is still
necessary because this not only impacts i2c_client instantiation but it
also makes the I2C-core ignore the I2cSerialBus resource when checking what
the maximum speed is the I2C bus supports, which is still necessary.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/acpi/scan.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 691d4b7686ee..4b6faa2350f5 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1727,6 +1727,7 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
 	 * Some ACPI devs contain SerialBus resources even though they are not
 	 * attached to a serial bus at all.
 	 */
+		{ACPI_VIDEO_HID, },
 		{"MSHW0028", },
 	/*
 	 * HIDs of device with an UartSerialBusV2 resource for which userspace
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/4] platform/x86: x86-android-tablets: Add support for SPI device instantiation
  2023-10-14 20:53 [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90 Hans de Goede
  2023-10-14 20:53 ` [PATCH 1/4] spi: Export acpi_spi_find_controller_by_adev() Hans de Goede
  2023-10-14 20:53 ` [PATCH 2/4] ACPI: scan: Add LNXVIDEO HID to ignore_serial_bus_ids[] Hans de Goede
@ 2023-10-14 20:53 ` Hans de Goede
  2023-10-14 20:53 ` [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F Hans de Goede
  2023-10-16 17:19 ` (subset) [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90 Mark Brown
  4 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2023-10-14 20:53 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ilpo Järvinen, Andy Shevchenko, Mark Brown
  Cc: Hans de Goede, linux-acpi, platform-driver-x86, linux-spi

Some x86 Android tablets have SPI devices which are not properly described
in their DSDT. Add support for instantiating SPI devices.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 .../platform/x86/x86-android-tablets/core.c   | 62 +++++++++++++++++++
 .../x86-android-tablets/x86-android-tablets.h |  9 +++
 2 files changed, 71 insertions(+)

diff --git a/drivers/platform/x86/x86-android-tablets/core.c b/drivers/platform/x86/x86-android-tablets/core.c
index b55957bde034..6a5975ac3286 100644
--- a/drivers/platform/x86/x86-android-tablets/core.c
+++ b/drivers/platform/x86/x86-android-tablets/core.c
@@ -141,9 +141,11 @@ int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data)
 }
 
 static int i2c_client_count;
+static int spi_dev_count;
 static int pdev_count;
 static int serdev_count;
 static struct i2c_client **i2c_clients;
+static struct spi_device **spi_devs;
 static struct platform_device **pdevs;
 static struct serdev_device **serdevs;
 static struct gpio_keys_button *buttons;
@@ -185,6 +187,46 @@ static __init int x86_instantiate_i2c_client(const struct x86_dev_info *dev_info
 	return 0;
 }
 
+static __init int x86_instantiate_spi_dev(const struct x86_dev_info *dev_info, int idx)
+{
+	const struct x86_spi_dev_info *spi_dev_info = &dev_info->spi_dev_info[idx];
+	struct spi_board_info board_info = spi_dev_info->board_info;
+	struct spi_controller *controller;
+	struct acpi_device *adev;
+	acpi_handle handle;
+	acpi_status status;
+
+	board_info.irq = x86_acpi_irq_helper_get(&spi_dev_info->irq_data);
+	if (board_info.irq < 0)
+		return board_info.irq;
+
+	status = acpi_get_handle(NULL, spi_dev_info->ctrl_path, &handle);
+	if (ACPI_FAILURE(status)) {
+		pr_err("Error could not get %s handle\n", spi_dev_info->ctrl_path);
+		return -ENODEV;
+	}
+
+	adev = acpi_fetch_acpi_dev(handle);
+	if (!adev) {
+		pr_err("Error could not get adev for %s\n", spi_dev_info->ctrl_path);
+		return -ENODEV;
+	}
+
+	controller = acpi_spi_find_controller_by_adev(adev);
+	if (!controller) {
+		pr_err("Error could not get SPI controller for %s\n", spi_dev_info->ctrl_path);
+		return -ENODEV;
+	}
+
+	spi_devs[idx] = spi_new_device(controller, &board_info);
+	put_device(&controller->dev);
+	if (IS_ERR(spi_devs[idx]))
+		return dev_err_probe(&controller->dev, PTR_ERR(spi_devs[idx]),
+				     "creating SPI-device %d\n", idx);
+
+	return 0;
+}
+
 static __init int x86_instantiate_serdev(const struct x86_serdev_info *info, int idx)
 {
 	struct acpi_device *ctrl_adev, *serdev_adev;
@@ -263,6 +305,11 @@ static void x86_android_tablet_remove(struct platform_device *pdev)
 	kfree(pdevs);
 	kfree(buttons);
 
+	for (i = 0; i < spi_dev_count; i++)
+		spi_unregister_device(spi_devs[i]);
+
+	kfree(spi_devs);
+
 	for (i = 0; i < i2c_client_count; i++)
 		i2c_unregister_device(i2c_clients[i]);
 
@@ -333,6 +380,21 @@ static __init int x86_android_tablet_probe(struct platform_device *pdev)
 		}
 	}
 
+	spi_devs = kcalloc(dev_info->spi_dev_count, sizeof(*spi_devs), GFP_KERNEL);
+	if (!spi_devs) {
+		x86_android_tablet_remove(pdev);
+		return -ENOMEM;
+	}
+
+	spi_dev_count = dev_info->spi_dev_count;
+	for (i = 0; i < spi_dev_count; i++) {
+		ret = x86_instantiate_spi_dev(dev_info, i);
+		if (ret < 0) {
+			x86_android_tablet_remove(pdev);
+			return ret;
+		}
+	}
+
 	/* + 1 to make space for (optional) gpio_keys_button pdev */
 	pdevs = kcalloc(dev_info->pdev_count + 1, sizeof(*pdevs), GFP_KERNEL);
 	if (!pdevs) {
diff --git a/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h b/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h
index 9d2fb7fded6d..49fed9410adb 100644
--- a/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h
+++ b/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h
@@ -14,6 +14,7 @@
 #include <linux/gpio_keys.h>
 #include <linux/i2c.h>
 #include <linux/irqdomain_defs.h>
+#include <linux/spi/spi.h>
 
 struct gpio_desc;
 struct gpiod_lookup_table;
@@ -48,6 +49,12 @@ struct x86_i2c_client_info {
 	struct x86_acpi_irq_data irq_data;
 };
 
+struct x86_spi_dev_info {
+	struct spi_board_info board_info;
+	char *ctrl_path;
+	struct x86_acpi_irq_data irq_data;
+};
+
 struct x86_serdev_info {
 	const char *ctrl_hid;
 	const char *ctrl_uid;
@@ -72,10 +79,12 @@ struct x86_dev_info {
 	const struct software_node *bat_swnode;
 	struct gpiod_lookup_table * const *gpiod_lookup_tables;
 	const struct x86_i2c_client_info *i2c_client_info;
+	const struct x86_spi_dev_info *spi_dev_info;
 	const struct platform_device_info *pdev_info;
 	const struct x86_serdev_info *serdev_info;
 	const struct x86_gpio_button *gpio_button;
 	int i2c_client_count;
+	int spi_dev_count;
 	int pdev_count;
 	int serdev_count;
 	int gpio_button_count;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F
  2023-10-14 20:53 [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90 Hans de Goede
                   ` (2 preceding siblings ...)
  2023-10-14 20:53 ` [PATCH 3/4] platform/x86: x86-android-tablets: Add support for SPI device instantiation Hans de Goede
@ 2023-10-14 20:53 ` Hans de Goede
  2023-10-15  9:15   ` Hans de Goede
  2023-10-16 14:47   ` Mark Brown
  2023-10-16 17:19 ` (subset) [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90 Mark Brown
  4 siblings, 2 replies; 12+ messages in thread
From: Hans de Goede @ 2023-10-14 20:53 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ilpo Järvinen, Andy Shevchenko, Mark Brown
  Cc: Hans de Goede, linux-acpi, platform-driver-x86, linux-spi

The SPI attached WM5102 codec on the Lenovo Yoga Tab 3 Pro YT3-X90F
is not described in the ACPI tables.

Add info to instantiate the SPI device for the codec manually.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 .../platform/x86/x86-android-tablets/lenovo.c | 99 +++++++++++++++++++
 1 file changed, 99 insertions(+)

diff --git a/drivers/platform/x86/x86-android-tablets/lenovo.c b/drivers/platform/x86/x86-android-tablets/lenovo.c
index 585f10a57810..d5d815940ce1 100644
--- a/drivers/platform/x86/x86-android-tablets/lenovo.c
+++ b/drivers/platform/x86/x86-android-tablets/lenovo.c
@@ -12,6 +12,8 @@
 
 #include <linux/efi.h>
 #include <linux/gpio/machine.h>
+#include <linux/mfd/arizona/pdata.h>
+#include <linux/mfd/arizona/registers.h>
 #include <linux/mfd/intel_soc_pmic.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/pinctrl/machine.h>
@@ -677,6 +679,89 @@ static const struct x86_i2c_client_info lenovo_yt3_i2c_clients[] __initconst = {
 	}
 };
 
+/*
+ * 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 },
+};
+
+/* YT3 WM5102 arizona_micd_config comes from Android kernel sources */
+static struct arizona_micd_config lenovo_yt3_wm5102_micd_config[]={
+	{ 0, 1, 0 },
+	{ ARIZONA_ACCDET_SRC, 2, 1 },
+};
+
+static struct arizona_pdata lenovo_yt3_wm5102_pdata = {
+	.irq_flags = IRQF_TRIGGER_LOW,
+	.micd_detect_debounce = 200,
+	.micd_ranges = arizona_micd_aosp_ranges,
+	.num_micd_ranges = ARRAY_SIZE(arizona_micd_aosp_ranges),
+	.hpdet_channel = ARIZONA_ACCDET_MODE_HPL,
+
+	/* Below settings come from Android kernel sources */
+	.micd_bias_start_time = 1,
+	.micd_rate = 6,
+	.micd_force_micbias = 1,
+	.micd_configs = lenovo_yt3_wm5102_micd_config,
+	.num_micd_configs = ARRAY_SIZE(lenovo_yt3_wm5102_micd_config),
+        .micbias={
+           [0]={ /*MICBIAS1*/
+                 .mV =2800 ,
+                 .ext_cap=1,
+                 .discharge =1 ,
+                 .soft_start =0,
+                 .bypass =0,
+           },
+           [1]={ /*MICBIAS2*/
+                 .mV =2800 ,
+                 .ext_cap=1,
+                 .discharge =1 ,
+                 .soft_start =0,
+                 .bypass =0,
+           },
+           [2]={ /*MICBIAS3*/
+                 .mV =2800 ,
+                 .ext_cap=1,
+                 .discharge =1 ,
+                 .soft_start =0,
+                 .bypass =0,
+           },
+        },
+};
+
+static const struct x86_spi_dev_info lenovo_yt3_spi_devs[] __initconst = {
+	{
+		/* WM5102 codec */
+		.board_info = {
+			.modalias = "wm5102",
+			.platform_data = &lenovo_yt3_wm5102_pdata,
+			.max_speed_hz = 5000000,
+		},
+		.ctrl_path = "\\_SB_.PCI0.SPI1",
+		.irq_data = {
+			.type = X86_ACPI_IRQ_TYPE_GPIOINT,
+			.chip = "INT33FF:00",
+			.index = 91,
+			.trigger = ACPI_LEVEL_SENSITIVE,
+			.polarity = ACPI_ACTIVE_LOW,
+			.con_id = "wm5102_irq",
+		},
+	}
+};
+
 static int __init lenovo_yt3_init(void)
 {
 	int ret;
@@ -720,14 +805,28 @@ static struct gpiod_lookup_table lenovo_yt3_hideep_gpios = {
 	},
 };
 
+static struct gpiod_lookup_table lenovo_yt3_wm5102_gpios = {
+	.dev_id = "spi1.0",
+	.table = {
+		GPIO_LOOKUP("INT33FF:00", 75, "wlf,spkvdd-ena", GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP("INT33FF:00", 81, "wlf,ldoena", GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP("INT33FF:00", 82, "reset", GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP("arizona", 2, "wlf,micd-pol", GPIO_ACTIVE_HIGH),
+		{ }
+	},
+};
+
 static struct gpiod_lookup_table * const lenovo_yt3_gpios[] = {
 	&lenovo_yt3_hideep_gpios,
+	&lenovo_yt3_wm5102_gpios,
 	NULL
 };
 
 const struct x86_dev_info lenovo_yt3_info __initconst = {
 	.i2c_client_info = lenovo_yt3_i2c_clients,
 	.i2c_client_count = ARRAY_SIZE(lenovo_yt3_i2c_clients),
+	.spi_dev_info = lenovo_yt3_spi_devs,
+	.spi_dev_count = ARRAY_SIZE(lenovo_yt3_spi_devs),
 	.gpiod_lookup_tables = lenovo_yt3_gpios,
 	.init = lenovo_yt3_init,
 };
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F
  2023-10-14 20:53 ` [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F Hans de Goede
@ 2023-10-15  9:15   ` Hans de Goede
  2023-10-16  8:13     ` Andy Shevchenko
  2023-10-16 14:47   ` Mark Brown
  1 sibling, 1 reply; 12+ messages in thread
From: Hans de Goede @ 2023-10-15  9:15 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ilpo Järvinen, Andy Shevchenko, Mark Brown
  Cc: linux-acpi, platform-driver-x86, linux-spi

Hi,

On 10/14/23 22:53, Hans de Goede wrote:
> The SPI attached WM5102 codec on the Lenovo Yoga Tab 3 Pro YT3-X90F
> is not described in the ACPI tables.
> 
> Add info to instantiate the SPI device for the codec manually.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  .../platform/x86/x86-android-tablets/lenovo.c | 99 +++++++++++++++++++
>  1 file changed, 99 insertions(+)
> 
> diff --git a/drivers/platform/x86/x86-android-tablets/lenovo.c b/drivers/platform/x86/x86-android-tablets/lenovo.c
> index 585f10a57810..d5d815940ce1 100644
> --- a/drivers/platform/x86/x86-android-tablets/lenovo.c
> +++ b/drivers/platform/x86/x86-android-tablets/lenovo.c
> @@ -12,6 +12,8 @@
>  
>  #include <linux/efi.h>
>  #include <linux/gpio/machine.h>
> +#include <linux/mfd/arizona/pdata.h>
> +#include <linux/mfd/arizona/registers.h>
>  #include <linux/mfd/intel_soc_pmic.h>
>  #include <linux/pinctrl/consumer.h>
>  #include <linux/pinctrl/machine.h>
> @@ -677,6 +679,89 @@ static const struct x86_i2c_client_info lenovo_yt3_i2c_clients[] __initconst = {
>  	}
>  };
>  
> +/*
> + * 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 },
> +};
> +
> +/* YT3 WM5102 arizona_micd_config comes from Android kernel sources */
> +static struct arizona_micd_config lenovo_yt3_wm5102_micd_config[]={
> +	{ 0, 1, 0 },
> +	{ ARIZONA_ACCDET_SRC, 2, 1 },
> +};
> +
> +static struct arizona_pdata lenovo_yt3_wm5102_pdata = {
> +	.irq_flags = IRQF_TRIGGER_LOW,
> +	.micd_detect_debounce = 200,
> +	.micd_ranges = arizona_micd_aosp_ranges,
> +	.num_micd_ranges = ARRAY_SIZE(arizona_micd_aosp_ranges),
> +	.hpdet_channel = ARIZONA_ACCDET_MODE_HPL,
> +
> +	/* Below settings come from Android kernel sources */
> +	.micd_bias_start_time = 1,
> +	.micd_rate = 6,
> +	.micd_force_micbias = 1,
> +	.micd_configs = lenovo_yt3_wm5102_micd_config,
> +	.num_micd_configs = ARRAY_SIZE(lenovo_yt3_wm5102_micd_config),
> +        .micbias={
> +           [0]={ /*MICBIAS1*/
> +                 .mV =2800 ,
> +                 .ext_cap=1,
> +                 .discharge =1 ,
> +                 .soft_start =0,
> +                 .bypass =0,
> +           },

Note I messed up the indentation here (spaces instead of tabs)
when copy pasting this from one terminal to another,
I'll go and fix this up locally.

Regards,

Hans




> +           [1]={ /*MICBIAS2*/
> +                 .mV =2800 ,
> +                 .ext_cap=1,
> +                 .discharge =1 ,
> +                 .soft_start =0,
> +                 .bypass =0,
> +           },
> +           [2]={ /*MICBIAS3*/
> +                 .mV =2800 ,
> +                 .ext_cap=1,
> +                 .discharge =1 ,
> +                 .soft_start =0,
> +                 .bypass =0,
> +           },
> +        },
> +};
> +
> +static const struct x86_spi_dev_info lenovo_yt3_spi_devs[] __initconst = {
> +	{
> +		/* WM5102 codec */
> +		.board_info = {
> +			.modalias = "wm5102",
> +			.platform_data = &lenovo_yt3_wm5102_pdata,
> +			.max_speed_hz = 5000000,
> +		},
> +		.ctrl_path = "\\_SB_.PCI0.SPI1",
> +		.irq_data = {
> +			.type = X86_ACPI_IRQ_TYPE_GPIOINT,
> +			.chip = "INT33FF:00",
> +			.index = 91,
> +			.trigger = ACPI_LEVEL_SENSITIVE,
> +			.polarity = ACPI_ACTIVE_LOW,
> +			.con_id = "wm5102_irq",
> +		},
> +	}
> +};
> +
>  static int __init lenovo_yt3_init(void)
>  {
>  	int ret;
> @@ -720,14 +805,28 @@ static struct gpiod_lookup_table lenovo_yt3_hideep_gpios = {
>  	},
>  };
>  
> +static struct gpiod_lookup_table lenovo_yt3_wm5102_gpios = {
> +	.dev_id = "spi1.0",
> +	.table = {
> +		GPIO_LOOKUP("INT33FF:00", 75, "wlf,spkvdd-ena", GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP("INT33FF:00", 81, "wlf,ldoena", GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP("INT33FF:00", 82, "reset", GPIO_ACTIVE_HIGH),
> +		GPIO_LOOKUP("arizona", 2, "wlf,micd-pol", GPIO_ACTIVE_HIGH),
> +		{ }
> +	},
> +};
> +
>  static struct gpiod_lookup_table * const lenovo_yt3_gpios[] = {
>  	&lenovo_yt3_hideep_gpios,
> +	&lenovo_yt3_wm5102_gpios,
>  	NULL
>  };
>  
>  const struct x86_dev_info lenovo_yt3_info __initconst = {
>  	.i2c_client_info = lenovo_yt3_i2c_clients,
>  	.i2c_client_count = ARRAY_SIZE(lenovo_yt3_i2c_clients),
> +	.spi_dev_info = lenovo_yt3_spi_devs,
> +	.spi_dev_count = ARRAY_SIZE(lenovo_yt3_spi_devs),
>  	.gpiod_lookup_tables = lenovo_yt3_gpios,
>  	.init = lenovo_yt3_init,
>  };


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F
  2023-10-15  9:15   ` Hans de Goede
@ 2023-10-16  8:13     ` Andy Shevchenko
  2023-10-16  8:58       ` Hans de Goede
  0 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2023-10-16  8:13 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Rafael J . Wysocki, Ilpo Järvinen, Mark Brown, linux-acpi,
	platform-driver-x86, linux-spi

On Sun, Oct 15, 2023 at 11:15:47AM +0200, Hans de Goede wrote:
> On 10/14/23 22:53, Hans de Goede wrote:

> > +        .micbias={
> > +           [0]={ /*MICBIAS1*/

Talking about spaces, how about

        .micbias = {
           [0] = { / *MICBIAS1 */
                 .mV = 2800 ,
                 .ext_cap = 1,
                 .discharge = 1 ,
                 .soft_start = 0,
                 .bypass = 0,

> > +                 .mV =2800 ,
> > +                 .ext_cap=1,
> > +                 .discharge =1 ,
> > +                 .soft_start =0,
> > +                 .bypass =0,
> > +           },
> 
> Note I messed up the indentation here (spaces instead of tabs)
> when copy pasting this from one terminal to another,
> I'll go and fix this up locally.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F
  2023-10-16  8:13     ` Andy Shevchenko
@ 2023-10-16  8:58       ` Hans de Goede
  0 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2023-10-16  8:58 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Rafael J . Wysocki, Ilpo Järvinen, Mark Brown, linux-acpi,
	platform-driver-x86, linux-spi

Hi,

On 10/16/23 10:13, Andy Shevchenko wrote:
> On Sun, Oct 15, 2023 at 11:15:47AM +0200, Hans de Goede wrote:
>> On 10/14/23 22:53, Hans de Goede wrote:
> 
>>> +        .micbias={
>>> +           [0]={ /*MICBIAS1*/
> 
> Talking about spaces, how about
> 
>         .micbias = {
>            [0] = { / *MICBIAS1 */
>                  .mV = 2800 ,
>                  .ext_cap = 1,
>                  .discharge = 1 ,
>                  .soft_start = 0,
>                  .bypass = 0,

Ack, I already have it like this locally now. Also using only
tabs, there is plenty of width to just indent the "[0] = { ..."
with a tab too.

Regards,

Hans


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F
  2023-10-14 20:53 ` [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F Hans de Goede
  2023-10-15  9:15   ` Hans de Goede
@ 2023-10-16 14:47   ` Mark Brown
  2023-10-16 15:34     ` Hans de Goede
  1 sibling, 1 reply; 12+ messages in thread
From: Mark Brown @ 2023-10-16 14:47 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Rafael J . Wysocki, Ilpo Järvinen, Andy Shevchenko,
	linux-acpi, platform-driver-x86, linux-spi

[-- Attachment #1: Type: text/plain, Size: 511 bytes --]

On Sat, Oct 14, 2023 at 10:53:14PM +0200, Hans de Goede wrote:

> +	.micd_force_micbias = 1,
> +	.micd_configs = lenovo_yt3_wm5102_micd_config,
> +	.num_micd_configs = ARRAY_SIZE(lenovo_yt3_wm5102_micd_config),
> +        .micbias={
> +           [0]={ /*MICBIAS1*/
> +                 .mV =2800 ,
> +                 .ext_cap=1,

The indentation of this section seems weird - .micbias is indented and
the lack of spaces around =s is odd.  There's also an extra space before
the , consistently on the mV lines.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F
  2023-10-16 14:47   ` Mark Brown
@ 2023-10-16 15:34     ` Hans de Goede
  0 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2023-10-16 15:34 UTC (permalink / raw)
  To: Mark Brown
  Cc: Rafael J . Wysocki, Ilpo Järvinen, Andy Shevchenko,
	linux-acpi, platform-driver-x86, linux-spi

Hi,

On 10/16/23 16:47, Mark Brown wrote:
> On Sat, Oct 14, 2023 at 10:53:14PM +0200, Hans de Goede wrote:
> 
>> +	.micd_force_micbias = 1,
>> +	.micd_configs = lenovo_yt3_wm5102_micd_config,
>> +	.num_micd_configs = ARRAY_SIZE(lenovo_yt3_wm5102_micd_config),
>> +        .micbias={
>> +           [0]={ /*MICBIAS1*/
>> +                 .mV =2800 ,
>> +                 .ext_cap=1,
> 
> The indentation of this section seems weird - .micbias is indented and
> the lack of spaces around =s is odd.  There's also an extra space before
> the , consistently on the mV lines.

Right this is a copy and paste fail on my side, I've fixed this up
locally already, so this will be fixed in the next version.

Regards,

Hans



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: (subset) [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90
  2023-10-14 20:53 [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90 Hans de Goede
                   ` (3 preceding siblings ...)
  2023-10-14 20:53 ` [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F Hans de Goede
@ 2023-10-16 17:19 ` Mark Brown
  4 siblings, 0 replies; 12+ messages in thread
From: Mark Brown @ 2023-10-16 17:19 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ilpo Järvinen, Andy Shevchenko, Hans de Goede
  Cc: linux-acpi, platform-driver-x86, linux-spi

On Sat, 14 Oct 2023 22:53:10 +0200, Hans de Goede wrote:
> Here is a patch series to fix audio on the Lenovo YT3-X90 x86 Android
> tablet.
> 
> This series takes care of instantiating the SPI device for the codec,
> to make things fully work there also are some sound/soc/intel/boards
> changes necessary which I'm still working on.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/4] spi: Export acpi_spi_find_controller_by_adev()
      commit: a8ecbc54165fca767e75a82372a7be3810c667cf

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/4] ACPI: scan: Add LNXVIDEO HID to ignore_serial_bus_ids[]
  2023-10-14 20:53 ` [PATCH 2/4] ACPI: scan: Add LNXVIDEO HID to ignore_serial_bus_ids[] Hans de Goede
@ 2023-10-18 11:01   ` Rafael J. Wysocki
  0 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2023-10-18 11:01 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Rafael J . Wysocki, Ilpo Järvinen, Andy Shevchenko,
	Mark Brown, linux-acpi, platform-driver-x86, linux-spi

On Sat, Oct 14, 2023 at 10:53 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> The I2C-core already has filtering to skip i2c_client instantiation for
> LNXVIDEO acpi_device-s with I2cSerialBus resources, since LNXVIDEO devices
> are not i2c_client-s and are handled by the acpi_video driver.
>
> This filtering was added to i2c-core-acpi.c in commit 3a4991a9864c ("i2c:
> acpi: Do not create i2c-clients for LNXVIDEO ACPI devices").
>
> Now a similar problem has shown up where the SPI-core is instantiating
> an unwanted SPI-device for a SpiSerialBus resource under a LNXVIDEO
> acpi_device. On a Lenovo Yoga Tab 3 YT3-X90F this unwanted SPI-device
> instanstantiation causes the SPI-device instanstantiation for the WM5102
> audio codec to fail with:
>
> [   21.988441] pxa2xx-spi 8086228E:00: chipselect 0 already in use
>
> Instead of duplicating the I2C-core filtering in the SPI-core code, push
> the filtering of SerialBus resources under LNXVIDEO acpi_device-s up into
> the ACPI-core by adding the LNXVIDEO HID to ignore_serial_bus_ids[].
>
> Note the filtering in the I2C-core i2c_acpi_do_lookup() function is still
> necessary because this not only impacts i2c_client instantiation but it
> also makes the I2C-core ignore the I2cSerialBus resource when checking what
> the maximum speed is the I2C bus supports, which is still necessary.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

and please feel free to route it along with the rest of the series.

> ---
>  drivers/acpi/scan.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 691d4b7686ee..4b6faa2350f5 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -1727,6 +1727,7 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
>          * Some ACPI devs contain SerialBus resources even though they are not
>          * attached to a serial bus at all.
>          */
> +               {ACPI_VIDEO_HID, },
>                 {"MSHW0028", },
>         /*
>          * HIDs of device with an UartSerialBusV2 resource for which userspace
> --
> 2.41.0
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-10-18 11:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-14 20:53 [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90 Hans de Goede
2023-10-14 20:53 ` [PATCH 1/4] spi: Export acpi_spi_find_controller_by_adev() Hans de Goede
2023-10-14 20:53 ` [PATCH 2/4] ACPI: scan: Add LNXVIDEO HID to ignore_serial_bus_ids[] Hans de Goede
2023-10-18 11:01   ` Rafael J. Wysocki
2023-10-14 20:53 ` [PATCH 3/4] platform/x86: x86-android-tablets: Add support for SPI device instantiation Hans de Goede
2023-10-14 20:53 ` [PATCH 4/4] platform/x86: x86-android-tablets: Add audio codec info for Lenovo Yoga Tab 3 Pro YT3-X90F Hans de Goede
2023-10-15  9:15   ` Hans de Goede
2023-10-16  8:13     ` Andy Shevchenko
2023-10-16  8:58       ` Hans de Goede
2023-10-16 14:47   ` Mark Brown
2023-10-16 15:34     ` Hans de Goede
2023-10-16 17:19 ` (subset) [PATCH 0/4] spi/ACPI: Add support for SPI WM5102 coded on Lenovo YT3-X90 Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).