Add ASoC machine driver for Cherryview tablets with RT5677
Subsystems (3)
v3 cover Add ASoC machine driver for Cherryview tablets with RT5677
This is the third iteration of my submission for sound support for Lenovo
Yoga Book YB1-X90/X91 tablets.
These are Cherry Trail-based platforms that use the RT5677 codec and TS3A227E jack detection IC.
The YB1-X90 is an Android-designated device and has incorrect ACPI entries for many onboard peripherals, including sound devices. The YB1-X91 has a DSDT node for the codec, and the same node is shared with the TS3A227E jack detection IC (see below).
Matching with ACPI entries is somewhat tricky; see the corresponding commit. Jack detection IC info is defined in the x86-android-tablets driver for both platforms to simplify the code.
The ASoC machine driver is called 'cht_rt5677' but has some device-specific things hardcoded because no other known Cherry Trail-based platforms use an RT5677 codec.
v3:
- Rename cht_yogabook driver to cht_rt5677;
- Allocate snd_soc_card structure dynamically;
- Reset the codec name in the global dailink array back to the default
at driver remove() method to prevent use-after-free error;
- Apply small fixes like removing code duplication and renaming variables in the probe method;
- Remove support for SOF;
- Skip checking if ctx->mclk is valid since probe() will fail if not;
- Ensure error codes are included in error messages during initialization;
- Eliminate debug messages;
- Split cht_rt5677_platform_clock_control() function into enable/disable subroutines;
- Move GPIOs initialization from codec init to probe and use gpiod_*
functions instead of devm_gpiod_* versions because GPIOs are linked to another device;
- Rename variable 'k' to 'kctl' for struct snd_kcontrol arguments;
- Remove ambiguous copyright statements;
- Switch from using *-objs to *-y in the Makefile;
- Correct alignment warnings reported by checkpatch;
- Update ACPI matching code: rename cht_quirk_nocodec() to cht_quirk_strict(), and use a default entry for the YB1-X91 tablet.
- Link to v2: https://lore.kernel.org/r/[email protected]
v2:
cht_yogabook driver:
- Remove likely obsolete code from the driver: GPIO magic manipulations when enabling the speaker amplifier and msleep() calls when turning the speaker/headphones on and off.
- Remove MICBIAS1 manipulation on headphone jack insertion (click prevention): the TS3A227E should handle it by itself.
- Rename struct cht_mc_private to cht_yb_private.
ACPI matching code:
- Split the changes into two commits: reworking existing entries and adding new ones.
- Use dmi_system_id.driver_data to specify matched machine data instead of callbacks.
For reference, there is an ACPI node for sound configuration from YB1-X91 DSDT below:
HID: 10EC5677_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
Decompiled fragment of ACPI dump:
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 */
}
}---
Yauhen Kharuzhy (3):
ASoC: Intel: soc-acpi-cht: Unify device quirks
ASoC: Intel: soc-acpi-cht: Add Lenovo Yoga Book entries
ASoC: Intel: Add cht_rt5677 driver
sound/soc/intel/boards/Kconfig | 18 + sound/soc/intel/boards/Makefile | 2 + sound/soc/intel/boards/cht_rt5677.c | 564 ++++++++++++++++++++++ sound/soc/intel/common/soc-acpi-intel-cht-match.c | 121 ++--- 4 files changed, 648 insertions(+), 57 deletions(-)
---
base-commit: 94a662ada263eb2238b85e1eb4b21fd03b9b5fa2
change-id: 20260219-asoc-yogabook-v2-70c146371d20
Best regards,
Signature · 1 line
Yauhen Kharuzhy
PATCH v3 1/3 ASoC: Intel: soc-acpi-cht: Unify device quirks
This file contains two types of quirks, both checking DMI for machine-specific strings and returning machine data for a matching entry.
The first one, cht_quirk, is used to override the default entry for an existing ACPI codec node if the node's info is invalid. It returns either the matched machine data or the default entry if no match is found.
The second one, cht_yt3_quirk_cb, is used for devices (originally the Lenovo Yoga Tab 3 Pro) without a valid codec DSDT entry. It is bound to the SST ACPI node and returns either the matched machine data or NULL if no match is found.
To allow adding new machine entries to the second case and to use a single DMI match entry for both cases (for example, if two variants of one device
exist: one with a valid ACPI entry and one without, like the Lenovo Yoga Book YB1-X91 and YB1-X90 - Windows and Android versions), reorganize these quirks functions to use the same approach: machine data is set in the matched dmi_system_id entry as driver_data field.
--- sound/soc/intel/common/soc-acpi-intel-cht-match.c | 100 +++++++++------------- 1 file changed, 42 insertions(+), 58 deletions(-)
sound/soc/intel/common/soc-acpi-intel-cht-match.c +42 -58
@@ -9,47 +9,63 @@#include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h> -static unsigned long cht_machine_id; - -#define CHT_SURFACE_MACH 1 +static struct snd_soc_acpi_mach cht_surface_mach = { + .id ="10EC5640" , + .drv_name ="cht-bsw-rt5645" , + .fw_filename ="intel/fw_sst_22a8.bin" , + .board ="cht-bsw" , + .sof_tplg_filename ="sof-cht-rt5645.tplg" , +}; -static int cht_surface_quirk_cb (const struct dmi_system_id *id) -{ - cht_machine_id =CHT_SURFACE_MACH ; -return 1 ; -} +static struct snd_soc_acpi_mach cht_lenovo_yoga_tab3_x90_mach = { + .id ="10WM5102" , + .drv_name ="bytcr_wm5102" , + .fw_filename ="intel/fw_sst_22a8.bin" , + .board ="bytcr_wm5102" , + .sof_tplg_filename ="sof-cht-wm5102.tplg" , +};static const struct dmi_system_id cht_table[] = { { - .callback = cht_surface_quirk_cb, + .driver_data = (void *)&cht_surface_mach, .matches = {DMI_MATCH (DMI_SYS_VENDOR ,"Microsoft Corporation" ),DMI_MATCH (DMI_PRODUCT_NAME ,"Surface 3" ), }, }, + { +/* +* The Lenovo Yoga Tab 3 Pro YT3-X90, with Android factory OS +* has a buggy DSDT with the codec not being listed at all. +*/ + .driver_data = (void *)&cht_lenovo_yoga_tab3_x90_mach, + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Intel Corporation" ), +DMI_MATCH (DMI_PRODUCT_VERSION ,"Blade3-10A-001" ), + }, + }, { } }; -static struct snd_soc_acpi_mach cht_surface_mach = { - .id ="10EC5640" , - .drv_name ="cht-bsw-rt5645" , - .fw_filename ="intel/fw_sst_22a8.bin" , - .board ="cht-bsw" , - .sof_tplg_filename ="sof-cht-rt5645.tplg" , -}; -static struct snd_soc_acpi_mach *cht_quirk (void *arg) {struct snd_soc_acpi_mach *mach = arg; +const struct dmi_system_id *match; -dmi_check_system (cht_table); - -if (cht_machine_id ==CHT_SURFACE_MACH ) -return &cht_surface_mach; + match =dmi_first_match (cht_table); +if (match) +return (struct snd_soc_acpi_mach *)match->driver_data;else return mach; } +static struct snd_soc_acpi_mach *cht_quirk_strict (void *arg) +{ +struct snd_soc_acpi_mach *mach =cht_quirk (arg); + +return mach == arg ?NULL : mach; +} +/* * Some tablets with Android factory OS have buggy DSDTs with an ESSX8316 device * in the ACPI tables. While they are not using an ESS8316 codec. These DSDTs
@@ -75,38 +91,6 @@ static struct snd_soc_acpi_mach *cht_ess8316_quirk(void *arg)return arg; } -/* -* The Lenovo Yoga Tab 3 Pro YT3-X90, with Android factory OS has a buggy DSDT -* with the coded not being listed at all. -*/ -static const struct dmi_system_id lenovo_yoga_tab3_x90[] = { - { -/* Lenovo Yoga Tab 3 Pro YT3-X90, codec missing from DSDT */ - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Intel Corporation" ), -DMI_MATCH (DMI_PRODUCT_VERSION ,"Blade3-10A-001" ), - }, - }, - { } -}; - -static struct snd_soc_acpi_mach cht_lenovo_yoga_tab3_x90_mach = { - .id ="10WM5102" , - .drv_name ="bytcr_wm5102" , - .fw_filename ="intel/fw_sst_22a8.bin" , - .board ="bytcr_wm5102" , - .sof_tplg_filename ="sof-cht-wm5102.tplg" , -}; - -static struct snd_soc_acpi_mach *lenovo_yt3_x90_quirk (void *arg) -{ -if (dmi_check_system (lenovo_yoga_tab3_x90)) -return &cht_lenovo_yoga_tab3_x90_mach; - -/* Skip wildcard match snd_soc_acpi_intel_cherrytrail_machines[] entry */ -return NULL ; -} -static const struct snd_soc_acpi_codecs rt5640_comp_ids = { .num_codecs =2 , .codecs = {"10EC5640" ,"10EC3276" },
@@ -208,14 +192,14 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { .sof_tplg_filename = "sof-cht-src-50khz-pcm512x.tplg", },/* -* Special case for the Lenovo Yoga Tab 3 Pro YT3-X90 where the DSDT -* misses the codec. Match on the SST id instead, lenovo_yt3_x90_quirk() -* will return a YT3 specific mach or NULL when called on other hw, -* skipping this entry. +* Special case for devices where the DSDT misses the codec. Match on +* the SST id instead, cht_quirk_nocodec() will return a +* device-specific mach for matched device or NULL when called on other +* hw, skipping this entry. */ { .id = "808622A8", - .machine_quirk = lenovo_yt3_x90_quirk, + .machine_quirk = cht_quirk_strict, },#if IS_ENABLED (CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH )
Signature · 1 line
2.53.0
Cezary Rojewski
maintainerRe: [PATCH v3 1/3] ASoC: Intel: soc-acpi-cht: Unify device quirks
Quoted 2 lines · Yauhen Kharuzhy
This file contains two types of quirks, both checking DMI for machine-specific strings and returning machine data for a matching entry.
(...)
Quoted 7 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +0
-0@@ -9,47 +9,63 @@#include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h>
sound/soc/intel/common/soc-acpi-intel-cht-match.c line 17
Quoted 10 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +6
-3-static unsigned long cht_machine_id; - -#define CHT_SURFACE_MACH 1 +static struct snd_soc_acpi_mach cht_surface_mach = { + .id ="10EC5640" , + .drv_name ="cht-bsw-rt5645" , + .fw_filename ="intel/fw_sst_22a8.bin" , + .board ="cht-bsw" , + .sof_tplg_filename ="sof-cht-rt5645.tplg" ,
Given all the relocations found in the patch, it's hard to assess the actual impact of it. Ideally there should be no need for the relocation at all.
If you believe this has to be done, please split the change - first have a "preparation patch" that relocates stuff/does whatever is necessary with the existing tables (rt5645 and wm5102) and then have a follow up that carries "the impact".
Quoted 14 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +8
-5+}; -static int cht_surface_quirk_cb (const struct dmi_system_id *id) -{ - cht_machine_id =CHT_SURFACE_MACH ; -return 1 ; -} +static struct snd_soc_acpi_mach cht_lenovo_yoga_tab3_x90_mach = { + .id ="10WM5102" , + .drv_name ="bytcr_wm5102" , + .fw_filename ="intel/fw_sst_22a8.bin" , + .board ="bytcr_wm5102" , + .sof_tplg_filename ="sof-cht-wm5102.tplg" , +};
(...)
Quoted 7 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +0
-7-static struct snd_soc_acpi_mach cht_surface_mach = { - .id ="10EC5640" , - .drv_name ="cht-bsw-rt5645" , - .fw_filename ="intel/fw_sst_22a8.bin" , - .board ="cht-bsw" , - .sof_tplg_filename ="sof-cht-rt5645.tplg" , -};
(...)
Quoted 7 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +0
-7-static struct snd_soc_acpi_mach cht_lenovo_yoga_tab3_x90_mach = { - .id ="10WM5102" , - .drv_name ="bytcr_wm5102" , - .fw_filename ="intel/fw_sst_22a8.bin" , - .board ="bytcr_wm5102" , - .sof_tplg_filename ="sof-cht-wm5102.tplg" , -};
Mark Brown
maintainerRe: [PATCH v3 1/3] ASoC: Intel: soc-acpi-cht: Unify device quirks
In reply to Yauhen KharuzhyQuoted 2 lines · Yauhen Kharuzhy
This file contains two types of quirks, both checking DMI for machine-specific strings and returning machine data for a matching entry.
You've not copied me on the rest of the series so I don't know what's going on with dependencies. When sending a patch series it is important to ensure that all the various maintainers understand what the relationship between the patches as the expecation is that there will be interdependencies. Either copy everyone on the whole series or at least copy them on the cover letter and explain what's going on. If there are no strong interdependencies then it's generally simplest to just send the patches separately to avoid any possible confusion.
Re: [PATCH v3 1/3] ASoC: Intel: soc-acpi-cht: Unify device quirks
Quoted 5 lines · Mark Brown
Quoted 2 lines · Yauhen Kharuzhy
This file contains two types of quirks, both checking DMI for machine-specific strings and returning machine data for a matching entry.
Quoted 8 lines
You've not copied me on the rest of the series so I don't know what's going on with dependencies. When sending a patch series it is important to ensure that all the various maintainers understand what the relationship between the patches as the expecation is that there will be interdependencies. Either copy everyone on the whole series or at least copy them on the cover letter and explain what's going on. If there are no strong interdependencies then it's generally simplest to just send the patches separately to avoid any possible confusion.
Hi,
Sorry, but your email is present in To: header of every patch in the series, could you explain what do you mean?
Signature · 1 line
Yauhen Kharuzhy
Mark Brown
maintainerRe: [PATCH v3 1/3] ASoC: Intel: soc-acpi-cht: Unify device quirks
Quoted 2 lines · Yauhen Kharuzhy
Sorry, but your email is present in To: header of every patch in the series, could you explain what do you mean?
There seems to have been some delay in delivering the rest.
PATCH v3 2/3 ASoC: Intel: soc-acpi-cht: Add Lenovo Yoga Book entries
In reply to Yauhen KharuzhyLenovo Yoga Book YB1-X91 device uses a Cherry Trail SoC and has a valid ACPI DSDT entry for the RT5677 codec. This entry has some non-standard resource definitions, such as jack detection chip information, and hardware has some additional GPIO controls so use 'cht-yogabook' for the driver name instead of some default (like 'cht-bsw-rt5677').
Lenovo Yoga Book YB1-X90 device (Android version of the tablet) has the same hardware configuration but lacks a valid ACPI DSDT entry for the codec, so add DMI match data for it and use the same machine data as for YB1-X91.
--- sound/soc/intel/common/soc-acpi-intel-cht-match.c | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+)
sound/soc/intel/common/soc-acpi-intel-cht-match.c +40 -0
@@ -17,6 +17,14 @@ static struct snd_soc_acpi_mach cht_surface_mach = { .sof_tplg_filename = "sof-cht-rt5645.tplg", }; +static struct snd_soc_acpi_mach cht_yogabook_mach = { + .id ="10EC5677" , + .drv_name ="cht-yogabook" , + .fw_filename ="intel/fw_sst_22a8.bin" , + .board ="cht-yogabook" , + .sof_tplg_filename ="sof-cht-rt5677.tplg" , +}; +static struct snd_soc_acpi_mach cht_lenovo_yoga_tab3_x90_mach = { .id ="10WM5102" , .drv_name ="bytcr_wm5102" ,
@@ -33,6 +41,24 @@ static const struct dmi_system_id cht_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"), }, }, + { + .ident = "Lenovo Yoga Book YB1-X91", + .driver_data = (void *)&cht_yogabook_mach, +/* YB1-X91L/F */ + .matches = { + DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X91"), + } + }, + { + .ident = "Lenovo Yoga Book YB1-X90", + .driver_data = (void *)&cht_yogabook_mach, +/* YB1-X90L/F, codec is not listed in DSDT */ + .matches = { +DMI_EXACT_MATCH (DMI_SYS_VENDOR ,"Intel Corporation" ), +DMI_EXACT_MATCH (DMI_PRODUCT_NAME ,"CHERRYVIEW D1 PLATFORM" ), + DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "YETI-11"), + } + }, {/* * The Lenovo Yoga Tab 3 Pro YT3-X90, with Android factory OS
@@ -121,6 +147,20 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { .board = "cht-bsw", .sof_tplg_filename = "sof-cht-rt5670.tplg", }, +/* +* The only known Cherry Trail device with RT5677 codec and 10EC677 +* DSTD entry is the Lenovo Yoga Book YB1-X91. It has a device-specific +* driver, so check DMI and use a machine quirk to override the default +* (non-existent) machine driver. +*/ + { + .id = "10EC5677", + .drv_name = "cht-bsw-rt5677", + .fw_filename = "intel/fw_sst_22a8.bin", + .board = "cht-bsw", + .machine_quirk = cht_quirk, + .sof_tplg_filename = "sof-cht-rt5677.tplg", + }, { .comp_ids = &rt5645_comp_ids, .drv_name = "cht-bsw-rt5645",
Signature · 1 line
2.53.0
Cezary Rojewski
maintainerRe: [PATCH v3 2/3] ASoC: Intel: soc-acpi-cht: Add Lenovo Yoga Book entries
Quoted 5 lines · Yauhen Kharuzhy
Lenovo Yoga Book YB1-X91 device uses a Cherry Trail SoC and has a valid ACPI DSDT entry for the RT5677 codec. This entry has some non-standard resource definitions, such as jack detection chip information, and hardware has some additional GPIO controls so use 'cht-yogabook' for the driver name instead of some default (like 'cht-bsw-rt5677').
...
Quoted 4 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +0
-0
...
Quoted 7 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +3
-0@@ -121,6 +147,20 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { .board = "cht-bsw", .sof_tplg_filename = "sof-cht-rt5670.tplg", }, +/* +* The only known Cherry Trail device with RT5677 codec and 10EC677 +* DSTD entry is the Lenovo Yoga Book YB1-X91. It has a device-specific
sound/soc/intel/common/soc-acpi-intel-cht-match.c struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { · line 162
Quoted 10 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +10
-0+* driver, so check DMI and use a machine quirk to override the default +* (non-existent) machine driver. +*/ + { + .id = "10EC5677", + .drv_name = "cht-bsw-rt5677", + .fw_filename = "intel/fw_sst_22a8.bin", + .board = "cht-bsw", + .machine_quirk = cht_quirk, + .sof_tplg_filename = "sof-cht-rt5677.tplg",
The cover letter reads:
v3:
(...)
- Remove support for SOF;
and yet here you're assigning .sof_tplg_filename.
Quoted 5 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +1
-0+ }, { .comp_ids = &rt5645_comp_ids, .drv_name = "cht-bsw-rt5645",
PATCH v3 3/3 ASoC: Intel: Add cht_rt5677 driver
In reply to Yauhen KharuzhyAdd a new ASoC machine driver for Intel Cherry Trail platforms with rt5677 codec.
It supports Lenovo Yoga Book tablets (YB1-X90F/L, YB1-X91F/L models) for now and can be extended for other platforms.
This platform uses a Realtek ALC5677 codec accompanied by a TS3A227E jack configuration detection IC.
The driver is based on the cht_bsw_rt5672.c mainline driver and the driver from the vendor's Android kernel [1].
There are no other known Cherry Trail platforms using an RT5677 codec, so some device-specific tricks are hardcoded, such as jack events and additional GPIOs controlling the speaker amplifier.
--- sound/soc/intel/boards/Kconfig | 18 + sound/soc/intel/boards/Makefile | 2 + sound/soc/intel/boards/cht_rt5677.c | 564 ++++++++++++++++++++++ sound/soc/intel/common/soc-acpi-intel-cht-match.c | 29 +- 4 files changed, 590 insertions(+), 23 deletions(-)
sound/soc/intel/boards/Kconfig +18 -0
@@ -198,6 +198,24 @@ config SND_SOC_INTEL_CHT_BSW_NAU8824_MACH Say Y or m if you have such a device. This is a recommended option. If unsure select "N". +config SND_SOC_INTEL_CHT_RT5677_MACH + tristate "Cherrytrail with RT5677 codec" + depends on I2C && ACPI + depends on X86_INTEL_LPSS || COMPILE_TEST + depends on GPIOLIB || COMPILE_TEST + select SND_SOC_ACPI + select SND_SOC_RT5677 + select SND_SOC_TS3A227E + help + This adds support for ASoC machine driver for Intel(R) Cherrytrail + platforms with RT5677 audio codec. + + The driver supports Lenovo Yoga Book tablets, models + YB1-X90F, YB1-X90L, YB1-X91F, YB1-X91L. The jack detection IC TS3A227E + is used. + Say Y or m if you have such a device. This is a recommended option. + If unsure select "N". + config SND_SOC_INTEL_BYT_CHT_CX2072X_MACH tristate "Baytrail & Cherrytrail with CX2072X codec" depends on I2C && ACPI
sound/soc/intel/boards/Makefile +2 -0
@@ -12,6 +12,7 @@ snd-soc-sst-cht-bsw-rt5672-y := cht_bsw_rt5672.o snd-soc-sst-cht-bsw-rt5645-y := cht_bsw_rt5645.o snd-soc-sst-cht-bsw-max98090_ti-y := cht_bsw_max98090_ti.o snd-soc-sst-cht-bsw-nau8824-y := cht_bsw_nau8824.o +snd-soc-sst-cht-rt5677-y := cht_rt5677.o snd-soc-sst-byt-cht-cx2072x-y := bytcht_cx2072x.o snd-soc-sst-byt-cht-da7213-y := bytcht_da7213.o snd-soc-sst-byt-cht-es8316-y := bytcht_es8316.o
@@ -42,6 +43,7 @@ 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_RT5677_MACH) += snd-soc-sst-cht-rt5677.o obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_MAX98090_TI_MACH) += snd-soc-sst-cht-bsw-max98090_ti.o obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_NAU8824_MACH) += snd-soc-sst-cht-bsw-nau8824.o obj-$(CONFIG_SND_SOC_INTEL_BYT_CHT_CX2072X_MACH) += snd-soc-sst-byt-cht-cx2072x.o
sound/soc/intel/boards/cht_rt5677.c new file +564 -0
564 lines not on this page · raw message
sound/soc/intel/common/soc-acpi-intel-cht-match.c +6 -23
@@ -17,12 +17,11 @@ static struct snd_soc_acpi_mach cht_surface_mach = { .sof_tplg_filename = "sof-cht-rt5645.tplg", }; -static struct snd_soc_acpi_mach cht_yogabook_mach = { +static struct snd_soc_acpi_mach cht_rt5677_mach = { .id ="10EC5677" , - .drv_name ="cht-yogabook" , + .drv_name ="cht-rt5677" , .fw_filename ="intel/fw_sst_22a8.bin" , - .board ="cht-yogabook" , - .sof_tplg_filename ="sof-cht-rt5677.tplg" , + .board ="cht_rt5677" , };static struct snd_soc_acpi_mach cht_lenovo_yoga_tab3_x90_mach = {
@@ -41,17 +40,9 @@ static const struct dmi_system_id cht_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"), }, }, - { - .ident = "Lenovo Yoga Book YB1-X91", - .driver_data = (void *)&cht_yogabook_mach, -/* YB1-X91L/F */ - .matches = { - DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X91"), - } - }, { .ident = "Lenovo Yoga Book YB1-X90", - .driver_data = (void *)&cht_yogabook_mach, + .driver_data = (void *)&cht_rt5677_mach,/* YB1-X90L/F, codec is not listed in DSDT */ .matches = { DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
@@ -147,19 +138,11 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { .board = "cht-bsw", .sof_tplg_filename = "sof-cht-rt5670.tplg", }, -/* -* The only known Cherry Trail device with RT5677 codec and 10EC677 -* DSTD entry is the Lenovo Yoga Book YB1-X91. It has a device-specific -* driver, so check DMI and use a machine quirk to override the default -* (non-existent) machine driver. -*/ { .id = "10EC5677", - .drv_name = "cht-bsw-rt5677", + .drv_name = "cht-rt5677", .fw_filename = "intel/fw_sst_22a8.bin", - .board = "cht-bsw", - .machine_quirk = cht_quirk, - .sof_tplg_filename = "sof-cht-rt5677.tplg", + .board = "cht_rt5677", }, { .comp_ids = &rt5645_comp_ids,
Signature · 1 line
2.53.0
Re: [PATCH v3 3/3] ASoC: Intel: Add cht_rt5677 driver
Quoted 2 lines · Yauhen Kharuzhy
Add a new ASoC machine driver for Intel Cherry Trail platforms with rt5677 codec.
...
sound/soc/intel/boards/cht_rt5677.c line 44
Quoted 4 lines
sound/soc/intel/boards/cht_rt5677.c new file +4
-0+struct cht_rt5677_private { +struct snd_soc_card card; +char codec_name[SND_ACPI_I2C_ID_LEN ]; +struct snd_soc_jack jack;
I'm strongly against any private context encompassing card and jack as fields (sick!). The design looks off - it's very unlikely you need to store the card (even as pointer) at all. All the APIs found below either hand you *card on the platter or provide means to do so e.g.: component->card. Retrieving private context from the card is a formality.
sound/soc/intel/boards/cht_rt5677.c line 57
Quoted 13 lines
sound/soc/intel/boards/cht_rt5677.c new file +13
-0+struct clk *mclk; +struct gpio_desc *gpio_spk_en1; +struct gpio_desc *gpio_spk_en2; +struct gpio_desc *gpio_hp_en; +}; + +static int cht_rt5677_platform_clock_enable (struct snd_soc_card *card, +struct snd_soc_dai *codec_dai) +{ +struct cht_rt5677_private *ctx =snd_soc_card_get_drvdata (card); +int ret; + + ret =clk_prepare_enable (ctx->mclk);
(save: enable succeeds)
sound/soc/intel/boards/cht_rt5677.c line 68
Quoted 11 lines
sound/soc/intel/boards/cht_rt5677.c new file +11
-0+if (ret <0 ) { +dev_err (card->dev,"could not configure MCLK state: %d\n" , ret); +return ret; + } + +/* set codec PLL source to the 19.2MHz platform clock (MCLK) */ + ret =snd_soc_dai_set_pll (codec_dai,0 ,RT5677_PLL1_S_MCLK , +CHT_PLAT_CLK_3_HZ ,48000 *512 ); +if (ret <0 ) { +dev_err (card->dev,"can't set codec pll: %d\n" , ret); +return ret;
(save: set_pll fails)
Result: clk is still running despite cht_rt5677_platform_clock_enable() failing.
sound/soc/intel/boards/cht_rt5677.c line 76
Quoted 8 lines
sound/soc/intel/boards/cht_rt5677.c new file +8
-0+ } + +/* set codec sysclk source to PLL */ + ret =snd_soc_dai_set_sysclk (codec_dai,RT5677_SCLK_S_PLL1 , +48000 *512 ,SND_SOC_CLOCK_IN ); +if (ret <0 ) { +dev_err (card->dev,"can't set codec sysclk: %d\n" , ret); +return ret;
And the story repeats itself here too.
Quoted 4 lines
sound/soc/intel/boards/cht_rt5677.c new file +4
-0+ } + +return 0 ; +}
...
sound/soc/intel/boards/cht_rt5677.c line 236
Quoted 10 lines
sound/soc/intel/boards/cht_rt5677.c new file +10
-0+static int cht_rt5677_codec_init (struct snd_soc_pcm_runtime *runtime) +{ +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (runtime,0 ); +struct snd_soc_component *component = codec_dai->component; +struct cht_rt5677_private *ctx =snd_soc_card_get_drvdata (runtime->card); +int ret =0 ; + +/* Enable codec ASRC function for Stereo DAC/Stereo1 ADC/DMIC/I2S1. +* The ASRC clock source is clk_i2s1_asrc. +*/
Explain _why_, don't just repeat the what's clearly visible in the parameter list. Otherwise, just drop the comment.
sound/soc/intel/boards/cht_rt5677.c line 242
Quoted 6 lines
sound/soc/intel/boards/cht_rt5677.c new file +6
-0+rt5677_sel_asrc_clk_src (component,RT5677_DA_STEREO_FILTER | +RT5677_AD_STEREO1_FILTER |RT5677_I2S1_SOURCE , +RT5677_CLK_SEL_I2S1_ASRC ); +/* Enable codec ASRC function for Mono ADC L. +* The ASRC clock source is clk_sys2_asrc. +*/
Ditto.
Quoted 25 lines
sound/soc/intel/boards/cht_rt5677.c new file +25
-0+rt5677_sel_asrc_clk_src (component,RT5677_AD_MONO_L_FILTER , +RT5677_CLK_SEL_SYS2 ); + +/* +* The firmware might enable the clock at +* boot (this information may or may not +* be reflected in the enable clock register). +* To change the rate we must disable the clock +* first to cover these cases. Due to common +* clock framework restrictions that do not allow +* to disable a clock that has not been enabled, +* we need to enable the clock first. +*/ + ret =clk_prepare_enable (ctx->mclk); +if (!ret) +clk_disable_unprepare (ctx->mclk); + + ret =clk_set_rate (ctx->mclk,CHT_PLAT_CLK_3_HZ ); +if (ret) { +dev_err (runtime->dev,"unable to set MCLK rate\n" ); +return ret; + } + +return 0 ; +}
...
sound/soc/intel/boards/cht_rt5677.c line 403
Quoted 4 lines
sound/soc/intel/boards/cht_rt5677.c new file +4
-0+static const struct acpi_gpio_params speaker_enable_gpio = {2 ,0 , false }; +static const struct acpi_gpio_mapping cht_rt5677_gpios[] = { + {"speaker-enable-gpios" , &speaker_enable_gpio,1 }, + {NULL }
Drop the NULL.
Quoted 3 lines
sound/soc/intel/boards/cht_rt5677.c new file +3
-0+}; + +static int snd_cht_rt5677_probe (struct platform_device *pdev)
...
sound/soc/intel/boards/cht_rt5677.c line 489
Quoted 8 lines
sound/soc/intel/boards/cht_rt5677.c new file +8
-0+ ctx->gpio_hp_en =gpiod_get (codec_dev,"headphone-enable" ,GPIOD_OUT_LOW ); +if (IS_ERR (ctx->gpio_hp_en)) { + ret =PTR_ERR (ctx->gpio_hp_en); +dev_err_probe (codec_dev, ret,"getting headphone enable GPIO\n" ); + goto out_put_spken2_gpio; + } + +/* override platform name, if required */
The comment is redundant, explains nothing, drop it.
Quoted 8 lines
sound/soc/intel/boards/cht_rt5677.c new file +8
-0+ platform_name = mach->mach_params.platform; + + ret =snd_soc_fixup_dai_links_platform_name (card, platform_name); +if (ret) { +dev_err_probe (&pdev->dev, ret,"fixing up dai links platform name\n" ); + goto out_put_hpen_gpio; + } +
sound/soc/intel/boards/cht_rt5677.c line 507
Quoted 10 lines
sound/soc/intel/boards/cht_rt5677.c new file +10
-0+ ctx->mclk =devm_clk_get (&pdev->dev,"pmc_plt_clk_3" ); +if (IS_ERR (ctx->mclk)) { + ret =PTR_ERR (ctx->mclk); +dev_err_probe (&pdev->dev, ret,"getting MCLK from pmc_plt_clk_3\n" ); + goto out_put_hpen_gpio; + } + +snd_soc_card_set_drvdata (card, ctx); + +/* register the soc card */
Ditto. The funtion's name says it all.
Quoted 20 lines
sound/soc/intel/boards/cht_rt5677.c new file +20
-0+ ret =devm_snd_soc_register_card (&pdev->dev, card); +if (ret) { +dev_err_probe (&pdev->dev, ret,"registering card\n" ); + goto out_put_hpen_gpio; + } + +return 0 ; + +out_put_hpen_gpio: +gpiod_put (ctx->gpio_hp_en); +out_put_spken2_gpio: +gpiod_put (ctx->gpio_spk_en2); +out_put_spken_gpio: +gpiod_put (ctx->gpio_spk_en1); + +return ret; +} + +static void snd_cht_rt5677_remove (struct platform_device *pdev) +{
sound/soc/intel/boards/cht_rt5677.c line 537
Quoted 10 lines
sound/soc/intel/boards/cht_rt5677.c new file +10
-0+struct snd_soc_card *card =platform_get_drvdata (pdev); +struct cht_rt5677_private *ctx =snd_soc_card_get_drvdata (card); +int i; + +/* +* Reset the codec name in the global dailink array back to the default +* to avoid a use-after-free on driver rebind (unbind/bind): +* ctx->codec_name is about to be freed together with ctx (devm), but +* cht_rt5677_dailink[] is a static global that persists across binds. +*/
All of this looks like a hack and brings me closer to simply stating:
NAK
as I do not believe the patch has been thoroughly tested if such hacks exist. remove() procedure should not care about codecs->name.
Quoted 11 lines
sound/soc/intel/boards/cht_rt5677.c new file +11
-0+for (i =0 ; i <ARRAY_SIZE (cht_rt5677_dailink); i++) { +if (cht_rt5677_dailink[i].codecs->name == ctx->codec_name) { + cht_rt5677_dailink[i].codecs->name =RT5677_I2C_DEFAULT ; +break ; + } + } + +gpiod_put (ctx->gpio_hp_en); +gpiod_put (ctx->gpio_spk_en2); +gpiod_put (ctx->gpio_spk_en1); +}
...
Quoted 40 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +4
-13@@ -17,12 +17,11 @@ static struct snd_soc_acpi_mach cht_surface_mach = { .sof_tplg_filename = "sof-cht-rt5645.tplg", }; -static struct snd_soc_acpi_mach cht_yogabook_mach = { +static struct snd_soc_acpi_mach cht_rt5677_mach = { .id ="10EC5677" , - .drv_name ="cht-yogabook" , + .drv_name ="cht-rt5677" , .fw_filename ="intel/fw_sst_22a8.bin" , - .board ="cht-yogabook" , - .sof_tplg_filename ="sof-cht-rt5677.tplg" , + .board ="cht_rt5677" , };static struct snd_soc_acpi_mach cht_lenovo_yoga_tab3_x90_mach = {@@ -41,17 +40,9 @@ static const struct dmi_system_id cht_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"), }, }, - { - .ident = "Lenovo Yoga Book YB1-X91", - .driver_data = (void *)&cht_yogabook_mach, -/* YB1-X91L/F */ - .matches = { - DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X91"), - } - }, { .ident = "Lenovo Yoga Book YB1-X90", - .driver_data = (void *)&cht_yogabook_mach, + .driver_data = (void *)&cht_rt5677_mach,/* YB1-X90L/F, codec is not listed in DSDT */ .matches = { DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
sound/soc/intel/common/soc-acpi-intel-cht-match.c struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { · line 155
Quoted 9 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +0
-6@@ -147,19 +138,11 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { .board = "cht-bsw", .sof_tplg_filename = "sof-cht-rt5670.tplg", }, -/* -* The only known Cherry Trail device with RT5677 codec and 10EC677 -* DSTD entry is the Lenovo Yoga Book YB1-X91. It has a device-specific -* driver, so check DMI and use a machine quirk to override the default -* (non-existent) machine driver. -*/
You are removing and editing (the below table) code you've just added with 2/3. This looks very bad.
Quoted 13 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +2
-4{ .id = "10EC5677", - .drv_name = "cht-bsw-rt5677", + .drv_name = "cht-rt5677", .fw_filename = "intel/fw_sst_22a8.bin", - .board = "cht-bsw", - .machine_quirk = cht_quirk, - .sof_tplg_filename = "sof-cht-rt5677.tplg", + .board = "cht_rt5677", }, { .comp_ids = &rt5645_comp_ids,
Re: [PATCH v3 3/3] ASoC: Intel: Add cht_rt5677 driver
Quoted 20 lines · Cezary Rojewski
Quoted 2 lines · Yauhen Kharuzhy
Add a new ASoC machine driver for Intel Cherry Trail platforms with rt5677 codec.
...
sound/soc/intel/boards/cht_rt5677.c line 537
Quoted 12 lines
sound/soc/intel/boards/cht_rt5677.c new file +12
-0+static void snd_cht_rt5677_remove (struct platform_device *pdev) +{ +struct snd_soc_card *card =platform_get_drvdata (pdev); +struct cht_rt5677_private *ctx =snd_soc_card_get_drvdata (card); +int i; + +/* +* Reset the codec name in the global dailink array back to the default +* to avoid a use-after-free on driver rebind (unbind/bind): +* ctx->codec_name is about to be freed together with ctx (devm), but +* cht_rt5677_dailink[] is a static global that persists across binds. +*/ All of this looks like a hack and brings me closer to simply stating:
Quoted 4 lines
NAK
as I do not believe the patch has been thoroughly tested if such hacks exist.
remove()procedure should not care aboutcodecs->name.
I agree but it was a simplest way to fix a possible use-after-free in probe():
ctx = kzalloc();
...
if (cht_rt5677_dailink[i].codecs->name &&
!strcmp(cht_rt5677_dailink[i].codecs->name, RT5677_I2C_DEFAULT)) cht_rt5677_dailink[i].codecs->name = ctx->codec_name;
So, if ctx will be freed (after remove()) and probe() will be called again, then cht_rt5677_dailink[i].codecs->name will be invalid.
Now I have checked how this issue is resolved in similar drivers. For example, cht_bsw_rt5672.c has the same pattern with potential use-after-free. cht_bsw_rt5645.c uses a statically allocated buffer to store the name instead of field inside a dynamically allocated context. Maybe a such approach with static buffer would be an acceptable compromise.
Quoted 52 lines
Quoted 12 lines
sound/soc/intel/boards/cht_rt5677.c new file +11
-0+for (i =0 ; i <ARRAY_SIZE (cht_rt5677_dailink); i++) { +if (cht_rt5677_dailink[i].codecs->name == ctx->codec_name) { + cht_rt5677_dailink[i].codecs->name =RT5677_I2C_DEFAULT ; +break ; + } + } + +gpiod_put (ctx->gpio_hp_en); +gpiod_put (ctx->gpio_spk_en2); +gpiod_put (ctx->gpio_spk_en1); +}...
Quoted 37 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +4
-13@@ -17,12 +17,11 @@ static struct snd_soc_acpi_mach cht_surface_mach = { .sof_tplg_filename = "sof-cht-rt5645.tplg", }; -static struct snd_soc_acpi_mach cht_yogabook_mach = { +static struct snd_soc_acpi_mach cht_rt5677_mach = { .id ="10EC5677" , - .drv_name ="cht-yogabook" , + .drv_name ="cht-rt5677" , .fw_filename ="intel/fw_sst_22a8.bin" , - .board ="cht-yogabook" , - .sof_tplg_filename ="sof-cht-rt5677.tplg" , + .board ="cht_rt5677" , };static struct snd_soc_acpi_mach cht_lenovo_yoga_tab3_x90_mach = {@@ -41,17 +40,9 @@ static const struct dmi_system_id cht_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"), }, }, - { - .ident = "Lenovo Yoga Book YB1-X91", - .driver_data = (void *)&cht_yogabook_mach, -/* YB1-X91L/F */ - .matches = { - DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X91"), - } - }, { .ident = "Lenovo Yoga Book YB1-X90", - .driver_data = (void *)&cht_yogabook_mach, + .driver_data = (void *)&cht_rt5677_mach,/* YB1-X90L/F, codec is not listed in DSDT */ .matches = {
Quoted 13 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { · line 155
Quoted 10 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +0
-6@@ -147,19 +138,11 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { .board = "cht-bsw", .sof_tplg_filename = "sof-cht-rt5670.tplg", }, -/* -* The only known Cherry Trail device with RT5677 codec and 10EC677 -* DSTD entry is the Lenovo Yoga Book YB1-X91. It has a device-specific -* driver, so check DMI and use a machine quirk to override the default -* (non-existent) machine driver. -*/ You are removing and editing (the below table) code you've just added with 2/3. This looks very bad.
Argh, it should have been integrated into the second patch in the series instead of this one... My bad, sorry.
Quoted 15 lines
Quoted 14 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +2
-4{ .id = "10EC5677", - .drv_name = "cht-bsw-rt5677", + .drv_name = "cht-rt5677", .fw_filename = "intel/fw_sst_22a8.bin", - .board = "cht-bsw", - .machine_quirk = cht_quirk, - .sof_tplg_filename = "sof-cht-rt5677.tplg", + .board = "cht_rt5677", }, { .comp_ids = &rt5645_comp_ids,
Signature · 1 line
Yauhen Kharuzhy