Skip to contentSkip to conversation

ASoC rt5677: Prepare to support Lenovo Yoga Book tablets

PATCH In review Yauhen Kharuzhy 2 participants 9 messages Feb 11 – Feb 25

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

There are two Intel Cherry Trail-based devices using the RT5677 as a sound
codec: Lenovo Yoga Book YB1-X90 (Android tablet) and YB1-X91 (Windows tablet).

They both have the same hardware configuration, but the X90 doesn't have correct ACPI table definitions for many peripherals, whereas the X91 does.

Devices missing in the ACPI are defined in the board-specific driver platform/x86/x86-android-tablets. In the X91 tablet, an ACPI _CRS method for the RT5677 contains GPIO configuration entries which were not supported by the codec driver before.

To support such device definitions, some modifications are added to the RT5677 code: ACPI, SPI, and I2C matching ids have been introduced, as well as some GPIO-related magic.

#1 lore raw

PATCH 1/7 ASoC: rt5677: Add 10EC5677 ACPI ID as supported

Add 10EC5677 ACPI ID to the match table. It is used in the Lenovo Yoga Book YB1-X91 tablet at least.

---
 sound/soc/codecs/rt5677.c | 1 +
 1 file changed, 1 insertion(+)
sound/soc/codecs/rt5677.c +1 -0
index d46385249867..ccbd32cf8298 100644
@@ -5204,6 +5204,7 @@ MODULE_DEVICE_TABLE(of, rt5677_of_match);
 static const struct acpi_device_id rt5677_acpi_match[] = {
 	{ "10EC5677", RT5677 },
 	{ "RT5677CE", RT5677 },
+	{ "10EC5677", RT5677 },
 	{ }
 };
 MODULE_DEVICE_TABLE(acpi, rt5677_acpi_match);
Signature · 1 line
2.51.0
#3 lore raw

PATCH 2/7 ASoC: rt5677: Allow it to be defined as an I2C board

In reply to Yauhen Kharuzhy

Some devices (e.g., Lenovo Yoga Book YB1-X90) define the codec as i2c_board, so add an I2C ID table to support this.

---
 sound/soc/codecs/rt5677.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
sound/soc/codecs/rt5677.c +8 -2
index ccbd32cf8298..6628c7ca5a8a 100644
@@ -5209,6 +5209,12 @@ static const struct acpi_device_id rt5677_acpi_match[] = {
 };
 MODULE_DEVICE_TABLE(acpi, rt5677_acpi_match);
 
+static const struct i2c_device_id rt5677_i2c_id[] = {
+	{ "rt5677", RT5677 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id);
+
 static void rt5677_read_device_properties(struct rt5677_priv *rt5677,
 		struct device *dev)
 {
@@ -5532,7 +5538,6 @@ static int rt5677_init_irq(struct i2c_client *i2c)
 
 static int rt5677_i2c_probe(struct i2c_client *i2c)
 {
-	struct device *dev = &i2c->dev;
 	struct rt5677_priv *rt5677;
 	int ret;
 	unsigned int val;
@@ -5547,7 +5552,7 @@ static int rt5677_i2c_probe(struct i2c_client *i2c)
 	INIT_DELAYED_WORK(&rt5677->dsp_work, rt5677_dsp_work);
 	i2c_set_clientdata(i2c, rt5677);
 
-	rt5677->type = (enum rt5677_type)(uintptr_t)device_get_match_data(dev);
+	rt5677->type = (enum rt5677_type)(uintptr_t)i2c_get_match_data(i2c);
 	if (rt5677->type == 0)
 		return -EINVAL;
 
@@ -5666,6 +5671,7 @@ static struct i2c_driver rt5677_i2c_driver = {
 		.of_match_table = rt5677_of_match,
 		.acpi_match_table = rt5677_acpi_match,
 	},
+	.id_table = rt5677_i2c_id,
 	.probe    = rt5677_i2c_probe,
 	.remove   = rt5677_i2c_remove,
 };
Signature · 1 line
2.51.0
#4 lore raw

PATCH 3/7 ASoC: rt5677: Fix typo in the header file

In reply to Yauhen Kharuzhy

Fix a typo in the DAC1 Digital Volume register description comment (it was mistakenly named as DAC3).

---
 sound/soc/codecs/rt5677.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/rt5677.h +1 -1
index d67ebae067d9..876f7674015c 100644
@@ -421,7 +421,7 @@
 #define RT5677_DAC3_R_VOL_MASK			(0xff)
 #define RT5677_DAC3_R_VOL_SFT			0
 
-/* DAC3 Digital Volume (0x19) */
+/* DAC1 Digital Volume (0x19) */
 #define RT5677_DAC1_L_VOL_MASK			(0xff << 8)
 #define RT5677_DAC1_L_VOL_SFT			8
 #define RT5677_DAC1_R_VOL_MASK			(0xff)
Signature · 1 line
2.51.0
#5 lore raw

PATCH 4/7 ASoC: rt5677: Report error if the ID register cannot be read

In reply to Yauhen Kharuzhy

To make error messages clearer, report if the ID register failed to be read via I2C during probing.

---
 sound/soc/codecs/rt5677.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
sound/soc/codecs/rt5677.c +7 -1
index 6628c7ca5a8a..845385c1fb88 100644
@@ -5602,7 +5602,13 @@ static int rt5677_i2c_probe(struct i2c_client *i2c)
 		return ret;
 	}
 
-	regmap_read(rt5677->regmap, RT5677_VENDOR_ID2, &val);
+	ret = regmap_read(rt5677->regmap, RT5677_VENDOR_ID2, &val);
+	if (ret) {
+		dev_err(&i2c->dev,
+			"Failed to read ID register: %d\n", ret);
+		return -ENODEV;
+	}
+
 	if (val != RT5677_DEVICE_ID) {
 		dev_err(&i2c->dev,
 			"Device with ID register %#x is not rt5677\n", val);
Signature · 1 line
2.51.0
#6 lore raw

PATCH 5/7 ASoC: rt5677: Set up ACPI GPIO pins mapping table

In reply to Yauhen Kharuzhy

To get GPIO configuration from ACPI, define an ACPI GPIO mapping table, linking GPIO names with CRS entries.

The only known device that has an ACPI entry for the RT5677 codec is the Lenovo Yoga Book YB1-X91, and it uses this entry to describe the entire sound system configuration: codec connections and jack detection chip connections.

This ACPI definition looks YogaBook-specific, but codec GPIOs may be recognized as generic, so add this lookup table for all devices.

Details about the YogaBook RT5677 ACPI entry are provided below.

CRS resources:
I2C devices:
0: rt5677 codec
1: ts3a227e jack detection IC

GPIOs:
0: rt5677 codec reset
1: rt5677 codec pow-ldo2
2: speaker enable

INTs:
0: rt5677 codec
1: ts3a227e jack detection IC

SPI device:
0: rt5677 codec SPI connection

ACPI decompiled dump fragment:

    Device (RTEK)
    {
        Name (_ADR, Zero)  // _ADR: Address
        Name (_HID, "10EC5677")  // _HID: Hardware ID
        Name (_CID, "10EC5677")  // _CID: Compatible ID
        Name (_DDN, "Realtek IIS Audio Codec")  // _DDN: DOS Device Name
        Name (_SUB, "17AA7005")  // _SUB: Subsystem ID
        Name (_UID, One)  // _UID: Unique ID
        Name (_PR0, Package (0x01)  // _PR0: Power Resources for D0
        {
            CLK3
        })
        Name (CHAN, Package (0x02)
        {
            One,
            0x0124F800
        })
        Method (_CRS, 0, NotSerialized)  // _CRS: Current Resource Settings
        {
            Name (SBUF, ResourceTemplate ()
            {
                I2cSerialBusV2 (0x002C, ControllerInitiated, 0x000186A0,
                    AddressingMode7Bit, "\\_SB.PCI0.I2C1",
                    0x00, ResourceConsumer, , Exclusive,
                    )
                I2cSerialBusV2 (0x003B, ControllerInitiated, 0x000186A0,
                    AddressingMode7Bit, "\\_SB.PCI0.I2C1",
                    0x00, ResourceConsumer, , Exclusive,
                    )
                GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
                    "\\_SB.GPO3", 0x00, ResourceConsumer, ,
                    )
                    {   // Pin list
                        0x0019
                    }
                GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
                    "\\_SB.GPO3", 0x00, ResourceConsumer, ,
                    )
                    {   // Pin list
                        0x0012
                    }
                GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
                    "\\_SB.GPO3", 0x00, ResourceConsumer, ,
                    )
                    {   // Pin list
                        0x0030
                    }
                GpioInt (Edge, ActiveLow, Exclusive, PullNone, 0x0000,
                    "\\_SB.GPO0", 0x00, ResourceConsumer, ,
                    )
                    {   // Pin list
                        0x005B
                    }
                GpioInt (Edge, ActiveLow, Exclusive, PullNone, 0x0000,
                    "\\_SB.GPO0", 0x00, ResourceConsumer, ,
                    )
                    {   // Pin list
                        0x004D
                    }
                SpiSerialBusV2 (0x0001, PolarityLow, FourWireMode, 0x08,
                    ControllerInitiated, 0x003D0900, ClockPolarityHigh,
                    ClockPhaseSecond, "\\_SB.PCI0.SPI1",
                    0x00, ResourceConsumer, , Exclusive,
                    )
            })
            Return (SBUF) /* \_SB_.PCI0.I2C1.RTEK._CRS.SBUF */
        }
    }
---
 sound/soc/codecs/rt5677.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
sound/soc/codecs/rt5677.c +12 -0
index 845385c1fb88..f56ac267f53b 100644
@@ -5536,6 +5536,15 @@ static int rt5677_init_irq(struct i2c_client *i2c)
 	return ret;
 }
 
+static const struct acpi_gpio_params rt5677_acpi_reset_gpios = {0, 0, true};
+static const struct acpi_gpio_params rt5677_acpi_ldo2_gpios = {1, 0, false};
+
+static const struct acpi_gpio_mapping rt5677_acpi_gpios[] = {
+	{ "realtek,reset-gpios", &rt5677_acpi_reset_gpios, 1 },
+	{ "realtek,pow-ldo2-gpios", &rt5677_acpi_ldo2_gpios, 1 },
+	{},
+};
+
 static int rt5677_i2c_probe(struct i2c_client *i2c)
 {
 	struct rt5677_priv *rt5677;
@@ -5556,6 +5565,9 @@ static int rt5677_i2c_probe(struct i2c_client *i2c)
 	if (rt5677->type == 0)
 		return -EINVAL;
 
+	if (devm_acpi_dev_add_driver_gpios(rt5677->dev, rt5677_acpi_gpios))
+		dev_warn(rt5677->dev, "Unable to add GPIO mapping table\n");
+
 	rt5677_read_device_properties(rt5677, &i2c->dev);
 
 	/* pow-ldo2 and reset are optional. The codec pins may be statically
Signature · 1 line
2.51.0
#7 lore raw

PATCH 6/7 ASoC: rt5677: Reset the codec during probing

In reply to Yauhen Kharuzhy

To ensure that the codec is in a known state, reset it during driver initialization.

---
 sound/soc/codecs/rt5677.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
sound/soc/codecs/rt5677.c +8 -1
index f56ac267f53b..60a93c3fe2e7 100644
@@ -5581,14 +5581,21 @@ static int rt5677_i2c_probe(struct i2c_client *i2c)
 		dev_err(&i2c->dev, "Failed to request POW_LDO2: %d\n", ret);
 		return ret;
 	}
+
 	rt5677->reset_pin = devm_gpiod_get_optional(&i2c->dev,
-			"realtek,reset", GPIOD_OUT_LOW);
+			"realtek,reset", GPIOD_OUT_HIGH);
+
 	if (IS_ERR(rt5677->reset_pin)) {
 		ret = PTR_ERR(rt5677->reset_pin);
 		dev_err(&i2c->dev, "Failed to request RESET: %d\n", ret);
 		return ret;
 	}
 
+	if (rt5677->reset_pin) {
+		msleep(1);
+		gpiod_set_value_cansleep(rt5677->reset_pin, 0);
+	}
+
 	if (rt5677->pow_ldo2 || rt5677->reset_pin) {
 		/* Wait a while until I2C bus becomes available. The datasheet
 		 * does not specify the exact we should wait but startup
Signature · 1 line
2.51.0
#8 lore raw

PATCH 7/7 ASoC: rt5677-spi: Add SPI device ID matching table

In reply to Yauhen Kharuzhy

To allow defining a device in board-specific drivers, add 'rt5677' as a supported SPI device ID.

---
 sound/soc/codecs/rt5677-spi.c | 7 +++++++
 1 file changed, 7 insertions(+)
sound/soc/codecs/rt5677-spi.c +7 -0
index 885edcf0a3a5..548180ec5762 100644
@@ -624,12 +624,19 @@ static const struct acpi_device_id rt5677_spi_acpi_id[] = {
 MODULE_DEVICE_TABLE(acpi, rt5677_spi_acpi_id);
 #endif
 
+static const struct spi_device_id rt5677_spi_ids[] = {
+	{ "rt5677", 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(spi, rt5677_spi_ids);
+
 static struct spi_driver rt5677_spi_driver = {
 	.driver = {
 		.name = DRV_NAME,
 		.acpi_match_table = ACPI_PTR(rt5677_spi_acpi_id),
 	},
 	.probe = rt5677_spi_probe,
+	.id_table = rt5677_spi_ids,
 };
 module_spi_driver(rt5677_spi_driver);
 
Signature · 1 line
2.51.0
maintainer
#2 lore raw

Re: [PATCH 1/7] ASoC: rt5677: Add 10EC5677 ACPI ID as supported

In reply to Yauhen Kharuzhy
Quoted 4 lines · Yauhen Kharuzhy

Add 10EC5677 ACPI ID to the match table. It is used in the Lenovo Yoga Book YB1-X91 tablet at least.

Applied to

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

Thanks!

[1/7] ASoC: rt5677: Add 10EC5677 ACPI ID as supported

      commit: f43aed8dfecb10e95b8235d002990739ebe72c5e
[2/7] ASoC: rt5677: Allow it to be defined as an I2C board
      commit: 9f56f0bd2e49876ceeaf9036887fe9b50dfa6b6b
[3/7] ASoC: rt5677: Fix typo in the header file
      commit: 687f2679e8bf65bca247ca7f4013130d609e1e56
[4/7] ASoC: rt5677: Report error if the ID register cannot be read
      commit: 14848e6a8058916e9b008734aa36da989725b6df
[5/7] ASoC: rt5677: Set up ACPI GPIO pins mapping table
      commit: 0cc00de3dd5b66c80e6ec1705ec929f4a45ffa1c
[6/7] ASoC: rt5677: Reset the codec during probing
      commit: 904e71d42505ca2af19b0031ffffefc8c1fefb48
[7/7] ASoC: rt5677-spi: Add SPI device ID matching table
      commit: bf122191473e26a8f195308b1ba924c98424c8e1

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